2 * BlueZ - Bluetooth protocol stack for Linux
4 * Copyright (C) 2010 Nokia Corporation
5 * Copyright (C) 2010 Marcel Holtmann <marcel@holtmann.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 #define __packed __attribute__((packed))
28 #define MGMT_INDEX_NONE 0xFFFF
30 #define MGMT_STATUS_SUCCESS 0x00
31 #define MGMT_STATUS_UNKNOWN_COMMAND 0x01
32 #define MGMT_STATUS_NOT_CONNECTED 0x02
33 #define MGMT_STATUS_FAILED 0x03
34 #define MGMT_STATUS_CONNECT_FAILED 0x04
35 #define MGMT_STATUS_AUTH_FAILED 0x05
36 #define MGMT_STATUS_NOT_PAIRED 0x06
37 #define MGMT_STATUS_NO_RESOURCES 0x07
38 #define MGMT_STATUS_TIMEOUT 0x08
39 #define MGMT_STATUS_ALREADY_CONNECTED 0x09
40 #define MGMT_STATUS_BUSY 0x0a
41 #define MGMT_STATUS_REJECTED 0x0b
42 #define MGMT_STATUS_NOT_SUPPORTED 0x0c
43 #define MGMT_STATUS_INVALID_PARAMS 0x0d
44 #define MGMT_STATUS_DISCONNECTED 0x0e
45 #define MGMT_STATUS_NOT_POWERED 0x0f
46 #define MGMT_STATUS_CANCELLED 0x10
47 #define MGMT_STATUS_INVALID_INDEX 0x11
54 #define MGMT_HDR_SIZE 6
56 struct mgmt_addr_info {
61 #define MGMT_OP_READ_VERSION 0x0001
62 struct mgmt_rp_read_version {
67 #define MGMT_OP_READ_COMMANDS 0x0002
68 struct mgmt_rp_read_commands {
69 uint16_t num_commands;
74 #define MGMT_OP_READ_INDEX_LIST 0x0003
75 struct mgmt_rp_read_index_list {
76 uint16_t num_controllers;
80 /* Reserve one extra byte for names in management messages so that they
81 * are always guaranteed to be nul-terminated */
82 #define MGMT_MAX_NAME_LENGTH (HCI_MAX_NAME_LENGTH + 1)
83 #define MGMT_MAX_SHORT_NAME_LENGTH (10 + 1)
85 #ifdef __TIZEN_PATCH__
86 #define MGMT_MAX_ADVERTISING_LENGTH 31
89 #define MGMT_SETTING_POWERED 0x00000001
90 #define MGMT_SETTING_CONNECTABLE 0x00000002
91 #define MGMT_SETTING_FAST_CONNECTABLE 0x00000004
92 #define MGMT_SETTING_DISCOVERABLE 0x00000008
93 #define MGMT_SETTING_PAIRABLE 0x00000010
94 #define MGMT_SETTING_LINK_SECURITY 0x00000020
95 #define MGMT_SETTING_SSP 0x00000040
96 #define MGMT_SETTING_BREDR 0x00000080
97 #define MGMT_SETTING_HS 0x00000100
98 #define MGMT_SETTING_LE 0x00000200
99 #ifdef __TIZEN_PATCH__
100 #define MGMT_SETTING_ADVERTISING 0x00000400
103 #define MGMT_OP_READ_INFO 0x0004
104 struct mgmt_rp_read_info {
107 uint16_t manufacturer;
108 uint32_t supported_settings;
109 uint32_t current_settings;
110 uint8_t dev_class[3];
111 uint8_t name[MGMT_MAX_NAME_LENGTH];
112 uint8_t short_name[MGMT_MAX_SHORT_NAME_LENGTH];
119 #define MGMT_OP_SET_POWERED 0x0005
121 #define MGMT_OP_SET_DISCOVERABLE 0x0006
122 struct mgmt_cp_set_discoverable {
127 #define MGMT_OP_SET_CONNECTABLE 0x0007
129 #define MGMT_OP_SET_FAST_CONNECTABLE 0x0008
131 #define MGMT_OP_SET_PAIRABLE 0x0009
133 #define MGMT_OP_SET_LINK_SECURITY 0x000A
135 #define MGMT_OP_SET_SSP 0x000B
137 #define MGMT_OP_SET_HS 0x000C
139 #define MGMT_OP_SET_LE 0x000D
141 #define MGMT_OP_SET_DEV_CLASS 0x000E
142 struct mgmt_cp_set_dev_class {
147 #define MGMT_OP_SET_LOCAL_NAME 0x000F
148 struct mgmt_cp_set_local_name {
149 uint8_t name[MGMT_MAX_NAME_LENGTH];
150 uint8_t short_name[MGMT_MAX_SHORT_NAME_LENGTH];
153 #define MGMT_OP_ADD_UUID 0x0010
154 struct mgmt_cp_add_uuid {
159 #define MGMT_OP_REMOVE_UUID 0x0011
160 struct mgmt_cp_remove_uuid {
164 struct mgmt_link_key_info {
165 struct mgmt_addr_info addr;
171 #define MGMT_OP_LOAD_LINK_KEYS 0x0012
172 struct mgmt_cp_load_link_keys {
175 struct mgmt_link_key_info keys[0];
178 struct mgmt_ltk_info {
179 struct mgmt_addr_info addr;
180 uint8_t authenticated;
188 #define MGMT_OP_LOAD_LONG_TERM_KEYS 0x0013
189 struct mgmt_cp_load_long_term_keys {
191 struct mgmt_ltk_info keys[0];
194 #define MGMT_OP_DISCONNECT 0x0014
195 struct mgmt_cp_disconnect {
196 struct mgmt_addr_info addr;
198 struct mgmt_rp_disconnect {
199 struct mgmt_addr_info addr;
202 #define MGMT_OP_GET_CONNECTIONS 0x0015
203 struct mgmt_rp_get_connections {
205 struct mgmt_addr_info addr[0];
208 #define MGMT_OP_PIN_CODE_REPLY 0x0016
209 struct mgmt_cp_pin_code_reply {
210 struct mgmt_addr_info addr;
212 uint8_t pin_code[16];
215 #define MGMT_OP_PIN_CODE_NEG_REPLY 0x0017
216 struct mgmt_cp_pin_code_neg_reply {
217 struct mgmt_addr_info addr;
220 #define MGMT_OP_SET_IO_CAPABILITY 0x0018
221 struct mgmt_cp_set_io_capability {
222 uint8_t io_capability;
225 #define MGMT_OP_PAIR_DEVICE 0x0019
226 struct mgmt_cp_pair_device {
227 struct mgmt_addr_info addr;
230 struct mgmt_rp_pair_device {
231 struct mgmt_addr_info addr;
234 #define MGMT_OP_CANCEL_PAIR_DEVICE 0x001A
236 #define MGMT_OP_UNPAIR_DEVICE 0x001B
237 struct mgmt_cp_unpair_device {
238 struct mgmt_addr_info addr;
241 struct mgmt_rp_unpair_device {
242 struct mgmt_addr_info addr;
245 #define MGMT_OP_USER_CONFIRM_REPLY 0x001C
246 struct mgmt_cp_user_confirm_reply {
247 struct mgmt_addr_info addr;
249 struct mgmt_rp_user_confirm_reply {
250 struct mgmt_addr_info addr;
253 #define MGMT_OP_USER_CONFIRM_NEG_REPLY 0x001D
255 #define MGMT_OP_USER_PASSKEY_REPLY 0x001E
256 struct mgmt_cp_user_passkey_reply {
257 struct mgmt_addr_info addr;
260 struct mgmt_rp_user_passkey_reply {
261 struct mgmt_addr_info addr;
264 #define MGMT_OP_USER_PASSKEY_NEG_REPLY 0x001F
265 struct mgmt_cp_user_passkey_neg_reply {
266 struct mgmt_addr_info addr;
269 #define MGMT_OP_READ_LOCAL_OOB_DATA 0x0020
270 struct mgmt_rp_read_local_oob_data {
272 uint8_t randomizer[16];
275 #define MGMT_OP_ADD_REMOTE_OOB_DATA 0x0021
276 struct mgmt_cp_add_remote_oob_data {
277 struct mgmt_addr_info addr;
279 uint8_t randomizer[16];
282 #define MGMT_OP_REMOVE_REMOTE_OOB_DATA 0x0022
283 struct mgmt_cp_remove_remote_oob_data {
284 struct mgmt_addr_info addr;
287 #define MGMT_OP_START_DISCOVERY 0x0023
288 struct mgmt_cp_start_discovery {
292 #define MGMT_OP_STOP_DISCOVERY 0x0024
293 struct mgmt_cp_stop_discovery {
297 #define MGMT_OP_CONFIRM_NAME 0x0025
298 struct mgmt_cp_confirm_name {
299 struct mgmt_addr_info addr;
302 struct mgmt_rp_confirm_name {
303 struct mgmt_addr_info addr;
306 #define MGMT_OP_BLOCK_DEVICE 0x0026
307 struct mgmt_cp_block_device {
308 struct mgmt_addr_info addr;
311 #define MGMT_OP_UNBLOCK_DEVICE 0x0027
312 struct mgmt_cp_unblock_device {
313 struct mgmt_addr_info addr;
316 #define MGMT_OP_SET_DEVICE_ID 0x0028
317 struct mgmt_cp_set_device_id {
324 #ifdef __TIZEN_PATCH__
325 #define MGMT_OP_SET_ADVERTISING 0x0029
327 #define MGMT_OP_SET_BREDR 0x002A
329 #define MGMT_OP_SET_STATIC_ADDRESS 0x002B
330 struct mgmt_cp_set_static_address {
334 #define MGMT_OP_SET_SCAN_PARAMS 0x002C
335 struct mgmt_cp_set_scan_params {
340 #define MGMT_OP_SET_ADVERTISING_PARAMS 0x002D
341 struct mgmt_cp_set_advertising_params {
342 uint16_t interval_min;
343 uint16_t interval_max;
344 uint8_t filter_policy;
347 #define MGMT_OP_SET_ADVERTISING_DATA 0x002E
348 struct mgmt_cp_set_advertising_data {
349 uint8_t data[MGMT_MAX_ADVERTISING_LENGTH - 3]; /* Except flag */
352 #define MGMT_OP_SET_SCAN_RSP_DATA 0x002F
353 struct mgmt_cp_set_scan_rsp_data {
354 uint8_t data[MGMT_MAX_ADVERTISING_LENGTH];
357 #define MGMT_OP_ADD_DEV_WHITE_LIST 0x0030
358 struct mgmt_cp_add_dev_white_list {
363 #define MGMT_OP_REMOVE_DEV_WHITE_LIST 0x0031
364 struct mgmt_cp_remove_dev_white_list {
369 #define MGMT_OP_CLEAR_DEV_WHITE_LIST 0x0032
371 struct mgmt_irk_info {
372 struct mgmt_addr_info addr;
377 #define MGMT_OP_RESOLVE_RPA 0x0033
378 #define MGMT_RESOLVE_RPA_SIZE 6
379 struct mgmt_cp_resolve_rpa {
383 #define MGMT_OP_LOAD_REMOTE_IRKS 0x0034
384 struct mgmt_cp_load_remote_irks {
386 struct mgmt_irk_info keys[0];
388 #define MGMT_LOAD_REMOTE_IRKS_SIZE 2
392 #define MGMT_EV_CMD_COMPLETE 0x0001
393 struct mgmt_ev_cmd_complete {
399 #define MGMT_EV_CMD_STATUS 0x0002
400 struct mgmt_ev_cmd_status {
405 #define MGMT_EV_CONTROLLER_ERROR 0x0003
406 struct mgmt_ev_controller_error {
410 #define MGMT_EV_INDEX_ADDED 0x0004
412 #define MGMT_EV_INDEX_REMOVED 0x0005
414 #define MGMT_EV_NEW_SETTINGS 0x0006
416 #define MGMT_EV_CLASS_OF_DEV_CHANGED 0x0007
417 struct mgmt_ev_class_of_dev_changed {
418 uint8_t class_of_dev[3];
421 #define MGMT_EV_LOCAL_NAME_CHANGED 0x0008
422 struct mgmt_ev_local_name_changed {
423 uint8_t name[MGMT_MAX_NAME_LENGTH];
424 uint8_t short_name[MGMT_MAX_SHORT_NAME_LENGTH];
427 #define MGMT_EV_NEW_LINK_KEY 0x0009
428 struct mgmt_ev_new_link_key {
430 struct mgmt_link_key_info key;
433 #define MGMT_EV_NEW_LONG_TERM_KEY 0x000A
434 struct mgmt_ev_new_long_term_key {
436 struct mgmt_ltk_info key;
439 #define MGMT_EV_DEVICE_CONNECTED 0x000B
440 struct mgmt_ev_device_connected {
441 struct mgmt_addr_info addr;
447 #define MGMT_DEV_DISCONN_UNKNOWN 0x00
448 #define MGMT_DEV_DISCONN_TIMEOUT 0x01
449 #define MGMT_DEV_DISCONN_LOCAL_HOST 0x02
450 #define MGMT_DEV_DISCONN_REMOTE 0x03
452 #define MGMT_EV_DEVICE_DISCONNECTED 0x000C
453 struct mgmt_ev_device_disconnected {
454 struct mgmt_addr_info addr;
458 #define MGMT_EV_CONNECT_FAILED 0x000D
459 struct mgmt_ev_connect_failed {
460 struct mgmt_addr_info addr;
464 #define MGMT_EV_PIN_CODE_REQUEST 0x000E
465 struct mgmt_ev_pin_code_request {
466 struct mgmt_addr_info addr;
470 #define MGMT_EV_USER_CONFIRM_REQUEST 0x000F
471 struct mgmt_ev_user_confirm_request {
472 struct mgmt_addr_info addr;
473 uint8_t confirm_hint;
477 #define MGMT_EV_USER_PASSKEY_REQUEST 0x0010
478 struct mgmt_ev_user_passkey_request {
479 struct mgmt_addr_info addr;
482 #define MGMT_EV_AUTH_FAILED 0x0011
483 struct mgmt_ev_auth_failed {
484 struct mgmt_addr_info addr;
488 #define MGMT_DEV_FOUND_CONFIRM_NAME 0x01
489 #define MGMT_DEV_FOUND_LEGACY_PAIRING 0x02
491 #define MGMT_EV_DEVICE_FOUND 0x0012
492 struct mgmt_ev_device_found {
493 struct mgmt_addr_info addr;
500 #define MGMT_EV_DISCOVERING 0x0013
501 struct mgmt_ev_discovering {
506 #define MGMT_EV_DEVICE_BLOCKED 0x0014
507 struct mgmt_ev_device_blocked {
508 struct mgmt_addr_info addr;
511 #define MGMT_EV_DEVICE_UNBLOCKED 0x0015
512 struct mgmt_ev_device_unblocked {
513 struct mgmt_addr_info addr;
516 #define MGMT_EV_DEVICE_UNPAIRED 0x0016
517 struct mgmt_ev_device_unpaired {
518 struct mgmt_addr_info addr;
521 #define MGMT_EV_PASSKEY_NOTIFY 0x0017
522 struct mgmt_ev_passkey_notify {
523 struct mgmt_addr_info addr;
528 #ifdef __TIZEN_PATCH__
529 #define MGMT_EV_DEVICE_NAME_UPDATE 0x0018
530 struct mgmt_ev_device_name_update {
531 struct mgmt_addr_info addr;
536 #define MGMT_EV_NEW_REMOTE_IRK 0x0019
537 struct mgmt_ev_new_remote_irk {
539 struct mgmt_irk_info key;
542 #define MGMT_EV_NEW_RPA 0x0020
543 struct mgmt_ev_new_rpa {
544 struct mgmt_addr_info rp_addr;
547 #define MGMT_EV_HARDWARE_ERROR 0x0022
548 struct mgmt_ev_hardware_error{
552 #define MGMT_TX_TIMEOUT_ERROR 0x0023
555 static const char *mgmt_op[] = {
560 "Read Controller Info",
564 "Set Fast Connectable", /* 0x0008 */
567 "Set Secure Simple Pairing",
572 "Add UUID", /* 0x0010 */
575 "Load Long Term Keys",
579 "PIN Code Neg Reply",
580 "Set IO Capability", /* 0x0018 */
582 "Cancel Pair Device",
584 "User Confirm Reply",
585 "User Confirm Neg Reply",
586 "User Passkey Reply",
587 "User Passkey Neg Reply",
588 "Read Local OOB Data", /* 0x0020 */
589 "Add Remote OOB Data",
590 "Remove Remove OOB Data",
597 #ifdef __TIZEN_PATCH__
600 "Set Static Address",
601 "Set Scan Parameters",
602 "Set Advertising Parameters",
603 "Set Advertising Data",
604 "Set Scan Response Data",
605 "Add Device White List", /* 0x0030 */
606 "Remove Device White List",
607 "Clear Device White List",
608 "Resolve Random Public Address",
613 static const char *mgmt_ev[] = {
621 "Class of Device Changed",
622 "Local Name Changed", /* 0x0008 */
626 "Device Disconnected",
629 "User Confirm Request",
630 "User Passkey Request", /* 0x0010 */
631 "Authentication Failed",
638 #ifdef __TIZEN_PATCH__
639 "Device Name Update",
640 "New Remote IRK", /* 0x0019 */
641 "New RPA", /* 0x0020 */
642 "New Remote Identity Address",
648 static const char *mgmt_status[] = {
654 "Authentication Failed",
662 "Invalid Parameters",
667 #ifdef __TIZEN_PATCH__
668 "New Identity Resolving Key",
669 "New Random Public Address",
670 #endif /* __TIZEN_PATCH__ */
674 #define NELEM(x) (sizeof(x) / sizeof((x)[0]))
677 static inline const char *mgmt_opstr(uint16_t op)
679 if (op >= NELEM(mgmt_op))
680 return "<unknown opcode>";
684 static inline const char *mgmt_evstr(uint16_t ev)
686 if (ev >= NELEM(mgmt_ev))
687 return "<unknown event>";
691 static inline const char *mgmt_errstr(uint8_t status)
693 if (status >= NELEM(mgmt_status))
694 return "<unknown status>";
695 return mgmt_status[status];