From da51c1f9749842b65608d6505a41b05981416443 Mon Sep 17 00:00:00 2001 From: Dean Camera Date: Wed, 2 Jun 2010 04:36:46 +0000 Subject: [PATCH] Add L2CAP service attribute table. Fix up ProtocolDescriptorList attributes, and add macros for used UUIDs to reduce typing and make the code easier to read. --- .../BluetoothHost/Lib/SDPServices.c | 150 ++++++++++++++---- .../BluetoothHost/Lib/SDPServices.h | 14 +- .../Lib/ServiceDiscoveryProtocol.c | 11 +- 3 files changed, 138 insertions(+), 37 deletions(-) diff --git a/Demos/Host/Incomplete/BluetoothHost/Lib/SDPServices.c b/Demos/Host/Incomplete/BluetoothHost/Lib/SDPServices.c index 28b9d77746..96401c010d 100644 --- a/Demos/Host/Incomplete/BluetoothHost/Lib/SDPServices.c +++ b/Demos/Host/Incomplete/BluetoothHost/Lib/SDPServices.c @@ -30,6 +30,8 @@ #include "SDPServices.h" +/* ------------------------------ SDP SERVICE ATTRIBUTES ------------------------------ */ + const struct { uint8_t Header; @@ -50,25 +52,7 @@ const struct (SDP_DATATYPE_Sequence | SDP_DATASIZE_Variable16Bit), SWAPENDIAN_16(sizeof(ItemUUID_t) * 1), { - {(SDP_DATATYPE_UUID | SDP_DATASIZE_128Bit), {BASE_80BIT_UUID, {0x00, 0x00, 0x00, 0x00, 0x10, 0x00}}} - } - }; - -const struct -{ - uint8_t Header; - uint16_t Size; - ItemProtocol_t ProtocolList[]; -} PROGMEM SDP_Attribute_ProtocolDescriptor = - { - (SDP_DATATYPE_Sequence | SDP_DATASIZE_Variable16Bit), - SWAPENDIAN_16(sizeof(ItemProtocol_t) * 1), - { - { - (SDP_DATATYPE_Sequence | SDP_DATASIZE_Variable8Bit), - sizeof(UUID_t), - {(SDP_DATATYPE_UUID | SDP_DATASIZE_128Bit), {BASE_80BIT_UUID, {0x00, 0x00, 0x00, 0x00, 0x01, 0x00}}}, - } + {(SDP_DATATYPE_UUID | SDP_DATASIZE_128Bit), SDP_CLASS_UUID} } }; @@ -115,7 +99,6 @@ const ServiceAttributeTable_t SDP_Attribute_Table[] PROGMEM = { {.AttributeID = SDP_ATTRIBUTE_ID_SERVICERECORDHANDLE, .Data = &SDP_Attribute_ServiceHandle }, {.AttributeID = SDP_ATTRIBUTE_ID_SERVICECLASSIDS, .Data = &SDP_Attribute_ServiceClassIDs }, -// {.AttributeID = SDP_ATTRIBUTE_ID_PROTOCOLDESCRIPTORLIST, .Data = &SDP_Attribute_ProtocolDescriptor }, {.AttributeID = SDP_ATTRIBUTE_ID_VERSION, .Data = &SDP_Attribute_Version }, {.AttributeID = SDP_ATTRIBUTE_ID_SERVICENAME, .Data = &SDP_Attribute_ServiceName }, {.AttributeID = SDP_ATTRIBUTE_ID_SERVICEDESCRIPTION, .Data = &SDP_Attribute_ServiceDescription }, @@ -123,6 +106,10 @@ const ServiceAttributeTable_t SDP_Attribute_Table[] PROGMEM = SERVICE_ATTRIBUTE_TABLE_TERMINATOR }; + +/* ------------------------------ RFCOMM SERVICE ATTRIBUTES ------------------------------ */ + + const struct { uint8_t Header; @@ -143,21 +130,35 @@ const struct (SDP_DATATYPE_Sequence | SDP_DATASIZE_Variable16Bit), SWAPENDIAN_16(sizeof(ItemUUID_t) * 1), { - {(SDP_DATATYPE_UUID | SDP_DATASIZE_128Bit), {BASE_80BIT_UUID, {0x00, 0x00, 0x00, 0x00, 0x11, 0x01}}} + {(SDP_DATATYPE_UUID | SDP_DATASIZE_128Bit), SP_CLASS_UUID} } }; const struct { - uint8_t Header; - uint8_t Size; - Item16Bit_t OffsetList[]; -} PROGMEM RFCOMM_Attribute_LangOffset = + uint8_t Header; + uint16_t Size; + + ItemProtocol_t ProtocolList[]; +} PROGMEM RFCOMM_Attribute_ProtocolDescriptor = { - (SDP_DATATYPE_Sequence | SDP_DATASIZE_Variable8Bit), - (sizeof(Item16Bit_t) * 1), + (SDP_DATATYPE_Sequence | SDP_DATASIZE_Variable16Bit), + SWAPENDIAN_16(sizeof(ItemProtocol_t) * 2), { - {(SDP_DATATYPE_UnsignedInt | SDP_DATASIZE_16Bit), SWAPENDIAN_16(0x0100)} + { + (SDP_DATATYPE_Sequence | SDP_DATASIZE_Variable8Bit), + sizeof(UUID_t), + { + {(SDP_DATATYPE_UUID | SDP_DATASIZE_128Bit), L2CAP_UUID}, + } + }, + { + (SDP_DATATYPE_Sequence | SDP_DATASIZE_Variable8Bit), + sizeof(UUID_t), + { + {(SDP_DATATYPE_UUID | SDP_DATASIZE_128Bit), RFCOMM_UUID}, + } + } } }; @@ -189,8 +190,101 @@ const ServiceAttributeTable_t RFCOMM_Attribute_Table[] PROGMEM = { {.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_SERVICENAME, .Data = &RFCOMM_Attribute_ServiceName }, {.AttributeID = SDP_ATTRIBUTE_ID_SERVICEDESCRIPTION, .Data = &RFCOMM_Attribute_ServiceDescription }, SERVICE_ATTRIBUTE_TABLE_TERMINATOR }; + + +/* ------------------------------ L2CAP SERVICE ATTRIBUTES ------------------------------ */ + + +const struct +{ + uint8_t Header; + uint32_t Data; +} PROGMEM L2CAP_Attribute_ServiceHandle = + { + (SDP_DATATYPE_UnsignedInt | SDP_DATASIZE_32Bit), + SWAPENDIAN_32(0x00010002), + }; + +const struct +{ + uint8_t Header; + uint16_t Size; + ItemUUID_t UUIDList[]; +} PROGMEM L2CAP_Attribute_ServiceClassIDs = + { + (SDP_DATATYPE_Sequence | SDP_DATASIZE_Variable16Bit), + SWAPENDIAN_16(sizeof(ItemUUID_t) * 2), + { + {(SDP_DATATYPE_UUID | SDP_DATASIZE_128Bit), SDP_CLASS_UUID }, + {(SDP_DATATYPE_UUID | SDP_DATASIZE_128Bit), SP_CLASS_UUID }, + } + }; + +const struct +{ + uint8_t Header; + uint16_t Size; + + ItemProtocol_t ProtocolList[]; +} PROGMEM L2CAP_Attribute_ProtocolDescriptor = + { + (SDP_DATATYPE_Sequence | SDP_DATASIZE_Variable16Bit), + SWAPENDIAN_16(sizeof(ItemProtocol_t) * 2), + { + { + (SDP_DATATYPE_Sequence | SDP_DATASIZE_Variable8Bit), + sizeof(UUID_t), + { + {(SDP_DATATYPE_UUID | SDP_DATASIZE_128Bit), L2CAP_UUID}, + } + }, + { + (SDP_DATATYPE_Sequence | SDP_DATASIZE_Variable8Bit), + sizeof(UUID_t), + { + {(SDP_DATATYPE_UUID | SDP_DATASIZE_128Bit), RFCOMM_UUID}, + } + } + } + }; + +const struct +{ + uint8_t Header; + uint8_t Size; + char Text[]; +} PROGMEM L2CAP_Attribute_ServiceName = + { + (SDP_DATATYPE_String | SDP_DATASIZE_Variable8Bit), + sizeof("L2CAP") - 1, + "L2CAP", + }; + +const struct +{ + uint8_t Header; + uint8_t Size; + char Text[]; +} PROGMEM L2CAP_Attribute_ServiceDescription = + { + (SDP_DATATYPE_String | SDP_DATASIZE_Variable8Bit), + sizeof("Logical Link Layer") - 1, + "Logical Link Layer", + }; + +const ServiceAttributeTable_t L2CAP_Attribute_Table[] PROGMEM = + { + {.AttributeID = SDP_ATTRIBUTE_ID_SERVICERECORDHANDLE, .Data = &L2CAP_Attribute_ServiceHandle }, + {.AttributeID = SDP_ATTRIBUTE_ID_SERVICECLASSIDS, .Data = &L2CAP_Attribute_ServiceClassIDs }, + {.AttributeID = SDP_ATTRIBUTE_ID_PROTOCOLDESCRIPTORLIST, .Data = &L2CAP_Attribute_ProtocolDescriptor }, + {.AttributeID = SDP_ATTRIBUTE_ID_SERVICENAME, .Data = &L2CAP_Attribute_ServiceName }, + {.AttributeID = SDP_ATTRIBUTE_ID_SERVICEDESCRIPTION, .Data = &L2CAP_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 61fd593904..a11850dcbb 100644 --- a/Demos/Host/Incomplete/BluetoothHost/Lib/SDPServices.h +++ b/Demos/Host/Incomplete/BluetoothHost/Lib/SDPServices.h @@ -46,6 +46,14 @@ /** 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 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 UPNP_UUID {BASE_80BIT_UUID, {0x00, 0x00, 0x00, 0x00, 0x00, 0x10}} + #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 UPNP_CLASS_UUID {BASE_80BIT_UUID, {0x00, 0x00, 0x00, 0x00, 0x12, 0x00}} + #define SDP_ATTRIBUTE_ID_SERVICERECORDHANDLE 0x0000 #define SDP_ATTRIBUTE_ID_SERVICECLASSIDS 0x0001 #define SDP_ATTRIBUTE_ID_PROTOCOLDESCRIPTORLIST 0x0004 @@ -124,11 +132,15 @@ uint8_t Header; /**< Data Element header, should be (SDP_DATATYPE_Sequence | SDP_DATASIZE_Variable8Bit) */ uint8_t Size; /**< Size of the inner Data Element sequence */ - ItemUUID_t UUID; /**< UUID to store in the protocol list Data Element sequence */ + struct + { + ItemUUID_t UUID; /**< UUID to store in the protocol list Data Element sequence */ + } Protocol; } ItemProtocol_t; /* External Variables: */ extern const ServiceAttributeTable_t SDP_Attribute_Table[]; extern const ServiceAttributeTable_t RFCOMM_Attribute_Table[]; + extern const ServiceAttributeTable_t L2CAP_Attribute_Table[]; #endif diff --git a/Demos/Host/Incomplete/BluetoothHost/Lib/ServiceDiscoveryProtocol.c b/Demos/Host/Incomplete/BluetoothHost/Lib/ServiceDiscoveryProtocol.c index 6bb35f65de..c6b3948194 100644 --- a/Demos/Host/Incomplete/BluetoothHost/Lib/ServiceDiscoveryProtocol.c +++ b/Demos/Host/Incomplete/BluetoothHost/Lib/ServiceDiscoveryProtocol.c @@ -36,14 +36,9 @@ */ const ServiceTable_t SDP_Services_Table[] PROGMEM = { - { // 128-bit UUID for the SDP service - .UUID = {BASE_80BIT_UUID, {0x00, 0x00, 0x00, 0x00, 0x00, 0x01}}, - .AttributeTable = SDP_Attribute_Table, - }, - { // 128-bit UUID for the RFCOMM service - .UUID = {BASE_80BIT_UUID, {0x00, 0x00, 0x00, 0x00, 0x00, 0x03}}, - .AttributeTable = RFCOMM_Attribute_Table, - }, + { .UUID = SDP_UUID , .AttributeTable = SDP_Attribute_Table }, + { .UUID = RFCOMM_UUID, .AttributeTable = RFCOMM_Attribute_Table }, + { .UUID = L2CAP_UUID , .AttributeTable = L2CAP_Attribute_Table }, }; /** Base UUID value common to all standardized Bluetooth services */