Line data Source code
1 1 : /** @file
2 : * @brief Service Discovery Protocol handling.
3 : */
4 :
5 : /*
6 : * Copyright (c) 2016 Intel Corporation
7 : *
8 : * SPDX-License-Identifier: Apache-2.0
9 : */
10 : #ifndef ZEPHYR_INCLUDE_BLUETOOTH_SDP_H_
11 : #define ZEPHYR_INCLUDE_BLUETOOTH_SDP_H_
12 :
13 : /**
14 : * @file
15 : * @brief Service Discovery Protocol (SDP)
16 : * @defgroup bt_sdp Service Discovery Protocol (SDP)
17 : * @ingroup bluetooth
18 : * @{
19 : */
20 :
21 : #include <zephyr/bluetooth/uuid.h>
22 : #include <zephyr/bluetooth/conn.h>
23 :
24 : #ifdef __cplusplus
25 : extern "C" {
26 : #endif
27 :
28 : /*
29 : * All definitions are based on Bluetooth Assigned Numbers
30 : * of the Bluetooth Specification
31 : */
32 :
33 : /**
34 : * @name Service class identifiers of standard services and service groups
35 : * @{
36 : */
37 1 : #define BT_SDP_SDP_SERVER_SVCLASS 0x1000 /**< Service Discovery Server */
38 1 : #define BT_SDP_BROWSE_GRP_DESC_SVCLASS 0x1001 /**< Browse Group Descriptor */
39 1 : #define BT_SDP_PUBLIC_BROWSE_GROUP 0x1002 /**< Public Browse Group */
40 1 : #define BT_SDP_SERIAL_PORT_SVCLASS 0x1101 /**< Serial Port */
41 1 : #define BT_SDP_LAN_ACCESS_SVCLASS 0x1102 /**< LAN Access Using PPP */
42 1 : #define BT_SDP_DIALUP_NET_SVCLASS 0x1103 /**< Dialup Networking */
43 1 : #define BT_SDP_IRMC_SYNC_SVCLASS 0x1104 /**< IrMC Sync */
44 1 : #define BT_SDP_OBEX_OBJPUSH_SVCLASS 0x1105 /**< OBEX Object Push */
45 1 : #define BT_SDP_OBEX_FILETRANS_SVCLASS 0x1106 /**< OBEX File Transfer */
46 1 : #define BT_SDP_IRMC_SYNC_CMD_SVCLASS 0x1107 /**< IrMC Sync Command */
47 1 : #define BT_SDP_HEADSET_SVCLASS 0x1108 /**< Headset */
48 1 : #define BT_SDP_CORDLESS_TELEPHONY_SVCLASS 0x1109 /**< Cordless Telephony */
49 1 : #define BT_SDP_AUDIO_SOURCE_SVCLASS 0x110a /**< Audio Source */
50 1 : #define BT_SDP_AUDIO_SINK_SVCLASS 0x110b /**< Audio Sink */
51 1 : #define BT_SDP_AV_REMOTE_TARGET_SVCLASS 0x110c /**< A/V Remote Control Target */
52 1 : #define BT_SDP_ADVANCED_AUDIO_SVCLASS 0x110d /**< Advanced Audio Distribution */
53 1 : #define BT_SDP_AV_REMOTE_SVCLASS 0x110e /**< A/V Remote Control */
54 1 : #define BT_SDP_AV_REMOTE_CONTROLLER_SVCLASS 0x110f /**< A/V Remote Control Controller */
55 1 : #define BT_SDP_INTERCOM_SVCLASS 0x1110 /**< Intercom */
56 1 : #define BT_SDP_FAX_SVCLASS 0x1111 /**< Fax */
57 1 : #define BT_SDP_HEADSET_AGW_SVCLASS 0x1112 /**< Headset AG */
58 1 : #define BT_SDP_WAP_SVCLASS 0x1113 /**< WAP */
59 1 : #define BT_SDP_WAP_CLIENT_SVCLASS 0x1114 /**< WAP Client */
60 1 : #define BT_SDP_PANU_SVCLASS 0x1115 /**< Personal Area Networking User */
61 1 : #define BT_SDP_NAP_SVCLASS 0x1116 /**< Network Access Point */
62 1 : #define BT_SDP_GN_SVCLASS 0x1117 /**< Group Network */
63 1 : #define BT_SDP_DIRECT_PRINTING_SVCLASS 0x1118 /**< Direct Printing */
64 1 : #define BT_SDP_REFERENCE_PRINTING_SVCLASS 0x1119 /**< Reference Printing */
65 1 : #define BT_SDP_IMAGING_SVCLASS 0x111a /**< Basic Imaging Profile */
66 1 : #define BT_SDP_IMAGING_RESPONDER_SVCLASS 0x111b /**< Imaging Responder */
67 1 : #define BT_SDP_IMAGING_ARCHIVE_SVCLASS 0x111c /**< Imaging Automatic Archive */
68 1 : #define BT_SDP_IMAGING_REFOBJS_SVCLASS 0x111d /**< Imaging Referenced Objects */
69 1 : #define BT_SDP_HANDSFREE_SVCLASS 0x111e /**< Handsfree */
70 1 : #define BT_SDP_HANDSFREE_AGW_SVCLASS 0x111f /**< Handsfree Audio Gateway */
71 1 : #define BT_SDP_DIRECT_PRT_REFOBJS_SVCLASS 0x1120 /**< Direct Printing Reference Objects Service */
72 1 : #define BT_SDP_REFLECTED_UI_SVCLASS 0x1121 /**< Reflected UI */
73 1 : #define BT_SDP_BASIC_PRINTING_SVCLASS 0x1122 /**< Basic Printing */
74 1 : #define BT_SDP_PRINTING_STATUS_SVCLASS 0x1123 /**< Printing Status */
75 1 : #define BT_SDP_HID_SVCLASS 0x1124 /**< Human Interface Device Service */
76 1 : #define BT_SDP_HCR_SVCLASS 0x1125 /**< Hardcopy Cable Replacement */
77 1 : #define BT_SDP_HCR_PRINT_SVCLASS 0x1126 /**< HCR Print */
78 1 : #define BT_SDP_HCR_SCAN_SVCLASS 0x1127 /**< HCR Scan */
79 1 : #define BT_SDP_CIP_SVCLASS 0x1128 /**< Common ISDN Access */
80 1 : #define BT_SDP_VIDEO_CONF_GW_SVCLASS 0x1129 /**< Video Conferencing Gateway */
81 1 : #define BT_SDP_UDI_MT_SVCLASS 0x112a /**< UDI MT */
82 1 : #define BT_SDP_UDI_TA_SVCLASS 0x112b /**< UDI TA */
83 1 : #define BT_SDP_AV_SVCLASS 0x112c /**< Audio/Video */
84 1 : #define BT_SDP_SAP_SVCLASS 0x112d /**< SIM Access */
85 1 : #define BT_SDP_PBAP_PCE_SVCLASS 0x112e /**< Phonebook Access Client */
86 1 : #define BT_SDP_PBAP_PSE_SVCLASS 0x112f /**< Phonebook Access Server */
87 1 : #define BT_SDP_PBAP_SVCLASS 0x1130 /**< Phonebook Access */
88 1 : #define BT_SDP_MAP_MSE_SVCLASS 0x1132 /**< Message Access Server */
89 1 : #define BT_SDP_MAP_MCE_SVCLASS 0x1133 /**< Message Notification Server */
90 1 : #define BT_SDP_MAP_SVCLASS 0x1134 /**< Message Access Profile */
91 1 : #define BT_SDP_GNSS_SVCLASS 0x1135 /**< GNSS */
92 1 : #define BT_SDP_GNSS_SERVER_SVCLASS 0x1136 /**< GNSS Server */
93 1 : #define BT_SDP_MPS_SC_SVCLASS 0x113a /**< MPS SC */
94 1 : #define BT_SDP_MPS_SVCLASS 0x113b /**< MPS */
95 1 : #define BT_SDP_PNP_INFO_SVCLASS 0x1200 /**< PnP Information */
96 1 : #define BT_SDP_GENERIC_NETWORKING_SVCLASS 0x1201 /**< Generic Networking */
97 1 : #define BT_SDP_GENERIC_FILETRANS_SVCLASS 0x1202 /**< Generic File Transfer */
98 1 : #define BT_SDP_GENERIC_AUDIO_SVCLASS 0x1203 /**< Generic Audio */
99 1 : #define BT_SDP_GENERIC_TELEPHONY_SVCLASS 0x1204 /**< Generic Telephony */
100 1 : #define BT_SDP_UPNP_SVCLASS 0x1205 /**< UPnP Service */
101 1 : #define BT_SDP_UPNP_IP_SVCLASS 0x1206 /**< UPnP IP Service */
102 1 : #define BT_SDP_UPNP_PAN_SVCLASS 0x1300 /**< UPnP IP PAN */
103 1 : #define BT_SDP_UPNP_LAP_SVCLASS 0x1301 /**< UPnP IP LAP */
104 1 : #define BT_SDP_UPNP_L2CAP_SVCLASS 0x1302 /**< UPnP IP L2CAP */
105 1 : #define BT_SDP_VIDEO_SOURCE_SVCLASS 0x1303 /**< Video Source */
106 1 : #define BT_SDP_VIDEO_SINK_SVCLASS 0x1304 /**< Video Sink */
107 1 : #define BT_SDP_VIDEO_DISTRIBUTION_SVCLASS 0x1305 /**< Video Distribution */
108 1 : #define BT_SDP_HDP_SVCLASS 0x1400 /**< HDP */
109 1 : #define BT_SDP_HDP_SOURCE_SVCLASS 0x1401 /**< HDP Source */
110 1 : #define BT_SDP_HDP_SINK_SVCLASS 0x1402 /**< HDP Sink */
111 1 : #define BT_SDP_GENERIC_ACCESS_SVCLASS 0x1800 /**< Generic Access Profile */
112 1 : #define BT_SDP_GENERIC_ATTRIB_SVCLASS 0x1801 /**< Generic Attribute Profile */
113 1 : #define BT_SDP_APPLE_AGENT_SVCLASS 0x2112 /**< Apple Agent */
114 : /**
115 : * @}
116 : */
117 :
118 0 : #define BT_SDP_SERVER_RECORD_HANDLE 0x0000
119 :
120 : /**
121 : * @name Attribute identifier codes
122 : *
123 : * Possible values for attribute-id are listed below.
124 : * See SDP Spec, section "Service Attribute Definitions" for more details.
125 : *
126 : * @{
127 : */
128 1 : #define BT_SDP_ATTR_RECORD_HANDLE 0x0000 /**< Service Record Handle */
129 1 : #define BT_SDP_ATTR_SVCLASS_ID_LIST 0x0001 /**< Service Class ID List */
130 1 : #define BT_SDP_ATTR_RECORD_STATE 0x0002 /**< Service Record State */
131 1 : #define BT_SDP_ATTR_SERVICE_ID 0x0003 /**< Service ID */
132 1 : #define BT_SDP_ATTR_PROTO_DESC_LIST 0x0004 /**< Protocol Descriptor List */
133 1 : #define BT_SDP_ATTR_BROWSE_GRP_LIST 0x0005 /**< Browse Group List */
134 1 : #define BT_SDP_ATTR_LANG_BASE_ATTR_ID_LIST 0x0006 /**< Language Base Attribute ID List */
135 1 : #define BT_SDP_ATTR_SVCINFO_TTL 0x0007 /**< Service Info Time to Live */
136 1 : #define BT_SDP_ATTR_SERVICE_AVAILABILITY 0x0008 /**< Service Availability */
137 1 : #define BT_SDP_ATTR_PROFILE_DESC_LIST 0x0009 /**< Bluetooth Profile Descriptor List */
138 1 : #define BT_SDP_ATTR_DOC_URL 0x000a /**< Documentation URL */
139 1 : #define BT_SDP_ATTR_CLNT_EXEC_URL 0x000b /**< Client Executable URL */
140 1 : #define BT_SDP_ATTR_ICON_URL 0x000c /**< Icon URL */
141 1 : #define BT_SDP_ATTR_ADD_PROTO_DESC_LIST 0x000d /**< Additional Protocol Descriptor List */
142 :
143 1 : #define BT_SDP_ATTR_GROUP_ID 0x0200 /**< Group ID */
144 1 : #define BT_SDP_ATTR_IP_SUBNET 0x0200 /**< IP Subnet */
145 1 : #define BT_SDP_ATTR_VERSION_NUM_LIST 0x0200 /**< Version Number List */
146 1 : #define BT_SDP_ATTR_SUPPORTED_FEATURES_LIST 0x0200 /**< Supported Features List */
147 1 : #define BT_SDP_ATTR_GOEP_L2CAP_PSM 0x0200 /**< GOEP L2CAP PSM */
148 1 : #define BT_SDP_ATTR_SVCDB_STATE 0x0201 /**< Service Database State */
149 :
150 1 : #define BT_SDP_ATTR_MPSD_SCENARIOS 0x0200 /**< MPSD Scenarios */
151 1 : #define BT_SDP_ATTR_MPMD_SCENARIOS 0x0201 /**< MPMD Scenarios */
152 1 : #define BT_SDP_ATTR_MPS_DEPENDENCIES 0x0202 /**< Supported Profiles & Protocols */
153 :
154 1 : #define BT_SDP_ATTR_SERVICE_VERSION 0x0300 /**< Service Version */
155 1 : #define BT_SDP_ATTR_EXTERNAL_NETWORK 0x0301 /**< External Network */
156 1 : #define BT_SDP_ATTR_SUPPORTED_DATA_STORES_LIST 0x0301 /**< Supported Data Stores List */
157 1 : #define BT_SDP_ATTR_DATA_EXCHANGE_SPEC 0x0301 /**< Data Exchange Specification */
158 1 : #define BT_SDP_ATTR_NETWORK 0x0301 /**< Network */
159 1 : #define BT_SDP_ATTR_FAX_CLASS1_SUPPORT 0x0302 /**< Fax Class 1 Support */
160 1 : #define BT_SDP_ATTR_REMOTE_AUDIO_VOLUME_CONTROL 0x0302 /**< Remote Audio Volume Control */
161 1 : #define BT_SDP_ATTR_MCAP_SUPPORTED_PROCEDURES 0x0302 /**< MCAP Supported Procedures */
162 1 : #define BT_SDP_ATTR_FAX_CLASS20_SUPPORT 0x0303 /**< Fax Class 2.0 Support */
163 1 : #define BT_SDP_ATTR_SUPPORTED_FORMATS_LIST 0x0303 /**< Supported Formats List */
164 1 : #define BT_SDP_ATTR_FAX_CLASS2_SUPPORT 0x0304 /**< Fax Class 2 Support (vendor-specific)*/
165 1 : #define BT_SDP_ATTR_AUDIO_FEEDBACK_SUPPORT 0x0305 /**< Audio Feedback Support */
166 1 : #define BT_SDP_ATTR_NETWORK_ADDRESS 0x0306 /**< Network Address */
167 1 : #define BT_SDP_ATTR_WAP_GATEWAY 0x0307 /**< WAP Gateway */
168 1 : #define BT_SDP_ATTR_HOMEPAGE_URL 0x0308 /**< Homepage URL */
169 1 : #define BT_SDP_ATTR_WAP_STACK_TYPE 0x0309 /**< WAP Stack Type */
170 1 : #define BT_SDP_ATTR_SECURITY_DESC 0x030a /**< Security Description */
171 1 : #define BT_SDP_ATTR_NET_ACCESS_TYPE 0x030b /**< Net Access Type */
172 1 : #define BT_SDP_ATTR_MAX_NET_ACCESSRATE 0x030c /**< Max Net Access Rate */
173 1 : #define BT_SDP_ATTR_IP4_SUBNET 0x030d /**< IPv4 Subnet */
174 1 : #define BT_SDP_ATTR_IP6_SUBNET 0x030e /**< IPv6 Subnet */
175 1 : #define BT_SDP_ATTR_SUPPORTED_CAPABILITIES 0x0310 /**< BIP Supported Capabilities */
176 1 : #define BT_SDP_ATTR_SUPPORTED_FEATURES 0x0311 /**< BIP Supported Features */
177 1 : #define BT_SDP_ATTR_SUPPORTED_FUNCTIONS 0x0312 /**< BIP Supported Functions */
178 1 : #define BT_SDP_ATTR_TOTAL_IMAGING_DATA_CAPACITY 0x0313 /**< BIP Total Imaging Data Capacity */
179 1 : #define BT_SDP_ATTR_SUPPORTED_REPOSITORIES 0x0314 /**< Supported Repositories */
180 1 : #define BT_SDP_ATTR_MAS_INSTANCE_ID 0x0315 /**< MAS Instance ID */
181 1 : #define BT_SDP_ATTR_SUPPORTED_MESSAGE_TYPES 0x0316 /**< Supported Message Types */
182 1 : #define BT_SDP_ATTR_PBAP_SUPPORTED_FEATURES 0x0317 /**< PBAP Supported Features */
183 1 : #define BT_SDP_ATTR_MAP_SUPPORTED_FEATURES 0x0317 /**< MAP Supported Features */
184 :
185 1 : #define BT_SDP_ATTR_SPECIFICATION_ID 0x0200 /**< Specification ID */
186 1 : #define BT_SDP_ATTR_VENDOR_ID 0x0201 /**< Vendor ID */
187 1 : #define BT_SDP_ATTR_PRODUCT_ID 0x0202 /**< Product ID */
188 1 : #define BT_SDP_ATTR_VERSION 0x0203 /**< Version */
189 1 : #define BT_SDP_ATTR_PRIMARY_RECORD 0x0204 /**< Primary Record */
190 1 : #define BT_SDP_ATTR_VENDOR_ID_SOURCE 0x0205 /**< Vendor ID Source */
191 :
192 1 : #define BT_SDP_ATTR_HID_DEVICE_RELEASE_NUMBER 0x0200 /**< HID Device Release Number */
193 1 : #define BT_SDP_ATTR_HID_PARSER_VERSION 0x0201 /**< HID Parser Version */
194 1 : #define BT_SDP_ATTR_HID_DEVICE_SUBCLASS 0x0202 /**< HID Device Subclass */
195 1 : #define BT_SDP_ATTR_HID_COUNTRY_CODE 0x0203 /**< HID Country Code */
196 1 : #define BT_SDP_ATTR_HID_VIRTUAL_CABLE 0x0204 /**< HID Virtual Cable */
197 1 : #define BT_SDP_ATTR_HID_RECONNECT_INITIATE 0x0205 /**< HID Reconnect Initiate */
198 1 : #define BT_SDP_ATTR_HID_DESCRIPTOR_LIST 0x0206 /**< HID Descriptor List */
199 1 : #define BT_SDP_ATTR_HID_LANG_ID_BASE_LIST 0x0207 /**< HID Language ID Base List */
200 1 : #define BT_SDP_ATTR_HID_SDP_DISABLE 0x0208 /**< HID SDP Disable */
201 1 : #define BT_SDP_ATTR_HID_BATTERY_POWER 0x0209 /**< HID Battery Power */
202 1 : #define BT_SDP_ATTR_HID_REMOTE_WAKEUP 0x020a /**< HID Remote Wakeup */
203 1 : #define BT_SDP_ATTR_HID_PROFILE_VERSION 0x020b /**< HID Profile Version */
204 1 : #define BT_SDP_ATTR_HID_SUPERVISION_TIMEOUT 0x020c /**< HID Supervision Timeout */
205 1 : #define BT_SDP_ATTR_HID_NORMALLY_CONNECTABLE 0x020d /**< HID Normally Connectable */
206 1 : #define BT_SDP_ATTR_HID_BOOT_DEVICE 0x020e /**< HID Boot Device */
207 : /**
208 : * @}
209 : */
210 :
211 : /*
212 : * These identifiers are based on the SDP spec stating that
213 : * "base attribute id of the primary (universal) language must be 0x0100"
214 : *
215 : * Other languages should have their own offset; e.g.:
216 : * #define XXXLangBase yyyy
217 : * #define AttrServiceName_XXX 0x0000+XXXLangBase
218 : */
219 0 : #define BT_SDP_PRIMARY_LANG_BASE 0x0100
220 :
221 0 : #define BT_SDP_ATTR_SVCNAME_PRIMARY (0x0000 + BT_SDP_PRIMARY_LANG_BASE)
222 0 : #define BT_SDP_ATTR_SVCDESC_PRIMARY (0x0001 + BT_SDP_PRIMARY_LANG_BASE)
223 0 : #define BT_SDP_ATTR_PROVNAME_PRIMARY (0x0002 + BT_SDP_PRIMARY_LANG_BASE)
224 :
225 : /**
226 : * @name The Data representation in SDP PDUs (pps 339, 340 of BT SDP Spec)
227 : *
228 : * These are the exact data type+size descriptor values
229 : * that go into the PDU buffer.
230 : *
231 : * The datatype (leading 5bits) + size descriptor (last 3 bits)
232 : * is 8 bits. The size descriptor is critical to extract the
233 : * right number of bytes for the data value from the PDU.
234 : *
235 : * For most basic types, the datatype+size descriptor is
236 : * straightforward. However for constructed types and strings,
237 : * the size of the data is in the next "n" bytes following the
238 : * 8 bits (datatype+size) descriptor. Exactly what the "n" is
239 : * specified in the 3 bits of the data size descriptor.
240 : *
241 : * TextString and URLString can be of size 2^{8, 16, 32} bytes
242 : * DataSequence and DataSequenceAlternates can be of size 2^{8, 16, 32}
243 : * The size are computed post-facto in the API and are not known apriori.
244 : *
245 : * For the type BT_SDP_UINT128, BT_SDP_INT128, and BT_SDP_UUID128, the
246 : * byteorder of data should be little-endian. Such as, SPP UUID128:
247 : * `00001101-0000-1000-8000-00805F9B34FB` will be represented as
248 : * {0xFB, 0x34, 0x9B, 0x5F, 0x80, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00,
249 : * 0x01, 0x11, 0x00, 0x00}
250 : * For UUID 128, @ref BT_SDP_ARRAY_UUID_128 is used to declare the array.
251 : * @{
252 : */
253 1 : #define BT_SDP_DATA_NIL 0x00 /**< Nil, the null type */
254 1 : #define BT_SDP_UINT8 0x08 /**< Unsigned 8-bit integer */
255 1 : #define BT_SDP_UINT16 0x09 /**< Unsigned 16-bit integer */
256 1 : #define BT_SDP_UINT32 0x0a /**< Unsigned 32-bit integer */
257 1 : #define BT_SDP_UINT64 0x0b /**< Unsigned 64-bit integer */
258 1 : #define BT_SDP_UINT128 0x0c /**< Unsigned 128-bit integer */
259 1 : #define BT_SDP_INT8 0x10 /**< Signed 8-bit integer */
260 1 : #define BT_SDP_INT16 0x11 /**< Signed 16-bit integer */
261 1 : #define BT_SDP_INT32 0x12 /**< Signed 32-bit integer */
262 1 : #define BT_SDP_INT64 0x13 /**< Signed 64-bit integer */
263 1 : #define BT_SDP_INT128 0x14 /**< Signed 128-bit integer */
264 1 : #define BT_SDP_UUID_UNSPEC 0x18 /**< UUID, unspecified size */
265 1 : #define BT_SDP_UUID16 0x19 /**< UUID, 16-bit */
266 1 : #define BT_SDP_UUID32 0x1a /**< UUID, 32-bit */
267 1 : #define BT_SDP_UUID128 0x1c /**< UUID, 128-bit */
268 1 : #define BT_SDP_TEXT_STR_UNSPEC 0x20 /**< Text string, unspecified size */
269 1 : #define BT_SDP_TEXT_STR8 0x25 /**< Text string, 8-bit length */
270 1 : #define BT_SDP_TEXT_STR16 0x26 /**< Text string, 16-bit length */
271 1 : #define BT_SDP_TEXT_STR32 0x27 /**< Text string, 32-bit length */
272 1 : #define BT_SDP_BOOL 0x28 /**< Boolean */
273 1 : #define BT_SDP_SEQ_UNSPEC 0x30 /**< Data element sequence, unspecified size */
274 1 : #define BT_SDP_SEQ8 0x35 /**< Data element sequence, 8-bit length */
275 1 : #define BT_SDP_SEQ16 0x36 /**< Data element sequence, 16-bit length */
276 1 : #define BT_SDP_SEQ32 0x37 /**< Data element sequence, 32-bit length */
277 1 : #define BT_SDP_ALT_UNSPEC 0x38 /**< Data element alternative, unspecified size */
278 1 : #define BT_SDP_ALT8 0x3d /**< Data element alternative, 8-bit length */
279 1 : #define BT_SDP_ALT16 0x3e /**< Data element alternative, 16-bit length */
280 1 : #define BT_SDP_ALT32 0x3f /**< Data element alternative, 32-bit length */
281 1 : #define BT_SDP_URL_STR_UNSPEC 0x40 /**< URL string, unspecified size */
282 1 : #define BT_SDP_URL_STR8 0x45 /**< URL string, 8-bit length */
283 1 : #define BT_SDP_URL_STR16 0x46 /**< URL string, 16-bit length */
284 1 : #define BT_SDP_URL_STR32 0x47 /**< URL string, 32-bit length */
285 : /**
286 : * @}
287 : */
288 :
289 0 : #define BT_SDP_TYPE_DESC_MASK 0xf8
290 0 : #define BT_SDP_SIZE_DESC_MASK 0x07
291 0 : #define BT_SDP_SIZE_INDEX_OFFSET 5
292 :
293 : /** @brief SDP Generic Data Element Value. */
294 1 : struct bt_sdp_data_elem {
295 1 : uint8_t type; /**< Type of the data element */
296 1 : uint32_t data_size; /**< Size of the data element */
297 1 : uint32_t total_size; /**< Total size of the data element */
298 0 : const void *data;
299 : };
300 :
301 : /** @brief SDP Attribute Value. */
302 1 : struct bt_sdp_attribute {
303 1 : uint16_t id; /**< Attribute ID */
304 1 : struct bt_sdp_data_elem val; /**< Attribute data */
305 : };
306 :
307 : /** @brief SDP Service Record Value. */
308 1 : struct bt_sdp_record {
309 1 : uint32_t handle; /**< Redundant, for quick ref */
310 1 : struct bt_sdp_attribute *attrs; /**< Base addr of attr array */
311 1 : size_t attr_count; /**< Number of attributes */
312 1 : uint8_t index; /**< Index of the record in LL */
313 1 : struct bt_sdp_record *next; /**< Next service record */
314 : };
315 :
316 : /*
317 : * --------------------------------------------------- ------------------
318 : * | Service Hdl | Attr list ptr | Attr count | Next | -> | Service Hdl | ...
319 : * --------------------------------------------------- ------------------
320 : */
321 :
322 : /**
323 : * @brief Declare an array of 8-bit elements in an attribute.
324 : */
325 1 : #define BT_SDP_ARRAY_8(...) ((uint8_t[]) {__VA_ARGS__})
326 :
327 : /**
328 : * @brief Declare an array of 16-bit elements in an attribute.
329 : */
330 1 : #define BT_SDP_ARRAY_16(...) ((uint16_t[]) {__VA_ARGS__})
331 :
332 : /**
333 : * @brief Declare an array of 32-bit elements in an attribute.
334 : */
335 1 : #define BT_SDP_ARRAY_32(...) ((uint32_t[]) {__VA_ARGS__})
336 :
337 : /**
338 : * @brief Declare a UUID 128 in little-endian format in an attribute.
339 : *
340 : * Helper macro to initialize a 128-bit UUID array value from the readable form
341 : * of UUIDs.
342 : *
343 : * Example of how to declare the UUID `6E400001-B5A3-F393-E0A9-E50E24DCCA9E`
344 : *
345 : * @code
346 : * BT_SDP_ARRAY_UUID_128(0x6E400001, 0xB5A3, 0xF393, 0xE0A9, 0xE50E24DCCA9E)
347 : * @endcode
348 : *
349 : * Just replace the hyphen by the comma and add `0x` prefixes.
350 : *
351 : * @param w32 First part of the UUID (32 bits)
352 : * @param w1 Second part of the UUID (16 bits)
353 : * @param w2 Third part of the UUID (16 bits)
354 : * @param w3 Fourth part of the UUID (16 bits)
355 : * @param w48 Fifth part of the UUID (48 bits)
356 : *
357 : * @return The comma separated values for UUID 128.
358 : */
359 1 : #define BT_SDP_ARRAY_UUID_128(w32, w1, w2, w3, w48) \
360 : BT_SDP_ARRAY_8(BT_UUID_128_ENCODE(w32, w1, w2, w3, w48))
361 :
362 : /**
363 : * @brief Declare a fixed-size data element header.
364 : *
365 : * @param _type Data element header containing type and size descriptors.
366 : */
367 1 : #define BT_SDP_TYPE_SIZE(_type) .type = _type, \
368 : .data_size = BIT(_type & BT_SDP_SIZE_DESC_MASK), \
369 : .total_size = BIT(_type & BT_SDP_SIZE_DESC_MASK) + 1
370 :
371 : /**
372 : * @brief Declare a variable-size data element header.
373 : *
374 : * @param _type Data element header containing type and size descriptors.
375 : * @param _size The actual size of the data.
376 : */
377 1 : #define BT_SDP_TYPE_SIZE_VAR(_type, _size) .type = _type, \
378 : .data_size = _size, \
379 : .total_size = BIT((_type & BT_SDP_SIZE_DESC_MASK) - \
380 : BT_SDP_SIZE_INDEX_OFFSET) + _size + 1
381 :
382 : /**
383 : * @brief Declare a list of data elements.
384 : */
385 1 : #define BT_SDP_DATA_ELEM_LIST(...) ((struct bt_sdp_data_elem[]) {__VA_ARGS__})
386 :
387 :
388 : /**
389 : * @brief SDP New Service Record Declaration Macro.
390 : *
391 : * Helper macro to declare a new service record.
392 : * Default attributes: Record Handle, Record State,
393 : * Language Base, Root Browse Group
394 : *
395 : */
396 1 : #define BT_SDP_NEW_SERVICE \
397 : { \
398 : BT_SDP_ATTR_RECORD_HANDLE, \
399 : { BT_SDP_TYPE_SIZE(BT_SDP_UINT32), BT_SDP_ARRAY_32(0) } \
400 : }, \
401 : { \
402 : BT_SDP_ATTR_RECORD_STATE, \
403 : { BT_SDP_TYPE_SIZE(BT_SDP_UINT32), BT_SDP_ARRAY_32(0) } \
404 : }, \
405 : { \
406 : BT_SDP_ATTR_LANG_BASE_ATTR_ID_LIST, \
407 : { BT_SDP_TYPE_SIZE_VAR(BT_SDP_SEQ8, 9), \
408 : BT_SDP_DATA_ELEM_LIST( \
409 : { BT_SDP_TYPE_SIZE(BT_SDP_UINT16), BT_SDP_ARRAY_8('n', 'e') }, \
410 : { BT_SDP_TYPE_SIZE(BT_SDP_UINT16), BT_SDP_ARRAY_16(106) }, \
411 : { BT_SDP_TYPE_SIZE(BT_SDP_UINT16), \
412 : BT_SDP_ARRAY_16(BT_SDP_PRIMARY_LANG_BASE) } \
413 : ), \
414 : } \
415 : }, \
416 : { \
417 : BT_SDP_ATTR_BROWSE_GRP_LIST, \
418 : { BT_SDP_TYPE_SIZE_VAR(BT_SDP_SEQ8, 3), \
419 : BT_SDP_DATA_ELEM_LIST( \
420 : { BT_SDP_TYPE_SIZE(BT_SDP_UUID16), \
421 : BT_SDP_ARRAY_16(BT_SDP_PUBLIC_BROWSE_GROUP) }, \
422 : ), \
423 : } \
424 : }
425 :
426 :
427 : /**
428 : * @brief Generic SDP List Attribute Declaration Macro.
429 : *
430 : * Helper macro to declare a list attribute.
431 : *
432 : * @param _att_id List Attribute ID.
433 : * @param _data_elem_seq Data element sequence for the list.
434 : * @param _type_size SDP type and size descriptor.
435 : */
436 1 : #define BT_SDP_LIST(_att_id, _type_size, _data_elem_seq) \
437 : { \
438 : _att_id, { _type_size, _data_elem_seq } \
439 : }
440 :
441 : /**
442 : * @brief SDP Service ID Attribute Declaration Macro.
443 : *
444 : * Helper macro to declare a service ID attribute.
445 : *
446 : * @param _uuid Service ID 16bit UUID.
447 : */
448 1 : #define BT_SDP_SERVICE_ID(_uuid) \
449 : { \
450 : BT_SDP_ATTR_SERVICE_ID, \
451 : { BT_SDP_TYPE_SIZE(BT_SDP_UUID16), &((struct bt_uuid_16) _uuid) } \
452 : }
453 :
454 : /**
455 : * @brief SDP Name Attribute Declaration Macro.
456 : *
457 : * Helper macro to declare a service name attribute.
458 : *
459 : * @param _name Service name as a string (up to 256 chars).
460 : */
461 1 : #define BT_SDP_SERVICE_NAME(_name) \
462 : { \
463 : BT_SDP_ATTR_SVCNAME_PRIMARY, \
464 : { BT_SDP_TYPE_SIZE_VAR(BT_SDP_TEXT_STR8, (sizeof(_name)-1)), _name } \
465 : }
466 :
467 : /**
468 : * @brief SDP Supported Features Attribute Declaration Macro.
469 : *
470 : * Helper macro to declare supported features of a profile/protocol.
471 : *
472 : * @param _features Feature mask as 16bit unsigned integer.
473 : */
474 1 : #define BT_SDP_SUPPORTED_FEATURES(_features) \
475 : { \
476 : BT_SDP_ATTR_SUPPORTED_FEATURES, \
477 : { BT_SDP_TYPE_SIZE(BT_SDP_UINT16), BT_SDP_ARRAY_16(_features) } \
478 : }
479 :
480 : /**
481 : * @brief SDP Service Declaration Macro.
482 : *
483 : * Helper macro to declare a service.
484 : *
485 : * @param _attrs List of attributes for the service record.
486 : */
487 1 : #define BT_SDP_RECORD(_attrs) \
488 : { \
489 : .attrs = _attrs, \
490 : .attr_count = ARRAY_SIZE((_attrs)), \
491 : }
492 :
493 : /* Server API */
494 :
495 : /** @brief Register a Service Record.
496 : *
497 : * Register a Service Record. Applications can make use of
498 : * macros such as BT_SDP_DECLARE_SERVICE, BT_SDP_LIST,
499 : * BT_SDP_SERVICE_ID, BT_SDP_SERVICE_NAME, etc.
500 : * A service declaration must start with BT_SDP_NEW_SERVICE.
501 : *
502 : * @param service Service record declared using BT_SDP_DECLARE_SERVICE.
503 : *
504 : * @return 0 in case of success or negative value in case of error.
505 : */
506 1 : int bt_sdp_register_service(struct bt_sdp_record *service);
507 :
508 : /* Client API */
509 :
510 : /** @brief Generic SDP Client Query Result data holder */
511 1 : struct bt_sdp_client_result {
512 : /** buffer containing unparsed SDP record result for given UUID */
513 1 : struct net_buf *resp_buf;
514 : /** flag pointing that there are more result chunks for given UUID */
515 1 : bool next_record_hint;
516 : };
517 :
518 : /** @brief Helper enum to be used as return value of bt_sdp_discover_func_t.
519 : * The value informs the caller to perform further pending actions or stop them.
520 : */
521 0 : enum {
522 : BT_SDP_DISCOVER_UUID_STOP = 0,
523 : BT_SDP_DISCOVER_UUID_CONTINUE,
524 : };
525 :
526 : struct bt_sdp_discover_params;
527 :
528 : /** @typedef bt_sdp_discover_func_t
529 : *
530 : * @brief Callback type reporting to user that there is a resolved result
531 : * on remote for given UUID and the result record buffer can be used by user
532 : * for further inspection.
533 : *
534 : * A function of this type is given by the user to the bt_sdp_discover_params
535 : * object. It'll be called on each valid record discovery completion for given
536 : * UUID. When UUID resolution gives back no records then NULL is passed
537 : * to the user. Otherwise user can get valid record(s) and then the internal
538 : * hint 'next record' is set to false saying the UUID resolution is complete or
539 : * the hint can be set by caller to true meaning that next record is available
540 : * for given UUID.
541 : * The returned function value allows the user to control retrieving follow-up
542 : * resolved records if any. If the user doesn't want to read more resolved
543 : * records for given UUID since current record data fulfills its requirements
544 : * then should return BT_SDP_DISCOVER_UUID_STOP. Otherwise returned value means
545 : * more subcall iterations are allowable.
546 : *
547 : * @param conn Connection object identifying connection to queried remote.
548 : * @param result Object pointing to logical unparsed SDP record collected on
549 : * base of response driven by given discover params.
550 : * @param params Discover parameters.
551 : *
552 : * @return BT_SDP_DISCOVER_UUID_STOP in case of no more need to read next
553 : * record data and continue discovery for given UUID. By returning
554 : * @return BT_SDP_DISCOVER_UUID_CONTINUE user allows this discovery continuation.
555 : */
556 1 : typedef uint8_t (*bt_sdp_discover_func_t)(struct bt_conn *conn, struct bt_sdp_client_result *result,
557 : const struct bt_sdp_discover_params *params);
558 :
559 : /** SDP Discover types */
560 1 : enum {
561 : /** Discover Service Search. */
562 : BT_SDP_DISCOVER_SERVICE_SEARCH,
563 : /** Discover Service Attribute. */
564 : BT_SDP_DISCOVER_SERVICE_ATTR,
565 : /** Discover Service Search Attribute. */
566 : BT_SDP_DISCOVER_SERVICE_SEARCH_ATTR,
567 : };
568 :
569 : /** @brief Main user structure used in SDP discovery of remote. */
570 1 : struct bt_sdp_discover_params {
571 : sys_snode_t _node;
572 : union {
573 : /** UUID (service) to be discovered on remote SDP entity */
574 1 : const struct bt_uuid *uuid;
575 : /** Service record handle */
576 1 : uint32_t handle;
577 0 : };
578 : /** Discover callback to be called on resolved SDP record */
579 1 : bt_sdp_discover_func_t func;
580 : /** Memory buffer enabled by user for SDP query results */
581 1 : struct net_buf_pool *pool;
582 : /** Discover type */
583 1 : uint8_t type;
584 : };
585 :
586 : /** @brief Allows user to start SDP discovery session.
587 : *
588 : * The function performs SDP service discovery on remote server driven by user
589 : * delivered discovery parameters. Discovery session is made as soon as
590 : * no SDP transaction is ongoing between peers and if any then this one
591 : * is queued to be processed at discovery completion of previous one.
592 : * On the service discovery completion the callback function will be
593 : * called to get feedback to user about findings.
594 : *
595 : * If the UUID is UUID 128 for discovery type `Service Search` and
596 : * `Service Search Attribute`, the UUID data should be represented as the
597 : * little-endian byteorder sequence.
598 : *
599 : * Service Search: The SDP Client generates an
600 : * SDP_SERVICE_SEARCH_REQ to locate service
601 : * records that match the service search
602 : * pattern (`params->uuid`) given as the first
603 : * parameter of the PDU.
604 : * Service Attribute: The SDP Client generates an
605 : * SDP_SERVICE_ATTR_REQ to retrieve specified
606 : * attribute values from a specific service
607 : * record (`params->handle`).
608 : * Service Search Attribute: The SDP Client generates an
609 : * SDP_SERVICE_SEARCH_ATTR_REQ to retrieve
610 : * specified attribute values that match the
611 : * service search pattern (`params->uuid`)
612 : * given as the first parameter of the PDU.
613 : *
614 : * @param conn Object identifying connection to remote.
615 : * @param params SDP discovery parameters.
616 : *
617 : * @return 0 in case of success or negative value in case of error.
618 : */
619 :
620 1 : int bt_sdp_discover(struct bt_conn *conn,
621 : struct bt_sdp_discover_params *params);
622 :
623 : /** @brief Release waiting SDP discovery request.
624 : *
625 : * It can cancel valid waiting SDP client request identified by SDP discovery
626 : * parameters object.
627 : *
628 : * @param conn Object identifying connection to remote.
629 : * @param params SDP discovery parameters.
630 : *
631 : * @return 0 in case of success or negative value in case of error.
632 : */
633 1 : int bt_sdp_discover_cancel(struct bt_conn *conn,
634 : const struct bt_sdp_discover_params *params);
635 :
636 :
637 : /* Helper types & functions for SDP client to get essential data from server */
638 :
639 : /** @brief Protocols to be asked about specific parameters */
640 0 : enum bt_sdp_proto {
641 : BT_SDP_PROTO_RFCOMM = 0x0003,
642 : BT_SDP_PROTO_AVDTP = 0x0019,
643 : BT_SDP_PROTO_L2CAP = 0x0100,
644 : };
645 :
646 : /** @brief Give to user parameter value related to given stacked protocol UUID.
647 : *
648 : * API extracts specific parameter associated with given protocol UUID
649 : * available in Protocol Descriptor List attribute.
650 : *
651 : * @param buf Original buffered raw record data.
652 : * @param proto Known protocol to be checked like RFCOMM or L2CAP.
653 : * @param param On success populated by found parameter value.
654 : *
655 : * @return 0 on success when specific parameter associated with given protocol
656 : * value is found, or negative if error occurred during processing.
657 : */
658 1 : int bt_sdp_get_proto_param(const struct net_buf *buf, enum bt_sdp_proto proto,
659 : uint16_t *param);
660 :
661 : /** @brief Get additional parameter value related to given stacked protocol UUID.
662 : *
663 : * API extracts specific parameter associated with given protocol UUID
664 : * available in Additional Protocol Descriptor List attribute.
665 : *
666 : * @param buf Original buffered raw record data.
667 : * @param proto Known protocol to be checked like RFCOMM or L2CAP.
668 : * @param param_index There may be more than one parameter related to the
669 : * given protocol UUID. This function returns the result that is
670 : * indexed by this parameter. It's value is from 0, 0 means the
671 : * first matched result, 1 means the second matched result.
672 : * @param[out] param On success populated by found parameter value.
673 : *
674 : * @return 0 on success when a specific parameter associated with a given protocol
675 : * value is found, or negative if error occurred during processing.
676 : */
677 1 : int bt_sdp_get_addl_proto_param(const struct net_buf *buf, enum bt_sdp_proto proto,
678 : uint8_t param_index, uint16_t *param);
679 :
680 : /** @brief Get profile version.
681 : *
682 : * Helper API extracting remote profile version number. To get it proper
683 : * generic profile parameter needs to be selected usually listed in SDP
684 : * Interoperability Requirements section for given profile specification.
685 : *
686 : * @param buf Original buffered raw record data.
687 : * @param profile Profile family identifier the profile belongs.
688 : * @param version On success populated by found version number.
689 : *
690 : * @return 0 on success, negative value if error occurred during processing.
691 : */
692 1 : int bt_sdp_get_profile_version(const struct net_buf *buf, uint16_t profile,
693 : uint16_t *version);
694 :
695 : /** @brief Get SupportedFeatures attribute value
696 : *
697 : * Allows if exposed by remote retrieve SupportedFeature attribute.
698 : *
699 : * @param buf Buffer holding original raw record data from remote.
700 : * @param features On success object to be populated with SupportedFeature
701 : * mask.
702 : *
703 : * @return 0 on success if feature found and valid, negative in case any error
704 : */
705 1 : int bt_sdp_get_features(const struct net_buf *buf, uint16_t *features);
706 :
707 : /** @brief Get Vendor ID
708 : *
709 : * Helper API extracting remote Vendor ID. To get it proper
710 : * generic profile parameter needs to be selected usually listed in SDP
711 : * Interoperability Requirements section for given profile specification.
712 : *
713 : * @param buf Buffer holding original raw record data from remote.
714 : * @param vendor_id On success populated by found Vendor ID.
715 : *
716 : * @return 0 on success if vendor_id found and valid, negative in case any error
717 : */
718 1 : int bt_sdp_get_vendor_id(const struct net_buf *buf, uint16_t *vendor_id);
719 :
720 : /** @brief Get Product ID
721 : *
722 : * Helper API extracting remote Product ID. To get it proper
723 : * generic profile parameter needs to be selected usually listed in SDP
724 : * Interoperability Requirements section for given profile specification.
725 : *
726 : * @param buf Buffer holding original raw record data from remote.
727 : * @param product_id On success populated by found Product ID.
728 : * mask.
729 : *
730 : * @return 0 on success if product_id found and valid, negative in case any error
731 : */
732 1 : int bt_sdp_get_product_id(const struct net_buf *buf, uint16_t *product_id);
733 :
734 : #ifdef __cplusplus
735 : }
736 : #endif
737 :
738 : /**
739 : * @}
740 : */
741 :
742 : #endif /* ZEPHYR_INCLUDE_BLUETOOTH_SDP_H_ */
|