OSDN Git Service

L2cap shim flag update
authorHansong Zhang <hsz@google.com>
Wed, 18 Nov 2020 02:38:21 +0000 (18:38 -0800)
committerHansong Zhang <hsz@google.com>
Sat, 21 Nov 2020 00:46:14 +0000 (16:46 -0800)
Tag: #gd-refactor
Bug: 141555841
Test: cert/run --host
Test: Pair and connect with a headset
Change-Id: Iccb704e6d87f6758c4af7cd9148b88d00751b1c2

main/shim/hci_layer.cc
stack/btm/btm_sec.cc
stack/gatt/connection_manager.cc
stack/l2cap/l2c_ble.cc
stack/l2cap/l2c_link.cc
stack/l2cap/l2c_utils.cc
stack/test/gatt_connection_manager_test.cc

index ee341f8..9a8b11b 100644 (file)
@@ -224,10 +224,11 @@ static bool event_already_registered_in_hci_layer(
     case bluetooth::hci::EventCode::MAX_SLOTS_CHANGE:
     case bluetooth::hci::EventCode::VENDOR_SPECIFIC:
       return bluetooth::shim::is_gd_hci_enabled();
-    case bluetooth::hci::EventCode::LE_META_EVENT:
     case bluetooth::hci::EventCode::DISCONNECTION_COMPLETE:
     case bluetooth::hci::EventCode::READ_REMOTE_VERSION_INFORMATION_COMPLETE:
-      return bluetooth::shim::is_gd_acl_enabled();
+    case bluetooth::hci::EventCode::LE_META_EVENT:
+      return bluetooth::shim::is_gd_acl_enabled() ||
+             bluetooth::shim::is_gd_l2cap_enabled();
     default:
       return false;
   }
@@ -237,7 +238,8 @@ static bool event_already_registered_in_controller_layer(
     bluetooth::hci::EventCode event_code) {
   switch (event_code) {
     case bluetooth::hci::EventCode::NUMBER_OF_COMPLETED_PACKETS:
-      return bluetooth::shim::is_gd_acl_enabled();
+      return bluetooth::shim::is_gd_acl_enabled() ||
+             bluetooth::shim::is_gd_l2cap_enabled();
     default:
       return false;
   }
@@ -247,7 +249,8 @@ static bool event_already_registered_in_acl_layer(
     bluetooth::hci::EventCode event_code) {
   for (auto event : bluetooth::hci::AclConnectionEvents) {
     if (event == event_code) {
-      return bluetooth::shim::is_gd_acl_enabled();
+      return bluetooth::shim::is_gd_acl_enabled() ||
+             bluetooth::shim::is_gd_l2cap_enabled();
     }
   }
   return false;
@@ -263,11 +266,11 @@ static bool subevent_already_registered_in_le_hci_layer(
     case bluetooth::hci::SubeventCode::PHY_UPDATE_COMPLETE:
     case bluetooth::hci::SubeventCode::REMOTE_CONNECTION_PARAMETER_REQUEST:
       return bluetooth::shim::is_gd_acl_enabled() ||
-             bluetooth::shim::is_gd_advertising_enabled();
+             bluetooth::shim::is_gd_l2cap_enabled();
     case bluetooth::hci::SubeventCode::ADVERTISING_SET_TERMINATED:
     case bluetooth::hci::SubeventCode::SCAN_REQUEST_RECEIVED:
-      return bluetooth::shim::is_gd_advertising_enabled();
-    case bluetooth::hci::SubeventCode::SCAN_TIMEOUT:
+      return bluetooth::shim::is_gd_acl_enabled() ||
+             bluetooth::shim::is_gd_l2cap_enabled();
     case bluetooth::hci::SubeventCode::ADVERTISING_REPORT:
     case bluetooth::hci::SubeventCode::DIRECTED_ADVERTISING_REPORT:
     case bluetooth::hci::SubeventCode::EXTENDED_ADVERTISING_REPORT:
@@ -278,6 +281,7 @@ static bool subevent_already_registered_in_le_hci_layer(
     case bluetooth::hci::SubeventCode::READ_REMOTE_FEATURES_COMPLETE:
     case bluetooth::hci::SubeventCode::READ_LOCAL_P256_PUBLIC_KEY_COMPLETE:
     case bluetooth::hci::SubeventCode::GENERATE_DHKEY_COMPLETE:
+    case bluetooth::hci::SubeventCode::SCAN_TIMEOUT:
     case bluetooth::hci::SubeventCode::CHANNEL_SELECTION_ALGORITHM:
     case bluetooth::hci::SubeventCode::CONNECTIONLESS_IQ_REPORT:
     case bluetooth::hci::SubeventCode::CONNECTION_IQ_REPORT:
@@ -582,7 +586,8 @@ void bluetooth::shim::hci_on_reset_complete() {
 
   // if gd advertising enabled, hci_queue_end will be register in
   // AclManager::impl::Start
-  if (!bluetooth::shim::is_gd_advertising_enabled()) {
+  if (!bluetooth::shim::is_gd_advertising_enabled() &&
+      !bluetooth::shim::is_gd_l2cap_enabled()) {
     hci_queue_end->RegisterDequeue(bluetooth::shim::GetGdShimHandler(),
                                    bluetooth::common::Bind(acl_data_callback));
   }
@@ -599,7 +604,8 @@ void bluetooth::shim::hci_on_shutting_down() {
     pending_data = nullptr;
   }
   if (hci_queue_end != nullptr) {
-    if (!bluetooth::shim::is_gd_advertising_enabled()) {
+    if (!bluetooth::shim::is_gd_advertising_enabled() &&
+        !bluetooth::shim::is_gd_l2cap_enabled()) {
       hci_queue_end->UnregisterDequeue();
     }
     for (uint8_t event_code_raw = 0; event_code_raw < 0xFF; event_code_raw++) {
index 9e37a0f..abead76 100644 (file)
@@ -1077,7 +1077,7 @@ tBTM_STATUS BTM_SetEncryption(const RawAddress& bd_addr,
       p_dev_rec->security_required, p_dev_rec, p_callback);
 
   if (transport == BT_TRANSPORT_LE) {
-    if (BTM_IsAclConnectionUp(bd_addr, transport)) {
+    if (BTM_IsAclConnectionUp(bd_addr, BT_TRANSPORT_LE)) {
       rc = btm_ble_set_encryption(bd_addr, sec_act,
                                   acl_link_role(bd_addr, transport));
     } else {
index 967bf0b..2d71d63 100644 (file)
@@ -92,7 +92,7 @@ std::set<tAPP_ID> get_apps_connecting_to(const RawAddress& address) {
 /** Add a device from the background connection list.  Returns true if device
  * added to the list, or already in list, false otherwise */
 bool background_connect_add(uint8_t app_id, const RawAddress& address) {
-  if (bluetooth::shim::is_gd_shim_enabled()) {
+  if (bluetooth::shim::is_gd_l2cap_enabled()) {
     return L2CA_ConnectFixedChnl(L2CAP_ATT_CID, address);
   }
 
@@ -205,7 +205,7 @@ void wl_direct_connect_timeout_cb(uint8_t app_id, const RawAddress& address) {
 /** Add a device to the direcgt connection list.  Returns true if device
  * added to the list, false otherwise */
 bool direct_connect_add(uint8_t app_id, const RawAddress& address) {
-  if (bluetooth::shim::is_gd_shim_enabled()) {
+  if (bluetooth::shim::is_gd_l2cap_enabled()) {
     return L2CA_ConnectFixedChnl(L2CAP_ATT_CID, address);
   }
 
index 6bd8fb7..19591e3 100644 (file)
 
 using base::StringPrintf;
 
-tL2CAP_LE_RESULT_CODE btm_ble_start_sec_check(const RawAddress& bd_addr,
-                                              uint16_t psm, bool is_originator,
-                                              tBTM_SEC_CALLBACK* p_callback,
-                                              void* p_ref_data);
-
 static void l2cble_start_conn_update(tL2C_LCB* p_lcb);
 
 /*******************************************************************************
@@ -1127,6 +1122,10 @@ bool l2cble_create_conn(tL2C_LCB* p_lcb) {
  *
  ******************************************************************************/
 void l2c_link_processs_ble_num_bufs(uint16_t num_lm_ble_bufs) {
+  if (bluetooth::shim::is_gd_l2cap_enabled()) {
+    return;
+  }
+
   if (num_lm_ble_bufs == 0) {
     num_lm_ble_bufs = L2C_DEF_NUM_BLE_BUF_SHARED;
     l2cb.num_lm_acl_bufs -= L2C_DEF_NUM_BLE_BUF_SHARED;
index e3f7364..5decfce 100644 (file)
@@ -322,7 +322,6 @@ void l2c_link_sec_comp2(const RawAddress& p_bda,
  ******************************************************************************/
 bool l2c_link_hci_disc_comp(uint16_t handle, uint8_t reason) {
   if (bluetooth::shim::is_gd_l2cap_enabled()) {
-    btm_acl_removed(handle);
     return false;
   }
 
@@ -735,6 +734,11 @@ void l2c_link_adjust_chnl_allocation(void) {
 }
 
 void l2c_link_init() {
+  if (bluetooth::shim::is_gd_l2cap_enabled()) {
+    // GD L2cap gets this info through GD ACL
+    return;
+  }
+
   const controller_t* controller = controller_get_interface();
 
   l2cb.num_lm_acl_bufs = controller->get_acl_buffer_count_classic();
@@ -1330,6 +1334,11 @@ void l2c_link_segments_xmitted(BT_HDR* p_msg) {
 }
 
 tBTM_STATUS l2cu_ConnectAclForSecurity(const RawAddress& bd_addr) {
+  if (bluetooth::shim::is_gd_l2cap_enabled()) {
+    bluetooth::shim::L2CA_ConnectForSecurity(bd_addr);
+    return BTM_SUCCESS;
+  }
+
   tL2C_LCB* p_lcb = l2cu_find_lcb_by_bd_addr(bd_addr, BT_TRANSPORT_BR_EDR);
   if (p_lcb && (p_lcb->link_state == LST_CONNECTED ||
                 p_lcb->link_state == LST_CONNECTING)) {
index 90069ea..bef8a65 100644 (file)
@@ -117,6 +117,11 @@ void l2cu_set_lcb_handle(struct t_l2c_linkcb& p_lcb, uint16_t handle) {
  *
  ******************************************************************************/
 void l2cu_update_lcb_4_bonding(const RawAddress& p_bd_addr, bool is_bonding) {
+  if (bluetooth::shim::is_gd_l2cap_enabled()) {
+    bluetooth::shim::L2CA_SetBondingState(p_bd_addr, is_bonding);
+    return;
+  }
+
   tL2C_LCB* p_lcb = l2cu_find_lcb_by_bd_addr(p_bd_addr, BT_TRANSPORT_BR_EDR);
 
   if (p_lcb) {
@@ -2019,6 +2024,10 @@ void l2cu_process_our_cfg_rsp(tL2C_CCB* p_ccb, tL2CAP_CFG_INFO* p_cfg) {
  *
  ******************************************************************************/
 void l2cu_device_reset(void) {
+  if (bluetooth::shim::is_gd_l2cap_enabled()) {
+    return;
+  }
+
   int xx;
   tL2C_LCB* p_lcb = &l2cb.lcb_pool[0];
 
@@ -2265,6 +2274,10 @@ bool l2cu_set_acl_priority(const RawAddress& bd_addr, tL2CAP_PRIORITY priority,
  *
  ******************************************************************************/
 void l2cu_set_non_flushable_pbf(bool is_supported) {
+  if (bluetooth::shim::is_gd_l2cap_enabled()) {
+    return;
+  }
+
   if (is_supported)
     l2cb.non_flushable_pbf =
         (L2CAP_PKT_START_NON_FLUSHABLE << L2CAP_PKT_TYPE_SHIFT);
index 63632d8..b5d2864 100644 (file)
@@ -62,7 +62,7 @@ void BTM_SetLeConnectionModeToSlow() {
 
 namespace bluetooth {
 namespace shim {
-bool is_gd_shim_enabled() { return false; }
+bool is_gd_l2cap_enabled() { return false; }
 }  // namespace shim
 }  // namespace bluetooth