xref: /netbsd-src/lib/libbluetooth/sdp_compat.c (revision 8ebedbbb875df9897951979cff3033060627aa4f)
1*8ebedbbbSplunky /*	$NetBSD: sdp_compat.c,v 1.2 2009/05/14 19:12:45 plunky Exp $	*/
2dfbf818aSplunky 
3dfbf818aSplunky /*-
4dfbf818aSplunky  * Copyright (c) 2006 Itronix Inc.
5dfbf818aSplunky  * All rights reserved.
6dfbf818aSplunky  *
7dfbf818aSplunky  * Written by Iain Hibbert for Itronix Inc.
8dfbf818aSplunky  *
9dfbf818aSplunky  * Redistribution and use in source and binary forms, with or without
10dfbf818aSplunky  * modification, are permitted provided that the following conditions
11dfbf818aSplunky  * are met:
12dfbf818aSplunky  * 1. Redistributions of source code must retain the above copyright
13dfbf818aSplunky  *    notice, this list of conditions and the following disclaimer.
14dfbf818aSplunky  * 2. Redistributions in binary form must reproduce the above copyright
15dfbf818aSplunky  *    notice, this list of conditions and the following disclaimer in the
16dfbf818aSplunky  *    documentation and/or other materials provided with the distribution.
17dfbf818aSplunky  * 3. The name of Itronix Inc. may not be used to endorse
18dfbf818aSplunky  *    or promote products derived from this software without specific
19dfbf818aSplunky  *    prior written permission.
20dfbf818aSplunky  *
21dfbf818aSplunky  * THIS SOFTWARE IS PROVIDED BY ITRONIX INC. ``AS IS'' AND
22dfbf818aSplunky  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23dfbf818aSplunky  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24dfbf818aSplunky  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL ITRONIX INC. BE LIABLE FOR ANY
25dfbf818aSplunky  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26dfbf818aSplunky  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27dfbf818aSplunky  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28dfbf818aSplunky  * ON ANY THEORY OF LIABILITY, WHETHER IN
29dfbf818aSplunky  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30dfbf818aSplunky  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31dfbf818aSplunky  * POSSIBILITY OF SUCH DAMAGE.
32dfbf818aSplunky  */
33dfbf818aSplunky /*-
34dfbf818aSplunky  * Copyright (c) 2001-2003 Maksim Yevmenkin <m_evmenkin@yahoo.com>
35dfbf818aSplunky  * All rights reserved.
36dfbf818aSplunky  *
37dfbf818aSplunky  * Redistribution and use in source and binary forms, with or without
38dfbf818aSplunky  * modification, are permitted provided that the following conditions
39dfbf818aSplunky  * are met:
40dfbf818aSplunky  * 1. Redistributions of source code must retain the above copyright
41dfbf818aSplunky  *    notice, this list of conditions and the following disclaimer.
42dfbf818aSplunky  * 2. Redistributions in binary form must reproduce the above copyright
43dfbf818aSplunky  *    notice, this list of conditions and the following disclaimer in the
44dfbf818aSplunky  *    documentation and/or other materials provided with the distribution.
45dfbf818aSplunky  *
46dfbf818aSplunky  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
47dfbf818aSplunky  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
48dfbf818aSplunky  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
49dfbf818aSplunky  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
50dfbf818aSplunky  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
51dfbf818aSplunky  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
52dfbf818aSplunky  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
53dfbf818aSplunky  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
54dfbf818aSplunky  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
55dfbf818aSplunky  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
56dfbf818aSplunky  * SUCH DAMAGE.
57dfbf818aSplunky  */
58dfbf818aSplunky 
59dfbf818aSplunky /*
60dfbf818aSplunky  * This file provides compatibility with the original library API,
61dfbf818aSplunky  * use -DSDP_COMPAT to access it.
62dfbf818aSplunky  *
63dfbf818aSplunky  * These functions are deprecated and will be removed eventually.
64dfbf818aSplunky  *
65dfbf818aSplunky  *	sdp_open(laddr, raddr)
66dfbf818aSplunky  *	sdp_open_local(control)
67dfbf818aSplunky  *	sdp_close(session)
68dfbf818aSplunky  *	sdp_error(session)
69dfbf818aSplunky  *	sdp_search(session, plen, protos, alen, attrs, vlen, values)
70dfbf818aSplunky  *	sdp_register_service(session, uuid, bdaddr, data, datalen, handle)
71dfbf818aSplunky  *	sdp_change_service(session, handle, data, datalen)
72dfbf818aSplunky  *	sdp_unregister_service(session, handle)
73dfbf818aSplunky  *	sdp_attr2desc(attribute)
74dfbf818aSplunky  *	sdp_uuid2desc(uuid16)
75dfbf818aSplunky  *	sdp_print(level, start, end)
76dfbf818aSplunky  */
77dfbf818aSplunky #define SDP_COMPAT
78dfbf818aSplunky 
79dfbf818aSplunky #include <sys/cdefs.h>
80*8ebedbbbSplunky __RCSID("$NetBSD: sdp_compat.c,v 1.2 2009/05/14 19:12:45 plunky Exp $");
81dfbf818aSplunky 
82dfbf818aSplunky #include <errno.h>
83dfbf818aSplunky #include <sdp.h>
84dfbf818aSplunky #include <stdlib.h>
85dfbf818aSplunky #include <string.h>
86dfbf818aSplunky #include <unistd.h>
87dfbf818aSplunky 
88dfbf818aSplunky #include "sdp-int.h"
89dfbf818aSplunky 
90dfbf818aSplunky struct sdp_compat {
91dfbf818aSplunky 	sdp_session_t	ss;
92dfbf818aSplunky 	int		error;
93dfbf818aSplunky 	uint8_t		buf[256];
94dfbf818aSplunky };
95dfbf818aSplunky 
96dfbf818aSplunky void *
sdp_open(bdaddr_t const * l,bdaddr_t const * r)97dfbf818aSplunky sdp_open(bdaddr_t const *l, bdaddr_t const *r)
98dfbf818aSplunky {
99dfbf818aSplunky 	struct sdp_compat *sc;
100dfbf818aSplunky 
101dfbf818aSplunky 	sc = malloc(sizeof(struct sdp_compat));
102dfbf818aSplunky 	if (sc == NULL)
103dfbf818aSplunky 		return NULL;
104dfbf818aSplunky 
105dfbf818aSplunky 	if (l == NULL || r == NULL) {
106dfbf818aSplunky 		sc->error = EINVAL;
107dfbf818aSplunky 		return sc;
108dfbf818aSplunky 	}
109dfbf818aSplunky 
110dfbf818aSplunky 	sc->ss = _sdp_open(l, r);
111dfbf818aSplunky 	if (sc->ss == NULL) {
112dfbf818aSplunky 		sc->error = errno;
113dfbf818aSplunky 		return sc;
114dfbf818aSplunky 	}
115dfbf818aSplunky 
116dfbf818aSplunky 	sc->error = 0;
117dfbf818aSplunky 	return sc;
118dfbf818aSplunky }
119dfbf818aSplunky 
120dfbf818aSplunky void *
sdp_open_local(char const * control)121dfbf818aSplunky sdp_open_local(char const *control)
122dfbf818aSplunky {
123dfbf818aSplunky 	struct sdp_compat *sc;
124dfbf818aSplunky 
125dfbf818aSplunky 	sc = malloc(sizeof(struct sdp_compat));
126dfbf818aSplunky 	if (sc == NULL)
127dfbf818aSplunky 		return NULL;
128dfbf818aSplunky 
129dfbf818aSplunky 	sc->ss = _sdp_open_local(control);
130dfbf818aSplunky 	if (sc->ss == NULL) {
131dfbf818aSplunky 		sc->error = errno;
132dfbf818aSplunky 		return sc;
133dfbf818aSplunky 	}
134dfbf818aSplunky 
135dfbf818aSplunky 	sc->error = 0;
136dfbf818aSplunky 	return sc;
137dfbf818aSplunky }
138dfbf818aSplunky 
139dfbf818aSplunky int32_t
sdp_close(void * xss)140dfbf818aSplunky sdp_close(void *xss)
141dfbf818aSplunky {
142dfbf818aSplunky 	struct sdp_compat *sc = xss;
143dfbf818aSplunky 
144dfbf818aSplunky 	if (sc == NULL)
145dfbf818aSplunky 		return 0;
146dfbf818aSplunky 
147dfbf818aSplunky 	if (sc->ss != NULL)
148dfbf818aSplunky 		_sdp_close(sc->ss);
149dfbf818aSplunky 
150dfbf818aSplunky 	free(sc);
151dfbf818aSplunky 
152dfbf818aSplunky 	return 0;
153dfbf818aSplunky }
154dfbf818aSplunky 
155dfbf818aSplunky int32_t
sdp_error(void * xss)156dfbf818aSplunky sdp_error(void *xss)
157dfbf818aSplunky {
158dfbf818aSplunky 	struct sdp_compat *sc = xss;
159dfbf818aSplunky 
160dfbf818aSplunky 	if (sc == NULL)
161dfbf818aSplunky 		return EINVAL;
162dfbf818aSplunky 
163dfbf818aSplunky 	return sc->error;
164dfbf818aSplunky }
165dfbf818aSplunky 
166dfbf818aSplunky int32_t
sdp_search(void * xss,uint32_t plen,uint16_t const * pp,uint32_t alen,uint32_t const * ap,uint32_t vlen,sdp_attr_t * vp)167dfbf818aSplunky sdp_search(void *xss, uint32_t plen, uint16_t const *pp, uint32_t alen,
168dfbf818aSplunky     uint32_t const *ap, uint32_t vlen, sdp_attr_t *vp)
169dfbf818aSplunky {
170dfbf818aSplunky 	struct sdp_compat *sc = xss;
171dfbf818aSplunky 	sdp_data_t seq, ssp, ail, rsp, value;
172dfbf818aSplunky 	uint16_t attr;
173*8ebedbbbSplunky 	size_t i;
174dfbf818aSplunky 	bool rv;
175dfbf818aSplunky 
176dfbf818aSplunky 	if (sc == NULL)
177dfbf818aSplunky 		return -1;
178dfbf818aSplunky 
179dfbf818aSplunky 	if (plen == 0 || pp == NULL || alen == 0 || ap == NULL) {
180dfbf818aSplunky 		sc->error = EINVAL;
181dfbf818aSplunky 		return -1;
182dfbf818aSplunky 	}
183dfbf818aSplunky 
184dfbf818aSplunky 	/*
185dfbf818aSplunky 	 * encode ServiceSearchPattern
186dfbf818aSplunky 	 */
187dfbf818aSplunky 	ssp.next = sc->buf;
188dfbf818aSplunky 	ssp.end = sc->buf + sizeof(sc->buf);
189dfbf818aSplunky 	for (i = 0; i < plen; i++)
190dfbf818aSplunky 		sdp_put_uuid16(&ssp, pp[i]);
191dfbf818aSplunky 
192dfbf818aSplunky 	ssp.end = ssp.next;
193dfbf818aSplunky 	ssp.next = sc->buf;
194dfbf818aSplunky 
195dfbf818aSplunky 	/*
196dfbf818aSplunky 	 * encode AttributeIDList
197dfbf818aSplunky 	 */
198dfbf818aSplunky 	ail.next = ssp.end;
199dfbf818aSplunky 	ail.end = sc->buf + sizeof(sc->buf);
200dfbf818aSplunky 	for (i = 0; i < alen; i++)
201dfbf818aSplunky 		sdp_put_uint32(&ail, ap[i]);
202dfbf818aSplunky 
203dfbf818aSplunky 	ail.end = ail.next;
204dfbf818aSplunky 	ail.next = ssp.end;
205dfbf818aSplunky 
206dfbf818aSplunky 	/*
207dfbf818aSplunky 	 * perform ServiceSearchAttribute transaction
208dfbf818aSplunky 	 */
209dfbf818aSplunky 	rv = sdp_service_search_attribute(sc->ss, &ssp, &ail, &rsp);
210dfbf818aSplunky 	if (rv == false) {
211dfbf818aSplunky 		sc->error = errno;
212dfbf818aSplunky 		return -1;
213dfbf818aSplunky 	}
214dfbf818aSplunky 
215dfbf818aSplunky 	if (vp == NULL)
216dfbf818aSplunky 		return 0;
217dfbf818aSplunky 
218dfbf818aSplunky 	/*
219dfbf818aSplunky 	 * The response buffer is a list of data element sequences,
220dfbf818aSplunky 	 * each containing a list of attribute/value pairs. We want to
221dfbf818aSplunky 	 * parse those to the attribute array that the user passed in.
222dfbf818aSplunky 	 */
223dfbf818aSplunky 	while (vlen > 0 && sdp_get_seq(&rsp, &seq)) {
224dfbf818aSplunky 		while (vlen > 0 && sdp_get_attr(&seq, &attr, &value)) {
225dfbf818aSplunky 			vp->attr = attr;
226dfbf818aSplunky 			if (vp->value != NULL) {
227*8ebedbbbSplunky 				if (value.end - value.next > (ssize_t)vp->vlen) {
228dfbf818aSplunky 					vp->flags = SDP_ATTR_TRUNCATED;
229dfbf818aSplunky 				} else {
230dfbf818aSplunky 					vp->flags = SDP_ATTR_OK;
231dfbf818aSplunky 					vp->vlen = value.end - value.next;
232dfbf818aSplunky 				}
233dfbf818aSplunky 				memcpy(vp->value, value.next, vp->vlen);
234dfbf818aSplunky 			} else {
235dfbf818aSplunky 				vp->flags = SDP_ATTR_INVALID;
236dfbf818aSplunky 			}
237dfbf818aSplunky 
238dfbf818aSplunky 			vp++;
239dfbf818aSplunky 			vlen--;
240dfbf818aSplunky 		}
241dfbf818aSplunky 	}
242dfbf818aSplunky 
243dfbf818aSplunky 	while (vlen-- > 0)
244dfbf818aSplunky 		vp++->flags = SDP_ATTR_INVALID;
245dfbf818aSplunky 
246dfbf818aSplunky 	return 0;
247dfbf818aSplunky }
248dfbf818aSplunky 
249dfbf818aSplunky int32_t
sdp_register_service(void * xss,uint16_t uuid,bdaddr_t * bdaddr,uint8_t * data,uint32_t datalen,uint32_t * handle)250dfbf818aSplunky sdp_register_service(void *xss, uint16_t uuid, bdaddr_t *bdaddr,
251dfbf818aSplunky     uint8_t *data, uint32_t datalen, uint32_t *handle)
252dfbf818aSplunky {
253dfbf818aSplunky 	struct sdp_compat *sc = xss;
254dfbf818aSplunky 	struct iovec req[4];
255dfbf818aSplunky 	ssize_t len;
256dfbf818aSplunky 
257dfbf818aSplunky 	if (sc == NULL)
258dfbf818aSplunky 		return -1;
259dfbf818aSplunky 
260dfbf818aSplunky 	if (bdaddr == NULL || data == NULL || datalen == 0) {
261dfbf818aSplunky 		sc->error = EINVAL;
262dfbf818aSplunky 		return -1;
263dfbf818aSplunky 	}
264dfbf818aSplunky 
265dfbf818aSplunky 	uuid = htobe16(uuid);
266dfbf818aSplunky 	req[1].iov_base = &uuid;
267dfbf818aSplunky 	req[1].iov_len = sizeof(uint16_t);
268dfbf818aSplunky 
269dfbf818aSplunky 	req[2].iov_base = bdaddr;
270dfbf818aSplunky 	req[2].iov_len = sizeof(bdaddr_t);
271dfbf818aSplunky 
272dfbf818aSplunky 	req[3].iov_base = data;
273dfbf818aSplunky 	req[3].iov_len = datalen;
274dfbf818aSplunky 
275dfbf818aSplunky 	if (!_sdp_send_pdu(sc->ss, SDP_PDU_SERVICE_REGISTER_REQUEST,
276dfbf818aSplunky 	    req, __arraycount(req))) {
277dfbf818aSplunky 		sc->error = errno;
278dfbf818aSplunky 		return -1;
279dfbf818aSplunky 	}
280dfbf818aSplunky 
281dfbf818aSplunky 	len = _sdp_recv_pdu(sc->ss, SDP_PDU_ERROR_RESPONSE);
282dfbf818aSplunky 	if (len == -1) {
283dfbf818aSplunky 		sc->error = errno;
284dfbf818aSplunky 		return -1;
285dfbf818aSplunky 	}
286dfbf818aSplunky 
287dfbf818aSplunky 	if (len != sizeof(uint16_t) + sizeof(uint32_t)
288dfbf818aSplunky 	    || be16dec(sc->ss->ibuf) != 0) {
289dfbf818aSplunky 		sc->error = EIO;
290dfbf818aSplunky 		return -1;
291dfbf818aSplunky 	}
292dfbf818aSplunky 
293dfbf818aSplunky 	if (handle != NULL)
294dfbf818aSplunky 		*handle = be32dec(sc->ss->ibuf + sizeof(uint16_t));
295dfbf818aSplunky 
296dfbf818aSplunky 	return 0;
297dfbf818aSplunky }
298dfbf818aSplunky 
299dfbf818aSplunky int32_t
sdp_change_service(void * xss,uint32_t handle,uint8_t * data,uint32_t datalen)300dfbf818aSplunky sdp_change_service(void *xss, uint32_t handle,
301dfbf818aSplunky     uint8_t *data, uint32_t datalen)
302dfbf818aSplunky {
303dfbf818aSplunky 	struct sdp_compat *sc = xss;
304dfbf818aSplunky 	struct iovec req[3];
305dfbf818aSplunky 	ssize_t len;
306dfbf818aSplunky 
307dfbf818aSplunky 	if (data == NULL || datalen == 0) {
308dfbf818aSplunky 		sc->error = EINVAL;
309dfbf818aSplunky 		return -1;
310dfbf818aSplunky 	}
311dfbf818aSplunky 
312dfbf818aSplunky 	handle = htobe32(handle);
313dfbf818aSplunky 	req[1].iov_base = &handle;
314dfbf818aSplunky 	req[1].iov_len = sizeof(uint32_t);
315dfbf818aSplunky 
316dfbf818aSplunky 	req[2].iov_base = data;
317dfbf818aSplunky 	req[2].iov_len = datalen;
318dfbf818aSplunky 
319dfbf818aSplunky 	if (!_sdp_send_pdu(sc->ss, SDP_PDU_SERVICE_CHANGE_REQUEST,
320dfbf818aSplunky 	    req, __arraycount(req))) {
321dfbf818aSplunky 		sc->error = errno;
322dfbf818aSplunky 		return -1;
323dfbf818aSplunky 	}
324dfbf818aSplunky 
325dfbf818aSplunky 	len = _sdp_recv_pdu(sc->ss, SDP_PDU_ERROR_RESPONSE);
326dfbf818aSplunky 	if (len == -1) {
327dfbf818aSplunky 		sc->error = errno;
328dfbf818aSplunky 		return -1;
329dfbf818aSplunky 	}
330dfbf818aSplunky 
331dfbf818aSplunky 	if (len != sizeof(uint16_t)
332dfbf818aSplunky 	    || be16dec(sc->ss->ibuf) != 0) {
333dfbf818aSplunky 		sc->error = EIO;
334dfbf818aSplunky 		return -1;
335dfbf818aSplunky 	}
336dfbf818aSplunky 
337dfbf818aSplunky 	return 0;
338dfbf818aSplunky }
339dfbf818aSplunky 
340dfbf818aSplunky int32_t
sdp_unregister_service(void * xss,uint32_t handle)341dfbf818aSplunky sdp_unregister_service(void *xss, uint32_t handle)
342dfbf818aSplunky {
343dfbf818aSplunky 	struct sdp_compat *sc = xss;
344dfbf818aSplunky 	struct iovec req[2];
345dfbf818aSplunky 	ssize_t len;
346dfbf818aSplunky 
347dfbf818aSplunky 	handle = htobe32(handle);
348dfbf818aSplunky 	req[1].iov_base = &handle;
349dfbf818aSplunky 	req[1].iov_len = sizeof(uint32_t);
350dfbf818aSplunky 
351dfbf818aSplunky 	if (!_sdp_send_pdu(sc->ss, SDP_PDU_SERVICE_UNREGISTER_REQUEST,
352dfbf818aSplunky 	    req, __arraycount(req))) {
353dfbf818aSplunky 		sc->error = errno;
354dfbf818aSplunky 		return -1;
355dfbf818aSplunky 	}
356dfbf818aSplunky 
357dfbf818aSplunky 	len = _sdp_recv_pdu(sc->ss, SDP_PDU_ERROR_RESPONSE);
358dfbf818aSplunky 	if (len == -1) {
359dfbf818aSplunky 		sc->error = errno;
360dfbf818aSplunky 		return -1;
361dfbf818aSplunky 	}
362dfbf818aSplunky 
363dfbf818aSplunky 	if (len != sizeof(uint16_t)
364dfbf818aSplunky 	    || be16dec(sc->ss->ibuf) != 0) {
365dfbf818aSplunky 		sc->error = EIO;
366dfbf818aSplunky 		return -1;
367dfbf818aSplunky 	}
368dfbf818aSplunky 
369dfbf818aSplunky 	return 0;
370dfbf818aSplunky }
371dfbf818aSplunky 
372dfbf818aSplunky /*
373dfbf818aSplunky  * SDP attribute description
374dfbf818aSplunky  */
375dfbf818aSplunky 
376dfbf818aSplunky struct sdp_attr_desc {
377dfbf818aSplunky 	uint32_t	 attr;
378dfbf818aSplunky 	char const	*desc;
379dfbf818aSplunky };
380dfbf818aSplunky typedef struct sdp_attr_desc	sdp_attr_desc_t;
381dfbf818aSplunky typedef struct sdp_attr_desc *	sdp_attr_desc_p;
382dfbf818aSplunky 
383dfbf818aSplunky static sdp_attr_desc_t	sdp_uuids_desc[] = {
384dfbf818aSplunky { SDP_UUID_PROTOCOL_SDP, "SDP", },
385dfbf818aSplunky { SDP_UUID_PROTOCOL_UDP, "UDP", },
386dfbf818aSplunky { SDP_UUID_PROTOCOL_RFCOMM, "RFCOMM", },
387dfbf818aSplunky { SDP_UUID_PROTOCOL_TCP, "TCP", },
388dfbf818aSplunky { SDP_UUID_PROTOCOL_TCS_BIN, "TCS BIN", },
389dfbf818aSplunky { SDP_UUID_PROTOCOL_TCS_AT, "TCS AT", },
390dfbf818aSplunky { SDP_UUID_PROTOCOL_OBEX, "OBEX", },
391dfbf818aSplunky { SDP_UUID_PROTOCOL_IP, "IP", },
392dfbf818aSplunky { SDP_UUID_PROTOCOL_FTP, "FTP", },
393dfbf818aSplunky { SDP_UUID_PROTOCOL_HTTP, "HTTP", },
394dfbf818aSplunky { SDP_UUID_PROTOCOL_WSP, "WSP", },
395dfbf818aSplunky { SDP_UUID_PROTOCOL_BNEP, "BNEP", },
396dfbf818aSplunky { SDP_UUID_PROTOCOL_UPNP, "UPNP", },
397dfbf818aSplunky { SDP_UUID_PROTOCOL_HIDP, "HIDP", },
398dfbf818aSplunky { SDP_UUID_PROTOCOL_HARDCOPY_CONTROL_CHANNEL, "Hardcopy Control Channel", },
399dfbf818aSplunky { SDP_UUID_PROTOCOL_HARDCOPY_DATA_CHANNEL, "Hardcopy Data Channel", },
400dfbf818aSplunky { SDP_UUID_PROTOCOL_HARDCOPY_NOTIFICATION, "Hardcopy Notification", },
401dfbf818aSplunky { SDP_UUID_PROTOCOL_AVCTP, "AVCTP", },
402dfbf818aSplunky { SDP_UUID_PROTOCOL_AVDTP, "AVDTP", },
403dfbf818aSplunky { SDP_UUID_PROTOCOL_CMPT, "CMPT", },
404dfbf818aSplunky { SDP_UUID_PROTOCOL_UDI_C_PLANE, "UDI C-Plane", },
405dfbf818aSplunky { SDP_UUID_PROTOCOL_L2CAP, "L2CAP", },
406dfbf818aSplunky /* Service Class IDs/Bluetooth Profile IDs */
407dfbf818aSplunky { SDP_SERVICE_CLASS_SERVICE_DISCOVERY_SERVER, "Service Discovery Server", },
408dfbf818aSplunky { SDP_SERVICE_CLASS_BROWSE_GROUP_DESCRIPTOR, "Browse Group Descriptor", },
409dfbf818aSplunky { SDP_SERVICE_CLASS_PUBLIC_BROWSE_GROUP, "Public Browse Group", },
410dfbf818aSplunky { SDP_SERVICE_CLASS_SERIAL_PORT, "Serial Port", },
411dfbf818aSplunky { SDP_SERVICE_CLASS_LAN_ACCESS_USING_PPP, "LAN Access Using PPP", },
412dfbf818aSplunky { SDP_SERVICE_CLASS_DIALUP_NETWORKING, "Dial-Up Networking", },
413dfbf818aSplunky { SDP_SERVICE_CLASS_IR_MC_SYNC, "IrMC Sync", },
414dfbf818aSplunky { SDP_SERVICE_CLASS_OBEX_OBJECT_PUSH, "OBEX Object Push", },
415dfbf818aSplunky { SDP_SERVICE_CLASS_OBEX_FILE_TRANSFER, "OBEX File Transfer", },
416dfbf818aSplunky { SDP_SERVICE_CLASS_IR_MC_SYNC_COMMAND, "IrMC Sync Command", },
417dfbf818aSplunky { SDP_SERVICE_CLASS_HEADSET, "Headset", },
418dfbf818aSplunky { SDP_SERVICE_CLASS_CORDLESS_TELEPHONY, "Cordless Telephony", },
419dfbf818aSplunky { SDP_SERVICE_CLASS_AUDIO_SOURCE, "Audio Source", },
420dfbf818aSplunky { SDP_SERVICE_CLASS_AUDIO_SINK, "Audio Sink", },
421dfbf818aSplunky { SDP_SERVICE_CLASS_AV_REMOTE_CONTROL_TARGET, "A/V Remote Control Target", },
422dfbf818aSplunky { SDP_SERVICE_CLASS_ADVANCED_AUDIO_DISTRIBUTION, "Advanced Audio Distribution", },
423dfbf818aSplunky { SDP_SERVICE_CLASS_AV_REMOTE_CONTROL, "A/V Remote Control", },
424dfbf818aSplunky { SDP_SERVICE_CLASS_VIDEO_CONFERENCING, "Video Conferencing", },
425dfbf818aSplunky { SDP_SERVICE_CLASS_INTERCOM, "Intercom", },
426dfbf818aSplunky { SDP_SERVICE_CLASS_FAX, "Fax", },
427dfbf818aSplunky { SDP_SERVICE_CLASS_HEADSET_AUDIO_GATEWAY, "Headset Audio Gateway", },
428dfbf818aSplunky { SDP_SERVICE_CLASS_WAP, "WAP", },
429dfbf818aSplunky { SDP_SERVICE_CLASS_WAP_CLIENT, "WAP Client", },
430dfbf818aSplunky { SDP_SERVICE_CLASS_PANU, "PANU", },
431dfbf818aSplunky { SDP_SERVICE_CLASS_NAP, "Network Access Point", },
432dfbf818aSplunky { SDP_SERVICE_CLASS_GN, "GN", },
433dfbf818aSplunky { SDP_SERVICE_CLASS_DIRECT_PRINTING, "Direct Printing", },
434dfbf818aSplunky { SDP_SERVICE_CLASS_REFERENCE_PRINTING, "Reference Printing", },
435dfbf818aSplunky { SDP_SERVICE_CLASS_IMAGING, "Imaging", },
436dfbf818aSplunky { SDP_SERVICE_CLASS_IMAGING_RESPONDER, "Imaging Responder", },
437dfbf818aSplunky { SDP_SERVICE_CLASS_IMAGING_AUTOMATIC_ARCHIVE, "Imaging Automatic Archive", },
438dfbf818aSplunky { SDP_SERVICE_CLASS_IMAGING_REFERENCED_OBJECTS, "Imaging Referenced Objects", },
439dfbf818aSplunky { SDP_SERVICE_CLASS_HANDSFREE, "Handsfree", },
440dfbf818aSplunky { SDP_SERVICE_CLASS_HANDSFREE_AUDIO_GATEWAY, "Handsfree Audio Gateway", },
441dfbf818aSplunky { SDP_SERVICE_CLASS_DIRECT_PRINTING_REFERENCE_OBJECTS, "Direct Printing Reference Objects", },
442dfbf818aSplunky { SDP_SERVICE_CLASS_REFLECTED_UI, "Reflected UI", },
443dfbf818aSplunky { SDP_SERVICE_CLASS_BASIC_PRINTING, "Basic Printing", },
444dfbf818aSplunky { SDP_SERVICE_CLASS_PRINTING_STATUS, "Printing Status", },
445dfbf818aSplunky { SDP_SERVICE_CLASS_HUMAN_INTERFACE_DEVICE, "Human Interface Device", },
446dfbf818aSplunky { SDP_SERVICE_CLASS_HARDCOPY_CABLE_REPLACEMENT, "Hardcopy Cable Replacement", },
447dfbf818aSplunky { SDP_SERVICE_CLASS_HCR_PRINT, "HCR Print", },
448dfbf818aSplunky { SDP_SERVICE_CLASS_HCR_SCAN, "HCR Scan", },
449dfbf818aSplunky { SDP_SERVICE_CLASS_COMMON_ISDN_ACCESS, "Common ISDN Access", },
450dfbf818aSplunky { SDP_SERVICE_CLASS_VIDEO_CONFERENCING_GW, "Video Conferencing Gateway", },
451dfbf818aSplunky { SDP_SERVICE_CLASS_UDI_MT, "UDI MT", },
452dfbf818aSplunky { SDP_SERVICE_CLASS_UDI_TA, "UDI TA", },
453dfbf818aSplunky { SDP_SERVICE_CLASS_AUDIO_VIDEO, "Audio/Video", },
454dfbf818aSplunky { SDP_SERVICE_CLASS_SIM_ACCESS, "SIM Access", },
455dfbf818aSplunky { SDP_SERVICE_CLASS_PNP_INFORMATION, "PNP Information", },
456dfbf818aSplunky { SDP_SERVICE_CLASS_GENERIC_NETWORKING, "Generic Networking", },
457dfbf818aSplunky { SDP_SERVICE_CLASS_GENERIC_FILE_TRANSFER, "Generic File Transfer", },
458dfbf818aSplunky { SDP_SERVICE_CLASS_GENERIC_AUDIO, "Generic Audio", },
459dfbf818aSplunky { SDP_SERVICE_CLASS_GENERIC_TELEPHONY, "Generic Telephony", },
460dfbf818aSplunky { SDP_SERVICE_CLASS_UPNP, "UPNP", },
461dfbf818aSplunky { SDP_SERVICE_CLASS_UPNP_IP, "UPNP IP", },
462dfbf818aSplunky { SDP_SERVICE_CLASS_ESDP_UPNP_IP_PAN, "ESDP UPNP IP PAN", },
463dfbf818aSplunky { SDP_SERVICE_CLASS_ESDP_UPNP_IP_LAP, "ESDP UPNP IP LAP", },
464dfbf818aSplunky { SDP_SERVICE_CLASS_ESDP_UPNP_L2CAP, "ESDP UPNP L2CAP", },
465dfbf818aSplunky { 0xffff, NULL, }
466dfbf818aSplunky };
467dfbf818aSplunky 
468dfbf818aSplunky static sdp_attr_desc_t	sdp_attrs_desc[] = {
469dfbf818aSplunky { SDP_ATTR_SERVICE_RECORD_HANDLE,
470dfbf818aSplunky   "Record handle",
471dfbf818aSplunky   },
472dfbf818aSplunky { SDP_ATTR_SERVICE_CLASS_ID_LIST,
473dfbf818aSplunky   "Service Class ID list",
474dfbf818aSplunky   },
475dfbf818aSplunky { SDP_ATTR_SERVICE_RECORD_STATE,
476dfbf818aSplunky   "Service Record State",
477dfbf818aSplunky   },
478dfbf818aSplunky { SDP_ATTR_SERVICE_ID,
479dfbf818aSplunky   "Service ID",
480dfbf818aSplunky   },
481dfbf818aSplunky { SDP_ATTR_PROTOCOL_DESCRIPTOR_LIST,
482dfbf818aSplunky   "Protocol Descriptor List",
483dfbf818aSplunky   },
484dfbf818aSplunky { SDP_ATTR_BROWSE_GROUP_LIST,
485dfbf818aSplunky   "Browse Group List",
486dfbf818aSplunky   },
487dfbf818aSplunky { SDP_ATTR_LANGUAGE_BASE_ATTRIBUTE_ID_LIST,
488dfbf818aSplunky   "Language Base Attribute ID List",
489dfbf818aSplunky   },
490dfbf818aSplunky { SDP_ATTR_SERVICE_INFO_TIME_TO_LIVE,
491dfbf818aSplunky   "Service Info Time-To-Live",
492dfbf818aSplunky   },
493dfbf818aSplunky { SDP_ATTR_SERVICE_AVAILABILITY,
494dfbf818aSplunky   "Service Availability",
495dfbf818aSplunky   },
496dfbf818aSplunky { SDP_ATTR_BLUETOOTH_PROFILE_DESCRIPTOR_LIST,
497dfbf818aSplunky   "Bluetooh Profile Descriptor List",
498dfbf818aSplunky   },
499dfbf818aSplunky { SDP_ATTR_DOCUMENTATION_URL,
500dfbf818aSplunky   "Documentation URL",
501dfbf818aSplunky   },
502dfbf818aSplunky { SDP_ATTR_CLIENT_EXECUTABLE_URL,
503dfbf818aSplunky   "Client Executable URL",
504dfbf818aSplunky   },
505dfbf818aSplunky { SDP_ATTR_ICON_URL,
506dfbf818aSplunky   "Icon URL",
507dfbf818aSplunky   },
508dfbf818aSplunky { SDP_ATTR_ADDITIONAL_PROTOCOL_DESCRIPTOR_LISTS,
509dfbf818aSplunky   "Additional Protocol Descriptor Lists" },
510dfbf818aSplunky { SDP_ATTR_GROUP_ID,
511dfbf818aSplunky /*SDP_ATTR_IP_SUBNET,
512dfbf818aSplunky   SDP_ATTR_VERSION_NUMBER_LIST*/
513dfbf818aSplunky   "Group ID/IP Subnet/Version Number List",
514dfbf818aSplunky   },
515dfbf818aSplunky { SDP_ATTR_SERVICE_DATABASE_STATE,
516dfbf818aSplunky   "Service Database State",
517dfbf818aSplunky   },
518dfbf818aSplunky { SDP_ATTR_SERVICE_VERSION,
519dfbf818aSplunky   "Service Version",
520dfbf818aSplunky   },
521dfbf818aSplunky { SDP_ATTR_EXTERNAL_NETWORK,
522dfbf818aSplunky /*SDP_ATTR_NETWORK,
523dfbf818aSplunky   SDP_ATTR_SUPPORTED_DATA_STORES_LIST*/
524dfbf818aSplunky   "External Network/Network/Supported Data Stores List",
525dfbf818aSplunky   },
526dfbf818aSplunky { SDP_ATTR_FAX_CLASS1_SUPPORT,
527dfbf818aSplunky /*SDP_ATTR_REMOTE_AUDIO_VOLUME_CONTROL*/
528dfbf818aSplunky   "Fax Class1 Support/Remote Audio Volume Control",
529dfbf818aSplunky   },
530dfbf818aSplunky { SDP_ATTR_FAX_CLASS20_SUPPORT,
531dfbf818aSplunky /*SDP_ATTR_SUPPORTED_FORMATS_LIST*/
532dfbf818aSplunky   "Fax Class20 Support/Supported Formats List",
533dfbf818aSplunky   },
534dfbf818aSplunky { SDP_ATTR_FAX_CLASS2_SUPPORT,
535dfbf818aSplunky   "Fax Class2 Support",
536dfbf818aSplunky   },
537dfbf818aSplunky { SDP_ATTR_AUDIO_FEEDBACK_SUPPORT,
538dfbf818aSplunky   "Audio Feedback Support",
539dfbf818aSplunky   },
540dfbf818aSplunky { SDP_ATTR_NETWORK_ADDRESS,
541dfbf818aSplunky   "Network Address",
542dfbf818aSplunky   },
543dfbf818aSplunky { SDP_ATTR_WAP_GATEWAY,
544dfbf818aSplunky   "WAP Gateway",
545dfbf818aSplunky   },
546dfbf818aSplunky { SDP_ATTR_HOME_PAGE_URL,
547dfbf818aSplunky   "Home Page URL",
548dfbf818aSplunky   },
549dfbf818aSplunky { SDP_ATTR_WAP_STACK_TYPE,
550dfbf818aSplunky   "WAP Stack Type",
551dfbf818aSplunky   },
552dfbf818aSplunky { SDP_ATTR_SECURITY_DESCRIPTION,
553dfbf818aSplunky   "Security Description",
554dfbf818aSplunky   },
555dfbf818aSplunky { SDP_ATTR_NET_ACCESS_TYPE,
556dfbf818aSplunky   "Net Access Type",
557dfbf818aSplunky   },
558dfbf818aSplunky { SDP_ATTR_MAX_NET_ACCESS_RATE,
559dfbf818aSplunky   "Max Net Access Rate",
560dfbf818aSplunky   },
561dfbf818aSplunky { SDP_ATTR_IPV4_SUBNET,
562dfbf818aSplunky   "IPv4 Subnet",
563dfbf818aSplunky   },
564dfbf818aSplunky { SDP_ATTR_IPV6_SUBNET,
565dfbf818aSplunky   "IPv6 Subnet",
566dfbf818aSplunky   },
567dfbf818aSplunky { SDP_ATTR_SUPPORTED_CAPABALITIES,
568dfbf818aSplunky   "Supported Capabalities",
569dfbf818aSplunky   },
570dfbf818aSplunky { SDP_ATTR_SUPPORTED_FEATURES,
571dfbf818aSplunky   "Supported Features",
572dfbf818aSplunky   },
573dfbf818aSplunky { SDP_ATTR_SUPPORTED_FUNCTIONS,
574dfbf818aSplunky   "Supported Functions",
575dfbf818aSplunky   },
576dfbf818aSplunky { SDP_ATTR_TOTAL_IMAGING_DATA_CAPACITY,
577dfbf818aSplunky   "Total Imaging Data Capacity",
578dfbf818aSplunky   },
579dfbf818aSplunky { 0xffff, NULL, }
580dfbf818aSplunky };
581dfbf818aSplunky 
582dfbf818aSplunky char const *
sdp_attr2desc(uint16_t attr)583dfbf818aSplunky sdp_attr2desc(uint16_t attr)
584dfbf818aSplunky {
585dfbf818aSplunky 	register sdp_attr_desc_p	a = sdp_attrs_desc;
586dfbf818aSplunky 
587dfbf818aSplunky 	for (; a->desc != NULL; a++)
588dfbf818aSplunky 		if (attr == a->attr)
589dfbf818aSplunky 			break;
590dfbf818aSplunky 
591dfbf818aSplunky 	return ((a->desc != NULL)? a->desc : "Unknown");
592dfbf818aSplunky }
593dfbf818aSplunky 
594dfbf818aSplunky char const *
sdp_uuid2desc(uint16_t uuid)595dfbf818aSplunky sdp_uuid2desc(uint16_t uuid)
596dfbf818aSplunky {
597dfbf818aSplunky 	register sdp_attr_desc_p	a = sdp_uuids_desc;
598dfbf818aSplunky 
599dfbf818aSplunky 	for (; a->desc != NULL; a++)
600dfbf818aSplunky 		if (uuid == a->attr)
601dfbf818aSplunky 			break;
602dfbf818aSplunky 
603dfbf818aSplunky 	return ((a->desc != NULL)? a->desc : "Unknown");
604dfbf818aSplunky }
605dfbf818aSplunky 
606dfbf818aSplunky void
sdp_print(uint32_t level,uint8_t * start,uint8_t const * end)607dfbf818aSplunky sdp_print(uint32_t level, uint8_t *start, uint8_t const *end)
608dfbf818aSplunky {
609dfbf818aSplunky 
610dfbf818aSplunky 	(void)_sdp_data_print(start, end, level);
611dfbf818aSplunky }
612