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 #include <stddef.h>
36 
37 #include "nrf_802154_const.h"
38 
39 #include "../spinel_base/spinel.h"
40 #include "nrf_802154_spinel_datatypes.h"
41 #include "nrf_802154_spinel_dec.h"
42 #include "nrf_802154_spinel_enc_net.h"
43 #include "nrf_802154_spinel_log.h"
44 #include "nrf_802154_serialization_error.h"
45 #include "nrf_802154_serialization_error_helper.h"
46 #include "nrf_802154_buffer_mgr_dst.h"
47 #include "nrf_802154_buffer_mgr_src.h"
48 
49 #include "nrf_802154.h"
50 #include "nrf_802154_config.h"
51 
52 #if NRF_802154_DELAYED_TRX_ENABLED
53 static uint8_t * mp_transmit_at_frame; ///< Pointer to the frame that was requested to delay-transmit
54 
55 #endif
56 
57 /**
58  * @brief Deal with SPINEL_PROP_VENDOR_NORDIC_NRF_802154_SLEEP request and send response.
59  *
60  * @param[in]  p_property_data    Pointer to a buffer - unused here (no additional data to decode).
61  * @param[in]  property_data_len  Size of the @ref p_data buffer - unused here.
62  *
63  */
spinel_decode_prop_nrf_802154_sleep(const void * p_property_data,size_t property_data_len)64 static nrf_802154_ser_err_t spinel_decode_prop_nrf_802154_sleep(const void * p_property_data,
65                                                                 size_t       property_data_len)
66 {
67     (void)p_property_data;
68     (void)property_data_len;
69 
70     bool sleep_response;
71 
72     sleep_response = nrf_802154_sleep();
73 
74     return nrf_802154_spinel_send_cmd_prop_value_is(SPINEL_PROP_VENDOR_NORDIC_NRF_802154_SLEEP,
75                                                     SPINEL_DATATYPE_NRF_802154_SLEEP_RET,
76                                                     sleep_response);
77 }
78 
79 /**
80  * @brief Deal with SPINEL_PROP_VENDOR_NORDIC_NRF_802154_SLEEP_IF_IDLE request and send response.
81  *
82  * @param[in]  p_property_data    Pointer to a buffer - unused here (no additional data to decode).
83  * @param[in]  property_data_len  Size of the @ref p_data buffer - unused here.
84  *
85  */
spinel_decode_prop_nrf_802154_sleep_if_idle(const void * p_property_data,size_t property_data_len)86 static nrf_802154_ser_err_t spinel_decode_prop_nrf_802154_sleep_if_idle(
87     const void * p_property_data,
88     size_t       property_data_len)
89 {
90     (void)p_property_data;
91     (void)property_data_len;
92 
93     nrf_802154_sleep_error_t sleep_response = nrf_802154_sleep_if_idle();
94 
95     return nrf_802154_spinel_send_cmd_prop_value_is(
96         SPINEL_PROP_VENDOR_NORDIC_NRF_802154_SLEEP_IF_IDLE,
97         SPINEL_DATATYPE_NRF_802154_SLEEP_IF_IDLE_RET,
98         sleep_response);
99 }
100 
101 /**
102  * @brief Deal with SPINEL_PROP_VENDOR_NORDIC_NRF_802154_RECEIVE request and send response.
103  *
104  * @param[in]  p_property_data    Pointer to a buffer - unused here (no additional data to decode).
105  * @param[in]  property_data_len  Size of the @ref p_data buffer - unused here.
106  *
107  */
spinel_decode_prop_nrf_802154_receive(const void * p_property_data,size_t property_data_len)108 static nrf_802154_ser_err_t spinel_decode_prop_nrf_802154_receive(const void * p_property_data,
109                                                                   size_t       property_data_len)
110 {
111     (void)p_property_data;
112     (void)property_data_len;
113 
114     bool receive_response;
115 
116     receive_response = nrf_802154_receive();
117 
118     return nrf_802154_spinel_send_cmd_prop_value_is(SPINEL_PROP_VENDOR_NORDIC_NRF_802154_RECEIVE,
119                                                     SPINEL_DATATYPE_NRF_802154_RECEIVE_RET,
120                                                     receive_response);
121 }
122 
123 #if NRF_802154_DELAYED_TRX_ENABLED
124 /**
125  * @brief Decode and dispatch SPINEL_PROP_VENDOR_NORDIC_NRF_802154_RECEIVE_AT.
126  *
127  * @param[in]  p_property_data    Pointer to a buffer that contains data to be decoded.
128  * @param[in]  property_data_len  Size of the @ref p_property_data buffer.
129  *
130  */
spinel_decode_prop_nrf_802154_receive_at(const void * p_property_data,size_t property_data_len)131 static nrf_802154_ser_err_t spinel_decode_prop_nrf_802154_receive_at(
132     const void * p_property_data,
133     size_t       property_data_len)
134 {
135     uint64_t       rx_time;
136     uint32_t       timeout;
137     uint8_t        channel;
138     uint32_t       id;
139     spinel_ssize_t siz;
140 
141     siz = spinel_datatype_unpack(p_property_data,
142                                  property_data_len,
143                                  SPINEL_DATATYPE_NRF_802154_RECEIVE_AT,
144                                  &rx_time,
145                                  &timeout,
146                                  &channel,
147                                  &id);
148 
149     if (siz < 0)
150     {
151         return NRF_802154_SERIALIZATION_ERROR_DECODING_FAILURE;
152     }
153 
154     bool result = nrf_802154_receive_at(rx_time, timeout, channel, id);
155 
156     return nrf_802154_spinel_send_cmd_prop_value_is(
157         SPINEL_PROP_VENDOR_NORDIC_NRF_802154_RECEIVE_AT,
158         SPINEL_DATATYPE_NRF_802154_RECEIVE_AT_RET,
159         result);
160 }
161 
162 /**
163  * @brief Decode and dispatch SPINEL_PROP_VENDOR_NORDIC_NRF_802154_RECEIVE_AT_CANCEL.
164  *
165  * @param[in]  p_property_data    Pointer to a buffer that contains data to be decoded.
166  * @param[in]  property_data_len  Size of the @ref p_property_data buffer.
167  *
168  */
spinel_decode_prop_nrf_802154_receive_at_cancel(const void * p_property_data,size_t property_data_len)169 static nrf_802154_ser_err_t spinel_decode_prop_nrf_802154_receive_at_cancel(
170     const void * p_property_data,
171     size_t       property_data_len)
172 {
173     uint32_t       id;
174     spinel_ssize_t siz;
175 
176     siz = spinel_datatype_unpack(p_property_data,
177                                  property_data_len,
178                                  SPINEL_DATATYPE_NRF_802154_RECEIVE_AT_CANCEL,
179                                  &id);
180 
181     if (siz < 0)
182     {
183         return NRF_802154_SERIALIZATION_ERROR_DECODING_FAILURE;
184     }
185 
186     bool result = nrf_802154_receive_at_cancel(id);
187 
188     return nrf_802154_spinel_send_cmd_prop_value_is(
189         SPINEL_PROP_VENDOR_NORDIC_NRF_802154_RECEIVE_AT_CANCEL,
190         SPINEL_DATATYPE_NRF_802154_RECEIVE_AT_CANCEL_RET,
191         result);
192 }
193 
194 #endif // NRF_802154_DELAYED_TRX_ENABLED
195 
spinel_decode_prop_nrf_802154_channel_get(const void * p_property_data,size_t property_data_len)196 static nrf_802154_ser_err_t spinel_decode_prop_nrf_802154_channel_get(const void * p_property_data,
197                                                                       size_t       property_data_len)
198 {
199     (void)p_property_data;
200     (void)property_data_len;
201 
202     uint8_t channel = nrf_802154_channel_get();
203 
204     return nrf_802154_spinel_send_cmd_prop_value_is(
205         SPINEL_PROP_VENDOR_NORDIC_NRF_802154_CHANNEL_GET,
206         SPINEL_DATATYPE_NRF_802154_CHANNEL_GET_RET,
207         channel);
208 }
209 
spinel_decode_prop_nrf_802154_channel_set(const void * p_property_data,size_t property_data_len)210 static nrf_802154_ser_err_t spinel_decode_prop_nrf_802154_channel_set(const void * p_property_data,
211                                                                       size_t       property_data_len)
212 {
213     uint8_t        channel;
214     spinel_ssize_t siz;
215 
216     siz = spinel_datatype_unpack(p_property_data,
217                                  property_data_len,
218                                  SPINEL_DATATYPE_NRF_802154_CHANNEL_SET,
219                                  &channel);
220 
221     if (siz < 0)
222     {
223         return NRF_802154_SERIALIZATION_ERROR_DECODING_FAILURE;
224     }
225 
226     nrf_802154_channel_set(channel);
227 
228     return nrf_802154_spinel_send_prop_last_status_is(SPINEL_STATUS_OK);
229 }
230 
231 /**
232  * @brief Decode and dispatch SPINEL_PROP_VENDOR_NORDIC_NRF_802154_PAN_ID_SET.
233  *
234  * @param[in]  p_property_data    Pointer to a buffer that contains data to be decoded.
235  * @param[in]  property_data_len  Size of the @ref p_property_data buffer.
236  *
237  */
spinel_decode_prop_nrf_802154_pan_id_set(const void * p_property_data,size_t property_data_len)238 static nrf_802154_ser_err_t spinel_decode_prop_nrf_802154_pan_id_set(
239     const void * p_property_data,
240     size_t       property_data_len)
241 {
242     const void   * p_pan_id;
243     size_t         pan_id_len;
244     spinel_ssize_t siz;
245 
246     siz = spinel_datatype_unpack(p_property_data,
247                                  property_data_len,
248                                  SPINEL_DATATYPE_NRF_802154_PAN_ID_SET,
249                                  &p_pan_id,
250                                  &pan_id_len);
251 
252     if (siz < 0)
253     {
254         return NRF_802154_SERIALIZATION_ERROR_DECODING_FAILURE;
255     }
256 
257     if (pan_id_len != PAN_ID_SIZE)
258     {
259         return NRF_802154_SERIALIZATION_ERROR_REQUEST_INVALID;
260     }
261 
262     nrf_802154_pan_id_set((uint8_t *)p_pan_id);
263 
264     return nrf_802154_spinel_send_prop_last_status_is(SPINEL_STATUS_OK);
265 }
266 
267 /**
268  * @brief Decode and dispatch SPINEL_PROP_VENDOR_NORDIC_NRF_802154_SHORT_ADDRESS_SET.
269  *
270  * @param[in]  p_property_data    Pointer to a buffer that contains data to be decoded.
271  * @param[in]  property_data_len  Size of the @ref p_property_data buffer.
272  *
273  */
spinel_decode_prop_nrf_802154_short_address_set(const void * p_property_data,size_t property_data_len)274 static nrf_802154_ser_err_t spinel_decode_prop_nrf_802154_short_address_set(
275     const void * p_property_data,
276     size_t       property_data_len)
277 {
278     const void   * p_short_address;
279     size_t         short_address_len;
280     spinel_ssize_t siz;
281 
282     siz = spinel_datatype_unpack(p_property_data,
283                                  property_data_len,
284                                  SPINEL_DATATYPE_NRF_802154_SHORT_ADDRESS_SET,
285                                  &p_short_address,
286                                  &short_address_len);
287 
288     if (siz < 0)
289     {
290         return NRF_802154_SERIALIZATION_ERROR_DECODING_FAILURE;
291     }
292 
293     if (short_address_len != SHORT_ADDRESS_SIZE)
294     {
295         return NRF_802154_SERIALIZATION_ERROR_REQUEST_INVALID;
296     }
297 
298     nrf_802154_short_address_set((uint8_t *)p_short_address);
299 
300     return nrf_802154_spinel_send_prop_last_status_is(SPINEL_STATUS_OK);
301 }
302 
303 /**
304  * @brief Decode and dispatch SPINEL_PROP_VENDOR_NORDIC_NRF_802154_EXTENDED_ADDRESS_SET.
305  *
306  * @param[in]  p_property_data    Pointer to a buffer that contains data to be decoded.
307  * @param[in]  property_data_len  Size of the @ref p_property_data buffer.
308  *
309  */
spinel_decode_prop_nrf_802154_extended_address_set(const void * p_property_data,size_t property_data_len)310 static nrf_802154_ser_err_t spinel_decode_prop_nrf_802154_extended_address_set(
311     const void * p_property_data,
312     size_t       property_data_len)
313 {
314     const void   * p_extended_address;
315     size_t         extended_address_len;
316     spinel_ssize_t siz;
317 
318     siz = spinel_datatype_unpack(p_property_data,
319                                  property_data_len,
320                                  SPINEL_DATATYPE_NRF_802154_EXTENDED_ADDRESS_SET,
321                                  &p_extended_address,
322                                  &extended_address_len);
323 
324     if (siz < 0)
325     {
326         return NRF_802154_SERIALIZATION_ERROR_DECODING_FAILURE;
327     }
328 
329     if (extended_address_len != EXTENDED_ADDRESS_SIZE)
330     {
331         return NRF_802154_SERIALIZATION_ERROR_REQUEST_INVALID;
332     }
333 
334     nrf_802154_extended_address_set((uint8_t *)p_extended_address);
335 
336     return nrf_802154_spinel_send_prop_last_status_is(SPINEL_STATUS_OK);
337 }
338 
339 /**
340  * @brief Decode and dispatch SPINEL_PROP_VENDOR_NORDIC_NRF_802154_PAN_COORD_SET.
341  *
342  * @param[in]  p_property_data    Pointer to a buffer that contains data to be decoded.
343  * @param[in]  property_data_len  Size of the @ref p_property_data buffer.
344  *
345  */
spinel_decode_prop_nrf_802154_pan_coord_set(const void * p_property_data,size_t property_data_len)346 static nrf_802154_ser_err_t spinel_decode_prop_nrf_802154_pan_coord_set(
347     const void * p_property_data,
348     size_t       property_data_len)
349 {
350     bool           enabled;
351     spinel_ssize_t siz;
352 
353     siz = spinel_datatype_unpack(p_property_data,
354                                  property_data_len,
355                                  SPINEL_DATATYPE_NRF_802154_PAN_COORD_SET,
356                                  &enabled);
357 
358     if (siz < 0)
359     {
360         return NRF_802154_SERIALIZATION_ERROR_DECODING_FAILURE;
361     }
362 
363     nrf_802154_pan_coord_set(enabled);
364 
365     return nrf_802154_spinel_send_prop_last_status_is(SPINEL_STATUS_OK);
366 }
367 
368 #if NRF_802154_PAN_COORD_GET_ENABLED
369 
spinel_decode_prop_nrf_802154_pan_coord_get(const void * p_property_data,size_t property_data_len)370 static nrf_802154_ser_err_t spinel_decode_prop_nrf_802154_pan_coord_get(
371     const void * p_property_data,
372     size_t       property_data_len)
373 {
374     (void)p_property_data;
375     (void)property_data_len;
376 
377     bool result = nrf_802154_pan_coord_get();
378 
379     return nrf_802154_spinel_send_cmd_prop_value_is(
380         SPINEL_PROP_VENDOR_NORDIC_NRF_802154_PAN_COORD_GET,
381         SPINEL_DATATYPE_NRF_802154_PAN_COORD_GET_RET,
382         result);
383 }
384 
385 #endif // NRF_802154_PAN_COORD_GET_ENABLED
386 
387 /**
388  * @brief Decode and dispatch SPINEL_PROP_VENDOR_NORDIC_NRF_802154_PROMISCUOUS_SET.
389  *
390  * @param[in]  p_property_data    Pointer to a buffer that contains data to be decoded.
391  * @param[in]  property_data_len  Size of the @ref p_property_data buffer.
392  *
393  */
spinel_decode_prop_nrf_802154_promiscuous_set(const void * p_property_data,size_t property_data_len)394 static nrf_802154_ser_err_t spinel_decode_prop_nrf_802154_promiscuous_set(
395     const void * p_property_data,
396     size_t       property_data_len)
397 {
398     bool           enabled;
399     spinel_ssize_t siz;
400 
401     siz = spinel_datatype_unpack(p_property_data,
402                                  property_data_len,
403                                  SPINEL_DATATYPE_NRF_802154_PROMISCUOUS_SET,
404                                  &enabled);
405 
406     if (siz < 0)
407     {
408         return NRF_802154_SERIALIZATION_ERROR_DECODING_FAILURE;
409     }
410 
411     nrf_802154_promiscuous_set(enabled);
412 
413     return nrf_802154_spinel_send_prop_last_status_is(SPINEL_STATUS_OK);
414 }
415 
416 /**
417  * @brief Decode and dispatch SPINEL_PROP_VENDOR_NORDIC_NRF_802154_RX_ON_WHEN_IDLE_SET.
418  *
419  * @param[in]  p_property_data    Pointer to a buffer that contains data to be decoded.
420  * @param[in]  property_data_len  Size of the @ref p_property_data buffer.
421  *
422  */
spinel_decode_prop_nrf_802154_rx_on_when_idle_set(const void * p_property_data,size_t property_data_len)423 static nrf_802154_ser_err_t spinel_decode_prop_nrf_802154_rx_on_when_idle_set(
424     const void * p_property_data,
425     size_t       property_data_len)
426 {
427     bool           enabled;
428     spinel_ssize_t siz;
429 
430     siz = spinel_datatype_unpack(p_property_data,
431                                  property_data_len,
432                                  SPINEL_DATATYPE_NRF_802154_RX_ON_WHEN_IDLE_SET,
433                                  &enabled);
434 
435     if (siz < 0)
436     {
437         return NRF_802154_SERIALIZATION_ERROR_DECODING_FAILURE;
438     }
439 
440     nrf_802154_rx_on_when_idle_set(enabled);
441 
442     return nrf_802154_spinel_send_prop_last_status_is(SPINEL_STATUS_OK);
443 }
444 
445 /**
446  * @brief Decode and dispatch SPINEL_PROP_VENDOR_NORDIC_NRF_802154_CCA.
447  *
448  * @param[in]  p_property_data    Pointer to a buffer that contains data to be decoded.
449  * @param[in]  property_data_len  Size of the @ref p_property_data buffer.
450  *
451  */
spinel_decode_prop_nrf_802154_cca(const void * p_property_data,size_t property_data_len)452 static nrf_802154_ser_err_t spinel_decode_prop_nrf_802154_cca(const void * p_property_data,
453                                                               size_t       property_data_len)
454 {
455     (void)p_property_data;
456     (void)property_data_len;
457 
458     bool result = nrf_802154_cca();
459 
460     return nrf_802154_spinel_send_cmd_prop_value_is(SPINEL_PROP_VENDOR_NORDIC_NRF_802154_CCA,
461                                                     SPINEL_DATATYPE_NRF_802154_CCA_RET,
462                                                     result);
463 }
464 
465 #if NRF_802154_CARRIER_FUNCTIONS_ENABLED
466 
467 /**
468  * @brief Decode and dispatch SPINEL_PROP_VENDOR_NORDIC_NRF_802154_CONTINUOUS_CARRIER.
469  *
470  * @param[in]  p_property_data    Pointer to a buffer that contains data to be decoded.
471  * @param[in]  property_data_len  Size of the @ref p_property_data buffer.
472  *
473  */
spinel_decode_prop_nrf_802154_continuous_carrier(const void * p_property_data,size_t property_data_len)474 static nrf_802154_ser_err_t spinel_decode_prop_nrf_802154_continuous_carrier(
475     const void * p_property_data,
476     size_t       property_data_len)
477 {
478     (void)p_property_data;
479     (void)property_data_len;
480 
481     bool result = nrf_802154_continuous_carrier();
482 
483     return nrf_802154_spinel_send_cmd_prop_value_is(
484         SPINEL_PROP_VENDOR_NORDIC_NRF_802154_CONTINUOUS_CARRIER,
485         SPINEL_DATATYPE_NRF_802154_CONTINUOUS_CARRIER_RET,
486         result);
487 }
488 
489 /**
490  * @brief Decode and dispatch SPINEL_PROP_VENDOR_NORDIC_NRF_802154_MODULATED_CARRIER.
491  *
492  * @param[in]  p_property_data    Pointer to a buffer that contains data to be decoded.
493  * @param[in]  property_data_len  Size of the @ref p_property_data buffer.
494  *
495  */
spinel_decode_prop_nrf_802154_modulated_carrier(const void * p_property_data,size_t property_data_len)496 static nrf_802154_ser_err_t spinel_decode_prop_nrf_802154_modulated_carrier(
497     const void * p_property_data,
498     size_t       property_data_len)
499 {
500     const void * p_buffer;
501     size_t       p_buffer_len;
502 
503     spinel_ssize_t siz = spinel_datatype_unpack(
504         p_property_data,
505         property_data_len,
506         SPINEL_DATATYPE_NRF_802154_MODULATED_CARRIER,
507         &p_buffer,
508         &p_buffer_len);
509 
510     if (siz < 0)
511     {
512         return NRF_802154_SERIALIZATION_ERROR_DECODING_FAILURE;
513     }
514 
515     if (p_buffer_len != RAW_PAYLOAD_OFFSET + ((uint8_t *)p_buffer)[0])
516     {
517         return NRF_802154_SERIALIZATION_ERROR_REQUEST_INVALID;
518     }
519 
520     bool result = nrf_802154_modulated_carrier(p_buffer);
521 
522     return nrf_802154_spinel_send_cmd_prop_value_is(
523         SPINEL_PROP_VENDOR_NORDIC_NRF_802154_MODULATED_CARRIER,
524         SPINEL_DATATYPE_NRF_802154_MODULATED_CARRIER_RET,
525         result);
526 }
527 
528 #endif // NRF_802154_CARRIER_FUNCTIONS_ENABLED
529 
530 /**
531  * @brief Decode and dispatch SPINEL_PROP_VENDOR_NORDIC_NRF_802154_ENERGY_DETECTION.
532  *
533  * @param[in]  p_property_data    Pointer to a buffer that contains data to be decoded.
534  * @param[in]  property_data_len  Size of the @ref p_property_data buffer.
535  *
536  */
spinel_decode_prop_nrf_802154_energy_detection(const void * p_property_data,size_t property_data_len)537 static nrf_802154_ser_err_t spinel_decode_prop_nrf_802154_energy_detection(
538     const void * p_property_data,
539     size_t       property_data_len)
540 {
541     uint32_t       time_us;
542     spinel_ssize_t siz;
543 
544     siz = spinel_datatype_unpack(p_property_data,
545                                  property_data_len,
546                                  SPINEL_DATATYPE_NRF_802154_ENERGY_DETECTION,
547                                  &time_us);
548 
549     if (siz < 0)
550     {
551         return NRF_802154_SERIALIZATION_ERROR_DECODING_FAILURE;
552     }
553 
554     bool result = nrf_802154_energy_detection(time_us);
555 
556     return nrf_802154_spinel_send_cmd_prop_value_is(
557         SPINEL_PROP_VENDOR_NORDIC_NRF_802154_ENERGY_DETECTION,
558         SPINEL_DATATYPE_NRF_802154_ENERGY_DETECTION_RET,
559         result);
560 }
561 
562 /**
563  * @brief Decode and dispatch SPINEL_PROP_VENDOR_NORDIC_NRF_802154_AUTO_PENDING_BIT_SET.
564  *
565  * @param[in]  p_property_data    Pointer to a buffer that contains data to be decoded.
566  * @param[in]  property_data_len  Size of the @ref p_property_data buffer.
567  */
spinel_decode_prop_nrf_802154_auto_pending_bit_set(const void * p_property_data,size_t property_data_len)568 static nrf_802154_ser_err_t spinel_decode_prop_nrf_802154_auto_pending_bit_set(
569     const void * p_property_data,
570     size_t       property_data_len)
571 {
572     bool           enabled;
573     spinel_ssize_t siz;
574 
575     siz = spinel_datatype_unpack(p_property_data,
576                                  property_data_len,
577                                  SPINEL_DATATYPE_NRF_802154_AUTO_PENDING_BIT_SET,
578                                  &enabled);
579 
580     if (siz < 0)
581     {
582         return NRF_802154_SERIALIZATION_ERROR_DECODING_FAILURE;
583     }
584 
585     nrf_802154_auto_pending_bit_set(enabled);
586 
587     return nrf_802154_spinel_send_prop_last_status_is(SPINEL_STATUS_OK);
588 }
589 
590 /**
591  * @brief Decode and dispatch SPINEL_PROP_VENDOR_NORDIC_NRF_802154_PENDING_BIT_FOR_ADDR_SET.
592  *
593  * @param[in]  p_property_data    Pointer to a buffer that contains data to be decoded.
594  * @param[in]  property_data_len  Size of the @ref p_property_data buffer.
595  */
spinel_decode_prop_nrf_802154_pending_bit_for_addr_set(const void * p_property_data,size_t property_data_len)596 static nrf_802154_ser_err_t spinel_decode_prop_nrf_802154_pending_bit_for_addr_set(
597     const void * p_property_data,
598     size_t       property_data_len)
599 {
600     const uint8_t * p_addr;
601     size_t          addr_len;
602     bool            extended;
603     bool            result = false;
604     spinel_ssize_t  siz;
605 
606     siz = spinel_datatype_unpack(p_property_data,
607                                  property_data_len,
608                                  SPINEL_DATATYPE_NRF_802154_PENDING_BIT_FOR_ADDR_SET,
609                                  &p_addr,
610                                  &addr_len);
611 
612     if (siz < 0)
613     {
614         return NRF_802154_SERIALIZATION_ERROR_DECODING_FAILURE;
615     }
616 
617     if (addr_len == EXTENDED_ADDRESS_SIZE)
618     {
619         extended = true;
620     }
621     else if (addr_len == SHORT_ADDRESS_SIZE)
622     {
623         extended = false;
624     }
625     else
626     {
627         return NRF_802154_SERIALIZATION_ERROR_REQUEST_INVALID;
628     }
629 
630     result = nrf_802154_pending_bit_for_addr_set(p_addr, extended);
631 
632     return nrf_802154_spinel_send_cmd_prop_value_is(
633         SPINEL_PROP_VENDOR_NORDIC_NRF_802154_PENDING_BIT_FOR_ADDR_SET,
634         SPINEL_DATATYPE_NRF_802154_PENDING_BIT_FOR_ADDR_SET_RET,
635         result);
636 }
637 
638 /**
639  * @brief Decode and dispatch SPINEL_PROP_VENDOR_NORDIC_NRF_802154_PENDING_BIT_FOR_ADDR_CLEAR.
640  *
641  * @param[in]  p_property_data    Pointer to a buffer that contains data to be decoded.
642  * @param[in]  property_data_len  Size of the @ref p_property_data buffer.
643  *
644  */
spinel_decode_prop_nrf_802154_pending_bit_for_addr_clear(const void * p_property_data,size_t property_data_len)645 static nrf_802154_ser_err_t spinel_decode_prop_nrf_802154_pending_bit_for_addr_clear(
646     const void * p_property_data,
647     size_t       property_data_len)
648 {
649     const uint8_t * p_addr;
650     size_t          addr_len;
651     bool            extended;
652     bool            result = false;
653     spinel_ssize_t  siz;
654 
655     siz = spinel_datatype_unpack(p_property_data,
656                                  property_data_len,
657                                  SPINEL_DATATYPE_NRF_802154_PENDING_BIT_FOR_ADDR_CLEAR,
658                                  &p_addr,
659                                  &addr_len);
660 
661     if (siz < 0)
662     {
663         return NRF_802154_SERIALIZATION_ERROR_DECODING_FAILURE;
664     }
665 
666     if (addr_len == EXTENDED_ADDRESS_SIZE)
667     {
668         extended = true;
669     }
670     else if (addr_len == SHORT_ADDRESS_SIZE)
671     {
672         extended = false;
673     }
674     else
675     {
676         return NRF_802154_SERIALIZATION_ERROR_REQUEST_INVALID;
677     }
678 
679     result = nrf_802154_pending_bit_for_addr_clear(p_addr, extended);
680 
681     return nrf_802154_spinel_send_cmd_prop_value_is(
682         SPINEL_PROP_VENDOR_NORDIC_NRF_802154_PENDING_BIT_FOR_ADDR_CLEAR,
683         SPINEL_DATATYPE_NRF_802154_PENDING_BIT_FOR_ADDR_CLEAR_RET,
684         result);
685 }
686 
687 /**
688  * @brief Decode and dispatch SPINEL_PROP_VENDOR_NORDIC_NRF_802154_PENDING_BIT_FOR_ADDR_RESET.
689  *
690  * @param[in]  p_property_data    Pointer to a buffer that contains data to be decoded.
691  * @param[in]  property_data_len  Size of the @ref p_property_data buffer.
692  *
693  */
spinel_decode_prop_nrf_802154_pending_bit_for_addr_reset(const void * p_property_data,size_t property_data_len)694 static nrf_802154_ser_err_t spinel_decode_prop_nrf_802154_pending_bit_for_addr_reset(
695     const void * p_property_data,
696     size_t       property_data_len)
697 {
698     bool           extended;
699     spinel_ssize_t siz;
700 
701     siz = spinel_datatype_unpack(p_property_data,
702                                  property_data_len,
703                                  SPINEL_DATATYPE_NRF_802154_PENDING_BIT_FOR_ADDR_RESET,
704                                  &extended);
705 
706     if (siz < 0)
707     {
708         return NRF_802154_SERIALIZATION_ERROR_DECODING_FAILURE;
709     }
710 
711     nrf_802154_pending_bit_for_addr_reset(extended);
712 
713     return nrf_802154_spinel_send_prop_last_status_is(SPINEL_STATUS_OK);
714 }
715 
716 /**
717  * @brief Decode and dispatch SPINEL_PROP_VENDOR_NORDIC_NRF_802154_SRC_ADDR_MATCHING_METHOD_SET.
718  *
719  * @param[in]  p_property_data    Pointer to a buffer that contains data to be decoded.
720  * @param[in]  property_data_len  Size of the @ref p_property_data buffer.
721  *
722  */
spinel_decode_prop_nrf_802154_src_addr_matching_method_set(const void * p_property_data,size_t property_data_len)723 static nrf_802154_ser_err_t spinel_decode_prop_nrf_802154_src_addr_matching_method_set(
724     const void * p_property_data,
725     size_t       property_data_len)
726 {
727     nrf_802154_src_addr_match_t match_method;
728     spinel_ssize_t              siz;
729 
730     siz = spinel_datatype_unpack(p_property_data,
731                                  property_data_len,
732                                  SPINEL_DATATYPE_NRF_802154_SRC_ADDR_MATCHING_METHOD_SET,
733                                  &match_method);
734 
735     if (siz < 0)
736     {
737         return NRF_802154_SERIALIZATION_ERROR_DECODING_FAILURE;
738     }
739 
740     switch (match_method)
741     {
742         case NRF_802154_SRC_ADDR_MATCH_THREAD:
743         case NRF_802154_SRC_ADDR_MATCH_ZIGBEE:
744         case NRF_802154_SRC_ADDR_MATCH_ALWAYS_1:
745             // Intentionally empty
746             break;
747 
748         default:
749             return nrf_802154_spinel_send_prop_last_status_is(SPINEL_STATUS_INVALID_ARGUMENT);
750     }
751 
752     nrf_802154_src_addr_matching_method_set(match_method);
753 
754     return nrf_802154_spinel_send_prop_last_status_is(SPINEL_STATUS_OK);
755 }
756 
757 /**
758  * @brief Decode and dispatch SPINEL_PROP_VENDOR_NORDIC_NRF_802154_ACK_DATA_SET.
759  *
760  * @param[in]  p_property_data    Pointer to a buffer that contains data to be decoded.
761  * @param[in]  property_data_len  Size of the @ref p_property_data buffer.
762  *
763  */
spinel_decode_prop_nrf_802154_ack_data_set(const void * p_property_data,size_t property_data_len)764 static nrf_802154_ser_err_t spinel_decode_prop_nrf_802154_ack_data_set(
765     const void * p_property_data,
766     size_t       property_data_len)
767 {
768     void                * p_addr;
769     size_t                addr_len;
770     void                * p_data;
771     size_t                length;
772     nrf_802154_ack_data_t data_type;
773     spinel_ssize_t        siz;
774     bool                  extended;
775 
776     siz = spinel_datatype_unpack(p_property_data,
777                                  property_data_len,
778                                  SPINEL_DATATYPE_NRF_802154_ACK_DATA_SET,
779                                  &p_addr,
780                                  &addr_len,
781                                  &p_data,
782                                  &length,
783                                  &data_type);
784 
785     if (siz < 0)
786     {
787         return NRF_802154_SERIALIZATION_ERROR_DECODING_FAILURE;
788     }
789 
790     if (addr_len == EXTENDED_ADDRESS_SIZE)
791     {
792         extended = true;
793     }
794     else if (addr_len == SHORT_ADDRESS_SIZE)
795     {
796         extended = false;
797     }
798     else
799     {
800         return NRF_802154_SERIALIZATION_ERROR_REQUEST_INVALID;
801     }
802 
803     bool ack_data_set_res = nrf_802154_ack_data_set(
804         (const uint8_t *)p_addr,
805         extended,
806         (const void *)p_data,
807         (uint16_t)length,
808         data_type);
809 
810     return nrf_802154_spinel_send_cmd_prop_value_is(
811         SPINEL_PROP_VENDOR_NORDIC_NRF_802154_ACK_DATA_SET,
812         SPINEL_DATATYPE_NRF_802154_ACK_DATA_SET_RET,
813         ack_data_set_res);
814 }
815 
816 /**
817  * @brief Decode and dispatch SPINEL_PROP_VENDOR_NORDIC_NRF_802154_ACK_DATA_CLEAR.
818  *
819  * @param[in]  p_property_data    Pointer to a buffer that contains data to be decoded.
820  * @param[in]  property_data_len  Size of the @ref p_property_data buffer.
821  *
822  */
spinel_decode_prop_nrf_802154_ack_data_clear(const void * p_property_data,size_t property_data_len)823 static nrf_802154_ser_err_t spinel_decode_prop_nrf_802154_ack_data_clear(
824     const void * p_property_data,
825     size_t       property_data_len)
826 {
827     const uint8_t       * p_addr;
828     size_t                addr_len;
829     bool                  extended;
830     nrf_802154_ack_data_t data_type;
831     spinel_ssize_t        siz;
832 
833     siz = spinel_datatype_unpack(p_property_data,
834                                  property_data_len,
835                                  SPINEL_DATATYPE_NRF_802154_ACK_DATA_CLEAR,
836                                  &p_addr,
837                                  &addr_len,
838                                  &data_type);
839 
840     if (siz < 0)
841     {
842         return NRF_802154_SERIALIZATION_ERROR_DECODING_FAILURE;
843     }
844 
845     if (addr_len == EXTENDED_ADDRESS_SIZE)
846     {
847         extended = true;
848     }
849     else if (addr_len == SHORT_ADDRESS_SIZE)
850     {
851         extended = false;
852     }
853     else
854     {
855         return NRF_802154_SERIALIZATION_ERROR_REQUEST_INVALID;
856     }
857 
858     bool ack_data_clear_res = nrf_802154_ack_data_clear(p_addr, extended, data_type);
859 
860     return nrf_802154_spinel_send_cmd_prop_value_is(
861         SPINEL_PROP_VENDOR_NORDIC_NRF_802154_ACK_DATA_CLEAR,
862         SPINEL_DATATYPE_NRF_802154_ACK_DATA_CLEAR_RET,
863         ack_data_clear_res);
864 }
865 
spinel_decode_prop_nrf_802154_ack_data_remove_all(const void * p_property_data,size_t property_data_len)866 static nrf_802154_ser_err_t spinel_decode_prop_nrf_802154_ack_data_remove_all(
867     const void * p_property_data,
868     size_t       property_data_len)
869 {
870     bool                  extended;
871     nrf_802154_ack_data_t data_type;
872     spinel_ssize_t        siz;
873 
874     siz = spinel_datatype_unpack(p_property_data,
875                                  property_data_len,
876                                  SPINEL_DATATYPE_NRF_802154_ACK_DATA_REMOVE_ALL,
877                                  &extended,
878                                  &data_type);
879 
880     if (siz < 0)
881     {
882         return NRF_802154_SERIALIZATION_ERROR_DECODING_FAILURE;
883     }
884 
885     nrf_802154_ack_data_remove_all(extended, data_type);
886 
887     return nrf_802154_spinel_send_prop_last_status_is(SPINEL_STATUS_OK);
888 }
889 
890 #if NRF_802154_CSMA_CA_ENABLED
891 
892 /**
893  * @brief Decode and dispatch SPINEL_PROP_VENDOR_NORDIC_NRF_802154_TRANSMIT_CSMA_CA_RAW.
894  *
895  * @param[in]  p_property_data    Pointer to a buffer that contains data to be decoded.
896  * @param[in]  property_data_len  Size of the @ref p_property_data buffer.
897  *
898  */
spinel_decode_prop_nrf_802154_transmit_csma_ca_raw(const void * p_property_data,size_t property_data_len)899 static nrf_802154_ser_err_t spinel_decode_prop_nrf_802154_transmit_csma_ca_raw(
900     const void * p_property_data,
901     size_t       property_data_len)
902 {
903     uint32_t                               remote_frame_handle;
904     const void                           * p_frame;
905     size_t                                 frame_hdata_len;
906     void                                 * p_local_frame_ptr;
907     nrf_802154_transmit_csma_ca_metadata_t tx_metadata;
908 
909     spinel_ssize_t siz = spinel_datatype_unpack(
910         p_property_data,
911         property_data_len,
912         SPINEL_DATATYPE_NRF_802154_TRANSMIT_CSMA_CA_RAW,
913         NRF_802154_TRANSMIT_CSMA_CA_METADATA_DECODE(tx_metadata),
914         NRF_802154_HDATA_DECODE(remote_frame_handle, p_frame, frame_hdata_len));
915 
916     if (siz < 0)
917     {
918         return NRF_802154_SERIALIZATION_ERROR_DECODING_FAILURE;
919     }
920 
921     // Map the remote handle to locally accessible pointer and copy the buffer content there
922     bool frame_added = nrf_802154_buffer_mgr_dst_add(
923         nrf_802154_spinel_dst_buffer_mgr_get(),
924         remote_frame_handle,
925         p_frame,
926         NRF_802154_DATA_LEN_FROM_HDATA_LEN(frame_hdata_len),
927         &p_local_frame_ptr);
928 
929     if (!frame_added)
930     {
931         return NRF_802154_SERIALIZATION_ERROR_NO_MEMORY;
932     }
933 
934     // Transmit the content under the locally accessible pointer
935     bool result = nrf_802154_transmit_csma_ca_raw(p_local_frame_ptr, &tx_metadata);
936 
937     if (!result)
938     {
939         nrf_802154_buffer_mgr_dst_remove_by_local_pointer(nrf_802154_spinel_dst_buffer_mgr_get(),
940                                                           p_local_frame_ptr);
941     }
942 
943     return nrf_802154_spinel_send_cmd_prop_value_is(
944         SPINEL_PROP_VENDOR_NORDIC_NRF_802154_TRANSMIT_CSMA_CA_RAW,
945         SPINEL_DATATYPE_NRF_802154_TRANSMIT_CSMA_CA_RAW_RET,
946         result);
947 }
948 
949 /**
950  * @brief Decode and dispatch SPINEL_PROP_VENDOR_NORDIC_NRF_802154_CSMA_CA_MIN_BE_SET.
951  *
952  * @param[in]  p_property_data    Pointer to a buffer that contains data to be decoded.
953  * @param[in]  property_data_len  Size of the @ref p_property_data buffer.
954  *
955  */
spinel_decode_prop_nrf_802154_csma_ca_min_be_set(const void * p_property_data,size_t property_data_len)956 static nrf_802154_ser_err_t spinel_decode_prop_nrf_802154_csma_ca_min_be_set(
957     const void * p_property_data,
958     size_t       property_data_len)
959 {
960     uint8_t        min_be;
961     spinel_ssize_t siz;
962     bool           result;
963 
964     siz = spinel_datatype_unpack(p_property_data,
965                                  property_data_len,
966                                  SPINEL_DATATYPE_NRF_802154_CSMA_CA_MIN_BE_SET,
967                                  &min_be);
968 
969     if (siz < 0)
970     {
971         return NRF_802154_SERIALIZATION_ERROR_DECODING_FAILURE;
972     }
973 
974     result = nrf_802154_csma_ca_min_be_set(min_be);
975 
976     return nrf_802154_spinel_send_cmd_prop_value_is(
977         SPINEL_PROP_VENDOR_NORDIC_NRF_802154_CSMA_CA_MIN_BE_SET,
978         SPINEL_DATATYPE_NRF_802154_CSMA_CA_MIN_BE_SET_RET,
979         result);
980 }
981 
982 /**
983  * @brief Decode and dispatch SPINEL_PROP_VENDOR_NORDIC_802154_CSMA_CA_MIN_BE_GET.
984  *
985  * @param[in]  p_property_data    Pointer to a buffer that contains data to be decoded.
986  * @param[in]  property_data_len  Size of the @ref p_property_data buffer.
987  *
988  */
spinel_decode_prop_nrf_802154_csma_ca_min_be_get(const void * p_property_data,size_t property_data_len)989 static nrf_802154_ser_err_t spinel_decode_prop_nrf_802154_csma_ca_min_be_get(
990     const void * p_property_data,
991     size_t       property_data_len)
992 {
993     (void)p_property_data;
994     (void)property_data_len;
995 
996     uint8_t min_be = nrf_802154_csma_ca_min_be_get();
997 
998     return nrf_802154_spinel_send_cmd_prop_value_is(
999         SPINEL_PROP_VENDOR_NORDIC_NRF_802154_CSMA_CA_MIN_BE_GET,
1000         SPINEL_DATATYPE_NRF_802154_CSMA_CA_MIN_BE_GET_RET,
1001         min_be);
1002 }
1003 
1004 /**
1005  * @brief Decode and dispatch SPINEL_PROP_VENDOR_NORDIC_NRF_802154_CSMA_CA_MAX_BE_SET.
1006  *
1007  * @param[in]  p_property_data    Pointer to a buffer that contains data to be decoded.
1008  * @param[in]  property_data_len  Size of the @ref p_property_data buffer.
1009  *
1010  */
spinel_decode_prop_nrf_802154_csma_ca_max_be_set(const void * p_property_data,size_t property_data_len)1011 static nrf_802154_ser_err_t spinel_decode_prop_nrf_802154_csma_ca_max_be_set(
1012     const void * p_property_data,
1013     size_t       property_data_len)
1014 {
1015     uint8_t        max_be;
1016     spinel_ssize_t siz;
1017     bool           result;
1018 
1019     siz = spinel_datatype_unpack(p_property_data,
1020                                  property_data_len,
1021                                  SPINEL_DATATYPE_NRF_802154_CSMA_CA_MAX_BE_SET,
1022                                  &max_be);
1023 
1024     if (siz < 0)
1025     {
1026         return NRF_802154_SERIALIZATION_ERROR_DECODING_FAILURE;
1027     }
1028 
1029     result = nrf_802154_csma_ca_max_be_set(max_be);
1030 
1031     return nrf_802154_spinel_send_cmd_prop_value_is(
1032         SPINEL_PROP_VENDOR_NORDIC_NRF_802154_CSMA_CA_MAX_BE_SET,
1033         SPINEL_DATATYPE_NRF_802154_CSMA_CA_MAX_BE_SET_RET,
1034         result);
1035 }
1036 
1037 /**
1038  * @brief Decode and dispatch SPINEL_PROP_VENDOR_NORDIC_NRF_802154_CSMA_CA_MAX_BE_GET.
1039  *
1040  * @param[in]  p_property_data    Pointer to a buffer that contains data to be decoded.
1041  * @param[in]  property_data_len  Size of the @ref p_property_data buffer.
1042  *
1043  */
spinel_decode_prop_nrf_802154_csma_ca_max_be_get(const void * p_property_data,size_t property_data_len)1044 static nrf_802154_ser_err_t spinel_decode_prop_nrf_802154_csma_ca_max_be_get(
1045     const void * p_property_data,
1046     size_t       property_data_len)
1047 {
1048     (void)p_property_data;
1049     (void)property_data_len;
1050 
1051     uint8_t max_be = nrf_802154_csma_ca_max_be_get();
1052 
1053     return nrf_802154_spinel_send_cmd_prop_value_is(
1054         SPINEL_PROP_VENDOR_NORDIC_NRF_802154_CSMA_CA_MAX_BE_GET,
1055         SPINEL_DATATYPE_NRF_802154_CSMA_CA_MAX_BE_GET_RET,
1056         max_be);
1057 }
1058 
1059 /**
1060  * @brief Decode and dispatch SPINEL_PROP_VENDOR_NORDIC_NRF_802154_CSMA_CA_MAX_BACKOFFS_SET.
1061  *
1062  * @param[in]  p_property_data    Pointer to a buffer that contains data to be decoded.
1063  * @param[in]  property_data_len  Size of the @ref p_property_data buffer.
1064  *
1065  */
spinel_decode_prop_nrf_802154_csma_ca_max_backoffs_set(const void * p_property_data,size_t property_data_len)1066 static nrf_802154_ser_err_t spinel_decode_prop_nrf_802154_csma_ca_max_backoffs_set(
1067     const void * p_property_data,
1068     size_t       property_data_len)
1069 {
1070     uint8_t        max_backoffs;
1071     spinel_ssize_t siz;
1072 
1073     siz = spinel_datatype_unpack(p_property_data,
1074                                  property_data_len,
1075                                  SPINEL_DATATYPE_NRF_802154_CSMA_CA_MAX_BACKOFFS_SET,
1076                                  &max_backoffs);
1077 
1078     if (siz < 0)
1079     {
1080         return NRF_802154_SERIALIZATION_ERROR_DECODING_FAILURE;
1081     }
1082 
1083     nrf_802154_csma_ca_max_backoffs_set(max_backoffs);
1084 
1085     return nrf_802154_spinel_send_prop_last_status_is(SPINEL_STATUS_OK);
1086 }
1087 
1088 /**
1089  * @brief Decode and dispatch SPINEL_PROP_VENDOR_NORDIC_NRF_802154_CSMA_CA_MAX_BACKOFFS_GET.
1090  *
1091  * @param[in]  p_property_data    Pointer to a buffer that contains data to backoffs decoded.
1092  * @param[in]  property_data_len  Size of the @ref p_data buffer.
1093  *
1094  */
spinel_decode_prop_nrf_802154_csma_ca_max_backoffs_get(const void * p_property_data,size_t property_data_len)1095 static nrf_802154_ser_err_t spinel_decode_prop_nrf_802154_csma_ca_max_backoffs_get(
1096     const void * p_property_data,
1097     size_t       property_data_len)
1098 {
1099     (void)p_property_data;
1100     (void)property_data_len;
1101 
1102     uint8_t max_backoffs = nrf_802154_csma_ca_max_backoffs_get();
1103 
1104     return nrf_802154_spinel_send_cmd_prop_value_is(
1105         SPINEL_PROP_VENDOR_NORDIC_NRF_802154_CSMA_CA_MAX_BACKOFFS_GET,
1106         SPINEL_DATATYPE_NRF_802154_CSMA_CA_MAX_BACKOFFS_GET_RET,
1107         max_backoffs);
1108 }
1109 
1110 #endif // NRF_802154_CSMA_CA_ENABLED
1111 
1112 #if NRF_802154_TEST_MODES_ENABLED
1113 /**
1114  * @brief Decode and dispatch SPINEL_PROP_VENDOR_NORDIC_NRF_802154_TEST_MODE_CSMACA_BACKOFF_SET.
1115  *
1116  * @param[in]  p_property_data    Pointer to a buffer that contains data to be decoded.
1117  * @param[in]  property_data_len  Size of the @ref p_property_data buffer.
1118  *
1119  */
spinel_decode_prop_nrf_802154_test_mode_csmaca_backoff_set(const void * p_property_data,size_t property_data_len)1120 static nrf_802154_ser_err_t spinel_decode_prop_nrf_802154_test_mode_csmaca_backoff_set(
1121     const void * p_property_data,
1122     size_t       property_data_len)
1123 {
1124     nrf_802154_test_mode_csmaca_backoff_t value;
1125     spinel_ssize_t                        siz;
1126 
1127     siz = spinel_datatype_unpack(p_property_data,
1128                                  property_data_len,
1129                                  SPINEL_DATATYPE_NRF_802154_TEST_MODE_CSMACA_BACKOFF_SET,
1130                                  &value);
1131 
1132     if (siz < 0)
1133     {
1134         return NRF_802154_SERIALIZATION_ERROR_DECODING_FAILURE;
1135     }
1136 
1137     nrf_802154_test_mode_csmaca_backoff_set(value);
1138 
1139     return nrf_802154_spinel_send_prop_last_status_is(SPINEL_STATUS_OK);
1140 }
1141 
1142 /**
1143  * @brief Decode and dispatch SPINEL_PROP_VENDOR_NORDIC_NRF_802154_TEST_MODE_CSMACA_BACKOFF_GET.
1144  *
1145  * @param[in]  p_property_data    Pointer to a buffer that contains data to be decoded.
1146  * @param[in]  property_data_len  Size of the @ref p_property_data buffer.
1147  *
1148  */
spinel_decode_prop_nrf_802154_test_mode_csmaca_backoff_get(const void * p_property_data,size_t property_data_len)1149 static nrf_802154_ser_err_t spinel_decode_prop_nrf_802154_test_mode_csmaca_backoff_get(
1150     const void * p_property_data,
1151     size_t       property_data_len)
1152 {
1153     (void)p_property_data;
1154     (void)property_data_len;
1155 
1156     nrf_802154_test_mode_csmaca_backoff_t value = nrf_802154_test_mode_csmaca_backoff_get();
1157 
1158     return nrf_802154_spinel_send_cmd_prop_value_is(
1159         SPINEL_PROP_VENDOR_NORDIC_NRF_802154_TEST_MODE_CSMACA_BACKOFF_GET,
1160         SPINEL_DATATYPE_NRF_802154_TEST_MODE_CSMACA_BACKOFF_GET_RET,
1161         value);
1162 }
1163 
1164 #endif // NRF_802154_TEST_MODES_ENABLED
1165 
1166 #if NRF_802154_IFS_ENABLED
1167 
1168 /**
1169  * @brief Decode and dispatch SPINEL_PROP_VENDOR_NORDIC_NRF_802154_IFS_MODE_SET
1170  *
1171  * @param[in]  p_property_data    Pointer to a buffer that contains data to be decoded.
1172  * @param[in]  property_data_len  Size of the @ref p_property_data buffer.
1173  *
1174  */
spinel_decode_prop_nrf_802154_ifs_mode_set(const void * p_property_data,size_t property_data_len)1175 static nrf_802154_ser_err_t spinel_decode_prop_nrf_802154_ifs_mode_set(
1176     const void * p_property_data,
1177     size_t       property_data_len)
1178 {
1179     nrf_802154_ifs_mode_t value;
1180     spinel_ssize_t        siz;
1181     bool                  result;
1182 
1183     siz = spinel_datatype_unpack(p_property_data,
1184                                  property_data_len,
1185                                  SPINEL_DATATYPE_NRF_802154_IFS_MODE_SET,
1186                                  &value);
1187 
1188     if (siz < 0)
1189     {
1190         return NRF_802154_SERIALIZATION_ERROR_DECODING_FAILURE;
1191     }
1192 
1193     result = nrf_802154_ifs_mode_set(value);
1194 
1195     return nrf_802154_spinel_send_cmd_prop_value_is(
1196         SPINEL_PROP_VENDOR_NORDIC_NRF_802154_IFS_MODE_SET,
1197         SPINEL_DATATYPE_NRF_802154_IFS_MODE_SET_RET,
1198         result);
1199 }
1200 
1201 /**
1202  * @brief Decode and dispatch SPINEL_PROP_VENDOR_NORDIC_NRF_802154_IFS_MODE_GET
1203  *
1204  * @param[in]  p_property_data    Pointer to a buffer that contains data to be decoded.
1205  * @param[in]  property_data_len  Size of the @ref p_property_data buffer.
1206  *
1207  */
spinel_decode_prop_nrf_802154_ifs_mode_get(const void * p_property_data,size_t property_data_len)1208 static nrf_802154_ser_err_t spinel_decode_prop_nrf_802154_ifs_mode_get(
1209     const void * p_property_data,
1210     size_t       property_data_len)
1211 {
1212     (void)p_property_data;
1213     (void)property_data_len;
1214 
1215     nrf_802154_ifs_mode_t value = nrf_802154_ifs_mode_get();
1216 
1217     return nrf_802154_spinel_send_cmd_prop_value_is(
1218         SPINEL_PROP_VENDOR_NORDIC_NRF_802154_IFS_MODE_GET,
1219         SPINEL_DATATYPE_NRF_802154_IFS_MODE_GET_RET,
1220         value);
1221 }
1222 
1223 /**
1224  * @brief Decode and dispatch SPINEL_PROP_VENDOR_NORDIC_NRF_802154_IFS_MIN_SIFS_PERIOD_SET
1225  *
1226  * @param[in]  p_property_data    Pointer to a buffer that contains data to be decoded.
1227  * @param[in]  property_data_len  Size of the @ref p_property_data buffer.
1228  *
1229  */
spinel_decode_prop_nrf_802154_ifs_min_sifs_period_set(const void * p_property_data,size_t property_data_len)1230 static nrf_802154_ser_err_t spinel_decode_prop_nrf_802154_ifs_min_sifs_period_set(
1231     const void * p_property_data,
1232     size_t       property_data_len)
1233 {
1234     uint16_t       value;
1235     spinel_ssize_t siz;
1236 
1237     siz = spinel_datatype_unpack(p_property_data,
1238                                  property_data_len,
1239                                  SPINEL_DATATYPE_NRF_802154_IFS_MIN_SIFS_PERIOD_SET,
1240                                  &value);
1241 
1242     if (siz < 0)
1243     {
1244         return NRF_802154_SERIALIZATION_ERROR_DECODING_FAILURE;
1245     }
1246 
1247     nrf_802154_ifs_min_sifs_period_set(value);
1248 
1249     return nrf_802154_spinel_send_prop_last_status_is(SPINEL_STATUS_OK);
1250 }
1251 
1252 /**
1253  * @brief Decode and dispatch SPINEL_PROP_VENDOR_NORDIC_NRF_802154_IFS_MIN_SIFS_PERIOD_GET
1254  *
1255  * @param[in]  p_property_data    Pointer to a buffer that contains data to be decoded.
1256  * @param[in]  property_data_len  Size of the @ref p_property_data buffer.
1257  *
1258  */
spinel_decode_prop_nrf_802154_ifs_min_sifs_period_get(const void * p_property_data,size_t property_data_len)1259 static nrf_802154_ser_err_t spinel_decode_prop_nrf_802154_ifs_min_sifs_period_get(
1260     const void * p_property_data,
1261     size_t       property_data_len)
1262 {
1263     (void)p_property_data;
1264     (void)property_data_len;
1265 
1266     uint16_t value = nrf_802154_ifs_min_sifs_period_get();
1267 
1268     return nrf_802154_spinel_send_cmd_prop_value_is(
1269         SPINEL_PROP_VENDOR_NORDIC_NRF_802154_IFS_MIN_SIFS_PERIOD_GET,
1270         SPINEL_DATATYPE_NRF_802154_IFS_MIN_SIFS_PERIOD_GET_RET,
1271         value);
1272 }
1273 
1274 /**
1275  * @brief Decode and dispatch SPINEL_PROP_VENDOR_NORDIC_NRF_802154_IFS_MIN_LIFS_PERIOD_SET
1276  *
1277  * @param[in]  p_property_data    Pointer to a buffer that contains data to be decoded.
1278  * @param[in]  property_data_len  Size of the @ref p_property_data buffer.
1279  *
1280  */
spinel_decode_prop_nrf_802154_ifs_min_lifs_period_set(const void * p_property_data,size_t property_data_len)1281 static nrf_802154_ser_err_t spinel_decode_prop_nrf_802154_ifs_min_lifs_period_set(
1282     const void * p_property_data,
1283     size_t       property_data_len)
1284 {
1285     uint16_t       value;
1286     spinel_ssize_t siz;
1287 
1288     siz = spinel_datatype_unpack(p_property_data,
1289                                  property_data_len,
1290                                  SPINEL_DATATYPE_NRF_802154_IFS_MIN_LIFS_PERIOD_SET,
1291                                  &value);
1292 
1293     if (siz < 0)
1294     {
1295         return NRF_802154_SERIALIZATION_ERROR_DECODING_FAILURE;
1296     }
1297 
1298     nrf_802154_ifs_min_lifs_period_set(value);
1299 
1300     return nrf_802154_spinel_send_prop_last_status_is(SPINEL_STATUS_OK);
1301 }
1302 
1303 /**
1304  * @brief Decode and dispatch SPINEL_PROP_VENDOR_NORDIC_NRF_802154_IFS_MIN_LIFS_PERIOD_GET
1305  *
1306  * @param[in]  p_property_data    Pointer to a buffer that contains data to be decoded.
1307  * @param[in]  property_data_len  Size of the @ref p_property_data buffer.
1308  *
1309  */
spinel_decode_prop_nrf_802154_ifs_min_lifs_period_get(const void * p_property_data,size_t property_data_len)1310 static nrf_802154_ser_err_t spinel_decode_prop_nrf_802154_ifs_min_lifs_period_get(
1311     const void * p_property_data,
1312     size_t       property_data_len)
1313 {
1314     (void)p_property_data;
1315     (void)property_data_len;
1316 
1317     uint16_t value = nrf_802154_ifs_min_lifs_period_get();
1318 
1319     return nrf_802154_spinel_send_cmd_prop_value_is(
1320         SPINEL_PROP_VENDOR_NORDIC_NRF_802154_IFS_MIN_LIFS_PERIOD_GET,
1321         SPINEL_DATATYPE_NRF_802154_IFS_MIN_LIFS_PERIOD_GET_RET,
1322         value);
1323 }
1324 
1325 #endif // NRF_802154_IFS_ENABLED
1326 
1327 /**
1328  * @brief Decode and dispatch SPINEL_PROP_VENDOR_NORDIC_NRF_802154_TRANSMIT_RAW.
1329  *
1330  * @param[in]  p_property_data    Pointer to a buffer that contains data to be decoded.
1331  * @param[in]  property_data_len  Size of the @ref p_property_data buffer.
1332  *
1333  */
spinel_decode_prop_nrf_802154_transmit_raw(const void * p_property_data,size_t property_data_len)1334 static nrf_802154_ser_err_t spinel_decode_prop_nrf_802154_transmit_raw(
1335     const void * p_property_data,
1336     size_t       property_data_len)
1337 {
1338     uint32_t                       remote_frame_handle;
1339     const void                   * p_frame;
1340     size_t                         frame_hdata_len;
1341     void                         * p_local_frame_ptr;
1342     nrf_802154_transmit_metadata_t tx_metadata;
1343 
1344     spinel_ssize_t siz = spinel_datatype_unpack(
1345         p_property_data,
1346         property_data_len,
1347         SPINEL_DATATYPE_NRF_802154_TRANSMIT_RAW,
1348         NRF_802154_TRANSMIT_METADATA_DECODE(tx_metadata),
1349         NRF_802154_HDATA_DECODE(remote_frame_handle, p_frame, frame_hdata_len));
1350 
1351     if (siz < 0)
1352     {
1353         return NRF_802154_SERIALIZATION_ERROR_DECODING_FAILURE;
1354     }
1355 
1356     // Map the remote handle to locally accessible pointer and copy the buffer content there
1357     bool frame_added = nrf_802154_buffer_mgr_dst_add(
1358         nrf_802154_spinel_dst_buffer_mgr_get(),
1359         remote_frame_handle,
1360         p_frame,
1361         NRF_802154_DATA_LEN_FROM_HDATA_LEN(frame_hdata_len),
1362         &p_local_frame_ptr);
1363 
1364     if (!frame_added)
1365     {
1366         return NRF_802154_SERIALIZATION_ERROR_NO_MEMORY;
1367     }
1368 
1369     bool result = nrf_802154_transmit_raw(p_local_frame_ptr, &tx_metadata);
1370 
1371     if (!result)
1372     {
1373         nrf_802154_buffer_mgr_dst_remove_by_local_pointer(nrf_802154_spinel_dst_buffer_mgr_get(),
1374                                                           p_local_frame_ptr);
1375     }
1376 
1377     return nrf_802154_spinel_send_cmd_prop_value_is(
1378         SPINEL_PROP_VENDOR_NORDIC_NRF_802154_TRANSMIT_RAW,
1379         SPINEL_DATATYPE_NRF_802154_TRANSMIT_RAW_RET,
1380         result);
1381 }
1382 
1383 #if NRF_802154_DELAYED_TRX_ENABLED
1384 /**
1385  * @brief Decode and dispatch SPINEL_PROP_VENDOR_NORDIC_NRF_802154_TRANSMIT_RAW_AT.
1386  *
1387  * @param[in]  p_property_data    Pointer to a buffer that contains data to be decoded.
1388  * @param[in]  property_data_len  Size of the @ref p_property_data buffer.
1389  *
1390  */
spinel_decode_prop_nrf_802154_transmit_raw_at(const void * p_property_data,size_t property_data_len)1391 static nrf_802154_ser_err_t spinel_decode_prop_nrf_802154_transmit_raw_at(
1392     const void * p_property_data,
1393     size_t       property_data_len)
1394 {
1395     uint32_t                          remote_frame_handle;
1396     const void                      * p_frame;
1397     size_t                            frame_hdata_len;
1398     void                            * p_local_frame_ptr;
1399     nrf_802154_transmit_at_metadata_t tx_metadata;
1400     uint64_t                          tx_time;
1401 
1402     spinel_ssize_t siz = spinel_datatype_unpack(
1403         p_property_data,
1404         property_data_len,
1405         SPINEL_DATATYPE_NRF_802154_TRANSMIT_RAW_AT,
1406         NRF_802154_TRANSMIT_AT_METADATA_DECODE(tx_metadata),
1407         &tx_time,
1408         NRF_802154_HDATA_DECODE(remote_frame_handle, p_frame, frame_hdata_len));
1409 
1410     if (siz < 0)
1411     {
1412         return NRF_802154_SERIALIZATION_ERROR_DECODING_FAILURE;
1413     }
1414 
1415     // Map the remote handle to locally accessible pointer and copy the buffer content there
1416     bool frame_added = nrf_802154_buffer_mgr_dst_add(
1417         nrf_802154_spinel_dst_buffer_mgr_get(),
1418         remote_frame_handle,
1419         p_frame,
1420         NRF_802154_DATA_LEN_FROM_HDATA_LEN(frame_hdata_len),
1421         &p_local_frame_ptr);
1422 
1423     if (!frame_added)
1424     {
1425         return NRF_802154_SERIALIZATION_ERROR_NO_MEMORY;
1426     }
1427 
1428     // tx_metadata.channel set to 0 means that NULL was passed as metadata on app core
1429     // and the channel should be set to the current channel from PIB
1430     if (0 == tx_metadata.channel)
1431     {
1432         tx_metadata.channel = nrf_802154_channel_get();
1433     }
1434 
1435     bool result = nrf_802154_transmit_raw_at(p_local_frame_ptr, tx_time, &tx_metadata);
1436 
1437     if (!result)
1438     {
1439         nrf_802154_buffer_mgr_dst_remove_by_local_pointer(nrf_802154_spinel_dst_buffer_mgr_get(),
1440                                                           p_local_frame_ptr);
1441     }
1442     else
1443     {
1444         // Latch the local pointer in case the transmission is cancelled
1445         mp_transmit_at_frame = p_local_frame_ptr;
1446     }
1447 
1448     return nrf_802154_spinel_send_cmd_prop_value_is(
1449         SPINEL_PROP_VENDOR_NORDIC_NRF_802154_TRANSMIT_RAW_AT,
1450         SPINEL_DATATYPE_NRF_802154_TRANSMIT_RAW_AT_RET,
1451         result);
1452 }
1453 
1454 /**
1455  * @brief Decode and dispatch SPINEL_PROP_VENDOR_NORDIC_NRF_802154_TRANSMIT_AT_CANCEL.
1456  *
1457  * @param[in]  p_property_data    Pointer to a buffer that contains data to be decoded.
1458  * @param[in]  property_data_len  Size of the @ref p_property_data buffer.
1459  *
1460  */
spinel_decode_prop_nrf_802154_transmit_at_cancel(const void * p_property_data,size_t property_data_len)1461 static nrf_802154_ser_err_t spinel_decode_prop_nrf_802154_transmit_at_cancel(
1462     const void * p_property_data,
1463     size_t       property_data_len)
1464 {
1465     (void)p_property_data;
1466     (void)property_data_len;
1467 
1468     bool result = nrf_802154_transmit_at_cancel();
1469 
1470     if (result)
1471     {
1472         // The transmission was cancelled successfully
1473         if (!mp_transmit_at_frame)
1474         {
1475             // This should never happen
1476             return NRF_802154_SERIALIZATION_ERROR_INVALID_BUFFER;
1477         }
1478 
1479         // Free the local frame pointer
1480         bool removed = nrf_802154_buffer_mgr_dst_remove_by_local_pointer(
1481             nrf_802154_spinel_dst_buffer_mgr_get(),
1482             mp_transmit_at_frame);
1483 
1484         if (!removed)
1485         {
1486             return NRF_802154_SERIALIZATION_ERROR_INVALID_BUFFER;
1487         }
1488     }
1489 
1490     return nrf_802154_spinel_send_cmd_prop_value_is(
1491         SPINEL_PROP_VENDOR_NORDIC_NRF_802154_TRANSMIT_AT_CANCEL,
1492         SPINEL_DATATYPE_NRF_802154_TRANSMIT_AT_CANCEL_RET,
1493         result);
1494 }
1495 
1496 #endif // NRF_802154_DELAYED_TRX_ENABLED
1497 
1498 /**
1499  * @brief Decode and dispatch SPINEL_PROP_VENDOR_NORDIC_NRF_802154_BUFFER_FREE_RAW.
1500  *
1501  * @param[in]  p_property_data    Pointer to a buffer that contains data to be decoded.
1502  * @param[in]  property_data_len  Size of the @ref p_property_data buffer.
1503  *
1504  */
spinel_decode_prop_nrf_802154_buffer_free_raw(const void * p_property_data,size_t property_data_len)1505 static nrf_802154_ser_err_t spinel_decode_prop_nrf_802154_buffer_free_raw(
1506     const void * p_property_data,
1507     size_t       property_data_len)
1508 {
1509     uint32_t local_frame_handle;
1510     void   * p_local_ptr;
1511 
1512     spinel_ssize_t siz = spinel_datatype_unpack(p_property_data,
1513                                                 property_data_len,
1514                                                 SPINEL_DATATYPE_NRF_802154_BUFFER_FREE_RAW,
1515                                                 &local_frame_handle);
1516 
1517     if (siz < 0)
1518     {
1519         return NRF_802154_SERIALIZATION_ERROR_DECODING_FAILURE;
1520     }
1521 
1522     // Search for a locally accessible pointer to be freed based on the local handle
1523     bool ptr_found = nrf_802154_buffer_mgr_src_search_by_buffer_handle(
1524         nrf_802154_spinel_src_buffer_mgr_get(),
1525         local_frame_handle,
1526         &p_local_ptr);
1527 
1528     if (ptr_found)
1529     {
1530         // Free the buffer
1531         nrf_802154_buffer_free_raw(p_local_ptr);
1532 
1533         // Remove the mapping associated with the provided handle
1534         bool ptr_removed = nrf_802154_buffer_mgr_src_remove_by_buffer_handle(
1535             nrf_802154_spinel_src_buffer_mgr_get(),
1536             local_frame_handle);
1537 
1538         if (!ptr_removed)
1539         {
1540             return NRF_802154_SERIALIZATION_ERROR_INVALID_BUFFER;
1541         }
1542     }
1543 
1544     return nrf_802154_spinel_send_prop_last_status_is(SPINEL_STATUS_OK);
1545 }
1546 
1547 /**
1548  * @brief Decode and dispatch SPINEL_PROP_VENDOR_NORDIC_NRF_802154_TX_POWER_SET.
1549  *
1550  * @param[in]  p_property_data    Pointer to a buffer that contains data to be decoded.
1551  * @param[in]  property_data_len  Size of the @ref p_property_data buffer.
1552  *
1553  */
spinel_decode_prop_nrf_802154_tx_power_set(const void * p_property_data,size_t property_data_len)1554 static nrf_802154_ser_err_t spinel_decode_prop_nrf_802154_tx_power_set(const void * p_property_data,
1555                                                                        size_t       property_data_len)
1556 {
1557     spinel_ssize_t siz;
1558     int8_t         power;
1559 
1560     siz = spinel_datatype_unpack(p_property_data,
1561                                  property_data_len,
1562                                  SPINEL_DATATYPE_NRF_802154_TX_POWER_SET,
1563                                  &power);
1564     if (siz < 0)
1565     {
1566         return NRF_802154_SERIALIZATION_ERROR_DECODING_FAILURE;
1567     }
1568 
1569     nrf_802154_tx_power_set(power);
1570 
1571     return nrf_802154_spinel_send_prop_last_status_is(SPINEL_STATUS_OK);
1572 }
1573 
1574 /**
1575  * @brief Decode and dispatch SPINEL_PROP_VENDOR_NORDIC_NRF_802154_TX_POWER_GET.
1576  *
1577  * @param[in]  p_property_data    Pointer to a buffer that contains data to be decoded.
1578  * @param[in]  property_data_len  Size of the @ref p_property_data buffer.
1579  *
1580  */
spinel_decode_prop_nrf_802154_tx_power_get(const void * p_property_data,size_t property_data_len)1581 static nrf_802154_ser_err_t spinel_decode_prop_nrf_802154_tx_power_get(const void * p_property_data,
1582                                                                        size_t       property_data_len)
1583 {
1584     (void)p_property_data;
1585     (void)property_data_len;
1586 
1587     int8_t power;
1588 
1589     power = nrf_802154_tx_power_get();
1590 
1591     return nrf_802154_spinel_send_cmd_prop_value_is(
1592         SPINEL_PROP_VENDOR_NORDIC_NRF_802154_TX_POWER_GET,
1593         SPINEL_DATATYPE_NRF_802154_TX_POWER_GET_RET,
1594         power);
1595 }
1596 
1597 /**
1598  * @brief Decode and dispatch SPINEL_PROP_VENDOR_NORDIC_NRF_802154_CAPABILITIES_GET.
1599  *
1600  * @param[in]  p_property_data    Pointer to a buffer that contains data to be decoded.
1601  * @param[in]  property_data_len  Size of the @ref p_property_data buffer.
1602  *
1603  */
spinel_decode_prop_nrf_802154_capabilities_get(const void * p_property_data,size_t property_data_len)1604 static nrf_802154_ser_err_t spinel_decode_prop_nrf_802154_capabilities_get(
1605     const void * p_property_data,
1606     size_t       property_data_len)
1607 {
1608     (void)p_property_data;
1609     (void)property_data_len;
1610 
1611     nrf_802154_capabilities_t caps;
1612 
1613     caps = nrf_802154_capabilities_get();
1614 
1615     return nrf_802154_spinel_send_cmd_prop_value_is(
1616         SPINEL_PROP_VENDOR_NORDIC_NRF_802154_CAPABILITIES_GET,
1617         SPINEL_DATATYPE_NRF_802154_CAPABILITIES_GET_RET,
1618         caps);
1619 }
1620 
1621 /**
1622  * @brief Decode and dispatch SPINEL_PROP_VENDOR_NORDIC_NRF_802154_TIME_GET.
1623  *
1624  * @param[in]  p_property_data    Pointer to a buffer that contains data to be decoded.
1625  * @param[in]  property_data_len  Size of the @ref p_property_data buffer.
1626  *
1627  */
spinel_decode_prop_nrf_802154_time_get(const void * p_property_data,size_t property_data_len)1628 static nrf_802154_ser_err_t spinel_decode_prop_nrf_802154_time_get(
1629     const void * p_property_data,
1630     size_t       property_data_len)
1631 {
1632     (void)p_property_data;
1633     (void)property_data_len;
1634 
1635     uint64_t time;
1636 
1637     time = nrf_802154_time_get();
1638 
1639     return nrf_802154_spinel_send_cmd_prop_value_is(
1640         SPINEL_PROP_VENDOR_NORDIC_NRF_802154_TIME_GET,
1641         SPINEL_DATATYPE_NRF_802154_TIME_GET_RET,
1642         time);
1643 }
1644 
spinel_decode_prop_nrf_802154_cca_cfg_get(const void * p_property_data,size_t property_data_len)1645 static nrf_802154_ser_err_t spinel_decode_prop_nrf_802154_cca_cfg_get(const void * p_property_data,
1646                                                                       size_t       property_data_len)
1647 {
1648     (void)p_property_data;
1649     (void)property_data_len;
1650 
1651     nrf_802154_cca_cfg_t cfg;
1652 
1653     nrf_802154_cca_cfg_get(&cfg);
1654 
1655     return nrf_802154_spinel_send_cmd_prop_value_is(
1656         SPINEL_PROP_VENDOR_NORDIC_NRF_802154_CCA_CFG_GET,
1657         SPINEL_DATATYPE_NRF_802154_CCA_CFG_GET_RET,
1658         NRF_802154_CCA_CFG_ENCODE(cfg));
1659 }
1660 
spinel_decode_prop_nrf_802154_stat_timestamps_get(const void * p_property_data,size_t property_data_len)1661 static nrf_802154_ser_err_t spinel_decode_prop_nrf_802154_stat_timestamps_get(
1662     const void * p_property_data,
1663     size_t       property_data_len)
1664 {
1665     (void)p_property_data;
1666     (void)property_data_len;
1667 
1668     nrf_802154_stat_timestamps_t t;
1669 
1670     nrf_802154_stat_timestamps_get(&t);
1671 
1672     return nrf_802154_spinel_send_cmd_prop_value_is(
1673         SPINEL_PROP_VENDOR_NORDIC_NRF_802154_STAT_TIMESTAMPS_GET,
1674         SPINEL_DATATYPE_NRF_802154_STAT_TIMESTAMPS_GET_RET,
1675         NRF_802154_STAT_TIMESTAMPS_ENCODE(t));
1676 }
1677 
spinel_decode_prop_nrf_802154_cca_cfg_set(const void * p_property_data,size_t property_data_len)1678 static nrf_802154_ser_err_t spinel_decode_prop_nrf_802154_cca_cfg_set(const void * p_property_data,
1679                                                                       size_t       property_data_len)
1680 {
1681     nrf_802154_cca_cfg_t cfg;
1682     spinel_ssize_t       siz;
1683 
1684     siz = spinel_datatype_unpack(p_property_data,
1685                                  property_data_len,
1686                                  SPINEL_DATATYPE_NRF_802154_CCA_CFG_SET,
1687                                  NRF_802154_CCA_CFG_DECODE(cfg));
1688 
1689     if (siz < 0)
1690     {
1691         return NRF_802154_SERIALIZATION_ERROR_DECODING_FAILURE;
1692     }
1693 
1694     nrf_802154_cca_cfg_set(&cfg);
1695 
1696     return nrf_802154_spinel_send_prop_last_status_is(SPINEL_STATUS_OK);
1697 }
1698 
1699 /**
1700  * @brief Decode and dispatch SPINEL_PROP_VENDOR_NORDIC_NRF_802154_SECURITY_GLOBAL_FRAME_COUNTER_SET.
1701  *
1702  * @param[in]  p_property_data    Pointer to a buffer that contains data to be decoded.
1703  * @param[in]  property_data_len  Size of the @ref p_property_data buffer.
1704  *
1705  */
spinel_decode_prop_nrf_802154_security_global_frame_counter_set(const void * p_property_data,size_t property_data_len)1706 static nrf_802154_ser_err_t spinel_decode_prop_nrf_802154_security_global_frame_counter_set(
1707     const void * p_property_data,
1708     size_t       property_data_len)
1709 {
1710     spinel_ssize_t siz;
1711     uint32_t       frame_counter;
1712 
1713     siz = spinel_datatype_unpack(p_property_data,
1714                                  property_data_len,
1715                                  SPINEL_DATATYPE_NRF_802154_SECURITY_GLOBAL_FRAME_COUNTER_SET,
1716                                  &frame_counter);
1717     if (siz < 0)
1718     {
1719         return NRF_802154_SERIALIZATION_ERROR_DECODING_FAILURE;
1720     }
1721 
1722     nrf_802154_security_global_frame_counter_set(frame_counter);
1723 
1724     return nrf_802154_spinel_send_prop_last_status_is(SPINEL_STATUS_OK);
1725 }
1726 
1727 /**
1728  * @brief Decode and dispatch SPINEL_PROP_VENDOR_NORDIC_NRF_802154_SECURITY_GLOBAL_FRAME_COUNTER_SET_IF_LARGER.
1729  *
1730  * @param[in]  p_property_data    Pointer to a buffer that contains data to be decoded.
1731  * @param[in]  property_data_len  Size of the @ref p_property_data buffer.
1732  *
1733  */
1734 static nrf_802154_ser_err_t
spinel_decode_prop_nrf_802154_security_global_frame_counter_set_if_larger(const void * p_property_data,size_t property_data_len)1735 spinel_decode_prop_nrf_802154_security_global_frame_counter_set_if_larger(
1736     const void * p_property_data,
1737     size_t       property_data_len)
1738 {
1739     spinel_ssize_t siz;
1740     uint32_t       frame_counter;
1741 
1742     siz = spinel_datatype_unpack(p_property_data,
1743                                  property_data_len,
1744                                  SPINEL_DATATYPE_NRF_802154_SECURITY_GLOBAL_FRAME_COUNTER_SET,
1745                                  &frame_counter);
1746     if (siz < 0)
1747     {
1748         return NRF_802154_SERIALIZATION_ERROR_DECODING_FAILURE;
1749     }
1750 
1751     nrf_802154_security_global_frame_counter_set_if_larger(frame_counter);
1752 
1753     return nrf_802154_spinel_send_prop_last_status_is(SPINEL_STATUS_OK);
1754 }
1755 
1756 /**
1757  * @brief Decode and dispatch SPINEL_PROP_VENDOR_NORDIC_NRF_802154_SECURITY_KEY_STORE.
1758  *
1759  * @param[in]  p_property_data    Pointer to a buffer that contains data to be decoded.
1760  * @param[in]  property_data_len  Size of the @ref p_property_data buffer.
1761  *
1762  */
spinel_decode_prop_nrf_802154_security_key_store(const void * p_property_data,size_t property_data_len)1763 static nrf_802154_ser_err_t spinel_decode_prop_nrf_802154_security_key_store(
1764     const void * p_property_data,
1765     size_t       property_data_len)
1766 {
1767     spinel_ssize_t              siz;
1768     nrf_802154_key_t            key = {0};
1769     uint32_t                    key_size;
1770     uint32_t                    key_id_size;
1771     nrf_802154_security_error_t err;
1772 
1773     siz = spinel_datatype_unpack(p_property_data,
1774                                  property_data_len,
1775                                  SPINEL_DATATYPE_NRF_802154_SECURITY_KEY_STORE,
1776                                  NRF_802154_SECURITY_KEY_STORE_DECODE(key, key_size, key_id_size));
1777     if (siz < 0)
1778     {
1779         return NRF_802154_SERIALIZATION_ERROR_DECODING_FAILURE;
1780     }
1781 
1782     err = nrf_802154_security_key_store(&key);
1783 
1784     return nrf_802154_spinel_send_cmd_prop_value_is(
1785         SPINEL_PROP_VENDOR_NORDIC_NRF_802154_SECURITY_KEY_STORE,
1786         SPINEL_DATATYPE_NRF_802154_SECURITY_ERROR_RET,
1787         err);
1788 }
1789 
1790 /**
1791  * @brief Decode and dispatch SPINEL_PROP_VENDOR_NORDIC_NRF_802154_SECURITY_KEY_REMOVE.
1792  *
1793  * @param[in]  p_property_data    Pointer to a buffer that contains data to be decoded.
1794  * @param[in]  property_data_len  Size of the @ref p_property_data buffer.
1795  *
1796  */
spinel_decode_prop_nrf_802154_security_key_remove(const void * p_property_data,size_t property_data_len)1797 static nrf_802154_ser_err_t spinel_decode_prop_nrf_802154_security_key_remove(
1798     const void * p_property_data,
1799     size_t       property_data_len)
1800 {
1801     spinel_ssize_t              siz;
1802     uint8_t                     key_id_data[KEY_ID_MODE_3_SIZE];
1803     nrf_802154_key_id_t         key_id = {.p_key_id = key_id_data};
1804     uint32_t                    key_id_size;
1805     nrf_802154_security_error_t err;
1806 
1807     siz = spinel_datatype_unpack(p_property_data,
1808                                  property_data_len,
1809                                  SPINEL_DATATYPE_NRF_802154_SECURITY_KEY_REMOVE,
1810                                  NRF_802154_SECURITY_KEY_REMOVE_DECODE(key_id, key_id_size));
1811     if (siz < 0)
1812     {
1813         return NRF_802154_SERIALIZATION_ERROR_DECODING_FAILURE;
1814     }
1815 
1816     err = nrf_802154_security_key_remove(&key_id);
1817 
1818     return nrf_802154_spinel_send_cmd_prop_value_is(
1819         SPINEL_PROP_VENDOR_NORDIC_NRF_802154_SECURITY_KEY_REMOVE,
1820         SPINEL_DATATYPE_NRF_802154_SECURITY_ERROR_RET,
1821         err);
1822 }
1823 
1824 /**
1825  * @brief Decode and dispatch SPINEL_PROP_VENDOR_NORDIC_NRF_802154_SECURITY_KEY_REMOVE_ALL.
1826  *
1827  * @param[in]  p_property_data    Pointer to a buffer that contains data to be decoded.
1828  * @param[in]  property_data_len  Size of the @ref p_property_data buffer.
1829  *
1830  */
spinel_decode_prop_nrf_802154_security_key_remove_all(const void * p_property_data,size_t property_data_len)1831 static nrf_802154_ser_err_t spinel_decode_prop_nrf_802154_security_key_remove_all(
1832     const void * p_property_data,
1833     size_t       property_data_len)
1834 {
1835     (void)p_property_data;
1836     (void)property_data_len;
1837 
1838     nrf_802154_security_key_remove_all();
1839 
1840     return nrf_802154_spinel_send_prop_last_status_is(SPINEL_STATUS_OK);
1841 }
1842 
1843 #if NRF_802154_DELAYED_TRX_ENABLED && NRF_802154_IE_WRITER_ENABLED
1844 
1845 /**
1846  * @brief Decode and dispatch SPINEL_PROP_VENDOR_NORDIC_NRF_802154_CSL_WRITER_PERIOD_SET.
1847  *
1848  * @param[in]  p_property_data    Pointer to a buffer that contains data to be decoded.
1849  * @param[in]  property_data_len  Size of the @ref p_property_data buffer.
1850  *
1851  */
spinel_decode_prop_nrf_802154_csl_writer_period_set(const void * p_property_data,size_t property_data_len)1852 static nrf_802154_ser_err_t spinel_decode_prop_nrf_802154_csl_writer_period_set(
1853     const void * p_property_data,
1854     size_t       property_data_len)
1855 {
1856     spinel_ssize_t siz;
1857     uint16_t       csl_period;
1858 
1859     siz = spinel_datatype_unpack(p_property_data,
1860                                  property_data_len,
1861                                  SPINEL_DATATYPE_NRF_802154_CSL_WRITER_PERIOD_SET,
1862                                  &csl_period);
1863     if (siz < 0)
1864     {
1865         return NRF_802154_SERIALIZATION_ERROR_DECODING_FAILURE;
1866     }
1867 
1868     nrf_802154_csl_writer_period_set(csl_period);
1869 
1870     return nrf_802154_spinel_send_prop_last_status_is(SPINEL_STATUS_OK);
1871 }
1872 
1873 /**
1874  * @brief Decode and dispatch SPINEL_PROP_VENDOR_NORDIC_NRF_802154_CSL_WRITER_ANCHOR_TIME_SET.
1875  *
1876  * @param[in]  p_property_data    Pointer to a buffer that contains data to be decoded.
1877  * @param[in]  property_data_len  Size of the @ref p_property_data buffer.
1878  *
1879  */
spinel_decode_prop_nrf_802154_csl_writer_anchor_time_set(const void * p_property_data,size_t property_data_len)1880 static nrf_802154_ser_err_t spinel_decode_prop_nrf_802154_csl_writer_anchor_time_set(
1881     const void * p_property_data,
1882     size_t       property_data_len)
1883 {
1884     spinel_ssize_t siz;
1885     uint64_t       csl_anchor_time;
1886 
1887     siz = spinel_datatype_unpack(p_property_data,
1888                                  property_data_len,
1889                                  SPINEL_DATATYPE_NRF_802154_CSL_WRITER_ANCHOR_TIME_SET,
1890                                  &csl_anchor_time);
1891     if (siz < 0)
1892     {
1893         return NRF_802154_SERIALIZATION_ERROR_DECODING_FAILURE;
1894     }
1895 
1896     nrf_802154_csl_writer_anchor_time_set(csl_anchor_time);
1897 
1898     return nrf_802154_spinel_send_prop_last_status_is(SPINEL_STATUS_OK);
1899 }
1900 
1901 #endif // NRF_802154_DELAYED_TRX_ENABLED && NRF_802154_IE_WRITER_ENABLED
1902 
nrf_802154_spinel_decode_cmd_prop_value_set(const void * p_cmd_data,size_t cmd_data_len)1903 nrf_802154_ser_err_t nrf_802154_spinel_decode_cmd_prop_value_set(const void * p_cmd_data,
1904                                                                  size_t       cmd_data_len)
1905 {
1906     spinel_prop_key_t property;
1907     const void      * p_property_data;
1908     size_t            property_data_len;
1909     spinel_ssize_t    siz;
1910 
1911     siz = spinel_datatype_unpack(p_cmd_data,
1912                                  cmd_data_len,
1913                                  SPINEL_DATATYPE_UINT_PACKED_S SPINEL_DATATYPE_DATA_S,
1914                                  &property,
1915                                  &p_property_data,
1916                                  &property_data_len);
1917 
1918     if (siz < 0)
1919     {
1920         return NRF_802154_SERIALIZATION_ERROR_DECODING_FAILURE;
1921     }
1922 
1923     switch (property)
1924     {
1925         case SPINEL_PROP_VENDOR_NORDIC_NRF_802154_SLEEP:
1926             return spinel_decode_prop_nrf_802154_sleep(p_property_data, property_data_len);
1927 
1928         case SPINEL_PROP_VENDOR_NORDIC_NRF_802154_SLEEP_IF_IDLE:
1929             return spinel_decode_prop_nrf_802154_sleep_if_idle(p_property_data, property_data_len);
1930 
1931         case SPINEL_PROP_VENDOR_NORDIC_NRF_802154_RECEIVE:
1932             return spinel_decode_prop_nrf_802154_receive(p_property_data, property_data_len);
1933 
1934 #if NRF_802154_DELAYED_TRX_ENABLED
1935         case SPINEL_PROP_VENDOR_NORDIC_NRF_802154_RECEIVE_AT:
1936             return spinel_decode_prop_nrf_802154_receive_at(p_property_data, property_data_len);
1937 
1938         case SPINEL_PROP_VENDOR_NORDIC_NRF_802154_RECEIVE_AT_CANCEL:
1939             return spinel_decode_prop_nrf_802154_receive_at_cancel(p_property_data,
1940                                                                    property_data_len);
1941 
1942 #endif // NRF_802154_DELAYED_TRX_ENABLED
1943         case SPINEL_PROP_VENDOR_NORDIC_NRF_802154_CHANNEL_GET:
1944             return spinel_decode_prop_nrf_802154_channel_get(p_property_data, property_data_len);
1945 
1946         case SPINEL_PROP_VENDOR_NORDIC_NRF_802154_CHANNEL_SET:
1947             return spinel_decode_prop_nrf_802154_channel_set(p_property_data, property_data_len);
1948 
1949         case SPINEL_PROP_VENDOR_NORDIC_NRF_802154_AUTO_PENDING_BIT_SET:
1950             return spinel_decode_prop_nrf_802154_auto_pending_bit_set(p_property_data,
1951                                                                       property_data_len);
1952 
1953         case SPINEL_PROP_VENDOR_NORDIC_NRF_802154_PENDING_BIT_FOR_ADDR_SET:
1954             return spinel_decode_prop_nrf_802154_pending_bit_for_addr_set(p_property_data,
1955                                                                           property_data_len);
1956 
1957         case SPINEL_PROP_VENDOR_NORDIC_NRF_802154_PENDING_BIT_FOR_ADDR_CLEAR:
1958             return spinel_decode_prop_nrf_802154_pending_bit_for_addr_clear(p_property_data,
1959                                                                             property_data_len);
1960 
1961         case SPINEL_PROP_VENDOR_NORDIC_NRF_802154_PENDING_BIT_FOR_ADDR_RESET:
1962             return spinel_decode_prop_nrf_802154_pending_bit_for_addr_reset(p_property_data,
1963                                                                             property_data_len);
1964 
1965         case SPINEL_PROP_VENDOR_NORDIC_NRF_802154_SRC_ADDR_MATCHING_METHOD_SET:
1966             return spinel_decode_prop_nrf_802154_src_addr_matching_method_set(p_property_data,
1967                                                                               property_data_len);
1968 
1969         case SPINEL_PROP_VENDOR_NORDIC_NRF_802154_PAN_ID_SET:
1970             return spinel_decode_prop_nrf_802154_pan_id_set(p_property_data, property_data_len);
1971 
1972         case SPINEL_PROP_VENDOR_NORDIC_NRF_802154_SHORT_ADDRESS_SET:
1973             return spinel_decode_prop_nrf_802154_short_address_set(p_property_data,
1974                                                                    property_data_len);
1975 
1976         case SPINEL_PROP_VENDOR_NORDIC_NRF_802154_EXTENDED_ADDRESS_SET:
1977             return spinel_decode_prop_nrf_802154_extended_address_set(p_property_data,
1978                                                                       property_data_len);
1979 
1980         case SPINEL_PROP_VENDOR_NORDIC_NRF_802154_PAN_COORD_SET:
1981             return spinel_decode_prop_nrf_802154_pan_coord_set(p_property_data, property_data_len);
1982 #if NRF_802154_PAN_COORD_GET_ENABLED
1983 
1984         case SPINEL_PROP_VENDOR_NORDIC_NRF_802154_PAN_COORD_GET:
1985             return spinel_decode_prop_nrf_802154_pan_coord_get(p_property_data, property_data_len);
1986 
1987 #endif // NRF_802154_PAN_COORD_GET_ENABLED
1988 
1989         case SPINEL_PROP_VENDOR_NORDIC_NRF_802154_PROMISCUOUS_SET:
1990             return spinel_decode_prop_nrf_802154_promiscuous_set(p_property_data,
1991                                                                  property_data_len);
1992 
1993         case SPINEL_PROP_VENDOR_NORDIC_NRF_802154_RX_ON_WHEN_IDLE_SET:
1994             return spinel_decode_prop_nrf_802154_rx_on_when_idle_set(p_property_data,
1995                                                                      property_data_len);
1996 
1997         case SPINEL_PROP_VENDOR_NORDIC_NRF_802154_CCA:
1998             return spinel_decode_prop_nrf_802154_cca(p_property_data, property_data_len);
1999 
2000 #if NRF_802154_CARRIER_FUNCTIONS_ENABLED
2001 
2002         case SPINEL_PROP_VENDOR_NORDIC_NRF_802154_CONTINUOUS_CARRIER:
2003             return spinel_decode_prop_nrf_802154_continuous_carrier(p_property_data,
2004                                                                     property_data_len);
2005 
2006         case SPINEL_PROP_VENDOR_NORDIC_NRF_802154_MODULATED_CARRIER:
2007             return spinel_decode_prop_nrf_802154_modulated_carrier(p_property_data,
2008                                                                    property_data_len);
2009 
2010 #endif // NRF_802154_CARRIER_FUNCTIONS_ENABLED
2011 
2012         case SPINEL_PROP_VENDOR_NORDIC_NRF_802154_ENERGY_DETECTION:
2013             return spinel_decode_prop_nrf_802154_energy_detection(p_property_data,
2014                                                                   property_data_len);
2015 
2016         case SPINEL_PROP_VENDOR_NORDIC_NRF_802154_TX_POWER_SET:
2017             return spinel_decode_prop_nrf_802154_tx_power_set(p_property_data, property_data_len);
2018 
2019         case SPINEL_PROP_VENDOR_NORDIC_NRF_802154_TX_POWER_GET:
2020             return spinel_decode_prop_nrf_802154_tx_power_get(p_property_data, property_data_len);
2021 
2022 #if NRF_802154_CSMA_CA_ENABLED
2023         case SPINEL_PROP_VENDOR_NORDIC_NRF_802154_TRANSMIT_CSMA_CA_RAW:
2024             return spinel_decode_prop_nrf_802154_transmit_csma_ca_raw(p_property_data,
2025                                                                       property_data_len);
2026 
2027         case SPINEL_PROP_VENDOR_NORDIC_NRF_802154_CSMA_CA_MIN_BE_SET:
2028             return spinel_decode_prop_nrf_802154_csma_ca_min_be_set(p_property_data,
2029                                                                     property_data_len);
2030 
2031         case SPINEL_PROP_VENDOR_NORDIC_NRF_802154_CSMA_CA_MIN_BE_GET:
2032             return spinel_decode_prop_nrf_802154_csma_ca_min_be_get(p_property_data,
2033                                                                     property_data_len);
2034 
2035         case SPINEL_PROP_VENDOR_NORDIC_NRF_802154_CSMA_CA_MAX_BE_SET:
2036             return spinel_decode_prop_nrf_802154_csma_ca_max_be_set(p_property_data,
2037                                                                     property_data_len);
2038 
2039         case SPINEL_PROP_VENDOR_NORDIC_NRF_802154_CSMA_CA_MAX_BE_GET:
2040             return spinel_decode_prop_nrf_802154_csma_ca_max_be_get(p_property_data,
2041                                                                     property_data_len);
2042 
2043         case SPINEL_PROP_VENDOR_NORDIC_NRF_802154_CSMA_CA_MAX_BACKOFFS_SET:
2044             return spinel_decode_prop_nrf_802154_csma_ca_max_backoffs_set(p_property_data,
2045                                                                           property_data_len);
2046 
2047         case SPINEL_PROP_VENDOR_NORDIC_NRF_802154_CSMA_CA_MAX_BACKOFFS_GET:
2048             return spinel_decode_prop_nrf_802154_csma_ca_max_backoffs_get(p_property_data,
2049                                                                           property_data_len);
2050 #endif // NRF_802154_CSMA_CA_ENABLED
2051 
2052 #if NRF_802154_TEST_MODES_ENABLED
2053         case SPINEL_PROP_VENDOR_NORDIC_NRF_802154_TEST_MODE_CSMACA_BACKOFF_SET:
2054             return spinel_decode_prop_nrf_802154_test_mode_csmaca_backoff_set(p_property_data,
2055                                                                               property_data_len);
2056 
2057         case SPINEL_PROP_VENDOR_NORDIC_NRF_802154_TEST_MODE_CSMACA_BACKOFF_GET:
2058             return spinel_decode_prop_nrf_802154_test_mode_csmaca_backoff_get(p_property_data,
2059                                                                               property_data_len);
2060 #endif // NRF_802154_TEST_MODES_ENABLED
2061 
2062 #if NRF_802154_IFS_ENABLED
2063         case SPINEL_PROP_VENDOR_NORDIC_NRF_802154_IFS_MODE_SET:
2064             return spinel_decode_prop_nrf_802154_ifs_mode_set(p_property_data,
2065                                                               property_data_len);
2066 
2067         case SPINEL_PROP_VENDOR_NORDIC_NRF_802154_IFS_MODE_GET:
2068             return spinel_decode_prop_nrf_802154_ifs_mode_get(p_property_data,
2069                                                               property_data_len);
2070 
2071         case SPINEL_PROP_VENDOR_NORDIC_NRF_802154_IFS_MIN_SIFS_PERIOD_SET:
2072             return spinel_decode_prop_nrf_802154_ifs_min_sifs_period_set(p_property_data,
2073                                                                          property_data_len);
2074 
2075         case SPINEL_PROP_VENDOR_NORDIC_NRF_802154_IFS_MIN_SIFS_PERIOD_GET:
2076             return spinel_decode_prop_nrf_802154_ifs_min_sifs_period_get(p_property_data,
2077                                                                          property_data_len);
2078 
2079         case SPINEL_PROP_VENDOR_NORDIC_NRF_802154_IFS_MIN_LIFS_PERIOD_SET:
2080             return spinel_decode_prop_nrf_802154_ifs_min_lifs_period_set(p_property_data,
2081                                                                          property_data_len);
2082 
2083         case SPINEL_PROP_VENDOR_NORDIC_NRF_802154_IFS_MIN_LIFS_PERIOD_GET:
2084             return spinel_decode_prop_nrf_802154_ifs_min_lifs_period_get(p_property_data,
2085                                                                          property_data_len);
2086 
2087 #endif // NRF_802154_IFS_ENABLED
2088 
2089         case SPINEL_PROP_VENDOR_NORDIC_NRF_802154_TRANSMIT_RAW:
2090             return spinel_decode_prop_nrf_802154_transmit_raw(p_property_data, property_data_len);
2091 
2092 #if NRF_802154_DELAYED_TRX_ENABLED
2093         case SPINEL_PROP_VENDOR_NORDIC_NRF_802154_TRANSMIT_RAW_AT:
2094             return spinel_decode_prop_nrf_802154_transmit_raw_at(p_property_data,
2095                                                                  property_data_len);
2096 
2097         case SPINEL_PROP_VENDOR_NORDIC_NRF_802154_TRANSMIT_AT_CANCEL:
2098             return spinel_decode_prop_nrf_802154_transmit_at_cancel(p_property_data,
2099                                                                     property_data_len);
2100 
2101 #endif // NRF_802154_DELAYED_TRX_ENABLED
2102         case SPINEL_PROP_VENDOR_NORDIC_NRF_802154_BUFFER_FREE_RAW:
2103             return spinel_decode_prop_nrf_802154_buffer_free_raw(p_property_data,
2104                                                                  property_data_len);
2105 
2106         case SPINEL_PROP_VENDOR_NORDIC_NRF_802154_CAPABILITIES_GET:
2107             return spinel_decode_prop_nrf_802154_capabilities_get(p_property_data,
2108                                                                   property_data_len);
2109 
2110         case SPINEL_PROP_VENDOR_NORDIC_NRF_802154_TIME_GET:
2111             return spinel_decode_prop_nrf_802154_time_get(p_property_data,
2112                                                           property_data_len);
2113 
2114         case SPINEL_PROP_VENDOR_NORDIC_NRF_802154_CCA_CFG_GET:
2115             return spinel_decode_prop_nrf_802154_cca_cfg_get(p_property_data, property_data_len);
2116 
2117         case SPINEL_PROP_VENDOR_NORDIC_NRF_802154_CCA_CFG_SET:
2118             return spinel_decode_prop_nrf_802154_cca_cfg_set(p_property_data, property_data_len);
2119 
2120         case SPINEL_PROP_VENDOR_NORDIC_NRF_802154_ACK_DATA_SET:
2121             return spinel_decode_prop_nrf_802154_ack_data_set(p_property_data,
2122                                                               property_data_len);
2123 
2124         case SPINEL_PROP_VENDOR_NORDIC_NRF_802154_ACK_DATA_CLEAR:
2125             return spinel_decode_prop_nrf_802154_ack_data_clear(p_property_data,
2126                                                                 property_data_len);
2127 
2128         case SPINEL_PROP_VENDOR_NORDIC_NRF_802154_ACK_DATA_REMOVE_ALL:
2129             return spinel_decode_prop_nrf_802154_ack_data_remove_all(p_property_data,
2130                                                                      property_data_len);
2131 
2132         case SPINEL_PROP_VENDOR_NORDIC_NRF_802154_SECURITY_GLOBAL_FRAME_COUNTER_SET:
2133             return spinel_decode_prop_nrf_802154_security_global_frame_counter_set(p_property_data,
2134                                                                                    property_data_len);
2135 
2136         case SPINEL_PROP_VENDOR_NORDIC_NRF_802154_SECURITY_KEY_STORE:
2137             return spinel_decode_prop_nrf_802154_security_key_store(p_property_data,
2138                                                                     property_data_len);
2139 
2140         case SPINEL_PROP_VENDOR_NORDIC_NRF_802154_SECURITY_KEY_REMOVE:
2141             return spinel_decode_prop_nrf_802154_security_key_remove(p_property_data,
2142                                                                      property_data_len);
2143 
2144         case SPINEL_PROP_VENDOR_NORDIC_NRF_802154_SECURITY_KEY_REMOVE_ALL:
2145             return spinel_decode_prop_nrf_802154_security_key_remove_all(p_property_data,
2146                                                                          property_data_len);
2147 
2148 #if NRF_802154_DELAYED_TRX_ENABLED && NRF_802154_IE_WRITER_ENABLED
2149         case SPINEL_PROP_VENDOR_NORDIC_NRF_802154_CSL_WRITER_PERIOD_SET:
2150             return spinel_decode_prop_nrf_802154_csl_writer_period_set(p_property_data,
2151                                                                        property_data_len);
2152 
2153         case SPINEL_PROP_VENDOR_NORDIC_NRF_802154_CSL_WRITER_ANCHOR_TIME_SET:
2154             return spinel_decode_prop_nrf_802154_csl_writer_anchor_time_set(p_property_data,
2155                                                                             property_data_len);
2156 #endif // NRF_802154_DELAYED_TRX_ENABLED && NRF_802154_IE_WRITER_ENABLED
2157 
2158         case SPINEL_PROP_VENDOR_NORDIC_NRF_802154_STAT_TIMESTAMPS_GET:
2159             return spinel_decode_prop_nrf_802154_stat_timestamps_get(p_property_data,
2160                                                                      property_data_len);
2161 
2162         case SPINEL_PROP_VENDOR_NORDIC_NRF_802154_SECURITY_GLOBAL_FRAME_COUNTER_SET_IF_LARGER:
2163             return spinel_decode_prop_nrf_802154_security_global_frame_counter_set_if_larger(
2164                 p_property_data,
2165                 property_data_len);
2166 
2167         default:
2168             NRF_802154_SPINEL_LOG_RAW("Unsupported property: %s(%u)\n",
2169                                       spinel_prop_key_to_cstr(property),
2170                                       property);
2171             return NRF_802154_SERIALIZATION_ERROR_DECODING_FAILURE;
2172 
2173     }
2174 }
2175 
nrf_802154_spinel_dispatch_cmd(spinel_command_t cmd,const void * p_cmd_data,size_t cmd_data_len)2176 nrf_802154_ser_err_t nrf_802154_spinel_dispatch_cmd(spinel_command_t cmd,
2177                                                     const void     * p_cmd_data,
2178                                                     size_t           cmd_data_len)
2179 {
2180     switch (cmd)
2181     {
2182         case SPINEL_CMD_PROP_VALUE_SET:
2183             return nrf_802154_spinel_decode_cmd_prop_value_set(p_cmd_data, cmd_data_len);
2184 
2185         default:
2186             NRF_802154_SPINEL_LOG_RAW("Unsupported command: %s(%u)\n",
2187                                       spinel_command_to_cstr(cmd),
2188                                       cmd);
2189             return NRF_802154_SERIALIZATION_ERROR_DECODING_FAILURE;
2190     }
2191 }
2192