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