From 522601435d7a499f7116d9eb3c0763e03cbbe0bf Mon Sep 17 00:00:00 2001 From: Jack He Date: Tue, 18 Dec 2018 15:43:27 -0800 Subject: [PATCH] Atom: Add BluetoothLinkLayerConnectionEvent atom * Add this atom to report events related to Bluetooth link layer connection, including: - Obfuscated ID of remote device - Connection handle - Direction of the connection - Type of the connection - Associated HCI command and/or event - Status code associated with HCI command and/or event - Reason code associated with HCI command and/or event * Add enum definitions for HCI commands and events as defined in the Bluetooth 5.0 specification * Add enum definitions for link type and direction Bug: 112969790 Test: make, test drive with statsd Change-Id: I0fdc59274d49ad503e9ba9cf8f49c9d8872a4131 Merged-In: I0fdc59274d49ad503e9ba9cf8f49c9d8872a4131 (cherry picked from commit ab86dbd20cf17a1389d42135865eabfc4fc48604) --- cmds/statsd/src/atoms.proto | 86 +++ core/proto/Android.bp | 27 + core/proto/android/bluetooth/enums.proto | 15 + core/proto/android/bluetooth/hci/enums.proto | 519 +++++++++++++++++++ 4 files changed, 647 insertions(+) create mode 100644 core/proto/Android.bp create mode 100644 core/proto/android/bluetooth/hci/enums.proto diff --git a/cmds/statsd/src/atoms.proto b/cmds/statsd/src/atoms.proto index 7cfa58fb7bba6..f5ddbbac61f21 100644 --- a/cmds/statsd/src/atoms.proto +++ b/cmds/statsd/src/atoms.proto @@ -24,6 +24,7 @@ import "frameworks/base/cmds/statsd/src/atom_field_options.proto"; import "frameworks/base/core/proto/android/app/enums.proto"; import "frameworks/base/core/proto/android/app/job/enums.proto"; import "frameworks/base/core/proto/android/bluetooth/enums.proto"; +import "frameworks/base/core/proto/android/bluetooth/hci/enums.proto"; import "frameworks/base/core/proto/android/net/networkcapabilities.proto"; import "frameworks/base/core/proto/android/os/enums.proto"; import "frameworks/base/core/proto/android/server/connectivity/data_stall_event.proto"; @@ -129,6 +130,7 @@ message Atom { LowMemReported low_mem_reported = 81; NetworkDnsEventReported network_dns_event_reported = 116; DataStallEvent data_stall_event = 121; + BluetoothLinkLayerConnectionEvent bluetooth_link_layer_connection_event = 125; } // Pulled events will start at field 10000. @@ -1014,6 +1016,90 @@ message BluetoothConnectionStateChanged { optional int32 bt_profile = 3; } +// Logs when there is an event affecting Bluetooth device's link layer connection. +// - This event is triggered when there is a related HCI command or event +// - Users of this metrics can deduce Bluetooth device's connection state from these events +// - HCI commands are logged before the command is sent, after receiving command status, and after +// receiving command complete +// - HCI events are logged when they arrive +// +// Low level log from system/bt +// +// Bluetooth classic commands: +// - CMD_CREATE_CONNECTION +// - CMD_DISCONNECT +// - CMD_CREATE_CONNECTION_CANCEL +// - CMD_ACCEPT_CONNECTION_REQUEST +// - CMD_REJECT_CONNECTION_REQUEST +// - CMD_SETUP_ESCO_CONNECTION +// - CMD_ACCEPT_ESCO_CONNECTION +// - CMD_REJECT_ESCO_CONNECTION +// - CMD_ENH_SETUP_ESCO_CONNECTION +// - CMD_ENH_ACCEPT_ESCO_CONNECTION +// +// Bluetooth low energy commands: +// - CMD_BLE_CREATE_LL_CONN [Only logged on error or when initiator filter policy is 0x00] +// - CMD_BLE_CREATE_CONN_CANCEL [Only logged when there is an error] +// - CMD_BLE_EXTENDED_CREATE_CONNECTION [Only logged on error or when initiator filter policy is 0x00] +// - CMD_BLE_CLEAR_WHITE_LIST +// - CMD_BLE_ADD_WHITE_LIST +// - CMD_BLE_REMOVE_WHITE_LIST +// +// Bluetooth classic events: +// - EVT_CONNECTION_COMP +// - EVT_CONNECTION_REQUEST +// - EVT_DISCONNECTION_COMP +// - EVT_ESCO_CONNECTION_COMP +// - EVT_ESCO_CONNECTION_CHANGED +// +// Bluetooth low energy meta events: +// - BLE_EVT_CONN_COMPLETE_EVT +// - BLE_EVT_ENHANCED_CONN_COMPLETE_EVT +// +// Next tag: 10 +message BluetoothLinkLayerConnectionEvent { + // An identifier that can be used to match events for this device. + // Currently, this is a salted hash of the MAC address of this Bluetooth device. + // Salt: Randomly generated 256 bit value + // Hash algorithm: HMAC-SHA256 + // Size: 32 byte + // Default: null or empty if the device identifier is not known + optional bytes obfuscated_id = 1 [(android.os.statsd.log_mode) = MODE_BYTES]; + // Connection handle of this connection if available + // Range: 0x0000 - 0x0EFF (12 bits) + // Default: 0xFFFF if the handle is unknown + optional int32 connection_handle = 2; + // Direction of the link + // Default: DIRECTION_UNKNOWN + optional android.bluetooth.DirectionEnum direction = 3; + // Type of this link + // Default: LINK_TYPE_UNKNOWN + optional android.bluetooth.LinkTypeEnum type = 4; + + // Reason metadata for this link layer connection event, rules for interpretation: + // 1. If hci_cmd is set and valid, hci_event can be either EVT_COMMAND_STATUS or + // EVT_COMMAND_COMPLETE, ignore hci_ble_event in this case + // 2. If hci_event is set to EVT_BLE_META, look at hci_ble_event; otherwise, if hci_event is + // set and valid, ignore hci_ble_event + + // HCI command associated with this event + // Default: CMD_UNKNOWN + optional android.bluetooth.hci.CommandEnum hci_cmd = 5; + // HCI event associated with this event + // Default: EVT_UNKNOWN + optional android.bluetooth.hci.EventEnum hci_event = 6; + // HCI BLE meta event associated with this event + // Default: BLE_EVT_UNKNOWN + optional android.bluetooth.hci.BleMetaEventEnum hci_ble_event = 7; + // HCI command status code if this is triggerred by hci_cmd + // Default: STATUS_UNKNOWN + optional android.bluetooth.hci.StatusEnum cmd_status = 8; + // HCI reason code associated with this event + // Default: STATUS_UNKNOWN + optional android.bluetooth.hci.StatusEnum reason_code = 9; +} + + /** * Logs when something is plugged into or removed from the USB-C connector. * diff --git a/core/proto/Android.bp b/core/proto/Android.bp new file mode 100644 index 0000000000000..80cc2d4cab94d --- /dev/null +++ b/core/proto/Android.bp @@ -0,0 +1,27 @@ +// Copyright (C) 2018 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// C++ library for Bluetooth platform wide protobuf definitions +cc_library_static { + name: "libbt-platform-protos-lite", + host_supported: true, + proto: { + export_proto_headers: true, + type: "lite", + }, + srcs: [ + "android/bluetooth/enums.proto", + "android/bluetooth/hci/enums.proto", + ], +} diff --git a/core/proto/android/bluetooth/enums.proto b/core/proto/android/bluetooth/enums.proto index d0c9226643516..76c240ecff4dc 100644 --- a/core/proto/android/bluetooth/enums.proto +++ b/core/proto/android/bluetooth/enums.proto @@ -41,3 +41,18 @@ enum EnableDisableReasonEnum { ENABLE_DISABLE_REASON_USER_SWITCH = 8; ENABLE_DISABLE_REASON_RESTORE_USER_SETTING = 9; } + +enum DirectionEnum { + DIRECTION_UNKNOWN = 0; + DIRECTION_OUTGOING = 1; + DIRECTION_INCOMING = 2; +} + +// First item is the default value, other values follow Bluetooth spec definition +enum LinkTypeEnum { + // Link type is at most 1 byte (0xFF), thus 0xFFF must not be a valid value + LINK_TYPE_UNKNOWN = 0xFFF; + LINK_TYPE_SCO = 0x00; + LINK_TYPE_ACL = 0x01; + LINK_TYPE_ESCO = 0x02; +} diff --git a/core/proto/android/bluetooth/hci/enums.proto b/core/proto/android/bluetooth/hci/enums.proto new file mode 100644 index 0000000000000..e1d96bbce68aa --- /dev/null +++ b/core/proto/android/bluetooth/hci/enums.proto @@ -0,0 +1,519 @@ +/* + * Copyright 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +syntax = "proto2"; +package android.bluetooth.hci; + +option java_outer_classname = "BluetoothHciProtoEnums"; +option java_multiple_files = true; + +// HCI command opcodes (OCF+OGF) from Bluetooth 5.0 specification Vol 2, Part E, Section 7 +// Original definition: system/bt/stack/include/hcidefs.h +enum CommandEnum { + // Opcode is at most 2 bytes (0xFFFF), thus 0xFFFFF must not be a valid value + CMD_UNKNOWN = 0xFFFFF; + // Link control commands 0x0400 + CMD_INQUIRY = 0x0401; + CMD_INQUIRY_CANCEL = 0x0402; + CMD_PERIODIC_INQUIRY_MODE = 0x0403; + CMD_EXIT_PERIODIC_INQUIRY_MODE = 0x0404; + CMD_CREATE_CONNECTION = 0x0405; + CMD_DISCONNECT = 0x0406; + CMD_ADD_SCO_CONNECTION = 0x0407; // Deprecated since Bluetooth 1.2 + CMD_CREATE_CONNECTION_CANCEL = 0x0408; + CMD_ACCEPT_CONNECTION_REQUEST = 0x0409; + CMD_REJECT_CONNECTION_REQUEST = 0x040A; + CMD_LINK_KEY_REQUEST_REPLY = 0x040B; + CMD_LINK_KEY_REQUEST_NEG_REPLY = 0x040C; + CMD_PIN_CODE_REQUEST_REPLY = 0x040D; + CMD_PIN_CODE_REQUEST_NEG_REPLY = 0x040E; + CMD_CHANGE_CONN_PACKET_TYPE = 0x040F; + CMD_AUTHENTICATION_REQUESTED = 0x0411; + CMD_SET_CONN_ENCRYPTION = 0x0413; + CMD_CHANGE_CONN_LINK_KEY = 0x0415; + CMD_MASTER_LINK_KEY = 0x0417; + CMD_RMT_NAME_REQUEST = 0x0419; + CMD_RMT_NAME_REQUEST_CANCEL = 0x041A; + CMD_READ_RMT_FEATURES = 0x041B; + CMD_READ_RMT_EXT_FEATURES = 0x041C; + CMD_READ_RMT_VERSION_INFO = 0x041D; + CMD_READ_RMT_CLOCK_OFFSET = 0x041F; + CMD_READ_LMP_HANDLE = 0x0420; + CMD_SETUP_ESCO_CONNECTION = 0x0428; + CMD_ACCEPT_ESCO_CONNECTION = 0x0429; + CMD_REJECT_ESCO_CONNECTION = 0x042A; + CMD_IO_CAPABILITY_REQUEST_REPLY = 0x042B; + CMD_USER_CONF_REQUEST_REPLY = 0x042C; + CMD_USER_CONF_VALUE_NEG_REPLY = 0x042D; + CMD_USER_PASSKEY_REQ_REPLY = 0x042E; + CMD_USER_PASSKEY_REQ_NEG_REPLY = 0x042F; + CMD_REM_OOB_DATA_REQ_REPLY = 0x0430; + CMD_REM_OOB_DATA_REQ_NEG_REPLY = 0x0433; + CMD_IO_CAP_REQ_NEG_REPLY = 0x0434; + // BEGIN: AMP commands (not used in system/bt) + CMD_CREATE_PHYSICAL_LINK = 0x0435; + CMD_ACCEPT_PHYSICAL_LINK = 0x0436; + CMD_DISCONNECT_PHYSICAL_LINK = 0x0437; + CMD_CREATE_LOGICAL_LINK = 0x0438; + CMD_ACCEPT_LOGICAL_LINK = 0x0439; + CMD_DISCONNECT_LOGICAL_LINK = 0x043A; + CMD_LOGICAL_LINK_CANCEL = 0x043B; + CMD_FLOW_SPEC_MODIFY = 0x043C; + // END: AMP commands + CMD_ENH_SETUP_ESCO_CONNECTION = 0x043D; + CMD_ENH_ACCEPT_ESCO_CONNECTION = 0x043E; + CMD_TRUNCATED_PAGE = 0x043F; + CMD_TRUNCATED_PAGE_CANCEL = 0x0440; + CMD_SET_CLB = 0x0441; + CMD_RECEIVE_CLB = 0x0442; + CMD_START_SYNC_TRAIN = 0x0443; + CMD_RECEIVE_SYNC_TRAIN = 0x0444; + CMD_REM_OOB_EXTENDED_DATA_REQ_REPLY = 0x0445; // Not currently used in system/bt + // Link policy commands 0x0800 + CMD_HOLD_MODE = 0x0801; + CMD_SNIFF_MODE = 0x0803; + CMD_EXIT_SNIFF_MODE = 0x0804; + CMD_PARK_MODE = 0x0805; + CMD_EXIT_PARK_MODE = 0x0806; + CMD_QOS_SETUP = 0x0807; + CMD_ROLE_DISCOVERY = 0x0809; + CMD_SWITCH_ROLE = 0x080B; + CMD_READ_POLICY_SETTINGS = 0x080C; + CMD_WRITE_POLICY_SETTINGS = 0x080D; + CMD_READ_DEF_POLICY_SETTINGS = 0x080E; + CMD_WRITE_DEF_POLICY_SETTINGS = 0x080F; + CMD_FLOW_SPECIFICATION = 0x0810; + CMD_SNIFF_SUB_RATE = 0x0811; + // Host controller baseband commands 0x0C00 + CMD_SET_EVENT_MASK = 0x0C01; + CMD_RESET = 0x0C03; + CMD_SET_EVENT_FILTER = 0x0C05; + CMD_FLUSH = 0x0C08; + CMD_READ_PIN_TYPE = 0x0C09; + CMD_WRITE_PIN_TYPE = 0x0C0A; + CMD_CREATE_NEW_UNIT_KEY = 0x0C0B; + CMD_GET_MWS_TRANS_LAYER_CFG = 0x0C0C; // Deprecated (not used in spec) + CMD_READ_STORED_LINK_KEY = 0x0C0D; + CMD_WRITE_STORED_LINK_KEY = 0x0C11; + CMD_DELETE_STORED_LINK_KEY = 0x0C12; + CMD_CHANGE_LOCAL_NAME = 0x0C13; + CMD_READ_LOCAL_NAME = 0x0C14; + CMD_READ_CONN_ACCEPT_TOUT = 0x0C15; + CMD_WRITE_CONN_ACCEPT_TOUT = 0x0C16; + CMD_READ_PAGE_TOUT = 0x0C17; + CMD_WRITE_PAGE_TOUT = 0x0C18; + CMD_READ_SCAN_ENABLE = 0x0C19; + CMD_WRITE_SCAN_ENABLE = 0x0C1A; + CMD_READ_PAGESCAN_CFG = 0x0C1B; + CMD_WRITE_PAGESCAN_CFG = 0x0C1C; + CMD_READ_INQUIRYSCAN_CFG = 0x0C1D; + CMD_WRITE_INQUIRYSCAN_CFG = 0x0C1E; + CMD_READ_AUTHENTICATION_ENABLE = 0x0C1F; + CMD_WRITE_AUTHENTICATION_ENABLE = 0x0C20; + CMD_READ_ENCRYPTION_MODE = 0x0C21; // Deprecated + CMD_WRITE_ENCRYPTION_MODE = 0x0C22; // Deprecated + CMD_READ_CLASS_OF_DEVICE = 0x0C23; + CMD_WRITE_CLASS_OF_DEVICE = 0x0C24; + CMD_READ_VOICE_SETTINGS = 0x0C25; + CMD_WRITE_VOICE_SETTINGS = 0x0C26; + CMD_READ_AUTOMATIC_FLUSH_TIMEOUT = 0x0C27; + CMD_WRITE_AUTOMATIC_FLUSH_TIMEOUT = 0x0C28; + CMD_READ_NUM_BCAST_REXMITS = 0x0C29; + CMD_WRITE_NUM_BCAST_REXMITS = 0x0C2A; + CMD_READ_HOLD_MODE_ACTIVITY = 0x0C2B; + CMD_WRITE_HOLD_MODE_ACTIVITY = 0x0C2C; + CMD_READ_TRANSMIT_POWER_LEVEL = 0x0C2D; + CMD_READ_SCO_FLOW_CTRL_ENABLE = 0x0C2E; + CMD_WRITE_SCO_FLOW_CTRL_ENABLE = 0x0C2F; + CMD_SET_HC_TO_HOST_FLOW_CTRL = 0x0C31; + CMD_HOST_BUFFER_SIZE = 0x0C33; + CMD_HOST_NUM_PACKETS_DONE = 0x0C35; + CMD_READ_LINK_SUPER_TOUT = 0x0C36; + CMD_WRITE_LINK_SUPER_TOUT = 0x0C37; + CMD_READ_NUM_SUPPORTED_IAC = 0x0C38; + CMD_READ_CURRENT_IAC_LAP = 0x0C39; + CMD_WRITE_CURRENT_IAC_LAP = 0x0C3A; + CMD_READ_PAGESCAN_PERIOD_MODE = 0x0C3B; // Deprecated + CMD_WRITE_PAGESCAN_PERIOD_MODE = 0x0C3C; // Deprecated + CMD_READ_PAGESCAN_MODE = 0x0C3D; // Deprecated + CMD_WRITE_PAGESCAN_MODE = 0x0C3E; // Deprecated + CMD_SET_AFH_CHANNELS = 0x0C3F; + CMD_READ_INQSCAN_TYPE = 0x0C42; + CMD_WRITE_INQSCAN_TYPE = 0x0C43; + CMD_READ_INQUIRY_MODE = 0x0C44; + CMD_WRITE_INQUIRY_MODE = 0x0C45; + CMD_READ_PAGESCAN_TYPE = 0x0C46; + CMD_WRITE_PAGESCAN_TYPE = 0x0C47; + CMD_READ_AFH_ASSESSMENT_MODE = 0x0C48; + CMD_WRITE_AFH_ASSESSMENT_MODE = 0x0C49; + CMD_READ_EXT_INQ_RESPONSE = 0x0C51; + CMD_WRITE_EXT_INQ_RESPONSE = 0x0C52; + CMD_REFRESH_ENCRYPTION_KEY = 0x0C53; + CMD_READ_SIMPLE_PAIRING_MODE = 0x0C55; + CMD_WRITE_SIMPLE_PAIRING_MODE = 0x0C56; + CMD_READ_LOCAL_OOB_DATA = 0x0C57; + CMD_READ_INQ_TX_POWER_LEVEL = 0x0C58; + CMD_WRITE_INQ_TX_POWER_LEVEL = 0x0C59; + CMD_READ_ERRONEOUS_DATA_RPT = 0x0C5A; + CMD_WRITE_ERRONEOUS_DATA_RPT = 0x0C5B; + CMD_ENHANCED_FLUSH = 0x0C5F; + CMD_SEND_KEYPRESS_NOTIF = 0x0C60; + CMD_READ_LOGICAL_LINK_ACCEPT_TIMEOUT = 0x0C61; + CMD_WRITE_LOGICAL_LINK_ACCEPT_TIMEOUT = 0x0C62; + CMD_SET_EVENT_MASK_PAGE_2 = 0x0C63; + CMD_READ_LOCATION_DATA = 0x0C64; + CMD_WRITE_LOCATION_DATA = 0x0C65; + CMD_READ_FLOW_CONTROL_MODE = 0x0C66; + CMD_WRITE_FLOW_CONTROL_MODE = 0x0C67; + CMD_READ_ENHANCED_TX_PWR_LEVEL = 0x0C68; // Not currently used in system/bt + CMD_READ_BE_FLUSH_TOUT = 0x0C69; + CMD_WRITE_BE_FLUSH_TOUT = 0x0C6A; + CMD_SHORT_RANGE_MODE = 0x0C6B; + CMD_READ_BLE_HOST_SUPPORT = 0x0C6C; + CMD_WRITE_BLE_HOST_SUPPORT = 0x0C6D; + CMD_SET_MWS_CHANNEL_PARAMETERS = 0x0C6E; + CMD_SET_EXTERNAL_FRAME_CONFIGURATION = 0x0C6F; + CMD_SET_MWS_SIGNALING = 0x0C70; + CMD_SET_MWS_TRANSPORT_LAYER = 0x0C71; + CMD_SET_MWS_SCAN_FREQUENCY_TABLE = 0x0C72; + CMD_SET_MWS_PATTERN_CONFIGURATION = 0x0C73; + CMD_SET_RESERVED_LT_ADDR = 0x0C74; + CMD_DELETE_RESERVED_LT_ADDR = 0x0C75; + CMD_WRITE_CLB_DATA = 0x0C76; + CMD_READ_SYNC_TRAIN_PARAM = 0x0C77; + CMD_WRITE_SYNC_TRAIN_PARAM = 0x0C78; + CMD_READ_SECURE_CONNS_SUPPORT = 0x0C79; + CMD_WRITE_SECURE_CONNS_SUPPORT = 0x0C7A; + CMD_READ_AUTHED_PAYLOAD_TIMEOUT = 0x0C7B; // Not currently used in system/bt + CMD_WRITE_AUTHED_PAYLOAD_TIMEOUT = 0x0C7C; // Not currently used in system/bt + CMD_READ_LOCAL_OOB_EXTENDED_DATA = 0x0C7D; // Not currently used in system/bt + CMD_READ_EXTENDED_PAGE_TIMEOUT = 0x0C7E; // Not currently used in system/bt + CMD_WRITE_EXTENDED_PAGE_TIMEOUT = 0x0C7F; // Not currently used in system/bt + CMD_READ_EXTENDED_INQUIRY_LENGTH = 0x0C80; // Not currently used in system/bt + CMD_WRITE_EXTENDED_INQUIRY_LENGTH = 0x0C81; // Not currently used in system/bt + // Informational parameter commands 0x1000 + CMD_READ_LOCAL_VERSION_INFO = 0x1001; + CMD_READ_LOCAL_SUPPORTED_CMDS = 0x1002; + CMD_READ_LOCAL_FEATURES = 0x1003; + CMD_READ_LOCAL_EXT_FEATURES = 0x1004; + CMD_READ_BUFFER_SIZE = 0x1005; + CMD_READ_COUNTRY_CODE = 0x1007; // Deprecated + CMD_READ_BD_ADDR = 0x1009; + CMD_READ_DATA_BLOCK_SIZE = 0x100A; + CMD_READ_LOCAL_SUPPORTED_CODECS = 0x100B; + // Status parameter commands 0x1400 + CMD_READ_FAILED_CONTACT_COUNTER = 0x1401; + CMD_RESET_FAILED_CONTACT_COUNTER = 0x1402; + CMD_GET_LINK_QUALITY = 0x1403; + CMD_READ_RSSI = 0x1405; + CMD_READ_AFH_CH_MAP = 0x1406; + CMD_READ_CLOCK = 0x1407; + CMD_READ_ENCR_KEY_SIZE = 0x1408; + CMD_READ_LOCAL_AMP_INFO = 0x1409; + CMD_READ_LOCAL_AMP_ASSOC = 0x140A; + CMD_WRITE_REMOTE_AMP_ASSOC = 0x140B; + CMD_GET_MWS_TRANSPORT_CFG = 0x140C; // Not currently used in system/bt + CMD_SET_TRIGGERED_CLK_CAPTURE = 0x140D; // Not currently used in system/bt + // Testing commands 0x1800 + CMD_READ_LOOPBACK_MODE = 0x1801; + CMD_WRITE_LOOPBACK_MODE = 0x1802; + CMD_ENABLE_DEV_UNDER_TEST_MODE = 0x1803; + CMD_WRITE_SIMP_PAIR_DEBUG_MODE = 0x1804; + CMD_ENABLE_AMP_RCVR_REPORTS = 0x1807; + CMD_AMP_TEST_END = 0x1808; + CMD_AMP_TEST = 0x1809; + CMD_WRITE_SECURE_CONN_TEST_MODE = 0x180A; // Not currently used in system/bt + // BLE commands 0x2000 + CMD_BLE_SET_EVENT_MASK = 0x2001; + CMD_BLE_READ_BUFFER_SIZE = 0x2002; + CMD_BLE_READ_LOCAL_SPT_FEAT = 0x2003; + CMD_BLE_WRITE_LOCAL_SPT_FEAT = 0x2004; + CMD_BLE_WRITE_RANDOM_ADDR = 0x2005; + CMD_BLE_WRITE_ADV_PARAMS = 0x2006; + CMD_BLE_READ_ADV_CHNL_TX_POWER = 0x2007; + CMD_BLE_WRITE_ADV_DATA = 0x2008; + CMD_BLE_WRITE_SCAN_RSP_DATA = 0x2009; + CMD_BLE_WRITE_ADV_ENABLE = 0x200A; + CMD_BLE_WRITE_SCAN_PARAMS = 0x200B; + CMD_BLE_WRITE_SCAN_ENABLE = 0x200C; + CMD_BLE_CREATE_LL_CONN = 0x200D; + CMD_BLE_CREATE_CONN_CANCEL = 0x200E; + CMD_BLE_READ_WHITE_LIST_SIZE = 0x200F; + CMD_BLE_CLEAR_WHITE_LIST = 0x2010; + CMD_BLE_ADD_WHITE_LIST = 0x2011; + CMD_BLE_REMOVE_WHITE_LIST = 0x2012; + CMD_BLE_UPD_LL_CONN_PARAMS = 0x2013; + CMD_BLE_SET_HOST_CHNL_CLASS = 0x2014; + CMD_BLE_READ_CHNL_MAP = 0x2015; + CMD_BLE_READ_REMOTE_FEAT = 0x2016; + CMD_BLE_ENCRYPT = 0x2017; + CMD_BLE_RAND = 0x2018; + CMD_BLE_START_ENC = 0x2019; + CMD_BLE_LTK_REQ_REPLY = 0x201A; + CMD_BLE_LTK_REQ_NEG_REPLY = 0x201B; + CMD_BLE_READ_SUPPORTED_STATES = 0x201C; + CMD_BLE_RECEIVER_TEST = 0x201D; + CMD_BLE_TRANSMITTER_TEST = 0x201E; + CMD_BLE_TEST_END = 0x201F; + CMD_BLE_RC_PARAM_REQ_REPLY = 0x2020; + CMD_BLE_RC_PARAM_REQ_NEG_REPLY = 0x2021; + CMD_BLE_SET_DATA_LENGTH = 0x2022; + CMD_BLE_READ_DEFAULT_DATA_LENGTH = 0x2023; + CMD_BLE_WRITE_DEFAULT_DATA_LENGTH = 0x2024; + CMD_BLE_GENERATE_DHKEY = 0x2026; // Not currently used in system/bt + CMD_BLE_ADD_DEV_RESOLVING_LIST = 0x2027; + CMD_BLE_RM_DEV_RESOLVING_LIST = 0x2028; + CMD_BLE_CLEAR_RESOLVING_LIST = 0x2029; + CMD_BLE_READ_RESOLVING_LIST_SIZE = 0x202A; + CMD_BLE_READ_RESOLVABLE_ADDR_PEER = 0x202B; + CMD_BLE_READ_RESOLVABLE_ADDR_LOCAL = 0x202C; + CMD_BLE_SET_ADDR_RESOLUTION_ENABLE = 0x202D; + CMD_BLE_SET_RAND_PRIV_ADDR_TIMOUT = 0x202E; + CMD_BLE_READ_MAXIMUM_DATA_LENGTH = 0x202F; + CMD_BLE_READ_PHY = 0x2030; + CMD_BLE_SET_DEFAULT_PHY = 0x2031; + CMD_BLE_SET_PHY = 0x2032; + CMD_BLE_ENH_RECEIVER_TEST = 0x2033; + CMD_BLE_ENH_TRANSMITTER_TEST = 0x2034; + CMD_BLE_SET_EXT_ADVERTISING_RANDOM_ADDRESS = 0x2035; + CMD_BLE_SET_EXT_ADVERTISING_PARAM = 0x2036; + CMD_BLE_SET_EXT_ADVERTISING_DATA = 0x2037; + CMD_BLE_SET_EXT_ADVERTISING_SCAN_RESP = 0x2038; + CMD_BLE_SET_EXT_ADVERTISING_ENABLE = 0x2039; + CMD_BLE_READ_MAXIMUM_ADVERTISING_DATA_LENGTH = 0x203A; + CMD_BLE_READ_NUMBER_OF_SUPPORTED_ADVERTISING_SETS = 0x203B; + CMD_BLE_REMOVE_ADVERTISING_SET = 0x203C; + CMD_BLE_CLEAR_ADVERTISING_SETS = 0x203D; + CMD_BLE_SET_PERIODIC_ADVERTISING_PARAM = 0x203E; + CMD_BLE_SET_PERIODIC_ADVERTISING_DATA = 0x203F; + CMD_BLE_SET_PERIODIC_ADVERTISING_ENABLE = 0x2040; + CMD_BLE_SET_EXTENDED_SCAN_PARAMETERS = 0x2041; + CMD_BLE_SET_EXTENDED_SCAN_ENABLE = 0x2042; + CMD_BLE_EXTENDED_CREATE_CONNECTION = 0x2043; + CMD_BLE_PERIODIC_ADVERTISING_CREATE_SYNC = 0x2044; + CMD_BLE_PERIODIC_ADVERTISING_CREATE_SYNC_CANCEL = 0x2045; + CMD_BLE_PERIODIC_ADVERTISING_TERMINATE_SYNC = 0x2046; + CMD_BLE_ADD_DEVICE_TO_PERIODIC_ADVERTISING_LIST = 0x2047; + CMD_BLE_RM_DEVICE_FROM_PERIODIC_ADVERTISING_LIST = 0x2048; + CMD_BLE_CLEAR_PERIODIC_ADVERTISING_LIST = 0x2049; + CMD_BLE_READ_PERIODIC_ADVERTISING_LIST_SIZE = 0x204A; + CMD_BLE_READ_TRANSMIT_POWER = 0x204B; + CMD_BLE_READ_RF_COMPENS_POWER = 0x204C; + CMD_BLE_WRITE_RF_COMPENS_POWER = 0x204D; + CMD_BLE_SET_PRIVACY_MODE = 0x204E; + // Vendor specific commands 0xFC00 and above + // Android vendor specific commands defined in + // https://source.android.com/devices/bluetooth/hci_requirements#vendor-specific-capabilities + CMD_BLE_VENDOR_CAP = 0xFD53; + CMD_BLE_MULTI_ADV = 0xFD54; + CMD_BLE_BATCH_SCAN = 0xFD56; + CMD_BLE_ADV_FILTER = 0xFD57; + CMD_BLE_TRACK_ADV = 0xFD58; + CMD_BLE_ENERGY_INFO = 0xFD59; + CMD_BLE_EXTENDED_SCAN_PARAMS = 0xFD5A; + CMD_CONTROLLER_DEBUG_INFO = 0xFD5B; + CMD_CONTROLLER_A2DP_OPCODE = 0xFD5D; + CMD_BRCM_SET_ACL_PRIORITY = 0xFC57; + // Other vendor specific commands below here +} + +// HCI event codes from the Bluetooth 5.0 specification Vol 2, Part 7, Section 7 +// Original definition: system/bt/stack/include/hcidefs.h +enum EventEnum { + // Event is at most 1 byte (0xFF), thus 0xFFF must not be a valid value + EVT_UNKNOWN = 0xFFF; + EVT_INQUIRY_COMP = 0x01; + EVT_INQUIRY_RESULT = 0x02; + EVT_CONNECTION_COMP = 0x03; + EVT_CONNECTION_REQUEST = 0x04; + EVT_DISCONNECTION_COMP = 0x05; + EVT_AUTHENTICATION_COMP = 0x06; + EVT_RMT_NAME_REQUEST_COMP = 0x07; + EVT_ENCRYPTION_CHANGE = 0x08; + EVT_CHANGE_CONN_LINK_KEY = 0x09; + EVT_MASTER_LINK_KEY_COMP = 0x0A; + EVT_READ_RMT_FEATURES_COMP = 0x0B; + EVT_READ_RMT_VERSION_COMP = 0x0C; + EVT_QOS_SETUP_COMP = 0x0D; + EVT_COMMAND_COMPLETE = 0x0E; + EVT_COMMAND_STATUS = 0x0F; + EVT_HARDWARE_ERROR = 0x10; + EVT_FLUSH_OCCURED = 0x11; + EVT_ROLE_CHANGE = 0x12; + EVT_NUM_COMPL_DATA_PKTS = 0x13; + EVT_MODE_CHANGE = 0x14; + EVT_RETURN_LINK_KEYS = 0x15; + EVT_PIN_CODE_REQUEST = 0x16; + EVT_LINK_KEY_REQUEST = 0x17; + EVT_LINK_KEY_NOTIFICATION = 0x18; + EVT_LOOPBACK_COMMAND = 0x19; + EVT_DATA_BUF_OVERFLOW = 0x1A; + EVT_MAX_SLOTS_CHANGED = 0x1B; + EVT_READ_CLOCK_OFF_COMP = 0x1C; + EVT_CONN_PKT_TYPE_CHANGE = 0x1D; + EVT_QOS_VIOLATION = 0x1E; + EVT_PAGE_SCAN_MODE_CHANGE = 0x1F; // Deprecated + EVT_PAGE_SCAN_REP_MODE_CHNG = 0x20; + EVT_FLOW_SPECIFICATION_COMP = 0x21; + EVT_INQUIRY_RSSI_RESULT = 0x22; + EVT_READ_RMT_EXT_FEATURES_COMP = 0x23; + EVT_ESCO_CONNECTION_COMP = 0x2C; + EVT_ESCO_CONNECTION_CHANGED = 0x2D; + EVT_SNIFF_SUB_RATE = 0x2E; + EVT_EXTENDED_INQUIRY_RESULT = 0x2F; + EVT_ENCRYPTION_KEY_REFRESH_COMP = 0x30; + EVT_IO_CAPABILITY_REQUEST = 0x31; + EVT_IO_CAPABILITY_RESPONSE = 0x32; + EVT_USER_CONFIRMATION_REQUEST = 0x33; + EVT_USER_PASSKEY_REQUEST = 0x34; + EVT_REMOTE_OOB_DATA_REQUEST = 0x35; + EVT_SIMPLE_PAIRING_COMPLETE = 0x36; + EVT_LINK_SUPER_TOUT_CHANGED = 0x38; + EVT_ENHANCED_FLUSH_COMPLETE = 0x39; + EVT_USER_PASSKEY_NOTIFY = 0x3B; + EVT_KEYPRESS_NOTIFY = 0x3C; + EVT_RMT_HOST_SUP_FEAT_NOTIFY = 0x3D; + EVT_BLE_META = 0x3E; + EVT_PHYSICAL_LINK_COMP = 0x40; + EVT_CHANNEL_SELECTED = 0x41; + EVT_DISC_PHYSICAL_LINK_COMP = 0x42; + EVT_PHY_LINK_LOSS_EARLY_WARNING = 0x43; + EVT_PHY_LINK_RECOVERY = 0x44; + EVT_LOGICAL_LINK_COMP = 0x45; + EVT_DISC_LOGICAL_LINK_COMP = 0x46; + EVT_FLOW_SPEC_MODIFY_COMP = 0x47; + EVT_NUM_COMPL_DATA_BLOCKS = 0x48; + EVT_AMP_TEST_START = 0x49; // Not currently used in system/bt + EVT_AMP_TEST_END = 0x4A; // Not currently used in system/bt + EVT_AMP_RECEIVER_RPT = 0x4B; // Not currently used in system/bt + EVT_SHORT_RANGE_MODE_COMPLETE = 0x4C; + EVT_AMP_STATUS_CHANGE = 0x4D; + EVT_SET_TRIGGERED_CLOCK_CAPTURE = 0x4E; + EVT_SYNC_TRAIN_CMPL = 0x4F; // Not currently used in system/bt + EVT_SYNC_TRAIN_RCVD = 0x50; // Not currently used in system/bt + EVT_CONNLESS_SLAVE_BROADCAST_RCVD = 0x51; // Not currently used in system/bt + EVT_CONNLESS_SLAVE_BROADCAST_TIMEOUT = 0x52; // Not currently used in system/bt + EVT_TRUNCATED_PAGE_CMPL = 0x53; // Not currently used in system/bt + EVT_SLAVE_PAGE_RES_TIMEOUT = 0x54; // Not currently used in system/bt + EVT_CONNLESS_SLAVE_BROADCAST_CHNL_MAP_CHANGE = 0x55; // Not currently used in system/bt + EVT_INQUIRY_RES_NOTIFICATION = 0x56; // Not currently used in system/bt + EVT_AUTHED_PAYLOAD_TIMEOUT = 0x57; // Not currently used in system/bt + EVT_SAM_STATUS_CHANGE = 0x58; // Not currently used in system/bt +} + +// Bluetooth low energy related meta event codes +// from the Bluetooth 5.0 specification Vol 2, Part E, Section 7.7.65 +// Original definition: system/bt/stack/include/hcidefs.h +enum BleMetaEventEnum { + // BLE meta event code is at most 1 byte (0xFF), thus 0xFFF must not be a valid value + BLE_EVT_UNKNOWN = 0xFFF; + BLE_EVT_CONN_COMPLETE_EVT = 0x01; + BLE_EVT_ADV_PKT_RPT_EVT = 0x02; + BLE_EVT_LL_CONN_PARAM_UPD_EVT = 0x03; + BLE_EVT_READ_REMOTE_FEAT_CMPL_EVT = 0x04; + BLE_EVT_LTK_REQ_EVT = 0x05; + BLE_EVT_RC_PARAM_REQ_EVT = 0x06; + BLE_EVT_DATA_LENGTH_CHANGE_EVT = 0x07; + BLE_EVT_READ_LOCAL_P256_PUB_KEY = 0x08; // Not currently used in system/bt + BLE_EVT_GEN_DHKEY_CMPL = 0x09; // Not currently used in system/bt + BLE_EVT_ENHANCED_CONN_COMPLETE_EVT = 0x0a; + BLE_EVT_DIRECT_ADV_EVT = 0x0b; + BLE_EVT_PHY_UPDATE_COMPLETE_EVT = 0x0c; + BLE_EVT_EXTENDED_ADVERTISING_REPORT_EVT = 0x0D; + BLE_EVT_PERIODIC_ADV_SYNC_EST_EVT = 0x0E; + BLE_EVT_PERIODIC_ADV_REPORT_EVT = 0x0F; + BLE_EVT_PERIODIC_ADV_SYNC_LOST_EVT = 0x10; + BLE_EVT_SCAN_TIMEOUT_EVT = 0x11; + BLE_EVT_ADVERTISING_SET_TERMINATED_EVT = 0x12; + BLE_EVT_SCAN_REQ_RX_EVT = 0x13; + BLE_EVT_CHNL_SELECTION_ALGORITHM = 0x14; // Not currently used in system/bt +} + +// HCI status code from the Bluetooth 5.0 specification Vol 2, Part D. +// Original definition: system/bt/stack/include/hcidefs.h +enum StatusEnum { + // Status is at most 1 byte (0xFF), thus 0xFFF must not be a valid value + STATUS_UNKNOWN = 0xFFF; + STATUS_SUCCESS = 0x00; + STATUS_ILLEGAL_COMMAND = 0x01; + STATUS_NO_CONNECTION = 0x02; + STATUS_HW_FAILURE = 0x03; + STATUS_PAGE_TIMEOUT = 0x04; + STATUS_AUTH_FAILURE = 0x05; + STATUS_KEY_MISSING = 0x06; + STATUS_MEMORY_FULL = 0x07; + STATUS_CONNECTION_TOUT = 0x08; + STATUS_MAX_NUM_OF_CONNECTIONS = 0x09; + STATUS_MAX_NUM_OF_SCOS = 0x0A; + STATUS_CONNECTION_EXISTS = 0x0B; + STATUS_COMMAND_DISALLOWED = 0x0C; + STATUS_HOST_REJECT_RESOURCES = 0x0D; + STATUS_HOST_REJECT_SECURITY = 0x0E; + STATUS_HOST_REJECT_DEVICE = 0x0F; + STATUS_HOST_TIMEOUT = 0x10; + STATUS_UNSUPPORTED_VALUE = 0x11; + STATUS_ILLEGAL_PARAMETER_FMT = 0x12; + STATUS_PEER_USER = 0x13; + STATUS_PEER_LOW_RESOURCES = 0x14; + STATUS_PEER_POWER_OFF = 0x15; + STATUS_CONN_CAUSE_LOCAL_HOST = 0x16; + STATUS_REPEATED_ATTEMPTS = 0x17; + STATUS_PAIRING_NOT_ALLOWED = 0x18; + STATUS_UNKNOWN_LMP_PDU = 0x19; + STATUS_UNSUPPORTED_REM_FEATURE = 0x1A; + STATUS_SCO_OFFSET_REJECTED = 0x1B; + STATUS_SCO_INTERVAL_REJECTED = 0x1C; + STATUS_SCO_AIR_MODE = 0x1D; + STATUS_INVALID_LMP_PARAM = 0x1E; + STATUS_UNSPECIFIED = 0x1F; + STATUS_UNSUPPORTED_LMP_FEATURE = 0x20; + STATUS_ROLE_CHANGE_NOT_ALLOWED = 0x21; + STATUS_LMP_RESPONSE_TIMEOUT = 0x22; + STATUS_LMP_STATUS_TRANS_COLLISION = 0x23; + STATUS_LMP_PDU_NOT_ALLOWED = 0x24; + STATUS_ENCRY_MODE_NOT_ACCEPTABLE = 0x25; + STATUS_UNIT_KEY_USED = 0x26; + STATUS_QOS_NOT_SUPPORTED = 0x27; + STATUS_INSTANT_PASSED = 0x28; + STATUS_PAIRING_WITH_UNIT_KEY_NOT_SUPPORTED = 0x29; + STATUS_DIFF_TRANSACTION_COLLISION = 0x2A; + STATUS_UNDEFINED_0x2B = 0x2B; // Not used + STATUS_QOS_UNACCEPTABLE_PARAM = 0x2C; + STATUS_QOS_REJECTED = 0x2D; + STATUS_CHAN_CLASSIF_NOT_SUPPORTED = 0x2E; + STATUS_INSUFFCIENT_SECURITY = 0x2F; + STATUS_PARAM_OUT_OF_RANGE = 0x30; + STATUS_UNDEFINED_0x31 = 0x31; // Not used + STATUS_ROLE_SWITCH_PENDING = 0x32; + STATUS_UNDEFINED_0x33 = 0x33; + STATUS_RESERVED_SLOT_VIOLATION = 0x34; + STATUS_ROLE_SWITCH_FAILED = 0x35; + STATUS_INQ_RSP_DATA_TOO_LARGE = 0x36; + STATUS_SIMPLE_PAIRING_NOT_SUPPORTED = 0x37; + STATUS_HOST_BUSY_PAIRING = 0x38; + STATUS_REJ_NO_SUITABLE_CHANNEL = 0x39; + STATUS_CONTROLLER_BUSY = 0x3A; + STATUS_UNACCEPT_CONN_INTERVAL = 0x3B; + STATUS_ADVERTISING_TIMEOUT = 0x3C; + STATUS_CONN_TOUT_DUE_TO_MIC_FAILURE = 0x3D; + STATUS_CONN_FAILED_ESTABLISHMENT = 0x3E; + STATUS_MAC_CONNECTION_FAILED = 0x3F; + STATUS_LT_ADDR_ALREADY_IN_USE = 0x40; + STATUS_LT_ADDR_NOT_ALLOCATED = 0x41; + STATUS_CLB_NOT_ENABLED = 0x42; + STATUS_CLB_DATA_TOO_BIG = 0x43; + STATUS_OPERATION_CANCELED_BY_HOST = 0x44; // Not currently used in system/bt +}