3
* BlueZ - Bluetooth protocol stack for Linux
5
* Copyright (C) 2004-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
37
#ifdef NEED_USB_GET_BUSSES
38
static inline struct usb_bus *usb_get_busses(void)
45
#define USB_DIR_OUT 0x00
49
#define USB_DIR_IN 0x80
52
#define HID_REQ_GET_REPORT 0x01
53
#define HID_REQ_GET_IDLE 0x02
54
#define HID_REQ_GET_PROTOCOL 0x03
55
#define HID_REQ_SET_REPORT 0x09
56
#define HID_REQ_SET_IDLE 0x0a
57
#define HID_REQ_SET_PROTOCOL 0x0b
64
int (*func)(struct device_info *dev, int argc, char *argv[]);
68
struct usb_device *dev;
72
#define GET_STATE 0x01
73
#define GET_REMOTE_BDADDR 0x02
75
#define SWITCH_TO_DFU 0x04
76
#define READ_CODEC 0x05
78
static int dongle_csr(struct device_info *devinfo, int argc, char *argv[])
81
struct usb_dev_handle *udev;
84
memset(buf, 0, sizeof(buf));
86
if (!strncasecmp(argv[0], "discover", 4))
88
else if (!strncasecmp(argv[0], "switch", 3))
89
buf[0] = SWITCH_TO_DFU;
90
else if (!strncasecmp(argv[0], "dfu", 3))
91
buf[0] = SWITCH_TO_DFU;
95
udev = usb_open(devinfo->dev);
99
if (usb_claim_interface(udev, intf) < 0) {
105
err = usb_control_msg(udev, USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
106
HID_REQ_SET_REPORT, 0x03 << 8, intf, buf, sizeof(buf), 10000);
112
if (errno == ETIMEDOUT)
116
usb_release_interface(udev, intf);
122
static struct device_id device_list[] = {
123
{ 0x0a12, 0x1004, dongle_csr },
127
static struct device_id *match_device(uint16_t vendor, uint16_t product)
131
for (i = 0; device_list[i].func; i++) {
132
if (vendor == device_list[i].vendor &&
133
product == device_list[i].product)
134
return &device_list[i];
140
static int find_devices(struct device_info *devinfo, size_t size)
143
struct usb_device *dev;
144
struct device_id *id;
145
unsigned int count = 0;
150
for (bus = usb_get_busses(); bus; bus = bus->next)
151
for (dev = bus->devices; dev; dev = dev->next) {
152
id = match_device(dev->descriptor.idVendor,
153
dev->descriptor.idProduct);
158
devinfo[count].dev = dev;
159
devinfo[count].id = id;
167
static void usage(void)
169
printf("avctrl - Bluetooth Audio/Video control utility\n\n");
172
"\tavctrl [options] <command>\n"
176
"\t-h, --help Display help\n"
177
"\t-q, --quiet Don't display any messages\n"
181
"\tdiscover Simulate pressing the discover button\n"
182
"\tswitch Switch the dongle to DFU mode\n"
186
static struct option main_options[] = {
187
{ "help", 0, 0, 'h' },
188
{ "quiet", 0, 0, 'q' },
192
int main(int argc, char *argv[])
194
struct device_info dev[16];
195
int i, opt, num, quiet = 0;
197
while ((opt = getopt_long(argc, argv, "+qh", main_options, NULL)) != -1) {
221
num = find_devices(dev, sizeof(dev) / sizeof(dev[0]));
224
fprintf(stderr, "No Audio/Video devices found\n");
228
for (i = 0; i < num; i++) {
229
struct device_id *id = dev[i].id;
233
printf("Selecting device %04x:%04x ",
234
id->vendor, id->product);
237
err = id->func(&dev[i], argc, argv);
240
printf("failed (%s)\n", strerror(-err));
243
printf("was successful\n");