4 * Copyright (c) 2006 Itronix Inc.
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
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.
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
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
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>
73 * SDP attribute description
76 struct sdp_attr_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", },
168 static sdp_attr_desc_t sdp_attrs_desc
[] = {
169 { SDP_ATTR_SERVICE_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
,
181 { SDP_ATTR_PROTOCOL_DESCRIPTOR_LIST
,
182 "Protocol Descriptor List",
184 { SDP_ATTR_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
,
202 { SDP_ATTR_CLIENT_EXECUTABLE_URL
,
203 "Client Executable URL",
208 { SDP_ATTR_ADDITIONAL_PROTOCOL_DESCRIPTOR_LISTS
,
209 "Additional Protocol Descriptor Lists" },
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
,
221 { SDP_ATTR_EXTERNAL_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
,
243 { SDP_ATTR_WAP_GATEWAY
,
246 { SDP_ATTR_HOME_PAGE_URL
,
249 { SDP_ATTR_WAP_STACK_TYPE
,
252 { SDP_ATTR_SECURITY_DESCRIPTION
,
253 "Security Description",
255 { SDP_ATTR_NET_ACCESS_TYPE
,
258 { SDP_ATTR_MAX_NET_ACCESS_RATE
,
259 "Max Net Access Rate",
261 { SDP_ATTR_IPV4_SUBNET
,
264 { SDP_ATTR_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",
283 sdp_attr2desc(uint16_t attr
)
285 register sdp_attr_desc_p a
= sdp_attrs_desc
;
287 for (; a
->desc
!= NULL
; a
++)
291 return ((a
->desc
!= NULL
)? a
->desc
: "Unknown");
295 sdp_uuid2desc(uint16_t uuid
)
297 register sdp_attr_desc_p a
= sdp_uuids_desc
;
299 for (; a
->desc
!= NULL
; a
++)
303 return ((a
->desc
!= NULL
)? a
->desc
: "Unknown");
307 sdp_print(uint32_t level
, uint8_t *start
, uint8_t const *end
)
323 if (start
== NULL
|| end
== NULL
)
326 while (start
< end
) {
327 for (i
= 0; i
< level
; i
++)
330 SDP_GET8(type
, start
);
338 SDP_GET8(value
.uint8
, start
);
339 printf("uint8 %u\n", value
.uint8
);
341 case SDP_DATA_UINT16
:
342 SDP_GET16(value
.uint16
, start
);
343 printf("uint16 %u\n", value
.uint16
);
345 case SDP_DATA_UINT32
:
346 SDP_GET32(value
.uint32
, start
);
347 printf("uint32 %u\n", value
.uint32
);
349 case SDP_DATA_UINT64
:
350 SDP_GET64(value
.uint64
, start
);
351 printf("uint64 %ju\n", value
.uint64
);
354 case SDP_DATA_UINT128
:
355 case SDP_DATA_INT128
:
356 SDP_GET128(&value
.int128
, start
);
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]);
372 case SDP_DATA_UUID128
:
373 SDP_GET_UUID128(&value
.int128
, start
);
375 "%2.2x%2.2x%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]);
391 SDP_GET8(value
.int8
, start
);
392 printf("int8 %d\n", value
.int8
);
395 SDP_GET16(value
.int16
, start
);
396 printf("int16 %d\n", value
.int16
);
399 SDP_GET32(value
.int32
, start
);
400 printf("int32 %d\n", value
.int32
);
403 SDP_GET64(value
.int64
, start
);
404 printf("int64 %ju\n", value
.int64
);
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
));
412 case SDP_DATA_UUID32
:
413 SDP_GET32(value
.uint32
, start
);
414 printf("uuid32 %#8.8x\n", value
.uint32
);
418 SDP_GET8(value
.uint8
, start
);
419 printf("str8 %*.*s\n", value
.uint8
, value
.uint8
, start
);
420 start
+= value
.uint8
;
423 SDP_GET16(value
.uint16
, start
);
424 printf("str16 %*.*s\n", value
.uint16
, value
.uint16
, start
);
425 start
+= value
.uint16
;
428 SDP_GET32(value
.uint32
, start
);
429 printf("str32 %*.*s\n", value
.uint32
, value
.uint32
, start
);
430 start
+= value
.uint32
;
434 SDP_GET8(value
.uint8
, start
);
435 printf("bool %d\n", value
.uint8
);
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
;
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
;
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
;
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
;
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
;
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
;
477 SDP_GET8(value
.uint8
, start
);
478 printf("url8 %*.*s\n", value
.uint8
, value
.uint8
, start
);
479 start
+= value
.uint8
;
482 SDP_GET16(value
.uint16
, start
);
483 printf("url16 %*.*s\n", value
.uint16
, value
.uint16
, start
);
484 start
+= value
.uint16
;
487 SDP_GET32(value
.uint32
, start
);
488 printf("url32 %*.*s\n", value
.uint32
, value
.uint32
, start
);
489 start
+= value
.uint32
;
493 printf("unknown data type: %#02x\n", *start
++);