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)
49 int (*func)(struct device_info *dev, int argc, char *argv[]);
53 struct usb_device *dev;
57 static int switch_babel(struct device_info *devinfo, int argc, char *argv[])
60 struct usb_dev_handle *udev;
63 memset(buf, 0, sizeof(buf));
69 udev = usb_open(devinfo->dev);
73 if (usb_claim_interface(udev, 0) < 0) {
79 err = usb_bulk_write(udev, 0x02, buf, sizeof(buf), 10000);
85 if (errno == ETIMEDOUT)
89 usb_release_interface(udev, 0);
95 static struct device_id device_list[] = {
96 { 0x0a12, 0x0042, switch_babel },
100 static struct device_id *match_device(uint16_t vendor, uint16_t product)
104 for (i = 0; device_list[i].func; i++) {
105 if (vendor == device_list[i].vendor &&
106 product == device_list[i].product)
107 return &device_list[i];
113 static int find_devices(struct device_info *devinfo, size_t size)
116 struct usb_device *dev;
117 struct device_id *id;
118 unsigned int count = 0;
123 for (bus = usb_get_busses(); bus; bus = bus->next)
124 for (dev = bus->devices; dev; dev = dev->next) {
125 id = match_device(dev->descriptor.idVendor,
126 dev->descriptor.idProduct);
131 devinfo[count].dev = dev;
132 devinfo[count].id = id;
140 static void usage(void)
142 printf("dfubabel - Babel DFU mode switching utility\n\n");
145 "\tdfubabel [options]\n"
149 "\t-h, --help Display help\n"
150 "\t-q, --quiet Don't display any messages\n"
154 static struct option main_options[] = {
155 { "help", 0, 0, 'h' },
156 { "quiet", 0, 0, 'q' },
160 int main(int argc, char *argv[])
162 struct device_info dev[16];
163 int i, opt, num, quiet = 0;
165 while ((opt = getopt_long(argc, argv, "+qh", main_options, NULL)) != -1) {
184 num = find_devices(dev, sizeof(dev) / sizeof(dev[0]));
187 fprintf(stderr, "No Babel devices found\n");
191 for (i = 0; i < num; i++) {
192 struct device_id *id = dev[i].id;
196 printf("Switching device %04x:%04x ",
197 id->vendor, id->product);
200 err = id->func(&dev[i], argc, argv);
203 printf("failed (%s)\n", strerror(-err));
206 printf("was successful\n");