#define INCLUDE_FROM_SERVICEDISCOVERYPROTOCOL_C\r
#include "ServiceDiscoveryProtocol.h"\r
\r
+SERVICE_ATTRIBUTE_TEXT(SDP_Attribute_Name, "SDP");\r
+SERVICE_ATTRIBUTE_TEXT(SDP_Attribute_Description, "BT Service Discovery");\r
+SERVICE_ATTRIBUTE_8BIT_LEN(SDP_Attribute_Availability, SDP_DATATYPE_UNSIGNED_INT, 1, {0xFF});\r
+const ServiceAttributeTable_t SDP_Attribute_Table[] PROGMEM =\r
+ {\r
+ {.AttributeID = SDP_ATTRIBUTE_NAME , .AttributeData = &SDP_Attribute_Name},\r
+ {.AttributeID = SDP_ATTRIBUTE_DESCRIPTION , .AttributeData = &SDP_Attribute_Description},\r
+ {.AttributeID = SDP_ATTRIBUTE_AVAILABILITY, .AttributeData = &SDP_Attribute_Availability},\r
+ {.AttributeData = NULL}\r
+ };\r
+\r
+SERVICE_ATTRIBUTE_TEXT(RFCOMM_Attribute_Name, "RFCOMM");\r
+SERVICE_ATTRIBUTE_TEXT(RFCOMM_Attribute_Description, "Virtual Serial");\r
+SERVICE_ATTRIBUTE_8BIT_LEN(RFCOMM_Attribute_Availability, SDP_DATATYPE_UNSIGNED_INT, 1, {0xFF});\r
+const ServiceAttributeTable_t RFCOMM_Attribute_Table[] PROGMEM =\r
+ {\r
+ {.AttributeID = SDP_ATTRIBUTE_NAME , .AttributeData = &RFCOMM_Attribute_Name},\r
+ {.AttributeID = SDP_ATTRIBUTE_DESCRIPTION , .AttributeData = &RFCOMM_Attribute_Description},\r
+ {.AttributeID = SDP_ATTRIBUTE_AVAILABILITY, .AttributeData = &RFCOMM_Attribute_Availability},\r
+ {.AttributeData = NULL}\r
+ };\r
+ \r
+const ServiceTable_t SDP_Services_Table[] =\r
+ {\r
+ { // 128-bit UUID for the SDP service\r
+ .UUID = {BASE_96BIT_UUID, 0x01, 0x00, 0x00, 0x00},\r
+ .AttributeTable = &SDP_Attribute_Table,\r
+ },\r
+ { // 128-bit UUID for the RFCOMM service\r
+ .UUID = {BASE_96BIT_UUID, 0x03, 0x00, 0x00, 0x00},\r
+ .AttributeTable = &RFCOMM_Attribute_Table,\r
+ },\r
+ };\r
+\r
+\r
void ServiceDiscovery_ProcessPacket(void* Data, Bluetooth_Channel_t* Channel)\r
{\r
SDP_PDUHeader_t* SDPHeader = (SDP_PDUHeader_t*)Data;\r
BT_SDP_DEBUG(1, "SDP Packet Received", NULL);\r
BT_SDP_DEBUG(2, "-- PDU ID: 0x%02X", SDPHeader->PDU);\r
BT_SDP_DEBUG(2, "-- Param Length: 0x%04X", SDPHeader->ParameterLength);\r
- \r
- printf("\r\n");\r
- for (uint8_t i = 0; i < SDPHeader->ParameterLength; i++)\r
- printf("0x%02X ", *((uint8_t*)Data + sizeof(SDP_PDUHeader_t) + i));\r
- printf("\r\n");\r
\r
switch (SDPHeader->PDU)\r
{\r
while (ServicePatternLength)\r
{\r
uint8_t UUIDLength = ServiceDiscovery_GetDataElementSize(&CurrentParameter, &ElementHeaderSize);\r
- uint8_t UUID[16];\r
+ uint8_t UUID[16] = {BASE_96BIT_UUID, 0x00, 0x00, 0x00, 0x00};\r
+\r
+ if (UUIDLength <= 32)\r
+ memcpy(&UUID[sizeof(UUID) - sizeof(uint32_t)], CurrentParameter, UUIDLength);\r
+ else\r
+ memcpy(UUID, CurrentParameter, UUIDLength);\r
\r
- memset(UUID, 0x00, sizeof(UUID));\r
- memcpy(UUID, CurrentParameter, UUIDLength);\r
CurrentParameter += UUIDLength;\r
\r
- BT_SDP_DEBUG(2, "-- UUID (%d): 0x%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",\r
+ BT_SDP_DEBUG(2, "-- UUID (%d): 0x%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X",\r
UUIDLength,\r
UUID[15], UUID[14], UUID[13], UUID[12], UUID[11], UUID[10], UUID[9], UUID[8],\r
UUID[7], UUID[6], UUID[5], UUID[4], UUID[3], UUID[2], UUID[1], UUID[0]);\r
#define SDP_PDU_SERVICESEARCHATTRIBUTEREQUEST 0x06\r
#define SDP_PDU_SERVICESEARCHATTRIBUTERESPONSE 0x07\r
\r
+ #define SDP_ATTRIBUTE_NAME 0x0000\r
+ #define SDP_ATTRIBUTE_DESCRIPTION 0x0001\r
+ #define SDP_ATTRIBUTE_PROVIDER 0x0002\r
+ #define SDP_ATTRIBUTE_AVAILABILITY 0x0008\r
+ \r
+ #define SDP_DATATYPE_NIL (0x00 << 3)\r
+ #define SDP_DATATYPE_UNSIGNED_INT (0x01 << 3)\r
+ #define SDP_DATATYPE_SIGNED_INT (0x02 << 3)\r
+ #define SDP_DATATYPE_UUID (0x03 << 3)\r
+ #define SDP_DATATYPE_TEXT (0x04 << 3)\r
+ #define SDP_DATATYPE_BOOLEAN (0x05 << 3)\r
+ #define SDP_DATATYPE_ELEMENT_SEQUENCE (0x06 << 3)\r
+ #define SDP_DATATYPE_ELEMENT_ALTERNATIVE (0x07 << 3)\r
+ #define SDP_DATATYPE_URL (0x08 << 3)\r
+ \r
+ #define BASE_96BIT_UUID 0xFB, 0x34, 0x9B, 0x5F, 0x80, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00\r
+ \r
+ #define SERVICE_ATTRIBUTE_TEXT(name, string) SERVICE_ATTRIBUTE_8BIT_LEN(name, SDP_DATATYPE_TEXT, sizeof(string), string)\r
+ #define SERVICE_ATTRIBUTE_8BIT_LEN(name, type, size, ...) const ServiceAttributeData8Bit_t name PROGMEM = \\r
+ {.Header = (type | 5), .Size = size, .Data = __VA_ARGS__}\r
+ #define SERVICE_ATTRIBUTE_16BIT_LEN(name, type, size, ...) const ServiceAttributeData16Bit_t name PROGMEM = \\r
+ {.Header = (type | 5), .Size = size, .Data = __VA_ARGS__}\r
+ #define SERVICE_ATTRIBUTE_32BIT_LEN(name, type, size, ...) const ServiceAttributeData32Bit_t name PROGMEM = \\r
+ {.Header = (type | 5), .Size = size, .Data = __VA_ARGS__}\r
+ \r
/* Type Defines: */\r
typedef struct\r
{\r
uint16_t ParameterLength;\r
} SDP_PDUHeader_t;\r
\r
+ typedef struct\r
+ {\r
+ uint16_t AttributeID;\r
+ const void* AttributeData;\r
+ } ServiceAttributeTable_t;\r
+\r
+ typedef struct\r
+ {\r
+ uint8_t UUID[16];\r
+ const void* AttributeTable;\r
+ } ServiceTable_t;\r
+\r
+ typedef struct\r
+ {\r
+ uint8_t Header;\r
+ uint32_t Size;\r
+ uint8_t Data[];\r
+ } ServiceAttributeData32Bit_t;\r
+\r
+ typedef struct\r
+ {\r
+ uint8_t Header;\r
+ uint16_t Size;\r
+ uint8_t Data[];\r
+ } ServiceAttributeData16Bit_t;\r
+\r
+ typedef struct\r
+ {\r
+ uint8_t Header;\r
+ uint8_t Size;\r
+ uint8_t Data[];\r
+ } ServiceAttributeData8Bit_t;\r
+\r
+ typedef struct\r
+ {\r
+ uint8_t Header;\r
+ uint8_t Data[];\r
+ } ServiceAttributeData_t;\r
+ \r
/* Function Prototypes: */\r
void ServiceDiscovery_ProcessPacket(void* Data, Bluetooth_Channel_t* Channel);\r
\r