|
1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // PhysLinksManHelper.cpp |
|
15 // |
|
16 // |
|
17 |
|
18 #include <bluetooth/logger.h> |
|
19 #include "PhysicalLinkHelper.h" |
|
20 #include "physicallinksmanager.h" |
|
21 #include "AclDataQController.h" |
|
22 #include "ProxySAP.h" |
|
23 #include "linkmgr.h" |
|
24 |
|
25 #ifdef __FLOG_ACTIVE |
|
26 _LIT8(KLogComponent, LOG_COMPONENT_LINKMGR); |
|
27 #endif |
|
28 |
|
29 CRoleSwitcher::CRoleSwitcher(CPhysicalLinksManager& aLinkMgr, CPhysicalLink& aLink, TBTBasebandRole aRole) |
|
30 : CTimer(CActive::EPriorityStandard) |
|
31 , iLinkMgr(aLinkMgr) |
|
32 , iLink(aLink) |
|
33 , iRole(aRole) |
|
34 , iIsEncryptionDisabledForRoleSwitch(EFalse) |
|
35 { |
|
36 LOG_FUNC |
|
37 iState = &iLinkMgr.RoleSwitcherStateFactory().GetState(CRoleSwitcherStateFactory::EIdle); |
|
38 } |
|
39 |
|
40 CRoleSwitcher* CRoleSwitcher::NewL(CPhysicalLinksManager& aLinkMgr, CPhysicalLink& aLink, TBTBasebandRole aRole) |
|
41 { |
|
42 LOG_STATIC_FUNC |
|
43 CRoleSwitcher* self = new(ELeave) CRoleSwitcher(aLinkMgr, aLink, aRole); |
|
44 CleanupStack::PushL(self); |
|
45 self->ConstructL(); |
|
46 CleanupStack::Pop(self); |
|
47 return self; |
|
48 } |
|
49 |
|
50 void CRoleSwitcher::ConstructL() |
|
51 { |
|
52 LOG_FUNC |
|
53 |
|
54 // create Proxy telling it the possible PHY |
|
55 iBTProxySAP = CBTProxySAP::NewL(iLinkMgr, &iLink); |
|
56 iBTProxySAP->SetNotify(this); |
|
57 |
|
58 TCallBack cb(EventReceivedCallBack, this); |
|
59 iEventReceivedCallBack = new (ELeave)CAsyncCallBack(cb, EActiveHighPriority); |
|
60 |
|
61 CTimer::ConstructL(); |
|
62 CActiveScheduler::Add(this); |
|
63 |
|
64 // add ourselves to the list in LinkMgr, LinkMgr will kick off the role change state machine |
|
65 iLinkMgr.AddRoleSwitcher(*this); |
|
66 iAddedToLinkMgr = ETrue; |
|
67 } |
|
68 |
|
69 CRoleSwitcher::~CRoleSwitcher() |
|
70 { |
|
71 LOG_FUNC |
|
72 if (iAddedToLinkMgr) |
|
73 { |
|
74 iLinkMgr.RemoveRoleSwitcher(*this); |
|
75 } |
|
76 |
|
77 Cancel(); // watchdog timer |
|
78 delete iBTProxySAP; |
|
79 if (iEventReceivedCallBack) |
|
80 { |
|
81 iEventReceivedCallBack->Cancel(); |
|
82 delete iEventReceivedCallBack; |
|
83 } |
|
84 } |
|
85 |
|
86 void CRoleSwitcher::DisableLPM() |
|
87 { |
|
88 LOG_FUNC |
|
89 TPckgBuf<TInt> optionBuf; |
|
90 iBTProxySAP->SAPSetOption(KSolBtLMProxy, EBBRequestPreventAllLowPowerModes, optionBuf); |
|
91 } |
|
92 |
|
93 void CRoleSwitcher::EnableLPM() |
|
94 { |
|
95 LOG_FUNC |
|
96 TPckgBuf<TInt> optionBuf; |
|
97 iBTProxySAP->SAPSetOption(KSolBtLMProxy, EBBRequestAllowAllLowPowerModes, optionBuf); |
|
98 } |
|
99 |
|
100 void CRoleSwitcher::DisableEncryption() |
|
101 { |
|
102 LOG_FUNC |
|
103 // data traffic suspended |
|
104 iLinkMgr.LinkManagerProtocol().ACLController().SetParked(iLink.Handle(), ETrue); |
|
105 TBTBasebandEvent event(ENotifyEncryptionChangeOff); |
|
106 iBTProxySAP->Ioctl(KSolBtLMProxy, KLMBasebandEventOneShotNotificationIoctl, &event); |
|
107 iLinkMgr.Encrypt(EFalse, iLink); |
|
108 |
|
109 // set flag here, it's too late when we receive the event as AccessReqester |
|
110 // might receive the baseband notification earlier then the flag is set! |
|
111 iIsEncryptionDisabledForRoleSwitch = ETrue; |
|
112 } |
|
113 |
|
114 void CRoleSwitcher::EnableEncryption() |
|
115 { |
|
116 LOG_FUNC |
|
117 TBTBasebandEvent event(ENotifyEncryptionChangeOn); |
|
118 iBTProxySAP->Ioctl(KSolBtLMProxy, KLMBasebandEventOneShotNotificationIoctl, &event); |
|
119 iLinkMgr.Encrypt(ETrue, iLink); |
|
120 // data traffic is enabled in IoctlComplete |
|
121 } |
|
122 |
|
123 void CRoleSwitcher::ChangeRole() |
|
124 { |
|
125 LOG_FUNC |
|
126 TBTBasebandEvent event(ENotifyAnyRole); |
|
127 iBTProxySAP->Ioctl(KSolBtLMProxy, KLMBasebandEventOneShotNotificationIoctl, &event); |
|
128 iLinkMgr.ChangeRole(iRole, iLink); |
|
129 } |
|
130 |
|
131 void CRoleSwitcher::CancelIoctl() |
|
132 { |
|
133 LOG_FUNC |
|
134 iBTProxySAP->CancelIoctl(KSolBtLMProxy, KLMBasebandEventOneShotNotificationIoctl); |
|
135 } |
|
136 |
|
137 // Timer |
|
138 void CRoleSwitcher::RunL() |
|
139 { |
|
140 LOG_FUNC |
|
141 iState->TimerExpired(*this); |
|
142 } |
|
143 |
|
144 TInt CRoleSwitcher::RunError(TInt aError) |
|
145 { |
|
146 LOG_FUNC |
|
147 iState->Error(*this, aError); |
|
148 return KErrNone; |
|
149 } |
|
150 |
|
151 // From MSocketNotify |
|
152 void CRoleSwitcher::NewData(TUint /*aCount*/) |
|
153 { |
|
154 LOG_FUNC |
|
155 |
|
156 } |
|
157 |
|
158 void CRoleSwitcher::CanSend() |
|
159 { |
|
160 LOG_FUNC |
|
161 |
|
162 } |
|
163 |
|
164 void CRoleSwitcher::ConnectComplete() |
|
165 { |
|
166 LOG_FUNC |
|
167 |
|
168 } |
|
169 |
|
170 void CRoleSwitcher::ConnectComplete(const TDesC8& /*aConnectData*/) |
|
171 { |
|
172 LOG_FUNC |
|
173 |
|
174 } |
|
175 |
|
176 void CRoleSwitcher::ConnectComplete(CServProviderBase& /*aSSP*/) |
|
177 { |
|
178 LOG_FUNC |
|
179 |
|
180 } |
|
181 |
|
182 void CRoleSwitcher::ConnectComplete(CServProviderBase& /*aSSP*/,const TDesC8& /*aConnectData*/) |
|
183 { |
|
184 LOG_FUNC |
|
185 |
|
186 } |
|
187 |
|
188 void CRoleSwitcher::CanClose(TDelete /*aDelete*/) |
|
189 { |
|
190 LOG_FUNC |
|
191 |
|
192 } |
|
193 |
|
194 void CRoleSwitcher::CanClose(const TDesC8& /*aDisconnectData*/,TDelete /*aDelete*/) |
|
195 { |
|
196 LOG_FUNC |
|
197 |
|
198 } |
|
199 |
|
200 void CRoleSwitcher::Error(TInt /*aError*/,TUint /*aOperationMask*/) |
|
201 { |
|
202 LOG_FUNC |
|
203 |
|
204 } |
|
205 |
|
206 void CRoleSwitcher::Disconnect(void) |
|
207 { |
|
208 LOG_FUNC |
|
209 iState->Error(*this, KErrDisconnected); |
|
210 } |
|
211 |
|
212 void CRoleSwitcher::Disconnect(TDesC8& /*aDisconnectData*/) |
|
213 { |
|
214 LOG_FUNC |
|
215 iState->Error(*this, KErrDisconnected); |
|
216 } |
|
217 |
|
218 void CRoleSwitcher::Start() |
|
219 { |
|
220 LOG_FUNC |
|
221 iState->Start(*this); |
|
222 } |
|
223 |
|
224 void CRoleSwitcher::Finish() |
|
225 { |
|
226 LOG_FUNC |
|
227 // async call to delete this class |
|
228 iLink.AsyncDeleteRoleSwitcher(); |
|
229 } |
|
230 |
|
231 void CRoleSwitcher::SaveEncryption() |
|
232 { |
|
233 LOG_FUNC |
|
234 iIsEncrypted = iLink.Encrypted(); |
|
235 } |
|
236 |
|
237 TBool CRoleSwitcher::IsEPRSupported() const |
|
238 { |
|
239 LOG_FUNC |
|
240 // For Lisbon (Bluetooth 2.1), if EPR is supported both locally and remotely, |
|
241 // then the controllers will disable/enable encryption automatically for us, |
|
242 // so skip some states. |
|
243 return iLink.IsEncryptionPauseResumeSupported(); |
|
244 } |
|
245 |
|
246 void CRoleSwitcher::LogRoleSwitchSuccessful() const |
|
247 { |
|
248 LOG_FUNC |
|
249 TInt eventType; |
|
250 eventType = (iRole == EMaster ? ENotifyMaster :ENotifySlave); |
|
251 |
|
252 if (iBasebandEvent.EventType()==eventType && |
|
253 iBasebandEvent.ErrorCode()==KErrNone) |
|
254 { |
|
255 LOG(_L("CRoleSwitcher RoleSwitch OK")); |
|
256 } |
|
257 else |
|
258 { |
|
259 LOG(_L("CRoleSwitcher RoleSwitch failed")); |
|
260 } |
|
261 } |
|
262 |
|
263 void CRoleSwitcher::IoctlComplete(TDesC8 *aBuf) |
|
264 { |
|
265 LOG_FUNC |
|
266 const TBTBasebandEventNotification* event = reinterpret_cast<const TBTBasebandEventNotification*>(aBuf->Ptr()); |
|
267 iBasebandEvent = *event; |
|
268 iEventReceivedCallBack->CallBack(); |
|
269 } |
|
270 |
|
271 /*static*/ TInt CRoleSwitcher::EventReceivedCallBack(TAny* aRoleSwitcher) |
|
272 { |
|
273 LOG_STATIC_FUNC |
|
274 CRoleSwitcher* roleSwitcher = static_cast<CRoleSwitcher*>(aRoleSwitcher); |
|
275 roleSwitcher->iState->EventReceived(*roleSwitcher); |
|
276 return EFalse; |
|
277 } |
|
278 |
|
279 |
|
280 //---------------------------------------------------------------------------------- |
|
281 // STATE FACTORY |
|
282 //---------------------------------------------------------------------------------- |
|
283 |
|
284 CRoleSwitcherStateFactory* CRoleSwitcherStateFactory::NewL() |
|
285 { |
|
286 LOG_STATIC_FUNC |
|
287 CRoleSwitcherStateFactory* ret=new (ELeave) CRoleSwitcherStateFactory(); |
|
288 CleanupStack::PushL(ret); |
|
289 ret->ConstructL(); |
|
290 CleanupStack::Pop(ret); |
|
291 return ret; |
|
292 } |
|
293 |
|
294 void CRoleSwitcherStateFactory::ConstructL() |
|
295 { |
|
296 LOG_FUNC |
|
297 iStates[EIdle] =new (ELeave) TRSStateIdle(*this); |
|
298 iStates[EDisablingLPM] =new (ELeave) TRSStateDisablingLPM(*this); |
|
299 iStates[EDisablingEncryption] =new (ELeave) TRSStateDisablingEncryption(*this); |
|
300 iStates[EChangingRole] =new (ELeave) TRSStateChangingRole(*this); |
|
301 iStates[EChangingRoleWithEPR] =new (ELeave) TRSStateChangingRoleWithEPR(*this); |
|
302 iStates[EEnablingEncryption] =new (ELeave) TRSStateEnablingEncryption(*this); |
|
303 } |
|
304 |
|
305 CRoleSwitcherStateFactory::CRoleSwitcherStateFactory() |
|
306 { |
|
307 LOG_FUNC |
|
308 iStates.DeleteAll(); |
|
309 } |
|
310 |
|
311 TRoleSwitcherState& CRoleSwitcherStateFactory::GetState(CRoleSwitcherStateFactory::TRoleSwitcherStates aState) |
|
312 { |
|
313 LOG_FUNC |
|
314 __ASSERT_DEBUG(iStates[aState], Panic(ERoleSwitcherInvalidState)); |
|
315 return *iStates[aState]; |
|
316 } |
|
317 |
|
318 TInt CRoleSwitcherStateFactory::StateIndex(const TRoleSwitcherState* aState) const |
|
319 { |
|
320 LOG_FUNC |
|
321 TInt state; |
|
322 for (state = 0; state < ERoleSwitcherMaxState; state++) |
|
323 { |
|
324 if (iStates[state] == aState) |
|
325 { |
|
326 return state; |
|
327 } |
|
328 } |
|
329 |
|
330 return KUnknownState; |
|
331 } |
|
332 |
|
333 |
|
334 //---------------------------------------------------------------------------------- |
|
335 // STATES |
|
336 //---------------------------------------------------------------------------------- |
|
337 |
|
338 TRoleSwitcherState::TRoleSwitcherState(CRoleSwitcherStateFactory& aFactory) |
|
339 : iFactory(aFactory) |
|
340 { |
|
341 LOG_FUNC |
|
342 } |
|
343 |
|
344 void TRoleSwitcherState::PanicInState(TLinkPanic aPanic) const |
|
345 { |
|
346 LOG_FUNC |
|
347 Panic(aPanic, iFactory.StateIndex(this)); |
|
348 } |
|
349 |
|
350 void TRoleSwitcherState::ChangeState(CRoleSwitcher& aContext, CRoleSwitcherStateFactory::TRoleSwitcherStates aState) const |
|
351 { |
|
352 LOG_FUNC |
|
353 |
|
354 aContext.iState->Exit(aContext); |
|
355 |
|
356 #ifdef __FLOG_ACTIVE |
|
357 TRoleSwitcherState* state=&iFactory.GetState(aState); |
|
358 LOG2(_L("RoleSwitcher: State %S -> %S"), &aContext.iState->iName, &state->iName); |
|
359 #endif //__FLOG_ACTIVE |
|
360 aContext.iState=&iFactory.GetState(aState); |
|
361 |
|
362 aContext.iState->Enter(aContext); |
|
363 } |
|
364 |
|
365 void TRoleSwitcherState::Enter(CRoleSwitcher& /*aContext*/) const |
|
366 { |
|
367 LOG_FUNC |
|
368 // do nothing |
|
369 } |
|
370 |
|
371 void TRoleSwitcherState::Exit(CRoleSwitcher& /*aContext*/) const |
|
372 { |
|
373 LOG_FUNC |
|
374 // do nothing |
|
375 } |
|
376 |
|
377 void TRoleSwitcherState::Start(CRoleSwitcher& /*aContext*/) const |
|
378 { |
|
379 LOG_FUNC |
|
380 PanicInState(ERoleSwitcherStateMachineInvalidEvent); |
|
381 } |
|
382 |
|
383 void TRoleSwitcherState::Error(CRoleSwitcher& aContext, TInt /*aErr*/) const |
|
384 { |
|
385 LOG_FUNC |
|
386 aContext.CancelIoctl(); |
|
387 aContext.Cancel(); |
|
388 ChangeState(aContext, CRoleSwitcherStateFactory::EIdle); |
|
389 } |
|
390 |
|
391 void TRoleSwitcherState::EventReceived(CRoleSwitcher& /*aContext*/) const |
|
392 { |
|
393 LOG_FUNC |
|
394 // do nothing |
|
395 } |
|
396 |
|
397 void TRoleSwitcherState::TimerExpired(CRoleSwitcher& aContext) const |
|
398 { |
|
399 LOG_FUNC |
|
400 ChangeState(aContext, CRoleSwitcherStateFactory::EIdle); |
|
401 } |
|
402 |
|
403 //---------------------------------------------------------------------------------- |
|
404 |
|
405 TRSStateIdle::TRSStateIdle(CRoleSwitcherStateFactory& aFactory) |
|
406 : TRoleSwitcherState(aFactory) |
|
407 { |
|
408 LOG_FUNC |
|
409 STATENAME("TRSStateIdle"); |
|
410 } |
|
411 |
|
412 void TRSStateIdle::Start(CRoleSwitcher& aContext) const |
|
413 { |
|
414 LOG_FUNC |
|
415 aContext.After(KTimeoutRoleSwitch); // watchdog timer |
|
416 ChangeState(aContext, CRoleSwitcherStateFactory::EDisablingLPM); |
|
417 } |
|
418 |
|
419 void TRSStateIdle::Enter(CRoleSwitcher& aContext) const |
|
420 { |
|
421 LOG_FUNC |
|
422 aContext.Finish(); |
|
423 } |
|
424 |
|
425 //---------------------------------------------------------------------------------- |
|
426 |
|
427 TRSStateDisablingLPM::TRSStateDisablingLPM(CRoleSwitcherStateFactory& aFactory) |
|
428 : TRoleSwitcherState(aFactory) |
|
429 { |
|
430 LOG_FUNC |
|
431 STATENAME("TRSStateDisablingLPM"); |
|
432 } |
|
433 |
|
434 void TRSStateDisablingLPM::Enter(CRoleSwitcher& aContext) const |
|
435 { |
|
436 LOG_FUNC |
|
437 // DisableLPM even if link is active to prevent possible LPM requests during encryption disabling |
|
438 |
|
439 if (aContext.iLink.LinkMode() == EActiveMode) |
|
440 { |
|
441 aContext.DisableLPM(); |
|
442 if (aContext.IsEPRSupported()) |
|
443 { |
|
444 ChangeState(aContext, CRoleSwitcherStateFactory::EChangingRoleWithEPR); |
|
445 } |
|
446 else |
|
447 { |
|
448 ChangeState(aContext, CRoleSwitcherStateFactory::EDisablingEncryption); |
|
449 } |
|
450 // don't wait for notification |
|
451 } |
|
452 else |
|
453 { |
|
454 TBTBasebandEvent event(ENotifyActiveMode); |
|
455 aContext.iBTProxySAP->Ioctl(KSolBtLMProxy, KLMBasebandEventOneShotNotificationIoctl, &event); |
|
456 aContext.DisableLPM(); |
|
457 } |
|
458 } |
|
459 |
|
460 void TRSStateDisablingLPM::EventReceived(CRoleSwitcher& aContext) const |
|
461 { |
|
462 LOG_FUNC |
|
463 if (aContext.iBasebandEvent.EventType()==ENotifyActiveMode && |
|
464 aContext.iBasebandEvent.ErrorCode()==KErrNone) |
|
465 { |
|
466 if (aContext.IsEPRSupported()) |
|
467 { |
|
468 ChangeState(aContext, CRoleSwitcherStateFactory::EChangingRoleWithEPR); |
|
469 } |
|
470 else |
|
471 { |
|
472 ChangeState(aContext, CRoleSwitcherStateFactory::EDisablingEncryption); |
|
473 } |
|
474 } |
|
475 else |
|
476 { |
|
477 LOG(_L("CRoleSwitcher RoleSwitch failed in DisableLPM")); |
|
478 // we can quit SM, don't need to rewind |
|
479 ChangeState(aContext, CRoleSwitcherStateFactory::EIdle); |
|
480 } |
|
481 } |
|
482 |
|
483 //---------------------------------------------------------------------------------- |
|
484 TRSStateDisablingEncryption::TRSStateDisablingEncryption(CRoleSwitcherStateFactory& aFactory) |
|
485 : TRoleSwitcherState(aFactory) |
|
486 { |
|
487 LOG_FUNC |
|
488 STATENAME("TRSStateDisablingEncryption"); |
|
489 } |
|
490 |
|
491 void TRSStateDisablingEncryption::Enter(CRoleSwitcher& aContext) const |
|
492 { |
|
493 LOG_FUNC |
|
494 aContext.SaveEncryption(); |
|
495 if (aContext.iIsEncrypted) |
|
496 { |
|
497 aContext.DisableEncryption(); |
|
498 } |
|
499 else |
|
500 { |
|
501 ChangeState(aContext, CRoleSwitcherStateFactory::EChangingRole); |
|
502 } |
|
503 } |
|
504 |
|
505 void TRSStateDisablingEncryption::EventReceived(CRoleSwitcher& aContext) const |
|
506 { |
|
507 LOG_FUNC |
|
508 if (aContext.iBasebandEvent.EventType()==ENotifyEncryptionChangeOff && |
|
509 aContext.iBasebandEvent.ErrorCode()==KErrNone) |
|
510 { |
|
511 ChangeState(aContext, CRoleSwitcherStateFactory::EChangingRole); |
|
512 } |
|
513 else |
|
514 { |
|
515 LOG(_L("CRoleSwitcher RoleSwitch failed in DisableEncryption")); |
|
516 // before quiting SM , try to enable LPM |
|
517 aContext.EnableLPM(); |
|
518 ChangeState(aContext, CRoleSwitcherStateFactory::EIdle); |
|
519 } |
|
520 } |
|
521 |
|
522 void TRSStateDisablingEncryption::TimerExpired(CRoleSwitcher& aContext) const |
|
523 { |
|
524 LOG_FUNC |
|
525 aContext.CancelIoctl(); |
|
526 ChangeState(aContext, CRoleSwitcherStateFactory::EEnablingEncryption); |
|
527 } |
|
528 |
|
529 //---------------------------------------------------------------------------------- |
|
530 TRSStateChangingRole::TRSStateChangingRole(CRoleSwitcherStateFactory& aFactory) |
|
531 : TRoleSwitcherState(aFactory) |
|
532 { |
|
533 LOG_FUNC |
|
534 STATENAME("TRSStateChangingRole"); |
|
535 } |
|
536 |
|
537 void TRSStateChangingRole::Enter(CRoleSwitcher& aContext) const |
|
538 { |
|
539 LOG_FUNC |
|
540 aContext.ChangeRole(); |
|
541 } |
|
542 |
|
543 void TRSStateChangingRole::EventReceived(CRoleSwitcher& aContext) const |
|
544 { |
|
545 LOG_FUNC |
|
546 aContext.Cancel(); // cancel watchdog timer |
|
547 |
|
548 FTRACE(aContext.LogRoleSwitchSuccessful()); |
|
549 |
|
550 |
|
551 ChangeState(aContext, CRoleSwitcherStateFactory::EEnablingEncryption); |
|
552 } |
|
553 |
|
554 void TRSStateChangingRole::TimerExpired(CRoleSwitcher& aContext) const |
|
555 { |
|
556 LOG_FUNC |
|
557 aContext.CancelIoctl(); |
|
558 ChangeState(aContext, CRoleSwitcherStateFactory::EEnablingEncryption); |
|
559 } |
|
560 |
|
561 //---------------------------------------------------------------------------------- |
|
562 TRSStateChangingRoleWithEPR::TRSStateChangingRoleWithEPR(CRoleSwitcherStateFactory& aFactory) |
|
563 : TRoleSwitcherState(aFactory) |
|
564 { |
|
565 LOG_FUNC |
|
566 STATENAME("TRSStateChangingRoleWithEPR"); |
|
567 } |
|
568 |
|
569 void TRSStateChangingRoleWithEPR::Enter(CRoleSwitcher& aContext) const |
|
570 { |
|
571 LOG_FUNC |
|
572 aContext.ChangeRole(); |
|
573 } |
|
574 |
|
575 void TRSStateChangingRoleWithEPR::EventReceived(CRoleSwitcher& aContext) const |
|
576 { |
|
577 LOG_FUNC |
|
578 aContext.Cancel(); // cancel watchdog timer |
|
579 |
|
580 FTRACE(aContext.LogRoleSwitchSuccessful()); |
|
581 |
|
582 ChangeState(aContext, CRoleSwitcherStateFactory::EIdle); |
|
583 } |
|
584 |
|
585 void TRSStateChangingRoleWithEPR::TimerExpired(CRoleSwitcher& aContext) const |
|
586 { |
|
587 LOG_FUNC |
|
588 aContext.CancelIoctl(); |
|
589 ChangeState(aContext, CRoleSwitcherStateFactory::EIdle); |
|
590 } |
|
591 |
|
592 //---------------------------------------------------------------------------------- |
|
593 TRSStateEnablingEncryption::TRSStateEnablingEncryption(CRoleSwitcherStateFactory& aFactory) |
|
594 : TRoleSwitcherState(aFactory) |
|
595 { |
|
596 LOG_FUNC |
|
597 STATENAME("TRSStateEnablingEncryption"); |
|
598 } |
|
599 |
|
600 void TRSStateEnablingEncryption::Enter(CRoleSwitcher& aContext) const |
|
601 { |
|
602 LOG_FUNC |
|
603 if (aContext.iIsEncrypted) |
|
604 { |
|
605 aContext.After(KTimeoutOneCommand); |
|
606 aContext.EnableEncryption(); |
|
607 } |
|
608 else |
|
609 { |
|
610 aContext.EnableLPM(); |
|
611 ChangeState(aContext, CRoleSwitcherStateFactory::EIdle); |
|
612 } |
|
613 } |
|
614 |
|
615 void TRSStateEnablingEncryption::Exit(CRoleSwitcher& aContext) const |
|
616 { |
|
617 LOG_FUNC |
|
618 if (aContext.iIsEncrypted) |
|
619 { |
|
620 // enable data traffic |
|
621 aContext.iLinkMgr.LinkManagerProtocol().ACLController().SetParked(aContext.iLink.Handle(), EFalse); |
|
622 } |
|
623 } |
|
624 |
|
625 void TRSStateEnablingEncryption::EventReceived(CRoleSwitcher& aContext) const |
|
626 { |
|
627 LOG_FUNC |
|
628 aContext.Cancel(); // watchdog timer |
|
629 if (aContext.iBasebandEvent.EventType()==ENotifyEncryptionChangeOn && |
|
630 aContext.iBasebandEvent.ErrorCode()==KErrNone) |
|
631 { |
|
632 aContext.EnableLPM(); |
|
633 ChangeState(aContext, CRoleSwitcherStateFactory::EIdle); |
|
634 aContext.iIsEncryptionDisabledForRoleSwitch = EFalse; |
|
635 } |
|
636 else |
|
637 { |
|
638 LOG(_L("CRoleSwitcher SetEncryption failed, disconnect link")); |
|
639 if (aContext.iLink.Terminate(ERemoteUserEndedConnection) != KErrNone) |
|
640 { |
|
641 LOG(_L("CRoleSwitcher OOM")); |
|
642 } |
|
643 ChangeState(aContext, CRoleSwitcherStateFactory::EIdle); |
|
644 } |
|
645 } |
|
646 |
|
647 void TRSStateEnablingEncryption::TimerExpired(CRoleSwitcher& aContext) const |
|
648 { |
|
649 LOG_FUNC |
|
650 LOG(_L("CRoleSwitcher Timeout in EncryptionEnable, disconnect")); |
|
651 aContext.CancelIoctl(); |
|
652 if (aContext.iLink.Terminate(ERemoteUserEndedConnection) != KErrNone) |
|
653 { |
|
654 LOG(_L("CRoleSwitcher OOM")); |
|
655 } |
|
656 ChangeState(aContext, CRoleSwitcherStateFactory::EIdle); |
|
657 } |
|
658 |
|
659 |
|
660 |