summaryrefslogtreecommitdiff
path: root/examples/opienet
authormickeyl <mickeyl>2005-01-29 14:09:25 (UTC)
committer mickeyl <mickeyl>2005-01-29 14:09:25 (UTC)
commit7b06e36fe27adc6a4fde2004eac13aaf8c0f0f02 (patch) (unidiff)
tree5b38b6eb9d8430b0a96a2e156995bb421cc1a570 /examples/opienet
parent0db5704f66f0d08f9928f749774ee0f37bb0250d (diff)
downloadopie-7b06e36fe27adc6a4fde2004eac13aaf8c0f0f02.zip
opie-7b06e36fe27adc6a4fde2004eac13aaf8c0f0f02.tar.gz
opie-7b06e36fe27adc6a4fde2004eac13aaf8c0f0f02.tar.bz2
examples start to appear here
Diffstat (limited to 'examples/opienet') (more/less context) (ignore whitespace changes)
-rw-r--r--examples/opienet/.cvsignore6
-rw-r--r--examples/opienet/miniwellenreiter/.cvsignore8
-rw-r--r--examples/opienet/miniwellenreiter/miniwellenreiter.cpp234
-rw-r--r--examples/opienet/miniwellenreiter/miniwellenreiter.pro19
-rw-r--r--examples/opienet/onetworkdemo/.cvsignore8
-rw-r--r--examples/opienet/onetworkdemo/onetworkdemo.cpp176
-rw-r--r--examples/opienet/onetworkdemo/onetworkdemo.pro12
-rw-r--r--examples/opienet/opienet.pro3
8 files changed, 466 insertions, 0 deletions
diff --git a/examples/opienet/.cvsignore b/examples/opienet/.cvsignore
new file mode 100644
index 0000000..8f7300c
--- a/dev/null
+++ b/examples/opienet/.cvsignore
@@ -0,0 +1,6 @@
1Makefile*
2moc*
3*moc
4*.o
5~*
6
diff --git a/examples/opienet/miniwellenreiter/.cvsignore b/examples/opienet/miniwellenreiter/.cvsignore
new file mode 100644
index 0000000..e0e629a
--- a/dev/null
+++ b/examples/opienet/miniwellenreiter/.cvsignore
@@ -0,0 +1,8 @@
1miniwellenreiter
2Makefile*
3obj
4moc*
5*moc
6*.o
7~*
8
diff --git a/examples/opienet/miniwellenreiter/miniwellenreiter.cpp b/examples/opienet/miniwellenreiter/miniwellenreiter.cpp
new file mode 100644
index 0000000..ebd3b5f
--- a/dev/null
+++ b/examples/opienet/miniwellenreiter/miniwellenreiter.cpp
@@ -0,0 +1,234 @@
1#include <qdict.h>
2#include <qsocketnotifier.h>
3#include <qstring.h>
4#include <opie2/onetwork.h>
5#include <qapplication.h>
6#include <opie2/opcap.h>
7#include <cerrno>
8#include <cstdio>
9#include <cstdlib>
10#include <cstring>
11
12
13using namespace Opie::Net;
14//======================== Station help class ===============================
15
16class Station
17{
18 public:
19 Station( QString t, int c, bool w ) : type(t), channel(c), wep(w), beacons(1) {};
20 ~Station() {};
21
22 QString type;
23 int channel;
24 bool wep;
25 int beacons;
26};
27
28QDict<Station> stations;
29
30//======================== Application class ===============================
31
32class Wellenreiter : public QApplication
33{
34Q_OBJECT
35public:
36 Wellenreiter( int argc, char** argv ) : QApplication( argc, argv ), channel( 1 )
37 {
38
39 ONetwork* net = ONetwork::instance();
40
41 if ( argc < 3 )
42 {
43 printf( "Usage: ./%s <interface> <driver> <interval>\n", argv[0] );
44 printf( "\n" );
45 printf( "Valid wireless interfaces (detected) are:\n" );
46
47 ONetwork::InterfaceIterator it = net->iterator();
48 while ( it.current() )
49 {
50 if ( it.current()->isWireless() )
51 {
52 printf( " - '%s' (MAC=%s) (IPv4=%s)\n", (const char*) it.current()->name(),
53 (const char*) it.current()->macAddress().toString(),
54 (const char*) it.current()->ipV4Address() );
55 }
56 ++it;
57 }
58 exit( -1 );
59 }
60
61 printf( "*******************************************************************\n" );
62 printf( "* Wellenreiter mini edition 1.0.0 (C) 2003 Michael 'Mickey' Lauer *\n" );
63 printf( "*******************************************************************\n" );
64 printf( "\n\n" );
65
66 QString interface( argv[1] );
67 QString driver( argv[2] );
68
69 printf( "Trying to use '%s' as %s-controlled device...\n", (const char*) interface, (const char*) driver );
70
71 // sanity checks before downcasting
72 ONetworkInterface* iface = net->interface( interface );
73 if ( !iface )
74 {
75 printf( "Interface '%s' doesn't exist. Exiting.\n", (const char*) interface );
76 exit( -1 );
77 }
78 if ( !iface->isWireless() )
79 {
80 printf( "Interface '%s' doesn't support wireless extensions. Exiting.\n", (const char*) interface );
81 exit( -1 );
82 }
83
84 // downcast should be safe now
85 wiface = (OWirelessNetworkInterface*) iface;
86 printf( "Using wireless interface '%s' for scanning (current SSID is '%s')...\n", (const char*) interface, (const char*) wiface->SSID() );
87
88 // ifconfig +promisc the interface to receive all packets
89 if ( !wiface->promiscuousMode() )
90 {
91 printf( "Interface status is not promisc... switching to promisc... " );
92 wiface->setPromiscuousMode( true );
93 if ( !wiface->promiscuousMode() )
94 {
95 printf( "failed (%s). Exiting.\n", strerror( errno ) );
96 exit( -1 );
97 }
98 else
99 {
100 printf( "ok.\n" );
101 }
102 }
103 else
104 printf( "Interface status is already promisc - good.\n" );
105
106 // connect a monitoring strategy to the interface
107 if ( driver == "orinoco" )
108 new OOrinocoMonitoringInterface( wiface, false );
109 else
110 if ( driver == "hostap" )
111 new OHostAPMonitoringInterface( wiface, false );
112 else
113 if ( driver == "wlan-ng" )
114 new OWlanNGMonitoringInterface( wiface, false );
115 else
116 {
117 printf( "Unknown driver. Exiting\n" );
118 exit( -1 );
119 }
120
121 // enable monitoring mode
122 printf( "Enabling monitor mode...\n" );
123 wiface->setMode( "monitor" );
124
125 // open a packet capturer
126 cap = new OPacketCapturer();
127 cap->open( interface );
128 if ( !cap->isOpen() )
129 {
130 printf( "Unable to open libpcap (%s). Exiting.\n", strerror( errno ) );
131 exit( -1 );
132 }
133
134 // set capturer to non-blocking mode
135 cap->setBlocking( false );
136
137 // start channel hopper
138 //wiface->setChannelHopping( 1000 );
139
140 // connect
141 connect( cap, SIGNAL( receivedPacket(OPacket*) ), this, SLOT( receivePacket(OPacket*) ) );
142 // timer
143 startTimer( 1000 );
144
145 }
146
147 ~Wellenreiter() {};
148
149public slots:
150 virtual void timerEvent(QTimerEvent* e)
151 {
152 wiface->setChannel( channel++ );
153 if ( channel == 14 ) channel = 1;
154 }
155
156 void receivePacket(OPacket* p)
157 {
158 if (!p)
159 {
160 printf( "(empty packet received)\n" );
161 return;
162 }
163
164 OWaveLanManagementPacket* beacon = (OWaveLanManagementPacket*) p->child( "802.11 Management" );
165 if ( beacon )
166 {
167 OWaveLanManagementSSID* ssid = static_cast<OWaveLanManagementSSID*>( p->child( "802.11 SSID" ) );
168 QString essid = ssid ? ssid->ID() : QString::fromLatin1( "<unknown>" );
169
170 if ( stations.find( essid ) )
171 stations[essid]->beacons++;
172 else
173 {
174 printf( "found new network @ channel %d, SSID = '%s'\n", wiface->channel(), (const char*) essid );
175 stations.insert( essid, new Station( "unknown", wiface->channel(),
176 ((OWaveLanPacket*) beacon->parent())->usesWep() ) );
177 }
178 return;
179 }
180
181 OWaveLanDataPacket* data = (OWaveLanDataPacket*) p->child( "802.11 Data" );
182 if ( data )
183 {
184 OWaveLanPacket* wlan = (OWaveLanPacket*) p->child( "802.11" );
185 if ( wlan->fromDS() && !wlan->toDS() )
186 {
187 printf( "FromDS: '%s' -> '%s' via '%s'\n",
188 (const char*) wlan->macAddress3().toString(true),
189 (const char*) wlan->macAddress1().toString(true),
190 (const char*) wlan->macAddress2().toString(true) );
191 }
192 else
193 if ( !wlan->fromDS() && wlan->toDS() )
194 {
195 printf( "ToDS: '%s' -> '%s' via '%s'\n",
196 (const char*) wlan->macAddress2().toString(true),
197 (const char*) wlan->macAddress3().toString(true),
198 (const char*) wlan->macAddress1().toString(true) );
199 }
200 else
201 if ( wlan->fromDS() && wlan->toDS() )
202 {
203 printf( "WSD(bridge): '%s' -> '%s' via '%s' and '%s'\n",
204 (const char*) wlan->macAddress4().toString(true),
205 (const char*) wlan->macAddress3().toString(true),
206 (const char*) wlan->macAddress1().toString(true),
207 (const char*) wlan->macAddress2().toString(true) );
208 }
209 else
210 {
211 printf( "IBSS(AdHoc): '%s' -> '%s' (Cell: '%s')'\n",
212 (const char*) wlan->macAddress2().toString(true),
213 (const char*) wlan->macAddress1().toString(true),
214 (const char*) wlan->macAddress3().toString(true) );
215 }
216 return;
217 }
218 }
219private:
220 OPacketCapturer* cap;
221 OWirelessNetworkInterface* wiface;
222 int channel;
223};
224
225
226int main( int argc, char** argv )
227{
228 Wellenreiter w( argc, argv );
229 w.exec();
230 return 0;
231}
232
233#include "miniwellenreiter.moc"
234
diff --git a/examples/opienet/miniwellenreiter/miniwellenreiter.pro b/examples/opienet/miniwellenreiter/miniwellenreiter.pro
new file mode 100644
index 0000000..d7c1fc2
--- a/dev/null
+++ b/examples/opienet/miniwellenreiter/miniwellenreiter.pro
@@ -0,0 +1,19 @@
1TEMPLATE = app
2CONFIG = qt warn_on
3HEADERS =
4SOURCES = miniwellenreiter.cpp
5INCLUDEPATH += $(OPIEDIR)/include
6DEPENDPATH += $(OPIEDIR)/include
7LIBS += -lopiecore2 -lopienet2
8TARGET = miniwellenreiter
9MOC_DIR = moc
10OBJECTS_DIR = obj
11
12include( $(OPIEDIR)/include.pro )
13
14!isEmpty( LIBPCAP_INC_DIR ) {
15 INCLUDEPATH = $$LIBPCAP_INC_DIR $$INCLUDEPATH
16}
17!isEmpty( LIBPCAP_LIB_DIR ) {
18 LIBS = -L$$LIBPCAP_LIB_DIR $$LIBS
19}
diff --git a/examples/opienet/onetworkdemo/.cvsignore b/examples/opienet/onetworkdemo/.cvsignore
new file mode 100644
index 0000000..c2638e5
--- a/dev/null
+++ b/examples/opienet/onetworkdemo/.cvsignore
@@ -0,0 +1,8 @@
1onetworkdemo
2Makefile*
3obj
4moc*
5*moc
6*.o
7~*
8
diff --git a/examples/opienet/onetworkdemo/onetworkdemo.cpp b/examples/opienet/onetworkdemo/onetworkdemo.cpp
new file mode 100644
index 0000000..e0c93a2
--- a/dev/null
+++ b/examples/opienet/onetworkdemo/onetworkdemo.cpp
@@ -0,0 +1,176 @@
1/*
2 =. This file is part of the Opie Project
3 .=l. Copyright (C) 2004 Opie Team <opie-devel@handhelds.org>
4 .>+-=
5 _;:, .> :=|. This library is free software; you can
6.> <`_, > . <= redistribute it and/or modify it under
7:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
8.="- .-=="i, .._ License as published by the Free Software
9 - . .-<_> .<> Foundation; either version 2 of the License,
10 ._= =} : or (at your option) any later version.
11 .%`+i> _;_.
12 .i_,=:_. -<s. This library is distributed in the hope that
13 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
14 : .. .:, . . . without even the implied warranty of
15 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
16 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
17..}^=.= = ; Library General Public License for more
18++= -. .` .: details.
19 : = ...= . :.=-
20 -. .:....=;==+<; You should have received a copy of the GNU
21 -_. . . )=. = Library General Public License along with
22 -- :-=` this library; see the file COPYING.LIB.
23 If not, write to the Free Software Foundation,
24 Inc., 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA.
26
27*/
28
29/* OPIE */
30#include <opie2/onetwork.h>
31#include <opie2/ostation.h>
32#include <opie2/omanufacturerdb.h>
33#include <opie2/odebug.h>
34
35/* STD */
36#include <unistd.h>
37
38using namespace Opie::Net;
39
40int main( int argc, char** argv )
41{
42 odebug << "OPIE Network Demo" << oendl;
43
44 ONetwork* net = ONetwork::instance();
45
46 ONetwork::InterfaceIterator it = net->iterator();
47
48 while ( it.current() )
49 {
50 odebug << "DEMO: ONetwork contains Interface '" << it.current()->name() << "'" << oendl;
51 odebug << "DEMO: Datalink code is '" << it.current()->dataLinkType() << "'" << oendl;
52 odebug << "DEMO: MAC Address is '" << it.current()->macAddress().toString() << "'" << oendl;
53 odebug << "DEMO: MAC Address is '" << it.current()->macAddress().toString(true) << "'" << oendl;
54 odebug << "DEMO: MAC Manufacturer seems to be '" << it.current()->macAddress().manufacturer() << "'" << oendl;
55 odebug << "DEMO: Manufacturertest1 = '" << OManufacturerDB::instance()->lookupExt( "08:00:87" ) << "'" << oendl;
56 odebug << "DEMO: Manufacturertest2 = '" << OManufacturerDB::instance()->lookupExt( "E2:0C:0F" ) << "'" << oendl;
57 odebug << "Demo: IPv4 Address is '" << it.current()->ipV4Address() << "'" << oendl;
58 if ( it.current()->isWireless() )
59 {
60 OWirelessNetworkInterface* iface = static_cast<OWirelessNetworkInterface*>( it.current() );
61 odebug << "DEMO: '" << iface->name() << "' seems to feature the wireless extensions." << oendl;
62 odebug << "DEMO: Current SSID is '" << iface->SSID() << "'" << oendl;
63 odebug << "DEMO: Antenna is tuned to '" << iface->frequency() << "', that is channel " << iface->channel() << "" << oendl;
64
65 //if ( iface->mode() == OWirelessNetworkInterface::adhoc )
66 //{
67 //odebug << "DEMO: Associated AP has MAC Address '" << iface->associatedAP().toString() << "'" << oendl;
68 //}
69
70 /*
71
72 // nickname
73 odebug << "DEMO: Current NickName is '" << iface->nickName() << "'" << oendl;
74 iface->setNickName( "MyNickName" );
75 if ( iface->nickName() != "MyNickName" )
76 odebug << "DEMO: Warning! Can't change nickname" << oendl;
77 else
78 odebug << "DEMO: Nickname change successful." << oendl;
79
80 /*
81
82 // operation mode
83 odebug << "DEMO: Current OperationMode is '" << iface->mode() << "'" << oendl;
84 iface->setMode( "adhoc" );
85 if ( iface->mode() != "adhoc" )
86 odebug << "DEMO: Warning! Can't change operation mode" << oendl;
87 else
88 odebug << "DEMO: Operation Mode change successful." << oendl;
89
90 // RF channel
91 odebug << "DEMO: Current Channel is '" << iface->channel() << "'" << oendl;
92 iface->setChannel( 1 );
93 if ( iface->channel() != 1 )
94 odebug << "DEMO: Warning! Can't change RF channel" << oendl;
95 else
96 odebug << "DEMO: RF channel change successful." << oendl;
97
98 iface->setMode( "managed" );
99
100 */
101
102 /*
103
104 // network scan
105
106 OStationList* stations = iface->scanNetwork();
107 if ( stations )
108 {
109 odebug << "DEMO: # of stations around = " << stations->count() << "" << oendl;
110 OStation* station;
111 for ( station = stations->first(); station != 0; station = stations->next() )
112 {
113 odebug << "DEMO: station dump following..." << oendl;
114 station->dump();
115 }
116 }
117
118 else
119 {
120 odebug << "DEMO: Warning! Scan didn't work!" << oendl;
121 }
122
123 /*
124
125 // first some wrong calls to check if this is working
126 iface->setPrivate( "seppel", 10 );
127 iface->setPrivate( "monitor", 0 );
128
129 // now the real deal
130 iface->setPrivate( "monitor", 2, 2, 3 );
131
132 // trying to set hw address to 12:34:56:AB:CD:EF
133
134 /*
135
136 OMacAddress addr = OMacAddress::fromString( "12:34:56:AB:CD:EF" );
137 iface->setUp( false );
138 iface->setMacAddress( addr );
139 iface->setUp( true );
140 odebug << "DEMO: MAC Address now is '" << iface->macAddress().toString() << "'" << oendl;
141
142 */
143
144 // monitor test
145
146
147
148 odebug << "DEMO: current interface mode is '" << iface->mode() << "'" << oendl;
149 iface->setMode( "monitor" );
150 odebug << "DEMO: current interface mode is '" << iface->mode() << "'" << oendl;
151
152 sleep( 1 );
153
154 iface->setChannel( 1 );
155 iface->setMode( "managed" );
156
157 //sleep( 1 );
158 odebug << "DEMO: current interface mode is '" << iface->mode() << "'" << oendl;
159
160 /*iface->setMode( "adhoc" );
161 sleep( 1 );
162 odebug << "DEMO: current interface mode is '" << iface->mode() << "'" << oendl;
163 iface->setMode( "managed" );
164 sleep( 1 );
165 odebug << "DEMO: current interface mode is '" << iface->mode() << "'" << oendl;
166 iface->setMode( "master" );
167 sleep( 1 );
168 odebug << "DEMO: current interface mode is '" << iface->mode() << "'" << oendl; */
169
170 }
171 ++it;
172 }
173
174 return 0;
175
176}
diff --git a/examples/opienet/onetworkdemo/onetworkdemo.pro b/examples/opienet/onetworkdemo/onetworkdemo.pro
new file mode 100644
index 0000000..cf293b5
--- a/dev/null
+++ b/examples/opienet/onetworkdemo/onetworkdemo.pro
@@ -0,0 +1,12 @@
1TEMPLATE = app
2CONFIG = qt warn_on
3HEADERS =
4SOURCES = onetworkdemo.cpp
5INCLUDEPATH += $(OPIEDIR)/include
6DEPENDPATH += $(OPIEDIR)/include
7LIBS += -lopiecore2 -lopienet2
8TARGET = onetworkdemo
9MOC_DIR = moc
10OBJECTS_DIR = obj
11
12include( $(OPIEDIR)/include.pro )
diff --git a/examples/opienet/opienet.pro b/examples/opienet/opienet.pro
new file mode 100644
index 0000000..c7800a9
--- a/dev/null
+++ b/examples/opienet/opienet.pro
@@ -0,0 +1,3 @@
1TEMPLATE = subdirs
2SUBDIRS = miniwellenreiter onetworkdemo
3