- /* If the current table item's UUID matches the search UUID, return a pointer the table item's Attribute table */
- if (!(memcmp_P(UUID, &SDP_Services_Table[CurrTableItem].UUID, UUID_SIZE_BYTES)))
- return CurrAttributeTable;
-
- /* Retrieve the list of the service's Class UUIDs from its Attribute table */
- void* ClassUUIDs = SDP_GetAttributeValue(CurrAttributeTable, SDP_ATTRIBUTE_ID_SERVICECLASSIDS);
+ /* If all UUIDs have been matched to the current service, return true */
+ return (UUIDMatches == TotalUUIDs);
+}
+
+/** Recursively upwraps the given locally stored attribute (in PROGMEM space), searching for UUIDs to match against
+ * the given UUID list. As matches are found, they are indicated in the UUIDMatch flag list.
+ *
+ * \param[in] UUIDList List of UUIDs which must be matched within the service attribute table
+ * \param[in] TotalUUIDs Total number of UUIDs stored in the UUID list
+ * \param[in, out] UUIDMatch Array of flags indicating which UUIDs in the list have already been matched
+ * \param[in] CurrAttribute Pointer to the current attribute to search through
+ *
+ * \return True if all the UUIDs given in the UUID list appear in the given attribute table, false otherwise
+ */
+static void SDP_CheckUUIDMatch(uint8_t UUIDList[][UUID_SIZE_BYTES], const uint8_t TotalUUIDs, bool UUIDMatch[],
+ const void* CurrAttribute)
+{
+ uint8_t CurrAttributeType = (pgm_read_byte(CurrAttribute) & ~0x07);
+
+ /* Check the data type of the current attribute value - if UUID, compare, if Sequence, unwrap and recurse */
+ if (CurrAttributeType == SDP_DATATYPE_UUID)
+ {
+ /* Look for matches in the UUID list against the current attribute UUID value */
+ for (uint8_t i = 0; i < TotalUUIDs; i++)
+ {
+ /* Check if the current unmatched UUID is identical to the search UUID */
+ if (!(UUIDMatch[i]) && !(memcmp_P(UUIDList[i], (CurrAttribute + 1), UUID_SIZE_BYTES)))
+ {
+ /* Indicate match found for the current attribute UUID and early-abort */
+ UUIDMatch[i] = true;
+ break;
+ }
+ }
+ }
+ else if (CurrAttributeType == SDP_DATATYPE_Sequence)
+ {
+ uint8_t SequenceHeaderSize;
+ uint16_t SequenceSize = SDP_GetLocalAttributeContainerSize(CurrAttribute, &SequenceHeaderSize);