forked from apache/mynewt-newtmgr
/
ble_proto.go
1643 lines (1393 loc) · 41.5 KB
/
ble_proto.go
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
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package nmble
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"strconv"
"strings"
. "mynewt.apache.org/newtmgr/nmxact/bledefs"
)
type MsgOp int
type MsgType int
type BleSeq uint32
type BleBytes struct {
Bytes []byte
}
const BLE_CONN_HANDLE_NONE uint16 = 0xffff
const BLE_SEQ_MIN BleSeq = 0
const BLE_SEQ_EVT_MIN BleSeq = 0xffffff00
const BLE_SEQ_NONE BleSeq = 0xffffffff
const ERR_CODE_ATT_BASE = 0x100
const ERR_CODE_HCI_BASE = 0x200
const ERR_CODE_L2C_BASE = 0x300
const ERR_CODE_SM_US_BASE = 0x400
const ERR_CODE_SM_PEER_BASE = 0x500
const (
ERR_CODE_EAGAIN int = 1
ERR_CODE_EALREADY = 2
ERR_CODE_EINVAL = 3
ERR_CODE_EMSGSIZE = 4
ERR_CODE_ENOENT = 5
ERR_CODE_ENOMEM = 6
ERR_CODE_ENOTCONN = 7
ERR_CODE_ENOTSUP = 8
ERR_CODE_EAPP = 9
ERR_CODE_EBADDATA = 10
ERR_CODE_EOS = 11
ERR_CODE_ECONTROLLER = 12
ERR_CODE_ETIMEOUT = 13
ERR_CODE_EDONE = 14
ERR_CODE_EBUSY = 15
ERR_CODE_EREJECT = 16
ERR_CODE_EUNKNOWN = 17
ERR_CODE_EROLE = 18
ERR_CODE_ETIMEOUT_HCI = 19
ERR_CODE_ENOMEM_EVT = 20
ERR_CODE_ENOADDR = 21
ERR_CODE_ENOTSYNCED = 22
ERR_CODE_EAUTHEN = 23
ERR_CODE_EAUTHOR = 24
ERR_CODE_EENCRYPT = 25
ERR_CODE_EENCRYPT_KEY_SZ = 26
ERR_CODE_ESTORE_CAP = 27
ERR_CODE_ESTORE_FAIL = 28
ERR_CODE_EPREEMPTED = 29
)
var ErrCodeStringMap = map[int]string{
ERR_CODE_EAGAIN: "eagain",
ERR_CODE_EALREADY: "ealready",
ERR_CODE_EINVAL: "einval",
ERR_CODE_EMSGSIZE: "emsgsize",
ERR_CODE_ENOENT: "enoent",
ERR_CODE_ENOMEM: "enomem",
ERR_CODE_ENOTCONN: "enotconn",
ERR_CODE_ENOTSUP: "enotsup",
ERR_CODE_EAPP: "eapp",
ERR_CODE_EBADDATA: "ebaddata",
ERR_CODE_EOS: "eos",
ERR_CODE_ECONTROLLER: "econtroller",
ERR_CODE_ETIMEOUT: "etimeout",
ERR_CODE_EDONE: "edone",
ERR_CODE_EBUSY: "ebusy",
ERR_CODE_EREJECT: "ereject",
ERR_CODE_EUNKNOWN: "eunknown",
ERR_CODE_EROLE: "erole",
ERR_CODE_ETIMEOUT_HCI: "etimeout_hci",
ERR_CODE_ENOMEM_EVT: "enomem_evt",
ERR_CODE_ENOADDR: "enoaddr",
ERR_CODE_ENOTSYNCED: "enotsynced",
}
const (
ERR_CODE_HCI_UNKNOWN_HCI_CMD int = 1
ERR_CODE_HCI_UNK_CONN_ID = 2
ERR_CODE_HCI_HW_FAIL = 3
ERR_CODE_HCI_PAGE_TMO = 4
ERR_CODE_HCI_AUTH_FAIL = 5
ERR_CODE_HCI_PINKEY_MISSING = 6
ERR_CODE_HCI_MEM_CAPACITY = 7
ERR_CODE_HCI_CONN_SPVN_TMO = 8
ERR_CODE_HCI_CONN_LIMIT = 9
ERR_CODE_HCI_SYNCH_CONN_LIMIT = 10
ERR_CODE_HCI_ACL_CONN_EXISTS = 11
ERR_CODE_HCI_CMD_DISALLOWED = 12
ERR_CODE_HCI_CONN_REJ_RESOURCES = 13
ERR_CODE_HCI_CONN_REJ_ENC = 14
ERR_CODE_HCI_CONN_REJ_BD_ADDR = 15
ERR_CODE_HCI_CONN_ACCEPT_TMO = 16
ERR_CODE_HCI_UNSUPPORTED = 17
ERR_CODE_HCI_INV_HCI_CMD_PARMS = 18
ERR_CODE_HCI_REM_USER_CONN_TERM = 19
ERR_CODE_HCI_RD_CONN_TERM_RESRCS = 20
ERR_CODE_HCI_RD_CONN_TERM_PWROFF = 21
ERR_CODE_HCI_CONN_TERM_LOCAL = 22
ERR_CODE_HCI_REPEATED_ATTEMPTS = 23
ERR_CODE_HCI_NO_PAIRING = 24
ERR_CODE_HCI_UNK_LMP = 25
ERR_CODE_HCI_UNSUPP_REM_FEATURE = 26
ERR_CODE_HCI_SCO_OFFSET = 27
ERR_CODE_HCI_SCO_ITVL = 28
ERR_CODE_HCI_SCO_AIR_MODE = 29
ERR_CODE_HCI_INV_LMP_LL_PARM = 30
ERR_CODE_HCI_UNSPECIFIED = 31
ERR_CODE_HCI_UNSUPP_LMP_LL_PARM = 32
ERR_CODE_HCI_NO_ROLE_CHANGE = 33
ERR_CODE_HCI_LMP_LL_RSP_TMO = 34
ERR_CODE_HCI_LMP_COLLISION = 35
ERR_CODE_HCI_LMP_PDU = 36
ERR_CODE_HCI_ENCRYPTION_MODE = 37
ERR_CODE_HCI_LINK_KEY_CHANGE = 38
ERR_CODE_HCI_UNSUPP_QOS = 39
ERR_CODE_HCI_INSTANT_PASSED = 40
ERR_CODE_HCI_UNIT_KEY_PAIRING = 41
ERR_CODE_HCI_DIFF_TRANS_COLL = 42
ERR_CODE_HCI_QOS_PARM = 44
ERR_CODE_HCI_QOS_REJECTED = 45
ERR_CODE_HCI_CHAN_CLASS = 46
ERR_CODE_HCI_INSUFFICIENT_SEC = 47
ERR_CODE_HCI_PARM_OUT_OF_RANGE = 48
ERR_CODE_HCI_PENDING_ROLE_SW = 50
ERR_CODE_HCI_RESERVED_SLOT = 52
ERR_CODE_HCI_ROLE_SW_FAIL = 53
ERR_CODE_HCI_INQ_RSP_TOO_BIG = 54
ERR_CODE_HCI_SEC_SIMPLE_PAIR = 55
ERR_CODE_HCI_HOST_BUSY_PAIR = 56
ERR_CODE_HCI_CONN_REJ_CHANNEL = 57
ERR_CODE_HCI_CTLR_BUSY = 58
ERR_CODE_HCI_CONN_PARMS = 59
ERR_CODE_HCI_DIR_ADV_TMO = 60
ERR_CODE_HCI_CONN_TERM_MIC = 61
ERR_CODE_HCI_CONN_ESTABLISHMENT = 62
ERR_CODE_HCI_MAC_CONN_FAIL = 63
ERR_CODE_HCI_COARSE_CLK_ADJ = 64
)
var HciErrCodeStringMap = map[int]string{
ERR_CODE_HCI_UNKNOWN_HCI_CMD: "unknown hci cmd",
ERR_CODE_HCI_UNK_CONN_ID: "unknown connection id",
ERR_CODE_HCI_HW_FAIL: "hw fail",
ERR_CODE_HCI_PAGE_TMO: "page tmo",
ERR_CODE_HCI_AUTH_FAIL: "auth fail",
ERR_CODE_HCI_PINKEY_MISSING: "pinkey missing",
ERR_CODE_HCI_MEM_CAPACITY: "mem capacity",
ERR_CODE_HCI_CONN_SPVN_TMO: "connection supervision timeout",
ERR_CODE_HCI_CONN_LIMIT: "conn limit",
ERR_CODE_HCI_SYNCH_CONN_LIMIT: "synch conn limit",
ERR_CODE_HCI_ACL_CONN_EXISTS: "acl conn exists",
ERR_CODE_HCI_CMD_DISALLOWED: "cmd disallowed",
ERR_CODE_HCI_CONN_REJ_RESOURCES: "conn rej resources",
ERR_CODE_HCI_CONN_REJ_ENC: "conn rej security",
ERR_CODE_HCI_CONN_REJ_BD_ADDR: "conn rej bd addr",
ERR_CODE_HCI_CONN_ACCEPT_TMO: "conn accept tmo",
ERR_CODE_HCI_UNSUPPORTED: "unsupported",
ERR_CODE_HCI_INV_HCI_CMD_PARMS: "inv hci cmd parms",
ERR_CODE_HCI_REM_USER_CONN_TERM: "rem user conn term",
ERR_CODE_HCI_RD_CONN_TERM_RESRCS: "rd conn term resrcs",
ERR_CODE_HCI_RD_CONN_TERM_PWROFF: "rd conn term pwroff",
ERR_CODE_HCI_CONN_TERM_LOCAL: "conn term local",
ERR_CODE_HCI_REPEATED_ATTEMPTS: "repeated attempts",
ERR_CODE_HCI_NO_PAIRING: "no pairing",
ERR_CODE_HCI_UNK_LMP: "unk lmp",
ERR_CODE_HCI_UNSUPP_REM_FEATURE: "unsupp rem feature",
ERR_CODE_HCI_SCO_OFFSET: "sco offset",
ERR_CODE_HCI_SCO_ITVL: "sco itvl",
ERR_CODE_HCI_SCO_AIR_MODE: "sco air mode",
ERR_CODE_HCI_INV_LMP_LL_PARM: "inv lmp ll parm",
ERR_CODE_HCI_UNSPECIFIED: "unspecified",
ERR_CODE_HCI_UNSUPP_LMP_LL_PARM: "unsupp lmp ll parm",
ERR_CODE_HCI_NO_ROLE_CHANGE: "no role change",
ERR_CODE_HCI_LMP_LL_RSP_TMO: "lmp ll rsp tmo",
ERR_CODE_HCI_LMP_COLLISION: "lmp collision",
ERR_CODE_HCI_LMP_PDU: "lmp pdu",
ERR_CODE_HCI_ENCRYPTION_MODE: "encryption mode",
ERR_CODE_HCI_LINK_KEY_CHANGE: "link key change",
ERR_CODE_HCI_UNSUPP_QOS: "unsupp qos",
ERR_CODE_HCI_INSTANT_PASSED: "instant passed",
ERR_CODE_HCI_UNIT_KEY_PAIRING: "unit key pairing",
ERR_CODE_HCI_DIFF_TRANS_COLL: "diff trans coll",
ERR_CODE_HCI_QOS_PARM: "qos parm",
ERR_CODE_HCI_QOS_REJECTED: "qos rejected",
ERR_CODE_HCI_CHAN_CLASS: "chan class",
ERR_CODE_HCI_INSUFFICIENT_SEC: "insufficient sec",
ERR_CODE_HCI_PARM_OUT_OF_RANGE: "parm out of range",
ERR_CODE_HCI_PENDING_ROLE_SW: "pending role sw",
ERR_CODE_HCI_RESERVED_SLOT: "reserved slot",
ERR_CODE_HCI_ROLE_SW_FAIL: "role sw fail",
ERR_CODE_HCI_INQ_RSP_TOO_BIG: "inq rsp too big",
ERR_CODE_HCI_SEC_SIMPLE_PAIR: "sec simple pair",
ERR_CODE_HCI_HOST_BUSY_PAIR: "host busy pair",
ERR_CODE_HCI_CONN_REJ_CHANNEL: "conn rej channel",
ERR_CODE_HCI_CTLR_BUSY: "ctlr busy",
ERR_CODE_HCI_CONN_PARMS: "conn parms",
ERR_CODE_HCI_DIR_ADV_TMO: "dir adv tmo",
ERR_CODE_HCI_CONN_TERM_MIC: "conn term mic",
ERR_CODE_HCI_CONN_ESTABLISHMENT: "conn establishment",
ERR_CODE_HCI_MAC_CONN_FAIL: "mac conn fail",
ERR_CODE_HCI_COARSE_CLK_ADJ: "coarse clk adj",
}
const (
ERR_CODE_ATT_INVALID_HANDLE int = 0x01
ERR_CODE_ATT_READ_NOT_PERMITTED = 0x02
ERR_CODE_ATT_WRITE_NOT_PERMITTED = 0x03
ERR_CODE_ATT_INVALID_PDU = 0x04
ERR_CODE_ATT_INSUFFICIENT_AUTHEN = 0x05
ERR_CODE_ATT_REQ_NOT_SUPPORTED = 0x06
ERR_CODE_ATT_INVALID_OFFSET = 0x07
ERR_CODE_ATT_INSUFFICIENT_AUTHOR = 0x08
ERR_CODE_ATT_PREPARE_QUEUE_FULL = 0x09
ERR_CODE_ATT_ATTR_NOT_FOUND = 0x0a
ERR_CODE_ATT_ATTR_NOT_LONG = 0x0b
ERR_CODE_ATT_INSUFFICIENT_KEY_SZ = 0x0c
ERR_CODE_ATT_INVALID_ATTR_VALUE_LEN = 0x0d
ERR_CODE_ATT_UNLIKELY = 0x0e
ERR_CODE_ATT_INSUFFICIENT_ENC = 0x0f
ERR_CODE_ATT_UNSUPPORTED_GROUP = 0x10
ERR_CODE_ATT_INSUFFICIENT_RES = 0x11
)
var AttErrCodeStringMap = map[int]string{
ERR_CODE_ATT_INVALID_HANDLE: "invalid handle",
ERR_CODE_ATT_READ_NOT_PERMITTED: "read not permitted",
ERR_CODE_ATT_WRITE_NOT_PERMITTED: "write not permitted",
ERR_CODE_ATT_INVALID_PDU: "invalid pdu",
ERR_CODE_ATT_INSUFFICIENT_AUTHEN: "insufficient authentication",
ERR_CODE_ATT_REQ_NOT_SUPPORTED: "request not supported",
ERR_CODE_ATT_INVALID_OFFSET: "invalid offset",
ERR_CODE_ATT_INSUFFICIENT_AUTHOR: "insufficient authorization",
ERR_CODE_ATT_PREPARE_QUEUE_FULL: "prepare queue full",
ERR_CODE_ATT_ATTR_NOT_FOUND: "attribute not found",
ERR_CODE_ATT_ATTR_NOT_LONG: "attribute not long",
ERR_CODE_ATT_INSUFFICIENT_KEY_SZ: "insufficient key size",
ERR_CODE_ATT_INVALID_ATTR_VALUE_LEN: "invalid attribute value length",
ERR_CODE_ATT_UNLIKELY: "unlikely error",
ERR_CODE_ATT_INSUFFICIENT_ENC: "insufficient encryption",
ERR_CODE_ATT_UNSUPPORTED_GROUP: "unsupported group",
ERR_CODE_ATT_INSUFFICIENT_RES: "insufficient resources",
}
const (
ERR_CODE_SM_ERR_PASSKEY int = 0x01
ERR_CODE_SM_ERR_OOB = 0x02
ERR_CODE_SM_ERR_AUTHREQ = 0x03
ERR_CODE_SM_ERR_CONFIRM_MISMATCH = 0x04
ERR_CODE_SM_ERR_PAIR_NOT_SUPP = 0x05
ERR_CODE_SM_ERR_ENC_KEY_SZ = 0x06
ERR_CODE_SM_ERR_CMD_NOT_SUPP = 0x07
ERR_CODE_SM_ERR_UNSPECIFIED = 0x08
ERR_CODE_SM_ERR_REPEATED = 0x09
ERR_CODE_SM_ERR_INVAL = 0x0a
ERR_CODE_SM_ERR_DHKEY = 0x0b
ERR_CODE_SM_ERR_NUMCMP = 0x0c
ERR_CODE_SM_ERR_ALREADY = 0x0d
ERR_CODE_SM_ERR_CROSS_TRANS = 0x0e
)
var SmErrCodeStringMap = map[int]string{
ERR_CODE_SM_ERR_PASSKEY: "passkey",
ERR_CODE_SM_ERR_OOB: "oob",
ERR_CODE_SM_ERR_AUTHREQ: "authreq",
ERR_CODE_SM_ERR_CONFIRM_MISMATCH: "confirm mismatch",
ERR_CODE_SM_ERR_PAIR_NOT_SUPP: "pairing not supported",
ERR_CODE_SM_ERR_ENC_KEY_SZ: "encryption key size",
ERR_CODE_SM_ERR_CMD_NOT_SUPP: "command not supported",
ERR_CODE_SM_ERR_UNSPECIFIED: "unspecified",
ERR_CODE_SM_ERR_REPEATED: "repeated attempts",
ERR_CODE_SM_ERR_INVAL: "invalid parameters",
ERR_CODE_SM_ERR_DHKEY: "dhkey check failed",
ERR_CODE_SM_ERR_NUMCMP: "numeric comparison failed",
ERR_CODE_SM_ERR_ALREADY: "pairing already in progress",
ERR_CODE_SM_ERR_CROSS_TRANS: "cross transport not allowed",
}
// These values never get transmitted or received, so their precise values
// don't matter. We specify them explicitly here to match the blehostd source.
const (
MSG_OP_REQ MsgOp = 0
MSG_OP_RSP = 1
MSG_OP_EVT = 2
)
// These values never get transmitted or received, so their precise values
// don't matter. We specify them explicitly here to match the blehostd source.
const (
MSG_TYPE_ERR MsgType = 1
MSG_TYPE_SYNC = 2
MSG_TYPE_CONNECT = 3
MSG_TYPE_TERMINATE = 4
MSG_TYPE_DISC_ALL_SVCS = 5
MSG_TYPE_DISC_SVC_UUID = 6
MSG_TYPE_DISC_ALL_CHRS = 7
MSG_TYPE_DISC_CHR_UUID = 8
MSG_TYPE_DISC_ALL_DSCS = 9
MSG_TYPE_WRITE = 10
MSG_TYPE_WRITE_CMD = 11
MSG_TYPE_EXCHANGE_MTU = 12
MSG_TYPE_GEN_RAND_ADDR = 13
MSG_TYPE_SET_RAND_ADDR = 14
MSG_TYPE_CONN_CANCEL = 15
MSG_TYPE_SCAN = 16
MSG_TYPE_SCAN_CANCEL = 17
MSG_TYPE_SET_PREFERRED_MTU = 18
MSG_TYPE_SECURITY_INITIATE = 19
MSG_TYPE_CONN_FIND = 20
MSG_TYPE_RESET = 21
MSG_TYPE_ADV_START = 22
MSG_TYPE_ADV_STOP = 23
MSG_TYPE_ADV_SET_DATA = 24
MSG_TYPE_ADV_RSP_SET_DATA = 25
MSG_TYPE_ADV_FIELDS = 26
MSG_TYPE_CLEAR_SVCS = 27
MSG_TYPE_ADD_SVCS = 28
MSG_TYPE_COMMIT_SVCS = 29
MSG_TYPE_ACCESS_STATUS = 30
MSG_TYPE_NOTIFY = 31
MSG_TYPE_FIND_CHR = 32
MSG_TYPE_SM_INJECT_IO = 33
MSG_TYPE_SYNC_EVT = 2049
MSG_TYPE_CONNECT_EVT = 2050
MSG_TYPE_CONN_CANCEL_EVT = 2051
MSG_TYPE_DISCONNECT_EVT = 2052
MSG_TYPE_DISC_SVC_EVT = 2053
MSG_TYPE_DISC_CHR_EVT = 2054
MSG_TYPE_DISC_DSC_EVT = 2055
MSG_TYPE_WRITE_ACK_EVT = 2056
MSG_TYPE_NOTIFY_RX_EVT = 2057
MSG_TYPE_MTU_CHANGE_EVT = 2058
MSG_TYPE_SCAN_EVT = 2059
MSG_TYPE_SCAN_COMPLETE_EVT = 2060
MSG_TYPE_ADV_COMPLETE_EVT = 2061
MSG_TYPE_ENC_CHANGE_EVT = 2062
MSG_TYPE_RESET_EVT = 2063
MSG_TYPE_ACCESS_EVT = 2064
MSG_TYPE_PASSKEY_EVT = 2065
)
var MsgOpStringMap = map[MsgOp]string{
MSG_OP_REQ: "request",
MSG_OP_RSP: "response",
MSG_OP_EVT: "event",
}
var MsgTypeStringMap = map[MsgType]string{
MSG_TYPE_ERR: "error",
MSG_TYPE_SYNC: "sync",
MSG_TYPE_CONNECT: "connect",
MSG_TYPE_TERMINATE: "terminate",
MSG_TYPE_DISC_ALL_SVCS: "disc_all_svcs",
MSG_TYPE_DISC_SVC_UUID: "disc_svc_uuid",
MSG_TYPE_DISC_ALL_CHRS: "disc_all_chrs",
MSG_TYPE_DISC_CHR_UUID: "disc_chr_uuid",
MSG_TYPE_DISC_ALL_DSCS: "disc_all_dscs",
MSG_TYPE_WRITE: "write",
MSG_TYPE_WRITE_CMD: "write_cmd",
MSG_TYPE_EXCHANGE_MTU: "exchange_mtu",
MSG_TYPE_GEN_RAND_ADDR: "gen_rand_addr",
MSG_TYPE_SET_RAND_ADDR: "set_rand_addr",
MSG_TYPE_CONN_CANCEL: "conn_cancel",
MSG_TYPE_SCAN: "scan",
MSG_TYPE_SCAN_CANCEL: "scan_cancel",
MSG_TYPE_SET_PREFERRED_MTU: "set_preferred_mtu",
MSG_TYPE_SECURITY_INITIATE: "security_initiate",
MSG_TYPE_CONN_FIND: "conn_find",
MSG_TYPE_RESET: "reset",
MSG_TYPE_ADV_START: "adv_start",
MSG_TYPE_ADV_STOP: "adv_stop",
MSG_TYPE_ADV_SET_DATA: "adv_set_data",
MSG_TYPE_ADV_RSP_SET_DATA: "adv_rsp_set_data",
MSG_TYPE_ADV_FIELDS: "adv_fields",
MSG_TYPE_CLEAR_SVCS: "clear_svcs",
MSG_TYPE_ADD_SVCS: "add_svcs",
MSG_TYPE_COMMIT_SVCS: "commit_svcs",
MSG_TYPE_ACCESS_STATUS: "access_status",
MSG_TYPE_NOTIFY: "notify",
MSG_TYPE_FIND_CHR: "find_chr",
MSG_TYPE_SM_INJECT_IO: "sm_inject_io",
MSG_TYPE_SYNC_EVT: "sync_evt",
MSG_TYPE_CONNECT_EVT: "connect_evt",
MSG_TYPE_CONN_CANCEL_EVT: "conn_cancel_evt",
MSG_TYPE_DISCONNECT_EVT: "disconnect_evt",
MSG_TYPE_DISC_SVC_EVT: "disc_svc_evt",
MSG_TYPE_DISC_CHR_EVT: "disc_chr_evt",
MSG_TYPE_DISC_DSC_EVT: "disc_dsc_evt",
MSG_TYPE_WRITE_ACK_EVT: "write_ack_evt",
MSG_TYPE_NOTIFY_RX_EVT: "notify_rx_evt",
MSG_TYPE_MTU_CHANGE_EVT: "mtu_change_evt",
MSG_TYPE_SCAN_EVT: "scan_evt",
MSG_TYPE_SCAN_COMPLETE_EVT: "scan_tmo_evt",
MSG_TYPE_ADV_COMPLETE_EVT: "adv_complete_evt",
MSG_TYPE_ENC_CHANGE_EVT: "enc_change_evt",
MSG_TYPE_RESET_EVT: "reset_evt",
MSG_TYPE_ACCESS_EVT: "access_evt",
MSG_TYPE_PASSKEY_EVT: "passkey_evt",
}
type BleHdr struct {
Op MsgOp `json:"op"`
Type MsgType `json:"type"`
Seq BleSeq `json:"seq"`
}
type Msg interface{}
type BleDiscSvc struct {
StartHandle int `json:"start_handle"`
EndHandle int `json:"end_handle"`
Uuid BleUuid `json:"uuid"`
}
type BleDiscChr struct {
DefHandle int `json:"def_handle"`
ValHandle int `json:"val_handle"`
Properties int `json:"properties"`
Uuid BleUuid `json:"uuid"`
}
type BleDiscDsc struct {
Handle uint16 `json:"handle"`
Uuid BleUuid `json:"uuid"`
}
type BleSyncReq struct {
// Header
Op MsgOp `json:"op"`
Type MsgType `json:"type"`
Seq BleSeq `json:"seq"`
}
type BleConnectReq struct {
// Header
Op MsgOp `json:"op"`
Type MsgType `json:"type"`
Seq BleSeq `json:"seq"`
// Mandatory
OwnAddrType BleAddrType `json:"own_addr_type"`
PeerAddrType BleAddrType `json:"peer_addr_type"`
PeerAddr BleAddr `json:"peer_addr"`
// Optional
DurationMs int `json:"duration_ms"`
ScanItvl int `json:"scan_itvl"`
ScanWindow int `json:"scan_window"`
ItvlMin int `json:"itvl_min"`
ItvlMax int `json:"itvl_max"`
Latency int `json:"latency"`
SupervisionTimeout int `json:"supervision_timeout"`
MinCeLen int `json:"min_ce_len"`
MaxCeLen int `json:"max_ce_len"`
}
type BleConnectRsp struct {
// Header
Op MsgOp `json:"op"`
Type MsgType `json:"type"`
Seq BleSeq `json:"seq"`
// Mandatory
Status int `json:"status"`
}
type BleConnectEvt struct {
// Header
Op MsgOp `json:"op"`
Type MsgType `json:"type"`
Seq BleSeq `json:"seq"`
// Mandatory
Status int `json:"status"`
ConnHandle uint16 `json:"conn_handle"`
}
type BleTerminateReq struct {
// Header
Op MsgOp `json:"op"`
Type MsgType `json:"type"`
Seq BleSeq `json:"seq"`
ConnHandle uint16 `json:"conn_handle"`
HciReason int `json:"hci_reason"`
}
type BleTerminateRsp struct {
// Header
Op MsgOp `json:"op"`
Type MsgType `json:"type"`
Seq BleSeq `json:"seq"`
// Mandatory
Status int `json:"status"`
}
type BleConnCancelReq struct {
// Header
Op MsgOp `json:"op"`
Type MsgType `json:"type"`
Seq BleSeq `json:"seq"`
}
type BleConnCancelRsp struct {
// Header
Op MsgOp `json:"op"`
Type MsgType `json:"type"`
Seq BleSeq `json:"seq"`
// Mandatory
Status int `json:"status"`
}
type BleConnCancelEvt struct {
// Header
Op MsgOp `json:"op"`
Type MsgType `json:"type"`
Seq BleSeq `json:"seq"`
}
type BleDisconnectEvt struct {
// Header
Op MsgOp `json:"op"`
Type MsgType `json:"type"`
Seq BleSeq `json:"seq"`
// Mandatory
Reason int `json:"reason"`
ConnHandle uint16 `json:"conn_handle"`
}
type BleDiscAllSvcsReq struct {
// Header
Op MsgOp `json:"op"`
Type MsgType `json:"type"`
Seq BleSeq `json:"seq"`
// Mandatory
ConnHandle uint16 `json:"conn_handle"`
}
type BleDiscAllSvcsRsp struct {
// Header
Op MsgOp `json:"op"`
Type MsgType `json:"type"`
Seq BleSeq `json:"seq"`
// Mandatory
Status int `json:"status"`
}
type BleDiscSvcUuidReq struct {
// Header
Op MsgOp `json:"op"`
Type MsgType `json:"type"`
Seq BleSeq `json:"seq"`
// Mandatory
ConnHandle uint16 `json:"conn_handle"`
Uuid BleUuid `json:"svc_uuid"`
}
type BleDiscSvcUuidRsp struct {
// Header
Op MsgOp `json:"op"`
Type MsgType `json:"type"`
Seq BleSeq `json:"seq"`
// Mandatory
Status int `json:"status"`
}
type BleDiscSvcEvt struct {
// Header
Op MsgOp `json:"op"`
Type MsgType `json:"type"`
Seq BleSeq `json:"seq"`
// Mandatory
Status int `json:"status"`
Svc BleDiscSvc `json:"service"`
}
type BleDiscAllChrsReq struct {
// Header
Op MsgOp `json:"op"`
Type MsgType `json:"type"`
Seq BleSeq `json:"seq"`
// Mandatory
ConnHandle uint16 `json:"conn_handle"`
StartHandle int `json:"start_handle"`
EndHandle int `json:"end_handle"`
}
type BleDiscAllChrsRsp struct {
// Header
Op MsgOp `json:"op"`
Type MsgType `json:"type"`
Seq BleSeq `json:"seq"`
// Mandatory
Status int `json:"status"`
}
type BleDiscChrUuidReq struct {
// Header
Op MsgOp `json:"op"`
Type MsgType `json:"type"`
Seq BleSeq `json:"seq"`
// Mandatory
ConnHandle uint16 `json:"conn_handle"`
StartHandle int `json:"start_handle"`
EndHandle int `json:"end_handle"`
Uuid BleUuid `json:"chr_uuid"`
}
type BleDiscChrUuidRsp struct {
// Header
Op MsgOp `json:"op"`
Type MsgType `json:"type"`
Seq BleSeq `json:"seq"`
// Mandatory
Status int `json:"status"`
}
type BleDiscChrEvt struct {
// Header
Op MsgOp `json:"op"`
Type MsgType `json:"type"`
Seq BleSeq `json:"seq"`
// Mandatory
Status int `json:"status"`
Chr BleDiscChr `json:"characteristic"`
}
type BleDiscAllDscsReq struct {
// Header
Op MsgOp `json:"op"`
Type MsgType `json:"type"`
Seq BleSeq `json:"seq"`
// Mandatory
ConnHandle uint16 `json:"conn_handle"`
StartHandle int `json:"start_handle"`
EndHandle int `json:"end_handle"`
}
type BleDiscAllDscsRsp struct {
// Header
Op MsgOp `json:"op"`
Type MsgType `json:"type"`
Seq BleSeq `json:"seq"`
// Mandatory
Status int `json:"status"`
}
type BleDiscDscEvt struct {
// Header
Op MsgOp `json:"op"`
Type MsgType `json:"type"`
Seq BleSeq `json:"seq"`
// Mandatory
Status int `json:"status"`
ChrDefHandle uint16 `json:"chr_def_handle"`
Dsc BleDiscDsc `json:"descriptor"`
}
type BleErrRsp struct {
// Header
Op MsgOp `json:"op"`
Type MsgType `json:"type"`
Seq BleSeq `json:"seq"`
// Mandatory
Status int `json:"status"`
Msg string `json:"msg"`
}
type BleSyncRsp struct {
// Header
Op MsgOp `json:"op"`
Type MsgType `json:"type"`
Seq BleSeq `json:"seq"`
// Mandatory
Synced bool `json:"synced"`
}
type BleWriteReq struct {
// Header
Op MsgOp `json:"op"`
Type MsgType `json:"type"`
Seq BleSeq `json:"seq"`
// Mandatory
ConnHandle uint16 `json:"conn_handle"`
AttrHandle int `json:"attr_handle"`
Data BleBytes `json:"data"`
}
type BleWriteRsp struct {
// Header
Op MsgOp `json:"op"`
Type MsgType `json:"type"`
Seq BleSeq `json:"seq"`
// Mandatory
Status int `json:"status"`
}
type BleWriteAckEvt struct {
// Header
Op MsgOp `json:"op"`
Type MsgType `json:"type"`
Seq BleSeq `json:"seq"`
// Mandatory
Status int `json:"status"`
}
type BleWriteCmdReq struct {
// Header
Op MsgOp `json:"op"`
Type MsgType `json:"type"`
Seq BleSeq `json:"seq"`
// Mandatory
ConnHandle uint16 `json:"conn_handle"`
AttrHandle int `json:"attr_handle"`
Data BleBytes `json:"data"`
}
type BleWriteCmdRsp struct {
// Header
Op MsgOp `json:"op"`
Type MsgType `json:"type"`
Seq BleSeq `json:"seq"`
// Mandatory
Status int `json:"status"`
}
type BleSyncEvt struct {
// Header
Op MsgOp `json:"op"`
Type MsgType `json:"type"`
Seq BleSeq `json:"seq"`
// Mandatory
Synced bool `json:"synced"`
}
type BleNotifyRxEvt struct {
// Header
Op MsgOp `json:"op"`
Type MsgType `json:"type"`
Seq BleSeq `json:"seq"`
// Mandatory
ConnHandle uint16 `json:"conn_handle"`
AttrHandle int `json:"attr_handle"`
Indication bool `json:"indication"`
Data BleBytes `json:"data"`
}
type BleExchangeMtuReq struct {
// Header
Op MsgOp `json:"op"`
Type MsgType `json:"type"`
Seq BleSeq `json:"seq"`
// Mandatory
ConnHandle uint16 `json:"conn_handle"`
}
type BleExchangeMtuRsp struct {
// Header
Op MsgOp `json:"op"`
Type MsgType `json:"type"`
Seq BleSeq `json:"seq"`
// Mandatory
Status int `json:"status"`
}
type BleMtuChangeEvt struct {
// Header
Op MsgOp `json:"op"`
Type MsgType `json:"type"`
Seq BleSeq `json:"seq"`
// Mandatory
Status int `json:"status"`
ConnHandle uint16 `json:"conn_handle"`
Mtu uint16 `json:"mtu"`
}
type BleGenRandAddrReq struct {
// Header
Op MsgOp `json:"op"`
Type MsgType `json:"type"`
Seq BleSeq `json:"seq"`
// Mandatory
Nrpa bool `json:"nrpa"`
}
type BleGenRandAddrRsp struct {
// Header
Op MsgOp `json:"op"`
Type MsgType `json:"type"`
Seq BleSeq `json:"seq"`
// Mandatory
Status int `json:"status"`
Addr BleAddr `json:"addr"`
}
type BleSetRandAddrReq struct {
// Header
Op MsgOp `json:"op"`
Type MsgType `json:"type"`
Seq BleSeq `json:"seq"`
// Mandatory
Addr BleAddr `json:"addr"`
}
type BleSetRandAddrRsp struct {
// Header
Op MsgOp `json:"op"`
Type MsgType `json:"type"`
Seq BleSeq `json:"seq"`
// Mandatory
Status int `json:"status"`
}
type BleScanReq struct {
// Header
Op MsgOp `json:"op"`
Type MsgType `json:"type"`
Seq BleSeq `json:"seq"`
// Mandatory
OwnAddrType BleAddrType `json:"own_addr_type"`
DurationMs int `json:"duration_ms"`
Itvl int `json:"itvl"`
Window int `json:"window"`
FilterPolicy BleScanFilterPolicy `json:"filter_policy"`
Limited bool `json:"limited"`
Passive bool `json:"passive"`
FilterDuplicates bool `json:"filter_duplicates"`
}
type BleScanRsp struct {
// Header
Op MsgOp `json:"op"`
Type MsgType `json:"type"`
Seq BleSeq `json:"seq"`
// Mandatory
Status int `json:"status"`
}
type BleScanEvt struct {
// Header
Op MsgOp `json:"op"`
Type MsgType `json:"type"`
Seq BleSeq `json:"seq"`
// Mandatory
EventType BleAdvEventType `json:"event_type"`
AddrType BleAddrType `json:"addr_type"`
Addr BleAddr `json:"addr"`
Rssi int8 `json:"rssi"`
Data BleBytes `json:"data"`
// Optional
DataFlags *uint8 `json:"data_flags"`
DataUuids16 []BleUuid16 `json:"data_uuids16"`
DataUuids16IsComplete bool `json:"data_uuids16_is_complete"`
DataUuids32 []uint32 `json:"data_uuids32"`
DataUuids32IsComplete bool `json:"data_uuids32_is_complete"`
DataUuids128 []BleUuid128 `json:"data_uuids128"`
DataUuids128IsComplete bool `json:"data_uuids128_is_complete"`
DataName *string `json:"data_name"`
DataNameIsComplete bool `json:"data_name_is_complete"`
DataTxPwrLvl *int8 `json:"data_tx_pwr_lvl"`
DataSlaveItvlMin *uint16 `json:"data_slave_itvl_min"`
DataSlaveItvlMax *uint16 `json:"data_slave_itvl_max"`
DataSvcDataUuid16 BleBytes `json:"data_svc_data_uuid16"`
DataPublicTgtAddrs []BleAddr `json:"data_public_tgt_addrs"`
DataAppearance *uint16 `json:"data_appearance"`
DataAdvItvl *uint16 `json:"data_adv_itvl"`
DataSvcDataUuid32 BleBytes `json:"data_svc_data_uuid32"`
DataSvcDataUuid128 BleBytes `json:"data_svc_data_uuid128"`
DataUri *string `json:"data_uri"`
DataMfgData BleBytes `json:"data_mfg_data"`
}
type BleScanCompleteEvt struct {
// Header
Op MsgOp `json:"op"`
Type MsgType `json:"type"`
Seq BleSeq `json:"seq"`
// Mandatory
Reason int `json:"reason"`
}
type BleScanCancelReq struct {
// Header
Op MsgOp `json:"op"`
Type MsgType `json:"type"`
Seq BleSeq `json:"seq"`
}
type BleScanCancelRsp struct {
// Header
Op MsgOp `json:"op"`
Type MsgType `json:"type"`
Seq BleSeq `json:"seq"`
// Mandatory
Status int `json:"status"`
}
type BleSetPreferredMtuReq struct {
// Header
Op MsgOp `json:"op"`
Type MsgType `json:"type"`
Seq BleSeq `json:"seq"`
// Mandatory
Mtu uint16 `json:"mtu"`
}
type BleSetPreferredMtuRsp struct {
// Header
Op MsgOp `json:"op"`
Type MsgType `json:"type"`
Seq BleSeq `json:"seq"`
// Mandatory
Status int `json:"status"`
}
type BleConnFindReq struct {
// Header
Op MsgOp `json:"op"`
Type MsgType `json:"type"`
Seq BleSeq `json:"seq"`
// Mandatory
ConnHandle uint16 `json:"conn_handle"`
}