From acc416288eb93f78fdf87ec965b971337350c3c9 Mon Sep 17 00:00:00 2001 From: Hansong Zhang Date: Fri, 25 Sep 2020 11:31:02 -0700 Subject: [PATCH] L2CA_ConfigReq and L2CA_ConfigRsp are internal now Only used by l2c_csm, so we make an internal version instead. Bug: 159815595 Tag: #refactor Test: compile & verify basic functions working Change-Id: If725c705bcbabec025cb16d063cd4d4aa4b319f9 --- stack/include/l2c_api.h | 23 ------------- stack/l2cap/l2c_api.cc | 89 ------------------------------------------------- stack/l2cap/l2c_csm.cc | 36 ++++++++++---------- 3 files changed, 18 insertions(+), 130 deletions(-) diff --git a/stack/include/l2c_api.h b/stack/include/l2c_api.h index e68cb6049..a0782af6a 100644 --- a/stack/include/l2c_api.h +++ b/stack/include/l2c_api.h @@ -484,29 +484,6 @@ extern bool L2CA_ErtmConnectRsp(const RawAddress& p_bd_addr, uint8_t id, /******************************************************************************* * - * Function L2CA_ConfigReq - * - * Description Higher layers call this function to send configuration. - * - * Returns true if configuration sent, else false - * - ******************************************************************************/ -extern bool L2CA_ConfigReq(uint16_t cid, tL2CAP_CFG_INFO* p_cfg); - -/******************************************************************************* - * - * Function L2CA_ConfigRsp - * - * Description Higher layers call this function to send a configuration - * response. - * - * Returns true if configuration response sent, else false - * - ******************************************************************************/ -extern bool L2CA_ConfigRsp(uint16_t cid, tL2CAP_CFG_INFO* p_cfg); - -/******************************************************************************* - * * Function L2CA_DisconnectReq * * Description Higher layers call this function to disconnect a channel. diff --git a/stack/l2cap/l2c_api.cc b/stack/l2cap/l2c_api.cc index 1ae7cea8b..82f4f1542 100644 --- a/stack/l2cap/l2c_api.cc +++ b/stack/l2cap/l2c_api.cc @@ -835,95 +835,6 @@ bool L2CA_ErtmConnectRsp(const RawAddress& p_bd_addr, uint8_t id, uint16_t lcid, /******************************************************************************* * - * Function L2CA_ConfigReq - * - * Description Higher layers call this function to send configuration. - * - * Note: The FCR options of p_cfg are not used. - * - * Returns true if configuration sent, else false - * - ******************************************************************************/ -bool L2CA_ConfigReq(uint16_t cid, tL2CAP_CFG_INFO* p_cfg) { - if (bluetooth::shim::is_gd_shim_enabled()) { - return bluetooth::shim::L2CA_ConfigReq(cid, p_cfg); - } - - tL2C_CCB* p_ccb; - - L2CAP_TRACE_API( - "L2CA_ConfigReq() CID 0x%04x: fcr_present:%d (mode %d) mtu_present:%d " - "(%d)", - cid, p_cfg->fcr_present, p_cfg->fcr.mode, p_cfg->mtu_present, p_cfg->mtu); - - /* Find the channel control block. We don't know the link it is on. */ - p_ccb = l2cu_find_ccb_by_cid(NULL, cid); - if (p_ccb == NULL) { - L2CAP_TRACE_WARNING("L2CAP - no CCB for L2CA_cfg_req, CID: %d", cid); - return (false); - } - - /* We need to have at least one mode type common with the peer */ - if (!l2c_fcr_adj_our_req_options(p_ccb, p_cfg)) return (false); - - /* Don't adjust FCR options if not used */ - if ((!p_cfg->fcr_present) || (p_cfg->fcr.mode == L2CAP_FCR_BASIC_MODE)) { - /* FCR and FCS options are not used in basic mode */ - p_cfg->fcs_present = false; - p_cfg->ext_flow_spec_present = false; - - if ((p_cfg->mtu_present) && (p_cfg->mtu > L2CAP_MTU_SIZE)) { - L2CAP_TRACE_WARNING("L2CAP - adjust MTU: %u too large", p_cfg->mtu); - p_cfg->mtu = L2CAP_MTU_SIZE; - } - } - - /* Save the adjusted configuration in case it needs to be used for - * renegotiation */ - p_ccb->our_cfg = *p_cfg; - - l2c_csm_execute(p_ccb, L2CEVT_L2CA_CONFIG_REQ, p_cfg); - - return (true); -} - -/******************************************************************************* - * - * Function L2CA_ConfigRsp - * - * Description Higher layers call this function to send a configuration - * response. - * - * Returns true if configuration response sent, else false - * - ******************************************************************************/ -bool L2CA_ConfigRsp(uint16_t cid, tL2CAP_CFG_INFO* p_cfg) { - if (bluetooth::shim::is_gd_shim_enabled()) { - return bluetooth::shim::L2CA_ConfigRsp(cid, p_cfg); - } - - tL2C_CCB* p_ccb; - - L2CAP_TRACE_API( - "L2CA_ConfigRsp() CID: 0x%04x Result: %d MTU present:%d Flush TO:%d " - "FCR:%d FCS:%d", - cid, p_cfg->result, p_cfg->mtu_present, p_cfg->flush_to_present, - p_cfg->fcr_present, p_cfg->fcs_present); - - /* Find the channel control block. We don't know the link it is on. */ - p_ccb = l2cu_find_ccb_by_cid(NULL, cid); - if (p_ccb == NULL) { - L2CAP_TRACE_WARNING("L2CAP - no CCB for L2CA_cfg_rsp, CID: %d", cid); - return (false); - } - - l2c_csm_execute(p_ccb, L2CEVT_L2CA_CONFIG_RSP, p_cfg); - - return (true); -} - -/******************************************************************************* - * * Function L2CA_DisconnectReq * * Description Higher layers call this function to disconnect a channel. diff --git a/stack/l2cap/l2c_csm.cc b/stack/l2cap/l2c_csm.cc index fb57b3381..eadd32492 100644 --- a/stack/l2cap/l2c_csm.cc +++ b/stack/l2cap/l2c_csm.cc @@ -54,17 +54,24 @@ 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) { +// Send a config request and adjust the state machine +static void l2c_csm_send_config_req(tL2C_CCB* p_ccb) { tL2CAP_CFG_INFO config{}; config.mtu_present = true; - config.mtu = mtu; - if (ertm_info.preferred_mode != L2CAP_FCR_BASIC_MODE) { + config.mtu = p_ccb->p_rcb->my_mtu; + if (p_ccb->p_rcb->ertm_info.preferred_mode != L2CAP_FCR_BASIC_MODE) { config.fcr_present = true; config.fcr = kDefaultErtmOptions; } - L2CA_ConfigReq(local_cid, &config); + p_ccb->our_cfg = config; + l2c_csm_execute(p_ccb, L2CEVT_L2CA_CONFIG_REQ, &config); +} + +// Send a config response with result OK and adjust the state machine +static void l2c_csm_send_config_rsp_ok(tL2C_CCB* p_ccb) { + tL2CAP_CFG_INFO config{}; + config.result = L2CAP_CFG_OK; + l2c_csm_execute(p_ccb, L2CEVT_L2CA_CONFIG_RSP, &config); } /******************************************************************************* @@ -438,8 +445,7 @@ 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); + l2c_csm_send_config_req(p_ccb); } else { /* ** L2CAP Connect Response will be sent out by 3 sec timer expiration @@ -559,8 +565,7 @@ 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); + l2c_csm_send_config_req(p_ccb); break; case L2CEVT_L2CAP_CONNECT_RSP_PND: /* Got peer connect pending */ @@ -718,8 +723,7 @@ 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); + l2c_csm_send_config_req(p_ccb); break; } } @@ -761,9 +765,7 @@ static void l2c_csm_config(tL2C_CCB* p_ccb, uint16_t event, void* p_data) { "L2CAP - Calling Config_Req_Cb(), CID: 0x%04x, C-bit %d", p_ccb->local_cid, (p_cfg->flags & L2CAP_CFG_FLAGS_MASK_CONT)); (*p_ccb->p_rcb->api.pL2CA_ConfigInd_Cb)(p_ccb->local_cid, p_cfg); - tL2CAP_CFG_INFO response = {}; - response.result = L2CAP_CFG_OK; - L2CA_ConfigRsp(p_ccb->local_cid, &response); + l2c_csm_send_config_rsp_ok(p_ccb); } else if (cfg_result == L2CAP_PEER_CFG_DISCONNECT) { /* Disconnect if channels are incompatible */ L2CAP_TRACE_EVENT("L2CAP - incompatible configurations disconnect"); @@ -996,9 +998,7 @@ static void l2c_csm_open(tL2C_CCB* p_ccb, uint16_t event, void* p_data) { cfg_result = l2cu_process_peer_cfg_req(p_ccb, p_cfg); if (cfg_result == L2CAP_PEER_CFG_OK) { (*p_ccb->p_rcb->api.pL2CA_ConfigInd_Cb)(p_ccb->local_cid, p_cfg); - tL2CAP_CFG_INFO response = {}; - response.result = L2CAP_CFG_OK; - L2CA_ConfigRsp(p_ccb->local_cid, &response); + l2c_csm_send_config_rsp_ok(p_ccb); } /* Error in config parameters: reset state and config flag */ -- 2.11.0