print.c revision 1.2 1 1.2 plunky /* $NetBSD: print.c,v 1.2 2009/07/04 16:01:15 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.2 plunky __RCSID("$NetBSD: print.c,v 1.2 2009/07/04 16:01:15 plunky Exp $");
34 1.1 plunky
35 1.1 plunky #include <ctype.h>
36 1.1 plunky #include <iconv.h>
37 1.1 plunky #include <langinfo.h>
38 1.1 plunky #include <sdp.h>
39 1.1 plunky #include <stdbool.h>
40 1.1 plunky #include <stdio.h>
41 1.1 plunky #include <stdlib.h>
42 1.1 plunky #include <string.h>
43 1.1 plunky #include <uuid.h>
44 1.1 plunky #include <vis.h>
45 1.1 plunky
46 1.1 plunky #include "sdpquery.h"
47 1.1 plunky
48 1.1 plunky typedef struct {
49 1.1 plunky uint16_t id;
50 1.1 plunky const char * desc;
51 1.1 plunky void (*print)(sdp_data_t *);
52 1.1 plunky } attr_t;
53 1.1 plunky
54 1.1 plunky typedef struct {
55 1.1 plunky uint16_t class;
56 1.1 plunky const char * desc;
57 1.1 plunky attr_t * attrs;
58 1.1 plunky size_t nattr;
59 1.1 plunky } service_t;
60 1.1 plunky
61 1.1 plunky typedef struct {
62 1.1 plunky uint16_t base;
63 1.1 plunky const char * codeset;
64 1.1 plunky } language_t;
65 1.1 plunky
66 1.1 plunky static const char *string_uuid(uuid_t *);
67 1.1 plunky static const char *string_vis(int, const char *, size_t);
68 1.1 plunky
69 1.1 plunky static void print_hexdump(const char *, const uint8_t *, size_t);
70 1.1 plunky static bool print_attribute(uint16_t, sdp_data_t *, attr_t *, int);
71 1.1 plunky static bool print_universal_attribute(uint16_t, sdp_data_t *);
72 1.1 plunky static bool print_language_attribute(uint16_t, sdp_data_t *);
73 1.1 plunky static bool print_service_attribute(uint16_t, sdp_data_t *);
74 1.1 plunky
75 1.1 plunky static void print_bool(sdp_data_t *);
76 1.1 plunky static void print_uint8x(sdp_data_t *);
77 1.1 plunky static void print_uint16d(sdp_data_t *);
78 1.2 plunky static void print_uint16x(sdp_data_t *);
79 1.1 plunky static void print_uint32x(sdp_data_t *);
80 1.1 plunky static void print_uint32d(sdp_data_t *);
81 1.1 plunky static void print_uuid(sdp_data_t *);
82 1.1 plunky static void print_uuid_list(sdp_data_t *);
83 1.1 plunky static void print_string(sdp_data_t *);
84 1.1 plunky static void print_url(sdp_data_t *);
85 1.1 plunky static void print_profile_version(sdp_data_t *);
86 1.1 plunky static void print_language_string(sdp_data_t *);
87 1.1 plunky
88 1.1 plunky static void print_service_class_id_list(sdp_data_t *);
89 1.1 plunky static void print_protocol_descriptor(sdp_data_t *);
90 1.1 plunky static void print_protocol_descriptor_list(sdp_data_t *);
91 1.1 plunky static void print_language_base_attribute_id_list(sdp_data_t *);
92 1.1 plunky static void print_service_availability(sdp_data_t *);
93 1.1 plunky static void print_bluetooth_profile_descriptor_list(sdp_data_t *);
94 1.1 plunky static void print_additional_protocol_descriptor_lists(sdp_data_t *);
95 1.1 plunky static void print_sds_version_number_list(sdp_data_t *);
96 1.1 plunky static void print_ct_network(sdp_data_t *);
97 1.1 plunky static void print_asrc_features(sdp_data_t *);
98 1.1 plunky static void print_asink_features(sdp_data_t *);
99 1.1 plunky static void print_avrcp_features(sdp_data_t *);
100 1.1 plunky static void print_supported_data_stores(sdp_data_t *);
101 1.1 plunky static void print_supported_formats(sdp_data_t *);
102 1.1 plunky static void print_hid_version(sdp_data_t *);
103 1.1 plunky static void print_hid_device_subclass(sdp_data_t *);
104 1.1 plunky static void print_hid_descriptor_list(sdp_data_t *);
105 1.1 plunky static void print_security_description(sdp_data_t *);
106 1.1 plunky static void print_hf_features(sdp_data_t *);
107 1.1 plunky static void print_hfag_network(sdp_data_t *);
108 1.1 plunky static void print_hfag_features(sdp_data_t *);
109 1.1 plunky static void print_net_access_type(sdp_data_t *);
110 1.2 plunky static void print_pnp_source(sdp_data_t *);
111 1.1 plunky
112 1.1 plunky static void print_rfcomm(sdp_data_t *);
113 1.1 plunky static void print_bnep(sdp_data_t *);
114 1.1 plunky static void print_avctp(sdp_data_t *);
115 1.1 plunky static void print_avdtp(sdp_data_t *);
116 1.1 plunky static void print_l2cap(sdp_data_t *);
117 1.1 plunky
118 1.1 plunky attr_t protocol_list[] = {
119 1.1 plunky { 0x0001, "SDP", NULL },
120 1.1 plunky { 0x0002, "UDP", NULL },
121 1.1 plunky { 0x0003, "RFCOMM", print_rfcomm },
122 1.1 plunky { 0x0004, "TCP", NULL },
123 1.1 plunky { 0x0005, "TCS_BIN", NULL },
124 1.1 plunky { 0x0006, "TCS_AT", NULL },
125 1.1 plunky { 0x0008, "OBEX", NULL },
126 1.1 plunky { 0x0009, "IP", NULL },
127 1.1 plunky { 0x000a, "FTP", NULL },
128 1.1 plunky { 0x000c, "HTTP", NULL },
129 1.1 plunky { 0x000e, "WSP", NULL },
130 1.1 plunky { 0x000f, "BNEP", print_bnep },
131 1.1 plunky { 0x0010, "UPNP", NULL },
132 1.1 plunky { 0x0011, "HIDP", NULL },
133 1.1 plunky { 0x0012, "HARDCOPY_CONTROL_CHANNEL", NULL },
134 1.1 plunky { 0x0014, "HARDCOPY_DATA_CHANNEL", NULL },
135 1.1 plunky { 0x0016, "HARDCOPY_NOTIFICATION", NULL },
136 1.1 plunky { 0x0017, "AVCTP", print_avctp },
137 1.1 plunky { 0x0019, "AVDTP", print_avdtp },
138 1.1 plunky { 0x001b, "CMTP", NULL },
139 1.1 plunky { 0x001d, "UDI_C_PLANE", NULL },
140 1.1 plunky { 0x0100, "L2CAP", print_l2cap },
141 1.1 plunky };
142 1.1 plunky
143 1.1 plunky attr_t universal_attrs[] = {
144 1.1 plunky { 0x0000, "ServiceRecordHandle", print_uint32x },
145 1.1 plunky { 0x0001, "ServiceClassIDList", print_service_class_id_list },
146 1.1 plunky { 0x0002, "ServiceRecordState", print_uint32x },
147 1.1 plunky { 0x0003, "ServiceID", print_uuid },
148 1.1 plunky { 0x0004, "ProtocolDescriptorList", print_protocol_descriptor_list },
149 1.1 plunky { 0x0005, "BrowseGroupList", print_uuid_list },
150 1.1 plunky { 0x0006, "LanguageBaseAttributeIDList", print_language_base_attribute_id_list },
151 1.1 plunky { 0x0007, "ServiceInfoTimeToLive", print_uint32d },
152 1.1 plunky { 0x0008, "ServiceAvailability", print_service_availability },
153 1.1 plunky { 0x0009, "BluetoothProfileDescriptorList", print_bluetooth_profile_descriptor_list },
154 1.1 plunky { 0x000a, "DocumentationURL", print_url },
155 1.1 plunky { 0x000b, "ClientExecutableURL", print_url },
156 1.1 plunky { 0x000c, "IconURL", print_url },
157 1.1 plunky { 0x000d, "AdditionalProtocolDescriptorLists", print_additional_protocol_descriptor_lists },
158 1.1 plunky };
159 1.1 plunky
160 1.1 plunky attr_t language_attrs[] = { /* Language Attribute Offsets */
161 1.1 plunky { 0x0000, "ServiceName", print_language_string },
162 1.1 plunky { 0x0001, "ServiceDescription", print_language_string },
163 1.1 plunky { 0x0002, "ProviderName", print_language_string },
164 1.1 plunky };
165 1.1 plunky
166 1.1 plunky attr_t sds_attrs[] = { /* Service Discovery Server */
167 1.1 plunky { 0x0200, "VersionNumberList", print_sds_version_number_list },
168 1.1 plunky { 0x0201, "ServiceDatabaseState", print_uint32x },
169 1.1 plunky };
170 1.1 plunky
171 1.1 plunky attr_t bgd_attrs[] = { /* Browse Group Descriptor */
172 1.1 plunky { 0x0200, "GroupID", print_uuid },
173 1.1 plunky };
174 1.1 plunky
175 1.1 plunky attr_t ct_attrs[] = { /* Cordless Telephony */
176 1.1 plunky { 0x0301, "ExternalNetwork", print_ct_network },
177 1.1 plunky };
178 1.1 plunky
179 1.1 plunky attr_t asrc_attrs[] = { /* Audio Source */
180 1.1 plunky { 0x0311, "SupportedFeatures", print_asrc_features },
181 1.1 plunky };
182 1.1 plunky
183 1.1 plunky attr_t asink_attrs[] = { /* Audio Sink */
184 1.1 plunky { 0x0311, "SupportedFeatures", print_asink_features },
185 1.1 plunky };
186 1.1 plunky
187 1.1 plunky attr_t avrcp_attrs[] = { /* Audio Video Remote Control Profile */
188 1.1 plunky { 0x0311, "SupportedFeatures", print_avrcp_features },
189 1.1 plunky };
190 1.1 plunky
191 1.1 plunky attr_t lan_attrs[] = { /* LAN Access Using PPP */
192 1.1 plunky { 0x0200, "IPSubnet", print_string },
193 1.1 plunky };
194 1.1 plunky
195 1.1 plunky attr_t dun_attrs[] = { /* Dialup Networking */
196 1.1 plunky { 0x0305, "AudioFeedbackSupport", print_bool },
197 1.1 plunky };
198 1.1 plunky
199 1.1 plunky attr_t irmc_sync_attrs[] = { /* IrMC Sync */
200 1.1 plunky { 0x0301, "SupportedDataStoresList", print_supported_data_stores },
201 1.1 plunky };
202 1.1 plunky
203 1.1 plunky attr_t opush_attrs[] = { /* Object Push */
204 1.1 plunky { 0x0303, "SupportedFormatsList", print_supported_formats },
205 1.1 plunky };
206 1.1 plunky
207 1.1 plunky attr_t hset_attrs[] = { /* Headset */
208 1.1 plunky { 0x0302, "RemoteAudioVolumeControl", print_bool },
209 1.1 plunky };
210 1.1 plunky
211 1.1 plunky attr_t fax_attrs[] = { /* Fax */
212 1.1 plunky { 0x0302, "FAXClass1", print_bool },
213 1.1 plunky { 0x0303, "FAXClass2.0", print_bool },
214 1.1 plunky { 0x0304, "FAXClass2", print_bool },
215 1.1 plunky { 0x0305, "AudioFeedbackSupport", print_bool },
216 1.1 plunky };
217 1.1 plunky
218 1.1 plunky attr_t panu_attrs[] = { /* Personal Area Networking User */
219 1.1 plunky { 0x030a, "SecurityDescription", print_security_description },
220 1.1 plunky };
221 1.1 plunky
222 1.1 plunky attr_t nap_attrs[] = { /* Network Access Point */
223 1.1 plunky { 0x030a, "SecurityDescription", print_security_description },
224 1.1 plunky { 0x030b, "NetAccessType", print_net_access_type },
225 1.1 plunky { 0x030c, "MaxNetAccessRate", print_uint32d },
226 1.1 plunky { 0x030d, "IPv4Subnet", print_string },
227 1.1 plunky { 0x030e, "IPv6Subnet", print_string },
228 1.1 plunky };
229 1.1 plunky
230 1.1 plunky attr_t gn_attrs[] = { /* Group Network */
231 1.1 plunky { 0x030a, "SecurityDescription", print_security_description },
232 1.1 plunky { 0x030d, "IPv4Subnet", print_string },
233 1.1 plunky { 0x030e, "IPv6Subnet", print_string },
234 1.1 plunky };
235 1.1 plunky
236 1.1 plunky attr_t hf_attrs[] = { /* Handsfree */
237 1.1 plunky { 0x0311, "SupportedFeatures", print_hf_features },
238 1.1 plunky };
239 1.1 plunky
240 1.1 plunky attr_t hfag_attrs[] = { /* Handsfree Audio Gateway */
241 1.1 plunky { 0x0301, "Network", print_hfag_network },
242 1.1 plunky { 0x0311, "SupportedFeatures", print_hfag_features },
243 1.1 plunky };
244 1.1 plunky
245 1.1 plunky attr_t hid_attrs[] = { /* Human Interface Device */
246 1.1 plunky { 0x0200, "HIDDeviceReleaseNumber", print_hid_version },
247 1.1 plunky { 0x0201, "HIDParserVersion", print_hid_version },
248 1.1 plunky { 0x0202, "HIDDeviceSubClass", print_hid_device_subclass },
249 1.1 plunky { 0x0203, "HIDCountryCode", print_uint8x },
250 1.1 plunky { 0x0204, "HIDVirtualCable", print_bool },
251 1.1 plunky { 0x0205, "HIDReconnectInitiate", print_bool },
252 1.1 plunky { 0x0206, "HIDDescriptorList", print_hid_descriptor_list },
253 1.1 plunky { 0x0207, "HIDLANGIDBaseList", NULL },
254 1.1 plunky { 0x0208, "HIDSDPDisable", print_bool },
255 1.1 plunky { 0x0209, "HIDBatteryPower", print_bool },
256 1.1 plunky { 0x020a, "HIDRemoteWake", print_bool },
257 1.1 plunky { 0x020b, "HIDProfileVersion", print_profile_version },
258 1.1 plunky { 0x020c, "HIDSupervisionTimeout", print_uint16d },
259 1.1 plunky { 0x020d, "HIDNormallyConnectable", print_bool },
260 1.1 plunky { 0x020e, "HIDBootDevice", print_bool },
261 1.1 plunky };
262 1.1 plunky
263 1.2 plunky attr_t pnp_attrs[] = { /* Device ID */
264 1.2 plunky { 0x0200, "SpecificationID", print_profile_version },
265 1.2 plunky { 0x0201, "VendorID", print_uint16x },
266 1.2 plunky { 0x0202, "ProductID", print_uint16x },
267 1.2 plunky { 0x0203, "Version", print_hid_version },
268 1.2 plunky { 0x0204, "PrimaryRecord", print_bool },
269 1.2 plunky { 0x0205, "VendorIDSource", print_pnp_source },
270 1.2 plunky };
271 1.2 plunky
272 1.1 plunky #define A(a) a, __arraycount(a)
273 1.1 plunky service_t service_list[] = {
274 1.1 plunky { 0x1000, "Service Discovery Server", A(sds_attrs) },
275 1.1 plunky { 0x1001, "Browse Group Descriptor", A(bgd_attrs) },
276 1.1 plunky { 0x1002, "Public Browse Root", NULL, 0 },
277 1.1 plunky { 0x1101, "Serial Port", NULL, 0 },
278 1.1 plunky { 0x1102, "LAN Access Using PPP", A(lan_attrs) },
279 1.1 plunky { 0x1103, "Dialup Networking", A(dun_attrs) },
280 1.1 plunky { 0x1104, "IrMC Sync", A(irmc_sync_attrs) },
281 1.1 plunky { 0x1105, "Object Push", A(opush_attrs) },
282 1.1 plunky { 0x1106, "File Transfer", NULL, 0 },
283 1.1 plunky { 0x1107, "IrMC Sync Command", NULL, 0 },
284 1.1 plunky { 0x1108, "Headset", A(hset_attrs) },
285 1.1 plunky { 0x1109, "Cordless Telephony", A(ct_attrs) },
286 1.1 plunky { 0x110a, "Audio Source", A(asrc_attrs) },
287 1.1 plunky { 0x110b, "Audio Sink", A(asink_attrs) },
288 1.1 plunky { 0x110c, "A/V Remote Control Target", A(avrcp_attrs) },
289 1.1 plunky { 0x110d, "Advanced Audio Distribution", NULL, 0 },
290 1.1 plunky { 0x110e, "A/V Remote Control", A(avrcp_attrs) },
291 1.1 plunky { 0x110f, "Video Conferencing", NULL, 0 },
292 1.1 plunky { 0x1110, "Intercom", NULL, 0 },
293 1.1 plunky { 0x1111, "Fax", A(fax_attrs) },
294 1.1 plunky { 0x1112, "Headset Audio Gateway", NULL, 0 },
295 1.1 plunky { 0x1113, "WAP", NULL, 0 },
296 1.1 plunky { 0x1114, "WAP Client", NULL, 0 },
297 1.1 plunky { 0x1115, "Personal Area Networking User", A(panu_attrs) },
298 1.1 plunky { 0x1116, "Network Access Point", A(nap_attrs) },
299 1.1 plunky { 0x1117, "Group Network", A(gn_attrs) },
300 1.1 plunky { 0x1118, "Direct Printing", NULL, 0 },
301 1.1 plunky { 0x1119, "Reference Printing", NULL, 0 },
302 1.1 plunky { 0x111a, "Imaging", NULL, 0 },
303 1.1 plunky { 0x111b, "Imaging Responder", NULL, 0 },
304 1.1 plunky { 0x111c, "Imaging Automatic Archive", NULL, 0 },
305 1.1 plunky { 0x111d, "Imaging Referenced Objects", NULL, 0 },
306 1.1 plunky { 0x111e, "Handsfree", A(hf_attrs) },
307 1.1 plunky { 0x111f, "Handsfree Audio Gateway", A(hfag_attrs) },
308 1.1 plunky { 0x1120, "Direct Printing Reference Objects", NULL, 0 },
309 1.1 plunky { 0x1121, "Reflected User Interface", NULL, 0 },
310 1.1 plunky { 0x1122, "Basic Printing", NULL, 0 },
311 1.1 plunky { 0x1123, "Printing Status", NULL, 0 },
312 1.1 plunky { 0x1124, "Human Interface Device", A(hid_attrs) },
313 1.1 plunky { 0x1125, "Hardcopy Cable Replacement", NULL, 0 },
314 1.1 plunky { 0x1126, "Hardcopy Cable Replacement Print", NULL, 0 },
315 1.1 plunky { 0x1127, "Hardcopy Cable Replacement Scan", NULL, 0 },
316 1.1 plunky { 0x1128, "Common ISDN Access", NULL, 0 },
317 1.1 plunky { 0x1129, "Video Conferencing GW", NULL, 0 },
318 1.1 plunky { 0x112a, "UDI MT", NULL, 0 },
319 1.1 plunky { 0x112b, "UDI TA", NULL, 0 },
320 1.1 plunky { 0x112c, "Audio/Video", NULL, 0 },
321 1.1 plunky { 0x112d, "SIM Access", NULL, 0 },
322 1.2 plunky { 0x1200, "PNP Information", A(pnp_attrs) },
323 1.1 plunky { 0x1201, "Generic Networking", NULL, 0 },
324 1.1 plunky { 0x1202, "Generic File Transfer", NULL, 0 },
325 1.1 plunky { 0x1203, "Generic Audio", NULL, 0 },
326 1.1 plunky { 0x1204, "Generic Telephony", NULL, 0 },
327 1.1 plunky { 0x1205, "UPNP", NULL, 0 },
328 1.1 plunky { 0x1206, "UPNP IP", NULL, 0 },
329 1.1 plunky { 0x1300, "UPNP IP PAN", NULL, 0 },
330 1.1 plunky { 0x1301, "UPNP IP LAP", NULL, 0 },
331 1.1 plunky { 0x1302, "UPNP IP L2CAP", NULL, 0 },
332 1.1 plunky };
333 1.1 plunky #undef A
334 1.1 plunky
335 1.1 plunky /* extracted Service Class ID List */
336 1.1 plunky #define MAX_SERVICES 16
337 1.1 plunky static size_t nservices;
338 1.1 plunky static uint16_t service_class[MAX_SERVICES];
339 1.1 plunky
340 1.1 plunky /* extracted Language Base Attribute ID List */
341 1.1 plunky #define MAX_LANGUAGES 16
342 1.1 plunky static int nlanguages;
343 1.1 plunky static language_t language[MAX_LANGUAGES];
344 1.1 plunky static int current;
345 1.1 plunky
346 1.1 plunky static bool
347 1.1 plunky sdp_get_uint8(sdp_data_t *d, uint8_t *vp)
348 1.1 plunky {
349 1.1 plunky uintmax_t v;
350 1.1 plunky
351 1.1 plunky if (sdp_data_type(d) != SDP_DATA_UINT8
352 1.1 plunky || !sdp_get_uint(d, &v))
353 1.1 plunky return false;
354 1.1 plunky
355 1.1 plunky *vp = (uint8_t)v;
356 1.1 plunky return true;
357 1.1 plunky }
358 1.1 plunky
359 1.1 plunky static bool
360 1.1 plunky sdp_get_uint16(sdp_data_t *d, uint16_t *vp)
361 1.1 plunky {
362 1.1 plunky uintmax_t v;
363 1.1 plunky
364 1.1 plunky if (sdp_data_type(d) != SDP_DATA_UINT16
365 1.1 plunky || !sdp_get_uint(d, &v))
366 1.1 plunky return false;
367 1.1 plunky
368 1.1 plunky *vp = (uint16_t)v;
369 1.1 plunky return true;
370 1.1 plunky }
371 1.1 plunky
372 1.1 plunky static bool
373 1.1 plunky sdp_get_uint32(sdp_data_t *d, uint32_t *vp)
374 1.1 plunky {
375 1.1 plunky uintmax_t v;
376 1.1 plunky
377 1.1 plunky if (sdp_data_type(d) != SDP_DATA_UINT32
378 1.1 plunky || !sdp_get_uint(d, &v))
379 1.1 plunky return false;
380 1.1 plunky
381 1.1 plunky *vp = (uint32_t)v;
382 1.1 plunky return true;
383 1.1 plunky }
384 1.1 plunky
385 1.1 plunky void
386 1.1 plunky print_record(sdp_data_t *rec)
387 1.1 plunky {
388 1.1 plunky sdp_data_t value;
389 1.1 plunky uint16_t id;
390 1.1 plunky
391 1.1 plunky nservices = 0;
392 1.1 plunky nlanguages = 0;
393 1.1 plunky current = -1;
394 1.1 plunky
395 1.1 plunky while (sdp_get_attr(rec, &id, &value)) {
396 1.1 plunky if (Xflag) {
397 1.1 plunky printf("AttributeID 0x%04x:\n", id);
398 1.1 plunky print_hexdump(" ", value.next, value.end - value.next);
399 1.1 plunky } else if (Rflag) {
400 1.1 plunky printf("AttributeID 0x%04x:\n", id);
401 1.1 plunky sdp_data_print(&value, 4);
402 1.1 plunky } else if (print_universal_attribute(id, &value)
403 1.1 plunky || print_language_attribute(id, &value)
404 1.1 plunky || print_service_attribute(id, &value)) {
405 1.1 plunky if (value.next != value.end)
406 1.1 plunky printf(" [additional data ignored]\n");
407 1.1 plunky } else {
408 1.1 plunky printf("AttributeID 0x%04x:\n", id);
409 1.1 plunky sdp_data_print(&value, 4);
410 1.1 plunky }
411 1.1 plunky }
412 1.1 plunky }
413 1.1 plunky
414 1.1 plunky static const char *
415 1.1 plunky string_uuid(uuid_t *uuid)
416 1.1 plunky {
417 1.1 plunky static char buf[64];
418 1.1 plunky const char *desc;
419 1.1 plunky uuid_t u;
420 1.1 plunky size_t i;
421 1.1 plunky
422 1.1 plunky u = *uuid;
423 1.1 plunky u.time_low = 0;
424 1.1 plunky if (!uuid_equal(&u, &BLUETOOTH_BASE_UUID, NULL)) {
425 1.1 plunky snprintf(buf, sizeof(buf),
426 1.1 plunky "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
427 1.1 plunky uuid->time_low, uuid->time_mid, uuid->time_hi_and_version,
428 1.1 plunky uuid->clock_seq_hi_and_reserved, uuid->clock_seq_low,
429 1.1 plunky uuid->node[0], uuid->node[1], uuid->node[2],
430 1.1 plunky uuid->node[3], uuid->node[4], uuid->node[5]);
431 1.1 plunky
432 1.1 plunky return buf;
433 1.1 plunky }
434 1.1 plunky
435 1.1 plunky desc = NULL;
436 1.1 plunky for (i = 0; i < __arraycount(service_list); i++) {
437 1.1 plunky if (uuid->time_low == service_list[i].class) {
438 1.1 plunky desc = service_list[i].desc;
439 1.1 plunky break;
440 1.1 plunky }
441 1.1 plunky }
442 1.1 plunky
443 1.1 plunky for (i = 0; i < __arraycount(protocol_list); i++) {
444 1.1 plunky if (uuid->time_low == protocol_list[i].id) {
445 1.1 plunky desc = protocol_list[i].desc;
446 1.1 plunky break;
447 1.1 plunky }
448 1.1 plunky }
449 1.1 plunky
450 1.1 plunky if (!Nflag && desc) {
451 1.1 plunky snprintf(buf, sizeof(buf), "%s", desc);
452 1.1 plunky return buf;
453 1.1 plunky }
454 1.1 plunky
455 1.1 plunky snprintf(buf, sizeof(buf), "%s%s(0x%*.*x)",
456 1.1 plunky (desc == NULL ? "" : desc),
457 1.1 plunky (desc == NULL ? "" : " "),
458 1.1 plunky (uuid->time_low > UINT16_MAX ? 8 : 4),
459 1.1 plunky (uuid->time_low > UINT16_MAX ? 8 : 4),
460 1.1 plunky uuid->time_low);
461 1.1 plunky
462 1.1 plunky return buf;
463 1.1 plunky }
464 1.1 plunky
465 1.1 plunky static const char *
466 1.1 plunky string_vis(int style, const char *src, size_t len)
467 1.1 plunky {
468 1.1 plunky static char buf[50];
469 1.1 plunky char *dst = buf;
470 1.1 plunky
471 1.1 plunky style |= VIS_NL;
472 1.1 plunky while (len > 0 && (dst + 5) < (buf + sizeof(buf))) {
473 1.1 plunky dst = vis(dst, src[0], style, (len > 1 ? src[1] : 0));
474 1.1 plunky src++;
475 1.1 plunky len--;
476 1.1 plunky }
477 1.1 plunky
478 1.1 plunky return buf;
479 1.1 plunky }
480 1.1 plunky
481 1.1 plunky static void
482 1.1 plunky print_hexdump(const char *title, const uint8_t *data, size_t len)
483 1.1 plunky {
484 1.1 plunky int n, i;
485 1.1 plunky
486 1.1 plunky i = 0;
487 1.1 plunky n = printf("%s", title);
488 1.1 plunky
489 1.1 plunky while (len-- > 0) {
490 1.1 plunky if (++i > 8) {
491 1.1 plunky printf("\n%*s", n, "");
492 1.1 plunky i = 1;
493 1.1 plunky }
494 1.1 plunky
495 1.1 plunky printf(" 0x%02x", *data++);
496 1.1 plunky }
497 1.1 plunky
498 1.1 plunky printf("\n");
499 1.1 plunky }
500 1.1 plunky
501 1.1 plunky static bool
502 1.1 plunky print_attribute(uint16_t id, sdp_data_t *value, attr_t *attr, int count)
503 1.1 plunky {
504 1.1 plunky int i;
505 1.1 plunky
506 1.1 plunky for (i = 0; i < count; i++) {
507 1.1 plunky if (id == attr[i].id) {
508 1.1 plunky printf("%s", attr[i].desc);
509 1.1 plunky
510 1.1 plunky if (Nflag) {
511 1.1 plunky printf(" (");
512 1.1 plunky
513 1.1 plunky if (current != -1)
514 1.1 plunky printf("0x%04x + ", language[current].base);
515 1.1 plunky
516 1.1 plunky printf("0x%04x)", id);
517 1.1 plunky }
518 1.1 plunky
519 1.1 plunky printf(": ");
520 1.1 plunky
521 1.1 plunky if (attr[i].print == NULL) {
522 1.1 plunky printf("\n");
523 1.1 plunky sdp_data_print(value, 4);
524 1.1 plunky value->next = value->end;
525 1.1 plunky } else {
526 1.1 plunky (attr[i].print)(value);
527 1.1 plunky }
528 1.1 plunky
529 1.1 plunky return true;
530 1.1 plunky }
531 1.1 plunky }
532 1.1 plunky
533 1.1 plunky return false;
534 1.1 plunky }
535 1.1 plunky
536 1.1 plunky static bool
537 1.1 plunky print_universal_attribute(uint16_t id, sdp_data_t *value)
538 1.1 plunky {
539 1.1 plunky
540 1.1 plunky return print_attribute(id, value,
541 1.1 plunky universal_attrs, __arraycount(universal_attrs));
542 1.1 plunky }
543 1.1 plunky
544 1.1 plunky static bool
545 1.1 plunky print_language_attribute(uint16_t id, sdp_data_t *value)
546 1.1 plunky {
547 1.1 plunky bool done = false;
548 1.1 plunky
549 1.1 plunky for (current = 0; current < nlanguages && !done; current++)
550 1.1 plunky done = print_attribute(id - language[current].base, value,
551 1.1 plunky language_attrs, __arraycount(language_attrs));
552 1.1 plunky
553 1.1 plunky current = -1;
554 1.1 plunky return done;
555 1.1 plunky }
556 1.1 plunky
557 1.1 plunky static bool
558 1.1 plunky print_service_attribute(uint16_t id, sdp_data_t *value)
559 1.1 plunky {
560 1.1 plunky size_t i, j;
561 1.1 plunky
562 1.1 plunky for (i = 0; i < nservices; i++) {
563 1.1 plunky for (j = 0; j < __arraycount(service_list); j++) {
564 1.1 plunky if (service_class[i] == service_list[j].class)
565 1.1 plunky return print_attribute(id, value,
566 1.1 plunky service_list[j].attrs,
567 1.1 plunky service_list[j].nattr);
568 1.1 plunky }
569 1.1 plunky }
570 1.1 plunky
571 1.1 plunky return false;
572 1.1 plunky }
573 1.1 plunky
574 1.1 plunky static void
575 1.1 plunky print_bool(sdp_data_t *data)
576 1.1 plunky {
577 1.1 plunky bool v;
578 1.1 plunky
579 1.1 plunky if (!sdp_get_bool(data, &v))
580 1.1 plunky return;
581 1.1 plunky
582 1.1 plunky printf("%s\n", (v ? "true" : "false"));
583 1.1 plunky }
584 1.1 plunky
585 1.1 plunky static void
586 1.1 plunky print_uint8x(sdp_data_t *data)
587 1.1 plunky {
588 1.1 plunky uint8_t v;
589 1.1 plunky
590 1.1 plunky if (!sdp_get_uint8(data, &v))
591 1.1 plunky return;
592 1.1 plunky
593 1.1 plunky printf("0x%02x\n", v);
594 1.1 plunky }
595 1.1 plunky
596 1.1 plunky static void
597 1.1 plunky print_uint16d(sdp_data_t *data)
598 1.1 plunky {
599 1.1 plunky uint16_t v;
600 1.1 plunky
601 1.1 plunky if (!sdp_get_uint16(data, &v))
602 1.1 plunky return;
603 1.1 plunky
604 1.1 plunky printf("%d\n", v);
605 1.1 plunky }
606 1.1 plunky
607 1.1 plunky static void
608 1.2 plunky print_uint16x(sdp_data_t *data)
609 1.2 plunky {
610 1.2 plunky uint16_t v;
611 1.2 plunky
612 1.2 plunky if (!sdp_get_uint16(data, &v))
613 1.2 plunky return;
614 1.2 plunky
615 1.2 plunky printf("0x%04x\n", v);
616 1.2 plunky }
617 1.2 plunky
618 1.2 plunky static void
619 1.1 plunky print_uint32x(sdp_data_t *data)
620 1.1 plunky {
621 1.1 plunky uint32_t v;
622 1.1 plunky
623 1.1 plunky if (!sdp_get_uint32(data, &v))
624 1.1 plunky return;
625 1.1 plunky
626 1.1 plunky printf("0x%08x\n", v);
627 1.1 plunky }
628 1.1 plunky
629 1.1 plunky static void
630 1.1 plunky print_uint32d(sdp_data_t *data)
631 1.1 plunky {
632 1.1 plunky uint32_t v;
633 1.1 plunky
634 1.1 plunky if (!sdp_get_uint32(data, &v))
635 1.1 plunky return;
636 1.1 plunky
637 1.1 plunky printf("%d\n", v);
638 1.1 plunky }
639 1.1 plunky
640 1.1 plunky static void
641 1.1 plunky print_uuid(sdp_data_t *data)
642 1.1 plunky {
643 1.1 plunky uuid_t uuid;
644 1.1 plunky
645 1.1 plunky if (!sdp_get_uuid(data, &uuid))
646 1.1 plunky return;
647 1.1 plunky
648 1.1 plunky printf("%s\n", string_uuid(&uuid));
649 1.1 plunky }
650 1.1 plunky
651 1.1 plunky static void
652 1.1 plunky print_uuid_list(sdp_data_t *data)
653 1.1 plunky {
654 1.1 plunky sdp_data_t seq;
655 1.1 plunky uuid_t uuid;
656 1.1 plunky
657 1.1 plunky if (!sdp_get_seq(data, &seq))
658 1.1 plunky return;
659 1.1 plunky
660 1.1 plunky printf("\n");
661 1.1 plunky while (sdp_get_uuid(&seq, &uuid))
662 1.1 plunky printf(" %s\n", string_uuid(&uuid));
663 1.1 plunky
664 1.1 plunky if (seq.next != seq.end)
665 1.1 plunky printf(" [additional data]\n");
666 1.1 plunky }
667 1.1 plunky
668 1.1 plunky static void
669 1.1 plunky print_string(sdp_data_t *data)
670 1.1 plunky {
671 1.1 plunky char *str;
672 1.1 plunky size_t len;
673 1.1 plunky
674 1.1 plunky if (!sdp_get_str(data, &str, &len))
675 1.1 plunky return;
676 1.1 plunky
677 1.1 plunky printf("\"%s\"\n", string_vis(VIS_CSTYLE, str, len));
678 1.1 plunky }
679 1.1 plunky
680 1.1 plunky static void
681 1.1 plunky print_url(sdp_data_t *data)
682 1.1 plunky {
683 1.1 plunky char *url;
684 1.1 plunky size_t len;
685 1.1 plunky
686 1.1 plunky if (!sdp_get_url(data, &url, &len))
687 1.1 plunky return;
688 1.1 plunky
689 1.1 plunky printf("\"%s\"\n", string_vis(VIS_HTTPSTYLE, url, len));
690 1.1 plunky }
691 1.1 plunky
692 1.1 plunky static void
693 1.1 plunky print_profile_version(sdp_data_t *data)
694 1.1 plunky {
695 1.1 plunky uint16_t v;
696 1.1 plunky
697 1.1 plunky if (!sdp_get_uint16(data, &v))
698 1.1 plunky return;
699 1.1 plunky
700 1.1 plunky printf("v%d.%d\n", (v >> 8), (v & 0xff));
701 1.1 plunky }
702 1.1 plunky
703 1.1 plunky /*
704 1.1 plunky * This should only be called through print_language_attribute() which
705 1.1 plunky * sets codeset of the string to be printed.
706 1.1 plunky */
707 1.1 plunky static void
708 1.1 plunky print_language_string(sdp_data_t *data)
709 1.1 plunky {
710 1.1 plunky char buf[50], *dst, *src;
711 1.1 plunky iconv_t ih;
712 1.1 plunky size_t n, srcleft, dstleft;
713 1.1 plunky
714 1.1 plunky if (!sdp_get_str(data, &src, &srcleft))
715 1.1 plunky return;
716 1.1 plunky
717 1.1 plunky dst = buf;
718 1.1 plunky dstleft = sizeof(buf);
719 1.1 plunky
720 1.1 plunky ih = iconv_open(nl_langinfo(CODESET), language[current].codeset);
721 1.1 plunky if (ih == (iconv_t)-1) {
722 1.1 plunky printf("Can't convert %s string\n", language[current].codeset);
723 1.1 plunky return;
724 1.1 plunky }
725 1.1 plunky
726 1.1 plunky n = iconv(ih, (const char **)&src, &srcleft, &dst, &dstleft);
727 1.1 plunky
728 1.1 plunky iconv_close(ih);
729 1.1 plunky
730 1.1 plunky if (Nflag || n > 0)
731 1.1 plunky printf("(%s) ", language[current].codeset);
732 1.1 plunky
733 1.1 plunky printf("\"%.*s%s\n", (int)(sizeof(buf) - dstleft), buf,
734 1.1 plunky (srcleft > 0 ? " ..." : "\""));
735 1.1 plunky }
736 1.1 plunky
737 1.1 plunky static void
738 1.1 plunky print_service_class_id_list(sdp_data_t *data)
739 1.1 plunky {
740 1.1 plunky sdp_data_t seq;
741 1.1 plunky uuid_t uuid;
742 1.1 plunky
743 1.1 plunky if (!sdp_get_seq(data, &seq))
744 1.1 plunky return;
745 1.1 plunky
746 1.1 plunky printf("\n");
747 1.1 plunky while (sdp_get_uuid(&seq, &uuid)) {
748 1.1 plunky printf(" %s\n", string_uuid(&uuid));
749 1.1 plunky
750 1.1 plunky if (nservices < MAX_SERVICES) {
751 1.1 plunky service_class[nservices] = uuid.time_low;
752 1.1 plunky uuid.time_low = 0;
753 1.1 plunky if (uuid_equal(&uuid, &BLUETOOTH_BASE_UUID, NULL))
754 1.1 plunky nservices++;
755 1.1 plunky }
756 1.1 plunky }
757 1.1 plunky
758 1.1 plunky if (seq.next != seq.end)
759 1.1 plunky printf(" [additional data]\n");
760 1.1 plunky }
761 1.1 plunky
762 1.1 plunky static void
763 1.1 plunky print_protocol_descriptor(sdp_data_t *data)
764 1.1 plunky {
765 1.1 plunky uuid_t u0, uuid;
766 1.1 plunky size_t i;
767 1.1 plunky
768 1.1 plunky if (!sdp_get_uuid(data, &uuid))
769 1.1 plunky return;
770 1.1 plunky
771 1.1 plunky u0 = uuid;
772 1.1 plunky u0.time_low = 0;
773 1.1 plunky if (uuid_equal(&u0, &BLUETOOTH_BASE_UUID, NULL)) {
774 1.1 plunky for (i = 0; i < __arraycount(protocol_list); i++) {
775 1.1 plunky if (uuid.time_low == protocol_list[i].id) {
776 1.1 plunky printf(" %s", protocol_list[i].desc);
777 1.1 plunky
778 1.1 plunky if (Nflag)
779 1.1 plunky printf(" (0x%04x)", protocol_list[i].id);
780 1.1 plunky
781 1.1 plunky if (protocol_list[i].print)
782 1.1 plunky (protocol_list[i].print)(data);
783 1.1 plunky
784 1.1 plunky if (data->next != data->end)
785 1.1 plunky printf(" [additional data ignored]");
786 1.1 plunky
787 1.1 plunky printf("\n");
788 1.1 plunky return;
789 1.1 plunky }
790 1.1 plunky }
791 1.1 plunky }
792 1.1 plunky
793 1.1 plunky printf(" %s\n", string_uuid(&uuid));
794 1.1 plunky sdp_data_print(data, 4);
795 1.1 plunky data->next = data->end;
796 1.1 plunky }
797 1.1 plunky
798 1.1 plunky static void
799 1.1 plunky print_protocol_descriptor_list(sdp_data_t *data)
800 1.1 plunky {
801 1.1 plunky sdp_data_t seq, proto;
802 1.1 plunky
803 1.1 plunky printf("\n");
804 1.1 plunky sdp_get_alt(data, data); /* strip [optional] alt header */
805 1.1 plunky
806 1.1 plunky while (sdp_get_seq(data, &seq))
807 1.1 plunky while (sdp_get_seq(&seq, &proto))
808 1.1 plunky print_protocol_descriptor(&proto);
809 1.1 plunky }
810 1.1 plunky
811 1.1 plunky static void
812 1.1 plunky print_language_base_attribute_id_list(sdp_data_t *data)
813 1.1 plunky {
814 1.1 plunky sdp_data_t list;
815 1.1 plunky uint16_t v;
816 1.1 plunky const char *codeset;
817 1.1 plunky char lang[2];
818 1.1 plunky
819 1.1 plunky if (!sdp_get_seq(data, &list))
820 1.1 plunky return;
821 1.1 plunky
822 1.1 plunky printf("\n");
823 1.1 plunky while (list.next < list.end) {
824 1.1 plunky /*
825 1.1 plunky * ISO-639-1 natural language values are published at
826 1.1 plunky * http://www.loc.gov/standards/iso639-2/php/code-list.php
827 1.1 plunky */
828 1.1 plunky if (!sdp_get_uint16(&list, &v))
829 1.1 plunky break;
830 1.1 plunky
831 1.1 plunky be16enc(lang, v);
832 1.1 plunky if (!islower((int)lang[0]) || !islower((int)lang[1]))
833 1.1 plunky break;
834 1.1 plunky
835 1.1 plunky /*
836 1.1 plunky * MIBenum values are published at
837 1.1 plunky * http://www.iana.org/assignments/character-sets
838 1.1 plunky */
839 1.1 plunky if (!sdp_get_uint16(&list, &v))
840 1.1 plunky break;
841 1.1 plunky
842 1.1 plunky switch(v) {
843 1.1 plunky case 3: codeset = "US-ASCII"; break;
844 1.1 plunky case 4: codeset = "ISO-8859-1"; break;
845 1.1 plunky case 5: codeset = "ISO-8859-2"; break;
846 1.1 plunky case 106: codeset = "UTF-8"; break;
847 1.1 plunky case 1013: codeset = "UTF-16BE"; break;
848 1.1 plunky case 1014: codeset = "UTF-16LE"; break;
849 1.1 plunky default: codeset = "Unknown"; break;
850 1.1 plunky }
851 1.1 plunky
852 1.1 plunky if (!sdp_get_uint16(&list, &v))
853 1.1 plunky break;
854 1.1 plunky
855 1.1 plunky printf(" %.2s.%s base 0x%04x\n", lang, codeset, v);
856 1.1 plunky
857 1.1 plunky if (nlanguages < MAX_LANGUAGES) {
858 1.1 plunky language[nlanguages].base = v;
859 1.1 plunky language[nlanguages].codeset = codeset;
860 1.1 plunky nlanguages++;
861 1.1 plunky }
862 1.1 plunky }
863 1.1 plunky
864 1.1 plunky if (list.next != list.end)
865 1.1 plunky printf(" [additional data]\n");
866 1.1 plunky }
867 1.1 plunky
868 1.1 plunky static void
869 1.1 plunky print_service_availability(sdp_data_t *data)
870 1.1 plunky {
871 1.1 plunky uint8_t v;
872 1.1 plunky
873 1.1 plunky if (!sdp_get_uint8(data, &v))
874 1.1 plunky return;
875 1.1 plunky
876 1.1 plunky printf("%d/%d\n", v, UINT8_MAX);
877 1.1 plunky }
878 1.1 plunky
879 1.1 plunky static void
880 1.1 plunky print_bluetooth_profile_descriptor_list(sdp_data_t *data)
881 1.1 plunky {
882 1.1 plunky sdp_data_t seq, profile;
883 1.1 plunky uuid_t uuid;
884 1.1 plunky uint16_t v;
885 1.1 plunky
886 1.1 plunky if (!sdp_get_seq(data, &seq))
887 1.1 plunky return;
888 1.1 plunky
889 1.1 plunky printf("\n");
890 1.1 plunky while (seq.next < seq.end) {
891 1.1 plunky if (!sdp_get_seq(&seq, &profile)
892 1.1 plunky || !sdp_get_uuid(&profile, &uuid)
893 1.1 plunky || !sdp_get_uint16(&profile, &v))
894 1.1 plunky break;
895 1.1 plunky
896 1.1 plunky printf(" %s, v%d.%d", string_uuid(&uuid),
897 1.1 plunky (v >> 8), (v & 0xff));
898 1.1 plunky
899 1.1 plunky if (profile.next != profile.end)
900 1.1 plunky printf(" [additional profile data]");
901 1.1 plunky
902 1.1 plunky printf("\n");
903 1.1 plunky }
904 1.1 plunky
905 1.1 plunky if (seq.next != seq.end)
906 1.1 plunky printf(" [additional data]\n");
907 1.1 plunky }
908 1.1 plunky
909 1.1 plunky static void
910 1.1 plunky print_additional_protocol_descriptor_lists(sdp_data_t *data)
911 1.1 plunky {
912 1.1 plunky sdp_data_t seq, stack, proto;
913 1.1 plunky
914 1.1 plunky printf("\n");
915 1.1 plunky sdp_get_seq(data, &seq);
916 1.1 plunky
917 1.1 plunky while (sdp_get_seq(&seq, &stack))
918 1.1 plunky while (sdp_get_seq(&stack, &proto))
919 1.1 plunky print_protocol_descriptor(&proto);
920 1.1 plunky
921 1.1 plunky if (seq.next != seq.end)
922 1.1 plunky printf(" [additional data]\n");
923 1.1 plunky }
924 1.1 plunky
925 1.1 plunky static void
926 1.1 plunky print_sds_version_number_list(sdp_data_t *data)
927 1.1 plunky {
928 1.1 plunky sdp_data_t list;
929 1.1 plunky const char *sep;
930 1.1 plunky uint16_t v;
931 1.1 plunky
932 1.1 plunky if (!sdp_get_seq(data, &list))
933 1.1 plunky return;
934 1.1 plunky
935 1.1 plunky sep = "";
936 1.1 plunky while (sdp_get_uint16(&list, &v)) {
937 1.1 plunky printf("%sv%d.%d", sep, (v >> 8), (v & 0xff));
938 1.1 plunky sep = ", ";
939 1.1 plunky }
940 1.1 plunky
941 1.1 plunky if (list.next != list.end)
942 1.1 plunky printf(" [additional data]");
943 1.1 plunky
944 1.1 plunky printf("\n");
945 1.1 plunky }
946 1.1 plunky
947 1.1 plunky static void
948 1.1 plunky print_ct_network(sdp_data_t *data)
949 1.1 plunky {
950 1.1 plunky uint8_t v;
951 1.1 plunky
952 1.1 plunky if (!sdp_get_uint8(data, &v))
953 1.1 plunky return;
954 1.1 plunky
955 1.1 plunky switch (v) {
956 1.1 plunky case 0x01: printf("PSTN"); break;
957 1.1 plunky case 0x02: printf("ISDN"); break;
958 1.1 plunky case 0x03: printf("GSM"); break;
959 1.1 plunky case 0x04: printf("CDMA"); break;
960 1.1 plunky case 0x05: printf("Analogue Cellular"); break;
961 1.1 plunky case 0x06: printf("Packet Switched"); break;
962 1.1 plunky case 0x07: printf("Other"); break;
963 1.1 plunky default: printf("0x%02x", v); break;
964 1.1 plunky }
965 1.1 plunky
966 1.1 plunky printf("\n");
967 1.1 plunky }
968 1.1 plunky
969 1.1 plunky static void
970 1.1 plunky print_asrc_features(sdp_data_t *data)
971 1.1 plunky {
972 1.1 plunky uint16_t v;
973 1.1 plunky
974 1.1 plunky if (!sdp_get_uint16(data, &v))
975 1.1 plunky return;
976 1.1 plunky
977 1.1 plunky if (Nflag)
978 1.1 plunky printf("(0x%04x)", v);
979 1.1 plunky
980 1.1 plunky printf("\n");
981 1.1 plunky if (v & (1<<0)) printf(" Player\n");
982 1.1 plunky if (v & (1<<1)) printf(" Microphone\n");
983 1.1 plunky if (v & (1<<2)) printf(" Tuner\n");
984 1.1 plunky if (v & (1<<3)) printf(" Mixer\n");
985 1.1 plunky }
986 1.1 plunky
987 1.1 plunky static void
988 1.1 plunky print_asink_features(sdp_data_t *data)
989 1.1 plunky {
990 1.1 plunky uint16_t v;
991 1.1 plunky
992 1.1 plunky if (!sdp_get_uint16(data, &v))
993 1.1 plunky return;
994 1.1 plunky
995 1.1 plunky if (Nflag)
996 1.1 plunky printf("(0x%04x)", v);
997 1.1 plunky
998 1.1 plunky printf("\n");
999 1.1 plunky if (v & (1<<0)) printf(" Headphone\n");
1000 1.1 plunky if (v & (1<<1)) printf(" Speaker\n");
1001 1.1 plunky if (v & (1<<2)) printf(" Recorder\n");
1002 1.1 plunky if (v & (1<<3)) printf(" Amplifier\n");
1003 1.1 plunky }
1004 1.1 plunky
1005 1.1 plunky static void
1006 1.1 plunky print_avrcp_features(sdp_data_t *data)
1007 1.1 plunky {
1008 1.1 plunky uint16_t v;
1009 1.1 plunky
1010 1.1 plunky if (!sdp_get_uint16(data, &v))
1011 1.1 plunky return;
1012 1.1 plunky
1013 1.1 plunky if (Nflag)
1014 1.1 plunky printf("(0x%04x)", v);
1015 1.1 plunky
1016 1.1 plunky printf("\n");
1017 1.1 plunky if (v & (1<<0)) printf(" Category 1\n");
1018 1.1 plunky if (v & (1<<1)) printf(" Category 2\n");
1019 1.1 plunky if (v & (1<<2)) printf(" Category 3\n");
1020 1.1 plunky if (v & (1<<3)) printf(" Category 4\n");
1021 1.1 plunky }
1022 1.1 plunky
1023 1.1 plunky static void
1024 1.1 plunky print_supported_data_stores(sdp_data_t *data)
1025 1.1 plunky {
1026 1.1 plunky sdp_data_t list;
1027 1.1 plunky const char *sep;
1028 1.1 plunky uint8_t v;
1029 1.1 plunky
1030 1.1 plunky if (!sdp_get_seq(data, &list))
1031 1.1 plunky return;
1032 1.1 plunky
1033 1.1 plunky sep = "\n ";
1034 1.1 plunky while (sdp_get_uint8(&list, &v)) {
1035 1.1 plunky printf(sep);
1036 1.1 plunky sep = ", ";
1037 1.1 plunky
1038 1.1 plunky switch(v) {
1039 1.1 plunky case 0x01: printf("Phonebook"); break;
1040 1.1 plunky case 0x03: printf("Calendar"); break;
1041 1.1 plunky case 0x05: printf("Notes"); break;
1042 1.1 plunky case 0x06: printf("Messages"); break;
1043 1.1 plunky default: printf("0x%02x", v); break;
1044 1.1 plunky }
1045 1.1 plunky }
1046 1.1 plunky
1047 1.1 plunky if (list.next != list.end)
1048 1.1 plunky printf(" [additional data]");
1049 1.1 plunky
1050 1.1 plunky printf("\n");
1051 1.1 plunky }
1052 1.1 plunky
1053 1.1 plunky static void
1054 1.1 plunky print_supported_formats(sdp_data_t *data)
1055 1.1 plunky {
1056 1.1 plunky sdp_data_t list;
1057 1.1 plunky const char *sep;
1058 1.1 plunky uint8_t v;
1059 1.1 plunky
1060 1.1 plunky if (!sdp_get_seq(data, &list))
1061 1.1 plunky return;
1062 1.1 plunky
1063 1.1 plunky sep = "\n ";
1064 1.1 plunky while (sdp_get_uint8(&list, &v)) {
1065 1.1 plunky printf(sep);
1066 1.1 plunky sep = ", ";
1067 1.1 plunky
1068 1.1 plunky switch(v) {
1069 1.1 plunky case 0x01: printf("vCard 2.1"); break;
1070 1.1 plunky case 0x02: printf("vCard 3.0"); break;
1071 1.1 plunky case 0x03: printf("vCal 1.0"); break;
1072 1.1 plunky case 0x04: printf("iCal 2.0"); break;
1073 1.1 plunky case 0x05: printf("vNote"); break;
1074 1.1 plunky case 0x06: printf("vMessage"); break;
1075 1.1 plunky case 0xff: printf("Any"); break;
1076 1.1 plunky default: printf("0x%02x", v); break;
1077 1.1 plunky }
1078 1.1 plunky }
1079 1.1 plunky
1080 1.1 plunky if (list.next != list.end)
1081 1.1 plunky printf(" [additional data]");
1082 1.1 plunky
1083 1.1 plunky printf("\n");
1084 1.1 plunky }
1085 1.1 plunky
1086 1.1 plunky static void
1087 1.1 plunky print_hid_version(sdp_data_t *data)
1088 1.1 plunky {
1089 1.1 plunky uint16_t v;
1090 1.1 plunky
1091 1.1 plunky if (!sdp_get_uint16(data, &v))
1092 1.1 plunky return;
1093 1.1 plunky
1094 1.1 plunky printf("v%d.%d.%d\n",
1095 1.1 plunky ((v & 0xff00) >> 8), ((v & 0x00f0) >> 4), (v & 0x000f));
1096 1.1 plunky }
1097 1.1 plunky
1098 1.1 plunky static void
1099 1.1 plunky print_hid_device_subclass(sdp_data_t *data)
1100 1.1 plunky {
1101 1.1 plunky uint8_t v;
1102 1.1 plunky
1103 1.1 plunky if (!sdp_get_uint8(data, &v))
1104 1.1 plunky return;
1105 1.1 plunky
1106 1.1 plunky switch ((v & 0x3c) >> 2) {
1107 1.1 plunky case 1: printf("Joystick"); break;
1108 1.1 plunky case 2: printf("Gamepad"); break;
1109 1.1 plunky case 3: printf("Remote Control"); break;
1110 1.1 plunky case 4: printf("Sensing Device"); break;
1111 1.1 plunky case 5: printf("Digitiser Tablet"); break;
1112 1.1 plunky case 6: printf("Card Reader"); break;
1113 1.1 plunky default: printf("Peripheral"); break;
1114 1.1 plunky }
1115 1.1 plunky
1116 1.1 plunky if (v & 0x40) printf(" <Keyboard>");
1117 1.1 plunky if (v & 0x80) printf(" <Mouse>");
1118 1.1 plunky
1119 1.1 plunky printf("\n");
1120 1.1 plunky }
1121 1.1 plunky
1122 1.1 plunky static void
1123 1.1 plunky print_hid_descriptor_list(sdp_data_t *data)
1124 1.1 plunky {
1125 1.1 plunky sdp_data_t list, seq;
1126 1.1 plunky uint8_t type;
1127 1.1 plunky const char *name;
1128 1.1 plunky char *str;
1129 1.1 plunky size_t len;
1130 1.1 plunky
1131 1.1 plunky
1132 1.1 plunky if (!sdp_get_seq(data, &list))
1133 1.1 plunky return;
1134 1.1 plunky
1135 1.1 plunky printf("\n");
1136 1.1 plunky while (list.next < list.end) {
1137 1.1 plunky if (!sdp_get_seq(&list, &seq)
1138 1.1 plunky || !sdp_get_uint8(&seq, &type)
1139 1.1 plunky || !sdp_get_str(&seq, &str, &len))
1140 1.1 plunky return;
1141 1.1 plunky
1142 1.1 plunky switch (type) {
1143 1.1 plunky case 0x22: name = "Report"; break;
1144 1.1 plunky case 0x23: name = "Physical Descriptor"; break;
1145 1.1 plunky default: name = ""; break;
1146 1.1 plunky }
1147 1.1 plunky
1148 1.1 plunky printf(" Type 0x%02x: %s\n", type, name);
1149 1.1 plunky print_hexdump(" Data", (uint8_t *)str, len);
1150 1.1 plunky
1151 1.1 plunky if (seq.next != seq.end)
1152 1.1 plunky printf(" [additional data]\n");
1153 1.1 plunky }
1154 1.1 plunky }
1155 1.1 plunky
1156 1.1 plunky static void
1157 1.1 plunky print_security_description(sdp_data_t *data)
1158 1.1 plunky {
1159 1.1 plunky uint16_t v;
1160 1.1 plunky
1161 1.1 plunky if (!sdp_get_uint16(data, &v))
1162 1.1 plunky return;
1163 1.1 plunky
1164 1.1 plunky switch (v) {
1165 1.1 plunky case 0x0000: printf("None"); break;
1166 1.1 plunky case 0x0001: printf("Service-level Security"); break;
1167 1.1 plunky case 0x0002: printf("802.1x Security"); break;
1168 1.1 plunky default: printf("0x%04x", v); break;
1169 1.1 plunky }
1170 1.1 plunky
1171 1.1 plunky printf("\n");
1172 1.1 plunky }
1173 1.1 plunky
1174 1.1 plunky static void
1175 1.1 plunky print_hf_features(sdp_data_t *data)
1176 1.1 plunky {
1177 1.1 plunky uint16_t v;
1178 1.1 plunky
1179 1.1 plunky if (!sdp_get_uint16(data, &v))
1180 1.1 plunky return;
1181 1.1 plunky
1182 1.1 plunky if (Nflag)
1183 1.1 plunky printf("(0x%04x)", v);
1184 1.1 plunky
1185 1.1 plunky printf("\n");
1186 1.1 plunky if (v & (1<<0)) printf(" Echo Cancellation/Noise Reduction\n");
1187 1.1 plunky if (v & (1<<1)) printf(" Call Waiting\n");
1188 1.1 plunky if (v & (1<<2)) printf(" Caller Line Identification\n");
1189 1.1 plunky if (v & (1<<3)) printf(" Voice Recognition\n");
1190 1.1 plunky if (v & (1<<4)) printf(" Volume Control\n");
1191 1.1 plunky }
1192 1.1 plunky
1193 1.1 plunky static void
1194 1.1 plunky print_hfag_network(sdp_data_t *data)
1195 1.1 plunky {
1196 1.1 plunky uint8_t v;
1197 1.1 plunky
1198 1.1 plunky if (!sdp_get_uint8(data, &v))
1199 1.1 plunky return;
1200 1.1 plunky
1201 1.1 plunky switch (v) {
1202 1.1 plunky case 0x01: printf("Ability to reject a call"); break;
1203 1.1 plunky case 0x02: printf("No ability to reject a call"); break;
1204 1.1 plunky default: printf("0x%02x", v); break;
1205 1.1 plunky }
1206 1.1 plunky
1207 1.1 plunky printf("\n");
1208 1.1 plunky }
1209 1.1 plunky
1210 1.1 plunky static void
1211 1.1 plunky print_hfag_features(sdp_data_t *data)
1212 1.1 plunky {
1213 1.1 plunky uint16_t v;
1214 1.1 plunky
1215 1.1 plunky if (!sdp_get_uint16(data, &v))
1216 1.1 plunky return;
1217 1.1 plunky
1218 1.1 plunky if (Nflag)
1219 1.1 plunky printf("(0x%04x)", v);
1220 1.1 plunky
1221 1.1 plunky printf("\n");
1222 1.1 plunky if (v & (1<<0)) printf(" 3 Way Calling\n");
1223 1.1 plunky if (v & (1<<1)) printf(" Echo Cancellation/Noise Reduction\n");
1224 1.1 plunky if (v & (1<<2)) printf(" Voice Recognition\n");
1225 1.1 plunky if (v & (1<<3)) printf(" In-band Ring Tone\n");
1226 1.1 plunky if (v & (1<<4)) printf(" Voice Tags\n");
1227 1.1 plunky }
1228 1.1 plunky
1229 1.1 plunky static void
1230 1.1 plunky print_net_access_type(sdp_data_t *data)
1231 1.1 plunky {
1232 1.1 plunky uint16_t v;
1233 1.1 plunky
1234 1.1 plunky if (!sdp_get_uint16(data, &v))
1235 1.1 plunky return;
1236 1.1 plunky
1237 1.1 plunky switch(v) {
1238 1.1 plunky case 0x0000: printf("PSTN"); break;
1239 1.1 plunky case 0x0001: printf("ISDN"); break;
1240 1.1 plunky case 0x0002: printf("DSL"); break;
1241 1.1 plunky case 0x0003: printf("Cable Modem"); break;
1242 1.1 plunky case 0x0004: printf("10Mb Ethernet"); break;
1243 1.1 plunky case 0x0005: printf("100Mb Ethernet"); break;
1244 1.1 plunky case 0x0006: printf("4Mb Token Ring"); break;
1245 1.1 plunky case 0x0007: printf("16Mb Token Ring"); break;
1246 1.1 plunky case 0x0008: printf("100Mb Token Ring"); break;
1247 1.1 plunky case 0x0009: printf("FDDI"); break;
1248 1.1 plunky case 0x000a: printf("GSM"); break;
1249 1.1 plunky case 0x000b: printf("CDMA"); break;
1250 1.1 plunky case 0x000c: printf("GPRS"); break;
1251 1.1 plunky case 0x000d: printf("3G Cellular"); break;
1252 1.1 plunky case 0xfffe: printf("other"); break;
1253 1.1 plunky default: printf("0x%04x", v); break;
1254 1.1 plunky }
1255 1.1 plunky
1256 1.1 plunky printf("\n");
1257 1.1 plunky }
1258 1.1 plunky
1259 1.1 plunky static void
1260 1.2 plunky print_pnp_source(sdp_data_t *data)
1261 1.2 plunky {
1262 1.2 plunky uint16_t v;
1263 1.2 plunky
1264 1.2 plunky if (!sdp_get_uint16(data, &v))
1265 1.2 plunky return;
1266 1.2 plunky
1267 1.2 plunky switch (v) {
1268 1.2 plunky case 0x0001: printf("Bluetooth SIG"); break;
1269 1.2 plunky case 0x0002: printf("USB Implementers Forum"); break;
1270 1.2 plunky default: printf("0x%04x", v); break;
1271 1.2 plunky }
1272 1.2 plunky
1273 1.2 plunky printf("\n");
1274 1.2 plunky }
1275 1.2 plunky
1276 1.2 plunky static void
1277 1.1 plunky print_rfcomm(sdp_data_t *data)
1278 1.1 plunky {
1279 1.1 plunky uint8_t v;
1280 1.1 plunky
1281 1.1 plunky if (sdp_get_uint8(data, &v))
1282 1.1 plunky printf(" (channel %d)", v);
1283 1.1 plunky }
1284 1.1 plunky
1285 1.1 plunky static void
1286 1.1 plunky print_bnep(sdp_data_t *data)
1287 1.1 plunky {
1288 1.1 plunky sdp_data_t seq;
1289 1.1 plunky uint16_t v;
1290 1.1 plunky const char *sep;
1291 1.1 plunky
1292 1.1 plunky if (!sdp_get_uint16(data, &v)
1293 1.1 plunky || !sdp_get_seq(data, &seq))
1294 1.1 plunky return;
1295 1.1 plunky
1296 1.1 plunky printf(" (v%d.%d", (v >> 8), (v & 0xff));
1297 1.1 plunky sep = "; ";
1298 1.1 plunky while (sdp_get_uint16(&seq, &v)) {
1299 1.1 plunky printf(sep);
1300 1.1 plunky sep = ", ";
1301 1.1 plunky
1302 1.1 plunky switch (v) {
1303 1.1 plunky case 0x0800: printf("IPv4"); break;
1304 1.1 plunky case 0x0806: printf("ARP"); break;
1305 1.1 plunky case 0x86dd: printf("IPv6"); break;
1306 1.1 plunky default: printf("0x%04x", v); break;
1307 1.1 plunky }
1308 1.1 plunky }
1309 1.1 plunky printf(")");
1310 1.1 plunky
1311 1.1 plunky if (seq.next != seq.end)
1312 1.1 plunky printf(" [additional data]");
1313 1.1 plunky }
1314 1.1 plunky
1315 1.1 plunky static void
1316 1.1 plunky print_avctp(sdp_data_t *data)
1317 1.1 plunky {
1318 1.1 plunky uint16_t v;
1319 1.1 plunky
1320 1.1 plunky if (sdp_get_uint16(data, &v))
1321 1.1 plunky printf(" (v%d.%d)", (v >> 8), (v & 0xff));
1322 1.1 plunky }
1323 1.1 plunky
1324 1.1 plunky static void
1325 1.1 plunky print_avdtp(sdp_data_t *data)
1326 1.1 plunky {
1327 1.1 plunky uint16_t v;
1328 1.1 plunky
1329 1.1 plunky if (sdp_get_uint16(data, &v))
1330 1.1 plunky printf(" (v%d.%d)", (v >> 8), (v & 0xff));
1331 1.1 plunky }
1332 1.1 plunky
1333 1.1 plunky static void
1334 1.1 plunky print_l2cap(sdp_data_t *data)
1335 1.1 plunky {
1336 1.1 plunky uint16_t v;
1337 1.1 plunky
1338 1.1 plunky if (sdp_get_uint16(data, &v))
1339 1.1 plunky printf(" (PSM 0x%04x)", v);
1340 1.1 plunky }
1341