From 3eb81df998349e90c3d973e6301f19382c5b2e84 Mon Sep 17 00:00:00 2001 From: Dean Camera Date: Thu, 15 Apr 2010 11:04:24 +0000 Subject: Rename FunctionAttributes.h to Attributes.h, as some attributes are applicable to variables also. Add new ATTR_NOINIT attribute for global variables. Add the beginnings of a SDP implentation to the incomplete BluetoothHost demo. Add const attribute to the Mass Storage Host driver functions where it was applicable, but missing. --- .../Host/Incomplete/BluetoothHost/BluetoothHost.c | 2 +- .../BluetoothHost/Lib/BluetoothACLPackets.c | 2 +- .../BluetoothHost/Lib/ServiceDiscoveryProtocol.c | 88 +++++++++++++++++++++- .../BluetoothHost/Lib/ServiceDiscoveryProtocol.h | 15 +++- 4 files changed, 102 insertions(+), 5 deletions(-) (limited to 'Demos') diff --git a/Demos/Host/Incomplete/BluetoothHost/BluetoothHost.c b/Demos/Host/Incomplete/BluetoothHost/BluetoothHost.c index df9f663e3..8dd5f91eb 100644 --- a/Demos/Host/Incomplete/BluetoothHost/BluetoothHost.c +++ b/Demos/Host/Incomplete/BluetoothHost/BluetoothHost.c @@ -251,7 +251,7 @@ void Bluetooth_PacketReceived(void* Data, uint16_t DataLen, Bluetooth_Channel_t* { case CHANNEL_PSM_SDP: /* Service Discovery Protocol packet */ - ServiceDiscovery_ProcessPacket(Data, DataLen, Channel); + ServiceDiscovery_ProcessPacket(Data, Channel); break; default: /* Unknown Protocol packet */ diff --git a/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothACLPackets.c b/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothACLPackets.c index d18e643b4..f96e10c37 100644 --- a/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothACLPackets.c +++ b/Demos/Host/Incomplete/BluetoothHost/Lib/BluetoothACLPackets.c @@ -694,7 +694,7 @@ static inline void Bluetooth_Signal_InformationReq(BT_Signal_Header_t* SignalCom struct { - BT_Signal_Header_t SignalCommandHeader; + BT_Signal_Header_t SignalCommandHeader; BT_Signal_InformationResp_t InformationResponse; uint8_t Data[4]; diff --git a/Demos/Host/Incomplete/BluetoothHost/Lib/ServiceDiscoveryProtocol.c b/Demos/Host/Incomplete/BluetoothHost/Lib/ServiceDiscoveryProtocol.c index 1ee4c842e..124b129a0 100644 --- a/Demos/Host/Incomplete/BluetoothHost/Lib/ServiceDiscoveryProtocol.c +++ b/Demos/Host/Incomplete/BluetoothHost/Lib/ServiceDiscoveryProtocol.c @@ -28,14 +28,98 @@ this software. */ +#define INCLUDE_FROM_SERVICEDISCOVERYPROTOCOL_C #include "ServiceDiscoveryProtocol.h" -void ServiceDiscovery_ProcessPacket(void* Data, uint16_t Length, Bluetooth_Channel_t* Channel) +void ServiceDiscovery_ProcessPacket(void* Data, Bluetooth_Channel_t* Channel) { SDP_PDUHeader_t* SDPHeader = (SDP_PDUHeader_t*)Data; SDPHeader->ParameterLength = SwapEndian_16(SDPHeader->ParameterLength); - BT_SDP_DEBUG(1, "<< Service Discovery Packet", NULL); + BT_SDP_DEBUG(1, "SDP Packet Received", NULL); BT_SDP_DEBUG(2, "-- PDU ID: 0x%02X", SDPHeader->PDU); BT_SDP_DEBUG(2, "-- Param Length: 0x%04X", SDPHeader->ParameterLength); + + switch (SDPHeader->PDU) + { + case SDP_PDU_SERVICESEARCHREQUEST: + ServiceDiscovery_ProcessServiceSearch(SDPHeader); + break; + case SDP_PDU_SERVICEATTRIBUTEREQUEST: + ServiceDiscovery_ProcessServiceAttribute(SDPHeader); + break; + case SDP_PDU_SERVICESEARCHATTRIBUTEREQUEST: + ServiceDiscovery_ProcessServiceSearchAttribute(SDPHeader); + break; + } +} + +static void ServiceDiscovery_ProcessServiceSearch(SDP_PDUHeader_t* SDPHeader) +{ + BT_SDP_DEBUG(1, "<< Service Search", NULL); +} + +static void ServiceDiscovery_ProcessServiceAttribute(SDP_PDUHeader_t* SDPHeader) +{ + BT_SDP_DEBUG(1, "<< Service Attribute", NULL); +} + +static void ServiceDiscovery_ProcessServiceSearchAttribute(SDP_PDUHeader_t* SDPHeader) +{ + uint8_t* CurrentParameter = ((uint8_t*)SDPHeader + sizeof(SDP_PDUHeader_t)); + + BT_SDP_DEBUG(1, "<< Service Search Attribute", NULL); + + uint8_t ServicePatternLength = ServiceDiscovery_GetDataElementSize(CurrentParameter); + while (ServicePatternLength) + { + uint8_t UUIDLength = ServiceDiscovery_GetDataElementSize(CurrentParameter); + uint8_t UUID[16]; + + memset(UUID, 0x00, sizeof(UUID)); + memcpy(&UUID[sizeof(UUID) - UUIDLength], CurrentParameter, UUIDLength); + + BT_SDP_DEBUG(2, "-- UUID: 0x%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X", + UUID[0], UUID[1], UUID[2], UUID[3], UUID[4], UUID[5], UUID[6], UUID[7], + UUID[8], UUID[9], UUID[10], UUID[11], UUID[12], UUID[13], UUID[14], UUID[15]); + + ServicePatternLength -= UUIDLength; + } + + uint16_t MaxAttributeSize = ServiceDiscovery_Read16BitParameter(CurrentParameter); + + uint8_t AttributeIDListLength = ServiceDiscovery_GetDataElementSize(CurrentParameter); + while (AttributeIDListLength) + { + uint8_t AttributeLength = ServiceDiscovery_GetDataElementSize(CurrentParameter); + + BT_SDP_DEBUG(2, "-- Attribute Length: 0x%04X", AttributeLength); + + AttributeIDListLength -= AttributeLength; + } +} + +static uint32_t ServiceDiscovery_GetDataElementSize(void* DataElementHeader) +{ + uint8_t SizeIndex = (*((uint8_t*)DataElementHeader++) & 0x07); + + switch (SizeIndex) + { + case 0: + return 1; + case 1: + return 2; + case 2: + return 4; + case 3: + return 8; + case 4: + return 16; + case 5: + return *((uint8_t*)DataElementHeader++); + case 6: + return *((uint16_t*)DataElementHeader++); + default: + return *((uint32_t*)DataElementHeader++); + } } diff --git a/Demos/Host/Incomplete/BluetoothHost/Lib/ServiceDiscoveryProtocol.h b/Demos/Host/Incomplete/BluetoothHost/Lib/ServiceDiscoveryProtocol.h index ed528e93f..b17cc2b1d 100644 --- a/Demos/Host/Incomplete/BluetoothHost/Lib/ServiceDiscoveryProtocol.h +++ b/Demos/Host/Incomplete/BluetoothHost/Lib/ServiceDiscoveryProtocol.h @@ -63,6 +63,19 @@ } SDP_PDUHeader_t; /* Function Prototypes: */ - void ServiceDiscovery_ProcessPacket(void* Data, uint16_t Length, Bluetooth_Channel_t* Channel); + void ServiceDiscovery_ProcessPacket(void* Data, Bluetooth_Channel_t* Channel); + + #if defined(INCLUDE_FROM_SERVICEDISCOVERYPROTOCOL_C) + static void ServiceDiscovery_ProcessServiceSearch(SDP_PDUHeader_t* SDPHeader); + static void ServiceDiscovery_ProcessServiceAttribute(SDP_PDUHeader_t* SDPHeader); + static void ServiceDiscovery_ProcessServiceSearchAttribute(SDP_PDUHeader_t* SDPHeader); + + static inline uint16_t ServiceDiscovery_Read16BitParameter(void* AttributeHeader) + { + return *((uint16_t*)AttributeHeader++); + } + + static uint32_t ServiceDiscovery_GetDataElementSize(void* AttributeHeader); + #endif #endif -- cgit v1.2.3