Home | History | Annotate | Download | only in avdt
      1 /******************************************************************************
      2  *
      3  *  Copyright (C) 2002-2012 Broadcom Corporation
      4  *
      5  *  Licensed under the Apache License, Version 2.0 (the "License");
      6  *  you may not use this file except in compliance with the License.
      7  *  You may obtain a copy of the License at:
      8  *
      9  *  http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  *  Unless required by applicable law or agreed to in writing, software
     12  *  distributed under the License is distributed on an "AS IS" BASIS,
     13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  *  See the License for the specific language governing permissions and
     15  *  limitations under the License.
     16  *
     17  ******************************************************************************/
     18 
     19 /******************************************************************************
     20  *
     21  *  This module contains the stream control block and functions which
     22  *  operate on the stream control block.
     23  *
     24  ******************************************************************************/
     25 
     26 #include <string.h>
     27 #include "avdt_api.h"
     28 #include "avdt_int.h"
     29 #include "avdtc_api.h"
     30 #include "bt_common.h"
     31 #include "bt_target.h"
     32 #include "bt_types.h"
     33 #include "bt_utils.h"
     34 #include "btu.h"
     35 #include "osi/include/osi.h"
     36 
     37 /*****************************************************************************
     38  * state machine constants and types
     39  ****************************************************************************/
     40 #if (AVDT_DEBUG == TRUE)
     41 
     42 /* verbose state strings for trace */
     43 const char* const avdt_scb_st_str[] = {"SCB_IDLE_ST",    "SCB_CONF_ST",
     44                                        "SCB_OPENING_ST", "SCB_OPEN_ST",
     45                                        "SCB_STREAM_ST",  "SCB_CLOSING_ST"};
     46 
     47 /* verbose event strings for trace */
     48 const char* const avdt_scb_evt_str[] = {
     49     "API_REMOVE_EVT",        "API_WRITE_REQ_EVT",     "API_GETCONFIG_REQ_EVT",
     50     "API_DELAY_RPT_REQ",     "API_SETCONFIG_REQ_EVT", "API_OPEN_REQ_EVT",
     51     "API_CLOSE_REQ_EVT",     "API_RECONFIG_REQ_EVT",  "API_SECURITY_REQ_EVT",
     52     "API_ABORT_REQ_EVT",     "API_GETCONFIG_RSP_EVT", "API_SETCONFIG_RSP_EVT",
     53     "API_SETCONFIG_REJ_EVT", "API_OPEN_RSP_EVT",      "API_CLOSE_RSP_EVT",
     54     "API_RECONFIG_RSP_EVT",  "API_SECURITY_RSP_EVT",  "API_ABORT_RSP_EVT",
     55     "MSG_SETCONFIG_CMD_EVT", "MSG_GETCONFIG_CMD_EVT", "MSG_OPEN_CMD_EVT",
     56     "MSG_START_CMD_EVT",     "MSG_SUSPEND_CMD_EVT",   "MSG_CLOSE_CMD_EVT",
     57     "MSG_ABORT_CMD_EVT",     "MSG_RECONFIG_CMD_EVT",  "MSG_SECURITY_CMD_EVT",
     58     "MSG_DELAY_RPT_CMD_EVT", "MSG_DELAY_RPT_RSP_EVT", "MSG_SETCONFIG_RSP_EVT",
     59     "MSG_GETCONFIG_RSP_EVT", "MSG_OPEN_RSP_EVT",      "MSG_START_RSP_EVT",
     60     "MSG_SUSPEND_RSP_EVT",   "MSG_CLOSE_RSP_EVT",     "MSG_ABORT_RSP_EVT",
     61     "MSG_RECONFIG_RSP_EVT",  "MSG_SECURITY_RSP_EVT",  "MSG_SETCONFIG_REJ_EVT",
     62     "MSG_OPEN_REJ_EVT",      "MSG_START_REJ_EVT",     "MSG_SUSPEND_REJ_EVT",
     63     "TC_TOUT_EVT",           "TC_OPEN_EVT",           "TC_CLOSE_EVT",
     64     "TC_CONG_EVT",           "TC_DATA_EVT",           "CC_CLOSE_EVT"};
     65 
     66 #endif
     67 
     68 /* action function list */
     69 const tAVDT_SCB_ACTION avdt_scb_action[] = {avdt_scb_hdl_abort_cmd,
     70                                             avdt_scb_hdl_abort_rsp,
     71                                             avdt_scb_hdl_close_cmd,
     72                                             avdt_scb_hdl_close_rsp,
     73                                             avdt_scb_hdl_getconfig_cmd,
     74                                             avdt_scb_hdl_getconfig_rsp,
     75                                             avdt_scb_hdl_open_cmd,
     76                                             avdt_scb_hdl_open_rej,
     77                                             avdt_scb_hdl_open_rsp,
     78                                             avdt_scb_hdl_pkt,
     79                                             avdt_scb_drop_pkt,
     80                                             avdt_scb_hdl_reconfig_cmd,
     81                                             avdt_scb_hdl_reconfig_rsp,
     82                                             avdt_scb_hdl_security_cmd,
     83                                             avdt_scb_hdl_security_rsp,
     84                                             avdt_scb_hdl_setconfig_cmd,
     85                                             avdt_scb_hdl_setconfig_rej,
     86                                             avdt_scb_hdl_setconfig_rsp,
     87                                             avdt_scb_hdl_start_cmd,
     88                                             avdt_scb_hdl_start_rsp,
     89                                             avdt_scb_hdl_suspend_cmd,
     90                                             avdt_scb_hdl_suspend_rsp,
     91                                             avdt_scb_hdl_tc_close,
     92 #if (AVDT_REPORTING == TRUE)
     93                                             avdt_scb_hdl_tc_close_sto,
     94 #endif
     95                                             avdt_scb_hdl_tc_open,
     96 #if (AVDT_REPORTING == TRUE)
     97                                             avdt_scb_hdl_tc_open_sto,
     98 #endif
     99                                             avdt_scb_snd_delay_rpt_req,
    100                                             avdt_scb_hdl_delay_rpt_cmd,
    101                                             avdt_scb_hdl_delay_rpt_rsp,
    102                                             avdt_scb_hdl_write_req,
    103                                             avdt_scb_snd_abort_req,
    104                                             avdt_scb_snd_abort_rsp,
    105                                             avdt_scb_snd_close_req,
    106                                             avdt_scb_snd_stream_close,
    107                                             avdt_scb_snd_close_rsp,
    108                                             avdt_scb_snd_getconfig_req,
    109                                             avdt_scb_snd_getconfig_rsp,
    110                                             avdt_scb_snd_open_req,
    111                                             avdt_scb_snd_open_rsp,
    112                                             avdt_scb_snd_reconfig_req,
    113                                             avdt_scb_snd_reconfig_rsp,
    114                                             avdt_scb_snd_security_req,
    115                                             avdt_scb_snd_security_rsp,
    116                                             avdt_scb_snd_setconfig_req,
    117                                             avdt_scb_snd_setconfig_rej,
    118                                             avdt_scb_snd_setconfig_rsp,
    119                                             avdt_scb_snd_tc_close,
    120                                             avdt_scb_cb_err,
    121                                             avdt_scb_cong_state,
    122                                             avdt_scb_rej_state,
    123                                             avdt_scb_rej_in_use,
    124                                             avdt_scb_rej_not_in_use,
    125                                             avdt_scb_set_remove,
    126                                             avdt_scb_free_pkt,
    127                                             avdt_scb_clr_pkt,
    128                                             avdt_scb_chk_snd_pkt,
    129                                             avdt_scb_transport_channel_timer,
    130                                             avdt_scb_clr_vars,
    131                                             avdt_scb_dealloc};
    132 
    133 /* state table information */
    134 #define AVDT_SCB_ACTIONS 2    /* number of actions */
    135 #define AVDT_SCB_NEXT_STATE 2 /* position of next state */
    136 #define AVDT_SCB_NUM_COLS 3   /* number of columns in state tables */
    137 
    138 /* state table for idle state */
    139 const uint8_t avdt_scb_st_idle[][AVDT_SCB_NUM_COLS] = {
    140     /* Event */
    141     /* Action 1                       Action 2                    Next state */
    142     /* API_REMOVE_EVT */
    143     {AVDT_SCB_DEALLOC, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST},
    144     /* API_WRITE_REQ_EVT */
    145     {AVDT_SCB_FREE_PKT, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST},
    146     /* API_GETCONFIG_REQ_EVT */
    147     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST},
    148     /* API_DELAY_RPT_REQ_EVT */
    149     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST},
    150     /* API_SETCONFIG_REQ_EVT */
    151     {AVDT_SCB_SND_SETCONFIG_REQ, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST},
    152     /* API_OPEN_REQ_EVT */
    153     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST},
    154     /* API_CLOSE_REQ_EVT */
    155     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST},
    156     /* API_RECONFIG_REQ_EVT */
    157     {AVDT_SCB_CB_ERR, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST},
    158     /* API_SECURITY_REQ_EVT */
    159     {AVDT_SCB_CB_ERR, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST},
    160     /* API_ABORT_REQ_EVT */
    161     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST},
    162     /* API_GETCONFIG_RSP_EVT */
    163     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST},
    164     /* API_SETCONFIG_RSP_EVT */
    165     {AVDT_SCB_SND_SETCONFIG_RSP, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST},
    166     /* API_SETCONFIG_REJ_EVT */
    167     {AVDT_SCB_SND_SETCONFIG_REJ, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST},
    168     /* API_OPEN_RSP_EVT */
    169     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST},
    170     /* API_CLOSE_RSP_EVT */
    171     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST},
    172     /* API_RECONFIG_RSP_EVT */
    173     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST},
    174     /* API_SECURITY_RSP_EVT */
    175     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST},
    176     /* API_ABORT_RSP_EVT */
    177     {AVDT_SCB_SND_ABORT_RSP, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST},
    178     /* MSG_SETCONFIG_CMD_EVT */
    179     {AVDT_SCB_HDL_SETCONFIG_CMD, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST},
    180     /* MSG_GETCONFIG_CMD_EVT */
    181     {AVDT_SCB_REJ_STATE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST},
    182     /* MSG_OPEN_CMD_EVT */
    183     {AVDT_SCB_REJ_STATE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST},
    184     /* MSG_START_CMD_EVT */
    185     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST},
    186     /* MSG_SUSPEND_CMD_EVT */
    187     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST},
    188     /* MSG_CLOSE_CMD_EVT */
    189     {AVDT_SCB_REJ_STATE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST},
    190     /* MSG_ABORT_CMD_EVT */
    191     {AVDT_SCB_HDL_ABORT_CMD, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST},
    192     /* MSG_RECONFIG_CMD_EVT */
    193     {AVDT_SCB_REJ_NOT_IN_USE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST},
    194     /* MSG_SECURITY_CMD_EVT */
    195     {AVDT_SCB_REJ_STATE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST},
    196     /* MSG_DELAY_RPT_CMD_EVT */
    197     {AVDT_SCB_REJ_STATE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST},
    198     /* MSG_DELAY_RPT_RSP_EVT */
    199     {AVDT_SCB_HDL_DELAY_RPT_RSP, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST},
    200     /* MSG_SETCONFIG_RSP_EVT */
    201     {AVDT_SCB_HDL_SETCONFIG_RSP, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST},
    202     /* MSG_GETCONFIG_RSP_EVT */
    203     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST},
    204     /* MSG_OPEN_RSP_EVT */
    205     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST},
    206     /* MSG_START_RSP_EVT */
    207     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST},
    208     /* MSG_SUSPEND_RSP_EVT */
    209     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST},
    210     /* MSG_CLOSE_RSP_EVT */
    211     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST},
    212     /* MSG_ABORT_RSP_EVT */
    213     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST},
    214     /* MSG_RECONFIG_RSP_EVT */
    215     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST},
    216     /* MSG_SECURITY_RSP_EVT */
    217     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST},
    218     /* MSG_SETCONFIG_REJ_EVT */
    219     {AVDT_SCB_HDL_SETCONFIG_REJ, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST},
    220     /* MSG_OPEN_REJ_EVT */
    221     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST},
    222     /* MSG_START_REJ_EVT */
    223     {AVDT_SCB_HDL_START_RSP, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST},
    224     /* MSG_SUSPEND_REJ_EVT */
    225     {AVDT_SCB_HDL_SUSPEND_RSP, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST},
    226     /* TC_TOUT_EVT */
    227     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST},
    228     /* TC_OPEN_EVT */
    229     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST},
    230     /* TC_CLOSE_EVT */
    231     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST},
    232     /* TC_CONG_EVT */
    233     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST},
    234     /* TC_DATA_EVT */
    235     {AVDT_SCB_DROP_PKT, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST},
    236     /* CC_CLOSE_EVT */
    237     {AVDT_SCB_CLR_VARS, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}};
    238 
    239 /* state table for configured state */
    240 const uint8_t avdt_scb_st_conf[][AVDT_SCB_NUM_COLS] = {
    241     /* Event */
    242     /* Action 1                       Action 2                    Next state */
    243     /* API_REMOVE_EVT */
    244     {AVDT_SCB_SND_ABORT_REQ, AVDT_SCB_SET_REMOVE, AVDT_SCB_CONF_ST},
    245     /* API_WRITE_REQ_EVT */
    246     {AVDT_SCB_FREE_PKT, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST},
    247     /* API_GETCONFIG_REQ_EVT */
    248     {AVDT_SCB_SND_GETCONFIG_REQ, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST},
    249     /* API_DELAY_RPT_REQ_EVT */
    250     {AVDT_SCB_SND_DELAY_RPT_REQ, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST},
    251     /* API_SETCONFIG_REQ_EVT */
    252     {AVDT_SCB_CB_ERR, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST},
    253     /* API_OPEN_REQ_EVT */
    254     {AVDT_SCB_SND_OPEN_REQ, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST},
    255     /* API_CLOSE_REQ_EVT */
    256     {AVDT_SCB_SND_ABORT_REQ, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST},
    257     /* API_RECONFIG_REQ_EVT */
    258     {AVDT_SCB_CB_ERR, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST},
    259     /* API_SECURITY_REQ_EVT */
    260     {AVDT_SCB_SND_SECURITY_REQ, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST},
    261     /* API_ABORT_REQ_EVT */
    262     {AVDT_SCB_SND_ABORT_REQ, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST},
    263     /* API_GETCONFIG_RSP_EVT */
    264     {AVDT_SCB_SND_GETCONFIG_RSP, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST},
    265     /* API_SETCONFIG_RSP_EVT */
    266     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST},
    267     /* API_SETCONFIG_REJ_EVT */
    268     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST},
    269     /* API_OPEN_RSP_EVT */
    270     {AVDT_SCB_SND_OPEN_RSP, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST},
    271     /* API_CLOSE_RSP_EVT */
    272     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST},
    273     /* API_RECONFIG_RSP_EVT */
    274     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST},
    275     /* API_SECURITY_RSP_EVT */
    276     {AVDT_SCB_SND_SECURITY_RSP, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST},
    277     /* API_ABORT_RSP_EVT */
    278     {AVDT_SCB_SND_ABORT_RSP, AVDT_SCB_HDL_TC_CLOSE, AVDT_SCB_IDLE_ST},
    279     /* MSG_SETCONFIG_CMD_EVT */
    280     {AVDT_SCB_REJ_IN_USE, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST},
    281     /* MSG_GETCONFIG_CMD_EVT */
    282     {AVDT_SCB_HDL_GETCONFIG_CMD, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST},
    283     /* MSG_OPEN_CMD_EVT */
    284     {AVDT_SCB_HDL_OPEN_CMD, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST},
    285     /* MSG_START_CMD_EVT */
    286     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST},
    287     /* MSG_SUSPEND_CMD_EVT */
    288     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST},
    289     /* MSG_CLOSE_CMD_EVT */
    290     {AVDT_SCB_REJ_STATE, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST},
    291     /* MSG_ABORT_CMD_EVT */
    292     {AVDT_SCB_HDL_ABORT_CMD, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST},
    293     /* MSG_RECONFIG_CMD_EVT */
    294     {AVDT_SCB_REJ_STATE, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST},
    295     /* MSG_SECURITY_CMD_EVT */
    296     {AVDT_SCB_HDL_SECURITY_CMD, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST},
    297     /* MSG_DELAY_RPT_CMD_EVT */
    298     {AVDT_SCB_HDL_DELAY_RPT_CMD, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST},
    299     /* MSG_DELAY_RPT_RSP_EVT */
    300     {AVDT_SCB_HDL_DELAY_RPT_RSP, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST},
    301     /* MSG_SETCONFIG_RSP_EVT */
    302     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST},
    303     /* MSG_GETCONFIG_RSP_EVT */
    304     {AVDT_SCB_HDL_GETCONFIG_RSP, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST},
    305     /* MSG_OPEN_RSP_EVT */
    306     {AVDT_SCB_HDL_OPEN_RSP, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST},
    307     /* MSG_START_RSP_EVT */
    308     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST},
    309     /* MSG_SUSPEND_RSP_EVT */
    310     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST},
    311     /* MSG_CLOSE_RSP_EVT */
    312     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST},
    313     /* MSG_ABORT_RSP_EVT */
    314     {AVDT_SCB_HDL_ABORT_RSP, AVDT_SCB_HDL_TC_CLOSE, AVDT_SCB_IDLE_ST},
    315     /* MSG_RECONFIG_RSP_EVT */
    316     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST},
    317     /* MSG_SECURITY_RSP_EVT */
    318     {AVDT_SCB_HDL_SECURITY_RSP, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST},
    319     /* MSG_SETCONFIG_REJ_EVT */
    320     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST},
    321     /* MSG_OPEN_REJ_EVT */
    322     {AVDT_SCB_HDL_OPEN_REJ, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST},
    323     /* MSG_START_REJ_EVT */
    324     {AVDT_SCB_HDL_START_RSP, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST},
    325     /* MSG_SUSPEND_REJ_EVT */
    326     {AVDT_SCB_HDL_SUSPEND_RSP, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST},
    327     /* TC_TOUT_EVT */
    328     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST},
    329     /* TC_OPEN_EVT */
    330     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST},
    331     /* TC_CLOSE_EVT */
    332     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST},
    333     /* TC_CONG_EVT */
    334     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST},
    335     /* TC_DATA_EVT */
    336     {AVDT_SCB_DROP_PKT, AVDT_SCB_IGNORE, AVDT_SCB_CONF_ST},
    337     /* CC_CLOSE_EVT */
    338     {AVDT_SCB_HDL_TC_CLOSE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST}};
    339 
    340 /* state table for opening state */
    341 const uint8_t avdt_scb_st_opening[][AVDT_SCB_NUM_COLS] = {
    342     /* Event */
    343     /* Action 1                       Action 2                    Next state */
    344     /* API_REMOVE_EVT */
    345     {AVDT_SCB_SND_CLOSE_REQ, AVDT_SCB_SET_REMOVE, AVDT_SCB_CLOSING_ST},
    346     /* API_WRITE_REQ_EVT */
    347     {AVDT_SCB_FREE_PKT, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST},
    348     /* API_GETCONFIG_REQ_EVT */
    349     {AVDT_SCB_SND_GETCONFIG_REQ, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST},
    350     /* API_DELAY_RPT_REQ_EVT */
    351     {AVDT_SCB_SND_DELAY_RPT_REQ, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST},
    352     /* API_SETCONFIG_REQ_EVT */
    353     {AVDT_SCB_CB_ERR, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST},
    354     /* API_OPEN_REQ_EVT */
    355     {AVDT_SCB_CB_ERR, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST},
    356     /* API_CLOSE_REQ_EVT */
    357     {AVDT_SCB_SND_CLOSE_REQ, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST},
    358     /* API_RECONFIG_REQ_EVT */
    359     {AVDT_SCB_CB_ERR, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST},
    360     /* API_SECURITY_REQ_EVT */
    361     {AVDT_SCB_SND_SECURITY_REQ, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST},
    362     /* API_ABORT_REQ_EVT */
    363     {AVDT_SCB_SND_ABORT_REQ, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST},
    364     /* API_GETCONFIG_RSP_EVT */
    365     {AVDT_SCB_SND_GETCONFIG_RSP, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST},
    366     /* API_SETCONFIG_RSP_EVT */
    367     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST},
    368     /* API_SETCONFIG_REJ_EVT */
    369     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST},
    370     /* API_OPEN_RSP_EVT */
    371     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST},
    372     /* API_CLOSE_RSP_EVT */
    373     {AVDT_SCB_SND_CLOSE_RSP, AVDT_SCB_SND_TC_CLOSE, AVDT_SCB_CLOSING_ST},
    374     /* API_RECONFIG_RSP_EVT */
    375     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST},
    376     /* API_SECURITY_RSP_EVT */
    377     {AVDT_SCB_SND_SECURITY_RSP, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST},
    378     /* API_ABORT_RSP_EVT */
    379     {AVDT_SCB_SND_ABORT_RSP, AVDT_SCB_SND_TC_CLOSE, AVDT_SCB_CLOSING_ST},
    380     /* MSG_SETCONFIG_CMD_EVT */
    381     {AVDT_SCB_REJ_STATE, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST},
    382     /* MSG_GETCONFIG_CMD_EVT */
    383     {AVDT_SCB_HDL_GETCONFIG_CMD, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST},
    384     /* MSG_OPEN_CMD_EVT */
    385     {AVDT_SCB_REJ_STATE, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST},
    386     /* MSG_START_CMD_EVT */
    387     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST},
    388     /* MSG_SUSPEND_CMD_EVT */
    389     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST},
    390     /* MSG_CLOSE_CMD_EVT */
    391     {AVDT_SCB_HDL_CLOSE_CMD, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST},
    392     /* MSG_ABORT_CMD_EVT */
    393     {AVDT_SCB_HDL_ABORT_CMD, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST},
    394     /* MSG_RECONFIG_CMD_EVT */
    395     {AVDT_SCB_REJ_STATE, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST},
    396     /* MSG_SECURITY_CMD_EVT */
    397     {AVDT_SCB_HDL_SECURITY_CMD, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST},
    398     /* MSG_DELAY_RPT_CMD_EVT */
    399     {AVDT_SCB_HDL_DELAY_RPT_CMD, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST},
    400     /* MSG_DELAY_RPT_RSP_EVT */
    401     {AVDT_SCB_HDL_DELAY_RPT_RSP, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST},
    402     /* MSG_SETCONFIG_RSP_EVT */
    403     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST},
    404     /* MSG_GETCONFIG_RSP_EVT */
    405     {AVDT_SCB_HDL_GETCONFIG_RSP, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST},
    406     /* MSG_OPEN_RSP_EVT */
    407     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST},
    408     /* MSG_START_RSP_EVT */
    409     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST},
    410     /* MSG_SUSPEND_RSP_EVT */
    411     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST},
    412     /* MSG_CLOSE_RSP_EVT */
    413     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST},
    414     /* MSG_ABORT_RSP_EVT */
    415     {AVDT_SCB_SND_TC_CLOSE, AVDT_SCB_HDL_ABORT_RSP, AVDT_SCB_CLOSING_ST},
    416     /* MSG_RECONFIG_RSP_EVT */
    417     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST},
    418     /* MSG_SECURITY_RSP_EVT */
    419     {AVDT_SCB_HDL_SECURITY_RSP, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST},
    420     /* MSG_SETCONFIG_REJ_EVT */
    421     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST},
    422     /* MSG_OPEN_REJ_EVT */
    423     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST},
    424     /* MSG_START_REJ_EVT */
    425     {AVDT_SCB_HDL_START_RSP, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST},
    426     /* MSG_SUSPEND_REJ_EVT */
    427     {AVDT_SCB_HDL_SUSPEND_RSP, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST},
    428     /* TC_TOUT_EVT */
    429     {AVDT_SCB_SND_ABORT_REQ, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST},
    430     /* TC_OPEN_EVT */
    431     {AVDT_SCB_HDL_TC_OPEN, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST},
    432     /* TC_CLOSE_EVT */
    433     {AVDT_SCB_HDL_TC_CLOSE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST},
    434     /* TC_CONG_EVT */
    435     {AVDT_SCB_CONG_STATE, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST},
    436     /* TC_DATA_EVT */
    437     {AVDT_SCB_DROP_PKT, AVDT_SCB_IGNORE, AVDT_SCB_OPENING_ST},
    438     /* CC_CLOSE_EVT */
    439     {AVDT_SCB_SND_TC_CLOSE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}};
    440 
    441 /* state table for open state */
    442 const uint8_t avdt_scb_st_open[][AVDT_SCB_NUM_COLS] = {
    443     /* Event */
    444     /* Action 1                       Action 2                    Next state */
    445     /* API_REMOVE_EVT */
    446     {AVDT_SCB_SND_CLOSE_REQ, AVDT_SCB_SET_REMOVE, AVDT_SCB_CLOSING_ST},
    447     /* API_WRITE_REQ_EVT */
    448     {AVDT_SCB_FREE_PKT, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST},
    449     /* API_GETCONFIG_REQ_EVT */
    450     {AVDT_SCB_SND_GETCONFIG_REQ, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST},
    451     /* API_DELAY_RPT_REQ_EVT */
    452     {AVDT_SCB_SND_DELAY_RPT_REQ, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST},
    453     /* API_SETCONFIG_REQ_EVT */
    454     {AVDT_SCB_CB_ERR, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST},
    455     /* API_OPEN_REQ_EVT */
    456     {AVDT_SCB_CB_ERR, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST},
    457     /* API_CLOSE_REQ_EVT */
    458     {AVDT_SCB_SND_CLOSE_REQ, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST},
    459     /* API_RECONFIG_REQ_EVT */
    460     {AVDT_SCB_SND_RECONFIG_REQ, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST},
    461     /* API_SECURITY_REQ_EVT */
    462     {AVDT_SCB_SND_SECURITY_REQ, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST},
    463     /* API_ABORT_REQ_EVT */
    464     {AVDT_SCB_SND_ABORT_REQ, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST},
    465     /* API_GETCONFIG_RSP_EVT */
    466     {AVDT_SCB_SND_GETCONFIG_RSP, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST},
    467     /* API_SETCONFIG_RSP_EVT */
    468     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST},
    469     /* API_SETCONFIG_REJ_EVT */
    470     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST},
    471     /* API_OPEN_RSP_EVT */
    472     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST},
    473     /* API_CLOSE_RSP_EVT */
    474     {AVDT_SCB_SND_CLOSE_RSP, AVDT_SCB_TC_TIMER, AVDT_SCB_CLOSING_ST},
    475     /* API_RECONFIG_RSP_EVT */
    476     {AVDT_SCB_SND_RECONFIG_RSP, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST},
    477     /* API_SECURITY_RSP_EVT */
    478     {AVDT_SCB_SND_SECURITY_RSP, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST},
    479     /* API_ABORT_RSP_EVT */
    480     {AVDT_SCB_SND_ABORT_RSP, AVDT_SCB_TC_TIMER, AVDT_SCB_CLOSING_ST},
    481     /* MSG_SETCONFIG_CMD_EVT */
    482     {AVDT_SCB_REJ_STATE, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST},
    483     /* MSG_GETCONFIG_CMD_EVT */
    484     {AVDT_SCB_HDL_GETCONFIG_CMD, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST},
    485     /* MSG_OPEN_CMD_EVT */
    486     {AVDT_SCB_REJ_STATE, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST},
    487     /* MSG_START_CMD_EVT */
    488     {AVDT_SCB_HDL_START_CMD, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST},
    489     /* MSG_SUSPEND_CMD_EVT */
    490     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST},
    491     /* MSG_CLOSE_CMD_EVT */
    492     {AVDT_SCB_HDL_CLOSE_CMD, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST},
    493     /* MSG_ABORT_CMD_EVT */
    494     {AVDT_SCB_HDL_ABORT_CMD, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST},
    495     /* MSG_RECONFIG_CMD_EVT */
    496     {AVDT_SCB_HDL_RECONFIG_CMD, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST},
    497     /* MSG_SECURITY_CMD_EVT */
    498     {AVDT_SCB_HDL_SECURITY_CMD, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST},
    499     /* MSG_DELAY_RPT_CMD_EVT */
    500     {AVDT_SCB_HDL_DELAY_RPT_CMD, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST},
    501     /* MSG_DELAY_RPT_RSP_EVT */
    502     {AVDT_SCB_HDL_DELAY_RPT_RSP, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST},
    503     /* MSG_SETCONFIG_RSP_EVT */
    504     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST},
    505     /* MSG_GETCONFIG_RSP_EVT */
    506     {AVDT_SCB_HDL_GETCONFIG_RSP, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST},
    507     /* MSG_OPEN_RSP_EVT */
    508     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST},
    509     /* MSG_START_RSP_EVT */
    510     {AVDT_SCB_HDL_START_RSP, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST},
    511     /* MSG_SUSPEND_RSP_EVT */
    512     {AVDT_SCB_HDL_SUSPEND_RSP, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST},
    513     /* MSG_CLOSE_RSP_EVT */
    514     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST},
    515     /* MSG_ABORT_RSP_EVT */
    516     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST},
    517     /* MSG_RECONFIG_RSP_EVT */
    518     {AVDT_SCB_HDL_RECONFIG_RSP, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST},
    519     /* MSG_SECURITY_RSP_EVT */
    520     {AVDT_SCB_HDL_SECURITY_RSP, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST},
    521     /* MSG_SETCONFIG_REJ_EVT */
    522     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST},
    523     /* MSG_OPEN_REJ_EVT */
    524     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST},
    525     /* MSG_START_REJ_EVT */
    526     {AVDT_SCB_HDL_START_RSP, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST},
    527     /* MSG_SUSPEND_REJ_EVT */
    528     {AVDT_SCB_HDL_SUSPEND_RSP, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST},
    529     /* TC_TOUT_EVT */
    530     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST},
    531 #if (AVDT_REPORTING == TRUE)
    532     /* TC_OPEN_EVT */
    533     {AVDT_SCB_HDL_TC_OPEN_STO, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST},
    534     /* TC_CLOSE_EVT */
    535     {AVDT_SCB_HDL_TC_CLOSE_STO, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST},
    536 #else
    537     /* TC_OPEN_EVT */
    538     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST},
    539     /* TC_CLOSE_EVT */
    540     {AVDT_SCB_HDL_TC_CLOSE, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST},
    541 #endif
    542     /* TC_CONG_EVT */
    543     {AVDT_SCB_CONG_STATE, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST},
    544     /* TC_DATA_EVT */
    545     {AVDT_SCB_DROP_PKT, AVDT_SCB_IGNORE, AVDT_SCB_OPEN_ST},
    546     /* CC_CLOSE_EVT */
    547     {AVDT_SCB_SND_TC_CLOSE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}};
    548 
    549 /* state table for streaming state */
    550 const uint8_t avdt_scb_st_stream[][AVDT_SCB_NUM_COLS] = {
    551     /* Event */
    552     /* Action 1                       Action 2                    Next state */
    553     /* API_REMOVE_EVT */
    554     {AVDT_SCB_SND_STREAM_CLOSE, AVDT_SCB_SET_REMOVE, AVDT_SCB_CLOSING_ST},
    555     /* API_WRITE_REQ_EVT */
    556     {AVDT_SCB_HDL_WRITE_REQ, AVDT_SCB_CHK_SND_PKT, AVDT_SCB_STREAM_ST},
    557     /* API_GETCONFIG_REQ_EVT */
    558     {AVDT_SCB_SND_GETCONFIG_REQ, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST},
    559     /* API_DELAY_RPT_REQ_EVT */
    560     {AVDT_SCB_SND_DELAY_RPT_REQ, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST},
    561     /* API_SETCONFIG_REQ_EVT */
    562     {AVDT_SCB_CB_ERR, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST},
    563     /* API_OPEN_REQ_EVT */
    564     {AVDT_SCB_CB_ERR, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST},
    565     /* API_CLOSE_REQ_EVT */
    566     {AVDT_SCB_SND_STREAM_CLOSE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST},
    567     /* API_RECONFIG_REQ_EVT */
    568     {AVDT_SCB_CB_ERR, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST},
    569     /* API_SECURITY_REQ_EVT */
    570     {AVDT_SCB_SND_SECURITY_REQ, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST},
    571     /* API_ABORT_REQ_EVT */
    572     {AVDT_SCB_SND_ABORT_REQ, AVDT_SCB_CLR_PKT, AVDT_SCB_CLOSING_ST},
    573     /* API_GETCONFIG_RSP_EVT */
    574     {AVDT_SCB_SND_GETCONFIG_RSP, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST},
    575     /* API_SETCONFIG_RSP_EVT */
    576     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST},
    577     /* API_SETCONFIG_REJ_EVT */
    578     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST},
    579     /* API_OPEN_RSP_EVT */
    580     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST},
    581     /* API_CLOSE_RSP_EVT */
    582     {AVDT_SCB_SND_CLOSE_RSP, AVDT_SCB_TC_TIMER, AVDT_SCB_CLOSING_ST},
    583     /* API_RECONFIG_RSP_EVT */
    584     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST},
    585     /* API_SECURITY_RSP_EVT */
    586     {AVDT_SCB_SND_SECURITY_RSP, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST},
    587     /* API_ABORT_RSP_EVT */
    588     {AVDT_SCB_SND_ABORT_RSP, AVDT_SCB_TC_TIMER, AVDT_SCB_CLOSING_ST},
    589     /* MSG_SETCONFIG_CMD_EVT */
    590     {AVDT_SCB_REJ_STATE, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST},
    591     /* MSG_GETCONFIG_CMD_EVT */
    592     {AVDT_SCB_HDL_GETCONFIG_CMD, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST},
    593     /* MSG_OPEN_CMD_EVT */
    594     {AVDT_SCB_REJ_STATE, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST},
    595     /* MSG_START_CMD_EVT */
    596     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST},
    597     /* MSG_SUSPEND_CMD_EVT */
    598     {AVDT_SCB_HDL_SUSPEND_CMD, AVDT_SCB_CLR_PKT, AVDT_SCB_OPEN_ST},
    599     /* MSG_CLOSE_CMD_EVT */
    600     {AVDT_SCB_HDL_CLOSE_CMD, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST},
    601     /* MSG_ABORT_CMD_EVT */
    602     {AVDT_SCB_HDL_ABORT_CMD, AVDT_SCB_CLR_PKT, AVDT_SCB_STREAM_ST},
    603     /* MSG_RECONFIG_CMD_EVT */
    604     {AVDT_SCB_REJ_STATE, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST},
    605     /* MSG_SECURITY_CMD_EVT */
    606     {AVDT_SCB_HDL_SECURITY_CMD, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST},
    607     /* MSG_DELAY_RPT_CMD_EVT */
    608     {AVDT_SCB_HDL_DELAY_RPT_CMD, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST},
    609     /* MSG_DELAY_RPT_RSP_EVT */
    610     {AVDT_SCB_HDL_DELAY_RPT_RSP, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST},
    611     /* MSG_SETCONFIG_RSP_EVT */
    612     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST},
    613     /* MSG_GETCONFIG_RSP_EVT */
    614     {AVDT_SCB_HDL_GETCONFIG_RSP, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST},
    615     /* MSG_OPEN_RSP_EVT */
    616     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST},
    617     /* MSG_START_RSP_EVT */
    618     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST},
    619     /* MSG_SUSPEND_RSP_EVT */
    620     {AVDT_SCB_HDL_SUSPEND_RSP, AVDT_SCB_CLR_PKT, AVDT_SCB_OPEN_ST},
    621     /* MSG_CLOSE_RSP_EVT */
    622     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST},
    623     /* MSG_ABORT_RSP_EVT */
    624     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST},
    625     /* MSG_RECONFIG_RSP_EVT */
    626     {AVDT_SCB_HDL_RECONFIG_RSP, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST},
    627     /* MSG_SECURITY_RSP_EVT */
    628     {AVDT_SCB_HDL_SECURITY_RSP, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST},
    629     /* MSG_SETCONFIG_REJ_EVT */
    630     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST},
    631     /* MSG_OPEN_REJ_EVT */
    632     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST},
    633     /* MSG_START_REJ_EVT */
    634     {AVDT_SCB_HDL_START_RSP, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST},
    635     /* MSG_SUSPEND_REJ_EVT */
    636     {AVDT_SCB_HDL_SUSPEND_RSP, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST},
    637     /* TC_TOUT_EVT */
    638     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST},
    639     /* TC_OPEN_EVT */
    640     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST},
    641     /* TC_CLOSE_EVT */
    642     {AVDT_SCB_HDL_TC_CLOSE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST},
    643     /* TC_CONG_EVT */
    644     {AVDT_SCB_CONG_STATE, AVDT_SCB_CHK_SND_PKT, AVDT_SCB_STREAM_ST},
    645     /* TC_DATA_EVT */
    646     {AVDT_SCB_HDL_PKT, AVDT_SCB_IGNORE, AVDT_SCB_STREAM_ST},
    647     /* CC_CLOSE_EVT */
    648     {AVDT_SCB_SND_TC_CLOSE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}};
    649 
    650 /* state table for closing state */
    651 const uint8_t avdt_scb_st_closing[][AVDT_SCB_NUM_COLS] = {
    652     /* Event */
    653     /* Action 1                       Action 2                    Next state */
    654     /* API_REMOVE_EVT */
    655     {AVDT_SCB_SET_REMOVE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST},
    656     /* API_WRITE_REQ_EVT */
    657     {AVDT_SCB_FREE_PKT, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST},
    658     /* API_GETCONFIG_REQ_EVT */
    659     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST},
    660     /* API_DELAY_RPT_REQ_EVT */
    661     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST},
    662     /* API_SETCONFIG_REQ_EVT */
    663     {AVDT_SCB_CB_ERR, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST},
    664     /* API_OPEN_REQ_EVT */
    665     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST},
    666     /* API_CLOSE_REQ_EVT */
    667     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST},
    668     /* API_RECONFIG_REQ_EVT */
    669     {AVDT_SCB_CB_ERR, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST},
    670     /* API_SECURITY_REQ_EVT */
    671     {AVDT_SCB_CB_ERR, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST},
    672     /* API_ABORT_REQ_EVT */
    673     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST},
    674     /* API_GETCONFIG_RSP_EVT */
    675     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST},
    676     /* API_SETCONFIG_RSP_EVT */
    677     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST},
    678     /* API_SETCONFIG_REJ_EVT */
    679     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST},
    680     /* API_OPEN_RSP_EVT */
    681     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST},
    682     /* API_CLOSE_RSP_EVT */
    683     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST},
    684     /* API_RECONFIG_RSP_EVT */
    685     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST},
    686     /* API_SECURITY_RSP_EVT */
    687     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST},
    688     /* API_ABORT_RSP_EVT */
    689     {AVDT_SCB_SND_ABORT_RSP, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST},
    690     /* MSG_SETCONFIG_CMD_EVT */
    691     {AVDT_SCB_REJ_STATE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST},
    692     /* MSG_GETCONFIG_CMD_EVT */
    693     {AVDT_SCB_REJ_STATE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST},
    694     /* MSG_OPEN_CMD_EVT */
    695     {AVDT_SCB_REJ_STATE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST},
    696     /* MSG_START_CMD_EVT */
    697     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST},
    698     /* MSG_SUSPEND_CMD_EVT */
    699     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST},
    700     /* MSG_CLOSE_CMD_EVT */
    701     {AVDT_SCB_REJ_STATE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST},
    702     /* MSG_ABORT_CMD_EVT */
    703     {AVDT_SCB_HDL_ABORT_CMD, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST},
    704     /* MSG_RECONFIG_CMD_EVT */
    705     {AVDT_SCB_REJ_STATE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST},
    706     /* MSG_SECURITY_CMD_EVT */
    707     {AVDT_SCB_REJ_STATE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST},
    708     /* MSG_DELAY_RPT_CMD_EVT */
    709     {AVDT_SCB_REJ_STATE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST},
    710     /* MSG_DELAY_RPT_RSP_EVT */
    711     {AVDT_SCB_HDL_DELAY_RPT_RSP, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST},
    712     /* MSG_SETCONFIG_RSP_EVT */
    713     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST},
    714     /* MSG_GETCONFIG_RSP_EVT */
    715     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST},
    716     /* MSG_OPEN_RSP_EVT */
    717     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST},
    718     /* MSG_START_RSP_EVT */
    719     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST},
    720     /* MSG_SUSPEND_RSP_EVT */
    721     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST},
    722     /* MSG_CLOSE_RSP_EVT */
    723     {AVDT_SCB_SND_TC_CLOSE, AVDT_SCB_HDL_CLOSE_RSP, AVDT_SCB_CLOSING_ST},
    724     /* MSG_ABORT_RSP_EVT */
    725     {AVDT_SCB_SND_TC_CLOSE, AVDT_SCB_HDL_ABORT_RSP, AVDT_SCB_CLOSING_ST},
    726     /* MSG_RECONFIG_RSP_EVT */
    727     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST},
    728     /* MSG_SECURITY_RSP_EVT */
    729     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST},
    730     /* MSG_SETCONFIG_REJ_EVT */
    731     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST},
    732     /* MSG_OPEN_REJ_EVT */
    733     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST},
    734     /* MSG_START_REJ_EVT */
    735     {AVDT_SCB_HDL_START_RSP, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST},
    736     /* MSG_SUSPEND_REJ_EVT */
    737     {AVDT_SCB_HDL_SUSPEND_RSP, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST},
    738     /* TC_TOUT_EVT */
    739     {AVDT_SCB_SND_TC_CLOSE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST},
    740     /* TC_OPEN_EVT */
    741     {AVDT_SCB_SND_TC_CLOSE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST},
    742     /* TC_CLOSE_EVT */
    743     {AVDT_SCB_HDL_TC_CLOSE, AVDT_SCB_IGNORE, AVDT_SCB_IDLE_ST},
    744     /* TC_CONG_EVT */
    745     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST},
    746     /* TC_DATA_EVT */
    747     {AVDT_SCB_DROP_PKT, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST},
    748     /* CC_CLOSE_EVT */
    749     {AVDT_SCB_IGNORE, AVDT_SCB_IGNORE, AVDT_SCB_CLOSING_ST}};
    750 
    751 /* type for state table */
    752 typedef const uint8_t (*tAVDT_SCB_ST_TBL)[AVDT_SCB_NUM_COLS];
    753 
    754 /* state table */
    755 const tAVDT_SCB_ST_TBL avdt_scb_st_tbl[] = {
    756     avdt_scb_st_idle, avdt_scb_st_conf,   avdt_scb_st_opening,
    757     avdt_scb_st_open, avdt_scb_st_stream, avdt_scb_st_closing};
    758 
    759 /*******************************************************************************
    760  *
    761  * Function         avdt_scb_event
    762  *
    763  * Description      State machine event handling function for scb
    764  *
    765  *
    766  * Returns          Nothing.
    767  *
    768  ******************************************************************************/
    769 void avdt_scb_event(tAVDT_SCB* p_scb, uint8_t event, tAVDT_SCB_EVT* p_data) {
    770   tAVDT_SCB_ST_TBL state_table;
    771   uint8_t action;
    772   int i;
    773 
    774 #if (AVDT_DEBUG == TRUE)
    775   AVDT_TRACE_EVENT("%s: SCB hdl=%d event=%d/%s state=%s", __func__,
    776                    avdt_scb_to_hdl(p_scb), event, avdt_scb_evt_str[event],
    777                    avdt_scb_st_str[p_scb->state]);
    778 #endif
    779   /* set current event */
    780   p_scb->curr_evt = event;
    781 
    782   /* look up the state table for the current state */
    783   state_table = avdt_scb_st_tbl[p_scb->state];
    784 
    785   /* set next state */
    786   if (p_scb->state != state_table[event][AVDT_SCB_NEXT_STATE]) {
    787     p_scb->state = state_table[event][AVDT_SCB_NEXT_STATE];
    788   }
    789 
    790   /* execute action functions */
    791   for (i = 0; i < AVDT_SCB_ACTIONS; i++) {
    792     action = state_table[event][i];
    793     if (action != AVDT_SCB_IGNORE) {
    794       (*avdt_cb.p_scb_act[action])(p_scb, p_data);
    795     } else {
    796       break;
    797     }
    798   }
    799 }
    800 
    801 /*******************************************************************************
    802  *
    803  * Function         avdt_scb_init
    804  *
    805  * Description      Initialize stream control block module.
    806  *
    807  *
    808  * Returns          Nothing.
    809  *
    810  ******************************************************************************/
    811 void avdt_scb_init(void) {
    812   memset(&avdt_cb.scb[0], 0, sizeof(tAVDT_SCB) * AVDT_NUM_SEPS);
    813   avdt_cb.p_scb_act = (tAVDT_SCB_ACTION*)avdt_scb_action;
    814 }
    815 
    816 /*******************************************************************************
    817  *
    818  * Function         avdt_scb_alloc
    819  *
    820  * Description      Allocate a stream control block.
    821  *
    822  *
    823  * Returns          pointer to the scb, or NULL if none could be allocated.
    824  *
    825  ******************************************************************************/
    826 tAVDT_SCB* avdt_scb_alloc(tAVDT_CS* p_cs) {
    827   tAVDT_SCB* p_scb = &avdt_cb.scb[0];
    828   int i;
    829 
    830   /* find available scb */
    831   for (i = 0; i < AVDT_NUM_SEPS; i++, p_scb++) {
    832     if (!p_scb->allocated) {
    833       memset(p_scb, 0, sizeof(tAVDT_SCB));
    834       p_scb->allocated = true;
    835       p_scb->p_ccb = NULL;
    836 
    837       memcpy(&p_scb->cs, p_cs, sizeof(tAVDT_CS));
    838       p_scb->transport_channel_timer =
    839           alarm_new("avdt_scb.transport_channel_timer");
    840       AVDT_TRACE_DEBUG("%s: hdl=%d, psc_mask:0x%x", __func__, i + 1,
    841                        p_cs->cfg.psc_mask);
    842       break;
    843     }
    844   }
    845 
    846   if (i == AVDT_NUM_SEPS) {
    847     /* out of ccbs */
    848     p_scb = NULL;
    849     AVDT_TRACE_WARNING("Out of scbs");
    850   }
    851 
    852   return p_scb;
    853 }
    854 
    855 /*******************************************************************************
    856  *
    857  * Function         avdt_scb_dealloc
    858  *
    859  * Description      Deallocate a stream control block.
    860  *
    861  *
    862  * Returns          void.
    863  *
    864  ******************************************************************************/
    865 void avdt_scb_dealloc(tAVDT_SCB* p_scb, UNUSED_ATTR tAVDT_SCB_EVT* p_data) {
    866   AVDT_TRACE_DEBUG("%s: hdl=%d", __func__, avdt_scb_to_hdl(p_scb));
    867   alarm_free(p_scb->transport_channel_timer);
    868   memset(p_scb, 0, sizeof(tAVDT_SCB));
    869 }
    870 
    871 /*******************************************************************************
    872  *
    873  * Function         avdt_scb_to_hdl
    874  *
    875  * Description      Given a pointer to an scb, return its handle (or seid).
    876  *
    877  *
    878  * Returns          Index of scb.
    879  *
    880  ******************************************************************************/
    881 uint8_t avdt_scb_to_hdl(tAVDT_SCB* p_scb) {
    882   return (uint8_t)(p_scb - avdt_cb.scb + 1);
    883 }
    884 
    885 /*******************************************************************************
    886  *
    887  * Function         avdt_scb_by_hdl
    888  *
    889  * Description      Given an scb handle (or seid), return a pointer to the scb.
    890  *
    891  *
    892  * Returns          Pointer to scb or NULL if index is out of range or scb
    893  *                  is not allocated.
    894  *
    895  ******************************************************************************/
    896 tAVDT_SCB* avdt_scb_by_hdl(uint8_t hdl) {
    897   tAVDT_SCB* p_scb;
    898 
    899   /* verify index */
    900   if ((hdl > 0) && (hdl <= AVDT_NUM_SEPS)) {
    901     p_scb = &avdt_cb.scb[hdl - 1];
    902 
    903     /* verify scb is allocated */
    904     if (!p_scb->allocated) {
    905       p_scb = NULL;
    906       AVDT_TRACE_WARNING("scb hdl %d not allocated", hdl);
    907     }
    908   } else {
    909     p_scb = NULL;
    910     AVDT_TRACE_WARNING("scb hdl %d out of range", hdl);
    911   }
    912   return p_scb;
    913 }
    914 
    915 /*******************************************************************************
    916  *
    917  * Function         avdt_scb_verify
    918  *
    919  * Description      Verify the condition of a list of scbs.
    920  *
    921  *
    922  * Returns          SEID that failed, or 0 if success.
    923  *
    924  ******************************************************************************/
    925 uint8_t avdt_scb_verify(tAVDT_CCB* p_ccb, uint8_t state, uint8_t* p_seid,
    926                         uint16_t num_seid, uint8_t* p_err_code) {
    927   int i;
    928   tAVDT_SCB* p_scb;
    929   uint8_t nsc_mask;
    930   uint8_t ret = 0;
    931 
    932   AVDT_TRACE_DEBUG("avdt_scb_verify state %d", state);
    933   /* set nonsupported command mask */
    934   /* translate public state into private state */
    935   nsc_mask = 0;
    936   if (state == AVDT_VERIFY_SUSPEND) nsc_mask = AVDT_NSC_SUSPEND;
    937 
    938   /* verify every scb */
    939   for (i = 0, *p_err_code = 0;
    940        (i < num_seid) && (*p_err_code == 0) && (i < AVDT_NUM_SEPS); i++) {
    941     p_scb = avdt_scb_by_hdl(p_seid[i]);
    942     if (p_scb == NULL)
    943       *p_err_code = AVDT_ERR_BAD_STATE;
    944     else if (p_scb->p_ccb != p_ccb)
    945       *p_err_code = AVDT_ERR_BAD_STATE;
    946     else if (p_scb->cs.nsc_mask & nsc_mask)
    947       *p_err_code = AVDT_ERR_NSC;
    948 
    949     switch (state) {
    950       case AVDT_VERIFY_OPEN:
    951       case AVDT_VERIFY_START:
    952         if (p_scb->state != AVDT_SCB_OPEN_ST &&
    953             p_scb->state != AVDT_SCB_STREAM_ST)
    954           *p_err_code = AVDT_ERR_BAD_STATE;
    955         break;
    956 
    957       case AVDT_VERIFY_SUSPEND:
    958       case AVDT_VERIFY_STREAMING:
    959         if (p_scb->state != AVDT_SCB_STREAM_ST)
    960           *p_err_code = AVDT_ERR_BAD_STATE;
    961         break;
    962     }
    963   }
    964 
    965   if ((i != num_seid) && (i < AVDT_NUM_SEPS)) {
    966     ret = p_seid[i];
    967   }
    968 
    969   return ret;
    970 }
    971 
    972 /*******************************************************************************
    973  *
    974  * Function         avdt_scb_peer_seid_list
    975  *
    976  * Description      Given a list of SCB handles, return a list of peer SEIDs
    977  *                  for the handles, copied in place into the struct passed in.
    978  *
    979  *
    980  * Returns          Nothing.
    981  *
    982  ******************************************************************************/
    983 void avdt_scb_peer_seid_list(tAVDT_MULTI* p_multi) {
    984   int i;
    985   tAVDT_SCB* p_scb;
    986 
    987   for (i = 0; i < p_multi->num_seps; i++) {
    988     p_scb = avdt_scb_by_hdl(p_multi->seid_list[i]);
    989     if (p_scb != NULL) {
    990       p_multi->seid_list[i] = p_scb->peer_seid;
    991     }
    992   }
    993 }
    994