Typo fix
[barry/pauldeden.git] / tools / bidentify.cc
blob56f2bed3e1cb9d351bd045db01b637af83a3d09e
1 ///
2 /// \file bidentify.cc
3 /// Tool for probing identifying Blackberry devices
4 ///
6 /*
7 Copyright (C) 2005-2008, Net Direct Inc. (http://www.netdirect.ca/)
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 See the GNU General Public License in the COPYING file at the
19 root directory of this project for more details.
22 #include <barry/barry.h>
23 #include <iostream>
24 #include <iomanip>
25 #include <getopt.h>
27 using namespace std;
28 using namespace Barry;
30 void Usage()
32 int major, minor;
33 const char *Version = Barry::Version(major, minor);
35 cerr
36 << "bidentify - USB Blackberry Identifier Tool\n"
37 << " Copyright 2005-2008, Net Direct Inc. (http://www.netdirect.ca/)\n"
38 << " Using: " << Version << "\n"
39 << "\n"
40 << " -B bus Specify which USB bus to search on\n"
41 << " -N dev Specify which system device, using system specific string\n"
42 << "\n"
43 << " -h This help\n"
44 << " -v Dump protocol data during operation\n"
45 << endl;
48 int main(int argc, char *argv[])
50 cout.sync_with_stdio(true); // leave this on, since libusb uses
51 // stdio for debug messages
53 try {
55 bool data_dump = false;
56 string busname;
57 string devname;
59 // process command line options
60 for(;;) {
61 int cmd = getopt(argc, argv, "B:hN:v");
62 if( cmd == -1 )
63 break;
65 switch( cmd )
67 case 'B': // busname
68 busname = optarg;
69 break;
71 case 'N': // Devname
72 devname = optarg;
73 break;
75 case 'v': // data dump on
76 data_dump = true;
77 break;
79 case 'h': // help
80 default:
81 Usage();
82 return 0;
86 Barry::Init(data_dump);
87 Barry::Probe probe(busname.c_str(), devname.c_str());
89 // show any errors during probe first
90 if( probe.GetFailCount() ) {
91 cerr << "Blackberry device errors with errors during probe:" << endl;
92 for( int i = 0; i < probe.GetFailCount(); i++ ) {
93 cerr << probe.GetFailMsg(i) << endl;
97 // show all successfully found devices
98 for( int i = 0; i < probe.GetCount(); i++ ) {
99 const ProbeResult &pr = probe.Get(i);
100 cout << hex << pr.m_pin << ", "
101 << pr.m_description << endl;
104 return probe.GetFailCount();
107 catch( std::exception &e ) {
108 cerr << "exception caught: " << e.what() << endl;
109 return 1;