+/** 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;
+}
+
+/** Adds the given attribute ID and value to the reponse buffer, and advances the response buffer pointer past the added data.
+ *
+ * \param[in] AttributeID Attribute ID to add to the response buffer
+ * \param[in] AttributeValue Pointer to the start of the Attribute's value, located in PROGMEM
+ * \param[in, out] ResponseBuffer Pointer to a buffer where the Attribute and Attribute Value is to be added
+ *
+ * \return Number of bytes added to the response buffer
+ */
+static uint16_t SDP_AddAttributeToResponse(const uint16_t AttributeID, const void* AttributeValue, void** ResponseBuffer)
+{
+ /* Retrieve the size of the attribute value from its container header */
+ uint8_t AttributeHeaderLength;
+ uint16_t AttributeValueLength = SDP_GetLocalAttributeContainerSize(AttributeValue, &AttributeHeaderLength);
+
+ BT_SDP_DEBUG(2, " -- Add Attribute (0x%04X) 0x%04X", (AttributeHeaderLength + AttributeValueLength), AttributeID);
+
+ /* Add a Data Element header to the response for the Attribute ID */
+ SDP_WriteData8(ResponseBuffer, (SDP_DATATYPE_UnsignedInt | SDP_DATASIZE_16Bit));
+
+ /* Add the Attribute ID to the created Data Element */
+ SDP_WriteData16(ResponseBuffer, AttributeID);
+
+ /* Copy over the Attribute value Data Element container to the response */
+ memcpy_P(*ResponseBuffer, AttributeValue, AttributeHeaderLength + AttributeValueLength);
+ *ResponseBuffer += AttributeHeaderLength + AttributeValueLength;
+
+ return (sizeof(uint8_t) + sizeof(uint16_t) + AttributeHeaderLength + AttributeValueLength);
+}
+
+/** Retrieves a pointer to the value of the given Attribute ID from the given Attribute table.
+ *
+ * \param[in] AttributeTable Pointer to the Attribute table to search in
+ * \param[in] AttributeID Attribute ID to search for within the table
+ *
+ * \return Pointer to the start of the Attribute's value if found within the table, NULL otherwise
+ */
+static void* SDP_GetAttributeValue(const ServiceAttributeTable_t* AttributeTable, const uint16_t AttributeID)