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