comparison gsm-fw/g23m-gsm/sim/sim_fkt.c @ 673:2f7df7a314f8

gsm-fw/g23m-gsm subtree: initial import from LoCosto source
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sun, 28 Sep 2014 23:20:04 +0000
parents
children ec171ca4afb4
comparison
equal deleted inserted replaced
672:0dc6f9e8e980 673:2f7df7a314f8
1 /*
2 +-----------------------------------------------------------------------------
3 | Project : GSM-F&D (8411)
4 | Modul : SIM_FKT
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 : This modul defines the wrapping functions for the
18 | SIM application.
19 +-----------------------------------------------------------------------------
20 */
21
22 #ifndef SIM_FKT_C
23 #define SIM_FKT_C
24
25 #define ENTITY_SIM
26
27 /*==== INCLUDES ===================================================*/
28
29 #include <string.h>
30 #include "typedefs.h"
31 #include "pconst.cdg"
32 #include "message.h"
33 #include "ccdapi.h"
34 #include "vsi.h"
35 #include "custom.h"
36 #include "gsm.h"
37 #include "cnf_sim.h"
38 #include "mon_sim.h"
39 #include "prim.h"
40 #include "pei.h"
41 #include "tok.h"
42 #include "sim.h"
43 #include "sim_em.h"
44
45 /*==== EXPORT =====================================================*/
46 #ifdef _SIMULATION_
47 LOCAL USHORT first_time_into_fkt_select = TRUE;
48 LOCAL USHORT file_id;
49 #endif
50 GLOBAL USHORT stk_l_cmd = 0;
51
52
53 /*==== PRIVAT =====================================================*/
54
55 /*==== VARIABLES ==================================================*/
56
57 /*==== FUNCTIONS ===================================================*/
58
59 /*
60 +--------------------------------------------------------------------+
61 | PROJECT : GSM-PS (6302) MODULE : SIM_FKT |
62 | STATE : code ROUTINE : FKT_check_pin_count |
63 +--------------------------------------------------------------------+
64
65 PURPOSE : PIN/PUK count is checked for secret code initialisation.
66 count is set to zero, if not initialised, otherwise the
67 initialisation flag (most significant bit) is reset.
68 */
69
70 GLOBAL UBYTE FKT_check_pin_count (UBYTE count)
71 {
72 if ((count & 0x80) EQ 0)
73 return 0;
74
75 return count & 0x0F;
76 }
77
78 /*
79 +--------------------------------------------------------------------+
80 | PROJECT : GSM-PS (6302) MODULE : SIM_FKT |
81 | STATE : code ROUTINE : FKT_convert_error |
82 +--------------------------------------------------------------------+
83
84 PURPOSE : Converts sw1 and sw2 to an unique error code for the
85 SIM application.
86
87 */
88
89 /*
90 * PIN/PUK is wrong, remaining attempts
91 */
92 const static USHORT sim_inv_chv_A [6] =
93 {
94 /* last requested PIN no error code */
95 /* none */ SIM_CAUSE_OTHER_ERROR,
96 /* PIN 1 */ SIM_CAUSE_PIN1_EXPECT,
97 /* PIN 2 */ SIM_CAUSE_PIN2_EXPECT,
98 /* PUK 1 */ SIM_CAUSE_PUK1_EXPECT,
99 /* PUK 2 */ SIM_CAUSE_PUK2_EXPECT,
100 /* NEVER */ SIM_CAUSE_ACCESS_PROHIBIT
101 };
102
103
104 /*
105 * PIN/PUK is wrong, no remaining attempts
106 */
107 const static USHORT sim_inv_chv_B [6] =
108 {
109 /* last requested PIN no error code */
110 /* none */ SIM_CAUSE_OTHER_ERROR,
111 /* PIN 1 */ SIM_CAUSE_PIN1_BLOCKED,
112 /* PIN 2 */ SIM_CAUSE_PIN2_BLOCKED,
113 /* PUK 1 */ SIM_CAUSE_PUK1_BLOCKED,
114 /* PUK 2 */ SIM_CAUSE_PUK2_BLOCKED,
115 /* NEVER */ SIM_CAUSE_OTHER_ERROR
116 };
117
118 GLOBAL USHORT FKT_convert_error (USHORT sw1sw2, USHORT size)
119 {
120 TRACE_FUNCTION ("FKT_convert_error()");
121
122 sim_data.sw1 = (UBYTE)(sw1sw2 >> 8);
123 sim_data.sw2 = (UBYTE)sw1sw2;
124
125 TRACE_EVENT_P2 ("SW1=%02X SW2=%02X", sim_data.sw1, sim_data.sw2);
126
127 switch (sim_data.sw1)
128 {
129 case 0x00:
130 /*
131 * SIM driver error
132 */
133 if (SIM_IS_FLAG_CLEARED(SIM_INSERT))
134 {
135 return SIM_CAUSE_CARD_REMOVED;
136 }
137 if (sim_data.sw2 EQ 14)
138 {
139 SIM_SET_FLAG(DRV_FAILED_RETRY);
140 return SIM_CAUSE_DRV_TEMPFAIL;
141 }
142 return CAUSE_MAKE(DEFBY_CONDAT, ORIGSIDE_MS, SIM_ORIGINATING_ENTITY, sim_data.sw2);
143 #if defined SIM_TOOLKIT
144 case 0x9E:
145 /*
146 * use SW2 as length indicator for
147 * the following get response
148 */
149 if (sim_data.sim_phase >= 3) /* Phase 2+ or higher */
150 {
151 if (sim_data.stk_profile[0] & SAT_TP1_9E_XX)
152 {
153 sim_data.sim_data_len = (sim_data.sw2 EQ 0)? 0x100: (USHORT)sim_data.sw2;
154 return SIM_CAUSE_DNL_ERROR;
155 }
156 else
157 return SIM_CAUSE_SAT_BUSY;
158 }
159 else
160 return SIM_CAUSE_OTHER_ERROR;
161 case 0x93:
162 if (sim_data.sim_phase >= 3) /* Phase 2+ or higher */
163 {
164 return SIM_CAUSE_SAT_BUSY;
165 }
166 else
167 return SIM_CAUSE_OTHER_ERROR;
168 case 0x91:
169 if (sim_data.sim_phase >= 3) /* Phase 2+ or higher */
170 {
171 sim_data.proactive_sim_data_len = (sim_data.sw2 EQ 0)? 0x100: (SHORT)sim_data.sw2;
172 return SIM_NO_ERROR;
173 }
174 else
175 return SIM_CAUSE_OTHER_ERROR;
176 #endif
177 case 0x92:
178 if (sim_data.sw2 > 0xF)
179 {
180 #ifdef REL99
181 if (sim_data.sw2 EQ SW2_MEMORY_PROBLEM)
182 {
183 return SIM_CAUSE_MEM_PROBLEM;
184 }
185 #endif /* end of ifdef REL99 */
186 return SIM_CAUSE_OTHER_ERROR;
187 }
188 /* no break (otherwise the command was successful) */
189 case 0x90:
190 if( (size >= 0) AND (size <= 0x100) )
191 {
192 sim_data.sim_data_len = size;
193 TRACE_EVENT_P1 ("sim_data.sim_data_len updated size =%X ", size);
194 }
195 return SIM_NO_ERROR;
196 case 0x9F:
197 /*
198 * use SW2 as length indicator for
199 * the following get response
200 */
201 sim_data.sim_data_len = (sim_data.sw2 EQ 0)? 0x100: (USHORT)sim_data.sw2;
202 return SIM_NO_ERROR;
203
204 case 0x94:
205 switch (sim_data.sw2)
206 {
207 case 0:
208 return SIM_CAUSE_NO_SELECT;
209 case 2:
210 return SIM_CAUSE_ADDR_WRONG;
211 case 4:
212 return SIM_CAUSE_UNKN_FILE_ID;
213 case 8:
214 return SIM_CAUSE_CMD_INCONSIST;
215 default:
216 break;
217 }
218 break;
219
220 case 0x98:
221 TRACE_EVENT_P1 ("LRP = %d", (int)sim_data.last_requested_pin_no);
222
223 switch (sim_data.sw2)
224 {
225 case 2:
226 return SIM_CAUSE_CHV_NOTSET;
227 case 8:
228 return SIM_CAUSE_CHV_VALIDATED;
229 case 0x10:
230 return SIM_CAUSE_EF_INVALID; /* contradiction cases */
231 case 4:
232 return sim_inv_chv_A [sim_data.last_requested_pin_no];
233 case 0x40:
234 return sim_inv_chv_B [sim_data.last_requested_pin_no];
235 case 0x50:
236 return SIM_CAUSE_MAX_INCREASE;
237 default:
238 break;
239 }
240 break;
241 }
242
243 return SIM_CAUSE_OTHER_ERROR;
244 }
245
246 /*
247 +--------------------------------------------------------------------+
248 | PROJECT : GSM-PS (6302) MODULE : SIM_FKT |
249 | STATE : code ROUTINE : FKT_ChangeCHV |
250 +--------------------------------------------------------------------+
251
252 PURPOSE : Wrapping function for the SIM driver call SIM_ChangeCHV.
253
254 */
255
256 GLOBAL USHORT FKT_ChangeCHV (UBYTE * old_pin,
257 UBYTE * new_pin,
258 UBYTE pin_id)
259 {
260 USHORT size = 0;
261 USHORT sw1sw2;
262 UBYTE response[4];
263
264 TRACE_FUNCTION ("FKT_ChangeCHV()");
265
266 sw1sw2 = SIM_ChangeCHV ((UBYTE *)response,
267 (UBYTE *)old_pin,
268 (UBYTE *)new_pin,
269 (UBYTE)pin_id,
270 &size);
271
272 return FKT_convert_error (sw1sw2, size);
273 }
274
275 /*
276 +--------------------------------------------------------------------+
277 | PROJECT : GSM-PS (6302) MODULE : SIM_FKT |
278 | STATE : code ROUTINE : FKT_DisableCHV |
279 +--------------------------------------------------------------------+
280
281 PURPOSE : Wrapping function for the SIM driver call SIM_DisableCHV.
282
283 */
284
285 GLOBAL USHORT FKT_DisableCHV (UBYTE * pin)
286 {
287 USHORT size = 0;
288 USHORT sw1sw2;
289 UBYTE response[4];
290
291 TRACE_FUNCTION ("FKT_DisableCHV()");
292
293 sw1sw2 = SIM_DisableCHV ((UBYTE *)response,
294 (UBYTE *)pin,
295 &size);
296
297 return FKT_convert_error (sw1sw2, size);
298 }
299
300 /*
301 +--------------------------------------------------------------------+
302 | PROJECT : GSM-PS (6302) MODULE : SIM_FKT |
303 | STATE : code ROUTINE : FKT_EnableCHV |
304 +--------------------------------------------------------------------+
305
306 PURPOSE : Wrapping function for the SIM driver call SIM_EnableCHV.
307
308 */
309
310 GLOBAL USHORT FKT_EnableCHV (UBYTE * pin)
311 {
312 USHORT size = 0;
313 USHORT sw1sw2;
314 UBYTE response[4];
315
316 TRACE_FUNCTION ("FKT_EnableCHV()");
317
318 sw1sw2 = SIM_EnableCHV ((UBYTE *)response,
319 (UBYTE *)pin,
320 &size);
321
322 return FKT_convert_error (sw1sw2, size);
323 }
324
325 /*
326 +--------------------------------------------------------------------+
327 | PROJECT : GSM-PS (6302) MODULE : SIM_FKT |
328 | STATE : code ROUTINE : FKT_GetResponse |
329 +--------------------------------------------------------------------+
330
331 PURPOSE : Wrapping function for the SIM driver call SIM_GetResponse.
332
333 */
334 GLOBAL USHORT FKT_GetResponse (UBYTE * data,
335 USHORT len)
336 {
337 USHORT size = 0;
338 USHORT sw1sw2;
339
340 TRACE_FUNCTION ("FKT_GetResponse()");
341
342 sw1sw2 = SIM_GetResponse ((UBYTE *)data,
343 len,
344 &size);
345 return FKT_convert_error (sw1sw2, len);
346 }
347
348 /*
349 +--------------------------------------------------------------------+
350 | PROJECT : GSM-PS (6302) MODULE : SIM_FKT |
351 | STATE : code ROUTINE : FKT_Increase |
352 +--------------------------------------------------------------------+
353
354 PURPOSE : Wrapping function for the SIM driver call SIM_Increase.
355
356 */
357
358 GLOBAL USHORT FKT_Increase (UBYTE * data)
359 {
360 USHORT sw1sw2;
361 USHORT size = 0;
362 UBYTE response[4];
363
364 TRACE_FUNCTION ("FKT_Increase()");
365 sw1sw2 = SIM_Increase ((UBYTE *)response,
366 (UBYTE *)data,
367 &size);
368
369 return FKT_convert_error (sw1sw2, size);
370 }
371
372
373 /*
374 +--------------------------------------------------------------------+
375 | PROJECT : GSM-PS (6302) MODULE : SIM_FKT |
376 | STATE : code ROUTINE : FKT_Invalidate |
377 +--------------------------------------------------------------------+
378
379 PURPOSE : Wrapping function for the SIM driver call SIM_Invalidate.
380
381 */
382
383 GLOBAL USHORT FKT_Invalidate (void)
384 {
385 USHORT size = 0;
386 USHORT sw1sw2;
387 UBYTE response[4];
388
389 TRACE_FUNCTION ("FKT_Invalidate()");
390
391 sw1sw2 = SIM_Invalidate ((UBYTE *)response,
392 &size);
393
394 if (sw1sw2 EQ 0x9810) /* already invalidated */
395 return SIM_NO_ERROR;
396
397 return FKT_convert_error (sw1sw2, size);
398 }
399
400
401 /*
402 +--------------------------------------------------------------------+
403 | PROJECT : GSM-PS (6302) MODULE : SIM_FKT |
404 | STATE : code ROUTINE : FKT_ReadBinary |
405 +--------------------------------------------------------------------+
406
407 PURPOSE : Wrapping function for the SIM driver call SIM_ReadBinary.
408
409 */
410
411 GLOBAL USHORT FKT_ReadBinary (UBYTE * data,
412 USHORT offset,
413 USHORT length)
414 {
415 USHORT sw1sw2;
416 USHORT size = 0;
417
418 TRACE_FUNCTION ("FKT_ReadBinary()");
419
420 sw1sw2= SIM_ReadBinary ((UBYTE *)data,
421 offset,
422 length,
423 &size);
424
425 return FKT_convert_error (sw1sw2, size);
426 }
427
428
429 /*
430 +--------------------------------------------------------------------+
431 | PROJECT : GSM-PS (6302) MODULE : SIM_FKT |
432 | STATE : code ROUTINE : FKT_ReadRecord |
433 +--------------------------------------------------------------------+
434
435 PURPOSE : Wrapping function for the SIM driver call SIM_ReadRecord.
436
437 */
438
439 GLOBAL USHORT FKT_ReadRecord (UBYTE * data,
440 UBYTE mode,
441 USHORT record,
442 USHORT length)
443 {
444 USHORT sw1sw2;
445 USHORT size = 0;
446
447 #if !defined NTRACE
448 char buf[48];
449 sprintf (buf, "FKT_ReadRecord(): Nr. %hu", record);
450 TRACE_FUNCTION (buf);
451 #endif
452
453 sw1sw2 = SIM_ReadRecord ((UBYTE *)data,
454 (UBYTE)mode,
455 (UBYTE)record,
456 length,
457 &size);
458
459 return FKT_convert_error (sw1sw2, size);
460 }
461
462
463 /*
464 +--------------------------------------------------------------------+
465 | PROJECT : GSM-PS (6302) MODULE : SIM_FKT |
466 | STATE : code ROUTINE : FKT_Rehabilitate |
467 +--------------------------------------------------------------------+
468
469 PURPOSE : Wrapping function for the SIM driver call SIM_Rehabilitate.
470
471 */
472
473 GLOBAL USHORT FKT_Rehabilitate (void)
474 {
475 USHORT size = 0;
476 USHORT sw1sw2;
477 UBYTE response[4];
478
479 TRACE_FUNCTION ("FKT_Rehabilitate()");
480
481 sw1sw2 = SIM_Rehabilitate ((UBYTE *)response,
482 &size);
483
484 if (sw1sw2 EQ 0x9810) /* already rehabilitated */
485 return SIM_NO_ERROR;
486
487 return FKT_convert_error (sw1sw2, size);
488 }
489
490
491 /*
492 +--------------------------------------------------------------------+
493 | PROJECT : GSM-PS (6302) MODULE : SIM_FKT |
494 | STATE : code ROUTINE : FKT_Status |
495 +--------------------------------------------------------------------+
496
497 PURPOSE : Wrapping function for the SIM driver call SIM_Status.
498
499 */
500
501 GLOBAL USHORT FKT_Status (UBYTE * pin_cnt,
502 UBYTE * pin2_cnt,
503 UBYTE * puk_cnt,
504 UBYTE * puk2_cnt)
505 {
506 USHORT size = 0;
507 USHORT sw1sw2;
508
509 USHORT cause;
510 USHORT fileid;
511 union
512 {
513 T_DIR_STATUS status;
514 UBYTE response [40];
515 } dir;
516
517 TRACE_FUNCTION ("FKT_Status()");
518
519 memset (dir.response, 0, sizeof(dir.response));
520
521 sw1sw2 = SIM_Status_Extended (dir.response,
522 sim_data.dir_status_len, &size);
523
524 cause = FKT_convert_error (sw1sw2, size);
525
526 *pin_cnt = 0;
527 *puk_cnt = 0;
528 *pin2_cnt = 0;
529 *puk2_cnt = 0;
530
531 if (cause EQ SIM_NO_ERROR)
532 {
533 /*
534 * Check file id on active call: if different from last directory
535 * indicate failure during SIM Presence Detection (27.20).
536 * A selection of a non-existent DF (possible with SIM_ACCESS_REQ)
537 * leads to the loss of the current DF: this confuses the SIM
538 * Presence Detection, therefore the validity of the actual DF
539 * stored in 'sim_data.act_directory' must be considered.
540 */
541 fileid = (dir.status.fileid[0] << 8) | dir.status.fileid[1];
542
543 if (SIM_IS_FLAG_SET (CALL_ACTIVE) AND /* call active */
544 sim_data.act_directory NEQ NOT_PRESENT_16BIT /* actual DF known? */
545 AND fileid NEQ sim_data.act_directory) /* compare DF */
546 return SIM_CAUSE_CARD_REMOVED;
547 else
548 {
549 if (SIM_TI_DRV_X_BYTES > 0) /* discard SW1, SW2 from response! */
550 memset (&dir.response[sim_data.dir_status_len], 0, SIM_TI_DRV_X_BYTES);
551 /*
552 * Directory status is available
553 */
554 *pin_cnt = FKT_check_pin_count (dir.status.pinstatus);
555 *puk_cnt = FKT_check_pin_count (dir.status.unbstatus);
556 *pin2_cnt = FKT_check_pin_count (dir.status.pin2status);
557 *puk2_cnt = FKT_check_pin_count (dir.status.unb2status);
558 }
559 }
560 return cause;
561 }
562
563 /*
564 +--------------------------------------------------------------------+
565 | PROJECT : GSM-PS (6302) MODULE : SIM_FKT |
566 | STATE : code ROUTINE : FKT_RunGSMAlgo |
567 +--------------------------------------------------------------------+
568
569 PURPOSE : Wrapping function for the SIM driver call SIM_RunGSMAlgo.
570
571 */
572 GLOBAL USHORT FKT_RunGSMAlgo (UBYTE * rand, UBYTE * data, USHORT len)
573 {
574 UBYTE response[4];
575 USHORT sw1sw2;
576 USHORT error;
577 USHORT size = 0;
578
579 TRACE_FUNCTION ("FKT_RunGSMAlgo()");
580
581 sw1sw2 = SIM_RunGSMAlgo ((UBYTE *)response,
582 (UBYTE *)rand,
583 &size);
584
585 error = FKT_convert_error (sw1sw2, size);
586
587 if (error EQ SIM_NO_ERROR)
588 error = FKT_GetResponse (data, len);
589
590 return error;
591 }
592
593 /*
594 +--------------------------------------------------------------------+
595 | PROJECT : GSM-PS (6302) MODULE : SIM_FKT |
596 | STATE : code ROUTINE : FKT_Select |
597 +--------------------------------------------------------------------+
598
599 PURPOSE : Wrapping function for the SIM driver call SIM_Select.
600
601 */
602 LOCAL USHORT fkt_select_one (USHORT id, UBYTE * data, USHORT len)
603 {
604
605 USHORT size = 0;
606 USHORT sw1sw2;
607 USHORT error;
608 UBYTE response[4];
609
610 sw1sw2 = SIM_Select (id,
611 (UBYTE *)response,
612 &size);
613
614
615 error = FKT_convert_error (sw1sw2, size);
616
617 if (error EQ SIM_NO_ERROR)
618 {
619 if( (data NEQ NULL )
620 AND (len NEQ 0 )
621 #ifdef _SIMULATION_
622 AND (id EQ file_id)
623 #endif
624 )
625 {
626 #ifdef _SIMULATION_
627 len = (sim_data.sim_data_len < len)?
628 sim_data.sim_data_len: len;
629 first_time_into_fkt_select = TRUE;
630 #endif
631
632 error = FKT_GetResponse (data, sim_data.sim_data_len);
633 }
634 }
635
636 return error;
637
638 }
639
640 /*
641 +--------------------------------------------------------------------+
642 | PROJECT : GSM-PS (6302) MODULE : SIM_FKT |
643 | STATE : code ROUTINE : sim_select_df |
644 +--------------------------------------------------------------------+
645
646 PURPOSE : Function to select the directory given the path.
647
648 */
649 LOCAL USHORT sim_select_df(U16 dir_level,UBYTE *data,USHORT len)
650 {
651 USHORT result = SIM_NO_ERROR;
652
653 result = fkt_select_one (dir_level, data, len);
654 if (result NEQ SIM_NO_ERROR)
655 {
656 sim_data.act_directory = NOT_PRESENT_16BIT;
657 sim_data.act_field = NOT_PRESENT_16BIT;
658 }
659 else
660 {
661 sim_data.act_directory = dir_level;
662 }
663 return result;
664 }
665
666 /*
667 +--------------------------------------------------------------------+
668 | PROJECT : GSM-PS (6302) MODULE : SIM_FKT |
669 | STATE : code ROUTINE : FKT_Select |
670 +--------------------------------------------------------------------+
671
672 PURPOSE : Wrapping function for the SIM driver call SIM_Select.
673
674 */
675 GLOBAL USHORT FKT_Select (USHORT id,
676 BOOL path_info_present, T_path_info * path_info_ptr,
677 UBYTE * data, USHORT len)
678 {
679 USHORT result;
680 USHORT directory = (SIM_IS_FLAG_SET (GSM_DATAFIELD))?
681 SIM_DF_GSM: SIM_DF_1800; /* default parent directory */
682
683 #if !defined NTRACE
684 char buf[32];
685
686 sprintf (buf, "FKT_Select(): id = %04X", id);
687 TRACE_FUNCTION (buf);
688 #endif
689
690 #ifdef _SIMULATION_
691 if( (first_time_into_fkt_select EQ TRUE ) AND
692 (data NEQ NULL) AND (len NEQ 0) )
693 file_id = id;
694 #endif
695
696
697 switch (id & 0xFF00) /* selecting DF deselects EF */
698 {
699 case 0x3F00:
700 case 0x7F00:
701 case 0x5F00:
702 sim_data.act_field = NOT_PRESENT_16BIT;
703 break;
704 }
705
706 if( path_info_present NEQ FALSE )
707 {
708 if((sim_data.act_directory & 0xFF00) NEQ 0x5F00 AND
709 sim_data.act_directory NEQ NOT_PRESENT_16BIT)
710 {
711 /* Currently selected df is MF or a first level directory */
712 if(sim_data.act_directory NEQ path_info_ptr->df_level1)
713 {
714 result = sim_select_df(path_info_ptr->df_level1,data,len);
715 if(result NEQ SIM_NO_ERROR)
716 return result;
717 }
718 }
719 /* Currently selected df is a second level directory */
720 else
721 {
722 result = sim_select_df(SIM_MF,data,len);
723 if(result NEQ SIM_NO_ERROR)
724 return result;
725 result = sim_select_df(path_info_ptr->df_level1,data,len);
726 if(result NEQ SIM_NO_ERROR)
727 return result;
728 }
729 if(path_info_ptr->v_df_level2)
730 {
731 result = sim_select_df(path_info_ptr->df_level2,data,len);
732 if(result NEQ SIM_NO_ERROR)
733 return result;
734 }
735 result = fkt_select_one (id, data, len);
736 if (result NEQ SIM_NO_ERROR)
737 {
738
739 sim_data.act_field = NOT_PRESENT_16BIT;
740 }
741 else
742 {
743 sim_data.act_field = id;
744 }
745 return result;
746 }
747 else
748 {
749 switch (id)
750 {
751 case SIM_MF:
752 result = fkt_select_one (SIM_MF, data, len);
753 if (result NEQ SIM_NO_ERROR)
754 sim_data.act_directory = NOT_PRESENT_16BIT;
755 else
756 {
757 sim_data.dir_status_len = sim_data.sim_data_len;
758 sim_data.act_directory = id;
759 }
760 return result;
761
762 default:
763 /* All the standard defined EFs would be handled before coming to this
764 * point. Complete path information should be given for non-standard 2nd level EFs
765 * and they also would be handled before coming to this point.
766 * This statement will be hit for non-standard files
767 * without path information. Hence returning error */
768 return SIM_CAUSE_UNKN_FILE_ID;
769 break; /* any other elementary file */
770
771 /* continue here in case of any first level directory */
772 case SIM_DF_GSM:
773 case SIM_DF_1800:
774 case SIM_DF_TELECOM:
775 case SIM_DF_VI:
776 case SIM_DF_ORANGE:
777 if (sim_data.act_directory EQ id)
778 return SIM_NO_ERROR; /* already selected */
779 else
780 {
781 /* If current directory has not been selected or it is a
782 2nd level and under another 1st level DF */
783 if (((sim_data.act_directory & 0xFF00) EQ 0x5F00 AND
784 ! SIM_IS_DF_LEVEL2_UNDER_DF_LEVEL1(sim_data.act_directory,id))
785 OR sim_data.act_directory EQ NOT_PRESENT_16BIT)
786 { /* MF has to be selected first */
787 result = sim_select_df(SIM_MF,data,len);
788 if(result NEQ SIM_NO_ERROR)
789 return result;
790 }
791 result = fkt_select_one (id, data, len);
792 if (result NEQ SIM_NO_ERROR)
793 {
794 sim_data.act_directory = NOT_PRESENT_16BIT;
795 sim_data.act_field = NOT_PRESENT_16BIT;
796 }
797 else
798 {
799 sim_data.dir_status_len = sim_data.sim_data_len;
800 sim_data.act_directory = id;
801 }
802 return result;
803 }
804 case SIM_DF_GRAPHICS:
805 directory = SIM_DF_TELECOM; /* parent directory */
806 /* no break */
807 /*lint -fallthrough*/
808 case SIM_DF_SOLSA:
809 case SIM_DF_MEXE:
810 if (sim_data.act_directory EQ id)
811 return SIM_NO_ERROR; /* already selected */
812
813 if (sim_data.act_directory NEQ directory)
814 { /* not the parent directory */
815 /* If current directory is MF or first level OR if the 2nd level
816 directory is under another 1st level df, select the parent directory */
817 if((sim_data.act_directory & 0xFF00) NEQ 0x5F00 ||
818 (!SIM_IS_DF_LEVEL2_UNDER_DF_LEVEL1(sim_data.act_directory,directory)) )
819 {
820 result = FKT_Select (directory, FALSE, NULL, data, len);
821 if (result NEQ SIM_NO_ERROR)
822 {
823 sim_data.act_directory = NOT_PRESENT_16BIT;
824 return result;
825 }
826 }
827 }
828 result = fkt_select_one (id, data, len);
829 if (result NEQ SIM_NO_ERROR)
830 {
831 sim_data.act_directory = NOT_PRESENT_16BIT;
832 sim_data.act_field = NOT_PRESENT_16BIT;
833 }
834 else
835 {
836 sim_data.dir_status_len = sim_data.sim_data_len;
837 sim_data.act_directory = id;
838 }
839 return result;
840
841 case SIM_ICCID:
842 case SIM_ELP:
843 /*
844 * Access to Root Directory
845 */
846 directory = SIM_MF;
847 break;
848
849 case SIM_ADN:
850 case SIM_FDN:
851 case SIM_SMS:
852 case SIM_CCP:
853 case SIM_MSISDN:
854 case SIM_SMSP:
855 case SIM_SMSS:
856 case SIM_LND:
857 case SIM_SMSR:
858 case SIM_SDN:
859 case SIM_EXT1:
860 case SIM_EXT2:
861 case SIM_EXT3:
862 case SIM_BDN:
863 case SIM_EXT4:
864 /* VO temp PATCH: Needed for reading CPHS info num from old SIMs */
865 case SIM_CPHS_INFN2:
866 /* VO temp PATCH end */
867 /*
868 * Access to Telecom Directory
869 */
870 directory = SIM_DF_TELECOM;
871 break;
872
873 case SIM_LP:
874 case SIM_IMSI:
875 case SIM_KC:
876 case SIM_PLMNSEL:
877 case SIM_HPLMN:
878 case SIM_ACMMAX:
879 case SIM_SST:
880 case SIM_ACM:
881 case SIM_GID1:
882 case SIM_GID2:
883 case SIM_PUCT:
884 case SIM_CBMI:
885 case SIM_SPN:
886 case SIM_CBMID:
887 case SIM_BCCH:
888 case SIM_ACC:
889 case SIM_FPLMN:
890 case SIM_LOCI:
891 case SIM_AD:
892 case SIM_PHASE:
893 case SIM_VGCS:
894 case SIM_VGCSS:
895 case SIM_VBS:
896 case SIM_VBSS:
897 case SIM_EMLPP:
898 case SIM_AAEM:
899 case SIM_ECC:
900 case SIM_CBMIR:
901 case SIM_DCK:
902 case SIM_CNL:
903 case SIM_NIA:
904 case SIM_KCGPRS:
905 case SIM_LOCGPRS:
906 case SIM_SUME:
907 case SIM_CPHS_VMW:
908 case SIM_CPHS_SST:
909 case SIM_CPHS_CFF:
910 case SIM_CPHS_ONSTR:
911 case SIM_CPHS_CSP:
912 case SIM_CPHS_CINF:
913 case SIM_CPHS_MBXN:
914 case SIM_CPHS_ONSHF:
915 case SIM_CPHS_INFN:
916
917 #ifdef REL99
918 case SIM_UCPS_ACTEC:
919 case SIM_OCPS_ACTEC:
920 case SIM_HPLMN_ACT:
921 case SIM_CPBCCH:
922 case SIM_INV_SCAN:
923 case SIM_RPLMN_ACT:
924 #endif /* REL99 */
925 case SIM_PNN:
926 case SIM_OPL:
927
928 /*
929 * Access to GSM
930 */
931 directory = (SIM_IS_FLAG_SET (GSM_DATAFIELD))?
932 SIM_DF_GSM: SIM_DF_1800;
933 break;
934
935 #ifndef REL99
936 case SIM_VI_HZ_PARAM:
937 case SIM_VI_HZ_CACHE_1:
938 case SIM_VI_HZ_CACHE_2:
939 case SIM_VI_HZ_CACHE_3:
940 case SIM_VI_HZ_CACHE_4:
941 directory = SIM_DF_VI;
942 break;
943 #endif /* ifndef REL99 */
944
945 case SIM_MEXE_ST:
946 case SIM_ORPK:
947 case SIM_ARPK:
948 case SIM_TPRPK:
949 /*
950 * Access to MExE Directory
951 */
952 directory = SIM_DF_MEXE;
953 break;
954 case SIM_IMG:
955 /*
956 * Access to Icon Directory
957 */
958 directory = SIM_DF_GRAPHICS;
959 break;
960
961 case SIM_ORANGE_DYN2_FLAG:
962 case SIM_ORANGE_CSP2:
963 case SIM_ORANGE_ACM2:
964 case SIM_ORANGE_DYN_FLAGS:
965 /*
966 * Access to Orange Directory
967 */
968 directory = SIM_DF_ORANGE;
969 break;
970
971 case SIM_SAI:
972 case SIM_SLL:
973 /*
974 * Access to SoLSA Directory
975 */
976 directory = SIM_DF_SOLSA;
977 break;
978 }
979 }
980
981 if (sim_data.act_directory NEQ directory)
982 {
983 /*
984 * select directory
985 */
986 #ifdef _SIMULATION_
987
988 if( (data NEQ NULL) AND (len NEQ 0) )
989 first_time_into_fkt_select = FALSE;
990 #endif
991 result = FKT_Select (directory, FALSE, NULL, data, len);
992 if (result NEQ SIM_NO_ERROR) /* directory selection fails */
993 {
994 sim_data.act_directory = NOT_PRESENT_16BIT;
995 sim_data.act_field = NOT_PRESENT_16BIT;
996 return result;
997 }
998 }
999
1000 if (sim_data.act_field NEQ id)
1001 {
1002 /*
1003 * secondly select elementary field
1004 */
1005 result = fkt_select_one (id, data, len);
1006 if (result NEQ SIM_NO_ERROR) /* EF selection fails */
1007 {
1008 sim_data.act_field = NOT_PRESENT_16BIT;
1009 #ifdef __INVALID /* more sophisticated SELECT error handling */
1010
1011 sw1 = (UBYTE)(SIM_Status_Extended ((UBYTE *)response, 6, &size) >> 8);
1012
1013 if (sw1 NEQ 0x90 AND sw1 NEQ 0x91)
1014 /*
1015 * SIM Status request failed
1016 */
1017 sim_data.act_directory = NOT_PRESENT_16BIT;
1018 else if (((response[4] << 8) | response[5])
1019 NEQ sim_data.act_directory)
1020 /*
1021 * SIM Presence Detection indicates invalid SIM
1022 */
1023 sim_data.act_directory = NOT_PRESENT_16BIT;
1024 #endif
1025 }
1026 else
1027 {
1028 sim_data.act_directory = directory;
1029 sim_data.act_field = id;
1030 }
1031 return result;
1032 }
1033 else
1034 /*
1035 * field is already selected
1036 */
1037 return SIM_NO_ERR_FILE_ALREADY_SELECTED;
1038 }
1039
1040
1041
1042 /*
1043 +--------------------------------------------------------------------+
1044 | PROJECT : GSM-PS (6302) MODULE : SIM_FKT |
1045 | STATE : code ROUTINE : FKT_UnblockCHV |
1046 +--------------------------------------------------------------------+
1047
1048 PURPOSE : Wrapping function for the SIM driver call SIM_UnblockCHV.
1049
1050 */
1051
1052 GLOBAL USHORT FKT_UnblockCHV (UBYTE * unblockCHV,
1053 UBYTE * new_CHV,
1054 UBYTE chvType)
1055 {
1056 USHORT size = 0;
1057 USHORT sw1sw2;
1058 UBYTE response[4];
1059
1060 TRACE_FUNCTION ("FKT_UnblockCHV()");
1061
1062 sw1sw2 = SIM_UnblockCHV ((UBYTE *)response,
1063 (UBYTE *)unblockCHV,
1064 (UBYTE *)new_CHV,
1065 (UBYTE)chvType,
1066 &size);
1067
1068 return FKT_convert_error (sw1sw2, size);
1069 }
1070
1071
1072 /*
1073 +--------------------------------------------------------------------+
1074 | PROJECT : GSM-PS (6302) MODULE : SIM_FKT |
1075 | STATE : code ROUTINE : FKT_UpdateBinary |
1076 +--------------------------------------------------------------------+
1077
1078 PURPOSE : Wrapping function for the SIM driver call SIM_UpdateBinary.
1079
1080 */
1081
1082 GLOBAL USHORT FKT_UpdateBinary (UBYTE * data,
1083 USHORT length,
1084 USHORT offset)
1085 {
1086 USHORT size = 0;
1087 USHORT sw1sw2;
1088 UBYTE response [4];
1089
1090 TRACE_FUNCTION ("FKT_UpdateBinary()");
1091
1092 sw1sw2 = SIM_UpdateBinary ((UBYTE *)response,
1093 (UBYTE *)data,
1094 offset,
1095 length,
1096 &size);
1097
1098 return FKT_convert_error (sw1sw2, size);
1099 }
1100
1101
1102 /*
1103 +--------------------------------------------------------------------+
1104 | PROJECT : GSM-PS (6302) MODULE : SIM_FKT |
1105 | STATE : code ROUTINE : FKT_UpdateRecord |
1106 +--------------------------------------------------------------------+
1107
1108 PURPOSE : Wrapping function for the SIM driver call SIM_UpdateRecord.
1109
1110 */
1111
1112 GLOBAL USHORT FKT_UpdateRecord (UBYTE * data,
1113 USHORT length,
1114 UBYTE mode,
1115 USHORT record)
1116 {
1117 USHORT size = 0;
1118 USHORT sw1sw2;
1119 UBYTE response [4];
1120
1121 #if !defined NTRACE
1122 char buf[48];
1123 sprintf (buf, "FKT_UpdateRecord(): Nr. %hu", record);
1124 TRACE_FUNCTION (buf);
1125 #endif
1126
1127 sw1sw2 = SIM_UpdateRecord ((UBYTE *)response,
1128 (UBYTE *)data,
1129 (UBYTE)mode,
1130 (UBYTE)record,
1131 length,
1132 &size);
1133
1134 return FKT_convert_error (sw1sw2, size);
1135 }
1136
1137
1138
1139 /*
1140 +--------------------------------------------------------------------+
1141 | PROJECT : GSM-PS (6302) MODULE : SIM_FKT |
1142 | STATE : code ROUTINE : FKT_VerifyCHV |
1143 +--------------------------------------------------------------------+
1144
1145 PURPOSE : Wrapping function for the SIM driver call SIM_VerifyCHV.
1146
1147 */
1148
1149 GLOBAL USHORT FKT_VerifyCHV (UBYTE * pin,
1150 UBYTE pin_id)
1151 {
1152 USHORT size = 0;
1153 USHORT sw1sw2;
1154 UBYTE response[4];
1155
1156 TRACE_FUNCTION ("FKT_VerifyCHV()");
1157
1158 sw1sw2 = SIM_VerifyCHV ((UBYTE *)response,
1159 (UBYTE *)pin,
1160 (UBYTE)pin_id,
1161 &size);
1162
1163 return FKT_convert_error (sw1sw2, size);
1164 }
1165
1166 /*
1167 +********************************************************************+
1168 | Moved from sim_stk.c - for CQ 34109 under feature flag SIM_TOOLKIT |
1169 +********************************************************************+
1170 */
1171
1172 #ifdef SIM_TOOLKIT
1173
1174 static const UBYTE timer_env[] = {
1175 STK_TIMER_EXPIRATION_TAG,
1176 STK_DEVICE_IDENTITY_LEN+STK_TIMER_ID_LEN+STK_TIMER_VALUE_LEN+6,
1177 STK_DEVICE_IDENTITY_TAG|STK_COMPREHENSION_REQUIRED, STK_DEVICE_IDENTITY_LEN, 0x82, 0x81,
1178 STK_TIMER_ID_TAG|STK_COMPREHENSION_REQUIRED, STK_TIMER_ID_LEN, 0,
1179 STK_TIMER_VALUE_TAG|STK_COMPREHENSION_REQUIRED, STK_TIMER_VALUE_LEN, 0, 0, 0
1180 };
1181
1182 UBYTE pending_timers[9] = {0,0,0,0,0,0,0,0,0};
1183 UBYTE next_pos_to_fill = 0;
1184 UBYTE next_pos_to_send = 0;
1185
1186 /*
1187 +--------------------------------------------------------------------+
1188 | PROJECT : GSM-PS (8419) MODULE : SIM_STK |
1189 | STATE : code ROUTINE : FKT_TerminalResponse |
1190 +--------------------------------------------------------------------+
1191
1192 PURPOSE : Wrapping function for the SIM driver call SIM_TerminalResponse
1193
1194 */
1195
1196 GLOBAL USHORT FKT_TerminalResponse (UBYTE * data,
1197 USHORT length)
1198 {
1199 USHORT size = 0;
1200 USHORT sw1sw2;
1201 UBYTE response[4];
1202 UBYTE env[sizeof(timer_env)];
1203 USHORT index;
1204 UBYTE dummy[4];
1205 USHORT error;
1206 USHORT i;
1207
1208 TRACE_FUNCTION ("FKT_TerminalResponse()");
1209
1210 sw1sw2 = SIM_TerminalResponse (response,
1211 data,
1212 length,
1213 &size);
1214 sim_data.term_resp_sent = TRUE;
1215
1216 SIM_EM_TERMINAL_RESPONSE;
1217 /*
1218 * if SIM response is OK, try resending pending timer expiry envelopes (send updated envelopes)
1219 */
1220 if( 0x9000 == sw1sw2 )
1221 {
1222 for(i=0;i<8;i++)
1223 {
1224 if (next_pos_to_fill != next_pos_to_send)
1225 {
1226 /*
1227 * some timer expiry envelopes are pending
1228 */
1229 index = pending_timers[next_pos_to_send];
1230 memcpy (env, timer_env, sizeof(timer_env));
1231 env[8] = (UBYTE)(index + 1); /* Timer number range is 1..8 */
1232 env[11] = sim_data.timer[index].hour;
1233 env[12] = sim_data.timer[index].minute;
1234 env[13] = sim_data.timer[index].second;
1235 error = FKT_Envelope (dummy, env, sizeof(timer_env),0);
1236 if(8 == next_pos_to_send)
1237 {
1238 next_pos_to_send = 0;
1239 }
1240 else
1241 {
1242 next_pos_to_send++;
1243 }
1244 if (error NEQ SIM_NO_ERROR)
1245 {
1246 break;
1247 }
1248 }
1249 }
1250 }
1251
1252 return FKT_convert_error (sw1sw2, size);
1253 }
1254
1255
1256 /*
1257 +--------------------------------------------------------------------+
1258 | PROJECT : GSM-PS (8419) MODULE : SIM_STK |
1259 | STATE : code ROUTINE : FKT_Envelope |
1260 +--------------------------------------------------------------------+
1261
1262 PURPOSE : Wrapping function for the SIM driver call SIM_Envelope
1263
1264 */
1265
1266 GLOBAL USHORT FKT_Envelope (UBYTE * data_out, UBYTE * data_in,
1267 USHORT in_length, USHORT out_length)
1268 {
1269
1270 USHORT size = 0;
1271 USHORT sw1sw2;
1272 USHORT error;
1273
1274
1275 TRACE_FUNCTION ("FKT_Envelope()");
1276
1277 sw1sw2 = SIM_Envelope (data_out,
1278 data_in,
1279 in_length,
1280 &size);
1281
1282 SIM_EM_ENVELOPE;
1283
1284 error = FKT_convert_error (sw1sw2, size);
1285
1286 if(sw1sw2 EQ 0x9000)
1287 sim_data.sim_data_len = 0;
1288
1289 if (error EQ SIM_NO_ERROR)
1290 {
1291 if (data_out AND out_length)
1292 {
1293 if (sim_data.sim_data_len > 0)
1294 {
1295 stk_l_cmd = sim_data.sim_data_len << 3;
1296 out_length = (USHORT) (stk_l_cmd >> 3);
1297 error = FKT_GetResponse (data_out, out_length);
1298 }
1299 }
1300 }
1301
1302 return error;
1303
1304 }
1305
1306 /*
1307 +--------------------------------------------------------------------+
1308 | PROJECT : GSM-PS (8419) MODULE : SIM_STK |
1309 | STATE : code ROUTINE : FKT_TerminalProfile |
1310 +--------------------------------------------------------------------+
1311
1312 PURPOSE : Wrapping function for the SIM driver call SIM_TerminalProfile
1313
1314 */
1315
1316 GLOBAL USHORT FKT_TerminalProfile (UBYTE * data,
1317 USHORT length)
1318 {
1319 USHORT size = 0;
1320 USHORT sw1sw2;
1321 UBYTE response[4];
1322
1323 TRACE_FUNCTION ("FKT_TerminalProfile()");
1324
1325 sw1sw2 = SIM_TerminalProfile (response,
1326 data,
1327 length,
1328 &size);
1329
1330 return FKT_convert_error (sw1sw2, size);
1331
1332 }
1333
1334
1335 /*
1336 +--------------------------------------------------------------------+
1337 | PROJECT : GSM-PS (8419) MODULE : SIM_STK |
1338 | STATE : code ROUTINE : FKT_Fetch |
1339 +--------------------------------------------------------------------+
1340
1341 PURPOSE : Wrapping function for the SIM driver call SIM_Fetch
1342
1343 */
1344
1345 GLOBAL USHORT FKT_Fetch (UBYTE * cmd,
1346 USHORT length)
1347 {
1348 USHORT size = 0;
1349 USHORT sw1sw2;
1350
1351 TRACE_FUNCTION ("FKT_Fetch()");
1352
1353 sw1sw2 = SIM_Fetch (cmd,
1354 length,
1355 &size);
1356
1357 return FKT_convert_error (sw1sw2, size);
1358
1359 }
1360
1361 #endif /* SIM_TOOLKIT */
1362
1363 #endif