From 65acfa23cf2b3abd92a0003d1ceaf60597eaf74b Mon Sep 17 00:00:00 2001 From: Hansong Zhang Date: Thu, 24 Sep 2020 21:32:08 -0700 Subject: [PATCH] L2CAP module will send ConfigReq for you No need to send it in client code. Will get rid of the fake L2CA_ConfigReq() next. Bug: 159815595 Tag: #refactor Test: compile & verify basic functions working Change-Id: I66e2efad144e76eb6abfa6d421e12ae4a60d8e1f --- stack/include/l2c_api.h | 1 + stack/l2cap/l2c_api.cc | 5 +++++ stack/l2cap/l2c_csm.cc | 19 +++++++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/stack/include/l2c_api.h b/stack/include/l2c_api.h index e68cb6049..06c4d6e5f 100644 --- a/stack/include/l2c_api.h +++ b/stack/include/l2c_api.h @@ -492,6 +492,7 @@ extern bool L2CA_ErtmConnectRsp(const RawAddress& p_bd_addr, uint8_t id, * ******************************************************************************/ extern bool L2CA_ConfigReq(uint16_t cid, tL2CAP_CFG_INFO* p_cfg); +extern bool L2CA_ConfigReq2(uint16_t cid, tL2CAP_CFG_INFO* p_cfg); /******************************************************************************* * diff --git a/stack/l2cap/l2c_api.cc b/stack/l2cap/l2c_api.cc index 1ae7cea8b..398d4fd40 100644 --- a/stack/l2cap/l2c_api.cc +++ b/stack/l2cap/l2c_api.cc @@ -845,6 +845,11 @@ bool L2CA_ErtmConnectRsp(const RawAddress& p_bd_addr, uint8_t id, uint16_t lcid, * ******************************************************************************/ bool L2CA_ConfigReq(uint16_t cid, tL2CAP_CFG_INFO* p_cfg) { + // Client code should no longer send config req. L2CAP will do it for you. + return false; +} + +bool L2CA_ConfigReq2(uint16_t cid, tL2CAP_CFG_INFO* p_cfg) { if (bluetooth::shim::is_gd_shim_enabled()) { return bluetooth::shim::L2CA_ConfigReq(cid, p_cfg); } diff --git a/stack/l2cap/l2c_csm.cc b/stack/l2cap/l2c_csm.cc index eb75bcd11..bad4b4919 100644 --- a/stack/l2cap/l2c_csm.cc +++ b/stack/l2cap/l2c_csm.cc @@ -54,6 +54,19 @@ static void l2c_csm_w4_l2ca_disconnect_rsp(tL2C_CCB* p_ccb, uint16_t event, static const char* l2c_csm_get_event_name(uint16_t event); +// Send a config request on user's behalf +static void l2c_csm_send_config_req(uint16_t local_cid, uint16_t mtu, + tL2CAP_ERTM_INFO ertm_info) { + tL2CAP_CFG_INFO config{}; + config.mtu_present = true; + config.mtu = mtu; + if (ertm_info.preferred_mode != L2CAP_FCR_BASIC_MODE) { + config.fcr_present = true; + config.fcr = kDefaultErtmOptions; + } + L2CA_ConfigReq2(local_cid, &config); +} + /******************************************************************************* * * Function l2c_csm_execute @@ -425,6 +438,8 @@ static void l2c_csm_term_w4_sec_comp(tL2C_CCB* p_ccb, uint16_t event, (*p_ccb->p_rcb->api.pL2CA_ConnectInd_Cb)( p_ccb->p_lcb->remote_bd_addr, p_ccb->local_cid, p_ccb->p_rcb->psm, p_ccb->remote_id); + l2c_csm_send_config_req(p_ccb->local_cid, p_ccb->p_rcb->my_mtu, + p_ccb->p_rcb->ertm_info); } else { /* ** L2CAP Connect Response will be sent out by 3 sec timer expiration @@ -544,6 +559,8 @@ static void l2c_csm_w4_l2cap_connect_rsp(tL2C_CCB* p_ccb, uint16_t event, p_ccb->local_cid); (*p_ccb->p_rcb->api.pL2CA_ConnectCfm_Cb)(local_cid, L2CAP_CONN_OK); + l2c_csm_send_config_req(p_ccb->local_cid, p_ccb->p_rcb->my_mtu, + p_ccb->p_rcb->ertm_info); break; case L2CEVT_L2CAP_CONNECT_RSP_PND: /* Got peer connect pending */ @@ -701,6 +718,8 @@ static void l2c_csm_w4_l2ca_connect_rsp(tL2C_CCB* p_ccb, uint16_t event, (*p_ccb->p_rcb->api.pL2CA_ConnectInd_Cb)( p_ccb->p_lcb->remote_bd_addr, p_ccb->local_cid, p_ccb->p_rcb->psm, p_ccb->remote_id); + l2c_csm_send_config_req(p_ccb->local_cid, p_ccb->p_rcb->my_mtu, + p_ccb->p_rcb->ertm_info); break; } } -- 2.11.0