From 7bfe49749a1f3de050e118b0d9e74b496c601942 Mon Sep 17 00:00:00 2001 From: Hansong Zhang Date: Sun, 27 Sep 2020 16:12:43 -0700 Subject: [PATCH] L2cap channel cb: Store who initiated dynamic channel Use pL2CA_ConfigCfm_Cb to let user know the direction. Later the user can run check in ConnectInd or ConnectCfm callback. Bug: 159815595 Tag: #refactor Test: compile & verify basic functions working Change-Id: Iae663e6bea0fc9426c5dfbbfc52bd1ae848f2965 --- stack/avct/avct_l2c.cc | 2 +- stack/avct/avct_l2c_br.cc | 2 +- stack/avdt/avdt_l2c.cc | 2 +- stack/bnep/bnep_main.cc | 2 +- stack/gap/gap_conn.cc | 2 +- stack/gatt/gatt_main.cc | 2 +- stack/hid/hidd_conn.cc | 2 +- stack/hid/hidh_conn.cc | 2 +- stack/include/l2c_api.h | 6 ++++-- stack/l2cap/l2c_api.cc | 4 ++++ stack/l2cap/l2c_ble.cc | 2 ++ stack/l2cap/l2c_csm.cc | 4 ++-- stack/l2cap/l2c_int.h | 2 ++ stack/l2cap/l2c_main.cc | 1 + stack/rfcomm/rfc_l2cap_if.cc | 4 ++-- stack/sdp/sdp_main.cc | 2 +- 16 files changed, 26 insertions(+), 15 deletions(-) diff --git a/stack/avct/avct_l2c.cc b/stack/avct/avct_l2c.cc index 33b0028cf..adac96135 100644 --- a/stack/avct/avct_l2c.cc +++ b/stack/avct/avct_l2c.cc @@ -216,7 +216,7 @@ void avct_l2c_connect_cfm_cback(uint16_t lcid, uint16_t result) { * Returns void * ******************************************************************************/ -void avct_l2c_config_cfm_cback(uint16_t lcid, uint16_t result) { +void avct_l2c_config_cfm_cback(uint16_t lcid, uint16_t initiator) { tAVCT_LCB* p_lcb; /* look up lcb for this channel */ diff --git a/stack/avct/avct_l2c_br.cc b/stack/avct/avct_l2c_br.cc index 1db9ec8b0..a11ece8a4 100644 --- a/stack/avct/avct_l2c_br.cc +++ b/stack/avct/avct_l2c_br.cc @@ -148,7 +148,7 @@ void avct_l2c_br_connect_cfm_cback(uint16_t lcid, uint16_t result) { * Returns void * ******************************************************************************/ -void avct_l2c_br_config_cfm_cback(uint16_t lcid, uint16_t result) { +void avct_l2c_br_config_cfm_cback(uint16_t lcid, uint16_t initiator) { tAVCT_BCB* p_lcb; /* look up lcb for this channel */ diff --git a/stack/avdt/avdt_l2c.cc b/stack/avdt/avdt_l2c.cc index fa2dfb183..f1d3515c7 100644 --- a/stack/avdt/avdt_l2c.cc +++ b/stack/avdt/avdt_l2c.cc @@ -289,7 +289,7 @@ void avdt_l2c_connect_cfm_cback(uint16_t lcid, uint16_t result) { * Returns void * ******************************************************************************/ -void avdt_l2c_config_cfm_cback(uint16_t lcid, uint16_t result) { +void avdt_l2c_config_cfm_cback(uint16_t lcid, uint16_t initiator) { AvdtpTransportChannel* p_tbl; AVDT_TRACE_DEBUG("%s: lcid: %d", __func__, lcid); diff --git a/stack/bnep/bnep_main.cc b/stack/bnep/bnep_main.cc index 7469dba9e..ba3ee0f93 100644 --- a/stack/bnep/bnep_main.cc +++ b/stack/bnep/bnep_main.cc @@ -211,7 +211,7 @@ static void bnep_config_ind(uint16_t l2cap_cid, tL2CAP_CFG_INFO* p_cfg) { * Returns void * ******************************************************************************/ -static void bnep_config_cfm(uint16_t l2cap_cid, uint16_t result) { +static void bnep_config_cfm(uint16_t l2cap_cid, uint16_t initiator) { tBNEP_CONN* p_bcb; BNEP_TRACE_EVENT("BNEP - Rcvd cfg cfm, CID: 0x%x", l2cap_cid); diff --git a/stack/gap/gap_conn.cc b/stack/gap/gap_conn.cc index bfda3d0ba..13b12e7e6 100644 --- a/stack/gap/gap_conn.cc +++ b/stack/gap/gap_conn.cc @@ -783,7 +783,7 @@ static void gap_config_ind(uint16_t l2cap_cid, tL2CAP_CFG_INFO* p_cfg) { * Returns void * ******************************************************************************/ -static void gap_config_cfm(uint16_t l2cap_cid, uint16_t result) { +static void gap_config_cfm(uint16_t l2cap_cid, uint16_t initiator) { tGAP_CCB* p_ccb; /* Find CCB based on CID */ diff --git a/stack/gatt/gatt_main.cc b/stack/gatt/gatt_main.cc index 5c0ad3bcb..07d6190e9 100644 --- a/stack/gatt/gatt_main.cc +++ b/stack/gatt/gatt_main.cc @@ -614,7 +614,7 @@ static void gatt_l2cif_connect_cfm_cback(uint16_t lcid, uint16_t result) { } /** This is the L2CAP config confirm callback function */ -void gatt_l2cif_config_cfm_cback(uint16_t lcid, uint16_t result) { +void gatt_l2cif_config_cfm_cback(uint16_t lcid, uint16_t initiator) { /* look up clcb for this channel */ tGATT_TCB* p_tcb = gatt_find_tcb_by_cid(lcid); if (!p_tcb) return; diff --git a/stack/hid/hidd_conn.cc b/stack/hid/hidd_conn.cc index 4518d3e88..ed4f4cf02 100644 --- a/stack/hid/hidd_conn.cc +++ b/stack/hid/hidd_conn.cc @@ -267,7 +267,7 @@ static void hidd_l2cif_config_ind(uint16_t cid, tL2CAP_CFG_INFO* p_cfg) { * Returns void * ******************************************************************************/ -static void hidd_l2cif_config_cfm(uint16_t cid, uint16_t result) { +static void hidd_l2cif_config_cfm(uint16_t cid, uint16_t initiator) { tHID_CONN* p_hcon; HIDD_TRACE_EVENT("%s: cid=%04x", __func__, cid); diff --git a/stack/hid/hidh_conn.cc b/stack/hid/hidh_conn.cc index e7d90b0ab..794d04ced 100644 --- a/stack/hid/hidh_conn.cc +++ b/stack/hid/hidh_conn.cc @@ -376,7 +376,7 @@ static void hidh_l2cif_config_ind(uint16_t l2cap_cid, tL2CAP_CFG_INFO* p_cfg) { * Returns void * ******************************************************************************/ -static void hidh_l2cif_config_cfm(uint16_t l2cap_cid, uint16_t result) { +static void hidh_l2cif_config_cfm(uint16_t l2cap_cid, uint16_t initiator) { uint8_t dhandle; tHID_CONN* p_hcon = NULL; uint32_t reason; diff --git a/stack/include/l2c_api.h b/stack/include/l2c_api.h index ab29e1589..84cd01378 100644 --- a/stack/include/l2c_api.h +++ b/stack/include/l2c_api.h @@ -194,10 +194,12 @@ typedef void(tL2CA_CONNECT_CFM_CB)(uint16_t, uint16_t); */ typedef void(tL2CA_CONFIG_IND_CB)(uint16_t, tL2CAP_CFG_INFO*); +constexpr uint16_t L2CAP_INITIATOR_LOCAL = 1; +constexpr uint16_t L2CAP_INITIATOR_REMOTE = 0; /* Configuration confirm callback prototype. Parameters are * Local CID assigned to the connection - * Config result (L2CA_CONN_OK) - * If there is an error, tL2CA_ERROR_CB is invoked + * Initiator (1 for local, 0 for remote) + * If there is an error, tL2CA_ERROR_CB is invoked */ typedef void(tL2CA_CONFIG_CFM_CB)(uint16_t, uint16_t); diff --git a/stack/l2cap/l2c_api.cc b/stack/l2cap/l2c_api.cc index 7fa972aee..762d49bf6 100644 --- a/stack/l2cap/l2c_api.cc +++ b/stack/l2cap/l2c_api.cc @@ -364,6 +364,8 @@ uint16_t L2CA_ConnectReq(uint16_t psm, const RawAddress& p_bd_addr) { /* Save registration info */ p_ccb->p_rcb = p_rcb; + p_ccb->connection_initiator = L2CAP_INITIATOR_LOCAL; + /* If link is up, start the L2CAP connection */ if (p_lcb->link_state == LST_CONNECTED) { l2c_csm_execute(p_ccb, L2CEVT_L2CA_CONNECT_REQ, nullptr); @@ -568,6 +570,8 @@ uint16_t L2CA_ConnectLECocReq(uint16_t psm, const RawAddress& p_bd_addr, /* Save registration info */ p_ccb->p_rcb = p_rcb; + p_ccb->connection_initiator = L2CAP_INITIATOR_LOCAL; + /* Save the configuration */ if (p_cfg) { p_ccb->local_conn_cfg = *p_cfg; diff --git a/stack/l2cap/l2c_ble.cc b/stack/l2cap/l2c_ble.cc index 5e7909d58..e760d659b 100644 --- a/stack/l2cap/l2c_ble.cc +++ b/stack/l2cap/l2c_ble.cc @@ -643,6 +643,8 @@ void l2cble_process_sig_cmd(tL2C_LCB* p_lcb, uint8_t* p, uint16_t pkt_len) { p_ccb->is_first_seg = true; p_ccb->peer_cfg.fcr.mode = L2CAP_FCR_LE_COC_MODE; + p_ccb->connection_initiator = L2CAP_INITIATOR_REMOTE; + l2c_csm_execute(p_ccb, L2CEVT_L2CAP_CONNECT_REQ, &con_info); break; diff --git a/stack/l2cap/l2c_csm.cc b/stack/l2cap/l2c_csm.cc index bb2e69eb4..7c2224337 100644 --- a/stack/l2cap/l2c_csm.cc +++ b/stack/l2cap/l2c_csm.cc @@ -757,7 +757,7 @@ static void l2c_csm_config(tL2C_CCB* p_ccb, uint16_t event, void* p_data) { if (p_ccb->config_done & OB_CFG_DONE) { if (p_ccb->remote_config_rsp_result == L2CAP_CFG_OK) { (*p_ccb->p_rcb->api.pL2CA_ConfigCfm_Cb)( - p_ccb->local_cid, p_ccb->remote_config_rsp_result); + p_ccb->local_cid, p_ccb->connection_initiator); } else { (*p_ccb->p_rcb->api.pL2CA_Error_Cb)(p_ccb->local_cid, L2CAP_CFG_FAILED_NO_REASON); @@ -830,7 +830,7 @@ static void l2c_csm_config(tL2C_CCB* p_ccb, uint16_t event, void* p_data) { p_ccb->remote_config_rsp_result = p_cfg->result; if (p_ccb->config_done & IB_CFG_DONE) { (*p_ccb->p_rcb->api.pL2CA_ConfigCfm_Cb)(p_ccb->local_cid, - p_cfg->result); + p_ccb->connection_initiator); } break; diff --git a/stack/l2cap/l2c_int.h b/stack/l2cap/l2c_int.h index e6e73dcb0..61c781f31 100644 --- a/stack/l2cap/l2c_int.h +++ b/stack/l2cap/l2c_int.h @@ -253,6 +253,8 @@ typedef struct t_l2c_ccb { #define CCB_FLAG_SENT_PENDING 0x02 /* already sent pending response */ uint8_t flags; + bool connection_initiator; /* true if we sent ConnectReq */ + tL2CAP_CFG_INFO our_cfg; /* Our saved configuration options */ tL2CAP_CFG_INFO peer_cfg; /* Peer's saved configuration options */ diff --git a/stack/l2cap/l2c_main.cc b/stack/l2cap/l2c_main.cc index 77a0cc5cc..cea264a77 100644 --- a/stack/l2cap/l2c_main.cc +++ b/stack/l2cap/l2c_main.cc @@ -392,6 +392,7 @@ static void process_l2cap_cmd(tL2C_LCB* p_lcb, uint8_t* p, uint16_t pkt_len) { p_ccb->remote_id = id; p_ccb->p_rcb = p_rcb; p_ccb->remote_cid = rcid; + p_ccb->connection_initiator = L2CAP_INITIATOR_REMOTE; if (p_rcb->psm == BT_PSM_RFCOMM) { btsnoop_get_interface()->add_rfc_l2c_channel( diff --git a/stack/rfcomm/rfc_l2cap_if.cc b/stack/rfcomm/rfc_l2cap_if.cc index 733301958..a3f0b6945 100644 --- a/stack/rfcomm/rfc_l2cap_if.cc +++ b/stack/rfcomm/rfc_l2cap_if.cc @@ -197,14 +197,14 @@ void RFCOMM_ConfigInd(uint16_t lcid, tL2CAP_CFG_INFO* p_cfg) { * event to the FSM. * ******************************************************************************/ -void RFCOMM_ConfigCnf(uint16_t lcid, uint16_t result) { +void RFCOMM_ConfigCnf(uint16_t lcid, uint16_t initiator) { tRFC_MCB* p_mcb = rfc_find_lcid_mcb(lcid); if (!p_mcb) { RFCOMM_TRACE_ERROR("RFCOMM_ConfigCnf no MCB LCID:0x%x", lcid); return; } - uintptr_t result_as_ptr = result; + uintptr_t result_as_ptr = L2CAP_CFG_OK; rfc_mx_sm_execute(p_mcb, RFC_MX_EVENT_CONF_CNF, (void*)result_as_ptr); } diff --git a/stack/sdp/sdp_main.cc b/stack/sdp/sdp_main.cc index 71e27571b..5bd4807d5 100644 --- a/stack/sdp/sdp_main.cc +++ b/stack/sdp/sdp_main.cc @@ -209,7 +209,7 @@ static void sdp_config_ind(uint16_t l2cap_cid, tL2CAP_CFG_INFO* p_cfg) { * Returns void * ******************************************************************************/ -static void sdp_config_cfm(uint16_t l2cap_cid, uint16_t result) { +static void sdp_config_cfm(uint16_t l2cap_cid, uint16_t initiator) { tCONN_CB* p_ccb; SDP_TRACE_EVENT("SDP - Rcvd cfg cfm, CID: 0x%x", l2cap_cid); -- 2.11.0