xref: /dragonfly/lib/libsdp/sdp.h (revision 42c447e672ef6f27c808db0bfcf5c9944c83c3a7)
1 /* $NetBSD: sdp.h,v 1.2 2006/08/17 20:13:31 plunky Exp $ */
2 
3 /*-
4  * Copyright (c) 2006 Itronix Inc.
5  * All rights reserved.
6  *
7  * Written by Iain Hibbert for Itronix Inc.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  * 3. The name of Itronix Inc. may not be used to endorse
18  *    or promote products derived from this software without specific
19  *    prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY ITRONIX INC. ``AS IS'' AND
22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL ITRONIX INC. BE LIABLE FOR ANY
25  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28  * ON ANY THEORY OF LIABILITY, WHETHER IN
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  */
33 /*
34  * sdp.h
35  *
36  * Copyright (c) 2001-2003 Maksim Yevmenkin <m_evmenkin@yahoo.com>
37  * All rights reserved.
38  *
39  * Redistribution and use in source and binary forms, with or without
40  * modification, are permitted provided that the following conditions
41  * are met:
42  * 1. Redistributions of source code must retain the above copyright
43  *    notice, this list of conditions and the following disclaimer.
44  * 2. Redistributions in binary form must reproduce the above copyright
45  *    notice, this list of conditions and the following disclaimer in the
46  *    documentation and/or other materials provided with the distribution.
47  *
48  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
49  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
52  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58  * SUCH DAMAGE.
59  *
60  * $Id: sdp.h,v 1.2 2006/08/17 20:13:31 plunky Exp $
61  * $FreeBSD: src/lib/libsdp/sdp.h,v 1.5 2005/05/27 19:11:33 emax Exp $
62  */
63 
64 #ifndef _SDP_H_
65 #define _SDP_H_
66 
67 #include <stdint.h>
68 #include <string.h>
69 #include <netbt/bluetooth.h>
70 
71 __BEGIN_DECLS
72 
73 /*
74  * Data representation (page 349)
75  */
76 
77 /* Nil, the null type */
78 #define SDP_DATA_NIL                                                  0x00
79 
80 /* Unsigned integer */
81 #define SDP_DATA_UINT8                                                0x08
82 #define SDP_DATA_UINT16                                               0x09
83 #define SDP_DATA_UINT32                                               0x0A
84 #define SDP_DATA_UINT64                                               0x0B
85 #define SDP_DATA_UINT128                                    0x0C
86 
87 /* Signed two's-complement integer */
88 #define SDP_DATA_INT8                                                 0x10
89 #define SDP_DATA_INT16                                                0x11
90 #define SDP_DATA_INT32                                                0x12
91 #define SDP_DATA_INT64                                                0x13
92 #define SDP_DATA_INT128                                               0x14
93 
94 /* UUID, a universally unique identifier */
95 #define SDP_DATA_UUID16                                               0x19
96 #define SDP_DATA_UUID32                                               0x1A
97 #define SDP_DATA_UUID128                                    0x1C
98 
99 /* Text string */
100 #define SDP_DATA_STR8                                                 0x25
101 #define SDP_DATA_STR16                                                0x26
102 #define SDP_DATA_STR32                                                0x27
103 
104 /* Boolean */
105 #define SDP_DATA_BOOL                                                 0x28
106 
107 /*
108  * Data element sequence.
109  * A data element whose data field is a sequence of data elements
110  */
111 #define SDP_DATA_SEQ8                                                 0x35
112 #define SDP_DATA_SEQ16                                                0x36
113 #define SDP_DATA_SEQ32                                                0x37
114 
115 /*
116  * Data element alternative.
117  * A data element whose data field is a sequence of data elements from
118  * which one data element is to be selected.
119  */
120 #define SDP_DATA_ALT8                                                 0x3D
121 #define SDP_DATA_ALT16                                                0x3E
122 #define SDP_DATA_ALT32                                                0x3F
123 
124 /* URL, a uniform resource locator */
125 #define SDP_DATA_URL8                                                 0x45
126 #define SDP_DATA_URL16                                                0x46
127 #define SDP_DATA_URL32                                                0x47
128 
129 /*
130  * Protocols UUID (short) http://www.bluetoothsig.org/assigned-numbers/sdp.htm
131  * BASE UUID 00000000-0000-1000-8000-00805F9B34FB
132  */
133 
134 #define SDP_UUID_PROTOCOL_SDP                               0x0001
135 #define SDP_UUID_PROTOCOL_UDP                               0x0002
136 #define SDP_UUID_PROTOCOL_RFCOMM                            0x0003
137 #define SDP_UUID_PROTOCOL_TCP                               0x0004
138 #define SDP_UUID_PROTOCOL_TCS_BIN                           0x0005
139 #define SDP_UUID_PROTOCOL_TCS_AT                            0x0006
140 #define SDP_UUID_PROTOCOL_OBEX                                        0x0008
141 #define SDP_UUID_PROTOCOL_IP                                0x0009
142 #define SDP_UUID_PROTOCOL_FTP                               0x000A
143 #define SDP_UUID_PROTOCOL_HTTP                                        0x000C
144 #define SDP_UUID_PROTOCOL_WSP                               0x000E
145 #define SDP_UUID_PROTOCOL_BNEP                                        0x000F
146 #define SDP_UUID_PROTOCOL_UPNP                                        0x0010
147 #define SDP_UUID_PROTOCOL_HIDP                                        0x0011
148 #define SDP_UUID_PROTOCOL_HARDCOPY_CONTROL_CHANNEL          0x0012
149 #define SDP_UUID_PROTOCOL_HARDCOPY_DATA_CHANNEL             0x0014
150 #define SDP_UUID_PROTOCOL_HARDCOPY_NOTIFICATION             0x0016
151 #define SDP_UUID_PROTOCOL_AVCTP                                       0x0017
152 #define SDP_UUID_PROTOCOL_AVDTP                                       0x0019
153 #define SDP_UUID_PROTOCOL_CMPT                                        0x001B
154 #define SDP_UUID_PROTOCOL_UDI_C_PLANE                       0x001D
155 #define SDP_UUID_PROTOCOL_L2CAP                                       0x0100
156 
157 /*
158  * Service class IDs http://www.bluetoothsig.org/assigned-numbers/sdp.htm
159  */
160 
161 #define SDP_SERVICE_CLASS_SERVICE_DISCOVERY_SERVER          0x1000
162 #define SDP_SERVICE_CLASS_BROWSE_GROUP_DESCRIPTOR 0x1001
163 #define SDP_SERVICE_CLASS_PUBLIC_BROWSE_GROUP               0x1002
164 #define SDP_SERVICE_CLASS_SERIAL_PORT                       0x1101
165 #define SDP_SERVICE_CLASS_LAN_ACCESS_USING_PPP              0x1102
166 #define SDP_SERVICE_CLASS_DIALUP_NETWORKING                 0x1103
167 #define SDP_SERVICE_CLASS_IR_MC_SYNC                        0x1104
168 #define SDP_SERVICE_CLASS_OBEX_OBJECT_PUSH                  0x1105
169 #define SDP_SERVICE_CLASS_OBEX_FILE_TRANSFER                0x1106
170 #define SDP_SERVICE_CLASS_IR_MC_SYNC_COMMAND                0x1107
171 #define SDP_SERVICE_CLASS_HEADSET                           0x1108
172 #define SDP_SERVICE_CLASS_CORDLESS_TELEPHONY                0x1109
173 #define SDP_SERVICE_CLASS_AUDIO_SOURCE                      0x110A
174 #define SDP_SERVICE_CLASS_AUDIO_SINK                        0x110B
175 #define SDP_SERVICE_CLASS_AV_REMOTE_CONTROL_TARGET          0x110C
176 #define SDP_SERVICE_CLASS_ADVANCED_AUDIO_DISTRIBUTION       0x110D
177 #define SDP_SERVICE_CLASS_AV_REMOTE_CONTROL                 0x110E
178 #define SDP_SERVICE_CLASS_VIDEO_CONFERENCING                0x110F
179 #define SDP_SERVICE_CLASS_INTERCOM                          0x1110
180 #define SDP_SERVICE_CLASS_FAX                               0x1111
181 #define SDP_SERVICE_CLASS_HEADSET_AUDIO_GATEWAY             0x1112
182 #define SDP_SERVICE_CLASS_WAP                               0x1113
183 #define SDP_SERVICE_CLASS_WAP_CLIENT                        0x1114
184 #define SDP_SERVICE_CLASS_PANU                                        0x1115
185 #define SDP_SERVICE_CLASS_NAP                               0x1116
186 #define SDP_SERVICE_CLASS_GN                                0x1117
187 #define SDP_SERVICE_CLASS_DIRECT_PRINTING                   0x1118
188 #define SDP_SERVICE_CLASS_REFERENCE_PRINTING                0x1119
189 #define SDP_SERVICE_CLASS_IMAGING                           0x111A
190 #define SDP_SERVICE_CLASS_IMAGING_RESPONDER                 0x111B
191 #define SDP_SERVICE_CLASS_IMAGING_AUTOMATIC_ARCHIVE         0x111C
192 #define SDP_SERVICE_CLASS_IMAGING_REFERENCED_OBJECTS        0x111D
193 #define SDP_SERVICE_CLASS_HANDSFREE                         0x111E
194 #define SDP_SERVICE_CLASS_HANDSFREE_AUDIO_GATEWAY 0x111F
195 #define SDP_SERVICE_CLASS_DIRECT_PRINTING_REFERENCE_OBJECTS 0x1120
196 #define SDP_SERVICE_CLASS_REFLECTED_UI                      0x1121
197 #define SDP_SERVICE_CLASS_BASIC_PRINTING                    0x1122
198 #define SDP_SERVICE_CLASS_PRINTING_STATUS                   0x1123
199 #define SDP_SERVICE_CLASS_HUMAN_INTERFACE_DEVICE  0x1124
200 #define SDP_SERVICE_CLASS_HARDCOPY_CABLE_REPLACEMENT        0x1125
201 #define SDP_SERVICE_CLASS_HCR_PRINT                         0x1126
202 #define SDP_SERVICE_CLASS_HCR_SCAN                          0x1127
203 #define SDP_SERVICE_CLASS_COMMON_ISDN_ACCESS                0x1128
204 #define SDP_SERVICE_CLASS_VIDEO_CONFERENCING_GW             0x1129
205 #define SDP_SERVICE_CLASS_UDI_MT                            0x112A
206 #define SDP_SERVICE_CLASS_UDI_TA                            0x112B
207 #define SDP_SERVICE_CLASS_AUDIO_VIDEO                       0x112C
208 #define SDP_SERVICE_CLASS_SIM_ACCESS                        0x112D
209 #define SDP_SERVICE_CLASS_PNP_INFORMATION                   0x1200
210 #define SDP_SERVICE_CLASS_GENERIC_NETWORKING                0x1201
211 #define SDP_SERVICE_CLASS_GENERIC_FILE_TRANSFER             0x1202
212 #define SDP_SERVICE_CLASS_GENERIC_AUDIO                     0x1203
213 #define SDP_SERVICE_CLASS_GENERIC_TELEPHONY                 0x1204
214 #define SDP_SERVICE_CLASS_UPNP                                        0x1205
215 #define SDP_SERVICE_CLASS_UPNP_IP                           0x1206
216 #define SDP_SERVICE_CLASS_ESDP_UPNP_IP_PAN                  0x1300
217 #define SDP_SERVICE_CLASS_ESDP_UPNP_IP_LAP                  0x1301
218 #define SDP_SERVICE_CLASS_ESDP_UPNP_L2CAP                   0x1302
219 
220 /*
221  * Universal attribute definitions (page 366) and
222  * http://www.bluetoothsig.org/assigned-numbers/sdp.htm
223  */
224 
225 #define SDP_ATTR_RANGE(lo, hi) \
226           (uint32_t)(((uint16_t)(lo) << 16) | ((uint16_t)(hi)))
227 
228 #define SDP_ATTR_SERVICE_RECORD_HANDLE                      0x0000
229 #define SDP_ATTR_SERVICE_CLASS_ID_LIST                      0x0001
230 #define SDP_ATTR_SERVICE_RECORD_STATE                       0x0002
231 #define SDP_ATTR_SERVICE_ID                                 0x0003
232 #define SDP_ATTR_PROTOCOL_DESCRIPTOR_LIST                   0x0004
233 #define SDP_ATTR_BROWSE_GROUP_LIST                          0x0005
234 #define SDP_ATTR_LANGUAGE_BASE_ATTRIBUTE_ID_LIST  0x0006
235 #define SDP_ATTR_SERVICE_INFO_TIME_TO_LIVE                  0x0007
236 #define SDP_ATTR_SERVICE_AVAILABILITY                       0x0008
237 #define SDP_ATTR_BLUETOOTH_PROFILE_DESCRIPTOR_LIST          0x0009
238 #define SDP_ATTR_DOCUMENTATION_URL                          0x000A
239 #define SDP_ATTR_CLIENT_EXECUTABLE_URL                      0x000B
240 #define SDP_ATTR_ICON_URL                                   0x000C
241 #define SDP_ATTR_ADDITIONAL_PROTOCOL_DESCRIPTOR_LISTS       0x000D
242 #define SDP_ATTR_GROUP_ID                                   0x0200
243 #define SDP_ATTR_IP_SUBNET                                  0x0200
244 #define SDP_ATTR_VERSION_NUMBER_LIST                        0x0200
245 #define SDP_ATTR_SERVICE_DATABASE_STATE                     0x0201
246 #define SDP_ATTR_SERVICE_VERSION                            0x0300
247 #define SDP_ATTR_EXTERNAL_NETWORK                           0x0301
248 #define SDP_ATTR_NETWORK                                    0x0301
249 #define SDP_ATTR_SUPPORTED_DATA_STORES_LIST                 0x0301
250 #define SDP_ATTR_FAX_CLASS1_SUPPORT                         0x0302
251 #define SDP_ATTR_REMOTE_AUDIO_VOLUME_CONTROL                0x0302
252 #define SDP_ATTR_FAX_CLASS20_SUPPORT                        0x0303
253 #define SDP_ATTR_SUPPORTED_FORMATS_LIST                     0x0303
254 #define SDP_ATTR_FAX_CLASS2_SUPPORT                         0x0304
255 #define SDP_ATTR_AUDIO_FEEDBACK_SUPPORT                     0x0305
256 #define SDP_ATTR_NETWORK_ADDRESS                            0x0306
257 #define SDP_ATTR_WAP_GATEWAY                                0x0307
258 #define SDP_ATTR_HOME_PAGE_URL                                        0x0308
259 #define SDP_ATTR_WAP_STACK_TYPE                                       0x0309
260 #define SDP_ATTR_SECURITY_DESCRIPTION                       0x030A
261 #define SDP_ATTR_NET_ACCESS_TYPE                            0x030B
262 #define SDP_ATTR_MAX_NET_ACCESS_RATE                        0x030C
263 #define SDP_ATTR_IPV4_SUBNET                                0x030D
264 #define SDP_ATTR_IPV6_SUBNET                                0x030E
265 #define SDP_ATTR_SUPPORTED_CAPABALITIES                     0x0310
266 #define SDP_ATTR_SUPPORTED_FEATURES                         0x0311
267 #define SDP_ATTR_SUPPORTED_FUNCTIONS                        0x0312
268 #define SDP_ATTR_TOTAL_IMAGING_DATA_CAPACITY                0x0313
269 
270 /*
271  * The offset must be added to the attribute ID base (contained in the
272  * LANGUAGE_BASE_ATTRIBUTE_ID_LIST attribute) in order to compute the
273  * attribute ID for these attributes.
274  */
275 
276 #define SDP_ATTR_PRIMARY_LANGUAGE_BASE_ID                   0x0100
277 #define SDP_ATTR_SERVICE_NAME_OFFSET                        0x0000
278 #define SDP_ATTR_SERVICE_DESCRIPTION_OFFSET                 0x0001
279 #define SDP_ATTR_PROVIDER_NAME_OFFSET                       0x0002
280 
281 /*
282  * Protocol data unit (PDU) format (page 352)
283  */
284 
285 #define SDP_PDU_ERROR_RESPONSE                                        0x01
286 #define SDP_PDU_SERVICE_SEARCH_REQUEST                      0x02
287 #define SDP_PDU_SERVICE_SEARCH_RESPONSE                     0x03
288 #define SDP_PDU_SERVICE_ATTRIBUTE_REQUEST                   0x04
289 #define SDP_PDU_SERVICE_ATTRIBUTE_RESPONSE                  0x05
290 #define SDP_PDU_SERVICE_SEARCH_ATTRIBUTE_REQUEST  0x06
291 #define SDP_PDU_SERVICE_SEARCH_ATTRIBUTE_RESPONSE 0x07
292 
293 struct sdp_pdu {
294           uint8_t             pid;      /* PDU ID - SDP_PDU_xxx */
295           uint16_t  tid;      /* transaction ID */
296           uint16_t  len;      /* parameters length (in bytes) */
297 } __attribute__ ((packed));
298 typedef struct sdp_pdu                  sdp_pdu_t;
299 typedef struct sdp_pdu *      sdp_pdu_p;
300 
301 /*
302  * Error codes for SDP_PDU_ERROR_RESPONSE
303  */
304 
305 #define SDP_ERROR_CODE_INVALID_SDP_VERSION                  0x0001
306 #define SDP_ERROR_CODE_INVALID_SERVICE_RECORD_HANDLE        0x0002
307 #define SDP_ERROR_CODE_INVALID_REQUEST_SYNTAX               0x0003
308 #define SDP_ERROR_CODE_INVALID_PDU_SIZE                     0x0004
309 #define SDP_ERROR_CODE_INVALID_CONTINUATION_STATE 0x0005
310 #define SDP_ERROR_CODE_INSUFFICIENT_RESOURCES               0x0006
311 
312 /*
313  * SDP int128/uint128 parameter
314  */
315 
316 struct int128 {
317           int8_t    b[16];
318 };
319 typedef struct int128         int128_t;
320 typedef struct int128         uint128_t;
321 
322 /*
323  * SDP attribute
324  */
325 
326 struct sdp_attr {
327           uint16_t   flags;
328 #define SDP_ATTR_OK           (0 << 0)
329 #define SDP_ATTR_INVALID      (1 << 0)
330 #define SDP_ATTR_TRUNCATED    (1 << 1)
331           uint16_t   attr;  /* SDP_ATTR_xxx */
332           uint32_t   vlen;    /* length of the value[] in bytes */
333           uint8_t             *value;   /* base pointer */
334 };
335 typedef struct sdp_attr                 sdp_attr_t;
336 typedef struct sdp_attr *     sdp_attr_p;
337 
338 /******************************************************************************
339  * User interface
340  *****************************************************************************/
341 
342 /* Inline versions of get/put byte/short/long. Pointer is advanced */
343 #define SDP_GET8(b, cp)                 do {                          \
344           (b) = *(const uint8_t *)(cp);                     \
345           (cp) += sizeof(uint8_t);                          \
346 } while (/* CONSTCOND */0)
347 
348 #define SDP_GET16(s, cp)      do {                          \
349           (s) = be16dec(cp);                                \
350           (cp) += sizeof(uint16_t);                         \
351 } while (/* CONSTCOND */0)
352 
353 #define SDP_GET32(l, cp)      do {                          \
354           (l) = be32dec(cp);                                \
355           (cp) += sizeof(uint32_t);                         \
356 } while (/* CONSTCOND */0)
357 
358 #define SDP_GET64(l, cp)      do {                          \
359           (l) = be64dec(cp);                                \
360           (cp) += sizeof(uint64_t);                         \
361 } while (/* CONSTCOND */0)
362 
363 #if BYTE_ORDER == LITTLE_ENDIAN
364 #define SDP_GET128(l, cp)     do {                          \
365           const uint8_t *t_cp = (const uint8_t *)(cp);      \
366           (l)->b[15] = *t_cp++;                                       \
367           (l)->b[14] = *t_cp++;                                       \
368           (l)->b[13] = *t_cp++;                                       \
369           (l)->b[12] = *t_cp++;                                       \
370           (l)->b[11] = *t_cp++;                                       \
371           (l)->b[10] = *t_cp++;                                       \
372           (l)->b[9]  = *t_cp++;                                       \
373           (l)->b[8]  = *t_cp++;                                       \
374           (l)->b[7]  = *t_cp++;                                       \
375           (l)->b[6]  = *t_cp++;                                       \
376           (l)->b[5]  = *t_cp++;                                       \
377           (l)->b[4]  = *t_cp++;                                       \
378           (l)->b[3]  = *t_cp++;                                       \
379           (l)->b[2]  = *t_cp++;                                       \
380           (l)->b[1]  = *t_cp++;                                       \
381           (l)->b[0]  = *t_cp++;                                       \
382           (cp) += 16;                                                 \
383 } while (/* CONSTCOND */0)
384 
385 #define SDP_GET_UUID128(l, cp)          do {                          \
386           memcpy(&((l)->b), (cp), 16);                      \
387           (cp) += 16;                                                 \
388 } while (/* CONSTCOND */0)
389 #elif BYTE_ORDER == BIG_ENDIAN
390 #define SDP_GET128(l, cp)     do {                          \
391           memcpy(&((l)->b), (cp), 16);                      \
392           (cp) += 16;                                                 \
393 } while (/* CONSTCOND */0)
394 
395 #define   SDP_GET_UUID128(l, cp)        SDP_GET128(l, cp)
396 #else
397 #error    "Unsupported BYTE_ORDER"
398 #endif /* BYTE_ORDER */
399 
400 #define SDP_PUT8(b, cp)                 do {                          \
401           *(uint8_t *)(cp) = (b);                                     \
402           (cp) += sizeof(uint8_t);                          \
403 } while (/* CONSTCOND */0)
404 
405 #define SDP_PUT16(s, cp)      do {                          \
406           be16enc((cp), (s));                               \
407           (cp) += sizeof(uint16_t);                         \
408 } while (/* CONSTCOND */0)
409 
410 #define SDP_PUT32(s, cp)      do {                          \
411           be32enc((cp), (s));                               \
412           (cp) += sizeof(uint32_t);                         \
413 } while (/* CONSTCOND */0)
414 
415 #define SDP_PUT64(s, cp)      do {                          \
416           be64enc((cp), (s));                               \
417           (cp) += sizeof(uint64_t);                         \
418 } while (/* CONSTCOND */0)
419 
420 #if BYTE_ORDER == LITTLE_ENDIAN
421 #define SDP_PUT128(l, cp)     do {                          \
422           const uint8_t *t_cp = (const uint8_t *)(cp);      \
423           *t_cp++ = (l)->b[15];                                       \
424           *t_cp++ = (l)->b[14];                                       \
425           *t_cp++ = (l)->b[13];                                       \
426           *t_cp++ = (l)->b[12];                                       \
427           *t_cp++ = (l)->b[11];                                       \
428           *t_cp++ = (l)->b[10];                                       \
429           *t_cp++ = (l)->b[9];                                        \
430           *t_cp++ = (l)->b[8];                                        \
431           *t_cp++ = (l)->b[7];                                        \
432           *t_cp++ = (l)->b[6];                                        \
433           *t_cp++ = (l)->b[5];                                        \
434           *t_cp++ = (l)->b[4];                                        \
435           *t_cp++ = (l)->b[3];                                        \
436           *t_cp++ = (l)->b[2];                                        \
437           *t_cp++ = (l)->b[1];                                        \
438           *t_cp   = (l)->b[0];                                        \
439           (cp) += 16;                                                 \
440 } while (/* CONSTCOND */0)
441 
442 #define SDP_PUT_UUID128(l, cp)          do {                          \
443           memcpy((cp), &((l)->b), 16);                      \
444           (cp) += 16;                                                 \
445 } while (/* CONSTCOND */0)
446 #elif BYTE_ORDER == BIG_ENDIAN
447 #define SDP_PUT128(l, cp)     do {                          \
448           memcpy((cp), &((l)->b), 16);                      \
449           (cp) += 16;                                                 \
450 } while (/* CONSTCOND */0)
451 
452 #define SDP_PUT_UUID128(l, cp)          SDP_PUT128(l, cp)
453 #else
454 #error    "Unsupported BYTE_ORDER"
455 #endif /* BYTE_ORDER */
456 
457 void *             sdp_open       (bdaddr_t const *l, bdaddr_t const *r);
458 void *             sdp_open_local (char const *control);
459 int32_t            sdp_close      (void *xs);
460 int32_t            sdp_error      (void *xs);
461 
462 int32_t            sdp_search     (void *xs,
463                                    uint32_t plen, uint16_t const *pp,
464                                    uint32_t alen, uint32_t const *ap,
465                                    uint32_t vlen, sdp_attr_t *vp);
466 
467 char const *       sdp_attr2desc  (uint16_t attr);
468 char const *       sdp_uuid2desc  (uint16_t uuid);
469 void               sdp_print      (uint32_t level, uint8_t *start,
470                                    uint8_t const *end);
471 
472 /******************************************************************************
473  * sdpd interface and Bluetooth profiles data
474  *****************************************************************************/
475 
476 #define SDP_LOCAL_PATH        "/var/run/sdp"
477 #define SDP_LOCAL_MTU         4096
478 
479 /*
480  * These are NOT defined in spec and only accepted on control sockets.
481  * The response to these request always will be SDP_PDU_ERROR_RESPONSE.
482  * The first 2 bytes (after PDU header) is an error code (in network
483  * byte order). The rest of the data (pdu->len - 2) is a response data
484  * and depend on the request.
485  *
486  * SDP_PDU_SERVICE_REGISTER_REQUEST
487  *        pdu_header_t        hdr;
488  *        uint16_t  uuid;     service class UUID (network byte order)
489  *        bdaddr_t  bdaddr;   local BD_ADDR (or ANY)
490  *        profile data[pdu->len - sizeof(uuid) - sizeof(bdaddr)]
491  *
492  * in successful reponse additional data will contain 4 bytes record handle
493  *
494  *
495  * SDP_PDU_SERVICE_UNREGISTER_REQUEST
496  *        pdu_header_t        hdr;
497  *        uint32_t  record_handle;      (network byte order)
498  *
499  * no additional data in response.
500  *
501  *
502  * SDP_PDU_SERVICE_CHANGE_REQUEST
503  *        pdu_header_t        hdr;
504  *        uint32_t  record_handle;      (network byte order)
505  *        profile data[pdu->len - sizeof(record_handle)]
506  *
507  * no additional data in response.
508  */
509 
510 #define SDP_PDU_SERVICE_REGISTER_REQUEST          0x81
511 #define SDP_PDU_SERVICE_UNREGISTER_REQUEST        0x82
512 #define SDP_PDU_SERVICE_CHANGE_REQUEST            0x83
513 
514 struct sdp_dun_profile
515 {
516           uint8_t   server_channel;
517           uint8_t   audio_feedback_support;
518           uint8_t   reserved[2];
519 };
520 typedef struct sdp_dun_profile                    sdp_dun_profile_t;
521 typedef struct sdp_dun_profile *        sdp_dun_profile_p;
522 
523 struct sdp_ftrn_profile
524 {
525           uint8_t   server_channel;
526           uint8_t   reserved[3];
527 };
528 typedef struct sdp_ftrn_profile                   sdp_ftrn_profile_t;
529 typedef struct sdp_ftrn_profile *       sdp_ftrn_profile_p;
530 
531 struct sdp_hset_profile
532 {
533           uint8_t server_channel;
534           uint8_t   reserved[3];
535 };
536 typedef struct sdp_hset_profile                   sdp_hset_profile_t;
537 typedef struct sdp_hset_profile *       sdp_hset_profile_p;
538 
539 struct sdp_hf_profile
540 {
541           uint8_t server_channel;
542           uint16_t supported_features;
543 };
544 typedef struct sdp_hf_profile           sdp_hf_profile_t;
545 typedef struct sdp_hf_profile *                   sdp_hf_profile_p;
546 
547 /* Keep this in sync with sdp_opush_profile */
548 struct sdp_irmc_profile
549 {
550           uint8_t   server_channel;
551           uint8_t   supported_formats_size;
552           uint8_t   supported_formats[30];
553 };
554 typedef struct sdp_irmc_profile                   sdp_irmc_profile_t;
555 typedef struct sdp_irmc_profile *       sdp_irmc_profile_p;
556 
557 struct sdp_irmc_command_profile
558 {
559           uint8_t   server_channel;
560           uint8_t   reserved[3];
561 };
562 typedef struct sdp_irmc_command_profile           sdp_irmc_command_profile_t;
563 typedef struct sdp_irmc_command_profile *         sdp_irmc_command_profile_p;
564 
565 struct sdp_lan_profile
566 {
567           uint8_t             server_channel;
568           uint8_t             load_factor;
569           uint8_t             reserved;
570           uint8_t             ip_subnet_radius;
571           uint32_t  ip_subnet;
572 };
573 typedef struct sdp_lan_profile                    sdp_lan_profile_t;
574 typedef struct sdp_lan_profile *        sdp_lan_profile_p;
575 
576 /* Keep this in sync with sdp_irmc_profile */
577 struct sdp_opush_profile
578 {
579           uint8_t   server_channel;
580           uint8_t   supported_formats_size;
581           uint8_t   supported_formats[30];
582 };
583 typedef struct sdp_opush_profile        sdp_opush_profile_t;
584 typedef struct sdp_opush_profile *      sdp_opush_profile_p;
585 
586 struct sdp_sp_profile
587 {
588           uint8_t   server_channel;
589           uint8_t   reserved[3];
590 };
591 typedef struct sdp_sp_profile sdp_sp_profile_t;
592 typedef struct sdp_sp_profile *         sdp_sp_profile_p;
593 
594 int32_t   sdp_register_service          (void *xss, uint16_t uuid,
595                                          bdaddr_t *bdaddr, uint8_t *data,
596                                          uint32_t datalen, uint32_t *handle);
597 int32_t   sdp_unregister_service        (void *xss, uint32_t handle);
598 int32_t   sdp_change_service  (void *xss, uint32_t handle,
599                                          uint8_t *data, uint32_t datalen);
600 
601 __END_DECLS
602 
603 #endif /* ndef _SDP_H_ */
604