+/** Adds all the Attributes in the given service table to the response that appear in the Attribute table.
+ *
+ * \param[in] AttributeTable Pointer to an Attribute table for the service to examine
+ * \param[in] AttributeList Pointer to a list of Attribute ranges
+ * \param[in] TotalAttributes Number of Attributes stored in the Attribute list
+ * \param[out] BufferPos Pointer to the output buffer position where the retrieved attributes are to be stored
+ *
+ * \return Number of bytes added to the output buffer
+ */
+static uint16_t SDP_AddListedAttributesToResponse(const ServiceAttributeTable_t* AttributeTable,
+ uint16_t AttributeList[][2], uint8_t TotalAttributes, void** BufferPos)
+{
+ uint16_t TotalResponseSize = 0;
+
+ /* Add an inner Data Element Sequence header for the current services's found Attributes */
+ uint16_t* AttributeListSize = SDP_AddDataElementHeader16(BufferPos, 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 */
+ *AttributeListSize += SDP_AddAttributeToResponse(CurrAttributeID, AttributeValue, BufferPos);
+ }
+
+ /* Increment the outer container size by the number of added bytes */
+ TotalResponseSize += 3 + *AttributeListSize;
+ }
+
+ /* Fix endianness of the added attribute data element sequence */
+ *AttributeListSize = SwapEndian_16(*AttributeListSize);
+
+ return TotalResponseSize;
+}
+