menu: added new Keywords tag to .desktop files
[barry.git] / tools / breset.cc
blob2038af38a80ecf54c37a67136d08bc2a913ed6ec
1 ///
2 /// \file breset.cc
3 /// Attempt to reset all connected Blackberry devices via software
4 ///
5 /// This file is part of the Barry project:
6 ///
7 /// http://www.netdirect.ca/software/packages/barry
8 /// http://sourceforge.net/projects/barry
9 ///
10 /// Compile with the following command (needs libusb):
11 ///
12 /// g++ -o breset breset.cc -lusb
13 ///
16 Copyright (C) 2007-2013, Net Direct Inc. (http://www.netdirect.ca/)
18 This program is free software; you can redistribute it and/or modify
19 it under the terms of the GNU General Public License as published by
20 the Free Software Foundation; either version 2 of the License, or
21 (at your option) any later version.
23 This program is distributed in the hope that it will be useful,
24 but WITHOUT ANY WARRANTY; without even the implied warranty of
25 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
27 See the GNU General Public License in the COPYING file at the
28 root directory of this project for more details.
31 #include <usb.h>
32 #include <stdio.h>
33 #include <unistd.h>
34 #include "i18n.h"
36 #define VENDOR_RIM 0x0fca
37 #define PRODUCT_RIM_BLACKBERRY 0x0001
38 #define PRODUCT_RIM_PEARL_DUAL 0x0004
39 #define PRODUCT_RIM_PEARL_8120 0x8004
40 #define PRODUCT_RIM_PEARL 0x0006
42 #define BLACKBERRY_INTERFACE 0
43 #define BLACKBERRY_CONFIGURATION 1
45 bool reset(struct usb_device *dev)
47 usb_dev_handle *handle = usb_open(dev);
48 if( !handle )
49 return false;
51 bool ret = usb_reset(handle) == 0;
52 usb_close(handle);
53 return ret;
56 int main()
58 struct usb_bus *busses;
60 INIT_I18N(PACKAGE);
62 usb_init();
63 usb_find_busses();
64 usb_find_devices();
65 busses = usb_get_busses();
67 printf(_("Scanning for Blackberry devices...\n"));
68 int found = 0;
70 struct usb_bus *bus;
71 for( bus = busses; bus; bus = bus->next ) {
72 struct usb_device *dev;
74 for (dev = bus->devices; dev; dev = dev->next) {
75 // Is this a blackberry?
76 if( dev->descriptor.idVendor == VENDOR_RIM &&
77 (dev->descriptor.idProduct == PRODUCT_RIM_BLACKBERRY ||
78 dev->descriptor.idProduct == PRODUCT_RIM_PEARL ||
79 dev->descriptor.idProduct == PRODUCT_RIM_PEARL_8120 ||
80 dev->descriptor.idProduct == PRODUCT_RIM_PEARL_DUAL ) ) {
81 printf(_("Found..."));
82 printf(_("attempting to reset.\n"));
83 if( reset(dev) )
84 found++;
85 else
86 printf(_("Can't reset device on bus %s, devnum %u\n"), bus->dirname, (unsigned int) dev->devnum);
91 printf(_("%d device%s reset.\n"), found, found > 1 ? "s" : "");