From a486ba59ea3e437a410ddda82282dbe573a5f0b0 Mon Sep 17 00:00:00 2001 From: "matthias.ringwald" Date: Thu, 12 May 2011 20:02:14 +0000 Subject: [PATCH] added sdp_traversal_set_attribute_for_id --- include/btstack/sdp_util.h | 1 + src/sdp_util.c | 39 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/include/btstack/sdp_util.h b/include/btstack/sdp_util.h index e457d0259..fc9dff489 100644 --- a/include/btstack/sdp_util.h +++ b/include/btstack/sdp_util.h @@ -125,6 +125,7 @@ int de_get_data_size(uint8_t * header); #pragma mark SDP int 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); + uint8_t sdp_set_attribute_value_for_attribute_id(uint8_t * record, uint16_t attributeID, uint32_t value); int sdp_record_matches_service_search_pattern(uint8_t *record, uint8_t *serviceSearchPattern); #if defined __cplusplus diff --git a/src/sdp_util.c b/src/sdp_util.c index 93adeddc6..7468e7f52 100644 --- a/src/sdp_util.c +++ b/src/sdp_util.c @@ -366,6 +366,45 @@ uint8_t * sdp_get_attribute_value_for_attribute_id(uint8_t * record, uint16_t at return context.attributeValue; } +#pragma mark Set AttributeValue for AttributeID +struct sdp_context_set_attribute_for_id { + uint16_t attributeID; + uint32_t attributeValue; + uint8_t attributeFound; +}; +static int sdp_traversal_set_attribute_for_id(uint16_t attributeID, uint8_t * attributeValue, de_type_t attributeType, de_size_t size, void *my_context){ + struct sdp_context_set_attribute_for_id * context = (struct sdp_context_set_attribute_for_id *) my_context; + if (attributeID == context->attributeID) { + context->attributeFound = 1; + switch (size){ + case DE_SIZE_8: + if (attributeType != DE_NIL){ + attributeValue[1] = context->attributeValue; + } + break; + case DE_SIZE_16: + net_store_16(attributeValue, 1, context->attributeValue); + break; + case DE_SIZE_32: + net_store_32(attributeValue, 1, context->attributeValue); + break; + // Might want to support STRINGS to, copy upto original length + default: + break; + } + return 1; + } + return 0; +} +uint8_t sdp_set_attribute_value_for_attribute_id(uint8_t * record, uint16_t attributeID, uint32_t value){ + struct sdp_context_set_attribute_for_id context; + context.attributeID = attributeID; + context.attributeValue = value; + context.attributeFound = 0; + sdp_attribute_list_traverse_sequence(record, sdp_traversal_set_attribute_for_id, &context); + return context.attributeFound; +} + #pragma mark ServiceRecord contains UUID // service record contains UUID // context { normalizedUUID }