OSDN Git Service

Add ACL shim event registration - with deps
authorChris Manton <cmanton@google.com>
Mon, 28 Sep 2020 20:15:06 +0000 (13:15 -0700)
committerChris Manton <cmanton@google.com>
Fri, 2 Oct 2020 15:22:54 +0000 (15:22 +0000)
Bug: 166280067
Tag: #refactor
Test: gd/cert/run --host
Test: ble paired 2 phones
Test: act.py -tc BleCocTest
Change-Id: I6494212c0f61d478792fc2948c12ae4187576cd1

main/shim/hci_layer.cc

index dff6cc7..7db8502 100644 (file)
@@ -161,14 +161,60 @@ bool is_valid_event_code(uint8_t event_code_raw) {
     case bluetooth::hci::EventCode::USER_PASSKEY_NOTIFICATION:
     case bluetooth::hci::EventCode::KEYPRESS_NOTIFICATION:
     case bluetooth::hci::EventCode::REMOTE_HOST_SUPPORTED_FEATURES_NOTIFICATION:
-    case bluetooth::hci::EventCode::LE_META_EVENT:
     case bluetooth::hci::EventCode::NUMBER_OF_COMPLETED_DATA_BLOCKS:
     case bluetooth::hci::EventCode::VENDOR_SPECIFIC:
       return true;
+    case bluetooth::hci::EventCode::LE_META_EVENT:  // Private to hci
+      return false;
   }
   return false;
 };
 
+bool is_valid_subevent_code(uint8_t subevent_code_raw) {
+  auto subevent_code =
+      static_cast<bluetooth::hci::SubeventCode>(subevent_code_raw);
+  switch (subevent_code) {
+    case bluetooth::hci::SubeventCode::CONNECTION_COMPLETE:
+    case bluetooth::hci::SubeventCode::CONNECTION_UPDATE_COMPLETE:
+    case bluetooth::hci::SubeventCode::DATA_LENGTH_CHANGE:
+    case bluetooth::hci::SubeventCode::ENHANCED_CONNECTION_COMPLETE:
+    case bluetooth::hci::SubeventCode::PHY_UPDATE_COMPLETE:
+    case bluetooth::hci::SubeventCode::READ_REMOTE_FEATURES_COMPLETE:
+    case bluetooth::hci::SubeventCode::REMOTE_CONNECTION_PARAMETER_REQUEST:
+    case bluetooth::hci::SubeventCode::READ_LOCAL_P256_PUBLIC_KEY_COMPLETE:
+    case bluetooth::hci::SubeventCode::GENERATE_DHKEY_COMPLETE:
+    case bluetooth::hci::SubeventCode::DIRECTED_ADVERTISING_REPORT:
+    case bluetooth::hci::SubeventCode::EXTENDED_ADVERTISING_REPORT:
+    case bluetooth::hci::SubeventCode::PERIODIC_ADVERTISING_SYNC_ESTABLISHED:
+    case bluetooth::hci::SubeventCode::PERIODIC_ADVERTISING_REPORT:
+    case bluetooth::hci::SubeventCode::PERIODIC_ADVERTISING_SYNC_LOST:
+    case bluetooth::hci::SubeventCode::SCAN_TIMEOUT:
+    case bluetooth::hci::SubeventCode::ADVERTISING_SET_TERMINATED:
+    case bluetooth::hci::SubeventCode::SCAN_REQUEST_RECEIVED:
+    case bluetooth::hci::SubeventCode::CHANNEL_SELECTION_ALGORITHM:
+    case bluetooth::hci::SubeventCode::CONNECTIONLESS_IQ_REPORT:
+    case bluetooth::hci::SubeventCode::CONNECTION_IQ_REPORT:
+    case bluetooth::hci::SubeventCode::CTE_REQUEST_FAILED:
+    case bluetooth::hci::SubeventCode::
+        PERIODIC_ADVERTISING_SYNC_TRANSFER_RECEIVED:
+    case bluetooth::hci::SubeventCode::CIS_ESTABLISHED:
+    case bluetooth::hci::SubeventCode::CIS_REQUEST:
+    case bluetooth::hci::SubeventCode::CREATE_BIG_COMPLETE:
+    case bluetooth::hci::SubeventCode::TERMINATE_BIG_COMPLETE:
+    case bluetooth::hci::SubeventCode::BIG_SYNC_ESTABLISHED:
+    case bluetooth::hci::SubeventCode::BIG_SYNC_LOST:
+    case bluetooth::hci::SubeventCode::REQUEST_PEER_SCA_COMPLETE:
+    case bluetooth::hci::SubeventCode::PATH_LOSS_THRESHOLD:
+    case bluetooth::hci::SubeventCode::TRANSMIT_POWER_REPORTING:
+    case bluetooth::hci::SubeventCode::BIG_INFO_ADVERTISING_REPORT:
+    case bluetooth::hci::SubeventCode::ADVERTISING_REPORT:
+    case bluetooth::hci::SubeventCode::LONG_TERM_KEY_REQUEST:
+      return true;
+    default:
+      return false;
+  }
+}
+
 static bool event_already_registered_in_hci_layer(
     bluetooth::hci::EventCode event_code) {
   switch (event_code) {
@@ -186,6 +232,61 @@ static bool event_already_registered_in_hci_layer(
   }
 }
 
+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 false;
+}
+
+static bool subevent_already_registered_in_le_hci_layer(
+    bluetooth::hci::SubeventCode subevent_code) {
+  switch (subevent_code) {
+    case bluetooth::hci::SubeventCode::CONNECTION_COMPLETE:
+    case bluetooth::hci::SubeventCode::CONNECTION_UPDATE_COMPLETE:
+    case bluetooth::hci::SubeventCode::DATA_LENGTH_CHANGE:
+    case bluetooth::hci::SubeventCode::ENHANCED_CONNECTION_COMPLETE:
+    case bluetooth::hci::SubeventCode::PHY_UPDATE_COMPLETE:
+    case bluetooth::hci::SubeventCode::REMOTE_CONNECTION_PARAMETER_REQUEST:
+      return bluetooth::shim::is_gd_acl_enabled();
+
+    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::DIRECTED_ADVERTISING_REPORT:
+    case bluetooth::hci::SubeventCode::EXTENDED_ADVERTISING_REPORT:
+    case bluetooth::hci::SubeventCode::PERIODIC_ADVERTISING_SYNC_ESTABLISHED:
+    case bluetooth::hci::SubeventCode::PERIODIC_ADVERTISING_REPORT:
+    case bluetooth::hci::SubeventCode::PERIODIC_ADVERTISING_SYNC_LOST:
+    case bluetooth::hci::SubeventCode::SCAN_TIMEOUT:
+    case bluetooth::hci::SubeventCode::ADVERTISING_SET_TERMINATED:
+    case bluetooth::hci::SubeventCode::SCAN_REQUEST_RECEIVED:
+    case bluetooth::hci::SubeventCode::CHANNEL_SELECTION_ALGORITHM:
+    case bluetooth::hci::SubeventCode::CONNECTIONLESS_IQ_REPORT:
+    case bluetooth::hci::SubeventCode::CONNECTION_IQ_REPORT:
+    case bluetooth::hci::SubeventCode::CTE_REQUEST_FAILED:
+    case bluetooth::hci::SubeventCode::
+        PERIODIC_ADVERTISING_SYNC_TRANSFER_RECEIVED:
+    case bluetooth::hci::SubeventCode::CIS_ESTABLISHED:
+    case bluetooth::hci::SubeventCode::CIS_REQUEST:
+    case bluetooth::hci::SubeventCode::CREATE_BIG_COMPLETE:
+    case bluetooth::hci::SubeventCode::TERMINATE_BIG_COMPLETE:
+    case bluetooth::hci::SubeventCode::BIG_SYNC_ESTABLISHED:
+    case bluetooth::hci::SubeventCode::BIG_SYNC_LOST:
+    case bluetooth::hci::SubeventCode::REQUEST_PEER_SCA_COMPLETE:
+    case bluetooth::hci::SubeventCode::PATH_LOSS_THRESHOLD:
+    case bluetooth::hci::SubeventCode::TRANSMIT_POWER_REPORTING:
+    case bluetooth::hci::SubeventCode::BIG_INFO_ADVERTISING_REPORT:
+    case bluetooth::hci::SubeventCode::ADVERTISING_REPORT:
+    case bluetooth::hci::SubeventCode::LONG_TERM_KEY_REQUEST:
+    default:
+      return false;
+  }
+}
+
 static bool event_already_registered_in_le_advertising_manager(
     bluetooth::hci::EventCode event_code) {
   for (auto event : bluetooth::hci::AclConnectionEvents) {
@@ -229,6 +330,15 @@ static void event_callback(bluetooth::hci::EventPacketView event_packet_view) {
                                                      &event_packet_view));
 }
 
+static void subevent_callback(
+    bluetooth::hci::LeMetaEventView le_meta_event_view) {
+  if (!send_data_upwards) {
+    return;
+  }
+  send_data_upwards.Run(FROM_HERE, WrapPacketAndCopy(MSG_HC_TO_STACK_HCI_EVT,
+                                                     &le_meta_event_view));
+}
+
 static void set_data_cb(
     base::Callback<void(const base::Location&, BT_HDR*)> send_data_cb) {
   send_data_upwards = std::move(send_data_cb);
@@ -421,7 +531,9 @@ void bluetooth::shim::hci_on_reset_complete() {
       continue;
     }
     auto event_code = static_cast<bluetooth::hci::EventCode>(event_code_raw);
-    if (event_already_registered_in_hci_layer(event_code)) {
+    if (event_already_registered_in_acl_layer(event_code)) {
+      continue;
+    } else if (event_already_registered_in_hci_layer(event_code)) {
       continue;
     } else if (event_already_registered_in_le_advertising_manager(event_code)) {
       continue;
@@ -431,6 +543,26 @@ void bluetooth::shim::hci_on_reset_complete() {
         event_code, handler->Bind(event_callback));
   }
 
+  for (uint8_t subevent_code_raw = 0; subevent_code_raw < 0xFF;
+       subevent_code_raw++) {
+    if (!is_valid_subevent_code(subevent_code_raw)) {
+      continue;
+    }
+    auto subevent_code =
+        static_cast<bluetooth::hci::SubeventCode>(subevent_code_raw);
+    if (subevent_already_registered_in_le_hci_layer(subevent_code)) {
+      continue;
+    }
+
+    auto handler = bluetooth::shim::GetGdShimHandler();
+    bluetooth::shim::GetHciLayer()->RegisterLeEventHandler(
+        subevent_code, handler->Bind(subevent_callback));
+  }
+
+  if (bluetooth::shim::is_gd_acl_enabled()) {
+    return;
+  }
+
   hci_queue_end = bluetooth::shim::GetHciLayer()->GetAclQueueEnd();
 
   // if gd advertising enabled, hci_queue_end will be register in