437813d305d96a51f102c1c7ade1db1d8053e73c
[sdk/emulator/qemu.git] / 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 /* bt-l2cap.c */
128 struct bt_l2cap_device_s;
129 struct bt_l2cap_conn_params_s;
130 struct bt_l2cap_psm_s;
131 void bt_l2cap_device_init(struct bt_l2cap_device_s *dev,
132                 struct bt_scatternet_s *net);
133 void bt_l2cap_device_done(struct bt_l2cap_device_s *dev);
134 void bt_l2cap_psm_register(struct bt_l2cap_device_s *dev, int psm,
135                 int min_mtu, int (*new_channel)(struct bt_l2cap_device_s *dev,
136                         struct bt_l2cap_conn_params_s *params));
137
138 struct bt_l2cap_device_s {
139     struct bt_device_s device;
140     struct bt_l2cap_psm_s *first_psm;
141 };
142
143 struct bt_l2cap_conn_params_s {
144     /* Input */
145     uint8_t *(*sdu_out)(struct bt_l2cap_conn_params_s *chan, int len);
146     void (*sdu_submit)(struct bt_l2cap_conn_params_s *chan);
147     int remote_mtu;
148     /* Output */
149     void *opaque;
150     void (*sdu_in)(void *opaque, const uint8_t *data, int len);
151     void (*close)(void *opaque);
152 };
153
154 enum bt_l2cap_psm_predef {
155     BT_PSM_SDP          = 0x0001,
156     BT_PSM_RFCOMM       = 0x0003,
157     BT_PSM_TELEPHONY    = 0x0005,
158     BT_PSM_TCS          = 0x0007,
159     BT_PSM_BNEP         = 0x000f,
160     BT_PSM_HID_CTRL     = 0x0011,
161     BT_PSM_HID_INTR     = 0x0013,
162     BT_PSM_UPNP         = 0x0015,
163     BT_PSM_AVCTP        = 0x0017,
164     BT_PSM_AVDTP        = 0x0019,
165 };
166
167 /* bt-sdp.c */
168 void bt_l2cap_sdp_init(struct bt_l2cap_device_s *dev);
169
170 /* Link Management Protocol layer defines */
171
172 #define LLID_ACLU_CONT          0x1
173 #define LLID_ACLU_START         0x2
174 #define LLID_ACLC               0x3
175
176 enum lmp_pdu_type {
177     LMP_NAME_REQ                = 0x0001,
178     LMP_NAME_RES                = 0x0002,
179     LMP_ACCEPTED                = 0x0003,
180     LMP_NOT_ACCEPTED            = 0x0004,
181     LMP_CLKOFFSET_REQ           = 0x0005,
182     LMP_CLKOFFSET_RES           = 0x0006,
183     LMP_DETACH                  = 0x0007,
184     LMP_IN_RAND                 = 0x0008,
185     LMP_COMB_KEY                = 0x0009,
186     LMP_UNIT_KEY                = 0x000a,
187     LMP_AU_RAND                 = 0x000b,
188     LMP_SRES                    = 0x000c,
189     LMP_TEMP_RAND               = 0x000d,
190     LMP_TEMP_KEY                = 0x000e,
191     LMP_CRYPT_MODE_REQ          = 0x000f,
192     LMP_CRYPT_KEY_SIZE_REQ      = 0x0010,
193     LMP_START_ENCRYPT_REQ       = 0x0011,
194     LMP_STOP_ENCRYPT_REQ        = 0x0012,
195     LMP_SWITCH_REQ              = 0x0013,
196     LMP_HOLD                    = 0x0014,
197     LMP_HOLD_REQ                = 0x0015,
198     LMP_SNIFF_REQ               = 0x0017,
199     LMP_UNSNIFF_REQ             = 0x0018,
200     LMP_LMP_PARK_REQ            = 0x0019,
201     LMP_SET_BCAST_SCAN_WND      = 0x001b,
202     LMP_MODIFY_BEACON           = 0x001c,
203     LMP_UNPARK_BD_ADDR_REQ      = 0x001d,
204     LMP_UNPARK_PM_ADDR_REQ      = 0x001e,
205     LMP_INCR_POWER_REQ          = 0x001f,
206     LMP_DECR_POWER_REQ          = 0x0020,
207     LMP_MAX_POWER               = 0x0021,
208     LMP_MIN_POWER               = 0x0022,
209     LMP_AUTO_RATE               = 0x0023,
210     LMP_PREFERRED_RATE          = 0x0024,
211     LMP_VERSION_REQ             = 0x0025,
212     LMP_VERSION_RES             = 0x0026,
213     LMP_FEATURES_REQ            = 0x0027,
214     LMP_FEATURES_RES            = 0x0028,
215     LMP_QUALITY_OF_SERVICE      = 0x0029,
216     LMP_QOS_REQ                 = 0x002a,
217     LMP_RM_SCO_LINK_REQ         = 0x002b,
218     LMP_SCO_LINK_REQ            = 0x002c,
219     LMP_MAX_SLOT                = 0x002d,
220     LMP_MAX_SLOT_REQ            = 0x002e,
221     LMP_TIMING_ACCURACY_REQ     = 0x002f,
222     LMP_TIMING_ACCURACY_RES     = 0x0030,
223     LMP_SETUP_COMPLETE          = 0x0031,
224     LMP_USE_SEMIPERM_KEY        = 0x0032,
225     LMP_HOST_CONNECTION_REQ     = 0x0033,
226     LMP_SLOT_OFFSET             = 0x0034,
227     LMP_PAGE_MODE_REQ           = 0x0035,
228     LMP_PAGE_SCAN_MODE_REQ      = 0x0036,
229     LMP_SUPERVISION_TIMEOUT     = 0x0037,
230     LMP_TEST_ACTIVATE           = 0x0038,
231     LMP_TEST_CONTROL            = 0x0039,
232     LMP_CRYPT_KEY_MASK_REQ      = 0x003a,
233     LMP_CRYPT_KEY_MASK_RES      = 0x003b,
234     LMP_SET_AFH                 = 0x003c,
235     LMP_ACCEPTED_EXT            = 0x7f01,
236     LMP_NOT_ACCEPTED_EXT        = 0x7f02,
237     LMP_FEATURES_REQ_EXT        = 0x7f03,
238     LMP_FEATURES_RES_EXT        = 0x7f04,
239     LMP_PACKET_TYPE_TBL_REQ     = 0x7f0b,
240     LMP_ESCO_LINK_REQ           = 0x7f0c,
241     LMP_RM_ESCO_LINK_REQ        = 0x7f0d,
242     LMP_CHANNEL_CLASS_REQ       = 0x7f10,
243     LMP_CHANNEL_CLASS           = 0x7f11,
244 };
245
246 /* Host Controller Interface layer defines */
247
248 enum hci_packet_type {
249     HCI_COMMAND_PKT             = 0x01,
250     HCI_ACLDATA_PKT             = 0x02,
251     HCI_SCODATA_PKT             = 0x03,
252     HCI_EVENT_PKT               = 0x04,
253     HCI_VENDOR_PKT              = 0xff,
254 };
255
256 enum bt_packet_type {
257     HCI_2DH1    = 1 << 1,
258     HCI_3DH1    = 1 << 2,
259     HCI_DM1     = 1 << 3,
260     HCI_DH1     = 1 << 4,
261     HCI_2DH3    = 1 << 8,
262     HCI_3DH3    = 1 << 9,
263     HCI_DM3     = 1 << 10,
264     HCI_DH3     = 1 << 11,
265     HCI_2DH5    = 1 << 12,
266     HCI_3DH5    = 1 << 13,
267     HCI_DM5     = 1 << 14,
268     HCI_DH5     = 1 << 15,
269 };
270
271 enum sco_packet_type {
272     HCI_HV1     = 1 << 5,
273     HCI_HV2     = 1 << 6,
274     HCI_HV3     = 1 << 7,
275 };
276
277 enum ev_packet_type {
278     HCI_EV3     = 1 << 3,
279     HCI_EV4     = 1 << 4,
280     HCI_EV5     = 1 << 5,
281     HCI_2EV3    = 1 << 6,
282     HCI_3EV3    = 1 << 7,
283     HCI_2EV5    = 1 << 8,
284     HCI_3EV5    = 1 << 9,
285 };
286
287 enum hci_error_code {
288     HCI_SUCCESS                         = 0x00,
289     HCI_UNKNOWN_COMMAND                 = 0x01,
290     HCI_NO_CONNECTION                   = 0x02,
291     HCI_HARDWARE_FAILURE                = 0x03,
292     HCI_PAGE_TIMEOUT                    = 0x04,
293     HCI_AUTHENTICATION_FAILURE          = 0x05,
294     HCI_PIN_OR_KEY_MISSING              = 0x06,
295     HCI_MEMORY_FULL                     = 0x07,
296     HCI_CONNECTION_TIMEOUT              = 0x08,
297     HCI_MAX_NUMBER_OF_CONNECTIONS       = 0x09,
298     HCI_MAX_NUMBER_OF_SCO_CONNECTIONS   = 0x0a,
299     HCI_ACL_CONNECTION_EXISTS           = 0x0b,
300     HCI_COMMAND_DISALLOWED              = 0x0c,
301     HCI_REJECTED_LIMITED_RESOURCES      = 0x0d,
302     HCI_REJECTED_SECURITY               = 0x0e,
303     HCI_REJECTED_PERSONAL               = 0x0f,
304     HCI_HOST_TIMEOUT                    = 0x10,
305     HCI_UNSUPPORTED_FEATURE             = 0x11,
306     HCI_INVALID_PARAMETERS              = 0x12,
307     HCI_OE_USER_ENDED_CONNECTION        = 0x13,
308     HCI_OE_LOW_RESOURCES                = 0x14,
309     HCI_OE_POWER_OFF                    = 0x15,
310     HCI_CONNECTION_TERMINATED           = 0x16,
311     HCI_REPEATED_ATTEMPTS               = 0x17,
312     HCI_PAIRING_NOT_ALLOWED             = 0x18,
313     HCI_UNKNOWN_LMP_PDU                 = 0x19,
314     HCI_UNSUPPORTED_REMOTE_FEATURE      = 0x1a,
315     HCI_SCO_OFFSET_REJECTED             = 0x1b,
316     HCI_SCO_INTERVAL_REJECTED           = 0x1c,
317     HCI_AIR_MODE_REJECTED               = 0x1d,
318     HCI_INVALID_LMP_PARAMETERS          = 0x1e,
319     HCI_UNSPECIFIED_ERROR               = 0x1f,
320     HCI_UNSUPPORTED_LMP_PARAMETER_VALUE = 0x20,
321     HCI_ROLE_CHANGE_NOT_ALLOWED         = 0x21,
322     HCI_LMP_RESPONSE_TIMEOUT            = 0x22,
323     HCI_LMP_ERROR_TRANSACTION_COLLISION = 0x23,
324     HCI_LMP_PDU_NOT_ALLOWED             = 0x24,
325     HCI_ENCRYPTION_MODE_NOT_ACCEPTED    = 0x25,
326     HCI_UNIT_LINK_KEY_USED              = 0x26,
327     HCI_QOS_NOT_SUPPORTED               = 0x27,
328     HCI_INSTANT_PASSED                  = 0x28,
329     HCI_PAIRING_NOT_SUPPORTED           = 0x29,
330     HCI_TRANSACTION_COLLISION           = 0x2a,
331     HCI_QOS_UNACCEPTABLE_PARAMETER      = 0x2c,
332     HCI_QOS_REJECTED                    = 0x2d,
333     HCI_CLASSIFICATION_NOT_SUPPORTED    = 0x2e,
334     HCI_INSUFFICIENT_SECURITY           = 0x2f,
335     HCI_PARAMETER_OUT_OF_RANGE          = 0x30,
336     HCI_ROLE_SWITCH_PENDING             = 0x32,
337     HCI_SLOT_VIOLATION                  = 0x34,
338     HCI_ROLE_SWITCH_FAILED              = 0x35,
339 };
340
341 enum acl_flag_bits {
342     ACL_CONT            = 1 << 0,
343     ACL_START           = 1 << 1,
344     ACL_ACTIVE_BCAST    = 1 << 2,
345     ACL_PICO_BCAST      = 1 << 3,
346 };
347
348 enum baseband_link_type {
349     SCO_LINK            = 0x00,
350     ACL_LINK            = 0x01,
351 };
352
353 enum lmp_feature_bits0 {
354     LMP_3SLOT           = 1 << 0,
355     LMP_5SLOT           = 1 << 1,
356     LMP_ENCRYPT         = 1 << 2,
357     LMP_SOFFSET         = 1 << 3,
358     LMP_TACCURACY       = 1 << 4,
359     LMP_RSWITCH         = 1 << 5,
360     LMP_HOLD_MODE       = 1 << 6,
361     LMP_SNIFF_MODE      = 1 << 7,
362 };
363
364 enum lmp_feature_bits1 {
365     LMP_PARK            = 1 << 0,
366     LMP_RSSI            = 1 << 1,
367     LMP_QUALITY         = 1 << 2,
368     LMP_SCO             = 1 << 3,
369     LMP_HV2             = 1 << 4,
370     LMP_HV3             = 1 << 5,
371     LMP_ULAW            = 1 << 6,
372     LMP_ALAW            = 1 << 7,
373 };
374
375 enum lmp_feature_bits2 {
376     LMP_CVSD            = 1 << 0,
377     LMP_PSCHEME         = 1 << 1,
378     LMP_PCONTROL        = 1 << 2,
379     LMP_TRSP_SCO        = 1 << 3,
380     LMP_BCAST_ENC       = 1 << 7,
381 };
382
383 enum lmp_feature_bits3 {
384     LMP_EDR_ACL_2M      = 1 << 1,
385     LMP_EDR_ACL_3M      = 1 << 2,
386     LMP_ENH_ISCAN       = 1 << 3,
387     LMP_ILACE_ISCAN     = 1 << 4,
388     LMP_ILACE_PSCAN     = 1 << 5,
389     LMP_RSSI_INQ        = 1 << 6,
390     LMP_ESCO            = 1 << 7,
391 };
392
393 enum lmp_feature_bits4 {
394     LMP_EV4             = 1 << 0,
395     LMP_EV5             = 1 << 1,
396     LMP_AFH_CAP_SLV     = 1 << 3,
397     LMP_AFH_CLS_SLV     = 1 << 4,
398     LMP_EDR_3SLOT       = 1 << 7,
399 };
400
401 enum lmp_feature_bits5 {
402     LMP_EDR_5SLOT       = 1 << 0,
403     LMP_SNIFF_SUBR      = 1 << 1,
404     LMP_AFH_CAP_MST     = 1 << 3,
405     LMP_AFH_CLS_MST     = 1 << 4,
406     LMP_EDR_ESCO_2M     = 1 << 5,
407     LMP_EDR_ESCO_3M     = 1 << 6,
408     LMP_EDR_3S_ESCO     = 1 << 7,
409 };
410
411 enum lmp_feature_bits6 {
412     LMP_EXT_INQ         = 1 << 0,
413 };
414
415 enum lmp_feature_bits7 {
416     LMP_EXT_FEAT        = 1 << 7,
417 };
418
419 enum hci_link_policy {
420     HCI_LP_RSWITCH      = 1 << 0,
421     HCI_LP_HOLD         = 1 << 1,
422     HCI_LP_SNIFF        = 1 << 2,
423     HCI_LP_PARK         = 1 << 3,
424 };
425
426 enum hci_link_mode {
427     HCI_LM_ACCEPT       = 1 << 15,
428     HCI_LM_MASTER       = 1 << 0,
429     HCI_LM_AUTH         = 1 << 1,
430     HCI_LM_ENCRYPT      = 1 << 2,
431     HCI_LM_TRUSTED      = 1 << 3,
432     HCI_LM_RELIABLE     = 1 << 4,
433     HCI_LM_SECURE       = 1 << 5,
434 };
435
436 /* HCI Commands */
437
438 /* Link Control */
439 #define OGF_LINK_CTL            0x01
440
441 #define OCF_INQUIRY                     0x0001
442 typedef struct {
443     uint8_t     lap[3];
444     uint8_t     length;         /* 1.28s units */
445     uint8_t     num_rsp;
446 } __attribute__ ((packed)) inquiry_cp;
447 #define INQUIRY_CP_SIZE 5
448
449 typedef struct {
450     uint8_t             status;
451     bdaddr_t    bdaddr;
452 } __attribute__ ((packed)) status_bdaddr_rp;
453 #define STATUS_BDADDR_RP_SIZE 7
454
455 #define OCF_INQUIRY_CANCEL              0x0002
456
457 #define OCF_PERIODIC_INQUIRY            0x0003
458 typedef struct {
459     uint16_t    max_period;     /* 1.28s units */
460     uint16_t    min_period;     /* 1.28s units */
461     uint8_t     lap[3];
462     uint8_t     length;         /* 1.28s units */
463     uint8_t     num_rsp;
464 } __attribute__ ((packed)) periodic_inquiry_cp;
465 #define PERIODIC_INQUIRY_CP_SIZE 9
466
467 #define OCF_EXIT_PERIODIC_INQUIRY       0x0004
468
469 #define OCF_CREATE_CONN                 0x0005
470 typedef struct {
471     bdaddr_t    bdaddr;
472     uint16_t    pkt_type;
473     uint8_t     pscan_rep_mode;
474     uint8_t     pscan_mode;
475     uint16_t    clock_offset;
476     uint8_t     role_switch;
477 } __attribute__ ((packed)) create_conn_cp;
478 #define CREATE_CONN_CP_SIZE 13
479
480 #define OCF_DISCONNECT                  0x0006
481 typedef struct {
482     uint16_t    handle;
483     uint8_t     reason;
484 } __attribute__ ((packed)) disconnect_cp;
485 #define DISCONNECT_CP_SIZE 3
486
487 #define OCF_ADD_SCO                     0x0007
488 typedef struct {
489     uint16_t    handle;
490     uint16_t    pkt_type;
491 } __attribute__ ((packed)) add_sco_cp;
492 #define ADD_SCO_CP_SIZE 4
493
494 #define OCF_CREATE_CONN_CANCEL          0x0008
495 typedef struct {
496     uint8_t     status;
497     bdaddr_t    bdaddr;
498 } __attribute__ ((packed)) create_conn_cancel_cp;
499 #define CREATE_CONN_CANCEL_CP_SIZE 6
500
501 typedef struct {
502     uint8_t     status;
503     bdaddr_t    bdaddr;
504 } __attribute__ ((packed)) create_conn_cancel_rp;
505 #define CREATE_CONN_CANCEL_RP_SIZE 7
506
507 #define OCF_ACCEPT_CONN_REQ             0x0009
508 typedef struct {
509     bdaddr_t    bdaddr;
510     uint8_t     role;
511 } __attribute__ ((packed)) accept_conn_req_cp;
512 #define ACCEPT_CONN_REQ_CP_SIZE 7
513
514 #define OCF_REJECT_CONN_REQ             0x000A
515 typedef struct {
516     bdaddr_t    bdaddr;
517     uint8_t     reason;
518 } __attribute__ ((packed)) reject_conn_req_cp;
519 #define REJECT_CONN_REQ_CP_SIZE 7
520
521 #define OCF_LINK_KEY_REPLY              0x000B
522 typedef struct {
523     bdaddr_t    bdaddr;
524     uint8_t     link_key[16];
525 } __attribute__ ((packed)) link_key_reply_cp;
526 #define LINK_KEY_REPLY_CP_SIZE 22
527
528 #define OCF_LINK_KEY_NEG_REPLY          0x000C
529
530 #define OCF_PIN_CODE_REPLY              0x000D
531 typedef struct {
532     bdaddr_t    bdaddr;
533     uint8_t     pin_len;
534     uint8_t     pin_code[16];
535 } __attribute__ ((packed)) pin_code_reply_cp;
536 #define PIN_CODE_REPLY_CP_SIZE 23
537
538 #define OCF_PIN_CODE_NEG_REPLY          0x000E
539
540 #define OCF_SET_CONN_PTYPE              0x000F
541 typedef struct {
542     uint16_t     handle;
543     uint16_t     pkt_type;
544 } __attribute__ ((packed)) set_conn_ptype_cp;
545 #define SET_CONN_PTYPE_CP_SIZE 4
546
547 #define OCF_AUTH_REQUESTED              0x0011
548 typedef struct {
549     uint16_t     handle;
550 } __attribute__ ((packed)) auth_requested_cp;
551 #define AUTH_REQUESTED_CP_SIZE 2
552
553 #define OCF_SET_CONN_ENCRYPT            0x0013
554 typedef struct {
555     uint16_t    handle;
556     uint8_t     encrypt;
557 } __attribute__ ((packed)) set_conn_encrypt_cp;
558 #define SET_CONN_ENCRYPT_CP_SIZE 3
559
560 #define OCF_CHANGE_CONN_LINK_KEY        0x0015
561 typedef struct {
562     uint16_t    handle;
563 } __attribute__ ((packed)) change_conn_link_key_cp;
564 #define CHANGE_CONN_LINK_KEY_CP_SIZE 2
565
566 #define OCF_MASTER_LINK_KEY             0x0017
567 typedef struct {
568     uint8_t     key_flag;
569 } __attribute__ ((packed)) master_link_key_cp;
570 #define MASTER_LINK_KEY_CP_SIZE 1
571
572 #define OCF_REMOTE_NAME_REQ             0x0019
573 typedef struct {
574     bdaddr_t    bdaddr;
575     uint8_t     pscan_rep_mode;
576     uint8_t     pscan_mode;
577     uint16_t    clock_offset;
578 } __attribute__ ((packed)) remote_name_req_cp;
579 #define REMOTE_NAME_REQ_CP_SIZE 10
580
581 #define OCF_REMOTE_NAME_REQ_CANCEL      0x001A
582 typedef struct {
583     bdaddr_t    bdaddr;
584 } __attribute__ ((packed)) remote_name_req_cancel_cp;
585 #define REMOTE_NAME_REQ_CANCEL_CP_SIZE 6
586
587 typedef struct {
588     uint8_t             status;
589     bdaddr_t    bdaddr;
590 } __attribute__ ((packed)) remote_name_req_cancel_rp;
591 #define REMOTE_NAME_REQ_CANCEL_RP_SIZE 7
592
593 #define OCF_READ_REMOTE_FEATURES        0x001B
594 typedef struct {
595     uint16_t    handle;
596 } __attribute__ ((packed)) read_remote_features_cp;
597 #define READ_REMOTE_FEATURES_CP_SIZE 2
598
599 #define OCF_READ_REMOTE_EXT_FEATURES    0x001C
600 typedef struct {
601     uint16_t    handle;
602     uint8_t     page_num;
603 } __attribute__ ((packed)) read_remote_ext_features_cp;
604 #define READ_REMOTE_EXT_FEATURES_CP_SIZE 3
605
606 #define OCF_READ_REMOTE_VERSION         0x001D
607 typedef struct {
608     uint16_t    handle;
609 } __attribute__ ((packed)) read_remote_version_cp;
610 #define READ_REMOTE_VERSION_CP_SIZE 2
611
612 #define OCF_READ_CLOCK_OFFSET           0x001F
613 typedef struct {
614     uint16_t    handle;
615 } __attribute__ ((packed)) read_clock_offset_cp;
616 #define READ_CLOCK_OFFSET_CP_SIZE 2
617
618 #define OCF_READ_LMP_HANDLE             0x0020
619 typedef struct {
620     uint16_t    handle;
621 } __attribute__ ((packed)) read_lmp_handle_cp;
622 #define READ_LMP_HANDLE_CP_SIZE 2
623
624 typedef struct {
625     uint8_t     status;
626     uint16_t    handle;
627     uint8_t     lmp_handle;
628     uint32_t    reserved;
629 } __attribute__ ((packed)) read_lmp_handle_rp;
630 #define READ_LMP_HANDLE_RP_SIZE 8
631
632 #define OCF_SETUP_SYNC_CONN             0x0028
633 typedef struct {
634     uint16_t    handle;
635     uint32_t    tx_bandwith;
636     uint32_t    rx_bandwith;
637     uint16_t    max_latency;
638     uint16_t    voice_setting;
639     uint8_t     retrans_effort;
640     uint16_t    pkt_type;
641 } __attribute__ ((packed)) setup_sync_conn_cp;
642 #define SETUP_SYNC_CONN_CP_SIZE 17
643
644 #define OCF_ACCEPT_SYNC_CONN_REQ        0x0029
645 typedef struct {
646     bdaddr_t    bdaddr;
647     uint32_t    tx_bandwith;
648     uint32_t    rx_bandwith;
649     uint16_t    max_latency;
650     uint16_t    voice_setting;
651     uint8_t     retrans_effort;
652     uint16_t    pkt_type;
653 } __attribute__ ((packed)) accept_sync_conn_req_cp;
654 #define ACCEPT_SYNC_CONN_REQ_CP_SIZE 21
655
656 #define OCF_REJECT_SYNC_CONN_REQ        0x002A
657 typedef struct {
658     bdaddr_t    bdaddr;
659     uint8_t     reason;
660 } __attribute__ ((packed)) reject_sync_conn_req_cp;
661 #define REJECT_SYNC_CONN_REQ_CP_SIZE 7
662
663 /* Link Policy */
664 #define OGF_LINK_POLICY         0x02
665
666 #define OCF_HOLD_MODE                   0x0001
667 typedef struct {
668     uint16_t    handle;
669     uint16_t    max_interval;
670     uint16_t    min_interval;
671 } __attribute__ ((packed)) hold_mode_cp;
672 #define HOLD_MODE_CP_SIZE 6
673
674 #define OCF_SNIFF_MODE                  0x0003
675 typedef struct {
676     uint16_t    handle;
677     uint16_t    max_interval;
678     uint16_t    min_interval;
679     uint16_t    attempt;
680     uint16_t    timeout;
681 } __attribute__ ((packed)) sniff_mode_cp;
682 #define SNIFF_MODE_CP_SIZE 10
683
684 #define OCF_EXIT_SNIFF_MODE             0x0004
685 typedef struct {
686     uint16_t    handle;
687 } __attribute__ ((packed)) exit_sniff_mode_cp;
688 #define EXIT_SNIFF_MODE_CP_SIZE 2
689
690 #define OCF_PARK_MODE                   0x0005
691 typedef struct {
692     uint16_t    handle;
693     uint16_t    max_interval;
694     uint16_t    min_interval;
695 } __attribute__ ((packed)) park_mode_cp;
696 #define PARK_MODE_CP_SIZE 6
697
698 #define OCF_EXIT_PARK_MODE              0x0006
699 typedef struct {
700     uint16_t    handle;
701 } __attribute__ ((packed)) exit_park_mode_cp;
702 #define EXIT_PARK_MODE_CP_SIZE 2
703
704 #define OCF_QOS_SETUP                   0x0007
705 typedef struct {
706     uint8_t     service_type;           /* 1 = best effort */
707     uint32_t    token_rate;             /* Byte per seconds */
708     uint32_t    peak_bandwidth;         /* Byte per seconds */
709     uint32_t    latency;                /* Microseconds */
710     uint32_t    delay_variation;        /* Microseconds */
711 } __attribute__ ((packed)) hci_qos;
712 #define HCI_QOS_CP_SIZE 17
713 typedef struct {
714     uint16_t    handle;
715     uint8_t     flags;                  /* Reserved */
716     hci_qos     qos;
717 } __attribute__ ((packed)) qos_setup_cp;
718 #define QOS_SETUP_CP_SIZE (3 + HCI_QOS_CP_SIZE)
719
720 #define OCF_ROLE_DISCOVERY              0x0009
721 typedef struct {
722     uint16_t    handle;
723 } __attribute__ ((packed)) role_discovery_cp;
724 #define ROLE_DISCOVERY_CP_SIZE 2
725 typedef struct {
726     uint8_t     status;
727     uint16_t    handle;
728     uint8_t     role;
729 } __attribute__ ((packed)) role_discovery_rp;
730 #define ROLE_DISCOVERY_RP_SIZE 4
731
732 #define OCF_SWITCH_ROLE                 0x000B
733 typedef struct {
734     bdaddr_t    bdaddr;
735     uint8_t     role;
736 } __attribute__ ((packed)) switch_role_cp;
737 #define SWITCH_ROLE_CP_SIZE 7
738
739 #define OCF_READ_LINK_POLICY            0x000C
740 typedef struct {
741     uint16_t    handle;
742 } __attribute__ ((packed)) read_link_policy_cp;
743 #define READ_LINK_POLICY_CP_SIZE 2
744 typedef struct {
745     uint8_t     status;
746     uint16_t    handle;
747     uint16_t    policy;
748 } __attribute__ ((packed)) read_link_policy_rp;
749 #define READ_LINK_POLICY_RP_SIZE 5
750
751 #define OCF_WRITE_LINK_POLICY           0x000D
752 typedef struct {
753     uint16_t    handle;
754     uint16_t    policy;
755 } __attribute__ ((packed)) write_link_policy_cp;
756 #define WRITE_LINK_POLICY_CP_SIZE 4
757 typedef struct {
758     uint8_t     status;
759     uint16_t    handle;
760 } __attribute__ ((packed)) write_link_policy_rp;
761 #define WRITE_LINK_POLICY_RP_SIZE 3
762
763 #define OCF_READ_DEFAULT_LINK_POLICY    0x000E
764
765 #define OCF_WRITE_DEFAULT_LINK_POLICY   0x000F
766
767 #define OCF_FLOW_SPECIFICATION          0x0010
768
769 #define OCF_SNIFF_SUBRATE               0x0011
770 typedef struct {
771     uint16_t    handle;
772     uint16_t    max_remote_latency;
773     uint16_t    max_local_latency;
774     uint16_t    min_remote_timeout;
775     uint16_t    min_local_timeout;
776 } __attribute__ ((packed)) sniff_subrate_cp;
777 #define SNIFF_SUBRATE_CP_SIZE 10
778
779 /* Host Controller and Baseband */
780 #define OGF_HOST_CTL            0x03
781
782 #define OCF_SET_EVENT_MASK              0x0001
783 typedef struct {
784     uint8_t     mask[8];
785 } __attribute__ ((packed)) set_event_mask_cp;
786 #define SET_EVENT_MASK_CP_SIZE 8
787
788 #define OCF_RESET                       0x0003
789
790 #define OCF_SET_EVENT_FLT               0x0005
791 typedef struct {
792     uint8_t     flt_type;
793     uint8_t     cond_type;
794     uint8_t     condition[0];
795 } __attribute__ ((packed)) set_event_flt_cp;
796 #define SET_EVENT_FLT_CP_SIZE 2
797
798 enum bt_filter_type {
799     FLT_CLEAR_ALL               = 0x00,
800     FLT_INQ_RESULT              = 0x01,
801     FLT_CONN_SETUP              = 0x02,
802 };
803 enum inq_result_cond_type {
804     INQ_RESULT_RETURN_ALL       = 0x00,
805     INQ_RESULT_RETURN_CLASS     = 0x01,
806     INQ_RESULT_RETURN_BDADDR    = 0x02,
807 };
808 enum conn_setup_cond_type {
809     CONN_SETUP_ALLOW_ALL        = 0x00,
810     CONN_SETUP_ALLOW_CLASS      = 0x01,
811     CONN_SETUP_ALLOW_BDADDR     = 0x02,
812 };
813 enum conn_setup_cond {
814     CONN_SETUP_AUTO_OFF         = 0x01,
815     CONN_SETUP_AUTO_ON          = 0x02,
816 };
817
818 #define OCF_FLUSH                       0x0008
819 typedef struct {
820     uint16_t    handle;
821 } __attribute__ ((packed)) flush_cp;
822 #define FLUSH_CP_SIZE 2
823
824 typedef struct {
825     uint8_t     status;
826     uint16_t    handle;
827 } __attribute__ ((packed)) flush_rp;
828 #define FLUSH_RP_SIZE 3
829
830 #define OCF_READ_PIN_TYPE               0x0009
831 typedef struct {
832     uint8_t     status;
833     uint8_t     pin_type;
834 } __attribute__ ((packed)) read_pin_type_rp;
835 #define READ_PIN_TYPE_RP_SIZE 2
836
837 #define OCF_WRITE_PIN_TYPE              0x000A
838 typedef struct {
839     uint8_t     pin_type;
840 } __attribute__ ((packed)) write_pin_type_cp;
841 #define WRITE_PIN_TYPE_CP_SIZE 1
842
843 #define OCF_CREATE_NEW_UNIT_KEY         0x000B
844
845 #define OCF_READ_STORED_LINK_KEY        0x000D
846 typedef struct {
847     bdaddr_t    bdaddr;
848     uint8_t     read_all;
849 } __attribute__ ((packed)) read_stored_link_key_cp;
850 #define READ_STORED_LINK_KEY_CP_SIZE 7
851 typedef struct {
852     uint8_t     status;
853     uint16_t    max_keys;
854     uint16_t    num_keys;
855 } __attribute__ ((packed)) read_stored_link_key_rp;
856 #define READ_STORED_LINK_KEY_RP_SIZE 5
857
858 #define OCF_WRITE_STORED_LINK_KEY       0x0011
859 typedef struct {
860     uint8_t     num_keys;
861     /* variable length part */
862 } __attribute__ ((packed)) write_stored_link_key_cp;
863 #define WRITE_STORED_LINK_KEY_CP_SIZE 1
864 typedef struct {
865     uint8_t     status;
866     uint8_t     num_keys;
867 } __attribute__ ((packed)) write_stored_link_key_rp;
868 #define READ_WRITE_LINK_KEY_RP_SIZE 2
869
870 #define OCF_DELETE_STORED_LINK_KEY      0x0012
871 typedef struct {
872     bdaddr_t    bdaddr;
873     uint8_t     delete_all;
874 } __attribute__ ((packed)) delete_stored_link_key_cp;
875 #define DELETE_STORED_LINK_KEY_CP_SIZE 7
876 typedef struct {
877     uint8_t     status;
878     uint16_t    num_keys;
879 } __attribute__ ((packed)) delete_stored_link_key_rp;
880 #define DELETE_STORED_LINK_KEY_RP_SIZE 3
881
882 #define OCF_CHANGE_LOCAL_NAME           0x0013
883 typedef struct {
884     char        name[248];
885 } __attribute__ ((packed)) change_local_name_cp;
886 #define CHANGE_LOCAL_NAME_CP_SIZE 248 
887
888 #define OCF_READ_LOCAL_NAME             0x0014
889 typedef struct {
890     uint8_t     status;
891     char        name[248];
892 } __attribute__ ((packed)) read_local_name_rp;
893 #define READ_LOCAL_NAME_RP_SIZE 249 
894
895 #define OCF_READ_CONN_ACCEPT_TIMEOUT    0x0015
896 typedef struct {
897     uint8_t     status;
898     uint16_t    timeout;
899 } __attribute__ ((packed)) read_conn_accept_timeout_rp;
900 #define READ_CONN_ACCEPT_TIMEOUT_RP_SIZE 3
901
902 #define OCF_WRITE_CONN_ACCEPT_TIMEOUT   0x0016
903 typedef struct {
904     uint16_t    timeout;
905 } __attribute__ ((packed)) write_conn_accept_timeout_cp;
906 #define WRITE_CONN_ACCEPT_TIMEOUT_CP_SIZE 2
907
908 #define OCF_READ_PAGE_TIMEOUT           0x0017
909 typedef struct {
910     uint8_t     status;
911     uint16_t    timeout;
912 } __attribute__ ((packed)) read_page_timeout_rp;
913 #define READ_PAGE_TIMEOUT_RP_SIZE 3
914
915 #define OCF_WRITE_PAGE_TIMEOUT          0x0018
916 typedef struct {
917     uint16_t    timeout;
918 } __attribute__ ((packed)) write_page_timeout_cp;
919 #define WRITE_PAGE_TIMEOUT_CP_SIZE 2
920
921 #define OCF_READ_SCAN_ENABLE            0x0019
922 typedef struct {
923     uint8_t     status;
924     uint8_t     enable;
925 } __attribute__ ((packed)) read_scan_enable_rp;
926 #define READ_SCAN_ENABLE_RP_SIZE 2
927
928 #define OCF_WRITE_SCAN_ENABLE           0x001A
929 typedef struct {
930     uint8_t     scan_enable;
931 } __attribute__ ((packed)) write_scan_enable_cp;
932 #define WRITE_SCAN_ENABLE_CP_SIZE 1
933
934 enum scan_enable_bits {
935     SCAN_DISABLED               = 0,
936     SCAN_INQUIRY                = 1 << 0,
937     SCAN_PAGE                   = 1 << 1,
938 };
939
940 #define OCF_READ_PAGE_ACTIVITY          0x001B
941 typedef struct {
942     uint8_t     status;
943     uint16_t    interval;
944     uint16_t    window;
945 } __attribute__ ((packed)) read_page_activity_rp;
946 #define READ_PAGE_ACTIVITY_RP_SIZE 5
947
948 #define OCF_WRITE_PAGE_ACTIVITY         0x001C
949 typedef struct {
950     uint16_t    interval;
951     uint16_t    window;
952 } __attribute__ ((packed)) write_page_activity_cp;
953 #define WRITE_PAGE_ACTIVITY_CP_SIZE 4
954
955 #define OCF_READ_INQ_ACTIVITY           0x001D
956 typedef struct {
957     uint8_t     status;
958     uint16_t    interval;
959     uint16_t    window;
960 } __attribute__ ((packed)) read_inq_activity_rp;
961 #define READ_INQ_ACTIVITY_RP_SIZE 5
962
963 #define OCF_WRITE_INQ_ACTIVITY          0x001E
964 typedef struct {
965     uint16_t    interval;
966     uint16_t    window;
967 } __attribute__ ((packed)) write_inq_activity_cp;
968 #define WRITE_INQ_ACTIVITY_CP_SIZE 4
969
970 #define OCF_READ_AUTH_ENABLE            0x001F
971
972 #define OCF_WRITE_AUTH_ENABLE           0x0020
973
974 #define AUTH_DISABLED           0x00
975 #define AUTH_ENABLED            0x01
976
977 #define OCF_READ_ENCRYPT_MODE           0x0021
978
979 #define OCF_WRITE_ENCRYPT_MODE          0x0022
980
981 #define ENCRYPT_DISABLED        0x00
982 #define ENCRYPT_P2P             0x01
983 #define ENCRYPT_BOTH            0x02
984
985 #define OCF_READ_CLASS_OF_DEV           0x0023
986 typedef struct {
987     uint8_t     status;
988     uint8_t     dev_class[3];
989 } __attribute__ ((packed)) read_class_of_dev_rp;
990 #define READ_CLASS_OF_DEV_RP_SIZE 4 
991
992 #define OCF_WRITE_CLASS_OF_DEV          0x0024
993 typedef struct {
994     uint8_t     dev_class[3];
995 } __attribute__ ((packed)) write_class_of_dev_cp;
996 #define WRITE_CLASS_OF_DEV_CP_SIZE 3
997
998 #define OCF_READ_VOICE_SETTING          0x0025
999 typedef struct {
1000     uint8_t     status;
1001     uint16_t    voice_setting;
1002 } __attribute__ ((packed)) read_voice_setting_rp;
1003 #define READ_VOICE_SETTING_RP_SIZE 3
1004
1005 #define OCF_WRITE_VOICE_SETTING         0x0026
1006 typedef struct {
1007     uint16_t    voice_setting;
1008 } __attribute__ ((packed)) write_voice_setting_cp;
1009 #define WRITE_VOICE_SETTING_CP_SIZE 2
1010
1011 #define OCF_READ_AUTOMATIC_FLUSH_TIMEOUT        0x0027
1012
1013 #define OCF_WRITE_AUTOMATIC_FLUSH_TIMEOUT       0x0028
1014
1015 #define OCF_READ_NUM_BROADCAST_RETRANS  0x0029
1016
1017 #define OCF_WRITE_NUM_BROADCAST_RETRANS 0x002A
1018
1019 #define OCF_READ_HOLD_MODE_ACTIVITY     0x002B
1020
1021 #define OCF_WRITE_HOLD_MODE_ACTIVITY    0x002C
1022
1023 #define OCF_READ_TRANSMIT_POWER_LEVEL   0x002D
1024 typedef struct {
1025     uint16_t    handle;
1026     uint8_t     type;
1027 } __attribute__ ((packed)) read_transmit_power_level_cp;
1028 #define READ_TRANSMIT_POWER_LEVEL_CP_SIZE 3
1029 typedef struct {
1030     uint8_t     status;
1031     uint16_t    handle;
1032     int8_t      level;
1033 } __attribute__ ((packed)) read_transmit_power_level_rp;
1034 #define READ_TRANSMIT_POWER_LEVEL_RP_SIZE 4
1035
1036 #define OCF_HOST_BUFFER_SIZE            0x0033
1037 typedef struct {
1038     uint16_t    acl_mtu;
1039     uint8_t     sco_mtu;
1040     uint16_t    acl_max_pkt;
1041     uint16_t    sco_max_pkt;
1042 } __attribute__ ((packed)) host_buffer_size_cp;
1043 #define HOST_BUFFER_SIZE_CP_SIZE 7
1044
1045 #define OCF_HOST_NUMBER_OF_COMPLETED_PACKETS    0x0035
1046
1047 #define OCF_READ_LINK_SUPERVISION_TIMEOUT       0x0036
1048 typedef struct {
1049     uint8_t     status;
1050     uint16_t    handle;
1051     uint16_t    link_sup_to;
1052 } __attribute__ ((packed)) read_link_supervision_timeout_rp;
1053 #define READ_LINK_SUPERVISION_TIMEOUT_RP_SIZE 5
1054
1055 #define OCF_WRITE_LINK_SUPERVISION_TIMEOUT      0x0037
1056 typedef struct {
1057     uint16_t    handle;
1058     uint16_t    link_sup_to;
1059 } __attribute__ ((packed)) write_link_supervision_timeout_cp;
1060 #define WRITE_LINK_SUPERVISION_TIMEOUT_CP_SIZE 4
1061 typedef struct {
1062     uint8_t     status;
1063     uint16_t    handle;
1064 } __attribute__ ((packed)) write_link_supervision_timeout_rp;
1065 #define WRITE_LINK_SUPERVISION_TIMEOUT_RP_SIZE 3
1066
1067 #define OCF_READ_NUM_SUPPORTED_IAC      0x0038
1068
1069 #define MAX_IAC_LAP 0x40
1070 #define OCF_READ_CURRENT_IAC_LAP        0x0039
1071 typedef struct {
1072     uint8_t     status;
1073     uint8_t     num_current_iac;
1074     uint8_t     lap[MAX_IAC_LAP][3];
1075 } __attribute__ ((packed)) read_current_iac_lap_rp;
1076 #define READ_CURRENT_IAC_LAP_RP_SIZE 2+3*MAX_IAC_LAP
1077
1078 #define OCF_WRITE_CURRENT_IAC_LAP       0x003A
1079 typedef struct {
1080     uint8_t     num_current_iac;
1081     uint8_t     lap[MAX_IAC_LAP][3];
1082 } __attribute__ ((packed)) write_current_iac_lap_cp;
1083 #define WRITE_CURRENT_IAC_LAP_CP_SIZE 1+3*MAX_IAC_LAP
1084
1085 #define OCF_READ_PAGE_SCAN_PERIOD_MODE  0x003B
1086
1087 #define OCF_WRITE_PAGE_SCAN_PERIOD_MODE 0x003C
1088
1089 #define OCF_READ_PAGE_SCAN_MODE         0x003D
1090
1091 #define OCF_WRITE_PAGE_SCAN_MODE        0x003E
1092
1093 #define OCF_SET_AFH_CLASSIFICATION      0x003F
1094 typedef struct {
1095     uint8_t     map[10];
1096 } __attribute__ ((packed)) set_afh_classification_cp;
1097 #define SET_AFH_CLASSIFICATION_CP_SIZE 10
1098 typedef struct {
1099     uint8_t     status;
1100 } __attribute__ ((packed)) set_afh_classification_rp;
1101 #define SET_AFH_CLASSIFICATION_RP_SIZE 1
1102
1103 #define OCF_READ_INQUIRY_SCAN_TYPE      0x0042
1104 typedef struct {
1105     uint8_t     status;
1106     uint8_t     type;
1107 } __attribute__ ((packed)) read_inquiry_scan_type_rp;
1108 #define READ_INQUIRY_SCAN_TYPE_RP_SIZE 2
1109
1110 #define OCF_WRITE_INQUIRY_SCAN_TYPE     0x0043
1111 typedef struct {
1112     uint8_t     type;
1113 } __attribute__ ((packed)) write_inquiry_scan_type_cp;
1114 #define WRITE_INQUIRY_SCAN_TYPE_CP_SIZE 1
1115 typedef struct {
1116     uint8_t     status;
1117 } __attribute__ ((packed)) write_inquiry_scan_type_rp;
1118 #define WRITE_INQUIRY_SCAN_TYPE_RP_SIZE 1
1119
1120 #define OCF_READ_INQUIRY_MODE           0x0044
1121 typedef struct {
1122     uint8_t     status;
1123     uint8_t     mode;
1124 } __attribute__ ((packed)) read_inquiry_mode_rp;
1125 #define READ_INQUIRY_MODE_RP_SIZE 2
1126
1127 #define OCF_WRITE_INQUIRY_MODE          0x0045
1128 typedef struct {
1129     uint8_t     mode;
1130 } __attribute__ ((packed)) write_inquiry_mode_cp;
1131 #define WRITE_INQUIRY_MODE_CP_SIZE 1
1132 typedef struct {
1133     uint8_t     status;
1134 } __attribute__ ((packed)) write_inquiry_mode_rp;
1135 #define WRITE_INQUIRY_MODE_RP_SIZE 1
1136
1137 #define OCF_READ_PAGE_SCAN_TYPE         0x0046
1138
1139 #define OCF_WRITE_PAGE_SCAN_TYPE        0x0047
1140
1141 #define OCF_READ_AFH_MODE               0x0048
1142 typedef struct {
1143     uint8_t     status;
1144     uint8_t     mode;
1145 } __attribute__ ((packed)) read_afh_mode_rp;
1146 #define READ_AFH_MODE_RP_SIZE 2
1147
1148 #define OCF_WRITE_AFH_MODE              0x0049
1149 typedef struct {
1150     uint8_t     mode;
1151 } __attribute__ ((packed)) write_afh_mode_cp;
1152 #define WRITE_AFH_MODE_CP_SIZE 1
1153 typedef struct {
1154     uint8_t     status;
1155 } __attribute__ ((packed)) write_afh_mode_rp;
1156 #define WRITE_AFH_MODE_RP_SIZE 1
1157
1158 #define OCF_READ_EXT_INQUIRY_RESPONSE   0x0051
1159 typedef struct {
1160     uint8_t     status;
1161     uint8_t     fec;
1162     uint8_t     data[240];
1163 } __attribute__ ((packed)) read_ext_inquiry_response_rp;
1164 #define READ_EXT_INQUIRY_RESPONSE_RP_SIZE 242
1165
1166 #define OCF_WRITE_EXT_INQUIRY_RESPONSE  0x0052
1167 typedef struct {
1168     uint8_t     fec;
1169     uint8_t     data[240];
1170 } __attribute__ ((packed)) write_ext_inquiry_response_cp;
1171 #define WRITE_EXT_INQUIRY_RESPONSE_CP_SIZE 241
1172 typedef struct {
1173     uint8_t     status;
1174 } __attribute__ ((packed)) write_ext_inquiry_response_rp;
1175 #define WRITE_EXT_INQUIRY_RESPONSE_RP_SIZE 1
1176
1177 /* Informational Parameters */
1178 #define OGF_INFO_PARAM          0x04
1179
1180 #define OCF_READ_LOCAL_VERSION          0x0001
1181 typedef struct {
1182     uint8_t     status;
1183     uint8_t     hci_ver;
1184     uint16_t    hci_rev;
1185     uint8_t     lmp_ver;
1186     uint16_t    manufacturer;
1187     uint16_t    lmp_subver;
1188 } __attribute__ ((packed)) read_local_version_rp;
1189 #define READ_LOCAL_VERSION_RP_SIZE 9
1190
1191 #define OCF_READ_LOCAL_COMMANDS         0x0002
1192 typedef struct {
1193     uint8_t     status;
1194     uint8_t     commands[64];
1195 } __attribute__ ((packed)) read_local_commands_rp;
1196 #define READ_LOCAL_COMMANDS_RP_SIZE 65
1197
1198 #define OCF_READ_LOCAL_FEATURES         0x0003
1199 typedef struct {
1200     uint8_t     status;
1201     uint8_t     features[8];
1202 } __attribute__ ((packed)) read_local_features_rp;
1203 #define READ_LOCAL_FEATURES_RP_SIZE 9
1204
1205 #define OCF_READ_LOCAL_EXT_FEATURES     0x0004
1206 typedef struct {
1207     uint8_t     page_num;
1208 } __attribute__ ((packed)) read_local_ext_features_cp;
1209 #define READ_LOCAL_EXT_FEATURES_CP_SIZE 1
1210 typedef struct {
1211     uint8_t     status;
1212     uint8_t     page_num;
1213     uint8_t     max_page_num;
1214     uint8_t     features[8];
1215 } __attribute__ ((packed)) read_local_ext_features_rp;
1216 #define READ_LOCAL_EXT_FEATURES_RP_SIZE 11
1217
1218 #define OCF_READ_BUFFER_SIZE            0x0005
1219 typedef struct {
1220     uint8_t     status;
1221     uint16_t    acl_mtu;
1222     uint8_t     sco_mtu;
1223     uint16_t    acl_max_pkt;
1224     uint16_t    sco_max_pkt;
1225 } __attribute__ ((packed)) read_buffer_size_rp;
1226 #define READ_BUFFER_SIZE_RP_SIZE 8
1227
1228 #define OCF_READ_COUNTRY_CODE           0x0007
1229 typedef struct {
1230     uint8_t     status;
1231     uint8_t     country_code;
1232 } __attribute__ ((packed)) read_country_code_rp;
1233 #define READ_COUNTRY_CODE_RP_SIZE 2
1234
1235 #define OCF_READ_BD_ADDR                0x0009
1236 typedef struct {
1237     uint8_t     status;
1238     bdaddr_t    bdaddr;
1239 } __attribute__ ((packed)) read_bd_addr_rp;
1240 #define READ_BD_ADDR_RP_SIZE 7
1241
1242 /* Status params */
1243 #define OGF_STATUS_PARAM        0x05
1244
1245 #define OCF_READ_FAILED_CONTACT_COUNTER         0x0001
1246 typedef struct {
1247     uint8_t     status;
1248     uint16_t    handle;
1249     uint8_t     counter;
1250 } __attribute__ ((packed)) read_failed_contact_counter_rp;
1251 #define READ_FAILED_CONTACT_COUNTER_RP_SIZE 4
1252
1253 #define OCF_RESET_FAILED_CONTACT_COUNTER        0x0002
1254 typedef struct {
1255     uint8_t     status;
1256     uint16_t    handle;
1257 } __attribute__ ((packed)) reset_failed_contact_counter_rp;
1258 #define RESET_FAILED_CONTACT_COUNTER_RP_SIZE 4
1259
1260 #define OCF_READ_LINK_QUALITY           0x0003
1261 typedef struct {
1262     uint16_t    handle;
1263 } __attribute__ ((packed)) read_link_quality_cp;
1264 #define READ_LINK_QUALITY_CP_SIZE 4
1265
1266 typedef struct {
1267     uint8_t     status;
1268     uint16_t    handle;
1269     uint8_t     link_quality;
1270 } __attribute__ ((packed)) read_link_quality_rp;
1271 #define READ_LINK_QUALITY_RP_SIZE 4
1272
1273 #define OCF_READ_RSSI                   0x0005
1274 typedef struct {
1275     uint8_t     status;
1276     uint16_t    handle;
1277     int8_t      rssi;
1278 } __attribute__ ((packed)) read_rssi_rp;
1279 #define READ_RSSI_RP_SIZE 4
1280
1281 #define OCF_READ_AFH_MAP                0x0006
1282 typedef struct {
1283     uint8_t     status;
1284     uint16_t    handle;
1285     uint8_t     mode;
1286     uint8_t     map[10];
1287 } __attribute__ ((packed)) read_afh_map_rp;
1288 #define READ_AFH_MAP_RP_SIZE 14
1289
1290 #define OCF_READ_CLOCK                  0x0007
1291 typedef struct {
1292     uint16_t    handle;
1293     uint8_t     which_clock;
1294 } __attribute__ ((packed)) read_clock_cp;
1295 #define READ_CLOCK_CP_SIZE 3
1296 typedef struct {
1297     uint8_t     status;
1298     uint16_t    handle;
1299     uint32_t    clock;
1300     uint16_t    accuracy;
1301 } __attribute__ ((packed)) read_clock_rp;
1302 #define READ_CLOCK_RP_SIZE 9
1303
1304 /* Testing commands */
1305 #define OGF_TESTING_CMD         0x3e
1306
1307 /* Vendor specific commands */
1308 #define OGF_VENDOR_CMD          0x3f
1309
1310 /* HCI Events */
1311
1312 #define EVT_INQUIRY_COMPLETE            0x01
1313
1314 #define EVT_INQUIRY_RESULT              0x02
1315 typedef struct {
1316     uint8_t     num_responses;
1317     bdaddr_t    bdaddr;
1318     uint8_t     pscan_rep_mode;
1319     uint8_t     pscan_period_mode;
1320     uint8_t     pscan_mode;
1321     uint8_t     dev_class[3];
1322     uint16_t    clock_offset;
1323 } __attribute__ ((packed)) inquiry_info;
1324 #define INQUIRY_INFO_SIZE 14
1325
1326 #define EVT_CONN_COMPLETE               0x03
1327 typedef struct {
1328     uint8_t     status;
1329     uint16_t    handle;
1330     bdaddr_t    bdaddr;
1331     uint8_t     link_type;
1332     uint8_t     encr_mode;
1333 } __attribute__ ((packed)) evt_conn_complete;
1334 #define EVT_CONN_COMPLETE_SIZE 11
1335
1336 #define EVT_CONN_REQUEST                0x04
1337 typedef struct {
1338     bdaddr_t    bdaddr;
1339     uint8_t     dev_class[3];
1340     uint8_t     link_type;
1341 } __attribute__ ((packed)) evt_conn_request;
1342 #define EVT_CONN_REQUEST_SIZE 10
1343
1344 #define EVT_DISCONN_COMPLETE            0x05
1345 typedef struct {
1346     uint8_t     status;
1347     uint16_t    handle;
1348     uint8_t     reason;
1349 } __attribute__ ((packed)) evt_disconn_complete;
1350 #define EVT_DISCONN_COMPLETE_SIZE 4
1351
1352 #define EVT_AUTH_COMPLETE               0x06
1353 typedef struct {
1354     uint8_t     status;
1355     uint16_t    handle;
1356 } __attribute__ ((packed)) evt_auth_complete;
1357 #define EVT_AUTH_COMPLETE_SIZE 3
1358
1359 #define EVT_REMOTE_NAME_REQ_COMPLETE    0x07
1360 typedef struct {
1361     uint8_t     status;
1362     bdaddr_t    bdaddr;
1363     char        name[248];
1364 } __attribute__ ((packed)) evt_remote_name_req_complete;
1365 #define EVT_REMOTE_NAME_REQ_COMPLETE_SIZE 255
1366
1367 #define EVT_ENCRYPT_CHANGE              0x08
1368 typedef struct {
1369     uint8_t     status;
1370     uint16_t    handle;
1371     uint8_t     encrypt;
1372 } __attribute__ ((packed)) evt_encrypt_change;
1373 #define EVT_ENCRYPT_CHANGE_SIZE 5
1374
1375 #define EVT_CHANGE_CONN_LINK_KEY_COMPLETE       0x09
1376 typedef struct {
1377     uint8_t     status;
1378     uint16_t    handle;
1379 }  __attribute__ ((packed)) evt_change_conn_link_key_complete;
1380 #define EVT_CHANGE_CONN_LINK_KEY_COMPLETE_SIZE 3
1381
1382 #define EVT_MASTER_LINK_KEY_COMPLETE            0x0A
1383 typedef struct {
1384     uint8_t     status;
1385     uint16_t    handle;
1386     uint8_t     key_flag;
1387 } __attribute__ ((packed)) evt_master_link_key_complete;
1388 #define EVT_MASTER_LINK_KEY_COMPLETE_SIZE 4
1389
1390 #define EVT_READ_REMOTE_FEATURES_COMPLETE       0x0B
1391 typedef struct {
1392     uint8_t     status;
1393     uint16_t    handle;
1394     uint8_t     features[8];
1395 } __attribute__ ((packed)) evt_read_remote_features_complete;
1396 #define EVT_READ_REMOTE_FEATURES_COMPLETE_SIZE 11
1397
1398 #define EVT_READ_REMOTE_VERSION_COMPLETE        0x0C
1399 typedef struct {
1400     uint8_t     status;
1401     uint16_t    handle;
1402     uint8_t     lmp_ver;
1403     uint16_t    manufacturer;
1404     uint16_t    lmp_subver;
1405 } __attribute__ ((packed)) evt_read_remote_version_complete;
1406 #define EVT_READ_REMOTE_VERSION_COMPLETE_SIZE 8
1407
1408 #define EVT_QOS_SETUP_COMPLETE          0x0D
1409 typedef struct {
1410     uint8_t     status;
1411     uint16_t    handle;
1412     uint8_t     flags;                  /* Reserved */
1413     hci_qos     qos;
1414 } __attribute__ ((packed)) evt_qos_setup_complete;
1415 #define EVT_QOS_SETUP_COMPLETE_SIZE (4 + HCI_QOS_CP_SIZE)
1416
1417 #define EVT_CMD_COMPLETE                0x0E
1418 typedef struct {
1419     uint8_t     ncmd;
1420     uint16_t    opcode;
1421 } __attribute__ ((packed)) evt_cmd_complete;
1422 #define EVT_CMD_COMPLETE_SIZE 3
1423
1424 #define EVT_CMD_STATUS                  0x0F
1425 typedef struct {
1426     uint8_t     status;
1427     uint8_t     ncmd;
1428     uint16_t    opcode;
1429 } __attribute__ ((packed)) evt_cmd_status;
1430 #define EVT_CMD_STATUS_SIZE 4
1431
1432 #define EVT_HARDWARE_ERROR              0x10
1433 typedef struct {
1434     uint8_t     code;
1435 } __attribute__ ((packed)) evt_hardware_error;
1436 #define EVT_HARDWARE_ERROR_SIZE 1
1437
1438 #define EVT_FLUSH_OCCURRED              0x11
1439 typedef struct {
1440     uint16_t    handle;
1441 } __attribute__ ((packed)) evt_flush_occured;
1442 #define EVT_FLUSH_OCCURRED_SIZE 2
1443
1444 #define EVT_ROLE_CHANGE                 0x12
1445 typedef struct {
1446     uint8_t     status;
1447     bdaddr_t    bdaddr;
1448     uint8_t     role;
1449 } __attribute__ ((packed)) evt_role_change;
1450 #define EVT_ROLE_CHANGE_SIZE 8
1451
1452 #define EVT_NUM_COMP_PKTS               0x13
1453 typedef struct {
1454     uint8_t     num_hndl;
1455     struct {
1456         uint16_t handle;
1457         uint16_t num_packets;
1458     } connection[0];
1459 } __attribute__ ((packed)) evt_num_comp_pkts;
1460 #define EVT_NUM_COMP_PKTS_SIZE(num_hndl) (1 + 4 * (num_hndl))
1461
1462 #define EVT_MODE_CHANGE                 0x14
1463 typedef struct {
1464     uint8_t     status;
1465     uint16_t    handle;
1466     uint8_t     mode;
1467     uint16_t    interval;
1468 } __attribute__ ((packed)) evt_mode_change;
1469 #define EVT_MODE_CHANGE_SIZE 6
1470
1471 #define EVT_RETURN_LINK_KEYS            0x15
1472 typedef struct {
1473     uint8_t     num_keys;
1474     /* variable length part */
1475 } __attribute__ ((packed)) evt_return_link_keys;
1476 #define EVT_RETURN_LINK_KEYS_SIZE 1
1477
1478 #define EVT_PIN_CODE_REQ                0x16
1479 typedef struct {
1480     bdaddr_t    bdaddr;
1481 } __attribute__ ((packed)) evt_pin_code_req;
1482 #define EVT_PIN_CODE_REQ_SIZE 6
1483
1484 #define EVT_LINK_KEY_REQ                0x17
1485 typedef struct {
1486     bdaddr_t    bdaddr;
1487 } __attribute__ ((packed)) evt_link_key_req;
1488 #define EVT_LINK_KEY_REQ_SIZE 6
1489
1490 #define EVT_LINK_KEY_NOTIFY             0x18
1491 typedef struct {
1492     bdaddr_t    bdaddr;
1493     uint8_t     link_key[16];
1494     uint8_t     key_type;
1495 } __attribute__ ((packed)) evt_link_key_notify;
1496 #define EVT_LINK_KEY_NOTIFY_SIZE 23
1497
1498 #define EVT_LOOPBACK_COMMAND            0x19
1499
1500 #define EVT_DATA_BUFFER_OVERFLOW        0x1A
1501 typedef struct {
1502     uint8_t     link_type;
1503 } __attribute__ ((packed)) evt_data_buffer_overflow;
1504 #define EVT_DATA_BUFFER_OVERFLOW_SIZE 1
1505
1506 #define EVT_MAX_SLOTS_CHANGE            0x1B
1507 typedef struct {
1508     uint16_t    handle;
1509     uint8_t     max_slots;
1510 } __attribute__ ((packed)) evt_max_slots_change;
1511 #define EVT_MAX_SLOTS_CHANGE_SIZE 3
1512
1513 #define EVT_READ_CLOCK_OFFSET_COMPLETE  0x1C
1514 typedef struct {
1515     uint8_t     status;
1516     uint16_t    handle;
1517     uint16_t    clock_offset;
1518 } __attribute__ ((packed)) evt_read_clock_offset_complete;
1519 #define EVT_READ_CLOCK_OFFSET_COMPLETE_SIZE 5
1520
1521 #define EVT_CONN_PTYPE_CHANGED          0x1D
1522 typedef struct {
1523     uint8_t     status;
1524     uint16_t    handle;
1525     uint16_t    ptype;
1526 } __attribute__ ((packed)) evt_conn_ptype_changed;
1527 #define EVT_CONN_PTYPE_CHANGED_SIZE 5
1528
1529 #define EVT_QOS_VIOLATION               0x1E
1530 typedef struct {
1531     uint16_t    handle;
1532 } __attribute__ ((packed)) evt_qos_violation;
1533 #define EVT_QOS_VIOLATION_SIZE 2
1534
1535 #define EVT_PSCAN_REP_MODE_CHANGE       0x20
1536 typedef struct {
1537     bdaddr_t    bdaddr;
1538     uint8_t     pscan_rep_mode;
1539 } __attribute__ ((packed)) evt_pscan_rep_mode_change;
1540 #define EVT_PSCAN_REP_MODE_CHANGE_SIZE 7
1541
1542 #define EVT_FLOW_SPEC_COMPLETE          0x21
1543 typedef struct {
1544     uint8_t     status;
1545     uint16_t    handle;
1546     uint8_t     flags;
1547     uint8_t     direction;
1548     hci_qos     qos;
1549 } __attribute__ ((packed)) evt_flow_spec_complete;
1550 #define EVT_FLOW_SPEC_COMPLETE_SIZE (5 + HCI_QOS_CP_SIZE)
1551
1552 #define EVT_INQUIRY_RESULT_WITH_RSSI    0x22
1553 typedef struct {
1554     uint8_t     num_responses;
1555     bdaddr_t    bdaddr;
1556     uint8_t     pscan_rep_mode;
1557     uint8_t     pscan_period_mode;
1558     uint8_t     dev_class[3];
1559     uint16_t    clock_offset;
1560     int8_t      rssi;
1561 } __attribute__ ((packed)) inquiry_info_with_rssi;
1562 #define INQUIRY_INFO_WITH_RSSI_SIZE 15
1563 typedef struct {
1564     uint8_t     num_responses;
1565     bdaddr_t    bdaddr;
1566     uint8_t     pscan_rep_mode;
1567     uint8_t     pscan_period_mode;
1568     uint8_t     pscan_mode;
1569     uint8_t     dev_class[3];
1570     uint16_t    clock_offset;
1571     int8_t      rssi;
1572 } __attribute__ ((packed)) inquiry_info_with_rssi_and_pscan_mode;
1573 #define INQUIRY_INFO_WITH_RSSI_AND_PSCAN_MODE_SIZE 16
1574
1575 #define EVT_READ_REMOTE_EXT_FEATURES_COMPLETE   0x23
1576 typedef struct {
1577     uint8_t     status;
1578     uint16_t    handle;
1579     uint8_t     page_num;
1580     uint8_t     max_page_num;
1581     uint8_t     features[8];
1582 } __attribute__ ((packed)) evt_read_remote_ext_features_complete;
1583 #define EVT_READ_REMOTE_EXT_FEATURES_COMPLETE_SIZE 13
1584
1585 #define EVT_SYNC_CONN_COMPLETE          0x2C
1586 typedef struct {
1587     uint8_t     status;
1588     uint16_t    handle;
1589     bdaddr_t    bdaddr;
1590     uint8_t     link_type;
1591     uint8_t     trans_interval;
1592     uint8_t     retrans_window;
1593     uint16_t    rx_pkt_len;
1594     uint16_t    tx_pkt_len;
1595     uint8_t     air_mode;
1596 } __attribute__ ((packed)) evt_sync_conn_complete;
1597 #define EVT_SYNC_CONN_COMPLETE_SIZE 17
1598
1599 #define EVT_SYNC_CONN_CHANGED           0x2D
1600 typedef struct {
1601     uint8_t     status;
1602     uint16_t    handle;
1603     uint8_t     trans_interval;
1604     uint8_t     retrans_window;
1605     uint16_t    rx_pkt_len;
1606     uint16_t    tx_pkt_len;
1607 } __attribute__ ((packed)) evt_sync_conn_changed;
1608 #define EVT_SYNC_CONN_CHANGED_SIZE 9
1609
1610 #define EVT_SNIFF_SUBRATE               0x2E
1611 typedef struct {
1612     uint8_t     status;
1613     uint16_t    handle;
1614     uint16_t    max_remote_latency;
1615     uint16_t    max_local_latency;
1616     uint16_t    min_remote_timeout;
1617     uint16_t    min_local_timeout;
1618 } __attribute__ ((packed)) evt_sniff_subrate;
1619 #define EVT_SNIFF_SUBRATE_SIZE 11
1620
1621 #define EVT_EXTENDED_INQUIRY_RESULT     0x2F
1622 typedef struct {
1623     bdaddr_t    bdaddr;
1624     uint8_t     pscan_rep_mode;
1625     uint8_t     pscan_period_mode;
1626     uint8_t     dev_class[3];
1627     uint16_t    clock_offset;
1628     int8_t      rssi;
1629     uint8_t     data[240];
1630 } __attribute__ ((packed)) extended_inquiry_info;
1631 #define EXTENDED_INQUIRY_INFO_SIZE 254
1632
1633 #define EVT_TESTING                     0xFE
1634
1635 #define EVT_VENDOR                      0xFF
1636
1637 /* Command opcode pack/unpack */
1638 #define cmd_opcode_pack(ogf, ocf)       (uint16_t)((ocf & 0x03ff)|(ogf << 10))
1639 #define cmd_opcode_ogf(op)              (op >> 10)
1640 #define cmd_opcode_ocf(op)              (op & 0x03ff)
1641
1642 /* ACL handle and flags pack/unpack */
1643 #define acl_handle_pack(h, f)   (uint16_t)(((h) & 0x0fff)|((f) << 12))
1644 #define acl_handle(h)           ((h) & 0x0fff)
1645 #define acl_flags(h)            ((h) >> 12)
1646
1647 /* HCI Packet structures */
1648 #define HCI_COMMAND_HDR_SIZE    3
1649 #define HCI_EVENT_HDR_SIZE      2
1650 #define HCI_ACL_HDR_SIZE        4
1651 #define HCI_SCO_HDR_SIZE        3
1652
1653 struct hci_command_hdr {
1654     uint16_t    opcode;         /* OCF & OGF */
1655     uint8_t     plen;
1656 } __attribute__ ((packed));
1657
1658 struct hci_event_hdr {
1659     uint8_t     evt;
1660     uint8_t     plen;
1661 } __attribute__ ((packed));
1662
1663 struct hci_acl_hdr {
1664     uint16_t    handle;         /* Handle & Flags(PB, BC) */
1665     uint16_t    dlen;
1666 } __attribute__ ((packed));
1667
1668 struct hci_sco_hdr {
1669     uint16_t    handle;
1670     uint8_t     dlen;
1671 } __attribute__ ((packed));
1672
1673 /* L2CAP layer defines */
1674
1675 enum bt_l2cap_lm_bits {
1676     L2CAP_LM_MASTER     = 1 << 0,
1677     L2CAP_LM_AUTH       = 1 << 1,
1678     L2CAP_LM_ENCRYPT    = 1 << 2,
1679     L2CAP_LM_TRUSTED    = 1 << 3,
1680     L2CAP_LM_RELIABLE   = 1 << 4,
1681     L2CAP_LM_SECURE     = 1 << 5,
1682 };
1683
1684 enum bt_l2cap_cid_predef {
1685     L2CAP_CID_INVALID   = 0x0000,
1686     L2CAP_CID_SIGNALLING= 0x0001,
1687     L2CAP_CID_GROUP     = 0x0002,
1688     L2CAP_CID_ALLOC     = 0x0040,
1689 };
1690
1691 /* L2CAP command codes */
1692 enum bt_l2cap_cmd {
1693     L2CAP_COMMAND_REJ   = 1,
1694     L2CAP_CONN_REQ,
1695     L2CAP_CONN_RSP,
1696     L2CAP_CONF_REQ,
1697     L2CAP_CONF_RSP,
1698     L2CAP_DISCONN_REQ,
1699     L2CAP_DISCONN_RSP,
1700     L2CAP_ECHO_REQ,
1701     L2CAP_ECHO_RSP,
1702     L2CAP_INFO_REQ,
1703     L2CAP_INFO_RSP,
1704 };
1705
1706 enum bt_l2cap_sar_bits {
1707     L2CAP_SAR_NO_SEG    = 0,
1708     L2CAP_SAR_START,
1709     L2CAP_SAR_END,
1710     L2CAP_SAR_CONT,
1711 };
1712
1713 /* L2CAP structures */
1714 typedef struct {
1715     uint16_t    len;
1716     uint16_t    cid;
1717     uint8_t     data[0];
1718 } __attribute__ ((packed)) l2cap_hdr;
1719 #define L2CAP_HDR_SIZE 4
1720
1721 typedef struct {
1722     uint8_t     code;
1723     uint8_t     ident;
1724     uint16_t    len;
1725 } __attribute__ ((packed)) l2cap_cmd_hdr;
1726 #define L2CAP_CMD_HDR_SIZE 4
1727
1728 typedef struct {
1729     uint16_t    reason;
1730 } __attribute__ ((packed)) l2cap_cmd_rej;
1731 #define L2CAP_CMD_REJ_SIZE 2
1732
1733 typedef struct {
1734     uint16_t    dcid;
1735     uint16_t    scid;
1736 } __attribute__ ((packed)) l2cap_cmd_rej_cid;
1737 #define L2CAP_CMD_REJ_CID_SIZE 4
1738
1739 /* reject reason */
1740 enum bt_l2cap_rej_reason {
1741     L2CAP_REJ_CMD_NOT_UNDERSTOOD = 0,
1742     L2CAP_REJ_SIG_TOOBIG,
1743     L2CAP_REJ_CID_INVAL,
1744 };
1745
1746 typedef struct {
1747     uint16_t    psm;
1748     uint16_t    scid;
1749 } __attribute__ ((packed)) l2cap_conn_req;
1750 #define L2CAP_CONN_REQ_SIZE 4
1751
1752 typedef struct {
1753     uint16_t    dcid;
1754     uint16_t    scid;
1755     uint16_t    result;
1756     uint16_t    status;
1757 } __attribute__ ((packed)) l2cap_conn_rsp;
1758 #define L2CAP_CONN_RSP_SIZE 8
1759
1760 /* connect result */
1761 enum bt_l2cap_conn_res {
1762     L2CAP_CR_SUCCESS    = 0,
1763     L2CAP_CR_PEND,
1764     L2CAP_CR_BAD_PSM,
1765     L2CAP_CR_SEC_BLOCK,
1766     L2CAP_CR_NO_MEM,
1767 };
1768
1769 /* connect status */
1770 enum bt_l2cap_conn_stat {
1771     L2CAP_CS_NO_INFO    = 0,
1772     L2CAP_CS_AUTHEN_PEND,
1773     L2CAP_CS_AUTHOR_PEND,
1774 };
1775
1776 typedef struct {
1777     uint16_t    dcid;
1778     uint16_t    flags;
1779     uint8_t     data[0];
1780 } __attribute__ ((packed)) l2cap_conf_req;
1781 #define L2CAP_CONF_REQ_SIZE(datalen) (4 + (datalen))
1782
1783 typedef struct {
1784     uint16_t    scid;
1785     uint16_t    flags;
1786     uint16_t    result;
1787     uint8_t     data[0];
1788 } __attribute__ ((packed)) l2cap_conf_rsp;
1789 #define L2CAP_CONF_RSP_SIZE(datalen) (6 + datalen)
1790
1791 enum bt_l2cap_conf_res {
1792     L2CAP_CONF_SUCCESS  = 0,
1793     L2CAP_CONF_UNACCEPT,
1794     L2CAP_CONF_REJECT,
1795     L2CAP_CONF_UNKNOWN,
1796 };
1797
1798 typedef struct {
1799     uint8_t     type;
1800     uint8_t     len;
1801     uint8_t     val[0];
1802 } __attribute__ ((packed)) l2cap_conf_opt;
1803 #define L2CAP_CONF_OPT_SIZE 2
1804
1805 enum bt_l2cap_conf_val {
1806     L2CAP_CONF_MTU      = 1,
1807     L2CAP_CONF_FLUSH_TO,
1808     L2CAP_CONF_QOS,
1809     L2CAP_CONF_RFC,
1810     L2CAP_CONF_RFC_MODE = L2CAP_CONF_RFC,
1811 };
1812
1813 typedef struct {
1814     uint8_t     flags;
1815     uint8_t     service_type;
1816     uint32_t    token_rate;
1817     uint32_t    token_bucket_size;
1818     uint32_t    peak_bandwidth;
1819     uint32_t    latency;
1820     uint32_t    delay_variation;
1821 } __attribute__ ((packed)) l2cap_conf_opt_qos;
1822 #define L2CAP_CONF_OPT_QOS_SIZE 22
1823
1824 enum bt_l2cap_conf_opt_qos_st {
1825     L2CAP_CONF_QOS_NO_TRAFFIC = 0x00,
1826     L2CAP_CONF_QOS_BEST_EFFORT,
1827     L2CAP_CONF_QOS_GUARANTEED,
1828 };
1829
1830 #define L2CAP_CONF_QOS_WILDCARD 0xffffffff
1831
1832 enum bt_l2cap_mode {
1833     L2CAP_MODE_BASIC    = 0,
1834     L2CAP_MODE_RETRANS  = 1,
1835     L2CAP_MODE_FLOWCTL  = 2,
1836 };
1837
1838 typedef struct {
1839     uint16_t    dcid;
1840     uint16_t    scid;
1841 } __attribute__ ((packed)) l2cap_disconn_req;
1842 #define L2CAP_DISCONN_REQ_SIZE 4
1843
1844 typedef struct {
1845     uint16_t    dcid;
1846     uint16_t    scid;
1847 } __attribute__ ((packed)) l2cap_disconn_rsp;
1848 #define L2CAP_DISCONN_RSP_SIZE 4
1849
1850 typedef struct {
1851     uint16_t    type;
1852 } __attribute__ ((packed)) l2cap_info_req;
1853 #define L2CAP_INFO_REQ_SIZE 2
1854
1855 typedef struct {
1856     uint16_t    type;
1857     uint16_t    result;
1858     uint8_t     data[0];
1859 } __attribute__ ((packed)) l2cap_info_rsp;
1860 #define L2CAP_INFO_RSP_SIZE 4
1861
1862 /* info type */
1863 enum bt_l2cap_info_type {
1864     L2CAP_IT_CL_MTU     = 1,
1865     L2CAP_IT_FEAT_MASK,
1866 };
1867
1868 /* info result */
1869 enum bt_l2cap_info_result {
1870     L2CAP_IR_SUCCESS    = 0,
1871     L2CAP_IR_NOTSUPP,
1872 };
1873
1874 /* Service Discovery Protocol defines */
1875 /* Note that all multibyte values in lower layer protocols (above in this file)
1876  * are little-endian while SDP is big-endian.  */
1877
1878 /* Protocol UUIDs */
1879 enum sdp_proto_uuid {
1880     SDP_UUID            = 0x0001,
1881     UDP_UUID            = 0x0002,
1882     RFCOMM_UUID         = 0x0003,
1883     TCP_UUID            = 0x0004,
1884     TCS_BIN_UUID        = 0x0005,
1885     TCS_AT_UUID         = 0x0006,
1886     OBEX_UUID           = 0x0008,
1887     IP_UUID             = 0x0009,
1888     FTP_UUID            = 0x000a,
1889     HTTP_UUID           = 0x000c,
1890     WSP_UUID            = 0x000e,
1891     BNEP_UUID           = 0x000f,
1892     UPNP_UUID           = 0x0010,
1893     HIDP_UUID           = 0x0011,
1894     HCRP_CTRL_UUID      = 0x0012,
1895     HCRP_DATA_UUID      = 0x0014,
1896     HCRP_NOTE_UUID      = 0x0016,
1897     AVCTP_UUID          = 0x0017,
1898     AVDTP_UUID          = 0x0019,
1899     CMTP_UUID           = 0x001b,
1900     UDI_UUID            = 0x001d,
1901     MCAP_CTRL_UUID      = 0x001e,
1902     MCAP_DATA_UUID      = 0x001f,
1903     L2CAP_UUID          = 0x0100,
1904 };
1905
1906 /*
1907  * Service class identifiers of standard services and service groups
1908  */
1909 enum service_class_id {
1910     SDP_SERVER_SVCLASS_ID               = 0x1000,
1911     BROWSE_GRP_DESC_SVCLASS_ID          = 0x1001,
1912     PUBLIC_BROWSE_GROUP                 = 0x1002,
1913     SERIAL_PORT_SVCLASS_ID              = 0x1101,
1914     LAN_ACCESS_SVCLASS_ID               = 0x1102,
1915     DIALUP_NET_SVCLASS_ID               = 0x1103,
1916     IRMC_SYNC_SVCLASS_ID                = 0x1104,
1917     OBEX_OBJPUSH_SVCLASS_ID             = 0x1105,
1918     OBEX_FILETRANS_SVCLASS_ID           = 0x1106,
1919     IRMC_SYNC_CMD_SVCLASS_ID            = 0x1107,
1920     HEADSET_SVCLASS_ID                  = 0x1108,
1921     CORDLESS_TELEPHONY_SVCLASS_ID       = 0x1109,
1922     AUDIO_SOURCE_SVCLASS_ID             = 0x110a,
1923     AUDIO_SINK_SVCLASS_ID               = 0x110b,
1924     AV_REMOTE_TARGET_SVCLASS_ID         = 0x110c,
1925     ADVANCED_AUDIO_SVCLASS_ID           = 0x110d,
1926     AV_REMOTE_SVCLASS_ID                = 0x110e,
1927     VIDEO_CONF_SVCLASS_ID               = 0x110f,
1928     INTERCOM_SVCLASS_ID                 = 0x1110,
1929     FAX_SVCLASS_ID                      = 0x1111,
1930     HEADSET_AGW_SVCLASS_ID              = 0x1112,
1931     WAP_SVCLASS_ID                      = 0x1113,
1932     WAP_CLIENT_SVCLASS_ID               = 0x1114,
1933     PANU_SVCLASS_ID                     = 0x1115,
1934     NAP_SVCLASS_ID                      = 0x1116,
1935     GN_SVCLASS_ID                       = 0x1117,
1936     DIRECT_PRINTING_SVCLASS_ID          = 0x1118,
1937     REFERENCE_PRINTING_SVCLASS_ID       = 0x1119,
1938     IMAGING_SVCLASS_ID                  = 0x111a,
1939     IMAGING_RESPONDER_SVCLASS_ID        = 0x111b,
1940     IMAGING_ARCHIVE_SVCLASS_ID          = 0x111c,
1941     IMAGING_REFOBJS_SVCLASS_ID          = 0x111d,
1942     HANDSFREE_SVCLASS_ID                = 0x111e,
1943     HANDSFREE_AGW_SVCLASS_ID            = 0x111f,
1944     DIRECT_PRT_REFOBJS_SVCLASS_ID       = 0x1120,
1945     REFLECTED_UI_SVCLASS_ID             = 0x1121,
1946     BASIC_PRINTING_SVCLASS_ID           = 0x1122,
1947     PRINTING_STATUS_SVCLASS_ID          = 0x1123,
1948     HID_SVCLASS_ID                      = 0x1124,
1949     HCR_SVCLASS_ID                      = 0x1125,
1950     HCR_PRINT_SVCLASS_ID                = 0x1126,
1951     HCR_SCAN_SVCLASS_ID                 = 0x1127,
1952     CIP_SVCLASS_ID                      = 0x1128,
1953     VIDEO_CONF_GW_SVCLASS_ID            = 0x1129,
1954     UDI_MT_SVCLASS_ID                   = 0x112a,
1955     UDI_TA_SVCLASS_ID                   = 0x112b,
1956     AV_SVCLASS_ID                       = 0x112c,
1957     SAP_SVCLASS_ID                      = 0x112d,
1958     PBAP_PCE_SVCLASS_ID                 = 0x112e,
1959     PBAP_PSE_SVCLASS_ID                 = 0x112f,
1960     PBAP_SVCLASS_ID                     = 0x1130,
1961     PNP_INFO_SVCLASS_ID                 = 0x1200,
1962     GENERIC_NETWORKING_SVCLASS_ID       = 0x1201,
1963     GENERIC_FILETRANS_SVCLASS_ID        = 0x1202,
1964     GENERIC_AUDIO_SVCLASS_ID            = 0x1203,
1965     GENERIC_TELEPHONY_SVCLASS_ID        = 0x1204,
1966     UPNP_SVCLASS_ID                     = 0x1205,
1967     UPNP_IP_SVCLASS_ID                  = 0x1206,
1968     UPNP_PAN_SVCLASS_ID                 = 0x1300,
1969     UPNP_LAP_SVCLASS_ID                 = 0x1301,
1970     UPNP_L2CAP_SVCLASS_ID               = 0x1302,
1971     VIDEO_SOURCE_SVCLASS_ID             = 0x1303,
1972     VIDEO_SINK_SVCLASS_ID               = 0x1304,
1973     VIDEO_DISTRIBUTION_SVCLASS_ID       = 0x1305,
1974     MDP_SVCLASS_ID                      = 0x1400,
1975     MDP_SOURCE_SVCLASS_ID               = 0x1401,
1976     MDP_SINK_SVCLASS_ID                 = 0x1402,
1977     APPLE_AGENT_SVCLASS_ID              = 0x2112,
1978 };
1979
1980 /*
1981  * Standard profile descriptor identifiers; note these
1982  * may be identical to some of the service classes defined above
1983  */
1984 #define SDP_SERVER_PROFILE_ID           SDP_SERVER_SVCLASS_ID
1985 #define BROWSE_GRP_DESC_PROFILE_ID      BROWSE_GRP_DESC_SVCLASS_ID
1986 #define SERIAL_PORT_PROFILE_ID          SERIAL_PORT_SVCLASS_ID
1987 #define LAN_ACCESS_PROFILE_ID           LAN_ACCESS_SVCLASS_ID
1988 #define DIALUP_NET_PROFILE_ID           DIALUP_NET_SVCLASS_ID
1989 #define IRMC_SYNC_PROFILE_ID            IRMC_SYNC_SVCLASS_ID
1990 #define OBEX_OBJPUSH_PROFILE_ID         OBEX_OBJPUSH_SVCLASS_ID
1991 #define OBEX_FILETRANS_PROFILE_ID       OBEX_FILETRANS_SVCLASS_ID
1992 #define IRMC_SYNC_CMD_PROFILE_ID        IRMC_SYNC_CMD_SVCLASS_ID
1993 #define HEADSET_PROFILE_ID              HEADSET_SVCLASS_ID
1994 #define CORDLESS_TELEPHONY_PROFILE_ID   CORDLESS_TELEPHONY_SVCLASS_ID
1995 #define AUDIO_SOURCE_PROFILE_ID         AUDIO_SOURCE_SVCLASS_ID
1996 #define AUDIO_SINK_PROFILE_ID           AUDIO_SINK_SVCLASS_ID
1997 #define AV_REMOTE_TARGET_PROFILE_ID     AV_REMOTE_TARGET_SVCLASS_ID
1998 #define ADVANCED_AUDIO_PROFILE_ID       ADVANCED_AUDIO_SVCLASS_ID
1999 #define AV_REMOTE_PROFILE_ID            AV_REMOTE_SVCLASS_ID
2000 #define VIDEO_CONF_PROFILE_ID           VIDEO_CONF_SVCLASS_ID
2001 #define INTERCOM_PROFILE_ID             INTERCOM_SVCLASS_ID
2002 #define FAX_PROFILE_ID                  FAX_SVCLASS_ID
2003 #define HEADSET_AGW_PROFILE_ID          HEADSET_AGW_SVCLASS_ID
2004 #define WAP_PROFILE_ID                  WAP_SVCLASS_ID
2005 #define WAP_CLIENT_PROFILE_ID           WAP_CLIENT_SVCLASS_ID
2006 #define PANU_PROFILE_ID                 PANU_SVCLASS_ID
2007 #define NAP_PROFILE_ID                  NAP_SVCLASS_ID
2008 #define GN_PROFILE_ID                   GN_SVCLASS_ID
2009 #define DIRECT_PRINTING_PROFILE_ID      DIRECT_PRINTING_SVCLASS_ID
2010 #define REFERENCE_PRINTING_PROFILE_ID   REFERENCE_PRINTING_SVCLASS_ID
2011 #define IMAGING_PROFILE_ID              IMAGING_SVCLASS_ID
2012 #define IMAGING_RESPONDER_PROFILE_ID    IMAGING_RESPONDER_SVCLASS_ID
2013 #define IMAGING_ARCHIVE_PROFILE_ID      IMAGING_ARCHIVE_SVCLASS_ID
2014 #define IMAGING_REFOBJS_PROFILE_ID      IMAGING_REFOBJS_SVCLASS_ID
2015 #define HANDSFREE_PROFILE_ID            HANDSFREE_SVCLASS_ID
2016 #define HANDSFREE_AGW_PROFILE_ID        HANDSFREE_AGW_SVCLASS_ID
2017 #define DIRECT_PRT_REFOBJS_PROFILE_ID   DIRECT_PRT_REFOBJS_SVCLASS_ID
2018 #define REFLECTED_UI_PROFILE_ID         REFLECTED_UI_SVCLASS_ID
2019 #define BASIC_PRINTING_PROFILE_ID       BASIC_PRINTING_SVCLASS_ID
2020 #define PRINTING_STATUS_PROFILE_ID      PRINTING_STATUS_SVCLASS_ID
2021 #define HID_PROFILE_ID                  HID_SVCLASS_ID
2022 #define HCR_PROFILE_ID                  HCR_SCAN_SVCLASS_ID
2023 #define HCR_PRINT_PROFILE_ID            HCR_PRINT_SVCLASS_ID
2024 #define HCR_SCAN_PROFILE_ID             HCR_SCAN_SVCLASS_ID
2025 #define CIP_PROFILE_ID                  CIP_SVCLASS_ID
2026 #define VIDEO_CONF_GW_PROFILE_ID        VIDEO_CONF_GW_SVCLASS_ID
2027 #define UDI_MT_PROFILE_ID               UDI_MT_SVCLASS_ID
2028 #define UDI_TA_PROFILE_ID               UDI_TA_SVCLASS_ID
2029 #define AV_PROFILE_ID                   AV_SVCLASS_ID
2030 #define SAP_PROFILE_ID                  SAP_SVCLASS_ID
2031 #define PBAP_PCE_PROFILE_ID             PBAP_PCE_SVCLASS_ID
2032 #define PBAP_PSE_PROFILE_ID             PBAP_PSE_SVCLASS_ID
2033 #define PBAP_PROFILE_ID                 PBAP_SVCLASS_ID
2034 #define PNP_INFO_PROFILE_ID             PNP_INFO_SVCLASS_ID
2035 #define GENERIC_NETWORKING_PROFILE_ID   GENERIC_NETWORKING_SVCLASS_ID
2036 #define GENERIC_FILETRANS_PROFILE_ID    GENERIC_FILETRANS_SVCLASS_ID
2037 #define GENERIC_AUDIO_PROFILE_ID        GENERIC_AUDIO_SVCLASS_ID
2038 #define GENERIC_TELEPHONY_PROFILE_ID    GENERIC_TELEPHONY_SVCLASS_ID
2039 #define UPNP_PROFILE_ID                 UPNP_SVCLASS_ID
2040 #define UPNP_IP_PROFILE_ID              UPNP_IP_SVCLASS_ID
2041 #define UPNP_PAN_PROFILE_ID             UPNP_PAN_SVCLASS_ID
2042 #define UPNP_LAP_PROFILE_ID             UPNP_LAP_SVCLASS_ID
2043 #define UPNP_L2CAP_PROFILE_ID           UPNP_L2CAP_SVCLASS_ID
2044 #define VIDEO_SOURCE_PROFILE_ID         VIDEO_SOURCE_SVCLASS_ID
2045 #define VIDEO_SINK_PROFILE_ID           VIDEO_SINK_SVCLASS_ID
2046 #define VIDEO_DISTRIBUTION_PROFILE_ID   VIDEO_DISTRIBUTION_SVCLASS_ID
2047 #define MDP_PROFILE_ID                  MDP_SVCLASS_ID
2048 #define MDP_SOURCE_PROFILE_ID           MDP_SROUCE_SVCLASS_ID
2049 #define MDP_SINK_PROFILE_ID             MDP_SINK_SVCLASS_ID
2050 #define APPLE_AGENT_PROFILE_ID          APPLE_AGENT_SVCLASS_ID
2051
2052 /* Data Representation */
2053 enum bt_sdp_data_type {
2054     SDP_DTYPE_NIL       = 0 << 3,
2055     SDP_DTYPE_UINT      = 1 << 3,
2056     SDP_DTYPE_SINT      = 2 << 3,
2057     SDP_DTYPE_UUID      = 3 << 3,
2058     SDP_DTYPE_STRING    = 4 << 3,
2059     SDP_DTYPE_BOOL      = 5 << 3,
2060     SDP_DTYPE_SEQ       = 6 << 3,
2061     SDP_DTYPE_ALT       = 7 << 3,
2062     SDP_DTYPE_URL       = 8 << 3,
2063 };
2064
2065 enum bt_sdp_data_size {
2066     SDP_DSIZE_1         = 0,
2067     SDP_DSIZE_2,
2068     SDP_DSIZE_4,
2069     SDP_DSIZE_8,
2070     SDP_DSIZE_16,
2071     SDP_DSIZE_NEXT1,
2072     SDP_DSIZE_NEXT2,
2073     SDP_DSIZE_NEXT4,
2074     SDP_DSIZE_MASK = SDP_DSIZE_NEXT4,
2075 };
2076
2077 enum bt_sdp_cmd {
2078     SDP_ERROR_RSP               = 0x01,
2079     SDP_SVC_SEARCH_REQ          = 0x02,
2080     SDP_SVC_SEARCH_RSP          = 0x03,
2081     SDP_SVC_ATTR_REQ            = 0x04,
2082     SDP_SVC_ATTR_RSP            = 0x05,
2083     SDP_SVC_SEARCH_ATTR_REQ     = 0x06,
2084     SDP_SVC_SEARCH_ATTR_RSP     = 0x07,
2085 };
2086
2087 enum bt_sdp_errorcode {
2088     SDP_INVALID_VERSION         = 0x0001,
2089     SDP_INVALID_RECORD_HANDLE   = 0x0002,
2090     SDP_INVALID_SYNTAX          = 0x0003,
2091     SDP_INVALID_PDU_SIZE        = 0x0004,
2092     SDP_INVALID_CSTATE          = 0x0005,
2093 };
2094
2095 /*
2096  * String identifiers are based on the SDP spec stating that
2097  * "base attribute id of the primary (universal) language must be 0x0100"
2098  *
2099  * Other languages should have their own offset; e.g.:
2100  * #define XXXLangBase yyyy
2101  * #define AttrServiceName_XXX  0x0000+XXXLangBase
2102  */
2103 #define SDP_PRIMARY_LANG_BASE           0x0100
2104
2105 enum bt_sdp_attribute_id {
2106     SDP_ATTR_RECORD_HANDLE                      = 0x0000,
2107     SDP_ATTR_SVCLASS_ID_LIST                    = 0x0001,
2108     SDP_ATTR_RECORD_STATE                       = 0x0002,
2109     SDP_ATTR_SERVICE_ID                         = 0x0003,
2110     SDP_ATTR_PROTO_DESC_LIST                    = 0x0004,
2111     SDP_ATTR_BROWSE_GRP_LIST                    = 0x0005,
2112     SDP_ATTR_LANG_BASE_ATTR_ID_LIST             = 0x0006,
2113     SDP_ATTR_SVCINFO_TTL                        = 0x0007,
2114     SDP_ATTR_SERVICE_AVAILABILITY               = 0x0008,
2115     SDP_ATTR_PFILE_DESC_LIST                    = 0x0009,
2116     SDP_ATTR_DOC_URL                            = 0x000a,
2117     SDP_ATTR_CLNT_EXEC_URL                      = 0x000b,
2118     SDP_ATTR_ICON_URL                           = 0x000c,
2119     SDP_ATTR_ADD_PROTO_DESC_LIST                = 0x000d,
2120
2121     SDP_ATTR_SVCNAME_PRIMARY                    = SDP_PRIMARY_LANG_BASE + 0,
2122     SDP_ATTR_SVCDESC_PRIMARY                    = SDP_PRIMARY_LANG_BASE + 1,
2123     SDP_ATTR_SVCPROV_PRIMARY                    = SDP_PRIMARY_LANG_BASE + 2,
2124
2125     SDP_ATTR_GROUP_ID                           = 0x0200,
2126     SDP_ATTR_IP_SUBNET                          = 0x0200,
2127
2128     /* SDP */
2129     SDP_ATTR_VERSION_NUM_LIST                   = 0x0200,
2130     SDP_ATTR_SVCDB_STATE                        = 0x0201,
2131
2132     SDP_ATTR_SERVICE_VERSION                    = 0x0300,
2133     SDP_ATTR_EXTERNAL_NETWORK                   = 0x0301,
2134     SDP_ATTR_SUPPORTED_DATA_STORES_LIST         = 0x0301,
2135     SDP_ATTR_FAX_CLASS1_SUPPORT                 = 0x0302,
2136     SDP_ATTR_REMOTE_AUDIO_VOLUME_CONTROL        = 0x0302,
2137     SDP_ATTR_FAX_CLASS20_SUPPORT                = 0x0303,
2138     SDP_ATTR_SUPPORTED_FORMATS_LIST             = 0x0303,
2139     SDP_ATTR_FAX_CLASS2_SUPPORT                 = 0x0304,
2140     SDP_ATTR_AUDIO_FEEDBACK_SUPPORT             = 0x0305,
2141     SDP_ATTR_NETWORK_ADDRESS                    = 0x0306,
2142     SDP_ATTR_WAP_GATEWAY                        = 0x0307,
2143     SDP_ATTR_HOMEPAGE_URL                       = 0x0308,
2144     SDP_ATTR_WAP_STACK_TYPE                     = 0x0309,
2145     SDP_ATTR_SECURITY_DESC                      = 0x030a,
2146     SDP_ATTR_NET_ACCESS_TYPE                    = 0x030b,
2147     SDP_ATTR_MAX_NET_ACCESSRATE                 = 0x030c,
2148     SDP_ATTR_IP4_SUBNET                         = 0x030d,
2149     SDP_ATTR_IP6_SUBNET                         = 0x030e,
2150     SDP_ATTR_SUPPORTED_CAPABILITIES             = 0x0310,
2151     SDP_ATTR_SUPPORTED_FEATURES                 = 0x0311,
2152     SDP_ATTR_SUPPORTED_FUNCTIONS                = 0x0312,
2153     SDP_ATTR_TOTAL_IMAGING_DATA_CAPACITY        = 0x0313,
2154     SDP_ATTR_SUPPORTED_REPOSITORIES             = 0x0314,
2155
2156     /* PnP Information */
2157     SDP_ATTR_SPECIFICATION_ID                   = 0x0200,
2158     SDP_ATTR_VENDOR_ID                          = 0x0201,
2159     SDP_ATTR_PRODUCT_ID                         = 0x0202,
2160     SDP_ATTR_VERSION                            = 0x0203,
2161     SDP_ATTR_PRIMARY_RECORD                     = 0x0204,
2162     SDP_ATTR_VENDOR_ID_SOURCE                   = 0x0205,
2163
2164     /* BT HID */
2165     SDP_ATTR_DEVICE_RELEASE_NUMBER              = 0x0200,
2166     SDP_ATTR_PARSER_VERSION                     = 0x0201,
2167     SDP_ATTR_DEVICE_SUBCLASS                    = 0x0202,
2168     SDP_ATTR_COUNTRY_CODE                       = 0x0203,
2169     SDP_ATTR_VIRTUAL_CABLE                      = 0x0204,
2170     SDP_ATTR_RECONNECT_INITIATE                 = 0x0205,
2171     SDP_ATTR_DESCRIPTOR_LIST                    = 0x0206,
2172     SDP_ATTR_LANG_ID_BASE_LIST                  = 0x0207,
2173     SDP_ATTR_SDP_DISABLE                        = 0x0208,
2174     SDP_ATTR_BATTERY_POWER                      = 0x0209,
2175     SDP_ATTR_REMOTE_WAKEUP                      = 0x020a,
2176     SDP_ATTR_PROFILE_VERSION                    = 0x020b,
2177     SDP_ATTR_SUPERVISION_TIMEOUT                = 0x020c,
2178     SDP_ATTR_NORMALLY_CONNECTABLE               = 0x020d,
2179     SDP_ATTR_BOOT_DEVICE                        = 0x020e,
2180 };