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