Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/next/external/cache/sources/hcitools/lib/mgmt.h
Views: 3959
/*1* BlueZ - Bluetooth protocol stack for Linux2*3* Copyright (C) 2010 Nokia Corporation4* Copyright (C) 2010 Marcel Holtmann <[email protected]>5*6*7* This program is free software; you can redistribute it and/or modify8* it under the terms of the GNU General Public License as published by9* the Free Software Foundation; either version 2 of the License, or10* (at your option) any later version.11*12* This program is distributed in the hope that it will be useful,13* but WITHOUT ANY WARRANTY; without even the implied warranty of14* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the15* GNU General Public License for more details.16*17* You should have received a copy of the GNU General Public License18* along with this program; if not, write to the Free Software19* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA20*21*/2223#ifndef __packed24#define __packed __attribute__((packed))25#endif2627#define MGMT_INDEX_NONE 0xFFFF2829#define MGMT_STATUS_SUCCESS 0x0030#define MGMT_STATUS_UNKNOWN_COMMAND 0x0131#define MGMT_STATUS_NOT_CONNECTED 0x0232#define MGMT_STATUS_FAILED 0x0333#define MGMT_STATUS_CONNECT_FAILED 0x0434#define MGMT_STATUS_AUTH_FAILED 0x0535#define MGMT_STATUS_NOT_PAIRED 0x0636#define MGMT_STATUS_NO_RESOURCES 0x0737#define MGMT_STATUS_TIMEOUT 0x0838#define MGMT_STATUS_ALREADY_CONNECTED 0x0939#define MGMT_STATUS_BUSY 0x0a40#define MGMT_STATUS_REJECTED 0x0b41#define MGMT_STATUS_NOT_SUPPORTED 0x0c42#define MGMT_STATUS_INVALID_PARAMS 0x0d43#define MGMT_STATUS_DISCONNECTED 0x0e44#define MGMT_STATUS_NOT_POWERED 0x0f45#define MGMT_STATUS_CANCELLED 0x1046#define MGMT_STATUS_INVALID_INDEX 0x1147#define MGMT_STATUS_RFKILLED 0x124849struct mgmt_hdr {50uint16_t opcode;51uint16_t index;52uint16_t len;53} __packed;54#define MGMT_HDR_SIZE 65556struct mgmt_addr_info {57bdaddr_t bdaddr;58uint8_t type;59} __packed;6061#define MGMT_OP_READ_VERSION 0x000162struct mgmt_rp_read_version {63uint8_t version;64uint16_t revision;65} __packed;6667#define MGMT_OP_READ_COMMANDS 0x000268struct mgmt_rp_read_commands {69uint16_t num_commands;70uint16_t num_events;71uint16_t opcodes[0];72} __packed;7374#define MGMT_OP_READ_INDEX_LIST 0x000375struct mgmt_rp_read_index_list {76uint16_t num_controllers;77uint16_t index[0];78} __packed;7980/* Reserve one extra byte for names in management messages so that they81* are always guaranteed to be nul-terminated */82#define MGMT_MAX_NAME_LENGTH (248 + 1)83#define MGMT_MAX_SHORT_NAME_LENGTH (10 + 1)8485#define MGMT_SETTING_POWERED 0x0000000186#define MGMT_SETTING_CONNECTABLE 0x0000000287#define MGMT_SETTING_FAST_CONNECTABLE 0x0000000488#define MGMT_SETTING_DISCOVERABLE 0x0000000889#define MGMT_SETTING_PAIRABLE 0x0000001090#define MGMT_SETTING_LINK_SECURITY 0x0000002091#define MGMT_SETTING_SSP 0x0000004092#define MGMT_SETTING_BREDR 0x0000008093#define MGMT_SETTING_HS 0x0000010094#define MGMT_SETTING_LE 0x0000020095#define MGMT_SETTING_ADVERTISING 0x000004009697#define MGMT_OP_READ_INFO 0x000498struct mgmt_rp_read_info {99bdaddr_t bdaddr;100uint8_t version;101uint16_t manufacturer;102uint32_t supported_settings;103uint32_t current_settings;104uint8_t dev_class[3];105uint8_t name[MGMT_MAX_NAME_LENGTH];106uint8_t short_name[MGMT_MAX_SHORT_NAME_LENGTH];107} __packed;108109struct mgmt_mode {110uint8_t val;111} __packed;112113struct mgmt_cod {114uint8_t val[3];115} __packed;116117#define MGMT_OP_SET_POWERED 0x0005118119#define MGMT_OP_SET_DISCOVERABLE 0x0006120struct mgmt_cp_set_discoverable {121uint8_t val;122uint16_t timeout;123} __packed;124125#define MGMT_OP_SET_CONNECTABLE 0x0007126127#define MGMT_OP_SET_FAST_CONNECTABLE 0x0008128129#define MGMT_OP_SET_PAIRABLE 0x0009130131#define MGMT_OP_SET_LINK_SECURITY 0x000A132133#define MGMT_OP_SET_SSP 0x000B134135#define MGMT_OP_SET_HS 0x000C136137#define MGMT_OP_SET_LE 0x000D138139#define MGMT_OP_SET_DEV_CLASS 0x000E140struct mgmt_cp_set_dev_class {141uint8_t major;142uint8_t minor;143} __packed;144145#define MGMT_OP_SET_LOCAL_NAME 0x000F146struct mgmt_cp_set_local_name {147uint8_t name[MGMT_MAX_NAME_LENGTH];148uint8_t short_name[MGMT_MAX_SHORT_NAME_LENGTH];149} __packed;150151#define MGMT_OP_ADD_UUID 0x0010152struct mgmt_cp_add_uuid {153uint8_t uuid[16];154uint8_t svc_hint;155} __packed;156157#define MGMT_OP_REMOVE_UUID 0x0011158struct mgmt_cp_remove_uuid {159uint8_t uuid[16];160} __packed;161162struct mgmt_link_key_info {163struct mgmt_addr_info addr;164uint8_t type;165uint8_t val[16];166uint8_t pin_len;167} __packed;168169#define MGMT_OP_LOAD_LINK_KEYS 0x0012170struct mgmt_cp_load_link_keys {171uint8_t debug_keys;172uint16_t key_count;173struct mgmt_link_key_info keys[0];174} __packed;175176struct mgmt_ltk_info {177struct mgmt_addr_info addr;178uint8_t authenticated;179uint8_t master;180uint8_t enc_size;181uint16_t ediv;182uint8_t rand[8];183uint8_t val[16];184} __packed;185186#define MGMT_OP_LOAD_LONG_TERM_KEYS 0x0013187struct mgmt_cp_load_long_term_keys {188uint16_t key_count;189struct mgmt_ltk_info keys[0];190} __packed;191192#define MGMT_OP_DISCONNECT 0x0014193struct mgmt_cp_disconnect {194struct mgmt_addr_info addr;195} __packed;196struct mgmt_rp_disconnect {197struct mgmt_addr_info addr;198} __packed;199200#define MGMT_OP_GET_CONNECTIONS 0x0015201struct mgmt_rp_get_connections {202uint16_t conn_count;203struct mgmt_addr_info addr[0];204} __packed;205206#define MGMT_OP_PIN_CODE_REPLY 0x0016207struct mgmt_cp_pin_code_reply {208struct mgmt_addr_info addr;209uint8_t pin_len;210uint8_t pin_code[16];211} __packed;212213#define MGMT_OP_PIN_CODE_NEG_REPLY 0x0017214struct mgmt_cp_pin_code_neg_reply {215struct mgmt_addr_info addr;216} __packed;217218#define MGMT_OP_SET_IO_CAPABILITY 0x0018219struct mgmt_cp_set_io_capability {220uint8_t io_capability;221} __packed;222223#define MGMT_OP_PAIR_DEVICE 0x0019224struct mgmt_cp_pair_device {225struct mgmt_addr_info addr;226uint8_t io_cap;227} __packed;228struct mgmt_rp_pair_device {229struct mgmt_addr_info addr;230} __packed;231232#define MGMT_OP_CANCEL_PAIR_DEVICE 0x001A233234#define MGMT_OP_UNPAIR_DEVICE 0x001B235struct mgmt_cp_unpair_device {236struct mgmt_addr_info addr;237uint8_t disconnect;238} __packed;239struct mgmt_rp_unpair_device {240struct mgmt_addr_info addr;241} __packed;242243#define MGMT_OP_USER_CONFIRM_REPLY 0x001C244struct mgmt_cp_user_confirm_reply {245struct mgmt_addr_info addr;246} __packed;247struct mgmt_rp_user_confirm_reply {248struct mgmt_addr_info addr;249} __packed;250251#define MGMT_OP_USER_CONFIRM_NEG_REPLY 0x001D252253#define MGMT_OP_USER_PASSKEY_REPLY 0x001E254struct mgmt_cp_user_passkey_reply {255struct mgmt_addr_info addr;256uint32_t passkey;257} __packed;258struct mgmt_rp_user_passkey_reply {259struct mgmt_addr_info addr;260} __packed;261262#define MGMT_OP_USER_PASSKEY_NEG_REPLY 0x001F263struct mgmt_cp_user_passkey_neg_reply {264struct mgmt_addr_info addr;265} __packed;266267#define MGMT_OP_READ_LOCAL_OOB_DATA 0x0020268struct mgmt_rp_read_local_oob_data {269uint8_t hash[16];270uint8_t randomizer[16];271} __packed;272273#define MGMT_OP_ADD_REMOTE_OOB_DATA 0x0021274struct mgmt_cp_add_remote_oob_data {275struct mgmt_addr_info addr;276uint8_t hash[16];277uint8_t randomizer[16];278} __packed;279280#define MGMT_OP_REMOVE_REMOTE_OOB_DATA 0x0022281struct mgmt_cp_remove_remote_oob_data {282struct mgmt_addr_info addr;283} __packed;284285#define MGMT_OP_START_DISCOVERY 0x0023286struct mgmt_cp_start_discovery {287uint8_t type;288} __packed;289290#define MGMT_OP_STOP_DISCOVERY 0x0024291struct mgmt_cp_stop_discovery {292uint8_t type;293} __packed;294295#define MGMT_OP_CONFIRM_NAME 0x0025296struct mgmt_cp_confirm_name {297struct mgmt_addr_info addr;298uint8_t name_known;299} __packed;300struct mgmt_rp_confirm_name {301struct mgmt_addr_info addr;302} __packed;303304#define MGMT_OP_BLOCK_DEVICE 0x0026305struct mgmt_cp_block_device {306struct mgmt_addr_info addr;307} __packed;308309#define MGMT_OP_UNBLOCK_DEVICE 0x0027310struct mgmt_cp_unblock_device {311struct mgmt_addr_info addr;312} __packed;313314#define MGMT_OP_SET_DEVICE_ID 0x0028315struct mgmt_cp_set_device_id {316uint16_t source;317uint16_t vendor;318uint16_t product;319uint16_t version;320} __packed;321322#define MGMT_OP_SET_ADVERTISING 0x0029323324#define MGMT_OP_SET_BREDR 0x002A325326#define MGMT_OP_SET_STATIC_ADDRESS 0x002B327struct mgmt_cp_set_static_address {328bdaddr_t bdaddr;329} __packed;330331#define MGMT_OP_SET_SCAN_PARAMS 0x002C332struct mgmt_cp_set_scan_params {333uint16_t interval;334uint16_t window;335} __packed;336337#define MGMT_EV_CMD_COMPLETE 0x0001338struct mgmt_ev_cmd_complete {339uint16_t opcode;340uint8_t status;341uint8_t data[0];342} __packed;343344#define MGMT_EV_CMD_STATUS 0x0002345struct mgmt_ev_cmd_status {346uint16_t opcode;347uint8_t status;348} __packed;349350#define MGMT_EV_CONTROLLER_ERROR 0x0003351struct mgmt_ev_controller_error {352uint8_t error_code;353} __packed;354355#define MGMT_EV_INDEX_ADDED 0x0004356357#define MGMT_EV_INDEX_REMOVED 0x0005358359#define MGMT_EV_NEW_SETTINGS 0x0006360361#define MGMT_EV_CLASS_OF_DEV_CHANGED 0x0007362struct mgmt_ev_class_of_dev_changed {363uint8_t class_of_dev[3];364} __packed;365366#define MGMT_EV_LOCAL_NAME_CHANGED 0x0008367struct mgmt_ev_local_name_changed {368uint8_t name[MGMT_MAX_NAME_LENGTH];369uint8_t short_name[MGMT_MAX_SHORT_NAME_LENGTH];370} __packed;371372#define MGMT_EV_NEW_LINK_KEY 0x0009373struct mgmt_ev_new_link_key {374uint8_t store_hint;375struct mgmt_link_key_info key;376} __packed;377378#define MGMT_EV_NEW_LONG_TERM_KEY 0x000A379struct mgmt_ev_new_long_term_key {380uint8_t store_hint;381struct mgmt_ltk_info key;382} __packed;383384#define MGMT_EV_DEVICE_CONNECTED 0x000B385struct mgmt_ev_device_connected {386struct mgmt_addr_info addr;387uint32_t flags;388uint16_t eir_len;389uint8_t eir[0];390} __packed;391392#define MGMT_DEV_DISCONN_UNKNOWN 0x00393#define MGMT_DEV_DISCONN_TIMEOUT 0x01394#define MGMT_DEV_DISCONN_LOCAL_HOST 0x02395#define MGMT_DEV_DISCONN_REMOTE 0x03396397#define MGMT_EV_DEVICE_DISCONNECTED 0x000C398struct mgmt_ev_device_disconnected {399struct mgmt_addr_info addr;400uint8_t reason;401} __packed;402403#define MGMT_EV_CONNECT_FAILED 0x000D404struct mgmt_ev_connect_failed {405struct mgmt_addr_info addr;406uint8_t status;407} __packed;408409#define MGMT_EV_PIN_CODE_REQUEST 0x000E410struct mgmt_ev_pin_code_request {411struct mgmt_addr_info addr;412uint8_t secure;413} __packed;414415#define MGMT_EV_USER_CONFIRM_REQUEST 0x000F416struct mgmt_ev_user_confirm_request {417struct mgmt_addr_info addr;418uint8_t confirm_hint;419uint32_t value;420} __packed;421422#define MGMT_EV_USER_PASSKEY_REQUEST 0x0010423struct mgmt_ev_user_passkey_request {424struct mgmt_addr_info addr;425} __packed;426427#define MGMT_EV_AUTH_FAILED 0x0011428struct mgmt_ev_auth_failed {429struct mgmt_addr_info addr;430uint8_t status;431} __packed;432433#define MGMT_DEV_FOUND_CONFIRM_NAME 0x01434#define MGMT_DEV_FOUND_LEGACY_PAIRING 0x02435436#define MGMT_EV_DEVICE_FOUND 0x0012437struct mgmt_ev_device_found {438struct mgmt_addr_info addr;439int8_t rssi;440uint32_t flags;441uint16_t eir_len;442uint8_t eir[0];443} __packed;444445#define MGMT_EV_DISCOVERING 0x0013446struct mgmt_ev_discovering {447uint8_t type;448uint8_t discovering;449} __packed;450451#define MGMT_EV_DEVICE_BLOCKED 0x0014452struct mgmt_ev_device_blocked {453struct mgmt_addr_info addr;454} __packed;455456#define MGMT_EV_DEVICE_UNBLOCKED 0x0015457struct mgmt_ev_device_unblocked {458struct mgmt_addr_info addr;459} __packed;460461#define MGMT_EV_DEVICE_UNPAIRED 0x0016462struct mgmt_ev_device_unpaired {463struct mgmt_addr_info addr;464} __packed;465466#define MGMT_EV_PASSKEY_NOTIFY 0x0017467struct mgmt_ev_passkey_notify {468struct mgmt_addr_info addr;469uint32_t passkey;470uint8_t entered;471} __packed;472473static const char *mgmt_op[] = {474"<0x0000>",475"Read Version",476"Read Commands",477"Read Index List",478"Read Controller Info",479"Set Powered",480"Set Discoverable",481"Set Connectable",482"Set Fast Connectable", /* 0x0008 */483"Set Pairable",484"Set Link Security",485"Set Secure Simple Pairing",486"Set High Speed",487"Set Low Energy",488"Set Dev Class",489"Set Local Name",490"Add UUID", /* 0x0010 */491"Remove UUID",492"Load Link Keys",493"Load Long Term Keys",494"Disconnect",495"Get Connections",496"PIN Code Reply",497"PIN Code Neg Reply",498"Set IO Capability", /* 0x0018 */499"Pair Device",500"Cancel Pair Device",501"Unpair Device",502"User Confirm Reply",503"User Confirm Neg Reply",504"User Passkey Reply",505"User Passkey Neg Reply",506"Read Local OOB Data", /* 0x0020 */507"Add Remote OOB Data",508"Remove Remove OOB Data",509"Start Discovery",510"Stop Discovery",511"Confirm Name",512"Block Device",513"Unblock Device",514"Set Device ID",515"Set Advertising",516"Set BR/EDR",517"Set Static Address",518"Set Scan Parameters",519};520521static const char *mgmt_ev[] = {522"<0x0000>",523"Command Complete",524"Command Status",525"Controller Error",526"Index Added",527"Index Removed",528"New Settings",529"Class of Device Changed",530"Local Name Changed", /* 0x0008 */531"New Link Key",532"New Long Term Key",533"Device Connected",534"Device Disconnected",535"Connect Failed",536"PIN Code Request",537"User Confirm Request",538"User Passkey Request", /* 0x0010 */539"Authentication Failed",540"Device Found",541"Discovering",542"Device Blocked",543"Device Unblocked",544"Device Unpaired",545"Passkey Notify",546};547548static const char *mgmt_status[] = {549"Success",550"Unknown Command",551"Not Connected",552"Failed",553"Connect Failed",554"Authentication Failed",555"Not Paired",556"No Resources",557"Timeout",558"Already Connected",559"Busy",560"Rejected",561"Not Supported",562"Invalid Parameters",563"Disconnected",564"Not Powered",565"Cancelled",566"Invalid Index",567"Blocked through rfkill",568};569570#ifndef NELEM571#define NELEM(x) (sizeof(x) / sizeof((x)[0]))572#endif573574static inline const char *mgmt_opstr(uint16_t op)575{576if (op >= NELEM(mgmt_op))577return "<unknown opcode>";578return mgmt_op[op];579}580581static inline const char *mgmt_evstr(uint16_t ev)582{583if (ev >= NELEM(mgmt_ev))584return "<unknown event>";585return mgmt_ev[ev];586}587588static inline const char *mgmt_errstr(uint8_t status)589{590if (status >= NELEM(mgmt_status))591return "<unknown status>";592return mgmt_status[status];593}594595596