Home | History | Annotate | Line # | Download | only in libbluetooth
sdp_data.c revision 1.1
      1  1.1  plunky /*	$NetBSD: sdp_data.c,v 1.1 2009/05/12 10:05:06 plunky Exp $	*/
      2  1.1  plunky 
      3  1.1  plunky /*-
      4  1.1  plunky  * Copyright (c) 2009 The NetBSD Foundation, Inc.
      5  1.1  plunky  * All rights reserved.
      6  1.1  plunky  *
      7  1.1  plunky  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1  plunky  * by Iain Hibbert.
      9  1.1  plunky  *
     10  1.1  plunky  * Redistribution and use in source and binary forms, with or without
     11  1.1  plunky  * modification, are permitted provided that the following conditions
     12  1.1  plunky  * are met:
     13  1.1  plunky  * 1. Redistributions of source code must retain the above copyright
     14  1.1  plunky  *    notice, this list of conditions and the following disclaimer.
     15  1.1  plunky  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1  plunky  *    notice, this list of conditions and the following disclaimer in the
     17  1.1  plunky  *    documentation and/or other materials provided with the distribution.
     18  1.1  plunky  *
     19  1.1  plunky  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  1.1  plunky  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  1.1  plunky  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  1.1  plunky  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  1.1  plunky  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  1.1  plunky  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  1.1  plunky  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  1.1  plunky  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  1.1  plunky  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  1.1  plunky  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  1.1  plunky  * POSSIBILITY OF SUCH DAMAGE.
     30  1.1  plunky  */
     31  1.1  plunky 
     32  1.1  plunky #include <sys/cdefs.h>
     33  1.1  plunky __RCSID("$NetBSD: sdp_data.c,v 1.1 2009/05/12 10:05:06 plunky Exp $");
     34  1.1  plunky 
     35  1.1  plunky #include <sdp.h>
     36  1.1  plunky #include <stdarg.h>
     37  1.1  plunky #include <stdio.h>
     38  1.1  plunky #include <vis.h>
     39  1.1  plunky 
     40  1.1  plunky #include "sdp-int.h"
     41  1.1  plunky 
     42  1.1  plunky 
     43  1.1  plunky /******************************************************************************
     44  1.1  plunky  *	sdp_data_type(data)
     45  1.1  plunky  *
     46  1.1  plunky  * return SDP data element type
     47  1.1  plunky  */
     48  1.1  plunky int
     49  1.1  plunky sdp_data_type(const sdp_data_t *data)
     50  1.1  plunky {
     51  1.1  plunky 
     52  1.1  plunky 	if (data->next + 1 > data->end)
     53  1.1  plunky 		return -1;
     54  1.1  plunky 
     55  1.1  plunky 	return data->next[0];
     56  1.1  plunky }
     57  1.1  plunky 
     58  1.1  plunky 
     59  1.1  plunky /******************************************************************************
     60  1.1  plunky  *	sdp_data_size(data)
     61  1.1  plunky  *
     62  1.1  plunky  * return the size of SDP data element. This will fail (return -1) if
     63  1.1  plunky  * the data element does not fit into the data space.
     64  1.1  plunky  */
     65  1.1  plunky ssize_t
     66  1.1  plunky sdp_data_size(const sdp_data_t *data)
     67  1.1  plunky {
     68  1.1  plunky 	uint8_t *p = data->next;
     69  1.1  plunky 
     70  1.1  plunky 	if (p + 1 > data->end)
     71  1.1  plunky 		return -1;
     72  1.1  plunky 
     73  1.1  plunky 	switch (*p++) {
     74  1.1  plunky 	case SDP_DATA_NIL:
     75  1.1  plunky 		break;
     76  1.1  plunky 
     77  1.1  plunky 	case SDP_DATA_BOOL:
     78  1.1  plunky 	case SDP_DATA_INT8:
     79  1.1  plunky 	case SDP_DATA_UINT8:
     80  1.1  plunky 		p += 1;
     81  1.1  plunky 		break;
     82  1.1  plunky 
     83  1.1  plunky 	case SDP_DATA_INT16:
     84  1.1  plunky 	case SDP_DATA_UINT16:
     85  1.1  plunky 	case SDP_DATA_UUID16:
     86  1.1  plunky 		p += 2;
     87  1.1  plunky 		break;
     88  1.1  plunky 
     89  1.1  plunky 	case SDP_DATA_INT32:
     90  1.1  plunky 	case SDP_DATA_UINT32:
     91  1.1  plunky 	case SDP_DATA_UUID32:
     92  1.1  plunky 		p += 4;
     93  1.1  plunky 		break;
     94  1.1  plunky 
     95  1.1  plunky 	case SDP_DATA_INT64:
     96  1.1  plunky 	case SDP_DATA_UINT64:
     97  1.1  plunky 		p += 8;
     98  1.1  plunky 		break;
     99  1.1  plunky 
    100  1.1  plunky 	case SDP_DATA_INT128:
    101  1.1  plunky 	case SDP_DATA_UINT128:
    102  1.1  plunky 	case SDP_DATA_UUID128:
    103  1.1  plunky 		p += 16;
    104  1.1  plunky 		break;
    105  1.1  plunky 
    106  1.1  plunky 	case SDP_DATA_ALT8:
    107  1.1  plunky 	case SDP_DATA_SEQ8:
    108  1.1  plunky 	case SDP_DATA_STR8:
    109  1.1  plunky 	case SDP_DATA_URL8:
    110  1.1  plunky 		if (p + 1 > data->end)
    111  1.1  plunky 			return -1;
    112  1.1  plunky 
    113  1.1  plunky 		p += 1 + *p;
    114  1.1  plunky 		break;
    115  1.1  plunky 
    116  1.1  plunky 	case SDP_DATA_ALT16:
    117  1.1  plunky 	case SDP_DATA_SEQ16:
    118  1.1  plunky 	case SDP_DATA_STR16:
    119  1.1  plunky 	case SDP_DATA_URL16:
    120  1.1  plunky 		if (p + 2 > data->end)
    121  1.1  plunky 			return -1;
    122  1.1  plunky 
    123  1.1  plunky 		p += 2 + be16dec(p);
    124  1.1  plunky 		break;
    125  1.1  plunky 
    126  1.1  plunky 	case SDP_DATA_ALT32:
    127  1.1  plunky 	case SDP_DATA_SEQ32:
    128  1.1  plunky 	case SDP_DATA_STR32:
    129  1.1  plunky 	case SDP_DATA_URL32:
    130  1.1  plunky 		if (p + 4 > data->end)
    131  1.1  plunky 			return -1;
    132  1.1  plunky 
    133  1.1  plunky 		p += 4 + be32dec(p);
    134  1.1  plunky 		break;
    135  1.1  plunky 
    136  1.1  plunky 	default:
    137  1.1  plunky 		return -1;
    138  1.1  plunky 	}
    139  1.1  plunky 
    140  1.1  plunky 	if (p > data->end)
    141  1.1  plunky 		return -1;
    142  1.1  plunky 
    143  1.1  plunky 	return (p - data->next);
    144  1.1  plunky }
    145  1.1  plunky 
    146  1.1  plunky /******************************************************************************
    147  1.1  plunky  *	sdp_data_valid(data)
    148  1.1  plunky  *
    149  1.1  plunky  * validate an SDP data element list recursively, ensuring elements do not
    150  1.1  plunky  * expand past the claimed length and that there is no invalid data.
    151  1.1  plunky  */
    152  1.1  plunky static bool
    153  1.1  plunky _sdp_data_valid(uint8_t *ptr, uint8_t *end)
    154  1.1  plunky {
    155  1.1  plunky 	size_t len;
    156  1.1  plunky 
    157  1.1  plunky 	while (ptr < end) {
    158  1.1  plunky 		if (ptr + 1 > end)
    159  1.1  plunky 			return false;
    160  1.1  plunky 
    161  1.1  plunky 		switch (*ptr++) {
    162  1.1  plunky 		case SDP_DATA_NIL:
    163  1.1  plunky 			break;
    164  1.1  plunky 
    165  1.1  plunky 		case SDP_DATA_BOOL:
    166  1.1  plunky 		case SDP_DATA_INT8:
    167  1.1  plunky 		case SDP_DATA_UINT8:
    168  1.1  plunky 			if (ptr + 1 > end)
    169  1.1  plunky 				return false;
    170  1.1  plunky 
    171  1.1  plunky 			ptr += 1;
    172  1.1  plunky 			break;
    173  1.1  plunky 
    174  1.1  plunky 		case SDP_DATA_INT16:
    175  1.1  plunky 		case SDP_DATA_UINT16:
    176  1.1  plunky 		case SDP_DATA_UUID16:
    177  1.1  plunky 			if (ptr + 2 > end)
    178  1.1  plunky 				return false;
    179  1.1  plunky 
    180  1.1  plunky 			ptr += 2;
    181  1.1  plunky 			break;
    182  1.1  plunky 
    183  1.1  plunky 		case SDP_DATA_INT32:
    184  1.1  plunky 		case SDP_DATA_UINT32:
    185  1.1  plunky 		case SDP_DATA_UUID32:
    186  1.1  plunky 			if (ptr + 4 > end)
    187  1.1  plunky 				return false;
    188  1.1  plunky 
    189  1.1  plunky 			ptr += 4;
    190  1.1  plunky 			break;
    191  1.1  plunky 
    192  1.1  plunky 		case SDP_DATA_INT64:
    193  1.1  plunky 		case SDP_DATA_UINT64:
    194  1.1  plunky 			if (ptr + 8 > end)
    195  1.1  plunky 				return false;
    196  1.1  plunky 
    197  1.1  plunky 			ptr += 8;
    198  1.1  plunky 			break;
    199  1.1  plunky 
    200  1.1  plunky 		case SDP_DATA_INT128:
    201  1.1  plunky 		case SDP_DATA_UINT128:
    202  1.1  plunky 		case SDP_DATA_UUID128:
    203  1.1  plunky 			if (ptr + 16 > end)
    204  1.1  plunky 				return false;
    205  1.1  plunky 
    206  1.1  plunky 			ptr += 16;
    207  1.1  plunky 			break;
    208  1.1  plunky 
    209  1.1  plunky 		case SDP_DATA_STR8:
    210  1.1  plunky 		case SDP_DATA_URL8:
    211  1.1  plunky 			if (ptr + 1 > end)
    212  1.1  plunky 				return false;
    213  1.1  plunky 
    214  1.1  plunky 			len = *ptr;
    215  1.1  plunky 			ptr += 1;
    216  1.1  plunky 
    217  1.1  plunky 			if (ptr + len > end)
    218  1.1  plunky 				return false;
    219  1.1  plunky 
    220  1.1  plunky 			ptr += len;
    221  1.1  plunky 			break;
    222  1.1  plunky 
    223  1.1  plunky 		case SDP_DATA_STR16:
    224  1.1  plunky 		case SDP_DATA_URL16:
    225  1.1  plunky 			if (ptr + 2 > end)
    226  1.1  plunky 				return false;
    227  1.1  plunky 
    228  1.1  plunky 			len = be16dec(ptr);
    229  1.1  plunky 			ptr += 2;
    230  1.1  plunky 
    231  1.1  plunky 			if (ptr + len > end)
    232  1.1  plunky 				return false;
    233  1.1  plunky 
    234  1.1  plunky 			ptr += len;
    235  1.1  plunky 			break;
    236  1.1  plunky 
    237  1.1  plunky 		case SDP_DATA_STR32:
    238  1.1  plunky 		case SDP_DATA_URL32:
    239  1.1  plunky 			if (ptr + 4 > end)
    240  1.1  plunky 				return false;
    241  1.1  plunky 
    242  1.1  plunky 			len = be32dec(ptr);
    243  1.1  plunky 			ptr += 4;
    244  1.1  plunky 
    245  1.1  plunky 			if (ptr + len > end)
    246  1.1  plunky 				return false;
    247  1.1  plunky 
    248  1.1  plunky 			ptr += len;
    249  1.1  plunky 			break;
    250  1.1  plunky 
    251  1.1  plunky 		case SDP_DATA_SEQ8:
    252  1.1  plunky 		case SDP_DATA_ALT8:
    253  1.1  plunky 			if (ptr + 1 > end)
    254  1.1  plunky 				return false;
    255  1.1  plunky 
    256  1.1  plunky 			len = *ptr;
    257  1.1  plunky 			ptr += 1;
    258  1.1  plunky 
    259  1.1  plunky 			if (ptr + len > end)
    260  1.1  plunky 				return false;
    261  1.1  plunky 
    262  1.1  plunky 			if (!_sdp_data_valid(ptr, ptr + len))
    263  1.1  plunky 				return false;
    264  1.1  plunky 
    265  1.1  plunky 			ptr += len;
    266  1.1  plunky 			break;
    267  1.1  plunky 
    268  1.1  plunky 		case SDP_DATA_SEQ16:
    269  1.1  plunky 		case SDP_DATA_ALT16:
    270  1.1  plunky 			if (ptr + 2 > end)
    271  1.1  plunky 				return false;
    272  1.1  plunky 
    273  1.1  plunky 			len = be16dec(ptr);
    274  1.1  plunky 			ptr += 2;
    275  1.1  plunky 
    276  1.1  plunky 			if (ptr + len > end)
    277  1.1  plunky 				return false;
    278  1.1  plunky 
    279  1.1  plunky 			if (!_sdp_data_valid(ptr, ptr + len))
    280  1.1  plunky 				return false;
    281  1.1  plunky 
    282  1.1  plunky 			ptr += len;
    283  1.1  plunky 			break;
    284  1.1  plunky 
    285  1.1  plunky 		case SDP_DATA_SEQ32:
    286  1.1  plunky 		case SDP_DATA_ALT32:
    287  1.1  plunky 			if (ptr + 4 > end)
    288  1.1  plunky 				return false;
    289  1.1  plunky 
    290  1.1  plunky 			len = be32dec(ptr);
    291  1.1  plunky 			ptr += 4;
    292  1.1  plunky 
    293  1.1  plunky 			if (ptr + len > end)
    294  1.1  plunky 				return false;
    295  1.1  plunky 
    296  1.1  plunky 			if (!_sdp_data_valid(ptr, ptr + len))
    297  1.1  plunky 				return false;
    298  1.1  plunky 
    299  1.1  plunky 			ptr += len;
    300  1.1  plunky 			break;
    301  1.1  plunky 
    302  1.1  plunky 		default:
    303  1.1  plunky 			return false;
    304  1.1  plunky 		}
    305  1.1  plunky 	}
    306  1.1  plunky 
    307  1.1  plunky 	return true;
    308  1.1  plunky }
    309  1.1  plunky 
    310  1.1  plunky bool
    311  1.1  plunky sdp_data_valid(const sdp_data_t *data)
    312  1.1  plunky {
    313  1.1  plunky 
    314  1.1  plunky 	if (data->next == NULL || data->end == NULL)
    315  1.1  plunky 		return false;
    316  1.1  plunky 
    317  1.1  plunky 	if (data->next >= data->end)
    318  1.1  plunky 		return false;
    319  1.1  plunky 
    320  1.1  plunky 	return _sdp_data_valid(data->next, data->end);
    321  1.1  plunky }
    322  1.1  plunky 
    323  1.1  plunky /******************************************************************************
    324  1.1  plunky  *	sdp_data_print(data, indent)
    325  1.1  plunky  *
    326  1.1  plunky  * print out a SDP data element list in human readable format
    327  1.1  plunky  */
    328  1.1  plunky static void
    329  1.1  plunky _sdp_put(int indent, const char *type, const char *fmt, ...)
    330  1.1  plunky {
    331  1.1  plunky 	va_list ap;
    332  1.1  plunky 
    333  1.1  plunky 	indent = printf("%*s%s", indent, "", type);
    334  1.1  plunky 	indent = 18 - indent;
    335  1.1  plunky 	if (indent < 2)
    336  1.1  plunky 		indent = 2;
    337  1.1  plunky 
    338  1.1  plunky 	printf("%*s", indent, "");
    339  1.1  plunky 
    340  1.1  plunky 	va_start(ap, fmt);
    341  1.1  plunky 	vprintf(fmt, ap);
    342  1.1  plunky 	va_end(ap);
    343  1.1  plunky 
    344  1.1  plunky 	printf("\n");
    345  1.1  plunky }
    346  1.1  plunky 
    347  1.1  plunky static void
    348  1.1  plunky _sdp_putstr(int indent, int style, const char *type,
    349  1.1  plunky     const uint8_t *str, size_t len)
    350  1.1  plunky {
    351  1.1  plunky 	char buf[50], *dst = buf;
    352  1.1  plunky 
    353  1.1  plunky 	indent = printf("%*s%s(%zu)", indent, "", type, len);
    354  1.1  plunky 	indent = 18 - indent;
    355  1.1  plunky 	if (indent < 2)
    356  1.1  plunky 		indent = 2;
    357  1.1  plunky 
    358  1.1  plunky 	printf("%*s", indent, "");
    359  1.1  plunky 
    360  1.1  plunky 	style |= VIS_NL;
    361  1.1  plunky 
    362  1.1  plunky 	while (len > 0 && (dst + 5) < (buf + sizeof(buf))) {
    363  1.1  plunky 		dst = vis(dst, str[0], style, (len > 0 ? str[1] : 0));
    364  1.1  plunky 		str++;
    365  1.1  plunky 		len--;
    366  1.1  plunky 	}
    367  1.1  plunky 
    368  1.1  plunky 	printf("\"%s%s\n", buf, (len == 0 ? "\"" : " ..."));
    369  1.1  plunky }
    370  1.1  plunky 
    371  1.1  plunky bool
    372  1.1  plunky _sdp_data_print(const uint8_t *next, const uint8_t *end, int indent)
    373  1.1  plunky {
    374  1.1  plunky 	size_t len;
    375  1.1  plunky 
    376  1.1  plunky 	while (next < end) {
    377  1.1  plunky 		if (next + 1 > end)
    378  1.1  plunky 			return false;
    379  1.1  plunky 
    380  1.1  plunky 		switch (*next++) {
    381  1.1  plunky 		case SDP_DATA_NIL:
    382  1.1  plunky 			_sdp_put(indent, "nil", "");
    383  1.1  plunky 			break;
    384  1.1  plunky 
    385  1.1  plunky 		case SDP_DATA_BOOL:
    386  1.1  plunky 			if (next + 1 > end)
    387  1.1  plunky 				return false;
    388  1.1  plunky 
    389  1.1  plunky 			_sdp_put(indent, "bool", "%s",
    390  1.1  plunky 			    (*next == 0x00 ? "false" : "true"));
    391  1.1  plunky 
    392  1.1  plunky 			next += 1;
    393  1.1  plunky 			break;
    394  1.1  plunky 
    395  1.1  plunky 		case SDP_DATA_INT8:
    396  1.1  plunky 			if (next + 1 > end)
    397  1.1  plunky 				return false;
    398  1.1  plunky 
    399  1.1  plunky 			_sdp_put(indent, "int8", "%" PRId8,
    400  1.1  plunky 			    *(const int8_t *)next);
    401  1.1  plunky 			next += 1;
    402  1.1  plunky 			break;
    403  1.1  plunky 
    404  1.1  plunky 		case SDP_DATA_UINT8:
    405  1.1  plunky 			if (next + 1 > end)
    406  1.1  plunky 				return false;
    407  1.1  plunky 
    408  1.1  plunky 			_sdp_put(indent, "uint8", "0x%02" PRIx8,
    409  1.1  plunky 			    *next);
    410  1.1  plunky 			next += 1;
    411  1.1  plunky 			break;
    412  1.1  plunky 
    413  1.1  plunky 		case SDP_DATA_INT16:
    414  1.1  plunky 			if (next + 2 > end)
    415  1.1  plunky 				return false;
    416  1.1  plunky 
    417  1.1  plunky 			_sdp_put(indent, "int16", "%" PRId16,
    418  1.1  plunky 			    (int16_t)be16dec(next));
    419  1.1  plunky 			next += 2;
    420  1.1  plunky 			break;
    421  1.1  plunky 
    422  1.1  plunky 		case SDP_DATA_UINT16:
    423  1.1  plunky 			if (next + 2 > end)
    424  1.1  plunky 				return false;
    425  1.1  plunky 
    426  1.1  plunky 			_sdp_put(indent, "uint16", "0x%04" PRIx16,
    427  1.1  plunky 			    be16dec(next));
    428  1.1  plunky 			next += 2;
    429  1.1  plunky 			break;
    430  1.1  plunky 
    431  1.1  plunky 		case SDP_DATA_UUID16:
    432  1.1  plunky 			if (next + 2 > end)
    433  1.1  plunky 				return false;
    434  1.1  plunky 
    435  1.1  plunky 			_sdp_put(indent, "uuid16", "0x%04" PRIx16,
    436  1.1  plunky 			    be16dec(next));
    437  1.1  plunky 			next += 2;
    438  1.1  plunky 			break;
    439  1.1  plunky 
    440  1.1  plunky 		case SDP_DATA_INT32:
    441  1.1  plunky 			if (next + 4 > end)
    442  1.1  plunky 				return false;
    443  1.1  plunky 
    444  1.1  plunky 			_sdp_put(indent, "int32", "%" PRId32,
    445  1.1  plunky 			    (int32_t)be32dec(next));
    446  1.1  plunky 			next += 4;
    447  1.1  plunky 			break;
    448  1.1  plunky 
    449  1.1  plunky 		case SDP_DATA_UINT32:
    450  1.1  plunky 			if (next + 4 > end)
    451  1.1  plunky 				return false;
    452  1.1  plunky 
    453  1.1  plunky 			_sdp_put(indent, "uint32", "0x%08" PRIx32,
    454  1.1  plunky 			    be32dec(next));
    455  1.1  plunky 			next += 4;
    456  1.1  plunky 			break;
    457  1.1  plunky 
    458  1.1  plunky 		case SDP_DATA_UUID32:
    459  1.1  plunky 			if (next + 4 > end)
    460  1.1  plunky 				return false;
    461  1.1  plunky 
    462  1.1  plunky 			_sdp_put(indent, "uuid32", "0x%08" PRIx32,
    463  1.1  plunky 			    be32dec(next));
    464  1.1  plunky 			next += 4;
    465  1.1  plunky 			break;
    466  1.1  plunky 
    467  1.1  plunky 		case SDP_DATA_INT64:
    468  1.1  plunky 			if (next + 8 > end)
    469  1.1  plunky 				return false;
    470  1.1  plunky 
    471  1.1  plunky 			_sdp_put(indent, "int64", "%" PRId64,
    472  1.1  plunky 			    (int64_t)be64dec(next));
    473  1.1  plunky 			next += 8;
    474  1.1  plunky 			break;
    475  1.1  plunky 
    476  1.1  plunky 		case SDP_DATA_UINT64:
    477  1.1  plunky 			if (next + 8 > end)
    478  1.1  plunky 				return false;
    479  1.1  plunky 
    480  1.1  plunky 			_sdp_put(indent, "uint64", "0x%016" PRIx64,
    481  1.1  plunky 			    be64dec(next));
    482  1.1  plunky 			next += 8;
    483  1.1  plunky 			break;
    484  1.1  plunky 
    485  1.1  plunky 		case SDP_DATA_INT128:
    486  1.1  plunky 			if (next + 16 > end)
    487  1.1  plunky 				return false;
    488  1.1  plunky 
    489  1.1  plunky 			_sdp_put(indent, "int128",
    490  1.1  plunky 				"0x%02x%02x%02x%02x%02x%02x%02x%02x"
    491  1.1  plunky 				"%02x%02x%02x%02x%02x%02x%02x%02x",
    492  1.1  plunky 				next[0], next[1], next[2], next[3],
    493  1.1  plunky 				next[4], next[5], next[6], next[7],
    494  1.1  plunky 				next[8], next[9], next[10], next[11],
    495  1.1  plunky 				next[12], next[13], next[14], next[15]);
    496  1.1  plunky 			next += 16;
    497  1.1  plunky 			break;
    498  1.1  plunky 
    499  1.1  plunky 		case SDP_DATA_UINT128:
    500  1.1  plunky 			if (next + 16 > end)
    501  1.1  plunky 				return false;
    502  1.1  plunky 
    503  1.1  plunky 			_sdp_put(indent, "uint128",
    504  1.1  plunky 				"0x%02x%02x%02x%02x%02x%02x%02x%02x"
    505  1.1  plunky 				"%02x%02x%02x%02x%02x%02x%02x%02x",
    506  1.1  plunky 				next[0], next[1], next[2], next[3],
    507  1.1  plunky 				next[4], next[5], next[6], next[7],
    508  1.1  plunky 				next[8], next[9], next[10], next[11],
    509  1.1  plunky 				next[12], next[13], next[14], next[15]);
    510  1.1  plunky 			next += 16;
    511  1.1  plunky 			break;
    512  1.1  plunky 
    513  1.1  plunky 		case SDP_DATA_UUID128:
    514  1.1  plunky 			if (next + 16 > end)
    515  1.1  plunky 				return false;
    516  1.1  plunky 
    517  1.1  plunky 			_sdp_put(indent, "uuid128",
    518  1.1  plunky 				"%02x%02x%02x%02x-"
    519  1.1  plunky 				"%02x%02x-"
    520  1.1  plunky 				"%02x%02x-"
    521  1.1  plunky 				"%02x%02x-"
    522  1.1  plunky 				"%02x%02x%02x%02x%02x%02x",
    523  1.1  plunky 				next[0], next[1], next[2], next[3],
    524  1.1  plunky 				next[4], next[5],
    525  1.1  plunky 				next[6], next[7],
    526  1.1  plunky 				next[8], next[9],
    527  1.1  plunky 				next[10], next[11], next[12],
    528  1.1  plunky 				next[13], next[14], next[15]);
    529  1.1  plunky 			next += 16;
    530  1.1  plunky 			break;
    531  1.1  plunky 
    532  1.1  plunky 		case SDP_DATA_STR8:
    533  1.1  plunky 			if (next + 1 > end)
    534  1.1  plunky 				return false;
    535  1.1  plunky 
    536  1.1  plunky 			len = *next;
    537  1.1  plunky 			next += 1;
    538  1.1  plunky 
    539  1.1  plunky 			if (next + len > end)
    540  1.1  plunky 				return false;
    541  1.1  plunky 
    542  1.1  plunky 			_sdp_putstr(indent, VIS_CSTYLE, "str8", next, len);
    543  1.1  plunky 			next += len;
    544  1.1  plunky 			break;
    545  1.1  plunky 
    546  1.1  plunky 		case SDP_DATA_URL8:
    547  1.1  plunky 			if (next + 1 > end)
    548  1.1  plunky 				return false;
    549  1.1  plunky 
    550  1.1  plunky 			len = *next;
    551  1.1  plunky 			next += 1;
    552  1.1  plunky 
    553  1.1  plunky 			if (next + len > end)
    554  1.1  plunky 				return false;
    555  1.1  plunky 
    556  1.1  plunky 			_sdp_putstr(indent, VIS_HTTPSTYLE, "url8", next, len);
    557  1.1  plunky 			next += len;
    558  1.1  plunky 			break;
    559  1.1  plunky 
    560  1.1  plunky 		case SDP_DATA_STR16:
    561  1.1  plunky 			if (next + 2 > end)
    562  1.1  plunky 				return false;
    563  1.1  plunky 
    564  1.1  plunky 			len = be16dec(next);
    565  1.1  plunky 			next += 2;
    566  1.1  plunky 
    567  1.1  plunky 			if (next + len > end)
    568  1.1  plunky 				return false;
    569  1.1  plunky 
    570  1.1  plunky 			_sdp_putstr(indent, VIS_CSTYLE, "str16", next, len);
    571  1.1  plunky 			next += len;
    572  1.1  plunky 			break;
    573  1.1  plunky 
    574  1.1  plunky 		case SDP_DATA_URL16:
    575  1.1  plunky 			if (next + 2 > end)
    576  1.1  plunky 				return false;
    577  1.1  plunky 
    578  1.1  plunky 			len = be16dec(next);
    579  1.1  plunky 			next += 2;
    580  1.1  plunky 
    581  1.1  plunky 			if (next + len > end)
    582  1.1  plunky 				return false;
    583  1.1  plunky 
    584  1.1  plunky 			_sdp_putstr(indent, VIS_HTTPSTYLE, "url16", next, len);
    585  1.1  plunky 			next += len;
    586  1.1  plunky 			break;
    587  1.1  plunky 
    588  1.1  plunky 		case SDP_DATA_STR32:
    589  1.1  plunky 			if (next + 4 > end)
    590  1.1  plunky 				return false;
    591  1.1  plunky 
    592  1.1  plunky 			len = be32dec(next);
    593  1.1  plunky 			next += 4;
    594  1.1  plunky 
    595  1.1  plunky 			if (next + len > end)
    596  1.1  plunky 				return false;
    597  1.1  plunky 
    598  1.1  plunky 			_sdp_putstr(indent, VIS_CSTYLE, "str32", next, len);
    599  1.1  plunky 			next += len;
    600  1.1  plunky 			break;
    601  1.1  plunky 
    602  1.1  plunky 		case SDP_DATA_URL32:
    603  1.1  plunky 			if (next + 4 > end)
    604  1.1  plunky 				return false;
    605  1.1  plunky 
    606  1.1  plunky 			len = be32dec(next);
    607  1.1  plunky 			next += 4;
    608  1.1  plunky 
    609  1.1  plunky 			if (next + len > end)
    610  1.1  plunky 				return false;
    611  1.1  plunky 
    612  1.1  plunky 			_sdp_putstr(indent, VIS_HTTPSTYLE, "url32", next, len);
    613  1.1  plunky 			next += len;
    614  1.1  plunky 			break;
    615  1.1  plunky 
    616  1.1  plunky 		case SDP_DATA_SEQ8:
    617  1.1  plunky 			if (next + 1 > end)
    618  1.1  plunky 				return false;
    619  1.1  plunky 
    620  1.1  plunky 			len = *next;
    621  1.1  plunky 			next += 1;
    622  1.1  plunky 
    623  1.1  plunky 			if (next + len > end)
    624  1.1  plunky 				return false;
    625  1.1  plunky 
    626  1.1  plunky 			printf("%*sseq8(%zu)\n", indent, "", len);
    627  1.1  plunky 			if (!_sdp_data_print(next, next + len, indent + 1))
    628  1.1  plunky 				return false;
    629  1.1  plunky 
    630  1.1  plunky 			next += len;
    631  1.1  plunky 			break;
    632  1.1  plunky 
    633  1.1  plunky 		case SDP_DATA_ALT8:
    634  1.1  plunky 			if (next + 1 > end)
    635  1.1  plunky 				return false;
    636  1.1  plunky 
    637  1.1  plunky 			len = *next;
    638  1.1  plunky 			next += 1;
    639  1.1  plunky 
    640  1.1  plunky 			if (next + len > end)
    641  1.1  plunky 				return false;
    642  1.1  plunky 
    643  1.1  plunky 			printf("%*salt8(%zu)\n", indent, "", len);
    644  1.1  plunky 			if (!_sdp_data_print(next, next + len, indent + 1))
    645  1.1  plunky 				return false;
    646  1.1  plunky 
    647  1.1  plunky 			next += len;
    648  1.1  plunky 			break;
    649  1.1  plunky 
    650  1.1  plunky 		case SDP_DATA_SEQ16:
    651  1.1  plunky 			if (next + 2 > end)
    652  1.1  plunky 				return false;
    653  1.1  plunky 
    654  1.1  plunky 			len = be16dec(next);
    655  1.1  plunky 			next += 2;
    656  1.1  plunky 
    657  1.1  plunky 			if (next + len > end)
    658  1.1  plunky 				return false;
    659  1.1  plunky 
    660  1.1  plunky 			printf("%*sseq16(%zu)\n", indent, "", len);
    661  1.1  plunky 			if (!_sdp_data_print(next, next + len, indent + 1))
    662  1.1  plunky 				return false;
    663  1.1  plunky 
    664  1.1  plunky 			next += len;
    665  1.1  plunky 			break;
    666  1.1  plunky 
    667  1.1  plunky 		case SDP_DATA_ALT16:
    668  1.1  plunky 			if (next + 2 > end)
    669  1.1  plunky 				return false;
    670  1.1  plunky 
    671  1.1  plunky 			len = be16dec(next);
    672  1.1  plunky 			next += 2;
    673  1.1  plunky 
    674  1.1  plunky 			if (next + len > end)
    675  1.1  plunky 				return false;
    676  1.1  plunky 
    677  1.1  plunky 			printf("%*salt16(%zu)\n", indent, "", len);
    678  1.1  plunky 			if (!_sdp_data_print(next, next + len, indent + 1))
    679  1.1  plunky 				return false;
    680  1.1  plunky 
    681  1.1  plunky 			next += len;
    682  1.1  plunky 			break;
    683  1.1  plunky 
    684  1.1  plunky 		case SDP_DATA_SEQ32:
    685  1.1  plunky 			if (next + 4 > end)
    686  1.1  plunky 				return false;
    687  1.1  plunky 
    688  1.1  plunky 			len = be32dec(next);
    689  1.1  plunky 			next += 4;
    690  1.1  plunky 
    691  1.1  plunky 			if (next + len > end)
    692  1.1  plunky 				return false;
    693  1.1  plunky 
    694  1.1  plunky 			printf("%*sseq32(%zu)\n", indent, "", len);
    695  1.1  plunky 			if (!_sdp_data_print(next, next + len, indent + 1))
    696  1.1  plunky 				return false;
    697  1.1  plunky 
    698  1.1  plunky 			next += len;
    699  1.1  plunky 			break;
    700  1.1  plunky 
    701  1.1  plunky 		case SDP_DATA_ALT32:
    702  1.1  plunky 			if (next + 4 > end)
    703  1.1  plunky 				return false;
    704  1.1  plunky 
    705  1.1  plunky 			len = be32dec(next);
    706  1.1  plunky 			next += 4;
    707  1.1  plunky 
    708  1.1  plunky 			if (next + len > end)
    709  1.1  plunky 				return false;
    710  1.1  plunky 
    711  1.1  plunky 			printf("%*salt32(%zu)\n", indent, "", len);
    712  1.1  plunky 			if (!_sdp_data_print(next, next + len, indent + 1))
    713  1.1  plunky 				return false;
    714  1.1  plunky 
    715  1.1  plunky 			next += len;
    716  1.1  plunky 			break;
    717  1.1  plunky 
    718  1.1  plunky 		default:
    719  1.1  plunky 			return false;
    720  1.1  plunky 		}
    721  1.1  plunky 	}
    722  1.1  plunky 
    723  1.1  plunky 	return true;
    724  1.1  plunky }
    725  1.1  plunky 
    726  1.1  plunky void
    727  1.1  plunky sdp_data_print(const sdp_data_t *data, int indent)
    728  1.1  plunky {
    729  1.1  plunky 
    730  1.1  plunky 	if (!_sdp_data_print(data->next, data->end, indent))
    731  1.1  plunky 		printf("SDP data error\n");
    732  1.1  plunky }
    733