# breset.cc

Go to the documentation of this file.

    00001 ///
    00002 /// \file       breset.cc
    00003 ///             Attempt to reset all connected Blackberry devices via software
    00004 ///
    00005 ///             This file is part of the Barry project:
    00006 ///
    00007 ///             http://www.netdirect.ca/software/packages/barry
    00008 ///             http://sourceforge.net/projects/barry
    00009 ///
    00010 ///             Compile with the following command (needs libusb):
    00011 ///
    00012 ///             g++ -o breset breset.cc -lusb
    00013 ///
    00014
    00015 /*
    00016     Copyright (C) 2007-2011, Net Direct Inc. (http://www.netdirect.ca/)
    00017
    00018     This program is free software; you can redistribute it and/or modify
    00019     it under the terms of the GNU General Public License as published by
    00020     the Free Software Foundation; either version 2 of the License, or
    00021     (at your option) any later version.
    00022
    00023     This program is distributed in the hope that it will be useful,
    00024     but WITHOUT ANY WARRANTY; without even the implied warranty of
    00025     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    00026
    00027     See the GNU General Public License in the COPYING file at the
    00028     root directory of this project for more details.
    00029 */
    00030
    00031 #include <usb.h>
    00032 #include <stdio.h>
    00033 #include <unistd.h>
    00034 #include "i18n.h"
    00035
    00036 #define VENDOR_RIM              0x0fca
    00037 #define PRODUCT_RIM_BLACKBERRY  0x0001
    00038 #define PRODUCT_RIM_PEARL_DUAL  0x0004
    00039 #define PRODUCT_RIM_PEARL_8120  0x8004
    00040 #define PRODUCT_RIM_PEARL       0x0006
    00041
    00042 #define BLACKBERRY_INTERFACE            0
    00043 #define BLACKBERRY_CONFIGURATION        1
    00044
    00045 bool reset(struct usb_device *dev)
    00046 {
    00047         usb_dev_handle *handle = usb_open(dev);
    00048         if( !handle )
    00049                 return false;
    00050
    00051         bool ret = usb_reset(handle) == 0;
    00052         usb_close(handle);
    00053         return ret;
    00054 }
    00055
    00056 int main()
    00057 {
    00058         struct usb_bus *busses;
    00059
    00060         INIT_I18N(PACKAGE);
    00061
    00062         usb_init();
    00063         usb_find_busses();
    00064         usb_find_devices();
    00065         busses = usb_get_busses();
    00066
    00067         printf(_("Scanning for Blackberry devices...\n"));
    00068         int found = 0;
    00069
    00070         struct usb_bus *bus;
    00071         for( bus = busses; bus; bus = bus->next ) {
    00072                 struct usb_device *dev;
    00073
    00074                 for (dev = bus->devices; dev; dev = dev->next) {
    00075                         // Is this a blackberry?
    00076                         if( dev->descriptor.idVendor == VENDOR_RIM &&
    00077                             (dev->descriptor.idProduct == PRODUCT_RIM_BLACKBERRY ||
    00078                              dev->descriptor.idProduct == PRODUCT_RIM_PEARL ||
    00079                              dev->descriptor.idProduct == PRODUCT_RIM_PEARL_8120 ||
    00080                              dev->descriptor.idProduct == PRODUCT_RIM_PEARL_DUAL ) ) {
    00081                                 printf(_("Found..."));
    00082                                 printf(_("attempting to reset.\n"));
    00083                                 if( reset(dev) )
    00084                                         found++;
    00085                                 else
    00086                                         printf(_("Can't reset device on bus %s, devnum %u\n"), bus->dirname, (unsigned int) dev->devnum);
    00087                         }
    00088                 }
    00089         }
    00090
    00091         printf(_("%d device%s reset.\n"), found, found > 1 ? "s" : "");
    00092 }
    00093