1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
51
52
53
54
55
56
57
58
59
60
66
67
68
74
75
76
82
83
84
85
86
87
88
89
90
91
92
93
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
142
143
167
168
174
175
176
177
178
179
180
181
182
183
184
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
216
217
218
219
220
221
222
223
224
225
226
227
228
232
236
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
388
389
390
391
396
397
403
404
405
406
/* ... */
/* ... */
#include <string.h>
#include "bta_ag_int.h"
#include "bta/bta_api.h"
#include "bta/bta_sys.h"
#include "bta/bta_ag_api.h"
#include "bta/bta_ag_co.h"
#include "bta/utl.h"
#include "stack/btm_api.h"
#include "stack/port_api.h"
#include "stack/rfcdefs.h"
#include "common/bt_trace.h"
#include "osi/allocator.h"12 includes
#if (BTA_AG_INCLUDED == TRUE)
#define BTA_AG_PORT_EV_MASK PORT_EV_RXCHAR
void bta_ag_port_cback_1(UINT32 code, UINT16 port_handle);
void bta_ag_port_cback_2(UINT32 code, UINT16 port_handle);
void bta_ag_port_cback_3(UINT32 code, UINT16 port_handle);
void bta_ag_mgmt_cback_1(UINT32 code, UINT16 port_handle, void* data);
void bta_ag_mgmt_cback_2(UINT32 code, UINT16 port_handle, void* data);
void bta_ag_mgmt_cback_3(UINT32 code, UINT16 port_handle, void* data);
int bta_ag_data_cback_1(UINT16 port_handle, void *p_data, UINT16 len);
int bta_ag_data_cback_2(UINT16 port_handle, void *p_data, UINT16 len);
int bta_ag_data_cback_3(UINT16 port_handle, void *p_data, UINT16 len);
typedef tPORT_CALLBACK *tBTA_AG_PORT_CBACK;
const tBTA_AG_PORT_CBACK bta_ag_port_cback_tbl[] =
{
bta_ag_port_cback_1,
bta_ag_port_cback_2,
bta_ag_port_cback_3
}{...};
typedef tPORT_MGMT_CALLBACK *tBTA_AG_MGMT_CBACK;
const tBTA_AG_MGMT_CBACK bta_ag_mgmt_cback_tbl[] =
{
bta_ag_mgmt_cback_1,
bta_ag_mgmt_cback_2,
bta_ag_mgmt_cback_3
}{...};
typedef tPORT_DATA_CALLBACK *tBTA_AG_DATA_CBACK;
const tBTA_AG_DATA_CBACK bta_ag_data_cback_tbl[] =
{
bta_ag_data_cback_1,
bta_ag_data_cback_2,
bta_ag_data_cback_3
}{...};
/* ... */
static void bta_ag_port_cback(UINT32 code, UINT16 port_handle, UINT16 handle)
{
BT_HDR *p_buf;
tBTA_AG_SCB *p_scb;
UNUSED(code);
if ((p_scb = bta_ag_scb_by_idx(handle)) != NULL) {
if (port_handle != p_scb->conn_handle) {
APPL_TRACE_DEBUG("ag_port_cback ignoring handle:%d conn_handle = %d other handle = %d",
port_handle, p_scb->conn_handle, handle);
return;
}{...}
if ((p_buf = (BT_HDR *) osi_malloc(sizeof(BT_HDR))) != NULL) {
p_buf->event = BTA_AG_RFC_DATA_EVT;
p_buf->layer_specific = handle;
bta_sys_sendmsg(p_buf);
}{...}
}{...}
}{...}
/* ... */
static void bta_ag_mgmt_cback(UINT32 code, UINT16 port_handle, UINT16 handle)
{
tBTA_AG_RFC *p_buf;
tBTA_AG_SCB *p_scb;
UINT16 event;
UINT8 i;
BOOLEAN found_handle = FALSE;
APPL_TRACE_DEBUG("ag_mgmt_cback : code = %d, port_handle = %d, handle = %d",
code, port_handle, handle);
if ((p_scb = bta_ag_scb_by_idx(handle)) != NULL) {
if ((code != PORT_SUCCESS) && (port_handle != p_scb->conn_handle)) {
APPL_TRACE_DEBUG("ag_mgmt_cback ignoring handle:%d", port_handle);
return;
}{...}
if (code == PORT_SUCCESS) {
if (p_scb->conn_handle) {
if (port_handle == p_scb->conn_handle)
found_handle = TRUE;
}{...} else {
for (i = 0; i < BTA_AG_NUM_IDX; i++) {
if (port_handle == p_scb->serv_handle[i])
found_handle = TRUE;
}{...}
}{...}
if (!found_handle) {
APPL_TRACE_ERROR ("bta_ag_mgmt_cback: PORT_SUCCESS, ignoring handle = %d", port_handle);
return;
}{...}
event = BTA_AG_RFC_OPEN_EVT;
}{...} else if (port_handle == p_scb->conn_handle) {
event = BTA_AG_RFC_CLOSE_EVT;
}{...} else {
event = BTA_AG_RFC_SRV_CLOSE_EVT;
}{...}
if ((p_buf = (tBTA_AG_RFC *) osi_malloc(sizeof(tBTA_AG_RFC))) != NULL) {
p_buf->hdr.event = event;
p_buf->hdr.layer_specific = handle;
p_buf->port_handle = port_handle;
bta_sys_sendmsg(p_buf);
}{...}
}{...}
}{...}
/* ... */
static int bta_ag_data_cback(UINT16 port_handle, void *p_data, UINT16 len, UINT16 handle)
{
UNUSED(port_handle);
#if (BTM_SCO_HCI_INCLUDED == TRUE)
bta_ag_co_tx_write(handle, (UINT8 *) p_data, len);
#endif
return 0;
}{...}
/* ... */
void bta_ag_mgmt_cback_1(UINT32 code, UINT16 handle, void* data) {bta_ag_mgmt_cback(code, handle, 1);}
void bta_ag_mgmt_cback_2(UINT32 code, UINT16 handle, void* data) {bta_ag_mgmt_cback(code, handle, 2);}
void bta_ag_mgmt_cback_3(UINT32 code, UINT16 handle, void* data) {bta_ag_mgmt_cback(code, handle, 3);}
void bta_ag_port_cback_1(UINT32 code, UINT16 handle) {bta_ag_port_cback(code, handle, 1);}
void bta_ag_port_cback_2(UINT32 code, UINT16 handle) {bta_ag_port_cback(code, handle, 2);}
void bta_ag_port_cback_3(UINT32 code, UINT16 handle) {bta_ag_port_cback(code, handle, 3);}
/* ... */
int bta_ag_data_cback_1(UINT16 port_handle, void *p_data, UINT16 len)
{
return bta_ag_data_cback(port_handle, p_data, len, 1);
}{...}
int bta_ag_data_cback_2(UINT16 port_handle, void *p_data, UINT16 len)
{
return bta_ag_data_cback(port_handle, p_data, len, 2);
}{...}
int bta_ag_data_cback_3(UINT16 port_handle, void *p_data, UINT16 len)
{
return bta_ag_data_cback(port_handle, p_data, len, 3);
}{...}
/* ... */
void bta_ag_setup_port(tBTA_AG_SCB *p_scb, UINT16 handle)
{
UINT16 i = bta_ag_scb_to_idx(p_scb) - 1;
if (bta_ag_cb.parse_mode == BTA_AG_PASS_THROUGH) {
PORT_SetDataCallback(handle, bta_ag_data_cback_tbl[i]);
}{...}
PORT_SetEventMask(handle, BTA_AG_PORT_EV_MASK);
PORT_SetEventCallback(handle, bta_ag_port_cback_tbl[i]);
}{...}
/* ... */
void bta_ag_start_servers(tBTA_AG_SCB *p_scb, tBTA_SERVICE_MASK services)
{
int bta_ag_port_status;
services >>= BTA_HSP_SERVICE_ID;
for (int i = 0; i < BTA_AG_NUM_IDX && services != 0; i++, services >>= 1) {
if (services & 1) {
BTM_SetSecurityLevel(FALSE, "", bta_ag_sec_id[i], p_scb->serv_sec_mask,
BT_PSM_RFCOMM, BTM_SEC_PROTO_RFCOMM, bta_ag_cb.profile[i].scn);
bta_ag_port_status = RFCOMM_CreateConnection(bta_ag_uuid[i], bta_ag_cb.profile[i].scn,
TRUE, BTA_AG_MTU, (UINT8 *) bd_addr_any, &(p_scb->serv_handle[i]),
bta_ag_mgmt_cback_tbl[bta_ag_scb_to_idx(p_scb) - 1]);
if( bta_ag_port_status == PORT_SUCCESS ) {
bta_ag_setup_port(p_scb, p_scb->serv_handle[i]);
}{...} else {
APPL_TRACE_DEBUG("bta_ag_start_servers: RFCOMM_CreateConnection returned error:%d", bta_ag_port_status);
}{...}
}{...}
}{...}
}{...}
/* ... */
void bta_ag_close_servers(tBTA_AG_SCB *p_scb, tBTA_SERVICE_MASK services)
{
int i;
services >>= BTA_HSP_SERVICE_ID;
for (i = 0; i < BTA_AG_NUM_IDX && services != 0; i++, services >>= 1) {
if (services & 1) {
RFCOMM_RemoveServer(p_scb->serv_handle[i]);
p_scb->serv_handle[i] = 0;
}{...}
}{...}
}{...}
/* ... */
BOOLEAN bta_ag_is_server_closed (tBTA_AG_SCB *p_scb)
{
UINT8 i;
BOOLEAN is_closed = TRUE;
for (i = 0; i < BTA_AG_NUM_IDX; i++) {
if (p_scb->serv_handle[i] != 0)
is_closed = FALSE;
}{...}
return is_closed;
}{...}
/* ... */
void bta_ag_rfc_do_open(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data)
{
BTM_SetSecurityLevel(TRUE, "", bta_ag_sec_id[p_scb->conn_service],
p_scb->cli_sec_mask, BT_PSM_RFCOMM, BTM_SEC_PROTO_RFCOMM, p_scb->peer_scn);
if (RFCOMM_CreateConnection(bta_ag_uuid[p_scb->conn_service], p_scb->peer_scn,
FALSE, BTA_AG_MTU, p_scb->peer_addr, &(p_scb->conn_handle),
bta_ag_mgmt_cback_tbl[bta_ag_scb_to_idx(p_scb) - 1]) == PORT_SUCCESS) {
bta_ag_setup_port(p_scb, p_scb->conn_handle);
APPL_TRACE_DEBUG("bta_ag_rfc_do_open : conn_handle = %d", p_scb->conn_handle);
}{...} else {
bta_ag_sm_execute(p_scb, BTA_AG_RFC_CLOSE_EVT, p_data);
}{...}
}{...}
/* ... */
void bta_ag_rfc_do_close(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data)
{
tBTA_AG_RFC *p_buf;
UNUSED(p_data);
if (p_scb->conn_handle) {
RFCOMM_RemoveConnection(p_scb->conn_handle);
}{...} else {
if ((p_buf = (tBTA_AG_RFC *) osi_malloc(sizeof(tBTA_AG_RFC))) != NULL) {
p_buf->hdr.event = BTA_AG_RFC_CLOSE_EVT;
p_buf->hdr.layer_specific = bta_ag_scb_to_idx(p_scb);
bta_sys_sendmsg(p_buf);
}{...}
/* ... */
}{...}
}{...}
/* ... */
#endif