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/index.php
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-2009, 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 
00035 #define VENDOR_RIM              0x0fca
00036 #define PRODUCT_RIM_BLACKBERRY  0x0001
00037 #define PRODUCT_RIM_PEARL_DUAL  0x0004
00038 #define PRODUCT_RIM_PEARL_8120  0x8004
00039 #define PRODUCT_RIM_PEARL       0x0006
00040 
00041 #define BLACKBERRY_INTERFACE            0
00042 #define BLACKBERRY_CONFIGURATION        1
00043 
00044 bool reset(struct usb_device *dev)
00045 {
00046         usb_dev_handle *handle = usb_open(dev);
00047         if( !handle )
00048                 return false;
00049 
00050         bool ret = usb_reset(handle) == 0;
00051         usb_close(handle);
00052         return ret;
00053 }
00054 
00055 int main()
00056 {
00057         struct usb_bus *busses;
00058 
00059         usb_init();
00060         usb_find_busses();
00061         usb_find_devices();
00062         busses = usb_get_busses();
00063 
00064         printf("Scanning for Blackberry devices...\n");
00065         int found = 0;
00066 
00067         struct usb_bus *bus;
00068         for( bus = busses; bus; bus = bus->next ) {
00069                 struct usb_device *dev;
00070 
00071                 for (dev = bus->devices; dev; dev = dev->next) {
00072                         // Is this a blackberry?
00073                         if( dev->descriptor.idVendor == VENDOR_RIM &&
00074                             (dev->descriptor.idProduct == PRODUCT_RIM_BLACKBERRY ||
00075                              dev->descriptor.idProduct == PRODUCT_RIM_PEARL ||
00076                              dev->descriptor.idProduct == PRODUCT_RIM_PEARL_8120 ||
00077                              dev->descriptor.idProduct == PRODUCT_RIM_PEARL_DUAL ) ) {
00078                                 printf("Found...");
00079                                 printf("attempting to reset.\n");
00080                                 if( reset(dev) )
00081                                         found++;
00082                                 else
00083                                         printf("Can't reset device on bus %s, devnum %u\n", bus->dirname, (unsigned int) dev->devnum);
00084                         }
00085                 }
00086         }
00087 
00088         printf("%d device%s reset.\n", found, found > 1 ? "s" : "");
00089 }
00090 

Generated on Mon Jan 12 10:51:12 2009 for Barry by  doxygen 1.5.7.1