summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2003-02-15 15:10:24 (UTC)
committer mickeyl <mickeyl>2003-02-15 15:10:24 (UTC)
commit2c635885e562ed5e2c687cd14164d2f509231994 (patch) (unidiff)
tree675721962838237158f501a5ae17ce50a11c592a
parentd838049d27006ea7ad0fc5bbd83e24bda8b3aa34 (diff)
downloadopie-2c635885e562ed5e2c687cd14164d2f509231994.zip
opie-2c635885e562ed5e2c687cd14164d2f509231994.tar.gz
opie-2c635885e562ed5e2c687cd14164d2f509231994.tar.bz2
- setCaption during scanning
- add some tr() - shut down / boot up interface after scanning (should work better than cardctl eject; cardctl insert)
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/wellenreiter/gui/wellenreiter.cpp15
1 files changed, 6 insertions, 9 deletions
diff --git a/noncore/net/wellenreiter/gui/wellenreiter.cpp b/noncore/net/wellenreiter/gui/wellenreiter.cpp
index 4c1c972..c1aae86 100644
--- a/noncore/net/wellenreiter/gui/wellenreiter.cpp
+++ b/noncore/net/wellenreiter/gui/wellenreiter.cpp
@@ -1,286 +1,283 @@
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#include <qsocketnotifier.h> 22#include <qsocketnotifier.h>
23 23
24// Qtopia 24// Qtopia
25 25
26#ifdef QWS 26#ifdef QWS
27#include <qpe/qpeapplication.h> 27#include <qpe/qpeapplication.h>
28#include <qpe/global.h> 28#include <qpe/global.h>
29#endif 29#endif
30 30
31// Opie 31// Opie
32 32
33#ifdef QWS 33#ifdef QWS
34#include <opie/odevice.h> 34#include <opie/odevice.h>
35using namespace Opie; 35using namespace Opie;
36#endif 36#endif
37 37
38// Standard 38// Standard
39 39
40#include <assert.h> 40#include <assert.h>
41#include <errno.h> 41#include <errno.h>
42#include <unistd.h> 42#include <unistd.h>
43#include <string.h> 43#include <string.h>
44#include <sys/types.h> 44#include <sys/types.h>
45#include <sys/socket.h> 45#include <sys/socket.h>
46#include <stdlib.h> 46#include <stdlib.h>
47#include <fcntl.h> 47#include <fcntl.h>
48 48
49// Local 49// Local
50 50
51#include "wellenreiter.h" 51#include "wellenreiter.h"
52#include "scanlist.h" 52#include "scanlist.h"
53#include "logwindow.h" 53#include "logwindow.h"
54#include "hexwindow.h" 54#include "hexwindow.h"
55#include "configwindow.h" 55#include "configwindow.h"
56 56
57#include "manufacturers.h" 57#include "manufacturers.h"
58 58
59#include <daemon/source/config.hh> 59#include <daemon/source/config.hh>
60#include <libwellenreiter/source/wl_types.hh> 60#include <libwellenreiter/source/wl_types.hh>
61#include <libwellenreiter/source/wl_sock.hh> 61#include <libwellenreiter/source/wl_sock.hh>
62#include <libwellenreiter/source/wl_proto.hh> 62#include <libwellenreiter/source/wl_proto.hh>
63 63
64Wellenreiter::Wellenreiter( QWidget* parent, const char* name, WFlags fl ) 64Wellenreiter::Wellenreiter( QWidget* parent, const char* name, WFlags fl )
65 : WellenreiterBase( parent, name, fl ), daemonRunning( false ), manufacturerdb( 0 ) 65 : WellenreiterBase( parent, name, fl ), daemonRunning( false ), manufacturerdb( 0 )
66{ 66{
67 67
68 // 68 //
69 // construct manufacturer database 69 // construct manufacturer database
70 // 70 //
71 71
72 QString manufile; 72 QString manufile;
73 #ifdef QWS 73 #ifdef QWS
74 manufile.sprintf( "%s/share/wellenreiter/manufacturers.dat", (const char*) QPEApplication::qpeDir() ); 74 manufile.sprintf( "%s/share/wellenreiter/manufacturers.dat", (const char*) QPEApplication::qpeDir() );
75 #else 75 #else
76 manufile.sprintf( "/home/mickey/work/opie/share/wellenreiter/manufacturers.dat" ); 76 manufile.sprintf( "/home/mickey/work/opie/share/wellenreiter/manufacturers.dat" );
77 #endif 77 #endif
78 manufacturerdb = new ManufacturerDB( manufile ); 78 manufacturerdb = new ManufacturerDB( manufile );
79 79
80 logwindow->log( "(i) Wellenreiter has been started." ); 80 logwindow->log( "(i) Wellenreiter has been started." );
81 81
82 // 82 //
83 // detect operating system 83 // detect operating system
84 // 84 //
85 85
86 #ifdef QWS 86 #ifdef QWS
87 QString sys; 87 QString sys;
88 sys.sprintf( "(i) Running on '%s'.", (const char*) ODevice::inst()->systemString() ); 88 sys.sprintf( "(i) Running on '%s'.", (const char*) ODevice::inst()->systemString() );
89 _system = ODevice::inst()->system(); 89 _system = ODevice::inst()->system();
90 logwindow->log( sys ); 90 logwindow->log( sys );
91 #endif 91 #endif
92 92
93 // 93 //
94 // setup socket for daemon communication, register socket notifier 94 // setup socket for daemon communication, register socket notifier
95 // 95 //
96 96
97 // struct sockaddr_in sockaddr; 97 // struct sockaddr_in sockaddr;
98 daemon_fd = wl_setupsock( GUIADDR, GUIPORT, sockaddr ); 98 daemon_fd = wl_setupsock( GUIADDR, GUIPORT, sockaddr );
99 if ( daemon_fd == -1 ) 99 if ( daemon_fd == -1 )
100 { 100 {
101 logwindow->log( "(E) Couldn't get file descriptor for commsocket." ); 101 logwindow->log( "(E) Couldn't get file descriptor for commsocket." );
102 } 102 }
103 else 103 else
104 { 104 {
105 int flags; 105 int flags;
106 flags = fcntl( daemon_fd, F_GETFL, 0 ); 106 flags = fcntl( daemon_fd, F_GETFL, 0 );
107 fcntl( daemon_fd, F_SETFL, flags | O_NONBLOCK ); 107 fcntl( daemon_fd, F_SETFL, flags | O_NONBLOCK );
108 QSocketNotifier *sn = new QSocketNotifier( daemon_fd, QSocketNotifier::Read, parent ); 108 QSocketNotifier *sn = new QSocketNotifier( daemon_fd, QSocketNotifier::Read, parent );
109 connect( sn, SIGNAL( activated( int ) ), this, SLOT( dataReceived() ) ); 109 connect( sn, SIGNAL( activated( int ) ), this, SLOT( dataReceived() ) );
110 } 110 }
111 111
112 // setup GUI 112 // setup GUI
113 113
114 connect( button, SIGNAL( clicked() ), this, SLOT( buttonClicked() ) ); 114 connect( button, SIGNAL( clicked() ), this, SLOT( buttonClicked() ) );
115 // button->setEnabled( false ); 115 // button->setEnabled( false );
116 netview->setColumnWidthMode( 1, QListView::Manual ); 116 netview->setColumnWidthMode( 1, QListView::Manual );
117 117
118 if ( manufacturerdb ) 118 if ( manufacturerdb )
119 netview->setManufacturerDB( manufacturerdb ); 119 netview->setManufacturerDB( manufacturerdb );
120 120
121} 121}
122 122
123Wellenreiter::~Wellenreiter() 123Wellenreiter::~Wellenreiter()
124{ 124{
125 // no need to delete child widgets, Qt does it all for us 125 // no need to delete child widgets, Qt does it all for us
126 126
127 delete manufacturerdb; 127 delete manufacturerdb;
128} 128}
129 129
130void Wellenreiter::handleMessage() 130void Wellenreiter::handleMessage()
131{ 131{
132 // FIXME: receive message and handle it 132 // FIXME: receive message and handle it
133 133
134 qDebug( "received message from daemon." ); 134 qDebug( "received message from daemon." );
135 135
136 /*char buffer[10000]; 136 /*char buffer[10000];
137 memset( &buffer, 0, sizeof( buffer ) );*/ 137 memset( &buffer, 0, sizeof( buffer ) );*/
138 138
139 char buffer[WL_SOCKBUF]; 139 char buffer[WL_SOCKBUF];
140 140
141 // int result = #wl_recv( &daemon_fd, (char*) &buffer, sizeof(buffer) ); 141 // int result = #wl_recv( &daemon_fd, (char*) &buffer, sizeof(buffer) );
142 142
143 /* 143 /*
144 144
145 struct sockaddr from; 145 struct sockaddr from;
146 socklen_t len; 146 socklen_t len;
147 147
148 int result = recvfrom( daemon_fd, &buffer, 8192, MSG_WAITALL, &from, &len ); 148 int result = recvfrom( daemon_fd, &buffer, 8192, MSG_WAITALL, &from, &len );
149 qDebug( "received %d from recv [%d bytes]", result, len ); 149 qDebug( "received %d from recv [%d bytes]", result, len );
150 150
151 */ 151 */
152 152
153 int result = wl_recv( &daemon_fd, sockaddr, (char*) &buffer, WL_SOCKBUF ); 153 int result = wl_recv( &daemon_fd, sockaddr, (char*) &buffer, WL_SOCKBUF );
154 154
155 if ( result == -1 ) 155 if ( result == -1 )
156 { 156 {
157 qDebug( "Warning: %s", strerror( errno ) ); 157 qDebug( "Warning: %s", strerror( errno ) );
158 return; 158 return;
159 } 159 }
160 160
161 int command = buffer[1] - 48; 161 int command = buffer[1] - 48;
162 162
163/* 163/*
164typedef struct { 164typedef struct {
165 int net_type; 1 = Accesspoint ; 2 = Ad-Hoc 165 int net_type; 1 = Accesspoint ; 2 = Ad-Hoc
166 int ssid_len; Length of SSID 166 int ssid_len; Length of SSID
167 int channel; Channel 167 int channel; Channel
168 int wep; 1 = WEP enabled ; 0 = disabled 168 int wep; 1 = WEP enabled ; 0 = disabled
169 char mac[64]; MAC address of Accesspoint 169 char mac[64]; MAC address of Accesspoint
170 char bssid[128]; BSSID of Accesspoint 170 char bssid[128]; BSSID of Accesspoint
171} wl_network_t; 171} wl_network_t;
172*/ 172*/
173 173
174 qDebug( "Recv result: %d", ( result ) ); 174 qDebug( "Recv result: %d", ( result ) );
175 qDebug( "Sniffer sent: '%s'", (const char*) buffer ); 175 qDebug( "Sniffer sent: '%s'", (const char*) buffer );
176 hexwindow->log( (const char*) &buffer ); 176 hexwindow->log( (const char*) &buffer );
177 177
178 if ( command == NETFOUND ) /* new network found */ 178 if ( command == NETFOUND ) /* new network found */
179 { 179 {
180 qDebug( "Sniffer said: new network found." ); 180 qDebug( "Sniffer said: new network found." );
181 wl_network_t n; 181 wl_network_t n;
182 get_network_found( &n, (char*) &buffer ); 182 get_network_found( &n, (char*) &buffer );
183 183
184 qDebug( "Sniffer said: net_type is %d.", n.net_type ); 184 qDebug( "Sniffer said: net_type is %d.", n.net_type );
185 qDebug( "Sniffer said: MAC is %s", (const char*) &n.mac ); 185 qDebug( "Sniffer said: MAC is %s", (const char*) &n.mac );
186 186
187 //n.bssid[n.ssid_len] = "\0"; 187 //n.bssid[n.ssid_len] = "\0";
188 188
189 QString type; 189 QString type;
190 190
191 if ( n.net_type == 1 ) 191 if ( n.net_type == 1 )
192 type = "managed"; 192 type = "managed";
193 else 193 else
194 type = "adhoc"; 194 type = "adhoc";
195 195
196 netview->addNewItem( type, n.bssid, QString( (const char*) &n.mac ), n.wep, n.channel, 0 ); 196 netview->addNewItem( type, n.bssid, QString( (const char*) &n.mac ), n.wep, n.channel, 0 );
197 197
198 } 198 }
199 199
200 else 200 else
201 201
202 { 202 {
203 qDebug( "unknown sniffer command." ); 203 qDebug( "unknown sniffer command." );
204 } 204 }
205 205
206} 206}
207 207
208void Wellenreiter::dataReceived() 208void Wellenreiter::dataReceived()
209{ 209{
210 logwindow->log( "(d) Received data from daemon" ); 210 logwindow->log( "(d) Received data from daemon" );
211 handleMessage(); 211 handleMessage();
212} 212}
213 213
214void Wellenreiter::buttonClicked() 214void Wellenreiter::buttonClicked()
215{ 215{
216 /* 216 /*
217 // add some test stations, so that we can see if the GUI part works 217 // add some test stations, so that we can see if the GUI part works
218 addNewItem( "managed", "Vanille", "04:00:20:EF:A6:43", true, 6, 80 ); 218 addNewItem( "managed", "Vanille", "04:00:20:EF:A6:43", true, 6, 80 );
219 addNewItem( "managed", "Vanille", "04:00:20:EF:A6:23", true, 11, 10 ); 219 addNewItem( "managed", "Vanille", "04:00:20:EF:A6:23", true, 11, 10 );
220 addNewItem( "adhoc", "ELAN", "40:03:43:E7:16:22", false, 3, 10 ); 220 addNewItem( "adhoc", "ELAN", "40:03:43:E7:16:22", false, 3, 10 );
221 addNewItem( "adhoc", "ELAN", "40:03:53:E7:56:62", false, 3, 15 ); 221 addNewItem( "adhoc", "ELAN", "40:03:53:E7:56:62", false, 3, 15 );
222 addNewItem( "adhoc", "ELAN", "40:03:63:E7:56:E2", false, 3, 20 ); 222 addNewItem( "adhoc", "ELAN", "40:03:63:E7:56:E2", false, 3, 20 );
223 */ 223 */
224 224
225 225
226 if ( daemonRunning ) 226 if ( daemonRunning )
227 { 227 {
228 daemonRunning = false; 228 daemonRunning = false;
229 229
230 logwindow->log( "(i) Daemon has been stopped." ); 230 logwindow->log( "(i) Daemon has been stopped." );
231 button->setText( "Start Scanning" ); 231 button->setText( tr( "Start Scanning" ) );
232 setCaption( tr( "Scanning in progress..." ) );
232 233
233 // Stop daemon - ugly for now... later better 234 // Stop daemon - ugly for now... later better
234 235
235 system( "killall wellenreiterd" ); 236 system( "killall wellenreiterd" );
236 237
237 // get configuration from config window 238 // get configuration from config window
238 239
239 const QString& interface = configwindow->interfaceName->currentText(); 240 const QString& interface = configwindow->interfaceName->currentText();
240 const QString& cardtype = configwindow->deviceType->currentText();
241 //const QString& interval = configwindow->hopInterval->cleanText();
242 241
243 // reset the card trying to get into a usable state again 242 // reset the interface trying to get it into a usable state again
244 243
245 QString cmdline; 244 QString cmdline;
246 cmdline.sprintf( "cardctl eject; cardctl insert" ); 245 cmdline.sprintf( "ifdown %s; ifup %s", (const char*) interface, (const char*) interface );
247 system( cmdline ); 246 system( cmdline );
248 cmdline.sprintf( "killall -14 dhcpcd" );
249 system( cmdline );
250 cmdline.sprintf( "killall -10 udhcpc" );
251 247
252 // message the user 248 // message the user
253 249
254 QMessageBox::information( this, "Wellenreiter/Opie", "Your wireless card\nshould now be usable again." ); 250 QMessageBox::information( this, "Wellenreiter/Opie", "Your wireless card\nshould now be usable again." );
255 } 251 }
256 252
257 else 253 else
258 { 254 {
259 255
260 // get configuration from config window 256 // get configuration from config window
261 257
262 const QString& interface = configwindow->interfaceName->currentText(); 258 const QString& interface = configwindow->interfaceName->currentText();
263 const int cardtype = configwindow->daemonDeviceType(); 259 const int cardtype = configwindow->daemonDeviceType();
264 const int interval = configwindow->daemonHopInterval(); 260 const int interval = configwindow->daemonHopInterval();
265 261
266 if ( ( interface == "<select>" ) || ( cardtype == 0 ) ) 262 if ( ( interface == "<select>" ) || ( cardtype == 0 ) )
267 { 263 {
268 QMessageBox::information( this, "Wellenreiter/Opie", "You must configure your\ndevice before scanning." ); 264 QMessageBox::information( this, "Wellenreiter/Opie", "You must configure your\ndevice before scanning." );
269 return; 265 return;
270 } 266 }
271 267
272 // start wellenreiterd 268 // start wellenreiterd
273 269
274 QString cmdline; 270 QString cmdline;
275 cmdline.sprintf( "wellenreiterd %s %d &", (const char*) interface, cardtype ); 271 cmdline.sprintf( "wellenreiterd %s %d &", (const char*) interface, cardtype );
276 272
277 qDebug( "about to execute '%s' ...", (const char*) cmdline ); 273 qDebug( "about to execute '%s' ...", (const char*) cmdline );
278 system( cmdline ); 274 system( cmdline );
279 qDebug( "done!" ); 275 qDebug( "done!" );
280 276
281 logwindow->log( "(i) Daemon has been started." ); 277 logwindow->log( "(i) Daemon has been started." );
282 daemonRunning = true; 278 daemonRunning = true;
283 button->setText( "Stop Scanning" ); 279 button->setText( tr( "Stop Scanning" ) );
280 setCaption( tr( "Wellenreiter/Opie" ) );
284 281
285 } 282 }
286} 283}