From: Hansong Zhang Date: Tue, 24 Nov 2020 21:14:57 +0000 (-0800) Subject: Refactor LE dynamic psm assignment X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=c846c3bae0b4842815f984640a3fe9da330a7ca9;p=android-x86%2Fsystem-bt.git Refactor LE dynamic psm assignment Tag: #gd-refactor Bug: 141555841 Test: cert/run --host Test: CtsVerifier Change-Id: If6d421a84b3978a564e5fb5da4bb97f0d440b1fe --- diff --git a/main/shim/l2c_api.cc b/main/shim/l2c_api.cc index b3bc4b0e6..2827a9069 100644 --- a/main/shim/l2c_api.cc +++ b/main/shim/l2c_api.cc @@ -16,6 +16,9 @@ #define LOG_TAG "bt_shim_l2cap" +#include +#include + #include "main/shim/l2c_api.h" #include "bta/include/bta_dm_acl.h" #include "gd/l2cap/classic/l2cap_classic_module.h" @@ -37,8 +40,6 @@ using bluetooth::hci::AddressWithType; using namespace bluetooth::l2cap; -static bluetooth::shim::legacy::L2cap shim_l2cap; - // Classic Dynamic Channel Shim Helper uint16_t classic_cid_token_counter_ = 0x41; @@ -577,18 +578,6 @@ void bluetooth::shim::L2CA_Deregister(uint16_t psm) { } } -uint16_t bluetooth::shim::L2CA_AllocateLePSM(void) { - return shim_l2cap.GetNextDynamicLePsm(); -} - -void bluetooth::shim::L2CA_FreeLePSM(uint16_t psm) { - if (!shim_l2cap.Le().IsPsmRegistered(psm)) { - LOG_ERROR("%s Not previously registered le psm:%hd", __func__, psm); - return; - } - shim_l2cap.Le().UnregisterPsm(psm); -} - /** * Classic Connection Oriented Channel APIS */ @@ -1136,6 +1125,29 @@ std::unordered_map> /** * Le Connection Oriented Channel APIs */ + +static std::unordered_set assigned_dynamic_le_psm_; +static uint16_t next_assigned_dynamic_le_psm_ = 0x80; + +uint16_t bluetooth::shim::L2CA_AllocateLePSM() { + if (le_dynamic_channel_helper_map_.size() > 100) { + LOG_ERROR("Why do we need more than 100 dynamic channel PSMs?"); + return 0; + } + while (le_dynamic_channel_helper_map_.count(next_assigned_dynamic_le_psm_)) { + next_assigned_dynamic_le_psm_++; + if (next_assigned_dynamic_le_psm_ > 0xff) { + next_assigned_dynamic_le_psm_ = 0x80; + } + } + assigned_dynamic_le_psm_.emplace(next_assigned_dynamic_le_psm_); + return next_assigned_dynamic_le_psm_; +} + +void bluetooth::shim::L2CA_FreeLePSM(uint16_t psm) { + assigned_dynamic_le_psm_.erase(psm); +} + uint16_t bluetooth::shim::L2CA_RegisterLECoc(uint16_t psm, const tL2CAP_APPL_INFO& callbacks, uint16_t sec_level) {