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 #define MGMT_SETTING_POWERED 0x00000001
86 #define MGMT_SETTING_CONNECTABLE 0x00000002
87 #define MGMT_SETTING_FAST_CONNECTABLE 0x00000004
88 #define MGMT_SETTING_DISCOVERABLE 0x00000008
89 #define MGMT_SETTING_PAIRABLE 0x00000010
90 #define MGMT_SETTING_LINK_SECURITY 0x00000020
91 #define MGMT_SETTING_SSP 0x00000040
92 #define MGMT_SETTING_BREDR 0x00000080
93 #define MGMT_SETTING_HS 0x00000100
94 #define MGMT_SETTING_LE 0x00000200
96 #define MGMT_OP_READ_INFO 0x0004
97 struct mgmt_rp_read_info {
100 uint16_t manufacturer;
101 uint32_t supported_settings;
102 uint32_t current_settings;
103 uint8_t dev_class[3];
104 uint8_t name[MGMT_MAX_NAME_LENGTH];
105 uint8_t short_name[MGMT_MAX_SHORT_NAME_LENGTH];
112 #define MGMT_OP_SET_POWERED 0x0005
114 #define MGMT_OP_SET_DISCOVERABLE 0x0006
115 struct mgmt_cp_set_discoverable {
120 #define MGMT_OP_SET_CONNECTABLE 0x0007
122 #define MGMT_OP_SET_FAST_CONNECTABLE 0x0008
124 #define MGMT_OP_SET_PAIRABLE 0x0009
126 #define MGMT_OP_SET_LINK_SECURITY 0x000A
128 #define MGMT_OP_SET_SSP 0x000B
130 #define MGMT_OP_SET_HS 0x000C
132 #define MGMT_OP_SET_LE 0x000D
134 #define MGMT_OP_SET_DEV_CLASS 0x000E
135 struct mgmt_cp_set_dev_class {
140 #define MGMT_OP_SET_LOCAL_NAME 0x000F
141 struct mgmt_cp_set_local_name {
142 uint8_t name[MGMT_MAX_NAME_LENGTH];
143 uint8_t short_name[MGMT_MAX_SHORT_NAME_LENGTH];
146 #define MGMT_OP_ADD_UUID 0x0010
147 struct mgmt_cp_add_uuid {
152 #define MGMT_OP_REMOVE_UUID 0x0011
153 struct mgmt_cp_remove_uuid {
157 struct mgmt_link_key_info {
158 struct mgmt_addr_info addr;
164 #define MGMT_OP_LOAD_LINK_KEYS 0x0012
165 struct mgmt_cp_load_link_keys {
168 struct mgmt_link_key_info keys[0];
171 struct mgmt_ltk_info {
172 struct mgmt_addr_info addr;
173 uint8_t authenticated;
181 #define MGMT_OP_LOAD_LONG_TERM_KEYS 0x0013
182 struct mgmt_cp_load_long_term_keys {
184 struct mgmt_ltk_info keys[0];
187 #define MGMT_OP_DISCONNECT 0x0014
188 struct mgmt_cp_disconnect {
189 struct mgmt_addr_info addr;
191 struct mgmt_rp_disconnect {
192 struct mgmt_addr_info addr;
195 #define MGMT_OP_GET_CONNECTIONS 0x0015
196 struct mgmt_rp_get_connections {
198 struct mgmt_addr_info addr[0];
201 #define MGMT_OP_PIN_CODE_REPLY 0x0016
202 struct mgmt_cp_pin_code_reply {
203 struct mgmt_addr_info addr;
205 uint8_t pin_code[16];
208 #define MGMT_OP_PIN_CODE_NEG_REPLY 0x0017
209 struct mgmt_cp_pin_code_neg_reply {
210 struct mgmt_addr_info addr;
213 #define MGMT_OP_SET_IO_CAPABILITY 0x0018
214 struct mgmt_cp_set_io_capability {
215 uint8_t io_capability;
218 #define MGMT_OP_PAIR_DEVICE 0x0019
219 struct mgmt_cp_pair_device {
220 struct mgmt_addr_info addr;
223 struct mgmt_rp_pair_device {
224 struct mgmt_addr_info addr;
227 #define MGMT_OP_CANCEL_PAIR_DEVICE 0x001A
229 #define MGMT_OP_UNPAIR_DEVICE 0x001B
230 struct mgmt_cp_unpair_device {
231 struct mgmt_addr_info addr;
234 struct mgmt_rp_unpair_device {
235 struct mgmt_addr_info addr;
238 #define MGMT_OP_USER_CONFIRM_REPLY 0x001C
239 struct mgmt_cp_user_confirm_reply {
240 struct mgmt_addr_info addr;
242 struct mgmt_rp_user_confirm_reply {
243 struct mgmt_addr_info addr;
246 #define MGMT_OP_USER_CONFIRM_NEG_REPLY 0x001D
248 #define MGMT_OP_USER_PASSKEY_REPLY 0x001E
249 struct mgmt_cp_user_passkey_reply {
250 struct mgmt_addr_info addr;
253 struct mgmt_rp_user_passkey_reply {
254 struct mgmt_addr_info addr;
257 #define MGMT_OP_USER_PASSKEY_NEG_REPLY 0x001F
258 struct mgmt_cp_user_passkey_neg_reply {
259 struct mgmt_addr_info addr;
262 #define MGMT_OP_READ_LOCAL_OOB_DATA 0x0020
263 struct mgmt_rp_read_local_oob_data {
265 uint8_t randomizer[16];
268 #define MGMT_OP_ADD_REMOTE_OOB_DATA 0x0021
269 struct mgmt_cp_add_remote_oob_data {
270 struct mgmt_addr_info addr;
272 uint8_t randomizer[16];
275 #define MGMT_OP_REMOVE_REMOTE_OOB_DATA 0x0022
276 struct mgmt_cp_remove_remote_oob_data {
277 struct mgmt_addr_info addr;
280 #define MGMT_OP_START_DISCOVERY 0x0023
281 struct mgmt_cp_start_discovery {
285 #define MGMT_OP_STOP_DISCOVERY 0x0024
286 struct mgmt_cp_stop_discovery {
290 #define MGMT_OP_CONFIRM_NAME 0x0025
291 struct mgmt_cp_confirm_name {
292 struct mgmt_addr_info addr;
295 struct mgmt_rp_confirm_name {
296 struct mgmt_addr_info addr;
299 #define MGMT_OP_BLOCK_DEVICE 0x0026
300 struct mgmt_cp_block_device {
301 struct mgmt_addr_info addr;
304 #define MGMT_OP_UNBLOCK_DEVICE 0x0027
305 struct mgmt_cp_unblock_device {
306 struct mgmt_addr_info addr;
309 #define MGMT_OP_SET_DEVICE_ID 0x0028
310 struct mgmt_cp_set_device_id {
317 #define MGMT_EV_CMD_COMPLETE 0x0001
318 struct mgmt_ev_cmd_complete {
324 #define MGMT_EV_CMD_STATUS 0x0002
325 struct mgmt_ev_cmd_status {
330 #define MGMT_EV_CONTROLLER_ERROR 0x0003
331 struct mgmt_ev_controller_error {
335 #define MGMT_EV_INDEX_ADDED 0x0004
337 #define MGMT_EV_INDEX_REMOVED 0x0005
339 #define MGMT_EV_NEW_SETTINGS 0x0006
341 #define MGMT_EV_CLASS_OF_DEV_CHANGED 0x0007
342 struct mgmt_ev_class_of_dev_changed {
343 uint8_t class_of_dev[3];
346 #define MGMT_EV_LOCAL_NAME_CHANGED 0x0008
347 struct mgmt_ev_local_name_changed {
348 uint8_t name[MGMT_MAX_NAME_LENGTH];
349 uint8_t short_name[MGMT_MAX_SHORT_NAME_LENGTH];
352 #define MGMT_EV_NEW_LINK_KEY 0x0009
353 struct mgmt_ev_new_link_key {
355 struct mgmt_link_key_info key;
358 #define MGMT_EV_NEW_LONG_TERM_KEY 0x000A
359 struct mgmt_ev_new_long_term_key {
361 struct mgmt_ltk_info key;
364 #define MGMT_EV_DEVICE_CONNECTED 0x000B
365 struct mgmt_ev_device_connected {
366 struct mgmt_addr_info addr;
372 #define MGMT_EV_DEVICE_DISCONNECTED 0x000C
373 struct mgmt_ev_device_disconnected {
374 struct mgmt_addr_info addr;
377 #define MGMT_EV_CONNECT_FAILED 0x000D
378 struct mgmt_ev_connect_failed {
379 struct mgmt_addr_info addr;
383 #define MGMT_EV_PIN_CODE_REQUEST 0x000E
384 struct mgmt_ev_pin_code_request {
385 struct mgmt_addr_info addr;
389 #define MGMT_EV_USER_CONFIRM_REQUEST 0x000F
390 struct mgmt_ev_user_confirm_request {
391 struct mgmt_addr_info addr;
392 uint8_t confirm_hint;
396 #define MGMT_EV_USER_PASSKEY_REQUEST 0x0010
397 struct mgmt_ev_user_passkey_request {
398 struct mgmt_addr_info addr;
401 #define MGMT_EV_AUTH_FAILED 0x0011
402 struct mgmt_ev_auth_failed {
403 struct mgmt_addr_info addr;
407 #define MGMT_DEV_FOUND_CONFIRM_NAME 0x01
408 #define MGMT_DEV_FOUND_LEGACY_PAIRING 0x02
410 #define MGMT_EV_DEVICE_FOUND 0x0012
411 struct mgmt_ev_device_found {
412 struct mgmt_addr_info addr;
419 #define MGMT_EV_DISCOVERING 0x0013
420 struct mgmt_ev_discovering {
425 #define MGMT_EV_DEVICE_BLOCKED 0x0014
426 struct mgmt_ev_device_blocked {
427 struct mgmt_addr_info addr;
430 #define MGMT_EV_DEVICE_UNBLOCKED 0x0015
431 struct mgmt_ev_device_unblocked {
432 struct mgmt_addr_info addr;
435 #define MGMT_EV_DEVICE_UNPAIRED 0x0016
436 struct mgmt_ev_device_unpaired {
437 struct mgmt_addr_info addr;
440 static const char *mgmt_op[] = {
445 "Read Controller Info",
449 "Set Fast Connectable", /* 0x0008 */
452 "Set Secure Simple Pairing",
457 "Add UUID", /* 0x0010 */
460 "Load Long Term Keys",
464 "PIN Code Neg Reply",
465 "Set IO Capability", /* 0x0018 */
467 "Cancel Pair Device",
469 "User Confirm Reply",
470 "User Confirm Neg Reply",
471 "User Passkey Reply",
472 "User Passkey Neg Reply",
473 "Read Local OOB Data", /* 0x0020 */
474 "Add Remote OOB Data",
475 "Remove Remove OOB Data",
484 static const char *mgmt_ev[] = {
492 "Class of Device Changed",
493 "Local Name Changed", /* 0x0008 */
497 "Device Disconnected",
500 "User Confirm Request",
501 "User Passkey Request", /* 0x0010 */
502 "Authentication Failed",
510 static const char *mgmt_status[] = {
516 "Authentication Failed",
524 "Invalid Parameters",
532 #define NELEM(x) (sizeof(x) / sizeof((x)[0]))
535 static inline const char *mgmt_opstr(uint16_t op)
537 if (op >= NELEM(mgmt_op))
538 return "<unknown opcode>";
542 static inline const char *mgmt_evstr(uint16_t ev)
544 if (ev >= NELEM(mgmt_ev))
545 return "<unknown event>";
549 static inline const char *mgmt_errstr(uint8_t status)
551 if (status >= NELEM(mgmt_status))
552 return "<unknown status>";
553 return mgmt_status[status];