diff options
author | Srikanth Uppala <suppala@broadcom.com> | 2012-06-17 21:44:48 -0700 |
---|---|---|
committer | Matthew Xie <mattx@google.com> | 2012-07-14 11:19:23 -0700 |
commit | 1144d2b375fc67c9b48298e0ffd774d969cfd2cc (patch) | |
tree | 4d36d4f8be4942d769300c242caeb9b9096c6a35 /stack/avct | |
parent | fed66f7b66d29da466e2e67befe3238e7ed8fc6a (diff) | |
download | external_bluetooth_bluedroid-1144d2b375fc67c9b48298e0ffd774d969cfd2cc.zip external_bluetooth_bluedroid-1144d2b375fc67c9b48298e0ffd774d969cfd2cc.tar.gz external_bluetooth_bluedroid-1144d2b375fc67c9b48298e0ffd774d969cfd2cc.tar.bz2 |
resubmit code-cleanup changes lost in gerrit merge
Change-Id: Iebc520d9b10ef220a83a16ff55efa46b4c5a0d27
Diffstat (limited to 'stack/avct')
-rw-r--r-- | stack/avct/avct_bcb_act.c | 749 | ||||
-rw-r--r-- | stack/avct/avct_l2c_br.c | 397 |
2 files changed, 0 insertions, 1146 deletions
diff --git a/stack/avct/avct_bcb_act.c b/stack/avct/avct_bcb_act.c deleted file mode 100644 index ad6d651..0000000 --- a/stack/avct/avct_bcb_act.c +++ /dev/null @@ -1,749 +0,0 @@ -/***************************************************************************** -** -** Name: avct_bcb_act.c -** -** Description: This module contains action functions of the browsing control -** state machine. -** -** Copyright (c) 2003-2008, Broadcom Corp., All Rights Reserved. -** Broadcom Bluetooth Core. Proprietary and confidential. -** -*****************************************************************************/ - -#include <string.h> -#include "data_types.h" -#include "bt_target.h" -#include "avct_api.h" -#include "avct_int.h" -#include "gki.h" - - -#include "btm_api.h" - -#if (AVCT_BROWSE_INCLUDED == TRUE) -/* action function list */ -const tAVCT_BCB_ACTION avct_bcb_action[] = { - avct_bcb_chnl_open, /* AVCT_LCB_CHNL_OPEN */ - avct_bcb_chnl_disc, /* AVCT_LCB_CHNL_DISC */ - avct_bcb_send_msg, /* AVCT_LCB_SEND_MSG */ - avct_bcb_open_ind, /* AVCT_LCB_OPEN_IND */ - avct_bcb_open_fail, /* AVCT_LCB_OPEN_FAIL */ - avct_bcb_close_ind, /* AVCT_LCB_CLOSE_IND */ - avct_bcb_close_cfm, /* AVCT_LCB_CLOSE_CFM */ - avct_bcb_msg_ind, /* AVCT_LCB_MSG_IND */ - avct_bcb_cong_ind, /* AVCT_LCB_CONG_IND */ - avct_bcb_bind_conn, /* AVCT_LCB_BIND_CONN */ - avct_bcb_bind_fail, /* AVCT_LCB_BIND_FAIL */ - avct_bcb_unbind_disc, /* AVCT_LCB_UNBIND_DISC */ - avct_bcb_chk_disc, /* AVCT_LCB_CHK_DISC */ - avct_bcb_discard_msg, /* AVCT_LCB_DISCARD_MSG */ - avct_bcb_dealloc, /* AVCT_LCB_DEALLOC */ - avct_bcb_free_msg_ind /* AVCT_LCB_FREE_MSG_IND */ -}; - - -/******************************************************************************* -** -** Function avct_bcb_msg_asmbl -** -** Description Reassemble incoming message. -** -** -** Returns Pointer to reassembled message; NULL if no message -** available. -** -*******************************************************************************/ -static BT_HDR *avct_bcb_msg_asmbl(tAVCT_BCB *p_bcb, BT_HDR *p_buf) -{ - UINT8 *p; - UINT8 pkt_type; - BT_HDR *p_ret = NULL; - - /* parse the message header */ - p = (UINT8 *)(p_buf + 1) + p_buf->offset; - AVCT_PRS_PKT_TYPE(p, pkt_type); - - /* must be single packet - can not fragment */ - if (pkt_type == AVCT_PKT_TYPE_SINGLE) - { - p_ret = p_buf; - } - else - { - GKI_freebuf(p_buf); - AVCT_TRACE_WARNING1("Pkt type=%d - fragmentation not allowed. drop it", pkt_type); - } - return p_ret; -} - - -/******************************************************************************* -** -** Function avct_bcb_chnl_open -** -** Description Open L2CAP channel to peer -** -** -** Returns Nothing. -** -*******************************************************************************/ -void avct_bcb_chnl_open(tAVCT_BCB *p_bcb, tAVCT_LCB_EVT *p_data) -{ - UINT16 result = AVCT_RESULT_FAIL; - tAVCT_LCB *p_lcb = avct_lcb_by_bcb(p_bcb); - tL2CAP_ERTM_INFO ertm_info; - - BTM_SetOutService(p_lcb->peer_addr, BTM_SEC_SERVICE_AVCTP_BROWSE, 0); - - /* Set the FCR options: Browsing channel mandates ERTM */ - ertm_info.preferred_mode = avct_l2c_br_fcr_opts_def.mode; - ertm_info.allowed_modes = L2CAP_FCR_CHAN_OPT_ERTM; - ertm_info.user_rx_pool_id = AVCT_BR_USER_RX_POOL_ID; - ertm_info.user_tx_pool_id = AVCT_BR_USER_TX_POOL_ID; - ertm_info.fcr_rx_pool_id = AVCT_BR_FCR_RX_POOL_ID; - ertm_info.fcr_tx_pool_id = AVCT_BR_FCR_TX_POOL_ID; - - /* call l2cap connect req */ - p_bcb->ch_state = AVCT_CH_CONN; - if ((p_bcb->ch_lcid = L2CA_ErtmConnectReq(AVCT_BR_PSM, p_lcb->peer_addr, &ertm_info)) == 0) - { - /* if connect req failed, send ourselves close event */ - avct_bcb_event(p_bcb, AVCT_LCB_LL_CLOSE_EVT, (tAVCT_LCB_EVT *) &result); - } -} - -/******************************************************************************* -** -** Function avct_bcb_unbind_disc -** -** Description call callback with disconnect event. -** -** -** Returns Nothing. -** -*******************************************************************************/ -void avct_bcb_unbind_disc(tAVCT_BCB *p_bcb, tAVCT_LCB_EVT *p_data) -{ - p_data->p_ccb->p_bcb = NULL; - (*p_data->p_ccb->cc.p_ctrl_cback)(avct_ccb_to_idx(p_data->p_ccb), AVCT_BROWSE_DISCONN_CFM_EVT, 0, NULL); -} - -/******************************************************************************* -** -** Function avct_bcb_open_ind -** -** Description Handle an LL_OPEN event. For each allocated ccb already -** bound to this lcb, send a connect event. For each -** unbound ccb with a new PID, bind that ccb to this lcb and -** send a connect event. -** -** -** Returns Nothing. -** -*******************************************************************************/ -void avct_bcb_open_ind(tAVCT_BCB *p_bcb, tAVCT_LCB_EVT *p_data) -{ - tAVCT_CCB *p_ccb = &avct_cb.ccb[0]; - tAVCT_CCB *p_ccb_bind = NULL; - int i; - BOOLEAN bind = FALSE; - tAVCT_UL_MSG ul_msg; - - for (i = 0; i < AVCT_NUM_CONN; i++, p_ccb++) - { - /* if ccb allocated and */ - if (p_ccb->allocated) - { - /* if bound to this lcb send connect confirm event */ - if (p_ccb->p_bcb == p_bcb) - { - bind = TRUE; - p_ccb_bind = p_ccb; - p_ccb->cc.p_ctrl_cback(avct_ccb_to_idx(p_ccb), AVCT_BROWSE_CONN_CFM_EVT, - 0, p_ccb->p_lcb->peer_addr); - } - /* if unbound acceptor and lcb e */ - else if ((p_ccb->p_bcb == NULL) && (p_ccb->cc.role == AVCT_ACP) && - (p_ccb->p_lcb != NULL)) - { - /* bind ccb to lcb and send connect ind event */ - bind = TRUE; - p_ccb_bind = p_ccb; - p_ccb->p_bcb = p_bcb; - p_ccb->cc.p_ctrl_cback(avct_ccb_to_idx(p_ccb), AVCT_BROWSE_CONN_IND_EVT, - 0, p_ccb->p_lcb->peer_addr); - } - } - } - - /* if no ccbs bound to this lcb, disconnect */ - if (bind == FALSE) - { - avct_bcb_event(p_bcb, AVCT_LCB_INT_CLOSE_EVT, p_data); - } - else if (p_bcb->p_tx_msg) - { - if (p_ccb_bind) - { - ul_msg.p_buf = p_bcb->p_tx_msg; - ul_msg.p_ccb = p_ccb_bind; - ul_msg.label = (UINT8)(p_bcb->p_tx_msg->layer_specific & 0xFF); - ul_msg.cr = (UINT8)((p_bcb->p_tx_msg->layer_specific & 0xFF00) >> 8); - p_bcb->p_tx_msg->layer_specific = AVCT_DATA_BROWSE; - p_bcb->p_tx_msg = NULL; - - /* send msg event to bcb */ - avct_bcb_event(p_bcb, AVCT_LCB_UL_MSG_EVT, (tAVCT_LCB_EVT *) &ul_msg); - } - else - { - GKI_freebuf (p_bcb->p_tx_msg); - p_bcb->p_tx_msg = NULL; - } - - } -} - -/******************************************************************************* -** -** Function avct_bcb_open_fail -** -** Description L2CAP channel open attempt failed. Mark the ccbs -** as NULL bcb. -** -** -** Returns Nothing. -** -*******************************************************************************/ -void avct_bcb_open_fail(tAVCT_BCB *p_bcb, tAVCT_LCB_EVT *p_data) -{ - tAVCT_CCB *p_ccb = &avct_cb.ccb[0]; - int i; - - for (i = 0; i < AVCT_NUM_CONN; i++, p_ccb++) - { - if (p_ccb->allocated && (p_ccb->p_bcb == p_bcb)) - { - p_ccb->p_bcb = NULL; - } - } -} - -/******************************************************************************* -** -** Function avct_bcb_close_ind -** -** Description L2CAP channel closed by peer. Deallocate any initiator -** ccbs on this lcb and send disconnect ind event. -** -** -** Returns Nothing. -** -*******************************************************************************/ -void avct_bcb_close_ind(tAVCT_BCB *p_bcb, tAVCT_LCB_EVT *p_data) -{ - tAVCT_CCB *p_ccb = &avct_cb.ccb[0]; - tAVCT_LCB *p_lcb = avct_lcb_by_bcb(p_bcb); - int i; - - for (i = 0; i < AVCT_NUM_CONN; i++, p_ccb++) - { - if (p_ccb->allocated && (p_ccb->p_bcb == p_bcb)) - { - if (p_ccb->cc.role == AVCT_INT) - { - (*p_ccb->cc.p_ctrl_cback)(avct_ccb_to_idx(p_ccb), AVCT_BROWSE_DISCONN_CFM_EVT, 0, p_lcb->peer_addr); - } - else - { - (*p_ccb->cc.p_ctrl_cback)(avct_ccb_to_idx(p_ccb), AVCT_BROWSE_DISCONN_IND_EVT, 0, NULL); - } - p_ccb->p_bcb = NULL; - } - } -} - -/******************************************************************************* -** -** Function avct_bcb_close_cfm -** -** Description L2CAP channel closed by us. Deallocate any initiator -** ccbs on this lcb and send disconnect ind or cfm event. -** -** -** Returns Nothing. -** -*******************************************************************************/ -void avct_bcb_close_cfm(tAVCT_BCB *p_bcb, tAVCT_LCB_EVT *p_data) -{ - tAVCT_CCB *p_ccb = &avct_cb.ccb[0]; - int i; - UINT8 event = 0; - BOOLEAN ch_close = p_bcb->ch_close; /* Whether BCB initiated channel close */ - tAVCT_CTRL_CBACK *p_cback; - - p_bcb->ch_close = FALSE; - p_bcb->allocated = 0; - for (i = 0; i < AVCT_NUM_CONN; i++, p_ccb++) - { - if (p_ccb->allocated && (p_ccb->p_bcb == p_bcb)) - { - /* if this ccb initiated close send disconnect cfm otherwise ind */ - if (ch_close) - { - event = AVCT_BROWSE_DISCONN_CFM_EVT; - } - else - { - event = AVCT_BROWSE_DISCONN_IND_EVT; - } - - p_cback = p_ccb->cc.p_ctrl_cback; - p_ccb->p_bcb = NULL; - if (p_ccb->p_lcb == NULL) - avct_ccb_dealloc(p_ccb, AVCT_NO_EVT, 0, NULL); - (*p_cback)(avct_ccb_to_idx(p_ccb), event, - p_data->result, NULL); - } - } -} - -/******************************************************************************* -** -** Function avct_bcb_bind_conn -** -** Description Bind ccb to lcb and send connect cfm event. -** -** -** Returns Nothing. -** -*******************************************************************************/ -void avct_bcb_bind_conn(tAVCT_BCB *p_bcb, tAVCT_LCB_EVT *p_data) -{ - tAVCT_LCB *p_lcb = avct_lcb_by_bcb(p_bcb); - p_data->p_ccb->p_bcb = p_bcb; - (*p_data->p_ccb->cc.p_ctrl_cback)(avct_ccb_to_idx(p_data->p_ccb), - AVCT_BROWSE_CONN_CFM_EVT, 0, p_lcb->peer_addr); -} - -/******************************************************************************* -** -** Function avct_bcb_chk_disc -** -** Description A ccb wants to close; if it is the last ccb on this lcb, -** close channel. Otherwise just deallocate and call -** callback. -** -** -** Returns Nothing. -** -*******************************************************************************/ -void avct_bcb_chk_disc(tAVCT_BCB *p_bcb, tAVCT_LCB_EVT *p_data) -{ - AVCT_TRACE_WARNING0("avct_bcb_chk_disc"); - p_bcb->ch_close = avct_bcb_last_ccb(p_bcb, p_data->p_ccb); - if (p_bcb->ch_close) - { - AVCT_TRACE_WARNING0("b closing"); - avct_bcb_event(p_bcb, AVCT_LCB_INT_CLOSE_EVT, p_data); - } - else - { - AVCT_TRACE_WARNING0("b unbind_disc"); - avct_bcb_unbind_disc(p_bcb, p_data); - } -} - -/******************************************************************************* -** -** Function avct_bcb_chnl_disc -** -** Description Disconnect L2CAP channel. -** -** -** Returns Nothing. -** -*******************************************************************************/ -void avct_bcb_chnl_disc(tAVCT_BCB *p_bcb, tAVCT_LCB_EVT *p_data) -{ - L2CA_DisconnectReq(p_bcb->ch_lcid); -} - -/******************************************************************************* -** -** Function avct_bcb_bind_fail -** -** Description Deallocate ccb and call callback with connect event -** with failure result. -** -** -** Returns Nothing. -** -*******************************************************************************/ -void avct_bcb_bind_fail(tAVCT_BCB *p_bcb, tAVCT_LCB_EVT *p_data) -{ - p_data->p_ccb->p_bcb = NULL; - (*p_data->p_ccb->cc.p_ctrl_cback)(avct_ccb_to_idx(p_data->p_ccb), AVCT_BROWSE_CONN_CFM_EVT, AVCT_RESULT_FAIL, NULL); -} - -/******************************************************************************* -** -** Function avct_bcb_cong_ind -** -** Description Handle congestion indication from L2CAP. -** -** -** Returns Nothing. -** -*******************************************************************************/ -void avct_bcb_cong_ind(tAVCT_BCB *p_bcb, tAVCT_LCB_EVT *p_data) -{ - tAVCT_CCB *p_ccb = &avct_cb.ccb[0]; - int i; - UINT8 event; - tAVCT_LCB *p_lcb = avct_lcb_by_bcb(p_bcb); - - /* set event */ - event = (p_data->cong) ? AVCT_BROWSE_CONG_IND_EVT : AVCT_BROWSE_UNCONG_IND_EVT; - - /* send event to all ccbs on this lcb */ - for (i = 0; i < AVCT_NUM_CONN; i++, p_ccb++) - { - if (p_ccb->allocated && (p_ccb->p_bcb == p_bcb)) - { - (*p_ccb->cc.p_ctrl_cback)(avct_ccb_to_idx(p_ccb), event, 0, p_lcb->peer_addr); - } - } - -} - -/******************************************************************************* -** -** Function avct_bcb_discard_msg -** -** Description Discard a message sent in from the API. -** -** -** Returns Nothing. -** -*******************************************************************************/ -void avct_bcb_discard_msg(tAVCT_BCB *p_bcb, tAVCT_LCB_EVT *p_data) -{ - AVCT_TRACE_WARNING0("save msg in control block"); - - if (p_bcb->p_tx_msg) - { - GKI_freebuf(p_bcb->p_tx_msg); - p_bcb->p_tx_msg = NULL; - } - - /* if control channel is up, save the message and open the browsing channel */ - if (p_data->ul_msg.p_ccb->p_lcb) - { - p_bcb->p_tx_msg = p_data->ul_msg.p_buf; - - if (p_bcb->p_tx_msg) - { - p_bcb->p_tx_msg->layer_specific = (p_data->ul_msg.cr << 8) + p_data->ul_msg.label; - - /* the channel is closed, opening or closing - open it again */ - AVCT_TRACE_DEBUG2("ch_state: %d, allocated:%d", p_bcb->ch_state, p_bcb->allocated); - p_bcb->allocated = p_data->ul_msg.p_ccb->p_lcb->allocated; - AVCT_TRACE_DEBUG2("ch_state: %d, allocated:%d", p_bcb->ch_state, p_bcb->allocated); - avct_bcb_event(p_bcb, AVCT_LCB_UL_BIND_EVT, (tAVCT_LCB_EVT *) p_data->ul_msg.p_ccb); - } - } - else - GKI_freebuf(p_data->ul_msg.p_buf); -} - -/******************************************************************************* -** -** Function avct_bcb_send_msg -** -** Description Build and send an AVCTP message. -** -** -** Returns Nothing. -** -*******************************************************************************/ -void avct_bcb_send_msg(tAVCT_BCB *p_bcb, tAVCT_LCB_EVT *p_data) -{ - UINT16 curr_msg_len; - UINT8 pkt_type = AVCT_PKT_TYPE_SINGLE; - UINT8 hdr_len; - BT_HDR *p_buf; - UINT8 *p; - - /* store msg len */ - curr_msg_len = p_data->ul_msg.p_buf->len; - - /* initialize packet type and other stuff */ - if (curr_msg_len > (p_bcb->peer_mtu - AVCT_HDR_LEN_SINGLE)) - { - AVCT_TRACE_ERROR3 ("avct_bcb_send_msg msg len (%d) exceeds peer mtu(%d-%d)!!", curr_msg_len, p_bcb->peer_mtu, AVCT_HDR_LEN_SINGLE); - GKI_freebuf(p_data->ul_msg.p_buf); - return; - } - - /* set header len */ - hdr_len = avct_lcb_pkt_type_len[pkt_type]; - p_buf = p_data->ul_msg.p_buf; - - /* set up to build header */ - p_buf->len += hdr_len; - p_buf->offset -= hdr_len; - p = (UINT8 *)(p_buf + 1) + p_buf->offset; - - /* build header */ - AVCT_BLD_HDR(p, p_data->ul_msg.label, pkt_type, p_data->ul_msg.cr); - UINT16_TO_BE_STREAM(p, p_data->ul_msg.p_ccb->cc.pid); - - /* send message to L2CAP */ - L2CA_DataWrite(p_bcb->ch_lcid, p_buf); - return; -} - -/******************************************************************************* -** -** Function avct_bcb_free_msg_ind -** -** Description Discard an incoming AVCTP message. -** -** -** Returns Nothing. -** -*******************************************************************************/ -void avct_bcb_free_msg_ind(tAVCT_BCB *p_bcb, tAVCT_LCB_EVT *p_data) -{ - if (p_data) - GKI_freebuf(p_data->p_buf); - return; -} - -/******************************************************************************* -** -** Function avct_bcb_msg_ind -** -** Description Handle an incoming AVCTP message. -** -** -** Returns Nothing. -** -*******************************************************************************/ -void avct_bcb_msg_ind(tAVCT_BCB *p_bcb, tAVCT_LCB_EVT *p_data) -{ - UINT8 *p; - UINT8 label, type, cr_ipid; - UINT16 pid; - tAVCT_CCB *p_ccb; - BT_HDR *p_buf; - tAVCT_LCB *p_lcb = avct_lcb_by_bcb(p_bcb); - - /* this p_buf is to be reported through p_msg_cback. The layer_specific - * needs to be set properly to indicate that it is received through - * broasing channel */ - p_data->p_buf->layer_specific = AVCT_DATA_BROWSE; - - /* reassemble message; if no message available (we received a fragment) return */ - if ((p_data->p_buf = avct_bcb_msg_asmbl(p_bcb, p_data->p_buf)) == NULL) - { - return; - } - - p = (UINT8 *)(p_data->p_buf + 1) + p_data->p_buf->offset; - - /* parse header byte */ - AVCT_PRS_HDR(p, label, type, cr_ipid); - - /* check for invalid cr_ipid */ - if (cr_ipid == AVCT_CR_IPID_INVALID) - { - AVCT_TRACE_WARNING1("Invalid cr_ipid", cr_ipid); - GKI_freebuf(p_data->p_buf); - return; - } - - /* parse and lookup PID */ - BE_STREAM_TO_UINT16(pid, p); - if ((p_ccb = avct_lcb_has_pid(p_lcb, pid)) != NULL) - { - /* PID found; send msg up, adjust bt hdr and call msg callback */ - p_data->p_buf->offset += AVCT_HDR_LEN_SINGLE; - p_data->p_buf->len -= AVCT_HDR_LEN_SINGLE; - (*p_ccb->cc.p_msg_cback)(avct_ccb_to_idx(p_ccb), label, cr_ipid, p_data->p_buf); - } - else - { - /* PID not found; drop message */ - AVCT_TRACE_WARNING1("No ccb for PID=%x", pid); - GKI_freebuf(p_data->p_buf); - - /* if command send reject */ - if (cr_ipid == AVCT_CMD) - { - if ((p_buf = (BT_HDR *) GKI_getpoolbuf(AVCT_CMD_POOL_ID)) != NULL) - { - p_buf->len = AVCT_HDR_LEN_SINGLE; - p_buf->offset = AVCT_MSG_OFFSET - AVCT_HDR_LEN_SINGLE; - p = (UINT8 *)(p_buf + 1) + p_buf->offset; - AVCT_BLD_HDR(p, label, AVCT_PKT_TYPE_SINGLE, AVCT_REJ); - UINT16_TO_BE_STREAM(p, pid); - L2CA_DataWrite(p_bcb->ch_lcid, p_buf); - } - } - } -} - -/******************************************************************************* -** -** Function avct_bcb_dealloc -** -** Description Deallocate a link control block. -** -** -** Returns void. -** -*******************************************************************************/ -void avct_bcb_dealloc(tAVCT_BCB *p_bcb, tAVCT_LCB_EVT *p_data) -{ - tAVCT_CCB *p_ccb = &avct_cb.ccb[0]; - tAVCT_CCB *p_ccb_found = NULL; - BOOLEAN found = FALSE; - int i; - - AVCT_TRACE_DEBUG1("avct_bcb_dealloc %d", p_bcb->allocated); - - for (i = 0; i < AVCT_NUM_CONN; i++, p_ccb++) - { - /* if ccb allocated and */ - if (p_ccb->allocated) - { - if (p_ccb->p_bcb == p_bcb) - { - p_ccb_found = p_ccb; - p_ccb->p_bcb = NULL; - AVCT_TRACE_DEBUG1("avct_bcb_dealloc used by ccb: %d", i); - found = TRUE; - break; - } - } - } - - /* the browsing channel is down. Check if we have pending messages */ - if (p_bcb->p_tx_msg != NULL) - { - GKI_freebuf(p_bcb->p_tx_msg); - } - memset(p_bcb, 0, sizeof(tAVCT_BCB)); -} - -/******************************************************************************* -** -** Function avct_close_bcb -** -** Description this function is called right before LCB disconnects. -** -** -** Returns Nothing. -** -*******************************************************************************/ -void avct_close_bcb(tAVCT_LCB *p_lcb, tAVCT_LCB_EVT *p_data) -{ - tAVCT_BCB *p_bcb = avct_bcb_by_lcb(p_lcb); - if (p_bcb->allocated) - { - avct_bcb_event(p_bcb, AVCT_LCB_UL_UNBIND_EVT, p_data); - } -} - - -/******************************************************************************* -** -** Function avct_lcb_by_bcb -** -** Description This lookup function finds the lcb for a bcb. -** -** Returns pointer to the lcb. -** -*******************************************************************************/ -tAVCT_LCB *avct_lcb_by_bcb(tAVCT_BCB *p_bcb) -{ - return &avct_cb.lcb[p_bcb->allocated - 1]; -} - -/******************************************************************************* -** -** Function avct_bcb_by_lcb -** -** Description This lookup function finds the bcb for a lcb. -** -** Returns pointer to the lcb. -** -*******************************************************************************/ -tAVCT_BCB *avct_bcb_by_lcb(tAVCT_LCB *p_lcb) -{ - return &avct_cb.bcb[p_lcb->allocated - 1]; -} - -/******************************************************************************* -** -** Function avct_bcb_last_ccb -** -** Description See if given ccb is only one on the bcb. -** -** -** Returns 0, if ccb is last, (ccb index + 1) otherwise. -** -*******************************************************************************/ -UINT8 avct_bcb_last_ccb(tAVCT_BCB *p_bcb, tAVCT_CCB *p_ccb_last) -{ - tAVCT_CCB *p_ccb = &avct_cb.ccb[0]; - int i; - UINT8 idx = 0; - - for (i = 0; i < AVCT_NUM_CONN; i++, p_ccb++) - { - if (p_ccb->allocated && (p_ccb->p_bcb == p_bcb)) - { - if (p_ccb != p_ccb_last) - return 0; - idx = (UINT8)(i + 1); - } - } - return idx; -} - -/******************************************************************************* -** -** Function avct_bcb_by_lcid -** -** Description Find the BCB associated with the L2CAP LCID -** -** -** Returns pointer to the lcb, or NULL if none found. -** -*******************************************************************************/ -tAVCT_BCB *avct_bcb_by_lcid(UINT16 lcid) -{ - tAVCT_BCB *p_bcb = &avct_cb.bcb[0]; - int i; - - for (i = 0; i < AVCT_NUM_LINKS; i++, p_bcb++) - { - if (p_bcb->allocated && (p_bcb->ch_lcid == lcid)) - { - break; - } - } - - if (i == AVCT_NUM_LINKS) - { - p_bcb = NULL; - /* out of lcbs */ - AVCT_TRACE_WARNING1("No bcb for lcid %x", lcid); - } - - return p_bcb; -} -#endif /* (AVCT_BROWSE_INCLUDED == TRUE) */ diff --git a/stack/avct/avct_l2c_br.c b/stack/avct/avct_l2c_br.c deleted file mode 100644 index e333edf..0000000 --- a/stack/avct/avct_l2c_br.c +++ /dev/null @@ -1,397 +0,0 @@ -/***************************************************************************** -** -** Name: avct_l2c_br.c -** -** Description: This AVCTP module interfaces to L2CAP -** -** Copyright (c) 2008, Broadcom Corp., All Rights Reserved. -** Broadcom Bluetooth Core. Proprietary and confidential. -** -*****************************************************************************/ - -#include <string.h> -#include "data_types.h" -#include "bt_target.h" -#include "avct_api.h" -#include "avct_int.h" -#include "l2c_api.h" -#include "l2cdefs.h" - -/* Configuration flags. */ -#define AVCT_L2C_CFG_IND_DONE (1<<0) -#define AVCT_L2C_CFG_CFM_DONE (1<<1) - -#if (AVCT_BROWSE_INCLUDED == TRUE) -/* callback function declarations */ -void avct_l2c_br_connect_ind_cback(BD_ADDR bd_addr, UINT16 lcid, UINT16 psm, UINT8 id); -void avct_l2c_br_connect_cfm_cback(UINT16 lcid, UINT16 result); -void avct_l2c_br_config_cfm_cback(UINT16 lcid, tL2CAP_CFG_INFO *p_cfg); -void avct_l2c_br_config_ind_cback(UINT16 lcid, tL2CAP_CFG_INFO *p_cfg); -void avct_l2c_br_disconnect_ind_cback(UINT16 lcid, BOOLEAN ack_needed); -void avct_l2c_br_disconnect_cfm_cback(UINT16 lcid, UINT16 result); -void avct_l2c_br_congestion_ind_cback(UINT16 lcid, BOOLEAN is_congested); -void avct_l2c_br_data_ind_cback(UINT16 lcid, BT_HDR *p_buf); - -/* L2CAP callback function structure */ -const tL2CAP_APPL_INFO avct_l2c_br_appl = { - avct_l2c_br_connect_ind_cback, - avct_l2c_br_connect_cfm_cback, - NULL, - avct_l2c_br_config_ind_cback, - avct_l2c_br_config_cfm_cback, - avct_l2c_br_disconnect_ind_cback, - avct_l2c_br_disconnect_cfm_cback, - NULL, - avct_l2c_br_data_ind_cback, - avct_l2c_br_congestion_ind_cback, - NULL /* tL2CA_TX_COMPLETE_CB */ -}; - -/* Browsing channel eL2CAP default options */ -const tL2CAP_FCR_OPTS avct_l2c_br_fcr_opts_def = { - L2CAP_FCR_ERTM_MODE, /* Mandatory for Browsing channel */ - AVCT_BR_FCR_OPT_TX_WINDOW_SIZE, /* Tx window size */ - AVCT_BR_FCR_OPT_MAX_TX_B4_DISCNT, /* Maximum transmissions before disconnecting */ - AVCT_BR_FCR_OPT_RETX_TOUT, /* Retransmission timeout (2 secs) */ - AVCT_BR_FCR_OPT_MONITOR_TOUT, /* Monitor timeout (12 secs) */ - L2CAP_DEFAULT_ERM_MPS /* MPS segment size */ -}; - -/******************************************************************************* -** -** Function avct_l2c_br_connect_ind_cback -** -** Description This is the L2CAP connect indication callback function. -** -** -** Returns void -** -*******************************************************************************/ -void avct_l2c_br_connect_ind_cback(BD_ADDR bd_addr, UINT16 lcid, UINT16 psm, UINT8 id) -{ - tAVCT_LCB *p_lcb; - UINT16 result = L2CAP_CONN_NO_RESOURCES; - tL2CAP_CFG_INFO cfg; - tAVCT_BCB *p_bcb; - tL2CAP_ERTM_INFO ertm_info; - - memset(&cfg, 0, sizeof(tL2CAP_CFG_INFO)); - cfg.mtu_present = TRUE; - - if ((p_lcb = avct_lcb_by_bd(bd_addr)) != NULL) - { - /* control channel exists */ - p_bcb = avct_bcb_by_lcb(p_lcb); - - if (!p_bcb->allocated) - { - /* browsing channel does not exist yet and the browsing channel is registered - * - accept connection */ - p_bcb->allocated = p_lcb->allocated; /* copy the index from lcb */ - - result = L2CAP_CONN_OK; - cfg.mtu = avct_cb.mtu_br; - - cfg.fcr_present = TRUE; - cfg.fcr = avct_l2c_br_fcr_opts_def; - } - } - /* else no control channel yet, reject */ - - /* Set the FCR options: Browsing channel mandates ERTM */ - ertm_info.preferred_mode = cfg.fcr.mode; - ertm_info.allowed_modes = L2CAP_FCR_CHAN_OPT_ERTM; - ertm_info.user_rx_pool_id = AVCT_BR_USER_RX_POOL_ID; - ertm_info.user_tx_pool_id = AVCT_BR_USER_TX_POOL_ID; - ertm_info.fcr_rx_pool_id = AVCT_BR_FCR_RX_POOL_ID; - ertm_info.fcr_tx_pool_id = AVCT_BR_FCR_TX_POOL_ID; - - /* Send L2CAP connect rsp */ - L2CA_ErtmConnectRsp(bd_addr, id, lcid, result, 0, &ertm_info); - - /* if result ok, proceed with connection */ - if (result == L2CAP_CONN_OK) - { - /* store LCID */ - p_bcb->ch_lcid = lcid; - - /* transition to configuration state */ - p_bcb->ch_state = AVCT_CH_CFG; - - /* Send L2CAP config req */ - L2CA_ConfigReq(lcid, &cfg); - } -} - -/******************************************************************************* -** -** Function avct_l2c_br_connect_cfm_cback -** -** Description This is the L2CAP connect confirm callback function. -** -** -** Returns void -** -*******************************************************************************/ -void avct_l2c_br_connect_cfm_cback(UINT16 lcid, UINT16 result) -{ - tAVCT_BCB *p_lcb; - tL2CAP_CFG_INFO cfg; - - /* look up lcb for this channel */ - if ((p_lcb = avct_bcb_by_lcid(lcid)) != NULL) - { - /* if in correct state */ - if (p_lcb->ch_state == AVCT_CH_CONN) - { - /* if result successful */ - 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_br; - - cfg.fcr_present = TRUE; - cfg.fcr = avct_l2c_br_fcr_opts_def; - - L2CA_ConfigReq(lcid, &cfg); - } - /* else failure */ - else - { - avct_bcb_event(p_lcb, AVCT_LCB_LL_CLOSE_EVT, (tAVCT_LCB_EVT *) &result); - } - } - } -} - -/******************************************************************************* -** -** Function avct_l2c_br_config_cfm_cback -** -** Description This is the L2CAP config confirm callback function. -** -** -** Returns void -** -*******************************************************************************/ -void avct_l2c_br_config_cfm_cback(UINT16 lcid, tL2CAP_CFG_INFO *p_cfg) -{ - tAVCT_BCB *p_lcb; - - /* look up lcb for this channel */ - if ((p_lcb = avct_bcb_by_lcid(lcid)) != NULL) - { - /* 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_bcb_event(p_lcb, AVCT_LCB_LL_OPEN_EVT, NULL); - } - } - /* else failure */ - else - { - /* store result value */ - p_lcb->ch_result = p_cfg->result; - - /* Send L2CAP disconnect req */ - L2CA_DisconnectReq(lcid); - } - } - } -} - -/******************************************************************************* -** -** Function avct_l2c_br_config_ind_cback -** -** Description This is the L2CAP config indication callback function. -** -** -** Returns void -** -*******************************************************************************/ -void avct_l2c_br_config_ind_cback(UINT16 lcid, tL2CAP_CFG_INFO *p_cfg) -{ - tAVCT_BCB *p_lcb; - UINT16 max_mtu = GKI_MAX_BUF_SIZE - L2CAP_MIN_OFFSET - BT_HDR_SIZE; - - /* Don't include QoS nor flush timeout in the response since we - currently always accept these values. Note: fcr_present is left - untouched since l2cap negotiates this internally - */ - p_cfg->flush_to_present = FALSE; - p_cfg->qos_present = FALSE; - - /* look up lcb for this channel */ - if ((p_lcb = avct_bcb_by_lcid(lcid)) != NULL) - { - /* store the mtu in tbl */ - if (p_cfg->mtu_present) - { - p_lcb->peer_mtu = p_cfg->mtu; - } - else - { - p_lcb->peer_mtu = L2CAP_DEFAULT_MTU; - } - - if (p_lcb->peer_mtu > max_mtu) - { - p_lcb->peer_mtu = p_cfg->mtu = max_mtu; - - /* Must tell the peer what the adjusted value is */ - p_cfg->mtu_present = TRUE; - } - else /* Don't include in the response */ - p_cfg->mtu_present = FALSE; - AVCT_TRACE_DEBUG2 ("avct_l2c_br_config_ind_cback peer_mtu:%d use:%d", p_lcb->peer_mtu, max_mtu); - - if (p_lcb->peer_mtu >= AVCT_MIN_BROWSE_MTU) - p_cfg->result = L2CAP_CFG_OK; - else - { - p_cfg->result = L2CAP_CFG_UNACCEPTABLE_PARAMS; - p_cfg->mtu_present = TRUE; - p_cfg->mtu = AVCT_MIN_BROWSE_MTU; - } - - /* send L2CAP configure response */ - L2CA_ConfigRsp(lcid, p_cfg); - - if (p_cfg->result != L2CAP_CFG_OK) - { - return; - } - - /* 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_bcb_event(p_lcb, AVCT_LCB_LL_OPEN_EVT, NULL); - } - } - } -} - -/******************************************************************************* -** -** Function avct_l2c_br_disconnect_ind_cback -** -** Description This is the L2CAP disconnect indication callback function. -** -** -** Returns void -** -*******************************************************************************/ -void avct_l2c_br_disconnect_ind_cback(UINT16 lcid, BOOLEAN ack_needed) -{ - tAVCT_BCB *p_lcb; - UINT16 result = AVCT_RESULT_FAIL; - - /* look up lcb for this channel */ - if ((p_lcb = avct_bcb_by_lcid(lcid)) != NULL) - { - if (ack_needed) - { - /* send L2CAP disconnect response */ - L2CA_DisconnectRsp(lcid); - } - - avct_bcb_event(p_lcb, AVCT_LCB_LL_CLOSE_EVT, (tAVCT_LCB_EVT *) &result); - } -} - -/******************************************************************************* -** -** Function avct_l2c_br_disconnect_cfm_cback -** -** Description This is the L2CAP disconnect confirm callback function. -** -** -** Returns void -** -*******************************************************************************/ -void avct_l2c_br_disconnect_cfm_cback(UINT16 lcid, UINT16 result) -{ - tAVCT_BCB *p_lcb; - UINT16 res; - - /* look up lcb for this channel */ - if ((p_lcb = avct_bcb_by_lcid(lcid)) != NULL) - { - /* result value may be previously stored */ - res = (p_lcb->ch_result != 0) ? p_lcb->ch_result : result; - p_lcb->ch_result = 0; - - avct_bcb_event(p_lcb, AVCT_LCB_LL_CLOSE_EVT, (tAVCT_LCB_EVT *) &res); - } -} - -/******************************************************************************* -** -** Function avct_l2c_br_congestion_ind_cback -** -** Description This is the L2CAP congestion indication callback function. -** -** -** Returns void -** -*******************************************************************************/ -void avct_l2c_br_congestion_ind_cback(UINT16 lcid, BOOLEAN is_congested) -{ - tAVCT_BCB *p_lcb; - - /* look up lcb for this channel */ - if ((p_lcb = avct_bcb_by_lcid(lcid)) != NULL) - { - avct_bcb_event(p_lcb, AVCT_LCB_LL_CONG_EVT, (tAVCT_LCB_EVT *) &is_congested); - } -} - -/******************************************************************************* -** -** Function avct_l2c_br_data_ind_cback -** -** Description This is the L2CAP data indication callback function. -** -** -** Returns void -** -*******************************************************************************/ -void avct_l2c_br_data_ind_cback(UINT16 lcid, BT_HDR *p_buf) -{ - tAVCT_BCB *p_lcb; - - /* look up lcb for this channel */ - if ((p_lcb = avct_bcb_by_lcid(lcid)) != NULL) - { - avct_bcb_event(p_lcb, AVCT_LCB_LL_MSG_EVT, (tAVCT_LCB_EVT *) &p_buf); - } - else /* prevent buffer leak */ - GKI_freebuf(p_buf); -} -#endif /* (AVCT_BROWSE_INCLUDED == TRUE) */ - - |