1 /* $NetBSD: command.c,v 1.2 2009/10/06 19:21:17 plunky Exp $ */
4 * Copyright (c) 2009 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h>
33 __RCSID("$NetBSD: command.c,v 1.2 2009/10/06 19:21:17 plunky Exp $");
35 #include <bluetooth.h>
43 static sdp_session_t
open_session(void);
44 static void build_ssp(sdp_data_t
*, int, const char **);
51 { SDP_SERVICE_CLASS_ADVANCED_AUDIO_DISTRIBUTION
,
52 "A2DP", "Advanced Audio Distribution Profile" },
53 { SDP_UUID_PROTOCOL_BNEP
,
54 "BNEP", "Bluetooth Network Encapsulation Protocol" },
55 { SDP_SERVICE_CLASS_COMMON_ISDN_ACCESS
,
56 "CIP", "Common ISDN Access Service" },
57 { SDP_SERVICE_CLASS_CORDLESS_TELEPHONY
,
58 "CTP", "Cordless Telephony Service" },
59 { SDP_SERVICE_CLASS_DIALUP_NETWORKING
,
60 "DUN", "Dial Up Networking Service" },
61 { SDP_SERVICE_CLASS_FAX
,
62 "FAX", "Fax Service" },
63 { SDP_SERVICE_CLASS_OBEX_FILE_TRANSFER
,
64 "FTRN", "File Transfer Service" },
65 { SDP_SERVICE_CLASS_GN
,
66 "GN", "Group ad-hoc Network Service" },
67 { SDP_SERVICE_CLASS_HUMAN_INTERFACE_DEVICE
,
68 "HID", "Human Interface Device Service" },
69 { SDP_SERVICE_CLASS_HANDSFREE
,
70 "HF", "Handsfree Service" },
71 { SDP_SERVICE_CLASS_HEADSET
,
72 "HSET", "Headset Service" },
73 { SDP_UUID_PROTOCOL_L2CAP
,
74 "L2CAP", "Logical Link Control and Adapatation Protocol" },
75 { SDP_SERVICE_CLASS_LAN_ACCESS_USING_PPP
,
76 "LAN", "Lan access using PPP Service" },
77 { SDP_SERVICE_CLASS_NAP
,
78 "NAP", "Network Access Point Service" },
79 { SDP_UUID_PROTOCOL_OBEX
,
80 "OBEX", "Object Exchange Protocol" },
81 { SDP_SERVICE_CLASS_OBEX_OBJECT_PUSH
,
82 "OPUSH", "Object Push Service" },
83 { SDP_SERVICE_CLASS_PANU
,
84 "PANU", "Personal Area Networking User Service" },
85 { SDP_SERVICE_CLASS_PNP_INFORMATION
,
86 "PNP", "PNP Information Service" },
87 { SDP_UUID_PROTOCOL_RFCOMM
,
88 "RFCOMM", "RFCOMM Protocol" },
89 { SDP_UUID_PROTOCOL_SDP
,
90 "SDP", "Service Discovery Protocol" },
91 { SDP_SERVICE_CLASS_SERIAL_PORT
,
92 "SP", "Serial Port Service" },
93 { SDP_SERVICE_CLASS_IR_MC_SYNC
,
94 "SYNC", "IrMC Sync Client Service" },
98 do_sdp_browse(int argc
, const char **argv
)
100 #define STR(x) __STRING(x)
101 const char *av
= STR(SDP_SERVICE_CLASS_PUBLIC_BROWSE_GROUP
);
105 errx(EXIT_FAILURE
, "Too many arguments");
112 return do_sdp_search(argc
, argv
);
116 do_sdp_record(int argc
, const char **argv
)
121 unsigned long handle
;
125 errx(EXIT_FAILURE
, "Record handle required");
129 for (; argc
-- > 0; argv
++) {
130 handle
= strtoul(*argv
, &ep
, 0);
131 if (*argv
[0] == '\0' || *ep
!= '\0' || handle
> UINT32_MAX
)
132 errx(EXIT_FAILURE
, "Invalid handle: %s\n", *argv
);
134 rv
= sdp_service_attribute(ss
, (uint32_t)handle
, NULL
, &rsp
);
149 do_sdp_search(int argc
, const char **argv
)
152 sdp_data_t ssp
, rec
, rsp
;
156 errx(EXIT_FAILURE
, "UUID required");
159 errx(EXIT_FAILURE
, "Too many UUIDs");
161 build_ssp(&ssp
, argc
, argv
);
165 rv
= sdp_service_search_attribute(ss
, &ssp
, NULL
, &rsp
);
167 err(EXIT_FAILURE
, "sdp_service_search_attribute");
169 while (sdp_get_seq(&rsp
, &rec
)) {
178 if (rsp
.next
!= rsp
.end
) {
179 printf("\n\nAdditional Data:\n");
180 sdp_data_print(&rsp
, 4);
193 if (bdaddr_any(&remote_addr
))
194 ss
= sdp_open_local(control_socket
);
196 ss
= sdp_open(&local_addr
, &remote_addr
);
199 err(EXIT_FAILURE
, "sdp_open");
205 * build ServiceSearchPattern from arglist
208 build_ssp(sdp_data_t
*ssp
, int argc
, const char **argv
)
210 static uint8_t data
[12 * sizeof(uuid_t
)];
218 ssp
->end
= data
+ sizeof(data
);
220 for (; argc
-- > 0; argv
++) {
221 uuid_from_string(*argv
, &uuid
, &status
);
222 if (status
!= uuid_s_ok
) {
223 umax
= strtoumax(*argv
, &ep
, 0);
224 if (*argv
[0] == '\0' || *ep
!= '\0') {
226 if (i
== __arraycount(aliases
))
228 "%s: Bad UUID", *argv
);
230 if (strcasecmp(aliases
[i
].name
,
235 umax
= aliases
[i
].uuid
;
236 } else if (umax
> UINT32_MAX
)
237 errx(EXIT_FAILURE
, "%s: Bad UUID", *argv
);
239 uuid
= BLUETOOTH_BASE_UUID
;
240 uuid
.time_low
= (uint32_t)umax
;
243 sdp_put_uuid(ssp
, &uuid
);
246 ssp
->end
= ssp
->next
;