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);
- //
- });
+ bluetooth::shim::BTIF_DM_SetUiCallback([](RawAddress address, bt_bdname_t bd_name, uint32_t cod, bt_ssp_variant_t pairing_variant, uint32_t pass_key) {
+ do_in_jni_thread(FROM_HERE, base::BindOnce([](RawAddress address, 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: java BondStateMachine requires change into bonding state. If we ever send this event separately, consider removing this line
+ HAL_CBACK(bt_hal_cbacks, bond_state_changed_cb, BT_STATUS_SUCCESS, &address, BT_BOND_STATE_BONDING);
+
+ HAL_CBACK(bt_hal_cbacks, ssp_request_cb, &address, &bd_name, cod, pairing_variant, pass_key);
+ }, address, bd_name, cod, pairing_variant, pass_key));
+ });
}
}
bt_status_t btif_dm_ssp_reply(const RawAddress* bd_addr,
bt_ssp_variant_t variant, uint8_t accept,
UNUSED_ATTR uint32_t passkey) {
+
+ if (bluetooth::shim::is_gd_shim_enabled()) {
+ uint8_t tmp_dev_type = 0;
+ uint8_t tmp_addr_type = 0;
+ BTM_ReadDevInfo(*bd_addr, &tmp_dev_type, &tmp_addr_type);
+
+ do_in_main_thread(
+ FROM_HERE,
+ base::Bind(&bluetooth::shim::BTIF_DM_ssp_reply, *bd_addr, tmp_addr_type, variant, accept));
+ }
+
if (variant == BT_SSP_VARIANT_PASSKEY_ENTRY) {
/* This is not implemented in the stack.
* For devices with display, this is not needed
*/
#define LOG_TAG "bt_shim_btif_dm"
-#include "main/shim/btif_dm.h"
+#include "osi/include/log.h"
+#include "main/shim/btif_dm.h"
#include "main/shim/entry.h"
-#include "osi/include/log.h"
+#include "main/shim/helpers.h"
#include "security/security_module.h"
#include "security/ui.h"
~ShimUi() {}
void DisplayPairingPrompt(const bluetooth::hci::AddressWithType& address,
std::string name) {
- LOG_WARN(LOG_TAG, "%s TODO Unimplemented", __func__);
+ LOG_WARN(LOG_TAG, "%s ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ TODO Unimplemented", __func__);
}
void Cancel(const bluetooth::hci::AddressWithType& address) {
- LOG_WARN(LOG_TAG, "%s TODO Unimplemented", __func__);
+ 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);
+ bt_bdname_t legacy_name{0};
+ memcpy(legacy_name.name, name.data(), name.length());
+ callback_(RawAddress(address.GetAddress().address), legacy_name, ((0x1F) << 8) /* COD_UNCLASSIFIED*/ , BT_SSP_VARIANT_PASSKEY_CONFIRMATION, numeric_value);
}
+
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);
+ bt_bdname_t legacy_name{0};
+ memcpy(legacy_name.name, name.data(), name.length());
+ callback_(RawAddress(address.GetAddress().address), legacy_name, ((0x1F) << 8) /* COD_UNCLASSIFIED*/ , BT_SSP_VARIANT_CONSENT, 0);
}
- void DisplayEnterPasskeyDialog(const bluetooth::hci::AddressWithType& address,
- std::string name) {
- LOG_WARN(LOG_TAG, "%s TODO Unimplemented", __func__);
+
+ void DisplayEnterPasskeyDialog(const bluetooth::hci::AddressWithType& address, std::string name) {
+ bt_bdname_t legacy_name{0};
+ memcpy(legacy_name.name, name.data(), name.length());
+ callback_(RawAddress(address.GetAddress().address), legacy_name, ((0x1F) << 8) /* COD_UNCLASSIFIED*/ , BT_SSP_VARIANT_PASSKEY_ENTRY, 0);
}
- void DisplayPasskey(const bluetooth::hci::AddressWithType& address,
- std::string name, uint32_t passkey) {
- LOG_WARN(LOG_TAG, "%s TODO Unimplemented", __func__);
+
+ void DisplayPasskey(const bluetooth::hci::AddressWithType& address, std::string name, uint32_t passkey) {
+ bt_bdname_t legacy_name{0};
+ memcpy(legacy_name.name, name.data(), name.length());
+ callback_(RawAddress(address.GetAddress().address), legacy_name, ((0x1F) << 8) /* COD_UNCLASSIFIED*/ , BT_SSP_VARIANT_PASSKEY_NOTIFICATION, passkey);
}
- void SetLegacyCallback(std::function<void(RawAddress*, bt_bdname_t*, uint32_t,
- bt_ssp_variant_t, uint32_t)>
- callback) {
+ 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,
+ std::function<void(RawAddress, bt_bdname_t, uint32_t, bt_ssp_variant_t,
uint32_t)>
callback_;
};
/**
* 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();
+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", __func__);
+ auto security_manager = bluetooth::shim::GetSecurityModule()->GetSecurityManager();
ui.SetLegacyCallback(callback);
- security_manager->SetUserInterfaceHandler(
- &ui, bluetooth::shim::GetGdShimHandler());
+ security_manager->SetUserInterfaceHandler(&ui, bluetooth::shim::GetGdShimHandler());
+}
+
+void BTIF_DM_ssp_reply(const RawAddress bd_addr, uint8_t addr_type, bt_ssp_variant_t variant, uint8_t accept) {
+ LOG_WARN(LOG_TAG, "%s", __func__);
+
+ hci::AddressWithType address = ToAddressWithType(bd_addr, addr_type);
+
+ auto security_manager = bluetooth::shim::GetSecurityModule()->GetSecurityManager();
+
+ if (variant == BT_SSP_VARIANT_PASSKEY_CONFIRMATION || variant == BT_SSP_VARIANT_CONSENT) {
+ security_manager->OnConfirmYesNo(address, accept);
+ } else {
+ //TODO:
+ // void OnPairingPromptAccepted(const bluetooth::hci::AddressWithType& address, bool confirmed) override;
+ // void OnPasskeyEntry(const bluetooth::hci::AddressWithType& address, uint32_t passkey) override;
+ LOG_WARN(LOG_TAG, "■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ Variant not implemented yet %02x", variant);
+ }
}
} // namespace shim