1 /******************************************************************************
2 *
3 * Copyright (C) 1998-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 #include <string.h>
20
21 #include "bt_target.h"
22 #if defined(HL_INCLUDED) && (HL_INCLUDED == TRUE)
23
24 #include "sdp_api.h"
25 #include "bta_hl_int.h"
26 #include "utl.h"
27
28 /*******************************************************************************
29 **
30 ** Function bta_hl_fill_sup_feature_list
31 **
32 ** Description Fill the supported features from teh SDP record
33 **
34 ** Returns TRUE if found, FALSE if not
35 ** If found, the passed protocol list element is filled in.
36 **
37 *******************************************************************************/
bta_hl_fill_sup_feature_list(const tSDP_DISC_ATTR * p_attr,tBTA_HL_SUP_FEATURE_LIST_ELEM * p_list)38 BOOLEAN bta_hl_fill_sup_feature_list( const tSDP_DISC_ATTR *p_attr,
39 tBTA_HL_SUP_FEATURE_LIST_ELEM *p_list)
40 {
41 tSDP_DISC_ATTR *p_sattr;
42 UINT8 item_cnt;
43 UINT8 list_cnt=0;
44 BOOLEAN status=TRUE;
45
46 for (p_attr = p_attr->attr_value.v.p_sub_attr; p_attr; p_attr = p_attr->p_next_attr)
47 {
48 /* mdep sequence */
49 if (SDP_DISC_ATTR_TYPE(p_attr->attr_len_type) != DATA_ELE_SEQ_DESC_TYPE)
50 {
51 return(FALSE);
52 }
53 SDP_DISC_ATTR_LEN(p_attr->attr_len_type);
54 item_cnt=0;
55
56 for (p_sattr = p_attr->attr_value.v.p_sub_attr; p_sattr && (item_cnt < 4) ; p_sattr = p_sattr->p_next_attr)
57 {
58 /* for each mdep list */
59
60 p_list->list_elem[list_cnt].p_mdep_desp = NULL;
61 switch (item_cnt)
62 {
63 case 0:
64 p_list->list_elem[list_cnt].mdep_id = p_sattr->attr_value.v.u8;
65 break;
66 case 1:
67 p_list->list_elem[list_cnt].data_type = p_sattr->attr_value.v.u16;
68 break;
69 case 2:
70 p_list->list_elem[list_cnt].mdep_role = (tBTA_HL_MDEP_ROLE) p_sattr->attr_value.v.u8;
71 break;
72 case 3:
73 p_list->list_elem[list_cnt].p_mdep_desp = (char *) p_sattr->attr_value.v.array;
74 break;
75 }
76
77 item_cnt++;
78 }
79 list_cnt++;
80 }
81 p_list->num_elems = list_cnt;
82 return(status);
83 }
84
85 /*******************************************************************************
86 **
87 ** Function bta_hl_compose_supported_feature_list
88 **
89 ** Description This function is called to compose a data sequence from
90 ** the supported feature element list struct pointer
91 **
92 ** Returns the length of the data sequence
93 **
94 *******************************************************************************/
bta_hl_compose_supported_feature_list(UINT8 * p,UINT16 num_elem,const tBTA_HL_SUP_FEATURE_ELEM * p_elem_list)95 int bta_hl_compose_supported_feature_list( UINT8 *p, UINT16 num_elem,
96 const tBTA_HL_SUP_FEATURE_ELEM *p_elem_list)
97 {
98 UINT16 xx, str_len, seq_len;
99 UINT8 *p_head = p;
100
101 for (xx = 0; xx < num_elem; xx++, p_elem_list++)
102 {
103 UINT8_TO_BE_STREAM (p, (DATA_ELE_SEQ_DESC_TYPE << 3) | SIZE_IN_NEXT_BYTE);
104 seq_len=7;
105 str_len=0;
106 if (p_elem_list->p_mdep_desp)
107 {
108 str_len = strlen(p_elem_list->p_mdep_desp)+1;
109 seq_len += str_len+2; /* todo add a # symbol for 2 */
110 }
111
112 *p++ = (UINT8) seq_len;
113
114 UINT8_TO_BE_STREAM (p, (UINT_DESC_TYPE << 3) | SIZE_ONE_BYTE);
115 UINT8_TO_BE_STREAM (p, p_elem_list->mdep_id);
116 UINT8_TO_BE_STREAM (p, (UINT_DESC_TYPE << 3) | SIZE_TWO_BYTES);
117 UINT16_TO_BE_STREAM (p, p_elem_list->data_type);
118 UINT8_TO_BE_STREAM (p, (UINT_DESC_TYPE << 3) | SIZE_ONE_BYTE);
119 UINT8_TO_BE_STREAM (p, p_elem_list->mdep_role);
120
121 if (str_len)
122 {
123 UINT8_TO_BE_STREAM (p, (TEXT_STR_DESC_TYPE << 3) | SIZE_IN_NEXT_BYTE);
124 UINT8_TO_BE_STREAM (p, str_len);
125 ARRAY_TO_BE_STREAM(p, p_elem_list->p_mdep_desp, str_len);
126 }
127 }
128
129 return(p - p_head);
130 }
131
132 /*******************************************************************************
133 **
134 ** Function bta_hl_add_sup_feature_list
135 **
136 ** Description This function is called to add a protocol descriptor list to
137 ** a record. This would be through the SDP database maintenance API.
138 ** If the protocol list already exists in the record, it is replaced
139 ** with the new list.
140 **
141 ** Returns TRUE if added OK, else FALSE
142 **
143 *******************************************************************************/
bta_hl_add_sup_feature_list(UINT32 handle,UINT16 num_elem,const tBTA_HL_SUP_FEATURE_ELEM * p_elem_list)144 BOOLEAN bta_hl_add_sup_feature_list (UINT32 handle, UINT16 num_elem,
145 const tBTA_HL_SUP_FEATURE_ELEM *p_elem_list)
146 {
147 UINT8 *p_buf;
148 int offset;
149 BOOLEAN result = FALSE;
150
151 if ((p_buf = (UINT8 *)GKI_getbuf(BTA_HL_SUP_FEATURE_SDP_BUF_SIZE)) != NULL)
152 {
153 offset = bta_hl_compose_supported_feature_list(p_buf, num_elem, p_elem_list);
154 result = SDP_AddAttribute (handle, ATTR_ID_HDP_SUP_FEAT_LIST,
155 DATA_ELE_SEQ_DESC_TYPE, (UINT32) offset, p_buf);
156 GKI_freebuf(p_buf);
157 }
158 return result;
159 }
160
161 /*****************************************************************************
162 **
163 ** Function: bta_hl_sdp_update
164 **
165 ** Purpose: Register an HDP application with SDP
166 **
167 ** Parameters:
168 **
169 ** Returns: void
170 **
171 *****************************************************************************/
bta_hl_sdp_update(UINT8 app_id)172 tBTA_HL_STATUS bta_hl_sdp_update (UINT8 app_id)
173 {
174 UINT16 svc_class_id_list[BTA_HL_NUM_SVC_ELEMS];
175 tSDP_PROTOCOL_ELEM proto_elem_list[BTA_HL_NUM_PROTO_ELEMS];
176 tSDP_PROTO_LIST_ELEM add_proto_list;
177 tBTA_HL_SUP_FEATURE_LIST_ELEM sup_feature_list;
178 UINT16 browse_list[] = {UUID_SERVCLASS_PUBLIC_BROWSE_GROUP};
179 UINT8 i,j, cnt,mdep_id, mdep_role;
180 UINT8 data_exchange_spec = BTA_HL_SDP_IEEE_11073_20601;
181 UINT8 mcap_sup_proc = BTA_HL_MCAP_SUP_PROC_MASK;
182 UINT16 profile_uuid = UUID_SERVCLASS_HDP_PROFILE;
183 UINT16 version = BTA_HL_VERSION_01_00;
184 UINT8 num_services=1;
185 tBTA_HL_APP_CB *p_cb = BTA_HL_GET_APP_CB_PTR(0);
186 BOOLEAN result = TRUE;
187 tBTA_HL_STATUS status = BTA_HL_STATUS_OK;
188 UNUSED(app_id);
189
190 if ((p_cb->sup_feature.app_role_mask == BTA_HL_MDEP_ROLE_MASK_SOURCE) &&
191 (!p_cb->sup_feature.advertize_source_sdp))
192 {
193 return BTA_HL_STATUS_OK;
194 }
195
196 num_services=1;
197 svc_class_id_list[0]= UUID_SERVCLASS_HDP_SOURCE;
198 if (p_cb->sup_feature.app_role_mask == BTA_HL_MDEP_ROLE_MASK_SINK)
199 {
200 svc_class_id_list[0]= UUID_SERVCLASS_HDP_SINK;
201 }
202 else
203 {
204 if (p_cb->sup_feature.app_role_mask != BTA_HL_MDEP_ROLE_MASK_SOURCE)
205 {
206 /* dual role */
207 num_services=2;
208 svc_class_id_list[1]= UUID_SERVCLASS_HDP_SINK;
209 }
210 }
211 result &= SDP_AddServiceClassIdList(p_cb->sdp_handle, num_services, svc_class_id_list);
212
213 if (result)
214 {
215 /* add the protocol element sequence */
216 proto_elem_list[0].protocol_uuid = UUID_PROTOCOL_L2CAP;
217 proto_elem_list[0].num_params = 1;
218 proto_elem_list[0].params[0] = p_cb->ctrl_psm;
219 proto_elem_list[1].protocol_uuid = UUID_PROTOCOL_MCAP_CTRL;
220 proto_elem_list[1].num_params = 1;
221 proto_elem_list[1].params[0] = version;
222 result &= SDP_AddProtocolList(p_cb->sdp_handle, BTA_HL_NUM_PROTO_ELEMS, proto_elem_list);
223
224 result &= SDP_AddProfileDescriptorList(p_cb->sdp_handle, profile_uuid, version);
225 }
226
227 if (result)
228 {
229 add_proto_list.num_elems = BTA_HL_NUM_ADD_PROTO_ELEMS;
230 add_proto_list.list_elem[0].protocol_uuid = UUID_PROTOCOL_L2CAP;
231 add_proto_list.list_elem[0].num_params = 1;
232 add_proto_list.list_elem[0].params[0] = p_cb->data_psm;
233 add_proto_list.list_elem[1].protocol_uuid = UUID_PROTOCOL_MCAP_DATA;
234 add_proto_list.list_elem[1].num_params = 0;
235 result &= SDP_AddAdditionProtoLists(p_cb->sdp_handle, BTA_HL_NUM_ADD_PROTO_LISTS,
236 (tSDP_PROTO_LIST_ELEM *)&add_proto_list);
237 }
238
239 if (result)
240 {
241 if (p_cb->srv_name[0] )
242 {
243 result &= SDP_AddAttribute(p_cb->sdp_handle,
244 (UINT16)ATTR_ID_SERVICE_NAME,
245 (UINT8)TEXT_STR_DESC_TYPE,
246 (UINT32)(strlen(p_cb->srv_name) + 1),
247 (UINT8 *)p_cb->srv_name);
248 } /* end of setting optional service name */
249 }
250
251 if (result)
252 {
253 if (p_cb->srv_desp[0] )
254 {
255 result &= SDP_AddAttribute(p_cb->sdp_handle,
256 (UINT16)ATTR_ID_SERVICE_DESCRIPTION,
257 (UINT8)TEXT_STR_DESC_TYPE,
258 (UINT32)(strlen(p_cb->srv_desp) + 1),
259 (UINT8 *)p_cb->srv_desp);
260
261 } /* end of setting optional service description */
262
263 }
264
265 if (result)
266 {
267 if (p_cb->provider_name[0] )
268 {
269 result &= SDP_AddAttribute(p_cb->sdp_handle,
270 (UINT16)ATTR_ID_PROVIDER_NAME,
271 (UINT8)TEXT_STR_DESC_TYPE,
272 (UINT32)(strlen(p_cb->provider_name) + 1),
273 (UINT8 *)p_cb->provider_name);
274 } /* end of setting optional provider name */
275 }
276
277 /* add supported feture list */
278
279 if (result)
280 {
281 cnt=0;
282 for (i=1; i< BTA_HL_NUM_MDEPS; i++)
283 {
284 if (p_cb->sup_feature.mdep[i].mdep_id)
285 {
286 mdep_id = (UINT8)p_cb->sup_feature.mdep[i].mdep_id;
287 mdep_role = (UINT8)p_cb->sup_feature.mdep[i].mdep_cfg.mdep_role;
288
289 APPL_TRACE_DEBUG("num_of_mdep_data_types %d ", p_cb->sup_feature.mdep[i].mdep_cfg.num_of_mdep_data_types);
290 for (j=0; j<p_cb->sup_feature.mdep[i].mdep_cfg.num_of_mdep_data_types; j++)
291 {
292 sup_feature_list.list_elem[cnt].mdep_id = mdep_id;
293 sup_feature_list.list_elem[cnt].mdep_role = mdep_role;
294 sup_feature_list.list_elem[cnt].data_type = p_cb->sup_feature.mdep[i].mdep_cfg.data_cfg[j].data_type;
295 if (p_cb->sup_feature.mdep[i].mdep_cfg.data_cfg[j].desp[0] != '\0')
296 {
297 sup_feature_list.list_elem[cnt].p_mdep_desp = p_cb->sup_feature.mdep[i].mdep_cfg.data_cfg[j].desp;
298 }
299 else
300 {
301 sup_feature_list.list_elem[cnt].p_mdep_desp = NULL;
302 }
303
304 cnt++;
305 if (cnt==BTA_HL_NUM_SUP_FEATURE_ELEMS)
306 {
307 result = FALSE;
308 break;
309 }
310 }
311 }
312 }
313 sup_feature_list.num_elems = cnt;
314 result &= bta_hl_add_sup_feature_list (p_cb->sdp_handle,
315 sup_feature_list.num_elems,
316 sup_feature_list.list_elem);
317 }
318 if (result)
319 {
320 result &= SDP_AddAttribute(p_cb->sdp_handle, ATTR_ID_HDP_DATA_EXCH_SPEC, UINT_DESC_TYPE,
321 (UINT32)1, (UINT8*)&data_exchange_spec);
322 }
323
324 if (result)
325 {
326
327 result &= SDP_AddAttribute(p_cb->sdp_handle, ATTR_ID_HDP_MCAP_SUP_PROC, UINT_DESC_TYPE,
328 (UINT32)1, (UINT8*)&mcap_sup_proc);
329 }
330
331 if (result)
332 {
333 result &= SDP_AddUuidSequence(p_cb->sdp_handle, ATTR_ID_BROWSE_GROUP_LIST, 1, browse_list);
334 }
335
336 if (result)
337 {
338 for(i=0; i < num_services; i++)
339 {
340 bta_sys_add_uuid(svc_class_id_list[i]);
341 APPL_TRACE_DEBUG("dbg bta_sys_add_uuid i=%d uuid=0x%x", i, svc_class_id_list[i]); //todo
342 }
343 }
344 else
345 {
346 if (p_cb->sdp_handle)
347 {
348 SDP_DeleteRecord(p_cb->sdp_handle);
349 p_cb->sdp_handle = 0;
350 }
351 status = BTA_HL_STATUS_SDP_FAIL;
352 }
353 #if BTA_HL_DEBUG == TRUE
354 APPL_TRACE_DEBUG("bta_hl_sdp_update status=%s", bta_hl_status_code(status));
355 #endif
356 return status;
357 }
358
359
360 /*****************************************************************************
361 **
362 ** Function: bta_hl_sdp_register
363 **
364 ** Purpose: Register an HDP application with SDP
365 **
366 ** Parameters: p_cb - Pointer to MA instance control block
367 ** p_service_name - MA server name
368 ** inst_id - MAS instance ID
369 ** msg_type - Supported message type(s)
370 **
371 **
372 ** Returns: void
373 **
374 *****************************************************************************/
bta_hl_sdp_register(UINT8 app_idx)375 tBTA_HL_STATUS bta_hl_sdp_register (UINT8 app_idx)
376 {
377 UINT16 svc_class_id_list[BTA_HL_NUM_SVC_ELEMS];
378 tSDP_PROTOCOL_ELEM proto_elem_list[BTA_HL_NUM_PROTO_ELEMS];
379 tSDP_PROTO_LIST_ELEM add_proto_list;
380 tBTA_HL_SUP_FEATURE_LIST_ELEM sup_feature_list;
381 UINT16 browse_list[] = {UUID_SERVCLASS_PUBLIC_BROWSE_GROUP};
382 UINT8 i,j, cnt,mdep_id, mdep_role;
383 UINT8 data_exchange_spec = BTA_HL_SDP_IEEE_11073_20601;
384 UINT8 mcap_sup_proc = BTA_HL_MCAP_SUP_PROC_MASK;
385 UINT16 profile_uuid = UUID_SERVCLASS_HDP_PROFILE;
386 UINT16 version = BTA_HL_VERSION_01_00;
387 UINT8 num_services=1;
388 tBTA_HL_APP_CB *p_cb = BTA_HL_GET_APP_CB_PTR(app_idx);
389 BOOLEAN result = TRUE;
390 tBTA_HL_STATUS status = BTA_HL_STATUS_OK;
391
392 #if BTA_HL_DEBUG == TRUE
393 APPL_TRACE_DEBUG("bta_hl_sdp_register app_idx=%d",app_idx);
394 #endif
395
396 if ((p_cb->sup_feature.app_role_mask == BTA_HL_MDEP_ROLE_MASK_SOURCE) &&
397 (!p_cb->sup_feature.advertize_source_sdp))
398 {
399 return BTA_HL_STATUS_OK;
400 }
401
402 if ((p_cb->sdp_handle = SDP_CreateRecord()) == 0)
403 {
404 return BTA_HL_STATUS_SDP_NO_RESOURCE;
405 }
406
407 num_services=1;
408 svc_class_id_list[0]= UUID_SERVCLASS_HDP_SOURCE;
409 if (p_cb->sup_feature.app_role_mask == BTA_HL_MDEP_ROLE_MASK_SINK)
410 {
411 svc_class_id_list[0]= UUID_SERVCLASS_HDP_SINK;
412 }
413 else
414 {
415 if (p_cb->sup_feature.app_role_mask != BTA_HL_MDEP_ROLE_MASK_SOURCE)
416 {
417 /* dual role */
418 num_services=2;
419 svc_class_id_list[1]= UUID_SERVCLASS_HDP_SINK;
420 }
421 }
422 result &= SDP_AddServiceClassIdList(p_cb->sdp_handle, num_services, svc_class_id_list);
423
424 if (result)
425 {
426 /* add the protocol element sequence */
427 proto_elem_list[0].protocol_uuid = UUID_PROTOCOL_L2CAP;
428 proto_elem_list[0].num_params = 1;
429 proto_elem_list[0].params[0] = p_cb->ctrl_psm;
430 proto_elem_list[1].protocol_uuid = UUID_PROTOCOL_MCAP_CTRL;
431 proto_elem_list[1].num_params = 1;
432 proto_elem_list[1].params[0] = version;
433 result &= SDP_AddProtocolList(p_cb->sdp_handle, BTA_HL_NUM_PROTO_ELEMS, proto_elem_list);
434
435 result &= SDP_AddProfileDescriptorList(p_cb->sdp_handle, profile_uuid, version);
436 }
437
438 if (result)
439 {
440 add_proto_list.num_elems = BTA_HL_NUM_ADD_PROTO_ELEMS;
441 add_proto_list.list_elem[0].protocol_uuid = UUID_PROTOCOL_L2CAP;
442 add_proto_list.list_elem[0].num_params = 1;
443 add_proto_list.list_elem[0].params[0] = p_cb->data_psm;
444 add_proto_list.list_elem[1].protocol_uuid = UUID_PROTOCOL_MCAP_DATA;
445 add_proto_list.list_elem[1].num_params = 0;
446 result &= SDP_AddAdditionProtoLists(p_cb->sdp_handle, BTA_HL_NUM_ADD_PROTO_LISTS,
447 (tSDP_PROTO_LIST_ELEM *)&add_proto_list);
448 }
449
450 if (result)
451 {
452 if (p_cb->srv_name[0] )
453 {
454 result &= SDP_AddAttribute(p_cb->sdp_handle,
455 (UINT16)ATTR_ID_SERVICE_NAME,
456 (UINT8)TEXT_STR_DESC_TYPE,
457 (UINT32)(strlen(p_cb->srv_name) + 1),
458 (UINT8 *)p_cb->srv_name);
459 } /* end of setting optional service name */
460 }
461
462 if (result)
463 {
464 if (p_cb->srv_desp[0] )
465 {
466 result &= SDP_AddAttribute(p_cb->sdp_handle,
467 (UINT16)ATTR_ID_SERVICE_DESCRIPTION,
468 (UINT8)TEXT_STR_DESC_TYPE,
469 (UINT32)(strlen(p_cb->srv_desp) + 1),
470 (UINT8 *)p_cb->srv_desp);
471
472 } /* end of setting optional service description */
473
474 }
475
476 if (result)
477 {
478 if (p_cb->provider_name[0] )
479 {
480 result &= SDP_AddAttribute(p_cb->sdp_handle,
481 (UINT16)ATTR_ID_PROVIDER_NAME,
482 (UINT8)TEXT_STR_DESC_TYPE,
483 (UINT32)(strlen(p_cb->provider_name) + 1),
484 (UINT8 *)p_cb->provider_name);
485 } /* end of setting optional provider name */
486 }
487
488 /* add supported feture list */
489
490 if (result)
491 {
492 cnt=0;
493 for (i=1; i<= p_cb->sup_feature.num_of_mdeps; i++)
494 {
495 mdep_id = (UINT8)p_cb->sup_feature.mdep[i].mdep_id;
496 mdep_role = (UINT8)p_cb->sup_feature.mdep[i].mdep_cfg.mdep_role;
497
498 for (j=0; j<p_cb->sup_feature.mdep[i].mdep_cfg.num_of_mdep_data_types; j++)
499 {
500 sup_feature_list.list_elem[cnt].mdep_id = mdep_id;
501 sup_feature_list.list_elem[cnt].mdep_role = mdep_role;
502 sup_feature_list.list_elem[cnt].data_type = p_cb->sup_feature.mdep[i].mdep_cfg.data_cfg[j].data_type;
503 if (p_cb->sup_feature.mdep[i].mdep_cfg.data_cfg[j].desp[0] != '\0')
504 {
505 sup_feature_list.list_elem[cnt].p_mdep_desp = p_cb->sup_feature.mdep[i].mdep_cfg.data_cfg[j].desp;
506 }
507 else
508 {
509 sup_feature_list.list_elem[cnt].p_mdep_desp = NULL;
510 }
511
512 cnt++;
513 if (cnt==BTA_HL_NUM_SUP_FEATURE_ELEMS)
514 {
515 result = FALSE;
516 break;
517 }
518 }
519 }
520 sup_feature_list.num_elems = cnt;
521 result &= bta_hl_add_sup_feature_list (p_cb->sdp_handle,
522 sup_feature_list.num_elems,
523 sup_feature_list.list_elem);
524 }
525 if (result)
526 {
527 result &= SDP_AddAttribute(p_cb->sdp_handle, ATTR_ID_HDP_DATA_EXCH_SPEC, UINT_DESC_TYPE,
528 (UINT32)1, (UINT8*)&data_exchange_spec);
529 }
530
531 if (result)
532 {
533
534 result &= SDP_AddAttribute(p_cb->sdp_handle, ATTR_ID_HDP_MCAP_SUP_PROC, UINT_DESC_TYPE,
535 (UINT32)1, (UINT8*)&mcap_sup_proc);
536 }
537
538 if (result)
539 {
540 result &= SDP_AddUuidSequence(p_cb->sdp_handle, ATTR_ID_BROWSE_GROUP_LIST, 1, browse_list);
541 }
542
543 if (result)
544 {
545 for(i=0; i < num_services; i++)
546 {
547 bta_sys_add_uuid(svc_class_id_list[i]);
548 APPL_TRACE_DEBUG("dbg bta_sys_add_uuid i=%d uuid=0x%x", i, svc_class_id_list[i]); //todo
549 }
550 }
551 else
552 {
553 if (p_cb->sdp_handle)
554 {
555 SDP_DeleteRecord(p_cb->sdp_handle);
556 p_cb->sdp_handle = 0;
557 }
558 status = BTA_HL_STATUS_SDP_FAIL;
559 }
560 #if BTA_HL_DEBUG == TRUE
561 APPL_TRACE_DEBUG("bta_hl_sdp_register status=%s", bta_hl_status_code(status));
562 #endif
563 return status;
564 }
565
566 /*******************************************************************************
567 **
568 ** Function bta_hl_find_sink_or_src_srv_class_in_db
569 **
570 ** Description This function queries an SDP database for either a HDP Sink or
571 ** Source service class ID.
572 ** If the p_start_rec pointer is NULL, it looks from the beginning
573 ** of the database, else it continues from the next record after
574 ** p_start_rec.
575 **
576 ** Returns Pointer to record containing service class, or NULL
577 **
578 *******************************************************************************/
bta_hl_find_sink_or_src_srv_class_in_db(const tSDP_DISCOVERY_DB * p_db,const tSDP_DISC_REC * p_start_rec)579 tSDP_DISC_REC *bta_hl_find_sink_or_src_srv_class_in_db (const tSDP_DISCOVERY_DB *p_db,
580 const tSDP_DISC_REC *p_start_rec)
581 {
582 #if SDP_CLIENT_ENABLED == TRUE
583 tSDP_DISC_REC *p_rec;
584 tSDP_DISC_ATTR *p_attr, *p_sattr;
585
586 /* Must have a valid database */
587 if (p_db == NULL)
588 return(NULL);
589
590
591 if (!p_start_rec)
592 {
593
594 p_rec = p_db->p_first_rec;
595 }
596 else
597 {
598 p_rec = p_start_rec->p_next_rec;
599 }
600
601 while (p_rec)
602 {
603 p_attr = p_rec->p_first_attr;
604 while (p_attr)
605 {
606 if ((p_attr->attr_id == ATTR_ID_SERVICE_CLASS_ID_LIST)
607 && (SDP_DISC_ATTR_TYPE(p_attr->attr_len_type) == DATA_ELE_SEQ_DESC_TYPE))
608 {
609 for (p_sattr = p_attr->attr_value.v.p_sub_attr; p_sattr; p_sattr = p_sattr->p_next_attr)
610 {
611 if ((SDP_DISC_ATTR_TYPE(p_sattr->attr_len_type) == UUID_DESC_TYPE)
612 && (SDP_DISC_ATTR_LEN(p_sattr->attr_len_type) == 2)
613 && ( (p_sattr->attr_value.v.u16 == UUID_SERVCLASS_HDP_SINK) ||
614 (p_sattr->attr_value.v.u16 == UUID_SERVCLASS_HDP_SOURCE)) )
615 {
616 return(p_rec);
617 }
618 }
619 break;
620 }
621
622 p_attr = p_attr->p_next_attr;
623 }
624
625 p_rec = p_rec->p_next_rec;
626 }
627 #endif
628 /* If here, no matching UUID found */
629
630 #if BTA_HL_DEBUG == TRUE
631 APPL_TRACE_DEBUG("bta_hl_find_sink_or_src_srv_class_in_db failed");
632 #endif
633
634 return(NULL);
635 }
636 #endif /* HL_INCLUDED */
637