|
1 /* |
|
2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Provides an interface to WLAN Engine. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <e32base.h> |
|
19 #include <utf.h> |
|
20 |
|
21 #include "CWlanSupport.h" |
|
22 #include "CEventQueue.h" |
|
23 #include "ConnMonIAP.h" |
|
24 #include "ConnMonAvailabilityManager.h" |
|
25 #include "connmoncommsdatcache.h" |
|
26 #include "log.h" |
|
27 #include "ConnMonUtils.h" |
|
28 #include "connmonwlannetwork.h" |
|
29 |
|
30 |
|
31 // ============================ MEMBER FUNCTIONS =============================== |
|
32 |
|
33 // ----------------------------------------------------------------------------- |
|
34 // CWlanSupport::NewL |
|
35 // ----------------------------------------------------------------------------- |
|
36 // |
|
37 CWlanSupport* CWlanSupport::NewL( CConnMonServer* aServer ) |
|
38 { |
|
39 //LOGENTRFN("CWlanSupport::NewL()") |
|
40 CWlanSupport* self = new( ELeave ) CWlanSupport( aServer ); |
|
41 |
|
42 CleanupStack::PushL( self ); |
|
43 self->ConstructL(); |
|
44 CleanupStack::Pop( self ); |
|
45 |
|
46 //LOGEXITFN("CWlanSupport::NewL()") |
|
47 return self; |
|
48 } |
|
49 |
|
50 // ----------------------------------------------------------------------------- |
|
51 // CWlanSupport::CWlanSupport |
|
52 // ----------------------------------------------------------------------------- |
|
53 // |
|
54 CWlanSupport::CWlanSupport( |
|
55 CConnMonServer* aServer ) |
|
56 : |
|
57 iServer( aServer ), |
|
58 iEnableScan( ETrue ), |
|
59 iEnableEventsToClients( EFalse ) |
|
60 { |
|
61 // iEnableScan has to be initialized to ETrue, so iAvailableWlanIapsCache will be initialized |
|
62 // properly when WLAN IAP availability is asked for the first time. |
|
63 } |
|
64 |
|
65 // ----------------------------------------------------------------------------- |
|
66 // CWlanSupport::ConstructL |
|
67 // ----------------------------------------------------------------------------- |
|
68 // |
|
69 void CWlanSupport::ConstructL() |
|
70 { |
|
71 iWlanMgmt = CWlanMgmtClient::NewL(); |
|
72 ActivateNotificationsL(); |
|
73 } |
|
74 |
|
75 // ----------------------------------------------------------------------------- |
|
76 // Destructor |
|
77 // ----------------------------------------------------------------------------- |
|
78 // |
|
79 CWlanSupport::~CWlanSupport() |
|
80 { |
|
81 CancelNotifications(); // Deletes iEventWatcher |
|
82 |
|
83 delete iWlanMgmt; |
|
84 iWlanMgmt = NULL; |
|
85 |
|
86 // Cleanup WLAN IAPs cache array |
|
87 iAvailableWlanIapsCache.Close(); |
|
88 |
|
89 // Cleanup WLAN sessions pointer array |
|
90 iWlanSessionsPtrArray.ResetAndDestroy(); |
|
91 } |
|
92 |
|
93 |
|
94 // ----------------------------------------------------------------------------- |
|
95 // CWlanSupport::GetBearerAvailabilityL |
|
96 // Called from CWlanEvent::OldNetworksLost |
|
97 // ----------------------------------------------------------------------------- |
|
98 // |
|
99 void CWlanSupport::GetBearerAvailabilityL( TBool& aAvailability ) |
|
100 { |
|
101 LOGENTRFN("CWlanSupport::GetBearerAvailabilityL()") |
|
102 aAvailability = EFalse; |
|
103 |
|
104 // Check if connection exists |
|
105 TInt mode( 0 ); |
|
106 TInt ret = GetConnectionMode( mode ); |
|
107 if ( KErrNone == ret ) |
|
108 { |
|
109 // An active WLAN connection exists. |
|
110 aAvailability = ETrue; |
|
111 } |
|
112 else // No active WLAN connections... Scan WLAN networks |
|
113 { |
|
114 CWlanScanInfo* scanInfo = CWlanScanInfo::NewL(); |
|
115 CleanupStack::PushL( scanInfo ); |
|
116 |
|
117 // Get scan results without parameters |
|
118 ret = iWlanMgmt->GetScanResults( *scanInfo ); |
|
119 if ( KErrNone == ret ) |
|
120 { |
|
121 // Check scan results |
|
122 if ( scanInfo->IsDone() ) |
|
123 { |
|
124 // Empty scan info, no WLAN networks available |
|
125 aAvailability = EFalse; |
|
126 } |
|
127 else |
|
128 { |
|
129 // WLAN networks found |
|
130 aAvailability = ETrue; |
|
131 } |
|
132 } |
|
133 else |
|
134 { |
|
135 LOGIT1("GetBearerAvailabilityL: GetScanResults error <%d>", ret) |
|
136 User::Leave( ret ); |
|
137 } |
|
138 |
|
139 CleanupStack::PopAndDestroy( scanInfo ); |
|
140 } |
|
141 |
|
142 LOGEXITFN("CWlanSupport::GetBearerAvailabilityL()") |
|
143 } |
|
144 |
|
145 // ----------------------------------------------------------------------------- |
|
146 // CWlanSupport::GetBearerAvailabilityL |
|
147 // ----------------------------------------------------------------------------- |
|
148 // |
|
149 TInt CWlanSupport::GetBearerAvailabilityL( const RMessage2& aMessage, TBool& aAvailability ) |
|
150 { |
|
151 LOGENTRFN("CWlanSupport::GetBearerAvailabilityL()") |
|
152 TInt result( KErrNone ); |
|
153 aAvailability = EFalse; |
|
154 |
|
155 // Check if event watcher has the availability information |
|
156 TBool eventWatcherKnowsAvailability( EFalse ); |
|
157 if ( iEventWatcher ) |
|
158 { |
|
159 eventWatcherKnowsAvailability = iEventWatcher->HasAvailabilityKnowledge(); |
|
160 } |
|
161 |
|
162 // Use WLAN bearer availability info from event watcher if possible. |
|
163 if ( eventWatcherKnowsAvailability ) |
|
164 { |
|
165 aAvailability = iEventWatcher->WlanAvailability(); |
|
166 result = KErrNone; |
|
167 } |
|
168 else |
|
169 { |
|
170 // Check if a WLAN connection exists |
|
171 TInt mode( 0 ); |
|
172 TInt ret = GetConnectionMode( mode ); |
|
173 if ( KErrNone == ret ) |
|
174 { |
|
175 // An active WLAN connection equals bearer availability. |
|
176 aAvailability = ETrue; |
|
177 result = KErrNone; |
|
178 } |
|
179 else // No active WLAN connections... Scan WLAN networks |
|
180 { |
|
181 // Add session to wlan session table (if not already there) |
|
182 TInt index = AddWlanSessionL( aMessage ); |
|
183 iWlanSessionsPtrArray[index]->GetScanResultsL( aMessage ); |
|
184 result = KRequestPending; |
|
185 } |
|
186 } |
|
187 |
|
188 LOGEXITFN1("CWlanSupport::GetBearerAvailabilityL()", result) |
|
189 return result; |
|
190 } |
|
191 |
|
192 |
|
193 // ----------------------------------------------------------------------------- |
|
194 // CWlanSupport::GetSignalStrength |
|
195 // ----------------------------------------------------------------------------- |
|
196 // |
|
197 TInt CWlanSupport::GetSignalStrengthL( |
|
198 const RMessage2& aMessage, |
|
199 TInt& aSignalStrength ) |
|
200 { |
|
201 LOGENTRFN("CWlanSupport::GetSignalStrengthL()") |
|
202 TInt result( KErrNone ); |
|
203 TInt mode( 0 ); |
|
204 aSignalStrength = 0; |
|
205 |
|
206 // Get connection mode to see if connection exists |
|
207 TInt ret = GetConnectionMode( mode ); |
|
208 if ( KErrNone == ret ) |
|
209 { |
|
210 // An active WLAN connection exists -> get signal quality |
|
211 result = GetConnectionSignalQuality( aSignalStrength ); |
|
212 } |
|
213 else // No connection -> scan networks |
|
214 { |
|
215 // Add session to wlan session table (if not already there) |
|
216 TInt index = AddWlanSessionL( aMessage ); |
|
217 iWlanSessionsPtrArray[index]->GetScanResultsL( aMessage ); |
|
218 result = KRequestPending; |
|
219 } |
|
220 |
|
221 LOGEXITFN1("CWlanSupport::GetSignalStrengthL()", result) |
|
222 return result; |
|
223 } |
|
224 |
|
225 // ----------------------------------------------------------------------------- |
|
226 // CWlanSupport::GetNetworkNamesL |
|
227 // ----------------------------------------------------------------------------- |
|
228 // |
|
229 TInt CWlanSupport::GetNetworkNamesL( const RMessage2& aMessage ) |
|
230 { |
|
231 LOGENTRFN("CWlanSupport::GetNetworkNamesL()") |
|
232 |
|
233 // Add session to wlan session table (if not already there) |
|
234 TInt index = AddWlanSessionL( aMessage ); |
|
235 iWlanSessionsPtrArray[index]->GetScanResultsL( aMessage ); |
|
236 |
|
237 LOGEXITFN1("CWlanSupport::GetNetworkNamesL()", KRequestPending) |
|
238 return KRequestPending; |
|
239 } |
|
240 |
|
241 |
|
242 // ----------------------------------------------------------------------------- |
|
243 // CWlanSupport::ParseNetworkNamesL |
|
244 // ----------------------------------------------------------------------------- |
|
245 // |
|
246 void CWlanSupport::ParseNetworkNamesL( |
|
247 CWlanScanInfo* aScanInfo, |
|
248 TConnMonNetworkNames& aNetInfo ) |
|
249 { |
|
250 LOGENTRFN("CWlanSupport::ParseNetworkNamesL()") |
|
251 |
|
252 TInt ret( KErrNone ); |
|
253 RArray< TConnMonNetwork > sortedNetworkNames; |
|
254 CleanupClosePushL( sortedNetworkNames ); |
|
255 aNetInfo.iCount = 0; |
|
256 |
|
257 // For logging only |
|
258 LOG(TInt count(0);) |
|
259 LOGIT("Parsing networks:") |
|
260 |
|
261 // Iterate through scan results. |
|
262 for ( aScanInfo->First(); !aScanInfo->IsDone(); aScanInfo->Next() ) |
|
263 { |
|
264 TConnMonNetwork nw; |
|
265 |
|
266 // Operating mode |
|
267 if ( aScanInfo->Capability() & KWlan802Dot11CapabilityEssMask ) |
|
268 { |
|
269 nw.iType = EConnMonInfraStructure; |
|
270 } |
|
271 else |
|
272 { |
|
273 nw.iType = EConnMonAdHoc; |
|
274 } |
|
275 |
|
276 // Signal strength |
|
277 nw.iSignalStrength = aScanInfo->RXLevel(); |
|
278 |
|
279 // SSID |
|
280 TUint8 ieLen( 0 ); |
|
281 const TUint8* ieData( NULL ); |
|
282 ret = aScanInfo->InformationElement( KWlan802Dot11SsidIE, ieLen, &ieData ); |
|
283 if ( ( KErrNone == ret ) && ( ieLen <= CConnMonWlanNetwork::KMaxNameLength ) ) |
|
284 { |
|
285 // ieData points to the beginning of the 802.11 SSID payload data i.e. |
|
286 // the header is bypassed. ieLen contains the length of payload data. |
|
287 nw.iName.Copy( ieData, ieLen ); |
|
288 } |
|
289 |
|
290 sortedNetworkNames.InsertInOrderAllowRepeatsL( nw, CWlanSupport::CompareNetworkStrengths ); |
|
291 |
|
292 #ifdef _DEBUG |
|
293 // Print network information to log |
|
294 count++; |
|
295 if ( ( KErrNone == ret ) && ( ieLen <= CConnMonWlanNetwork::KMaxNameLength ) ) |
|
296 { |
|
297 TBuf<CConnMonWlanNetwork::KMaxNameLength+1> debug_name; |
|
298 ConnMonUtils::TDes8ToTDes( nw.iName, debug_name ); |
|
299 TWlanBssid bssid; |
|
300 aScanInfo->Bssid( bssid ); |
|
301 LOGIT11("%02d: %02X:%02X:%02X:%02X:%02X:%02X sig.str %d, type %d, name(%02d): %s", |
|
302 count, bssid[0], bssid[1], bssid[2], bssid[3], bssid[4], bssid[5], |
|
303 nw.iSignalStrength, nw.iType, debug_name.Length(), debug_name.PtrZ()) |
|
304 } |
|
305 #endif // _DEBUG |
|
306 } // for |
|
307 |
|
308 // Go through the items one by one starting from the largest signal strength. |
|
309 // Always uses the first item in array, since it is removed in the end of loop. |
|
310 while ( sortedNetworkNames.Count() > 0 && aNetInfo.iCount < KConnMonMaxNetworkCount ) |
|
311 { |
|
312 TConnMonNetwork &item( sortedNetworkNames[0] ); |
|
313 |
|
314 TBool duplicate( EFalse ); |
|
315 for ( TUint i = 0; i < aNetInfo.iCount; i++ ) |
|
316 { |
|
317 if ( aNetInfo.iNetwork[i].iType == item.iType && |
|
318 aNetInfo.iNetwork[i].iName == item.iName ) |
|
319 { |
|
320 duplicate = ETrue; |
|
321 } |
|
322 } |
|
323 if ( !duplicate ) |
|
324 { |
|
325 // Adding the item |
|
326 aNetInfo.iNetwork[aNetInfo.iCount].iType = item.iType; |
|
327 aNetInfo.iNetwork[aNetInfo.iCount].iSignalStrength = item.iSignalStrength; |
|
328 aNetInfo.iNetwork[aNetInfo.iCount].iName.Copy( item.iName ); |
|
329 #ifdef _DEBUG |
|
330 // One letter longer than max WLAN network name, since we are adding a '\0' when printing |
|
331 TBuf<CConnMonWlanNetwork::KMaxNameLength+1> name; |
|
332 ConnMonUtils::TDes8ToTDes( aNetInfo.iNetwork[aNetInfo.iCount].iName, name ); |
|
333 LOGIT3("Added network %.2d, sig.str %d, name: %s", |
|
334 aNetInfo.iCount, |
|
335 aNetInfo.iNetwork[aNetInfo.iCount].iSignalStrength, |
|
336 name.PtrZ()) |
|
337 #endif // _DEBUG |
|
338 aNetInfo.iCount++; |
|
339 } |
|
340 |
|
341 sortedNetworkNames.Remove( 0 ); |
|
342 } |
|
343 |
|
344 CleanupStack::PopAndDestroy( &sortedNetworkNames ); |
|
345 |
|
346 LOGEXITFN("CWlanSupport::ParseNetworkNamesL()") |
|
347 } |
|
348 |
|
349 |
|
350 // ----------------------------------------------------------------------------- |
|
351 // CWlanSupport::CompareNetworkStrengths |
|
352 // |
|
353 // Compares two WLAN network signal strengths. |
|
354 // It should return: |
|
355 // 1. zero, if the two objects are equal. |
|
356 // 2. a negative value, if the first object is less than the second. |
|
357 // 3. a positive value, if the first object is greater than the second. |
|
358 // ----------------------------------------------------------------------------- |
|
359 // |
|
360 TInt CWlanSupport::CompareNetworkStrengths( |
|
361 const TConnMonNetwork& aFirst, |
|
362 const TConnMonNetwork& aSecond ) |
|
363 { |
|
364 //LOGENTRFN("CWlanSupport::CompareNetworkStrengths()") |
|
365 TInt result( 0 ); |
|
366 |
|
367 if ( aFirst.iSignalStrength < aSecond.iSignalStrength ) |
|
368 { |
|
369 result = -1; |
|
370 } |
|
371 else if ( aFirst.iSignalStrength > aSecond.iSignalStrength ) |
|
372 { |
|
373 result = 1; |
|
374 } |
|
375 |
|
376 //LOGEXITFN1("CWlanSupport::CompareNetworkStrengths()", result) |
|
377 return result; |
|
378 } |
|
379 |
|
380 // ----------------------------------------------------------------------------- |
|
381 // CWlanSupport::AppendAvailableIaps |
|
382 // ----------------------------------------------------------------------------- |
|
383 // |
|
384 TInt CWlanSupport::AppendAvailableIaps( RArray<TUint>& aIdArray ) |
|
385 { |
|
386 //LOGENTRFN("CWlanSupport::AppendAvailableIaps()") |
|
387 TInt err( KErrNone ); |
|
388 |
|
389 if ( iEnableScan ) |
|
390 { |
|
391 iAvailableWlanIapsCache.Reset(); |
|
392 err = iWlanMgmt->GetAvailableIaps( iAvailableWlanIapsCache ); |
|
393 LOGIT2("WLAN IAPs available: %d, err <%d> (from WLAN engine)", iAvailableWlanIapsCache.Count(), err) |
|
394 iEnableScan = EFalse; |
|
395 } |
|
396 else |
|
397 { |
|
398 LOGIT1("WLAN IAPs available: %d (from cache, no scan)", iAvailableWlanIapsCache.Count()) |
|
399 } |
|
400 |
|
401 const TInt wlanIapCount( iAvailableWlanIapsCache.Count() ); |
|
402 if ( KErrNone == err && wlanIapCount > 0 ) |
|
403 { |
|
404 for ( TInt i = 0; i < wlanIapCount; i++ ) |
|
405 { |
|
406 err = aIdArray.Append( iAvailableWlanIapsCache[i] ); |
|
407 if ( err ) |
|
408 { |
|
409 break; |
|
410 } |
|
411 } |
|
412 } |
|
413 |
|
414 //LOGEXITFN1("CWlanSupport::AppendAvailableIaps()", err) |
|
415 return err; |
|
416 } |
|
417 |
|
418 // ----------------------------------------------------------------------------- |
|
419 // CWlanSupport::AppendAvailableIapsBySsid |
|
420 // ----------------------------------------------------------------------------- |
|
421 // |
|
422 TInt CWlanSupport::AppendAvailableIapsBySsidL( RArray<TUint>& aIdArray ) |
|
423 { |
|
424 LOGENTRFN("CWlanSupport::AppendAvailableIapsBySsidL()") |
|
425 TInt ret( KErrNone ); |
|
426 |
|
427 // Get ssid of current connection |
|
428 TWlanSsid currentSsid; |
|
429 ret = iWlanMgmt->GetConnectionSsid( currentSsid ); |
|
430 if ( KErrNone != ret ) |
|
431 { |
|
432 LOGIT1("ERROR reading current connection ssid from wlan engine <%d>", ret) |
|
433 ret = KErrDisconnected; |
|
434 } |
|
435 else |
|
436 { |
|
437 LOGTIMINGSTART("CWlanSupport::AppendAvailableIapsBySsidL") |
|
438 |
|
439 // Create a session with the latest version CommsDat |
|
440 CMDBSession* db = CMDBSession::NewLC( CMDBSession::LatestVersion() ); |
|
441 db->SetAttributeMask( ECDProtectedWrite ); |
|
442 |
|
443 TBuf<CConnMonWlanNetwork::KMaxNameLength> ssid16; |
|
444 CnvUtfConverter::ConvertToUnicodeFromUtf8( ssid16, currentSsid ); |
|
445 LOGIT2("AppendAvailableIapsBySsidL: ssid: %S, length: %d", &ssid16, ssid16.Length()) |
|
446 |
|
447 // Create wlan service record set |
|
448 CMDBRecordSet<CCDWlanServiceRecord>* wlanSet = |
|
449 new( ELeave ) CMDBRecordSet<CCDWlanServiceRecord>( |
|
450 CCDWlanServiceRecord::TableIdL( *db ) ); |
|
451 CleanupStack::PushL( wlanSet ); |
|
452 |
|
453 // Create wlan service record |
|
454 CCDWlanServiceRecord* wlanRecord = |
|
455 new( ELeave ) CCDWlanServiceRecord( CCDWlanServiceRecord::TableIdL( *db ) ); |
|
456 CleanupStack::PushL( wlanRecord ); |
|
457 |
|
458 // Set ssid field in wlan service record (see wlancontainer.h) |
|
459 wlanRecord->iWLanSSID.SetL( ssid16 ); |
|
460 // Append wlan service record to wlan service record set (currently empty) |
|
461 wlanSet->iRecords.AppendL( wlanRecord ); |
|
462 CleanupStack::Pop( wlanRecord ); // Ownership moved |
|
463 |
|
464 // Find matching wlan service records (all wlan service records with same SSID) |
|
465 if ( wlanSet->FindL( *db ) ) |
|
466 { |
|
467 TInt wlanRecordCount( wlanSet->iRecords.Count() ); |
|
468 LOGIT1("AppendAvailableIapsBySsidL: wlan record count: %d", wlanRecordCount) |
|
469 |
|
470 // Loop for each record found |
|
471 for ( TInt i = 0; i < wlanRecordCount; i++ ) |
|
472 { |
|
473 // Load current record to make sure all fields are up to date |
|
474 // LoadL() will only look at ElementId and updates the rest of the fields |
|
475 wlanRecord->SetElementId( wlanSet->iRecords[i]->ElementId() ); |
|
476 wlanRecord->LoadL( *db ); |
|
477 |
|
478 // Create IAP record |
|
479 CCDIAPRecord* iapRecord = |
|
480 static_cast<CCDIAPRecord*>( CCDRecordBase::RecordFactoryL( KCDTIdIAPRecord ) ); |
|
481 CleanupStack::PushL( iapRecord ); |
|
482 |
|
483 iapRecord->iServiceType.SetL( TPtrC( KCDTypeNameLANService ) ); |
|
484 // Set the service field to the same value as in the wlan service record we are currently looking |
|
485 iapRecord->iService = wlanRecord->iWlanServiceId; |
|
486 // Find matching IAP record |
|
487 if ( iapRecord->FindL( *db ) ) |
|
488 { |
|
489 // Read IAP ID and append to buffer |
|
490 TUint iapId = iapRecord->RecordId(); |
|
491 LOGIT2("AppendAvailableIapsBySsidL: index: %d, id: %d", i, iapId) |
|
492 aIdArray.Append( iapId ); // Ignore if Append fails, ID will be absent from availability list. |
|
493 } |
|
494 else |
|
495 { |
|
496 LOGIT("AppendAvailableIapsBySsidL: no matching IAP record found") |
|
497 } |
|
498 CleanupStack::PopAndDestroy( iapRecord ); |
|
499 } |
|
500 } |
|
501 else |
|
502 { |
|
503 LOGIT("AppendAvailableIapsBySsidL: no matching IAP records found") |
|
504 ret = KErrNotFound; |
|
505 } |
|
506 CleanupStack::PopAndDestroy( wlanSet ); |
|
507 CleanupStack::PopAndDestroy( db ); |
|
508 |
|
509 LOGTIMINGEND("CWlanSupport::AppendAvailableIapsBySsidL") |
|
510 } |
|
511 |
|
512 LOGEXITFN1("CWlanSupport::AppendAvailableIapsBySsidL()", ret) |
|
513 return ret; |
|
514 } |
|
515 |
|
516 // ----------------------------------------------------------------------------- |
|
517 // CWlanSupport::GetConnectionSsid |
|
518 // ----------------------------------------------------------------------------- |
|
519 // |
|
520 TInt CWlanSupport::GetConnectionSsid( TDes& aSsid ) |
|
521 { |
|
522 LOGENTRFN("CWlanSupport::GetConnectionSsid()") |
|
523 TInt err( KErrNone ); |
|
524 TWlanSsid ssid; |
|
525 |
|
526 err = iWlanMgmt->GetConnectionSsid( ssid ); |
|
527 if ( KErrNone == err ) |
|
528 { |
|
529 CnvUtfConverter::ConvertToUnicodeFromUtf8( aSsid, ssid ); |
|
530 #ifdef _DEBUG |
|
531 // One letter longer than max WLAN network name, since we are adding a '\0' when printing |
|
532 TBuf<CConnMonWlanNetwork::KMaxNameLength + 1> debug_name( aSsid ); |
|
533 LOGIT1("GetConnectionSsid: SSID <%s>", debug_name.PtrZ()) |
|
534 #endif // _DEBUG |
|
535 } |
|
536 |
|
537 LOGEXITFN1("CWlanSupport::GetConnectionSsid()", err) |
|
538 return err; |
|
539 } |
|
540 |
|
541 // ----------------------------------------------------------------------------- |
|
542 // CWlanSupport::GetConnectionMode |
|
543 // ----------------------------------------------------------------------------- |
|
544 // |
|
545 TInt CWlanSupport::GetConnectionMode( TInt& aConnectionMode ) |
|
546 { |
|
547 LOGENTRFN("CWlanSupport::GetConnectionMode()") |
|
548 TInt err( KErrNone ); |
|
549 |
|
550 TWlanConnectionMode mode( EWlanConnectionModeNotConnected ); |
|
551 aConnectionMode = KErrNotFound; |
|
552 |
|
553 // Get connection mode from WLAN engine |
|
554 err = iWlanMgmt->GetConnectionMode( mode ); |
|
555 if ( KErrNone == err ) |
|
556 { |
|
557 switch ( mode ) |
|
558 { |
|
559 case EWlanConnectionModeNotConnected: |
|
560 err = KErrNotFound; // Connection does not exist |
|
561 break; |
|
562 case EWlanConnectionModeInfrastructure: |
|
563 aConnectionMode = EConnMonInfraStructure; |
|
564 break; |
|
565 case EWlanConnectionModeAdhoc: |
|
566 aConnectionMode = EConnMonAdHoc; |
|
567 break; |
|
568 case EWlanConnectionModeSecureInfra: |
|
569 aConnectionMode = EConnMonSecureInfra; |
|
570 break; |
|
571 case EWlanConnectionModeSearching: |
|
572 err = KErrNotFound; // Connection does not exist |
|
573 break; |
|
574 default: |
|
575 err = KErrNotFound; |
|
576 break; |
|
577 } |
|
578 LOGIT1("CWlanSupport::GetConnectionMode: %d", aConnectionMode) |
|
579 } |
|
580 |
|
581 LOGEXITFN1("CWlanSupport::GetConnectionMode()", err) |
|
582 return err; |
|
583 } |
|
584 |
|
585 // ----------------------------------------------------------------------------- |
|
586 // CWlanSupport::GetConnectionSecurity |
|
587 // ----------------------------------------------------------------------------- |
|
588 // |
|
589 TInt CWlanSupport::GetConnectionSecurity( TInt& aConnectionSecurity ) |
|
590 { |
|
591 LOGENTRFN("CWlanSupport::GetConnectionSecurity()") |
|
592 TInt err( KErrNone ); |
|
593 |
|
594 TWlanConnectionSecurityMode mode( EWlanConnectionSecurityOpen ); |
|
595 |
|
596 // Get security mode |
|
597 err = iWlanMgmt->GetConnectionSecurityMode( mode ); |
|
598 if ( KErrNone == err ) |
|
599 { |
|
600 switch ( mode ) |
|
601 { |
|
602 case EWlanConnectionSecurityOpen: |
|
603 aConnectionSecurity = EConnMonSecurityOpen; |
|
604 break; |
|
605 case EWlanConnectionSecurityWep: |
|
606 aConnectionSecurity = EConnMonSecurityWep; |
|
607 break; |
|
608 case EWlanConnectionSecurity802d1x: |
|
609 aConnectionSecurity = EConnMonSecurity802d1x; |
|
610 break; |
|
611 case EWlanConnectionSecurityWpa: |
|
612 aConnectionSecurity = EConnMonSecurityWpa; |
|
613 break; |
|
614 case EWlanConnectionSecurityWpaPsk: |
|
615 aConnectionSecurity = EConnMonSecurityWpaPsk; |
|
616 break; |
|
617 default: |
|
618 aConnectionSecurity = EConnMonSecurityOpen; |
|
619 break; |
|
620 } |
|
621 LOGIT1("GetConnectionSecurity: security mode %d", aConnectionSecurity) |
|
622 } |
|
623 |
|
624 LOGEXITFN1("CWlanSupport::GetConnectionSecurity()", err) |
|
625 return err; |
|
626 } |
|
627 |
|
628 // ----------------------------------------------------------------------------- |
|
629 // CWlanSupport::GetConnectionSignalQuality |
|
630 // ----------------------------------------------------------------------------- |
|
631 // |
|
632 TInt CWlanSupport::GetConnectionSignalQuality( TInt& aSignalQuality ) |
|
633 { |
|
634 LOGENTRFN("CWlanSupport::GetConnectionSignalQuality()") |
|
635 TInt err( KErrNone ); |
|
636 TInt32 rssi( 0 ); |
|
637 |
|
638 err = iWlanMgmt->GetConnectionSignalQuality( rssi ); |
|
639 if ( KErrNone == err ) |
|
640 { |
|
641 aSignalQuality = static_cast<TInt>( rssi ); |
|
642 LOGIT1("CWlanSupport::GetConnectionSignalQuality: %d dBm", aSignalQuality) |
|
643 } |
|
644 |
|
645 LOGEXITFN1("CWlanSupport::GetConnectionSignalQuality()", err) |
|
646 return err; |
|
647 } |
|
648 |
|
649 // ----------------------------------------------------------------------------- |
|
650 // CWlanSupport::GetConnectionBssid |
|
651 // ----------------------------------------------------------------------------- |
|
652 // |
|
653 TInt CWlanSupport::GetConnectionBssid( TBuf8<CConnMonWlanNetwork::KWlanBssId>& aBssid ) |
|
654 { |
|
655 LOGENTRFN("CWlanSupport::GetConnectionBssid()") |
|
656 TInt err( KErrNone ); |
|
657 |
|
658 err = iWlanMgmt->GetConnectionBssid( aBssid ); |
|
659 #ifdef _DEBUG |
|
660 if ( KErrNone == err ) |
|
661 { |
|
662 LOGIT6("Bssid %02X:%02X:%02X:%02X:%02X:%02X", aBssid[0], aBssid[1], aBssid[2], aBssid[3], aBssid[4], aBssid[5]) |
|
663 } |
|
664 #endif // _DEBUG |
|
665 |
|
666 LOGEXITFN1("CWlanSupport::GetConnectionBssid()", err) |
|
667 return err; |
|
668 } |
|
669 |
|
670 // ----------------------------------------------------------------------------- |
|
671 // CWlanSupport::GetTransmitPower |
|
672 // ----------------------------------------------------------------------------- |
|
673 // |
|
674 TInt CWlanSupport::GetTransmitPower( TUint& aPower ) |
|
675 { |
|
676 LOGENTRFN("CWlanSupport::GetTransmitPower()") |
|
677 TInt err( KErrNone ); |
|
678 |
|
679 if ( iEventWatcher ) |
|
680 { |
|
681 aPower = iEventWatcher->TxPower(); |
|
682 LOGIT1("CWlanSupport:GetTransmitPower: %d mW", aPower) |
|
683 } |
|
684 else |
|
685 { |
|
686 err = KErrUnknown; |
|
687 } |
|
688 |
|
689 LOGEXITFN1("CWlanSupport::GetTransmitPower()", err) |
|
690 return err; |
|
691 } |
|
692 |
|
693 // ----------------------------------------------------------------------------- |
|
694 // CWlanSupport::ActivateNotificationsL |
|
695 // ----------------------------------------------------------------------------- |
|
696 // |
|
697 void CWlanSupport::ActivateNotificationsL() |
|
698 { |
|
699 //LOGENTRFN("CWlanSupport::ActivateNotificationsL()") |
|
700 |
|
701 if ( !iEventWatcher ) |
|
702 { |
|
703 iEventWatcher = CWlanEvent::NewL( this, iServer ); |
|
704 iWlanMgmt->ActivateNotificationsL( *iEventWatcher ); |
|
705 } |
|
706 |
|
707 //LOGEXITFN("CWlanSupport::ActivateNotificationsL()") |
|
708 } |
|
709 |
|
710 // ----------------------------------------------------------------------------- |
|
711 // CWlanSupport::CancelNotifications |
|
712 // ----------------------------------------------------------------------------- |
|
713 // |
|
714 void CWlanSupport::CancelNotifications() |
|
715 { |
|
716 LOGENTRFN("CWlanSupport::CancelNotifications()") |
|
717 |
|
718 if ( iEventWatcher ) |
|
719 { |
|
720 iWlanMgmt->CancelNotifications(); |
|
721 |
|
722 delete iEventWatcher; |
|
723 iEventWatcher = NULL; |
|
724 } |
|
725 |
|
726 LOGEXITFN("CWlanSupport::CancelNotifications()") |
|
727 } |
|
728 |
|
729 // ----------------------------------------------------------------------------- |
|
730 // CWlanSupport::GetWLANNetworksL |
|
731 // ----------------------------------------------------------------------------- |
|
732 // |
|
733 void CWlanSupport::GetWLANNetworksL( RConnMonWLANNetworksArray& aWlanNetworks ) |
|
734 { |
|
735 LOGENTRFN("CWlanSupport::GetWLANNetworksL()") |
|
736 |
|
737 // ScanInfo points to a CScanInfo object that will contain results from a scan. |
|
738 CWlanScanInfo* scanInfo = CWlanScanInfo::NewL(); |
|
739 CleanupStack::PushL( scanInfo ); |
|
740 |
|
741 TInt ret = iWlanMgmt->GetScanResults( *scanInfo ); |
|
742 if ( KErrNone == ret ) |
|
743 { |
|
744 // For logging only |
|
745 LOG(TInt count(0);) |
|
746 |
|
747 // Iterate through scan results |
|
748 for ( scanInfo->First(); !scanInfo->IsDone(); scanInfo->Next() ) |
|
749 { |
|
750 LOG(count++;) |
|
751 LOGIT1("CWlanSupport::GetWLANNetworksL: count %d", count) |
|
752 |
|
753 #ifdef _DEBUG |
|
754 // BSSID |
|
755 TWlanBssid bssid; |
|
756 scanInfo->Bssid( bssid ); |
|
757 LOGIT6("Bssid %02X:%02X:%02X:%02X:%02X:%02X", |
|
758 bssid[0], bssid[1], bssid[2], bssid[3], bssid[4], bssid[5]) |
|
759 #endif //_DEBUG |
|
760 |
|
761 // Connection mode |
|
762 TUint connectionMode( EConnMonInfraStructure ); |
|
763 if ( scanInfo->Capability() & KWlan802Dot11CapabilityEssMask ) |
|
764 { |
|
765 connectionMode = EConnMonInfraStructure; |
|
766 } |
|
767 else |
|
768 { |
|
769 connectionMode = EConnMonAdHoc; |
|
770 } |
|
771 |
|
772 // Signal strength |
|
773 TUint signalStrength(scanInfo->RXLevel()); |
|
774 LOGIT1("CWlanSupport::GetWLANNetworksL: signalStrength %d", signalStrength) |
|
775 |
|
776 // SecurityMode |
|
777 TUint8 ieLength( 0 ); |
|
778 const TUint8* wpaData; |
|
779 |
|
780 TUint securityMode( EConnMonSecurityOpen ); |
|
781 if ( scanInfo->Capability() & KWlan802Dot11CapabilityPrivacyMask ) |
|
782 { |
|
783 if ( ( scanInfo->InformationElement( |
|
784 KWlan802Dot11RsnIE, |
|
785 ieLength, |
|
786 &wpaData ) == KErrNone ) || |
|
787 ( scanInfo->WpaIE( |
|
788 ieLength, |
|
789 &wpaData ) == KErrNone ) ) |
|
790 { |
|
791 securityMode = EConnMonSecurityWpa; // WPA |
|
792 } |
|
793 else |
|
794 { |
|
795 securityMode = EConnMonSecurityWep; // WEP |
|
796 } |
|
797 } |
|
798 LOGIT1("CWlanSupport::GetWLANNetworksL: securityMode %d", securityMode) |
|
799 |
|
800 // SSID == name |
|
801 TBuf8<TConnMonWLANNetwork::KMaxNameLength> name8; |
|
802 TUint8 ieLen( 0 ); |
|
803 const TUint8* ieData; |
|
804 ieData = NULL; |
|
805 |
|
806 ret = scanInfo->InformationElement( KWlan802Dot11SsidIE, ieLen, &ieData ); |
|
807 if ( KErrNone == ret && ieLen <= CConnMonWlanNetwork::KMaxNameLength ) |
|
808 { |
|
809 // ieData points to the beginning of the 802.11 SSID payload data i.e. |
|
810 // the header is bypassed. ieLen contains the length of payload data. |
|
811 name8.Copy( ieData, ieLen ); |
|
812 } |
|
813 LOGIT1("CWlanSupport::GetWLANNetworksL: ieLen %d", ieLen) |
|
814 |
|
815 TBuf<TConnMonWLANNetwork::KMaxNameLength> name; |
|
816 ConnMonUtils::TDes8ToTDes( name8, name ); |
|
817 |
|
818 #ifdef _DEBUG |
|
819 // One letter longer than max WLAN network name, since we are adding a '\0' when printing |
|
820 TBuf<CConnMonWlanNetwork::KMaxNameLength+1> debug_name; |
|
821 ConnMonUtils::TDes8ToTDes( name8, debug_name ); |
|
822 LOGIT2("CWlanSupport::GetWLANNetworksL: name <%s>, length %d", |
|
823 debug_name.PtrZ(), name.Length()) |
|
824 #endif // _DEBUG |
|
825 |
|
826 RArray<TInt> extrafields; |
|
827 CleanupClosePushL( extrafields ); |
|
828 |
|
829 aWlanNetworks.AppendL( TConnMonWLANNetwork( |
|
830 name, |
|
831 connectionMode, |
|
832 signalStrength, |
|
833 securityMode, |
|
834 extrafields ) ); |
|
835 CleanupStack::PopAndDestroy( &extrafields ); |
|
836 } |
|
837 aWlanNetworks.Sort( TLinearOrder<TConnMonWLANNetwork>( |
|
838 TConnMonWLANNetwork::LessBySignal ) ); |
|
839 } |
|
840 else |
|
841 { |
|
842 // Could not get any scan results |
|
843 User::Leave( ret ); |
|
844 } |
|
845 CleanupStack::PopAndDestroy( scanInfo ); |
|
846 |
|
847 LOGEXITFN("CWlanSupport::GetWLANNetworksL()") |
|
848 } |
|
849 |
|
850 |
|
851 // ----------------------------------------------------------------------------- |
|
852 // CWlanSupport::GetWlanNetworksL |
|
853 // ----------------------------------------------------------------------------- |
|
854 // |
|
855 TInt CWlanSupport::GetWlanNetworksL( const RMessage2& aMessage ) |
|
856 { |
|
857 LOGENTRFN("CWlanSupport::GetWlanNetworksL()") |
|
858 |
|
859 // Add session to wlan session table (if not already there) |
|
860 TInt index = AddWlanSessionL( aMessage ); |
|
861 |
|
862 iWlanSessionsPtrArray[index]->GetScanResultsL( aMessage ); |
|
863 |
|
864 LOGEXITFN1("CWlanSupport::GetWlanNetworksL()", KRequestPending) |
|
865 return KRequestPending; |
|
866 } |
|
867 |
|
868 |
|
869 // ----------------------------------------------------------------------------- |
|
870 // CWlanSupport::ParseWlanNetworks |
|
871 // ----------------------------------------------------------------------------- |
|
872 // |
|
873 void CWlanSupport::ParseWlanNetworksL( |
|
874 CWlanScanInfo* aScanInfo, |
|
875 RConnMonWlanNetworksPtrArray& aWlanNetworks ) |
|
876 { |
|
877 LOGENTRFN("CWlanSupport::ParseWlanNetworksL()") |
|
878 LOG(TInt count( 0 );) // For logging only |
|
879 |
|
880 LOGIT("ParseWlanNetworksL: WLAN scan info:") |
|
881 // Iterate through scan results |
|
882 for ( aScanInfo->First(); !aScanInfo->IsDone(); aScanInfo->Next() ) |
|
883 { |
|
884 // BSSID |
|
885 TWlanBssid bssid; |
|
886 aScanInfo->Bssid( bssid ); |
|
887 |
|
888 // Connection mode |
|
889 TUint connectionMode( EConnMonInfraStructure ); |
|
890 if ( aScanInfo->Capability() & KWlan802Dot11CapabilityEssMask ) |
|
891 { |
|
892 connectionMode = EConnMonInfraStructure; |
|
893 } |
|
894 else |
|
895 { |
|
896 connectionMode = EConnMonAdHoc; |
|
897 } |
|
898 |
|
899 // Signal strength |
|
900 TUint signalStrength( aScanInfo->RXLevel() ); |
|
901 |
|
902 // SecurityMode |
|
903 TUint8 ieLength( 0 ); |
|
904 const TUint8* wpaData; |
|
905 |
|
906 TUint securityMode( EConnMonSecurityOpen ); |
|
907 if ( aScanInfo->Capability() & KWlan802Dot11CapabilityPrivacyMask ) |
|
908 { |
|
909 if ( ( aScanInfo->InformationElement( |
|
910 KWlan802Dot11RsnIE, |
|
911 ieLength, |
|
912 &wpaData ) == KErrNone ) || |
|
913 ( aScanInfo->WpaIE( |
|
914 ieLength, |
|
915 &wpaData ) == KErrNone ) ) |
|
916 { |
|
917 securityMode = EConnMonSecurityWpa; // WPA |
|
918 } |
|
919 else |
|
920 { |
|
921 securityMode = EConnMonSecurityWep; // WEP |
|
922 } |
|
923 } |
|
924 |
|
925 // SSID == name |
|
926 TBuf8<CConnMonWlanNetwork::KMaxNameLength> name8; |
|
927 TUint8 ieLen( 0 ); |
|
928 const TUint8* ieData; |
|
929 ieData = NULL; |
|
930 |
|
931 TInt ret = aScanInfo->InformationElement( KWlan802Dot11SsidIE, ieLen, &ieData ); |
|
932 if ( ret == KErrNone && ieLen <= CConnMonWlanNetwork::KMaxNameLength ) |
|
933 { |
|
934 // ieData points to the beginning of the 802.11 SSID payload data i.e. |
|
935 // the header is bypassed. ieLen contains the length of payload data. |
|
936 name8.Copy( ieData, ieLen ); |
|
937 } |
|
938 |
|
939 TBuf<CConnMonWlanNetwork::KMaxNameLength> name; |
|
940 ConnMonUtils::TDes8ToTDes( name8, name ); |
|
941 |
|
942 #ifdef _DEBUG |
|
943 LOG(count++;) |
|
944 // One letter longer than max WLAN network name, since we are adding a '\0' when printing |
|
945 TBuf<CConnMonWlanNetwork::KMaxNameLength + 1> debug_name; |
|
946 ConnMonUtils::TDes8ToTDes( name8, debug_name ); |
|
947 LOGIT11("%02d: %02X:%02X:%02X:%02X:%02X:%02X sig.str %d, sec.mode %d, name(%02d): %s", |
|
948 count, bssid[0], bssid[1], bssid[2], bssid[3], bssid[4], bssid[5], |
|
949 signalStrength, securityMode, name.Length(), debug_name.PtrZ()) |
|
950 #endif // _DEBUG |
|
951 |
|
952 // Create CConnMonWlanNetwork object with scan results |
|
953 CConnMonWlanNetwork* net = CConnMonWlanNetwork::NewL( |
|
954 name, |
|
955 connectionMode, |
|
956 signalStrength, |
|
957 securityMode, |
|
958 bssid, |
|
959 KNullDesC() ); |
|
960 CleanupStack::PushL( net ); |
|
961 aWlanNetworks.AppendL( net ); |
|
962 CleanupStack::Pop( net ); |
|
963 } |
|
964 LOGIT("ParseWlanNetworksL: sorting wlan networks") |
|
965 aWlanNetworks.Sort( TLinearOrder<CConnMonWlanNetwork>( |
|
966 CConnMonWlanNetwork::CompareBySignal ) ); |
|
967 |
|
968 LOGEXITFN("CWlanSupport::ParseWlanNetworksL()") |
|
969 } |
|
970 |
|
971 |
|
972 // ----------------------------------------------------------------------------- |
|
973 // CWlanSupport::GetCurrentWlanNetwork |
|
974 // ----------------------------------------------------------------------------- |
|
975 // |
|
976 TInt CWlanSupport::GetCurrentWlanNetworkL( |
|
977 RConnMonWlanNetworksPtrArray& aWlanNetwork ) |
|
978 { |
|
979 LOGENTRFN("CWlanSupport::GetCurrentWlanNetworkL()") |
|
980 TInt err( KErrNone ); |
|
981 |
|
982 TInt connectionMode; |
|
983 TInt connectionSecurity; |
|
984 TInt connectionSignalQuality; |
|
985 TBuf<CConnMonWlanNetwork::KMaxNameLength> connectionSsid; |
|
986 TBuf8<CConnMonWlanNetwork::KWlanBssId> connectionBssid; |
|
987 |
|
988 // Get connection mode to see if connection exists |
|
989 err = GetConnectionMode( connectionMode ); |
|
990 if ( KErrNone == err ) |
|
991 { |
|
992 // Get connection security mode |
|
993 err = GetConnectionSecurity( connectionSecurity ); |
|
994 } |
|
995 if ( KErrNone == err ) |
|
996 { |
|
997 // Get connection signal quality |
|
998 err = GetConnectionSignalQuality( connectionSignalQuality ); |
|
999 } |
|
1000 if ( KErrNone == err ) |
|
1001 { |
|
1002 // Get connection SSID |
|
1003 err = GetConnectionSsid( connectionSsid ); |
|
1004 } |
|
1005 if ( KErrNone == err ) |
|
1006 { |
|
1007 // Get connection BSSID |
|
1008 err = GetConnectionBssid( connectionBssid ); |
|
1009 } |
|
1010 if ( KErrNone == err ) |
|
1011 { |
|
1012 // Create CConnMonWlanNetwork object with results |
|
1013 CConnMonWlanNetwork* net = CConnMonWlanNetwork::NewL( |
|
1014 connectionSsid, |
|
1015 connectionMode, |
|
1016 connectionSignalQuality, |
|
1017 connectionSecurity, |
|
1018 connectionBssid, |
|
1019 KNullDesC() ); |
|
1020 CleanupStack::PushL( net ); |
|
1021 aWlanNetwork.AppendL( net ); |
|
1022 CleanupStack::Pop( net ); |
|
1023 } |
|
1024 |
|
1025 LOGEXITFN1("CWlanSupport::GetCurrentWlanNetworkL()", err) |
|
1026 return err; |
|
1027 } |
|
1028 |
|
1029 |
|
1030 // ----------------------------------------------------------------------------- |
|
1031 // CWlanSupport::GetWlanProbeRawBuffersL |
|
1032 // ----------------------------------------------------------------------------- |
|
1033 // |
|
1034 TInt CWlanSupport::GetWlanProbeRawBuffersL( const RMessage2& aMessage ) |
|
1035 { |
|
1036 LOGENTRFN("CWlanSupport::GetWlanProbeRawBuffersL()") |
|
1037 |
|
1038 // Add session to wlan session table (if not already there) |
|
1039 TInt index = AddWlanSessionL( aMessage ); |
|
1040 iWlanSessionsPtrArray[index]->GetScanResultsL( aMessage ); |
|
1041 |
|
1042 LOGEXITFN1("CWlanSupport::GetWlanProbeRawBuffersL()", KRequestPending) |
|
1043 return KRequestPending; |
|
1044 } |
|
1045 |
|
1046 |
|
1047 // ----------------------------------------------------------------------------- |
|
1048 // CWlanSupport::ParseWlanNetworks |
|
1049 // ----------------------------------------------------------------------------- |
|
1050 // |
|
1051 void CWlanSupport::ParseWlanProbeRawBuffersL( |
|
1052 CWlanScanInfo* aScanInfo, |
|
1053 RConnMonWlanProbeRawBuffersPtrArray& aWlanProbeRawBuffers ) |
|
1054 { |
|
1055 LOGENTRFN("CWlanSupport::ParseWlanProbeRawBuffersL()") |
|
1056 |
|
1057 // For logging only |
|
1058 LOG(TInt count( 0 );) |
|
1059 |
|
1060 // Iterate through scan results. |
|
1061 for( aScanInfo->First(); !aScanInfo->IsDone(); aScanInfo->Next() ) |
|
1062 { |
|
1063 LOG(count++;) |
|
1064 LOGIT1("CWlanSupport::ParseWlanProbeRawBuffersL: network number %d", count) |
|
1065 |
|
1066 // Length of the raw data == Size - CNTRL_HEADER_LEN (==12) |
|
1067 TUint16 length( 0 ); |
|
1068 length = aScanInfo->Size() - KWlanProbeControlHeaderLength; |
|
1069 LOGIT1("CWlanSupport::ParseWlanProbeRawBuffersL: length %d", length) |
|
1070 |
|
1071 // Get pointer start of the raw data |
|
1072 const TWlanScanInfoFrame* probeRawDataStartPtr = |
|
1073 aScanInfo->Current() + KWlanProbeControlHeaderLength; |
|
1074 |
|
1075 // Create temporary heap descriptor for raw data |
|
1076 HBufC8* rawBuffer = HBufC8::NewL( length ); |
|
1077 CleanupStack::PushL( rawBuffer ); |
|
1078 rawBuffer->Des().Copy( probeRawDataStartPtr, length ); |
|
1079 |
|
1080 #ifdef _CONNMON_HEXDUMP_LOGGING |
|
1081 #if ( _CONNMON_LOG_OUTPUT == 2 ) // Works only when logging to file |
|
1082 const TText* header = _S( "header" ); |
|
1083 const TText* margin = _S( "margin" ); |
|
1084 Log::HexDump( header, margin, probeRawDataStartPtr, length ); |
|
1085 #endif // _CONNMON_LOG_OUTPUT |
|
1086 #endif // _CONNMON_HEXDUMP_LOGGING |
|
1087 |
|
1088 // Create CConnMonWlanProbeRawBuffer object |
|
1089 CConnMonWlanProbeRawBuffer* net = CConnMonWlanProbeRawBuffer::NewL( rawBuffer ); |
|
1090 CleanupStack::PushL( net ); |
|
1091 |
|
1092 // Add object pointer to array |
|
1093 aWlanProbeRawBuffers.AppendL( net ); |
|
1094 |
|
1095 CleanupStack::Pop( net ); |
|
1096 // Clear temporary heap descriptor |
|
1097 CleanupStack::PopAndDestroy( rawBuffer ); |
|
1098 LOGIT(".") |
|
1099 } |
|
1100 |
|
1101 LOGEXITFN("CWlanSupport::ParseWlanProbeRawBuffersL()") |
|
1102 } |
|
1103 |
|
1104 |
|
1105 // ----------------------------------------------------------------------------- |
|
1106 // CWlanSupport::GetWlanSsidNetworksL |
|
1107 // ----------------------------------------------------------------------------- |
|
1108 // |
|
1109 TInt CWlanSupport::GetWlanSsidNetworksL( const RMessage2& aMessage ) |
|
1110 { |
|
1111 LOGENTRFN("CWlanSupport::GetWlanSsidNetworksL()") |
|
1112 TInt result( KErrNone ); |
|
1113 |
|
1114 // Add session to wlan session table (if not already there) |
|
1115 TInt index = AddWlanSessionL( aMessage ); |
|
1116 result = iWlanSessionsPtrArray[index]->GetSsidScanResultsL( aMessage ); |
|
1117 |
|
1118 LOGEXITFN1("CWlanSupport::GetWlanSsidNetworksL()", result) |
|
1119 return result; |
|
1120 } |
|
1121 |
|
1122 |
|
1123 // ----------------------------------------------------------------------------- |
|
1124 // CWlanSupport::AddWlanSessionL |
|
1125 // ----------------------------------------------------------------------------- |
|
1126 // |
|
1127 TInt CWlanSupport::AddWlanSessionL( const RMessage2& aMessage ) |
|
1128 { |
|
1129 LOGENTRFN("CWlanSupport::AddWlanSessionL()") |
|
1130 |
|
1131 // Set active session Id to session object |
|
1132 CConnMonSession* sessionId = (CConnMonSession*)aMessage.Session(); |
|
1133 |
|
1134 // Check if session exist in WLAN sessions array |
|
1135 TInt index = WlanSessionIndex( sessionId ); // Returns either KErrNotFound or a valid index |
|
1136 if ( index != KErrNotFound ) |
|
1137 { |
|
1138 LOGIT2("AddWlanSessionL: session id %d already in array at index %d", sessionId, index) |
|
1139 } |
|
1140 else |
|
1141 { |
|
1142 CWlanSession* session = CWlanSession::NewL( sessionId, this ); |
|
1143 CleanupStack::PushL( session ); |
|
1144 iWlanSessionsPtrArray.AppendL( session ); |
|
1145 CleanupStack::Pop( session ); |
|
1146 index = iWlanSessionsPtrArray.Count() - 1; |
|
1147 LOGIT2("AddWlanSessionL: new session id %d added to array at index %d", sessionId, index) |
|
1148 } |
|
1149 |
|
1150 LOGEXITFN1("CWlanSupport::AddWlanSessionL()", index) |
|
1151 return index; |
|
1152 } |
|
1153 |
|
1154 |
|
1155 // ----------------------------------------------------------------------------- |
|
1156 // CWlanSupport::DeleteWlanSession |
|
1157 // ----------------------------------------------------------------------------- |
|
1158 // |
|
1159 void CWlanSupport::DeleteWlanSession( CConnMonSession* aSessionId ) |
|
1160 { |
|
1161 LOGENTRFN("CWlanSupport::DeleteWlanSession()") |
|
1162 |
|
1163 // Check if session found from WLAN sessions array |
|
1164 TInt index = WlanSessionIndex( aSessionId ); |
|
1165 |
|
1166 if ( index != KErrNotFound ) |
|
1167 { |
|
1168 delete iWlanSessionsPtrArray[index]; |
|
1169 iWlanSessionsPtrArray[index] = NULL; |
|
1170 iWlanSessionsPtrArray.Remove( index ); |
|
1171 LOGIT2("DeleteWlanSession: deleted session id %d from array index %d", aSessionId, index) |
|
1172 } |
|
1173 |
|
1174 LOGEXITFN("CWlanSupport::DeleteWlanSession()") |
|
1175 } |
|
1176 |
|
1177 |
|
1178 // ----------------------------------------------------------------------------- |
|
1179 // CWlanSupport::WlanSessionIndex |
|
1180 // ----------------------------------------------------------------------------- |
|
1181 // |
|
1182 TInt CWlanSupport::WlanSessionIndex( CConnMonSession* aSessionId ) |
|
1183 { |
|
1184 LOGENTRFN("CWlanSupport::WlanSessionIndex()") |
|
1185 TInt result( KErrNotFound ); |
|
1186 |
|
1187 // Check session index of the WLAN sessions array |
|
1188 for ( TInt index = 0; index < iWlanSessionsPtrArray.Count(); index++ ) |
|
1189 { |
|
1190 if ( aSessionId == iWlanSessionsPtrArray[index]->GetSessionId() ) |
|
1191 { |
|
1192 LOGIT2("WlanSessionIndex: session id %d found from index %d", aSessionId, index) |
|
1193 result = index; |
|
1194 break; |
|
1195 } |
|
1196 } |
|
1197 |
|
1198 LOGEXITFN1("CWlanSupport::WlanSessionIndex()", result) |
|
1199 return result; |
|
1200 } |
|
1201 |
|
1202 // ----------------------------------------------------------------------------- |
|
1203 // CWlanSupport::SetIntAttribute |
|
1204 // ----------------------------------------------------------------------------- |
|
1205 // |
|
1206 TInt CWlanSupport::SetIntAttributeL( |
|
1207 const RMessage2& aMessage, |
|
1208 const TInt aValue ) |
|
1209 { |
|
1210 LOGENTRFN("CWlanSupport::SetIntAttributeL()") |
|
1211 TInt result( KErrNone ); |
|
1212 TUint attribute = aMessage.Int2(); |
|
1213 |
|
1214 // Add session to wlan session table (if not already there) |
|
1215 TInt index = AddWlanSessionL( aMessage ); |
|
1216 |
|
1217 switch ( attribute ) |
|
1218 { |
|
1219 case KWlanScanCacheLifetime: |
|
1220 iWlanSessionsPtrArray[index]->SetWlanScanCacheLifetime( aValue ); |
|
1221 LOGIT1("SetIntAttributeL: KWlanScanCacheLifetime set to value <%d>", aValue) |
|
1222 result = KErrNone; |
|
1223 break; |
|
1224 default: |
|
1225 LOGIT1("SetIntAttributeL: Error, unknown attribute <%d>", attribute) |
|
1226 result = KErrArgument; |
|
1227 break; |
|
1228 } |
|
1229 |
|
1230 LOGEXITFN1("CWlanSupport::SetIntAttributeL()", result) |
|
1231 return result; |
|
1232 } |
|
1233 |
|
1234 // ----------------------------------------------------------------------------- |
|
1235 // CWlanSupport::SetUintAttribute |
|
1236 // ----------------------------------------------------------------------------- |
|
1237 // |
|
1238 TInt CWlanSupport::SetUintAttributeL( |
|
1239 const RMessage2& aMessage, |
|
1240 const TUint aValue ) |
|
1241 { |
|
1242 LOGENTRFN("CWlanSupport::SetUintAttributeL()") |
|
1243 TInt result( KErrNone ); |
|
1244 TUint attribute = aMessage.Int2(); |
|
1245 |
|
1246 // Add session to wlan session table (if not already there) |
|
1247 TInt index = AddWlanSessionL( aMessage ); |
|
1248 |
|
1249 switch ( attribute ) |
|
1250 { |
|
1251 case KWlanScanMaxDelay: |
|
1252 iWlanSessionsPtrArray[index]->SetWlanScanMaxDelay( aValue ); |
|
1253 LOGIT1("SetUintAttributeL: KWlanScanMaxDelay set to value %d", aValue) |
|
1254 result = KErrNone; |
|
1255 break; |
|
1256 default: |
|
1257 LOGIT1("SetUintAttributeL: Error, unknown attribute %d", attribute) |
|
1258 result = KErrArgument; |
|
1259 break; |
|
1260 } |
|
1261 |
|
1262 LOGEXITFN1("CWlanSupport::SetUintAttributeL()", result) |
|
1263 return result; |
|
1264 } |
|
1265 |
|
1266 // ----------------------------------------------------------------------------- |
|
1267 // CWlanSupport::GetIntAttribute |
|
1268 // ----------------------------------------------------------------------------- |
|
1269 // |
|
1270 TInt CWlanSupport::GetIntAttributeL( const RMessage2& aMessage, TInt& aValue ) |
|
1271 { |
|
1272 LOGENTRFN("CWlanSupport::GetIntAttributeL()") |
|
1273 TInt err( KErrNone ); |
|
1274 TUint attribute = aMessage.Int2(); |
|
1275 |
|
1276 // Add session to wlan session table (if not already there) |
|
1277 TInt index = AddWlanSessionL( aMessage ); |
|
1278 switch ( attribute ) |
|
1279 { |
|
1280 case KWlanScanCacheLifetime: |
|
1281 aValue = iWlanSessionsPtrArray[index]->GetWlanScanCacheLifetime(); |
|
1282 LOGIT1("GetIntAttributeL: KWlanScanCacheLifetime got value %d", aValue) |
|
1283 err = KErrNone; |
|
1284 break; |
|
1285 default: |
|
1286 LOGIT1("GetIntAttributeL: Error, unknown attribute %d", attribute) |
|
1287 err = KErrArgument; |
|
1288 break; |
|
1289 } |
|
1290 |
|
1291 LOGEXITFN1("CWlanSupport::GetIntAttributeL()", err) |
|
1292 return err; |
|
1293 } |
|
1294 |
|
1295 // ----------------------------------------------------------------------------- |
|
1296 // CWlanSupport::GetUintAttribute |
|
1297 // ----------------------------------------------------------------------------- |
|
1298 // |
|
1299 TInt CWlanSupport::GetUintAttributeL( const RMessage2& aMessage, TUint& aValue ) |
|
1300 { |
|
1301 LOGENTRFN("CWlanSupport::GetUintAttributeL()") |
|
1302 TInt err( KErrNone ); |
|
1303 TUint attribute( aMessage.Int2() ); |
|
1304 |
|
1305 // Add session to wlan session table (if not already there) |
|
1306 TInt index = AddWlanSessionL( aMessage ); |
|
1307 switch ( attribute ) |
|
1308 { |
|
1309 case KWlanScanMaxDelay: |
|
1310 aValue = iWlanSessionsPtrArray[index]->GetWlanScanMaxDelay(); |
|
1311 LOGIT1("GetUintAttributeL: KWlanScanMaxDelay got value %d", aValue) |
|
1312 err = KErrNone; |
|
1313 break; |
|
1314 default: |
|
1315 LOGIT1("GetUintAttributeL: Error, unknown attribute %d", attribute) |
|
1316 err = KErrArgument; |
|
1317 break; |
|
1318 } |
|
1319 |
|
1320 LOGEXITFN1("CWlanSupport::GetUintAttributeL()", err) |
|
1321 return err; |
|
1322 } |
|
1323 |
|
1324 // ----------------------------------------------------------------------------- |
|
1325 // CWlanSupport::SetStringAttribute |
|
1326 // |
|
1327 // Currently assumes the descriptor attribute 'aValue' length has been checked |
|
1328 // earlier and is short enough. |
|
1329 // ----------------------------------------------------------------------------- |
|
1330 // |
|
1331 TInt CWlanSupport::SetStringAttributeL( |
|
1332 const RMessage2& aMessage, |
|
1333 const TDes& aValue ) |
|
1334 { |
|
1335 LOGENTRFN("CWlanSupport::SetStringAttributeL()") |
|
1336 TInt err( KErrNone ); |
|
1337 TUint attribute( aMessage.Int2() ); |
|
1338 |
|
1339 // Add session to wlan session table (if not already there) |
|
1340 TInt index = AddWlanSessionL( aMessage ); |
|
1341 switch ( attribute ) |
|
1342 { |
|
1343 case KWlanSsid: |
|
1344 { |
|
1345 TBuf8<CConnMonWlanNetwork::KMaxNameLength> ssid; |
|
1346 ConnMonUtils::TDesToTDes8( aValue, ssid ); |
|
1347 iWlanSessionsPtrArray[index]->SetWlanSsid( ssid ); |
|
1348 } |
|
1349 break; |
|
1350 default: |
|
1351 LOGIT1("SetStringAttributeL: invalid attribute %d", attribute) |
|
1352 err = KErrArgument; |
|
1353 break; |
|
1354 } |
|
1355 |
|
1356 LOGEXITFN1("CWlanSupport::SetStringAttributeL()", err) |
|
1357 return err; |
|
1358 } |
|
1359 |
|
1360 // ----------------------------------------------------------------------------- |
|
1361 // CWlanSupport::GetStringAttribute |
|
1362 // ----------------------------------------------------------------------------- |
|
1363 // |
|
1364 TInt CWlanSupport::GetStringAttributeL( |
|
1365 const RMessage2& aMessage, |
|
1366 TDes& aValue ) |
|
1367 { |
|
1368 LOGENTRFN("CWlanSupport::GetStringAttributeL()") |
|
1369 TInt err( KErrNone ); |
|
1370 TUint attribute( aMessage.Int2() ); |
|
1371 |
|
1372 // Add session to wlan session table (if not already there) |
|
1373 TInt index = AddWlanSessionL( aMessage ); |
|
1374 |
|
1375 switch ( attribute ) |
|
1376 { |
|
1377 case KWlanSsid: |
|
1378 { |
|
1379 TBuf8<CConnMonWlanNetwork::KMaxNameLength> ssid; |
|
1380 iWlanSessionsPtrArray[index]->GetWlanSsid( ssid ); |
|
1381 ConnMonUtils::TDes8ToTDes( ssid, aValue ); |
|
1382 } |
|
1383 break; |
|
1384 default: |
|
1385 LOGIT1("GetStringAttributeL: invalid attribute %d", attribute) |
|
1386 err = KErrArgument; |
|
1387 break; |
|
1388 } |
|
1389 |
|
1390 LOGEXITFN1("CWlanSupport::GetStringAttributeL()", err) |
|
1391 return err; |
|
1392 } |
|
1393 |
|
1394 // ----------------------------------------------------------------------------- |
|
1395 // CWlanSupport::CancelAsyncRequest |
|
1396 // ----------------------------------------------------------------------------- |
|
1397 // |
|
1398 TInt CWlanSupport::CancelAsyncRequest( const RMessage2& aMessage ) |
|
1399 { |
|
1400 LOGENTRFN("CWlanSupport::CancelAsyncRequest()") |
|
1401 TInt err( KErrNone ); |
|
1402 |
|
1403 // Check array index |
|
1404 TInt index = WlanSessionIndex( (CConnMonSession*)aMessage.Session() ); |
|
1405 |
|
1406 // Check if session exist in WLAN sessions array |
|
1407 if ( KErrNotFound == index ) |
|
1408 { |
|
1409 // Nothing to cancel on WLAN side |
|
1410 err = KErrNotFound; |
|
1411 } |
|
1412 else |
|
1413 { |
|
1414 // Cancel client active requests |
|
1415 iWlanSessionsPtrArray[index]->CancelActiveRequests( aMessage.Int0() ); |
|
1416 } |
|
1417 |
|
1418 LOGEXITFN1("CWlanSupport::CancelAsyncRequest()", err) |
|
1419 return err; |
|
1420 } |
|
1421 |
|
1422 // ----------------------------------------------------------------------------- |
|
1423 // CWlanSupport::EnableEventsToClients |
|
1424 // ----------------------------------------------------------------------------- |
|
1425 // |
|
1426 void CWlanSupport::EnableEventsToClients() |
|
1427 { |
|
1428 iEnableEventsToClients = ETrue; |
|
1429 } |
|
1430 |
|
1431 // ----------------------------------------------------------------------------- |
|
1432 // CWlanSupport::DisableEventsToClients |
|
1433 // ----------------------------------------------------------------------------- |
|
1434 // |
|
1435 void CWlanSupport::DisableEventsToClients() |
|
1436 { |
|
1437 iEnableEventsToClients = EFalse; |
|
1438 } |
|
1439 |
|
1440 // ----------------------------------------------------------------------------- |
|
1441 // CWlanSupport::EventsToClientsEnabled |
|
1442 // ----------------------------------------------------------------------------- |
|
1443 // |
|
1444 TBool CWlanSupport::EventsToClientsEnabled() |
|
1445 { |
|
1446 return iEnableEventsToClients; |
|
1447 } |
|
1448 |
|
1449 // ----------------------------------------------------------------------------- |
|
1450 // CWlanSupport::WlanRssGoodEnough |
|
1451 // ----------------------------------------------------------------------------- |
|
1452 // |
|
1453 TBool CWlanSupport::WlanRssGoodEnough() |
|
1454 { |
|
1455 LOGENTRFN("CWlanSupport::WlanRssGoodEnough()") |
|
1456 |
|
1457 // Return ETrue by default. Return EFalse only if there is no error |
|
1458 // situation and WLAN engine has reported received signal strength |
|
1459 // class as weak. |
|
1460 TBool value( ETrue ); |
|
1461 |
|
1462 if ( iEventWatcher ) |
|
1463 { |
|
1464 if ( iEventWatcher->RssClass() == EConnMonWlanRssClassWeak ) |
|
1465 { |
|
1466 value = EFalse; |
|
1467 } |
|
1468 } |
|
1469 |
|
1470 LOGEXITFN1("CWlanSupport::WlanRssGoodEnough()", value) |
|
1471 return value; |
|
1472 } |
|
1473 |
|
1474 // ============================ MEMBER FUNCTIONS =============================== |
|
1475 |
|
1476 // ----------------------------------------------------------------------------- |
|
1477 // CWlanEvent::NewL |
|
1478 // ----------------------------------------------------------------------------- |
|
1479 // |
|
1480 CWlanEvent* CWlanEvent::NewL( CWlanSupport* aWlanSupport, CConnMonServer* aServer ) |
|
1481 { |
|
1482 CWlanEvent* self = new( ELeave ) CWlanEvent( aWlanSupport, aServer ); |
|
1483 return self; |
|
1484 } |
|
1485 |
|
1486 // ----------------------------------------------------------------------------- |
|
1487 // CWlanEvent::CWlanEvent |
|
1488 // ----------------------------------------------------------------------------- |
|
1489 // |
|
1490 CWlanEvent::CWlanEvent( |
|
1491 CWlanSupport* aWlanSupport, |
|
1492 CConnMonServer* aServer ) |
|
1493 : |
|
1494 iWlanSupport( aWlanSupport ), |
|
1495 iServer( aServer ), |
|
1496 iWlanAvailable( EFalse ), |
|
1497 iHasAvailabilityKnowledge( EFalse ), |
|
1498 iRssClass( EConnMonWlanRssClassUnknown ), |
|
1499 iRss( 0 ) |
|
1500 { |
|
1501 } |
|
1502 |
|
1503 // ----------------------------------------------------------------------------- |
|
1504 // Destructor |
|
1505 // ----------------------------------------------------------------------------- |
|
1506 // |
|
1507 CWlanEvent::~CWlanEvent() |
|
1508 { |
|
1509 iWlanSupport = NULL; |
|
1510 iServer = NULL; |
|
1511 } |
|
1512 |
|
1513 // ----------------------------------------------------------------------------- |
|
1514 // CWlanEvent::NewNetworksDetected |
|
1515 // New networks have been detected during scan. |
|
1516 // ----------------------------------------------------------------------------- |
|
1517 // |
|
1518 void CWlanEvent::NewNetworksDetected() |
|
1519 { |
|
1520 LOGIT(".") |
|
1521 LOGENTRFN("CWlanEvent::NewNetworksDetected()") |
|
1522 iHasAvailabilityKnowledge = ETrue; |
|
1523 iWlanAvailable = ETrue; |
|
1524 |
|
1525 if ( iWlanSupport->EventsToClientsEnabled() ) |
|
1526 { |
|
1527 TEventInfo eventInfo; |
|
1528 // Check bearer availability threshold |
|
1529 TUint threshold( 0 ); |
|
1530 iServer->CalculateThreshold( EBearerIdAll, EBearerAvailabilityThreshold, threshold ); |
|
1531 |
|
1532 // Send bearer availability change event only if threshold is set by some of the clients |
|
1533 if ( threshold > 0 ) |
|
1534 { |
|
1535 // Create event info |
|
1536 eventInfo.Reset(); |
|
1537 eventInfo.iConnectionId = EBearerIdWLAN; |
|
1538 eventInfo.iEventType = EConnMonBearerAvailabilityChange; |
|
1539 eventInfo.iData = iWlanAvailable; |
|
1540 |
|
1541 // Send EConnMonBearerAvailabilityChange event to clients |
|
1542 iServer->EventQueue()->Add( eventInfo ); |
|
1543 LOGIT1("SERVER: EVENT -> WLAN bearer availability changed: %d (bool)", iWlanAvailable) |
|
1544 } |
|
1545 |
|
1546 LOGIT("CWlanEvent::NewNetworksDetected triggered HandleAvailabilityChange()") |
|
1547 iWlanSupport->EnableWlanScan(); |
|
1548 iServer->AvailabilityManager()->HandleAvailabilityChange(); |
|
1549 |
|
1550 // Create and send EConnMonNewWLANNetworkDetected event to clients |
|
1551 eventInfo.Reset(); |
|
1552 eventInfo.iConnectionId = EBearerIdWLAN; |
|
1553 eventInfo.iEventType = EConnMonNewWLANNetworkDetected; |
|
1554 |
|
1555 iServer->EventQueue()->Add( eventInfo ); |
|
1556 LOGIT("SERVER: EVENT -> EConnMonNewWLANNetworkDetected") |
|
1557 } |
|
1558 |
|
1559 LOGEXITFN("CWlanEvent::NewNetworksDetected()") |
|
1560 } |
|
1561 |
|
1562 // ----------------------------------------------------------------------------- |
|
1563 // CWlanEvent::OldNetworksLost |
|
1564 // One or more networks have been lost since the last scan. |
|
1565 // ----------------------------------------------------------------------------- |
|
1566 // |
|
1567 void CWlanEvent::OldNetworksLost() |
|
1568 { |
|
1569 LOGIT(".") |
|
1570 LOGENTRFN("CWlanEvent::OldNetworksLost()") |
|
1571 |
|
1572 if ( iWlanSupport->EventsToClientsEnabled() ) |
|
1573 { |
|
1574 TEventInfo eventInfo; |
|
1575 if ( iWlanAvailable || !iHasAvailabilityKnowledge ) |
|
1576 { |
|
1577 iHasAvailabilityKnowledge = ETrue; |
|
1578 |
|
1579 // Get availability from scan results |
|
1580 TBool availability( EFalse ); |
|
1581 TRAPD( leaveCode, iWlanSupport->GetBearerAvailabilityL( availability ) ); |
|
1582 |
|
1583 if ( !availability && leaveCode == KErrNone ) |
|
1584 { |
|
1585 TUint threshold( 0 ); |
|
1586 iWlanAvailable = EFalse; |
|
1587 |
|
1588 // Check bearer availability threshold |
|
1589 iServer->CalculateThreshold( |
|
1590 EBearerIdAll, |
|
1591 EBearerAvailabilityThreshold, |
|
1592 threshold ); |
|
1593 |
|
1594 // Send the event only if threshold is set by some of the clients |
|
1595 if ( threshold > 0 ) |
|
1596 { |
|
1597 // Create event info |
|
1598 eventInfo.Reset(); |
|
1599 eventInfo.iConnectionId = EBearerIdWLAN; |
|
1600 eventInfo.iEventType = EConnMonBearerAvailabilityChange; |
|
1601 eventInfo.iData = iWlanAvailable; |
|
1602 |
|
1603 // Send EConnMonBearerAvailabilityChange event to clients |
|
1604 iServer->EventQueue()->Add( eventInfo ); |
|
1605 LOGIT1("SERVER: EVENT -> WLAN bearer availability changed: %d (bool)", iWlanAvailable) |
|
1606 } |
|
1607 } |
|
1608 } |
|
1609 |
|
1610 LOGIT("CWlanEvent::OldNetworksLost triggered HandleAvailabilityChange()") |
|
1611 iWlanSupport->EnableWlanScan(); |
|
1612 iServer->AvailabilityManager()->HandleAvailabilityChange(); |
|
1613 |
|
1614 // Create and send EConnMonOldWLANNetworkLost event to clients |
|
1615 eventInfo.Reset(); |
|
1616 eventInfo.iConnectionId = EBearerIdWLAN; |
|
1617 eventInfo.iEventType = EConnMonOldWLANNetworkLost; |
|
1618 |
|
1619 iServer->EventQueue()->Add( eventInfo ); |
|
1620 LOGIT("SERVER: EVENT -> EConnMonOldWLANNetworkLost") |
|
1621 } |
|
1622 |
|
1623 LOGEXITFN("CWlanEvent::OldNetworksLost()") |
|
1624 } |
|
1625 |
|
1626 // ----------------------------------------------------------------------------- |
|
1627 // CWlanEvent::TransmitPowerChanged |
|
1628 // TransmitPower related to the active connection has changed. |
|
1629 // ----------------------------------------------------------------------------- |
|
1630 // |
|
1631 void CWlanEvent::TransmitPowerChanged( TUint aPower ) |
|
1632 { |
|
1633 LOGIT(".") |
|
1634 LOGENTRFN("CWlanEvent::TransmitPowerChanged()") |
|
1635 |
|
1636 iTxPower = aPower; |
|
1637 if ( iWlanSupport->EventsToClientsEnabled() ) |
|
1638 { |
|
1639 LOGIT1("SERVER: EVENT -> WLAN transmit power changed: %d mW", aPower) |
|
1640 TEventInfo eventInfo; |
|
1641 |
|
1642 // Send EConnMonTransmitPowerChange event to clients |
|
1643 eventInfo.Reset(); |
|
1644 eventInfo.iConnectionId = EBearerIdWLAN; |
|
1645 eventInfo.iEventType = EConnMonTransmitPowerChange; |
|
1646 eventInfo.iData = iTxPower; |
|
1647 |
|
1648 iServer->EventQueue()->Add( eventInfo ); |
|
1649 } |
|
1650 |
|
1651 LOGEXITFN("CWlanEvent::TransmitPowerChanged()") |
|
1652 } |
|
1653 |
|
1654 // ----------------------------------------------------------------------------- |
|
1655 // CWlanEvent::ConnectionStateChanged |
|
1656 // Connection status has changed. |
|
1657 // ----------------------------------------------------------------------------- |
|
1658 // |
|
1659 void CWlanEvent::ConnectionStateChanged( TWlanConnectionMode aNewState ) |
|
1660 { |
|
1661 LOGIT(".") |
|
1662 LOGENTRFN("CWlanEvent::ConnectionStateChanged()") |
|
1663 LOGIT1("SERVER: EVENT -> WLAN state changed: %d", aNewState) |
|
1664 |
|
1665 if ( aNewState == EWlanConnectionModeNotConnected ) |
|
1666 { |
|
1667 LOGIT2("RSS class changed from %d to %d (unknown)", iRssClass, EConnMonWlanRssClassUnknown) |
|
1668 iRssClass = EConnMonWlanRssClassUnknown; |
|
1669 } |
|
1670 |
|
1671 LOGEXITFN("CWlanEvent::ConnectionStateChanged()") |
|
1672 } |
|
1673 |
|
1674 // ----------------------------------------------------------------------------- |
|
1675 // CWlanEvent::RssChanged |
|
1676 // Received signal strength level has been changed. |
|
1677 // ----------------------------------------------------------------------------- |
|
1678 // |
|
1679 void CWlanEvent::RssChanged( TWlanRssClass aRssClass, TUint aRss ) |
|
1680 { |
|
1681 LOGIT(".") |
|
1682 LOGENTRFN("CWlanEvent::RssChanged()") |
|
1683 |
|
1684 TInt previousRssClass = iRssClass; |
|
1685 |
|
1686 if ( aRssClass == EWlanRssClassWeak ) |
|
1687 { |
|
1688 LOGIT3("Rss changed from %d to %d dBm class %d (weak)", iRss, aRss, aRssClass) |
|
1689 iRssClass = EConnMonWlanRssClassWeak; |
|
1690 } |
|
1691 else |
|
1692 { |
|
1693 LOGIT3("Rss changed from %d to %d dBm class %d (normal)", iRss, aRss, aRssClass) |
|
1694 iRssClass = EConnMonWlanRssClassNormal; |
|
1695 } |
|
1696 iRss = aRss; |
|
1697 |
|
1698 if ( ( aRssClass == EWlanRssClassWeak && previousRssClass != EConnMonWlanRssClassWeak ) || |
|
1699 ( aRssClass == EWlanRssClassNormal && previousRssClass == EConnMonWlanRssClassWeak ) ) |
|
1700 { |
|
1701 LOGIT("Rss class change caused call to HandleAvailabilityChange()") |
|
1702 iServer->AvailabilityManager()->HandleAvailabilityChange(); |
|
1703 } |
|
1704 |
|
1705 LOGEXITFN("CWlanEvent::RssChanged()") |
|
1706 } |
|
1707 |
|
1708 |
|
1709 // ============================ MEMBER FUNCTIONS =============================== |
|
1710 |
|
1711 |
|
1712 // ----------------------------------------------------------------------------- |
|
1713 // CWlanSession::NewL |
|
1714 // ----------------------------------------------------------------------------- |
|
1715 // |
|
1716 CWlanSession* CWlanSession::NewL( |
|
1717 CConnMonSession* aSessionId, |
|
1718 CWlanSupport* aWlanSupport ) |
|
1719 { |
|
1720 LOGENTRFN("CWlanSession::NewL()") |
|
1721 CWlanSession* self = new( ELeave ) CWlanSession( aSessionId, aWlanSupport ); |
|
1722 LOGEXITFN("CWlanSession::NewL()") |
|
1723 return self; |
|
1724 } |
|
1725 |
|
1726 // ----------------------------------------------------------------------------- |
|
1727 // CWlanSession::CWlanSession |
|
1728 // ----------------------------------------------------------------------------- |
|
1729 // |
|
1730 CWlanSession::CWlanSession( |
|
1731 CConnMonSession* aSessionId, |
|
1732 CWlanSupport* aWlanSupport ) |
|
1733 : |
|
1734 iSessionId( aSessionId ), |
|
1735 iWlanSupport( aWlanSupport ), |
|
1736 iWlanScanMaxDelay( 0 ), |
|
1737 iWlanScanCacheLifetime( -1 ) |
|
1738 { |
|
1739 } |
|
1740 |
|
1741 // ----------------------------------------------------------------------------- |
|
1742 // Destructor |
|
1743 // ----------------------------------------------------------------------------- |
|
1744 // |
|
1745 CWlanSession::~CWlanSession() |
|
1746 { |
|
1747 LOGENTRFN("CWlanSession::~CWlanSession()") |
|
1748 |
|
1749 iSessionId = NULL; |
|
1750 iWlanSupport = NULL; |
|
1751 |
|
1752 if ( iGetScanResultsAO ) |
|
1753 { |
|
1754 delete iGetScanResultsAO; |
|
1755 iGetScanResultsAO = NULL; |
|
1756 } |
|
1757 |
|
1758 if ( iGetSsidScanResultsAO ) |
|
1759 { |
|
1760 delete iGetSsidScanResultsAO; |
|
1761 iGetSsidScanResultsAO = NULL; |
|
1762 } |
|
1763 |
|
1764 // Cleanup message requests array |
|
1765 iWlanRequestsArray.Close(); |
|
1766 |
|
1767 LOGEXITFN("CWlanSession::~CWlanSession()") |
|
1768 } |
|
1769 |
|
1770 // ----------------------------------------------------------------------------- |
|
1771 // CWlanSession::SetWlanScanCacheLifeTime |
|
1772 // ----------------------------------------------------------------------------- |
|
1773 // |
|
1774 void CWlanSession::SetWlanScanCacheLifetime( |
|
1775 const TInt& aWlanScanCacheLifetime ) |
|
1776 { |
|
1777 LOGENTRFN("CWlanSession::SetWlanScanCacheLifetime()") |
|
1778 if ( aWlanScanCacheLifetime < 0 ) |
|
1779 { |
|
1780 iWlanScanCacheLifetime = -1; |
|
1781 } |
|
1782 else |
|
1783 { |
|
1784 iWlanScanCacheLifetime = aWlanScanCacheLifetime; |
|
1785 } |
|
1786 LOGEXITFN("CWlanSession::SetWlanScanCacheLifetime()") |
|
1787 } |
|
1788 |
|
1789 // ----------------------------------------------------------------------------- |
|
1790 // CWlanSession::GetScanResults |
|
1791 // ----------------------------------------------------------------------------- |
|
1792 // |
|
1793 void CWlanSession::GetScanResultsL( const RMessage2& aMessage ) |
|
1794 { |
|
1795 LOGENTRFN("CWlanSession::GetScanResultsL()") |
|
1796 |
|
1797 // Create iGetScanResultsAO |
|
1798 if ( !iGetScanResultsAO ) |
|
1799 { |
|
1800 iGetScanResultsAO = CWlanGetScanResults::NewL( this ); |
|
1801 } |
|
1802 |
|
1803 // Set message to request message table to pend message completion |
|
1804 iWlanRequestsArray.AppendL( aMessage ); |
|
1805 |
|
1806 // Check if AO already active |
|
1807 if ( !( iGetScanResultsAO->IsActive() ) ) |
|
1808 { |
|
1809 // Start listening when scan results are ready |
|
1810 iGetScanResultsAO->StartL(); |
|
1811 } |
|
1812 |
|
1813 LOGEXITFN("CWlanSession::GetScanResultsL()") |
|
1814 } |
|
1815 |
|
1816 // ----------------------------------------------------------------------------- |
|
1817 // CWlanSession::GetSsidScanResultsL |
|
1818 // ----------------------------------------------------------------------------- |
|
1819 // |
|
1820 TInt CWlanSession::GetSsidScanResultsL( const RMessage2& aMessage ) |
|
1821 { |
|
1822 LOGENTRFN("CWlanSession::GetSsidScanResultsL()") |
|
1823 TInt result( KRequestPending ); |
|
1824 |
|
1825 // Create iGetSsidScanResultsAO |
|
1826 if ( !iGetSsidScanResultsAO ) |
|
1827 { |
|
1828 iGetSsidScanResultsAO = CWlanGetSsidScanResults::NewL( this ); |
|
1829 } |
|
1830 |
|
1831 // Check if AO already active |
|
1832 if ( !( iGetSsidScanResultsAO->IsActive() ) ) |
|
1833 { |
|
1834 // Set message to request message table to pend message completion |
|
1835 // NOTE: ConnMon will allow only 1 concurrent ssid scan from a client. |
|
1836 iWlanRequestsArray.AppendL( aMessage ); |
|
1837 |
|
1838 // Start listening when scan results are ready |
|
1839 iGetSsidScanResultsAO->StartL( iWlanSsid ); |
|
1840 } |
|
1841 else |
|
1842 { |
|
1843 // Only one SSID scan can be done at a time. |
|
1844 // Allowing more would cause conflicts with string attribute KWlanSsid |
|
1845 result = KErrInUse; |
|
1846 } |
|
1847 |
|
1848 LOGEXITFN1("CWlanSession::GetSsidScanResultsL()", result) |
|
1849 return result; |
|
1850 } |
|
1851 |
|
1852 |
|
1853 // ----------------------------------------------------------------------------- |
|
1854 // CWlanSession::CancelActiveRequests |
|
1855 // ----------------------------------------------------------------------------- |
|
1856 // |
|
1857 void CWlanSession::CancelActiveRequests( const TInt aReqType ) |
|
1858 { |
|
1859 LOGENTRFN("CWlanSession::CancelActiveRequests()") |
|
1860 TBool otherReqTypesInQueue = EFalse; |
|
1861 TBool ssidScanInQueue = EFalse; |
|
1862 TBool normalScanInQueue = EFalse; |
|
1863 |
|
1864 LOGIT2("Request type %d, requests waiting %d", aReqType, iWlanRequestsArray.Count()) |
|
1865 |
|
1866 for ( TInt index = 0; index < iWlanRequestsArray.Count(); index++ ) |
|
1867 { |
|
1868 TUint attribType = iWlanRequestsArray[index].Int2(); |
|
1869 LOGIT1("Attribute type %d", attribType) |
|
1870 switch ( aReqType ) |
|
1871 { |
|
1872 case EConnMonGetPckgAttribute: |
|
1873 if ( ( attribType == KNetworkNames ) || |
|
1874 ( attribType == KWlanNetworks ) || |
|
1875 ( attribType == KWlanProbeRawBuffers ) ) |
|
1876 { |
|
1877 normalScanInQueue = ETrue; |
|
1878 iWlanRequestsArray[index].Complete( KErrCancel ); |
|
1879 iWlanRequestsArray.Remove( index ); |
|
1880 index--; |
|
1881 } |
|
1882 else if ( attribType == KWlanSsidNetworks ) |
|
1883 { |
|
1884 ssidScanInQueue = ETrue; // Ssid scan |
|
1885 iWlanRequestsArray[index].Complete( KErrCancel ); |
|
1886 iWlanRequestsArray.Remove( index ); |
|
1887 index--; |
|
1888 } |
|
1889 else |
|
1890 { |
|
1891 // Non-cancelled requests still remain. |
|
1892 otherReqTypesInQueue = ETrue; |
|
1893 } |
|
1894 break; |
|
1895 |
|
1896 case EConnMonGetIntAttribute: |
|
1897 if ( KSignalStrength == attribType ) |
|
1898 { |
|
1899 normalScanInQueue = ETrue; |
|
1900 iWlanRequestsArray[index].Complete( KErrCancel ); |
|
1901 iWlanRequestsArray.Remove( index ); |
|
1902 index--; |
|
1903 } |
|
1904 else |
|
1905 { |
|
1906 // Non-cancelled requests still remain. |
|
1907 otherReqTypesInQueue = ETrue; |
|
1908 } |
|
1909 break; |
|
1910 |
|
1911 case EConnMonGetBoolAttribute: |
|
1912 if ( KBearerAvailability == attribType ) |
|
1913 { |
|
1914 normalScanInQueue = ETrue; |
|
1915 iWlanRequestsArray[index].Complete( KErrCancel ); |
|
1916 iWlanRequestsArray.Remove( index ); |
|
1917 index--; |
|
1918 } |
|
1919 else |
|
1920 { |
|
1921 // Non-cancelled requests still remain. |
|
1922 otherReqTypesInQueue = ETrue; |
|
1923 } |
|
1924 break; |
|
1925 |
|
1926 default: |
|
1927 // Nothing about async WLAN calls in other request types |
|
1928 break; |
|
1929 } |
|
1930 } |
|
1931 LOGIT3("Flags: other req. types %d, normal scan %d, ssid scan %d", |
|
1932 otherReqTypesInQueue, normalScanInQueue, ssidScanInQueue) |
|
1933 |
|
1934 if ( ssidScanInQueue ) |
|
1935 { |
|
1936 // iGetSsidScanResultsAO only listens to a single type of request, |
|
1937 // it can be safely cancelled and deleted. |
|
1938 if ( iGetSsidScanResultsAO ) |
|
1939 { |
|
1940 LOGIT("Cancel and delete iGetSsidScanResultsAO") |
|
1941 iGetSsidScanResultsAO->Cancel(); |
|
1942 } |
|
1943 } |
|
1944 |
|
1945 if ( normalScanInQueue && ( !otherReqTypesInQueue ) ) |
|
1946 { |
|
1947 if ( iGetScanResultsAO ) |
|
1948 { |
|
1949 LOGIT("Cancel and delete iGetScanResultsAO") |
|
1950 iGetScanResultsAO->Cancel(); |
|
1951 } |
|
1952 } |
|
1953 |
|
1954 LOGEXITFN("CWlanSession::CancelActiveRequests()") |
|
1955 } |
|
1956 |
|
1957 // ----------------------------------------------------------------------------- |
|
1958 // CWlanSession::CompleteActiveRequestsWithError |
|
1959 // ----------------------------------------------------------------------------- |
|
1960 // |
|
1961 void CWlanSession::CompleteActiveRequestsWithError( |
|
1962 const TInt aErrorCode, |
|
1963 const TBool aSsidScan ) |
|
1964 { |
|
1965 //LOGENTRFN("CWlanSession::CompleteActiveRequestsWithError()") |
|
1966 |
|
1967 LOGIT3("Cancelling wlan requests (%d), ssid flag %d, error code <%d>", |
|
1968 iWlanRequestsArray.Count(), aSsidScan, aErrorCode) |
|
1969 for ( TInt index = 0; index < iWlanRequestsArray.Count(); index++ ) |
|
1970 { |
|
1971 TInt type = iWlanRequestsArray[index].Int2(); |
|
1972 |
|
1973 // Check if request came from SSID scan |
|
1974 if ( aSsidScan ) |
|
1975 { |
|
1976 // Complete only KWlanSsidNetworks request(s) |
|
1977 if ( type == KWlanSsidNetworks ) |
|
1978 { |
|
1979 LOGIT("Cancelled a wlan request, type: ssid") |
|
1980 iWlanRequestsArray[index].Complete( aErrorCode ); |
|
1981 iWlanRequestsArray.Remove( index ); |
|
1982 index--; |
|
1983 } |
|
1984 } |
|
1985 else // Otherwise, complete all other messages |
|
1986 { |
|
1987 if ( type == KBearerAvailability || |
|
1988 type == KSignalStrength || |
|
1989 type == KNetworkNames || |
|
1990 type == KWlanNetworks || |
|
1991 type == KWlanProbeRawBuffers ) |
|
1992 { |
|
1993 LOGIT("Cancelled a wlan request, type: normal") |
|
1994 iWlanRequestsArray[index].Complete( aErrorCode ); |
|
1995 iWlanRequestsArray.Remove( index ); |
|
1996 index--; |
|
1997 } |
|
1998 } |
|
1999 } |
|
2000 //LOGEXITFN("CWlanSession::CompleteActiveRequestsWithError()") |
|
2001 } |
|
2002 |
|
2003 // ----------------------------------------------------------------------------- |
|
2004 // CWlanSession::CompleteActiveRequests |
|
2005 // ----------------------------------------------------------------------------- |
|
2006 // |
|
2007 void CWlanSession::CompleteActiveRequestsL( |
|
2008 const TInt aStatus, |
|
2009 CWlanScanInfo* aScanInfo, |
|
2010 const TBool aSsidScan ) |
|
2011 { |
|
2012 LOGENTRFN("CWlanSession::CompleteActiveRequestsL()") |
|
2013 |
|
2014 // Check status |
|
2015 if ( KErrNone != aStatus ) |
|
2016 { |
|
2017 LOGIT1("CWlanSession::CompleteActiveRequestsL(): WLAN scanning failed, err <%d>", aStatus) |
|
2018 CompleteActiveRequestsWithError( aStatus, aSsidScan ); |
|
2019 } |
|
2020 else |
|
2021 { |
|
2022 LOGIT("CWlanSession::CompleteActiveRequestsL(): WLAN scanning successful") |
|
2023 |
|
2024 // Complete messages according to message type |
|
2025 for ( TUint index = 0; index < iWlanRequestsArray.Count(); index++ ) |
|
2026 { |
|
2027 TUint type = iWlanRequestsArray[index].Int2(); |
|
2028 |
|
2029 // Check if request came from SSID scan |
|
2030 if ( aSsidScan ) |
|
2031 { |
|
2032 // Complete only KWlanSsidNetworks message |
|
2033 if ( type == KWlanSsidNetworks ) |
|
2034 { |
|
2035 LOGIT("CWlanSession::CompleteActiveRequestsL(): complete KWlanSsidNetworks") |
|
2036 CompleteGetWlanSsidNetworksRequestL( aScanInfo, index ); |
|
2037 iWlanRequestsArray.Remove( index ); |
|
2038 index--; |
|
2039 } |
|
2040 } |
|
2041 else // Complete all other messages |
|
2042 { |
|
2043 if ( type == KBearerAvailability ) |
|
2044 { |
|
2045 LOGIT("CWlanSession::CompleteActiveRequestsL(): complete KBearerAvailability") |
|
2046 CompleteGetBearerAvailabilityRequest( aScanInfo, index ); |
|
2047 iWlanRequestsArray.Remove( index ); |
|
2048 index--; |
|
2049 } |
|
2050 |
|
2051 else if ( type == KSignalStrength ) |
|
2052 { |
|
2053 LOGIT("CWlanSession::CompleteActiveRequestsL(): complete KSignalStrength") |
|
2054 CompleteGetSignalStrengthRequest( aScanInfo, index ); |
|
2055 iWlanRequestsArray.Remove( index ); |
|
2056 index--; |
|
2057 } |
|
2058 |
|
2059 else if ( type == KNetworkNames ) |
|
2060 { |
|
2061 LOGIT("CWlanSession::CompleteActiveRequestsL(): complete KNetworkNames") |
|
2062 CompleteGetNetworkNamesRequestL( aScanInfo, index ); |
|
2063 iWlanRequestsArray.Remove( index ); |
|
2064 index--; |
|
2065 } |
|
2066 |
|
2067 else if ( type == KWlanNetworks ) |
|
2068 { |
|
2069 LOGIT("CWlanSession::CompleteActiveRequestsL(): complete KWlanNetworks") |
|
2070 CompleteGetWlanNetworksRequestL( aScanInfo, index ); |
|
2071 iWlanRequestsArray.Remove( index ); |
|
2072 index--; |
|
2073 } |
|
2074 |
|
2075 else if ( type == KWlanProbeRawBuffers ) |
|
2076 { |
|
2077 LOGIT("CWlanSession::CompleteActiveRequestsL(): complete KWlanProbeRawBuffers") |
|
2078 CompleteGetWlanProbeRawBuffersRequestL( aScanInfo, index ); |
|
2079 iWlanRequestsArray.Remove( index ); |
|
2080 index--; |
|
2081 } |
|
2082 } |
|
2083 } |
|
2084 } |
|
2085 |
|
2086 LOGEXITFN("CWlanSession::CompleteActiveRequestsL()") |
|
2087 } |
|
2088 |
|
2089 |
|
2090 |
|
2091 // ----------------------------------------------------------------------------- |
|
2092 // CWlanSession::CompleteGetBearerAvailabilityRequest |
|
2093 // Completes the asynchronous client request: GetBoolAttribute( KBearerAvailability ) |
|
2094 // ----------------------------------------------------------------------------- |
|
2095 // |
|
2096 void CWlanSession::CompleteGetBearerAvailabilityRequest( |
|
2097 CWlanScanInfo* aScanInfo, |
|
2098 const TUint aIndex ) |
|
2099 { |
|
2100 LOGENTRFN("CWlanSession::CompleteGetBearerAvailabilityRequest()") |
|
2101 TBool availability = EFalse; |
|
2102 |
|
2103 // Set pointer to first IAP, just in case |
|
2104 aScanInfo->First(); |
|
2105 |
|
2106 // Check scan results |
|
2107 if ( aScanInfo->IsDone() ) |
|
2108 { |
|
2109 // No WLAN networks available |
|
2110 availability = EFalse; |
|
2111 } |
|
2112 else |
|
2113 { |
|
2114 // Found WLAN networks |
|
2115 availability = ETrue; |
|
2116 } |
|
2117 |
|
2118 LOGIT1("CompleteGetBearerAvailabilityRequest: availability %d", availability) |
|
2119 |
|
2120 // Write result back to client's address space, and complete message |
|
2121 TPtrC8 d( reinterpret_cast<TUint8*>( &availability ), sizeof( availability ) ); |
|
2122 TInt res = iWlanRequestsArray[aIndex].Write( KAttributeParameterIndex, d ); |
|
2123 if ( KErrNone != res ) |
|
2124 { |
|
2125 LOGIT1("ERROR writing data to client <%d>", res) |
|
2126 iWlanRequestsArray[aIndex].Complete( KErrBadDescriptor ); |
|
2127 } |
|
2128 else |
|
2129 { |
|
2130 iWlanRequestsArray[aIndex].Complete( KErrNone ); |
|
2131 } |
|
2132 |
|
2133 LOGEXITFN("CWlanSession::CompleteGetBearerAvailabilityRequest()") |
|
2134 } |
|
2135 |
|
2136 |
|
2137 // ----------------------------------------------------------------------------- |
|
2138 // CWlanSession::CompleteGetSignalStrengthRequest |
|
2139 // Completes the asynchronous client request: GetIntAttribute ( KSignalStrength ) |
|
2140 // ----------------------------------------------------------------------------- |
|
2141 // |
|
2142 void CWlanSession::CompleteGetSignalStrengthRequest( |
|
2143 CWlanScanInfo* aScanInfo, |
|
2144 const TUint aIndex ) |
|
2145 { |
|
2146 LOGENTRFN("CWlanSession::CompleteGetSignalStrengthRequest()") |
|
2147 TInt signalStrength( KMaxTInt ); // Means infinitely weak |
|
2148 |
|
2149 // Iterate through scan results. |
|
2150 for ( aScanInfo->First(); !aScanInfo->IsDone(); aScanInfo->Next() ) |
|
2151 { |
|
2152 // RXLevel() returns signal strength in unsigned dBm (-60dBm == 60dBm) |
|
2153 if ( static_cast<TInt>( aScanInfo->RXLevel() ) < signalStrength ) |
|
2154 { |
|
2155 signalStrength = static_cast<TInt>( aScanInfo->RXLevel() ); |
|
2156 } |
|
2157 } |
|
2158 |
|
2159 LOGIT1("CWlanSession::CompleteGetSignalStrengthRequest(): signalStrength %d", signalStrength) |
|
2160 |
|
2161 // Write result back to client's address space, and complete message |
|
2162 TPtrC8 d( reinterpret_cast<TUint8*>( &signalStrength ), sizeof( signalStrength ) ); |
|
2163 TInt res = iWlanRequestsArray[aIndex].Write( KAttributeParameterIndex, d ); |
|
2164 if ( res != KErrNone ) |
|
2165 { |
|
2166 LOGIT1("ERROR writing data to client <%d>", res) |
|
2167 iWlanRequestsArray[aIndex].Complete( KErrBadDescriptor ); |
|
2168 } |
|
2169 else |
|
2170 { |
|
2171 iWlanRequestsArray[aIndex].Complete( KErrNone ); |
|
2172 } |
|
2173 |
|
2174 LOGEXITFN("CWlanSession::CompleteGetSignalStrengthRequest()") |
|
2175 } |
|
2176 |
|
2177 // ----------------------------------------------------------------------------- |
|
2178 // CWlanSession::CompleteGetNetworkNamesRequest |
|
2179 // Completes the asynchronous client request: GetPckgAttribute( KNetworkNames ) |
|
2180 // ----------------------------------------------------------------------------- |
|
2181 // |
|
2182 void CWlanSession::CompleteGetNetworkNamesRequestL( |
|
2183 CWlanScanInfo* aScanInfo, |
|
2184 const TUint aIndex ) |
|
2185 { |
|
2186 LOGENTRFN("CWlanSession::CompleteGetNetworkNamesRequestL()") |
|
2187 TConnMonNetworkNames netInfo; |
|
2188 |
|
2189 // Parse network names |
|
2190 iWlanSupport->ParseNetworkNamesL( aScanInfo, netInfo ); |
|
2191 |
|
2192 // Write result back to client's address space, and complete message |
|
2193 TConnMonNetworkNamesBuf namesBuf( netInfo ); |
|
2194 TInt res = iWlanRequestsArray[aIndex].Write( KAttributeParameterIndex, namesBuf ); |
|
2195 if ( KErrNone != res ) |
|
2196 { |
|
2197 LOGIT1("ERROR writing data to client <%d>", res) |
|
2198 iWlanRequestsArray[aIndex].Complete( KErrBadDescriptor ); |
|
2199 } |
|
2200 else |
|
2201 { |
|
2202 iWlanRequestsArray[aIndex].Complete( KErrNone ); |
|
2203 } |
|
2204 |
|
2205 LOGEXITFN("CWlanSession::CompleteGetNetworkNamesRequestL()") |
|
2206 } |
|
2207 |
|
2208 // ----------------------------------------------------------------------------- |
|
2209 // CWlanSession::CompleteGetWlanNetworksRequest |
|
2210 // Completes the asynchronous client request: GetPckgAttribute( KWlanNetworks ) |
|
2211 // ----------------------------------------------------------------------------- |
|
2212 // |
|
2213 void CWlanSession::CompleteGetWlanNetworksRequestL( |
|
2214 CWlanScanInfo* aScanInfo, |
|
2215 const TUint aIndex ) |
|
2216 { |
|
2217 LOGENTRFN("CWlanSession::CompleteGetWlanNetworksRequestL()") |
|
2218 |
|
2219 TInt maxSize( iWlanRequestsArray[aIndex].GetDesMaxLength( KAttributeParameterIndex ) ); |
|
2220 if ( maxSize < 2 ) |
|
2221 { |
|
2222 LOGIT1("ERROR with message descriptor <%d>", maxSize) |
|
2223 iWlanRequestsArray[aIndex].Complete( KErrBadDescriptor ); |
|
2224 } |
|
2225 else |
|
2226 { |
|
2227 RConnMonWlanNetworksPtrArray wlanNetworks; |
|
2228 ConnMonCleanupResetAndDestroyPushL( wlanNetworks ); |
|
2229 |
|
2230 // Parse WLAN networks |
|
2231 iWlanSupport->ParseWlanNetworksL( aScanInfo, wlanNetworks ); |
|
2232 |
|
2233 CConnMonWlanNetworksPtrArrayPckg arr( wlanNetworks, maxSize ); // maxSize >= 2 |
|
2234 CleanupStack::PopAndDestroy( &wlanNetworks ); |
|
2235 |
|
2236 if ( !arr.Buf() ) |
|
2237 { |
|
2238 LOGIT("ERROR no memory for CConnMonWlanNetworksPtrArrayPckg") |
|
2239 iWlanRequestsArray[aIndex].Complete( KErrNoMemory ); |
|
2240 } |
|
2241 else |
|
2242 { |
|
2243 // Write result back to client's address space, and complete message |
|
2244 TInt res = iWlanRequestsArray[aIndex].Write( KAttributeParameterIndex, *arr.Buf() ); |
|
2245 if ( res != KErrNone ) |
|
2246 { |
|
2247 LOGIT1("ERROR writing data to client <%d>", res) |
|
2248 iWlanRequestsArray[aIndex].Complete( KErrBadDescriptor ); |
|
2249 } |
|
2250 else |
|
2251 { |
|
2252 iWlanRequestsArray[aIndex].Complete( KErrNone ); |
|
2253 } |
|
2254 } |
|
2255 } |
|
2256 |
|
2257 LOGEXITFN("CWlanSession::CompleteGetWlanNetworksRequestL()") |
|
2258 } |
|
2259 |
|
2260 // ----------------------------------------------------------------------------- |
|
2261 // CWlanSession::CompleteGetWlanSsidNetworksRequest |
|
2262 // Completes the asynchronous client request: GetPckgAttribute( KWlanSsidNetworks ) |
|
2263 // ----------------------------------------------------------------------------- |
|
2264 // |
|
2265 void CWlanSession::CompleteGetWlanSsidNetworksRequestL( |
|
2266 CWlanScanInfo* aScanInfo, |
|
2267 const TUint aIndex ) |
|
2268 { |
|
2269 LOGENTRFN("CWlanSession::CompleteGetWlanSsidNetworksRequestL()") |
|
2270 |
|
2271 TInt maxSize( iWlanRequestsArray[aIndex].GetDesMaxLength( KAttributeParameterIndex ) ); |
|
2272 if ( maxSize < 2 ) |
|
2273 { |
|
2274 LOGIT1("ERROR with message descriptor <%d>", maxSize) |
|
2275 iWlanRequestsArray[aIndex].Complete( KErrBadDescriptor ); |
|
2276 } |
|
2277 else |
|
2278 { |
|
2279 RConnMonWlanNetworksPtrArray wlanNetworks; |
|
2280 ConnMonCleanupResetAndDestroyPushL( wlanNetworks ); |
|
2281 |
|
2282 // Parse WLAN networks |
|
2283 iWlanSupport->ParseWlanNetworksL( aScanInfo, wlanNetworks ); |
|
2284 |
|
2285 CConnMonWlanNetworksPtrArrayPckg arr( wlanNetworks, maxSize ); // maxSize >= 2 |
|
2286 CleanupStack::PopAndDestroy( &wlanNetworks ); |
|
2287 |
|
2288 if ( !arr.Buf() ) |
|
2289 { |
|
2290 LOGIT("ERROR no memory for CConnMonWlanNetworksPtrArrayPckg") |
|
2291 iWlanRequestsArray[aIndex].Complete( KErrNoMemory ); |
|
2292 } |
|
2293 else |
|
2294 { |
|
2295 // Write result back to client's address space, and complete message |
|
2296 TInt res = iWlanRequestsArray[aIndex].Write( KAttributeParameterIndex, *arr.Buf() ); |
|
2297 if ( res != KErrNone ) |
|
2298 { |
|
2299 LOGIT1("ERROR writing data to client <%d>", res) |
|
2300 iWlanRequestsArray[aIndex].Complete( KErrBadDescriptor ); |
|
2301 } |
|
2302 else |
|
2303 { |
|
2304 iWlanRequestsArray[aIndex].Complete( KErrNone ); |
|
2305 } |
|
2306 } |
|
2307 } |
|
2308 |
|
2309 LOGEXITFN("CWlanSession::CompleteGetWlanSsidNetworksRequestL()") |
|
2310 } |
|
2311 |
|
2312 // ----------------------------------------------------------------------------- |
|
2313 // CWlanSession::CompleteGetWlanProbeRawBuffersRequest |
|
2314 // Completes the asynchronous client request: GetPckgAttribute( KWlanProbeRawBuffers ) |
|
2315 // ----------------------------------------------------------------------------- |
|
2316 // |
|
2317 void CWlanSession::CompleteGetWlanProbeRawBuffersRequestL( |
|
2318 CWlanScanInfo* aScanInfo, |
|
2319 const TUint aIndex ) |
|
2320 { |
|
2321 LOGENTRFN("CWlanSession::CompleteGetWlanProbeRawBuffersRequestL()") |
|
2322 |
|
2323 TInt maxSize( iWlanRequestsArray[aIndex].GetDesMaxLength( KAttributeParameterIndex ) ); |
|
2324 if ( maxSize < 2 ) |
|
2325 { |
|
2326 LOGIT1("ERROR with message descriptor <%d>", maxSize) |
|
2327 iWlanRequestsArray[aIndex].Complete( KErrBadDescriptor ); |
|
2328 } |
|
2329 else |
|
2330 { |
|
2331 RConnMonWlanProbeRawBuffersPtrArray wlanProbeRawBuffers; |
|
2332 ConnMonCleanupResetAndDestroyPushL( wlanProbeRawBuffers ); |
|
2333 |
|
2334 // Parse raw buffers networks |
|
2335 iWlanSupport->ParseWlanProbeRawBuffersL( aScanInfo, wlanProbeRawBuffers ); |
|
2336 |
|
2337 CConnMonWlanProbeRawBuffersPckg arr( wlanProbeRawBuffers, maxSize ); // maxSize >= 2 |
|
2338 CleanupStack::PopAndDestroy( &wlanProbeRawBuffers ); |
|
2339 |
|
2340 if ( !arr.Buf() ) |
|
2341 { |
|
2342 LOGIT("ERROR no memory for CConnMonWlanProbeRawBuffersPckg") |
|
2343 iWlanRequestsArray[aIndex].Complete( KErrNoMemory ); |
|
2344 } |
|
2345 else |
|
2346 { |
|
2347 // Write result back to client's address space, and complete message |
|
2348 TInt res = iWlanRequestsArray[aIndex].Write( KAttributeParameterIndex, *arr.Buf() ); |
|
2349 if ( KErrNone != res ) |
|
2350 { |
|
2351 LOGIT1("ERROR writing data to client <%d>", res) |
|
2352 iWlanRequestsArray[aIndex].Complete( KErrBadDescriptor ); |
|
2353 } |
|
2354 else |
|
2355 { |
|
2356 iWlanRequestsArray[aIndex].Complete( KErrNone ); |
|
2357 } |
|
2358 } |
|
2359 } |
|
2360 |
|
2361 LOGEXITFN("CWlanSession::CompleteGetWlanProbeRawBuffersRequestL()") |
|
2362 } |
|
2363 |
|
2364 |
|
2365 // =========================== MEMBER FUNCTIONS =============================== |
|
2366 |
|
2367 // ----------------------------------------------------------------------------- |
|
2368 // CWlanGetScanResults::NewL |
|
2369 // ----------------------------------------------------------------------------- |
|
2370 // |
|
2371 CWlanGetScanResults* CWlanGetScanResults::NewL( CWlanSession* aWlanSession ) |
|
2372 { |
|
2373 LOGENTRFN("CWlanGetScanResults::NewL()") |
|
2374 CWlanGetScanResults* self = new( ELeave ) CWlanGetScanResults( aWlanSession ); |
|
2375 |
|
2376 CleanupStack::PushL( self ); |
|
2377 self->ConstructL(); |
|
2378 CleanupStack::Pop( self ); |
|
2379 |
|
2380 LOGEXITFN("CWlanGetScanResults::NewL()") |
|
2381 return self; |
|
2382 } |
|
2383 |
|
2384 // ----------------------------------------------------------------------------- |
|
2385 // CWlanGetScanResults::CWlanGetScanResults |
|
2386 // ----------------------------------------------------------------------------- |
|
2387 // |
|
2388 CWlanGetScanResults::CWlanGetScanResults( |
|
2389 CWlanSession* aWlanSession ) |
|
2390 : |
|
2391 CActive( EConnMonPriorityNormal ), |
|
2392 iWlanSession( aWlanSession ) |
|
2393 { |
|
2394 } |
|
2395 |
|
2396 // ----------------------------------------------------------------------------- |
|
2397 // CWlanGetScanResults::ConstructL |
|
2398 // ----------------------------------------------------------------------------- |
|
2399 // |
|
2400 void CWlanGetScanResults::ConstructL() |
|
2401 { |
|
2402 iWlanMgmt = CWlanMgmtClient::NewL(); |
|
2403 CActiveScheduler::Add( this ); |
|
2404 } |
|
2405 |
|
2406 // ----------------------------------------------------------------------------- |
|
2407 // CWlanGetScanResults::~CWlanGetScanResults |
|
2408 // ----------------------------------------------------------------------------- |
|
2409 // |
|
2410 CWlanGetScanResults::~CWlanGetScanResults() |
|
2411 { |
|
2412 LOGENTRFN("CWlanGetScanResults::~CWlanGetScanResults()") |
|
2413 |
|
2414 Cancel(); |
|
2415 |
|
2416 if ( iWlanMgmt ) |
|
2417 { |
|
2418 delete iWlanMgmt; |
|
2419 iWlanMgmt = NULL; |
|
2420 } |
|
2421 |
|
2422 if ( iScanInfo ) |
|
2423 { |
|
2424 delete iScanInfo; |
|
2425 iScanInfo = NULL; |
|
2426 } |
|
2427 |
|
2428 LOGEXITFN("CWlanGetScanResults::~CWlanGetScanResults()") |
|
2429 } |
|
2430 |
|
2431 // ----------------------------------------------------------------------------- |
|
2432 // CWlanGetScanResults::StartL |
|
2433 // ----------------------------------------------------------------------------- |
|
2434 // |
|
2435 void CWlanGetScanResults::StartL() |
|
2436 { |
|
2437 LOGENTRFN("CWlanGetScanResults::StartL()") |
|
2438 |
|
2439 if ( IsActive() ) |
|
2440 { |
|
2441 LOGIT("CWlanGetScanResults::StartL(): Already active, calling Cancel()") |
|
2442 Cancel(); |
|
2443 } |
|
2444 |
|
2445 // Create scaninfo object for scan results |
|
2446 if ( !iScanInfo ) |
|
2447 { |
|
2448 iScanInfo = CWlanScanInfo::NewL(); |
|
2449 } |
|
2450 |
|
2451 // Get scan results from WLAN engine |
|
2452 TInt oldWlanScanCacheLifetime( iWlanSession->GetWlanScanCacheLifetime() ); |
|
2453 TInt newWlanScanCacheLifetime( oldWlanScanCacheLifetime ); |
|
2454 |
|
2455 TUint oldWlanScanMaxDelay( iWlanSession->GetWlanScanMaxDelay() ); |
|
2456 TUint newWlanScanMaxDelay( oldWlanScanMaxDelay ); |
|
2457 |
|
2458 TBuf8<CConnMonWlanNetwork::KMaxNameLength> emptySsid( 0 ); |
|
2459 LOGIT2("wlanScanCacheLifetime %d, wlanScanMaxDelay %d", |
|
2460 newWlanScanCacheLifetime, newWlanScanMaxDelay) |
|
2461 iWlanMgmt->GetScanResults( |
|
2462 newWlanScanCacheLifetime, |
|
2463 newWlanScanMaxDelay, |
|
2464 emptySsid, |
|
2465 iStatus, |
|
2466 *iScanInfo ); |
|
2467 |
|
2468 // Check if wlan engine has changed the timing parameters |
|
2469 if ( oldWlanScanCacheLifetime != newWlanScanCacheLifetime ) |
|
2470 { |
|
2471 LOGIT2("CWlanGetScanResults::StartL(): wlanScanCacheLifetime changed from %d to %d", |
|
2472 oldWlanScanCacheLifetime, newWlanScanCacheLifetime) |
|
2473 iWlanSession->SetWlanScanCacheLifetime( newWlanScanCacheLifetime ); |
|
2474 } |
|
2475 if ( oldWlanScanMaxDelay != newWlanScanMaxDelay ) |
|
2476 { |
|
2477 LOGIT2("CWlanGetScanResults::StartL(): wlanScanMaxDelay changed from %d to %d", |
|
2478 oldWlanScanMaxDelay, newWlanScanMaxDelay) |
|
2479 iWlanSession->SetWlanScanMaxDelay( newWlanScanMaxDelay ); |
|
2480 } |
|
2481 |
|
2482 // Start listening when scan results are ready |
|
2483 SetActive(); |
|
2484 |
|
2485 LOGIT3("wlanScanCacheLifetime %d, wlanScanMaxDelay %d, status <%d>", |
|
2486 newWlanScanCacheLifetime, newWlanScanMaxDelay, iStatus.Int()) |
|
2487 LOGEXITFN("CWlanGetScanResults::StartL()") |
|
2488 } |
|
2489 |
|
2490 // ----------------------------------------------------------------------------- |
|
2491 // CWlanGetScanResults::DoCancel |
|
2492 // ----------------------------------------------------------------------------- |
|
2493 // |
|
2494 void CWlanGetScanResults::DoCancel() |
|
2495 { |
|
2496 LOGIT("CWlanGetScanResults::DoCancel()") |
|
2497 |
|
2498 if ( IsActive() ) |
|
2499 { |
|
2500 // Cancel async request from WLAN engine |
|
2501 iWlanMgmt->CancelGetScanResults(); |
|
2502 } |
|
2503 } |
|
2504 |
|
2505 // ----------------------------------------------------------------------------- |
|
2506 // CWlanGetScanResults::RunL |
|
2507 // ----------------------------------------------------------------------------- |
|
2508 // |
|
2509 void CWlanGetScanResults::RunL() |
|
2510 { |
|
2511 LOGIT(".") |
|
2512 LOGIT1("CWlanGetScanResults::RunL(): sessionId %d", iWlanSession->GetSessionId()) |
|
2513 |
|
2514 // Complete all session requests |
|
2515 iWlanSession->CompleteActiveRequestsL( iStatus.Int(), iScanInfo, EFalse ); |
|
2516 |
|
2517 // Delete scaninfo object to save memory |
|
2518 if ( iScanInfo ) |
|
2519 { |
|
2520 delete iScanInfo; |
|
2521 iScanInfo = NULL; |
|
2522 } |
|
2523 } |
|
2524 |
|
2525 // ----------------------------------------------------------------------------- |
|
2526 // CWlanGetScanResults::RunError |
|
2527 // ----------------------------------------------------------------------------- |
|
2528 // |
|
2529 TInt CWlanGetScanResults::RunError( TInt aLeaveCode ) |
|
2530 { |
|
2531 //LOGENTRFN("CWlanGetScanResults::RunError()") |
|
2532 |
|
2533 LOGIT1("CWlanGetScanResults::RunError() <%d>", aLeaveCode) |
|
2534 iWlanSession->CompleteActiveRequestsWithError( aLeaveCode, EFalse ); |
|
2535 |
|
2536 //LOGEXITFN("CWlanGetScanResults::RunError()") |
|
2537 return KErrNone; |
|
2538 } |
|
2539 |
|
2540 |
|
2541 // =========================== MEMBER FUNCTIONS =============================== |
|
2542 |
|
2543 // ----------------------------------------------------------------------------- |
|
2544 // CWlanGetSsidScanResults::NewL |
|
2545 // ----------------------------------------------------------------------------- |
|
2546 // |
|
2547 CWlanGetSsidScanResults* CWlanGetSsidScanResults::NewL( |
|
2548 CWlanSession* aWlanSession ) |
|
2549 { |
|
2550 LOGENTRFN("CWlanGetSsidScanResults::NewL()") |
|
2551 CWlanGetSsidScanResults* self = new( ELeave ) CWlanGetSsidScanResults( aWlanSession ); |
|
2552 |
|
2553 CleanupStack::PushL( self ); |
|
2554 self->ConstructL(); |
|
2555 CleanupStack::Pop( self ); |
|
2556 |
|
2557 LOGEXITFN("CWlanGetSsidScanResults::NewL()") |
|
2558 return self; |
|
2559 } |
|
2560 |
|
2561 // ----------------------------------------------------------------------------- |
|
2562 // CWlanGetSsidScanResults::CWlanGetSsidScanResults |
|
2563 // ----------------------------------------------------------------------------- |
|
2564 // |
|
2565 CWlanGetSsidScanResults::CWlanGetSsidScanResults( |
|
2566 CWlanSession* aWlanSession ) |
|
2567 : |
|
2568 CActive( EConnMonPriorityNormal ), |
|
2569 iWlanSession( aWlanSession ) |
|
2570 { |
|
2571 } |
|
2572 |
|
2573 // ----------------------------------------------------------------------------- |
|
2574 // CWlanGetSsidScanResults::ConstructL |
|
2575 // ----------------------------------------------------------------------------- |
|
2576 // |
|
2577 void CWlanGetSsidScanResults::ConstructL() |
|
2578 { |
|
2579 iWlanMgmt = CWlanMgmtClient::NewL(); |
|
2580 CActiveScheduler::Add( this ); |
|
2581 } |
|
2582 |
|
2583 // ----------------------------------------------------------------------------- |
|
2584 // CWlanGetSsidScanResults::~CWlanGetSsidScanResults |
|
2585 // ----------------------------------------------------------------------------- |
|
2586 // |
|
2587 CWlanGetSsidScanResults::~CWlanGetSsidScanResults() |
|
2588 { |
|
2589 LOGENTRFN("CWlanGetSsidScanResults::~CWlanGetSsidScanResults()") |
|
2590 |
|
2591 Cancel(); |
|
2592 |
|
2593 if ( iWlanMgmt ) |
|
2594 { |
|
2595 delete iWlanMgmt; |
|
2596 iWlanMgmt = NULL; |
|
2597 } |
|
2598 |
|
2599 if ( iScanInfo ) |
|
2600 { |
|
2601 delete iScanInfo; |
|
2602 iScanInfo = NULL; |
|
2603 } |
|
2604 |
|
2605 LOGEXITFN("CWlanGetSsidScanResults::~CWlanGetSsidScanResults()") |
|
2606 } |
|
2607 |
|
2608 // ----------------------------------------------------------------------------- |
|
2609 // CWlanGetSsidScanResults::StartL |
|
2610 // ----------------------------------------------------------------------------- |
|
2611 // |
|
2612 void CWlanGetSsidScanResults::StartL( |
|
2613 TBuf8<CConnMonWlanNetwork::KMaxNameLength>& aWlanSsid ) |
|
2614 { |
|
2615 LOGENTRFN("CWlanGetSsidScanResults::StartL()") |
|
2616 |
|
2617 if ( IsActive() ) |
|
2618 { |
|
2619 LOGIT("StartL(): Already active, calling Cancel()") |
|
2620 Cancel(); |
|
2621 } |
|
2622 |
|
2623 // Create scaninfo object for scan results |
|
2624 if ( !iScanInfo ) |
|
2625 { |
|
2626 iScanInfo = CWlanScanInfo::NewL(); |
|
2627 } |
|
2628 |
|
2629 // Get scan results from WLAN engine |
|
2630 TInt oldWlanScanCacheLifetime( iWlanSession->GetWlanScanCacheLifetime() ); |
|
2631 TInt newWlanScanCacheLifetime( oldWlanScanCacheLifetime ); |
|
2632 |
|
2633 TUint oldWlanScanMaxDelay( iWlanSession->GetWlanScanMaxDelay() ); |
|
2634 TUint newWlanScanMaxDelay( oldWlanScanMaxDelay ); |
|
2635 |
|
2636 LOGIT2("wlanScanCacheLifetime %d, wlanScanMaxDelay %d", newWlanScanCacheLifetime, newWlanScanMaxDelay) |
|
2637 iWlanMgmt->GetScanResults( |
|
2638 newWlanScanCacheLifetime, |
|
2639 newWlanScanMaxDelay, |
|
2640 aWlanSsid, |
|
2641 iStatus, |
|
2642 *iScanInfo ); |
|
2643 |
|
2644 // Check if wlan engine has changed the timing parameters |
|
2645 if ( oldWlanScanCacheLifetime != newWlanScanCacheLifetime ) |
|
2646 { |
|
2647 LOGIT2("wlanScanCacheLifetime changed from %d to %d", oldWlanScanCacheLifetime, newWlanScanCacheLifetime) |
|
2648 iWlanSession->SetWlanScanCacheLifetime( newWlanScanCacheLifetime ); |
|
2649 } |
|
2650 if ( oldWlanScanMaxDelay != newWlanScanMaxDelay ) |
|
2651 { |
|
2652 LOGIT2("wlanScanMaxDelay changed from %d to %d", oldWlanScanMaxDelay, newWlanScanMaxDelay) |
|
2653 iWlanSession->SetWlanScanMaxDelay( newWlanScanMaxDelay ); |
|
2654 } |
|
2655 |
|
2656 // Start listening when scan results are ready |
|
2657 SetActive(); |
|
2658 |
|
2659 LOGEXITFN("CWlanGetSsidScanResults::StartL()") |
|
2660 } |
|
2661 |
|
2662 // ----------------------------------------------------------------------------- |
|
2663 // CWlanGetSsidScanResults::DoCancel |
|
2664 // ----------------------------------------------------------------------------- |
|
2665 // |
|
2666 void CWlanGetSsidScanResults::DoCancel() |
|
2667 { |
|
2668 LOGIT("CWlanGetSsidScanResults::DoCancel()") |
|
2669 |
|
2670 if ( IsActive() ) |
|
2671 { |
|
2672 // Cancel async request from WLAN engine |
|
2673 iWlanMgmt->CancelGetScanResults(); |
|
2674 } |
|
2675 } |
|
2676 |
|
2677 // ----------------------------------------------------------------------------- |
|
2678 // CWlanGetSsidScanResults::RunL |
|
2679 // ----------------------------------------------------------------------------- |
|
2680 // |
|
2681 void CWlanGetSsidScanResults::RunL() |
|
2682 { |
|
2683 LOGIT(".") |
|
2684 LOGIT1("CWlanGetSsidScanResults::RunL(): sessionId %d", iWlanSession->GetSessionId()) |
|
2685 |
|
2686 // Complete all session requests |
|
2687 iWlanSession->CompleteActiveRequestsL( iStatus.Int(), iScanInfo, ETrue ); |
|
2688 |
|
2689 // Delete scaninfo object to save memory |
|
2690 if ( iScanInfo ) |
|
2691 { |
|
2692 delete iScanInfo; |
|
2693 iScanInfo = NULL; |
|
2694 } |
|
2695 } |
|
2696 |
|
2697 // ----------------------------------------------------------------------------- |
|
2698 // CWlanGetSsidScanResults::RunError |
|
2699 // ----------------------------------------------------------------------------- |
|
2700 // |
|
2701 TInt CWlanGetSsidScanResults::RunError( TInt aLeaveCode ) |
|
2702 { |
|
2703 //LOGENTRFN("CWlanGetSsidScanResults::RunError()") |
|
2704 |
|
2705 LOGIT1("CWlanGetSsidScanResults::RunError() <%d>", aLeaveCode) |
|
2706 iWlanSession->CompleteActiveRequestsWithError( aLeaveCode, ETrue ); |
|
2707 |
|
2708 //LOGEXITFN("CWlanGetSsidScanResults::RunError()") |
|
2709 return KErrNone; |
|
2710 } |
|
2711 |
|
2712 |
|
2713 // =========================== MEMBER FUNCTIONS =============================== |
|
2714 |
|
2715 // --------------------------------------------------------------------------- |
|
2716 // Constructor |
|
2717 // --------------------------------------------------------------------------- |
|
2718 // |
|
2719 CConnMonWlanProbeRawBuffer::CConnMonWlanProbeRawBuffer() |
|
2720 { |
|
2721 } |
|
2722 |
|
2723 // --------------------------------------------------------------------------- |
|
2724 // Constructor |
|
2725 // --------------------------------------------------------------------------- |
|
2726 // |
|
2727 EXPORT_C CConnMonWlanProbeRawBuffer* CConnMonWlanProbeRawBuffer::NewL() |
|
2728 { |
|
2729 CConnMonWlanProbeRawBuffer* self = new( ELeave ) CConnMonWlanProbeRawBuffer(); |
|
2730 return self; |
|
2731 } |
|
2732 |
|
2733 // --------------------------------------------------------------------------- |
|
2734 // Constructor |
|
2735 // --------------------------------------------------------------------------- |
|
2736 // |
|
2737 EXPORT_C CConnMonWlanProbeRawBuffer* CConnMonWlanProbeRawBuffer::NewL( |
|
2738 const HBufC8* aRawBuffer ) |
|
2739 { |
|
2740 CConnMonWlanProbeRawBuffer* self = new( ELeave ) CConnMonWlanProbeRawBuffer(); |
|
2741 |
|
2742 CleanupStack::PushL( self ); |
|
2743 self->ConstructL( aRawBuffer ); |
|
2744 CleanupStack::Pop( self ); |
|
2745 |
|
2746 return self; |
|
2747 } |
|
2748 |
|
2749 // --------------------------------------------------------------------------- |
|
2750 // Second-phase constructor |
|
2751 // --------------------------------------------------------------------------- |
|
2752 // |
|
2753 void CConnMonWlanProbeRawBuffer::ConstructL() |
|
2754 { |
|
2755 } |
|
2756 |
|
2757 // --------------------------------------------------------------------------- |
|
2758 // Second-phase constructor |
|
2759 // --------------------------------------------------------------------------- |
|
2760 // |
|
2761 void CConnMonWlanProbeRawBuffer::ConstructL( const HBufC8* aRawBuffer ) |
|
2762 { |
|
2763 if ( aRawBuffer && aRawBuffer->Length() > 0 ) |
|
2764 { |
|
2765 iRawBuffer = HBufC8::NewL( aRawBuffer->Length() ); |
|
2766 iRawBuffer->Des().Copy( *aRawBuffer ); |
|
2767 } |
|
2768 } |
|
2769 |
|
2770 // --------------------------------------------------------------------------- |
|
2771 // Copy Constructor |
|
2772 // --------------------------------------------------------------------------- |
|
2773 // |
|
2774 EXPORT_C CConnMonWlanProbeRawBuffer* CConnMonWlanProbeRawBuffer::NewL( |
|
2775 CConnMonWlanProbeRawBuffer& aConnMonWlanProbeRawBuffer ) |
|
2776 { |
|
2777 CConnMonWlanProbeRawBuffer* self = new( ELeave ) CConnMonWlanProbeRawBuffer(); |
|
2778 |
|
2779 CleanupStack::PushL( self ); |
|
2780 self->ConstructL( aConnMonWlanProbeRawBuffer.iRawBuffer ); |
|
2781 CleanupStack::Pop( self ); |
|
2782 |
|
2783 return self; |
|
2784 } |
|
2785 |
|
2786 // --------------------------------------------------------------------------- |
|
2787 // Destructor |
|
2788 // --------------------------------------------------------------------------- |
|
2789 // |
|
2790 EXPORT_C CConnMonWlanProbeRawBuffer::~CConnMonWlanProbeRawBuffer() |
|
2791 { |
|
2792 delete iRawBuffer; |
|
2793 } |
|
2794 |
|
2795 // --------------------------------------------------------------------------- |
|
2796 // = operator |
|
2797 // --------------------------------------------------------------------------- |
|
2798 // |
|
2799 EXPORT_C CConnMonWlanProbeRawBuffer& CConnMonWlanProbeRawBuffer::operator=( |
|
2800 CConnMonWlanProbeRawBuffer& aConnMonWlanProbeRawBuffer ) |
|
2801 { |
|
2802 TInt err( KErrNone ); |
|
2803 |
|
2804 if ( aConnMonWlanProbeRawBuffer.iRawBuffer ) |
|
2805 { |
|
2806 delete iRawBuffer; |
|
2807 iRawBuffer = NULL; |
|
2808 TRAP( err, iRawBuffer = HBufC8::NewL( aConnMonWlanProbeRawBuffer.iRawBuffer->Size() ) ); |
|
2809 if ( err ) |
|
2810 { |
|
2811 LOGIT1("Raw buffer handling error <%d>", err) |
|
2812 } |
|
2813 else |
|
2814 { |
|
2815 iRawBuffer->Des().Copy( *aConnMonWlanProbeRawBuffer.iRawBuffer ); |
|
2816 } |
|
2817 } |
|
2818 |
|
2819 return *this; |
|
2820 } |
|
2821 |
|
2822 |
|
2823 // --------------------------------------------------------------------------- |
|
2824 // Packages object to HBufC8 descriptor |
|
2825 // --------------------------------------------------------------------------- |
|
2826 // |
|
2827 EXPORT_C const HBufC8* CConnMonWlanProbeRawBuffer::ToBuf() const |
|
2828 { |
|
2829 //LOGENTRFN("CConnMonWlanProbeRawBuffer::ToBuf()") |
|
2830 |
|
2831 // Allocate buffer to all data |
|
2832 HBufC8* buf = HBufC8::New( sizeof( CConnMonWlanProbeRawBuffer ) + iRawBuffer->Length() ); |
|
2833 if ( !buf ) |
|
2834 { |
|
2835 LOGEXITFN("ToBuf: out of memory error") |
|
2836 return NULL; |
|
2837 } |
|
2838 |
|
2839 TPtr8 ptr( buf->Des() ); |
|
2840 |
|
2841 // Add CConnMonWlanProbeRawBuffer object |
|
2842 ptr.Copy( (TUint8*)this, (TInt)sizeof( CConnMonWlanProbeRawBuffer ) ); |
|
2843 |
|
2844 // If rawdata exists add it too |
|
2845 if ( iRawBuffer->Length() > 0 ) |
|
2846 { |
|
2847 ptr.Append( iRawBuffer->Des() ); |
|
2848 } |
|
2849 |
|
2850 //LOGEXITFN("CConnMonWlanProbeRawBuffer::ToBuf()") |
|
2851 return buf; |
|
2852 } |
|
2853 |
|
2854 |
|
2855 // --------------------------------------------------------------------------- |
|
2856 // Unpackages CConnMonWlanProbeRawBuffer from TPtrC descriptor |
|
2857 // --------------------------------------------------------------------------- |
|
2858 // |
|
2859 EXPORT_C TInt CConnMonWlanProbeRawBuffer::FromPtrC( |
|
2860 const TPtrC8& aPtrC, |
|
2861 CConnMonWlanProbeRawBuffer* aConnMonWlanProbeRawBuffer ) |
|
2862 { |
|
2863 //LOGENTRFN("CConnMonWlanProbeRawBuffer::FromPtrC()") |
|
2864 TInt err( KErrNone ); |
|
2865 |
|
2866 // Copy CConnMonWlanProbeRawBuffer object data from the beginning of aPtrC |
|
2867 memcpy( aConnMonWlanProbeRawBuffer, aPtrC.Ptr(), sizeof( CConnMonWlanProbeRawBuffer ) ); |
|
2868 |
|
2869 // Reset rawdata pointer |
|
2870 aConnMonWlanProbeRawBuffer->iRawBuffer = NULL; |
|
2871 |
|
2872 // If rawdata data exists, allocate memory and read it (it exists just after |
|
2873 // CConnMonWlanProbeRawBuffer object data) from aPtrC |
|
2874 if ( aPtrC.Length() > sizeof( CConnMonWlanProbeRawBuffer ) ) |
|
2875 { |
|
2876 TInt rawDataLen = aPtrC.Length() - sizeof( CConnMonWlanProbeRawBuffer ); |
|
2877 |
|
2878 aConnMonWlanProbeRawBuffer->iRawBuffer = HBufC8::New( rawDataLen ); |
|
2879 if ( !aConnMonWlanProbeRawBuffer->iRawBuffer ) |
|
2880 { |
|
2881 err = KErrNoMemory; |
|
2882 LOGIT("FromPtrC: out of memory error") |
|
2883 } |
|
2884 else |
|
2885 { |
|
2886 aConnMonWlanProbeRawBuffer->iRawBuffer->Des().Copy( |
|
2887 aPtrC.Mid( sizeof( CConnMonWlanProbeRawBuffer ), rawDataLen ) ); |
|
2888 } |
|
2889 } |
|
2890 |
|
2891 //LOGEXITFN1("CConnMonWlanProbeRawBuffer::FromPtrC()", err) |
|
2892 return err; |
|
2893 } |
|
2894 |
|
2895 // --------------------------------------------------------------------------- |
|
2896 // Getter |
|
2897 // --------------------------------------------------------------------------- |
|
2898 // |
|
2899 EXPORT_C HBufC8* CConnMonWlanProbeRawBuffer::RawBuffer() const |
|
2900 { |
|
2901 return iRawBuffer; |
|
2902 } |
|
2903 |
|
2904 |
|
2905 |
|
2906 |
|
2907 |
|
2908 // =========================== MEMBER FUNCTIONS =============================== |
|
2909 |
|
2910 // --------------------------------------------------------------------------- |
|
2911 // Constructor |
|
2912 // --------------------------------------------------------------------------- |
|
2913 // |
|
2914 CConnMonWlanProbeRawBuffersPckg::CConnMonWlanProbeRawBuffersPckg( |
|
2915 const RConnMonWlanProbeRawBuffersPtrArray& aRef, |
|
2916 TUint aBufLen ) |
|
2917 { |
|
2918 LOGENTRFN("CConnMonWlanProbeRawBuffersPckg::CConnMonWlanProbeRawBuffersPckg()") |
|
2919 |
|
2920 const TUint KItemLengthFieldSize = 2; // 2 bytes (item lenth can be larger than 255) |
|
2921 |
|
2922 // First 2 bytes in buffer will contain the total number of objects and the number of transfered objects. |
|
2923 TUint currentPosition( 2 ); |
|
2924 TInt totalItemCount = aRef.Count(); |
|
2925 |
|
2926 LOGIT2("CConnMonWlanProbeRawBuffersPckg: buffer size %d, item count %d", aBufLen, totalItemCount) |
|
2927 |
|
2928 // Create a temporary pointer array table for buffer objects |
|
2929 RPointerArray<HBufC8> items; |
|
2930 |
|
2931 for ( TUint i = 0; i < totalItemCount; ++i ) |
|
2932 { |
|
2933 const HBufC8* item( aRef[i]->ToBuf() ); |
|
2934 if ( item ) |
|
2935 { |
|
2936 // Check if there is room in buffer for the next item |
|
2937 if ( ( currentPosition + KItemLengthFieldSize + item->Length() ) > aBufLen ) |
|
2938 { |
|
2939 LOGIT4("Buffer full, current position %d, item length %d, buffer size %d, i %d", |
|
2940 currentPosition, item->Length(), aBufLen, i) |
|
2941 delete item; |
|
2942 item = NULL; |
|
2943 break; |
|
2944 } |
|
2945 TInt err = items.Append( item ); |
|
2946 if ( !err ) |
|
2947 { |
|
2948 currentPosition += KItemLengthFieldSize + item->Length(); |
|
2949 } |
|
2950 else |
|
2951 { |
|
2952 LOGIT1("ERROR: append failed <%d>", err) |
|
2953 delete item; |
|
2954 item = NULL; |
|
2955 } |
|
2956 } |
|
2957 } |
|
2958 |
|
2959 // Check that given buffer length (aBufLen) is not smaller than one |
|
2960 // item (CConnMonWlanProbeRawBuffer) + aRef count + items count + item length |
|
2961 if ( items.Count() == 0 && totalItemCount > 0 ) |
|
2962 { |
|
2963 aBufLen = 2; // aRef.Count(), items.Count() |
|
2964 } |
|
2965 |
|
2966 // Allocate memory for buffer |
|
2967 iBuf = HBufC8::New( aBufLen ); |
|
2968 if ( !iBuf ) |
|
2969 { |
|
2970 LOGIT("CConnMonWlanProbeRawBuffersPckg: out of memory error") |
|
2971 } |
|
2972 else |
|
2973 { |
|
2974 // Add total and transferred counts to buffer |
|
2975 iBuf->Des().Append( totalItemCount ); // Total amount of objects |
|
2976 iBuf->Des().Append( items.Count() ); // Amount of objects in buffer |
|
2977 |
|
2978 // Add item length and item data to buffer |
|
2979 for ( TUint i = 0; i < items.Count(); ++i ) |
|
2980 { |
|
2981 // Add item length by splitting 16bit number |
|
2982 TUint8 tempLength1 = (TUint8)( items[i]->Length() & 0x00FF ); |
|
2983 TUint8 tempLength2 = (TUint8)( ( items[i]->Length() & 0xFF00 ) >> KBitsInByte ); |
|
2984 iBuf->Des().Append( tempLength1 ); |
|
2985 iBuf->Des().Append( tempLength2 ); |
|
2986 |
|
2987 iBuf->Des().Append( *items[i] ); |
|
2988 } |
|
2989 LOGIT1("Used buffer %d", iBuf->Length()) |
|
2990 } |
|
2991 items.ResetAndDestroy(); // Clear array |
|
2992 |
|
2993 LOGEXITFN("CConnMonWlanProbeRawBuffersPckg::CConnMonWlanProbeRawBuffersPckg()") |
|
2994 } |
|
2995 |
|
2996 // --------------------------------------------------------------------------- |
|
2997 // Constructor |
|
2998 // --------------------------------------------------------------------------- |
|
2999 // |
|
3000 EXPORT_C CConnMonWlanProbeRawBuffersPckg::CConnMonWlanProbeRawBuffersPckg( |
|
3001 TUint aBufSize ) |
|
3002 { |
|
3003 iBuf = HBufC8::New( aBufSize ); |
|
3004 } |
|
3005 |
|
3006 // --------------------------------------------------------------------------- |
|
3007 // Destructor |
|
3008 // --------------------------------------------------------------------------- |
|
3009 // |
|
3010 EXPORT_C CConnMonWlanProbeRawBuffersPckg::~CConnMonWlanProbeRawBuffersPckg() |
|
3011 { |
|
3012 delete iBuf; |
|
3013 } |
|
3014 |
|
3015 // --------------------------------------------------------------------------- |
|
3016 // Unpacking |
|
3017 // --------------------------------------------------------------------------- |
|
3018 // |
|
3019 EXPORT_C void CConnMonWlanProbeRawBuffersPckg::UnpackToL( |
|
3020 RConnMonWlanProbeRawBuffersPtrArray& aRef ) const |
|
3021 { |
|
3022 LOGENTRFN("CConnMonWlanProbeRawBuffersPckg::UnpackToL()") |
|
3023 |
|
3024 if ( !iBuf || iBuf->Length() < 2 ) |
|
3025 { |
|
3026 User::Leave( KErrBadDescriptor ); |
|
3027 } |
|
3028 |
|
3029 // Parse total and transferred data counts |
|
3030 TUint index( 0 ); |
|
3031 TUint total( (*iBuf)[index++] ); // Total amount of objects |
|
3032 TUint count( (*iBuf)[index++] ); // Amount of objects in buffer |
|
3033 LOGIT2("UnpackToL: total %d, in buffer %d", total, count) |
|
3034 |
|
3035 // Parse CConnMonWlanProbeRawBuffer objects from buffer |
|
3036 for ( TUint i = 0; i < count; ++i ) |
|
3037 { |
|
3038 // Parse object length (stored in 2 bytes) |
|
3039 TUint len( 0 ); |
|
3040 TUint8 len1( (*iBuf)[index++] ); // 1st byte of length |
|
3041 TUint8 len2( (*iBuf)[index++] ); // 2nd byte of length |
|
3042 len = (TUint)len2; |
|
3043 len = len<<8 & 0xFF00; |
|
3044 len = len | (TUint)len1; |
|
3045 |
|
3046 // Parse object data |
|
3047 TPtrC8 ptr( iBuf->Mid( index, len ) ); |
|
3048 index += len; |
|
3049 |
|
3050 CConnMonWlanProbeRawBuffer* net = CConnMonWlanProbeRawBuffer::NewL(); |
|
3051 TInt err = CConnMonWlanProbeRawBuffer::FromPtrC( ptr, net ); |
|
3052 if ( err != KErrNone ) |
|
3053 { |
|
3054 LOGIT2("UnpackToL: error <%d> reading data, stopping. i %d", err, i) |
|
3055 break; |
|
3056 } |
|
3057 |
|
3058 CleanupStack::PushL( net ); |
|
3059 aRef.AppendL( net ); |
|
3060 CleanupStack::Pop( net ); |
|
3061 } |
|
3062 |
|
3063 LOGEXITFN("CConnMonWlanProbeRawBuffersPckg::UnpackToL()") |
|
3064 } |
|
3065 |
|
3066 // --------------------------------------------------------------------------- |
|
3067 // Getter |
|
3068 // --------------------------------------------------------------------------- |
|
3069 // |
|
3070 EXPORT_C HBufC8* CConnMonWlanProbeRawBuffersPckg::Buf() const |
|
3071 { |
|
3072 return iBuf; |
|
3073 } |
|
3074 |
|
3075 // --------------------------------------------------------------------------- |
|
3076 // Returns all available networks |
|
3077 // --------------------------------------------------------------------------- |
|
3078 // |
|
3079 EXPORT_C TUint CConnMonWlanProbeRawBuffersPckg::Total() const |
|
3080 { |
|
3081 TUint ret( 0 ); |
|
3082 if ( iBuf && iBuf->Length() > 0 ) |
|
3083 { |
|
3084 ret = (*iBuf)[0]; // Total amount of objects |
|
3085 } |
|
3086 return ret; |
|
3087 } |
|
3088 |
|
3089 // --------------------------------------------------------------------------- |
|
3090 // Returns transfered networks |
|
3091 // --------------------------------------------------------------------------- |
|
3092 // |
|
3093 EXPORT_C TUint CConnMonWlanProbeRawBuffersPckg::Count() const |
|
3094 { |
|
3095 TUint ret( 0 ); |
|
3096 if ( iBuf && iBuf->Length() > 1 ) |
|
3097 { |
|
3098 ret = (*iBuf)[1]; // Amount of objects in buffer |
|
3099 } |
|
3100 return ret; |
|
3101 } |
|
3102 |
|
3103 // End-of-file |