/** Reads in the collection of Attribute ranges from the input buffer's Data Element Sequence container, into the given * Attribute list for later use. Once complete, the input buffer pointer is advanced to the end of the Attribute container. * * \param[out] AttributeList Pointer to a buffer where the list of Attribute ranges are to be stored * \param[in] CurrentParameter Pointer to a Buffer containing a Data Element Sequence of Attribute and Attribute Range elements * * \return Total number of Attribute ranges stored in the Data Element Sequence */ static uint8_t SDP_GetAttributeList(uint16_t AttributeList[][2], const void** const CurrentParameter) { uint8_t ElementHeaderSize; uint8_t TotalAttributes = 0; /* Retrieve the total size of the Attribute container, and unwrap the outer Data Element Sequence container */ uint16_t AttributeIDListLength = SDP_GetDataElementSize(CurrentParameter, &ElementHeaderSize); while (AttributeIDListLength) { /* Retrieve the size of the next Attribute in the container and get a pointer to the next free Attribute element in the list */ uint16_t* CurrentAttributeRange = AttributeList[TotalAttributes++]; uint8_t AttributeLength = SDP_GetDataElementSize(CurrentParameter, &ElementHeaderSize); /* Copy over the starting Attribute ID and (if it the current element is a range) the ending Attribute ID */ memcpy(&CurrentAttributeRange[0], *CurrentParameter, AttributeLength); /* If the element is not an Attribute Range, copy over the starting ID to the ending ID to make a range of 1 */ if (AttributeLength == 2) CurrentAttributeRange[1] = CurrentAttributeRange[0]; /* Swap the endianness of the attribute range values */ CurrentAttributeRange[0] = be16_to_cpu(CurrentAttributeRange[0]); CurrentAttributeRange[1] = be16_to_cpu(CurrentAttributeRange[1]); AttributeIDListLength -= (AttributeLength + ElementHeaderSize); *CurrentParameter += AttributeLength; } return TotalAttributes; }
/** Reads in the collection of UUIDs from the input buffer's Data Element Sequence container, into the given * UUID list for later use. Once complete, the input buffer pointer is advanced to the end of the UUID container. * * \param[out] UUIDList Pointer to a buffer where the list of UUIDs are to be stored * \param[in] CurrentParameter Pointer to a Buffer containing a Data Element Sequence of UUID elements * * \return Total number of UUIDs stored in the Data Element Sequence */ static uint8_t SDP_GetUUIDList(uint8_t UUIDList[][UUID_SIZE_BYTES], const void** const CurrentParameter) { uint8_t ElementHeaderSize; uint8_t TotalUUIDs = 0; /* Retrieve the total size of the UUID container, and unwrap the outer Data Element Sequence container */ uint16_t ServicePatternLength = SDP_GetDataElementSize(CurrentParameter, &ElementHeaderSize); BT_SDP_DEBUG(2, "-- Total UUID Length: 0x%04X", ServicePatternLength); while (ServicePatternLength) { /* Retrieve the size of the next UUID in the container and get a pointer to the next free UUID element in the list */ uint8_t* CurrentUUID = UUIDList[TotalUUIDs++]; uint8_t UUIDLength = SDP_GetDataElementSize(CurrentParameter, &ElementHeaderSize); /* Copy over UUID from the container to the free slot */ if (UUIDLength <= 4) { /* Copy over the base UUID value to the free UUID slot in the list */ memcpy_P(CurrentUUID, &BaseUUID, sizeof(BaseUUID)); /* Copy over short UUID */ memcpy(CurrentUUID + (4 - UUIDLength), *CurrentParameter, UUIDLength); } else { /* Copy over full UUID */ memcpy(CurrentUUID, *CurrentParameter, UUIDLength); } BT_SDP_DEBUG(2, "-- UUID (%d): %02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X", UUIDLength, CurrentUUID[0], CurrentUUID[1], CurrentUUID[2], CurrentUUID[3], CurrentUUID[4], CurrentUUID[5], CurrentUUID[6], CurrentUUID[7], CurrentUUID[8], CurrentUUID[9], CurrentUUID[10], CurrentUUID[11], CurrentUUID[12], CurrentUUID[13], CurrentUUID[14], CurrentUUID[15]); ServicePatternLength -= (UUIDLength + ElementHeaderSize); *CurrentParameter += UUIDLength; } return TotalUUIDs; }