author | mickeyl <mickeyl> | 2002-12-28 18:57:11 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2002-12-28 18:57:11 (UTC) |
commit | f70916f3ab05917a3d0dda64beb8db5ac16448ab (patch) (unidiff) | |
tree | bd138c1a901de7ea49b012b32e48d3f4b8b073f8 /noncore/net/wellenreiter/gui/wellenreiter.cpp | |
parent | 1362726346f1ab497ad5822db1a9b284f5bdaa1a (diff) | |
download | opie-f70916f3ab05917a3d0dda64beb8db5ac16448ab.zip opie-f70916f3ab05917a3d0dda64beb8db5ac16448ab.tar.gz opie-f70916f3ab05917a3d0dda64beb8db5ac16448ab.tar.bz2 |
- refactored a number of classes
- removed dumb polling ==> QSocketNotifier rocks
- switched to parsing the daemon stuff in the gui,
since libwellenreiter still has problems.
Diffstat (limited to 'noncore/net/wellenreiter/gui/wellenreiter.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/wellenreiter/gui/wellenreiter.cpp | 213 |
1 files changed, 73 insertions, 140 deletions
diff --git a/noncore/net/wellenreiter/gui/wellenreiter.cpp b/noncore/net/wellenreiter/gui/wellenreiter.cpp index 0fd929f..2d9bbee 100644 --- a/noncore/net/wellenreiter/gui/wellenreiter.cpp +++ b/noncore/net/wellenreiter/gui/wellenreiter.cpp | |||
@@ -16,32 +16,42 @@ | |||
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 | 23 | ||
23 | // Qtopia | 24 | // Qtopia |
24 | 25 | ||
25 | #ifdef QWS | 26 | #ifdef QWS |
26 | #include <qpe/global.h> | 27 | #include <qpe/global.h> |
27 | #endif | 28 | #endif |
28 | 29 | ||
30 | // Opie | ||
31 | |||
32 | #ifdef QWS | ||
33 | #include <opie/odevice.h> | ||
34 | using namespace Opie; | ||
35 | #endif | ||
36 | |||
29 | // Standard | 37 | // Standard |
30 | 38 | ||
31 | #include <assert.h> | 39 | #include <assert.h> |
32 | #include <errno.h> | 40 | #include <errno.h> |
33 | #include <unistd.h> | 41 | #include <unistd.h> |
34 | #include <string.h> | 42 | #include <string.h> |
35 | #include <sys/types.h> | 43 | #include <sys/types.h> |
44 | #include <sys/socket.h> | ||
36 | #include <stdlib.h> | 45 | #include <stdlib.h> |
46 | #include <fcntl.h> | ||
37 | 47 | ||
38 | // Local | 48 | // Local |
39 | 49 | ||
40 | #include "wellenreiter.h" | 50 | #include "wellenreiter.h" |
41 | #include "scanlistitem.h" | 51 | #include "scanlist.h" |
42 | #include "logwindow.h" | 52 | #include "logwindow.h" |
43 | #include "hexwindow.h" | 53 | #include "hexwindow.h" |
44 | #include "configwindow.h" | 54 | #include "configwindow.h" |
45 | 55 | ||
46 | #include <libwellenreiter/source/wl_sock.hh> | 56 | #include <libwellenreiter/source/wl_sock.hh> |
47 | #include <libwellenreiter/source/wl_proto.hh> | 57 | #include <libwellenreiter/source/wl_proto.hh> |
@@ -50,28 +60,47 @@ | |||
50 | Wellenreiter::Wellenreiter( QWidget* parent, const char* name, WFlags fl ) | 60 | Wellenreiter::Wellenreiter( QWidget* parent, const char* name, WFlags fl ) |
51 | : WellenreiterBase( parent, name, fl ), daemonRunning( false ) | 61 | : WellenreiterBase( parent, name, fl ), daemonRunning( false ) |
52 | { | 62 | { |
53 | 63 | ||
54 | logwindow->log( "(i) Wellenreiter has been started." ); | 64 | logwindow->log( "(i) Wellenreiter has been started." ); |
55 | 65 | ||
56 | connect( button, SIGNAL( clicked() ), this, SLOT( buttonClicked() ) ); | ||
57 | netview->setColumnWidthMode( 1, QListView::Manual ); | ||
58 | |||
59 | // | 66 | // |
60 | // setup socket for daemon communication and start poller | 67 | // detect operating system |
68 | // | ||
69 | |||
70 | #ifdef QWS | ||
71 | QString sys; | ||
72 | sys.sprintf( "(i) Running on '%s'.", (const char*) ODevice::inst()->systemString() ); | ||
73 | _system = ODevice::inst()->system(); | ||
74 | logwindow->log( sys ); | ||
75 | #endif | ||
76 | |||
77 | // | ||
78 | // setup socket for daemon communication, register socket notifier | ||
61 | // | 79 | // |
62 | 80 | ||
63 | daemon_fd = wl_setupsock( GUIADDR, GUIPORT ); | 81 | daemon_fd = wl_setupsock( GUIADDR, GUIPORT ); |
64 | if ( daemon_fd == -1 ) | 82 | if ( daemon_fd == -1 ) |
65 | { | 83 | { |
66 | logwindow->log( "(E) Couldn't get file descriptor for commsocket." ); | 84 | logwindow->log( "(E) Couldn't get file descriptor for commsocket." ); |
67 | qDebug( "D'oh! Could not get file descriptor for daemon-->gui communication socket." ); | ||
68 | } | 85 | } |
69 | else | 86 | else |
70 | startTimer( 700 ); | 87 | { |
88 | int flags; | ||
89 | flags = fcntl( daemon_fd, F_GETFL, 0 ); | ||
90 | fcntl( daemon_fd, F_SETFL, flags | O_NONBLOCK ); | ||
91 | QSocketNotifier *sn = new QSocketNotifier( daemon_fd, QSocketNotifier::Read, parent ); | ||
92 | connect( sn, SIGNAL( activated( int ) ), this, SLOT( dataReceived() ) ); | ||
93 | } | ||
71 | 94 | ||
95 | // setup GUI | ||
96 | |||
97 | connect( button, SIGNAL( clicked() ), this, SLOT( buttonClicked() ) ); | ||
98 | button->setEnabled( false ); | ||
99 | netview->setColumnWidthMode( 1, QListView::Manual ); | ||
100 | |||
72 | } | 101 | } |
73 | 102 | ||
74 | Wellenreiter::~Wellenreiter() | 103 | Wellenreiter::~Wellenreiter() |
75 | { | 104 | { |
76 | // no need to delete child widgets, Qt does it all for us | 105 | // no need to delete child widgets, Qt does it all for us |
77 | } | 106 | } |
@@ -79,32 +108,48 @@ Wellenreiter::~Wellenreiter() | |||
79 | void Wellenreiter::handleMessage() | 108 | void Wellenreiter::handleMessage() |
80 | { | 109 | { |
81 | // FIXME: receive message and handle it | 110 | // FIXME: receive message and handle it |
82 | 111 | ||
83 | qDebug( "received message from daemon." ); | 112 | qDebug( "received message from daemon." ); |
84 | 113 | ||
85 | char buffer[128]; | 114 | char buffer[10000]; |
86 | 115 | memset( &buffer, 0, sizeof( buffer ) ); | |
87 | int result = wl_recv( &daemon_fd, (char*) &buffer, sizeof(buffer) ); | ||
88 | qDebug( "received %d from recvcomm", result ); | ||
89 | 116 | ||
117 | // int result = #wl_recv( &daemon_fd, (char*) &buffer, sizeof(buffer) ); | ||
118 | |||
119 | struct sockaddr from; | ||
120 | socklen_t len; | ||
121 | |||
122 | int result = recvfrom( daemon_fd, &buffer, 8192, MSG_WAITALL, &from, &len ); | ||
123 | |||
124 | qDebug( "received %d from recv [%d bytes]", result, len ); | ||
125 | |||
126 | if ( result == -1 ) | ||
127 | { | ||
128 | qDebug( "Warning: %s", strerror( errno ) ); | ||
129 | return; | ||
130 | } | ||
131 | |||
132 | int command = buffer[1] - 48; | ||
133 | |||
90 | /* | 134 | /* |
91 | typedef struct { | 135 | typedef struct { |
92 | int net_type; 1 = Accesspoint ; 2 = Ad-Hoc | 136 | int net_type; 1 = Accesspoint ; 2 = Ad-Hoc |
93 | int ssid_len; Length of SSID | 137 | int ssid_len; Length of SSID |
94 | int channel; Channel | 138 | int channel; Channel |
95 | int wep; 1 = WEP enabled ; 0 = disabled | 139 | int wep; 1 = WEP enabled ; 0 = disabled |
96 | char mac[64]; MAC address of Accesspoint | 140 | char mac[64]; MAC address of Accesspoint |
97 | char bssid[128]; BSSID of Accesspoint | 141 | char bssid[128]; BSSID of Accesspoint |
98 | } wl_network_t; | 142 | } wl_network_t; |
99 | */ | 143 | */ |
100 | 144 | ||
101 | // qDebug( "Sniffer sent: '%s'", (const char*) buffer ); | 145 | qDebug( "Recv result: %d", ( result ) ); |
146 | qDebug( "Sniffer sent: '%s'", (const char*) buffer ); | ||
102 | hexwindow->log( (const char*) &buffer ); | 147 | hexwindow->log( (const char*) &buffer ); |
103 | 148 | ||
104 | if ( result == NETFOUND ) /* new network found */ | 149 | if ( command == NETFOUND ) /* new network found */ |
105 | { | 150 | { |
106 | qDebug( "Sniffer said: new network found." ); | 151 | qDebug( "Sniffer said: new network found." ); |
107 | wl_network_t n; | 152 | wl_network_t n; |
108 | get_network_found( &n, (char*) &buffer ); | 153 | get_network_found( &n, (char*) &buffer ); |
109 | 154 | ||
110 | qDebug( "Sniffer said: net_type is %d.", n.net_type ); | 155 | qDebug( "Sniffer said: net_type is %d.", n.net_type ); |
@@ -116,143 +161,46 @@ typedef struct { | |||
116 | 161 | ||
117 | if ( n.net_type == 1 ) | 162 | if ( n.net_type == 1 ) |
118 | type = "managed"; | 163 | type = "managed"; |
119 | else | 164 | else |
120 | type = "adhoc"; | 165 | type = "adhoc"; |
121 | 166 | ||
122 | addNewItem( type, n.bssid, QString( (const char*) &n.mac ), n.wep, n.channel, 0 ); | 167 | netview->addNewItem( type, n.bssid, QString( (const char*) &n.mac ), n.wep, n.channel, 0 ); |
123 | 168 | ||
124 | } | 169 | } |
125 | 170 | ||
126 | else | 171 | else |
127 | 172 | ||
128 | { | 173 | { |
129 | qDebug( "unknown sniffer command." ); | 174 | qDebug( "unknown sniffer command." ); |
130 | } | 175 | } |
131 | 176 | ||
132 | } | 177 | } |
133 | 178 | ||
134 | 179 | void Wellenreiter::dataReceived() | |
135 | bool Wellenreiter::hasMessage() | ||
136 | { | 180 | { |
137 | 181 | logwindow->log( "(d) Received data from daemon" ); | |
138 | // FIXME: do this in libwellenreiter, not here!!! | 182 | handleMessage(); |
139 | |||
140 | fd_set rfds; | ||
141 | FD_ZERO( &rfds ); | ||
142 | FD_SET( daemon_fd, &rfds ); | ||
143 | struct timeval tv; | ||
144 | tv.tv_sec = 0; | ||
145 | tv.tv_usec = 10; | ||
146 | int result = select( daemon_fd+1, &rfds, NULL, NULL, &tv ); | ||
147 | |||
148 | if ( result == 0 ) | ||
149 | { | ||
150 | return false; | ||
151 | } | ||
152 | else if ( result == -1 ) | ||
153 | { | ||
154 | qDebug( "selected returned: %s", strerror( errno ) ); | ||
155 | return false; | ||
156 | } | ||
157 | else | ||
158 | return true; //FD_ISSET( daemon_fd, &rfds ); gibbet 'eh nur einen Deskriptor | ||
159 | } | 183 | } |
160 | 184 | ||
161 | void Wellenreiter::timerEvent( QTimerEvent* e ) | 185 | void Wellenreiter::buttonClicked() |
162 | { | ||
163 | //qDebug( "checking for message..." ); | ||
164 | if ( hasMessage() ) | ||
165 | { | ||
166 | //qDebug( "got message from daemon" ); | ||
167 | handleMessage(); | ||
168 | } | ||
169 | else | ||
170 | { | ||
171 | //qDebug( "no message..." ); | ||
172 | } | ||
173 | } | ||
174 | |||
175 | void Wellenreiter::addNewItem( QString type, QString essid, QString macaddr, bool wep, int channel, int signal ) | ||
176 | { | 186 | { |
177 | // FIXME: this code belongs in customized QListView, not into this class | 187 | /* |
178 | // FIXME: scanlistitem needs a proper encapsulation and not such a damn dealing with text(...) | 188 | // add some test stations, so that we can see if the GUI part works |
179 | 189 | addNewItem( "managed", "Vanille", "04:00:20:EF:A6:43", true, 6, 80 ); | |
180 | qDebug( "Wellenreiter::addNewItem( %s / %s / %s [%d]", | 190 | addNewItem( "managed", "Vanille", "04:00:20:EF:A6:23", true, 11, 10 ); |
181 | (const char*) type, | 191 | addNewItem( "adhoc", "ELAN", "40:03:43:E7:16:22", false, 3, 10 ); |
182 | (const char*) essid, | 192 | addNewItem( "adhoc", "ELAN", "40:03:53:E7:56:62", false, 3, 15 ); |
183 | (const char*) macaddr, | 193 | addNewItem( "adhoc", "ELAN", "40:03:63:E7:56:E2", false, 3, 20 ); |
184 | channel ); | 194 | */ |
185 | |||
186 | // search, if we already have seen this net | ||
187 | |||
188 | QString s; | ||
189 | MScanListItem* network; | ||
190 | MScanListItem* item = static_cast<MScanListItem*> ( netview->firstChild() ); | ||
191 | |||
192 | while ( item && ( item->text( 0 ) != essid ) ) | ||
193 | { | ||
194 | qDebug( "itemtext: %s", (const char*) item->text( 0 ) ); | ||
195 | item = static_cast<MScanListItem*> ( item->itemBelow() ); | ||
196 | } | ||
197 | if ( item ) | ||
198 | { | ||
199 | // we have already seen this net, check all childs if MAC exists | ||
200 | |||
201 | network = item; | ||
202 | |||
203 | item = static_cast<MScanListItem*> ( item->firstChild() ); | ||
204 | assert( item ); // this shouldn't fail | ||
205 | |||
206 | while ( item && ( item->text( 2 ) != macaddr ) ) | ||
207 | { | ||
208 | qDebug( "subitemtext: %s", (const char*) item->text( 2 ) ); | ||
209 | item = static_cast<MScanListItem*> ( item->itemBelow() ); | ||
210 | } | ||
211 | |||
212 | if ( item ) | ||
213 | { | ||
214 | // we have already seen this item, it's a dupe | ||
215 | qDebug( "%s is a dupe - ignoring...", (const char*) macaddr ); | ||
216 | return; | ||
217 | } | ||
218 | } | ||
219 | else | ||
220 | { | ||
221 | s.sprintf( "(i) new network: '%s'", (const char*) essid ); | ||
222 | logwindow->log( s ); | ||
223 | |||
224 | network = new MScanListItem( netview, "networks", essid, QString::null, 0, 0, 0 ); | ||
225 | } | ||
226 | |||
227 | |||
228 | // insert new station as child from network | ||
229 | |||
230 | // no essid to reduce clutter, maybe later we have a nick or stationname to display!? | ||
231 | |||
232 | qDebug( "inserting new station %s", (const char*) macaddr ); | ||
233 | |||
234 | new MScanListItem( network, type, "", macaddr, wep, channel, signal ); | ||
235 | |||
236 | if ( type == "managed" ) | ||
237 | { | ||
238 | s.sprintf( "(i) new AP in '%s' [%d]", (const char*) essid, channel ); | ||
239 | } | ||
240 | else | ||
241 | { | ||
242 | s.sprintf( "(i) new adhoc station in '%s' [%d]", (const char*) essid, channel ); | ||
243 | } | ||
244 | |||
245 | logwindow->log( s ); | ||
246 | 195 | ||
247 | } | ||
248 | 196 | ||
249 | void Wellenreiter::buttonClicked() | ||
250 | { | ||
251 | if ( daemonRunning ) | 197 | if ( daemonRunning ) |
252 | { | 198 | { |
199 | daemonRunning = false; | ||
200 | |||
253 | logwindow->log( "(i) Daemon has been stopped." ); | 201 | logwindow->log( "(i) Daemon has been stopped." ); |
254 | button->setText( "Start Scanning" ); | 202 | button->setText( "Start Scanning" ); |
255 | 203 | ||
256 | // Stop daemon - ugly for now... later better | 204 | // Stop daemon - ugly for now... later better |
257 | 205 | ||
258 | system( "killall orinoco_hopper" ); | 206 | system( "killall orinoco_hopper" ); |
@@ -313,23 +261,8 @@ void Wellenreiter::buttonClicked() | |||
313 | cmdline += " &"; | 261 | cmdline += " &"; |
314 | 262 | ||
315 | qDebug( "execute: %s", (const char*) cmdline ); | 263 | qDebug( "execute: %s", (const char*) cmdline ); |
316 | system( cmdline ); | 264 | system( cmdline ); |
317 | qDebug( "done" ); | 265 | qDebug( "done" ); |
318 | 266 | ||
319 | /* | ||
320 | |||
321 | // add some test stations, so that we can see if the GUI part works | ||
322 | |||
323 | addNewItem( "managed", "Vanille", "04:00:20:EF:A6:43", true, 6, 80 ); | ||
324 | addNewItem( "managed", "Vanille", "04:00:20:EF:A6:23", true, 11, 10 ); | ||
325 | addNewItem( "adhoc", "ELAN", "40:03:43:E7:16:22", false, 3, 10 ); | ||
326 | addNewItem( "adhoc", "ELAN", "40:03:53:E7:56:62", false, 3, 15 ); | ||
327 | addNewItem( "adhoc", "ELAN", "40:03:63:E7:56:E2", false, 3, 20 ); | ||
328 | |||
329 | QString command ("98"); | ||
330 | |||
331 | //sendcomm( DAEMONADDR, DAEMONPORT, (const char*) command ); | ||
332 | |||
333 | */ | ||
334 | } | 267 | } |
335 | } | 268 | } |