Deleted Added
full compact
search.c (121054) search.c (124317)
1/*
2 * search.c
3 *
4 * Copyright (c) 2001-2003 Maksim Yevmenkin <m_evmenkin@yahoo.com>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 12 unchanged lines hidden (view full) ---

21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 *
28 * $Id: search.c,v 1.2 2003/09/08 17:35:15 max Exp $
1/*
2 * search.c
3 *
4 * Copyright (c) 2001-2003 Maksim Yevmenkin <m_evmenkin@yahoo.com>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 12 unchanged lines hidden (view full) ---

21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 *
28 * $Id: search.c,v 1.2 2003/09/08 17:35:15 max Exp $
29 * $FreeBSD: head/usr.sbin/bluetooth/sdpcontrol/search.c 121054 2003-10-12 22:04:24Z emax $
29 * $FreeBSD: head/usr.sbin/bluetooth/sdpcontrol/search.c 124317 2004-01-09 22:44:28Z emax $
30 */
31
32#include <bluetooth.h>
33#include <ctype.h>
34#include <sdp.h>
35#include <stdio.h>
36#include <stdlib.h>
37#include "sdpcontrol.h"
38
39/* List of the attributes we are looking for */
30 */
31
32#include <bluetooth.h>
33#include <ctype.h>
34#include <sdp.h>
35#include <stdio.h>
36#include <stdlib.h>
37#include "sdpcontrol.h"
38
39/* List of the attributes we are looking for */
40static u_int32_t attrs[] =
40static uint32_t attrs[] =
41{
42 SDP_ATTR_RANGE( SDP_ATTR_SERVICE_RECORD_HANDLE,
43 SDP_ATTR_SERVICE_RECORD_HANDLE),
44 SDP_ATTR_RANGE( SDP_ATTR_SERVICE_CLASS_ID_LIST,
45 SDP_ATTR_SERVICE_CLASS_ID_LIST),
46 SDP_ATTR_RANGE( SDP_ATTR_PROTOCOL_DESCRIPTOR_LIST,
47 SDP_ATTR_PROTOCOL_DESCRIPTOR_LIST),
48 SDP_ATTR_RANGE( SDP_ATTR_BLUETOOTH_PROFILE_DESCRIPTOR_LIST,
49 SDP_ATTR_BLUETOOTH_PROFILE_DESCRIPTOR_LIST)
50};
51#define attrs_len (sizeof(attrs)/sizeof(attrs[0]))
52
53/* Buffer for the attributes */
54#define NRECS 25 /* request this much records from the SDP server */
55#define BSIZE 256 /* one attribute buffer size */
41{
42 SDP_ATTR_RANGE( SDP_ATTR_SERVICE_RECORD_HANDLE,
43 SDP_ATTR_SERVICE_RECORD_HANDLE),
44 SDP_ATTR_RANGE( SDP_ATTR_SERVICE_CLASS_ID_LIST,
45 SDP_ATTR_SERVICE_CLASS_ID_LIST),
46 SDP_ATTR_RANGE( SDP_ATTR_PROTOCOL_DESCRIPTOR_LIST,
47 SDP_ATTR_PROTOCOL_DESCRIPTOR_LIST),
48 SDP_ATTR_RANGE( SDP_ATTR_BLUETOOTH_PROFILE_DESCRIPTOR_LIST,
49 SDP_ATTR_BLUETOOTH_PROFILE_DESCRIPTOR_LIST)
50};
51#define attrs_len (sizeof(attrs)/sizeof(attrs[0]))
52
53/* Buffer for the attributes */
54#define NRECS 25 /* request this much records from the SDP server */
55#define BSIZE 256 /* one attribute buffer size */
56static u_int8_t buffer[NRECS * attrs_len][BSIZE];
56static uint8_t buffer[NRECS * attrs_len][BSIZE];
57
58/* SDP attributes */
59static sdp_attr_t values[NRECS * attrs_len];
60#define values_len (sizeof(values)/sizeof(values[0]))
61
62/*
63 * Print Service Class ID List
64 *
65 * The ServiceClassIDList attribute consists of a data element sequence in
66 * which each data element is a UUID representing the service classes that
67 * a given service record conforms to. The UUIDs are listed in order from
68 * the most specific class to the most general class. The ServiceClassIDList
69 * must contain at least one service class UUID.
70 */
71
72static void
57
58/* SDP attributes */
59static sdp_attr_t values[NRECS * attrs_len];
60#define values_len (sizeof(values)/sizeof(values[0]))
61
62/*
63 * Print Service Class ID List
64 *
65 * The ServiceClassIDList attribute consists of a data element sequence in
66 * which each data element is a UUID representing the service classes that
67 * a given service record conforms to. The UUIDs are listed in order from
68 * the most specific class to the most general class. The ServiceClassIDList
69 * must contain at least one service class UUID.
70 */
71
72static void
73print_service_class_id_list(u_int8_t const *start, u_int8_t const *end)
73print_service_class_id_list(uint8_t const *start, uint8_t const *end)
74{
74{
75 u_int32_t type, len, value;
75 uint32_t type, len, value;
76
77 if (end - start < 2) {
78 fprintf(stderr, "Invalid Service Class ID List. " \
79 "Too short, len=%d\n", end - start);
80 return;
81 }
82
83 SDP_GET8(type, start);

--- 31 unchanged lines hidden (view full) ---

115 fprintf(stdout, "\t%#8.8x\n", value);
116 break;
117
118 case SDP_DATA_UUID128: {
119 int128_t uuid;
120
121 SDP_GET128(&uuid, start);
122 fprintf(stdout, "\t%#8.8x-%4.4x-%4.4x-%4.4x-%4.4x%8.8x\n",
76
77 if (end - start < 2) {
78 fprintf(stderr, "Invalid Service Class ID List. " \
79 "Too short, len=%d\n", end - start);
80 return;
81 }
82
83 SDP_GET8(type, start);

--- 31 unchanged lines hidden (view full) ---

115 fprintf(stdout, "\t%#8.8x\n", value);
116 break;
117
118 case SDP_DATA_UUID128: {
119 int128_t uuid;
120
121 SDP_GET128(&uuid, start);
122 fprintf(stdout, "\t%#8.8x-%4.4x-%4.4x-%4.4x-%4.4x%8.8x\n",
123 *(u_int32_t *)&uuid.b[0],
124 *(u_int16_t *)&uuid.b[4],
125 *(u_int16_t *)&uuid.b[6],
126 *(u_int16_t *)&uuid.b[8],
127 *(u_int16_t *)&uuid.b[10],
128 *(u_int32_t *)&uuid.b[12]);
123 *(uint32_t *)&uuid.b[0],
124 *(uint16_t *)&uuid.b[4],
125 *(uint16_t *)&uuid.b[6],
126 *(uint16_t *)&uuid.b[8],
127 *(uint16_t *)&uuid.b[10],
128 *(uint32_t *)&uuid.b[12]);
129 } break;
130
131 default:
132 fprintf(stderr, "Invalid Service Class ID List. " \
133 "Not a UUID, type=%#x\n", type);
134 return;
135 /* NOT REACHED */
136 }

--- 11 unchanged lines hidden (view full) ---

148 * descriptors are listed in order from the lowest layer protocol to the
149 * highest layer protocol used to gain access to the service. If it is possible
150 * for more than one kind of protocol stack to be used to gain access to the
151 * service, the ProtocolDescriptorList takes the form of a data element
152 * alternative where each member is a data element sequence as described above.
153 */
154
155static void
129 } break;
130
131 default:
132 fprintf(stderr, "Invalid Service Class ID List. " \
133 "Not a UUID, type=%#x\n", type);
134 return;
135 /* NOT REACHED */
136 }

--- 11 unchanged lines hidden (view full) ---

148 * descriptors are listed in order from the lowest layer protocol to the
149 * highest layer protocol used to gain access to the service. If it is possible
150 * for more than one kind of protocol stack to be used to gain access to the
151 * service, the ProtocolDescriptorList takes the form of a data element
152 * alternative where each member is a data element sequence as described above.
153 */
154
155static void
156print_protocol_descriptor(u_int8_t const *start, u_int8_t const *end)
156print_protocol_descriptor(uint8_t const *start, uint8_t const *end)
157{
158 union {
159 uint8_t uint8;
160 uint16_t uint16;
161 uint32_t uint32;
162 uint64_t uint64;
163 int128_t int128;
164 } value;
157{
158 union {
159 uint8_t uint8;
160 uint16_t uint16;
161 uint32_t uint32;
162 uint64_t uint64;
163 int128_t int128;
164 } value;
165 u_int32_t type, len, param;
165 uint32_t type, len, param;
166
167 /* Get Protocol UUID */
168 SDP_GET8(type, start);
169 switch (type) {
170 case SDP_DATA_UUID16:
171 SDP_GET16(value.uint16, start);
172 fprintf(stdout, "\t%s (%#4.4x)\n", sdp_uuid2desc(value.uint16),
173 value.uint16);
174 break;
175
176 case SDP_DATA_UUID32:
177 SDP_GET32(value.uint32, start);
178 fprintf(stdout, "\t%#8.8x\n", value.uint32);
179 break;
180
181 case SDP_DATA_UUID128:
182 SDP_GET128(&value.int128, start);
183 fprintf(stdout, "\t%#8.8x-%4.4x-%4.4x-%4.4x-%4.4x%8.8x\n",
166
167 /* Get Protocol UUID */
168 SDP_GET8(type, start);
169 switch (type) {
170 case SDP_DATA_UUID16:
171 SDP_GET16(value.uint16, start);
172 fprintf(stdout, "\t%s (%#4.4x)\n", sdp_uuid2desc(value.uint16),
173 value.uint16);
174 break;
175
176 case SDP_DATA_UUID32:
177 SDP_GET32(value.uint32, start);
178 fprintf(stdout, "\t%#8.8x\n", value.uint32);
179 break;
180
181 case SDP_DATA_UUID128:
182 SDP_GET128(&value.int128, start);
183 fprintf(stdout, "\t%#8.8x-%4.4x-%4.4x-%4.4x-%4.4x%8.8x\n",
184 *(u_int32_t *)&value.int128.b[0],
185 *(u_int16_t *)&value.int128.b[4],
186 *(u_int16_t *)&value.int128.b[6],
187 *(u_int16_t *)&value.int128.b[8],
188 *(u_int16_t *)&value.int128.b[10],
189 *(u_int32_t *)&value.int128.b[12]);
184 *(uint32_t *)&value.int128.b[0],
185 *(uint16_t *)&value.int128.b[4],
186 *(uint16_t *)&value.int128.b[6],
187 *(uint16_t *)&value.int128.b[8],
188 *(uint16_t *)&value.int128.b[10],
189 *(uint32_t *)&value.int128.b[12]);
190 break;
191
192 default:
193 fprintf(stderr, "Invalid Protocol Descriptor. " \
194 "Not a UUID, type=%#x\n", type);
195 return;
196 /* NOT REACHED */
197 }

--- 35 unchanged lines hidden (view full) ---

233 fprintf(stdout, "u/int64 %llu\n", value.uint64);
234 break;
235
236 case SDP_DATA_UINT128:
237 case SDP_DATA_INT128:
238 case SDP_DATA_UUID128:
239 SDP_GET128(&value.int128, start);
240 fprintf(stdout, "u/int/uuid128 %#8.8x-%4.4x-%4.4x-%4.4x-%4.4x%8.8x\n",
190 break;
191
192 default:
193 fprintf(stderr, "Invalid Protocol Descriptor. " \
194 "Not a UUID, type=%#x\n", type);
195 return;
196 /* NOT REACHED */
197 }

--- 35 unchanged lines hidden (view full) ---

233 fprintf(stdout, "u/int64 %llu\n", value.uint64);
234 break;
235
236 case SDP_DATA_UINT128:
237 case SDP_DATA_INT128:
238 case SDP_DATA_UUID128:
239 SDP_GET128(&value.int128, start);
240 fprintf(stdout, "u/int/uuid128 %#8.8x-%4.4x-%4.4x-%4.4x-%4.4x%8.8x\n",
241 *(u_int32_t *)&value.int128.b[0],
242 *(u_int16_t *)&value.int128.b[4],
243 *(u_int16_t *)&value.int128.b[6],
244 *(u_int16_t *)&value.int128.b[8],
245 *(u_int16_t *)&value.int128.b[10],
246 *(u_int32_t *)&value.int128.b[12]);
241 *(uint32_t *)&value.int128.b[0],
242 *(uint16_t *)&value.int128.b[4],
243 *(uint16_t *)&value.int128.b[6],
244 *(uint16_t *)&value.int128.b[8],
245 *(uint16_t *)&value.int128.b[10],
246 *(uint32_t *)&value.int128.b[12]);
247 break;
248
249 case SDP_DATA_STR8:
250 case SDP_DATA_URL8:
251 SDP_GET8(len, start);
252 fprintf(stdout, "%*.*s\n", len, len, (char *) start);
253 start += len;
254 break;

--- 41 unchanged lines hidden (view full) ---

296 "Unknown data type: %#02x\n", type);
297 return;
298 /* NOT REACHED */
299 }
300 }
301} /* print_protocol_descriptor */
302
303static void
247 break;
248
249 case SDP_DATA_STR8:
250 case SDP_DATA_URL8:
251 SDP_GET8(len, start);
252 fprintf(stdout, "%*.*s\n", len, len, (char *) start);
253 start += len;
254 break;

--- 41 unchanged lines hidden (view full) ---

296 "Unknown data type: %#02x\n", type);
297 return;
298 /* NOT REACHED */
299 }
300 }
301} /* print_protocol_descriptor */
302
303static void
304print_protocol_descriptor_list(u_int8_t const *start, u_int8_t const *end)
304print_protocol_descriptor_list(uint8_t const *start, uint8_t const *end)
305{
305{
306 u_int32_t type, len;
306 uint32_t type, len;
307
308 if (end - start < 2) {
309 fprintf(stderr, "Invalid Protocol Descriptor List. " \
310 "Too short, len=%d\n", end - start);
311 return;
312 }
313
314 SDP_GET8(type, start);

--- 55 unchanged lines hidden (view full) ---

370 * second element is a 16-bit profile version number. Each version of a profile
371 * is assigned a 16-bit unsigned integer profile version number, which consists
372 * of two 8-bit fields. The higher-order 8 bits contain the major version
373 * number field and the lower-order 8 bits contain the minor version number
374 * field.
375 */
376
377static void
307
308 if (end - start < 2) {
309 fprintf(stderr, "Invalid Protocol Descriptor List. " \
310 "Too short, len=%d\n", end - start);
311 return;
312 }
313
314 SDP_GET8(type, start);

--- 55 unchanged lines hidden (view full) ---

370 * second element is a 16-bit profile version number. Each version of a profile
371 * is assigned a 16-bit unsigned integer profile version number, which consists
372 * of two 8-bit fields. The higher-order 8 bits contain the major version
373 * number field and the lower-order 8 bits contain the minor version number
374 * field.
375 */
376
377static void
378print_bluetooth_profile_descriptor_list(u_int8_t const *start, u_int8_t const *end)
378print_bluetooth_profile_descriptor_list(uint8_t const *start, uint8_t const *end)
379{
379{
380 u_int32_t type, len, value;
380 uint32_t type, len, value;
381
382 if (end - start < 2) {
383 fprintf(stderr, "Invalid Bluetooth Profile Descriptor List. " \
384 "Too short, len=%d\n", end - start);
385 return;
386 }
387
388 SDP_GET8(type, start);

--- 54 unchanged lines hidden (view full) ---

443 fprintf(stdout, "\t%#8.8x ", value);
444 break;
445
446 case SDP_DATA_UUID128: {
447 int128_t uuid;
448
449 SDP_GET128(&uuid, start);
450 fprintf(stdout, "\t%#8.8x-%4.4x-%4.4x-%4.4x-%4.4x%8.8x ",
381
382 if (end - start < 2) {
383 fprintf(stderr, "Invalid Bluetooth Profile Descriptor List. " \
384 "Too short, len=%d\n", end - start);
385 return;
386 }
387
388 SDP_GET8(type, start);

--- 54 unchanged lines hidden (view full) ---

443 fprintf(stdout, "\t%#8.8x ", value);
444 break;
445
446 case SDP_DATA_UUID128: {
447 int128_t uuid;
448
449 SDP_GET128(&uuid, start);
450 fprintf(stdout, "\t%#8.8x-%4.4x-%4.4x-%4.4x-%4.4x%8.8x ",
451 *(u_int32_t *)&uuid.b[0],
452 *(u_int16_t *)&uuid.b[4],
453 *(u_int16_t *)&uuid.b[6],
454 *(u_int16_t *)&uuid.b[8],
455 *(u_int16_t *)&uuid.b[10],
456 *(u_int32_t *)&uuid.b[12]);
451 *(uint32_t *)&uuid.b[0],
452 *(uint16_t *)&uuid.b[4],
453 *(uint16_t *)&uuid.b[6],
454 *(uint16_t *)&uuid.b[8],
455 *(uint16_t *)&uuid.b[10],
456 *(uint32_t *)&uuid.b[12]);
457 } break;
458
459 default:
460 fprintf(stderr, "Invalid Bluetooth Profile " \
461 "Descriptor List. " \
462 "Not a UUID, type=%#x\n", type);
463 return;
464 /* NOT REACHED */

--- 15 unchanged lines hidden (view full) ---

480} /* print_bluetooth_profile_descriptor_list */
481
482/* Perform SDP search command */
483static int
484do_sdp_search(void *xs, int argc, char **argv)
485{
486 char *ep = NULL;
487 int32_t n, type, value;
457 } break;
458
459 default:
460 fprintf(stderr, "Invalid Bluetooth Profile " \
461 "Descriptor List. " \
462 "Not a UUID, type=%#x\n", type);
463 return;
464 /* NOT REACHED */

--- 15 unchanged lines hidden (view full) ---

480} /* print_bluetooth_profile_descriptor_list */
481
482/* Perform SDP search command */
483static int
484do_sdp_search(void *xs, int argc, char **argv)
485{
486 char *ep = NULL;
487 int32_t n, type, value;
488 u_int16_t service;
488 uint16_t service;
489
490 /* Parse command line arguments */
491 switch (argc) {
492 case 1:
493 n = strtoul(argv[0], &ep, 16);
494 if (*ep != 0) {
495 switch (tolower(argv[0][0])) {
496 case 'c': /* CIP/CTP */

--- 68 unchanged lines hidden (view full) ---

565 service = SDP_SERVICE_CLASS_SERIAL_PORT;
566 break;
567
568 default:
569 return (USAGE);
570 /* NOT REACHED */
571 }
572 } else
489
490 /* Parse command line arguments */
491 switch (argc) {
492 case 1:
493 n = strtoul(argv[0], &ep, 16);
494 if (*ep != 0) {
495 switch (tolower(argv[0][0])) {
496 case 'c': /* CIP/CTP */

--- 68 unchanged lines hidden (view full) ---

565 service = SDP_SERVICE_CLASS_SERIAL_PORT;
566 break;
567
568 default:
569 return (USAGE);
570 /* NOT REACHED */
571 }
572 } else
573 service = (u_int16_t) n;
573 service = (uint16_t) n;
574 break;
575
576 default:
577 return (USAGE);
578 }
579
580 if (service < SDP_SERVICE_CLASS_SERVICE_DISCOVERY_SERVER)
581 return (USAGE);

--- 126 unchanged lines hidden ---
574 break;
575
576 default:
577 return (USAGE);
578 }
579
580 if (service < SDP_SERVICE_CLASS_SERVICE_DISCOVERY_SERVER)
581 return (USAGE);

--- 126 unchanged lines hidden ---