aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDean Camera <dean@fourwalledcubicle.com>2010-06-02 14:49:06 +0000
committerDean Camera <dean@fourwalledcubicle.com>2010-06-02 14:49:06 +0000
commit23a94a7181a0773431b3ea5dbcddab9e06010391 (patch)
tree916a61f17a3a1f67278dbbe4d1bfe29571f6e247
parentc362709a1e2b0252cffbf1633f7cce41fea4d769 (diff)
downloadlufa-23a94a7181a0773431b3ea5dbcddab9e06010391.tar.gz
lufa-23a94a7181a0773431b3ea5dbcddab9e06010391.tar.bz2
lufa-23a94a7181a0773431b3ea5dbcddab9e06010391.zip
Fix byte ordering of UUIDs in the SDP server - host can now successfully pair to the Bluetooth device and discover the exposed Serial Port Profile RFCOMM service.
-rw-r--r--Demos/Host/Incomplete/BluetoothHost/Lib/SDPServices.c48
-rw-r--r--Demos/Host/Incomplete/BluetoothHost/Lib/SDPServices.h58
-rw-r--r--Demos/Host/Incomplete/BluetoothHost/Lib/ServiceDiscoveryProtocol.c37
-rw-r--r--Demos/Host/Incomplete/BluetoothHost/Lib/ServiceDiscoveryProtocol.h2
-rw-r--r--LUFA/Common/Common.h2
5 files changed, 92 insertions, 55 deletions
diff --git a/Demos/Host/Incomplete/BluetoothHost/Lib/SDPServices.c b/Demos/Host/Incomplete/BluetoothHost/Lib/SDPServices.c
index 511e0b074..908be0c6d 100644
--- a/Demos/Host/Incomplete/BluetoothHost/Lib/SDPServices.c
+++ b/Demos/Host/Incomplete/BluetoothHost/Lib/SDPServices.c
@@ -34,7 +34,7 @@ const struct
{
uint8_t Header;
uint32_t Data;
-} PROGMEM RFCOMM_Attribute_ServiceHandle =
+} PROGMEM SerialPort_Attribute_ServiceHandle =
{
(SDP_DATATYPE_UnsignedInt | SDP_DATASIZE_32Bit),
SWAPENDIAN_32(0x00010001),
@@ -45,7 +45,7 @@ const struct
uint8_t Header;
uint16_t Size;
ItemUUID_t UUIDList[];
-} PROGMEM RFCOMM_Attribute_ServiceClassIDs =
+} PROGMEM SerialPort_Attribute_ServiceClassIDs =
{
(SDP_DATATYPE_Sequence | SDP_DATASIZE_Variable16Bit),
SWAPENDIAN_16(sizeof(ItemUUID_t) * 1),
@@ -56,11 +56,11 @@ const struct
const struct
{
- uint8_t Header;
- uint16_t Size;
+ uint8_t Header;
+ uint16_t Size;
ItemProtocol_t ProtocolList[];
-} PROGMEM RFCOMM_Attribute_ProtocolDescriptor =
+} PROGMEM SerialPort_Attribute_ProtocolDescriptor =
{
(SDP_DATATYPE_Sequence | SDP_DATASIZE_Variable16Bit),
SWAPENDIAN_16(sizeof(ItemProtocol_t) * 2),
@@ -87,7 +87,7 @@ const struct
uint8_t Header;
uint16_t Size;
ItemUUID_t UUIDList[];
-} PROGMEM RFCOMM_Attribute_BrowseGroupList =
+} PROGMEM SerialPort_Attribute_BrowseGroupList =
{
(SDP_DATATYPE_Sequence | SDP_DATASIZE_Variable16Bit),
SWAPENDIAN_16(sizeof(ItemUUID_t) * 1),
@@ -98,14 +98,14 @@ const struct
const struct
{
- uint8_t Header;
- uint8_t Size;
- ItemLangID_t OffsetList[];
-} PROGMEM RFCOMM_Attribute_LanguageBaseIDOffset =
+ uint8_t Header;
+ uint8_t Size;
+ ItemLangEncoding_t LanguageEncodings[];
+} PROGMEM SerialPort_Attribute_LanguageBaseIDOffset =
{
.Header = (SDP_DATATYPE_Sequence | SDP_DATASIZE_Variable8Bit),
- .Size = (sizeof(ItemLangID_t) * 1),
- .OffsetList =
+ .Size = (sizeof(ItemLangEncoding_t) * 1),
+ .LanguageEncodings =
{
{
{(SDP_DATATYPE_UnsignedInt | SDP_DATASIZE_16Bit), SWAPENDIAN_16(0x454E)},
@@ -120,11 +120,11 @@ const struct
uint8_t Header;
uint8_t Size;
char Text[];
-} PROGMEM RFCOMM_Attribute_ServiceName =
+} PROGMEM SerialPort_Attribute_ServiceName =
{
(SDP_DATATYPE_String | SDP_DATASIZE_Variable8Bit),
- sizeof("Serial Port") - 1,
- "Serial Port",
+ sizeof("Wireless Serial Port") - 1,
+ "Wireless Serial Port",
};
const struct
@@ -132,22 +132,22 @@ const struct
uint8_t Header;
uint8_t Size;
char Text[];
-} PROGMEM RFCOMM_Attribute_ServiceDescription =
+} PROGMEM SerialPort_Attribute_ServiceDescription =
{
(SDP_DATATYPE_String | SDP_DATASIZE_Variable8Bit),
sizeof("Wireless Serial Port Service") - 1,
"Wireless Serial Port Service",
};
-const ServiceAttributeTable_t PROGMEM RFCOMM_Attribute_Table[] =
+const ServiceAttributeTable_t PROGMEM SerialPort_Attribute_Table[] =
{
- {.AttributeID = SDP_ATTRIBUTE_ID_SERVICERECORDHANDLE, .Data = &RFCOMM_Attribute_ServiceHandle },
- {.AttributeID = SDP_ATTRIBUTE_ID_SERVICECLASSIDS, .Data = &RFCOMM_Attribute_ServiceClassIDs },
- {.AttributeID = SDP_ATTRIBUTE_ID_PROTOCOLDESCRIPTORLIST, .Data = &RFCOMM_Attribute_ProtocolDescriptor },
- {.AttributeID = SDP_ATTRIBUTE_ID_BROWSEGROUPLIST, .Data = &RFCOMM_Attribute_BrowseGroupList },
- {.AttributeID = SDP_ATTRIBUTE_ID_LANGUAGEBASEATTROFFSET, .Data = &RFCOMM_Attribute_LanguageBaseIDOffset},
- {.AttributeID = SDP_ATTRIBUTE_ID_SERVICENAME, .Data = &RFCOMM_Attribute_ServiceName },
- {.AttributeID = SDP_ATTRIBUTE_ID_SERVICEDESCRIPTION, .Data = &RFCOMM_Attribute_ServiceDescription },
+ {.AttributeID = SDP_ATTRIBUTE_ID_SERVICERECORDHANDLE, .Data = &SerialPort_Attribute_ServiceHandle },
+ {.AttributeID = SDP_ATTRIBUTE_ID_SERVICECLASSIDS, .Data = &SerialPort_Attribute_ServiceClassIDs },
+ {.AttributeID = SDP_ATTRIBUTE_ID_PROTOCOLDESCRIPTORLIST, .Data = &SerialPort_Attribute_ProtocolDescriptor },
+ {.AttributeID = SDP_ATTRIBUTE_ID_BROWSEGROUPLIST, .Data = &SerialPort_Attribute_BrowseGroupList },
+ {.AttributeID = SDP_ATTRIBUTE_ID_LANGUAGEBASEATTROFFSET, .Data = &SerialPort_Attribute_LanguageBaseIDOffset},
+ {.AttributeID = SDP_ATTRIBUTE_ID_SERVICENAME, .Data = &SerialPort_Attribute_ServiceName },
+ {.AttributeID = SDP_ATTRIBUTE_ID_SERVICEDESCRIPTION, .Data = &SerialPort_Attribute_ServiceDescription },
SERVICE_ATTRIBUTE_TABLE_TERMINATOR
};
diff --git a/Demos/Host/Incomplete/BluetoothHost/Lib/SDPServices.h b/Demos/Host/Incomplete/BluetoothHost/Lib/SDPServices.h
index 654ed94e0..738cc063d 100644
--- a/Demos/Host/Incomplete/BluetoothHost/Lib/SDPServices.h
+++ b/Demos/Host/Incomplete/BluetoothHost/Lib/SDPServices.h
@@ -44,43 +44,58 @@
#define UUID_SIZE_BYTES 16
/** First 80 bits common to all standardized Bluetooth services. */
- #define BASE_80BIT_UUID SWAPENDIAN_32(0xFB349B5F), SWAPENDIAN_16(0x8000), SWAPENDIAN_16(0x0080), SWAPENDIAN_16(0x0010)
+ #define BASE_80BIT_UUID 0x0000, 0x0010, 0x0080, {0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB}
- #define SDP_UUID {BASE_80BIT_UUID, {0x00, 0x00, 0x00, 0x00, 0x00, 0x01}}
- #define RFCOMM_UUID {BASE_80BIT_UUID, {0x00, 0x00, 0x00, 0x00, 0x00, 0x03}}
- #define L2CAP_UUID {BASE_80BIT_UUID, {0x00, 0x00, 0x00, 0x00, 0x01, 0x00}}
- #define SDP_CLASS_UUID {BASE_80BIT_UUID, {0x00, 0x00, 0x00, 0x00, 0x10, 0x00}}
- #define SP_CLASS_UUID {BASE_80BIT_UUID, {0x00, 0x00, 0x00, 0x00, 0x11, 0x01}}
- #define PUBLICBROWSEGROUP_CLASS_UUID {BASE_80BIT_UUID, {0x00, 0x00, 0x00, 0x00, 0x10, 0x02}}
+ #define RFCOMM_UUID {SWAPENDIAN_32(0x00000003), BASE_80BIT_UUID}
+ #define L2CAP_UUID {SWAPENDIAN_32(0x00000100), BASE_80BIT_UUID}
+ #define SP_CLASS_UUID {SWAPENDIAN_32(0x00001101), BASE_80BIT_UUID}
+ #define PUBLICBROWSEGROUP_CLASS_UUID {SWAPENDIAN_32(0x00001002), BASE_80BIT_UUID}
#define SDP_ATTRIBUTE_ID_SERVICERECORDHANDLE 0x0000
#define SDP_ATTRIBUTE_ID_SERVICECLASSIDS 0x0001
#define SDP_ATTRIBUTE_ID_PROTOCOLDESCRIPTORLIST 0x0004
#define SDP_ATTRIBUTE_ID_BROWSEGROUPLIST 0x0005
#define SDP_ATTRIBUTE_ID_LANGUAGEBASEATTROFFSET 0x0006
- #define SDP_ATTRIBUTE_ID_VERSION 0x0200
#define SDP_ATTRIBUTE_ID_SERVICENAME 0x0100
#define SDP_ATTRIBUTE_ID_SERVICEDESCRIPTION 0x0101
+ /** Swaps the byte ordering of a 16-bit value at compile time. Do not use this macro for swapping byte orderings
+ * of dynamic values computed at runtime -- use SwapEndian_16() instead.
+ *
+ * \param[in] x 16-bit value whose byte ordering is to be swapped
+ *
+ * \return Input value with the byte ordering reversed
+ */
#define SWAPENDIAN_16(x) ((((x) & 0xFF00) >> 8) | (((x) & 0x00FF) << 8))
- #define SWAPENDIAN_32(x) ((((x) & 0xFF000000) >> 24) | (((x) & 0x00FF0000) >> 8) | \
- (((x) & 0x0000FF00) << 8) | (((x) & 0x000000FF) << 24))
+
+ /** Swaps the byte ordering of a 32-bit value at compile time. Do not use this macro for swapping byte orderings
+ * of dynamic values computed at runtime -- use SwapEndian_32() instead.
+ *
+ * \param[in] x 32-bit value whose byte ordering is to be swapped
+ *
+ * \return Input value with the byte ordering reversed
+ */
+ #define SWAPENDIAN_32(x) ((((x) & 0xFF000000UL) >> 24UL) | (((x) & 0x00FF0000UL) >> 8UL) | \
+ (((x) & 0x0000FF00UL) << 8UL) | (((x) & 0x000000FFUL) << 24UL))
/** Terminator for a service attribute table of type \ref ServiceAttributeTable_t. */
#define SERVICE_ATTRIBUTE_TABLE_TERMINATOR {.Data = NULL}
/* Type Defines: */
+ /** Type define for a UUID value structure. This struct can be used to hold full 128-bit UUIDs. */
typedef struct
{
- uint32_t A;
- uint16_t B;
- uint16_t C;
- uint16_t D;
- uint8_t E[6];
+ uint32_t A; /**< Bits 0-31 of the UUID. */
+ uint16_t B; /**< Bits 32-47 of the UUID. */
+ uint16_t C; /**< Bits 48-63 of the UUID. */
+ uint16_t D; /**< Bits 64-79 of the UUID. */
+ uint8_t E[6]; /**< Bits 80-128 of the UUID. */
} UUID_t;
/** Structure for the association of attribute ID values to an attribute value in FLASH. A table of these
* structures can then be built up for each supported UUID service within the device.
+ *
+ * \note This table must be terminated with a \ref SERVICE_ATTRIBUTE_TABLE_TERMINATOR element.
*/
typedef struct
{
@@ -130,14 +145,17 @@
} Protocol;
} ItemProtocol_t;
+ /** Structure for a list of Data Elements containing language encodings, including the language ID, Encoding ID and
+ * Attribute base offset.
+ */
typedef struct
{
- Item16Bit_t LanguageID;
- Item16Bit_t EncodingID;
- Item16Bit_t OffsetID;
- } ItemLangID_t;
+ Item16Bit_t LanguageID; /**< Language ID for the current language */
+ Item16Bit_t EncodingID; /**< Encoding used for the current language */
+ Item16Bit_t OffsetID; /**< Attribute offset added to all strings using this language within the service */
+ } ItemLangEncoding_t;
/* External Variables: */
- extern const ServiceAttributeTable_t RFCOMM_Attribute_Table[];
+ extern const ServiceAttributeTable_t SerialPort_Attribute_Table[];
#endif
diff --git a/Demos/Host/Incomplete/BluetoothHost/Lib/ServiceDiscoveryProtocol.c b/Demos/Host/Incomplete/BluetoothHost/Lib/ServiceDiscoveryProtocol.c
index ffe2be0b7..df0db3bed 100644
--- a/Demos/Host/Incomplete/BluetoothHost/Lib/ServiceDiscoveryProtocol.c
+++ b/Demos/Host/Incomplete/BluetoothHost/Lib/ServiceDiscoveryProtocol.c
@@ -34,11 +34,11 @@
/** Service attribute table list, containing a pointer to each service attribute table the device contains */
const ServiceAttributeTable_t* SDP_Services_Table[] PROGMEM =
{
- RFCOMM_Attribute_Table,
+ SerialPort_Attribute_Table,
};
/** Base UUID value common to all standardized Bluetooth services */
-const UUID_t BaseUUID PROGMEM = {BASE_80BIT_UUID, {0, 0, 0, 0, 0, 0}};
+const UUID_t BaseUUID PROGMEM = {0x00000000, BASE_80BIT_UUID};
/** Main Service Discovery Protocol packet processing routine. This function processes incomming SDP packets from
* a connected Bluetooth device, and sends back appropriate responses to allow other devices to determine the
@@ -487,6 +487,16 @@ static void SDP_CheckUUIDMatch(uint8_t UUIDList[][UUID_SIZE_BYTES], const uint8_
/* Look for matches in the UUID list against the current attribute UUID value */
for (uint8_t i = 0; i < TotalUUIDs; i++)
{
+ uint8_t CurrentUUID[16];
+ memcpy_P(CurrentUUID, (CurrAttribute + 1), 16);
+
+ BT_SDP_DEBUG(2, "-- TEST UUID: %02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X",
+ CurrentUUID[0], CurrentUUID[1], CurrentUUID[2], CurrentUUID[3],
+ CurrentUUID[4], CurrentUUID[5],
+ CurrentUUID[6], CurrentUUID[7],
+ CurrentUUID[8], CurrentUUID[9],
+ CurrentUUID[10], CurrentUUID[11], CurrentUUID[12], CurrentUUID[13], CurrentUUID[14], CurrentUUID[15]);
+
if (!(UUIDMatch[i]) && !(memcmp_P(UUIDList[i], (CurrAttribute + 1), UUID_SIZE_BYTES)))
{
/* Indicate match found for the current attribute UUID and early-abort */
@@ -580,19 +590,28 @@ static uint8_t SDP_GetUUIDList(uint8_t UUIDList[][UUID_SIZE_BYTES], const void**
uint8_t* CurrentUUID = UUIDList[TotalUUIDs++];
uint8_t UUIDLength = SDP_GetDataElementSize(CurrentParameter, &ElementHeaderSize);
- /* Copy over the base UUID value to the free UUID slot in the list */
- memcpy_P(CurrentUUID, &BaseUUID, sizeof(BaseUUID));
-
/* Copy over UUID from the container to the free slot */
- memcpy(&CurrentUUID[UUID_SIZE_BYTES - UUIDLength], *CurrentParameter, UUIDLength);
+ if (UUIDLength <= 4)
+ {
+ /* Copy over the base UUID value to the free UUID slot in the list */
+ memcpy_P(CurrentUUID, &BaseUUID, sizeof(BaseUUID));
+
+ /* Copy over short UUID */
+ memcpy(CurrentUUID + (4 - UUIDLength), *CurrentParameter, UUIDLength);
+ }
+ else
+ {
+ /* Copy over full UUID */
+ memcpy(CurrentUUID, *CurrentParameter, UUIDLength);
+ }
BT_SDP_DEBUG(2, "-- UUID (%d): %02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X",
UUIDLength,
CurrentUUID[0], CurrentUUID[1], CurrentUUID[2], CurrentUUID[3],
CurrentUUID[4], CurrentUUID[5],
- CurrentUUID[6], CurrentUUID[7],
- CurrentUUID[8], CurrentUUID[9],
- CurrentUUID[10], CurrentUUID[11], CurrentUUID[12], CurrentUUID[13], CurrentUUID[14], CurrentUUID[15]);
+ CurrentUUID[6], CurrentUUID[7],
+ CurrentUUID[8], CurrentUUID[9],
+ CurrentUUID[10], CurrentUUID[11], CurrentUUID[12], CurrentUUID[13], CurrentUUID[14], CurrentUUID[15]);
ServicePatternLength -= (UUIDLength + ElementHeaderSize);
*CurrentParameter += UUIDLength;
diff --git a/Demos/Host/Incomplete/BluetoothHost/Lib/ServiceDiscoveryProtocol.h b/Demos/Host/Incomplete/BluetoothHost/Lib/ServiceDiscoveryProtocol.h
index 50f436642..e46729cd9 100644
--- a/Demos/Host/Incomplete/BluetoothHost/Lib/ServiceDiscoveryProtocol.h
+++ b/Demos/Host/Incomplete/BluetoothHost/Lib/ServiceDiscoveryProtocol.h
@@ -50,7 +50,7 @@
/* Macros: */
#define BT_SDP_DEBUG(l, s, ...) do { if (SDP_DEBUG_LEVEL >= l) printf_P(PSTR("(SDP) " s "\r\n"), ##__VA_ARGS__); } while (0)
- #define SDP_DEBUG_LEVEL 1
+ #define SDP_DEBUG_LEVEL 0
#define SDP_PDU_ERRORRESPONSE 0x01
#define SDP_PDU_SERVICESEARCHREQUEST 0x02
diff --git a/LUFA/Common/Common.h b/LUFA/Common/Common.h
index 14473cddc..76307d7e9 100644
--- a/LUFA/Common/Common.h
+++ b/LUFA/Common/Common.h
@@ -111,7 +111,7 @@
"Assertion \"%s\" failed.\r\n"), \
__FILE__, __func__, __LINE__, #x); } \
}MACROE
-
+
/* Inline Functions: */
/** Function to reverse the individual bits in a byte - i.e. bit 7 is moved to bit 0, bit 6 to bit 1,
* etc.