1/*
2 * Copyright 2007 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com
3 * All rights reserved. Distributed under the terms of the MIT License.
4 */
5#ifndef _BTHCI_H_
6#define _BTHCI_H_
7
8/* typedefs */
9typedef int32 hci_id;
10#define HCI_DEVICE_INDEX_OFFSET 0x7c
11
12typedef enum { H2 = 2, H3, H4, H5 } transport_type;
13
14typedef enum { 	BT_COMMAND = 0,
15				BT_EVENT,
16				BT_ACL,
17				BT_SCO,
18				BT_ESCO,
19				// more packets here
20				HCI_NUM_PACKET_TYPES
21} bt_packet_t;
22
23const char* BluetoothCommandOpcode(uint16 opcode);
24const char* BluetoothEvent(uint8 event);
25const char* BluetoothManufacturer(uint16 manufacturer);
26const char* BluetoothHciVersion(uint16 ver);
27const char* BluetoothLmpVersion(uint16 ver);
28const char* BluetoothError(uint8 error);
29
30/* packets sizes */
31#define HCI_MAX_ACL_SIZE		1024
32#define HCI_MAX_SCO_SIZE		255
33#define HCI_MAX_EVENT_SIZE		260
34#define HCI_MAX_FRAME_SIZE		(HCI_MAX_ACL_SIZE + 4)
35
36/* fields sizes */
37#define HCI_LAP_SIZE			3	/* LAP */
38#define HCI_LINK_KEY_SIZE		16	/* link key */
39#define HCI_PIN_SIZE			16	/* PIN */
40#define HCI_EVENT_MASK_SIZE		8	/* event mask */
41#define HCI_CLASS_SIZE			3	/* class */
42#define HCI_FEATURES_SIZE		8	/* LMP features */
43#define HCI_DEVICE_NAME_SIZE	248	/* unit name size */
44
45// HCI Packet types
46#define HCI_2DH1        0x0002
47#define HCI_3DH1        0x0004
48#define HCI_DM1         0x0008
49#define HCI_DH1         0x0010
50#define HCI_2DH3        0x0100
51#define HCI_3DH3        0x0200
52#define HCI_DM3         0x0400
53#define HCI_DH3         0x0800
54#define HCI_2DH5        0x1000
55#define HCI_3DH5        0x2000
56#define HCI_DM5         0x4000
57#define HCI_DH5         0x8000
58
59#define HCI_HV1         0x0020
60#define HCI_HV2         0x0040
61#define HCI_HV3         0x0080
62
63#define HCI_EV3         0x0008
64#define HCI_EV4         0x0010
65#define HCI_EV5         0x0020
66#define HCI_2EV3        0x0040
67#define HCI_3EV3        0x0080
68#define HCI_2EV5        0x0100
69#define HCI_3EV5        0x0200
70
71#define SCO_PTYPE_MASK  (HCI_HV1 | HCI_HV2 | HCI_HV3)
72#define ACL_PTYPE_MASK  (HCI_DM1 | HCI_DH1 | HCI_DM3 | HCI_DH3 | HCI_DM5 | HCI_DH5)
73
74
75// LMP features
76#define LMP_3SLOT       0x01
77#define LMP_5SLOT       0x02
78#define LMP_ENCRYPT     0x04
79#define LMP_SOFFSET     0x08
80#define LMP_TACCURACY   0x10
81#define LMP_RSWITCH     0x20
82#define LMP_HOLD        0x40
83#define LMP_SNIFF       0x80
84
85#define LMP_PARK        0x01
86#define LMP_RSSI        0x02
87#define LMP_QUALITY     0x04
88#define LMP_SCO         0x08
89#define LMP_HV2         0x10
90#define LMP_HV3         0x20
91#define LMP_ULAW        0x40
92#define LMP_ALAW        0x80
93
94#define LMP_CVSD        0x01
95#define LMP_PSCHEME     0x02
96#define LMP_PCONTROL    0x04
97#define LMP_TRSP_SCO    0x08
98#define LMP_BCAST_ENC   0x80
99
100#define LMP_EDR_ACL_2M  0x02
101#define LMP_EDR_ACL_3M  0x04
102#define LMP_ENH_ISCAN   0x08
103#define LMP_ILACE_ISCAN 0x10
104#define LMP_ILACE_PSCAN 0x20
105#define LMP_RSSI_INQ    0x40
106#define LMP_ESCO        0x80
107
108#define LMP_EV4         0x01
109#define LMP_EV5         0x02
110#define LMP_AFH_CAP_SLV 0x08
111#define LMP_AFH_CLS_SLV 0x10
112#define LMP_EDR_3SLOT   0x80
113
114#define LMP_EDR_5SLOT   0x01
115#define LMP_SNIFF_SUBR  0x02
116#define LMP_PAUSE_ENC   0x04
117#define LMP_AFH_CAP_MST 0x08
118#define LMP_AFH_CLS_MST 0x10
119#define LMP_EDR_ESCO_2M 0x20
120#define LMP_EDR_ESCO_3M 0x40
121#define LMP_EDR_3S_ESCO 0x80
122
123#define LMP_EXT_INQ     0x01
124#define LMP_SIMPLE_PAIR 0x08
125#define LMP_ENCAPS_PDU  0x10
126#define LMP_ERR_DAT_REP 0x20
127#define LMP_NFLUSH_PKTS 0x40
128
129#define LMP_LSTO        0x01
130#define LMP_INQ_TX_PWR  0x02
131#define LMP_EXT_FEAT    0x80
132
133// Link policies
134#define HCI_LP_RSWITCH  0x0001
135#define HCI_LP_HOLD     0x0002
136#define HCI_LP_SNIFF    0x0004
137#define HCI_LP_PARK     0x0008
138
139// Link mode
140#define HCI_LM_ACCEPT   0x8000
141#define HCI_LM_MASTER   0x0001
142#define HCI_LM_AUTH     0x0002
143#define HCI_LM_ENCRYPT  0x0004
144#define HCI_LM_TRUSTED  0x0008
145#define HCI_LM_RELIABLE 0x0010
146#define HCI_LM_SECURE   0x0020
147
148
149#endif // _BTHCI_H_
150
151