comparison g23m-aci/aci_ext/aci_ext_pers.c @ 0:75a11d740a02

initial import of gsm-fw from freecalypso-sw rev 1033:5ab737ac3ad7
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 09 Jun 2016 00:02:41 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:75a11d740a02
1 /*
2 +-----------------------------------------------------------------------------
3 | Project :
4 | Modul : J:\g23m-aci\aci_ext\aci_ext_pers.c
5 +-----------------------------------------------------------------------------
6 | Copyright 2002 Texas Instruments Berlin, AG
7 | All rights reserved.
8 |
9 | This file is confidential and a trade secret of Texas
10 | Instruments Berlin, AG
11 | The receipt of or possession of this file does not convey
12 | any rights to reproduce or disclose its contents or to
13 | manufacture, use, or sell anything it may describe, in
14 | whole, or in part, without the specific written consent of
15 | Texas Instruments Berlin, AG.
16 +-----------------------------------------------------------------------------
17 | Purpose :
18 +-----------------------------------------------------------------------------
19 */
20
21 #include "config.h"
22 #include "fixedconf.h"
23 #include "condat-features.h"
24 #include "aci_conf.h"
25
26 #include "aci_all.h"
27
28 #include "aci_cmh.h"
29 #include "ati_cmd.h"
30 #include "aci_cmd.h"
31
32 #ifdef FAX_AND_DATA
33 #include "aci_fd.h"
34 #endif /* of #ifdef FAX_AND_DATA */
35
36 #ifndef WIN32
37 #define ACI_PERSONALISTION_USE_FFS
38 #endif
39
40 #include "aci.h"
41 #include "psa.h"
42 #include "psa_sim.h"
43 #include "psa_sms.h"
44 #include "psa_mmi.h"
45 #include "cmh.h"
46 #include "phb.h"
47 #include "aoc.h"
48
49 #include "psa_sim.h" /* simShrdPrm */
50
51 #include "aci_ext_pers.h"
52 #include "aci_slock.h"
53
54 #ifdef SIM_PERS
55 #include "general.h" /* inluded for UINT8 compilation error in sec_drv.h */
56 #include "sec_drv.h"
57 #endif
58
59 #include "pcm.h" /* EF_SIMLCKEXT */
60
61 #ifdef MMI_SIMLOCK_TEST
62 #define ACI_PERSONALISTION_USE_FFS
63 #endif
64
65 #ifdef ACI_PERSONALISTION_USE_FFS
66 #include "../../services/ffs/ffs.h"
67 #include "ffs_coat.h"
68 #endif /* ACI_PERSONALISTION_USE_FFS */
69
70
71
72 #define SLOCK_PCM_NRM 1 /* SIM lock data is stored as SIMLOCK to the PCM */
73 #define SLOCK_PCM_EXT 2 /* SIM lock data is stored as SIMLOCKEXT to the PCM */
74
75 #ifdef SIM_PERS
76 #define TRUNCATION_KEY_LEN 8 /* */
77 #endif
78
79 #ifdef _SIMULATION_
80 EF_SIMLCKEXT simlock_pcm_memory; /* emulates the PCM memory in WIN32 environment. */
81 #endif
82
83 #include "aci_ext_pers_cus.h" /* the customer specific personalisation data. */
84
85
86 #ifdef FF_PHONE_LOCK
87 T_OPER_RET_STATUS aci_ext_set_phone_lock_satus(T_SEC_DRV_EXT_PHONE_LOCK_TYPE type,T_SEC_DRV_EXT_PHONE_LOCK_STATUS status,const char *passwd);
88 T_OPER_RET_STATUS aci_ext_get_phone_lock_satus(T_SEC_DRV_EXT_PHONE_LOCK_TYPE type,T_SEC_DRV_EXT_PHONE_LOCK_STATUS *status);
89 T_OPER_RET_STATUS aci_ext_set_phone_lock_key(const char *pOldKey,const char *pNewKey);
90 #endif
91 LOCAL void aci_ext_personalisation_MMI_save( void );
92
93 /*lint -esym(528,pre_firstsimpersonalisation ) pre_firstsimpersonalisation not referenced */
94 static BOOL pre_firstsimpersonalisation = FALSE; /* this will be set when a FIRST_SIM_LOCK is applied. All further locks
95 will not be applied but only prepare the lock for the next power-cycle */
96 LOCAL void decodeB2A (U8 *bcd, U8 bcd_len, U8 *ascii); /* decode a BCD to ASCII */
97 LOCAL void encodeA2B (char *ascii, UBYTE *bcd, UBYTE bcd_len); /* encode ASCII to BCD, fill up with 0xf */
98 #ifdef SIM_PERS
99 EXTERN T_SEC_DRV_CONFIGURATION *cfg_data ;
100 EXTERN T_ACI_SIM_CONFIG aci_slock_sim_config; /* SIM configuration, initialised by a T_SIM_MMI_INSERT_IND */
101 #endif
102
103
104
105
106 /*
107 +------------------------------------------------------------------------------
108 | Function : aci_ext_personalisation_init
109 +------------------------------------------------------------------------------
110 | Description : Initialisation of this extension. Might be used to initialise variables, set temporary data to default values and so on.
111 This method will be called once before any other public method of this extension.
112 |
113 | Parameters : void
114 |
115 | Return : void
116 |
117 +------------------------------------------------------------------------------
118 */
119
120
121 void aci_ext_personalisation_init( void )
122 {
123 #ifdef SIM_PERS
124 T_SIMLOCK_TYPE lock_type;
125 T_SEC_DRV_RETURN status ;
126 #endif
127
128 TRACE_FUNCTION("aci_ext_personalisation_init()");
129
130 #ifndef MMI_SIMLOCK_TEST
131
132 #ifdef SIM_PERS
133 for (lock_type=SIMLOCK_NETWORK;lock_type< SIMLOCK_LAST ;lock_type++) /*prateek: changed loop till simlock_first_sim */
134 {
135 switch (lock_type)
136 {
137 case SIMLOCK_NETWORK:
138 status =sec_get_REC (lock_type, &personalisation_nw);
139 if (status NEQ SEC_DRV_RET_Ok)
140 personalisation_nw = NULL;
141 else
142 {
143 AciSLockShrd.status[lock_type]=(T_SIMLOCK_STATUS)personalisation_nw->Header.Status;
144 AciSLockShrd.dependency[lock_type]=personalisation_nw->Header.Dependency;
145 }
146 break;
147
148 case SIMLOCK_NETWORK_SUBSET:
149 status =sec_get_REC (lock_type, &personalisation_ns);
150 if (status NEQ SEC_DRV_RET_Ok)
151 personalisation_ns= NULL;
152 else
153 {
154 AciSLockShrd.status[lock_type]=(T_SIMLOCK_STATUS)personalisation_ns->Header.Status;
155 AciSLockShrd.dependency[lock_type]=personalisation_ns->Header.Dependency;
156 }
157 break;
158
159 case SIMLOCK_SERVICE_PROVIDER:
160 status =sec_get_REC (lock_type, &personalisation_sp);
161 if (status NEQ SEC_DRV_RET_Ok)
162 personalisation_sp= NULL;
163 else
164 {
165 AciSLockShrd.status[lock_type]=(T_SIMLOCK_STATUS)personalisation_sp->Header.Status;
166 AciSLockShrd.dependency[lock_type]=personalisation_sp->Header.Dependency;
167 }
168 break;
169
170 case SIMLOCK_CORPORATE:
171 status =sec_get_REC (lock_type, &personalisation_cp);
172 if (status NEQ SEC_DRV_RET_Ok)
173 personalisation_cp = NULL;
174 else
175 {
176 AciSLockShrd.status[lock_type]=(T_SIMLOCK_STATUS)personalisation_cp->Header.Status;
177 AciSLockShrd.dependency[lock_type]=personalisation_cp->Header.Dependency;
178 }
179 break;
180
181 case SIMLOCK_SIM:
182 status =sec_get_REC (lock_type, &personalisation_sim);
183 if (status NEQ SEC_DRV_RET_Ok)
184 personalisation_sim = NULL;
185 else
186 {
187 AciSLockShrd.status[lock_type]=(T_SIMLOCK_STATUS)personalisation_sim->Header.Status;
188 AciSLockShrd.dependency[lock_type]=personalisation_sim->Header.Dependency;
189 }
190 break;
191
192 case SIMLOCK_BLOCKED_NETWORK:
193 status =sec_get_REC (lock_type, &personalisation_bnw);
194 if (status NEQ SEC_DRV_RET_Ok)
195 personalisation_bnw = NULL;
196 else
197 {
198 AciSLockShrd.status[lock_type]=(T_SIMLOCK_STATUS)personalisation_bnw->Header.Status;
199 AciSLockShrd.dependency[lock_type]=personalisation_bnw->Header.Dependency;
200 }
201 break;
202
203 case SIMLOCK_FIRST_SIM:
204 status =sec_get_REC (lock_type, &personalisation_first_sim);
205 if (status NEQ SEC_DRV_RET_Ok)
206 {
207 TRACE_FUNCTION("personalisation_first_sim = NULL");
208 personalisation_first_sim = NULL;
209 }
210 else
211 {
212 AciSLockShrd.status[lock_type]=(T_SIMLOCK_STATUS)personalisation_first_sim->Header.Status;
213 AciSLockShrd.dependency[lock_type]=personalisation_first_sim->Header.Dependency;
214 }
215 break;
216 }
217 }
218 #endif /*SIM_PERS */
219
220 #else /*for mmi testing, just read FFS MMI_SIMLOCK_TEST */
221
222 #endif /*MMI_SIMLOCK_TEST */
223 }
224
225 #ifdef SIM_PERS
226
227 /*
228 +------------------------------------------------------------------------------
229 | Function : aci_ext_personalisation_free
230 +------------------------------------------------------------------------------
231 | Description : Free the MEPD structure Memory
232 |
233 | Parameters : void
234 |
235 | Return : void
236 |
237 +------------------------------------------------------------------------------
238 */
239 void aci_ext_personalisation_free( void )
240 {
241 T_SIMLOCK_TYPE lock_type;
242
243 for (lock_type=SIMLOCK_NETWORK;lock_type<SIMLOCK_LAST;lock_type++)
244 {
245 switch (lock_type)
246 {
247 case SIMLOCK_NETWORK:
248 if(personalisation_nw NEQ NULL)
249 {
250 if(personalisation_nw->pBody NEQ NULL)
251 {
252 MFREE(personalisation_nw->pBody);
253 }
254 MFREE(personalisation_nw);
255 }
256 break;
257
258 case SIMLOCK_NETWORK_SUBSET:
259 if(personalisation_ns NEQ NULL)
260 {
261 if(personalisation_ns->pBody NEQ NULL)
262 {
263 MFREE(personalisation_ns->pBody);
264 }
265 MFREE(personalisation_ns);
266 }
267 break ;
268
269 case SIMLOCK_SERVICE_PROVIDER:
270 if(personalisation_sp NEQ NULL)
271 {
272 if(personalisation_sp->pBody NEQ NULL)
273 {
274 MFREE(personalisation_sp->pBody);
275 }
276 MFREE(personalisation_sp);
277 }
278 break ;
279
280 case SIMLOCK_CORPORATE:
281 if(personalisation_cp NEQ NULL)
282 {
283 if(personalisation_cp->pBody NEQ NULL)
284 {
285 MFREE(personalisation_cp->pBody);
286 }
287 MFREE(personalisation_cp);
288 }
289 break ;
290
291 case SIMLOCK_SIM:
292 if(personalisation_sim NEQ NULL)
293 {
294 if(personalisation_sim->pBody NEQ NULL)
295 {
296 MFREE(personalisation_sim->pBody);
297 }
298 MFREE(personalisation_sim);
299 }
300 break ;
301 case SIMLOCK_BLOCKED_NETWORK:
302 if(personalisation_bnw NEQ NULL)
303 {
304 if(personalisation_bnw->pBody NEQ NULL)
305 {
306 MFREE(personalisation_bnw->pBody);
307 }
308 MFREE(personalisation_bnw);
309 }
310 break;
311 case SIMLOCK_FIRST_SIM:
312 if(personalisation_first_sim NEQ NULL)
313 {
314 MFREE(personalisation_first_sim);
315 }
316 break;
317 }
318 }
319 }
320
321
322
323 /*
324 ACI extension method for retrieving the status of a single personalisation type.
325 The personalisation status is stored in a separate customer managed memory area
326 and the customer has to implement this extension method to return the actual status
327 of the questioned personalisation type.
328 */
329 T_SIMLOCK_STATUS aci_ext_personalisation_get_status( T_SIMLOCK_TYPE personalisation_type )
330 {
331 TRACE_FUNCTION("aci_ext_personalisation_get_status()");
332 #ifdef SIM_PERS
333 switch (personalisation_type)
334 {
335 case SIMLOCK_FIRST_SIM: /* should not occour */
336 case SIMLOCK_SIM:
337 if(personalisation_sim NEQ NULL)
338 return (T_SIMLOCK_STATUS)personalisation_sim->Header.Status;
339 else
340 return SIMLOCK_FAIL;
341
342 case SIMLOCK_NETWORK:
343 if(personalisation_nw NEQ NULL)
344 return (T_SIMLOCK_STATUS)personalisation_nw->Header.Status;
345 else
346 return SIMLOCK_FAIL;
347
348 case SIMLOCK_NETWORK_SUBSET:
349 if(personalisation_ns NEQ NULL)
350 return (T_SIMLOCK_STATUS)personalisation_ns->Header.Status;
351 else
352 return SIMLOCK_FAIL;
353
354 case SIMLOCK_SERVICE_PROVIDER:
355 if(personalisation_sp NEQ NULL)
356 return (T_SIMLOCK_STATUS)personalisation_sp->Header.Status;
357 else
358 return SIMLOCK_FAIL;
359
360 case SIMLOCK_CORPORATE:
361 if(personalisation_cp NEQ NULL)
362 return (T_SIMLOCK_STATUS)personalisation_cp->Header.Status;
363 else
364 return SIMLOCK_FAIL;
365
366 case SIMLOCK_BLOCKED_NETWORK:
367 if(personalisation_bnw NEQ NULL)
368 return (T_SIMLOCK_STATUS)personalisation_bnw->Header.Status;
369 else
370 return SIMLOCK_FAIL;
371
372
373 default: return SIMLOCK_FAIL; /* should not occour */
374 }
375 #endif
376 }
377
378
379 /*
380 +------------------------------------------------------------------------------
381 | Function : aci_ext_personalisation_verify_password
382 +------------------------------------------------------------------------------
383 | Description : ACI extension method for verifying the passowrd.
384 |f the password is false then the counter is increased. If maxcnt is reached then the key
385 |will been blocked. If the password is correct then the counter is set to 0
386 |
387 | Parameters : personalisation_type - category type (Network,Network subset, Service Provider,Corporate,SIM actegory)
388 | : passwd - category password
389 |
390 | Return : T_SIMLOCK_STATUS - Return SIMLOCK_DISABLED if compare key pass.
391 | - Return SIMLOCK_FAIL if compare key fails.
392 | - Return SIMLOCK_BLOCKED if FC counter is greater than
393 | FC Max.
394 +------------------------------------------------------------------------------
395 */
396
397
398 T_SIMLOCK_STATUS aci_ext_personalisation_verify_password( T_SIMLOCK_TYPE personalisation_type, char *passwd)
399 {
400
401 T_SEC_DRV_RETURN ret;
402 UINT8 key_len = 0; /* For truncation check -Samir */
403
404
405 TRACE_FUNCTION("aci_ext_personalisation_verify_password()");
406
407 if(cfg_data->Flags & SEC_DRV_HDR_FLAG_Truncation)
408 {
409 key_len = TRUNCATION_KEY_LEN;
410 }
411 ret = sec_cmp_KEY(personalisation_type, passwd, key_len) ;
412
413 switch (ret)
414 {
415 case SEC_DRV_RET_Ok :
416 return SIMLOCK_DISABLED;
417 /* part of code is returning before break ,so break is not required */
418 case SEC_DRV_RET_KeyWrong :
419 case SEC_DRV_RET_KeyMismatch:
420 /*Increment failure counter since input password is wrong*/
421 ret = sec_FC_Increment();
422 return SIMLOCK_FAIL;
423
424 /* part of code is returning before break ,so break is not required */
425 default:/*ERROR!- invalid input to sec_cmp_key OR some error in sec_cmp_key*/
426 return SIMLOCK_FAIL;
427 }
428 }
429
430
431 /*
432 +------------------------------------------------------------------------------
433 | Function : aci_ext_personalisation_change_password
434 +------------------------------------------------------------------------------
435 | Description : ACI extension method for verifying the passowrd.
436 |f the password is false then the counter is increased. If maxcnt is reached then the key
437 |will been blocked. If the password is correct then the counter is set to 0
438 |
439 | Parameters : personalisation_type - category type (Network,Network subset, Service Provider,Corporate,SIM actegory)
440 | : passwd - category password
441 | : new_passwd - New Password
442
443 | Return : T_SIMLOCK_STATUS - Return OPER_SUCCESS if changes password is successfull.
444 | - Return OPER_FAIL if changes password is fail.
445 |
446 +------------------------------------------------------------------------------
447 */
448
449 T_OPER_RET_STATUS aci_ext_personalisation_change_password( T_SIMLOCK_TYPE personalisation_type, char *passwd, char *new_passwd )
450 {
451 T_SEC_DRV_RETURN retstat;
452
453 retstat = sec_set_KEY (personalisation_type, passwd, new_passwd, 0);
454 switch(retstat)
455 {
456 case SEC_DRV_RET_Ok :
457 return OPER_SUCCESS;
458 case SEC_DRV_RET_FCExeeded :
459 AciSLockShrd.blocked = TRUE;
460 return OPER_BLOCKED ;
461 default :
462 return OPER_FAIL;
463 }
464
465 }
466
467
468 /*
469 +------------------------------------------------------------------------------
470 | Function : aci_ext_personalisation_set_status
471 +------------------------------------------------------------------------------
472 | Description : ACI extension method for lock/unlock the category record
473 |
474 | Parameters : personalisation_type - category type (Network,Network subset, Service Provider,Corporate,SIM actegory)
475 | : lock - SIMLOCK_ENABLED to lock the category
476 | - SIMLOCK_DISABLED to unlock the category
477 | : passwd - category lock/unlock password
478 |
479 |
480 | Return : T_SIMLOCK_STATUS - Return SIMLOCK_ENABLED if lock is successfull.
481 | - Return SIMLOCK_DISABLED if unlock is successfull.
482 | - Return SIMLOCK_FAIL if lock or unlock fails
483 | - Return SIMLOCK_BLOCKED if FC exeeded for wrong password
484 | - Return SIMLOCK_FAIL if lock/unlock fail
485 +------------------------------------------------------------------------------
486 */
487
488 T_SIMLOCK_STATUS aci_ext_personalisation_set_status( T_SIMLOCK_TYPE personalisation_type,
489 T_SIMLOCK_STATUS lock, char* passwd)
490 {
491
492 /* #ifdef SIM_PERS */
493 int rec_num = personalisation_type;
494 int key_len = 0;
495 T_SEC_DRV_RETURN ret;
496
497 TRACE_FUNCTION("aci_ext_personalisation_set_status()");
498
499 if(lock EQ SIMLOCK_ENABLED)
500 {
501 ret=sec_rec_Lock(rec_num, passwd, key_len,0xffff/*depend mask*/);/*aci_ext_personalisation_verify_password(personalisation_type, passwd);*/
502 if (ret EQ SEC_DRV_RET_Ok){
503 return SIMLOCK_ENABLED;
504 }
505 else{
506 return SIMLOCK_FAIL;
507 }
508 }
509
510 if(lock EQ SIMLOCK_DISABLED)
511 {
512 if(cfg_data->Flags & SEC_DRV_HDR_FLAG_Truncation)
513 {
514 key_len = TRUNCATION_KEY_LEN;
515 }
516 ret = sec_rec_Unlock(rec_num,TEMPORARY_UNLOCK,passwd,key_len,0xffff/*depend mask*/);
517
518 switch(ret)
519 {
520 case SEC_DRV_RET_Ok :
521 return SIMLOCK_DISABLED;
522 case SEC_DRV_RET_FCExceeded :
523 return SIMLOCK_BLOCKED;
524 case SEC_DRV_RET_KeyMismatch :
525 case SEC_DRV_RET_KeyWrong :
526 case SEC_DRV_RET_NotPresent :
527 case SEC_DRV_RET_Unknown :
528 return SIMLOCK_FAIL;
529 }
530 }
531 return SIMLOCK_FAIL;
532 /*#endif */
533 }
534
535
536
537
538 /*#ifdef SIM_PERS */
539
540 /*
541 +------------------------------------------------------------------------------
542 | Function : aci_ext_slock_reset_fc
543 +------------------------------------------------------------------------------
544 | Description : For Failure Counter reset. Uses Security Drv. method to reset FC
545 |
546 | Parameters : fckey - Password for resetting FC counter
547 |
548 |
549 | Return : T_OPER_RET_STATUS - Return OPER_SUCCESS if FC reset is successfull.
550 | - Return OPER_FAIL if FC reset is fail
551 |
552 +------------------------------------------------------------------------------
553 */
554
555
556 T_OPER_RET_STATUS aci_ext_slock_reset_fc(char *fckey)
557 {
558 T_SEC_DRV_RETURN retstat;
559 TRACE_FUNCTION("aci_ext_slock_reset_fc ()");
560
561 retstat= sec_FC_Reset(fckey,0);
562
563 switch(retstat)
564 {
565 case SEC_DRV_RET_Ok :
566 return OPER_SUCCESS;
567 case SEC_DRV_RET_FCExceeded:
568 case SEC_DRV_RET_KeyWrong:
569 case SEC_DRV_RET_KeyMismatch:
570 return OPER_WRONG_PASSWORD;
571 default :
572 return OPER_FAIL;
573 }
574
575 }
576
577
578
579 /*
580 +------------------------------------------------------------------------------
581 | Function : aci_ext_slock_sup_info
582 +------------------------------------------------------------------------------
583 | Description : For Supplementary Info( e.g. FC MAX, FC Current value).
584 |
585 | Parameters : sup_info -which has the element info type and Data value.
586 |
587 |
588 | Return : T_OPER_RET_STATUS - Return OPER_SUCCESS if successfully read the Info type data
589 | value from security driver. Info type data value is filled in this
590 | Function
591 | - Return OPER_FAIL if unable to read Info type data value from
592 | security driverl
593 |
594 +------------------------------------------------------------------------------
595 */
596
597
598 T_OPER_RET_STATUS aci_ext_slock_sup_info (T_SUP_INFO *sup_info)
599 {
600 T_SEC_DRV_CONFIGURATION *cfg_data;
601
602 TRACE_FUNCTION("aci_ext_slock_sup_info ()");
603 if ((sec_get_CFG(&cfg_data)) NEQ SEC_DRV_RET_Ok)
604 return OPER_FAIL;
605 else
606 {
607 switch(sup_info->infoType )
608 {
609 case(FCMAX ): sup_info->datavalue = cfg_data->FC_Max; break;
610 case(FCATTEMPTSLEFT): sup_info->datavalue = ((cfg_data->FC_Max) - (cfg_data->FC_Current)); break;
611 case(FCRESETFAILMAX ): sup_info->datavalue = cfg_data->FC_Reset_Fail_Max ; break;
612 case(FCRESETFAILATTEMPTSLEFT): sup_info->datavalue = ((cfg_data->FC_Reset_Fail_Max) - (cfg_data->FC_Reset_Fail_Current)); break;
613 case(FCRESETSUCCESSMAX ): sup_info->datavalue = cfg_data->FC_Reset_Success_Max ; break;
614 case(FCRESETSUCCESSATTEMPTSLEFT): sup_info->datavalue = ((cfg_data->FC_Reset_Success_Max) - (cfg_data->FC_Reset_Success_Current)); break;
615 case (TIMERFLAG): sup_info->datavalue =(cfg_data->Flags & SEC_DRV_HDR_FLAG_Unlock_Timer)?(1):(0) ;break;
616 case (ETSIFLAG) : sup_info->datavalue =(cfg_data->Flags & SEC_DRV_HDR_FLAG_ETSI_Flag)?(1):(0) ; break;
617 case (AIRTELINDFLAG) : sup_info->datavalue =(cfg_data->Flags & SEC_DRV_HDR_FLAG_Airtel_Ind)?(1):(0) ; break;
618 } /*end of switch*/
619
620 MFREE(cfg_data);/* deallocate configuration data allocated from Security Driver; */
621 return OPER_SUCCESS;
622 }
623 }
624
625
626 /*
627 +------------------------------------------------------------------------------
628 | Function : aci_ext_auto_personalise
629 +------------------------------------------------------------------------------
630 | Description : It Auto personalise the sim. If Add new IMSI flag set and If Code is not present
631 | then adds the code in the MEPD data and lock the category ( Network, Sub Network,
632 | sim )
633 | Parameters : void
634 |
635 |
636 | Return : void
637 |
638 +------------------------------------------------------------------------------
639 */
640
641 T_AUTOLOCK_STATUS aci_ext_auto_personalise(T_SIMLOCK_TYPE current_lock)
642 {
643 UBYTE imsi_sim[MAX_IMSI_LEN+1];
644 T_SIMLOCK_TYPE type;
645 static UINT16 flag = 0xffff;
646 UINT16 dependMask = 0xffff;
647
648 TRACE_FUNCTION("aci_ext_auto_personalise()");
649
650 psaSIM_decodeIMSI(simShrdPrm.imsi.field, simShrdPrm.imsi.c_field, (char *)imsi_sim);
651
652 if((AciSLockShrd.dependency[SIMLOCK_FIRST_SIM] & NW_AUTO_LOCK)AND (flag & NW_AUTO_LOCK))
653 {
654 type = SIMLOCK_NETWORK;
655 sim_code_present_in_me = FALSE;
656 aci_slock_check_NWlock(imsi_sim,1);
657 flag &= ~(NW_AUTO_LOCK);
658
659 if(sim_code_present_in_me EQ FALSE)
660 {
661 aci_ext_add_code(type);
662 }
663 }
664
665 if((AciSLockShrd.dependency[SIMLOCK_FIRST_SIM] & NS_AUTO_LOCK)AND (flag & NS_AUTO_LOCK))
666 {
667 type = SIMLOCK_NETWORK_SUBSET;
668 flag &= ~(NS_AUTO_LOCK);
669 sim_code_present_in_me = FALSE;
670 aci_slock_check_NSlock(imsi_sim,1);
671 if(sim_code_present_in_me EQ FALSE)
672 {
673 aci_ext_add_code(type);
674 }
675 }
676
677 if((AciSLockShrd.dependency[SIMLOCK_FIRST_SIM] & SIM_AUTO_LOCK ) AND (flag & SIM_AUTO_LOCK))
678 {
679 flag &= ~(SIM_AUTO_LOCK);
680 type = SIMLOCK_SIM;
681 sim_code_present_in_me = FALSE;
682 aci_slock_check_SMlock(imsi_sim,1);
683 if(sim_code_present_in_me EQ FALSE)
684 {
685 aci_ext_add_code(type);
686 }
687 }
688
689 if((AciSLockShrd.dependency[SIMLOCK_FIRST_SIM] & SP_AUTO_LOCK) AND (flag & SP_AUTO_LOCK))
690 {
691 if (psaSIM_ChkSIMSrvSup(SRV_GrpLvl1))
692 {
693 if(aci_slock_sim_config.sim_read_gid1 EQ FALSE)
694 {
695 aci_slock_sim_read_sim(SIM_GID1, NOT_PRESENT_8BIT, MAX_GID);
696 return AUTOLOCK_EXCT ;
697 }
698 else
699 {
700 type = SIMLOCK_SERVICE_PROVIDER;
701 sim_code_present_in_me = FALSE;
702 aci_slock_check_SPlock(imsi_sim,1);
703 TRACE_FUNCTION_P1("SP sim_code_present_in_me = %d", sim_code_present_in_me);
704 switch(sim_code_present_in_me)
705 {
706 case FALSE :
707 aci_ext_add_code(type);
708 break;
709 case CHECK_FAIL :
710 dependMask &= ~(SP_AUTO_LOCK) ;
711 break;
712 case TRUE :
713 break;
714 }
715 flag &= ~(SP_AUTO_LOCK);
716
717 }
718 }
719 else
720 {
721 flag &= ~(SP_AUTO_LOCK);
722 dependMask &= ~(SP_AUTO_LOCK) ;
723 }
724 }
725
726
727 if((AciSLockShrd.dependency[SIMLOCK_FIRST_SIM] & CP_AUTO_LOCK)AND (flag & CP_AUTO_LOCK))
728 {
729
730 if (psaSIM_ChkSIMSrvSup(SRV_GrpLvl1))
731 {
732 if(aci_slock_sim_config.sim_read_gid1 EQ FALSE)
733 {
734 aci_slock_sim_read_sim(SIM_GID1, NOT_PRESENT_8BIT, MAX_GID);
735 return AUTOLOCK_EXCT ;
736 }
737 }
738
739 if (psaSIM_ChkSIMSrvSup(SRV_GrpLvl2))
740 {
741 if(aci_slock_sim_config.sim_read_gid2 EQ FALSE)
742 {
743 aci_slock_sim_read_sim(SIM_GID2, NOT_PRESENT_8BIT, MAX_GID);
744 return AUTOLOCK_EXCT ;
745 }
746 }
747
748 if(psaSIM_ChkSIMSrvSup(SRV_GrpLvl1) AND psaSIM_ChkSIMSrvSup(SRV_GrpLvl2))
749 {
750 type = SIMLOCK_CORPORATE;
751 sim_code_present_in_me = FALSE;
752 aci_slock_check_CPlock(imsi_sim,1);
753 switch(sim_code_present_in_me)
754 {
755 case FALSE :
756 aci_ext_add_code(type);
757 break;
758 case CHECK_FAIL :
759 dependMask &= ~(CP_AUTO_LOCK) ;
760 break;
761 case TRUE :
762 break;
763 }
764 flag &= ~(CP_AUTO_LOCK);
765 }
766 else
767 {
768 flag &= ~(CP_AUTO_LOCK);
769 dependMask &= ~(CP_AUTO_LOCK) ;
770 }
771
772 }
773
774
775 sec_rec_Lock(SIMLOCK_FIRST_SIM,NULL,0,dependMask);
776 return AUTOLOCK_CMPL ;
777
778 }
779
780
781
782
783 /*
784 +------------------------------------------------------------------------------
785 | Function : aci_ext_add_code
786 +------------------------------------------------------------------------------
787 | Description : It append the category code in MEPD. It foolows FIFO procedure while adding the code
788 | Parameters : type -- category type (Network,Network subset, Service Provider,Corporate,SIM actegory)
789 | Return : void
790 |
791 +------------------------------------------------------------------------------
792 */
793
794
795 void aci_ext_add_code(T_SIMLOCK_TYPE type)
796 {
797 UINT16 index =0;
798 UBYTE max_num_user_codes;
799 UBYTE num_user_codes;
800 UBYTE curr_user_code_index;
801 UBYTE imsi_field[20];
802
803 TRACE_FUNCTION("aci_ext_add_code()");
804 switch (type)
805 {
806 case SIMLOCK_NETWORK :
807 max_num_user_codes =((UBYTE *) personalisation_nw->pBody)[index];
808 index += MAX_NUM_USERCODE_SIZE;
809 index += NUM_OPCODE_SIZE ;
810 index += OPCODE_LEN_SIZE + ((UBYTE *) personalisation_nw->pBody)[OPCODE_LEN_INDEX];
811
812 num_user_codes = ((UBYTE *)personalisation_nw->pBody)[index];
813 index +=NUM_USER_CODE_SIZE;
814 curr_user_code_index = ((UBYTE *)personalisation_nw->pBody)[index];
815 index += CURR_USER_CODE_INDEX_SIZE ;
816
817 memcpy(imsi_field,simShrdPrm.imsi.field,simShrdPrm.imsi.c_field);
818 if(simShrdPrm.mnc_len EQ 3)
819 imsi_field[NW_CODE_LEN-1] |= 0xf0;
820 else
821 imsi_field[NW_CODE_LEN-1] |= 0xff;
822
823 /*
824 * If no user code is present, curr_user_code_index will be ff. After that, curr_user_code_index starts from 0
825 */
826 if((curr_user_code_index EQ 0xff) || (curr_user_code_index EQ max_num_user_codes -1))
827 curr_user_code_index = 0;
828 else
829 curr_user_code_index++;
830
831 if(num_user_codes < max_num_user_codes)
832 num_user_codes++;
833
834 memcpy(&((UBYTE *)personalisation_nw->pBody)[index + curr_user_code_index*NW_CODE_LEN/*multiplication added*/],imsi_field,NW_CODE_LEN);
835 ((UBYTE *)personalisation_nw->pBody)[index - CURR_USER_CODE_INDEX_SIZE] = curr_user_code_index;
836 ((UBYTE *)personalisation_nw->pBody)[index - CURR_USER_CODE_INDEX_SIZE - NUM_USER_CODE_SIZE] = num_user_codes;
837 sec_set_REC(type, personalisation_nw);
838 break;
839
840
841 case SIMLOCK_NETWORK_SUBSET :
842 max_num_user_codes = ((UBYTE *)personalisation_ns->pBody)[index];
843 index += MAX_NUM_USERCODE_SIZE;
844 index += NUM_OPCODE_SIZE ;
845 index += OPCODE_LEN_SIZE + ((UBYTE *) personalisation_ns->pBody)[OPCODE_LEN_INDEX];
846
847 num_user_codes = ((UBYTE *) personalisation_ns->pBody)[index];
848 index +=NUM_USER_CODE_SIZE;
849 curr_user_code_index = ((UBYTE *)personalisation_ns->pBody)[index];
850 index += CURR_USER_CODE_INDEX_SIZE ;
851
852 memcpy(imsi_field,simShrdPrm.imsi.field,simShrdPrm.imsi.c_field);
853 if(simShrdPrm.mnc_len EQ 3)
854 imsi_field[NW_NS_CODE_LEN-1] |= 0xf0; /* prateek: unused nibbles to be '00' and not 'FF' to avoid problems during decodeIMSI */
855 else
856 imsi_field[NW_NS_CODE_LEN-1] |= 0xff;
857
858 /*
859 * If no user code is present, curr_user_code_index will be ff. After that, curr_user_code_index starts from 0
860 */
861 if((curr_user_code_index EQ 0xff) || (curr_user_code_index EQ max_num_user_codes -1))
862 curr_user_code_index = 0;
863 else
864 curr_user_code_index++;
865
866 if(num_user_codes < max_num_user_codes)
867 num_user_codes++;
868
869 memcpy(&((UBYTE *)personalisation_ns->pBody)[index + curr_user_code_index*NW_NS_CODE_LEN/*multiplication added*/],imsi_field,NW_NS_CODE_LEN);
870 ((UBYTE *)personalisation_ns->pBody)[index - CURR_USER_CODE_INDEX_SIZE] = curr_user_code_index;
871 ((UBYTE *)personalisation_ns->pBody)[index - CURR_USER_CODE_INDEX_SIZE - NUM_USER_CODE_SIZE] = num_user_codes;
872 sec_set_REC(type, personalisation_ns);
873 break;
874
875 case SIMLOCK_SERVICE_PROVIDER :
876 if(!psaSIM_ChkSIMSrvSup(SRV_GrpLvl1) OR (aci_slock_sim_config.sim_gidl1[0] EQ 0xff))
877 {
878 TRACE_FUNCTION("not adding sp as no service or maybe gid1 is ff");
879 break;
880 }
881
882 max_num_user_codes =((UBYTE *) personalisation_sp->pBody)[index];
883 index += MAX_NUM_USERCODE_SIZE;
884 index += NUM_OPCODE_SIZE ;
885 index += OPCODE_LEN_SIZE + ((UBYTE *)personalisation_sp->pBody)[OPCODE_LEN_INDEX];
886
887 num_user_codes = ((UBYTE *)personalisation_sp->pBody)[index];
888 index +=NUM_USER_CODE_SIZE;
889 curr_user_code_index = ((UBYTE *)personalisation_sp->pBody)[index];
890 index += CURR_USER_CODE_INDEX_SIZE ;
891
892 memcpy(imsi_field,simShrdPrm.imsi.field,simShrdPrm.imsi.c_field);
893 if(simShrdPrm.mnc_len EQ 3)
894 imsi_field[NW_CODE_LEN-1] |= 0xf0; /* prateek: unused nibbles to be '00' and not 'FF' to avoid problems during decodeIMSI */
895 else
896 imsi_field[NW_CODE_LEN-1] |= 0xff;
897
898 if (psaSIM_ChkSIMSrvSup(SRV_GrpLvl1))
899 {
900 memcpy(imsi_field+NW_CODE_LEN,aci_slock_sim_config.sim_gidl1,GID1_LEN);
901 /*
902 * If no user code is present, curr_user_code_index will be ff. After that, curr_user_code_index starts from 0
903 */
904 if((curr_user_code_index EQ 0xff) || (curr_user_code_index EQ max_num_user_codes -1))
905 curr_user_code_index = 0;
906 else
907 curr_user_code_index++;
908
909 if(num_user_codes < max_num_user_codes)
910 num_user_codes++;
911
912 memcpy(&((UBYTE *)personalisation_sp->pBody)[index + curr_user_code_index*(NW_CODE_LEN+GID1_LEN)],imsi_field,NW_CODE_LEN+GID1_LEN);
913 ((UBYTE *)personalisation_sp->pBody)[index - CURR_USER_CODE_INDEX_SIZE] = curr_user_code_index;
914 ((UBYTE *)personalisation_sp->pBody)[index - CURR_USER_CODE_INDEX_SIZE - NUM_USER_CODE_SIZE] = num_user_codes;
915 sec_set_REC(type, personalisation_sp);
916 }
917 break;
918
919 case SIMLOCK_CORPORATE :
920 if( !psaSIM_ChkSIMSrvSup(SRV_GrpLvl1) OR !psaSIM_ChkSIMSrvSup(SRV_GrpLvl2) OR (aci_slock_sim_config.sim_gidl1[0] EQ 0xff) OR (aci_slock_sim_config.sim_gidl2[0] EQ 0xff))
921 {
922 TRACE_FUNCTION("not adding cp as no service or maybe gid1/gid2 is ff");
923 break;
924 }
925
926 max_num_user_codes = ((UBYTE *)personalisation_cp->pBody)[index];
927 index += MAX_NUM_USERCODE_SIZE;
928 index += NUM_OPCODE_SIZE ;
929 index += OPCODE_LEN_SIZE + ((UBYTE *)personalisation_cp->pBody)[OPCODE_LEN_INDEX];
930
931 num_user_codes = ((UBYTE *)personalisation_cp->pBody)[index];
932 index +=NUM_USER_CODE_SIZE;
933 curr_user_code_index =((UBYTE *) personalisation_cp->pBody)[index];
934 index += CURR_USER_CODE_INDEX_SIZE ;
935
936 memcpy(imsi_field,simShrdPrm.imsi.field,simShrdPrm.imsi.c_field);
937 if(simShrdPrm.mnc_len EQ 3)
938 imsi_field[NW_CODE_LEN-1] |= 0xf0; /* prateek: unused nibbles to be '00' and not 'FF' to avoid problems during decodeIMSI */
939 else
940 /* if(curr_user_code_index NEQ 0) */
941 imsi_field[NW_CODE_LEN-1] |= 0xff;
942
943 if (psaSIM_ChkSIMSrvSup(SRV_GrpLvl1))
944 {
945 memcpy(imsi_field+NW_CODE_LEN,aci_slock_sim_config.sim_gidl1,GID1_LEN);
946 if (psaSIM_ChkSIMSrvSup(SRV_GrpLvl2))
947 {
948 memcpy(imsi_field+NW_CODE_LEN+GID1_LEN,aci_slock_sim_config.sim_gidl2,GID2_LEN);
949 /*
950 * If no user code is present, curr_user_code_index will be ff. After that, curr_user_code_index starts from 0
951 */
952 if((curr_user_code_index EQ 0xff) || (curr_user_code_index EQ max_num_user_codes -1))
953 curr_user_code_index = 0;
954 else
955 curr_user_code_index++;
956
957 if(num_user_codes < max_num_user_codes)
958 num_user_codes++;
959
960 memcpy(&((UBYTE *)personalisation_cp->pBody)[index + (curr_user_code_index*(NW_CODE_LEN+GID1_LEN+GID2_LEN))],imsi_field,NW_CODE_LEN+GID1_LEN+GID2_LEN);
961 ((UBYTE *)personalisation_cp->pBody)[index - CURR_USER_CODE_INDEX_SIZE] = curr_user_code_index;
962 ((UBYTE *)personalisation_cp->pBody)[index - CURR_USER_CODE_INDEX_SIZE - NUM_USER_CODE_SIZE] = num_user_codes;
963 sec_set_REC(type, personalisation_cp);
964 }
965 }
966 break;
967
968 case SIMLOCK_SIM :
969 max_num_user_codes = ((UBYTE *)personalisation_sim->pBody)[index];
970 index += MAX_NUM_USERCODE_SIZE;
971 index += NUM_OPCODE_SIZE ;
972 index += OPCODE_LEN_SIZE + ((UBYTE *)personalisation_sim->pBody)[OPCODE_LEN_INDEX];
973
974 num_user_codes = ((UBYTE *)personalisation_sim->pBody)[index];
975 index +=NUM_USER_CODE_SIZE;
976 curr_user_code_index =((UBYTE *) personalisation_sim->pBody)[index];
977 index += CURR_USER_CODE_INDEX_SIZE ;
978
979 memcpy(imsi_field,simShrdPrm.imsi.field,simShrdPrm.imsi.c_field);
980
981 /*
982 * If no user code is present, curr_user_code_index will be ff. After that, curr_user_code_index starts from 0
983 */
984 if((curr_user_code_index EQ 0xff) || (curr_user_code_index EQ max_num_user_codes -1))
985 curr_user_code_index = 0;
986 else
987 curr_user_code_index++;
988
989 if(num_user_codes < max_num_user_codes)
990 num_user_codes++;
991
992 memcpy(&((UBYTE *)personalisation_sim->pBody)[index + (curr_user_code_index*NW_NS_MSIN_CODE_LEN)],imsi_field,NW_NS_MSIN_CODE_LEN);
993 ((UBYTE *)personalisation_sim->pBody)[index - CURR_USER_CODE_INDEX_SIZE] = curr_user_code_index;
994 ((UBYTE *)personalisation_sim->pBody)[index - CURR_USER_CODE_INDEX_SIZE - NUM_USER_CODE_SIZE] = num_user_codes;
995 sec_set_REC(type, personalisation_sim);
996 break;
997 }
998 }
999
1000 /*
1001 +------------------------------------------------------------------------------
1002 | Function : aci_ext_slock_master_unlock
1003 +------------------------------------------------------------------------------
1004 | Description :
1005 | Parameters : masterkey
1006 | Return : T_OPER_RET_STATUS
1007 |
1008 +------------------------------------------------------------------------------
1009 */
1010 T_OPER_RET_STATUS aci_ext_slock_master_unlock(char *masterkey)
1011 {
1012 T_SEC_DRV_RETURN ret;
1013 ret = sec_master_Unlock( masterkey,0,0xffff );
1014 switch (ret)
1015 {
1016 case SEC_DRV_RET_Ok :
1017 return( OPER_SUCCESS );
1018 case SEC_DRV_RET_Unknown :
1019 return( OPER_FAIL );
1020 case SEC_DRV_RET_KeyMismatch :
1021 case SEC_DRV_RET_KeyWrong :
1022 return( OPER_WRONG_PASSWORD );
1023 case SEC_DRV_RET_NotPresent :
1024 return( OPER_NOT_ALLOWED );
1025 }
1026 return( OPER_FAIL );
1027 }
1028
1029 /*
1030 +------------------------------------------------------------------------------
1031 | Function : aci_ext_check_timer
1032 +------------------------------------------------------------------------------
1033 | Description : Check the timer status,is active or not
1034 | Parameters : None
1035 | Return : Status of timer
1036 |
1037 +------------------------------------------------------------------------------
1038 */
1039 UBYTE aci_ext_check_timer()
1040 {
1041 T_SEC_DRV_RETURN ret;
1042 UBYTE pStatus;
1043 ret = sec_get_timer(&pStatus);
1044 switch(ret)
1045 {
1046 case SEC_DRV_RET_Ok :
1047 return(pStatus);
1048 case SEC_DRV_RET_Unknown :
1049 return(TIMER_RUNNING);
1050 case SEC_DRV_RET_NotPresent :
1051 return(TIMER_STOPPED);
1052 }
1053 return(TIMER_STOPPED);
1054 }
1055
1056 /*
1057 +------------------------------------------------------------------------------
1058 | Function : aci_ext_set_timer_flag
1059 +------------------------------------------------------------------------------
1060 | Description : check the timer status
1061 | Parameters : status
1062 | Return : None
1063 |
1064 +------------------------------------------------------------------------------
1065 */
1066 void aci_ext_set_timer_flag(UBYTE status)
1067 {
1068 sec_set_timer(status);
1069 }
1070
1071 /*
1072 +------------------------------------------------------------------------------
1073 | Function : aci_ext_is_timer_support
1074 +------------------------------------------------------------------------------
1075 | Description : Check wheather the timer support or not
1076 | Parameters : None
1077 | Return : Timer status
1078 |
1079 +------------------------------------------------------------------------------
1080 */
1081
1082 UBYTE aci_ext_is_timer_support()
1083 {
1084
1085 if(cfg_data->Flags & SEC_DRV_HDR_FLAG_Unlock_Timer)
1086 {
1087 return TRUE;
1088 }
1089 else
1090 {
1091 return FALSE;
1092 }
1093 }
1094
1095 #endif /* SIM_PERS */
1096
1097
1098
1099 /*
1100 PURPOSE : convert bcd to ASCII
1101
1102 */
1103
1104
1105 LOCAL void decodeB2A (U8 *bcd, U8 bcd_len, U8 *ascii)
1106 {
1107 int i;
1108
1109 TRACE_FUNCTION("decodeB2A()");
1110
1111 for (i=0; i<bcd_len*2; i++)
1112 {
1113 ascii[i] = (i & 1) ? (bcd[i/2]>>4)+'0' : (bcd[i/2]&0x0f)+'0';
1114 if (ascii[i]>'9')
1115 break; /* stop if invalid digit */
1116 }
1117 ascii[i] = 0;
1118 }
1119
1120 LOCAL void encodeA2B (char *ascii, UBYTE *bcd, UBYTE bcd_len)
1121 {
1122 UBYTE i;
1123 UBYTE digit;
1124
1125 TRACE_FUNCTION("encodeA2B()");
1126
1127 for (i=0; i<bcd_len*2; i++) /* fill the whole field, pad remaining with 0xf */
1128 {
1129 if (i<strlen(ascii))
1130 {
1131 digit = ascii[i];
1132 if (digit >= '0' OR digit <= '9')
1133 {
1134 digit-= '0';
1135 }
1136 else
1137 {
1138 TRACE_EVENT_P1("[WRN] invalid digit in PIN \"%d\", skipping!", digit);
1139 digit = 0x0f;
1140 }
1141 }
1142 else
1143 {
1144 digit = 0x0f; /* unused nibbles are set to 'F'. */
1145 }
1146
1147 if ((i & 1) EQ 0)
1148 {
1149 /* process PIN digit 1,3,5,... at i=0,2,4,...*/
1150 bcd[i/2] = digit;
1151 }
1152 else
1153 {
1154 /* process PIN digit 2,4,6,... at i=1,3,5,...*/
1155 bcd[i/2] |= digit << 4;
1156 }
1157 }
1158 }
1159
1160 /* That is a workaround to buld simulation test cases */
1161 #ifdef _SIMULATION_
1162 #define effs_t int
1163 #define EFFS_OK 0
1164 #define FFS_fread(a, b, c) 0
1165 #define FFS_fwrite(a, b, c) 0
1166 #endif /*_SIMULATION_*/
1167
1168 #define FFS_MMILOCK_STATUS "/gsm/MELOCK/SecCode"
1169
1170 #ifdef TI_PS_FF_AT_P_CMD_SECS
1171 /*
1172 +------------------------------------------------------------------------------
1173 | Function : aci_ext_personalisation_CS_get_status
1174 +------------------------------------------------------------------------------
1175 | Description : Reads value of CS lock from file and returns it
1176 | Parameters : void
1177 |
1178 |
1179 | Return : status of CS lock
1180 | Remark: : It is proposed to implement through security driver
1181 |
1182 +------------------------------------------------------------------------------
1183 */
1184 T_SIMLOCK_STATUS aci_ext_personalisation_CS_get_status()
1185 {
1186 effs_t ffs_rslt;
1187 TRACE_FUNCTION("aci_ext_personalisation_CS_get_status()");
1188
1189 ffs_rslt = FFS_fread(FFS_MMILOCK_STATUS, &MMI_personalisation_status, sizeof(MMI_personalisation_status));
1190 if(ffs_rslt < EFFS_OK) /* error */
1191 {
1192 TRACE_EVENT_P1("unable to read %s", FFS_MMILOCK_STATUS);
1193 return SIMLOCK_FAIL;
1194 }
1195 return (T_SIMLOCK_STATUS) MMI_personalisation_status.State;
1196 }
1197
1198
1199 /*
1200 +------------------------------------------------------------------------------
1201 | Function : aci_ext_personalisation_CS_set_status
1202 +------------------------------------------------------------------------------
1203 | Description : Reads value of CS lock from file compare passwords and if correct, sets CS lock status
1204 | Parameters : lock - enable or disable
1205 | passwd - password to change lock
1206 |
1207 |
1208 | Return : status of operation
1209 | Remark: : It is proposed to implement through security driver
1210 |
1211 +------------------------------------------------------------------------------
1212 */
1213 T_SIMLOCK_STATUS aci_ext_personalisation_CS_set_status(T_SIMLOCK_STATUS lock , char * passwd)
1214 {
1215 effs_t ffs_rslt;
1216 U8 exp_pin[6+1]; /* +1 for '\0' */
1217 T_SIMLOCK_STATUS result;
1218 TRACE_FUNCTION("aci_ext_personalisation_CS_set_status()");
1219
1220 /* Read data from FFS */
1221
1222 ffs_rslt = FFS_fread(FFS_MMILOCK_STATUS, &MMI_personalisation_status, sizeof(MMI_personalisation_status));
1223
1224 if(ffs_rslt < EFFS_OK) /* error */
1225 {
1226 TRACE_EVENT_P1("unable to read %s", FFS_MMILOCK_STATUS);
1227 return SIMLOCK_FAIL;
1228 }
1229
1230 decodeB2A(MMI_personalisation_status.Cur_code, 3, exp_pin);
1231
1232 if (strncmp((char *)exp_pin, (char *)passwd, 3))
1233 {
1234 /* Block personalisation lock, if tried too often! */
1235 MMI_personalisation_status.cnt++;
1236 if (MMI_personalisation_status.cnt >= MMI_personalisation_status.maxcnt)
1237 {
1238 result = SIMLOCK_BLOCKED;
1239 }
1240 else
1241 {
1242 result = SIMLOCK_LOCKED;
1243 }
1244 }
1245 else
1246 {
1247 /* correct pin passed */
1248 MMI_personalisation_status.cnt = 0;
1249 MMI_personalisation_status.State = lock;
1250 result = lock;
1251 }
1252 ffs_rslt = FFS_fwrite(FFS_MMILOCK_STATUS, &MMI_personalisation_status, sizeof(MMI_personalisation_status));
1253
1254 if (ffs_rslt < EFFS_OK)
1255 {
1256 TRACE_EVENT_P1("unable to write %s", FFS_MMILOCK_STATUS);
1257 return SIMLOCK_FAIL;
1258 }
1259 return result;
1260 }
1261 #endif /* TI_PS_FF_AT_P_CMD_SECP */
1262 #ifdef TI_PS_FF_AT_P_CMD_SECP
1263 /*
1264 +------------------------------------------------------------------------------
1265 | Function : aci_ext_personalisation_CS_change_password
1266 +------------------------------------------------------------------------------
1267 | Description : Reads value of CS lock from file compare passwords and if correct, sets new password
1268 | Parameters : passwd - old password
1269 | new_passwd - new password
1270 |
1271 |
1272 | Return : status of operation
1273 | Remark: : It is proposed to implement through security driver
1274 |
1275 +------------------------------------------------------------------------------
1276 */
1277 T_SIMLOCK_STATUS aci_ext_personalisation_CS_change_password( char *passwd, char *new_passwd )
1278 {
1279 effs_t ffs_rslt;
1280 U8 exp_pin[6+1]; /* +1 for '\0' */
1281 T_SIMLOCK_STATUS result;
1282
1283 TRACE_FUNCTION("aci_ext_personalisation_CS_change_password()");
1284
1285 ffs_rslt = FFS_fread(FFS_MMILOCK_STATUS, &MMI_personalisation_status, sizeof(MMI_personalisation_status));
1286 if(ffs_rslt < EFFS_OK) /* error */
1287 {
1288 TRACE_EVENT_P1("unable to read %s", FFS_MMILOCK_STATUS);
1289 return SIMLOCK_FAIL;
1290 }
1291
1292
1293 decodeB2A(MMI_personalisation_status.Cur_code, 3, exp_pin);
1294
1295 if (strncmp((char *)exp_pin, (char *)passwd, 3))
1296 {
1297 /* Block personalisation lock, if tried too often! */
1298 MMI_personalisation_status.cnt++;
1299 if (MMI_personalisation_status.cnt >= MMI_personalisation_status.maxcnt)
1300 {
1301 result = SIMLOCK_BLOCKED;
1302 }
1303 else
1304 {
1305 result = SIMLOCK_LOCKED;
1306 }
1307 }
1308 else
1309 {
1310 /* correct pin passed */
1311 MMI_personalisation_status.cnt=0;
1312 if ((new_passwd NEQ NULL) AND (strlen(new_passwd) > 0))
1313 {
1314 encodeA2B(new_passwd, MMI_personalisation_status.Cur_code, 3);
1315 }
1316 result = (T_SIMLOCK_STATUS) MMI_personalisation_status.State;
1317 }
1318 ffs_rslt = FFS_fwrite(FFS_MMILOCK_STATUS, &MMI_personalisation_status, sizeof(MMI_personalisation_status));
1319
1320 if (ffs_rslt < EFFS_OK)
1321 {
1322 TRACE_EVENT_P1("unable to write %s", FFS_MMILOCK_STATUS);
1323 return SIMLOCK_FAIL;
1324 }
1325 return result;
1326 }
1327 #endif /* TI_PS_FF_AT_P_CMD_SECP */
1328
1329 #ifdef FF_PHONE_LOCK
1330
1331 /*
1332 +------------------------------------------------------------------------------
1333 | Function : aci_ext_set_phone_lock_satus
1334 +------------------------------------------------------------------------------
1335 | Description : Sets the Phone Lock status value
1336 | Parameters : type - Phone Lock or Auto Phone Lock
1337 | status - Enable or Disable
1338 | passwd - Unlock passwd
1339 |
1340 |
1341 | Return : status of operation OPER_SUCCESS or OPER_WRONG_PASSWORD
1342 | |
1343 +------------------------------------------------------------------------------
1344 */
1345 T_OPER_RET_STATUS aci_ext_set_phone_lock_satus(T_SEC_DRV_EXT_PHONE_LOCK_TYPE type,T_SEC_DRV_EXT_PHONE_LOCK_STATUS status,const char *passwd)
1346 {
1347 T_SEC_DRV_RETURN results;
1348
1349 results = sec_set_phone_lock_status(type,status,passwd,0);
1350 if(results EQ SEC_DRV_RET_Ok)
1351 return(OPER_SUCCESS);
1352 else if(results EQ SEC_DRV_RET_KeyMismatch)
1353 return(OPER_WRONG_PASSWORD);
1354 else
1355 return(OPER_NOT_ALLOWED);
1356 }
1357
1358 /*
1359 +------------------------------------------------------------------------------
1360 | Function : aci_ext_get_phone_lock_satus
1361 +------------------------------------------------------------------------------
1362 | Description : Gets the Phone Lock status value
1363 | Parameters : type - Phone Lock or Auto Phone Lock
1364 | status - Address of the Status.
1365 |
1366 |
1367 | Return : Plone Lock or Auto Lock status value is set in the address
1368 | |
1369 +------------------------------------------------------------------------------
1370 */
1371 T_OPER_RET_STATUS aci_ext_get_phone_lock_satus(T_SEC_DRV_EXT_PHONE_LOCK_TYPE type,T_SEC_DRV_EXT_PHONE_LOCK_STATUS *status)
1372 {
1373 T_SEC_DRV_RETURN results;
1374
1375 results = sec_get_phone_lock_status(type,status);
1376 if(results EQ SEC_DRV_RET_Ok)
1377 return(OPER_SUCCESS);
1378 else
1379 return(OPER_NOT_ALLOWED);
1380 }
1381
1382
1383 /*
1384 +------------------------------------------------------------------------------
1385 | Function : aci_ext_set_phone_lock_key
1386 +------------------------------------------------------------------------------
1387 | Description : Sets the Phone Lock key value
1388 | Parameters : pOldKey - Old key
1389 | pNewKey - New Key.
1390 |
1391 |
1392 | Return : OPER_SUCCESS if change key is success
1393 | OPER_WRONG_PASSWORD if wrong old key
1394 | |
1395 +------------------------------------------------------------------------------
1396 */
1397
1398 T_OPER_RET_STATUS aci_ext_set_phone_lock_key(const char *pOldKey,const char *pNewKey)
1399 {
1400 T_SEC_DRV_RETURN results;
1401
1402 results = sec_set_phone_lock_key(pOldKey, pNewKey, 0);
1403 if(results EQ SEC_DRV_RET_Ok)
1404 return(OPER_SUCCESS);
1405 else if((results EQ SEC_DRV_RET_KeyMismatch) OR (results EQ SEC_DRV_RET_KeyWrong))
1406 return(OPER_WRONG_PASSWORD);
1407 else
1408 return(OPER_NOT_ALLOWED);
1409
1410 }
1411 #endif
1412