comparison g23m-gsm/sim/sim_fkt.c @ 0:75a11d740a02

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