2 /// \file breset_libusb_1_0.cc
3 /// Attempt to reset all connected Blackberry devices via software
5 /// This file is part of the Barry project:
7 /// http://www.netdirect.ca/software/packages/barry
8 /// http://sourceforge.net/projects/barry
10 /// Compile with the following command (needs libusb 1.0):
12 /// g++ -o breset breset.cc -I/usr/include/libusb -lusb-1.0
16 Copyright (C) 2007-2013, Net Direct Inc. (http://www.netdirect.ca/)
17 Portions Copyright (C) 2011, RealVNC Ltd.
19 This program is free software; you can redistribute it and/or modify
20 it under the terms of the GNU General Public License as published by
21 the Free Software Foundation; either version 2 of the License, or
22 (at your option) any later version.
24 This program is distributed in the hope that it will be useful,
25 but WITHOUT ANY WARRANTY; without even the implied warranty of
26 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
28 See the GNU General Public License in the COPYING file at the
29 root directory of this project for more details.
37 #define VENDOR_RIM 0x0fca
38 #define PRODUCT_RIM_BLACKBERRY 0x0001
39 #define PRODUCT_RIM_PEARL_DUAL 0x0004
40 #define PRODUCT_RIM_PEARL_8120 0x8004
41 #define PRODUCT_RIM_PEARL 0x0006
43 #define BLACKBERRY_INTERFACE 0
44 #define BLACKBERRY_CONFIGURATION 1
46 #define BUSNAME_FORMAT_STR "libusb-%d"
47 // USB bus numbers can only go up to 256, i.e. 3 characters
48 #define MAX_BUSNAME_LENGTH (7 + 3 + 1)
50 bool reset(struct libusb_device
*dev
)
52 libusb_device_handle
*handle
= NULL
;
53 int err
= libusb_open(dev
, &handle
);
58 // Attempt to set the configuration as a way to reset
59 libusb_set_configuration(handle
, BLACKBERRY_CONFIGURATION
);
62 bool ret
= libusb_reset_device(handle
) == 0;
69 libusb_context
*usbctx
= NULL
;
70 libusb_device
**devices
= NULL
;
77 int err
= libusb_init(&usbctx
);
79 printf(_("Failed to start USB: %d\n"), err
);
82 printf(_("Scanning for Blackberry devices...\n"));
84 count
= libusb_get_device_list(usbctx
, &devices
);
86 for(i
= 0; i
< count
; ++i
) {
87 libusb_device
*dev
= devices
[i
];
88 uint8_t devnum
= libusb_get_device_address(dev
);
89 uint8_t busnum
= libusb_get_bus_number(dev
);
90 struct libusb_device_descriptor desc
;
91 char busname
[MAX_BUSNAME_LENGTH
];
92 int err
= libusb_get_device_descriptor(dev
, &desc
);
93 snprintf(busname
, sizeof(busname
),
94 BUSNAME_FORMAT_STR
, busnum
);
95 // Be sure it's nul terminated
96 busname
[MAX_BUSNAME_LENGTH
- 1] = 0;
98 // Is this a blackberry?
100 desc
.idVendor
== VENDOR_RIM
&&
101 (desc
.idProduct
== PRODUCT_RIM_BLACKBERRY
||
102 desc
.idProduct
== PRODUCT_RIM_PEARL
||
103 desc
.idProduct
== PRODUCT_RIM_PEARL_8120
||
104 desc
.idProduct
== PRODUCT_RIM_PEARL_DUAL
) ) {
105 printf(_("Found..."));
106 printf(_("attempting to reset.\n"));
110 printf(_("Can't reset device on bus %s, devnum %u\n"), busname
, devnum
);
114 printf(_("%d device%s reset.\n"), found
, found
> 1 ? "s" : "");
117 libusb_free_device_list(devices
, 1);