OSDN Git Service

Move btm_sec_set_peer_sec_caps to btm_sec
authorHansong Zhang <hsz@google.com>
Fri, 30 Oct 2020 03:37:13 +0000 (20:37 -0700)
committerHansong Zhang <hsz@google.com>
Thu, 5 Nov 2020 02:03:01 +0000 (18:03 -0800)
Bug: 159815595
Tag: #refactor
Test: compile & verify basic functions working
Change-Id: I1d05c78b08deeb7120fc0eaced20384e2f438e79

stack/acl/btm_acl.cc
stack/btm/btm_sec.cc
stack/btm/btm_sec.h

index e9c183f..9bef302 100644 (file)
@@ -125,9 +125,6 @@ static void btm_read_rssi_timeout(void* data);
 static void btm_read_tx_power_timeout(void* data);
 static void btm_process_remote_ext_features(tACL_CONN* p_acl_cb,
                                             uint8_t num_read_pages);
-static void btm_sec_set_peer_sec_caps(uint16_t hci_handle, bool ssp_supported,
-                                      bool sc_supported,
-                                      bool hci_role_switch_supported);
 static bool acl_is_role_central(const RawAddress& bda, tBT_TRANSPORT transport);
 static void btm_set_link_policy(tACL_CONN* conn, uint16_t policy);
 static bool btm_ble_get_acl_remote_addr(const tBTM_SEC_DEV_REC& p_dev_rec,
@@ -2513,60 +2510,6 @@ void btm_ble_refresh_local_resolvable_private_addr(
   }
 }
 
-/*******************************************************************************
- *
- * Function         btm_sec_set_peer_sec_caps
- *
- * Description      This function is called to set sm4 and rmt_sec_caps fields
- *                  based on the available peer device features.
- *
- * Returns          void
- *
- ******************************************************************************/
-void btm_sec_set_peer_sec_caps(uint16_t hci_handle, bool ssp_supported,
-                               bool sc_supported,
-                               bool hci_role_switch_supported) {
-  tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev_by_handle(hci_handle);
-  if (p_dev_rec == nullptr) return;
-
-  p_dev_rec->remote_feature_received = true;
-  p_dev_rec->remote_supports_hci_role_switch = hci_role_switch_supported;
-
-  uint8_t req_pend = (p_dev_rec->sm4 & BTM_SM4_REQ_PEND);
-
-  if (!(p_dev_rec->sec_flags & BTM_SEC_NAME_KNOWN) ||
-      p_dev_rec->is_originator) {
-    uint8_t status = btm_sec_execute_procedure(p_dev_rec);
-    if (status != BTM_CMD_STARTED) {
-      LOG_WARN("Security procedure not started! status:%s",
-               hci_error_code_text(status).c_str());
-      btm_sec_dev_rec_cback_event(p_dev_rec, status, false);
-    }
-  }
-
-  /* Store the Peer Security Capabilites (in SM4 and rmt_sec_caps) */
-  if ((btm_cb.security_mode == BTM_SEC_MODE_SP ||
-       btm_cb.security_mode == BTM_SEC_MODE_SC) &&
-      ssp_supported) {
-    p_dev_rec->sm4 = BTM_SM4_TRUE;
-    p_dev_rec->remote_supports_secure_connections = sc_supported;
-  } else {
-    p_dev_rec->sm4 = BTM_SM4_KNOWN;
-    p_dev_rec->remote_supports_secure_connections = false;
-  }
-
-  if (p_dev_rec->remote_features_needed) {
-    LOG_DEBUG("Now device in SC Only mode, waiting for peer remote features!");
-    btm_io_capabilities_req(p_dev_rec->bd_addr);
-    p_dev_rec->remote_features_needed = false;
-  }
-
-  if (req_pend) {
-    /* Request for remaining Security Features (if any) */
-    l2cu_resubmit_pending_sec_req(&p_dev_rec->bd_addr);
-  }
-}
-
 bool sco_peer_supports_esco_2m_phy(uint16_t hci_handle) {
   tACL_CONN* p_acl = internal_.acl_get_connection_from_handle(hci_handle);
   if (p_acl == nullptr) {
index 3232f97..fb8db9e 100644 (file)
@@ -4772,3 +4772,57 @@ static bool btm_sec_use_smp_br_chnl(tBTM_SEC_DEV_REC* p_dev_rec) {
 
   return true;
 }
+
+/*******************************************************************************
+ *
+ * Function         btm_sec_set_peer_sec_caps
+ *
+ * Description      This function is called to set sm4 and rmt_sec_caps fields
+ *                  based on the available peer device features.
+ *
+ * Returns          void
+ *
+ ******************************************************************************/
+void btm_sec_set_peer_sec_caps(uint16_t hci_handle, bool ssp_supported,
+                               bool sc_supported,
+                               bool hci_role_switch_supported) {
+  tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev_by_handle(hci_handle);
+  if (p_dev_rec == nullptr) return;
+
+  p_dev_rec->remote_feature_received = true;
+  p_dev_rec->remote_supports_hci_role_switch = hci_role_switch_supported;
+
+  uint8_t req_pend = (p_dev_rec->sm4 & BTM_SM4_REQ_PEND);
+
+  if (!(p_dev_rec->sec_flags & BTM_SEC_NAME_KNOWN) ||
+      p_dev_rec->is_originator) {
+    uint8_t status = btm_sec_execute_procedure(p_dev_rec);
+    if (status != BTM_CMD_STARTED) {
+      LOG_WARN("Security procedure not started! status:%s",
+               hci_error_code_text(status).c_str());
+      btm_sec_dev_rec_cback_event(p_dev_rec, status, false);
+    }
+  }
+
+  /* Store the Peer Security Capabilites (in SM4 and rmt_sec_caps) */
+  if ((btm_cb.security_mode == BTM_SEC_MODE_SP ||
+       btm_cb.security_mode == BTM_SEC_MODE_SC) &&
+      ssp_supported) {
+    p_dev_rec->sm4 = BTM_SM4_TRUE;
+    p_dev_rec->remote_supports_secure_connections = sc_supported;
+  } else {
+    p_dev_rec->sm4 = BTM_SM4_KNOWN;
+    p_dev_rec->remote_supports_secure_connections = false;
+  }
+
+  if (p_dev_rec->remote_features_needed) {
+    LOG_DEBUG("Now device in SC Only mode, waiting for peer remote features!");
+    btm_io_capabilities_req(p_dev_rec->bd_addr);
+    p_dev_rec->remote_features_needed = false;
+  }
+
+  if (req_pend) {
+    /* Request for remaining Security Features (if any) */
+    l2cu_resubmit_pending_sec_req(&p_dev_rec->bd_addr);
+  }
+}
index d230b92..0e65581 100644 (file)
@@ -764,3 +764,17 @@ void btm_sec_clear_ble_keys(tBTM_SEC_DEV_REC* p_dev_rec);
  *
  ******************************************************************************/
 bool btm_sec_is_a_bonded_dev(const RawAddress& bda);
+
+/*******************************************************************************
+ *
+ * Function         btm_sec_set_peer_sec_caps
+ *
+ * Description      This function is called to set sm4 and rmt_sec_caps fields
+ *                  based on the available peer device features.
+ *
+ * Returns          void
+ *
+ ******************************************************************************/
+void btm_sec_set_peer_sec_caps(uint16_t hci_handle, bool ssp_supported,
+                               bool sc_supported,
+                               bool hci_role_switch_supported);
\ No newline at end of file