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