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
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
/*
 * 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.
 */
 
#ifndef H_BLE_HCI_COMMON_
#define H_BLE_HCI_COMMON_
 
#include "ble.h"
#include "nimble/transport.h"
 
#ifdef __cplusplus
extern "C" {
#endif
 
#define BLE_HCI_MAX_DATA_LEN    (MYNEWT_VAL(BLE_TRANSPORT_EVT_SIZE) - \
                                 sizeof(struct ble_hci_ev))
 
/* Generic command header */
struct ble_hci_cmd {
    uint16_t opcode;
    uint8_t  length;
    uint8_t  data[0];
} __attribute__((packed));
 
/* Generic event header */
struct ble_hci_ev {
    uint8_t opcode;
    uint8_t length;
    uint8_t  data[0];
} __attribute__((packed));
 
#define BLE_HCI_OPCODE_NOP                  (0)
 
/* Set opcode based on OCF and OGF */
#define BLE_HCI_OP(ogf, ocf)            ((ocf) | ((ogf) << 10))
 
/* Get the OGF and OCF from the opcode in the command */
#define BLE_HCI_OGF(opcode)                 (((opcode) >> 10) & 0x003F)
#define BLE_HCI_OCF(opcode)                 ((opcode) & 0x03FF)
 
/* Opcode Group definitions (note: 0x07 not defined in spec) */
#define BLE_HCI_OGF_LINK_CTRL               (0x01)
#define BLE_HCI_OGF_LINK_POLICY             (0x02)
#define BLE_HCI_OGF_CTLR_BASEBAND           (0x03)
#define BLE_HCI_OGF_INFO_PARAMS             (0x04)
#define BLE_HCI_OGF_STATUS_PARAMS           (0x05)
#define BLE_HCI_OGF_TESTING                 (0x06)
#define BLE_HCI_OGF_LE                      (0x08)
#define BLE_HCI_OGF_VENDOR                  (0x3F)
 
/*
 * Number of LE commands. NOTE: this is really just used to size the array
 * containing the lengths of the LE commands.
 */
#define BLE_HCI_NUM_LE_CMDS                 (79)
 
/* List of OCF for Link Control commands (OGF=0x01) */
#define BLE_HCI_OCF_DISCONNECT_CMD          (0x0006)
struct ble_hci_lc_disconnect_cp {
    uint16_t conn_handle;
    uint8_t  reason;
} __attribute__((packed));
 
#define BLE_HCI_OCF_RD_REM_VER_INFO         (0x001D)
struct ble_hci_rd_rem_ver_info_cp {
    uint16_t conn_handle;
} __attribute__((packed));
 
/* List of OCF for Controller and Baseband commands (OGF=0x03) */
#define BLE_HCI_OCF_CB_SET_EVENT_MASK       (0x0001)
struct ble_hci_cb_set_event_mask_cp {
    uint64_t event_mask;
} __attribute__((packed));
 
#define BLE_HCI_OCF_CB_RESET                (0x0003)
 
#define BLE_HCI_OCF_CB_READ_TX_PWR          (0x002D)
struct ble_hci_cb_read_tx_pwr_cp {
    uint16_t conn_handle;
    uint8_t  type;
} __attribute__((packed));
 
struct ble_hci_cb_read_tx_pwr_rp {
    uint16_t conn_handle;
    int8_t   tx_level;
} __attribute__((packed));
 
 
#define BLE_HCI_OCF_CB_SET_CTLR_TO_HOST_FC  (0x0031)
struct ble_hci_cb_ctlr_to_host_fc_cp {
    uint8_t enable;
} __attribute__((packed));
 
#define BLE_HCI_OCF_CB_HOST_BUF_SIZE        (0x0033)
struct ble_hci_cb_host_buf_size_cp {
    uint16_t acl_data_len;
    uint8_t  sco_data_len;
    uint16_t acl_num;
    uint16_t sco_num;
} __attribute__((packed));
 
#define BLE_HCI_OCF_CB_HOST_NUM_COMP_PKTS   (0x0035)
struct  ble_hci_cb_host_num_comp_pkts_entry {
    uint16_t handle;
    uint16_t count;
} __attribute__((packed));
struct ble_hci_cb_host_num_comp_pkts_cp {
    uint8_t handles;
    struct ble_hci_cb_host_num_comp_pkts_entry h[0];
} __attribute__((packed));
 
#define BLE_HCI_OCF_CB_SET_EVENT_MASK2      (0x0063)
struct ble_hci_cb_set_event_mask2_cp {
    uint64_t event_mask2;
} __attribute__((packed));
 
#define BLE_HCI_OCF_CB_RD_AUTH_PYLD_TMO     (0x007B)
struct ble_hci_cb_rd_auth_pyld_tmo_cp {
    uint16_t conn_handle;
} __attribute__((packed));
struct ble_hci_cb_rd_auth_pyld_tmo_rp {
    uint16_t conn_handle;
    uint16_t tmo;
} __attribute__((packed));
 
#define BLE_HCI_OCF_CB_WR_AUTH_PYLD_TMO     (0x007C)
struct ble_hci_cb_wr_auth_pyld_tmo_cp {
    uint16_t conn_handle;
    uint16_t tmo;
} __attribute__((packed));
struct ble_hci_cb_wr_auth_pyld_tmo_rp {
    uint16_t conn_handle;
} __attribute__((packed));
 
/* List of OCF for Info Param commands (OGF=0x04) */
#define BLE_HCI_OCF_IP_RD_LOCAL_VER         (0x0001)
struct ble_hci_ip_rd_local_ver_rp {
    uint8_t  hci_ver;
    uint16_t hci_rev;
    uint8_t  lmp_ver;
    uint16_t manufacturer;
    uint16_t lmp_subver;
} __attribute__((packed));
 
#define BLE_HCI_OCF_IP_RD_LOC_SUPP_CMD      (0x0002)
struct ble_hci_ip_rd_loc_supp_cmd_rp {
    uint8_t commands[64];
} __attribute__((packed));
 
#define BLE_HCI_OCF_IP_RD_LOC_SUPP_FEAT     (0x0003)
struct ble_hci_ip_rd_loc_supp_feat_rp {
    uint64_t features;
} __attribute__((packed));
 
#define BLE_HCI_OCF_IP_RD_BUF_SIZE          (0x0005)
struct ble_hci_ip_rd_buf_size_rp {
    uint16_t acl_data_len;
    uint8_t  sco_data_len;
    uint16_t acl_num;
    uint16_t sco_num;
} __attribute__((packed));
 
#define BLE_HCI_OCF_IP_RD_BD_ADDR           (0x0009)
struct ble_hci_ip_rd_bd_addr_rp {
    uint8_t addr[6];
} __attribute__((packed));
 
/* List of OCF for Status parameters commands (OGF = 0x05) */
#define BLE_HCI_OCF_RD_RSSI                 (0x0005)
struct ble_hci_rd_rssi_cp {
    uint16_t handle;
} __attribute__((packed));
struct ble_hci_rd_rssi_rp {
    uint16_t handle;
    int8_t   rssi;
} __attribute__((packed));
 
/* List of OCF for LE commands (OGF = 0x08) */
#define BLE_HCI_OCF_LE_SET_EVENT_MASK               (0x0001)
struct ble_hci_le_set_event_mask_cp {
    uint64_t event_mask;
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_RD_BUF_SIZE                  (0x0002)
struct ble_hci_le_rd_buf_size_rp {
    uint16_t data_len;
    uint8_t  data_packets;
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_RD_BUF_SIZE_V2                    (0x0060)
struct ble_hci_le_rd_buf_size_v2_rp {
    uint16_t data_len;
    uint8_t  data_packets;
    uint16_t iso_data_len;
    uint8_t  iso_data_packets;
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_RD_LOC_SUPP_FEAT             (0x0003)
struct ble_hci_le_rd_loc_supp_feat_rp {
    uint64_t features;
} __attribute__((packed));
 
/* NOTE: 0x0004 is intentionally left undefined */
#define BLE_HCI_OCF_LE_SET_RAND_ADDR                (0x0005)
struct ble_hci_le_set_rand_addr_cp {
    uint8_t addr[6];
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_SET_ADV_PARAMS               (0x0006)
struct ble_hci_le_set_adv_params_cp {
    uint16_t min_interval;
    uint16_t max_interval;
    uint8_t type;
    uint8_t own_addr_type;
    uint8_t peer_addr_type;
    uint8_t peer_addr[6];
    uint8_t chan_map;
    uint8_t filter_policy;
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_RD_ADV_CHAN_TXPWR            (0x0007)
struct ble_hci_le_rd_adv_chan_txpwr_rp {
    int8_t power_level;
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_SET_ADV_DATA                 (0x0008)
#define BLE_HCI_MAX_ADV_DATA_LEN                    (31)
struct ble_hci_le_set_adv_data_cp {
    uint8_t adv_data_len;
    uint8_t adv_data[BLE_HCI_MAX_ADV_DATA_LEN];
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_SET_SCAN_RSP_DATA            (0x0009)
#define BLE_HCI_MAX_SCAN_RSP_DATA_LEN               (31)
struct ble_hci_le_set_scan_rsp_data_cp {
    uint8_t scan_rsp_len;
    uint8_t scan_rsp[BLE_HCI_MAX_SCAN_RSP_DATA_LEN];
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_SET_ADV_ENABLE               (0x000A)
struct ble_hci_le_set_adv_enable_cp {
    uint8_t enable;
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_SET_SCAN_PARAMS              (0x000B)
struct ble_hci_le_set_scan_params_cp {
    uint8_t  scan_type;
    uint16_t scan_itvl;
    uint16_t scan_window;
    uint8_t  own_addr_type;
    uint8_t  filter_policy;
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_SET_SCAN_ENABLE              (0x000C)
struct ble_hci_le_set_scan_enable_cp {
    uint8_t enable;
    uint8_t filter_duplicates;
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_CREATE_CONN                  (0x000D)
struct ble_hci_le_create_conn_cp {
    uint16_t scan_itvl;
    uint16_t scan_window;
    uint8_t  filter_policy;
    uint8_t  peer_addr_type;
    uint8_t  peer_addr[6];
    uint8_t  own_addr_type;
    uint16_t min_conn_itvl;
    uint16_t max_conn_itvl;
    uint16_t conn_latency;
    uint16_t tmo;
    uint16_t min_ce;
    uint16_t max_ce;
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_CREATE_CONN_CANCEL           (0x000E)
 
#define BLE_HCI_OCF_LE_RD_WHITE_LIST_SIZE           (0x000F)
struct ble_hci_le_rd_white_list_rp {
    uint8_t size;
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_CLEAR_WHITE_LIST             (0x0010)
 
#define BLE_HCI_OCF_LE_ADD_WHITE_LIST               (0x0011)
struct ble_hci_le_add_whte_list_cp {
    uint8_t addr_type;
    uint8_t addr[6];
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_RMV_WHITE_LIST               (0x0012)
struct ble_hci_le_rmv_white_list_cp {
    uint8_t addr_type;
    uint8_t addr[6];
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_CONN_UPDATE                  (0x0013)
struct ble_hci_le_conn_update_cp {
    uint16_t conn_handle;
    uint16_t conn_itvl_min;
    uint16_t conn_itvl_max;
    uint16_t conn_latency;
    uint16_t supervision_timeout;
    uint16_t min_ce_len;
    uint16_t max_ce_len;
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_SET_HOST_CHAN_CLASS          (0x0014)
struct ble_hci_le_set_host_chan_class_cp {
    uint8_t chan_map[5];
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_RD_CHAN_MAP                  (0x0015)
struct ble_hci_le_rd_chan_map_cp {
    uint16_t conn_handle;
} __attribute__((packed));
struct ble_hci_le_rd_chan_map_rp {
    uint16_t conn_handle;
    uint8_t chan_map[5];
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_RD_REM_FEAT                  (0x0016)
struct ble_hci_le_rd_rem_feat_cp {
    uint16_t conn_handle;
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_ENCRYPT                      (0x0017)
struct ble_hci_le_encrypt_cp {
    uint8_t key[16];
    uint8_t data[16];
} __attribute__((packed));
struct ble_hci_le_encrypt_rp {
    uint8_t data[16];
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_RAND                         (0x0018)
struct ble_hci_le_rand_rp {
    uint64_t random_number;
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_START_ENCRYPT                (0x0019)
struct ble_hci_le_start_encrypt_cp {
    uint16_t conn_handle;
    uint64_t rand;
    uint16_t div;
    uint8_t  ltk[16];
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_LT_KEY_REQ_REPLY             (0x001A)
struct ble_hci_le_lt_key_req_reply_cp {
    uint16_t conn_handle;
    uint8_t  ltk[16];
} __attribute__((packed));
struct ble_hci_le_lt_key_req_reply_rp {
    uint16_t conn_handle;
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_LT_KEY_REQ_NEG_REPLY         (0x001B)
struct ble_hci_le_lt_key_req_neg_reply_cp {
    uint16_t conn_handle;
} __attribute__((packed));
struct ble_hci_le_lt_key_req_neg_reply_rp {
    uint16_t conn_handle;
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_RD_SUPP_STATES               (0x001C)
struct ble_hci_le_rd_supp_states_rp {
    uint64_t states;
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_RX_TEST                      (0x001D)
struct ble_hci_le_rx_test_cp {
    uint8_t rx_chan;
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_TX_TEST                      (0x001E)
struct ble_hci_le_tx_test_cp {
    uint8_t tx_chan;
    uint8_t test_data_len;
    uint8_t payload;
} __attribute__((packed));
#if MYNEWT_VAL(BLE_LL_DTM_EXTENSIONS)
struct ble_hci_le_tx_test_ext_cp {
    uint8_t tx_chan;
    uint8_t test_data_len;
    uint8_t payload;
    uint16_t interval;
    uint16_t pkt_count;
} __attribute__((packed));
#endif
 
#define BLE_HCI_OCF_LE_TEST_END                     (0x001F)
struct ble_hci_le_test_end_rp {
    uint16_t num_packets;
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_REM_CONN_PARAM_RR            (0x0020)
struct ble_hci_le_rem_conn_param_rr_cp {
    uint16_t conn_handle;
    uint16_t conn_itvl_min;
    uint16_t conn_itvl_max;
    uint16_t conn_latency;
    uint16_t supervision_timeout;
    uint16_t min_ce;
    uint16_t max_ce;
} __attribute__((packed));
struct ble_hci_le_rem_conn_param_rr_rp {
    uint16_t conn_handle;
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_REM_CONN_PARAM_NRR           (0x0021)
struct ble_hci_le_rem_conn_params_nrr_cp {
    uint16_t conn_handle;
    uint8_t  reason;
} __attribute__((packed));
struct ble_hci_le_rem_conn_params_nrr_rp {
    uint16_t conn_handle;
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_SET_DATA_LEN                 (0x0022)
struct ble_hci_le_set_data_len_cp {
    uint16_t conn_handle;
    uint16_t tx_octets;
    uint16_t tx_time;
} __attribute__((packed));
struct ble_hci_le_set_data_len_rp {
    uint16_t conn_handle;
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_RD_SUGG_DEF_DATA_LEN         (0x0023)
struct ble_hci_le_rd_sugg_def_data_len_rp {
    uint16_t max_tx_octets;
    uint16_t max_tx_time;
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_WR_SUGG_DEF_DATA_LEN         (0x0024)
struct ble_hci_le_wr_sugg_def_data_len_cp {
    uint16_t max_tx_octets;
    uint16_t max_tx_time;
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_RD_P256_PUBKEY               (0x0025)
 
#define BLE_HCI_OCF_LE_GEN_DHKEY                    (0x0026)
struct ble_hci_le_gen_dhkey_cp {
    uint8_t pkey[64];
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_ADD_RESOLV_LIST              (0x0027)
struct ble_hci_le_add_resolv_list_cp {
    uint8_t peer_addr_type;
    uint8_t peer_id_addr[6];
    uint8_t peer_irk[16];
    uint8_t local_irk[16];
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_RMV_RESOLV_LIST              (0x0028)
struct ble_hci_le_rmv_resolve_list_cp {
    uint8_t peer_addr_type;
    uint8_t peer_id_addr[6];
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_CLR_RESOLV_LIST              (0x0029)
 
#define BLE_HCI_OCF_LE_RD_RESOLV_LIST_SIZE          (0x002A)
struct ble_hci_le_rd_resolv_list_size_rp {
    uint8_t size;
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_RD_PEER_RESOLV_ADDR          (0x002B)
struct ble_hci_le_rd_peer_resolv_addr_cp {
    uint8_t peer_addr_type;
    uint8_t peer_id_addr[6];
} __attribute__((packed));
struct ble_hci_le_rd_peer_resolv_addr_rp {
    uint8_t rpa[6];
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_RD_LOCAL_RESOLV_ADDR         (0x002C)
struct ble_hci_le_rd_local_resolv_addr_cp {
    uint8_t peer_addr_type;
    uint8_t peer_id_addr[6];
} __attribute__((packed));
struct ble_hci_le_rd_local_resolv_addr_rp {
    uint8_t rpa[6];
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_SET_ADDR_RES_EN              (0x002D)
struct ble_hci_le_set_addr_res_en_cp {
    uint8_t enable;
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_SET_RPA_TMO                  (0x002E)
struct ble_hci_le_set_rpa_tmo_cp {
    uint16_t rpa_timeout;
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_RD_MAX_DATA_LEN              (0x002F)
struct ble_hci_le_rd_max_data_len_rp {
    uint16_t max_tx_octests;
    uint16_t max_tx_time;
    uint16_t max_rx_octests;
    uint16_t max_rx_time;
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_RD_PHY                       (0x0030)
struct ble_hci_le_rd_phy_cp {
    uint16_t conn_handle;
} __attribute__((packed));
struct ble_hci_le_rd_phy_rp {
    uint16_t conn_handle;
    uint8_t tx_phy;
    uint8_t rx_phy;
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_SET_DEFAULT_PHY              (0x0031)
struct ble_hci_le_set_default_phy_cp {
    uint8_t all_phys;
    uint8_t tx_phys;
    uint8_t rx_phys;
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_SET_PHY                      (0x0032)
struct ble_hci_le_set_phy_cp {
    uint16_t conn_handle;
    uint8_t all_phys;
    uint8_t tx_phys;
    uint8_t rx_phys;
    uint16_t phy_options;
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_RX_TEST_V2                  (0x0033)
struct ble_hci_le_rx_test_v2_cp {
    uint8_t rx_chan;
    uint8_t phy;
    uint8_t index;
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_TX_TEST_V2                  (0x0034)
struct ble_hci_le_tx_test_v2_cp {
    uint8_t tx_chan;
    uint8_t test_data_len;
    uint8_t payload;
    uint8_t phy;
} __attribute__((packed));
#if MYNEWT_VAL(BLE_LL_DTM_EXTENSIONS)
struct ble_hci_le_tx_test_v2_ext_cp {
    uint8_t tx_chan;
    uint8_t test_data_len;
    uint8_t payload;
    uint8_t phy;
    uint16_t interval;
    uint16_t pkt_count;
} __attribute__((packed));
#endif
 
#define BLE_HCI_OCF_LE_SET_ADV_SET_RND_ADDR         (0x0035)
struct ble_hci_le_set_adv_set_rnd_addr_cp {
    uint8_t adv_handle;
    uint8_t addr[6];
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_SET_EXT_ADV_PARAM            (0x0036)
struct ble_hci_le_set_ext_adv_params_cp {
    uint8_t  adv_handle;
    uint16_t props;
    uint8_t  pri_itvl_min[3];
    uint8_t  pri_itvl_max[3];
    uint8_t pri_chan_map;
    uint8_t own_addr_type;
    uint8_t peer_addr_type;
    uint8_t peer_addr[6];
    uint8_t filter_policy;
    int8_t tx_power;
    uint8_t pri_phy;
    uint8_t sec_max_skip;
    uint8_t sec_phy;
    uint8_t sid;
    uint8_t scan_req_notif;
} __attribute__((packed));
struct ble_hci_le_set_ext_adv_params_rp {
    int8_t  tx_power;
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_SET_EXT_ADV_DATA             (0x0037)
struct ble_hci_le_set_ext_adv_data_cp {
    uint8_t adv_handle;
    uint8_t operation;
    uint8_t fragment_pref;
    uint8_t adv_data_len;
    uint8_t adv_data[0];
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_SET_EXT_SCAN_RSP_DATA        (0x0038)
struct ble_hci_le_set_ext_scan_rsp_data_cp {
    uint8_t adv_handle;
    uint8_t operation;
    uint8_t fragment_pref;
    uint8_t scan_rsp_len;
    uint8_t scan_rsp[0];
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_SET_EXT_ADV_ENABLE           (0x0039)
struct adv_set {
    uint8_t adv_handle;
    uint16_t duration;
    uint8_t max_events;
} __attribute__((packed));
struct ble_hci_le_set_ext_adv_enable_cp {
    uint8_t enable;
    uint8_t num_sets;
    struct adv_set sets[0];
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_RD_MAX_ADV_DATA_LEN          (0x003A)
struct ble_hci_le_rd_max_adv_data_len_rp {
    uint16_t max_adv_data_len;
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_RD_NUM_OF_ADV_SETS           (0x003B)
struct ble_hci_le_rd_num_of_adv_sets_rp {
    uint8_t num_sets;
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_REMOVE_ADV_SET               (0x003C)
struct ble_hci_le_remove_adv_set_cp {
    uint8_t adv_handle;
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_CLEAR_ADV_SETS               (0x003D)
 
#define BLE_HCI_OCF_LE_SET_PERIODIC_ADV_PARAMS      (0x003E)
struct ble_hci_le_set_periodic_adv_params_cp {
    uint8_t adv_handle;
    uint16_t min_itvl;
    uint16_t max_itvl;
    uint16_t props;
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_SET_PERIODIC_ADV_DATA        (0x003F)
struct ble_hci_le_set_periodic_adv_data_cp {
    uint8_t adv_handle;
    uint8_t operation;
    uint8_t adv_data_len;
    uint8_t adv_data[0];
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_SET_PERIODIC_ADV_ENABLE      (0x0040)
struct ble_hci_le_set_periodic_adv_enable_cp {
    uint8_t enable;
    uint8_t adv_handle;
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_SET_EXT_SCAN_PARAM           (0x0041)
struct scan_params {
    uint8_t  type;
    uint16_t itvl;
    uint16_t window;
} __attribute__((packed));
struct ble_hci_le_set_ext_scan_params_cp {
    uint8_t own_addr_type;
    uint8_t filter_policy;
    uint8_t phys;
    struct scan_params scans[0];
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_SET_EXT_SCAN_ENABLE          (0x0042)
struct ble_hci_le_set_ext_scan_enable_cp {
    uint8_t  enable;
    uint8_t  filter_dup;
    uint16_t duration;
    uint16_t period;
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_EXT_CREATE_CONN              (0x0043)
struct conn_params {
    uint16_t scan_itvl;
    uint16_t scan_window;
    uint16_t conn_min_itvl;
    uint16_t conn_max_itvl;
    uint16_t conn_latency;
    uint16_t supervision_timeout;
    uint16_t min_ce;
    uint16_t max_ce;
} __attribute__((packed));
struct ble_hci_le_ext_create_conn_cp {
    uint8_t filter_policy;
    uint8_t own_addr_type;
    uint8_t peer_addr_type;
    uint8_t peer_addr[6];
    uint8_t init_phy_mask;
    struct conn_params conn_params[0];
} __attribute__((packed));
 
#define BLE_HCI_LE_PERIODIC_ADV_CREATE_SYNC_OPT_FILTER      0x01
#define BLE_HCI_LE_PERIODIC_ADV_CREATE_SYNC_OPT_DISABLED    0x02
#define BLE_HCI_LE_PERIODIC_ADV_CREATE_SYNC_OPT_DUPLICATES  0x04
 
#define BLE_HCI_OCF_LE_PERIODIC_ADV_CREATE_SYNC          (0x0044)
struct ble_hci_le_periodic_adv_create_sync_cp {
    uint8_t  options;
    uint8_t  sid;
    uint8_t  peer_addr_type;
    uint8_t  peer_addr[6];
    uint16_t skip;
    uint16_t sync_timeout;
    uint8_t  sync_cte_type;
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_PERIODIC_ADV_CREATE_SYNC_CANCEL   (0x0045)
 
#define BLE_HCI_OCF_LE_PERIODIC_ADV_TERM_SYNC            (0x0046)
struct ble_hci_le_periodic_adv_term_sync_cp {
    uint16_t sync_handle;
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_ADD_DEV_TO_PERIODIC_ADV_LIST      (0x0047)
struct ble_hci_le_add_dev_to_periodic_adv_list_cp {
    uint8_t peer_addr_type;
    uint8_t peer_addr[6];
    uint8_t sid;
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_REM_DEV_FROM_PERIODIC_ADV_LIST    (0x0048)
struct ble_hci_le_rem_dev_from_periodic_adv_list_cp {
    uint8_t peer_addr_type;
    uint8_t peer_addr[6];
    uint8_t sid;
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_CLEAR_PERIODIC_ADV_LIST           (0x0049)
 
#define BLE_HCI_OCF_LE_RD_PERIODIC_ADV_LIST_SIZE         (0x004A)
struct ble_hci_le_rd_periodic_adv_list_size_rp {
    uint8_t list_size;
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_RD_TRANSMIT_POWER            (0x004B)
struct ble_hci_le_rd_transmit_power_rp {
    int8_t min_tx_power;
    int8_t max_tx_power;
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_RD_RF_PATH_COMPENSATION      (0x004C)
struct ble_hci_le_rd_rf_path_compensation_rp {
    int16_t tx_path_compensation;
    int16_t rx_path_compensation;
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_WR_RF_PATH_COMPENSATION      (0x004D)
struct ble_hci_le_wr_rf_path_compensation_cp {
    int16_t tx_path_compensation;
    int16_t rx_path_compensation;
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_SET_PRIVACY_MODE             (0x004E)
struct ble_hci_le_set_privacy_mode_cp {
    uint8_t peer_id_addr_type;
    uint8_t peer_id_addr[6];
    uint8_t mode;
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_RX_TEST_V3                        (0x004F)
#define BLE_HCI_OCF_LE_TX_TEST_V3                        (0x0050)
#define BLE_HCI_OCF_LE_SET_CONNLESS_CTE_TX_PARAMS        (0x0051)
#define BLE_HCI_OCF_LE_SET_CONNLESS_CTE_TX_ENABLE        (0x0052)
#define BLE_HCI_OCF_LE_SET_CONNLESS_IQ_SAMPLING_ENABLE   (0x0053)
#define BLE_HCI_OCF_LE_SET_CONN_CTE_RX_PARAMS            (0x0054)
#define BLE_HCI_OCF_LE_SET_CONN_CTE_TX_PARAMS            (0x0055)
#define BLE_HCI_OCF_LE_SET_CONN_CTE_REQ_ENABLE           (0x0056)
#define BLE_HCI_OCF_LE_SET_CONN_CTE_RESP_ENABLE          (0x0057)
#define BLE_HCI_OCF_LE_RD_ANTENNA_INFO                   (0x0058)
 
#define BLE_HCI_OCF_LE_PERIODIC_ADV_RECEIVE_ENABLE       (0x0059)
struct ble_hci_le_periodic_adv_receive_enable_cp {
    uint16_t sync_handle;
    uint8_t enable;
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_PERIODIC_ADV_SYNC_TRANSFER        (0x005A)
struct ble_hci_le_periodic_adv_sync_transfer_cp {
    uint16_t conn_handle;
    uint16_t service_data;
    uint16_t sync_handle;
} __attribute__((packed));
struct ble_hci_le_periodic_adv_sync_transfer_rp {
    uint16_t conn_handle;
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_PERIODIC_ADV_SET_INFO_TRANSFER    (0x005B)
struct ble_hci_le_periodic_adv_set_info_transfer_cp {
    uint16_t conn_handle;
    uint16_t service_data;
    uint8_t adv_handle;
} __attribute__((packed));
struct ble_hci_le_periodic_adv_set_info_transfer_rp {
    uint16_t conn_handle;
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_PERIODIC_ADV_SYNC_TRANSFER_PARAMS (0x005C)
struct ble_hci_le_periodic_adv_sync_transfer_params_cp {
    uint16_t conn_handle;
    uint8_t  mode;
    uint16_t skip;
    uint16_t sync_timeout;
    uint8_t  sync_cte_type;
} __attribute__((packed));
struct ble_hci_le_periodic_adv_sync_transfer_params_rp {
    uint16_t conn_handle;
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_SET_DEFAULT_SYNC_TRANSFER_PARAMS  (0x005D)
struct ble_hci_le_set_default_periodic_sync_transfer_params_cp {
    uint8_t  mode;
    uint16_t skip;
    uint16_t sync_timeout;
    uint8_t  sync_cte_type;
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_GENERATE_DHKEY_V2                 (0x005E)
#define BLE_HCI_OCF_LE_MODIFY_SCA                        (0x005F)
 
#if MYNEWT_VAL(BLE_ISO)
#define BLE_HCI_OCF_LE_READ_ISO_TX_SYNC                  (0x0061)
struct ble_hci_le_read_iso_tx_sync_cp {
    uint16_t conn_handle;
} __attribute__((packed));
 
struct ble_hci_le_read_iso_tx_sync_rp {
    uint16_t conn_handle;
    uint16_t packet_seq_num;
    uint32_t timestamp;
    uint8_t timeoffset[3];
} __attribute__((packed));
 
#define BLE_HCI_LE_SET_CIG_CIS_MAX_NUM                   (0x1F)
#define BLE_HCI_OCF_LE_SET_CIG_PARAM                     (0x0062)
struct ble_hci_le_cis_params {
    uint8_t cis_id;
    uint16_t max_sdu_mtos;
    uint16_t max_sdu_stom;
    uint8_t phy_mtos;
    uint8_t phy_stom;
    uint8_t rnt_mtos;
    uint8_t rnt_stom;
} __attribute__((packed));
 
struct ble_hci_le_set_cig_params_cp {
    uint8_t cig_id;
    uint8_t sdu_interval_mtos[3];
    uint8_t sdu_interval_stom[3];
    uint8_t sca;
    uint8_t packing;
    uint8_t framing;
    uint16_t max_latency_mtos;
    uint16_t max_latency_stom;
    uint8_t cis_cnt;
    struct ble_hci_le_cis_params cis_params[0];
} __attribute__((packed));
 
struct ble_hci_le_set_cig_params_rp {
    uint8_t cig_id;
    uint8_t cis_cnt;
    uint16_t cis_handle[0];
} __attribute__((packed));
 
#if MYNEWT_VAL(BLE_ISO_TEST)
#define BLE_HCI_OCF_LE_SET_CIG_PARAM_TEST                (0x0063)
struct ble_hci_le_cis_params_test {
    uint8_t cis_id;
    uint8_t nse;
    uint16_t max_sdu_mtos;
    uint16_t max_sdu_stom;
    uint16_t max_pdu_mtos;
    uint16_t max_pdu_stom;
    uint8_t phy_mtos;
    uint8_t phy_stom;
    uint8_t bn_mtos;
    uint8_t bn_stom;
} __attribute__((packed));
 
struct ble_hci_le_set_cig_params_test_cp {
    uint8_t cig_id;
    uint8_t sdu_interval_mtos[3];
    uint8_t sdu_interval_stom[3];
    uint8_t ft_mtos;
    uint8_t ft_stom;
    uint16_t iso_interval;
    uint8_t sca;
    uint8_t packing;
    uint8_t framing;
    uint8_t cis_cnt;
    struct ble_hci_le_cis_params_test cis_params[0];
} __attribute__((packed));
#endif
 
#define BLE_HCI_LE_CREATE_CIS_MAX_CIS_NUM                (0x1F)
#define BLE_HCI_OCF_LE_CREATE_CIS                        (0x0064)
struct ble_hci_le_create_cis_params {
    uint16_t cis_handle;
    uint16_t conn_handle;
} __attribute__((packed));
 
struct ble_hci_le_create_cis_cp {
    uint8_t cis_cnt;
    struct ble_hci_le_create_cis_params params[0];
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_REMOVE_CIG                        (0x0065)
struct ble_hci_le_remove_cig_cp {
    uint8_t cig_id;
} __attribute__((packed));
 
struct ble_hci_le_remove_cig_rp {
    uint8_t cig_id;
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_ACCEPT_CIS_REQ                    (0x0066)
struct ble_hci_le_accept_cis_request_cp {
    uint16_t cis_handle;
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_REJECT_CIS_REQ                    (0x0067)
struct ble_hci_le_reject_cis_request_cp {
    uint16_t cis_handle;
    uint8_t reason;
} __attribute__((packed));
 
struct ble_hci_le_reject_cis_request_rp {
    uint16_t conn_handle;
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_CREATE_BIG                        (0x0068)
struct ble_hci_le_create_big_cp {
    uint8_t big_handle;
    uint8_t adv_handle;
    uint8_t bis_cnt;
    uint8_t sdu_interval[3];
    uint16_t max_sdu;
    uint16_t max_transport_latency;
    uint8_t rnt;
    uint8_t phy;
    uint8_t packing;
    uint8_t framing;
    uint8_t encryption;
    uint8_t broadcast_code[16];
} __attribute__((packed));
 
#if MYNEWT_VAL(BLE_ISO_TEST)
#define BLE_HCI_OCF_LE_CREATE_BIG_TEST                   (0x0069)
struct ble_hci_le_create_big_test_cp {
    uint8_t big_handle;
    uint8_t adv_handle;
    uint8_t bis_cnt;
    uint8_t sdu_interval[3];
    uint16_t iso_interval;
    uint8_t nse;
    uint16_t max_sdu;
    uint16_t max_pdu;
    uint8_t phy;
    uint8_t packing;
    uint8_t framing;
    uint8_t bn;
    uint8_t irc;
    uint8_t pto;
    uint8_t encryption;
    uint8_t broadcast_code[16];
} __attribute__((packed));
#endif
 
#define BLE_HCI_OCF_LE_TERMINATE_BIG                     (0x006a)
struct ble_hci_le_terminate_big_cp {
    uint8_t big_handle;
    uint8_t reason;
} __attribute__((packed));
 
#define BLE_HCI_LE_BIG_CREATE_SYNC_LEN_MIN               (25)
#define BLE_HCI_OCF_LE_BIG_CREATE_SYNC                   (0x006b)
struct ble_hci_le_big_create_sync_cp {
    uint8_t big_handle;
    uint16_t sync_handle;
    uint8_t big_cnt;
    uint8_t encryption;
    uint8_t broadcast_code[16];
    uint8_t mse;
    uint16_t timeout;
    uint8_t bis[0];
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_BIG_TERMINATE_SYNC                (0x006c)
struct ble_hci_le_terminate_big_sync_cp {
    uint8_t big_handle;
} __attribute__((packed));
#endif
 
#define BLE_HCI_OCF_LE_REQ_PEER_SCA                      (0x006d)
struct ble_hci_le_request_peer_sca_cp {
    uint16_t conn_handle;
} __attribute__((packed));
 
#if MYNEWT_VAL(BLE_ISO)
#define BLE_HCI_OCF_LE_SETUP_ISO_DATA_PATH               (0x006e)
struct ble_hci_le_iso_setup_data_path_cp {
    uint16_t iso_handle;
    uint8_t direction;
    uint8_t id;
    uint8_t codec_id[5];
    uint8_t controller_delay[3];
    uint8_t codec_conf_len;
    uint8_t codec_conf[0];
} __attribute__((packed));
 
#define BLE_HCI_LE_REMOVE_INPUT_DATA_PATH_BIT            (0x01)
#define BLE_HCI_LE_REMOVE_OUTPUT_DATA_PATH_BIT           (0x02)
#define BLE_HCI_OCF_LE_REMOVE_ISO_DATA_PATH              (0x006f)
struct ble_hci_le_iso_remove_data_path_cp {
    uint16_t iso_handle;
    uint8_t direction;
} __attribute__((packed));
 
#if MYNEWT_VAL(BLE_ISO_TEST)
#define BLE_HCI_OCF_LE_ISO_TRANSMIT_TEST                 (0x0070)
struct ble_hci_le_iso_transmit_test_cp {
    uint16_t iso_handle;
    uint8_t payload_type;
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_ISO_RECEIVE_TEST                  (0x0071)
struct ble_hci_le_iso_receive_test_cp {
    uint16_t iso_handle;
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_ISO_READ_TEST_COUNTERS            (0x0072)
struct ble_hci_le_iso_read_test_counters_cp {
    uint16_t iso_handle;
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_ISO_TEST_END                      (0x0073)
struct ble_hci_le_iso_test_end_cp {
    uint16_t iso_handle;
} __attribute__((packed));
#endif
#endif
 
#define BLE_HCI_OCF_LE_SET_HOST_FEAT                     (0x0074)
struct ble_hci_le_set_host_feat_cp {
    uint8_t bit_num;
    uint8_t val;
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_SET_DEFAULT_SUBRATE               (0x007D)
struct ble_hci_le_set_default_subrate_cp {
    uint16_t subrate_min;
    uint16_t subrate_max;
    uint16_t max_latency;
    uint16_t cont_num;
    uint16_t supervision_tmo;
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_SUBRATE_REQ                       (0x007E)
struct ble_hci_le_subrate_req_cp {
    uint16_t conn_handle;
    uint16_t subrate_min;
    uint16_t subrate_max;
    uint16_t max_latency;
    uint16_t cont_num;
    uint16_t supervision_tmo;
} __attribute__((packed));
 
/* --- Vendor specific commands (OGF 0x003F) */
/* Read Random Static Address */
#define BLE_HCI_OCF_VS_RD_STATIC_ADDR                   (MYNEWT_VAL(BLE_HCI_VS_OCF_OFFSET) + (0x0001))
struct ble_hci_vs_rd_static_addr_rp {
    uint8_t addr[6];
} __attribute__((packed));
 
/* Set default transmit power. Actual selected TX power is returned
 * in reply. Setting 0xff restores controller reset default.
 */
#define BLE_HCI_OCF_VS_SET_TX_PWR                       (MYNEWT_VAL(BLE_HCI_VS_OCF_OFFSET) + (0x0002))
struct ble_hci_vs_set_tx_pwr_cp {
    int8_t tx_power;
} __attribute__((packed));
struct ble_hci_vs_set_tx_pwr_rp {
    int8_t tx_power;
} __attribute__((packed));
 
#define BLE_HCI_OCF_VS_CSS                              (0x0003)
struct ble_hci_vs_css_cp {
    uint8_t opcode;
} __attribute__((packed));
#define BLE_HCI_VS_CSS_OP_CONFIGURE                     0x01
struct ble_hci_vs_css_configure_cp {
    uint8_t opcode;
    uint32_t slot_us;
    uint32_t period_slots;
} __attribute__((packed));
#define BLE_HCI_VS_CSS_OP_SET_NEXT_SLOT                 0x02
struct ble_hci_vs_css_set_next_slot_cp {
    uint8_t opcode;
    uint16_t slot_idx;
} __attribute__((packed));
#define BLE_HCI_VS_CSS_OP_SET_CONN_SLOT                 0x03
struct ble_hci_vs_css_set_conn_slot_cp {
    uint8_t opcode;
    uint16_t conn_handle;
    uint16_t slot_idx;
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_ENH_READ_TRANSMIT_POWER_LEVEL     (0x0076)
struct ble_hci_le_enh_read_transmit_power_level_cp {
    uint16_t conn_handle;
    uint8_t phy;
} __attribute__((packed));
struct ble_hci_le_enh_read_transmit_power_level_rp {
    uint8_t status;
    uint16_t conn_handle;
    uint8_t phy;
    uint8_t curr_tx_power_level;
    uint8_t max_tx_power_level;
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_READ_REMOTE_TRANSMIT_POWER_LEVEL  (0x0077)
struct ble_hci_le_read_remote_transmit_power_level_cp {
    uint16_t conn_handle;
    uint8_t phy;
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_SET_PATH_LOSS_REPORT_PARAM        (0x0078)
struct ble_hci_le_set_path_loss_report_param_cp {
    uint16_t conn_handle;
    uint8_t high_threshold;
    uint8_t high_hysteresis;
    uint8_t low_threshold;
    uint8_t low_hysteresis;
    uint16_t min_time_spent;
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_SET_PATH_LOSS_REPORT_ENABLE       (0x0079)
struct ble_hci_le_set_path_loss_report_enable_cp {
    uint16_t conn_handle;
    uint8_t enable;
} __attribute__((packed));
 
#define BLE_HCI_OCF_LE_SET_TRANS_PWR_REPORT_ENABLE       (0x007A)
struct ble_hci_le_set_transmit_power_report_enable_cp {
    uint16_t conn_handle;
    uint8_t local_enable;
    uint8_t remote_enable;
} __attribute__((packed));
 
 
/* Command Specific Definitions */
/* --- Set controller to host flow control (OGF 0x03, OCF 0x0031) --- */
#define BLE_HCI_CTLR_TO_HOST_FC_OFF         (0)
#define BLE_HCI_CTLR_TO_HOST_FC_ACL         (1)
#define BLE_HCI_CTLR_TO_HOST_FC_SYNC        (2)
#define BLE_HCI_CTLR_TO_HOST_FC_BOTH        (3)
 
/* --- LE set advertising parameters (OCF 0x0006) */
/* Advertising types */
#define BLE_HCI_ADV_TYPE_ADV_IND            (0)
#define BLE_HCI_ADV_TYPE_ADV_DIRECT_IND_HD  (1)
#define BLE_HCI_ADV_TYPE_ADV_SCAN_IND       (2)
#define BLE_HCI_ADV_TYPE_ADV_NONCONN_IND    (3)
#define BLE_HCI_ADV_TYPE_ADV_DIRECT_IND_LD  (4)
#define BLE_HCI_ADV_TYPE_MAX                (4)
 
#define BLE_HCI_ADV_CONN_MASK               (0x0001)
#define BLE_HCI_ADV_SCAN_MASK               (0x0002)
#define BLE_HCI_ADV_DIRECT_MASK             (0x0004)
#define BLE_HCI_ADV_SCAN_RSP_MASK           (0x0008)
#define BLE_HCI_ADV_LEGACY_MASK             (0x0010)
 
#define BLE_HCI_ADV_DATA_STATUS_COMPLETE    (0x0000)
#define BLE_HCI_ADV_DATA_STATUS_INCOMPLETE  (0x0020)
#define BLE_HCI_ADV_DATA_STATUS_TRUNCATED   (0x0040)
#define BLE_HCI_ADV_DATA_STATUS_MASK        (0x0060)
 
/* Own address types */
#define BLE_HCI_ADV_OWN_ADDR_PUBLIC         (0)
#define BLE_HCI_ADV_OWN_ADDR_RANDOM         (1)
#define BLE_HCI_ADV_OWN_ADDR_PRIV_PUB       (2)
#define BLE_HCI_ADV_OWN_ADDR_PRIV_RAND      (3)
#define BLE_HCI_ADV_OWN_ADDR_MAX            (3)
 
/* Advertisement peer address Type */
#define BLE_HCI_ADV_PEER_ADDR_PUBLIC        (0)
#define BLE_HCI_ADV_PEER_ADDR_RANDOM        (1)
#define BLE_HCI_ADV_PEER_ADDR_MAX           (1)
 
/* --- LE advertising channel tx power (OCF 0x0007) */
#define BLE_HCI_ADV_CHAN_TXPWR_MIN             (-20)
#define BLE_HCI_ADV_CHAN_TXPWR_MAX             (10)
 
/* --- LE set scan enable (OCF 0x000c) */
 
/* Connect peer address type */
#define BLE_HCI_CONN_PEER_ADDR_PUBLIC        (0)
#define BLE_HCI_CONN_PEER_ADDR_RANDOM        (1)
#define BLE_HCI_CONN_PEER_ADDR_PUBLIC_IDENT  (2)
#define BLE_HCI_CONN_PEER_ADDR_RANDOM_IDENT  (3)
#define BLE_HCI_CONN_PEER_ADDR_MAX           (3)
 
/*
 * Advertising filter policy
 *
 * Determines how an advertiser filters scan and connection requests.
 *
 *  NONE: no filtering (default value). No whitelist used.
 *  SCAN: process all connection requests but only scans from white list.
 *  CONN: process all scan request but only connection requests from white list
 *  BOTH: ignore all scan and connection requests unless in white list.
 */
#define BLE_HCI_ADV_FILT_NONE               (0)
#define BLE_HCI_ADV_FILT_SCAN               (1)
#define BLE_HCI_ADV_FILT_CONN               (2)
#define BLE_HCI_ADV_FILT_BOTH               (3)
#define BLE_HCI_ADV_FILT_MAX                (3)
 
#define BLE_HCI_ADV_FILT_DEF                (BLE_HCI_ADV_FILT_NONE)
 
/* Advertising interval */
#define BLE_HCI_ADV_ITVL                    (625)           /* usecs */
#define BLE_HCI_ADV_ITVL_MIN                (32)            /* units */
#define BLE_HCI_ADV_ITVL_MAX                (16384)         /* units */
#define BLE_HCI_ADV_ITVL_NONCONN_MIN        (160)           /* units */
 
#define BLE_HCI_ADV_ITVL_DEF                (0x800)         /* 1.28 seconds */
#define BLE_HCI_ADV_CHANMASK_DEF            (0x7)           /* all channels */
 
/* Set scan parameters */
#define BLE_HCI_SCAN_TYPE_PASSIVE           (0)
#define BLE_HCI_SCAN_TYPE_ACTIVE            (1)
 
/* Scan interval and scan window timing */
#define BLE_HCI_SCAN_ITVL                   (625)           /* usecs */
#define BLE_HCI_SCAN_ITVL_MIN               (0x0004)        /* units */
#define BLE_HCI_SCAN_ITVL_MAX               (0x4000)        /* units */
#define BLE_HCI_SCAN_ITVL_MAX_EXT           (0xffff)        /* units */
#define BLE_HCI_SCAN_ITVL_DEF               (16)            /* units */
#define BLE_HCI_SCAN_WINDOW_MIN             (0x0004)        /* units */
#define BLE_HCI_SCAN_WINDOW_MAX             (0x4000)        /* units */
#define BLE_HCI_SCAN_WINDOW_MAX_EXT         (0xffff)        /* units */
#define BLE_HCI_SCAN_WINDOW_DEF             (16)            /* units */
 
/*
 * Scanning filter policy
 *  NO_WL:
 *      Scanner processes all advertising packets (white list not used) except
 *      directed, connectable advertising packets not sent to the scanner.
 *  USE_WL:
 *      Scanner processes advertisements from white list only. A connectable,
 *      directed advertisment is ignored unless it contains scanners address.
 *  NO_WL_INITA:
 *      Scanner process all advertising packets (white list not used). A
 *      connectable, directed advertisement shall not be ignored if the InitA
 *      is a resolvable private address.
 *  USE_WL_INITA:
 *      Scanner process advertisements from white list only. A connectable,
 *      directed advertisement shall not be ignored if the InitA is a
 *      resolvable private address.
 */
#define BLE_HCI_SCAN_FILT_NO_WL             (0)
#define BLE_HCI_SCAN_FILT_USE_WL            (1)
#define BLE_HCI_SCAN_FILT_NO_WL_INITA       (2)
#define BLE_HCI_SCAN_FILT_USE_WL_INITA      (3)
#define BLE_HCI_SCAN_FILT_MAX               (3)
 
/* Whitelist commands */
#define BLE_HCI_ADD_WHITE_LIST_LEN          (7)
#define BLE_HCI_RMV_WHITE_LIST_LEN          (7)
 
/* Create Connection */
#define BLE_HCI_CREATE_CONN_LEN             (25)
#define BLE_HCI_CONN_ITVL                   (1250)  /* usecs */
#define BLE_HCI_CONN_FILT_NO_WL             (0)
#define BLE_HCI_CONN_FILT_USE_WL            (1)
#define BLE_HCI_CONN_FILT_MAX               (1)
#define BLE_HCI_CONN_ITVL_MIN               (0x0006)
#define BLE_HCI_CONN_ITVL_MAX               (0x0c80)
#define BLE_HCI_CONN_LATENCY_MIN            (0x0000)
#define BLE_HCI_CONN_LATENCY_MAX            (0x01f3)
#define BLE_HCI_CONN_SPVN_TIMEOUT_MIN       (0x000a)
#define BLE_HCI_CONN_SPVN_TIMEOUT_MAX       (0x0c80)
#define BLE_HCI_CONN_SPVN_TMO_UNITS         (10)    /* msecs */
#define BLE_HCI_INITIATOR_FILT_POLICY_MAX   (1)
 
/* Peer Address Type */
#define BLE_HCI_CONN_PEER_ADDR_PUBLIC       (0)
#define BLE_HCI_CONN_PEER_ADDR_RANDOM       (1)
#define BLE_HCI_CONN_PEER_ADDR_PUB_ID       (2)
#define BLE_HCI_CONN_PEER_ADDR_RAND_ID      (3)
#define BLE_HCI_CONN_PEER_ADDR_MAX          (3)
 
 
/* --- LE set data length (OCF 0x0022) */
#define BLE_HCI_SET_DATALEN_TX_OCTETS_MIN   (0x001b)
#define BLE_HCI_SET_DATALEN_TX_OCTETS_MAX   (0x00fb)
#define BLE_HCI_SET_DATALEN_TX_TIME_MIN     (0x0148)
#define BLE_HCI_SET_DATALEN_TX_TIME_MAX     (0x4290)
 
/* --- LE read maximum default PHY (OCF 0x0030) */
#define BLE_HCI_LE_PHY_1M                   (1)
#define BLE_HCI_LE_PHY_2M                   (2)
#define BLE_HCI_LE_PHY_CODED                (3)
 
/* --- LE set default PHY (OCF 0x0031) */
#define BLE_HCI_LE_PHY_NO_TX_PREF_MASK              (0x01)
#define BLE_HCI_LE_PHY_NO_RX_PREF_MASK              (0x02)
#define BLE_HCI_LE_PHY_1M_PREF_MASK                 (0x01)
#define BLE_HCI_LE_PHY_2M_PREF_MASK                 (0x02)
#define BLE_HCI_LE_PHY_CODED_PREF_MASK              (0x04)
 
#define BLE_HCI_LE_PHY_PREF_MASK_ALL                \
    (BLE_HCI_LE_PHY_1M_PREF_MASK | BLE_HCI_LE_PHY_2M_PREF_MASK |  \
     BLE_HCI_LE_PHY_CODED_PREF_MASK)
 
/* --- LE set PHY (OCF 0x0032) */
#define BLE_HCI_LE_PHY_CODED_ANY                    (0x0000)
#define BLE_HCI_LE_PHY_CODED_S2_PREF                (0x0001)
#define BLE_HCI_LE_PHY_CODED_S8_PREF                (0x0002)
 
/* --- LE enhanced receiver test (OCF 0x0033) */
#define BLE_HCI_LE_PHY_1M                           (1)
#define BLE_HCI_LE_PHY_2M                           (2)
#define BLE_HCI_LE_PHY_CODED                        (3)
 
/* --- LE enhanced transmitter test (OCF 0x0034) */
#define BLE_HCI_LE_PHY_CODED_S8                     (3)
#define BLE_HCI_LE_PHY_CODED_S2                     (4)
 
/* --- LE set extended advertising parameters (OCF 0x0036) */
#define BLE_HCI_LE_SET_EXT_ADV_PROP_CONNECTABLE     (0x0001)
#define BLE_HCI_LE_SET_EXT_ADV_PROP_SCANNABLE       (0x0002)
#define BLE_HCI_LE_SET_EXT_ADV_PROP_DIRECTED        (0x0004)
#define BLE_HCI_LE_SET_EXT_ADV_PROP_HD_DIRECTED     (0x0008)
#define BLE_HCI_LE_SET_EXT_ADV_PROP_LEGACY          (0x0010)
#define BLE_HCI_LE_SET_EXT_ADV_PROP_ANON_ADV        (0x0020)
#define BLE_HCI_LE_SET_EXT_ADV_PROP_INC_TX_PWR      (0x0040)
#define BLE_HCI_LE_SET_EXT_ADV_PROP_MASK            (0x7F)
 
#define BLE_HCI_LE_SET_EXT_ADV_PROP_LEGACY_IND      (0x0013)
#define BLE_HCI_LE_SET_EXT_ADV_PROP_LEGACY_LD_DIR   (0x0015)
#define BLE_HCI_LE_SET_EXT_ADV_PROP_LEGACY_HD_DIR   (0x001d)
#define BLE_HCI_LE_SET_EXT_ADV_PROP_LEGACY_SCAN     (0x0012)
#define BLE_HCI_LE_SET_EXT_ADV_PROP_LEGACY_NONCONN  (0x0010)
 
/* --- LE set extended advertising data (OCF 0x0037) */
#define BLE_HCI_MAX_EXT_ADV_DATA_LEN                (251)
 
#define BLE_HCI_LE_SET_DATA_OPER_INT        (0)
#define BLE_HCI_LE_SET_DATA_OPER_FIRST      (1)
#define BLE_HCI_LE_SET_DATA_OPER_LAST       (2)
#define BLE_HCI_LE_SET_DATA_OPER_COMPLETE   (3)
#define BLE_HCI_LE_SET_DATA_OPER_UNCHANGED  (4)
 
/* --- LE set extended scan response data (OCF 0x0038) */
#define BLE_HCI_MAX_EXT_SCAN_RSP_DATA_LEN           (251)
 
/* --- LE set periodic advertising parameters (OCF 0x003E) */
#define BLE_HCI_LE_SET_PERIODIC_ADV_PROP_INC_TX_PWR (0x0040)
#define BLE_HCI_LE_SET_PERIODIC_ADV_PROP_MASK       (0x0040)
 
/* --- LE set periodic advertising data (OCF 0x003F) */
#define BLE_HCI_MAX_PERIODIC_ADV_DATA_LEN                (252)
 
/* --- LE remove device from periodic advertising list (OCF 0x0048) */
#define BLE_HCI_PERIODIC_DATA_STATUS_COMPLETE   0x00
#define BLE_HCI_PERIODIC_DATA_STATUS_INCOMPLETE 0x01
#define BLE_HCI_PERIODIC_DATA_STATUS_TRUNCATED  0x02
 
/* --- LE set privacy mode (OCF 0x004E) */
#define BLE_HCI_PRIVACY_NETWORK                     (0)
#define BLE_HCI_PRIVACY_DEVICE                      (1)
 
/* Event Codes */
#define BLE_HCI_EVCODE_INQUIRY_CMP          (0x01)
#define BLE_HCI_EVCODE_INQUIRY_RESULT       (0x02)
#define BLE_HCI_EVCODE_CONN_DONE            (0x03)
#define BLE_HCI_EVCODE_CONN_REQUEST         (0x04)
#define BLE_HCI_EVCODE_DISCONN_CMP          (0x05)
struct ble_hci_ev_disconn_cmp {
    uint8_t status;
    uint16_t conn_handle;
    uint8_t reason;
} __attribute__((packed));
 
#define BLE_HCI_EVCODE_AUTH_CMP             (0x06)
#define BLE_HCI_EVCODE_REM_NAME_REQ_CMP     (0x07)
 
#define BLE_HCI_EVCODE_ENCRYPT_CHG          (0x08)
struct ble_hci_ev_enrypt_chg {
    uint8_t status;
    uint16_t connection_handle;
    uint8_t enabled;
} __attribute__((packed));
 
#define BLE_HCI_EVCODE_CHG_LINK_KEY_CMP     (0x09)
#define BLE_HCI_EVCODE_MASTER_LINK_KEY_CMP  (0x0A)
#define BLE_HCI_EVCODE_RD_REM_SUPP_FEAT_CMP (0x0B)
#define BLE_HCI_EVCODE_RD_REM_VER_INFO_CMP  (0x0C)
struct ble_hci_ev_rd_rem_ver_info_cmp {
    uint8_t  status;
    uint16_t conn_handle;
    uint8_t  version;
    uint16_t manufacturer;
    uint16_t subversion;
} __attribute__((packed));
 
#define BLE_HCI_EVCODE_QOS_SETUP_CMP        (0x0D)
 
#define BLE_HCI_EVCODE_COMMAND_COMPLETE     (0x0E)
struct ble_hci_ev_command_complete {
    uint8_t  num_packets;
    uint16_t opcode;
    uint8_t  status;
    uint8_t  return_params[0];
} __attribute__((packed));
/* NOP is exception and has no return parameters */
struct ble_hci_ev_command_complete_nop {
    uint8_t  num_packets;
    uint16_t opcode;
} __attribute__((packed));
 
#define BLE_HCI_EVCODE_COMMAND_STATUS       (0x0F)
struct ble_hci_ev_command_status {
    uint8_t status;
    uint8_t  num_packets;
    uint16_t opcode;
} __attribute__((packed));
 
#define BLE_HCI_EVCODE_HW_ERROR             (0x10)
struct ble_hci_ev_hw_error {
    uint8_t hw_code;
} __attribute__((packed));
 
#define BLE_HCI_EVCODE_NUM_COMP_PKTS        (0x13)
struct comp_pkt {
    uint16_t handle;
    uint16_t packets;
} __attribute__((packed));;
struct ble_hci_ev_num_comp_pkts {
    uint8_t count;
    struct comp_pkt completed[0];
} __attribute__((packed));
 
#define BLE_HCI_EVCODE_MODE_CHANGE          (0x14)
#define BLE_HCI_EVCODE_RETURN_LINK_KEYS     (0x15)
#define BLE_HCI_EVCODE_PIN_CODE_REQ         (0x16)
#define BLE_HCI_EVCODE_LINK_KEY_REQ         (0x17)
#define BLE_HCI_EVCODE_LINK_KEY_NOTIFY      (0x18)
#define BLE_HCI_EVCODE_LOOPBACK_CMD         (0x19)
 
#define BLE_HCI_EVCODE_DATA_BUF_OVERFLOW    (0x1A)
struct ble_hci_ev_data_buf_overflow {
    uint8_t link_type;
} __attribute__((packed));
 
#define BLE_HCI_EVCODE_MAX_SLOTS_CHG        (0x1B)
#define BLE_HCI_EVCODE_READ_CLK_OFF_COMP    (0x1C)
#define BLE_HCI_EVCODE_CONN_PKT_TYPE_CHG    (0x1D)
#define BLE_HCI_EVCODE_QOS_VIOLATION        (0x1E)
/* NOTE: 0x1F not defined */
#define BLE_HCI_EVCODE_PSR_MODE_CHG         (0x20)
#define BLE_HCI_EVCODE_FLOW_SPEC_COMP       (0x21)
#define BLE_HCI_EVCODE_INQ_RESULT_RSSI      (0x22)
#define BLE_HCI_EVCODE_READ_REM_EXT_FEAT    (0x23)
/* NOTE: 0x24 - 0x2B not defined */
#define BLE_HCI_EVCODE_SYNCH_CONN_COMP      (0x2C)
#define BLE_HCI_EVCODE_SYNCH_CONN_CHG       (0x2D)
#define BLE_HCI_EVCODE_SNIFF_SUBRATING      (0x2E)
#define BLE_HCI_EVCODE_EXT_INQ_RESULT       (0x2F)
 
#define BLE_HCI_EVCODE_ENC_KEY_REFRESH      (0x30)
struct ble_hci_ev_enc_key_refresh {
    uint8_t status;
    uint16_t conn_handle;
} __attribute__((packed));
 
#define BLE_HCI_EVOCDE_IO_CAP_REQ           (0x31)
#define BLE_HCI_EVCODE_IO_CAP_RSP           (0x32)
#define BLE_HCI_EVCODE_USER_CONFIRM_REQ     (0x33)
#define BLE_HCI_EVCODE_PASSKEY_REQ          (0x34)
#define BLE_HCI_EVCODE_REM_OOB_DATA_REQ     (0x35)
#define BLE_HCI_EVCODE_SIMPLE_PAIR_COMP     (0x36)
/* NOTE: 0x37 not defined */
#define BLE_HCI_EVCODE_LNK_SPVN_TMO_CHG     (0x38)
#define BLE_HCI_EVCODE_ENH_FLUSH_COMP       (0x39)
#define BLE_HCI_EVCODE_USER_PASSKEY_NOTIFY  (0x3B)
#define BLE_HCI_EVCODE_KEYPRESS_NOTIFY      (0x3C)
#define BLE_HCI_EVCODE_REM_HOST_SUPP_FEAT   (0x3D)
 
#define BLE_HCI_EVCODE_LE_META              (0x3E)
struct ble_hci_ev_le_meta {
    uint8_t subevent;
    uint8_t data[0];
} __attribute__((packed));
 
/* NOTE: 0x3F not defined */
#define BLE_HCI_EVCODE_PHYS_LINK_COMP       (0x40)
#define BLE_HCI_EVCODE_CHAN_SELECTED        (0x41)
#define BLE_HCI_EVCODE_DISCONN_PHYS_LINK    (0x42)
#define BLE_HCI_EVCODE_PHYS_LINK_LOSS_EARLY (0x43)
#define BLE_HCI_EVCODE_PHYS_LINK_RECOVERY   (0x44)
#define BLE_HCI_EVCODE_LOGICAL_LINK_COMP    (0x45)
#define BLE_HCI_EVCODE_DISCONN_LOGICAL_LINK (0x46)
#define BLE_HCI_EVCODE_FLOW_SPEC_MODE_COMP  (0x47)
#define BLE_HCI_EVCODE_NUM_COMP_DATA_BLKS   (0x48)
#define BLE_HCI_EVCODE_AMP_START_TEST       (0x49)
#define BLE_HCI_EVOCDE_AMP_TEST_END         (0x4A)
#define BLE_HCI_EVOCDE_AMP_RCVR_REPORT      (0x4B)
#define BLE_HCI_EVCODE_SHORT_RANGE_MODE_CHG (0x4C)
#define BLE_HCI_EVCODE_AMP_STATUS_CHG       (0x4D)
#define BLE_HCI_EVCODE_TRIG_CLK_CAPTURE     (0x4E)
#define BLE_HCI_EVCODE_SYNCH_TRAIN_COMP     (0x4F)
#define BLE_HCI_EVCODE_SYNCH_TRAIN_RCVD     (0x50)
#define BLE_HCI_EVCODE_SLAVE_BCAST_RX       (0x51)
#define BLE_HCI_EVCODE_SLAVE_BCAST_TMO      (0x52)
#define BLE_HCI_EVCODE_TRUNC_PAGE_COMP      (0x53)
#define BLE_HCI_EVCODE_SLAVE_PAGE_RSP_TMO   (0x54)
#define BLE_HCI_EVCODE_SLAVE_BCAST_CHAN_MAP (0x55)
#define BLE_HCI_EVCODE_INQ_RSP_NOTIFY       (0x56)
 
#define BLE_HCI_EVCODE_AUTH_PYLD_TMO        (0x57)
struct ble_hci_ev_auth_pyld_tmo {
    uint16_t conn_handle;
} __attribute__((packed));
 
#define BLE_HCI_EVCODE_SAM_STATUS_CHG       (0x58)
 
#define BLE_HCI_EVCODE_VS_DEBUG             (0xFF)
struct ble_hci_ev_vs_debug {
    uint8_t id;
    uint8_t data[0];
} __attribute__((packed));
 
/* LE sub-event codes */
#define BLE_HCI_LE_SUBEV_CONN_COMPLETE          (0x01)
struct ble_hci_ev_le_subev_conn_complete {
    uint8_t  subev_code;
    uint8_t  status;
    uint16_t conn_handle;
    uint8_t  role;
    uint8_t  peer_addr_type;
    uint8_t  peer_addr[6];
    uint16_t conn_itvl;
    uint16_t conn_latency;
    uint16_t supervision_timeout;
    uint8_t  mca;
} __attribute__((packed));
 
#define BLE_HCI_LE_SUBEV_ADV_RPT                (0x02)
struct adv_report {
    uint8_t type;
    uint8_t addr_type;
    uint8_t addr[6];
    uint8_t data_len;
    uint8_t data[0];
} __attribute__((packed));
struct ble_hci_ev_le_subev_adv_rpt {
    uint8_t  subev_code;
    uint8_t  num_reports;
    struct adv_report reports[0];
} __attribute__((packed));
 
#define BLE_HCI_LE_SUBEV_CONN_UPD_COMPLETE      (0x03)
struct ble_hci_ev_le_subev_conn_upd_complete {
    uint8_t  subev_code;
    uint8_t  status;
    uint16_t conn_handle;
    uint16_t conn_itvl;
    uint16_t conn_latency;
    uint16_t supervision_timeout;
} __attribute__((packed));
 
#define BLE_HCI_LE_SUBEV_RD_REM_USED_FEAT       (0x04)
struct ble_hci_ev_le_subev_rd_rem_used_feat {
    uint8_t  subev_code;
    uint8_t  status;
    uint16_t conn_handle;
    uint8_t features[8];
} __attribute__((packed));
 
#define BLE_HCI_LE_SUBEV_LT_KEY_REQ             (0x05)
struct ble_hci_ev_le_subev_lt_key_req {
    uint8_t  subev_code;
    uint16_t conn_handle;
    uint64_t rand;
    uint16_t div;
} __attribute__((packed));
 
#define BLE_HCI_LE_SUBEV_REM_CONN_PARM_REQ      (0x06)
struct ble_hci_ev_le_subev_rem_conn_param_req {
    uint8_t  subev_code;
    uint16_t conn_handle;
    uint16_t min_interval;
    uint16_t max_interval;
    uint16_t latency;
    uint16_t timeout;
} __attribute__((packed));
 
#define BLE_HCI_LE_SUBEV_DATA_LEN_CHG           (0x07)
struct ble_hci_ev_le_subev_data_len_chg {
    uint8_t  subev_code;
    uint16_t conn_handle;
    uint16_t max_tx_octets;
    uint16_t max_tx_time;
    uint16_t max_rx_octets;
    uint16_t max_rx_time;
} __attribute__((packed));
 
#define BLE_HCI_LE_SUBEV_RD_LOC_P256_PUBKEY     (0x08)
struct ble_hci_ev_le_subev_rd_loc_p256_pubkey {
    uint8_t subev_code;
    uint8_t status;
    uint8_t public_key[64];
} __attribute__((packed));
 
#define BLE_HCI_LE_SUBEV_GEN_DHKEY_COMPLETE     (0x09)
struct ble_hci_ev_le_subev_gen_dhkey_complete {
    uint8_t subev_code;
    uint8_t status;
    uint8_t dh_key[32];
} __attribute__((packed));
 
#define BLE_HCI_LE_SUBEV_ENH_CONN_COMPLETE      (0x0A)
struct ble_hci_ev_le_subev_enh_conn_complete {
    uint8_t  subev_code;
    uint8_t  status;
    uint16_t conn_handle;
    uint8_t  role;
    uint8_t  peer_addr_type;
    uint8_t  peer_addr[6];
    uint8_t  local_rpa[6];
    uint8_t  peer_rpa[6];
    uint16_t conn_itvl;
    uint16_t conn_latency;
    uint16_t supervision_timeout;
    uint8_t  mca;
} __attribute__((packed));
 
#define BLE_HCI_LE_SUBEV_DIRECT_ADV_RPT         (0x0B)
struct dir_adv_report {
    uint8_t type;
    uint8_t addr_type;
    uint8_t addr[6];
    uint8_t dir_addr_type;
    uint8_t dir_addr[6];
    int8_t  rssi;
} __attribute__((packed));
struct ble_hci_ev_le_subev_direct_adv_rpt {
    uint8_t subev_code;
    uint8_t num_reports;
    struct dir_adv_report reports[0];
} __attribute__((packed));
 
#define BLE_HCI_LE_SUBEV_PHY_UPDATE_COMPLETE    (0x0C)
struct ble_hci_ev_le_subev_phy_update_complete {
    uint8_t  subev_code;
    uint8_t  status;
    uint16_t conn_handle;
    uint8_t  tx_phy;
    uint8_t  rx_phy;
} __attribute__((packed));
 
#define BLE_HCI_LE_SUBEV_EXT_ADV_RPT            (0x0D)
struct ext_adv_report {
    uint16_t  evt_type;
    uint8_t  addr_type;
    uint8_t  addr[6];
    uint8_t  pri_phy;
    uint8_t  sec_phy;
    uint8_t  sid;
    int8_t   tx_power;
    int8_t   rssi;
    uint16_t periodic_itvl;
    uint8_t  dir_addr_type;
    uint8_t  dir_addr[6];
    uint8_t  data_len;
    uint8_t  data[0];
} __attribute__((packed));
struct ble_hci_ev_le_subev_ext_adv_rpt {
    uint8_t subev_code;
    uint8_t num_reports;
    struct ext_adv_report reports[0];
} __attribute__((packed));
 
#define BLE_HCI_LE_SUBEV_PERIODIC_ADV_SYNC_ESTAB     (0x0E)
struct ble_hci_ev_le_subev_periodic_adv_sync_estab {
    uint8_t  subev_code;
    uint8_t  status;
    uint16_t sync_handle;
    uint8_t  sid;
    uint8_t  peer_addr_type;
    uint8_t  peer_addr[6];
    uint8_t  phy;
    uint16_t interval;
    uint8_t  aca;
} __attribute__((packed));
 
#define BLE_HCI_LE_SUBEV_PERIODIC_ADV_RPT            (0x0F)
struct ble_hci_ev_le_subev_periodic_adv_rpt {
    uint8_t  subev_code;
    uint16_t sync_handle;
    int8_t   tx_power;
    int8_t   rssi;
    uint8_t  cte_type;
    uint8_t  data_status;
    uint8_t  data_len;
    uint8_t  data[0];
} __attribute__((packed));
 
#define BLE_HCI_LE_SUBEV_PERIODIC_ADV_SYNC_LOST      (0x10)
struct ble_hci_ev_le_subev_periodic_adv_sync_lost {
    uint8_t  subev_code;
    uint16_t sync_handle;
} __attribute__((packed));
 
#define BLE_HCI_LE_SUBEV_SCAN_TIMEOUT           (0x11)
struct ble_hci_ev_le_subev_scan_timeout {
    uint8_t  subev_code;
} __attribute__((packed));
 
#define BLE_HCI_LE_SUBEV_ADV_SET_TERMINATED     (0x12)
struct ble_hci_ev_le_subev_adv_set_terminated {
    uint8_t  subev_code;
    uint8_t  status;
    uint8_t  adv_handle;
    uint16_t conn_handle;
    uint8_t  num_events;
} __attribute__((packed));
 
#define BLE_HCI_LE_SUBEV_SCAN_REQ_RCVD          (0x13)
struct ble_hci_ev_le_subev_scan_req_rcvd {
    uint8_t subev_code;
    uint8_t adv_handle;
    uint8_t peer_addr_type;
    uint8_t peer_addr[6];
} __attribute__((packed));
 
#define BLE_HCI_LE_SUBEV_CHAN_SEL_ALG           (0x14)
struct ble_hci_ev_le_subev_chan_sel_alg {
    uint8_t  subev_code;
    uint16_t conn_handle;
    uint8_t  csa;
} __attribute__((packed));
 
#define BLE_HCI_LE_SUBEV_CONNLESS_IQ_RPT        (0x15)
#define BLE_HCI_LE_SUBEV_CONN_IQ_RPT            (0x16)
#define BLE_HCI_LE_SUBEV_CTE_REQ_FAILED         (0x17)
 
#define BLE_HCI_LE_SUBEV_PERIODIC_ADV_SYNC_TRANSFER   (0x18)
struct ble_hci_ev_le_subev_periodic_adv_sync_transfer {
    uint8_t  subev_code;
    uint8_t  status;
    uint16_t conn_handle;
    uint16_t service_data;
    uint16_t sync_handle;
    uint8_t  sid;
    uint8_t  peer_addr_type;
    uint8_t  peer_addr[6];
    uint8_t  phy;
    uint16_t interval;
    uint8_t  aca;
} __attribute__((packed));
 
#define BLE_HCI_LE_SUBEV_CIS_ESTAB              (0x19)
struct ble_hci_ev_le_subev_cis_established {
    uint8_t subev_code;
    uint8_t status;
    uint16_t cis_handle;
    uint8_t cig_sync_delay[3];
    uint8_t cis_sync_delay[3];
    uint8_t trans_latency_mtos[3];
    uint8_t trans_latency_stom[3];
    uint8_t phy_mtos;
    uint8_t phy_stom;
    uint8_t nse;
    uint8_t bn_mtos;
    uint8_t bn_stom;
    uint8_t ft_mtos;
    uint8_t ft_stom;
    uint16_t max_pdu_mtos;
    uint16_t max_pdu_stom;
    uint16_t iso_interval;
} __attribute__((packed));
 
#define BLE_HCI_LE_SUBEV_CIS_REQUEST            (0x1A)
struct ble_hci_ev_le_subev_cis_request {
    uint8_t subev_code;
    uint16_t conn_handle;
    uint16_t cis_handle;
    uint8_t cig_id;
    uint8_t cis_id;
} __attribute__((packed));
 
#define BLE_HCI_LE_SUBEV_BIG_COMP               (0x1B)
struct ble_hci_ev_le_subev_big_complete {
    uint8_t subev_code;
    uint8_t status;
    uint8_t big_handle;
    uint8_t big_sync_delay[3];
    uint8_t transport_latency[3];
    uint8_t phy;
    uint8_t nse;
    uint8_t bn;
    uint8_t pto;
    uint8_t irc;
    uint16_t max_pdu;
    uint16_t iso_interval;
    uint8_t bis_cnt;
    uint16_t bis[0];
} __attribute__((packed));
 
#define BLE_HCI_LE_SUBEV_BIG_TERMINATE_COMP     (0x1C)
struct ble_hci_ev_le_subev_big_terminate_complete {
    uint8_t subev_code;
    uint8_t big_handle;
    uint8_t reason;
} __attribute__((packed));
 
#define BLE_HCI_LE_SUBEV_BIG_SYNC_ESTAB         (0x1D)
struct ble_hci_ev_le_subev_big_sync_established {
    uint8_t subev_code;
    uint8_t status;
    uint8_t big_handle;
    uint8_t transport_latency[3];
    uint8_t nse;
    uint8_t bn;
    uint8_t pto;
    uint8_t irc;
    uint16_t max_pdu;
    uint16_t iso_interval;
    uint8_t bis_cnt;
    uint16_t bis_handles[0];
} __attribute__((packed));
 
#define BLE_HCI_LE_SUBEV_BIG_SYNC_LOST          (0x1E)
struct ble_hci_ev_le_subev_big_sync_lost {
    uint8_t subev_code;
    uint8_t big_handle;
    uint8_t reason;
} __attribute__((packed));
 
#define BLE_HCI_LE_SUBEV_REQ_PEER_SCA_COMP      (0x1F)
struct ble_hci_ev_le_subev_peer_sca_complete {
    uint8_t subev_code;
    uint8_t status;
    uint16_t conn_handle;
    uint8_t sca;
} __attribute__((packed));
 
#define BLE_HCI_LE_SUBEV_PATH_LOSS_THRESHOLD     (0x20)
struct ble_hci_ev_le_subev_path_loss_threshold {
    uint8_t subev_code;
    uint16_t conn_handle;
    uint8_t current_path_loss;
    uint8_t zone_entered;
} __attribute__((packed));
 
#define BLE_HCI_LE_SUBEV_TRANSMIT_POWER_REPORT   (0x21)
struct ble_hci_ev_le_subev_transmit_power_report {
    uint8_t  subev_code;
    uint8_t  status;
    uint16_t conn_handle;
    uint8_t  reason;
    uint8_t  phy;
    uint8_t  transmit_power_level;
    uint8_t  transmit_power_level_flag;
    uint8_t delta;
} __attribute__((packed));
 
#define BLE_HCI_LE_SUBEV_BIGINFO_ADV_REPORT         (0x22)
struct ble_hci_ev_le_subev_biginfo_adv_report {
    uint8_t subev_code;
    uint16_t sync_handle;
    uint8_t bis_cnt;
    uint8_t nse;
    uint16_t iso_interval;
    uint8_t bn;
    uint8_t pto;
    uint8_t irc;
    uint16_t max_pdu;
    uint8_t sdu_interval[3];
    uint16_t max_sdu;
    uint8_t phy;
    uint8_t framing;
    uint8_t encryption;
} __attribute__((packed));
 
#define BLE_HCI_LE_SUBEV_SUBRATE_CHANGE             (0x23)
struct ble_hci_ev_le_subev_subrate_change {
    uint8_t subev_code;
    uint8_t status;
    uint16_t conn_handle;
    uint16_t subrate_factor;
    uint16_t periph_latency;
    uint16_t cont_num;
    uint16_t supervision_tmo;
} __attribute__((packed));
 
/* Data buffer overflow event */
#define BLE_HCI_EVENT_ACL_BUF_OVERFLOW      (0x01)
 
/* Advertising report */
#define BLE_HCI_ADV_RPT_EVTYPE_ADV_IND      (0)
#define BLE_HCI_ADV_RPT_EVTYPE_DIR_IND      (1)
#define BLE_HCI_ADV_RPT_EVTYPE_SCAN_IND     (2)
#define BLE_HCI_ADV_RPT_EVTYPE_NONCONN_IND  (3)
#define BLE_HCI_ADV_RPT_EVTYPE_SCAN_RSP     (4)
 
/* Bluetooth 5, Vol 2, Part E, 7.7.65.13 */
#define BLE_HCI_LEGACY_ADV_EVTYPE_ADV_IND                 (0x13)
#define BLE_HCI_LEGACY_ADV_EVTYPE_ADV_DIRECT_IND          (0x15)
#define BLE_HCI_LEGACY_ADV_EVTYPE_ADV_SCAN_IND            (0x12)
#define BLE_HCI_LEGACY_ADV_EVTYPE_ADV_NONCON_IND          (0x10)
#define BLE_HCI_LEGACY_ADV_EVTYPE_SCAN_RSP_ADV_IND        (0x1b)
#define BLE_HCI_LEGACY_ADV_EVTYPE_SCAN_RSP_ADV_SCAN_IND   (0x1a)
 
/* LE connection complete event (sub event 0x01) */
#define BLE_HCI_LE_CONN_COMPLETE_ROLE_MASTER    (0x00)
#define BLE_HCI_LE_CONN_COMPLETE_ROLE_SLAVE     (0x01)
 
/* Maximum valid connection handle value */
#define BLE_HCI_LE_CONN_HANDLE_MAX              (0x0eff)
 
/* LE advertising report event. (sub event 0x02) */
#define BLE_HCI_LE_ADV_RPT_NUM_RPTS_MIN     (1)
#define BLE_HCI_LE_ADV_RPT_NUM_RPTS_MAX     (0x19)
 
/* Bluetooth Assigned numbers for version information.*/
#define BLE_HCI_VER_BCS_1_0b                (0)
#define BLE_HCI_VER_BCS_1_1                 (1)
#define BLE_HCI_VER_BCS_1_2                 (2)
#define BLE_HCI_VER_BCS_2_0_EDR             (3)
#define BLE_HCI_VER_BCS_2_1_EDR             (4)
#define BLE_HCI_VER_BCS_3_0_HCS             (5)
#define BLE_HCI_VER_BCS_4_0                 (6)
#define BLE_HCI_VER_BCS_4_1                 (7)
#define BLE_HCI_VER_BCS_4_2                 (8)
#define BLE_HCI_VER_BCS_5_0                 (9)
#define BLE_HCI_VER_BCS_5_1                 (10)
#define BLE_HCI_VER_BCS_5_2                 (11)
#define BLE_HCI_VER_BCS_5_3                 (12)
 
#define BLE_LMP_VER_BCS_1_0b                (0)
#define BLE_LMP_VER_BCS_1_1                 (1)
#define BLE_LMP_VER_BCS_1_2                 (2)
#define BLE_LMP_VER_BCS_2_0_EDR             (3)
#define BLE_LMP_VER_BCS_2_1_EDR             (4)
#define BLE_LMP_VER_BCS_3_0_HCS             (5)
#define BLE_LMP_VER_BCS_4_0                 (6)
#define BLE_LMP_VER_BCS_4_1                 (7)
#define BLE_LMP_VER_BCS_4_2                 (8)
#define BLE_LMP_VER_BCS_5_0                 (9)
#define BLE_LMP_VER_BCS_5_1                 (10)
#define BLE_LMP_VER_BCS_5_2                 (11)
#define BLE_LMP_VER_BCS_5_3                 (12)
 
/* selected HCI and LMP version */
#if MYNEWT_VAL(BLE_VERSION) == 50
#define BLE_HCI_VER_BCS BLE_HCI_VER_BCS_5_0
#define BLE_LMP_VER_BCS BLE_LMP_VER_BCS_5_0
#elif MYNEWT_VAL(BLE_VERSION) == 51
#define BLE_HCI_VER_BCS BLE_HCI_VER_BCS_5_1
#define BLE_LMP_VER_BCS BLE_LMP_VER_BCS_5_1
#elif MYNEWT_VAL(BLE_VERSION) == 52
#define BLE_HCI_VER_BCS BLE_HCI_VER_BCS_5_2
#define BLE_LMP_VER_BCS BLE_LMP_VER_BCS_5_2
#elif MYNEWT_VAL(BLE_VERSION) == 53
#define BLE_HCI_VER_BCS BLE_HCI_VER_BCS_5_3
#define BLE_LMP_VER_BCS BLE_LMP_VER_BCS_5_3
#endif
 
#define BLE_HCI_DATA_HDR_SZ                 4
#define BLE_HCI_DATA_HANDLE(handle_pb_bc)   (((handle_pb_bc) & 0x0fff) >> 0)
#define BLE_HCI_DATA_PB(handle_pb_bc)       (((handle_pb_bc) & 0x3000) >> 12)
#define BLE_HCI_DATA_BC(handle_pb_bc)       (((handle_pb_bc) & 0xc000) >> 14)
 
struct hci_data_hdr
{
    uint16_t hdh_handle_pb_bc;
    uint16_t hdh_len;
};
 
#define BLE_HCI_PB_FIRST_NON_FLUSH          0
#define BLE_HCI_PB_MIDDLE                   1
#define BLE_HCI_PB_FIRST_FLUSH              2
#define BLE_HCI_PB_FULL                     3
 
#ifdef __cplusplus
}
#endif
 
#endif /* H_BLE_HCI_COMMON_ */