2 BlueZ - Bluetooth protocol stack for Linux
3 Copyright (C) 2000-2001 Qualcomm Incorporated
5 Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com>
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;
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.
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.
26 * $Id: hci.h,v 1.1.1.1 2005/04/11 02:51:08 jack Exp $
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)
39 #define HCI_DEV_UNREG 2
41 #define HCI_DEV_DOWN 4
42 #define HCI_DEV_SUSPEND 5
43 #define HCI_DEV_RESUME 6
45 /* HCI device types */
53 /* HCI device flags */
68 /* HCI ioctl defines */
69 #define HCIDEVUP _IOW('H', 201, int)
70 #define HCIDEVDOWN _IOW('H', 202, int)
71 #define HCIDEVRESET _IOW('H', 203, int)
72 #define HCIDEVRESTAT _IOW('H', 204, int)
74 #define HCIGETDEVLIST _IOR('H', 210, int)
75 #define HCIGETDEVINFO _IOR('H', 211, int)
76 #define HCIGETCONNLIST _IOR('H', 212, int)
77 #define HCIGETCONNINFO _IOR('H', 213, int)
79 #define HCISETRAW _IOW('H', 220, int)
80 #define HCISETSCAN _IOW('H', 221, int)
81 #define HCISETAUTH _IOW('H', 222, int)
82 #define HCISETENCRYPT _IOW('H', 223, int)
83 #define HCISETPTYPE _IOW('H', 224, int)
84 #define HCISETLINKPOL _IOW('H', 225, int)
85 #define HCISETLINKMODE _IOW('H', 226, int)
86 #define HCISETACLMTU _IOW('H', 227, int)
87 #define HCISETSCOMTU _IOW('H', 228, int)
89 #define HCIINQUIRY _IOR('H', 240, int)
92 #define HCI_CONN_TIMEOUT (HZ * 40)
93 #define HCI_DISCONN_TIMEOUT (HZ * 2)
94 #define HCI_CONN_IDLE_TIMEOUT (HZ * 60)
96 /* HCI Packet types */
97 #define HCI_COMMAND_PKT 0x01
98 #define HCI_ACLDATA_PKT 0x02
99 #define HCI_SCODATA_PKT 0x03
100 #define HCI_EVENT_PKT 0x04
101 #define HCI_UNKNOWN_PKT 0xff
103 /* HCI Packet types */
104 #define HCI_DM1 0x0008
105 #define HCI_DM3 0x0400
106 #define HCI_DM5 0x4000
107 #define HCI_DH1 0x0010
108 #define HCI_DH3 0x0800
109 #define HCI_DH5 0x8000
111 #define HCI_HV1 0x0020
112 #define HCI_HV2 0x0040
113 #define HCI_HV3 0x0080
115 #define SCO_PTYPE_MASK (HCI_HV1 | HCI_HV2 | HCI_HV3)
116 #define ACL_PTYPE_MASK (~SCO_PTYPE_MASK)
119 #define ACL_CONT 0x01
120 #define ACL_START 0x02
121 #define ACL_ACTIVE_BCAST 0x04
122 #define ACL_PICO_BCAST 0x08
125 #define SCO_LINK 0x00
126 #define ACL_LINK 0x01
129 #define LMP_3SLOT 0x01
130 #define LMP_5SLOT 0x02
131 #define LMP_ENCRYPT 0x04
132 #define LMP_SOFFSET 0x08
133 #define LMP_TACCURACY 0x10
134 #define LMP_RSWITCH 0x20
135 #define LMP_HOLD 0x40
136 #define LMP_SNIF 0x80
138 #define LMP_PARK 0x01
139 #define LMP_RSSI 0x02
140 #define LMP_QUALITY 0x04
144 #define LMP_ULAW 0x40
145 #define LMP_ALAW 0x80
147 #define LMP_CVSD 0x01
148 #define LMP_PSCHEME 0x02
149 #define LMP_PCONTROL 0x04
152 #define HCI_LP_RSWITCH 0x0001
153 #define HCI_LP_HOLD 0x0002
154 #define HCI_LP_SNIFF 0x0004
155 #define HCI_LP_PARK 0x0008
158 #define HCI_LM_ACCEPT 0x8000
159 #define HCI_LM_MASTER 0x0001
160 #define HCI_LM_AUTH 0x0002
161 #define HCI_LM_ENCRYPT 0x0004
162 #define HCI_LM_TRUSTED 0x0008
164 /* ----- HCI Commands ----- */
165 /* OGF & OCF values */
167 /* Informational Parameters */
168 #define OGF_INFO_PARAM 0x04
170 #define OCF_READ_LOCAL_VERSION 0x0001
178 } __attribute__ ((packed)) read_local_version_rp;
179 #define READ_LOCAL_VERSION_RP_SIZE 9
181 #define OCF_READ_LOCAL_FEATURES 0x0003
185 } __attribute__ ((packed)) read_local_features_rp;
187 #define OCF_READ_BUFFER_SIZE 0x0005
194 } __attribute__ ((packed)) read_buffer_size_rp;
196 #define OCF_READ_BD_ADDR 0x0009
200 } __attribute__ ((packed)) read_bd_addr_rp;
202 /* Host Controller and Baseband */
203 #define OGF_HOST_CTL 0x03
204 #define OCF_RESET 0x0003
205 #define OCF_READ_AUTH_ENABLE 0x001F
206 #define OCF_WRITE_AUTH_ENABLE 0x0020
207 #define AUTH_DISABLED 0x00
208 #define AUTH_ENABLED 0x01
210 #define OCF_READ_ENCRYPT_MODE 0x0021
211 #define OCF_WRITE_ENCRYPT_MODE 0x0022
212 #define ENCRYPT_DISABLED 0x00
213 #define ENCRYPT_P2P 0x01
214 #define ENCRYPT_BOTH 0x02
216 #define OCF_WRITE_CA_TIMEOUT 0x0016
217 #define OCF_WRITE_PG_TIMEOUT 0x0018
219 #define OCF_WRITE_SCAN_ENABLE 0x001A
220 #define SCAN_DISABLED 0x00
221 #define SCAN_INQUIRY 0x01
222 #define SCAN_PAGE 0x02
224 #define OCF_SET_EVENT_FLT 0x0005
229 } __attribute__ ((packed)) set_event_flt_cp;
230 #define SET_EVENT_FLT_CP_SIZE 2
233 #define FLT_CLEAR_ALL 0x00
234 #define FLT_INQ_RESULT 0x01
235 #define FLT_CONN_SETUP 0x02
237 /* CONN_SETUP Condition types */
238 #define CONN_SETUP_ALLOW_ALL 0x00
239 #define CONN_SETUP_ALLOW_CLASS 0x01
240 #define CONN_SETUP_ALLOW_BDADDR 0x02
242 /* CONN_SETUP Conditions */
243 #define CONN_SETUP_AUTO_OFF 0x01
244 #define CONN_SETUP_AUTO_ON 0x02
246 #define OCF_CHANGE_LOCAL_NAME 0x0013
249 } __attribute__ ((packed)) change_local_name_cp;
250 #define CHANGE_LOCAL_NAME_CP_SIZE 248
252 #define OCF_READ_LOCAL_NAME 0x0014
256 } __attribute__ ((packed)) read_local_name_rp;
257 #define READ_LOCAL_NAME_RP_SIZE 249
259 #define OCF_READ_CLASS_OF_DEV 0x0023
263 } __attribute__ ((packed)) read_class_of_dev_rp;
264 #define READ_CLASS_OF_DEV_RP_SIZE 4
266 #define OCF_WRITE_CLASS_OF_DEV 0x0024
269 } __attribute__ ((packed)) write_class_of_dev_cp;
270 #define WRITE_CLASS_OF_DEV_CP_SIZE 3
272 #define OCF_HOST_BUFFER_SIZE 0x0033
278 } __attribute__ ((packed)) host_buffer_size_cp;
279 #define HOST_BUFFER_SIZE_CP_SIZE 7
282 #define OGF_LINK_CTL 0x01
283 #define OCF_CREATE_CONN 0x0005
291 } __attribute__ ((packed)) create_conn_cp;
292 #define CREATE_CONN_CP_SIZE 13
294 #define OCF_ACCEPT_CONN_REQ 0x0009
298 } __attribute__ ((packed)) accept_conn_req_cp;
299 #define ACCEPT_CONN_REQ_CP_SIZE 7
301 #define OCF_REJECT_CONN_REQ 0x000a
305 } __attribute__ ((packed)) reject_conn_req_cp;
306 #define REJECT_CONN_REQ_CP_SIZE 7
308 #define OCF_DISCONNECT 0x0006
312 } __attribute__ ((packed)) disconnect_cp;
313 #define DISCONNECT_CP_SIZE 3
315 #define OCF_ADD_SCO 0x0007
319 } __attribute__ ((packed)) add_sco_cp;
320 #define ADD_SCO_CP_SIZE 4
322 #define OCF_INQUIRY 0x0001
327 } __attribute__ ((packed)) inquiry_cp;
328 #define INQUIRY_CP_SIZE 5
333 } __attribute__ ((packed)) status_bdaddr_rp;
334 #define STATUS_BDADDR_RP_SIZE 7
336 #define OCF_LINK_KEY_REPLY 0x000B
337 #define OCF_LINK_KEY_NEG_REPLY 0x000C
341 } __attribute__ ((packed)) link_key_reply_cp;
342 #define LINK_KEY_REPLY_CP_SIZE 22
344 #define OCF_PIN_CODE_REPLY 0x000D
345 #define OCF_PIN_CODE_NEG_REPLY 0x000E
350 } __attribute__ ((packed)) pin_code_reply_cp;
351 #define PIN_CODE_REPLY_CP_SIZE 23
353 #define OCF_CHANGE_CONN_PTYPE 0x000F
357 } __attribute__ ((packed)) change_conn_ptype_cp;
358 #define CHANGE_CONN_PTYPE_CP_SIZE 4
360 #define OCF_AUTH_REQUESTED 0x0011
363 } __attribute__ ((packed)) auth_requested_cp;
364 #define AUTH_REQUESTED_CP_SIZE 2
366 #define OCF_SET_CONN_ENCRYPT 0x0013
370 } __attribute__ ((packed)) set_conn_encrypt_cp;
371 #define SET_CONN_ENCRYPT_CP_SIZE 3
373 #define OCF_REMOTE_NAME_REQ 0x0019
379 } __attribute__ ((packed)) remote_name_req_cp;
380 #define REMOTE_NAME_REQ_CP_SIZE 10
382 #define OCF_READ_REMOTE_FEATURES 0x001B
385 } __attribute__ ((packed)) read_remote_features_cp;
386 #define READ_REMOTE_FEATURES_CP_SIZE 2
388 #define OCF_READ_REMOTE_VERSION 0x001D
391 } __attribute__ ((packed)) read_remote_version_cp;
392 #define READ_REMOTE_VERSION_CP_SIZE 2
395 #define OGF_LINK_POLICY 0x02
396 #define OCF_ROLE_DISCOVERY 0x0009
399 } __attribute__ ((packed)) role_discovery_cp;
400 #define ROLE_DISCOVERY_CP_SIZE 2
405 } __attribute__ ((packed)) role_discovery_rp;
406 #define ROLE_DISCOVERY_RP_SIZE 4
408 #define OCF_READ_LINK_POLICY 0x000C
411 } __attribute__ ((packed)) read_link_policy_cp;
412 #define READ_LINK_POLICY_CP_SIZE 2
417 } __attribute__ ((packed)) read_link_policy_rp;
418 #define READ_LINK_POLICY_RP_SIZE 5
420 #define OCF_SWITCH_ROLE 0x000B
424 } __attribute__ ((packed)) switch_role_cp;
425 #define SWITCH_ROLE_CP_SIZE 7
427 #define OCF_WRITE_LINK_POLICY 0x000D
431 } __attribute__ ((packed)) write_link_policy_cp;
432 #define WRITE_LINK_POLICY_CP_SIZE 4
436 } __attribute__ ((packed)) write_link_policy_rp;
437 #define WRITE_LINK_POLICY_RP_SIZE 3
440 #define OGF_STATUS_PARAM 0x05
442 /* ---- HCI Events ---- */
443 #define EVT_INQUIRY_COMPLETE 0x01
445 #define EVT_INQUIRY_RESULT 0x02
449 __u8 pscan_period_mode;
453 } __attribute__ ((packed)) inquiry_info;
454 #define INQUIRY_INFO_SIZE 14
456 #define EVT_CONN_COMPLETE 0x03
463 } __attribute__ ((packed)) evt_conn_complete;
464 #define EVT_CONN_COMPLETE_SIZE 13
466 #define EVT_CONN_REQUEST 0x04
471 } __attribute__ ((packed)) evt_conn_request;
472 #define EVT_CONN_REQUEST_SIZE 10
474 #define EVT_DISCONN_COMPLETE 0x05
479 } __attribute__ ((packed)) evt_disconn_complete;
480 #define EVT_DISCONN_COMPLETE_SIZE 4
482 #define EVT_AUTH_COMPLETE 0x06
486 } __attribute__ ((packed)) evt_auth_complete;
487 #define EVT_AUTH_COMPLETE_SIZE 3
489 #define EVT_REMOTE_NAME_REQ_COMPLETE 0x07
494 } __attribute__ ((packed)) evt_remote_name_req_complete;
495 #define EVT_REMOTE_NAME_REQ_COMPLETE_SIZE 255
497 #define EVT_ENCRYPT_CHANGE 0x08
502 } __attribute__ ((packed)) evt_encrypt_change;
503 #define EVT_ENCRYPT_CHANGE_SIZE 5
505 #define EVT_QOS_SETUP_COMPLETE 0x0D
509 __u32 peak_bandwidth;
511 __u32 delay_variation;
512 } __attribute__ ((packed)) hci_qos;
517 } __attribute__ ((packed)) evt_qos_setup_complete;
518 #define EVT_QOS_SETUP_COMPLETE_SIZE 20
520 #define EVT_CMD_COMPLETE 0x0e
524 } __attribute__ ((packed)) evt_cmd_complete;
525 #define EVT_CMD_COMPLETE_SIZE 3
527 #define EVT_CMD_STATUS 0x0f
532 } __attribute__ ((packed)) evt_cmd_status;
533 #define EVT_CMD_STATUS_SIZE 4
535 #define EVT_NUM_COMP_PKTS 0x13
538 /* variable length part */
539 } __attribute__ ((packed)) evt_num_comp_pkts;
540 #define EVT_NUM_COMP_PKTS_SIZE 1
542 #define EVT_ROLE_CHANGE 0x12
547 } __attribute__ ((packed)) evt_role_change;
548 #define EVT_ROLE_CHANGE_SIZE 8
550 #define EVT_PIN_CODE_REQ 0x16
553 } __attribute__ ((packed)) evt_pin_code_req;
554 #define EVT_PIN_CODE_REQ_SIZE 6
556 #define EVT_LINK_KEY_REQ 0x17
559 } __attribute__ ((packed)) evt_link_key_req;
560 #define EVT_LINK_KEY_REQ_SIZE 6
562 #define EVT_LINK_KEY_NOTIFY 0x18
567 } __attribute__ ((packed)) evt_link_key_notify;
568 #define EVT_LINK_KEY_NOTIFY_SIZE 23
570 #define EVT_READ_REMOTE_FEATURES_COMPLETE 0x0B
575 } __attribute__ ((packed)) evt_read_remote_features_complete;
576 #define EVT_READ_REMOTE_FEATURES_COMPLETE_SIZE 11
578 #define EVT_READ_REMOTE_VERSION_COMPLETE 0x0C
585 } __attribute__ ((packed)) evt_read_remote_version_complete;
586 #define EVT_READ_REMOTE_VERSION_COMPLETE_SIZE 8
588 /* Internal events generated by BlueZ stack */
589 #define EVT_STACK_INTERNAL 0xfd
593 } __attribute__ ((packed)) evt_stack_internal;
594 #define EVT_STACK_INTERNAL_SIZE 2
596 #define EVT_SI_DEVICE 0x01
600 } __attribute__ ((packed)) evt_si_device;
601 #define EVT_SI_DEVICE_SIZE 4
603 #define EVT_SI_SECURITY 0x02
609 } __attribute__ ((packed)) evt_si_security;
611 /* -------- HCI Packet structures -------- */
612 #define HCI_TYPE_LEN 1
615 __u16 opcode; /* OCF & OGF */
617 } __attribute__ ((packed)) hci_command_hdr;
618 #define HCI_COMMAND_HDR_SIZE 3
623 } __attribute__ ((packed)) hci_event_hdr;
624 #define HCI_EVENT_HDR_SIZE 2
627 __u16 handle; /* Handle & Flags(PB, BC) */
629 } __attribute__ ((packed)) hci_acl_hdr;
630 #define HCI_ACL_HDR_SIZE 4
635 } __attribute__ ((packed)) hci_sco_hdr;
636 #define HCI_SCO_HDR_SIZE 3
638 /* Command opcode pack/unpack */
639 #define cmd_opcode_pack(ogf, ocf) (__u16)((ocf & 0x03ff)|(ogf << 10))
640 #define cmd_opcode_ogf(op) (op >> 10)
641 #define cmd_opcode_ocf(op) (op & 0x03ff)
643 /* ACL handle and flags pack/unpack */
644 #define acl_handle_pack(h, f) (__u16)((h & 0x0fff)|(f << 12))
645 #define acl_handle(h) (h & 0x0fff)
646 #define acl_flags(h) (h >> 12)
648 /* HCI Socket options */
649 #define HCI_DATA_DIR 1
651 #define HCI_TIME_STAMP 3
654 #define HCI_CMSG_DIR 0x0001
655 #define HCI_CMSG_TSTAMP 0x0002
657 struct sockaddr_hci {
658 sa_family_t hci_family;
659 unsigned short hci_dev;
661 #define HCI_DEV_NONE 0xffff
669 #define HCI_FLT_TYPE_BITS 31
670 #define HCI_FLT_EVENT_BITS 63
671 #define HCI_FLT_OGF_BITS 63
672 #define HCI_FLT_OCF_BITS 127
674 #if BITS_PER_LONG == 64
675 static inline void hci_set_bit(int nr, void *addr)
677 *((__u32 *) addr + (nr >> 5)) |= ((__u32) 1 << (nr & 31));
679 static inline int hci_test_bit(int nr, void *addr)
681 return *((__u32 *) addr + (nr >> 5)) & ((__u32) 1 << (nr & 31));
684 #define hci_set_bit set_bit
685 #define hci_test_bit test_bit
688 /* Ioctl requests structures */
689 struct hci_dev_stats {
702 struct hci_dev_info {
722 struct hci_dev_stats stat;
725 struct hci_conn_info {
739 struct hci_dev_list_req {
741 struct hci_dev_req dev_req[0]; /* hci_dev_req structures */
744 struct hci_conn_list_req {
747 struct hci_conn_info conn_info[0];
750 struct hci_conn_info_req {
753 struct hci_conn_info conn_info[0];
756 struct hci_inquiry_req {
763 #define IREQ_CACHE_FLUSH 0x0001
765 struct hci_remotename_req {