|
1 // Copyright (c) 2006-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 // |
|
15 |
|
16 |
|
17 |
|
18 // INCLUDE FILES |
|
19 #include "CMmSimLockTsy.h" |
|
20 #include <ctsy/tflogger.h> |
|
21 #include <ctsy/pluginapi/cmmdatapackage.h> |
|
22 |
|
23 // ======== MEMBER FUNCTIONS ======== |
|
24 |
|
25 CMmSimLockTsy::CMmSimLockTsy() |
|
26 { |
|
27 return; |
|
28 } |
|
29 |
|
30 void CMmSimLockTsy::ConstructL( |
|
31 CMmCustomTsy* aMmCustomTsy ) |
|
32 { |
|
33 iMmCustomTsy = aMmCustomTsy; |
|
34 |
|
35 // Create req handle store |
|
36 #ifdef REQHANDLE_TIMER |
|
37 iTsyReqHandleStore = CMmTsyReqHandleStore::NewL( iMmCustomTsy, |
|
38 iMmCustomTsy->iMmPhoneTsy, ESimLockRequestTypeMaxNumOfRequests, |
|
39 iSimLockReqHandles ); |
|
40 #else |
|
41 iTsyReqHandleStore = CMmTsyReqHandleStore::NewL( |
|
42 ESimLockRequestTypeMaxNumOfRequests, iSimLockReqHandles ); |
|
43 #endif // REQHANDLE_TIMER |
|
44 |
|
45 return; |
|
46 } |
|
47 |
|
48 CMmSimLockTsy* CMmSimLockTsy::NewL( |
|
49 CMmCustomTsy* aMmCustomTsy ) |
|
50 { |
|
51 CMmSimLockTsy* self = new (ELeave) CMmSimLockTsy(); |
|
52 |
|
53 CleanupStack::PushL( self ); |
|
54 self->ConstructL( aMmCustomTsy ); |
|
55 CleanupStack::Pop(); |
|
56 |
|
57 return self; |
|
58 } |
|
59 |
|
60 CMmSimLockTsy::~CMmSimLockTsy() |
|
61 { |
|
62 delete iTsyReqHandleStore; |
|
63 } |
|
64 |
|
65 // --------------------------------------------------------------------------- |
|
66 // CMmSimLockTsy::Init |
|
67 // Initialisation method that is called from ETel Server. |
|
68 // (other items were commented in a header). |
|
69 // --------------------------------------------------------------------------- |
|
70 // |
|
71 void CMmSimLockTsy::Init() |
|
72 { |
|
73 } |
|
74 |
|
75 // --------------------------------------------------------------------------- |
|
76 // CMmSimLockTsy::SupportingIPC |
|
77 // Tells whether the object supports given IPC. |
|
78 // (other items were commented in a header). |
|
79 // --------------------------------------------------------------------------- |
|
80 // |
|
81 TBool CMmSimLockTsy::SupportingIPC( |
|
82 TInt aIpc ) |
|
83 { |
|
84 TBool ret( EFalse ); |
|
85 |
|
86 switch ( aIpc ) |
|
87 { |
|
88 case ECustomSimLockActivateIPC: |
|
89 case ECustomSimLockDeActivateIPC: |
|
90 { |
|
91 ret = ETrue; |
|
92 break; |
|
93 } |
|
94 default: |
|
95 { |
|
96 ret = EFalse; |
|
97 break; |
|
98 } |
|
99 } |
|
100 |
|
101 return ret; |
|
102 } |
|
103 |
|
104 // --------------------------------------------------------------------------- |
|
105 // CMmSimLockTsy::DoExtFuncL |
|
106 // Dispatches extension function requests. At the beginning of this method, |
|
107 // packaged pointers are unpacked. Then the correct function is selected |
|
108 // using the IPC number. |
|
109 // If the IPC is supported, return the return value of corresponding function, |
|
110 // else return KErrNotSupported. |
|
111 // (other items were commented in a header). |
|
112 // --------------------------------------------------------------------------- |
|
113 // |
|
114 TInt CMmSimLockTsy::DoExtFuncL( |
|
115 const TTsyReqHandle aTsyReqHandle, |
|
116 const TInt aIpc, |
|
117 const TDataPackage& aPackage ) |
|
118 { |
|
119 switch ( aIpc ) |
|
120 { |
|
121 case ECustomSimLockActivateIPC: |
|
122 return ActivateSimLockL( aTsyReqHandle, |
|
123 REINTERPRET_CAST( RMmCustomAPI::TSimLockPassword*, |
|
124 aPackage.Ptr1() ), |
|
125 REINTERPRET_CAST( RMmCustomAPI::TLockNumber*, |
|
126 aPackage.Ptr2() ) ); |
|
127 case ECustomSimLockDeActivateIPC: |
|
128 return DeActivateSimLockL( aTsyReqHandle, |
|
129 REINTERPRET_CAST( RMmCustomAPI::TSimLockPassword*, |
|
130 aPackage.Ptr1() ), |
|
131 REINTERPRET_CAST( RMmCustomAPI::TLockNumber*, |
|
132 aPackage.Ptr2() ) ); |
|
133 default: |
|
134 return KErrNotSupported; |
|
135 } |
|
136 } |
|
137 |
|
138 // --------------------------------------------------------------------------- |
|
139 // CMmSimLockTsy::ReqModeL |
|
140 // Returns request mode for given IPC. Leaves with error code KErrNotSupported |
|
141 // if the IPC number does not belong to some of the SimLock API functions. |
|
142 // (other items were commented in a header). |
|
143 // --------------------------------------------------------------------------- |
|
144 // |
|
145 CTelObject::TReqMode CMmSimLockTsy::ReqModeL( |
|
146 const TInt aIpc ) |
|
147 { |
|
148 CTelObject::TReqMode ret = 0; |
|
149 |
|
150 switch ( aIpc ) |
|
151 { |
|
152 case ECustomSimLockActivateIPC: |
|
153 case ECustomSimLockDeActivateIPC: |
|
154 ret = 0; // flow control in tsy |
|
155 break; |
|
156 default: |
|
157 User::Leave(KErrNotSupported); |
|
158 break; |
|
159 } |
|
160 |
|
161 return ret; |
|
162 } |
|
163 |
|
164 // --------------------------------------------------------------------------- |
|
165 // CMmSimLockTsy::NumberOfSlotsL |
|
166 // Returns number of slots to be used for given IPC. Leaves with error code |
|
167 // KErrNotSupported if the IPC number does not belong to some of the SimLock |
|
168 // API functions. |
|
169 // (other items were commented in a header). |
|
170 // --------------------------------------------------------------------------- |
|
171 // |
|
172 TInt CMmSimLockTsy::NumberOfSlotsL( |
|
173 const TInt aIpc ) |
|
174 { |
|
175 TInt numberOfSlots = KMmCustomDefaultSlots; |
|
176 |
|
177 switch ( aIpc ) |
|
178 { |
|
179 case ECustomSimLockActivateIPC: |
|
180 case ECustomSimLockDeActivateIPC: |
|
181 numberOfSlots = KMmCustomSimLockSlots; |
|
182 break; |
|
183 default: |
|
184 // Unknown or invalid IPC |
|
185 User::Leave( KErrNotSupported ); |
|
186 break; |
|
187 } |
|
188 |
|
189 return numberOfSlots; |
|
190 } |
|
191 |
|
192 // --------------------------------------------------------------------------- |
|
193 // CMmSimLockTsy::CancelService |
|
194 // When the clients close their sub-sessions (eg. by calling RPhone::Close), |
|
195 // they may not have cancelled all their outstanding asynchronous requests |
|
196 // before closing. It is up to the ETel server to clean up in this situation, |
|
197 // so the server will find the list of outstanding requests related to that |
|
198 // sub-session object and pass these outstanding IPC request numbers, one at |
|
199 // a time, to the CancelService function in the TSY. |
|
200 // (other items were commented in a header). |
|
201 // --------------------------------------------------------------------------- |
|
202 // |
|
203 TInt CMmSimLockTsy::CancelService( |
|
204 const TInt aIpc, |
|
205 const TTsyReqHandle ) |
|
206 { |
|
207 TInt ret( KErrGeneral ); |
|
208 |
|
209 switch ( aIpc ) |
|
210 { |
|
211 case ECustomSimLockActivateIPC: |
|
212 case ECustomSimLockDeActivateIPC: |
|
213 // request can't be cancelled on DOS side |
|
214 ret = KErrNone; |
|
215 break; |
|
216 default: |
|
217 return KErrGeneral; |
|
218 } |
|
219 |
|
220 return ret; |
|
221 } |
|
222 |
|
223 // --------------------------------------------------------------------------- |
|
224 // CMmSimLockTsy::RegisterNotification |
|
225 // Called when the server recognises this notification being posted for |
|
226 // the first time on this sub-session object. It enables the TSY to "turn on" |
|
227 // any regular notification messages that it may receive from DOS. |
|
228 // (other items were commented in a header). |
|
229 // --------------------------------------------------------------------------- |
|
230 // |
|
231 TInt CMmSimLockTsy::RegisterNotification( |
|
232 const TInt ) |
|
233 { |
|
234 return KErrNotSupported; |
|
235 } |
|
236 |
|
237 // --------------------------------------------------------------------------- |
|
238 // CMmSimLockTsy::DeregisterNotification |
|
239 // Called when the server recognises that this notification will not be posted |
|
240 // again because the last client to have a handle on this sub-session object |
|
241 // has just closed the handle. It enables the TSY to "turn off" any regular |
|
242 // notification messages that it may receive from DOS. |
|
243 // (other items were commented in a header). |
|
244 // --------------------------------------------------------------------------- |
|
245 // |
|
246 TInt CMmSimLockTsy::DeregisterNotification( |
|
247 const TInt ) |
|
248 { |
|
249 return KErrNotSupported; |
|
250 } |
|
251 |
|
252 // --------------------------------------------------------------------------- |
|
253 // CMmSimLockTsy::ActivateSimLockL |
|
254 // This method activates SimLock. |
|
255 // (other items were commented in a header). |
|
256 // --------------------------------------------------------------------------- |
|
257 // |
|
258 TInt CMmSimLockTsy::ActivateSimLockL( |
|
259 const TTsyReqHandle aTsyReqHandle, |
|
260 RMmCustomAPI::TSimLockPassword* aPassword, |
|
261 RMmCustomAPI::TLockNumber* aLockNumber ) |
|
262 { |
|
263 TInt ret( KErrArgument ); |
|
264 |
|
265 if ( NULL != iTsyReqHandleStore->GetTsyReqHandle( |
|
266 ESimLockRequestTypeActivateSimLock ) ) |
|
267 { |
|
268 return KErrServerBusy; |
|
269 } |
|
270 |
|
271 switch ( *aLockNumber ) |
|
272 { |
|
273 case RMmCustomAPI::EOperator: |
|
274 case RMmCustomAPI::EGid1: |
|
275 case RMmCustomAPI::EGid2: |
|
276 case RMmCustomAPI::EImsi: |
|
277 case RMmCustomAPI::EOperator_Gid1: |
|
278 case RMmCustomAPI::EOperator_Gid2: |
|
279 iActivateSimLockNumber = aLockNumber; |
|
280 break; |
|
281 default: |
|
282 return KErrArgument; |
|
283 } |
|
284 iActivateSimLockPassword = aPassword; |
|
285 |
|
286 // Ask DOS to activate SimLock |
|
287 // packed parameters: RMmCustomAPI::TSimLockPassword and |
|
288 // RMmCustomAPI::TLockNumber |
|
289 CMmDataPackage dataPackage; |
|
290 dataPackage.PackData( aPassword, aLockNumber ); |
|
291 ret = iMmCustomTsy->Phone()->MessageManager()->HandleRequestL( |
|
292 ECustomSimLockActivateIPC, &dataPackage ); |
|
293 |
|
294 if ( KErrNone == ret ) |
|
295 { |
|
296 #ifdef REQHANDLE_TIMER |
|
297 SetTypeOfResponse( ESimLockRequestTypeActivateSimLock, |
|
298 aTsyReqHandle ); |
|
299 #else |
|
300 iTsyReqHandleStore->SetTsyReqHandle( |
|
301 ESimLockRequestTypeActivateSimLock, aTsyReqHandle ); |
|
302 #endif // REQHANDLE_TIMER |
|
303 } |
|
304 |
|
305 return ret; |
|
306 } |
|
307 |
|
308 // --------------------------------------------------------------------------- |
|
309 // CMmSimLockTsy::CompleteActivateSimLock |
|
310 // Completes ActivateSimLock request. |
|
311 // (other items were commented in a header). |
|
312 // --------------------------------------------------------------------------- |
|
313 // |
|
314 void CMmSimLockTsy::CompleteActivateSimLock( |
|
315 TInt aError ) |
|
316 { |
|
317 if ( NULL != iTsyReqHandleStore->GetTsyReqHandle( |
|
318 ESimLockRequestTypeActivateSimLock ) ) |
|
319 { |
|
320 iMmCustomTsy->ReqCompleted( iTsyReqHandleStore-> |
|
321 ResetTsyReqHandle( ESimLockRequestTypeActivateSimLock ), aError ); |
|
322 } |
|
323 } |
|
324 |
|
325 // --------------------------------------------------------------------------- |
|
326 // CMmSimLockTsy::DeActivateSimLockL |
|
327 // This method deactivates SimLock. |
|
328 // (other items were commented in a header). |
|
329 // --------------------------------------------------------------------------- |
|
330 // |
|
331 TInt CMmSimLockTsy::DeActivateSimLockL( |
|
332 const TTsyReqHandle aTsyReqHandle, |
|
333 RMmCustomAPI::TSimLockPassword* aPassword, |
|
334 RMmCustomAPI::TLockNumber* aLockNumber ) |
|
335 { |
|
336 TInt ret( KErrArgument ); |
|
337 |
|
338 if ( NULL != iTsyReqHandleStore->GetTsyReqHandle( |
|
339 ESimLockRequestTypeDeActivateSimLock ) ) |
|
340 { |
|
341 return KErrServerBusy; |
|
342 } |
|
343 |
|
344 switch ( *aLockNumber ) |
|
345 { |
|
346 case RMmCustomAPI::EOperator: |
|
347 case RMmCustomAPI::EGid1: |
|
348 case RMmCustomAPI::EGid2: |
|
349 case RMmCustomAPI::EImsi: |
|
350 case RMmCustomAPI::EOperator_Gid1: |
|
351 case RMmCustomAPI::EOperator_Gid2: |
|
352 case RMmCustomAPI::EGlobalUnlock: |
|
353 iDeActivateSimLockNumber = aLockNumber; |
|
354 break; |
|
355 default: |
|
356 return KErrArgument; |
|
357 } |
|
358 |
|
359 iDeActivateSimLockPassword = aPassword; |
|
360 |
|
361 // Ask DOS to deactivate SimLock |
|
362 // packed parameters: RMmCustomAPI::TSimLockPassword and |
|
363 // RMmCustomAPI::TLockNumber |
|
364 CMmDataPackage dataPackage; |
|
365 dataPackage.PackData( aPassword, aLockNumber ); |
|
366 ret = iMmCustomTsy->Phone()->MessageManager()->HandleRequestL( |
|
367 ECustomSimLockDeActivateIPC, &dataPackage ); |
|
368 |
|
369 if ( KErrNone == ret ) |
|
370 { |
|
371 #ifdef REQHANDLE_TIMER |
|
372 SetTypeOfResponse( ESimLockRequestTypeDeActivateSimLock, |
|
373 aTsyReqHandle ); |
|
374 #else |
|
375 iTsyReqHandleStore->SetTsyReqHandle( |
|
376 ESimLockRequestTypeDeActivateSimLock, aTsyReqHandle ); |
|
377 #endif // REQHANDLE_TIMER |
|
378 } |
|
379 |
|
380 return ret; |
|
381 } |
|
382 |
|
383 // --------------------------------------------------------------------------- |
|
384 // CMmSimLockTsy::CompleteDeActivateSimLock |
|
385 // Completes DeActivateSimLock request. |
|
386 // (other items were commented in a header). |
|
387 // --------------------------------------------------------------------------- |
|
388 // |
|
389 void CMmSimLockTsy::CompleteDeActivateSimLock( |
|
390 TInt aError ) |
|
391 { |
|
392 if ( NULL != iTsyReqHandleStore->GetTsyReqHandle( |
|
393 ESimLockRequestTypeDeActivateSimLock ) ) |
|
394 { |
|
395 iMmCustomTsy->ReqCompleted( iTsyReqHandleStore-> |
|
396 ResetTsyReqHandle( ESimLockRequestTypeDeActivateSimLock ), |
|
397 aError ); |
|
398 } |
|
399 } |
|
400 |
|
401 #ifdef REQHANDLE_TIMER |
|
402 // --------------------------------------------------------------------------- |
|
403 // CMmSimLockTsy::SetTypeOfResponse |
|
404 // Sets the type of response for a given handle. Automatic mode includes an |
|
405 // automatic response in case of non response from the DOS in a specified time. |
|
406 // (other items were commented in a header). |
|
407 // --------------------------------------------------------------------------- |
|
408 // |
|
409 void CMmSimLockTsy::SetTypeOfResponse( |
|
410 const TInt aReqHandleType, |
|
411 const TTsyReqHandle aTsyReqHandle ) |
|
412 { |
|
413 TInt timeOut( 0 ); |
|
414 TInt ipc( 0 ); |
|
415 |
|
416 switch ( aReqHandleType ) |
|
417 { |
|
418 case ESimLockRequestTypeActivateSimLock: |
|
419 timeOut = KMmActivateSimLockTimeOut; |
|
420 ipc = ECustomSimLockActivateIPC; |
|
421 break; |
|
422 case ESimLockRequestTypeDeActivateSimLock: |
|
423 timeOut = KMmDeactivateSimLockTimeOut; |
|
424 ipc = ECustomSimLockDeActivateIPC; |
|
425 break; |
|
426 default: |
|
427 // Does not use timer |
|
428 iTsyReqHandleStore->SetTsyReqHandle( |
|
429 aReqHandleType, aTsyReqHandle ); |
|
430 break; |
|
431 } |
|
432 |
|
433 if ( 0 < timeOut ) |
|
434 { |
|
435 // The timeout parameter is given in seconds. |
|
436 iTsyReqHandleStore->SetTsyReqHandle( aReqHandleType, aTsyReqHandle, |
|
437 timeOut, ipc ); |
|
438 } |
|
439 } |
|
440 |
|
441 // --------------------------------------------------------------------------- |
|
442 // CMmSimLockTsy::Complete |
|
443 // Completes the request due the timer expiration. |
|
444 // (other items were commented in a header). |
|
445 // --------------------------------------------------------------------------- |
|
446 // |
|
447 void CMmSimLockTsy::Complete( |
|
448 TInt aReqHandleType, |
|
449 TInt aError ) |
|
450 { |
|
451 TFLOGSTRING3( "CMmCustomTsy: CMmSimLockTsy::Complete.\n\t ReqHandleType:%d \n\t Error:%d\n", aReqHandleType, aError ); |
|
452 |
|
453 // All possible TSY req handle types are listed in the |
|
454 // switch case below. |
|
455 switch ( aReqHandleType ) |
|
456 { |
|
457 case ESimLockRequestTypeActivateSimLock: |
|
458 CompleteActivateSimLock( aError ); |
|
459 break; |
|
460 case ESimLockRequestTypeDeActivateSimLock: |
|
461 CompleteDeActivateSimLock( aError ); |
|
462 break; |
|
463 default: |
|
464 iMmCustomTsy->ReqCompleted( iTsyReqHandleStore->ResetTsyReqHandle( |
|
465 aReqHandleType ), aError ); |
|
466 break; |
|
467 } |
|
468 } |
|
469 #endif // REQHANDLE_TIMER |
|
470 |
|
471 // End of File |