Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2fed4160 authored by Hansong Zhang's avatar Hansong Zhang
Browse files

RFCOMM: Use std map to store channel map

Instead of using legacy fixed size array

Test: Speaker
Bug: 179117950
Tag: #stability
Change-Id: Ibc8a2e947f218a6d5870cc7a9566306ddc7eb2b3
parent 47b46f54
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -1110,6 +1110,7 @@ int PORT_WriteData(uint16_t handle, const char* p_data, uint16_t max_len,
void RFCOMM_Init(void) {
  memset(&rfc_cb, 0, sizeof(tRFC_CB)); /* Init RFCOMM control block */
  rfcomm_security_records = {};
  rfc_lcid_mcb = {};

  rfc_cb.rfc.last_mux = MAX_BD_CONNECTIONS;

+3 −2
Original line number Diff line number Diff line
@@ -235,8 +235,6 @@ typedef struct {
  MX_FRAME rx_frame;
  tL2CAP_APPL_INFO reg_info; /* L2CAP Registration info */

  /* MCB based on the L2CAP's lcid */
  tRFC_MCB* p_rfc_lcid_mcb[MAX_L2CAP_CHANNELS];
  bool peer_rx_disabled; /* If true peer sent FCOFF */
  uint8_t last_mux;      /* Last mux allocated */
  uint8_t last_port_index;  // Index of last port allocated in rfc_cb.port
@@ -254,6 +252,9 @@ extern tRFC_CB rfc_cb;
extern std::unordered_map<uint32_t /* scn */, uint16_t /* sec_mask */>
    rfcomm_security_records;

/* MCB based on the L2CAP's lcid */
extern std::unordered_map<uint16_t /* cid */, tRFC_MCB*> rfc_lcid_mcb;

/* Timer running on the multiplexor channel while no DLCI connection is open */
#define RFC_MCB_INIT_INACT_TIMER 60 /* in seconds */

+9 −22
Original line number Diff line number Diff line
@@ -357,11 +357,7 @@ void RFCOMM_CongestionStatusInd(uint16_t lcid, bool is_congested) {
 *
 ******************************************************************************/
tRFC_MCB* rfc_find_lcid_mcb(uint16_t lcid) {
  if (lcid - L2CAP_BASE_APPL_CID >= MAX_L2CAP_CHANNELS) {
    RFCOMM_TRACE_ERROR("rfc_find_lcid_mcb LCID:0x%x", lcid);
    return nullptr;
  } else {
    tRFC_MCB* p_mcb = rfc_cb.rfc.p_rfc_lcid_mcb[lcid - L2CAP_BASE_APPL_CID];
  tRFC_MCB* p_mcb = rfc_lcid_mcb[lcid];
  if (p_mcb != nullptr) {
    if (p_mcb->lcid != lcid) {
      LOG(WARNING) << __func__ << "LCID reused lcid=:" << loghex(lcid)
@@ -371,7 +367,6 @@ tRFC_MCB* rfc_find_lcid_mcb(uint16_t lcid) {
  }
  return p_mcb;
}
}

/*******************************************************************************
 *
@@ -381,14 +376,6 @@ tRFC_MCB* rfc_find_lcid_mcb(uint16_t lcid) {
 *
 ******************************************************************************/
void rfc_save_lcid_mcb(tRFC_MCB* p_mcb, uint16_t lcid) {
  if (lcid < L2CAP_BASE_APPL_CID) {
    LOG(ERROR) << __func__ << ": LCID " << lcid << " is too small";
    return;
  }
  auto mcb_index = static_cast<size_t>(lcid - L2CAP_BASE_APPL_CID);
  if (mcb_index >= MAX_L2CAP_CHANNELS) {
    LOG(ERROR) << __func__ << ": LCID " << lcid << " is too large";
    return;
  }
  rfc_cb.rfc.p_rfc_lcid_mcb[mcb_index] = p_mcb;
  auto mcb_index = static_cast<size_t>(lcid);
  rfc_lcid_mcb[mcb_index] = p_mcb;
}
+1 −0
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@

tRFC_CB rfc_cb;
std::unordered_map<uint32_t, uint16_t> rfcomm_security_records;
std::unordered_map<uint16_t /* sci */, tRFC_MCB*> rfc_lcid_mcb;

/*******************************************************************************
 *