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