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

Commit b430bc1d authored by Hansong Zhang's avatar Hansong Zhang
Browse files

L2cap: Auto send ConnectRsp

In the past, L2cap user can decide whether to accept or reject a
ConnectReq. If reject, the channel is closed.

Now let L2cap layer always auto accept the remote ConnectReq and start
config process. If the L2cap user wants to reject, they can send a
DisconnectReq. According to L2cap state machine, a DisconnectReq after
ConnectRsp terminates the channel, which is equivalent to sending a
negative ConnectRsp, as before.

Bug: 159815595
Tag: #refactor
Test: compile & verify basic functions working
Change-Id: Ibed56206148922356e8d9cb10650e9d82ab61225
parent cb2dcc08
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -120,8 +120,11 @@ void avct_l2c_connect_ind_cback(const RawAddress& bd_addr, uint16_t lcid,
    AVCT_TRACE_DEBUG("avct_l2c_connect_ind_cback: 0x%x, res: %d, ch_state: %d",
                     lcid, result, p_lcb->ch_state);
  }
  /* Send L2CAP connect rsp */
  L2CA_ConnectRsp(bd_addr, id, lcid, result, 0);

  /* If we reject the connection, send DisconnectReq */
  if (result != L2CAP_CONN_OK) {
    L2CA_DisconnectReq(lcid);
  }

  /* if result ok, proceed with connection */
  if (result == L2CAP_CONN_OK) {
+4 −2
Original line number Diff line number Diff line
@@ -88,8 +88,10 @@ void avct_l2c_br_connect_ind_cback(const RawAddress& bd_addr, uint16_t lcid,
  /* Set the FCR options: Browsing channel mandates ERTM */
  ertm_info.preferred_mode = L2CAP_FCR_ERTM_MODE;

  /* Send L2CAP connect rsp */
  L2CA_ConnectRsp(bd_addr, id, lcid, result, 0);
  /* If we reject the connection, send DisconnectReq */
  if (result != L2CAP_CONN_OK) {
    L2CA_DisconnectReq(lcid);
  }

  /* if result ok, proceed with connection */
  if (result == L2CAP_CONN_OK) {
+11 −14
Original line number Diff line number Diff line
@@ -74,10 +74,6 @@ static void avdt_sec_check_complete_term(const RawAddress* bd_addr,
  p_tbl = avdt_ad_tc_tbl_by_st(AVDT_CHAN_SIG, p_ccb, AVDT_AD_ST_SEC_ACP);
  if (p_tbl == NULL) return;

  /* Send response to the L2CAP layer. */
  L2CA_ConnectRsp(*bd_addr, p_tbl->id, p_tbl->lcid, L2CAP_CONN_OK,
                  L2CAP_CONN_OK);

  /* store idx in LCID table, store LCID in routing table */
  avdtp_cb.ad.lcid_tbl[p_tbl->lcid - L2CAP_BASE_APPL_CID] =
      avdt_ad_tc_tbl_to_idx(p_tbl);
@@ -199,11 +195,13 @@ void avdt_l2c_connect_ind_cback(const RawAddress& bd_addr, uint16_t lcid,
    }
  }

  /* Send L2CAP connect rsp */
  L2CA_ConnectRsp(bd_addr, id, lcid, result, 0);
  /* If we reject the connection, send DisconnectReq */
  if (result != L2CAP_CONN_OK) {
    L2CA_DisconnectReq(lcid);
    return;
  }

  /* if result ok, proceed with connection */
  if (result == L2CAP_CONN_OK) {
  /* store idx in LCID table, store LCID in routing table */
  avdtp_cb.ad.lcid_tbl[lcid - L2CAP_BASE_APPL_CID] =
      avdt_ad_tc_tbl_to_idx(p_tbl);
@@ -212,7 +210,6 @@ void avdt_l2c_connect_ind_cback(const RawAddress& bd_addr, uint16_t lcid,
  /* transition to configuration state */
  p_tbl->state = AVDT_AD_ST_CFG;
}
}

static void avdt_on_l2cap_error(uint16_t lcid, uint16_t result) {
  avdt_l2c_disconnect(lcid);
+1 −4
Original line number Diff line number Diff line
@@ -115,7 +115,7 @@ static void bnep_connect_ind(const RawAddress& bd_addr, uint16_t l2cap_cid,
  /* no more resources to handle the connection, reject the connection.    */
  if (!(bnep_cb.profile_registered) || (p_bcb) ||
      ((p_bcb = bnepu_allocate_bcb(bd_addr)) == NULL)) {
    L2CA_ConnectRsp(bd_addr, l2cap_id, l2cap_cid, L2CAP_CONN_NO_PSM, 0);
    L2CA_DisconnectReq(l2cap_cid);
    return;
  }

@@ -125,9 +125,6 @@ static void bnep_connect_ind(const RawAddress& bd_addr, uint16_t l2cap_cid,
  /* Save the L2CAP Channel ID. */
  p_bcb->l2cap_cid = l2cap_cid;

  /* Send response to the L2CAP layer. */
  L2CA_ConnectRsp(bd_addr, l2cap_id, l2cap_cid, L2CAP_CONN_OK, L2CAP_CONN_OK);

  /* Start timer waiting for config setup */
  alarm_set_on_mloop(p_bcb->conn_timer, BNEP_CONN_TIMEOUT_MS,
                     bnep_conn_timer_timeout, p_bcb);
+0 −4
Original line number Diff line number Diff line
@@ -615,10 +615,6 @@ static void gap_connect_ind(const RawAddress& bd_addr, uint16_t l2cap_cid,
  p_ccb->rem_dev_address = bd_addr;
  p_ccb->connection_id = l2cap_cid;

  /* Send response to the L2CAP layer. */
  if (p_ccb->transport == BT_TRANSPORT_BR_EDR)
    L2CA_ConnectRsp(bd_addr, l2cap_id, l2cap_cid, L2CAP_CONN_OK, L2CAP_CONN_OK);

  if (p_ccb->transport == BT_TRANSPORT_LE) {
    L2CA_ConnectLECocRsp(bd_addr, l2cap_id, l2cap_cid, L2CAP_CONN_OK,
                         L2CAP_CONN_OK, &p_ccb->local_coc_cfg);
Loading