comparison g23m/condat/ms/src/aci/aci_slock.c @ 0:509db1a7b7b8

initial import: leo2moko-r1
author Space Falcon <falcon@ivan.Harhan.ORG>
date Mon, 01 Jun 2015 03:24:05 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:509db1a7b7b8
1 /*
2 +-----------------------------------------------------------------------------
3 | Project :
4 | Modul : J:\g23m-aci\aci\aci_slock.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 #ifdef SIM_PERS
22 #include "aci_all.h"
23
24 #include "aci_cmh.h"
25 #include "ati_cmd.h"
26 #include "aci_cmd.h"
27
28 #ifdef FAX_AND_DATA
29 #include "aci_fd.h"
30 #endif /* FAX_AND_DATA */
31
32 #include "aci.h"
33 #include "psa.h"
34 #include "psa_sim.h"
35 #include "psa_sms.h"
36 #include "psa_mmi.h"
37 #include "cmh.h"
38 #include "dti_conn_mng.h"
39 #include "cmh_sim.h"
40 #include "phb.h"
41 #include "aoc.h"
42
43 #include "psa_sim.h" /* simShrdPrm */
44
45 #include "aci_ext_pers.h" /* we are using personalisation extensions */
46 #include "aci_slock.h" /* in order to asure interfaces */
47
48 /* Remember actual stati of already checked locks */
49 GLOBAL T_ACI_SLOCK_SHARED AciSLockShrd;
50
51 GLOBAL UBYTE sim_code_present_in_me; /* used by personalisation */
52 GLOBAL T_ACI_SIM_CONFIG aci_slock_sim_config; /* SIM configuration, initialised by a T_SIM_MMI_INSERT_IND */
53
54 #include "general.h" // inluded for UINT8 compilation error in sec_drv.h
55 #include "sec_drv.h"
56
57 GLOBAL T_SEC_DRV_CONFIGURATION *cfg_data ;
58
59 EXTERN T_SEC_DRV_CATEGORY *personalisation_nw;
60
61 EXTERN T_SEC_DRV_CATEGORY *personalisation_ns;
62
63 EXTERN T_SEC_DRV_CATEGORY *personalisation_sp;
64
65 EXTERN T_SEC_DRV_CATEGORY *personalisation_cp;
66
67 EXTERN T_SEC_DRV_CATEGORY *personalisation_sim;
68
69 EXTERN T_SEC_DRV_CATEGORY *personalisation_first_sim;
70 EXTERN void psaSAT_FUConfirm ( int, USHORT );
71 const UBYTE mnc_mcc[6] = "00101"; // 04-08-2005
72
73 LOCAL UBYTE aci_slock_sim_service_table [10]; /* SIM service table */
74
75 EXTERN T_SIM_MMI_INSERT_IND *last_sim_mmi_insert_ind;
76
77
78
79 /*
80 +------------------------------------------------------------------------------
81 | Function : aci_slock_init
82 +------------------------------------------------------------------------------
83 | Description : Initialising of this module. Has to be called first and *once only* before
84 | calling any other method.
85 |
86 | Parameters : None
87 |
88 | Return : void
89 |
90 +------------------------------------------------------------------------------
91 */
92
93 void aci_slock_init ( void )
94 {
95
96 TRACE_FUNCTION("aci_slock_init()");
97
98 /* Initialise the ACI Personalisation extension */
99 aci_ext_personalisation_init();
100 AciSLockShrd.blocked = FALSE;
101
102 }
103
104
105
106
107 /*
108 Temporary Unlocks the lock of the given type after verifying the given password.
109 The ACI extension for password verifying (see 2.3.9.1) will be used to
110 determine if the given password is correct or not.
111 On a successful unlock the actual status of the lock will be returned.
112 If an error occurred SIMLOCK_FAIL will be returned.
113 (Uses the ACI extension "personalisation data access".)
114 */
115 T_SIMLOCK_STATUS aci_slock_authenticate ( T_SIMLOCK_TYPE type, char *passwd )
116 {
117 T_SIMLOCK_STATUS result;
118
119 TRACE_FUNCTION("aci_slock_authenticate()");
120 result = aci_ext_personalisation_verify_password(type, passwd);
121
122 if ( (result EQ SIMLOCK_DISABLED) AND (AciSLockShrd.blocked)) /* If lock is checked as blocked at the moment uncheck it! */
123 {
124 AciSLockShrd.blocked = !(AciSLockShrd.current_lock EQ type);
125 }
126
127 return result;
128 }
129
130
131 /*
132 ACI method for retrieving the status of a single personalisation type. This method calls extension
133 methods which in turn calls Security Drv. API and retrn the status of a personalisation category.
134 The personalisation status is stored in MEPD which is directly accessed by Security Drv.
135 Added on 11/03/2005
136 */
137 T_SIMLOCK_STATUS aci_personalisation_get_status ( T_SIMLOCK_TYPE personalisation_type )
138 {
139 TRACE_FUNCTION("aci_personalisation_get_status ()");
140 return aci_ext_personalisation_get_status(personalisation_type);
141 }
142 //#endif
143
144
145 /*
146 +------------------------------------------------------------------------------
147 | Function : aci_slock_unlock
148 +------------------------------------------------------------------------------
149 | Description : Unlocks the lock of the given type after verifying the given password.
150 | The ACI extension for password verifying (see 2.3.9.1) will be used to
151 | determine if the given password is correct or not.
152 | On a successful unlock the actual status of the lock will be returned.
153 | If an error occurred SIMLOCK_FAIL will be returned.
154 | (Uses the ACI extension "personalisation data access".)
155 |
156 | Parameters : type - Category Lock type
157 | passwd - lock Password
158 |
159 | Return : SIMLOCK_FAIL = -1,
160 | SIMLOCK_DISABLED, No SIM lock check has to be done
161 | SIMLOCK_PERM_DISABLED,
162 | SIMLOCK_ENABLED, A SIM lock check has to be executed
163 | SIMLOCK_BLOCKED, The SIM is blocked, i.e. because of a (or to many) wrong PIN(s)
164 | SIMLOCK_LOCKED The ME is locked because of wrong SIM
165 |
166 +------------------------------------------------------------------------------
167 */
168
169 T_SIMLOCK_STATUS aci_slock_unlock ( T_SIMLOCK_TYPE type, char *passwd )
170 {
171 T_SIMLOCK_STATUS result;
172
173 TRACE_FUNCTION("aci_slock_unlock()");
174 aci_slock_set_CFG();
175 if(cfg_data EQ NULL)
176 {
177 return SIMLOCK_FAIL;
178 }
179
180 result = aci_ext_personalisation_set_status(type, SIMLOCK_DISABLED, passwd);
181
182 if ( (result EQ SIMLOCK_DISABLED) AND (AciSLockShrd.blocked)) /* If lock is checked as blocked at the moment uncheck it! */
183 {
184 AciSLockShrd.blocked = !(AciSLockShrd.current_lock EQ type);
185 }
186 MFREE(cfg_data);
187
188 return result;
189
190
191 }
192
193
194 /*
195 +------------------------------------------------------------------------------
196 | Function : aci_slock_lock
197 +------------------------------------------------------------------------------
198 | Description : Locks the lock of the given type. On a successful lock the actual
199 | status of the lock will be returned. If an error occurred SIMLOCK_FAIL
200 | will be returned. This method will use the ACI extension for password
201 | verifying (see 2.3.9.1) to determine if the given password is correct
202 | or not. (Uses the ACI extension "personalisation data access".)
203 |
204 | Parameters : type - Category Lock type
205 | passwd - lock Password
206 |
207 | Return : SIMLOCK_FAIL = -1,
208 | SIMLOCK_DISABLED, No SIM lock check has to be done
209 | SIMLOCK_PERM_DISABLED,
210 | SIMLOCK_ENABLED, A SIM lock check has to be executed
211 | SIMLOCK_BLOCKED, The SIM is blocked, i.e. because of a (or to many) wrong PIN(s)
212 | SIMLOCK_LOCKED The ME is locked because of wrong SIM
213 |
214 +------------------------------------------------------------------------------
215 */
216 T_SIMLOCK_STATUS aci_slock_lock ( T_SIMLOCK_TYPE type, char *passwd )
217 {
218
219 T_SIMLOCK_STATUS result;
220 T_SEC_DRV_RETURN ret;
221 UBYTE imsi_sim[MAX_IMSI_LEN+1];
222 int numUserCodeIdx;
223 BOOL lock = TRUE;
224 TRACE_FUNCTION("aci_slock_lock()");
225
226 if(aci_slock_sim_config.sim_type EQ SIM_NORMAL)
227 {
228 aci_slock_set_CFG();
229 if(cfg_data EQ NULL)
230 {
231 return SIMLOCK_FAIL;
232 }
233 aci_ext_personalisation_init();
234 result = aci_ext_personalisation_get_status( type );
235
236 if(result EQ SIMLOCK_DISABLED)
237 {
238 if(cfg_data->AddNewIMSI & ( 0x0001 << type) ) /* 1-Apr-05 Bitmap check */
239 {
240 sim_code_present_in_me = FALSE;
241 psaSIM_decodeIMSI(simShrdPrm.imsi.field, simShrdPrm.imsi.c_field, (char *)imsi_sim);
242 switch(type)
243 {
244 case SIMLOCK_NETWORK: aci_slock_check_NWlock(imsi_sim, 1);break;
245 case SIMLOCK_NETWORK_SUBSET: aci_slock_check_NSlock(imsi_sim, 1);break;
246 case SIMLOCK_SIM: aci_slock_check_SMlock(imsi_sim, 1); break;
247 /*Added cases for SP & CP below: 2nd April - 2005*/
248 case SIMLOCK_SERVICE_PROVIDER:
249 if (psaSIM_ChkSIMSrvSup(SRV_GrpLvl1) )
250 {
251 if(aci_slock_sim_config.sim_read_gid1 EQ FALSE)
252 {
253 aci_slock_sim_read_sim(SIM_GID1, NOT_PRESENT_8BIT, MAX_GID);
254 aci_ext_personalisation_free();
255 MFREE(cfg_data);
256 return SIMLOCK_WAIT;
257 }
258 }
259 else
260 {
261 aci_ext_personalisation_free();
262 MFREE(cfg_data);
263 return SIMLOCK_FAIL;
264 }
265 aci_slock_check_SPlock(imsi_sim,1);break;
266 case SIMLOCK_CORPORATE:
267 if (psaSIM_ChkSIMSrvSup(SRV_GrpLvl1))
268 {
269 if(aci_slock_sim_config.sim_read_gid1 EQ FALSE)
270 {
271 aci_slock_sim_read_sim(SIM_GID1, NOT_PRESENT_8BIT, MAX_GID);
272 aci_ext_personalisation_free();
273 MFREE(cfg_data);
274 return SIMLOCK_WAIT;
275 }
276 }
277 else
278 {
279 aci_ext_personalisation_free();
280 MFREE(cfg_data);
281 return SIMLOCK_FAIL;
282 }
283
284 if (psaSIM_ChkSIMSrvSup(SRV_GrpLvl2))
285 {
286 if(aci_slock_sim_config.sim_read_gid2 EQ FALSE)
287 {
288 aci_slock_sim_read_sim(SIM_GID2, NOT_PRESENT_8BIT, MAX_GID);
289 aci_ext_personalisation_free();
290 MFREE(cfg_data);
291 return SIMLOCK_WAIT;
292 }
293 }
294 else
295 {
296 aci_ext_personalisation_free();
297 MFREE(cfg_data);
298 return SIMLOCK_FAIL;
299 }
300 aci_slock_check_CPlock(imsi_sim, 1);break;
301 default:TRACE_ERROR ("illegal type aci_slock_lock ()");
302 return;
303 }
304 if (sim_code_present_in_me EQ FALSE)
305 {
306 /* changes for ETSI behavior date : 01-Apr-05*/
307 if (cfg_data->Flags & SEC_DRV_HDR_FLAG_ETSI_Flag)
308 {
309 ret = SEC_DRV_RET_Ok ;
310 }
311 else
312 {
313 ret = sec_cmp_KEY(type,passwd,0);
314 }
315 if(ret EQ SEC_DRV_RET_Ok)
316 {
317 aci_ext_add_code(type);
318 }
319 else
320 {
321 aci_ext_personalisation_free();
322 MFREE(cfg_data);
323 return SIMLOCK_FAIL;
324 }
325 }
326 else if(sim_code_present_in_me EQ CHECK_FAIL)
327 {
328 aci_ext_personalisation_free();
329 MFREE(cfg_data);
330 return SIMLOCK_FAIL;
331 }
332 }
333
334 /*
335 * If there are no operator-defined codes or user-defined codes in the MEPD at all, do not lock the category
336 */
337 switch(type)
338 {
339 case SIMLOCK_NETWORK :
340 numUserCodeIdx = OPCODE_LEN_INDEX + ((UBYTE *)personalisation_nw->pBody)[OPCODE_LEN_INDEX] + 1;
341 if( (((UBYTE *) personalisation_nw->pBody)[OPCODE_LEN_INDEX] EQ 0) AND
342 (((UBYTE *) personalisation_nw->pBody)[numUserCodeIdx] EQ 0) )
343 {
344 /*Do not lock the category*/
345 lock = FALSE;
346 }
347 break;
348
349 case SIMLOCK_NETWORK_SUBSET :
350 numUserCodeIdx = OPCODE_LEN_INDEX + ((UBYTE *)personalisation_ns->pBody)[OPCODE_LEN_INDEX] + 1;
351 if( ( ((UBYTE *)personalisation_ns->pBody)[OPCODE_LEN_INDEX] EQ 0) AND
352 ( ((UBYTE *)personalisation_ns->pBody)[numUserCodeIdx] EQ 0) )
353 {
354 /*Do not lock the category*/
355 lock = FALSE;
356 }
357 break;
358
359 case SIMLOCK_SIM :
360 numUserCodeIdx = OPCODE_LEN_INDEX +((UBYTE *) personalisation_sim->pBody)[OPCODE_LEN_INDEX] + 1;
361 if( (((UBYTE *) personalisation_sim->pBody)[OPCODE_LEN_INDEX] EQ 0) AND
362 (((UBYTE *) personalisation_sim->pBody)[numUserCodeIdx] EQ 0) )
363 {
364 /*Do not lock the category*/
365 lock = FALSE;
366 }
367 break;
368
369 case SIMLOCK_SERVICE_PROVIDER:
370 numUserCodeIdx = OPCODE_LEN_INDEX + ((UBYTE *)personalisation_sp->pBody)[OPCODE_LEN_INDEX] + 1;
371 if( ( ((UBYTE *)personalisation_sp->pBody)[OPCODE_LEN_INDEX] EQ 0) AND
372 (((UBYTE *) personalisation_sp->pBody)[numUserCodeIdx] EQ 0) )
373 {
374 /*Do not lock the category*/
375 lock = FALSE;
376 }
377 break;
378
379 case SIMLOCK_CORPORATE:
380 numUserCodeIdx = OPCODE_LEN_INDEX + ((UBYTE *)personalisation_cp->pBody)[OPCODE_LEN_INDEX] + 1;
381 if( ( ((UBYTE *)personalisation_cp->pBody)[OPCODE_LEN_INDEX] EQ 0) AND
382 ( ((UBYTE *)personalisation_cp->pBody)[numUserCodeIdx] EQ 0) )
383 {
384 /*Do not lock the category*/
385 lock = FALSE;
386 }
387 break;
388 }
389
390 if(lock EQ TRUE)
391 {
392 result = aci_ext_personalisation_set_status(type, SIMLOCK_ENABLED, passwd);
393 }
394
395 aci_ext_personalisation_free();
396 MFREE(cfg_data);
397 return result;
398 }
399 else
400 {
401 aci_ext_personalisation_free();
402 MFREE(cfg_data);
403 return SIMLOCK_FAIL;
404 }
405 }
406 else
407 return SIMLOCK_FAIL;
408 }
409
410
411 /*
412 +------------------------------------------------------------------------------
413 | Function : aci_slock_reset_fc
414 +------------------------------------------------------------------------------
415 | Description : This function is used to reset the Failure Counter
416 |
417 | Parameters : char* fcKey - Failure Reset Key
418 |
419 | Return : OPER_FAIL
420 | OPER_SUCCESS
421 |
422 +------------------------------------------------------------------------------
423 */
424
425 T_OPER_RET_STATUS aci_slock_reset_fc ( char *fcKey )
426 {
427 TRACE_FUNCTION("aci_slock_reset_fc ()");
428 return aci_ext_slock_reset_fc(fcKey);
429 }
430
431 /*
432 +------------------------------------------------------------------------------
433 | Function : aci_slock_sup_info
434 +------------------------------------------------------------------------------
435 | Description : This function is used to get the supplementary information like FCMAX,
436 | FCATTEMPTSLEFT, FCRESETFAILMAX, FCRESETFAILATTEMPTSLEFT,
437 | FCRESETSUCCESSMAX, FCRESETSUCCESSATTEMPTSLEFT, TIMERFLAG,
438 | ETSIFLAG, AIRTELINDFLAG
439 |
440 | Parameters : sup_info - Pointer to T_SUP_INFO
441 |
442 | Return : OPER_FAIL
443 | OPER_SUCCESS
444 |
445 +------------------------------------------------------------------------------
446 */
447 T_OPER_RET_STATUS aci_slock_sup_info(T_SUP_INFO *sup_info)
448 {
449 TRACE_FUNCTION("aci_slock_sup_info()");
450 return aci_ext_slock_sup_info (sup_info);
451 }
452
453
454 /*
455 +------------------------------------------------------------------------------
456 | Function : aci_slock_change_password
457 +------------------------------------------------------------------------------
458 | Description : This function is used to change the password of a category
459 |
460 | Parameters : type - Category lock type
461 | passwd - Old Control key
462 | new_passwd - New Control key
463 |
464 | Return : SIMLOCK_FAIL = -1,
465 | SIMLOCK_DISABLED, No SIM lock check has to be done
466 | SIMLOCK_PERM_DISABLED,
467 | SIMLOCK_ENABLED, A SIM lock check has to be executed
468 | SIMLOCK_BLOCKED, The SIM is blocked, i.e. because of a (or to many) wrong PIN(s)
469 | SIMLOCK_LOCKED The ME is locked because of wrong SIM
470 |
471 +------------------------------------------------------------------------------
472 */
473
474 T_SIMLOCK_STATUS aci_slock_change_password ( T_SIMLOCK_TYPE type, char *passwd, char *new_passwd )
475 {
476 TRACE_FUNCTION("aci_slock_change_password()");
477 return aci_ext_personalisation_change_password(type, passwd, new_passwd);
478 }
479
480
481 /*
482 +------------------------------------------------------------------------------
483 | Function : aci_slock_psaSIM_decodeIMSI
484 +------------------------------------------------------------------------------
485 | Description : convert imsi (packed bcd to ASCIIZ; ->11.11)
486 |
487 | Parameters : imsi_field - IMSI in BCD
488 | imsi_c_field -
489 | imsi_asciiz - ASCII IMSI
490 |
491 | Return : void
492 |
493 +------------------------------------------------------------------------------
494 */
495 GLOBAL void aci_slock_psaSIM_decodeIMSI (UBYTE* imsi_field,
496 UBYTE imsi_c_field, CHAR* imsi_asciiz)
497 {
498
499 UBYTE imsi_len;
500 UBYTE i;
501 UBYTE digit;
502
503
504 /*
505
506 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 |
507
508 +---+---+---+---+---+---+---+---+
509 imsi_c_field = | Length indicator |
510 imsi_field[0] = | IMSI digit 1 | p | 0 | 0 | 1 |
511 imsi_field[1] = | IMSI digit 3 | IMSI digit 2 |
512
513 imsi_c_field = length indicator:
514
515 The length indicator refers to the number of significant bytes, not including this length byte,
516 required for the IMSI.
517 p = parity
518 0: Even number of IMSI digits
519 1: Odd number of IMSI digits
520
521 If the number of IMSI digits is even then bits 5 to 8 of the last octet shall be filled with an end mark coded as 1111b
522 */
523
524 /*
525 *
526 Check length
527 */
528 if ((imsi_c_field EQ 0) OR (imsi_c_field > (MAX_IMSI-1))) /* maybe 0xFF on some testcards */
529 {
530 TRACE_EVENT_P1("[WRN] imsi_c_field = %d is not valid", imsi_c_field);
531
532 imsi_asciiz[0] = '\0'; /* return empty string in case of error */
533
534 return;
535 }
536
537 /*
538 * calculate number of digits
539 */
540 imsi_len = (imsi_c_field)*2-1; /* -1 goes off for parity nibble */
541
542
543 /*
544 * if even number of digits then last upper nibble is an end mark '1111'
545 */
546 if ((imsi_field[0] & 0x08) EQ 0)
547 {
548 imsi_len--;
549 }
550
551
552
553 if ((imsi_field[0] & 0x08) EQ 0)
554 {
555 imsi_len--;
556 }
557
558 /*
559 * extract all digits
560 */
561 for (i=0; i<imsi_len; i++)
562 {
563 if ((i & 1) EQ 0)
564 {
565 /* process IMSI digit 1,3,5,... at i=0,2,4,...*/
566 digit = (imsi_field[(i+1)/2] & 0xf0) >> 4; /* +1 is to skip parity nibble */
567 }
568 else
569 {
570 /* process IMSI digit 2,4,6,... at i=1,3,5,...*/
571 digit = (imsi_field[(i+1)/2] & 0x0f);
572 }
573
574 if (digit > 9)
575 {
576 imsi_asciiz[i] = 'F';
577 // return;
578 }
579 else
580 {
581 imsi_asciiz[i] = '0' + digit;
582 }
583
584 }
585 imsi_asciiz[i] = '\0';
586 return;
587 }
588
589
590 /*
591 +------------------------------------------------------------------------------
592 | Function : aci_slock_psaSIM_decodeIMSI_without_parity
593 +------------------------------------------------------------------------------
594 | Description : convert imsi (packed bcd to ASCIIZ; ->11.11)
595 |
596 | Parameters : imsi_field - IMSI in BCD
597 | imsi_c_field -
598 | imsi_asciiz - ASCII IMSI
599 |
600 | Return : void
601 |
602 +------------------------------------------------------------------------------
603 */
604
605 GLOBAL void aci_slock_psaSIM_decodeIMSI_without_parity(UBYTE* imsi_field,
606 UBYTE imsi_c_field,
607 CHAR* imsi_asciiz)
608 {
609
610 UBYTE imsi_len;
611 UBYTE i;
612 UBYTE digit;
613
614 //TRACE_FUNCTION ("aci_slock_sim_decodeIMSI()");
615
616 /*
617 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 |
618 +---+---+---+---+---+---+---+---+
619 imsi_c_field = | Length indicator |
620 imsi_field[0] = | IMSI digit 1 | p | 0 | 0 | 1 |
621 imsi_field[1] = | IMSI digit 3 | IMSI digit 2 |
622
623
624 imsi_c_field = length indicator:
625 The length indicator refers to the number of significant bytes,
626 not including this length byte, required for the IMSI.
627 p = parity
628 0: Even number of IMSI digits
629 1: Odd number of IMSI digits
630
631 If the number of IMSI digits is even then bits 5 to 8 of the last octet
632 shall be filled with an end mark coded as 1111b
633 */
634
635 /*
636 * Check length
637 */
638 if ((imsi_c_field EQ 0) OR (imsi_c_field > (MAX_IMSI-1))) /* maybe 0xFF on some testcards */
639 {
640 TRACE_EVENT_P1("[WRN] imsi_c_field = %d is not valid", imsi_c_field);
641 imsi_asciiz[0] = '\0'; /* return empty string in case of error */
642 return;
643 }
644
645 /*
646 * calculate number of digits
647 */
648 imsi_len = (imsi_c_field)*2;
649
650
651
652 /*
653 * extract all digits
654 */
655 for (i=0; i<imsi_len; i++)
656 {
657 if ((i & 1) EQ 0)
658 {
659 /* process IMSI digit 1,3,5,... at i=0,2,4,...*/
660 digit = (imsi_field[i/2] & 0x0f);
661
662 }
663 else
664 {
665 /* process IMSI digit 2,4,6,... at i=1,3,5,...*/
666 digit = (imsi_field[i/2] & 0xf0) >> 4; /* +1 is to skip parity nibble */
667 }
668
669 if (digit > 9)
670 {
671
672 imsi_asciiz[i] = 'F';
673 // return;
674 }
675 else
676 {
677 imsi_asciiz[i] = '0' + digit;
678 }
679
680
681 }
682 imsi_asciiz[i] = '\0';
683 return;
684
685 }
686
687
688 /*
689 +------------------------------------------------------------------------------
690 | Function : aci_slock_check_NWlock
691 +------------------------------------------------------------------------------
692 | Description : Check IMSI against network personalisation
693 |
694 | Parameters : imsi_sim - IMSI
695 | personalisation - 0-add the lock data
696 | 1-verify the existing lock data
697 |
698 | Return : void
699 |
700 +------------------------------------------------------------------------------
701 */
702
703 void aci_slock_check_NWlock( UBYTE* imsi_sim, UBYTE personalisation )
704 {
705
706 UBYTE max_num_user_codes;
707 UBYTE num_op_codes;
708 UBYTE curr_user_code_index;
709 UBYTE num_user_codes;
710 UBYTE opcode_len;
711 UBYTE code_type;
712
713 UBYTE i;
714 UINT16 index =0;
715 UBYTE me_nw_code_bcd[NW_CODE_LEN];
716 UBYTE me_nw_code_first_bcd[NW_CODE_LEN];
717 UBYTE me_nw_code_last_bcd[NW_CODE_LEN];
718 UBYTE imsi_me[MAX_IMSI_LEN+1];
719 UBYTE imsi_sim_temp[MAX_IMSI_LEN+1];
720
721 int me_nw_code_first, me_nw_code_last, sim_nw_code;
722
723 TRACE_FUNCTION("aci_slock_check_NWlock()");
724
725 /*
726 personalisation_nw->pBody[0] -----maximum number of user codes
727 personalisation_nw->pBody[1] -----num of operator codes
728 personalisation_nw->pBody[2] -----Operator Code-group length (To be set during configuration)
729 where length = total number of bytes occupied by operator codes
730
731
732 Code type = 0x0a ( Type identifier for normal code)
733 Normal code (Including parity nibble) -- 4 bytes
734
735 Code type = 0x0b (Type identifier for range)
736 Start value (Including parity nibble) ---- 4 byte
737 End value (Including parity nibble) -----4 byte
738
739 Code type = 0x0c (Type identifier for regular expression)
740 Regular Expression -------------6 byte
741
742
743 Number of User Codes --- 1 byte
744 Current user code index --- 1 byte
745 User code1 ------------4 byte
746
747 */
748 //TRACE_FUNCTION_P1("personalisation = %d",personalisation);
749 if((personalisation_nw NEQ NULL) AND ((UBYTE *)personalisation_nw->pBody NEQ NULL))
750 {
751 max_num_user_codes = ((UBYTE *)personalisation_nw->pBody)[index];
752 index += MAX_NUM_USERCODE_SIZE;
753
754 num_op_codes = ((UBYTE *)personalisation_nw->pBody)[index];
755 index += NUM_OPCODE_SIZE;
756
757 opcode_len = ((UBYTE *)personalisation_nw->pBody)[index];
758 index +=OPCODE_LEN_SIZE;
759
760 if(!personalisation)
761 {
762 AciSLockShrd.blocked = TRUE;
763 }
764 else
765 {
766 sim_code_present_in_me = FALSE;
767 }
768 /*
769 * check operator defined code-groups
770 */
771 for(i=0; i< num_op_codes; i++)
772 {
773 code_type =((UBYTE *) personalisation_nw->pBody)[index];
774 index +=CODE_TYPE_SIZE;
775
776 switch(code_type)
777 {
778 case NORMAL_CODE :
779 memcpy(me_nw_code_bcd,&(((UBYTE *)personalisation_nw->pBody)[index]),NW_CODE_LEN);
780 index +=NW_CODE_LEN;
781 aci_slock_psaSIM_decodeIMSI(me_nw_code_bcd, NW_CODE_LEN, (char *)imsi_me);
782
783 if(!personalisation)
784 {
785 AciSLockShrd.blocked = memcmp(imsi_sim,imsi_me,simShrdPrm.mnc_len+3/*MCC length*/) NEQ 0;
786 if (AciSLockShrd.blocked EQ FALSE)
787 {
788 return; /* IMSI is matching a personalisation, so break! */
789 }
790 }
791 else
792 {
793 sim_code_present_in_me =memcmp(imsi_sim,imsi_me,simShrdPrm.mnc_len+3/*MCC length*/) EQ 0;
794 if(sim_code_present_in_me EQ TRUE)
795 return;
796 }
797
798 break;
799
800 case INTERVAL_TYPE1 :
801 memcpy(me_nw_code_first_bcd,&(((UBYTE *)personalisation_nw->pBody)[index]),NW_CODE_LEN);
802 index +=NW_CODE_LEN;
803 memcpy(me_nw_code_last_bcd,&(((UBYTE *)personalisation_nw->pBody)[index]),NW_CODE_LEN);
804 index +=NW_CODE_LEN;
805
806 aci_slock_psaSIM_decodeIMSI(me_nw_code_first_bcd, NW_CODE_LEN, (char *)imsi_me);
807 imsi_me[simShrdPrm.mnc_len+3] = '\0'; //to remove trailing F (if any) from imsi_me string
808 me_nw_code_first = atoi((const char *)imsi_me);
809 aci_slock_psaSIM_decodeIMSI(me_nw_code_last_bcd, NW_CODE_LEN, (char *)imsi_me);
810 imsi_me[simShrdPrm.mnc_len+3] = '\0';
811 me_nw_code_last = atoi((const char *)imsi_me);
812
813 memcpy(imsi_sim_temp,imsi_sim,simShrdPrm.mnc_len+3);
814 imsi_sim_temp[simShrdPrm.mnc_len+3] = '\0';
815 sim_nw_code = atoi((const char *)imsi_sim_temp);
816
817 if(!personalisation)
818 {
819 if((sim_nw_code >= me_nw_code_first ) AND (sim_nw_code <= me_nw_code_last))
820 {
821 AciSLockShrd.blocked = FALSE;
822 return ;
823 }
824 else
825 AciSLockShrd.blocked = TRUE;
826 }
827 else
828 {
829 if((sim_nw_code >= me_nw_code_first ) AND (sim_nw_code <= me_nw_code_last))
830 {
831 sim_code_present_in_me = TRUE;
832 return;
833 }
834 }
835 break;
836
837 case REGULAR_EXP :
838 break;
839
840 default :
841 break;
842 }
843 }
844
845 num_user_codes = ((UBYTE *)personalisation_nw->pBody)[index];
846 index +=NUM_USER_CODE_SIZE;
847
848 curr_user_code_index = ((UBYTE *)personalisation_nw->pBody)[index];
849 index +=CURR_USER_CODE_INDEX_SIZE;
850
851 /*
852 * check user defined code-groups
853 */
854 for(i=0; i< num_user_codes; i++)
855 {
856 memcpy(me_nw_code_bcd,&(((UBYTE *)personalisation_nw->pBody)[index]),NW_CODE_LEN);
857 index +=NW_CODE_LEN;
858 aci_slock_psaSIM_decodeIMSI(me_nw_code_bcd, NW_CODE_LEN, (char *)imsi_me);
859
860 if(!personalisation)
861 {
862 AciSLockShrd.blocked = memcmp(imsi_sim,imsi_me,simShrdPrm.mnc_len+3/*MCC length*/) NEQ 0;
863 if (AciSLockShrd.blocked EQ FALSE)
864 return; /* IMSI is matching a personalisation, so break! */
865 }
866 else
867 {
868 sim_code_present_in_me =memcmp(imsi_sim,imsi_me,simShrdPrm.mnc_len+3/*MCC length*/) EQ 0;
869 if(sim_code_present_in_me EQ TRUE)
870 return;
871 }
872 }
873 }
874 }
875
876
877 /*
878 +------------------------------------------------------------------------------
879 | Function : aci_slock_check_NSlock
880 +------------------------------------------------------------------------------
881 | Description : Check IMSI against network subset personalisation
882 |
883 | Parameters : imsi_sim - IMSI
884 | personalisation - 0-add the lock data
885 | 1-verify the existing lock data
886 |
887 | Return : void
888 |
889 +------------------------------------------------------------------------------
890 */
891 void aci_slock_check_NSlock( UBYTE* imsi_sim, UBYTE personalisation )
892 {
893 UBYTE max_num_user_codes;
894 UBYTE num_op_codes;
895 UBYTE curr_user_code_index;
896 UBYTE num_user_codes;
897 UBYTE opcode_len;
898 UBYTE code_type;
899
900
901 UINT16 index =0;
902 UBYTE me_nw_code_bcd[NW_CODE_LEN];
903 UBYTE me_ns_code_bcd[NS_CODE_LEN];
904 UBYTE me_nw_ns_code_bcd[NW_NS_CODE_LEN];
905 UBYTE me_nw_ns_ns_code_bcd[NW_NS_NS_CODE_LEN];
906 UBYTE me_nw_code[MAX_IMSI_LEN+1];
907 UBYTE me_ns_code[2 +1];
908 UBYTE imsi_me[MAX_IMSI_LEN+1];
909 UBYTE me_nw_ns_ns_code_str[6+2+2+1];
910 UBYTE imsi_sim_temp[MAX_IMSI_LEN+1];
911 UBYTE imsi_sim_8or9th_digit_str[1+1] ;
912 UBYTE imsi_sim_ns_code_str[2+1] ;
913 UBYTE no_of_digit_8th_value;
914 UBYTE digit_8th_value;
915 UBYTE no_of_normal_8th_digit_ns_code;
916 UBYTE no_of_interval_8th_digit_ns_code;
917
918
919 int me_ns_code_first,
920 me_ns_code_last,
921 sim_ns_code,
922 sim_8or9th_digit_code,
923 i,j,k;
924
925 TRACE_FUNCTION("aci_slock_check_NSlock()");
926
927 /*
928 personalisation_ns->pBody[0] -----maximum number of user codes
929 personalisation_ns->pBody[1] -----num of operator codes
930 personalisation_ns->pBody[2] -----Operator Code-group length (To be set during configuration)
931 where length = total number of bytes occupied by operator codes
932
933
934 Code type = 0x0a ( Type identifier for normal code)
935 Normal code (Including parity nibble) -- 5 bytes (Nw code + NS code)
936
937 Code type = 0x0b (Type identifier for range)
938 Network code --------- 4 byte
939 Start value of NS code ---- 1 byte
940 End value of NS code -----1 byte
941
942 Code type = 0x0c (Type identifier for regular expression)
943 Regular expression including Network + NS Code -------------8 byte
944
945 Code type = 0x0d
946 (8thdigit normal code/range)
947 Network code (Including parity nibble) ------ 4 byte
948 No. of 8th digit values for which normal codes and/or intervals are to be stored ---- 1 byte
949 8th digit value -- 1 byte
950 No. of normal codes to be associated with the digit (n1) ---- 1 byte
951 No. of intervals to be associated with the digit (n2) ----- 1 byte
952 Normal code 1 --- 1 byte
953 |
954 |
955 |
956 Normal code n1 ---- 1 byte
957
958 Start value of interval 1 ---- 1 byte
959 End value of interval 1 ---- 1 byte
960 |
961 |
962 |
963 Start value of interval n2 ------ 1 byte
964 End value of interval n2 ------- 1 byte
965
966 Number of User Codes ------- 1 byt e
967 Current user code index
968 (for FIFO based addition/deletion of user codes)
969 (should be set to 0xff if no user codes are present) ---- 1 byte
970
971 User code1 ---------- 5 byte
972 User code 2 ---------- 5 byte
973 |
974 |
975 User code n (n = Max number of user codes for NS) -- 5 byte
976
977
978 */
979
980 if(!personalisation)
981 {
982 AciSLockShrd.blocked = TRUE;
983 }
984 else
985 {
986 sim_code_present_in_me = FALSE;
987 }
988 if((personalisation_ns NEQ NULL) AND ((UBYTE *)personalisation_ns->pBody NEQ NULL))
989 {
990 max_num_user_codes = ((UBYTE *)personalisation_ns->pBody)[index];
991 index += MAX_NUM_USERCODE_SIZE;
992
993 num_op_codes =((UBYTE *) personalisation_ns->pBody)[index];
994 index += NUM_OPCODE_SIZE;
995
996 opcode_len = ((UBYTE *)personalisation_ns->pBody)[index];
997 index +=OPCODE_LEN_SIZE;
998
999 /*
1000 * check operator defined code-groups
1001 */
1002 for(i=0; i< num_op_codes; i++)
1003 {
1004 code_type = ((UBYTE *)personalisation_ns->pBody)[index];
1005 index +=CODE_TYPE_SIZE;
1006 switch(code_type)
1007 {
1008 case NORMAL_CODE :
1009 memcpy(me_nw_ns_code_bcd,&(((UBYTE *)personalisation_ns->pBody)[index]),NW_NS_CODE_LEN);
1010 index +=NW_NS_CODE_LEN;
1011 aci_slock_psaSIM_decodeIMSI(me_nw_ns_code_bcd, NW_NS_CODE_LEN, (char *)imsi_me);
1012 if(!personalisation)
1013 {
1014 AciSLockShrd.blocked = memcmp(imsi_sim,imsi_me,simShrdPrm.mnc_len+3/*MCC length*/+2/* NS length */) NEQ 0;
1015 if (AciSLockShrd.blocked EQ FALSE)
1016 {
1017 return; /* IMSI is matching a personalisation, so break! */
1018 }
1019 }
1020 else
1021 {
1022 sim_code_present_in_me =memcmp(imsi_sim,imsi_me,simShrdPrm.mnc_len+3/*MCC length*/+2/* NS length */) EQ 0;
1023 if(sim_code_present_in_me EQ TRUE)
1024 return;
1025 }
1026 break;
1027
1028 case INTERVAL_TYPE1 :
1029 memcpy(me_nw_ns_ns_code_bcd,&(((UBYTE *)personalisation_ns->pBody)[index]),NW_NS_NS_CODE_LEN);
1030 index +=NW_NS_NS_CODE_LEN;
1031 aci_slock_psaSIM_decodeIMSI(me_nw_ns_ns_code_bcd, NW_NS_NS_CODE_LEN, (char *)me_nw_ns_ns_code_str);
1032 memcpy(me_nw_code,me_nw_ns_ns_code_str,simShrdPrm.mnc_len+3);
1033
1034 if(!personalisation)
1035 {
1036 AciSLockShrd.blocked = memcmp(imsi_sim,me_nw_code,simShrdPrm.mnc_len+3/*MCC length*/) NEQ 0;
1037 if (AciSLockShrd.blocked EQ FALSE)
1038 {
1039 memcpy(me_ns_code,me_nw_ns_ns_code_str+7/*skip the 'F'*/,2);
1040 me_ns_code[2] = '\0';
1041 me_ns_code_first = atoi((const char *)me_ns_code);
1042
1043 memcpy(me_ns_code,me_nw_ns_ns_code_str+7+2/*skip the 'F'*/,2);
1044 me_ns_code[2] = '\0';
1045 me_ns_code_last = atoi((const char *)me_ns_code);
1046
1047 memcpy(imsi_sim_temp,imsi_sim+simShrdPrm.mnc_len+3,2);
1048 imsi_sim_temp[2] = '\0';
1049 sim_ns_code = atoi((const char *)imsi_sim_temp);
1050 if((sim_ns_code >= me_ns_code_first ) AND (sim_ns_code <= me_ns_code_last))
1051 {
1052 AciSLockShrd.blocked = FALSE;
1053 return ;
1054 }
1055 else
1056 AciSLockShrd.blocked = TRUE;
1057 }
1058 }
1059 else
1060 {
1061 sim_code_present_in_me= memcmp(imsi_sim,me_nw_code,simShrdPrm.mnc_len+3/*MCC length*/) EQ 0;
1062 if(sim_code_present_in_me EQ TRUE)
1063 {
1064 sim_code_present_in_me = FALSE;
1065 memcpy(me_ns_code,me_nw_ns_ns_code_str+7/*skip the 'F'*/,2);
1066 me_ns_code[2] = '\0';
1067 me_ns_code_first = atoi((const char *)me_ns_code);
1068
1069 memcpy(me_ns_code,me_nw_ns_ns_code_str+7+2/*skip the 'F'*/,2);
1070 me_ns_code[2] = '\0';
1071 me_ns_code_last = atoi((const char *)me_ns_code);
1072
1073 memcpy(imsi_sim_temp,imsi_sim+simShrdPrm.mnc_len+3,2);
1074 imsi_sim_temp[2] = '\0';
1075 sim_ns_code = atoi((const char *)imsi_sim_temp);
1076 if((sim_ns_code >= me_ns_code_first ) AND (sim_ns_code <= me_ns_code_last))
1077 {
1078 sim_code_present_in_me =TRUE;
1079 return;
1080 }
1081 }
1082 }
1083
1084 break;
1085
1086 case INTERVAL_TYPE2 :
1087 TRACE_FUNCTION("INTERVAL_TYPE2");
1088 memcpy(me_nw_code_bcd,&(((UBYTE *)personalisation_ns->pBody)[index]),NW_CODE_LEN);
1089 index +=NW_CODE_LEN;
1090 aci_slock_psaSIM_decodeIMSI(me_nw_code_bcd, NW_CODE_LEN, (char *)me_nw_code);
1091 no_of_digit_8th_value = ((UBYTE *)personalisation_ns->pBody)[index] ;
1092 index += 1;
1093
1094 if(!personalisation)
1095 {
1096 AciSLockShrd.blocked = memcmp(imsi_sim,me_nw_code,simShrdPrm.mnc_len+3/*MCC length*/) NEQ 0;
1097 if (AciSLockShrd.blocked EQ FALSE)
1098 {
1099 AciSLockShrd.blocked = TRUE;
1100
1101 imsi_sim_8or9th_digit_str[0] = imsi_sim[simShrdPrm.mnc_len+3+2] ;
1102 imsi_sim_8or9th_digit_str[1] ='\0';
1103 sim_8or9th_digit_code = atoi((const char *)imsi_sim_8or9th_digit_str);
1104
1105 for(j=0; j <no_of_digit_8th_value; j++ )
1106 {
1107 digit_8th_value = ((UBYTE *)personalisation_ns->pBody)[index] ;
1108 index += 1;
1109 no_of_normal_8th_digit_ns_code = ((UBYTE *)personalisation_ns->pBody)[index] ;
1110 index += 1;
1111 no_of_interval_8th_digit_ns_code = ((UBYTE *)personalisation_ns->pBody)[index] ;
1112 index += 1;
1113 if(sim_8or9th_digit_code EQ digit_8th_value)
1114 {
1115 for(k =0; k < no_of_normal_8th_digit_ns_code; k++)
1116 {
1117 memcpy(me_ns_code_bcd,&(((UBYTE *)personalisation_ns->pBody)[index]),NS_CODE_LEN);
1118 index += NS_CODE_LEN;
1119 aci_slock_psaSIM_decodeIMSI_without_parity(me_ns_code_bcd, NS_CODE_LEN, (char *)me_ns_code);
1120 AciSLockShrd.blocked = memcmp(imsi_sim+simShrdPrm.mnc_len+3,me_ns_code,2) NEQ 0;
1121 if(AciSLockShrd.blocked EQ FALSE)
1122 return ;
1123 }
1124 if(AciSLockShrd.blocked EQ TRUE)
1125 {
1126 for(k =0; k < no_of_interval_8th_digit_ns_code; k++)
1127 {
1128 memcpy(me_ns_code_bcd,&(((UBYTE *)personalisation_ns->pBody)[index]),NS_CODE_LEN);
1129 index += NS_CODE_LEN;
1130 aci_slock_psaSIM_decodeIMSI_without_parity(me_ns_code_bcd, NS_CODE_LEN, (char *)me_ns_code);
1131 me_ns_code[2] = '\0';
1132 me_ns_code_first = atoi((const char *)me_ns_code);
1133
1134 memcpy(me_ns_code_bcd,&(((UBYTE *)personalisation_ns->pBody)[index]),NS_CODE_LEN);
1135 index += NS_CODE_LEN;
1136 aci_slock_psaSIM_decodeIMSI_without_parity(me_ns_code_bcd, NS_CODE_LEN, (char *)me_ns_code);
1137 me_ns_code[2] = '\0';
1138 me_ns_code_last = atoi((const char *)me_ns_code);
1139
1140 memcpy(imsi_sim_ns_code_str,&imsi_sim[simShrdPrm.mnc_len+3],2);
1141 imsi_sim_ns_code_str[2] = '\0';
1142 sim_ns_code = atoi((const char *)imsi_sim_ns_code_str);
1143
1144 if((sim_ns_code >= me_ns_code_first) AND (sim_ns_code <= me_ns_code_last) )
1145 {
1146 AciSLockShrd.blocked = FALSE;
1147 return ;
1148 }
1149 else
1150 AciSLockShrd.blocked = TRUE;
1151 }
1152 }
1153 }
1154 else
1155 index += (NS_CODE_LEN*no_of_normal_8th_digit_ns_code +2*NS_CODE_LEN*no_of_interval_8th_digit_ns_code ) ;
1156 }
1157 }
1158 }
1159 else
1160 {
1161 sim_code_present_in_me = memcmp(imsi_sim,me_nw_code,simShrdPrm.mnc_len+3/*MCC length*/) EQ 0;
1162 if (sim_code_present_in_me EQ TRUE)
1163 {
1164 sim_code_present_in_me = FALSE;
1165 imsi_sim_8or9th_digit_str[0] = imsi_sim[simShrdPrm.mnc_len+3+2] ;
1166 imsi_sim_8or9th_digit_str[1] ='\0';
1167 sim_8or9th_digit_code = atoi((const char *)imsi_sim_8or9th_digit_str);
1168
1169 for(j=0; j <no_of_digit_8th_value; j++ )
1170 {
1171 digit_8th_value = ((UBYTE *)personalisation_ns->pBody)[index] ;
1172 index += 1;
1173 no_of_normal_8th_digit_ns_code = ((UBYTE *)personalisation_ns->pBody)[index] ;
1174 index += 1;
1175 no_of_interval_8th_digit_ns_code = ((UBYTE *)personalisation_ns->pBody)[index] ;
1176 index += 1;
1177
1178 if(sim_8or9th_digit_code EQ digit_8th_value)
1179 {
1180 for(k =0; k < no_of_normal_8th_digit_ns_code; k++)
1181 {
1182 memcpy(me_ns_code_bcd,&(((UBYTE *)personalisation_ns->pBody)[index]),NS_CODE_LEN);
1183 index += NS_CODE_LEN;
1184 aci_slock_psaSIM_decodeIMSI_without_parity(me_ns_code_bcd, NS_CODE_LEN, (char *)me_ns_code);
1185 sim_code_present_in_me = memcmp(imsi_sim+simShrdPrm.mnc_len+3,me_ns_code,2) EQ 0;
1186 if(sim_code_present_in_me EQ TRUE)
1187 return ;
1188 }
1189 if(sim_code_present_in_me EQ FALSE)
1190 {
1191 for(k =0; k < no_of_interval_8th_digit_ns_code; k++)
1192 {
1193 memcpy(me_ns_code_bcd,&(((UBYTE *)personalisation_ns->pBody)[index]),NS_CODE_LEN);
1194 index += NS_CODE_LEN;
1195 aci_slock_psaSIM_decodeIMSI_without_parity(me_ns_code_bcd, NS_CODE_LEN, (char *)me_ns_code);
1196 me_ns_code[2] = '\0';
1197 me_ns_code_first = atoi((const char *)me_ns_code);
1198
1199 memcpy(me_ns_code_bcd,&(((UBYTE *)personalisation_ns->pBody)[index]),NS_CODE_LEN);
1200 index += NS_CODE_LEN;
1201 aci_slock_psaSIM_decodeIMSI_without_parity(me_ns_code_bcd, NS_CODE_LEN, (char *)me_ns_code);
1202 me_ns_code[2] = '\0';
1203 me_ns_code_last = atoi((const char *)me_ns_code);
1204
1205 memcpy(imsi_sim_ns_code_str,&imsi_sim[simShrdPrm.mnc_len+3],2);
1206 imsi_sim_ns_code_str[2] = '\0';
1207 sim_ns_code = atoi((const char *)imsi_sim_ns_code_str);
1208
1209 if((sim_ns_code >= me_ns_code_first) AND (sim_ns_code <= me_ns_code_last) )
1210 {
1211 sim_code_present_in_me = TRUE;
1212 return ;
1213 }
1214 else
1215 sim_code_present_in_me = FALSE;
1216 }
1217 }
1218 }
1219 else
1220 index += (NS_CODE_LEN*no_of_normal_8th_digit_ns_code +2*NS_CODE_LEN*no_of_interval_8th_digit_ns_code ) ;
1221 }
1222 }
1223 }
1224 break;
1225
1226 case REGULAR_EXP :
1227 break;
1228
1229 default :
1230 break;
1231 }
1232 }
1233
1234 num_user_codes = ((UBYTE *)personalisation_ns->pBody)[index];
1235 index +=NUM_USER_CODE_SIZE;
1236
1237 curr_user_code_index = ((UBYTE *)personalisation_ns->pBody)[index];
1238 index +=CURR_USER_CODE_INDEX_SIZE;
1239
1240 /*
1241 * check user defined code-groups
1242 */
1243 for(i=0; i< num_user_codes; i++)
1244 {
1245 memcpy(me_nw_ns_code_bcd,&(((UBYTE *)personalisation_ns->pBody)[index]),NW_NS_CODE_LEN);
1246 index +=NW_NS_CODE_LEN;
1247 aci_slock_psaSIM_decodeIMSI(me_nw_ns_code_bcd, NW_NS_CODE_LEN, (char *)imsi_me);
1248 if(!personalisation)
1249 {
1250 AciSLockShrd.blocked = memcmp(imsi_sim,imsi_me,simShrdPrm.mnc_len+3/*MCC length*/+2/* NS length */) NEQ 0; // F is not expected here
1251 if (AciSLockShrd.blocked EQ FALSE)
1252 {
1253 return; /* IMSI is matching a personalisation, so break! */
1254 }
1255 }
1256 else
1257 {
1258 sim_code_present_in_me= memcmp(imsi_sim,imsi_me,simShrdPrm.mnc_len+3/*MCC length*/+2/* NS length */) EQ 0; // F is not expected here
1259 if(sim_code_present_in_me EQ TRUE)
1260 {
1261 return;
1262 }
1263 }
1264 }
1265 }
1266 }
1267
1268
1269 /*
1270 +------------------------------------------------------------------------------
1271 | Function : aci_slock_check_SPlock
1272 +------------------------------------------------------------------------------
1273 | Description : Check IMSI against service provider personalisation
1274 |
1275 | Parameters : imsi_sim - IMSI
1276 | personalisation - 0-add the lock data
1277 | 1-verify the existing lock data
1278 |
1279 | Return : void
1280 |
1281 +------------------------------------------------------------------------------
1282 */
1283 void aci_slock_check_SPlock( UBYTE* imsi_sim, UBYTE personalisation )
1284 {
1285 UBYTE max_num_user_codes;
1286 UBYTE num_op_codes;
1287 UBYTE curr_user_code_index;
1288 UBYTE num_user_codes;
1289 UBYTE opcode_len;
1290 UBYTE code_type;
1291
1292 UINT16 index =0;
1293 UBYTE me_nw_code_bcd[NW_CODE_LEN];
1294 UBYTE imsi_me[MAX_IMSI_LEN+1];
1295 UBYTE me_gid1_str[GID1_LEN+1];
1296 UBYTE sim_gid1_str[GID1_LEN+1];
1297
1298 int me_gid1_first,
1299 me_gid1_last,
1300 sim_gid1,
1301 i;
1302
1303 TRACE_FUNCTION("aci_slock_check_SPlock()");
1304
1305 if((aci_slock_sim_config.sim_gidl1[0] EQ NOT_PRESENT_8BIT) OR (aci_slock_sim_config.gid1_len NEQ cfg_data->GID1_Len))
1306 {
1307
1308 TRACE_FUNCTION_P1("aci_slock_sim_config.sim_gidl1[0] %d", aci_slock_sim_config.sim_gidl1[0]);
1309 if(!personalisation)
1310 {
1311 AciSLockShrd.blocked = TRUE;
1312 }
1313 else
1314 {
1315 sim_code_present_in_me = CHECK_FAIL;
1316 }
1317 return;
1318 }
1319 else
1320 {
1321
1322
1323 /*
1324 personalisation_sp->pBody[0] -----maximum number of user codes
1325 personalisation_sp->pBody[1] -----num of operator codes
1326 personalisation_sp->pBody[2] -----Operator Code-group length (To be set during configuration)
1327 where length = total number of bytes occupied by operator codes
1328
1329
1330 Code type = 0x0a ( Type identifier for normal code)
1331 Normal code (Including parity nibble) -- 8 bytes (Network code + GID1 value)
1332
1333 Code type = 0x0b (Type identifier for range)
1334 Network code --------- 4 byte
1335 Start GID1 ---- -------4 byte
1336 End GID1 -------------4 byte
1337
1338 Code type = 0x0c (Type identifier for regular expression)
1339 Regular Expression (including NW code and GID1 value) --- 10 byte
1340
1341 Number of User Codes ------- 1 byt e
1342 Current user code index
1343 (for FIFO based addition/deletion of user codes)
1344 (should be set to 0xff if no user codes are present) ---- 1 byte
1345
1346 User code1 ---------- 8 byte
1347 User code 2 ---------- 8 byte
1348 |
1349 |
1350 User code n (n = Max number of user codes for NS) -- 8 byte
1351
1352
1353 */
1354 if(!personalisation)
1355 {
1356 AciSLockShrd.blocked = TRUE;
1357 }
1358 else
1359 {
1360 sim_code_present_in_me = FALSE;
1361 }
1362 if((personalisation_sp NEQ NULL) AND ((UBYTE *)personalisation_sp->pBody NEQ NULL))
1363 {
1364 max_num_user_codes = ((UBYTE *)personalisation_sp->pBody)[index];
1365 index += MAX_NUM_USERCODE_SIZE;
1366
1367 num_op_codes = ((UBYTE *)personalisation_sp->pBody)[index];
1368 index += NUM_OPCODE_SIZE;
1369
1370 opcode_len = ((UBYTE *)personalisation_sp->pBody)[index];
1371 index +=OPCODE_LEN_SIZE;
1372
1373 /*
1374 * check operator defined code-groups
1375 */
1376 for(i=0; i< num_op_codes; i++)
1377 {
1378 code_type = ((UBYTE *)personalisation_sp->pBody)[index];
1379 index +=CODE_TYPE_SIZE;
1380 switch(code_type)
1381 {
1382 case NORMAL_CODE :
1383 memcpy(me_nw_code_bcd,&(((UBYTE *)personalisation_sp->pBody)[index]),NW_CODE_LEN);
1384 index +=NW_CODE_LEN;
1385 aci_slock_psaSIM_decodeIMSI(me_nw_code_bcd, NW_CODE_LEN, (char *)imsi_me);
1386 if(!personalisation)
1387 {
1388 AciSLockShrd.blocked = memcmp(imsi_sim,imsi_me,simShrdPrm.mnc_len+3/*MCC length*/) NEQ 0;
1389 if (AciSLockShrd.blocked EQ FALSE)
1390 {
1391 if (psaSIM_ChkSIMSrvSup(SRV_GrpLvl1))
1392 {
1393 memcpy(me_gid1_str,&(((UBYTE *)personalisation_sp->pBody)[index]),GID1_LEN);
1394 index +=GID1_LEN;
1395 AciSLockShrd.blocked = memcmp(aci_slock_sim_config.sim_gidl1,me_gid1_str,cfg_data->GID1_Len/*GID1_LEN*/) NEQ 0;
1396 if (AciSLockShrd.blocked EQ FALSE)
1397 {
1398 return;
1399 }
1400 }
1401 else
1402 AciSLockShrd.blocked = TRUE;
1403 }
1404 }
1405 else
1406 {
1407 sim_code_present_in_me= memcmp(imsi_sim,imsi_me,simShrdPrm.mnc_len+3/*MCC length*/) EQ 0;
1408 if(sim_code_present_in_me EQ TRUE)
1409 {
1410 sim_code_present_in_me = FALSE;
1411 if (psaSIM_ChkSIMSrvSup(SRV_GrpLvl1))
1412 {
1413 memcpy(me_gid1_str,&(((UBYTE *)personalisation_sp->pBody)[index]),GID1_LEN);
1414 index +=GID1_LEN;
1415 sim_code_present_in_me = memcmp(aci_slock_sim_config.sim_gidl1,me_gid1_str,cfg_data->GID1_Len) EQ 0;
1416 if (sim_code_present_in_me EQ TRUE)
1417 {
1418 return;
1419 }
1420 }
1421 }
1422 }
1423 break;
1424
1425 case INTERVAL_TYPE1 :
1426 memcpy(me_nw_code_bcd,&(((UBYTE *)personalisation_sp->pBody)[index]),NW_CODE_LEN);
1427 index +=NW_CODE_LEN;
1428 aci_slock_psaSIM_decodeIMSI(me_nw_code_bcd, NW_CODE_LEN, (char *)imsi_me);
1429
1430 if(!personalisation)
1431 {
1432 AciSLockShrd.blocked = memcmp(imsi_sim,imsi_me,simShrdPrm.mnc_len+3/*MCC length*/) NEQ 0;
1433 if (AciSLockShrd.blocked EQ FALSE)
1434 {
1435 if (psaSIM_ChkSIMSrvSup(SRV_GrpLvl1))
1436 {
1437 memcpy(me_gid1_str,&(((UBYTE *)personalisation_sp->pBody)[index]),GID1_LEN);
1438 index +=GID1_LEN;
1439 me_gid1_str[GID1_LEN] ='\0';
1440 me_gid1_first = atoi((const char *)me_gid1_str);
1441
1442 memcpy(me_gid1_str,&(((UBYTE *)personalisation_sp->pBody)[index]),GID1_LEN);
1443 index +=GID1_LEN;
1444 me_gid1_str[GID1_LEN] ='\0';
1445 me_gid1_last = atoi((const char *)me_gid1_str);
1446 memcpy(sim_gid1_str,aci_slock_sim_config.sim_gidl1,GID1_LEN);
1447 sim_gid1_str[GID1_LEN] = '\0';
1448 sim_gid1 = atoi((const char *)sim_gid1_str);
1449
1450 if((sim_gid1 >= me_gid1_first) AND (sim_gid1 <= me_gid1_last))
1451 {
1452 AciSLockShrd.blocked = FALSE;
1453 return ;
1454 }
1455 else
1456 AciSLockShrd.blocked = TRUE;
1457 }
1458 else
1459 AciSLockShrd.blocked = TRUE;
1460 }
1461 }
1462 else
1463 {
1464 sim_code_present_in_me= memcmp(imsi_sim,imsi_me,simShrdPrm.mnc_len+3/*MCC length*/) EQ 0;
1465 if (sim_code_present_in_me EQ TRUE)
1466 {
1467 sim_code_present_in_me = FALSE;
1468 if (psaSIM_ChkSIMSrvSup(SRV_GrpLvl1))
1469 {
1470 memcpy(me_gid1_str,&(((UBYTE *)personalisation_sp->pBody)[index]),GID1_LEN);
1471 index +=GID1_LEN;
1472 me_gid1_str[GID1_LEN] ='\0';
1473 me_gid1_first = atoi((const char *)me_gid1_str);
1474
1475
1476 memcpy(me_gid1_str,&(((UBYTE *)personalisation_sp->pBody)[index]),GID1_LEN);
1477 index +=GID1_LEN;
1478 me_gid1_str[GID1_LEN] ='\0';
1479 me_gid1_last = atoi((const char *)me_gid1_str);
1480 memcpy(sim_gid1_str,aci_slock_sim_config.sim_gidl1,GID1_LEN);
1481 sim_gid1_str[GID1_LEN] = '\0';
1482 sim_gid1 = atoi((const char *)sim_gid1_str);
1483
1484 if((sim_gid1 >= me_gid1_first) AND (sim_gid1 <= me_gid1_last))
1485 {
1486 sim_code_present_in_me = TRUE;
1487 return ;
1488 }
1489 }
1490 }
1491 }
1492 break;
1493
1494 case REGULAR_EXP :
1495 break;
1496 default :
1497 break;
1498 }
1499 }
1500
1501 num_user_codes = ((UBYTE *)personalisation_sp->pBody)[index];
1502 index +=NUM_USER_CODE_SIZE;
1503
1504 curr_user_code_index =((UBYTE *) personalisation_sp->pBody)[index];
1505 index +=CURR_USER_CODE_INDEX_SIZE;
1506
1507
1508 /*
1509 * check user defined code-groups
1510 */
1511 for(i=0; i< num_user_codes; i++)
1512 {
1513 memcpy(me_nw_code_bcd,&(((UBYTE *)personalisation_sp->pBody)[index]),NW_CODE_LEN);
1514 index +=NW_CODE_LEN;
1515 aci_slock_psaSIM_decodeIMSI(me_nw_code_bcd, NW_CODE_LEN, (char *)imsi_me);
1516 if(!personalisation)
1517 {
1518 AciSLockShrd.blocked = memcmp(imsi_sim,imsi_me,simShrdPrm.mnc_len+3/*MCC length*/) NEQ 0;
1519 if (AciSLockShrd.blocked EQ FALSE)
1520 {
1521 if (psaSIM_ChkSIMSrvSup(SRV_GrpLvl1))
1522 {
1523 memcpy(me_gid1_str,&(((UBYTE *)personalisation_sp->pBody)[index]),GID1_LEN);
1524 index +=GID1_LEN;
1525 AciSLockShrd.blocked = memcmp(aci_slock_sim_config.sim_gidl1,me_gid1_str,cfg_data->GID1_Len) NEQ 0;
1526 if (AciSLockShrd.blocked EQ FALSE)
1527 {
1528 return;
1529 }
1530 }
1531 else
1532 AciSLockShrd.blocked = TRUE;
1533 }
1534 }
1535 else
1536 {
1537 sim_code_present_in_me = memcmp(imsi_sim,imsi_me,simShrdPrm.mnc_len+3/*MCC length*/) EQ 0;
1538 if (sim_code_present_in_me EQ TRUE)
1539 {
1540 sim_code_present_in_me = FALSE;
1541 if (psaSIM_ChkSIMSrvSup(SRV_GrpLvl1))
1542 {
1543 memcpy(me_gid1_str,&(((UBYTE *)personalisation_sp->pBody)[index]),GID1_LEN);
1544 index +=GID1_LEN;
1545 sim_code_present_in_me= memcmp(aci_slock_sim_config.sim_gidl1,me_gid1_str,cfg_data->GID1_Len) EQ 0;
1546 if (sim_code_present_in_me EQ TRUE)
1547 {
1548 return;
1549 }
1550 }
1551 }
1552 }
1553 }
1554 }
1555 }
1556 }
1557
1558
1559 /*
1560 +------------------------------------------------------------------------------
1561 | Function : aci_slock_check_CPlock
1562 +------------------------------------------------------------------------------
1563 | Description : Check IMSI against service corporate personalisation
1564 |
1565 | Parameters : imsi_sim - IMSI
1566 | personalisation - 0-add the lock data
1567 | 1-verify the existing lock data
1568 |
1569 | Return : void
1570 |
1571 +------------------------------------------------------------------------------
1572 */
1573 void aci_slock_check_CPlock( UBYTE* imsi_sim, UBYTE personalisation)
1574 {
1575 UBYTE max_num_user_codes;
1576 UBYTE num_op_codes;
1577 UBYTE curr_user_code_index;
1578 UBYTE num_user_codes;
1579 UBYTE opcode_len;
1580
1581 UBYTE code_type;
1582
1583 UINT16 index =0;
1584 UBYTE me_nw_code_bcd[NW_CODE_LEN];
1585 UBYTE imsi_me[MAX_IMSI_LEN+1];
1586 UBYTE me_gid1_str[GID1_LEN+1];
1587 UBYTE me_gid2_str[GID2_LEN+1];
1588 UBYTE sim_gid2_str[GID2_LEN+1];
1589
1590 int me_gid2_first,
1591 me_gid2_last,
1592 sim_gid2,
1593 i;
1594
1595 TRACE_FUNCTION("aci_slock_check_CPlock()");
1596
1597
1598
1599 if((aci_slock_sim_config.sim_gidl1[0] EQ NOT_PRESENT_8BIT) OR (aci_slock_sim_config.sim_gidl2[0] EQ NOT_PRESENT_8BIT)
1600 OR (aci_slock_sim_config.gid1_len NEQ cfg_data->GID1_Len) OR (aci_slock_sim_config.gid2_len NEQ cfg_data->GID2_Len))
1601 {
1602 if(!personalisation)
1603 {
1604 AciSLockShrd.blocked = TRUE;
1605 }
1606 else
1607 {
1608 sim_code_present_in_me = CHECK_FAIL;
1609 }
1610 return;
1611 }
1612 else
1613 {
1614
1615
1616 /*
1617 personalisation_cp->pBody[0] -----maximum number of user codes
1618 personalisation_cp->pBody[1] -----num of operator codes
1619 personalisation_cp->pBody[2] -----Operator Code-group length (To be set during configuration)
1620 where length = total number of bytes occupied by operator codes
1621
1622
1623 Code type = 0x0a ( Type identifier for normal code)
1624 Normal code (Including parity nibble) -- 12 bytes (Network code + GID1 value + GID2 value)
1625
1626 Code type = 0x0b (Type identifier for range)
1627 Network code --------- 4 byte
1628 GID1 value------------4 byte
1629 Start GID1 ---- -------4 byte
1630 End GID1 -------------4 byte
1631
1632 Code type = 0x0c (Type identifier for regular expression)
1633 Regular Expression (including NW code, GID1 value and GID2 value) --- 14 byte
1634
1635 Number of User Codes ------- 1 byt e
1636 Current user code index
1637 (for FIFO based addition/deletion of user codes)
1638 (should be set to 0xff if no user codes are present) ---- 1 byte
1639
1640 User code1 ---------- 12 byte
1641 User code 2 ---------- 12 byte
1642 |
1643 |
1644 User code n (n = Max number of user codes for NS) -- 12 byte
1645
1646
1647 */
1648 if(!personalisation)
1649 {
1650 AciSLockShrd.blocked = TRUE;
1651 }
1652 else
1653 {
1654 sim_code_present_in_me = FALSE;
1655 }
1656 if((personalisation_cp NEQ NULL) AND ((UBYTE *)personalisation_cp->pBody NEQ NULL))
1657 {
1658 max_num_user_codes = ((UBYTE *)personalisation_cp->pBody)[index];
1659 index += MAX_NUM_USERCODE_SIZE;
1660
1661 num_op_codes = ((UBYTE *)personalisation_cp->pBody)[index];
1662 index += NUM_OPCODE_SIZE;
1663
1664 opcode_len = ((UBYTE *)personalisation_cp->pBody)[index];
1665 index +=OPCODE_LEN_SIZE;
1666 /*
1667 * check operator defined code-groups
1668 */
1669 for(i=0; i< num_op_codes; i++)
1670 {
1671 code_type = ((UBYTE *)personalisation_cp->pBody)[index];
1672 index +=CODE_TYPE_SIZE;
1673 switch(code_type)
1674 {
1675 case NORMAL_CODE :
1676 memcpy(me_nw_code_bcd,&(((UBYTE *)personalisation_cp->pBody)[index]),NW_CODE_LEN);
1677 index +=NW_CODE_LEN;
1678 aci_slock_psaSIM_decodeIMSI(me_nw_code_bcd, NW_CODE_LEN, (char *)imsi_me);
1679
1680 if(!personalisation)
1681 {
1682 AciSLockShrd.blocked = memcmp(imsi_sim,imsi_me,simShrdPrm.mnc_len+3/*MCC length*/) NEQ 0;
1683 if (AciSLockShrd.blocked EQ FALSE)
1684 {
1685 if (psaSIM_ChkSIMSrvSup(SRV_GrpLvl1))
1686 {
1687 memcpy(me_gid1_str,&(((UBYTE *)personalisation_cp->pBody)[index]),GID1_LEN);
1688 index +=GID1_LEN;
1689 AciSLockShrd.blocked = memcmp(aci_slock_sim_config.sim_gidl1,me_gid1_str,cfg_data->GID1_Len) NEQ 0;
1690 if (AciSLockShrd.blocked EQ FALSE)
1691 {
1692 if (psaSIM_ChkSIMSrvSup(SRV_GrpLvl2))
1693 {
1694 memcpy(me_gid2_str,&(((UBYTE *)personalisation_cp->pBody)[index]),GID2_LEN);
1695 index +=GID2_LEN;
1696 AciSLockShrd.blocked = memcmp(aci_slock_sim_config.sim_gidl2,me_gid2_str,cfg_data->GID2_Len) NEQ 0;
1697 if (AciSLockShrd.blocked EQ FALSE)
1698 {
1699 return;
1700 }
1701 }
1702 else
1703 AciSLockShrd.blocked = TRUE;
1704 }
1705 }
1706 else
1707 AciSLockShrd.blocked = TRUE;
1708 }
1709 }
1710 else
1711 {
1712 sim_code_present_in_me = memcmp(imsi_sim,imsi_me,simShrdPrm.mnc_len+3/*MCC length*/) EQ 0;
1713 if(sim_code_present_in_me EQ TRUE)
1714 {
1715 sim_code_present_in_me = FALSE;
1716 if (psaSIM_ChkSIMSrvSup(SRV_GrpLvl1))
1717 {
1718 memcpy(me_gid1_str,&(((UBYTE *)personalisation_cp->pBody)[index]),GID1_LEN);
1719 index +=GID1_LEN;
1720 sim_code_present_in_me = memcmp(aci_slock_sim_config.sim_gidl1,me_gid1_str,cfg_data->GID1_Len) EQ 0;
1721 if (sim_code_present_in_me EQ TRUE)
1722 {
1723 sim_code_present_in_me = FALSE;
1724 if (psaSIM_ChkSIMSrvSup(SRV_GrpLvl2))
1725 {
1726 memcpy(me_gid2_str,&(((UBYTE *)personalisation_cp->pBody)[index]),GID2_LEN);
1727 index +=GID2_LEN;
1728 sim_code_present_in_me = memcmp(aci_slock_sim_config.sim_gidl2,me_gid2_str,cfg_data->GID2_Len) EQ 0;
1729 if (sim_code_present_in_me EQ TRUE)
1730 {
1731 return;
1732 }
1733 }
1734 }
1735 }
1736 }
1737 }
1738 break;
1739
1740 case INTERVAL_TYPE1 :
1741 memcpy(me_nw_code_bcd,&(((UBYTE *)personalisation_cp->pBody)[index]),NW_CODE_LEN);
1742 index +=NW_CODE_LEN;
1743 aci_slock_psaSIM_decodeIMSI(me_nw_code_bcd, NW_CODE_LEN, (char *)imsi_me);
1744
1745 if(!personalisation)
1746 {
1747 AciSLockShrd.blocked = memcmp(imsi_sim,imsi_me,simShrdPrm.mnc_len+3/*MCC length*/) NEQ 0;
1748
1749 if (AciSLockShrd.blocked EQ FALSE)
1750 {
1751 if (psaSIM_ChkSIMSrvSup(SRV_GrpLvl1))
1752 {
1753 memcpy(me_gid1_str,&(((UBYTE *)personalisation_cp->pBody)[index]),GID1_LEN);
1754 index +=GID1_LEN;
1755 AciSLockShrd.blocked = memcmp(aci_slock_sim_config.sim_gidl1,me_gid1_str,cfg_data->GID1_Len) NEQ 0;
1756
1757 if (AciSLockShrd.blocked EQ FALSE)
1758 {
1759 if (psaSIM_ChkSIMSrvSup(SRV_GrpLvl2))
1760 {
1761 memcpy(me_gid2_str,&(((UBYTE *)personalisation_cp->pBody)[index]),GID2_LEN);
1762 index +=GID2_LEN;
1763 me_gid2_str[GID2_LEN] ='\0';
1764 me_gid2_first = atoi((const char *)me_gid2_str);
1765
1766 memcpy(me_gid2_str,&(((UBYTE *)personalisation_cp->pBody)[index]),GID2_LEN);
1767 index +=GID2_LEN;
1768 me_gid2_str[GID2_LEN] ='\0';
1769 me_gid2_last = atoi((const char *)me_gid2_str);
1770
1771 memcpy(sim_gid2_str,aci_slock_sim_config.sim_gidl2,GID1_LEN);
1772 sim_gid2_str[GID2_LEN] = '\0';
1773 sim_gid2 = atoi((const char *)sim_gid2_str);
1774 if((sim_gid2 >= me_gid2_first) AND (sim_gid2 <= me_gid2_last))
1775 {
1776 AciSLockShrd.blocked = FALSE;
1777 return ;
1778 }
1779 else
1780 AciSLockShrd.blocked = TRUE;
1781 }
1782 else
1783 AciSLockShrd.blocked = TRUE;
1784 }
1785 }
1786 else
1787 AciSLockShrd.blocked = TRUE;
1788 }
1789 }
1790 else
1791 {
1792 sim_code_present_in_me = memcmp(imsi_sim,imsi_me,simShrdPrm.mnc_len+3/*MCC length*/) EQ 0;
1793 if (sim_code_present_in_me EQ TRUE)
1794 {
1795 sim_code_present_in_me = FALSE;
1796 if (psaSIM_ChkSIMSrvSup(SRV_GrpLvl1))
1797 {
1798 memcpy(me_gid1_str,&(((UBYTE *)personalisation_cp->pBody)[index]),GID1_LEN);
1799 index +=GID1_LEN;
1800 sim_code_present_in_me= memcmp(aci_slock_sim_config.sim_gidl1,me_gid1_str,cfg_data->GID1_Len) EQ 0;
1801 if (sim_code_present_in_me EQ TRUE)
1802 {
1803 sim_code_present_in_me = FALSE;
1804 if (psaSIM_ChkSIMSrvSup(SRV_GrpLvl2))
1805 {
1806 memcpy(me_gid2_str,&(((UBYTE *)personalisation_cp->pBody)[index]),GID2_LEN);
1807 index +=GID2_LEN;
1808 me_gid2_str[GID2_LEN] ='\0';
1809 me_gid2_first = atoi((const char *)me_gid2_str);
1810
1811 memcpy(me_gid2_str,&(((UBYTE *)personalisation_cp->pBody)[index]),GID2_LEN);
1812 index +=GID2_LEN;
1813 me_gid2_str[GID2_LEN] ='\0';
1814 me_gid2_last = atoi((const char *)me_gid2_str);
1815
1816 memcpy(sim_gid2_str,aci_slock_sim_config.sim_gidl2,GID1_LEN);
1817 sim_gid2_str[GID2_LEN] = '\0';
1818 sim_gid2 = atoi((const char *)sim_gid2_str);
1819 if((sim_gid2 >= me_gid2_first) AND (sim_gid2 <= me_gid2_last))
1820 {
1821 sim_code_present_in_me = TRUE;
1822 }
1823 }
1824 }
1825 }
1826 }
1827 }
1828 break;
1829
1830 case REGULAR_EXP :
1831 break;
1832
1833 default :
1834 break;
1835 }
1836 }
1837
1838 num_user_codes = ((UBYTE *)personalisation_cp->pBody)[index];
1839 index +=NUM_USER_CODE_SIZE;
1840
1841 curr_user_code_index =((UBYTE *) personalisation_cp->pBody)[index];
1842 index +=CURR_USER_CODE_INDEX_SIZE;
1843
1844
1845 /*
1846 * check user defined code-groups
1847 */
1848 for(i=0; i< num_user_codes; i++)
1849 {
1850 memcpy(me_nw_code_bcd,&(((UBYTE *)personalisation_cp->pBody)[index]),NW_CODE_LEN);
1851 index +=NW_CODE_LEN;
1852 aci_slock_psaSIM_decodeIMSI(me_nw_code_bcd, NW_CODE_LEN, (char *)imsi_me);
1853 if(!personalisation)
1854 {
1855 AciSLockShrd.blocked = memcmp(imsi_sim,imsi_me,simShrdPrm.mnc_len+3/*MCC length*/) NEQ 0;
1856 if (AciSLockShrd.blocked EQ FALSE)
1857 {
1858 if (psaSIM_ChkSIMSrvSup(SRV_GrpLvl1))
1859 {
1860 memcpy(me_gid1_str,&(((UBYTE *)personalisation_cp->pBody)[index]),GID1_LEN);
1861 index +=GID1_LEN;
1862 AciSLockShrd.blocked = memcmp(aci_slock_sim_config.sim_gidl1,me_gid1_str,cfg_data->GID1_Len) NEQ 0;
1863 if (AciSLockShrd.blocked EQ FALSE)
1864 {
1865 if (psaSIM_ChkSIMSrvSup(SRV_GrpLvl2))
1866 {
1867 memcpy(me_gid2_str,&(((UBYTE *)personalisation_cp->pBody)[index]),GID2_LEN);
1868 index +=GID2_LEN;
1869 AciSLockShrd.blocked = memcmp(aci_slock_sim_config.sim_gidl2,me_gid2_str,cfg_data->GID2_Len) NEQ 0;
1870 if (AciSLockShrd.blocked EQ FALSE)
1871 {
1872 return;
1873 }
1874 }
1875 else
1876 AciSLockShrd.blocked = TRUE;
1877 }
1878 }
1879 else
1880 AciSLockShrd.blocked = TRUE;
1881 }
1882 }
1883 else
1884 {
1885 sim_code_present_in_me= memcmp(imsi_sim,imsi_me,simShrdPrm.mnc_len+3/*MCC length*/) EQ 0;
1886 if ( sim_code_present_in_me EQ TRUE)
1887 {
1888 sim_code_present_in_me = FALSE;
1889 if (psaSIM_ChkSIMSrvSup(SRV_GrpLvl1))
1890 {
1891 memcpy(me_gid1_str,&(((UBYTE *)personalisation_cp->pBody)[index]),GID1_LEN);
1892 index +=GID1_LEN;
1893 sim_code_present_in_me = memcmp(aci_slock_sim_config.sim_gidl1,me_gid1_str,cfg_data->GID1_Len) EQ 0;
1894 if (sim_code_present_in_me EQ TRUE)
1895 {
1896 sim_code_present_in_me = FALSE;
1897 if (psaSIM_ChkSIMSrvSup(SRV_GrpLvl2))
1898 {
1899 memcpy(me_gid2_str,&(((UBYTE *)personalisation_cp->pBody)[index]),GID2_LEN);
1900 index +=GID2_LEN;
1901 sim_code_present_in_me = memcmp(aci_slock_sim_config.sim_gidl2,me_gid2_str,cfg_data->GID2_Len) EQ 0;
1902 if (sim_code_present_in_me EQ TRUE)
1903 {
1904 return;
1905 }
1906 }
1907 }
1908 }
1909 }
1910 }
1911 }
1912 }
1913 }
1914
1915 }
1916
1917
1918 /*
1919 +------------------------------------------------------------------------------
1920 | Function : aci_slock_check_SMlock
1921 +------------------------------------------------------------------------------
1922 | Description : Check IMSI against SIM personalisation
1923 |
1924 | Parameters : imsi_sim - IMSI
1925 | personalisation - 0-add the lock data
1926 | 1-verify the existing lock data
1927 |
1928 | Return : void
1929 |
1930 +------------------------------------------------------------------------------
1931 */
1932 void aci_slock_check_SMlock( UBYTE* imsi_sim, UBYTE personalisation)
1933 {
1934 UBYTE max_num_user_codes;
1935 UBYTE num_op_codes;
1936 UBYTE curr_user_code_index;
1937 UBYTE num_user_codes;
1938 UBYTE opcode_len;
1939
1940 UBYTE code_type;
1941
1942 UBYTE i;
1943 UINT16 index =0;
1944 UBYTE me_nw_ns_msin_code_bcd[NW_NS_MSIN_CODE_LEN];
1945 UBYTE me_nw_ns_msin_msin_code_bcd[NW_NS_MSIN_MSIN_CODE_LEN];
1946
1947 UBYTE me_nw_ns_code_str[6+2+1];
1948 UBYTE me_msin_code_str[8+1];
1949 UBYTE me_nw_ns_msin_msin_code_str[6+2+8+8+1];
1950
1951 UBYTE imsi_me[MAX_IMSI_LEN+1];
1952 UBYTE imsi_sim_temp[MAX_IMSI_LEN+1];
1953
1954 int me_msin_code_first,
1955 me_msin_code_last,
1956 sim_msin_code;
1957
1958 TRACE_FUNCTION("aci_slock_check_SMlock()");
1959
1960 /*
1961 personalisation_sim->pBody[0] -----maximum number of user codes
1962 personalisation_sim->pBody[1] -----num of operator codes
1963 personalisation_sim->pBody[2] -----Operator Code-group length (To be set during configuration)
1964 where length = total number of bytes occupied by operator codes
1965
1966
1967 Code type = 0x0a ( Type identifier for normal code)
1968 Normal code (Including parity nibble) -- 8 bytes (Network code + NS code + MSIN)
1969
1970 Code type = 0x0b (Type identifier for range)
1971 Network code + NS code --------- 5 byte
1972 Start MSIN ---- -------4 byte
1973 End MSIN -------------4 byte
1974
1975 Code type = 0x0c (Type identifier for regular expression)
1976 Regular Expression (including NW code NS code and MSIN) --- 15 byte
1977
1978 Number of User Codes ------- 1 byt e
1979 Current user code index
1980 (for FIFO based addition/deletion of user codes)
1981 (should be set to 0xff if no user codes are present) ---- 1 byte
1982
1983 User code1 ---------- 8 byte
1984 User code 2 ---------- 8 byte
1985 |
1986 |
1987 User code n (n = Max number of user codes for NS) -- 8 byte
1988
1989
1990 */
1991
1992 if(!personalisation)
1993 {
1994 AciSLockShrd.blocked = TRUE;
1995 }
1996 else
1997 {
1998 sim_code_present_in_me = FALSE;
1999 }
2000 if((personalisation_sim NEQ NULL) AND ((UBYTE *)personalisation_sim->pBody NEQ NULL))
2001 {
2002 max_num_user_codes =((UBYTE *) personalisation_sim->pBody)[index];
2003 index += MAX_NUM_USERCODE_SIZE;
2004
2005 num_op_codes =((UBYTE *) personalisation_sim->pBody)[index];
2006 index += NUM_OPCODE_SIZE;
2007
2008 opcode_len =((UBYTE *) personalisation_sim->pBody)[index];
2009 index +=OPCODE_LEN_SIZE;
2010
2011 /*
2012 * check operator defined code-groups
2013 */
2014 for(i=0; i< num_op_codes; i++)
2015 {
2016 code_type = ((UBYTE *)personalisation_sim->pBody)[index];
2017 index +=CODE_TYPE_SIZE;
2018
2019 switch(code_type)
2020 {
2021 case NORMAL_CODE :
2022 memcpy(me_nw_ns_msin_code_bcd,&(((UBYTE *)personalisation_sim->pBody)[index]),NW_NS_MSIN_CODE_LEN);
2023 index +=NW_NS_MSIN_CODE_LEN;
2024 aci_slock_psaSIM_decodeIMSI(me_nw_ns_msin_code_bcd, NW_NS_MSIN_CODE_LEN, (char *)imsi_me);
2025 if(!personalisation)
2026 {
2027 AciSLockShrd.blocked = memcmp(imsi_sim,imsi_me,MAX_IMSI_LEN) NEQ 0;
2028 if (AciSLockShrd.blocked EQ FALSE)
2029 {
2030 return; /* IMSI is matching a personalisation, so break! */
2031 }
2032 }
2033 else
2034 {
2035 sim_code_present_in_me= memcmp(imsi_sim,imsi_me,MAX_IMSI_LEN) EQ 0;
2036 if (sim_code_present_in_me EQ TRUE)
2037 {
2038 return; /* IMSI is matching a personalisation, so break! */
2039 }
2040 }
2041 break;
2042
2043 case INTERVAL_TYPE1 :
2044 memcpy(me_nw_ns_msin_msin_code_bcd,&(((UBYTE *)personalisation_sim->pBody)[index]),NW_NS_MSIN_MSIN_CODE_LEN);
2045 index +=NW_NS_MSIN_MSIN_CODE_LEN;
2046 aci_slock_psaSIM_decodeIMSI(me_nw_ns_msin_msin_code_bcd, NW_NS_MSIN_MSIN_CODE_LEN, (char *)me_nw_ns_msin_msin_code_str);
2047 memcpy(me_nw_ns_code_str,me_nw_ns_msin_msin_code_str,simShrdPrm.mnc_len+3+2);
2048 if(!personalisation)
2049 {
2050 AciSLockShrd.blocked = memcmp(imsi_sim,me_nw_ns_code_str,simShrdPrm.mnc_len+3/*MCC length*/+2 /* Ns code length*/) NEQ 0;
2051 if (AciSLockShrd.blocked EQ FALSE)
2052 {
2053 memcpy(me_msin_code_str,me_nw_ns_msin_msin_code_str+9/*skip the 'F'*/,(MAX_IMSI_LEN - simShrdPrm.mnc_len+3/*MCC length*/+2/* Ns length*/)/* MSIN length*/);
2054 me_msin_code_str[(MAX_IMSI_LEN - simShrdPrm.mnc_len+3/*MCC length*/+2/* Ns length*/)/* MSIN length*/] = '\0';
2055 me_msin_code_first = atoi((const char *)me_msin_code_str);
2056
2057 memcpy(me_msin_code_str,me_nw_ns_msin_msin_code_str+9+8/*skip the 'F'*/,(MAX_IMSI_LEN - simShrdPrm.mnc_len+3/*MCC length*/+2/* Ns length*/)/* MSIN length*/);
2058 me_msin_code_str[(MAX_IMSI_LEN - simShrdPrm.mnc_len+3/*MCC length*/+2/* Ns length*/)/* MSIN length*/] = '\0';
2059 me_msin_code_last = atoi((const char *)me_msin_code_str);
2060
2061 memcpy(imsi_sim_temp,imsi_sim+simShrdPrm.mnc_len+3+2,(MAX_IMSI_LEN - cfg_data->MNC_Len+3/*MCC length*/+2/* Ns length*/)/* MSIN length*/);
2062 imsi_sim_temp[(MAX_IMSI_LEN - simShrdPrm.mnc_len+3/*MCC length*/+2/* Ns length*/)/* MSIN length*/] = '\0';
2063 sim_msin_code = atoi((const char *)imsi_sim_temp);
2064 if((sim_msin_code >= me_msin_code_first ) AND (sim_msin_code <= me_msin_code_last))
2065 {
2066 AciSLockShrd.blocked = FALSE;
2067 return ;
2068 }
2069 else
2070 AciSLockShrd.blocked = TRUE;
2071 }
2072 }
2073 else
2074 {
2075 sim_code_present_in_me= memcmp(imsi_sim,me_nw_ns_code_str,simShrdPrm.mnc_len+3/*MCC length*/+2 /* Ns code length*/) EQ 0;
2076 if (sim_code_present_in_me EQ TRUE)
2077 {
2078 sim_code_present_in_me = FALSE;
2079
2080 memcpy(me_msin_code_str,me_nw_ns_msin_msin_code_str+9/*skip the 'F'*/,(MAX_IMSI_LEN - simShrdPrm.mnc_len+3/*MCC length*/+2/* Ns length*/)/* MSIN length*/);
2081 me_msin_code_str[(MAX_IMSI_LEN - simShrdPrm.mnc_len+3/*MCC length*/+2/* Ns length*/)/* MSIN length*/] = '\0';
2082 me_msin_code_first = atoi((const char *)me_msin_code_str);
2083
2084 memcpy(me_msin_code_str,me_nw_ns_msin_msin_code_str+9+8/*skip the 'F'*/,(MAX_IMSI_LEN -simShrdPrm.mnc_len+3/*MCC length*/+2/* Ns length*/)/* MSIN length*/);
2085 me_msin_code_str[(MAX_IMSI_LEN - simShrdPrm.mnc_len+3/*MCC length*/+2/* Ns length*/)/* MSIN length*/] = '\0';
2086 me_msin_code_last = atoi((const char *)me_msin_code_str);
2087
2088 memcpy(imsi_sim_temp,imsi_sim+simShrdPrm.mnc_len+3+2,(MAX_IMSI_LEN - cfg_data->MNC_Len+3/*MCC length*/+2/* Ns length*/)/* MSIN length*/);
2089 imsi_sim_temp[(MAX_IMSI_LEN - simShrdPrm.mnc_len+3/*MCC length*/+2/* Ns length*/)/* MSIN length*/] = '\0';
2090 sim_msin_code = atoi((const char *)imsi_sim_temp);
2091 if((sim_msin_code >= me_msin_code_first ) AND (sim_msin_code <= me_msin_code_last))
2092 {
2093 sim_code_present_in_me = TRUE;
2094 return ;
2095 }
2096 }
2097 }
2098 break;
2099
2100 case REGULAR_EXP :
2101 break;
2102 default :
2103 break;
2104 }
2105 }
2106
2107 num_user_codes = ((UBYTE *)personalisation_sim->pBody)[index];
2108 index +=NUM_USER_CODE_SIZE;
2109
2110 curr_user_code_index =((UBYTE *) personalisation_sim->pBody)[index];
2111 index +=CURR_USER_CODE_INDEX_SIZE;
2112
2113 /*
2114 * check user defined code-groups
2115 */
2116 for(i=0; i< num_user_codes; i++)
2117 {
2118 memcpy(me_nw_ns_msin_code_bcd,&(((UBYTE *)personalisation_sim->pBody)[index]),NW_NS_MSIN_CODE_LEN);
2119 index +=NW_NS_MSIN_CODE_LEN;
2120 aci_slock_psaSIM_decodeIMSI(me_nw_ns_msin_code_bcd, NW_NS_MSIN_CODE_LEN, (char *)imsi_me);
2121 if(!personalisation)
2122 {
2123 AciSLockShrd.blocked = memcmp(imsi_sim,imsi_me,MAX_IMSI_LEN) NEQ 0;
2124 if (AciSLockShrd.blocked EQ FALSE)
2125 return; /* IMSI is matching a personalisation, so break! */
2126 }
2127 else
2128 {
2129 sim_code_present_in_me = memcmp(imsi_sim,imsi_me,MAX_IMSI_LEN) EQ 0;
2130 if (sim_code_present_in_me EQ TRUE)
2131 return; /* IMSI is matching a personalisation, so break! */
2132 }
2133 }
2134 }
2135 }
2136
2137
2138
2139
2140 /*
2141 +------------------------------------------------------------------------------
2142 | Function : aci_slock_checkpersonalisation
2143 +------------------------------------------------------------------------------
2144 | Description : Checks for all kinds of personalisation locks (except sp & cp : Apr 03,2005).
2145 | The given IMSI will be checked against the internal personalisation data.
2146 | Returns SIMLOCK_BLOCKED, if one lock was not matching the given IMSI.
2147 |
2148 | Parameters : None
2149 |
2150 | Return : SIMLOCK_FAIL = -1,
2151 | SIMLOCK_DISABLED, No SIM lock check has to be done
2152 | SIMLOCK_PERM_DISABLED,
2153 | SIMLOCK_ENABLED, A SIM lock check has to be executed
2154 | SIMLOCK_BLOCKED, The SIM is blocked, i.e. because of a (or to many) wrong PIN(s)
2155 | SIMLOCK_LOCKED The ME is locked because of wrong SIM
2156 |
2157 +------------------------------------------------------------------------------
2158 */
2159 T_SIMLOCK_STATUS aci_slock_checkpersonalisation(T_SIMLOCK_TYPE current_lock)
2160 {
2161 T_SIMLOCK_TYPE type;
2162
2163 UBYTE imsi_sim[MAX_IMSI_LEN+1];
2164 T_SIMLOCK_TYPE check_type;
2165 T_SIMLOCK_STATUS sl_status;
2166 T_AUTOLOCK_STATUS al_status;
2167
2168 TRACE_FUNCTION("aci_slock_checkpersonalisation()");
2169
2170 psaSIM_decodeIMSI(simShrdPrm.imsi.field, simShrdPrm.imsi.c_field, (char *)imsi_sim);
2171
2172 /*
2173 * Test SIM
2174 */
2175 if(memcmp(imsi_sim,mnc_mcc,5) EQ 0)
2176 {
2177 aci_slock_set_simtype(SIM_TEST);
2178 switch(cfg_data->TestCPHS)
2179 {
2180 case ALWAYS_ACCEPTED :
2181 TRACE_FUNCTION("TEST SIM: always accepted");
2182 return( aci_slock_check_done(SIMLOCK_ENABLED));
2183 break;
2184 case ALWAYS_REJECTED :
2185 TRACE_FUNCTION("TEST SIM: always rejected");
2186 break;
2187 }
2188 }
2189 /*
2190 * type approval
2191 */
2192 else if(aci_slock_sim_config.sim_read_ad_first_byte & 0x80)
2193 {
2194 TRACE_FUNCTION("sim type: Classic Test SIM (Type Approval SIM)");
2195 aci_slock_set_simtype(SIM_TYPEAPPROVAL);
2196 switch(cfg_data->TypeAprovalSIM)
2197 {
2198 case ALWAYS_ACCEPTED :
2199 TRACE_FUNCTION("type approval: always accepted");
2200 return( aci_slock_check_done(SIMLOCK_ENABLED));
2201 break;
2202
2203 case ALWAYS_REJECTED :
2204 TRACE_FUNCTION("type approval: always rejected");
2205 for (type=SIMLOCK_NETWORK; type<=SIMLOCK_SIM; type++)
2206 {
2207 if(AciSLockShrd.status[type] EQ SIMLOCK_ENABLED)
2208 {
2209 sl_status = SIMLOCK_BLOCKED;
2210 AciSLockShrd.blocked = TRUE;
2211 break;
2212 }
2213 }
2214 if(AciSLockShrd.blocked NEQ TRUE)
2215 {
2216 sl_status = SIMLOCK_ENABLED ;
2217 }
2218 return(aci_slock_check_done(sl_status));
2219 break;
2220
2221 case UNTIL_NORMAL_SIM :
2222 if(AciSLockShrd.status[SIMLOCK_FIRST_SIM] EQ SIMLOCK_ENABLED) /*11_Apr_05*/
2223 {
2224 AciSLockShrd.blocked = TRUE;
2225 return(aci_slock_check_done(SIMLOCK_BLOCKED));
2226 }
2227 break;
2228 }
2229 }
2230 /*
2231 *Normal SIM
2232 */
2233 else
2234 {
2235 TRACE_FUNCTION("sim type: NORMAL SIM");
2236 aci_slock_set_simtype(SIM_NORMAL );
2237
2238 }
2239
2240 if((cfg_data->FC_Current < cfg_data->FC_Max) OR (cfg_data->FC_Max EQ FC_MAX_INFINITE))
2241 {
2242
2243 if((aci_slock_sim_config.sim_type EQ SIM_NORMAL) AND (personalisation_first_sim NEQ NULL)
2244 AND (AciSLockShrd.status[SIMLOCK_FIRST_SIM] EQ SIMLOCK_DISABLED) )
2245 {
2246 TRACE_FUNCTION("personalisation_first_sim NEQ NULL");
2247 al_status = aci_ext_auto_personalise(current_lock);
2248 switch(al_status)
2249 {
2250 case AUTOLOCK_CMPL :
2251 return(aci_slock_check_done(SIMLOCK_ENABLED));
2252 case AUTOLOCK_EXCT:
2253 return SIMLOCK_WAIT; /* wait for gid1 andgid2 read cnf*/
2254 case AUTOLOCK_FAIL:
2255 default :
2256 AciSLockShrd.blocked = TRUE;
2257 return (aci_slock_check_done(SIMLOCK_BLOCKED));
2258 }
2259
2260 }
2261 else
2262 {
2263
2264 for (type=current_lock; type<=SIMLOCK_SIM; type++)
2265 {
2266 AciSLockShrd.current_lock=type;
2267
2268 if (AciSLockShrd.status[type] EQ SIMLOCK_ENABLED) /* initialised in aci_slock_init */
2269 {
2270 switch (type)
2271 {
2272 case SIMLOCK_NETWORK: aci_slock_check_NWlock(imsi_sim, 0); break;
2273 case SIMLOCK_NETWORK_SUBSET: aci_slock_check_NSlock(imsi_sim, 0); break;
2274 case SIMLOCK_SERVICE_PROVIDER:
2275 if (psaSIM_ChkSIMSrvSup(SRV_GrpLvl1) )
2276 {
2277 if(aci_slock_sim_config.sim_read_gid1 EQ FALSE)
2278 {
2279 aci_slock_sim_read_sim(SIM_GID1, NOT_PRESENT_8BIT, MAX_GID);
2280 return SIMLOCK_WAIT;
2281 }
2282 }
2283 else
2284 {
2285 AciSLockShrd.blocked = TRUE;
2286 return (aci_slock_check_done(SIMLOCK_BLOCKED));
2287 }
2288
2289 aci_slock_check_SPlock(imsi_sim, 0);
2290 break;
2291 case SIMLOCK_CORPORATE:
2292 if (psaSIM_ChkSIMSrvSup(SRV_GrpLvl1))
2293 {
2294 if(aci_slock_sim_config.sim_read_gid1 EQ FALSE)
2295 {
2296 aci_slock_sim_read_sim(SIM_GID1, NOT_PRESENT_8BIT, MAX_GID);
2297 return SIMLOCK_WAIT;
2298 }
2299 }
2300 else
2301 {
2302 AciSLockShrd.blocked = TRUE;
2303 return (aci_slock_check_done(SIMLOCK_BLOCKED));
2304 }
2305 if (psaSIM_ChkSIMSrvSup(SRV_GrpLvl2))
2306 {
2307 if(aci_slock_sim_config.sim_read_gid2 EQ FALSE)
2308 {
2309 aci_slock_sim_read_sim(SIM_GID2, NOT_PRESENT_8BIT, MAX_GID);
2310 return SIMLOCK_WAIT;
2311 }
2312 }
2313 else
2314 {
2315 AciSLockShrd.blocked = TRUE;
2316 return (aci_slock_check_done(SIMLOCK_BLOCKED));
2317 }
2318 aci_slock_check_CPlock(imsi_sim, 0);
2319 break;
2320
2321 case SIMLOCK_SIM: aci_slock_check_SMlock(imsi_sim, 0); break;
2322 default: return (aci_slock_check_done(SIMLOCK_FAIL)); /* won't happen */
2323 }
2324 }
2325
2326 if (AciSLockShrd.blocked) /* if one lock isn't matching, don't try the others */
2327 return (aci_slock_check_done(SIMLOCK_BLOCKED));
2328 }
2329
2330 return (aci_slock_check_done(SIMLOCK_ENABLED));
2331
2332 }
2333 }
2334 else
2335 {
2336 AciSLockShrd.blocked = TRUE;
2337 return (aci_slock_check_done(SIMLOCK_BLOCKED));
2338 }
2339 }
2340
2341
2342
2343
2344 /*
2345 +------------------------------------------------------------------------------
2346 | Function : aci_slock_sim_init
2347 +------------------------------------------------------------------------------
2348 | Description : Install information found in the primitive into configuration buffers
2349 |
2350 | Parameters : sim_mmi_insert_ind- pointer to T_SIM_MMI_INSERT_IND
2351 |
2352 | Return : void
2353 |
2354 +------------------------------------------------------------------------------
2355 */
2356 void aci_slock_sim_init ( T_SIM_MMI_INSERT_IND *sim_mmi_insert_ind )
2357 {
2358 TRACE_FUNCTION("aci_slock_sim_init()");
2359
2360 aci_slock_sim_config.oper_mode = sim_mmi_insert_ind->func;
2361 memcpy(aci_slock_sim_service_table,sim_mmi_insert_ind->sim_serv,sizeof(aci_slock_sim_service_table));
2362
2363 aci_slock_sim_config.phase = sim_mmi_insert_ind->phase;
2364 aci_slock_sim_config.access_acm = sim_mmi_insert_ind->access_acm;
2365 aci_slock_sim_config.access_acmmax = sim_mmi_insert_ind->access_acmmax;
2366 aci_slock_sim_config.access_puct = sim_mmi_insert_ind->access_puct;
2367 aci_slock_reset();
2368
2369 }
2370
2371
2372
2373 /*
2374 +------------------------------------------------------------------------------
2375 | Function : aci_slock_sim_gid1_cnf
2376 +------------------------------------------------------------------------------
2377 | Description : read SIM group identifier 1 from SIM card
2378 | Parameters : error- error code
2379 | data - gid1 data
2380 |
2381 | Return : void
2382 |
2383 +------------------------------------------------------------------------------
2384 */
2385 void aci_slock_sim_gid1_cnf(USHORT error, UBYTE *data)
2386 {
2387 T_SIMLOCK_STATUS sl_status;
2388 T_ACI_CME_ERR err_code; /* code holding the correct error code for SIM LOCK */
2389
2390 TRACE_FUNCTION("aci_slock_sim_gid1_cnf()");
2391 if (error EQ SIM_NO_ERROR)
2392 {
2393 aci_slock_sim_config.sim_read_gid1= TRUE; //this flag will be used to check whether gid's were read
2394 memcpy(aci_slock_sim_config.sim_gidl1, data, MAX_GID);
2395 if(simEntStat.curCmd NEQ AT_CMD_NONE)
2396 {
2397 if(AciSLockShrd.check_lock EQ SIMLOCK_CHECK_LOCK)
2398 {
2399 sl_status = aci_slock_lock(AciSLockShrd.lock_type, AciSLockShrd.lock_passwd);
2400 aci_slock_check_done(sl_status);
2401 }
2402 else if((AciSLockShrd.check_lock EQ SIMLOCK_CHECK_PERS) OR (AciSLockShrd.check_lock EQ SIMLOCK_CHECK_RESET_FC))
2403 {
2404
2405 /* check for SP and corporate personalisation. This is the first case, we can do this, as we have the gid1/gid2 file here */
2406 sl_status= aci_slock_checkpersonalisation(AciSLockShrd.current_lock);
2407 }
2408
2409 }
2410 }
2411 }
2412
2413
2414
2415 /*
2416 +------------------------------------------------------------------------------
2417 | Function : aci_slock_sim_gid2_cnf
2418 +------------------------------------------------------------------------------
2419 | Description : read SIM group identifier 2 from SIM card
2420 | Parameters : error- error code
2421 | data - gid2 data
2422 |
2423 | Return : void
2424 |
2425 +------------------------------------------------------------------------------
2426 */
2427 void aci_slock_sim_gid2_cnf(USHORT error, UBYTE *data)
2428 {
2429 T_SIMLOCK_STATUS sl_status;
2430 T_ACI_CME_ERR err_code; /* code holding the correct error code for SIM LOCK */
2431
2432 TRACE_FUNCTION("aci_slock_sim_gid2_cnf()");
2433
2434 if (error EQ SIM_NO_ERROR)
2435 {
2436 aci_slock_sim_config.sim_read_gid2= TRUE; //this flag will be used to check whether gid's were read
2437 memcpy(aci_slock_sim_config.sim_gidl2, data, MAX_GID);
2438 if(simEntStat.curCmd NEQ AT_CMD_NONE)
2439 {
2440 if(AciSLockShrd.check_lock EQ SIMLOCK_CHECK_LOCK)
2441 {
2442 sl_status = aci_slock_lock(AciSLockShrd.lock_type, AciSLockShrd.lock_passwd);
2443 aci_slock_check_done(sl_status);
2444 }
2445 else if((AciSLockShrd.check_lock EQ SIMLOCK_CHECK_PERS) OR (AciSLockShrd.check_lock EQ SIMLOCK_CHECK_RESET_FC))
2446 {
2447
2448 /* check for SP and corporate personalisation. This is the first case, we can do this, as we have the gid1/gid2 file here */
2449 sl_status= aci_slock_checkpersonalisation(AciSLockShrd.current_lock);
2450 }
2451
2452 }
2453 }
2454 }
2455
2456
2457 /*
2458 +------------------------------------------------------------------------------
2459 | Function : aci_slock_sim_read_sim_cb
2460 +------------------------------------------------------------------------------
2461 | Description : Call back for SIM read.
2462 | Parameters : table_id-
2463 |
2464 | Return : void
2465 |
2466 +------------------------------------------------------------------------------
2467 */
2468 void aci_slock_sim_read_sim_cb(SHORT table_id)
2469 {
2470
2471 T_SIMLOCK_STATUS sl_status;
2472 T_ACI_CME_ERR err_code; /* code holding the correct error code for SIM LOCK */
2473
2474 TRACE_FUNCTION ("aci_slock_sim_read_sim_cb()");
2475
2476 simShrdPrm.atb[table_id].ntryUsdFlg = FALSE;
2477
2478 switch (simShrdPrm.atb[table_id].reqDataFld)
2479 {
2480 case SIM_GID1:
2481 aci_slock_sim_config.gid1_len = simShrdPrm.atb[table_id].dataLen;
2482 aci_slock_sim_gid1_cnf(simShrdPrm.atb[table_id].errCode, simShrdPrm.atb[table_id].exchData);
2483 break;
2484
2485 case SIM_GID2:
2486 aci_slock_sim_config.gid2_len= simShrdPrm.atb[table_id].dataLen;
2487 aci_slock_sim_gid2_cnf(simShrdPrm.atb[table_id].errCode, simShrdPrm.atb[table_id].exchData);
2488 break;
2489 default:
2490 break;
2491 }
2492
2493 }
2494
2495
2496 /*
2497 +------------------------------------------------------------------------------
2498 | Function : aci_slock_sim_read_sim
2499 +------------------------------------------------------------------------------
2500 | Description : Request to read SIM card.
2501 | Parameters : data_id - data field identifier
2502 | len - actual length of data
2503 | max_length - max length of data
2504 |
2505 | Return : void
2506 |
2507 +------------------------------------------------------------------------------
2508 */
2509 void aci_slock_sim_read_sim(USHORT data_id, UBYTE len, UBYTE max_length)
2510 {
2511 SHORT table_id;
2512
2513 TRACE_FUNCTION ("aci_slock_sim_read_sim()");
2514
2515 table_id = psaSIM_atbNewEntry();
2516
2517 if(table_id NEQ NO_ENTRY)
2518 {
2519 simShrdPrm.atb[table_id].ntryUsdFlg = TRUE;
2520 simShrdPrm.atb[table_id].accType = ACT_RD_DAT;
2521 simShrdPrm.atb[table_id].reqDataFld = data_id;
2522 simShrdPrm.atb[table_id].dataOff = 0;
2523 simShrdPrm.atb[table_id].dataLen = len;
2524 simShrdPrm.atb[table_id].recMax = max_length;
2525 simShrdPrm.atb[table_id].exchData = NULL;
2526 simShrdPrm.atb[table_id].rplyCB = aci_slock_sim_read_sim_cb;
2527
2528 simShrdPrm.aId = table_id;
2529 if(psaSIM_AccessSIMData() < 0)
2530 {
2531 TRACE_FUNCTION("abc FATAL ERROR");
2532 }
2533 }
2534 }
2535
2536
2537
2538
2539 /*
2540 +------------------------------------------------------------------------------
2541 | Function : aci_slock_set_simtype
2542 +------------------------------------------------------------------------------
2543 | Description : Setting the sim_type value (Normal, Test SIM, Type Approval SIM
2544 | Parameters : sim_type - SIM_NORMAL =0,
2545 | SIM_TYPEAPPROVAL,
2546 | SIM_TEST
2547 |
2548 | Return : void
2549 |
2550 +------------------------------------------------------------------------------
2551 */
2552 void aci_slock_set_simtype(T_SIM_TYPE sim_type )
2553 {
2554 aci_slock_sim_config.sim_type = sim_type;
2555 }
2556
2557
2558 /*
2559 +------------------------------------------------------------------------------
2560 | Function : aci_slock_set_CFG
2561 +------------------------------------------------------------------------------
2562 | Description : To set global variable for configuration data ( part1 of Security Driver)
2563 | Parameters : none
2564 |
2565 | Return : void
2566 |
2567 +------------------------------------------------------------------------------
2568 */
2569 void aci_slock_set_CFG(void)
2570 {
2571 T_SEC_DRV_RETURN status ;
2572 TRACE_FUNCTION("aci_slock_set_CFG()");
2573 status = sec_get_CFG(&cfg_data);
2574 if(status NEQ SEC_DRV_RET_Ok)
2575 cfg_data = NULL;
2576 }
2577
2578
2579
2580
2581
2582
2583 /*
2584 +------------------------------------------------------------------------------
2585 | Function : aci_set_cme_error
2586 +------------------------------------------------------------------------------
2587 | Description : Set the cme error using ACI_ERR_DESC
2588 | Parameters : slocktype - lock type
2589 |
2590 | Return : void
2591 |
2592 +------------------------------------------------------------------------------
2593 */
2594 void aci_set_cme_error(T_SIMLOCK_TYPE slocktype)
2595 {
2596 switch (slocktype)
2597 {
2598 case SIMLOCK_NETWORK:
2599 if(cfg_data->FC_Current < cfg_data->FC_Max)
2600 {
2601 ACI_ERR_DESC( ACI_ERR_CLASS_Cme, CME_ERR_NetworkPersPinReq );
2602 }
2603 else
2604 {
2605 ACI_ERR_DESC( ACI_ERR_CLASS_Cme, CME_ERR_NetworkPersPukReq);
2606 }
2607 break;
2608
2609 case SIMLOCK_NETWORK_SUBSET:
2610 if(cfg_data->FC_Current < cfg_data->FC_Max)
2611 {
2612 ACI_ERR_DESC( ACI_ERR_CLASS_Cme, CME_ERR_NetworkSubsetPersPinReq );
2613 }
2614 else
2615 {
2616 ACI_ERR_DESC( ACI_ERR_CLASS_Cme, CME_ERR_NetworkSubsetPersPukReq);
2617 }
2618 break;
2619
2620 case SIMLOCK_SERVICE_PROVIDER:
2621 if(cfg_data->FC_Current < cfg_data->FC_Max)
2622 {
2623 ACI_ERR_DESC( ACI_ERR_CLASS_Cme, CME_ERR_ProviderPersPinReq );
2624 }
2625 else
2626 {
2627 ACI_ERR_DESC( ACI_ERR_CLASS_Cme, CME_ERR_ProviderPersPukReq);
2628 }
2629 break;
2630
2631 case SIMLOCK_CORPORATE:
2632 if(cfg_data->FC_Current < cfg_data->FC_Max)
2633 {
2634 ACI_ERR_DESC( ACI_ERR_CLASS_Cme, CME_ERR_CorporatePersPinReq );
2635 }
2636 else
2637 {
2638 ACI_ERR_DESC( ACI_ERR_CLASS_Cme, CME_ERR_CorporatePersPukReq);
2639 }
2640 break;
2641
2642 case SIMLOCK_SIM:
2643 if(cfg_data->FC_Current < cfg_data->FC_Max)
2644 {
2645 ACI_ERR_DESC( ACI_ERR_CLASS_Cme, CME_ERR_PhSimPinReq );
2646 }
2647 else
2648 {
2649 ACI_ERR_DESC( ACI_ERR_CLASS_Cme, CME_ERR_PhoneFail);
2650 }
2651 break;
2652
2653 default:
2654 {
2655 ACI_ERR_DESC( ACI_ERR_CLASS_Cme, CME_ERR_WrongPasswd );
2656 break;
2657 }
2658 }
2659 }
2660
2661 /*
2662 +------------------------------------------------------------------------------
2663 | Function : aci_set_cme_error_code
2664 +------------------------------------------------------------------------------
2665 | Description : Set the cme error code
2666 | Parameters : err_code - cme error code
2667 |
2668 | Return : void
2669 |
2670 +------------------------------------------------------------------------------
2671 */
2672 void aci_set_cme_error_code(T_SIMLOCK_TYPE current_lock ,T_ACI_CME_ERR *err_code)
2673 {
2674 /* @GBR: Alternativly CME_ERR_SimWrong might be returned, but this way is telling the MMI mor specific, what went wrong. */
2675 switch (current_lock)
2676 {
2677 case SIMLOCK_NETWORK:
2678 if(cfg_data->FC_Current < cfg_data->FC_Max)
2679 *err_code = CME_ERR_NetworkPersPinReq ;
2680 else
2681 *err_code = CME_ERR_NetworkPersPukReq;
2682 break;
2683
2684 case SIMLOCK_NETWORK_SUBSET:
2685
2686 if(cfg_data->FC_Current < cfg_data->FC_Max)
2687 *err_code = CME_ERR_NetworkSubsetPersPinReq ;
2688 else
2689 *err_code = CME_ERR_NetworkSubsetPersPukReq;
2690
2691 break;
2692
2693 case SIMLOCK_SERVICE_PROVIDER:
2694
2695 if(cfg_data->FC_Current < cfg_data->FC_Max)
2696 *err_code = CME_ERR_ProviderPersPinReq;
2697 else
2698 *err_code = CME_ERR_ProviderPersPukReq;
2699
2700 break;
2701
2702 case SIMLOCK_CORPORATE:
2703
2704 if(cfg_data->FC_Current < cfg_data->FC_Max)
2705 *err_code = CME_ERR_CorporatePersPinReq ;
2706 else
2707 *err_code = CME_ERR_CorporatePersPukReq;
2708
2709 break;
2710
2711 case SIMLOCK_SIM:
2712
2713 if(cfg_data->FC_Current < cfg_data->FC_Max)
2714 *err_code = CME_ERR_PhSimPinReq;
2715 else
2716 *err_code = CME_ERR_PhoneFail; /* for SIMLOCK_SIM there is no PUK available. Instead the phone is blocked and can only be unblocked by the manufacturer as an anti-theft protection. (See manual of several competitor phones ...) */
2717
2718 break;
2719
2720 case SIMLOCK_FIRST_SIM:
2721
2722 if(cfg_data->FC_Current < cfg_data->FC_Max)
2723 *err_code = CME_ERR_PhFSimPinReq ;
2724 else
2725 *err_code = CME_ERR_PhFSimPukReq;
2726
2727 break;
2728
2729 default:
2730 *err_code = CME_ERR_Unknown;
2731 break;
2732 }
2733
2734 }
2735
2736
2737 void aci_slock_reset()
2738 {
2739 aci_slock_sim_config.sim_gidl1[0] = NOT_PRESENT_8BIT;
2740 aci_slock_sim_config.sim_gidl2[0] = NOT_PRESENT_8BIT;
2741 aci_slock_sim_config.sim_read_gid1= FALSE;
2742 aci_slock_sim_config.sim_read_gid2= FALSE;
2743 }
2744
2745
2746 T_SIMLOCK_STATUS aci_slock_check_done(T_SIMLOCK_STATUS sl_status)
2747 {
2748
2749 UBYTE cmdBuf;
2750 T_ACI_CME_ERR err_code = CME_ERR_NotPresent; /* code holding the correct error code calculated */
2751
2752 TRACE_FUNCTION_P1 ("aci_slock_check_done() %d",simEntStat.curCmd );
2753 switch( simEntStat.curCmd )
2754 {
2755 case( AT_CMD_CFUN ):
2756 case( AT_CMD_CPIN ):
2757 case( AT_CMD_PVRF ):
2758 case(AT_CMD_NRG) :
2759 case( AT_CMD_SIMRST):
2760 case( AT_CMD_NONE ):
2761 case (AT_CMD_CIMI):
2762 case( KSD_CMD_UBLK):
2763 /*
2764 * Start to build phonebook
2765 */
2766 AciSLockShrd.pb_load = TRUE;
2767 pb_reset();
2768
2769 #ifdef TI_PS_FFS_PHB
2770 if(last_sim_mmi_insert_ind NEQ NULL)
2771 {
2772 pb_inserted_sim (MAX_SRV_TBL,
2773 last_sim_mmi_insert_ind->sim_serv,
2774 &last_sim_mmi_insert_ind->imsi_field,
2775 last_sim_mmi_insert_ind->func,
2776 last_sim_mmi_insert_ind->phase);
2777 }
2778 #else
2779 if(last_sim_mmi_insert_ind NEQ NULL)
2780 {
2781 pb_build_req(last_sim_mmi_insert_ind);
2782 }
2783 #endif
2784
2785 /* Request the Customer Service Profile from the SIM (EF_CPHS_CSP) */
2786 cmhSIM_Get_CSP();
2787 if(last_sim_mmi_insert_ind NEQ NULL)
2788 {
2789 #ifdef SIM_TOOLKIT
2790 cmhSMS_ReadCbDtaDwnl (last_sim_mmi_insert_ind);
2791 #endif
2792 #ifdef FF_MMI_RIV
2793 rAT_PlusCFUNP (last_sim_mmi_insert_ind);
2794 #endif /* FF_MMI_RIV */
2795 PFREE (last_sim_mmi_insert_ind); /* 11_Apr_05 */
2796 last_sim_mmi_insert_ind= NULL;
2797 }
2798
2799 cmhSIM_SIMInserted();
2800 aci_ext_personalisation_free();
2801 MFREE(cfg_data);
2802 break;
2803
2804 case (AT_CMD_CLCK):
2805
2806 if(AciSLockShrd.check_lock EQ SIMLOCK_CHECK_RESET_FC)
2807 {
2808 cmdBuf = simEntStat.curCmd;
2809 simEntStat.curCmd = AT_CMD_NONE;
2810 if((sl_status EQ SIMLOCK_ENABLED) AND (AciSLockShrd.pb_load EQ FALSE))
2811 {
2812 /*
2813 * Start to build phonebook
2814 */
2815 AciSLockShrd.pb_load = TRUE;
2816 pb_reset();
2817
2818 #ifdef TI_PS_FFS_PHB
2819 if(last_sim_mmi_insert_ind NEQ NULL)
2820 {
2821 pb_inserted_sim (MAX_SRV_TBL,
2822 last_sim_mmi_insert_ind->sim_serv,
2823 &last_sim_mmi_insert_ind->imsi_field,
2824 last_sim_mmi_insert_ind->func,
2825 last_sim_mmi_insert_ind->phase);
2826 }
2827 #else
2828 if(last_sim_mmi_insert_ind NEQ NULL)
2829 {
2830 pb_build_req(last_sim_mmi_insert_ind);
2831 }
2832 #endif
2833
2834 /* Request the Customer Service Profile from the SIM (EF_CPHS_CSP) */
2835 cmhSIM_Get_CSP();
2836
2837 if(last_sim_mmi_insert_ind NEQ NULL)
2838 {
2839 #ifdef SIM_TOOLKIT
2840 cmhSMS_ReadCbDtaDwnl (last_sim_mmi_insert_ind);
2841 #endif
2842 #ifdef FF_MMI_RIV
2843 rAT_PlusCFUNP (last_sim_mmi_insert_ind);
2844 #endif /* FF_MMI_RIV */
2845 PFREE (last_sim_mmi_insert_ind); /* 11_Apr_05 */
2846 last_sim_mmi_insert_ind= NULL;
2847 }
2848 R_AT( RAT_OK, simEntStat.entOwn ) ( cmdBuf );
2849 cmh_logRslt ( simEntStat.entOwn, RAT_OK, cmdBuf, -1, -1, -1 );
2850 }
2851 if ( AciSLockShrd.blocked)
2852 {
2853 /* @GBR: Alternativly CME_ERR_SimWrong might be returned, but this way is telling the MMI mor specific, what went wrong. */
2854 aci_set_cme_error_code(AciSLockShrd.current_lock,&err_code);
2855 R_AT( RAT_CME, simEntStat.entOwn )
2856 ( cmdBuf, err_code );
2857 cmh_logRslt ( simEntStat.entOwn, RAT_CME, cmdBuf, -1, -1, err_code );
2858 }
2859 aci_ext_personalisation_free();
2860 MFREE(cfg_data);
2861 }
2862
2863 else if(AciSLockShrd.check_lock EQ SIMLOCK_CHECK_LOCK)
2864 {
2865
2866 switch(sl_status)
2867 {
2868 case SIMLOCK_ENABLED :
2869 cmdBuf = simEntStat.curCmd;
2870 simEntStat.curCmd = AT_CMD_NONE;
2871 R_AT( RAT_OK, simEntStat.entOwn ) ( cmdBuf );
2872 cmh_logRslt ( simEntStat.entOwn, RAT_OK, cmdBuf, -1, -1, -1 );
2873 break;
2874 case SIMLOCK_WAIT :
2875 break;
2876 case SIMLOCK_FAIL :
2877 cmdBuf = simEntStat.curCmd;
2878 simEntStat.curCmd = AT_CMD_NONE;
2879 err_code =CME_ERR_WrongPasswd;
2880 R_AT( RAT_CME, simEntStat.entOwn )
2881 ( cmdBuf, err_code );
2882 cmh_logRslt ( simEntStat.entOwn, RAT_CME, cmdBuf, -1, -1, err_code );
2883 break;
2884 }
2885 }
2886 break;
2887
2888 }
2889 return sl_status;
2890 }
2891
2892 #endif