Add a virtual HCI.
[qemu] / hw / bt.h
1 /*
2  * QEMU Bluetooth HCI helpers.
3  *
4  * Copyright (C) 2007 OpenMoko, Inc.
5  * Written by Andrzej Zaborowski <andrew@openedhand.com>
6  *
7  * Useful definitions taken from BlueZ project's headers.
8  * Copyright (C) 2000-2001  Qualcomm Incorporated
9  * Copyright (C) 2002-2003  Maxim Krasnyansky <maxk@qualcomm.com>
10  * Copyright (C) 2002-2006  Marcel Holtmann <marcel@holtmann.org>
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License as
14  * published by the Free Software Foundation; either version 2 of
15  * the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
25  * MA  02110-1301  USA
26  */
27
28 /* BD Address */
29 typedef struct {
30     uint8_t b[6];
31 } __attribute__((packed)) bdaddr_t;
32
33 #define BDADDR_ANY      (&(bdaddr_t) {{0, 0, 0, 0, 0, 0}})
34 #define BDADDR_ALL      (&(bdaddr_t) {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}})
35 #define BDADDR_LOCAL    (&(bdaddr_t) {{0, 0, 0, 0xff, 0xff, 0xff}})
36
37 /* Copy, swap, convert BD Address */
38 static inline int bacmp(const bdaddr_t *ba1, const bdaddr_t *ba2)
39 {
40     return memcmp(ba1, ba2, sizeof(bdaddr_t));
41 }
42 static inline void bacpy(bdaddr_t *dst, const bdaddr_t *src)
43 {
44     memcpy(dst, src, sizeof(bdaddr_t));
45 }
46
47 #define BAINIT(orig)    { .b = {                \
48     (orig)->b[0], (orig)->b[1], (orig)->b[2],   \
49     (orig)->b[3], (orig)->b[4], (orig)->b[5],   \
50 }, }
51
52 /* The twisted structures of a bluetooth environment */
53 struct bt_device_s;
54 struct bt_scatternet_s;
55 struct bt_piconet_s;
56 struct bt_link_s;
57
58 struct bt_scatternet_s {
59     struct bt_device_s *slave;
60 };
61
62 struct bt_link_s {
63     struct bt_device_s *slave, *host;
64     uint16_t handle;            /* Master (host) side handle */
65     uint16_t acl_interval;
66     enum {
67         acl_active,
68         acl_hold,
69         acl_sniff,
70         acl_parked,
71     } acl_mode;
72 };
73
74 struct bt_device_s {
75     int lt_addr;
76     bdaddr_t bd_addr;
77     int mtu;
78     int setup;
79     struct bt_scatternet_s *net;
80
81     uint8_t key[16];
82     int key_present;
83     uint8_t class[3];
84
85     uint8_t reject_reason;
86
87     uint64_t lmp_caps;
88     const char *lmp_name;
89     void (*lmp_connection_request)(struct bt_link_s *link);
90     void (*lmp_connection_complete)(struct bt_link_s *link);
91     void (*lmp_disconnect_master)(struct bt_link_s *link);
92     void (*lmp_disconnect_slave)(struct bt_link_s *link);
93     void (*lmp_acl_data)(struct bt_link_s *link, const uint8_t *data,
94                     int start, int len);
95     void (*lmp_acl_resp)(struct bt_link_s *link, const uint8_t *data,
96                     int start, int len);
97     void (*lmp_mode_change)(struct bt_link_s *link);
98
99     void (*handle_destroy)(struct bt_device_s *device);
100     struct bt_device_s *next;   /* Next in the piconet/scatternet */
101
102     int inquiry_scan;
103     int page_scan;
104
105     uint16_t clkoff;    /* Note: Always little-endian */
106 };
107
108 /* bt.c */
109 void bt_device_init(struct bt_device_s *dev, struct bt_scatternet_s *net);
110 void bt_device_done(struct bt_device_s *dev);
111
112 /* bt-hci.c */
113 struct HCIInfo *bt_new_hci(struct bt_scatternet_s *net);
114
115 /* bt-host.c */
116 struct HCIInfo *bt_host_hci(const char *id);
117
118 /* bt-hci-csr.c */
119 enum {
120     csrhci_pin_reset,
121     csrhci_pin_wakeup,
122     __csrhci_pins,
123 };
124 qemu_irq *csrhci_pins_get(CharDriverState *chr);
125 CharDriverState *uart_hci_init(qemu_irq wakeup);
126
127 /* Link Management Protocol layer defines */
128
129 #define LLID_ACLU_CONT          0x1
130 #define LLID_ACLU_START         0x2
131 #define LLID_ACLC               0x3
132
133 enum lmp_pdu_type {
134     LMP_NAME_REQ                = 0x0001,
135     LMP_NAME_RES                = 0x0002,
136     LMP_ACCEPTED                = 0x0003,
137     LMP_NOT_ACCEPTED            = 0x0004,
138     LMP_CLKOFFSET_REQ           = 0x0005,
139     LMP_CLKOFFSET_RES           = 0x0006,
140     LMP_DETACH                  = 0x0007,
141     LMP_IN_RAND                 = 0x0008,
142     LMP_COMB_KEY                = 0x0009,
143     LMP_UNIT_KEY                = 0x000a,
144     LMP_AU_RAND                 = 0x000b,
145     LMP_SRES                    = 0x000c,
146     LMP_TEMP_RAND               = 0x000d,
147     LMP_TEMP_KEY                = 0x000e,
148     LMP_CRYPT_MODE_REQ          = 0x000f,
149     LMP_CRYPT_KEY_SIZE_REQ      = 0x0010,
150     LMP_START_ENCRYPT_REQ       = 0x0011,
151     LMP_STOP_ENCRYPT_REQ        = 0x0012,
152     LMP_SWITCH_REQ              = 0x0013,
153     LMP_HOLD                    = 0x0014,
154     LMP_HOLD_REQ                = 0x0015,
155     LMP_SNIFF_REQ               = 0x0017,
156     LMP_UNSNIFF_REQ             = 0x0018,
157     LMP_LMP_PARK_REQ            = 0x0019,
158     LMP_SET_BCAST_SCAN_WND      = 0x001b,
159     LMP_MODIFY_BEACON           = 0x001c,
160     LMP_UNPARK_BD_ADDR_REQ      = 0x001d,
161     LMP_UNPARK_PM_ADDR_REQ      = 0x001e,
162     LMP_INCR_POWER_REQ          = 0x001f,
163     LMP_DECR_POWER_REQ          = 0x0020,
164     LMP_MAX_POWER               = 0x0021,
165     LMP_MIN_POWER               = 0x0022,
166     LMP_AUTO_RATE               = 0x0023,
167     LMP_PREFERRED_RATE          = 0x0024,
168     LMP_VERSION_REQ             = 0x0025,
169     LMP_VERSION_RES             = 0x0026,
170     LMP_FEATURES_REQ            = 0x0027,
171     LMP_FEATURES_RES            = 0x0028,
172     LMP_QUALITY_OF_SERVICE      = 0x0029,
173     LMP_QOS_REQ                 = 0x002a,
174     LMP_RM_SCO_LINK_REQ         = 0x002b,
175     LMP_SCO_LINK_REQ            = 0x002c,
176     LMP_MAX_SLOT                = 0x002d,
177     LMP_MAX_SLOT_REQ            = 0x002e,
178     LMP_TIMING_ACCURACY_REQ     = 0x002f,
179     LMP_TIMING_ACCURACY_RES     = 0x0030,
180     LMP_SETUP_COMPLETE          = 0x0031,
181     LMP_USE_SEMIPERM_KEY        = 0x0032,
182     LMP_HOST_CONNECTION_REQ     = 0x0033,
183     LMP_SLOT_OFFSET             = 0x0034,
184     LMP_PAGE_MODE_REQ           = 0x0035,
185     LMP_PAGE_SCAN_MODE_REQ      = 0x0036,
186     LMP_SUPERVISION_TIMEOUT     = 0x0037,
187     LMP_TEST_ACTIVATE           = 0x0038,
188     LMP_TEST_CONTROL            = 0x0039,
189     LMP_CRYPT_KEY_MASK_REQ      = 0x003a,
190     LMP_CRYPT_KEY_MASK_RES      = 0x003b,
191     LMP_SET_AFH                 = 0x003c,
192     LMP_ACCEPTED_EXT            = 0x7f01,
193     LMP_NOT_ACCEPTED_EXT        = 0x7f02,
194     LMP_FEATURES_REQ_EXT        = 0x7f03,
195     LMP_FEATURES_RES_EXT        = 0x7f04,
196     LMP_PACKET_TYPE_TBL_REQ     = 0x7f0b,
197     LMP_ESCO_LINK_REQ           = 0x7f0c,
198     LMP_RM_ESCO_LINK_REQ        = 0x7f0d,
199     LMP_CHANNEL_CLASS_REQ       = 0x7f10,
200     LMP_CHANNEL_CLASS           = 0x7f11,
201 };
202
203 /* Host Controller Interface layer defines */
204
205 enum hci_packet_type {
206     HCI_COMMAND_PKT             = 0x01,
207     HCI_ACLDATA_PKT             = 0x02,
208     HCI_SCODATA_PKT             = 0x03,
209     HCI_EVENT_PKT               = 0x04,
210     HCI_VENDOR_PKT              = 0xff,
211 };
212
213 enum bt_packet_type {
214     HCI_2DH1    = 1 << 1,
215     HCI_3DH1    = 1 << 2,
216     HCI_DM1     = 1 << 3,
217     HCI_DH1     = 1 << 4,
218     HCI_2DH3    = 1 << 8,
219     HCI_3DH3    = 1 << 9,
220     HCI_DM3     = 1 << 10,
221     HCI_DH3     = 1 << 11,
222     HCI_2DH5    = 1 << 12,
223     HCI_3DH5    = 1 << 13,
224     HCI_DM5     = 1 << 14,
225     HCI_DH5     = 1 << 15,
226 };
227
228 enum sco_packet_type {
229     HCI_HV1     = 1 << 5,
230     HCI_HV2     = 1 << 6,
231     HCI_HV3     = 1 << 7,
232 };
233
234 enum ev_packet_type {
235     HCI_EV3     = 1 << 3,
236     HCI_EV4     = 1 << 4,
237     HCI_EV5     = 1 << 5,
238     HCI_2EV3    = 1 << 6,
239     HCI_3EV3    = 1 << 7,
240     HCI_2EV5    = 1 << 8,
241     HCI_3EV5    = 1 << 9,
242 };
243
244 enum hci_error_code {
245     HCI_SUCCESS                         = 0x00,
246     HCI_UNKNOWN_COMMAND                 = 0x01,
247     HCI_NO_CONNECTION                   = 0x02,
248     HCI_HARDWARE_FAILURE                = 0x03,
249     HCI_PAGE_TIMEOUT                    = 0x04,
250     HCI_AUTHENTICATION_FAILURE          = 0x05,
251     HCI_PIN_OR_KEY_MISSING              = 0x06,
252     HCI_MEMORY_FULL                     = 0x07,
253     HCI_CONNECTION_TIMEOUT              = 0x08,
254     HCI_MAX_NUMBER_OF_CONNECTIONS       = 0x09,
255     HCI_MAX_NUMBER_OF_SCO_CONNECTIONS   = 0x0a,
256     HCI_ACL_CONNECTION_EXISTS           = 0x0b,
257     HCI_COMMAND_DISALLOWED              = 0x0c,
258     HCI_REJECTED_LIMITED_RESOURCES      = 0x0d,
259     HCI_REJECTED_SECURITY               = 0x0e,
260     HCI_REJECTED_PERSONAL               = 0x0f,
261     HCI_HOST_TIMEOUT                    = 0x10,
262     HCI_UNSUPPORTED_FEATURE             = 0x11,
263     HCI_INVALID_PARAMETERS              = 0x12,
264     HCI_OE_USER_ENDED_CONNECTION        = 0x13,
265     HCI_OE_LOW_RESOURCES                = 0x14,
266     HCI_OE_POWER_OFF                    = 0x15,
267     HCI_CONNECTION_TERMINATED           = 0x16,
268     HCI_REPEATED_ATTEMPTS               = 0x17,
269     HCI_PAIRING_NOT_ALLOWED             = 0x18,
270     HCI_UNKNOWN_LMP_PDU                 = 0x19,
271     HCI_UNSUPPORTED_REMOTE_FEATURE      = 0x1a,
272     HCI_SCO_OFFSET_REJECTED             = 0x1b,
273     HCI_SCO_INTERVAL_REJECTED           = 0x1c,
274     HCI_AIR_MODE_REJECTED               = 0x1d,
275     HCI_INVALID_LMP_PARAMETERS          = 0x1e,
276     HCI_UNSPECIFIED_ERROR               = 0x1f,
277     HCI_UNSUPPORTED_LMP_PARAMETER_VALUE = 0x20,
278     HCI_ROLE_CHANGE_NOT_ALLOWED         = 0x21,
279     HCI_LMP_RESPONSE_TIMEOUT            = 0x22,
280     HCI_LMP_ERROR_TRANSACTION_COLLISION = 0x23,
281     HCI_LMP_PDU_NOT_ALLOWED             = 0x24,
282     HCI_ENCRYPTION_MODE_NOT_ACCEPTED    = 0x25,
283     HCI_UNIT_LINK_KEY_USED              = 0x26,
284     HCI_QOS_NOT_SUPPORTED               = 0x27,
285     HCI_INSTANT_PASSED                  = 0x28,
286     HCI_PAIRING_NOT_SUPPORTED           = 0x29,
287     HCI_TRANSACTION_COLLISION           = 0x2a,
288     HCI_QOS_UNACCEPTABLE_PARAMETER      = 0x2c,
289     HCI_QOS_REJECTED                    = 0x2d,
290     HCI_CLASSIFICATION_NOT_SUPPORTED    = 0x2e,
291     HCI_INSUFFICIENT_SECURITY           = 0x2f,
292     HCI_PARAMETER_OUT_OF_RANGE          = 0x30,
293     HCI_ROLE_SWITCH_PENDING             = 0x32,
294     HCI_SLOT_VIOLATION                  = 0x34,
295     HCI_ROLE_SWITCH_FAILED              = 0x35,
296 };
297
298 enum acl_flag_bits {
299     ACL_CONT            = 1 << 0,
300     ACL_START           = 1 << 1,
301     ACL_ACTIVE_BCAST    = 1 << 2,
302     ACL_PICO_BCAST      = 1 << 3,
303 };
304
305 enum baseband_link_type {
306     SCO_LINK            = 0x00,
307     ACL_LINK            = 0x01,
308 };
309
310 enum lmp_feature_bits0 {
311     LMP_3SLOT           = 1 << 0,
312     LMP_5SLOT           = 1 << 1,
313     LMP_ENCRYPT         = 1 << 2,
314     LMP_SOFFSET         = 1 << 3,
315     LMP_TACCURACY       = 1 << 4,
316     LMP_RSWITCH         = 1 << 5,
317     LMP_HOLD_MODE       = 1 << 6,
318     LMP_SNIFF_MODE      = 1 << 7,
319 };
320
321 enum lmp_feature_bits1 {
322     LMP_PARK            = 1 << 0,
323     LMP_RSSI            = 1 << 1,
324     LMP_QUALITY         = 1 << 2,
325     LMP_SCO             = 1 << 3,
326     LMP_HV2             = 1 << 4,
327     LMP_HV3             = 1 << 5,
328     LMP_ULAW            = 1 << 6,
329     LMP_ALAW            = 1 << 7,
330 };
331
332 enum lmp_feature_bits2 {
333     LMP_CVSD            = 1 << 0,
334     LMP_PSCHEME         = 1 << 1,
335     LMP_PCONTROL        = 1 << 2,
336     LMP_TRSP_SCO        = 1 << 3,
337     LMP_BCAST_ENC       = 1 << 7,
338 };
339
340 enum lmp_feature_bits3 {
341     LMP_EDR_ACL_2M      = 1 << 1,
342     LMP_EDR_ACL_3M      = 1 << 2,
343     LMP_ENH_ISCAN       = 1 << 3,
344     LMP_ILACE_ISCAN     = 1 << 4,
345     LMP_ILACE_PSCAN     = 1 << 5,
346     LMP_RSSI_INQ        = 1 << 6,
347     LMP_ESCO            = 1 << 7,
348 };
349
350 enum lmp_feature_bits4 {
351     LMP_EV4             = 1 << 0,
352     LMP_EV5             = 1 << 1,
353     LMP_AFH_CAP_SLV     = 1 << 3,
354     LMP_AFH_CLS_SLV     = 1 << 4,
355     LMP_EDR_3SLOT       = 1 << 7,
356 };
357
358 enum lmp_feature_bits5 {
359     LMP_EDR_5SLOT       = 1 << 0,
360     LMP_SNIFF_SUBR      = 1 << 1,
361     LMP_AFH_CAP_MST     = 1 << 3,
362     LMP_AFH_CLS_MST     = 1 << 4,
363     LMP_EDR_ESCO_2M     = 1 << 5,
364     LMP_EDR_ESCO_3M     = 1 << 6,
365     LMP_EDR_3S_ESCO     = 1 << 7,
366 };
367
368 enum lmp_feature_bits6 {
369     LMP_EXT_INQ         = 1 << 0,
370 };
371
372 enum lmp_feature_bits7 {
373     LMP_EXT_FEAT        = 1 << 7,
374 };
375
376 enum hci_link_policy {
377     HCI_LP_RSWITCH      = 1 << 0,
378     HCI_LP_HOLD         = 1 << 1,
379     HCI_LP_SNIFF        = 1 << 2,
380     HCI_LP_PARK         = 1 << 3,
381 };
382
383 enum hci_link_mode {
384     HCI_LM_ACCEPT       = 1 << 15,
385     HCI_LM_MASTER       = 1 << 0,
386     HCI_LM_AUTH         = 1 << 1,
387     HCI_LM_ENCRYPT      = 1 << 2,
388     HCI_LM_TRUSTED      = 1 << 3,
389     HCI_LM_RELIABLE     = 1 << 4,
390     HCI_LM_SECURE       = 1 << 5,
391 };
392
393 /* HCI Commands */
394
395 /* Link Control */
396 #define OGF_LINK_CTL            0x01
397
398 #define OCF_INQUIRY                     0x0001
399 typedef struct {
400     uint8_t     lap[3];
401     uint8_t     length;         /* 1.28s units */
402     uint8_t     num_rsp;
403 } __attribute__ ((packed)) inquiry_cp;
404 #define INQUIRY_CP_SIZE 5
405
406 typedef struct {
407     uint8_t             status;
408     bdaddr_t    bdaddr;
409 } __attribute__ ((packed)) status_bdaddr_rp;
410 #define STATUS_BDADDR_RP_SIZE 7
411
412 #define OCF_INQUIRY_CANCEL              0x0002
413
414 #define OCF_PERIODIC_INQUIRY            0x0003
415 typedef struct {
416     uint16_t    max_period;     /* 1.28s units */
417     uint16_t    min_period;     /* 1.28s units */
418     uint8_t     lap[3];
419     uint8_t     length;         /* 1.28s units */
420     uint8_t     num_rsp;
421 } __attribute__ ((packed)) periodic_inquiry_cp;
422 #define PERIODIC_INQUIRY_CP_SIZE 9
423
424 #define OCF_EXIT_PERIODIC_INQUIRY       0x0004
425
426 #define OCF_CREATE_CONN                 0x0005
427 typedef struct {
428     bdaddr_t    bdaddr;
429     uint16_t    pkt_type;
430     uint8_t     pscan_rep_mode;
431     uint8_t     pscan_mode;
432     uint16_t    clock_offset;
433     uint8_t     role_switch;
434 } __attribute__ ((packed)) create_conn_cp;
435 #define CREATE_CONN_CP_SIZE 13
436
437 #define OCF_DISCONNECT                  0x0006
438 typedef struct {
439     uint16_t    handle;
440     uint8_t     reason;
441 } __attribute__ ((packed)) disconnect_cp;
442 #define DISCONNECT_CP_SIZE 3
443
444 #define OCF_ADD_SCO                     0x0007
445 typedef struct {
446     uint16_t    handle;
447     uint16_t    pkt_type;
448 } __attribute__ ((packed)) add_sco_cp;
449 #define ADD_SCO_CP_SIZE 4
450
451 #define OCF_CREATE_CONN_CANCEL          0x0008
452 typedef struct {
453     uint8_t     status;
454     bdaddr_t    bdaddr;
455 } __attribute__ ((packed)) create_conn_cancel_cp;
456 #define CREATE_CONN_CANCEL_CP_SIZE 6
457
458 typedef struct {
459     uint8_t     status;
460     bdaddr_t    bdaddr;
461 } __attribute__ ((packed)) create_conn_cancel_rp;
462 #define CREATE_CONN_CANCEL_RP_SIZE 7
463
464 #define OCF_ACCEPT_CONN_REQ             0x0009
465 typedef struct {
466     bdaddr_t    bdaddr;
467     uint8_t     role;
468 } __attribute__ ((packed)) accept_conn_req_cp;
469 #define ACCEPT_CONN_REQ_CP_SIZE 7
470
471 #define OCF_REJECT_CONN_REQ             0x000A
472 typedef struct {
473     bdaddr_t    bdaddr;
474     uint8_t     reason;
475 } __attribute__ ((packed)) reject_conn_req_cp;
476 #define REJECT_CONN_REQ_CP_SIZE 7
477
478 #define OCF_LINK_KEY_REPLY              0x000B
479 typedef struct {
480     bdaddr_t    bdaddr;
481     uint8_t     link_key[16];
482 } __attribute__ ((packed)) link_key_reply_cp;
483 #define LINK_KEY_REPLY_CP_SIZE 22
484
485 #define OCF_LINK_KEY_NEG_REPLY          0x000C
486
487 #define OCF_PIN_CODE_REPLY              0x000D
488 typedef struct {
489     bdaddr_t    bdaddr;
490     uint8_t     pin_len;
491     uint8_t     pin_code[16];
492 } __attribute__ ((packed)) pin_code_reply_cp;
493 #define PIN_CODE_REPLY_CP_SIZE 23
494
495 #define OCF_PIN_CODE_NEG_REPLY          0x000E
496
497 #define OCF_SET_CONN_PTYPE              0x000F
498 typedef struct {
499     uint16_t     handle;
500     uint16_t     pkt_type;
501 } __attribute__ ((packed)) set_conn_ptype_cp;
502 #define SET_CONN_PTYPE_CP_SIZE 4
503
504 #define OCF_AUTH_REQUESTED              0x0011
505 typedef struct {
506     uint16_t     handle;
507 } __attribute__ ((packed)) auth_requested_cp;
508 #define AUTH_REQUESTED_CP_SIZE 2
509
510 #define OCF_SET_CONN_ENCRYPT            0x0013
511 typedef struct {
512     uint16_t    handle;
513     uint8_t     encrypt;
514 } __attribute__ ((packed)) set_conn_encrypt_cp;
515 #define SET_CONN_ENCRYPT_CP_SIZE 3
516
517 #define OCF_CHANGE_CONN_LINK_KEY        0x0015
518 typedef struct {
519     uint16_t    handle;
520 } __attribute__ ((packed)) change_conn_link_key_cp;
521 #define CHANGE_CONN_LINK_KEY_CP_SIZE 2
522
523 #define OCF_MASTER_LINK_KEY             0x0017
524 typedef struct {
525     uint8_t     key_flag;
526 } __attribute__ ((packed)) master_link_key_cp;
527 #define MASTER_LINK_KEY_CP_SIZE 1
528
529 #define OCF_REMOTE_NAME_REQ             0x0019
530 typedef struct {
531     bdaddr_t    bdaddr;
532     uint8_t     pscan_rep_mode;
533     uint8_t     pscan_mode;
534     uint16_t    clock_offset;
535 } __attribute__ ((packed)) remote_name_req_cp;
536 #define REMOTE_NAME_REQ_CP_SIZE 10
537
538 #define OCF_REMOTE_NAME_REQ_CANCEL      0x001A
539 typedef struct {
540     bdaddr_t    bdaddr;
541 } __attribute__ ((packed)) remote_name_req_cancel_cp;
542 #define REMOTE_NAME_REQ_CANCEL_CP_SIZE 6
543
544 typedef struct {
545     uint8_t             status;
546     bdaddr_t    bdaddr;
547 } __attribute__ ((packed)) remote_name_req_cancel_rp;
548 #define REMOTE_NAME_REQ_CANCEL_RP_SIZE 7
549
550 #define OCF_READ_REMOTE_FEATURES        0x001B
551 typedef struct {
552     uint16_t    handle;
553 } __attribute__ ((packed)) read_remote_features_cp;
554 #define READ_REMOTE_FEATURES_CP_SIZE 2
555
556 #define OCF_READ_REMOTE_EXT_FEATURES    0x001C
557 typedef struct {
558     uint16_t    handle;
559     uint8_t     page_num;
560 } __attribute__ ((packed)) read_remote_ext_features_cp;
561 #define READ_REMOTE_EXT_FEATURES_CP_SIZE 3
562
563 #define OCF_READ_REMOTE_VERSION         0x001D
564 typedef struct {
565     uint16_t    handle;
566 } __attribute__ ((packed)) read_remote_version_cp;
567 #define READ_REMOTE_VERSION_CP_SIZE 2
568
569 #define OCF_READ_CLOCK_OFFSET           0x001F
570 typedef struct {
571     uint16_t    handle;
572 } __attribute__ ((packed)) read_clock_offset_cp;
573 #define READ_CLOCK_OFFSET_CP_SIZE 2
574
575 #define OCF_READ_LMP_HANDLE             0x0020
576 typedef struct {
577     uint16_t    handle;
578 } __attribute__ ((packed)) read_lmp_handle_cp;
579 #define READ_LMP_HANDLE_CP_SIZE 2
580
581 typedef struct {
582     uint8_t     status;
583     uint16_t    handle;
584     uint8_t     lmp_handle;
585     uint32_t    reserved;
586 } __attribute__ ((packed)) read_lmp_handle_rp;
587 #define READ_LMP_HANDLE_RP_SIZE 8
588
589 #define OCF_SETUP_SYNC_CONN             0x0028
590 typedef struct {
591     uint16_t    handle;
592     uint32_t    tx_bandwith;
593     uint32_t    rx_bandwith;
594     uint16_t    max_latency;
595     uint16_t    voice_setting;
596     uint8_t     retrans_effort;
597     uint16_t    pkt_type;
598 } __attribute__ ((packed)) setup_sync_conn_cp;
599 #define SETUP_SYNC_CONN_CP_SIZE 17
600
601 #define OCF_ACCEPT_SYNC_CONN_REQ        0x0029
602 typedef struct {
603     bdaddr_t    bdaddr;
604     uint32_t    tx_bandwith;
605     uint32_t    rx_bandwith;
606     uint16_t    max_latency;
607     uint16_t    voice_setting;
608     uint8_t     retrans_effort;
609     uint16_t    pkt_type;
610 } __attribute__ ((packed)) accept_sync_conn_req_cp;
611 #define ACCEPT_SYNC_CONN_REQ_CP_SIZE 21
612
613 #define OCF_REJECT_SYNC_CONN_REQ        0x002A
614 typedef struct {
615     bdaddr_t    bdaddr;
616     uint8_t     reason;
617 } __attribute__ ((packed)) reject_sync_conn_req_cp;
618 #define REJECT_SYNC_CONN_REQ_CP_SIZE 7
619
620 /* Link Policy */
621 #define OGF_LINK_POLICY         0x02
622
623 #define OCF_HOLD_MODE                   0x0001
624 typedef struct {
625     uint16_t    handle;
626     uint16_t    max_interval;
627     uint16_t    min_interval;
628 } __attribute__ ((packed)) hold_mode_cp;
629 #define HOLD_MODE_CP_SIZE 6
630
631 #define OCF_SNIFF_MODE                  0x0003
632 typedef struct {
633     uint16_t    handle;
634     uint16_t    max_interval;
635     uint16_t    min_interval;
636     uint16_t    attempt;
637     uint16_t    timeout;
638 } __attribute__ ((packed)) sniff_mode_cp;
639 #define SNIFF_MODE_CP_SIZE 10
640
641 #define OCF_EXIT_SNIFF_MODE             0x0004
642 typedef struct {
643     uint16_t    handle;
644 } __attribute__ ((packed)) exit_sniff_mode_cp;
645 #define EXIT_SNIFF_MODE_CP_SIZE 2
646
647 #define OCF_PARK_MODE                   0x0005
648 typedef struct {
649     uint16_t    handle;
650     uint16_t    max_interval;
651     uint16_t    min_interval;
652 } __attribute__ ((packed)) park_mode_cp;
653 #define PARK_MODE_CP_SIZE 6
654
655 #define OCF_EXIT_PARK_MODE              0x0006
656 typedef struct {
657     uint16_t    handle;
658 } __attribute__ ((packed)) exit_park_mode_cp;
659 #define EXIT_PARK_MODE_CP_SIZE 2
660
661 #define OCF_QOS_SETUP                   0x0007
662 typedef struct {
663     uint8_t     service_type;           /* 1 = best effort */
664     uint32_t    token_rate;             /* Byte per seconds */
665     uint32_t    peak_bandwidth;         /* Byte per seconds */
666     uint32_t    latency;                /* Microseconds */
667     uint32_t    delay_variation;        /* Microseconds */
668 } __attribute__ ((packed)) hci_qos;
669 #define HCI_QOS_CP_SIZE 17
670 typedef struct {
671     uint16_t    handle;
672     uint8_t     flags;                  /* Reserved */
673     hci_qos     qos;
674 } __attribute__ ((packed)) qos_setup_cp;
675 #define QOS_SETUP_CP_SIZE (3 + HCI_QOS_CP_SIZE)
676
677 #define OCF_ROLE_DISCOVERY              0x0009
678 typedef struct {
679     uint16_t    handle;
680 } __attribute__ ((packed)) role_discovery_cp;
681 #define ROLE_DISCOVERY_CP_SIZE 2
682 typedef struct {
683     uint8_t     status;
684     uint16_t    handle;
685     uint8_t     role;
686 } __attribute__ ((packed)) role_discovery_rp;
687 #define ROLE_DISCOVERY_RP_SIZE 4
688
689 #define OCF_SWITCH_ROLE                 0x000B
690 typedef struct {
691     bdaddr_t    bdaddr;
692     uint8_t     role;
693 } __attribute__ ((packed)) switch_role_cp;
694 #define SWITCH_ROLE_CP_SIZE 7
695
696 #define OCF_READ_LINK_POLICY            0x000C
697 typedef struct {
698     uint16_t    handle;
699 } __attribute__ ((packed)) read_link_policy_cp;
700 #define READ_LINK_POLICY_CP_SIZE 2
701 typedef struct {
702     uint8_t     status;
703     uint16_t    handle;
704     uint16_t    policy;
705 } __attribute__ ((packed)) read_link_policy_rp;
706 #define READ_LINK_POLICY_RP_SIZE 5
707
708 #define OCF_WRITE_LINK_POLICY           0x000D
709 typedef struct {
710     uint16_t    handle;
711     uint16_t    policy;
712 } __attribute__ ((packed)) write_link_policy_cp;
713 #define WRITE_LINK_POLICY_CP_SIZE 4
714 typedef struct {
715     uint8_t     status;
716     uint16_t    handle;
717 } __attribute__ ((packed)) write_link_policy_rp;
718 #define WRITE_LINK_POLICY_RP_SIZE 3
719
720 #define OCF_READ_DEFAULT_LINK_POLICY    0x000E
721
722 #define OCF_WRITE_DEFAULT_LINK_POLICY   0x000F
723
724 #define OCF_FLOW_SPECIFICATION          0x0010
725
726 #define OCF_SNIFF_SUBRATE               0x0011
727 typedef struct {
728     uint16_t    handle;
729     uint16_t    max_remote_latency;
730     uint16_t    max_local_latency;
731     uint16_t    min_remote_timeout;
732     uint16_t    min_local_timeout;
733 } __attribute__ ((packed)) sniff_subrate_cp;
734 #define SNIFF_SUBRATE_CP_SIZE 10
735
736 /* Host Controller and Baseband */
737 #define OGF_HOST_CTL            0x03
738
739 #define OCF_SET_EVENT_MASK              0x0001
740 typedef struct {
741     uint8_t     mask[8];
742 } __attribute__ ((packed)) set_event_mask_cp;
743 #define SET_EVENT_MASK_CP_SIZE 8
744
745 #define OCF_RESET                       0x0003
746
747 #define OCF_SET_EVENT_FLT               0x0005
748 typedef struct {
749     uint8_t     flt_type;
750     uint8_t     cond_type;
751     uint8_t     condition[0];
752 } __attribute__ ((packed)) set_event_flt_cp;
753 #define SET_EVENT_FLT_CP_SIZE 2
754
755 enum bt_filter_type {
756     FLT_CLEAR_ALL               = 0x00,
757     FLT_INQ_RESULT              = 0x01,
758     FLT_CONN_SETUP              = 0x02,
759 };
760 enum inq_result_cond_type {
761     INQ_RESULT_RETURN_ALL       = 0x00,
762     INQ_RESULT_RETURN_CLASS     = 0x01,
763     INQ_RESULT_RETURN_BDADDR    = 0x02,
764 };
765 enum conn_setup_cond_type {
766     CONN_SETUP_ALLOW_ALL        = 0x00,
767     CONN_SETUP_ALLOW_CLASS      = 0x01,
768     CONN_SETUP_ALLOW_BDADDR     = 0x02,
769 };
770 enum conn_setup_cond {
771     CONN_SETUP_AUTO_OFF         = 0x01,
772     CONN_SETUP_AUTO_ON          = 0x02,
773 };
774
775 #define OCF_FLUSH                       0x0008
776 typedef struct {
777     uint16_t    handle;
778 } __attribute__ ((packed)) flush_cp;
779 #define FLUSH_CP_SIZE 2
780
781 typedef struct {
782     uint8_t     status;
783     uint16_t    handle;
784 } __attribute__ ((packed)) flush_rp;
785 #define FLUSH_RP_SIZE 3
786
787 #define OCF_READ_PIN_TYPE               0x0009
788 typedef struct {
789     uint8_t     status;
790     uint8_t     pin_type;
791 } __attribute__ ((packed)) read_pin_type_rp;
792 #define READ_PIN_TYPE_RP_SIZE 2
793
794 #define OCF_WRITE_PIN_TYPE              0x000A
795 typedef struct {
796     uint8_t     pin_type;
797 } __attribute__ ((packed)) write_pin_type_cp;
798 #define WRITE_PIN_TYPE_CP_SIZE 1
799
800 #define OCF_CREATE_NEW_UNIT_KEY         0x000B
801
802 #define OCF_READ_STORED_LINK_KEY        0x000D
803 typedef struct {
804     bdaddr_t    bdaddr;
805     uint8_t     read_all;
806 } __attribute__ ((packed)) read_stored_link_key_cp;
807 #define READ_STORED_LINK_KEY_CP_SIZE 7
808 typedef struct {
809     uint8_t     status;
810     uint16_t    max_keys;
811     uint16_t    num_keys;
812 } __attribute__ ((packed)) read_stored_link_key_rp;
813 #define READ_STORED_LINK_KEY_RP_SIZE 5
814
815 #define OCF_WRITE_STORED_LINK_KEY       0x0011
816 typedef struct {
817     uint8_t     num_keys;
818     /* variable length part */
819 } __attribute__ ((packed)) write_stored_link_key_cp;
820 #define WRITE_STORED_LINK_KEY_CP_SIZE 1
821 typedef struct {
822     uint8_t     status;
823     uint8_t     num_keys;
824 } __attribute__ ((packed)) write_stored_link_key_rp;
825 #define READ_WRITE_LINK_KEY_RP_SIZE 2
826
827 #define OCF_DELETE_STORED_LINK_KEY      0x0012
828 typedef struct {
829     bdaddr_t    bdaddr;
830     uint8_t     delete_all;
831 } __attribute__ ((packed)) delete_stored_link_key_cp;
832 #define DELETE_STORED_LINK_KEY_CP_SIZE 7
833 typedef struct {
834     uint8_t     status;
835     uint16_t    num_keys;
836 } __attribute__ ((packed)) delete_stored_link_key_rp;
837 #define DELETE_STORED_LINK_KEY_RP_SIZE 3
838
839 #define OCF_CHANGE_LOCAL_NAME           0x0013
840 typedef struct {
841     char        name[248];
842 } __attribute__ ((packed)) change_local_name_cp;
843 #define CHANGE_LOCAL_NAME_CP_SIZE 248 
844
845 #define OCF_READ_LOCAL_NAME             0x0014
846 typedef struct {
847     uint8_t     status;
848     char        name[248];
849 } __attribute__ ((packed)) read_local_name_rp;
850 #define READ_LOCAL_NAME_RP_SIZE 249 
851
852 #define OCF_READ_CONN_ACCEPT_TIMEOUT    0x0015
853 typedef struct {
854     uint8_t     status;
855     uint16_t    timeout;
856 } __attribute__ ((packed)) read_conn_accept_timeout_rp;
857 #define READ_CONN_ACCEPT_TIMEOUT_RP_SIZE 3
858
859 #define OCF_WRITE_CONN_ACCEPT_TIMEOUT   0x0016
860 typedef struct {
861     uint16_t    timeout;
862 } __attribute__ ((packed)) write_conn_accept_timeout_cp;
863 #define WRITE_CONN_ACCEPT_TIMEOUT_CP_SIZE 2
864
865 #define OCF_READ_PAGE_TIMEOUT           0x0017
866 typedef struct {
867     uint8_t     status;
868     uint16_t    timeout;
869 } __attribute__ ((packed)) read_page_timeout_rp;
870 #define READ_PAGE_TIMEOUT_RP_SIZE 3
871
872 #define OCF_WRITE_PAGE_TIMEOUT          0x0018
873 typedef struct {
874     uint16_t    timeout;
875 } __attribute__ ((packed)) write_page_timeout_cp;
876 #define WRITE_PAGE_TIMEOUT_CP_SIZE 2
877
878 #define OCF_READ_SCAN_ENABLE            0x0019
879 typedef struct {
880     uint8_t     status;
881     uint8_t     enable;
882 } __attribute__ ((packed)) read_scan_enable_rp;
883 #define READ_SCAN_ENABLE_RP_SIZE 2
884
885 #define OCF_WRITE_SCAN_ENABLE           0x001A
886 typedef struct {
887     uint8_t     scan_enable;
888 } __attribute__ ((packed)) write_scan_enable_cp;
889 #define WRITE_SCAN_ENABLE_CP_SIZE 1
890
891 enum scan_enable_bits {
892     SCAN_DISABLED               = 0,
893     SCAN_INQUIRY                = 1 << 0,
894     SCAN_PAGE                   = 1 << 1,
895 };
896
897 #define OCF_READ_PAGE_ACTIVITY          0x001B
898 typedef struct {
899     uint8_t     status;
900     uint16_t    interval;
901     uint16_t    window;
902 } __attribute__ ((packed)) read_page_activity_rp;
903 #define READ_PAGE_ACTIVITY_RP_SIZE 5
904
905 #define OCF_WRITE_PAGE_ACTIVITY         0x001C
906 typedef struct {
907     uint16_t    interval;
908     uint16_t    window;
909 } __attribute__ ((packed)) write_page_activity_cp;
910 #define WRITE_PAGE_ACTIVITY_CP_SIZE 4
911
912 #define OCF_READ_INQ_ACTIVITY           0x001D
913 typedef struct {
914     uint8_t     status;
915     uint16_t    interval;
916     uint16_t    window;
917 } __attribute__ ((packed)) read_inq_activity_rp;
918 #define READ_INQ_ACTIVITY_RP_SIZE 5
919
920 #define OCF_WRITE_INQ_ACTIVITY          0x001E
921 typedef struct {
922     uint16_t    interval;
923     uint16_t    window;
924 } __attribute__ ((packed)) write_inq_activity_cp;
925 #define WRITE_INQ_ACTIVITY_CP_SIZE 4
926
927 #define OCF_READ_AUTH_ENABLE            0x001F
928
929 #define OCF_WRITE_AUTH_ENABLE           0x0020
930
931 #define AUTH_DISABLED           0x00
932 #define AUTH_ENABLED            0x01
933
934 #define OCF_READ_ENCRYPT_MODE           0x0021
935
936 #define OCF_WRITE_ENCRYPT_MODE          0x0022
937
938 #define ENCRYPT_DISABLED        0x00
939 #define ENCRYPT_P2P             0x01
940 #define ENCRYPT_BOTH            0x02
941
942 #define OCF_READ_CLASS_OF_DEV           0x0023
943 typedef struct {
944     uint8_t     status;
945     uint8_t     dev_class[3];
946 } __attribute__ ((packed)) read_class_of_dev_rp;
947 #define READ_CLASS_OF_DEV_RP_SIZE 4 
948
949 #define OCF_WRITE_CLASS_OF_DEV          0x0024
950 typedef struct {
951     uint8_t     dev_class[3];
952 } __attribute__ ((packed)) write_class_of_dev_cp;
953 #define WRITE_CLASS_OF_DEV_CP_SIZE 3
954
955 #define OCF_READ_VOICE_SETTING          0x0025
956 typedef struct {
957     uint8_t     status;
958     uint16_t    voice_setting;
959 } __attribute__ ((packed)) read_voice_setting_rp;
960 #define READ_VOICE_SETTING_RP_SIZE 3
961
962 #define OCF_WRITE_VOICE_SETTING         0x0026
963 typedef struct {
964     uint16_t    voice_setting;
965 } __attribute__ ((packed)) write_voice_setting_cp;
966 #define WRITE_VOICE_SETTING_CP_SIZE 2
967
968 #define OCF_READ_AUTOMATIC_FLUSH_TIMEOUT        0x0027
969
970 #define OCF_WRITE_AUTOMATIC_FLUSH_TIMEOUT       0x0028
971
972 #define OCF_READ_NUM_BROADCAST_RETRANS  0x0029
973
974 #define OCF_WRITE_NUM_BROADCAST_RETRANS 0x002A
975
976 #define OCF_READ_HOLD_MODE_ACTIVITY     0x002B
977
978 #define OCF_WRITE_HOLD_MODE_ACTIVITY    0x002C
979
980 #define OCF_READ_TRANSMIT_POWER_LEVEL   0x002D
981 typedef struct {
982     uint16_t    handle;
983     uint8_t     type;
984 } __attribute__ ((packed)) read_transmit_power_level_cp;
985 #define READ_TRANSMIT_POWER_LEVEL_CP_SIZE 3
986 typedef struct {
987     uint8_t     status;
988     uint16_t    handle;
989     int8_t      level;
990 } __attribute__ ((packed)) read_transmit_power_level_rp;
991 #define READ_TRANSMIT_POWER_LEVEL_RP_SIZE 4
992
993 #define OCF_HOST_BUFFER_SIZE            0x0033
994 typedef struct {
995     uint16_t    acl_mtu;
996     uint8_t     sco_mtu;
997     uint16_t    acl_max_pkt;
998     uint16_t    sco_max_pkt;
999 } __attribute__ ((packed)) host_buffer_size_cp;
1000 #define HOST_BUFFER_SIZE_CP_SIZE 7
1001
1002 #define OCF_HOST_NUMBER_OF_COMPLETED_PACKETS    0x0035
1003
1004 #define OCF_READ_LINK_SUPERVISION_TIMEOUT       0x0036
1005 typedef struct {
1006     uint8_t     status;
1007     uint16_t    handle;
1008     uint16_t    link_sup_to;
1009 } __attribute__ ((packed)) read_link_supervision_timeout_rp;
1010 #define READ_LINK_SUPERVISION_TIMEOUT_RP_SIZE 5
1011
1012 #define OCF_WRITE_LINK_SUPERVISION_TIMEOUT      0x0037
1013 typedef struct {
1014     uint16_t    handle;
1015     uint16_t    link_sup_to;
1016 } __attribute__ ((packed)) write_link_supervision_timeout_cp;
1017 #define WRITE_LINK_SUPERVISION_TIMEOUT_CP_SIZE 4
1018 typedef struct {
1019     uint8_t     status;
1020     uint16_t    handle;
1021 } __attribute__ ((packed)) write_link_supervision_timeout_rp;
1022 #define WRITE_LINK_SUPERVISION_TIMEOUT_RP_SIZE 3
1023
1024 #define OCF_READ_NUM_SUPPORTED_IAC      0x0038
1025
1026 #define MAX_IAC_LAP 0x40
1027 #define OCF_READ_CURRENT_IAC_LAP        0x0039
1028 typedef struct {
1029     uint8_t     status;
1030     uint8_t     num_current_iac;
1031     uint8_t     lap[MAX_IAC_LAP][3];
1032 } __attribute__ ((packed)) read_current_iac_lap_rp;
1033 #define READ_CURRENT_IAC_LAP_RP_SIZE 2+3*MAX_IAC_LAP
1034
1035 #define OCF_WRITE_CURRENT_IAC_LAP       0x003A
1036 typedef struct {
1037     uint8_t     num_current_iac;
1038     uint8_t     lap[MAX_IAC_LAP][3];
1039 } __attribute__ ((packed)) write_current_iac_lap_cp;
1040 #define WRITE_CURRENT_IAC_LAP_CP_SIZE 1+3*MAX_IAC_LAP
1041
1042 #define OCF_READ_PAGE_SCAN_PERIOD_MODE  0x003B
1043
1044 #define OCF_WRITE_PAGE_SCAN_PERIOD_MODE 0x003C
1045
1046 #define OCF_READ_PAGE_SCAN_MODE         0x003D
1047
1048 #define OCF_WRITE_PAGE_SCAN_MODE        0x003E
1049
1050 #define OCF_SET_AFH_CLASSIFICATION      0x003F
1051 typedef struct {
1052     uint8_t     map[10];
1053 } __attribute__ ((packed)) set_afh_classification_cp;
1054 #define SET_AFH_CLASSIFICATION_CP_SIZE 10
1055 typedef struct {
1056     uint8_t     status;
1057 } __attribute__ ((packed)) set_afh_classification_rp;
1058 #define SET_AFH_CLASSIFICATION_RP_SIZE 1
1059
1060 #define OCF_READ_INQUIRY_SCAN_TYPE      0x0042
1061 typedef struct {
1062     uint8_t     status;
1063     uint8_t     type;
1064 } __attribute__ ((packed)) read_inquiry_scan_type_rp;
1065 #define READ_INQUIRY_SCAN_TYPE_RP_SIZE 2
1066
1067 #define OCF_WRITE_INQUIRY_SCAN_TYPE     0x0043
1068 typedef struct {
1069     uint8_t     type;
1070 } __attribute__ ((packed)) write_inquiry_scan_type_cp;
1071 #define WRITE_INQUIRY_SCAN_TYPE_CP_SIZE 1
1072 typedef struct {
1073     uint8_t     status;
1074 } __attribute__ ((packed)) write_inquiry_scan_type_rp;
1075 #define WRITE_INQUIRY_SCAN_TYPE_RP_SIZE 1
1076
1077 #define OCF_READ_INQUIRY_MODE           0x0044
1078 typedef struct {
1079     uint8_t     status;
1080     uint8_t     mode;
1081 } __attribute__ ((packed)) read_inquiry_mode_rp;
1082 #define READ_INQUIRY_MODE_RP_SIZE 2
1083
1084 #define OCF_WRITE_INQUIRY_MODE          0x0045
1085 typedef struct {
1086     uint8_t     mode;
1087 } __attribute__ ((packed)) write_inquiry_mode_cp;
1088 #define WRITE_INQUIRY_MODE_CP_SIZE 1
1089 typedef struct {
1090     uint8_t     status;
1091 } __attribute__ ((packed)) write_inquiry_mode_rp;
1092 #define WRITE_INQUIRY_MODE_RP_SIZE 1
1093
1094 #define OCF_READ_PAGE_SCAN_TYPE         0x0046
1095
1096 #define OCF_WRITE_PAGE_SCAN_TYPE        0x0047
1097
1098 #define OCF_READ_AFH_MODE               0x0048
1099 typedef struct {
1100     uint8_t     status;
1101     uint8_t     mode;
1102 } __attribute__ ((packed)) read_afh_mode_rp;
1103 #define READ_AFH_MODE_RP_SIZE 2
1104
1105 #define OCF_WRITE_AFH_MODE              0x0049
1106 typedef struct {
1107     uint8_t     mode;
1108 } __attribute__ ((packed)) write_afh_mode_cp;
1109 #define WRITE_AFH_MODE_CP_SIZE 1
1110 typedef struct {
1111     uint8_t     status;
1112 } __attribute__ ((packed)) write_afh_mode_rp;
1113 #define WRITE_AFH_MODE_RP_SIZE 1
1114
1115 #define OCF_READ_EXT_INQUIRY_RESPONSE   0x0051
1116 typedef struct {
1117     uint8_t     status;
1118     uint8_t     fec;
1119     uint8_t     data[240];
1120 } __attribute__ ((packed)) read_ext_inquiry_response_rp;
1121 #define READ_EXT_INQUIRY_RESPONSE_RP_SIZE 242
1122
1123 #define OCF_WRITE_EXT_INQUIRY_RESPONSE  0x0052
1124 typedef struct {
1125     uint8_t     fec;
1126     uint8_t     data[240];
1127 } __attribute__ ((packed)) write_ext_inquiry_response_cp;
1128 #define WRITE_EXT_INQUIRY_RESPONSE_CP_SIZE 241
1129 typedef struct {
1130     uint8_t     status;
1131 } __attribute__ ((packed)) write_ext_inquiry_response_rp;
1132 #define WRITE_EXT_INQUIRY_RESPONSE_RP_SIZE 1
1133
1134 /* Informational Parameters */
1135 #define OGF_INFO_PARAM          0x04
1136
1137 #define OCF_READ_LOCAL_VERSION          0x0001
1138 typedef struct {
1139     uint8_t     status;
1140     uint8_t     hci_ver;
1141     uint16_t    hci_rev;
1142     uint8_t     lmp_ver;
1143     uint16_t    manufacturer;
1144     uint16_t    lmp_subver;
1145 } __attribute__ ((packed)) read_local_version_rp;
1146 #define READ_LOCAL_VERSION_RP_SIZE 9
1147
1148 #define OCF_READ_LOCAL_COMMANDS         0x0002
1149 typedef struct {
1150     uint8_t     status;
1151     uint8_t     commands[64];
1152 } __attribute__ ((packed)) read_local_commands_rp;
1153 #define READ_LOCAL_COMMANDS_RP_SIZE 65
1154
1155 #define OCF_READ_LOCAL_FEATURES         0x0003
1156 typedef struct {
1157     uint8_t     status;
1158     uint8_t     features[8];
1159 } __attribute__ ((packed)) read_local_features_rp;
1160 #define READ_LOCAL_FEATURES_RP_SIZE 9
1161
1162 #define OCF_READ_LOCAL_EXT_FEATURES     0x0004
1163 typedef struct {
1164     uint8_t     page_num;
1165 } __attribute__ ((packed)) read_local_ext_features_cp;
1166 #define READ_LOCAL_EXT_FEATURES_CP_SIZE 1
1167 typedef struct {
1168     uint8_t     status;
1169     uint8_t     page_num;
1170     uint8_t     max_page_num;
1171     uint8_t     features[8];
1172 } __attribute__ ((packed)) read_local_ext_features_rp;
1173 #define READ_LOCAL_EXT_FEATURES_RP_SIZE 11
1174
1175 #define OCF_READ_BUFFER_SIZE            0x0005
1176 typedef struct {
1177     uint8_t     status;
1178     uint16_t    acl_mtu;
1179     uint8_t     sco_mtu;
1180     uint16_t    acl_max_pkt;
1181     uint16_t    sco_max_pkt;
1182 } __attribute__ ((packed)) read_buffer_size_rp;
1183 #define READ_BUFFER_SIZE_RP_SIZE 8
1184
1185 #define OCF_READ_COUNTRY_CODE           0x0007
1186 typedef struct {
1187     uint8_t     status;
1188     uint8_t     country_code;
1189 } __attribute__ ((packed)) read_country_code_rp;
1190 #define READ_COUNTRY_CODE_RP_SIZE 2
1191
1192 #define OCF_READ_BD_ADDR                0x0009
1193 typedef struct {
1194     uint8_t     status;
1195     bdaddr_t    bdaddr;
1196 } __attribute__ ((packed)) read_bd_addr_rp;
1197 #define READ_BD_ADDR_RP_SIZE 7
1198
1199 /* Status params */
1200 #define OGF_STATUS_PARAM        0x05
1201
1202 #define OCF_READ_FAILED_CONTACT_COUNTER         0x0001
1203 typedef struct {
1204     uint8_t     status;
1205     uint16_t    handle;
1206     uint8_t     counter;
1207 } __attribute__ ((packed)) read_failed_contact_counter_rp;
1208 #define READ_FAILED_CONTACT_COUNTER_RP_SIZE 4
1209
1210 #define OCF_RESET_FAILED_CONTACT_COUNTER        0x0002
1211 typedef struct {
1212     uint8_t     status;
1213     uint16_t    handle;
1214 } __attribute__ ((packed)) reset_failed_contact_counter_rp;
1215 #define RESET_FAILED_CONTACT_COUNTER_RP_SIZE 4
1216
1217 #define OCF_READ_LINK_QUALITY           0x0003
1218 typedef struct {
1219     uint16_t    handle;
1220 } __attribute__ ((packed)) read_link_quality_cp;
1221 #define READ_LINK_QUALITY_CP_SIZE 4
1222
1223 typedef struct {
1224     uint8_t     status;
1225     uint16_t    handle;
1226     uint8_t     link_quality;
1227 } __attribute__ ((packed)) read_link_quality_rp;
1228 #define READ_LINK_QUALITY_RP_SIZE 4
1229
1230 #define OCF_READ_RSSI                   0x0005
1231 typedef struct {
1232     uint8_t     status;
1233     uint16_t    handle;
1234     int8_t      rssi;
1235 } __attribute__ ((packed)) read_rssi_rp;
1236 #define READ_RSSI_RP_SIZE 4
1237
1238 #define OCF_READ_AFH_MAP                0x0006
1239 typedef struct {
1240     uint8_t     status;
1241     uint16_t    handle;
1242     uint8_t     mode;
1243     uint8_t     map[10];
1244 } __attribute__ ((packed)) read_afh_map_rp;
1245 #define READ_AFH_MAP_RP_SIZE 14
1246
1247 #define OCF_READ_CLOCK                  0x0007
1248 typedef struct {
1249     uint16_t    handle;
1250     uint8_t     which_clock;
1251 } __attribute__ ((packed)) read_clock_cp;
1252 #define READ_CLOCK_CP_SIZE 3
1253 typedef struct {
1254     uint8_t     status;
1255     uint16_t    handle;
1256     uint32_t    clock;
1257     uint16_t    accuracy;
1258 } __attribute__ ((packed)) read_clock_rp;
1259 #define READ_CLOCK_RP_SIZE 9
1260
1261 /* Testing commands */
1262 #define OGF_TESTING_CMD         0x3e
1263
1264 /* Vendor specific commands */
1265 #define OGF_VENDOR_CMD          0x3f
1266
1267 /* HCI Events */
1268
1269 #define EVT_INQUIRY_COMPLETE            0x01
1270
1271 #define EVT_INQUIRY_RESULT              0x02
1272 typedef struct {
1273     uint8_t     num_responses;
1274     bdaddr_t    bdaddr;
1275     uint8_t     pscan_rep_mode;
1276     uint8_t     pscan_period_mode;
1277     uint8_t     pscan_mode;
1278     uint8_t     dev_class[3];
1279     uint16_t    clock_offset;
1280 } __attribute__ ((packed)) inquiry_info;
1281 #define INQUIRY_INFO_SIZE 14
1282
1283 #define EVT_CONN_COMPLETE               0x03
1284 typedef struct {
1285     uint8_t     status;
1286     uint16_t    handle;
1287     bdaddr_t    bdaddr;
1288     uint8_t     link_type;
1289     uint8_t     encr_mode;
1290 } __attribute__ ((packed)) evt_conn_complete;
1291 #define EVT_CONN_COMPLETE_SIZE 11
1292
1293 #define EVT_CONN_REQUEST                0x04
1294 typedef struct {
1295     bdaddr_t    bdaddr;
1296     uint8_t     dev_class[3];
1297     uint8_t     link_type;
1298 } __attribute__ ((packed)) evt_conn_request;
1299 #define EVT_CONN_REQUEST_SIZE 10
1300
1301 #define EVT_DISCONN_COMPLETE            0x05
1302 typedef struct {
1303     uint8_t     status;
1304     uint16_t    handle;
1305     uint8_t     reason;
1306 } __attribute__ ((packed)) evt_disconn_complete;
1307 #define EVT_DISCONN_COMPLETE_SIZE 4
1308
1309 #define EVT_AUTH_COMPLETE               0x06
1310 typedef struct {
1311     uint8_t     status;
1312     uint16_t    handle;
1313 } __attribute__ ((packed)) evt_auth_complete;
1314 #define EVT_AUTH_COMPLETE_SIZE 3
1315
1316 #define EVT_REMOTE_NAME_REQ_COMPLETE    0x07
1317 typedef struct {
1318     uint8_t     status;
1319     bdaddr_t    bdaddr;
1320     char        name[248];
1321 } __attribute__ ((packed)) evt_remote_name_req_complete;
1322 #define EVT_REMOTE_NAME_REQ_COMPLETE_SIZE 255
1323
1324 #define EVT_ENCRYPT_CHANGE              0x08
1325 typedef struct {
1326     uint8_t     status;
1327     uint16_t    handle;
1328     uint8_t     encrypt;
1329 } __attribute__ ((packed)) evt_encrypt_change;
1330 #define EVT_ENCRYPT_CHANGE_SIZE 5
1331
1332 #define EVT_CHANGE_CONN_LINK_KEY_COMPLETE       0x09
1333 typedef struct {
1334     uint8_t     status;
1335     uint16_t    handle;
1336 }  __attribute__ ((packed)) evt_change_conn_link_key_complete;
1337 #define EVT_CHANGE_CONN_LINK_KEY_COMPLETE_SIZE 3
1338
1339 #define EVT_MASTER_LINK_KEY_COMPLETE            0x0A
1340 typedef struct {
1341     uint8_t     status;
1342     uint16_t    handle;
1343     uint8_t     key_flag;
1344 } __attribute__ ((packed)) evt_master_link_key_complete;
1345 #define EVT_MASTER_LINK_KEY_COMPLETE_SIZE 4
1346
1347 #define EVT_READ_REMOTE_FEATURES_COMPLETE       0x0B
1348 typedef struct {
1349     uint8_t     status;
1350     uint16_t    handle;
1351     uint8_t     features[8];
1352 } __attribute__ ((packed)) evt_read_remote_features_complete;
1353 #define EVT_READ_REMOTE_FEATURES_COMPLETE_SIZE 11
1354
1355 #define EVT_READ_REMOTE_VERSION_COMPLETE        0x0C
1356 typedef struct {
1357     uint8_t     status;
1358     uint16_t    handle;
1359     uint8_t     lmp_ver;
1360     uint16_t    manufacturer;
1361     uint16_t    lmp_subver;
1362 } __attribute__ ((packed)) evt_read_remote_version_complete;
1363 #define EVT_READ_REMOTE_VERSION_COMPLETE_SIZE 8
1364
1365 #define EVT_QOS_SETUP_COMPLETE          0x0D
1366 typedef struct {
1367     uint8_t     status;
1368     uint16_t    handle;
1369     uint8_t     flags;                  /* Reserved */
1370     hci_qos     qos;
1371 } __attribute__ ((packed)) evt_qos_setup_complete;
1372 #define EVT_QOS_SETUP_COMPLETE_SIZE (4 + HCI_QOS_CP_SIZE)
1373
1374 #define EVT_CMD_COMPLETE                0x0E
1375 typedef struct {
1376     uint8_t     ncmd;
1377     uint16_t    opcode;
1378 } __attribute__ ((packed)) evt_cmd_complete;
1379 #define EVT_CMD_COMPLETE_SIZE 3
1380
1381 #define EVT_CMD_STATUS                  0x0F
1382 typedef struct {
1383     uint8_t     status;
1384     uint8_t     ncmd;
1385     uint16_t    opcode;
1386 } __attribute__ ((packed)) evt_cmd_status;
1387 #define EVT_CMD_STATUS_SIZE 4
1388
1389 #define EVT_HARDWARE_ERROR              0x10
1390 typedef struct {
1391     uint8_t     code;
1392 } __attribute__ ((packed)) evt_hardware_error;
1393 #define EVT_HARDWARE_ERROR_SIZE 1
1394
1395 #define EVT_FLUSH_OCCURRED              0x11
1396 typedef struct {
1397     uint16_t    handle;
1398 } __attribute__ ((packed)) evt_flush_occured;
1399 #define EVT_FLUSH_OCCURRED_SIZE 2
1400
1401 #define EVT_ROLE_CHANGE                 0x12
1402 typedef struct {
1403     uint8_t     status;
1404     bdaddr_t    bdaddr;
1405     uint8_t     role;
1406 } __attribute__ ((packed)) evt_role_change;
1407 #define EVT_ROLE_CHANGE_SIZE 8
1408
1409 #define EVT_NUM_COMP_PKTS               0x13
1410 typedef struct {
1411     uint8_t     num_hndl;
1412     struct {
1413         uint16_t handle;
1414         uint16_t num_packets;
1415     } connection[0];
1416 } __attribute__ ((packed)) evt_num_comp_pkts;
1417 #define EVT_NUM_COMP_PKTS_SIZE(num_hndl) (1 + 4 * (num_hndl))
1418
1419 #define EVT_MODE_CHANGE                 0x14
1420 typedef struct {
1421     uint8_t     status;
1422     uint16_t    handle;
1423     uint8_t     mode;
1424     uint16_t    interval;
1425 } __attribute__ ((packed)) evt_mode_change;
1426 #define EVT_MODE_CHANGE_SIZE 6
1427
1428 #define EVT_RETURN_LINK_KEYS            0x15
1429 typedef struct {
1430     uint8_t     num_keys;
1431     /* variable length part */
1432 } __attribute__ ((packed)) evt_return_link_keys;
1433 #define EVT_RETURN_LINK_KEYS_SIZE 1
1434
1435 #define EVT_PIN_CODE_REQ                0x16
1436 typedef struct {
1437     bdaddr_t    bdaddr;
1438 } __attribute__ ((packed)) evt_pin_code_req;
1439 #define EVT_PIN_CODE_REQ_SIZE 6
1440
1441 #define EVT_LINK_KEY_REQ                0x17
1442 typedef struct {
1443     bdaddr_t    bdaddr;
1444 } __attribute__ ((packed)) evt_link_key_req;
1445 #define EVT_LINK_KEY_REQ_SIZE 6
1446
1447 #define EVT_LINK_KEY_NOTIFY             0x18
1448 typedef struct {
1449     bdaddr_t    bdaddr;
1450     uint8_t     link_key[16];
1451     uint8_t     key_type;
1452 } __attribute__ ((packed)) evt_link_key_notify;
1453 #define EVT_LINK_KEY_NOTIFY_SIZE 23
1454
1455 #define EVT_LOOPBACK_COMMAND            0x19
1456
1457 #define EVT_DATA_BUFFER_OVERFLOW        0x1A
1458 typedef struct {
1459     uint8_t     link_type;
1460 } __attribute__ ((packed)) evt_data_buffer_overflow;
1461 #define EVT_DATA_BUFFER_OVERFLOW_SIZE 1
1462
1463 #define EVT_MAX_SLOTS_CHANGE            0x1B
1464 typedef struct {
1465     uint16_t    handle;
1466     uint8_t     max_slots;
1467 } __attribute__ ((packed)) evt_max_slots_change;
1468 #define EVT_MAX_SLOTS_CHANGE_SIZE 3
1469
1470 #define EVT_READ_CLOCK_OFFSET_COMPLETE  0x1C
1471 typedef struct {
1472     uint8_t     status;
1473     uint16_t    handle;
1474     uint16_t    clock_offset;
1475 } __attribute__ ((packed)) evt_read_clock_offset_complete;
1476 #define EVT_READ_CLOCK_OFFSET_COMPLETE_SIZE 5
1477
1478 #define EVT_CONN_PTYPE_CHANGED          0x1D
1479 typedef struct {
1480     uint8_t     status;
1481     uint16_t    handle;
1482     uint16_t    ptype;
1483 } __attribute__ ((packed)) evt_conn_ptype_changed;
1484 #define EVT_CONN_PTYPE_CHANGED_SIZE 5
1485
1486 #define EVT_QOS_VIOLATION               0x1E
1487 typedef struct {
1488     uint16_t    handle;
1489 } __attribute__ ((packed)) evt_qos_violation;
1490 #define EVT_QOS_VIOLATION_SIZE 2
1491
1492 #define EVT_PSCAN_REP_MODE_CHANGE       0x20
1493 typedef struct {
1494     bdaddr_t    bdaddr;
1495     uint8_t     pscan_rep_mode;
1496 } __attribute__ ((packed)) evt_pscan_rep_mode_change;
1497 #define EVT_PSCAN_REP_MODE_CHANGE_SIZE 7
1498
1499 #define EVT_FLOW_SPEC_COMPLETE          0x21
1500 typedef struct {
1501     uint8_t     status;
1502     uint16_t    handle;
1503     uint8_t     flags;
1504     uint8_t     direction;
1505     hci_qos     qos;
1506 } __attribute__ ((packed)) evt_flow_spec_complete;
1507 #define EVT_FLOW_SPEC_COMPLETE_SIZE (5 + HCI_QOS_CP_SIZE)
1508
1509 #define EVT_INQUIRY_RESULT_WITH_RSSI    0x22
1510 typedef struct {
1511     uint8_t     num_responses;
1512     bdaddr_t    bdaddr;
1513     uint8_t     pscan_rep_mode;
1514     uint8_t     pscan_period_mode;
1515     uint8_t     dev_class[3];
1516     uint16_t    clock_offset;
1517     int8_t      rssi;
1518 } __attribute__ ((packed)) inquiry_info_with_rssi;
1519 #define INQUIRY_INFO_WITH_RSSI_SIZE 15
1520 typedef struct {
1521     uint8_t     num_responses;
1522     bdaddr_t    bdaddr;
1523     uint8_t     pscan_rep_mode;
1524     uint8_t     pscan_period_mode;
1525     uint8_t     pscan_mode;
1526     uint8_t     dev_class[3];
1527     uint16_t    clock_offset;
1528     int8_t      rssi;
1529 } __attribute__ ((packed)) inquiry_info_with_rssi_and_pscan_mode;
1530 #define INQUIRY_INFO_WITH_RSSI_AND_PSCAN_MODE_SIZE 16
1531
1532 #define EVT_READ_REMOTE_EXT_FEATURES_COMPLETE   0x23
1533 typedef struct {
1534     uint8_t     status;
1535     uint16_t    handle;
1536     uint8_t     page_num;
1537     uint8_t     max_page_num;
1538     uint8_t     features[8];
1539 } __attribute__ ((packed)) evt_read_remote_ext_features_complete;
1540 #define EVT_READ_REMOTE_EXT_FEATURES_COMPLETE_SIZE 13
1541
1542 #define EVT_SYNC_CONN_COMPLETE          0x2C
1543 typedef struct {
1544     uint8_t     status;
1545     uint16_t    handle;
1546     bdaddr_t    bdaddr;
1547     uint8_t     link_type;
1548     uint8_t     trans_interval;
1549     uint8_t     retrans_window;
1550     uint16_t    rx_pkt_len;
1551     uint16_t    tx_pkt_len;
1552     uint8_t     air_mode;
1553 } __attribute__ ((packed)) evt_sync_conn_complete;
1554 #define EVT_SYNC_CONN_COMPLETE_SIZE 17
1555
1556 #define EVT_SYNC_CONN_CHANGED           0x2D
1557 typedef struct {
1558     uint8_t     status;
1559     uint16_t    handle;
1560     uint8_t     trans_interval;
1561     uint8_t     retrans_window;
1562     uint16_t    rx_pkt_len;
1563     uint16_t    tx_pkt_len;
1564 } __attribute__ ((packed)) evt_sync_conn_changed;
1565 #define EVT_SYNC_CONN_CHANGED_SIZE 9
1566
1567 #define EVT_SNIFF_SUBRATE               0x2E
1568 typedef struct {
1569     uint8_t     status;
1570     uint16_t    handle;
1571     uint16_t    max_remote_latency;
1572     uint16_t    max_local_latency;
1573     uint16_t    min_remote_timeout;
1574     uint16_t    min_local_timeout;
1575 } __attribute__ ((packed)) evt_sniff_subrate;
1576 #define EVT_SNIFF_SUBRATE_SIZE 11
1577
1578 #define EVT_EXTENDED_INQUIRY_RESULT     0x2F
1579 typedef struct {
1580     bdaddr_t    bdaddr;
1581     uint8_t     pscan_rep_mode;
1582     uint8_t     pscan_period_mode;
1583     uint8_t     dev_class[3];
1584     uint16_t    clock_offset;
1585     int8_t      rssi;
1586     uint8_t     data[240];
1587 } __attribute__ ((packed)) extended_inquiry_info;
1588 #define EXTENDED_INQUIRY_INFO_SIZE 254
1589
1590 #define EVT_TESTING                     0xFE
1591
1592 #define EVT_VENDOR                      0xFF
1593
1594 /* Command opcode pack/unpack */
1595 #define cmd_opcode_pack(ogf, ocf)       (uint16_t)((ocf & 0x03ff)|(ogf << 10))
1596 #define cmd_opcode_ogf(op)              (op >> 10)
1597 #define cmd_opcode_ocf(op)              (op & 0x03ff)
1598
1599 /* ACL handle and flags pack/unpack */
1600 #define acl_handle_pack(h, f)   (uint16_t)(((h) & 0x0fff)|((f) << 12))
1601 #define acl_handle(h)           ((h) & 0x0fff)
1602 #define acl_flags(h)            ((h) >> 12)
1603
1604 /* HCI Packet structures */
1605 #define HCI_COMMAND_HDR_SIZE    3
1606 #define HCI_EVENT_HDR_SIZE      2
1607 #define HCI_ACL_HDR_SIZE        4
1608 #define HCI_SCO_HDR_SIZE        3
1609
1610 struct hci_command_hdr {
1611     uint16_t    opcode;         /* OCF & OGF */
1612     uint8_t     plen;
1613 } __attribute__ ((packed));
1614
1615 struct hci_event_hdr {
1616     uint8_t     evt;
1617     uint8_t     plen;
1618 } __attribute__ ((packed));
1619
1620 struct hci_acl_hdr {
1621     uint16_t    handle;         /* Handle & Flags(PB, BC) */
1622     uint16_t    dlen;
1623 } __attribute__ ((packed));
1624
1625 struct hci_sco_hdr {
1626     uint16_t    handle;
1627     uint8_t     dlen;
1628 } __attribute__ ((packed));