1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
25
26
33
34
35
36
39
40
41
42
43
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
285
286
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
320
321
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
385
386
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
441
442
443
444
445
/* ... */
/* ... */
#include <string.h>
#include "stack/bt_types.h"
#include "common/bt_target.h"
#include "common/bt_defs.h"
#include "stack/avct_api.h"
#include "avct_int.h"
#include "osi/allocator.h"7 includes
#if (defined(AVCT_INCLUDED) && AVCT_INCLUDED == TRUE)
/* ... */
#if BT_TRACE_VERBOSE == TRUE
const char *const avct_lcb_st_str[] = {
"LCB_IDLE_ST",
"LCB_OPENING_ST",
"LCB_OPEN_ST",
"LCB_CLOSING_ST"
}{...};
const char *const avct_lcb_evt_str[] = {
"UL_BIND_EVT",
"UL_UNBIND_EVT",
"UL_MSG_EVT",
"INT_CLOSE_EVT",
"LL_OPEN_EVT",
"LL_CLOSE_EVT",
"LL_MSG_EVT",
"LL_CONG_EVT"
}{...};
/* ... */
#endif
enum {
AVCT_LCB_IDLE_ST,
AVCT_LCB_OPENING_ST,
AVCT_LCB_OPEN_ST,
AVCT_LCB_CLOSING_ST
}{...};
enum {
AVCT_LCB_CHNL_OPEN,
AVCT_LCB_CHNL_DISC,
AVCT_LCB_SEND_MSG,
AVCT_LCB_OPEN_IND,
AVCT_LCB_OPEN_FAIL,
AVCT_LCB_CLOSE_IND,
AVCT_LCB_CLOSE_CFM,
AVCT_LCB_MSG_IND,
AVCT_LCB_CONG_IND,
AVCT_LCB_BIND_CONN,
AVCT_LCB_BIND_FAIL,
AVCT_LCB_UNBIND_DISC,
AVCT_LCB_CHK_DISC,
AVCT_LCB_DISCARD_MSG,
AVCT_LCB_DEALLOC,
AVCT_LCB_FREE_MSG_IND,
AVCT_LCB_NUM_ACTIONS
}{...};
#define AVCT_LCB_IGNORE AVCT_LCB_NUM_ACTIONS
typedef void (*tAVCT_LCB_ACTION)(tAVCT_LCB *p_ccb, tAVCT_LCB_EVT *p_data);
const tAVCT_LCB_ACTION avct_lcb_action[] = {
avct_lcb_chnl_open,
avct_lcb_chnl_disc,
avct_lcb_send_msg,
avct_lcb_open_ind,
avct_lcb_open_fail,
avct_lcb_close_ind,
avct_lcb_close_cfm,
avct_lcb_msg_ind,
avct_lcb_cong_ind,
avct_lcb_bind_conn,
avct_lcb_bind_fail,
avct_lcb_unbind_disc,
avct_lcb_chk_disc,
avct_lcb_discard_msg,
avct_lcb_dealloc,
avct_lcb_free_msg_ind
}{...};
#define AVCT_LCB_ACTIONS 2
#define AVCT_LCB_NEXT_STATE 2
#define AVCT_LCB_NUM_COLS 3
const UINT8 avct_lcb_st_idle[][AVCT_LCB_NUM_COLS] = {
{AVCT_LCB_CHNL_OPEN, AVCT_LCB_IGNORE, AVCT_LCB_OPENING_ST},
{AVCT_LCB_UNBIND_DISC, AVCT_LCB_IGNORE, AVCT_LCB_IDLE_ST},
{AVCT_LCB_DISCARD_MSG, AVCT_LCB_IGNORE, AVCT_LCB_IDLE_ST},
{AVCT_LCB_IGNORE, AVCT_LCB_IGNORE, AVCT_LCB_IDLE_ST},
{AVCT_LCB_OPEN_IND, AVCT_LCB_IGNORE, AVCT_LCB_OPEN_ST},
{AVCT_LCB_CLOSE_IND, AVCT_LCB_DEALLOC, AVCT_LCB_IDLE_ST},
{AVCT_LCB_FREE_MSG_IND, AVCT_LCB_IGNORE, AVCT_LCB_IDLE_ST},
{AVCT_LCB_IGNORE, AVCT_LCB_IGNORE, AVCT_LCB_IDLE_ST}
}{...};
const UINT8 avct_lcb_st_opening[][AVCT_LCB_NUM_COLS] = {
{AVCT_LCB_IGNORE, AVCT_LCB_IGNORE, AVCT_LCB_OPENING_ST},
{AVCT_LCB_UNBIND_DISC, AVCT_LCB_IGNORE, AVCT_LCB_OPENING_ST},
{AVCT_LCB_DISCARD_MSG, AVCT_LCB_IGNORE, AVCT_LCB_OPENING_ST},
{AVCT_LCB_CHNL_DISC, AVCT_LCB_IGNORE, AVCT_LCB_CLOSING_ST},
{AVCT_LCB_OPEN_IND, AVCT_LCB_IGNORE, AVCT_LCB_OPEN_ST},
{AVCT_LCB_OPEN_FAIL, AVCT_LCB_DEALLOC, AVCT_LCB_IDLE_ST},
{AVCT_LCB_FREE_MSG_IND, AVCT_LCB_IGNORE, AVCT_LCB_OPENING_ST},
{AVCT_LCB_CONG_IND, AVCT_LCB_IGNORE, AVCT_LCB_OPENING_ST}
}{...};
const UINT8 avct_lcb_st_open[][AVCT_LCB_NUM_COLS] = {
{AVCT_LCB_BIND_CONN, AVCT_LCB_IGNORE, AVCT_LCB_OPEN_ST},
{AVCT_LCB_CHK_DISC, AVCT_LCB_IGNORE, AVCT_LCB_OPEN_ST},
{AVCT_LCB_SEND_MSG, AVCT_LCB_IGNORE, AVCT_LCB_OPEN_ST},
{AVCT_LCB_CHNL_DISC, AVCT_LCB_IGNORE, AVCT_LCB_CLOSING_ST},
{AVCT_LCB_IGNORE, AVCT_LCB_IGNORE, AVCT_LCB_OPEN_ST},
{AVCT_LCB_CLOSE_IND, AVCT_LCB_DEALLOC, AVCT_LCB_IDLE_ST},
{AVCT_LCB_MSG_IND, AVCT_LCB_IGNORE, AVCT_LCB_OPEN_ST},
{AVCT_LCB_CONG_IND, AVCT_LCB_IGNORE, AVCT_LCB_OPEN_ST}
}{...};
const UINT8 avct_lcb_st_closing[][AVCT_LCB_NUM_COLS] = {
{AVCT_LCB_BIND_FAIL, AVCT_LCB_IGNORE, AVCT_LCB_CLOSING_ST},
{AVCT_LCB_IGNORE, AVCT_LCB_IGNORE, AVCT_LCB_CLOSING_ST},
{AVCT_LCB_DISCARD_MSG, AVCT_LCB_IGNORE, AVCT_LCB_CLOSING_ST},
{AVCT_LCB_IGNORE, AVCT_LCB_IGNORE, AVCT_LCB_CLOSING_ST},
{AVCT_LCB_IGNORE, AVCT_LCB_IGNORE, AVCT_LCB_CLOSING_ST},
{AVCT_LCB_CLOSE_CFM, AVCT_LCB_DEALLOC, AVCT_LCB_IDLE_ST},
{AVCT_LCB_FREE_MSG_IND, AVCT_LCB_IGNORE, AVCT_LCB_CLOSING_ST},
{AVCT_LCB_IGNORE, AVCT_LCB_IGNORE, AVCT_LCB_CLOSING_ST}
}{...};
typedef const UINT8 (*tAVCT_LCB_ST_TBL)[AVCT_LCB_NUM_COLS];
const tAVCT_LCB_ST_TBL avct_lcb_st_tbl[] = {
avct_lcb_st_idle,
avct_lcb_st_opening,
avct_lcb_st_open,
avct_lcb_st_closing
}{...};
/* ... */
void avct_lcb_event(tAVCT_LCB *p_lcb, UINT8 event, tAVCT_LCB_EVT *p_data)
{
tAVCT_LCB_ST_TBL state_table;
UINT8 action;
int i;
#if BT_TRACE_VERBOSE == TRUE
AVCT_TRACE_EVENT("LCB lcb=%d event=%s state=%s", p_lcb->allocated, avct_lcb_evt_str[event], avct_lcb_st_str[p_lcb->state]);
#else
AVCT_TRACE_EVENT("LCB lcb=%d event=%d state=%d", p_lcb->allocated, event, p_lcb->state);
#endif
state_table = avct_lcb_st_tbl[p_lcb->state];
p_lcb->state = state_table[event][AVCT_LCB_NEXT_STATE];
for (i = 0; i < AVCT_LCB_ACTIONS; i++) {
if ((action = state_table[event][i]) != AVCT_LCB_IGNORE) {
(*avct_lcb_action[action])(p_lcb, p_data);
}{...} else {
break;
}{...}
}{...}
}{...}
/* ... */
#if (AVCT_BROWSE_INCLUDED == TRUE)
void avct_bcb_event(tAVCT_BCB *p_bcb, UINT8 event, tAVCT_LCB_EVT *p_data)
{
tAVCT_LCB_ST_TBL state_table;
UINT8 action;
int i;
#if BT_TRACE_VERBOSE == TRUE
AVCT_TRACE_EVENT("BCB lcb=%d event=%s state=%s", p_bcb->allocated, avct_lcb_evt_str[event], avct_lcb_st_str[p_bcb->state]);
#else
AVCT_TRACE_EVENT("BCB lcb=%d event=%d state=%d", p_bcb->allocated, event, p_bcb->state);
#endif
state_table = avct_lcb_st_tbl[p_bcb->state];
p_bcb->state = state_table[event][AVCT_LCB_NEXT_STATE];
for (i = 0; i < AVCT_LCB_ACTIONS; i++) {
if ((action = state_table[event][i]) != AVCT_LCB_IGNORE) {
(*avct_bcb_action[action])(p_bcb, p_data);
}{...} else {
break;
}{...}
}{...}
}{...}
/* ... */#endif
/* ... */
tAVCT_LCB *avct_lcb_by_bd(BD_ADDR bd_addr)
{
tAVCT_LCB *p_lcb = &avct_cb.lcb[0];
int i;
for (i = 0; i < AVCT_NUM_LINKS; i++, p_lcb++) {
if (p_lcb->allocated && (!memcmp(p_lcb->peer_addr, bd_addr, BD_ADDR_LEN))) {
break;
}{...}
}{...}
if (i == AVCT_NUM_LINKS) {
p_lcb = NULL;
AVCT_TRACE_DEBUG("No lcb for addr %02x-%02x-%02x-%02x-%02x-%02x",
bd_addr[0], bd_addr[1], bd_addr[2], bd_addr[3], bd_addr[4], bd_addr[5]);
}{...}
return p_lcb;
}{...}
/* ... */
tAVCT_LCB *avct_lcb_alloc(BD_ADDR bd_addr)
{
tAVCT_LCB *p_lcb = &avct_cb.lcb[0];
int i;
for (i = 0; i < AVCT_NUM_LINKS; i++, p_lcb++) {
if (!p_lcb->allocated) {
p_lcb->allocated = (UINT8)(i + 1);
memcpy(p_lcb->peer_addr, bd_addr, BD_ADDR_LEN);
AVCT_TRACE_DEBUG("avct_lcb_alloc %d", p_lcb->allocated);
p_lcb->tx_q = fixed_queue_new(QUEUE_SIZE_MAX);
break;
}{...}
}{...}
if (i == AVCT_NUM_LINKS) {
p_lcb = NULL;
AVCT_TRACE_WARNING("Out of lcbs");
}{...}
return p_lcb;
}{...}
/* ... */
void avct_lcb_dealloc(tAVCT_LCB *p_lcb, tAVCT_LCB_EVT *p_data)
{
UNUSED(p_data);
AVCT_TRACE_DEBUG("%s allocated: %d", __func__, p_lcb->allocated);
tAVCT_CCB *p_ccb = &avct_cb.ccb[0];
for (size_t i = 0; i < AVCT_NUM_CONN; i++, p_ccb++)
{
if (p_ccb->allocated && p_ccb->p_lcb == p_lcb)
{
AVCT_TRACE_DEBUG("%s LCB in use; lcb index: %d", __func__, i);
return;
}{...}
}{...}
AVCT_TRACE_DEBUG("%s Freeing LCB", __func__);
osi_free(p_lcb->p_rx_msg);
fixed_queue_free(p_lcb->tx_q, NULL);
memset(p_lcb, 0, sizeof(tAVCT_LCB));
}{...}
/* ... */
tAVCT_LCB *avct_lcb_by_lcid(UINT16 lcid)
{
tAVCT_LCB *p_lcb = &avct_cb.lcb[0];
int i;
for (i = 0; i < AVCT_NUM_LINKS; i++, p_lcb++) {
if (p_lcb->allocated && ((p_lcb->ch_lcid == lcid) || (p_lcb->conflict_lcid == lcid))) {
break;
}{...}
}{...}
if (i == AVCT_NUM_LINKS) {
p_lcb = NULL;
AVCT_TRACE_WARNING("No lcb for lcid %x", lcid);
}{...}
return p_lcb;
}{...}
/* ... */
tAVCT_CCB *avct_lcb_has_pid(tAVCT_LCB *p_lcb, UINT16 pid)
{
tAVCT_CCB *p_ccb = &avct_cb.ccb[0];
int i;
for (i = 0; i < AVCT_NUM_CONN; i++, p_ccb++) {
if (p_ccb->allocated && (p_ccb->p_lcb == p_lcb) && (p_ccb->cc.pid == pid)) {
return p_ccb;
}{...}
}{...}
return NULL;
}{...}
/* ... */
BOOLEAN avct_lcb_last_ccb(tAVCT_LCB *p_lcb, tAVCT_CCB *p_ccb_last)
{
tAVCT_CCB *p_ccb = &avct_cb.ccb[0];
int i;
AVCT_TRACE_DEBUG("avct_lcb_last_ccb");
for (i = 0; i < AVCT_NUM_CONN; i++, p_ccb++) {
AVCT_TRACE_DEBUG("%x: aloc:%d, lcb:%p/%p, ccb:%p/%p",
i, p_ccb->allocated, p_ccb->p_lcb, p_lcb, p_ccb, p_ccb_last);
if (p_ccb->allocated && (p_ccb->p_lcb == p_lcb) && (p_ccb != p_ccb_last)) {
return FALSE;
}{...}
}{...}
return TRUE;
}{...}
/* ... */
#endif