-rw-r--r-- | examples/opienet/miniwellenreiter/miniwellenreiter.cpp | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/examples/opienet/miniwellenreiter/miniwellenreiter.cpp b/examples/opienet/miniwellenreiter/miniwellenreiter.cpp index ba9d2ca..284b35a 100644 --- a/examples/opienet/miniwellenreiter/miniwellenreiter.cpp +++ b/examples/opienet/miniwellenreiter/miniwellenreiter.cpp | |||
@@ -1,222 +1,223 @@ | |||
1 | #include <qdict.h> | 1 | #include <qdict.h> |
2 | #include <qsocketnotifier.h> | 2 | #include <qsocketnotifier.h> |
3 | #include <qstring.h> | 3 | #include <qstring.h> |
4 | #include <opie2/onetwork.h> | 4 | #include <opie2/onetwork.h> |
5 | #include <qapplication.h> | 5 | #include <qapplication.h> |
6 | #include <opie2/opcap.h> | 6 | #include <opie2/opcap.h> |
7 | #include <cerrno> | 7 | #include <cerrno> |
8 | #include <cstdio> | 8 | #include <cstdio> |
9 | #include <cstdlib> | 9 | #include <cstdlib> |
10 | #include <cstring> | 10 | #include <cstring> |
11 | 11 | ||
12 | 12 | ||
13 | using namespace Opie::Net; | 13 | using namespace Opie::Net; |
14 | //======================== Station help class =============================== | 14 | //======================== Station help class =============================== |
15 | 15 | ||
16 | class Station | 16 | class Station |
17 | { | 17 | { |
18 | public: | 18 | public: |
19 | Station( QString t, int c, bool w ) : type(t), channel(c), wep(w), beacons(1) {}; | 19 | Station( QString t, int c, bool w ) : type(t), channel(c), wep(w), beacons(1) {}; |
20 | ~Station() {}; | 20 | ~Station() {}; |
21 | 21 | ||
22 | QString type; | 22 | QString type; |
23 | int channel; | 23 | int channel; |
24 | bool wep; | 24 | bool wep; |
25 | int beacons; | 25 | int beacons; |
26 | }; | 26 | }; |
27 | 27 | ||
28 | QDict<Station> stations; | 28 | QDict<Station> stations; |
29 | 29 | ||
30 | //======================== Application class =============================== | 30 | //======================== Application class =============================== |
31 | 31 | ||
32 | class Wellenreiter : public QApplication | 32 | class Wellenreiter : public QApplication |
33 | { | 33 | { |
34 | Q_OBJECT | 34 | Q_OBJECT |
35 | public: | 35 | public: |
36 | Wellenreiter( int argc, char** argv ) : QApplication( argc, argv ), channel( 1 ) | 36 | Wellenreiter( int argc, char** argv ) : QApplication( argc, argv ), channel( 1 ) |
37 | { | 37 | { |
38 | 38 | ||
39 | ONetwork* net = ONetwork::instance(); | 39 | ONetwork* net = ONetwork::instance(); |
40 | 40 | ||
41 | if ( argc < 3 ) | 41 | if ( argc < 3 ) |
42 | { | 42 | { |
43 | printf( "Usage: ./%s <interface> <driver> <interval>\n", argv[0] ); | 43 | printf( "Usage: ./%s <interface> <driver> <interval>\n", argv[0] ); |
44 | printf( "\n" ); | 44 | printf( "\n" ); |
45 | printf( "Valid wireless interfaces (detected) are:\n" ); | 45 | printf( "Valid wireless interfaces (detected) are:\n" ); |
46 | 46 | ||
47 | ONetwork::InterfaceIterator it = net->iterator(); | 47 | ONetwork::InterfaceIterator it = net->iterator(); |
48 | while ( it.current() ) | 48 | while ( it.current() ) |
49 | { | 49 | { |
50 | if ( it.current()->isWireless() ) | 50 | if ( it.current()->isWireless() ) |
51 | { | 51 | { |
52 | printf( " - '%s' (MAC=%s) (IPv4=%s)\n", (const char*) it.current()->name(), | 52 | printf( " - '%s' (MAC=%s) (IPv4=%s)\n", (const char*) it.current()->name(), |
53 | (const char*) it.current()->macAddress().toString(), | 53 | (const char*) it.current()->macAddress().toString(), |
54 | (const char*) it.current()->ipV4Address().toString() ); | 54 | (const char*) it.current()->ipV4Address().toString() ); |
55 | } | 55 | } |
56 | ++it; | 56 | ++it; |
57 | } | 57 | } |
58 | exit( -1 ); | 58 | exit( -1 ); |
59 | } | 59 | } |
60 | 60 | ||
61 | printf( "*******************************************************************\n" ); | 61 | printf( "************************************************************************\n" ); |
62 | printf( "* Wellenreiter mini edition 1.0.0 (C) 2003 Michael 'Mickey' Lauer *\n" ); | 62 | printf( "* Wellenreiter mini edition 1.0.0 (C) 2003-2005 Michael 'Mickey' Lauer *\n" ); |
63 | printf( "*******************************************************************\n" ); | 63 | printf( "************************************************************************\n" ); |
64 | printf( "\n\n" ); | 64 | printf( "\n\n" ); |
65 | 65 | ||
66 | QString interface( argv[1] ); | 66 | QString interface( argv[1] ); |
67 | QString driver( argv[2] ); | 67 | QString driver( argv[2] ); |
68 | 68 | ||
69 | printf( "Trying to use '%s' as %s-controlled device...\n", (const char*) interface, (const char*) driver ); | 69 | printf( "Trying to use '%s' as %s-controlled device...\n", (const char*) interface, (const char*) driver ); |
70 | 70 | ||
71 | // sanity checks before downcasting | 71 | // sanity checks before downcasting |
72 | ONetworkInterface* iface = net->interface( interface ); | 72 | ONetworkInterface* iface = net->interface( interface ); |
73 | if ( !iface ) | 73 | if ( !iface ) |
74 | { | 74 | { |
75 | printf( "Interface '%s' doesn't exist. Exiting.\n", (const char*) interface ); | 75 | printf( "Interface '%s' doesn't exist. Exiting.\n", (const char*) interface ); |
76 | exit( -1 ); | 76 | exit( -1 ); |
77 | } | 77 | } |
78 | if ( !iface->isWireless() ) | 78 | if ( !iface->isWireless() ) |
79 | { | 79 | { |
80 | printf( "Interface '%s' doesn't support wireless extensions. Exiting.\n", (const char*) interface ); | 80 | printf( "Interface '%s' doesn't support wireless extensions. Exiting.\n", (const char*) interface ); |
81 | exit( -1 ); | 81 | exit( -1 ); |
82 | } | 82 | } |
83 | 83 | ||
84 | // downcast should be safe now | 84 | // downcast should be safe now |
85 | wiface = (OWirelessNetworkInterface*) iface; | 85 | wiface = (OWirelessNetworkInterface*) iface; |
86 | printf( "Using wireless interface '%s' for scanning (current SSID is '%s')...\n", (const char*) interface, (const char*) wiface->SSID() ); | 86 | printf( "Using wireless interface '%s' for scanning (current SSID is '%s')...\n", (const char*) interface, (const char*) wiface->SSID() ); |
87 | 87 | ||
88 | // ifconfig +promisc the interface to receive all packets | 88 | // ifconfig +promisc the interface to receive all packets |
89 | if ( !wiface->promiscuousMode() ) | 89 | if ( !wiface->promiscuousMode() ) |
90 | { | 90 | { |
91 | printf( "Interface status is not promisc... switching to promisc... " ); | 91 | printf( "Interface status is not promisc... switching to promisc... " ); |
92 | wiface->setPromiscuousMode( true ); | 92 | wiface->setPromiscuousMode( true ); |
93 | if ( !wiface->promiscuousMode() ) | 93 | if ( !wiface->promiscuousMode() ) |
94 | { | 94 | { |
95 | printf( "failed (%s). Exiting.\n", strerror( errno ) ); | 95 | printf( "failed (%s). Exiting.\n", strerror( errno ) ); |
96 | exit( -1 ); | 96 | exit( -1 ); |
97 | } | 97 | } |
98 | else | 98 | else |
99 | { | 99 | { |
100 | printf( "ok.\n" ); | 100 | printf( "ok.\n" ); |
101 | } | 101 | } |
102 | } | 102 | } |
103 | else | 103 | else |
104 | printf( "Interface status is already promisc - good.\n" ); | 104 | printf( "Interface status is already promisc - good.\n" ); |
105 | 105 | ||
106 | // connect a monitoring strategy to the interface | 106 | // connect a monitoring strategy to the interface |
107 | if ( driver == "orinoco" ) | 107 | if ( driver == "orinoco" ) |
108 | new OOrinocoMonitoringInterface( wiface, false ); | 108 | new OOrinocoMonitoringInterface( wiface, false ); |
109 | else | 109 | else |
110 | if ( driver == "hostap" ) | 110 | if ( driver == "hostap" ) |
111 | new OHostAPMonitoringInterface( wiface, false ); | 111 | new OHostAPMonitoringInterface( wiface, false ); |
112 | else | 112 | else |
113 | if ( driver == "wlan-ng" ) | 113 | if ( driver == "wlan-ng" ) |
114 | new OWlanNGMonitoringInterface( wiface, false ); | 114 | new OWlanNGMonitoringInterface( wiface, false ); |
115 | else | 115 | else |
116 | { | 116 | { |
117 | printf( "Unknown driver. Exiting\n" ); | 117 | printf( "Unknown driver. Exiting\n" ); |
118 | exit( -1 ); | 118 | exit( -1 ); |
119 | } | 119 | } |
120 | 120 | ||
121 | // enable monitoring mode | 121 | // enable monitoring mode |
122 | printf( "Enabling monitor mode...\n" ); | 122 | printf( "Enabling monitor mode...\n" ); |
123 | wiface->setMode( "monitor" ); | 123 | wiface->setMode( "monitor" ); |
124 | 124 | ||
125 | // open a packet capturer | 125 | // open a packet capturer |
126 | cap = new OPacketCapturer(); | 126 | cap = new OPacketCapturer(); |
127 | printf( "OPacketCapturer using libpcap %s", (const char*) cap->version() ); | ||
127 | cap->open( interface ); | 128 | cap->open( interface ); |
128 | if ( !cap->isOpen() ) | 129 | if ( !cap->isOpen() ) |
129 | { | 130 | { |
130 | printf( "Unable to open libpcap (%s). Exiting.\n", strerror( errno ) ); | 131 | printf( "Unable to open libpcap (%s). Exiting.\n", strerror( errno ) ); |
131 | exit( -1 ); | 132 | exit( -1 ); |
132 | } | 133 | } |
133 | 134 | ||
134 | // set capturer to non-blocking mode | 135 | // set capturer to non-blocking mode |
135 | cap->setBlocking( false ); | 136 | cap->setBlocking( false ); |
136 | 137 | ||
137 | // start channel hopper | 138 | // start channel hopper |
138 | //wiface->setChannelHopping( 1000 ); | 139 | //wiface->setChannelHopping( 1000 ); |
139 | 140 | ||
140 | // connect | 141 | // connect |
141 | connect( cap, SIGNAL( receivedPacket(OPacket*) ), this, SLOT( receivePacket(OPacket*) ) ); | 142 | connect( cap, SIGNAL( receivedPacket(OPacket*) ), this, SLOT( receivePacket(OPacket*) ) ); |
142 | // timer | 143 | // timer |
143 | startTimer( 1000 ); | 144 | startTimer( 1000 ); |
144 | 145 | ||
145 | } | 146 | } |
146 | 147 | ||
147 | ~Wellenreiter() {}; | 148 | ~Wellenreiter() {}; |
148 | 149 | ||
149 | public slots: | 150 | public slots: |
150 | virtual void timerEvent(QTimerEvent* e) | 151 | virtual void timerEvent(QTimerEvent* e) |
151 | { | 152 | { |
152 | wiface->setChannel( channel++ ); | 153 | wiface->setChannel( channel++ ); |
153 | if ( channel == 14 ) channel = 1; | 154 | if ( channel == 14 ) channel = 1; |
154 | } | 155 | } |
155 | 156 | ||
156 | void receivePacket(OPacket* p) | 157 | void receivePacket(OPacket* p) |
157 | { | 158 | { |
158 | if (!p) | 159 | if (!p) |
159 | { | 160 | { |
160 | printf( "(empty packet received)\n" ); | 161 | printf( "(empty packet received)\n" ); |
161 | return; | 162 | return; |
162 | } | 163 | } |
163 | 164 | ||
164 | OWaveLanManagementPacket* beacon = (OWaveLanManagementPacket*) p->child( "802.11 Management" ); | 165 | OWaveLanManagementPacket* beacon = (OWaveLanManagementPacket*) p->child( "802.11 Management" ); |
165 | if ( beacon ) | 166 | if ( beacon ) |
166 | { | 167 | { |
167 | OWaveLanManagementSSID* ssid = static_cast<OWaveLanManagementSSID*>( p->child( "802.11 SSID" ) ); | 168 | OWaveLanManagementSSID* ssid = static_cast<OWaveLanManagementSSID*>( p->child( "802.11 SSID" ) ); |
168 | QString essid = ssid ? ssid->ID() : QString::fromLatin1( "<unknown>" ); | 169 | QString essid = ssid ? ssid->ID() : QString::fromLatin1( "<unknown>" ); |
169 | 170 | ||
170 | if ( stations.find( essid ) ) | 171 | if ( stations.find( essid ) ) |
171 | stations[essid]->beacons++; | 172 | stations[essid]->beacons++; |
172 | else | 173 | else |
173 | { | 174 | { |
174 | printf( "found new network @ channel %d, SSID = '%s'\n", wiface->channel(), (const char*) essid ); | 175 | printf( "found new network @ channel %d, SSID = '%s'\n", wiface->channel(), (const char*) essid ); |
175 | stations.insert( essid, new Station( "unknown", wiface->channel(), | 176 | stations.insert( essid, new Station( "unknown", wiface->channel(), |
176 | ((OWaveLanPacket*) beacon->parent())->usesWep() ) ); | 177 | ((OWaveLanPacket*) beacon->parent())->usesWep() ) ); |
177 | } | 178 | } |
178 | return; | 179 | return; |
179 | } | 180 | } |
180 | 181 | ||
181 | OWaveLanDataPacket* data = (OWaveLanDataPacket*) p->child( "802.11 Data" ); | 182 | OWaveLanDataPacket* data = (OWaveLanDataPacket*) p->child( "802.11 Data" ); |
182 | if ( data ) | 183 | if ( data ) |
183 | { | 184 | { |
184 | OWaveLanPacket* wlan = (OWaveLanPacket*) p->child( "802.11" ); | 185 | OWaveLanPacket* wlan = (OWaveLanPacket*) p->child( "802.11" ); |
185 | if ( wlan->fromDS() && !wlan->toDS() ) | 186 | if ( wlan->fromDS() && !wlan->toDS() ) |
186 | { | 187 | { |
187 | printf( "FromDS: '%s' -> '%s' via '%s'\n", | 188 | printf( "FromDS: '%s' -> '%s' via '%s'\n", |
188 | (const char*) wlan->macAddress3().toString(true), | 189 | (const char*) wlan->macAddress3().toString(true), |
189 | (const char*) wlan->macAddress1().toString(true), | 190 | (const char*) wlan->macAddress1().toString(true), |
190 | (const char*) wlan->macAddress2().toString(true) ); | 191 | (const char*) wlan->macAddress2().toString(true) ); |
191 | } | 192 | } |
192 | else | 193 | else |
193 | if ( !wlan->fromDS() && wlan->toDS() ) | 194 | if ( !wlan->fromDS() && wlan->toDS() ) |
194 | { | 195 | { |
195 | printf( "ToDS: '%s' -> '%s' via '%s'\n", | 196 | printf( "ToDS: '%s' -> '%s' via '%s'\n", |
196 | (const char*) wlan->macAddress2().toString(true), | 197 | (const char*) wlan->macAddress2().toString(true), |
197 | (const char*) wlan->macAddress3().toString(true), | 198 | (const char*) wlan->macAddress3().toString(true), |
198 | (const char*) wlan->macAddress1().toString(true) ); | 199 | (const char*) wlan->macAddress1().toString(true) ); |
199 | } | 200 | } |
200 | else | 201 | else |
201 | if ( wlan->fromDS() && wlan->toDS() ) | 202 | if ( wlan->fromDS() && wlan->toDS() ) |
202 | { | 203 | { |
203 | printf( "WSD(bridge): '%s' -> '%s' via '%s' and '%s'\n", | 204 | printf( "WSD(bridge): '%s' -> '%s' via '%s' and '%s'\n", |
204 | (const char*) wlan->macAddress4().toString(true), | 205 | (const char*) wlan->macAddress4().toString(true), |
205 | (const char*) wlan->macAddress3().toString(true), | 206 | (const char*) wlan->macAddress3().toString(true), |
206 | (const char*) wlan->macAddress1().toString(true), | 207 | (const char*) wlan->macAddress1().toString(true), |
207 | (const char*) wlan->macAddress2().toString(true) ); | 208 | (const char*) wlan->macAddress2().toString(true) ); |
208 | } | 209 | } |
209 | else | 210 | else |
210 | { | 211 | { |
211 | printf( "IBSS(AdHoc): '%s' -> '%s' (Cell: '%s')'\n", | 212 | printf( "IBSS(AdHoc): '%s' -> '%s' (Cell: '%s')'\n", |
212 | (const char*) wlan->macAddress2().toString(true), | 213 | (const char*) wlan->macAddress2().toString(true), |
213 | (const char*) wlan->macAddress1().toString(true), | 214 | (const char*) wlan->macAddress1().toString(true), |
214 | (const char*) wlan->macAddress3().toString(true) ); | 215 | (const char*) wlan->macAddress3().toString(true) ); |
215 | } | 216 | } |
216 | return; | 217 | return; |
217 | } | 218 | } |
218 | } | 219 | } |
219 | private: | 220 | private: |
220 | OPacketCapturer* cap; | 221 | OPacketCapturer* cap; |
221 | OWirelessNetworkInterface* wiface; | 222 | OWirelessNetworkInterface* wiface; |
222 | int channel; | 223 | int channel; |