# 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-2011, 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 #include "i18n.h"
    00027
    00028 using namespace std;
    00029 using namespace Barry;
    00030
    00031 void Usage()
    00032 {
    00033    int major, minor;
    00034    const char *Version = Barry::Version(major, minor);
    00035
    00036    cerr
    00037    << "bidentify - USB Blackberry Identifier Tool\n"
    00038    << "            Copyright 2005-2011, Net Direct Inc. (http://www.netdirect.ca/)\n"
    00039    << "            Using: " << Version << "\n"
    00040    << "\n"
    00041    << "   -B bus    Specify which USB bus to search on\n"
    00042    << "   -N dev    Specify which system device, using system specific string\n"
    00043    << "\n"
    00044    << "   -h        This help\n"
    00045    << "   -v        Dump protocol data during operation\n"
    00046    << endl;
    00047 }
    00048
    00049 int main(int argc, char *argv[])
    00050 {
    00051         INIT_I18N(PACKAGE);
    00052
    00053         cout.sync_with_stdio(true);     // leave this on, since libusb uses
    00054                                         // stdio for debug messages
    00055
    00056         try {
    00057
    00058                 bool data_dump = false;
    00059                 string busname;
    00060                 string devname;
    00061
    00062                 // process command line options
    00063                 for(;;) {
    00064                         int cmd = getopt(argc, argv, "B:hN:v");
    00065                         if( cmd == -1 )
    00066                                 break;
    00067
    00068                         switch( cmd )
    00069                         {
    00070                         case 'B':       // busname
    00071                                 busname = optarg;
    00072                                 break;
    00073
    00074                         case 'N':       // Devname
    00075                                 devname = optarg;
    00076                                 break;
    00077
    00078                         case 'v':       // data dump on
    00079                                 data_dump = true;
    00080                                 break;
    00081
    00082                         case 'h':       // help
    00083                         default:
    00084                                 Usage();
    00085                                 return 0;
    00086                         }
    00087                 }
    00088
    00089                 Barry::Init(data_dump);
    00090                 Barry::Probe probe(busname.c_str(), devname.c_str());
    00091
    00092                 // show any errors during probe first
    00093                 if( probe.GetFailCount() ) {
    00094                         cerr << "Blackberry device errors with errors during probe:" << endl;
    00095                         for( int i = 0; i < probe.GetFailCount(); i++ ) {
    00096                                 cerr << probe.GetFailMsg(i) << endl;
    00097                         }
    00098                 }
    00099
    00100                 // show all successfully found devices
    00101                 for( int i = 0; i < probe.GetCount(); i++ ) {
    00102                         const ProbeResult &pr = probe.Get(i);
    00103                         cout    << pr.m_pin.Str() << ", "
    00104                                 << pr.m_description << endl;
    00105                 }
    00106
    00107                 return probe.GetFailCount();
    00108
    00109         }
    00110         catch( std::exception &e ) {
    00111                 cerr << "exception caught: " << e.what() << endl;
    00112                 return 1;
    00113         }
    00114 }
    00115