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-2012, 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
);
57 bool ret
= libusb_reset_device(handle
) == 0;
64 libusb_context
*usbctx
= NULL
;
65 libusb_device
**devices
= NULL
;
72 int err
= libusb_init(&usbctx
);
74 printf(_("Failed to start USB: %d\n"), err
);
77 printf(_("Scanning for Blackberry devices...\n"));
79 count
= libusb_get_device_list(usbctx
, &devices
);
81 for(i
= 0; i
< count
; ++i
) {
82 libusb_device
*dev
= devices
[i
];
83 uint8_t devnum
= libusb_get_device_address(dev
);
84 uint8_t busnum
= libusb_get_bus_number(dev
);
85 struct libusb_device_descriptor desc
;
86 char busname
[MAX_BUSNAME_LENGTH
];
87 int err
= libusb_get_device_descriptor(dev
, &desc
);
88 snprintf(busname
, sizeof(busname
),
89 BUSNAME_FORMAT_STR
, busnum
);
90 // Be sure it's nul terminated
91 busname
[MAX_BUSNAME_LENGTH
- 1] = 0;
93 // Is this a blackberry?
95 desc
.idVendor
== VENDOR_RIM
&&
96 (desc
.idProduct
== PRODUCT_RIM_BLACKBERRY
||
97 desc
.idProduct
== PRODUCT_RIM_PEARL
||
98 desc
.idProduct
== PRODUCT_RIM_PEARL_8120
||
99 desc
.idProduct
== PRODUCT_RIM_PEARL_DUAL
) ) {
100 printf(_("Found..."));
101 printf(_("attempting to reset.\n"));
105 printf(_("Can't reset device on bus %s, devnum %u\n"), busname
, devnum
);
109 printf(_("%d device%s reset.\n"), found
, found
> 1 ? "s" : "");
112 libusb_free_device_list(devices
, 1);