1 /******************************************************************************
3 * Copyright (C) 1999-2012 Broadcom Corporation
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:
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 ******************************************************************************/
19 /******************************************************************************
21 * this file contains functions that handle the database
23 ******************************************************************************/
29 #include "bt_target.h"
31 #include "bt_common.h"
40 #if (SDP_SERVER_ENABLED == TRUE)
41 /******************************************************************************/
42 /* L O C A L F U N C T I O N P R O T O T Y P E S */
43 /******************************************************************************/
44 static bool find_uuid_in_seq(uint8_t* p, uint32_t seq_len, uint8_t* p_his_uuid,
45 uint16_t his_len, int nest_level);
47 /*******************************************************************************
49 * Function sdp_db_service_search
51 * Description This function searches for a record that contains the
52 * specified UIDs. It is passed either NULL to start at the
53 * beginning, or the previous record found.
55 * Returns Pointer to the record, or NULL if not found.
57 ******************************************************************************/
58 tSDP_RECORD* sdp_db_service_search(tSDP_RECORD* p_rec, tSDP_UUID_SEQ* p_seq) {
60 tSDP_ATTRIBUTE* p_attr;
61 tSDP_RECORD* p_end = &sdp_cb.server_db.record[sdp_cb.server_db.num_records];
63 /* If NULL, start at the beginning, else start at the first specified record
66 p_rec = &sdp_cb.server_db.record[0];
70 /* Look through the records. The spec says that a match occurs if */
71 /* the record contains all the passed UUIDs in it. */
72 for (; p_rec < p_end; p_rec++) {
73 for (yy = 0; yy < p_seq->num_uids; yy++) {
74 p_attr = &p_rec->attribute[0];
75 for (xx = 0; xx < p_rec->num_attributes; xx++, p_attr++) {
76 if (p_attr->type == UUID_DESC_TYPE) {
77 if (sdpu_compare_uuid_arrays(p_attr->value_ptr, p_attr->len,
78 &p_seq->uuid_entry[yy].value[0],
79 p_seq->uuid_entry[yy].len))
81 } else if (p_attr->type == DATA_ELE_SEQ_DESC_TYPE) {
82 if (find_uuid_in_seq(p_attr->value_ptr, p_attr->len,
83 &p_seq->uuid_entry[yy].value[0],
84 p_seq->uuid_entry[yy].len, 0))
88 /* If any UUID was not found, on to the next record */
89 if (xx == p_rec->num_attributes) break;
92 /* If every UUID was found in the record, return the record */
93 if (yy == p_seq->num_uids) return (p_rec);
96 /* If here, no more records found */
100 /*******************************************************************************
102 * Function find_uuid_in_seq
104 * Description This function searches a data element sequenct for a UUID.
106 * Returns true if found, else false
108 ******************************************************************************/
109 static bool find_uuid_in_seq(uint8_t* p, uint32_t seq_len, uint8_t* p_uuid,
110 uint16_t uuid_len, int nest_level) {
111 uint8_t* p_end = p + seq_len;
115 /* A little safety check to avoid excessive recursion */
116 if (nest_level > 3) return (false);
120 p = sdpu_get_len_from_type(p, p_end, type, &len);
121 if (p == NULL || (p + len) > p_end) {
122 SDP_TRACE_WARNING("%s: bad length", __func__);
126 if (type == UUID_DESC_TYPE) {
127 if (sdpu_compare_uuid_arrays(p, len, p_uuid, uuid_len)) return (true);
128 } else if (type == DATA_ELE_SEQ_DESC_TYPE) {
129 if (find_uuid_in_seq(p, len, p_uuid, uuid_len, nest_level + 1))
135 /* If here, failed to match */
139 /*******************************************************************************
141 * Function sdp_db_find_record
143 * Description This function searches for a record with a specific handle
144 * It is passed the handle of the record.
146 * Returns Pointer to the record, or NULL if not found.
148 ******************************************************************************/
149 tSDP_RECORD* sdp_db_find_record(uint32_t handle) {
151 tSDP_RECORD* p_end = &sdp_cb.server_db.record[sdp_cb.server_db.num_records];
153 /* Look through the records for the caller's handle */
154 for (p_rec = &sdp_cb.server_db.record[0]; p_rec < p_end; p_rec++) {
155 if (p_rec->record_handle == handle) return (p_rec);
158 /* Record with that handle not found. */
162 /*******************************************************************************
164 * Function sdp_db_find_attr_in_rec
166 * Description This function searches a record for specific attributes.
167 * It is passed a pointer to the record. If the record contains
168 * the specified attribute, (the caller may specify be a range
169 * of attributes), the attribute is returned.
171 * Returns Pointer to the attribute, or NULL if not found.
173 ******************************************************************************/
174 tSDP_ATTRIBUTE* sdp_db_find_attr_in_rec(tSDP_RECORD* p_rec, uint16_t start_attr,
176 tSDP_ATTRIBUTE* p_at;
179 /* Note that the attributes in a record are assumed to be in sorted order */
180 for (xx = 0, p_at = &p_rec->attribute[0]; xx < p_rec->num_attributes;
182 if ((p_at->id >= start_attr) && (p_at->id <= end_attr)) return (p_at);
185 /* No matching attribute found */
189 /*******************************************************************************
191 * Function sdp_compose_proto_list
193 * Description This function is called to compose a data sequence from
194 * protocol element list struct pointer
196 * Returns the length of the data sequence
198 ******************************************************************************/
199 static int sdp_compose_proto_list(uint8_t* p, uint16_t num_elem,
200 tSDP_PROTOCOL_ELEM* p_elem_list) {
201 uint16_t xx, yy, len;
206 /* First, build the protocol list. This consists of a set of data element
207 ** sequences, one for each layer. Each layer sequence consists of layer's
208 ** UUID and optional parameters
210 for (xx = 0; xx < num_elem; xx++, p_elem_list++) {
211 len = 3 + (p_elem_list->num_params * 3);
212 UINT8_TO_BE_STREAM(p, (DATA_ELE_SEQ_DESC_TYPE << 3) | SIZE_IN_NEXT_BYTE);
217 UINT8_TO_BE_STREAM(p, (UUID_DESC_TYPE << 3) | SIZE_TWO_BYTES);
218 UINT16_TO_BE_STREAM(p, p_elem_list->protocol_uuid);
220 if (p_elem_list->protocol_uuid == UUID_PROTOCOL_RFCOMM)
221 is_rfcomm_scn = true;
223 is_rfcomm_scn = false;
225 for (yy = 0; yy < p_elem_list->num_params; yy++) {
227 UINT8_TO_BE_STREAM(p, (UINT_DESC_TYPE << 3) | SIZE_ONE_BYTE);
228 UINT8_TO_BE_STREAM(p, p_elem_list->params[yy]);
232 UINT8_TO_BE_STREAM(p, (UINT_DESC_TYPE << 3) | SIZE_TWO_BYTES);
233 UINT16_TO_BE_STREAM(p, p_elem_list->params[yy]);
240 #endif /* SDP_SERVER_ENABLED == TRUE */
242 /*******************************************************************************
244 * Function SDP_CreateRecord
246 * Description This function is called to create a record in the database.
247 * This would be through the SDP database maintenance API. The
248 * record is created empty, teh application should then call
249 * "add_attribute" to add the record's attributes.
251 * Returns Record handle if OK, else 0.
253 ******************************************************************************/
254 uint32_t SDP_CreateRecord(void) {
255 #if (SDP_SERVER_ENABLED == TRUE)
258 tSDP_DB* p_db = &sdp_cb.server_db;
260 /* First, check if there is a free record */
261 if (p_db->num_records < SDP_MAX_RECORDS) {
262 memset(&p_db->record[p_db->num_records], 0, sizeof(tSDP_RECORD));
264 /* We will use a handle of the first unreserved handle plus last record
266 if (p_db->num_records)
267 handle = p_db->record[p_db->num_records - 1].record_handle + 1;
271 p_db->record[p_db->num_records].record_handle = handle;
274 SDP_TRACE_DEBUG("SDP_CreateRecord ok, num_records:%d", p_db->num_records);
275 /* Add the first attribute (the handle) automatically */
276 UINT32_TO_BE_FIELD(buf, handle);
277 SDP_AddAttribute(handle, ATTR_ID_SERVICE_RECORD_HDL, UINT_DESC_TYPE, 4,
280 return (p_db->record[p_db->num_records - 1].record_handle);
282 SDP_TRACE_ERROR("SDP_CreateRecord fail, exceed maximum records:%d",
288 /*******************************************************************************
290 * Function SDP_DeleteRecord
292 * Description This function is called to add a record (or all records)
293 * from the database. This would be through the SDP database
296 * If a record handle of 0 is passed, all records are deleted.
298 * Returns true if succeeded, else false
300 ******************************************************************************/
301 bool SDP_DeleteRecord(uint32_t handle) {
302 #if (SDP_SERVER_ENABLED == TRUE)
304 tSDP_RECORD* p_rec = &sdp_cb.server_db.record[0];
306 if (handle == 0 || sdp_cb.server_db.num_records == 0) {
307 /* Delete all records in the database */
308 sdp_cb.server_db.num_records = 0;
310 /* require new DI record to be created in SDP_SetLocalDiRecord */
311 sdp_cb.server_db.di_primary_handle = 0;
315 /* Find the record in the database */
316 for (xx = 0; xx < sdp_cb.server_db.num_records; xx++, p_rec++) {
317 if (p_rec->record_handle == handle) {
318 /* Found it. Shift everything up one */
319 for (yy = xx; yy < sdp_cb.server_db.num_records - 1; yy++, p_rec++) {
320 *p_rec = *(p_rec + 1);
322 /* Adjust the attribute value pointer for each attribute */
323 for (zz = 0; zz < p_rec->num_attributes; zz++)
324 p_rec->attribute[zz].value_ptr -= sizeof(tSDP_RECORD);
327 sdp_cb.server_db.num_records--;
329 SDP_TRACE_DEBUG("SDP_DeleteRecord ok, num_records:%d",
330 sdp_cb.server_db.num_records);
331 /* if we're deleting the primary DI record, clear the */
332 /* value in the control block */
333 if (sdp_cb.server_db.di_primary_handle == handle) {
334 sdp_cb.server_db.di_primary_handle = 0;
345 /*******************************************************************************
347 * Function SDP_AddAttribute
349 * Description This function is called to add an attribute to a record.
350 * This would be through the SDP database maintenance API.
351 * If the attribute already exists in the record, it is
352 * replaced with the new value.
354 * NOTE Attribute values must be passed as a Big Endian stream.
356 * Returns true if added OK, else false
358 ******************************************************************************/
359 bool SDP_AddAttribute(uint32_t handle, uint16_t attr_id, uint8_t attr_type,
360 uint32_t attr_len, uint8_t* p_val) {
361 #if (SDP_SERVER_ENABLED == TRUE)
363 tSDP_RECORD* p_rec = &sdp_cb.server_db.record[0];
365 if (sdp_cb.trace_level >= BT_TRACE_LEVEL_DEBUG) {
366 if ((attr_type == UINT_DESC_TYPE) ||
367 (attr_type == TWO_COMP_INT_DESC_TYPE) ||
368 (attr_type == UUID_DESC_TYPE) ||
369 (attr_type == DATA_ELE_SEQ_DESC_TYPE) ||
370 (attr_type == DATA_ELE_ALT_DESC_TYPE)) {
371 uint8_t num_array[400];
372 uint32_t len = (attr_len > 200) ? 200 : attr_len;
375 for (uint32_t i = 0; i < len; i++) {
376 snprintf((char*)&num_array[i * 2], sizeof(num_array) - i * 2, "%02X",
377 (uint8_t)(p_val[i]));
380 "SDP_AddAttribute: handle:%X, id:%04X, type:%d, len:%d, p_val:%p, "
382 handle, attr_id, attr_type, attr_len, p_val, num_array);
383 } else if (attr_type == BOOLEAN_DESC_TYPE) {
385 "SDP_AddAttribute: handle:%X, id:%04X, type:%d, len:%d, p_val:%p, "
387 handle, attr_id, attr_type, attr_len, p_val, *p_val);
390 "SDP_AddAttribute: handle:%X, id:%04X, type:%d, len:%d, p_val:%p, "
392 handle, attr_id, attr_type, attr_len, p_val, p_val);
396 /* Find the record in the database */
397 for (zz = 0; zz < sdp_cb.server_db.num_records; zz++, p_rec++) {
398 if (p_rec->record_handle == handle) {
399 tSDP_ATTRIBUTE* p_attr = &p_rec->attribute[0];
401 /* Found the record. Now, see if the attribute already exists */
402 for (xx = 0; xx < p_rec->num_attributes; xx++, p_attr++) {
403 /* The attribute exists. replace it */
404 if (p_attr->id == attr_id) {
405 SDP_DeleteAttribute(handle, attr_id);
408 if (p_attr->id > attr_id) break;
411 if (p_rec->num_attributes == SDP_MAX_REC_ATTR) return (false);
413 /* If not found, see if we can allocate a new entry */
414 if (xx == p_rec->num_attributes)
415 p_attr = &p_rec->attribute[p_rec->num_attributes];
417 /* Since the attributes are kept in sorted order, insert ours here */
418 for (yy = p_rec->num_attributes; yy > xx; yy--)
419 p_rec->attribute[yy] = p_rec->attribute[yy - 1];
422 p_attr->id = attr_id;
423 p_attr->type = attr_type;
424 p_attr->len = attr_len;
426 if (p_rec->free_pad_ptr + attr_len >= SDP_MAX_PAD_LEN) {
427 /* do truncate only for text string type descriptor */
428 if (attr_type == TEXT_STR_DESC_TYPE) {
430 "SDP_AddAttribute: attr_len:%d too long. truncate to (%d)",
431 attr_len, SDP_MAX_PAD_LEN - p_rec->free_pad_ptr);
433 attr_len = SDP_MAX_PAD_LEN - p_rec->free_pad_ptr;
434 p_val[SDP_MAX_PAD_LEN - p_rec->free_pad_ptr] = '\0';
435 p_val[SDP_MAX_PAD_LEN - p_rec->free_pad_ptr + 1] = '\0';
440 if ((attr_len > 0) && (p_val != 0)) {
441 p_attr->len = attr_len;
442 memcpy(&p_rec->attr_pad[p_rec->free_pad_ptr], p_val, (size_t)attr_len);
443 p_attr->value_ptr = &p_rec->attr_pad[p_rec->free_pad_ptr];
444 p_rec->free_pad_ptr += attr_len;
445 } else if ((attr_len == 0 &&
447 0) || /* if truncate to 0 length, simply don't add */
450 "SDP_AddAttribute fail, length exceed maximum: ID %d: attr_len:%d ",
452 p_attr->id = p_attr->type = p_attr->len = 0;
455 p_rec->num_attributes++;
463 /*******************************************************************************
465 * Function SDP_AddSequence
467 * Description This function is called to add a sequence to a record.
468 * This would be through the SDP database maintenance API.
469 * If the sequence already exists in the record, it is replaced
470 * with the new sequence.
472 * NOTE Element values must be passed as a Big Endian stream.
474 * Returns true if added OK, else false
476 ******************************************************************************/
477 bool SDP_AddSequence(uint32_t handle, uint16_t attr_id, uint16_t num_elem,
478 uint8_t type[], uint8_t len[], uint8_t* p_val[]) {
479 #if (SDP_SERVER_ENABLED == TRUE)
485 (uint8_t*)osi_malloc(sizeof(uint8_t) * SDP_MAX_ATTR_LEN * 2);
489 /* First, build the sequence */
490 for (xx = 0; xx < num_elem; xx++) {
494 UINT8_TO_BE_STREAM(p, (type[xx] << 3) | SIZE_ONE_BYTE);
497 UINT8_TO_BE_STREAM(p, (type[xx] << 3) | SIZE_TWO_BYTES);
500 UINT8_TO_BE_STREAM(p, (type[xx] << 3) | SIZE_FOUR_BYTES);
503 UINT8_TO_BE_STREAM(p, (type[xx] << 3) | SIZE_EIGHT_BYTES);
506 UINT8_TO_BE_STREAM(p, (type[xx] << 3) | SIZE_SIXTEEN_BYTES);
509 UINT8_TO_BE_STREAM(p, (type[xx] << 3) | SIZE_IN_NEXT_BYTE);
510 UINT8_TO_BE_STREAM(p, len[xx]);
514 ARRAY_TO_BE_STREAM(p, p_val[xx], len[xx]);
516 if (p - p_buff > SDP_MAX_ATTR_LEN) {
517 /* go back to before we add this element */
519 if (p_head == p_buff) {
520 /* the first element exceed the max length */
521 SDP_TRACE_ERROR("SDP_AddSequence - too long(attribute is not added)!!");
525 SDP_TRACE_ERROR("SDP_AddSequence - too long, add %d elements of %d", xx,
530 result = SDP_AddAttribute(handle, attr_id, DATA_ELE_SEQ_DESC_TYPE,
531 (uint32_t)(p - p_buff), p_buff);
534 #else /* SDP_SERVER_ENABLED == FALSE */
539 /*******************************************************************************
541 * Function SDP_AddUuidSequence
543 * Description This function is called to add a UUID sequence to a record.
544 * This would be through the SDP database maintenance API.
545 * If the sequence already exists in the record, it is replaced
546 * with the new sequence.
548 * Returns true if added OK, else false
550 ******************************************************************************/
551 bool SDP_AddUuidSequence(uint32_t handle, uint16_t attr_id, uint16_t num_uuids,
553 #if (SDP_SERVER_ENABLED == TRUE)
556 int32_t max_len = SDP_MAX_ATTR_LEN - 3;
559 (uint8_t*)osi_malloc(sizeof(uint8_t) * SDP_MAX_ATTR_LEN * 2);
563 /* First, build the sequence */
564 for (xx = 0; xx < num_uuids; xx++, p_uuids++) {
565 UINT8_TO_BE_STREAM(p, (UUID_DESC_TYPE << 3) | SIZE_TWO_BYTES);
566 UINT16_TO_BE_STREAM(p, *p_uuids);
568 if ((p - p_buff) > max_len) {
569 SDP_TRACE_WARNING("SDP_AddUuidSequence - too long, add %d uuids of %d",
575 result = SDP_AddAttribute(handle, attr_id, DATA_ELE_SEQ_DESC_TYPE,
576 (uint32_t)(p - p_buff), p_buff);
579 #else /* SDP_SERVER_ENABLED == FALSE */
584 /*******************************************************************************
586 * Function SDP_AddProtocolList
588 * Description This function is called to add a protocol descriptor list to
589 * a record. This would be through the SDP database
590 * maintenance API. If the protocol list already exists in the
591 * record, it is replaced with the new list.
593 * Returns true if added OK, else false
595 ******************************************************************************/
596 bool SDP_AddProtocolList(uint32_t handle, uint16_t num_elem,
597 tSDP_PROTOCOL_ELEM* p_elem_list) {
598 #if (SDP_SERVER_ENABLED == TRUE)
602 (uint8_t*)osi_malloc(sizeof(uint8_t) * SDP_MAX_ATTR_LEN * 2);
604 offset = sdp_compose_proto_list(p_buff, num_elem, p_elem_list);
605 result = SDP_AddAttribute(handle, ATTR_ID_PROTOCOL_DESC_LIST,
606 DATA_ELE_SEQ_DESC_TYPE, (uint32_t)offset, p_buff);
609 #else /* SDP_SERVER_ENABLED == FALSE */
614 /*******************************************************************************
616 * Function SDP_AddAdditionProtoLists
618 * Description This function is called to add a protocol descriptor list to
619 * a record. This would be through the SDP database maintenance
620 * API. If the protocol list already exists in the record, it
621 * is replaced with the new list.
623 * Returns true if added OK, else false
625 ******************************************************************************/
626 bool SDP_AddAdditionProtoLists(uint32_t handle, uint16_t num_elem,
627 tSDP_PROTO_LIST_ELEM* p_proto_list) {
628 #if (SDP_SERVER_ENABLED == TRUE)
635 (uint8_t*)osi_malloc(sizeof(uint8_t) * SDP_MAX_ATTR_LEN * 2);
639 /* for each ProtocolDescriptorList */
640 for (xx = 0; xx < num_elem; xx++, p_proto_list++) {
641 UINT8_TO_BE_STREAM(p, (DATA_ELE_SEQ_DESC_TYPE << 3) | SIZE_IN_NEXT_BYTE);
644 offset = sdp_compose_proto_list(p, p_proto_list->num_elems,
645 p_proto_list->list_elem);
648 *p_len = (uint8_t)(p - p_len - 1);
651 SDP_AddAttribute(handle, ATTR_ID_ADDITION_PROTO_DESC_LISTS,
652 DATA_ELE_SEQ_DESC_TYPE, (uint32_t)(p - p_buff), p_buff);
656 #else /* SDP_SERVER_ENABLED == FALSE */
661 /*******************************************************************************
663 * Function SDP_AddProfileDescriptorList
665 * Description This function is called to add a profile descriptor list to
666 * a record. This would be through the SDP database maintenance
667 * API. If the version already exists in the record, it is
668 * replaced with the new one.
670 * Returns true if added OK, else false
672 ******************************************************************************/
673 bool SDP_AddProfileDescriptorList(uint32_t handle, uint16_t profile_uuid,
675 #if (SDP_SERVER_ENABLED == TRUE)
678 uint8_t* p_buff = (uint8_t*)osi_malloc(sizeof(uint8_t) * SDP_MAX_ATTR_LEN);
682 /* First, build the profile descriptor list. This consists of a data element
684 /* The sequence consists of profile's UUID and version number */
685 UINT8_TO_BE_STREAM(p, (UUID_DESC_TYPE << 3) | SIZE_TWO_BYTES);
686 UINT16_TO_BE_STREAM(p, profile_uuid);
688 UINT8_TO_BE_STREAM(p, (UINT_DESC_TYPE << 3) | SIZE_TWO_BYTES);
689 UINT16_TO_BE_STREAM(p, version);
691 /* Add in type and length fields */
692 *p_buff = (uint8_t)((DATA_ELE_SEQ_DESC_TYPE << 3) | SIZE_IN_NEXT_BYTE);
693 *(p_buff + 1) = (uint8_t)(p - (p_buff + 2));
696 SDP_AddAttribute(handle, ATTR_ID_BT_PROFILE_DESC_LIST,
697 DATA_ELE_SEQ_DESC_TYPE, (uint32_t)(p - p_buff), p_buff);
701 #else /* SDP_SERVER_ENABLED == FALSE */
706 /*******************************************************************************
708 * Function SDP_AddLanguageBaseAttrIDList
710 * Description This function is called to add a language base attr list to
711 * a record. This would be through the SDP database maintenance
712 * API. If the version already exists in the record, it is
713 * replaced with the new one.
715 * Returns true if added OK, else false
717 ******************************************************************************/
718 bool SDP_AddLanguageBaseAttrIDList(uint32_t handle, uint16_t lang,
719 uint16_t char_enc, uint16_t base_id) {
720 #if (SDP_SERVER_ENABLED == TRUE)
723 uint8_t* p_buff = (uint8_t*)osi_malloc(sizeof(uint8_t) * SDP_MAX_ATTR_LEN);
727 /* First, build the language base descriptor list. This consists of a data */
728 /* element sequence. The sequence consists of 9 bytes (3 UINt16 fields) */
729 UINT8_TO_BE_STREAM(p, (UINT_DESC_TYPE << 3) | SIZE_TWO_BYTES);
730 UINT16_TO_BE_STREAM(p, lang);
732 UINT8_TO_BE_STREAM(p, (UINT_DESC_TYPE << 3) | SIZE_TWO_BYTES);
733 UINT16_TO_BE_STREAM(p, char_enc);
735 UINT8_TO_BE_STREAM(p, (UINT_DESC_TYPE << 3) | SIZE_TWO_BYTES);
736 UINT16_TO_BE_STREAM(p, base_id);
739 SDP_AddAttribute(handle, ATTR_ID_LANGUAGE_BASE_ATTR_ID_LIST,
740 DATA_ELE_SEQ_DESC_TYPE, (uint32_t)(p - p_buff), p_buff);
743 #else /* SDP_SERVER_ENABLED == FALSE */
748 /*******************************************************************************
750 * Function SDP_AddServiceClassIdList
752 * Description This function is called to add a service list to a record.
753 * This would be through the SDP database maintenance API.
754 * If the service list already exists in the record, it is
755 * replaced with the new list.
757 * Returns true if added OK, else false
759 ******************************************************************************/
760 bool SDP_AddServiceClassIdList(uint32_t handle, uint16_t num_services,
761 uint16_t* p_service_uuids) {
762 #if (SDP_SERVER_ENABLED == TRUE)
767 (uint8_t*)osi_malloc(sizeof(uint8_t) * SDP_MAX_ATTR_LEN * 2);
771 for (xx = 0; xx < num_services; xx++, p_service_uuids++) {
772 UINT8_TO_BE_STREAM(p, (UUID_DESC_TYPE << 3) | SIZE_TWO_BYTES);
773 UINT16_TO_BE_STREAM(p, *p_service_uuids);
777 SDP_AddAttribute(handle, ATTR_ID_SERVICE_CLASS_ID_LIST,
778 DATA_ELE_SEQ_DESC_TYPE, (uint32_t)(p - p_buff), p_buff);
781 #else /* SDP_SERVER_ENABLED == FALSE */
786 /*******************************************************************************
788 * Function SDP_DeleteAttribute
790 * Description This function is called to delete an attribute from a
791 * record. This would be through the SDP database maintenance
794 * Returns true if deleted OK, else false if not found
796 ******************************************************************************/
797 bool SDP_DeleteAttribute(uint32_t handle, uint16_t attr_id) {
798 #if (SDP_SERVER_ENABLED == TRUE)
800 tSDP_RECORD* p_rec = &sdp_cb.server_db.record[0];
802 uint32_t len; /* Number of bytes in the entry */
804 /* Find the record in the database */
805 for (xx = 0; xx < sdp_cb.server_db.num_records; xx++, p_rec++) {
806 if (p_rec->record_handle == handle) {
807 tSDP_ATTRIBUTE* p_attr = &p_rec->attribute[0];
809 SDP_TRACE_API("Deleting attr_id 0x%04x for handle 0x%x", attr_id, handle);
810 /* Found it. Now, find the attribute */
811 for (xx = 0; xx < p_rec->num_attributes; xx++, p_attr++) {
812 if (p_attr->id == attr_id) {
813 pad_ptr = p_attr->value_ptr;
817 for (yy = 0; yy < p_rec->num_attributes; yy++) {
818 if (p_rec->attribute[yy].value_ptr > pad_ptr)
819 p_rec->attribute[yy].value_ptr -= len;
823 /* Found it. Shift everything up one */
824 p_rec->num_attributes--;
826 for (yy = xx; yy < p_rec->num_attributes; yy++, p_attr++) {
827 *p_attr = *(p_attr + 1);
830 /* adjust attribute values if needed */
833 (p_rec->free_pad_ptr - ((pad_ptr + len) - &p_rec->attr_pad[0]));
834 for (yy = 0; yy < xx; yy++, pad_ptr++) *pad_ptr = *(pad_ptr + len);
835 p_rec->free_pad_ptr -= len;
843 /* If here, not found */
847 /*******************************************************************************
849 * Function SDP_ReadRecord
851 * Description This function is called to get the raw data of the record
852 * with the given handle from the database.
854 * Returns -1, if the record is not found.
855 * Otherwise, the offset (0 or 1) to start of data in p_data.
857 * The size of data copied into p_data is in *p_data_len.
859 ******************************************************************************/
860 #if (SDP_RAW_DATA_INCLUDED == TRUE)
861 int32_t SDP_ReadRecord(uint32_t handle, uint8_t* p_data, int32_t* p_data_len) {
862 int32_t len = 0; /* Number of bytes in the entry */
863 int32_t offset = -1; /* default to not found */
864 #if (SDP_SERVER_ENABLED == TRUE)
867 uint16_t end = 0xffff;
868 tSDP_ATTRIBUTE* p_attr;
872 /* Find the record in the database */
873 p_rec = sdp_db_find_record(handle);
874 if (p_rec && p_data && p_data_len) {
876 while ((p_attr = sdp_db_find_attr_in_rec(p_rec, start, end)) != NULL) {
877 /* Check if attribute fits. Assume 3-byte value type/length */
878 rem_len = *p_data_len - (uint16_t)(p_rsp - p_data);
880 if (p_attr->len > (uint32_t)(rem_len - 6)) break;
882 p_rsp = sdpu_build_attrib_entry(p_rsp, p_attr);
885 start = p_attr->id + 1;
887 len = (int32_t)(p_rsp - p_data);
889 /* Put in the sequence header (2 or 3 bytes) */
892 p_data[0] = (uint8_t)((DATA_ELE_SEQ_DESC_TYPE << 3) | SIZE_IN_NEXT_WORD);
893 p_data[1] = (uint8_t)((len - 3) >> 8);
894 p_data[2] = (uint8_t)(len - 3);
898 p_data[1] = (uint8_t)((DATA_ELE_SEQ_DESC_TYPE << 3) | SIZE_IN_NEXT_BYTE);
899 p_data[2] = (uint8_t)(len - 3);
906 /* If here, not found */