Loading system/common/metrics.cc +22 −0 Original line number Diff line number Diff line Loading @@ -735,6 +735,28 @@ void LogReadTxPowerLevelResult(const RawAddress& address, uint16_t handle, } } void LogSmpPairingEvent(const RawAddress& address, uint8_t smp_cmd, android::bluetooth::DirectionEnum direction, uint8_t smp_fail_reason) { std::string obfuscated_id; if (!address.IsEmpty()) { obfuscated_id = AddressObfuscator::GetInstance()->Obfuscate(address); } // nullptr and size 0 represent missing value for obfuscated_id android::util::BytesField obfuscated_id_field( address.IsEmpty() ? nullptr : obfuscated_id.c_str(), address.IsEmpty() ? 0 : obfuscated_id.size()); int ret = android::util::stats_write( android::util::BLUETOOTH_SMP_PAIRING_EVENT_REPORTED, obfuscated_id_field, smp_cmd, direction, smp_fail_reason); if (ret < 0) { LOG(WARNING) << __func__ << ": failed for " << address << ", smp_cmd " << loghex(smp_cmd) << ", direction " << direction << ", smp_fail_reason " << loghex(smp_fail_reason) << ", error " << ret; } } } // namespace common } // namespace bluetooth system/common/metrics.h +11 −0 Original line number Diff line number Diff line Loading @@ -399,6 +399,17 @@ void LogReadTxPowerLevelResult(const RawAddress& address, uint16_t handle, uint32_t cmd_status, int32_t transmit_power_level); /** * Logs when there is an event related to Bluetooth Security Manager Protocol * * @param address address of associated device * @param smp_cmd SMP command code associated with this event * @param direction direction of this SMP command * @param smp_fail_reason SMP pairing failure reason code from SMP spec */ void LogSmpPairingEvent(const RawAddress& address, uint8_t smp_cmd, android::bluetooth::DirectionEnum direction, uint8_t smp_fail_reason); } // namespace common } // namespace bluetooth system/stack/smp/smp_int.h +2 −0 Original line number Diff line number Diff line Loading @@ -440,6 +440,8 @@ extern void smp_l2cap_if_init(void); extern void smp_data_ind(const RawAddress& bd_addr, BT_HDR* p_buf); /* smp_util.cc */ extern void smp_log_metrics(const RawAddress& bd_addr, bool is_outgoing, const uint8_t* p_buf, size_t buf_len); extern bool smp_send_cmd(uint8_t cmd_code, tSMP_CB* p_cb); extern void smp_cb_cleanup(tSMP_CB* p_cb); extern void smp_reset_control_value(tSMP_CB* p_cb); Loading system/stack/smp/smp_l2c.cc +7 −0 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ #include <string.h> #include "btm_ble_api.h" #include "common/metrics.h" #include "l2c_api.h" #include "smp_int.h" Loading Loading @@ -172,6 +173,9 @@ static void smp_data_received(uint16_t channel, const RawAddress& bd_addr, alarm_set_on_mloop(p_cb->smp_rsp_timer_ent, SMP_WAIT_FOR_RSP_TIMEOUT_MS, smp_rsp_timeout, NULL); smp_log_metrics(p_cb->pairing_bda, false /* incoming */, p_buf->data + p_buf->offset, p_buf->len); if (cmd == SMP_OPCODE_CONFIRM) { SMP_TRACE_DEBUG( "in %s cmd = 0x%02x, peer_auth_req = 0x%02x," Loading Loading @@ -310,6 +314,9 @@ static void smp_br_data_received(uint16_t channel, const RawAddress& bd_addr, alarm_set_on_mloop(p_cb->smp_rsp_timer_ent, SMP_WAIT_FOR_RSP_TIMEOUT_MS, smp_rsp_timeout, NULL); smp_log_metrics(p_cb->pairing_bda, false /* incoming */, p_buf->data + p_buf->offset, p_buf->len); p_cb->rcvd_cmd_code = cmd; p_cb->rcvd_cmd_len = (uint8_t)p_buf->len; tSMP_INT_DATA smp_int_data; Loading system/stack/smp/smp_utils.cc +32 −0 Original line number Diff line number Diff line Loading @@ -29,6 +29,7 @@ #include "bt_utils.h" #include "btm_ble_api.h" #include "btm_int.h" #include "common/metrics.h" #include "device/include/controller.h" #include "hcidefs.h" #include "l2c_api.h" Loading Loading @@ -295,6 +296,34 @@ static tSMP_ASSO_MODEL smp_select_legacy_association_model(tSMP_CB* p_cb); static tSMP_ASSO_MODEL smp_select_association_model_secure_connections( tSMP_CB* p_cb); /** * Log metrics data for SMP command * * @param bd_addr current pairing address * @param is_outgoing whether this command is outgoing * @param p_buf buffer to the beginning of SMP command * @param buf_len length available to read for p_buf */ void smp_log_metrics(const RawAddress& bd_addr, bool is_outgoing, const uint8_t* p_buf, size_t buf_len) { if (buf_len < 1) { LOG(WARNING) << __func__ << ": buffer is too small, size is " << buf_len; return; } uint8_t cmd; STREAM_TO_UINT8(cmd, p_buf); buf_len--; uint8_t failure_reason = 0; if (cmd == SMP_OPCODE_PAIRING_FAILED && buf_len >= 1) { STREAM_TO_UINT8(failure_reason, p_buf); } android::bluetooth::DirectionEnum direction = is_outgoing ? android::bluetooth::DirectionEnum::DIRECTION_OUTGOING : android::bluetooth::DirectionEnum::DIRECTION_INCOMING; bluetooth::common::LogSmpPairingEvent(bd_addr, cmd, direction, failure_reason); } /******************************************************************************* * * Function smp_send_msg_to_L2CAP Loading @@ -313,6 +342,9 @@ bool smp_send_msg_to_L2CAP(const RawAddress& rem_bda, BT_HDR* p_toL2CAP) { SMP_TRACE_EVENT("%s", __func__); smp_cb.total_tx_unacked += 1; smp_log_metrics(rem_bda, true /* outgoing */, p_toL2CAP->data + p_toL2CAP->offset, p_toL2CAP->len); l2cap_ret = L2CA_SendFixedChnlData(fixed_cid, rem_bda, p_toL2CAP); if (l2cap_ret == L2CAP_DW_FAILED) { smp_cb.total_tx_unacked -= 1; Loading Loading
system/common/metrics.cc +22 −0 Original line number Diff line number Diff line Loading @@ -735,6 +735,28 @@ void LogReadTxPowerLevelResult(const RawAddress& address, uint16_t handle, } } void LogSmpPairingEvent(const RawAddress& address, uint8_t smp_cmd, android::bluetooth::DirectionEnum direction, uint8_t smp_fail_reason) { std::string obfuscated_id; if (!address.IsEmpty()) { obfuscated_id = AddressObfuscator::GetInstance()->Obfuscate(address); } // nullptr and size 0 represent missing value for obfuscated_id android::util::BytesField obfuscated_id_field( address.IsEmpty() ? nullptr : obfuscated_id.c_str(), address.IsEmpty() ? 0 : obfuscated_id.size()); int ret = android::util::stats_write( android::util::BLUETOOTH_SMP_PAIRING_EVENT_REPORTED, obfuscated_id_field, smp_cmd, direction, smp_fail_reason); if (ret < 0) { LOG(WARNING) << __func__ << ": failed for " << address << ", smp_cmd " << loghex(smp_cmd) << ", direction " << direction << ", smp_fail_reason " << loghex(smp_fail_reason) << ", error " << ret; } } } // namespace common } // namespace bluetooth
system/common/metrics.h +11 −0 Original line number Diff line number Diff line Loading @@ -399,6 +399,17 @@ void LogReadTxPowerLevelResult(const RawAddress& address, uint16_t handle, uint32_t cmd_status, int32_t transmit_power_level); /** * Logs when there is an event related to Bluetooth Security Manager Protocol * * @param address address of associated device * @param smp_cmd SMP command code associated with this event * @param direction direction of this SMP command * @param smp_fail_reason SMP pairing failure reason code from SMP spec */ void LogSmpPairingEvent(const RawAddress& address, uint8_t smp_cmd, android::bluetooth::DirectionEnum direction, uint8_t smp_fail_reason); } // namespace common } // namespace bluetooth
system/stack/smp/smp_int.h +2 −0 Original line number Diff line number Diff line Loading @@ -440,6 +440,8 @@ extern void smp_l2cap_if_init(void); extern void smp_data_ind(const RawAddress& bd_addr, BT_HDR* p_buf); /* smp_util.cc */ extern void smp_log_metrics(const RawAddress& bd_addr, bool is_outgoing, const uint8_t* p_buf, size_t buf_len); extern bool smp_send_cmd(uint8_t cmd_code, tSMP_CB* p_cb); extern void smp_cb_cleanup(tSMP_CB* p_cb); extern void smp_reset_control_value(tSMP_CB* p_cb); Loading
system/stack/smp/smp_l2c.cc +7 −0 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ #include <string.h> #include "btm_ble_api.h" #include "common/metrics.h" #include "l2c_api.h" #include "smp_int.h" Loading Loading @@ -172,6 +173,9 @@ static void smp_data_received(uint16_t channel, const RawAddress& bd_addr, alarm_set_on_mloop(p_cb->smp_rsp_timer_ent, SMP_WAIT_FOR_RSP_TIMEOUT_MS, smp_rsp_timeout, NULL); smp_log_metrics(p_cb->pairing_bda, false /* incoming */, p_buf->data + p_buf->offset, p_buf->len); if (cmd == SMP_OPCODE_CONFIRM) { SMP_TRACE_DEBUG( "in %s cmd = 0x%02x, peer_auth_req = 0x%02x," Loading Loading @@ -310,6 +314,9 @@ static void smp_br_data_received(uint16_t channel, const RawAddress& bd_addr, alarm_set_on_mloop(p_cb->smp_rsp_timer_ent, SMP_WAIT_FOR_RSP_TIMEOUT_MS, smp_rsp_timeout, NULL); smp_log_metrics(p_cb->pairing_bda, false /* incoming */, p_buf->data + p_buf->offset, p_buf->len); p_cb->rcvd_cmd_code = cmd; p_cb->rcvd_cmd_len = (uint8_t)p_buf->len; tSMP_INT_DATA smp_int_data; Loading
system/stack/smp/smp_utils.cc +32 −0 Original line number Diff line number Diff line Loading @@ -29,6 +29,7 @@ #include "bt_utils.h" #include "btm_ble_api.h" #include "btm_int.h" #include "common/metrics.h" #include "device/include/controller.h" #include "hcidefs.h" #include "l2c_api.h" Loading Loading @@ -295,6 +296,34 @@ static tSMP_ASSO_MODEL smp_select_legacy_association_model(tSMP_CB* p_cb); static tSMP_ASSO_MODEL smp_select_association_model_secure_connections( tSMP_CB* p_cb); /** * Log metrics data for SMP command * * @param bd_addr current pairing address * @param is_outgoing whether this command is outgoing * @param p_buf buffer to the beginning of SMP command * @param buf_len length available to read for p_buf */ void smp_log_metrics(const RawAddress& bd_addr, bool is_outgoing, const uint8_t* p_buf, size_t buf_len) { if (buf_len < 1) { LOG(WARNING) << __func__ << ": buffer is too small, size is " << buf_len; return; } uint8_t cmd; STREAM_TO_UINT8(cmd, p_buf); buf_len--; uint8_t failure_reason = 0; if (cmd == SMP_OPCODE_PAIRING_FAILED && buf_len >= 1) { STREAM_TO_UINT8(failure_reason, p_buf); } android::bluetooth::DirectionEnum direction = is_outgoing ? android::bluetooth::DirectionEnum::DIRECTION_OUTGOING : android::bluetooth::DirectionEnum::DIRECTION_INCOMING; bluetooth::common::LogSmpPairingEvent(bd_addr, cmd, direction, failure_reason); } /******************************************************************************* * * Function smp_send_msg_to_L2CAP Loading @@ -313,6 +342,9 @@ bool smp_send_msg_to_L2CAP(const RawAddress& rem_bda, BT_HDR* p_toL2CAP) { SMP_TRACE_EVENT("%s", __func__); smp_cb.total_tx_unacked += 1; smp_log_metrics(rem_bda, true /* outgoing */, p_toL2CAP->data + p_toL2CAP->offset, p_toL2CAP->len); l2cap_ret = L2CA_SendFixedChnlData(fixed_cid, rem_bda, p_toL2CAP); if (l2cap_ret == L2CAP_DW_FAILED) { smp_cb.total_tx_unacked -= 1; Loading