Merge git://git.infradead.org/mtd-2.6
[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 device types */
47 #define HCI_VHCI        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
54 /* HCI device quirks */
55 enum {
56         HCI_QUIRK_RESET_ON_INIT,
57         HCI_QUIRK_RAW_DEVICE,
58         HCI_QUIRK_FIXUP_BUFFER_SIZE
59 };
60
61 /* HCI device flags */
62 enum {
63         HCI_UP,
64         HCI_INIT,
65         HCI_RUNNING,
66
67         HCI_PSCAN,
68         HCI_ISCAN,
69         HCI_AUTH,
70         HCI_ENCRYPT,
71         HCI_INQUIRY,
72
73         HCI_RAW,
74
75         HCI_SECMGR
76 };
77
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)
83
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)
88
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)
98
99 #define HCISETSECMGR    _IOW('H', 230, int)
100
101 #define HCIINQUIRY      _IOR('H', 240, int)
102
103 /* HCI timeouts */
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 */
108
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
115
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
123
124 #define HCI_HV1         0x0020
125 #define HCI_HV2         0x0040
126 #define HCI_HV3         0x0080
127
128 #define SCO_PTYPE_MASK  (HCI_HV1 | HCI_HV2 | HCI_HV3)
129 #define ACL_PTYPE_MASK  (~SCO_PTYPE_MASK)
130
131 /* ACL flags */
132 #define ACL_CONT                0x01
133 #define ACL_START               0x02
134 #define ACL_ACTIVE_BCAST        0x04
135 #define ACL_PICO_BCAST          0x08
136
137 /* Baseband links */
138 #define SCO_LINK        0x00
139 #define ACL_LINK        0x01
140
141 /* LMP features */
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
150
151 #define LMP_PARK        0x01
152 #define LMP_RSSI        0x02
153 #define LMP_QUALITY     0x04
154 #define LMP_SCO         0x08
155 #define LMP_HV2         0x10
156 #define LMP_HV3         0x20
157 #define LMP_ULAW        0x40
158 #define LMP_ALAW        0x80
159
160 #define LMP_CVSD        0x01
161 #define LMP_PSCHEME     0x02
162 #define LMP_PCONTROL    0x04
163
164 #define LMP_SNIFF_SUBR  0x02
165
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
171
172 /* Link policies */
173 #define HCI_LP_RSWITCH  0x0001
174 #define HCI_LP_HOLD     0x0002
175 #define HCI_LP_SNIFF    0x0004
176 #define HCI_LP_PARK     0x0008
177
178 /* Link modes */
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
186
187 /* -----  HCI Commands ---- */
188 /* OGF & OCF values */
189
190 /* Informational Parameters */
191 #define OGF_INFO_PARAM  0x04
192
193 #define OCF_READ_LOCAL_VERSION  0x0001
194 struct hci_rp_read_loc_version {
195         __u8     status;
196         __u8     hci_ver;
197         __le16   hci_rev;
198         __u8     lmp_ver;
199         __le16   manufacturer;
200         __le16   lmp_subver;
201 } __attribute__ ((packed));
202
203 #define OCF_READ_LOCAL_FEATURES 0x0003
204 struct hci_rp_read_local_features {
205         __u8 status;
206         __u8 features[8];
207 } __attribute__ ((packed));
208
209 #define OCF_READ_BUFFER_SIZE    0x0005
210 struct hci_rp_read_buffer_size {
211         __u8     status;
212         __le16   acl_mtu;
213         __u8     sco_mtu;
214         __le16   acl_max_pkt;
215         __le16   sco_max_pkt;
216 } __attribute__ ((packed));
217
218 #define OCF_READ_BD_ADDR        0x0009
219 struct hci_rp_read_bd_addr {
220         __u8     status;
221         bdaddr_t bdaddr;
222 } __attribute__ ((packed));
223
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
231
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
237
238 #define OCF_WRITE_CA_TIMEOUT    0x0016  
239 #define OCF_WRITE_PG_TIMEOUT    0x0018
240
241 #define OCF_WRITE_SCAN_ENABLE   0x001A
242         #define SCAN_DISABLED           0x00
243         #define SCAN_INQUIRY            0x01
244         #define SCAN_PAGE               0x02
245
246 #define OCF_SET_EVENT_FLT       0x0005
247 struct hci_cp_set_event_flt {
248         __u8     flt_type;
249         __u8     cond_type;
250         __u8     condition[0];
251 } __attribute__ ((packed));
252
253 /* Filter types */
254 #define HCI_FLT_CLEAR_ALL       0x00
255 #define HCI_FLT_INQ_RESULT      0x01
256 #define HCI_FLT_CONN_SETUP      0x02
257
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
262
263 /* CONN_SETUP Conditions */
264 #define HCI_CONN_SETUP_AUTO_OFF 0x01
265 #define HCI_CONN_SETUP_AUTO_ON  0x02
266
267 #define OCF_READ_CLASS_OF_DEV   0x0023
268 struct hci_rp_read_dev_class {
269         __u8     status;
270         __u8     dev_class[3];
271 } __attribute__ ((packed));
272
273 #define OCF_WRITE_CLASS_OF_DEV  0x0024
274 struct hci_cp_write_dev_class {
275         __u8     dev_class[3];
276 } __attribute__ ((packed));
277
278 #define OCF_READ_VOICE_SETTING  0x0025
279 struct hci_rp_read_voice_setting {
280         __u8     status;
281         __le16   voice_setting;
282 } __attribute__ ((packed));
283
284 #define OCF_WRITE_VOICE_SETTING 0x0026
285 struct hci_cp_write_voice_setting {
286         __le16   voice_setting;
287 } __attribute__ ((packed));
288
289 #define OCF_HOST_BUFFER_SIZE    0x0033
290 struct hci_cp_host_buffer_size {
291         __le16   acl_mtu;
292         __u8     sco_mtu;
293         __le16   acl_max_pkt;
294         __le16   sco_max_pkt;
295 } __attribute__ ((packed));
296
297 /* Link Control */
298 #define OGF_LINK_CTL    0x01 
299 #define OCF_CREATE_CONN         0x0005
300 struct hci_cp_create_conn {
301         bdaddr_t bdaddr;
302         __le16   pkt_type;
303         __u8     pscan_rep_mode;
304         __u8     pscan_mode;
305         __le16   clock_offset;
306         __u8     role_switch;
307 } __attribute__ ((packed));
308
309 #define OCF_ACCEPT_CONN_REQ     0x0009
310 struct hci_cp_accept_conn_req {
311         bdaddr_t bdaddr;
312         __u8     role;
313 } __attribute__ ((packed));
314
315 #define OCF_REJECT_CONN_REQ     0x000a
316 struct hci_cp_reject_conn_req {
317         bdaddr_t bdaddr;
318         __u8     reason;
319 } __attribute__ ((packed));
320
321 #define OCF_DISCONNECT  0x0006
322 struct hci_cp_disconnect {
323         __le16   handle;
324         __u8     reason;
325 } __attribute__ ((packed));
326
327 #define OCF_ADD_SCO     0x0007
328 struct hci_cp_add_sco {
329         __le16   handle;
330         __le16   pkt_type;
331 } __attribute__ ((packed));
332
333 #define OCF_INQUIRY             0x0001
334 struct hci_cp_inquiry {
335         __u8     lap[3];
336         __u8     length;
337         __u8     num_rsp;
338 } __attribute__ ((packed));
339
340 #define OCF_INQUIRY_CANCEL      0x0002
341
342 #define OCF_LINK_KEY_REPLY      0x000B
343 struct hci_cp_link_key_reply {
344         bdaddr_t bdaddr;
345         __u8     link_key[16];
346 } __attribute__ ((packed));
347
348 #define OCF_LINK_KEY_NEG_REPLY  0x000C
349 struct hci_cp_link_key_neg_reply {
350         bdaddr_t bdaddr;
351 } __attribute__ ((packed));
352
353 #define OCF_PIN_CODE_REPLY      0x000D
354 struct hci_cp_pin_code_reply {
355         bdaddr_t bdaddr;
356         __u8     pin_len;
357         __u8     pin_code[16];
358 } __attribute__ ((packed));
359
360 #define OCF_PIN_CODE_NEG_REPLY  0x000E
361 struct hci_cp_pin_code_neg_reply {
362         bdaddr_t bdaddr;
363 } __attribute__ ((packed));
364
365 #define OCF_CHANGE_CONN_PTYPE   0x000F
366 struct hci_cp_change_conn_ptype {
367         __le16   handle;
368         __le16   pkt_type;
369 } __attribute__ ((packed));
370
371 #define OCF_AUTH_REQUESTED      0x0011
372 struct hci_cp_auth_requested {
373         __le16   handle;
374 } __attribute__ ((packed));
375
376 #define OCF_SET_CONN_ENCRYPT    0x0013
377 struct hci_cp_set_conn_encrypt {
378         __le16   handle;
379         __u8     encrypt;
380 } __attribute__ ((packed));
381
382 #define OCF_CHANGE_CONN_LINK_KEY 0x0015
383 struct hci_cp_change_conn_link_key {
384         __le16   handle;
385 } __attribute__ ((packed));
386
387 #define OCF_READ_REMOTE_FEATURES 0x001B
388 struct hci_cp_read_remote_features {
389         __le16   handle;
390 } __attribute__ ((packed));
391
392 #define OCF_READ_REMOTE_VERSION 0x001D
393 struct hci_cp_read_remote_version {
394         __le16   handle;
395 } __attribute__ ((packed));
396
397 /* Link Policy */
398 #define OGF_LINK_POLICY 0x02   
399
400 #define OCF_SNIFF_MODE          0x0003
401 struct hci_cp_sniff_mode {
402         __le16   handle;
403         __le16   max_interval;
404         __le16   min_interval;
405         __le16   attempt;
406         __le16   timeout;
407 } __attribute__ ((packed));
408
409 #define OCF_EXIT_SNIFF_MODE     0x0004
410 struct hci_cp_exit_sniff_mode {
411         __le16   handle;
412 } __attribute__ ((packed));
413
414 #define OCF_ROLE_DISCOVERY      0x0009
415 struct hci_cp_role_discovery {
416         __le16   handle;
417 } __attribute__ ((packed));
418 struct hci_rp_role_discovery {
419         __u8     status;
420         __le16   handle;
421         __u8     role;
422 } __attribute__ ((packed));
423
424 #define OCF_READ_LINK_POLICY    0x000C
425 struct hci_cp_read_link_policy {
426         __le16   handle;
427 } __attribute__ ((packed));
428 struct hci_rp_read_link_policy {
429         __u8     status;
430         __le16   handle;
431         __le16   policy;
432 } __attribute__ ((packed));
433
434 #define OCF_SWITCH_ROLE         0x000B
435 struct hci_cp_switch_role {
436         bdaddr_t bdaddr;
437         __u8     role;
438 } __attribute__ ((packed));
439
440 #define OCF_WRITE_LINK_POLICY   0x000D
441 struct hci_cp_write_link_policy {
442         __le16   handle;
443         __le16   policy;
444 } __attribute__ ((packed));
445 struct hci_rp_write_link_policy {
446         __u8     status;
447         __le16   handle;
448 } __attribute__ ((packed));
449
450 #define OCF_SNIFF_SUBRATE       0x0011
451 struct hci_cp_sniff_subrate {
452         __le16   handle;
453         __le16   max_latency;
454         __le16   min_remote_timeout;
455         __le16   min_local_timeout;
456 } __attribute__ ((packed));
457
458 /* Status params */
459 #define OGF_STATUS_PARAM        0x05
460
461 /* Testing commands */
462 #define OGF_TESTING_CMD         0x3E
463
464 /* Vendor specific commands */
465 #define OGF_VENDOR_CMD          0x3F
466
467 /* ---- HCI Events ---- */
468 #define HCI_EV_INQUIRY_COMPLETE 0x01
469
470 #define HCI_EV_INQUIRY_RESULT   0x02
471 struct inquiry_info {
472         bdaddr_t bdaddr;
473         __u8     pscan_rep_mode;
474         __u8     pscan_period_mode;
475         __u8     pscan_mode;
476         __u8     dev_class[3];
477         __le16   clock_offset;
478 } __attribute__ ((packed));
479
480 #define HCI_EV_INQUIRY_RESULT_WITH_RSSI 0x22
481 struct inquiry_info_with_rssi {
482         bdaddr_t bdaddr;
483         __u8     pscan_rep_mode;
484         __u8     pscan_period_mode;
485         __u8     dev_class[3];
486         __le16   clock_offset;
487         __s8     rssi;
488 } __attribute__ ((packed));
489 struct inquiry_info_with_rssi_and_pscan_mode {
490         bdaddr_t bdaddr;
491         __u8     pscan_rep_mode;
492         __u8     pscan_period_mode;
493         __u8     pscan_mode;
494         __u8     dev_class[3];
495         __le16   clock_offset;
496         __s8     rssi;
497 } __attribute__ ((packed));
498
499 #define HCI_EV_EXTENDED_INQUIRY_RESULT  0x2F
500 struct extended_inquiry_info {
501         bdaddr_t bdaddr;
502         __u8     pscan_rep_mode;
503         __u8     pscan_period_mode;
504         __u8     dev_class[3];
505         __le16   clock_offset;
506         __s8     rssi;
507         __u8     data[240];
508 } __attribute__ ((packed));
509
510 #define HCI_EV_CONN_COMPLETE    0x03
511 struct hci_ev_conn_complete {
512         __u8     status;
513         __le16   handle;
514         bdaddr_t bdaddr;
515         __u8     link_type;
516         __u8     encr_mode;
517 } __attribute__ ((packed));
518
519 #define HCI_EV_CONN_REQUEST     0x04
520 struct hci_ev_conn_request {
521         bdaddr_t bdaddr;
522         __u8     dev_class[3];
523         __u8     link_type;
524 } __attribute__ ((packed));
525
526 #define HCI_EV_DISCONN_COMPLETE 0x05
527 struct hci_ev_disconn_complete {
528         __u8     status;
529         __le16   handle;
530         __u8     reason;
531 } __attribute__ ((packed));
532
533 #define HCI_EV_AUTH_COMPLETE    0x06
534 struct hci_ev_auth_complete {
535         __u8     status;
536         __le16   handle;
537 } __attribute__ ((packed));
538
539 #define HCI_EV_ENCRYPT_CHANGE   0x08
540 struct hci_ev_encrypt_change {
541         __u8     status;
542         __le16   handle;
543         __u8     encrypt;
544 } __attribute__ ((packed));
545
546 #define HCI_EV_CHANGE_CONN_LINK_KEY_COMPLETE    0x09
547 struct hci_ev_change_conn_link_key_complete {
548         __u8     status;
549         __le16   handle;
550 } __attribute__ ((packed));
551
552 #define HCI_EV_QOS_SETUP_COMPLETE       0x0D
553 struct hci_qos {
554         __u8     service_type;
555         __u32    token_rate;
556         __u32    peak_bandwidth;
557         __u32    latency;
558         __u32    delay_variation;
559 } __attribute__ ((packed));
560 struct hci_ev_qos_setup_complete {
561         __u8     status;
562         __le16   handle;
563         struct   hci_qos qos;
564 } __attribute__ ((packed));
565
566 #define HCI_EV_CMD_COMPLETE     0x0E
567 struct hci_ev_cmd_complete {
568         __u8     ncmd;
569         __le16   opcode;
570 } __attribute__ ((packed));
571
572 #define HCI_EV_CMD_STATUS       0x0F
573 struct hci_ev_cmd_status {
574         __u8     status;
575         __u8     ncmd;
576         __le16   opcode;
577 } __attribute__ ((packed));
578
579 #define HCI_EV_NUM_COMP_PKTS    0x13
580 struct hci_ev_num_comp_pkts {
581         __u8     num_hndl;
582         /* variable length part */
583 } __attribute__ ((packed));
584
585 #define HCI_EV_ROLE_CHANGE      0x12
586 struct hci_ev_role_change {
587         __u8     status;
588         bdaddr_t bdaddr;
589         __u8     role;
590 } __attribute__ ((packed));
591
592 #define HCI_EV_MODE_CHANGE      0x14
593 struct hci_ev_mode_change {
594         __u8     status;
595         __le16   handle;
596         __u8     mode;
597         __le16   interval;
598 } __attribute__ ((packed));
599
600 #define HCI_EV_PIN_CODE_REQ     0x16
601 struct hci_ev_pin_code_req {
602         bdaddr_t bdaddr;
603 } __attribute__ ((packed));
604
605 #define HCI_EV_LINK_KEY_REQ     0x17
606 struct hci_ev_link_key_req {
607         bdaddr_t bdaddr;
608 } __attribute__ ((packed));
609
610 #define HCI_EV_LINK_KEY_NOTIFY  0x18
611 struct hci_ev_link_key_notify {
612         bdaddr_t bdaddr;
613         __u8     link_key[16];
614         __u8     key_type;
615 } __attribute__ ((packed));
616
617 #define HCI_EV_REMOTE_FEATURES  0x0B
618 struct hci_ev_remote_features {
619         __u8     status;
620         __le16   handle;
621         __u8     features[8];
622 } __attribute__ ((packed));
623
624 #define HCI_EV_REMOTE_VERSION   0x0C
625 struct hci_ev_remote_version {
626         __u8     status;
627         __le16   handle;
628         __u8     lmp_ver;
629         __le16   manufacturer;
630         __le16   lmp_subver;
631 } __attribute__ ((packed));
632
633 #define HCI_EV_CLOCK_OFFSET     0x01C
634 struct hci_ev_clock_offset {
635         __u8     status;
636         __le16   handle;
637         __le16   clock_offset;
638 } __attribute__ ((packed));
639
640 #define HCI_EV_PSCAN_REP_MODE   0x20
641 struct hci_ev_pscan_rep_mode {
642         bdaddr_t bdaddr;
643         __u8     pscan_rep_mode;
644 } __attribute__ ((packed));
645
646 #define HCI_EV_SNIFF_SUBRATE    0x2E
647 struct hci_ev_sniff_subrate {
648         __u8     status;
649         __le16   handle;
650         __le16   max_tx_latency;
651         __le16   max_rx_latency;
652         __le16   max_remote_timeout;
653         __le16   max_local_timeout;
654 } __attribute__ ((packed));
655
656 /* Internal events generated by Bluetooth stack */
657 #define HCI_EV_STACK_INTERNAL   0xFD
658 struct hci_ev_stack_internal {
659         __u16    type;
660         __u8     data[0];
661 } __attribute__ ((packed));
662
663 #define HCI_EV_SI_DEVICE        0x01
664 struct hci_ev_si_device {
665         __u16    event;
666         __u16    dev_id;
667 } __attribute__ ((packed));
668
669 #define HCI_EV_SI_SECURITY      0x02
670 struct hci_ev_si_security {
671         __u16    event;
672         __u16    proto;
673         __u16    subproto;
674         __u8     incoming;
675 } __attribute__ ((packed));
676
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
682
683 struct hci_command_hdr {
684         __le16  opcode;         /* OCF & OGF */
685         __u8    plen;
686 } __attribute__ ((packed));
687
688 struct hci_event_hdr {
689         __u8    evt;
690         __u8    plen;
691 } __attribute__ ((packed));
692
693 struct hci_acl_hdr {
694         __le16  handle;         /* Handle & Flags(PB, BC) */
695         __le16  dlen;
696 } __attribute__ ((packed));
697
698 struct hci_sco_hdr {
699         __le16  handle;
700         __u8    dlen;
701 } __attribute__ ((packed));
702
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)
707
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)
712
713 /* ---- HCI Sockets ---- */
714
715 /* Socket options */
716 #define HCI_DATA_DIR    1
717 #define HCI_FILTER      2
718 #define HCI_TIME_STAMP  3
719
720 /* CMSG flags */
721 #define HCI_CMSG_DIR    0x0001
722 #define HCI_CMSG_TSTAMP 0x0002
723
724 struct sockaddr_hci {
725         sa_family_t    hci_family;
726         unsigned short hci_dev;
727 };
728 #define HCI_DEV_NONE    0xffff
729
730 struct hci_filter {
731         unsigned long type_mask;
732         unsigned long event_mask[2];
733         __u16   opcode;
734 };
735
736 struct hci_ufilter {
737         __u32   type_mask;
738         __u32   event_mask[2];
739         __u16   opcode;
740 };
741
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
746
747 /* ---- HCI Ioctl requests structures ---- */
748 struct hci_dev_stats {
749         __u32 err_rx;
750         __u32 err_tx;
751         __u32 cmd_tx;
752         __u32 evt_rx;
753         __u32 acl_tx;
754         __u32 acl_rx;
755         __u32 sco_tx;
756         __u32 sco_rx;
757         __u32 byte_rx;
758         __u32 byte_tx;
759 };
760
761 struct hci_dev_info {
762         __u16 dev_id;
763         char  name[8];
764
765         bdaddr_t bdaddr;
766
767         __u32 flags;
768         __u8  type;
769
770         __u8  features[8];
771
772         __u32 pkt_type;
773         __u32 link_policy;
774         __u32 link_mode;
775
776         __u16 acl_mtu;
777         __u16 acl_pkts;
778         __u16 sco_mtu;
779         __u16 sco_pkts;
780
781         struct hci_dev_stats stat;
782 };
783
784 struct hci_conn_info {
785         __u16    handle;
786         bdaddr_t bdaddr;
787         __u8     type;
788         __u8     out;
789         __u16    state;
790         __u32    link_mode;
791 };
792
793 struct hci_dev_req {
794         __u16 dev_id;
795         __u32 dev_opt;
796 };
797
798 struct hci_dev_list_req {
799         __u16  dev_num;
800         struct hci_dev_req dev_req[0];  /* hci_dev_req structures */
801 };
802
803 struct hci_conn_list_req {
804         __u16  dev_id;
805         __u16  conn_num;
806         struct hci_conn_info conn_info[0];
807 };
808
809 struct hci_conn_info_req {
810         bdaddr_t bdaddr;
811         __u8     type;
812         struct   hci_conn_info conn_info[0];
813 };
814
815 struct hci_inquiry_req {
816         __u16 dev_id;
817         __u16 flags;
818         __u8  lap[3];
819         __u8  length;
820         __u8  num_rsp;
821 };
822 #define IREQ_CACHE_FLUSH 0x0001
823
824 #endif /* __HCI_H */