xref: /haiku/headers/os/bluetooth/HCI/btHCI_command.h (revision 579f1dbca962a2a03df54f69fdc6e9423f91f20e)
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_READ_SCAN_ENABLE		0x0019
119 	struct hci_read_scan_enable {
120 		uint8		status;
121 		uint8		enable;
122 	} __attribute__ ((packed));
123 
124 	#define OCF_WRITE_SCAN_ENABLE		0x001A
125 		#define HCI_SCAN_DISABLED		0x00
126 		#define HCI_SCAN_INQUIRY		0x01 //Page Scan disabled
127 		#define HCI_SCAN_PAGE			0x02 //Inquiry Scan disabled
128 		#define HCI_SCAN_INQUIRY_PAGE	0x03 //All enabled
129 	struct hci_write_scan_enable {
130 		uint8		scan;
131 	} __attribute__ ((packed));
132 
133 	#define OCF_READ_AUTH_ENABLE		0x001F
134 	#define OCF_WRITE_AUTH_ENABLE		0x0020
135 		#define HCI_AUTH_DISABLED		0x00
136 		#define HCI_AUTH_ENABLED		0x01
137 	struct hci_write_authentication_enable {
138 		uint8		authentication;
139 	} __attribute__ ((packed));
140 
141 	#define OCF_READ_ENCRYPT_MODE		0x0021
142 	#define OCF_WRITE_ENCRYPT_MODE		0x0022
143 		#define HCI_ENCRYPT_DISABLED	0x00
144 		#define HCI_ENCRYPT_P2P			0x01
145 		#define HCI_ENCRYPT_BOTH		0x02
146 	struct hci_write_encryption_mode_enable {
147 		uint8		encryption;
148 	} __attribute__ ((packed));
149 
150 	/* Filter types */
151 	#define HCI_FLT_CLEAR_ALL			0x00
152 	#define HCI_FLT_INQ_RESULT			0x01
153 	#define HCI_FLT_CONN_SETUP			0x02
154 
155 	/* CONN_SETUP Condition types */
156 	#define HCI_CONN_SETUP_ALLOW_ALL	0x00
157 	#define HCI_CONN_SETUP_ALLOW_CLASS	0x01
158 	#define HCI_CONN_SETUP_ALLOW_BDADDR	0x02
159 
160 	/* CONN_SETUP Conditions */
161 	#define HCI_CONN_SETUP_AUTO_OFF		0x01
162 	#define HCI_CONN_SETUP_AUTO_ON		0x02
163 
164 	#define OCF_READ_CLASS_OF_DEV		0x0023
165 
166 	struct hci_read_dev_class_reply {
167 		uint8		status;
168 		uint8		dev_class[3];
169 	} __attribute__ ((packed));
170 
171 	#define OCF_WRITE_CLASS_OF_DEV		0x0024
172 	struct hci_write_dev_class {
173 		uint8		dev_class[3];
174 	} __attribute__ ((packed));
175 
176 	#define OCF_READ_VOICE_SETTING		0x0025
177 	struct hci_rp_read_voice_setting {
178 		uint8		status;
179 		uint16		voice_setting;
180 	} __attribute__ ((packed));
181 
182 	#define OCF_WRITE_VOICE_SETTING		0x0026
183 	struct hci_cp_write_voice_setting {
184 		uint16		voice_setting;
185 	} __attribute__ ((packed));
186 
187 	#define OCF_HOST_BUFFER_SIZE		0x0033
188 	struct hci_cp_host_buffer_size {
189 		uint16		acl_mtu;
190 		uint8		sco_mtu;
191 		uint16		acl_max_pkt;
192 		uint16		sco_max_pkt;
193 	} __attribute__ ((packed));
194 
195 	/* Link Control Command definition */
196 	#define OGF_LINK_CONTROL			0x01
197 
198 	#define OCF_INQUIRY					0x0001
199 	struct hci_cp_inquiry {
200 		uint8		lap[3];
201 		uint8		length;
202 		uint8		num_rsp;
203 	} __attribute__ ((packed));
204 
205 	#define OCF_INQUIRY_CANCEL			0x0002
206 
207 	#define OCF_CREATE_CONN				0x0005
208 	struct hci_cp_create_conn {
209 		bdaddr_t bdaddr;
210 		uint16		pkt_type;
211 		uint8		pscan_rep_mode;
212 		uint8		pscan_mode;
213 		uint16		clock_offset;
214 		uint8		role_switch;
215 	} __attribute__ ((packed));
216 
217 	#define OCF_DISCONNECT				0x0006
218 	struct hci_disconnect {
219 		uint16		handle;
220 		uint8		reason;
221 	} __attribute__ ((packed));
222 
223 	#define OCF_ADD_SCO					0x0007
224 	struct hci_cp_add_sco {
225 		uint16		handle;
226 		uint16		pkt_type;
227 	} __attribute__ ((packed));
228 
229 	#define OCF_ACCEPT_CONN_REQ			0x0009
230 	struct hci_cp_accept_conn_req {
231 		bdaddr_t	bdaddr;
232 		uint8		role;
233 	} __attribute__ ((packed));
234 
235 	#define OCF_REJECT_CONN_REQ			0x000a
236 	struct hci_cp_reject_conn_req {
237 		bdaddr_t	bdaddr;
238 		uint8		reason;
239 	} __attribute__ ((packed));
240 
241 	#define OCF_LINK_KEY_REPLY			0x000B
242 	struct hci_cp_link_key_reply {
243 		bdaddr_t	bdaddr;
244 		uint8		link_key[16];
245 	} __attribute__ ((packed));
246 
247 	#define OCF_LINK_KEY_NEG_REPLY		0x000C
248 	struct hci_cp_link_key_neg_reply {
249 		bdaddr_t	bdaddr;
250 	} __attribute__ ((packed));
251 
252 	#define OCF_PIN_CODE_REPLY			0x000D
253 	struct hci_cp_pin_code_reply {
254 		bdaddr_t bdaddr;
255 		uint8		pin_len;
256 		uint8		pin_code[HCI_PIN_SIZE];
257 	} __attribute__ ((packed));
258 
259 	struct hci_cp_link_key_reply_reply {
260 		uint8	status;
261 		bdaddr_t bdaddr;
262 	} __attribute__ ((packed));
263 
264 	#define OCF_PIN_CODE_NEG_REPLY		0x000E
265 	struct hci_cp_pin_code_neg_reply {
266 		bdaddr_t	bdaddr;
267 	} __attribute__ ((packed));
268 
269 	#define OCF_CHANGE_CONN_PTYPE		0x000F
270 	struct hci_cp_change_conn_ptype {
271 		uint16		handle;
272 		uint16		pkt_type;
273 	} __attribute__ ((packed));
274 
275 	#define OCF_AUTH_REQUESTED			0x0011
276 	struct hci_cp_auth_requested {
277 		uint16		handle;
278 	} __attribute__ ((packed));
279 
280 	#define OCF_SET_CONN_ENCRYPT		0x0013
281 	struct hci_cp_set_conn_encrypt {
282 		uint16		handle;
283 		uint8		encrypt;
284 	} __attribute__ ((packed));
285 
286 	#define OCF_CHANGE_CONN_LINK_KEY	0x0015
287 	struct hci_cp_change_conn_link_key {
288 		uint16		handle;
289 	} __attribute__ ((packed));
290 
291 	#define OCF_REMOTE_NAME_REQUEST		0x0019
292 	struct hci_remote_name_request {
293 		bdaddr_t bdaddr;
294 		uint8		pscan_rep_mode;
295 		uint8		reserved;
296 		uint16		clock_offset;
297 	} __attribute__ ((packed));
298 
299 	#define OCF_READ_REMOTE_FEATURES	0x001B
300 	struct hci_cp_read_rmt_features {
301 		uint16		handle;
302 	} __attribute__ ((packed));
303 
304 	#define OCF_READ_REMOTE_VERSION		0x001D
305 	struct hci_cp_read_rmt_version {
306 		uint16		handle;
307 	} __attribute__ ((packed));
308 
309 
310 /* Link Policy Command definition */
311 #define OGF_LINK_POLICY					0x02
312 
313 	#define OCF_ROLE_DISCOVERY			0x0009
314 	struct hci_cp_role_discovery {
315 		uint16		handle;
316 	} __attribute__ ((packed));
317 	struct hci_rp_role_discovery {
318 		uint8		status;
319 		uint16		handle;
320 		uint8		role;
321 	} __attribute__ ((packed));
322 
323 	#define OCF_FLOW_SPECIFICATION
324 	struct hci_cp_flow_specification {
325 		uint16		handle;
326 		uint8		flags;
327 		uint8		flow_direction;
328 		uint8		service_type;
329 		uint32		token_rate;
330 		uint32		token_bucket;
331 		uint32		peak;
332 		uint32		latency;
333 	} __attribute__ ((packed));
334 	/* Quality of service types */
335 	#define HCI_SERVICE_TYPE_NO_TRAFFIC		0x00
336 	#define HCI_SERVICE_TYPE_BEST_EFFORT		0x01
337 	#define HCI_SERVICE_TYPE_GUARANTEED		0x02
338 	/* 0x03 - 0xFF - reserved for future use */
339 
340 	#define OCF_READ_LINK_POLICY		0x000C
341 	struct hci_cp_read_link_policy {
342 		uint16		handle;
343 	} __attribute__ ((packed));
344 	struct hci_rp_read_link_policy {
345 		uint8		status;
346 		uint16		handle;
347 		uint16		policy;
348 	} __attribute__ ((packed));
349 
350 	#define OCF_SWITCH_ROLE				0x000B
351 	struct hci_cp_switch_role {
352 		bdaddr_t	bdaddr;
353 		uint8		role;
354 	} __attribute__ ((packed));
355 
356 	#define OCF_WRITE_LINK_POLICY		0x000D
357 	struct hci_cp_write_link_policy {
358 		uint16		handle;
359 		uint16		policy;
360 	} __attribute__ ((packed));
361 	struct hci_rp_write_link_policy {
362 		uint8		status;
363 		uint16		handle;
364 	} __attribute__ ((packed));
365 
366 /* Status params */
367 #define OGF_STATUS_PARAM				0x05
368 
369 /* Testing commands */
370 #define OGF_TESTING_CMD					0x06
371 
372 /* Vendor specific commands */
373 #define OGF_VENDOR_CMD					0x3F
374 
375 #define OCF_WRITE_BCM2035_BDADDR		0x01
376 	struct hci_write_bcm2035_bdaddr {
377 		bdaddr_t bdaddr;
378 	} _PACKED;
379 
380 #endif // _BTHCI_COMMAND_H_
381