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.
28 #define HCI_MAX_ACL_SIZE 1024
29 #define HCI_MAX_SCO_SIZE 255
30 #define HCI_MAX_EVENT_SIZE 260
31 #define HCI_MAX_FRAME_SIZE (HCI_MAX_ACL_SIZE + 4)
35 #define HCI_DEV_UNREG 2
37 #define HCI_DEV_DOWN 4
38 #define HCI_DEV_SUSPEND 5
39 #define HCI_DEV_RESUME 6
41 /* HCI notify events */
42 #define HCI_NOTIFY_CONN_ADD 1
43 #define HCI_NOTIFY_CONN_DEL 2
44 #define HCI_NOTIFY_VOICE_SETTING 3
46 /* HCI device types */
54 /* HCI device quirks */
56 HCI_QUIRK_RESET_ON_INIT,
58 HCI_QUIRK_FIXUP_BUFFER_SIZE
61 /* HCI device flags */
78 /* HCI ioctl defines */
79 #define HCIDEVUP _IOW('H', 201, int)
80 #define HCIDEVDOWN _IOW('H', 202, int)
81 #define HCIDEVRESET _IOW('H', 203, int)
82 #define HCIDEVRESTAT _IOW('H', 204, int)
84 #define HCIGETDEVLIST _IOR('H', 210, int)
85 #define HCIGETDEVINFO _IOR('H', 211, int)
86 #define HCIGETCONNLIST _IOR('H', 212, int)
87 #define HCIGETCONNINFO _IOR('H', 213, int)
89 #define HCISETRAW _IOW('H', 220, int)
90 #define HCISETSCAN _IOW('H', 221, int)
91 #define HCISETAUTH _IOW('H', 222, int)
92 #define HCISETENCRYPT _IOW('H', 223, int)
93 #define HCISETPTYPE _IOW('H', 224, int)
94 #define HCISETLINKPOL _IOW('H', 225, int)
95 #define HCISETLINKMODE _IOW('H', 226, int)
96 #define HCISETACLMTU _IOW('H', 227, int)
97 #define HCISETSCOMTU _IOW('H', 228, int)
99 #define HCISETSECMGR _IOW('H', 230, int)
101 #define HCIINQUIRY _IOR('H', 240, int)
104 #define HCI_CONNECT_TIMEOUT (40000) /* 40 seconds */
105 #define HCI_DISCONN_TIMEOUT (2000) /* 2 seconds */
106 #define HCI_IDLE_TIMEOUT (6000) /* 6 seconds */
107 #define HCI_INIT_TIMEOUT (10000) /* 10 seconds */
109 /* HCI Packet types */
110 #define HCI_COMMAND_PKT 0x01
111 #define HCI_ACLDATA_PKT 0x02
112 #define HCI_SCODATA_PKT 0x03
113 #define HCI_EVENT_PKT 0x04
114 #define HCI_VENDOR_PKT 0xff
116 /* HCI Packet types */
117 #define HCI_DM1 0x0008
118 #define HCI_DM3 0x0400
119 #define HCI_DM5 0x4000
120 #define HCI_DH1 0x0010
121 #define HCI_DH3 0x0800
122 #define HCI_DH5 0x8000
124 #define HCI_HV1 0x0020
125 #define HCI_HV2 0x0040
126 #define HCI_HV3 0x0080
128 #define SCO_PTYPE_MASK (HCI_HV1 | HCI_HV2 | HCI_HV3)
129 #define ACL_PTYPE_MASK (~SCO_PTYPE_MASK)
132 #define ACL_CONT 0x01
133 #define ACL_START 0x02
134 #define ACL_ACTIVE_BCAST 0x04
135 #define ACL_PICO_BCAST 0x08
138 #define SCO_LINK 0x00
139 #define ACL_LINK 0x01
142 #define LMP_3SLOT 0x01
143 #define LMP_5SLOT 0x02
144 #define LMP_ENCRYPT 0x04
145 #define LMP_SOFFSET 0x08
146 #define LMP_TACCURACY 0x10
147 #define LMP_RSWITCH 0x20
148 #define LMP_HOLD 0x40
149 #define LMP_SNIFF 0x80
151 #define LMP_PARK 0x01
152 #define LMP_RSSI 0x02
153 #define LMP_QUALITY 0x04
157 #define LMP_ULAW 0x40
158 #define LMP_ALAW 0x80
160 #define LMP_CVSD 0x01
161 #define LMP_PSCHEME 0x02
162 #define LMP_PCONTROL 0x04
164 #define LMP_SNIFF_SUBR 0x02
166 /* Connection modes */
167 #define HCI_CM_ACTIVE 0x0000
168 #define HCI_CM_HOLD 0x0001
169 #define HCI_CM_SNIFF 0x0002
170 #define HCI_CM_PARK 0x0003
173 #define HCI_LP_RSWITCH 0x0001
174 #define HCI_LP_HOLD 0x0002
175 #define HCI_LP_SNIFF 0x0004
176 #define HCI_LP_PARK 0x0008
179 #define HCI_LM_ACCEPT 0x8000
180 #define HCI_LM_MASTER 0x0001
181 #define HCI_LM_AUTH 0x0002
182 #define HCI_LM_ENCRYPT 0x0004
183 #define HCI_LM_TRUSTED 0x0008
184 #define HCI_LM_RELIABLE 0x0010
185 #define HCI_LM_SECURE 0x0020
187 /* ----- HCI Commands ---- */
188 /* OGF & OCF values */
190 /* Informational Parameters */
191 #define OGF_INFO_PARAM 0x04
193 #define OCF_READ_LOCAL_VERSION 0x0001
194 struct hci_rp_read_loc_version {
201 } __attribute__ ((packed));
203 #define OCF_READ_LOCAL_FEATURES 0x0003
204 struct hci_rp_read_local_features {
207 } __attribute__ ((packed));
209 #define OCF_READ_BUFFER_SIZE 0x0005
210 struct hci_rp_read_buffer_size {
216 } __attribute__ ((packed));
218 #define OCF_READ_BD_ADDR 0x0009
219 struct hci_rp_read_bd_addr {
222 } __attribute__ ((packed));
224 /* Host Controller and Baseband */
225 #define OGF_HOST_CTL 0x03
226 #define OCF_RESET 0x0003
227 #define OCF_READ_AUTH_ENABLE 0x001F
228 #define OCF_WRITE_AUTH_ENABLE 0x0020
229 #define AUTH_DISABLED 0x00
230 #define AUTH_ENABLED 0x01
232 #define OCF_READ_ENCRYPT_MODE 0x0021
233 #define OCF_WRITE_ENCRYPT_MODE 0x0022
234 #define ENCRYPT_DISABLED 0x00
235 #define ENCRYPT_P2P 0x01
236 #define ENCRYPT_BOTH 0x02
238 #define OCF_WRITE_CA_TIMEOUT 0x0016
239 #define OCF_WRITE_PG_TIMEOUT 0x0018
241 #define OCF_WRITE_SCAN_ENABLE 0x001A
242 #define SCAN_DISABLED 0x00
243 #define SCAN_INQUIRY 0x01
244 #define SCAN_PAGE 0x02
246 #define OCF_SET_EVENT_FLT 0x0005
247 struct hci_cp_set_event_flt {
251 } __attribute__ ((packed));
254 #define HCI_FLT_CLEAR_ALL 0x00
255 #define HCI_FLT_INQ_RESULT 0x01
256 #define HCI_FLT_CONN_SETUP 0x02
258 /* CONN_SETUP Condition types */
259 #define HCI_CONN_SETUP_ALLOW_ALL 0x00
260 #define HCI_CONN_SETUP_ALLOW_CLASS 0x01
261 #define HCI_CONN_SETUP_ALLOW_BDADDR 0x02
263 /* CONN_SETUP Conditions */
264 #define HCI_CONN_SETUP_AUTO_OFF 0x01
265 #define HCI_CONN_SETUP_AUTO_ON 0x02
267 #define OCF_READ_CLASS_OF_DEV 0x0023
268 struct hci_rp_read_dev_class {
271 } __attribute__ ((packed));
273 #define OCF_WRITE_CLASS_OF_DEV 0x0024
274 struct hci_cp_write_dev_class {
276 } __attribute__ ((packed));
278 #define OCF_READ_VOICE_SETTING 0x0025
279 struct hci_rp_read_voice_setting {
281 __le16 voice_setting;
282 } __attribute__ ((packed));
284 #define OCF_WRITE_VOICE_SETTING 0x0026
285 struct hci_cp_write_voice_setting {
286 __le16 voice_setting;
287 } __attribute__ ((packed));
289 #define OCF_HOST_BUFFER_SIZE 0x0033
290 struct hci_cp_host_buffer_size {
295 } __attribute__ ((packed));
298 #define OGF_LINK_CTL 0x01
299 #define OCF_CREATE_CONN 0x0005
300 struct hci_cp_create_conn {
307 } __attribute__ ((packed));
309 #define OCF_ACCEPT_CONN_REQ 0x0009
310 struct hci_cp_accept_conn_req {
313 } __attribute__ ((packed));
315 #define OCF_REJECT_CONN_REQ 0x000a
316 struct hci_cp_reject_conn_req {
319 } __attribute__ ((packed));
321 #define OCF_DISCONNECT 0x0006
322 struct hci_cp_disconnect {
325 } __attribute__ ((packed));
327 #define OCF_ADD_SCO 0x0007
328 struct hci_cp_add_sco {
331 } __attribute__ ((packed));
333 #define OCF_INQUIRY 0x0001
334 struct hci_cp_inquiry {
338 } __attribute__ ((packed));
340 #define OCF_INQUIRY_CANCEL 0x0002
342 #define OCF_LINK_KEY_REPLY 0x000B
343 struct hci_cp_link_key_reply {
346 } __attribute__ ((packed));
348 #define OCF_LINK_KEY_NEG_REPLY 0x000C
349 struct hci_cp_link_key_neg_reply {
351 } __attribute__ ((packed));
353 #define OCF_PIN_CODE_REPLY 0x000D
354 struct hci_cp_pin_code_reply {
358 } __attribute__ ((packed));
360 #define OCF_PIN_CODE_NEG_REPLY 0x000E
361 struct hci_cp_pin_code_neg_reply {
363 } __attribute__ ((packed));
365 #define OCF_CHANGE_CONN_PTYPE 0x000F
366 struct hci_cp_change_conn_ptype {
369 } __attribute__ ((packed));
371 #define OCF_AUTH_REQUESTED 0x0011
372 struct hci_cp_auth_requested {
374 } __attribute__ ((packed));
376 #define OCF_SET_CONN_ENCRYPT 0x0013
377 struct hci_cp_set_conn_encrypt {
380 } __attribute__ ((packed));
382 #define OCF_CHANGE_CONN_LINK_KEY 0x0015
383 struct hci_cp_change_conn_link_key {
385 } __attribute__ ((packed));
387 #define OCF_READ_REMOTE_FEATURES 0x001B
388 struct hci_cp_read_remote_features {
390 } __attribute__ ((packed));
392 #define OCF_READ_REMOTE_VERSION 0x001D
393 struct hci_cp_read_remote_version {
395 } __attribute__ ((packed));
398 #define OGF_LINK_POLICY 0x02
400 #define OCF_SNIFF_MODE 0x0003
401 struct hci_cp_sniff_mode {
407 } __attribute__ ((packed));
409 #define OCF_EXIT_SNIFF_MODE 0x0004
410 struct hci_cp_exit_sniff_mode {
412 } __attribute__ ((packed));
414 #define OCF_ROLE_DISCOVERY 0x0009
415 struct hci_cp_role_discovery {
417 } __attribute__ ((packed));
418 struct hci_rp_role_discovery {
422 } __attribute__ ((packed));
424 #define OCF_READ_LINK_POLICY 0x000C
425 struct hci_cp_read_link_policy {
427 } __attribute__ ((packed));
428 struct hci_rp_read_link_policy {
432 } __attribute__ ((packed));
434 #define OCF_SWITCH_ROLE 0x000B
435 struct hci_cp_switch_role {
438 } __attribute__ ((packed));
440 #define OCF_WRITE_LINK_POLICY 0x000D
441 struct hci_cp_write_link_policy {
444 } __attribute__ ((packed));
445 struct hci_rp_write_link_policy {
448 } __attribute__ ((packed));
450 #define OCF_SNIFF_SUBRATE 0x0011
451 struct hci_cp_sniff_subrate {
454 __le16 min_remote_timeout;
455 __le16 min_local_timeout;
456 } __attribute__ ((packed));
459 #define OGF_STATUS_PARAM 0x05
461 /* Testing commands */
462 #define OGF_TESTING_CMD 0x3E
464 /* Vendor specific commands */
465 #define OGF_VENDOR_CMD 0x3F
467 /* ---- HCI Events ---- */
468 #define HCI_EV_INQUIRY_COMPLETE 0x01
470 #define HCI_EV_INQUIRY_RESULT 0x02
471 struct inquiry_info {
474 __u8 pscan_period_mode;
478 } __attribute__ ((packed));
480 #define HCI_EV_INQUIRY_RESULT_WITH_RSSI 0x22
481 struct inquiry_info_with_rssi {
484 __u8 pscan_period_mode;
488 } __attribute__ ((packed));
489 struct inquiry_info_with_rssi_and_pscan_mode {
492 __u8 pscan_period_mode;
497 } __attribute__ ((packed));
499 #define HCI_EV_EXTENDED_INQUIRY_RESULT 0x2F
500 struct extended_inquiry_info {
503 __u8 pscan_period_mode;
508 } __attribute__ ((packed));
510 #define HCI_EV_CONN_COMPLETE 0x03
511 struct hci_ev_conn_complete {
517 } __attribute__ ((packed));
519 #define HCI_EV_CONN_REQUEST 0x04
520 struct hci_ev_conn_request {
524 } __attribute__ ((packed));
526 #define HCI_EV_DISCONN_COMPLETE 0x05
527 struct hci_ev_disconn_complete {
531 } __attribute__ ((packed));
533 #define HCI_EV_AUTH_COMPLETE 0x06
534 struct hci_ev_auth_complete {
537 } __attribute__ ((packed));
539 #define HCI_EV_ENCRYPT_CHANGE 0x08
540 struct hci_ev_encrypt_change {
544 } __attribute__ ((packed));
546 #define HCI_EV_CHANGE_CONN_LINK_KEY_COMPLETE 0x09
547 struct hci_ev_change_conn_link_key_complete {
550 } __attribute__ ((packed));
552 #define HCI_EV_QOS_SETUP_COMPLETE 0x0D
556 __u32 peak_bandwidth;
558 __u32 delay_variation;
559 } __attribute__ ((packed));
560 struct hci_ev_qos_setup_complete {
564 } __attribute__ ((packed));
566 #define HCI_EV_CMD_COMPLETE 0x0E
567 struct hci_ev_cmd_complete {
570 } __attribute__ ((packed));
572 #define HCI_EV_CMD_STATUS 0x0F
573 struct hci_ev_cmd_status {
577 } __attribute__ ((packed));
579 #define HCI_EV_NUM_COMP_PKTS 0x13
580 struct hci_ev_num_comp_pkts {
582 /* variable length part */
583 } __attribute__ ((packed));
585 #define HCI_EV_ROLE_CHANGE 0x12
586 struct hci_ev_role_change {
590 } __attribute__ ((packed));
592 #define HCI_EV_MODE_CHANGE 0x14
593 struct hci_ev_mode_change {
598 } __attribute__ ((packed));
600 #define HCI_EV_PIN_CODE_REQ 0x16
601 struct hci_ev_pin_code_req {
603 } __attribute__ ((packed));
605 #define HCI_EV_LINK_KEY_REQ 0x17
606 struct hci_ev_link_key_req {
608 } __attribute__ ((packed));
610 #define HCI_EV_LINK_KEY_NOTIFY 0x18
611 struct hci_ev_link_key_notify {
615 } __attribute__ ((packed));
617 #define HCI_EV_REMOTE_FEATURES 0x0B
618 struct hci_ev_remote_features {
622 } __attribute__ ((packed));
624 #define HCI_EV_REMOTE_VERSION 0x0C
625 struct hci_ev_remote_version {
631 } __attribute__ ((packed));
633 #define HCI_EV_CLOCK_OFFSET 0x01C
634 struct hci_ev_clock_offset {
638 } __attribute__ ((packed));
640 #define HCI_EV_PSCAN_REP_MODE 0x20
641 struct hci_ev_pscan_rep_mode {
644 } __attribute__ ((packed));
646 #define HCI_EV_SNIFF_SUBRATE 0x2E
647 struct hci_ev_sniff_subrate {
650 __le16 max_tx_latency;
651 __le16 max_rx_latency;
652 __le16 max_remote_timeout;
653 __le16 max_local_timeout;
654 } __attribute__ ((packed));
656 /* Internal events generated by Bluetooth stack */
657 #define HCI_EV_STACK_INTERNAL 0xFD
658 struct hci_ev_stack_internal {
661 } __attribute__ ((packed));
663 #define HCI_EV_SI_DEVICE 0x01
664 struct hci_ev_si_device {
667 } __attribute__ ((packed));
669 #define HCI_EV_SI_SECURITY 0x02
670 struct hci_ev_si_security {
675 } __attribute__ ((packed));
677 /* ---- HCI Packet structures ---- */
678 #define HCI_COMMAND_HDR_SIZE 3
679 #define HCI_EVENT_HDR_SIZE 2
680 #define HCI_ACL_HDR_SIZE 4
681 #define HCI_SCO_HDR_SIZE 3
683 struct hci_command_hdr {
684 __le16 opcode; /* OCF & OGF */
686 } __attribute__ ((packed));
688 struct hci_event_hdr {
691 } __attribute__ ((packed));
694 __le16 handle; /* Handle & Flags(PB, BC) */
696 } __attribute__ ((packed));
701 } __attribute__ ((packed));
703 /* Command opcode pack/unpack */
704 #define hci_opcode_pack(ogf, ocf) (__u16) ((ocf & 0x03ff)|(ogf << 10))
705 #define hci_opcode_ogf(op) (op >> 10)
706 #define hci_opcode_ocf(op) (op & 0x03ff)
708 /* ACL handle and flags pack/unpack */
709 #define hci_handle_pack(h, f) (__u16) ((h & 0x0fff)|(f << 12))
710 #define hci_handle(h) (h & 0x0fff)
711 #define hci_flags(h) (h >> 12)
713 /* ---- HCI Sockets ---- */
716 #define HCI_DATA_DIR 1
718 #define HCI_TIME_STAMP 3
721 #define HCI_CMSG_DIR 0x0001
722 #define HCI_CMSG_TSTAMP 0x0002
724 struct sockaddr_hci {
725 sa_family_t hci_family;
726 unsigned short hci_dev;
728 #define HCI_DEV_NONE 0xffff
731 unsigned long type_mask;
732 unsigned long event_mask[2];
742 #define HCI_FLT_TYPE_BITS 31
743 #define HCI_FLT_EVENT_BITS 63
744 #define HCI_FLT_OGF_BITS 63
745 #define HCI_FLT_OCF_BITS 127
747 /* ---- HCI Ioctl requests structures ---- */
748 struct hci_dev_stats {
761 struct hci_dev_info {
781 struct hci_dev_stats stat;
784 struct hci_conn_info {
798 struct hci_dev_list_req {
800 struct hci_dev_req dev_req[0]; /* hci_dev_req structures */
803 struct hci_conn_list_req {
806 struct hci_conn_info conn_info[0];
809 struct hci_conn_info_req {
812 struct hci_conn_info conn_info[0];
815 struct hci_inquiry_req {
822 #define IREQ_CACHE_FLUSH 0x0001