Diffstat (limited to 'noncore/net/wellenreiter/gui/wellenreiter.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/wellenreiter/gui/wellenreiter.cpp | 228 |
1 files changed, 87 insertions, 141 deletions
diff --git a/noncore/net/wellenreiter/gui/wellenreiter.cpp b/noncore/net/wellenreiter/gui/wellenreiter.cpp index 09a44e6..5bdc1b3 100644 --- a/noncore/net/wellenreiter/gui/wellenreiter.cpp +++ b/noncore/net/wellenreiter/gui/wellenreiter.cpp | |||
@@ -22,11 +22,4 @@ | |||
22 | #include <qsocketnotifier.h> | 22 | #include <qsocketnotifier.h> |
23 | 23 | ||
24 | // Qtopia | ||
25 | |||
26 | #ifdef QWS | ||
27 | #include <qpe/qpeapplication.h> | ||
28 | #include <qpe/global.h> | ||
29 | #endif | ||
30 | |||
31 | // Opie | 24 | // Opie |
32 | 25 | ||
@@ -36,4 +29,8 @@ using namespace Opie; | |||
36 | #endif | 29 | #endif |
37 | 30 | ||
31 | #include <opie2/oapplication.h> | ||
32 | #include <opie2/onetwork.h> | ||
33 | #include <opie2/opcap.h> | ||
34 | |||
38 | // Standard | 35 | // Standard |
39 | 36 | ||
@@ -43,7 +40,5 @@ using namespace Opie; | |||
43 | #include <string.h> | 40 | #include <string.h> |
44 | #include <sys/types.h> | 41 | #include <sys/types.h> |
45 | #include <sys/socket.h> | ||
46 | #include <stdlib.h> | 42 | #include <stdlib.h> |
47 | #include <fcntl.h> | ||
48 | 43 | ||
49 | // Local | 44 | // Local |
@@ -57,12 +52,7 @@ using namespace Opie; | |||
57 | #include "manufacturers.h" | 52 | #include "manufacturers.h" |
58 | 53 | ||
59 | #include <daemon/source/config.hh> | ||
60 | #include <libwellenreiter/source/wl_types.hh> | ||
61 | #include <libwellenreiter/source/wl_sock.hh> | ||
62 | #include <libwellenreiter/source/wl_proto.hh> | ||
63 | |||
64 | Wellenreiter::Wellenreiter( QWidget* parent ) | 54 | Wellenreiter::Wellenreiter( QWidget* parent ) |
65 | : WellenreiterBase( parent, 0, 0 ), | 55 | : WellenreiterBase( parent, 0, 0 ), |
66 | daemonRunning( false ), manufacturerdb( 0 ), configwindow( 0 ) | 56 | sniffing( false ), iface( 0 ), manufacturerdb( 0 ), configwindow( 0 ) |
67 | { | 57 | { |
68 | 58 | ||
@@ -92,23 +82,4 @@ Wellenreiter::Wellenreiter( QWidget* parent ) | |||
92 | #endif | 82 | #endif |
93 | 83 | ||
94 | // | ||
95 | // setup socket for daemon communication, register socket notifier | ||
96 | // | ||
97 | |||
98 | // struct sockaddr_in sockaddr; | ||
99 | daemon_fd = wl_setupsock( GUIADDR, GUIPORT, sockaddr ); | ||
100 | if ( daemon_fd == -1 ) | ||
101 | { | ||
102 | logwindow->log( "(E) Couldn't get file descriptor for commsocket." ); | ||
103 | } | ||
104 | else | ||
105 | { | ||
106 | int flags; | ||
107 | flags = fcntl( daemon_fd, F_GETFL, 0 ); | ||
108 | fcntl( daemon_fd, F_SETFL, flags | O_NONBLOCK ); | ||
109 | QSocketNotifier *sn = new QSocketNotifier( daemon_fd, QSocketNotifier::Read, this ); | ||
110 | connect( sn, SIGNAL( activated( int ) ), this, SLOT( dataReceived() ) ); | ||
111 | } | ||
112 | |||
113 | // setup GUI | 84 | // setup GUI |
114 | netview->setColumnWidthMode( 1, QListView::Manual ); | 85 | netview->setColumnWidthMode( 1, QListView::Manual ); |
@@ -117,4 +88,6 @@ Wellenreiter::Wellenreiter( QWidget* parent ) | |||
117 | netview->setManufacturerDB( manufacturerdb ); | 88 | netview->setManufacturerDB( manufacturerdb ); |
118 | 89 | ||
90 | pcap = new OPacketCapturer(); | ||
91 | |||
119 | } | 92 | } |
120 | 93 | ||
@@ -124,12 +97,5 @@ Wellenreiter::~Wellenreiter() | |||
124 | 97 | ||
125 | delete manufacturerdb; | 98 | delete manufacturerdb; |
126 | 99 | delete pcap; | |
127 | if ( daemon_fd != -1 ) | ||
128 | { | ||
129 | qDebug( "closing comm socket" ); | ||
130 | ::shutdown( daemon_fd, 0 ); | ||
131 | ::close( daemon_fd ); | ||
132 | qDebug( "comm socket closed." ); | ||
133 | } | ||
134 | } | 100 | } |
135 | 101 | ||
@@ -139,119 +105,72 @@ void Wellenreiter::setConfigWindow( WellenreiterConfigWindow* cw ) | |||
139 | } | 105 | } |
140 | 106 | ||
141 | void Wellenreiter::handleMessage() | 107 | void Wellenreiter::receivePacket(OPacket* p) |
142 | { | 108 | { |
143 | // FIXME: receive message and handle it | 109 | logwindow->log( "(d) Received data from daemon" ); |
144 | 110 | //TODO | |
145 | qDebug( "received message from daemon." ); | ||
146 | |||
147 | /*char buffer[10000]; | ||
148 | memset( &buffer, 0, sizeof( buffer ) );*/ | ||
149 | |||
150 | char buffer[WL_SOCKBUF]; | ||
151 | |||
152 | // int result = #wl_recv( &daemon_fd, (char*) &buffer, sizeof(buffer) ); | ||
153 | |||
154 | /* | ||
155 | |||
156 | struct sockaddr from; | ||
157 | socklen_t len; | ||
158 | |||
159 | int result = recvfrom( daemon_fd, &buffer, 8192, MSG_WAITALL, &from, &len ); | ||
160 | qDebug( "received %d from recv [%d bytes]", result, len ); | ||
161 | |||
162 | */ | ||
163 | |||
164 | int result = wl_recv( &daemon_fd, sockaddr, (char*) &buffer, WL_SOCKBUF ); | ||
165 | |||
166 | if ( result == -1 ) | ||
167 | { | ||
168 | qDebug( "Warning: %s", strerror( errno ) ); | ||
169 | return; | ||
170 | } | ||
171 | |||
172 | int command = buffer[1] - 48; | ||
173 | |||
174 | /* | ||
175 | typedef struct { | ||
176 | int net_type; 1 = Accesspoint ; 2 = Ad-Hoc | ||
177 | int ssid_len; Length of SSID | ||
178 | int channel; Channel | ||
179 | int wep; 1 = WEP enabled ; 0 = disabled | ||
180 | char mac[64]; MAC address of Accesspoint | ||
181 | char bssid[128]; BSSID of Accesspoint | ||
182 | } wl_network_t; | ||
183 | */ | ||
184 | |||
185 | qDebug( "Recv result: %d", ( result ) ); | ||
186 | qDebug( "Sniffer sent: '%s'", (const char*) buffer ); | ||
187 | hexwindow->log( (const char*) &buffer ); | ||
188 | |||
189 | if ( command == NETFOUND ) /* new network found */ | ||
190 | { | ||
191 | qDebug( "Sniffer said: new network found." ); | ||
192 | wl_network_t n; | ||
193 | get_network_found( &n, (char*) &buffer ); | ||
194 | |||
195 | qDebug( "Sniffer said: net_type is %d.", n.net_type ); | ||
196 | qDebug( "Sniffer said: MAC is %s", (const char*) &n.mac ); | ||
197 | |||
198 | //n.bssid[n.ssid_len] = "\0"; | ||
199 | |||
200 | QString type; | ||
201 | |||
202 | if ( n.net_type == 1 ) | ||
203 | type = "managed"; | ||
204 | else | ||
205 | type = "adhoc"; | ||
206 | 111 | ||
207 | netview->addNewItem( type, n.bssid, QString( (const char*) &n.mac ), n.wep, n.channel, 0 ); | 112 | // check if we received a beacon frame |
113 | // static_cast is justified here | ||
114 | OWaveLanManagementPacket* beacon = static_cast<OWaveLanManagementPacket*>( p->child( "802.11 Management" ) ); | ||
115 | if ( !beacon ) return; | ||
116 | QString type; | ||
208 | 117 | ||
209 | } | 118 | //FIXME: Can stations in ESS mode can be distinguished from APs? |
119 | //FIXME: Apparently yes, but not by listening to beacons, because | ||
120 | //FIXME: they simply don't send beacons in infrastructure mode. | ||
121 | //FIXME: so we also have to listen to data packets | ||
210 | 122 | ||
123 | if ( beacon->canIBSS() ) | ||
124 | type = "adhoc"; | ||
211 | else | 125 | else |
126 | type = "managed"; | ||
212 | 127 | ||
213 | { | 128 | OWaveLanManagementSSID* ssid = static_cast<OWaveLanManagementSSID*>( p->child( "802.11 SSID" ) ); |
214 | qDebug( "unknown sniffer command." ); | 129 | QString essid = ssid ? ssid->ID() : "<unknown>"; |
215 | } | 130 | OWaveLanManagementDS* ds = static_cast<OWaveLanManagementDS*>( p->child( "802.11 DS" ) ); |
131 | int channel = ds ? ds->channel() : -1; | ||
216 | 132 | ||
217 | } | 133 | OWaveLanPacket* header = static_cast<OWaveLanPacket*>( p->child( "802.11" ) ); |
218 | 134 | netView()->addNewItem( type, essid, header->macAddress2().toString(), header->usesWep(), channel, 0 ); | |
219 | void Wellenreiter::dataReceived() | ||
220 | { | ||
221 | logwindow->log( "(d) Received data from daemon" ); | ||
222 | handleMessage(); | ||
223 | } | 135 | } |
224 | 136 | ||
225 | void Wellenreiter::startStopClicked() | 137 | void Wellenreiter::startStopClicked() |
226 | { | 138 | { |
227 | if ( daemonRunning ) | 139 | if ( sniffing ) |
228 | { | 140 | { |
229 | daemonRunning = false; | 141 | disconnect( SIGNAL( receivedPacket(OPacket*) ), this, SLOT( receivePacket(OPacket*) ) ); |
230 | 142 | ||
231 | logwindow->log( "(i) Daemon has been stopped." ); | 143 | iface->setChannelHopping(); // stop hopping channels |
232 | setCaption( tr( "Wellenreiter/Opie" ) ); | 144 | pcap->close(); |
145 | sniffing = false; | ||
146 | oApp->setTitle(); | ||
233 | 147 | ||
234 | // Stop daemon - ugly for now... later better | 148 | // get interface name from config window |
149 | const QString& interface = configwindow->interfaceName->currentText(); | ||
150 | ONetwork* net = ONetwork::instance(); | ||
151 | iface = static_cast<OWirelessNetworkInterface*>(net->interface( interface )); | ||
235 | 152 | ||
236 | system( "killall wellenreiterd" ); | 153 | // switch off monitor mode |
154 | iface->setMonitorMode( false ); | ||
155 | // switch off promisc flag | ||
156 | iface->setPromiscuousMode( false ); | ||
237 | 157 | ||
238 | // get configuration from config window | 158 | //TODO: Display "please wait..." (use owait?) |
239 | 159 | ||
240 | const QString& interface = configwindow->interfaceName->currentText(); | 160 | /* |
241 | |||
242 | // reset the interface trying to get it into a usable state again | ||
243 | 161 | ||
244 | QString cmdline; | 162 | QString cmdline; |
245 | cmdline.sprintf( "iwpriv %s monitor 0; ifdown %s; ifup %s", (const char*) interface, (const char*) interface, (const char*) interface ); | 163 | cmdline.sprintf( "ifdown %s; sleep 1; ifup %s", (const char*) interface, (const char*) interface, (const char*) interface ); |
246 | system( cmdline ); | 164 | system( cmdline ); //FIXME: Use OProcess |
165 | |||
166 | */ | ||
247 | 167 | ||
248 | // message the user | 168 | // message the user |
249 | 169 | ||
250 | QMessageBox::information( this, "Wellenreiter/Opie", "Your wireless card\nshould now be usable again." ); | 170 | //QMessageBox::information( this, "Wellenreiter II", "Your wireless card\nshould now be usable again." ); |
251 | } | 171 | } |
252 | 172 | ||
253 | else | 173 | else |
254 | { | 174 | { |
255 | |||
256 | // get configuration from config window | 175 | // get configuration from config window |
257 | 176 | ||
@@ -260,22 +179,49 @@ void Wellenreiter::startStopClicked() | |||
260 | const int interval = configwindow->daemonHopInterval(); | 179 | const int interval = configwindow->daemonHopInterval(); |
261 | 180 | ||
262 | if ( ( interface == "<select>" ) || ( cardtype == 0 ) ) | 181 | if ( ( interface == "" ) || ( cardtype == 0 ) ) |
263 | { | 182 | { |
264 | QMessageBox::information( this, "Wellenreiter/Opie", "Your device is not\nptoperly configured. Please reconfigure!" ); | 183 | QMessageBox::information( this, "Wellenreiter II", "Your device is not\nproperly configured. Please reconfigure!" ); |
265 | return; | 184 | return; |
266 | } | 185 | } |
267 | 186 | ||
268 | // start wellenreiterd | 187 | // configure device |
269 | 188 | ||
270 | QString cmdline; | 189 | ONetwork* net = ONetwork::instance(); |
271 | cmdline.sprintf( "wellenreiterd %s %d &", (const char*) interface, cardtype ); | 190 | iface = static_cast<OWirelessNetworkInterface*>(net->interface( interface )); |
191 | |||
192 | // set monitor mode | ||
193 | |||
194 | switch ( cardtype ) | ||
195 | { | ||
196 | case 1: iface->setMonitoring( new OCiscoMonitoringInterface( iface ) ); break; | ||
197 | case 2: iface->setMonitoring( new OWlanNGMonitoringInterface( iface ) ); break; | ||
198 | case 3: iface->setMonitoring( new OHostAPMonitoringInterface( iface ) ); break; | ||
199 | case 4: iface->setMonitoring( new OOrinocoMonitoringInterface( iface ) ); break; | ||
200 | default: assert( 0 ); // shouldn't happen | ||
201 | } | ||
202 | |||
203 | iface->setMonitorMode( true ); | ||
204 | |||
205 | // open pcap and start sniffing | ||
206 | pcap->open( interface ); | ||
207 | |||
208 | if ( !pcap->isOpen() ) | ||
209 | { | ||
210 | QMessageBox::warning( this, "Wellenreiter II", "Can't open packet capturer:\n" + QString(strerror( errno ) )); | ||
211 | return; | ||
212 | } | ||
213 | |||
214 | // set capturer to non-blocking mode | ||
215 | pcap->setBlocking( false ); | ||
216 | |||
217 | // start channel hopper | ||
218 | iface->setChannelHopping( 1000 ); //use interval from config window | ||
272 | 219 | ||
273 | qDebug( "about to execute '%s' ...", (const char*) cmdline ); | 220 | // connect |
274 | system( cmdline ); | 221 | connect( pcap, SIGNAL( receivedPacket(OPacket*) ), this, SLOT( receivePacket(OPacket*) ) ); |
275 | qDebug( "done!" ); | ||
276 | 222 | ||
277 | logwindow->log( "(i) Daemon has been started." ); | 223 | logwindow->log( "(i) Daemon has been started." ); |
278 | daemonRunning = true; | 224 | oApp->setTitle( "Scanning ..." ); |
279 | setCaption( tr( "Scanning ..." ) ); | 225 | sniffing = true; |
280 | 226 | ||
281 | } | 227 | } |