Loading system/btif/src/btif_dm.cc +20 −1 Original line number Diff line number Diff line Loading @@ -64,6 +64,8 @@ #include "device/include/controller.h" #include "device/include/interop.h" #include "internal_include/stack_config.h" #include "main/shim/btif_dm.h" #include "main/shim/shim.h" #include "osi/include/allocator.h" #include "osi/include/log.h" #include "osi/include/osi.h" Loading Loading @@ -288,7 +290,24 @@ static void btif_dm_data_free(uint16_t event, tBTA_DM_SEC* dm_sec) { osi_free_and_reset((void**)&dm_sec->ble_key.p_key_value); } void btif_dm_init(uid_set_t* set) { uid_set = set; } void btif_dm_init(uid_set_t* set) { uid_set = set; if (bluetooth::shim::is_gd_shim_enabled()) { bluetooth::shim::BTIF_DM_SetUiCallback( [](RawAddress* bt_addr, bt_bdname_t* bd_name, uint32_t cod, bt_ssp_variant_t pairing_variant, uint32_t pass_key) { LOG(ERROR) << __func__ << ": UI Callback fired!"; // TODO(optedoblivion): Wire up HAL_CBACK // HAL_CBACK(bt_hal_cbacks, ssp_request_cb, &bd_addr, &bd_name, // cod, // (p_ssp_cfm_req->just_works ? BT_SSP_VARIANT_CONSENT // : // BT_SSP_VARIANT_PASSKEY_CONFIRMATION), // p_ssp_cfm_req->num_val); // }); } } void btif_dm_cleanup(void) { if (uid_set) { Loading system/gd/security/pairing/classic_pairing_handler.cc +5 −0 Original line number Diff line number Diff line Loading @@ -24,26 +24,31 @@ namespace security { namespace pairing { void ClassicPairingHandler::NotifyUiDisplayYesNo(uint32_t numeric_value) { ASSERT(user_interface_handler_ != nullptr); user_interface_handler_->Post(common::BindOnce(&UI::DisplayConfirmValue, common::Unretained(user_interface_), GetRecord()->GetPseudoAddress(), device_name_, numeric_value)); } void ClassicPairingHandler::NotifyUiDisplayYesNo() { ASSERT(user_interface_handler_ != nullptr); user_interface_handler_->Post(common::BindOnce(&UI::DisplayYesNoDialog, common::Unretained(user_interface_), GetRecord()->GetPseudoAddress(), device_name_)); } void ClassicPairingHandler::NotifyUiDisplayPasskey(uint32_t passkey) { ASSERT(user_interface_handler_ != nullptr); user_interface_handler_->Post(common::BindOnce(&UI::DisplayPasskey, common::Unretained(user_interface_), GetRecord()->GetPseudoAddress(), device_name_, passkey)); } void ClassicPairingHandler::NotifyUiDisplayPasskeyInput() { ASSERT(user_interface_handler_ != nullptr); user_interface_handler_->Post(common::BindOnce(&UI::DisplayEnterPasskeyDialog, common::Unretained(user_interface_), GetRecord()->GetPseudoAddress(), device_name_)); } void ClassicPairingHandler::NotifyUiDisplayCancel() { ASSERT(user_interface_handler_ != nullptr); user_interface_handler_->Post( common::BindOnce(&UI::Cancel, common::Unretained(user_interface_), GetRecord()->GetPseudoAddress())); } Loading system/gd/security/pairing/classic_pairing_handler_unittest.cc +0 −7 Original line number Diff line number Diff line Loading @@ -102,13 +102,6 @@ class SecurityManagerChannelCallback : public ISecurityManagerChannelListener { static void pairing_complete_callback(bluetooth::hci::Address address, PairingResultOrFailure status) { ASSERT(std::holds_alternative<PairingResult>(status)); // auto result = std::get<PairingResult>(status); // if (std::holds_alternative<PairingResult>(status)) { // auto result = status::get<PairingResult>(status); // } // if (std::holds_alternative<PairingFailure>(status)) { // auto failure = status::get<PairingFailure>(status); // } } class ClassicPairingHandlerTest : public ::testing::Test { Loading system/main/shim/Android.bp +1 −0 Original line number Diff line number Diff line filegroup { name: "LibBluetoothShimSources", srcs: [ "btif_dm.cc", "btm.cc", "btm_api.cc", "controller.cc", Loading system/main/shim/btif_dm.cc 0 → 100644 +97 −0 Original line number Diff line number Diff line /* * Copyright 2020 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #define LOG_TAG "bt_shim_btif_dm" #include "main/shim/btif_dm.h" #include "main/shim/entry.h" #include "osi/include/log.h" #include "security/security_module.h" #include "security/ui.h" using ::bluetooth::shim::GetSecurityModule; namespace bluetooth { namespace shim { class ShimUi : public security::UI { public: ~ShimUi() {} void DisplayPairingPrompt(const bluetooth::hci::AddressWithType& address, std::string name) { LOG_WARN(LOG_TAG, "%s TODO Unimplemented", __func__); } void Cancel(const bluetooth::hci::AddressWithType& address) { LOG_WARN(LOG_TAG, "%s TODO Unimplemented", __func__); } void DisplayConfirmValue(const bluetooth::hci::AddressWithType& address, std::string name, uint32_t numeric_value) { LOG_WARN(LOG_TAG, "%s TODO Unimplemented", __func__); // TODO(optedoblivion): Remove and wire up to UI callback auto security_manager = bluetooth::shim::GetSecurityModule()->GetSecurityManager(); security_manager->OnConfirmYesNo(address, true); // callback(address, name, 0, 0, 0); } void DisplayYesNoDialog(const bluetooth::hci::AddressWithType& address, std::string name) { LOG_WARN(LOG_TAG, "%s TODO Unimplemented", __func__); // TODO(optedoblivion): Remove and wire up to UI callback auto security_manager = bluetooth::shim::GetSecurityModule()->GetSecurityManager(); security_manager->OnConfirmYesNo(address, true); // callback(address, name, 0, 0, 0); } void DisplayEnterPasskeyDialog(const bluetooth::hci::AddressWithType& address, std::string name) { LOG_WARN(LOG_TAG, "%s TODO Unimplemented", __func__); } void DisplayPasskey(const bluetooth::hci::AddressWithType& address, std::string name, uint32_t passkey) { LOG_WARN(LOG_TAG, "%s TODO Unimplemented", __func__); } void SetLegacyCallback(std::function<void(RawAddress*, bt_bdname_t*, uint32_t, bt_ssp_variant_t, uint32_t)> callback) { callback_ = callback; } private: std::function<void(RawAddress*, bt_bdname_t*, uint32_t, bt_ssp_variant_t, uint32_t)> callback_; }; ShimUi ui; /** * Sets handler to SecurityModule and provides callback to handler */ void BTIF_DM_SetUiCallback( std::function<void(RawAddress*, bt_bdname_t*, uint32_t, bt_ssp_variant_t, uint32_t)> callback) { LOG_WARN(LOG_TAG, "%s called", __func__); auto security_manager = bluetooth::shim::GetSecurityModule()->GetSecurityManager(); ui.SetLegacyCallback(callback); security_manager->SetUserInterfaceHandler( &ui, bluetooth::shim::GetGdShimHandler()); } } // namespace shim } // namespace bluetooth Loading
system/btif/src/btif_dm.cc +20 −1 Original line number Diff line number Diff line Loading @@ -64,6 +64,8 @@ #include "device/include/controller.h" #include "device/include/interop.h" #include "internal_include/stack_config.h" #include "main/shim/btif_dm.h" #include "main/shim/shim.h" #include "osi/include/allocator.h" #include "osi/include/log.h" #include "osi/include/osi.h" Loading Loading @@ -288,7 +290,24 @@ static void btif_dm_data_free(uint16_t event, tBTA_DM_SEC* dm_sec) { osi_free_and_reset((void**)&dm_sec->ble_key.p_key_value); } void btif_dm_init(uid_set_t* set) { uid_set = set; } void btif_dm_init(uid_set_t* set) { uid_set = set; if (bluetooth::shim::is_gd_shim_enabled()) { bluetooth::shim::BTIF_DM_SetUiCallback( [](RawAddress* bt_addr, bt_bdname_t* bd_name, uint32_t cod, bt_ssp_variant_t pairing_variant, uint32_t pass_key) { LOG(ERROR) << __func__ << ": UI Callback fired!"; // TODO(optedoblivion): Wire up HAL_CBACK // HAL_CBACK(bt_hal_cbacks, ssp_request_cb, &bd_addr, &bd_name, // cod, // (p_ssp_cfm_req->just_works ? BT_SSP_VARIANT_CONSENT // : // BT_SSP_VARIANT_PASSKEY_CONFIRMATION), // p_ssp_cfm_req->num_val); // }); } } void btif_dm_cleanup(void) { if (uid_set) { Loading
system/gd/security/pairing/classic_pairing_handler.cc +5 −0 Original line number Diff line number Diff line Loading @@ -24,26 +24,31 @@ namespace security { namespace pairing { void ClassicPairingHandler::NotifyUiDisplayYesNo(uint32_t numeric_value) { ASSERT(user_interface_handler_ != nullptr); user_interface_handler_->Post(common::BindOnce(&UI::DisplayConfirmValue, common::Unretained(user_interface_), GetRecord()->GetPseudoAddress(), device_name_, numeric_value)); } void ClassicPairingHandler::NotifyUiDisplayYesNo() { ASSERT(user_interface_handler_ != nullptr); user_interface_handler_->Post(common::BindOnce(&UI::DisplayYesNoDialog, common::Unretained(user_interface_), GetRecord()->GetPseudoAddress(), device_name_)); } void ClassicPairingHandler::NotifyUiDisplayPasskey(uint32_t passkey) { ASSERT(user_interface_handler_ != nullptr); user_interface_handler_->Post(common::BindOnce(&UI::DisplayPasskey, common::Unretained(user_interface_), GetRecord()->GetPseudoAddress(), device_name_, passkey)); } void ClassicPairingHandler::NotifyUiDisplayPasskeyInput() { ASSERT(user_interface_handler_ != nullptr); user_interface_handler_->Post(common::BindOnce(&UI::DisplayEnterPasskeyDialog, common::Unretained(user_interface_), GetRecord()->GetPseudoAddress(), device_name_)); } void ClassicPairingHandler::NotifyUiDisplayCancel() { ASSERT(user_interface_handler_ != nullptr); user_interface_handler_->Post( common::BindOnce(&UI::Cancel, common::Unretained(user_interface_), GetRecord()->GetPseudoAddress())); } Loading
system/gd/security/pairing/classic_pairing_handler_unittest.cc +0 −7 Original line number Diff line number Diff line Loading @@ -102,13 +102,6 @@ class SecurityManagerChannelCallback : public ISecurityManagerChannelListener { static void pairing_complete_callback(bluetooth::hci::Address address, PairingResultOrFailure status) { ASSERT(std::holds_alternative<PairingResult>(status)); // auto result = std::get<PairingResult>(status); // if (std::holds_alternative<PairingResult>(status)) { // auto result = status::get<PairingResult>(status); // } // if (std::holds_alternative<PairingFailure>(status)) { // auto failure = status::get<PairingFailure>(status); // } } class ClassicPairingHandlerTest : public ::testing::Test { Loading
system/main/shim/Android.bp +1 −0 Original line number Diff line number Diff line filegroup { name: "LibBluetoothShimSources", srcs: [ "btif_dm.cc", "btm.cc", "btm_api.cc", "controller.cc", Loading
system/main/shim/btif_dm.cc 0 → 100644 +97 −0 Original line number Diff line number Diff line /* * Copyright 2020 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #define LOG_TAG "bt_shim_btif_dm" #include "main/shim/btif_dm.h" #include "main/shim/entry.h" #include "osi/include/log.h" #include "security/security_module.h" #include "security/ui.h" using ::bluetooth::shim::GetSecurityModule; namespace bluetooth { namespace shim { class ShimUi : public security::UI { public: ~ShimUi() {} void DisplayPairingPrompt(const bluetooth::hci::AddressWithType& address, std::string name) { LOG_WARN(LOG_TAG, "%s TODO Unimplemented", __func__); } void Cancel(const bluetooth::hci::AddressWithType& address) { LOG_WARN(LOG_TAG, "%s TODO Unimplemented", __func__); } void DisplayConfirmValue(const bluetooth::hci::AddressWithType& address, std::string name, uint32_t numeric_value) { LOG_WARN(LOG_TAG, "%s TODO Unimplemented", __func__); // TODO(optedoblivion): Remove and wire up to UI callback auto security_manager = bluetooth::shim::GetSecurityModule()->GetSecurityManager(); security_manager->OnConfirmYesNo(address, true); // callback(address, name, 0, 0, 0); } void DisplayYesNoDialog(const bluetooth::hci::AddressWithType& address, std::string name) { LOG_WARN(LOG_TAG, "%s TODO Unimplemented", __func__); // TODO(optedoblivion): Remove and wire up to UI callback auto security_manager = bluetooth::shim::GetSecurityModule()->GetSecurityManager(); security_manager->OnConfirmYesNo(address, true); // callback(address, name, 0, 0, 0); } void DisplayEnterPasskeyDialog(const bluetooth::hci::AddressWithType& address, std::string name) { LOG_WARN(LOG_TAG, "%s TODO Unimplemented", __func__); } void DisplayPasskey(const bluetooth::hci::AddressWithType& address, std::string name, uint32_t passkey) { LOG_WARN(LOG_TAG, "%s TODO Unimplemented", __func__); } void SetLegacyCallback(std::function<void(RawAddress*, bt_bdname_t*, uint32_t, bt_ssp_variant_t, uint32_t)> callback) { callback_ = callback; } private: std::function<void(RawAddress*, bt_bdname_t*, uint32_t, bt_ssp_variant_t, uint32_t)> callback_; }; ShimUi ui; /** * Sets handler to SecurityModule and provides callback to handler */ void BTIF_DM_SetUiCallback( std::function<void(RawAddress*, bt_bdname_t*, uint32_t, bt_ssp_variant_t, uint32_t)> callback) { LOG_WARN(LOG_TAG, "%s called", __func__); auto security_manager = bluetooth::shim::GetSecurityModule()->GetSecurityManager(); ui.SetLegacyCallback(callback); security_manager->SetUserInterfaceHandler( &ui, bluetooth::shim::GetGdShimHandler()); } } // namespace shim } // namespace bluetooth