-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
spinel.h
4141 lines (3740 loc) · 158 KB
/
spinel.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 2016, The OpenThread Authors.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @file
* This file contains definitions of spinel.
*/
#ifndef SPINEL_HEADER_INCLUDED
#define SPINEL_HEADER_INCLUDED 1
/*
* Spinel is a host-controller protocol designed to enable
* inter-operation over simple serial connections between general purpose
* device operating systems (OS) host and network co-processors (NCP) for
* the purpose of controlling and managing the NCP.
*
* ---------------------------------------------------------------------------
*
* Frame Format
*
* A frame is defined simply as the concatenation of
*
* - A header byte
* - A command (up to three bytes)
* - An optional command payload
*
* +---------+--------+-----+-------------+
* | Octets: | 1 | 1-3 | n |
* +---------+--------+-----+-------------+
* | Fields: | HEADER | CMD | CMD_PAYLOAD |
* +---------+--------+-----+-------------+
*
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*
* Header Format
*
* The header byte is broken down as follows:
*
* 0 1 2 3 4 5 6 7
* +---+---+---+---+---+---+---+---+
* | FLG | IID | TID |
* +---+---+---+---+---+---+---+---+
*
*
* The flag field of the header byte ("FLG") is always set to the value
* two (or "10" in binary). Any frame received with these bits set to
* any other value else MUST NOT be considered a Spinel frame.
*
* This convention allows Spinel to be line compatible with BTLE HCI.
* By defining the first two bit in this way we can disambiguate between
* Spinel frames and HCI frames (which always start with either "0x01"
* or "0x04") without any additional framing overhead.
*
* The Interface Identifier (IID) is a number between 0 and 3, which
* is associated by the OS with a specific NCP. This allows the protocol
* to support up to 4 NCPs under same connection.
*
* The least significant bits of the header represent the Transaction
* Identifier (TID). The TID is used for correlating responses to the
* commands which generated them.
*
* When a command is sent from the host, any reply to that command sent
* by the NCP will use the same value for the TID. When the host
* receives a frame that matches the TID of the command it sent, it can
* easily recognize that frame as the actual response to that command.
*
* The TID value of zero (0) is used for commands to which a correlated
* response is not expected or needed, such as for unsolicited update
* commands sent to the host from the NCP.
*
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*
* The command identifier is a 21-bit unsigned integer encoded in up to
* three bytes using the packed unsigned integer format described below.
* Depending on the semantics of the command in question, a payload MAY
* be included in the frame. The exact composition and length of the
* payload is defined by the command identifier.
*
* ---------------------------------------------------------------------------
*
* Data Packing
*
* Data serialization for properties is performed using a light-weight
* data packing format which was loosely inspired by D-Bus. The format
* of a serialization is defined by a specially formatted string.
*
* This packing format is used for notational convenience. While this
* string-based data-type format has been designed so that the strings
* may be directly used by a structured data parser, such a thing is not
* required to implement Spinel.
*
* Goals:
*
* - Be lightweight and favor direct representation of values.
* - Use an easily readable and memorable format string.
* - Support lists and structures.
* - Allow properties to be appended to structures while maintaining
* backward compatibility.
*
* Each primitive data-type has an ASCII character associated with it.
* Structures can be represented as strings of these characters. For
* example:
*
* - "C": A single unsigned byte.
* - "C6U": A single unsigned byte, followed by a 128-bit IPv6 address,
* followed by a zero-terminated UTF8 string.
* - "A(6)": An array of concatenated IPv6 addresses
*
* In each case, the data is represented exactly as described. For
* example, an array of 10 IPv6 address is stored as 160 bytes.
*
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*
* Primitive Types
*
* +----------+----------------------+---------------------------------+
* | Char | Name | Description |
* +----------+----------------------+---------------------------------+
* | "." | DATATYPE_VOID | Empty data type. Used |
* | | | internally. |
* | "b" | DATATYPE_BOOL | Boolean value. Encoded in |
* | | | 8-bits as either 0x00 or 0x01. |
* | | | All other values are illegal. |
* | "C" | DATATYPE_UINT8 | Unsigned 8-bit integer. |
* | "c" | DATATYPE_INT8 | Signed 8-bit integer. |
* | "S" | DATATYPE_UINT16 | Unsigned 16-bit integer. |
* | "s" | DATATYPE_INT16 | Signed 16-bit integer. |
* | "L" | DATATYPE_UINT32 | Unsigned 32-bit integer. |
* | "l" | DATATYPE_INT32 | Signed 32-bit integer. |
* | "i" | DATATYPE_UINT_PACKED | Packed Unsigned Integer. See |
* | | | description below |
* | "6" | DATATYPE_IPv6ADDR | IPv6 Address. (Big-endian) |
* | "E" | DATATYPE_EUI64 | EUI-64 Address. (Big-endian) |
* | "e" | DATATYPE_EUI48 | EUI-48 Address. (Big-endian) |
* | "D" | DATATYPE_DATA | Arbitrary data. See related |
* | | | section below for details. |
* | "d" | DATATYPE_DATA_WLEN | Arbitrary data with prepended |
* | | | length. See below for details |
* | "U" | DATATYPE_UTF8 | Zero-terminated UTF8-encoded |
* | | | string. |
* | "t(...)" | DATATYPE_STRUCT | Structured datatype with |
* | | | prepended length. |
* | "A(...)" | DATATYPE_ARRAY | Array of datatypes. Compound |
* | | | type. |
* +----------+----------------------+---------------------------------+
*
* All multi-byte values are little-endian unless explicitly stated
* otherwise.
*
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*
* Packed Unsigned Integer
*
* For certain types of integers, such command or property identifiers,
* usually have a value on the wire that is less than 127. However, in
* order to not preclude the use of values larger than 255, we would
* need to add an extra byte. Doing this would add an extra byte to the
* majority of instances, which can add up in terms of bandwidth.
*
* The packed unsigned integer format is based on the unsigned integer
* format in EXI, except that we limit the maximum value to the
* largest value that can be encoded into three bytes (2,097,151).
*
* For all values less than 127, the packed form of the number is simply
* a single byte which directly represents the number. For values
* larger than 127, the following process is used to encode the value:
*
* 1. The unsigned integer is broken up into _n_ 7-bit chunks and
* placed into _n_ octets, leaving the most significant bit of each
* octet unused.
* 2. Order the octets from least-significant to most-significant.
* (Little-endian)
* 3. Clear the most significant bit of the most significant octet.
* Set the least significant bit on all other octets.
*
* Where `n` is the smallest number of 7-bit chunks you can use to
* represent the given value.
*
* Take the value 1337, for example:
*
* 1337 => 0x0539
* => [39 0A]
* => [B9 0A]
*
* To decode the value, you collect the 7-bit chunks until you find an
* octet with the most significant bit clear.
*
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*
* Data Blobs
*
* There are two types for data blobs: "d" and "D".
*
* - "d" has the length of the data (in bytes) prepended to the data
* (with the length encoded as type "S"). The size of the length
* field is not included in the length.
* - "D" does not have a prepended length: the length of the data is
* implied by the bytes remaining to be parsed. It is an error for
* "D" to not be the last type in a type in a type signature.
*
* This dichotomy allows for more efficient encoding by eliminating
* redundancy. If the rest of the buffer is a data blob, encoding the
* length would be redundant because we already know how many bytes are
* in the rest of the buffer.
*
* In some cases we use "d" even if it is the last field in a type
* signature. We do this to allow for us to be able to append
* additional fields to the type signature if necessary in the future.
* This is usually the case with embedded structs, like in the scan
* results.
*
* For example, let's say we have a buffer that is encoded with the
* datatype signature of "CLLD". In this case, it is pretty easy to
* tell where the start and end of the data blob is: the start is 9
* bytes from the start of the buffer, and its length is the length of
* the buffer minus 9. (9 is the number of bytes taken up by a byte and
* two longs)
*
* The datatype signature "CLLDU" is illegal because we can't determine
* where the last field (a zero-terminated UTF8 string) starts. But the
* datatype "CLLdU" is legal, because the parser can determine the
* exact length of the data blob-- allowing it to know where the start
* of the next field would be.
*
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*
* Structured Data
*
* The structure data type ("t(...)") is a way of bundling together
* several fields into a single structure. It can be thought of as a
* "d" type except that instead of being opaque, the fields in the
* content are known. This is useful for things like scan results where
* you have substructures which are defined by different layers.
*
* For example, consider the type signature "Lt(ES)t(6C)". In this
* hypothetical case, the first struct is defined by the MAC layer, and
* the second struct is defined by the PHY layer. Because of the use of
* structures, we know exactly what part comes from that layer.
* Additionally, we can add fields to each structure without introducing
* backward compatability problems: Data encoded as "Lt(ESU)t(6C)"
* (Notice the extra "U") will decode just fine as "Lt(ES)t(6C)".
* Additionally, if we don't care about the MAC layer and only care
* about the network layer, we could parse as "Lt()t(6C)".
*
* Note that data encoded as "Lt(ES)t(6C)" will also parse as "Ldd",
* with the structures from both layers now being opaque data blobs.
*
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*
* Arrays
*
* An array is simply a concatenated set of _n_ data encodings. For
* example, the type "A(6)" is simply a list of IPv6 addresses---one
* after the other. The type "A(6E)" likewise a concatenation of IPv6-
* address/EUI-64 pairs.
*
* If an array contains many fields, the fields will often be surrounded
* by a structure ("t(...)"). This effectively prepends each item in
* the array with its length. This is useful for improving parsing
* performance or to allow additional fields to be added in the future
* in a backward compatible way. If there is a high certainty that
* additional fields will never be added, the struct may be omitted
* (saving two bytes per item).
*
* This specification does not define a way to embed an array as a field
* alongside other fields.
*
* ---------------------------------------------------------------------------
*
* Spinel definition guideline:
*
* New NCP firmware should work with an older host driver, i.e., NCP
* implementation should remain backward compatible.
*
* - Existing fields in the format of an already implemented spinel
* property or command cannot change.
*
* - New fields may be appended at the end of the format (or the end of
* a struct) as long as the NCP implementation treats the new fields as
* optional (i.e., a driver not aware of and therefore not using the
* new fields should continue to function as before).
*
* ---------------------------------------------------------------------------
*/
#ifdef SPINEL_PLATFORM_HEADER
#include SPINEL_PLATFORM_HEADER
#else // ifdef SPINEL_PLATFORM_HEADER
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#endif // else SPINEL_PLATFORM_HEADER
// ----------------------------------------------------------------------------
#ifndef DOXYGEN_SHOULD_SKIP_THIS
#if defined(__GNUC__)
#define SPINEL_API_EXTERN extern __attribute__((visibility("default")))
#define SPINEL_API_NONNULL_ALL __attribute__((nonnull))
#define SPINEL_API_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
#endif // ifdef __GNUC__
#endif // ifndef DOXYGEN_SHOULD_SKIP_THIS
#ifndef SPINEL_API_EXTERN
#define SPINEL_API_EXTERN extern
#endif
#ifndef SPINEL_API_NONNULL_ALL
#define SPINEL_API_NONNULL_ALL
#endif
#ifndef SPINEL_API_WARN_UNUSED_RESULT
#define SPINEL_API_WARN_UNUSED_RESULT
#endif
// ----------------------------------------------------------------------------
#define SPINEL_PROTOCOL_VERSION_THREAD_MAJOR 4
#define SPINEL_PROTOCOL_VERSION_THREAD_MINOR 3
#define SPINEL_FRAME_MAX_SIZE 1300
/**
* @def SPINEL_ENCRYPTER_EXTRA_DATA_SIZE
*
* The size of extra data to be allocated for spinel frame buffer,
* needed by Spinel Encrypter.
*
*/
#define SPINEL_ENCRYPTER_EXTRA_DATA_SIZE 0
/**
* @def SPINEL_FRAME_BUFFER_SIZE
*
* The size of buffer large enough to fit one whole spinel frame with extra data
* needed by Spinel Encrypter.
*
*/
#define SPINEL_FRAME_BUFFER_SIZE (SPINEL_FRAME_MAX_SIZE + SPINEL_ENCRYPTER_EXTRA_DATA_SIZE)
/// Macro for generating bit masks using bit index from the spec
#define SPINEL_BIT_MASK(bit_index, field_bit_count) ((1 << ((field_bit_count)-1)) >> (bit_index))
// ----------------------------------------------------------------------------
#if defined(__cplusplus)
extern "C" {
#endif
enum
{
SPINEL_STATUS_OK = 0, ///< Operation has completed successfully.
SPINEL_STATUS_FAILURE = 1, ///< Operation has failed for some undefined reason.
SPINEL_STATUS_UNIMPLEMENTED = 2, ///< Given operation has not been implemented.
SPINEL_STATUS_INVALID_ARGUMENT = 3, ///< An argument to the operation is invalid.
SPINEL_STATUS_INVALID_STATE = 4, ///< This operation is invalid for the current device state.
SPINEL_STATUS_INVALID_COMMAND = 5, ///< This command is not recognized.
SPINEL_STATUS_INVALID_INTERFACE = 6, ///< This interface is not supported.
SPINEL_STATUS_INTERNAL_ERROR = 7, ///< An internal runtime error has occurred.
SPINEL_STATUS_SECURITY_ERROR = 8, ///< A security/authentication error has occurred.
SPINEL_STATUS_PARSE_ERROR = 9, ///< A error has occurred while parsing the command.
SPINEL_STATUS_IN_PROGRESS = 10, ///< This operation is in progress.
SPINEL_STATUS_NOMEM = 11, ///< Operation prevented due to memory pressure.
SPINEL_STATUS_BUSY = 12, ///< The device is currently performing a mutually exclusive operation
SPINEL_STATUS_PROP_NOT_FOUND = 13, ///< The given property is not recognized.
SPINEL_STATUS_DROPPED = 14, ///< A/The packet was dropped.
SPINEL_STATUS_EMPTY = 15, ///< The result of the operation is empty.
SPINEL_STATUS_CMD_TOO_BIG = 16, ///< The command was too large to fit in the internal buffer.
SPINEL_STATUS_NO_ACK = 17, ///< The packet was not acknowledged.
SPINEL_STATUS_CCA_FAILURE = 18, ///< The packet was not sent due to a CCA failure.
SPINEL_STATUS_ALREADY = 19, ///< The operation is already in progress.
SPINEL_STATUS_ITEM_NOT_FOUND = 20, ///< The given item could not be found.
SPINEL_STATUS_INVALID_COMMAND_FOR_PROP = 21, ///< The given command cannot be performed on this property.
SPINEL_STATUS_JOIN__BEGIN = 104,
/// Generic failure to associate with other peers.
/**
* This status error should not be used by implementors if
* enough information is available to determine that one of the
* later join failure status codes would be more accurate.
*
* \sa SPINEL_PROP_NET_REQUIRE_JOIN_EXISTING
* \sa SPINEL_PROP_MESHCOP_JOINER_COMMISSIONING
*/
SPINEL_STATUS_JOIN_FAILURE = SPINEL_STATUS_JOIN__BEGIN + 0,
/// The node found other peers but was unable to decode their packets.
/**
* Typically this error code indicates that the network
* key has been set incorrectly.
*
* \sa SPINEL_PROP_NET_REQUIRE_JOIN_EXISTING
* \sa SPINEL_PROP_MESHCOP_JOINER_COMMISSIONING
*/
SPINEL_STATUS_JOIN_SECURITY = SPINEL_STATUS_JOIN__BEGIN + 1,
/// The node was unable to find any other peers on the network.
/**
* \sa SPINEL_PROP_NET_REQUIRE_JOIN_EXISTING
* \sa SPINEL_PROP_MESHCOP_JOINER_COMMISSIONING
*/
SPINEL_STATUS_JOIN_NO_PEERS = SPINEL_STATUS_JOIN__BEGIN + 2,
/// The only potential peer nodes found are incompatible.
/**
* \sa SPINEL_PROP_NET_REQUIRE_JOIN_EXISTING
*/
SPINEL_STATUS_JOIN_INCOMPATIBLE = SPINEL_STATUS_JOIN__BEGIN + 3,
/// No response in expecting time.
/**
* \sa SPINEL_PROP_MESHCOP_JOINER_COMMISSIONING
*/
SPINEL_STATUS_JOIN_RSP_TIMEOUT = SPINEL_STATUS_JOIN__BEGIN + 4,
/// The node succeeds in commissioning and get the network credentials.
/**
* \sa SPINEL_PROP_MESHCOP_JOINER_COMMISSIONING
*/
SPINEL_STATUS_JOIN_SUCCESS = SPINEL_STATUS_JOIN__BEGIN + 5,
SPINEL_STATUS_JOIN__END = 112,
SPINEL_STATUS_RESET__BEGIN = 112,
SPINEL_STATUS_RESET_POWER_ON = SPINEL_STATUS_RESET__BEGIN + 0,
SPINEL_STATUS_RESET_EXTERNAL = SPINEL_STATUS_RESET__BEGIN + 1,
SPINEL_STATUS_RESET_SOFTWARE = SPINEL_STATUS_RESET__BEGIN + 2,
SPINEL_STATUS_RESET_FAULT = SPINEL_STATUS_RESET__BEGIN + 3,
SPINEL_STATUS_RESET_CRASH = SPINEL_STATUS_RESET__BEGIN + 4,
SPINEL_STATUS_RESET_ASSERT = SPINEL_STATUS_RESET__BEGIN + 5,
SPINEL_STATUS_RESET_OTHER = SPINEL_STATUS_RESET__BEGIN + 6,
SPINEL_STATUS_RESET_UNKNOWN = SPINEL_STATUS_RESET__BEGIN + 7,
SPINEL_STATUS_RESET_WATCHDOG = SPINEL_STATUS_RESET__BEGIN + 8,
SPINEL_STATUS_RESET__END = 128,
SPINEL_STATUS_VENDOR__BEGIN = 15360,
SPINEL_STATUS_VENDOR__END = 16384,
SPINEL_STATUS_STACK_NATIVE__BEGIN = 16384,
SPINEL_STATUS_STACK_NATIVE__END = 81920,
SPINEL_STATUS_EXPERIMENTAL__BEGIN = 2000000,
SPINEL_STATUS_EXPERIMENTAL__END = 2097152,
};
typedef uint32_t spinel_status_t;
typedef enum
{
SPINEL_NET_ROLE_DETACHED = 0,
SPINEL_NET_ROLE_CHILD = 1,
SPINEL_NET_ROLE_ROUTER = 2,
SPINEL_NET_ROLE_LEADER = 3,
} spinel_net_role_t;
typedef enum
{
SPINEL_IPV6_ICMP_PING_OFFLOAD_DISABLED = 0,
SPINEL_IPV6_ICMP_PING_OFFLOAD_UNICAST_ONLY = 1,
SPINEL_IPV6_ICMP_PING_OFFLOAD_MULTICAST_ONLY = 2,
SPINEL_IPV6_ICMP_PING_OFFLOAD_ALL = 3,
} spinel_ipv6_icmp_ping_offload_mode_t;
typedef enum
{
SPINEL_SCAN_STATE_IDLE = 0,
SPINEL_SCAN_STATE_BEACON = 1,
SPINEL_SCAN_STATE_ENERGY = 2,
SPINEL_SCAN_STATE_DISCOVER = 3,
} spinel_scan_state_t;
typedef enum
{
SPINEL_MCU_POWER_STATE_ON = 0,
SPINEL_MCU_POWER_STATE_LOW_POWER = 1,
SPINEL_MCU_POWER_STATE_OFF = 2,
} spinel_mcu_power_state_t;
// The `spinel_power_state_t` enumeration and `POWER_STATE`
// property are deprecated. Please use `MCU_POWER_STATE`
// instead.
typedef enum
{
SPINEL_POWER_STATE_OFFLINE = 0,
SPINEL_POWER_STATE_DEEP_SLEEP = 1,
SPINEL_POWER_STATE_STANDBY = 2,
SPINEL_POWER_STATE_LOW_POWER = 3,
SPINEL_POWER_STATE_ONLINE = 4,
} spinel_power_state_t;
typedef enum
{
SPINEL_HOST_POWER_STATE_OFFLINE = 0,
SPINEL_HOST_POWER_STATE_DEEP_SLEEP = 1,
SPINEL_HOST_POWER_STATE_RESERVED = 2,
SPINEL_HOST_POWER_STATE_LOW_POWER = 3,
SPINEL_HOST_POWER_STATE_ONLINE = 4,
} spinel_host_power_state_t;
typedef enum
{
SPINEL_MESHCOP_JOINER_STATE_IDLE = 0,
SPINEL_MESHCOP_JOINER_STATE_DISCOVER = 1,
SPINEL_MESHCOP_JOINER_STATE_CONNECTING = 2,
SPINEL_MESHCOP_JOINER_STATE_CONNECTED = 3,
SPINEL_MESHCOP_JOINER_STATE_ENTRUST = 4,
SPINEL_MESHCOP_JOINER_STATE_JOINED = 5,
} spinel_meshcop_joiner_state_t;
enum
{
SPINEL_NET_FLAG_ON_MESH = (1 << 0),
SPINEL_NET_FLAG_DEFAULT_ROUTE = (1 << 1),
SPINEL_NET_FLAG_CONFIGURE = (1 << 2),
SPINEL_NET_FLAG_DHCP = (1 << 3),
SPINEL_NET_FLAG_SLAAC = (1 << 4),
SPINEL_NET_FLAG_PREFERRED = (1 << 5),
SPINEL_NET_FLAG_PREFERENCE_OFFSET = 6,
SPINEL_NET_FLAG_PREFERENCE_MASK = (3 << SPINEL_NET_FLAG_PREFERENCE_OFFSET),
};
enum
{
SPINEL_ROUTE_PREFERENCE_HIGH = (1 << SPINEL_NET_FLAG_PREFERENCE_OFFSET),
SPINEL_ROUTE_PREFERENCE_MEDIUM = (0 << SPINEL_NET_FLAG_PREFERENCE_OFFSET),
SPINEL_ROUTE_PREFERENCE_LOW = (3 << SPINEL_NET_FLAG_PREFERENCE_OFFSET),
};
enum
{
SPINEL_THREAD_MODE_FULL_NETWORK_DATA = (1 << 0),
SPINEL_THREAD_MODE_FULL_THREAD_DEV = (1 << 1),
SPINEL_THREAD_MODE_SECURE_DATA_REQUEST = (1 << 2),
SPINEL_THREAD_MODE_RX_ON_WHEN_IDLE = (1 << 3),
};
enum
{
SPINEL_GPIO_FLAG_DIR_INPUT = 0,
SPINEL_GPIO_FLAG_DIR_OUTPUT = SPINEL_BIT_MASK(0, 8),
SPINEL_GPIO_FLAG_PULL_UP = SPINEL_BIT_MASK(1, 8),
SPINEL_GPIO_FLAG_PULL_DOWN = SPINEL_BIT_MASK(2, 8),
SPINEL_GPIO_FLAG_OPEN_DRAIN = SPINEL_BIT_MASK(2, 8),
SPINEL_GPIO_FLAG_TRIGGER_NONE = 0,
SPINEL_GPIO_FLAG_TRIGGER_RISING = SPINEL_BIT_MASK(3, 8),
SPINEL_GPIO_FLAG_TRIGGER_FALLING = SPINEL_BIT_MASK(4, 8),
SPINEL_GPIO_FLAG_TRIGGER_ANY = SPINEL_GPIO_FLAG_TRIGGER_RISING | SPINEL_GPIO_FLAG_TRIGGER_FALLING,
};
enum
{
SPINEL_PROTOCOL_TYPE_BOOTLOADER = 0,
SPINEL_PROTOCOL_TYPE_ZIGBEE_IP = 2,
SPINEL_PROTOCOL_TYPE_THREAD = 3,
};
enum
{
SPINEL_MAC_PROMISCUOUS_MODE_OFF = 0, ///< Normal MAC filtering is in place.
SPINEL_MAC_PROMISCUOUS_MODE_NETWORK = 1, ///< All MAC packets matching network are passed up the stack.
SPINEL_MAC_PROMISCUOUS_MODE_FULL = 2, ///< All decoded MAC packets are passed up the stack.
};
enum
{
SPINEL_NCP_LOG_LEVEL_EMERG = 0,
SPINEL_NCP_LOG_LEVEL_ALERT = 1,
SPINEL_NCP_LOG_LEVEL_CRIT = 2,
SPINEL_NCP_LOG_LEVEL_ERR = 3,
SPINEL_NCP_LOG_LEVEL_WARN = 4,
SPINEL_NCP_LOG_LEVEL_NOTICE = 5,
SPINEL_NCP_LOG_LEVEL_INFO = 6,
SPINEL_NCP_LOG_LEVEL_DEBUG = 7,
};
enum
{
SPINEL_NCP_LOG_REGION_NONE = 0,
SPINEL_NCP_LOG_REGION_OT_API = 1,
SPINEL_NCP_LOG_REGION_OT_MLE = 2,
SPINEL_NCP_LOG_REGION_OT_ARP = 3,
SPINEL_NCP_LOG_REGION_OT_NET_DATA = 4,
SPINEL_NCP_LOG_REGION_OT_ICMP = 5,
SPINEL_NCP_LOG_REGION_OT_IP6 = 6,
SPINEL_NCP_LOG_REGION_OT_MAC = 7,
SPINEL_NCP_LOG_REGION_OT_MEM = 8,
SPINEL_NCP_LOG_REGION_OT_NCP = 9,
SPINEL_NCP_LOG_REGION_OT_MESH_COP = 10,
SPINEL_NCP_LOG_REGION_OT_NET_DIAG = 11,
SPINEL_NCP_LOG_REGION_OT_PLATFORM = 12,
SPINEL_NCP_LOG_REGION_OT_COAP = 13,
SPINEL_NCP_LOG_REGION_OT_CLI = 14,
SPINEL_NCP_LOG_REGION_OT_CORE = 15,
SPINEL_NCP_LOG_REGION_OT_UTIL = 16,
};
enum
{
SPINEL_MESHCOP_COMMISSIONER_STATE_DISABLED = 0,
SPINEL_MESHCOP_COMMISSIONER_STATE_PETITION = 1,
SPINEL_MESHCOP_COMMISSIONER_STATE_ACTIVE = 2,
};
typedef struct
{
uint8_t bytes[8];
} spinel_eui64_t;
typedef struct
{
uint8_t bytes[8];
} spinel_net_xpanid_t;
typedef struct
{
uint8_t bytes[16];
} spinel_net_pskc_t;
typedef struct
{
uint8_t bytes[6];
} spinel_eui48_t;
typedef struct
{
uint8_t bytes[16];
} spinel_ipv6addr_t;
typedef int spinel_ssize_t;
typedef unsigned int spinel_size_t;
typedef uint8_t spinel_tid_t;
enum
{
SPINEL_MD_FLAG_TX = 0x0001, //!< Packet was transmitted, not received.
SPINEL_MD_FLAG_BAD_FCS = 0x0004, //!< Packet was received with bad FCS
SPINEL_MD_FLAG_DUPE = 0x0008, //!< Packet seems to be a duplicate
SPINEL_MD_FLAG_ACKED_FP = 0x0010, //!< Packet was acknowledged with frame pending set
SPINEL_MD_FLAG_RESERVED = 0xFFE2, //!< Flags reserved for future use.
};
enum
{
/**
* No-Operation command (Host -> NCP)
*
* Encoding: Empty
*
* Induces the NCP to send a success status back to the host. This is
* primarily used for liveliness checks. The command payload for this
* command SHOULD be empty.
*
* There is no error condition for this command.
*
*/
SPINEL_CMD_NOOP = 0,
/**
* Reset NCP command (Host -> NCP)
*
* Encoding: Empty
*
* Causes the NCP to perform a software reset. Due to the nature of
* this command, the TID is ignored. The host should instead wait
* for a `CMD_PROP_VALUE_IS` command from the NCP indicating
* `PROP_LAST_STATUS` has been set to `STATUS_RESET_SOFTWARE`.
*
* The command payload for this command SHOULD be empty.
*
* If an error occurs, the value of `PROP_LAST_STATUS` will be emitted
* instead with the value set to the generated status code for the error.
*
*/
SPINEL_CMD_RESET = 1,
/**
* Get property value command (Host -> NCP)
*
* Encoding: `i`
* `i` : Property Id
*
* Causes the NCP to emit a `CMD_PROP_VALUE_IS` command for the
* given property identifier.
*
* The payload for this command is the property identifier encoded
* in the packed unsigned integer format `i`.
*
* If an error occurs, the value of `PROP_LAST_STATUS` will be emitted
* instead with the value set to the generated status code for the error.
*
*/
SPINEL_CMD_PROP_VALUE_GET = 2,
/**
* Set property value command (Host -> NCP)
*
* Encoding: `iD`
* `i` : Property Id
* `D` : Value (encoding depends on the property)
*
* Instructs the NCP to set the given property to the specific given
* value, replacing any previous value.
*
* The payload for this command is the property identifier encoded in the
* packed unsigned integer format, followed by the property value. The
* exact format of the property value is defined by the property.
*
* On success a `CMD_PROP_VALUE_IS` command is emitted either for the
* given property identifier with the set value, or for `PROP_LAST_STATUS`
* with value `LAST_STATUS_OK`.
*
* If an error occurs, the value of `PROP_LAST_STATUS` will be emitted
* with the value set to the generated status code for the error.
*
*/
SPINEL_CMD_PROP_VALUE_SET = 3,
/**
* Insert value into property command (Host -> NCP)
*
* Encoding: `iD`
* `i` : Property Id
* `D` : Value (encoding depends on the property)
*
* Instructs the NCP to insert the given value into a list-oriented
* property without removing other items in the list. The resulting order
* of items in the list is defined by the individual property being
* operated on.
*
* The payload for this command is the property identifier encoded in the
* packed unsigned integer format, followed by the value to be inserted.
* The exact format of the value is defined by the property.
*
* If the type signature of the property consists of a single structure
* enclosed by an array `A(t(...))`, then the contents of value MUST
* contain the contents of the structure (`...`) rather than the
* serialization of the whole item (`t(...)`). Specifically, the length
* of the structure MUST NOT be prepended to value. This helps to
* eliminate redundant data.
*
* On success, either a `CMD_PROP_VALUE_INSERTED` command is emitted for
* the given property, or a `CMD_PROP_VALUE_IS` command is emitted of
* property `PROP_LAST_STATUS` with value `LAST_STATUS_OK`.
*
* If an error occurs, the value of `PROP_LAST_STATUS` will be emitted
* with the value set to the generated status code for the error.
*
*/
SPINEL_CMD_PROP_VALUE_INSERT = 4,
/**
* Remove value from property command (Host -> NCP)
*
* Encoding: `iD`
* `i` : Property Id
* `D` : Value (encoding depends on the property)
* Instructs the NCP to remove the given value from a list-oriented property,
* without affecting other items in the list. The resulting order of items
* in the list is defined by the individual property being operated on.
*
* Note that this command operates by value, not by index!
*
* The payload for this command is the property identifier encoded in the
* packed unsigned integer format, followed by the value to be removed. The
* exact format of the value is defined by the property.
*
* If the type signature of the property consists of a single structure
* enclosed by an array `A(t(...))`, then the contents of value MUST contain
* the contents of the structure (`...`) rather than the serialization of the
* whole item (`t(...)`). Specifically, the length of the structure MUST NOT
* be prepended to `VALUE`. This helps to eliminate redundant data.
*
* On success, either a `CMD_PROP_VALUE_REMOVED` command is emitted for the
* given property, or a `CMD_PROP_VALUE_IS` command is emitted of property
* `PROP_LAST_STATUS` with value `LAST_STATUS_OK`.
*
* If an error occurs, the value of `PROP_LAST_STATUS` will be emitted
* with the value set to the generated status code for the error.
*
*/
SPINEL_CMD_PROP_VALUE_REMOVE = 5,
/**
* Property value notification command (NCP -> Host)
*
* Encoding: `iD`
* `i` : Property Id
* `D` : Value (encoding depends on the property)
*
* This command can be sent by the NCP in response to a previous command
* from the host, or it can be sent by the NCP in an unsolicited fashion
* to notify the host of various state changes asynchronously.
*
* The payload for this command is the property identifier encoded in the
* packed unsigned integer format, followed by the current value of the
* given property.
*
*/
SPINEL_CMD_PROP_VALUE_IS = 6,
/**
* Property value insertion notification command (NCP -> Host)
*
* Encoding:`iD`
* `i` : Property Id
* `D` : Value (encoding depends on the property)
*
* This command can be sent by the NCP in response to the
* `CMD_PROP_VALUE_INSERT` command, or it can be sent by the NCP in an
* unsolicited fashion to notify the host of various state changes
* asynchronously.
*
* The payload for this command is the property identifier encoded in the
* packed unsigned integer format, followed by the value that was inserted
* into the given property.
*
* If the type signature of the property specified by property id consists
* of a single structure enclosed by an array (`A(t(...))`), then the
* contents of value MUST contain the contents of the structure (`...`)
* rather than the serialization of the whole item (`t(...)`). Specifically,
* the length of the structure MUST NOT be prepended to `VALUE`. This
* helps to eliminate redundant data.
*
* The resulting order of items in the list is defined by the given
* property.
*
*/
SPINEL_CMD_PROP_VALUE_INSERTED = 7,
/**
* Property value removal notification command (NCP -> Host)
*
* Encoding: `iD`
* `i` : Property Id
* `D` : Value (encoding depends on the property)
*
* This command can be sent by the NCP in response to the
* `CMD_PROP_VALUE_REMOVE` command, or it can be sent by the NCP in an
* unsolicited fashion to notify the host of various state changes
* asynchronously.
*
* Note that this command operates by value, not by index!
*
* The payload for this command is the property identifier encoded in the
* packed unsigned integer format described in followed by the value that
* was removed from the given property.
*
* If the type signature of the property specified by property id consists
* of a single structure enclosed by an array (`A(t(...))`), then the
* contents of value MUST contain the contents of the structure (`...`)
* rather than the serialization of the whole item (`t(...)`). Specifically,
* the length of the structure MUST NOT be prepended to `VALUE`. This
* helps to eliminate redundant data.
*
* The resulting order of items in the list is defined by the given
* property.
*
*/
SPINEL_CMD_PROP_VALUE_REMOVED = 8,
SPINEL_CMD_NET_SAVE = 9, // Deprecated
/**
* Clear saved network settings command (Host -> NCP)
*
* Encoding: Empty
*
* Erases all network credentials and state from non-volatile memory.
*
* This operation affects non-volatile memory only. The current network
* information stored in volatile memory is unaffected.
*
* The response to this command is always a `CMD_PROP_VALUE_IS` for
* `PROP_LAST_STATUS`, indicating the result of the operation.
*
*/
SPINEL_CMD_NET_CLEAR = 10,
SPINEL_CMD_NET_RECALL = 11, // Deprecated
/**
* Host buffer offload is an optional NCP capability that, when
* present, allows the NCP to store data buffers on the host processor
* that can be recalled at a later time.
*
* The presence of this feature can be detected by the host by
* checking for the presence of the `CAP_HBO`
* capability in `PROP_CAPS`.
*
* This feature is not currently supported on OpenThread.
*
*/
SPINEL_CMD_HBO_OFFLOAD = 12,
SPINEL_CMD_HBO_RECLAIM = 13,
SPINEL_CMD_HBO_DROP = 14,
SPINEL_CMD_HBO_OFFLOADED = 15,
SPINEL_CMD_HBO_RECLAIMED = 16,
SPINEL_CMD_HBO_DROPPED = 17,
/**
* Peek command (Host -> NCP)
*
* Encoding: `LU`
* `L` : The address to peek
* `U` : Number of bytes to read
*
* This command allows the NCP to fetch values from the RAM of the NCP
* for debugging purposes. Upon success, `CMD_PEEK_RET` is sent from the
* NCP to the host. Upon failure, `PROP_LAST_STATUS` is emitted with
* the appropriate error indication.
*
* The NCP MAY prevent certain regions of memory from being accessed.
*
* This command requires the capability `CAP_PEEK_POKE` to be present.
*
*/
SPINEL_CMD_PEEK = 18,
/**
* Peek return command (NCP -> Host)
*
* Encoding: `LUD`
* `L` : The address peeked
* `U` : Number of bytes read
* `D` : Memory content
*
* This command contains the contents of memory that was requested by
* a previous call to `CMD_PEEK`.
*
* This command requires the capability `CAP_PEEK_POKE` to be present.
*
*/
SPINEL_CMD_PEEK_RET = 19,
/**
* Poke command (Host -> NCP)
*
* Encoding: `LUD`
* `L` : The address to be poked
* `U` : Number of bytes to write
* `D` : Content to write
*
* This command writes the bytes to the specified memory address
* for debugging purposes.
*
* This command requires the capability `CAP_PEEK_POKE` to be present.
*
*/
SPINEL_CMD_POKE = 20,
SPINEL_CMD_PROP_VALUE_MULTI_GET = 21,
SPINEL_CMD_PROP_VALUE_MULTI_SET = 22,
SPINEL_CMD_PROP_VALUES_ARE = 23,
SPINEL_CMD_NEST__BEGIN = 15296,
SPINEL_CMD_NEST__END = 15360,
SPINEL_CMD_VENDOR__BEGIN = 15360,
SPINEL_CMD_VENDOR__END = 16384,
SPINEL_CMD_EXPERIMENTAL__BEGIN = 2000000,
SPINEL_CMD_EXPERIMENTAL__END = 2097152,
};
typedef uint32_t spinel_command_t;
enum
{
SPINEL_CAP_LOCK = 1,