diff --git a/include/btstack/sdp_util.h b/include/btstack/sdp_util.h index 4a682f9ab..018104b65 100644 --- a/include/btstack/sdp_util.h +++ b/include/btstack/sdp_util.h @@ -74,6 +74,6 @@ void de_add_data( uint8_t *seq, de_type_t type, uint16_t size, uint8_t *data); int de_get_data_size(uint8_t * header); #pragma mark SDP -void sdp_append_attributes_in_attributeIDList(uint8_t *record, uint8_t *attributeIDList, uint8_t *buffer, uint16_t maxBytes); +uint16_t sdp_append_attributes_in_attributeIDList(uint8_t *record, uint8_t *attributeIDList, uint16_t startIndex, uint16_t maxBytes, uint8_t *buffer); uint8_t * sdp_get_attribute_value_for_attribute_id(uint8_t * record, uint16_t attributeID); int sdp_record_matches_service_search_pattern(uint8_t *record, uint8_t *serviceSearchPattern); \ No newline at end of file diff --git a/src/sdp_util.c b/src/sdp_util.c index c814973c9..d30c1a435 100644 --- a/src/sdp_util.c +++ b/src/sdp_util.c @@ -257,41 +257,58 @@ int sdp_attribute_list_constains_id(uint8_t *attributeIDList, uint16_t attribute #pragma mark Append Attributes for AttributeIDList // pre: buffer contains DES with 2 byte length field -// context: { buffer, data_size, maxBytes, attributeListID } struct sdp_context_append_attributes { uint8_t * buffer; uint16_t dataSize; + uint16_t startIndex; // index of first to examine + uint16_t attributeIndex; // index over list uint16_t maxBytes; uint8_t *attributeIDList; + uint8_t moreData; // extra data: attributeIndex has to be examined next }; static int sdp_traversal_append_attributes(uint8_t * element, de_type_t type, de_size_t size, void *my_context){ struct sdp_context_append_attributes * context = (struct sdp_context_append_attributes *) my_context; // check each Attribute in root DES int attributeDataSize = de_get_data_size(element); int attributeLen = de_get_len(element); - // Attribute must be DES with more than sizeof(UINT16 element) - if (type == DE_DES && attributeDataSize >= 3){ + // Attribute must be DES with more than sizeof(UINT16 element) and index at least continuation index + if (type == DE_DES && attributeDataSize >= 3 && context->attributeIndex >= context->startIndex){ int attributeIDPos = de_get_header_size(element); de_size_t attributeIDSize = de_get_size_type(element+attributeIDPos); if (attributeIDSize == DE_SIZE_16) { uint16_t attributeID = READ_NET_16(element, attributeIDPos+1); - if ((context->dataSize + 3< context->maxBytes) && sdp_attribute_list_constains_id(context->attributeIDList, attributeID)){ - // copy Attribute - memcpy( context->buffer + 3 + context->dataSize, element, attributeLen); - context->dataSize += attributeLen; + if ( sdp_attribute_list_constains_id(context->attributeIDList, attributeID)){ + if (context->dataSize + 3< context->maxBytes) { + // copy Attribute + memcpy( context->buffer + 3 + context->dataSize, element, attributeLen); + context->dataSize += attributeLen; + } else { + // not enought space left -> continuation + context->moreData = 1; + return 1; + } } } } + context->attributeIndex++; return 0; } -void sdp_append_attributes_in_attributeIDList(uint8_t *record, uint8_t *attributeIDList, uint8_t *buffer, uint16_t maxBytes){ +// returns index of the next attribute index to process, if not all could be passed on, 0 = all processed +uint16_t sdp_append_attributes_in_attributeIDList(uint8_t *record, uint8_t *attributeIDList, uint16_t startIndex, uint16_t maxBytes, uint8_t *buffer){ struct sdp_context_append_attributes context; context.buffer = buffer; context.dataSize = READ_NET_16(buffer,1); context.maxBytes = maxBytes; + context.attributeIndex = 0; + context.startIndex = startIndex; + context.moreData = 0; context.attributeIDList = attributeIDList; de_traverse_sequence(record, sdp_traversal_append_attributes, &context); net_store_16(buffer, 1, context.dataSize); + if (!context.moreData) { + context.attributeIndex = 0; + } + return context.attributeIndex; } #pragma mark Get AttributeValue for AttributeID