1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
64
65
66
67
68
69
70
71
72
73
74
75
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
166
167
168
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
322
323
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
364
365
368
369
370
371
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
410
411
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
447
448
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
511
512
513
514
515
516
517
522
523
524
525
526
527
528
529
530
531
532
533
534
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
594
595
596
/* ... */
/* ... */
#include <assert.h>
#include "common/bt_trace.h"
#include <string.h>
#include "stack/bt_types.h"
#include "common/bt_target.h"
#include "common/bt_defs.h"
#include "stack/avdt_api.h"
#include "stack/avdtc_api.h"
#include "avdt_int.h"
#include "stack/l2c_api.h"
#include "stack/l2cdefs.h"
#include "osi/allocator.h"12 includes
#if (defined(AVDT_INCLUDED) && AVDT_INCLUDED == TRUE)
/* ... */
UINT8 avdt_ad_type_to_tcid(UINT8 type, tAVDT_SCB *p_scb)
{
UINT8 scb_idx;
if (type == AVDT_CHAN_SIG) {
return 0;
}{...} else {
scb_idx = avdt_scb_to_hdl(p_scb) - 1;
/* ... */
return ((scb_idx * (AVDT_CHAN_NUM_TYPES - 1)) + type);
}{...}
}{...}
/* ... */
static UINT8 avdt_ad_tcid_to_type(UINT8 tcid)
{
UINT8 type;
if (tcid == 0) {
type = AVDT_CHAN_SIG;
}{...} else {
/* ... */
type = ((tcid + AVDT_CHAN_NUM_TYPES - 2) % (AVDT_CHAN_NUM_TYPES - 1)) + 1;
}{...}
AVDT_TRACE_DEBUG("tcid: %d, type: %d\n", tcid, type);
return type;
}{...}
/* ... */
void avdt_ad_init(void)
{
int i;
tAVDT_TC_TBL *p_tbl = avdt_cb.ad.tc_tbl;
memset(&avdt_cb.ad, 0, sizeof(tAVDT_AD));
for (i = 0; i < AVDT_NUM_TC_TBL; i++, p_tbl++) {
p_tbl->peer_mtu = L2CAP_DEFAULT_MTU;
}{...}
}{...}
/* ... */
tAVDT_TC_TBL *avdt_ad_tc_tbl_by_st(UINT8 type, tAVDT_CCB *p_ccb, UINT8 state)
{
int i;
tAVDT_TC_TBL *p_tbl = avdt_cb.ad.tc_tbl;
UINT8 ccb_idx;
if (p_ccb == NULL) {
for (i = 0; i < AVDT_NUM_TC_TBL; i++, p_tbl++) {
if ((p_tbl->tcid == 0) &&
(p_tbl->state == state)) {
break;
}{...}
}{...}
}{...} else {
ccb_idx = avdt_ccb_to_idx(p_ccb);
for (i = 0; i < AVDT_NUM_TC_TBL; i++, p_tbl++) {
if (type == AVDT_CHAN_SIG) {
if ((p_tbl->tcid == 0) &&
(p_tbl->ccb_idx == ccb_idx) &&
(p_tbl->state == state)) {
break;
}{...}
}{...} else {
if ((p_tbl->tcid > 0) &&
(p_tbl->ccb_idx == ccb_idx) &&
(p_tbl->state == state)) {
break;
}{...}
}{...}
}{...}
}{...}
if (i == AVDT_NUM_TC_TBL) {
p_tbl = NULL;
}{...}
return p_tbl;
}{...}
/* ... */
tAVDT_TC_TBL *avdt_ad_tc_tbl_by_lcid(UINT16 lcid)
{
UINT8 idx;
idx = avdt_cb.ad.lcid_tbl[lcid - L2CAP_BASE_APPL_CID];
if (idx < AVDT_NUM_TC_TBL) {
return &avdt_cb.ad.tc_tbl[idx];
}{...} else {
return NULL;
}{...}
}{...}
/* ... */
tAVDT_TC_TBL *avdt_ad_tc_tbl_by_type(UINT8 type, tAVDT_CCB *p_ccb, tAVDT_SCB *p_scb)
{
UINT8 tcid;
int i;
tAVDT_TC_TBL *p_tbl = avdt_cb.ad.tc_tbl;
UINT8 ccb_idx = avdt_ccb_to_idx(p_ccb);
tcid = avdt_ad_type_to_tcid(type, p_scb);
for (i = 0; i < AVDT_NUM_TC_TBL; i++, p_tbl++) {
if ((p_tbl->tcid == tcid) && (p_tbl->ccb_idx == ccb_idx)) {
break;
}{...}
}{...}
assert(i != AVDT_NUM_TC_TBL);
return p_tbl;
}{...}
/* ... */
tAVDT_TC_TBL *avdt_ad_tc_tbl_alloc(tAVDT_CCB *p_ccb)
{
int i;
tAVDT_TC_TBL *p_tbl = avdt_cb.ad.tc_tbl;
for (i = 0; i < AVDT_NUM_TC_TBL; i++, p_tbl++) {
if (p_tbl->state == AVDT_AD_ST_UNUSED) {
break;
}{...}
}{...}
assert(i != AVDT_NUM_TC_TBL);
p_tbl->peer_mtu = L2CAP_DEFAULT_MTU;
p_tbl->cfg_flags = 0;
p_tbl->ccb_idx = avdt_ccb_to_idx(p_ccb);
p_tbl->state = AVDT_AD_ST_IDLE;
return p_tbl;
}{...}
/* ... */
UINT8 avdt_ad_tc_tbl_to_idx(tAVDT_TC_TBL *p_tbl)
{
AVDT_TRACE_DEBUG("avdt_ad_tc_tbl_to_idx: %d\n", (p_tbl - avdt_cb.ad.tc_tbl));
return (UINT8) (p_tbl - avdt_cb.ad.tc_tbl);
}{...}
/* ... */
void avdt_ad_tc_close_ind(tAVDT_TC_TBL *p_tbl, UINT16 reason)
{
tAVDT_CCB *p_ccb;
tAVDT_SCB *p_scb;
tAVDT_SCB_TC_CLOSE close;
close.old_tc_state = p_tbl->state;
p_tbl->state = AVDT_AD_ST_UNUSED;
p_tbl->cfg_flags = 0;
p_tbl->peer_mtu = L2CAP_DEFAULT_MTU;
AVDT_TRACE_DEBUG("avdt_ad_tc_close_ind tcid: %d, old: %d\n",
p_tbl->tcid, close.old_tc_state);
if (p_tbl->tcid == 0) {
p_ccb = avdt_ccb_by_idx(p_tbl->ccb_idx);
p_ccb->disc_rsn = (reason == AVDT_DISC_RSN_ABNORMAL) ? AVDT_DISC_RSN_ABNORMAL : AVDT_DISC_RSN_NORMAL;
avdt_ccb_event(p_ccb, AVDT_CCB_LL_CLOSE_EVT, NULL);
}{...}
else {
p_scb = avdt_scb_by_hdl(avdt_cb.ad.rt_tbl[p_tbl->ccb_idx][p_tbl->tcid].scb_hdl);
if (p_scb != NULL) {
close.tcid = p_tbl->tcid;
close.type = avdt_ad_tcid_to_type(p_tbl->tcid);
close.disc_rsn = (reason == AVDT_DISC_RSN_ABNORMAL) ? AVDT_DISC_RSN_ABNORMAL : AVDT_DISC_RSN_NORMAL;
avdt_scb_event(p_scb, AVDT_SCB_TC_CLOSE_EVT, (tAVDT_SCB_EVT *)&close);
}{...}
}{...}
}{...}
/* ... */
void avdt_ad_tc_open_ind(tAVDT_TC_TBL *p_tbl)
{
tAVDT_CCB *p_ccb;
tAVDT_SCB *p_scb;
tAVDT_OPEN open;
tAVDT_EVT_HDR evt;
p_tbl->state = AVDT_AD_ST_OPEN;
if (p_tbl->tcid == 0) {
L2CA_SetTxPriority(avdt_cb.ad.rt_tbl[p_tbl->ccb_idx][AVDT_CHAN_SIG].lcid, L2CAP_CHNL_PRIORITY_HIGH);
p_ccb = avdt_ccb_by_idx(p_tbl->ccb_idx);
/* ... */
evt.err_param = AVDT_INT;
if (p_tbl->cfg_flags & AVDT_L2C_CFG_CONN_ACP) {
evt.err_param = AVDT_ACP;
}{...}
avdt_ccb_event(p_ccb, AVDT_CCB_LL_OPEN_EVT, (tAVDT_CCB_EVT *)&evt);
}{...}
else {
p_scb = avdt_scb_by_hdl(avdt_cb.ad.rt_tbl[p_tbl->ccb_idx][p_tbl->tcid].scb_hdl);
if (p_scb != NULL) {
open.peer_mtu = p_tbl->peer_mtu;
open.lcid = avdt_cb.ad.rt_tbl[p_tbl->ccb_idx][p_tbl->tcid].lcid;
open.hdr.err_code = avdt_ad_tcid_to_type(p_tbl->tcid);
avdt_scb_event(p_scb, AVDT_SCB_TC_OPEN_EVT, (tAVDT_SCB_EVT *) &open);
}{...}
}{...}
}{...}
/* ... */
void avdt_ad_tc_cong_ind(tAVDT_TC_TBL *p_tbl, BOOLEAN is_congested)
{
tAVDT_CCB *p_ccb;
tAVDT_SCB *p_scb;
if (p_tbl->tcid == 0) {
p_ccb = avdt_ccb_by_idx(p_tbl->ccb_idx);
avdt_ccb_event(p_ccb, AVDT_CCB_LL_CONG_EVT, (tAVDT_CCB_EVT *) &is_congested);
}{...}
else {
p_scb = avdt_scb_by_hdl(avdt_cb.ad.rt_tbl[p_tbl->ccb_idx][p_tbl->tcid].scb_hdl);
if (p_scb != NULL) {
avdt_scb_event(p_scb, AVDT_SCB_TC_CONG_EVT, (tAVDT_SCB_EVT *) &is_congested);
}{...}
}{...}
}{...}
/* ... */
void avdt_ad_tc_data_ind(tAVDT_TC_TBL *p_tbl, BT_HDR *p_buf)
{
tAVDT_CCB *p_ccb;
tAVDT_SCB *p_scb;
p_buf->layer_specific = avdt_ad_tcid_to_type(p_tbl->tcid);
if (p_tbl->tcid == 0) {
p_ccb = avdt_ccb_by_idx(p_tbl->ccb_idx);
avdt_msg_ind(p_ccb, p_buf);
}{...}
else {
p_scb = avdt_scb_by_hdl(avdt_cb.ad.rt_tbl[p_tbl->ccb_idx][p_tbl->tcid].scb_hdl);
if (p_scb != NULL) {
avdt_scb_event(p_scb, AVDT_SCB_TC_DATA_EVT, (tAVDT_SCB_EVT *) &p_buf);
}{...} else {
osi_free(p_buf);
AVDT_TRACE_ERROR(" avdt_ad_tc_data_ind buffer freed");
}{...}
}{...}
}{...}
/* ... */
UINT8 avdt_ad_write_req(UINT8 type, tAVDT_CCB *p_ccb, tAVDT_SCB *p_scb, BT_HDR *p_buf)
{
UINT8 tcid;
tcid = avdt_ad_type_to_tcid(type, p_scb);
return L2CA_DataWrite(avdt_cb.ad.rt_tbl[avdt_ccb_to_idx(p_ccb)][tcid].lcid, p_buf);
}{...}
/* ... */
void avdt_ad_open_req(UINT8 type, tAVDT_CCB *p_ccb, tAVDT_SCB *p_scb, UINT8 role)
{
tAVDT_TC_TBL *p_tbl;
UINT16 lcid;
if ((p_tbl = avdt_ad_tc_tbl_alloc(p_ccb)) == NULL) {
AVDT_TRACE_ERROR("avdt_ad_open_req: Cannot allocate p_tbl");
return;
}{...}
p_tbl->tcid = avdt_ad_type_to_tcid(type, p_scb);
AVDT_TRACE_DEBUG("avdt_ad_open_req: type: %d, role: %d, tcid:%d\n",
type, role, p_tbl->tcid);
if (type == AVDT_CHAN_SIG) {
p_tbl->my_mtu = avdt_cb.rcb.ctrl_mtu;
p_tbl->my_flush_to = L2CAP_DEFAULT_FLUSH_TO;
}{...} else {
p_tbl->my_mtu = p_scb->cs.mtu;
p_tbl->my_flush_to = p_scb->cs.flush_to;
avdt_cb.ad.rt_tbl[avdt_ccb_to_idx(p_ccb)][p_tbl->tcid].scb_hdl = avdt_scb_to_hdl(p_scb);
AVDT_TRACE_DEBUG("avdt_cb.ad.rt_tbl[%d][%d].scb_hdl = %d\n",
avdt_ccb_to_idx(p_ccb), p_tbl->tcid,
avdt_scb_to_hdl(p_scb));
}{...}
if (role == AVDT_ACP) {
p_tbl->state = AVDT_AD_ST_ACP;
}{...}
else {
p_tbl->state = AVDT_AD_ST_CONN;
if ((lcid = L2CA_ConnectReq(AVDT_PSM, p_ccb->peer_addr)) != 0) {
avdt_cb.ad.lcid_tbl[lcid - L2CAP_BASE_APPL_CID] = avdt_ad_tc_tbl_to_idx(p_tbl);
AVDT_TRACE_DEBUG("avdt_cb.ad.lcid_tbl[%d] = %d\n",
(lcid - L2CAP_BASE_APPL_CID), avdt_ad_tc_tbl_to_idx(p_tbl));
avdt_cb.ad.rt_tbl[avdt_ccb_to_idx(p_ccb)][p_tbl->tcid].lcid = lcid;
AVDT_TRACE_DEBUG("avdt_cb.ad.rt_tbl[%d][%d].lcid = 0x%x\n",
avdt_ccb_to_idx(p_ccb), p_tbl->tcid,
lcid);
}{...} else {
avdt_ad_tc_close_ind(p_tbl, 0);
}{...}
}{...}
}{...}
/* ... */
void avdt_ad_close_req(UINT8 type, tAVDT_CCB *p_ccb, tAVDT_SCB *p_scb)
{
UINT8 tcid;
tAVDT_TC_TBL *p_tbl;
p_tbl = avdt_ad_tc_tbl_by_type(type, p_ccb, p_scb);
AVDT_TRACE_DEBUG("avdt_ad_close_req state: %d\n", p_tbl->state);
switch (p_tbl->state) {
case AVDT_AD_ST_UNUSED:
break;...
case AVDT_AD_ST_ACP:
avdt_ad_tc_close_ind(p_tbl, 0);
break;...
default:
tcid = avdt_ad_type_to_tcid(type, p_scb);
L2CA_DisconnectReq(avdt_cb.ad.rt_tbl[avdt_ccb_to_idx(p_ccb)][tcid].lcid);...
}{...}
}{...}
/* ... */
#endif