9ce46cd00ba22563ddff5b7f617bcdd9cb1c47c1
[pandora-kernel.git] / include / net / bluetooth / hci.h
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 #ifndef __HCI_H
26 #define __HCI_H
27
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)
32
33 /* HCI dev events */
34 #define HCI_DEV_REG                     1
35 #define HCI_DEV_UNREG                   2
36 #define HCI_DEV_UP                      3
37 #define HCI_DEV_DOWN                    4
38 #define HCI_DEV_SUSPEND                 5
39 #define HCI_DEV_RESUME                  6
40
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
45
46 /* HCI bus types */
47 #define HCI_VIRTUAL     0
48 #define HCI_USB         1
49 #define HCI_PCCARD      2
50 #define HCI_UART        3
51 #define HCI_RS232       4
52 #define HCI_PCI         5
53 #define HCI_SDIO        6
54
55 /* HCI controller types */
56 #define HCI_BREDR       0x00
57 #define HCI_AMP         0x01
58
59 /* HCI device quirks */
60 enum {
61         HCI_QUIRK_NO_RESET,
62         HCI_QUIRK_RAW_DEVICE,
63         HCI_QUIRK_FIXUP_BUFFER_SIZE
64 };
65
66 /* HCI device flags */
67 enum {
68         HCI_UP,
69         HCI_INIT,
70         HCI_RUNNING,
71
72         HCI_PSCAN,
73         HCI_ISCAN,
74         HCI_AUTH,
75         HCI_ENCRYPT,
76         HCI_INQUIRY,
77
78         HCI_RAW,
79
80         HCI_SETUP,
81         HCI_AUTO_OFF,
82         HCI_MGMT,
83         HCI_PAIRABLE,
84         HCI_SERVICE_CACHE,
85 };
86
87 /* HCI ioctl defines */
88 #define HCIDEVUP        _IOW('H', 201, int)
89 #define HCIDEVDOWN      _IOW('H', 202, int)
90 #define HCIDEVRESET     _IOW('H', 203, int)
91 #define HCIDEVRESTAT    _IOW('H', 204, int)
92
93 #define HCIGETDEVLIST   _IOR('H', 210, int)
94 #define HCIGETDEVINFO   _IOR('H', 211, int)
95 #define HCIGETCONNLIST  _IOR('H', 212, int)
96 #define HCIGETCONNINFO  _IOR('H', 213, int)
97 #define HCIGETAUTHINFO  _IOR('H', 215, int)
98
99 #define HCISETRAW       _IOW('H', 220, int)
100 #define HCISETSCAN      _IOW('H', 221, int)
101 #define HCISETAUTH      _IOW('H', 222, int)
102 #define HCISETENCRYPT   _IOW('H', 223, int)
103 #define HCISETPTYPE     _IOW('H', 224, int)
104 #define HCISETLINKPOL   _IOW('H', 225, int)
105 #define HCISETLINKMODE  _IOW('H', 226, int)
106 #define HCISETACLMTU    _IOW('H', 227, int)
107 #define HCISETSCOMTU    _IOW('H', 228, int)
108
109 #define HCIBLOCKADDR    _IOW('H', 230, int)
110 #define HCIUNBLOCKADDR  _IOW('H', 231, int)
111
112 #define HCIINQUIRY      _IOR('H', 240, int)
113
114 /* HCI timeouts */
115 #define HCI_CONNECT_TIMEOUT     (40000) /* 40 seconds */
116 #define HCI_DISCONN_TIMEOUT     (2000)  /* 2 seconds */
117 #define HCI_PAIRING_TIMEOUT     (60000) /* 60 seconds */
118 #define HCI_IDLE_TIMEOUT        (6000)  /* 6 seconds */
119 #define HCI_INIT_TIMEOUT        (10000) /* 10 seconds */
120
121 /* HCI data types */
122 #define HCI_COMMAND_PKT         0x01
123 #define HCI_ACLDATA_PKT         0x02
124 #define HCI_SCODATA_PKT         0x03
125 #define HCI_EVENT_PKT           0x04
126 #define HCI_VENDOR_PKT          0xff
127
128 /* HCI packet types */
129 #define HCI_DM1         0x0008
130 #define HCI_DM3         0x0400
131 #define HCI_DM5         0x4000
132 #define HCI_DH1         0x0010
133 #define HCI_DH3         0x0800
134 #define HCI_DH5         0x8000
135
136 #define HCI_HV1         0x0020
137 #define HCI_HV2         0x0040
138 #define HCI_HV3         0x0080
139
140 #define SCO_PTYPE_MASK  (HCI_HV1 | HCI_HV2 | HCI_HV3)
141 #define ACL_PTYPE_MASK  (~SCO_PTYPE_MASK)
142
143 /* eSCO packet types */
144 #define ESCO_HV1        0x0001
145 #define ESCO_HV2        0x0002
146 #define ESCO_HV3        0x0004
147 #define ESCO_EV3        0x0008
148 #define ESCO_EV4        0x0010
149 #define ESCO_EV5        0x0020
150 #define ESCO_2EV3       0x0040
151 #define ESCO_3EV3       0x0080
152 #define ESCO_2EV5       0x0100
153 #define ESCO_3EV5       0x0200
154
155 #define SCO_ESCO_MASK  (ESCO_HV1 | ESCO_HV2 | ESCO_HV3)
156 #define EDR_ESCO_MASK  (ESCO_2EV3 | ESCO_3EV3 | ESCO_2EV5 | ESCO_3EV5)
157
158 /* ACL flags */
159 #define ACL_START_NO_FLUSH      0x00
160 #define ACL_CONT                0x01
161 #define ACL_START               0x02
162 #define ACL_ACTIVE_BCAST        0x04
163 #define ACL_PICO_BCAST          0x08
164
165 /* Baseband links */
166 #define SCO_LINK        0x00
167 #define ACL_LINK        0x01
168 #define ESCO_LINK       0x02
169
170 /* LMP features */
171 #define LMP_3SLOT       0x01
172 #define LMP_5SLOT       0x02
173 #define LMP_ENCRYPT     0x04
174 #define LMP_SOFFSET     0x08
175 #define LMP_TACCURACY   0x10
176 #define LMP_RSWITCH     0x20
177 #define LMP_HOLD        0x40
178 #define LMP_SNIFF       0x80
179
180 #define LMP_PARK        0x01
181 #define LMP_RSSI        0x02
182 #define LMP_QUALITY     0x04
183 #define LMP_SCO         0x08
184 #define LMP_HV2         0x10
185 #define LMP_HV3         0x20
186 #define LMP_ULAW        0x40
187 #define LMP_ALAW        0x80
188
189 #define LMP_CVSD        0x01
190 #define LMP_PSCHEME     0x02
191 #define LMP_PCONTROL    0x04
192
193 #define LMP_RSSI_INQ    0x40
194 #define LMP_ESCO        0x80
195
196 #define LMP_EV4         0x01
197 #define LMP_EV5         0x02
198 #define LMP_LE          0x40
199
200 #define LMP_SNIFF_SUBR  0x02
201 #define LMP_PAUSE_ENC   0x04
202 #define LMP_EDR_ESCO_2M 0x20
203 #define LMP_EDR_ESCO_3M 0x40
204 #define LMP_EDR_3S_ESCO 0x80
205
206 #define LMP_EXT_INQ     0x01
207 #define LMP_SIMPLE_PAIR 0x08
208 #define LMP_NO_FLUSH    0x40
209
210 #define LMP_LSTO        0x01
211 #define LMP_INQ_TX_PWR  0x02
212
213 /* Connection modes */
214 #define HCI_CM_ACTIVE   0x0000
215 #define HCI_CM_HOLD     0x0001
216 #define HCI_CM_SNIFF    0x0002
217 #define HCI_CM_PARK     0x0003
218
219 /* Link policies */
220 #define HCI_LP_RSWITCH  0x0001
221 #define HCI_LP_HOLD     0x0002
222 #define HCI_LP_SNIFF    0x0004
223 #define HCI_LP_PARK     0x0008
224
225 /* Link modes */
226 #define HCI_LM_ACCEPT   0x8000
227 #define HCI_LM_MASTER   0x0001
228 #define HCI_LM_AUTH     0x0002
229 #define HCI_LM_ENCRYPT  0x0004
230 #define HCI_LM_TRUSTED  0x0008
231 #define HCI_LM_RELIABLE 0x0010
232 #define HCI_LM_SECURE   0x0020
233
234 /* Authentication types */
235 #define HCI_AT_NO_BONDING               0x00
236 #define HCI_AT_NO_BONDING_MITM          0x01
237 #define HCI_AT_DEDICATED_BONDING        0x02
238 #define HCI_AT_DEDICATED_BONDING_MITM   0x03
239 #define HCI_AT_GENERAL_BONDING          0x04
240 #define HCI_AT_GENERAL_BONDING_MITM     0x05
241
242 /* -----  HCI Commands ---- */
243 #define HCI_OP_INQUIRY                  0x0401
244 struct hci_cp_inquiry {
245         __u8     lap[3];
246         __u8     length;
247         __u8     num_rsp;
248 } __packed;
249
250 #define HCI_OP_INQUIRY_CANCEL           0x0402
251
252 #define HCI_OP_EXIT_PERIODIC_INQ        0x0404
253
254 #define HCI_OP_CREATE_CONN              0x0405
255 struct hci_cp_create_conn {
256         bdaddr_t bdaddr;
257         __le16   pkt_type;
258         __u8     pscan_rep_mode;
259         __u8     pscan_mode;
260         __le16   clock_offset;
261         __u8     role_switch;
262 } __packed;
263
264 #define HCI_OP_DISCONNECT               0x0406
265 struct hci_cp_disconnect {
266         __le16   handle;
267         __u8     reason;
268 } __packed;
269
270 #define HCI_OP_ADD_SCO                  0x0407
271 struct hci_cp_add_sco {
272         __le16   handle;
273         __le16   pkt_type;
274 } __packed;
275
276 #define HCI_OP_CREATE_CONN_CANCEL       0x0408
277 struct hci_cp_create_conn_cancel {
278         bdaddr_t bdaddr;
279 } __packed;
280
281 #define HCI_OP_ACCEPT_CONN_REQ          0x0409
282 struct hci_cp_accept_conn_req {
283         bdaddr_t bdaddr;
284         __u8     role;
285 } __packed;
286
287 #define HCI_OP_REJECT_CONN_REQ          0x040a
288 struct hci_cp_reject_conn_req {
289         bdaddr_t bdaddr;
290         __u8     reason;
291 } __packed;
292
293 #define HCI_OP_LINK_KEY_REPLY           0x040b
294 struct hci_cp_link_key_reply {
295         bdaddr_t bdaddr;
296         __u8     link_key[16];
297 } __packed;
298
299 #define HCI_OP_LINK_KEY_NEG_REPLY       0x040c
300 struct hci_cp_link_key_neg_reply {
301         bdaddr_t bdaddr;
302 } __packed;
303
304 #define HCI_OP_PIN_CODE_REPLY           0x040d
305 struct hci_cp_pin_code_reply {
306         bdaddr_t bdaddr;
307         __u8     pin_len;
308         __u8     pin_code[16];
309 } __packed;
310
311 #define HCI_OP_PIN_CODE_NEG_REPLY       0x040e
312 struct hci_cp_pin_code_neg_reply {
313         bdaddr_t bdaddr;
314 } __packed;
315
316 #define HCI_OP_CHANGE_CONN_PTYPE        0x040f
317 struct hci_cp_change_conn_ptype {
318         __le16   handle;
319         __le16   pkt_type;
320 } __packed;
321
322 #define HCI_OP_AUTH_REQUESTED           0x0411
323 struct hci_cp_auth_requested {
324         __le16   handle;
325 } __packed;
326
327 #define HCI_OP_SET_CONN_ENCRYPT         0x0413
328 struct hci_cp_set_conn_encrypt {
329         __le16   handle;
330         __u8     encrypt;
331 } __packed;
332
333 #define HCI_OP_CHANGE_CONN_LINK_KEY     0x0415
334 struct hci_cp_change_conn_link_key {
335         __le16   handle;
336 } __packed;
337
338 #define HCI_OP_REMOTE_NAME_REQ          0x0419
339 struct hci_cp_remote_name_req {
340         bdaddr_t bdaddr;
341         __u8     pscan_rep_mode;
342         __u8     pscan_mode;
343         __le16   clock_offset;
344 } __packed;
345
346 #define HCI_OP_REMOTE_NAME_REQ_CANCEL   0x041a
347 struct hci_cp_remote_name_req_cancel {
348         bdaddr_t bdaddr;
349 } __packed;
350
351 #define HCI_OP_READ_REMOTE_FEATURES     0x041b
352 struct hci_cp_read_remote_features {
353         __le16   handle;
354 } __packed;
355
356 #define HCI_OP_READ_REMOTE_EXT_FEATURES 0x041c
357 struct hci_cp_read_remote_ext_features {
358         __le16   handle;
359         __u8     page;
360 } __packed;
361
362 #define HCI_OP_READ_REMOTE_VERSION      0x041d
363 struct hci_cp_read_remote_version {
364         __le16   handle;
365 } __packed;
366
367 #define HCI_OP_SETUP_SYNC_CONN          0x0428
368 struct hci_cp_setup_sync_conn {
369         __le16   handle;
370         __le32   tx_bandwidth;
371         __le32   rx_bandwidth;
372         __le16   max_latency;
373         __le16   voice_setting;
374         __u8     retrans_effort;
375         __le16   pkt_type;
376 } __packed;
377
378 #define HCI_OP_ACCEPT_SYNC_CONN_REQ     0x0429
379 struct hci_cp_accept_sync_conn_req {
380         bdaddr_t bdaddr;
381         __le32   tx_bandwidth;
382         __le32   rx_bandwidth;
383         __le16   max_latency;
384         __le16   content_format;
385         __u8     retrans_effort;
386         __le16   pkt_type;
387 } __packed;
388
389 #define HCI_OP_REJECT_SYNC_CONN_REQ     0x042a
390 struct hci_cp_reject_sync_conn_req {
391         bdaddr_t bdaddr;
392         __u8     reason;
393 } __packed;
394
395 #define HCI_OP_IO_CAPABILITY_NEG_REPLY  0x0434
396 struct hci_cp_io_capability_neg_reply {
397         bdaddr_t bdaddr;
398         __u8     reason;
399 } __packed;
400
401 #define HCI_OP_SNIFF_MODE               0x0803
402 struct hci_cp_sniff_mode {
403         __le16   handle;
404         __le16   max_interval;
405         __le16   min_interval;
406         __le16   attempt;
407         __le16   timeout;
408 } __packed;
409
410 #define HCI_OP_EXIT_SNIFF_MODE          0x0804
411 struct hci_cp_exit_sniff_mode {
412         __le16   handle;
413 } __packed;
414
415 #define HCI_OP_ROLE_DISCOVERY           0x0809
416 struct hci_cp_role_discovery {
417         __le16   handle;
418 } __packed;
419 struct hci_rp_role_discovery {
420         __u8     status;
421         __le16   handle;
422         __u8     role;
423 } __packed;
424
425 #define HCI_OP_SWITCH_ROLE              0x080b
426 struct hci_cp_switch_role {
427         bdaddr_t bdaddr;
428         __u8     role;
429 } __packed;
430
431 #define HCI_OP_READ_LINK_POLICY         0x080c
432 struct hci_cp_read_link_policy {
433         __le16   handle;
434 } __packed;
435 struct hci_rp_read_link_policy {
436         __u8     status;
437         __le16   handle;
438         __le16   policy;
439 } __packed;
440
441 #define HCI_OP_WRITE_LINK_POLICY        0x080d
442 struct hci_cp_write_link_policy {
443         __le16   handle;
444         __le16   policy;
445 } __packed;
446 struct hci_rp_write_link_policy {
447         __u8     status;
448         __le16   handle;
449 } __packed;
450
451 #define HCI_OP_READ_DEF_LINK_POLICY     0x080e
452 struct hci_rp_read_def_link_policy {
453         __u8     status;
454         __le16   policy;
455 } __packed;
456
457 #define HCI_OP_WRITE_DEF_LINK_POLICY    0x080f
458 struct hci_cp_write_def_link_policy {
459         __le16   policy;
460 } __packed;
461
462 #define HCI_OP_SNIFF_SUBRATE            0x0811
463 struct hci_cp_sniff_subrate {
464         __le16   handle;
465         __le16   max_latency;
466         __le16   min_remote_timeout;
467         __le16   min_local_timeout;
468 } __packed;
469
470 #define HCI_OP_SET_EVENT_MASK           0x0c01
471 struct hci_cp_set_event_mask {
472         __u8     mask[8];
473 } __packed;
474
475 #define HCI_OP_RESET                    0x0c03
476
477 #define HCI_OP_SET_EVENT_FLT            0x0c05
478 struct hci_cp_set_event_flt {
479         __u8     flt_type;
480         __u8     cond_type;
481         __u8     condition[0];
482 } __packed;
483
484 /* Filter types */
485 #define HCI_FLT_CLEAR_ALL       0x00
486 #define HCI_FLT_INQ_RESULT      0x01
487 #define HCI_FLT_CONN_SETUP      0x02
488
489 /* CONN_SETUP Condition types */
490 #define HCI_CONN_SETUP_ALLOW_ALL        0x00
491 #define HCI_CONN_SETUP_ALLOW_CLASS      0x01
492 #define HCI_CONN_SETUP_ALLOW_BDADDR     0x02
493
494 /* CONN_SETUP Conditions */
495 #define HCI_CONN_SETUP_AUTO_OFF 0x01
496 #define HCI_CONN_SETUP_AUTO_ON  0x02
497
498 #define HCI_OP_DELETE_STORED_LINK_KEY   0x0c12
499 struct hci_cp_delete_stored_link_key {
500         bdaddr_t bdaddr;
501         __u8     delete_all;
502 } __packed;
503
504 #define HCI_OP_WRITE_LOCAL_NAME         0x0c13
505 struct hci_cp_write_local_name {
506         __u8     name[248];
507 } __packed;
508
509 #define HCI_OP_READ_LOCAL_NAME          0x0c14
510 struct hci_rp_read_local_name {
511         __u8     status;
512         __u8     name[248];
513 } __packed;
514
515 #define HCI_OP_WRITE_CA_TIMEOUT         0x0c16
516
517 #define HCI_OP_WRITE_PG_TIMEOUT         0x0c18
518
519 #define HCI_OP_WRITE_SCAN_ENABLE        0x0c1a
520         #define SCAN_DISABLED           0x00
521         #define SCAN_INQUIRY            0x01
522         #define SCAN_PAGE               0x02
523
524 #define HCI_OP_READ_AUTH_ENABLE         0x0c1f
525
526 #define HCI_OP_WRITE_AUTH_ENABLE        0x0c20
527         #define AUTH_DISABLED           0x00
528         #define AUTH_ENABLED            0x01
529
530 #define HCI_OP_READ_ENCRYPT_MODE        0x0c21
531
532 #define HCI_OP_WRITE_ENCRYPT_MODE       0x0c22
533         #define ENCRYPT_DISABLED        0x00
534         #define ENCRYPT_P2P             0x01
535         #define ENCRYPT_BOTH            0x02
536
537 #define HCI_OP_READ_CLASS_OF_DEV        0x0c23
538 struct hci_rp_read_class_of_dev {
539         __u8     status;
540         __u8     dev_class[3];
541 } __packed;
542
543 #define HCI_OP_WRITE_CLASS_OF_DEV       0x0c24
544 struct hci_cp_write_class_of_dev {
545         __u8     dev_class[3];
546 } __packed;
547
548 #define HCI_OP_READ_VOICE_SETTING       0x0c25
549 struct hci_rp_read_voice_setting {
550         __u8     status;
551         __le16   voice_setting;
552 } __packed;
553
554 #define HCI_OP_WRITE_VOICE_SETTING      0x0c26
555 struct hci_cp_write_voice_setting {
556         __le16   voice_setting;
557 } __packed;
558
559 #define HCI_OP_HOST_BUFFER_SIZE         0x0c33
560 struct hci_cp_host_buffer_size {
561         __le16   acl_mtu;
562         __u8     sco_mtu;
563         __le16   acl_max_pkt;
564         __le16   sco_max_pkt;
565 } __packed;
566
567 #define HCI_OP_WRITE_INQUIRY_MODE       0x0c45
568
569 #define HCI_OP_READ_SSP_MODE            0x0c55
570 struct hci_rp_read_ssp_mode {
571         __u8     status;
572         __u8     mode;
573 } __packed;
574
575 #define HCI_OP_WRITE_SSP_MODE           0x0c56
576 struct hci_cp_write_ssp_mode {
577         __u8     mode;
578 } __packed;
579
580 #define HCI_OP_READ_INQ_RSP_TX_POWER    0x0c58
581
582 #define HCI_OP_READ_LOCAL_VERSION       0x1001
583 struct hci_rp_read_local_version {
584         __u8     status;
585         __u8     hci_ver;
586         __le16   hci_rev;
587         __u8     lmp_ver;
588         __le16   manufacturer;
589         __le16   lmp_subver;
590 } __packed;
591
592 #define HCI_OP_READ_LOCAL_COMMANDS      0x1002
593 struct hci_rp_read_local_commands {
594         __u8     status;
595         __u8     commands[64];
596 } __packed;
597
598 #define HCI_OP_READ_LOCAL_FEATURES      0x1003
599 struct hci_rp_read_local_features {
600         __u8     status;
601         __u8     features[8];
602 } __packed;
603
604 #define HCI_OP_READ_LOCAL_EXT_FEATURES  0x1004
605 struct hci_rp_read_local_ext_features {
606         __u8     status;
607         __u8     page;
608         __u8     max_page;
609         __u8     features[8];
610 } __packed;
611
612 #define HCI_OP_READ_BUFFER_SIZE         0x1005
613 struct hci_rp_read_buffer_size {
614         __u8     status;
615         __le16   acl_mtu;
616         __u8     sco_mtu;
617         __le16   acl_max_pkt;
618         __le16   sco_max_pkt;
619 } __packed;
620
621 #define HCI_OP_READ_BD_ADDR             0x1009
622 struct hci_rp_read_bd_addr {
623         __u8     status;
624         bdaddr_t bdaddr;
625 } __packed;
626
627 /* ---- HCI Events ---- */
628 #define HCI_EV_INQUIRY_COMPLETE         0x01
629
630 #define HCI_EV_INQUIRY_RESULT           0x02
631 struct inquiry_info {
632         bdaddr_t bdaddr;
633         __u8     pscan_rep_mode;
634         __u8     pscan_period_mode;
635         __u8     pscan_mode;
636         __u8     dev_class[3];
637         __le16   clock_offset;
638 } __packed;
639
640 #define HCI_EV_CONN_COMPLETE            0x03
641 struct hci_ev_conn_complete {
642         __u8     status;
643         __le16   handle;
644         bdaddr_t bdaddr;
645         __u8     link_type;
646         __u8     encr_mode;
647 } __packed;
648
649 #define HCI_EV_CONN_REQUEST             0x04
650 struct hci_ev_conn_request {
651         bdaddr_t bdaddr;
652         __u8     dev_class[3];
653         __u8     link_type;
654 } __packed;
655
656 #define HCI_EV_DISCONN_COMPLETE         0x05
657 struct hci_ev_disconn_complete {
658         __u8     status;
659         __le16   handle;
660         __u8     reason;
661 } __packed;
662
663 #define HCI_EV_AUTH_COMPLETE            0x06
664 struct hci_ev_auth_complete {
665         __u8     status;
666         __le16   handle;
667 } __packed;
668
669 #define HCI_EV_REMOTE_NAME              0x07
670 struct hci_ev_remote_name {
671         __u8     status;
672         bdaddr_t bdaddr;
673         __u8     name[248];
674 } __packed;
675
676 #define HCI_EV_ENCRYPT_CHANGE           0x08
677 struct hci_ev_encrypt_change {
678         __u8     status;
679         __le16   handle;
680         __u8     encrypt;
681 } __packed;
682
683 #define HCI_EV_CHANGE_LINK_KEY_COMPLETE 0x09
684 struct hci_ev_change_link_key_complete {
685         __u8     status;
686         __le16   handle;
687 } __packed;
688
689 #define HCI_EV_REMOTE_FEATURES          0x0b
690 struct hci_ev_remote_features {
691         __u8     status;
692         __le16   handle;
693         __u8     features[8];
694 } __packed;
695
696 #define HCI_EV_REMOTE_VERSION           0x0c
697 struct hci_ev_remote_version {
698         __u8     status;
699         __le16   handle;
700         __u8     lmp_ver;
701         __le16   manufacturer;
702         __le16   lmp_subver;
703 } __packed;
704
705 #define HCI_EV_QOS_SETUP_COMPLETE       0x0d
706 struct hci_qos {
707         __u8     service_type;
708         __u32    token_rate;
709         __u32    peak_bandwidth;
710         __u32    latency;
711         __u32    delay_variation;
712 } __packed;
713 struct hci_ev_qos_setup_complete {
714         __u8     status;
715         __le16   handle;
716         struct   hci_qos qos;
717 } __packed;
718
719 #define HCI_EV_CMD_COMPLETE             0x0e
720 struct hci_ev_cmd_complete {
721         __u8     ncmd;
722         __le16   opcode;
723 } __packed;
724
725 #define HCI_EV_CMD_STATUS               0x0f
726 struct hci_ev_cmd_status {
727         __u8     status;
728         __u8     ncmd;
729         __le16   opcode;
730 } __packed;
731
732 #define HCI_EV_ROLE_CHANGE              0x12
733 struct hci_ev_role_change {
734         __u8     status;
735         bdaddr_t bdaddr;
736         __u8     role;
737 } __packed;
738
739 #define HCI_EV_NUM_COMP_PKTS            0x13
740 struct hci_ev_num_comp_pkts {
741         __u8     num_hndl;
742         /* variable length part */
743 } __packed;
744
745 #define HCI_EV_MODE_CHANGE              0x14
746 struct hci_ev_mode_change {
747         __u8     status;
748         __le16   handle;
749         __u8     mode;
750         __le16   interval;
751 } __packed;
752
753 #define HCI_EV_PIN_CODE_REQ             0x16
754 struct hci_ev_pin_code_req {
755         bdaddr_t bdaddr;
756 } __packed;
757
758 #define HCI_EV_LINK_KEY_REQ             0x17
759 struct hci_ev_link_key_req {
760         bdaddr_t bdaddr;
761 } __packed;
762
763 #define HCI_EV_LINK_KEY_NOTIFY          0x18
764 struct hci_ev_link_key_notify {
765         bdaddr_t bdaddr;
766         __u8     link_key[16];
767         __u8     key_type;
768 } __packed;
769
770 #define HCI_EV_CLOCK_OFFSET             0x1c
771 struct hci_ev_clock_offset {
772         __u8     status;
773         __le16   handle;
774         __le16   clock_offset;
775 } __packed;
776
777 #define HCI_EV_PKT_TYPE_CHANGE          0x1d
778 struct hci_ev_pkt_type_change {
779         __u8     status;
780         __le16   handle;
781         __le16   pkt_type;
782 } __packed;
783
784 #define HCI_EV_PSCAN_REP_MODE           0x20
785 struct hci_ev_pscan_rep_mode {
786         bdaddr_t bdaddr;
787         __u8     pscan_rep_mode;
788 } __packed;
789
790 #define HCI_EV_INQUIRY_RESULT_WITH_RSSI 0x22
791 struct inquiry_info_with_rssi {
792         bdaddr_t bdaddr;
793         __u8     pscan_rep_mode;
794         __u8     pscan_period_mode;
795         __u8     dev_class[3];
796         __le16   clock_offset;
797         __s8     rssi;
798 } __packed;
799 struct inquiry_info_with_rssi_and_pscan_mode {
800         bdaddr_t bdaddr;
801         __u8     pscan_rep_mode;
802         __u8     pscan_period_mode;
803         __u8     pscan_mode;
804         __u8     dev_class[3];
805         __le16   clock_offset;
806         __s8     rssi;
807 } __packed;
808
809 #define HCI_EV_REMOTE_EXT_FEATURES      0x23
810 struct hci_ev_remote_ext_features {
811         __u8     status;
812         __le16   handle;
813         __u8     page;
814         __u8     max_page;
815         __u8     features[8];
816 } __packed;
817
818 #define HCI_EV_SYNC_CONN_COMPLETE       0x2c
819 struct hci_ev_sync_conn_complete {
820         __u8     status;
821         __le16   handle;
822         bdaddr_t bdaddr;
823         __u8     link_type;
824         __u8     tx_interval;
825         __u8     retrans_window;
826         __le16   rx_pkt_len;
827         __le16   tx_pkt_len;
828         __u8     air_mode;
829 } __packed;
830
831 #define HCI_EV_SYNC_CONN_CHANGED        0x2d
832 struct hci_ev_sync_conn_changed {
833         __u8     status;
834         __le16   handle;
835         __u8     tx_interval;
836         __u8     retrans_window;
837         __le16   rx_pkt_len;
838         __le16   tx_pkt_len;
839 } __packed;
840
841 #define HCI_EV_SNIFF_SUBRATE            0x2e
842 struct hci_ev_sniff_subrate {
843         __u8     status;
844         __le16   handle;
845         __le16   max_tx_latency;
846         __le16   max_rx_latency;
847         __le16   max_remote_timeout;
848         __le16   max_local_timeout;
849 } __packed;
850
851 #define HCI_EV_EXTENDED_INQUIRY_RESULT  0x2f
852 struct extended_inquiry_info {
853         bdaddr_t bdaddr;
854         __u8     pscan_rep_mode;
855         __u8     pscan_period_mode;
856         __u8     dev_class[3];
857         __le16   clock_offset;
858         __s8     rssi;
859         __u8     data[240];
860 } __packed;
861
862 #define HCI_EV_IO_CAPA_REQUEST          0x31
863 struct hci_ev_io_capa_request {
864         bdaddr_t bdaddr;
865 } __packed;
866
867 #define HCI_EV_IO_CAPA_REPLY            0x32
868 struct hci_ev_io_capa_reply {
869         bdaddr_t bdaddr;
870         __u8     capability;
871         __u8     oob_data;
872         __u8     authentication;
873 } __packed;
874
875 #define HCI_EV_SIMPLE_PAIR_COMPLETE     0x36
876 struct hci_ev_simple_pair_complete {
877         __u8     status;
878         bdaddr_t bdaddr;
879 } __packed;
880
881 #define HCI_EV_REMOTE_HOST_FEATURES     0x3d
882 struct hci_ev_remote_host_features {
883         bdaddr_t bdaddr;
884         __u8     features[8];
885 } __packed;
886
887 /* Internal events generated by Bluetooth stack */
888 #define HCI_EV_STACK_INTERNAL   0xfd
889 struct hci_ev_stack_internal {
890         __u16    type;
891         __u8     data[0];
892 } __packed;
893
894 #define HCI_EV_SI_DEVICE        0x01
895 struct hci_ev_si_device {
896         __u16    event;
897         __u16    dev_id;
898 } __packed;
899
900 #define HCI_EV_SI_SECURITY      0x02
901 struct hci_ev_si_security {
902         __u16    event;
903         __u16    proto;
904         __u16    subproto;
905         __u8     incoming;
906 } __packed;
907
908 /* ---- HCI Packet structures ---- */
909 #define HCI_COMMAND_HDR_SIZE 3
910 #define HCI_EVENT_HDR_SIZE   2
911 #define HCI_ACL_HDR_SIZE     4
912 #define HCI_SCO_HDR_SIZE     3
913
914 struct hci_command_hdr {
915         __le16  opcode;         /* OCF & OGF */
916         __u8    plen;
917 } __packed;
918
919 struct hci_event_hdr {
920         __u8    evt;
921         __u8    plen;
922 } __packed;
923
924 struct hci_acl_hdr {
925         __le16  handle;         /* Handle & Flags(PB, BC) */
926         __le16  dlen;
927 } __packed;
928
929 struct hci_sco_hdr {
930         __le16  handle;
931         __u8    dlen;
932 } __packed;
933
934 #ifdef __KERNEL__
935 #include <linux/skbuff.h>
936 static inline struct hci_event_hdr *hci_event_hdr(const struct sk_buff *skb)
937 {
938         return (struct hci_event_hdr *) skb->data;
939 }
940
941 static inline struct hci_acl_hdr *hci_acl_hdr(const struct sk_buff *skb)
942 {
943         return (struct hci_acl_hdr *) skb->data;
944 }
945
946 static inline struct hci_sco_hdr *hci_sco_hdr(const struct sk_buff *skb)
947 {
948         return (struct hci_sco_hdr *) skb->data;
949 }
950 #endif
951
952 /* Command opcode pack/unpack */
953 #define hci_opcode_pack(ogf, ocf)       (__u16) ((ocf & 0x03ff)|(ogf << 10))
954 #define hci_opcode_ogf(op)              (op >> 10)
955 #define hci_opcode_ocf(op)              (op & 0x03ff)
956
957 /* ACL handle and flags pack/unpack */
958 #define hci_handle_pack(h, f)   (__u16) ((h & 0x0fff)|(f << 12))
959 #define hci_handle(h)           (h & 0x0fff)
960 #define hci_flags(h)            (h >> 12)
961
962 /* ---- HCI Sockets ---- */
963
964 /* Socket options */
965 #define HCI_DATA_DIR    1
966 #define HCI_FILTER      2
967 #define HCI_TIME_STAMP  3
968
969 /* CMSG flags */
970 #define HCI_CMSG_DIR    0x0001
971 #define HCI_CMSG_TSTAMP 0x0002
972
973 struct sockaddr_hci {
974         sa_family_t    hci_family;
975         unsigned short hci_dev;
976         unsigned short hci_channel;
977 };
978 #define HCI_DEV_NONE    0xffff
979
980 #define HCI_CHANNEL_RAW         0
981 #define HCI_CHANNEL_CONTROL     1
982
983 struct hci_filter {
984         unsigned long type_mask;
985         unsigned long event_mask[2];
986         __le16 opcode;
987 };
988
989 struct hci_ufilter {
990         __u32  type_mask;
991         __u32  event_mask[2];
992         __le16 opcode;
993 };
994
995 #define HCI_FLT_TYPE_BITS       31
996 #define HCI_FLT_EVENT_BITS      63
997 #define HCI_FLT_OGF_BITS        63
998 #define HCI_FLT_OCF_BITS        127
999
1000 /* ---- HCI Ioctl requests structures ---- */
1001 struct hci_dev_stats {
1002         __u32 err_rx;
1003         __u32 err_tx;
1004         __u32 cmd_tx;
1005         __u32 evt_rx;
1006         __u32 acl_tx;
1007         __u32 acl_rx;
1008         __u32 sco_tx;
1009         __u32 sco_rx;
1010         __u32 byte_rx;
1011         __u32 byte_tx;
1012 };
1013
1014 struct hci_dev_info {
1015         __u16 dev_id;
1016         char  name[8];
1017
1018         bdaddr_t bdaddr;
1019
1020         __u32 flags;
1021         __u8  type;
1022
1023         __u8  features[8];
1024
1025         __u32 pkt_type;
1026         __u32 link_policy;
1027         __u32 link_mode;
1028
1029         __u16 acl_mtu;
1030         __u16 acl_pkts;
1031         __u16 sco_mtu;
1032         __u16 sco_pkts;
1033
1034         struct hci_dev_stats stat;
1035 };
1036
1037 struct hci_conn_info {
1038         __u16    handle;
1039         bdaddr_t bdaddr;
1040         __u8     type;
1041         __u8     out;
1042         __u16    state;
1043         __u32    link_mode;
1044 };
1045
1046 struct hci_dev_req {
1047         __u16  dev_id;
1048         __u32  dev_opt;
1049 };
1050
1051 struct hci_dev_list_req {
1052         __u16  dev_num;
1053         struct hci_dev_req dev_req[0];  /* hci_dev_req structures */
1054 };
1055
1056 struct hci_conn_list_req {
1057         __u16  dev_id;
1058         __u16  conn_num;
1059         struct hci_conn_info conn_info[0];
1060 };
1061
1062 struct hci_conn_info_req {
1063         bdaddr_t bdaddr;
1064         __u8     type;
1065         struct   hci_conn_info conn_info[0];
1066 };
1067
1068 struct hci_auth_info_req {
1069         bdaddr_t bdaddr;
1070         __u8     type;
1071 };
1072
1073 struct hci_inquiry_req {
1074         __u16 dev_id;
1075         __u16 flags;
1076         __u8  lap[3];
1077         __u8  length;
1078         __u8  num_rsp;
1079 };
1080 #define IREQ_CACHE_FLUSH 0x0001
1081
1082 #endif /* __HCI_H */