bidentify.cc

Go to the documentation of this file.
00001 ///
00002 /// \file       bidentify.cc
00003 ///             Tool for probing identifying Blackberry devices
00004 ///
00005 
00006 /*
00007     Copyright (C) 2005-2008, Net Direct Inc. (http://www.netdirect.ca/)
00008 
00009     This program is free software; you can redistribute it and/or modify
00010     it under the terms of the GNU General Public License as published by
00011     the Free Software Foundation; either version 2 of the License, or
00012     (at your option) any later version.
00013 
00014     This program is distributed in the hope that it will be useful,
00015     but WITHOUT ANY WARRANTY; without even the implied warranty of
00016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00017 
00018     See the GNU General Public License in the COPYING file at the
00019     root directory of this project for more details.
00020 */
00021 
00022 #include <barry/barry.h>
00023 #include <iostream>
00024 #include <iomanip>
00025 #include <getopt.h>
00026 
00027 using namespace std;
00028 using namespace Barry;
00029 
00030 void Usage()
00031 {
00032    int major, minor;
00033    const char *Version = Barry::Version(major, minor);
00034 
00035    cerr
00036    << "bidentify - USB Blackberry Identifier Tool\n"
00037    << "            Copyright 2005-2008, Net Direct Inc. (http://www.netdirect.ca/)\n"
00038    << "            Using: " << Version << "\n"
00039    << "\n"
00040    << "   -B bus    Specify which USB bus to search on\n"
00041    << "   -N dev    Specify which system device, using system specific string\n"
00042    << "\n"
00043    << "   -h        This help\n"
00044    << "   -v        Dump protocol data during operation\n"
00045    << endl;
00046 }
00047 
00048 int main(int argc, char *argv[])
00049 {
00050         cout.sync_with_stdio(true);     // leave this on, since libusb uses
00051                                         // stdio for debug messages
00052 
00053         try {
00054 
00055                 bool data_dump = false;
00056                 string busname;
00057                 string devname;
00058 
00059                 // process command line options
00060                 for(;;) {
00061                         int cmd = getopt(argc, argv, "B:hN:v");
00062                         if( cmd == -1 )
00063                                 break;
00064 
00065                         switch( cmd )
00066                         {
00067                         case 'B':       // busname
00068                                 busname = optarg;
00069                                 break;
00070 
00071                         case 'N':       // Devname
00072                                 devname = optarg;
00073                                 break;
00074 
00075                         case 'v':       // data dump on
00076                                 data_dump = true;
00077                                 break;
00078 
00079                         case 'h':       // help
00080                         default:
00081                                 Usage();
00082                                 return 0;
00083                         }
00084                 }
00085 
00086                 Barry::Init(data_dump);
00087                 Barry::Probe probe(busname.c_str(), devname.c_str());
00088 
00089                 // show any errors during probe first
00090                 if( probe.GetFailCount() ) {
00091                         cerr << "Blackberry device errors with errors during probe:" << endl;
00092                         for( int i = 0; i < probe.GetFailCount(); i++ ) {
00093                                 cerr << probe.GetFailMsg(i) << endl;
00094                         }
00095                 }
00096 
00097                 // show all successfully found devices
00098                 for( int i = 0; i < probe.GetCount(); i++ ) {
00099                         const ProbeResult &pr = probe.Get(i);
00100                         cout    << hex << pr.m_pin << ", "
00101                                 << pr.m_description << endl;
00102                 }
00103 
00104                 return probe.GetFailCount();
00105 
00106         }
00107         catch( std::exception &e ) {
00108                 cerr << "exception caught: " << e.what() << endl;
00109                 return 1;
00110         }
00111 }
00112 

Generated on Wed Sep 24 21:27:31 2008 for Barry by  doxygen 1.5.1