1 /******************************************************************************
2  *
3  *  Copyright (C) 2004-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 is the private interface file for the BTA advanced audio/video.
22  *
23  ******************************************************************************/
24 #ifndef BTA_AV_INT_H
25 #define BTA_AV_INT_H
26 
27 #include "avdt_api.h"
28 #include "bta_api.h"
29 #include "bta_av_api.h"
30 #include "bta_av_co.h"
31 #include "bta_sys.h"
32 #include "osi/include/list.h"
33 #include "stack/include/a2dp_api.h"
34 
35 /*****************************************************************************
36  *  Constants
37  ****************************************************************************/
38 
39 enum {
40   /* these events are handled by the AV main state machine */
41   BTA_AV_API_DISABLE_EVT = BTA_SYS_EVT_START(BTA_ID_AV),
42   BTA_AV_API_REMOTE_CMD_EVT,
43   BTA_AV_API_VENDOR_CMD_EVT,
44   BTA_AV_API_VENDOR_RSP_EVT,
45   BTA_AV_API_META_RSP_EVT,
46   BTA_AV_API_RC_CLOSE_EVT,
47   BTA_AV_AVRC_OPEN_EVT,
48   BTA_AV_AVRC_MSG_EVT,
49   BTA_AV_AVRC_NONE_EVT,
50 
51   /* these events are handled by the AV stream state machine */
52   BTA_AV_API_OPEN_EVT,
53   BTA_AV_API_CLOSE_EVT,
54   BTA_AV_AP_START_EVT, /* the following 2 events must be in the same order as
55                           the *API_*EVT */
56   BTA_AV_AP_STOP_EVT,
57   BTA_AV_API_RECONFIG_EVT,
58   BTA_AV_API_PROTECT_REQ_EVT,
59   BTA_AV_API_PROTECT_RSP_EVT,
60   BTA_AV_API_RC_OPEN_EVT,
61   BTA_AV_SRC_DATA_READY_EVT,
62   BTA_AV_CI_SETCONFIG_OK_EVT,
63   BTA_AV_CI_SETCONFIG_FAIL_EVT,
64   BTA_AV_SDP_DISC_OK_EVT,
65   BTA_AV_SDP_DISC_FAIL_EVT,
66   BTA_AV_STR_DISC_OK_EVT,
67   BTA_AV_STR_DISC_FAIL_EVT,
68   BTA_AV_STR_GETCAP_OK_EVT,
69   BTA_AV_STR_GETCAP_FAIL_EVT,
70   BTA_AV_STR_OPEN_OK_EVT,
71   BTA_AV_STR_OPEN_FAIL_EVT,
72   BTA_AV_STR_START_OK_EVT,
73   BTA_AV_STR_START_FAIL_EVT,
74   BTA_AV_STR_CLOSE_EVT,
75   BTA_AV_STR_CONFIG_IND_EVT,
76   BTA_AV_STR_SECURITY_IND_EVT,
77   BTA_AV_STR_SECURITY_CFM_EVT,
78   BTA_AV_STR_WRITE_CFM_EVT,
79   BTA_AV_STR_SUSPEND_CFM_EVT,
80   BTA_AV_STR_RECONFIG_CFM_EVT,
81   BTA_AV_AVRC_TIMER_EVT,
82   BTA_AV_AVDT_CONNECT_EVT,
83   BTA_AV_AVDT_DISCONNECT_EVT,
84   BTA_AV_ROLE_CHANGE_EVT,
85   BTA_AV_AVDT_DELAY_RPT_EVT,
86   BTA_AV_ACP_CONNECT_EVT,
87   BTA_AV_API_OFFLOAD_START_EVT,
88   BTA_AV_API_OFFLOAD_START_RSP_EVT,
89 
90   /* these events are handled outside of the state machine */
91   BTA_AV_API_ENABLE_EVT,
92   BTA_AV_API_REGISTER_EVT,
93   BTA_AV_API_DEREGISTER_EVT,
94   BTA_AV_API_DISCONNECT_EVT,
95   BTA_AV_CI_SRC_DATA_READY_EVT,
96   BTA_AV_SIG_CHG_EVT,
97   BTA_AV_SIGNALLING_TIMER_EVT,
98   BTA_AV_SDP_AVRC_DISC_EVT,
99   BTA_AV_AVRC_CLOSE_EVT,
100   BTA_AV_AVRC_BROWSE_OPEN_EVT,
101   BTA_AV_AVRC_BROWSE_CLOSE_EVT,
102   BTA_AV_CONN_CHG_EVT,
103   BTA_AV_DEREG_COMP_EVT,
104 #if (AVDT_REPORTING == TRUE)
105   BTA_AV_AVDT_RPT_CONN_EVT,
106 #endif
107   BTA_AV_API_START_EVT, /* the following 2 events must be in the same order as
108                            the *AP_*EVT */
109   BTA_AV_API_STOP_EVT
110 };
111 
112 /* events for AV control block state machine */
113 #define BTA_AV_FIRST_SM_EVT BTA_AV_API_DISABLE_EVT
114 #define BTA_AV_LAST_SM_EVT BTA_AV_AVRC_NONE_EVT
115 
116 /* events for AV stream control block state machine */
117 #define BTA_AV_FIRST_SSM_EVT BTA_AV_API_OPEN_EVT
118 
119 /* events that do not go through state machine */
120 #define BTA_AV_FIRST_NSM_EVT BTA_AV_API_ENABLE_EVT
121 #define BTA_AV_LAST_NSM_EVT BTA_AV_API_STOP_EVT
122 
123 /* API events passed to both SSMs (by bta_av_api_to_ssm) */
124 #define BTA_AV_FIRST_A2S_API_EVT BTA_AV_API_START_EVT
125 #define BTA_AV_FIRST_A2S_SSM_EVT BTA_AV_AP_START_EVT
126 
127 #define BTA_AV_LAST_EVT BTA_AV_API_STOP_EVT
128 
129 /* maximum number of SEPS in stream discovery results */
130 #define BTA_AV_NUM_SEPS 32
131 
132 /* initialization value for AVRC handle */
133 #define BTA_AV_RC_HANDLE_NONE 0xFF
134 
135 /* size of database for service discovery */
136 #define BTA_AV_DISC_BUF_SIZE 1000
137 
138 /* maximum length of AVDTP security data */
139 #define BTA_AV_SECURITY_MAX_LEN 400
140 
141 /* check number of buffers queued at L2CAP when this amount of buffers are
142  * queued to L2CAP */
143 #define BTA_AV_QUEUE_DATA_CHK_NUM L2CAP_HIGH_PRI_MIN_XMIT_QUOTA
144 
145 /* the number of ACL links with AVDT */
146 #define BTA_AV_NUM_LINKS AVDT_NUM_LINKS
147 
148 #define BTA_AV_BE_STREAM_TO_CO_ID(u32, p)                                 \
149   {                                                                       \
150     (u32) = (((uint32_t)(*((p) + 2))) + (((uint32_t)(*((p) + 1))) << 8) + \
151              (((uint32_t)(*(p))) << 16));                                 \
152     (p) += 3;                                                             \
153   }
154 
155 /*****************************************************************************
156  *  Data types
157  ****************************************************************************/
158 
159 /* function types for call-out functions */
160 typedef bool (*tBTA_AV_CO_INIT)(btav_a2dp_codec_index_t codec_index,
161                                 tAVDT_CFG* p_cfg);
162 typedef void (*tBTA_AV_CO_DISC_RES)(tBTA_AV_HNDL hndl, uint8_t num_seps,
163                                     uint8_t num_snk, uint8_t num_src,
164                                     BD_ADDR addr, uint16_t uuid_local);
165 typedef tA2DP_STATUS (*tBTA_AV_CO_GETCFG)(tBTA_AV_HNDL hndl,
166                                           uint8_t* p_codec_info,
167                                           uint8_t* p_sep_info_idx, uint8_t seid,
168                                           uint8_t* p_num_protect,
169                                           uint8_t* p_protect_info);
170 typedef void (*tBTA_AV_CO_SETCFG)(tBTA_AV_HNDL hndl,
171                                   const uint8_t* p_codec_info, uint8_t seid,
172                                   BD_ADDR addr, uint8_t num_protect,
173                                   const uint8_t* p_protect_info,
174                                   uint8_t t_local_sep, uint8_t avdt_handle);
175 typedef void (*tBTA_AV_CO_OPEN)(tBTA_AV_HNDL hndl, uint16_t mtu);
176 typedef void (*tBTA_AV_CO_CLOSE)(tBTA_AV_HNDL hndl);
177 typedef void (*tBTA_AV_CO_START)(tBTA_AV_HNDL hndl, uint8_t* p_codec_info,
178                                  bool* p_no_rtp_hdr);
179 typedef void (*tBTA_AV_CO_STOP)(tBTA_AV_HNDL hndl);
180 typedef void* (*tBTA_AV_CO_DATAPATH)(const uint8_t* p_codec_info,
181                                      uint32_t* p_timestamp);
182 typedef void (*tBTA_AV_CO_DELAY)(tBTA_AV_HNDL hndl, uint16_t delay);
183 typedef void (*tBTA_AV_CO_UPDATE_MTU)(tBTA_AV_HNDL hndl, uint16_t mtu);
184 
185 /* the call-out functions for one stream */
186 typedef struct {
187   tBTA_AV_CO_INIT init;
188   tBTA_AV_CO_DISC_RES disc_res;
189   tBTA_AV_CO_GETCFG getcfg;
190   tBTA_AV_CO_SETCFG setcfg;
191   tBTA_AV_CO_OPEN open;
192   tBTA_AV_CO_CLOSE close;
193   tBTA_AV_CO_START start;
194   tBTA_AV_CO_STOP stop;
195   tBTA_AV_CO_DATAPATH data;
196   tBTA_AV_CO_DELAY delay;
197   tBTA_AV_CO_UPDATE_MTU update_mtu;
198 } tBTA_AV_CO_FUNCTS;
199 
200 /* data type for BTA_AV_API_ENABLE_EVT */
201 typedef struct {
202   BT_HDR hdr;
203   tBTA_AV_CBACK* p_cback;
204   tBTA_AV_FEAT features;
205   tBTA_SEC sec_mask;
206 } tBTA_AV_API_ENABLE;
207 
208 /* data type for BTA_AV_API_REGISTER_EVT */
209 typedef struct {
210   BT_HDR hdr;
211   char p_service_name[BTA_SERVICE_NAME_LEN + 1];
212   uint8_t app_id;
213   tBTA_AV_SINK_DATA_CBACK* p_app_sink_data_cback;
214   uint16_t service_uuid;
215 } tBTA_AV_API_REG;
216 
217 enum {
218   BTA_AV_RS_NONE, /* straight API call */
219   BTA_AV_RS_OK,   /* the role switch result - successful */
220   BTA_AV_RS_FAIL, /* the role switch result - failed */
221   BTA_AV_RS_DONE  /* the role switch is done - continue */
222 };
223 typedef uint8_t tBTA_AV_RS_RES;
224 /* data type for BTA_AV_API_OPEN_EVT */
225 typedef struct {
226   BT_HDR hdr;
227   BD_ADDR bd_addr;
228   bool use_rc;
229   tBTA_SEC sec_mask;
230   tBTA_AV_RS_RES switch_res;
231   uint16_t uuid; /* uuid of initiator */
232 } tBTA_AV_API_OPEN;
233 
234 /* data type for BTA_AV_API_STOP_EVT */
235 typedef struct {
236   BT_HDR hdr;
237   bool suspend;
238   bool flush;
239   bool reconfig_stop;  // True if the stream is stopped for reconfiguration
240 } tBTA_AV_API_STOP;
241 
242 /* data type for BTA_AV_API_DISCONNECT_EVT */
243 typedef struct {
244   BT_HDR hdr;
245   BD_ADDR bd_addr;
246 } tBTA_AV_API_DISCNT;
247 
248 /* data type for BTA_AV_API_PROTECT_REQ_EVT */
249 typedef struct {
250   BT_HDR hdr;
251   uint8_t* p_data;
252   uint16_t len;
253 } tBTA_AV_API_PROTECT_REQ;
254 
255 /* data type for BTA_AV_API_PROTECT_RSP_EVT */
256 typedef struct {
257   BT_HDR hdr;
258   uint8_t* p_data;
259   uint16_t len;
260   uint8_t error_code;
261 } tBTA_AV_API_PROTECT_RSP;
262 
263 /* data type for BTA_AV_API_REMOTE_CMD_EVT */
264 typedef struct {
265   BT_HDR hdr;
266   tAVRC_MSG_PASS msg;
267   uint8_t label;
268 } tBTA_AV_API_REMOTE_CMD;
269 
270 /* data type for BTA_AV_API_VENDOR_CMD_EVT and RSP */
271 typedef struct {
272   BT_HDR hdr;
273   tAVRC_MSG_VENDOR msg;
274   uint8_t label;
275 } tBTA_AV_API_VENDOR;
276 
277 /* data type for BTA_AV_API_RC_OPEN_EVT */
278 typedef struct { BT_HDR hdr; } tBTA_AV_API_OPEN_RC;
279 
280 /* data type for BTA_AV_API_RC_CLOSE_EVT */
281 typedef struct { BT_HDR hdr; } tBTA_AV_API_CLOSE_RC;
282 
283 /* data type for BTA_AV_API_META_RSP_EVT */
284 typedef struct {
285   BT_HDR hdr;
286   bool is_rsp;
287   uint8_t label;
288   tBTA_AV_CODE rsp_code;
289   BT_HDR* p_pkt;
290 } tBTA_AV_API_META_RSP;
291 
292 /* data type for BTA_AV_API_RECONFIG_EVT */
293 typedef struct {
294   BT_HDR hdr;
295   uint8_t codec_info[AVDT_CODEC_SIZE]; /* codec configuration */
296   uint8_t* p_protect_info;
297   uint8_t num_protect;
298   bool suspend;
299   uint8_t sep_info_idx;
300 } tBTA_AV_API_RCFG;
301 
302 /* data type for BTA_AV_CI_SETCONFIG_OK_EVT and BTA_AV_CI_SETCONFIG_FAIL_EVT */
303 typedef struct {
304   BT_HDR hdr;
305   tBTA_AV_HNDL hndl;
306   uint8_t err_code;
307   uint8_t category;
308   uint8_t num_seid;
309   uint8_t* p_seid;
310   bool recfg_needed;
311   uint8_t avdt_handle; /* local sep type for which this stream will be set up */
312 } tBTA_AV_CI_SETCONFIG;
313 
314 /* data type for all stream events from AVDTP */
315 typedef struct {
316   BT_HDR hdr;
317   tAVDT_CFG cfg;   /* configuration/capabilities parameters */
318   tAVDT_CTRL msg;  /* AVDTP callback message parameters */
319   BD_ADDR bd_addr; /* bd address */
320   uint8_t handle;
321   uint8_t avdt_event;
322   bool initiator; /* true, if local device initiates the SUSPEND */
323 } tBTA_AV_STR_MSG;
324 
325 /* data type for BTA_AV_AVRC_MSG_EVT */
326 typedef struct {
327   BT_HDR hdr;
328   tAVRC_MSG msg;
329   uint8_t handle;
330   uint8_t label;
331   uint8_t opcode;
332 } tBTA_AV_RC_MSG;
333 
334 /* data type for BTA_AV_AVRC_OPEN_EVT, BTA_AV_AVRC_CLOSE_EVT */
335 typedef struct {
336   BT_HDR hdr;
337   BD_ADDR peer_addr;
338   uint8_t handle;
339 } tBTA_AV_RC_CONN_CHG;
340 
341 /* data type for BTA_AV_CONN_CHG_EVT */
342 typedef struct {
343   BT_HDR hdr;
344   BD_ADDR peer_addr;
345   bool is_up;
346 } tBTA_AV_CONN_CHG;
347 
348 /* data type for BTA_AV_ROLE_CHANGE_EVT */
349 typedef struct {
350   BT_HDR hdr;
351   uint8_t new_role;
352   uint8_t hci_status;
353 } tBTA_AV_ROLE_RES;
354 
355 /* data type for BTA_AV_SDP_DISC_OK_EVT */
356 typedef struct {
357   BT_HDR hdr;
358   uint16_t avdt_version; /* AVDTP protocol version */
359 } tBTA_AV_SDP_RES;
360 
361 /* data type for BTA_AV_API_OFFLOAD_RSP_EVT */
362 typedef struct {
363   BT_HDR hdr;
364   tBTA_AV_STATUS status;
365 } tBTA_AV_API_STATUS_RSP;
366 
367 /* type for SEP control block */
368 typedef struct {
369   uint8_t av_handle;                   /* AVDTP handle */
370   uint8_t tsep;                        /* SEP type of local SEP */
371   uint8_t codec_info[AVDT_CODEC_SIZE]; /* Codec info */
372   tBTA_AV_SINK_DATA_CBACK*
373       p_app_sink_data_cback; /* Sink application callback for media packets */
374 } tBTA_AV_SEP;
375 
376 /* initiator/acceptor role for adaption */
377 #define BTA_AV_ROLE_AD_INT 0x00 /* initiator */
378 #define BTA_AV_ROLE_AD_ACP 0x01 /* acceptor */
379 
380 /* initiator/acceptor signaling roles */
381 #define BTA_AV_ROLE_START_ACP 0x00
382 #define BTA_AV_ROLE_START_INT 0x10 /* do not change this value */
383 
384 #define BTA_AV_ROLE_SUSPEND 0x20     /* suspending on start */
385 #define BTA_AV_ROLE_SUSPEND_OPT 0x40 /* Suspend on Start option is set */
386 
387 /* union of all event datatypes */
388 typedef union {
389   BT_HDR hdr;
390   tBTA_AV_API_ENABLE api_enable;
391   tBTA_AV_API_REG api_reg;
392   tBTA_AV_API_OPEN api_open;
393   tBTA_AV_API_STOP api_stop;
394   tBTA_AV_API_DISCNT api_discnt;
395   tBTA_AV_API_PROTECT_REQ api_protect_req;
396   tBTA_AV_API_PROTECT_RSP api_protect_rsp;
397   tBTA_AV_API_REMOTE_CMD api_remote_cmd;
398   tBTA_AV_API_VENDOR api_vendor;
399   tBTA_AV_API_RCFG api_reconfig;
400   tBTA_AV_CI_SETCONFIG ci_setconfig;
401   tBTA_AV_STR_MSG str_msg;
402   tBTA_AV_RC_MSG rc_msg;
403   tBTA_AV_RC_CONN_CHG rc_conn_chg;
404   tBTA_AV_CONN_CHG conn_chg;
405   tBTA_AV_ROLE_RES role_res;
406   tBTA_AV_SDP_RES sdp_res;
407   tBTA_AV_API_META_RSP api_meta_rsp;
408   tBTA_AV_API_STATUS_RSP api_status_rsp;
409 } tBTA_AV_DATA;
410 
411 typedef union {
412   tBTA_AV_API_OPEN open; /* used only before open and role switch
413                             is needed on another AV channel */
414 } tBTA_AV_Q_INFO;
415 
416 #define BTA_AV_Q_TAG_OPEN 0x01   /* after API_OPEN, before STR_OPENED */
417 #define BTA_AV_Q_TAG_START 0x02  /* before start sending media packets */
418 #define BTA_AV_Q_TAG_STREAM 0x03 /* during streaming */
419 
420 #define BTA_AV_WAIT_ACP_CAPS_ON 0x01 /* retriving the peer capabilities */
421 #define BTA_AV_WAIT_ACP_CAPS_STARTED \
422   0x02 /* started while retriving peer capabilities */
423 #define BTA_AV_WAIT_ROLE_SW_RES_OPEN \
424   0x04 /* waiting for role switch result after API_OPEN, before STR_OPENED */
425 #define BTA_AV_WAIT_ROLE_SW_RES_START \
426   0x08 /* waiting for role switch result before streaming */
427 #define BTA_AV_WAIT_ROLE_SW_STARTED \
428   0x10 /* started while waiting for role switch result */
429 #define BTA_AV_WAIT_ROLE_SW_RETRY 0x20 /* set when retry on timeout */
430 #define BTA_AV_WAIT_CHECK_RC \
431   0x40 /* set when the timer is used by role switch */
432 #define BTA_AV_WAIT_ROLE_SW_FAILED 0x80 /* role switch failed */
433 
434 #define BTA_AV_WAIT_ROLE_SW_BITS                                  \
435   (BTA_AV_WAIT_ROLE_SW_RES_OPEN | BTA_AV_WAIT_ROLE_SW_RES_START | \
436    BTA_AV_WAIT_ROLE_SW_STARTED | BTA_AV_WAIT_ROLE_SW_RETRY)
437 
438 /* Bitmap for collision, coll_mask */
439 #define BTA_AV_COLL_INC_TMR \
440   0x01 /* Timer is running for incoming L2C connection */
441 #define BTA_AV_COLL_API_CALLED \
442   0x02 /* API open was called while incoming timer is running */
443 
444 /* type for AV stream control block */
445 typedef struct {
446   const tBTA_AV_ACT* p_act_tbl; /* the action table for stream state machine */
447   const tBTA_AV_CO_FUNCTS* p_cos; /* the associated callout functions */
448   bool sdp_discovery_started; /* variable to determine whether SDP is started */
449   tBTA_AV_SEP seps[BTAV_A2DP_CODEC_INDEX_MAX];
450   tAVDT_CFG* p_cap;  /* buffer used for get capabilities */
451   list_t* a2dp_list; /* used for audio channels only */
452   tBTA_AV_Q_INFO q_info;
453   tAVDT_SEP_INFO sep_info[BTA_AV_NUM_SEPS]; /* stream discovery results */
454   tAVDT_CFG cfg;                            /* local SEP configuration */
455   alarm_t* avrc_ct_timer;                   /* delay timer for AVRC CT */
456   BD_ADDR peer_addr;                        /* peer BD address */
457   uint16_t l2c_cid;                         /* L2CAP channel ID */
458   uint16_t stream_mtu;                      /* MTU of stream */
459   uint16_t avdt_version;      /* the avdt version of peer device */
460   tBTA_SEC sec_mask;          /* security mask */
461   uint8_t media_type;         /* Media type: AVDT_MEDIA_TYPE_* */
462   bool cong;                  /* true if AVDTP congested */
463   tBTA_AV_STATUS open_status; /* open failure status */
464   tBTA_AV_CHNL chnl;          /* the channel: audio/video */
465   tBTA_AV_HNDL hndl;          /* the handle: ((hdi + 1)|chnl) */
466   uint16_t cur_psc_mask;      /* Protocol service capabilities mask for current
467                                  connection */
468   uint8_t avdt_handle;        /* AVDTP handle */
469   uint8_t hdi;                /* the index to SCB[] */
470   uint8_t num_seps;           /* number of seps returned by stream discovery */
471   uint8_t num_disc_snks;      /* number of discovered snks */
472   uint8_t num_disc_srcs;      /* number of discovered srcs */
473   uint8_t sep_info_idx;       /* current index into sep_info */
474   uint8_t sep_idx;            /* current index into local seps[] */
475   uint8_t rcfg_idx;           /* reconfig requested index into sep_info */
476   uint8_t state;              /* state machine state */
477   uint8_t avdt_label;         /* AVDTP label */
478   uint8_t app_id;             /* application id */
479   uint8_t num_recfg;          /* number of reconfigure sent */
480   uint8_t role;
481   uint8_t l2c_bufs;  /* the number of buffers queued to L2CAP */
482   uint8_t rc_handle; /* connected AVRCP handle */
483   bool use_rc;       /* true if AVRCP is allowed */
484   bool started;      /* true if stream started */
485   A2dpCodecConfig* current_codec; /* The current A2DP codec */
486   uint8_t
487       co_started;    /* non-zero, if stream started from call-out perspective */
488   bool recfg_sup;    /* true if the first attempt to reconfigure the stream was
489                         successfull, else False if command fails */
490   bool suspend_sup;  /* true if Suspend stream is supported, else false if
491                         suspend command fails */
492   bool deregistring; /* true if deregistering */
493   bool sco_suspend;  /* true if SUSPEND is issued automatically for SCO */
494   uint8_t coll_mask; /* Mask to check incoming and outgoing collision */
495   tBTA_AV_API_OPEN open_api; /* Saved OPEN api message */
496   uint8_t wait;  /* set 0x1, when getting Caps as ACP, set 0x2, when started */
497   uint8_t q_tag; /* identify the associated q_info union member */
498   bool no_rtp_hdr;   /* true if add no RTP header*/
499   uint16_t uuid_int; /*intended UUID of Initiator to connect to */
500   bool offload_start_pending;
501   bool skip_sdp; /* Decides if sdp to be done prior to profile connection */
502 } tBTA_AV_SCB;
503 
504 #define BTA_AV_RC_ROLE_MASK 0x10
505 #define BTA_AV_RC_ROLE_INT 0x00
506 #define BTA_AV_RC_ROLE_ACP 0x10
507 
508 #define BTA_AV_RC_CONN_MASK 0x20
509 
510 /* type for AV RCP control block */
511 /* index to this control block is the rc handle */
512 typedef struct {
513   uint8_t status;
514   uint8_t handle;
515   uint8_t shdl;               /* stream handle (hdi + 1) */
516   uint8_t lidx;               /* (index+1) to LCB */
517   tBTA_AV_FEAT peer_features; /* peer features mask */
518 } tBTA_AV_RCB;
519 #define BTA_AV_NUM_RCB (BTA_AV_NUM_STRS + 2)
520 
521 enum { BTA_AV_LCB_FREE, BTA_AV_LCB_FIND };
522 
523 /* type for AV ACL Link control block */
524 typedef struct {
525   BD_ADDR addr;     /* peer BD address */
526   uint8_t conn_msk; /* handle mask of connected stream handle */
527   uint8_t lidx;     /* index + 1 */
528 } tBTA_AV_LCB;
529 
530 /* type for stream state machine action functions */
531 typedef void (*tBTA_AV_SACT)(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data);
532 
533 /* type for AV control block */
534 typedef struct {
535   tBTA_AV_SCB* p_scb[BTA_AV_NUM_STRS];   /* stream control block */
536   tSDP_DISCOVERY_DB* p_disc_db;          /* pointer to discovery database */
537   tBTA_AV_CBACK* p_cback;                /* application callback function */
538   tBTA_AV_RCB rcb[BTA_AV_NUM_RCB];       /* RCB control block */
539   tBTA_AV_LCB lcb[BTA_AV_NUM_LINKS + 1]; /* link control block */
540   alarm_t* link_signalling_timer;
541   alarm_t*
542       accept_signalling_timer;  /* timer to monitor signalling when accepting */
543   uint32_t sdp_a2dp_handle;     /* SDP record handle for audio src */
544   uint32_t sdp_a2dp_snk_handle; /* SDP record handle for audio snk */
545   uint32_t sdp_vdp_handle;      /* SDP record handle for video src */
546   tBTA_AV_FEAT features;        /* features mask */
547   tBTA_SEC sec_mask;            /* security mask */
548   tBTA_AV_HNDL handle;          /* the handle for SDP activity */
549   bool disabling;               /* true if api disabled called */
550   uint8_t
551       disc; /* (hdi+1) or (rc_handle|BTA_AV_CHNL_MSK) if p_disc_db is in use */
552   uint8_t state;          /* state machine state */
553   uint8_t conn_rc;        /* handle mask of connected RCP channels */
554   uint8_t conn_audio;     /* handle mask of connected audio channels */
555   uint8_t conn_video;     /* handle mask of connected video channels */
556   uint8_t conn_lcb;       /* index mask of used LCBs */
557   uint8_t audio_open_cnt; /* number of connected audio channels */
558   uint8_t reg_audio;      /* handle mask of registered audio channels */
559   uint8_t reg_video;      /* handle mask of registered video channels */
560   uint8_t rc_acp_handle;
561   uint8_t rc_acp_idx; /* (index + 1) to RCB */
562   uint8_t rs_idx;    /* (index + 1) to SCB for the one waiting for RS on open */
563   bool sco_occupied; /* true if SCO is being used or call is in progress */
564   uint8_t audio_streams; /* handle mask of streaming audio channels */
565   uint8_t video_streams; /* handle mask of streaming video channels */
566 } tBTA_AV_CB;
567 
568 /*****************************************************************************
569  *  Global data
570  ****************************************************************************/
571 
572 /* control block declaration */
573 extern tBTA_AV_CB bta_av_cb;
574 
575 /* config struct */
576 extern tBTA_AV_CFG* p_bta_av_cfg;
577 extern const tBTA_AV_CFG bta_avk_cfg;
578 extern const tBTA_AV_CFG bta_av_cfg;
579 
580 /* rc id config struct */
581 extern uint16_t* p_bta_av_rc_id;
582 extern uint16_t* p_bta_av_rc_id_ac;
583 
584 extern const tBTA_AV_SACT bta_av_a2dp_action[];
585 extern const tBTA_AV_CO_FUNCTS bta_av_a2dp_cos;
586 extern tAVDT_CTRL_CBACK* const bta_av_dt_cback[];
587 extern void bta_av_sink_data_cback(uint8_t handle, BT_HDR* p_pkt,
588                                    uint32_t time_stamp, uint8_t m_pt);
589 
590 /*****************************************************************************
591  *  Function prototypes
592  ****************************************************************************/
593 /* utility functions */
594 extern tBTA_AV_SCB* bta_av_hndl_to_scb(uint16_t handle);
595 extern bool bta_av_chk_start(tBTA_AV_SCB* p_scb);
596 extern void bta_av_restore_switch(void);
597 extern uint16_t bta_av_chk_mtu(tBTA_AV_SCB* p_scb, uint16_t mtu);
598 extern void bta_av_conn_cback(uint8_t handle, BD_ADDR bd_addr, uint8_t event,
599                               tAVDT_CTRL* p_data);
600 extern uint8_t bta_av_rc_create(tBTA_AV_CB* p_cb, uint8_t role, uint8_t shdl,
601                                 uint8_t lidx);
602 extern void bta_av_stream_chg(tBTA_AV_SCB* p_scb, bool started);
603 extern bool bta_av_is_scb_opening(tBTA_AV_SCB* p_scb);
604 extern bool bta_av_is_scb_incoming(tBTA_AV_SCB* p_scb);
605 extern void bta_av_set_scb_sst_init(tBTA_AV_SCB* p_scb);
606 extern bool bta_av_is_scb_init(tBTA_AV_SCB* p_scb);
607 extern void bta_av_set_scb_sst_incoming(tBTA_AV_SCB* p_scb);
608 extern tBTA_AV_LCB* bta_av_find_lcb(BD_ADDR addr, uint8_t op);
609 
610 /* main functions */
611 extern void bta_av_api_deregister(tBTA_AV_DATA* p_data);
612 extern void bta_av_dup_audio_buf(tBTA_AV_SCB* p_scb, BT_HDR* p_buf);
613 extern void bta_av_sm_execute(tBTA_AV_CB* p_cb, uint16_t event,
614                               tBTA_AV_DATA* p_data);
615 extern void bta_av_ssm_execute(tBTA_AV_SCB* p_scb, uint16_t event,
616                                tBTA_AV_DATA* p_data);
617 extern bool bta_av_hdl_event(BT_HDR* p_msg);
618 extern const char* bta_av_evt_code(uint16_t evt_code);
619 extern bool bta_av_switch_if_needed(tBTA_AV_SCB* p_scb);
620 extern bool bta_av_link_role_ok(tBTA_AV_SCB* p_scb, uint8_t bits);
621 extern bool bta_av_is_rcfg_sst(tBTA_AV_SCB* p_scb);
622 
623 /* nsm action functions */
624 extern void bta_av_api_disconnect(tBTA_AV_DATA* p_data);
625 extern void bta_av_sig_chg(tBTA_AV_DATA* p_data);
626 extern void bta_av_signalling_timer(tBTA_AV_DATA* p_data);
627 extern void bta_av_rc_disc_done(tBTA_AV_DATA* p_data);
628 extern void bta_av_rc_closed(tBTA_AV_DATA* p_data);
629 extern void bta_av_rc_browse_opened(tBTA_AV_DATA* p_data);
630 extern void bta_av_rc_browse_closed(tBTA_AV_DATA* p_data);
631 extern void bta_av_rc_disc(uint8_t disc);
632 extern void bta_av_conn_chg(tBTA_AV_DATA* p_data);
633 extern void bta_av_dereg_comp(tBTA_AV_DATA* p_data);
634 
635 /* sm action functions */
636 extern void bta_av_disable(tBTA_AV_CB* p_cb, tBTA_AV_DATA* p_data);
637 extern void bta_av_rc_opened(tBTA_AV_CB* p_cb, tBTA_AV_DATA* p_data);
638 extern void bta_av_rc_remote_cmd(tBTA_AV_CB* p_cb, tBTA_AV_DATA* p_data);
639 extern void bta_av_rc_vendor_cmd(tBTA_AV_CB* p_cb, tBTA_AV_DATA* p_data);
640 extern void bta_av_rc_vendor_rsp(tBTA_AV_CB* p_cb, tBTA_AV_DATA* p_data);
641 extern void bta_av_rc_msg(tBTA_AV_CB* p_cb, tBTA_AV_DATA* p_data);
642 extern void bta_av_rc_close(tBTA_AV_CB* p_cb, tBTA_AV_DATA* p_data);
643 extern void bta_av_rc_meta_rsp(tBTA_AV_CB* p_cb, tBTA_AV_DATA* p_data);
644 extern void bta_av_rc_free_rsp(tBTA_AV_CB* p_cb, tBTA_AV_DATA* p_data);
645 extern void bta_av_rc_free_browse_msg(tBTA_AV_CB* p_cb, tBTA_AV_DATA* p_data);
646 
647 extern tBTA_AV_RCB* bta_av_get_rcb_by_shdl(uint8_t shdl);
648 extern void bta_av_del_rc(tBTA_AV_RCB* p_rcb);
649 
650 /* ssm action functions */
651 extern void bta_av_do_disc_a2dp(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data);
652 extern void bta_av_cleanup(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data);
653 extern void bta_av_free_sdb(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data);
654 extern void bta_av_config_ind(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data);
655 extern void bta_av_disconnect_req(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data);
656 extern void bta_av_security_req(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data);
657 extern void bta_av_security_rsp(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data);
658 extern void bta_av_setconfig_rsp(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data);
659 extern void bta_av_str_opened(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data);
660 extern void bta_av_security_ind(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data);
661 extern void bta_av_security_cfm(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data);
662 extern void bta_av_do_close(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data);
663 extern void bta_av_connect_req(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data);
664 extern void bta_av_sdp_failed(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data);
665 extern void bta_av_disc_results(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data);
666 extern void bta_av_disc_res_as_acp(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data);
667 extern void bta_av_open_failed(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data);
668 extern void bta_av_getcap_results(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data);
669 extern void bta_av_setconfig_rej(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data);
670 extern void bta_av_discover_req(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data);
671 extern void bta_av_conn_failed(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data);
672 extern void bta_av_do_start(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data);
673 extern void bta_av_str_stopped(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data);
674 extern void bta_av_reconfig(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data);
675 extern void bta_av_data_path(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data);
676 extern void bta_av_start_ok(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data);
677 extern void bta_av_start_failed(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data);
678 extern void bta_av_str_closed(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data);
679 extern void bta_av_clr_cong(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data);
680 extern void bta_av_suspend_cfm(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data);
681 extern void bta_av_rcfg_str_ok(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data);
682 extern void bta_av_rcfg_failed(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data);
683 extern void bta_av_rcfg_connect(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data);
684 extern void bta_av_rcfg_discntd(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data);
685 extern void bta_av_suspend_cont(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data);
686 extern void bta_av_rcfg_cfm(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data);
687 extern void bta_av_rcfg_open(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data);
688 extern void bta_av_security_rej(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data);
689 extern void bta_av_open_rc(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data);
690 extern void bta_av_chk_2nd_start(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data);
691 extern void bta_av_save_caps(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data);
692 extern void bta_av_rej_conn(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data);
693 extern void bta_av_rej_conn(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data);
694 extern void bta_av_set_use_rc(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data);
695 extern void bta_av_cco_close(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data);
696 extern void bta_av_switch_role(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data);
697 extern void bta_av_role_res(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data);
698 extern void bta_av_delay_co(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data);
699 extern void bta_av_open_at_inc(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data);
700 extern void bta_av_offload_req(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data);
701 extern void bta_av_offload_rsp(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data);
702 
703 #endif /* BTA_AV_INT_H */
704