comparison src/g23m-gsm/sim/uicc_fkt.c @ 104:27a4235405c6

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