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