X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/c362709a1e2b0252cffbf1633f7cce41fea4d769..96063b9f98c8201623f8c91ec5cbe3bb88aca6c3:/Demos/Host/Incomplete/BluetoothHost/Lib/ServiceDiscoveryProtocol.c?ds=sidebyside diff --git a/Demos/Host/Incomplete/BluetoothHost/Lib/ServiceDiscoveryProtocol.c b/Demos/Host/Incomplete/BluetoothHost/Lib/ServiceDiscoveryProtocol.c index ffe2be0b7..5223d29b1 100644 --- a/Demos/Host/Incomplete/BluetoothHost/Lib/ServiceDiscoveryProtocol.c +++ b/Demos/Host/Incomplete/BluetoothHost/Lib/ServiceDiscoveryProtocol.c @@ -28,17 +28,35 @@ this software. */ +/** \file + * + * SDP layer module. This module implements a simple Service Discovery + * Protocol server, which can broadcast the device's supported services + * to other Bluetooth devices upon request, so that they can determine + * what services are available. + */ + +/* + TODO: Honor remote device's buffer size constraints via continuation state + */ + #define INCLUDE_FROM_SERVICEDISCOVERYPROTOCOL_C #include "ServiceDiscoveryProtocol.h" /** 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}; + +/** Initializes the SDP service, ready for new connections from a SDP client. */ +void SDP_Initialize(void) +{ + /* Not currently used */ +} /** 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 @@ -56,6 +74,7 @@ void SDP_ProcessPacket(void* Data, Bluetooth_Channel_t* const Channel) BT_SDP_DEBUG(2, "-- PDU ID: 0x%02X", SDPHeader->PDU); BT_SDP_DEBUG(2, "-- Param Length: 0x%04X", SDPHeader->ParameterLength); + /* Dispatch to the correct processing routine for the given SDP packet type */ switch (SDPHeader->PDU) { case SDP_PDU_SERVICESEARCHREQUEST: @@ -119,11 +138,10 @@ static void SDP_ProcessServiceSearch(const SDP_PDUHeader_t* const SDPHeader, Blu /* Copy over the service record handle to the response list */ uint8_t AttrHeaderSize; - SDP_GetLocalAttributeContainerSize(AttributeValue, &AttrHeaderSize); - memcpy_P(CurrResponsePos, AttributeValue + AttrHeaderSize, sizeof(uint32_t)); - CurrResponsePos += AttrHeaderSize + sizeof(uint32_t); + uint8_t AttrSize = SDP_GetLocalAttributeContainerSize(AttributeValue, &AttrHeaderSize); + memcpy_P(CurrResponsePos, AttributeValue + AttrHeaderSize, AttrSize); + CurrResponsePos += AttrHeaderSize + AttrSize; - /* Increment the total number of service records added to the list */ AddedServiceHandles++; } @@ -172,7 +190,7 @@ static void SDP_ProcessServiceAttribute(const SDP_PDUHeader_t* const SDPHeader, BT_SDP_DEBUG(2, "-- Max Return Attribute Bytes: 0x%04X", MaxAttributeSize); /* Retrieve the list of Attributes from the request */ - uint16_t AttributeList[15][2]; + uint16_t AttributeList[8][2]; uint8_t TotalAttributes = SDP_GetAttributeList(AttributeList, &CurrentParameter); BT_SDP_DEBUG(2, "-- Total Attributes: %d", TotalAttributes); @@ -263,7 +281,7 @@ static void SDP_ProcessServiceSearchAttribute(const SDP_PDUHeader_t* const SDPHe BT_SDP_DEBUG(2, "-- Max Return Attribute Bytes: 0x%04X", MaxAttributeSize); /* Retrieve the list of Attributes from the request */ - uint16_t AttributeList[15][2]; + uint16_t AttributeList[8][2]; uint8_t TotalAttributes = SDP_GetAttributeList(AttributeList, &CurrentParameter); BT_SDP_DEBUG(2, "-- Total Attributes: %d", TotalAttributes); @@ -487,6 +505,7 @@ 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++) { + /* Check if the current unmatched UUID is identical to the search UUID */ 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 +599,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;