Fix the bug : TIVI-204 Fail to connect to bluetooth network
[profile/ivi/bluez.git] / monitor / bt.h
1 /*
2  *
3  *  BlueZ - Bluetooth protocol stack for Linux
4  *
5  *  Copyright (C) 2011-2012  Intel Corporation
6  *  Copyright (C) 2004-2010  Marcel Holtmann <marcel@holtmann.org>
7  *
8  *
9  *  This program is free software; you can redistribute it and/or modify
10  *  it under the terms of the GNU General Public License as published by
11  *  the Free Software Foundation; either version 2 of the License, or
12  *  (at your option) any later version.
13  *
14  *  This program is distributed in the hope that it will be useful,
15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  *  GNU General Public License for more details.
18  *
19  *  You should have received a copy of the GNU General Public License
20  *  along with this program; if not, write to the Free Software
21  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
22  *
23  */
24
25 #include <stdint.h>
26
27 #define BT_H4_CMD_PKT   0x01
28 #define BT_H4_ACL_PKT   0x02
29 #define BT_H4_SCO_PKT   0x03
30 #define BT_H4_EVT_PKT   0x04
31
32 struct bt_hci_cmd_hdr {
33         uint16_t opcode;
34         uint8_t  plen;
35 } __attribute__ ((packed));
36
37 struct bt_hci_evt_hdr {
38         uint8_t  evt;
39         uint8_t  plen;
40 } __attribute__ ((packed));
41
42 #define BT_HCI_CMD_NOP                          0x0000
43
44 #define BT_HCI_CMD_INQUIRY                      0x0401
45 struct bt_hci_cmd_inquiry {
46         uint8_t  lap[3];
47         uint8_t  length;
48         uint8_t  num_rsp;
49 } __attribute__ ((packed));
50
51 #define BT_HCI_CMD_INQUIRY_CANCEL               0x0402
52
53 #define BT_HCI_CMD_CREATE_CONN                  0x0405
54 struct bt_hci_cmd_create_conn {
55         uint8_t  bdaddr[6];
56         uint16_t pkt_type;
57         uint8_t  pscan_rep_mode;
58         uint8_t  pscan_mode;
59         uint16_t clock_offset;
60         uint8_t  role_switch;
61 } __attribute__ ((packed));
62
63 #define BT_HCI_CMD_DISCONNECT                   0x0406
64 struct bt_hci_cmd_disconnect {
65         uint16_t handle;
66         uint8_t  reason;
67 } __attribute__ ((packed));
68
69 #define BT_HCI_CMD_ADD_SCO_CONN                 0x0407
70 struct bt_hci_cmd_add_sco_conn {
71         uint16_t handle;
72         uint16_t pkt_type;
73 } __attribute__ ((packed));
74
75 #define BT_HCI_CMD_CREATE_CONN_CANCEL           0x0408
76 struct bt_hci_cmd_create_conn_cancel {
77         uint8_t  bdaddr[6];
78 } __attribute__ ((packed));
79
80 #define BT_HCI_CMD_ACCEPT_CONN_REQUEST          0x0409
81 struct bt_hci_cmd_accept_conn_request {
82         uint8_t  bdaddr[6];
83         uint8_t  role;
84 } __attribute__ ((packed));
85
86 #define BT_HCI_CMD_REJECT_CONN_REQUEST          0x040a
87 struct bt_hci_cmd_reject_conn_request {
88         uint8_t  bdaddr[6];
89         uint8_t  reason;
90 } __attribute__ ((packed));
91
92 #define BT_HCI_CMD_CHANGE_CONN_PKT_TYPE         0x040f
93 struct bt_hci_cmd_change_conn_pkt_type {
94         uint16_t handle;
95         uint16_t pkt_type;
96 } __attribute__ ((packed));
97
98 #define BT_HCI_CMD_REMOTE_NAME_REQUEST          0x0419
99 struct bt_hci_cmd_remote_name_request {
100         uint8_t  bdaddr[6];
101         uint8_t  pscan_rep_mode;
102         uint8_t  pscan_mode;
103         uint16_t clock_offset;
104 } __attribute__ ((packed));
105
106 #define BT_HCI_CMD_REMOTE_NAME_REQUEST_CANCEL   0x041a
107 struct bt_hci_cmd_remote_name_request_cancel {
108         uint8_t  bdaddr[6];
109 } __attribute__ ((packed));
110
111 #define BT_HCI_CMD_READ_REMOTE_FEATURES         0x041b
112 struct bt_hci_cmd_read_remote_features {
113         uint16_t handle;
114 } __attribute__ ((packed));
115
116 #define BT_HCI_CMD_READ_REMOTE_EXT_FEATURES     0x041c
117 struct bt_hci_cmd_read_remote_ext_features {
118         uint16_t handle;
119         uint8_t  page;
120 } __attribute__ ((packed));
121
122 #define BT_HCI_CMD_READ_REMOTE_VERSION          0x041d
123 struct bt_hci_cmd_read_remote_version {
124         uint16_t handle;
125 } __attribute__ ((packed));
126
127 #define BT_HCI_CMD_READ_DEFAULT_LINK_POLICY     0x080e
128 struct bt_hci_rsp_read_default_link_policy {
129         uint8_t  status;
130         uint16_t policy;
131 } __attribute__ ((packed));
132
133 #define BT_HCI_CMD_WRITE_DEFAULT_LINK_POLICY    0x080f
134 struct bt_hci_cmd_write_default_link_policy {
135         uint16_t policy;
136 } __attribute__ ((packed));
137
138 #define BT_HCI_CMD_SET_EVENT_MASK               0x0c01
139 struct bt_hci_cmd_set_event_mask {
140         uint8_t  mask[8];
141 } __attribute__ ((packed));
142
143 #define BT_HCI_CMD_RESET                        0x0c03
144
145 #define BT_HCI_CMD_SET_EVENT_FILTER             0x0c05
146 struct bt_hci_cmd_set_event_filter {
147         uint8_t  type;
148         uint8_t  cond_type;
149         uint8_t  cond[0];
150 } __attribute__ ((packed));
151
152 #define BT_HCI_CMD_READ_STORED_LINK_KEY         0x0c0d
153 struct bt_hci_cmd_read_stored_link_key {
154         uint8_t  bdaddr[6];
155         uint8_t  read_all;
156 } __attribute__ ((packed));
157 struct bt_hci_rsp_read_stored_link_key {
158         uint8_t  status;
159         uint16_t max_num_keys;
160         uint16_t num_keys;
161 } __attribute__ ((packed));
162
163 #define BT_HCI_CMD_WRITE_STORED_LINK_KEY        0x0c11
164 struct bt_hci_cmd_write_stored_link_key {
165         uint8_t  num_keys;
166 } __attribute__ ((packed));
167 struct bt_hci_rsp_write_stored_link_key {
168         uint8_t  status;
169         uint8_t  num_keys;
170 } __attribute__ ((packed));
171
172 #define BT_HCI_CMD_DELETE_STORED_LINK_KEY       0x0c12
173 struct bt_hci_cmd_delete_stored_link_key {
174         uint8_t  bdaddr[6];
175         uint8_t  delete_all;
176 } __attribute__ ((packed));
177 struct bt_hci_rsp_delete_stored_link_key {
178         uint8_t  status;
179         uint16_t num_keys;
180 } __attribute__ ((packed));
181
182 #define BT_HCI_CMD_WRITE_LOCAL_NAME             0x0c13
183 struct bt_hci_cmd_write_local_name {
184         uint8_t  name[248];
185 } __attribute__ ((packed));
186
187 #define BT_HCI_CMD_READ_LOCAL_NAME              0x0c14
188 struct bt_hci_rsp_read_local_name {
189         uint8_t  status;
190         uint8_t  name[248];
191 } __attribute__ ((packed));
192
193 #define BT_HCI_CMD_READ_CONN_ACCEPT_TIMEOUT     0x0c15
194 struct bt_hci_rsp_read_conn_accept_timeout {
195         uint8_t  status;
196         uint16_t timeout;
197 } __attribute__ ((packed));
198
199 #define BT_HCI_CMD_WRITE_CONN_ACCEPT_TIMEOUT    0x0c16
200 struct bt_hci_cmd_write_conn_accept_timeout {
201         uint16_t timeout;
202 } __attribute__ ((packed));
203
204 #define BT_HCI_CMD_READ_PAGE_TIMEOUT            0x0c17
205 struct bt_hci_rsp_read_page_timeout {
206         uint8_t  status;
207         uint16_t timeout;
208 } __attribute__ ((packed));
209
210 #define BT_HCI_CMD_WRITE_PAGE_TIMEOUT           0x0c18
211 struct bt_hci_cmd_write_page_timeout {
212         uint16_t timeout;
213 } __attribute__ ((packed));
214
215 #define BT_HCI_CMD_READ_SCAN_ENABLE             0x0c19
216 struct bt_hci_rsp_read_scan_enable {
217         uint8_t  status;
218         uint8_t  enable;
219 } __attribute__ ((packed));
220
221 #define BT_HCI_CMD_WRITE_SCAN_ENABLE            0x0c1a
222 struct bt_hci_cmd_write_scan_enable {
223         uint8_t  enable;
224 } __attribute__ ((packed));
225
226 #define BT_HCI_CMD_READ_AUTH_ENABLE             0x0c1f
227 struct bt_hci_rsp_read_auth_enable {
228         uint8_t  status;
229         uint8_t  enable;
230 } __attribute__ ((packed));
231
232 #define BT_HCI_CMD_WRITE_AUTH_ENABLE            0x0c20
233 struct bt_hci_cmd_write_auth_enable {
234         uint8_t  enable;
235 } __attribute__ ((packed));
236
237 #define BT_HCI_CMD_READ_CLASS_OF_DEV            0x0c23
238 struct bt_hci_rsp_read_class_of_dev {
239         uint8_t  status;
240         uint8_t  dev_class[3];
241 } __attribute__ ((packed));
242
243 #define BT_HCI_CMD_WRITE_CLASS_OF_DEV           0x0c24
244 struct bt_hci_cmd_write_class_of_dev {
245         uint8_t  dev_class[3];
246 } __attribute__ ((packed));
247
248 #define BT_HCI_CMD_READ_VOICE_SETTING           0x0c25
249 struct bt_hci_rsp_read_voice_setting {
250         uint8_t  status;
251         uint16_t setting;
252 } __attribute__ ((packed));
253
254 #define BT_HCI_CMD_WRITE_VOICE_SETTING          0x0c26
255 struct bt_hci_cmd_write_voice_setting {
256         uint16_t setting;
257 } __attribute__ ((packed));
258
259 #define BT_HCI_CMD_READ_INQUIRY_MODE            0x0c44
260 struct bt_hci_rsp_read_inquiry_mode {
261         uint8_t  status;
262         uint8_t  mode;
263 } __attribute__ ((packed));
264
265 #define BT_HCI_CMD_WRITE_INQUIRY_MODE           0x0c45
266 struct bt_hci_cmd_write_inquiry_mode {
267         uint8_t  mode;
268 } __attribute__ ((packed));
269
270 #define BT_HCI_CMD_READ_AFH_ASSESS_MODE         0x0c48
271 struct bt_hci_rsp_read_afh_assess_mode {
272         uint8_t  status;
273         uint8_t  mode;
274 } __attribute__ ((packed));
275
276 #define BT_HCI_CMD_WRITE_AFH_ASSESS_MODE        0x0c49
277 struct bt_hci_cmd_write_afh_assess_mode {
278         uint8_t  mode;
279 } __attribute__ ((packed));
280
281 #define BT_HCI_CMD_READ_EXT_INQUIRY_RSP         0x0c51
282 struct bt_hci_rsp_read_ext_inquiry_rsp {
283         uint8_t  status;
284         uint8_t  fec;
285         uint8_t  data[240];
286 } __attribute__ ((packed));
287
288 #define BT_HCI_CMD_WRITE_EXT_INQUIRY_RSP        0x0c52
289 struct bt_hci_cmd_write_ext_inquiry_rsp {
290         uint8_t  fec;
291         uint8_t  data[240];
292 } __attribute__ ((packed));
293
294 #define BT_HCI_CMD_READ_SIMPLE_PAIRING_MODE     0x0c55
295 struct bt_hci_rsp_read_simple_pairing_mode {
296         uint8_t  status;
297         uint8_t  mode;
298 } __attribute__ ((packed));
299
300 #define BT_HCI_CMD_WRITE_SIMPLE_PAIRING_MODE    0x0c56
301 struct bt_hci_cmd_write_simple_pairing_mode {
302         uint8_t  mode;
303 } __attribute__ ((packed));
304
305 #define BT_HCI_CMD_READ_INQUIRY_RSP_TX_POWER    0x0c58
306 struct bt_hci_rsp_read_inquiry_rsp_tx_power {
307         uint8_t  status;
308         int8_t   level;
309 } __attribute__ ((packed));
310
311 #define BT_HCI_CMD_READ_LE_HOST_SUPPORTED       0x0c6c
312 struct bt_hci_rsp_read_le_host_supported {
313         uint8_t  status;
314         uint8_t  supported;
315         uint8_t  simultaneous;
316 } __attribute__ ((packed));
317
318 #define BT_HCI_CMD_WRITE_LE_HOST_SUPPORTED      0x0c6d
319 struct bt_hci_cmd_write_le_host_supported {
320         uint8_t  supported;
321         uint8_t  simultaneous;
322 } __attribute__ ((packed));
323
324 #define BT_HCI_CMD_READ_LOCAL_VERSION           0x1001
325 struct bt_hci_rsp_read_local_version {
326         uint8_t  status;
327         uint8_t  hci_ver;
328         uint16_t hci_rev;
329         uint8_t  lmp_ver;
330         uint16_t manufacturer;
331         uint16_t lmp_subver;
332 } __attribute__ ((packed));
333
334 #define BT_HCI_CMD_READ_LOCAL_COMMANDS          0x1002
335 struct bt_hci_rsp_read_local_commands {
336         uint8_t  status;
337         uint8_t  commands[64];
338 } __attribute__ ((packed));
339
340 #define BT_HCI_CMD_READ_LOCAL_FEATURES          0x1003
341 struct bt_hci_rsp_read_local_features {
342         uint8_t  status;
343         uint8_t  features[8];
344 } __attribute__ ((packed));
345
346 #define BT_HCI_CMD_READ_LOCAL_EXT_FEATURES      0x1004
347 struct bt_hci_cmd_read_local_ext_features {
348         uint8_t  page;
349 } __attribute__ ((packed));
350 struct bt_hci_rsp_read_local_ext_features {
351         uint8_t  status;
352         uint8_t  page;
353         uint8_t  max_page;
354         uint8_t  features[8];
355 } __attribute__ ((packed));
356
357 #define BT_HCI_CMD_READ_BUFFER_SIZE             0x1005
358 struct bt_hci_rsp_read_buffer_size {
359         uint8_t  status;
360         uint16_t acl_mtu;
361         uint8_t  sco_mtu;
362         uint16_t acl_max_pkt;
363         uint16_t sco_max_pkt;
364 } __attribute__ ((packed));
365
366 #define BT_HCI_CMD_READ_COUNTRY_CODE            0x1007
367 struct bt_hci_rsp_read_country_code {
368         uint8_t  status;
369         uint8_t  code;
370 } __attribute__ ((packed));
371
372 #define BT_HCI_CMD_READ_BD_ADDR                 0x1009
373 struct bt_hci_rsp_read_bd_addr {
374         uint8_t  status;
375         uint8_t  bdaddr[6];
376 } __attribute__ ((packed));
377
378 #define BT_HCI_CMD_READ_DATA_BLOCK_SIZE         0x100a
379 struct bt_hci_rsp_read_data_block_size {
380         uint8_t  status;
381         uint16_t max_acl_len;
382         uint16_t block_len;
383         uint16_t num_blocks;
384 } __attribute__ ((packed));
385
386 #define BT_HCI_CMD_LE_SET_EVENT_MASK            0x2001
387 struct bt_hci_cmd_le_set_event_mask {
388         uint8_t  mask[8];
389 } __attribute__ ((packed));
390
391 #define BT_HCI_CMD_LE_READ_BUFFER_SIZE          0x2002
392 struct bt_hci_rsp_le_read_buffer_size {
393         uint8_t  status;
394         uint16_t le_mtu;
395         uint8_t  le_max_pkt;
396 } __attribute__ ((packed));
397
398 #define BT_HCI_CMD_LE_READ_LOCAL_FEATURES       0x2003
399 struct bt_hci_rsp_le_read_local_features {
400         uint8_t  status;
401         uint8_t  features[8];
402 } __attribute__ ((packed));
403
404 #define BT_HCI_CMD_LE_SET_SCAN_PARAMETERS       0x200b
405 struct bt_hci_cmd_le_set_scan_parameters {
406         uint8_t  type;
407         uint16_t interval;
408         uint16_t window;
409         uint8_t  own_addr_type;
410         uint8_t  filter_policy;
411 } __attribute__ ((packed));
412
413 #define BT_HCI_CMD_LE_SET_SCAN_ENABLE           0x200c
414 struct bt_hci_cmd_le_set_scan_enable {
415         uint8_t  enable;
416         uint8_t  filter_dup;
417 } __attribute__ ((packed));
418
419 #define BT_HCI_CMD_LE_READ_SUPPORTED_STATES     0x201c
420 struct bt_hci_rsp_le_read_supported_states {
421         uint8_t  status;
422         uint8_t  states[8];
423 } __attribute__ ((packed));
424
425 #define BT_HCI_EVT_INQUIRY_COMPLETE             0x01
426 struct bt_hci_evt_inquiry_complete {
427         uint8_t  status;
428 } __attribute__ ((packed));
429
430 #define BT_HCI_EVT_INQUIRY_RESULT               0x02
431 struct bt_hci_evt_inquiry_result {
432         uint8_t  num_resp;
433         uint8_t  bdaddr[6];
434         uint8_t  pscan_rep_mode;
435         uint8_t  pscan_period_mode;
436         uint8_t  pscan_mode;
437         uint8_t  dev_class[3];
438         uint8_t  clock_offset;
439 } __attribute__ ((packed));
440
441 #define BT_HCI_EVT_CONN_COMPLETE                0x03
442 struct bt_hci_evt_conn_complete {
443         uint8_t  status;
444         uint16_t handle;
445         uint8_t  bdaddr[6];
446         uint8_t  link_type;
447         uint8_t  encr_mode;
448 } __attribute__ ((packed));
449
450 #define BT_HCI_EVT_CONN_REQUEST                 0x04
451 struct bt_hci_evt_conn_request {
452         uint8_t  bdaddr[6];
453         uint8_t  dev_class[3];
454         uint8_t  link_type;
455 } __attribute__ ((packed));
456
457 #define BT_HCI_EVT_DISCONNECT_COMPLETE          0x05
458 struct bt_hci_evt_disconnect_complete {
459         uint8_t  status;
460         uint16_t handle;
461         uint8_t  reason;
462 } __attribute__ ((packed));
463
464 #define BT_HCI_EVT_REMOTE_NAME_REQUEST_COMPLETE 0x07
465 struct bt_hci_evt_remote_name_req_complete {
466         uint8_t  status;
467         uint8_t  bdaddr[6];
468         uint8_t  name[248];
469 } __attribute__ ((packed));
470
471 #define BT_HCI_EVT_REMOTE_FEATURES_COMPLETE     0x0b
472 struct bt_hci_evt_remote_features_complete {
473         uint8_t  status;
474         uint16_t handle;
475         uint8_t  features[8];
476 } __attribute__ ((packed));
477
478 #define BT_HCI_EVT_REMOTE_VERSION_COMPLETE      0x0c
479 struct bt_hci_evt_remote_version_complete {
480         uint8_t  status;
481         uint16_t handle;
482         uint8_t  lmp_ver;
483         uint16_t manufacturer;
484         uint16_t lmp_subver;
485 } __attribute__ ((packed));
486
487 #define BT_HCI_EVT_CMD_COMPLETE                 0x0e
488 struct bt_hci_evt_cmd_complete {
489         uint8_t  ncmd;
490         uint16_t opcode;
491 } __attribute__ ((packed));
492
493 #define BT_HCI_EVT_CMD_STATUS                   0x0f
494 struct bt_hci_evt_cmd_status {
495         uint8_t  status;
496         uint8_t  ncmd;
497         uint16_t opcode;
498 } __attribute__ ((packed));
499
500 #define BT_HCI_EVT_NUM_COMPLETED_PACKETS        0x13
501 struct bt_hci_evt_num_completed_packets {
502         uint8_t  num_handles;
503         uint16_t handle;
504         uint16_t count;
505 } __attribute__ ((packed));
506
507 #define BT_HCI_EVT_CONN_PKT_TYPE_CHANGED        0x1d
508 struct bt_hci_evt_conn_pkt_type_changed {
509         uint8_t  status;
510         uint16_t handle;
511         uint16_t pkt_type;
512 } __attribute__ ((packed));
513
514 #define BT_HCI_EVT_INQUIRY_RESULT_WITH_RSSI     0x22
515 struct bt_hci_evt_inquiry_result_with_rssi {
516         uint8_t  num_resp;
517         uint8_t  bdaddr[6];
518         uint8_t  pscan_rep_mode;
519         uint8_t  pscan_period_mode;
520         uint8_t  dev_class[3];
521         uint16_t clock_offset;
522         int8_t   rssi;
523 } __attribute__ ((packed));
524
525 #define BT_HCI_EVT_REMOTE_EXT_FEATURES_COMPLETE 0x23
526 struct bt_hci_evt_remote_ext_features_complete {
527         uint8_t  status;
528         uint16_t handle;
529         uint8_t  page;
530         uint8_t  max_page;
531         uint8_t  features[8];
532 } __attribute__ ((packed));
533
534 #define BT_HCI_EVT_EXT_INQUIRY_RESULT           0x2f
535 struct bt_hci_evt_ext_inquiry_result {
536         uint8_t  num_resp;
537         uint8_t  bdaddr[6];
538         uint8_t  pscan_rep_mode;
539         uint8_t  pscan_period_mode;
540         uint8_t  dev_class[3];
541         uint16_t clock_offset;
542         int8_t   rssi;
543         uint8_t  data[240];
544 } __attribute__ ((packed));
545
546 #define BT_HCI_ERR_SUCCESS                      0x00
547 #define BT_HCI_ERR_UNKNOWN_COMMAND              0x01
548 #define BT_HCI_ERR_UNKNOWN_CONN_ID              0x02
549 #define BT_HCI_ERR_HARDWARE_FAILURE             0x03
550 #define BT_HCI_ERR_PAGE_TIMEOUT                 0x04
551 #define BT_HCI_ERR_INVALID_PARAMETERS           0x12