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 ******************************************************************************/
27 #include <netinet/in.h>
43 static const UINT8 sdp_base_uuid[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
44 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
46 /*******************************************************************************
48 ** Function sdpu_find_ccb_by_cid
50 ** Description This function searches the CCB table for an entry with the
53 ** Returns the CCB address, or NULL if not found.
55 *******************************************************************************/
56 tCONN_CB *sdpu_find_ccb_by_cid (UINT16 cid)
61 /* Look through each connection control block */
62 for (xx = 0, p_ccb = sdp_cb.ccb; xx < SDP_MAX_CONNECTIONS; xx++, p_ccb++)
64 if ((p_ccb->con_state != SDP_STATE_IDLE) && (p_ccb->connection_id == cid))
68 /* If here, not found */
73 /*******************************************************************************
75 ** Function sdpu_find_ccb_by_db
77 ** Description This function searches the CCB table for an entry with the
78 ** passed discovery db.
80 ** Returns the CCB address, or NULL if not found.
82 *******************************************************************************/
83 tCONN_CB *sdpu_find_ccb_by_db (tSDP_DISCOVERY_DB *p_db)
85 #if SDP_CLIENT_ENABLED == TRUE
91 /* Look through each connection control block */
92 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))
99 /* If here, not found */
104 /*******************************************************************************
106 ** Function sdpu_allocate_ccb
108 ** Description This function allocates a new CCB.
110 ** Returns CCB address, or NULL if none available.
112 *******************************************************************************/
113 tCONN_CB *sdpu_allocate_ccb (void)
118 /* Look through each connection control block for a free one */
119 for (xx = 0, p_ccb = sdp_cb.ccb; xx < SDP_MAX_CONNECTIONS; xx++, p_ccb++)
121 if (p_ccb->con_state == SDP_STATE_IDLE)
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 */
148 btu_stop_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 */
159 SDP_TRACE_DEBUG("releasing SDP rsp_list");
161 GKI_freebuf(p_ccb->rsp_list);
162 p_ccb->rsp_list = NULL;
167 /*******************************************************************************
169 ** Function sdpu_build_attrib_seq
171 ** Description This function builds an attribute sequence from the list of
172 ** passed attributes. It is also passed the address of the output
175 ** Returns Pointer to next byte in the output buffer.
177 *******************************************************************************/
178 UINT8 *sdpu_build_attrib_seq (UINT8 *p_out, UINT16 *p_attr, UINT16 num_attrs)
182 /* First thing is the data element header. See if the length fits 1 byte */
183 /* If no attributes, assume a 4-byte wildcard */
191 UINT8_TO_BE_STREAM (p_out, (DATA_ELE_SEQ_DESC_TYPE << 3) | SIZE_IN_NEXT_WORD);
192 UINT16_TO_BE_STREAM (p_out, xx);
196 UINT8_TO_BE_STREAM (p_out, (DATA_ELE_SEQ_DESC_TYPE << 3) | SIZE_IN_NEXT_BYTE);
197 UINT8_TO_BE_STREAM (p_out, xx);
200 /* If there are no attributes specified, assume caller wants wildcard */
203 UINT8_TO_BE_STREAM (p_out, (UINT_DESC_TYPE << 3) | SIZE_FOUR_BYTES);
204 UINT16_TO_BE_STREAM (p_out, 0);
205 UINT16_TO_BE_STREAM (p_out, 0xFFFF);
209 /* Loop through and put in all the attributes(s) */
210 for (xx = 0; xx < num_attrs; xx++, p_attr++)
212 UINT8_TO_BE_STREAM (p_out, (UINT_DESC_TYPE << 3) | SIZE_TWO_BYTES);
213 UINT16_TO_BE_STREAM (p_out, *p_attr);
221 /*******************************************************************************
223 ** Function sdpu_build_attrib_entry
225 ** Description This function builds an attribute entry from the passed
226 ** attribute record. It is also passed the address of the output
229 ** Returns Pointer to next byte in the output buffer.
231 *******************************************************************************/
232 UINT8 *sdpu_build_attrib_entry (UINT8 *p_out, tSDP_ATTRIBUTE *p_attr)
234 /* First, store the attribute ID. Goes as a UINT */
235 UINT8_TO_BE_STREAM (p_out, (UINT_DESC_TYPE << 3) | SIZE_TWO_BYTES);
236 UINT16_TO_BE_STREAM (p_out, p_attr->id);
238 /* the attribute is in the db record.
239 * assuming the attribute len is less than SDP_MAX_ATTR_LEN */
242 case TEXT_STR_DESC_TYPE: /* 4 */
243 case DATA_ELE_SEQ_DESC_TYPE:/* 6 */
244 case DATA_ELE_ALT_DESC_TYPE:/* 7 */
245 case URL_DESC_TYPE: /* 8 */
246 #if (SDP_MAX_ATTR_LEN > 0xFFFF)
247 if(p_attr->len > 0xFFFF)
249 UINT8_TO_BE_STREAM (p_out, (p_attr->type << 3) | SIZE_IN_NEXT_LONG);
250 UINT32_TO_BE_STREAM (p_out, p_attr->len);
254 #endif /* 0xFFFF - 0xFF */
255 #if (SDP_MAX_ATTR_LEN > 0xFF)
256 if(p_attr->len > 0xFF)
258 UINT8_TO_BE_STREAM (p_out, (p_attr->type << 3) | SIZE_IN_NEXT_WORD);
259 UINT16_TO_BE_STREAM (p_out, p_attr->len);
263 #endif /* 0xFF and less*/
265 UINT8_TO_BE_STREAM (p_out, (p_attr->type << 3) | SIZE_IN_NEXT_BYTE);
266 UINT8_TO_BE_STREAM (p_out, p_attr->len);
269 if (p_attr->value_ptr != NULL) {
270 ARRAY_TO_BE_STREAM (p_out, p_attr->value_ptr, (int)p_attr->len);
276 /* Now, store the attribute value */
280 UINT8_TO_BE_STREAM (p_out, (p_attr->type << 3) | SIZE_ONE_BYTE);
283 UINT8_TO_BE_STREAM (p_out, (p_attr->type << 3) | SIZE_TWO_BYTES);
286 UINT8_TO_BE_STREAM (p_out, (p_attr->type << 3) | SIZE_FOUR_BYTES);
289 UINT8_TO_BE_STREAM (p_out, (p_attr->type << 3) | SIZE_EIGHT_BYTES);
292 UINT8_TO_BE_STREAM (p_out, (p_attr->type << 3) | SIZE_SIXTEEN_BYTES);
295 UINT8_TO_BE_STREAM (p_out, (p_attr->type << 3) | SIZE_IN_NEXT_BYTE);
296 UINT8_TO_BE_STREAM (p_out, p_attr->len);
300 if (p_attr->value_ptr != NULL) {
301 ARRAY_TO_BE_STREAM (p_out, p_attr->value_ptr, (int)p_attr->len);
308 /*******************************************************************************
310 ** Function sdpu_build_n_send_error
312 ** Description This function builds and sends an error packet.
316 *******************************************************************************/
317 void sdpu_build_n_send_error (tCONN_CB *p_ccb, UINT16 trans_num, UINT16 error_code, char *p_error_text)
319 UINT8 *p_rsp, *p_rsp_start, *p_rsp_param_len;
320 UINT16 rsp_param_len;
324 SDP_TRACE_WARNING ("SDP - sdpu_build_n_send_error code: 0x%x CID: 0x%x",
325 error_code, p_ccb->connection_id);
327 /* Get a buffer to use to build and send the packet to L2CAP */
328 if ((p_buf = (BT_HDR *)GKI_getpoolbuf (SDP_POOL_ID)) == NULL)
330 SDP_TRACE_ERROR ("SDP - no buf for err msg");
333 p_buf->offset = L2CAP_MIN_OFFSET;
334 p_rsp = p_rsp_start = (UINT8 *)(p_buf + 1) + L2CAP_MIN_OFFSET;
336 UINT8_TO_BE_STREAM (p_rsp, SDP_PDU_ERROR_RESPONSE);
337 UINT16_TO_BE_STREAM (p_rsp, trans_num);
339 /* Skip the parameter length, we need to add it at the end */
340 p_rsp_param_len = p_rsp;
343 UINT16_TO_BE_STREAM (p_rsp, error_code);
345 /* Unplugfest example traces do not have any error text */
347 ARRAY_TO_BE_STREAM (p_rsp, p_error_text, (int) strlen (p_error_text));
349 /* Go back and put the parameter length into the buffer */
350 rsp_param_len = p_rsp - p_rsp_param_len - 2;
351 UINT16_TO_BE_STREAM (p_rsp_param_len, rsp_param_len);
353 /* Set the length of the SDP data in the buffer */
354 p_buf->len = p_rsp - p_rsp_start;
357 /* Send the buffer through L2CAP */
358 L2CA_DataWrite (p_ccb->connection_id, p_buf);
363 /*******************************************************************************
365 ** Function sdpu_extract_uid_seq
367 ** Description This function extracts a UUID sequence from the passed input
368 ** buffer, and puts it into the passed output list.
370 ** Returns Pointer to next byte in the input buffer after the sequence.
372 *******************************************************************************/
373 UINT8 *sdpu_extract_uid_seq (UINT8 *p, UINT16 param_len, tSDP_UUID_SEQ *p_seq)
376 UINT8 descr, type, size;
377 UINT32 seq_len, uuid_len;
379 /* Assume none found */
382 /* A UID sequence is composed of a bunch of UIDs. */
384 BE_STREAM_TO_UINT8 (descr, p);
388 if (type != DATA_ELE_SEQ_DESC_TYPE)
396 case SIZE_FOUR_BYTES:
399 case SIZE_SIXTEEN_BYTES:
402 case SIZE_IN_NEXT_BYTE:
403 BE_STREAM_TO_UINT8 (seq_len, p);
405 case SIZE_IN_NEXT_WORD:
406 BE_STREAM_TO_UINT16 (seq_len, p);
408 case SIZE_IN_NEXT_LONG:
409 BE_STREAM_TO_UINT32 (seq_len, p);
415 if (seq_len >= param_len)
418 p_seq_end = p + seq_len;
420 /* Loop through, extracting the UIDs */
421 for ( ; p < p_seq_end ; )
423 BE_STREAM_TO_UINT8 (descr, p);
427 if (type != UUID_DESC_TYPE)
435 case SIZE_FOUR_BYTES:
438 case SIZE_SIXTEEN_BYTES:
441 case SIZE_IN_NEXT_BYTE:
442 BE_STREAM_TO_UINT8 (uuid_len, p);
444 case SIZE_IN_NEXT_WORD:
445 BE_STREAM_TO_UINT16 (uuid_len, p);
447 case SIZE_IN_NEXT_LONG:
448 BE_STREAM_TO_UINT32 (uuid_len, p);
454 /* If UUID length is valid, copy it across */
455 if ((uuid_len == 2) || (uuid_len == 4) || (uuid_len == 16))
457 p_seq->uuid_entry[p_seq->num_uids].len = (UINT16) uuid_len;
458 BE_STREAM_TO_ARRAY (p, p_seq->uuid_entry[p_seq->num_uids].value, (int)uuid_len);
464 /* We can only do so many */
465 if (p_seq->num_uids >= MAX_UUIDS_PER_SEQ)
477 /*******************************************************************************
479 ** Function sdpu_extract_attr_seq
481 ** Description This function extracts an attribute sequence from the passed
482 ** input buffer, and puts it into the passed output list.
484 ** Returns Pointer to next byte in the input buffer after the sequence.
486 *******************************************************************************/
487 UINT8 *sdpu_extract_attr_seq (UINT8 *p, UINT16 param_len, tSDP_ATTR_SEQ *p_seq)
490 UINT8 descr, type, size;
491 UINT32 list_len, attr_len;
493 /* Assume none found */
496 /* Get attribute sequence info */
497 BE_STREAM_TO_UINT8 (descr, p);
501 if (type != DATA_ELE_SEQ_DESC_TYPE)
506 case SIZE_IN_NEXT_BYTE:
507 BE_STREAM_TO_UINT8 (list_len, p);
510 case SIZE_IN_NEXT_WORD:
511 BE_STREAM_TO_UINT16 (list_len, p);
514 case SIZE_IN_NEXT_LONG:
515 BE_STREAM_TO_UINT32 (list_len, p);
522 if (list_len > param_len)
525 p_end_list = p + list_len;
527 /* Loop through, extracting the attribute IDs */
528 for ( ; p < p_end_list ; )
530 BE_STREAM_TO_UINT8 (descr, p);
534 if (type != UINT_DESC_TYPE)
542 case SIZE_FOUR_BYTES:
545 case SIZE_IN_NEXT_BYTE:
546 BE_STREAM_TO_UINT8 (attr_len, p);
548 case SIZE_IN_NEXT_WORD:
549 BE_STREAM_TO_UINT16 (attr_len, p);
551 case SIZE_IN_NEXT_LONG:
552 BE_STREAM_TO_UINT32 (attr_len, p);
559 /* Attribute length must be 2-bytes or 4-bytes for a paired entry. */
562 BE_STREAM_TO_UINT16 (p_seq->attr_entry[p_seq->num_attr].start, p);
563 p_seq->attr_entry[p_seq->num_attr].end = p_seq->attr_entry[p_seq->num_attr].start;
565 else if (attr_len == 4)
567 BE_STREAM_TO_UINT16 (p_seq->attr_entry[p_seq->num_attr].start, p);
568 BE_STREAM_TO_UINT16 (p_seq->attr_entry[p_seq->num_attr].end, p);
573 /* We can only do so many */
574 if (++p_seq->num_attr >= MAX_ATTR_PER_SEQ)
582 /*******************************************************************************
584 ** Function sdpu_get_len_from_type
586 ** Description This function gets the length
590 *******************************************************************************/
591 UINT8 *sdpu_get_len_from_type (UINT8 *p, UINT8 type, UINT32 *p_len)
605 case SIZE_FOUR_BYTES:
608 case SIZE_EIGHT_BYTES:
611 case SIZE_SIXTEEN_BYTES:
614 case SIZE_IN_NEXT_BYTE:
615 BE_STREAM_TO_UINT8 (u8, p);
618 case SIZE_IN_NEXT_WORD:
619 BE_STREAM_TO_UINT16 (u16, p);
622 case SIZE_IN_NEXT_LONG:
623 BE_STREAM_TO_UINT32 (u32, p);
624 *p_len = (UINT16) u32;
632 /*******************************************************************************
634 ** Function sdpu_is_base_uuid
636 ** Description This function checks a 128-bit UUID with the base to see if
637 ** it matches. Only the last 12 bytes are compared.
639 ** Returns TRUE if matched, else FALSE
641 *******************************************************************************/
642 BOOLEAN sdpu_is_base_uuid (UINT8 *p_uuid)
646 for (xx = 4; xx < MAX_UUID_SIZE; xx++)
647 if (p_uuid[xx] != sdp_base_uuid[xx])
650 /* If here, matched */
655 /*******************************************************************************
657 ** Function sdpu_compare_uuid_arrays
659 ** Description This function compares 2 BE UUIDs. If needed, they are expanded
660 ** to 128-bit UUIDs, then compared.
662 ** NOTE it is assumed that the arrays are in Big Endian format
664 ** Returns TRUE if matched, else FALSE
666 *******************************************************************************/
667 BOOLEAN sdpu_compare_uuid_arrays (UINT8 *p_uuid1, UINT32 len1, UINT8 *p_uuid2, UINT16 len2)
669 UINT8 nu1[MAX_UUID_SIZE];
670 UINT8 nu2[MAX_UUID_SIZE];
672 if( ((len1 != 2) && (len1 != 4) && (len1 != 16)) ||
673 ((len2 != 2) && (len2 != 4) && (len2 != 16)) )
675 SDP_TRACE_ERROR("%s: invalid length", __func__);
679 /* If lengths match, do a straight compare */
683 return ((p_uuid1[0] == p_uuid2[0]) && (p_uuid1[1] == p_uuid2[1]));
685 return ( (p_uuid1[0] == p_uuid2[0]) && (p_uuid1[1] == p_uuid2[1])
686 && (p_uuid1[2] == p_uuid2[2]) && (p_uuid1[3] == p_uuid2[3]) );
688 return (memcmp (p_uuid1, p_uuid2, (size_t)len1) == 0);
690 else if (len1 > len2)
692 /* If the len1 was 4-byte, (so len2 is 2-byte), compare on the fly */
695 return ( (p_uuid1[0] == 0) && (p_uuid1[1] == 0)
696 && (p_uuid1[2] == p_uuid2[0]) && (p_uuid1[3] == p_uuid2[1]) );
700 /* Normalize UUIDs to 16-byte form, then compare. Len1 must be 16 */
701 memcpy (nu1, p_uuid1, MAX_UUID_SIZE);
702 memcpy (nu2, sdp_base_uuid, MAX_UUID_SIZE);
705 memcpy (nu2, p_uuid2, len2);
707 memcpy (nu2 + 2, p_uuid2, len2);
709 return (memcmp (nu1, nu2, MAX_UUID_SIZE) == 0);
714 /* len2 is greater than len1 */
715 /* If the len2 was 4-byte, (so len1 is 2-byte), compare on the fly */
718 return ( (p_uuid2[0] == 0) && (p_uuid2[1] == 0)
719 && (p_uuid2[2] == p_uuid1[0]) && (p_uuid2[3] == p_uuid1[1]) );
723 /* Normalize UUIDs to 16-byte form, then compare. Len1 must be 16 */
724 memcpy (nu2, p_uuid2, MAX_UUID_SIZE);
725 memcpy (nu1, sdp_base_uuid, MAX_UUID_SIZE);
728 memcpy (nu1, p_uuid1, (size_t)len1);
730 memcpy (nu1 + 2, p_uuid1, (size_t)len1);
732 return (memcmp (nu1, nu2, MAX_UUID_SIZE) == 0);
738 /*******************************************************************************
740 ** Function sdpu_compare_bt_uuids
742 ** Description This function compares 2 BT UUID structures.
744 ** NOTE it is assumed that BT UUID structures are compressed to the
745 ** smallest possible UUIDs (by removing the base SDP UUID)
747 ** Returns TRUE if matched, else FALSE
749 *******************************************************************************/
750 BOOLEAN sdpu_compare_bt_uuids (tBT_UUID *p_uuid1, tBT_UUID *p_uuid2)
752 /* Lengths must match for BT UUIDs to match */
753 if (p_uuid1->len == p_uuid2->len)
755 if (p_uuid1->len == 2)
756 return (p_uuid1->uu.uuid16 == p_uuid2->uu.uuid16);
757 else if (p_uuid1->len == 4)
758 return (p_uuid1->uu.uuid32 == p_uuid2->uu.uuid32);
759 else if (!memcmp (p_uuid1->uu.uuid128, p_uuid2->uu.uuid128, 16))
767 /*******************************************************************************
769 ** Function sdpu_compare_uuid_with_attr
771 ** Description This function compares a BT UUID structure with the UUID in an
772 ** SDP attribute record. If needed, they are expanded to 128-bit
773 ** UUIDs, then compared.
775 ** NOTE - it is assumed that BT UUID structures are compressed to the
776 ** smallest possible UUIDs (by removing the base SDP UUID).
777 ** - it is also assumed that the discovery atribute is compressed
778 ** to the smallest possible
780 ** Returns TRUE if matched, else FALSE
782 *******************************************************************************/
783 BOOLEAN sdpu_compare_uuid_with_attr (tBT_UUID *p_btuuid, tSDP_DISC_ATTR *p_attr)
785 UINT16 attr_len = SDP_DISC_ATTR_LEN (p_attr->attr_len_type);
787 /* Since both UUIDs are compressed, lengths must match */
788 if (p_btuuid->len != attr_len)
791 if (p_btuuid->len == 2)
792 return (BOOLEAN)(p_btuuid->uu.uuid16 == p_attr->attr_value.v.u16);
793 else if (p_btuuid->len == 4)
794 return (BOOLEAN)(p_btuuid->uu.uuid32 == p_attr->attr_value.v.u32);
795 /* coverity[overrun-buffer-arg] */
797 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
798 FALSE-POSITIVE error from Coverity test tool. Please do NOT remove following comment.
799 False-positive: SDP uses scratch buffer to hold the attribute value.
800 The actual size of tSDP_DISC_ATVAL does not matter.
801 If the array size in tSDP_DISC_ATVAL is increase, we would increase the system RAM usage unnecessarily
803 else if (!memcmp (p_btuuid->uu.uuid128,(void*) p_attr->attr_value.v.array, MAX_UUID_SIZE))
809 /*******************************************************************************
811 ** Function sdpu_sort_attr_list
813 ** Description sorts a list of attributes in numeric order from lowest to
814 ** highest to conform to SDP specification
818 *******************************************************************************/
819 void sdpu_sort_attr_list( UINT16 num_attr, tSDP_DISCOVERY_DB *p_db )
824 /* Done if no attributes to sort */
829 else if (num_attr > SDP_MAX_ATTR_FILTERS)
831 num_attr = SDP_MAX_ATTR_FILTERS;
834 num_attr--; /* for the for-loop */
835 for( i = 0; i < num_attr; )
837 if( p_db->attr_filters[i] > p_db->attr_filters[i+1] )
839 /* swap the attribute IDs and start from the beginning */
840 x = p_db->attr_filters[i];
841 p_db->attr_filters[i] = p_db->attr_filters[i+1];
842 p_db->attr_filters[i+1] = x;
852 /*******************************************************************************
854 ** Function sdpu_get_list_len
856 ** Description gets the total list length in the sdp database for a given
857 ** uid sequence and attr sequence
861 *******************************************************************************/
862 UINT16 sdpu_get_list_len(tSDP_UUID_SEQ *uid_seq, tSDP_ATTR_SEQ *attr_seq)
868 for (p_rec = sdp_db_service_search (NULL, uid_seq); p_rec; p_rec = sdp_db_service_search (p_rec, uid_seq))
872 len1 = sdpu_get_attrib_seq_len(p_rec, attr_seq );
882 /*******************************************************************************
884 ** Function sdpu_get_attrib_seq_len
886 ** Description gets the length of the specific attributes in a given
891 *******************************************************************************/
892 UINT16 sdpu_get_attrib_seq_len(tSDP_RECORD *p_rec, tSDP_ATTR_SEQ *attr_seq)
894 tSDP_ATTRIBUTE *p_attr;
897 BOOLEAN is_range = FALSE;
898 UINT16 start_id=0, end_id=0;
900 for (xx = 0; xx < attr_seq->num_attr; xx++)
902 if (is_range == FALSE)
904 start_id = attr_seq->attr_entry[xx].start;
905 end_id = attr_seq->attr_entry[xx].end;
907 p_attr = sdp_db_find_attr_in_rec (p_rec,
912 len1 += sdpu_get_attrib_entry_len (p_attr);
914 /* If doing a range, stick with this one till no more attributes found */
915 if (start_id != end_id)
917 /* Update for next time through */
918 start_id = p_attr->id + 1;
931 /*******************************************************************************
933 ** Function sdpu_get_attrib_entry_len
935 ** Description gets the length of a specific attribute
939 *******************************************************************************/
940 UINT16 sdpu_get_attrib_entry_len(tSDP_ATTRIBUTE *p_attr)
944 /* the attribute is in the db record.
945 * assuming the attribute len is less than SDP_MAX_ATTR_LEN */
948 case TEXT_STR_DESC_TYPE: /* 4 */
949 case DATA_ELE_SEQ_DESC_TYPE:/* 6 */
950 case DATA_ELE_ALT_DESC_TYPE:/* 7 */
951 case URL_DESC_TYPE: /* 8 */
952 #if (SDP_MAX_ATTR_LEN > 0xFFFF)
953 if(p_attr->len > 0xFFFF)
959 #endif/* 0xFFFF - 0xFF */
960 #if (SDP_MAX_ATTR_LEN > 0xFF)
961 if(p_attr->len > 0xFF)
967 #endif /* 0xFF and less*/
975 /* Now, the attribute value */
995 /*******************************************************************************
997 ** Function sdpu_build_partial_attrib_entry
999 ** Description This function fills a buffer with partial attribute. It is
1000 ** assumed that the maximum size of any attribute is 256 bytes.
1002 ** p_out: output buffer
1003 ** p_attr: attribute to be copied partially into p_out
1004 ** rem_len: num bytes to copy into p_out
1005 ** offset: current start offset within the attr that needs to be copied
1007 ** Returns Pointer to next byte in the output buffer.
1008 ** offset is also updated
1010 *******************************************************************************/
1011 UINT8 *sdpu_build_partial_attrib_entry (UINT8 *p_out, tSDP_ATTRIBUTE *p_attr, UINT16 len, UINT16 *offset)
1018 if ((p_attr_buff = (UINT8 *) GKI_getbuf(sizeof(UINT8) * SDP_MAX_ATTR_LEN )) == NULL)
1020 SDP_TRACE_ERROR("sdpu_build_partial_attrib_entry cannot get a buffer!");
1023 p_tmp_attr = p_attr_buff;
1025 sdpu_build_attrib_entry(p_tmp_attr, p_attr);
1026 attr_len = sdpu_get_attrib_entry_len(p_attr);
1028 len_to_copy = ((attr_len - *offset) < len) ? (attr_len - *offset): len;
1030 memcpy(p_out, &p_attr_buff[*offset], len_to_copy);
1032 p_out = &p_out[len_to_copy];
1033 *offset += len_to_copy;
1035 GKI_freebuf(p_attr_buff);
1039 /*******************************************************************************
1041 ** Function sdpu_uuid16_to_uuid128
1043 ** Description This function converts UUID-16 to UUID-128 by including the base UUID
1045 ** uuid16: 2-byte UUID
1046 ** p_uuid128: Expanded 128-bit UUID
1050 *******************************************************************************/
1051 void sdpu_uuid16_to_uuid128(UINT16 uuid16, UINT8* p_uuid128)
1054 memset(p_uuid128, 0, 16);
1056 memcpy(p_uuid128, sdp_base_uuid, MAX_UUID_SIZE);
1057 uuid16_bo = ntohs(uuid16);
1058 memcpy(p_uuid128+ 2, &uuid16_bo, sizeof(uint16_t));