-rw-r--r-- | noncore/net/wellenreiter/gui/wellenreiter.cpp | 13 |
1 files changed, 4 insertions, 9 deletions
diff --git a/noncore/net/wellenreiter/gui/wellenreiter.cpp b/noncore/net/wellenreiter/gui/wellenreiter.cpp index dd8a365..09a44e6 100644 --- a/noncore/net/wellenreiter/gui/wellenreiter.cpp +++ b/noncore/net/wellenreiter/gui/wellenreiter.cpp | |||
@@ -13,222 +13,217 @@ | |||
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> |
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 ) | 64 | Wellenreiter::Wellenreiter( QWidget* parent ) |
65 | : WellenreiterBase( parent, 0, 0 ), | 65 | : WellenreiterBase( parent, 0, 0 ), |
66 | daemonRunning( false ), manufacturerdb( 0 ), configwindow( 0 ) | 66 | daemonRunning( false ), manufacturerdb( 0 ), configwindow( 0 ) |
67 | { | 67 | { |
68 | 68 | ||
69 | // | 69 | // |
70 | // construct manufacturer database | 70 | // construct manufacturer database |
71 | // | 71 | // |
72 | 72 | ||
73 | QString manufile; | 73 | QString manufile; |
74 | #ifdef QWS | 74 | #ifdef QWS |
75 | manufile.sprintf( "%s/share/wellenreiter/manufacturers.dat", (const char*) QPEApplication::qpeDir() ); | 75 | manufile.sprintf( "%s/share/wellenreiter/manufacturers.dat", (const char*) QPEApplication::qpeDir() ); |
76 | #else | 76 | #else |
77 | manufile.sprintf( "/usr/local/share/wellenreiter/manufacturers.dat" ); | 77 | manufile.sprintf( "/usr/local/share/wellenreiter/manufacturers.dat" ); |
78 | #endif | 78 | #endif |
79 | manufacturerdb = new ManufacturerDB( manufile ); | 79 | manufacturerdb = new ManufacturerDB( manufile ); |
80 | 80 | ||
81 | logwindow->log( "(i) Wellenreiter has been started." ); | 81 | logwindow->log( "(i) Wellenreiter has been started." ); |
82 | 82 | ||
83 | // | 83 | // |
84 | // detect operating system | 84 | // detect operating system |
85 | // | 85 | // |
86 | 86 | ||
87 | #ifdef QWS | 87 | #ifdef QWS |
88 | QString sys; | 88 | QString sys; |
89 | sys.sprintf( "(i) Running on '%s'.", (const char*) ODevice::inst()->systemString() ); | 89 | sys.sprintf( "(i) Running on '%s'.", (const char*) ODevice::inst()->systemString() ); |
90 | _system = ODevice::inst()->system(); | 90 | _system = ODevice::inst()->system(); |
91 | logwindow->log( sys ); | 91 | logwindow->log( sys ); |
92 | #endif | 92 | #endif |
93 | 93 | ||
94 | // | 94 | // |
95 | // setup socket for daemon communication, register socket notifier | 95 | // setup socket for daemon communication, register socket notifier |
96 | // | 96 | // |
97 | 97 | ||
98 | // struct sockaddr_in sockaddr; | 98 | // struct sockaddr_in sockaddr; |
99 | daemon_fd = wl_setupsock( GUIADDR, GUIPORT, sockaddr ); | 99 | daemon_fd = wl_setupsock( GUIADDR, GUIPORT, sockaddr ); |
100 | if ( daemon_fd == -1 ) | 100 | if ( daemon_fd == -1 ) |
101 | { | 101 | { |
102 | logwindow->log( "(E) Couldn't get file descriptor for commsocket." ); | 102 | logwindow->log( "(E) Couldn't get file descriptor for commsocket." ); |
103 | } | 103 | } |
104 | else | 104 | else |
105 | { | 105 | { |
106 | int flags; | 106 | int flags; |
107 | flags = fcntl( daemon_fd, F_GETFL, 0 ); | 107 | flags = fcntl( daemon_fd, F_GETFL, 0 ); |
108 | fcntl( daemon_fd, F_SETFL, flags | O_NONBLOCK ); | 108 | fcntl( daemon_fd, F_SETFL, flags | O_NONBLOCK ); |
109 | QSocketNotifier *sn = new QSocketNotifier( daemon_fd, QSocketNotifier::Read, parent ); | 109 | QSocketNotifier *sn = new QSocketNotifier( daemon_fd, QSocketNotifier::Read, this ); |
110 | connect( sn, SIGNAL( activated( int ) ), this, SLOT( dataReceived() ) ); | 110 | connect( sn, SIGNAL( activated( int ) ), this, SLOT( dataReceived() ) ); |
111 | } | 111 | } |
112 | 112 | ||
113 | // setup GUI | 113 | // setup GUI |
114 | netview->setColumnWidthMode( 1, QListView::Manual ); | 114 | netview->setColumnWidthMode( 1, QListView::Manual ); |
115 | 115 | ||
116 | if ( manufacturerdb ) | 116 | if ( manufacturerdb ) |
117 | netview->setManufacturerDB( manufacturerdb ); | 117 | netview->setManufacturerDB( manufacturerdb ); |
118 | 118 | ||
119 | } | 119 | } |
120 | 120 | ||
121 | Wellenreiter::~Wellenreiter() | 121 | Wellenreiter::~Wellenreiter() |
122 | { | 122 | { |
123 | // 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 |
124 | 124 | ||
125 | delete manufacturerdb; | 125 | delete manufacturerdb; |
126 | 126 | ||
127 | // X11-only - Hmm... Closing the socket here segfaults on exit, | ||
128 | // Maybe because the notifier still has a handle to it!? Seems not to | ||
129 | // occur on Qt/Embedded | ||
130 | |||
131 | #ifdef QWS | ||
132 | if ( daemon_fd != -1 ) | 127 | if ( daemon_fd != -1 ) |
133 | { | 128 | { |
134 | qDebug( "closing comm socket" ); | 129 | qDebug( "closing comm socket" ); |
135 | close( daemon_fd ); | 130 | ::shutdown( daemon_fd, 0 ); |
131 | ::close( daemon_fd ); | ||
132 | qDebug( "comm socket closed." ); | ||
136 | } | 133 | } |
137 | #endif | ||
138 | |||
139 | } | 134 | } |
140 | 135 | ||
141 | void Wellenreiter::setConfigWindow( WellenreiterConfigWindow* cw ) | 136 | void Wellenreiter::setConfigWindow( WellenreiterConfigWindow* cw ) |
142 | { | 137 | { |
143 | configwindow = cw; | 138 | configwindow = cw; |
144 | } | 139 | } |
145 | 140 | ||
146 | void Wellenreiter::handleMessage() | 141 | void Wellenreiter::handleMessage() |
147 | { | 142 | { |
148 | // FIXME: receive message and handle it | 143 | // FIXME: receive message and handle it |
149 | 144 | ||
150 | qDebug( "received message from daemon." ); | 145 | qDebug( "received message from daemon." ); |
151 | 146 | ||
152 | /*char buffer[10000]; | 147 | /*char buffer[10000]; |
153 | memset( &buffer, 0, sizeof( buffer ) );*/ | 148 | memset( &buffer, 0, sizeof( buffer ) );*/ |
154 | 149 | ||
155 | char buffer[WL_SOCKBUF]; | 150 | char buffer[WL_SOCKBUF]; |
156 | 151 | ||
157 | // int result = #wl_recv( &daemon_fd, (char*) &buffer, sizeof(buffer) ); | 152 | // int result = #wl_recv( &daemon_fd, (char*) &buffer, sizeof(buffer) ); |
158 | 153 | ||
159 | /* | 154 | /* |
160 | 155 | ||
161 | struct sockaddr from; | 156 | struct sockaddr from; |
162 | socklen_t len; | 157 | socklen_t len; |
163 | 158 | ||
164 | int result = recvfrom( daemon_fd, &buffer, 8192, MSG_WAITALL, &from, &len ); | 159 | int result = recvfrom( daemon_fd, &buffer, 8192, MSG_WAITALL, &from, &len ); |
165 | qDebug( "received %d from recv [%d bytes]", result, len ); | 160 | qDebug( "received %d from recv [%d bytes]", result, len ); |
166 | 161 | ||
167 | */ | 162 | */ |
168 | 163 | ||
169 | int result = wl_recv( &daemon_fd, sockaddr, (char*) &buffer, WL_SOCKBUF ); | 164 | int result = wl_recv( &daemon_fd, sockaddr, (char*) &buffer, WL_SOCKBUF ); |
170 | 165 | ||
171 | if ( result == -1 ) | 166 | if ( result == -1 ) |
172 | { | 167 | { |
173 | qDebug( "Warning: %s", strerror( errno ) ); | 168 | qDebug( "Warning: %s", strerror( errno ) ); |
174 | return; | 169 | return; |
175 | } | 170 | } |
176 | 171 | ||
177 | int command = buffer[1] - 48; | 172 | int command = buffer[1] - 48; |
178 | 173 | ||
179 | /* | 174 | /* |
180 | typedef struct { | 175 | typedef struct { |
181 | int net_type; 1 = Accesspoint ; 2 = Ad-Hoc | 176 | int net_type; 1 = Accesspoint ; 2 = Ad-Hoc |
182 | int ssid_len; Length of SSID | 177 | int ssid_len; Length of SSID |
183 | int channel; Channel | 178 | int channel; Channel |
184 | int wep; 1 = WEP enabled ; 0 = disabled | 179 | int wep; 1 = WEP enabled ; 0 = disabled |
185 | char mac[64]; MAC address of Accesspoint | 180 | char mac[64]; MAC address of Accesspoint |
186 | char bssid[128]; BSSID of Accesspoint | 181 | char bssid[128]; BSSID of Accesspoint |
187 | } wl_network_t; | 182 | } wl_network_t; |
188 | */ | 183 | */ |
189 | 184 | ||
190 | qDebug( "Recv result: %d", ( result ) ); | 185 | qDebug( "Recv result: %d", ( result ) ); |
191 | qDebug( "Sniffer sent: '%s'", (const char*) buffer ); | 186 | qDebug( "Sniffer sent: '%s'", (const char*) buffer ); |
192 | hexwindow->log( (const char*) &buffer ); | 187 | hexwindow->log( (const char*) &buffer ); |
193 | 188 | ||
194 | if ( command == NETFOUND ) /* new network found */ | 189 | if ( command == NETFOUND ) /* new network found */ |
195 | { | 190 | { |
196 | qDebug( "Sniffer said: new network found." ); | 191 | qDebug( "Sniffer said: new network found." ); |
197 | wl_network_t n; | 192 | wl_network_t n; |
198 | get_network_found( &n, (char*) &buffer ); | 193 | get_network_found( &n, (char*) &buffer ); |
199 | 194 | ||
200 | qDebug( "Sniffer said: net_type is %d.", n.net_type ); | 195 | qDebug( "Sniffer said: net_type is %d.", n.net_type ); |
201 | qDebug( "Sniffer said: MAC is %s", (const char*) &n.mac ); | 196 | qDebug( "Sniffer said: MAC is %s", (const char*) &n.mac ); |
202 | 197 | ||
203 | //n.bssid[n.ssid_len] = "\0"; | 198 | //n.bssid[n.ssid_len] = "\0"; |
204 | 199 | ||
205 | QString type; | 200 | QString type; |
206 | 201 | ||
207 | if ( n.net_type == 1 ) | 202 | if ( n.net_type == 1 ) |
208 | type = "managed"; | 203 | type = "managed"; |
209 | else | 204 | else |
210 | type = "adhoc"; | 205 | type = "adhoc"; |
211 | 206 | ||
212 | netview->addNewItem( type, n.bssid, QString( (const char*) &n.mac ), n.wep, n.channel, 0 ); | 207 | netview->addNewItem( type, n.bssid, QString( (const char*) &n.mac ), n.wep, n.channel, 0 ); |
213 | 208 | ||
214 | } | 209 | } |
215 | 210 | ||
216 | else | 211 | else |
217 | 212 | ||
218 | { | 213 | { |
219 | qDebug( "unknown sniffer command." ); | 214 | qDebug( "unknown sniffer command." ); |
220 | } | 215 | } |
221 | 216 | ||
222 | } | 217 | } |
223 | 218 | ||
224 | void Wellenreiter::dataReceived() | 219 | void Wellenreiter::dataReceived() |
225 | { | 220 | { |
226 | logwindow->log( "(d) Received data from daemon" ); | 221 | logwindow->log( "(d) Received data from daemon" ); |
227 | handleMessage(); | 222 | handleMessage(); |
228 | } | 223 | } |
229 | 224 | ||
230 | void Wellenreiter::startStopClicked() | 225 | void Wellenreiter::startStopClicked() |
231 | { | 226 | { |
232 | if ( daemonRunning ) | 227 | if ( daemonRunning ) |
233 | { | 228 | { |
234 | daemonRunning = false; | 229 | daemonRunning = false; |