diff options
Diffstat (limited to 'stack/avct/avct_l2c.cc')
-rw-r--r-- | stack/avct/avct_l2c.cc | 158 |
1 files changed, 52 insertions, 106 deletions
diff --git a/stack/avct/avct_l2c.cc b/stack/avct/avct_l2c.cc index 718a9c9c2..40005e128 100644 --- a/stack/avct/avct_l2c.cc +++ b/stack/avct/avct_l2c.cc @@ -22,44 +22,35 @@ * ******************************************************************************/ -#include <string.h> #include "avct_api.h" #include "avct_int.h" #include "bt_target.h" #include "bt_types.h" -#include "bt_utils.h" #include "l2c_api.h" #include "l2cdefs.h" #include "osi/include/osi.h" -/* Configuration flags. */ -#define AVCT_L2C_CFG_IND_DONE (1 << 0) -#define AVCT_L2C_CFG_CFM_DONE (1 << 1) - /* callback function declarations */ void avct_l2c_connect_ind_cback(const RawAddress& bd_addr, uint16_t lcid, uint16_t psm, uint8_t id); void avct_l2c_connect_cfm_cback(uint16_t lcid, uint16_t result); -void avct_l2c_config_cfm_cback(uint16_t lcid, tL2CAP_CFG_INFO* p_cfg); +void avct_l2c_config_cfm_cback(uint16_t lcid, uint16_t result, + tL2CAP_CFG_INFO* p_cfg); void avct_l2c_config_ind_cback(uint16_t lcid, tL2CAP_CFG_INFO* p_cfg); void avct_l2c_disconnect_ind_cback(uint16_t lcid, bool ack_needed); -void avct_l2c_disconnect_cfm_cback(uint16_t lcid, uint16_t result); void avct_l2c_congestion_ind_cback(uint16_t lcid, bool is_congested); void avct_l2c_data_ind_cback(uint16_t lcid, BT_HDR* p_buf); +static void avct_on_l2cap_error(uint16_t lcid, uint16_t result); /* L2CAP callback function structure */ -const tL2CAP_APPL_INFO avct_l2c_appl = {avct_l2c_connect_ind_cback, - avct_l2c_connect_cfm_cback, - NULL, - avct_l2c_config_ind_cback, - avct_l2c_config_cfm_cback, - avct_l2c_disconnect_ind_cback, - avct_l2c_disconnect_cfm_cback, - NULL, - avct_l2c_data_ind_cback, - avct_l2c_congestion_ind_cback, - NULL, /* tL2CA_TX_COMPLETE_CB */ - NULL /* tL2CA_CREDITS_RECEIVED_CB */}; +const tL2CAP_APPL_INFO avct_l2c_appl = { + avct_l2c_connect_ind_cback, avct_l2c_connect_cfm_cback, + avct_l2c_config_ind_cback, avct_l2c_config_cfm_cback, + avct_l2c_disconnect_ind_cback, avct_l2c_data_ind_cback, + avct_l2c_congestion_ind_cback, NULL, + avct_on_l2cap_error, NULL, + NULL, NULL, +}; /******************************************************************************* * @@ -102,7 +93,6 @@ void avct_l2c_connect_ind_cback(const RawAddress& bd_addr, uint16_t lcid, UNUSED_ATTR uint16_t psm, uint8_t id) { tAVCT_LCB* p_lcb; uint16_t result = L2CAP_CONN_OK; - tL2CAP_CFG_INFO cfg; /* do we already have a channel for this peer? */ p_lcb = avct_lcb_by_bd(bd_addr); @@ -132,8 +122,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) { @@ -142,18 +135,35 @@ void avct_l2c_connect_ind_cback(const RawAddress& bd_addr, uint16_t lcid, /* transition to configuration state */ p_lcb->ch_state = AVCT_CH_CFG; - - /* Send L2CAP config req */ - memset(&cfg, 0, sizeof(tL2CAP_CFG_INFO)); - cfg.mtu_present = true; - cfg.mtu = avct_cb.mtu; - L2CA_ConfigReq(lcid, &cfg); - AVCT_TRACE_DEBUG("avct_l2c snd Cfg Req"); } if (p_lcb) AVCT_TRACE_DEBUG("ch_state cni: %d ", p_lcb->ch_state); } +static void avct_on_l2cap_error(uint16_t lcid, uint16_t result) { + tAVCT_LCB* p_lcb = avct_lcb_by_lcid(lcid); + if (p_lcb == nullptr) return; + if (p_lcb->ch_state == AVCT_CH_CONN) { + AVCT_TRACE_DEBUG("avct_l2c_connect_cfm_cback conflict_lcid:0x%x", + p_lcb->conflict_lcid); + if (p_lcb->conflict_lcid == lcid) { + p_lcb->conflict_lcid = 0; + } else { + tAVCT_LCB_EVT avct_lcb_evt; + avct_lcb_evt.result = result; + avct_lcb_event(p_lcb, AVCT_LCB_LL_CLOSE_EVT, &avct_lcb_evt); + } + } else if (p_lcb->ch_state == AVCT_CH_CFG) { + AVCT_TRACE_DEBUG("ERROR avct_l2c_config_cfm_cback L2CA_DisconnectReq %d ", + p_lcb->ch_state); + /* store result value */ + p_lcb->ch_result = result; + + /* Send L2CAP disconnect req */ + L2CA_DisconnectReq(lcid); + } +} + /******************************************************************************* * * Function avct_l2c_connect_cfm_cback @@ -166,7 +176,6 @@ void avct_l2c_connect_ind_cback(const RawAddress& bd_addr, uint16_t lcid, ******************************************************************************/ void avct_l2c_connect_cfm_cback(uint16_t lcid, uint16_t result) { tAVCT_LCB* p_lcb; - tL2CAP_CFG_INFO cfg; /* look up lcb for this channel */ p_lcb = avct_lcb_by_lcid(lcid); @@ -181,25 +190,10 @@ void avct_l2c_connect_cfm_cback(uint16_t lcid, uint16_t result) { if (result == L2CAP_CONN_OK) { /* set channel state */ p_lcb->ch_state = AVCT_CH_CFG; - - /* Send L2CAP config req */ - memset(&cfg, 0, sizeof(tL2CAP_CFG_INFO)); - cfg.mtu_present = true; - cfg.mtu = avct_cb.mtu; - L2CA_ConfigReq(lcid, &cfg); - AVCT_TRACE_DEBUG("avct_l2c snd Cfg Req"); } /* else failure */ else { - AVCT_TRACE_DEBUG("avct_l2c_connect_cfm_cback conflict_lcid:0x%x", - p_lcb->conflict_lcid); - if (p_lcb->conflict_lcid == lcid) { - p_lcb->conflict_lcid = 0; - } else { - tAVCT_LCB_EVT avct_lcb_evt; - avct_lcb_evt.result = result; - avct_lcb_event(p_lcb, AVCT_LCB_LL_CLOSE_EVT, &avct_lcb_evt); - } + 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 */ @@ -227,38 +221,21 @@ void avct_l2c_connect_cfm_cback(uint16_t lcid, uint16_t result) { * Returns void * ******************************************************************************/ -void avct_l2c_config_cfm_cback(uint16_t lcid, tL2CAP_CFG_INFO* p_cfg) { +void avct_l2c_config_cfm_cback(uint16_t lcid, uint16_t initiator, + tL2CAP_CFG_INFO* p_cfg) { + avct_l2c_config_ind_cback(lcid, p_cfg); + tAVCT_LCB* p_lcb; /* look up lcb for this channel */ p_lcb = avct_lcb_by_lcid(lcid); if (p_lcb != NULL) { - AVCT_TRACE_DEBUG("avct_l2c_config_cfm_cback: 0x%x, ch_state: %d, res: %d", - lcid, p_lcb->ch_state, p_cfg->result); + AVCT_TRACE_DEBUG("avct_l2c_config_cfm_cback: 0x%x, ch_state: %d,", lcid, + p_lcb->ch_state); /* if in correct state */ if (p_lcb->ch_state == AVCT_CH_CFG) { - /* if result successful */ - if (p_cfg->result == L2CAP_CFG_OK) { - /* update flags */ - p_lcb->ch_flags |= AVCT_L2C_CFG_CFM_DONE; - - /* if configuration complete */ - if (p_lcb->ch_flags & AVCT_L2C_CFG_IND_DONE) { - p_lcb->ch_state = AVCT_CH_OPEN; - avct_lcb_event(p_lcb, AVCT_LCB_LL_OPEN_EVT, NULL); - } - } - /* else failure */ - else { - AVCT_TRACE_DEBUG( - "ERROR avct_l2c_config_cfm_cback L2CA_DisconnectReq %d ", - p_lcb->ch_state); - /* store result value */ - p_lcb->ch_result = p_cfg->result; - - /* Send L2CAP disconnect req */ - L2CA_DisconnectReq(lcid); - } + p_lcb->ch_state = AVCT_CH_OPEN; + avct_lcb_event(p_lcb, AVCT_LCB_LL_OPEN_EVT, NULL); } AVCT_TRACE_DEBUG("ch_state cfc: %d ", p_lcb->ch_state); } @@ -288,24 +265,6 @@ void avct_l2c_config_ind_cback(uint16_t lcid, tL2CAP_CFG_INFO* p_cfg) { } else { p_lcb->peer_mtu = L2CAP_DEFAULT_MTU; } - - /* send L2CAP configure response */ - memset(p_cfg, 0, sizeof(tL2CAP_CFG_INFO)); - p_cfg->result = L2CAP_CFG_OK; - L2CA_ConfigRsp(lcid, p_cfg); - - /* if first config ind */ - if ((p_lcb->ch_flags & AVCT_L2C_CFG_IND_DONE) == 0) { - /* update flags */ - p_lcb->ch_flags |= AVCT_L2C_CFG_IND_DONE; - - /* if configuration complete */ - if (p_lcb->ch_flags & AVCT_L2C_CFG_CFM_DONE) { - p_lcb->ch_state = AVCT_CH_OPEN; - avct_lcb_event(p_lcb, AVCT_LCB_LL_OPEN_EVT, NULL); - } - } - AVCT_TRACE_DEBUG("ch_state cfi: %d ", p_lcb->ch_state); } } @@ -328,11 +287,6 @@ void avct_l2c_disconnect_ind_cback(uint16_t lcid, bool ack_needed) { if (p_lcb != NULL) { AVCT_TRACE_DEBUG("avct_l2c_disconnect_ind_cback: 0x%x, ch_state: %d", lcid, p_lcb->ch_state); - if (ack_needed) { - /* send L2CAP disconnect response */ - L2CA_DisconnectRsp(lcid); - } - tAVCT_LCB_EVT avct_lcb_evt; avct_lcb_evt.result = result; avct_lcb_event(p_lcb, AVCT_LCB_LL_CLOSE_EVT, &avct_lcb_evt); @@ -340,17 +294,9 @@ void avct_l2c_disconnect_ind_cback(uint16_t lcid, bool ack_needed) { } } -/******************************************************************************* - * - * Function avct_l2c_disconnect_cfm_cback - * - * Description This is the L2CAP disconnect confirm callback function. - * - * - * Returns void - * - ******************************************************************************/ -void avct_l2c_disconnect_cfm_cback(uint16_t lcid, uint16_t result) { +void avct_l2c_disconnect(uint16_t lcid, uint16_t result) { + L2CA_DisconnectReq(lcid); + tAVCT_LCB* p_lcb; uint16_t res; |