author | mickeyl <mickeyl> | 2002-08-14 23:55:37 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2002-08-14 23:55:37 (UTC) |
commit | f4fb50020242275a11f4b185ff843517e0862f9b (patch) (unidiff) | |
tree | 92a0fb73206a86faea9604edcc7666b968512389 | |
parent | 8951b45cfd2c0063e66d947346535f1af319d2a9 (diff) | |
download | opie-f4fb50020242275a11f4b185ff843517e0862f9b.zip opie-f4fb50020242275a11f4b185ff843517e0862f9b.tar.gz opie-f4fb50020242275a11f4b185ff843517e0862f9b.tar.bz2 |
Fixed damn bug causing wirelessapplet to hang Opie if /proc/net/wireless is not found (i.e. SHARP ROM or Desktop PC)
-rw-r--r-- | noncore/applets/wirelessapplet/networkinfo.cpp | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/noncore/applets/wirelessapplet/networkinfo.cpp b/noncore/applets/wirelessapplet/networkinfo.cpp index dc5c3be..22d7d83 100644 --- a/noncore/applets/wirelessapplet/networkinfo.cpp +++ b/noncore/applets/wirelessapplet/networkinfo.cpp | |||
@@ -111,157 +111,161 @@ void MWirelessNetworkInterface::updateStatistics() | |||
111 | const char* buffer[200]; | 111 | const char* buffer[200]; |
112 | 112 | ||
113 | struct iwreq iwr; | 113 | struct iwreq iwr; |
114 | memset( &iwr, 0, sizeof( iwr ) ); | 114 | memset( &iwr, 0, sizeof( iwr ) ); |
115 | iwr.u.essid.pointer = (caddr_t) buffer; | 115 | iwr.u.essid.pointer = (caddr_t) buffer; |
116 | iwr.u.essid.length = IW_ESSID_MAX_SIZE; | 116 | iwr.u.essid.length = IW_ESSID_MAX_SIZE; |
117 | iwr.u.essid.flags = 0; | 117 | iwr.u.essid.flags = 0; |
118 | 118 | ||
119 | // check if it is an IEEE 802.11 standard conform | 119 | // check if it is an IEEE 802.11 standard conform |
120 | // wireless device by sending SIOCGIWESSID | 120 | // wireless device by sending SIOCGIWESSID |
121 | // which also gives back the Extended Service Set ID | 121 | // which also gives back the Extended Service Set ID |
122 | // (see IEEE 802.11 for more information) | 122 | // (see IEEE 802.11 for more information) |
123 | 123 | ||
124 | strcpy( iwr.ifr_ifrn.ifrn_name, (const char*) name ); | 124 | strcpy( iwr.ifr_ifrn.ifrn_name, (const char*) name ); |
125 | int result = ioctl( fd, SIOCGIWESSID, &iwr ); | 125 | int result = ioctl( fd, SIOCGIWESSID, &iwr ); |
126 | if ( result == 0 ) | 126 | if ( result == 0 ) |
127 | { | 127 | { |
128 | hasWirelessExtensions = true; | 128 | hasWirelessExtensions = true; |
129 | iwr.u.essid.pointer[(unsigned int) iwr.u.essid.length-1] = '\0'; | 129 | iwr.u.essid.pointer[(unsigned int) iwr.u.essid.length-1] = '\0'; |
130 | essid = iwr.u.essid.pointer; | 130 | essid = iwr.u.essid.pointer; |
131 | } | 131 | } |
132 | else essid = "*** Unknown ***"; | 132 | else essid = "*** Unknown ***"; |
133 | 133 | ||
134 | // Address of associated access-point | 134 | // Address of associated access-point |
135 | 135 | ||
136 | result = ioctl( fd, SIOCGIWAP, &iwr ); | 136 | result = ioctl( fd, SIOCGIWAP, &iwr ); |
137 | if ( result == 0 ) | 137 | if ( result == 0 ) |
138 | { | 138 | { |
139 | APAddr.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", | 139 | APAddr.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", |
140 | iwr.u.ap_addr.sa_data[0]&0xff, | 140 | iwr.u.ap_addr.sa_data[0]&0xff, |
141 | iwr.u.ap_addr.sa_data[1]&0xff, | 141 | iwr.u.ap_addr.sa_data[1]&0xff, |
142 | iwr.u.ap_addr.sa_data[2]&0xff, | 142 | iwr.u.ap_addr.sa_data[2]&0xff, |
143 | iwr.u.ap_addr.sa_data[3]&0xff, | 143 | iwr.u.ap_addr.sa_data[3]&0xff, |
144 | iwr.u.ap_addr.sa_data[4]&0xff, | 144 | iwr.u.ap_addr.sa_data[4]&0xff, |
145 | iwr.u.ap_addr.sa_data[5]&0xff ); | 145 | iwr.u.ap_addr.sa_data[5]&0xff ); |
146 | } else APAddr = "*** Unknown ***"; | 146 | } else APAddr = "*** Unknown ***"; |
147 | 147 | ||
148 | iwr.u.data.pointer = (caddr_t) buffer; | 148 | iwr.u.data.pointer = (caddr_t) buffer; |
149 | iwr.u.data.length = IW_ESSID_MAX_SIZE; | 149 | iwr.u.data.length = IW_ESSID_MAX_SIZE; |
150 | iwr.u.data.flags = 0; | 150 | iwr.u.data.flags = 0; |
151 | 151 | ||
152 | result = ioctl( fd, SIOCGIWNICKN, &iwr ); | 152 | result = ioctl( fd, SIOCGIWNICKN, &iwr ); |
153 | if ( result == 0 ) | 153 | if ( result == 0 ) |
154 | { | 154 | { |
155 | iwr.u.data.pointer[(unsigned int) iwr.u.data.length-1] = '\0'; | 155 | iwr.u.data.pointer[(unsigned int) iwr.u.data.length-1] = '\0'; |
156 | nick = iwr.u.data.pointer; | 156 | nick = iwr.u.data.pointer; |
157 | } else nick = "*** Unknown ***"; | 157 | } else nick = "*** Unknown ***"; |
158 | 158 | ||
159 | result = ioctl( fd, SIOCGIWMODE, &iwr ); | 159 | result = ioctl( fd, SIOCGIWMODE, &iwr ); |
160 | if ( result == 0 ) | 160 | if ( result == 0 ) |
161 | mode = ( iwr.u.mode == IW_MODE_ADHOC ) ? "Ad-Hoc" : "Managed"; | 161 | mode = ( iwr.u.mode == IW_MODE_ADHOC ) ? "Ad-Hoc" : "Managed"; |
162 | else mode = "*** Unknown ***"; | 162 | else mode = "*** Unknown ***"; |
163 | 163 | ||
164 | result = ioctl( fd, SIOCGIWFREQ, &iwr ); | 164 | result = ioctl( fd, SIOCGIWFREQ, &iwr ); |
165 | if ( result == 0 ) | 165 | if ( result == 0 ) |
166 | freq = double( iwr.u.freq.m ) * pow( 10, iwr.u.freq.e ) / 1000000000; | 166 | freq = double( iwr.u.freq.m ) * pow( 10, iwr.u.freq.e ) / 1000000000; |
167 | else freq = 0; | 167 | else freq = 0; |
168 | 168 | ||
169 | // gather link quality from /proc/net/wireless | 169 | // gather link quality from /proc/net/wireless |
170 | 170 | ||
171 | char c; | 171 | char c; |
172 | QString status; | 172 | QString status; |
173 | QString name; | 173 | QString name; |
174 | QFile wfile( PROCNETWIRELESS ); | 174 | QFile wfile( PROCNETWIRELESS ); |
175 | wfile.open( IO_ReadOnly ); | 175 | bool hasFile = wfile.open( IO_ReadOnly ); |
176 | QTextStream wstream( &wfile ); | 176 | QTextStream wstream( &wfile ); |
177 | wstream.readLine(); // skip the first two lines | 177 | if ( hasFile ) |
178 | wstream.readLine(); // because they only contain headers | 178 | { |
179 | 179 | wstream.readLine(); // skip the first two lines | |
180 | if ( wstream.atEnd() ) | 180 | wstream.readLine(); // because they only contain headers |
181 | } | ||
182 | if ( ( !hasFile ) || ( wstream.atEnd() ) ) | ||
181 | { | 183 | { |
182 | qDebug( "WIFIAPPLET: D'oh! Someone removed the card..." ); | 184 | qDebug( "WIFIAPPLET: D'oh! Someone removed the card..." ); |
183 | quality = -1; | 185 | quality = -1; |
184 | signal = IW_LOWER; | 186 | signal = IW_LOWER; |
185 | noise = IW_LOWER; | 187 | noise = IW_LOWER; |
186 | return; | 188 | return; |
187 | } | 189 | } |
188 | 190 | ||
189 | wstream >> name >> status >> quality >> c >> signal >> c >> noise; | 191 | wstream >> name >> status >> quality >> c >> signal >> c >> noise; |
190 | 192 | ||
191 | if ( quality > 92 ) | 193 | if ( quality > 92 ) |
192 | qDebug( "WIFIAPPLET: D'oh! Quality %d > estimated max!\n", quality ); | 194 | qDebug( "WIFIAPPLET: D'oh! Quality %d > estimated max!\n", quality ); |
193 | if ( ( signal > IW_UPPER ) || ( signal < IW_LOWER ) ) | 195 | if ( ( signal > IW_UPPER ) || ( signal < IW_LOWER ) ) |
194 | qDebug( "WIFIAPPLET: Doh! Strength %d > estimated max!\n", signal ); | 196 | qDebug( "WIFIAPPLET: Doh! Strength %d > estimated max!\n", signal ); |
195 | if ( ( noise > IW_UPPER ) || ( noise < IW_LOWER ) ) | 197 | if ( ( noise > IW_UPPER ) || ( noise < IW_LOWER ) ) |
196 | qDebug( "WIFIAPPLET: Doh! Noise %d > estimated max!\n", noise ); | 198 | qDebug( "WIFIAPPLET: Doh! Noise %d > estimated max!\n", noise ); |
197 | } | 199 | } |
198 | 200 | ||
199 | //--------------------------------------------------------------------------- | 201 | //--------------------------------------------------------------------------- |
200 | // class Network | 202 | // class Network |
201 | // | 203 | // |
202 | 204 | ||
203 | MNetwork::MNetwork() | 205 | MNetwork::MNetwork() |
204 | { | 206 | { |
205 | qDebug( "MNetwork::MNetwork()" ); | 207 | //qDebug( "MNetwork::MNetwork()" ); |
206 | procfile = "/proc/net/dev"; | 208 | procfile = PROCNETDEV; |
207 | } | 209 | } |
208 | 210 | ||
209 | MNetwork::~MNetwork() | 211 | MNetwork::~MNetwork() |
210 | { | 212 | { |
211 | qDebug( "MNetwork::~MNetwork()" ); | 213 | //qDebug( "MNetwork::~MNetwork()" ); |
212 | } | 214 | } |
213 | 215 | ||
214 | //--------------------------------------------------------------------------- | 216 | //--------------------------------------------------------------------------- |
215 | // class WirelessNetwork | 217 | // class WirelessNetwork |
216 | // | 218 | // |
217 | 219 | ||
218 | MWirelessNetwork::MWirelessNetwork() | 220 | MWirelessNetwork::MWirelessNetwork() |
219 | { | 221 | { |
220 | qDebug( "MWirelessNetwork::MWirelessNetwork()" ); | 222 | //qDebug( "MWirelessNetwork::MWirelessNetwork()" ); |
221 | procfile = "/proc/net/wireless"; | 223 | procfile = PROCNETWIRELESS; |
222 | } | 224 | } |
223 | 225 | ||
224 | MWirelessNetwork::~MWirelessNetwork() | 226 | MWirelessNetwork::~MWirelessNetwork() |
225 | { | 227 | { |
226 | qDebug( "MWirelessNetwork::~MWirelessNetwork()" ); | 228 | //qDebug( "MWirelessNetwork::~MWirelessNetwork()" ); |
227 | } | 229 | } |
228 | 230 | ||
229 | MNetworkInterface* MWirelessNetwork::createInterface( const char* n ) const | 231 | MNetworkInterface* MWirelessNetwork::createInterface( const char* n ) const |
230 | { | 232 | { |
231 | return new MWirelessNetworkInterface( n ); | 233 | return new MWirelessNetworkInterface( n ); |
232 | } | 234 | } |
233 | 235 | ||
234 | //--------------------------------------------------------------------------- | 236 | //--------------------------------------------------------------------------- |
235 | // class NetworkInterface | 237 | // class NetworkInterface |
236 | // | 238 | // |
237 | 239 | ||
238 | MNetworkInterface* MNetwork::getFirstInterface() | 240 | MNetworkInterface* MNetwork::getFirstInterface() |
239 | { | 241 | { |
240 | enumerateInterfaces(); | 242 | enumerateInterfaces(); |
241 | InterfaceMapIterator it( interfaces ); | 243 | InterfaceMapIterator it( interfaces ); |
242 | return ( it.count() > 0 ) ? it.toFirst() : 0; | 244 | return ( it.count() > 0 ) ? it.toFirst() : 0; |
243 | } | 245 | } |
244 | 246 | ||
245 | void MNetwork::enumerateInterfaces() | 247 | void MNetwork::enumerateInterfaces() |
246 | { | 248 | { |
247 | interfaces.clear(); | 249 | interfaces.clear(); |
248 | QString str; | 250 | QString str; |
249 | QFile f( procfile ); | 251 | QFile f( procfile ); |
250 | f.open( IO_ReadOnly ); | 252 | bool hasFile = f.open( IO_ReadOnly ); |
253 | if ( !hasFile ) | ||
254 | return; | ||
251 | QTextStream s( &f ); | 255 | QTextStream s( &f ); |
252 | s.readLine(); | 256 | s.readLine(); |
253 | s.readLine(); | 257 | s.readLine(); |
254 | while ( !s.atEnd() ) | 258 | while ( !s.atEnd() ) |
255 | { | 259 | { |
256 | s >> str; | 260 | s >> str; |
257 | str.truncate( str.find( ':' ) ); | 261 | str.truncate( str.find( ':' ) ); |
258 | qDebug( "WIFIAPPLET: found interface '%s'", (const char*) str ); | 262 | qDebug( "WIFIAPPLET: found interface '%s'", (const char*) str ); |
259 | interfaces.insert( str, createInterface( str ) ); | 263 | interfaces.insert( str, createInterface( str ) ); |
260 | s.readLine(); | 264 | s.readLine(); |
261 | } | 265 | } |
262 | } | 266 | } |
263 | 267 | ||
264 | MNetworkInterface* MNetwork::createInterface( const char* n ) const | 268 | MNetworkInterface* MNetwork::createInterface( const char* n ) const |
265 | { | 269 | { |
266 | return new MNetworkInterface( n ); | 270 | return new MNetworkInterface( n ); |
267 | } | 271 | } |