12 #define __packed __attribute__((packed)) 15 #define MGMT_INDEX_NONE 0xFFFF 17 #define MGMT_STATUS_SUCCESS 0x00 18 #define MGMT_STATUS_UNKNOWN_COMMAND 0x01 19 #define MGMT_STATUS_NOT_CONNECTED 0x02 20 #define MGMT_STATUS_FAILED 0x03 21 #define MGMT_STATUS_CONNECT_FAILED 0x04 22 #define MGMT_STATUS_AUTH_FAILED 0x05 23 #define MGMT_STATUS_NOT_PAIRED 0x06 24 #define MGMT_STATUS_NO_RESOURCES 0x07 25 #define MGMT_STATUS_TIMEOUT 0x08 26 #define MGMT_STATUS_ALREADY_CONNECTED 0x09 27 #define MGMT_STATUS_BUSY 0x0a 28 #define MGMT_STATUS_REJECTED 0x0b 29 #define MGMT_STATUS_NOT_SUPPORTED 0x0c 30 #define MGMT_STATUS_INVALID_PARAMS 0x0d 31 #define MGMT_STATUS_DISCONNECTED 0x0e 32 #define MGMT_STATUS_NOT_POWERED 0x0f 33 #define MGMT_STATUS_CANCELLED 0x10 34 #define MGMT_STATUS_INVALID_INDEX 0x11 35 #define MGMT_STATUS_RFKILLED 0x12 36 #define MGMT_STATUS_ALREADY_PAIRED 0x13 37 #define MGMT_STATUS_PERMISSION_DENIED 0x14 44 #define MGMT_HDR_SIZE 6 57 #define MGMT_OP_READ_VERSION 0x0001 63 #define MGMT_OP_READ_COMMANDS 0x0002 65 uint16_t num_commands;
70 #define MGMT_OP_READ_INDEX_LIST 0x0003 72 uint16_t num_controllers;
78 #define MGMT_MAX_NAME_LENGTH (248 + 1) 79 #define MGMT_MAX_SHORT_NAME_LENGTH (10 + 1) 81 #define MGMT_SETTING_POWERED 0x00000001 82 #define MGMT_SETTING_CONNECTABLE 0x00000002 83 #define MGMT_SETTING_FAST_CONNECTABLE 0x00000004 84 #define MGMT_SETTING_DISCOVERABLE 0x00000008 85 #define MGMT_SETTING_BONDABLE 0x00000010 86 #define MGMT_SETTING_LINK_SECURITY 0x00000020 87 #define MGMT_SETTING_SSP 0x00000040 88 #define MGMT_SETTING_BREDR 0x00000080 89 #define MGMT_SETTING_HS 0x00000100 90 #define MGMT_SETTING_LE 0x00000200 91 #define MGMT_SETTING_ADVERTISING 0x00000400 92 #define MGMT_SETTING_SECURE_CONN 0x00000800 93 #define MGMT_SETTING_DEBUG_KEYS 0x00001000 94 #define MGMT_SETTING_PRIVACY 0x00002000 95 #define MGMT_SETTING_CONFIGURATION 0x00004000 96 #define MGMT_SETTING_STATIC_ADDRESS 0x00008000 97 #define MGMT_SETTING_PHY_CONFIGURATION 0x00010000 98 #define MGMT_SETTING_WIDEBAND_SPEECH 0x00020000 100 #define MGMT_OP_READ_INFO 0x0004 104 uint16_t manufacturer;
105 uint32_t supported_settings;
106 uint32_t current_settings;
107 uint8_t dev_class[3];
108 uint8_t name[MGMT_MAX_NAME_LENGTH];
109 uint8_t short_name[MGMT_MAX_SHORT_NAME_LENGTH];
120 #define MGMT_OP_SET_POWERED 0x0005 122 #define MGMT_OP_SET_DISCOVERABLE 0x0006 128 #define MGMT_OP_SET_CONNECTABLE 0x0007 130 #define MGMT_OP_SET_FAST_CONNECTABLE 0x0008 132 #define MGMT_OP_SET_BONDABLE 0x0009 134 #define MGMT_OP_SET_LINK_SECURITY 0x000A 136 #define MGMT_OP_SET_SSP 0x000B 138 #define MGMT_OP_SET_HS 0x000C 140 #define MGMT_OP_SET_LE 0x000D 142 #define MGMT_OP_SET_DEV_CLASS 0x000E 148 #define MGMT_OP_SET_LOCAL_NAME 0x000F 150 uint8_t name[MGMT_MAX_NAME_LENGTH];
151 uint8_t short_name[MGMT_MAX_SHORT_NAME_LENGTH];
154 #define MGMT_OP_ADD_UUID 0x0010 160 #define MGMT_OP_REMOVE_UUID 0x0011 172 #define MGMT_OP_LOAD_LINK_KEYS 0x0012 189 #define MGMT_OP_LOAD_LONG_TERM_KEYS 0x0013 195 #define MGMT_OP_DISCONNECT 0x0014 203 #define MGMT_OP_GET_CONNECTIONS 0x0015 209 #define MGMT_OP_PIN_CODE_REPLY 0x0016 213 uint8_t pin_code[16];
216 #define MGMT_OP_PIN_CODE_NEG_REPLY 0x0017 221 #define MGMT_OP_SET_IO_CAPABILITY 0x0018 223 uint8_t io_capability;
226 #define MGMT_OP_PAIR_DEVICE 0x0019 235 #define MGMT_OP_CANCEL_PAIR_DEVICE 0x001A 237 #define MGMT_OP_UNPAIR_DEVICE 0x001B 246 #define MGMT_OP_USER_CONFIRM_REPLY 0x001C 254 #define MGMT_OP_USER_CONFIRM_NEG_REPLY 0x001D 256 #define MGMT_OP_USER_PASSKEY_REPLY 0x001E 265 #define MGMT_OP_USER_PASSKEY_NEG_REPLY 0x001F 270 #define MGMT_OP_READ_LOCAL_OOB_DATA 0x0020 278 #define MGMT_OP_ADD_REMOTE_OOB_DATA 0x0021 287 #define MGMT_OP_REMOVE_REMOTE_OOB_DATA 0x0022 292 #define MGMT_OP_START_DISCOVERY 0x0023 297 #define MGMT_OP_STOP_DISCOVERY 0x0024 302 #define MGMT_OP_CONFIRM_NAME 0x0025 311 #define MGMT_OP_BLOCK_DEVICE 0x0026 316 #define MGMT_OP_UNBLOCK_DEVICE 0x0027 321 #define MGMT_OP_SET_DEVICE_ID 0x0028 329 #define MGMT_OP_SET_ADVERTISING 0x0029 331 #define MGMT_OP_SET_BREDR 0x002A 333 #define MGMT_OP_SET_STATIC_ADDRESS 0x002B 338 #define MGMT_OP_SET_SCAN_PARAMS 0x002C 344 #define MGMT_OP_SET_SECURE_CONN 0x002D 346 #define MGMT_OP_SET_DEBUG_KEYS 0x002E 353 #define MGMT_OP_SET_PRIVACY 0x002F 359 #define MGMT_OP_LOAD_IRKS 0x0030 365 #define MGMT_OP_GET_CONN_INFO 0x0031 376 #define MGMT_OP_GET_CLOCK_INFO 0x0032 382 uint32_t local_clock;
383 uint32_t piconet_clock;
387 #define MGMT_OP_ADD_DEVICE 0x0033 396 #define MGMT_OP_REMOVE_DEVICE 0x0034 406 uint16_t min_interval;
407 uint16_t max_interval;
412 #define MGMT_OP_LOAD_CONN_PARAM 0x0035 414 uint16_t param_count;
418 #define MGMT_OP_READ_UNCONF_INDEX_LIST 0x0036 420 uint16_t num_controllers;
424 #define MGMT_OPTION_EXTERNAL_CONFIG 0x00000001 425 #define MGMT_OPTION_PUBLIC_ADDRESS 0x00000002 427 #define MGMT_OP_READ_CONFIG_INFO 0x0037 429 uint16_t manufacturer;
430 uint32_t supported_options;
431 uint32_t missing_options;
434 #define MGMT_OP_SET_EXTERNAL_CONFIG 0x0038 439 #define MGMT_OP_SET_PUBLIC_ADDRESS 0x0039 444 #define MGMT_OP_START_SERVICE_DISCOVERY 0x003A 449 uint8_t uuids[0][16];
452 #define MGMT_OP_READ_LOCAL_OOB_EXT_DATA 0x003B 462 #define MGMT_OP_READ_EXT_INDEX_LIST 0x003C 464 uint16_t num_controllers;
472 #define MGMT_OP_READ_ADV_FEATURES 0x003D 474 uint32_t supported_flags;
475 uint8_t max_adv_data_len;
476 uint8_t max_scan_rsp_len;
477 uint8_t max_instances;
478 uint8_t num_instances;
482 #define MGMT_OP_ADD_ADVERTISING 0x003E 488 uint8_t adv_data_len;
489 uint8_t scan_rsp_len;
496 #define MGMT_ADV_FLAG_CONNECTABLE (1 << 0) 497 #define MGMT_ADV_FLAG_DISCOV (1 << 1) 498 #define MGMT_ADV_FLAG_LIMITED_DISCOV (1 << 2) 499 #define MGMT_ADV_FLAG_MANAGED_FLAGS (1 << 3) 500 #define MGMT_ADV_FLAG_TX_POWER (1 << 4) 501 #define MGMT_ADV_FLAG_APPEARANCE (1 << 5) 502 #define MGMT_ADV_FLAG_LOCAL_NAME (1 << 6) 503 #define MGMT_ADV_FLAG_SEC_1M (1 << 7) 504 #define MGMT_ADV_FLAG_SEC_2M (1 << 8) 505 #define MGMT_ADV_FLAG_SEC_CODED (1 << 9) 506 #define MGMT_ADV_FLAG_CAN_SET_TX_POWER (1 << 10) 507 #define MGMT_ADV_FLAG_HW_OFFLOAD (1 << 11) 508 #define MGMT_ADV_PARAM_DURATION (1 << 12) 509 #define MGMT_ADV_PARAM_TIMEOUT (1 << 13) 510 #define MGMT_ADV_PARAM_INTERVALS (1 << 14) 511 #define MGMT_ADV_PARAM_TX_POWER (1 << 15) 512 #define MGMT_ADV_PARAM_SCAN_RSP (1 << 16) 514 #define MGMT_OP_REMOVE_ADVERTISING 0x003F 518 #define MGMT_REMOVE_ADVERTISING_SIZE 1 523 #define MGMT_OP_GET_ADV_SIZE_INFO 0x0040 528 #define MGMT_GET_ADV_SIZE_INFO_SIZE 5 532 uint8_t max_adv_data_len;
533 uint8_t max_scan_rsp_len;
536 #define MGMT_OP_START_LIMITED_DISCOVERY 0x0041 538 #define MGMT_OP_READ_EXT_INFO 0x0042 542 uint16_t manufacturer;
543 uint32_t supported_settings;
544 uint32_t current_settings;
549 #define MGMT_OP_SET_APPEARANCE 0x0043 554 #define MGMT_OP_GET_PHY_CONFIGURATION 0x0044 556 uint32_t supported_phys;
557 uint32_t configurable_phys;
558 uint32_t selected_phys;
561 #define MGMT_PHY_BR_1M_1SLOT 0x00000001 562 #define MGMT_PHY_BR_1M_3SLOT 0x00000002 563 #define MGMT_PHY_BR_1M_5SLOT 0x00000004 564 #define MGMT_PHY_EDR_2M_1SLOT 0x00000008 565 #define MGMT_PHY_EDR_2M_3SLOT 0x00000010 566 #define MGMT_PHY_EDR_2M_5SLOT 0x00000020 567 #define MGMT_PHY_EDR_3M_1SLOT 0x00000040 568 #define MGMT_PHY_EDR_3M_3SLOT 0x00000080 569 #define MGMT_PHY_EDR_3M_5SLOT 0x00000100 570 #define MGMT_PHY_LE_1M_TX 0x00000200 571 #define MGMT_PHY_LE_1M_RX 0x00000400 572 #define MGMT_PHY_LE_2M_TX 0x00000800 573 #define MGMT_PHY_LE_2M_RX 0x00001000 574 #define MGMT_PHY_LE_CODED_TX 0x00002000 575 #define MGMT_PHY_LE_CODED_RX 0x00004000 577 #define MGMT_PHY_LE_TX_MASK (MGMT_PHY_LE_1M_TX | MGMT_PHY_LE_2M_TX | \ 578 MGMT_PHY_LE_CODED_TX) 579 #define MGMT_PHY_LE_RX_MASK (MGMT_PHY_LE_1M_RX | MGMT_PHY_LE_2M_RX | \ 580 MGMT_PHY_LE_CODED_RX) 582 #define MGMT_OP_SET_PHY_CONFIGURATION 0x0045 584 uint32_t selected_phys;
587 #define MGMT_OP_SET_BLOCKED_KEYS 0x0046 589 #define MGMT_OP_SET_WIDEBAND_SPEECH 0x0047 591 #define HCI_BLOCKED_KEY_TYPE_LINKKEY 0x00 592 #define HCI_BLOCKED_KEY_TYPE_LTK 0x01 593 #define HCI_BLOCKED_KEY_TYPE_IRK 0x02 605 #define MGMT_CAP_SEC_FLAGS 0x01 606 #define MGMT_CAP_MAX_ENC_KEY_SIZE 0x02 607 #define MGMT_CAP_SMP_MAX_ENC_KEY_SIZE 0x03 608 #define MGMT_CAP_LE_TX_PWR 0x04 610 #define MGMT_OP_READ_CONTROLLER_CAP 0x0048 611 #define MGMT_READ_CONTROLLER_CAP_SIZE 0 617 #define MGMT_OP_READ_EXP_FEATURES_INFO 0x0049 619 uint16_t feature_count;
626 #define MGMT_OP_SET_EXP_FEATURE 0x004a 631 #define MGMT_SET_EXP_FEATURE_SIZE 17 637 #define MGMT_OP_READ_DEF_SYSTEM_CONFIG 0x004b 639 uint8_t parameters[0];
642 #define MGMT_OP_SET_DEF_SYSTEM_CONFIG 0x004c 644 uint8_t parameters[0];
647 #define MGMT_OP_READ_DEF_RUNTIME_CONFIG 0x004d 649 uint8_t parameters[0];
652 #define MGMT_OP_SET_DEF_RUNTIME_CONFIG 0x004e 654 uint8_t parameters[0];
657 #define MGMT_OP_GET_DEVICE_FLAGS 0x004F 658 #define MGMT_GET_DEVICE_FLAGS_SIZE 7 664 uint32_t supported_flags;
665 uint32_t current_flags;
668 #define DEVICE_FLAG_REMOTE_WAKEUP BIT(0) 669 #define DEVICE_FLAG_DEVICE_PRIVACY BIT(1) 671 #define MGMT_OP_SET_DEVICE_FLAGS 0x0050 672 #define MGMT_SET_DEVICE_FLAGS_SIZE 11 675 uint32_t current_flags;
681 #define MGMT_ADV_MONITOR_FEATURE_MASK_OR_PATTERNS (1 << 0) 683 #define MGMT_OP_READ_ADV_MONITOR_FEATURES 0x0051 685 uint32_t supported_features;
686 uint32_t enabled_features;
687 uint16_t max_num_handles;
688 uint8_t max_num_patterns;
689 uint16_t num_handles;
700 #define MGMT_OP_ADD_ADV_PATTERNS_MONITOR 0x0052 702 uint8_t pattern_count;
706 uint16_t monitor_handle;
709 #define MGMT_OP_REMOVE_ADV_MONITOR 0x0053 711 uint16_t monitor_handle;
714 uint16_t monitor_handle;
717 #define MGMT_OP_ADD_EXT_ADV_PARAMS 0x0054 723 uint32_t min_interval;
724 uint32_t max_interval;
730 uint8_t max_adv_data_len;
731 uint8_t max_scan_rsp_len;
734 #define MGMT_OP_ADD_EXT_ADV_DATA 0x0055 737 uint8_t adv_data_len;
738 uint8_t scan_rsp_len;
746 int8_t high_threshold;
747 uint16_t high_threshold_timeout;
748 int8_t low_threshold;
749 uint16_t low_threshold_timeout;
750 uint8_t sampling_period;
753 #define MGMT_OP_ADD_ADV_PATTERNS_MONITOR_RSSI 0x0056 756 uint8_t pattern_count;
760 #define MGMT_EV_CMD_COMPLETE 0x0001 767 #define MGMT_EV_CMD_STATUS 0x0002 773 #define MGMT_EV_CONTROLLER_ERROR 0x0003 778 #define MGMT_EV_INDEX_ADDED 0x0004 780 #define MGMT_EV_INDEX_REMOVED 0x0005 782 #define MGMT_EV_NEW_SETTINGS 0x0006 784 #define MGMT_EV_CLASS_OF_DEV_CHANGED 0x0007 786 uint8_t dev_class[3];
789 #define MGMT_EV_LOCAL_NAME_CHANGED 0x0008 791 uint8_t name[MGMT_MAX_NAME_LENGTH];
792 uint8_t short_name[MGMT_MAX_SHORT_NAME_LENGTH];
795 #define MGMT_EV_NEW_LINK_KEY 0x0009 801 #define MGMT_EV_NEW_LONG_TERM_KEY 0x000A 807 #define MGMT_EV_DEVICE_CONNECTED 0x000B 815 #define MGMT_DEV_DISCONN_UNKNOWN 0x00 816 #define MGMT_DEV_DISCONN_TIMEOUT 0x01 817 #define MGMT_DEV_DISCONN_LOCAL_HOST 0x02 818 #define MGMT_DEV_DISCONN_REMOTE 0x03 819 #define MGMT_DEV_DISCONN_LOCAL_HOST_SUSPEND 0x05 821 #define MGMT_EV_DEVICE_DISCONNECTED 0x000C 827 #define MGMT_EV_CONNECT_FAILED 0x000D 833 #define MGMT_EV_PIN_CODE_REQUEST 0x000E 839 #define MGMT_EV_USER_CONFIRM_REQUEST 0x000F 842 uint8_t confirm_hint;
846 #define MGMT_EV_USER_PASSKEY_REQUEST 0x0010 851 #define MGMT_EV_AUTH_FAILED 0x0011 857 #define MGMT_DEV_FOUND_CONFIRM_NAME 0x01 858 #define MGMT_DEV_FOUND_LEGACY_PAIRING 0x02 859 #define MGMT_DEV_FOUND_NOT_CONNECTABLE 0x04 861 #define MGMT_EV_DEVICE_FOUND 0x0012 870 #define MGMT_EV_DISCOVERING 0x0013 876 #define MGMT_EV_DEVICE_BLOCKED 0x0014 881 #define MGMT_EV_DEVICE_UNBLOCKED 0x0015 886 #define MGMT_EV_DEVICE_UNPAIRED 0x0016 891 #define MGMT_EV_PASSKEY_NOTIFY 0x0017 898 #define MGMT_EV_NEW_IRK 0x0018 911 #define MGMT_EV_NEW_CSRK 0x0019 917 #define MGMT_EV_DEVICE_ADDED 0x001a 923 #define MGMT_EV_DEVICE_REMOVED 0x001b 928 #define MGMT_EV_NEW_CONN_PARAM 0x001c 932 uint16_t min_interval;
933 uint16_t max_interval;
938 #define MGMT_EV_UNCONF_INDEX_ADDED 0x001d 940 #define MGMT_EV_UNCONF_INDEX_REMOVED 0x001e 942 #define MGMT_EV_NEW_CONFIG_OPTIONS 0x001f 944 #define MGMT_EV_EXT_INDEX_ADDED 0x0020 950 #define MGMT_EV_EXT_INDEX_REMOVED 0x0021 956 #define MGMT_EV_LOCAL_OOB_DATA_UPDATED 0x0022 963 #define MGMT_EV_ADVERTISING_ADDED 0x0023 968 #define MGMT_EV_ADVERTISING_REMOVED 0x0024 973 #define MGMT_EV_EXT_INFO_CHANGED 0x0025 979 #define MGMT_EV_PHY_CONFIGURATION_CHANGED 0x0026 981 uint16_t selected_phys;
984 #define MGMT_EV_EXP_FEATURE_CHANGE 0x0027 990 #define MGMT_EV_DEVICE_FLAGS_CHANGED 0x002a 993 uint32_t supported_flags;
994 uint32_t current_flags;
997 #define MGMT_EV_ADV_MONITOR_ADDED 0x002b 999 uint16_t monitor_handle;
1002 #define MGMT_EV_ADV_MONITOR_REMOVED 0x002c 1004 uint16_t monitor_handle;
1007 #define MGMT_EV_CONTROLLER_SUSPEND 0x002d 1009 uint8_t suspend_state;
1012 #define MGMT_EV_CONTROLLER_RESUME 0x002e 1015 uint8_t wake_reason;
1018 static const char *mgmt_op[] = {
1023 "Read Controller Info",
1027 "Set Fast Connectable",
1029 "Set Link Security",
1030 "Set Secure Simple Pairing",
1038 "Load Long Term Keys",
1042 "PIN Code Neg Reply",
1043 "Set IO Capability",
1045 "Cancel Pair Device",
1047 "User Confirm Reply",
1048 "User Confirm Neg Reply",
1049 "User Passkey Reply",
1050 "User Passkey Neg Reply",
1051 "Read Local OOB Data",
1052 "Add Remote OOB Data",
1053 "Remove Remove OOB Data",
1062 "Set Static Address",
1063 "Set Scan Parameters",
1064 "Set Secure Connections",
1067 "Load Identity Resolving Keys",
1068 "Get Connection Information",
1069 "Get Clock Information",
1072 "Load Connection Parameters",
1073 "Read Unconfigured Index List",
1074 "Read Controller Configuration Information",
1075 "Set External Configuration",
1076 "Set Public Address",
1077 "Start Service Discovery",
1078 "Read Local Out Of Band Extended Data",
1079 "Read Extended Controller Index List",
1080 "Read Advertising Features",
1082 "Remove Advertising",
1083 "Get Advertising Size Information",
1084 "Start Limited Discovery",
1085 "Read Extended Controller Information",
1087 "Get PHY Configuration",
1088 "Set PHY Configuration",
1090 "Set Wideband Speech",
1091 "Read Controller Capabilities Information",
1092 "Read Experimental Features Information",
1093 "Set Experimental Feature",
1094 "Read Default System Configuration",
1095 "Set Default System Configuration",
1096 "Read Default Runtime Configuration",
1097 "Set Default Runtime Configuration",
1100 "Read Advertisement Monitor Features",
1101 "Add Advertisement Patterns Monitor",
1102 "Remove Advertisement Monitor",
1103 "Add Extended Advertisement Parameters",
1104 "Add Extended Advertisement Data",
1105 "Add Advertisement Patterns Monitor RSSI",
1108 static const char *mgmt_ev[] = {
1116 "Class of Device Changed",
1117 "Local Name Changed",
1119 "New Long Term Key",
1121 "Device Disconnected",
1124 "User Confirm Request",
1125 "User Passkey Request",
1126 "Authentication Failed",
1133 "New Identity Resolving Key",
1134 "New Signature Resolving Key",
1137 "New Connection Parameter",
1138 "Unconfigured Index Added",
1139 "Unconfigured Index Removed",
1140 "New Configuration Options",
1141 "Extended Index Added",
1142 "Extended Index Removed",
1143 "Local Out Of Band Extended Data Updated",
1144 "Advertising Added",
1145 "Advertising Removed",
1146 "Extended Controller Information Changed",
1147 "PHY Configuration Changed",
1148 "Experimental Feature Changed",
1149 "Default System Configuration Changed",
1150 "Default Runtime Configuration Changed",
1151 "Device Flags Changed",
1152 "Advertisement Monitor Added",
1153 "Advertisement Monitor Removed",
1154 "Controller Suspend",
1155 "Controller Resume",
1158 static const char *mgmt_status[] = {
1164 "Authentication Failed",
1168 "Already Connected",
1172 "Invalid Parameters",
1177 "Blocked through rfkill",
1179 "Permission Denied",
1180 "Connection Not Established",
1184 #define NELEM(x) (sizeof(x) / sizeof((x)[0])) 1187 static inline const char *mgmt_opstr(uint16_t op)
1189 if (op >= NELEM(mgmt_op))
1190 return "<unknown opcode>";
1194 static inline const char *mgmt_evstr(uint16_t ev)
1196 if (ev >= NELEM(mgmt_ev))
1197 return "<unknown event>";
1201 static inline const char *mgmt_errstr(uint8_t status)
1203 if (status >= NELEM(mgmt_status))
1204 return "<unknown status>";
1205 return mgmt_status[status];