Loading system/gd/l2cap/classic/internal/link_manager.cc +4 −0 Original line number Diff line number Diff line Loading @@ -114,6 +114,10 @@ void LinkManager::RegisterLinkSecurityInterfaceListener(os::Handler* handler, Li link_security_interface_listener_ = listener; } LinkSecurityInterfaceListener* LinkManager::GetLinkSecurityInterfaceListener() { return link_security_interface_listener_; } Link* LinkManager::GetLink(const hci::Address device) { if (links_.find(device) == links_.end()) { return nullptr; Loading system/gd/l2cap/classic/internal/link_manager.h +3 −0 Original line number Diff line number Diff line Loading @@ -87,6 +87,9 @@ class LinkManager : public hci::acl_manager::ConnectionCallbacks { // LinkManager will handle sending OnLinkConnected() callback and construct a LinkSecurityInterface proxy. void RegisterLinkSecurityInterfaceListener(os::Handler* handler, LinkSecurityInterfaceListener* listener); // For the link to get LinkSecurityInterfaceListener LinkSecurityInterfaceListener* GetLinkSecurityInterfaceListener(); private: // Handles requests from LinkSecurityInterface friend class LinkSecurityInterfaceImpl; Loading system/main/shim/l2c_api.cc +49 −4 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ #define LOG_TAG "bt_shim_l2cap" #include <future> #include <unordered_map> #include <unordered_set> Loading @@ -36,6 +37,10 @@ #include "stack/include/btm_api.h" #include "stack/include/btu.h" extern void gatt_notify_conn_update(const RawAddress& remote, uint16_t interval, uint16_t latency, uint16_t timeout, tHCI_STATUS status); namespace bluetooth { namespace shim { Loading Loading @@ -696,7 +701,9 @@ struct LeFixedChannelHelper { GetGdShimHandler(), bluetooth::common::BindOnce( &LeFixedChannelHelper::on_channel_close, bluetooth::common::Unretained(this), device)); if (cid_ == kAttCid) { channel->Acquire(); } channel_enqueue_buffer_[device] = std::make_unique< bluetooth::os::EnqueueBuffer<bluetooth::packet::BasePacketBuilder>>( channel->GetQueueUpEnd()); Loading Loading @@ -835,6 +842,33 @@ bool L2CA_RemoveFixedChnl(uint16_t cid, const RawAddress& rem_bda) { return true; } uint16_t L2CA_GetLeHandle(uint16_t cid, const RawAddress& rem_bda) { if (cid != kAttCid && cid != kSmpCid) { LOG(ERROR) << "Invalid cid " << cid; return 0; } auto* helper = &le_fixed_channel_helper_.find(cid)->second; auto remote = ToAddressWithType(rem_bda, Btm::GetAddressType(rem_bda)); auto channel = helper->channels_.find(remote); if (channel == helper->channels_.end() || channel->second == nullptr) { LOG(ERROR) << "Channel is not open"; return 0; } return channel->second->GetLinkOptions()->GetHandle(); } void L2CA_LeConnectionUpdate(const RawAddress& rem_bda) { auto* helper = &le_fixed_channel_helper_.find(4)->second; auto remote = ToAddressWithType(rem_bda, Btm::GetAddressType(rem_bda)); auto channel = helper->channels_.find(remote); if (channel == helper->channels_.end() || channel->second == nullptr) { LOG(ERROR) << "Channel is not open"; } channel->second->GetLinkOptions()->UpdateConnectionParameter(0x24, 0x24, 0, 0x01f4, 0, 0); } /** * Channel hygiene APIs */ Loading Loading @@ -879,7 +913,11 @@ uint16_t L2CA_FlushChannel(uint16_t lcid, uint16_t num_to_flush) { bool L2CA_IsLinkEstablished(const RawAddress& bd_addr, tBT_TRANSPORT transport) { if (transport == BT_TRANSPORT_BR_EDR) { return security_listener_shim_.IsLinkUp(bd_addr); } else { return bluetooth::shim::L2CA_GetLeHandle(kAttCid, bd_addr) != 0; } } void L2CA_ConnectForSecurity(const RawAddress& bd_addr) { Loading Loading @@ -930,29 +968,36 @@ struct LeDynamicChannelHelper { le::SecurityPolicy policy_; void Register() { std::promise<void> promise; auto future = promise.get_future(); GetL2capLeModule()->GetDynamicChannelManager()->RegisterService( psm_, config_, policy_, base::BindOnce(&LeDynamicChannelHelper::on_registration_complete, base::Unretained(this)), base::Unretained(this), std::move(promise)), base::Bind(&LeDynamicChannelHelper::on_channel_open, base::Unretained(this), 0), GetGdShimHandler()); future.wait_for(std::chrono::milliseconds(300)); } void on_registration_complete( std::promise<void> promise, le::DynamicChannelManager::RegistrationResult result, std::unique_ptr<le::DynamicChannelService> service) { if (result != le::DynamicChannelManager::RegistrationResult::SUCCESS) { LOG(ERROR) << "Channel is not registered. psm=" << +psm_ << (int)result; promise.set_value(); return; } channel_service_ = std::move(service); promise.set_value(); } std::unique_ptr<le::DynamicChannelService> channel_service_ = nullptr; void Connect(uint16_t cid_token, bluetooth::hci::AddressWithType device) { if (channel_service_ == nullptr) { LOG(ERROR) << __func__ << "Not registered"; return; } initiated_by_us_[cid_token] = true; Loading Loading @@ -1161,7 +1206,7 @@ uint16_t L2CA_ConnectLECocReq(uint16_t psm, const RawAddress& p_bd_addr, } uint16_t cid_token = add_le_cid_token_entry(psm); le_dynamic_channel_helper_map_[psm]->Connect( cid_token, ToAddressWithType(p_bd_addr, BLE_ADDR_PUBLIC)); cid_token, ToAddressWithType(p_bd_addr, Btm::GetAddressType(p_bd_addr))); return cid_token; } Loading system/main/shim/l2c_api.h +3 −0 Original line number Diff line number Diff line Loading @@ -393,6 +393,9 @@ uint16_t L2CA_SendFixedChnlData(uint16_t fixed_cid, const RawAddress& rem_bda, ******************************************************************************/ bool L2CA_RemoveFixedChnl(uint16_t fixed_cid, const RawAddress& rem_bda); uint16_t L2CA_GetLeHandle(uint16_t cid, const RawAddress& rem_bda); void L2CA_LeConnectionUpdate(const RawAddress& rem_bda); /******************************************************************************* * * Function L2CA_SetFixedChannelTout Loading system/stack/acl/ble_acl.cc +8 −2 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ #include "osi/include/log.h" #include "stack/btm/btm_ble_int.h" #include "stack/btm/btm_dev.h" #include "stack/btm/btm_sec.h" #include "stack/gatt/connection_manager.h" #include "stack/include/acl_api.h" Loading Loading @@ -155,7 +156,7 @@ void acl_ble_connection_fail(const tBLE_BD_ADDR& address_with_type, status); } void gatt_notify_conn_update(uint16_t handle, uint16_t interval, void gatt_notify_conn_update(const RawAddress& remote, uint16_t interval, uint16_t latency, uint16_t timeout, tHCI_STATUS status); void acl_ble_update_event_received(tHCI_STATUS status, uint16_t handle, Loading @@ -163,5 +164,10 @@ void acl_ble_update_event_received(tHCI_STATUS status, uint16_t handle, uint16_t timeout) { l2cble_process_conn_update_evt(handle, status, interval, latency, timeout); gatt_notify_conn_update(handle & 0x0FFF, interval, latency, timeout, status); tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev_by_handle(handle); if (!p_dev_rec) return; gatt_notify_conn_update(p_dev_rec->ble.pseudo_addr, interval, latency, timeout, status); } Loading
system/gd/l2cap/classic/internal/link_manager.cc +4 −0 Original line number Diff line number Diff line Loading @@ -114,6 +114,10 @@ void LinkManager::RegisterLinkSecurityInterfaceListener(os::Handler* handler, Li link_security_interface_listener_ = listener; } LinkSecurityInterfaceListener* LinkManager::GetLinkSecurityInterfaceListener() { return link_security_interface_listener_; } Link* LinkManager::GetLink(const hci::Address device) { if (links_.find(device) == links_.end()) { return nullptr; Loading
system/gd/l2cap/classic/internal/link_manager.h +3 −0 Original line number Diff line number Diff line Loading @@ -87,6 +87,9 @@ class LinkManager : public hci::acl_manager::ConnectionCallbacks { // LinkManager will handle sending OnLinkConnected() callback and construct a LinkSecurityInterface proxy. void RegisterLinkSecurityInterfaceListener(os::Handler* handler, LinkSecurityInterfaceListener* listener); // For the link to get LinkSecurityInterfaceListener LinkSecurityInterfaceListener* GetLinkSecurityInterfaceListener(); private: // Handles requests from LinkSecurityInterface friend class LinkSecurityInterfaceImpl; Loading
system/main/shim/l2c_api.cc +49 −4 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ #define LOG_TAG "bt_shim_l2cap" #include <future> #include <unordered_map> #include <unordered_set> Loading @@ -36,6 +37,10 @@ #include "stack/include/btm_api.h" #include "stack/include/btu.h" extern void gatt_notify_conn_update(const RawAddress& remote, uint16_t interval, uint16_t latency, uint16_t timeout, tHCI_STATUS status); namespace bluetooth { namespace shim { Loading Loading @@ -696,7 +701,9 @@ struct LeFixedChannelHelper { GetGdShimHandler(), bluetooth::common::BindOnce( &LeFixedChannelHelper::on_channel_close, bluetooth::common::Unretained(this), device)); if (cid_ == kAttCid) { channel->Acquire(); } channel_enqueue_buffer_[device] = std::make_unique< bluetooth::os::EnqueueBuffer<bluetooth::packet::BasePacketBuilder>>( channel->GetQueueUpEnd()); Loading Loading @@ -835,6 +842,33 @@ bool L2CA_RemoveFixedChnl(uint16_t cid, const RawAddress& rem_bda) { return true; } uint16_t L2CA_GetLeHandle(uint16_t cid, const RawAddress& rem_bda) { if (cid != kAttCid && cid != kSmpCid) { LOG(ERROR) << "Invalid cid " << cid; return 0; } auto* helper = &le_fixed_channel_helper_.find(cid)->second; auto remote = ToAddressWithType(rem_bda, Btm::GetAddressType(rem_bda)); auto channel = helper->channels_.find(remote); if (channel == helper->channels_.end() || channel->second == nullptr) { LOG(ERROR) << "Channel is not open"; return 0; } return channel->second->GetLinkOptions()->GetHandle(); } void L2CA_LeConnectionUpdate(const RawAddress& rem_bda) { auto* helper = &le_fixed_channel_helper_.find(4)->second; auto remote = ToAddressWithType(rem_bda, Btm::GetAddressType(rem_bda)); auto channel = helper->channels_.find(remote); if (channel == helper->channels_.end() || channel->second == nullptr) { LOG(ERROR) << "Channel is not open"; } channel->second->GetLinkOptions()->UpdateConnectionParameter(0x24, 0x24, 0, 0x01f4, 0, 0); } /** * Channel hygiene APIs */ Loading Loading @@ -879,7 +913,11 @@ uint16_t L2CA_FlushChannel(uint16_t lcid, uint16_t num_to_flush) { bool L2CA_IsLinkEstablished(const RawAddress& bd_addr, tBT_TRANSPORT transport) { if (transport == BT_TRANSPORT_BR_EDR) { return security_listener_shim_.IsLinkUp(bd_addr); } else { return bluetooth::shim::L2CA_GetLeHandle(kAttCid, bd_addr) != 0; } } void L2CA_ConnectForSecurity(const RawAddress& bd_addr) { Loading Loading @@ -930,29 +968,36 @@ struct LeDynamicChannelHelper { le::SecurityPolicy policy_; void Register() { std::promise<void> promise; auto future = promise.get_future(); GetL2capLeModule()->GetDynamicChannelManager()->RegisterService( psm_, config_, policy_, base::BindOnce(&LeDynamicChannelHelper::on_registration_complete, base::Unretained(this)), base::Unretained(this), std::move(promise)), base::Bind(&LeDynamicChannelHelper::on_channel_open, base::Unretained(this), 0), GetGdShimHandler()); future.wait_for(std::chrono::milliseconds(300)); } void on_registration_complete( std::promise<void> promise, le::DynamicChannelManager::RegistrationResult result, std::unique_ptr<le::DynamicChannelService> service) { if (result != le::DynamicChannelManager::RegistrationResult::SUCCESS) { LOG(ERROR) << "Channel is not registered. psm=" << +psm_ << (int)result; promise.set_value(); return; } channel_service_ = std::move(service); promise.set_value(); } std::unique_ptr<le::DynamicChannelService> channel_service_ = nullptr; void Connect(uint16_t cid_token, bluetooth::hci::AddressWithType device) { if (channel_service_ == nullptr) { LOG(ERROR) << __func__ << "Not registered"; return; } initiated_by_us_[cid_token] = true; Loading Loading @@ -1161,7 +1206,7 @@ uint16_t L2CA_ConnectLECocReq(uint16_t psm, const RawAddress& p_bd_addr, } uint16_t cid_token = add_le_cid_token_entry(psm); le_dynamic_channel_helper_map_[psm]->Connect( cid_token, ToAddressWithType(p_bd_addr, BLE_ADDR_PUBLIC)); cid_token, ToAddressWithType(p_bd_addr, Btm::GetAddressType(p_bd_addr))); return cid_token; } Loading
system/main/shim/l2c_api.h +3 −0 Original line number Diff line number Diff line Loading @@ -393,6 +393,9 @@ uint16_t L2CA_SendFixedChnlData(uint16_t fixed_cid, const RawAddress& rem_bda, ******************************************************************************/ bool L2CA_RemoveFixedChnl(uint16_t fixed_cid, const RawAddress& rem_bda); uint16_t L2CA_GetLeHandle(uint16_t cid, const RawAddress& rem_bda); void L2CA_LeConnectionUpdate(const RawAddress& rem_bda); /******************************************************************************* * * Function L2CA_SetFixedChannelTout Loading
system/stack/acl/ble_acl.cc +8 −2 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ #include "osi/include/log.h" #include "stack/btm/btm_ble_int.h" #include "stack/btm/btm_dev.h" #include "stack/btm/btm_sec.h" #include "stack/gatt/connection_manager.h" #include "stack/include/acl_api.h" Loading Loading @@ -155,7 +156,7 @@ void acl_ble_connection_fail(const tBLE_BD_ADDR& address_with_type, status); } void gatt_notify_conn_update(uint16_t handle, uint16_t interval, void gatt_notify_conn_update(const RawAddress& remote, uint16_t interval, uint16_t latency, uint16_t timeout, tHCI_STATUS status); void acl_ble_update_event_received(tHCI_STATUS status, uint16_t handle, Loading @@ -163,5 +164,10 @@ void acl_ble_update_event_received(tHCI_STATUS status, uint16_t handle, uint16_t timeout) { l2cble_process_conn_update_evt(handle, status, interval, latency, timeout); gatt_notify_conn_update(handle & 0x0FFF, interval, latency, timeout, status); tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev_by_handle(handle); if (!p_dev_rec) return; gatt_notify_conn_update(p_dev_rec->ble.pseudo_addr, interval, latency, timeout, status); }