• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  *  Copyright 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 main implementation file for the BTA advanced audio/video.
22  *
23  ******************************************************************************/
24 
25 #define LOG_TAG "bt_bta_av"
26 
27 #include <base/logging.h>
28 #include <string.h>
29 
30 #include "bt_target.h"
31 #include "osi/include/log.h"
32 #include "osi/include/osi.h"
33 #include "osi/include/properties.h"
34 
35 #include "bta_av_co.h"
36 #include "bta_av_int.h"
37 #include "btif/include/btif_av_co.h"
38 #include "btif/include/btif_config.h"
39 #include "l2c_api.h"
40 #include "l2cdefs.h"
41 #include "utl.h"
42 
43 #if (BTA_AR_INCLUDED == TRUE)
44 #include "bta_ar_api.h"
45 #endif
46 
47 /*****************************************************************************
48  * Constants and types
49  ****************************************************************************/
50 
51 #ifndef BTA_AV_RET_TOUT
52 #define BTA_AV_RET_TOUT 4
53 #endif
54 
55 #ifndef BTA_AV_SIG_TOUT
56 #define BTA_AV_SIG_TOUT 4
57 #endif
58 
59 #ifndef BTA_AV_IDLE_TOUT
60 #define BTA_AV_IDLE_TOUT 10
61 #endif
62 
63 /* the delay time in milliseconds to retry role switch */
64 #ifndef BTA_AV_RS_TIME_VAL
65 #define BTA_AV_RS_TIME_VAL 1000
66 #endif
67 
68 #ifndef AVRCP_VERSION_PROPERTY
69 #define AVRCP_VERSION_PROPERTY "persist.bluetooth.avrcpversion"
70 #endif
71 
72 #ifndef AVRCP_1_6_STRING
73 #define AVRCP_1_6_STRING "avrcp16"
74 #endif
75 
76 #ifndef AVRCP_1_5_STRING
77 #define AVRCP_1_5_STRING "avrcp15"
78 #endif
79 
80 #ifndef AVRCP_1_4_STRING
81 #define AVRCP_1_4_STRING "avrcp14"
82 #endif
83 
84 #ifndef AVRCP_1_3_STRING
85 #define AVRCP_1_3_STRING "avrcp13"
86 #endif
87 
88 #ifndef AVRCP_DEFAULT_VERSION
89 #define AVRCP_DEFAULT_VERSION AVRCP_1_4_STRING
90 #endif
91 
92 /* state machine states */
93 enum { BTA_AV_INIT_ST, BTA_AV_OPEN_ST };
94 
95 /* state machine action enumeration list */
96 enum {
97   BTA_AV_DISABLE,
98   BTA_AV_RC_OPENED,
99   BTA_AV_RC_REMOTE_CMD,
100   BTA_AV_RC_VENDOR_CMD,
101   BTA_AV_RC_VENDOR_RSP,
102   BTA_AV_RC_FREE_RSP,
103   BTA_AV_RC_FREE_BROWSE_MSG,
104   BTA_AV_RC_META_RSP,
105   BTA_AV_RC_MSG,
106   BTA_AV_RC_CLOSE,
107   BTA_AV_RC_BROWSE_CLOSE,
108   BTA_AV_NUM_ACTIONS
109 };
110 
111 #define BTA_AV_IGNORE BTA_AV_NUM_ACTIONS
112 
113 /* type for action functions */
114 typedef void (*tBTA_AV_ACTION)(tBTA_AV_CB* p_cb, tBTA_AV_DATA* p_data);
115 
116 /* action functions */
117 const tBTA_AV_ACTION bta_av_action[] = {
118     bta_av_disable,
119     bta_av_rc_opened,
120     bta_av_rc_remote_cmd,
121     bta_av_rc_vendor_cmd,
122     bta_av_rc_vendor_rsp,
123     bta_av_rc_free_rsp,
124     bta_av_rc_free_browse_msg,
125     bta_av_rc_meta_rsp,
126     bta_av_rc_msg,
127     bta_av_rc_close,
128 };
129 
130 /* state table information */
131 #define BTA_AV_ACTION_COL 0 /* position of actions */
132 #define BTA_AV_NEXT_STATE 1 /* position of next state */
133 #define BTA_AV_NUM_COLS 2   /* number of columns in state tables */
134 
135 /* state table for init state */
136 static const uint8_t bta_av_st_init[][BTA_AV_NUM_COLS] = {
137     /* Event                     Action 1                   Next state */
138     /* API_DISABLE_EVT */ {BTA_AV_DISABLE, BTA_AV_INIT_ST},
139     /* API_REMOTE_CMD_EVT */ {BTA_AV_IGNORE, BTA_AV_INIT_ST},
140     /* API_VENDOR_CMD_EVT */ {BTA_AV_IGNORE, BTA_AV_INIT_ST},
141     /* API_VENDOR_RSP_EVT */ {BTA_AV_IGNORE, BTA_AV_INIT_ST},
142     /* API_META_RSP_EVT */ {BTA_AV_RC_FREE_RSP, BTA_AV_INIT_ST},
143     /* API_RC_CLOSE_EVT */ {BTA_AV_IGNORE, BTA_AV_INIT_ST},
144     /* AVRC_OPEN_EVT */ {BTA_AV_RC_OPENED, BTA_AV_OPEN_ST},
145     /* AVRC_MSG_EVT */ {BTA_AV_RC_FREE_BROWSE_MSG, BTA_AV_INIT_ST},
146     /* AVRC_NONE_EVT */ {BTA_AV_IGNORE, BTA_AV_INIT_ST},
147 };
148 
149 /* state table for open state */
150 static const uint8_t bta_av_st_open[][BTA_AV_NUM_COLS] = {
151     /* Event                     Action 1                   Next state */
152     /* API_DISABLE_EVT */ {BTA_AV_DISABLE, BTA_AV_INIT_ST},
153     /* API_REMOTE_CMD_EVT */ {BTA_AV_RC_REMOTE_CMD, BTA_AV_OPEN_ST},
154     /* API_VENDOR_CMD_EVT */ {BTA_AV_RC_VENDOR_CMD, BTA_AV_OPEN_ST},
155     /* API_VENDOR_RSP_EVT */ {BTA_AV_RC_VENDOR_RSP, BTA_AV_OPEN_ST},
156     /* API_META_RSP_EVT */ {BTA_AV_RC_META_RSP, BTA_AV_OPEN_ST},
157     /* API_RC_CLOSE_EVT */ {BTA_AV_RC_CLOSE, BTA_AV_OPEN_ST},
158     /* AVRC_OPEN_EVT */ {BTA_AV_RC_OPENED, BTA_AV_OPEN_ST},
159     /* AVRC_MSG_EVT */ {BTA_AV_RC_MSG, BTA_AV_OPEN_ST},
160     /* AVRC_NONE_EVT */ {BTA_AV_IGNORE, BTA_AV_INIT_ST},
161 };
162 
163 /* type for state table */
164 typedef const uint8_t (*tBTA_AV_ST_TBL)[BTA_AV_NUM_COLS];
165 
166 /* state table */
167 static const tBTA_AV_ST_TBL bta_av_st_tbl[] = {bta_av_st_init, bta_av_st_open};
168 
169 typedef void (*tBTA_AV_NSM_ACT)(tBTA_AV_DATA* p_data);
170 static void bta_av_api_enable(tBTA_AV_DATA* p_data);
171 static void bta_av_api_register(tBTA_AV_DATA* p_data);
172 static void bta_av_ci_data(tBTA_AV_DATA* p_data);
173 static void bta_av_rpc_conn(tBTA_AV_DATA* p_data);
174 static void bta_av_api_to_ssm(tBTA_AV_DATA* p_data);
175 
176 static void bta_av_sco_chg_cback(tBTA_SYS_CONN_STATUS status, uint8_t id,
177                                  uint8_t app_id, const RawAddress& peer_addr);
178 static void bta_av_sys_rs_cback(tBTA_SYS_CONN_STATUS status, uint8_t id,
179                                 uint8_t app_id, const RawAddress& peer_addr);
180 
181 /* action functions */
182 const tBTA_AV_NSM_ACT bta_av_nsm_act[] = {
183     bta_av_api_enable,       /* BTA_AV_API_ENABLE_EVT */
184     bta_av_api_register,     /* BTA_AV_API_REGISTER_EVT */
185     bta_av_api_deregister,   /* BTA_AV_API_DEREGISTER_EVT */
186     bta_av_api_disconnect,   /* BTA_AV_API_DISCONNECT_EVT */
187     bta_av_ci_data,          /* BTA_AV_CI_SRC_DATA_READY_EVT */
188     bta_av_sig_chg,          /* BTA_AV_SIG_CHG_EVT */
189     bta_av_signalling_timer, /* BTA_AV_SIGNALLING_TIMER_EVT */
190     bta_av_rc_disc_done,     /* BTA_AV_SDP_AVRC_DISC_EVT */
191     bta_av_rc_closed,        /* BTA_AV_AVRC_CLOSE_EVT */
192     bta_av_rc_browse_opened, /* BTA_AV_AVRC_BROWSE_OPEN_EVT */
193     bta_av_rc_browse_closed, /* BTA_AV_AVRC_BROWSE_CLOSE_EVT */
194     bta_av_conn_chg,         /* BTA_AV_CONN_CHG_EVT */
195     bta_av_dereg_comp,       /* BTA_AV_DEREG_COMP_EVT */
196     bta_av_rpc_conn, /* BTA_AV_AVDT_RPT_CONN_EVT */
197     bta_av_api_to_ssm, /* BTA_AV_API_START_EVT */
198     bta_av_api_to_ssm, /* BTA_AV_API_STOP_EVT */
199 };
200 
201 /*****************************************************************************
202  * Global data
203  ****************************************************************************/
204 
205 /* AV control block */
206 tBTA_AV_CB bta_av_cb;
207 
208 static const char* bta_av_st_code(uint8_t state);
209 
210 /*******************************************************************************
211  *
212  * Function         bta_av_api_enable
213  *
214  * Description      Handle an API enable event.
215  *
216  *
217  * Returns          void
218  *
219  ******************************************************************************/
bta_av_api_enable(tBTA_AV_DATA * p_data)220 static void bta_av_api_enable(tBTA_AV_DATA* p_data) {
221   /* initialize control block */
222   memset(&bta_av_cb, 0, sizeof(tBTA_AV_CB));
223 
224   for (int i = 0; i < BTA_AV_NUM_RCB; i++)
225     bta_av_cb.rcb[i].handle = BTA_AV_RC_HANDLE_NONE;
226 
227   bta_av_cb.rc_acp_handle = BTA_AV_RC_HANDLE_NONE;
228 
229   /*
230    * TODO: The "disable" event handling is missing - there we need
231    * to alarm_free() the alarms below.
232    */
233   bta_av_cb.link_signalling_timer = alarm_new("bta_av.link_signalling_timer");
234   bta_av_cb.accept_signalling_timer =
235       alarm_new("bta_av.accept_signalling_timer");
236 
237   /* store parameters */
238   bta_av_cb.p_cback = p_data->api_enable.p_cback;
239   bta_av_cb.features = p_data->api_enable.features;
240   bta_av_cb.sec_mask = p_data->api_enable.sec_mask;
241 
242   tBTA_AV_ENABLE enable;
243   enable.features = bta_av_cb.features;
244 
245   /* Register for SCO change event */
246   if (!(bta_av_cb.features & BTA_AV_FEAT_NO_SCO_SSPD)) {
247     bta_sys_sco_register(bta_av_sco_chg_cback);
248   }
249 
250   /* call callback with enable event */
251   tBTA_AV bta_av_data;
252   bta_av_data.enable = enable;
253   (*bta_av_cb.p_cback)(BTA_AV_ENABLE_EVT, &bta_av_data);
254 }
255 
256 /*******************************************************************************
257  *
258  * Function         bta_av_addr_to_scb
259  *
260  * Description      find the stream control block by the peer addr
261  *
262  * Returns          void
263  *
264  ******************************************************************************/
bta_av_addr_to_scb(const RawAddress & bd_addr)265 static tBTA_AV_SCB* bta_av_addr_to_scb(const RawAddress& bd_addr) {
266   tBTA_AV_SCB* p_scb = NULL;
267   int xx;
268 
269   for (xx = 0; xx < BTA_AV_NUM_STRS; xx++) {
270     if (bta_av_cb.p_scb[xx]) {
271       if (bd_addr == bta_av_cb.p_scb[xx]->PeerAddress()) {
272         p_scb = bta_av_cb.p_scb[xx];
273         break;
274       }
275     }
276   }
277   return p_scb;
278 }
279 
BTA_AvObtainPeerChannelIndex(const RawAddress & peer_address)280 int BTA_AvObtainPeerChannelIndex(const RawAddress& peer_address) {
281   // Find the entry for the peer (if exists)
282   tBTA_AV_SCB* p_scb = bta_av_addr_to_scb(peer_address);
283   if (p_scb != nullptr) {
284     return p_scb->hdi;
285   }
286 
287   // Find the index for an entry that is not used
288   for (int index = 0; index < BTA_AV_NUM_STRS; index++) {
289     tBTA_AV_SCB* p_scb = bta_av_cb.p_scb[index];
290     if (p_scb == nullptr) {
291       continue;
292     }
293     if (p_scb->PeerAddress().IsEmpty()) {
294       return p_scb->hdi;
295     }
296   }
297 
298   return -1;
299 }
300 
301 /*******************************************************************************
302  *
303  * Function         bta_av_hndl_to_scb
304  *
305  * Description      find the stream control block by the handle
306  *
307  * Returns          void
308  *
309  ******************************************************************************/
bta_av_hndl_to_scb(uint16_t handle)310 tBTA_AV_SCB* bta_av_hndl_to_scb(uint16_t handle) {
311   tBTA_AV_HNDL hndl = (tBTA_AV_HNDL)handle;
312   tBTA_AV_SCB* p_scb = NULL;
313   uint8_t idx = (hndl & BTA_AV_HNDL_MSK);
314 
315   if (idx && (idx <= BTA_AV_NUM_STRS)) {
316     p_scb = bta_av_cb.p_scb[idx - 1];
317   }
318   return p_scb;
319 }
320 
321 /*******************************************************************************
322  *
323  * Function         bta_av_alloc_scb
324  *
325  * Description      allocate stream control block,
326  *                  register the service to stack
327  *                  create SDP record
328  *
329  * Returns          void
330  *
331  ******************************************************************************/
bta_av_alloc_scb(tBTA_AV_CHNL chnl)332 static tBTA_AV_SCB* bta_av_alloc_scb(tBTA_AV_CHNL chnl) {
333   if (chnl != BTA_AV_CHNL_AUDIO) {
334     APPL_TRACE_ERROR("%s: bad channel: %d", __func__, chnl);
335     return nullptr;
336   }
337 
338   for (int xx = 0; xx < BTA_AV_NUM_STRS; xx++) {
339     if (bta_av_cb.p_scb[xx] != nullptr) continue;
340     // Found an empty spot
341     // TODO: After tBTA_AV_SCB is changed to a proper class, the entry
342     // here should be allocated by C++ 'new' statement.
343     tBTA_AV_SCB* p_ret = (tBTA_AV_SCB*)osi_calloc(sizeof(tBTA_AV_SCB));
344     p_ret->rc_handle = BTA_AV_RC_HANDLE_NONE;
345     p_ret->chnl = chnl;
346     p_ret->hndl = (tBTA_AV_HNDL)((xx + 1) | chnl);
347     p_ret->hdi = xx;
348     p_ret->a2dp_list = list_new(nullptr);
349     p_ret->avrc_ct_timer = alarm_new("bta_av.avrc_ct_timer");
350     bta_av_cb.p_scb[xx] = p_ret;
351     return p_ret;
352   }
353 
354   return nullptr;
355 }
356 
bta_av_free_scb(tBTA_AV_SCB * p_scb)357 void bta_av_free_scb(tBTA_AV_SCB* p_scb) {
358   if (p_scb == nullptr) return;
359   uint8_t scb_index = p_scb->hdi;
360   CHECK(scb_index < BTA_AV_NUM_STRS);
361 
362   CHECK(p_scb == bta_av_cb.p_scb[scb_index]);
363   bta_av_cb.p_scb[scb_index] = nullptr;
364   alarm_free(p_scb->avrc_ct_timer);
365   // TODO: After tBTA_AV_SCB is changed to a proper class, the entry
366   // here should be de-allocated by C++ 'delete' statement.
367   osi_free(p_scb);
368 }
369 
OnConnected(const RawAddress & peer_address)370 void tBTA_AV_SCB::OnConnected(const RawAddress& peer_address) {
371   peer_address_ = peer_address;
372 
373   if (peer_address.IsEmpty()) {
374     LOG_ERROR(LOG_TAG, "%s: Invalid peer address: %s", __func__,
375               peer_address.ToString().c_str());
376     return;
377   }
378 
379   // Read and restore the AVDTP version from local storage
380   uint16_t avdtp_version = 0;
381   size_t version_value_size = sizeof(avdtp_version);
382   if (!btif_config_get_bin(peer_address_.ToString(), AVDTP_VERSION_CONFIG_KEY,
383                            (uint8_t*)&avdtp_version, &version_value_size)) {
384     LOG_WARN(LOG_TAG, "%s: Failed to read cached peer AVDTP version for %s",
385              __func__, peer_address_.ToString().c_str());
386   } else {
387     SetAvdtpVersion(avdtp_version);
388   }
389 }
390 
OnDisconnected()391 void tBTA_AV_SCB::OnDisconnected() {
392   peer_address_ = RawAddress::kEmpty;
393   SetAvdtpVersion(0);
394 }
395 
SetAvdtpVersion(uint16_t avdtp_version)396 void tBTA_AV_SCB::SetAvdtpVersion(uint16_t avdtp_version) {
397   avdtp_version_ = avdtp_version;
398   LOG_DEBUG(LOG_TAG, "%s: AVDTP version for %s set to 0x%x", __func__,
399             peer_address_.ToString().c_str(), avdtp_version_);
400 }
401 
402 /*******************************************************************************
403  ******************************************************************************/
bta_av_conn_cback(UNUSED_ATTR uint8_t handle,const RawAddress & bd_addr,uint8_t event,tAVDT_CTRL * p_data,uint8_t scb_index)404 void bta_av_conn_cback(UNUSED_ATTR uint8_t handle, const RawAddress& bd_addr,
405                        uint8_t event, tAVDT_CTRL* p_data, uint8_t scb_index) {
406   uint16_t evt = 0;
407   tBTA_AV_SCB* p_scb = NULL;
408 
409 #if (BTA_AR_INCLUDED == TRUE)
410   if (event == BTA_AR_AVDT_CONN_EVT || event == AVDT_CONNECT_IND_EVT ||
411       event == AVDT_DISCONNECT_IND_EVT)
412 #else
413   if (event == AVDT_CONNECT_IND_EVT || event == AVDT_DISCONNECT_IND_EVT)
414 #endif
415   {
416     evt = BTA_AV_SIG_CHG_EVT;
417     if (event == AVDT_DISCONNECT_IND_EVT) {
418       p_scb = bta_av_addr_to_scb(bd_addr);
419     } else if (event == AVDT_CONNECT_IND_EVT) {
420       APPL_TRACE_DEBUG("%s: CONN_IND is ACP:%d", __func__,
421                        p_data->hdr.err_param);
422     }
423 
424     tBTA_AV_STR_MSG* p_msg =
425         (tBTA_AV_STR_MSG*)osi_malloc(sizeof(tBTA_AV_STR_MSG));
426     p_msg->hdr.event = evt;
427     p_msg->hdr.layer_specific = event;
428     p_msg->hdr.offset = p_data->hdr.err_param;
429     p_msg->bd_addr = bd_addr;
430     p_msg->scb_index = scb_index;
431     if (p_scb) {
432       APPL_TRACE_DEBUG("%s: scb hndl x%x, role x%x", __func__, p_scb->hndl,
433                        p_scb->role);
434     }
435     LOG_INFO(LOG_TAG, "%s: conn_cback bd_addr: %s", __func__,
436              bd_addr.ToString().c_str());
437     bta_sys_sendmsg(p_msg);
438   }
439 }
440 
441 /*******************************************************************************
442  *
443  * Function         bta_av_a2dp_report_cback
444  *
445  * Description      A2DP report callback.
446  *
447  * Returns          void
448  *
449  ******************************************************************************/
bta_av_a2dp_report_cback(UNUSED_ATTR uint8_t handle,UNUSED_ATTR AVDT_REPORT_TYPE type,UNUSED_ATTR tAVDT_REPORT_DATA * p_data)450 static void bta_av_a2dp_report_cback(UNUSED_ATTR uint8_t handle,
451                                      UNUSED_ATTR AVDT_REPORT_TYPE type,
452                                      UNUSED_ATTR tAVDT_REPORT_DATA* p_data) {
453   /* Do not need to handle report data for now.
454    * This empty function is here for conformance reasons. */
455 }
456 
457 /*******************************************************************************
458  *
459  * Function         bta_av_api_register
460  *
461  * Description      allocate stream control block,
462  *                  register the service to stack
463  *                  create SDP record
464  *
465  * Returns          void
466  *
467  ******************************************************************************/
bta_av_api_register(tBTA_AV_DATA * p_data)468 static void bta_av_api_register(tBTA_AV_DATA* p_data) {
469   tBTA_AV_REGISTER registr;
470   tBTA_AV_SCB* p_scb; /* stream control block */
471   AvdtpRcb reg;
472   AvdtpStreamConfig avdtp_stream_config;
473   char* p_service_name;
474   tBTA_UTL_COD cod;
475 
476   avdtp_stream_config.Reset();
477 
478   registr.status = BTA_AV_FAIL_RESOURCES;
479   registr.app_id = p_data->api_reg.app_id;
480   registr.chnl = (tBTA_AV_CHNL)p_data->hdr.layer_specific;
481 
482   char avrcp_version[PROPERTY_VALUE_MAX] = {0};
483   osi_property_get(AVRCP_VERSION_PROPERTY, avrcp_version,
484                    AVRCP_DEFAULT_VERSION);
485   LOG_INFO(LOG_TAG, "%s: AVRCP version used for sdp: \"%s\"", __func__,
486            avrcp_version);
487 
488   uint16_t profile_initialized = p_data->api_reg.service_uuid;
489   if (profile_initialized == UUID_SERVCLASS_AUDIO_SINK) {
490     p_bta_av_cfg = &bta_avk_cfg;
491   } else if (profile_initialized == UUID_SERVCLASS_AUDIO_SOURCE) {
492     p_bta_av_cfg = &bta_av_cfg;
493 
494     if (!strncmp(AVRCP_1_3_STRING, avrcp_version, sizeof(AVRCP_1_3_STRING))) {
495       LOG_INFO(LOG_TAG, "%s: AVRCP 1.3 capabilites used", __func__);
496       p_bta_av_cfg = &bta_av_cfg_compatibility;
497     }
498   }
499 
500   APPL_TRACE_DEBUG("%s: profile: 0x%x", __func__, profile_initialized);
501   if (p_bta_av_cfg == NULL) {
502     APPL_TRACE_ERROR("%s: AV configuration is null!", __func__);
503     return;
504   }
505 
506   do {
507     p_scb = bta_av_alloc_scb(registr.chnl);
508     if (p_scb == NULL) {
509       APPL_TRACE_ERROR("%s: failed to alloc SCB", __func__);
510       break;
511     }
512 
513     registr.hndl = p_scb->hndl;
514     p_scb->app_id = registr.app_id;
515 
516     /* initialize the stream control block */
517     registr.status = BTA_AV_SUCCESS;
518 
519     if (bta_av_cb.reg_audio == 0) {
520       /* the first channel registered. register to AVDTP */
521       reg.ctrl_mtu = p_bta_av_cfg->sig_mtu;
522       reg.ret_tout = BTA_AV_RET_TOUT;
523       reg.sig_tout = BTA_AV_SIG_TOUT;
524       reg.idle_tout = BTA_AV_IDLE_TOUT;
525       reg.sec_mask = bta_av_cb.sec_mask;
526       reg.scb_index = p_scb->hdi;
527 #if (BTA_AR_INCLUDED == TRUE)
528       bta_ar_reg_avdt(&reg, bta_av_conn_cback, BTA_ID_AV);
529 #endif
530       bta_sys_role_chg_register(&bta_av_sys_rs_cback);
531 
532       /* create remote control TG service if required */
533       if (bta_av_cb.features & (BTA_AV_FEAT_RCTG)) {
534 /* register with no authorization; let AVDTP use authorization instead */
535 #if (BTA_AR_INCLUDED == TRUE)
536 #if (BTA_AV_WITH_AVCTP_AUTHORIZATION == TRUE)
537         bta_ar_reg_avct(p_bta_av_cfg->avrc_mtu, p_bta_av_cfg->avrc_br_mtu,
538                         bta_av_cb.sec_mask, BTA_ID_AV);
539 #else
540         bta_ar_reg_avct(p_bta_av_cfg->avrc_mtu, p_bta_av_cfg->avrc_br_mtu,
541                         (uint8_t)(bta_av_cb.sec_mask & (~BTA_SEC_AUTHORIZE)),
542                         BTA_ID_AV);
543 #endif
544 
545         /* For the Audio Sink role we support additional TG to support
546          * absolute volume.
547          */
548         uint16_t profile_version = AVRC_REV_1_0;
549 
550         if (!strncmp(AVRCP_1_6_STRING, avrcp_version,
551                      sizeof(AVRCP_1_6_STRING))) {
552           profile_version = AVRC_REV_1_6;
553         } else if (!strncmp(AVRCP_1_5_STRING, avrcp_version,
554                             sizeof(AVRCP_1_5_STRING))) {
555           profile_version = AVRC_REV_1_5;
556         } else if (!strncmp(AVRCP_1_3_STRING, avrcp_version,
557                             sizeof(AVRCP_1_3_STRING))) {
558           profile_version = AVRC_REV_1_3;
559         } else {
560           profile_version = AVRC_REV_1_4;
561         }
562 
563         bta_ar_reg_avrc(
564             UUID_SERVCLASS_AV_REM_CTRL_TARGET, "AV Remote Control Target", NULL,
565             p_bta_av_cfg->avrc_tg_cat, BTA_ID_AV,
566             (bta_av_cb.features & BTA_AV_FEAT_BROWSE), profile_version);
567 #endif
568       }
569 
570       /* Set the Capturing service class bit */
571       if (profile_initialized == UUID_SERVCLASS_AUDIO_SOURCE)
572         cod.service = BTM_COD_SERVICE_CAPTURING;
573       else if (profile_initialized == UUID_SERVCLASS_AUDIO_SINK)
574         cod.service = BTM_COD_SERVICE_RENDERING;
575       utl_set_device_class(&cod, BTA_UTL_SET_COD_SERVICE_CLASS);
576     } /* if 1st channel */
577 
578     /* get stream configuration and create stream */
579     avdtp_stream_config.cfg.num_codec = 1;
580     avdtp_stream_config.nsc_mask = AvdtpStreamConfig::AVDT_NSC_RECONFIG;
581     if (!(bta_av_cb.features & BTA_AV_FEAT_PROTECT)) {
582       avdtp_stream_config.nsc_mask |= AvdtpStreamConfig::AVDT_NSC_SECURITY;
583     }
584     APPL_TRACE_DEBUG("%s: nsc_mask: 0x%x", __func__,
585                      avdtp_stream_config.nsc_mask);
586 
587     if (p_data->api_reg.p_service_name[0] == 0) {
588       p_service_name = NULL;
589     } else {
590       p_service_name = p_data->api_reg.p_service_name;
591     }
592 
593     p_scb->suspend_sup = true;
594     p_scb->recfg_sup = true;
595 
596     avdtp_stream_config.scb_index = p_scb->hdi;
597     avdtp_stream_config.p_avdt_ctrl_cback = &bta_av_proc_stream_evt;
598 
599     /* set up the audio stream control block */
600     p_scb->p_act_tbl = (const tBTA_AV_ACT*)bta_av_a2dp_action;
601     p_scb->p_cos = &bta_av_a2dp_cos;
602     p_scb->media_type = AVDT_MEDIA_TYPE_AUDIO;
603     avdtp_stream_config.cfg.psc_mask = AVDT_PSC_TRANS;
604     avdtp_stream_config.media_type = AVDT_MEDIA_TYPE_AUDIO;
605     avdtp_stream_config.mtu = p_bta_av_cfg->audio_mtu;
606     avdtp_stream_config.flush_to = L2CAP_DEFAULT_FLUSH_TO;
607     btav_a2dp_codec_index_t codec_index_min = BTAV_A2DP_CODEC_INDEX_SOURCE_MIN;
608     btav_a2dp_codec_index_t codec_index_max = BTAV_A2DP_CODEC_INDEX_SOURCE_MAX;
609 
610     if (bta_av_cb.features & BTA_AV_FEAT_REPORT) {
611       avdtp_stream_config.cfg.psc_mask |= AVDT_PSC_REPORT;
612       avdtp_stream_config.p_report_cback = bta_av_a2dp_report_cback;
613     }
614     if (bta_av_cb.features & BTA_AV_FEAT_DELAY_RPT)
615       avdtp_stream_config.cfg.psc_mask |= AVDT_PSC_DELAY_RPT;
616 
617     if (profile_initialized == UUID_SERVCLASS_AUDIO_SOURCE) {
618       avdtp_stream_config.tsep = AVDT_TSEP_SRC;
619       codec_index_min = BTAV_A2DP_CODEC_INDEX_SOURCE_MIN;
620       codec_index_max = BTAV_A2DP_CODEC_INDEX_SOURCE_MAX;
621     } else if (profile_initialized == UUID_SERVCLASS_AUDIO_SINK) {
622       avdtp_stream_config.tsep = AVDT_TSEP_SNK;
623       avdtp_stream_config.p_sink_data_cback = bta_av_sink_data_cback;
624       codec_index_min = BTAV_A2DP_CODEC_INDEX_SINK_MIN;
625       codec_index_max = BTAV_A2DP_CODEC_INDEX_SINK_MAX;
626     }
627 
628     /* Initialize handles to zero */
629     for (int xx = 0; xx < BTAV_A2DP_CODEC_INDEX_MAX; xx++) {
630       p_scb->seps[xx].av_handle = 0;
631     }
632 
633     /* keep the configuration in the stream control block */
634     p_scb->cfg = avdtp_stream_config.cfg;
635     for (int i = codec_index_min; i < codec_index_max; i++) {
636       btav_a2dp_codec_index_t codec_index =
637           static_cast<btav_a2dp_codec_index_t>(i);
638       if (!bta_av_co_is_supported_codec(codec_index)) {
639         continue;
640       }
641       if (!(*bta_av_a2dp_cos.init)(codec_index, &avdtp_stream_config.cfg)) {
642         continue;
643       }
644       if (AVDT_CreateStream(p_scb->app_id, &p_scb->seps[codec_index].av_handle,
645                             avdtp_stream_config) != AVDT_SUCCESS) {
646         continue;
647       }
648       /* Save a copy of the codec */
649       memcpy(p_scb->seps[codec_index].codec_info,
650              avdtp_stream_config.cfg.codec_info, AVDT_CODEC_SIZE);
651       p_scb->seps[codec_index].tsep = avdtp_stream_config.tsep;
652       if (avdtp_stream_config.tsep == AVDT_TSEP_SNK) {
653         p_scb->seps[codec_index].p_app_sink_data_cback =
654             p_data->api_reg.p_app_sink_data_cback;
655       } else {
656         /* In case of A2DP SOURCE we don't need a callback to
657          * handle media packets.
658          */
659         p_scb->seps[codec_index].p_app_sink_data_cback = NULL;
660       }
661     }
662 
663     if (!bta_av_cb.reg_audio) {
664       bta_av_cb.sdp_a2dp_handle = 0;
665       bta_av_cb.sdp_a2dp_snk_handle = 0;
666       if (profile_initialized == UUID_SERVCLASS_AUDIO_SOURCE) {
667         /* create the SDP records on the 1st audio channel */
668         bta_av_cb.sdp_a2dp_handle = SDP_CreateRecord();
669         A2DP_AddRecord(UUID_SERVCLASS_AUDIO_SOURCE, p_service_name, NULL,
670                        A2DP_SUPF_PLAYER, bta_av_cb.sdp_a2dp_handle);
671         bta_sys_add_uuid(UUID_SERVCLASS_AUDIO_SOURCE);
672       } else if (profile_initialized == UUID_SERVCLASS_AUDIO_SINK) {
673 #if (BTA_AV_SINK_INCLUDED == TRUE)
674         bta_av_cb.sdp_a2dp_snk_handle = SDP_CreateRecord();
675         A2DP_AddRecord(UUID_SERVCLASS_AUDIO_SINK, p_service_name, NULL,
676                        A2DP_SUPF_PLAYER, bta_av_cb.sdp_a2dp_snk_handle);
677         bta_sys_add_uuid(UUID_SERVCLASS_AUDIO_SINK);
678 #endif
679       }
680       /* start listening when A2DP is registered */
681       if (bta_av_cb.features & BTA_AV_FEAT_RCTG)
682         bta_av_rc_create(&bta_av_cb, AVCT_ACP, 0, BTA_AV_NUM_LINKS + 1);
683 
684       /* if the AV and AVK are both supported, it cannot support the CT role
685        */
686       if (bta_av_cb.features & (BTA_AV_FEAT_RCCT)) {
687         /* if TG is not supported, we need to register to AVCT now */
688         if ((bta_av_cb.features & (BTA_AV_FEAT_RCTG)) == 0) {
689 #if (BTA_AR_INCLUDED == TRUE)
690 #if (BTA_AV_WITH_AVCTP_AUTHORIZATION == TRUE)
691           bta_ar_reg_avct(p_bta_av_cfg->avrc_mtu, p_bta_av_cfg->avrc_br_mtu,
692                           bta_av_cb.sec_mask, BTA_ID_AV);
693 #else
694           bta_ar_reg_avct(p_bta_av_cfg->avrc_mtu, p_bta_av_cfg->avrc_br_mtu,
695                           (uint8_t)(bta_av_cb.sec_mask & (~BTA_SEC_AUTHORIZE)),
696                           BTA_ID_AV);
697 #endif
698 #endif
699           bta_av_rc_create(&bta_av_cb, AVCT_ACP, 0, BTA_AV_NUM_LINKS + 1);
700         }
701 #if (BTA_AR_INCLUDED == TRUE)
702         /* create an SDP record as AVRC CT. We create 1.3 for SOURCE
703          * because we rely on feature bits being scanned by external
704          * devices more than the profile version itself.
705          *
706          * We create 1.4 for SINK since we support browsing.
707          */
708         if (profile_initialized == UUID_SERVCLASS_AUDIO_SOURCE) {
709           bta_ar_reg_avrc(UUID_SERVCLASS_AV_REMOTE_CONTROL, NULL, NULL,
710                           p_bta_av_cfg->avrc_ct_cat, BTA_ID_AV,
711                           (bta_av_cb.features & BTA_AV_FEAT_BROWSE),
712                           AVRC_REV_1_3);
713         } else if (profile_initialized == UUID_SERVCLASS_AUDIO_SINK) {
714           bta_ar_reg_avrc(UUID_SERVCLASS_AV_REMOTE_CONTROL, NULL, NULL,
715                           p_bta_av_cfg->avrc_ct_cat, BTA_ID_AV,
716                           (bta_av_cb.features & BTA_AV_FEAT_BROWSE),
717                           AVRC_REV_1_6);
718         }
719 #endif
720       }
721     }
722     bta_av_cb.reg_audio |= BTA_AV_HNDL_TO_MSK(p_scb->hdi);
723     APPL_TRACE_DEBUG("%s: reg_audio: 0x%x", __func__, bta_av_cb.reg_audio);
724   } while (0);
725 
726   /* call callback with register event */
727   tBTA_AV bta_av_data;
728   bta_av_data.registr = registr;
729   (*bta_av_cb.p_cback)(BTA_AV_REGISTER_EVT, &bta_av_data);
730 }
731 
732 /*******************************************************************************
733  *
734  * Function         bta_av_api_deregister
735  *
736  * Description      de-register a channel
737  *
738  *
739  * Returns          void
740  *
741  ******************************************************************************/
bta_av_api_deregister(tBTA_AV_DATA * p_data)742 void bta_av_api_deregister(tBTA_AV_DATA* p_data) {
743   tBTA_AV_SCB* p_scb = bta_av_hndl_to_scb(p_data->hdr.layer_specific);
744 
745   if (p_scb) {
746     p_scb->deregistering = true;
747     bta_av_ssm_execute(p_scb, BTA_AV_API_CLOSE_EVT, p_data);
748   } else {
749     bta_av_dereg_comp(p_data);
750   }
751 }
752 
753 /*******************************************************************************
754  *
755  * Function         bta_av_ci_data
756  *
757  * Description      Forward the BTA_AV_CI_SRC_DATA_READY_EVT to stream state
758  *                  machine.
759  *
760  *
761  * Returns          void
762  *
763  ******************************************************************************/
bta_av_ci_data(tBTA_AV_DATA * p_data)764 static void bta_av_ci_data(tBTA_AV_DATA* p_data) {
765   tBTA_AV_SCB* p_scb;
766   int i;
767   uint8_t chnl = (uint8_t)p_data->hdr.layer_specific;
768 
769   for (i = 0; i < BTA_AV_NUM_STRS; i++) {
770     p_scb = bta_av_cb.p_scb[i];
771 
772     if (p_scb && p_scb->chnl == chnl) {
773       bta_av_ssm_execute(p_scb, BTA_AV_SRC_DATA_READY_EVT, p_data);
774     }
775   }
776 }
777 
778 /*******************************************************************************
779  *
780  * Function         bta_av_rpc_conn
781  *
782  * Description      report report channel open
783  *
784  * Returns          void
785  *
786  ******************************************************************************/
bta_av_rpc_conn(UNUSED_ATTR tBTA_AV_DATA * p_data)787 static void bta_av_rpc_conn(UNUSED_ATTR tBTA_AV_DATA* p_data) {}
788 
789 /*******************************************************************************
790  *
791  * Function         bta_av_api_to_ssm
792  *
793  * Description      forward the API request to stream state machine
794  *
795  *
796  * Returns          void
797  *
798  ******************************************************************************/
bta_av_api_to_ssm(tBTA_AV_DATA * p_data)799 static void bta_av_api_to_ssm(tBTA_AV_DATA* p_data) {
800   uint16_t event =
801       p_data->hdr.event - BTA_AV_FIRST_A2S_API_EVT + BTA_AV_FIRST_A2S_SSM_EVT;
802   tBTA_AV_HNDL handle = p_data->hdr.layer_specific;
803   tBTA_AV_SCB* p_scb = bta_av_hndl_to_scb(handle);
804 
805   if (p_scb != nullptr) {
806     bta_av_ssm_execute(p_scb, event, p_data);
807   }
808 }
809 
810 /*******************************************************************************
811  *
812  * Function         bta_av_chk_start
813  *
814  * Description      if this is audio channel, check if more than one audio
815  *                  channel is connected & already started.
816  *                  This function needs to be kept very similar to
817  *                  bta_av_chk_2nd_start
818  *
819  * Returns          true, if need api_start
820  *
821  ******************************************************************************/
bta_av_chk_start(tBTA_AV_SCB * p_scb)822 bool bta_av_chk_start(tBTA_AV_SCB* p_scb) {
823   bool start = false;
824 
825   if ((p_scb->chnl == BTA_AV_CHNL_AUDIO) && (bta_av_cb.audio_open_cnt >= 2) &&
826       (((p_scb->role & BTA_AV_ROLE_AD_ACP) == 0) ||  // Outgoing connection or
827        (bta_av_cb.features & BTA_AV_FEAT_ACP_START))) {  // Auto-starting option
828     // More than one audio channel is connected.
829     // If this is the 2nd stream as ACP, give INT a chance to issue the START
830     // command.
831     for (int i = 0; i < BTA_AV_NUM_STRS; i++) {
832       tBTA_AV_SCB* p_scbi = bta_av_cb.p_scb[i];
833       if (p_scbi && p_scbi->chnl == BTA_AV_CHNL_AUDIO && p_scbi->co_started) {
834         start = true;
835         // May need to update the flush timeout of this already started stream
836         if (p_scbi->co_started != bta_av_cb.audio_open_cnt) {
837           p_scbi->co_started = bta_av_cb.audio_open_cnt;
838           L2CA_SetFlushTimeout(
839               p_scbi->PeerAddress(),
840               p_bta_av_cfg->p_audio_flush_to[p_scbi->co_started - 1]);
841         }
842       }
843     }
844   }
845 
846   LOG_INFO(LOG_TAG,
847            "%s: peer %s channel:%d bta_av_cb.audio_open_cnt:%d role:0x%x "
848            "features:0x%x start:%s",
849            __func__, p_scb->PeerAddress().ToString().c_str(), p_scb->chnl,
850            bta_av_cb.audio_open_cnt, p_scb->role, bta_av_cb.features,
851            logbool(start).c_str());
852   return start;
853 }
854 
855 /*******************************************************************************
856  *
857  * Function         bta_av_restore_switch
858  *
859  * Description      assume that the caller of this function already makes
860  *                  sure that there's only one ACL connection left
861  *
862  * Returns          void
863  *
864  ******************************************************************************/
bta_av_restore_switch(void)865 void bta_av_restore_switch(void) {
866   tBTA_AV_CB* p_cb = &bta_av_cb;
867   int i;
868   uint8_t mask;
869   uint8_t set_policy = (HCI_ENABLE_SNIFF_MODE | HCI_ENABLE_MASTER_SLAVE_SWITCH);
870 
871   APPL_TRACE_DEBUG("%s: reg_audio: 0x%x", __func__, bta_av_cb.reg_audio);
872   for (i = 0; i < BTA_AV_NUM_STRS; i++) {
873     mask = BTA_AV_HNDL_TO_MSK(i);
874     if (p_cb->conn_audio == mask) {
875       if (p_cb->p_scb[i]) {
876         bta_sys_set_policy(BTA_ID_AV, set_policy,
877                            p_cb->p_scb[i]->PeerAddress());
878       }
879       break;
880     }
881   }
882 }
883 
884 /*******************************************************************************
885  *
886  * Function         bta_av_sys_rs_cback
887  *
888  * Description      Receives the role change event from dm
889  *
890  * Returns          (BTA_SYS_ROLE_CHANGE, new_role, hci_status, p_bda)
891  *
892  ******************************************************************************/
bta_av_sys_rs_cback(UNUSED_ATTR tBTA_SYS_CONN_STATUS status,uint8_t id,uint8_t app_id,const RawAddress & peer_addr)893 static void bta_av_sys_rs_cback(UNUSED_ATTR tBTA_SYS_CONN_STATUS status,
894                                 uint8_t id, uint8_t app_id,
895                                 const RawAddress& peer_addr) {
896   int i;
897   tBTA_AV_SCB* p_scb = NULL;
898   uint8_t cur_role;
899   uint8_t peer_idx = 0;
900   uint8_t set_policy = (HCI_ENABLE_SNIFF_MODE | HCI_ENABLE_MASTER_SLAVE_SWITCH);
901 
902   APPL_TRACE_DEBUG(
903       "%s: peer %s new_role:%d hci_status:0x%x bta_av_cb.rs_idx:%d", __func__,
904       peer_addr.ToString().c_str(), id, app_id, bta_av_cb.rs_idx);
905 
906   for (i = 0; i < BTA_AV_NUM_STRS; i++) {
907     /* loop through all the SCBs to find matching peer addresses and report the
908      * role change event */
909     /* note that more than one SCB (a2dp & vdp) maybe waiting for this event */
910     p_scb = bta_av_cb.p_scb[i];
911     if (p_scb && p_scb->PeerAddress() == peer_addr) {
912       tBTA_AV_ROLE_RES* p_buf =
913           (tBTA_AV_ROLE_RES*)osi_malloc(sizeof(tBTA_AV_ROLE_RES));
914       APPL_TRACE_DEBUG(
915           "%s: peer %s found: new_role:%d, hci_status:0x%x hndl:0x%x", __func__,
916           peer_addr.ToString().c_str(), id, app_id, p_scb->hndl);
917       /*
918       if ((id != BTM_ROLE_MASTER) && (app_id != HCI_SUCCESS))
919       {
920           bta_sys_set_policy(BTA_ID_AV, set_policy, p_scb->PeerAddress());
921       }
922       */
923       p_buf->hdr.event = BTA_AV_ROLE_CHANGE_EVT;
924       p_buf->hdr.layer_specific = p_scb->hndl;
925       p_buf->new_role = id;
926       p_buf->hci_status = app_id;
927       bta_sys_sendmsg(p_buf);
928 
929       peer_idx = p_scb->hdi + 1; /* Handle index for the peer_addr */
930     }
931   }
932 
933   /* restore role switch policy, if role switch failed */
934   if ((HCI_SUCCESS != app_id) &&
935       (BTM_GetRole(peer_addr, &cur_role) == BTM_SUCCESS) &&
936       (cur_role == BTM_ROLE_SLAVE)) {
937     bta_sys_set_policy(BTA_ID_AV, set_policy, peer_addr);
938   }
939 
940   /* if BTA_AvOpen() was called for other device, which caused the role switch
941    * of the peer_addr,  */
942   /* we need to continue opening process for the BTA_AvOpen(). */
943   if ((bta_av_cb.rs_idx != 0) && (bta_av_cb.rs_idx != peer_idx)) {
944     if ((bta_av_cb.rs_idx - 1) < BTA_AV_NUM_STRS) {
945       p_scb = bta_av_cb.p_scb[bta_av_cb.rs_idx - 1];
946     }
947     if (p_scb && p_scb->q_tag == BTA_AV_Q_TAG_OPEN) {
948       APPL_TRACE_DEBUG("%s: peer %s rs_idx:%d, hndl:0x%x q_tag:%d", __func__,
949                        p_scb->PeerAddress().ToString().c_str(),
950                        bta_av_cb.rs_idx, p_scb->hndl, p_scb->q_tag);
951 
952       if (HCI_SUCCESS == app_id || HCI_ERR_NO_CONNECTION == app_id) {
953         p_scb->q_info.open.switch_res = BTA_AV_RS_OK;
954       } else {
955         APPL_TRACE_ERROR(
956             "%s: peer %s (p_scb peer %s) role switch failed: new_role:%d "
957             "hci_status:0x%x",
958             __func__, peer_addr.ToString().c_str(),
959             p_scb->PeerAddress().ToString().c_str(), id, app_id);
960         p_scb->q_info.open.switch_res = BTA_AV_RS_FAIL;
961       }
962 
963       /* Continue av open process */
964       bta_av_do_disc_a2dp(p_scb, (tBTA_AV_DATA*)&(p_scb->q_info.open));
965     }
966 
967     bta_av_cb.rs_idx = 0;
968   }
969 }
970 
971 /*******************************************************************************
972  *
973  * Function         bta_av_sco_chg_cback
974  *
975  * Description      receive & process the SCO connection up/down event from sys.
976  *                  call setup also triggers this callback, to suspend av before
977  *                  SCO activity happens, or to resume av once call ends.
978  *
979  * Returns          void
980  *
981  ******************************************************************************/
bta_av_sco_chg_cback(tBTA_SYS_CONN_STATUS status,uint8_t id,UNUSED_ATTR uint8_t app_id,UNUSED_ATTR const RawAddress & peer_addr)982 static void bta_av_sco_chg_cback(tBTA_SYS_CONN_STATUS status, uint8_t id,
983                                  UNUSED_ATTR uint8_t app_id,
984                                  UNUSED_ATTR const RawAddress& peer_addr) {
985   tBTA_AV_SCB* p_scb;
986   int i;
987   tBTA_AV_API_STOP stop;
988 
989   APPL_TRACE_DEBUG("%s: id:%d status:%d", __func__, id, status);
990   if (id) {
991     bta_av_cb.sco_occupied = true;
992 
993     /* either BTA_SYS_SCO_OPEN or BTA_SYS_SCO_CLOSE with remaining active SCO */
994     for (i = 0; i < BTA_AV_NUM_STRS; i++) {
995       p_scb = bta_av_cb.p_scb[i];
996 
997       if (p_scb && p_scb->co_started && (!p_scb->sco_suspend)) {
998         APPL_TRACE_DEBUG("%s: suspending scb:%d", __func__, i);
999         /* scb is used and started, not suspended automatically */
1000         p_scb->sco_suspend = true;
1001         stop.flush = false;
1002         stop.suspend = true;
1003         stop.reconfig_stop = false;
1004         bta_av_ssm_execute(p_scb, BTA_AV_AP_STOP_EVT, (tBTA_AV_DATA*)&stop);
1005       }
1006     }
1007   } else {
1008     bta_av_cb.sco_occupied = false;
1009 
1010     for (i = 0; i < BTA_AV_NUM_STRS; i++) {
1011       p_scb = bta_av_cb.p_scb[i];
1012 
1013       if (p_scb && p_scb->sco_suspend) /* scb is used and suspended for SCO */
1014       {
1015         APPL_TRACE_DEBUG("%s: starting scb:%d", __func__, i);
1016         bta_av_ssm_execute(p_scb, BTA_AV_AP_START_EVT, NULL);
1017       }
1018     }
1019   }
1020 }
1021 
1022 /*******************************************************************************
1023  *
1024  * Function         bta_av_switch_if_needed
1025  *
1026  * Description      This function checks if there is another existing AV
1027  *                  channel that is local as slave role.
1028  *                  If so, role switch and remove it from link policy.
1029  *
1030  * Returns          true, if role switch is done
1031  *
1032  ******************************************************************************/
bta_av_switch_if_needed(tBTA_AV_SCB * p_scb)1033 bool bta_av_switch_if_needed(tBTA_AV_SCB* p_scb) {
1034   // TODO: A workaround for devices that are connected first, become
1035   // Master, and block follow-up role changes - b/72122792 .
1036   return false;
1037 #if 0
1038   uint8_t role;
1039   bool needed = false;
1040   tBTA_AV_SCB* p_scbi;
1041   int i;
1042   uint8_t mask;
1043 
1044   for (i = 0; i < BTA_AV_NUM_STRS; i++) {
1045     mask = BTA_AV_HNDL_TO_MSK(i);
1046     p_scbi = bta_av_cb.p_scb[i];
1047     if (p_scbi && (p_scb->hdi != i) &&   /* not the original channel */
1048         ((bta_av_cb.conn_audio & mask))) /* connected audio */
1049     {
1050       BTM_GetRole(p_scbi->PeerAddress(), &role);
1051       /* this channel is open - clear the role switch link policy for this link
1052        */
1053       if (BTM_ROLE_MASTER != role) {
1054         if (bta_av_cb.features & BTA_AV_FEAT_MASTER)
1055           bta_sys_clear_policy(BTA_ID_AV, HCI_ENABLE_MASTER_SLAVE_SWITCH,
1056                                p_scbi->PeerAddress());
1057         if (BTM_CMD_STARTED !=
1058             BTM_SwitchRole(p_scbi->PeerAddress(), BTM_ROLE_MASTER, NULL)) {
1059           /* can not switch role on SCBI
1060            * start the timer on SCB - because this function is ONLY called when
1061            * SCB gets API_OPEN */
1062           bta_sys_start_timer(p_scb->avrc_ct_timer, BTA_AV_RS_TIME_VAL,
1063                               BTA_AV_AVRC_TIMER_EVT, p_scb->hndl);
1064         }
1065         needed = true;
1066         /* mark the original channel as waiting for RS result */
1067         bta_av_cb.rs_idx = p_scb->hdi + 1;
1068         break;
1069       }
1070     }
1071   }
1072   return needed;
1073 #endif
1074 }
1075 
1076 /*******************************************************************************
1077  *
1078  * Function         bta_av_link_role_ok
1079  *
1080  * Description      This function checks if the SCB has existing ACL connection
1081  *                  If so, check if the link role fits the requirements.
1082  *
1083  * Returns          true, if role is ok
1084  *
1085  ******************************************************************************/
bta_av_link_role_ok(tBTA_AV_SCB * p_scb,uint8_t bits)1086 bool bta_av_link_role_ok(tBTA_AV_SCB* p_scb, uint8_t bits) {
1087   uint8_t role;
1088   bool is_ok = true;
1089 
1090   if (BTM_GetRole(p_scb->PeerAddress(), &role) == BTM_SUCCESS) {
1091     LOG_INFO(
1092         LOG_TAG,
1093         "%s: peer %s hndl:0x%x role:%d conn_audio:0x%x bits:%d features:0x%x",
1094         __func__, p_scb->PeerAddress().ToString().c_str(), p_scb->hndl, role,
1095         bta_av_cb.conn_audio, bits, bta_av_cb.features);
1096     if (BTM_ROLE_MASTER != role &&
1097         (A2DP_BitsSet(bta_av_cb.conn_audio) > bits ||
1098          (bta_av_cb.features & BTA_AV_FEAT_MASTER))) {
1099       if (bta_av_cb.features & BTA_AV_FEAT_MASTER)
1100         bta_sys_clear_policy(BTA_ID_AV, HCI_ENABLE_MASTER_SLAVE_SWITCH,
1101                              p_scb->PeerAddress());
1102 
1103       tBTM_STATUS status =
1104           BTM_SwitchRole(p_scb->PeerAddress(), BTM_ROLE_MASTER, NULL);
1105       if (status != BTM_CMD_STARTED) {
1106         /* can not switch role on SCB - start the timer on SCB */
1107         LOG_ERROR(LOG_TAG,
1108                   "%s: peer %s BTM_SwitchRole(BTM_ROLE_MASTER) error: %d",
1109                   __func__, p_scb->PeerAddress().ToString().c_str(), status);
1110       }
1111       is_ok = false;
1112       p_scb->wait |= BTA_AV_WAIT_ROLE_SW_RES_START;
1113     }
1114   }
1115 
1116   return is_ok;
1117 }
1118 
1119 /*******************************************************************************
1120  *
1121  * Function         bta_av_dup_audio_buf
1122  *
1123  * Description      dup the audio data to the q_info.a2dp of other audio
1124  *                  channels
1125  *
1126  * Returns          void
1127  *
1128  ******************************************************************************/
bta_av_dup_audio_buf(tBTA_AV_SCB * p_scb,BT_HDR * p_buf)1129 void bta_av_dup_audio_buf(tBTA_AV_SCB* p_scb, BT_HDR* p_buf) {
1130   /* Test whether there is more than one audio channel connected */
1131   if ((p_buf == NULL) || (bta_av_cb.audio_open_cnt < 2)) return;
1132 
1133   uint16_t copy_size = BT_HDR_SIZE + p_buf->len + p_buf->offset;
1134   for (int i = 0; i < BTA_AV_NUM_STRS; i++) {
1135     tBTA_AV_SCB* p_scbi = bta_av_cb.p_scb[i];
1136 
1137     if (i == p_scb->hdi) continue; /* Ignore the original channel */
1138     if ((p_scbi == NULL) || !p_scbi->co_started)
1139       continue; /* Ignore if SCB is not used or started */
1140     if (!(bta_av_cb.conn_audio & BTA_AV_HNDL_TO_MSK(i)))
1141       continue; /* Audio is not connected */
1142 
1143     /* Enqueue the data */
1144     BT_HDR* p_new = (BT_HDR*)osi_malloc(copy_size);
1145     memcpy(p_new, p_buf, copy_size);
1146     list_append(p_scbi->a2dp_list, p_new);
1147 
1148     if (list_length(p_scbi->a2dp_list) > p_bta_av_cfg->audio_mqs) {
1149       // Drop the oldest packet
1150       bta_av_co_audio_drop(p_scbi->hndl, p_scbi->PeerAddress());
1151       BT_HDR* p_buf_drop = static_cast<BT_HDR*>(list_front(p_scbi->a2dp_list));
1152       list_remove(p_scbi->a2dp_list, p_buf_drop);
1153       osi_free(p_buf_drop);
1154     }
1155   }
1156 }
1157 
1158 /*******************************************************************************
1159  *
1160  * Function         bta_av_sm_execute
1161  *
1162  * Description      State machine event handling function for AV
1163  *
1164  *
1165  * Returns          void
1166  *
1167  ******************************************************************************/
bta_av_sm_execute(tBTA_AV_CB * p_cb,uint16_t event,tBTA_AV_DATA * p_data)1168 void bta_av_sm_execute(tBTA_AV_CB* p_cb, uint16_t event, tBTA_AV_DATA* p_data) {
1169   tBTA_AV_ST_TBL state_table;
1170   uint8_t action;
1171 
1172   APPL_TRACE_EVENT("%s: AV event=0x%x(%s) state=%d(%s)", __func__, event,
1173                    bta_av_evt_code(event), p_cb->state,
1174                    bta_av_st_code(p_cb->state));
1175 
1176   /* look up the state table for the current state */
1177   state_table = bta_av_st_tbl[p_cb->state];
1178 
1179   event &= 0x00FF;
1180 
1181   /* set next state */
1182   p_cb->state = state_table[event][BTA_AV_NEXT_STATE];
1183   APPL_TRACE_EVENT("%s: next state=%d event offset:%d", __func__, p_cb->state,
1184                    event);
1185 
1186   /* execute action functions */
1187   action = state_table[event][BTA_AV_ACTION_COL];
1188   if (action != BTA_AV_IGNORE) {
1189     APPL_TRACE_EVENT("%s: action executed %d", __func__, action);
1190     (*bta_av_action[action])(p_cb, p_data);
1191   }
1192 }
1193 
1194 /*******************************************************************************
1195  *
1196  * Function         bta_av_hdl_event
1197  *
1198  * Description      Advanced audio/video main event handling function.
1199  *
1200  *
1201  * Returns          bool
1202  *
1203  ******************************************************************************/
bta_av_hdl_event(BT_HDR * p_msg)1204 bool bta_av_hdl_event(BT_HDR* p_msg) {
1205   if (p_msg->event > BTA_AV_LAST_EVT) {
1206     return true; /* to free p_msg */
1207   }
1208   if (p_msg->event >= BTA_AV_FIRST_NSM_EVT) {
1209     APPL_TRACE_VERBOSE("%s: AV nsm event=0x%x(%s)", __func__, p_msg->event,
1210                        bta_av_evt_code(p_msg->event));
1211     /* non state machine events */
1212     (*bta_av_nsm_act[p_msg->event - BTA_AV_FIRST_NSM_EVT])(
1213         (tBTA_AV_DATA*)p_msg);
1214   } else if (p_msg->event >= BTA_AV_FIRST_SM_EVT &&
1215              p_msg->event <= BTA_AV_LAST_SM_EVT) {
1216     APPL_TRACE_VERBOSE("%s: AV sm event=0x%x(%s)", __func__, p_msg->event,
1217                        bta_av_evt_code(p_msg->event));
1218     /* state machine events */
1219     bta_av_sm_execute(&bta_av_cb, p_msg->event, (tBTA_AV_DATA*)p_msg);
1220   } else {
1221     APPL_TRACE_VERBOSE("%s: handle=0x%x", __func__, p_msg->layer_specific);
1222     /* stream state machine events */
1223     bta_av_ssm_execute(bta_av_hndl_to_scb(p_msg->layer_specific), p_msg->event,
1224                        (tBTA_AV_DATA*)p_msg);
1225   }
1226   return true;
1227 }
1228 
1229 /*****************************************************************************
1230  *  Debug Functions
1231  ****************************************************************************/
1232 /*******************************************************************************
1233  *
1234  * Function         bta_av_st_code
1235  *
1236  * Description
1237  *
1238  * Returns          char *
1239  *
1240  ******************************************************************************/
bta_av_st_code(uint8_t state)1241 static const char* bta_av_st_code(uint8_t state) {
1242   switch (state) {
1243     case BTA_AV_INIT_ST:
1244       return "INIT";
1245     case BTA_AV_OPEN_ST:
1246       return "OPEN";
1247     default:
1248       return "unknown";
1249   }
1250 }
1251 /*******************************************************************************
1252  *
1253  * Function         bta_av_evt_code
1254  *
1255  * Description
1256  *
1257  * Returns          char *
1258  *
1259  ******************************************************************************/
bta_av_evt_code(uint16_t evt_code)1260 const char* bta_av_evt_code(uint16_t evt_code) {
1261   switch (evt_code) {
1262     case BTA_AV_API_DISABLE_EVT:
1263       return "API_DISABLE";
1264     case BTA_AV_API_REMOTE_CMD_EVT:
1265       return "API_REMOTE_CMD";
1266     case BTA_AV_API_VENDOR_CMD_EVT:
1267       return "API_VENDOR_CMD";
1268     case BTA_AV_API_VENDOR_RSP_EVT:
1269       return "API_VENDOR_RSP";
1270     case BTA_AV_API_META_RSP_EVT:
1271       return "API_META_RSP_EVT";
1272     case BTA_AV_API_RC_CLOSE_EVT:
1273       return "API_RC_CLOSE";
1274     case BTA_AV_AVRC_OPEN_EVT:
1275       return "AVRC_OPEN";
1276     case BTA_AV_AVRC_MSG_EVT:
1277       return "AVRC_MSG";
1278     case BTA_AV_AVRC_NONE_EVT:
1279       return "AVRC_NONE";
1280 
1281     case BTA_AV_API_OPEN_EVT:
1282       return "API_OPEN";
1283     case BTA_AV_API_CLOSE_EVT:
1284       return "API_CLOSE";
1285     case BTA_AV_AP_START_EVT:
1286       return "AP_START";
1287     case BTA_AV_AP_STOP_EVT:
1288       return "AP_STOP";
1289     case BTA_AV_API_RECONFIG_EVT:
1290       return "API_RECONFIG";
1291     case BTA_AV_API_PROTECT_REQ_EVT:
1292       return "API_PROTECT_REQ";
1293     case BTA_AV_API_PROTECT_RSP_EVT:
1294       return "API_PROTECT_RSP";
1295     case BTA_AV_API_RC_OPEN_EVT:
1296       return "API_RC_OPEN";
1297     case BTA_AV_SRC_DATA_READY_EVT:
1298       return "SRC_DATA_READY";
1299     case BTA_AV_CI_SETCONFIG_OK_EVT:
1300       return "CI_SETCONFIG_OK";
1301     case BTA_AV_CI_SETCONFIG_FAIL_EVT:
1302       return "CI_SETCONFIG_FAIL";
1303     case BTA_AV_SDP_DISC_OK_EVT:
1304       return "SDP_DISC_OK";
1305     case BTA_AV_SDP_DISC_FAIL_EVT:
1306       return "SDP_DISC_FAIL";
1307     case BTA_AV_STR_DISC_OK_EVT:
1308       return "STR_DISC_OK";
1309     case BTA_AV_STR_DISC_FAIL_EVT:
1310       return "STR_DISC_FAIL";
1311     case BTA_AV_STR_GETCAP_OK_EVT:
1312       return "STR_GETCAP_OK";
1313     case BTA_AV_STR_GETCAP_FAIL_EVT:
1314       return "STR_GETCAP_FAIL";
1315     case BTA_AV_STR_OPEN_OK_EVT:
1316       return "STR_OPEN_OK";
1317     case BTA_AV_STR_OPEN_FAIL_EVT:
1318       return "STR_OPEN_FAIL";
1319     case BTA_AV_STR_START_OK_EVT:
1320       return "STR_START_OK";
1321     case BTA_AV_STR_START_FAIL_EVT:
1322       return "STR_START_FAIL";
1323     case BTA_AV_STR_CLOSE_EVT:
1324       return "STR_CLOSE";
1325     case BTA_AV_STR_CONFIG_IND_EVT:
1326       return "STR_CONFIG_IND";
1327     case BTA_AV_STR_SECURITY_IND_EVT:
1328       return "STR_SECURITY_IND";
1329     case BTA_AV_STR_SECURITY_CFM_EVT:
1330       return "STR_SECURITY_CFM";
1331     case BTA_AV_STR_WRITE_CFM_EVT:
1332       return "STR_WRITE_CFM";
1333     case BTA_AV_STR_SUSPEND_CFM_EVT:
1334       return "STR_SUSPEND_CFM";
1335     case BTA_AV_STR_RECONFIG_CFM_EVT:
1336       return "STR_RECONFIG_CFM";
1337     case BTA_AV_AVRC_TIMER_EVT:
1338       return "AVRC_TIMER";
1339     case BTA_AV_AVDT_CONNECT_EVT:
1340       return "AVDT_CONNECT";
1341     case BTA_AV_AVDT_DISCONNECT_EVT:
1342       return "AVDT_DISCONNECT";
1343     case BTA_AV_ROLE_CHANGE_EVT:
1344       return "ROLE_CHANGE";
1345     case BTA_AV_AVDT_DELAY_RPT_EVT:
1346       return "AVDT_DELAY_RPT";
1347     case BTA_AV_ACP_CONNECT_EVT:
1348       return "ACP_CONNECT";
1349 
1350     case BTA_AV_API_ENABLE_EVT:
1351       return "API_ENABLE";
1352     case BTA_AV_API_REGISTER_EVT:
1353       return "API_REG";
1354     case BTA_AV_API_DEREGISTER_EVT:
1355       return "API_DEREG";
1356     case BTA_AV_API_DISCONNECT_EVT:
1357       return "API_DISCNT";
1358     case BTA_AV_CI_SRC_DATA_READY_EVT:
1359       return "CI_DATA_READY";
1360     case BTA_AV_SIG_CHG_EVT:
1361       return "SIG_CHG";
1362     case BTA_AV_SIGNALLING_TIMER_EVT:
1363       return "SIGNALLING_TIMER";
1364     case BTA_AV_SDP_AVRC_DISC_EVT:
1365       return "SDP_AVRC_DISC";
1366     case BTA_AV_AVRC_CLOSE_EVT:
1367       return "AVRC_CLOSE";
1368     case BTA_AV_AVRC_BROWSE_OPEN_EVT:
1369       return "AVRC_BROWSE_OPEN";
1370     case BTA_AV_AVRC_BROWSE_CLOSE_EVT:
1371       return "AVRC_BROWSE_CLOSE";
1372     case BTA_AV_CONN_CHG_EVT:
1373       return "CONN_CHG";
1374     case BTA_AV_DEREG_COMP_EVT:
1375       return "DEREG_COMP";
1376     case BTA_AV_AVDT_RPT_CONN_EVT:
1377       return "RPT_CONN";
1378     case BTA_AV_API_START_EVT:
1379       return "API_START";
1380     case BTA_AV_API_STOP_EVT:
1381       return "API_STOP";
1382     default:
1383       return "unknown";
1384   }
1385 }
1386 
bta_debug_av_dump(int fd)1387 void bta_debug_av_dump(int fd) {
1388   if (appl_trace_level < BT_TRACE_LEVEL_DEBUG) return;
1389 
1390   dprintf(fd, "\nBTA AV State:\n");
1391   dprintf(fd, "  State Machine State: %s\n", bta_av_st_code(bta_av_cb.state));
1392   dprintf(fd, "  Link signalling timer: %s\n",
1393           alarm_is_scheduled(bta_av_cb.link_signalling_timer)
1394               ? "Scheduled"
1395               : "Not scheduled");
1396   dprintf(fd, "  Accept signalling timer: %s\n",
1397           alarm_is_scheduled(bta_av_cb.accept_signalling_timer)
1398               ? "Scheduled"
1399               : "Not scheduled");
1400   dprintf(fd, "  SDP A2DP source handle: %d\n", bta_av_cb.sdp_a2dp_handle);
1401   dprintf(fd, "  SDP A2DP sink handle: %d\n", bta_av_cb.sdp_a2dp_snk_handle);
1402   dprintf(fd, "  Features: 0x%x\n", bta_av_cb.features);
1403   dprintf(fd, "  Security mask: 0x%x\n", bta_av_cb.sec_mask);
1404   dprintf(fd, "  SDP handle: %d\n", bta_av_cb.handle);
1405   dprintf(fd, "  Disabling: %s\n", bta_av_cb.disabling ? "true" : "false");
1406   dprintf(fd, "  SCO occupied: %s\n",
1407           bta_av_cb.sco_occupied ? "true" : "false");
1408   dprintf(fd, "  Connected audio channels: %d\n", bta_av_cb.audio_open_cnt);
1409   dprintf(fd, "  Connected audio channels mask: 0x%x\n", bta_av_cb.conn_audio);
1410   dprintf(fd, "  Streaming audio channels mask: 0x%x\n",
1411           bta_av_cb.audio_streams);
1412   dprintf(fd, "  Registered audio channels mask: 0x%x\n", bta_av_cb.reg_audio);
1413   dprintf(fd, "  Connected LCBs mask: 0x%x\n", bta_av_cb.conn_lcb);
1414 
1415   for (size_t i = 0; i < sizeof(bta_av_cb.lcb) / sizeof(bta_av_cb.lcb[0]);
1416        i++) {
1417     const tBTA_AV_LCB& lcb = bta_av_cb.lcb[i];
1418     if (lcb.addr.IsEmpty()) {
1419       continue;
1420     }
1421     dprintf(fd, "\n  Link control block: %zu peer: %s\n", i,
1422             lcb.addr.ToString().c_str());
1423     dprintf(fd, "    Connected stream handle mask: 0x%x\n", lcb.conn_msk);
1424     dprintf(fd, "    Index(+1) to LCB: %d\n", lcb.lidx);
1425   }
1426   for (size_t i = 0; i < BTA_AV_NUM_STRS; i++) {
1427     const tBTA_AV_SCB* p_scb = bta_av_cb.p_scb[i];
1428     if (p_scb == nullptr) {
1429       continue;
1430     }
1431     if (p_scb->PeerAddress().IsEmpty()) {
1432       continue;
1433     }
1434     dprintf(fd, "\n  BTA ID: %zu peer: %s\n", i,
1435             p_scb->PeerAddress().ToString().c_str());
1436     dprintf(fd, "    SDP discovery started: %s\n",
1437             p_scb->sdp_discovery_started ? "true" : "false");
1438     for (size_t j = 0; j < BTAV_A2DP_CODEC_INDEX_MAX; j++) {
1439       const tBTA_AV_SEP& sep = p_scb->seps[j];
1440       if (sep.av_handle == 0) {
1441         continue;
1442       }
1443       dprintf(fd, "    SEP ID: %zu\n", j);
1444       dprintf(fd, "      SEP AVDTP handle: %d\n", sep.av_handle);
1445       dprintf(fd, "      Local SEP type: %d\n", sep.tsep);
1446       dprintf(fd, "      Codec: %s\n", A2DP_CodecName(sep.codec_info));
1447     }
1448     dprintf(fd, "    BTA info tag: %d\n", p_scb->q_tag);
1449     dprintf(fd, "    API Open peer: %s\n",
1450             p_scb->q_info.open.bd_addr.ToString().c_str());
1451     dprintf(fd, "      Use AVRCP: %s\n",
1452             p_scb->q_info.open.use_rc ? "true" : "false");
1453     dprintf(fd, "      Security mask: 0x%x\n", p_scb->q_info.open.sec_mask);
1454     dprintf(fd, "      Switch result: %d\n", p_scb->q_info.open.switch_res);
1455     dprintf(fd, "      Initiator UUID: 0x%x\n", p_scb->q_info.open.uuid);
1456     dprintf(fd, "    Saved API Open peer: %s\n",
1457             p_scb->open_api.bd_addr.ToString().c_str());
1458     dprintf(fd, "      Use AVRCP: %s\n",
1459             p_scb->open_api.use_rc ? "true" : "false");
1460     dprintf(fd, "      Security mask: 0x%x\n", p_scb->open_api.sec_mask);
1461     dprintf(fd, "      Switch result: %d\n", p_scb->open_api.switch_res);
1462     dprintf(fd, "      Initiator UUID: 0x%x\n", p_scb->open_api.uuid);
1463     // TODO: Print p_scb->sep_info[], cfg, avrc_ct_timer, current_codec ?
1464     dprintf(fd, "    L2CAP Channel ID: %d\n", p_scb->l2c_cid);
1465     dprintf(fd, "    Stream MTU: %d\n", p_scb->stream_mtu);
1466     dprintf(fd, "    AVDTP version: 0x%x\n", p_scb->AvdtpVersion());
1467     dprintf(fd, "    Security mask: 0x%x\n", p_scb->sec_mask);
1468     dprintf(fd, "    Media type: %d\n", p_scb->media_type);
1469     dprintf(fd, "    Congested: %s\n", p_scb->cong ? "true" : "false");
1470     dprintf(fd, "    Open status: %d\n", p_scb->open_status);
1471     dprintf(fd, "    Channel: %d\n", p_scb->chnl);
1472     dprintf(fd, "    BTA handle: 0x%x\n", p_scb->hndl);
1473     dprintf(fd, "    Protocol service capabilities mask: 0x%x\n",
1474             p_scb->cur_psc_mask);
1475     dprintf(fd, "    AVDTP handle: %d\n", p_scb->avdt_handle);
1476     dprintf(fd, "    Stream control block index: %d\n", p_scb->hdi);
1477     dprintf(fd, "    State machine state: %s(%d)\n",
1478             bta_av_sst_code(p_scb->state), p_scb->state);
1479     dprintf(fd, "    AVDTP label: 0x%x\n", p_scb->avdt_label);
1480     dprintf(fd, "    Application ID: %d\n", p_scb->app_id);
1481     dprintf(fd, "    Role: 0x%x\n", p_scb->role);
1482     dprintf(fd, "    Queued L2CAP buffers: %d\n", p_scb->l2c_bufs);
1483     dprintf(fd, "    AVRCP allowed: %s\n", p_scb->use_rc ? "true" : "false");
1484     dprintf(fd, "    Stream started: %s\n", p_scb->started ? "true" : "false");
1485     dprintf(fd, "    Stream call-out started: %d\n", p_scb->co_started);
1486     dprintf(fd, "    AVDTP Reconfig supported: %s\n",
1487             p_scb->recfg_sup ? "true" : "false");
1488     dprintf(fd, "    AVDTP Suspend supported: %s\n",
1489             p_scb->suspend_sup ? "true" : "false");
1490     dprintf(fd, "    Deregistering: %s\n",
1491             p_scb->deregistering ? "true" : "false");
1492     dprintf(fd, "    SCO automatic Suspend: %s\n",
1493             p_scb->sco_suspend ? "true" : "false");
1494     dprintf(fd, "    Incoming/outgoing connection collusion mask: 0x%x\n",
1495             p_scb->coll_mask);
1496     dprintf(fd, "    Wait mask: 0x%x\n", p_scb->wait);
1497     dprintf(fd, "    Don't use RTP header: %s\n",
1498             p_scb->no_rtp_header ? "true" : "false");
1499     dprintf(fd, "    Intended UUID of Initiator to connect to: 0x%x\n",
1500             p_scb->uuid_int);
1501   }
1502 }
1503