3 Copyright (C) Dean Camera, 2010.
5 dean [at] fourwalledcubicle [dot] com
6 www.fourwalledcubicle.com
10 Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com)
12 Permission to use, copy, modify, distribute, and sell this
13 software and its documentation for any purpose is hereby granted
14 without fee, provided that the above copyright notice appear in
15 all copies and that both that the copyright notice and this
16 permission notice and warranty disclaimer appear in supporting
17 documentation, and that the name of the author not be used in
18 advertising or publicity pertaining to distribution of the
19 software without specific, written prior permission.
21 The author disclaim all warranties with regard to this
22 software, including all implied warranties of merchantability
23 and fitness. In no event shall the author be liable for any
24 special, indirect or consequential damages or any damages
25 whatsoever resulting from loss of use, data or profits, whether
26 in an action of contract, negligence or other tortious action,
27 arising out of or in connection with the use or performance of
31 #ifndef _SERVICEDISCOVERYPROTOCOL_H_
32 #define _SERVICEDISCOVERYPROTOCOL_H_
40 #include <LUFA/Common/Common.h>
41 #include <LUFA/Drivers/Peripheral/SerialStream.h>
43 #include "BluetoothStack.h"
46 #define BT_SDP_DEBUG(l, s, ...) do { if (SDP_DEBUG_LEVEL >= l) printf_P(PSTR("(SDP) " s "\r\n"), ##__VA_ARGS__); } while (0)
47 #define SDP_DEBUG_LEVEL 2
49 #define SDP_PDU_ERRORRESPONSE 0x01
50 #define SDP_PDU_SERVICESEARCHREQUEST 0x02
51 #define SDP_PDU_SERVICESEARCHRESPONSE 0x03
52 #define SDP_PDU_SERVICEATTRIBUTEREQUEST 0x04
53 #define SDP_PDU_SERVICEATTRIBUTERESPONSE 0x05
54 #define SDP_PDU_SERVICESEARCHATTRIBUTEREQUEST 0x06
55 #define SDP_PDU_SERVICESEARCHATTRIBUTERESPONSE 0x07
57 #define SDP_ATTRIBUTE_NAME 0x0000
58 #define SDP_ATTRIBUTE_DESCRIPTION 0x0001
59 #define SDP_ATTRIBUTE_PROVIDER 0x0002
60 #define SDP_ATTRIBUTE_AVAILABILITY 0x0008
62 /** Size of a full 128 bit UUID, in bytes */
63 #define UUID_SIZE_BYTES 16
65 /** First 96 bits common to all standadized Bluetooth services */
66 #define BASE_96BIT_UUID 0xFB, 0x34, 0x9B, 0x5F, 0x80, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00
68 /** Defines a service attribute as a string of characters.
70 * \param name Name of the attribute (used to identify the attribute variable only)
71 * \param string String of characters to associate with the attribute
73 #define SERVICE_ATTRIBUTE_TEXT(name, string) SERVICE_ATTRIBUTE_LEN8(name, SDP_DATATYPE_String, sizeof(string), string)
75 /** Defines a service attribute with a contents that can fit into an 8-bit integer.
77 * \param name Name of the attribute (used to identify the attribute variable only)
78 * \param type Type of attribute contents, a value from the \ref ServiceDiscovery_DataTypes_t enum
79 * \param size Size of the data, in bytes
80 * \param ... Data to associate with the attribute
82 #define SERVICE_ATTRIBUTE_LEN8(name, type, size, ...) const ServiceAttributeData8Bit_t name PROGMEM = \
83 {.Header = (type | 5), .Size = size, .Data = __VA_ARGS__}
85 /** Defines a service attribute with a contents that can fit into an 16-bit integer.
87 * \param name Name of the attribute (used to identify the attribute variable only)
88 * \param type Type of attribute contents, a value from the \ref ServiceDiscovery_DataTypes_t enum
89 * \param size Size of the data, in bytes
90 * \param ... Data to associate with the attribute
92 #define SERVICE_ATTRIBUTE_LEN16(name, type, size, ...) const ServiceAttributeData16Bit_t name PROGMEM = \
93 {.Header = (type | 6), .Size = size, .Data = __VA_ARGS__}
95 /** Defines a service attribute with a contents that can fit into an 32-bit integer.
97 * \param name Name of the attribute (used to identify the attribute variable only)
98 * \param type Type of attribute contents, a value from the \ref ServiceDiscovery_DataTypes_t enum
99 * \param size Size of the data, in bytes
100 * \param ... Data to associate with the attribute
102 #define SERVICE_ATTRIBUTE_LEN32(name, type, size, ...) const ServiceAttributeData32Bit_t name PROGMEM = \
103 {.Header = (type | 7), .Size = size, .Data = __VA_ARGS__}
105 /** Terminator for a service attribute table of type \ref ServiceAttributeTable_t. */
106 #define SERVICE_ATTRIBUTE_TABLE_TERMINATOR {.Data = NULL}
109 enum ServiceDiscovery_DataTypes_t
111 SDP_DATATYPE_Nill
= (0 << 3),
112 SDP_DATATYPE_UnsignedInt
= (1 << 3),
113 SDP_DATATYPE_SignedInt
= (2 << 3),
114 SDP_DATATYPE_UUID
= (3 << 3),
115 SDP_DATATYPE_String
= (4 << 3),
116 SDP_DATATYPE_Boolean
= (5 << 3),
117 SDP_DATATYPE_Sequence
= (6 << 3),
118 SDP_DATATYPE_Alternative
= (7 << 3),
119 SDP_DATATYPE_URL
= (8 << 3),
126 uint16_t TransactionID
;
127 uint16_t ParameterLength
;
132 uint16_t AttributeID
;
134 } ServiceAttributeTable_t
;
139 const void* AttributeTable
;
147 } ServiceAttributeData32Bit_t
;
154 } ServiceAttributeData16Bit_t
;
161 } ServiceAttributeData8Bit_t
;
167 } ServiceAttributeData_t
;
169 /* Inline Functions: */
170 static inline uint16_t* ServiceDiscovery_AddDataElementHeader(uint8_t** BufferPos
, const uint8_t Type
)
172 **BufferPos
= (6 | Type
);
175 uint16_t* SizePos
= (uint16_t*)*BufferPos
;
183 static inline uint16_t ServiceDiscovery_Read16BitParameter(const void** AttributeHeader
)
185 uint16_t ParamValue
= *((uint16_t*)*AttributeHeader
);
186 *AttributeHeader
+= sizeof(uint16_t);
190 /* Function Prototypes: */
191 void ServiceDiscovery_ProcessPacket(void* Data
, Bluetooth_Channel_t
* Channel
);
193 #if defined(INCLUDE_FROM_SERVICEDISCOVERYPROTOCOL_C)
194 static void ServiceDiscovery_ProcessServiceSearch(SDP_PDUHeader_t
* SDPHeader
, Bluetooth_Channel_t
* Channel
);
195 static void ServiceDiscovery_ProcessServiceAttribute(SDP_PDUHeader_t
* SDPHeader
, Bluetooth_Channel_t
* Channel
);
196 static void ServiceDiscovery_ProcessServiceSearchAttribute(SDP_PDUHeader_t
* SDPHeader
, Bluetooth_Channel_t
* Channel
);
198 static void* ServiceDiscovery_GetAttributeValue(ServiceAttributeTable_t
* AttributeTable
, uint16_t AttributeID
);
199 static ServiceAttributeTable_t
* ServiceDiscovery_GetAttributeTable(uint8_t* UUID
);
200 static uint8_t ServiceDiscovery_GetAttributeList(uint16_t AttributeList
[][2], const void** CurrentParameter
);
201 static uint8_t ServiceDiscovery_GetUUIDList(uint8_t UUIDList
[][UUID_SIZE_BYTES
], const void** CurrentParameter
);
202 static uint32_t ServiceDiscovery_GetDataElementSize(const void** AttributeHeader
, uint8_t* ElementHeaderSize
);