+ /* Add the outer Data Element Sequence header for all of the retrieved Attributes */
+ uint16_t* TotalResponseSize = SDP_AddDataElementHeader16(&CurrResponsePos, SDP_DATATYPE_Sequence);
+
+ /* Search through the list of UUIDs one at a time looking for matching search Attributes */
+ for (uint8_t CurrUUIDItem = 0; CurrUUIDItem < TotalUUIDs; CurrUUIDItem++)
+ {
+ /* Retrieve the attribute table of the current search UUID from the global UUID table if it exists */
+ ServiceAttributeTable_t* AttributeTable = SDP_GetAttributeTable(UUIDList[CurrUUIDItem]);
+
+ /* If the UUID does not exist in the global UUID table, continue on to the next search UUID */
+ if (AttributeTable == NULL)
+ continue;
+
+ BT_SDP_DEBUG(2, " -- Found UUID %d in table", CurrUUIDItem);
+
+ /* Add an inner Data Element Sequence header for the current UUID's found Attributes */
+ uint16_t* CurrentUUIDResponseSize = SDP_AddDataElementHeader16(&CurrResponsePos, SDP_DATATYPE_Sequence);
+
+ /* Search through the list of Attributes one at a time looking for values in the current UUID's Attribute table */
+ for (uint8_t CurrAttribute = 0; CurrAttribute < TotalAttributes; CurrAttribute++)
+ {
+ uint16_t* AttributeIDRange = AttributeList[CurrAttribute];
+
+ /* Look in the current Attribute Range for a matching Attribute ID in the UUID's Attribute table */
+ for (uint32_t CurrAttributeID = AttributeIDRange[0]; CurrAttributeID <= AttributeIDRange[1]; CurrAttributeID++)
+ {
+ /* Retrieve a PROGMEM pointer to the value of the current Attribute ID, if it exists in the UUID's Attribute table */
+ const void* AttributeValue = SDP_GetAttributeValue(AttributeTable, CurrAttributeID);
+
+ /* If the Attribute does not exist in the current UUID's Attribute table, continue to the next Attribute ID */
+ if (AttributeValue == NULL)
+ continue;
+
+ BT_SDP_DEBUG(2, " -- Add Attribute 0x%04X", CurrAttributeID);
+
+ /* Increment the current UUID's returned Attribute container size by the number of added bytes */
+ *CurrentUUIDResponseSize += SDP_AddAttributeToResponse(CurrAttributeID, AttributeValue, &CurrResponsePos);
+ }
+
+ /* Increment the outer container size by the number of added bytes */
+ *TotalResponseSize += 3 + *CurrentUUIDResponseSize;
+ }
+ }
+
+ /* Continuation state - always zero */
+ *((uint8_t*)CurrResponsePos) = 0;
+
+ /* Set the total response list size to the size of the outer container plus its header size and continuation state */
+ ResponsePacket.AttributeListByteCount = 4 + *TotalResponseSize;
+
+ /* Fill in the response packet's header */
+ ResponsePacket.SDPHeader.PDU = SDP_PDU_SERVICESEARCHATTRIBUTERESPONSE;
+ ResponsePacket.SDPHeader.TransactionID = SDPHeader->TransactionID;
+ ResponsePacket.SDPHeader.ParameterLength = (ResponsePacket.AttributeListByteCount + sizeof(ResponsePacket.AttributeListByteCount));
+
+ BT_SDP_DEBUG(1, ">> Service Search Attribute Response");
+ BT_SDP_DEBUG(2, "-- Total Parameter Length: 0x%04X", ResponsePacket.SDPHeader.ParameterLength);
+
+ /* Send the completed response packet to the sender */