|
1 /* |
|
2 * Copyright (c) 2007-2008 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: Implementation of the WLAN signal level handler |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include <wlanmgmtclient.h> |
|
21 #include "vccwlansignallevelhandler.h" |
|
22 #include "rubydebug.h" |
|
23 #include "vccengpsproperty.h" |
|
24 #include <ccpdefs.h> |
|
25 |
|
26 // Min. signal strength. |
|
27 static const TInt32 KStrengthMin = 110; |
|
28 |
|
29 const TInt KWlanPollIntervalLowSignal= 1000000; |
|
30 const TInt KWlanPollIntervalHighSignal= 5000000; |
|
31 |
|
32 // --------------------------------------------------------------------------- |
|
33 // C++ destructor. |
|
34 // --------------------------------------------------------------------------- |
|
35 // |
|
36 CVccWlanSignalLevelHandler::~CVccWlanSignalLevelHandler() |
|
37 { |
|
38 // Cancel any request, if outstanding |
|
39 Cancel(); |
|
40 #ifndef __WINS__ |
|
41 delete iWlanMgmt; |
|
42 #endif |
|
43 } |
|
44 |
|
45 // --------------------------------------------------------------------------- |
|
46 // Symbian constructor. |
|
47 // --------------------------------------------------------------------------- |
|
48 // |
|
49 CVccWlanSignalLevelHandler* CVccWlanSignalLevelHandler::NewL( |
|
50 MVccSignalLevelObserver& aObserver, |
|
51 const TSignalLevelParams& aParams, CVccEngPsProperty& aPsProperty ) |
|
52 { |
|
53 CVccWlanSignalLevelHandler* self = |
|
54 CVccWlanSignalLevelHandler::NewLC( aObserver, aParams, aPsProperty ); |
|
55 |
|
56 CleanupStack::Pop( self ); |
|
57 |
|
58 return self; |
|
59 } |
|
60 |
|
61 // --------------------------------------------------------------------------- |
|
62 // Symbian constructor. |
|
63 // --------------------------------------------------------------------------- |
|
64 // |
|
65 CVccWlanSignalLevelHandler* CVccWlanSignalLevelHandler::NewLC( |
|
66 MVccSignalLevelObserver& aObserver, |
|
67 const TSignalLevelParams& aParams, CVccEngPsProperty& aPsProperty ) |
|
68 { |
|
69 CVccWlanSignalLevelHandler * self = |
|
70 new ( ELeave ) CVccWlanSignalLevelHandler( aObserver, aParams, aPsProperty ); |
|
71 |
|
72 CleanupStack::PushL( self ); |
|
73 self->ConstructL(); |
|
74 return self; |
|
75 } |
|
76 |
|
77 // --------------------------------------------------------------------------- |
|
78 // C++ constructor. |
|
79 // --------------------------------------------------------------------------- |
|
80 // |
|
81 CVccWlanSignalLevelHandler::CVccWlanSignalLevelHandler( |
|
82 MVccSignalLevelObserver& aObserver, |
|
83 const TSignalLevelParams& aParams, CVccEngPsProperty& aPsProperty ) |
|
84 : CVccSignalLevelHandler( aObserver, aParams ), iVccPsp( aPsProperty ) |
|
85 { |
|
86 iManualHoDone = EFalse; |
|
87 } |
|
88 |
|
89 // --------------------------------------------------------------------------- |
|
90 // Symbian second-phase constructor. |
|
91 // --------------------------------------------------------------------------- |
|
92 // |
|
93 void CVccWlanSignalLevelHandler::ConstructL() |
|
94 { |
|
95 RUBY_DEBUG_BLOCKL( "CVccWlanSignalLevelHandler::ConstructL" ); |
|
96 |
|
97 CVccSignalLevelHandler::ConstructL(); |
|
98 #ifndef __WINS__ |
|
99 //WlanMgmtClient is not started when the phone is not f. ex. labeled |
|
100 TRAP_IGNORE( iWlanMgmt = CWlanMgmtClient::NewL() ); |
|
101 #endif |
|
102 } |
|
103 |
|
104 // --------------------------------------------------------------------------- |
|
105 // Enable notifications. |
|
106 // --------------------------------------------------------------------------- |
|
107 // |
|
108 void CVccWlanSignalLevelHandler::EnableNotificationsL() |
|
109 { |
|
110 RUBY_DEBUG_BLOCK( "CVccWlanSignalLevelHandler::EnableNotificationsL" ); |
|
111 #ifndef __WINS__ |
|
112 if( iWlanMgmt ) |
|
113 { |
|
114 TInt error = iWlanMgmt->UpdateRssNotificationBoundary( |
|
115 iParams.iLowLevel, |
|
116 iParams.iLowLevel - iParams.iHighLevel ); |
|
117 |
|
118 User::LeaveIfError( error ); |
|
119 |
|
120 iWlanMgmt->ActivateNotificationsL( *this ); |
|
121 } |
|
122 #endif |
|
123 } |
|
124 |
|
125 // --------------------------------------------------------------------------- |
|
126 // Disable notifications. |
|
127 // --------------------------------------------------------------------------- |
|
128 // |
|
129 void CVccWlanSignalLevelHandler::DisableNotifications() |
|
130 { |
|
131 RUBY_DEBUG_BLOCK( "CVccWlanSignalLevelHandler::DisableNotificationsL" ); |
|
132 #ifndef __WINS__ |
|
133 if( iWlanMgmt ) |
|
134 { |
|
135 iWlanMgmt->CancelNotifications(); |
|
136 } |
|
137 #endif |
|
138 } |
|
139 |
|
140 // --------------------------------------------------------------------------- |
|
141 // Get signal strength. |
|
142 // --------------------------------------------------------------------------- |
|
143 // |
|
144 void CVccWlanSignalLevelHandler::GetStrength() |
|
145 { |
|
146 |
|
147 RUBY_DEBUG_BLOCK( "CVccWlanSignalLevelHandler::GetStrength" ); |
|
148 |
|
149 iStrength = KStrengthMin; |
|
150 #ifndef __WINS__ |
|
151 if( iWlanMgmt ) |
|
152 { |
|
153 iWlanMgmt->GetConnectionSignalQuality( iStrength ); |
|
154 } |
|
155 #endif |
|
156 RUBY_DEBUG1( " -strength = %d", iStrength ); |
|
157 |
|
158 // Because the RMobilePhone used in GSM is asynchronous we need here |
|
159 // to signal that the request is complete (in order to continue |
|
160 // processing stuff in RunL) |
|
161 |
|
162 TRequestStatus *sP = &iStatus; |
|
163 |
|
164 User::RequestComplete( sP, KErrNone ); |
|
165 } |
|
166 |
|
167 // --------------------------------------------------------------------------- |
|
168 // Cancel outstanding GetStrength. |
|
169 // We do not need to do anything since WLAN GetStrength is synchronous. |
|
170 // --------------------------------------------------------------------------- |
|
171 // |
|
172 void CVccWlanSignalLevelHandler::CancelGetStrength() |
|
173 { |
|
174 RUBY_DEBUG_BLOCK( "CVccWlanSignalLevelHandler::CancelGetStrength" ); |
|
175 } |
|
176 |
|
177 // --------------------------------------------------------------------------- |
|
178 // Handles indication of changed RSS value. |
|
179 // --------------------------------------------------------------------------- |
|
180 // |
|
181 void CVccWlanSignalLevelHandler::RssChanged( TWlanRssClass aRssClass, TUint aRss ) |
|
182 { |
|
183 RUBY_DEBUG_BLOCK( "CVccWlanSignalLevelHandler::RssChanged" ); |
|
184 RUBY_DEBUG2( " -class = %d rss = %d", aRssClass, aRss); |
|
185 |
|
186 // Do some basic check |
|
187 // Zero (0) is not acceptable strength (too good?). |
|
188 |
|
189 iStrength = aRss ? aRss : KStrengthMin; |
|
190 StrengthChanged(); |
|
191 } |
|
192 |
|
193 // --------------------------------------------------------------------------- |
|
194 // Handles BSSID has changed (i.e. AP handover) situation. |
|
195 // --------------------------------------------------------------------------- |
|
196 // |
|
197 void CVccWlanSignalLevelHandler::BssidChanged( TWlanBssid& aNewBSSID ) |
|
198 { |
|
199 RUBY_DEBUG_BLOCK( "CVccWlanSignalLevelHandler::BssidChanged" ); |
|
200 RUBY_DEBUG1( " -aNewBSSID = %S", &aNewBSSID ); |
|
201 |
|
202 iStrength = KStrengthMin; |
|
203 #ifndef __WINS__ |
|
204 if( iWlanMgmt ) |
|
205 { |
|
206 iWlanMgmt->GetConnectionSignalQuality( iStrength ); |
|
207 } |
|
208 #endif |
|
209 |
|
210 StrengthChanged(); |
|
211 } |
|
212 |
|
213 // --------------------------------------------------------------------------- |
|
214 // Handles lost of one or more networks |
|
215 // --------------------------------------------------------------------------- |
|
216 // |
|
217 void CVccWlanSignalLevelHandler::OldNetworksLost() |
|
218 { |
|
219 RUBY_DEBUG_BLOCK( "CVccWlanSignalLevelHandler::OldNetworksLost" ); |
|
220 |
|
221 iStrength = KStrengthMin; |
|
222 #ifndef __WINS__ |
|
223 if( iWlanMgmt ) |
|
224 { |
|
225 iWlanMgmt->GetConnectionSignalQuality( iStrength ); |
|
226 } |
|
227 #endif |
|
228 StrengthChanged(); |
|
229 |
|
230 TVccHoStatus hoStatus( EVccHoStateUnknown ); |
|
231 iVccPsp.GetCurrentHoStatus( hoStatus ); |
|
232 |
|
233 RUBY_DEBUG1("Current HoStatus; %d", hoStatus); |
|
234 |
|
235 if( hoStatus == EVccCsToPsHoStarted || hoStatus == EVccCsToPsHoInprogress |
|
236 || hoStatus == EVccHoUnavailable ) |
|
237 { |
|
238 iVccPsp.NotifySubscriberL( EVccCsToPsHoFailure, ECCPErrorNetworkOutOfOrder ); |
|
239 } |
|
240 } |
|
241 |
|
242 // --------------------------------------------------------------------------- |
|
243 // Notify observer that the signal level has been changed. |
|
244 // --------------------------------------------------------------------------- |
|
245 // |
|
246 void CVccWlanSignalLevelHandler::NotifyChanges( |
|
247 TInt32 aSignalStrength, |
|
248 MVccSignalLevelObserver::TSignalStrengthClass aClass ) |
|
249 { |
|
250 RUBY_DEBUG_BLOCK( "CVccWlanSignalLevelHandler::NotifyChanges" ); |
|
251 RUBY_DEBUG1( " -New strength = -%d dBm", aSignalStrength ); |
|
252 |
|
253 iObserver.WlanSignalChanged( aSignalStrength, aClass ); |
|
254 } |
|
255 |
|
256 |
|
257 // --------------------------------------------------------------------------- |
|
258 // Handles getting the signal strength and notifying the observer about |
|
259 // strength changes. |
|
260 // --------------------------------------------------------------------------- |
|
261 |
|
262 void CVccWlanSignalLevelHandler::RunL() |
|
263 { |
|
264 RUBY_DEBUG_BLOCK( "CVccWlanSignalLevelHandler::RunL" ); |
|
265 |
|
266 // Zero (0) is not acceptable. |
|
267 if ( !iStrength ) |
|
268 { |
|
269 RUBY_DEBUG0( " -0 strength not acceptable, setting to KStrengthMin"); |
|
270 iStrength = KStrengthMin; |
|
271 } |
|
272 |
|
273 RUBY_DEBUG3( " -iStrength = %d iState = %d iOp = %d", iStrength, iState, iOperation ); |
|
274 |
|
275 switch ( iOperation ) |
|
276 { |
|
277 case EOperationGet: |
|
278 { |
|
279 |
|
280 // We are in the Get-mode to get the signal strength. |
|
281 // If the strength is < than the high level (== the strength |
|
282 // is good), start timer to check if we are still in good level |
|
283 // after the timer completes. |
|
284 // The same is done if we have a low level (== bad). |
|
285 |
|
286 RUBY_DEBUG0( " -EOperationGet"); |
|
287 |
|
288 if ( iStrength <= iParams.iHighLevel && iStrength > 0 ) |
|
289 { |
|
290 RUBY_DEBUG0( " set state = EStrengthHigh, op = EOperationWait" ); |
|
291 |
|
292 After( iParams.iHighTimeout ); |
|
293 iState = EStrengthHigh; |
|
294 iOperation = EOperationWait; |
|
295 } |
|
296 else if ( iStrength >= iParams.iLowLevel ) |
|
297 { |
|
298 RUBY_DEBUG0( " set state = EStrengtLow, op = EOperationWait" ); |
|
299 After( iParams.iLowTimeout ); |
|
300 iState = EStrengthLow; |
|
301 iOperation = EOperationWait; |
|
302 } |
|
303 else |
|
304 { |
|
305 RUBY_DEBUG0( " strength between low and high, set op = EOperationNone" ); |
|
306 |
|
307 //WLAN signal is almost weak, check again with low interval |
|
308 After( KWlanPollIntervalLowSignal ); |
|
309 iOperation = EOperationNone; |
|
310 iState = EStrengthLow; |
|
311 // PCLint |
|
312 } |
|
313 break; |
|
314 } |
|
315 |
|
316 case EOperationWait: |
|
317 { |
|
318 |
|
319 // Timer has completed. Check the signal level again. |
|
320 |
|
321 RUBY_DEBUG0( " -EOperationWait" ); |
|
322 RUBY_DEBUG0( " set op = EOperationComplete" ); |
|
323 GetStrength(); |
|
324 |
|
325 SetActive(); |
|
326 |
|
327 iOperation = EOperationComplete; |
|
328 |
|
329 break; |
|
330 } |
|
331 |
|
332 case EOperationComplete: |
|
333 { |
|
334 // Checking signal strength is now done. |
|
335 // Notify our observer (if needed). |
|
336 |
|
337 RUBY_DEBUG1( " -EOperationComplete, iStrength = %d", iStrength ); |
|
338 |
|
339 // Do we have a good signal level? |
|
340 if ( iStrength <= iParams.iHighLevel && iStrength > 0 && iState == EStrengthHigh ) |
|
341 { |
|
342 RUBY_DEBUG0( " -if ( iStrength <= iParams.iHighLevel" ); |
|
343 NotifyChanges( iStrength, MVccSignalLevelObserver::ESignalClassNormal ); |
|
344 } |
|
345 // Or do we have a bad signal level? |
|
346 else if ( iStrength >= iParams.iHighLevel && iState == EStrengthLow ) |
|
347 { |
|
348 RUBY_DEBUG0( " -else if ( iStrength >= iParams.iHighLevel" ); |
|
349 NotifyChanges( iStrength, MVccSignalLevelObserver::ESignalClassWeak ); |
|
350 } |
|
351 else |
|
352 { |
|
353 // PCLint |
|
354 } |
|
355 |
|
356 TTimeIntervalMicroSeconds32 interval; |
|
357 |
|
358 if( iState == EStrengthHigh ) |
|
359 { |
|
360 RUBY_DEBUG0( " high interval" ); |
|
361 interval = KWlanPollIntervalHighSignal; |
|
362 } |
|
363 else |
|
364 { |
|
365 RUBY_DEBUG0( " low interval" ) |
|
366 interval = KWlanPollIntervalLowSignal; |
|
367 } |
|
368 |
|
369 After( interval ); |
|
370 |
|
371 iState = EStrengthUnknown; |
|
372 iOperation = EOperationNone; |
|
373 |
|
374 break; |
|
375 } |
|
376 |
|
377 case EOperationNone: |
|
378 { |
|
379 RUBY_DEBUG0( " -EOperationNone" ); |
|
380 |
|
381 //if manual HO is done then there is no need for checking signal strength so much, |
|
382 //so stopping the loop |
|
383 if( !iManualHoDone ) |
|
384 { |
|
385 RUBY_DEBUG0( " -call GetStrength()" ); |
|
386 GetStrength(); |
|
387 SetActive(); |
|
388 RUBY_DEBUG1( " -iStrength = %d, set op = EOperationGet \ |
|
389 state = EStrengthUnknown", iStrength ); |
|
390 iOperation = EOperationGet; |
|
391 } |
|
392 break; |
|
393 |
|
394 } |
|
395 |
|
396 |
|
397 default: |
|
398 { |
|
399 break; |
|
400 } |
|
401 } |
|
402 |
|
403 } |
|
404 |
|
405 // --------------------------------------------------------------------------- |
|
406 // Lets Wlan Signal Level Handler know is manual handover done or not done |
|
407 // |
|
408 // --------------------------------------------------------------------------- |
|
409 |
|
410 |
|
411 void CVccWlanSignalLevelHandler::SetManualHoDone( TBool aValue ) |
|
412 { |
|
413 RUBY_DEBUG_BLOCK( "CVccWlanSignalLevelHandler::SetManualHoDone" ); |
|
414 iManualHoDone = aValue; |
|
415 } |
|
416 |
|
417 |
|
418 // --------------------------------------------------------------------------- |
|
419 // Cancel outstanding requests. |
|
420 // --------------------------------------------------------------------------- |
|
421 // |
|
422 void CVccWlanSignalLevelHandler::DoCancel() |
|
423 { |
|
424 RUBY_DEBUG_BLOCK( "CVccSignalLevelHandler::DoCancel" ); |
|
425 switch ( iOperation ) |
|
426 { |
|
427 case EOperationWait: |
|
428 case EOperationNone: |
|
429 { |
|
430 RUBY_DEBUG0( "EOperationWait / EOperationNone" ); |
|
431 CTimer::DoCancel(); |
|
432 |
|
433 break; |
|
434 } |
|
435 |
|
436 |
|
437 default: |
|
438 { |
|
439 break; |
|
440 } |
|
441 } |
|
442 } |