xref: /haiku/headers/os/bluetooth/HCI/btHCI_command.h (revision adb0d19d561947362090081e81d90dde59142026)
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_COMMAND_H_
6 #define _BTHCI_COMMAND_H_
7 
8 #include <bluetooth/bluetooth.h>
9 #include <bluetooth/HCI/btHCI.h>
10 
11 #define HCI_COMMAND_HDR_SIZE 3
12 
13 const char* GetCommand(uint16 command);
14 const char* GetEvent(uint8 event);
15 const char* GetManufacturer(uint16 manufacturer);
16 const char* GetHciVersion(uint16 ver);
17 const char* GetLmpVersion(uint16 ver);
18 
19 struct hci_command_header {
20 	uint16	opcode;		/* OCF & OGF */
21 	uint8	clen;
22 } __attribute__ ((packed));
23 
24 
25 /* Command opcode pack/unpack */
26 #define PACK_OPCODE(ogf, ocf)	(uint16)((ocf & 0x03ff)|(ogf << 10))
27 #define GET_OPCODE_OGF(op)		(op >> 10)
28 #define GET_OPCODE_OCF(op)		(op & 0x03ff)
29 
30 
31 /* - Informational Parameters Command definition - */
32 #define OGF_INFORMATIONAL_PARAM	0x04
33 
34 	#define OCF_READ_LOCAL_VERSION		0x0001
35 	struct hci_rp_read_loc_version {
36 		uint8		status;
37 		uint8		hci_version;
38 		uint16		hci_revision;
39 		uint8		lmp_version;
40 		uint16		manufacturer;
41 		uint16		lmp_subversion;
42 	} __attribute__ ((packed));
43 
44 	#define OCF_READ_LOCAL_FEATURES		0x0003
45 	struct hci_rp_read_loc_features {
46 		uint8		status;
47 		uint8		features[8];
48 	} __attribute__ ((packed));
49 
50 	#define OCF_READ_BUFFER_SIZE		0x0005
51 	struct hci_rp_read_buffer_size {
52 		uint8		status;
53 		uint16		acl_mtu;
54 		uint8		sco_mtu;
55 		uint16		acl_max_pkt;
56 		uint16		sco_max_pkt;
57 	} __attribute__ ((packed));
58 
59 	#define OCF_READ_BD_ADDR			0x0009
60 	struct hci_rp_read_bd_addr {
61 		uint8		status;
62 		bdaddr_t	bdaddr;
63 	} __attribute__ ((packed));
64 
65 /* - Host Controller and Baseband Command definition - */
66 #define OGF_CONTROL_BASEBAND			0x03
67 
68 	#define OCF_RESET					0x0003
69   /*struct hci_reset {
70 		void no_fields;
71 	} __attribute__ ((packed));*/
72 
73 	#define OCF_SET_EVENT_FLT			0x0005
74 	struct hci_cp_set_event_flt {
75 		uint8		flt_type;
76 		uint8		cond_type;
77 		uint8		condition[0];
78 	} __attribute__ ((packed));
79 
80 	#define OCF_READ_STORED_LINK_KEY	0x000D
81 	struct hci_read_stored_link_key {
82 		bdaddr_t	bdaddr;
83 		uint8		all_keys_flag;
84 	} __attribute__ ((packed));
85 	struct hci_read_stored_link_key_reply {
86 		uint8		status;
87 		uint16		max_num_keys;
88 		uint16		num_keys_read;
89 	} __attribute__ ((packed));
90 
91 	#define OCF_WRITE_STORED_LINK_KEY	0x0011
92 	struct hci_write_stored_link_key {
93 		uint8		num_keys_to_write;
94 		// these are repeated "num_keys_write" times
95 		bdaddr_t	bdaddr;
96 		uint8		key[HCI_LINK_KEY_SIZE];
97 	} __attribute__ ((packed));
98 	struct hci_write_stored_link_key_reply {
99 		uint8		status;
100 		uint8		num_keys_written;
101 	} __attribute__ ((packed));
102 
103 
104 	#define OCF_WRITE_LOCAL_NAME		0x0013
105 	#define OCF_READ_LOCAL_NAME			0x0014
106 	struct hci_rp_read_local_name {
107 		uint8		status;
108 		char		local_name[HCI_DEVICE_NAME_SIZE];
109 	} __attribute__ ((packed));
110 
111 	#define OCF_WRITE_CA_TIMEOUT		0x0016
112 	#define OCF_WRITE_PG_TIMEOUT		0x0018
113 
114 	#define OCF_WRITE_SCAN_ENABLE		0x001A
115 		#define HCI_SCAN_DISABLED		0x00
116 		#define HCI_SCAN_INQUIRY		0x01
117 		#define HCI_SCAN_PAGE			0x02
118 		#define HCI_SCAN_INQUIRY_PAGE	0x03
119 	struct hci_write_scan_enable {
120 		uint8		scan;
121 	} __attribute__ ((packed));
122 
123 	#define OCF_READ_AUTH_ENABLE		0x001F
124 	#define OCF_WRITE_AUTH_ENABLE		0x0020
125 		#define HCI_AUTH_DISABLED		0x00
126 		#define HCI_AUTH_ENABLED		0x01
127 	struct hci_write_authentication_enable {
128 		uint8		authentication;
129 	} __attribute__ ((packed));
130 
131 	#define OCF_READ_ENCRYPT_MODE		0x0021
132 	#define OCF_WRITE_ENCRYPT_MODE		0x0022
133 		#define HCI_ENCRYPT_DISABLED	0x00
134 		#define HCI_ENCRYPT_P2P			0x01
135 		#define HCI_ENCRYPT_BOTH		0x02
136 	struct hci_write_encryption_mode_enable {
137 		uint8		encryption;
138 	} __attribute__ ((packed));
139 
140 	/* Filter types */
141 	#define HCI_FLT_CLEAR_ALL			0x00
142 	#define HCI_FLT_INQ_RESULT			0x01
143 	#define HCI_FLT_CONN_SETUP			0x02
144 
145 	/* CONN_SETUP Condition types */
146 	#define HCI_CONN_SETUP_ALLOW_ALL	0x00
147 	#define HCI_CONN_SETUP_ALLOW_CLASS	0x01
148 	#define HCI_CONN_SETUP_ALLOW_BDADDR	0x02
149 
150 	/* CONN_SETUP Conditions */
151 	#define HCI_CONN_SETUP_AUTO_OFF		0x01
152 	#define HCI_CONN_SETUP_AUTO_ON		0x02
153 
154 	#define OCF_READ_CLASS_OF_DEV		0x0023
155 
156 	struct hci_read_dev_class_reply {
157 		uint8		status;
158 		uint8		dev_class[3];
159 	} __attribute__ ((packed));
160 
161 	#define OCF_WRITE_CLASS_OF_DEV		0x0024
162 	struct hci_write_dev_class {
163 		uint8		dev_class[3];
164 	} __attribute__ ((packed));
165 
166 	#define OCF_READ_VOICE_SETTING		0x0025
167 	struct hci_rp_read_voice_setting {
168 		uint8		status;
169 		uint16		voice_setting;
170 	} __attribute__ ((packed));
171 
172 	#define OCF_WRITE_VOICE_SETTING		0x0026
173 	struct hci_cp_write_voice_setting {
174 		uint16		voice_setting;
175 	} __attribute__ ((packed));
176 
177 	#define OCF_HOST_BUFFER_SIZE		0x0033
178 	struct hci_cp_host_buffer_size {
179 		uint16		acl_mtu;
180 		uint8		sco_mtu;
181 		uint16		acl_max_pkt;
182 		uint16		sco_max_pkt;
183 	} __attribute__ ((packed));
184 
185 	/* Link Control Command definition */
186 	#define OGF_LINK_CONTROL			0x01
187 
188 	#define OCF_INQUIRY					0x0001
189 	struct hci_cp_inquiry {
190 		uint8		lap[3];
191 		uint8		length;
192 		uint8		num_rsp;
193 	} __attribute__ ((packed));
194 
195 	#define OCF_INQUIRY_CANCEL			0x0002
196 
197 	#define OCF_CREATE_CONN				0x0005
198 	struct hci_cp_create_conn {
199 		bdaddr_t bdaddr;
200 		uint16		pkt_type;
201 		uint8		pscan_rep_mode;
202 		uint8		pscan_mode;
203 		uint16		clock_offset;
204 		uint8		role_switch;
205 	} __attribute__ ((packed));
206 
207 	#define OCF_DISCONNECT				0x0006
208 	struct hci_disconnect {
209 		uint16		handle;
210 		uint8		reason;
211 	} __attribute__ ((packed));
212 
213 	#define OCF_ADD_SCO					0x0007
214 	struct hci_cp_add_sco {
215 		uint16		handle;
216 		uint16		pkt_type;
217 	} __attribute__ ((packed));
218 
219 	#define OCF_ACCEPT_CONN_REQ			0x0009
220 	struct hci_cp_accept_conn_req {
221 		bdaddr_t	bdaddr;
222 		uint8		role;
223 	} __attribute__ ((packed));
224 
225 	#define OCF_REJECT_CONN_REQ			0x000a
226 	struct hci_cp_reject_conn_req {
227 		bdaddr_t	bdaddr;
228 		uint8		reason;
229 	} __attribute__ ((packed));
230 
231 	#define OCF_LINK_KEY_REPLY			0x000B
232 	struct hci_cp_link_key_reply {
233 		bdaddr_t	bdaddr;
234 		uint8		link_key[16];
235 	} __attribute__ ((packed));
236 
237 	#define OCF_LINK_KEY_NEG_REPLY		0x000C
238 	struct hci_cp_link_key_neg_reply {
239 		bdaddr_t	bdaddr;
240 	} __attribute__ ((packed));
241 
242 	#define OCF_PIN_CODE_REPLY			0x000D
243 	struct hci_cp_pin_code_reply {
244 		bdaddr_t bdaddr;
245 		uint8		pin_len;
246 		uint8		pin_code[HCI_PIN_SIZE];
247 	} __attribute__ ((packed));
248 
249 	#define OCF_PIN_CODE_NEG_REPLY		0x000E
250 	struct hci_cp_pin_code_neg_reply {
251 		bdaddr_t	bdaddr;
252 	} __attribute__ ((packed));
253 
254 	#define OCF_CHANGE_CONN_PTYPE		0x000F
255 	struct hci_cp_change_conn_ptype {
256 		uint16		handle;
257 		uint16		pkt_type;
258 	} __attribute__ ((packed));
259 
260 	#define OCF_AUTH_REQUESTED			0x0011
261 	struct hci_cp_auth_requested {
262 		uint16		handle;
263 	} __attribute__ ((packed));
264 
265 	#define OCF_SET_CONN_ENCRYPT		0x0013
266 	struct hci_cp_set_conn_encrypt {
267 		uint16		handle;
268 		uint8		encrypt;
269 	} __attribute__ ((packed));
270 
271 	#define OCF_CHANGE_CONN_LINK_KEY	0x0015
272 	struct hci_cp_change_conn_link_key {
273 		uint16		handle;
274 	} __attribute__ ((packed));
275 
276 	#define OCF_REMOTE_NAME_REQUEST		0x0019
277 	struct hci_remote_name_request {
278 		bdaddr_t bdaddr;
279 		uint8		pscan_rep_mode;
280 		uint8		reserved;
281 		uint16		clock_offset;
282 	} __attribute__ ((packed));
283 
284 	#define OCF_READ_REMOTE_FEATURES	0x001B
285 	struct hci_cp_read_rmt_features {
286 		uint16		handle;
287 	} __attribute__ ((packed));
288 
289 	#define OCF_READ_REMOTE_VERSION		0x001D
290 	struct hci_cp_read_rmt_version {
291 		uint16		handle;
292 	} __attribute__ ((packed));
293 
294 
295 /* Link Policy Command definition */
296 #define OGF_LINK_POLICY					0x02
297 
298 	#define OCF_ROLE_DISCOVERY			0x0009
299 	struct hci_cp_role_discovery {
300 		uint16		handle;
301 	} __attribute__ ((packed));
302 	struct hci_rp_role_discovery {
303 		uint8		status;
304 		uint16		handle;
305 		uint8		role;
306 	} __attribute__ ((packed));
307 
308 	#define OCF_FLOW_SPECIFICATION
309 	struct hci_cp_flow_specification {
310 		uint16		handle;
311 		uint8		flags;
312 		uint8		flow_direction;
313 		uint8		service_type;
314 		uint32		token_rate;
315 		uint32		token_bucket;
316 		uint32		peak;
317 		uint32		latency;
318 	} __attribute__ ((packed));
319 	/* Quality of service types */
320 	#define HCI_SERVICE_TYPE_NO_TRAFFIC		0x00
321 	#define HCI_SERVICE_TYPE_BEST_EFFORT		0x01
322 	#define HCI_SERVICE_TYPE_GUARANTEED		0x02
323 	/* 0x03 - 0xFF - reserved for future use */
324 
325 	#define OCF_READ_LINK_POLICY		0x000C
326 	struct hci_cp_read_link_policy {
327 		uint16		handle;
328 	} __attribute__ ((packed));
329 	struct hci_rp_read_link_policy {
330 		uint8		status;
331 		uint16		handle;
332 		uint16		policy;
333 	} __attribute__ ((packed));
334 
335 	#define OCF_SWITCH_ROLE				0x000B
336 	struct hci_cp_switch_role {
337 		bdaddr_t	bdaddr;
338 		uint8		role;
339 	} __attribute__ ((packed));
340 
341 	#define OCF_WRITE_LINK_POLICY		0x000D
342 	struct hci_cp_write_link_policy {
343 		uint16		handle;
344 		uint16		policy;
345 	} __attribute__ ((packed));
346 	struct hci_rp_write_link_policy {
347 		uint8		status;
348 		uint16		handle;
349 	} __attribute__ ((packed));
350 
351 /* Status params */
352 #define OGF_STATUS_PARAM				0x05
353 
354 /* Testing commands */
355 #define OGF_TESTING_CMD					0x06
356 
357 /* Vendor specific commands */
358 #define OGF_VENDOR_CMD					0x3F
359 
360 #define OCF_WRITE_BCM2035_BDADDR		0x01
361 	struct hci_write_bcm2035_bdaddr {
362 		bdaddr_t bdaddr;
363 	} _PACKED;
364 
365 #endif // _BTHCI_COMMAND_H_
366