15738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/****************************************************************************** 25738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project * 35738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project * Copyright (C) 2002-2012 Broadcom Corporation 45738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project * 55738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project * Licensed under the Apache License, Version 2.0 (the "License"); 65738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project * you may not use this file except in compliance with the License. 75738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project * You may obtain a copy of the License at: 85738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project * 95738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project * http://www.apache.org/licenses/LICENSE-2.0 105738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project * 115738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project * Unless required by applicable law or agreed to in writing, software 125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project * distributed under the License is distributed on an "AS IS" BASIS, 135738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project * See the License for the specific language governing permissions and 155738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project * limitations under the License. 165738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project * 175738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project ******************************************************************************/ 185738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 195738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/****************************************************************************** 205738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project * 215738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project * This module contains the AVDTP adaption layer. 225738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project * 235738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project ******************************************************************************/ 245738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 255738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#include <string.h> 265738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#include "data_types.h" 275738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#include "bt_target.h" 285738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#include "avdt_api.h" 295738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#include "avdtc_api.h" 305738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#include "avdt_int.h" 315738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#include "l2c_api.h" 325738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#include "l2cdefs.h" 335738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#include "wcassert.h" 345738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 355738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 365738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/******************************************************************************* 375738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 385738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function avdt_ad_type_to_tcid 395738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 405738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description Derives the TCID from the channel type and SCB. 415738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 425738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 435738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns TCID value. 445738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 455738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/ 465738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source ProjectUINT8 avdt_ad_type_to_tcid(UINT8 type, tAVDT_SCB *p_scb) 475738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 485738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project UINT8 scb_idx; 495738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 505738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (type == AVDT_CHAN_SIG) 515738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 525738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project return 0; 535738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 545738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project else 555738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 565738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project scb_idx = avdt_scb_to_hdl(p_scb) - 1; 575738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* 585738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project AVDT_TRACE_DEBUG2("type: %d, tcid: %d", type, ((scb_idx * (AVDT_CHAN_NUM_TYPES - 1)) + type)); 595738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project */ 605738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project return ((scb_idx * (AVDT_CHAN_NUM_TYPES - 1)) + type); 615738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 625738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project} 635738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 645738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/******************************************************************************* 655738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 665738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function avdt_ad_tcid_to_type 675738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 685738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description Derives the channel type from the TCID. 695738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 705738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 715738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns Channel type value. 725738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 735738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/ 745738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectstatic UINT8 avdt_ad_tcid_to_type(UINT8 tcid) 755738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 765738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project UINT8 type; 775738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 785738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (tcid == 0) 795738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 805738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project type = AVDT_CHAN_SIG; 815738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 825738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project else 835738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 845738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* tcid translates to type based on number of channels, as follows: 855738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project ** only media channel : tcid=1,2,3,4,5,6... type=1,1,1,1,1,1... 865738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project ** media and report : tcid=1,2,3,4,5,6... type=1,2,1,2,1,2... 875738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project ** media, report, recov : tcid=1,2,3,4,5,6... type=1,2,3,1,2,3... 885738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project */ 895738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project type = ((tcid + AVDT_CHAN_NUM_TYPES - 2) % (AVDT_CHAN_NUM_TYPES - 1)) + 1; 905738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 915738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project AVDT_TRACE_DEBUG2("tcid: %d, type: %d", tcid, type); 925738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project return type; 935738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project} 945738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 955738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 965738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/******************************************************************************* 975738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 985738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function avdt_ad_init 995738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 1005738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description Initialize adaption layer. 1015738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 1025738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 1035738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns Nothing. 1045738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 1055738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/ 1065738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid avdt_ad_init(void) 1075738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 1085738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project int i; 1095738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project tAVDT_TC_TBL *p_tbl = avdt_cb.ad.tc_tbl; 1105738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project memset(&avdt_cb.ad, 0, sizeof(tAVDT_AD)); 1115738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 1125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* make sure the peer_mtu is a valid value */ 1135738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project for (i = 0; i < AVDT_NUM_TC_TBL; i++, p_tbl++) 1145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 1155738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_tbl->peer_mtu = L2CAP_DEFAULT_MTU; 1165738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 1175738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project} 1185738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 1195738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 1205738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/******************************************************************************* 1215738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 1225738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function avdt_ad_tc_tbl_by_st 1235738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 1245738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description Find adaption layer transport channel table entry matching 1255738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** the given state. 1265738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 1275738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 1285738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns Pointer to matching entry. For control channel it returns 1295738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** the matching entry. For media or other it returns the 1305738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** first matching entry (there could be more than one). 1315738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 1325738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/ 1335738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source ProjecttAVDT_TC_TBL *avdt_ad_tc_tbl_by_st(UINT8 type, tAVDT_CCB *p_ccb, UINT8 state) 1345738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 1355738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project int i; 1365738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project tAVDT_TC_TBL *p_tbl = avdt_cb.ad.tc_tbl; 1375738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project UINT8 ccb_idx; 1385738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 1395738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (p_ccb == NULL) 1405738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 1415738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* resending security req */ 1425738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project for (i = 0; i < AVDT_NUM_TC_TBL; i++, p_tbl++) 1435738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 1445738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* must be AVDT_CHAN_SIG - tcid always zero */ 1455738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if ((p_tbl->tcid == 0) && 1465738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project (p_tbl->state == state)) 1475738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 1485738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project break; 1495738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 1505738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 1515738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 1525738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project else 1535738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 1545738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project ccb_idx = avdt_ccb_to_idx(p_ccb); 1555738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 1565738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project for (i = 0; i < AVDT_NUM_TC_TBL; i++, p_tbl++) 1575738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 1585738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (type == AVDT_CHAN_SIG) 1595738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 1605738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* if control channel, tcid always zero */ 1615738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if ((p_tbl->tcid == 0) && 1625738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project (p_tbl->ccb_idx == ccb_idx) && 1635738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project (p_tbl->state == state)) 1645738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 1655738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project break; 1665738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 1675738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 1685738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project else 1695738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 1705738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* if other channel, tcid is always > zero */ 1715738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if ((p_tbl->tcid > 0) && 1725738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project (p_tbl->ccb_idx == ccb_idx) && 1735738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project (p_tbl->state == state)) 1745738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 1755738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project break; 1765738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 1775738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 1785738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 1795738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 1805738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 1815738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* if nothing found return null */ 1825738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (i == AVDT_NUM_TC_TBL) 1835738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 1845738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_tbl = NULL; 1855738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 1865738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 1875738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project return p_tbl; 1885738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project} 1895738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 1905738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 1915738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/******************************************************************************* 1925738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 1935738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function avdt_ad_tc_tbl_by_lcid 1945738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 1955738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description Find adaption layer transport channel table entry by LCID. 1965738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 1975738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 1985738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns Pointer to entry. 1995738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 2005738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/ 2015738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source ProjecttAVDT_TC_TBL *avdt_ad_tc_tbl_by_lcid(UINT16 lcid) 2025738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 2035738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project UINT8 idx; 2045738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 2055738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project idx = avdt_cb.ad.lcid_tbl[lcid - L2CAP_BASE_APPL_CID]; 2065738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 2075738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (idx < AVDT_NUM_TC_TBL) 2085738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 2095738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project return &avdt_cb.ad.tc_tbl[idx]; 2105738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 2115738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project else 2125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 2135738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project return NULL; 2145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 2155738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project} 2165738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 2175738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 2185738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/******************************************************************************* 2195738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 2205738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function avdt_ad_tc_tbl_by_type 2215738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 2225738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description This function retrieves the transport channel table entry 2235738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** for a particular channel. 2245738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 2255738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 2265738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns Pointer to transport channel table entry. 2275738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 2285738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/ 2295738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source ProjecttAVDT_TC_TBL *avdt_ad_tc_tbl_by_type(UINT8 type, tAVDT_CCB *p_ccb, tAVDT_SCB *p_scb) 2305738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 2315738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project UINT8 tcid; 2325738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project int i; 2335738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project tAVDT_TC_TBL *p_tbl = avdt_cb.ad.tc_tbl; 2345738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project UINT8 ccb_idx = avdt_ccb_to_idx(p_ccb); 2355738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 2365738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* get tcid from type, scb */ 2375738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project tcid = avdt_ad_type_to_tcid(type, p_scb); 2385738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 2395738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project for (i = 0; i < AVDT_NUM_TC_TBL; i++, p_tbl++) 2405738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 2415738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if ((p_tbl->tcid == tcid) && (p_tbl->ccb_idx == ccb_idx)) 2425738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 2435738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project break; 2445738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 2455738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 2465738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 2475738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project WC_ASSERT(i != AVDT_NUM_TC_TBL); 2485738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 2495738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project return p_tbl; 2505738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project} 2515738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 2525738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 2535738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/******************************************************************************* 2545738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 2555738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function avdt_ad_tc_tbl_alloc 2565738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 2575738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description Allocate an entry in the traffic channel table. 2585738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 2595738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 2605738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns Pointer to entry. 2615738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 2625738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/ 2635738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source ProjecttAVDT_TC_TBL *avdt_ad_tc_tbl_alloc(tAVDT_CCB *p_ccb) 2645738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 2655738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project int i; 2665738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project tAVDT_TC_TBL *p_tbl = avdt_cb.ad.tc_tbl; 2675738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 2685738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* find next free entry in tc table */ 2695738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project for (i = 0; i < AVDT_NUM_TC_TBL; i++, p_tbl++) 2705738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 2715738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (p_tbl->state == AVDT_AD_ST_UNUSED) 2725738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 2735738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project break; 2745738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 2755738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 2765738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 2775738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* sanity check */ 2785738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project WC_ASSERT(i != AVDT_NUM_TC_TBL); 2795738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 2805738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* initialize entry */ 2815738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_tbl->peer_mtu = L2CAP_DEFAULT_MTU; 2825738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_tbl->cfg_flags = 0; 2835738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_tbl->ccb_idx = avdt_ccb_to_idx(p_ccb); 2845738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_tbl->state = AVDT_AD_ST_IDLE; 2855738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 2865738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project return p_tbl; 2875738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project} 2885738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 2895738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/******************************************************************************* 2905738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 2915738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function avdt_ad_tc_tbl_to_idx 2925738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 2935738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description Convert a transport channel table entry to an index. 2945738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 2955738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 2965738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns Index value. 2975738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 2985738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/ 2995738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source ProjectUINT8 avdt_ad_tc_tbl_to_idx(tAVDT_TC_TBL *p_tbl) 3005738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 3015738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project AVDT_TRACE_DEBUG1("avdt_ad_tc_tbl_to_idx: %d", (p_tbl - avdt_cb.ad.tc_tbl)); 3025738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* use array arithmetic to determine index */ 3035738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project return (UINT8) (p_tbl - avdt_cb.ad.tc_tbl); 3045738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project} 3055738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 3065738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/******************************************************************************* 3075738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 3085738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function avdt_ad_tc_close_ind 3095738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 3105738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description This function is called by the L2CAP interface when the 3115738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** L2CAP channel is closed. It looks up the CCB or SCB for 3125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** the channel and sends it a close event. The reason 3135738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** parameter is the same value passed by the L2CAP 3145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** callback function. 3155738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 3165738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 3175738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns Nothing. 3185738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 3195738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/ 3205738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid avdt_ad_tc_close_ind(tAVDT_TC_TBL *p_tbl, UINT16 reason) 3215738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 3225738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project tAVDT_CCB *p_ccb; 3235738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project tAVDT_SCB *p_scb; 3245738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project tAVDT_SCB_TC_CLOSE close; 3255738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 3265738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project close.old_tc_state = p_tbl->state; 3275738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* clear avdt_ad_tc_tbl entry */ 3285738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_tbl->state = AVDT_AD_ST_UNUSED; 3295738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_tbl->cfg_flags = 0; 3305738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_tbl->peer_mtu = L2CAP_DEFAULT_MTU; 3315738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 3325738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project AVDT_TRACE_DEBUG2("avdt_ad_tc_close_ind tcid: %d, old: %d", 3335738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_tbl->tcid, close.old_tc_state); 3345738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* if signaling channel, notify ccb that channel open */ 3355738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (p_tbl->tcid == 0) 3365738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 3375738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_ccb = avdt_ccb_by_idx(p_tbl->ccb_idx); 3385738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project avdt_ccb_event(p_ccb, AVDT_CCB_LL_CLOSE_EVT, NULL); 3395738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 3405738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* if media or other channel, notify scb that channel close */ 3415738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project else 3425738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 3435738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* look up scb in stream routing table by ccb, tcid */ 3445738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_scb = avdt_scb_by_hdl(avdt_cb.ad.rt_tbl[p_tbl->ccb_idx][p_tbl->tcid].scb_hdl); 3455738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (p_scb != NULL) 3465738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 3475738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project close.tcid = p_tbl->tcid; 3485738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project close.type = avdt_ad_tcid_to_type(p_tbl->tcid); 3495738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project avdt_scb_event(p_scb, AVDT_SCB_TC_CLOSE_EVT, (tAVDT_SCB_EVT *)&close); 3505738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 3515738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 3525738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project} 3535738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 3545738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/******************************************************************************* 3555738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 3565738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function avdt_ad_tc_open_ind 3575738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 3585738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description This function is called by the L2CAP interface when 3595738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** the L2CAP channel is opened. It looks up the CCB or SCB 3605738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** for the channel and sends it an open event. 3615738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 3625738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 3635738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns Nothing. 3645738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 3655738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/ 3665738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid avdt_ad_tc_open_ind(tAVDT_TC_TBL *p_tbl) 3675738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 3685738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project tAVDT_CCB *p_ccb; 3695738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project tAVDT_SCB *p_scb; 3705738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project tAVDT_OPEN open; 3715738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project tAVDT_EVT_HDR evt; 3725738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 3735738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_tbl->state = AVDT_AD_ST_OPEN; 3745738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 3755738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* if signaling channel, notify ccb that channel open */ 3765738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (p_tbl->tcid == 0) 3775738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 3785738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* set the signal channel to use high priority within the ACL link */ 3795738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project L2CA_SetTxPriority(avdt_cb.ad.rt_tbl[p_tbl->ccb_idx][AVDT_CHAN_SIG].lcid, L2CAP_CHNL_PRIORITY_HIGH); 3805738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 3815738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_ccb = avdt_ccb_by_idx(p_tbl->ccb_idx); 3825738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* use err_param to indicate the role of connection. 3835738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project * AVDT_ACP, if ACP */ 3845738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project evt.err_param = AVDT_INT; 3855738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if(p_tbl->cfg_flags & AVDT_L2C_CFG_CONN_ACP) 3865738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 3875738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project evt.err_param = AVDT_ACP; 3885738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 3895738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project avdt_ccb_event(p_ccb, AVDT_CCB_LL_OPEN_EVT, (tAVDT_CCB_EVT *)&evt); 3905738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 3915738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* if media or other channel, notify scb that channel open */ 3925738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project else 3935738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 3945738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* look up scb in stream routing table by ccb, tcid */ 3955738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_scb = avdt_scb_by_hdl(avdt_cb.ad.rt_tbl[p_tbl->ccb_idx][p_tbl->tcid].scb_hdl); 3965738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 3975738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* put lcid in event data */ 3985738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (p_scb != NULL) 3995738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 4005738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project open.peer_mtu = p_tbl->peer_mtu; 4015738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project open.lcid = avdt_cb.ad.rt_tbl[p_tbl->ccb_idx][p_tbl->tcid].lcid; 4025738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project open.hdr.err_code = avdt_ad_tcid_to_type(p_tbl->tcid); 4035738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project avdt_scb_event(p_scb, AVDT_SCB_TC_OPEN_EVT, (tAVDT_SCB_EVT *) &open); 4045738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 4055738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 4065738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project} 4075738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 4085738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 4095738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/******************************************************************************* 4105738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 4115738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function avdt_ad_tc_cong_ind 4125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 4135738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description This function is called by the L2CAP interface layer when 4145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** L2CAP calls the congestion callback. It looks up the CCB 4155738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** or SCB for the channel and sends it a congestion event. 4165738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** The is_congested parameter is the same value passed by 4175738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** the L2CAP callback function. 4185738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 4195738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 4205738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns Nothing. 4215738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 4225738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/ 4235738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid avdt_ad_tc_cong_ind(tAVDT_TC_TBL *p_tbl, BOOLEAN is_congested) 4245738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 4255738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project tAVDT_CCB *p_ccb; 4265738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project tAVDT_SCB *p_scb; 4275738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 4285738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* if signaling channel, notify ccb of congestion */ 4295738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (p_tbl->tcid == 0) 4305738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 4315738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_ccb = avdt_ccb_by_idx(p_tbl->ccb_idx); 4325738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project avdt_ccb_event(p_ccb, AVDT_CCB_LL_CONG_EVT, (tAVDT_CCB_EVT *) &is_congested); 4335738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 4345738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* if media or other channel, notify scb that channel open */ 4355738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project else 4365738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 4375738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* look up scb in stream routing table by ccb, tcid */ 4385738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_scb = avdt_scb_by_hdl(avdt_cb.ad.rt_tbl[p_tbl->ccb_idx][p_tbl->tcid].scb_hdl); 4395738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (p_scb != NULL) 4405738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 4415738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project avdt_scb_event(p_scb, AVDT_SCB_TC_CONG_EVT, (tAVDT_SCB_EVT *) &is_congested); 4425738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 4435738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 4445738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project} 4455738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 4465738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 4475738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/******************************************************************************* 4485738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 4495738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function avdt_ad_tc_data_ind 4505738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 4515738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description This function is called by the L2CAP interface layer when 4525738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** incoming data is received from L2CAP. It looks up the CCB 4535738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** or SCB for the channel and routes the data accordingly. 4545738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 4555738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 4565738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns Nothing. 4575738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 4585738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/ 4595738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid avdt_ad_tc_data_ind(tAVDT_TC_TBL *p_tbl, BT_HDR *p_buf) 4605738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 4615738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project tAVDT_CCB *p_ccb; 4625738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project tAVDT_SCB *p_scb; 4635738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 4645738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* store type (media, recovery, reporting) */ 4655738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_buf->layer_specific = avdt_ad_tcid_to_type(p_tbl->tcid); 4665738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 4675738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 4685738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* if signaling channel, handle control message */ 4695738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (p_tbl->tcid == 0) 4705738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 4715738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_ccb = avdt_ccb_by_idx(p_tbl->ccb_idx); 4725738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project avdt_msg_ind(p_ccb, p_buf); 4735738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 4745738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* if media or other channel, send event to scb */ 4755738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project else 4765738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 4775738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_scb = avdt_scb_by_hdl(avdt_cb.ad.rt_tbl[p_tbl->ccb_idx][p_tbl->tcid].scb_hdl); 4785738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (p_scb != NULL) 4795738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 4805738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project avdt_scb_event(p_scb, AVDT_SCB_TC_DATA_EVT, (tAVDT_SCB_EVT *) &p_buf); 4815738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 4825738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project else 4835738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project GKI_freebuf(p_buf); 4845738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 4855738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project} 4865738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 4875738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/******************************************************************************* 4885738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 4895738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function avdt_ad_write_req 4905738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 4915738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description This function is called by a CCB or SCB to send data to a 4925738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** transport channel. It looks up the LCID of the channel 4935738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** based on the type, CCB, and SCB (if present). Then it 4945738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** passes the data to L2CA_DataWrite(). 4955738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 4965738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 4975738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns AVDT_AD_SUCCESS, if data accepted, else FALSE 4985738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** AVDT_AD_CONGESTED, if data accepted and the channel is congested 4995738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** AVDT_AD_FAILED, if error 5005738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 5015738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/ 5025738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source ProjectUINT8 avdt_ad_write_req(UINT8 type, tAVDT_CCB *p_ccb, tAVDT_SCB *p_scb, BT_HDR *p_buf) 5035738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 5045738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project UINT8 tcid; 5055738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 5065738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* get tcid from type, scb */ 5075738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project tcid = avdt_ad_type_to_tcid(type, p_scb); 5085738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 5095738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 5105738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project return L2CA_DataWrite(avdt_cb.ad.rt_tbl[avdt_ccb_to_idx(p_ccb)][tcid].lcid, p_buf); 5115738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project} 5125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 5135738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 5145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/******************************************************************************* 5155738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 5165738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function avdt_ad_open_req 5175738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 5185738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description This function is called by a CCB or SCB to open a transport 5195738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** channel. This function allocates and initializes a 5205738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** transport channel table entry. The channel can be opened 5215738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** in two roles: as an initiator or acceptor. When opened 5225738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** as an initiator the function will start an L2CAP connection. 5235738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** When opened as an acceptor the function simply configures 5245738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** the table entry to listen for an incoming channel. 5255738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 5265738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 5275738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns Nothing. 5285738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 5295738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/ 5305738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid avdt_ad_open_req(UINT8 type, tAVDT_CCB *p_ccb, tAVDT_SCB *p_scb, UINT8 role) 5315738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 5325738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project tAVDT_TC_TBL *p_tbl; 5335738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project UINT16 lcid; 5345738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 5355738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_tbl = avdt_ad_tc_tbl_alloc(p_ccb); 5365738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 5375738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_tbl->tcid = avdt_ad_type_to_tcid(type, p_scb); 5385738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project AVDT_TRACE_DEBUG3("avdt_ad_open_req: type: %d, role: %d, tcid:%d", 5395738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project type, role, p_tbl->tcid); 5405738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 5415738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (type == AVDT_CHAN_SIG) 5425738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 5435738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* if signaling, get mtu from registration control block */ 5445738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_tbl->my_mtu = avdt_cb.rcb.ctrl_mtu; 5455738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_tbl->my_flush_to = L2CAP_DEFAULT_FLUSH_TO; 5465738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 5475738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project else 5485738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 5495738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* otherwise get mtu from scb */ 5505738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_tbl->my_mtu = p_scb->cs.mtu; 5515738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_tbl->my_flush_to = p_scb->cs.flush_to; 5525738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 5535738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* also set scb_hdl in rt_tbl */ 5545738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project avdt_cb.ad.rt_tbl[avdt_ccb_to_idx(p_ccb)][p_tbl->tcid].scb_hdl = avdt_scb_to_hdl(p_scb); 5555738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project AVDT_TRACE_DEBUG3("avdt_cb.ad.rt_tbl[%d][%d].scb_hdl = %d", 5565738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project avdt_ccb_to_idx(p_ccb), p_tbl->tcid, 5575738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project avdt_scb_to_hdl(p_scb)); 5585738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 5595738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 5605738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* if we're acceptor, we're done; just sit back and listen */ 5615738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (role == AVDT_ACP) 5625738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 5635738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_tbl->state = AVDT_AD_ST_ACP; 5645738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 5655738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* else we're inititator, start the L2CAP connection */ 5665738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project else 5675738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 5685738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_tbl->state = AVDT_AD_ST_CONN; 5695738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 5705738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* call l2cap connect req */ 5715738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if ((lcid = L2CA_ConnectReq(AVDT_PSM, p_ccb->peer_addr)) != 0) 5725738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 5735738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* if connect req ok, store tcid in lcid table */ 5745738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project avdt_cb.ad.lcid_tbl[lcid - L2CAP_BASE_APPL_CID] = avdt_ad_tc_tbl_to_idx(p_tbl); 5755738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project AVDT_TRACE_DEBUG2("avdt_cb.ad.lcid_tbl[%d] = %d", 5765738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project (lcid - L2CAP_BASE_APPL_CID), avdt_ad_tc_tbl_to_idx(p_tbl)); 5775738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 5785738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project avdt_cb.ad.rt_tbl[avdt_ccb_to_idx(p_ccb)][p_tbl->tcid].lcid = lcid; 5795738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project AVDT_TRACE_DEBUG3("avdt_cb.ad.rt_tbl[%d][%d].lcid = 0x%x", 5805738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project avdt_ccb_to_idx(p_ccb), p_tbl->tcid, 5815738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project lcid); 5825738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 5835738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project else 5845738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 5855738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* if connect req failed, call avdt_ad_tc_close_ind() */ 5865738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project avdt_ad_tc_close_ind(p_tbl, 0); 5875738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 5885738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 5895738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project} 5905738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 5915738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/******************************************************************************* 5925738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 5935738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function avdt_ad_close_req 5945738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 5955738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description This function is called by a CCB or SCB to close a 5965738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** transport channel. The function looks up the LCID for the 5975738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** channel and calls L2CA_DisconnectReq(). 5985738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 5995738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 6005738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns Nothing. 6015738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 6025738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/ 6035738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid avdt_ad_close_req(UINT8 type, tAVDT_CCB *p_ccb, tAVDT_SCB *p_scb) 6045738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 6055738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project UINT8 tcid; 6065738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project tAVDT_TC_TBL *p_tbl; 6075738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 6085738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_tbl = avdt_ad_tc_tbl_by_type(type, p_ccb, p_scb); 6095738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project AVDT_TRACE_DEBUG1("avdt_ad_close_req state: %d", p_tbl->state); 6105738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 6115738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project switch(p_tbl->state) 6125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 6135738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project case AVDT_AD_ST_UNUSED: 6145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* probably for reporting */ 6155738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project break; 6165738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project case AVDT_AD_ST_ACP: 6175738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* if we're listening on this channel, send ourselves a close ind */ 6185738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project avdt_ad_tc_close_ind(p_tbl, 0); 6195738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project break; 6205738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project default: 6215738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* get tcid from type, scb */ 6225738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project tcid = avdt_ad_type_to_tcid(type, p_scb); 6235738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 6245738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* call l2cap disconnect req */ 6255738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project L2CA_DisconnectReq(avdt_cb.ad.rt_tbl[avdt_ccb_to_idx(p_ccb)][tcid].lcid); 6265738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 6275738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project} 6285738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 629