3 /// In the same vein as pppoe, used with pppd to create a
4 /// pty tunnel and GPRS modem link.
8 Copyright (C) 2007-2008, Net Direct Inc. (http://www.netdirect.ca/)
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19 See the GNU General Public License in the COPYING file at the
20 root directory of this project for more details.
23 #include <barry/barry.h>
30 #include <sys/select.h>
32 #include <sys/types.h>
37 using namespace Barry
;
39 bool data_dump
= false;
44 const char *Version
= Barry::Version(major
, minor
);
47 << "pppob - PPP over Barry\n"
48 << " Copyright 2007-2008, Net Direct Inc. (http://www.netdirect.ca/)\n"
49 << " Using: " << Version
<< "\n"
51 << " -p pin PIN of device to talk with\n"
52 << " If only one device plugged in, this flag is optional\n"
53 << " -v Dump protocol data during operation (debugging only!)\n"
57 void SerialDataCallback(void *context
, const unsigned char *data
, int len
)
59 if( len
&& data_dump
)
60 barryverbose("ReadThread:\n" << Data(data
, len
));
63 int written
= write(1, data
, len
);
69 barryverbose("Error in write()");
74 int main(int argc
, char *argv
[])
76 cout
.sync_with_stdio(true); // leave this on, since libusb uses
77 // stdio for debug messages
83 // process command line options
85 int cmd
= getopt(argc
, argv
, "p:v");
91 case 'p': // Blackberry PIN
92 pin
= strtoul(optarg
, NULL
, 16);
95 case 'v': // data dump on
106 // Initialize the barry library. Must be called before
108 // Log to stderr, since stdout is for data in this program.
109 // std::ofstream log("/tmp/log", ios::app);
110 // Barry::Init(data_dump, &log);
111 Barry::Init(data_dump
, &std::cerr
);
113 // Probe the USB bus for Blackberry devices and display.
114 // If user has specified a PIN, search for it in the
115 // available device list here as well
117 int activeDevice
= probe
.FindActive(pin
);
118 if( activeDevice
== -1 ) {
120 cerr
<< "PIN " << setbase(16) << pin
121 << " not found" << endl
;
122 cerr
<< "No device selected" << endl
;
127 // for serial mode, not yet supported
128 // Create our socket router and start thread to handle
129 // the USB reading, instead of creating our own thread.
130 SocketRoutingQueue router;
131 router.SpinoffSimpleReadThread();
133 // Create our controller object using our threaded router.
134 Controller con(probe.Get(activeDevice), router);
136 // Open desktop mode... this handles the password side
138 // Mode::Desktop desktop(con);
139 // desktop.Open(); // FIXME - support password here?
143 // Create our controller object using our threaded router.
144 Controller
con(probe
.Get(activeDevice
));
146 // Open serial mode... the callback handles reading from
147 // USB and writing to stdout
148 Mode::IpModem
modem(con
, SerialDataCallback
, 0);
151 // Read from stdin and write to USB, until
162 // Need to use select() here, so that pppd doesn't
163 // hang when it tries to set the line discipline
170 ret
= select(1, &rfds
, NULL
, NULL
, &tv
);
174 else if( ret
&& FD_ISSET(0, &rfds
) ) {
175 bytes_read
= read(0, data
.GetBuffer(), data
.GetBufSize());
176 if( bytes_read
== 0 )
179 if( bytes_read
> 0 ) {
180 data
.ReleaseBuffer(bytes_read
);
186 barryverbose("Exiting");
189 catch( std::exception
&e
) {
190 cerr
<< "exception caught in main(): " << e
.what() << endl
;