1 /*
2  * Copyright (c) 2020, Nordic Semiconductor ASA
3  * All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright notice, this
11  *    list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
18  *    contributors may be used to endorse or promote products derived from this
19  *    software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  *
33  */
34 
35 /**
36  * @defgroup nrf_802154_spinel_serialization_decoder_app
37  * 802.15.4 radio driver spinel serialization decoder for APP core
38  * @{
39  *
40  */
41 
42 #ifndef NRF_802154_SPINEL_DEC_APP_H_
43 #define NRF_802154_SPINEL_DEC_APP_H_
44 
45 #include <stddef.h>
46 
47 #include "../spinel_base/spinel.h"
48 #include "nrf_802154_serialization_error.h"
49 
50 #include "nrf_802154.h"
51 #include "nrf_802154_types.h"
52 
53 #ifdef __cplusplus
54 extern "C" {
55 #endif
56 
57 /**
58  * @brief Decode SPINEL_PROP_LAST_STATUS.
59  *
60  * @param[in]  p_property_data    Pointer to a buffer that contains data to be decoded.
61  * @param[in]  property_data_len  Size of the @ref p_property_data buffer.
62  * @param[out] status             Decoded spinel status.
63  *
64  * @returns zero on success or negative error value on failure.
65  *
66  */
67 nrf_802154_ser_err_t nrf_802154_spinel_decode_prop_last_status(const void      * p_property_data,
68                                                                size_t            property_data_len,
69                                                                spinel_status_t * status);
70 
71 /**
72  * @brief Decode SPINEL_DATATYPE_BOOL_S.
73  *
74  * @note This is used to decode `bool` responses for several kinds of requests in 802.15.4 radio driver.
75  *
76  * @param[in]  p_property_data    Pointer to a buffer that contains data to be decoded.
77  * @param[in]  property_data_len  Size of the @ref p_property_data buffer.
78  * @param[out] p_bool_response    Pointer to decoded response value.
79  *
80  * @returns zero on success or negative error value on failure.
81  *
82  */
83 nrf_802154_ser_err_t nrf_802154_spinel_decode_prop_generic_bool(
84     const void * p_property_data,
85     size_t       property_data_len,
86     bool       * p_bool_response);
87 
88 /**
89  * @brief Decode SPINEL_DATATYPE_UINT8_S.
90  *
91  * @note This is used to decode `uint8_t` responses for several kinds of requests in 802.15.4 radio driver.
92  *
93  * @param[in]  p_property_data    Pointer to a buffer that contains data to be decoded.
94  * @param[in]  property_data_len  Size of the @ref p_property_data buffer.
95  * @param[out] p_uint8_response   Pointer to decoded response value.
96  *
97  * @returns zero on success or negative error value on failure.
98  *
99  */
100 nrf_802154_ser_err_t nrf_802154_spinel_decode_prop_generic_uint8(
101     const void * p_property_data,
102     size_t       property_data_len,
103     uint8_t    * p_uint8_response);
104 
105 /**
106  * @brief Decode SPINEL_DATATYPE_UINT16_S.
107  *
108  * @note This is used to decode `uint16_t` responses for several kinds of requests in 802.15.4 radio driver.
109  *
110  * @param[in]  p_property_data    Pointer to a buffer that contains data to be decoded.
111  * @param[in]  property_data_len  Size of the @ref p_property_data buffer.
112  * @param[out] p_uint8_response   Pointer to decoded response value.
113  *
114  * @returns zero on success or negative error value on failure.
115  *
116  */
117 nrf_802154_ser_err_t nrf_802154_spinel_decode_prop_generic_uint16(
118     const void * p_property_data,
119     size_t       property_data_len,
120     uint16_t   * p_uint16_response);
121 
122 /**
123  * @brief Decode SPINEL_PROP_VENDOR_NORDIC_NRF_802154_TX_POWER_GET.
124  *
125  * @param[in]  p_property_data    Pointer to a buffer that contains data to be decoded.
126  * @param[in]  property_data_len  Size of the @ref p_property_data buffer.
127  * @param[out] p_power            Decoded Tx Power.
128  *
129  * @returns zero on success or negative error value on failure.
130  */
131 nrf_802154_ser_err_t nrf_802154_spinel_decode_prop_nrf_802154_tx_power_get_ret(
132     const void * p_property_data,
133     size_t       property_data_len,
134     int8_t     * p_power);
135 
136 /**
137  * @brief Decode SPINEL_PROP_VENDOR_NORDIC_NRF_802154_CHANNEL_GET.
138  *
139  * @param[in]  p_property_data    Pointer to a buffer that contains data to be decoded.
140  * @param[in]  property_data_len  Size of the @ref p_property_data buffer.
141  * @param[out] p_channel          Decoded channel.
142  *
143  * @returns zero on success or negative error value on failure.
144  *
145  */
146 nrf_802154_ser_err_t nrf_802154_spinel_decode_prop_channel(const void * p_property_data,
147                                                            size_t       property_data_len,
148                                                            uint8_t    * p_channel);
149 
150 /**
151  * @brief Decode SPINEL_PROP_VENDOR_NORDIC_NRF_802154_CAPABILITIES_GET.
152  *
153  * @param[in]  p_property_data    Pointer to a buffer that contains data to be decoded.
154  * @param[in]  property_data_len  Size of the @ref p_property_data buffer.
155  * @param[out] p_capabilities     Decoded capabilities.
156  *
157  * @returns zero on success or negative error value on failure.
158  *
159  */
160 nrf_802154_ser_err_t nrf_802154_spinel_decode_prop_nrf_802154_capabilities_get_ret(
161     const void                * p_property_data,
162     size_t                      property_data_len,
163     nrf_802154_capabilities_t * p_capabilities);
164 
165 /**
166  * @brief Decode SPINEL_PROP_VENDOR_NORDIC_NRF_802154_TIME_GET.
167  *
168  * @param[in]  p_property_data    Pointer to a buffer that contains data to be decoded.
169  * @param[in]  property_data_len  Size of the @ref p_property_data buffer.
170  * @param[out] p_time             Decoded time.
171  *
172  * @returns zero on success or negative error value on failure.
173  *
174  */
175 nrf_802154_ser_err_t nrf_802154_spinel_decode_prop_nrf_802154_time_get_ret(
176     const void * p_property_data,
177     size_t       property_data_len,
178     uint64_t   * p_time);
179 
180 /**
181  * @brief Decode SPINEL_PROP_VENDOR_NORDIC_NRF_802154_CCA_CFG_GET.
182  *
183  * @param[in]  p_property_data    Pointer to a buffer that contains data to be decoded.
184  * @param[in]  property_data_len  Size of the @ref p_property_data buffer.
185  * @param[out] p_cfg              Decoded CCA configuration.
186  *
187  * @returns zero on success or negative error value on failure.
188  *
189  */
190 nrf_802154_ser_err_t nrf_802154_spinel_decode_prop_nrf_802154_cca_cfg_get_ret(
191     const void           * p_property_data,
192     size_t                 property_data_len,
193     nrf_802154_cca_cfg_t * p_cfg);
194 
195 /**
196  * @brief Decode SPINEL_PROP_VENDOR_NORDIC_NRF_802154_STAT_TIMESTAMPS_GET.
197  *
198  * @param[in]  p_property_data    Pointer to a buffer that contains data to be decoded.
199  * @param[in]  property_data_len  Size of the @ref p_property_data buffer.
200  * @param[out] p_stat_timestamps  Decoded stat timestamps
201  *
202  * @returns zero on success or negative error value on failure.
203  *
204  */
205 nrf_802154_ser_err_t nrf_802154_spinel_decode_prop_nrf_802154_stat_timestamps_get_ret(
206     const void                   * p_property_data,
207     size_t                         property_data_len,
208     nrf_802154_stat_timestamps_t * p_stat_timestamps);
209 
210 /**
211  * @brief Decode and dispatch SPINEL_CMD_PROP_VALUE_IS.
212  *
213  * @param[in]  p_data    Pointer to a buffer that contains data to be decoded.
214  * @param[in]  data_len  Size of the @ref p_data buffer.
215  *
216  * @returns zero on success or negative error value on failure.
217  *
218  */
219 nrf_802154_ser_err_t nrf_802154_spinel_decode_cmd_prop_value_is(const void * cmd_data,
220                                                                 size_t       cmd_data_len);
221 
222 #ifdef __cplusplus
223 }
224 #endif
225 
226 #endif /* NRF_802154_SPINEL_DEC_APP_H_ */
227 
228 /** @} */
229