summaryrefslogtreecommitdiff
path: root/sys/netbt/hci.h
blob: 254ec3a41714d2d8b33a00ccd8237bf763f0b265 (plain)
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
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
/*	$OpenBSD: hci.h,v 1.9 2007/07/22 21:05:00 gwk Exp $	*/
/*	$NetBSD: hci.h,v 1.10 2007/04/21 06:15:23 plunky Exp $	*/

/*-
 * Copyright (c) 2005 Iain Hibbert.
 * Copyright (c) 2006 Itronix Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. The name of Itronix Inc. may not be used to endorse
 *    or promote products derived from this software without specific
 *    prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY ITRONIX INC. ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL ITRONIX INC. BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */
/*-
 * Copyright (c) 2001 Maksim Yevmenkin <m_evmenkin@yahoo.com>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * $Id: hci.h,v 1.9 2007/07/22 21:05:00 gwk Exp $
 * $FreeBSD: src/sys/netgraph/bluetooth/include/ng_hci.h,v 1.6 2005/01/07 01:45:43 imp Exp $
 */

/*
 * This file contains everything that applications need to know from
 * Host Controller Interface (HCI). Information taken from Bluetooth
 * Core Specifications (v1.1 and v2.0)
 *
 * This file can be included by both kernel and userland applications.
 *
 * NOTE: Here and after Bluetooth device is called a "unit". Bluetooth
 *       specification refers to both devices and units. They are the
 *       same thing (I think), so to be consistent word "unit" will be
 *       used.
 */

#ifndef _NETBT_HCI_H_
#define _NETBT_HCI_H_

#include <netbt/bluetooth.h>

/**************************************************************************
 **************************************************************************
 **                   Common defines and types (HCI)
 **************************************************************************
 **************************************************************************/

#define HCI_LAP_SIZE			3   /* unit LAP */
#define HCI_KEY_SIZE			16  /* link key */
#define HCI_PIN_SIZE			16  /* link PIN */
#define HCI_EVENT_MASK_SIZE		8   /* event mask */
#define HCI_CLASS_SIZE			3   /* unit class */
#define HCI_FEATURES_SIZE		8   /* LMP features */
#define HCI_UNIT_NAME_SIZE		248 /* unit name size */
#define HCI_DEVNAME_SIZE		16  /* same as dv_xname */

/* HCI specification */
#define HCI_SPEC_V10			0x00 /* v1.0 */
#define HCI_SPEC_V11			0x01 /* v1.1 */
#define HCI_SPEC_V12			0x02 /* v1.2 */
#define HCI_SPEC_V20			0x03 /* v2.0 */
/* 0x02 - 0xFF - reserved for future use */

/* LMP features (and page 0 of extended features) */
/* ------------------- byte 0 --------------------*/
#define HCI_LMP_3SLOT			0x01
#define HCI_LMP_5SLOT			0x02
#define HCI_LMP_ENCRYPTION		0x04
#define HCI_LMP_SLOT_OFFSET		0x08
#define HCI_LMP_TIMIACCURACY		0x10
#define HCI_LMP_ROLE_SWITCH		0x20
#define HCI_LMP_HOLD_MODE		0x40
#define HCI_LMP_SNIFF_MODE		0x80
/* ------------------- byte 1 --------------------*/
#define HCI_LMP_PARK_MODE		0x01
#define HCI_LMP_RSSI			0x02
#define HCI_LMP_CHANNEL_QUALITY		0x04
#define HCI_LMP_SCO_LINK		0x08
#define HCI_LMP_HV2_PKT			0x10
#define HCI_LMP_HV3_PKT			0x20
#define HCI_LMP_ULAW_LOG		0x40
#define HCI_LMP_ALAW_LOG		0x80
/* ------------------- byte 2 --------------------*/
#define HCI_LMP_CVSD			0x01
#define HCI_LMP_PAGISCHEME		0x02
#define HCI_LMP_POWER_CONTROL		0x04
#define HCI_LMP_TRANSPARENT_SCO		0x08
#define HCI_LMP_FLOW_CONTROL_LAG0	0x10
#define HCI_LMP_FLOW_CONTROL_LAG1	0x20
#define HCI_LMP_FLOW_CONTROL_LAG2	0x40
#define HCI_LMP_BC_ENCRYPTION		0x80
/* ------------------- byte 3 --------------------*/
/* reserved				0x01 */
#define HCI_LMP_EDR_ACL_2MBPS		0x02
#define HCI_LMP_EDR_ACL_3MBPS		0x04
#define HCI_LMP_ENHANCED_ISCAN		0x08
#define HCI_LMP_INTERLACED_ISCAN	0x10
#define HCI_LMP_INTERLACED_PSCAN	0x20
#define HCI_LMP_RSSI_INQUIRY		0x40
#define HCI_LMP_EV3_PKT			0x80
/* ------------------- byte 4 --------------------*/
#define HCI_LMP_EV4_PKT			0x01
#define HCI_LMP_EV5_PKT			0x02
/* reserved				0x04 */
#define HCI_LMP_AFH_CAPABLE_SLAVE	0x08
#define HCI_LMP_AFH_CLASS_SLAVE		0x10
/* reserved				0x20 */
/* reserved				0x40 */
#define HCI_LMP_3SLOT_EDR_ACL		0x80
/* ------------------- byte 5 --------------------*/
#define HCI_LMP_5SLOT_EDR_ACL		0x01
/* reserved				0x02 */
/* reserved				0x04 */
#define HCI_LMP_AFH_CAPABLE_MASTER	0x08
#define HCI_LMP_AFH_CLASS_MASTER	0x10
#define HCI_LMP_EDR_eSCO_2MBPS		0x20
#define HCI_LMP_EDR_eSCO_3MBPS		0x40
#define HCI_LMP_3SLOT_EDR_eSCO		0x80
/* ------------------- byte 6 --------------------*/
/* reserved					  */
/* ------------------- byte 7 --------------------*/
#define HCI_LMP_EXTENDED_FEATURES	0x80

/* Link types */
#define HCI_LINK_SCO			0x00 /* Voice */
#define HCI_LINK_ACL			0x01 /* Data */
#define HCI_LINK_eSCO			0x02 /* eSCO */
/* 0x03 - 0xFF - reserved for future use */

/*
 * ACL/SCO packet type bits are set to enable the
 * packet type, except for 2MBPS and 3MBPS when they
 * are unset to enable the packet type.
 */
/* ACL Packet types for "Create Connection" */
#define HCI_PKT_2MBPS_DH1	0x0002
#define HCI_PKT_3MBPS_DH1	0x0004
#define HCI_PKT_DM1		0x0008
#define HCI_PKT_DH1		0x0010
#define HCI_PKT_2MBPS_DH3	0x0100
#define HCI_PKT_3MBPS_DH3	0x0200
#define HCI_PKT_DM3		0x0400
#define HCI_PKT_DH3		0x0800
#define HCI_PKT_2MBPS_DH5	0x1000
#define HCI_PKT_3MBPS_DH5	0x2000
#define HCI_PKT_DM5		0x4000
#define HCI_PKT_DH5		0x8000

/* SCO Packet types for "Setup Synchronous Connection" */
#define HCI_PKT_HV1		0x0001
#define HCI_PKT_HV2		0x0002
#define HCI_PKT_HV3		0x0004
#define HCI_PKT_EV3		0x0008
#define HCI_PKT_EV4		0x0010
#define HCI_PKT_EV5		0x0020
#define HCI_PKT_2MBPS_EV3	0x0040
#define HCI_PKT_3MBPS_EV3	0x0080
#define HCI_PKT_2MBPS_EV5	0x0100
#define HCI_PKT_3MBPS_EV5	0x0200

/*
 * Connection modes/Unit modes
 *
 * This is confusing. It means that one of the units change its mode
 * for the specific connection. For example one connection was put on
 * hold (but i could be wrong :)
 */

/* Page scan modes (are deprecated) */
#define HCI_MANDATORY_PAGE_SCAN_MODE		0x00
#define HCI_OPTIONAL_PAGE_SCAN_MODE1		0x01
#define HCI_OPTIONAL_PAGE_SCAN_MODE2		0x02
#define HCI_OPTIONAL_PAGE_SCAN_MODE3		0x03
/* 0x04 - 0xFF - reserved for future use */

/* Page scan repetition modes */
#define HCI_SCAN_REP_MODE0			0x00
#define HCI_SCAN_REP_MODE1			0x01
#define HCI_SCAN_REP_MODE2			0x02
/* 0x03 - 0xFF - reserved for future use */

/* Page scan period modes */
#define HCI_PAGE_SCAN_PERIOD_MODE0		0x00
#define HCI_PAGE_SCAN_PERIOD_MODE1		0x01
#define HCI_PAGE_SCAN_PERIOD_MODE2		0x02
/* 0x03 - 0xFF - reserved for future use */

/* Scan enable */
#define HCI_NO_SCAN_ENABLE			0x00
#define HCI_INQUIRY_SCAN_ENABLE			0x01
#define HCI_PAGE_SCAN_ENABLE			0x02
/* 0x04 - 0xFF - reserved for future use */

/* Hold mode activities */
#define HCI_HOLD_MODE_NO_CHANGE			0x00
#define HCI_HOLD_MODE_SUSPEND_PAGE_SCAN		0x01
#define HCI_HOLD_MODE_SUSPEND_INQUIRY_SCAN	0x02
#define HCI_HOLD_MODE_SUSPEND_PERIOD_INQUIRY	0x04
/* 0x08 - 0x80 - reserved for future use */

/* Connection roles */
#define HCI_ROLE_MASTER				0x00
#define HCI_ROLE_SLAVE				0x01
/* 0x02 - 0xFF - reserved for future use */

/* Key flags */
#define HCI_USE_SEMI_PERMANENT_LINK_KEYS	0x00
#define HCI_USE_TEMPORARY_LINK_KEY		0x01
/* 0x02 - 0xFF - reserved for future use */

/* Pin types */
#define HCI_PIN_TYPE_VARIABLE			0x00
#define HCI_PIN_TYPE_FIXED			0x01

/* Link key types */
#define HCI_LINK_KEY_TYPE_COMBINATION_KEY	0x00
#define HCI_LINK_KEY_TYPE_LOCAL_UNIT_KEY	0x01
#define HCI_LINK_KEY_TYPE_REMOTE_UNIT_KEY	0x02
/* 0x03 - 0xFF - reserved for future use */

/* Encryption modes */
#define HCI_ENCRYPTION_MODE_NONE		0x00
#define HCI_ENCRYPTION_MODE_P2P			0x01
#define HCI_ENCRYPTION_MODE_ALL			0x02
/* 0x03 - 0xFF - reserved for future use */

/* Quality of service types */
#define HCI_SERVICE_TYPE_NO_TRAFFIC		0x00
#define HCI_SERVICE_TYPE_BEST_EFFORT		0x01
#define HCI_SERVICE_TYPE_GUARANTEED		0x02
/* 0x03 - 0xFF - reserved for future use */

/* Link policy settings */
#define HCI_LINK_POLICY_DISABLE_ALL_LM_MODES	0x0000
#define HCI_LINK_POLICY_ENABLE_ROLE_SWITCH	0x0001 /* Master/Slave switch */
#define HCI_LINK_POLICY_ENABLE_HOLD_MODE	0x0002
#define HCI_LINK_POLICY_ENABLE_SNIFF_MODE	0x0004
#define HCI_LINK_POLICY_ENABLE_PARK_MODE	0x0008
/* 0x0010 - 0x8000 - reserved for future use */

/* Event masks */
#define HCI_EVMSK_ALL				0x00000000ffffffff
#define HCI_EVMSK_NONE				0x0000000000000000
#define HCI_EVMSK_INQUIRY_COMPL			0x0000000000000001
#define HCI_EVMSK_INQUIRY_RESULT		0x0000000000000002
#define HCI_EVMSK_CON_COMPL			0x0000000000000004
#define HCI_EVMSK_CON_REQ			0x0000000000000008
#define HCI_EVMSK_DISCON_COMPL			0x0000000000000010
#define HCI_EVMSK_AUTH_COMPL			0x0000000000000020
#define HCI_EVMSK_REMOTE_NAME_REQ_COMPL		0x0000000000000040
#define HCI_EVMSK_ENCRYPTION_CHANGE		0x0000000000000080
#define HCI_EVMSK_CHANGE_CON_LINK_KEY_COMPL	0x0000000000000100
#define HCI_EVMSK_MASTER_LINK_KEY_COMPL		0x0000000000000200
#define HCI_EVMSK_READ_REMOTE_FEATURES_COMPL	0x0000000000000400
#define HCI_EVMSK_READ_REMOTE_VER_INFO_COMPL	0x0000000000000800
#define HCI_EVMSK_QOS_SETUP_COMPL		0x0000000000001000
#define HCI_EVMSK_COMMAND_COMPL			0x0000000000002000
#define HCI_EVMSK_COMMAND_STATUS		0x0000000000004000
#define HCI_EVMSK_HARDWARE_ERROR		0x0000000000008000
#define HCI_EVMSK_FLUSH_OCCUR			0x0000000000010000
#define HCI_EVMSK_ROLE_CHANGE			0x0000000000020000
#define HCI_EVMSK_NUM_COMPL_PKTS		0x0000000000040000
#define HCI_EVMSK_MODE_CHANGE			0x0000000000080000
#define HCI_EVMSK_RETURN_LINK_KEYS		0x0000000000100000
#define HCI_EVMSK_PIN_CODE_REQ			0x0000000000200000
#define HCI_EVMSK_LINK_KEY_REQ			0x0000000000400000
#define HCI_EVMSK_LINK_KEY_NOTIFICATION		0x0000000000800000
#define HCI_EVMSK_LOOPBACK_COMMAND		0x0000000001000000
#define HCI_EVMSK_DATA_BUFFER_OVERFLOW		0x0000000002000000
#define HCI_EVMSK_MAX_SLOT_CHANGE		0x0000000004000000
#define HCI_EVMSK_READ_CLOCK_OFFSET_COMLETE	0x0000000008000000
#define HCI_EVMSK_CON_PKT_TYPE_CHANGED		0x0000000010000000
#define HCI_EVMSK_QOS_VIOLATION			0x0000000020000000
#define HCI_EVMSK_PAGE_SCAN_MODE_CHANGE		0x0000000040000000
#define HCI_EVMSK_PAGE_SCAN_REP_MODE_CHANGE	0x0000000080000000
/* 0x0000000100000000 - 0x8000000000000000 - reserved for future use */

/* Filter types */
#define HCI_FILTER_TYPE_NONE			0x00
#define HCI_FILTER_TYPE_INQUIRY_RESULT		0x01
#define HCI_FILTER_TYPE_CON_SETUP		0x02
/* 0x03 - 0xFF - reserved for future use */

/* Filter condition types for HCI_FILTER_TYPE_INQUIRY_RESULT */
#define HCI_FILTER_COND_INQUIRY_NEW_UNIT	0x00
#define HCI_FILTER_COND_INQUIRY_UNIT_CLASS	0x01
#define HCI_FILTER_COND_INQUIRY_BDADDR		0x02
/* 0x03 - 0xFF - reserved for future use */

/* Filter condition types for HCI_FILTER_TYPE_CON_SETUP */
#define HCI_FILTER_COND_CON_ANY_UNIT		0x00
#define HCI_FILTER_COND_CON_UNIT_CLASS		0x01
#define HCI_FILTER_COND_CON_BDADDR		0x02
/* 0x03 - 0xFF - reserved for future use */

/* Xmit level types */
#define HCI_XMIT_LEVEL_CURRENT			0x00
#define HCI_XMIT_LEVEL_MAXIMUM			0x01
/* 0x02 - 0xFF - reserved for future use */

/* Host Controller to Host flow control */
#define HCI_HC2H_FLOW_CONTROL_NONE		0x00
#define HCI_HC2H_FLOW_CONTROL_ACL		0x01
#define HCI_HC2H_FLOW_CONTROL_SCO		0x02
#define HCI_HC2H_FLOW_CONTROL_BOTH		0x03
/* 0x04 - 0xFF - reserved future use */

/* Loopback modes */
#define HCI_LOOPBACK_NONE			0x00
#define HCI_LOOPBACK_LOCAL			0x01
#define HCI_LOOPBACK_REMOTE			0x02
/* 0x03 - 0xFF - reserved future use */

/**************************************************************************
 **************************************************************************
 **                 Link level defines, headers and types
 **************************************************************************
 **************************************************************************/

/*
 * Macro(s) to combine OpCode and extract OGF (OpCode Group Field)
 * and OCF (OpCode Command Field) from OpCode.
 */

#define HCI_OPCODE(gf,cf)		((((gf) & 0x3f) << 10) | ((cf) & 0x3ff))
#define HCI_OCF(op)			((op) & 0x3ff)
#define HCI_OGF(op)			(((op) >> 10) & 0x3f)

/*
 * Macro(s) to extract/combine connection handle, BC (Broadcast) and
 * PB (Packet boundary) flags.
 */

#define HCI_CON_HANDLE(h)		((h) & 0x0fff)
#define HCI_PB_FLAG(h)			(((h) & 0x3000) >> 12)
#define HCI_BC_FLAG(h)			(((h) & 0xc000) >> 14)
#define HCI_MK_CON_HANDLE(h, pb, bc) \
	(((h) & 0x0fff) | (((pb) & 3) << 12) | (((bc) & 3) << 14))

/* PB flag values */
					/* 00 - reserved for future use */
#define	HCI_PACKET_FRAGMENT		0x1
#define	HCI_PACKET_START		0x2
					/* 11 - reserved for future use */

/* BC flag values */
#define HCI_POINT2POINT			0x0 /* only Host controller to Host */
#define HCI_BROADCAST_ACTIVE		0x1 /* both directions */
#define HCI_BROADCAST_PICONET		0x2 /* both directions */
					/* 11 - reserved for future use */

/* HCI command packet header */
typedef struct {
	uint8_t		type;	/* MUST be 0x01 */
	uint16_t	opcode; /* OpCode */
	uint8_t		length; /* parameter(s) length in bytes */
} __attribute__ ((__packed__)) hci_cmd_hdr_t;

#define HCI_CMD_PKT			0x01
#define HCI_CMD_PKT_SIZE		(sizeof(hci_cmd_hdr_t) + 0xff)

/* ACL data packet header */
typedef struct {
	uint8_t		type;	     /* MUST be 0x02 */
	uint16_t	con_handle;  /* connection handle + PB + BC flags */
	uint16_t	length;      /* payload length in bytes */
} __attribute__ ((__packed__)) hci_acldata_hdr_t;

#define HCI_ACL_DATA_PKT		0x02
#define HCI_ACL_PKT_SIZE		(sizeof(hci_acldata_hdr_t) + 0xffff)

/* SCO data packet header */
typedef struct {
	uint8_t		type;	    /* MUST be 0x03 */
	uint16_t	con_handle; /* connection handle + reserved bits */
	uint8_t		length;     /* payload length in bytes */
} __attribute__ ((__packed__)) hci_scodata_hdr_t;

#define HCI_SCO_DATA_PKT		0x03
#define HCI_SCO_PKT_SIZE		(sizeof(hci_scodata_hdr_t) + 0xff)

/* HCI event packet header */
typedef struct {
	uint8_t		type;	/* MUST be 0x04 */
	uint8_t		event;  /* event */
	uint8_t		length; /* parameter(s) length in bytes */
} __attribute__ ((__packed__)) hci_event_hdr_t;

#define HCI_EVENT_PKT			0x04
#define HCI_EVENT_PKT_SIZE		(sizeof(hci_event_hdr_t) + 0xff)

/* HCI status return parameter */
typedef struct {
	uint8_t		status; /* 0x00 - success */
} __attribute__ ((__packed__)) hci_status_rp;

/**************************************************************************
 **************************************************************************
 ** OGF 0x01	Link control commands and return parameters
 **************************************************************************
 **************************************************************************/

#define HCI_OGF_LINK_CONTROL			0x01

#define HCI_OCF_INQUIRY					0x0001
#define HCI_CMD_INQUIRY					0x0401
typedef struct {
	uint8_t		lap[HCI_LAP_SIZE]; /* LAP */
	uint8_t		inquiry_length;    /* (N x 1.28) sec */
	uint8_t		num_responses;     /* Max. # of responses */
} __attribute__ ((__packed__)) hci_inquiry_cp;
/* No return parameter(s) */

#define HCI_OCF_INQUIRY_CANCEL				0x0002
#define HCI_CMD_INQUIRY_CANCEL				0x0402
/* No command parameter(s) */
typedef hci_status_rp	hci_inquiry_cancel_rp;

#define HCI_OCF_PERIODIC_INQUIRY			0x0003
#define HCI_CMD_PERIODIC_INQUIRY			0x0403
typedef struct {
	uint16_t	max_period_length; /* Max. and min. amount of time */
	uint16_t	min_period_length; /* between consecutive inquiries */
	uint8_t		lap[HCI_LAP_SIZE]; /* LAP */
	uint8_t		inquiry_length;    /* (inquiry_length * 1.28) sec */
	uint8_t		num_responses;     /* Max. # of responses */
} __attribute__ ((__packed__)) hci_periodic_inquiry_cp;

typedef hci_status_rp	hci_periodic_inquiry_rp;

#define HCI_OCF_EXIT_PERIODIC_INQUIRY			0x0004
#define HCI_CMD_EXIT_PERIODIC_INQUIRY			0x0404
/* No command parameter(s) */
typedef hci_status_rp	hci_exit_periodic_inquiry_rp;

#define HCI_OCF_CREATE_CON				0x0005
#define HCI_CMD_CREATE_CON				0x0405
typedef struct {
	bdaddr_t	bdaddr;		    /* destination address */
	uint16_t	pkt_type;	    /* packet type */
	uint8_t		page_scan_rep_mode; /* page scan repetition mode */
	uint8_t		page_scan_mode;     /* reserved - set to 0x00 */
	uint16_t	clock_offset;       /* clock offset */
	uint8_t		accept_role_switch; /* accept role switch? 0x00 == No */
} __attribute__ ((__packed__)) hci_create_con_cp;
/* No return parameter(s) */

#define HCI_OCF_DISCONNECT				0x0006
#define HCI_CMD_DISCONNECT				0x0406
typedef struct {
	uint16_t	con_handle; /* connection handle */
	uint8_t		reason;     /* reason to disconnect */
} __attribute__ ((__packed__)) hci_discon_cp;
/* No return parameter(s) */

/* Add SCO Connection is deprecated */
#define HCI_OCF_ADD_SCO_CON				0x0007
#define HCI_CMD_ADD_SCO_CON				0x0407
typedef struct {
	uint16_t	con_handle; /* connection handle */
	uint16_t	pkt_type;   /* packet type */
} __attribute__ ((__packed__)) hci_add_sco_con_cp;
/* No return parameter(s) */

#define HCI_OCF_CREATE_CON_CANCEL			0x0008
#define HCI_CMD_CREATE_CON_CANCEL			0x0408
typedef struct {
	bdaddr_t	bdaddr;		/* destination address */
} __attribute__ ((__packed__)) hci_create_con_cancel_cp;

typedef struct {
	uint8_t		status;		/* 0x00 - success */
	bdaddr_t	bdaddr;		/* destination address */
} __attribute__ ((__packed__)) hci_create_con_cancel_rp;

#define HCI_OCF_ACCEPT_CON				0x0009
#define HCI_CMD_ACCEPT_CON				0x0409
typedef struct {
	bdaddr_t	bdaddr; /* address of unit to be connected */
	uint8_t		role;   /* connection role */
} __attribute__ ((__packed__)) hci_accept_con_cp;
/* No return parameter(s) */

#define HCI_OCF_REJECT_CON				0x000a
#define HCI_CMD_REJECT_CON				0x040A
typedef struct {
	bdaddr_t	bdaddr; /* remote address */
	uint8_t		reason; /* reason to reject */
} __attribute__ ((__packed__)) hci_reject_con_cp;
/* No return parameter(s) */

#define HCI_OCF_LINK_KEY_REP				0x000b
#define HCI_CMD_LINK_KEY_REP				0x040B
typedef struct {
	bdaddr_t	bdaddr;		   /* remote address */
	uint8_t		key[HCI_KEY_SIZE]; /* key */
} __attribute__ ((__packed__)) hci_link_key_rep_cp;

typedef struct {
	uint8_t		status; /* 0x00 - success */
	bdaddr_t	bdaddr; /* unit address */
} __attribute__ ((__packed__)) hci_link_key_rep_rp;

#define HCI_OCF_LINK_KEY_NEG_REP			0x000c
#define HCI_CMD_LINK_KEY_NEG_REP			0x040C
typedef struct {
	bdaddr_t	bdaddr; /* remote address */
} __attribute__ ((__packed__)) hci_link_key_neg_rep_cp;

typedef struct {
	uint8_t		status; /* 0x00 - success */
	bdaddr_t	bdaddr; /* unit address */
} __attribute__ ((__packed__)) hci_link_key_neg_rep_rp;

#define HCI_OCF_PIN_CODE_REP				0x000d
#define HCI_CMD_PIN_CODE_REP				0x040D
typedef struct {
	bdaddr_t	bdaddr;		      /* remote address */
	uint8_t		pin_size;	      /* pin code length (in bytes) */
	uint8_t		pin[HCI_PIN_SIZE];    /* pin code */
} __attribute__ ((__packed__)) hci_pin_code_rep_cp;

typedef struct {
	uint8_t		status; /* 0x00 - success */
	bdaddr_t	bdaddr; /* unit address */
} __attribute__ ((__packed__)) hci_pin_code_rep_rp;

#define HCI_OCF_PIN_CODE_NEG_REP			0x000e
#define HCI_CMD_PIN_CODE_NEG_REP			0x040E
typedef struct {
	bdaddr_t	bdaddr; /* remote address */
} __attribute__ ((__packed__)) hci_pin_code_neg_rep_cp;

typedef struct {
	uint8_t		status; /* 0x00 - success */
	bdaddr_t	bdaddr; /* unit address */
} __attribute__ ((__packed__)) hci_pin_code_neg_rep_rp;

#define HCI_OCF_CHANGE_CON_PACKET_TYPE			0x000f
#define HCI_CMD_CHANGE_CON_PACKET_TYPE			0x040F
typedef struct {
	uint16_t	con_handle; /* connection handle */
	uint16_t	pkt_type;   /* packet type */
} __attribute__ ((__packed__)) hci_change_con_pkt_type_cp;
/* No return parameter(s) */

#define HCI_OCF_AUTH_REQ				0x0011
#define HCI_CMD_AUTH_REQ				0x0411
typedef struct {
	uint16_t	con_handle; /* connection handle */
} __attribute__ ((__packed__)) hci_auth_req_cp;
/* No return parameter(s) */

#define HCI_OCF_SET_CON_ENCRYPTION			0x0013
#define HCI_CMD_SET_CON_ENCRYPTION			0x0413
typedef struct {
	uint16_t	con_handle;	   /* connection handle */
	uint8_t		encryption_enable; /* 0x00 - disable, 0x01 - enable */
} __attribute__ ((__packed__)) hci_set_con_encryption_cp;
/* No return parameter(s) */

#define HCI_OCF_CHANGE_CON_LINK_KEY			0x0015
#define HCI_CMD_CHANGE_CON_LINK_KEY			0x0415
typedef struct {
	uint16_t	con_handle; /* connection handle */
} __attribute__ ((__packed__)) hci_change_con_link_key_cp;
/* No return parameter(s) */

#define HCI_OCF_MASTER_LINK_KEY				0x0017
#define HCI_CMD_MASTER_LINK_KEY				0x0417
typedef struct {
	uint8_t		key_flag; /* key flag */
} __attribute__ ((__packed__)) hci_master_link_key_cp;
/* No return parameter(s) */

#define HCI_OCF_REMOTE_NAME_REQ				0x0019
#define HCI_CMD_REMOTE_NAME_REQ				0x0419
typedef struct {
	bdaddr_t	bdaddr;		    /* remote address */
	uint8_t		page_scan_rep_mode; /* page scan repetition mode */
	uint8_t		page_scan_mode;     /* page scan mode */
	uint16_t	clock_offset;       /* clock offset */
} __attribute__ ((__packed__)) hci_remote_name_req_cp;
/* No return parameter(s) */

#define HCI_OCF_REMOTE_NAME_REQ_CANCEL			0x001a
#define HCI_CMD_REMOTE_NAME_REQ_CANCEL			0x041A
typedef struct {
	bdaddr_t	bdaddr;		/* remote address */
} __attribute__ ((__packed__)) hci_remote_name_req_cancel_cp;

typedef struct {
	uint8_t		status;		/* 0x00 - success */
	bdaddr_t	bdaddr;		/* remote address */
} __attribute__ ((__packed__)) hci_remote_name_req_cancel_rp;

#define HCI_OCF_READ_REMOTE_FEATURES			0x001b
#define HCI_CMD_READ_REMOTE_FEATURES			0x041B
typedef struct {
	uint16_t	con_handle; /* connection handle */
} __attribute__ ((__packed__)) hci_read_remote_features_cp;
/* No return parameter(s) */

#define HCI_OCF_READ_REMOTE_EXTENDED_FEATURES		0x001c
#define HCI_CMD_READ_REMOTE_EXTENDED_FEATURES		0x041C
typedef struct {
	uint16_t	con_handle;	/* connection handle */
	uint8_t		page;		/* page number */
} __attribute__ ((__packed__)) hci_read_remote_extended_features_cp;
/* No return parameter(s) */

#define HCI_OCF_READ_REMOTE_VER_INFO			0x001d
#define HCI_CMD_READ_REMOTE_VER_INFO			0x041D
typedef struct {
	uint16_t	con_handle; /* connection handle */
} __attribute__ ((__packed__)) hci_read_remote_ver_info_cp;
/* No return parameter(s) */

#define HCI_OCF_READ_CLOCK_OFFSET			0x001f
#define HCI_CMD_READ_CLOCK_OFFSET			0x041F
typedef struct {
	uint16_t	con_handle; /* connection handle */
} __attribute__ ((__packed__)) hci_read_clock_offset_cp;
/* No return parameter(s) */

#define HCI_OCF_READ_LMP_HANDLE				0x0020
#define HCI_CMD_READ_LMP_HANDLE				0x0420
typedef struct {
	uint16_t	con_handle; /* connection handle */
} __attribute__ ((__packed__)) hci_read_lmp_handle_cp;

typedef struct {
	uint8_t		status;	    /* 0x00 - success */
	uint16_t	con_handle; /* connection handle */
	uint8_t		lmp_handle; /* LMP handle */
	uint32_t	reserved;   /* reserved */
} __attribute__ ((__packed__)) hci_read_lmp_handle_rp;

#define HCI_OCF_SETUP_SCO_CON				0x0028
#define HCI_CMD_SETUP_SCO_CON				0x0428
typedef struct {
	uint16_t	con_handle;	/* connection handle */
	uint32_t	tx_bandwidth;	/* transmit bandwidth */
	uint32_t	rx_bandwidth;	/* receive bandwidth */
	uint16_t	latency;	/* maximum latency */
	uint16_t	voice;		/* voice setting */
	uint8_t		rt_effort;	/* retransmission effort */
	uint16_t	pkt_type;	/* packet types */
} __attribute__ ((__packed__)) hci_setup_sco_con_cp;
/* No return parameter(s) */

#define HCI_OCF_ACCEPT_SCO_CON_REQ			0x0029
#define HCI_CMD_ACCEPT_SCO_CON_REQ			0x0429
typedef struct {
	bdaddr_t	bdaddr;		/* remote address */
	uint32_t	tx_bandwidth;	/* transmit bandwidth */
	uint32_t	rx_bandwidth;	/* receive bandwidth */
	uint16_t	latency;	/* maximum latency */
	uint16_t	content;	/* voice setting */
	uint8_t		rt_effort;	/* retransmission effort */
	uint16_t	pkt_type;	/* packet types */
} __attribute__ ((__packed__)) hci_accept_sco_con_req_cp;
/* No return parameter(s) */

#define HCI_OCF_REJECT_SCO_CON_REQ			0x002a
#define HCI_CMD_REJECT_SCO_CON_REQ			0x042a
typedef struct {
	bdaddr_t	bdaddr;		/* remote address */
	uint8_t		reason;		/* reject error code */
} __attribute__ ((__packed__)) hci_reject_sco_con_req_cp;
/* No return parameter(s) */

/**************************************************************************
 **************************************************************************
 ** OGF 0x02	Link policy commands and return parameters
 **************************************************************************
 **************************************************************************/

#define HCI_OGF_LINK_POLICY			0x02

#define HCI_OCF_HOLD_MODE				0x0001
#define HCI_CMD_HOLD_MODE				0x0801
typedef struct {
	uint16_t	con_handle;   /* connection handle */
	uint16_t	max_interval; /* (max_interval * 0.625) msec */
	uint16_t	min_interval; /* (max_interval * 0.625) msec */
} __attribute__ ((__packed__)) hci_hold_mode_cp;
/* No return parameter(s) */

#define HCI_OCF_SNIFF_MODE				0x0003
#define HCI_CMD_SNIFF_MODE				0x0803
typedef struct {
	uint16_t	con_handle;   /* connection handle */
	uint16_t	max_interval; /* (max_interval * 0.625) msec */
	uint16_t	min_interval; /* (max_interval * 0.625) msec */
	uint16_t	attempt;      /* (2 * attempt - 1) * 0.625 msec */
	uint16_t	timeout;      /* (2 * attempt - 1) * 0.625 msec */
} __attribute__ ((__packed__)) hci_sniff_mode_cp;
/* No return parameter(s) */

#define HCI_OCF_EXIT_SNIFF_MODE				0x0004
#define HCI_CMD_EXIT_SNIFF_MODE				0x0804
typedef struct {
	uint16_t	con_handle; /* connection handle */
} __attribute__ ((__packed__)) hci_exit_sniff_mode_cp;
/* No return parameter(s) */

#define HCI_OCF_PARK_MODE				0x0005
#define HCI_CMD_PARK_MODE				0x0805
typedef struct {
	uint16_t	con_handle;   /* connection handle */
	uint16_t	max_interval; /* (max_interval * 0.625) msec */
	uint16_t	min_interval; /* (max_interval * 0.625) msec */
} __attribute__ ((__packed__)) hci_park_mode_cp;
/* No return parameter(s) */

#define HCI_OCF_EXIT_PARK_MODE				0x0006
#define HCI_CMD_EXIT_PARK_MODE				0x0806
typedef struct {
	uint16_t	con_handle; /* connection handle */
} __attribute__ ((__packed__)) hci_exit_park_mode_cp;
/* No return parameter(s) */

#define HCI_OCF_QOS_SETUP				0x0007
#define HCI_CMD_QOS_SETUP				0x0807
typedef struct {
	uint16_t	con_handle;      /* connection handle */
	uint8_t		flags;		 /* reserved for future use */
	uint8_t		service_type;    /* service type */
	uint32_t	token_rate;      /* bytes per second */
	uint32_t	peak_bandwidth;  /* bytes per second */
	uint32_t	latency;	 /* microseconds */
	uint32_t	delay_variation; /* microseconds */
} __attribute__ ((__packed__)) hci_qos_setup_cp;
/* No return parameter(s) */

#define HCI_OCF_ROLE_DISCOVERY				0x0009
#define HCI_CMD_ROLE_DISCOVERY				0x0809
typedef struct {
	uint16_t	con_handle; /* connection handle */
} __attribute__ ((__packed__)) hci_role_discovery_cp;

typedef struct {
	uint8_t		status;     /* 0x00 - success */
	uint16_t	con_handle; /* connection handle */
	uint8_t		role;       /* role for the connection handle */
} __attribute__ ((__packed__)) hci_role_discovery_rp;

#define HCI_OCF_SWITCH_ROLE				0x000b
#define HCI_CMD_SWITCH_ROLE				0x080B
typedef struct {
	bdaddr_t	bdaddr; /* remote address */
	uint8_t		role;   /* new local role */
} __attribute__ ((__packed__)) hci_switch_role_cp;
/* No return parameter(s) */

#define HCI_OCF_READ_LINK_POLICY_SETTINGS		0x000c
#define HCI_CMD_READ_LINK_POLICY_SETTINGS		0x080C
typedef struct {
	uint16_t	con_handle; /* connection handle */
} __attribute__ ((__packed__)) hci_read_link_policy_settings_cp;

typedef struct {
	uint8_t		status;     /* 0x00 - success */
	uint16_t	con_handle; /* connection handle */
	uint16_t	settings;   /* link policy settings */
} __attribute__ ((__packed__)) hci_read_link_policy_settings_rp;

#define HCI_OCF_WRITE_LINK_POLICY_SETTINGS		0x000d
#define HCI_CMD_WRITE_LINK_POLICY_SETTINGS		0x080D
typedef struct {
	uint16_t	con_handle; /* connection handle */
	uint16_t	settings;   /* link policy settings */
} __attribute__ ((__packed__)) hci_write_link_policy_settings_cp;

typedef struct {
	uint8_t		status;     /* 0x00 - success */
	uint16_t	con_handle; /* connection handle */
} __attribute__ ((__packed__)) hci_write_link_policy_settings_rp;

#define HCI_OCF_READ_DEFAULT_LINK_POLICY_SETTINGS	0x000e
#define HCI_CMD_READ_DEFAULT_LINK_POLICY_SETTINGS	0x080E
/* No command parameter(s) */
typedef struct {
	uint8_t		status;     /* 0x00 - success */
	uint16_t	settings;   /* link policy settings */
} __attribute__ ((__packed__)) hci_read_default_link_policy_settings_rp;

#define HCI_OCF_WRITE_DEFAULT_LINK_POLICY_SETTINGS	0x000f
#define HCI_CMD_WRITE_DEFAULT_LINK_POLICY_SETTINGS	0x080F
typedef struct {
	uint16_t	settings;   /* link policy settings */
} __attribute__ ((__packed__)) hci_write_default_link_policy_settings_cp;

typedef hci_status_rp	hci_write_default_link_policy_settings_rp;

#define HCI_OCF_FLOW_SPECIFICATION			0x0010
#define HCI_CMD_FLOW_SPECIFICATION			0x0810
typedef struct {
	uint16_t	con_handle;	/* connection handle */
	uint8_t		flags;		/* reserved */
	uint8_t		flow_direction;
	uint8_t		service_type;
	uint32_t	token_rate;
	uint32_t	token_bucket;
	uint32_t	peak_bandwidth;
	uint32_t	latency;
} __attribute__ ((__packed__)) hci_flow_specification_cp;
/* No return parameter(s) */

/**************************************************************************
 **************************************************************************
 ** OGF 0x03	Host Controller and Baseband commands and return parameters
 **************************************************************************
 **************************************************************************/

#define HCI_OGF_HC_BASEBAND			0x03

#define HCI_OCF_SET_EVENT_MASK				0x0001
#define HCI_CMD_SET_EVENT_MASK				0x0C01
typedef struct {
	uint8_t		event_mask[HCI_EVENT_MASK_SIZE]; /* event_mask */
} __attribute__ ((__packed__)) hci_set_event_mask_cp;

typedef hci_status_rp	hci_set_event_mask_rp;

#define HCI_OCF_RESET					0x0003
#define HCI_CMD_RESET					0x0C03
/* No command parameter(s) */
typedef hci_status_rp	hci_reset_rp;

#define HCI_OCF_SET_EVENT_FILTER			0x0005
#define HCI_CMD_SET_EVENT_FILTER			0x0C05
typedef struct {
	uint8_t		filter_type;	       /* filter type */
	uint8_t		filter_condition_type; /* filter condition type */
/* variable size condition
	uint8_t		condition[]; -- conditions */
} __attribute__ ((__packed__)) hci_set_event_filter_cp;

typedef hci_status_rp	hci_set_event_filter_rp;

#define HCI_OCF_FLUSH					0x0008
#define HCI_CMD_FLUSH					0x0C08
typedef struct {
	uint16_t	con_handle; /* connection handle */
} __attribute__ ((__packed__)) hci_flush_cp;

typedef struct {
	uint8_t		status;     /* 0x00 - success */
	uint16_t	con_handle; /* connection handle */
} __attribute__ ((__packed__)) hci_flush_rp;

#define HCI_OCF_READ_PIN_TYPE				0x0009
#define HCI_CMD_READ_PIN_TYPE				0x0C09
/* No command parameter(s) */
typedef struct {
	uint8_t		status;   /* 0x00 - success */
	uint8_t		pin_type; /* PIN type */
} __attribute__ ((__packed__)) hci_read_pin_type_rp;

#define HCI_OCF_WRITE_PIN_TYPE				0x000a
#define HCI_CMD_WRITE_PIN_TYPE				0x0C0A
typedef struct {
	uint8_t		pin_type; /* PIN type */
} __attribute__ ((__packed__)) hci_write_pin_type_cp;

typedef hci_status_rp	hci_write_pin_type_rp;

#define HCI_OCF_CREATE_NEW_UNIT_KEY			0x000b
#define HCI_CMD_CREATE_NEW_UNIT_KEY			0x0C0B
/* No command parameter(s) */
typedef hci_status_rp	hci_create_new_unit_key_rp;

#define HCI_OCF_READ_STORED_LINK_KEY			0x000d
#define HCI_CMD_READ_STORED_LINK_KEY			0x0C0D
typedef struct {
	bdaddr_t	bdaddr;   /* address */
	uint8_t		read_all; /* read all keys? 0x01 - yes */
} __attribute__ ((__packed__)) hci_read_stored_link_key_cp;

typedef struct {
	uint8_t		status;	       /* 0x00 - success */
	uint16_t	max_num_keys;  /* Max. number of keys */
	uint16_t	num_keys_read; /* Number of stored keys */
} __attribute__ ((__packed__)) hci_read_stored_link_key_rp;

#define HCI_OCF_WRITE_STORED_LINK_KEY			0x0011
#define HCI_CMD_WRITE_STORED_LINK_KEY			0x0C11
typedef struct {
	uint8_t		num_keys_write; /* # of keys to write */
/* these are repeated "num_keys_write" times
	bdaddr_t	bdaddr;             --- remote address(es)
	uint8_t		key[HCI_KEY_SIZE];  --- key(s) */
} __attribute__ ((__packed__)) hci_write_stored_link_key_cp;

typedef struct {
	uint8_t		status;		  /* 0x00 - success */
	uint8_t		num_keys_written; /* # of keys successfully written */
} __attribute__ ((__packed__)) hci_write_stored_link_key_rp;

#define HCI_OCF_DELETE_STORED_LINK_KEY			0x0012
#define HCI_CMD_DELETE_STORED_LINK_KEY			0x0C12
typedef struct {
	bdaddr_t	bdaddr;     /* address */
	uint8_t		delete_all; /* delete all keys? 0x01 - yes */
} __attribute__ ((__packed__)) hci_delete_stored_link_key_cp;

typedef struct {
	uint8_t		status;		  /* 0x00 - success */
	uint16_t	num_keys_deleted; /* Number of keys deleted */
} __attribute__ ((__packed__)) hci_delete_stored_link_key_rp;

#define HCI_OCF_WRITE_LOCAL_NAME			0x0013
#define HCI_CMD_WRITE_LOCAL_NAME			0x0C13
typedef struct {
	char		name[HCI_UNIT_NAME_SIZE]; /* new unit name */
} __attribute__ ((__packed__)) hci_write_local_name_cp;

typedef hci_status_rp	hci_write_local_name_rp;

#define HCI_OCF_READ_LOCAL_NAME				0x0014
#define HCI_CMD_READ_LOCAL_NAME				0x0C14
/* No command parameter(s) */
typedef struct {
	uint8_t		status;			  /* 0x00 - success */
	char		name[HCI_UNIT_NAME_SIZE]; /* unit name */
} __attribute__ ((__packed__)) hci_read_local_name_rp;

#define HCI_OCF_READ_CON_ACCEPT_TIMEOUT			0x0015
#define HCI_CMD_READ_CON_ACCEPT_TIMEOUT			0x0C15
/* No command parameter(s) */
typedef struct {
	uint8_t		status;  /* 0x00 - success */
	uint16_t	timeout; /* (timeout * 0.625) msec */
} __attribute__ ((__packed__)) hci_read_con_accept_timeout_rp;

#define HCI_OCF_WRITE_CON_ACCEPT_TIMEOUT		0x0016
#define HCI_CMD_WRITE_CON_ACCEPT_TIMEOUT		0x0C16
typedef struct {
	uint16_t	timeout; /* (timeout * 0.625) msec */
} __attribute__ ((__packed__)) hci_write_con_accept_timeout_cp;

typedef hci_status_rp	hci_write_con_accept_timeout_rp;

#define HCI_OCF_READ_PAGE_TIMEOUT			0x0017
#define HCI_CMD_READ_PAGE_TIMEOUT			0x0C17
/* No command parameter(s) */
typedef struct {
	uint8_t		status;  /* 0x00 - success */
	uint16_t	timeout; /* (timeout * 0.625) msec */
} __attribute__ ((__packed__)) hci_read_page_timeout_rp;

#define HCI_OCF_WRITE_PAGE_TIMEOUT			0x0018
#define HCI_CMD_WRITE_PAGE_TIMEOUT			0x0C18
typedef struct {
	uint16_t	timeout; /* (timeout * 0.625) msec */
} __attribute__ ((__packed__)) hci_write_page_timeout_cp;

typedef hci_status_rp	hci_write_page_timeout_rp;

#define HCI_OCF_READ_SCAN_ENABLE			0x0019
#define HCI_CMD_READ_SCAN_ENABLE			0x0C19
/* No command parameter(s) */
typedef struct {
	uint8_t		status;      /* 0x00 - success */
	uint8_t		scan_enable; /* Scan enable */
} __attribute__ ((__packed__)) hci_read_scan_enable_rp;

#define HCI_OCF_WRITE_SCAN_ENABLE			0x001a
#define HCI_CMD_WRITE_SCAN_ENABLE			0x0C1A
typedef struct {
	uint8_t		scan_enable; /* Scan enable */
} __attribute__ ((__packed__)) hci_write_scan_enable_cp;

typedef hci_status_rp	hci_write_scan_enable_rp;

#define HCI_OCF_READ_PAGE_SCAN_ACTIVITY			0x001b
#define HCI_CMD_READ_PAGE_SCAN_ACTIVITY			0x0C1B
/* No command parameter(s) */
typedef struct {
	uint8_t		status;		    /* 0x00 - success */
	uint16_t	page_scan_interval; /* interval * 0.625 msec */
	uint16_t	page_scan_window;   /* window * 0.625 msec */
} __attribute__ ((__packed__)) hci_read_page_scan_activity_rp;

#define HCI_OCF_WRITE_PAGE_SCAN_ACTIVITY		0x001c
#define HCI_CMD_WRITE_PAGE_SCAN_ACTIVITY		0x0C1C
typedef struct {
	uint16_t	page_scan_interval; /* interval * 0.625 msec */
	uint16_t	page_scan_window;   /* window * 0.625 msec */
} __attribute__ ((__packed__)) hci_write_page_scan_activity_cp;

typedef hci_status_rp	hci_write_page_scan_activity_rp;

#define HCI_OCF_READ_INQUIRY_SCAN_ACTIVITY		0x001d
#define HCI_CMD_READ_INQUIRY_SCAN_ACTIVITY		0x0C1D
/* No command parameter(s) */
typedef struct {
	uint8_t		status;		       /* 0x00 - success */
	uint16_t	inquiry_scan_interval; /* interval * 0.625 msec */
	uint16_t	inquiry_scan_window;   /* window * 0.625 msec */
} __attribute__ ((__packed__)) hci_read_inquiry_scan_activity_rp;

#define HCI_OCF_WRITE_INQUIRY_SCAN_ACTIVITY		0x001e
#define HCI_CMD_WRITE_INQUIRY_SCAN_ACTIVITY		0x0C1E
typedef struct {
	uint16_t	inquiry_scan_interval; /* interval * 0.625 msec */
	uint16_t	inquiry_scan_window;   /* window * 0.625 msec */
} __attribute__ ((__packed__)) hci_write_inquiry_scan_activity_cp;

typedef hci_status_rp	hci_write_inquiry_scan_activity_rp;

#define HCI_OCF_READ_AUTH_ENABLE			0x001f
#define HCI_CMD_READ_AUTH_ENABLE			0x0C1F
/* No command parameter(s) */
typedef struct {
	uint8_t		status;      /* 0x00 - success */
	uint8_t		auth_enable; /* 0x01 - enabled */
} __attribute__ ((__packed__)) hci_read_auth_enable_rp;

#define HCI_OCF_WRITE_AUTH_ENABLE			0x0020
#define HCI_CMD_WRITE_AUTH_ENABLE			0x0C20
typedef struct {
	uint8_t		auth_enable; /* 0x01 - enabled */
} __attribute__ ((__packed__)) hci_write_auth_enable_cp;

typedef hci_status_rp	hci_write_auth_enable_rp;

#define HCI_OCF_READ_ENCRYPTION_MODE			0x0021
#define HCI_CMD_READ_ENCRYPTION_MODE			0x0C21
/* No command parameter(s) */
typedef struct {
	uint8_t		status;		 /* 0x00 - success */
	uint8_t		encryption_mode; /* encryption mode */
} __attribute__ ((__packed__)) hci_read_encryption_mode_rp;

#define HCI_OCF_WRITE_ENCRYPTION_MODE			0x0022
#define HCI_CMD_WRITE_ENCRYPTION_MODE			0x0C22
typedef struct {
	uint8_t		encryption_mode; /* encryption mode */
} __attribute__ ((__packed__)) hci_write_encryption_mode_cp;

typedef hci_status_rp	hci_write_encryption_mode_rp;

#define HCI_OCF_READ_UNIT_CLASS				0x0023
#define HCI_CMD_READ_UNIT_CLASS				0x0C23
/* No command parameter(s) */
typedef struct {
	uint8_t		status;		/* 0x00 - success */
	uint8_t		uclass[HCI_CLASS_SIZE]; /* unit class */
} __attribute__ ((__packed__)) hci_read_unit_class_rp;

#define HCI_OCF_WRITE_UNIT_CLASS			0x0024
#define HCI_CMD_WRITE_UNIT_CLASS			0x0C24
typedef struct {
	uint8_t		uclass[HCI_CLASS_SIZE]; /* unit class */
} __attribute__ ((__packed__)) hci_write_unit_class_cp;

typedef hci_status_rp	hci_write_unit_class_rp;

#define HCI_OCF_READ_VOICE_SETTING			0x0025
#define HCI_CMD_READ_VOICE_SETTING			0x0C25
/* No command parameter(s) */
typedef struct {
	uint8_t		status;   /* 0x00 - success */
	uint16_t	settings; /* voice settings */
} __attribute__ ((__packed__)) hci_read_voice_setting_rp;

#define HCI_OCF_WRITE_VOICE_SETTING			0x0026
#define HCI_CMD_WRITE_VOICE_SETTING			0x0C26
typedef struct {
	uint16_t	settings; /* voice settings */
} __attribute__ ((__packed__)) hci_write_voice_setting_cp;

typedef hci_status_rp	hci_write_voice_setting_rp;

#define HCI_OCF_READ_AUTO_FLUSH_TIMEOUT			0x0027
#define HCI_CMD_READ_AUTO_FLUSH_TIMEOUT			0x0C27
typedef struct {
	uint16_t	con_handle; /* connection handle */
} __attribute__ ((__packed__)) hci_read_auto_flush_timeout_cp;

typedef struct {
	uint8_t		status;     /* 0x00 - success */
	uint16_t	con_handle; /* connection handle */
	uint16_t	timeout;    /* 0x00 - no flush, timeout * 0.625 msec */
} __attribute__ ((__packed__)) hci_read_auto_flush_timeout_rp;

#define HCI_OCF_WRITE_AUTO_FLUSH_TIMEOUT		0x0028
#define HCI_CMD_WRITE_AUTO_FLUSH_TIMEOUT		0x0C28
typedef struct {
	uint16_t	con_handle; /* connection handle */
	uint16_t	timeout;    /* 0x00 - no flush, timeout * 0.625 msec */
} __attribute__ ((__packed__)) hci_write_auto_flush_timeout_cp;

typedef struct {
	uint8_t		status;     /* 0x00 - success */
	uint16_t	con_handle; /* connection handle */
} __attribute__ ((__packed__)) hci_write_auto_flush_timeout_rp;

#define HCI_OCF_READ_NUM_BROADCAST_RETRANS		0x0029
#define HCI_CMD_READ_NUM_BROADCAST_RETRANS		0x0C29
/* No command parameter(s) */
typedef struct {
	uint8_t		status;  /* 0x00 - success */
	uint8_t		counter; /* number of broadcast retransmissions */
} __attribute__ ((__packed__)) hci_read_num_broadcast_retrans_rp;

#define HCI_OCF_WRITE_NUM_BROADCAST_RETRANS		0x002a
#define HCI_CMD_WRITE_NUM_BROADCAST_RETRANS		0x0C2A
typedef struct {
	uint8_t		counter; /* number of broadcast retransmissions */
} __attribute__ ((__packed__)) hci_write_num_broadcast_retrans_cp;

typedef hci_status_rp	hci_write_num_broadcast_retrans_rp;

#define HCI_OCF_READ_HOLD_MODE_ACTIVITY			0x002b
#define HCI_CMD_READ_HOLD_MODE_ACTIVITY			0x0C2B
/* No command parameter(s) */
typedef struct {
	uint8_t		status;		    /* 0x00 - success */
	uint8_t		hold_mode_activity; /* Hold mode activities */
} __attribute__ ((__packed__)) hci_read_hold_mode_activity_rp;

#define HCI_OCF_WRITE_HOLD_MODE_ACTIVITY		0x002c
#define HCI_CMD_WRITE_HOLD_MODE_ACTIVITY		0x0C2C
typedef struct {
	uint8_t		hold_mode_activity; /* Hold mode activities */
} __attribute__ ((__packed__)) hci_write_hold_mode_activity_cp;

typedef hci_status_rp	hci_write_hold_mode_activity_rp;

#define HCI_OCF_READ_XMIT_LEVEL				0x002d
#define HCI_CMD_READ_XMIT_LEVEL				0x0C2D
typedef struct {
	uint16_t	con_handle; /* connection handle */
	uint8_t		type;       /* Xmit level type */
} __attribute__ ((__packed__)) hci_read_xmit_level_cp;

typedef struct {
	uint8_t		status;     /* 0x00 - success */
	uint16_t	con_handle; /* connection handle */
	char		level;      /* -30 <= level <= 30 dBm */
} __attribute__ ((__packed__)) hci_read_xmit_level_rp;

#define HCI_OCF_READ_SCO_FLOW_CONTROL			0x002e
#define HCI_CMD_READ_SCO_FLOW_CONTROL			0x0C2E
/* No command parameter(s) */
typedef struct {
	uint8_t		status;       /* 0x00 - success */
	uint8_t		flow_control; /* 0x00 - disabled */
} __attribute__ ((__packed__)) hci_read_sco_flow_control_rp;

#define HCI_OCF_WRITE_SCO_FLOW_CONTROL			0x002f
#define HCI_CMD_WRITE_SCO_FLOW_CONTROL			0x0C2F
typedef struct {
	uint8_t		flow_control; /* 0x00 - disabled */
} __attribute__ ((__packed__)) hci_write_sco_flow_control_cp;

typedef hci_status_rp	hci_write_sco_flow_control_rp;

#define HCI_OCF_HC2H_FLOW_CONTROL			0x0031
#define HCI_CMD_HC2H_FLOW_CONTROL			0x0C31
typedef struct {
	uint8_t		hc2h_flow; /* Host Controller to Host flow control */
} __attribute__ ((__packed__)) hci_hc2h_flow_control_cp;

typedef hci_status_rp	hci_h2hc_flow_control_rp;

#define HCI_OCF_HOST_BUFFER_SIZE			0x0033
#define HCI_CMD_HOST_BUFFER_SIZE			0x0C33
typedef struct {
	uint16_t	max_acl_size; /* Max. size of ACL packet (bytes) */
	uint8_t		max_sco_size; /* Max. size of SCO packet (bytes) */
	uint16_t	num_acl_pkts;  /* Max. number of ACL packets */
	uint16_t	num_sco_pkts;  /* Max. number of SCO packets */
} __attribute__ ((__packed__)) hci_host_buffer_size_cp;

typedef hci_status_rp	hci_host_buffer_size_rp;

#define HCI_OCF_HOST_NUM_COMPL_PKTS			0x0035
#define HCI_CMD_HOST_NUM_COMPL_PKTS			0x0C35
typedef struct {
	uint8_t		nu_con_handles; /* # of connection handles */
/* these are repeated "num_con_handles" times
	uint16_t	con_handle;    --- connection handle(s)
	uint16_t	compl_pkts;    --- # of completed packets */
} __attribute__ ((__packed__)) hci_host_num_compl_pkts_cp;
/* No return parameter(s) */

#define HCI_OCF_READ_LINK_SUPERVISION_TIMEOUT		0x0036
#define HCI_CMD_READ_LINK_SUPERVISION_TIMEOUT		0x0C36
typedef struct {
	uint16_t	con_handle; /* connection handle */
} __attribute__ ((__packed__)) hci_read_link_supervision_timeout_cp;

typedef struct {
	uint8_t		status;     /* 0x00 - success */
	uint16_t	con_handle; /* connection handle */
	uint16_t	timeout;    /* Link supervision timeout * 0.625 msec */
} __attribute__ ((__packed__)) hci_read_link_supervision_timeout_rp;

#define HCI_OCF_WRITE_LINK_SUPERVISION_TIMEOUT		0x0037
#define HCI_CMD_WRITE_LINK_SUPERVISION_TIMEOUT		0x0C37
typedef struct {
	uint16_t	con_handle; /* connection handle */
	uint16_t	timeout;    /* Link supervision timeout * 0.625 msec */
} __attribute__ ((__packed__)) hci_write_link_supervision_timeout_cp;

typedef struct {
	uint8_t		status;     /* 0x00 - success */
	uint16_t	con_handle; /* connection handle */
} __attribute__ ((__packed__)) hci_write_link_supervision_timeout_rp;

#define HCI_OCF_READ_NUM_SUPPORTED_IAC			0x0038
#define HCI_CMD_READ_NUM_SUPPORTED_IAC			0x0C38
/* No command parameter(s) */
typedef struct {
	uint8_t		status;  /* 0x00 - success */
	uint8_t		num_iac; /* # of supported IAC during scan */
} __attribute__ ((__packed__)) hci_read_num_supported_iac_rp;

#define HCI_OCF_READ_IAC_LAP				0x0039
#define HCI_CMD_READ_IAC_LAP				0x0C39
/* No command parameter(s) */
typedef struct {
	uint8_t		status;  /* 0x00 - success */
	uint8_t		num_iac; /* # of IAC */
/* these are repeated "num_iac" times
	uint8_t		laps[HCI_LAP_SIZE]; --- LAPs */
} __attribute__ ((__packed__)) hci_read_iac_lap_rp;

#define HCI_OCF_WRITE_IAC_LAP				0x003a
#define HCI_CMD_WRITE_IAC_LAP				0x0C3A
typedef struct {
	uint8_t		num_iac; /* # of IAC */
/* these are repeated "num_iac" times
	uint8_t		laps[HCI_LAP_SIZE]; --- LAPs */
} __attribute__ ((__packed__)) hci_write_iac_lap_cp;

typedef hci_status_rp	hci_write_iac_lap_rp;

#define HCI_OCF_READ_PAGE_SCAN_PERIOD			0x003b
#define HCI_CMD_READ_PAGE_SCAN_PERIOD			0x0C3B
/* No command parameter(s) */
typedef struct {
	uint8_t		status;		       /* 0x00 - success */
	uint8_t		page_scan_period_mode; /* Page scan period mode */
} __attribute__ ((__packed__)) hci_read_page_scan_period_rp;

#define HCI_OCF_WRITE_PAGE_SCAN_PERIOD			0x003c
#define HCI_CMD_WRITE_PAGE_SCAN_PERIOD			0x0C3C
typedef struct {
	uint8_t		page_scan_period_mode; /* Page scan period mode */
} __attribute__ ((__packed__)) hci_write_page_scan_period_cp;

typedef hci_status_rp	hci_write_page_scan_period_rp;

/* Read Page Scan Mode is deprecated */
#define HCI_OCF_READ_PAGE_SCAN				0x003d
#define HCI_CMD_READ_PAGE_SCAN				0x0C3D
/* No command parameter(s) */
typedef struct {
	uint8_t		status;		/* 0x00 - success */
	uint8_t		page_scan_mode; /* Page scan mode */
} __attribute__ ((__packed__)) hci_read_page_scan_rp;

/* Write Page Scan Mode is deprecated */
#define HCI_OCF_WRITE_PAGE_SCAN				0x003e
#define HCI_CMD_WRITE_PAGE_SCAN				0x0C3E
typedef struct {
	uint8_t		page_scan_mode; /* Page scan mode */
} __attribute__ ((__packed__)) hci_write_page_scan_cp;

typedef hci_status_rp	hci_write_page_scan_rp;

#define HCI_OCF_SET_AFH_CLASSIFICATION			0x003f
#define HCI_CMD_SET_AFH_CLASSIFICATION			0x0C3F
typedef struct {
	uint8_t		classification[10];
} __attribute__ ((__packed__)) hci_set_afh_classification_cp;

typedef hci_status_rp	hci_set_afh_classification_rp;

#define HCI_OCF_READ_INQUIRY_SCAN_TYPE			0x0042
#define HCI_CMD_READ_INQUIRY_SCAN_TYPE			0x0C42
/* No command parameter(s) */

typedef struct {
	uint8_t		status;		/* 0x00 - success */
	uint8_t		type;		/* inquiry scan type */
} __attribute__ ((__packed__)) hci_read_inquiry_scan_type_rp;

#define HCI_OCF_WRITE_INQUIRY_SCAN_TYPE			0x0043
#define HCI_CMD_WRITE_INQUIRY_SCAN_TYPE			0x0C43
typedef struct {
	uint8_t		type;		/* inquiry scan type */
} __attribute__ ((__packed__)) hci_write_inquiry_scan_type_cp;

typedef hci_status_rp	hci_write_inquiry_scan_type_rp;

#define HCI_OCF_READ_INQUIRY_MODE			0x0044
#define HCI_CMD_READ_INQUIRY_MODE			0x0C44
/* No command parameter(s) */

typedef struct {
	uint8_t		status;		/* 0x00 - success */
	uint8_t		mode;		/* inquiry mode */
} __attribute__ ((__packed__)) hci_read_inquiry_mode_rp;

#define HCI_OCF_WRITE_INQUIRY_MODE			0x0045
#define HCI_CMD_WRITE_INQUIRY_MODE			0x0C45
typedef struct {
	uint8_t		mode;		/* inquiry mode */
} __attribute__ ((__packed__)) hci_write_inquiry_mode_cp;

typedef hci_status_rp	hci_write_inquiry_mode_rp;

#define HCI_OCF_READ_PAGE_SCAN_TYPE			0x0046
#define HCI_CMD_READ_PAGE_SCAN_TYPE			0x0C46
/* No command parameter(s) */

typedef struct {
	uint8_t		status;		/* 0x00 - success */
	uint8_t		type;		/* page scan type */
} __attribute__ ((__packed__)) hci_read_page_scan_type_rp;

#define HCI_OCF_WRITE_PAGE_SCAN_TYPE			0x0047
#define HCI_CMD_WRITE_PAGE_SCAN_TYPE			0x0C47
typedef struct {
	uint8_t		type;		/* page scan type */
} __attribute__ ((__packed__)) hci_write_page_scan_type_cp;

typedef hci_status_rp	hci_write_page_scan_type_rp;

#define HCI_OCF_READ_AFH_ASSESSMENT			0x0048
#define HCI_CMD_READ_AFH_ASSESSMENT			0x0C48
/* No command parameter(s) */

typedef struct {
	uint8_t		status;		/* 0x00 - success */
	uint8_t		mode;		/* assessment mode */
} __attribute__ ((__packed__)) hci_read_afh_assessment_rp;

#define HCI_OCF_WRITE_AFH_ASSESSMENT			0x0049
#define HCI_CMD_WRITE_AFH_ASSESSMENT			0x0C49
typedef struct {
	uint8_t		mode;		/* assessment mode */
} __attribute__ ((__packed__)) hci_write_afh_assessment_cp;

typedef hci_status_rp	hci_write_afh_assessment_rp;

/**************************************************************************
 **************************************************************************
 ** OGF 0x04	Informational commands and return parameters
 **************************************************************************
 **************************************************************************/

#define HCI_OGF_INFO				0x04

#define HCI_OCF_READ_LOCAL_VER				0x0001
#define HCI_CMD_READ_LOCAL_VER				0x1001
/* No command parameter(s) */
typedef struct {
	uint8_t		status;		/* 0x00 - success */
	uint8_t		hci_version;    /* HCI version */
	uint16_t	hci_revision;   /* HCI revision */
	uint8_t		lmp_version;    /* LMP version */
	uint16_t	manufacturer;   /* Hardware manufacturer name */
	uint16_t	lmp_subversion; /* LMP sub-version */
} __attribute__ ((__packed__)) hci_read_local_ver_rp;

#define HCI_OCF_READ_LOCAL_COMMANDS			0x0002
#define HCI_CMD_READ_LOCAL_COMMANDS			0x1002
/* No command parameter(s) */
typedef struct {
	uint8_t		status;		/* 0x00 - success */
	uint8_t		commands[64];	/* opcode bitmask */
} __attribute__ ((__packed__)) hci_read_local_commands_rp;

#define HCI_OCF_READ_LOCAL_FEATURES			0x0003
#define HCI_CMD_READ_LOCAL_FEATURES			0x1003
/* No command parameter(s) */
typedef struct {
	uint8_t		status;			     /* 0x00 - success */
	uint8_t		features[HCI_FEATURES_SIZE]; /* LMP features bitmsk*/
} __attribute__ ((__packed__)) hci_read_local_features_rp;

#define HCI_OCF_READ_LOCAL_EXTENDED_FEATURES		0x0004
#define HCI_CMD_READ_LOCAL_EXTENDED_FEATURES		0x1004
typedef struct {
	uint8_t		page;		/* page number */
} __attribute__ ((__packed__)) hci_read_local_extended_features_cp;

typedef struct {
	uint8_t		status;		/* 0x00 - success */
	uint8_t		page;		/* page number */
	uint8_t		max_page;	/* maximum page number */
	uint8_t		features[HCI_FEATURES_SIZE];	/* LMP features */
} __attribute__ ((__packed__)) hci_read_local_extended_features_rp;

#define HCI_OCF_READ_BUFFER_SIZE			0x0005
#define HCI_CMD_READ_BUFFER_SIZE			0x1005
/* No command parameter(s) */
typedef struct {
	uint8_t		status;       /* 0x00 - success */
	uint16_t	max_acl_size; /* Max. size of ACL packet (bytes) */
	uint8_t		max_sco_size; /* Max. size of SCO packet (bytes) */
	uint16_t	num_acl_pkts;  /* Max. number of ACL packets */
	uint16_t	num_sco_pkts;  /* Max. number of SCO packets */
} __attribute__ ((__packed__)) hci_read_buffer_size_rp;

/* Read Country Code is deprecated */
#define HCI_OCF_READ_COUNTRY_CODE			0x0007
#define HCI_CMD_READ_COUNTRY_CODE			0x1007
/* No command parameter(s) */
typedef struct {
	uint8_t		status;       /* 0x00 - success */
	uint8_t		country_code; /* 0x00 - NAM, EUR, JP; 0x01 - France */
} __attribute__ ((__packed__)) hci_read_country_code_rp;

#define HCI_OCF_READ_BDADDR				0x0009
#define HCI_CMD_READ_BDADDR				0x1009
/* No command parameter(s) */
typedef struct {
	uint8_t		status; /* 0x00 - success */
	bdaddr_t	bdaddr; /* unit address */
} __attribute__ ((__packed__)) hci_read_bdaddr_rp;

/**************************************************************************
 **************************************************************************
 ** OGF 0x05	Status commands and return parameters
 **************************************************************************
 **************************************************************************/

#define HCI_OGF_STATUS				0x05

#define HCI_OCF_READ_FAILED_CONTACT_CNTR		0x0001
#define HCI_CMD_READ_FAILED_CONTACT_CNTR		0x1401
typedef struct {
	uint16_t	con_handle; /* connection handle */
} __attribute__ ((__packed__)) hci_read_failed_contact_cntr_cp;

typedef struct {
	uint8_t		status;     /* 0x00 - success */
	uint16_t	con_handle; /* connection handle */
	uint16_t	counter;    /* number of consecutive failed contacts */
} __attribute__ ((__packed__)) hci_read_failed_contact_cntr_rp;

#define HCI_OCF_RESET_FAILED_CONTACT_CNTR		0x0002
#define HCI_CMD_RESET_FAILED_CONTACT_CNTR		0x1402
typedef struct {
	uint16_t	con_handle; /* connection handle */
} __attribute__ ((__packed__)) hci_reset_failed_contact_cntr_cp;

typedef struct {
	uint8_t		status;     /* 0x00 - success */
	uint16_t	con_handle; /* connection handle */
} __attribute__ ((__packed__)) hci_reset_failed_contact_cntr_rp;

#define HCI_OCF_READ_LINK_QUALITY			0x0003
#define HCI_CMD_READ_LINK_QUALITY			0x1403
typedef struct {
	uint16_t	con_handle; /* connection handle */
} __attribute__ ((__packed__)) hci_read_link_quality_cp;

typedef struct {
	uint8_t		status;     /* 0x00 - success */
	uint16_t	con_handle; /* connection handle */
	uint8_t		quality;    /* higher value means better quality */
} __attribute__ ((__packed__)) hci_read_link_quality_rp;

#define HCI_OCF_READ_RSSI				0x0005
#define HCI_CMD_READ_RSSI				0x1405
typedef struct {
	uint16_t	con_handle; /* connection handle */
} __attribute__ ((__packed__)) hci_read_rssi_cp;

typedef struct {
	uint8_t		status;     /* 0x00 - success */
	uint16_t	con_handle; /* connection handle */
	char		rssi;       /* -127 <= rssi <= 127 dB */
} __attribute__ ((__packed__)) hci_read_rssi_rp;

#define HCI_OCF_READ_AFH_CHANNEL_MAP			0x0006
#define HCI_CMD_READ_AFH_CHANNEL_MAP			0x1406
typedef struct {
	uint16_t	con_handle; /* connection handle */
} __attribute__ ((__packed__)) hci_read_afh_channel_map_cp;

typedef struct {
	uint8_t		status;     /* 0x00 - success */
	uint16_t	con_handle; /* connection handle */
	uint8_t		mode;       /* AFH mode */
	uint8_t		map[10];    /* AFH Channel Map */
} __attribute__ ((__packed__)) hci_read_afh_channel_map_rp;

#define HCI_OCF_READ_CLOCK				0x0007
#define HCI_CMD_READ_CLOCK				0x1407
typedef struct {
	uint16_t	con_handle;	/* connection handle */
	uint8_t		clock;		/* which clock */
} __attribute__ ((__packed__)) hci_read_clock_cp;

typedef struct {
	uint8_t		status;		/* 0x00 - success */
	uint16_t	con_handle;	/* connection handle */
	uint32_t	clock;		/* clock value */
	uint16_t	accuracy;	/* clock accuracy */
} __attribute__ ((__packed__)) hci_read_clock_rp;


/**************************************************************************
 **************************************************************************
 ** OGF 0x06	Testing commands and return parameters
 **************************************************************************
 **************************************************************************/

#define HCI_OGF_TESTING				0x06

#define HCI_OCF_READ_LOOPBACK_MODE			0x0001
#define HCI_CMD_READ_LOOPBACK_MODE			0x1801
/* No command parameter(s) */
typedef struct {
	uint8_t		status; /* 0x00 - success */
	uint8_t		lbmode; /* loopback mode */
} __attribute__ ((__packed__)) hci_read_loopback_mode_rp;

#define HCI_OCF_WRITE_LOOPBACK_MODE			0x0002
#define HCI_CMD_WRITE_LOOPBACK_MODE			0x1802
typedef struct {
	uint8_t		lbmode; /* loopback mode */
} __attribute__ ((__packed__)) hci_write_loopback_mode_cp;

typedef hci_status_rp	hci_write_loopback_mode_rp;

#define HCI_OCF_ENABLE_UNIT_UNDER_TEST			0x0003
#define HCI_CMD_ENABLE_UNIT_UNDER_TEST			0x1803
/* No command parameter(s) */
typedef hci_status_rp	hci_enable_unit_under_test_rp;

/**************************************************************************
 **************************************************************************
 ** OGF 0x3e	Bluetooth Logo Testing
 ** OGF 0x3f	Vendor Specific
 **************************************************************************
 **************************************************************************/

#define HCI_OGF_BT_LOGO				0x3e
#define HCI_OGF_VENDOR				0x3f

/* Ericsson specific FC */
#define HCI_CMD_ERICSSON_WRITE_PCM_SETTINGS		0xFC07
#define HCI_CMD_ERICSSON_SET_UART_BAUD_RATE		0xFC09
#define HCI_CMD_ERICSSON_SET_SCO_DATA_PATH		0xFC1D

/* Cambridge Silicon Radio specific FC */
#define HCI_CMD_CSR_EXTN				0xFC00


/**************************************************************************
 **************************************************************************
 **                         Events and event parameters
 **************************************************************************
 **************************************************************************/

#define HCI_EVENT_INQUIRY_COMPL			0x01
typedef struct {
	uint8_t		status; /* 0x00 - success */
} __attribute__ ((__packed__)) hci_inquiry_compl_ep;

#define HCI_EVENT_INQUIRY_RESULT		0x02
typedef struct {
	uint8_t		num_responses;      /* number of responses */
/*	hci_inquiry_response[num_responses]   -- see below */
} __attribute__ ((__packed__)) hci_inquiry_result_ep;

typedef struct {
	bdaddr_t	bdaddr;			  /* unit address */
	uint8_t		page_scan_rep_mode;       /* page scan rep. mode */
	uint8_t		page_scan_period_mode;    /* page scan period mode */
	uint8_t		page_scan_mode;		  /* page scan mode */
	uint8_t		uclass[HCI_CLASS_SIZE];   /* unit class */
	uint16_t	clock_offset;		  /* clock offset */
} __attribute__ ((__packed__)) hci_inquiry_response;

#define HCI_EVENT_CON_COMPL			0x03
typedef struct {
	uint8_t		status;		 /* 0x00 - success */
	uint16_t	con_handle;      /* Connection handle */
	bdaddr_t	bdaddr;		 /* remote unit address */
	uint8_t		link_type;       /* Link type */
	uint8_t		encryption_mode; /* Encryption mode */
} __attribute__ ((__packed__)) hci_con_compl_ep;

#define HCI_EVENT_CON_REQ			0x04
typedef struct {
	bdaddr_t	bdaddr;		/* remote unit address */
	uint8_t		uclass[HCI_CLASS_SIZE]; /* remote unit class */
	uint8_t		link_type;	/* link type */
} __attribute__ ((__packed__)) hci_con_req_ep;

#define HCI_EVENT_DISCON_COMPL			0x05
typedef struct {
	uint8_t		status;     /* 0x00 - success */
	uint16_t	con_handle; /* connection handle */
	uint8_t		reason;     /* reason to disconnect */
} __attribute__ ((__packed__)) hci_discon_compl_ep;

#define HCI_EVENT_AUTH_COMPL			0x06
typedef struct {
	uint8_t		status;     /* 0x00 - success */
	uint16_t	con_handle; /* connection handle */
} __attribute__ ((__packed__)) hci_auth_compl_ep;

#define HCI_EVENT_REMOTE_NAME_REQ_COMPL		0x07
typedef struct {
	uint8_t		status;			  /* 0x00 - success */
	bdaddr_t	bdaddr;			  /* remote unit address */
	char		name[HCI_UNIT_NAME_SIZE]; /* remote unit name */
} __attribute__ ((__packed__)) hci_remote_name_req_compl_ep;

#define HCI_EVENT_ENCRYPTION_CHANGE		0x08
typedef struct {
	uint8_t		status;			  /* 0x00 - success */
	uint16_t	con_handle;		  /* Connection handle */
	uint8_t		encryption_enable;	  /* 0x00 - disable */
} __attribute__ ((__packed__)) hci_encryption_change_ep;

#define HCI_EVENT_CHANGE_CON_LINK_KEY_COMPL	0x09
typedef struct {
	uint8_t		status;     /* 0x00 - success */
	uint16_t	con_handle; /* Connection handle */
} __attribute__ ((__packed__)) hci_change_con_link_key_compl_ep;

#define HCI_EVENT_MASTER_LINK_KEY_COMPL		0x0a
typedef struct {
	uint8_t		status;     /* 0x00 - success */
	uint16_t	con_handle; /* Connection handle */
	uint8_t		key_flag;   /* Key flag */
} __attribute__ ((__packed__)) hci_master_link_key_compl_ep;

#define HCI_EVENT_READ_REMOTE_FEATURES_COMPL	0x0b
typedef struct {
	uint8_t		status;			     /* 0x00 - success */
	uint16_t	con_handle;		     /* Connection handle */
	uint8_t		features[HCI_FEATURES_SIZE]; /* LMP features bitmsk*/
} __attribute__ ((__packed__)) hci_read_remote_features_compl_ep;

#define HCI_EVENT_READ_REMOTE_VER_INFO_COMPL	0x0c
typedef struct {
	uint8_t		status;		/* 0x00 - success */
	uint16_t	con_handle;     /* Connection handle */
	uint8_t		lmp_version;    /* LMP version */
	uint16_t	manufacturer;   /* Hardware manufacturer name */
	uint16_t	lmp_subversion; /* LMP sub-version */
} __attribute__ ((__packed__)) hci_read_remote_ver_info_compl_ep;

#define HCI_EVENT_QOS_SETUP_COMPL		0x0d
typedef struct {
	uint8_t		status;		 /* 0x00 - success */
	uint16_t	con_handle;      /* connection handle */
	uint8_t		flags;		 /* reserved for future use */
	uint8_t		service_type;    /* service type */
	uint32_t	token_rate;      /* bytes per second */
	uint32_t	peak_bandwidth;  /* bytes per second */
	uint32_t	latency;	 /* microseconds */
	uint32_t	delay_variation; /* microseconds */
} __attribute__ ((__packed__)) hci_qos_setup_compl_ep;

#define HCI_EVENT_COMMAND_COMPL			0x0e
typedef struct {
	uint8_t		num_cmd_pkts; /* # of HCI command packets */
	uint16_t	opcode;       /* command OpCode */
	/* command return parameters (if any) */
} __attribute__ ((__packed__)) hci_command_compl_ep;

#define HCI_EVENT_COMMAND_STATUS		0x0f
typedef struct {
	uint8_t		status;       /* 0x00 - pending */
	uint8_t		num_cmd_pkts; /* # of HCI command packets */
	uint16_t	opcode;       /* command OpCode */
} __attribute__ ((__packed__)) hci_command_status_ep;

#define HCI_EVENT_HARDWARE_ERROR		0x10
typedef struct {
	uint8_t		hardware_code; /* hardware error code */
} __attribute__ ((__packed__)) hci_hardware_error_ep;

#define HCI_EVENT_FLUSH_OCCUR			0x11
typedef struct {
	uint16_t	con_handle; /* connection handle */
} __attribute__ ((__packed__)) hci_flush_occur_ep;

#define HCI_EVENT_ROLE_CHANGE			0x12
typedef struct {
	uint8_t		status; /* 0x00 - success */
	bdaddr_t	bdaddr; /* address of remote unit */
	uint8_t		role;   /* new connection role */
} __attribute__ ((__packed__)) hci_role_change_ep;

#define HCI_EVENT_NUM_COMPL_PKTS		0x13
typedef struct {
	uint8_t		num_con_handles; /* # of connection handles */
/* these are repeated "num_con_handles" times
	uint16_t	con_handle; --- connection handle(s)
	uint16_t	compl_pkts; --- # of completed packets */
} __attribute__ ((__packed__)) hci_num_compl_pkts_ep;

#define HCI_EVENT_MODE_CHANGE			0x14
typedef struct {
	uint8_t		status;     /* 0x00 - success */
	uint16_t	con_handle; /* connection handle */
	uint8_t		unit_mode;  /* remote unit mode */
	uint16_t	interval;   /* interval * 0.625 msec */
} __attribute__ ((__packed__)) hci_mode_change_ep;

#define HCI_EVENT_RETURN_LINK_KEYS		0x15
typedef struct {
	uint8_t		num_keys; /* # of keys */
/* these are repeated "num_keys" times
	bdaddr_t	bdaddr;               --- remote address(es)
	uint8_t		key[HCI_KEY_SIZE]; --- key(s) */
} __attribute__ ((__packed__)) hci_return_link_keys_ep;

#define HCI_EVENT_PIN_CODE_REQ			0x16
typedef struct {
	bdaddr_t	bdaddr; /* remote unit address */
} __attribute__ ((__packed__)) hci_pin_code_req_ep;

#define HCI_EVENT_LINK_KEY_REQ			0x17
typedef struct {
	bdaddr_t	bdaddr; /* remote unit address */
} __attribute__ ((__packed__)) hci_link_key_req_ep;

#define HCI_EVENT_LINK_KEY_NOTIFICATION		0x18
typedef struct {
	bdaddr_t	bdaddr;		   /* remote unit address */
	uint8_t		key[HCI_KEY_SIZE]; /* link key */
	uint8_t		key_type;	   /* type of the key */
} __attribute__ ((__packed__)) hci_link_key_notification_ep;

#define HCI_EVENT_LOOPBACK_COMMAND		0x19
typedef hci_cmd_hdr_t	hci_loopback_command_ep;

#define HCI_EVENT_DATA_BUFFER_OVERFLOW		0x1a
typedef struct {
	uint8_t		link_type; /* Link type */
} __attribute__ ((__packed__)) hci_data_buffer_overflow_ep;

#define HCI_EVENT_MAX_SLOT_CHANGE		0x1b
typedef struct {
	uint16_t	con_handle;    /* connection handle */
	uint8_t		lmp_max_slots; /* Max. # of slots allowed */
} __attribute__ ((__packed__)) hci_max_slot_change_ep;

#define HCI_EVENT_READ_CLOCK_OFFSET_COMPL	0x1c
typedef struct {
	uint8_t		status;       /* 0x00 - success */
	uint16_t	con_handle;   /* Connection handle */
	uint16_t	clock_offset; /* Clock offset */
} __attribute__ ((__packed__)) hci_read_clock_offset_compl_ep;

#define HCI_EVENT_CON_PKT_TYPE_CHANGED		0x1d
typedef struct {
	uint8_t		status;     /* 0x00 - success */
	uint16_t	con_handle; /* connection handle */
	uint16_t	pkt_type;   /* packet type */
} __attribute__ ((__packed__)) hci_con_pkt_type_changed_ep;

#define HCI_EVENT_QOS_VIOLATION			0x1e
typedef struct {
	uint16_t	con_handle; /* connection handle */
} __attribute__ ((__packed__)) hci_qos_violation_ep;

/* Page Scan Mode Change Event is deprecated */
#define HCI_EVENT_PAGE_SCAN_MODE_CHANGE		0x1f
typedef struct {
	bdaddr_t	bdaddr;		/* destination address */
	uint8_t		page_scan_mode; /* page scan mode */
} __attribute__ ((__packed__)) hci_page_scan_mode_change_ep;

#define HCI_EVENT_PAGE_SCAN_REP_MODE_CHANGE	0x20
typedef struct {
	bdaddr_t	bdaddr;		    /* destination address */
	uint8_t		page_scan_rep_mode; /* page scan repetition mode */
} __attribute__ ((__packed__)) hci_page_scan_rep_mode_change_ep;

#define HCI_EVENT_FLOW_SPECIFICATION_COMPL	0x21
typedef struct {
	uint8_t		status;		/* 0x00 - success */
	uint16_t	con_handle;	/* connection handle */
	uint8_t		flags;		/* reserved */
	uint8_t		direction;	/* flow direction */
	uint8_t		type;		/* service type */
	uint32_t	token_rate;	/* token rate */
	uint32_t	bucket_size;	/* token bucket size */
	uint32_t	peak_bandwidth;	/* peak bandwidth */
	uint32_t	latency;	/* access latency */
} __attribute__ ((__packed__)) hci_flow_specification_compl_ep;

#define HCI_EVENT_RSSI_RESULT			0x22
typedef struct {
	uint8_t		num_responses;      /* number of responses */
/*	hci_rssi_response[num_responses]   -- see below */
} __attribute__ ((__packed__)) hci_rssi_result_ep;

typedef struct {
	bdaddr_t	bdaddr;			/* unit address */
	uint8_t		page_scan_rep_mode;	/* page scan rep. mode */
	uint8_t		blank;			/* reserved */
	uint8_t		uclass[HCI_CLASS_SIZE];	/* unit class */
	uint16_t	clock_offset;		/* clock offset */
	int8_t		rssi;			/* rssi */
} __attribute__ ((__packed__)) hci_rssi_response_ep;

#define HCI_EVENT_READ_REMOTE_EXTENDED_FEATURES	0x23
typedef struct {
	uint8_t		status;		/* 0x00 - success */
	uint16_t	con_handle;	/* connection handle */
	uint8_t		page;		/* page number */
	uint8_t		max;		/* max page number */
	uint8_t		features[HCI_FEATURES_SIZE]; /* LMP features bitmsk*/
} __attribute__ ((__packed__)) hci_read_remote_extended_features_ep;

#define HCI_EVENT_SCO_CON_COMPL			0x2c
typedef struct {
	uint8_t		status;		/* 0x00 - success */
	uint16_t	con_handle;	/* connection handle */
	bdaddr_t	bdaddr;		/* unit address */
	uint8_t		link_type;	/* link type */
	uint8_t		interval;	/* transmission interval */
	uint8_t		window;		/* retransmission window */
	uint16_t	rxlen;		/* rx packet length */
	uint16_t	txlen;		/* tx packet length */
	uint8_t		mode;		/* air mode */
} __attribute__ ((__packed__)) hci_sco_con_compl_ep;

#define HCI_EVENT_SCO_CON_CHANGED		0x2d
typedef struct {
	uint8_t		status;		/* 0x00 - success */
	uint16_t	con_handle;	/* connection handle */
	uint8_t		interval;	/* transmission interval */
	uint8_t		window;		/* retransmission window */
	uint16_t	rxlen;		/* rx packet length */
	uint16_t	txlen;		/* tx packet length */
} __attribute__ ((__packed__)) hci_sco_con_changed_ep;

#define HCI_EVENT_BT_LOGO			0xfe

#define HCI_EVENT_VENDOR			0xff

/**************************************************************************
 **************************************************************************
 **                 HCI Socket Definitions
 **************************************************************************
 **************************************************************************/

/* HCI socket options */
#define SO_HCI_EVT_FILTER		1	/* get/set event filter */
#define SO_HCI_PKT_FILTER		2	/* get/set packet filter */
#define SO_HCI_DIRECTION		3	/* packet direction indicator */

/* Control Messages */
#define SCM_HCI_DIRECTION		SO_HCI_DIRECTION

/*
 * HCI socket filter and get/set routines
 *
 * for ease of use, we filter 256 possible events/packets
 */
struct hci_filter {
	uint32_t	mask[8];	/* 256 bits */
};

static __inline void
hci_filter_set(uint8_t bit, struct hci_filter *filter)
{
	uint8_t off = bit - 1;

	off >>= 5;
	filter->mask[off] |= (1 << ((bit - 1) & 0x1f));
}

static __inline void
hci_filter_clr(uint8_t bit, struct hci_filter *filter)
{
	uint8_t off = bit - 1;

	off >>= 5;
	filter->mask[off] &= ~(1 << ((bit - 1) & 0x1f));
}

static __inline int
hci_filter_test(uint8_t bit, struct hci_filter *filter)
{
	uint8_t off = bit - 1;

	off >>= 5;
	return (filter->mask[off] & (1 << ((bit - 1) & 0x1f)));
}

/*
 * HCI socket ioctl's
 *
 * Apart from GBTINFOA, these are all indexed on the unit name
 */

#define SIOCGBTINFO	_IOWR('b',  5, struct btreq) /* get unit info */
#define SIOCGBTINFOA	_IOWR('b',  6, struct btreq) /* get info by address */
#define SIOCNBTINFO	_IOWR('b',  7, struct btreq) /* next unit info */

#define SIOCSBTFLAGS	_IOWR('b',  8, struct btreq) /* set unit flags */
#define SIOCSBTPOLICY	_IOWR('b',  9, struct btreq) /* set unit link policy */
#define SIOCSBTPTYPE	_IOWR('b', 10, struct btreq) /* set unit packet type */

#define SIOCGBTSTATS	_IOWR('b', 11, struct btreq) /* get unit statistics */
#define SIOCZBTSTATS	_IOWR('b', 12, struct btreq) /* zero unit statistics */

#define SIOCBTDUMP	 _IOW('b', 13, struct btreq) /* print debug info */
#define SIOCSBTSCOMTU	_IOWR('b', 17, struct btreq) /* set sco_mtu value */

struct bt_stats {
	uint32_t	err_tx;
	uint32_t	err_rx;
	uint32_t	cmd_tx;
	uint32_t	evt_rx;
	uint32_t	acl_tx;
	uint32_t	acl_rx;
	uint32_t	sco_tx;
	uint32_t	sco_rx;
	uint32_t	byte_tx;
	uint32_t	byte_rx;
};

struct btreq {
	char	btr_name[HCI_DEVNAME_SIZE];	/* device name */

	union {
	    struct {
		bdaddr_t btri_bdaddr;		/* device bdaddr */
		uint16_t btri_flags;		/* flags */
		uint16_t btri_num_cmd;		/* # of free cmd buffers */
		uint16_t btri_num_acl;		/* # of free ACL buffers */
		uint16_t btri_num_sco;		/* # of free SCO buffers */
		uint16_t btri_acl_mtu;		/* ACL mtu */
		uint16_t btri_sco_mtu;		/* SCO mtu */
		uint16_t btri_link_policy;	/* Link Policy */
		uint16_t btri_packet_type;	/* Packet Type */
	    } btri;
	    struct bt_stats btrs;   /* unit stats */
	} btru;
};

#define btr_flags	btru.btri.btri_flags
#define btr_bdaddr	btru.btri.btri_bdaddr
#define btr_num_cmd	btru.btri.btri_num_cmd
#define btr_num_acl	btru.btri.btri_num_acl
#define btr_num_sco	btru.btri.btri_num_sco
#define btr_acl_mtu	btru.btri.btri_acl_mtu
#define btr_sco_mtu	btru.btri.btri_sco_mtu
#define btr_link_policy btru.btri.btri_link_policy
#define btr_packet_type btru.btri.btri_packet_type
#define btr_uclass	btru.btri.btri_uclass
#define btr_stats	btru.btrs

/* hci_unit & btr_flags */
#define BTF_UP			(1<<0)	/* unit is up */
#define BTF_RUNNING		(1<<1)	/* unit is running */
#define BTF_XMIT_CMD		(1<<2)	/* unit is transmitting CMD packets */
#define BTF_XMIT_ACL		(1<<3)	/* unit is transmitting ACL packets */
#define BTF_XMIT_SCO		(1<<4)	/* unit is transmitting SCO packets */
#define BTF_XMIT		(BTF_XMIT_CMD | BTF_XMIT_ACL | BTF_XMIT_SCO)
#define BTF_INIT_BDADDR		(1<<5)	/* waiting for bdaddr */
#define BTF_INIT_BUFFER_SIZE	(1<<6)	/* waiting for buffer size */
#define BTF_INIT_FEATURES	(1<<7)	/* waiting for features */
#define BTF_INIT		(BTF_INIT_BDADDR | BTF_INIT_BUFFER_SIZE | BTF_INIT_FEATURES)

/**************************************************************************
 **************************************************************************
 **                 HCI Kernel Definitions
 **************************************************************************
 **************************************************************************/

#ifdef _KERNEL

#include <net/if.h>		/* for struct ifqueue */

struct l2cap_channel;
struct mbuf;
struct sco_pcb;
struct socket;

/* global HCI kernel variables */

/* sysctl variables */
extern int hci_memo_expiry;
extern int hci_acl_expiry;
extern int hci_sendspace, hci_recvspace;
extern int hci_eventq_max, hci_aclrxq_max, hci_scorxq_max;

/*
 * HCI Connection Information
 */
struct hci_link {
	struct hci_unit		*hl_unit;	/* our unit */
	TAILQ_ENTRY(hci_link)	 hl_next;	/* next link on unit */

	/* common info */
	uint16_t		 hl_state;	/* connection state */
	uint16_t		 hl_flags;	/* link flags */
	bdaddr_t		 hl_bdaddr;	/* dest address */
	uint16_t		 hl_handle;	/* connection handle */
	uint8_t			 hl_type;	/* link type */

	/* ACL link info */
	uint8_t			 hl_lastid;	/* last id used */
	uint16_t		 hl_refcnt;	/* reference count */
	uint16_t		 hl_mtu;	/* signalling mtu for link */
	uint16_t		 hl_flush;	/* flush timeout */

	TAILQ_HEAD(,l2cap_pdu)	 hl_txq;	/* queue of outgoing PDUs */
	int			 hl_txqlen;	/* number of fragments */
	struct mbuf		*hl_rxp;	/* incoming PDU (accumulating)*/
	struct timeout		 hl_expire;	/* connection expiry timer */
	TAILQ_HEAD(,l2cap_req)	 hl_reqs;	/* pending requests */

	/* SCO link info */
	struct hci_link		*hl_link;	/* SCO ACL link */
	struct sco_pcb		*hl_sco;	/* SCO pcb */
	struct ifqueue		 hl_data;	/* SCO outgoing data */
};

/* hci_link state */
#define HCI_LINK_CLOSED		0  /* closed */
#define HCI_LINK_WAIT_CONNECT	1  /* waiting to connect */
#define HCI_LINK_WAIT_AUTH	2  /* waiting for auth */
#define HCI_LINK_WAIT_ENCRYPT	3  /* waiting for encrypt */
#define HCI_LINK_WAIT_SECURE	4  /* waiting for secure */
#define HCI_LINK_OPEN		5  /* ready and willing */
#define HCI_LINK_BLOCK		6  /* open but blocking (see hci_acl_start) */

/* hci_link flags */
#define HCI_LINK_AUTH_REQ	(1<<0)  /* authentication requested */
#define HCI_LINK_ENCRYPT_REQ	(1<<1)  /* encryption requested */
#define HCI_LINK_SECURE_REQ	(1<<2)	/* secure link requested */
#define HCI_LINK_AUTH		(1<<3)	/* link is authenticated */
#define HCI_LINK_ENCRYPT	(1<<4)	/* link is encrypted */
#define HCI_LINK_SECURE		(1<<5)	/* link is secured */

/*
 * Bluetooth Memo
 *	cached device information for remote devices that this unit has seen
 */
struct hci_memo {
	struct timeval		time;		/* time of last response */
	hci_inquiry_response	response;	/* inquiry response */
	LIST_ENTRY(hci_memo)	next;
};

/*
 * The Bluetooth HCI device unit structure
 */
struct hci_unit {
	struct device	*hci_softc;		/* ptr to device softc */
	struct device	*hci_bthub;		/* bthub(4) handle */

	/* device info */
	char		*hci_devname;		/* device name */
	bdaddr_t	 hci_bdaddr;		/* device address */
	uint16_t	 hci_flags;		/* see BTF_ above */

	uint16_t	 hci_packet_type;	/* packet types */
	uint16_t	 hci_acl_mask;		/* ACL packet capabilities */
	uint16_t	 hci_sco_mask;		/* SCO packet capabilities */

	uint16_t	 hci_link_policy;	/* link policy */
	uint16_t	 hci_lmp_mask;		/* link policy capabilities */

	/* flow control */
	uint16_t	 hci_max_acl_size;	/* ACL payload mtu */
	uint16_t	 hci_num_acl_pkts;	/* free ACL packet buffers */
	uint8_t		 hci_num_cmd_pkts;	/* free CMD packet buffers */
	uint8_t		 hci_max_sco_size;	/* SCO payload mtu */
	uint16_t	 hci_num_sco_pkts;	/* free SCO packet buffers */

	TAILQ_HEAD(,hci_link)	hci_links;	/* list of ACL/SCO links */
	LIST_HEAD(,hci_memo)	hci_memos;	/* cached memo list */

	/*
	 * h/w driver callbacks
	 *
	 * the device driver must supply these.
	 */
	int	(*hci_enable)		/* enable device */
		(struct hci_unit *);
	void	(*hci_disable)		/* disable device */
		(struct hci_unit *);
	void	(*hci_start_cmd)	/* initiate cmd output routine */
		(struct hci_unit *);
	void	(*hci_start_acl)	/* initiate acl output routine */
		(struct hci_unit *);
	void	(*hci_start_sco)	/* initiate sco output routine */
		(struct hci_unit *);
	int hci_ipl;		/* to block queue operations */

	/* input queues */
	struct ifqueue		 hci_eventq;	/* Event queue */
	struct ifqueue		 hci_aclrxq;	/* ACL rx queue */
	struct ifqueue		 hci_scorxq;	/* SCO rx queue */
	uint16_t		 hci_eventqlen;	/* Event queue length */
	uint16_t		 hci_aclrxqlen;	/* ACL rx queue length */
	uint16_t		 hci_scorxqlen;	/* SCO rx queue length */

	/* output queues */
	struct ifqueue		 hci_cmdwait;	/* pending commands */
	struct ifqueue		 hci_cmdq;	/* Command queue */
	struct ifqueue		 hci_acltxq;	/* ACL tx queue */
	struct ifqueue		 hci_scotxq;	/* SCO tx queue */
	struct ifqueue		 hci_scodone;	/* SCO done queue */

	struct bt_stats		 hci_stats;	/* unit statistics */

	TAILQ_ENTRY(hci_unit) hci_next;
};

extern TAILQ_HEAD(hci_unit_list, hci_unit) hci_unit_list;

/*
 * HCI layer function prototypes
 */

/* hci_event.c */
void hci_event(struct mbuf *, struct hci_unit *);

/* hci_ioctl.c */
int hci_ioctl(unsigned long, void *, struct proc *);

/* hci_link.c */
struct hci_link *hci_acl_open(struct hci_unit *, bdaddr_t *);
struct hci_link *hci_acl_newconn(struct hci_unit *, bdaddr_t *);
void hci_acl_close(struct hci_link *, int);
void hci_acl_timeout(void *);
int hci_acl_setmode(struct hci_link *);
void hci_acl_linkmode(struct hci_link *);
void hci_acl_recv(struct mbuf *, struct hci_unit *);
int hci_acl_send(struct mbuf *, struct hci_link *, struct l2cap_channel *);
void hci_acl_start(struct hci_link *);
void hci_acl_complete(struct hci_link *, int);
struct hci_link *hci_sco_newconn(struct hci_unit *, bdaddr_t *);
void hci_sco_recv(struct mbuf *, struct hci_unit *);
void hci_sco_start(struct hci_link *);
void hci_sco_complete(struct hci_link *, int);
struct hci_link *hci_link_alloc(struct hci_unit *);
void hci_link_free(struct hci_link *, int);
struct hci_link *hci_link_lookup_state(struct hci_unit *, uint16_t, uint16_t);
struct hci_link *hci_link_lookup_bdaddr(struct hci_unit *, bdaddr_t *, uint16_t);
struct hci_link *hci_link_lookup_handle(struct hci_unit *, uint16_t);

/* hci_misc.c */
int hci_route_lookup(bdaddr_t *, bdaddr_t *);
struct hci_memo *hci_memo_find(struct hci_unit *, bdaddr_t *);
void hci_memo_free(struct hci_memo *);

/* hci_socket.c */
void hci_drop(void *);
int hci_usrreq(struct socket *, int, struct mbuf *, struct mbuf *, struct mbuf *);
int hci_ctloutput(int, struct socket *, int, int, struct mbuf **);
void hci_mtap(struct mbuf *, struct hci_unit *);

/* hci_unit.c */
void hci_attach(struct hci_unit *);
void hci_detach(struct hci_unit *);
int hci_enable(struct hci_unit *);
void hci_disable(struct hci_unit *);
struct hci_unit *hci_unit_lookup(bdaddr_t *);
int hci_send_cmd(struct hci_unit *, uint16_t, void *, uint8_t);
void hci_input_event(struct hci_unit *, struct mbuf *);
void hci_input_acl(struct hci_unit *, struct mbuf *);
void hci_input_sco(struct hci_unit *, struct mbuf *);
void hci_complete_sco(struct hci_unit *, struct mbuf *);
void hci_output_cmd(struct hci_unit *, struct mbuf *);
void hci_output_acl(struct hci_unit *, struct mbuf *);
void hci_output_sco(struct hci_unit *, struct mbuf *);
void hci_intr(void *);

/* XXX mimic NetBSD for now, although we don't have these interfaces */
#define M_GETCTX(m, t)	((t)(m)->m_pkthdr.rcvif)
#define M_SETCTX(m, c)	((m)->m_pkthdr.rcvif = (void *)(c))
#define splraiseipl(ipl) splbio() /* XXX */
#define ENOLINK ENOENT		/* XXX */
#define EPASSTHROUGH ENOTTY	/* XXX */

#endif	/* _KERNEL */

#endif /* _NETBT_HCI_H_ */