Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include <libusb.h>
00033 #include <stdio.h>
00034 #include <unistd.h>
00035 #include "i18n.h"
00036
00037 #define VENDOR_RIM 0x0fca
00038 #define PRODUCT_RIM_BLACKBERRY 0x0001
00039 #define PRODUCT_RIM_PEARL_DUAL 0x0004
00040 #define PRODUCT_RIM_PEARL_8120 0x8004
00041 #define PRODUCT_RIM_PEARL 0x0006
00042
00043 #define BLACKBERRY_INTERFACE 0
00044 #define BLACKBERRY_CONFIGURATION 1
00045
00046 #define BUSNAME_FORMAT_STR "libusb-%d"
00047
00048 #define MAX_BUSNAME_LENGTH (7 + 3 + 1)
00049
00050 bool reset(struct libusb_device *dev)
00051 {
00052 libusb_device_handle *handle = NULL;
00053 int err = libusb_open(dev, &handle);
00054 if( err != 0 )
00055 return false;
00056
00057 bool ret = libusb_reset_device(handle) == 0;
00058 libusb_close(handle);
00059 return ret;
00060 }
00061
00062 int main()
00063 {
00064 libusb_context *usbctx = NULL;
00065 libusb_device **devices = NULL;
00066 int found = 0;
00067 int count = 0;
00068 int i;
00069
00070 INIT_I18N(PACKAGE);
00071
00072 int err = libusb_init(&usbctx);
00073 if( err != 0 ) {
00074 printf(_("Failed to start USB: %d\n"), err);
00075 }
00076
00077 printf(_("Scanning for Blackberry devices...\n"));
00078
00079 count = libusb_get_device_list(usbctx, &devices);
00080
00081 for(i = 0; i < count; ++i ) {
00082 libusb_device *dev = devices[i];
00083 uint8_t devnum = libusb_get_device_address(dev);
00084 uint8_t busnum = libusb_get_bus_number(dev);
00085 struct libusb_device_descriptor desc;
00086 char busname[MAX_BUSNAME_LENGTH];
00087 int err = libusb_get_device_descriptor(dev, &desc);
00088 snprintf(busname, sizeof(busname),
00089 BUSNAME_FORMAT_STR, busnum);
00090
00091 busname[MAX_BUSNAME_LENGTH - 1] = 0;
00092
00093
00094 if( err == 0 &&
00095 desc.idVendor == VENDOR_RIM &&
00096 (desc.idProduct == PRODUCT_RIM_BLACKBERRY ||
00097 desc.idProduct == PRODUCT_RIM_PEARL ||
00098 desc.idProduct == PRODUCT_RIM_PEARL_8120 ||
00099 desc.idProduct == PRODUCT_RIM_PEARL_DUAL ) ) {
00100 printf(_("Found..."));
00101 printf(_("attempting to reset.\n"));
00102 if( reset(dev) )
00103 found++;
00104 else
00105 printf(_("Can't reset device on bus %s, devnum %u\n"), busname, devnum);
00106 }
00107 }
00108
00109 printf(_("%d device%s reset.\n"), found, found > 1 ? "s" : "");
00110
00111 if( devices )
00112 libusb_free_device_list(devices, 1);
00113 libusb_exit(usbctx);
00114 }
00115