+/** 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],
+ const uint8_t TotalAttributes, void** const BufferPos)
+{
+ uint16_t TotalResponseSize;
+
+ /* Add an inner Data Element Sequence header for the current services's found Attributes */
+ uint16_t* AttributeListSize = SDP_AddSequence16(BufferPos);
+
+ /* 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];
+ void* AttributeValue;
+
+ /* Look through the current service's attribute list, examining all the attributes */
+ while ((AttributeValue = pgm_read_ptr(&AttributeTable->Data)) != NULL)
+ {
+ /* Get the current Attribute's ID from the current attribute table entry */
+ uint16_t CurrAttributeID = pgm_read_word(&AttributeTable->AttributeID);
+
+ /* Check if the current Attribute's ID is within the current Attribute range */
+ if ((CurrAttributeID >= AttributeIDRange[0]) && (CurrAttributeID <= AttributeIDRange[1]))
+ {
+ /* Increment the current UUID's returned Attribute container size by the number of added bytes */
+ *AttributeListSize += SDP_AddAttributeToResponse(CurrAttributeID, AttributeValue, BufferPos);
+ }
+
+ AttributeTable++;
+ }
+ }
+
+ /* Record the total number of added bytes to the buffer */
+ TotalResponseSize = 3 + *AttributeListSize;
+
+ /* Fix endianness of the added attribute data element sequence */
+ *AttributeListSize = SwapEndian_16(*AttributeListSize);
+
+ return TotalResponseSize;
+}
+