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 SDP utility functions
23 ******************************************************************************/
28 #include "allocator.h"
43 #if (SDP_INCLUDED == TRUE)
44 static const UINT8 sdp_base_uuid[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
45 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB
48 /*******************************************************************************
50 ** Function sdpu_find_ccb_by_cid
52 ** Description This function searches the CCB table for an entry with the
55 ** Returns the CCB address, or NULL if not found.
57 *******************************************************************************/
58 tCONN_CB *sdpu_find_ccb_by_cid (UINT16 cid)
63 /* Look through each connection control block */
64 for (xx = 0, p_ccb = sdp_cb.ccb; xx < SDP_MAX_CONNECTIONS; xx++, p_ccb++) {
65 if ((p_ccb->con_state != SDP_STATE_IDLE) && (p_ccb->connection_id == cid)) {
70 /* If here, not found */
75 /*******************************************************************************
77 ** Function sdpu_find_ccb_by_db
79 ** Description This function searches the CCB table for an entry with the
80 ** passed discovery db.
82 ** Returns the CCB address, or NULL if not found.
84 *******************************************************************************/
85 tCONN_CB *sdpu_find_ccb_by_db (tSDP_DISCOVERY_DB *p_db)
87 #if SDP_CLIENT_ENABLED == TRUE
92 /* Look through each connection control block */
93 for (xx = 0, p_ccb = sdp_cb.ccb; xx < SDP_MAX_CONNECTIONS; xx++, p_ccb++) {
94 if ((p_ccb->con_state != SDP_STATE_IDLE) && (p_ccb->p_db == p_db)) {
100 /* If here, not found */
105 /*******************************************************************************
107 ** Function sdpu_allocate_ccb
109 ** Description This function allocates a new CCB.
111 ** Returns CCB address, or NULL if none available.
113 *******************************************************************************/
114 tCONN_CB *sdpu_allocate_ccb (void)
119 /* Look through each connection control block for a free one */
120 for (xx = 0, p_ccb = sdp_cb.ccb; xx < SDP_MAX_CONNECTIONS; xx++, p_ccb++) {
121 if (p_ccb->con_state == SDP_STATE_IDLE) {
122 btu_free_timer(&p_ccb->timer_entry);
123 memset (p_ccb, 0, sizeof (tCONN_CB));
125 p_ccb->timer_entry.param = (UINT32) p_ccb;
131 /* If here, no free CCB found */
136 /*******************************************************************************
138 ** Function sdpu_release_ccb
140 ** Description This function releases a CCB.
144 *******************************************************************************/
145 void sdpu_release_ccb (tCONN_CB *p_ccb)
147 /* Ensure timer is stopped and released */
148 btu_free_timer(&p_ccb->timer_entry);
150 /* Drop any response pointer we may be holding */
151 p_ccb->con_state = SDP_STATE_IDLE;
152 #if SDP_CLIENT_ENABLED == TRUE
153 p_ccb->is_attr_search = FALSE;
156 /* Free the response buffer */
157 if (p_ccb->rsp_list) {
158 SDP_TRACE_DEBUG("releasing SDP rsp_list\n");
160 osi_free(p_ccb->rsp_list);
161 p_ccb->rsp_list = NULL;
166 /*******************************************************************************
168 ** Function sdpu_build_attrib_seq
170 ** Description This function builds an attribute sequence from the list of
171 ** passed attributes. It is also passed the address of the output
174 ** Returns Pointer to next byte in the output buffer.
176 *******************************************************************************/
177 UINT8 *sdpu_build_attrib_seq (UINT8 *p_out, UINT16 *p_attr, UINT16 num_attrs)
181 /* First thing is the data element header. See if the length fits 1 byte */
182 /* If no attributes, assume a 4-byte wildcard */
190 UINT8_TO_BE_STREAM (p_out, (DATA_ELE_SEQ_DESC_TYPE << 3) | SIZE_IN_NEXT_WORD);
191 UINT16_TO_BE_STREAM (p_out, xx);
193 UINT8_TO_BE_STREAM (p_out, (DATA_ELE_SEQ_DESC_TYPE << 3) | SIZE_IN_NEXT_BYTE);
194 UINT8_TO_BE_STREAM (p_out, xx);
197 /* If there are no attributes specified, assume caller wants wildcard */
199 UINT8_TO_BE_STREAM (p_out, (UINT_DESC_TYPE << 3) | SIZE_FOUR_BYTES);
200 UINT16_TO_BE_STREAM (p_out, 0);
201 UINT16_TO_BE_STREAM (p_out, 0xFFFF);
203 /* Loop through and put in all the attributes(s) */
204 for (xx = 0; xx < num_attrs; xx++, p_attr++) {
205 UINT8_TO_BE_STREAM (p_out, (UINT_DESC_TYPE << 3) | SIZE_TWO_BYTES);
206 UINT16_TO_BE_STREAM (p_out, *p_attr);
214 /*******************************************************************************
216 ** Function sdpu_build_attrib_entry
218 ** Description This function builds an attribute entry from the passed
219 ** attribute record. It is also passed the address of the output
222 ** Returns Pointer to next byte in the output buffer.
224 *******************************************************************************/
225 UINT8 *sdpu_build_attrib_entry (UINT8 *p_out, tSDP_ATTRIBUTE *p_attr)
227 /* First, store the attribute ID. Goes as a UINT */
228 UINT8_TO_BE_STREAM (p_out, (UINT_DESC_TYPE << 3) | SIZE_TWO_BYTES);
229 UINT16_TO_BE_STREAM (p_out, p_attr->id);
231 /* the attribute is in the db record.
232 * assuming the attribute len is less than SDP_MAX_ATTR_LEN */
233 switch (p_attr->type) {
234 case TEXT_STR_DESC_TYPE: /* 4 */
235 case DATA_ELE_SEQ_DESC_TYPE:/* 6 */
236 case DATA_ELE_ALT_DESC_TYPE:/* 7 */
237 case URL_DESC_TYPE: /* 8 */
238 #if (SDP_MAX_ATTR_LEN > 0xFFFF)
239 if (p_attr->len > 0xFFFF) {
240 UINT8_TO_BE_STREAM (p_out, (p_attr->type << 3) | SIZE_IN_NEXT_LONG);
241 UINT32_TO_BE_STREAM (p_out, p_attr->len);
244 #endif /* 0xFFFF - 0xFF */
245 #if (SDP_MAX_ATTR_LEN > 0xFF)
246 if (p_attr->len > 0xFF) {
247 UINT8_TO_BE_STREAM (p_out, (p_attr->type << 3) | SIZE_IN_NEXT_WORD);
248 UINT16_TO_BE_STREAM (p_out, p_attr->len);
251 #endif /* 0xFF and less*/
253 UINT8_TO_BE_STREAM (p_out, (p_attr->type << 3) | SIZE_IN_NEXT_BYTE);
254 UINT8_TO_BE_STREAM (p_out, p_attr->len);
257 if (p_attr->value_ptr != NULL) {
258 ARRAY_TO_BE_STREAM (p_out, p_attr->value_ptr, (int)p_attr->len);
264 /* Now, store the attribute value */
265 switch (p_attr->len) {
267 UINT8_TO_BE_STREAM (p_out, (p_attr->type << 3) | SIZE_ONE_BYTE);
270 UINT8_TO_BE_STREAM (p_out, (p_attr->type << 3) | SIZE_TWO_BYTES);
273 UINT8_TO_BE_STREAM (p_out, (p_attr->type << 3) | SIZE_FOUR_BYTES);
276 UINT8_TO_BE_STREAM (p_out, (p_attr->type << 3) | SIZE_EIGHT_BYTES);
279 UINT8_TO_BE_STREAM (p_out, (p_attr->type << 3) | SIZE_SIXTEEN_BYTES);
282 UINT8_TO_BE_STREAM (p_out, (p_attr->type << 3) | SIZE_IN_NEXT_BYTE);
283 UINT8_TO_BE_STREAM (p_out, p_attr->len);
287 if (p_attr->value_ptr != NULL) {
288 ARRAY_TO_BE_STREAM (p_out, p_attr->value_ptr, (int)p_attr->len);
295 /*******************************************************************************
297 ** Function sdpu_build_n_send_error
299 ** Description This function builds and sends an error packet.
303 *******************************************************************************/
304 void sdpu_build_n_send_error (tCONN_CB *p_ccb, UINT16 trans_num, UINT16 error_code, char *p_error_text)
306 UINT8 *p_rsp, *p_rsp_start, *p_rsp_param_len;
307 UINT16 rsp_param_len;
311 SDP_TRACE_WARNING ("SDP - sdpu_build_n_send_error code: 0x%x CID: 0x%x\n",
312 error_code, p_ccb->connection_id);
314 /* Get a buffer to use to build and send the packet to L2CAP */
315 if ((p_buf = (BT_HDR *)osi_malloc(SDP_DATA_BUF_SIZE)) == NULL) {
316 SDP_TRACE_ERROR ("SDP - no buf for err msg\n");
319 p_buf->offset = L2CAP_MIN_OFFSET;
320 p_rsp = p_rsp_start = (UINT8 *)(p_buf + 1) + L2CAP_MIN_OFFSET;
322 UINT8_TO_BE_STREAM (p_rsp, SDP_PDU_ERROR_RESPONSE);
323 UINT16_TO_BE_STREAM (p_rsp, trans_num);
325 /* Skip the parameter length, we need to add it at the end */
326 p_rsp_param_len = p_rsp;
329 UINT16_TO_BE_STREAM (p_rsp, error_code);
331 /* Unplugfest example traces do not have any error text */
333 ARRAY_TO_BE_STREAM (p_rsp, p_error_text, (int) strlen (p_error_text));
336 /* Go back and put the parameter length into the buffer */
337 rsp_param_len = p_rsp - p_rsp_param_len - 2;
338 UINT16_TO_BE_STREAM (p_rsp_param_len, rsp_param_len);
340 /* Set the length of the SDP data in the buffer */
341 p_buf->len = p_rsp - p_rsp_start;
344 /* Send the buffer through L2CAP */
345 L2CA_DataWrite (p_ccb->connection_id, p_buf);
350 /*******************************************************************************
352 ** Function sdpu_extract_uid_seq
354 ** Description This function extracts a UUID sequence from the passed input
355 ** buffer, and puts it into the passed output list.
357 ** Returns Pointer to next byte in the input buffer after the sequence.
359 *******************************************************************************/
360 UINT8 *sdpu_extract_uid_seq (UINT8 *p, UINT16 param_len, tSDP_UUID_SEQ *p_seq)
363 UINT8 descr, type, size;
364 UINT32 seq_len, uuid_len;
366 /* Assume none found */
369 /* A UID sequence is composed of a bunch of UIDs. */
371 BE_STREAM_TO_UINT8 (descr, p);
375 if (type != DATA_ELE_SEQ_DESC_TYPE) {
383 case SIZE_FOUR_BYTES:
386 case SIZE_SIXTEEN_BYTES:
389 case SIZE_IN_NEXT_BYTE:
390 BE_STREAM_TO_UINT8 (seq_len, p);
392 case SIZE_IN_NEXT_WORD:
393 BE_STREAM_TO_UINT16 (seq_len, p);
395 case SIZE_IN_NEXT_LONG:
396 BE_STREAM_TO_UINT32 (seq_len, p);
402 if (seq_len >= param_len) {
406 p_seq_end = p + seq_len;
408 /* Loop through, extracting the UIDs */
409 for ( ; p < p_seq_end ; ) {
410 BE_STREAM_TO_UINT8 (descr, p);
414 if (type != UUID_DESC_TYPE) {
422 case SIZE_FOUR_BYTES:
425 case SIZE_SIXTEEN_BYTES:
428 case SIZE_IN_NEXT_BYTE:
429 BE_STREAM_TO_UINT8 (uuid_len, p);
431 case SIZE_IN_NEXT_WORD:
432 BE_STREAM_TO_UINT16 (uuid_len, p);
434 case SIZE_IN_NEXT_LONG:
435 BE_STREAM_TO_UINT32 (uuid_len, p);
441 /* If UUID length is valid, copy it across */
442 if ((uuid_len == 2) || (uuid_len == 4) || (uuid_len == 16)) {
443 p_seq->uuid_entry[p_seq->num_uids].len = (UINT16) uuid_len;
444 BE_STREAM_TO_ARRAY (p, p_seq->uuid_entry[p_seq->num_uids].value, (int)uuid_len);
450 /* We can only do so many */
451 if (p_seq->num_uids >= MAX_UUIDS_PER_SEQ) {
456 if (p != p_seq_end) {
465 /*******************************************************************************
467 ** Function sdpu_extract_attr_seq
469 ** Description This function extracts an attribute sequence from the passed
470 ** input buffer, and puts it into the passed output list.
472 ** Returns Pointer to next byte in the input buffer after the sequence.
474 *******************************************************************************/
475 UINT8 *sdpu_extract_attr_seq (UINT8 *p, UINT16 param_len, tSDP_ATTR_SEQ *p_seq)
478 UINT8 descr, type, size;
479 UINT32 list_len, attr_len;
481 /* Assume none found */
484 /* Get attribute sequence info */
485 BE_STREAM_TO_UINT8 (descr, p);
489 if (type != DATA_ELE_SEQ_DESC_TYPE) {
494 case SIZE_IN_NEXT_BYTE:
495 BE_STREAM_TO_UINT8 (list_len, p);
498 case SIZE_IN_NEXT_WORD:
499 BE_STREAM_TO_UINT16 (list_len, p);
502 case SIZE_IN_NEXT_LONG:
503 BE_STREAM_TO_UINT32 (list_len, p);
510 if (list_len > param_len) {
514 p_end_list = p + list_len;
516 /* Loop through, extracting the attribute IDs */
517 for ( ; p < p_end_list ; ) {
518 BE_STREAM_TO_UINT8 (descr, p);
522 if (type != UINT_DESC_TYPE) {
530 case SIZE_FOUR_BYTES:
533 case SIZE_IN_NEXT_BYTE:
534 BE_STREAM_TO_UINT8 (attr_len, p);
536 case SIZE_IN_NEXT_WORD:
537 BE_STREAM_TO_UINT16 (attr_len, p);
539 case SIZE_IN_NEXT_LONG:
540 BE_STREAM_TO_UINT32 (attr_len, p);
547 /* Attribute length must be 2-bytes or 4-bytes for a paired entry. */
549 BE_STREAM_TO_UINT16 (p_seq->attr_entry[p_seq->num_attr].start, p);
550 p_seq->attr_entry[p_seq->num_attr].end = p_seq->attr_entry[p_seq->num_attr].start;
551 } else if (attr_len == 4) {
552 BE_STREAM_TO_UINT16 (p_seq->attr_entry[p_seq->num_attr].start, p);
553 BE_STREAM_TO_UINT16 (p_seq->attr_entry[p_seq->num_attr].end, p);
558 /* We can only do so many */
559 if (++p_seq->num_attr >= MAX_ATTR_PER_SEQ) {
568 /*******************************************************************************
570 ** Function sdpu_get_len_from_type
572 ** Description This function gets the length
576 *******************************************************************************/
577 UINT8 *sdpu_get_len_from_type (UINT8 *p, UINT8 type, UINT32 *p_len)
590 case SIZE_FOUR_BYTES:
593 case SIZE_EIGHT_BYTES:
596 case SIZE_SIXTEEN_BYTES:
599 case SIZE_IN_NEXT_BYTE:
600 BE_STREAM_TO_UINT8 (u8, p);
603 case SIZE_IN_NEXT_WORD:
604 BE_STREAM_TO_UINT16 (u16, p);
607 case SIZE_IN_NEXT_LONG:
608 BE_STREAM_TO_UINT32 (u32, p);
609 *p_len = (UINT16) u32;
617 /*******************************************************************************
619 ** Function sdpu_is_base_uuid
621 ** Description This function checks a 128-bit UUID with the base to see if
622 ** it matches. Only the last 12 bytes are compared.
624 ** Returns TRUE if matched, else FALSE
626 *******************************************************************************/
627 BOOLEAN sdpu_is_base_uuid (UINT8 *p_uuid)
631 for (xx = 4; xx < MAX_UUID_SIZE; xx++)
632 if (p_uuid[xx] != sdp_base_uuid[xx]) {
636 /* If here, matched */
641 /*******************************************************************************
643 ** Function sdpu_compare_uuid_arrays
645 ** Description This function compares 2 BE UUIDs. If needed, they are expanded
646 ** to 128-bit UUIDs, then compared.
648 ** NOTE it is assumed that the arrays are in Big Endian format
650 ** Returns TRUE if matched, else FALSE
652 *******************************************************************************/
653 BOOLEAN sdpu_compare_uuid_arrays (UINT8 *p_uuid1, UINT32 len1, UINT8 *p_uuid2, UINT16 len2)
655 UINT8 nu1[MAX_UUID_SIZE];
656 UINT8 nu2[MAX_UUID_SIZE];
658 if ( ((len1 != 2) && (len1 != 4) && (len1 != 16)) ||
659 ((len2 != 2) && (len2 != 4) && (len2 != 16)) ) {
660 SDP_TRACE_ERROR("%s: invalid length\n", __func__);
664 /* If lengths match, do a straight compare */
667 return ((p_uuid1[0] == p_uuid2[0]) && (p_uuid1[1] == p_uuid2[1]));
670 return ( (p_uuid1[0] == p_uuid2[0]) && (p_uuid1[1] == p_uuid2[1])
671 && (p_uuid1[2] == p_uuid2[2]) && (p_uuid1[3] == p_uuid2[3]) );
673 return (memcmp (p_uuid1, p_uuid2, (size_t)len1) == 0);
675 } else if (len1 > len2) {
676 /* If the len1 was 4-byte, (so len2 is 2-byte), compare on the fly */
678 return ( (p_uuid1[0] == 0) && (p_uuid1[1] == 0)
679 && (p_uuid1[2] == p_uuid2[0]) && (p_uuid1[3] == p_uuid2[1]) );
681 /* Normalize UUIDs to 16-byte form, then compare. Len1 must be 16 */
682 memcpy (nu1, p_uuid1, MAX_UUID_SIZE);
683 memcpy (nu2, sdp_base_uuid, MAX_UUID_SIZE);
686 memcpy (nu2, p_uuid2, len2);
687 } else if (len2 == 2) {
688 memcpy (nu2 + 2, p_uuid2, len2);
691 return (memcmp (nu1, nu2, MAX_UUID_SIZE) == 0);
694 /* len2 is greater than len1 */
695 /* If the len2 was 4-byte, (so len1 is 2-byte), compare on the fly */
697 return ( (p_uuid2[0] == 0) && (p_uuid2[1] == 0)
698 && (p_uuid2[2] == p_uuid1[0]) && (p_uuid2[3] == p_uuid1[1]) );
700 /* Normalize UUIDs to 16-byte form, then compare. Len1 must be 16 */
701 memcpy (nu2, p_uuid2, MAX_UUID_SIZE);
702 memcpy (nu1, sdp_base_uuid, MAX_UUID_SIZE);
705 memcpy (nu1, p_uuid1, (size_t)len1);
706 } else if (len1 == 2) {
707 memcpy (nu1 + 2, p_uuid1, (size_t)len1);
710 return (memcmp (nu1, nu2, MAX_UUID_SIZE) == 0);
716 /*******************************************************************************
718 ** Function sdpu_compare_bt_uuids
720 ** Description This function compares 2 BT UUID structures.
722 ** NOTE it is assumed that BT UUID structures are compressed to the
723 ** smallest possible UUIDs (by removing the base SDP UUID)
725 ** Returns TRUE if matched, else FALSE
727 *******************************************************************************/
728 BOOLEAN sdpu_compare_bt_uuids (tBT_UUID *p_uuid1, tBT_UUID *p_uuid2)
730 /* Lengths must match for BT UUIDs to match */
731 if (p_uuid1->len == p_uuid2->len) {
732 if (p_uuid1->len == 2) {
733 return (p_uuid1->uu.uuid16 == p_uuid2->uu.uuid16);
734 } else if (p_uuid1->len == 4) {
735 return (p_uuid1->uu.uuid32 == p_uuid2->uu.uuid32);
736 } else if (!memcmp (p_uuid1->uu.uuid128, p_uuid2->uu.uuid128, 16)) {
745 /*******************************************************************************
747 ** Function sdpu_compare_uuid_with_attr
749 ** Description This function compares a BT UUID structure with the UUID in an
750 ** SDP attribute record. If needed, they are expanded to 128-bit
751 ** UUIDs, then compared.
753 ** NOTE - it is assumed that BT UUID structures are compressed to the
754 ** smallest possible UUIDs (by removing the base SDP UUID).
755 ** - it is also assumed that the discovery atribute is compressed
756 ** to the smallest possible
758 ** Returns TRUE if matched, else FALSE
760 *******************************************************************************/
761 BOOLEAN sdpu_compare_uuid_with_attr (tBT_UUID *p_btuuid, tSDP_DISC_ATTR *p_attr)
763 UINT16 attr_len = SDP_DISC_ATTR_LEN (p_attr->attr_len_type);
765 /* Since both UUIDs are compressed, lengths must match */
766 if (p_btuuid->len != attr_len) {
770 if (p_btuuid->len == 2) {
771 return (BOOLEAN)(p_btuuid->uu.uuid16 == p_attr->attr_value.v.u16);
772 } else if (p_btuuid->len == 4) {
773 return (BOOLEAN)(p_btuuid->uu.uuid32 == p_attr->attr_value.v.u32);
775 /* coverity[overrun-buffer-arg] */
777 Event overrun-buffer-arg: Overrun of static array "&p_attr->attr_value.v.array" of size 4 bytes by passing it to a function which indexes it with argument "16U" at byte position 15
778 FALSE-POSITIVE error from Coverity test tool. Please do NOT remove following comment.
779 False-positive: SDP uses scratch buffer to hold the attribute value.
780 The actual size of tSDP_DISC_ATVAL does not matter.
781 If the array size in tSDP_DISC_ATVAL is increase, we would increase the system RAM usage unnecessarily
783 else if (!memcmp (p_btuuid->uu.uuid128, (void *) p_attr->attr_value.v.array, MAX_UUID_SIZE)) {
790 /*******************************************************************************
792 ** Function sdpu_sort_attr_list
794 ** Description sorts a list of attributes in numeric order from lowest to
795 ** highest to conform to SDP specification
799 *******************************************************************************/
800 void sdpu_sort_attr_list( UINT16 num_attr, tSDP_DISCOVERY_DB *p_db )
805 /* Done if no attributes to sort */
808 } else if (num_attr > SDP_MAX_ATTR_FILTERS) {
809 num_attr = SDP_MAX_ATTR_FILTERS;
812 num_attr--; /* for the for-loop */
813 for ( i = 0; i < num_attr; ) {
814 if ( p_db->attr_filters[i] > p_db->attr_filters[i + 1] ) {
815 /* swap the attribute IDs and start from the beginning */
816 x = p_db->attr_filters[i];
817 p_db->attr_filters[i] = p_db->attr_filters[i + 1];
818 p_db->attr_filters[i + 1] = x;
828 /*******************************************************************************
830 ** Function sdpu_get_list_len
832 ** Description gets the total list length in the sdp database for a given
833 ** uid sequence and attr sequence
837 *******************************************************************************/
838 UINT16 sdpu_get_list_len(tSDP_UUID_SEQ *uid_seq, tSDP_ATTR_SEQ *attr_seq)
844 for (p_rec = sdp_db_service_search (NULL, uid_seq); p_rec; p_rec = sdp_db_service_search (p_rec, uid_seq)) {
847 len1 = sdpu_get_attrib_seq_len(p_rec, attr_seq );
858 /*******************************************************************************
860 ** Function sdpu_get_attrib_seq_len
862 ** Description gets the length of the specific attributes in a given
867 *******************************************************************************/
868 UINT16 sdpu_get_attrib_seq_len(tSDP_RECORD *p_rec, tSDP_ATTR_SEQ *attr_seq)
870 tSDP_ATTRIBUTE *p_attr;
873 BOOLEAN is_range = FALSE;
874 UINT16 start_id = 0, end_id = 0;
876 for (xx = 0; xx < attr_seq->num_attr; xx++) {
877 if (is_range == FALSE) {
878 start_id = attr_seq->attr_entry[xx].start;
879 end_id = attr_seq->attr_entry[xx].end;
881 p_attr = sdp_db_find_attr_in_rec (p_rec,
885 len1 += sdpu_get_attrib_entry_len (p_attr);
887 /* If doing a range, stick with this one till no more attributes found */
888 if (start_id != end_id) {
889 /* Update for next time through */
890 start_id = p_attr->id + 1;
903 /*******************************************************************************
905 ** Function sdpu_get_attrib_entry_len
907 ** Description gets the length of a specific attribute
911 *******************************************************************************/
912 UINT16 sdpu_get_attrib_entry_len(tSDP_ATTRIBUTE *p_attr)
916 /* the attribute is in the db record.
917 * assuming the attribute len is less than SDP_MAX_ATTR_LEN */
918 switch (p_attr->type) {
919 case TEXT_STR_DESC_TYPE: /* 4 */
920 case DATA_ELE_SEQ_DESC_TYPE:/* 6 */
921 case DATA_ELE_ALT_DESC_TYPE:/* 7 */
922 case URL_DESC_TYPE: /* 8 */
923 #if (SDP_MAX_ATTR_LEN > 0xFFFF)
924 if (p_attr->len > 0xFFFF) {
928 #endif/* 0xFFFF - 0xFF */
929 #if (SDP_MAX_ATTR_LEN > 0xFF)
930 if (p_attr->len > 0xFF) {
934 #endif /* 0xFF and less*/
942 /* Now, the attribute value */
943 switch (p_attr->len) {
961 /*******************************************************************************
963 ** Function sdpu_build_partial_attrib_entry
965 ** Description This function fills a buffer with partial attribute. It is
966 ** assumed that the maximum size of any attribute is 256 bytes.
968 ** p_out: output buffer
969 ** p_attr: attribute to be copied partially into p_out
970 ** rem_len: num bytes to copy into p_out
971 ** offset: current start offset within the attr that needs to be copied
973 ** Returns Pointer to next byte in the output buffer.
974 ** offset is also updated
976 *******************************************************************************/
977 UINT8 *sdpu_build_partial_attrib_entry (UINT8 *p_out, tSDP_ATTRIBUTE *p_attr, UINT16 len, UINT16 *offset)
984 if ((p_attr_buff = (UINT8 *) osi_malloc(sizeof(UINT8) * SDP_MAX_ATTR_LEN )) == NULL) {
985 SDP_TRACE_ERROR("sdpu_build_partial_attrib_entry cannot get a buffer!\n");
988 p_tmp_attr = p_attr_buff;
990 sdpu_build_attrib_entry(p_tmp_attr, p_attr);
991 attr_len = sdpu_get_attrib_entry_len(p_attr);
993 len_to_copy = ((attr_len - *offset) < len) ? (attr_len - *offset) : len;
995 memcpy(p_out, &p_attr_buff[*offset], len_to_copy);
997 p_out = &p_out[len_to_copy];
998 *offset += len_to_copy;
1000 osi_free(p_attr_buff);
1004 /*******************************************************************************
1006 ** Function sdpu_uuid16_to_uuid128
1008 ** Description This function converts UUID-16 to UUID-128 by including the base UUID
1010 ** uuid16: 2-byte UUID
1011 ** p_uuid128: Expanded 128-bit UUID
1015 *******************************************************************************/
1017 void sdpu_uuid16_to_uuid128(UINT16 uuid16, UINT8 *p_uuid128)
1020 memset(p_uuid128, 0, 16);
1022 memcpy(p_uuid128, sdp_base_uuid, MAX_UUID_SIZE);
1023 uuid16_bo = ntohs(uuid16);
1024 memcpy(p_uuid128 + 2, &uuid16_bo, sizeof(uint16_t));
1027 #endif ///SDP_INCLUDED == TRUE