1121054Semax/*
2121054Semax * sdp.h
3121054Semax *
4121054Semax * Copyright (c) 2001-2003 Maksim Yevmenkin <m_evmenkin@yahoo.com>
5121054Semax * All rights reserved.
6121054Semax *
7121054Semax * Redistribution and use in source and binary forms, with or without
8121054Semax * modification, are permitted provided that the following conditions
9121054Semax * are met:
10121054Semax * 1. Redistributions of source code must retain the above copyright
11121054Semax *    notice, this list of conditions and the following disclaimer.
12121054Semax * 2. Redistributions in binary form must reproduce the above copyright
13121054Semax *    notice, this list of conditions and the following disclaimer in the
14121054Semax *    documentation and/or other materials provided with the distribution.
15121054Semax *
16121054Semax * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17121054Semax * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18121054Semax * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19121054Semax * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20121054Semax * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21121054Semax * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22121054Semax * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23121054Semax * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24121054Semax * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25121054Semax * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26121054Semax * SUCH DAMAGE.
27121054Semax *
28121054Semax * $Id: sdp.h,v 1.3 2003/09/05 00:33:59 max Exp $
29121054Semax * $FreeBSD: stable/10/lib/libsdp/sdp.h 343902 2019-02-08 10:28:13Z hselasky $
30121054Semax */
31121054Semax
32121054Semax#ifndef _SDP_H_
33121054Semax#define _SDP_H_
34121054Semax
35121054Semax__BEGIN_DECLS
36121054Semax
37121054Semax/*
38121054Semax * Data representation (page 349)
39121054Semax */
40121054Semax
41121054Semax/* Nil, the null type */
42121054Semax#define SDP_DATA_NIL					0x00
43121054Semax
44121054Semax/* Unsigned integer */
45121054Semax#define SDP_DATA_UINT8					0x08
46121054Semax#define SDP_DATA_UINT16					0x09
47121054Semax#define SDP_DATA_UINT32					0x0A
48121054Semax#define SDP_DATA_UINT64					0x0B
49121054Semax#define SDP_DATA_UINT128				0x0C
50121054Semax
51121054Semax/* Signed two's-complement integer */
52121054Semax#define SDP_DATA_INT8					0x10
53121054Semax#define SDP_DATA_INT16					0x11
54121054Semax#define SDP_DATA_INT32					0x12
55121054Semax#define SDP_DATA_INT64					0x13
56121054Semax#define SDP_DATA_INT128					0x14
57121054Semax
58121054Semax/* UUID, a universally unique identifier */
59121054Semax#define SDP_DATA_UUID16					0x19
60121054Semax#define SDP_DATA_UUID32					0x1A
61121054Semax#define SDP_DATA_UUID128				0x1C
62121054Semax
63121054Semax/* Text string */
64121054Semax#define SDP_DATA_STR8					0x25
65121054Semax#define SDP_DATA_STR16					0x26
66121054Semax#define SDP_DATA_STR32					0x27
67121054Semax
68121054Semax/* Boolean */
69121054Semax#define SDP_DATA_BOOL					0x28
70121054Semax
71121054Semax/*
72121054Semax * Data element sequence.
73121054Semax * A data element whose data field is a sequence of data elements
74121054Semax */
75121054Semax#define SDP_DATA_SEQ8					0x35
76121054Semax#define SDP_DATA_SEQ16					0x36
77121054Semax#define SDP_DATA_SEQ32					0x37
78121054Semax
79121054Semax/*
80121054Semax * Data element alternative.
81121054Semax * A data element whose data field is a sequence of data elements from
82121054Semax * which one data element is to be selected.
83121054Semax */
84121054Semax#define SDP_DATA_ALT8					0x3D
85121054Semax#define SDP_DATA_ALT16					0x3E
86121054Semax#define SDP_DATA_ALT32					0x3F
87121054Semax
88121054Semax/* URL, a uniform resource locator */
89121054Semax#define SDP_DATA_URL8					0x45
90121054Semax#define SDP_DATA_URL16					0x46
91121054Semax#define SDP_DATA_URL32					0x47
92121054Semax
93121054Semax/*
94161662Smarkus * Protocols UUID (short) https://www.bluetooth.org/assigned-numbers/service_discovery.php
95121054Semax * BASE UUID 00000000-0000-1000-8000-00805F9B34FB
96121054Semax */
97121054Semax
98121054Semax#define SDP_UUID_PROTOCOL_SDP				0x0001
99121054Semax#define SDP_UUID_PROTOCOL_UDP				0x0002
100121054Semax#define SDP_UUID_PROTOCOL_RFCOMM			0x0003
101121054Semax#define SDP_UUID_PROTOCOL_TCP				0x0004
102121054Semax#define SDP_UUID_PROTOCOL_TCS_BIN			0x0005
103121054Semax#define SDP_UUID_PROTOCOL_TCS_AT			0x0006
104121054Semax#define SDP_UUID_PROTOCOL_OBEX				0x0008
105121054Semax#define SDP_UUID_PROTOCOL_IP				0x0009
106121054Semax#define SDP_UUID_PROTOCOL_FTP				0x000A
107121054Semax#define SDP_UUID_PROTOCOL_HTTP				0x000C
108121054Semax#define SDP_UUID_PROTOCOL_WSP				0x000E
109121054Semax#define SDP_UUID_PROTOCOL_BNEP				0x000F
110121054Semax#define SDP_UUID_PROTOCOL_UPNP				0x0010
111121054Semax#define SDP_UUID_PROTOCOL_HIDP				0x0011
112121054Semax#define SDP_UUID_PROTOCOL_HARDCOPY_CONTROL_CHANNEL	0x0012
113121054Semax#define SDP_UUID_PROTOCOL_HARDCOPY_DATA_CHANNEL		0x0014
114121054Semax#define SDP_UUID_PROTOCOL_HARDCOPY_NOTIFICATION		0x0016
115121054Semax#define SDP_UUID_PROTOCOL_AVCTP				0x0017
116121054Semax#define SDP_UUID_PROTOCOL_AVDTP				0x0019
117121054Semax#define SDP_UUID_PROTOCOL_CMPT				0x001B
118121054Semax#define SDP_UUID_PROTOCOL_UDI_C_PLANE			0x001D
119121054Semax#define SDP_UUID_PROTOCOL_L2CAP				0x0100
120121054Semax
121121054Semax/*
122161662Smarkus * Service class IDs https://www.bluetooth.org/assigned-numbers/service_discovery.php
123121054Semax */
124121054Semax
125121054Semax#define SDP_SERVICE_CLASS_SERVICE_DISCOVERY_SERVER	0x1000
126121054Semax#define SDP_SERVICE_CLASS_BROWSE_GROUP_DESCRIPTOR	0x1001
127121054Semax#define SDP_SERVICE_CLASS_PUBLIC_BROWSE_GROUP		0x1002
128121054Semax#define SDP_SERVICE_CLASS_SERIAL_PORT			0x1101
129121054Semax#define SDP_SERVICE_CLASS_LAN_ACCESS_USING_PPP		0x1102
130121054Semax#define SDP_SERVICE_CLASS_DIALUP_NETWORKING		0x1103
131121054Semax#define SDP_SERVICE_CLASS_IR_MC_SYNC			0x1104
132121054Semax#define SDP_SERVICE_CLASS_OBEX_OBJECT_PUSH		0x1105
133121054Semax#define SDP_SERVICE_CLASS_OBEX_FILE_TRANSFER		0x1106
134121054Semax#define SDP_SERVICE_CLASS_IR_MC_SYNC_COMMAND		0x1107
135121054Semax#define SDP_SERVICE_CLASS_HEADSET			0x1108
136121054Semax#define SDP_SERVICE_CLASS_CORDLESS_TELEPHONY		0x1109
137121054Semax#define SDP_SERVICE_CLASS_AUDIO_SOURCE			0x110A
138121054Semax#define SDP_SERVICE_CLASS_AUDIO_SINK			0x110B
139121054Semax#define SDP_SERVICE_CLASS_AV_REMOTE_CONTROL_TARGET	0x110C
140121054Semax#define SDP_SERVICE_CLASS_ADVANCED_AUDIO_DISTRIBUTION	0x110D
141121054Semax#define SDP_SERVICE_CLASS_AV_REMOTE_CONTROL		0x110E
142121054Semax#define SDP_SERVICE_CLASS_VIDEO_CONFERENCING		0x110F
143121054Semax#define SDP_SERVICE_CLASS_INTERCOM			0x1110
144121054Semax#define SDP_SERVICE_CLASS_FAX				0x1111
145121054Semax#define SDP_SERVICE_CLASS_HEADSET_AUDIO_GATEWAY		0x1112
146121054Semax#define SDP_SERVICE_CLASS_WAP				0x1113
147121054Semax#define SDP_SERVICE_CLASS_WAP_CLIENT			0x1114
148121054Semax#define SDP_SERVICE_CLASS_PANU				0x1115
149121054Semax#define SDP_SERVICE_CLASS_NAP				0x1116
150121054Semax#define SDP_SERVICE_CLASS_GN				0x1117
151121054Semax#define SDP_SERVICE_CLASS_DIRECT_PRINTING		0x1118
152121054Semax#define SDP_SERVICE_CLASS_REFERENCE_PRINTING		0x1119
153121054Semax#define SDP_SERVICE_CLASS_IMAGING			0x111A
154121054Semax#define SDP_SERVICE_CLASS_IMAGING_RESPONDER		0x111B
155121054Semax#define SDP_SERVICE_CLASS_IMAGING_AUTOMATIC_ARCHIVE	0x111C
156121054Semax#define SDP_SERVICE_CLASS_IMAGING_REFERENCED_OBJECTS	0x111D
157121054Semax#define SDP_SERVICE_CLASS_HANDSFREE			0x111E
158121054Semax#define SDP_SERVICE_CLASS_HANDSFREE_AUDIO_GATEWAY	0x111F
159121054Semax#define SDP_SERVICE_CLASS_DIRECT_PRINTING_REFERENCE_OBJECTS	0x1120
160121054Semax#define SDP_SERVICE_CLASS_REFLECTED_UI			0x1121
161121054Semax#define SDP_SERVICE_CLASS_BASIC_PRINTING		0x1122
162121054Semax#define SDP_SERVICE_CLASS_PRINTING_STATUS		0x1123
163121054Semax#define SDP_SERVICE_CLASS_HUMAN_INTERFACE_DEVICE	0x1124
164121054Semax#define SDP_SERVICE_CLASS_HARDCOPY_CABLE_REPLACEMENT	0x1125
165121054Semax#define SDP_SERVICE_CLASS_HCR_PRINT			0x1126
166121054Semax#define SDP_SERVICE_CLASS_HCR_SCAN			0x1127
167121054Semax#define SDP_SERVICE_CLASS_COMMON_ISDN_ACCESS		0x1128
168121054Semax#define SDP_SERVICE_CLASS_VIDEO_CONFERENCING_GW		0x1129
169121054Semax#define SDP_SERVICE_CLASS_UDI_MT			0x112A
170121054Semax#define SDP_SERVICE_CLASS_UDI_TA			0x112B
171121054Semax#define SDP_SERVICE_CLASS_AUDIO_VIDEO			0x112C
172121054Semax#define SDP_SERVICE_CLASS_SIM_ACCESS			0x112D
173161662Smarkus#define SDP_SERVICE_CLASS_PHONEBOOK_ACCESS_PCE		0x112E
174161662Smarkus#define SDP_SERVICE_CLASS_PHONEBOOK_ACCESS_PSE		0x112F
175161662Smarkus#define SDP_SERVICE_CLASS_PHONEBOOK_ACCESS		0x1130
176121054Semax#define SDP_SERVICE_CLASS_PNP_INFORMATION		0x1200
177121054Semax#define SDP_SERVICE_CLASS_GENERIC_NETWORKING		0x1201
178121054Semax#define SDP_SERVICE_CLASS_GENERIC_FILE_TRANSFER		0x1202
179121054Semax#define SDP_SERVICE_CLASS_GENERIC_AUDIO			0x1203
180121054Semax#define SDP_SERVICE_CLASS_GENERIC_TELEPHONY		0x1204
181121054Semax#define SDP_SERVICE_CLASS_UPNP				0x1205
182121054Semax#define SDP_SERVICE_CLASS_UPNP_IP			0x1206
183121054Semax#define SDP_SERVICE_CLASS_ESDP_UPNP_IP_PAN		0x1300
184121054Semax#define SDP_SERVICE_CLASS_ESDP_UPNP_IP_LAP		0x1301
185121054Semax#define SDP_SERVICE_CLASS_ESDP_UPNP_L2CAP		0x1302
186161662Smarkus#define SDP_SERVICE_CLASS_VIDEO_SOURCE			0x1303
187161662Smarkus#define SDP_SERVICE_CLASS_VIDEO_SINK			0x1304
188161662Smarkus#define SDP_SERVICE_CLASS_VIDEO_DISTRIBUTION		0x1305
189121054Semax
190121054Semax/*
191121054Semax * Universal attribute definitions (page 366) and
192161662Smarkus * https://www.bluetooth.org/assigned-numbers/service_discovery.php
193121054Semax */
194121054Semax
195121054Semax#define SDP_ATTR_RANGE(lo, hi) \
196124305Semax	(uint32_t)(((uint16_t)(lo) << 16) | ((uint16_t)(hi)))
197121054Semax
198121054Semax#define SDP_ATTR_SERVICE_RECORD_HANDLE			0x0000
199121054Semax#define SDP_ATTR_SERVICE_CLASS_ID_LIST			0x0001
200121054Semax#define SDP_ATTR_SERVICE_RECORD_STATE			0x0002
201121054Semax#define SDP_ATTR_SERVICE_ID				0x0003
202121054Semax#define SDP_ATTR_PROTOCOL_DESCRIPTOR_LIST		0x0004
203121054Semax#define SDP_ATTR_BROWSE_GROUP_LIST			0x0005
204121054Semax#define SDP_ATTR_LANGUAGE_BASE_ATTRIBUTE_ID_LIST	0x0006
205121054Semax#define SDP_ATTR_SERVICE_INFO_TIME_TO_LIVE		0x0007
206121054Semax#define SDP_ATTR_SERVICE_AVAILABILITY			0x0008
207121054Semax#define SDP_ATTR_BLUETOOTH_PROFILE_DESCRIPTOR_LIST	0x0009
208121054Semax#define SDP_ATTR_DOCUMENTATION_URL			0x000A
209121054Semax#define SDP_ATTR_CLIENT_EXECUTABLE_URL			0x000B
210121054Semax#define SDP_ATTR_ICON_URL				0x000C
211121054Semax#define SDP_ATTR_ADDITIONAL_PROTOCOL_DESCRIPTOR_LISTS	0x000D
212121054Semax#define SDP_ATTR_GROUP_ID				0x0200
213121054Semax#define SDP_ATTR_IP_SUBNET				0x0200
214121054Semax#define SDP_ATTR_VERSION_NUMBER_LIST			0x0200
215121054Semax#define SDP_ATTR_SERVICE_DATABASE_STATE			0x0201
216121054Semax#define SDP_ATTR_SERVICE_VERSION			0x0300
217121054Semax#define SDP_ATTR_EXTERNAL_NETWORK			0x0301
218121054Semax#define SDP_ATTR_NETWORK				0x0301
219121054Semax#define SDP_ATTR_SUPPORTED_DATA_STORES_LIST		0x0301
220121054Semax#define SDP_ATTR_FAX_CLASS1_SUPPORT			0x0302
221121054Semax#define SDP_ATTR_REMOTE_AUDIO_VOLUME_CONTROL		0x0302
222121054Semax#define SDP_ATTR_FAX_CLASS20_SUPPORT			0x0303
223121054Semax#define SDP_ATTR_SUPPORTED_FORMATS_LIST			0x0303
224121054Semax#define SDP_ATTR_FAX_CLASS2_SUPPORT			0x0304
225121054Semax#define SDP_ATTR_AUDIO_FEEDBACK_SUPPORT			0x0305
226121054Semax#define SDP_ATTR_NETWORK_ADDRESS			0x0306
227121054Semax#define SDP_ATTR_WAP_GATEWAY				0x0307
228121054Semax#define SDP_ATTR_HOME_PAGE_URL				0x0308
229121054Semax#define SDP_ATTR_WAP_STACK_TYPE				0x0309
230121054Semax#define SDP_ATTR_SECURITY_DESCRIPTION			0x030A
231121054Semax#define SDP_ATTR_NET_ACCESS_TYPE			0x030B
232121054Semax#define SDP_ATTR_MAX_NET_ACCESS_RATE			0x030C
233121054Semax#define SDP_ATTR_IPV4_SUBNET				0x030D
234121054Semax#define SDP_ATTR_IPV6_SUBNET				0x030E
235121054Semax#define SDP_ATTR_SUPPORTED_CAPABALITIES			0x0310
236121054Semax#define SDP_ATTR_SUPPORTED_FEATURES			0x0311
237121054Semax#define SDP_ATTR_SUPPORTED_FUNCTIONS			0x0312
238121054Semax#define SDP_ATTR_TOTAL_IMAGING_DATA_CAPACITY		0x0313
239161662Smarkus#define SDP_ATTR_SUPPORTED_REPOSITORIES			0x0314
240121054Semax
241121054Semax/*
242121054Semax * The offset must be added to the attribute ID base (contained in the
243121054Semax * LANGUAGE_BASE_ATTRIBUTE_ID_LIST attribute) in order to compute the
244121054Semax * attribute ID for these attributes.
245121054Semax */
246121054Semax
247124305Semax#define SDP_ATTR_PRIMARY_LANGUAGE_BASE_ID		0x0100
248121054Semax#define SDP_ATTR_SERVICE_NAME_OFFSET			0x0000
249121054Semax#define SDP_ATTR_SERVICE_DESCRIPTION_OFFSET		0x0001
250121054Semax#define SDP_ATTR_PROVIDER_NAME_OFFSET			0x0002
251121054Semax
252121054Semax/*
253121054Semax * Protocol data unit (PDU) format (page 352)
254121054Semax */
255121054Semax
256121054Semax#define SDP_PDU_ERROR_RESPONSE				0x01
257121054Semax#define SDP_PDU_SERVICE_SEARCH_REQUEST			0x02
258121054Semax#define SDP_PDU_SERVICE_SEARCH_RESPONSE			0x03
259121054Semax#define SDP_PDU_SERVICE_ATTRIBUTE_REQUEST		0x04
260121054Semax#define SDP_PDU_SERVICE_ATTRIBUTE_RESPONSE		0x05
261121054Semax#define SDP_PDU_SERVICE_SEARCH_ATTRIBUTE_REQUEST	0x06
262121054Semax#define SDP_PDU_SERVICE_SEARCH_ATTRIBUTE_RESPONSE	0x07
263121054Semax
264121054Semaxstruct sdp_pdu {
265124305Semax	uint8_t		pid;	/* PDU ID - SDP_PDU_xxx */
266124305Semax	uint16_t	tid;	/* transaction ID */
267124305Semax	uint16_t	len;	/* parameters length (in bytes) */
268121054Semax} __attribute__ ((packed));
269121054Semaxtypedef struct sdp_pdu		sdp_pdu_t;
270121054Semaxtypedef struct sdp_pdu *	sdp_pdu_p;
271121054Semax
272121054Semax/*
273124305Semax * Error codes for SDP_PDU_ERROR_RESPONSE
274124305Semax */
275124305Semax
276124305Semax#define SDP_ERROR_CODE_INVALID_SDP_VERSION		0x0001
277124305Semax#define SDP_ERROR_CODE_INVALID_SERVICE_RECORD_HANDLE	0x0002
278124305Semax#define SDP_ERROR_CODE_INVALID_REQUEST_SYNTAX		0x0003
279124305Semax#define SDP_ERROR_CODE_INVALID_PDU_SIZE			0x0004
280124305Semax#define SDP_ERROR_CODE_INVALID_CONTINUATION_STATE	0x0005
281124305Semax#define SDP_ERROR_CODE_INSUFFICIENT_RESOURCES		0x0006
282124305Semax
283124305Semax/*
284121054Semax * SDP int128/uint128 parameter
285121054Semax */
286121054Semax
287121054Semaxstruct int128 {
288121054Semax	int8_t	b[16];
289121054Semax};
290121054Semaxtypedef struct int128	int128_t;
291124305Semaxtypedef struct int128	uint128_t;
292121054Semax
293121054Semax/*
294121054Semax * SDP attribute
295121054Semax */
296121054Semax
297121054Semaxstruct sdp_attr {
298124305Semax	uint16_t	 flags;
299121054Semax#define SDP_ATTR_OK		(0 << 0)
300121054Semax#define SDP_ATTR_INVALID	(1 << 0)
301121054Semax#define SDP_ATTR_TRUNCATED	(1 << 1)
302124305Semax	uint16_t	 attr;  /* SDP_ATTR_xxx */
303124305Semax	uint32_t	 vlen;	/* length of the value[] in bytes */
304124305Semax	uint8_t		*value;	/* base pointer */
305121054Semax};
306121054Semaxtypedef struct sdp_attr		sdp_attr_t;
307121054Semaxtypedef struct sdp_attr *	sdp_attr_p;
308121054Semax
309121054Semax/******************************************************************************
310121054Semax * User interface
311121054Semax *****************************************************************************/
312121054Semax
313121054Semax/* Inline versions of get/put byte/short/long. Pointer is advanced */
314121054Semax#define SDP_GET8(b, cp) { \
315226426Sed	const uint8_t *t_cp = (const uint8_t *)(cp); \
316121054Semax	(b) = *t_cp; \
317121054Semax	(cp) ++; \
318121054Semax}
319121054Semax
320121054Semax#define SDP_GET16(s, cp) { \
321226426Sed	const uint8_t *t_cp = (const uint8_t *)(cp); \
322124305Semax	(s) = ((uint16_t)t_cp[0] << 8) \
323124305Semax	    | ((uint16_t)t_cp[1]) \
324121054Semax	    ; \
325121054Semax	(cp) += 2; \
326121054Semax}
327121054Semax
328121054Semax#define SDP_GET32(l, cp) { \
329226426Sed	const uint8_t *t_cp = (const uint8_t *)(cp); \
330124305Semax	(l) = ((uint32_t)t_cp[0] << 24) \
331124305Semax	    | ((uint32_t)t_cp[1] << 16) \
332124305Semax	    | ((uint32_t)t_cp[2] << 8) \
333124305Semax	    | ((uint32_t)t_cp[3]) \
334121054Semax	    ; \
335121054Semax	(cp) += 4; \
336121054Semax}
337121054Semax
338121054Semax#define SDP_GET64(l, cp) { \
339124305Semax	register uint8_t *t_cp = (uint8_t *)(cp); \
340124305Semax	(l) = ((uint64_t)t_cp[0] << 56) \
341124305Semax	    | ((uint64_t)t_cp[1] << 48) \
342124305Semax	    | ((uint64_t)t_cp[2] << 40) \
343124305Semax	    | ((uint64_t)t_cp[3] << 32) \
344124305Semax	    | ((uint64_t)t_cp[4] << 24) \
345124305Semax	    | ((uint64_t)t_cp[5] << 16) \
346124305Semax	    | ((uint64_t)t_cp[6] << 8) \
347124305Semax	    | ((uint64_t)t_cp[7]) \
348121054Semax	    ; \
349121054Semax	(cp) += 8; \
350121054Semax}
351121054Semax
352121054Semax#if BYTE_ORDER == LITTLE_ENDIAN
353121054Semax#define SDP_GET128(l, cp) { \
354124305Semax	register uint8_t *t_cp = (uint8_t *)(cp); \
355121054Semax	(l)->b[15] = *t_cp++; \
356121054Semax	(l)->b[14] = *t_cp++; \
357121054Semax	(l)->b[13] = *t_cp++; \
358121054Semax	(l)->b[12] = *t_cp++; \
359121054Semax	(l)->b[11] = *t_cp++; \
360121054Semax	(l)->b[10] = *t_cp++; \
361121054Semax	(l)->b[9]  = *t_cp++; \
362121054Semax	(l)->b[8]  = *t_cp++; \
363121054Semax	(l)->b[7]  = *t_cp++; \
364121054Semax	(l)->b[6]  = *t_cp++; \
365121054Semax	(l)->b[5]  = *t_cp++; \
366121054Semax	(l)->b[4]  = *t_cp++; \
367121054Semax	(l)->b[3]  = *t_cp++; \
368121054Semax	(l)->b[2]  = *t_cp++; \
369121054Semax	(l)->b[1]  = *t_cp++; \
370146691Semax	(l)->b[0]  = *t_cp++; \
371121054Semax	(cp) += 16; \
372121054Semax}
373146691Semax
374146691Semax#define SDP_GET_UUID128(l, cp) { \
375146691Semax	register uint8_t *t_cp = (uint8_t *)(cp); \
376146691Semax	(l)->b[0]  = *t_cp++; \
377146691Semax	(l)->b[1]  = *t_cp++; \
378146691Semax	(l)->b[2]  = *t_cp++; \
379146691Semax	(l)->b[3]  = *t_cp++; \
380146691Semax	(l)->b[4]  = *t_cp++; \
381146691Semax	(l)->b[5]  = *t_cp++; \
382146691Semax	(l)->b[6]  = *t_cp++; \
383146691Semax	(l)->b[7]  = *t_cp++; \
384146691Semax	(l)->b[8]  = *t_cp++; \
385146691Semax	(l)->b[9]  = *t_cp++; \
386146691Semax	(l)->b[10] = *t_cp++; \
387146691Semax	(l)->b[11] = *t_cp++; \
388146691Semax	(l)->b[12] = *t_cp++; \
389146691Semax	(l)->b[13] = *t_cp++; \
390146691Semax	(l)->b[14] = *t_cp++; \
391146691Semax	(l)->b[15] = *t_cp++; \
392146691Semax	(cp) += 16; \
393146691Semax}
394146691Semax#elif BYTE_ORDER == BIG_ENDIAN
395121054Semax#define SDP_GET128(l, cp) { \
396124305Semax	register uint8_t *t_cp = (uint8_t *)(cp); \
397121054Semax	(l)->b[0]  = *t_cp++; \
398121054Semax	(l)->b[1]  = *t_cp++; \
399121054Semax	(l)->b[2]  = *t_cp++; \
400121054Semax	(l)->b[3]  = *t_cp++; \
401121054Semax	(l)->b[4]  = *t_cp++; \
402121054Semax	(l)->b[5]  = *t_cp++; \
403121054Semax	(l)->b[6]  = *t_cp++; \
404121054Semax	(l)->b[7]  = *t_cp++; \
405121054Semax	(l)->b[8]  = *t_cp++; \
406121054Semax	(l)->b[9]  = *t_cp++; \
407121054Semax	(l)->b[10] = *t_cp++; \
408121054Semax	(l)->b[11] = *t_cp++; \
409121054Semax	(l)->b[12] = *t_cp++; \
410121054Semax	(l)->b[13] = *t_cp++; \
411121054Semax	(l)->b[14] = *t_cp++; \
412121054Semax	(l)->b[15] = *t_cp++; \
413121054Semax	(cp) += 16; \
414121054Semax}
415146691Semax
416146691Semax#define	SDP_GET_UUID128(l, cp)	SDP_GET128(l, cp)
417146691Semax#else
418146691Semax#error	"Unsupported BYTE_ORDER"
419121054Semax#endif /* BYTE_ORDER */
420121054Semax
421121054Semax#define SDP_PUT8(b, cp) { \
422124305Semax	register uint8_t t_b = (uint8_t)(b); \
423124305Semax	register uint8_t *t_cp = (uint8_t *)(cp); \
424121054Semax	*t_cp = t_b; \
425121054Semax	(cp) ++; \
426121054Semax}
427121054Semax
428121054Semax#define SDP_PUT16(s, cp) { \
429124305Semax	register uint16_t t_s = (uint16_t)(s); \
430124305Semax	register uint8_t *t_cp = (uint8_t *)(cp); \
431121054Semax	*t_cp++ = t_s >> 8; \
432121054Semax	*t_cp   = t_s; \
433121054Semax	(cp) += 2; \
434121054Semax}
435121054Semax
436121054Semax#define SDP_PUT32(l, cp) { \
437124305Semax	register uint32_t t_l = (uint32_t)(l); \
438124305Semax	register uint8_t *t_cp = (uint8_t *)(cp); \
439121054Semax	*t_cp++ = t_l >> 24; \
440121054Semax	*t_cp++ = t_l >> 16; \
441121054Semax	*t_cp++ = t_l >> 8; \
442121054Semax	*t_cp   = t_l; \
443121054Semax	(cp) += 4; \
444121054Semax}
445121054Semax
446121054Semax#define SDP_PUT64(l, cp) { \
447124305Semax	register uint64_t t_l = (uint64_t)(l); \
448124305Semax	register uint8_t *t_cp = (uint8_t *)(cp); \
449121054Semax	*t_cp++ = t_l >> 56; \
450121054Semax	*t_cp++ = t_l >> 48; \
451121054Semax	*t_cp++ = t_l >> 40; \
452121054Semax	*t_cp++ = t_l >> 32; \
453121054Semax	*t_cp++ = t_l >> 24; \
454121054Semax	*t_cp++ = t_l >> 16; \
455121054Semax	*t_cp++ = t_l >> 8; \
456121054Semax	*t_cp   = t_l; \
457121054Semax	(cp) += 8; \
458121054Semax}
459121054Semax
460121054Semax#if BYTE_ORDER == LITTLE_ENDIAN
461121054Semax#define SDP_PUT128(l, cp) { \
462124305Semax	register uint8_t *t_cp = (uint8_t *)(cp); \
463121054Semax	*t_cp++ = (l)->b[15]; \
464121054Semax	*t_cp++ = (l)->b[14]; \
465121054Semax	*t_cp++ = (l)->b[13]; \
466121054Semax	*t_cp++ = (l)->b[12]; \
467121054Semax	*t_cp++ = (l)->b[11]; \
468121054Semax	*t_cp++ = (l)->b[10]; \
469121054Semax	*t_cp++ = (l)->b[9];  \
470121054Semax	*t_cp++ = (l)->b[8];  \
471121054Semax	*t_cp++ = (l)->b[7];  \
472121054Semax	*t_cp++ = (l)->b[6];  \
473121054Semax	*t_cp++ = (l)->b[5];  \
474121054Semax	*t_cp++ = (l)->b[4];  \
475121054Semax	*t_cp++ = (l)->b[3];  \
476121054Semax	*t_cp++ = (l)->b[2];  \
477121054Semax	*t_cp++ = (l)->b[1];  \
478121054Semax	*t_cp   = (l)->b[0];  \
479121054Semax	(cp) += 16; \
480121054Semax}
481146691Semax
482146691Semax#define SDP_PUT_UUID128(l, cp) { \
483146691Semax	register uint8_t *t_cp = (uint8_t *)(cp); \
484146691Semax	*t_cp++ = (l)->b[0];  \
485146691Semax	*t_cp++ = (l)->b[1];  \
486146691Semax	*t_cp++ = (l)->b[2];  \
487146691Semax	*t_cp++ = (l)->b[3];  \
488146691Semax	*t_cp++ = (l)->b[4];  \
489146691Semax	*t_cp++ = (l)->b[5];  \
490146691Semax	*t_cp++ = (l)->b[6];  \
491146691Semax	*t_cp++ = (l)->b[7];  \
492146691Semax	*t_cp++ = (l)->b[8];  \
493146691Semax	*t_cp++ = (l)->b[9];  \
494146691Semax	*t_cp++ = (l)->b[10]; \
495146691Semax	*t_cp++ = (l)->b[11]; \
496146691Semax	*t_cp++ = (l)->b[12]; \
497146691Semax	*t_cp++ = (l)->b[13]; \
498146691Semax	*t_cp++ = (l)->b[14]; \
499146691Semax	*t_cp   = (l)->b[15]; \
500146691Semax	(cp) += 16; \
501146691Semax}
502146691Semax#elif BYTE_ORDER == BIG_ENDIAN
503121054Semax#define SDP_PUT128(l, cp) { \
504124305Semax	register uint8_t *t_cp = (uint8_t *)(cp); \
505121054Semax	*t_cp++ = (l)->b[0];  \
506121054Semax	*t_cp++ = (l)->b[1];  \
507121054Semax	*t_cp++ = (l)->b[2];  \
508121054Semax	*t_cp++ = (l)->b[3];  \
509121054Semax	*t_cp++ = (l)->b[4];  \
510121054Semax	*t_cp++ = (l)->b[5];  \
511121054Semax	*t_cp++ = (l)->b[6];  \
512121054Semax	*t_cp++ = (l)->b[7];  \
513121054Semax	*t_cp++ = (l)->b[8];  \
514121054Semax	*t_cp++ = (l)->b[9];  \
515121054Semax	*t_cp++ = (l)->b[10]; \
516121054Semax	*t_cp++ = (l)->b[11]; \
517121054Semax	*t_cp++ = (l)->b[12]; \
518121054Semax	*t_cp++ = (l)->b[13]; \
519121054Semax	*t_cp++ = (l)->b[14]; \
520121054Semax	*t_cp   = (l)->b[15]; \
521121054Semax	(cp) += 16; \
522121054Semax}
523146691Semax
524146691Semax#define SDP_PUT_UUID128(l, cp)	SDP_PUT128(l, cp)
525146691Semax#else
526146691Semax#error	"Unsupported BYTE_ORDER"
527121054Semax#endif /* BYTE_ORDER */
528121054Semax
529121054Semaxvoid *             sdp_open       (bdaddr_t const *l, bdaddr_t const *r);
530124317Semaxvoid *             sdp_open_local (char const *control);
531121054Semaxint32_t            sdp_close      (void *xs);
532121054Semaxint32_t            sdp_error      (void *xs);
533121054Semax
534121054Semaxint32_t            sdp_search     (void *xs,
535124305Semax                                   uint32_t plen, uint16_t const *pp,
536124305Semax                                   uint32_t alen, uint32_t const *ap,
537124305Semax                                   uint32_t vlen, sdp_attr_t *vp);
538121054Semax
539159350Semaxchar const *	   sdp_attr2desc  (uint16_t attr);
540159350Semaxchar const *	   sdp_uuid2desc  (uint16_t uuid);
541124305Semaxvoid               sdp_print      (uint32_t level, uint8_t const *start,
542124305Semax                                   uint8_t const *end);
543121054Semax
544124305Semax/******************************************************************************
545124305Semax * sdpd interface and Bluetooth profiles data
546124305Semax *****************************************************************************/
547124305Semax
548124305Semax#define SDP_LOCAL_PATH	"/var/run/sdp"
549124305Semax#define SDP_LOCAL_MTU	4096
550124305Semax
551124758Semax/*
552124758Semax * These are NOT defined in spec and only accepted on control sockets.
553124758Semax * The response to these request always will be SDP_PDU_ERROR_RESPONSE.
554124758Semax * The first 2 bytes (after PDU header) is an error code (in network
555124758Semax * byte order). The rest of the data (pdu->len - 2) is a response data
556124758Semax * and depend on the request.
557124758Semax *
558124758Semax * SDP_PDU_SERVICE_REGISTER_REQUEST
559124758Semax * 	pdu_header_t	hdr;
560124758Semax *	u_int16_t	uuid;	service class UUID (network byte order)
561124758Semax *	bdaddr_t	bdaddr;	local BD_ADDR (or ANY)
562124758Semax *	profile data[pdu->len - sizeof(uuid) - sizeof(bdaddr)]
563124758Semax *
564124758Semax * in successful reponse additional data will contain 4 bytes record handle
565124758Semax *
566124758Semax *
567124758Semax * SDP_PDU_SERVICE_UNREGISTER_REQUEST
568124758Semax *	pdu_header_t	hdr;
569124758Semax *	u_int32_t	record_handle;	(network byte order)
570124758Semax *
571124758Semax * no additional data in response.
572124758Semax *
573124758Semax *
574124758Semax * SDP_PDU_SERVICE_CHANGE_REQUEST
575124758Semax * 	pdu_header_t	hdr;
576124758Semax *	u_int32_t	record_handle;	(network byte order)
577124758Semax *	profile data[pdu->len - sizeof(record_handle)]
578124758Semax *
579124758Semax * no additional data in response.
580124758Semax */
581124758Semax
582124758Semax#define SDP_PDU_SERVICE_REGISTER_REQUEST	0x81
583124758Semax#define SDP_PDU_SERVICE_UNREGISTER_REQUEST	0x82
584124758Semax#define SDP_PDU_SERVICE_CHANGE_REQUEST		0x83
585124758Semax
586343902Shselaskystruct sdp_audio_sink_profile
587343902Shselasky{
588343902Shselasky	uint16_t psm;
589343902Shselasky	uint16_t protover;
590343902Shselasky	uint16_t features;
591343902Shselasky};
592343902Shselaskytypedef struct sdp_audio_sink_profile	sdp_audio_sink_profile_t;
593343902Shselaskytypedef struct sdp_audio_sink_profile	*sdp_audio_sink_profile_p;
594343902Shselasky
595343902Shselaskystruct sdp_audio_source_profile
596343902Shselasky{
597343902Shselasky	uint16_t psm;
598343902Shselasky	uint16_t protover;
599343902Shselasky	uint16_t features;
600343902Shselasky};
601343902Shselaskytypedef struct sdp_audio_source_profile	sdp_audio_source_profile_t;
602343902Shselaskytypedef struct sdp_audio_source_profile *sdp_audio_source_profile_p;
603343902Shselasky
604124305Semaxstruct sdp_dun_profile
605124305Semax{
606124305Semax	uint8_t	server_channel;
607124305Semax	uint8_t	audio_feedback_support;
608124305Semax	uint8_t	reserved[2];
609124305Semax};
610124305Semaxtypedef struct sdp_dun_profile		sdp_dun_profile_t;
611124305Semaxtypedef struct sdp_dun_profile *	sdp_dun_profile_p;
612124305Semax
613124305Semaxstruct sdp_ftrn_profile
614124305Semax{
615124305Semax	uint8_t	server_channel;
616124305Semax	uint8_t	reserved[3];
617124305Semax};
618124305Semaxtypedef struct sdp_ftrn_profile		sdp_ftrn_profile_t;
619124305Semaxtypedef struct sdp_ftrn_profile *	sdp_ftrn_profile_p;
620124305Semax
621124758Semax/* Keep this in sync with sdp_opush_profile */
622124305Semaxstruct sdp_irmc_profile
623124305Semax{
624124305Semax	uint8_t	server_channel;
625124305Semax	uint8_t	supported_formats_size;
626124305Semax	uint8_t	supported_formats[30];
627124305Semax};
628124305Semaxtypedef struct sdp_irmc_profile		sdp_irmc_profile_t;
629124305Semaxtypedef struct sdp_irmc_profile *	sdp_irmc_profile_p;
630124305Semax
631124305Semaxstruct sdp_irmc_command_profile
632124305Semax{
633124305Semax	uint8_t	server_channel;
634124305Semax	uint8_t	reserved[3];
635124305Semax};
636124305Semaxtypedef struct sdp_irmc_command_profile		sdp_irmc_command_profile_t;
637124305Semaxtypedef struct sdp_irmc_command_profile *	sdp_irmc_command_profile_p;
638124305Semax
639124305Semaxstruct sdp_lan_profile
640124305Semax{
641124305Semax	uint8_t		server_channel;
642124305Semax	uint8_t		load_factor;
643124305Semax	uint8_t		reserved;
644124305Semax	uint8_t		ip_subnet_radius;
645124305Semax	uint32_t	ip_subnet;
646124305Semax};
647124305Semaxtypedef struct sdp_lan_profile		sdp_lan_profile_t;
648124305Semaxtypedef struct sdp_lan_profile *	sdp_lan_profile_p;
649124305Semax
650124758Semax/* Keep this in sync with sdp_irmc_profile */
651124305Semaxstruct sdp_opush_profile
652124305Semax{
653124305Semax	uint8_t	server_channel;
654124305Semax	uint8_t	supported_formats_size;
655124305Semax	uint8_t	supported_formats[30];
656124305Semax};
657124305Semaxtypedef struct sdp_opush_profile	sdp_opush_profile_t;
658124305Semaxtypedef struct sdp_opush_profile *	sdp_opush_profile_p;
659124305Semax
660124305Semaxstruct sdp_sp_profile
661124305Semax{
662124305Semax	uint8_t	server_channel;
663124305Semax	uint8_t	reserved[3];
664124305Semax};
665124305Semaxtypedef struct sdp_sp_profile	sdp_sp_profile_t;
666124305Semaxtypedef struct sdp_sp_profile *	sdp_sp_profile_p;
667124305Semax
668177044Semaxstruct sdp_nap_profile
669177044Semax{
670177358Semax	uint8_t		reserved;
671177358Semax	uint8_t		load_factor;
672177358Semax	uint16_t	psm;			/* HBO */
673177358Semax	uint16_t	security_description;	/* HBO */
674177358Semax	uint16_t	net_access_type;	/* HBO */
675177358Semax	uint32_t	max_net_access_rate;	/* HBO */
676177044Semax};
677177044Semaxtypedef struct sdp_nap_profile		sdp_nap_profile_t;
678177044Semaxtypedef struct sdp_nap_profile *	sdp_nap_profile_p;
679177044Semax
680177358Semaxstruct sdp_gn_profile
681177358Semax{
682177358Semax	uint8_t		reserved;
683177358Semax	uint8_t		load_factor;
684177358Semax	uint16_t	psm;			/* HBO */
685177358Semax	uint16_t	security_description;	/* HBO */
686177358Semax	uint16_t	reserved2;
687177358Semax};
688177358Semaxtypedef struct sdp_gn_profile		sdp_gn_profile_t;
689177358Semaxtypedef struct sdp_gn_profile *		sdp_gn_profile_p;
690177044Semax
691177358Semaxstruct sdp_panu_profile
692177358Semax{
693177358Semax	uint8_t		reserved;
694177358Semax	uint8_t		load_factor;
695177358Semax	uint16_t	psm;			/* HBO */
696177364Semax	uint16_t	security_description;	/* HBO */
697177364Semax	uint16_t	reserved2;
698177358Semax};
699177358Semaxtypedef struct sdp_panu_profile		sdp_panu_profile_t;
700177358Semaxtypedef struct sdp_panu_profile *	sdp_panu_profile_p;
701177044Semax
702124758Semaxint32_t	sdp_register_service	(void *xss, uint16_t uuid,
703124758Semax				 bdaddr_p const bdaddr, uint8_t const *data,
704124758Semax				 uint32_t datalen, uint32_t *handle);
705124758Semaxint32_t	sdp_unregister_service	(void *xss, uint32_t handle);
706124758Semaxint32_t	sdp_change_service	(void *xss, uint32_t handle,
707124758Semax				 uint8_t const *data, uint32_t datalen);
708124758Semax
709121054Semax__END_DECLS
710121054Semax
711121054Semax#endif /* ndef _SDP_H_ */
712121054Semax
713