2016-11-02 05:42:26 -04:00
|
|
|
/******************************************************************************
|
|
|
|
*
|
|
|
|
* Copyright (C) 2003-2012 Broadcom Corporation
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at:
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
*
|
|
|
|
* This module contains functions which operate on the AVCTP connection
|
|
|
|
* control block.
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include "bt_types.h"
|
|
|
|
#include "bt_target.h"
|
|
|
|
#include "avct_api.h"
|
|
|
|
#include "avct_int.h"
|
|
|
|
|
2017-03-17 03:08:47 -04:00
|
|
|
#if (defined(AVCT_INCLUDED) && AVCT_INCLUDED == TRUE)
|
|
|
|
|
2016-11-02 05:42:26 -04:00
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function avct_ccb_alloc
|
|
|
|
**
|
|
|
|
** Description Allocate a connection control block; copy parameters to ccb.
|
|
|
|
**
|
|
|
|
**
|
|
|
|
** Returns pointer to the ccb, or NULL if none could be allocated.
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
tAVCT_CCB *avct_ccb_alloc(tAVCT_CC *p_cc)
|
|
|
|
{
|
|
|
|
tAVCT_CCB *p_ccb = &avct_cb.ccb[0];
|
|
|
|
int i;
|
|
|
|
|
2017-03-17 10:46:49 -04:00
|
|
|
for (i = 0; i < AVCT_NUM_CONN; i++, p_ccb++) {
|
|
|
|
if (!p_ccb->allocated) {
|
2016-11-02 05:42:26 -04:00
|
|
|
p_ccb->allocated = AVCT_ALOC_LCB;
|
|
|
|
memcpy(&p_ccb->cc, p_cc, sizeof(tAVCT_CC));
|
|
|
|
AVCT_TRACE_DEBUG("avct_ccb_alloc %d", i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-17 10:46:49 -04:00
|
|
|
if (i == AVCT_NUM_CONN) {
|
2016-11-02 05:42:26 -04:00
|
|
|
/* out of ccbs */
|
|
|
|
p_ccb = NULL;
|
|
|
|
AVCT_TRACE_WARNING("Out of ccbs");
|
|
|
|
}
|
|
|
|
return p_ccb;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function avct_ccb_dealloc
|
|
|
|
**
|
|
|
|
** Description Deallocate a connection control block and call application
|
|
|
|
** callback.
|
|
|
|
**
|
|
|
|
**
|
|
|
|
** Returns void.
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void avct_ccb_dealloc(tAVCT_CCB *p_ccb, UINT8 event, UINT16 result, BD_ADDR bd_addr)
|
|
|
|
{
|
|
|
|
tAVCT_CTRL_CBACK *p_cback = p_ccb->cc.p_ctrl_cback;
|
|
|
|
|
|
|
|
AVCT_TRACE_DEBUG("avct_ccb_dealloc %d", avct_ccb_to_idx(p_ccb));
|
|
|
|
#if (AVCT_BROWSE_INCLUDED == TRUE)
|
2017-03-17 10:46:49 -04:00
|
|
|
if (p_ccb->p_bcb == NULL) {
|
2016-11-02 05:42:26 -04:00
|
|
|
memset(p_ccb, 0, sizeof(tAVCT_CCB));
|
2017-03-17 10:46:49 -04:00
|
|
|
} else {
|
2016-11-02 05:42:26 -04:00
|
|
|
/* control channel is down, but the browsing channel is still connected 0 disconnect it now */
|
|
|
|
avct_bcb_event(p_ccb->p_bcb, AVCT_LCB_UL_UNBIND_EVT, (tAVCT_LCB_EVT *) &p_ccb);
|
|
|
|
p_ccb->p_lcb = NULL;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
memset(p_ccb, 0, sizeof(tAVCT_CCB));
|
|
|
|
#endif
|
|
|
|
|
2017-03-17 10:46:49 -04:00
|
|
|
if (event != AVCT_NO_EVT) {
|
2016-11-02 05:42:26 -04:00
|
|
|
(*p_cback)(avct_ccb_to_idx(p_ccb), event, result, bd_addr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function avct_ccb_to_idx
|
|
|
|
**
|
|
|
|
** Description Given a pointer to an ccb, return its index.
|
|
|
|
**
|
|
|
|
**
|
|
|
|
** Returns Index of ccb.
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
UINT8 avct_ccb_to_idx(tAVCT_CCB *p_ccb)
|
|
|
|
{
|
|
|
|
/* use array arithmetic to determine index */
|
|
|
|
return (UINT8) (p_ccb - avct_cb.ccb);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function avct_ccb_by_idx
|
|
|
|
**
|
|
|
|
** Description Return ccb pointer based on ccb index (or handle).
|
|
|
|
**
|
|
|
|
**
|
|
|
|
** Returns pointer to the ccb, or NULL if none found.
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
tAVCT_CCB *avct_ccb_by_idx(UINT8 idx)
|
|
|
|
{
|
|
|
|
tAVCT_CCB *p_ccb;
|
|
|
|
|
|
|
|
/* verify index */
|
2017-03-17 10:46:49 -04:00
|
|
|
if (idx < AVCT_NUM_CONN) {
|
2016-11-02 05:42:26 -04:00
|
|
|
p_ccb = &avct_cb.ccb[idx];
|
|
|
|
|
|
|
|
/* verify ccb is allocated */
|
2017-03-17 10:46:49 -04:00
|
|
|
if (!p_ccb->allocated) {
|
2016-11-02 05:42:26 -04:00
|
|
|
p_ccb = NULL;
|
|
|
|
AVCT_TRACE_WARNING("ccb %d not allocated", idx);
|
|
|
|
}
|
2017-03-17 10:46:49 -04:00
|
|
|
} else {
|
2016-11-02 05:42:26 -04:00
|
|
|
p_ccb = NULL;
|
|
|
|
AVCT_TRACE_WARNING("No ccb for idx %d", idx);
|
|
|
|
}
|
|
|
|
return p_ccb;
|
|
|
|
}
|
2017-03-17 03:08:47 -04:00
|
|
|
|
|
|
|
#endif /* #if (defined(AVCT_INCLUDED) && AVCT_INCLUDED == TRUE) */
|