Loading system/stack/btm/btm_ble_sec.cc +8 −8 Original line number Original line Diff line number Diff line Loading @@ -30,7 +30,6 @@ #include "btif/include/btif_storage.h" #include "btif/include/btif_storage.h" #include "crypto_toolbox/crypto_toolbox.h" #include "crypto_toolbox/crypto_toolbox.h" #include "device/include/interop.h" #include "device/include/interop.h" #include "device/include/interop_config.h" #include "hci/controller_interface.h" #include "hci/controller_interface.h" #include "main/shim/entry.h" #include "main/shim/entry.h" #include "osi/include/allocator.h" #include "osi/include/allocator.h" Loading Loading @@ -1068,7 +1067,7 @@ void btm_ble_link_sec_check(const RawAddress& bd_addr, } } if (p_dev_rec->sec_rec.is_security_state_encrypting() || if (p_dev_rec->sec_rec.is_security_state_encrypting() || p_dev_rec->sec_rec.sec_state == BTM_SEC_STATE_AUTHENTICATING) { p_dev_rec->sec_rec.sec_state == tSECURITY_STATE::BTM_SEC_STATE_AUTHENTICATING) { /* race condition: discard the security request while central is encrypting /* race condition: discard the security request while central is encrypting * the link */ * the link */ *p_sec_req_act = BTM_BLE_SEC_REQ_ACT_DISCARD; *p_sec_req_act = BTM_BLE_SEC_REQ_ACT_DISCARD; Loading Loading @@ -1172,7 +1171,7 @@ tBTM_STATUS btm_ble_set_encryption(const RawAddress& bd_addr, if (SMP_Pair(bd_addr) == SMP_STARTED) { if (SMP_Pair(bd_addr) == SMP_STARTED) { cmd = BTM_CMD_STARTED; cmd = BTM_CMD_STARTED; p_rec->sec_rec.sec_state = BTM_SEC_STATE_AUTHENTICATING; p_rec->sec_rec.sec_state = tSECURITY_STATE::BTM_SEC_STATE_AUTHENTICATING; } } break; break; Loading Loading @@ -1253,8 +1252,9 @@ tBTM_STATUS btm_ble_start_encrypt(const RawAddress& bda, bool use_stk, return BTM_ERR_KEY_MISSING; return BTM_ERR_KEY_MISSING; } } if (p_rec->sec_rec.sec_state == BTM_SEC_STATE_IDLE) if (p_rec->sec_rec.sec_state == tSECURITY_STATE::BTM_SEC_STATE_IDLE) { p_rec->sec_rec.sec_state = BTM_SEC_STATE_LE_ENCRYPTING; p_rec->sec_rec.sec_state = tSECURITY_STATE::BTM_SEC_STATE_LE_ENCRYPTING; } return BTM_CMD_STARTED; return BTM_CMD_STARTED; } } Loading Loading @@ -1324,7 +1324,7 @@ void btm_ble_link_encrypted(const RawAddress& bd_addr, uint8_t encr_enable) { if (encr_enable && p_dev_rec->sec_rec.enc_key_size == 0) if (encr_enable && p_dev_rec->sec_rec.enc_key_size == 0) p_dev_rec->sec_rec.enc_key_size = p_dev_rec->sec_rec.ble_keys.key_size; p_dev_rec->sec_rec.enc_key_size = p_dev_rec->sec_rec.ble_keys.key_size; p_dev_rec->sec_rec.sec_state = BTM_SEC_STATE_IDLE; p_dev_rec->sec_rec.sec_state = tSECURITY_STATE::BTM_SEC_STATE_IDLE; if (p_dev_rec->sec_rec.p_callback && enc_cback) { if (p_dev_rec->sec_rec.p_callback && enc_cback) { if (encr_enable) btm_sec_dev_rec_cback_event(p_dev_rec, BTM_SUCCESS, true); if (encr_enable) btm_sec_dev_rec_cback_event(p_dev_rec, BTM_SUCCESS, true); /* LTK missing on peripheral */ /* LTK missing on peripheral */ Loading Loading @@ -1594,7 +1594,7 @@ tBTM_STATUS btm_proc_smp_cback(tSMP_EVT event, const RawAddress& bd_addr, } } btm_sec_cb.pairing_bda = bd_addr; btm_sec_cb.pairing_bda = bd_addr; if (event != SMP_CONSENT_REQ_EVT) { if (event != SMP_CONSENT_REQ_EVT) { p_dev_rec->sec_rec.sec_state = BTM_SEC_STATE_AUTHENTICATING; p_dev_rec->sec_rec.sec_state = tSECURITY_STATE::BTM_SEC_STATE_AUTHENTICATING; } } btm_sec_cb.pairing_flags |= BTM_PAIR_FLAGS_LE_ACTIVE; btm_sec_cb.pairing_flags |= BTM_PAIR_FLAGS_LE_ACTIVE; FALLTHROUGH_INTENDED; /* FALLTHROUGH */ FALLTHROUGH_INTENDED; /* FALLTHROUGH */ Loading Loading @@ -1651,7 +1651,7 @@ tBTM_STATUS btm_proc_smp_cback(tSMP_EVT event, const RawAddress& bd_addr, } } if (res == BTM_SUCCESS) { if (res == BTM_SUCCESS) { p_dev_rec->sec_rec.sec_state = BTM_SEC_STATE_IDLE; p_dev_rec->sec_rec.sec_state = tSECURITY_STATE::BTM_SEC_STATE_IDLE; if (p_dev_rec->sec_rec.bond_type != BOND_TYPE_TEMPORARY) { if (p_dev_rec->sec_rec.bond_type != BOND_TYPE_TEMPORARY) { // Add all bonded device into resolving list if IRK is available. // Add all bonded device into resolving list if IRK is available. Loading system/stack/btm/btm_dev.cc +1 −1 Original line number Original line Diff line number Diff line Loading @@ -214,7 +214,7 @@ void BTM_SecClearSecurityFlags(const RawAddress& bd_addr) { if (p_dev_rec == NULL) return; if (p_dev_rec == NULL) return; p_dev_rec->sec_rec.sec_flags = 0; p_dev_rec->sec_rec.sec_flags = 0; p_dev_rec->sec_rec.sec_state = BTM_SEC_STATE_IDLE; p_dev_rec->sec_rec.sec_state = tSECURITY_STATE::BTM_SEC_STATE_IDLE; p_dev_rec->sm4 = BTM_SM4_UNKNOWN; p_dev_rec->sm4 = BTM_SM4_UNKNOWN; } } Loading system/stack/btm/btm_devctl.cc +1 −1 Original line number Original line Diff line number Diff line Loading @@ -161,7 +161,7 @@ void BTM_db_reset(void) { static bool set_sec_state_idle(void* data, void* /* context */) { static bool set_sec_state_idle(void* data, void* /* context */) { tBTM_SEC_DEV_REC* p_dev_rec = static_cast<tBTM_SEC_DEV_REC*>(data); tBTM_SEC_DEV_REC* p_dev_rec = static_cast<tBTM_SEC_DEV_REC*>(data); p_dev_rec->sec_rec.sec_state = BTM_SEC_STATE_IDLE; p_dev_rec->sec_rec.sec_state = tSECURITY_STATE::BTM_SEC_STATE_IDLE; return true; return true; } } Loading system/stack/btm/btm_sec.cc +62 −56 Original line number Original line Diff line number Diff line Loading @@ -766,7 +766,7 @@ tBTM_STATUS btm_sec_bond_by_transport(const RawAddress& bd_addr, if (SMP_Pair(bd_addr, addr_type) == SMP_STARTED) { if (SMP_Pair(bd_addr, addr_type) == SMP_STARTED) { btm_sec_cb.pairing_flags |= BTM_PAIR_FLAGS_LE_ACTIVE; btm_sec_cb.pairing_flags |= BTM_PAIR_FLAGS_LE_ACTIVE; p_dev_rec->sec_rec.sec_state = BTM_SEC_STATE_AUTHENTICATING; p_dev_rec->sec_rec.sec_state = tSECURITY_STATE::BTM_SEC_STATE_AUTHENTICATING; btm_sec_cb.change_pairing_state(BTM_PAIR_STATE_WAIT_AUTH_COMPLETE); btm_sec_cb.change_pairing_state(BTM_PAIR_STATE_WAIT_AUTH_COMPLETE); return BTM_CMD_STARTED; return BTM_CMD_STARTED; } } Loading Loading @@ -918,7 +918,7 @@ tBTM_STATUS BTM_SecBondCancel(const RawAddress& bd_addr) { } } if (btm_sec_cb.pairing_flags & BTM_PAIR_FLAGS_LE_ACTIVE) { if (btm_sec_cb.pairing_flags & BTM_PAIR_FLAGS_LE_ACTIVE) { if (p_dev_rec->sec_rec.sec_state == BTM_SEC_STATE_AUTHENTICATING) { if (p_dev_rec->sec_rec.sec_state == tSECURITY_STATE::BTM_SEC_STATE_AUTHENTICATING) { log::verbose("Cancel LE pairing"); log::verbose("Cancel LE pairing"); if (SMP_PairCancel(bd_addr)) { if (SMP_PairCancel(bd_addr)) { return BTM_CMD_STARTED; return BTM_CMD_STARTED; Loading @@ -942,9 +942,10 @@ tBTM_STATUS BTM_SecBondCancel(const RawAddress& bd_addr) { /* If the HCI link is up */ /* If the HCI link is up */ if (p_dev_rec->hci_handle != HCI_INVALID_HANDLE) { if (p_dev_rec->hci_handle != HCI_INVALID_HANDLE) { /* If some other thread disconnecting, we do not send second command */ /* If some other thread disconnecting, we do not send second command */ if ((p_dev_rec->sec_rec.sec_state == BTM_SEC_STATE_DISCONNECTING) || if ((p_dev_rec->sec_rec.sec_state == tSECURITY_STATE::BTM_SEC_STATE_DISCONNECTING) || (p_dev_rec->sec_rec.sec_state == BTM_SEC_STATE_DISCONNECTING_BOTH)) (p_dev_rec->sec_rec.sec_state == tSECURITY_STATE::BTM_SEC_STATE_DISCONNECTING_BOTH)) { return (BTM_CMD_STARTED); return (BTM_CMD_STARTED); } /* If the HCI link was set up by Bonding process */ /* If the HCI link was set up by Bonding process */ if (btm_sec_cb.pairing_flags & BTM_PAIR_FLAGS_DISC_WHEN_DONE) if (btm_sec_cb.pairing_flags & BTM_PAIR_FLAGS_DISC_WHEN_DONE) Loading Loading @@ -1101,21 +1102,21 @@ tBTM_STATUS BTM_SetEncryption(const RawAddress& bd_addr, if (bluetooth::common::init_flags::encryption_in_busy_state_is_enabled()) { if (bluetooth::common::init_flags::encryption_in_busy_state_is_enabled()) { bool enqueue = false; bool enqueue = false; switch (p_dev_rec->sec_rec.sec_state) { switch (p_dev_rec->sec_rec.sec_state) { case BTM_SEC_STATE_AUTHENTICATING: case tSECURITY_STATE::BTM_SEC_STATE_AUTHENTICATING: case BTM_SEC_STATE_DISCONNECTING_BOTH: case tSECURITY_STATE::BTM_SEC_STATE_DISCONNECTING_BOTH: /* Applicable for both transports */ /* Applicable for both transports */ enqueue = true; enqueue = true; break; break; case BTM_SEC_STATE_ENCRYPTING: case tSECURITY_STATE::BTM_SEC_STATE_ENCRYPTING: case BTM_SEC_STATE_DISCONNECTING: case tSECURITY_STATE::BTM_SEC_STATE_DISCONNECTING: if (transport == BT_TRANSPORT_BR_EDR) { if (transport == BT_TRANSPORT_BR_EDR) { enqueue = true; enqueue = true; } } break; break; case BTM_SEC_STATE_LE_ENCRYPTING: case tSECURITY_STATE::BTM_SEC_STATE_LE_ENCRYPTING: case BTM_SEC_STATE_DISCONNECTING_BLE: case tSECURITY_STATE::BTM_SEC_STATE_DISCONNECTING_BLE: if (transport == BT_TRANSPORT_LE) { if (transport == BT_TRANSPORT_LE) { enqueue = true; enqueue = true; } } Loading @@ -1137,7 +1138,7 @@ tBTM_STATUS BTM_SetEncryption(const RawAddress& bd_addr, } } } else { } else { if (p_dev_rec->sec_rec.p_callback || if (p_dev_rec->sec_rec.p_callback || (p_dev_rec->sec_rec.sec_state != BTM_SEC_STATE_IDLE)) { (p_dev_rec->sec_rec.sec_state != tSECURITY_STATE::BTM_SEC_STATE_IDLE)) { log::warn("Security Manager: BTM_SetEncryption busy, enqueue request"); log::warn("Security Manager: BTM_SetEncryption busy, enqueue request"); btm_sec_queue_encrypt_request(bd_addr, transport, p_callback, p_ref_data, btm_sec_queue_encrypt_request(bd_addr, transport, p_callback, p_ref_data, sec_act); sec_act); Loading Loading @@ -1204,7 +1205,7 @@ bool BTM_SecIsSecurityPending(const RawAddress& bd_addr) { tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(bd_addr); tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(bd_addr); return p_dev_rec && return p_dev_rec && (p_dev_rec->sec_rec.is_security_state_encrypting() || (p_dev_rec->sec_rec.is_security_state_encrypting() || p_dev_rec->sec_rec.sec_state == BTM_SEC_STATE_AUTHENTICATING); p_dev_rec->sec_rec.sec_state == tSECURITY_STATE::BTM_SEC_STATE_AUTHENTICATING); } } /******************************************************************************* /******************************************************************************* Loading @@ -1220,32 +1221,32 @@ static tBTM_STATUS btm_sec_send_hci_disconnect(tBTM_SEC_DEV_REC* p_dev_rec, /* send HCI_Disconnect on a transport only once */ /* send HCI_Disconnect on a transport only once */ switch (old_state) { switch (old_state) { case BTM_SEC_STATE_DISCONNECTING: case tSECURITY_STATE::BTM_SEC_STATE_DISCONNECTING: if (conn_handle == p_dev_rec->hci_handle) { if (conn_handle == p_dev_rec->hci_handle) { // Already sent classic disconnect // Already sent classic disconnect return status; return status; } } // Prepare to send disconnect on le transport // Prepare to send disconnect on le transport p_dev_rec->sec_rec.sec_state = BTM_SEC_STATE_DISCONNECTING_BOTH; p_dev_rec->sec_rec.sec_state = tSECURITY_STATE::BTM_SEC_STATE_DISCONNECTING_BOTH; break; break; case BTM_SEC_STATE_DISCONNECTING_BLE: case tSECURITY_STATE::BTM_SEC_STATE_DISCONNECTING_BLE: if (conn_handle == p_dev_rec->ble_hci_handle) { if (conn_handle == p_dev_rec->ble_hci_handle) { // Already sent ble disconnect // Already sent ble disconnect return status; return status; } } // Prepare to send disconnect on classic transport // Prepare to send disconnect on classic transport p_dev_rec->sec_rec.sec_state = BTM_SEC_STATE_DISCONNECTING_BOTH; p_dev_rec->sec_rec.sec_state = tSECURITY_STATE::BTM_SEC_STATE_DISCONNECTING_BOTH; break; break; case BTM_SEC_STATE_DISCONNECTING_BOTH: case tSECURITY_STATE::BTM_SEC_STATE_DISCONNECTING_BOTH: // Already sent disconnect on both transports // Already sent disconnect on both transports return status; return status; default: default: p_dev_rec->sec_rec.sec_state = (conn_handle == p_dev_rec->hci_handle) p_dev_rec->sec_rec.sec_state = (conn_handle == p_dev_rec->hci_handle) ? BTM_SEC_STATE_DISCONNECTING ? tSECURITY_STATE::BTM_SEC_STATE_DISCONNECTING : BTM_SEC_STATE_DISCONNECTING_BLE; : tSECURITY_STATE::BTM_SEC_STATE_DISCONNECTING_BLE; break; break; } } Loading Loading @@ -1723,7 +1724,7 @@ tBTM_STATUS btm_sec_l2cap_access_req_by_requirement( log::info( log::info( "peer should have initiated security process by now (SM4 to SM4)"); "peer should have initiated security process by now (SM4 to SM4)"); p_dev_rec->sec_rec.p_callback = p_callback; p_dev_rec->sec_rec.p_callback = p_callback; p_dev_rec->sec_rec.sec_state = BTM_SEC_STATE_DELAY_FOR_ENC; p_dev_rec->sec_rec.sec_state = tSECURITY_STATE::BTM_SEC_STATE_DELAY_FOR_ENC; (*p_callback)(bd_addr, transport, p_ref_data, rc); (*p_callback)(bd_addr, transport, p_ref_data, rc); return BTM_SUCCESS; return BTM_SUCCESS; Loading Loading @@ -1906,7 +1907,7 @@ tBTM_STATUS btm_sec_mx_access_request(const RawAddress& bd_addr, } } /* the new security request */ /* the new security request */ if (p_dev_rec->sec_rec.sec_state != BTM_SEC_STATE_IDLE) { if (p_dev_rec->sec_rec.sec_state != tSECURITY_STATE::BTM_SEC_STATE_IDLE) { log::debug("A pending security procedure in progress"); log::debug("A pending security procedure in progress"); rc = BTM_CMD_STARTED; rc = BTM_CMD_STARTED; } } Loading Loading @@ -2195,11 +2196,12 @@ void btm_sec_abort_access_req(const RawAddress& bd_addr) { if (!p_dev_rec) return; if (!p_dev_rec) return; if ((p_dev_rec->sec_rec.sec_state != BTM_SEC_STATE_AUTHORIZING) && if ((p_dev_rec->sec_rec.sec_state != tSECURITY_STATE::BTM_SEC_STATE_AUTHORIZING) && (p_dev_rec->sec_rec.sec_state != BTM_SEC_STATE_AUTHENTICATING)) (p_dev_rec->sec_rec.sec_state != tSECURITY_STATE::BTM_SEC_STATE_AUTHENTICATING)) { return; return; } p_dev_rec->sec_rec.sec_state = BTM_SEC_STATE_IDLE; p_dev_rec->sec_rec.sec_state = tSECURITY_STATE::BTM_SEC_STATE_IDLE; log::verbose("clearing callback. p_dev_rec={}, p_callback={}", log::verbose("clearing callback. p_dev_rec={}, p_callback={}", fmt::ptr(p_dev_rec), fmt::ptr(p_dev_rec->sec_rec.p_callback)); fmt::ptr(p_dev_rec), fmt::ptr(p_dev_rec->sec_rec.p_callback)); Loading Loading @@ -2300,7 +2302,7 @@ void btm_sec_rmt_name_request_complete(const RawAddress* p_bd_addr, log::info( log::info( "Remote read request complete with no address so searching device " "Remote read request complete with no address so searching device " "database"); "database"); p_dev_rec = btm_sec_find_dev_by_sec_state(BTM_SEC_STATE_GETTING_NAME); p_dev_rec = btm_sec_find_dev_by_sec_state(tSECURITY_STATE::BTM_SEC_STATE_GETTING_NAME); if (p_dev_rec) { if (p_dev_rec) { p_bd_addr = &p_dev_rec->bd_addr; p_bd_addr = &p_dev_rec->bd_addr; } } Loading Loading @@ -2359,8 +2361,9 @@ void btm_sec_rmt_name_request_complete(const RawAddress* p_bd_addr, // Security procedure resumes // Security procedure resumes tSECURITY_STATE old_sec_state = p_dev_rec->sec_rec.sec_state; tSECURITY_STATE old_sec_state = p_dev_rec->sec_rec.sec_state; if (p_dev_rec->sec_rec.sec_state == BTM_SEC_STATE_GETTING_NAME) if (p_dev_rec->sec_rec.sec_state == tSECURITY_STATE::BTM_SEC_STATE_GETTING_NAME) { p_dev_rec->sec_rec.sec_state = BTM_SEC_STATE_IDLE; p_dev_rec->sec_rec.sec_state = tSECURITY_STATE::BTM_SEC_STATE_IDLE; } /* If we were delaying asking UI for a PIN because name was not resolved, /* If we were delaying asking UI for a PIN because name was not resolved, * ask now */ * ask now */ Loading Loading @@ -2482,7 +2485,9 @@ void btm_sec_rmt_name_request_complete(const RawAddress* p_bd_addr, return; return; } } if (old_sec_state != BTM_SEC_STATE_GETTING_NAME) return; if (old_sec_state != tSECURITY_STATE::BTM_SEC_STATE_GETTING_NAME) { return; } /* If get name failed, notify the waiting layer */ /* If get name failed, notify the waiting layer */ if (status != HCI_SUCCESS) { if (status != HCI_SUCCESS) { Loading Loading @@ -2960,7 +2965,7 @@ void btm_simple_pair_complete(const RawAddress bd_addr, uint8_t status) { /* stop the timer */ /* stop the timer */ alarm_cancel(btm_sec_cb.pairing_timer); alarm_cancel(btm_sec_cb.pairing_timer); if (p_dev_rec->sec_rec.sec_state != BTM_SEC_STATE_AUTHENTICATING) { if (p_dev_rec->sec_rec.sec_state != tSECURITY_STATE::BTM_SEC_STATE_AUTHENTICATING) { /* the initiating side: will receive auth complete event. disconnect ACL /* the initiating side: will receive auth complete event. disconnect ACL * at that time */ * at that time */ disc = true; disc = true; Loading Loading @@ -3061,9 +3066,9 @@ static void btm_sec_auth_collision(uint16_t handle) { if ((bluetooth::common::time_get_os_boottime_ms() - if ((bluetooth::common::time_get_os_boottime_ms() - btm_sec_cb.collision_start_time) < BTM_SEC_MAX_COLLISION_DELAY) { btm_sec_cb.collision_start_time) < BTM_SEC_MAX_COLLISION_DELAY) { if (handle == HCI_INVALID_HANDLE) { if (handle == HCI_INVALID_HANDLE) { p_dev_rec = btm_sec_find_dev_by_sec_state(BTM_SEC_STATE_AUTHENTICATING); p_dev_rec = btm_sec_find_dev_by_sec_state(tSECURITY_STATE::BTM_SEC_STATE_AUTHENTICATING); if (p_dev_rec == NULL) if (p_dev_rec == NULL) p_dev_rec = btm_sec_find_dev_by_sec_state(BTM_SEC_STATE_ENCRYPTING); p_dev_rec = btm_sec_find_dev_by_sec_state(tSECURITY_STATE::BTM_SEC_STATE_ENCRYPTING); } else } else p_dev_rec = btm_find_dev_by_handle(handle); p_dev_rec = btm_find_dev_by_handle(handle); Loading @@ -3071,9 +3076,10 @@ static void btm_sec_auth_collision(uint16_t handle) { log::verbose("btm_sec_auth_collision: state {} (retrying in a moment...)", log::verbose("btm_sec_auth_collision: state {} (retrying in a moment...)", p_dev_rec->sec_rec.sec_state); p_dev_rec->sec_rec.sec_state); /* We will restart authentication after timeout */ /* We will restart authentication after timeout */ if (p_dev_rec->sec_rec.sec_state == BTM_SEC_STATE_AUTHENTICATING || if (p_dev_rec->sec_rec.sec_state == tSECURITY_STATE::BTM_SEC_STATE_AUTHENTICATING || p_dev_rec->sec_rec.is_security_state_bredr_encrypting()) p_dev_rec->sec_rec.is_security_state_bredr_encrypting()) { p_dev_rec->sec_rec.sec_state = BTM_SEC_STATE_IDLE; p_dev_rec->sec_rec.sec_state = tSECURITY_STATE::BTM_SEC_STATE_IDLE; } btm_sec_cb.p_collided_dev_rec = p_dev_rec; btm_sec_cb.p_collided_dev_rec = p_dev_rec; alarm_set_on_mloop(btm_sec_cb.sec_collision_timer, BT_1SEC_TIMEOUT_MS, alarm_set_on_mloop(btm_sec_cb.sec_collision_timer, BT_1SEC_TIMEOUT_MS, Loading Loading @@ -3118,7 +3124,7 @@ static bool btm_sec_auth_retry(uint16_t handle, uint8_t status) { controller. controller. If the stack may sit on top of other controller, we may need this If the stack may sit on top of other controller, we may need this BTM_DeleteStoredLinkKey (bd_addr, NULL); */ BTM_DeleteStoredLinkKey (bd_addr, NULL); */ p_dev_rec->sec_rec.sec_state = BTM_SEC_STATE_IDLE; p_dev_rec->sec_rec.sec_state = tSECURITY_STATE::BTM_SEC_STATE_IDLE; btm_sec_execute_procedure(p_dev_rec); btm_sec_execute_procedure(p_dev_rec); return true; return true; } } Loading Loading @@ -3171,8 +3177,8 @@ void btm_sec_auth_complete(uint16_t handle, tHCI_STATUS status) { if (!p_dev_rec) return; if (!p_dev_rec) return; if (p_dev_rec->sec_rec.sec_state == BTM_SEC_STATE_AUTHENTICATING) { if (p_dev_rec->sec_rec.sec_state == tSECURITY_STATE::BTM_SEC_STATE_AUTHENTICATING) { p_dev_rec->sec_rec.sec_state = BTM_SEC_STATE_IDLE; p_dev_rec->sec_rec.sec_state = tSECURITY_STATE::BTM_SEC_STATE_IDLE; was_authenticating = true; was_authenticating = true; /* There can be a race condition, when we are starting authentication /* There can be a race condition, when we are starting authentication * and the peer device is doing encryption. * and the peer device is doing encryption. Loading Loading @@ -3440,8 +3446,8 @@ void btm_sec_encrypt_change(uint16_t handle, tHCI_STATUS status, /* If this encryption was started by peer do not need to do anything */ /* If this encryption was started by peer do not need to do anything */ if (!p_dev_rec->sec_rec.is_security_state_bredr_encrypting()) { if (!p_dev_rec->sec_rec.is_security_state_bredr_encrypting()) { if (BTM_SEC_STATE_DELAY_FOR_ENC == p_dev_rec->sec_rec.sec_state) { if (tSECURITY_STATE::BTM_SEC_STATE_DELAY_FOR_ENC == p_dev_rec->sec_rec.sec_state) { p_dev_rec->sec_rec.sec_state = BTM_SEC_STATE_IDLE; p_dev_rec->sec_rec.sec_state = tSECURITY_STATE::BTM_SEC_STATE_IDLE; log::verbose("clearing callback. p_dev_rec={}, p_callback={}", log::verbose("clearing callback. p_dev_rec={}, p_callback={}", fmt::ptr(p_dev_rec), fmt::ptr(p_dev_rec), fmt::ptr(p_dev_rec->sec_rec.p_callback)); fmt::ptr(p_dev_rec->sec_rec.p_callback)); Loading @@ -3449,8 +3455,8 @@ void btm_sec_encrypt_change(uint16_t handle, tHCI_STATUS status, l2cu_resubmit_pending_sec_req(&p_dev_rec->bd_addr); l2cu_resubmit_pending_sec_req(&p_dev_rec->bd_addr); return; return; } else if (!concurrentPeerAuthIsEnabled() && } else if (!concurrentPeerAuthIsEnabled() && p_dev_rec->sec_rec.sec_state == BTM_SEC_STATE_AUTHENTICATING) { p_dev_rec->sec_rec.sec_state == tSECURITY_STATE::BTM_SEC_STATE_AUTHENTICATING) { p_dev_rec->sec_rec.sec_state = BTM_SEC_STATE_IDLE; p_dev_rec->sec_rec.sec_state = tSECURITY_STATE::BTM_SEC_STATE_IDLE; return; return; } } if (!handleUnexpectedEncryptionChange()) { if (!handleUnexpectedEncryptionChange()) { Loading @@ -3458,7 +3464,7 @@ void btm_sec_encrypt_change(uint16_t handle, tHCI_STATUS status, } } } } p_dev_rec->sec_rec.sec_state = BTM_SEC_STATE_IDLE; p_dev_rec->sec_rec.sec_state = tSECURITY_STATE::BTM_SEC_STATE_IDLE; /* If encryption setup failed, notify the waiting layer */ /* If encryption setup failed, notify the waiting layer */ if (status != HCI_SUCCESS) { if (status != HCI_SUCCESS) { btm_sec_dev_rec_cback_event(p_dev_rec, BTM_ERR_PROCESSING, false); btm_sec_dev_rec_cback_event(p_dev_rec, BTM_ERR_PROCESSING, false); Loading Loading @@ -4037,12 +4043,12 @@ void btm_sec_disconnected(uint16_t handle, tHCI_REASON reason, return; return; } } if (p_dev_rec->sec_rec.sec_state == BTM_SEC_STATE_DISCONNECTING_BOTH) { if (p_dev_rec->sec_rec.sec_state == tSECURITY_STATE::BTM_SEC_STATE_DISCONNECTING_BOTH) { log::debug("Waiting for other transport to disconnect current:{}", log::debug("Waiting for other transport to disconnect current:{}", bt_transport_text(transport)); bt_transport_text(transport)); p_dev_rec->sec_rec.sec_state = (transport == BT_TRANSPORT_LE) p_dev_rec->sec_rec.sec_state = (transport == BT_TRANSPORT_LE) ? BTM_SEC_STATE_DISCONNECTING ? tSECURITY_STATE::BTM_SEC_STATE_DISCONNECTING : BTM_SEC_STATE_DISCONNECTING_BLE; : tSECURITY_STATE::BTM_SEC_STATE_DISCONNECTING_BLE; return; return; } } Loading @@ -4055,14 +4061,14 @@ void btm_sec_disconnected(uint16_t handle, tHCI_REASON reason, return; return; } } if (p_dev_rec->sec_rec.sec_state == BTM_SEC_STATE_LE_ENCRYPTING && if (p_dev_rec->sec_rec.sec_state == tSECURITY_STATE::BTM_SEC_STATE_LE_ENCRYPTING && transport != BT_TRANSPORT_LE) { transport != BT_TRANSPORT_LE) { log::debug("Disconnection on the other transport while encrypting LE"); log::debug("Disconnection on the other transport while encrypting LE"); return; return; } } if ((p_dev_rec->sec_rec.sec_state == BTM_SEC_STATE_AUTHENTICATING || if ((p_dev_rec->sec_rec.sec_state == tSECURITY_STATE::BTM_SEC_STATE_AUTHENTICATING || p_dev_rec->sec_rec.sec_state == BTM_SEC_STATE_ENCRYPTING) && p_dev_rec->sec_rec.sec_state == tSECURITY_STATE::BTM_SEC_STATE_ENCRYPTING) && transport != BT_TRANSPORT_BR_EDR) { transport != BT_TRANSPORT_BR_EDR) { log::debug( log::debug( "Disconnection on the other transport while encrypting BR/EDR"); "Disconnection on the other transport while encrypting BR/EDR"); Loading @@ -4070,7 +4076,7 @@ void btm_sec_disconnected(uint16_t handle, tHCI_REASON reason, } } } } p_dev_rec->sec_rec.sec_state = BTM_SEC_STATE_IDLE; p_dev_rec->sec_rec.sec_state = tSECURITY_STATE::BTM_SEC_STATE_IDLE; p_dev_rec->sec_rec.security_required = BTM_SEC_NONE; p_dev_rec->sec_rec.security_required = BTM_SEC_NONE; if (p_dev_rec->sec_rec.p_callback != nullptr) { if (p_dev_rec->sec_rec.p_callback != nullptr) { Loading Loading @@ -4278,7 +4284,7 @@ void btm_sec_link_key_request(const RawAddress bda) { log::verbose("bda: {}", bda); log::verbose("bda: {}", bda); if (!concurrentPeerAuthIsEnabled()) { if (!concurrentPeerAuthIsEnabled()) { p_dev_rec->sec_rec.sec_state = BTM_SEC_STATE_AUTHENTICATING; p_dev_rec->sec_rec.sec_state = tSECURITY_STATE::BTM_SEC_STATE_AUTHENTICATING; } } if ((btm_sec_cb.pairing_state == BTM_PAIR_STATE_WAIT_PIN_REQ) && if ((btm_sec_cb.pairing_state == BTM_PAIR_STATE_WAIT_PIN_REQ) && Loading Loading @@ -4606,8 +4612,8 @@ tBTM_STATUS btm_sec_execute_procedure(tBTM_SEC_DEV_REC* p_dev_rec) { static_cast<tSECURITY_STATE>(p_dev_rec->sec_rec.sec_state)), static_cast<tSECURITY_STATE>(p_dev_rec->sec_rec.sec_state)), p_dev_rec->sec_rec.sec_state); p_dev_rec->sec_rec.sec_state); if (p_dev_rec->sec_rec.sec_state != BTM_SEC_STATE_IDLE && if (p_dev_rec->sec_rec.sec_state != tSECURITY_STATE::BTM_SEC_STATE_IDLE && p_dev_rec->sec_rec.sec_state != BTM_SEC_STATE_LE_ENCRYPTING) { p_dev_rec->sec_rec.sec_state != tSECURITY_STATE::BTM_SEC_STATE_LE_ENCRYPTING) { log::info("No immediate action taken in busy state: {}", log::info("No immediate action taken in busy state: {}", security_state_text(p_dev_rec->sec_rec.sec_state)); security_state_text(p_dev_rec->sec_rec.sec_state)); return (BTM_CMD_STARTED); return (BTM_CMD_STARTED); Loading Loading @@ -4702,7 +4708,7 @@ tBTM_STATUS btm_sec_execute_procedure(tBTM_SEC_DEV_REC* p_dev_rec) { log::verbose("Security Manager: Start encryption"); log::verbose("Security Manager: Start encryption"); btsnd_hcic_set_conn_encrypt(p_dev_rec->hci_handle, true); btsnd_hcic_set_conn_encrypt(p_dev_rec->hci_handle, true); p_dev_rec->sec_rec.sec_state = BTM_SEC_STATE_ENCRYPTING; p_dev_rec->sec_rec.sec_state = tSECURITY_STATE::BTM_SEC_STATE_ENCRYPTING; return (BTM_CMD_STARTED); return (BTM_CMD_STARTED); } else { } else { log::debug("Encryption not required"); log::debug("Encryption not required"); Loading Loading @@ -4749,7 +4755,7 @@ static bool btm_sec_start_get_name(tBTM_SEC_DEV_REC* p_dev_rec) { return false; return false; } } p_dev_rec->sec_rec.sec_state = BTM_SEC_STATE_GETTING_NAME; p_dev_rec->sec_rec.sec_state = tSECURITY_STATE::BTM_SEC_STATE_GETTING_NAME; /* 0 and NULL are as timeout and callback params because they are not used in /* 0 and NULL are as timeout and callback params because they are not used in * security get name case */ * security get name case */ Loading Loading @@ -4807,11 +4813,11 @@ static void btm_sec_auth_timer_timeout(void* data) { p_dev_rec->sec_rec.p_ref_data, p_dev_rec->sec_rec.p_ref_data, BTM_SUCCESS); BTM_SUCCESS); } } } else if (p_dev_rec->sec_rec.sec_state == BTM_SEC_STATE_AUTHENTICATING) { } else if (p_dev_rec->sec_rec.sec_state == tSECURITY_STATE::BTM_SEC_STATE_AUTHENTICATING) { log::info("device is in the process of authenticating"); log::info("device is in the process of authenticating"); } else { } else { log::info("starting authentication"); log::info("starting authentication"); p_dev_rec->sec_rec.sec_state = BTM_SEC_STATE_AUTHENTICATING; p_dev_rec->sec_rec.sec_state = tSECURITY_STATE::BTM_SEC_STATE_AUTHENTICATING; btsnd_hcic_auth_request(p_dev_rec->hci_handle); btsnd_hcic_auth_request(p_dev_rec->hci_handle); } } } } Loading system/stack/btm/security_device_record.h +25 −27 Original line number Original line Diff line number Diff line Loading @@ -154,7 +154,7 @@ enum : uint16_t { BTM_SEC_16_DIGIT_PIN_AUTHED = 0x4000, BTM_SEC_16_DIGIT_PIN_AUTHED = 0x4000, }; }; typedef enum : uint8_t { enum class tSECURITY_STATE : uint8_t { BTM_SEC_STATE_IDLE = 0, BTM_SEC_STATE_IDLE = 0, BTM_SEC_STATE_AUTHENTICATING = 1, BTM_SEC_STATE_AUTHENTICATING = 1, BTM_SEC_STATE_ENCRYPTING = 2, BTM_SEC_STATE_ENCRYPTING = 2, Loading @@ -169,23 +169,23 @@ typedef enum : uint8_t { BTM_SEC_STATE_DISCONNECTING_BLE = 8, BTM_SEC_STATE_DISCONNECTING_BLE = 8, BTM_SEC_STATE_DISCONNECTING_BOTH = 9, BTM_SEC_STATE_DISCONNECTING_BOTH = 9, BTM_SEC_STATE_LE_ENCRYPTING = 10, BTM_SEC_STATE_LE_ENCRYPTING = 10, } tSECURITY_STATE; }; static inline std::string security_state_text(const tSECURITY_STATE& state) { static inline std::string security_state_text(const tSECURITY_STATE& state) { switch (state) { switch (state) { CASE_RETURN_TEXT(BTM_SEC_STATE_IDLE); CASE_RETURN_STRING(tSECURITY_STATE::BTM_SEC_STATE_IDLE); CASE_RETURN_TEXT(BTM_SEC_STATE_AUTHENTICATING); CASE_RETURN_STRING(tSECURITY_STATE::BTM_SEC_STATE_AUTHENTICATING); CASE_RETURN_TEXT(BTM_SEC_STATE_ENCRYPTING); CASE_RETURN_STRING(tSECURITY_STATE::BTM_SEC_STATE_ENCRYPTING); CASE_RETURN_TEXT(BTM_SEC_STATE_GETTING_NAME); CASE_RETURN_STRING(tSECURITY_STATE::BTM_SEC_STATE_GETTING_NAME); CASE_RETURN_TEXT(BTM_SEC_STATE_AUTHORIZING); CASE_RETURN_STRING(tSECURITY_STATE::BTM_SEC_STATE_AUTHORIZING); CASE_RETURN_TEXT(BTM_SEC_STATE_SWITCHING_ROLE); CASE_RETURN_STRING(tSECURITY_STATE::BTM_SEC_STATE_SWITCHING_ROLE); CASE_RETURN_TEXT(BTM_SEC_STATE_DISCONNECTING); CASE_RETURN_STRING(tSECURITY_STATE::BTM_SEC_STATE_DISCONNECTING); CASE_RETURN_TEXT(BTM_SEC_STATE_DELAY_FOR_ENC); CASE_RETURN_STRING(tSECURITY_STATE::BTM_SEC_STATE_DELAY_FOR_ENC); CASE_RETURN_TEXT(BTM_SEC_STATE_DISCONNECTING_BLE); CASE_RETURN_STRING(tSECURITY_STATE::BTM_SEC_STATE_DISCONNECTING_BLE); CASE_RETURN_TEXT(BTM_SEC_STATE_DISCONNECTING_BOTH); CASE_RETURN_STRING(tSECURITY_STATE::BTM_SEC_STATE_DISCONNECTING_BOTH); CASE_RETURN_TEXT(BTM_SEC_STATE_LE_ENCRYPTING); CASE_RETURN_STRING(tSECURITY_STATE::BTM_SEC_STATE_LE_ENCRYPTING); default: default: return base::StringPrintf("UNKNOWN[%hhu]", state); RETURN_UNKNOWN_TYPE_STRING(tSECURITY_STATE, state); } } } } Loading Loading @@ -304,42 +304,40 @@ struct tBTM_SEC_REC { sec_flags &= ~BTM_SEC_16_DIGIT_PIN_AUTHED; sec_flags &= ~BTM_SEC_16_DIGIT_PIN_AUTHED; } } bool is_security_state_idle() const { bool is_security_state_idle() const { return sec_state == tSECURITY_STATE::BTM_SEC_STATE_IDLE; } return sec_state == BTM_SEC_STATE_IDLE; } bool is_security_state_authenticating() const { bool is_security_state_authenticating() const { return sec_state == BTM_SEC_STATE_AUTHENTICATING; return sec_state == tSECURITY_STATE::BTM_SEC_STATE_AUTHENTICATING; } } bool is_security_state_bredr_encrypting() const { bool is_security_state_bredr_encrypting() const { return sec_state == BTM_SEC_STATE_ENCRYPTING; return sec_state == tSECURITY_STATE::BTM_SEC_STATE_ENCRYPTING; } } bool is_security_state_le_encrypting() const { bool is_security_state_le_encrypting() const { return sec_state == BTM_SEC_STATE_LE_ENCRYPTING; return sec_state == tSECURITY_STATE::BTM_SEC_STATE_LE_ENCRYPTING; } } bool is_security_state_encrypting() const { bool is_security_state_encrypting() const { return (is_security_state_bredr_encrypting() || return (is_security_state_bredr_encrypting() || is_security_state_le_encrypting()); is_security_state_le_encrypting()); } } bool is_security_state_getting_name() const { bool is_security_state_getting_name() const { return sec_state == BTM_SEC_STATE_GETTING_NAME; return sec_state == tSECURITY_STATE::BTM_SEC_STATE_GETTING_NAME; } } bool is_security_state_authorizing() const { bool is_security_state_authorizing() const { return sec_state == BTM_SEC_STATE_AUTHORIZING; return sec_state == tSECURITY_STATE::BTM_SEC_STATE_AUTHORIZING; } } bool is_security_state_switching_role() const { bool is_security_state_switching_role() const { return sec_state == BTM_SEC_STATE_SWITCHING_ROLE; return sec_state == tSECURITY_STATE::BTM_SEC_STATE_SWITCHING_ROLE; } } bool is_security_state_disconnecting() const { bool is_security_state_disconnecting() const { return sec_state == BTM_SEC_STATE_DISCONNECTING; return sec_state == tSECURITY_STATE::BTM_SEC_STATE_DISCONNECTING; } } bool is_security_state_wait_for_encryption() const { bool is_security_state_wait_for_encryption() const { return sec_state == BTM_SEC_STATE_DELAY_FOR_ENC; return sec_state == tSECURITY_STATE::BTM_SEC_STATE_DELAY_FOR_ENC; } } bool is_security_state_ble_disconnecting() const { bool is_security_state_ble_disconnecting() const { return sec_state == BTM_SEC_STATE_DISCONNECTING_BLE; return sec_state == tSECURITY_STATE::BTM_SEC_STATE_DISCONNECTING_BLE; } } bool is_security_state_br_edr_and_ble() const { bool is_security_state_br_edr_and_ble() const { return sec_state == BTM_SEC_STATE_DISCONNECTING_BOTH; return sec_state == tSECURITY_STATE::BTM_SEC_STATE_DISCONNECTING_BOTH; } } bool is_bond_type_unknown() const { return bond_type == BOND_TYPE_UNKNOWN; } bool is_bond_type_unknown() const { return bond_type == BOND_TYPE_UNKNOWN; } Loading Loading
system/stack/btm/btm_ble_sec.cc +8 −8 Original line number Original line Diff line number Diff line Loading @@ -30,7 +30,6 @@ #include "btif/include/btif_storage.h" #include "btif/include/btif_storage.h" #include "crypto_toolbox/crypto_toolbox.h" #include "crypto_toolbox/crypto_toolbox.h" #include "device/include/interop.h" #include "device/include/interop.h" #include "device/include/interop_config.h" #include "hci/controller_interface.h" #include "hci/controller_interface.h" #include "main/shim/entry.h" #include "main/shim/entry.h" #include "osi/include/allocator.h" #include "osi/include/allocator.h" Loading Loading @@ -1068,7 +1067,7 @@ void btm_ble_link_sec_check(const RawAddress& bd_addr, } } if (p_dev_rec->sec_rec.is_security_state_encrypting() || if (p_dev_rec->sec_rec.is_security_state_encrypting() || p_dev_rec->sec_rec.sec_state == BTM_SEC_STATE_AUTHENTICATING) { p_dev_rec->sec_rec.sec_state == tSECURITY_STATE::BTM_SEC_STATE_AUTHENTICATING) { /* race condition: discard the security request while central is encrypting /* race condition: discard the security request while central is encrypting * the link */ * the link */ *p_sec_req_act = BTM_BLE_SEC_REQ_ACT_DISCARD; *p_sec_req_act = BTM_BLE_SEC_REQ_ACT_DISCARD; Loading Loading @@ -1172,7 +1171,7 @@ tBTM_STATUS btm_ble_set_encryption(const RawAddress& bd_addr, if (SMP_Pair(bd_addr) == SMP_STARTED) { if (SMP_Pair(bd_addr) == SMP_STARTED) { cmd = BTM_CMD_STARTED; cmd = BTM_CMD_STARTED; p_rec->sec_rec.sec_state = BTM_SEC_STATE_AUTHENTICATING; p_rec->sec_rec.sec_state = tSECURITY_STATE::BTM_SEC_STATE_AUTHENTICATING; } } break; break; Loading Loading @@ -1253,8 +1252,9 @@ tBTM_STATUS btm_ble_start_encrypt(const RawAddress& bda, bool use_stk, return BTM_ERR_KEY_MISSING; return BTM_ERR_KEY_MISSING; } } if (p_rec->sec_rec.sec_state == BTM_SEC_STATE_IDLE) if (p_rec->sec_rec.sec_state == tSECURITY_STATE::BTM_SEC_STATE_IDLE) { p_rec->sec_rec.sec_state = BTM_SEC_STATE_LE_ENCRYPTING; p_rec->sec_rec.sec_state = tSECURITY_STATE::BTM_SEC_STATE_LE_ENCRYPTING; } return BTM_CMD_STARTED; return BTM_CMD_STARTED; } } Loading Loading @@ -1324,7 +1324,7 @@ void btm_ble_link_encrypted(const RawAddress& bd_addr, uint8_t encr_enable) { if (encr_enable && p_dev_rec->sec_rec.enc_key_size == 0) if (encr_enable && p_dev_rec->sec_rec.enc_key_size == 0) p_dev_rec->sec_rec.enc_key_size = p_dev_rec->sec_rec.ble_keys.key_size; p_dev_rec->sec_rec.enc_key_size = p_dev_rec->sec_rec.ble_keys.key_size; p_dev_rec->sec_rec.sec_state = BTM_SEC_STATE_IDLE; p_dev_rec->sec_rec.sec_state = tSECURITY_STATE::BTM_SEC_STATE_IDLE; if (p_dev_rec->sec_rec.p_callback && enc_cback) { if (p_dev_rec->sec_rec.p_callback && enc_cback) { if (encr_enable) btm_sec_dev_rec_cback_event(p_dev_rec, BTM_SUCCESS, true); if (encr_enable) btm_sec_dev_rec_cback_event(p_dev_rec, BTM_SUCCESS, true); /* LTK missing on peripheral */ /* LTK missing on peripheral */ Loading Loading @@ -1594,7 +1594,7 @@ tBTM_STATUS btm_proc_smp_cback(tSMP_EVT event, const RawAddress& bd_addr, } } btm_sec_cb.pairing_bda = bd_addr; btm_sec_cb.pairing_bda = bd_addr; if (event != SMP_CONSENT_REQ_EVT) { if (event != SMP_CONSENT_REQ_EVT) { p_dev_rec->sec_rec.sec_state = BTM_SEC_STATE_AUTHENTICATING; p_dev_rec->sec_rec.sec_state = tSECURITY_STATE::BTM_SEC_STATE_AUTHENTICATING; } } btm_sec_cb.pairing_flags |= BTM_PAIR_FLAGS_LE_ACTIVE; btm_sec_cb.pairing_flags |= BTM_PAIR_FLAGS_LE_ACTIVE; FALLTHROUGH_INTENDED; /* FALLTHROUGH */ FALLTHROUGH_INTENDED; /* FALLTHROUGH */ Loading Loading @@ -1651,7 +1651,7 @@ tBTM_STATUS btm_proc_smp_cback(tSMP_EVT event, const RawAddress& bd_addr, } } if (res == BTM_SUCCESS) { if (res == BTM_SUCCESS) { p_dev_rec->sec_rec.sec_state = BTM_SEC_STATE_IDLE; p_dev_rec->sec_rec.sec_state = tSECURITY_STATE::BTM_SEC_STATE_IDLE; if (p_dev_rec->sec_rec.bond_type != BOND_TYPE_TEMPORARY) { if (p_dev_rec->sec_rec.bond_type != BOND_TYPE_TEMPORARY) { // Add all bonded device into resolving list if IRK is available. // Add all bonded device into resolving list if IRK is available. Loading
system/stack/btm/btm_dev.cc +1 −1 Original line number Original line Diff line number Diff line Loading @@ -214,7 +214,7 @@ void BTM_SecClearSecurityFlags(const RawAddress& bd_addr) { if (p_dev_rec == NULL) return; if (p_dev_rec == NULL) return; p_dev_rec->sec_rec.sec_flags = 0; p_dev_rec->sec_rec.sec_flags = 0; p_dev_rec->sec_rec.sec_state = BTM_SEC_STATE_IDLE; p_dev_rec->sec_rec.sec_state = tSECURITY_STATE::BTM_SEC_STATE_IDLE; p_dev_rec->sm4 = BTM_SM4_UNKNOWN; p_dev_rec->sm4 = BTM_SM4_UNKNOWN; } } Loading
system/stack/btm/btm_devctl.cc +1 −1 Original line number Original line Diff line number Diff line Loading @@ -161,7 +161,7 @@ void BTM_db_reset(void) { static bool set_sec_state_idle(void* data, void* /* context */) { static bool set_sec_state_idle(void* data, void* /* context */) { tBTM_SEC_DEV_REC* p_dev_rec = static_cast<tBTM_SEC_DEV_REC*>(data); tBTM_SEC_DEV_REC* p_dev_rec = static_cast<tBTM_SEC_DEV_REC*>(data); p_dev_rec->sec_rec.sec_state = BTM_SEC_STATE_IDLE; p_dev_rec->sec_rec.sec_state = tSECURITY_STATE::BTM_SEC_STATE_IDLE; return true; return true; } } Loading
system/stack/btm/btm_sec.cc +62 −56 Original line number Original line Diff line number Diff line Loading @@ -766,7 +766,7 @@ tBTM_STATUS btm_sec_bond_by_transport(const RawAddress& bd_addr, if (SMP_Pair(bd_addr, addr_type) == SMP_STARTED) { if (SMP_Pair(bd_addr, addr_type) == SMP_STARTED) { btm_sec_cb.pairing_flags |= BTM_PAIR_FLAGS_LE_ACTIVE; btm_sec_cb.pairing_flags |= BTM_PAIR_FLAGS_LE_ACTIVE; p_dev_rec->sec_rec.sec_state = BTM_SEC_STATE_AUTHENTICATING; p_dev_rec->sec_rec.sec_state = tSECURITY_STATE::BTM_SEC_STATE_AUTHENTICATING; btm_sec_cb.change_pairing_state(BTM_PAIR_STATE_WAIT_AUTH_COMPLETE); btm_sec_cb.change_pairing_state(BTM_PAIR_STATE_WAIT_AUTH_COMPLETE); return BTM_CMD_STARTED; return BTM_CMD_STARTED; } } Loading Loading @@ -918,7 +918,7 @@ tBTM_STATUS BTM_SecBondCancel(const RawAddress& bd_addr) { } } if (btm_sec_cb.pairing_flags & BTM_PAIR_FLAGS_LE_ACTIVE) { if (btm_sec_cb.pairing_flags & BTM_PAIR_FLAGS_LE_ACTIVE) { if (p_dev_rec->sec_rec.sec_state == BTM_SEC_STATE_AUTHENTICATING) { if (p_dev_rec->sec_rec.sec_state == tSECURITY_STATE::BTM_SEC_STATE_AUTHENTICATING) { log::verbose("Cancel LE pairing"); log::verbose("Cancel LE pairing"); if (SMP_PairCancel(bd_addr)) { if (SMP_PairCancel(bd_addr)) { return BTM_CMD_STARTED; return BTM_CMD_STARTED; Loading @@ -942,9 +942,10 @@ tBTM_STATUS BTM_SecBondCancel(const RawAddress& bd_addr) { /* If the HCI link is up */ /* If the HCI link is up */ if (p_dev_rec->hci_handle != HCI_INVALID_HANDLE) { if (p_dev_rec->hci_handle != HCI_INVALID_HANDLE) { /* If some other thread disconnecting, we do not send second command */ /* If some other thread disconnecting, we do not send second command */ if ((p_dev_rec->sec_rec.sec_state == BTM_SEC_STATE_DISCONNECTING) || if ((p_dev_rec->sec_rec.sec_state == tSECURITY_STATE::BTM_SEC_STATE_DISCONNECTING) || (p_dev_rec->sec_rec.sec_state == BTM_SEC_STATE_DISCONNECTING_BOTH)) (p_dev_rec->sec_rec.sec_state == tSECURITY_STATE::BTM_SEC_STATE_DISCONNECTING_BOTH)) { return (BTM_CMD_STARTED); return (BTM_CMD_STARTED); } /* If the HCI link was set up by Bonding process */ /* If the HCI link was set up by Bonding process */ if (btm_sec_cb.pairing_flags & BTM_PAIR_FLAGS_DISC_WHEN_DONE) if (btm_sec_cb.pairing_flags & BTM_PAIR_FLAGS_DISC_WHEN_DONE) Loading Loading @@ -1101,21 +1102,21 @@ tBTM_STATUS BTM_SetEncryption(const RawAddress& bd_addr, if (bluetooth::common::init_flags::encryption_in_busy_state_is_enabled()) { if (bluetooth::common::init_flags::encryption_in_busy_state_is_enabled()) { bool enqueue = false; bool enqueue = false; switch (p_dev_rec->sec_rec.sec_state) { switch (p_dev_rec->sec_rec.sec_state) { case BTM_SEC_STATE_AUTHENTICATING: case tSECURITY_STATE::BTM_SEC_STATE_AUTHENTICATING: case BTM_SEC_STATE_DISCONNECTING_BOTH: case tSECURITY_STATE::BTM_SEC_STATE_DISCONNECTING_BOTH: /* Applicable for both transports */ /* Applicable for both transports */ enqueue = true; enqueue = true; break; break; case BTM_SEC_STATE_ENCRYPTING: case tSECURITY_STATE::BTM_SEC_STATE_ENCRYPTING: case BTM_SEC_STATE_DISCONNECTING: case tSECURITY_STATE::BTM_SEC_STATE_DISCONNECTING: if (transport == BT_TRANSPORT_BR_EDR) { if (transport == BT_TRANSPORT_BR_EDR) { enqueue = true; enqueue = true; } } break; break; case BTM_SEC_STATE_LE_ENCRYPTING: case tSECURITY_STATE::BTM_SEC_STATE_LE_ENCRYPTING: case BTM_SEC_STATE_DISCONNECTING_BLE: case tSECURITY_STATE::BTM_SEC_STATE_DISCONNECTING_BLE: if (transport == BT_TRANSPORT_LE) { if (transport == BT_TRANSPORT_LE) { enqueue = true; enqueue = true; } } Loading @@ -1137,7 +1138,7 @@ tBTM_STATUS BTM_SetEncryption(const RawAddress& bd_addr, } } } else { } else { if (p_dev_rec->sec_rec.p_callback || if (p_dev_rec->sec_rec.p_callback || (p_dev_rec->sec_rec.sec_state != BTM_SEC_STATE_IDLE)) { (p_dev_rec->sec_rec.sec_state != tSECURITY_STATE::BTM_SEC_STATE_IDLE)) { log::warn("Security Manager: BTM_SetEncryption busy, enqueue request"); log::warn("Security Manager: BTM_SetEncryption busy, enqueue request"); btm_sec_queue_encrypt_request(bd_addr, transport, p_callback, p_ref_data, btm_sec_queue_encrypt_request(bd_addr, transport, p_callback, p_ref_data, sec_act); sec_act); Loading Loading @@ -1204,7 +1205,7 @@ bool BTM_SecIsSecurityPending(const RawAddress& bd_addr) { tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(bd_addr); tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(bd_addr); return p_dev_rec && return p_dev_rec && (p_dev_rec->sec_rec.is_security_state_encrypting() || (p_dev_rec->sec_rec.is_security_state_encrypting() || p_dev_rec->sec_rec.sec_state == BTM_SEC_STATE_AUTHENTICATING); p_dev_rec->sec_rec.sec_state == tSECURITY_STATE::BTM_SEC_STATE_AUTHENTICATING); } } /******************************************************************************* /******************************************************************************* Loading @@ -1220,32 +1221,32 @@ static tBTM_STATUS btm_sec_send_hci_disconnect(tBTM_SEC_DEV_REC* p_dev_rec, /* send HCI_Disconnect on a transport only once */ /* send HCI_Disconnect on a transport only once */ switch (old_state) { switch (old_state) { case BTM_SEC_STATE_DISCONNECTING: case tSECURITY_STATE::BTM_SEC_STATE_DISCONNECTING: if (conn_handle == p_dev_rec->hci_handle) { if (conn_handle == p_dev_rec->hci_handle) { // Already sent classic disconnect // Already sent classic disconnect return status; return status; } } // Prepare to send disconnect on le transport // Prepare to send disconnect on le transport p_dev_rec->sec_rec.sec_state = BTM_SEC_STATE_DISCONNECTING_BOTH; p_dev_rec->sec_rec.sec_state = tSECURITY_STATE::BTM_SEC_STATE_DISCONNECTING_BOTH; break; break; case BTM_SEC_STATE_DISCONNECTING_BLE: case tSECURITY_STATE::BTM_SEC_STATE_DISCONNECTING_BLE: if (conn_handle == p_dev_rec->ble_hci_handle) { if (conn_handle == p_dev_rec->ble_hci_handle) { // Already sent ble disconnect // Already sent ble disconnect return status; return status; } } // Prepare to send disconnect on classic transport // Prepare to send disconnect on classic transport p_dev_rec->sec_rec.sec_state = BTM_SEC_STATE_DISCONNECTING_BOTH; p_dev_rec->sec_rec.sec_state = tSECURITY_STATE::BTM_SEC_STATE_DISCONNECTING_BOTH; break; break; case BTM_SEC_STATE_DISCONNECTING_BOTH: case tSECURITY_STATE::BTM_SEC_STATE_DISCONNECTING_BOTH: // Already sent disconnect on both transports // Already sent disconnect on both transports return status; return status; default: default: p_dev_rec->sec_rec.sec_state = (conn_handle == p_dev_rec->hci_handle) p_dev_rec->sec_rec.sec_state = (conn_handle == p_dev_rec->hci_handle) ? BTM_SEC_STATE_DISCONNECTING ? tSECURITY_STATE::BTM_SEC_STATE_DISCONNECTING : BTM_SEC_STATE_DISCONNECTING_BLE; : tSECURITY_STATE::BTM_SEC_STATE_DISCONNECTING_BLE; break; break; } } Loading Loading @@ -1723,7 +1724,7 @@ tBTM_STATUS btm_sec_l2cap_access_req_by_requirement( log::info( log::info( "peer should have initiated security process by now (SM4 to SM4)"); "peer should have initiated security process by now (SM4 to SM4)"); p_dev_rec->sec_rec.p_callback = p_callback; p_dev_rec->sec_rec.p_callback = p_callback; p_dev_rec->sec_rec.sec_state = BTM_SEC_STATE_DELAY_FOR_ENC; p_dev_rec->sec_rec.sec_state = tSECURITY_STATE::BTM_SEC_STATE_DELAY_FOR_ENC; (*p_callback)(bd_addr, transport, p_ref_data, rc); (*p_callback)(bd_addr, transport, p_ref_data, rc); return BTM_SUCCESS; return BTM_SUCCESS; Loading Loading @@ -1906,7 +1907,7 @@ tBTM_STATUS btm_sec_mx_access_request(const RawAddress& bd_addr, } } /* the new security request */ /* the new security request */ if (p_dev_rec->sec_rec.sec_state != BTM_SEC_STATE_IDLE) { if (p_dev_rec->sec_rec.sec_state != tSECURITY_STATE::BTM_SEC_STATE_IDLE) { log::debug("A pending security procedure in progress"); log::debug("A pending security procedure in progress"); rc = BTM_CMD_STARTED; rc = BTM_CMD_STARTED; } } Loading Loading @@ -2195,11 +2196,12 @@ void btm_sec_abort_access_req(const RawAddress& bd_addr) { if (!p_dev_rec) return; if (!p_dev_rec) return; if ((p_dev_rec->sec_rec.sec_state != BTM_SEC_STATE_AUTHORIZING) && if ((p_dev_rec->sec_rec.sec_state != tSECURITY_STATE::BTM_SEC_STATE_AUTHORIZING) && (p_dev_rec->sec_rec.sec_state != BTM_SEC_STATE_AUTHENTICATING)) (p_dev_rec->sec_rec.sec_state != tSECURITY_STATE::BTM_SEC_STATE_AUTHENTICATING)) { return; return; } p_dev_rec->sec_rec.sec_state = BTM_SEC_STATE_IDLE; p_dev_rec->sec_rec.sec_state = tSECURITY_STATE::BTM_SEC_STATE_IDLE; log::verbose("clearing callback. p_dev_rec={}, p_callback={}", log::verbose("clearing callback. p_dev_rec={}, p_callback={}", fmt::ptr(p_dev_rec), fmt::ptr(p_dev_rec->sec_rec.p_callback)); fmt::ptr(p_dev_rec), fmt::ptr(p_dev_rec->sec_rec.p_callback)); Loading Loading @@ -2300,7 +2302,7 @@ void btm_sec_rmt_name_request_complete(const RawAddress* p_bd_addr, log::info( log::info( "Remote read request complete with no address so searching device " "Remote read request complete with no address so searching device " "database"); "database"); p_dev_rec = btm_sec_find_dev_by_sec_state(BTM_SEC_STATE_GETTING_NAME); p_dev_rec = btm_sec_find_dev_by_sec_state(tSECURITY_STATE::BTM_SEC_STATE_GETTING_NAME); if (p_dev_rec) { if (p_dev_rec) { p_bd_addr = &p_dev_rec->bd_addr; p_bd_addr = &p_dev_rec->bd_addr; } } Loading Loading @@ -2359,8 +2361,9 @@ void btm_sec_rmt_name_request_complete(const RawAddress* p_bd_addr, // Security procedure resumes // Security procedure resumes tSECURITY_STATE old_sec_state = p_dev_rec->sec_rec.sec_state; tSECURITY_STATE old_sec_state = p_dev_rec->sec_rec.sec_state; if (p_dev_rec->sec_rec.sec_state == BTM_SEC_STATE_GETTING_NAME) if (p_dev_rec->sec_rec.sec_state == tSECURITY_STATE::BTM_SEC_STATE_GETTING_NAME) { p_dev_rec->sec_rec.sec_state = BTM_SEC_STATE_IDLE; p_dev_rec->sec_rec.sec_state = tSECURITY_STATE::BTM_SEC_STATE_IDLE; } /* If we were delaying asking UI for a PIN because name was not resolved, /* If we were delaying asking UI for a PIN because name was not resolved, * ask now */ * ask now */ Loading Loading @@ -2482,7 +2485,9 @@ void btm_sec_rmt_name_request_complete(const RawAddress* p_bd_addr, return; return; } } if (old_sec_state != BTM_SEC_STATE_GETTING_NAME) return; if (old_sec_state != tSECURITY_STATE::BTM_SEC_STATE_GETTING_NAME) { return; } /* If get name failed, notify the waiting layer */ /* If get name failed, notify the waiting layer */ if (status != HCI_SUCCESS) { if (status != HCI_SUCCESS) { Loading Loading @@ -2960,7 +2965,7 @@ void btm_simple_pair_complete(const RawAddress bd_addr, uint8_t status) { /* stop the timer */ /* stop the timer */ alarm_cancel(btm_sec_cb.pairing_timer); alarm_cancel(btm_sec_cb.pairing_timer); if (p_dev_rec->sec_rec.sec_state != BTM_SEC_STATE_AUTHENTICATING) { if (p_dev_rec->sec_rec.sec_state != tSECURITY_STATE::BTM_SEC_STATE_AUTHENTICATING) { /* the initiating side: will receive auth complete event. disconnect ACL /* the initiating side: will receive auth complete event. disconnect ACL * at that time */ * at that time */ disc = true; disc = true; Loading Loading @@ -3061,9 +3066,9 @@ static void btm_sec_auth_collision(uint16_t handle) { if ((bluetooth::common::time_get_os_boottime_ms() - if ((bluetooth::common::time_get_os_boottime_ms() - btm_sec_cb.collision_start_time) < BTM_SEC_MAX_COLLISION_DELAY) { btm_sec_cb.collision_start_time) < BTM_SEC_MAX_COLLISION_DELAY) { if (handle == HCI_INVALID_HANDLE) { if (handle == HCI_INVALID_HANDLE) { p_dev_rec = btm_sec_find_dev_by_sec_state(BTM_SEC_STATE_AUTHENTICATING); p_dev_rec = btm_sec_find_dev_by_sec_state(tSECURITY_STATE::BTM_SEC_STATE_AUTHENTICATING); if (p_dev_rec == NULL) if (p_dev_rec == NULL) p_dev_rec = btm_sec_find_dev_by_sec_state(BTM_SEC_STATE_ENCRYPTING); p_dev_rec = btm_sec_find_dev_by_sec_state(tSECURITY_STATE::BTM_SEC_STATE_ENCRYPTING); } else } else p_dev_rec = btm_find_dev_by_handle(handle); p_dev_rec = btm_find_dev_by_handle(handle); Loading @@ -3071,9 +3076,10 @@ static void btm_sec_auth_collision(uint16_t handle) { log::verbose("btm_sec_auth_collision: state {} (retrying in a moment...)", log::verbose("btm_sec_auth_collision: state {} (retrying in a moment...)", p_dev_rec->sec_rec.sec_state); p_dev_rec->sec_rec.sec_state); /* We will restart authentication after timeout */ /* We will restart authentication after timeout */ if (p_dev_rec->sec_rec.sec_state == BTM_SEC_STATE_AUTHENTICATING || if (p_dev_rec->sec_rec.sec_state == tSECURITY_STATE::BTM_SEC_STATE_AUTHENTICATING || p_dev_rec->sec_rec.is_security_state_bredr_encrypting()) p_dev_rec->sec_rec.is_security_state_bredr_encrypting()) { p_dev_rec->sec_rec.sec_state = BTM_SEC_STATE_IDLE; p_dev_rec->sec_rec.sec_state = tSECURITY_STATE::BTM_SEC_STATE_IDLE; } btm_sec_cb.p_collided_dev_rec = p_dev_rec; btm_sec_cb.p_collided_dev_rec = p_dev_rec; alarm_set_on_mloop(btm_sec_cb.sec_collision_timer, BT_1SEC_TIMEOUT_MS, alarm_set_on_mloop(btm_sec_cb.sec_collision_timer, BT_1SEC_TIMEOUT_MS, Loading Loading @@ -3118,7 +3124,7 @@ static bool btm_sec_auth_retry(uint16_t handle, uint8_t status) { controller. controller. If the stack may sit on top of other controller, we may need this If the stack may sit on top of other controller, we may need this BTM_DeleteStoredLinkKey (bd_addr, NULL); */ BTM_DeleteStoredLinkKey (bd_addr, NULL); */ p_dev_rec->sec_rec.sec_state = BTM_SEC_STATE_IDLE; p_dev_rec->sec_rec.sec_state = tSECURITY_STATE::BTM_SEC_STATE_IDLE; btm_sec_execute_procedure(p_dev_rec); btm_sec_execute_procedure(p_dev_rec); return true; return true; } } Loading Loading @@ -3171,8 +3177,8 @@ void btm_sec_auth_complete(uint16_t handle, tHCI_STATUS status) { if (!p_dev_rec) return; if (!p_dev_rec) return; if (p_dev_rec->sec_rec.sec_state == BTM_SEC_STATE_AUTHENTICATING) { if (p_dev_rec->sec_rec.sec_state == tSECURITY_STATE::BTM_SEC_STATE_AUTHENTICATING) { p_dev_rec->sec_rec.sec_state = BTM_SEC_STATE_IDLE; p_dev_rec->sec_rec.sec_state = tSECURITY_STATE::BTM_SEC_STATE_IDLE; was_authenticating = true; was_authenticating = true; /* There can be a race condition, when we are starting authentication /* There can be a race condition, when we are starting authentication * and the peer device is doing encryption. * and the peer device is doing encryption. Loading Loading @@ -3440,8 +3446,8 @@ void btm_sec_encrypt_change(uint16_t handle, tHCI_STATUS status, /* If this encryption was started by peer do not need to do anything */ /* If this encryption was started by peer do not need to do anything */ if (!p_dev_rec->sec_rec.is_security_state_bredr_encrypting()) { if (!p_dev_rec->sec_rec.is_security_state_bredr_encrypting()) { if (BTM_SEC_STATE_DELAY_FOR_ENC == p_dev_rec->sec_rec.sec_state) { if (tSECURITY_STATE::BTM_SEC_STATE_DELAY_FOR_ENC == p_dev_rec->sec_rec.sec_state) { p_dev_rec->sec_rec.sec_state = BTM_SEC_STATE_IDLE; p_dev_rec->sec_rec.sec_state = tSECURITY_STATE::BTM_SEC_STATE_IDLE; log::verbose("clearing callback. p_dev_rec={}, p_callback={}", log::verbose("clearing callback. p_dev_rec={}, p_callback={}", fmt::ptr(p_dev_rec), fmt::ptr(p_dev_rec), fmt::ptr(p_dev_rec->sec_rec.p_callback)); fmt::ptr(p_dev_rec->sec_rec.p_callback)); Loading @@ -3449,8 +3455,8 @@ void btm_sec_encrypt_change(uint16_t handle, tHCI_STATUS status, l2cu_resubmit_pending_sec_req(&p_dev_rec->bd_addr); l2cu_resubmit_pending_sec_req(&p_dev_rec->bd_addr); return; return; } else if (!concurrentPeerAuthIsEnabled() && } else if (!concurrentPeerAuthIsEnabled() && p_dev_rec->sec_rec.sec_state == BTM_SEC_STATE_AUTHENTICATING) { p_dev_rec->sec_rec.sec_state == tSECURITY_STATE::BTM_SEC_STATE_AUTHENTICATING) { p_dev_rec->sec_rec.sec_state = BTM_SEC_STATE_IDLE; p_dev_rec->sec_rec.sec_state = tSECURITY_STATE::BTM_SEC_STATE_IDLE; return; return; } } if (!handleUnexpectedEncryptionChange()) { if (!handleUnexpectedEncryptionChange()) { Loading @@ -3458,7 +3464,7 @@ void btm_sec_encrypt_change(uint16_t handle, tHCI_STATUS status, } } } } p_dev_rec->sec_rec.sec_state = BTM_SEC_STATE_IDLE; p_dev_rec->sec_rec.sec_state = tSECURITY_STATE::BTM_SEC_STATE_IDLE; /* If encryption setup failed, notify the waiting layer */ /* If encryption setup failed, notify the waiting layer */ if (status != HCI_SUCCESS) { if (status != HCI_SUCCESS) { btm_sec_dev_rec_cback_event(p_dev_rec, BTM_ERR_PROCESSING, false); btm_sec_dev_rec_cback_event(p_dev_rec, BTM_ERR_PROCESSING, false); Loading Loading @@ -4037,12 +4043,12 @@ void btm_sec_disconnected(uint16_t handle, tHCI_REASON reason, return; return; } } if (p_dev_rec->sec_rec.sec_state == BTM_SEC_STATE_DISCONNECTING_BOTH) { if (p_dev_rec->sec_rec.sec_state == tSECURITY_STATE::BTM_SEC_STATE_DISCONNECTING_BOTH) { log::debug("Waiting for other transport to disconnect current:{}", log::debug("Waiting for other transport to disconnect current:{}", bt_transport_text(transport)); bt_transport_text(transport)); p_dev_rec->sec_rec.sec_state = (transport == BT_TRANSPORT_LE) p_dev_rec->sec_rec.sec_state = (transport == BT_TRANSPORT_LE) ? BTM_SEC_STATE_DISCONNECTING ? tSECURITY_STATE::BTM_SEC_STATE_DISCONNECTING : BTM_SEC_STATE_DISCONNECTING_BLE; : tSECURITY_STATE::BTM_SEC_STATE_DISCONNECTING_BLE; return; return; } } Loading @@ -4055,14 +4061,14 @@ void btm_sec_disconnected(uint16_t handle, tHCI_REASON reason, return; return; } } if (p_dev_rec->sec_rec.sec_state == BTM_SEC_STATE_LE_ENCRYPTING && if (p_dev_rec->sec_rec.sec_state == tSECURITY_STATE::BTM_SEC_STATE_LE_ENCRYPTING && transport != BT_TRANSPORT_LE) { transport != BT_TRANSPORT_LE) { log::debug("Disconnection on the other transport while encrypting LE"); log::debug("Disconnection on the other transport while encrypting LE"); return; return; } } if ((p_dev_rec->sec_rec.sec_state == BTM_SEC_STATE_AUTHENTICATING || if ((p_dev_rec->sec_rec.sec_state == tSECURITY_STATE::BTM_SEC_STATE_AUTHENTICATING || p_dev_rec->sec_rec.sec_state == BTM_SEC_STATE_ENCRYPTING) && p_dev_rec->sec_rec.sec_state == tSECURITY_STATE::BTM_SEC_STATE_ENCRYPTING) && transport != BT_TRANSPORT_BR_EDR) { transport != BT_TRANSPORT_BR_EDR) { log::debug( log::debug( "Disconnection on the other transport while encrypting BR/EDR"); "Disconnection on the other transport while encrypting BR/EDR"); Loading @@ -4070,7 +4076,7 @@ void btm_sec_disconnected(uint16_t handle, tHCI_REASON reason, } } } } p_dev_rec->sec_rec.sec_state = BTM_SEC_STATE_IDLE; p_dev_rec->sec_rec.sec_state = tSECURITY_STATE::BTM_SEC_STATE_IDLE; p_dev_rec->sec_rec.security_required = BTM_SEC_NONE; p_dev_rec->sec_rec.security_required = BTM_SEC_NONE; if (p_dev_rec->sec_rec.p_callback != nullptr) { if (p_dev_rec->sec_rec.p_callback != nullptr) { Loading Loading @@ -4278,7 +4284,7 @@ void btm_sec_link_key_request(const RawAddress bda) { log::verbose("bda: {}", bda); log::verbose("bda: {}", bda); if (!concurrentPeerAuthIsEnabled()) { if (!concurrentPeerAuthIsEnabled()) { p_dev_rec->sec_rec.sec_state = BTM_SEC_STATE_AUTHENTICATING; p_dev_rec->sec_rec.sec_state = tSECURITY_STATE::BTM_SEC_STATE_AUTHENTICATING; } } if ((btm_sec_cb.pairing_state == BTM_PAIR_STATE_WAIT_PIN_REQ) && if ((btm_sec_cb.pairing_state == BTM_PAIR_STATE_WAIT_PIN_REQ) && Loading Loading @@ -4606,8 +4612,8 @@ tBTM_STATUS btm_sec_execute_procedure(tBTM_SEC_DEV_REC* p_dev_rec) { static_cast<tSECURITY_STATE>(p_dev_rec->sec_rec.sec_state)), static_cast<tSECURITY_STATE>(p_dev_rec->sec_rec.sec_state)), p_dev_rec->sec_rec.sec_state); p_dev_rec->sec_rec.sec_state); if (p_dev_rec->sec_rec.sec_state != BTM_SEC_STATE_IDLE && if (p_dev_rec->sec_rec.sec_state != tSECURITY_STATE::BTM_SEC_STATE_IDLE && p_dev_rec->sec_rec.sec_state != BTM_SEC_STATE_LE_ENCRYPTING) { p_dev_rec->sec_rec.sec_state != tSECURITY_STATE::BTM_SEC_STATE_LE_ENCRYPTING) { log::info("No immediate action taken in busy state: {}", log::info("No immediate action taken in busy state: {}", security_state_text(p_dev_rec->sec_rec.sec_state)); security_state_text(p_dev_rec->sec_rec.sec_state)); return (BTM_CMD_STARTED); return (BTM_CMD_STARTED); Loading Loading @@ -4702,7 +4708,7 @@ tBTM_STATUS btm_sec_execute_procedure(tBTM_SEC_DEV_REC* p_dev_rec) { log::verbose("Security Manager: Start encryption"); log::verbose("Security Manager: Start encryption"); btsnd_hcic_set_conn_encrypt(p_dev_rec->hci_handle, true); btsnd_hcic_set_conn_encrypt(p_dev_rec->hci_handle, true); p_dev_rec->sec_rec.sec_state = BTM_SEC_STATE_ENCRYPTING; p_dev_rec->sec_rec.sec_state = tSECURITY_STATE::BTM_SEC_STATE_ENCRYPTING; return (BTM_CMD_STARTED); return (BTM_CMD_STARTED); } else { } else { log::debug("Encryption not required"); log::debug("Encryption not required"); Loading Loading @@ -4749,7 +4755,7 @@ static bool btm_sec_start_get_name(tBTM_SEC_DEV_REC* p_dev_rec) { return false; return false; } } p_dev_rec->sec_rec.sec_state = BTM_SEC_STATE_GETTING_NAME; p_dev_rec->sec_rec.sec_state = tSECURITY_STATE::BTM_SEC_STATE_GETTING_NAME; /* 0 and NULL are as timeout and callback params because they are not used in /* 0 and NULL are as timeout and callback params because they are not used in * security get name case */ * security get name case */ Loading Loading @@ -4807,11 +4813,11 @@ static void btm_sec_auth_timer_timeout(void* data) { p_dev_rec->sec_rec.p_ref_data, p_dev_rec->sec_rec.p_ref_data, BTM_SUCCESS); BTM_SUCCESS); } } } else if (p_dev_rec->sec_rec.sec_state == BTM_SEC_STATE_AUTHENTICATING) { } else if (p_dev_rec->sec_rec.sec_state == tSECURITY_STATE::BTM_SEC_STATE_AUTHENTICATING) { log::info("device is in the process of authenticating"); log::info("device is in the process of authenticating"); } else { } else { log::info("starting authentication"); log::info("starting authentication"); p_dev_rec->sec_rec.sec_state = BTM_SEC_STATE_AUTHENTICATING; p_dev_rec->sec_rec.sec_state = tSECURITY_STATE::BTM_SEC_STATE_AUTHENTICATING; btsnd_hcic_auth_request(p_dev_rec->hci_handle); btsnd_hcic_auth_request(p_dev_rec->hci_handle); } } } } Loading
system/stack/btm/security_device_record.h +25 −27 Original line number Original line Diff line number Diff line Loading @@ -154,7 +154,7 @@ enum : uint16_t { BTM_SEC_16_DIGIT_PIN_AUTHED = 0x4000, BTM_SEC_16_DIGIT_PIN_AUTHED = 0x4000, }; }; typedef enum : uint8_t { enum class tSECURITY_STATE : uint8_t { BTM_SEC_STATE_IDLE = 0, BTM_SEC_STATE_IDLE = 0, BTM_SEC_STATE_AUTHENTICATING = 1, BTM_SEC_STATE_AUTHENTICATING = 1, BTM_SEC_STATE_ENCRYPTING = 2, BTM_SEC_STATE_ENCRYPTING = 2, Loading @@ -169,23 +169,23 @@ typedef enum : uint8_t { BTM_SEC_STATE_DISCONNECTING_BLE = 8, BTM_SEC_STATE_DISCONNECTING_BLE = 8, BTM_SEC_STATE_DISCONNECTING_BOTH = 9, BTM_SEC_STATE_DISCONNECTING_BOTH = 9, BTM_SEC_STATE_LE_ENCRYPTING = 10, BTM_SEC_STATE_LE_ENCRYPTING = 10, } tSECURITY_STATE; }; static inline std::string security_state_text(const tSECURITY_STATE& state) { static inline std::string security_state_text(const tSECURITY_STATE& state) { switch (state) { switch (state) { CASE_RETURN_TEXT(BTM_SEC_STATE_IDLE); CASE_RETURN_STRING(tSECURITY_STATE::BTM_SEC_STATE_IDLE); CASE_RETURN_TEXT(BTM_SEC_STATE_AUTHENTICATING); CASE_RETURN_STRING(tSECURITY_STATE::BTM_SEC_STATE_AUTHENTICATING); CASE_RETURN_TEXT(BTM_SEC_STATE_ENCRYPTING); CASE_RETURN_STRING(tSECURITY_STATE::BTM_SEC_STATE_ENCRYPTING); CASE_RETURN_TEXT(BTM_SEC_STATE_GETTING_NAME); CASE_RETURN_STRING(tSECURITY_STATE::BTM_SEC_STATE_GETTING_NAME); CASE_RETURN_TEXT(BTM_SEC_STATE_AUTHORIZING); CASE_RETURN_STRING(tSECURITY_STATE::BTM_SEC_STATE_AUTHORIZING); CASE_RETURN_TEXT(BTM_SEC_STATE_SWITCHING_ROLE); CASE_RETURN_STRING(tSECURITY_STATE::BTM_SEC_STATE_SWITCHING_ROLE); CASE_RETURN_TEXT(BTM_SEC_STATE_DISCONNECTING); CASE_RETURN_STRING(tSECURITY_STATE::BTM_SEC_STATE_DISCONNECTING); CASE_RETURN_TEXT(BTM_SEC_STATE_DELAY_FOR_ENC); CASE_RETURN_STRING(tSECURITY_STATE::BTM_SEC_STATE_DELAY_FOR_ENC); CASE_RETURN_TEXT(BTM_SEC_STATE_DISCONNECTING_BLE); CASE_RETURN_STRING(tSECURITY_STATE::BTM_SEC_STATE_DISCONNECTING_BLE); CASE_RETURN_TEXT(BTM_SEC_STATE_DISCONNECTING_BOTH); CASE_RETURN_STRING(tSECURITY_STATE::BTM_SEC_STATE_DISCONNECTING_BOTH); CASE_RETURN_TEXT(BTM_SEC_STATE_LE_ENCRYPTING); CASE_RETURN_STRING(tSECURITY_STATE::BTM_SEC_STATE_LE_ENCRYPTING); default: default: return base::StringPrintf("UNKNOWN[%hhu]", state); RETURN_UNKNOWN_TYPE_STRING(tSECURITY_STATE, state); } } } } Loading Loading @@ -304,42 +304,40 @@ struct tBTM_SEC_REC { sec_flags &= ~BTM_SEC_16_DIGIT_PIN_AUTHED; sec_flags &= ~BTM_SEC_16_DIGIT_PIN_AUTHED; } } bool is_security_state_idle() const { bool is_security_state_idle() const { return sec_state == tSECURITY_STATE::BTM_SEC_STATE_IDLE; } return sec_state == BTM_SEC_STATE_IDLE; } bool is_security_state_authenticating() const { bool is_security_state_authenticating() const { return sec_state == BTM_SEC_STATE_AUTHENTICATING; return sec_state == tSECURITY_STATE::BTM_SEC_STATE_AUTHENTICATING; } } bool is_security_state_bredr_encrypting() const { bool is_security_state_bredr_encrypting() const { return sec_state == BTM_SEC_STATE_ENCRYPTING; return sec_state == tSECURITY_STATE::BTM_SEC_STATE_ENCRYPTING; } } bool is_security_state_le_encrypting() const { bool is_security_state_le_encrypting() const { return sec_state == BTM_SEC_STATE_LE_ENCRYPTING; return sec_state == tSECURITY_STATE::BTM_SEC_STATE_LE_ENCRYPTING; } } bool is_security_state_encrypting() const { bool is_security_state_encrypting() const { return (is_security_state_bredr_encrypting() || return (is_security_state_bredr_encrypting() || is_security_state_le_encrypting()); is_security_state_le_encrypting()); } } bool is_security_state_getting_name() const { bool is_security_state_getting_name() const { return sec_state == BTM_SEC_STATE_GETTING_NAME; return sec_state == tSECURITY_STATE::BTM_SEC_STATE_GETTING_NAME; } } bool is_security_state_authorizing() const { bool is_security_state_authorizing() const { return sec_state == BTM_SEC_STATE_AUTHORIZING; return sec_state == tSECURITY_STATE::BTM_SEC_STATE_AUTHORIZING; } } bool is_security_state_switching_role() const { bool is_security_state_switching_role() const { return sec_state == BTM_SEC_STATE_SWITCHING_ROLE; return sec_state == tSECURITY_STATE::BTM_SEC_STATE_SWITCHING_ROLE; } } bool is_security_state_disconnecting() const { bool is_security_state_disconnecting() const { return sec_state == BTM_SEC_STATE_DISCONNECTING; return sec_state == tSECURITY_STATE::BTM_SEC_STATE_DISCONNECTING; } } bool is_security_state_wait_for_encryption() const { bool is_security_state_wait_for_encryption() const { return sec_state == BTM_SEC_STATE_DELAY_FOR_ENC; return sec_state == tSECURITY_STATE::BTM_SEC_STATE_DELAY_FOR_ENC; } } bool is_security_state_ble_disconnecting() const { bool is_security_state_ble_disconnecting() const { return sec_state == BTM_SEC_STATE_DISCONNECTING_BLE; return sec_state == tSECURITY_STATE::BTM_SEC_STATE_DISCONNECTING_BLE; } } bool is_security_state_br_edr_and_ble() const { bool is_security_state_br_edr_and_ble() const { return sec_state == BTM_SEC_STATE_DISCONNECTING_BOTH; return sec_state == tSECURITY_STATE::BTM_SEC_STATE_DISCONNECTING_BOTH; } } bool is_bond_type_unknown() const { return bond_type == BOND_TYPE_UNKNOWN; } bool is_bond_type_unknown() const { return bond_type == BOND_TYPE_UNKNOWN; } Loading