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 BOOLEAN find_uuid_in_seq (UINT8 *p , UINT32 seq_len, UINT8 *p_his_uuid,
45 UINT16 his_len, int nest_level);
48 /*******************************************************************************
50 ** Function sdp_db_service_search
52 ** Description This function searches for a record that contains the
53 ** specified UIDs. It is passed either NULL to start at the
54 ** beginning, or the previous record found.
56 ** Returns Pointer to the record, or NULL if not found.
58 *******************************************************************************/
59 tSDP_RECORD *sdp_db_service_search (tSDP_RECORD *p_rec, tSDP_UUID_SEQ *p_seq)
62 tSDP_ATTRIBUTE *p_attr;
63 tSDP_RECORD *p_end = &sdp_cb.server_db.record[sdp_cb.server_db.num_records];
65 /* If NULL, start at the beginning, else start at the first specified record */
67 p_rec = &sdp_cb.server_db.record[0];
71 /* Look through the records. The spec says that a match occurs if */
72 /* the record contains all the passed UUIDs in it. */
73 for ( ; p_rec < p_end; p_rec++)
75 for (yy = 0; yy < p_seq->num_uids; yy++)
77 p_attr = &p_rec->attribute[0];
78 for (xx = 0; xx < p_rec->num_attributes; xx++, p_attr++)
80 if (p_attr->type == UUID_DESC_TYPE)
82 if (sdpu_compare_uuid_arrays (p_attr->value_ptr, p_attr->len,
83 &p_seq->uuid_entry[yy].value[0],
84 p_seq->uuid_entry[yy].len))
87 else if (p_attr->type == DATA_ELE_SEQ_DESC_TYPE)
89 if (find_uuid_in_seq (p_attr->value_ptr, p_attr->len,
90 &p_seq->uuid_entry[yy].value[0],
91 p_seq->uuid_entry[yy].len, 0))
95 /* If any UUID was not found, on to the next record */
96 if (xx == p_rec->num_attributes)
100 /* If every UUID was found in the record, return the record */
101 if (yy == p_seq->num_uids)
105 /* If here, no more records found */
109 /*******************************************************************************
111 ** Function find_uuid_in_seq
113 ** Description This function searches a data element sequenct for a UUID.
115 ** Returns TRUE if found, else FALSE
117 *******************************************************************************/
118 static BOOLEAN find_uuid_in_seq (UINT8 *p , UINT32 seq_len, UINT8 *p_uuid,
119 UINT16 uuid_len, int nest_level)
121 UINT8 *p_end = p + seq_len;
125 /* A little safety check to avoid excessive recursion */
132 p = sdpu_get_len_from_type (p, type, &len);
134 if (type == UUID_DESC_TYPE)
136 if (sdpu_compare_uuid_arrays (p, len, p_uuid, uuid_len))
139 else if (type == DATA_ELE_SEQ_DESC_TYPE)
141 if (find_uuid_in_seq (p, len, p_uuid, uuid_len, nest_level + 1))
147 /* If here, failed to match */
151 /*******************************************************************************
153 ** Function sdp_db_find_record
155 ** Description This function searches for a record with a specific handle
156 ** It is passed the handle of the record.
158 ** Returns Pointer to the record, or NULL if not found.
160 *******************************************************************************/
161 tSDP_RECORD *sdp_db_find_record (UINT32 handle)
164 tSDP_RECORD *p_end = &sdp_cb.server_db.record[sdp_cb.server_db.num_records];
166 /* Look through the records for the caller's handle */
167 for (p_rec = &sdp_cb.server_db.record[0]; p_rec < p_end; p_rec++)
169 if (p_rec->record_handle == handle)
173 /* Record with that handle not found. */
177 /*******************************************************************************
179 ** Function sdp_db_find_attr_in_rec
181 ** Description This function searches a record for specific attributes.
182 ** It is passed a pointer to the record. If the record contains
183 ** the specified attribute, (the caller may specify be a range
184 ** of attributes), the attribute is returned.
186 ** Returns Pointer to the attribute, or NULL if not found.
188 *******************************************************************************/
189 tSDP_ATTRIBUTE *sdp_db_find_attr_in_rec (tSDP_RECORD *p_rec, UINT16 start_attr,
192 tSDP_ATTRIBUTE *p_at;
195 /* Note that the attributes in a record are assumed to be in sorted order */
196 for (xx = 0, p_at = &p_rec->attribute[0]; xx < p_rec->num_attributes;
199 if ((p_at->id >= start_attr) && (p_at->id <= end_attr))
203 /* No matching attribute found */
208 /*******************************************************************************
210 ** Function sdp_compose_proto_list
212 ** Description This function is called to compose a data sequence from
213 ** protocol element list struct pointer
215 ** Returns the length of the data sequence
217 *******************************************************************************/
218 static int sdp_compose_proto_list( UINT8 *p, UINT16 num_elem,
219 tSDP_PROTOCOL_ELEM *p_elem_list)
222 BOOLEAN is_rfcomm_scn;
226 /* First, build the protocol list. This consists of a set of data element
227 ** sequences, one for each layer. Each layer sequence consists of layer's
228 ** UUID and optional parameters
230 for (xx = 0; xx < num_elem; xx++, p_elem_list++)
232 len = 3 + (p_elem_list->num_params * 3);
233 UINT8_TO_BE_STREAM (p, (DATA_ELE_SEQ_DESC_TYPE << 3) | SIZE_IN_NEXT_BYTE);
238 UINT8_TO_BE_STREAM (p, (UUID_DESC_TYPE << 3) | SIZE_TWO_BYTES);
239 UINT16_TO_BE_STREAM (p, p_elem_list->protocol_uuid);
241 if (p_elem_list->protocol_uuid == UUID_PROTOCOL_RFCOMM)
242 is_rfcomm_scn = TRUE;
244 is_rfcomm_scn = FALSE;
246 for (yy = 0; yy < p_elem_list->num_params; yy++)
250 UINT8_TO_BE_STREAM (p, (UINT_DESC_TYPE << 3) | SIZE_ONE_BYTE);
251 UINT8_TO_BE_STREAM (p, p_elem_list->params[yy]);
257 UINT8_TO_BE_STREAM (p, (UINT_DESC_TYPE << 3) | SIZE_TWO_BYTES);
258 UINT16_TO_BE_STREAM (p, p_elem_list->params[yy]);
265 #endif /* SDP_SERVER_ENABLED == TRUE */
267 /*******************************************************************************
269 ** Function SDP_CreateRecord
271 ** Description This function is called to create a record in the database.
272 ** This would be through the SDP database maintenance API. The
273 ** record is created empty, teh application should then call
274 ** "add_attribute" to add the record's attributes.
276 ** Returns Record handle if OK, else 0.
278 *******************************************************************************/
279 UINT32 SDP_CreateRecord (void)
281 #if SDP_SERVER_ENABLED == TRUE
284 tSDP_DB *p_db = &sdp_cb.server_db;
286 /* First, check if there is a free record */
287 if (p_db->num_records < SDP_MAX_RECORDS)
289 memset (&p_db->record[p_db->num_records], 0,
290 sizeof (tSDP_RECORD));
292 /* We will use a handle of the first unreserved handle plus last record
294 if (p_db->num_records)
295 handle = p_db->record[p_db->num_records - 1].record_handle + 1;
299 p_db->record[p_db->num_records].record_handle = handle;
302 SDP_TRACE_DEBUG("SDP_CreateRecord ok, num_records:%d", p_db->num_records);
303 /* Add the first attribute (the handle) automatically */
304 UINT32_TO_BE_FIELD (buf, handle);
305 SDP_AddAttribute (handle, ATTR_ID_SERVICE_RECORD_HDL, UINT_DESC_TYPE,
308 return (p_db->record[p_db->num_records - 1].record_handle);
310 else SDP_TRACE_ERROR("SDP_CreateRecord fail, exceed maximum records:%d", SDP_MAX_RECORDS);
316 /*******************************************************************************
318 ** Function SDP_DeleteRecord
320 ** Description This function is called to add a record (or all records)
321 ** from the database. This would be through the SDP database
324 ** If a record handle of 0 is passed, all records are deleted.
326 ** Returns TRUE if succeeded, else FALSE
328 *******************************************************************************/
329 BOOLEAN SDP_DeleteRecord (UINT32 handle)
331 #if SDP_SERVER_ENABLED == TRUE
333 tSDP_RECORD *p_rec = &sdp_cb.server_db.record[0];
335 if (handle == 0 || sdp_cb.server_db.num_records == 0)
337 /* Delete all records in the database */
338 sdp_cb.server_db.num_records = 0;
340 /* require new DI record to be created in SDP_SetLocalDiRecord */
341 sdp_cb.server_db.di_primary_handle = 0;
347 /* Find the record in the database */
348 for (xx = 0; xx < sdp_cb.server_db.num_records; xx++, p_rec++)
350 if (p_rec->record_handle == handle)
352 /* Found it. Shift everything up one */
353 for (yy = xx; yy < sdp_cb.server_db.num_records; yy++, p_rec++)
355 *p_rec = *(p_rec + 1);
357 /* Adjust the attribute value pointer for each attribute */
358 for (zz = 0; zz < p_rec->num_attributes; zz++)
359 p_rec->attribute[zz].value_ptr -= sizeof(tSDP_RECORD);
362 sdp_cb.server_db.num_records--;
364 SDP_TRACE_DEBUG("SDP_DeleteRecord ok, num_records:%d", sdp_cb.server_db.num_records);
365 /* if we're deleting the primary DI record, clear the */
366 /* value in the control block */
367 if( sdp_cb.server_db.di_primary_handle == handle )
369 sdp_cb.server_db.di_primary_handle = 0;
381 /*******************************************************************************
383 ** Function SDP_AddAttribute
385 ** Description This function is called to add an attribute to a record.
386 ** This would be through the SDP database maintenance API.
387 ** If the attribute already exists in the record, it is replaced
388 ** with the new value.
390 ** NOTE Attribute values must be passed as a Big Endian stream.
392 ** Returns TRUE if added OK, else FALSE
394 *******************************************************************************/
395 BOOLEAN SDP_AddAttribute (UINT32 handle, UINT16 attr_id, UINT8 attr_type,
396 UINT32 attr_len, UINT8 *p_val)
398 #if SDP_SERVER_ENABLED == TRUE
400 tSDP_RECORD *p_rec = &sdp_cb.server_db.record[0];
402 #if (BT_TRACE_VERBOSE == TRUE)
403 if (sdp_cb.trace_level >= BT_TRACE_LEVEL_DEBUG)
405 if ((attr_type == UINT_DESC_TYPE) ||
406 (attr_type == TWO_COMP_INT_DESC_TYPE) ||
407 (attr_type == UUID_DESC_TYPE) ||
408 (attr_type == DATA_ELE_SEQ_DESC_TYPE) ||
409 (attr_type == DATA_ELE_ALT_DESC_TYPE))
411 UINT8 num_array[400];
413 UINT32 len = (attr_len > 200) ? 200 : attr_len;
416 for (i = 0; i < len; i++)
418 sprintf((char *)&num_array[i*2],"%02X",(UINT8)(p_val[i]));
420 SDP_TRACE_DEBUG("SDP_AddAttribute: handle:%X, id:%04X, type:%d, len:%d, p_val:%p, *p_val:%s",
421 handle,attr_id,attr_type,attr_len,p_val,num_array);
423 else if (attr_type == BOOLEAN_DESC_TYPE)
425 SDP_TRACE_DEBUG("SDP_AddAttribute: handle:%X, id:%04X, type:%d, len:%d, p_val:%p, *p_val:%d",
426 handle,attr_id,attr_type,attr_len,p_val,*p_val);
430 SDP_TRACE_DEBUG("SDP_AddAttribute: handle:%X, id:%04X, type:%d, len:%d, p_val:%p, *p_val:%s",
431 handle,attr_id,attr_type,attr_len,p_val,p_val);
436 /* Find the record in the database */
437 for (zz = 0; zz < sdp_cb.server_db.num_records; zz++, p_rec++)
439 if (p_rec->record_handle == handle)
441 tSDP_ATTRIBUTE *p_attr = &p_rec->attribute[0];
443 /* Found the record. Now, see if the attribute already exists */
444 for (xx = 0; xx < p_rec->num_attributes; xx++, p_attr++)
446 /* The attribute exists. replace it */
447 if (p_attr->id == attr_id)
449 SDP_DeleteAttribute (handle, attr_id);
452 if (p_attr->id > attr_id)
456 if (p_rec->num_attributes == SDP_MAX_REC_ATTR)
459 /* If not found, see if we can allocate a new entry */
460 if (xx == p_rec->num_attributes)
461 p_attr = &p_rec->attribute[p_rec->num_attributes];
464 /* Since the attributes are kept in sorted order, insert ours here */
465 for (yy = p_rec->num_attributes; yy > xx; yy--)
466 p_rec->attribute[yy] = p_rec->attribute[yy - 1];
469 p_attr->id = attr_id;
470 p_attr->type = attr_type;
471 p_attr->len = attr_len;
473 if (p_rec->free_pad_ptr + attr_len >= SDP_MAX_PAD_LEN)
475 /* do truncate only for text string type descriptor */
476 if (attr_type == TEXT_STR_DESC_TYPE)
478 SDP_TRACE_WARNING("SDP_AddAttribute: attr_len:%d too long. truncate to (%d)",
479 attr_len, SDP_MAX_PAD_LEN - p_rec->free_pad_ptr );
481 attr_len = SDP_MAX_PAD_LEN - p_rec->free_pad_ptr;
482 p_val[SDP_MAX_PAD_LEN - p_rec->free_pad_ptr] = '\0';
483 p_val[SDP_MAX_PAD_LEN - p_rec->free_pad_ptr+1] = '\0';
489 if ((attr_len > 0) && (p_val != 0))
491 p_attr->len = attr_len;
492 memcpy (&p_rec->attr_pad[p_rec->free_pad_ptr], p_val, (size_t)attr_len);
493 p_attr->value_ptr = &p_rec->attr_pad[p_rec->free_pad_ptr];
494 p_rec->free_pad_ptr += attr_len;
496 else if ((attr_len == 0 && p_attr->len != 0) || /* if truncate to 0 length, simply don't add */
499 SDP_TRACE_ERROR("SDP_AddAttribute fail, length exceed maximum: ID %d: attr_len:%d ",
501 p_attr->id = p_attr->type = p_attr->len = 0;
504 p_rec->num_attributes++;
513 /*******************************************************************************
515 ** Function SDP_AddSequence
517 ** Description This function is called to add a sequence to a record.
518 ** This would be through the SDP database maintenance API.
519 ** If the sequence already exists in the record, it is replaced
520 ** with the new sequence.
522 ** NOTE Element values must be passed as a Big Endian stream.
524 ** Returns TRUE if added OK, else FALSE
526 *******************************************************************************/
527 BOOLEAN SDP_AddSequence (UINT32 handle, UINT16 attr_id, UINT16 num_elem,
528 UINT8 type[], UINT8 len[], UINT8 *p_val[])
530 #if SDP_SERVER_ENABLED == TRUE
537 if ((p_buff = (UINT8 *) osi_getbuf(sizeof(UINT8) * SDP_MAX_ATTR_LEN * 2)) == NULL)
539 SDP_TRACE_ERROR("SDP_AddSequence cannot get a buffer!");
544 /* First, build the sequence */
545 for (xx = 0; xx < num_elem; xx++)
551 UINT8_TO_BE_STREAM (p, (type[xx] << 3) | SIZE_ONE_BYTE);
554 UINT8_TO_BE_STREAM (p, (type[xx] << 3) | SIZE_TWO_BYTES);
557 UINT8_TO_BE_STREAM (p, (type[xx] << 3) | SIZE_FOUR_BYTES);
560 UINT8_TO_BE_STREAM (p, (type[xx] << 3) | SIZE_EIGHT_BYTES);
563 UINT8_TO_BE_STREAM (p, (type[xx] << 3) | SIZE_SIXTEEN_BYTES);
566 UINT8_TO_BE_STREAM (p, (type[xx] << 3) | SIZE_IN_NEXT_BYTE);
567 UINT8_TO_BE_STREAM (p, len[xx]);
571 ARRAY_TO_BE_STREAM (p, p_val[xx], len[xx]);
573 if (p - p_buff > SDP_MAX_ATTR_LEN)
575 /* go back to before we add this element */
579 /* the first element exceed the max length */
580 SDP_TRACE_ERROR ("SDP_AddSequence - too long(attribute is not added)!!");
585 SDP_TRACE_ERROR ("SDP_AddSequence - too long, add %d elements of %d", xx, num_elem);
589 result = SDP_AddAttribute (handle, attr_id, DATA_ELE_SEQ_DESC_TYPE,(UINT32) (p - p_buff), p_buff);
592 #else /* SDP_SERVER_ENABLED == FALSE */
598 /*******************************************************************************
600 ** Function SDP_AddUuidSequence
602 ** Description This function is called to add a UUID sequence to a record.
603 ** This would be through the SDP database maintenance API.
604 ** If the sequence already exists in the record, it is replaced
605 ** with the new sequence.
607 ** Returns TRUE if added OK, else FALSE
609 *******************************************************************************/
610 BOOLEAN SDP_AddUuidSequence (UINT32 handle, UINT16 attr_id, UINT16 num_uuids,
613 #if SDP_SERVER_ENABLED == TRUE
617 INT32 max_len = SDP_MAX_ATTR_LEN -3;
620 if ((p_buff = (UINT8 *) osi_getbuf(sizeof(UINT8) * SDP_MAX_ATTR_LEN * 2)) == NULL)
622 SDP_TRACE_ERROR("SDP_AddUuidSequence cannot get a buffer!");
627 /* First, build the sequence */
628 for (xx = 0; xx < num_uuids ; xx++, p_uuids++)
630 UINT8_TO_BE_STREAM (p, (UUID_DESC_TYPE << 3) | SIZE_TWO_BYTES);
631 UINT16_TO_BE_STREAM (p, *p_uuids);
633 if((p - p_buff) > max_len)
635 SDP_TRACE_WARNING ("SDP_AddUuidSequence - too long, add %d uuids of %d", xx, num_uuids);
640 result = SDP_AddAttribute (handle, attr_id, DATA_ELE_SEQ_DESC_TYPE,(UINT32) (p - p_buff), p_buff);
643 #else /* SDP_SERVER_ENABLED == FALSE */
648 /*******************************************************************************
650 ** Function SDP_AddProtocolList
652 ** Description This function is called to add a protocol descriptor list to
653 ** a record. This would be through the SDP database maintenance API.
654 ** If the protocol list already exists in the record, it is replaced
655 ** with the new list.
657 ** Returns TRUE if added OK, else FALSE
659 *******************************************************************************/
660 BOOLEAN SDP_AddProtocolList (UINT32 handle, UINT16 num_elem,
661 tSDP_PROTOCOL_ELEM *p_elem_list)
663 #if SDP_SERVER_ENABLED == TRUE
668 if ((p_buff = (UINT8 *) osi_getbuf(sizeof(UINT8) * SDP_MAX_ATTR_LEN * 2)) == NULL)
670 SDP_TRACE_ERROR("SDP_AddProtocolList cannot get a buffer!");
674 offset = sdp_compose_proto_list(p_buff, num_elem, p_elem_list);
675 result = SDP_AddAttribute (handle, ATTR_ID_PROTOCOL_DESC_LIST,DATA_ELE_SEQ_DESC_TYPE, (UINT32) offset, p_buff);
678 #else /* SDP_SERVER_ENABLED == FALSE */
684 /*******************************************************************************
686 ** Function SDP_AddAdditionProtoLists
688 ** Description This function is called to add a protocol descriptor list to
689 ** a record. This would be through the SDP database maintenance API.
690 ** If the protocol list already exists in the record, it is replaced
691 ** with the new list.
693 ** Returns TRUE if added OK, else FALSE
695 *******************************************************************************/
696 BOOLEAN SDP_AddAdditionProtoLists (UINT32 handle, UINT16 num_elem,
697 tSDP_PROTO_LIST_ELEM *p_proto_list)
699 #if SDP_SERVER_ENABLED == TRUE
707 if ((p_buff = (UINT8 *) osi_getbuf(sizeof(UINT8) * SDP_MAX_ATTR_LEN * 2)) == NULL)
709 SDP_TRACE_ERROR("SDP_AddAdditionProtoLists cannot get a buffer!");
714 /* for each ProtocolDescriptorList */
715 for (xx = 0; xx < num_elem; xx++, p_proto_list++)
717 UINT8_TO_BE_STREAM (p, (DATA_ELE_SEQ_DESC_TYPE << 3) | SIZE_IN_NEXT_BYTE);
720 offset = sdp_compose_proto_list(p, p_proto_list->num_elems,
721 p_proto_list->list_elem);
724 *p_len = (UINT8)(p - p_len - 1);
726 result = SDP_AddAttribute (handle, ATTR_ID_ADDITION_PROTO_DESC_LISTS,DATA_ELE_SEQ_DESC_TYPE,
727 (UINT32) (p - p_buff), p_buff);
731 #else /* SDP_SERVER_ENABLED == FALSE */
736 /*******************************************************************************
738 ** Function SDP_AddProfileDescriptorList
740 ** Description This function is called to add a profile descriptor list to
741 ** a record. This would be through the SDP database maintenance API.
742 ** If the version already exists in the record, it is replaced
745 ** Returns TRUE if added OK, else FALSE
747 *******************************************************************************/
748 BOOLEAN SDP_AddProfileDescriptorList (UINT32 handle, UINT16 profile_uuid,
751 #if SDP_SERVER_ENABLED == TRUE
756 if ((p_buff = (UINT8 *) osi_getbuf(sizeof(UINT8) * SDP_MAX_ATTR_LEN)) == NULL)
758 SDP_TRACE_ERROR("SDP_AddProfileDescriptorList cannot get a buffer!");
763 /* First, build the profile descriptor list. This consists of a data element sequence. */
764 /* The sequence consists of profile's UUID and version number */
765 UINT8_TO_BE_STREAM (p, (UUID_DESC_TYPE << 3) | SIZE_TWO_BYTES);
766 UINT16_TO_BE_STREAM (p, profile_uuid);
768 UINT8_TO_BE_STREAM (p, (UINT_DESC_TYPE << 3) | SIZE_TWO_BYTES);
769 UINT16_TO_BE_STREAM (p, version);
771 /* Add in type and length fields */
772 *p_buff = (UINT8) ((DATA_ELE_SEQ_DESC_TYPE << 3) | SIZE_IN_NEXT_BYTE);
773 *(p_buff+1) = (UINT8) (p - (p_buff+2));
775 result = SDP_AddAttribute (handle, ATTR_ID_BT_PROFILE_DESC_LIST,DATA_ELE_SEQ_DESC_TYPE, (UINT32) (p - p_buff), p_buff);
779 #else /* SDP_SERVER_ENABLED == FALSE */
785 /*******************************************************************************
787 ** Function SDP_AddLanguageBaseAttrIDList
789 ** Description This function is called to add a language base attr list to
790 ** a record. This would be through the SDP database maintenance API.
791 ** If the version already exists in the record, it is replaced
794 ** Returns TRUE if added OK, else FALSE
796 *******************************************************************************/
797 BOOLEAN SDP_AddLanguageBaseAttrIDList (UINT32 handle, UINT16 lang,
798 UINT16 char_enc, UINT16 base_id)
800 #if SDP_SERVER_ENABLED == TRUE
805 if ((p_buff = (UINT8 *) osi_getbuf(sizeof(UINT8) * SDP_MAX_ATTR_LEN)) == NULL)
807 SDP_TRACE_ERROR("SDP_AddLanguageBaseAttrIDList cannot get a buffer!");
812 /* First, build the language base descriptor list. This consists of a data */
813 /* element sequence. The sequence consists of 9 bytes (3 UINt16 fields) */
814 UINT8_TO_BE_STREAM (p, (UINT_DESC_TYPE << 3) | SIZE_TWO_BYTES);
815 UINT16_TO_BE_STREAM (p, lang);
817 UINT8_TO_BE_STREAM (p, (UINT_DESC_TYPE << 3) | SIZE_TWO_BYTES);
818 UINT16_TO_BE_STREAM (p, char_enc);
820 UINT8_TO_BE_STREAM (p, (UINT_DESC_TYPE << 3) | SIZE_TWO_BYTES);
821 UINT16_TO_BE_STREAM (p, base_id);
823 result = SDP_AddAttribute (handle, ATTR_ID_LANGUAGE_BASE_ATTR_ID_LIST,DATA_ELE_SEQ_DESC_TYPE,
824 (UINT32) (p - p_buff), p_buff);
827 #else /* SDP_SERVER_ENABLED == FALSE */
833 /*******************************************************************************
835 ** Function SDP_AddServiceClassIdList
837 ** Description This function is called to add a service list to a record.
838 ** This would be through the SDP database maintenance API.
839 ** If the service list already exists in the record, it is replaced
840 ** with the new list.
842 ** Returns TRUE if added OK, else FALSE
844 *******************************************************************************/
845 BOOLEAN SDP_AddServiceClassIdList (UINT32 handle, UINT16 num_services,
846 UINT16 *p_service_uuids)
848 #if SDP_SERVER_ENABLED == TRUE
854 if ((p_buff = (UINT8 *) osi_getbuf(sizeof(UINT8) * SDP_MAX_ATTR_LEN * 2)) == NULL)
856 SDP_TRACE_ERROR("SDP_AddServiceClassIdList cannot get a buffer!");
861 for (xx = 0; xx < num_services; xx++, p_service_uuids++)
863 UINT8_TO_BE_STREAM (p, (UUID_DESC_TYPE << 3) | SIZE_TWO_BYTES);
864 UINT16_TO_BE_STREAM (p, *p_service_uuids);
867 result = SDP_AddAttribute (handle, ATTR_ID_SERVICE_CLASS_ID_LIST,DATA_ELE_SEQ_DESC_TYPE,
868 (UINT32) (p - p_buff), p_buff);
871 #else /* SDP_SERVER_ENABLED == FALSE */
877 /*******************************************************************************
879 ** Function SDP_DeleteAttribute
881 ** Description This function is called to delete an attribute from a record.
882 ** This would be through the SDP database maintenance API.
884 ** Returns TRUE if deleted OK, else FALSE if not found
886 *******************************************************************************/
887 BOOLEAN SDP_DeleteAttribute (UINT32 handle, UINT16 attr_id)
889 #if SDP_SERVER_ENABLED == TRUE
891 tSDP_RECORD *p_rec = &sdp_cb.server_db.record[0];
893 UINT32 len; /* Number of bytes in the entry */
895 /* Find the record in the database */
896 for (xx = 0; xx < sdp_cb.server_db.num_records; xx++, p_rec++)
898 if (p_rec->record_handle == handle)
900 tSDP_ATTRIBUTE *p_attr = &p_rec->attribute[0];
902 SDP_TRACE_API("Deleting attr_id 0x%04x for handle 0x%x", attr_id, handle);
903 /* Found it. Now, find the attribute */
904 for (xx = 0; xx < p_rec->num_attributes; xx++, p_attr++)
906 if (p_attr->id == attr_id)
908 pad_ptr = p_attr->value_ptr;
913 for (yy = 0; yy < p_rec->num_attributes; yy++)
915 if( p_rec->attribute[yy].value_ptr > pad_ptr )
916 p_rec->attribute[yy].value_ptr -= len;
920 /* Found it. Shift everything up one */
921 p_rec->num_attributes--;
923 for (yy = xx; yy < p_rec->num_attributes; yy++, p_attr++)
925 *p_attr = *(p_attr + 1);
928 /* adjust attribute values if needed */
931 xx = (p_rec->free_pad_ptr - ((pad_ptr+len) -
932 &p_rec->attr_pad[0]));
933 for( yy=0; yy<xx; yy++, pad_ptr++)
934 *pad_ptr = *(pad_ptr+len);
935 p_rec->free_pad_ptr -= len;
943 /* If here, not found */
947 /*******************************************************************************
949 ** Function SDP_ReadRecord
951 ** Description This function is called to get the raw data of the record
952 ** with the given handle from the database.
954 ** Returns -1, if the record is not found.
955 ** Otherwise, the offset (0 or 1) to start of data in p_data.
957 ** The size of data copied into p_data is in *p_data_len.
959 *******************************************************************************/
960 #if (SDP_RAW_DATA_INCLUDED == TRUE)
961 INT32 SDP_ReadRecord(UINT32 handle, UINT8 *p_data, INT32 *p_data_len)
963 INT32 len = 0; /* Number of bytes in the entry */
964 INT32 offset = -1; /* default to not found */
965 #if SDP_SERVER_ENABLED == TRUE
969 tSDP_ATTRIBUTE *p_attr;
973 /* Find the record in the database */
974 p_rec = sdp_db_find_record(handle);
975 if(p_rec && p_data && p_data_len)
978 while ( (p_attr = sdp_db_find_attr_in_rec (p_rec, start, end)) != NULL)
980 /* Check if attribute fits. Assume 3-byte value type/length */
981 rem_len = *p_data_len - (UINT16) (p_rsp - p_data);
983 if (p_attr->len > (UINT32)(rem_len - 6))
986 p_rsp = sdpu_build_attrib_entry (p_rsp, p_attr);
989 start = p_attr->id + 1;
991 len = (INT32) (p_rsp - p_data);
993 /* Put in the sequence header (2 or 3 bytes) */
997 p_data[0] = (UINT8) ((DATA_ELE_SEQ_DESC_TYPE << 3) | SIZE_IN_NEXT_WORD);
998 p_data[1] = (UINT8) ((len - 3) >> 8);
999 p_data[2] = (UINT8) (len - 3);
1005 p_data[1] = (UINT8) ((DATA_ELE_SEQ_DESC_TYPE << 3) | SIZE_IN_NEXT_BYTE);
1006 p_data[2] = (UINT8) (len - 3);
1013 /* If here, not found */