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 memset (p_ccb, 0, sizeof (tCONN_CB));
124 p_ccb->timer_entry.param = (UINT32) p_ccb;
130 /* If here, no free CCB found */
135 /*******************************************************************************
137 ** Function sdpu_release_ccb
139 ** Description This function releases a CCB.
143 *******************************************************************************/
144 void sdpu_release_ccb (tCONN_CB *p_ccb)
146 /* Ensure timer is stopped */
147 btu_stop_timer (&p_ccb->timer_entry);
149 /* Drop any response pointer we may be holding */
150 p_ccb->con_state = SDP_STATE_IDLE;
151 #if SDP_CLIENT_ENABLED == TRUE
152 p_ccb->is_attr_search = FALSE;
155 /* Free the response buffer */
156 if (p_ccb->rsp_list) {
157 SDP_TRACE_DEBUG("releasing SDP rsp_list\n");
159 osi_free(p_ccb->rsp_list);
160 p_ccb->rsp_list = NULL;
165 /*******************************************************************************
167 ** Function sdpu_build_attrib_seq
169 ** Description This function builds an attribute sequence from the list of
170 ** passed attributes. It is also passed the address of the output
173 ** Returns Pointer to next byte in the output buffer.
175 *******************************************************************************/
176 UINT8 *sdpu_build_attrib_seq (UINT8 *p_out, UINT16 *p_attr, UINT16 num_attrs)
180 /* First thing is the data element header. See if the length fits 1 byte */
181 /* If no attributes, assume a 4-byte wildcard */
189 UINT8_TO_BE_STREAM (p_out, (DATA_ELE_SEQ_DESC_TYPE << 3) | SIZE_IN_NEXT_WORD);
190 UINT16_TO_BE_STREAM (p_out, xx);
192 UINT8_TO_BE_STREAM (p_out, (DATA_ELE_SEQ_DESC_TYPE << 3) | SIZE_IN_NEXT_BYTE);
193 UINT8_TO_BE_STREAM (p_out, xx);
196 /* If there are no attributes specified, assume caller wants wildcard */
198 UINT8_TO_BE_STREAM (p_out, (UINT_DESC_TYPE << 3) | SIZE_FOUR_BYTES);
199 UINT16_TO_BE_STREAM (p_out, 0);
200 UINT16_TO_BE_STREAM (p_out, 0xFFFF);
202 /* Loop through and put in all the attributes(s) */
203 for (xx = 0; xx < num_attrs; xx++, p_attr++) {
204 UINT8_TO_BE_STREAM (p_out, (UINT_DESC_TYPE << 3) | SIZE_TWO_BYTES);
205 UINT16_TO_BE_STREAM (p_out, *p_attr);
213 /*******************************************************************************
215 ** Function sdpu_build_attrib_entry
217 ** Description This function builds an attribute entry from the passed
218 ** attribute record. It is also passed the address of the output
221 ** Returns Pointer to next byte in the output buffer.
223 *******************************************************************************/
224 UINT8 *sdpu_build_attrib_entry (UINT8 *p_out, tSDP_ATTRIBUTE *p_attr)
226 /* First, store the attribute ID. Goes as a UINT */
227 UINT8_TO_BE_STREAM (p_out, (UINT_DESC_TYPE << 3) | SIZE_TWO_BYTES);
228 UINT16_TO_BE_STREAM (p_out, p_attr->id);
230 /* the attribute is in the db record.
231 * assuming the attribute len is less than SDP_MAX_ATTR_LEN */
232 switch (p_attr->type) {
233 case TEXT_STR_DESC_TYPE: /* 4 */
234 case DATA_ELE_SEQ_DESC_TYPE:/* 6 */
235 case DATA_ELE_ALT_DESC_TYPE:/* 7 */
236 case URL_DESC_TYPE: /* 8 */
237 #if (SDP_MAX_ATTR_LEN > 0xFFFF)
238 if (p_attr->len > 0xFFFF) {
239 UINT8_TO_BE_STREAM (p_out, (p_attr->type << 3) | SIZE_IN_NEXT_LONG);
240 UINT32_TO_BE_STREAM (p_out, p_attr->len);
243 #endif /* 0xFFFF - 0xFF */
244 #if (SDP_MAX_ATTR_LEN > 0xFF)
245 if (p_attr->len > 0xFF) {
246 UINT8_TO_BE_STREAM (p_out, (p_attr->type << 3) | SIZE_IN_NEXT_WORD);
247 UINT16_TO_BE_STREAM (p_out, p_attr->len);
250 #endif /* 0xFF and less*/
252 UINT8_TO_BE_STREAM (p_out, (p_attr->type << 3) | SIZE_IN_NEXT_BYTE);
253 UINT8_TO_BE_STREAM (p_out, p_attr->len);
256 if (p_attr->value_ptr != NULL) {
257 ARRAY_TO_BE_STREAM (p_out, p_attr->value_ptr, (int)p_attr->len);
263 /* Now, store the attribute value */
264 switch (p_attr->len) {
266 UINT8_TO_BE_STREAM (p_out, (p_attr->type << 3) | SIZE_ONE_BYTE);
269 UINT8_TO_BE_STREAM (p_out, (p_attr->type << 3) | SIZE_TWO_BYTES);
272 UINT8_TO_BE_STREAM (p_out, (p_attr->type << 3) | SIZE_FOUR_BYTES);
275 UINT8_TO_BE_STREAM (p_out, (p_attr->type << 3) | SIZE_EIGHT_BYTES);
278 UINT8_TO_BE_STREAM (p_out, (p_attr->type << 3) | SIZE_SIXTEEN_BYTES);
281 UINT8_TO_BE_STREAM (p_out, (p_attr->type << 3) | SIZE_IN_NEXT_BYTE);
282 UINT8_TO_BE_STREAM (p_out, p_attr->len);
286 if (p_attr->value_ptr != NULL) {
287 ARRAY_TO_BE_STREAM (p_out, p_attr->value_ptr, (int)p_attr->len);
294 /*******************************************************************************
296 ** Function sdpu_build_n_send_error
298 ** Description This function builds and sends an error packet.
302 *******************************************************************************/
303 void sdpu_build_n_send_error (tCONN_CB *p_ccb, UINT16 trans_num, UINT16 error_code, char *p_error_text)
305 UINT8 *p_rsp, *p_rsp_start, *p_rsp_param_len;
306 UINT16 rsp_param_len;
310 SDP_TRACE_WARNING ("SDP - sdpu_build_n_send_error code: 0x%x CID: 0x%x\n",
311 error_code, p_ccb->connection_id);
313 /* Get a buffer to use to build and send the packet to L2CAP */
314 if ((p_buf = (BT_HDR *)osi_malloc(SDP_DATA_BUF_SIZE)) == NULL) {
315 SDP_TRACE_ERROR ("SDP - no buf for err msg\n");
318 p_buf->offset = L2CAP_MIN_OFFSET;
319 p_rsp = p_rsp_start = (UINT8 *)(p_buf + 1) + L2CAP_MIN_OFFSET;
321 UINT8_TO_BE_STREAM (p_rsp, SDP_PDU_ERROR_RESPONSE);
322 UINT16_TO_BE_STREAM (p_rsp, trans_num);
324 /* Skip the parameter length, we need to add it at the end */
325 p_rsp_param_len = p_rsp;
328 UINT16_TO_BE_STREAM (p_rsp, error_code);
330 /* Unplugfest example traces do not have any error text */
332 ARRAY_TO_BE_STREAM (p_rsp, p_error_text, (int) strlen (p_error_text));
335 /* Go back and put the parameter length into the buffer */
336 rsp_param_len = p_rsp - p_rsp_param_len - 2;
337 UINT16_TO_BE_STREAM (p_rsp_param_len, rsp_param_len);
339 /* Set the length of the SDP data in the buffer */
340 p_buf->len = p_rsp - p_rsp_start;
343 /* Send the buffer through L2CAP */
344 L2CA_DataWrite (p_ccb->connection_id, p_buf);
349 /*******************************************************************************
351 ** Function sdpu_extract_uid_seq
353 ** Description This function extracts a UUID sequence from the passed input
354 ** buffer, and puts it into the passed output list.
356 ** Returns Pointer to next byte in the input buffer after the sequence.
358 *******************************************************************************/
359 UINT8 *sdpu_extract_uid_seq (UINT8 *p, UINT16 param_len, tSDP_UUID_SEQ *p_seq)
362 UINT8 descr, type, size;
363 UINT32 seq_len, uuid_len;
365 /* Assume none found */
368 /* A UID sequence is composed of a bunch of UIDs. */
370 BE_STREAM_TO_UINT8 (descr, p);
374 if (type != DATA_ELE_SEQ_DESC_TYPE) {
382 case SIZE_FOUR_BYTES:
385 case SIZE_SIXTEEN_BYTES:
388 case SIZE_IN_NEXT_BYTE:
389 BE_STREAM_TO_UINT8 (seq_len, p);
391 case SIZE_IN_NEXT_WORD:
392 BE_STREAM_TO_UINT16 (seq_len, p);
394 case SIZE_IN_NEXT_LONG:
395 BE_STREAM_TO_UINT32 (seq_len, p);
401 if (seq_len >= param_len) {
405 p_seq_end = p + seq_len;
407 /* Loop through, extracting the UIDs */
408 for ( ; p < p_seq_end ; ) {
409 BE_STREAM_TO_UINT8 (descr, p);
413 if (type != UUID_DESC_TYPE) {
421 case SIZE_FOUR_BYTES:
424 case SIZE_SIXTEEN_BYTES:
427 case SIZE_IN_NEXT_BYTE:
428 BE_STREAM_TO_UINT8 (uuid_len, p);
430 case SIZE_IN_NEXT_WORD:
431 BE_STREAM_TO_UINT16 (uuid_len, p);
433 case SIZE_IN_NEXT_LONG:
434 BE_STREAM_TO_UINT32 (uuid_len, p);
440 /* If UUID length is valid, copy it across */
441 if ((uuid_len == 2) || (uuid_len == 4) || (uuid_len == 16)) {
442 p_seq->uuid_entry[p_seq->num_uids].len = (UINT16) uuid_len;
443 BE_STREAM_TO_ARRAY (p, p_seq->uuid_entry[p_seq->num_uids].value, (int)uuid_len);
449 /* We can only do so many */
450 if (p_seq->num_uids >= MAX_UUIDS_PER_SEQ) {
455 if (p != p_seq_end) {
464 /*******************************************************************************
466 ** Function sdpu_extract_attr_seq
468 ** Description This function extracts an attribute sequence from the passed
469 ** input buffer, and puts it into the passed output list.
471 ** Returns Pointer to next byte in the input buffer after the sequence.
473 *******************************************************************************/
474 UINT8 *sdpu_extract_attr_seq (UINT8 *p, UINT16 param_len, tSDP_ATTR_SEQ *p_seq)
477 UINT8 descr, type, size;
478 UINT32 list_len, attr_len;
480 /* Assume none found */
483 /* Get attribute sequence info */
484 BE_STREAM_TO_UINT8 (descr, p);
488 if (type != DATA_ELE_SEQ_DESC_TYPE) {
493 case SIZE_IN_NEXT_BYTE:
494 BE_STREAM_TO_UINT8 (list_len, p);
497 case SIZE_IN_NEXT_WORD:
498 BE_STREAM_TO_UINT16 (list_len, p);
501 case SIZE_IN_NEXT_LONG:
502 BE_STREAM_TO_UINT32 (list_len, p);
509 if (list_len > param_len) {
513 p_end_list = p + list_len;
515 /* Loop through, extracting the attribute IDs */
516 for ( ; p < p_end_list ; ) {
517 BE_STREAM_TO_UINT8 (descr, p);
521 if (type != UINT_DESC_TYPE) {
529 case SIZE_FOUR_BYTES:
532 case SIZE_IN_NEXT_BYTE:
533 BE_STREAM_TO_UINT8 (attr_len, p);
535 case SIZE_IN_NEXT_WORD:
536 BE_STREAM_TO_UINT16 (attr_len, p);
538 case SIZE_IN_NEXT_LONG:
539 BE_STREAM_TO_UINT32 (attr_len, p);
546 /* Attribute length must be 2-bytes or 4-bytes for a paired entry. */
548 BE_STREAM_TO_UINT16 (p_seq->attr_entry[p_seq->num_attr].start, p);
549 p_seq->attr_entry[p_seq->num_attr].end = p_seq->attr_entry[p_seq->num_attr].start;
550 } else if (attr_len == 4) {
551 BE_STREAM_TO_UINT16 (p_seq->attr_entry[p_seq->num_attr].start, p);
552 BE_STREAM_TO_UINT16 (p_seq->attr_entry[p_seq->num_attr].end, p);
557 /* We can only do so many */
558 if (++p_seq->num_attr >= MAX_ATTR_PER_SEQ) {
567 /*******************************************************************************
569 ** Function sdpu_get_len_from_type
571 ** Description This function gets the length
575 *******************************************************************************/
576 UINT8 *sdpu_get_len_from_type (UINT8 *p, UINT8 type, UINT32 *p_len)
589 case SIZE_FOUR_BYTES:
592 case SIZE_EIGHT_BYTES:
595 case SIZE_SIXTEEN_BYTES:
598 case SIZE_IN_NEXT_BYTE:
599 BE_STREAM_TO_UINT8 (u8, p);
602 case SIZE_IN_NEXT_WORD:
603 BE_STREAM_TO_UINT16 (u16, p);
606 case SIZE_IN_NEXT_LONG:
607 BE_STREAM_TO_UINT32 (u32, p);
608 *p_len = (UINT16) u32;
616 /*******************************************************************************
618 ** Function sdpu_is_base_uuid
620 ** Description This function checks a 128-bit UUID with the base to see if
621 ** it matches. Only the last 12 bytes are compared.
623 ** Returns TRUE if matched, else FALSE
625 *******************************************************************************/
626 BOOLEAN sdpu_is_base_uuid (UINT8 *p_uuid)
630 for (xx = 4; xx < MAX_UUID_SIZE; xx++)
631 if (p_uuid[xx] != sdp_base_uuid[xx]) {
635 /* If here, matched */
640 /*******************************************************************************
642 ** Function sdpu_compare_uuid_arrays
644 ** Description This function compares 2 BE UUIDs. If needed, they are expanded
645 ** to 128-bit UUIDs, then compared.
647 ** NOTE it is assumed that the arrays are in Big Endian format
649 ** Returns TRUE if matched, else FALSE
651 *******************************************************************************/
652 BOOLEAN sdpu_compare_uuid_arrays (UINT8 *p_uuid1, UINT32 len1, UINT8 *p_uuid2, UINT16 len2)
654 UINT8 nu1[MAX_UUID_SIZE];
655 UINT8 nu2[MAX_UUID_SIZE];
657 if ( ((len1 != 2) && (len1 != 4) && (len1 != 16)) ||
658 ((len2 != 2) && (len2 != 4) && (len2 != 16)) ) {
659 SDP_TRACE_ERROR("%s: invalid length\n", __func__);
663 /* If lengths match, do a straight compare */
666 return ((p_uuid1[0] == p_uuid2[0]) && (p_uuid1[1] == p_uuid2[1]));
669 return ( (p_uuid1[0] == p_uuid2[0]) && (p_uuid1[1] == p_uuid2[1])
670 && (p_uuid1[2] == p_uuid2[2]) && (p_uuid1[3] == p_uuid2[3]) );
672 return (memcmp (p_uuid1, p_uuid2, (size_t)len1) == 0);
674 } else if (len1 > len2) {
675 /* If the len1 was 4-byte, (so len2 is 2-byte), compare on the fly */
677 return ( (p_uuid1[0] == 0) && (p_uuid1[1] == 0)
678 && (p_uuid1[2] == p_uuid2[0]) && (p_uuid1[3] == p_uuid2[1]) );
680 /* Normalize UUIDs to 16-byte form, then compare. Len1 must be 16 */
681 memcpy (nu1, p_uuid1, MAX_UUID_SIZE);
682 memcpy (nu2, sdp_base_uuid, MAX_UUID_SIZE);
685 memcpy (nu2, p_uuid2, len2);
686 } else if (len2 == 2) {
687 memcpy (nu2 + 2, p_uuid2, len2);
690 return (memcmp (nu1, nu2, MAX_UUID_SIZE) == 0);
693 /* len2 is greater than len1 */
694 /* If the len2 was 4-byte, (so len1 is 2-byte), compare on the fly */
696 return ( (p_uuid2[0] == 0) && (p_uuid2[1] == 0)
697 && (p_uuid2[2] == p_uuid1[0]) && (p_uuid2[3] == p_uuid1[1]) );
699 /* Normalize UUIDs to 16-byte form, then compare. Len1 must be 16 */
700 memcpy (nu2, p_uuid2, MAX_UUID_SIZE);
701 memcpy (nu1, sdp_base_uuid, MAX_UUID_SIZE);
704 memcpy (nu1, p_uuid1, (size_t)len1);
705 } else if (len1 == 2) {
706 memcpy (nu1 + 2, p_uuid1, (size_t)len1);
709 return (memcmp (nu1, nu2, MAX_UUID_SIZE) == 0);
715 /*******************************************************************************
717 ** Function sdpu_compare_bt_uuids
719 ** Description This function compares 2 BT UUID structures.
721 ** NOTE it is assumed that BT UUID structures are compressed to the
722 ** smallest possible UUIDs (by removing the base SDP UUID)
724 ** Returns TRUE if matched, else FALSE
726 *******************************************************************************/
727 BOOLEAN sdpu_compare_bt_uuids (tBT_UUID *p_uuid1, tBT_UUID *p_uuid2)
729 /* Lengths must match for BT UUIDs to match */
730 if (p_uuid1->len == p_uuid2->len) {
731 if (p_uuid1->len == 2) {
732 return (p_uuid1->uu.uuid16 == p_uuid2->uu.uuid16);
733 } else if (p_uuid1->len == 4) {
734 return (p_uuid1->uu.uuid32 == p_uuid2->uu.uuid32);
735 } else if (!memcmp (p_uuid1->uu.uuid128, p_uuid2->uu.uuid128, 16)) {
744 /*******************************************************************************
746 ** Function sdpu_compare_uuid_with_attr
748 ** Description This function compares a BT UUID structure with the UUID in an
749 ** SDP attribute record. If needed, they are expanded to 128-bit
750 ** UUIDs, then compared.
752 ** NOTE - it is assumed that BT UUID structures are compressed to the
753 ** smallest possible UUIDs (by removing the base SDP UUID).
754 ** - it is also assumed that the discovery atribute is compressed
755 ** to the smallest possible
757 ** Returns TRUE if matched, else FALSE
759 *******************************************************************************/
760 BOOLEAN sdpu_compare_uuid_with_attr (tBT_UUID *p_btuuid, tSDP_DISC_ATTR *p_attr)
762 UINT16 attr_len = SDP_DISC_ATTR_LEN (p_attr->attr_len_type);
764 /* Since both UUIDs are compressed, lengths must match */
765 if (p_btuuid->len != attr_len) {
769 if (p_btuuid->len == 2) {
770 return (BOOLEAN)(p_btuuid->uu.uuid16 == p_attr->attr_value.v.u16);
771 } else if (p_btuuid->len == 4) {
772 return (BOOLEAN)(p_btuuid->uu.uuid32 == p_attr->attr_value.v.u32);
774 /* coverity[overrun-buffer-arg] */
776 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
777 FALSE-POSITIVE error from Coverity test tool. Please do NOT remove following comment.
778 False-positive: SDP uses scratch buffer to hold the attribute value.
779 The actual size of tSDP_DISC_ATVAL does not matter.
780 If the array size in tSDP_DISC_ATVAL is increase, we would increase the system RAM usage unnecessarily
782 else if (!memcmp (p_btuuid->uu.uuid128, (void *) p_attr->attr_value.v.array, MAX_UUID_SIZE)) {
789 /*******************************************************************************
791 ** Function sdpu_sort_attr_list
793 ** Description sorts a list of attributes in numeric order from lowest to
794 ** highest to conform to SDP specification
798 *******************************************************************************/
799 void sdpu_sort_attr_list( UINT16 num_attr, tSDP_DISCOVERY_DB *p_db )
804 /* Done if no attributes to sort */
807 } else if (num_attr > SDP_MAX_ATTR_FILTERS) {
808 num_attr = SDP_MAX_ATTR_FILTERS;
811 num_attr--; /* for the for-loop */
812 for ( i = 0; i < num_attr; ) {
813 if ( p_db->attr_filters[i] > p_db->attr_filters[i + 1] ) {
814 /* swap the attribute IDs and start from the beginning */
815 x = p_db->attr_filters[i];
816 p_db->attr_filters[i] = p_db->attr_filters[i + 1];
817 p_db->attr_filters[i + 1] = x;
827 /*******************************************************************************
829 ** Function sdpu_get_list_len
831 ** Description gets the total list length in the sdp database for a given
832 ** uid sequence and attr sequence
836 *******************************************************************************/
837 UINT16 sdpu_get_list_len(tSDP_UUID_SEQ *uid_seq, tSDP_ATTR_SEQ *attr_seq)
843 for (p_rec = sdp_db_service_search (NULL, uid_seq); p_rec; p_rec = sdp_db_service_search (p_rec, uid_seq)) {
846 len1 = sdpu_get_attrib_seq_len(p_rec, attr_seq );
857 /*******************************************************************************
859 ** Function sdpu_get_attrib_seq_len
861 ** Description gets the length of the specific attributes in a given
866 *******************************************************************************/
867 UINT16 sdpu_get_attrib_seq_len(tSDP_RECORD *p_rec, tSDP_ATTR_SEQ *attr_seq)
869 tSDP_ATTRIBUTE *p_attr;
872 BOOLEAN is_range = FALSE;
873 UINT16 start_id = 0, end_id = 0;
875 for (xx = 0; xx < attr_seq->num_attr; xx++) {
876 if (is_range == FALSE) {
877 start_id = attr_seq->attr_entry[xx].start;
878 end_id = attr_seq->attr_entry[xx].end;
880 p_attr = sdp_db_find_attr_in_rec (p_rec,
884 len1 += sdpu_get_attrib_entry_len (p_attr);
886 /* If doing a range, stick with this one till no more attributes found */
887 if (start_id != end_id) {
888 /* Update for next time through */
889 start_id = p_attr->id + 1;
902 /*******************************************************************************
904 ** Function sdpu_get_attrib_entry_len
906 ** Description gets the length of a specific attribute
910 *******************************************************************************/
911 UINT16 sdpu_get_attrib_entry_len(tSDP_ATTRIBUTE *p_attr)
915 /* the attribute is in the db record.
916 * assuming the attribute len is less than SDP_MAX_ATTR_LEN */
917 switch (p_attr->type) {
918 case TEXT_STR_DESC_TYPE: /* 4 */
919 case DATA_ELE_SEQ_DESC_TYPE:/* 6 */
920 case DATA_ELE_ALT_DESC_TYPE:/* 7 */
921 case URL_DESC_TYPE: /* 8 */
922 #if (SDP_MAX_ATTR_LEN > 0xFFFF)
923 if (p_attr->len > 0xFFFF) {
927 #endif/* 0xFFFF - 0xFF */
928 #if (SDP_MAX_ATTR_LEN > 0xFF)
929 if (p_attr->len > 0xFF) {
933 #endif /* 0xFF and less*/
941 /* Now, the attribute value */
942 switch (p_attr->len) {
960 /*******************************************************************************
962 ** Function sdpu_build_partial_attrib_entry
964 ** Description This function fills a buffer with partial attribute. It is
965 ** assumed that the maximum size of any attribute is 256 bytes.
967 ** p_out: output buffer
968 ** p_attr: attribute to be copied partially into p_out
969 ** rem_len: num bytes to copy into p_out
970 ** offset: current start offset within the attr that needs to be copied
972 ** Returns Pointer to next byte in the output buffer.
973 ** offset is also updated
975 *******************************************************************************/
976 UINT8 *sdpu_build_partial_attrib_entry (UINT8 *p_out, tSDP_ATTRIBUTE *p_attr, UINT16 len, UINT16 *offset)
983 if ((p_attr_buff = (UINT8 *) osi_malloc(sizeof(UINT8) * SDP_MAX_ATTR_LEN )) == NULL) {
984 SDP_TRACE_ERROR("sdpu_build_partial_attrib_entry cannot get a buffer!\n");
987 p_tmp_attr = p_attr_buff;
989 sdpu_build_attrib_entry(p_tmp_attr, p_attr);
990 attr_len = sdpu_get_attrib_entry_len(p_attr);
992 len_to_copy = ((attr_len - *offset) < len) ? (attr_len - *offset) : len;
994 memcpy(p_out, &p_attr_buff[*offset], len_to_copy);
996 p_out = &p_out[len_to_copy];
997 *offset += len_to_copy;
999 osi_free(p_attr_buff);
1003 /*******************************************************************************
1005 ** Function sdpu_uuid16_to_uuid128
1007 ** Description This function converts UUID-16 to UUID-128 by including the base UUID
1009 ** uuid16: 2-byte UUID
1010 ** p_uuid128: Expanded 128-bit UUID
1014 *******************************************************************************/
1016 void sdpu_uuid16_to_uuid128(UINT16 uuid16, UINT8 *p_uuid128)
1019 memset(p_uuid128, 0, 16);
1021 memcpy(p_uuid128, sdp_base_uuid, MAX_UUID_SIZE);
1022 uuid16_bo = ntohs(uuid16);
1023 memcpy(p_uuid128 + 2, &uuid16_bo, sizeof(uint16_t));
1026 #endif ///SDP_INCLUDED == TRUE