Diffstat (limited to 'noncore/net/wellenreiter/gui/wellenreiter.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/wellenreiter/gui/wellenreiter.cpp | 37 |
1 files changed, 14 insertions, 23 deletions
diff --git a/noncore/net/wellenreiter/gui/wellenreiter.cpp b/noncore/net/wellenreiter/gui/wellenreiter.cpp index 4c53028..db7063b 100644 --- a/noncore/net/wellenreiter/gui/wellenreiter.cpp +++ b/noncore/net/wellenreiter/gui/wellenreiter.cpp | |||
@@ -16,268 +16,259 @@ | |||
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> |
35 | using namespace Opie; | 35 | using 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 | ||
64 | Wellenreiter::Wellenreiter( QWidget* parent, const char* name, WFlags fl ) | 64 | Wellenreiter::Wellenreiter( QWidget* parent ) |
65 | : WellenreiterBase( parent, name, fl ), daemonRunning( false ), manufacturerdb( 0 ) | 65 | : WellenreiterBase( parent, 0, 0 ), |
66 | daemonRunning( false ), manufacturerdb( 0 ), configwindow( 0 ) | ||
66 | { | 67 | { |
67 | 68 | ||
68 | // | 69 | // |
69 | // construct manufacturer database | 70 | // construct manufacturer database |
70 | // | 71 | // |
71 | 72 | ||
72 | QString manufile; | 73 | QString manufile; |
73 | #ifdef QWS | 74 | #ifdef QWS |
74 | manufile.sprintf( "%s/share/wellenreiter/manufacturers.dat", (const char*) QPEApplication::qpeDir() ); | 75 | manufile.sprintf( "%s/share/wellenreiter/manufacturers.dat", (const char*) QPEApplication::qpeDir() ); |
75 | #else | 76 | #else |
76 | manufile.sprintf( "/home/mickey/work/opie/share/wellenreiter/manufacturers.dat" ); | 77 | manufile.sprintf( "/home/mickey/work/opie/share/wellenreiter/manufacturers.dat" ); |
77 | #endif | 78 | #endif |
78 | manufacturerdb = new ManufacturerDB( manufile ); | 79 | manufacturerdb = new ManufacturerDB( manufile ); |
79 | 80 | ||
80 | logwindow->log( "(i) Wellenreiter has been started." ); | 81 | logwindow->log( "(i) Wellenreiter has been started." ); |
81 | 82 | ||
82 | // | 83 | // |
83 | // detect operating system | 84 | // detect operating system |
84 | // | 85 | // |
85 | 86 | ||
86 | #ifdef QWS | 87 | #ifdef QWS |
87 | QString sys; | 88 | QString sys; |
88 | sys.sprintf( "(i) Running on '%s'.", (const char*) ODevice::inst()->systemString() ); | 89 | sys.sprintf( "(i) Running on '%s'.", (const char*) ODevice::inst()->systemString() ); |
89 | _system = ODevice::inst()->system(); | 90 | _system = ODevice::inst()->system(); |
90 | logwindow->log( sys ); | 91 | logwindow->log( sys ); |
91 | #endif | 92 | #endif |
92 | 93 | ||
93 | // | 94 | // |
94 | // setup socket for daemon communication, register socket notifier | 95 | // setup socket for daemon communication, register socket notifier |
95 | // | 96 | // |
96 | 97 | ||
97 | // struct sockaddr_in sockaddr; | 98 | // struct sockaddr_in sockaddr; |
98 | daemon_fd = wl_setupsock( GUIADDR, GUIPORT, sockaddr ); | 99 | daemon_fd = wl_setupsock( GUIADDR, GUIPORT, sockaddr ); |
99 | if ( daemon_fd == -1 ) | 100 | if ( daemon_fd == -1 ) |
100 | { | 101 | { |
101 | logwindow->log( "(E) Couldn't get file descriptor for commsocket." ); | 102 | logwindow->log( "(E) Couldn't get file descriptor for commsocket." ); |
102 | } | 103 | } |
103 | else | 104 | else |
104 | { | 105 | { |
105 | int flags; | 106 | int flags; |
106 | flags = fcntl( daemon_fd, F_GETFL, 0 ); | 107 | flags = fcntl( daemon_fd, F_GETFL, 0 ); |
107 | fcntl( daemon_fd, F_SETFL, flags | O_NONBLOCK ); | 108 | fcntl( daemon_fd, F_SETFL, flags | O_NONBLOCK ); |
108 | QSocketNotifier *sn = new QSocketNotifier( daemon_fd, QSocketNotifier::Read, parent ); | 109 | QSocketNotifier *sn = new QSocketNotifier( daemon_fd, QSocketNotifier::Read, parent ); |
109 | connect( sn, SIGNAL( activated( int ) ), this, SLOT( dataReceived() ) ); | 110 | connect( sn, SIGNAL( activated( int ) ), this, SLOT( dataReceived() ) ); |
110 | } | 111 | } |
111 | 112 | ||
112 | // setup GUI | 113 | // setup GUI |
113 | |||
114 | connect( button, SIGNAL( clicked() ), this, SLOT( buttonClicked() ) ); | ||
115 | // button->setEnabled( false ); | ||
116 | netview->setColumnWidthMode( 1, QListView::Manual ); | 114 | netview->setColumnWidthMode( 1, QListView::Manual ); |
117 | 115 | ||
118 | if ( manufacturerdb ) | 116 | if ( manufacturerdb ) |
119 | netview->setManufacturerDB( manufacturerdb ); | 117 | netview->setManufacturerDB( manufacturerdb ); |
120 | 118 | ||
121 | } | 119 | } |
122 | 120 | ||
123 | Wellenreiter::~Wellenreiter() | 121 | Wellenreiter::~Wellenreiter() |
124 | { | 122 | { |
125 | // no need to delete child widgets, Qt does it all for us | 123 | // no need to delete child widgets, Qt does it all for us |
126 | 124 | ||
127 | delete manufacturerdb; | 125 | delete manufacturerdb; |
128 | } | 126 | } |
129 | 127 | ||
128 | void Wellenreiter::setConfigWindow( WellenreiterConfigWindow* cw ) | ||
129 | { | ||
130 | configwindow = cw; | ||
131 | } | ||
132 | |||
130 | void Wellenreiter::handleMessage() | 133 | void Wellenreiter::handleMessage() |
131 | { | 134 | { |
132 | // FIXME: receive message and handle it | 135 | // FIXME: receive message and handle it |
133 | 136 | ||
134 | qDebug( "received message from daemon." ); | 137 | qDebug( "received message from daemon." ); |
135 | 138 | ||
136 | /*char buffer[10000]; | 139 | /*char buffer[10000]; |
137 | memset( &buffer, 0, sizeof( buffer ) );*/ | 140 | memset( &buffer, 0, sizeof( buffer ) );*/ |
138 | 141 | ||
139 | char buffer[WL_SOCKBUF]; | 142 | char buffer[WL_SOCKBUF]; |
140 | 143 | ||
141 | // int result = #wl_recv( &daemon_fd, (char*) &buffer, sizeof(buffer) ); | 144 | // int result = #wl_recv( &daemon_fd, (char*) &buffer, sizeof(buffer) ); |
142 | 145 | ||
143 | /* | 146 | /* |
144 | 147 | ||
145 | struct sockaddr from; | 148 | struct sockaddr from; |
146 | socklen_t len; | 149 | socklen_t len; |
147 | 150 | ||
148 | int result = recvfrom( daemon_fd, &buffer, 8192, MSG_WAITALL, &from, &len ); | 151 | int result = recvfrom( daemon_fd, &buffer, 8192, MSG_WAITALL, &from, &len ); |
149 | qDebug( "received %d from recv [%d bytes]", result, len ); | 152 | qDebug( "received %d from recv [%d bytes]", result, len ); |
150 | 153 | ||
151 | */ | 154 | */ |
152 | 155 | ||
153 | int result = wl_recv( &daemon_fd, sockaddr, (char*) &buffer, WL_SOCKBUF ); | 156 | int result = wl_recv( &daemon_fd, sockaddr, (char*) &buffer, WL_SOCKBUF ); |
154 | 157 | ||
155 | if ( result == -1 ) | 158 | if ( result == -1 ) |
156 | { | 159 | { |
157 | qDebug( "Warning: %s", strerror( errno ) ); | 160 | qDebug( "Warning: %s", strerror( errno ) ); |
158 | return; | 161 | return; |
159 | } | 162 | } |
160 | 163 | ||
161 | int command = buffer[1] - 48; | 164 | int command = buffer[1] - 48; |
162 | 165 | ||
163 | /* | 166 | /* |
164 | typedef struct { | 167 | typedef struct { |
165 | int net_type; 1 = Accesspoint ; 2 = Ad-Hoc | 168 | int net_type; 1 = Accesspoint ; 2 = Ad-Hoc |
166 | int ssid_len; Length of SSID | 169 | int ssid_len; Length of SSID |
167 | int channel; Channel | 170 | int channel; Channel |
168 | int wep; 1 = WEP enabled ; 0 = disabled | 171 | int wep; 1 = WEP enabled ; 0 = disabled |
169 | char mac[64]; MAC address of Accesspoint | 172 | char mac[64]; MAC address of Accesspoint |
170 | char bssid[128]; BSSID of Accesspoint | 173 | char bssid[128]; BSSID of Accesspoint |
171 | } wl_network_t; | 174 | } wl_network_t; |
172 | */ | 175 | */ |
173 | 176 | ||
174 | qDebug( "Recv result: %d", ( result ) ); | 177 | qDebug( "Recv result: %d", ( result ) ); |
175 | qDebug( "Sniffer sent: '%s'", (const char*) buffer ); | 178 | qDebug( "Sniffer sent: '%s'", (const char*) buffer ); |
176 | hexwindow->log( (const char*) &buffer ); | 179 | hexwindow->log( (const char*) &buffer ); |
177 | 180 | ||
178 | if ( command == NETFOUND ) /* new network found */ | 181 | if ( command == NETFOUND ) /* new network found */ |
179 | { | 182 | { |
180 | qDebug( "Sniffer said: new network found." ); | 183 | qDebug( "Sniffer said: new network found." ); |
181 | wl_network_t n; | 184 | wl_network_t n; |
182 | get_network_found( &n, (char*) &buffer ); | 185 | get_network_found( &n, (char*) &buffer ); |
183 | 186 | ||
184 | qDebug( "Sniffer said: net_type is %d.", n.net_type ); | 187 | qDebug( "Sniffer said: net_type is %d.", n.net_type ); |
185 | qDebug( "Sniffer said: MAC is %s", (const char*) &n.mac ); | 188 | qDebug( "Sniffer said: MAC is %s", (const char*) &n.mac ); |
186 | 189 | ||
187 | //n.bssid[n.ssid_len] = "\0"; | 190 | //n.bssid[n.ssid_len] = "\0"; |
188 | 191 | ||
189 | QString type; | 192 | QString type; |
190 | 193 | ||
191 | if ( n.net_type == 1 ) | 194 | if ( n.net_type == 1 ) |
192 | type = "managed"; | 195 | type = "managed"; |
193 | else | 196 | else |
194 | type = "adhoc"; | 197 | type = "adhoc"; |
195 | 198 | ||
196 | netview->addNewItem( type, n.bssid, QString( (const char*) &n.mac ), n.wep, n.channel, 0 ); | 199 | netview->addNewItem( type, n.bssid, QString( (const char*) &n.mac ), n.wep, n.channel, 0 ); |
197 | 200 | ||
198 | } | 201 | } |
199 | 202 | ||
200 | else | 203 | else |
201 | 204 | ||
202 | { | 205 | { |
203 | qDebug( "unknown sniffer command." ); | 206 | qDebug( "unknown sniffer command." ); |
204 | } | 207 | } |
205 | 208 | ||
206 | } | 209 | } |
207 | 210 | ||
208 | void Wellenreiter::dataReceived() | 211 | void Wellenreiter::dataReceived() |
209 | { | 212 | { |
210 | logwindow->log( "(d) Received data from daemon" ); | 213 | logwindow->log( "(d) Received data from daemon" ); |
211 | handleMessage(); | 214 | handleMessage(); |
212 | } | 215 | } |
213 | 216 | ||
214 | void Wellenreiter::buttonClicked() | 217 | void Wellenreiter::startStopClicked() |
215 | { | 218 | { |
216 | /* | ||
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 ); | ||
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 ); | ||
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 ); | ||
223 | */ | ||
224 | |||
225 | |||
226 | if ( daemonRunning ) | 219 | if ( daemonRunning ) |
227 | { | 220 | { |
228 | daemonRunning = false; | 221 | daemonRunning = false; |
229 | 222 | ||
230 | logwindow->log( "(i) Daemon has been stopped." ); | 223 | logwindow->log( "(i) Daemon has been stopped." ); |
231 | button->setText( tr( "Start Scanning" ) ); | ||
232 | setCaption( tr( "Wellenreiter/Opie" ) ); | 224 | setCaption( tr( "Wellenreiter/Opie" ) ); |
233 | 225 | ||
234 | // Stop daemon - ugly for now... later better | 226 | // Stop daemon - ugly for now... later better |
235 | 227 | ||
236 | system( "killall wellenreiterd" ); | 228 | system( "killall wellenreiterd" ); |
237 | 229 | ||
238 | // get configuration from config window | 230 | // get configuration from config window |
239 | 231 | ||
240 | const QString& interface = configwindow->interfaceName->currentText(); | 232 | const QString& interface = configwindow->interfaceName->currentText(); |
241 | 233 | ||
242 | // reset the interface trying to get it into a usable state again | 234 | // reset the interface trying to get it into a usable state again |
243 | 235 | ||
244 | QString cmdline; | 236 | QString cmdline; |
245 | cmdline.sprintf( "iwpriv %s monitor 0; ifdown %s; ifup %s", (const char*) interface, (const char*) interface, (const char*) interface ); | 237 | cmdline.sprintf( "iwpriv %s monitor 0; ifdown %s; ifup %s", (const char*) interface, (const char*) interface, (const char*) interface ); |
246 | system( cmdline ); | 238 | system( cmdline ); |
247 | 239 | ||
248 | // message the user | 240 | // message the user |
249 | 241 | ||
250 | QMessageBox::information( this, "Wellenreiter/Opie", "Your wireless card\nshould now be usable again." ); | 242 | QMessageBox::information( this, "Wellenreiter/Opie", "Your wireless card\nshould now be usable again." ); |
251 | } | 243 | } |
252 | 244 | ||
253 | else | 245 | else |
254 | { | 246 | { |
255 | 247 | ||
256 | // get configuration from config window | 248 | // get configuration from config window |
257 | 249 | ||
258 | const QString& interface = configwindow->interfaceName->currentText(); | 250 | const QString& interface = configwindow->interfaceName->currentText(); |
259 | const int cardtype = configwindow->daemonDeviceType(); | 251 | const int cardtype = configwindow->daemonDeviceType(); |
260 | const int interval = configwindow->daemonHopInterval(); | 252 | const int interval = configwindow->daemonHopInterval(); |
261 | 253 | ||
262 | if ( ( interface == "<select>" ) || ( cardtype == 0 ) ) | 254 | if ( ( interface == "<select>" ) || ( cardtype == 0 ) ) |
263 | { | 255 | { |
264 | QMessageBox::information( this, "Wellenreiter/Opie", "You must configure your\ndevice before scanning." ); | 256 | QMessageBox::information( this, "Wellenreiter/Opie", "Your device is not\nptoperly configured. Please reconfigure!" ); |
265 | return; | 257 | return; |
266 | } | 258 | } |
267 | 259 | ||
268 | // start wellenreiterd | 260 | // start wellenreiterd |
269 | 261 | ||
270 | QString cmdline; | 262 | QString cmdline; |
271 | cmdline.sprintf( "wellenreiterd %s %d &", (const char*) interface, cardtype ); | 263 | cmdline.sprintf( "wellenreiterd %s %d &", (const char*) interface, cardtype ); |
272 | 264 | ||
273 | qDebug( "about to execute '%s' ...", (const char*) cmdline ); | 265 | qDebug( "about to execute '%s' ...", (const char*) cmdline ); |
274 | system( cmdline ); | 266 | system( cmdline ); |
275 | qDebug( "done!" ); | 267 | qDebug( "done!" ); |
276 | 268 | ||
277 | logwindow->log( "(i) Daemon has been started." ); | 269 | logwindow->log( "(i) Daemon has been started." ); |
278 | daemonRunning = true; | 270 | daemonRunning = true; |
279 | button->setText( tr( "Stop Scanning" ) ); | ||
280 | setCaption( tr( "Scanning ..." ) ); | 271 | setCaption( tr( "Scanning ..." ) ); |
281 | 272 | ||
282 | } | 273 | } |
283 | } | 274 | } |