summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Hui Peng <phui@google.com> 2023-07-11 01:27:26 -0700
committer Hui Peng <phui@google.com> 2023-07-11 18:38:29 +0000
commitf9bae4998dfaf548d3c376f12a96268a68774f64 (patch)
tree0e826cc528325d2847e36c6c3f92a5d8ec03b251
parent421d0fb87bae1afb350e1905e7bed165159f97c1 (diff)
Remove dependency on btm_cb in smp
Bug: 277282212 Test: mma packages/modules/Bluetooth Change-Id: I0fde3403ee091458514faab9c2a882b53dc4c9da
-rw-r--r--system/btif/src/stack_manager.cc2
-rw-r--r--system/stack/btm/btm_client_interface.cc1
-rw-r--r--system/stack/btm/btm_sec.cc12
-rw-r--r--system/stack/btm/btm_sec.h10
-rw-r--r--system/stack/fuzzers/smp_fuzzer.cc2
-rw-r--r--system/stack/include/btm_client_interface.h1
-rw-r--r--system/stack/include/smp_api.h2
-rw-r--r--system/stack/smp/smp_act.cc6
-rw-r--r--system/stack/smp/smp_api.cc4
-rw-r--r--system/stack/smp/smp_int.h1
-rw-r--r--system/stack/smp/smp_keys.cc8
-rw-r--r--system/stack/smp/smp_utils.cc2
-rw-r--r--system/test/mock/mock_stack_smp_api.cc2
13 files changed, 39 insertions, 14 deletions
diff --git a/system/btif/src/stack_manager.cc b/system/btif/src/stack_manager.cc
index 14e557b133..86ac66a8a7 100644
--- a/system/btif/src/stack_manager.cc
+++ b/system/btif/src/stack_manager.cc
@@ -317,7 +317,7 @@ static void event_start_up_stack(bluetooth::core::CoreInterface* interface,
l2c_init();
sdp_init();
gatt_init();
- SMP_Init();
+ SMP_Init(get_btm_client_interface().security.BTM_GetSecurityMode());
get_btm_client_interface().lifecycle.btm_ble_init();
RFCOMM_Init();
diff --git a/system/stack/btm/btm_client_interface.cc b/system/stack/btm/btm_client_interface.cc
index 576bd0848b..cf836da771 100644
--- a/system/stack/btm/btm_client_interface.cc
+++ b/system/stack/btm/btm_client_interface.cc
@@ -129,6 +129,7 @@ struct btm_client_interface_t btm_client_interface = {
.BTM_SecIsSecurityPending = BTM_SecIsSecurityPending,
.BTM_IsLinkKeyKnown = BTM_IsLinkKeyKnown,
.BTM_BleSirkConfirmDeviceReply = BTM_BleSirkConfirmDeviceReply,
+ .BTM_GetSecurityMode = BTM_GetSecurityMode,
},
.ble =
diff --git a/system/stack/btm/btm_sec.cc b/system/stack/btm/btm_sec.cc
index 2a6f70414f..cebab2b5a5 100644
--- a/system/stack/btm/btm_sec.cc
+++ b/system/stack/btm/btm_sec.cc
@@ -1494,6 +1494,18 @@ tBT_DEVICE_TYPE BTM_GetPeerDeviceTypeFromFeatures(const RawAddress& bd_addr) {
return BT_DEVICE_TYPE_BREDR;
}
+/*******************************************************************************
+ *
+ * Function BTM_GetInitialSecurityMode
+ *
+ * Description This function is called to retrieve the configured
+ * security mode.
+ *
+ ******************************************************************************/
+uint8_t BTM_GetSecurityMode() {
+ return btm_cb.security_mode;
+}
+
/************************************************************************
* I N T E R N A L F U N C T I O N S
************************************************************************/
diff --git a/system/stack/btm/btm_sec.h b/system/stack/btm/btm_sec.h
index 52a0c3f1ea..7f66116530 100644
--- a/system/stack/btm/btm_sec.h
+++ b/system/stack/btm/btm_sec.h
@@ -382,6 +382,16 @@ bool BTM_PeerSupportsSecureConnections(const RawAddress& bd_addr);
/*******************************************************************************
*
+ * Function BTM_GetInitialSecurityMode
+ *
+ * Description This function is called to retrieve the configured
+ * security mode.
+ *
+ ******************************************************************************/
+uint8_t BTM_GetSecurityMode();
+
+/*******************************************************************************
+ *
* Function btm_sec_l2cap_access_req
*
* Description This function is called by the L2CAP to grant permission to
diff --git a/system/stack/fuzzers/smp_fuzzer.cc b/system/stack/fuzzers/smp_fuzzer.cc
index ebb38d736c..1c8dd2b373 100644
--- a/system/stack/fuzzers/smp_fuzzer.cc
+++ b/system/stack/fuzzers/smp_fuzzer.cc
@@ -185,7 +185,7 @@ void Fuzz(const uint8_t* data, size_t size) {
btm_cb = tBTM_CB();
- SMP_Init();
+ SMP_Init(BTM_SEC_MODE_SP);
SMP_Register(smp_callback);
SMP_SetTraceLevel(BT_TRACE_LEVEL_DEBUG);
SMP_ClearLocScOobData();
diff --git a/system/stack/include/btm_client_interface.h b/system/stack/include/btm_client_interface.h
index 8c195345a4..e2326e853b 100644
--- a/system/stack/include/btm_client_interface.h
+++ b/system/stack/include/btm_client_interface.h
@@ -162,6 +162,7 @@ struct btm_client_interface_t {
tBT_TRANSPORT transport);
void (*BTM_BleSirkConfirmDeviceReply)(const RawAddress& bd_addr,
uint8_t res);
+ uint8_t (*BTM_GetSecurityMode)();
} security;
struct {
diff --git a/system/stack/include/smp_api.h b/system/stack/include/smp_api.h
index 0a56f19c91..7ed93c6568 100644
--- a/system/stack/include/smp_api.h
+++ b/system/stack/include/smp_api.h
@@ -45,7 +45,7 @@
* Returns void
*
******************************************************************************/
-void SMP_Init(void);
+void SMP_Init(uint8_t init_security_mode);
/*******************************************************************************
*
diff --git a/system/stack/smp/smp_act.cc b/system/stack/smp/smp_act.cc
index 35895c50a4..2ceba77f18 100644
--- a/system/stack/smp/smp_act.cc
+++ b/system/stack/smp/smp_act.cc
@@ -39,8 +39,6 @@
#include "stack/smp/smp_int.h"
#include "types/raw_address.h"
-extern tBTM_CB btm_cb;
-
namespace {
constexpr char kBtmLogTag[] = "SMP";
}
@@ -178,7 +176,7 @@ void smp_send_app_cback(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) {
p_cb->loc_enc_size, p_cb->local_i_key, p_cb->local_r_key);
p_cb->secure_connections_only_mode_required =
- (btm_cb.security_mode == BTM_SEC_MODE_SC) ? true : false;
+ (p_cb->init_security_mode == BTM_SEC_MODE_SC) ? true : false;
/* just for PTS, force SC bit */
if (p_cb->secure_connections_only_mode_required) {
p_cb->loc_auth_req |= SMP_SC_SUPPORT_BIT;
@@ -482,7 +480,7 @@ void smp_proc_sec_req(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) {
case BTM_BLE_SEC_REQ_ACT_PAIR:
p_cb->secure_connections_only_mode_required =
- (btm_cb.security_mode == BTM_SEC_MODE_SC) ? true : false;
+ (p_cb->init_security_mode == BTM_SEC_MODE_SC) ? true : false;
/* respond to non SC pairing request as failure in SC only mode */
if (p_cb->secure_connections_only_mode_required &&
diff --git a/system/stack/smp/smp_api.cc b/system/stack/smp/smp_api.cc
index 3362bc01c8..b274fc5aa2 100644
--- a/system/stack/smp/smp_api.cc
+++ b/system/stack/smp/smp_api.cc
@@ -49,12 +49,14 @@
* Returns void
*
******************************************************************************/
-void SMP_Init(void) {
+void SMP_Init(uint8_t init_security_mode) {
if (bluetooth::shim::is_gd_shim_enabled()) {
LOG(INFO) << "Skipping legacy SMP_Init because GD is enabled";
return;
}
+ smp_cb.init_security_mode = init_security_mode;
+
memset(&smp_cb, 0, sizeof(tSMP_CB));
smp_cb.smp_rsp_timer_ent = alarm_new("smp.smp_rsp_timer_ent");
smp_cb.delayed_auth_timer_ent = alarm_new("smp.delayed_auth_timer_ent");
diff --git a/system/stack/smp/smp_int.h b/system/stack/smp/smp_int.h
index 3a3fe65fb9..6032c700b5 100644
--- a/system/stack/smp/smp_int.h
+++ b/system/stack/smp/smp_int.h
@@ -234,6 +234,7 @@ typedef struct {
/* SMP control block */
typedef struct {
+ uint8_t init_security_mode{0};
tSMP_CALLBACK* p_callback;
alarm_t* smp_rsp_timer_ent;
uint8_t trace_level;
diff --git a/system/stack/smp/smp_keys.cc b/system/stack/smp/smp_keys.cc
index 809366ce1c..d3f6ca4d23 100644
--- a/system/stack/smp/smp_keys.cc
+++ b/system/stack/smp/smp_keys.cc
@@ -41,8 +41,6 @@
#include "stack/include/bt_octets.h"
#include "types/raw_address.h"
-extern tBTM_CB btm_cb; // TODO Remove
-
using base::Bind;
using crypto_toolbox::aes_128;
@@ -979,7 +977,7 @@ bool smp_calculate_link_key_from_long_term_key(tSMP_CB* p_cb) {
crypto_toolbox::ltk_to_link_key(p_cb->ltk, p_cb->key_derivation_h7_used);
uint8_t link_key_type;
- if (btm_cb.security_mode == BTM_SEC_MODE_SC) {
+ if (p_cb->init_security_mode == BTM_SEC_MODE_SC) {
/* Secure Connections Only Mode */
link_key_type = BTM_LKEY_TYPE_AUTH_COMB_P_256;
} else if (controller_get_interface()->supports_secure_connections()) {
@@ -988,7 +986,7 @@ bool smp_calculate_link_key_from_long_term_key(tSMP_CB* p_cb) {
link_key_type = BTM_LKEY_TYPE_AUTH_COMB_P_256;
else
link_key_type = BTM_LKEY_TYPE_UNAUTH_COMB_P_256;
- } else if (btm_cb.security_mode == BTM_SEC_MODE_SP) {
+ } else if (p_cb->init_security_mode == BTM_SEC_MODE_SP) {
/* BR/EDR transport is SSP capable */
if (p_cb->sec_level == SMP_SEC_AUTHENTICATED)
link_key_type = BTM_LKEY_TYPE_AUTH_COMB;
@@ -996,7 +994,7 @@ bool smp_calculate_link_key_from_long_term_key(tSMP_CB* p_cb) {
link_key_type = BTM_LKEY_TYPE_UNAUTH_COMB;
} else {
SMP_TRACE_ERROR("%s failed to update link_key. Sec Mode = %d, sm4 = 0x%02x",
- __func__, btm_cb.security_mode, p_dev_rec->sm4);
+ __func__, p_cb->init_security_mode, p_dev_rec->sm4);
return false;
}
diff --git a/system/stack/smp/smp_utils.cc b/system/stack/smp/smp_utils.cc
index 956066754b..12609f768d 100644
--- a/system/stack/smp/smp_utils.cc
+++ b/system/stack/smp/smp_utils.cc
@@ -882,6 +882,7 @@ void smp_xor_128(Octet16* a, const Octet16& b) {
void smp_cb_cleanup(tSMP_CB* p_cb) {
tSMP_CALLBACK* p_callback = p_cb->p_callback;
uint8_t trace_level = p_cb->trace_level;
+ uint8_t init_security_mode = p_cb->init_security_mode;
alarm_t* smp_rsp_timer_ent = p_cb->smp_rsp_timer_ent;
alarm_t* delayed_auth_timer_ent = p_cb->delayed_auth_timer_ent;
@@ -892,6 +893,7 @@ void smp_cb_cleanup(tSMP_CB* p_cb) {
memset(p_cb, 0, sizeof(tSMP_CB));
p_cb->p_callback = p_callback;
p_cb->trace_level = trace_level;
+ p_cb->init_security_mode = init_security_mode;
p_cb->smp_rsp_timer_ent = smp_rsp_timer_ent;
p_cb->delayed_auth_timer_ent = delayed_auth_timer_ent;
}
diff --git a/system/test/mock/mock_stack_smp_api.cc b/system/test/mock/mock_stack_smp_api.cc
index 74232f2c9d..ef2fea5294 100644
--- a/system/test/mock/mock_stack_smp_api.cc
+++ b/system/test/mock/mock_stack_smp_api.cc
@@ -66,7 +66,7 @@ uint8_t SMP_SetTraceLevel(uint8_t new_level) {
void SMP_ConfirmReply(const RawAddress& bd_addr, uint8_t res) {
inc_func_call_count(__func__);
}
-void SMP_Init(void) { inc_func_call_count(__func__); }
+void SMP_Init(uint8_t init_security_mode) { inc_func_call_count(__func__); }
void SMP_OobDataReply(const RawAddress& bd_addr, tSMP_STATUS res, uint8_t len,
uint8_t* p_data) {
inc_func_call_count(__func__);