1 /*
2    BlueZ - Bluetooth protocol stack for Linux
3    Copyright (C) 2000-2001 Qualcomm Incorporated
4 
5    Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com>
6 
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License version 2 as
9    published by the Free Software Foundation;
10 
11    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
12    OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
14    IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
15    CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
16    WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17    ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18    OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 
20    ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
21    COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
22    SOFTWARE IS DISCLAIMED.
23 */
24 
25 /*
26  *  $Id: hci.h,v 1.5 2002/06/27 17:29:30 maxk Exp $
27  */
28 
29 #ifndef __HCI_H
30 #define __HCI_H
31 
32 #define HCI_MAX_ACL_SIZE	1024
33 #define HCI_MAX_SCO_SIZE	255
34 #define HCI_MAX_EVENT_SIZE	260
35 #define HCI_MAX_FRAME_SIZE	(HCI_MAX_ACL_SIZE + 4)
36 
37 /* HCI dev events */
38 #define HCI_DEV_REG	1
39 #define HCI_DEV_UNREG   2
40 #define HCI_DEV_UP	3
41 #define HCI_DEV_DOWN	4
42 #define HCI_DEV_SUSPEND	5
43 #define HCI_DEV_RESUME	6
44 
45 /* HCI device types */
46 #define HCI_VHCI	0
47 #define HCI_USB		1
48 #define HCI_PCCARD	2
49 #define HCI_UART 	3
50 #define HCI_RS232 	4
51 #define HCI_PCI		5
52 
53 /* HCI device quirks */
54 enum {
55 	HCI_QUIRK_RESET_ON_INIT
56 };
57 
58 /* HCI device flags */
59 enum {
60 	HCI_UP,
61 	HCI_INIT,
62 	HCI_RUNNING,
63 
64 	HCI_PSCAN,
65 	HCI_ISCAN,
66 	HCI_AUTH,
67 	HCI_ENCRYPT,
68 	HCI_INQUIRY,
69 
70 	HCI_RAW
71 };
72 
73 /* HCI ioctl defines */
74 #define HCIDEVUP        _IOW('H', 201, int)
75 #define HCIDEVDOWN      _IOW('H', 202, int)
76 #define HCIDEVRESET     _IOW('H', 203, int)
77 #define HCIDEVRESTAT    _IOW('H', 204, int)
78 
79 #define HCIGETDEVLIST   _IOR('H', 210, int)
80 #define HCIGETDEVINFO   _IOR('H', 211, int)
81 #define HCIGETCONNLIST  _IOR('H', 212, int)
82 #define HCIGETCONNINFO  _IOR('H', 213, int)
83 
84 #define HCISETRAW       _IOW('H', 220, int)
85 #define HCISETSCAN      _IOW('H', 221, int)
86 #define HCISETAUTH      _IOW('H', 222, int)
87 #define HCISETENCRYPT   _IOW('H', 223, int)
88 #define HCISETPTYPE     _IOW('H', 224, int)
89 #define HCISETLINKPOL   _IOW('H', 225, int)
90 #define HCISETLINKMODE  _IOW('H', 226, int)
91 #define HCISETACLMTU    _IOW('H', 227, int)
92 #define HCISETSCOMTU    _IOW('H', 228, int)
93 
94 #define HCIINQUIRY      _IOR('H', 240, int)
95 
96 /* HCI timeouts */
97 #define HCI_CONN_TIMEOUT 	(HZ * 40)
98 #define HCI_DISCONN_TIMEOUT 	(HZ * 2)
99 #define HCI_CONN_IDLE_TIMEOUT	(HZ * 60)
100 
101 /* HCI Packet types */
102 #define HCI_COMMAND_PKT		0x01
103 #define HCI_ACLDATA_PKT 	0x02
104 #define HCI_SCODATA_PKT 	0x03
105 #define HCI_EVENT_PKT		0x04
106 #define HCI_UNKNOWN_PKT		0xff
107 
108 /* HCI Packet types */
109 #define HCI_DM1 	0x0008
110 #define HCI_DM3 	0x0400
111 #define HCI_DM5 	0x4000
112 #define HCI_DH1 	0x0010
113 #define HCI_DH3 	0x0800
114 #define HCI_DH5 	0x8000
115 
116 #define HCI_HV1		0x0020
117 #define HCI_HV2		0x0040
118 #define HCI_HV3		0x0080
119 
120 #define SCO_PTYPE_MASK	(HCI_HV1 | HCI_HV2 | HCI_HV3)
121 #define ACL_PTYPE_MASK	(~SCO_PTYPE_MASK)
122 
123 /* ACL flags */
124 #define ACL_CONT		0x01
125 #define ACL_START		0x02
126 #define ACL_ACTIVE_BCAST	0x04
127 #define ACL_PICO_BCAST		0x08
128 
129 /* Baseband links */
130 #define SCO_LINK	0x00
131 #define ACL_LINK	0x01
132 
133 /* LMP features */
134 #define LMP_3SLOT	0x01
135 #define LMP_5SLOT	0x02
136 #define LMP_ENCRYPT	0x04
137 #define LMP_SOFFSET	0x08
138 #define LMP_TACCURACY	0x10
139 #define LMP_RSWITCH	0x20
140 #define LMP_HOLD	0x40
141 #define LMP_SNIF	0x80
142 
143 #define LMP_PARK	0x01
144 #define LMP_RSSI	0x02
145 #define LMP_QUALITY	0x04
146 #define LMP_SCO		0x08
147 #define LMP_HV2		0x10
148 #define LMP_HV3		0x20
149 #define LMP_ULAW	0x40
150 #define LMP_ALAW	0x80
151 
152 #define LMP_CVSD	0x01
153 #define LMP_PSCHEME	0x02
154 #define LMP_PCONTROL	0x04
155 
156 /* Link policies */
157 #define HCI_LP_RSWITCH	0x0001
158 #define HCI_LP_HOLD	0x0002
159 #define HCI_LP_SNIFF	0x0004
160 #define HCI_LP_PARK	0x0008
161 
162 /* Link mode */
163 #define HCI_LM_ACCEPT	0x8000
164 #define HCI_LM_MASTER	0x0001
165 #define HCI_LM_AUTH	0x0002
166 #define HCI_LM_ENCRYPT	0x0004
167 #define HCI_LM_TRUSTED	0x0008
168 #define HCI_LM_RELIABLE	0x0010
169 
170 /* -----  HCI Commands ----- */
171 /* OGF & OCF values */
172 
173 /* Informational Parameters */
174 #define OGF_INFO_PARAM	0x04
175 
176 #define OCF_READ_LOCAL_VERSION	0x0001
177 typedef struct {
178 	__u8  status;
179 	__u8  hci_ver;
180 	__u16 hci_rev;
181 	__u8  lmp_ver;
182 	__u16 manufacturer;
183 	__u16 lmp_subver;
184 } __attribute__ ((packed)) read_local_version_rp;
185 #define READ_LOCAL_VERSION_RP_SIZE 9
186 
187 #define OCF_READ_LOCAL_FEATURES	0x0003
188 typedef struct {
189 	__u8 status;
190 	__u8 features[8];
191 } __attribute__ ((packed)) read_local_features_rp;
192 
193 #define OCF_READ_BUFFER_SIZE	0x0005
194 typedef struct {
195 	__u8 	status;
196 	__u16 	acl_mtu;
197 	__u8 	sco_mtu;
198 	__u16 	acl_max_pkt;
199 	__u16	sco_max_pkt;
200 } __attribute__ ((packed)) read_buffer_size_rp;
201 
202 #define OCF_READ_BD_ADDR	0x0009
203 typedef struct {
204 	__u8 status;
205 	bdaddr_t bdaddr;
206 } __attribute__ ((packed)) read_bd_addr_rp;
207 
208 /* Host Controller and Baseband */
209 #define OGF_HOST_CTL	0x03
210 #define OCF_RESET		0x0003
211 #define OCF_READ_AUTH_ENABLE	0x001F
212 #define OCF_WRITE_AUTH_ENABLE	0x0020
213 	#define AUTH_DISABLED		0x00
214 	#define AUTH_ENABLED		0x01
215 
216 #define OCF_READ_ENCRYPT_MODE	0x0021
217 #define OCF_WRITE_ENCRYPT_MODE	0x0022
218 	#define ENCRYPT_DISABLED	0x00
219 	#define ENCRYPT_P2P		0x01
220 	#define ENCRYPT_BOTH		0x02
221 
222 #define OCF_WRITE_CA_TIMEOUT  	0x0016
223 #define OCF_WRITE_PG_TIMEOUT  	0x0018
224 
225 #define OCF_WRITE_SCAN_ENABLE 	0x001A
226 	#define SCAN_DISABLED		0x00
227 	#define SCAN_INQUIRY		0x01
228 	#define SCAN_PAGE		0x02
229 
230 #define OCF_SET_EVENT_FLT	0x0005
231 typedef struct {
232 	__u8 	flt_type;
233 	__u8 	cond_type;
234 	__u8 	condition[0];
235 } __attribute__ ((packed)) set_event_flt_cp;
236 #define SET_EVENT_FLT_CP_SIZE 2
237 
238 /* Filter types */
239 #define FLT_CLEAR_ALL	0x00
240 #define FLT_INQ_RESULT	0x01
241 #define FLT_CONN_SETUP	0x02
242 
243 /* CONN_SETUP Condition types */
244 #define CONN_SETUP_ALLOW_ALL	0x00
245 #define CONN_SETUP_ALLOW_CLASS	0x01
246 #define CONN_SETUP_ALLOW_BDADDR	0x02
247 
248 /* CONN_SETUP Conditions */
249 #define CONN_SETUP_AUTO_OFF	0x01
250 #define CONN_SETUP_AUTO_ON	0x02
251 
252 #define OCF_CHANGE_LOCAL_NAME	0x0013
253 typedef struct {
254 	__u8 	name[248];
255 } __attribute__ ((packed)) change_local_name_cp;
256 #define CHANGE_LOCAL_NAME_CP_SIZE 248
257 
258 #define OCF_READ_LOCAL_NAME	0x0014
259 typedef struct {
260 	__u8	status;
261 	__u8 	name[248];
262 } __attribute__ ((packed)) read_local_name_rp;
263 #define READ_LOCAL_NAME_RP_SIZE 249
264 
265 #define OCF_READ_CLASS_OF_DEV	0x0023
266 typedef struct {
267 	__u8	status;
268 	__u8 	dev_class[3];
269 } __attribute__ ((packed)) read_class_of_dev_rp;
270 #define READ_CLASS_OF_DEV_RP_SIZE 4
271 
272 #define OCF_WRITE_CLASS_OF_DEV	0x0024
273 typedef struct {
274 	__u8 	dev_class[3];
275 } __attribute__ ((packed)) write_class_of_dev_cp;
276 #define WRITE_CLASS_OF_DEV_CP_SIZE 3
277 
278 #define OCF_HOST_BUFFER_SIZE	0x0033
279 typedef struct {
280 	__u16 	acl_mtu;
281 	__u8 	sco_mtu;
282 	__u16 	acl_max_pkt;
283 	__u16	sco_max_pkt;
284 } __attribute__ ((packed)) host_buffer_size_cp;
285 #define HOST_BUFFER_SIZE_CP_SIZE 7
286 
287 /* Link Control */
288 #define OGF_LINK_CTL	0x01
289 #define OCF_CREATE_CONN		0x0005
290 typedef struct {
291 	bdaddr_t bdaddr;
292 	__u16 	pkt_type;
293 	__u8 	pscan_rep_mode;
294 	__u8 	pscan_mode;
295 	__u16 	clock_offset;
296 	__u8 	role_switch;
297 } __attribute__ ((packed)) create_conn_cp;
298 #define CREATE_CONN_CP_SIZE 13
299 
300 #define OCF_ACCEPT_CONN_REQ	0x0009
301 typedef struct {
302 	bdaddr_t bdaddr;
303 	__u8 	role;
304 } __attribute__ ((packed)) accept_conn_req_cp;
305 #define ACCEPT_CONN_REQ_CP_SIZE	7
306 
307 #define OCF_REJECT_CONN_REQ	0x000a
308 typedef struct {
309 	bdaddr_t bdaddr;
310 	__u8 	reason;
311 } __attribute__ ((packed)) reject_conn_req_cp;
312 #define REJECT_CONN_REQ_CP_SIZE	7
313 
314 #define OCF_DISCONNECT	0x0006
315 typedef struct {
316 	__u16 	handle;
317 	__u8 	reason;
318 } __attribute__ ((packed)) disconnect_cp;
319 #define DISCONNECT_CP_SIZE 3
320 
321 #define OCF_ADD_SCO	0x0007
322 typedef struct {
323 	__u16 	handle;
324 	__u16 	pkt_type;
325 } __attribute__ ((packed)) add_sco_cp;
326 #define ADD_SCO_CP_SIZE 4
327 
328 #define OCF_INQUIRY		0x0001
329 typedef struct {
330 	__u8 	lap[3];
331 	__u8 	length;
332 	__u8	num_rsp;
333 } __attribute__ ((packed)) inquiry_cp;
334 #define INQUIRY_CP_SIZE 5
335 
336 typedef struct {
337 	__u8     status;
338 	bdaddr_t bdaddr;
339 } __attribute__ ((packed)) status_bdaddr_rp;
340 #define STATUS_BDADDR_RP_SIZE 7
341 
342 #define OCF_INQUIRY_CANCEL	0x0002
343 
344 #define OCF_LINK_KEY_REPLY	0x000B
345 #define OCF_LINK_KEY_NEG_REPLY	0x000C
346 typedef struct {
347 	bdaddr_t bdaddr;
348 	__u8     link_key[16];
349 } __attribute__ ((packed)) link_key_reply_cp;
350 #define LINK_KEY_REPLY_CP_SIZE 22
351 
352 #define OCF_PIN_CODE_REPLY	0x000D
353 #define OCF_PIN_CODE_NEG_REPLY	0x000E
354 typedef struct {
355 	bdaddr_t bdaddr;
356 	__u8	 pin_len;
357 	__u8	 pin_code[16];
358 } __attribute__ ((packed)) pin_code_reply_cp;
359 #define PIN_CODE_REPLY_CP_SIZE 23
360 
361 #define OCF_CHANGE_CONN_PTYPE	0x000F
362 typedef struct {
363 	__u16	 handle;
364 	__u16	 pkt_type;
365 } __attribute__ ((packed)) change_conn_ptype_cp;
366 #define CHANGE_CONN_PTYPE_CP_SIZE 4
367 
368 #define OCF_AUTH_REQUESTED	0x0011
369 typedef struct {
370 	__u16	 handle;
371 } __attribute__ ((packed)) auth_requested_cp;
372 #define AUTH_REQUESTED_CP_SIZE 2
373 
374 #define OCF_SET_CONN_ENCRYPT	0x0013
375 typedef struct {
376 	__u16	 handle;
377 	__u8	 encrypt;
378 } __attribute__ ((packed)) set_conn_encrypt_cp;
379 #define SET_CONN_ENCRYPT_CP_SIZE 3
380 
381 #define OCF_REMOTE_NAME_REQ	0x0019
382 typedef struct {
383 	bdaddr_t bdaddr;
384 	__u8     pscan_rep_mode;
385 	__u8     pscan_mode;
386 	__u16    clock_offset;
387 } __attribute__ ((packed)) remote_name_req_cp;
388 #define REMOTE_NAME_REQ_CP_SIZE 10
389 
390 #define OCF_READ_REMOTE_FEATURES 0x001B
391 typedef struct {
392 	__u16   handle;
393 } __attribute__ ((packed)) read_remote_features_cp;
394 #define READ_REMOTE_FEATURES_CP_SIZE 2
395 
396 #define OCF_READ_REMOTE_VERSION 0x001D
397 typedef struct {
398 	__u16   handle;
399 } __attribute__ ((packed)) read_remote_version_cp;
400 #define READ_REMOTE_VERSION_CP_SIZE 2
401 
402 /* Link Policy */
403 #define OGF_LINK_POLICY	 0x02
404 #define OCF_ROLE_DISCOVERY	0x0009
405 typedef struct {
406 	__u16	handle;
407 } __attribute__ ((packed)) role_discovery_cp;
408 #define ROLE_DISCOVERY_CP_SIZE 2
409 typedef struct {
410 	__u8    status;
411 	__u16	handle;
412 	__u8    role;
413 } __attribute__ ((packed)) role_discovery_rp;
414 #define ROLE_DISCOVERY_RP_SIZE 4
415 
416 #define OCF_READ_LINK_POLICY	0x000C
417 typedef struct {
418 	__u16	handle;
419 } __attribute__ ((packed)) read_link_policy_cp;
420 #define READ_LINK_POLICY_CP_SIZE 2
421 typedef struct {
422 	__u8    status;
423 	__u16	handle;
424 	__u16   policy;
425 } __attribute__ ((packed)) read_link_policy_rp;
426 #define READ_LINK_POLICY_RP_SIZE 5
427 
428 #define OCF_SWITCH_ROLE	0x000B
429 typedef struct {
430 	bdaddr_t bdaddr;
431 	__u8     role;
432 } __attribute__ ((packed)) switch_role_cp;
433 #define SWITCH_ROLE_CP_SIZE 7
434 
435 #define OCF_WRITE_LINK_POLICY	0x000D
436 typedef struct {
437 	__u16	handle;
438 	__u16   policy;
439 } __attribute__ ((packed)) write_link_policy_cp;
440 #define WRITE_LINK_POLICY_CP_SIZE 4
441 typedef struct {
442 	__u8    status;
443 	__u16	handle;
444 } __attribute__ ((packed)) write_link_policy_rp;
445 #define WRITE_LINK_POLICY_RP_SIZE 3
446 
447 /* Status params */
448 #define OGF_STATUS_PARAM 	0x05
449 
450 /* Testing commands */
451 #define OGF_TESTING_CMD 	0x3e
452 
453 /* Vendor specific commands */
454 #define OGF_VENDOR_CMD  	0x3f
455 
456 /* ---- HCI Events ---- */
457 #define EVT_INQUIRY_COMPLETE 	0x01
458 
459 #define EVT_INQUIRY_RESULT 	0x02
460 typedef struct {
461 	bdaddr_t	bdaddr;
462 	__u8	pscan_rep_mode;
463 	__u8	pscan_period_mode;
464 	__u8	pscan_mode;
465 	__u8	dev_class[3];
466 	__u16	clock_offset;
467 } __attribute__ ((packed)) inquiry_info;
468 #define INQUIRY_INFO_SIZE 14
469 
470 #define EVT_INQUIRY_RESULT_WITH_RSSI	0x22
471 typedef struct {
472 	bdaddr_t	bdaddr;
473 	__u8	pscan_rep_mode;
474 	__u8	pscan_period_mode;
475 	__u8	dev_class[3];
476 	__u16	clock_offset;
477 	__s8	rssi;
478 } __attribute__ ((packed)) inquiry_info_with_rssi;
479 #define INQUIRY_INFO_WITH_RSSI_SIZE 14
480 
481 #define EVT_CONN_COMPLETE 	0x03
482 typedef struct {
483 	__u8	status;
484 	__u16	handle;
485 	bdaddr_t	bdaddr;
486 	__u8	link_type;
487 	__u8	encr_mode;
488 } __attribute__ ((packed)) evt_conn_complete;
489 #define EVT_CONN_COMPLETE_SIZE 13
490 
491 #define EVT_CONN_REQUEST	0x04
492 typedef struct {
493 	bdaddr_t 	bdaddr;
494 	__u8 		dev_class[3];
495 	__u8		link_type;
496 } __attribute__ ((packed)) evt_conn_request;
497 #define EVT_CONN_REQUEST_SIZE 10
498 
499 #define EVT_DISCONN_COMPLETE	0x05
500 typedef struct {
501 	__u8 	status;
502 	__u16 	handle;
503 	__u8 	reason;
504 } __attribute__ ((packed)) evt_disconn_complete;
505 #define EVT_DISCONN_COMPLETE_SIZE 4
506 
507 #define EVT_AUTH_COMPLETE	0x06
508 typedef struct {
509 	__u8 	status;
510 	__u16 	handle;
511 } __attribute__ ((packed)) evt_auth_complete;
512 #define EVT_AUTH_COMPLETE_SIZE 3
513 
514 #define EVT_REMOTE_NAME_REQ_COMPLETE	0x07
515 typedef struct {
516 	__u8 	 status;
517 	bdaddr_t bdaddr;
518 	__u8 	 name[248];
519 } __attribute__ ((packed)) evt_remote_name_req_complete;
520 #define EVT_REMOTE_NAME_REQ_COMPLETE_SIZE 255
521 
522 #define EVT_ENCRYPT_CHANGE	0x08
523 typedef struct {
524 	__u8 	status;
525 	__u16 	handle;
526 	__u8	encrypt;
527 } __attribute__ ((packed)) evt_encrypt_change;
528 #define EVT_ENCRYPT_CHANGE_SIZE 5
529 
530 #define EVT_QOS_SETUP_COMPLETE 0x0D
531 typedef struct {
532 	__u8	service_type;
533 	__u32	token_rate;
534 	__u32	peak_bandwidth;
535 	__u32	latency;
536 	__u32	delay_variation;
537 } __attribute__ ((packed)) hci_qos;
538 typedef struct {
539 	__u8	status;
540 	__u16	handle;
541 	hci_qos qos;
542 } __attribute__ ((packed)) evt_qos_setup_complete;
543 #define EVT_QOS_SETUP_COMPLETE_SIZE 20
544 
545 #define EVT_CMD_COMPLETE 	0x0e
546 typedef struct {
547 	__u8 	ncmd;
548 	__u16 	opcode;
549 } __attribute__ ((packed)) evt_cmd_complete;
550 #define EVT_CMD_COMPLETE_SIZE 3
551 
552 #define EVT_CMD_STATUS 		0x0f
553 typedef struct {
554 	__u8 	status;
555 	__u8 	ncmd;
556 	__u16 	opcode;
557 } __attribute__ ((packed)) evt_cmd_status;
558 #define EVT_CMD_STATUS_SIZE 4
559 
560 #define EVT_NUM_COMP_PKTS	0x13
561 typedef struct {
562 	__u8 	num_hndl;
563 	/* variable length part */
564 } __attribute__ ((packed)) evt_num_comp_pkts;
565 #define EVT_NUM_COMP_PKTS_SIZE 1
566 
567 #define EVT_ROLE_CHANGE		0x12
568 typedef struct {
569 	__u8 	 status;
570 	bdaddr_t bdaddr;
571 	__u8     role;
572 } __attribute__ ((packed)) evt_role_change;
573 #define EVT_ROLE_CHANGE_SIZE 8
574 
575 #define EVT_PIN_CODE_REQ        0x16
576 typedef struct {
577 	bdaddr_t bdaddr;
578 } __attribute__ ((packed)) evt_pin_code_req;
579 #define EVT_PIN_CODE_REQ_SIZE 6
580 
581 #define EVT_LINK_KEY_REQ        0x17
582 typedef struct {
583 	bdaddr_t bdaddr;
584 } __attribute__ ((packed)) evt_link_key_req;
585 #define EVT_LINK_KEY_REQ_SIZE 6
586 
587 #define EVT_LINK_KEY_NOTIFY	0x18
588 typedef struct {
589 	bdaddr_t bdaddr;
590 	__u8	 link_key[16];
591 	__u8	 key_type;
592 } __attribute__ ((packed)) evt_link_key_notify;
593 #define EVT_LINK_KEY_NOTIFY_SIZE 23
594 
595 #define EVT_READ_REMOTE_FEATURES_COMPLETE 0x0B
596 typedef struct {
597 	__u8    status;
598 	__u16   handle;
599 	__u8    features[8];
600 } __attribute__ ((packed)) evt_read_remote_features_complete;
601 #define EVT_READ_REMOTE_FEATURES_COMPLETE_SIZE 11
602 
603 #define EVT_READ_REMOTE_VERSION_COMPLETE 0x0C
604 typedef struct {
605 	__u8    status;
606 	__u16   handle;
607 	__u8    lmp_ver;
608 	__u16   manufacturer;
609 	__u16   lmp_subver;
610 } __attribute__ ((packed)) evt_read_remote_version_complete;
611 #define EVT_READ_REMOTE_VERSION_COMPLETE_SIZE 8
612 
613 /* Internal events generated by BlueZ stack */
614 #define EVT_STACK_INTERNAL	0xfd
615 typedef struct {
616 	__u16   type;
617 	__u8 	data[0];
618 } __attribute__ ((packed)) evt_stack_internal;
619 #define EVT_STACK_INTERNAL_SIZE 2
620 
621 #define EVT_SI_DEVICE  	0x01
622 typedef struct {
623 	__u16   event;
624 	__u16 	dev_id;
625 } __attribute__ ((packed)) evt_si_device;
626 #define EVT_SI_DEVICE_SIZE 4
627 
628 #define EVT_SI_SECURITY	0x02
629 typedef struct {
630 	__u16 	event;
631 	__u16   proto;
632 	__u16   subproto;
633 	__u8    incomming;
634 } __attribute__ ((packed)) evt_si_security;
635 
636 /* --------  HCI Packet structures  -------- */
637 #define HCI_TYPE_LEN	1
638 
639 typedef struct {
640 	__u16 	opcode;		/* OCF & OGF */
641 	__u8 	plen;
642 } __attribute__ ((packed))	hci_command_hdr;
643 #define HCI_COMMAND_HDR_SIZE 	3
644 
645 typedef struct {
646 	__u8 	evt;
647 	__u8 	plen;
648 } __attribute__ ((packed))	hci_event_hdr;
649 #define HCI_EVENT_HDR_SIZE 	2
650 
651 typedef struct {
652 	__u16 	handle;		/* Handle & Flags(PB, BC) */
653 	__u16 	dlen;
654 } __attribute__ ((packed))	hci_acl_hdr;
655 #define HCI_ACL_HDR_SIZE 	4
656 
657 typedef struct {
658 	__u16 	handle;
659 	__u8 	dlen;
660 } __attribute__ ((packed))	hci_sco_hdr;
661 #define HCI_SCO_HDR_SIZE 	3
662 
663 /* Command opcode pack/unpack */
664 #define cmd_opcode_pack(ogf, ocf)	(__u16)((ocf & 0x03ff)|(ogf << 10))
665 #define cmd_opcode_ogf(op)		(op >> 10)
666 #define cmd_opcode_ocf(op)		(op & 0x03ff)
667 
668 /* ACL handle and flags pack/unpack */
669 #define acl_handle_pack(h, f)	(__u16)((h & 0x0fff)|(f << 12))
670 #define acl_handle(h)		(h & 0x0fff)
671 #define acl_flags(h)		(h >> 12)
672 
673 /* HCI Socket options */
674 #define HCI_DATA_DIR	1
675 #define HCI_FILTER	2
676 #define HCI_TIME_STAMP	3
677 
678 /* HCI CMSG flags */
679 #define HCI_CMSG_DIR	0x0001
680 #define HCI_CMSG_TSTAMP	0x0002
681 
682 struct sockaddr_hci {
683 	sa_family_t    hci_family;
684 	unsigned short hci_dev;
685 };
686 #define HCI_DEV_NONE	0xffff
687 
688 struct hci_filter {
689 	__u32 type_mask;
690 	__u32 event_mask[2];
691 	__u16 opcode;
692 };
693 
694 #define HCI_FLT_TYPE_BITS	31
695 #define HCI_FLT_EVENT_BITS	63
696 #define HCI_FLT_OGF_BITS	63
697 #define HCI_FLT_OCF_BITS	127
698 
699 #if BITS_PER_LONG == 64
hci_set_bit(int nr,void * addr)700 static inline void hci_set_bit(int nr, void *addr)
701 {
702 	*((__u32 *) addr + (nr >> 5)) |= ((__u32) 1 << (nr & 31));
703 }
hci_test_bit(int nr,void * addr)704 static inline int hci_test_bit(int nr, void *addr)
705 {
706 	return *((__u32 *) addr + (nr >> 5)) & ((__u32) 1 << (nr & 31));
707 }
708 #else
709 #define hci_set_bit	set_bit
710 #define hci_test_bit	test_bit
711 #endif
712 
713 /* Ioctl requests structures */
714 struct hci_dev_stats {
715 	__u32 err_rx;
716 	__u32 err_tx;
717 	__u32 cmd_tx;
718 	__u32 evt_rx;
719 	__u32 acl_tx;
720 	__u32 acl_rx;
721 	__u32 sco_tx;
722 	__u32 sco_rx;
723 	__u32 byte_rx;
724 	__u32 byte_tx;
725 };
726 
727 struct hci_dev_info {
728 	__u16 dev_id;
729 	char  name[8];
730 
731 	bdaddr_t bdaddr;
732 
733 	__u32 flags;
734 	__u8  type;
735 
736 	__u8  features[8];
737 
738 	__u32 pkt_type;
739 	__u32 link_policy;
740 	__u32 link_mode;
741 
742 	__u16 acl_mtu;
743 	__u16 acl_pkts;
744 	__u16 sco_mtu;
745 	__u16 sco_pkts;
746 
747 	struct hci_dev_stats stat;
748 };
749 
750 struct hci_conn_info {
751 	__u16    handle;
752 	bdaddr_t bdaddr;
753 	__u8	 type;
754 	__u8	 out;
755 	__u16	 state;
756 	__u32	 link_mode;
757 };
758 
759 struct hci_dev_req {
760 	__u16 dev_id;
761 	__u32 dev_opt;
762 };
763 
764 struct hci_dev_list_req {
765 	__u16  dev_num;
766 	struct hci_dev_req dev_req[0];	/* hci_dev_req structures */
767 };
768 
769 struct hci_conn_list_req {
770 	__u16  dev_id;
771 	__u16  conn_num;
772 	struct hci_conn_info conn_info[0];
773 };
774 
775 struct hci_conn_info_req {
776 	bdaddr_t bdaddr;
777 	__u8     type;
778 	struct   hci_conn_info conn_info[0];
779 };
780 
781 struct hci_inquiry_req {
782 	__u16 dev_id;
783 	__u16 flags;
784 	__u8  lap[3];
785 	__u8  length;
786 	__u8  num_rsp;
787 };
788 #define IREQ_CACHE_FLUSH 0x0001
789 
790 struct hci_remotename_req {
791 	__u16 dev_id;
792 	__u16 flags;
793 	bdaddr_t bdaddr;
794 	__u8  name[248];
795 };
796 
797 #endif /* __HCI_H */
798