mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-04-24 15:02:43 +00:00
implemented continuation handling for sdp_handle_service_attribute_request
This commit is contained in:
parent
e170797053
commit
231e1adb5d
@ -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);
|
int de_get_data_size(uint8_t * header);
|
||||||
|
|
||||||
#pragma mark SDP
|
#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);
|
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);
|
int sdp_record_matches_service_search_pattern(uint8_t *record, uint8_t *serviceSearchPattern);
|
@ -257,41 +257,58 @@ int sdp_attribute_list_constains_id(uint8_t *attributeIDList, uint16_t attribute
|
|||||||
|
|
||||||
#pragma mark Append Attributes for AttributeIDList
|
#pragma mark Append Attributes for AttributeIDList
|
||||||
// pre: buffer contains DES with 2 byte length field
|
// pre: buffer contains DES with 2 byte length field
|
||||||
// context: { buffer, data_size, maxBytes, attributeListID }
|
|
||||||
struct sdp_context_append_attributes {
|
struct sdp_context_append_attributes {
|
||||||
uint8_t * buffer;
|
uint8_t * buffer;
|
||||||
uint16_t dataSize;
|
uint16_t dataSize;
|
||||||
|
uint16_t startIndex; // index of first to examine
|
||||||
|
uint16_t attributeIndex; // index over list
|
||||||
uint16_t maxBytes;
|
uint16_t maxBytes;
|
||||||
uint8_t *attributeIDList;
|
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){
|
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;
|
struct sdp_context_append_attributes * context = (struct sdp_context_append_attributes *) my_context;
|
||||||
// check each Attribute in root DES
|
// check each Attribute in root DES
|
||||||
int attributeDataSize = de_get_data_size(element);
|
int attributeDataSize = de_get_data_size(element);
|
||||||
int attributeLen = de_get_len(element);
|
int attributeLen = de_get_len(element);
|
||||||
// Attribute must be DES with more than sizeof(UINT16 element)
|
// Attribute must be DES with more than sizeof(UINT16 element) and index at least continuation index
|
||||||
if (type == DE_DES && attributeDataSize >= 3){
|
if (type == DE_DES && attributeDataSize >= 3 && context->attributeIndex >= context->startIndex){
|
||||||
int attributeIDPos = de_get_header_size(element);
|
int attributeIDPos = de_get_header_size(element);
|
||||||
de_size_t attributeIDSize = de_get_size_type(element+attributeIDPos);
|
de_size_t attributeIDSize = de_get_size_type(element+attributeIDPos);
|
||||||
if (attributeIDSize == DE_SIZE_16) {
|
if (attributeIDSize == DE_SIZE_16) {
|
||||||
uint16_t attributeID = READ_NET_16(element, attributeIDPos+1);
|
uint16_t attributeID = READ_NET_16(element, attributeIDPos+1);
|
||||||
if ((context->dataSize + 3< context->maxBytes) && sdp_attribute_list_constains_id(context->attributeIDList, attributeID)){
|
if ( sdp_attribute_list_constains_id(context->attributeIDList, attributeID)){
|
||||||
|
if (context->dataSize + 3< context->maxBytes) {
|
||||||
// copy Attribute
|
// copy Attribute
|
||||||
memcpy( context->buffer + 3 + context->dataSize, element, attributeLen);
|
memcpy( context->buffer + 3 + context->dataSize, element, attributeLen);
|
||||||
context->dataSize += attributeLen;
|
context->dataSize += attributeLen;
|
||||||
|
} else {
|
||||||
|
// not enought space left -> continuation
|
||||||
|
context->moreData = 1;
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
context->attributeIndex++;
|
||||||
return 0;
|
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;
|
struct sdp_context_append_attributes context;
|
||||||
context.buffer = buffer;
|
context.buffer = buffer;
|
||||||
context.dataSize = READ_NET_16(buffer,1);
|
context.dataSize = READ_NET_16(buffer,1);
|
||||||
context.maxBytes = maxBytes;
|
context.maxBytes = maxBytes;
|
||||||
|
context.attributeIndex = 0;
|
||||||
|
context.startIndex = startIndex;
|
||||||
|
context.moreData = 0;
|
||||||
context.attributeIDList = attributeIDList;
|
context.attributeIDList = attributeIDList;
|
||||||
de_traverse_sequence(record, sdp_traversal_append_attributes, &context);
|
de_traverse_sequence(record, sdp_traversal_append_attributes, &context);
|
||||||
net_store_16(buffer, 1, context.dataSize);
|
net_store_16(buffer, 1, context.dataSize);
|
||||||
|
if (!context.moreData) {
|
||||||
|
context.attributeIndex = 0;
|
||||||
|
}
|
||||||
|
return context.attributeIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark Get AttributeValue for AttributeID
|
#pragma mark Get AttributeValue for AttributeID
|
||||||
|
Loading…
x
Reference in New Issue
Block a user