+
+ /* Retrieve the service handle whose attributes are to be examined */
+ uint32_t ServiceHandle = SDP_ReadData32(&CurrentParameter);
+ BT_SDP_DEBUG(2, "-- Service Handle: 0x%08lX", ServiceHandle);
+
+ /* Retrieve the maximum Attribute reponse size from the request */
+ uint16_t MaxAttributeSize = SDP_ReadData16(&CurrentParameter);
+ BT_SDP_DEBUG(2, "-- Max Return Attribute Bytes: 0x%04X", MaxAttributeSize);
+
+ /* Retrieve the list of Attributes from the request */
+ uint16_t AttributeList[8][2];
+ uint8_t TotalAttributes = SDP_GetAttributeList(AttributeList, &CurrentParameter);
+ BT_SDP_DEBUG(2, "-- Total Attributes: %d", TotalAttributes);
+
+ struct
+ {
+ SDP_PDUHeader_t SDPHeader;
+ uint16_t AttributeListByteCount;
+ uint8_t ResponseData[100];
+ } ResponsePacket;
+
+ /* Create a pointer to the buffer to indicate the current location for response data to be added */
+ void* CurrResponsePos = ResponsePacket.ResponseData;
+
+ /* Clamp the maximum attribute size to the size of the allocated buffer */
+ if (MaxAttributeSize > sizeof(ResponsePacket.ResponseData))
+ MaxAttributeSize = sizeof(ResponsePacket.ResponseData);
+
+ uint16_t TotalResponseSize = 0;
+
+ /* Search through the global UUID list an item at a time */
+ for (uint8_t CurrTableItem = 0; CurrTableItem < (sizeof(SDP_Services_Table) / sizeof(void*)); CurrTableItem++)
+ {
+ /* Read in a pointer to the current UUID table entry's Attribute table */
+ ServiceAttributeTable_t* CurrAttributeTable = pgm_read_ptr(&SDP_Services_Table[CurrTableItem]);
+
+ /* Retrieve a PROGMEM pointer to the value of the Service Record Handle */
+ const void* ServiceRecord = SDP_GetAttributeValue(CurrAttributeTable, SDP_ATTRIBUTE_ID_SERVICERECORDHANDLE);
+
+ /* Get the size of the header for the Service Record Handle */
+ uint8_t AttrHeaderSize;
+ SDP_GetLocalAttributeContainerSize(ServiceRecord, &AttrHeaderSize);
+
+ /* Retrieve the endian-swapped service handle of the current service being examined */
+ uint32_t CurrServiceHandle = SwapEndian_32(pgm_read_dword(ServiceRecord + AttrHeaderSize));
+
+ /* Check if the current service in the service table has the requested service handle */
+ if (ServiceHandle == CurrServiceHandle)
+ {
+ /* Add the listed attributes for the found UUID to the response */
+ TotalResponseSize = SDP_AddListedAttributesToResponse(CurrAttributeTable, AttributeList, TotalAttributes,
+ &CurrResponsePos);
+
+ /* Requested service found, abort the search through the service table */
+ break;
+ }
+ }
+
+ /* Continuation state - always zero */
+ SDP_WriteData8(&CurrResponsePos, 0);
+
+ /* Set the total response list size to the size of the outer container plus its header size and continuation state */
+ ResponsePacket.AttributeListByteCount = SwapEndian_16(TotalResponseSize);
+
+ /* Calculate the total parameter length that is to be sent, including the fixed return parameters, the created attribute
+ value list and the SDP continuation state */
+ uint16_t ParamLength = (sizeof(ResponsePacket.AttributeListByteCount) + TotalResponseSize + sizeof(uint8_t));
+
+ /* Fill in the response packet's header */
+ ResponsePacket.SDPHeader.PDU = SDP_PDU_SERVICEATTRIBUTERESPONSE;
+ ResponsePacket.SDPHeader.TransactionID = SDPHeader->TransactionID;
+ ResponsePacket.SDPHeader.ParameterLength = SwapEndian_16(ParamLength);
+
+ BT_SDP_DEBUG(1, ">> Service Attribute Response");
+ BT_SDP_DEBUG(2, "-- Param Len 0x%04X", ParamLength);
+
+ /* Send the completed response packet to the sender */
+ Bluetooth_SendPacket(&ResponsePacket, (sizeof(ResponsePacket.SDPHeader) + ParamLength), Channel);