<sys/types.h>: Add definitions of bool, true and false for the kernel.
[dragonfly.git] / lib / libsdp / util.c
blob3a62c52b6ece60955f4bc2471fb027bd0f25fa8a
1 /* $NetBSD: util.c,v 1.1 2006/06/19 15:44:36 gdamore Exp $ */
2 /* $DragonFly: src/lib/libsdp/util.c,v 1.2 2008/09/30 16:57:05 swildner Exp $ */
4 /*-
5 * Copyright (c) 2006 Itronix Inc.
6 * All rights reserved.
8 * Written by Iain Hibbert for Itronix Inc.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. The name of Itronix Inc. may not be used to endorse
19 * or promote products derived from this software without specific
20 * prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY ITRONIX INC. ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
24 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ITRONIX INC. BE LIABLE FOR ANY
26 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
29 * ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
35 * util.c
37 * Copyright (c) 2001-2003 Maksim Yevmenkin <m_evmenkin@yahoo.com>
38 * All rights reserved.
40 * Redistribution and use in source and binary forms, with or without
41 * modification, are permitted provided that the following conditions
42 * are met:
43 * 1. Redistributions of source code must retain the above copyright
44 * notice, this list of conditions and the following disclaimer.
45 * 2. Redistributions in binary form must reproduce the above copyright
46 * notice, this list of conditions and the following disclaimer in the
47 * documentation and/or other materials provided with the distribution.
49 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
50 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
51 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
52 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
53 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
54 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
55 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
56 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
57 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
58 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
59 * SUCH DAMAGE.
61 * $Id: util.c,v 1.1 2006/06/19 15:44:36 gdamore Exp $
62 * $FreeBSD: src/lib/libsdp/util.c,v 1.5 2005/05/27 19:11:33 emax Exp $
65 #include <netinet/in.h>
66 #include <bluetooth.h>
67 #include <stdio.h>
68 #include <sdp.h>
71 * SDP attribute description
74 struct sdp_attr_desc {
75 uint32_t attr;
76 char const *desc;
78 typedef struct sdp_attr_desc sdp_attr_desc_t;
79 typedef struct sdp_attr_desc * sdp_attr_desc_p;
81 static sdp_attr_desc_t sdp_uuids_desc[] = {
82 { SDP_UUID_PROTOCOL_SDP, "SDP", },
83 { SDP_UUID_PROTOCOL_UDP, "UDP", },
84 { SDP_UUID_PROTOCOL_RFCOMM, "RFCOMM", },
85 { SDP_UUID_PROTOCOL_TCP, "TCP", },
86 { SDP_UUID_PROTOCOL_TCS_BIN, "TCS BIN", },
87 { SDP_UUID_PROTOCOL_TCS_AT, "TCS AT", },
88 { SDP_UUID_PROTOCOL_OBEX, "OBEX", },
89 { SDP_UUID_PROTOCOL_IP, "IP", },
90 { SDP_UUID_PROTOCOL_FTP, "FTP", },
91 { SDP_UUID_PROTOCOL_HTTP, "HTTP", },
92 { SDP_UUID_PROTOCOL_WSP, "WSP", },
93 { SDP_UUID_PROTOCOL_BNEP, "BNEP", },
94 { SDP_UUID_PROTOCOL_UPNP, "UPNP", },
95 { SDP_UUID_PROTOCOL_HIDP, "HIDP", },
96 { SDP_UUID_PROTOCOL_HARDCOPY_CONTROL_CHANNEL, "Hardcopy Control Channel", },
97 { SDP_UUID_PROTOCOL_HARDCOPY_DATA_CHANNEL, "Hardcopy Data Channel", },
98 { SDP_UUID_PROTOCOL_HARDCOPY_NOTIFICATION, "Hardcopy Notification", },
99 { SDP_UUID_PROTOCOL_AVCTP, "AVCTP", },
100 { SDP_UUID_PROTOCOL_AVDTP, "AVDTP", },
101 { SDP_UUID_PROTOCOL_CMPT, "CMPT", },
102 { SDP_UUID_PROTOCOL_UDI_C_PLANE, "UDI C-Plane", },
103 { SDP_UUID_PROTOCOL_L2CAP, "L2CAP", },
104 /* Service Class IDs/Bluetooth Profile IDs */
105 { SDP_SERVICE_CLASS_SERVICE_DISCOVERY_SERVER, "Service Discovery Server", },
106 { SDP_SERVICE_CLASS_BROWSE_GROUP_DESCRIPTOR, "Browse Group Descriptor", },
107 { SDP_SERVICE_CLASS_PUBLIC_BROWSE_GROUP, "Public Browse Group", },
108 { SDP_SERVICE_CLASS_SERIAL_PORT, "Serial Port", },
109 { SDP_SERVICE_CLASS_LAN_ACCESS_USING_PPP, "LAN Access Using PPP", },
110 { SDP_SERVICE_CLASS_DIALUP_NETWORKING, "Dial-Up Networking", },
111 { SDP_SERVICE_CLASS_IR_MC_SYNC, "IrMC Sync", },
112 { SDP_SERVICE_CLASS_OBEX_OBJECT_PUSH, "OBEX Object Push", },
113 { SDP_SERVICE_CLASS_OBEX_FILE_TRANSFER, "OBEX File Transfer", },
114 { SDP_SERVICE_CLASS_IR_MC_SYNC_COMMAND, "IrMC Sync Command", },
115 { SDP_SERVICE_CLASS_HEADSET, "Headset", },
116 { SDP_SERVICE_CLASS_CORDLESS_TELEPHONY, "Cordless Telephony", },
117 { SDP_SERVICE_CLASS_AUDIO_SOURCE, "Audio Source", },
118 { SDP_SERVICE_CLASS_AUDIO_SINK, "Audio Sink", },
119 { SDP_SERVICE_CLASS_AV_REMOTE_CONTROL_TARGET, "A/V Remote Control Target", },
120 { SDP_SERVICE_CLASS_ADVANCED_AUDIO_DISTRIBUTION, "Advanced Audio Distribution", },
121 { SDP_SERVICE_CLASS_AV_REMOTE_CONTROL, "A/V Remote Control", },
122 { SDP_SERVICE_CLASS_VIDEO_CONFERENCING, "Video Conferencing", },
123 { SDP_SERVICE_CLASS_INTERCOM, "Intercom", },
124 { SDP_SERVICE_CLASS_FAX, "Fax", },
125 { SDP_SERVICE_CLASS_HEADSET_AUDIO_GATEWAY, "Headset Audio Gateway", },
126 { SDP_SERVICE_CLASS_WAP, "WAP", },
127 { SDP_SERVICE_CLASS_WAP_CLIENT, "WAP Client", },
128 { SDP_SERVICE_CLASS_PANU, "PANU", },
129 { SDP_SERVICE_CLASS_NAP, "Network Access Point", },
130 { SDP_SERVICE_CLASS_GN, "GN", },
131 { SDP_SERVICE_CLASS_DIRECT_PRINTING, "Direct Printing", },
132 { SDP_SERVICE_CLASS_REFERENCE_PRINTING, "Reference Printing", },
133 { SDP_SERVICE_CLASS_IMAGING, "Imaging", },
134 { SDP_SERVICE_CLASS_IMAGING_RESPONDER, "Imaging Responder", },
135 { SDP_SERVICE_CLASS_IMAGING_AUTOMATIC_ARCHIVE, "Imaging Automatic Archive", },
136 { SDP_SERVICE_CLASS_IMAGING_REFERENCED_OBJECTS, "Imaging Referenced Objects", },
137 { SDP_SERVICE_CLASS_HANDSFREE, "Handsfree", },
138 { SDP_SERVICE_CLASS_HANDSFREE_AUDIO_GATEWAY, "Handsfree Audio Gateway", },
139 { SDP_SERVICE_CLASS_DIRECT_PRINTING_REFERENCE_OBJECTS, "Direct Printing Reference Objects", },
140 { SDP_SERVICE_CLASS_REFLECTED_UI, "Reflected UI", },
141 { SDP_SERVICE_CLASS_BASIC_PRINTING, "Basic Printing", },
142 { SDP_SERVICE_CLASS_PRINTING_STATUS, "Printing Status", },
143 { SDP_SERVICE_CLASS_HUMAN_INTERFACE_DEVICE, "Human Interface Device", },
144 { SDP_SERVICE_CLASS_HARDCOPY_CABLE_REPLACEMENT, "Hardcopy Cable Replacement", },
145 { SDP_SERVICE_CLASS_HCR_PRINT, "HCR Print", },
146 { SDP_SERVICE_CLASS_HCR_SCAN, "HCR Scan", },
147 { SDP_SERVICE_CLASS_COMMON_ISDN_ACCESS, "Common ISDN Access", },
148 { SDP_SERVICE_CLASS_VIDEO_CONFERENCING_GW, "Video Conferencing Gateway", },
149 { SDP_SERVICE_CLASS_UDI_MT, "UDI MT", },
150 { SDP_SERVICE_CLASS_UDI_TA, "UDI TA", },
151 { SDP_SERVICE_CLASS_AUDIO_VIDEO, "Audio/Video", },
152 { SDP_SERVICE_CLASS_SIM_ACCESS, "SIM Access", },
153 { SDP_SERVICE_CLASS_PNP_INFORMATION, "PNP Information", },
154 { SDP_SERVICE_CLASS_GENERIC_NETWORKING, "Generic Networking", },
155 { SDP_SERVICE_CLASS_GENERIC_FILE_TRANSFER, "Generic File Transfer", },
156 { SDP_SERVICE_CLASS_GENERIC_AUDIO, "Generic Audio", },
157 { SDP_SERVICE_CLASS_GENERIC_TELEPHONY, "Generic Telephony", },
158 { SDP_SERVICE_CLASS_UPNP, "UPNP", },
159 { SDP_SERVICE_CLASS_UPNP_IP, "UPNP IP", },
160 { SDP_SERVICE_CLASS_ESDP_UPNP_IP_PAN, "ESDP UPNP IP PAN", },
161 { SDP_SERVICE_CLASS_ESDP_UPNP_IP_LAP, "ESDP UPNP IP LAP", },
162 { SDP_SERVICE_CLASS_ESDP_UPNP_L2CAP, "ESDP UPNP L2CAP", },
163 { 0xffff, NULL, }
166 static sdp_attr_desc_t sdp_attrs_desc[] = {
167 { SDP_ATTR_SERVICE_RECORD_HANDLE,
168 "Record handle",
170 { SDP_ATTR_SERVICE_CLASS_ID_LIST,
171 "Service Class ID list",
173 { SDP_ATTR_SERVICE_RECORD_STATE,
174 "Service Record State",
176 { SDP_ATTR_SERVICE_ID,
177 "Service ID",
179 { SDP_ATTR_PROTOCOL_DESCRIPTOR_LIST,
180 "Protocol Descriptor List",
182 { SDP_ATTR_BROWSE_GROUP_LIST,
183 "Browse Group List",
185 { SDP_ATTR_LANGUAGE_BASE_ATTRIBUTE_ID_LIST,
186 "Language Base Attribute ID List",
188 { SDP_ATTR_SERVICE_INFO_TIME_TO_LIVE,
189 "Service Info Time-To-Live",
191 { SDP_ATTR_SERVICE_AVAILABILITY,
192 "Service Availability",
194 { SDP_ATTR_BLUETOOTH_PROFILE_DESCRIPTOR_LIST,
195 "Bluetooh Profile Descriptor List",
197 { SDP_ATTR_DOCUMENTATION_URL,
198 "Documentation URL",
200 { SDP_ATTR_CLIENT_EXECUTABLE_URL,
201 "Client Executable URL",
203 { SDP_ATTR_ICON_URL,
204 "Icon URL",
206 { SDP_ATTR_ADDITIONAL_PROTOCOL_DESCRIPTOR_LISTS,
207 "Additional Protocol Descriptor Lists" },
208 { SDP_ATTR_GROUP_ID,
209 /*SDP_ATTR_IP_SUBNET,
210 SDP_ATTR_VERSION_NUMBER_LIST*/
211 "Group ID/IP Subnet/Version Number List",
213 { SDP_ATTR_SERVICE_DATABASE_STATE,
214 "Service Database State",
216 { SDP_ATTR_SERVICE_VERSION,
217 "Service Version",
219 { SDP_ATTR_EXTERNAL_NETWORK,
220 /*SDP_ATTR_NETWORK,
221 SDP_ATTR_SUPPORTED_DATA_STORES_LIST*/
222 "External Network/Network/Supported Data Stores List",
224 { SDP_ATTR_FAX_CLASS1_SUPPORT,
225 /*SDP_ATTR_REMOTE_AUDIO_VOLUME_CONTROL*/
226 "Fax Class1 Support/Remote Audio Volume Control",
228 { SDP_ATTR_FAX_CLASS20_SUPPORT,
229 /*SDP_ATTR_SUPPORTED_FORMATS_LIST*/
230 "Fax Class20 Support/Supported Formats List",
232 { SDP_ATTR_FAX_CLASS2_SUPPORT,
233 "Fax Class2 Support",
235 { SDP_ATTR_AUDIO_FEEDBACK_SUPPORT,
236 "Audio Feedback Support",
238 { SDP_ATTR_NETWORK_ADDRESS,
239 "Network Address",
241 { SDP_ATTR_WAP_GATEWAY,
242 "WAP Gateway",
244 { SDP_ATTR_HOME_PAGE_URL,
245 "Home Page URL",
247 { SDP_ATTR_WAP_STACK_TYPE,
248 "WAP Stack Type",
250 { SDP_ATTR_SECURITY_DESCRIPTION,
251 "Security Description",
253 { SDP_ATTR_NET_ACCESS_TYPE,
254 "Net Access Type",
256 { SDP_ATTR_MAX_NET_ACCESS_RATE,
257 "Max Net Access Rate",
259 { SDP_ATTR_IPV4_SUBNET,
260 "IPv4 Subnet",
262 { SDP_ATTR_IPV6_SUBNET,
263 "IPv6 Subnet",
265 { SDP_ATTR_SUPPORTED_CAPABALITIES,
266 "Supported Capabalities",
268 { SDP_ATTR_SUPPORTED_FEATURES,
269 "Supported Features",
271 { SDP_ATTR_SUPPORTED_FUNCTIONS,
272 "Supported Functions",
274 { SDP_ATTR_TOTAL_IMAGING_DATA_CAPACITY,
275 "Total Imaging Data Capacity",
277 { 0xffff, NULL, }
280 char const *
281 sdp_attr2desc(uint16_t attr)
283 sdp_attr_desc_p a = sdp_attrs_desc;
285 for (; a->desc != NULL; a++)
286 if (attr == a->attr)
287 break;
289 return ((a->desc != NULL)? a->desc : "Unknown");
292 char const *
293 sdp_uuid2desc(uint16_t uuid)
295 sdp_attr_desc_p a = sdp_uuids_desc;
297 for (; a->desc != NULL; a++)
298 if (uuid == a->attr)
299 break;
301 return ((a->desc != NULL)? a->desc : "Unknown");
304 void
305 sdp_print(uint32_t level, uint8_t *start, uint8_t const *end)
307 union {
308 int8_t int8;
309 int16_t int16;
310 int32_t int32;
311 int64_t int64;
312 int128_t int128;
313 uint8_t uint8;
314 uint16_t uint16;
315 uint32_t uint32;
316 uint64_t uint64;
317 } value;
318 uint8_t type;
319 uint32_t i;
321 if (start == NULL || end == NULL)
322 return;
324 while (start < end) {
325 for (i = 0; i < level; i++)
326 printf("\t");
328 SDP_GET8(type, start);
330 switch (type) {
331 case SDP_DATA_NIL:
332 printf("nil\n");
333 break;
335 case SDP_DATA_UINT8:
336 SDP_GET8(value.uint8, start);
337 printf("uint8 %u\n", value.uint8);
338 break;
339 case SDP_DATA_UINT16:
340 SDP_GET16(value.uint16, start);
341 printf("uint16 %u\n", value.uint16);
342 break;
343 case SDP_DATA_UINT32:
344 SDP_GET32(value.uint32, start);
345 printf("uint32 %u\n", value.uint32);
346 break;
347 case SDP_DATA_UINT64:
348 SDP_GET64(value.uint64, start);
349 printf("uint64 %ju\n", value.uint64);
350 break;
352 case SDP_DATA_UINT128:
353 case SDP_DATA_INT128:
354 SDP_GET128(&value.int128, start);
355 printf("u/int128 0x"
356 "%2.2x%2.2x%2.2x%2.2x"
357 "%2.2x%2.2x%2.2x%2.2x"
358 "%2.2x%2.2x%2.2x%2.2x"
359 "%2.2x%2.2x%2.2x%2.2x\n",
360 value.int128.b[ 0], value.int128.b[ 1],
361 value.int128.b[ 2], value.int128.b[ 3],
362 value.int128.b[ 4], value.int128.b[ 5],
363 value.int128.b[ 6], value.int128.b[ 7],
364 value.int128.b[ 8], value.int128.b[ 9],
365 value.int128.b[10], value.int128.b[11],
366 value.int128.b[12], value.int128.b[13],
367 value.int128.b[14], value.int128.b[15]);
368 break;
370 case SDP_DATA_UUID128:
371 SDP_GET_UUID128(&value.int128, start);
372 printf("uuid128 0x"
373 "%2.2x%2.2x%2.2x%2.2x-"
374 "%2.2x%2.2x-"
375 "%2.2x%2.2x-"
376 "%2.2x%2.2x-"
377 "%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x\n",
378 value.int128.b[ 0], value.int128.b[ 1],
379 value.int128.b[ 2], value.int128.b[ 3],
380 value.int128.b[ 4], value.int128.b[ 5],
381 value.int128.b[ 6], value.int128.b[ 7],
382 value.int128.b[ 8], value.int128.b[ 9],
383 value.int128.b[10], value.int128.b[11],
384 value.int128.b[12], value.int128.b[13],
385 value.int128.b[14], value.int128.b[15]);
386 break;
388 case SDP_DATA_INT8:
389 SDP_GET8(value.int8, start);
390 printf("int8 %d\n", value.int8);
391 break;
392 case SDP_DATA_INT16:
393 SDP_GET16(value.int16, start);
394 printf("int16 %d\n", value.int16);
395 break;
396 case SDP_DATA_INT32:
397 SDP_GET32(value.int32, start);
398 printf("int32 %d\n", value.int32);
399 break;
400 case SDP_DATA_INT64:
401 SDP_GET64(value.int64, start);
402 printf("int64 %ju\n", value.int64);
403 break;
405 case SDP_DATA_UUID16:
406 SDP_GET16(value.uint16, start);
407 printf("uuid16 %#4.4x - %s\n", value.uint16,
408 sdp_uuid2desc(value.uint16));
409 break;
410 case SDP_DATA_UUID32:
411 SDP_GET32(value.uint32, start);
412 printf("uuid32 %#8.8x\n", value.uint32);
413 break;
415 case SDP_DATA_STR8:
416 SDP_GET8(value.uint8, start);
417 printf("str8 %*.*s\n", value.uint8, value.uint8, start);
418 start += value.uint8;
419 break;
420 case SDP_DATA_STR16:
421 SDP_GET16(value.uint16, start);
422 printf("str16 %*.*s\n", value.uint16, value.uint16, start);
423 start += value.uint16;
424 break;
425 case SDP_DATA_STR32:
426 SDP_GET32(value.uint32, start);
427 printf("str32 %*.*s\n", value.uint32, value.uint32, start);
428 start += value.uint32;
429 break;
431 case SDP_DATA_BOOL:
432 SDP_GET8(value.uint8, start);
433 printf("bool %d\n", value.uint8);
434 break;
436 case SDP_DATA_SEQ8:
437 SDP_GET8(value.uint8, start);
438 printf("seq8 %d\n", value.uint8);
439 sdp_print(level + 1, start, start + value.uint8);
440 start += value.uint8;
441 break;
442 case SDP_DATA_SEQ16:
443 SDP_GET16(value.uint16, start);
444 printf("seq16 %d\n", value.uint16);
445 sdp_print(level + 1, start, start + value.uint16);
446 start += value.uint16;
447 break;
448 case SDP_DATA_SEQ32:
449 SDP_GET32(value.uint32, start);
450 printf("seq32 %d\n", value.uint32);
451 sdp_print(level + 1, start, start + value.uint32);
452 start += value.uint32;
453 break;
455 case SDP_DATA_ALT8:
456 SDP_GET8(value.uint8, start);
457 printf("alt8 %d\n", value.uint8);
458 sdp_print(level + 1, start, start + value.uint8);
459 start += value.uint8;
460 break;
461 case SDP_DATA_ALT16:
462 SDP_GET16(value.uint16, start);
463 printf("alt16 %d\n", value.uint16);
464 sdp_print(level + 1, start, start + value.uint16);
465 start += value.uint16;
466 break;
467 case SDP_DATA_ALT32:
468 SDP_GET32(value.uint32, start);
469 printf("alt32 %d\n", value.uint32);
470 sdp_print(level + 1, start, start + value.uint32);
471 start += value.uint32;
472 break;
474 case SDP_DATA_URL8:
475 SDP_GET8(value.uint8, start);
476 printf("url8 %*.*s\n", value.uint8, value.uint8, start);
477 start += value.uint8;
478 break;
479 case SDP_DATA_URL16:
480 SDP_GET16(value.uint16, start);
481 printf("url16 %*.*s\n", value.uint16, value.uint16, start);
482 start += value.uint16;
483 break;
484 case SDP_DATA_URL32:
485 SDP_GET32(value.uint32, start);
486 printf("url32 %*.*s\n", value.uint32, value.uint32, start);
487 start += value.uint32;
488 break;
490 default:
491 printf("unknown data type: %#02x\n", *start ++);
492 break;