1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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
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
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
255
256
257
258
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
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
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
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
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
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
444
445
446
447
448
449
450
451
452
453
454
455
456
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
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
|
/*****************************************************************************/
/* */
/* Name: dun_api.c */
/* */
/* Description: This file contains the DUN API routines */
/* */
/* */
/* Copyright (c) 1999-2009, Broadcom Corp., All Rights Reserved. */
/* Broadcom Bluetooth Core. Proprietary and confidential. */
/*****************************************************************************/
#include <string.h>
#include "bt_target.h"
#include "btm_api.h"
#include "port_api.h"
#include "dun_api.h"
#include "dun_int.h"
#include "rfcdefs.h"
/*****************************************************************************
** Constants
*****************************************************************************/
/* Number of attributes in DUN and Fax SDP records. */
#define DUN_NUM_ATTR_DUN 4
#define DUN_NUM_ATTR_FAX 7
/* Number of protocol elements in protocol element list. */
#define DUN_NUM_PROTO_ELEMS 2
/* Global DUN/FAX control block structure
*/
#if DUN_DYNAMIC_MEMORY == FALSE
tDUN_CB dun_cb;
#endif
/******************************************************************************
**
** Function dun_sdp_cback
**
** Description This is the SDP callback function used by DUN_FindService.
** This function will be executed by SDP when the service
** search is completed. If the search is successful, it
** finds the first record in the database that matches the
** UUID of the search. Then retrieves various parameters
** from the record. When it is finished it calls the
** application callback function.
**
** Returns Nothing.
**
******************************************************************************/
static void dun_sdp_cback(UINT16 status)
{
tSDP_DISC_REC *p_rec = NULL;
tSDP_DISC_ATTR *p_attr;
tSDP_PROTOCOL_ELEM pe;
UINT8 scn = 0;
UINT16 name_len = 0;
char *p_name = "";
UINT16 options = 0;
BOOLEAN found = FALSE;
DUN_TRACE_API1("dun_sdp_cback status: %d", status);
if (status == SDP_SUCCESS)
{
/* loop through all records we found */
do
{
/* get next record; if none found, we're done */
if ((p_rec = SDP_FindServiceInDb(dun_cb.find_cb.p_db,
dun_cb.find_cb.service_uuid, p_rec)) == NULL)
{
break;
}
/* get scn from proto desc list; if not found, go to next record */
if (SDP_FindProtocolListElemInRec(p_rec, UUID_PROTOCOL_RFCOMM, &pe))
{
scn = (UINT8) pe.params[0];
}
else
{
continue;
}
/* get service name */
if ((p_attr = SDP_FindAttributeInRec(p_rec,
ATTR_ID_SERVICE_NAME)) != NULL)
{
p_name = (char *) p_attr->attr_value.v.array;
name_len = SDP_DISC_ATTR_LEN(p_attr->attr_len_type);
}
/* get audio support */
if ((p_attr = SDP_FindAttributeInRec(p_rec,
ATTR_ID_AUDIO_FEEDBACK_SUPPORT)) != NULL)
{
options |= (p_attr->attr_value.v.u8) ? DUN_OPTIONS_AUDIO : 0;
}
/* get fax options */
if(dun_cb.find_cb.service_uuid == UUID_SERVCLASS_FAX)
{
if ((p_attr = SDP_FindAttributeInRec(p_rec,
ATTR_ID_FAX_CLASS_1_SUPPORT)) != NULL)
{
options |= (p_attr->attr_value.v.u8) ? DUN_OPTIONS_CLASS1 : 0;
}
if ((p_attr = SDP_FindAttributeInRec(p_rec,
ATTR_ID_FAX_CLASS_2_0_SUPPORT)) != NULL)
{
options |= (p_attr->attr_value.v.u8) ? DUN_OPTIONS_CLASS20 : 0;
}
if ((p_attr = SDP_FindAttributeInRec(p_rec,
ATTR_ID_FAX_CLASS_2_SUPPORT)) != NULL)
{
options |= (p_attr->attr_value.v.u8) ? DUN_OPTIONS_CLASS2 : 0;
}
}
/* we've got everything, we're done */
found = TRUE;
break;
} while (TRUE);
}
/* return info from sdp record in app callback function */
if (dun_cb.find_cb.p_cback != NULL)
{
(*dun_cb.find_cb.p_cback)(found, scn, p_name, name_len, options);
}
return;
}
/******************************************************************************
**
** Function DUN_Listen
**
** Description This function opens a DUN or Fax connection in server mode.
** It configures the security settings for the connection and
** opens an RFCOMM connection in server mode. It returns
** the handle for the RFCOMM connection.
**
** Input Parameters:
** service_uuid: Indicates DUN or Fax.
**
** p_service_name: A null-terminated character string
** containing the service name. This is used for security.
**
** scn: The server channel number for the RFCOMM
** connection.
**
** mtu: The MTU, or maximum data frame size, for the
** RFCOMM connection.
**
** security_mask: Security configuration. See the BTM API.
**
** p_cback: RFCOMM port callback function. See the
** RFCOMM API.
**
** Output Parameters:
** p_handle: The handle for the RFCOMM connection.
** This value is used in subsequent calls to the RFCOMM API.
**
** Returns DUN_SUCCESS if function execution succeeded,
** DUN_FAIL if function execution failed.
**
******************************************************************************/
UINT8 DUN_Listen(UINT16 service_uuid, char *p_service_name, UINT8 scn, UINT16 mtu,
UINT8 security_mask, UINT16 *p_handle, tPORT_CALLBACK *p_cback)
{
BD_ADDR bd_addr = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
UINT8 status = DUN_SUCCESS;
UINT8 service_id;
DUN_TRACE_API1("DUN_Listen uuid: %x", service_uuid);
switch (service_uuid)
{
case UUID_SERVCLASS_DIALUP_NETWORKING:
service_id = BTM_SEC_SERVICE_DUN;
break;
case UUID_SERVCLASS_FAX:
service_id = BTM_SEC_SERVICE_FAX;
break;
case UUID_SERVCLASS_SERIAL_PORT:
default:
service_id = BTM_SEC_SERVICE_SERIAL_PORT;
break;
}
/* set up security */
if (BTM_SetSecurityLevel(FALSE, (char *) p_service_name, service_id,
security_mask, BT_PSM_RFCOMM, BTM_SEC_PROTO_RFCOMM, scn) == FALSE)
{
status = DUN_FAIL;
}
/* open rfcomm server connection */
if (status == DUN_SUCCESS)
{
if (RFCOMM_CreateConnection(service_uuid, scn, TRUE, mtu, bd_addr,
p_handle, p_cback) != PORT_SUCCESS)
{
status = DUN_FAIL;
}
}
return status;
}
/******************************************************************************
**
** Function DUN_Connect
**
** Description This function opens a DUN or Fax client connection.
** It configures the security settings for the connection
** and opens an RFCOMM connection in server mode.
** It returns the handle for the RFCOMM connection.
**
** Input Parameters:
** service_uuid: Indicates DUN or Fax.
**
** bd_addr: BD address of the peer device.
**
** scn: The server channel number for the RFCOMM
** connection.
**
** mtu: The MTU, or maximum data frame size, for the
** RFCOMM connection.
**
** security_mask: Security configuration. See the BTM API.
**
** p_cback: RFCOMM port callback function. See the
** RFCOMM API.
**
** Output Parameters:
** p_handle: The handle for the RFCOMM connection.
** This value is used in subsequent calls to the RFCOMM API.
**
** Returns DUN_SUCCESS if function execution succeeded,
** DUN_FAIL if function execution failed.
**
******************************************************************************/
UINT8 DUN_Connect(UINT16 service_uuid, BD_ADDR bd_addr, UINT8 scn, UINT16 mtu,
UINT8 security_mask, UINT16 *p_handle, tPORT_CALLBACK *p_cback)
{
char name[] = ""; /* don't bother using a name for security */
UINT8 status = DUN_SUCCESS;
UINT8 service_id;
DUN_TRACE_API1("DUN_Connect uuid: %x", service_uuid);
switch (service_uuid)
{
case UUID_SERVCLASS_DIALUP_NETWORKING:
service_id = BTM_SEC_SERVICE_DUN;
break;
case UUID_SERVCLASS_FAX:
service_id = BTM_SEC_SERVICE_FAX;
break;
case UUID_SERVCLASS_SERIAL_PORT:
default:
service_id = BTM_SEC_SERVICE_SERIAL_PORT;
break;
}
/* set up security */
if(BTM_SetSecurityLevel(TRUE, name, service_id, security_mask,
BT_PSM_RFCOMM, BTM_SEC_PROTO_RFCOMM, scn) == FALSE)
{
status = DUN_FAIL;
}
/* open rfcomm client connection */
if (status == DUN_SUCCESS)
{
if (RFCOMM_CreateConnection(service_uuid, scn, FALSE, mtu, bd_addr,
p_handle, p_cback) != PORT_SUCCESS)
{
status = DUN_FAIL;
}
}
return status;
}
/******************************************************************************
**
** Function DUN_Close
**
** Description This function closes a DUN or Fax client connection
** previously opened with DUN_Connect().
**
** Input Parameters:
** handle: The handle for the RFCOMM connection
** previously returned by DUN_Connect().
**
** Output Parameters:
** None.
**
** Returns DUN_SUCCESS if function execution succeeded,
** DUN_FAIL if function execution failed.
**
******************************************************************************/
UINT8 DUN_Close(UINT16 handle)
{
UINT8 status = DUN_SUCCESS;
DUN_TRACE_API0("DUN_close");
if (RFCOMM_RemoveConnection(handle) != PORT_SUCCESS)
{
status = DUN_FAIL;
}
return status;
}
/******************************************************************************
**
** Function DUN_Shutdown
**
** Description This function closes a DUN or Fax server connection
** previously opened with DUN_Listen(). It is called if
** the application wishes to close the DUN or Fax server
** connection at any time.
**
** Input Parameters:
** service_uuid: Indicates DUN or Fax.
**
** handle: The handle for the RFCOMM connection
** previously returned by DUN_Connect().
**
** Output Parameters:
** None.
**
** Returns DUN_SUCCESS if function execution succeeded,
** DUN_FAIL if function execution failed.
**
******************************************************************************/
UINT8 DUN_Shutdown(UINT16 handle)
{
UINT8 status = DUN_SUCCESS;
DUN_TRACE_API0("DUN_Shutdown");
/* close rfcomm connection */
if (RFCOMM_RemoveServer(handle) != PORT_SUCCESS)
{
status = DUN_FAIL;
}
return status;
}
/******************************************************************************
**
** Function DUN_AddRecord
**
** Description This function is called by a server application to add
** DUN or Fax information to an SDP record. Prior to
** calling this function the application must call
** SDP_CreateRecord() to create an SDP record.
**
** Input Parameters:
** service_uuid: Indicates DUN or Fax.
**
** p_service_name: Pointer to a null-terminated character
** string containing the service name.
**
** scn: The server channel number of the RFCOMM
** connection.
**
** options: Profile support options.
**
** sdp_handle: SDP handle returned by SDP_CreateRecord().
**
** Output Parameters:
** None.
**
** Returns DUN_SUCCESS if function execution succeeded,
** DUN_FAIL if function execution failed.
**
******************************************************************************/
UINT8 DUN_AddRecord(UINT16 service_uuid, char *p_service_name, UINT8 scn,
UINT16 options, UINT32 sdp_handle)
{
tSDP_PROTOCOL_ELEM proto_elem_list[DUN_NUM_PROTO_ELEMS];
UINT8 audio;
UINT8 class1;
UINT8 class20;
UINT8 class2;
UINT16 browse_list[1];
BOOLEAN result = TRUE;
DUN_TRACE_API1("DUN_AddRecord uuid: %x", service_uuid);
memset((void*) proto_elem_list, 0 , DUN_NUM_PROTO_ELEMS*sizeof(tSDP_PROTOCOL_ELEM));
/* add the protocol element sequence */
proto_elem_list[0].protocol_uuid = UUID_PROTOCOL_L2CAP;
proto_elem_list[0].num_params = 0;
proto_elem_list[1].protocol_uuid = UUID_PROTOCOL_RFCOMM;
proto_elem_list[1].num_params = 1;
proto_elem_list[1].params[0] = scn;
result &= SDP_AddProtocolList(sdp_handle, DUN_NUM_PROTO_ELEMS, proto_elem_list);
/* add service class id list */
result &= SDP_AddServiceClassIdList(sdp_handle, 1, &service_uuid);
/* add service name */
if (p_service_name != NULL)
{
result &= SDP_AddAttribute(sdp_handle, ATTR_ID_SERVICE_NAME, TEXT_STR_DESC_TYPE,
(UINT32)(strlen(p_service_name)+1), (UINT8 *) p_service_name);
}
/* add audio feedback support */
if((service_uuid == UUID_SERVCLASS_FAX) ||
(service_uuid == UUID_SERVCLASS_DIALUP_NETWORKING))
{
audio = (options & DUN_OPTIONS_AUDIO) ? TRUE : FALSE;
result &= SDP_AddAttribute(sdp_handle, ATTR_ID_AUDIO_FEEDBACK_SUPPORT,
BOOLEAN_DESC_TYPE, 1, &audio);
}
/* add fax service class support */
if(service_uuid == UUID_SERVCLASS_FAX)
{
class1 = (options & DUN_OPTIONS_CLASS1) ? TRUE : FALSE;
result &= SDP_AddAttribute(sdp_handle, ATTR_ID_FAX_CLASS_1_SUPPORT,
BOOLEAN_DESC_TYPE, 1, &class1);
class20 = (options & DUN_OPTIONS_CLASS20) ? TRUE : FALSE;
result &= SDP_AddAttribute(sdp_handle, ATTR_ID_FAX_CLASS_2_0_SUPPORT,
BOOLEAN_DESC_TYPE, 1, &class20);
class2 = (options & DUN_OPTIONS_CLASS2) ? TRUE : FALSE;
result &= SDP_AddAttribute(sdp_handle, ATTR_ID_FAX_CLASS_2_SUPPORT,
BOOLEAN_DESC_TYPE, 1, &class2);
}
/* add browse group list */
browse_list[0] = UUID_SERVCLASS_PUBLIC_BROWSE_GROUP;
result &= SDP_AddUuidSequence(sdp_handle, ATTR_ID_BROWSE_GROUP_LIST, 1, browse_list);
/* add profile descriptor list */
if (service_uuid != UUID_SERVCLASS_SERIAL_PORT) /* BQB fix: BTA DG uses this for SPP */
result &= SDP_AddProfileDescriptorList(sdp_handle, service_uuid, 0x0100);
return (result ? DUN_SUCCESS : DUN_FAIL);
}
/******************************************************************************
**
** Function DUN_FindService
**
** Description This function is called by a client application to
** perform service discovery and retrieve DUN or Fax SDP
** record information from a server. Information is
** returned for the first service record found on the
** server that matches the service UUID. The callback
** function will be executed when service discovery is
** complete. There can only be one outstanding call to
** DUN_FindService() at a time; the application must wait
** for the callback before it makes another call to
** the function.
**
** Input Parameters:
** service_uuid: Indicates DUN or Fax.
**
** bd_addr: BD address of the peer device.
**
** p_db: Pointer to the discovery database.
**
** db_len: Length, in bytes, of the discovery database.
**
** p_cback: Pointer to the DUN_FindService()
** callback function.
**
** Output Parameters:
** None.
**
** Returns DUN_SUCCESS if function execution succeeded,
** DUN_FAIL if function execution failed.
**
******************************************************************************/
UINT8 DUN_FindService(UINT16 service_uuid, BD_ADDR bd_addr,
tSDP_DISCOVERY_DB *p_db, UINT32 db_len, tDUN_FIND_CBACK *p_cback)
{
tSDP_UUID uuid_list;
UINT16 num_attr;
BOOLEAN result = TRUE;
UINT16 dun_attr_list[] = {ATTR_ID_SERVICE_CLASS_ID_LIST,
ATTR_ID_PROTOCOL_DESC_LIST,
ATTR_ID_SERVICE_NAME,
ATTR_ID_AUDIO_FEEDBACK_SUPPORT,
ATTR_ID_FAX_CLASS_1_SUPPORT,
ATTR_ID_FAX_CLASS_2_0_SUPPORT,
ATTR_ID_FAX_CLASS_2_SUPPORT};
DUN_TRACE_API1("DUN_FindService uuid: %x", service_uuid);
/* set up discovery database */
uuid_list.len = LEN_UUID_16;
uuid_list.uu.uuid16 = service_uuid;
num_attr = (service_uuid == UUID_SERVCLASS_FAX) ?
DUN_NUM_ATTR_FAX : DUN_NUM_ATTR_DUN;
result = SDP_InitDiscoveryDb(p_db, db_len, 1, &uuid_list, num_attr,
(UINT16 *) dun_attr_list);
if (result == TRUE)
{
/* store service_uuid and discovery db pointer */
dun_cb.find_cb.p_db = p_db;
dun_cb.find_cb.service_uuid = service_uuid;
dun_cb.find_cb.p_cback = p_cback;
/* perform service search */
result = SDP_ServiceSearchAttributeRequest(bd_addr, p_db, dun_sdp_cback);
}
return (result ? DUN_SUCCESS : DUN_FAIL);
}
/*******************************************************************************
**
** Function DUN_Init
**
** Description This function is called to initialize the control block
** for this layer. It must be called before accessing any
** other API functions for this layer. It is typically called
** once during the start up of the stack.
**
** Returns void
**
*******************************************************************************/
void DUN_Init (void)
{
/* All fields are cleared; nonzero fields are reinitialized in appropriate function */
memset(&dun_cb, 0, sizeof(tDUN_CB));
#if defined(DUN_INITIAL_TRACE_LEVEL)
dun_cb.trace_level = DUN_INITIAL_TRACE_LEVEL;
#else
dun_cb.trace_level = BT_TRACE_LEVEL_NONE; /* No traces */
#endif
}
/******************************************************************************
**
** Function DUN_SetTraceLevel
**
** Description Sets the trace level for DUN. If 0xff is passed, the
** current trace level is returned.
**
** Input Parameters:
** new_level: The level to set the DUN tracing to:
** 0xff-returns the current setting.
** 0-turns off tracing.
** >= 1-Errors.
** >= 2-Warnings.
** >= 3-APIs.
** >= 4-Events.
** >= 5-Debug.
**
** Returns The new trace level or current trace level if
** the input parameter is 0xff.
**
******************************************************************************/
UINT8 DUN_SetTraceLevel (UINT8 new_level)
{
if (new_level != 0xFF)
dun_cb.trace_level = new_level;
return (dun_cb.trace_level);
}
|