|
1 /* |
|
2 * Copyright (c) 2002 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: Observer for ETel security events. Uses SecurityNotifier |
|
15 * which calls appropriate dialog to be opened from SecUi. |
|
16 * |
|
17 * |
|
18 */ |
|
19 |
|
20 #include <w32std.h> |
|
21 #include <e32std.h> |
|
22 #include <coedef.h> |
|
23 |
|
24 #include <e32base.h> |
|
25 #include <etelmm.h> |
|
26 #include <eiksrv.h> |
|
27 #include <e32property.h> |
|
28 #include <PSVariables.h> // Property values |
|
29 #include <CoreApplicationUIsPrivatePSKeys.h> |
|
30 #include <SecurityNotifier.h> |
|
31 #include <MmTsy_names.h> |
|
32 #include "SecurityObserver.h" |
|
33 #include "SecObsNotify.h" |
|
34 #include "SecurityObserver.hrh" |
|
35 |
|
36 |
|
37 // LOCAL CONSTANTS AND MACROS |
|
38 /***************************************************** |
|
39 * Series 60 Customer / TSY |
|
40 * Needs customer TSY implementation |
|
41 *****************************************************/ |
|
42 |
|
43 _LIT(SecObserver,"SecurityObserver"); |
|
44 |
|
45 const TInt KTriesToConnectServer( 2 ); |
|
46 const TInt KTimeBeforeRetryingServerConnection( 50000 ); |
|
47 const TInt PhoneIndex( 0 ); |
|
48 |
|
49 // LOCAL FUNCTION PROTOTYPES |
|
50 LOCAL_C void StartL(); |
|
51 |
|
52 |
|
53 //===================== LOCAL FUNCTIONS ==================== |
|
54 // |
|
55 //---------------------------------------------------------- |
|
56 // E32Main |
|
57 //---------------------------------------------------------- |
|
58 // |
|
59 GLDEF_C TInt E32Main() |
|
60 { |
|
61 __UHEAP_MARK; |
|
62 CTrapCleanup* theCleanup = CTrapCleanup::New(); |
|
63 TRAPD(ret,StartL()); |
|
64 delete theCleanup; |
|
65 __UHEAP_MARKEND; |
|
66 if (ret) |
|
67 { |
|
68 // Panic here in order to enter SW |
|
69 // reset mechanism. |
|
70 User::Panic(SecObserver,ret); |
|
71 } |
|
72 return(KErrNone); |
|
73 } |
|
74 |
|
75 #if defined(__WINS__) |
|
76 EXPORT_C TInt WinsMain(TAny *) |
|
77 { |
|
78 E32Main(); |
|
79 return KErrNone; |
|
80 } |
|
81 #endif // __WINS__ |
|
82 |
|
83 // |
|
84 //---------------------------------------------------------- |
|
85 // StartL() SecurityObserver starter. |
|
86 //---------------------------------------------------------- |
|
87 // |
|
88 LOCAL_C void StartL() |
|
89 { |
|
90 __UHEAP_MARK; |
|
91 |
|
92 #if defined(_DEBUG) |
|
93 RDebug::Print(_L("Starting SecurityObsever")); |
|
94 #endif |
|
95 |
|
96 |
|
97 #ifdef __WINS__ |
|
98 |
|
99 // do nothing... |
|
100 |
|
101 #else // __WINS__ |
|
102 TInt simStatus; |
|
103 #ifndef RD_STARTUP_CHANGE |
|
104 RProperty property; |
|
105 for(;;) |
|
106 { |
|
107 property.Get(KUidSystemCategory, KPSUidSimCStatusValue, simStatus); |
|
108 if (simStatus > EPSCSimInitWait) |
|
109 break; |
|
110 User::After(100000); |
|
111 } |
|
112 #endif //RD_STARTUP_CHANGE |
|
113 #endif // __WINS__ |
|
114 // rename thread to "SecurityObserver" |
|
115 User::RenameThread(SecObserver); |
|
116 |
|
117 //Initialise the PubSub variable used to distinguish between code requests |
|
118 //originated from DOS and SecUi |
|
119 _LIT_SECURITY_POLICY_PASS(KReadPolicy); |
|
120 _LIT_SECURITY_POLICY_C1(KWritePolicy, ECapabilityWriteDeviceData); |
|
121 TInt pSresult = RProperty::Define(KPSUidCoreApplicationUIs, KCoreAppUIsSecUIOriginatedQuery, RProperty::EInt, KReadPolicy, KWritePolicy); |
|
122 RProperty::Set(KPSUidCoreApplicationUIs, KCoreAppUIsSecUIOriginatedQuery, ECoreAppUIsETelAPIOriginated); |
|
123 #if defined(_DEBUG) |
|
124 RDebug::Print(_L("SecurityObsever PS Define result:´%d"), pSresult); |
|
125 #endif |
|
126 |
|
127 // Install active scheduler |
|
128 CActiveScheduler* theScheduler = new (ELeave) CActiveScheduler(); |
|
129 CleanupStack::PushL(theScheduler); |
|
130 CActiveScheduler::Install(theScheduler); |
|
131 |
|
132 // Start Observer |
|
133 CSecurityObserver * theObserver = CSecurityObserver::NewL(); |
|
134 CleanupStack::PushL(theObserver); |
|
135 |
|
136 #if defined(_DEBUG) |
|
137 RDebug::Print(_L("SecurityObsever has been started")); |
|
138 #endif |
|
139 |
|
140 // Run the scheduler |
|
141 CActiveScheduler::Start(); |
|
142 |
|
143 |
|
144 |
|
145 |
|
146 CleanupStack::PopAndDestroy(2);//theScheduler and theObserver |
|
147 |
|
148 __UHEAP_MARKEND; |
|
149 } |
|
150 // ================= MEMBER FUNCTIONS ======================= |
|
151 // |
|
152 // ---------------------------------------------------------- |
|
153 // CSecurityObserver::NewL() |
|
154 // Constructs a new entry. |
|
155 // ---------------------------------------------------------- |
|
156 // |
|
157 CSecurityObserver* CSecurityObserver::NewL() |
|
158 { |
|
159 CSecurityObserver* self = new (ELeave) CSecurityObserver(); |
|
160 CleanupStack::PushL(self); |
|
161 self->ConstructL(); |
|
162 CleanupStack::Pop(); |
|
163 return self; |
|
164 } |
|
165 |
|
166 // |
|
167 // ---------------------------------------------------------- |
|
168 // CSecurityObserver::ConstructL() |
|
169 // Symbian OS constructor |
|
170 // ---------------------------------------------------------- |
|
171 // |
|
172 void CSecurityObserver::ConstructL() |
|
173 { |
|
174 /***************************************************** |
|
175 * Series 60 Customer / ETel |
|
176 * Series 60 ETel API |
|
177 *****************************************************/ |
|
178 /***************************************************** |
|
179 * Series 60 Customer / TSY |
|
180 * Needs customer TSY implementation |
|
181 *****************************************************/ |
|
182 TInt err( KErrGeneral ); |
|
183 TInt thisTry( 0 ); |
|
184 RTelServer::TPhoneInfo PhoneInfo; |
|
185 //connect to ETel |
|
186 |
|
187 thisTry = 0; |
|
188 |
|
189 // connect to ETel server |
|
190 while ( ( err = iServer.Connect() ) != KErrNone && ( thisTry++ ) <= KTriesToConnectServer ) |
|
191 { |
|
192 User::After( KTimeBeforeRetryingServerConnection ); |
|
193 } |
|
194 User::LeaveIfError( err ); |
|
195 |
|
196 // load TSY |
|
197 err = iServer.LoadPhoneModule( KMmTsyModuleName ); |
|
198 if ( err != KErrAlreadyExists ) |
|
199 { |
|
200 // may return also KErrAlreadyExists if some other |
|
201 // is already loaded the tsy module. And that is |
|
202 // not an error. |
|
203 User::LeaveIfError( err ); |
|
204 } |
|
205 |
|
206 // open phone |
|
207 User::LeaveIfError(iServer.GetPhoneInfo(PhoneIndex, PhoneInfo)); |
|
208 User::LeaveIfError(iPhone.Open(iServer,PhoneInfo.iName)); |
|
209 |
|
210 // Add this active object to the scheduler. |
|
211 CActiveScheduler::Add(this); |
|
212 |
|
213 //start notifier controller |
|
214 iNotifierController = CSecObsNotify::NewL(this); |
|
215 |
|
216 //Sim lock observer |
|
217 iSimLockObserver = CSimLockObserver::NewL(iNotifierController); |
|
218 |
|
219 |
|
220 #if defined(_DEBUG) |
|
221 RDebug::Print(_L("SecurityObsever: Checking sim lock status")); |
|
222 #endif |
|
223 |
|
224 // check sim lock state at startup |
|
225 #ifndef RD_STARTUP_CHANGE |
|
226 TInt ret2; |
|
227 iProperty.Get(KUidSystemCategory, KPSUidSimLockStatusValue, ret2); |
|
228 |
|
229 if (ret2 == EPSSimLockRestrictionOn) |
|
230 { |
|
231 iNotifierController->StartNotifier(ESecuritySimLockRestrictionOn); |
|
232 } |
|
233 else |
|
234 { |
|
235 // start observing sim lock events |
|
236 iSimLockObserver->Start(); |
|
237 } |
|
238 #else //RD_STARTUP_CHANGE |
|
239 iSimLockObserver->Start(); |
|
240 #endif //RD_STARTUP_CHANGE |
|
241 |
|
242 #if defined(_DEBUG) |
|
243 RDebug::Print(_L("SecurityObsever: Checking sim status")); |
|
244 #endif |
|
245 |
|
246 #ifndef RD_STARTUP_CHANGE |
|
247 // check sim state at startup |
|
248 TInt simStatus; |
|
249 iProperty.Get(KUidSystemCategory, KPSUidSimCStatusValue, simStatus); |
|
250 |
|
251 switch (simStatus) |
|
252 { |
|
253 #if defined(__PROTOCOL_WCDMA) || defined(__UPIN) |
|
254 case EPSCSimUPinVerifyRequired: |
|
255 #if defined(_DEBUG) |
|
256 RDebug::Print(_L("SecurityObsever: UPin required ")); |
|
257 #endif |
|
258 |
|
259 iUPinRequired = ETrue; |
|
260 iNotifierController->StartNotifier(ESecurityNotifierUPin); |
|
261 // set the first notification request to ETel active |
|
262 StartListen(); |
|
263 return; |
|
264 #endif //__PROTOCOL_WCDMA |
|
265 case EPSCSimPinVerifyRequired: |
|
266 #if defined(_DEBUG) |
|
267 RDebug::Print(_L("SecurityObsever: Pin required ")); |
|
268 #endif |
|
269 |
|
270 iPin1Required = ETrue; |
|
271 iNotifierController->StartNotifier(ESecurityNotifierPin1); |
|
272 // set the first notification request to ETel active |
|
273 StartListen(); |
|
274 return; |
|
275 case EPSCSimBlocked: |
|
276 #if defined(_DEBUG) |
|
277 RDebug::Print(_L("SecurityObsever: Puk required ")); |
|
278 #endif |
|
279 |
|
280 iPuk1Required = ETrue; |
|
281 iNotifierController->StartNotifier(ESecurityNotifierPuk1); |
|
282 // set the first notification request to ETel active |
|
283 StartListen(); |
|
284 return; |
|
285 #if defined(__PROTOCOL_WCDMA) || defined(__UPIN) |
|
286 case EPSCSimUPinBlocked: |
|
287 #if defined(_DEBUG) |
|
288 RDebug::Print(_L("SecurityObsever: UPuk required ")); |
|
289 #endif |
|
290 |
|
291 iUPukRequired = ETrue; |
|
292 iNotifierController->StartNotifier(ESecurityNotifierUPuk); |
|
293 // set the first notification request to ETel active |
|
294 StartListen(); |
|
295 return; |
|
296 #endif //__PROTOCOL_WCDMA |
|
297 default: |
|
298 break; |
|
299 } |
|
300 |
|
301 #ifndef __WINS__ |
|
302 // check if security code is needed at startup |
|
303 for (;;) |
|
304 { |
|
305 iProperty.Get(KUidSystemCategory, KPSUidSecurityCodeStatusValue, ret2); |
|
306 if (ret2 == EPSSecurityCodeRequired) |
|
307 { |
|
308 iPassPhraseRequired = ETrue; |
|
309 iNotifierController->StartNotifier(ESecurityNotifierSecurityCode); |
|
310 break; |
|
311 } |
|
312 if (ret2 == EPSSecurityCodeNotRequired) |
|
313 { |
|
314 break; |
|
315 } |
|
316 User::After(100000); |
|
317 } |
|
318 #endif // __WINS__ |
|
319 |
|
320 |
|
321 #if defined(_DEBUG) |
|
322 RDebug::Print(_L("SecurityObsever: No Pin/Puk required. Start listening security events")); |
|
323 #endif |
|
324 #endif //RD_STARTUP_CHANGE |
|
325 // set the first notification request to ETel active |
|
326 StartListen(); |
|
327 } |
|
328 |
|
329 // |
|
330 // ---------------------------------------------------------- |
|
331 // CSecurityObserver::CSecurityObserver() |
|
332 // C++ constructor |
|
333 // ---------------------------------------------------------- |
|
334 // |
|
335 |
|
336 CSecurityObserver::CSecurityObserver(): CActive(0),iPin1Required(EFalse) |
|
337 ,iPuk1Required(EFalse) |
|
338 ,iPassPhraseRequired(EFalse) |
|
339 { |
|
340 } |
|
341 |
|
342 // |
|
343 // ---------------------------------------------------------- |
|
344 // CSecurityObserver::~CSecurityObserver() |
|
345 // C++ destructor. Stops observing ETel events and closes ETel connection. |
|
346 // ---------------------------------------------------------- |
|
347 // |
|
348 CSecurityObserver::~CSecurityObserver() |
|
349 { |
|
350 /***************************************************** |
|
351 * Series 60 Customer / ETel |
|
352 * Series 60 ETel API |
|
353 *****************************************************/ |
|
354 /***************************************************** |
|
355 * Series 60 Customer / TSY |
|
356 * Needs customer TSY implementation |
|
357 *****************************************************/ |
|
358 // Call DoCancel() if iActive |
|
359 Cancel(); |
|
360 |
|
361 if (iServer.Handle()) |
|
362 { |
|
363 iPhone.Close(); |
|
364 iServer.UnloadPhoneModule(KMmTsyModuleName); |
|
365 iServer.Close(); |
|
366 } |
|
367 |
|
368 delete iSimLockObserver; |
|
369 iSimLockObserver = NULL; |
|
370 delete iNotifierController; |
|
371 iNotifierController = NULL; |
|
372 } |
|
373 // |
|
374 // ---------------------------------------------------------- |
|
375 // CSecurityObserver::StartListen() |
|
376 // Starts observing ETel security events |
|
377 // ---------------------------------------------------------- |
|
378 // |
|
379 void CSecurityObserver::StartListen() |
|
380 { |
|
381 #if defined(_DEBUG) |
|
382 RDebug::Print(_L("(SECURITYOBSERVER)CSecurityObsever::StartListen()")); |
|
383 #endif |
|
384 if (!IsActive()) |
|
385 { |
|
386 iPhone.NotifySecurityEvent(iStatus, iEvent); |
|
387 SetActive(); |
|
388 } |
|
389 } |
|
390 // |
|
391 // ---------------------------------------------------------- |
|
392 // CSecurityObserver::RunL() |
|
393 // Handles security events received from ETel. |
|
394 // ---------------------------------------------------------- |
|
395 // |
|
396 void CSecurityObserver::RunL() |
|
397 { |
|
398 /***************************************************** |
|
399 * Series 60 Customer / ETel |
|
400 * Series 60 ETel API |
|
401 *****************************************************/ |
|
402 #if defined(_DEBUG) |
|
403 RDebug::Print(_L("(SECURITYOBSERVER)CSecurityObsever::RunL()")); |
|
404 #endif |
|
405 if (iStatus != KErrNone) |
|
406 return; |
|
407 |
|
408 switch(iEvent) |
|
409 { |
|
410 #if defined(__PROTOCOL_WCDMA) || defined(__UPIN) |
|
411 case RMobilePhone::EUniversalPinRequired: |
|
412 |
|
413 #if defined(_DEBUG) |
|
414 RDebug::Print(_L("SecurityObsever: Handling EUniversalPinRequired event")); |
|
415 #endif |
|
416 |
|
417 iUPinRequired = ETrue; |
|
418 iNotifierController->StartNotifier(ESecurityNotifierUPin); |
|
419 break; |
|
420 case RMobilePhone::EUniversalPukRequired: |
|
421 |
|
422 #if defined(_DEBUG) |
|
423 RDebug::Print(_L("SecurityObsever: Handling EUniversalPukRequired event")); |
|
424 #endif |
|
425 |
|
426 iUPukRequired = ETrue; |
|
427 iNotifierController->StartNotifier(ESecurityNotifierUPuk); |
|
428 break; |
|
429 #endif //__PROTOCOL_WCDMA |
|
430 case RMobilePhone::EPin1Required: |
|
431 |
|
432 #if defined(_DEBUG) |
|
433 RDebug::Print(_L("SecurityObsever: Handling EPin1Required event")); |
|
434 #endif |
|
435 |
|
436 iPin1Required = ETrue; |
|
437 iNotifierController->StartNotifier(ESecurityNotifierPin1); |
|
438 break; |
|
439 case RMobilePhone::EPuk1Required: |
|
440 |
|
441 #if defined(_DEBUG) |
|
442 RDebug::Print(_L("SecurityObsever: Handling EPuk1Required event")); |
|
443 #endif |
|
444 |
|
445 iPuk1Required = ETrue; |
|
446 iNotifierController->StartNotifier(ESecurityNotifierPuk1); |
|
447 break; |
|
448 case RMobilePhone::EPin2Required: |
|
449 |
|
450 #if defined(_DEBUG) |
|
451 RDebug::Print(_L("SecurityObsever: Handling EPin2Required event")); |
|
452 #endif |
|
453 |
|
454 iNotifierController->StartNotifier(ESecurityNotifierPin2); |
|
455 break; |
|
456 case RMobilePhone::EPuk2Required: |
|
457 |
|
458 #if defined(_DEBUG) |
|
459 RDebug::Print(_L("SecurityObsever: Handling EPuk2Required event")); |
|
460 #endif |
|
461 |
|
462 iNotifierController->StartNotifier(ESecurityNotifierPuk2); |
|
463 break; |
|
464 case RMobilePhone::EPhonePasswordRequired: |
|
465 |
|
466 #if defined(_DEBUG) |
|
467 RDebug::Print(_L("SecurityObsever: Handling EPhonePasswordRequired event")); |
|
468 #endif |
|
469 |
|
470 iPassPhraseRequired = ETrue; |
|
471 iNotifierController->StartNotifier(ESecurityNotifierSecurityCode); |
|
472 break; |
|
473 #if defined(__PROTOCOL_WCDMA) || defined(__UPIN) |
|
474 case RMobilePhone::EUniversalPinVerified: |
|
475 iUPinRequired = EFalse; |
|
476 break; |
|
477 case RMobilePhone::EUniversalPukVerified: |
|
478 iUPukRequired = EFalse; |
|
479 break; |
|
480 #endif //__PROTOCOL_WCDMA |
|
481 case RMobilePhone::EPin1Verified: |
|
482 iPin1Required = EFalse; |
|
483 break; |
|
484 case RMobilePhone::EPuk1Verified: |
|
485 iPuk1Required = EFalse; |
|
486 break; |
|
487 case RMobilePhone::EPhonePasswordVerified: |
|
488 iPassPhraseRequired = EFalse; |
|
489 break; |
|
490 default: |
|
491 break; |
|
492 } |
|
493 StartListen(); |
|
494 } |
|
495 // |
|
496 // ---------------------------------------------------------- |
|
497 // CSecurityObserver::DoCancel() |
|
498 // Stops observing ETel events. |
|
499 // ---------------------------------------------------------- |
|
500 // |
|
501 void CSecurityObserver::DoCancel() |
|
502 { |
|
503 /***************************************************** |
|
504 * Series 60 Customer / ETel |
|
505 * Series 60 ETel API |
|
506 *****************************************************/ |
|
507 #if defined(_DEBUG) |
|
508 RDebug::Print(_L("(SECURITYOBSERVER)CSecurityObsever::DoCancel()")); |
|
509 #endif |
|
510 iPhone.CancelAsyncRequest(EMobilePhoneNotifySecurityEvent); |
|
511 } |
|
512 |
|
513 // End of file |