From 30a07c56e1afb07482f939cf40478c168c0660da Mon Sep 17 00:00:00 2001 From: Hansong Zhang Date: Sat, 26 Sep 2020 16:58:47 -0700 Subject: [PATCH] l2c_csm: Use pL2CA_Error_Cb on error Note that we only have two result codes, because the user only needs to know whether it's during ConnectRsp or ConfigRsp (except for HIDH retry), which we need further research. Bug: 159815595 Tag: #refactor Test: compile & verify basic functions working Change-Id: I24aa7bf8487c9b2b69fc455cfdb52a7ec758b90b --- stack/avct/avct_l2c.cc | 4 ++-- stack/avct/avct_l2c_br.cc | 4 ++-- stack/avdt/avdt_l2c.cc | 4 ++-- stack/bnep/bnep_main.cc | 4 ++-- stack/gap/gap_conn.cc | 4 ---- stack/gatt/gatt_main.cc | 2 +- stack/hid/hidd_conn.cc | 4 ++-- stack/hid/hidh_conn.cc | 5 +++-- stack/l2cap/l2c_csm.cc | 51 +++++++++++++++++--------------------------- stack/rfcomm/rfc_l2cap_if.cc | 1 - stack/rfcomm/rfc_mx_fsm.cc | 3 +-- stack/sdp/sdp_main.cc | 4 ++-- 12 files changed, 37 insertions(+), 53 deletions(-) diff --git a/stack/avct/avct_l2c.cc b/stack/avct/avct_l2c.cc index b2d60b41b..cbdf406df 100644 --- a/stack/avct/avct_l2c.cc +++ b/stack/avct/avct_l2c.cc @@ -188,7 +188,7 @@ void avct_l2c_connect_cfm_cback(uint16_t lcid, uint16_t result) { } /* else failure */ else { - avct_on_l2cap_error(lcid, result); + LOG(ERROR) << __func__ << ": invoked with non OK status"; } } else if (p_lcb->conflict_lcid == lcid) { /* we must be in AVCT_CH_CFG state for the ch_lcid channel */ @@ -233,7 +233,7 @@ void avct_l2c_config_cfm_cback(uint16_t lcid, uint16_t result) { } /* else failure */ else { - avct_on_l2cap_error(lcid, result); + LOG(ERROR) << __func__ << ": invoked with non OK status"; } } AVCT_TRACE_DEBUG("ch_state cfc: %d ", p_lcb->ch_state); diff --git a/stack/avct/avct_l2c_br.cc b/stack/avct/avct_l2c_br.cc index e7327010c..b3f14043c 100644 --- a/stack/avct/avct_l2c_br.cc +++ b/stack/avct/avct_l2c_br.cc @@ -129,7 +129,7 @@ void avct_l2c_br_connect_cfm_cback(uint16_t lcid, uint16_t result) { if ((p_lcb == NULL) || (p_lcb->ch_state != AVCT_CH_CONN)) return; if (result != L2CAP_CONN_OK) { - avct_br_on_l2cap_error(lcid, result); + LOG(ERROR) << __func__ << ": invoked with non OK status"; return; } @@ -162,7 +162,7 @@ void avct_l2c_br_config_cfm_cback(uint16_t lcid, uint16_t result) { } /* else failure */ else { - avct_br_on_l2cap_error(lcid, result); + LOG(ERROR) << __func__ << ": invoked with non OK status"; } } diff --git a/stack/avdt/avdt_l2c.cc b/stack/avdt/avdt_l2c.cc index 571f4ff5f..5d3e0f54c 100644 --- a/stack/avdt/avdt_l2c.cc +++ b/stack/avdt/avdt_l2c.cc @@ -281,7 +281,7 @@ void avdt_l2c_connect_cfm_cback(uint16_t lcid, uint16_t result) { /* failure; notify adaption that channel closed */ if (result != L2CAP_CONN_OK) { - avdt_on_l2cap_error(lcid, result); + LOG(ERROR) << __func__ << ": invoked with non OK status"; } } } @@ -315,7 +315,7 @@ void avdt_l2c_config_cfm_cback(uint16_t lcid, uint16_t result) { } /* else failure */ else { - avdt_on_l2cap_error(lcid, result); + LOG(ERROR) << __func__ << ": invoked with non OK status"; } } } diff --git a/stack/bnep/bnep_main.cc b/stack/bnep/bnep_main.cc index df0cbcda0..61cdd6d53 100644 --- a/stack/bnep/bnep_main.cc +++ b/stack/bnep/bnep_main.cc @@ -183,7 +183,7 @@ static void bnep_connect_cfm(uint16_t l2cap_cid, uint16_t result) { BNEP_TRACE_EVENT("BNEP - got conn cnf, sent cfg req, CID: 0x%x", p_bcb->l2cap_cid); } else { - bnep_on_l2cap_error(l2cap_cid, result); + LOG(ERROR) << __func__ << ": invoked with non OK status"; } } @@ -238,7 +238,7 @@ static void bnep_config_cfm(uint16_t l2cap_cid, uint16_t result) { BTM_SUCCESS); } } else { - bnep_on_l2cap_error(l2cap_cid, result); + LOG(ERROR) << __func__ << ": invoked with non OK status"; } } diff --git a/stack/gap/gap_conn.cc b/stack/gap/gap_conn.cc index 49b6af094..4ad4158ad 100644 --- a/stack/gap/gap_conn.cc +++ b/stack/gap/gap_conn.cc @@ -739,8 +739,6 @@ static void gap_connect_cfm(uint16_t l2cap_cid, uint16_t result) { p_ccb->con_flags |= GAP_CCB_FLAGS_SEC_DONE; gap_checks_con_flags(p_ccb); } - } else { - gap_on_l2cap_error(l2cap_cid, result); } } @@ -796,8 +794,6 @@ static void gap_config_cfm(uint16_t l2cap_cid, uint16_t result) { p_ccb->con_flags |= GAP_CCB_FLAGS_MY_CFG_DONE; p_ccb->con_flags |= GAP_CCB_FLAGS_HIS_CFG_DONE; gap_checks_con_flags(p_ccb); - } else { - gap_on_l2cap_error(l2cap_cid, result); } } diff --git a/stack/gatt/gatt_main.cc b/stack/gatt/gatt_main.cc index 92261aea8..967dc31ed 100644 --- a/stack/gatt/gatt_main.cc +++ b/stack/gatt/gatt_main.cc @@ -624,7 +624,7 @@ void gatt_l2cif_config_cfm_cback(uint16_t lcid, uint16_t result) { /* if result not successful */ if (result != L2CAP_CFG_OK) { - gatt_on_l2cap_error(lcid, result); + LOG(ERROR) << __func__ << ": invoked with non OK status"; return; } diff --git a/stack/hid/hidd_conn.cc b/stack/hid/hidd_conn.cc index 404d25a1c..dc84cd9e6 100644 --- a/stack/hid/hidd_conn.cc +++ b/stack/hid/hidd_conn.cc @@ -216,7 +216,7 @@ static void hidd_l2cif_connect_cfm(uint16_t cid, uint16_t result) { } if (result != L2CAP_CONN_OK) { - hidd_on_l2cap_error(cid, result); + LOG(ERROR) << __func__ << ": invoked with non OK status"; return; } @@ -280,7 +280,7 @@ static void hidd_l2cif_config_cfm(uint16_t cid, uint16_t result) { } if (result != L2CAP_CFG_OK) { - hidd_on_l2cap_error(cid, result); + LOG(ERROR) << __func__ << ": invoked with non OK status"; return; } diff --git a/stack/hid/hidh_conn.cc b/stack/hid/hidh_conn.cc index 741b68659..11f19e2f3 100644 --- a/stack/hid/hidh_conn.cc +++ b/stack/hid/hidh_conn.cc @@ -311,7 +311,8 @@ static void hidh_l2cif_connect_cfm(uint16_t l2cap_cid, uint16_t result) { } if (result != L2CAP_CONN_OK) { - hidh_on_l2cap_error(l2cap_cid, result); + // TODO: We need to provide the real HCI status if we want to retry. + LOG(ERROR) << __func__ << ": invoked with non OK status"; return; } /* receive Control Channel connect confirmation */ @@ -395,7 +396,7 @@ static void hidh_l2cif_config_cfm(uint16_t l2cap_cid, uint16_t result) { /* If configuration failed, disconnect the channel(s) */ if (result != L2CAP_CFG_OK) { - hidh_on_l2cap_error(l2cap_cid, L2CAP_CFG_FAILED_NO_REASON); + LOG(ERROR) << __func__ << ": invoked with non OK status"; return; } diff --git a/stack/l2cap/l2c_csm.cc b/stack/l2cap/l2c_csm.cc index fd5547204..344ce8849 100644 --- a/stack/l2cap/l2c_csm.cc +++ b/stack/l2cap/l2c_csm.cc @@ -148,7 +148,6 @@ static void l2c_csm_closed(tL2C_CCB* p_ccb, uint16_t event, void* p_data) { tL2C_CONN_INFO* p_ci = (tL2C_CONN_INFO*)p_data; uint16_t local_cid = p_ccb->local_cid; tL2CA_DISCONNECT_IND_CB* disconnect_ind; - tL2CA_CONNECT_CFM_CB* connect_cfm; if (p_ccb->p_rcb == NULL) { L2CAP_TRACE_ERROR("L2CAP - LCID: 0x%04x st: CLOSED evt: %s p_rcb == NULL", @@ -157,7 +156,6 @@ static void l2c_csm_closed(tL2C_CCB* p_ccb, uint16_t event, void* p_data) { } disconnect_ind = p_ccb->p_rcb->api.pL2CA_DisconnectInd_Cb; - connect_cfm = p_ccb->p_rcb->api.pL2CA_ConnectCfm_Cb; L2CAP_TRACE_EVENT("L2CAP - LCID: 0x%04x st: CLOSED evt: %s", p_ccb->local_cid, l2c_csm_get_event_name(event)); @@ -188,11 +186,8 @@ static void l2c_csm_closed(tL2C_CCB* p_ccb, uint16_t event, void* p_data) { if (p_ci->status == HCI_ERR_CONNECTION_EXISTS) { btm_acl_notif_conn_collision(p_ccb->p_lcb->remote_bd_addr); } else { - L2CAP_TRACE_API( - "L2CAP - Calling ConnectCfm_Cb(), CID: 0x%04x Status: %d", - p_ccb->local_cid, p_ci->status); l2cu_release_ccb(p_ccb); - (*connect_cfm)(local_cid, p_ci->status); + (*p_ccb->p_rcb->api.pL2CA_Error_Cb)(local_cid, L2CAP_CONN_OTHER_ERROR); } break; @@ -229,8 +224,8 @@ static void l2c_csm_closed(tL2C_CCB* p_ccb, uint16_t event, void* p_data) { /* Need to have at least one compatible channel to continue */ if (!l2c_fcr_chk_chan_modes(p_ccb)) { l2cu_release_ccb(p_ccb); - (*p_ccb->p_rcb->api.pL2CA_ConnectCfm_Cb)(local_cid, - L2CAP_CONN_NO_LINK); + (*p_ccb->p_rcb->api.pL2CA_Error_Cb)(local_cid, + L2CAP_CONN_OTHER_ERROR); } else { l2cu_send_peer_connect_req(p_ccb); alarm_set_on_mloop(p_ccb->l2c_ccb_timer, @@ -241,11 +236,8 @@ static void l2c_csm_closed(tL2C_CCB* p_ccb, uint16_t event, void* p_data) { break; case L2CEVT_SEC_COMP_NEG: /* something is really bad with security */ - L2CAP_TRACE_API( - "L2CAP - Calling ConnectCfm_Cb(), CID: 0x%04x Status: %d", - p_ccb->local_cid, L2CAP_CONN_TIMEOUT); l2cu_release_ccb(p_ccb); - (*connect_cfm)(local_cid, L2CAP_CONN_SECURITY_BLOCK); + (*p_ccb->p_rcb->api.pL2CA_Error_Cb)(local_cid, L2CAP_CONN_OTHER_ERROR); break; case L2CEVT_L2CAP_CONNECT_REQ: /* Peer connect request */ @@ -291,11 +283,8 @@ static void l2c_csm_closed(tL2C_CCB* p_ccb, uint16_t event, void* p_data) { break; case L2CEVT_TIMEOUT: - L2CAP_TRACE_API( - "L2CAP - Calling ConnectCfm_Cb(), CID: 0x%04x Status: %d", - p_ccb->local_cid, L2CAP_CONN_TIMEOUT); l2cu_release_ccb(p_ccb); - (*connect_cfm)(local_cid, L2CAP_CONN_TIMEOUT); + (*p_ccb->p_rcb->api.pL2CA_Error_Cb)(local_cid, L2CAP_CONN_OTHER_ERROR); break; case L2CEVT_L2CAP_DATA: /* Peer data packet rcvd */ @@ -323,7 +312,6 @@ static void l2c_csm_orig_w4_sec_comp(tL2C_CCB* p_ccb, uint16_t event, void* p_data) { tL2CA_DISCONNECT_IND_CB* disconnect_ind = p_ccb->p_rcb->api.pL2CA_DisconnectInd_Cb; - tL2CA_CONNECT_CFM_CB* connect_cfm = p_ccb->p_rcb->api.pL2CA_ConnectCfm_Cb; uint16_t local_cid = p_ccb->local_cid; L2CAP_TRACE_EVENT( @@ -366,7 +354,8 @@ static void l2c_csm_orig_w4_sec_comp(tL2C_CCB* p_ccb, uint16_t event, /* Need to have at least one compatible channel to continue */ if (!l2c_fcr_chk_chan_modes(p_ccb)) { l2cu_release_ccb(p_ccb); - (*connect_cfm)(local_cid, L2CAP_CONN_NO_LINK); + (*p_ccb->p_rcb->api.pL2CA_Error_Cb)(local_cid, + L2CAP_CONN_OTHER_ERROR); } else { alarm_set_on_mloop(p_ccb->l2c_ccb_timer, L2CAP_CHNL_CONNECT_TIMEOUT_MS, @@ -378,10 +367,6 @@ static void l2c_csm_orig_w4_sec_comp(tL2C_CCB* p_ccb, uint16_t event, break; case L2CEVT_SEC_COMP_NEG: - L2CAP_TRACE_API( - "L2CAP - Calling ConnectCfm_Cb(), CID: 0x%04x Status: %d", - p_ccb->local_cid, HCI_ERR_AUTH_FAILURE); - /* If last channel immediately disconnect the ACL for better security. Also prevents a race condition between BTM and L2CAP */ if ((p_ccb == p_ccb->p_lcb->ccb_queue.p_first_ccb) && @@ -390,7 +375,7 @@ static void l2c_csm_orig_w4_sec_comp(tL2C_CCB* p_ccb, uint16_t event, } l2cu_release_ccb(p_ccb); - (*connect_cfm)(local_cid, HCI_ERR_AUTH_FAILURE); + (*p_ccb->p_rcb->api.pL2CA_Error_Cb)(local_cid, L2CAP_CONN_OTHER_ERROR); break; case L2CEVT_L2CA_DATA_WRITE: /* Upper layer data to send */ @@ -526,7 +511,6 @@ static void l2c_csm_w4_l2cap_connect_rsp(tL2C_CCB* p_ccb, uint16_t event, tL2C_CONN_INFO* p_ci = (tL2C_CONN_INFO*)p_data; tL2CA_DISCONNECT_IND_CB* disconnect_ind = p_ccb->p_rcb->api.pL2CA_DisconnectInd_Cb; - tL2CA_CONNECT_CFM_CB* connect_cfm = p_ccb->p_rcb->api.pL2CA_ConnectCfm_Cb; uint16_t local_cid = p_ccb->local_cid; L2CAP_TRACE_EVENT("L2CAP - LCID: 0x%04x st: W4_L2CAP_CON_RSP evt: %s", @@ -580,14 +564,14 @@ static void l2c_csm_w4_l2cap_connect_rsp(tL2C_CCB* p_ccb, uint16_t event, << loghex(p_ccb->local_cid) << ", reason=" << loghex(p_ci->l2cap_result); l2cu_release_ccb(p_ccb); - (*connect_cfm)(local_cid, p_ci->l2cap_result); + (*p_ccb->p_rcb->api.pL2CA_Error_Cb)(local_cid, L2CAP_CONN_OTHER_ERROR); break; case L2CEVT_TIMEOUT: LOG(WARNING) << __func__ << ": L2CAP connection timeout, lcid=" << loghex(p_ccb->local_cid); l2cu_release_ccb(p_ccb); - (*connect_cfm)(local_cid, L2CAP_CONN_TIMEOUT); + (*p_ccb->p_rcb->api.pL2CA_Error_Cb)(local_cid, L2CAP_CONN_OTHER_ERROR); break; case L2CEVT_L2CA_DISCONNECT_REQ: /* Upper wants to disconnect */ @@ -612,7 +596,7 @@ static void l2c_csm_w4_l2cap_connect_rsp(tL2C_CCB* p_ccb, uint16_t event, /* Need to have at least one compatible channel to continue */ if (!l2c_fcr_chk_chan_modes(p_ccb)) { l2cu_release_ccb(p_ccb); - (*connect_cfm)(local_cid, L2CAP_CONN_NO_LINK); + (*p_ccb->p_rcb->api.pL2CA_Error_Cb)(local_cid, L2CAP_CONN_OTHER_ERROR); } else { /* We have feature info, so now send peer connect request */ alarm_set_on_mloop(p_ccb->l2c_ccb_timer, L2CAP_CHNL_CONNECT_TIMEOUT_MS, @@ -767,8 +751,13 @@ static void l2c_csm_config(tL2C_CCB* p_ccb, uint16_t event, void* p_data) { (*p_ccb->p_rcb->api.pL2CA_ConfigInd_Cb)(p_ccb->local_cid, p_cfg); l2c_csm_send_config_rsp_ok(p_ccb); if (p_ccb->config_done & OB_CFG_DONE) { - (*p_ccb->p_rcb->api.pL2CA_ConfigCfm_Cb)( - p_ccb->local_cid, p_ccb->remote_config_rsp_result); + 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); + } else { + (*p_ccb->p_rcb->api.pL2CA_Error_Cb)(p_ccb->local_cid, + L2CAP_CFG_FAILED_NO_REASON); + } } } else if (cfg_result == L2CAP_PEER_CFG_DISCONNECT) { /* Disconnect if channels are incompatible */ @@ -852,8 +841,8 @@ static void l2c_csm_config(tL2C_CCB* p_ccb, uint16_t event, void* p_data) { L2CAP_TRACE_API( "L2CAP - Calling Config_Rsp_Cb(), CID: 0x%04x, Failure: %d", p_ccb->local_cid, p_cfg->result); - (*p_ccb->p_rcb->api.pL2CA_ConfigCfm_Cb)(p_ccb->local_cid, - p_cfg->result); + (*p_ccb->p_rcb->api.pL2CA_Error_Cb)(p_ccb->local_cid, + L2CAP_CFG_FAILED_NO_REASON); } break; diff --git a/stack/rfcomm/rfc_l2cap_if.cc b/stack/rfcomm/rfc_l2cap_if.cc index 88321faa4..733301958 100644 --- a/stack/rfcomm/rfc_l2cap_if.cc +++ b/stack/rfcomm/rfc_l2cap_if.cc @@ -148,7 +148,6 @@ void RFCOMM_ConnectCnf(uint16_t lcid, uint16_t result) { /* if peer rejects our connect request but peer's connect request is pending */ if (result != L2CAP_CONN_OK) { - rfc_on_l2cap_error(lcid, L2CAP_CONN_NO_RESOURCES); return; } else { RFCOMM_TRACE_DEBUG("RFCOMM_ConnectCnf peer gave up pending LCID(0x%x)", diff --git a/stack/rfcomm/rfc_mx_fsm.cc b/stack/rfcomm/rfc_mx_fsm.cc index 347e4841b..d8977a5dc 100644 --- a/stack/rfcomm/rfc_mx_fsm.cc +++ b/stack/rfcomm/rfc_mx_fsm.cc @@ -557,7 +557,7 @@ static void rfc_mx_send_config_req(tRFC_MCB* p_mcb) { void rfc_on_l2cap_error(uint16_t lcid, uint16_t result) { tRFC_MCB* p_mcb = rfc_find_lcid_mcb(lcid); - if (result == L2CAP_CONN_NO_RESOURCES) { + if (result == L2CAP_CONN_OTHER_ERROR) { RFCOMM_TRACE_DEBUG( "RFCOMM_ConnectCnf retry as acceptor on pending LCID(0x%x)", p_mcb->pending_lcid); @@ -614,7 +614,6 @@ static void rfc_mx_conf_cnf(tRFC_MCB* p_mcb, uint16_t result) { RFCOMM_TRACE_EVENT("rfc_mx_conf_cnf result:%d ", result); if (result != L2CAP_CFG_OK) { - rfc_on_l2cap_error(p_mcb->lcid, L2CAP_CFG_FAILED_NO_REASON); return; } diff --git a/stack/sdp/sdp_main.cc b/stack/sdp/sdp_main.cc index cb6a46121..14f8bc099 100644 --- a/stack/sdp/sdp_main.cc +++ b/stack/sdp/sdp_main.cc @@ -160,7 +160,7 @@ static void sdp_connect_cfm(uint16_t l2cap_cid, uint16_t result) { if ((result == L2CAP_CONN_OK) && (p_ccb->con_state == SDP_STATE_CONN_SETUP)) { p_ccb->con_state = SDP_STATE_CFG_SETUP; } else { - sdp_on_l2cap_error(l2cap_cid, result); + LOG(ERROR) << __func__ << ": invoked with non OK status"; } } @@ -234,7 +234,7 @@ static void sdp_config_cfm(uint16_t l2cap_cid, uint16_t result) { sdp_conn_timer_timeout, p_ccb); } } else { - sdp_on_l2cap_error(l2cap_cid, result); + LOG(ERROR) << __func__ << ": invoked with non OK status"; } } -- 2.11.0