comparison src/aci2/mfw/mfw_sim.~c @ 3:93999a60b835

src/aci2, src/condat2: import of g23m/condat source pieces from TCS211
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 26 Sep 2016 00:29:36 +0000 (2016-09-26)
parents
children
comparison
equal deleted inserted replaced
2:c41a534f33c6 3:93999a60b835
1 /*
2 +--------------------------------------------------------------------+
3 | PROJECT: MMI-Framework (8417) $Workfile:: mfw_sim.c $|
4 | $Author:: Vo $Revision:: 1 $|
5 | CREATED: 13.10.98 $Modtime:: 22.03.00 17:21 $|
6 | STATE : code |
7 +--------------------------------------------------------------------+
8
9 MODULE : MFW_SIM
10
11 PURPOSE : This modul contains the functions for SIM management.
12
13
14 $History:: mfw_sim.c $
15 *
16 * ***************** Version 43 *****************
17 * User: Vo Date: 22.03.00 Time: 17:29
18 * Updated in $/GSM/Condat/MS/SRC/MFW
19 * Add new parameter PIN type in structure T_MFW_SIM_STATUS to
20 * identify PIN type
21 * Change in SIM lock
22 *
23 * ***************** Version 42 *****************
24 * User: Es Date: 2.03.00 Time: 16:18
25 * Updated in $/GSM/Condat/MS/SRC/MFW
26 * use 'aci_delete()' instead of 'aci_ext_init()' to clear the
27 * primitive routing for mfw_sim. (because other routings may have to
28 * be preserved!)
29 *
30 * ***************** Version 41 *****************
31 * User: Vo Date: 22.12.99 Time: 16:03
32 * Updated in $/GSM/Condat/MS/SRC/MFW
33 * Remove maximum preferred PLMN records and used preferred PLMN
34 * records in local memory
35 *
36 * ***************** Version 40 *****************
37 * User: Vo Date: 2.12.99 Time: 13:18
38 * Updated in $/GSM/Condat/MS/SRC/MFW
39 * New: request of max/used perferred PLMN list
40 *
41 * ***************** Version 39 *****************
42 * User: Vo Date: 17.11.99 Time: 11:37
43 * Updated in $/GSM/Condat/MS/SRC/MFW
44 * Bug fix: de-personalisation for SIM lock
45 * New: SIM inserted
46 *
47 * ***************** Version 38 *****************
48 * User: Vo Date: 21.10.99 Time: 13:26
49 * Updated in $/GSM/Condat/MS/SRC/MFW
50 * add response of de-registration
51 |
52 | ***************** Version 37 *****************
53 | User: Le Date: 11.10.99 Time: 16:27
54 | Updated in $/GSM/Condat/MS/SRC/MFW
55 |
56 | ***************** Version 36 *****************
57 | User: Le Date: 8.10.99 Time: 13:38
58 | Updated in $/GSM/Condat/MS/SRC/MFW
59 |
60 | ***************** Version 35 *****************
61 | User: Le Date: 4.10.99 Time: 10:33
62 | Updated in $/GSM/Condat/MS/SRC/MFW
63 *
64 * ***************** Version 34 *****************
65 * User: Es Date: 29.09.99 Time: 11:20
66 * Updated in $/GSM/DEV/MS/SRC/MFW
67 * including CFUN_OK enhancement by AK, not fully implemented
68 *
69 * ***************** Version 33 *****************
70 * User: Es Date: 16.09.99 Time: 16:56
71 * Updated in $/GSM/DEV/MS/SRC/MFW
72 * reordered include statements due to addons in mfw_phb.h
73 *
74 * ***************** Version 32 *****************
75 * User: Vo Date: 13.09.99 Time: 12:05
76 * Updated in $/GSM/DEV/MS/SRC/MFW
77 * change comment
78 *
79 * ***************** Version 31 *****************
80 * User: Vo Date: 12.09.99 Time: 15:32
81 * Updated in $/GSM/DEV/MS/SRC/MFW
82 * Bug fix: change PIN
83 * Bug fix/New: SIM lock
84 * New: request of PIN status
85 * New: save preferred language
86 * New: read group identifier level 1 & 2
87 *
88 * ***************** Version 30 *****************
89 * User: Vo Date: 30.08.99 Time: 14:23
90 * Updated in $/GSM/DEV/MS/SRC/MFW
91 * bug fix
92 * new function
93 *
94 * ***************** Version 29 *****************
95 * User: Vo Date: 9.08.99 Time: 13:11
96 * Updated in $/GSM/DEV/MS/SRC/MFW
97 * PIN/PUK count
98 *
99 * ***************** Version 28 *****************
100 * User: Vo Date: 26.07.99 Time: 14:34
101 * Updated in $/GSM/DEV/MS/SRC/MFW
102 * Move include file mfw_cb.h
103 *
104 * ***************** Version 27 *****************
105 * User: Vo Date: 21.07.99 Time: 14:41
106 * Updated in $/GSM/DEV/MS/SRC/MFW
107 *
108 * ***************** Version 26 *****************
109 * User: Vo Date: 16.07.99 Time: 13:50
110 * Updated in $/GSM/DEV/MS/SRC/MFW
111 *
112 * ***************** Version 25 *****************
113 * User: Vo Date: 9.07.99 Time: 14:34
114 * Updated in $/GSM/DEV/MS/SRC/MFW
115 *
116 * ***************** Version 24 *****************
117 * User: Vo Date: 2.07.99 Time: 19:03
118 * Updated in $/GSM/DEV/MS/SRC/MFW
119 *
120 * ***************** Version 23 *****************
121 * User: Vo Date: 28.05.99 Time: 9:52
122 * Updated in $/GSM/DEV/MS/SRC/MFW
123 *
124 * ***************** Version 22 *****************
125 * User: Vo Date: 31.03.99 Time: 14:09
126 * Updated in $/GSM/DEV/MS/SRC/MFW
127 *
128 * ***************** Version 21 *****************
129 * User: Es Date: 15.03.99 Time: 18:21
130 * Updated in $/GSM/DEV/MS/SRC/MFW
131 * recode
132 *
133 * ***************** Version 20 *****************
134 * User: Vo Date: 25.02.99 Time: 16:47
135 * Updated in $/GSM/DEV/MS/SRC/MFW
136 *
137 * ***************** Version 19 *****************
138 * User: Vo Date: 17.02.99 Time: 19:03
139 * Updated in $/GSM/DEV/MS/SRC/MFW
140 *
141 * ***************** Version 18 *****************
142 * User: Vo Date: 12.02.99 Time: 18:05
143 * Updated in $/GSM/DEV/MS/SRC/MFW
144 *
145 * ***************** Version 17 *****************
146 * User: Vo Date: 12.02.99 Time: 17:46
147 * Updated in $/GSM/DEV/MS/SRC/MFW
148 *
149 * ***************** Version 16 *****************
150 * User: Vo Date: 9.02.99 Time: 14:54
151 * Updated in $/GSM/DEV/MS/SRC/MFW
152 *
153 * ***************** Version 15 *****************
154 * User: Vo Date: 12.01.99 Time: 14:27
155 * Updated in $/GSM/DEV/MS/SRC/MFW
156 *
157 * ***************** Version 14 *****************
158 * User: Es Date: 23.12.98 Time: 15:47
159 * Updated in $/GSM/DEV/MS/SRC/MFW
160 *
161 * ***************** Version 12 *****************
162 * User: Es Date: 18.12.98 Time: 13:05
163 * Updated in $/GSM/DEV/MS/SRC/MFW
164 *
165 * ***************** Version 11 *****************
166 * User: Vo Date: 17.12.98 Time: 14:31
167 * Updated in $/GSM/DEV/MS/SRC/MFW
168 *
169 * ***************** Version 10 *****************
170 * User: Es Date: 8.12.98 Time: 16:53
171 * Updated in $/GSM/DEV/MS/SRC/MFW
172 *
173 * ***************** Version 8 *****************
174 * User: Vo Date: 24.11.98 Time: 21:40
175 * Updated in $/GSM/DEV/MS/SRC/MFW
176 * first successful compilation of MFW
177 |
178 | ***************** Version 6 *****************
179 | User: Le Date: 11.11.98 Time: 13:35
180 | Updated in $/GSM/DEV/MS/SRC/MFW
181 |
182 | ***************** Version 5 *****************
183 | User: Le Date: 10.11.98 Time: 16:07
184 | Updated in $/GSM/DEV/MS/SRC/MFW
185 |
186 | ***************** Version 4 *****************
187 | User: Le Date: 10.11.98 Time: 11:08
188 | Updated in $/GSM/DEV/MS/SRC/MFW
189 |
190 | ***************** Version 3 *****************
191 | User: Le Date: 27.10.98 Time: 15:59
192 | Updated in $/GSM/DEV/MS/SRC/MFW
193 |
194 | ***************** Version 2 *****************
195 | User: Le Date: 21.10.98 Time: 16:20
196 | Updated in $/GSM/DEV/MS/SRC/MFW
197 */
198
199 #define ENTITY_MFW
200
201 #include <string.h>
202 #include <stdio.h>
203 #include <stdlib.h>
204
205 #if defined (NEW_FRAME)
206
207 #include "typedefs.h"
208 #include "vsi.h"
209 #include "pei.h"
210 #include "custom.h"
211 #include "gsm.h"
212
213 #else
214
215 #include "stddefs.h"
216 #include "custom.h"
217 #include "gsm.h"
218 #include "vsi.h"
219
220 #endif
221
222 #include "p_sim.h"
223 #include "aci_cmh.h"
224 #include "psa.h"
225 #include "psa_sim.h"
226 #include "pcm.h"
227 #include "mfw_mfw.h"
228 #include "mfw_nm.h"
229 #include "mfw_sim.h"
230 #include "mfw_sima.h"
231 #include "mfw_simi.h"
232 #include "mfw_nmi.h"
233 #include "mfw_nma.h"
234 #include "mfw_phb.h"
235 #include "mfw_cm.h"
236 #include "mfw_cmi.h"
237 #include "mfw_acie.h"
238 #include "mfw_sms.h"
239 #include "mfw_smsi.h"
240 #include "mfw_win.h"
241
242
243 #include "ksd.h"
244 #include "psa.h"
245
246 #if defined (FAX_AND_DATA)
247 #include "aci_fd.h"
248 #endif
249
250 #include "cmh.h"
251 #include "phb.h"
252 #include "cmh_phb.h"
253
254 #include "mfw_ss.h"
255 #include "mfw_ssi.h"
256
257 #ifdef SIM_TOOLKIT
258 #include "mfw_sat.h"
259 #endif
260
261 extern BOOL sima_response_cb (USHORT opc, void * data);
262 extern void simDecodeIMSI (UBYTE *ci, UBYTE li, UBYTE *di);
263 extern UBYTE mfw_IMSI []; /* expanded IMSI (ASCIIZ) */
264 static T_MFW_SIM_STATUS sim_status;
265 static T_MFW_SIM_CONFIG sim_config;
266 static int pin_flag;
267 static UBYTE pin_ident;
268
269 UBYTE sim_nlock; /* Network lock */
270 UBYTE sim_splock; /* Service provider lock */
271 UBYTE sim_plock; /* SIM lock */
272 UBYTE sim_nslock; /* Network SUBSET lock */
273 UBYTE sim_clock; /* corporate lock */
274 UBYTE sim_blocked; /* blocked flag */
275
276 static UBYTE sim_service_table [10]; /* SIM service table */
277 static UBYTE sim_stat = SIM_NOT_ACTIVE;
278
279 static int simCommand (ULONG cmd, void *h); /* handle win commands */
280
281 UBYTE pin1_set = MFW_SIM_UNKNOWN;
282 UBYTE pin2_set = MFW_SIM_ENABLE;
283
284 static BOOL sat_update = FALSE;
285
286 static int pSlot; /* primitive handler slot */
287
288 EXTERN MfwHdr * current_mfw_elem;
289 #if defined (WIN32)
290 /*
291 * Only for windows to check several SIM lock combinations
292 */
293 UBYTE sim_lock_mode = 0;
294 #endif
295 UBYTE sim_lock_field = NOT_PRESENT_8BIT; /* type of sim lock field */
296
297 static UBYTE sim_get_sim_lock (EF_SIMLCKEXT * simlck);
298 static void sim_set_sim_lock (EF_SIMLCKEXT * simlck);
299 static void sim_fill_sim_lock (EF_SIMLCKEXT * simlck);
300 static void sim_check_unblock_sim (EF_SIMLCKEXT * simlck);
301
302 #define SIMLOCK_DISABLED 0
303 #define SIMLOCK_ENABLED 1
304 #define SIMLOCK_LOCKED 2
305 #define SIMLOCK_BLOCKED 3
306
307 /*
308 +--------------------------------------------------------------------+
309 | PROJECT : MMI-Framework (8417) MODULE : MFW_SIM |
310 | STATE : code ROUTINE : sim_init |
311 +--------------------------------------------------------------------+
312
313 PURPOSE : initialize SIM manager
314
315 */
316
317 int sim_init (void)
318 {
319 EF_SIMLCKEXT simlck;
320
321 TRACE_FUNCTION("sim_init()");
322
323 /*
324 * initialise SIM lock flags
325 */
326 sim_nslock = sim_plock = sim_nlock = sim_clock = sim_splock = 0;
327 sim_blocked = FALSE;
328
329 /*
330 * Read SIM Lock Flags
331 */
332 if (sim_get_sim_lock (&simlck) EQ PCM_OK)
333 {
334 sim_plock = (UBYTE) FldGet(simlck.locks1,plock);
335 sim_nlock = (UBYTE) FldGet(simlck.locks1,nlock);
336 sim_nslock = (UBYTE) FldGet(simlck.locks1,nslock);
337 sim_splock = (UBYTE) FldGet(simlck.locks1,splock);
338 sim_clock = (UBYTE) FldGet(simlck.locks2,clock);
339
340 if (simlck.cnt >= simlck.maxcnt)
341 sim_blocked = TRUE;
342 else
343 sim_blocked = FALSE;
344 }
345
346 pin_flag = -1;
347 pin_ident = MFW_SIM_UNKNOWN;
348
349 /*
350 * install prim handler
351 */
352 pSlot = aci_create(sima_response_cb,NULL);
353 mfwCommand[MfwTypSim] = (MfwCb) simCommand;
354
355 return TRUE;
356 }
357
358
359 /*
360 +---------------------------------------------------------------------+
361 | PROJECT : MMI-Framework (8417) MODULE : MFW_SIM |
362 | STATE : code ROUTINE : sim_init_sim_insert |
363 +---------------------------------------------------------------------+
364
365 PURPOSE : initialize SIM manager
366
367 */
368
369 void sim_init_sim_insert()
370 {
371 }
372
373
374 /*
375 +--------------------------------------------------------------------+
376 | PROJECT : MMI-Framework (8417) MODULE : MFW_SIM |
377 | STATE : code ROUTINE : sim_exit |
378 +--------------------------------------------------------------------+
379
380 PURPOSE : finalize SIM manager
381
382 */
383
384 void sim_exit (void)
385 {
386 TRACE_FUNCTION("sim_exit()");
387
388 /*
389 * remove prim handler
390 */
391 aci_delete(pSlot);
392 sim_stat = SIM_NOT_ACTIVE;
393 }
394
395
396 /*
397 +--------------------------------------------------------------------+
398 | PROJECT : MMI-Framework (8417) MODULE : MFW_SIM |
399 | STATE : code ROUTINE : sim_create |
400 +--------------------------------------------------------------------+
401
402 PURPOSE : create SIM event handler
403
404 */
405
406 T_MFW_HND sim_create (MfwHnd hWin, MfwEvt event, MfwCb cbfunc)
407 {
408 MfwHdr *hdr;
409 T_MFW_SIM *sim_para;
410
411 TRACE_FUNCTION("sim_create()");
412
413 hdr = (MfwHdr *) mfwAlloc(sizeof(MfwHdr));
414 sim_para = (T_MFW_SIM *) mfwAlloc(sizeof(T_MFW_SIM));
415
416 if (!hdr || !sim_para)
417 return 0;
418
419 sim_para->emask = event;
420 sim_para->handler = cbfunc;
421
422 hdr->data = sim_para;
423 hdr->type = MfwTypSim;
424
425 return mfwInsert((MfwHdr *) hWin,hdr);
426 }
427
428
429 /*
430 +--------------------------------------------------------------------+
431 | PROJECT : MMI-Framework (8417) MODULE : MFW_SIM |
432 | STATE : code ROUTINE : sim_delete |
433 +--------------------------------------------------------------------+
434
435 PURPOSE : delete SIM event handler
436
437 */
438
439 MfwRes sim_delete (MfwHnd h)
440 {
441 TRACE_FUNCTION("sim_delete()");
442
443 if (!h || !((MfwHdr *) h)->data)
444 return MfwResIllHnd;
445
446 if (!mfwRemove((MfwHdr *) h))
447 return MfwResIllHnd;
448
449 mfwFree((U8 *) ((MfwHdr *) h)->data,sizeof(T_MFW_SIM));
450 mfwFree((U8 *) h,sizeof(MfwHdr));
451
452 return MfwResOk;
453 }
454
455
456 /*
457 +--------------------------------------------------------------------+
458 | PROJECT : MMI-Framework (8417) MODULE : MFW_SIM |
459 | STATE : code ROUTINE : sim_signal |
460 +--------------------------------------------------------------------+
461
462 PURPOSE : Send a signal
463
464 */
465
466 void sim_signal (MfwEvt event, void *para)
467 {
468 TRACE_FUNCTION ("sim_signal()");
469
470 if (mfwSignallingMethod EQ 0)
471 {
472 if (mfwFocus)
473 if (sim_sign_exec(mfwFocus,event,para))
474 return;
475 if (mfwRoot)
476 sim_sign_exec(mfwRoot,event,para);
477 }
478 else
479 {
480 MfwHdr * h = 0;
481
482 /*
483 * Focus set, then start here
484 */
485 if (mfwFocus)
486 h = mfwFocus;
487 /*
488 * Focus not set, then start root
489 */
490 if (!h)
491 h = mfwRoot;
492
493 /*
494 * No elements available, return
495 */
496
497 while (h)
498
499
500 {
501 /*
502 * Signal consumed, then return
503 */
504 if (sim_sign_exec (h, event, para))
505 return;
506
507 /*
508 * All windows tried inclusive root
509 */
510 if (h == mfwRoot)
511 return;
512
513 /*
514 * get parent window
515 */
516 h = mfwParent(mfwParent(h));
517 if(h)
518 h = ((MfwWin * )(h->data))->elems;
519 }
520 sim_sign_exec (mfwRoot, event, para);
521 }
522 }
523
524
525 /*
526 +--------------------------------------------------------------------+
527 | PROJECT : MMI-Framework (8417) MODULE : MFW_SIM |
528 | STATE : code ROUTINE : sim_sign_exec |
529 +--------------------------------------------------------------------+
530
531 PURPOSE : Send a signal if SIM management handler
532
533 */
534
535 int sim_sign_exec (MfwHdr *cur_elem, MfwEvt event, T_MFW_SIM_PARA *para)
536 {
537
538 TRACE_FUNCTION("sim_sign_exec()");
539
540 while (cur_elem)
541 {
542 if (cur_elem->type == MfwTypSim)
543 {
544 T_MFW_SIM *sim_data;
545 sim_data = (T_MFW_SIM *) cur_elem->data;
546 if (sim_data->emask & event)
547 {
548 sim_data->event = event;
549 switch (event)
550 {
551 case E_SIM_STATUS:
552 memcpy(&sim_data->para.status,
553 para,sizeof(T_MFW_SIM_STATUS));
554 break;
555 }
556 if (sim_data->handler)
557 {
558 // PATCH LE 06.06.00
559 // store current mfw elem
560 current_mfw_elem = cur_elem;
561 // END PATCH LE 06.06.00
562 if ((*(sim_data->handler))(sim_data->event,
563 (void *) &sim_data->para))
564 return TRUE;
565 }
566 }
567 }
568 cur_elem = cur_elem->next;
569 }
570
571 return FALSE;
572 }
573
574
575 /*
576 +--------------------------------------------------------------------+
577 | PROJECT : MMI-Framework (8417) MODULE : MFW_SIM |
578 | STATE : code ROUTINE : sim_activate |
579 +--------------------------------------------------------------------+
580
581 PURPOSE : Start SIM card activation
582
583 */
584
585 void sim_activate (void)
586 {
587 TRACE_FUNCTION("sim_activate()");
588
589 /*
590 * Full functionality is used don´t reset the ME
591 */
592 if (sAT_PlusCFUN(CMD_SRC_LCL,CFUN_FUN_Full,CFUN_RST_NotPresent)
593 NEQ AT_EXCT)
594 {
595 TRACE_ERROR("sAT_PlusCFUN error");
596 }
597 }
598
599
600 /*
601 +--------------------------------------------------------------------+
602 | PROJECT : MMI-Framework (8417) MODULE : MFW_SIM |
603 | STATE : code ROUTINE : sim_spn_req |
604 +--------------------------------------------------------------------+
605
606 PURPOSE : Request service provider name
607
608 */
609
610 void sim_spn_req (void)
611 {
612 T_EF_SPN spn;
613
614 TRACE_FUNCTION("sim_spn_req()");
615
616 memset(&spn,0,sizeof(T_EF_SPN));
617
618 if (sim_check_service(17,sim_service_table)
619 EQ ALLOCATED_AND_ACTIVATED)
620 sim_read_sim(SIM_SPN,17,17);
621 else
622 nm_spn_cnf(&spn);
623 }
624
625
626 /*
627 +--------------------------------------------------------------------+
628 | PROJECT : MMI-Framework (8417) MODULE : MFW_SIM |
629 | STATE : code ROUTINE : sim_ok_cfun |
630 +--------------------------------------------------------------------+
631
632 PURPOSE : Notify successful end of SIM card activation
633
634 */
635
636 void sim_ok_cfun (void)
637 {
638 T_ACI_CFUN_FUN fun;
639
640 TRACE_FUNCTION ("sim_ok_cfun()");
641
642 qAT_PlusCFUN( CMD_SRC_LCL, &fun );
643
644 if( fun EQ CFUN_FUN_Full )
645 {
646 sim_stat = SIM_ACTIVE;
647 sim_status.sim_status = MFW_SIM_NO_PIN;
648 sim_status.sim_operation_mode = sim_config.oper_mode;
649 sim_status.sim_pin_retries = 0;
650 sim_status.sim_procedure = MFW_SIM_ACTIVATION;
651 sim_status.sim_status_type = pin_ident;
652
653 pin_ident = MFW_SIM_UNKNOWN;
654 sim_signal(E_SIM_STATUS,&sim_status);
655 nm_activate(MFW_SIM_NO_PIN);
656
657 pin1_set = MFW_SIM_DISABLE;
658 }
659 else if( fun EQ CFUN_FUN_Minimum )
660 {
661 nm_ok_deregistration();
662 }
663 }
664
665
666 /*
667 +--------------------------------------------------------------------+
668 | PROJECT : MMI-Framework (8417) MODULE : MFW_SIM |
669 | STATE : code ROUTINE : sim_error_cfun |
670 +--------------------------------------------------------------------+
671
672 PURPOSE : Notify error status of SIM card
673
674 */
675
676 void sim_error_cfun (U8 result)
677 {
678 TRACE_FUNCTION("sim_error_cfun()");
679
680 sim_status.sim_procedure = MFW_SIM_ACTIVATION;
681 sim_status.sim_operation_mode = sim_config.oper_mode;
682
683 switch (result)
684 {
685 case CME_ERR_SimPinReq: /* PIN 1 must be entered */
686 sim_status.sim_status = MFW_SIM_PIN_REQ;
687 sim_status.sim_pin_retries = sim_pin_count(MFW_SIM_PIN1);
688 sim_status.sim_status_type = MFW_SIM_PIN1;
689 sim_stat = SIM_ACTIVE;
690 break;
691 case CME_ERR_SimPin2Req: /* PIN 2 must be entered */
692 sim_status.sim_status = MFW_SIM_PIN2_REQ;
693 sim_status.sim_pin_retries = sim_pin_count(MFW_SIM_PIN2);
694 sim_status.sim_status_type = MFW_SIM_PIN2;
695 sim_stat = SIM_ACTIVE;
696 break;
697 case CME_ERR_SimPukReq: /* PUK 1 must be entered */
698 sim_status.sim_status = MFW_SIM_PUK_REQ;
699 sim_status.sim_pin_retries = sim_pin_count(MFW_SIM_PUK1);
700 sim_status.sim_status_type = MFW_SIM_PUK1;
701 sim_stat = SIM_ACTIVE;
702 break;
703 case CME_ERR_SimPuk2Req: /* PUK 2 must be entered */
704 sim_status.sim_status = MFW_SIM_PUK2_REQ;
705 sim_status.sim_pin_retries = sim_pin_count(MFW_SIM_PUK2);
706 sim_status.sim_status_type = MFW_SIM_PUK2;
707 sim_stat = SIM_ACTIVE;
708 break;
709 case CME_ERR_SimFail: /* SIM card is invalid */
710 case CME_ERR_SimWrong:
711 sim_status.sim_status = MFW_SIM_INVALID_CARD;
712 sim_status.sim_pin_retries = 0;
713 sim_status.sim_status_type = MFW_SIM_UNKNOWN;
714 sim_stat = SIM_NOT_ACTIVE;
715 break;
716 case CME_ERR_SimNotIns: /* no SIM card inserted */
717 sim_status.sim_status = MFW_SIM_NO_SIM_CARD;
718 sim_status.sim_pin_retries = 0;
719 sim_status.sim_status_type = MFW_SIM_UNKNOWN;
720 sim_stat = SIM_NOT_ACTIVE;
721 break;
722 default:
723 TRACE_ERROR("sim_error_cfun(): result");
724 return;
725 }
726
727 sim_signal(E_SIM_STATUS,&sim_status);
728
729 if ((result == CME_ERR_SimPinReq)
730 OR (result == CME_ERR_SimPukReq))
731 pin1_set = MFW_SIM_ENABLE;
732 }
733
734
735 /*
736 +--------------------------------------------------------------------+
737 | PROJECT : MMI-Framework (8417) MODULE : MFW_SIM |
738 | STATE : code ROUTINE : sim_error_cpin |
739 +--------------------------------------------------------------------+
740
741 PURPOSE : Inform about error of PIN entering or PUK entering
742
743 */
744
745 void sim_error_cpin (T_ACI_CME_ERR reason)
746 {
747 T_ACI_CPIN_RSLT code;
748
749 TRACE_FUNCTION("sim_error_cpin()");
750
751 sim_status.sim_procedure = pin_flag;
752 sim_status.sim_operation_mode = sim_config.oper_mode;
753 sim_status.sim_status = MFW_SIM_FAILURE;
754 sim_status.sim_status_type = pin_ident;
755
756 pin_flag = -1;
757 pin_ident = MFW_SIM_UNKNOWN;
758
759 switch (reason)
760 {
761 case CME_ERR_WrongPasswd:
762 if (qAT_PlusCPIN(CMD_SRC_LCL,&code) != AT_CMPL)
763 {
764 TRACE_ERROR("sim_error_cpin():CPIN? failed");
765 sim_signal(E_SIM_STATUS,&sim_status);
766 return;
767 }
768 break;
769 case CME_ERR_SimWrong:
770 sim_status.sim_status = MFW_SIM_INVALID_CARD;
771 sim_signal(E_SIM_STATUS,&sim_status);
772 return;
773 default:
774 TRACE_ERROR("sim_error_cpin():Ill reason");
775 sim_signal(E_SIM_STATUS,&sim_status);
776 return;
777 }
778
779 switch (code)
780 {
781 case CPIN_RSLT_SimPinReq:
782 sim_status.sim_status = MFW_SIM_PIN_REQ;
783 sim_status.sim_pin_retries = sim_pin_count(MFW_SIM_PIN1);
784 break;
785 case CPIN_RSLT_SimPukReq:
786 sim_status.sim_status = MFW_SIM_PUK_REQ;
787 sim_status.sim_pin_retries = sim_pin_count(MFW_SIM_PUK1);
788 break;
789 case CPIN_RSLT_SimPin2Req:
790 sim_status.sim_status = MFW_SIM_PIN2_REQ;
791 sim_status.sim_pin_retries = sim_pin_count(MFW_SIM_PIN2);
792 break;
793 case CPIN_RSLT_SimPuk2Req:
794 sim_status.sim_status = MFW_SIM_PUK2_REQ;
795 sim_status.sim_pin_retries = sim_pin_count(MFW_SIM_PUK2);
796 break;
797 case CPIN_RSLT_NotPresent:
798 case CPIN_RSLT_SimReady:
799 default:
800 TRACE_ERROR("sim_error_cpin():Ill code");
801 break;
802 }
803
804 sim_signal(E_SIM_STATUS,&sim_status);
805 }
806
807
808 /*
809 +--------------------------------------------------------------------+
810 | PROJECT : MMI-Framework (8417) MODULE : MFW_SIM |
811 | STATE : code ROUTINE : sim_ok_cpin |
812 +--------------------------------------------------------------------+
813
814 PURPOSE : Successful end of PIN entering or PUK entering
815
816 */
817
818 void sim_ok_cpin (void)
819 {
820 TRACE_FUNCTION("sim_ok_cpin()");
821
822 switch (pin_flag)
823 {
824 case MFW_SIM_VERIFY:
825 sim_status.sim_procedure = MFW_SIM_VERIFY;
826 sim_status.sim_status = MFW_SIM_NO_PIN;
827 sim_status.sim_status_type = pin_ident;
828 break;
829 case MFW_SIM_UNBLOCK:
830 sim_status.sim_procedure = MFW_SIM_UNBLOCK;
831 sim_status.sim_status = MFW_SIM_SUCCESS;
832 sim_status.sim_status_type = pin_ident;
833 break;
834 default:
835 break;
836 }
837
838 pin_flag = -1;
839 pin_ident = MFW_SIM_UNKNOWN;
840 sim_status.sim_operation_mode = sim_config.oper_mode;
841 sim_status.sim_pin_retries = 0;
842
843 sim_signal (E_SIM_STATUS, &sim_status);
844 if (nm_reg_flag_req())
845 nm_activate(MFW_SIM_NO_PIN);
846 }
847
848
849 /*
850 +--------------------------------------------------------------------+
851 | PROJECT : MMI-Framework (8417) MODULE : MFW_SIM |
852 | STATE : code ROUTINE : sim_ss_unblock |
853 +--------------------------------------------------------------------+
854
855 PURPOSE : SIM unblock via SS string
856
857 */
858
859 void sim_ss_unblock(UBYTE result, T_ACI_CME_ERR reason)
860 {
861 TRACE_FUNCTION("sim_ss_unblock()");
862
863 pin_flag = MFW_SIM_UNBLOCK;
864
865 if (result == SIM_UBLK_ERROR)
866 sim_error_cpin (reason);
867 if (result == SIM_UBLK_OK)
868 sim_ok_cpin ();
869 }
870
871
872 /*
873 +--------------------------------------------------------------------+
874 | PROJECT : MMI-Framework (8417) MODULE : MFW_SIM |
875 | STATE : code ROUTINE : sim_verify_pin |
876 +--------------------------------------------------------------------+
877
878 PURPOSE : Verify PIN
879
880 */
881
882 void sim_verify_pin (U8 pin_id, char *pin)
883 {
884 TRACE_FUNCTION("sim_verify_pin()");
885
886 pin_flag = MFW_SIM_VERIFY;
887 pin_ident = pin_id;
888 switch (pin_id)
889 {
890 case MFW_SIM_PIN1:
891 sAT_PercentPVRF(CMD_SRC_LCL, PVRF_TYPE_Pin1, pin, 0);
892 break;
893 case MFW_SIM_PIN2:
894 sAT_PercentPVRF(CMD_SRC_LCL, PVRF_TYPE_Pin2, pin, 0);
895 break;
896 }
897 }
898
899
900 /*
901 +--------------------------------------------------------------------+
902 | PROJECT : MMI-Framework (8417) MODULE : MFW_SIM |
903 | STATE : code ROUTINE : sim_unblock_pin |
904 +--------------------------------------------------------------------+
905
906 PURPOSE : unblock SIM
907
908 */
909
910 void sim_unblock_pin (U8 pin_id, char *puk, char *newpin)
911 {
912 TRACE_FUNCTION("sim_unblock_pin()");
913
914 pin_flag = MFW_SIM_UNBLOCK;
915 pin_ident = pin_id;
916 switch (pin_id)
917 {
918 case MFW_SIM_PUK1:
919 sAT_PercentPVRF(CMD_SRC_LCL, PVRF_TYPE_Puk1, puk, newpin);
920 break;
921 case MFW_SIM_PUK2:
922 sAT_PercentPVRF(CMD_SRC_LCL, PVRF_TYPE_Puk2, puk, newpin);
923 break;
924 }
925 }
926
927
928 /*
929 +--------------------------------------------------------------------+
930 | PROJECT : MMI-Framework (8417) MODULE : MFW_SIM |
931 | STATE : code ROUTINE : sim_change_pin |
932 +--------------------------------------------------------------------+
933
934 PURPOSE : Request of PIN change
935
936 */
937
938 void sim_change_pin (U8 pin_id, U8 *old_pin, U8 *new_pin)
939 {
940 TRACE_FUNCTION("sim_change_pin()");
941
942 pin_ident = pin_id;
943 switch (pin_id)
944 {
945 case MFW_SIM_PIN1:
946 sAT_PlusCPWD(CMD_SRC_LCL, CPWD_FAC_Sc,
947 (char *)old_pin, (char *)new_pin);
948 break;
949 case MFW_SIM_PIN2:
950 sAT_PlusCPWD(CMD_SRC_LCL, CPWD_FAC_P2,
951 (char *)old_pin, (char *)new_pin);
952 break;
953 }
954 }
955
956
957 /*
958 +--------------------------------------------------------------------+
959 | PROJECT : MMI-Framework (8417) MODULE : MFW_SIM |
960 | STATE : code ROUTINE : sim_ok_cpinc |
961 +--------------------------------------------------------------------+
962
963 PURPOSE : Notify successful end of PIN change
964
965 */
966
967 void sim_ok_cpinc (void)
968 {
969 TRACE_FUNCTION("sim_ok_cpinc()");
970
971 sim_status.sim_procedure = MFW_SIM_CHANGE;
972 sim_status.sim_status = MFW_SIM_SUCCESS;
973 sim_status.sim_operation_mode = sim_config.oper_mode;
974 sim_status.sim_pin_retries = 0;
975 sim_status.sim_status_type = pin_ident;
976
977 pin_ident = MFW_SIM_UNKNOWN;
978 sim_signal(E_SIM_STATUS,&sim_status);
979 }
980
981
982 /*
983 +--------------------------------------------------------------------+
984 | PROJECT : MMI-Framework (8417) MODULE : MFW_SIM |
985 | STATE : code ROUTINE : sim_error_cpinc |
986 +--------------------------------------------------------------------+
987
988 PURPOSE : Notify failed PIN change
989
990 */
991
992 void sim_error_cpinc (void)
993 {
994 TRACE_FUNCTION("sim_error_cpinc()");
995
996 sim_status.sim_procedure = MFW_SIM_CHANGE;
997 sim_status.sim_status = MFW_SIM_FAILURE;
998 sim_status.sim_operation_mode = sim_config.oper_mode;
999 if (pin_ident EQ MFW_SIM_PIN1)
1000 sim_status.sim_pin_retries = sim_pin_count(MFW_SIM_PIN1);
1001 else if (pin_ident EQ MFW_SIM_PIN2)
1002 sim_status.sim_pin_retries = sim_pin_count(MFW_SIM_PIN2);
1003 else
1004 sim_status.sim_pin_retries = 0;
1005 sim_status.sim_status_type = pin_ident;
1006
1007 pin_ident = MFW_SIM_UNKNOWN;
1008 sim_signal(E_SIM_STATUS,&sim_status);
1009 }
1010
1011
1012 /*
1013 +--------------------------------------------------------------------+
1014 | PROJECT : MMI-Framework (8417) MODULE : MFW_SIM |
1015 | STATE : code ROUTINE : sim_disable_pin |
1016 +--------------------------------------------------------------------+
1017
1018 PURPOSE : Request PIN disability
1019
1020 */
1021
1022 void sim_disable_pin (U8 *pin)
1023 {
1024 TRACE_FUNCTION("sim_disable_pin()");
1025
1026 ss_set_clck(CLCK_FAC_Sc, CLCK_MOD_Unlock,
1027 (char *)pin, -1, MFW_SIM_CPIND);
1028 }
1029
1030
1031 /*
1032 +--------------------------------------------------------------------+
1033 | PROJECT : MMI-Framework (8417) MODULE : MFW_SIM |
1034 | STATE : code ROUTINE : sim_ok_cpind |
1035 +--------------------------------------------------------------------+
1036
1037 PURPOSE : Successful end of PIN disability
1038
1039 */
1040
1041 void sim_ok_cpind (void)
1042 {
1043 TRACE_FUNCTION("sim_ok_cpind()");
1044
1045 sim_status.sim_procedure = MFW_SIM_DISABLE;
1046 sim_status.sim_status = MFW_SIM_SUCCESS;
1047 sim_status.sim_operation_mode = sim_config.oper_mode;
1048 sim_status.sim_pin_retries = 0;
1049 sim_status.sim_status_type = MFW_SIM_UNKNOWN; // no indication
1050
1051 pin1_set = MFW_SIM_DISABLE;
1052 sim_signal(E_SIM_STATUS,&sim_status);
1053 }
1054
1055
1056 /*
1057 +--------------------------------------------------------------------+
1058 | PROJECT : MMI-Framework (8417) MODULE : MFW_SIM |
1059 | STATE : code ROUTINE : sim_error_cpind |
1060 +--------------------------------------------------------------------+
1061
1062 PURPOSE : Failed PIN disability
1063
1064 */
1065
1066 void sim_error_cpind (void)
1067 {
1068 TRACE_FUNCTION("sim_error_cpind()");
1069
1070 sim_status.sim_procedure = MFW_SIM_DISABLE;
1071 sim_status.sim_status = MFW_SIM_FAILURE;
1072 sim_status.sim_operation_mode = sim_config.oper_mode;
1073 sim_status.sim_pin_retries = sim_pin_count(MFW_SIM_PIN1);
1074 sim_status.sim_status_type = MFW_SIM_UNKNOWN; // no indication
1075
1076 sim_signal(E_SIM_STATUS,&sim_status);
1077 }
1078
1079
1080 /*
1081 +--------------------------------------------------------------------+
1082 | PROJECT : MMI-Framework (8417) MODULE : MFW_SIM |
1083 | STATE : code ROUTINE : sim_enable_pin |
1084 +--------------------------------------------------------------------+
1085
1086 PURPOSE : Request PIN enability
1087
1088 */
1089
1090 void sim_enable_pin (U8 *pin)
1091 {
1092 TRACE_FUNCTION("sim_enable_pin()");
1093
1094 ss_set_clck(CLCK_FAC_Sc, CLCK_MOD_Lock,
1095 (char *)pin, -1, MFW_SIM_CPINE);
1096 }
1097
1098
1099 /*
1100 +--------------------------------------------------------------------+
1101 | PROJECT : MMI-Framework (8417) MODULE : MFW_SIM |
1102 | STATE : code ROUTINE : sim_ok_cpine |
1103 +--------------------------------------------------------------------+
1104
1105 PURPOSE : Successful end of PIN enability
1106
1107 */
1108
1109 void sim_ok_cpine()
1110 {
1111 TRACE_FUNCTION("sim_ok_cpine()");
1112
1113 sim_status.sim_procedure = MFW_SIM_ENABLE;
1114 sim_status.sim_status = MFW_SIM_SUCCESS;
1115 sim_status.sim_operation_mode = sim_config.oper_mode;
1116 sim_status.sim_pin_retries = 0;
1117 sim_status.sim_status_type = MFW_SIM_UNKNOWN; // no indication
1118
1119 pin1_set = MFW_SIM_ENABLE;
1120 sim_signal(E_SIM_STATUS,&sim_status);
1121 }
1122
1123
1124 /*
1125 +--------------------------------------------------------------------+
1126 | PROJECT : MMI-Framework (8417) MODULE : MFW_SIM |
1127 | STATE : code ROUTINE : sim_error_cpine |
1128 +--------------------------------------------------------------------+
1129
1130 PURPOSE : Failed PIN enability
1131
1132 */
1133
1134 void sim_error_cpine (void)
1135 {
1136 TRACE_FUNCTION("sim_error_cpine()");
1137
1138 sim_status.sim_procedure = MFW_SIM_ENABLE;
1139 sim_status.sim_status = MFW_SIM_FAILURE;
1140 sim_status.sim_operation_mode = sim_config.oper_mode;
1141 sim_status.sim_pin_retries = sim_pin_count(MFW_SIM_PIN1);
1142 sim_status.sim_status_type = MFW_SIM_UNKNOWN; // no indication
1143
1144 sim_signal(E_SIM_STATUS,&sim_status);
1145 }
1146
1147
1148 /*
1149 +--------------------------------------------------------------------+
1150 | PROJECT : MMI-Framework (8417) MODULE : MFW_SIM |
1151 | STATE : code ROUTINE : sim_check_service |
1152 +--------------------------------------------------------------------+
1153
1154 PURPOSE : Checks a service status
1155
1156 */
1157
1158 U8 sim_check_service (U8 nr, U8 *serv_table)
1159 {
1160 U8 value;
1161
1162 TRACE_FUNCTION("sim_check_service()");
1163
1164 value = *(serv_table + (nr - 1) / 4);
1165 value >>= ((nr - 1) & 3) * 2;
1166
1167 return (value & 3);
1168 }
1169
1170
1171 /*
1172 +-----------------------------------------------------------------------+
1173 | PROJECT : MMI-Framework (8417) MODULE : MFW_SIM |
1174 | STATE : code ROUTINE : sim_serv_table_check |
1175 +-----------------------------------------------------------------------+
1176
1177 PURPOSE : Checks a service status in SIM service table
1178
1179 */
1180
1181 T_MFW sim_serv_table_check(UBYTE serv_num)
1182 {
1183 TRACE_FUNCTION("sim_serv_table_check()");
1184 return sim_check_service(serv_num, sim_service_table);
1185 }
1186
1187
1188 /*
1189 +--------------------------------------------------------------------+
1190 | PROJECT : MMI-Framework (8417) MODULE : MFW_SIM |
1191 | STATE : code ROUTINE : rAT_PlusCFUNP |
1192 +--------------------------------------------------------------------+
1193
1194 PURPOSE : MMI relevant parameters from the SIM card
1195
1196 */
1197
1198 void rAT_PlusCFUNP (T_SIM_MMI_INSERT_IND *mmi_insert_ind)
1199 {
1200 TRACE_FUNCTION("rAT_PlusCFUNP()");
1201
1202 sim_stat = SIM_ACTIVE;
1203
1204 sim_config.oper_mode = mmi_insert_ind->func;
1205 // sms_mmi_parameter(mmi_insert_ind->cbmid);
1206 nm_mmi_parameters(&mmi_insert_ind->imsi_field,
1207 &mmi_insert_ind->pref_plmn);
1208 memcpy(sim_service_table,mmi_insert_ind->sim_serv,
1209 sizeof(sim_service_table));
1210 //memcpy(sim_config.deper_key,mmi_insert_ind->deper_key,
1211 // sizeof(sim_config.deper_key));
1212 sim_config.phase = mmi_insert_ind->phase;
1213 sim_config.access_acm = mmi_insert_ind->access_acm;
1214 sim_config.access_acmmax = mmi_insert_ind->access_acmmax;
1215 sim_config.access_puct = mmi_insert_ind->access_puct;
1216
1217 // sim_init_sim_insert();
1218
1219 if (sim_check_service(15,sim_service_table)
1220 == ALLOCATED_AND_ACTIVATED)
1221 sim_read_sim(SIM_GID1, NOT_PRESENT_8BIT, 5);
1222 }
1223
1224
1225 /*
1226 +--------------------------------------------------------------------+
1227 | PROJECT : MMI-Framework (8417) MODULE : MFW_SIM |
1228 | STATE : code ROUTINE : sim_mmi_parameter |
1229 +--------------------------------------------------------------------+
1230
1231 PURPOSE : MMI relevant parameters from the SIM card
1232
1233 */
1234
1235 void sim_mmi_parameter(T_SIM_ACTIVATE_CNF *sim_act_cnf)
1236 {
1237 TRACE_FUNCTION("sim_mmi_parameter()");
1238
1239 memcpy( sim_config.pref_lang, sim_act_cnf->pref_lang, 5);
1240 }
1241
1242
1243 /*
1244 +--------------------------------------------------------------------+
1245 | PROJECT : MMI-Framework (8417) MODULE : MFW_SIM |
1246 | STATE : code ROUTINE : sim_gid1_cnf |
1247 +--------------------------------------------------------------------+
1248
1249 PURPOSE : read SIM group identifier 1 from SIM card
1250
1251 */
1252
1253 void sim_gid1_cnf(SHORT error, UBYTE *data)
1254 {
1255 TRACE_FUNCTION("sim_gid1_cnf()");
1256
1257 if (error EQ SIM_NO_ERROR)
1258 memcpy(sim_config.sim_gidl1, data, 5);
1259
1260 if (!sat_update)
1261 {
1262 if (sim_check_service(16,sim_service_table)
1263 == ALLOCATED_AND_ACTIVATED)
1264 sim_read_sim(SIM_GID2, NOT_PRESENT_8BIT, 5);
1265 }
1266 #ifdef SIM_TOOLKIT
1267 else
1268 {
1269 sat_update = FALSE;
1270 satUpdateFiles ( TRUE, SIM_GID1 );
1271 }
1272 #endif
1273 }
1274
1275
1276 /*
1277 +--------------------------------------------------------------------+
1278 | PROJECT : MMI-Framework (8417) MODULE : MFW_SIM |
1279 | STATE : code ROUTINE : sim_gid2_cnf |
1280 +--------------------------------------------------------------------+
1281
1282 PURPOSE : read SIM group identifier 2 from SIM card
1283
1284 */
1285
1286 void sim_gid2_cnf(SHORT error, UBYTE *data)
1287 {
1288 TRACE_FUNCTION("sim_gid2_cnf()");
1289 if (error EQ SIM_NO_ERROR)
1290 memcpy(sim_config.sim_gidl2, data, 5);
1291
1292 #ifdef SIM_TOOLKIT
1293 if ( sat_update )
1294 {
1295 sat_update = FALSE;
1296 satUpdateFiles ( TRUE, SIM_GID2 );
1297 }
1298 #endif
1299 }
1300
1301
1302 /*
1303 +--------------------------------------------------------------------+
1304 | PROJECT : MMI-Framework (8417) MODULE : MFW_SIM |
1305 | STATE : code ROUTINE : sim_save_pref_lang |
1306 +--------------------------------------------------------------------+
1307
1308 PURPOSE : save preferred language
1309
1310 */
1311
1312 void sim_save_pref_lang (UBYTE *lang, UBYTE len)
1313 {
1314 UBYTE sim_data[7];
1315 UBYTE i;
1316
1317 TRACE_FUNCTION("sim_save_pref_lang()");
1318
1319 //
1320 // copy a maximum of 5 bytes for storing on the SIM card
1321 //
1322 for (i=0;i<len AND i<5;i++)
1323 sim_data[i] = lang[i];
1324
1325 //
1326 // if less than 5 bytes fill with dummy values
1327 //
1328 for (i=len; i<5;i++)
1329 sim_data[i] = 0xFF;
1330
1331 //
1332 // write to the SIM card
1333 //
1334 sim_write_sim(SIM_LP, sim_data, 5);
1335 }
1336
1337
1338 /*
1339 +--------------------------------------------------------------------+
1340 | PROJECT : MMI-Framework (8417) MODULE : MFW_SIM |
1341 | STATE : code ROUTINE : rAT_PercentSIMREM |
1342 +--------------------------------------------------------------------+
1343
1344 PURPOSE : call back for SIM removed
1345
1346 */
1347
1348 void rAT_PercentSIMREM( T_ACI_SIMREM_TYPE srType )
1349 {
1350 TRACE_FUNCTION("rAT_PercentSIMREM()");
1351
1352 if ( srType EQ SIMREM_FAILURE )
1353 {
1354 sim_status.sim_procedure = MFW_SIM_REMOVED;
1355 sim_status.sim_status = MFW_SIM_NO_SIM_CARD;
1356 sim_status.sim_operation_mode = sim_config.oper_mode;
1357 sim_status.sim_pin_retries = 0;
1358 sim_status.sim_status_type = MFW_SIM_UNKNOWN;
1359 sim_stat = SIM_NOT_ACTIVE;
1360 sim_signal(E_SIM_STATUS,&sim_status);
1361 }
1362 else if ( srType EQ SIMREM_RESET )
1363 {
1364 #ifdef SIM_TOOLKIT
1365 sim_signal(E_SIM_RESET, 0);
1366 #endif
1367 }
1368 }
1369
1370
1371 /*
1372 +--------------------------------------------------------------------+
1373 | PROJECT : MMI-Framework (8417) MODULE : MFW_SIM |
1374 | STATE : code ROUTINE : rAT_percentSIMINS |
1375 +--------------------------------------------------------------------+
1376
1377 PURPOSE : call back for SIM inserted
1378
1379 */
1380
1381 void rAT_PercentSIMINS( T_ACI_CME_ERR err )
1382 {
1383 TRACE_FUNCTION("rAT_percentSIMINS()");
1384
1385 sim_signal(E_SIM_INSERTED, 0);
1386
1387 switch ( err )
1388 {
1389 case CME_ERR_SimPinReq:
1390 sim_status.sim_status = MFW_SIM_PIN_REQ;
1391 sim_status.sim_pin_retries = sim_pin_count(MFW_SIM_PIN1);
1392 sim_status.sim_status_type = MFW_SIM_PIN1;
1393 sim_stat = SIM_ACTIVE;
1394 sim_signal(E_SIM_STATUS, &sim_status);
1395 break;
1396
1397 case CME_ERR_SimPukReq:
1398 sim_status.sim_status = MFW_SIM_PUK_REQ;
1399 sim_status.sim_pin_retries = sim_pin_count(MFW_SIM_PUK1);
1400 sim_status.sim_status_type = MFW_SIM_PUK1;
1401 sim_stat = SIM_ACTIVE;
1402 sim_signal(E_SIM_STATUS, &sim_status);
1403 break;
1404
1405 default:
1406 break;
1407 }
1408 }
1409
1410
1411 /*
1412 +--------------------------------------------------------------------+
1413 | PROJECT : MMI-Framework (8417) MODULE : MFW_SIM |
1414 | STATE : code ROUTINE : sim_configuration |
1415 +--------------------------------------------------------------------+
1416
1417 PURPOSE : Request the configuration of SIM card
1418
1419 */
1420
1421 UBYTE sim_cvt_access_status(UBYTE acs)
1422 {
1423 TRACE_FUNCTION("sim_cvt_access_status()");
1424
1425 switch(acs)
1426 {
1427 case ACCESS_ALWAYS: return MFW_SIM_NO_PIN;
1428 case ACCESS_PIN_1: return MFW_SIM_PIN1;
1429 case ACCESS_PIN_2: return MFW_SIM_PIN2;
1430 default: return MFW_SIM_UNKNOWN;
1431 }
1432 }
1433
1434
1435 /*
1436 +--------------------------------------------------------------------+
1437 | PROJECT : MMI-Framework (8417) MODULE : MFW_SIM |
1438 | STATE : code ROUTINE : sim_configuration |
1439 +--------------------------------------------------------------------+
1440
1441 PURPOSE : Request the configuration of SIM card
1442
1443 */
1444
1445 MfwRes sim_configuration (U8 *phase, U8 *serv, U8 *slen,
1446 U8 *lang, U8 *llen,
1447 T_MFW_AOC_ACCESS *access)
1448 {
1449 U8 l;
1450 TRACE_FUNCTION("sim_configuration()");
1451
1452 //PATCH2 TB 1310: Add test of NULL parameter to avoid to declare parameter of unwanted data
1453 if (sim_stat != SIM_ACTIVE)
1454 return MFW_SIM_FAILURE;
1455
1456 if (phase != NULL)
1457 *phase = sim_config.phase;
1458
1459 if ((serv != NULL) && (slen != NULL))
1460 {
1461 l = sizeof(sim_service_table);
1462 if (l < *slen)
1463 *slen = l;
1464 memcpy(serv,sim_service_table,*slen);
1465 }
1466
1467 //PATCH1 TB 1310: replace slen by llen
1468 if ((lang != NULL) && (llen != NULL))
1469 {
1470 l = sizeof(sim_config.pref_lang);
1471 if (l < *llen)
1472 *llen = l;
1473 memcpy(lang, sim_config.pref_lang, *llen);
1474 }
1475 //END PATCH1 TB
1476
1477 if (access != NULL)
1478 {
1479 access->access_acm = sim_cvt_access_status(sim_config.access_acm);
1480 access->access_acmmax = sim_cvt_access_status(sim_config.access_acmmax);
1481 access->access_puct = sim_cvt_access_status(sim_config.access_puct);
1482 }
1483 //END PATCH2 TB
1484
1485 return MFW_SIM_SUCCESS;
1486 }
1487
1488
1489 /*
1490 +--------------------------------------------------------------------+
1491 | PROJECT : MMI-Framework (8417) MODULE : MFW_SIM |
1492 | STATE : code ROUTINE : sim_status_check |
1493 +--------------------------------------------------------------------+
1494
1495 PURPOSE : check activation of SIM card
1496
1497 */
1498
1499 int sim_status_check (void)
1500 {
1501 TRACE_FUNCTION("sim_status_check()");
1502
1503 return sim_stat;
1504 }
1505
1506
1507 /*
1508 +--------------------------------------------------------------------+
1509 | PROJECT : MMI-Framework (8417) MODULE : MFW_SIM |
1510 | STATE : code ROUTINE : sim_pin_count |
1511 +--------------------------------------------------------------------+
1512
1513 PURPOSE : Request PIN/PUK count
1514
1515 */
1516
1517 int sim_pin_count(U8 pin_id)
1518 {
1519 SHORT pn1Cnt;
1520 SHORT pn2Cnt;
1521 SHORT pk1Cnt;
1522 SHORT pk2Cnt;
1523 T_ACI_PVRF_STAT ps1;
1524 T_ACI_PVRF_STAT ps2;
1525
1526 TRACE_FUNCTION("sim_pin_count()");
1527
1528
1529 if (qAT_PercentPVRF(CMD_SRC_LCL, &pn1Cnt,
1530 &pn2Cnt, &pk1Cnt, &pk2Cnt, &ps1, &ps2) != AT_CMPL)
1531 return -1;
1532
1533 switch (pin_id)
1534 {
1535 case MFW_SIM_PIN1: return pn1Cnt;
1536 case MFW_SIM_PIN2: return pn2Cnt;
1537 case MFW_SIM_PUK1: return pk1Cnt;
1538 case MFW_SIM_PUK2: return pk2Cnt;
1539 default: return -1;
1540 }
1541 }
1542
1543
1544 /*
1545 +--------------------------------------------------------------------+
1546 | PROJECT : MMI-Framework (8417) MODULE : MFW_SIM |
1547 | STATE : code ROUTINE : simDecodeB2A |
1548 +--------------------------------------------------------------------+
1549
1550 PURPOSE : convert bcd to ASCII
1551
1552 */
1553
1554 void simDecodeB2A (U8 *ci, U8 li, U8 *di)
1555 {
1556 int i;
1557
1558 TRACE_FUNCTION("simDecodeB2A()");
1559
1560 for (i = 0; i < li * 2; i++)
1561 {
1562 di[i] = (i & 1) ? (ci[i/2] >> 4) + '0'
1563 : (ci[i/2] & 0x0f) + '0';
1564 if (di[i] > '9')
1565 {
1566 di[i] = 0;
1567 break;
1568 }
1569 }
1570 di[i] = 0;
1571 }
1572
1573
1574 /*
1575 +---------------------------------------------------------------------+
1576 | PROJECT : MMI-Framework (8417) MODULE : MFW_SIM |
1577 | STATE : code ROUTINE : sim_unlock_sim_lock |
1578 +---------------------------------------------------------------------+
1579
1580 PURPOSE : de-personalisation for SIM lock.
1581
1582 */
1583
1584 T_MFW sim_unlock_sim_lock(UBYTE type, UBYTE *passwd)
1585 {
1586 UBYTE eep_ckey [LONG_NAME]; // extracted version of PCM content
1587 EF_SIMLCKEXT simlck;
1588
1589 TRACE_FUNCTION("sim_unlock_sim_lock()");
1590
1591 /*
1592 * Read SIM LOCK Record from PCM
1593 */
1594 if (sim_get_sim_lock (&simlck) NEQ PCM_OK)
1595 {
1596 TRACE_ERROR("No SIMLCK");
1597 return MFW_SIM_UNLOCK_ERR;
1598 }
1599
1600 /*
1601 * check whether card is already blocked
1602 */
1603 if (simlck.cnt >= simlck.maxcnt)
1604 return MFW_SIM_BLOCKED;
1605
1606 switch (type)
1607 {
1608 /*
1609 * N-Lock
1610 */
1611 case MFW_SIM_NLOCK:
1612 /*
1613 * Extract Key from PCM record
1614 */
1615 simDecodeB2A (simlck.NKey, 8, eep_ckey);
1616 if (!strcmp((char *)eep_ckey, (char *)passwd))
1617 {
1618 /*
1619 * unblock password is okay
1620 */
1621 sim_nlock = SIMLOCK_ENABLED;
1622 simlck.locks1 = (UBYTE) FldSet(simlck.locks1,nlock,sim_nlock);
1623 simlck.cnt = 0;
1624 sim_set_sim_lock (&simlck);
1625
1626 return MFW_SIM_NLOCK;
1627 }
1628 break;
1629
1630 /*
1631 * SP-Lock
1632 */
1633 case MFW_SIM_SPLOCK:
1634 /*
1635 * Extract Key from PCM record
1636 */
1637 simDecodeB2A (simlck.SPKey, 8, eep_ckey);
1638 if (!strcmp((char *)eep_ckey, (char *)passwd))
1639 {
1640 /*
1641 * unblock password is okay
1642 */
1643 sim_splock = SIMLOCK_ENABLED;
1644 simlck.locks1 = (UBYTE) FldSet(simlck.locks1,splock,sim_splock);
1645 simlck.cnt = 0;
1646 sim_set_sim_lock (&simlck);
1647
1648 return MFW_SIM_SPLOCK;
1649 }
1650 break;
1651
1652 /*
1653 * NS-Lock
1654 */
1655 case MFW_SIM_NSLOCK:
1656 /*
1657 * Extract Key from PCM record
1658 */
1659 simDecodeB2A (simlck.NSKey, 8, eep_ckey);
1660 if (!strcmp((char *)eep_ckey, (char *)passwd))
1661 {
1662 /*
1663 * unblock password is okay
1664 */
1665 sim_nslock = SIMLOCK_ENABLED;
1666 simlck.locks1 = (UBYTE) FldSet(simlck.locks1,nslock,sim_nslock);
1667 simlck.cnt = 0;
1668 sim_set_sim_lock (&simlck);
1669
1670 return MFW_SIM_NSLOCK;
1671 }
1672 break;
1673
1674 /*
1675 * C-Lock
1676 */
1677 case MFW_SIM_CLOCK:
1678 /*
1679 * Extract Key from PCM record
1680 */
1681 simDecodeB2A (simlck.CKey, 8, eep_ckey);
1682 if (!strcmp((char *)eep_ckey, (char *)passwd))
1683 {
1684 /*
1685 * unblock password is okay
1686 */
1687 sim_clock = SIMLOCK_ENABLED;
1688 simlck.locks2 = (UBYTE) FldSet(simlck.locks2,clock,sim_clock);
1689 simlck.cnt = 0;
1690 sim_set_sim_lock (&simlck);
1691
1692 return MFW_SIM_CLOCK;
1693 }
1694 break;
1695
1696 /*
1697 * P-Lock
1698 */
1699 case MFW_SIM_PLOCK:
1700 /*
1701 * Extract Key from PCM record
1702 */
1703 simDecodeB2A (simlck.PKey, 8, eep_ckey);
1704 if (!strcmp((char *)eep_ckey, (char *)passwd))
1705 {
1706 /*
1707 * unblock password is correct
1708 */
1709 sim_plock = SIMLOCK_ENABLED;
1710 simlck.locks1 = (UBYTE) FldSet(simlck.locks1,plock,sim_plock);
1711 simlck.cnt = 0;
1712 sim_set_sim_lock (&simlck);
1713
1714 return MFW_SIM_PLOCK;
1715 }
1716 break;
1717
1718 default:
1719 return MFW_SIM_UNLOCK_ERR;
1720 }
1721
1722 /*
1723 * another failed attempt
1724 * increment counter, store in PCM and may change the status
1725 */
1726 simlck.cnt++;
1727 sim_set_sim_lock (&simlck);
1728
1729 if (simlck.cnt >= simlck.maxcnt)
1730 {
1731 sim_blocked = TRUE;
1732 return MFW_SIM_BLOCKED;
1733 }
1734 else
1735 return MFW_SIM_UNLOCK_ERR;
1736 }
1737
1738 /*
1739 +---------------------------------------------------------------------+
1740 | PROJECT : MMI-Framework (8417) MODULE : MFW_SIM |
1741 | STATE : code ROUTINE : sim_check_sim_Plock |
1742 +---------------------------------------------------------------------+
1743
1744 PURPOSE : check SIM lock
1745
1746 */
1747
1748 int sim_check_sim_Plock (void)
1749 {
1750 EF_SIMLCKEXT simlck;
1751 UBYTE i;
1752
1753 TRACE_FUNCTION ("sim_check_sim_Plock()");
1754
1755
1756 if (sim_blocked EQ TRUE OR
1757 sim_plock EQ SIMLOCK_BLOCKED)
1758 {
1759 /*
1760 * Try to reset unlock attempt counter
1761 */
1762 sim_check_unblock_sim (&simlck);
1763 return MFW_SIM_BLOCKED;
1764 }
1765
1766 /*
1767 * lock check disabled
1768 */
1769 if (sim_plock EQ SIMLOCK_DISABLED)
1770 return MFW_SIM_DISABLE;
1771
1772 /*
1773 * lock check blocked
1774 */
1775 if (sim_plock EQ SIMLOCK_LOCKED)
1776 return MFW_SIM_LOCKED;
1777
1778 /*
1779 * lock check enabled
1780 */
1781 if (sim_plock EQ SIMLOCK_ENABLED)
1782 {
1783 if (sim_get_sim_lock (&simlck) NEQ PCM_OK)
1784 {
1785 TRACE_ERROR("No SIMLCK");
1786 return MFW_SIM_FAILURE;
1787 }
1788
1789 /*
1790 * Check all digits
1791 */
1792 for (i=0; i<simlck.len_p_imsi; i++)
1793 {
1794 if (sim_check_imsi_digit(simlck.p_imsi[i], mfw_IMSI[i]) EQ FALSE)
1795 break;
1796 }
1797
1798 /*
1799 * all digits okay
1800 */
1801 if (i EQ simlck.len_p_imsi)
1802 return MFW_SIM_ENABLE;
1803
1804 /*
1805 * P-LOCK check failed
1806 */
1807
1808 sim_plock = SIMLOCK_LOCKED;
1809 simlck.locks1 = (UBYTE) FldSet(simlck.locks1,plock,sim_plock);
1810 sim_set_sim_lock (&simlck);
1811 return MFW_SIM_LOCKED;
1812 }
1813
1814 /*
1815 * shall not happen
1816 */
1817 return MFW_SIM_FAILURE;
1818 }
1819
1820
1821 /*
1822 +---------------------------------------------------------------------+
1823 | PROJECT : MMI-Framework (8417) MODULE : MFW_SIM |
1824 | STATE : code ROUTINE : sim_check_sim_Nlock |
1825 +---------------------------------------------------------------------+
1826
1827 PURPOSE : Check network lock
1828
1829 */
1830
1831 int sim_check_sim_Nlock (void)
1832 {
1833 EF_SIMLCKEXT simlck;
1834 UBYTE i;
1835
1836 TRACE_FUNCTION ("sim_check_sim_Nlock()");
1837
1838 if (sim_blocked EQ TRUE OR
1839 sim_nlock EQ SIMLOCK_BLOCKED)
1840 {
1841 /*
1842 * Try to reset unlock attempt counter
1843 */
1844 sim_check_unblock_sim (&simlck);
1845 return MFW_SIM_BLOCKED;
1846 }
1847
1848 /*
1849 * lock check disabled
1850 */
1851 if (sim_nlock EQ SIMLOCK_DISABLED)
1852 return MFW_SIM_DISABLE;
1853
1854 /*
1855 * lock check blocked
1856 */
1857 if (sim_nlock EQ SIMLOCK_LOCKED)
1858 return MFW_SIM_LOCKED;
1859
1860 /*
1861 * lock check enabled
1862 */
1863 if (sim_nlock EQ SIMLOCK_ENABLED)
1864 {
1865 if (sim_get_sim_lock (&simlck) NEQ PCM_OK)
1866 {
1867 TRACE_ERROR("No SIMLCK");
1868 return MFW_SIM_FAILURE;
1869 }
1870
1871 /*
1872 * check all digits
1873 */
1874 for (i=0; i<simlck.len_n_imsi; i++)
1875 {
1876 if (sim_check_imsi_digit(simlck.n_imsi[i], mfw_IMSI[i]) EQ FALSE)
1877 break;
1878 }
1879
1880 /*
1881 * all digits okay
1882 */
1883 if (i EQ simlck.len_n_imsi)
1884 return MFW_SIM_ENABLE;
1885
1886 /*
1887 * N-LOCK check failed
1888 */
1889 sim_nlock = SIMLOCK_LOCKED;
1890 simlck.locks1 = (U8) FldSet(simlck.locks1,nlock,sim_nlock);
1891 sim_set_sim_lock (&simlck);
1892 return MFW_SIM_LOCKED;
1893 }
1894 /*
1895 * shall not happen
1896 */
1897 return MFW_SIM_FAILURE;
1898 }
1899
1900
1901 /*
1902 +---------------------------------------------------------------------+
1903 | PROJECT : MMI-Framework (8417) MODULE : MFW_SIM |
1904 | STATE : code ROUTINE : sim_check_sim_SPlock|
1905 +---------------------------------------------------------------------+
1906
1907 PURPOSE : Check SIM service provider lock. It only works with SIMs
1908 which support GID1 file.
1909
1910 */
1911
1912 int sim_check_sim_SPlock (void)
1913 {
1914 EF_SIMLCKEXT simlck;
1915 UBYTE i;
1916
1917 TRACE_FUNCTION ("sim_check_sim_SPlock()");
1918
1919 /*
1920 * Only if Service 15 is activated and allocated
1921 */
1922 if (sim_check_service(15,sim_service_table) NEQ ALLOCATED_AND_ACTIVATED)
1923 return MFW_SIM_FAILURE;
1924
1925 if (sim_blocked EQ TRUE OR
1926 sim_splock EQ SIMLOCK_BLOCKED)
1927 {
1928 /*
1929 * Try to reset unlock attempt counter
1930 */
1931 sim_check_unblock_sim (&simlck);
1932 return MFW_SIM_BLOCKED;
1933 }
1934
1935 /*
1936 * lock check disabled
1937 */
1938 if (sim_splock EQ SIMLOCK_DISABLED)
1939 return MFW_SIM_DISABLE;
1940
1941 /*
1942 * lock check blocked
1943 */
1944 if (sim_splock EQ SIMLOCK_LOCKED)
1945 return MFW_SIM_LOCKED;
1946
1947 /*
1948 * lock check enabled
1949 */
1950 if (sim_splock EQ SIMLOCK_ENABLED)
1951 {
1952 if (sim_get_sim_lock (&simlck) NEQ PCM_OK)
1953 {
1954 TRACE_ERROR("No SIMLCK");
1955 return MFW_SIM_FAILURE;
1956 }
1957
1958 /*
1959 * check SP group identifier
1960 */
1961 if (memcmp(&simlck.gidl1, sim_config.sim_gidl1, 1))
1962 {
1963 sim_splock = SIMLOCK_LOCKED;
1964 simlck.locks1 = (UBYTE) FldSet(simlck.locks1,splock,sim_splock);
1965 sim_set_sim_lock (&simlck);
1966
1967 return MFW_SIM_LOCKED;
1968 }
1969
1970 /*
1971 * check all digits
1972 */
1973 for (i=0; i<simlck.len_sp_imsi; i++)
1974 {
1975 if (sim_check_imsi_digit(simlck.sp_imsi[i], mfw_IMSI[i]) EQ FALSE)
1976 break;
1977 }
1978
1979 /*
1980 * all digits okay
1981 */
1982 if (i EQ simlck.len_sp_imsi)
1983 return MFW_SIM_ENABLE;
1984
1985 /*
1986 * failed SP-Lock
1987 */
1988 sim_splock = SIMLOCK_LOCKED;
1989 simlck.locks1 = (UBYTE) FldSet(simlck.locks1,splock,sim_splock);
1990 sim_set_sim_lock (&simlck);
1991
1992 return MFW_SIM_LOCKED;
1993 }
1994 /*
1995 * shall not happen
1996 */
1997 return MFW_SIM_FAILURE;
1998 }
1999
2000
2001 /*
2002 +---------------------------------------------------------------------+
2003 | PROJECT : MMI-Framework (8417) MODULE : MFW_SIM |
2004 | STATE : code ROUTINE : sim_check_sim_NSlock|
2005 +---------------------------------------------------------------------+
2006
2007 PURPOSE : Check network subset lock
2008
2009 */
2010
2011 int sim_check_sim_NSlock (void)
2012 {
2013 EF_SIMLCKEXT simlck;
2014 UBYTE i;
2015
2016 TRACE_FUNCTION ("sim_check_sim_NSlock()");
2017
2018 if (sim_blocked EQ TRUE OR
2019 sim_nslock EQ SIMLOCK_BLOCKED)
2020 {
2021 /*
2022 * Try to reset unlock attempt counter
2023 */
2024 sim_check_unblock_sim (&simlck);
2025 return MFW_SIM_BLOCKED;
2026 }
2027
2028 /*
2029 * lock check disabled
2030 */
2031 if (sim_nslock EQ SIMLOCK_DISABLED)
2032 return MFW_SIM_DISABLE;
2033
2034 /*
2035 * lock check blocked
2036 */
2037 if (sim_nslock EQ SIMLOCK_LOCKED)
2038 return MFW_SIM_LOCKED;
2039
2040 /*
2041 * lock check enabled
2042 */
2043 if (sim_nslock EQ SIMLOCK_ENABLED)
2044 {
2045 if (sim_get_sim_lock (&simlck) NEQ PCM_OK)
2046 {
2047 TRACE_ERROR("No SIMLCK");
2048 return MFW_SIM_FAILURE;
2049 }
2050
2051 /*
2052 * check all digits
2053 */
2054 for (i=0; i<simlck.len_ns_imsi; i++)
2055 {
2056 if (sim_check_imsi_digit(simlck.ns_imsi[i], mfw_IMSI[i]) EQ FALSE)
2057 break;
2058 }
2059
2060 /*
2061 * all digits okay
2062 */
2063 if (i EQ simlck.len_ns_imsi)
2064 return MFW_SIM_ENABLE;
2065
2066 /*
2067 * Lock has failed
2068 */
2069 sim_nslock = SIMLOCK_LOCKED;
2070 simlck.locks1 = (UBYTE) FldSet(simlck.locks1,nslock,sim_nslock);
2071 sim_set_sim_lock (&simlck);
2072
2073 return MFW_SIM_LOCKED;
2074 }
2075
2076 /*
2077 * shall not happen
2078 */
2079 return MFW_SIM_FAILURE;
2080 }
2081
2082 /*
2083 +---------------------------------------------------------------------+
2084 | PROJECT : MMI-Framework (8417) MODULE : MFW_SIM |
2085 | STATE : code ROUTINE : sim_check_sim_Clock |
2086 +---------------------------------------------------------------------+
2087
2088 PURPOSE : Check corporate lock. It only works with SIMs
2089 which support GID1 and GID2 files.
2090
2091 */
2092
2093 int sim_check_sim_Clock (void)
2094 {
2095 EF_SIMLCKEXT simlck;
2096 UBYTE i;
2097
2098 TRACE_FUNCTION ("sim_check_sim_Clock()");
2099
2100 /*
2101 * check the SIM supports GID1 and GID2
2102 */
2103 if (sim_check_service(15,sim_service_table) NEQ ALLOCATED_AND_ACTIVATED)
2104 return MFW_SIM_FAILURE;
2105
2106 if (sim_check_service(16,sim_service_table) NEQ ALLOCATED_AND_ACTIVATED)
2107 return MFW_SIM_FAILURE;
2108
2109 if (sim_blocked EQ TRUE OR
2110 sim_clock EQ SIMLOCK_BLOCKED)
2111 {
2112 /*
2113 * Try to reset unlock attempt counter
2114 */
2115 sim_check_unblock_sim (&simlck);
2116 return MFW_SIM_BLOCKED;
2117 }
2118
2119 /*
2120 * lock check disabled
2121 */
2122 if (sim_clock EQ SIMLOCK_DISABLED)
2123 return MFW_SIM_DISABLE;
2124
2125 /*
2126 * lock check blocked
2127 */
2128 if (sim_clock EQ SIMLOCK_LOCKED)
2129 return MFW_SIM_LOCKED;
2130
2131 /*
2132 * lock check enabled
2133 */
2134 if (sim_clock EQ SIMLOCK_ENABLED)
2135 {
2136 if (sim_get_sim_lock (&simlck) NEQ PCM_OK)
2137 {
2138 TRACE_ERROR("No SIMLCK");
2139 return MFW_SIM_FAILURE;
2140 }
2141
2142 /*
2143 * check SP group identifier 1 and 2
2144 */
2145 if (simlck.gidl1 NEQ sim_config.sim_gidl1[0] OR
2146 simlck.gidl2 NEQ sim_config.sim_gidl2[0])
2147 {
2148 sim_clock = SIMLOCK_LOCKED;
2149 simlck.locks2 = (UBYTE) FldSet(simlck.locks2,clock,sim_clock);
2150 sim_set_sim_lock (&simlck);
2151 return MFW_SIM_LOCKED;
2152 }
2153
2154 /*
2155 * check all digits */
2156 for (i=0; i<simlck.len_c_imsi; i++)
2157 {
2158 if (sim_check_imsi_digit(simlck.c_imsi[i], mfw_IMSI[i]) EQ FALSE)
2159 break;
2160 }
2161
2162 /*
2163 * all digits okay
2164 */
2165 if (i EQ simlck.len_c_imsi)
2166 return MFW_SIM_ENABLE;
2167
2168 /*
2169 * C-Lock has failed
2170 */
2171 sim_clock = SIMLOCK_LOCKED;
2172 simlck.locks2 = (UBYTE) FldSet(simlck.locks2,clock,sim_clock);
2173 sim_set_sim_lock (&simlck);
2174
2175 return MFW_SIM_LOCKED;
2176 }
2177 return MFW_SIM_FAILURE;
2178 }
2179
2180 /*
2181 +-----------------------------------------------------------------------+
2182 | PROJECT : MMI-Framework (8417) MODULE : MFW_SIM |
2183 | STATE : code ROUTINE : sim_get_simlock_count |
2184 +-----------------------------------------------------------------------+
2185
2186 PURPOSE : Request the count of SIMLOCK
2187
2188 */
2189
2190 T_MFW sim_get_simlock_count(UBYTE *cnt)
2191 {
2192 EF_SIMLCKEXT simlck;
2193
2194 TRACE_FUNCTION("sim_get_simlock_count()");
2195
2196 if (sim_get_sim_lock (&simlck) NEQ PCM_OK)
2197 return MFW_SIM_FAILURE;
2198 else
2199 *cnt = simlck.cnt;
2200 return MFW_SIM_SUCCESS;
2201 }
2202
2203 /*
2204 +--------------------------------------------------------------------+
2205 | PROJECT : MMI-Framework (8417) MODULE : MFW_SIM |
2206 | STATE : code ROUTINE : sim_pin_status |
2207 +--------------------------------------------------------------------+
2208
2209 PURPOSE : Request PIN1/PIN2 status
2210
2211 */
2212
2213 void sim_pin_status(T_MFW_SIM_PIN_STATUS *status)
2214 {
2215 SHORT pn1Cnt;
2216 SHORT pn2Cnt;
2217 SHORT pk1Cnt;
2218 SHORT pk2Cnt;
2219 T_ACI_PVRF_STAT ps1;
2220 T_ACI_PVRF_STAT ps2;
2221
2222 TRACE_FUNCTION("sim_pin_status()");
2223
2224 status->stat = MFW_SIM_UNKNOWN;
2225 status->set = MFW_SIM_UNKNOWN;
2226 if (qAT_PercentPVRF(CMD_SRC_LCL, &pn1Cnt,
2227 &pn2Cnt, &pk1Cnt, &pk2Cnt, &ps1, &ps2) == AT_CMPL)
2228 {
2229 switch (status->type)
2230 {
2231 case MFW_SIM_PIN1:
2232 status->stat = sim_cvtPINstatus(ps1, MFW_SIM_PIN1);
2233 status->set = pin1_set;
2234 break;
2235 case MFW_SIM_PIN2:
2236 status->stat = sim_cvtPINstatus(ps2, MFW_SIM_PIN2);
2237 status->set = pin2_set;
2238 break;
2239 }
2240 }
2241 }
2242
2243
2244 /*
2245 +--------------------------------------------------------------------+
2246 | PROJECT : MMI-Framework (8417) MODULE : MFW_SIM |
2247 | STATE : code ROUTINE : sim_cvtPINstatus |
2248 +--------------------------------------------------------------------+
2249
2250 PURPOSE :
2251
2252 */
2253
2254 UBYTE sim_cvtPINstatus(T_ACI_PVRF_STAT ps, UBYTE type)
2255 {
2256 TRACE_FUNCTION("sim_cvtPINstatus()");
2257
2258 switch (ps)
2259 {
2260 case PVRF_STAT_NotRequired:
2261 return MFW_SIM_NO_PIN;
2262 case PVRF_STAT_Required:
2263 if (type EQ MFW_SIM_PIN1)
2264 return MFW_SIM_PIN_REQ;
2265 if (type EQ MFW_SIM_PIN2)
2266 return MFW_SIM_PIN2_REQ;
2267 return MFW_SIM_UNKNOWN;
2268 default:
2269 return MFW_SIM_UNKNOWN;
2270 }
2271 }
2272
2273
2274 /*
2275 +--------------------------------------------------------------------+
2276 | PROJECT : MMI-Framework (8417) MODULE : MFW_SIM |
2277 | STATE : code ROUTINE : simDecodeIMSI |
2278 +--------------------------------------------------------------------+
2279
2280 PURPOSE : convert imsi (packed bcd to ASCIIZ; ->11.11)
2281
2282 */
2283
2284 void simDecodeIMSI (UBYTE * imsi_field,
2285 UBYTE imsi_c_field,
2286 UBYTE * imsi_extracted)
2287 {
2288 UBYTE length;
2289 UBYTE i;
2290 UBYTE digit;
2291
2292 TRACE_FUNCTION ("simDecodeImsi()");
2293
2294 /*
2295 * calculate number of digits
2296 */
2297 length = (imsi_c_field-1)*2;
2298
2299 /*
2300 * if odd number of digits add one
2301 */
2302 if (imsi_field[0] & 0x08)
2303 length++;
2304
2305 /*
2306 * extract all digits
2307 */
2308 for (i = 0; i < length; i++)
2309 {
2310 digit = (i & 1) ?
2311 imsi_field[(i + 1) / 2] & 0x0f :
2312 (imsi_field[(i + 1) / 2] & 0xf0) >> 4;
2313
2314 #if defined (WIN32)
2315 {
2316 char buf[40];
2317 sprintf (buf, "DIGIT [%d] = %d",i, digit);
2318 TRACE_FUNCTION (buf);
2319 }
2320 #endif
2321 if (i < LONG_NAME)
2322 imsi_extracted [i] = digit + 0x30;
2323 else
2324 {
2325 imsi_extracted [i] = 0;
2326 return;
2327 }
2328 }
2329 }
2330
2331 /*
2332 +--------------------------------------------------------------------+
2333 | PROJECT : MMI-Framework (8417) MODULE : MFW_SIM |
2334 | STATE : code ROUTINE : sim_pin_ident |
2335 +--------------------------------------------------------------------+
2336
2337 PURPOSE : handle mfw windows command
2338
2339 */
2340
2341 void sim_pin_ident(UBYTE id)
2342 {
2343 TRACE_FUNCTION("sim_pin_ident()");
2344 pin_ident = id;
2345 }
2346
2347 /*
2348 +-----------------------------------------------------------------------+
2349 | PROJECT : MMI-Framework (8417) MODULE : MFW_SIM |
2350 | STATE : code ROUTINE : sim_check_imsi_digit |
2351 +-----------------------------------------------------------------------+
2352
2353 PURPOSE : Check a IMSI digit
2354
2355 */
2356
2357 T_MFW sim_check_imsi_digit(UBYTE pcm_imsi, UBYTE sim_imsi)
2358 {
2359 UBYTE h;
2360 UBYTE l;
2361
2362 TRACE_FUNCTION("sim_check_imsi_digit()");
2363
2364 h = pcm_imsi >> 4 | 0x30;
2365 l = pcm_imsi & 0x0F | 0x30;
2366
2367 #if defined (WIN32)
2368 {
2369 char buf[40];
2370 sprintf (buf, "check %c shall be in the range [%c..%c]",
2371 sim_imsi, h, l);
2372 TRACE_FUNCTION (buf);
2373 }
2374 #endif
2375
2376 if (h > l)
2377 return FALSE;
2378
2379 if ((sim_imsi < h) OR (sim_imsi > l))
2380 return FALSE;
2381
2382 return TRUE;
2383 }
2384
2385 /*
2386 +--------------------------------------------------------------------+
2387 | PROJECT : MMI-Framework (8417) MODULE : MFW_SIM |
2388 | STATE : code ROUTINE : simCommand |
2389 +--------------------------------------------------------------------+
2390
2391 PURPOSE : handle mfw windows command
2392
2393 */
2394
2395 static int simCommand (U32 cmd, void *h)
2396 {
2397 switch (cmd)
2398 {
2399 case MfwCmdDelete: /* delete me */
2400 if (!h)
2401 return 0;
2402 sim_delete(h);
2403 return 1;
2404 default:
2405 break;
2406 }
2407
2408 return 0;
2409 }
2410
2411
2412
2413 /*
2414 +--------------------------------------------------------------------+
2415 | PROJECT : MMI-Framework (8417) MODULE : MFW_SIM |
2416 | STATE : code ROUTINE : sim_get_sim_lock |
2417 +--------------------------------------------------------------------+
2418
2419 PURPOSE : Reads the SIM LOCK Record content from PCM
2420
2421 */
2422
2423 #if defined (WIN32)
2424 static const UBYTE sim_lock_table_1 [] =
2425 {
2426 //
2427 // all locks enabled, wrong IMSI
2428 //
2429 0x55, 0x01, // locks
2430 0x00, // unblock counter
2431 0x0F, // maximum attempt
2432 0x21, 0x43, 0x65, 0x87, // P control key
2433 0xFF, 0xFF, 0xFF, 0xFF,
2434 0x21, 0x43, 0x65, 0x87, // N control key
2435 0xFF, 0xFF, 0xFF, 0xFF,
2436 0x21, 0x43, 0x65, 0x87, // NS control key
2437 0xFF, 0xFF, 0xFF, 0xFF,
2438 0x21, 0x43, 0x65, 0x87, // SP control key
2439 0xFF, 0xFF, 0xFF, 0xFF,
2440 0x21, 0x43, 0x65, 0x87, // C control key
2441 0xFF, 0xFF, 0xFF, 0xFF,
2442 0x0F, // length of IMSI
2443 0x22, 0x00, 0x22, 0x01, // IMSI range definition
2444 0x23, 0x15, 0x22, 0x35,
2445 0x24, 0x25, 0x11, 0x22,
2446 0x46, 0x55, 0x66,
2447 0x00, 0x00 // Group Identifier
2448 };
2449
2450 static const UBYTE sim_lock_table_2 [] =
2451 {
2452 //
2453 // all locks enabled, IMSI ok
2454 //
2455 0x55, 0x01, // locks
2456 0x00, // unblock counter
2457 0x0F, // maximum attempt
2458 0x21, 0x43, 0x65, 0x87, // P control key
2459 0xFF, 0xFF, 0xFF, 0xFF,
2460 0x21, 0x43, 0x65, 0x87, // N control key
2461 0xFF, 0xFF, 0xFF, 0xFF,
2462 0x21, 0x43, 0x65, 0x87, // NS control key
2463 0xFF, 0xFF, 0xFF, 0xFF,
2464 0x21, 0x43, 0x65, 0x87, // SP control key
2465 0xFF, 0xFF, 0xFF, 0xFF,
2466 0x21, 0x43, 0x65, 0x87, // C control key
2467 0xFF, 0xFF, 0xFF, 0xFF,
2468 0x0D, // length of IMSI
2469 0x22, 0x66, 0x22, 0x00, // IMSI range definition
2470 0x11, 0x44, 0x77, 0x09,
2471 0x09, 0x09, 0x09, 0x09,
2472 0x09, 0x09, 0x09,
2473 0x00, 0x00 // Group Identifier
2474 };
2475
2476 static const UBYTE sim_lock_table_3 [] =
2477 {
2478 //
2479 // all locks enabled, wrong IMSI, extended format
2480 //
2481 0x55, 0x01, // locks
2482 0x00, // unblock counter
2483 0x0F, // maximum attempt
2484 0x21, 0x43, 0x65, 0x87, // P control key
2485 0xFF, 0xFF, 0xFF, 0xFF,
2486 0x21, 0x43, 0x65, 0x87, // N control key
2487 0xFF, 0xFF, 0xFF, 0xFF,
2488 0x21, 0x43, 0x65, 0x87, // NS control key
2489 0xFF, 0xFF, 0xFF, 0xFF,
2490 0x21, 0x43, 0x65, 0x87, // SP control key
2491 0xFF, 0xFF, 0xFF, 0xFF,
2492 0x21, 0x43, 0x65, 0x87, // C control key
2493 0xFF, 0xFF, 0xFF, 0xFF,
2494 0x0F, // length of IMSI P-Lock
2495 0x22, 0x00, 0x22, 0x01, // IMSI range definition P-Lock
2496 0x23, 0x15, 0x22, 0x35,
2497 0x24, 0x25, 0x11, 0x22,
2498 0x46, 0x55, 0x66,
2499 0x0F, // length of IMSI SP-Lock
2500 0x22, 0x00, 0x22, 0x01, // IMSI range definition SP-Lock
2501 0x23, 0x15, 0x22, 0x35,
2502 0x24, 0x25, 0x11, 0x22,
2503 0x46, 0x55, 0x66,
2504 0x0F, // length of IMSI NS-Lock
2505 0x22, 0x00, 0x22, 0x01, // IMSI range definition NS-Lock
2506 0x23, 0x15, 0x22, 0x35,
2507 0x24, 0x25, 0x11, 0x22,
2508 0x46, 0x55, 0x66,
2509 0x0F, // length of IMSI C-Lock
2510 0x22, 0x00, 0x22, 0x01, // IMSI range definition C-Lock
2511 0x23, 0x15, 0x22, 0x35,
2512 0x24, 0x25, 0x11, 0x22,
2513 0x46, 0x55, 0x66,
2514 0x0F, // length of IMSI N-Lock
2515 0x22, 0x00, 0x22, 0x01, // IMSI range definition N-Lock
2516 0x23, 0x15, 0x22, 0x35,
2517 0x24, 0x25, 0x11, 0x22,
2518 0x46, 0x55, 0x66,
2519 0x0F, // length of IMSI U-Lock
2520 0x22, 0x00, 0x22, 0x01, // IMSI range definition U-Lock
2521 0x23, 0x15, 0x22, 0x35,
2522 0x24, 0x25, 0x11, 0x22,
2523 0x46, 0x55, 0x66,
2524 0x00, 0x00 // Group Identifier
2525 };
2526
2527 static const UBYTE sim_lock_table_4 [] =
2528 {
2529 //
2530 // all locks enabled, IMSI ok, extended format
2531 //
2532 0x55, 0x01, // locks
2533 0x00, // unblock counter
2534 0x0F, // maximum attempt
2535 0x21, 0x43, 0x65, 0x87, // P control key
2536 0xFF, 0xFF, 0xFF, 0xFF,
2537 0x21, 0x43, 0x65, 0x87, // N control key
2538 0xFF, 0xFF, 0xFF, 0xFF,
2539 0x21, 0x43, 0x65, 0x87, // NS control key
2540 0xFF, 0xFF, 0xFF, 0xFF,
2541 0x21, 0x43, 0x65, 0x87, // SP control key
2542 0xFF, 0xFF, 0xFF, 0xFF,
2543 0x21, 0x43, 0x65, 0x87, // C control key
2544 0xFF, 0xFF, 0xFF, 0xFF,
2545 0x0D, // length of IMSI P-Lock
2546 0x22, 0x66, 0x22, 0x00, // IMSI range definition P-Lock
2547 0x11, 0x44, 0x77, 0x09,
2548 0x09, 0x09, 0x09, 0x09,
2549 0x09, 0x09, 0x09,
2550 0x0D, // length of IMSI SP-Lock
2551 0x22, 0x66, 0x22, 0x00, // IMSI range definition SP-Lock
2552 0x11, 0x44, 0x77, 0x09,
2553 0x09, 0x09, 0x09, 0x09,
2554 0x09, 0x09, 0x09,
2555 0x0D, // length of IMSI NS-Lock
2556 0x22, 0x66, 0x22, 0x00, // IMSI range definition NS-Lock
2557 0x11, 0x44, 0x77, 0x09,
2558 0x09, 0x09, 0x09, 0x09,
2559 0x09, 0x09, 0x09,
2560 0x0D, // length of IMSI C-Lock
2561 0x22, 0x66, 0x22, 0x00, // IMSI range definition C-Lock
2562 0x11, 0x44, 0x77, 0x09,
2563 0x09, 0x09, 0x09, 0x09,
2564 0x09, 0x09, 0x09,
2565 0x0D, // length of IMSI N-Lock
2566 0x22, 0x66, 0x22, 0x00, // IMSI range definition N-Lock
2567 0x11, 0x44, 0x77, 0x09,
2568 0x09, 0x09, 0x09, 0x09,
2569 0x09, 0x09, 0x09,
2570 0x0D, // length of IMSI U-Lock
2571 0x22, 0x66, 0x22, 0x00, // IMSI range definition U-Lock
2572 0x11, 0x44, 0x77, 0x09,
2573 0x09, 0x09, 0x09, 0x09,
2574 0x09, 0x09, 0x09,
2575 0x00, 0x00 // Group Identifier
2576 };
2577
2578 static const UBYTE sim_lock_table_5 [] =
2579 {
2580 //
2581 // one lock enabled, wrong IMSI ok
2582 //
2583 0x01, 0x00, // locks
2584 0x00, // unblock counter
2585 0x0F, // maximum attempt
2586 0x21, 0x43, 0x65, 0x87, // P control key
2587 0xFF, 0xFF, 0xFF, 0xFF,
2588 0x21, 0x43, 0x65, 0x87, // N control key
2589 0xFF, 0xFF, 0xFF, 0xFF,
2590 0x21, 0x43, 0x65, 0x87, // NS control key
2591 0xFF, 0xFF, 0xFF, 0xFF,
2592 0x21, 0x43, 0x65, 0x87, // SP control key
2593 0xFF, 0xFF, 0xFF, 0xFF,
2594 0x21, 0x43, 0x65, 0x87, // C control key
2595 0xFF, 0xFF, 0xFF, 0xFF,
2596 0x0D, // length of IMSI
2597 0x22, 0x00, 0x22, 0x00, // IMSI range definition
2598 0x11, 0x44, 0x77, 0x09,
2599 0x09, 0x09, 0x09, 0x09,
2600 0x09, 0x09, 0x09,
2601 0x00, 0x00 // Group Identifier
2602 };
2603
2604 #endif
2605
2606 static UBYTE sim_get_sim_lock (EF_SIMLCKEXT * simlck)
2607 {
2608 UBYTE version;
2609 UBYTE sim_lock_type = 0;
2610
2611 TRACE_FUNCTION("sim_get_sim_lock()");
2612
2613 #if defined (WIN32)
2614 version = 0;
2615
2616 switch (sim_lock_mode)
2617 {
2618 case 1:
2619 memcpy (simlck, sim_lock_table_1, SIZE_EF_SIMLCK);
2620 sim_lock_field = 1;
2621 sim_fill_sim_lock (simlck);
2622 break;
2623 case 2:
2624 memcpy (simlck, sim_lock_table_2, SIZE_EF_SIMLCK);
2625 sim_lock_field = 1;
2626 sim_fill_sim_lock (simlck);
2627 break;
2628 case 3:
2629 memcpy (simlck, sim_lock_table_3, SIZE_EF_SIMLCKEXT);
2630 sim_lock_field = 2;
2631 break;
2632 case 4:
2633 memcpy (simlck, sim_lock_table_4, SIZE_EF_SIMLCKEXT);
2634 sim_lock_field = 2;
2635 break;
2636 case 5:
2637 memcpy (simlck, sim_lock_table_5, SIZE_EF_SIMLCKEXT);
2638 sim_lock_field = 1;
2639 break;
2640 default:
2641 memset (simlck, 0, SIZE_EF_SIMLCKEXT);
2642 sim_lock_field = 2;
2643 break;
2644 }
2645 return PCM_OK;
2646 #else
2647
2648 if (sim_lock_field EQ NOT_PRESENT_8BIT)
2649 {
2650 if (pcm_ReadFile((UBYTE *) EF_SIMLCK_ID,
2651 SIZE_EF_SIMLCK,
2652 (UBYTE *) simlck,
2653 &version) EQ PCM_OK)
2654 {
2655 sim_lock_field = 1;
2656 sim_fill_sim_lock (simlck);
2657 return PCM_OK;
2658 }
2659 if (pcm_ReadFile((UBYTE *) EF_SIMLCKEXT_ID,
2660 SIZE_EF_SIMLCKEXT,
2661 (UBYTE *) simlck,
2662 &version) EQ PCM_OK)
2663 {
2664 sim_lock_field = 2;
2665 return PCM_OK;
2666 }
2667 return PCM_NVRAM_ACCS_FAIL;
2668 }
2669
2670 if (sim_lock_field EQ 1)
2671 {
2672 if (pcm_ReadFile((UBYTE *) EF_SIMLCK_ID,
2673 SIZE_EF_SIMLCK,
2674 (UBYTE *) simlck,
2675 &version) EQ PCM_OK)
2676 {
2677 sim_fill_sim_lock (simlck);
2678 return PCM_OK;
2679 }
2680 }
2681
2682 if (sim_lock_field EQ 2)
2683 {
2684 if (pcm_ReadFile((UBYTE *) EF_SIMLCKEXT_ID,
2685 SIZE_EF_SIMLCKEXT,
2686 (UBYTE *) simlck,
2687 &version) EQ PCM_OK)
2688 {
2689 return PCM_OK;
2690 }
2691 }
2692 return PCM_NVRAM_ACCS_FAIL;
2693 #endif
2694 }
2695
2696 /*
2697 +--------------------------------------------------------------------+
2698 | PROJECT : MMI-Framework (8417) MODULE : MFW_SIM |
2699 | STATE : code ROUTINE : sim_get_sim_lock |
2700 +--------------------------------------------------------------------+
2701
2702 PURPOSE : Reads the SIM LOCK Record content from PCM
2703
2704 */
2705
2706 static void sim_set_sim_lock (EF_SIMLCKEXT * simlck)
2707 {
2708 TRACE_FUNCTION("sim_set_sim_lock()");
2709
2710 if (sim_lock_field EQ 1)
2711 {
2712 /*
2713 * set GDL1 and 2 on the expected location
2714 * => len_sp_imsi = gdl1, sp_imsi[0] = gdl2
2715 */
2716 simlck->len_sp_imsi = simlck->gidl1;
2717 simlck->sp_imsi [0] = simlck->gidl2;
2718 pcm_WriteFile((UBYTE *) EF_SIMLCK_ID,SIZE_EF_SIMLCK,
2719 (UBYTE *) simlck);
2720 }
2721 else
2722 pcm_WriteFile((UBYTE *) EF_SIMLCKEXT_ID,SIZE_EF_SIMLCKEXT,
2723 (UBYTE *) simlck);
2724 }
2725
2726
2727 /*
2728 +--------------------------------------------------------------------+
2729 | PROJECT : MMI-Framework (8417) MODULE : MFW_SIM |
2730 | STATE : code ROUTINE : sim_fill_sim_lock |
2731 +--------------------------------------------------------------------+
2732
2733 PURPOSE : Fills the extended SIM Lock record with defaults if
2734 only the simple SIM Lock Record is available.
2735
2736 */
2737
2738 static void sim_fill_sim_lock (EF_SIMLCKEXT * simlck)
2739 {
2740 TRACE_FUNCTION("sim_fill_sim_lock()");
2741
2742 if (sim_lock_field EQ 1)
2743 {
2744 /*
2745 * PCM contains SIMLOCK record. Must be mapped to the internal
2746 * used SIMLOCKEXT record.
2747 *
2748 * gidl1, gidl2 to the end of record:
2749 */
2750 simlck->gidl1 = simlck->len_sp_imsi;
2751 simlck->gidl2 = simlck->sp_imsi [0];
2752 /*
2753 * IMSI must be copied for the other locks
2754 * N-Lock digits 1..5, rest filled with 0x09 to suppress compare
2755 * SP-Lock digits 1..5, rest filled with 0x09 to suppress compare
2756 * NS-Lock digits 1..7, rest filled with 0x09 to suppress compare
2757 * C-Lock digits 1..5, rest filled with 0x09 to suppress compare
2758 */
2759 memset (simlck->n_imsi, 0x09, 15);
2760 memcpy (simlck->n_imsi, simlck->p_imsi, 5);
2761 simlck->len_n_imsi = 5;
2762 memset (simlck->sp_imsi, 0x09, 15);
2763 memcpy (simlck->sp_imsi, simlck->p_imsi, 5);
2764 simlck->len_ns_imsi = 5;
2765 memset (simlck->ns_imsi, 0x09, 15);
2766 memcpy (simlck->ns_imsi, simlck->p_imsi, 7);
2767 simlck->len_ns_imsi = 7;
2768 memset (simlck->c_imsi, 0x09, 15);
2769 memcpy (simlck->c_imsi, simlck->p_imsi, 5);
2770 simlck->len_c_imsi = 5;
2771 /*
2772 * initialise unblock imsi so that it never will fit
2773 */
2774 simlck->len_u_imsi = 0;
2775 }
2776 }
2777
2778 /*
2779 +--------------------------------------------------------------------+
2780 | PROJECT : MMI-Framework (8417) MODULE : MFW_SIM |
2781 | STATE : code ROUTINE : sim_check_unblock_sim |
2782 +--------------------------------------------------------------------+
2783
2784 PURPOSE : Checks the IMSI against a stored unblock SIM. If the
2785 check is positive, the unlock attempt counter will
2786 be resetted.
2787
2788 */
2789
2790 static void sim_check_unblock_sim (EF_SIMLCKEXT * simlck)
2791 {
2792 UBYTE i;
2793
2794 TRACE_FUNCTION("sim_check_unblock_sim()");
2795
2796 if (sim_get_sim_lock (simlck) EQ PCM_OK)
2797 {
2798 if (simlck->len_u_imsi EQ 0)
2799 return;
2800
2801 /*
2802 * check all digits */
2803 for (i=0; i<simlck->len_u_imsi; i++)
2804 {
2805 if (sim_check_imsi_digit(simlck->u_imsi[i], mfw_IMSI[i]) EQ FALSE)
2806 break;
2807 }
2808
2809 /*
2810 * all digits okay, then reset counter and nothing else
2811 */
2812 if (i EQ simlck->len_u_imsi)
2813 {
2814 simlck->cnt = 0;
2815 sim_set_sim_lock (simlck);
2816 }
2817 }
2818 }
2819
2820 /*
2821 +--------------------------------------------------------------------+
2822 | PROJECT : MMI-Framework (8417) MODULE : MFW_SIM |
2823 | STATE : code ROUTINE : sim_simlock_ok |
2824 +--------------------------------------------------------------------+
2825
2826 PURPOSE : The function checks whether the SIM LOCK is active or not.
2827
2828 */
2829
2830 UBYTE sim_simlock_ok (void)
2831 {
2832 if (sim_nslock EQ SIMLOCK_BLOCKED OR
2833 sim_nslock EQ SIMLOCK_LOCKED)
2834 return FALSE;
2835
2836 if (sim_plock EQ SIMLOCK_BLOCKED OR
2837 sim_plock EQ SIMLOCK_LOCKED)
2838 return FALSE;
2839
2840 if (sim_splock EQ SIMLOCK_BLOCKED OR
2841 sim_splock EQ SIMLOCK_LOCKED)
2842 return FALSE;
2843
2844 if (sim_nlock EQ SIMLOCK_BLOCKED OR
2845 sim_nlock EQ SIMLOCK_LOCKED)
2846 return FALSE;
2847
2848 if (sim_clock EQ SIMLOCK_BLOCKED OR
2849 sim_clock EQ SIMLOCK_LOCKED)
2850 return FALSE;
2851
2852 return TRUE;
2853 }
2854
2855 /*
2856 +--------------------------------------------------------------------+
2857 | PROJECT : MMI-Framework (8417) MODULE : MFW_SIM |
2858 | STATE : code ROUTINE : sim_get_imsi |
2859 +--------------------------------------------------------------------+
2860
2861 PURPOSE : Request IMSI number in SIM card
2862
2863 */
2864
2865 UBYTE * sim_get_imsi (void)
2866 {
2867 return mfw_IMSI;
2868 }
2869
2870 /*
2871 +---------------------------------------------------------------------+
2872 | PROJECT : MMI-Framework (8417) MODULE : MFW_SIM |
2873 | STATE : code ROUTINE : sim_mmi_update_parameter |
2874 +---------------------------------------------------------------------+
2875
2876 PURPOSE : MMI relevant parameters from the SIM card
2877
2878 */
2879
2880 void sim_mmi_update_parameter(T_SIM_ACTIVATE_IND *sim_act_ind)
2881 {
2882 TRACE_FUNCTION("sim_mmi_update_parameter()");
2883
2884 memcpy( sim_config.pref_lang, sim_act_ind->pref_lang, 5);
2885 }
2886
2887 #ifdef SIM_TOOLKIT
2888 /*
2889 +---------------------------------------------------------------------+
2890 | PROJECT : MMI-Framework (8417) MODULE : MFW_SIM |
2891 | STATE : code ROUTINE : sim_sat_file_update |
2892 +---------------------------------------------------------------------+
2893
2894 PURPOSE : SIM file change indication
2895
2896 */
2897
2898 void sim_sat_file_update(USHORT dataId)
2899 {
2900 TRACE_FUNCTION("sim_sat_file_update()");
2901
2902 sat_update = TRUE;
2903 switch (dataId)
2904 {
2905 case SIM_SST:
2906 sim_read_sim(SIM_SST, NOT_PRESENT_8BIT, 10);
2907 break;
2908 case SIM_GID1:
2909 sim_read_sim(SIM_GID1, NOT_PRESENT_8BIT, 5);
2910 break;
2911 case SIM_GID2:
2912 sim_read_sim(SIM_GID2, NOT_PRESENT_8BIT, 5);
2913 break;
2914 default:
2915 break;
2916 }
2917 }
2918 #endif
2919
2920 /*
2921 +---------------------------------------------------------------------+
2922 | PROJECT : MMI-Framework (8417) MODULE : MFW_SIM |
2923 | STATE : code ROUTINE : sim_read_sst_cnf |
2924 +---------------------------------------------------------------------+
2925
2926 PURPOSE : SIM file change indication
2927
2928 */
2929
2930 void sim_read_sst_cnf (SHORT error, UBYTE *data)
2931 {
2932 TRACE_FUNCTION("sim_read_sst_cnf()");
2933
2934 if (error EQ SIM_NO_ERROR)
2935 memcpy(sim_service_table, data, sizeof(sim_service_table));
2936 else
2937 TRACE_EVENT("SST read error");
2938
2939 #ifdef SIM_TOOLKIT
2940 if (sat_update)
2941 {
2942 sat_update = FALSE;
2943 satUpdateFiles ( TRUE, SIM_SST );
2944 }
2945 #endif
2946 }