summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2002-12-18 00:00:51 (UTC)
committer mickeyl <mickeyl>2002-12-18 00:00:51 (UTC)
commit930884a92b064766ed436111778fc55f157c6e1c (patch) (unidiff)
treed3c4b56b4b50f7cf7ef52cc486b377f39aaab044
parent96a9654c2fccce382a4a9ad5d2d0b991b4191468 (diff)
downloadopie-930884a92b064766ed436111778fc55f157c6e1c.zip
opie-930884a92b064766ed436111778fc55f157c6e1c.tar.gz
opie-930884a92b064766ed436111778fc55f157c6e1c.tar.bz2
use system() to start daemon and hopper instead of Global::execute,
which makes nothing but trouble for non-gui processes.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/wellenreiter/gui/wellenreiter.cpp36
1 files changed, 23 insertions, 13 deletions
diff --git a/noncore/net/wellenreiter/gui/wellenreiter.cpp b/noncore/net/wellenreiter/gui/wellenreiter.cpp
index 764ef34..0e95b28 100644
--- a/noncore/net/wellenreiter/gui/wellenreiter.cpp
+++ b/noncore/net/wellenreiter/gui/wellenreiter.cpp
@@ -1,325 +1,335 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2002 Michael 'Mickey' Lauer. All rights reserved. 2** Copyright (C) 2002 Michael 'Mickey' Lauer. All rights reserved.
3** 3**
4** This file is part of Opie Environment. 4** This file is part of Opie Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14***********************************************************************/ 14***********************************************************************/
15 15
16// Qt 16// Qt
17 17
18#include <qpushbutton.h> 18#include <qpushbutton.h>
19#include <qmessagebox.h> 19#include <qmessagebox.h>
20#include <qcombobox.h> 20#include <qcombobox.h>
21#include <qspinbox.h> 21#include <qspinbox.h>
22 22
23// Qtopia 23// Qtopia
24 24
25#ifdef QWS 25#ifdef QWS
26#include <qpe/global.h> 26#include <qpe/global.h>
27#endif 27#endif
28 28
29// Standard 29// Standard
30 30
31#include <assert.h> 31#include <assert.h>
32#include <errno.h> 32#include <errno.h>
33#include <unistd.h> 33#include <unistd.h>
34#include <string.h> 34#include <string.h>
35#include <sys/types.h> 35#include <sys/types.h>
36#include <stdlib.h> 36#include <stdlib.h>
37 37
38// Local 38// Local
39 39
40#include "wellenreiter.h" 40#include "wellenreiter.h"
41#include "scanlistitem.h" 41#include "scanlistitem.h"
42#include "logwindow.h" 42#include "logwindow.h"
43#include "hexwindow.h" 43#include "hexwindow.h"
44#include "configwindow.h" 44#include "configwindow.h"
45 45
46#include "../libwellenreiter/source/sock.hh" // <--- ugly path, FIX THIS! 46#include "../libwellenreiter/source/sock.hh" // <--- ugly path, FIX THIS!
47#include "../libwellenreiter/source/proto.hh" // <--- ugly path, FIX THIS! 47#include "../libwellenreiter/source/proto.hh" // <--- ugly path, FIX THIS!
48#include "../daemon/source/config.hh" // <--- ugly path, FIX THIS! 48#include "../daemon/source/config.hh" // <--- ugly path, FIX THIS!
49 49
50Wellenreiter::Wellenreiter( QWidget* parent, const char* name, WFlags fl ) 50Wellenreiter::Wellenreiter( QWidget* parent, const char* name, WFlags fl )
51 : WellenreiterBase( parent, name, fl ), daemonRunning( false ) 51 : WellenreiterBase( parent, name, fl ), daemonRunning( false )
52{ 52{
53 53
54 logwindow->log( "(i) Wellenreiter has been started." ); 54 logwindow->log( "(i) Wellenreiter has been started." );
55 55
56 connect( button, SIGNAL( clicked() ), this, SLOT( buttonClicked() ) ); 56 connect( button, SIGNAL( clicked() ), this, SLOT( buttonClicked() ) );
57 netview->setColumnWidthMode( 1, QListView::Manual ); 57 netview->setColumnWidthMode( 1, QListView::Manual );
58 58
59 // 59 //
60 // setup socket for daemon communication and start poller 60 // setup socket for daemon communication and start poller
61 // 61 //
62 62
63 daemon_fd = commsock( GUIADDR, GUIPORT ); 63 daemon_fd = commsock( GUIADDR, GUIPORT );
64 if ( daemon_fd == -1 ) 64 if ( daemon_fd == -1 )
65 { 65 {
66 logwindow->log( "(E) Couldn't get file descriptor for commsocket." ); 66 logwindow->log( "(E) Couldn't get file descriptor for commsocket." );
67 qDebug( "D'oh! Could not get file descriptor for daemon-->gui communication socket." ); 67 qDebug( "D'oh! Could not get file descriptor for daemon-->gui communication socket." );
68 } 68 }
69 else 69 else
70 startTimer( 700 ); 70 startTimer( 700 );
71 71
72} 72}
73 73
74Wellenreiter::~Wellenreiter() 74Wellenreiter::~Wellenreiter()
75{ 75{
76 // no need to delete child widgets, Qt does it all for us 76 // no need to delete child widgets, Qt does it all for us
77} 77}
78 78
79void Wellenreiter::handleMessage() 79void Wellenreiter::handleMessage()
80{ 80{
81 // FIXME: receive message and handle it 81 // FIXME: receive message and handle it
82 82
83 qDebug( "received message from daemon." ); 83 qDebug( "received message from daemon." );
84 84
85 char buffer[128]; 85 char buffer[128];
86 86
87 int result = recvcomm( &daemon_fd, (char*) &buffer, sizeof(buffer) ); 87 int result = recvcomm( &daemon_fd, (char*) &buffer, sizeof(buffer) );
88 qDebug( "received %d from recvcomm", result ); 88 qDebug( "received %d from recvcomm", result );
89 89
90/* 90/*
91typedef struct { 91typedef struct {
92 int net_type; 1 = Accesspoint ; 2 = Ad-Hoc 92 int net_type; 1 = Accesspoint ; 2 = Ad-Hoc
93 int ssid_len; Length of SSID 93 int ssid_len; Length of SSID
94 int channel; Channel 94 int channel; Channel
95 int wep; 1 = WEP enabled ; 0 = disabled 95 int wep; 1 = WEP enabled ; 0 = disabled
96 char mac[64]; MAC address of Accesspoint 96 char mac[64]; MAC address of Accesspoint
97 char bssid[128]; BSSID of Accesspoint 97 char bssid[128]; BSSID of Accesspoint
98} wl_network_t; 98} wl_network_t;
99*/ 99*/
100 100
101 // qDebug( "Sniffer sent: '%s'", (const char*) buffer ); 101 // qDebug( "Sniffer sent: '%s'", (const char*) buffer );
102 hexwindow->log( (const char*) &buffer ); 102 hexwindow->log( (const char*) &buffer );
103 103
104 if ( result == NETFOUND ) /* new network found */ 104 if ( result == NETFOUND ) /* new network found */
105 { 105 {
106 qDebug( "Sniffer said: new network found." ); 106 qDebug( "Sniffer said: new network found." );
107 wl_network_t n; 107 wl_network_t n;
108 get_network_found( &n, (char*) &buffer ); 108 get_network_found( &n, (char*) &buffer );
109 109
110 qDebug( "Sniffer said: net_type is %d.", n.net_type ); 110 qDebug( "Sniffer said: net_type is %d.", n.net_type );
111 qDebug( "Sniffer said: MAC is %s", (const char*) &n.mac ); 111 qDebug( "Sniffer said: MAC is %s", (const char*) &n.mac );
112 112
113 //n.bssid[n.ssid_len] = "\0"; 113 //n.bssid[n.ssid_len] = "\0";
114 114
115 QString type; 115 QString type;
116 116
117 if ( n.net_type == 1 ) 117 if ( n.net_type == 1 )
118 type = "managed"; 118 type = "managed";
119 else 119 else
120 type = "adhoc"; 120 type = "adhoc";
121 121
122 addNewItem( type, n.bssid, QString( (const char*) &n.mac ), n.wep, n.channel, 0 ); 122 addNewItem( type, n.bssid, QString( (const char*) &n.mac ), n.wep, n.channel, 0 );
123 123
124 } 124 }
125 125
126 else 126 else
127 127
128 { 128 {
129 qDebug( "unknown sniffer command." ); 129 qDebug( "unknown sniffer command." );
130 } 130 }
131 131
132} 132}
133 133
134 134
135bool Wellenreiter::hasMessage() 135bool Wellenreiter::hasMessage()
136{ 136{
137 137
138 // FIXME: do this in libwellenreiter, not here!!! 138 // FIXME: do this in libwellenreiter, not here!!!
139 139
140 fd_set rfds; 140 fd_set rfds;
141 FD_ZERO( &rfds ); 141 FD_ZERO( &rfds );
142 FD_SET( daemon_fd, &rfds ); 142 FD_SET( daemon_fd, &rfds );
143 struct timeval tv; 143 struct timeval tv;
144 tv.tv_sec = 0; 144 tv.tv_sec = 0;
145 tv.tv_usec = 10; 145 tv.tv_usec = 10;
146 int result = select( daemon_fd+1, &rfds, NULL, NULL, &tv ); 146 int result = select( daemon_fd+1, &rfds, NULL, NULL, &tv );
147 147
148 if ( result == 0 ) 148 if ( result == 0 )
149 { 149 {
150 return false; 150 return false;
151 } 151 }
152 else if ( result == -1 ) 152 else if ( result == -1 )
153 { 153 {
154 qDebug( "selected returned: %s", strerror( errno ) ); 154 qDebug( "selected returned: %s", strerror( errno ) );
155 return false; 155 return false;
156 } 156 }
157 else 157 else
158 return true; //FD_ISSET( daemon_fd, &rfds ); gibbet 'eh nur einen Deskriptor 158 return true; //FD_ISSET( daemon_fd, &rfds ); gibbet 'eh nur einen Deskriptor
159} 159}
160 160
161void Wellenreiter::timerEvent( QTimerEvent* e ) 161void Wellenreiter::timerEvent( QTimerEvent* e )
162{ 162{
163 //qDebug( "checking for message..." ); 163 //qDebug( "checking for message..." );
164 if ( hasMessage() ) 164 if ( hasMessage() )
165 { 165 {
166 //qDebug( "got message from daemon" ); 166 //qDebug( "got message from daemon" );
167 handleMessage(); 167 handleMessage();
168 } 168 }
169 else 169 else
170 { 170 {
171 //qDebug( "no message..." ); 171 //qDebug( "no message..." );
172 } 172 }
173} 173}
174 174
175void Wellenreiter::addNewItem( QString type, QString essid, QString macaddr, bool wep, int channel, int signal ) 175void Wellenreiter::addNewItem( QString type, QString essid, QString macaddr, bool wep, int channel, int signal )
176{ 176{
177 // FIXME: this code belongs in customized QListView, not into this class 177 // FIXME: this code belongs in customized QListView, not into this class
178 // FIXME: scanlistitem needs a proper encapsulation and not such a damn dealing with text(...) 178 // FIXME: scanlistitem needs a proper encapsulation and not such a damn dealing with text(...)
179 179
180 qDebug( "Wellenreiter::addNewItem( %s / %s / %s [%d]", 180 qDebug( "Wellenreiter::addNewItem( %s / %s / %s [%d]",
181 (const char*) type, 181 (const char*) type,
182 (const char*) essid, 182 (const char*) essid,
183 (const char*) macaddr, 183 (const char*) macaddr,
184 channel ); 184 channel );
185 185
186 // search, if we already have seen this net 186 // search, if we already have seen this net
187 187
188 QString s; 188 QString s;
189 MScanListItem* network; 189 MScanListItem* network;
190 MScanListItem* item = static_cast<MScanListItem*> ( netview->firstChild() ); 190 MScanListItem* item = static_cast<MScanListItem*> ( netview->firstChild() );
191 191
192 while ( item && ( item->text( 0 ) != essid ) ) 192 while ( item && ( item->text( 0 ) != essid ) )
193 { 193 {
194 qDebug( "itemtext: %s", (const char*) item->text( 0 ) ); 194 qDebug( "itemtext: %s", (const char*) item->text( 0 ) );
195 item = static_cast<MScanListItem*> ( item->itemBelow() ); 195 item = static_cast<MScanListItem*> ( item->itemBelow() );
196 } 196 }
197 if ( item ) 197 if ( item )
198 { 198 {
199 // we have already seen this net, check all childs if MAC exists 199 // we have already seen this net, check all childs if MAC exists
200 200
201 network = item; 201 network = item;
202 202
203 item = static_cast<MScanListItem*> ( item->firstChild() ); 203 item = static_cast<MScanListItem*> ( item->firstChild() );
204 assert( item ); // this shouldn't fail 204 assert( item ); // this shouldn't fail
205 205
206 while ( item && ( item->text( 2 ) != macaddr ) ) 206 while ( item && ( item->text( 2 ) != macaddr ) )
207 { 207 {
208 qDebug( "subitemtext: %s", (const char*) item->text( 2 ) ); 208 qDebug( "subitemtext: %s", (const char*) item->text( 2 ) );
209 item = static_cast<MScanListItem*> ( item->itemBelow() ); 209 item = static_cast<MScanListItem*> ( item->itemBelow() );
210 } 210 }
211 211
212 if ( item ) 212 if ( item )
213 { 213 {
214 // we have already seen this item, it's a dupe 214 // we have already seen this item, it's a dupe
215 qDebug( "%s is a dupe - ignoring...", (const char*) macaddr ); 215 qDebug( "%s is a dupe - ignoring...", (const char*) macaddr );
216 return; 216 return;
217 } 217 }
218 } 218 }
219 else 219 else
220 { 220 {
221 s.sprintf( "(i) new network: '%s'", (const char*) essid ); 221 s.sprintf( "(i) new network: '%s'", (const char*) essid );
222 logwindow->log( s ); 222 logwindow->log( s );
223 223
224 network = new MScanListItem( netview, "networks", essid, QString::null, 0, 0, 0 ); 224 network = new MScanListItem( netview, "networks", essid, QString::null, 0, 0, 0 );
225 } 225 }
226 226
227 227
228 // insert new station as child from network 228 // insert new station as child from network
229 229
230 // no essid to reduce clutter, maybe later we have a nick or stationname to display!? 230 // no essid to reduce clutter, maybe later we have a nick or stationname to display!?
231 231
232 qDebug( "inserting new station %s", (const char*) macaddr ); 232 qDebug( "inserting new station %s", (const char*) macaddr );
233 233
234 new MScanListItem( network, type, "", macaddr, wep, channel, signal ); 234 new MScanListItem( network, type, "", macaddr, wep, channel, signal );
235 235
236 if ( type == "managed" ) 236 if ( type == "managed" )
237 { 237 {
238 s.sprintf( "(i) new AP in '%s' [%d]", (const char*) essid, channel ); 238 s.sprintf( "(i) new AP in '%s' [%d]", (const char*) essid, channel );
239 } 239 }
240 else 240 else
241 { 241 {
242 s.sprintf( "(i) new adhoc station in '%s' [%d]", (const char*) essid, channel ); 242 s.sprintf( "(i) new adhoc station in '%s' [%d]", (const char*) essid, channel );
243 } 243 }
244 244
245 logwindow->log( s ); 245 logwindow->log( s );
246 246
247} 247}
248 248
249void Wellenreiter::buttonClicked() 249void Wellenreiter::buttonClicked()
250{ 250{
251 if ( daemonRunning ) 251 if ( daemonRunning )
252 { 252 {
253 logwindow->log( "(i) Daemon has been stopped." ); 253 logwindow->log( "(i) Daemon has been stopped." );
254 button->setText( "Start Scanning" ); 254 button->setText( "Start Scanning" );
255 255
256 // Stop daemon 256 // Stop daemon - ugly for now... later better
257 257
258 // find out pids of wellenreiterd and orinoco_hopper 258 system( "killall orinoco_hopper" );
259 system( "killall wellenreiterd" );
259 260
261 // FIXME: reset the card trying to get into a usable state again
262
263 // for now, just message the user
264
265 QMessageBox::information( this, "Wellenreiter/Opie", "You should reset your\ndevice before using it again." );
260 } 266 }
261 267
262 else 268 else
263 { 269 {
264 270
271 logwindow->log( "(i) Daemon has been started." );
272 daemonRunning = true;
273 button->setText( "Stop Scanning" );
274
265 // get configuration from config window 275 // get configuration from config window
266 276
267 const QString& interface = configwindow->interfaceName->currentText(); 277 const QString& interface = configwindow->interfaceName->currentText();
268 const QString& cardtype = configwindow->deviceType->currentText(); 278 const QString& cardtype = configwindow->deviceType->currentText();
269 const QString& interval = configwindow->hopInterval->cleanText(); 279 const QString& interval = configwindow->hopInterval->cleanText();
270 280
271 if ( ( interface == "<select>" ) || ( cardtype == "<select>" ) ) 281 if ( ( interface == "<select>" ) || ( cardtype == "<select>" ) )
272 { 282 {
273 QMessageBox::information( this, "Wellenreiter/Opie", "You must configure your\ndevice before scanning." ); 283 QMessageBox::information( this, "Wellenreiter/Opie", "You must configure your\ndevice before scanning." );
274 return; 284 return;
275 } 285 }
276 286
277 logwindow->log( "(i) Daemon has been started." );
278 button->setText( "Stop Scanning" );
279
280#ifdef QWS
281
282 // set interface into monitor mode 287 // set interface into monitor mode
288 /* Global::Execute definitely does not work very well with non-gui stuff! :( */
283 289
284 QString cmdline; 290 QString cmdline;
285 291
286 cmdline.sprintf( "iwpriv %s monitor 2", (const char*) interface ); 292 cmdline.sprintf( "iwpriv %s monitor 2", (const char*) interface );
287 system( cmdline ); 293 system( cmdline );
288 cmdline.sprintf( "iwpriv %s monitor 2 1", (const char*) interface ); 294 cmdline.sprintf( "iwpriv %s monitor 2 1", (const char*) interface );
289 system( cmdline ); 295 system( cmdline );
290 296
291 // start channel hopper 297 // start channel hopper
292 298
293 cmdline = "orinoco_hopper "; 299 cmdline = "orinoco_hopper ";
294 cmdline += interface; 300 cmdline += interface;
295 cmdline += " -i "; 301 cmdline += " -i ";
296 cmdline += interval; 302 cmdline += interval;
297 //qDebug( "execute: %s", (const char*) cmdline ); 303 cmdline += " &";
298 Global::execute( cmdline ); 304 qDebug( "execute: %s", (const char*) cmdline );
305 system( cmdline );
306 qDebug( "done" );
299 307
300 // start daemon 308 // start daemon
301 309
302 cmdline = "wellenreiterd "; 310 cmdline = "wellenreiterd ";
303 cmdline += interface; 311 cmdline += interface;
304 cmdline += " 3"; 312 cmdline += " 3";
305 //qDebug( "execute: %s", (const char*) cmdline ); 313 cmdline += " &";
306 Global::execute( cmdline );
307#endif
308 314
309 /* 315 qDebug( "execute: %s", (const char*) cmdline );
316 system( cmdline );
317 qDebug( "done" );
310 318
319 /*
320
311 // add some test stations, so that we can see if the GUI part works 321 // add some test stations, so that we can see if the GUI part works
312 322
313 addNewItem( "managed", "Vanille", "04:00:20:EF:A6:43", true, 6, 80 ); 323 addNewItem( "managed", "Vanille", "04:00:20:EF:A6:43", true, 6, 80 );
314 addNewItem( "managed", "Vanille", "04:00:20:EF:A6:23", true, 11, 10 ); 324 addNewItem( "managed", "Vanille", "04:00:20:EF:A6:23", true, 11, 10 );
315 addNewItem( "adhoc", "ELAN", "40:03:43:E7:16:22", false, 3, 10 ); 325 addNewItem( "adhoc", "ELAN", "40:03:43:E7:16:22", false, 3, 10 );
316 addNewItem( "adhoc", "ELAN", "40:03:53:E7:56:62", false, 3, 15 ); 326 addNewItem( "adhoc", "ELAN", "40:03:53:E7:56:62", false, 3, 15 );
317 addNewItem( "adhoc", "ELAN", "40:03:63:E7:56:E2", false, 3, 20 ); 327 addNewItem( "adhoc", "ELAN", "40:03:63:E7:56:E2", false, 3, 20 );
318 328
319 QString command ("98"); 329 QString command ("98");
320 330
321 //sendcomm( DAEMONADDR, DAEMONPORT, (const char*) command ); 331 //sendcomm( DAEMONADDR, DAEMONPORT, (const char*) command );
322 332
323 */ 333 */
324 } 334 }
325} 335}