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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
use super::VendorReturnParameters;
use byteorder::{ByteOrder, LittleEndian};
use core::convert::{TryFrom, TryInto};
use core::fmt::{Debug, Formatter, Result as FmtResult};
use core::mem;
#[derive(Clone, Debug)]
pub struct CommandComplete<V>
where
V: super::VendorEvent,
{
pub num_hci_command_packets: u8,
pub return_params: ReturnParameters<V>,
}
impl<V> CommandComplete<V>
where
V: super::VendorEvent,
{
pub fn new(bytes: &[u8]) -> Result<CommandComplete<V>, ::event::Error<V::Error>> {
require_len_at_least!(bytes, 3);
let params = match ::opcode::Opcode(LittleEndian::read_u16(&bytes[1..])) {
::opcode::Opcode(0x0000) => ReturnParameters::Spontaneous,
::opcode::SET_EVENT_MASK => ReturnParameters::SetEventMask(to_status(&bytes[3..])?),
::opcode::RESET => ReturnParameters::Reset(to_status(&bytes[3..])?),
::opcode::READ_TX_POWER_LEVEL => {
ReturnParameters::ReadTxPowerLevel(to_tx_power_level(&bytes[3..])?)
}
::opcode::READ_LOCAL_VERSION_INFO => {
ReturnParameters::ReadLocalVersionInformation(to_local_version_info(&bytes[3..])?)
}
::opcode::READ_LOCAL_SUPPORTED_COMMANDS => {
ReturnParameters::ReadLocalSupportedCommands(to_supported_commands(&bytes[3..])?)
}
::opcode::READ_LOCAL_SUPPORTED_FEATURES => {
ReturnParameters::ReadLocalSupportedFeatures(to_supported_features(&bytes[3..])?)
}
::opcode::READ_BD_ADDR => ReturnParameters::ReadBdAddr(to_bd_addr(&bytes[3..])?),
::opcode::READ_RSSI => ReturnParameters::ReadRssi(to_read_rssi(&bytes[3..])?),
::opcode::LE_SET_EVENT_MASK => {
ReturnParameters::LeSetEventMask(to_status(&bytes[3..])?)
}
::opcode::LE_READ_BUFFER_SIZE => {
ReturnParameters::LeReadBufferSize(to_le_read_buffer_status(&bytes[3..])?)
}
::opcode::LE_READ_LOCAL_SUPPORTED_FEATURES => {
ReturnParameters::LeReadLocalSupportedFeatures(to_le_local_supported_features(
&bytes[3..],
)?)
}
::opcode::LE_SET_RANDOM_ADDRESS => {
ReturnParameters::LeSetRandomAddress(to_status(&bytes[3..])?)
}
::opcode::LE_SET_ADVERTISING_PARAMETERS => {
ReturnParameters::LeSetAdvertisingParameters(to_status(&bytes[3..])?)
}
::opcode::LE_READ_ADVERTISING_CHANNEL_TX_POWER => {
ReturnParameters::LeReadAdvertisingChannelTxPower(
to_le_advertising_channel_tx_power(&bytes[3..])?,
)
}
::opcode::LE_SET_ADVERTISING_DATA => {
ReturnParameters::LeSetAdvertisingData(to_status(&bytes[3..])?)
}
::opcode::LE_SET_SCAN_RESPONSE_DATA => {
ReturnParameters::LeSetScanResponseData(to_status(&bytes[3..])?)
}
::opcode::LE_SET_ADVERTISE_ENABLE => {
to_le_set_advertise_enable(to_status(&bytes[3..])?)
}
::opcode::LE_SET_SCAN_PARAMETERS => {
ReturnParameters::LeSetScanParameters(to_status(&bytes[3..])?)
}
::opcode::LE_SET_SCAN_ENABLE => {
ReturnParameters::LeSetScanEnable(to_status(&bytes[3..])?)
}
::opcode::LE_CREATE_CONNECTION_CANCEL => {
ReturnParameters::LeCreateConnectionCancel(to_status(&bytes[3..])?)
}
::opcode::LE_READ_WHITE_LIST_SIZE => {
ReturnParameters::LeReadWhiteListSize(to_status(&bytes[3..])?, bytes[4] as usize)
}
::opcode::LE_CLEAR_WHITE_LIST => {
ReturnParameters::LeClearWhiteList(to_status(&bytes[3..])?)
}
::opcode::LE_ADD_DEVICE_TO_WHITE_LIST => {
ReturnParameters::LeAddDeviceToWhiteList(to_status(&bytes[3..])?)
}
::opcode::LE_REMOVE_DEVICE_FROM_WHITE_LIST => {
ReturnParameters::LeRemoveDeviceFromWhiteList(to_status(&bytes[3..])?)
}
::opcode::LE_SET_HOST_CHANNEL_CLASSIFICATION => {
ReturnParameters::LeSetHostChannelClassification(to_status(&bytes[3..])?)
}
::opcode::LE_READ_CHANNEL_MAP => {
ReturnParameters::LeReadChannelMap(to_le_channel_map_parameters(&bytes[3..])?)
}
::opcode::LE_ENCRYPT => ReturnParameters::LeEncrypt(to_le_encrypted_data(&bytes[3..])?),
::opcode::LE_RAND => ReturnParameters::LeRand(to_random_number(&bytes[3..])?),
::opcode::LE_LTK_REQUEST_REPLY => {
ReturnParameters::LeLongTermKeyRequestReply(to_le_ltk_request_reply(&bytes[3..])?)
}
::opcode::LE_LTK_REQUEST_NEGATIVE_REPLY => {
ReturnParameters::LeLongTermKeyRequestNegativeReply(to_le_ltk_request_reply(
&bytes[3..],
)?)
}
::opcode::LE_READ_STATES => {
ReturnParameters::LeReadSupportedStates(to_le_read_states(&bytes[3..])?)
}
::opcode::LE_RECEIVER_TEST => ReturnParameters::LeReceiverTest(to_status(&bytes[3..])?),
::opcode::LE_TRANSMITTER_TEST => {
ReturnParameters::LeTransmitterTest(to_status(&bytes[3..])?)
}
::opcode::LE_TEST_END => ReturnParameters::LeTestEnd(to_le_test_end(&bytes[3..])?),
other => {
const VENDOR_OGF: u16 = 0x3F;
if other.ogf() != VENDOR_OGF {
return Err(::event::Error::UnknownOpcode(other));
}
ReturnParameters::Vendor(V::ReturnParameters::new(&bytes)?)
}
};
Ok(CommandComplete::<V> {
num_hci_command_packets: bytes[0],
return_params: params,
})
}
}
#[derive(Copy, Clone, Debug)]
pub enum ReturnParameters<V>
where
V: super::VendorEvent,
{
Spontaneous,
SetEventMask(::Status<V::Status>),
Reset(::Status<V::Status>),
ReadTxPowerLevel(TxPowerLevel<V::Status>),
ReadLocalVersionInformation(LocalVersionInfo<V::Status>),
ReadLocalSupportedCommands(LocalSupportedCommands<V::Status>),
ReadLocalSupportedFeatures(LocalSupportedFeatures<V::Status>),
ReadBdAddr(ReadBdAddr<V::Status>),
ReadRssi(ReadRssi<V::Status>),
LeSetEventMask(::Status<V::Status>),
LeReadBufferSize(LeReadBufferSize<V::Status>),
LeReadLocalSupportedFeatures(LeSupportedFeatures<V::Status>),
LeSetRandomAddress(::Status<V::Status>),
LeSetAdvertisingParameters(::Status<V::Status>),
LeReadAdvertisingChannelTxPower(LeAdvertisingChannelTxPower<V::Status>),
LeSetAdvertisingData(::Status<V::Status>),
LeSetScanResponseData(::Status<V::Status>),
#[cfg(not(feature = "version-5-0"))]
LeSetAdvertiseEnable(::Status<V::Status>),
#[cfg(feature = "version-5-0")]
LeSetAdvertisingEnable(::Status<V::Status>),
LeSetScanParameters(::Status<V::Status>),
LeSetScanEnable(::Status<V::Status>),
LeCreateConnectionCancel(::Status<V::Status>),
LeReadWhiteListSize(::Status<V::Status>, usize),
LeClearWhiteList(::Status<V::Status>),
LeAddDeviceToWhiteList(::Status<V::Status>),
LeRemoveDeviceFromWhiteList(::Status<V::Status>),
LeSetHostChannelClassification(::Status<V::Status>),
LeReadChannelMap(ChannelMapParameters<V::Status>),
LeEncrypt(EncryptedReturnParameters<V::Status>),
LeRand(LeRandom<V::Status>),
LeLongTermKeyRequestReply(LeLongTermRequestReply<V::Status>),
LeLongTermKeyRequestNegativeReply(LeLongTermRequestReply<V::Status>),
LeReadSupportedStates(LeReadSupportedStates<V::Status>),
LeReceiverTest(::Status<V::Status>),
LeTransmitterTest(::Status<V::Status>),
LeTestEnd(LeTestEnd<V::Status>),
Vendor(V::ReturnParameters),
}
fn to_status<VE, VS>(bytes: &[u8]) -> Result<::Status<VS>, ::event::Error<VE>>
where
::Status<VS>: TryFrom<u8, Error = ::BadStatusError>,
{
bytes[0].try_into().map_err(super::rewrap_bad_status)
}
#[derive(Copy, Clone, Debug)]
pub struct TxPowerLevel<VS> {
pub status: ::Status<VS>,
pub conn_handle: ::ConnectionHandle,
pub tx_power_level_dbm: i8,
}
fn to_tx_power_level<VE, VS>(bytes: &[u8]) -> Result<TxPowerLevel<VS>, ::event::Error<VE>>
where
::Status<VS>: TryFrom<u8, Error = ::BadStatusError>,
{
require_len!(bytes, 4);
Ok(TxPowerLevel {
status: to_status(bytes)?,
conn_handle: ::ConnectionHandle(LittleEndian::read_u16(&bytes[1..])),
tx_power_level_dbm: unsafe { mem::transmute::<u8, i8>(bytes[3]) },
})
}
#[derive(Copy, Clone, Debug)]
pub struct LocalVersionInfo<VS> {
pub status: ::Status<VS>,
pub hci_version: u8,
pub hci_revision: u16,
pub lmp_version: u8,
pub manufacturer_name: u16,
pub lmp_subversion: u16,
}
fn to_local_version_info<VE, VS>(bytes: &[u8]) -> Result<LocalVersionInfo<VS>, ::event::Error<VE>>
where
::Status<VS>: TryFrom<u8, Error = ::BadStatusError>,
{
require_len!(bytes, 9);
Ok(LocalVersionInfo {
status: bytes[0].try_into().map_err(super::rewrap_bad_status)?,
hci_version: bytes[1],
hci_revision: LittleEndian::read_u16(&bytes[2..]),
lmp_version: bytes[4],
manufacturer_name: LittleEndian::read_u16(&bytes[5..]),
lmp_subversion: LittleEndian::read_u16(&bytes[7..]),
})
}
#[derive(Copy, Clone, Debug)]
pub struct LocalSupportedCommands<VS> {
pub status: ::Status<VS>,
pub supported_commands: CommandFlags,
}
const COMMAND_FLAGS_SIZE: usize = 64;
bitflag_array! {
#[derive(Copy, Clone)]
pub struct CommandFlags : COMMAND_FLAGS_SIZE;
pub struct CommandFlag;
const INQUIRY = 0, 1 << 0;
const INQUIRY_CANCEL = 0, 1 << 1;
const PERIODIC_INQUIRY_MODE = 0, 1 << 2;
const EXIT_PERIODIC_INQUIRY_MODE = 0, 1 << 3;
const CREATE_CONNECTION = 0, 1 << 4;
const DISCONNECT = 0, 1 << 5;
#[deprecated]
const ADD_SCO_CONNECTION = 0, 1 << 6;
const CREATE_CONNECTION_CANCEL = 0, 1 << 7;
const ACCEPT_CONNECTION_REQUEST = 1, 1 << 0;
const REJECT_CONNECTION_REQUEST = 1, 1 << 1;
const LINK_KEY_REQUEST_REPLY = 1, 1 << 2;
const LINK_KEY_REQUEST_NEGATIVE_REPLY = 1, 1 << 3;
const PIN_CODE_REQUEST_REPLY = 1, 1 << 4;
const PIN_CODE_REQUEST_NEGATIVE_REPLY = 1, 1 << 5;
const CHANGE_CONNECTION_PACKET_TYPE = 1, 1 << 6;
const AUTHENTICATION_REQUESTED = 1, 1 << 7;
const SET_CONNECTION_ENCRYPTION = 2, 1 << 0;
const CHANGE_CONNECTION_LINK_KEY = 2, 1 << 1;
const MASTER_LINK_KEY = 2, 1 << 2;
const REMOTE_NAME_REQUEST = 2, 1 << 3;
const REMOTE_NAME_REQUEST_CANCEL = 2, 1 << 4;
const READ_REMOTE_SUPPORTED_FEATURES = 2, 1 << 5;
const READ_REMOTE_EXTENDED_FEATURES = 2, 1 << 6;
const READ_REMOTE_VERSION_INFORMATION = 2, 1 << 7;
const READ_CLOCK_OFFSET = 3, 1 << 0;
const READ_LMP_HANDLE = 3, 1 << 1;
const HOLD_MODE = 4, 1 << 1;
const SNIFF_MODE = 4, 1 << 2;
const EXIT_SNIFF_MODE = 4, 1 << 3;
const PARK_STATE = 4, 1 << 4;
const EXIT_PARK_STATE = 4, 1 << 5;
const QOS_SETUP = 4, 1 << 6;
const ROLE_DISCOVERY = 4, 1 << 7;
const SWITCH_ROLE = 5, 1 << 0;
const READ_LINK_POLICY_SETTINGS = 5, 1 << 1;
const WRITE_LINK_POLICY_SETTINGS = 5, 1 << 2;
const READ_DEFAULT_LINK_POLICY_SETTINGS = 5, 1 << 3;
const WRITE_DEFAULT_LINK_POLICY_SETTINGS = 5, 1 << 4;
const FLOW_SPECIFICATION = 5, 1 << 5;
const SET_EVENT_MASK = 5, 1 << 6;
const RESET = 5, 1 << 7;
const SET_EVENT_FILTER = 6, 1 << 0;
const FLUSH = 6, 1 << 1;
const READ_PIN_TYPE = 6, 1 << 2;
const WRITE_PIN_TYPE = 6, 1 << 3;
const CREATE_NEW_UNIT_KEY = 6, 1 << 4;
const READ_STORED_LINK_KEY = 6, 1 << 5;
const WRITE_STORED_LINK_KEY = 6, 1 << 6;
const DELETE_STORED_LINK_KEY = 6, 1 << 7;
const WRITE_LOCAL_NAME = 7, 1 << 0;
const READ_LOCAL_NAME = 7, 1 << 1;
const READ_CONNECTION_ACCEPT_TIMEOUT = 7, 1 << 2;
const WRITE_CONNECTION_ACCEPT_TIMEOUT = 7, 1 << 3;
const READ_PAGE_TIMEOUT = 7, 1 << 4;
const WRITE_PAGE_TIMEOUT = 7, 1 << 5;
const READ_SCAN_ENABLE = 7, 1 << 6;
const WRITE_SCAN_ENABLE = 7, 1 << 7;
const READ_PAGE_SCAN_ACTIVITY = 8, 1 << 0;
const WRITE_PAGE_SCAN_ACTIVITY = 8, 1 << 1;
const READ_INQUIRY_SCAN_ACTIVITY = 8, 1 << 2;
const WRITE_INQUIRY_SCAN_ACTIVITY = 8, 1 << 3;
const READ_AUTHENTICATION_ENABLE = 8, 1 << 4;
const WRITE_AUTHENTICATION_ENABLE = 8, 1 << 5;
#[deprecated]
const READ_ENCRYPTION_MODE = 8, 1 << 6;
#[deprecated]
const WRITE_ENCRYPTION_MODE = 8, 1 << 7;
const READ_CLASS_OF_DEVICE = 9, 1 << 0;
const WRITE_CLASS_OF_DEVICE = 9, 1 << 1;
const READ_VOICE_SETTING = 9, 1 << 2;
const WRITE_VOICE_SETTING = 9, 1 << 3;
const READ_AUTOMATIC_FLUSH_TIMEOUT = 9, 1 << 4;
const WRITE_AUTOMATIC_FLUSH_TIMEOUT = 9, 1 << 5;
const READ_NUM_BROADCAST_RETRANSMISSIONS = 9, 1 << 6;
const WRITE_NUM_BROADCAST_RETRANSMISSIONS = 9, 1 << 7;
const READ_HOLD_MODE_ACTIVITY = 10, 1 << 0;
const WRITE_HOLD_MODE_ACTIVITY = 10, 1 << 1;
const READ_TRANSMIT_POWER_LEVEL = 10, 1 << 2;
const READ_SYNCHRONOUS_FLOW_CONTROL_ENABLE = 10, 1 << 3;
const WRITE_SYNCHRONOUS_FLOW_CONTROL_ENABLE = 10, 1 << 4;
const SET_CONTROLLER_TO_HOST_FLOW_CONTROL = 10, 1 << 5;
const HOST_BUFFER_SIZE = 10, 1 << 6;
const HOST_NUMBER_OF_COMPLETED_PACKETS = 10, 1 << 7;
const READ_LINK_SUPERVISION_TIMEOUT = 11, 1 << 0;
const WRITE_LINK_SUPERVISION_TIMEOUT = 11, 1 << 1;
const READ_NUMBER_OF_SUPPORTED_IAC = 11, 1 << 2;
const READ_CURRENT_IAC_LAP = 11, 1 << 3;
const WRITE_CURRENT_IAC_LAP = 11, 1 << 4;
#[deprecated]
const READ_PAGE_SCAN_MODE_PERIOD = 11, 1 << 5;
#[deprecated]
const WRITE_PAGE_SCAN_MODE_PERIOD = 11, 1 << 6;
#[deprecated]
const READ_PAGE_SCAN_MODE = 11, 1 << 7;
#[deprecated]
const WRITE_PAGE_SCAN_MODE = 12, 1 << 0;
const SET_AFH_HOST_CHANNEL_CLASSIFICATION = 12, 1 << 1;
const READ_INQUIRY_SCAN_TYPE = 12, 1 << 4;
const WRITE_INQUIRY_SCAN_TYPE = 12, 1 << 5;
const READ_INQUIRY_MODE = 12, 1 << 6;
const WRITE_INQUIRY_MODE = 12, 1 << 7;
const READ_PAGE_SCAN_TYPE = 13, 1 << 0;
const WRITE_PAGE_SCAN_TYPE = 13, 1 << 1;
const READ_AFH_CHANNEL_ASSESSMENT_MODE = 13, 1 << 2;
const WRITE_AFH_CHANNEL_ASSESSMENT_MODE = 13, 1 << 3;
const READ_LOCAL_VERSION_INFORMATION = 14, 1 << 3;
const READ_LOCAL_SUPPORTED_FEATURES = 14, 1 << 5;
const READ_LOCAL_EXTENDED_FEATURES = 14, 1 << 6;
const READ_BUFFER_SIZE = 14, 1 << 7;
#[deprecated]
const READ_COUNTRY_CODE = 15, 1 << 0;
const READ_BD_ADDR = 15, 1 << 1;
const READ_FAILED_CONTACT_COUNTER = 15, 1 << 2;
const RESET_FAILED_CONTACT_COUNTER = 15, 1 << 3;
const READ_LINK_QUALITY = 15, 1 << 4;
const READ_RSSI = 15, 1 << 5;
const READ_AFH_CHANNEL_MAP = 15, 1 << 6;
const READ_CLOCK = 15, 1 << 7;
const READ_LOOPBACK_MODE = 16, 1 << 0;
const WRITE_LOOPBACK_MODE = 16, 1 << 1;
const ENABLE_DEVICE_UNDER_TEST_MODE = 16, 1 << 2;
const SETUP_SYNCHRONOUS_CONNECTION_REQUEST = 16, 1 << 3;
const ACCEPT_SYNCHRONOUS_CONNECTION_REQUEST = 16, 1 << 4;
const REJECT_SYNCHRONOUS_CONNECTION_REQUEST = 16, 1 << 5;
const READ_EXTENDED_INQUIRY_RESPONSE = 17, 1 << 0;
const WRITE_EXTENDED_INQUIRY_RESPONSE = 17, 1 << 1;
const REFRESH_ENCRYPTION_KEY = 17, 1 << 2;
const SNIFF_SUBRATING = 17, 1 << 4;
const READ_SIMPLE_PAIRING_MODE = 17, 1 << 5;
const WRITE_SIMPLE_PAIRING_MODE = 17, 1 << 6;
const READ_LOCAL_OOB_DATA = 17, 1 << 7;
const READ_INQUIRY_RESPONSE_TRANSMIT_POWER_LEVEL = 18, 1 << 0;
const WRITE_INQUIRY_TRANSMIT_POWER_LEVEL = 18, 1 << 1;
const READ_DEFAULT_ERRONEOUS_DATA_REPORTING = 18, 1 << 2;
const WRITE_DEFAULT_ERRONEOUS_DATA_REPORTING = 18, 1 << 3;
const IO_CAPABILITY_REQUEST_REPLY = 18, 1 << 7;
const USER_CONFIRMATION_REQUEST_REPLY = 19, 1 << 0;
const USER_CONFIRMATION_REQUEST_NEGATIVE_REPLY = 19, 1 << 1;
const USER_PASSKEY_REQUEST_REPLY = 19, 1 << 2;
const USER_PASSKEY_REQUEST_NEGATIVE_REPLY = 19, 1 << 3;
const REMOTE_OOB_DATA_REQUEST_REPLY = 19, 1 << 4;
const WRITE_SIMPLE_PAIRING_DEBUG_MODE = 19, 1 << 5;
const ENHANCED_FLUSH = 19, 1 << 6;
const REMOTE_OOB_DATA_REQUEST_NEGATIVE_REPLY = 19, 1 << 7;
const SEND_KEYPRESS_NOTIFICATION = 20, 1 << 2;
const IO_CAPABILITY_REQUEST_NEGATIVE_REPLY = 20, 1 << 3;
const READ_ENCRYPTION_KEY_SIZE = 20, 1 << 4;
const CREATE_PHYSICAL_LINK = 21, 1 << 0;
const ACCEPT_PHYSICAL_LINK = 21, 1 << 1;
const DISCONNECT_PHYSICAL_LINK = 21, 1 << 2;
const CREATE_LOGICAL_LINK = 21, 1 << 3;
const ACCEPT_LOGICAL_LINK = 21, 1 << 4;
const DISCONNECT_LOGICAL_LINK = 21, 1 << 5;
const LOGICAL_LINK_CANCEL = 21, 1 << 6;
const FLOW_SPEC_MODIFY = 21, 1 << 7;
const READ_LOGICAL_LINK_ACCEPT_TIMEOUT = 22, 1 << 0;
const WRITE_LOGICAL_LINK_ACCEPT_TIMEOUT = 22, 1 << 1;
const SET_EVENT_MASK_PAGE_2 = 22, 1 << 2;
const READ_LOCATION_DATA = 22, 1 << 3;
const WRITE_LOCATION_DATA = 22, 1 << 4;
const READ_LOCAL_AMP_INFO = 22, 1 << 5;
const READ_LOCAL_AMP_ASSOC = 22, 1 << 6;
const WRITE_REMOTE_AMP_ASSOC = 22, 1 << 7;
const READ_FLOW_CONTROL_MODE = 23, 1 << 0;
const WRITE_FLOW_CONTROL_MODE = 23, 1 << 1;
const READ_DATA_BLOCK_SIZE = 23, 1 << 2;
const ENABLE_AMP_RECEIVER_REPORTS = 23, 1 << 5;
const AMP_TEST_END = 23, 1 << 6;
const AMP_TEST = 23, 1 << 7;
const READ_ENHANCED_TRANSMIT_POWER_LEVEL = 24, 1 << 0;
const READ_BEST_EFFORT_FLUSH_TIMEOUT = 24, 1 << 2;
const WRITE_BEST_EFFORT_FLUSH_TIMEOUT = 24, 1 << 3;
const SHORT_RANGE_MODE = 24, 1 << 4;
const READ_LE_HOST_SUPPORT = 24, 1 << 5;
const WRITE_LE_HOST_SUPPORT = 24, 1 << 6;
const LE_SET_EVENT_MASK = 25, 1 << 0;
const LE_READ_BUFFER_SIZE = 25, 1 << 1;
const LE_READ_LOCAL_SUPPORTED_FEATURES = 25, 1 << 2;
const LE_SET_RANDOM_ADDRESS = 25, 1 << 4;
const LE_SET_ADVERTISING_PARAMETERS = 25, 1 << 5;
const LE_READ_ADVERTISING_CHANNEL_TX_POWER = 25, 1 << 6;
const LE_SET_ADVERTISING_DATA = 25, 1 << 7;
const LE_SET_SCAN_RESPONSE_DATA = 26, 1 << 0;
const LE_SET_ADVERTISE_ENABLE = 26, 1 << 1;
const LE_SET_SCAN_PARAMETERS = 26, 1 << 2;
const LE_SET_SCAN_ENABLE = 26, 1 << 3;
const LE_CREATE_CONNECTION = 26, 1 << 4;
const LE_CREATE_CONNECTION_CANCEL = 26, 1 << 5;
const LE_READ_WHITE_LIST_SIZE = 26, 1 << 6;
const LE_CLEAR_WHITE_LIST = 26, 1 << 7;
const LE_ADD_DEVICE_TO_WHITE_LIST = 27, 1 << 0;
const LE_REMOVE_DEVICE_FROM_WHITE_LIST = 27, 1 << 1;
const LE_CONNECTION_UPDATE = 27, 1 << 2;
const LE_SET_HOST_CHANNEL_CLASSIFICATION = 27, 1 << 3;
const LE_READ_CHANNEL_MAP = 27, 1 << 4;
const LE_READ_REMOTE_USED_FEATURES = 27, 1 << 5;
const LE_ENCRYPT = 27, 1 << 6;
const LE_RAND = 27, 1 << 7;
const LE_START_ENCRYPTION = 28, 1 << 0;
const LE_LONG_TERM_KEY_REQUEST_REPLY = 28, 1 << 1;
const LE_LONG_TERM_KEY_REQUEST_NEGATIVE_REPLY = 28, 1 << 2;
const LE_READ_SUPPORTED_STATES = 28, 1 << 3;
const LE_RECEIVER_TEST = 28, 1 << 4;
const LE_TRANSMITTER_TEST = 28, 1 << 5;
const LE_TEST_END = 28, 1 << 6;
const ENHANCED_SETUP_SYNCHRONOUS_CONNECTION = 29, 1 << 3;
const ENHANCED_ACCEPT_SYNCHRONOUS_CONNECTION = 29, 1 << 4;
const READ_LOCAL_SUPPORTED_CODECS = 29, 1 << 5;
const SET_MWS_CHANNEL_PARAMETERS_COMMAND = 29, 1 << 6;
const SET_EXTERNAL_FRAME_CONFIGURATION_COMMAND = 29, 1 << 7;
const SET_MWS_SIGNALING_COMMAND = 30, 1 << 0;
const SET_TRANSPORT_LAYER_COMMAND = 30, 1 << 1;
const SET_MWS_SCAN_FREQUENCY_TABLE_COMMAND = 30, 1 << 2;
const GET_TRANSPORT_LAYER_CONFIGURATION_COMMAND = 30, 1 << 3;
const SET_MWS_PATTERN_CONFIGURATION_COMMAND = 30, 1 << 4;
const SET_TRIGGERED_CLOCK_CAPTURE = 30, 1 << 5;
const TRUNCATED_PAGE = 30, 1 << 6;
const TRUNCATED_PAGE_CANCEL = 30, 1 << 7;
const SET_CONNECTIONLESS_PERIPHERAL_BROADCAST = 31, 1 << 0;
const SET_CONNECTIONLESS_PERIPHERAL_BROADCAST_RECEIVE = 31, 1 << 1;
const START_SYNCHRONIZATION_TRAIN = 31, 1 << 2;
const RECEIVE_SYNCHRONIZATION_TRAIN = 31, 1 << 3;
const SET_CONNECTIONLESS_PERIPHERAL_BROADCAST_DATA = 31, 1 << 6;
const READ_SYNCHRONIZATION_TRAIN_PARAMETERS = 31, 1 << 7;
const WRITE_SYNCHRONIZATION_TRAIN_PARAMETERS = 32, 1 << 0;
const REMOTE_OOB_EXTENDED_DATA_REQUEST_REPLY = 32, 1 << 1;
const READ_SECURE_CONNECTIONS_HOST_SUPPORT = 32, 1 << 2;
const WRITE_SECURE_CONNECTIONS_HOST_SUPPORT = 32, 1 << 3;
const READ_AUTHENTICATED_PAYLOAD_TIMEOUT = 32, 1 << 4;
const WRITE_AUTHENTICATED_PAYLOAD_TIMEOUT = 32, 1 << 5;
const READ_LOCAL_OOB_EXTENDED_DATA = 32, 1 << 6;
const WRITE_SECURE_CONNECTIONS_TEST_MODE = 32, 1 << 7;
const READ_EXTENDED_PAGE_TIMEOUT = 33, 1 << 0;
const WRITE_EXTENDED_PAGE_TIMEOUT = 33, 1 << 1;
const READ_EXTENDED_INQUIRY_LENGTH = 33, 1 << 2;
const WRITE_EXTENDED_INQUIRY_LENGTH = 33, 1 << 3;
const LE_REMOTE_CONNECTION_PARAMETER_REQUEST_REPLY_COMMAND = 33, 1 << 4;
const LE_REMOTE_CONNECTION_PARAMETER_REQUEST_NEGATIVE_REPLY_COMMAND = 33, 1 << 5;
#[cfg(any(feature = "version-4-2", feature = "version-5-0"))]
const LE_SET_DATA_LENGTH = 33, 1 << 6;
#[cfg(any(feature = "version-4-2", feature = "version-5-0"))]
const LE_READ_SUGGESTED_DEFAULT_DATA_LENGTH = 33, 1 << 7;
#[cfg(any(feature = "version-4-2", feature = "version-5-0"))]
const LE_WRITE_SUGGESTED_DEFAULT_DATA_LENGTH = 34, 1 << 0;
#[cfg(any(feature = "version-4-2", feature = "version-5-0"))]
const LE_READ_LOCAL_P256_PUBLIC_KEY = 34, 1 << 1;
#[cfg(any(feature = "version-4-2", feature = "version-5-0"))]
const LE_GENERATE_DH_KEY = 34, 1 << 2;
#[cfg(any(feature = "version-4-2", feature = "version-5-0"))]
const LE_ADD_DEVICE_TO_RESOLVING_LIST = 34, 1 << 3;
#[cfg(any(feature = "version-4-2", feature = "version-5-0"))]
const LE_REMOVE_DEVICE_FROM_RESOLVING_LIST = 34, 1 << 4;
#[cfg(any(feature = "version-4-2", feature = "version-5-0"))]
const LE_CLEAR_RESOLVING_LIST = 34, 1 << 5;
#[cfg(any(feature = "version-4-2", feature = "version-5-0"))]
const LE_READ_RESOLVING_LIST_SIZE = 34, 1 << 6;
#[cfg(any(feature = "version-4-2", feature = "version-5-0"))]
const LE_READ_PEER_RESOLVABLE_ADDRESS = 34, 1 << 7;
#[cfg(any(feature = "version-4-2", feature = "version-5-0"))]
const LE_READ_LOCAL_RESOLVABLE_ADDRESS = 35, 1 << 0;
#[cfg(any(feature = "version-4-2", feature = "version-5-0"))]
const LE_SET_ADDRESS_RESOLUTION_ENABLE = 35, 1 << 1;
#[cfg(any(feature = "version-4-2", feature = "version-5-0"))]
const LE_SET_RESOLVABLE_PRIVATE_ADDRESS_TIMEOUT = 35, 1 << 2;
#[cfg(any(feature = "version-4-2", feature = "version-5-0"))]
const LE_READ_MAXIMUM_DATA_LENGTH = 35, 1 << 3;
#[cfg(feature = "version-5-0")]
const LE_READ_PHY_COMMAND = 35, 1 << 4;
#[cfg(feature = "version-5-0")]
const LE_SET_DEFAULT_PHY_COMMAND = 35, 1 << 5;
#[cfg(feature = "version-5-0")]
const LE_SET_PHY_COMMAND = 35, 1 << 6;
#[cfg(feature = "version-5-0")]
const LE_ENHANCED_RECEIVER_TEST_COMMAND = 35, 1 << 7;
#[cfg(feature = "version-5-0")]
const LE_ENHANCED_TRANSMITTER_TEST_COMMAND = 36, 1 << 0;
#[cfg(feature = "version-5-0")]
const LE_SET_ADVERTISING_SET_RANDOM_ADDRESS_COMMAND = 36, 1 << 1;
#[cfg(feature = "version-5-0")]
const LE_SET_EXTENDED_ADVERTISING_PARAMETERS_COMMAND = 36, 1 << 2;
#[cfg(feature = "version-5-0")]
const LE_SET_EXTENDED_ADVERTISING_DATA_COMMAND = 36, 1 << 3;
#[cfg(feature = "version-5-0")]
const LE_SET_EXTENDED_SCAN_RESPONSE_DATA_COMMAND = 36, 1 << 4;
#[cfg(feature = "version-5-0")]
const LE_SET_EXTENDED_ADVERTISING_ENABLE_COMMAND = 36, 1 << 5;
#[cfg(feature = "version-5-0")]
const LE_READ_MAXIMUM_ADVERTISING_DATA_LENGTH_COMMAND = 36, 1 << 6;
#[cfg(feature = "version-5-0")]
const LE_READ_NUMBER_OF_SUPPORTED_ADVERTISING_SETS_COMMAND = 36, 1 << 7;
#[cfg(feature = "version-5-0")]
const LE_REMOVE_ADVERTISING_SET_COMMAND = 37, 1 << 0;
#[cfg(feature = "version-5-0")]
const LE_CLEAR_ADVERTISING_SETS_COMMAND = 37, 1 << 1;
#[cfg(feature = "version-5-0")]
const LE_SET_PERIODIC_ADVERTISING_PARAMETERS_COMMAND = 37, 1 << 2;
#[cfg(feature = "version-5-0")]
const LE_SET_PERIODIC_ADVERTISING_DATA_COMMAND = 37, 1 << 3;
#[cfg(feature = "version-5-0")]
const LE_SET_PERIODIC_ADVERTISING_ENABLE_COMMAND = 37, 1 << 4;
#[cfg(feature = "version-5-0")]
const LE_SET_EXTENDED_SCAN_PARAMETERS_COMMAND = 37, 1 << 5;
#[cfg(feature = "version-5-0")]
const LE_SET_EXTENDED_SCAN_ENABLE_COMMAND = 37, 1 << 6;
#[cfg(feature = "version-5-0")]
const LE_EXTENDED_CREATE_CONNECTION_COMMAND = 37, 1 << 7;
#[cfg(feature = "version-5-0")]
const LE_PERIODIC_ADVERTISING_CREATE_SYNC_COMMAND = 38, 1 << 0;
#[cfg(feature = "version-5-0")]
const LE_PERIODIC_ADVERTISING_CREATE_SYNC_CANCEL_COMMAND = 38, 1 << 1;
#[cfg(feature = "version-5-0")]
const LE_PERIODIC_ADVERTISING_TERMINATE_SYNC_COMMAND = 38, 1 << 2;
#[cfg(feature = "version-5-0")]
const LE_ADD_DEVICE_TO_PERIODIC_ADVERTISER_LIST_COMMAND = 38, 1 << 3;
#[cfg(feature = "version-5-0")]
const LE_REMOVE_DEVICE_FROM_PERIODIC_ADVERTISER_LIST_COMMAND = 38, 1 << 4;
#[cfg(feature = "version-5-0")]
const LE_CLEAR_PERIODIC_ADVERTISER_LIST_COMMAND = 38, 1 << 5;
#[cfg(feature = "version-5-0")]
const LE_READ_PERIODIC_ADVERTISER_LIST_SIZE_COMMAND = 38, 1 << 6;
#[cfg(feature = "version-5-0")]
const LE_READ_TRANSMIT_POWER_COMMAND = 38, 1 << 7;
#[cfg(feature = "version-5-0")]
const LE_READ_RF_PATH_COMPENSATION_COMMAND = 39, 1 << 0;
#[cfg(feature = "version-5-0")]
const LE_WRITE_RF_PATH_COMPENSATION_COMMAND = 39, 1 << 1;
#[cfg(feature = "version-5-0")]
const LE_SET_PRIVACY_MODE = 39, 1 << 2;
}
impl Debug for CommandFlags {
fn fmt(&self, f: &mut Formatter) -> FmtResult {
writeln!(f, "{:?}", &self.0[..16])?;
writeln!(f, "{:?}", &self.0[16..32])?;
writeln!(f, "{:?}", &self.0[32..39])
}
}
impl<'a> TryFrom<&'a [u8]> for CommandFlags {
type Error = ::event::Error<!>;
fn try_from(value: &[u8]) -> Result<CommandFlags, Self::Error> {
require_len!(value, COMMAND_FLAGS_SIZE);
CommandFlags::from_bits(value).ok_or(::event::Error::BadCommandFlag)
}
}
fn to_supported_commands<VE, VS>(
bytes: &[u8],
) -> Result<LocalSupportedCommands<VS>, ::event::Error<VE>>
where
::Status<VS>: TryFrom<u8, Error = ::BadStatusError>,
{
require_len!(bytes, 1 + COMMAND_FLAGS_SIZE);
Ok(LocalSupportedCommands {
status: bytes[0].try_into().map_err(super::rewrap_bad_status)?,
supported_commands: bytes[1..=COMMAND_FLAGS_SIZE]
.try_into()
.map_err(|e| match e {
::event::Error::BadLength(actual, expected) => {
return ::event::Error::BadLength(actual, expected);
}
::event::Error::BadCommandFlag => {
return ::event::Error::BadCommandFlag;
}
_ => unreachable!(),
})?,
})
}
#[derive(Copy, Clone, Debug)]
pub struct LocalSupportedFeatures<VS> {
pub status: ::Status<VS>,
pub supported_features: LmpFeatures,
}
bitflags! {
pub struct LmpFeatures : u64 {
const THREE_SLOT_PACKETS = 1 << 0;
const FIVE_SLOT_PACKETS = 1 << 1;
const ENCRYPTION = 1 << 2;
const SLOT_OFFSET = 1 << 3;
const TIMING_ACCURACY = 1 << 4;
const ROLE_SWITCH = 1 << 5;
const HOLD_MODE = 1 << 6;
const SNIFF_MODE = 1 << 7;
const POWER_CONTROL_REQUESTS = 1 << 9;
const CHANNEL_QUALITY_DRIVEN_DATA_RATE_CQDDR = 1 << 10;
const SCO_LINK = 1 << 11;
const HV2_PACKETS = 1 << 12;
const HV3_PACKETS = 1 << 13;
const MU_LAW_LOG_SYNCHRONOUS_DATA = 1 << 14;
const A_LAW_LOG_SYNCHRONOUS_DATA = 1 << 15;
const CVSD_SYNCHRONOUS_DATA = 1 << 16;
const PAGING_PARAMETER_NEGOTIATION = 1 << 17;
const POWER_CONTROL = 1 << 18;
const TRANSPARENT_SYNCHRONOUS_DATA = 1 << 19;
const FLOW_CONTROL_LAG_LSB = 1 << 20;
const FLOW_CONTROL_LAG_MID = 1 << 21;
const FLOW_CONTROL_LAG_MSB = 1 << 22;
const BROADCAST_ENCRYPTION = 1 << 23;
const ENHANCED_DATA_RATE_ACL_2_MB_PER_S_MODE = 1 << 25;
const ENHANCED_DATA_RATE_ACL_3_MB_PER_S_MODE = 1 << 26;
const ENHANCED_INQUIRY_SCAN = 1 << 27;
const INTERLACED_INQUIRY_SCAN = 1 << 28;
const INTERLACED_PAGE_SCAN = 1 << 29;
const RSSI_WITH_INQUIRY_RESULTS = 1 << 30;
const EXTENDED_SCO_LINK_EV3_PACKETS = 1 << 31;
const EV4_PACKETS = 1 << 32;
const EV5_PACKETS = 1 << 33;
const AFH_CAPABLE_PERIPHERAL = 1 << 35;
const AFH_CLASSIFICATION_PERIPHERAL = 1 << 36;
const BR_EDR_NOT_SUPPORTED = 1 << 37;
const LE_SUPPORTED_BY_CONTROLLER = 1 << 38;
const THREE_SLOT_ENHANCED_DATA_RATE_ACL_PACKETS = 1 << 39;
const FIVE_SLOT_ENHANCED_DATA_RATE_ACL_PACKETS = 1 << 40;
const SNIFF_SUBRATING = 1 << 41;
const PAUSE_ENCRYPTION = 1 << 42;
const AFH_CAPABLE_CENTRAL_DEVICE = 1 << 43;
const AFH_CLASSIFICATION_CENTRAL_DEVICE = 1 << 44;
const ENHANCED_DATA_RATE_ESCO_2_MB_PER_S_MODE = 1 << 45;
const ENHANCED_DATA_RATE_ESCO_3_MB_PER_S_MODE = 1 << 46;
const THREE_SLOT_ENHANCED_DATA_RATE_ESCO_PACKETS = 1 << 47;
const EXTENDED_INQUIRY_RESPONSE = 1 << 48;
const SIMULTANEOUS_LE_AND_BR_EDR_TO_SAME_DEVICE_CAPABLE = 1 << 49;
const SECURE_SIMPLE_PAIRING = 1 << 51;
const ENCAPSULATED_PDU = 1 << 52;
const ERRONEOUS_DATA_REPORTING = 1 << 53;
const NON_FLUSHABLE_PACKET_BOUNDARY_FLAG = 1 << 54;
const LINK_SUPERVISION_TIMEOUT_CHANGED_EVENT = 1 << 56;
const INQUIRY_TX_POWER_LEVEL = 1 << 57;
const ENHANCED_POWER_CONTROL = 1 << 58;
const EXTENDED_FEATURES = 1 << 63;
}
}
fn to_supported_features<VE, VS>(
bytes: &[u8],
) -> Result<LocalSupportedFeatures<VS>, ::event::Error<VE>>
where
::Status<VS>: TryFrom<u8, Error = ::BadStatusError>,
{
require_len!(bytes, 9);
Ok(LocalSupportedFeatures {
status: to_status(bytes)?,
supported_features: LmpFeatures::from_bits_truncate(LittleEndian::read_u64(&bytes[1..])),
})
}
#[derive(Copy, Clone, Debug)]
pub struct ReadBdAddr<VS> {
pub status: ::Status<VS>,
pub bd_addr: ::BdAddr,
}
fn to_bd_addr<VE, VS>(bytes: &[u8]) -> Result<ReadBdAddr<VS>, ::event::Error<VE>>
where
::Status<VS>: TryFrom<u8, Error = ::BadStatusError>,
{
require_len!(bytes, 7);
let mut bd_addr = ::BdAddr([0; 6]);
bd_addr.0.copy_from_slice(&bytes[1..]);
Ok(ReadBdAddr {
status: to_status(bytes)?,
bd_addr: bd_addr,
})
}
#[derive(Copy, Clone, Debug)]
pub struct ReadRssi<VS> {
pub status: ::Status<VS>,
pub conn_handle: ::ConnectionHandle,
pub rssi: i8,
}
fn to_read_rssi<VE, VS>(bytes: &[u8]) -> Result<ReadRssi<VS>, ::event::Error<VE>>
where
::Status<VS>: TryFrom<u8, Error = ::BadStatusError>,
{
require_len!(bytes, 4);
Ok(ReadRssi {
status: to_status(bytes)?,
conn_handle: ::ConnectionHandle(LittleEndian::read_u16(&bytes[1..])),
rssi: unsafe { mem::transmute::<u8, i8>(bytes[3]) },
})
}
#[derive(Copy, Clone, Debug)]
pub struct LeReadBufferSize<VS> {
pub status: ::Status<VS>,
pub data_packet_length: u16,
pub data_packet_count: u8,
}
fn to_le_read_buffer_status<VE, VS>(
bytes: &[u8],
) -> Result<LeReadBufferSize<VS>, ::event::Error<VE>>
where
::Status<VS>: TryFrom<u8, Error = ::BadStatusError>,
{
require_len!(bytes, 4);
Ok(LeReadBufferSize {
status: to_status(bytes)?,
data_packet_length: LittleEndian::read_u16(&bytes[1..]),
data_packet_count: bytes[3],
})
}
#[derive(Copy, Clone, Debug)]
pub struct LeSupportedFeatures<VS> {
pub status: ::Status<VS>,
pub supported_features: LeFeatures,
}
bitflags! {
pub struct LeFeatures : u64 {
const ENCRYPTION = 1 << 0;
const CONNECTION_PARAMETERS_REQUEST_PROCEDURE = 1 << 1;
const EXTENDED_REJECT_INDICATION = 1 << 2;
const PERIPHERALINITIATED_FEATURES_EXCHANGE = 1 << 3;
const PING = 1 << 4;
#[cfg(any(feature = "version-4-2", feature = "version-5-0"))]
const DATA_PACKET_LENGTH_EXTENSION = 1 << 5;
#[cfg(any(feature = "version-4-2", feature = "version-5-0"))]
const LL_PRIVACY = 1 << 6;
#[cfg(any(feature = "version-4-2", feature = "version-5-0"))]
const EXTENDED_SCANNER_FILTER_POLICIES = 1 << 7;
#[cfg(feature = "version-5-0")]
const PHY_2M = 1 << 8;
#[cfg(feature = "version-5-0")]
const STABLE_MODULATION_INDEX_TX = 1 << 9;
#[cfg(feature = "version-5-0")]
const STABLE_MODULATION_INDEX_RX = 1 << 10;
#[cfg(feature = "version-5-0")]
const CODED_PHY = 1 << 11;
#[cfg(feature = "version-5-0")]
const EXTENDED_ADVERTISING = 1 << 12;
#[cfg(feature = "version-5-0")]
const PERIODIC_ADVERTISING = 1 << 13;
#[cfg(feature = "version-5-0")]
const CHANNEL_SELECTION_ALGORITHM_2 = 1 << 14;
#[cfg(feature = "version-5-0")]
const POWER_CLASS_1 = 1 << 15;
#[cfg(feature = "version-5-0")]
const MINIMUM_NUMBER_OF_USED_CHANNELS_PROCEDURE = 1 << 16;
}
}
fn to_le_local_supported_features<VE, VS>(
bytes: &[u8],
) -> Result<LeSupportedFeatures<VS>, ::event::Error<VE>>
where
::Status<VS>: TryFrom<u8, Error = ::BadStatusError>,
{
require_len!(bytes, 9);
Ok(LeSupportedFeatures {
status: to_status(bytes)?,
supported_features: LeFeatures::from_bits_truncate(LittleEndian::read_u64(&bytes[1..])),
})
}
#[derive(Copy, Clone, Debug)]
pub struct LeAdvertisingChannelTxPower<VS> {
pub status: ::Status<VS>,
pub power: i8,
}
fn to_le_advertising_channel_tx_power<VE, VS>(
bytes: &[u8],
) -> Result<LeAdvertisingChannelTxPower<VS>, ::event::Error<VE>>
where
::Status<VS>: TryFrom<u8, Error = ::BadStatusError>,
{
require_len!(bytes, 2);
Ok(LeAdvertisingChannelTxPower {
status: to_status(bytes)?,
power: unsafe { mem::transmute::<u8, i8>(bytes[1]) },
})
}
#[cfg(not(feature = "version-5-0"))]
fn to_le_set_advertise_enable<V>(status: ::Status<V::Status>) -> ReturnParameters<V>
where
V: super::VendorEvent,
{
ReturnParameters::LeSetAdvertiseEnable(status)
}
#[cfg(feature = "version-5-0")]
fn to_le_set_advertise_enable<V>(status: ::Status<V::Status>) -> ReturnParameters<V>
where
V: super::VendorEvent,
{
ReturnParameters::LeSetAdvertisingEnable(status)
}
#[derive(Copy, Clone, Debug)]
pub struct ChannelMapParameters<VS> {
pub status: ::Status<VS>,
pub conn_handle: ::ConnectionHandle,
pub channel_map: ::ChannelClassification,
}
fn to_le_channel_map_parameters<VE, VS>(
bytes: &[u8],
) -> Result<ChannelMapParameters<VS>, ::event::Error<VE>>
where
::Status<VS>: TryFrom<u8, Error = ::BadStatusError>,
{
require_len!(bytes, 8);
let mut channel_bits = [0; 5];
channel_bits.copy_from_slice(&bytes[3..8]);
let channel_bits = channel_bits;
Ok(ChannelMapParameters {
status: to_status(&bytes[0..])?,
conn_handle: ::ConnectionHandle(LittleEndian::read_u16(&bytes[1..])),
channel_map: ::ChannelClassification::from_bits(&bytes[3..])
.ok_or(::event::Error::InvalidChannelMap(channel_bits))?,
})
}
#[derive(Copy, Clone, Debug)]
pub struct EncryptedReturnParameters<VS> {
pub status: ::Status<VS>,
pub encrypted_data: EncryptedBlock,
}
#[derive(Copy, Clone)]
pub struct EncryptedBlock(pub [u8; 16]);
impl Debug for EncryptedBlock {
fn fmt(&self, f: &mut Formatter) -> FmtResult {
writeln!(f, "AES-128 Encrypted Data ({:X?})", &self.0)
}
}
fn to_le_encrypted_data<VE, VS>(
bytes: &[u8],
) -> Result<EncryptedReturnParameters<VS>, ::event::Error<VE>>
where
::Status<VS>: TryFrom<u8, Error = ::BadStatusError>,
{
require_len!(bytes, 17);
let mut block = [0; 16];
block.copy_from_slice(&bytes[1..]);
Ok(EncryptedReturnParameters {
status: to_status(&bytes)?,
encrypted_data: EncryptedBlock(block),
})
}
#[derive(Copy, Clone, Debug)]
pub struct LeRandom<VS> {
pub status: ::Status<VS>,
pub random_number: u64,
}
fn to_random_number<VE, VS>(bytes: &[u8]) -> Result<LeRandom<VS>, ::event::Error<VE>>
where
::Status<VS>: TryFrom<u8, Error = ::BadStatusError>,
{
require_len!(bytes, 9);
Ok(LeRandom {
status: to_status(&bytes)?,
random_number: LittleEndian::read_u64(&bytes[1..]),
})
}
#[derive(Copy, Clone, Debug)]
pub struct LeLongTermRequestReply<VS> {
pub status: ::Status<VS>,
pub conn_handle: ::ConnectionHandle,
}
fn to_le_ltk_request_reply<VE, VS>(
bytes: &[u8],
) -> Result<LeLongTermRequestReply<VS>, ::event::Error<VE>>
where
::Status<VS>: TryFrom<u8, Error = ::BadStatusError>,
{
require_len!(bytes, 3);
Ok(LeLongTermRequestReply {
status: to_status(&bytes)?,
conn_handle: ::ConnectionHandle(LittleEndian::read_u16(&bytes[1..])),
})
}
#[derive(Copy, Clone, Debug)]
pub struct LeReadSupportedStates<VS> {
pub status: ::Status<VS>,
pub supported_states: LeStates,
}
bitflags! {
pub struct LeStates : u64 {
const NON_CONNECTABLE_ADVERTISING = 1 << 0;
const SCANNABLE_ADVERTISING = 1 << 1;
const CONNECTABLE_ADVERTISING = 1 << 2;
const DIRECTED_ADVERTISING_HIGH_DUTY_CYCLE = 1 << 3;
const PASSIVE_SCANNING = 1 << 4;
const ACTIVE_SCANNING = 1 << 5;
const INITIATING = 1 << 6;
const PERIPHERAL_CONNECTION = 1 << 7;
const NONCONN_AD_AND_PASS_SCAN = 1 << 8;
const SCAN_AD_AND_PASS_SCAN = 1 << 9;
const CONN_AD_AND_PASS_SCAN = 1 << 10;
const DIR_AD_HDC_AND_PASS_SCAN = 1 << 11;
const NONCONN_AD_AND_ACT_SCAN = 1 << 12;
const SCAN_AD_AND_ACT_SCAN = 1 << 13;
const CONN_AD_AND_ACT_SCAN = 1 << 14;
const DIR_AD_HDC_AND_ACT_SCAN = 1 << 15;
const NONCONN_AD_AND_INITIATING = 1 << 16;
const SCAN_AD_AND_INITIATING = 1 << 17;
const NONCONN_AD_AND_CENTRAL_CONN = 1 << 18;
const SCAN_AD_AND_CENTRAL_CONN = 1 << 19;
const NONCONN_AD_AND_PERIPH_CONN = 1 << 20;
const SCAN_AD_AND_PERIPH_CONN = 1 << 21;
const PASS_SCAN_AND_INITIATING = 1 << 22;
const ACT_SCAN_AND_INITIATING = 1 << 23;
const PASS_SCAN_AND_CENTRAL_CONN = 1 << 24;
const ACT_SCAN_AND_CENTRAL_CONN = 1 << 25;
const PASS_SCAN_AND_PERIPH_CONN = 1 << 26;
const ACT_SCAN_AND_PERIPH_CONN = 1 << 27;
const INITIATING_AND_CENTRAL_CONN = 1 << 28;
const DIRECTED_ADVERTISING_LOW_DUTY_CYCLE = 1 << 29;
const DIR_AD_LDC_AND_PASS_SCAN = 1 << 30;
const DIR_AD_LDC_AND_ACT_SCAN = 1 << 31;
const CONN_AD_AND_INITIATING = 1 << 32;
const DIR_AD_HDC_AND_INITIATING = 1 << 33;
const DIR_AD_LDC_AND_INITIATING = 1 << 34;
const CONN_AD_AND_CENTRAL_CONN = 1 << 35;
const DIR_AD_HDC_AND_CENTRAL_CONN = 1 << 36;
const DIR_AD_LDC_AND_CENTRAL_CONN = 1 << 37;
const CONN_AD_AND_PERIPH_CONN = 1 << 38;
const DIR_AD_HDC_AND_PERIPH_CONN = 1 << 39;
const DIR_AD_LDC_AND_PERIPH_CONN = 1 << 40;
const INITIATING_AND_PERIPH_CONN = 1 << 41;
}
}
fn to_le_read_states<VE, VS>(bytes: &[u8]) -> Result<LeReadSupportedStates<VS>, ::event::Error<VE>>
where
::Status<VS>: TryFrom<u8, Error = ::BadStatusError>,
{
require_len!(bytes, 9);
let bitfield = LittleEndian::read_u64(&bytes[1..]);
Ok(LeReadSupportedStates {
status: to_status(bytes)?,
supported_states: LeStates::from_bits(bitfield)
.ok_or(::event::Error::InvalidLeStates(bitfield))?,
})
}
#[derive(Copy, Clone, Debug)]
pub struct LeTestEnd<VS> {
pub status: ::Status<VS>,
pub number_of_packets: usize,
}
fn to_le_test_end<VE, VS>(bytes: &[u8]) -> Result<LeTestEnd<VS>, ::event::Error<VE>>
where
::Status<VS>: TryFrom<u8, Error = ::BadStatusError>,
{
require_len!(bytes, 3);
Ok(LeTestEnd {
status: to_status(bytes)?,
number_of_packets: LittleEndian::read_u16(&bytes[1..]) as usize,
})
}