3 * BlueZ - Bluetooth protocol stack for Linux
5 * Copyright (C) 2005-2010 Marcel Holtmann <marcel@holtmann.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
33 #include <sys/socket.h>
35 #include <bluetooth/bluetooth.h>
36 #include <bluetooth/hci.h>
37 #include <bluetooth/hci_lib.h>
38 #include <bluetooth/sdp.h>
39 #include <bluetooth/sdp_lib.h>
41 static volatile sig_atomic_t __io_finished = 0;
43 static void callback(uint8_t type, uint16_t status,
44 uint8_t *rsp, size_t size, void *udata)
48 for (i = 0; i < size; i++) {
49 printf("%02x ", rsp[i]);
52 if ((i + 1) % 16 == 0)
60 static void cmd_search(bdaddr_t *src, bdaddr_t *dst)
62 sdp_session_t *session;
63 sdp_list_t *search, *attrids;
64 uint32_t range = 0x0000ffff;
67 session = sdp_connect(src, dst, 0);
69 perror("Can't connect to SDP service");
73 sdp_set_notify(session, callback, NULL);
75 sdp_uuid16_create(&uuid, PUBLIC_BROWSE_GROUP);
77 search = sdp_list_append(NULL, &uuid);
79 attrids = sdp_list_append(NULL, &range);
81 //sdp_service_search_attr_async(session, search,
82 // SDP_ATTR_REQ_RANGE, attrids);
84 sdp_service_search_async(session, search, 0xffff);
86 sdp_list_free(attrids, NULL);
88 sdp_list_free(search, NULL);
90 while (!__io_finished)
96 static void usage(void)
98 printf("sdptest - Utility for SDP testing\n\n");
100 "\tsdptest [-i <dev>] <bdaddr>\n");
103 static struct option main_options[] = {
104 { "device", 1, 0, 'i' },
105 { "help", 0, 0, 'h' },
109 int main(int argc, char *argv[])
114 bacpy(&src, BDADDR_ANY);
116 while ((opt=getopt_long(argc, argv, "+i:h", main_options, NULL)) != -1) {
119 if (!strncasecmp(optarg, "hci", 3))
120 hci_devba(atoi(optarg + 3), &src);
122 str2ba(optarg, &dst);
141 str2ba(argv[0], &dst);
143 cmd_search(&src, &dst);