OSDN Git Service

BTM Shim: Put/Get information bits to ConfirmationData
authorMartin Brabham <optedoblivion@google.com>
Mon, 21 Sep 2020 17:12:30 +0000 (10:12 -0700)
committerMartin Brabham <optedoblivion@google.com>
Thu, 1 Oct 2020 08:38:31 +0000 (01:38 -0700)
We need the io_caps, auth_reqs, and oob present to send to BTA.
We won't need this when the shim goes away, but for now its necessary.

Bug: 162984360
Tag: #gd-refactor
Test: cert/run --host SecurityTest
Test: atest --host bluetooth_test_gd
Change-Id: I3f3a2ba909ed4384ca44ad2ddca5b5ecda64822e

gd/security/cert/security_test.py
gd/security/pairing/classic_pairing_handler.cc
main/shim/btm_api.cc

index 21a9b5c..cd8efd9 100644 (file)
@@ -65,14 +65,10 @@ class SecurityTest(GdBaseTestClass):
         IoCapabilities.NO_INPUT_NO_OUTPUT)
 
     # Possible Authentication Requirements
-    auth_reqs = (
-        AuthenticationRequirements.NO_BONDING,
-        # TODO(optedoblivion): Figure out MITM cases
-        AuthenticationRequirements.NO_BONDING_MITM_PROTECTION,
-        AuthenticationRequirements.DEDICATED_BONDING,
-        AuthenticationRequirements.DEDICATED_BONDING_MITM_PROTECTION,
-        AuthenticationRequirements.GENERAL_BONDING,
-        AuthenticationRequirements.GENERAL_BONDING_MITM_PROTECTION)
+    auth_reqs = (AuthenticationRequirements.NO_BONDING, AuthenticationRequirements.NO_BONDING_MITM_PROTECTION,
+                 AuthenticationRequirements.DEDICATED_BONDING,
+                 AuthenticationRequirements.DEDICATED_BONDING_MITM_PROTECTION,
+                 AuthenticationRequirements.GENERAL_BONDING, AuthenticationRequirements.GENERAL_BONDING_MITM_PROTECTION)
 
     # Possible Out-of-Band data options
     oob_present = (
index 9831ad9..ba95a5a 100644 (file)
@@ -27,24 +27,36 @@ namespace pairing {
 void ClassicPairingHandler::NotifyUiDisplayYesNo(uint32_t numeric_value) {
   ASSERT(user_interface_handler_ != nullptr);
   ConfirmationData data(*GetRecord()->GetPseudoAddress(), device_name_, numeric_value);
+  data.PutExtraData("remote_io_caps", hci::IoCapabilityText(remote_io_capability_));
+  data.PutExtraData("remote_auth_reqs", hci::AuthenticationRequirementsText(remote_authentication_requirements_));
+  data.PutExtraData("remote_oob_data_present", hci::OobDataPresentText(remote_oob_present_));
   user_interface_handler_->CallOn(user_interface_, &UI::DisplayConfirmValue, data);
 }
 
 void ClassicPairingHandler::NotifyUiDisplayYesNo() {
   ASSERT(user_interface_handler_ != nullptr);
   ConfirmationData data(*GetRecord()->GetPseudoAddress(), device_name_);
+  data.PutExtraData("remote_io_caps", hci::IoCapabilityText(remote_io_capability_));
+  data.PutExtraData("remote_auth_reqs", hci::AuthenticationRequirementsText(remote_authentication_requirements_));
+  data.PutExtraData("remote_oob_data_present", hci::OobDataPresentText(remote_oob_present_));
   user_interface_handler_->CallOn(user_interface_, &UI::DisplayYesNoDialog, data);
 }
 
 void ClassicPairingHandler::NotifyUiDisplayPasskey(uint32_t passkey) {
   ASSERT(user_interface_handler_ != nullptr);
   ConfirmationData data(*GetRecord()->GetPseudoAddress(), device_name_, passkey);
+  data.PutExtraData("remote_io_caps", hci::IoCapabilityText(remote_io_capability_));
+  data.PutExtraData("remote_auth_reqs", hci::AuthenticationRequirementsText(remote_authentication_requirements_));
+  data.PutExtraData("remote_oob_data_present", hci::OobDataPresentText(remote_oob_present_));
   user_interface_handler_->CallOn(user_interface_, &UI::DisplayPasskey, data);
 }
 
 void ClassicPairingHandler::NotifyUiDisplayPasskeyInput() {
   ASSERT(user_interface_handler_ != nullptr);
   ConfirmationData data(*GetRecord()->GetPseudoAddress(), device_name_);
+  data.PutExtraData("remote_io_caps", hci::IoCapabilityText(remote_io_capability_));
+  data.PutExtraData("remote_auth_reqs", hci::AuthenticationRequirementsText(remote_authentication_requirements_));
+  data.PutExtraData("remote_oob_data_present", hci::OobDataPresentText(remote_oob_present_));
   user_interface_handler_->CallOn(user_interface_, &UI::DisplayEnterPasskeyDialog, data);
 }
 
@@ -54,7 +66,8 @@ void ClassicPairingHandler::NotifyUiDisplayCancel() {
 }
 
 void ClassicPairingHandler::OnPairingPromptAccepted(const bluetooth::hci::AddressWithType& address, bool confirmed) {
-  LOG_WARN("TODO Not Implemented!");
+  // NOTE: This is not used by Classic, only by LE
+  LOG_ALWAYS_FATAL("This is not supported by Classic Pairing Handler, only LE");
 }
 
 void ClassicPairingHandler::OnConfirmYesNo(const bluetooth::hci::AddressWithType& address, bool confirmed) {
@@ -179,7 +192,6 @@ void ClassicPairingHandler::OnReceive(hci::IoCapabilityResponseView packet) {
   LOG_INFO("Received: %s", hci::EventCodeText(packet.GetEventCode()).c_str());
   ASSERT_LOG(GetRecord()->GetPseudoAddress()->GetAddress() == packet.GetBdAddr(), "Address mismatch");
 
-  // Using local variable until device database pointer is ready
   remote_io_capability_ = packet.GetIoCapability();
   remote_authentication_requirements_ = packet.GetAuthenticationRequirements();
   remote_oob_present_ = packet.GetOobDataPresent();
index 90a891c..14dba56 100644 (file)
@@ -239,6 +239,45 @@ void btm_api_process_extended_inquiry_result(RawAddress raw_address,
 namespace {
 std::unordered_map<bluetooth::hci::AddressWithType, bt_bdname_t>
     address_name_map_;
+
+std::unordered_map<std::string, int> gd_legacy_io_caps_map_ = {
+    {bluetooth::hci::IoCapabilityText(
+         bluetooth::hci::IoCapability::DISPLAY_ONLY),
+     BTM_IO_CAP_OUT},
+    {bluetooth::hci::IoCapabilityText(
+         bluetooth::hci::IoCapability::DISPLAY_YES_NO),
+     BTM_IO_CAP_IO},
+    {bluetooth::hci::IoCapabilityText(
+         bluetooth::hci::IoCapability::KEYBOARD_ONLY),
+     BTM_IO_CAP_IN},
+    {bluetooth::hci::IoCapabilityText(
+         bluetooth::hci::IoCapability::NO_INPUT_NO_OUTPUT),
+     BTM_IO_CAP_NONE},
+};
+
+std::unordered_map<std::string, int> gd_legacy_auth_reqs_map_ = {
+    {bluetooth::hci::AuthenticationRequirementsText(
+         bluetooth::hci::AuthenticationRequirements::NO_BONDING),
+     BTM_AUTH_SP_NO},
+    {bluetooth::hci::AuthenticationRequirementsText(
+         bluetooth::hci::AuthenticationRequirements::
+             NO_BONDING_MITM_PROTECTION),
+     BTM_AUTH_SP_YES},
+    {bluetooth::hci::AuthenticationRequirementsText(
+         bluetooth::hci::AuthenticationRequirements::DEDICATED_BONDING),
+     BTM_AUTH_AP_NO},
+    {bluetooth::hci::AuthenticationRequirementsText(
+         bluetooth::hci::AuthenticationRequirements::
+             DEDICATED_BONDING_MITM_PROTECTION),
+     BTM_AUTH_AP_YES},
+    {bluetooth::hci::AuthenticationRequirementsText(
+         bluetooth::hci::AuthenticationRequirements::GENERAL_BONDING),
+     BTM_AUTH_SPGB_NO},
+    {bluetooth::hci::AuthenticationRequirementsText(
+         bluetooth::hci::AuthenticationRequirements::
+             GENERAL_BONDING_MITM_PROTECTION),
+     BTM_AUTH_SPGB_YES},
+};
 }
 
 class ShimUi : public bluetooth::security::UI {
@@ -302,7 +341,8 @@ class ShimUi : public bluetooth::security::UI {
       io_req_evt_data.bd_addr = bluetooth::ToRawAddress(address.GetAddress());
       // Local IO Caps (Phone is always DisplayYesNo)
       io_req_evt_data.io_cap = BTM_IO_CAP_IO;
-      io_req_evt_data.auth_req = BTM_AUTH_AP_YES;
+      // Local Auth Reqs (Phone is always DEDICATED_BONDING)
+      io_req_evt_data.auth_req = BTM_AUTH_AP_NO;
       io_req_evt_data.oob_data = BTM_OOB_NONE;
       (*bta_callbacks_->p_sp_callback)(BTM_SP_IO_REQ_EVT,
                                        (tBTM_SP_EVT_DATA*)&io_req_evt_data);
@@ -310,9 +350,10 @@ class ShimUi : public bluetooth::security::UI {
       // Call sp_cback for IO_RSP
       tBTM_SP_IO_RSP io_rsp_evt_data;
       io_rsp_evt_data.bd_addr = bluetooth::ToRawAddress(address.GetAddress());
-      // TODO(optedoblivion): Get remote IO Cap to set here
-      io_rsp_evt_data.io_cap = BTM_IO_CAP_IO;
-      // TODO(optedoblivion): Get remote AUTH REQ to set here
+      io_rsp_evt_data.io_cap =
+          gd_legacy_io_caps_map_[data.GetExtraData("remote_io_caps")];
+      io_rsp_evt_data.auth_req =
+          gd_legacy_auth_reqs_map_[data.GetExtraData("remote_auth_reqs")];
       io_rsp_evt_data.auth_req = BTM_AUTH_AP_YES;
       io_rsp_evt_data.oob_data = BTM_OOB_NONE;
       (*bta_callbacks_->p_sp_callback)(BTM_SP_IO_RSP_EVT,