blob: 6c384e0a03582fe06ba2eca2054486876e61548e [file] [log] [blame]
The Android Open Source Project5738f832012-12-12 16:00:35 -08001/******************************************************************************
2 *
Jakub Pawlowski5b790fe2017-09-18 09:00:20 -07003 * Copyright 2004-2012 Broadcom Corporation
The Android Open Source Project5738f832012-12-12 16:00:35 -08004 *
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 is the stream state machine for the BTA advanced audio/video.
22 *
23 ******************************************************************************/
Myles Watsonf355ef52016-11-09 13:04:33 -080024#include <string.h>
The Android Open Source Project5738f832012-12-12 16:00:35 -080025
26#include "bt_target.h"
The Android Open Source Project5738f832012-12-12 16:00:35 -080027#include "bta_av_co.h"
28#include "bta_av_int.h"
29
30/*****************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -080031 * Constants and types
32 ****************************************************************************/
The Android Open Source Project5738f832012-12-12 16:00:35 -080033
34/* state machine states */
Myles Watsoncd1fd072016-11-09 13:17:43 -080035enum {
36 BTA_AV_INIT_SST,
37 BTA_AV_INCOMING_SST,
38 BTA_AV_OPENING_SST,
39 BTA_AV_OPEN_SST,
40 BTA_AV_RCFG_SST,
41 BTA_AV_CLOSING_SST
The Android Open Source Project5738f832012-12-12 16:00:35 -080042};
43
The Android Open Source Project5738f832012-12-12 16:00:35 -080044/* state machine action enumeration list */
Myles Watsoncd1fd072016-11-09 13:17:43 -080045enum {
46 BTA_AV_DO_DISC,
47 BTA_AV_CLEANUP,
48 BTA_AV_FREE_SDB,
49 BTA_AV_CONFIG_IND,
50 BTA_AV_DISCONNECT_REQ,
51 BTA_AV_SECURITY_REQ,
52 BTA_AV_SECURITY_RSP,
53 BTA_AV_SETCONFIG_RSP,
54 BTA_AV_ST_RC_TIMER,
55 BTA_AV_STR_OPENED,
56 BTA_AV_SECURITY_IND,
57 BTA_AV_SECURITY_CFM,
58 BTA_AV_DO_CLOSE,
59 BTA_AV_CONNECT_REQ,
60 BTA_AV_SDP_FAILED,
61 BTA_AV_DISC_RESULTS,
62 BTA_AV_DISC_RES_AS_ACP,
63 BTA_AV_OPEN_FAILED,
64 BTA_AV_GETCAP_RESULTS,
65 BTA_AV_SETCONFIG_REJ,
66 BTA_AV_DISCOVER_REQ,
67 BTA_AV_CONN_FAILED,
68 BTA_AV_DO_START,
69 BTA_AV_STR_STOPPED,
70 BTA_AV_RECONFIG,
71 BTA_AV_DATA_PATH,
72 BTA_AV_START_OK,
73 BTA_AV_START_FAILED,
74 BTA_AV_STR_CLOSED,
75 BTA_AV_CLR_CONG,
76 BTA_AV_SUSPEND_CFM,
77 BTA_AV_RCFG_STR_OK,
78 BTA_AV_RCFG_FAILED,
79 BTA_AV_RCFG_CONNECT,
80 BTA_AV_RCFG_DISCNTD,
81 BTA_AV_SUSPEND_CONT,
82 BTA_AV_RCFG_CFM,
83 BTA_AV_RCFG_OPEN,
84 BTA_AV_SECURITY_REJ,
85 BTA_AV_OPEN_RC,
86 BTA_AV_CHK_2ND_START,
87 BTA_AV_SAVE_CAPS,
88 BTA_AV_SET_USE_RC,
89 BTA_AV_CCO_CLOSE,
90 BTA_AV_SWITCH_ROLE,
91 BTA_AV_ROLE_RES,
92 BTA_AV_DELAY_CO,
93 BTA_AV_OPEN_AT_INC,
94 BTA_AV_OFFLOAD_REQ,
95 BTA_AV_OFFLOAD_RSP,
96 BTA_AV_NUM_SACTIONS
The Android Open Source Project5738f832012-12-12 16:00:35 -080097};
98
Myles Watsoncd1fd072016-11-09 13:17:43 -080099#define BTA_AV_SIGNORE BTA_AV_NUM_SACTIONS
The Android Open Source Project5738f832012-12-12 16:00:35 -0800100
101/* state table information */
102/* #define BTA_AV_SACTION_COL 0 position of actions */
Myles Watsoncd1fd072016-11-09 13:17:43 -0800103#define BTA_AV_SACTIONS 2 /* number of actions */
104#define BTA_AV_SNEXT_STATE 2 /* position of next state */
105#define BTA_AV_NUM_COLS 3 /* number of columns in state tables */
The Android Open Source Project5738f832012-12-12 16:00:35 -0800106
107/* state table for init state */
Myles Watsoncd1fd072016-11-09 13:17:43 -0800108static const uint8_t bta_av_sst_init[][BTA_AV_NUM_COLS] = {
109 /* Event Action 1 Action 2 Next state */
Pavlin Radoslavovd7522292017-11-24 19:12:11 -0800110 /* API_OPEN_EVT */ {BTA_AV_DO_DISC, BTA_AV_SIGNORE, BTA_AV_OPENING_SST},
111 /* API_CLOSE_EVT */ {BTA_AV_CLEANUP, BTA_AV_SIGNORE, BTA_AV_INIT_SST},
Myles Watsoncd1fd072016-11-09 13:17:43 -0800112 /* AP_START_EVT */ {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_INIT_SST},
113 /* AP_STOP_EVT */ {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_INIT_SST},
114 /* API_RECONFIG_EVT */ {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_INIT_SST},
115 /* API_PROTECT_REQ_EVT */ {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_INIT_SST},
116 /* API_PROTECT_RSP_EVT */ {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_INIT_SST},
117 /* API_RC_OPEN_EVT */ {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_INIT_SST},
118 /* SRC_DATA_READY_EVT */ {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_INIT_SST},
119 /* CI_SETCONFIG_OK_EVT */ {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_INIT_SST},
Pavlin Radoslavovd7522292017-11-24 19:12:11 -0800120 /* CI_SETCONFIG_FAIL_EVT */
121 {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_INIT_SST},
Myles Watsoncd1fd072016-11-09 13:17:43 -0800122 /* SDP_DISC_OK_EVT */ {BTA_AV_FREE_SDB, BTA_AV_SIGNORE, BTA_AV_INIT_SST},
123 /* SDP_DISC_FAIL_EVT */ {BTA_AV_FREE_SDB, BTA_AV_SIGNORE, BTA_AV_INIT_SST},
124 /* STR_DISC_OK_EVT */ {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_INIT_SST},
125 /* STR_DISC_FAIL_EVT */ {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_INIT_SST},
126 /* STR_GETCAP_OK_EVT */ {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_INIT_SST},
127 /* STR_GETCAP_FAIL_EVT */ {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_INIT_SST},
128 /* STR_OPEN_OK_EVT */ {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_INIT_SST},
129 /* STR_OPEN_FAIL_EVT */ {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_INIT_SST},
130 /* STR_START_OK_EVT */ {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_INIT_SST},
131 /* STR_START_FAIL_EVT */ {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_INIT_SST},
132 /* STR_CLOSE_EVT */ {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_INIT_SST},
Pavlin Radoslavovd7522292017-11-24 19:12:11 -0800133 /* STR_CONFIG_IND_EVT */
134 {BTA_AV_SETCONFIG_REJ, BTA_AV_SIGNORE, BTA_AV_INIT_SST},
135 /* STR_SECURITY_IND_EVT */
136 {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_INIT_SST},
137 /* STR_SECURITY_CFM_EVT */
138 {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_INIT_SST},
Myles Watsoncd1fd072016-11-09 13:17:43 -0800139 /* STR_WRITE_CFM_EVT */ {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_INIT_SST},
140 /* STR_SUSPEND_CFM_EVT */ {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_INIT_SST},
Pavlin Radoslavovd7522292017-11-24 19:12:11 -0800141 /* STR_RECONFIG_CFM_EVT */
142 {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_INIT_SST},
Myles Watsoncd1fd072016-11-09 13:17:43 -0800143 /* AVRC_TIMER_EVT */ {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_INIT_SST},
144 /* AVDT_CONNECT_EVT */ {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_INIT_SST},
145 /* AVDT_DISCONNECT_EVT */ {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_INIT_SST},
146 /* ROLE_CHANGE_EVT*/ {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_INIT_SST},
147 /* AVDT_DELAY_RPT_EVT */ {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_INIT_SST},
148 /* ACP_CONNECT_EVT */ {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_INCOMING_SST},
Pavlin Radoslavovd7522292017-11-24 19:12:11 -0800149 /* API_OFFLOAD_START_EVT */
150 {BTA_AV_OFFLOAD_REQ, BTA_AV_SIGNORE, BTA_AV_INIT_SST},
151 /* API_OFFLOAD_START_RSP_EVT */
152 {BTA_AV_OFFLOAD_RSP, BTA_AV_SIGNORE, BTA_AV_INIT_SST}};
The Android Open Source Project5738f832012-12-12 16:00:35 -0800153
154/* state table for incoming state */
Myles Watsoncd1fd072016-11-09 13:17:43 -0800155static const uint8_t bta_av_sst_incoming[][BTA_AV_NUM_COLS] = {
156 /* Event Action 1 Action 2 Next state */
Pavlin Radoslavovd7522292017-11-24 19:12:11 -0800157 /* API_OPEN_EVT */ {BTA_AV_OPEN_AT_INC, BTA_AV_SIGNORE,
158 BTA_AV_INCOMING_SST},
159 /* API_CLOSE_EVT */
160 {BTA_AV_CCO_CLOSE, BTA_AV_DISCONNECT_REQ, BTA_AV_CLOSING_SST},
Myles Watsoncd1fd072016-11-09 13:17:43 -0800161 /* AP_START_EVT */ {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_INCOMING_SST},
162 /* AP_STOP_EVT */ {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_INCOMING_SST},
Pavlin Radoslavovd7522292017-11-24 19:12:11 -0800163 /* API_RECONFIG_EVT */
164 {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_INCOMING_SST},
165 /* API_PROTECT_REQ_EVT */
166 {BTA_AV_SECURITY_REQ, BTA_AV_SIGNORE, BTA_AV_INCOMING_SST},
167 /* API_PROTECT_RSP_EVT */
168 {BTA_AV_SECURITY_RSP, BTA_AV_SIGNORE, BTA_AV_INCOMING_SST},
169 /* API_RC_OPEN_EVT */
170 {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_INCOMING_SST},
171 /* SRC_DATA_READY_EVT */
172 {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_INCOMING_SST},
173 /* CI_SETCONFIG_OK_EVT */
174 {BTA_AV_SETCONFIG_RSP, BTA_AV_ST_RC_TIMER, BTA_AV_INCOMING_SST},
175 /* CI_SETCONFIG_FAIL_EVT */
176 {BTA_AV_SETCONFIG_REJ, BTA_AV_CLEANUP, BTA_AV_INIT_SST},
177 /* SDP_DISC_OK_EVT */
178 {BTA_AV_FREE_SDB, BTA_AV_SIGNORE, BTA_AV_INCOMING_SST},
179 /* SDP_DISC_FAIL_EVT */
180 {BTA_AV_FREE_SDB, BTA_AV_SIGNORE, BTA_AV_INCOMING_SST},
181 /* STR_DISC_OK_EVT */
182 {BTA_AV_DISC_RES_AS_ACP, BTA_AV_SIGNORE, BTA_AV_INCOMING_SST},
183 /* STR_DISC_FAIL_EVT */
184 {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_INCOMING_SST},
185 /* STR_GETCAP_OK_EVT */
186 {BTA_AV_SAVE_CAPS, BTA_AV_SIGNORE, BTA_AV_INCOMING_SST},
187 /* STR_GETCAP_FAIL_EVT */
188 {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_INCOMING_SST},
Myles Watsoncd1fd072016-11-09 13:17:43 -0800189 /* STR_OPEN_OK_EVT */ {BTA_AV_STR_OPENED, BTA_AV_SIGNORE, BTA_AV_OPEN_SST},
Pavlin Radoslavovd7522292017-11-24 19:12:11 -0800190 /* STR_OPEN_FAIL_EVT */
191 {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_INCOMING_SST},
192 /* STR_START_OK_EVT */
193 {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_INCOMING_SST},
194 /* STR_START_FAIL_EVT */
195 {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_INCOMING_SST},
Myles Watsoncd1fd072016-11-09 13:17:43 -0800196 /* STR_CLOSE_EVT */ {BTA_AV_CCO_CLOSE, BTA_AV_CLEANUP, BTA_AV_INIT_SST},
Pavlin Radoslavovd7522292017-11-24 19:12:11 -0800197 /* STR_CONFIG_IND_EVT */
198 {BTA_AV_CONFIG_IND, BTA_AV_SIGNORE, BTA_AV_INCOMING_SST},
199 /* STR_SECURITY_IND_EVT */
200 {BTA_AV_SECURITY_IND, BTA_AV_SIGNORE, BTA_AV_INCOMING_SST},
201 /* STR_SECURITY_CFM_EVT */
202 {BTA_AV_SECURITY_CFM, BTA_AV_SIGNORE, BTA_AV_INCOMING_SST},
203 /* STR_WRITE_CFM_EVT */
204 {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_INCOMING_SST},
205 /* STR_SUSPEND_CFM_EVT */
206 {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_INCOMING_SST},
207 /* STR_RECONFIG_CFM_EVT */
208 {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_INCOMING_SST},
Myles Watsoncd1fd072016-11-09 13:17:43 -0800209 /* AVRC_TIMER_EVT */ {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_INCOMING_SST},
Pavlin Radoslavovd7522292017-11-24 19:12:11 -0800210 /* AVDT_CONNECT_EVT */
211 {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_INCOMING_SST},
212 /* AVDT_DISCONNECT_EVT */
213 {BTA_AV_CCO_CLOSE, BTA_AV_DISCONNECT_REQ, BTA_AV_CLOSING_SST},
Myles Watsoncd1fd072016-11-09 13:17:43 -0800214 /* ROLE_CHANGE_EVT*/ {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_INCOMING_SST},
Pavlin Radoslavovd7522292017-11-24 19:12:11 -0800215 /* AVDT_DELAY_RPT_EVT */
216 {BTA_AV_DELAY_CO, BTA_AV_SIGNORE, BTA_AV_INCOMING_SST},
Myles Watsoncd1fd072016-11-09 13:17:43 -0800217 /* ACP_CONNECT_EVT */ {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_INCOMING_SST},
Pavlin Radoslavovd7522292017-11-24 19:12:11 -0800218 /* API_OFFLOAD_START_EVT */
219 {BTA_AV_OFFLOAD_REQ, BTA_AV_SIGNORE, BTA_AV_INCOMING_SST},
220 /* API_OFFLOAD_START_RSP_EVT */
221 {BTA_AV_OFFLOAD_RSP, BTA_AV_SIGNORE, BTA_AV_INCOMING_SST}};
The Android Open Source Project5738f832012-12-12 16:00:35 -0800222
223/* state table for opening state */
Myles Watsoncd1fd072016-11-09 13:17:43 -0800224static const uint8_t bta_av_sst_opening[][BTA_AV_NUM_COLS] = {
225 /* Event Action 1 Action 2 Next state */
Pavlin Radoslavovd7522292017-11-24 19:12:11 -0800226 /* API_OPEN_EVT */ {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_OPENING_SST},
227 /* API_CLOSE_EVT */ {BTA_AV_DO_CLOSE, BTA_AV_SIGNORE, BTA_AV_CLOSING_SST},
Myles Watsoncd1fd072016-11-09 13:17:43 -0800228 /* AP_START_EVT */ {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_OPENING_SST},
229 /* AP_STOP_EVT */ {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_OPENING_SST},
230 /* API_RECONFIG_EVT */ {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_OPENING_SST},
Pavlin Radoslavovd7522292017-11-24 19:12:11 -0800231 /* API_PROTECT_REQ_EVT */
232 {BTA_AV_SECURITY_REQ, BTA_AV_SIGNORE, BTA_AV_OPENING_SST},
233 /* API_PROTECT_RSP_EVT */
234 {BTA_AV_SECURITY_RSP, BTA_AV_SIGNORE, BTA_AV_OPENING_SST},
Myles Watsoncd1fd072016-11-09 13:17:43 -0800235 /* API_RC_OPEN_EVT */ {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_OPENING_SST},
Pavlin Radoslavovd7522292017-11-24 19:12:11 -0800236 /* SRC_DATA_READY_EVT */
237 {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_OPENING_SST},
238 /* CI_SETCONFIG_OK_EVT */
239 {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_OPENING_SST},
240 /* CI_SETCONFIG_FAIL_EVT */
241 {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_OPENING_SST},
242 /* SDP_DISC_OK_EVT */
243 {BTA_AV_CONNECT_REQ, BTA_AV_SIGNORE, BTA_AV_OPENING_SST},
244 /* SDP_DISC_FAIL_EVT */
245 {BTA_AV_CONNECT_REQ, BTA_AV_SIGNORE, BTA_AV_OPENING_SST},
246 /* STR_DISC_OK_EVT */
247 {BTA_AV_DISC_RESULTS, BTA_AV_SIGNORE, BTA_AV_OPENING_SST},
248 /* STR_DISC_FAIL_EVT */
249 {BTA_AV_OPEN_FAILED, BTA_AV_SIGNORE, BTA_AV_CLOSING_SST},
250 /* STR_GETCAP_OK_EVT */
251 {BTA_AV_GETCAP_RESULTS, BTA_AV_SIGNORE, BTA_AV_OPENING_SST},
252 /* STR_GETCAP_FAIL_EVT */
253 {BTA_AV_OPEN_FAILED, BTA_AV_SIGNORE, BTA_AV_CLOSING_SST},
254 /* STR_OPEN_OK_EVT */
255 {BTA_AV_ST_RC_TIMER, BTA_AV_STR_OPENED, BTA_AV_OPEN_SST},
256 /* STR_OPEN_FAIL_EVT */
257 {BTA_AV_OPEN_FAILED, BTA_AV_SIGNORE, BTA_AV_CLOSING_SST},
Myles Watsoncd1fd072016-11-09 13:17:43 -0800258 /* STR_START_OK_EVT */ {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_OPENING_SST},
Pavlin Radoslavovd7522292017-11-24 19:12:11 -0800259 /* STR_START_FAIL_EVT */
260 {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_OPENING_SST},
Myles Watsoncd1fd072016-11-09 13:17:43 -0800261 /* STR_CLOSE_EVT */ {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_OPENING_SST},
Pavlin Radoslavovd7522292017-11-24 19:12:11 -0800262 /* STR_CONFIG_IND_EVT */
263 {BTA_AV_CONFIG_IND, BTA_AV_SIGNORE, BTA_AV_INCOMING_SST},
264 /* STR_SECURITY_IND_EVT */
265 {BTA_AV_SECURITY_IND, BTA_AV_SIGNORE, BTA_AV_OPENING_SST},
266 /* STR_SECURITY_CFM_EVT */
267 {BTA_AV_SECURITY_CFM, BTA_AV_SIGNORE, BTA_AV_OPENING_SST},
268 /* STR_WRITE_CFM_EVT */
269 {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_OPENING_SST},
270 /* STR_SUSPEND_CFM_EVT */
271 {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_OPENING_SST},
272 /* STR_RECONFIG_CFM_EVT */
273 {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_OPENING_SST},
274 /* AVRC_TIMER_EVT */
275 {BTA_AV_SWITCH_ROLE, BTA_AV_SIGNORE, BTA_AV_OPENING_SST},
276 /* AVDT_CONNECT_EVT */
277 {BTA_AV_DISCOVER_REQ, BTA_AV_SIGNORE, BTA_AV_OPENING_SST},
278 /* AVDT_DISCONNECT_EVT */
279 {BTA_AV_CONN_FAILED, BTA_AV_SIGNORE, BTA_AV_INIT_SST},
Myles Watsoncd1fd072016-11-09 13:17:43 -0800280 /* ROLE_CHANGE_EVT*/ {BTA_AV_ROLE_RES, BTA_AV_SIGNORE, BTA_AV_OPENING_SST},
Pavlin Radoslavovd7522292017-11-24 19:12:11 -0800281 /* AVDT_DELAY_RPT_EVT */
282 {BTA_AV_DELAY_CO, BTA_AV_SIGNORE, BTA_AV_OPENING_SST},
Myles Watsoncd1fd072016-11-09 13:17:43 -0800283 /* ACP_CONNECT_EVT */ {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_OPENING_SST},
Pavlin Radoslavovd7522292017-11-24 19:12:11 -0800284 /* API_OFFLOAD_START_EVT */
285 {BTA_AV_OFFLOAD_REQ, BTA_AV_SIGNORE, BTA_AV_OPENING_SST},
286 /* API_OFFLOAD_START_RSP_EVT */
287 {BTA_AV_OFFLOAD_RSP, BTA_AV_SIGNORE, BTA_AV_OPENING_SST}};
The Android Open Source Project5738f832012-12-12 16:00:35 -0800288
289/* state table for open state */
Myles Watsoncd1fd072016-11-09 13:17:43 -0800290static const uint8_t bta_av_sst_open[][BTA_AV_NUM_COLS] = {
291 /* Event Action 1 Action 2 Next state */
Pavlin Radoslavovd7522292017-11-24 19:12:11 -0800292 /* API_OPEN_EVT */ {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_OPEN_SST},
293 /* API_CLOSE_EVT */ {BTA_AV_DO_CLOSE, BTA_AV_SIGNORE, BTA_AV_CLOSING_SST},
Myles Watsoncd1fd072016-11-09 13:17:43 -0800294 /* AP_START_EVT */ {BTA_AV_DO_START, BTA_AV_SIGNORE, BTA_AV_OPEN_SST},
295 /* AP_STOP_EVT */ {BTA_AV_STR_STOPPED, BTA_AV_SIGNORE, BTA_AV_OPEN_SST},
296 /* API_RECONFIG_EVT */ {BTA_AV_RECONFIG, BTA_AV_SIGNORE, BTA_AV_RCFG_SST},
Pavlin Radoslavovd7522292017-11-24 19:12:11 -0800297 /* API_PROTECT_REQ_EVT */
298 {BTA_AV_SECURITY_REQ, BTA_AV_SIGNORE, BTA_AV_OPEN_SST},
299 /* API_PROTECT_RSP_EVT */
300 {BTA_AV_SECURITY_RSP, BTA_AV_SIGNORE, BTA_AV_OPEN_SST},
Myles Watsoncd1fd072016-11-09 13:17:43 -0800301 /* API_RC_OPEN_EVT */ {BTA_AV_SET_USE_RC, BTA_AV_OPEN_RC, BTA_AV_OPEN_SST},
Pavlin Radoslavovd7522292017-11-24 19:12:11 -0800302 /* SRC_DATA_READY_EVT */
303 {BTA_AV_DATA_PATH, BTA_AV_SIGNORE, BTA_AV_OPEN_SST},
Myles Watsoncd1fd072016-11-09 13:17:43 -0800304 /* CI_SETCONFIG_OK_EVT */ {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_OPEN_SST},
Pavlin Radoslavovd7522292017-11-24 19:12:11 -0800305 /* CI_SETCONFIG_FAIL_EVT */
306 {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_OPEN_SST},
Myles Watsoncd1fd072016-11-09 13:17:43 -0800307 /* SDP_DISC_OK_EVT */ {BTA_AV_FREE_SDB, BTA_AV_SIGNORE, BTA_AV_OPEN_SST},
308 /* SDP_DISC_FAIL_EVT */ {BTA_AV_FREE_SDB, BTA_AV_SIGNORE, BTA_AV_OPEN_SST},
309 /* STR_DISC_OK_EVT */ {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_OPEN_SST},
310 /* STR_DISC_FAIL_EVT */ {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_OPEN_SST},
311 /* STR_GETCAP_OK_EVT */ {BTA_AV_SAVE_CAPS, BTA_AV_SIGNORE, BTA_AV_OPEN_SST},
312 /* STR_GETCAP_FAIL_EVT */ {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_OPEN_SST},
313 /* STR_OPEN_OK_EVT */ {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_OPEN_SST},
314 /* STR_OPEN_FAIL_EVT */ {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_OPEN_SST},
315 /* STR_START_OK_EVT */ {BTA_AV_START_OK, BTA_AV_SIGNORE, BTA_AV_OPEN_SST},
Pavlin Radoslavovd7522292017-11-24 19:12:11 -0800316 /* STR_START_FAIL_EVT */
317 {BTA_AV_START_FAILED, BTA_AV_SIGNORE, BTA_AV_OPEN_SST},
Myles Watsoncd1fd072016-11-09 13:17:43 -0800318 /* STR_CLOSE_EVT */ {BTA_AV_STR_CLOSED, BTA_AV_SIGNORE, BTA_AV_INIT_SST},
Pavlin Radoslavovd7522292017-11-24 19:12:11 -0800319 /* STR_CONFIG_IND_EVT */
320 {BTA_AV_SETCONFIG_REJ, BTA_AV_SIGNORE, BTA_AV_OPEN_SST},
321 /* STR_SECURITY_IND_EVT */
322 {BTA_AV_SECURITY_IND, BTA_AV_SIGNORE, BTA_AV_OPEN_SST},
323 /* STR_SECURITY_CFM_EVT */
324 {BTA_AV_SECURITY_CFM, BTA_AV_SIGNORE, BTA_AV_OPEN_SST},
325 /* STR_WRITE_CFM_EVT */
326 {BTA_AV_CLR_CONG, BTA_AV_DATA_PATH, BTA_AV_OPEN_SST},
327 /* STR_SUSPEND_CFM_EVT */
328 {BTA_AV_SUSPEND_CFM, BTA_AV_SIGNORE, BTA_AV_OPEN_SST},
329 /* STR_RECONFIG_CFM_EVT */
330 {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_OPEN_SST},
331 /* AVRC_TIMER_EVT */
332 {BTA_AV_OPEN_RC, BTA_AV_CHK_2ND_START, BTA_AV_OPEN_SST},
Myles Watsoncd1fd072016-11-09 13:17:43 -0800333 /* AVDT_CONNECT_EVT */ {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_OPEN_SST},
Pavlin Radoslavovd7522292017-11-24 19:12:11 -0800334 /* AVDT_DISCONNECT_EVT */
335 {BTA_AV_STR_CLOSED, BTA_AV_SIGNORE, BTA_AV_INIT_SST},
Myles Watsoncd1fd072016-11-09 13:17:43 -0800336 /* ROLE_CHANGE_EVT*/ {BTA_AV_ROLE_RES, BTA_AV_SIGNORE, BTA_AV_OPEN_SST},
337 /* AVDT_DELAY_RPT_EVT */ {BTA_AV_DELAY_CO, BTA_AV_SIGNORE, BTA_AV_OPEN_SST},
338 /* ACP_CONNECT_EVT */ {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_OPEN_SST},
Pavlin Radoslavovd7522292017-11-24 19:12:11 -0800339 /* API_OFFLOAD_START_EVT */
340 {BTA_AV_OFFLOAD_REQ, BTA_AV_SIGNORE, BTA_AV_OPEN_SST},
341 /* API_OFFLOAD_START_RSP_EVT */
342 {BTA_AV_OFFLOAD_RSP, BTA_AV_SIGNORE, BTA_AV_OPEN_SST}};
The Android Open Source Project5738f832012-12-12 16:00:35 -0800343
344/* state table for reconfig state */
Myles Watsoncd1fd072016-11-09 13:17:43 -0800345static const uint8_t bta_av_sst_rcfg[][BTA_AV_NUM_COLS] = {
346 /* Event Action 1 Action 2 Next state */
Pavlin Radoslavovd7522292017-11-24 19:12:11 -0800347 /* API_OPEN_EVT */ {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_RCFG_SST},
348 /* API_CLOSE_EVT */
349 {BTA_AV_DISCONNECT_REQ, BTA_AV_SIGNORE, BTA_AV_CLOSING_SST},
Myles Watsoncd1fd072016-11-09 13:17:43 -0800350 /* AP_START_EVT */ {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_RCFG_SST},
351 /* AP_STOP_EVT */ {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_RCFG_SST},
Pavlin Radoslavova72b0e22017-02-11 01:20:49 -0800352 /* API_RECONFIG_EVT */ {BTA_AV_RECONFIG, BTA_AV_SIGNORE, BTA_AV_RCFG_SST},
Myles Watsoncd1fd072016-11-09 13:17:43 -0800353 /* API_PROTECT_REQ_EVT */ {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_RCFG_SST},
354 /* API_PROTECT_RSP_EVT */ {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_RCFG_SST},
355 /* API_RC_OPEN_EVT */ {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_RCFG_SST},
356 /* SRC_DATA_READY_EVT */ {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_RCFG_SST},
357 /* CI_SETCONFIG_OK_EVT */ {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_RCFG_SST},
Pavlin Radoslavovd7522292017-11-24 19:12:11 -0800358 /* CI_SETCONFIG_FAIL_EVT */
359 {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_RCFG_SST},
Myles Watsoncd1fd072016-11-09 13:17:43 -0800360 /* SDP_DISC_OK_EVT */ {BTA_AV_FREE_SDB, BTA_AV_SIGNORE, BTA_AV_RCFG_SST},
361 /* SDP_DISC_FAIL_EVT */ {BTA_AV_FREE_SDB, BTA_AV_SIGNORE, BTA_AV_RCFG_SST},
Pavlin Radoslavovd7522292017-11-24 19:12:11 -0800362 /* STR_DISC_OK_EVT */
363 {BTA_AV_DISC_RESULTS, BTA_AV_SIGNORE, BTA_AV_RCFG_SST},
364 /* STR_DISC_FAIL_EVT */
365 {BTA_AV_STR_CLOSED, BTA_AV_SIGNORE, BTA_AV_INIT_SST},
366 /* STR_GETCAP_OK_EVT */
367 {BTA_AV_GETCAP_RESULTS, BTA_AV_SIGNORE, BTA_AV_RCFG_SST},
368 /* STR_GETCAP_FAIL_EVT */
369 {BTA_AV_STR_CLOSED, BTA_AV_SIGNORE, BTA_AV_INIT_SST},
Myles Watsoncd1fd072016-11-09 13:17:43 -0800370 /* STR_OPEN_OK_EVT */ {BTA_AV_RCFG_STR_OK, BTA_AV_SIGNORE, BTA_AV_OPEN_SST},
Pavlin Radoslavovd7522292017-11-24 19:12:11 -0800371 /* STR_OPEN_FAIL_EVT */
372 {BTA_AV_RCFG_FAILED, BTA_AV_SIGNORE, BTA_AV_RCFG_SST},
Myles Watsoncd1fd072016-11-09 13:17:43 -0800373 /* STR_START_OK_EVT */ {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_RCFG_SST},
374 /* STR_START_FAIL_EVT */ {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_RCFG_SST},
375 /* STR_CLOSE_EVT */ {BTA_AV_RCFG_CONNECT, BTA_AV_SIGNORE, BTA_AV_RCFG_SST},
Pavlin Radoslavovd7522292017-11-24 19:12:11 -0800376 /* STR_CONFIG_IND_EVT */
377 {BTA_AV_SETCONFIG_REJ, BTA_AV_SIGNORE, BTA_AV_RCFG_SST},
378 /* STR_SECURITY_IND_EVT */
379 {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_RCFG_SST},
380 /* STR_SECURITY_CFM_EVT */
381 {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_RCFG_SST},
Myles Watsoncd1fd072016-11-09 13:17:43 -0800382 /* STR_WRITE_CFM_EVT */ {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_RCFG_SST},
Pavlin Radoslavovd7522292017-11-24 19:12:11 -0800383 /* STR_SUSPEND_CFM_EVT */
384 {BTA_AV_SUSPEND_CFM, BTA_AV_SUSPEND_CONT, BTA_AV_RCFG_SST},
385 /* STR_RECONFIG_CFM_EVT */
386 {BTA_AV_RCFG_CFM, BTA_AV_SIGNORE, BTA_AV_RCFG_SST},
Myles Watsoncd1fd072016-11-09 13:17:43 -0800387 /* AVRC_TIMER_EVT */ {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_RCFG_SST},
388 /* AVDT_CONNECT_EVT */ {BTA_AV_RCFG_OPEN, BTA_AV_SIGNORE, BTA_AV_RCFG_SST},
Pavlin Radoslavovd7522292017-11-24 19:12:11 -0800389 /* AVDT_DISCONNECT_EVT */
390 {BTA_AV_RCFG_DISCNTD, BTA_AV_SIGNORE, BTA_AV_RCFG_SST},
Myles Watsoncd1fd072016-11-09 13:17:43 -0800391 /* ROLE_CHANGE_EVT*/ {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_RCFG_SST},
392 /* AVDT_DELAY_RPT_EVT */ {BTA_AV_DELAY_CO, BTA_AV_SIGNORE, BTA_AV_RCFG_SST},
393 /* ACP_CONNECT_EVT */ {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_RCFG_SST},
Pavlin Radoslavovd7522292017-11-24 19:12:11 -0800394 /* API_OFFLOAD_START_EVT */
395 {BTA_AV_OFFLOAD_REQ, BTA_AV_SIGNORE, BTA_AV_RCFG_SST},
396 /* API_OFFLOAD_START_RSP_EVT */
397 {BTA_AV_OFFLOAD_RSP, BTA_AV_SIGNORE, BTA_AV_RCFG_SST}};
The Android Open Source Project5738f832012-12-12 16:00:35 -0800398
399/* state table for closing state */
Myles Watsoncd1fd072016-11-09 13:17:43 -0800400static const uint8_t bta_av_sst_closing[][BTA_AV_NUM_COLS] = {
401 /* Event Action 1 Action 2 Next state */
Pavlin Radoslavovd7522292017-11-24 19:12:11 -0800402 /* API_OPEN_EVT */ {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_CLOSING_SST},
403 /* API_CLOSE_EVT */
404 {BTA_AV_DISCONNECT_REQ, BTA_AV_SIGNORE, BTA_AV_CLOSING_SST},
Myles Watsoncd1fd072016-11-09 13:17:43 -0800405 /* AP_START_EVT */ {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_CLOSING_SST},
406 /* AP_STOP_EVT */ {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_CLOSING_SST},
407 /* API_RECONFIG_EVT */ {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_CLOSING_SST},
Pavlin Radoslavovd7522292017-11-24 19:12:11 -0800408 /* API_PROTECT_REQ_EVT */
409 {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_CLOSING_SST},
410 /* API_PROTECT_RSP_EVT */
411 {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_CLOSING_SST},
Myles Watsoncd1fd072016-11-09 13:17:43 -0800412 /* API_RC_OPEN_EVT */ {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_CLOSING_SST},
Pavlin Radoslavovd7522292017-11-24 19:12:11 -0800413 /* SRC_DATA_READY_EVT */
414 {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_CLOSING_SST},
415 /* CI_SETCONFIG_OK_EVT */
416 {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_CLOSING_SST},
417 /* CI_SETCONFIG_FAIL_EVT */
418 {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_CLOSING_SST},
Myles Watsoncd1fd072016-11-09 13:17:43 -0800419 /* SDP_DISC_OK_EVT */ {BTA_AV_SDP_FAILED, BTA_AV_SIGNORE, BTA_AV_INIT_SST},
Pavlin Radoslavovd7522292017-11-24 19:12:11 -0800420 /* SDP_DISC_FAIL_EVT */
421 {BTA_AV_SDP_FAILED, BTA_AV_SIGNORE, BTA_AV_INIT_SST},
Myles Watsoncd1fd072016-11-09 13:17:43 -0800422 /* STR_DISC_OK_EVT */ {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_CLOSING_SST},
Pavlin Radoslavovd7522292017-11-24 19:12:11 -0800423 /* STR_DISC_FAIL_EVT */
424 {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_CLOSING_SST},
425 /* STR_GETCAP_OK_EVT */
426 {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_CLOSING_SST},
427 /* STR_GETCAP_FAIL_EVT */
428 {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_CLOSING_SST},
Myles Watsoncd1fd072016-11-09 13:17:43 -0800429 /* STR_OPEN_OK_EVT */ {BTA_AV_DO_CLOSE, BTA_AV_SIGNORE, BTA_AV_CLOSING_SST},
Pavlin Radoslavovd7522292017-11-24 19:12:11 -0800430 /* STR_OPEN_FAIL_EVT */
431 {BTA_AV_DISCONNECT_REQ, BTA_AV_SIGNORE, BTA_AV_CLOSING_SST},
Myles Watsoncd1fd072016-11-09 13:17:43 -0800432 /* STR_START_OK_EVT */ {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_CLOSING_SST},
Pavlin Radoslavovd7522292017-11-24 19:12:11 -0800433 /* STR_START_FAIL_EVT */
434 {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_CLOSING_SST},
435 /* STR_CLOSE_EVT */
436 {BTA_AV_DISCONNECT_REQ, BTA_AV_SIGNORE, BTA_AV_CLOSING_SST},
437 /* STR_CONFIG_IND_EVT */
438 {BTA_AV_SETCONFIG_REJ, BTA_AV_SIGNORE, BTA_AV_CLOSING_SST},
439 /* STR_SECURITY_IND_EVT */
440 {BTA_AV_SECURITY_REJ, BTA_AV_SIGNORE, BTA_AV_CLOSING_SST},
441 /* STR_SECURITY_CFM_EVT */
442 {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_CLOSING_SST},
443 /* STR_WRITE_CFM_EVT */
444 {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_CLOSING_SST},
445 /* STR_SUSPEND_CFM_EVT */
446 {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_CLOSING_SST},
447 /* STR_RECONFIG_CFM_EVT */
448 {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_CLOSING_SST},
Myles Watsoncd1fd072016-11-09 13:17:43 -0800449 /* AVRC_TIMER_EVT */ {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_CLOSING_SST},
450 /* AVDT_CONNECT_EVT */ {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_CLOSING_SST},
Pavlin Radoslavovd7522292017-11-24 19:12:11 -0800451 /* AVDT_DISCONNECT_EVT */
452 {BTA_AV_STR_CLOSED, BTA_AV_SIGNORE, BTA_AV_INIT_SST},
Myles Watsoncd1fd072016-11-09 13:17:43 -0800453 /* ROLE_CHANGE_EVT*/ {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_CLOSING_SST},
Pavlin Radoslavovd7522292017-11-24 19:12:11 -0800454 /* AVDT_DELAY_RPT_EVT */
455 {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_CLOSING_SST},
Myles Watsoncd1fd072016-11-09 13:17:43 -0800456 /* ACP_CONNECT_EVT */ {BTA_AV_SIGNORE, BTA_AV_SIGNORE, BTA_AV_CLOSING_SST},
Pavlin Radoslavovd7522292017-11-24 19:12:11 -0800457 /* API_OFFLOAD_START_EVT */
458 {BTA_AV_OFFLOAD_REQ, BTA_AV_SIGNORE, BTA_AV_CLOSING_SST},
459 /* API_OFFLOAD_START_RSP_EVT */
460 {BTA_AV_OFFLOAD_RSP, BTA_AV_SIGNORE, BTA_AV_CLOSING_SST}};
The Android Open Source Project5738f832012-12-12 16:00:35 -0800461
462/* type for state table */
Marie Janssene9e58ce2016-06-17 14:12:17 -0700463typedef const uint8_t (*tBTA_AV_SST_TBL)[BTA_AV_NUM_COLS];
The Android Open Source Project5738f832012-12-12 16:00:35 -0800464
465/* state table */
Myles Watsoncd1fd072016-11-09 13:17:43 -0800466static const tBTA_AV_SST_TBL bta_av_sst_tbl[] = {
467 bta_av_sst_init, bta_av_sst_incoming, bta_av_sst_opening,
468 bta_av_sst_open, bta_av_sst_rcfg, bta_av_sst_closing};
The Android Open Source Project5738f832012-12-12 16:00:35 -0800469
The Android Open Source Project5738f832012-12-12 16:00:35 -0800470
471/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800472 *
Myles Watson8af480e2016-11-09 10:40:23 -0800473 * Function bta_av_ssm_execute
474 *
475 * Description Stream state machine event handling function for AV
476 *
477 *
478 * Returns void
479 *
480 ******************************************************************************/
Myles Watsoncd1fd072016-11-09 13:17:43 -0800481void bta_av_ssm_execute(tBTA_AV_SCB* p_scb, uint16_t event,
482 tBTA_AV_DATA* p_data) {
Myles Watsoncd1fd072016-11-09 13:17:43 -0800483 if (p_scb == NULL) {
484 /* this stream is not registered */
Pavlin Radoslavovd7522292017-11-24 19:12:11 -0800485 APPL_TRACE_EVENT("%s: AV channel not registered", __func__);
Myles Watsoncd1fd072016-11-09 13:17:43 -0800486 return;
487 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800488
Pavlin Radoslavovd7522292017-11-24 19:12:11 -0800489 APPL_TRACE_VERBOSE(
490 "%s: peer %s AV event(0x%x)=0x%x(%s) state=%d(%s) p_scb=%p", __func__,
Pavlin Radoslavova634f4e2018-04-23 13:36:33 -0700491 p_scb->PeerAddress().ToString().c_str(), p_scb->hndl, event,
Pavlin Radoslavovd7522292017-11-24 19:12:11 -0800492 bta_av_evt_code(event), p_scb->state, bta_av_sst_code(p_scb->state),
493 p_scb);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800494
Myles Watsoncd1fd072016-11-09 13:17:43 -0800495 /* look up the state table for the current state */
Pavlin Radoslavovd7522292017-11-24 19:12:11 -0800496 tBTA_AV_SST_TBL state_table = bta_av_sst_tbl[p_scb->state];
The Android Open Source Project5738f832012-12-12 16:00:35 -0800497
Myles Watsoncd1fd072016-11-09 13:17:43 -0800498 /* set next state */
Pavlin Radoslavovd7522292017-11-24 19:12:11 -0800499 event -= BTA_AV_FIRST_SSM_EVT;
Myles Watsoncd1fd072016-11-09 13:17:43 -0800500 p_scb->state = state_table[event][BTA_AV_SNEXT_STATE];
The Android Open Source Project5738f832012-12-12 16:00:35 -0800501
Pavlin Radoslavovd7522292017-11-24 19:12:11 -0800502 APPL_TRACE_VERBOSE("%s: peer %s AV next state=%d(%s) p_scb=%p", __func__,
Pavlin Radoslavova634f4e2018-04-23 13:36:33 -0700503 p_scb->PeerAddress().ToString().c_str(), p_scb->state,
Pavlin Radoslavovd7522292017-11-24 19:12:11 -0800504 bta_av_sst_code(p_scb->state), p_scb);
505
Myles Watsoncd1fd072016-11-09 13:17:43 -0800506 /* execute action functions */
Pavlin Radoslavovd7522292017-11-24 19:12:11 -0800507 for (int i = 0; i < BTA_AV_SACTIONS; i++) {
508 uint8_t action = state_table[event][i];
Marie Janssenf33b6f42016-11-22 15:01:42 -0800509 if (action != BTA_AV_SIGNORE) {
Myles Watsoncd1fd072016-11-09 13:17:43 -0800510 (*p_scb->p_act_tbl[action])(p_scb, p_data);
511 } else
512 break;
513 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800514}
515
516/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800517 *
518 * Function bta_av_is_scb_opening
519 *
520 * Description Returns true is scb is in opening state.
521 *
522 *
523 * Returns true if scb is in opening state.
524 *
525 ******************************************************************************/
Myles Watsoncd1fd072016-11-09 13:17:43 -0800526bool bta_av_is_scb_opening(tBTA_AV_SCB* p_scb) {
527 bool is_opening = false;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800528
Myles Watsoncd1fd072016-11-09 13:17:43 -0800529 if (p_scb) {
530 if (p_scb->state == BTA_AV_OPENING_SST) is_opening = true;
531 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800532
Myles Watsoncd1fd072016-11-09 13:17:43 -0800533 return is_opening;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800534}
535
536/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800537 *
538 * Function bta_av_is_scb_incoming
539 *
540 * Description Returns true is scb is in incoming state.
541 *
542 *
543 * Returns true if scb is in incoming state.
544 *
545 ******************************************************************************/
Myles Watsoncd1fd072016-11-09 13:17:43 -0800546bool bta_av_is_scb_incoming(tBTA_AV_SCB* p_scb) {
547 bool is_incoming = false;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800548
Myles Watsoncd1fd072016-11-09 13:17:43 -0800549 if (p_scb) {
550 if (p_scb->state == BTA_AV_INCOMING_SST) is_incoming = true;
551 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800552
Myles Watsoncd1fd072016-11-09 13:17:43 -0800553 return is_incoming;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800554}
555
556/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800557 *
558 * Function bta_av_set_scb_sst_init
559 *
560 * Description Set SST state to INIT.
561 * Use this function to change SST outside of state machine.
562 *
563 * Returns None
564 *
565 ******************************************************************************/
Myles Watsoncd1fd072016-11-09 13:17:43 -0800566void bta_av_set_scb_sst_init(tBTA_AV_SCB* p_scb) {
Pavlin Radoslavovd7522292017-11-24 19:12:11 -0800567 if (p_scb == nullptr) {
568 return;
Myles Watsoncd1fd072016-11-09 13:17:43 -0800569 }
Pavlin Radoslavovd7522292017-11-24 19:12:11 -0800570
571 uint8_t next_state = BTA_AV_INIT_SST;
572
573 APPL_TRACE_VERBOSE(
574 "%s: peer %s AV (hndl=0x%x) state=%d(%s) next state=%d(%s) p_scb=%p",
Pavlin Radoslavova634f4e2018-04-23 13:36:33 -0700575 __func__, p_scb->PeerAddress().ToString().c_str(), p_scb->hndl,
576 p_scb->state, bta_av_sst_code(p_scb->state), next_state,
577 bta_av_sst_code(next_state), p_scb);
Pavlin Radoslavovd7522292017-11-24 19:12:11 -0800578
579 p_scb->state = next_state;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800580}
581
582/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800583 *
584 * Function bta_av_is_scb_init
585 *
586 * Description Returns true is scb is in init state.
587 *
588 *
589 * Returns true if scb is in incoming state.
590 *
591 ******************************************************************************/
Myles Watsoncd1fd072016-11-09 13:17:43 -0800592bool bta_av_is_scb_init(tBTA_AV_SCB* p_scb) {
593 bool is_init = false;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800594
Myles Watsoncd1fd072016-11-09 13:17:43 -0800595 if (p_scb) {
596 if (p_scb->state == BTA_AV_INIT_SST) is_init = true;
597 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800598
Myles Watsoncd1fd072016-11-09 13:17:43 -0800599 return is_init;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800600}
601
602/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800603 *
604 * Function bta_av_set_scb_sst_incoming
605 *
606 * Description Set SST state to incoming.
607 * Use this function to change SST outside of state machine.
608 *
609 * Returns None
610 *
611 ******************************************************************************/
Myles Watsoncd1fd072016-11-09 13:17:43 -0800612void bta_av_set_scb_sst_incoming(tBTA_AV_SCB* p_scb) {
613 if (p_scb) {
614 p_scb->state = BTA_AV_INCOMING_SST;
615 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800616}
617
618/*****************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800619 * Debug Functions
620 ****************************************************************************/
The Android Open Source Project5738f832012-12-12 16:00:35 -0800621/*******************************************************************************
Myles Watson8af480e2016-11-09 10:40:23 -0800622 *
623 * Function bta_av_sst_code
624 *
625 * Description
626 *
627 * Returns char *
628 *
629 ******************************************************************************/
Pavlin Radoslavovd7522292017-11-24 19:12:11 -0800630const char* bta_av_sst_code(uint8_t state) {
Myles Watsoncd1fd072016-11-09 13:17:43 -0800631 switch (state) {
632 case BTA_AV_INIT_SST:
633 return "INIT";
634 case BTA_AV_INCOMING_SST:
635 return "INCOMING";
636 case BTA_AV_OPENING_SST:
637 return "OPENING";
638 case BTA_AV_OPEN_SST:
639 return "OPEN";
640 case BTA_AV_RCFG_SST:
641 return "RCFG";
642 case BTA_AV_CLOSING_SST:
643 return "CLOSING";
644 default:
645 return "unknown";
646 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800647}