4 files changed, 26 insertions, 8 deletions
diff --git a/libopie2/examples/opiecore/odebugdemo/odebugdemo.cpp b/libopie2/examples/opiecore/odebugdemo/odebugdemo.cpp index 74886fa..e8bf04f 100644 --- a/libopie2/examples/opiecore/odebugdemo/odebugdemo.cpp +++ b/libopie2/examples/opiecore/odebugdemo/odebugdemo.cpp @@ -1,138 +1,140 @@ /* QT */ #include <qvbox.h> #include <qhbox.h> #include <qvbuttongroup.h> #include <qhbuttongroup.h> #include <qlineedit.h> #include <qradiobutton.h> #include <qpushbutton.h> /* OPIE */ #include <qpe/config.h> #include <opie2/odebug.h> #include <opie2/oapplication.h> #include <opie2/oglobal.h> #include <opie2/oglobalsettings.h> class DemoApp : public OApplication { Q_OBJECT public: DemoApp( int argc, char** argv ) : OApplication( argc, argv, "libopie2 debug demo" ) { // you have access to your OApplication object via oApp qDebug( "Process-wide OApplication object @ %0x", oApp ); // you have access to global settings via OGlobalSettings int mode = OGlobalSettings::debugMode(); QVBox* vbox = new QVBox(); setMainWidget( vbox ); g = new QVButtonGroup( "Output Strategy", vbox ); QRadioButton* r0 = new QRadioButton( "file", g ); QRadioButton* r1 = new QRadioButton( "messagebox", g ); QRadioButton* r2 = new QRadioButton( "stderr", g ); QRadioButton* r3 = new QRadioButton( "syslog", g ); QRadioButton* r4 = new QRadioButton( "socket", g ); g->insert( r0, 0 ); g->insert( r1, 1 ); g->insert( r2, 2 ); g->insert( r3, 3 ); g->insert( r4, 4 ); g->setRadioButtonExclusive( true ); connect( g, SIGNAL( clicked(int) ), this, SLOT( chooseMethod(int) ) ); if ( mode != -1 ) g->setButton( mode ); QHButtonGroup* hbox = new QHButtonGroup( "Extra Output Information", vbox ); e = new QLineEdit( hbox ); QPushButton* pb = new QPushButton( hbox ); connect( e, SIGNAL( returnPressed() ), this, SLOT( updateDebugOutput() ) ); connect( pb, SIGNAL( clicked() ), this, SLOT( updateDebugOutput() ) ); // show the additional debug mode dependent output information e->setText( OGlobalSettings::debugOutput() ); // buttos QPushButton* info = new QPushButton( "Emit Debug(Info) Output!", vbox ); connect( info, SIGNAL( clicked() ), this, SLOT( emitInfoOutput() ) ); QPushButton* warn = new QPushButton( "Emit a Warning Output!", vbox ); connect( warn, SIGNAL( clicked() ), this, SLOT( emitWarningOutput() ) ); QPushButton* error = new QPushButton( "Emit an Error Output!", vbox ); connect( error, SIGNAL( clicked() ), this, SLOT( emitErrorOutput() ) ); QPushButton* fatal = new QPushButton( "Emit a Fatal Output!", vbox ); connect( fatal, SIGNAL( clicked() ), this, SLOT( emitFatalOutput() ) ); QPushButton* tb = new QPushButton( "Emit a Fatal Backtrace!", vbox ); connect( tb, SIGNAL( clicked() ), this, SLOT( emitTBOutput() ) ); info->show(); warn->show(); error->show(); fatal->show(); tb->show(); g->show(); hbox->show(); e->show(); vbox->show(); showMainWidget( vbox ); } public slots: void chooseMethod(int method) { m = method; qDebug( "choosing method: %d", method ); OConfig* g = OGlobal::config(); g->setGroup( "General" ); g->writeEntry( "debugMode", m ); e->setText( OGlobalSettings::debugOutput() ); + g->write(); } void updateDebugOutput() { OConfig* g = OGlobal::config(); g->setGroup( "General" ); g->writeEntry( "debugOutput"+QString::number(OGlobalSettings::debugMode()), e->text() ); + g->write(); } void emitInfoOutput() { odebug << "This is a debug message" << oendl; } void emitWarningOutput() { owarn << "This is a warning message" << oendl; } void emitErrorOutput() { oerr << "This is an errror message" << oendl; } void emitFatalOutput() { ofatal << "This is a fatal message" << oendl; } void emitTBOutput() { ofatal << "This is a fatal message + backtrace\n" + odBacktrace(); // odBacktrace includes \n } private: QButtonGroup* g; int m; QLineEdit* e; }; int main( int argc, char** argv ) { DemoApp* app = new DemoApp( argc, argv ); app->exec(); return 0; } #include "moc/odebugdemo.moc" diff --git a/libopie2/examples/opienet/miniwellenreiter/miniwellenreiter.cpp b/libopie2/examples/opienet/miniwellenreiter/miniwellenreiter.cpp index c49daa0..eb2e8e8 100644 --- a/libopie2/examples/opienet/miniwellenreiter/miniwellenreiter.cpp +++ b/libopie2/examples/opienet/miniwellenreiter/miniwellenreiter.cpp @@ -1,217 +1,232 @@ #include <qdict.h> #include <qsocketnotifier.h> #include <qstring.h> #include <opie2/onetwork.h> #include <qapplication.h> #include <opie2/opcap.h> #include <cerrno> #include <cstdio> #include <cstdlib> #include <cstring> //======================== Station help class =============================== class Station { public: Station( QString t, int c, bool w ) : type(t), channel(c), wep(w), beacons(1) {}; ~Station() {}; QString type; int channel; bool wep; int beacons; }; QDict<Station> stations; //======================== Application class =============================== class Wellenreiter : public QApplication { Q_OBJECT public: - Wellenreiter( int argc, char** argv ) : QApplication( argc, argv ) + Wellenreiter( int argc, char** argv ) : QApplication( argc, argv ), channel( 1 ) { ONetwork* net = ONetwork::instance(); if ( argc < 3 ) { printf( "Usage: ./%s <interface> <driver> <interval>\n", argv[0] ); printf( "\n" ); printf( "Valid wireless interfaces (detected) are:\n" ); ONetwork::InterfaceIterator it = net->iterator(); while ( it.current() ) { if ( it.current()->isWireless() ) { printf( " - '%s' (MAC=%s) (IPv4=%s)\n", (const char*) it.current()->name(), (const char*) it.current()->macAddress().toString(), (const char*) it.current()->ipV4Address() ); } ++it; } exit( -1 ); } - printf( "****************************************************\n" ); - printf( "* Wellenreiter mini edition 1.0 (C) 2003 M-M-M *\n" ); - printf( "****************************************************\n" ); + printf( "*******************************************************************\n" ); + printf( "* Wellenreiter mini edition 1.0.0 (C) 2003 Michael 'Mickey' Lauer *\n" ); + printf( "*******************************************************************\n" ); printf( "\n\n" ); QString interface( argv[1] ); QString driver( argv[2] ); printf( "Trying to use '%s' as %s-controlled device...\n", (const char*) interface, (const char*) driver ); // sanity checks before downcasting ONetworkInterface* iface = net->interface( interface ); if ( !iface ) { printf( "Interface '%s' doesn't exist. Exiting.\n", (const char*) interface ); exit( -1 ); } if ( !iface->isWireless() ) { printf( "Interface '%s' doesn't support wireless extensions. Exiting.\n", (const char*) interface ); exit( -1 ); } // downcast should be safe now wiface = (OWirelessNetworkInterface*) iface; printf( "Using wireless interface '%s' for scanning (current SSID is '%s')...\n", (const char*) interface, (const char*) wiface->SSID() ); // ifconfig +promisc the interface to receive all packets if ( !wiface->promiscuousMode() ) { printf( "Interface status is not promisc... switching to promisc... " ); wiface->setPromiscuousMode( true ); if ( !wiface->promiscuousMode() ) { printf( "failed (%s). Exiting.\n", strerror( errno ) ); exit( -1 ); } else { printf( "ok.\n" ); } } else printf( "Interface status is already promisc - good.\n" ); // connect a monitoring strategy to the interface if ( driver == "orinoco" ) new OOrinocoMonitoringInterface( wiface, false ); else + if ( driver == "hostap" ) + new OHostAPMonitoringInterface( wiface, false ); + else + if ( driver == "wlan-ng" ) + new OWlanNGMonitoringInterface( wiface, false ); + else { printf( "Unknown driver. Exiting\n" ); exit( -1 ); } // enable monitoring mode printf( "Enabling monitor mode...\n" ); - //wiface->setMonitorMode( true ); + wiface->setMode( "monitor" ); // open a packet capturer cap = new OPacketCapturer(); cap->open( interface ); if ( !cap->isOpen() ) { printf( "Unable to open libpcap (%s). Exiting.\n", strerror( errno ) ); exit( -1 ); } // set capturer to non-blocking mode cap->setBlocking( false ); // start channel hopper //wiface->setChannelHopping( 1000 ); // connect connect( cap, SIGNAL( receivedPacket(OPacket*) ), this, SLOT( receivePacket(OPacket*) ) ); + // timer + startTimer( 1000 ); } ~Wellenreiter() {}; public slots: + virtual void timerEvent(QTimerEvent* e) + { + wiface->setChannel( channel++ ); + if ( channel == 14 ) channel = 1; + } + void receivePacket(OPacket* p) { if (!p) { printf( "(empty packet received)\n" ); return; } OWaveLanManagementPacket* beacon = (OWaveLanManagementPacket*) p->child( "802.11 Management" ); if ( beacon ) { OWaveLanManagementSSID* ssid = static_cast<OWaveLanManagementSSID*>( p->child( "802.11 SSID" ) ); QString essid = ssid ? ssid->ID() : "<unknown>"; if ( stations.find( essid ) ) stations[essid]->beacons++; else { printf( "found new network @ channel %d, SSID = '%s'\n", wiface->channel(), (const char*) essid ); stations.insert( essid, new Station( "unknown", wiface->channel(), ((OWaveLanPacket*) beacon->parent())->usesWep() ) ); } return; } OWaveLanDataPacket* data = (OWaveLanDataPacket*) p->child( "802.11 Data" ); if ( data ) { OWaveLanPacket* wlan = (OWaveLanPacket*) p->child( "802.11" ); if ( wlan->fromDS() && !wlan->toDS() ) { printf( "FromDS: '%s' -> '%s' via '%s'\n", (const char*) wlan->macAddress3().toString(true), (const char*) wlan->macAddress1().toString(true), (const char*) wlan->macAddress2().toString(true) ); } else if ( !wlan->fromDS() && wlan->toDS() ) { printf( "ToDS: '%s' -> '%s' via '%s'\n", (const char*) wlan->macAddress2().toString(true), (const char*) wlan->macAddress3().toString(true), (const char*) wlan->macAddress1().toString(true) ); } else if ( wlan->fromDS() && wlan->toDS() ) { printf( "WSD(bridge): '%s' -> '%s' via '%s' and '%s'\n", (const char*) wlan->macAddress4().toString(true), (const char*) wlan->macAddress3().toString(true), (const char*) wlan->macAddress1().toString(true), (const char*) wlan->macAddress2().toString(true) ); } else { printf( "IBSS(AdHoc): '%s' -> '%s' (Cell: '%s')'\n", (const char*) wlan->macAddress2().toString(true), (const char*) wlan->macAddress1().toString(true), (const char*) wlan->macAddress3().toString(true) ); } return; } } private: OPacketCapturer* cap; OWirelessNetworkInterface* wiface; + int channel; }; int main( int argc, char** argv ) { Wellenreiter w( argc, argv ); w.exec(); return 0; } #include "miniwellenreiter.moc" diff --git a/libopie2/examples/opienet/miniwellenreiter/miniwellenreiter.pro b/libopie2/examples/opienet/miniwellenreiter/miniwellenreiter.pro index 7ce535c..b2c5c14 100644 --- a/libopie2/examples/opienet/miniwellenreiter/miniwellenreiter.pro +++ b/libopie2/examples/opienet/miniwellenreiter/miniwellenreiter.pro diff --git a/libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp b/libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp index 06b8b19..4763316 100644 --- a/libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp +++ b/libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp @@ -17,126 +17,127 @@ int main( int argc, char** argv ) qDebug( "DEMO: ONetwork contains Interface '%s'", (const char*) it.current()->name() ); qDebug( "DEMO: Datalink code is '%d'", it.current()->dataLinkType() ); qDebug( "DEMO: MAC Address is '%s'", (const char*) it.current()->macAddress().toString() ); qDebug( "DEMO: MAC Address is '%s'", (const char*) it.current()->macAddress().toString(true) ); qDebug( "DEMO: MAC Manufacturer seems to be '%s'", (const char*) it.current()->macAddress().manufacturer() ); qDebug( "DEMO: Manufacturertest1 = '%s'", (const char*) OManufacturerDB::instance()->lookupExt( "08:00:87" ) ); qDebug( "DEMO: Manufacturertest2 = '%s'", (const char*) OManufacturerDB::instance()->lookupExt( "E2:0C:0F" ) ); qDebug( "Demo: IPv4 Address is '%s'", (const char*) it.current()->ipV4Address() ); if ( it.current()->isWireless() ) { OWirelessNetworkInterface* iface = static_cast<OWirelessNetworkInterface*>( it.current() ); qDebug( "DEMO: '%s' seems to feature the wireless extensions.", (const char*) iface->name() ); qDebug( "DEMO: Current SSID is '%s'", (const char*) iface->SSID() ); qDebug( "DEMO: Antenna is tuned to '%f', that is channel %d", iface->frequency(), iface->channel() ); //if ( iface->mode() == OWirelessNetworkInterface::adhoc ) //{ //qDebug( "DEMO: Associated AP has MAC Address '%s'", (const char*) iface->associatedAP().toString() ); //} /* // nickname qDebug( "DEMO: Current NickName is '%s'", (const char*) iface->nickName() ); iface->setNickName( "MyNickName" ); if ( iface->nickName() != "MyNickName" ) qDebug( "DEMO: Warning! Can't change nickname" ); else qDebug( "DEMO: Nickname change successful." ); /* // operation mode qDebug( "DEMO: Current OperationMode is '%s'", (const char*) iface->mode() ); iface->setMode( "adhoc" ); if ( iface->mode() != "adhoc" ) qDebug( "DEMO: Warning! Can't change operation mode" ); else qDebug( "DEMO: Operation Mode change successful." ); // RF channel qDebug( "DEMO: Current Channel is '%d'", iface->channel() ); iface->setChannel( 1 ); if ( iface->channel() != 1 ) qDebug( "DEMO: Warning! Can't change RF channel" ); else qDebug( "DEMO: RF channel change successful." ); iface->setMode( "managed" ); */ /* // network scan OStationList* stations = iface->scanNetwork(); if ( stations ) { qDebug( "DEMO: # of stations around = %d", stations->count() ); OStation* station; for ( station = stations->first(); station != 0; station = stations->next() ) { qDebug( "DEMO: station dump following..." ); station->dump(); } } else { qDebug( "DEMO: Warning! Scan didn't work!" ); } /* // first some wrong calls to check if this is working iface->setPrivate( "seppel", 10 ); iface->setPrivate( "monitor", 0 ); // now the real deal iface->setPrivate( "monitor", 2, 2, 3 ); // trying to set hw address to 12:34:56:AB:CD:EF /* OMacAddress addr = OMacAddress::fromString( "12:34:56:AB:CD:EF" ); iface->setUp( false ); iface->setMacAddress( addr ); iface->setUp( true ); qDebug( "DEMO: MAC Address now is '%s'", (const char*) iface->macAddress().toString() ); */ // monitor test - /* + qDebug( "DEMO: current interface mode is '%s'", (const char*) iface->mode() ); iface->setMode( "monitor" ); qDebug( "DEMO: current interface mode is '%s'", (const char*) iface->mode() ); - sleep( 1 ); */ + sleep( 1 ); - iface->setMode( "master" ); + iface->setChannel( 1 ); + iface->setMode( "managed" ); //sleep( 1 ); qDebug( "DEMO: current interface mode is '%s'", (const char*) iface->mode() ); /*iface->setMode( "adhoc" ); sleep( 1 ); qDebug( "DEMO: current interface mode is '%s'", (const char*) iface->mode() ); iface->setMode( "managed" ); sleep( 1 ); qDebug( "DEMO: current interface mode is '%s'", (const char*) iface->mode() ); iface->setMode( "master" ); sleep( 1 ); qDebug( "DEMO: current interface mode is '%s'", (const char*) iface->mode() );*/ } ++it; } return 0; } |