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