comparison src/g23m-gsm/sim/sim_app.c @ 1:d393cd9bb723

src/g23m-*: initial import from Magnetite
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 15 Jul 2018 04:40:46 +0000
parents
children
comparison
equal deleted inserted replaced
0:b6a5e36de839 1:d393cd9bb723
1 /*
2 +-----------------------------------------------------------------------------
3 | Project : GSM-F&D (8411)
4 | Modul : SIM_APP
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 SIM Application.
18 +-----------------------------------------------------------------------------
19 */
20
21 #ifndef SIM_APP_C
22 #define SIM_APP_C
23
24 #define ENTITY_SIM
25
26 /*==== INCLUDES ===================================================*/
27
28 #include <string.h>
29 #include "typedefs.h"
30 #include "pcm.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 #ifdef TI_PS_UICC_CHIPSET_15
46 #include "8010_136_SIMDRV_SAP_inline.h"
47 #endif
48
49 /*==== EXPORT =====================================================*/
50
51 /*==== PRIVAT =====================================================*/
52
53 /*==== VARIABLES ==================================================*/
54 GLOBAL T_FIELD_STATUS field_status;
55
56 /*==== FUNCTIONS ==================================================*/
57
58
59 LOCAL UBYTE app_read_sim_service_table (T_SIM_MMI_INSERT_IND * sim_mmi_insert_ind);
60 LOCAL USHORT app_get_ef_size(USHORT service, USHORT ef_name, UBYTE* res);
61 #ifdef TI_PS_UICC_CHIPSET_15
62 GLOBAL void app_sim_insert( T_SIMDRV_atr_string_info *atr_string_info,
63 U8 config_requested,
64 T_SIMDRV_config_characteristics *config_characteristics);
65
66 #ifdef _SIMULATION_
67 GLOBAL UBYTE sim_command_type;
68 #endif
69
70 #endif /* TI_PS_UICC_CHIPSET_15 */
71
72 #ifndef TI_PS_UICC_CHIPSET_15
73 #define SIMDRV_MAX_RESULT 0x100
74 #endif
75
76
77 /* Implements Measure# 2 to 8 */
78 /* Table */
79 #ifdef TI_PS_HCOMM_CHANGE
80 T_HANDLE const hComm_mux[] = {_hCommMMI, _hCommMM, _hCommSMS};
81 #else
82 T_HANDLE* const hComm_mux[] = {&sim_hCommMMI, &sim_hCommMM, &sim_hCommSMS};
83 #endif
84
85 /*
86 +--------------------------------------------------------------------+
87 | PROJECT : GSM-PS MODULE : SIM_APP |
88 | STATE : code ROUTINE : app_get_ef_size |
89 +--------------------------------------------------------------------+
90
91 PURPOSE : Return size of the Elementory file. If Elementory file is
92 not present return 0.
93
94 */
95
96 LOCAL USHORT app_get_ef_size(USHORT service, USHORT ef_name, UBYTE *res)
97 {
98
99 if (SIM_IS_FLAG_SET (service))
100 {
101 T_FIELD_STATUS field_status;
102
103 if (FKT_Select (ef_name, FALSE, NULL, res, SIM_MIN_EF_ST_LEN) EQ SIM_NO_ERROR)
104 {
105 memcpy(&field_status, res, SIM_MIN_EF_ST_LEN);
106 return((((USHORT)field_status.field_size[0]) << 8)
107 | (USHORT)field_status.field_size[1]);
108 }
109 }
110
111 return 0;
112
113 }
114
115 /* Implements Measure# 18 */
116 /*
117 +----------------------------------------------------------------------+
118 | PROJECT : GSM-PS (6302) MODULE : SIM_APP |
119 | STATE : code ROUTINE : app_sim_read_n_update_req |
120 +----------------------------------------------------------------------+
121
122 PURPOSE : Process the primitive SIM_READ_REQ and SIM_UPDATE_REQ
123
124 */
125 LOCAL void app_sim_read_n_update_req(USHORT *cause, USHORT *datafield, UBYTE rd_upd_access, U8 *v_path_info, T_path_info *path_info)
126 {
127 UBYTE response[SIMDRV_MAX_RESULT];
128
129
130 TRACE_FUNCTION ("app_sim_read_n_update_req()");
131
132
133 /* if SIM is inserted, try to select the SIM card.*/
134 *cause = FKT_Select (*datafield, *v_path_info, path_info, response, SIM_MIN_EF_ST_LEN);
135
136 if (*cause EQ SIM_NO_ERROR)
137 {
138 memcpy(&field_status, response, SIM_MIN_EF_ST_LEN);
139
140 sim_data.act_length = (USHORT)field_status.field_size[0] * 256 +
141 field_status.field_size[1];
142 }
143
144 if ((*cause EQ SIM_NO_ERROR) OR (*cause EQ SIM_NO_ERR_FILE_ALREADY_SELECTED))
145 {
146 /* field_status is global and has been updated either
147 * in "if" above or during previous operation on same file
148 */
149 if (!(sim_data.act_access = app_check_access_conditions (rd_upd_access,
150 &field_status)))
151 {
152 /* access not allowed */
153 *cause = SIM_CAUSE_ACCESS_PROHIBIT;
154 }
155 else
156 {
157 *cause = SIM_NO_ERROR;
158 }
159 }
160
161 }
162
163
164 /* Implements Measure# 14 */
165 /*
166 +-------------------------------------------------------------------------------+
167 | PROJECT : GSM-PS (6302) MODULE : SIM_APP |
168 | STATE : code ROUTINE : app_sim_activate_req_fdn_enable |
169 +-------------------------------------------------------------------------------+
170
171 PURPOSE : Process the SIM activate req for FDN ENABLE and FDN DISABLE cases
172
173 */
174
175 LOCAL void app_sim_activate_req_fdn_enable(BOOL sim_fdn_en)
176 {
177 ULONG support_flag, service_flag;
178 USHORT error, (*FKT_FuncPtr)(void);
179
180 TRACE_FUNCTION ("app_sim_activate_req_fdn_enable()");
181
182 if(sim_fdn_en EQ TRUE)
183 {
184 support_flag = ADN_SUPPORT_BY_SIM;
185 service_flag = SERVICE_3_SUPPORT;
186 FKT_FuncPtr = FKT_Invalidate ;
187 }
188 else
189 {
190 support_flag = FDN_SUPPORT_BY_SIM;
191 service_flag = SERVICE_2_SUPPORT;
192 FKT_FuncPtr = FKT_Rehabilitate ;
193 }
194
195 if (SIM_IS_FLAG_SET (support_flag))
196 {
197 if (SIM_IS_FLAG_SET (service_flag))
198 {
199 sim_data.last_requested_pin_no = LRP_PIN_2;
200 error = FKT_Select (SIM_ADN, FALSE, NULL, NULL, 0);
201 if (error EQ SIM_NO_ERROR OR error EQ SIM_NO_ERR_FILE_ALREADY_SELECTED)
202 {
203 error = FKT_FuncPtr();
204 if (error EQ SIM_NO_ERROR)
205 {
206 if(sim_fdn_en EQ FALSE)
207 {
208 if (!app_check_imsi_loci_validation())
209 {
210 if (!app_rehabilitate_imsi_loci())
211 {
212 app_sim_card_error (SIM_CAUSE_EF_INVALID);
213 return ; /* return is replaced for break */
214 }
215 }
216 SIM_SET_FLAG (ADN_SUPPORT_BY_SIM);
217 }
218 else
219 SIM_SET_FLAG (FDN_SUPPORT_BY_SIM);
220 SIM_CLEAR_FLAG (support_flag);
221 app_sim_card_error (SIM_NO_ERROR);
222 }
223 else
224 app_sim_card_error (error);
225 }
226 else
227 app_sim_card_error (error);
228
229 if(sim_fdn_en EQ TRUE)
230 {
231 SIM_EM_FDN_ENABLE;
232 }
233 else
234 {
235 SIM_EM_ADN_ENABLE;
236 }
237
238 }
239 else
240 app_sim_card_error (SIM_CAUSE_ACCESS_PROHIBIT);
241 }
242 else
243 app_sim_card_error (SIM_NO_ERROR);
244 }
245
246
247
248
249 /*
250 * -------------------------------------------------------------------
251 * PRIMITIVE Processing functions
252 * -------------------------------------------------------------------
253 */
254 /*lint -e720 (boolean test of assignment) */
255 /*
256 +--------------------------------------------------------------------+
257 | PROJECT : GSM-PS (6302) MODULE : SIM_APP |
258 | STATE : code ROUTINE : app_init_sim_data |
259 +--------------------------------------------------------------------+
260
261 PURPOSE : Initialize the SIM data for the module application.
262
263 */
264
265 GLOBAL void app_init_sim_data (void)
266 {
267 #ifdef SIM_TOOLKIT
268 int i;
269 #endif
270
271 TRACE_FUNCTION ("app_init_sim_data()");
272 /*
273 * initialize all internal flags
274 */
275 sim_data.flags = 0;
276
277 sim_data.last_requested_pin_no = LRP_NONE;
278 /*
279 sim_data.pin_no_puct = NOT_PRESENT_8BIT;
280 sim_data.pin_no_acm = NOT_PRESENT_8BIT;
281 sim_data.pin_no_acmmax = NOT_PRESENT_8BIT;
282 */
283
284 sim_data.act_directory = NOT_PRESENT_16BIT;
285 sim_data.act_field = NOT_PRESENT_16BIT;
286 sim_data.remove_error = SIM_CAUSE_CARD_REMOVED;
287
288 #ifdef SIM_TOOLKIT
289 sim_data.sync_awaited = 0;
290
291 /* startup with idle polling, after 11.11[11.2.8] */
292 sim_data.idle_polling = TRUE;
293
294 for (i = 0; i < MAX_SAT_TIMER; i++)
295 {
296 sim_data.timer[i].active = FALSE;
297 }
298 #endif
299
300 #ifndef TI_PS_UICC_CHIPSET_15
301 SIM_Init (app_sim_insert, app_sim_remove);
302 #else
303 simdrv_register(app_sim_insert, app_sim_remove);
304 #endif
305 }
306
307 /*
308 +--------------------------------------------------------------------+
309 | PROJECT : GSM-PS (6302) MODULE : SIM_APP |
310 | STATE : code ROUTINE : app_sim_read_req |
311 +--------------------------------------------------------------------+
312
313 PURPOSE : Process the primitive SIM_READ_REQ.
314
315 */
316
317 GLOBAL void app_sim_read_req (T_SIM_READ_REQ * sim_read_req)
318 {
319 USHORT source;
320
321 PALLOC (sim_read_cnf, SIM_READ_CNF);
322
323 TRACE_FUNCTION ("app_sim_read_req()");
324
325 // initialize answer
326 source = sim_read_req->source;
327 sim_read_cnf->req_id = sim_read_req->req_id;
328
329 if (SIM_IS_FLAG_SET (SIM_INSERT))
330 {
331 /*
332 * If unknown length request, a Select must be
333 * carried out in any case to determine real length
334 */
335 if (sim_read_req->length EQ NOT_PRESENT_8BIT)
336 {
337 sim_data.act_field = NOT_PRESENT_16BIT;
338 }
339
340 /* Implements Measure# 18 */
341 app_sim_read_n_update_req(&sim_read_cnf->cause, &sim_read_req->datafield, ACCESS_READ,&sim_read_req->v_path_info ,&sim_read_req->path_info);
342
343
344 if (sim_read_cnf->cause EQ SIM_NO_ERROR)
345 {
346 if (sim_read_req->length EQ NOT_PRESENT_8BIT)
347 {
348 // unknown length, must be calculated by the entity
349 if (sim_read_req->offset < sim_data.act_length)
350 {
351 sim_read_cnf->length = (UBYTE)(sim_data.act_length - sim_read_req->offset);
352 }
353 else
354 {
355 // incorrect offset
356 sim_read_cnf->cause = SIM_CAUSE_PARAM_WRONG;
357 }
358 }
359 else
360 {
361 sim_read_cnf->length = sim_read_req->length;
362 // check given length
363 if (((USHORT)sim_read_req->offset + sim_read_req->length) <= sim_data.act_length)
364 {
365 sim_read_cnf->length = sim_read_req->length;
366 }
367 else
368 {
369 // incorrect offset and/or length
370 sim_read_cnf->cause = SIM_CAUSE_PARAM_WRONG;
371 }
372 }
373 }
374 }
375 else
376 {
377 // sim is not inserted
378 sim_read_cnf->cause = SIM_CAUSE_CARD_REMOVED;
379 }
380
381 if (sim_read_cnf->cause EQ SIM_NO_ERROR)
382 {
383 // cut length if needed
384 if ((sim_read_req->max_length > 0) AND
385 (sim_read_cnf->length > sim_read_req->max_length))
386 sim_read_cnf->length = sim_read_req->max_length;
387 // length is available then read and start status timer again
388 sim_read_cnf->cause = FKT_ReadBinary (sim_read_cnf->trans_data,
389 sim_read_req->offset,
390 (USHORT)sim_read_cnf->length);
391 app_start_status_timer (FALSE);
392 }
393 else
394 {
395 sim_read_cnf->length = 0;
396 memset (sim_read_cnf->trans_data, 0, sizeof (sim_read_cnf->trans_data));
397 }
398
399 SIM_EM_READ_BINARY_FILE;
400
401 // free incoming primitive
402 PFREE (sim_read_req);
403
404 /* Implements Measure# 2 */
405 #ifdef TI_PS_HCOMM_CHANGE
406 vsi_c_psend (hComm_mux[source], (T_VOID_STRUCT*) sim_read_cnf FILE_LINE_MACRO);
407 #else
408 vsi_c_psend (*hComm_mux[source], (T_VOID_STRUCT*) sim_read_cnf FILE_LINE_MACRO);
409 #endif
410
411 }
412
413 /*
414 +--------------------------------------------------------------------+
415 | PROJECT : GSM-PS (6302) MODULE : SIM_APP |
416 | STATE : code ROUTINE : app_sim_read_record_req |
417 +--------------------------------------------------------------------+
418
419 PURPOSE : Process the primitive SIM_READ_RECORD_REQ.
420
421 */
422
423 GLOBAL void app_sim_read_record_req (T_SIM_READ_RECORD_REQ * sim_read_record_req)
424 {
425 USHORT source;
426 UBYTE response[SIMDRV_MAX_RESULT];
427
428 PALLOC (sim_read_record_cnf, SIM_READ_RECORD_CNF);
429
430 TRACE_FUNCTION ("app_sim_read_record_req()");
431
432 source = sim_read_record_req->source;
433 sim_read_record_cnf->req_id = sim_read_record_req->req_id;
434
435 sim_read_record_cnf->max_record = 0;
436
437 if (SIM_IS_FLAG_SET (SIM_INSERT))
438 {
439 sim_read_record_cnf->cause = FKT_Select (sim_read_record_req->datafield,
440 sim_read_record_req->v_path_info, &sim_read_record_req->path_info,
441 response, SIM_MIN_EF_ST_LEN);
442
443 if (sim_read_record_cnf->cause EQ SIM_NO_ERROR)
444 {
445 USHORT total_length;
446 memcpy(&field_status,response,SIM_MIN_EF_ST_LEN);
447 sim_data.field_type = field_status.field_type;
448 sim_data.act_length = (USHORT)field_status.record_length;
449 total_length = (USHORT)field_status.field_size[0] * 256 +
450 field_status.field_size[1];
451 if (field_status.record_length)
452 {
453 sim_read_record_cnf->max_record =
454 total_length / field_status.record_length;
455 }
456 else
457 {
458 sim_read_record_cnf->max_record = 1; /* don't divide by zero */
459 }
460 sim_data.max_record = sim_read_record_cnf->max_record;
461 }
462
463 if ((sim_read_record_cnf->cause EQ SIM_NO_ERROR) OR
464 (sim_read_record_cnf->cause EQ SIM_NO_ERR_FILE_ALREADY_SELECTED))
465 {
466 /* field_status is global and has been updated either
467 * in "if" above or during previous operation on same file
468 */
469 if (!(sim_data.act_access = app_check_access_conditions (ACCESS_READ,
470 &field_status)))
471 {
472 sim_read_record_cnf->cause = SIM_CAUSE_ACCESS_PROHIBIT;
473 }
474 else if ((sim_read_record_req->record EQ 0) OR
475 (sim_read_record_req->record > sim_data.max_record))
476 {
477 sim_read_record_cnf->cause = SIM_CAUSE_ADDR_WRONG;
478 }
479 else
480 {
481 sim_read_record_cnf->cause = SIM_NO_ERROR;
482 sim_read_record_cnf->max_record = sim_data.max_record;
483 sim_read_record_cnf->length = (sim_read_record_req->length > (UBYTE)sim_data.act_length)?
484 (UBYTE)sim_data.act_length: sim_read_record_req->length;
485 }
486 }
487 }
488 else
489 {
490 sim_read_record_cnf->cause = SIM_CAUSE_CARD_REMOVED;
491 }
492
493 if (sim_read_record_cnf->cause EQ SIM_NO_ERROR)
494 {
495 sim_read_record_cnf->cause =
496 FKT_ReadRecord (sim_read_record_cnf->linear_data,
497 4,
498 sim_read_record_req->record,
499 (USHORT)sim_data.act_length);
500 app_start_status_timer (FALSE);
501 }
502 else
503 {
504 sim_read_record_cnf->length = 0;
505 memset (sim_read_record_cnf->linear_data, 0, sizeof (sim_read_record_cnf->linear_data));
506 }
507
508 SIM_EM_READ_RECORD_FILE;
509
510 PFREE (sim_read_record_req);
511
512
513 /* Implements Measure# 2 */
514 #ifdef TI_PS_HCOMM_CHANGE
515 vsi_c_psend (hComm_mux[source], (T_VOID_STRUCT*) sim_read_record_cnf FILE_LINE_MACRO);
516 #else
517 vsi_c_psend (*hComm_mux[source], (T_VOID_STRUCT*) sim_read_record_cnf FILE_LINE_MACRO);
518 #endif
519 }
520
521 /*
522 +--------------------------------------------------------------------+
523 | PROJECT : GSM-PS (6302) MODULE : SIM_APP |
524 | STATE : code ROUTINE : app_sim_update_req |
525 +--------------------------------------------------------------------+
526
527 PURPOSE : Process the primitive SIM_UPDATE_REQ.
528
529 */
530 GLOBAL void app_sim_update_req (T_SIM_UPDATE_REQ * sim_update_req)
531 {
532 USHORT source;
533 PALLOC (sim_update_cnf, SIM_UPDATE_CNF);
534
535 TRACE_FUNCTION ("app_sim_update_req()");
536
537 source = sim_update_req->source;
538 sim_update_cnf->req_id = sim_update_req->req_id;
539 sim_update_cnf->cause = SIM_NO_ERROR;
540
541 if (SIM_IS_FLAG_SET (SIM_INSERT))
542 {
543
544 /* Implements Measure# 18 */
545 app_sim_read_n_update_req(&sim_update_cnf->cause, &sim_update_req->datafield, ACCESS_UPDATE,&sim_update_req->v_path_info ,&sim_update_req->path_info) ;
546
547 if (sim_update_cnf->cause EQ SIM_NO_ERROR)
548 {
549 if ((sim_update_req->offset + (USHORT)sim_update_req->length)
550 > sim_data.act_length)
551 {
552 sim_update_cnf->cause = SIM_CAUSE_PARAM_WRONG;
553 }
554 else
555 {
556 sim_update_cnf->cause =
557 FKT_UpdateBinary (sim_update_req->trans_data,
558 (USHORT)sim_update_req->length,
559 sim_update_req->offset);
560
561 app_start_status_timer (FALSE);
562
563 if ((sim_update_cnf->cause EQ SIM_NO_ERROR) AND (sim_update_req->v_path_info EQ FALSE))
564 {
565 switch(sim_update_req->datafield)
566 {
567 case SIM_PLMNSEL:
568 if (SIM_IS_FLAG_SET (SERVICE_7_SUPPORT))
569 {
570 /*
571 * MM should be notified about the changed file so that MM can read this file.
572 */
573 PALLOC (sim_mm_info_ind, SIM_MM_INFO_IND);
574 sim_mm_info_ind->datafield = sim_update_req->datafield;
575 PSENDX (MM, sim_mm_info_ind);
576 }
577 break;
578 #ifdef REL99
579 case SIM_UCPS_ACTEC:
580 if (SIM_IS_FLAG_SET (SERVICE_43_SUPPORT))
581 {
582 /*
583 * MM should be notified about the changed file so that MM can read this file.
584 */
585 PALLOC (sim_mm_info_ind, SIM_MM_INFO_IND);
586 sim_mm_info_ind->datafield = sim_update_req->datafield;
587 PSENDX (MM, sim_mm_info_ind);
588 }
589 break;
590 #endif
591 default:
592 break;
593 }
594 }
595 }
596 }
597 }
598 else
599 {
600 sim_update_cnf->cause = SIM_CAUSE_CARD_REMOVED;
601 }
602
603 SIM_EM_UPDATE_BINARY_FILE;
604
605 PFREE (sim_update_req);
606
607 #ifdef TI_PS_HCOMM_CHANGE
608 vsi_c_psend (hComm_mux[source], (T_VOID_STRUCT*) sim_update_cnf FILE_LINE_MACRO);
609 #else
610 vsi_c_psend (*hComm_mux[source], (T_VOID_STRUCT*) sim_update_cnf FILE_LINE_MACRO);
611 #endif
612 /* Implements Measure# 3 */
613 }
614 /*
615 +--------------------------------------------------------------------+
616 | PROJECT : GSM-PS (6302) MODULE : SIM_APP |
617 | STATE : code ROUTINE : app_sim_update_record_req |
618 +--------------------------------------------------------------------+
619
620 PURPOSE : Process the primitive SIM_UPDATE_RECORD_REQ.
621
622 */
623
624 GLOBAL void app_sim_update_record_req (T_SIM_UPDATE_RECORD_REQ * sim_update_record_req)
625 {
626 USHORT source;
627 UBYTE response[SIMDRV_MAX_RESULT];
628
629 PALLOC (sim_update_record_cnf, SIM_UPDATE_RECORD_CNF);
630
631 TRACE_FUNCTION ("app_sim_update_record_req()");
632
633 source = sim_update_record_req->source;
634
635 sim_update_record_cnf->req_id = sim_update_record_req->req_id;
636
637 if (SIM_IS_FLAG_SET (SIM_INSERT))
638 {
639 sim_update_record_cnf->cause = FKT_Select (sim_update_record_req->datafield,
640 sim_update_record_req->v_path_info, &sim_update_record_req->path_info,
641 response,SIM_MIN_EF_ST_LEN);
642
643 if (sim_update_record_cnf->cause EQ SIM_NO_ERROR)
644 {
645 USHORT total_length;
646 memcpy(&field_status,response,SIM_MIN_EF_ST_LEN);
647 sim_data.field_type = field_status.field_type;
648 sim_data.act_length = (USHORT)field_status.record_length;
649 total_length = (USHORT)field_status.field_size[0] * 256 +
650 (USHORT)field_status.field_size[1];
651 if (field_status.record_length)
652 {
653 sim_data.max_record = (UBYTE)(total_length / field_status.record_length);
654 }
655 else
656 {
657 sim_data.max_record = 1; /* don't divide by zero */
658 }
659 }
660
661 if ((sim_update_record_cnf->cause EQ SIM_NO_ERROR) OR
662 (sim_update_record_cnf->cause EQ SIM_NO_ERR_FILE_ALREADY_SELECTED))
663 {
664 /* field_status is global and has been updated either
665 * in "if" above or during previous operation on same file
666 */
667 if (!(sim_data.act_access = app_check_access_conditions (ACCESS_UPDATE,
668 &field_status)))
669 {
670 sim_update_record_cnf->cause = SIM_CAUSE_ACCESS_PROHIBIT;
671 }
672 else if ((sim_update_record_req->length > sim_data.act_length) OR
673 ((sim_data.field_type EQ LINEAR_FIXED) AND
674 (sim_update_record_req->record EQ 0)) OR
675 (sim_update_record_req->record > sim_data.max_record))
676 {
677 sim_update_record_cnf->cause = SIM_CAUSE_ADDR_WRONG;
678 }
679 else
680 {
681 if (sim_data.field_type EQ LINEAR_FIXED)
682 {
683 sim_update_record_cnf->cause =
684 FKT_UpdateRecord (sim_update_record_req->linear_data,
685 (USHORT)sim_update_record_req->length,
686 4,
687 sim_update_record_req->record);
688 }
689 else
690 {
691 /*
692 * Cyclic file
693 */
694 sim_update_record_cnf->cause =
695 FKT_UpdateRecord (sim_update_record_req->linear_data,
696 (USHORT)sim_update_record_req->length,
697 3,
698 0);
699 }
700 app_start_status_timer (FALSE);
701 }
702 }
703 }
704 else
705 {
706 sim_update_record_cnf->cause = SIM_CAUSE_CARD_REMOVED;
707 }
708
709 SIM_EM_UPDATE_RECORD;
710
711 PFREE (sim_update_record_req);
712
713 /* Implements Measure# 4 */
714 #ifdef TI_PS_HCOMM_CHANGE
715 vsi_c_psend (hComm_mux[source], (T_VOID_STRUCT*) sim_update_record_cnf FILE_LINE_MACRO);
716 #else
717 vsi_c_psend (*hComm_mux[source], (T_VOID_STRUCT*) sim_update_record_cnf FILE_LINE_MACRO);
718 #endif
719 }
720
721 /*
722 +--------------------------------------------------------------------+
723 | PROJECT : GSM-PS (6302) MODULE : SIM_APP |
724 | STATE : code ROUTINE : app_sim_increment_req |
725 +--------------------------------------------------------------------+
726
727 PURPOSE : Process the primitive SIM_INCREMENT_REQ.
728
729 */
730
731 GLOBAL void app_sim_increment_req (T_SIM_INCREMENT_REQ * sim_increment_req)
732 {
733 USHORT source;
734 UBYTE response[SIMDRV_MAX_RESULT];
735
736 PALLOC (sim_increment_cnf, SIM_INCREMENT_CNF);
737
738 TRACE_FUNCTION ("app_sim_increment_req()");
739
740 source = sim_increment_req->source;
741 sim_increment_cnf->req_id = sim_increment_req->req_id;
742
743 if (SIM_IS_FLAG_SET (SIM_INSERT))
744 {
745 sim_increment_cnf->cause = FKT_Select (sim_increment_req->datafield,
746 sim_increment_req->v_path_info, &sim_increment_req->path_info,
747 response,SIM_MIN_EF_ST_LEN );
748
749 if (sim_increment_cnf->cause EQ SIM_NO_ERROR)
750 {
751 memcpy(&field_status,response,SIM_MIN_EF_ST_LEN);
752 sim_data.field_type = field_status.field_type;
753 }
754 if ((sim_increment_cnf->cause EQ SIM_NO_ERROR) OR
755 (sim_increment_cnf->cause EQ SIM_NO_ERR_FILE_ALREADY_SELECTED))
756 {
757 /* field_status is global and has been updated either
758 * in "if" above or during previous operation on same file
759 */
760 if (!(sim_data.act_access = app_check_access_conditions (ACCESS_INCREASE, &field_status)))
761 {
762 sim_increment_cnf->cause = SIM_CAUSE_ACCESS_PROHIBIT;
763 }
764 else
765 {
766 sim_increment_cnf->cause = SIM_NO_ERROR;
767 }
768 }
769 }
770 else
771 {
772 sim_increment_cnf->cause = SIM_CAUSE_CARD_REMOVED;
773 }
774
775 if (sim_increment_cnf->cause EQ SIM_NO_ERROR)
776 {
777 sim_increment_cnf->cause = FKT_Increase (sim_increment_req->linear_data);
778 sim_increment_cnf->length = 0; /* sim_increment_req ->length; */
779
780 app_start_status_timer (FALSE);
781 }
782 else
783 {
784 memset (&sim_increment_cnf->linear_data, 0, sizeof (sim_increment_cnf->linear_data));
785 sim_increment_cnf->length = 0;
786 }
787
788 SIM_EM_INCREMENT_FILE;
789
790 PFREE (sim_increment_req);
791
792 /* Implements Measure# 5 */
793 #ifdef TI_PS_HCOMM_CHANGE
794 vsi_c_psend (hComm_mux[source], (T_VOID_STRUCT*) sim_increment_cnf FILE_LINE_MACRO);
795 #else
796 vsi_c_psend (*hComm_mux[source], (T_VOID_STRUCT*) sim_increment_cnf FILE_LINE_MACRO);
797 #endif
798 }
799
800 /*
801 +--------------------------------------------------------------------+
802 | PROJECT : GSM-PS (6302) MODULE : SIM_APP |
803 | STATE : code ROUTINE : app_sim_verify_pin_req |
804 +--------------------------------------------------------------------+
805
806 PURPOSE : Process the primitive SIM_VERIFY_PIN_REQ.
807
808 */
809
810 GLOBAL void app_sim_verify_pin_req (T_SIM_VERIFY_PIN_REQ * sim_verify_pin_req)
811 {
812 USHORT source; /* which entity has requested */
813 USHORT error; /* result of operation */
814 /*
815 * allocate buffer for answer
816 */
817 PALLOC (sim_verify_pin_cnf, SIM_VERIFY_PIN_CNF);
818
819 TRACE_FUNCTION ("app_sim_verify_pin_req()");
820
821 SIM_EM_VERIFY_PIN;
822
823 /*
824 * fill the answer
825 */
826 memset (sim_verify_pin_cnf, 0, sizeof(T_SIM_VERIFY_PIN_CNF));
827 source = sim_verify_pin_req->source;
828 sim_verify_pin_cnf->pin_id = sim_verify_pin_req->pin_id;
829 sim_data.last_requested_pin_no = sim_verify_pin_req->pin_id;
830 /*
831 * use SIM driver call for verification
832 */
833 if (SIM_IS_FLAG_SET (SIM_INSERT))
834 {
835 error = FKT_VerifyCHV (sim_verify_pin_req->pin,
836 sim_verify_pin_req->pin_id);
837 }
838 else
839 error = SIM_CAUSE_CARD_REMOVED;
840
841 /*
842 * deallocate incoming primitive
843 */
844 PFREE (sim_verify_pin_req);
845
846 /*
847 * check actual pin/puk counts
848 */
849 FKT_Status (&sim_verify_pin_cnf->pin_cnt,
850 &sim_verify_pin_cnf->pin2_cnt,
851 &sim_verify_pin_cnf->puk_cnt,
852 &sim_verify_pin_cnf->puk2_cnt);
853
854 /*
855 * fill results for answer
856 */
857 sim_verify_pin_cnf->cause = error;
858
859 /* Implements Measure# 6 */
860 #ifdef TI_PS_HCOMM_CHANGE
861 vsi_c_psend (hComm_mux[source], (T_VOID_STRUCT*) sim_verify_pin_cnf FILE_LINE_MACRO);
862 #else
863 vsi_c_psend (*hComm_mux[source], (T_VOID_STRUCT*) sim_verify_pin_cnf FILE_LINE_MACRO);
864 #endif
865 /*
866 * during initialization start
867 * remaining part of initialisation procedure
868 *
869 */
870 if (error EQ SIM_NO_ERROR)
871 {
872 if (SIM_IS_FLAG_CLEARED (MM_KNOWS_FROM_SIM))
873 {
874 app_sim_read_parameters ();
875 app_start_status_timer (TRUE);
876 }
877 else
878 app_start_status_timer (FALSE);
879 }
880 }
881
882 /*
883 +--------------------------------------------------------------------+
884 | PROJECT : GSM-PS (6302) MODULE : SIM_APP |
885 | STATE : code ROUTINE : app_sim_change_pin_req |
886 +--------------------------------------------------------------------+
887
888 PURPOSE : Process the primitive SIM_CHANGE_PIN_REQ.
889
890 */
891
892 GLOBAL void app_sim_change_pin_req (T_SIM_CHANGE_PIN_REQ * sim_change_pin_req)
893 {
894 USHORT source;
895
896 PALLOC (sim_change_pin_cnf, SIM_CHANGE_PIN_CNF);
897
898 TRACE_FUNCTION ("app_sim_change_pin_req()");
899
900 SIM_EM_CHANGE_PIN;
901
902 source = sim_change_pin_req->source;
903 sim_change_pin_cnf->pin_id = sim_change_pin_req->pin_id;
904 sim_data.last_requested_pin_no = sim_change_pin_req->pin_id;
905
906 if (SIM_IS_FLAG_SET (SIM_INSERT))
907 {
908 sim_change_pin_cnf->cause = FKT_ChangeCHV (sim_change_pin_req->old_pin,
909 sim_change_pin_req->new_pin,
910 sim_change_pin_req->pin_id);
911 app_start_status_timer (FALSE);
912 }
913 else
914 sim_change_pin_cnf->cause = SIM_CAUSE_CARD_REMOVED;
915
916 PFREE (sim_change_pin_req);
917
918 /*
919 * check actual pin/puk counts
920 */
921 FKT_Status (&sim_change_pin_cnf->pin_cnt,
922 &sim_change_pin_cnf->pin2_cnt,
923 &sim_change_pin_cnf->puk_cnt,
924 &sim_change_pin_cnf->puk2_cnt);
925
926 /* Implements Measure# 7 */
927 #ifdef TI_PS_HCOMM_CHANGE
928 vsi_c_psend (hComm_mux[source], (T_VOID_STRUCT*) sim_change_pin_cnf FILE_LINE_MACRO);
929 #else
930 vsi_c_psend (*hComm_mux[source], (T_VOID_STRUCT*) sim_change_pin_cnf FILE_LINE_MACRO);
931 #endif
932 }
933
934 /*
935 +--------------------------------------------------------------------+
936 | PROJECT : GSM-PS (6302) MODULE : SIM_APP |
937 | STATE : code ROUTINE : app_sim_disable_pin_req |
938 +--------------------------------------------------------------------+
939
940 PURPOSE : Process the primitive SIM_DISABLE_PIN_REQ.
941
942 */
943
944 GLOBAL void app_sim_disable_pin_req (T_SIM_DISABLE_PIN_REQ * sim_disable_pin_req)
945 {
946 USHORT source;
947
948 PALLOC (sim_disable_pin_cnf, SIM_DISABLE_PIN_CNF);
949
950 TRACE_FUNCTION ("app_sim_disable_pin_req()");
951
952 SIM_EM_DISABLE_PIN;
953
954 /*
955 * store source of request
956 */
957 source = sim_disable_pin_req->source;
958
959 if (SIM_IS_FLAG_SET (SIM_INSERT))
960 {
961 /*
962 * only if a SIM card is inserted
963 */
964 if (SIM_IS_FLAG_SET (SIM_PIN_FLAG))
965 {
966 /*
967 * CHV1 entering was necessary, that means not disabled
968 */
969 if (SIM_IS_FLAG_SET (SERVICE_1_SUPPORT))
970 {
971 /*
972 * SIM card supports disabling of CHV1
973 */
974 sim_data.last_requested_pin_no = LRP_PIN_1;
975 sim_disable_pin_cnf->cause = FKT_DisableCHV (sim_disable_pin_req->pin);
976 app_start_status_timer (FALSE);
977 }
978 else
979 sim_disable_pin_cnf->cause = SIM_CAUSE_ACCESS_PROHIBIT;
980 }
981 else
982 sim_disable_pin_cnf->cause = SIM_NO_ERROR;
983 }
984 else
985 sim_disable_pin_cnf->cause = SIM_CAUSE_CARD_REMOVED;
986
987 if (sim_disable_pin_cnf->cause EQ SIM_NO_ERROR)
988 {
989 SIM_CLEAR_FLAG (SIM_PIN_FLAG);
990 }
991
992 PFREE (sim_disable_pin_req);
993
994 /*
995 * check actual pin/puk counts
996 */
997 FKT_Status (&sim_disable_pin_cnf->pin_cnt,
998 &sim_disable_pin_cnf->pin2_cnt,
999 &sim_disable_pin_cnf->puk_cnt,
1000 &sim_disable_pin_cnf->puk2_cnt);
1001
1002 /* Implements Measure# 2 to 8 */
1003 #ifdef TI_PS_HCOMM_CHANGE
1004 vsi_c_psend (hComm_mux[source], (T_VOID_STRUCT*) sim_disable_pin_cnf FILE_LINE_MACRO);
1005 #else
1006 vsi_c_psend (*hComm_mux[source], (T_VOID_STRUCT*) sim_disable_pin_cnf FILE_LINE_MACRO);
1007 #endif
1008 }
1009
1010 /*
1011 +--------------------------------------------------------------------+
1012 | PROJECT : GSM-PS (6302) MODULE : SIM_APP |
1013 | STATE : code ROUTINE : app_sim_enable_pin_req |
1014 +--------------------------------------------------------------------+
1015
1016 PURPOSE : Process the primitive SIM_ENABLE_PIN_REQ.
1017
1018 */
1019
1020 GLOBAL void app_sim_enable_pin_req (T_SIM_ENABLE_PIN_REQ * sim_enable_pin_req)
1021 {
1022 USHORT source;
1023
1024 PALLOC (sim_enable_pin_cnf, SIM_ENABLE_PIN_CNF);
1025
1026 TRACE_FUNCTION ("app_sim_enable_pin_req()");
1027
1028 SIM_EM_ENABLE_PIN;
1029
1030 source = sim_enable_pin_req->source;
1031
1032 if (SIM_IS_FLAG_SET (SIM_INSERT))
1033 {
1034 if (SIM_IS_FLAG_SET (SIM_PIN_FLAG))
1035 sim_enable_pin_cnf->cause = SIM_NO_ERROR;
1036 else
1037 {
1038 sim_data.last_requested_pin_no = LRP_PIN_1;
1039 sim_enable_pin_cnf->cause = FKT_EnableCHV (sim_enable_pin_req->pin);
1040 app_start_status_timer (FALSE);
1041 }
1042 }
1043 else
1044 sim_enable_pin_cnf->cause = SIM_CAUSE_CARD_REMOVED;
1045
1046 if (sim_enable_pin_cnf->cause EQ SIM_NO_ERROR)
1047 {
1048 SIM_SET_FLAG (SIM_PIN_FLAG);
1049 }
1050
1051 PFREE (sim_enable_pin_req);
1052
1053 /*
1054 * check actual pin/puk counts
1055 */
1056 FKT_Status (&sim_enable_pin_cnf->pin_cnt,
1057 &sim_enable_pin_cnf->pin2_cnt,
1058 &sim_enable_pin_cnf->puk_cnt,
1059 &sim_enable_pin_cnf->puk2_cnt);
1060
1061 /* Implements Measure# 2 to 8 */
1062 #ifdef TI_PS_HCOMM_CHANGE
1063 vsi_c_psend (hComm_mux[source], (T_VOID_STRUCT*) sim_enable_pin_cnf FILE_LINE_MACRO);
1064 #else
1065 vsi_c_psend (*hComm_mux[source], (T_VOID_STRUCT*) sim_enable_pin_cnf FILE_LINE_MACRO);
1066 #endif
1067 }
1068
1069 /*
1070 +--------------------------------------------------------------------+
1071 | PROJECT : GSM-PS (6302) MODULE : SIM_APP |
1072 | STATE : code ROUTINE : app_sim_unblock_req |
1073 +--------------------------------------------------------------------+
1074
1075 PURPOSE : Process the primitive SIM_UNBLOCK_REQ.
1076
1077 */
1078
1079 GLOBAL void app_sim_unblock_req (T_SIM_UNBLOCK_REQ * sim_unblock_req)
1080 {
1081 USHORT source;
1082 USHORT error;
1083
1084 PALLOC (sim_unblock_cnf, SIM_UNBLOCK_CNF);
1085
1086 TRACE_FUNCTION ("app_sim_unblock_req()");
1087
1088 SIM_EM_UNBLOCK_PIN;
1089
1090 /*
1091 * fill the answer
1092 */
1093 memset (sim_unblock_cnf, 0, sizeof(T_SIM_VERIFY_PIN_CNF));
1094 source = sim_unblock_req->source;
1095 sim_unblock_cnf->pin_id = sim_unblock_req->pin_id;
1096
1097 if (SIM_IS_FLAG_SET (SIM_INSERT))
1098 {
1099 if (sim_unblock_req->pin_id EQ PHASE_2_PUK_2)
1100 {
1101 sim_unblock_req->pin_id = UNBL_CHV2; /* PUK2 */
1102 sim_data.last_requested_pin_no = LRP_PUK_2;
1103 }
1104 else
1105 {
1106 sim_unblock_req->pin_id = UNBL_CHV1; /* PUK1 */
1107 sim_data.last_requested_pin_no = LRP_PUK_1;
1108 }
1109 error = FKT_UnblockCHV (sim_unblock_req->unblock_key,
1110 sim_unblock_req->pin,
1111 sim_unblock_req->pin_id);
1112 }
1113 else
1114 error = SIM_CAUSE_CARD_REMOVED;
1115
1116 /*
1117 * deallocate incoming primitive
1118 */
1119 PFREE (sim_unblock_req);
1120
1121 /*
1122 * check actual pin/puk counts regardless the outcome of
1123 * of the UNBLOCK operation
1124 */
1125 FKT_Status (&sim_unblock_cnf->pin_cnt,
1126 &sim_unblock_cnf->pin2_cnt,
1127 &sim_unblock_cnf->puk_cnt,
1128 &sim_unblock_cnf->puk2_cnt);
1129
1130 /*
1131 * after a successful UNBLOCK of CHV1 the PIN is enabled,
1132 * otherwise its state remains unchanged
1133 */
1134 if (error EQ SIM_NO_ERROR AND
1135 sim_data.last_requested_pin_no EQ LRP_PUK_1)
1136 {
1137 SIM_SET_FLAG (SIM_PIN_FLAG);
1138 }
1139 /*
1140 * fill results for answer
1141 */
1142 sim_unblock_cnf->cause = error;
1143
1144 /* Implements Measure# 8 */
1145 #ifdef TI_PS_HCOMM_CHANGE
1146 vsi_c_psend (hComm_mux[source], (T_VOID_STRUCT*) sim_unblock_cnf FILE_LINE_MACRO);
1147 #else
1148 vsi_c_psend (*hComm_mux[source], (T_VOID_STRUCT*) sim_unblock_cnf FILE_LINE_MACRO);
1149 #endif
1150 /*
1151 * during initialization start
1152 * remaining part of initialisation procedure
1153 *
1154 */
1155 if (error EQ SIM_NO_ERROR)
1156 {
1157 if (SIM_IS_FLAG_CLEARED (MM_KNOWS_FROM_SIM))
1158 {
1159 app_sim_read_parameters ();
1160 app_start_status_timer (TRUE);
1161 }
1162 else
1163 app_start_status_timer (FALSE);
1164 }
1165 }
1166
1167 /*
1168 +--------------------------------------------------------------------+
1169 | PROJECT : GSM-PS (6302) MODULE : SIM_APP |
1170 | STATE : code ROUTINE : app_sim_auth_req |
1171 +--------------------------------------------------------------------+
1172
1173 PURPOSE : Process the primitive SIM_AUTHENTICATION_REQ.
1174
1175 */
1176
1177 GLOBAL void app_sim_auth_req (T_SIM_AUTHENTICATION_REQ * sim_authentication_req)
1178 {
1179 USHORT error;
1180 USHORT source;
1181 T_SRES_KC sres_kc;
1182 T_kc_n kc_n;
1183 UBYTE response[SIMDRV_MAX_RESULT];
1184
1185 PALLOC (sim_authentication_cnf, SIM_AUTHENTICATION_CNF);
1186
1187 TRACE_FUNCTION ("app_sim_auth_req()");
1188
1189 SIM_EM_AUTHENTICATION;
1190
1191 memset(response, 0, SIMDRV_MAX_RESULT);
1192 source = sim_authentication_req->source;
1193 kc_n.kc[MAX_KC] = sim_authentication_req->cksn;
1194
1195 sim_authentication_cnf->req_id = sim_authentication_req->req_id;
1196
1197 if (SIM_IS_FLAG_SET (GSM_DATAFIELD))
1198 error = FKT_Select (SIM_DF_GSM, FALSE, NULL, NULL, 0);
1199 else
1200 error = FKT_Select (SIM_DF_1800, FALSE, NULL, NULL, 0);
1201
1202 if ((error EQ SIM_NO_ERROR) OR (error EQ SIM_NO_ERR_FILE_ALREADY_SELECTED))
1203 error = FKT_RunGSMAlgo (sim_authentication_req->rand, response, SIM_GSM_ALG_LEN);
1204
1205 if (error EQ SIM_NO_ERROR)
1206 {
1207 memcpy(&sres_kc,response,SIM_GSM_ALG_LEN);
1208 app_start_status_timer (FALSE);
1209 }
1210 if (error EQ SIM_NO_ERROR)
1211 {
1212 int i;
1213 /*lint -e{645} (when if statement TRUE, then 'sres_kc' valid) */
1214 memcpy (sim_authentication_cnf->sres, sres_kc.sres, 4);
1215
1216 for (i = 0; i < MAX_KC; i++)
1217 sim_authentication_cnf->kc[(MAX_KC-1)-i] = kc_n.kc[i] = sres_kc.kc[i];
1218
1219 switch (source)
1220 {
1221 #if defined (GPRS)
1222 case SRC_GMM:
1223 PSENDX (GMM, sim_authentication_cnf);
1224 if (SIM_IS_FLAG_SET (SERVICE_38_SUPPORT))
1225 {
1226 error = FKT_Select (SIM_KCGPRS, FALSE, NULL, NULL, 0); /* use SIM */
1227 if(error EQ SIM_NO_ERR_FILE_ALREADY_SELECTED)
1228 error = SIM_NO_ERROR;
1229 }
1230 else
1231 { /* use PCM */
1232 T_imsi_field sim_imsi;
1233 error = FKT_Select (SIM_IMSI, FALSE, NULL, NULL, 0);
1234 if ((error EQ SIM_NO_ERROR OR error EQ SIM_NO_ERR_FILE_ALREADY_SELECTED)
1235 AND
1236 FKT_ReadBinary ((UBYTE *)&sim_imsi, 0, MAX_IMSI)
1237 EQ SIM_NO_ERROR)
1238 {
1239 if (gprs_check_pcm_data (&sim_imsi))
1240 pcm_WriteFile((UBYTE *)EF_KCGPRS_ID, SIZE_EF_KCGPRS,
1241 (UBYTE *)kc_n.kc);
1242 }
1243 PFREE (sim_authentication_req);
1244 return;
1245 }
1246 break;
1247 #endif
1248 default:
1249 PSENDX (MM, sim_authentication_cnf);
1250 error = FKT_Select (SIM_KC, FALSE, NULL, NULL, 0);
1251 if(error EQ SIM_NO_ERR_FILE_ALREADY_SELECTED)
1252 error = SIM_NO_ERROR;
1253 break;
1254 }
1255 }
1256
1257 PFREE (sim_authentication_req);
1258
1259 if (error EQ SIM_NO_ERROR)
1260 {
1261 kc_n.c_kc = MAX_KC_N;
1262 FKT_UpdateBinary (kc_n.kc, (USHORT)kc_n.c_kc, 0);
1263 }
1264 //TISH, OMAPS00133714
1265 //start
1266 else
1267 {
1268 sim_data.remove_error = error;
1269 app_sim_remove ();
1270 sim_data.remove_error = SIM_CAUSE_CARD_REMOVED;
1271 }
1272 //end
1273 }
1274
1275 #ifdef TI_PS_UICC_CHIPSET_15
1276 LOCAL void app_require_uicc_characteristics(T_SIMDRV_config_characteristics *config_characteristics)
1277 {
1278 UBYTE clock_stop = 0;
1279 UBYTE voltage_class = 0;
1280
1281 TRACE_FUNCTION("app_require_uicc_characteristics()");
1282 TRACE_EVENT_P1 ("SIMDRV - GSM SIM File Characteristics : 0x%02X", config_characteristics->uicc_characteristics);
1283
1284 clock_stop = (config_characteristics->uicc_characteristics & 0x0D);/*get bit 1,3 and 4*/
1285 voltage_class = (config_characteristics->uicc_characteristics & 0x30);/*get bit 5 and 6*/
1286
1287 switch(voltage_class)
1288 {
1289 case 0x00:/*8GSM 5V - No voltage class bits set.*/
1290 voltage_class = 0x10; /*UMTS CLASS A - Bit 5 set*/
1291 break;
1292 case 0x10:/*GSM 3V - Voltage class bit 5 set.*/
1293 voltage_class = 0x20;/*UMTS CLASS B - Bit 6 set*/
1294 break;
1295 case 0x30:/*GSM 1.8V - Voltage class bit 5 and 6 set.*/
1296 voltage_class = 0x40;/*UMTS CLASS C - Bit 7 set*/
1297 break;
1298 default:
1299 voltage_class = 0x00;
1300 break;
1301 }
1302 config_characteristics->uicc_characteristics = (voltage_class | clock_stop);
1303 TRACE_EVENT_P1 ("SIMDRV - SIM File Characteristics (Converted) : 0x%02X", config_characteristics->uicc_characteristics);
1304 /* Clear traces of the fact that we have already used the card */
1305 sim_data.act_directory = NOT_PRESENT_16BIT;
1306 sim_data.act_field = NOT_PRESENT_16BIT;
1307 }
1308 #endif
1309 /*
1310 +--------------------------------------------------------------------+
1311 | PROJECT : GSM-PS (6302) MODULE : SIM_APP |
1312 | STATE : code ROUTINE : app_sim_insert |
1313 +--------------------------------------------------------------------+
1314
1315 PURPOSE : Hook function for SIM driver after SIM insertion.
1316
1317 */
1318
1319 #ifndef TI_PS_UICC_CHIPSET_15
1320 GLOBAL void app_sim_insert (T_SIM_CARD *p_atr)
1321 #else /*!TI_PS_UICC_CHIPSET_15*/
1322 GLOBAL void app_sim_insert( T_SIMDRV_atr_string_info *atr_string_info,
1323 U8 config_requested,
1324 T_SIMDRV_config_characteristics *config_characteristics)
1325 #endif /*!TI_PS_UICC_CHIPSET_15*/
1326 {
1327 USHORT error;
1328 USHORT length;
1329 T_DIR_STATUS dir_status;
1330 T_FIELD_STATUS field_status;
1331 UBYTE response[SIMDRV_MAX_RESULT];
1332
1333 TRACE_FUNCTION ("app_sim_insert()");
1334
1335 #ifdef TI_PS_UICC_CHIPSET_15
1336 if (atr_string_info NEQ NULL)
1337 {
1338 /*
1339 * stop card detection timer
1340 */
1341 vsi_t_stop (VSI_CALLER SIM_TIMER);
1342 }
1343 else
1344 {
1345 /* SIM reinsert has been automatically detect and hence
1346 inform ACI */
1347 T_SIM_ACTIVATE_CNF * sim_activate_cnf;
1348
1349 PALLOC (sim_activate, SIM_ACTIVATE_IND);
1350 sim_activate_cnf = (T_SIM_ACTIVATE_CNF *)sim_activate;
1351
1352 sim_activate_cnf->cause = SIM_CAUSE_SIM_REINSERTED;
1353
1354 PSENDX (MMI, sim_activate_cnf);
1355
1356 return;
1357 }
1358 #else
1359 /*
1360 * stop card detection timer
1361 */
1362 vsi_t_stop (VSI_CALLER SIM_TIMER);
1363 #endif
1364
1365
1366 #ifdef FF_DUAL_SIM
1367 if(sim_data.SIM_Selection)
1368 {
1369 T_SIM_ACTIVATE_CNF * sim_activate_cnf;
1370
1371 PALLOC (sim_activate, SIM_ACTIVATE_CNF);
1372 sim_activate_cnf = sim_activate;
1373
1374 sim_data.sim_num = SIM_GetSIM();
1375
1376 sim_activate_cnf->cause = SIM_NO_ERROR;
1377 sim_activate_cnf->sim_num = (UBYTE)sim_data.sim_num;
1378
1379 TRACE_EVENT_P1("SIM Selected is %d",sim_activate_cnf->sim_num);
1380
1381 PSENDX (MMI, sim_activate_cnf);
1382
1383 SIM_SET_FLAG (SIM_INSERT);
1384
1385 return;
1386 }
1387 #endif /*FF_DUAL_SIM*/
1388
1389 /*
1390 * As per the section 6.5 of 3GPP TS 11.11, After the Answer To Reset (ATR),
1391 * the Master File (MF) is implicitly selected and becomes the Current Directory.
1392 *
1393 * Set Current Dir to MF, this makes the selection hit the DF_GSM as it is supposed to !
1394 */
1395 sim_data.act_directory = SIM_MF;
1396
1397 /*
1398 * Read Datafield GSM
1399 */
1400 error = FKT_Select (SIM_DF_GSM, FALSE, NULL, response, SIM_MIN_DMF_ST_LEN);
1401 if (error EQ SIM_NO_ERROR OR error EQ SIM_NO_ERR_FILE_ALREADY_SELECTED)
1402 {
1403 length = (sim_data.sim_data_len < SIM_MIN_DMF_ST_LEN)?
1404 sim_data.sim_data_len: SIM_MIN_DMF_ST_LEN;
1405 memcpy(&dir_status,response,SIM_MIN_DMF_ST_LEN);
1406 #ifdef TI_PS_UICC_CHIPSET_15
1407 if (config_requested EQ SIMDRV_REQUEST_CONFIG_CHARACTERISTICS)
1408 {
1409 config_characteristics->uicc_characteristics = dir_status.characteristics;
1410 app_require_uicc_characteristics(config_characteristics);
1411 memset ((UBYTE *)&dir_status + length, 0, SIM_MIN_DMF_ST_LEN - length);
1412 return;
1413 }
1414 #endif
1415 memset ((UBYTE *)&dir_status + length, 0, SIM_MIN_DMF_ST_LEN - length);
1416 }
1417 if (error NEQ SIM_NO_ERROR)
1418 {
1419 /*
1420 * If not possible read Datafield DCS1800
1421 * for backward compatibility reasons
1422 */
1423 error = FKT_Select (SIM_DF_1800, FALSE, NULL, response, SIM_MIN_DMF_ST_LEN);
1424 if (error EQ SIM_NO_ERROR OR error EQ SIM_NO_ERR_FILE_ALREADY_SELECTED)
1425 {
1426 length = (sim_data.sim_data_len < SIM_MIN_DMF_ST_LEN)?
1427 sim_data.sim_data_len: SIM_MIN_DMF_ST_LEN;
1428 memcpy(&dir_status,response,SIM_MIN_DMF_ST_LEN);
1429 #ifdef TI_PS_UICC_CHIPSET_15
1430 if (config_requested EQ SIMDRV_REQUEST_CONFIG_CHARACTERISTICS)
1431 {
1432 config_characteristics->uicc_characteristics = dir_status.characteristics;
1433 app_require_uicc_characteristics(config_characteristics);
1434 memset ((UBYTE *)&dir_status + length, 0, SIM_MIN_DMF_ST_LEN - length);
1435 return;
1436 }
1437 #endif
1438 memset ((UBYTE *)&dir_status + length, 0, SIM_MIN_DMF_ST_LEN - length);
1439 }
1440 SIM_CLEAR_FLAG (GSM_DATAFIELD);
1441 }
1442 else
1443 SIM_SET_FLAG (GSM_DATAFIELD);
1444
1445 if (error NEQ SIM_NO_ERROR)
1446 {
1447 /*
1448 * datafields are not readable
1449 */
1450 if (SIM_IS_FLAG_SET (ACTIVATION_STARTED))
1451 {
1452 app_sim_card_error ((USHORT)((SIM_IS_FLAG_SET(DRV_FAILED_RETRY))?
1453 SIM_CAUSE_DRV_TEMPFAIL: SIM_CAUSE_OTHER_ERROR));
1454 SIM_CLEAR_FLAG (ACTIVATION_STARTED);
1455 }
1456 return;
1457 }
1458
1459 {
1460 T_SIM_ACTIVATE_CNF * sim_activate_cnf;
1461
1462 if (SIM_IS_FLAG_SET (ACTIVATION_STARTED))
1463 {
1464 PALLOC (sim_activate, SIM_ACTIVATE_CNF);
1465 sim_activate_cnf = sim_activate;
1466 }
1467 else
1468 {
1469 PALLOC (sim_activate, SIM_ACTIVATE_IND);
1470 sim_activate_cnf = (T_SIM_ACTIVATE_CNF *)sim_activate;
1471 }
1472 /*
1473 * Read Emergency Call Codes
1474 */
1475 memset (sim_activate_cnf->ec_code, NOT_PRESENT_8BIT, MAX_ECC);
1476 if (FKT_Select (SIM_ECC, FALSE, NULL, response, SIM_MIN_EF_ST_LEN) EQ SIM_NO_ERROR)
1477 {
1478 memcpy(&field_status,response,SIM_MIN_EF_ST_LEN);
1479 {
1480 length = (USHORT)field_status.field_size[0] * 256 +
1481 field_status.field_size[1];
1482 if (length > MAX_ECC)
1483 length = MAX_ECC;
1484 FKT_ReadBinary (sim_activate_cnf->ec_code, 0, length);
1485 }
1486 }
1487 /*
1488 * Read Preferred Language
1489 */
1490 memset (sim_activate_cnf->pref_lang, NOT_PRESENT_8BIT, MAX_LNG_PREF);
1491 if (FKT_Select (SIM_LP, FALSE, NULL, response, SIM_MIN_EF_ST_LEN) EQ SIM_NO_ERROR)
1492 {
1493 memcpy(&field_status,response,SIM_MIN_EF_ST_LEN);
1494 {
1495 length = (USHORT)field_status.field_size[0] * 256 +
1496 field_status.field_size[1];
1497 if (length > MAX_LNG_PREF)
1498 length = MAX_LNG_PREF;
1499 FKT_ReadBinary (sim_activate_cnf->pref_lang, 0, length);
1500 }
1501 }
1502 sim_activate_cnf->cause = SIM_NO_ERROR;
1503 /*
1504 * get ATR data
1505 */
1506
1507 #ifndef TI_PS_UICC_CHIPSET_15
1508 length = MINIMUM(p_atr->atr_size, MAX_SIM_ATR);
1509 sim_activate_cnf->c_atr = (UBYTE)length;
1510 memcpy (sim_activate_cnf->atr, p_atr->atr_data, length);
1511 #else /*!TI_PS_UICC_CHIPSET_15*/
1512 length = MINIMUM(atr_string_info->c_atr_string, MAX_SIM_ATR);
1513 sim_activate_cnf->c_atr = (UBYTE)length;
1514 memcpy (sim_activate_cnf->atr, atr_string_info->atr_string, length);
1515 #endif /*!TI_PS_UICC_CHIPSET_15*/
1516
1517 /*
1518 * check PIN/PUK status
1519 */
1520 SIM_CLEAR_FLAG (SIM_PIN_FLAG);
1521 /*lint -e{644} (only reachable when SIM_NO_ERROR, then 'dir_status' valid) */
1522 sim_activate_cnf->pin_cnt = FKT_check_pin_count (dir_status.pinstatus);
1523 sim_activate_cnf->puk_cnt = FKT_check_pin_count (dir_status.unbstatus);
1524 sim_activate_cnf->pin2_cnt = FKT_check_pin_count (dir_status.pin2status);
1525 sim_activate_cnf->puk2_cnt = FKT_check_pin_count (dir_status.unb2status);
1526
1527
1528 if (sim_activate_cnf->pin_cnt > 0)
1529 {
1530 /*
1531 * card is not blocked
1532 */
1533 if ((dir_status.characteristics & 0x80) EQ 0)
1534 {
1535 /*
1536 * PIN is enabled
1537 */
1538 sim_activate_cnf->cause = SIM_CAUSE_PIN1_EXPECT;
1539 SIM_SET_FLAG (SIM_PIN_FLAG);
1540 }
1541 }
1542 else if (sim_activate_cnf->puk_cnt > 0)
1543 {
1544 /*
1545 * SIM card is blocked, unblock attempts available
1546 */
1547 sim_activate_cnf->cause = SIM_CAUSE_PUK1_EXPECT;
1548 SIM_SET_FLAG (SIM_PIN_FLAG);
1549 }
1550 else
1551 {
1552 /*
1553 * SIM card is blocked, no unblock attempts available
1554 */
1555 TRACE_EVENT ("Card blocked");
1556 sim_activate_cnf->cause = SIM_CAUSE_PUK1_BLOCKED;
1557
1558 SIM_EM_SIM_ACTIVATION_RESULT;
1559
1560 PSENDX (MMI, sim_activate_cnf);
1561 SIM_CLEAR_FLAG (ACTIVATION_STARTED);
1562 return;
1563 }
1564
1565
1566 SIM_EM_SIM_ACTIVATION_RESULT;
1567
1568 PSENDX (MMI, sim_activate_cnf);
1569 SIM_CLEAR_FLAG (ACTIVATION_STARTED);
1570 }
1571
1572 SIM_SET_FLAG (SIM_INSERT);
1573
1574 if (SIM_IS_FLAG_CLEARED (SIM_PIN_FLAG))
1575 /*
1576 * PIN entering is not necessary
1577 */
1578 {
1579 TRACE_EVENT ("Read the rest of Parameters");
1580 app_sim_read_parameters ();
1581 app_start_status_timer (TRUE);
1582 }
1583 else
1584 {
1585 TRACE_EVENT ("Wait for PIN/PUK entering");
1586 SIM_CLEAR_FLAG (MM_KNOWS_FROM_SIM);
1587 TIMER_STOP (sim_handle, SIM_TIMER);
1588 }
1589 }
1590
1591 /*
1592 +--------------------------------------------------------------------+
1593 | PROJECT : GSM-PS (6302) MODULE : SIM_APP |
1594 | STATE : code ROUTINE : app_sim_read_parameters |
1595 +--------------------------------------------------------------------+
1596
1597 PURPOSE : Start the rest of the initialisation procedure.
1598
1599 */
1600
1601 GLOBAL void app_sim_read_parameters (void)
1602 {
1603 UBYTE result;
1604
1605 PALLOC (sim_mmi_insert_ind, SIM_MMI_INSERT_IND);
1606
1607 TRACE_FUNCTION ("app_sim_read_parameters()");
1608
1609 app_sim_phase ();
1610
1611 switch (sim_data.sim_phase)
1612 {
1613 case 1:
1614 // try to read the SIM service table
1615 if (!app_read_sim_service_table(sim_mmi_insert_ind))
1616 {
1617 app_sim_mmi_insert_ind (sim_mmi_insert_ind, SIM_NO_OPERATION);
1618 return;
1619 }
1620 if (app_sim_mm_insert_ind (sim_mmi_insert_ind) EQ FALSE)
1621 app_sim_mmi_insert_ind (sim_mmi_insert_ind, SIM_NO_OPERATION);
1622 else
1623 app_sim_mmi_insert_ind (sim_mmi_insert_ind, SIM_ADN_ENABLED) ;
1624
1625 PSENDX (MMI, sim_mmi_insert_ind);
1626 app_sim_sms_insert_ind ();
1627 break;
1628 case 3:
1629 #if defined SIM_TOOLKIT
1630 stk_perform_profile_download ();
1631
1632 /* Update the Terminal Support table*/
1633 {
1634 T_path_info tmp_path;
1635 tmp_path.df_level1 = SIM_DF_CING;
1636 tmp_path.v_df_level2 = FALSE;
1637
1638 if(FKT_Select(SIM_CING_TRMST, TRUE, &tmp_path, NULL, 0) EQ SIM_NO_ERROR)
1639 {
1640 FKT_UpdateBinary (sim_data.trmst, MAX_TRMST, 0);
1641 }
1642 }
1643 SIM_EM_SIM_TOOLKIT_ACTIVATION;
1644
1645 #endif
1646 /* no break;*/
1647 /*lint -fallthrough*/
1648 case 2:
1649 /* includes reading of the SIM service table*/
1650 result = app_fdn_bdn_procedures (sim_mmi_insert_ind);
1651 if ((result EQ SIM_NO_OPERATION) OR
1652 !app_sim_mm_insert_ind (sim_mmi_insert_ind))
1653 app_sim_mmi_insert_ind (sim_mmi_insert_ind, SIM_NO_OPERATION);
1654 else
1655 app_sim_mmi_insert_ind (sim_mmi_insert_ind, result);
1656
1657 PSENDX (MMI, sim_mmi_insert_ind);
1658 if (result NEQ SIM_NO_OPERATION)
1659 app_sim_sms_insert_ind ();
1660 break;
1661 default:
1662 break;
1663 }
1664 }
1665
1666 /*
1667 +--------------------------------------------------------------------+
1668 | PROJECT : GSM-PS (6302) MODULE : SIM_APP |
1669 | STATE : code ROUTINE : app_sim_phase |
1670 +--------------------------------------------------------------------+
1671
1672 PURPOSE : Read the phase identification.
1673
1674 */
1675
1676 GLOBAL void app_sim_phase (void)
1677 {
1678 USHORT error;
1679
1680 TRACE_FUNCTION ("app_sim_phase()");
1681 error = FKT_Select (SIM_PHASE, FALSE, NULL, NULL, 0);
1682 if (error EQ SIM_NO_ERROR OR error EQ SIM_NO_ERR_FILE_ALREADY_SELECTED)
1683 error = FKT_ReadBinary (&sim_data.sim_phase, 0, 1);
1684
1685 /*
1686 * Default is phase 1 SIM card
1687 * G23 interpretation is
1688 * 1: Phase 1
1689 * 2: Phase 2
1690 * 3: Phase 2+
1691 */
1692 if (error NEQ SIM_NO_ERROR)
1693 sim_data.sim_phase = 1;
1694 else
1695 {
1696 if (sim_data.sim_phase EQ 0)
1697 sim_data.sim_phase = 1;
1698 //TISH, patch for OMAPS00122397
1699 //start
1700 else if (sim_data.sim_phase EQ 0xFF)
1701 sim_data.sim_phase = 3;
1702 //end
1703 }
1704 }
1705
1706 /*
1707 +--------------------------------------------------------------------+
1708 | PROJECT : GSM-PS (6302) MODULE : SIM_APP |
1709 | STATE : code ROUTINE : app_read_sim_service_table |
1710 +--------------------------------------------------------------------+
1711
1712 PURPOSE : Read the SIM Service Table.
1713
1714 */
1715
1716 LOCAL UBYTE app_read_sim_service_table (T_SIM_MMI_INSERT_IND * sim_mmi_insert_ind)
1717 {
1718 USHORT length;
1719 USHORT error;
1720 T_FIELD_STATUS field_status;
1721 UBYTE response[SIMDRV_MAX_RESULT];
1722
1723 /*
1724 * read SIM service table
1725 * Currently selected EF information is reset to force the selection
1726 */
1727 sim_data.act_field = NOT_PRESENT_16BIT;
1728
1729 error = FKT_Select (SIM_SST, FALSE, NULL, response, SIM_MIN_EF_ST_LEN);
1730 if (error EQ SIM_NO_ERROR)
1731 {
1732 memcpy(&field_status,response,SIM_MIN_EF_ST_LEN);
1733
1734 length = (USHORT)field_status.field_size[0] * 256
1735 + field_status.field_size[1];
1736 if (length > MAX_SRV_TBL)
1737
1738 length = MAX_SRV_TBL;
1739 memset (sim_mmi_insert_ind->sim_serv, 0, MAX_SRV_TBL);
1740 if (FKT_ReadBinary (sim_mmi_insert_ind->sim_serv, 0, length) NEQ SIM_NO_ERROR)
1741 return FALSE;
1742 }
1743 else
1744 return FALSE;
1745
1746 /*
1747 * set flags according to the allocated and activated services
1748 */
1749 if (SERVICE(1,sim_mmi_insert_ind->sim_serv) EQ ALLOCATED_AND_ACTIVATED)
1750 SIM_SET_FLAG (SERVICE_1_SUPPORT);
1751 else
1752 SIM_CLEAR_FLAG (SERVICE_1_SUPPORT);
1753
1754 if (SERVICE(2,sim_mmi_insert_ind->sim_serv) EQ ALLOCATED_AND_ACTIVATED)
1755 SIM_SET_FLAG (SERVICE_2_SUPPORT);
1756 else
1757 SIM_CLEAR_FLAG (SERVICE_2_SUPPORT);
1758
1759 if (SERVICE(3,sim_mmi_insert_ind->sim_serv) EQ ALLOCATED_AND_ACTIVATED)
1760 SIM_SET_FLAG (SERVICE_3_SUPPORT);
1761 else
1762 SIM_CLEAR_FLAG (SERVICE_3_SUPPORT);
1763
1764 if (SERVICE(4,sim_mmi_insert_ind->sim_serv) EQ ALLOCATED_AND_ACTIVATED)
1765 SIM_SET_FLAG (SERVICE_4_SUPPORT);
1766 else
1767 SIM_CLEAR_FLAG (SERVICE_4_SUPPORT);
1768
1769 if (SERVICE(7,sim_mmi_insert_ind->sim_serv) EQ ALLOCATED_AND_ACTIVATED)
1770 SIM_SET_FLAG (SERVICE_7_SUPPORT);
1771 else
1772 SIM_CLEAR_FLAG (SERVICE_7_SUPPORT);
1773
1774 if (SERVICE(26,sim_mmi_insert_ind->sim_serv) EQ ALLOCATED_AND_ACTIVATED)
1775 SIM_SET_FLAG (SERVICE_26_SUPPORT);
1776 else
1777 SIM_CLEAR_FLAG (SERVICE_26_SUPPORT);
1778
1779 if (SERVICE(31,sim_mmi_insert_ind->sim_serv) EQ ALLOCATED_AND_ACTIVATED)
1780 SIM_SET_FLAG (SERVICE_31_SUPPORT);
1781 else
1782 SIM_CLEAR_FLAG (SERVICE_31_SUPPORT);
1783
1784 if (SERVICE(35,sim_mmi_insert_ind->sim_serv) EQ ALLOCATED_AND_ACTIVATED)
1785 SIM_SET_FLAG (SERVICE_35_SUPPORT);
1786 else
1787 SIM_CLEAR_FLAG (SERVICE_35_SUPPORT);
1788
1789 if ((SERVICE(39,sim_mmi_insert_ind->sim_serv) & ALLOCATED)
1790 AND FKT_Select (SIM_DF_GRAPHICS, FALSE, NULL, NULL, 0) EQ SIM_NO_ERROR)
1791 SIM_SET_FLAG (DF_GRAPHICS_EXISTENT);
1792 else
1793 SIM_CLEAR_FLAG (DF_GRAPHICS_EXISTENT);
1794
1795 if ((SERVICE(40,sim_mmi_insert_ind->sim_serv) & ALLOCATED)
1796 AND FKT_Select (SIM_DF_SOLSA, FALSE, NULL, NULL, 0) EQ SIM_NO_ERROR)
1797 SIM_SET_FLAG (DF_SOLSA_EXISTENT);
1798 else
1799 SIM_CLEAR_FLAG (DF_SOLSA_EXISTENT);
1800
1801 /* @@TODO -- CHECK THE SERVICE NUMBER */
1802 if (FKT_Select (SIM_DF_ORANGE, FALSE,NULL, NULL, 0) EQ SIM_NO_ERROR)
1803 SIM_SET_FLAG (DF_ORANGE_EXISTENT);
1804 else
1805 SIM_CLEAR_FLAG (DF_ORANGE_EXISTENT);
1806
1807 #ifdef REL99
1808 /*
1809 * SET SERVICE FLAG for SERVICE 43 if "user controlled PLMN Selector with
1810 * Access Technology" is supported
1811 */
1812 if (SERVICE(43,sim_mmi_insert_ind->sim_serv) EQ ALLOCATED_AND_ACTIVATED)
1813 SIM_SET_FLAG (SERVICE_43_SUPPORT);
1814 else
1815 SIM_CLEAR_FLAG (SERVICE_43_SUPPORT);
1816
1817 /*
1818 * SET SERVICE FLAG for SERVICE 44 if "Operator controlled PLMN Selector with
1819 * Access Technology" is supported
1820 */
1821 if (SERVICE(44,sim_mmi_insert_ind->sim_serv) EQ ALLOCATED_AND_ACTIVATED)
1822 SIM_SET_FLAG (SERVICE_44_SUPPORT);
1823 else
1824 SIM_CLEAR_FLAG (SERVICE_44_SUPPORT);
1825 #endif /* REl99 */
1826
1827 #if defined (GPRS)
1828 if (SERVICE(38,sim_mmi_insert_ind->sim_serv) EQ ALLOCATED_AND_ACTIVATED)
1829 SIM_SET_FLAG (SERVICE_38_SUPPORT);
1830 else
1831 SIM_CLEAR_FLAG (SERVICE_38_SUPPORT);
1832 #endif
1833
1834 #ifdef SIM_TOOLKIT
1835 if (SERVICE(29,sim_mmi_insert_ind->sim_serv) EQ ALLOCATED_AND_ACTIVATED)
1836 SIM_SET_FLAG (PRO_ACTIVE_SIM);
1837 else
1838 SIM_CLEAR_FLAG (PRO_ACTIVE_SIM);
1839 #endif
1840 return TRUE;
1841 }
1842
1843 /*
1844 +--------------------------------------------------------------------+
1845 | PROJECT : GSM-PS (6302) MODULE : SIM_APP |
1846 | STATE : code ROUTINE : app_sim_mm_insert_ind |
1847 +--------------------------------------------------------------------+
1848
1849 PURPOSE : Reads some fields and build SIM_MM_INSERT_IND.
1850
1851 */
1852
1853 GLOBAL UBYTE app_sim_mm_insert_ind (T_SIM_MMI_INSERT_IND * sim_mmi_insert_ind)
1854 {
1855 UBYTE kc_n [MAX_KC_N];
1856 int i;
1857 USHORT error;
1858 USHORT length;
1859 T_FIELD_STATUS field_status;
1860 USHORT FileSelRes;
1861 UBYTE response[SIMDRV_MAX_RESULT];
1862 T_path_info tmp_path;
1863
1864 /*
1865 * Read remaining parameters for mobility management
1866 */
1867 PALLOC (sim_mm_insert_ind, SIM_MM_INSERT_IND);
1868
1869 TRACE_FUNCTION ("app_sim_mm_insert_ind()");
1870
1871 SIM_EM_READ_MM_PARAMETER;
1872
1873 SIM_CLEAR_FLAG (TEST_SIM_INSERTED);
1874 #if defined SIM_TOOLKIT
1875 SIM_CLEAR_FLAG (TEST_MODE_POLLING);
1876 #endif
1877 /*
1878 * read administrative data
1879 */
1880 memset (&sim_mmi_insert_ind->ad, 0, MAX_AD);
1881 error = FKT_Select (SIM_AD, FALSE, NULL, response, SIM_MIN_EF_ST_LEN);
1882
1883 if ( error EQ SIM_NO_ERROR OR error EQ SIM_NO_ERR_FILE_ALREADY_SELECTED)
1884 {
1885 memcpy(&field_status, response, SIM_MIN_EF_ST_LEN);
1886 {
1887 length = field_status.field_size[0] * 256 +
1888 field_status.field_size[1];
1889
1890 if(length > MAX_AD)
1891 length = MAX_AD;
1892
1893 sim_mm_insert_ind->c_ad = (UBYTE)length;
1894 if(FKT_ReadBinary ((UBYTE *)&sim_mm_insert_ind->ad, 0, length) EQ SIM_NO_ERROR)
1895 {
1896 TRACE_EVENT_P1("The length of AD is %d", length);
1897 }
1898 else
1899 {
1900 PFREE (sim_mm_insert_ind);
1901 return FALSE;
1902 }
1903 }
1904
1905 sim_mmi_insert_ind->c_ad = sim_mm_insert_ind->c_ad;
1906 memcpy (&sim_mmi_insert_ind->ad, &sim_mm_insert_ind->ad,sim_mmi_insert_ind->c_ad);
1907
1908
1909 if(sim_mm_insert_ind->ad[0] & 0x80)
1910 {
1911 SIM_SET_FLAG (TEST_SIM_INSERTED);
1912 #if defined SIM_TOOLKIT
1913 TRACE_EVENT("REG POLLING");
1914 SIM_SET_FLAG (TEST_MODE_POLLING);
1915 #endif
1916 }
1917
1918 }
1919 else
1920 {
1921 PFREE (sim_mm_insert_ind);
1922 return FALSE;
1923 }
1924
1925 /*
1926 * read IMSI (set to zero in case of error)
1927 */
1928 memset (&sim_mmi_insert_ind->imsi_field, 0, sizeof (T_imsi_field));
1929 if (FKT_Select (SIM_IMSI, FALSE, NULL, NULL, 0) EQ SIM_NO_ERROR)
1930 {
1931 if (FKT_ReadBinary ((UBYTE *)&sim_mm_insert_ind->imsi_field, 0, MAX_IMSI)
1932 NEQ SIM_NO_ERROR)
1933 {
1934 PFREE (sim_mm_insert_ind);
1935 return FALSE;
1936 }
1937 /*
1938 * Check length of IMSI for validity
1939 */
1940 if ((sim_mm_insert_ind->imsi_field.c_field <= 3) OR
1941 (sim_mm_insert_ind->imsi_field.c_field > MAX_IMSI-1))
1942 {
1943 PFREE (sim_mm_insert_ind);
1944 return FALSE;
1945 }
1946 memcpy (&sim_mmi_insert_ind->imsi_field, &sim_mm_insert_ind->imsi_field,
1947 sizeof (T_imsi_field));
1948 /*
1949 * Modify polling algorithm in case of HPLMN == Test Network
1950 */
1951 if ((sim_mm_insert_ind->imsi_field.c_field >= 3) AND
1952 ((sim_mm_insert_ind->imsi_field.field[0] & 0xF7) EQ 0x01) AND
1953 (sim_mm_insert_ind->imsi_field.field[1] EQ 0x10) AND
1954 (sim_mm_insert_ind->imsi_field.field[2] EQ 0x10))
1955 {
1956 SIM_SET_FLAG (TEST_SIM_INSERTED);
1957 #if defined SIM_TOOLKIT
1958 TRACE_EVENT("REG POLLING");
1959 SIM_SET_FLAG (TEST_MODE_POLLING);
1960 #endif
1961 }
1962 }
1963 else
1964 {
1965 PFREE (sim_mm_insert_ind);
1966 return FALSE;
1967 }
1968
1969 /*
1970 * read location information
1971 */
1972 if (FKT_Select (SIM_LOCI, FALSE, NULL, NULL, 0) EQ SIM_NO_ERROR)
1973 {
1974 sim_mm_insert_ind->loc_info.c_loc = MAX_LOC_INFO;
1975 if (FKT_ReadBinary ((UBYTE *)sim_mm_insert_ind->loc_info.loc, 0,
1976 MAX_LOC_INFO) NEQ SIM_NO_ERROR)
1977 {
1978 PFREE (sim_mm_insert_ind);
1979 return FALSE;
1980 }
1981 }
1982 else
1983 {
1984 PFREE (sim_mm_insert_ind);
1985 return FALSE;
1986 }
1987
1988 /*
1989 * Access control classes
1990 */
1991 if (FKT_Select (SIM_ACC, FALSE, NULL, NULL, 0) EQ SIM_NO_ERROR)
1992 {
1993 sim_mm_insert_ind->acc_ctrl.c_acc = MAX_ACCESS_CONTROL;
1994 if (FKT_ReadBinary ((UBYTE *)sim_mm_insert_ind->acc_ctrl.acc, 0,
1995 MAX_ACCESS_CONTROL) NEQ SIM_NO_ERROR)
1996 {
1997 PFREE (sim_mm_insert_ind);
1998 return FALSE;
1999 }
2000 }
2001 else
2002 {
2003 PFREE (sim_mm_insert_ind);
2004 return FALSE;
2005 }
2006
2007 /*
2008 * BCCH information
2009 */
2010 if (FKT_Select (SIM_BCCH, FALSE, NULL, NULL, 0) EQ SIM_NO_ERROR)
2011 {
2012 sim_mm_insert_ind->bcch_inf.c_bcch = MAX_BCCH_INFO;
2013 if (FKT_ReadBinary ((UBYTE *)sim_mm_insert_ind->bcch_inf.bcch, 0,
2014 MAX_BCCH_INFO) NEQ SIM_NO_ERROR)
2015 {
2016 PFREE (sim_mm_insert_ind);
2017 return FALSE;
2018 }
2019 }
2020 else
2021 {
2022 PFREE (sim_mm_insert_ind);
2023 return FALSE;
2024 }
2025
2026 /*
2027 * KC and cipher key sequence number
2028 */
2029 if (FKT_Select (SIM_KC, FALSE, NULL, NULL, 0) EQ SIM_NO_ERROR)
2030 {
2031 if (FKT_ReadBinary ((UBYTE *)kc_n, 0, MAX_KC_N) NEQ SIM_NO_ERROR)
2032 {
2033 PFREE (sim_mm_insert_ind);
2034 return FALSE;
2035 }
2036 else
2037 {
2038 sim_mm_insert_ind->kc_n.c_kc = MAX_KC_N;
2039 /*
2040 * Store KC in opposite order
2041 */
2042 for (i = 0; i < MAX_KC; i++)
2043 sim_mm_insert_ind->kc_n.kc[(MAX_KC-1)-i] = kc_n[i];
2044 /*
2045 * Store cipher key sequence number
2046 */
2047 sim_mm_insert_ind->kc_n.kc[MAX_KC] = kc_n[MAX_KC];
2048 }
2049 }
2050 else
2051 {
2052 PFREE (sim_mm_insert_ind);
2053 return FALSE;
2054 }
2055
2056 /*
2057 * Read Preferred PLMN information
2058 * Initialize preferred plmn information is not present
2059 */
2060 sim_mm_insert_ind->pref_plmn_list_sz =
2061 app_get_ef_size(SERVICE_7_SUPPORT, SIM_PLMNSEL,response);
2062
2063 /*
2064 * Read forbidden PLMNs
2065 */
2066 if (FKT_Select (SIM_FPLMN, FALSE, NULL, NULL, 0) EQ SIM_NO_ERROR)
2067 {
2068 sim_mm_insert_ind->forb_plmn.c_forb = MAX_FORB_PLMN;
2069 if (FKT_ReadBinary ((UBYTE *)sim_mm_insert_ind->forb_plmn.forb, 0,
2070 MAX_FORB_PLMN) NEQ SIM_NO_ERROR)
2071 {
2072 PFREE (sim_mm_insert_ind);
2073 return FALSE;
2074 }
2075 }
2076 else
2077 {
2078 PFREE (sim_mm_insert_ind);
2079 return FALSE;
2080 }
2081
2082 #ifdef REL99
2083 /*
2084 * Extract "User controlled PLMN Selector with Access Technology" Information
2085 * Initially set 'usr ctrl plmn selector with Access Technology informaiton' is not present
2086 */
2087 sim_mm_insert_ind->u_ctl_plmn_sel_actech_list_sz =
2088 app_get_ef_size(SERVICE_43_SUPPORT, SIM_UCPS_ACTEC,response);
2089
2090 /*
2091 * Extract "Operator controlled PLMN Selector with Access Technology" Information
2092 * Initailly set 'operator ctrl plmn with Access Technology informaiton' is not present
2093 */
2094 sim_mm_insert_ind->o_ctl_plmn_sel_actech_list_sz =
2095 app_get_ef_size(SERVICE_44_SUPPORT, SIM_OCPS_ACTEC,response);
2096
2097 #endif /* REl99 */
2098
2099 /*
2100 * Read Acting HPLMN
2101 */
2102 tmp_path.df_level1 = SIM_DF_CING;
2103 tmp_path.v_df_level2 = TRUE;
2104 tmp_path.df_level2 = SIM_DF2_CING;
2105
2106 FileSelRes = FKT_Select(SIM_CING_AHPLMN, TRUE, &tmp_path, NULL, 0);
2107
2108 if( FileSelRes EQ SIM_NO_ERROR)
2109 {
2110 sim_mm_insert_ind->v_act_hplmn = TRUE;
2111 if(FKT_ReadBinary ((UBYTE *)sim_mm_insert_ind->act_hplmn, 0,
2112 MAX_SIM_PLMN_SIZE) NEQ SIM_NO_ERROR)
2113 {
2114 sim_mm_insert_ind->v_act_hplmn = FALSE;
2115 }
2116 }
2117 else
2118 {
2119 sim_mm_insert_ind->v_act_hplmn = FALSE;
2120 }
2121
2122
2123 /*
2124 * set phase identification and
2125 * default value for hplmn search period
2126 * for phase 1 card.
2127 */
2128 sim_mm_insert_ind->phase = sim_data.sim_phase;
2129 /*
2130 * 3GPP 23.122 clause 4.4.3.3 states the default search period
2131 * is now 60 minutes. This is different from ETSI 03.22
2132 * clause 4.4.3.3 where the default value was only 30 minutes.
2133 */
2134 sim_mm_insert_ind->hplmn = 10;
2135
2136 if (sim_data.sim_phase NEQ PHASE_1_SIM)
2137 {
2138 if (FKT_Select (SIM_HPLMN, FALSE, NULL, NULL, 0) EQ SIM_NO_ERROR)
2139 {
2140 if (FKT_ReadBinary (&sim_mm_insert_ind->hplmn, 0, 1)
2141 NEQ SIM_NO_ERROR)
2142 sim_mm_insert_ind->hplmn = 10;
2143 }
2144 }
2145
2146 #if defined (GPRS)
2147 gprs_gmm_insert_ind (sim_mm_insert_ind);
2148 #endif
2149
2150 /*
2151 * send information to mobility management
2152 */
2153 PSENDX (MM, sim_mm_insert_ind);
2154 SIM_SET_FLAG (MM_KNOWS_FROM_SIM);
2155
2156 return TRUE;
2157 }
2158
2159 /*
2160 +--------------------------------------------------------------------+
2161 | PROJECT : GSM-PS (6302) MODULE : SIM_APP |
2162 | STATE : code ROUTINE : app_sim_mmi_insert_ind |
2163 +--------------------------------------------------------------------+
2164
2165 PURPOSE : Build the primitive SIM_MMI_INSERT_IND.
2166 */
2167
2168 GLOBAL void app_sim_mmi_insert_ind (T_SIM_MMI_INSERT_IND * sim_mmi_insert_ind, UBYTE func)
2169 {
2170 T_FIELD_STATUS field_status;
2171 USHORT length;
2172 UBYTE response[SIMDRV_MAX_RESULT];
2173
2174 TRACE_FUNCTION ("app_sim_mmi_insert_ind()");
2175
2176 SIM_EM_READ_MMI_PARAMETER;
2177
2178 /*
2179 * copy parameters known from MM INSERT reading
2180 */
2181
2182 sim_mmi_insert_ind->func = func;
2183
2184 if (func & 1)
2185 SIM_SET_FLAG (ADN_SUPPORT_BY_SIM);
2186 else
2187 SIM_CLEAR_FLAG (ADN_SUPPORT_BY_SIM);
2188
2189 if (func & 2)
2190 SIM_SET_FLAG (FDN_SUPPORT_BY_SIM);
2191 else
2192 SIM_CLEAR_FLAG (FDN_SUPPORT_BY_SIM);
2193
2194 if (func & 4)
2195 SIM_SET_FLAG (BDN_SUPPORT_BY_SIM);
2196 else
2197 SIM_CLEAR_FLAG (BDN_SUPPORT_BY_SIM);
2198
2199 sim_mmi_insert_ind->phase = sim_data.sim_phase;
2200
2201 /*
2202 * check access conditions for AoC fields
2203 * Currently selected EF information is reset to force the selection
2204 */
2205
2206 sim_data.act_field = NOT_PRESENT_16BIT;
2207 sim_mmi_insert_ind->access_acm = NOT_PRESENT_8BIT;
2208 if (FKT_Select (SIM_ACM, FALSE, NULL, response, SIM_MIN_EF_ST_LEN) EQ SIM_NO_ERROR)
2209 {
2210 memcpy(&field_status, response, SIM_MIN_EF_ST_LEN);
2211 sim_mmi_insert_ind->access_acm = field_status.access_1 & 0x0F;
2212 }
2213
2214 sim_mmi_insert_ind->access_acmmax = NOT_PRESENT_8BIT;
2215 if (FKT_Select (SIM_ACMMAX, FALSE, NULL, response, SIM_MIN_EF_ST_LEN) EQ SIM_NO_ERROR)
2216 {
2217 memcpy(&field_status, response, SIM_MIN_EF_ST_LEN);
2218 sim_mmi_insert_ind->access_acmmax = field_status.access_1 & 0x0F;
2219 }
2220
2221 sim_mmi_insert_ind->access_puct = NOT_PRESENT_8BIT;
2222 if (FKT_Select (SIM_PUCT, FALSE, NULL, response, SIM_MIN_EF_ST_LEN) EQ SIM_NO_ERROR)
2223 {
2224 memcpy(&field_status, response, SIM_MIN_EF_ST_LEN);
2225 sim_mmi_insert_ind->access_puct = field_status.access_1 & 0x0F;
2226 }
2227
2228 TRACE_EVENT_P1 ("Access ACM = %d", sim_mmi_insert_ind->access_acm);
2229 TRACE_EVENT_P1 ("Access ACMMAX = %d", sim_mmi_insert_ind->access_acmmax);
2230 TRACE_EVENT_P1 ("Access PUCT = %d", sim_mmi_insert_ind->access_puct);
2231
2232 #ifdef SIM_TOOLKIT
2233 if ( (SERVICE(25,sim_mmi_insert_ind->sim_serv) EQ ALLOCATED_AND_ACTIVATED)
2234 AND (sim_data.stk_profile[0] & SAT_TP1_CB_DNL) )
2235 {
2236 if (FKT_Select (SIM_CBMID, FALSE, NULL, response, SIM_MIN_EF_ST_LEN) EQ SIM_NO_ERROR)
2237 {
2238 memcpy(&field_status, response, SIM_MIN_EF_ST_LEN);
2239 {
2240 length = field_status.field_size[0] * 256 +
2241 field_status.field_size[1];
2242
2243 length = MINIMUM(length, MAX_CBMID_REC);
2244
2245 sim_mmi_insert_ind->cbmid_rec.c_rec = (UBYTE)length;
2246
2247 if(FKT_ReadBinary ((UBYTE *)sim_mmi_insert_ind->cbmid_rec.rec, 0, length)
2248 EQ SIM_NO_ERROR)
2249 {
2250 TRACE_EVENT_P1("The length of CBMID is %d", length);
2251 }
2252 }
2253 }
2254 }
2255 #endif
2256 }
2257
2258 /*
2259 +--------------------------------------------------------------------+
2260 | PROJECT : GSM-PS (6302) MODULE : SIM_APP |
2261 | STATE : code ROUTINE : app_sim_sms_insert_ind |
2262 +--------------------------------------------------------------------+
2263
2264 PURPOSE : Build the primitive SIM_SMS_INSERT_IND.
2265 */
2266
2267 GLOBAL void app_sim_sms_insert_ind (void)
2268 {
2269 PALLOC (sim_sms_insert_ind, SIM_SMS_INSERT_IND);
2270
2271 TRACE_FUNCTION ("app_sim_sms_insert_ind()");
2272
2273 SIM_EM_READ_SMS_PARAMETER;
2274
2275 memset (sim_sms_insert_ind, 0, sizeof(T_SIM_SMS_INSERT_IND));
2276 sim_sms_insert_ind->mem_cap_avail = SIM_SMS_NO_MEM;
2277 /*
2278 * Read SMS Status
2279 */
2280 if (SIM_IS_FLAG_SET (SERVICE_4_SUPPORT))
2281 {
2282 USHORT error;
2283 error = FKT_Select (SIM_SMSS, FALSE, NULL, NULL, 0);
2284 if (error EQ SIM_NO_ERROR OR error EQ SIM_NO_ERR_FILE_ALREADY_SELECTED)
2285 {
2286 if (FKT_ReadBinary (&sim_sms_insert_ind->tp_mr, 0, 2)
2287 EQ SIM_NO_ERROR)
2288 {
2289 sim_sms_insert_ind->mem_cap_avail &= 1;
2290 }
2291 else
2292 {
2293 sim_sms_insert_ind->mem_cap_avail = SIM_SMS_MEM_AVAIL;
2294 }
2295 }
2296 else if (sim_data.sim_phase < PHASE_2_SIM)
2297 {
2298 sim_sms_insert_ind->mem_cap_avail = SIM_SMS_MEM_AVAIL;
2299 }
2300 }
2301 /*
2302 * check SIM phase and determine support of SMS data download
2303 */
2304 sim_sms_insert_ind->phase = sim_data.sim_phase;
2305
2306 switch (sim_data.sim_phase)
2307 {
2308 case 1:
2309 case 2:
2310 sim_sms_insert_ind->download_sms = DOWNLOAD_SMS_NO;
2311 break;
2312 case 3:
2313 #ifdef SIM_TOOLKIT
2314 /*
2315 * check service 26: data download via point-to-point SMS
2316 */
2317 if (SIM_IS_FLAG_SET (SERVICE_26_SUPPORT))
2318 sim_sms_insert_ind->download_sms = DOWNLOAD_SMS_YES;
2319 else
2320 #endif
2321 sim_sms_insert_ind->download_sms = DOWNLOAD_SMS_NO;
2322 break;
2323 }
2324 /*
2325 * check service 35: store SM Status Reports
2326 */
2327 if (SIM_IS_FLAG_SET (SERVICE_35_SUPPORT))
2328 sim_sms_insert_ind->smsr_mem_cap = SIM_SMSR_ENABLE;
2329 else
2330 sim_sms_insert_ind->smsr_mem_cap = SIM_SMSR_DISABLE;
2331
2332 /*
2333 * send information to short message service
2334 */
2335 PSENDX (SMS, sim_sms_insert_ind);
2336 }
2337
2338 /*
2339 +--------------------------------------------------------------------+
2340 | PROJECT : GSM-PS (6302) MODULE : SIM_APP |
2341 | STATE : code ROUTINE : app_sim_remove |
2342 +--------------------------------------------------------------------+
2343
2344 PURPOSE : Hook function for SIM driver after SIM remove.
2345
2346 */
2347
2348 GLOBAL void app_sim_remove (void)
2349 {
2350 TRACE_FUNCTION ("app_sim_remove()");
2351 #ifdef SIM_TOOLKIT
2352 stk_stop_all_sat_timers ();
2353 #endif
2354 if (SIM_IS_FLAG_SET (SIM_INSERT))
2355 {
2356 {
2357 PALLOC (sim_remove_ind_to_mm , SIM_REMOVE_IND);
2358 sim_remove_ind_to_mm->cause = sim_data.remove_error;
2359 PSENDX (MM, sim_remove_ind_to_mm);
2360 }
2361 #ifdef GPRS
2362 {
2363 PALLOC (sim_remove_ind_to_gmm , SIM_REMOVE_IND);
2364 sim_remove_ind_to_gmm->cause = sim_data.remove_error;
2365 PSENDX (GMM, sim_remove_ind_to_gmm);
2366 }
2367 #endif
2368 {
2369 PALLOC (sim_remove_ind_to_mmi, SIM_REMOVE_IND);
2370 sim_remove_ind_to_mmi->cause = sim_data.remove_error;
2371 PSENDX (MMI, sim_remove_ind_to_mmi);
2372 }
2373 {
2374 PALLOC (sim_remove_ind_to_sms, SIM_REMOVE_IND);
2375 sim_remove_ind_to_sms->cause = sim_data.remove_error;
2376 PSENDX (SMS, sim_remove_ind_to_sms);
2377 }
2378 SIM_EM_SIM_REMOVE;
2379 }
2380 SIM_CLEAR_FLAG (SIM_INSERT);
2381 }
2382
2383 /*
2384 +--------------------------------------------------------------------+
2385 | PROJECT : GSM-PS (6302) MODULE : SIM_APP |
2386 | STATE : code ROUTINE : app_sim_timeout |
2387 +--------------------------------------------------------------------+
2388
2389 PURPOSE : A timeout has occured.
2390
2391 */
2392
2393 GLOBAL void app_sim_timeout (U16 timer)
2394 {
2395 USHORT error;
2396 UBYTE pin_cnt, pin2_cnt, puk_cnt, puk2_cnt;
2397
2398 if (SIM_IS_FLAG_SET (SIM_INSERT))
2399 {
2400 /*
2401 * Presence check all thirty seconds
2402 */
2403 if (timer EQ SLEEP_TIMER AND sim_data.sat_session EQ TRUE)
2404 {
2405 TRACE_EVENT("STK SESSION RUNNING");
2406 return;
2407 }
2408
2409 if ((error = FKT_Status (&pin_cnt, &pin2_cnt, &puk_cnt, &puk2_cnt))
2410 NEQ SIM_NO_ERROR)
2411 {
2412 /* stop Poll Timer*/
2413 TIMER_STOP (sim_handle, SIM_TIMER);
2414
2415 sim_data.remove_error = error;
2416 app_sim_remove ();
2417 sim_data.remove_error = SIM_CAUSE_CARD_REMOVED;
2418 }
2419
2420 #ifdef TI_PS_FF_SIM_POLL_ALWAYS
2421
2422 else
2423 {
2424 #if defined SIM_TOOLKIT
2425 if(SIM_IS_FLAG_SET (PRO_ACTIVE_SIM))
2426 {
2427 stk_proactive_polling();
2428 }
2429 else
2430 #endif
2431 {
2432 TRACE_FUNCTION ("Restarting timer for polling non-proactive SIMs");
2433 app_start_status_timer(FALSE);
2434 }
2435 }
2436
2437 #else
2438
2439 #if defined SIM_TOOLKIT
2440 else
2441 stk_proactive_polling();
2442 #endif
2443
2444 #endif
2445
2446 }
2447 else if (SIM_IS_FLAG_SET (ACTIVATION_STARTED))
2448 {
2449 /*
2450 * Timeout indicates no recognition of
2451 * a SIM card by the driver
2452 */
2453 app_sim_card_error (SIM_CAUSE_CARD_REMOVED);
2454 SIM_CLEAR_FLAG (ACTIVATION_STARTED);
2455 }
2456 else if (SIM_IS_FLAG_SET(DRV_FAILED_RETRY))
2457 {
2458 /*
2459 * Timeout indicates failed recovery after
2460 * a SIM driver retry failure
2461 */
2462 app_sim_remove();
2463 SIM_CLEAR_FLAG(DRV_FAILED_RETRY);
2464 }
2465 else
2466 {
2467 /*
2468 * Timer may still run in case of auto-restart
2469 */
2470 TIMER_STOP (sim_handle, SIM_TIMER);
2471 }
2472 }
2473
2474 /*
2475 +--------------------------------------------------------------------+
2476 | PROJECT : GSM-PS (6302) MODULE : SIM_APP |
2477 | STATE : code ROUTINE : app_sim_card_error |
2478 +--------------------------------------------------------------------+
2479
2480 PURPOSE : An error is signalled to MMI.
2481
2482 */
2483
2484 GLOBAL void app_sim_card_error (USHORT error)
2485 {
2486 PALLOC (sim_activate_cnf, SIM_ACTIVATE_CNF);
2487
2488 memset (sim_activate_cnf, NOT_PRESENT_8BIT, sizeof (T_SIM_ACTIVATE_CNF));
2489
2490 #ifdef FF_DUAL_SIM
2491 if(sim_data.SIM_Selection)
2492 {
2493 sim_activate_cnf->sim_num = SIM_NUM_0;
2494 sim_activate_cnf->cause = error;
2495
2496 PSENDX (MMI, sim_activate_cnf);
2497
2498 return;
2499 }
2500 #endif /*FF_DUAL_SIM*/
2501
2502 sim_activate_cnf->pin_cnt = sim_activate_cnf->puk_cnt = 0;
2503 sim_activate_cnf->pin2_cnt = sim_activate_cnf->puk2_cnt = 0;
2504 sim_activate_cnf->cause = error;
2505 sim_activate_cnf->c_atr = 0;
2506
2507 SIM_EM_SIM_ACTIVATION_RESULT;
2508
2509 PSENDX (MMI, sim_activate_cnf);
2510 }
2511
2512 /*
2513 +--------------------------------------------------------------------+
2514 | PROJECT : GSM-PS (6302) MODULE : SIM_APP |
2515 | STATE : code ROUTINE : app_sim_mm_update_req |
2516 +--------------------------------------------------------------------+
2517
2518 PURPOSE : Process of the primitive SIM_MM_UPDATE_REQ.
2519
2520 */
2521
2522 GLOBAL void app_sim_mm_update_req (T_SIM_MM_UPDATE_REQ * sim_mm_update_req)
2523 {
2524 int i;
2525 USHORT error;
2526 T_kc_n kc_n;
2527 BOOL all_upd = TRUE;
2528
2529 TRACE_FUNCTION ("app_sim_mm_update_req()");
2530
2531 /*
2532 * check location information
2533 */
2534 if (sim_mm_update_req->loc_info.c_loc > 0)
2535 {
2536 #if defined SIM_TOOLKIT
2537 memcpy (&sim_data.location_info, &sim_mm_update_req->loc_info,
2538 sizeof (sim_data.location_info));
2539 #endif
2540 if(sim_mm_update_req->ef_indicator & 0x01)
2541 {
2542 error = FKT_Select (SIM_LOCI, FALSE, NULL, NULL, 0);
2543 if (error EQ SIM_NO_ERROR)
2544 error = FKT_UpdateBinary (sim_mm_update_req->loc_info.loc,
2545 (USHORT)sim_mm_update_req->loc_info.c_loc, 0);
2546 if (error NEQ SIM_NO_ERROR)
2547 {
2548 #ifdef REL99
2549 if (error EQ SIM_CAUSE_MEM_PROBLEM)
2550 {
2551 /*
2552 * In case when updating EF LOCI with data containing the
2553 * TMSI value and the card reports the error '92 40' (Memory Problem),
2554 * the ME shall terminate GSM operation.
2555 */
2556 sim_data.remove_error = SIM_CAUSE_MEM_PROBLEM;
2557 app_sim_remove();
2558 PFREE (sim_mm_update_req);
2559 return;
2560 }
2561 #endif /* end of ifdef REL99 */
2562 all_upd = FALSE;
2563 }
2564 }
2565 #if defined SIM_TOOLKIT
2566 sim_data.cell_identity = sim_mm_update_req->cell_identity;
2567 /*
2568 * Modify polling algorithm if connected to Test Network
2569 */
2570 if ((sim_mm_update_req->loc_info.c_loc >= 7) AND
2571 (sim_mm_update_req->loc_info.loc[4] EQ 0x00) AND
2572 ((sim_mm_update_req->loc_info.loc[5] & 0x0F) EQ 0x1) AND
2573 (sim_mm_update_req->loc_info.loc[6] EQ 0x10))
2574 {
2575 TRACE_EVENT("REG POLLING");
2576 SIM_SET_FLAG (TEST_MODE_POLLING);
2577 }
2578 else if (SIM_IS_FLAG_CLEARED (TEST_SIM_INSERTED))
2579 {
2580 TRACE_EVENT("STD POLLING");
2581 SIM_CLEAR_FLAG (TEST_MODE_POLLING);
2582 }
2583 #endif
2584 }
2585
2586 /*
2587 * check bcch information
2588 */
2589 if(sim_mm_update_req->ef_indicator & 0x02)
2590 {
2591 if (sim_mm_update_req->bcch_inf.c_bcch > 0)
2592 {
2593 error = FKT_Select (SIM_BCCH, FALSE, NULL, NULL, 0);
2594 if (error EQ SIM_NO_ERROR)
2595 error = FKT_UpdateBinary (sim_mm_update_req->bcch_inf.bcch,
2596 (USHORT)sim_mm_update_req->bcch_inf.c_bcch, 0);
2597 if (error NEQ SIM_NO_ERROR)
2598 all_upd = FALSE;
2599 }
2600 }
2601
2602 /*
2603 * check forbidden PLMN
2604 */
2605 if(sim_mm_update_req->ef_indicator & 0x04)
2606 {
2607 if (sim_mm_update_req->forb_plmn.c_forb > 0)
2608 {
2609 error = FKT_Select (SIM_FPLMN, FALSE, NULL, NULL, 0);
2610 if (error EQ SIM_NO_ERROR)
2611 error = FKT_UpdateBinary (sim_mm_update_req->forb_plmn.forb,
2612 (USHORT)sim_mm_update_req->forb_plmn.c_forb, 0);
2613 if (error NEQ SIM_NO_ERROR)
2614 all_upd = FALSE;
2615 }
2616 }
2617
2618 /*
2619 * check kc and cksn
2620 */
2621 if(sim_mm_update_req->ef_indicator & 0x08)
2622 {
2623 error = FKT_Select (SIM_KC, FALSE, NULL, NULL, 0);
2624 if (error EQ SIM_NO_ERROR)
2625 {
2626 kc_n.c_kc = 9;
2627 kc_n.kc[8] = sim_mm_update_req->cksn;
2628 for (i = 0; i < 8; i++)
2629 kc_n.kc[7-i] = sim_mm_update_req->kc[i];
2630 error = FKT_UpdateBinary (kc_n.kc, (USHORT)kc_n.c_kc, 0);
2631 }
2632 if (error NEQ SIM_NO_ERROR)
2633 all_upd = FALSE;
2634 }
2635
2636 SIM_EM_PARAMETER_UPDATE;
2637
2638 PFREE (sim_mm_update_req);
2639
2640 if (all_upd)
2641 app_start_status_timer (FALSE);
2642 }
2643
2644 /*
2645 +--------------------------------------------------------------------+
2646 | PROJECT : GSM-PS (6302) MODULE : SIM_APP |
2647 | STATE : code ROUTINE : app_sim_sync_req |
2648 +--------------------------------------------------------------------+
2649
2650 PURPOSE : Process the primitive SIM_SYNC_REQ.
2651
2652 */
2653
2654 GLOBAL void app_sim_sync_req (T_SIM_SYNC_REQ * sim_sync_req)
2655 {
2656 #ifdef TI_PS_UICC_CHIPSET_15
2657 U8 reader_id = SIMDRV_VAL_READER_ID__RANGE_MIN;
2658 #endif
2659 PALLOC (sim_sync_cnf, SIM_SYNC_CNF);
2660 sim_sync_cnf->cause = SIM_NO_ERROR;
2661
2662 TRACE_FUNCTION ("app_sim_sync_req()");
2663
2664 SIM_EM_PARAMETER_SYNCHRONISATION;
2665
2666 switch (sim_sync_req->synccs)
2667 {
2668 case SYNC_START_CALL:
2669 SIM_SET_FLAG (CALL_ACTIVE);
2670 PSENDX (MMI, sim_sync_cnf);
2671 app_sim_timeout (SIM_TIMER); /* checks SIM status!*/
2672 app_start_status_timer (TRUE); /* restart SIM presence detection*/
2673 break;
2674
2675 case SYNC_STOP_CALL:
2676 SIM_CLEAR_FLAG (CALL_ACTIVE);
2677 /*
2678 * only if SIM inserted
2679 */
2680 if (SIM_IS_FLAG_SET (SIM_INSERT))
2681 {
2682 #if defined SIM_TOOLKIT
2683 /*
2684 * if SIM Toolkit is active, idle polling
2685 * might be needed, additionally
2686 */
2687 if (SIM_IS_FLAG_CLEARED (PRO_ACTIVE_SIM))
2688 #endif
2689 {
2690 /*
2691 * Stop presence detection polling, after Call
2692 */
2693 TIMER_STOP (sim_handle, SIM_TIMER);
2694 }
2695 #if defined SIM_TOOLKIT
2696 else if (sim_data.idle_polling)
2697 {
2698 app_start_status_timer (TRUE);
2699 }
2700 #endif
2701 }
2702 else
2703 sim_sync_cnf->cause = SIM_CAUSE_CARD_REMOVED;
2704
2705 PSENDX (MMI, sim_sync_cnf);
2706 break;
2707
2708
2709 case SYNC_MM_FINISHED_READING:
2710 #if defined SIM_TOOLKIT
2711 if(sim_data.sync_awaited & SIM_SYNC_AWAIT_MM_READ)
2712 {
2713 sim_data.sync_awaited &= ~SIM_SYNC_AWAIT_MM_READ;
2714 /* Check if both MM and MMI have sent SYNC_REQ */
2715 if(sim_data.sync_awaited EQ 0 AND sim_data.stk_resp_len NEQ 0)
2716 {
2717 FKT_TerminalResponse (sim_data.stk_response, (USHORT)sim_data.stk_resp_len);
2718 sim_data.stk_resp_len = 0;
2719 }
2720 }
2721 #endif /* SIM_TOOLKIT */
2722 PSENDX (MM, sim_sync_cnf);
2723 break;
2724
2725 case SYNC_MMI_FINISHED_READING:
2726 #if defined SIM_TOOLKIT
2727 if(sim_data.sync_awaited & SIM_SYNC_AWAIT_MMI_READ)
2728 {
2729 sim_data.sync_awaited &= ~SIM_SYNC_AWAIT_MMI_READ;
2730 /* Check if both MM and MMI have sent SYNC_REQ */
2731 if(sim_data.sync_awaited EQ 0 AND sim_data.stk_resp_len NEQ 0)
2732 {
2733 FKT_TerminalResponse (sim_data.stk_response, (USHORT)sim_data.stk_resp_len);
2734 sim_data.stk_resp_len = 0;
2735 }
2736 }
2737 #endif /* SIM_TOOLKIT */
2738 PSENDX (MMI, sim_sync_cnf);
2739 break;
2740
2741 case SYNC_DEACTIVATE:
2742 TIMER_STOP (sim_handle, SIM_TIMER);
2743 #ifdef SIM_TOOLKIT
2744 stk_stop_all_sat_timers ();
2745 #endif
2746 PSENDX (MMI, sim_sync_cnf);
2747 /*
2748 * switch off SIM driver
2749 */
2750 #ifndef TI_PS_UICC_CHIPSET_15
2751 SIM_PowerOff ();
2752 #else
2753 simdrv_poweroff( reader_id );
2754 #endif
2755 SIM_CLEAR_FLAG (SIM_INSERT);
2756 /*
2757 * Initialize SIM for next Power On
2758 */
2759 app_init_sim_data ();
2760 break;
2761
2762 default:
2763 sim_sync_cnf->cause = SIM_CAUSE_PARAM_WRONG;
2764 PSENDX (MMI, sim_sync_cnf);
2765 break;
2766 }
2767 PFREE (sim_sync_req);
2768 }
2769
2770 /*
2771 +--------------------------------------------------------------------+
2772 | PROJECT : GSM-PS (6302) MODULE : SIM_APP |
2773 | STATE : code ROUTINE : app_sim_activate_req |
2774 +--------------------------------------------------------------------+
2775
2776 PURPOSE : Process the primitive SIM_ACTIVATE_REQ.
2777
2778 */
2779
2780 GLOBAL void app_sim_activate_req (T_SIM_ACTIVATE_REQ * sim_activate_req)
2781 {
2782 USHORT retcode;
2783
2784 #ifdef TI_PS_UICC_CHIPSET_15
2785 U8 reader_id =SIMDRV_VAL_READER_ID__RANGE_MIN;
2786 U8 voltage_select = SIMDRV_REQ_VOLTAGE_SEL;
2787 #endif /* TI_PS_UICC_CHIPSET_15 */
2788 #if defined FF_DUAL_SIM OR (!defined TI_PS_UICC_CHIPSET_15)
2789 T_SIM_CARD sim_info;
2790 #endif /* FF_DUAL_SIM OR TI_PS_UICC_CHIPSET_15*/
2791
2792 TRACE_FUNCTION ("app_sim_activate_req()");
2793
2794 switch (sim_activate_req->proc)
2795 {
2796 case SIM_INITIALISATION:
2797 SIM_SET_FLAG (ACTIVATION_STARTED);
2798 SIM_CLEAR_FLAG (CALL_ACTIVE);
2799 sim_data.act_directory = NOT_PRESENT_16BIT;
2800 sim_data.act_field = NOT_PRESENT_16BIT;
2801 sim_data.status_time = THIRTY_SECONDS;
2802 sim_data.cust_mode = sim_activate_req->cust_mode;
2803
2804 if (sim_activate_req->mmi_pro_file & SIM_MMI_BDN)
2805 SIM_SET_FLAG (BDN_SUPPORT_BY_MMI);
2806 else
2807 SIM_CLEAR_FLAG (BDN_SUPPORT_BY_MMI);
2808
2809 if (sim_activate_req->mmi_pro_file & SIM_MMI_FDN)
2810 SIM_SET_FLAG (FDN_SUPPORT_BY_MMI);
2811 else
2812 SIM_CLEAR_FLAG (FDN_SUPPORT_BY_MMI);
2813
2814 SIM_CLEAR_FLAG (CC_WITH_STK);
2815
2816 #if defined SIM_TOOLKIT
2817 stk_check_tp (sim_data.stk_profile, sim_activate_req->stk_pro_file,
2818 MINIMUM(sizeof sim_data.stk_profile, sizeof sim_activate_req->stk_pro_file));
2819 if (sim_data.stk_profile[1] & SAT_TP2_CC)
2820 SIM_SET_FLAG (CC_WITH_STK);
2821
2822 if(sim_activate_req->v_trmst_file)
2823 {
2824 memcpy (sim_data.trmst, sim_activate_req->trmst_file, sizeof(sim_activate_req->trmst_file));
2825 }
2826 else
2827 {
2828 memset (sim_data.trmst, FALSE, MAX_TRMST);
2829 }
2830 #endif
2831
2832 TIMER_START (sim_handle, SIM_TIMER, T_DETECT_VALUE);
2833 #ifndef TI_PS_UICC_CHIPSET_15
2834 retcode = SIM_Reset (&sim_info);
2835 #else
2836 retcode = simdrv_reset( reader_id, voltage_select);
2837 #endif
2838
2839 TRACE_EVENT_P1 ("Result SIM Reset = %d", (int)retcode);
2840
2841 switch (retcode)
2842 {
2843 case 0:
2844 /*
2845 * No problem
2846 */
2847 break;
2848 case 1:
2849 case 3:
2850 case 8:
2851 case 9:
2852 /*
2853 * No card inserted
2854 */
2855 TIMER_STOP (sim_handle, SIM_TIMER);
2856
2857 app_sim_card_error (SIM_CAUSE_CARD_REMOVED);
2858 SIM_CLEAR_FLAG (SIM_INSERT);
2859 SIM_CLEAR_FLAG (ACTIVATION_STARTED);
2860 break;
2861 default:
2862 /*
2863 * other card problems
2864 */
2865 TIMER_STOP (sim_handle, SIM_TIMER);
2866 app_sim_card_error (CAUSE_MAKE(DEFBY_CONDAT, ORIGSIDE_MS,
2867 SIM_ORIGINATING_ENTITY, retcode));
2868 SIM_CLEAR_FLAG (SIM_INSERT);
2869 SIM_CLEAR_FLAG (ACTIVATION_STARTED);
2870 break;
2871 }
2872
2873 break;
2874
2875 case SIM_FDN_ENABLE:
2876 /* Implements Measure# 14 */
2877 app_sim_activate_req_fdn_enable(TRUE);
2878 break;
2879
2880 case SIM_FDN_DISABLE:
2881 /* Implements Measure# 14 */
2882 app_sim_activate_req_fdn_enable(FALSE);
2883 break;
2884
2885 #ifdef FF_DUAL_SIM
2886 case SIM_SELECT:
2887
2888 if(sim_activate_req->sim_num < 0 OR sim_activate_req->sim_num > 2)
2889 {
2890 app_sim_card_error (SIM_CAUSE_PARAM_WRONG);
2891 break;
2892 }
2893
2894 sim_data.SIM_Selection = TRUE;
2895
2896 if(SIM_IS_FLAG_SET (SIM_INSERT))
2897 {
2898 SIM_PowerOff ();
2899 app_init_sim_data ();
2900 SIM_CLEAR_FLAG (SIM_INSERT);
2901 }
2902 retcode = SIM_SwitchDualSIM(sim_activate_req->sim_num);
2903
2904 if(!retcode)
2905 {
2906 sim_data.sim_num = sim_activate_req->sim_num;
2907
2908 TIMER_START (sim_handle, SIM_TIMER, T_DETECT_VALUE);
2909
2910 retcode = SIM_Reset (&sim_info);
2911 TRACE_EVENT_P1 ("Result SIM Reset = %d", (int)retcode);
2912
2913 switch (retcode)
2914 {
2915 case 0:
2916 /*
2917 * No problem
2918 */
2919 break;
2920 case 1:
2921 case 3:
2922 case 8:
2923 case 9:
2924 /*
2925 * No card inserted
2926 */
2927 TIMER_STOP (sim_handle, SIM_TIMER);
2928
2929 app_sim_card_error (SIM_CAUSE_CARD_REMOVED);
2930 SIM_CLEAR_FLAG (SIM_INSERT);
2931 break;
2932 default:
2933 /*
2934 * other card problems
2935 */
2936 TIMER_STOP (sim_handle, SIM_TIMER);
2937
2938 app_sim_card_error (CAUSE_MAKE(DEFBY_CONDAT, ORIGSIDE_MS,
2939 SIM_ORIGINATING_ENTITY, retcode));
2940 SIM_CLEAR_FLAG (SIM_INSERT);
2941 break;
2942 }
2943 }
2944 else
2945 {
2946 app_sim_card_error (CAUSE_MAKE(DEFBY_CONDAT, ORIGSIDE_MS,
2947 SIM_ORIGINATING_ENTITY, retcode));
2948 }
2949 sim_data.SIM_Selection = FALSE;
2950 break;
2951 #endif /*FF_DUAL_SIM*/
2952
2953 default:
2954 app_sim_card_error (SIM_CAUSE_PARAM_WRONG); /* wrong parameter */
2955
2956 SIM_EM_SIM_ACTIVATION_STARTED;
2957
2958 break;
2959 }
2960
2961 PFREE (sim_activate_req);
2962
2963 }
2964
2965
2966 /*
2967 +--------------------------------------------------------------------+
2968 | PROJECT : GSM-PS (6302) MODULE : SIM_APP |
2969 | STATE : code ROUTINE : app_sim_check_service |
2970 +--------------------------------------------------------------------+
2971
2972 PURPOSE : Checks a service status.
2973
2974 */
2975
2976 GLOBAL UBYTE app_sim_check_service (UBYTE nr, UBYTE * serv_table)
2977 {
2978 UBYTE value;
2979
2980 TRACE_FUNCTION ("app_check_sim_service()");
2981
2982 serv_table = serv_table + (nr-1)/4;
2983 value = * serv_table;
2984
2985 value = value >> (((nr-1) & 3) * 2);
2986 value = value & 3;
2987
2988 return value;
2989 }
2990
2991 /*
2992 +--------------------------------------------------------------------+
2993 | PROJECT : GSM-PS (6302) MODULE : SIM_APP |
2994 | STATE : code ROUTINE : app_fdn_bdn_procedures |
2995 +--------------------------------------------------------------------+
2996
2997 PURPOSE : Processing of the FDN/BDN procedures according annex B
2998 of GSM 11.11.
2999
3000 */
3001
3002 static const UBYTE op [9] =
3003 {
3004 SIM_ADN_ENABLED, /* no BDN, no FDN */
3005 SIM_ADN_BDN_ENABLED, /* BDN enabled, no FDN */
3006 SIM_ADN_ENABLED, /* BDN disabled, no FND */
3007 SIM_FDN_ENABLED, /* no BDN, FDN enabled */
3008 SIM_FDN_BDN_ENABLED, /* BDN enabled, FDN enabled */
3009 SIM_FDN_ENABLED, /* BDN disabled, FND enabled */
3010 SIM_ADN_ENABLED, /* no BDN, FDN disabled */
3011 SIM_ADN_BDN_ENABLED, /* BDN enabled, FDN disabled */
3012 SIM_ADN_ENABLED /* BDN disabled, FND disabled */
3013 };
3014
3015 GLOBAL UBYTE app_fdn_bdn_procedures (T_SIM_MMI_INSERT_IND *sim_mmi_insert_ind)
3016 {
3017 UBYTE bdn_capability;
3018 UBYTE fdn_capability;
3019 UBYTE check_imsi_loci;
3020
3021 TRACE_FUNCTION ("app_fdn_bdn_procedures()");
3022
3023 /*
3024 * IMSI and Location Information are
3025 * both not invalidated
3026 */
3027 check_imsi_loci = app_check_imsi_loci_validation ();
3028
3029 if (!app_read_sim_service_table(sim_mmi_insert_ind))
3030 return SIM_NO_OPERATION;
3031
3032 if (check_imsi_loci)
3033 return SIM_ADN_ENABLED;
3034
3035 bdn_capability = app_bdn_capability_request ();
3036 fdn_capability = app_fdn_capability_request ();
3037
3038 if (SIM_IS_FLAG_SET (CC_WITH_STK))
3039 {
3040 /*
3041 * ME supports Call control with SIM Toolkit
3042 */
3043
3044 /*
3045 * if mobile has no BDN capability, but the SIM card
3046 */
3047 if (bdn_capability EQ BDN_ENABLED AND
3048 SIM_IS_FLAG_CLEARED (BDN_SUPPORT_BY_MMI))
3049 return SIM_NO_OPERATION;
3050 /*
3051 * if mobile has no FDN capability, but the SIM card
3052 */
3053 if (fdn_capability EQ FDN_ENABLED AND
3054 SIM_IS_FLAG_CLEARED (FDN_SUPPORT_BY_MMI))
3055 return SIM_NO_OPERATION;
3056
3057 /*
3058 * Try rehabilitation of IMSI and Location Information
3059 */
3060
3061 if (app_rehabilitate_imsi_loci ())
3062 return op [bdn_capability + 3 * fdn_capability];
3063 else
3064 return SIM_NO_OPERATION;
3065 }
3066 else
3067 {
3068 /*
3069 * ME doesn´t support Call control with SIM Toolkit
3070 */
3071
3072 /*
3073 * if mobile has no FDN capability or FDN is not enabled on the SIM card
3074 */
3075 if (fdn_capability NEQ FDN_ENABLED OR
3076 SIM_IS_FLAG_CLEARED (FDN_SUPPORT_BY_MMI))
3077 return SIM_NO_OPERATION;
3078
3079 /*
3080 * Try rehabilitation of IMSI and Location Information
3081 */
3082 if (app_rehabilitate_imsi_loci ())
3083 return SIM_FDN_ENABLED;
3084 else
3085 return SIM_NO_OPERATION;
3086 }
3087 }
3088
3089 /*
3090 +--------------------------------------------------------------------+
3091 | PROJECT : GSM-PS (6302) MODULE : SIM_APP |
3092 | STATE : code ROUTINE : app_check_imsi_loci_validation |
3093 +--------------------------------------------------------------------+
3094
3095 PURPOSE : Checks the validation flag of IMSI and Location information.
3096
3097 */
3098
3099 GLOBAL UBYTE app_check_imsi_loci_validation (void)
3100 {
3101 UBYTE response[SIMDRV_MAX_RESULT];
3102 T_FIELD_STATUS field_status;
3103
3104 TRACE_FUNCTION ("app_check_imsi_loci_validation()");
3105
3106
3107 /* Currently selected EF information is reset to force the selection */
3108 sim_data.act_field = NOT_PRESENT_16BIT;
3109
3110 /*
3111 * check IMSI
3112 */
3113 if (FKT_Select (SIM_LOCI, FALSE, NULL,response, SIM_MIN_EF_ST_LEN) EQ SIM_NO_ERROR)
3114 memcpy(&field_status,response,SIM_MIN_EF_ST_LEN);
3115 else
3116 return FALSE;
3117
3118 /*
3119 * check invalidation flag
3120 */
3121 if ((field_status.file_status & 1) EQ 0)
3122 return FALSE;
3123
3124 /*
3125 * check Location Information
3126 */
3127 if (FKT_Select (SIM_IMSI, FALSE, NULL,response, SIM_MIN_EF_ST_LEN) EQ SIM_NO_ERROR)
3128 memcpy(&field_status,response,SIM_MIN_EF_ST_LEN);
3129 else
3130 return FALSE;
3131
3132 /*
3133 * check invalidation flag
3134 */
3135 if ((field_status.file_status & 1) EQ 0)
3136 return FALSE;
3137
3138 /*
3139 * both fields are not invalidated
3140 */
3141 return TRUE;
3142 }
3143
3144
3145 /*
3146 +--------------------------------------------------------------------+
3147 | PROJECT : GSM-PS (6302) MODULE : SIM_APP |
3148 | STATE : code ROUTINE : app_bdn_capability_request |
3149 +--------------------------------------------------------------------+
3150
3151 PURPOSE : Checks the BDN capability of the SIM card.
3152
3153 */
3154
3155 GLOBAL UBYTE app_bdn_capability_request (void)
3156 {
3157 T_FIELD_STATUS field_status;
3158 UBYTE response[SIMDRV_MAX_RESULT];
3159
3160 TRACE_FUNCTION ("app_bdn_capability_request()");
3161
3162 /*
3163 * check service in sim service table
3164 */
3165 if (SIM_IS_FLAG_CLEARED (SERVICE_31_SUPPORT))
3166 return NO_BDN_SIM;
3167
3168 /*
3169 * Select BDN field and check invalidation flag
3170 */
3171 /* Currently selected EF information is reset to force the selection */
3172 sim_data.act_field = NOT_PRESENT_16BIT;
3173
3174 if (FKT_Select (SIM_BDN, FALSE, NULL, response, SIM_MIN_EF_ST_LEN) EQ SIM_NO_ERROR)
3175
3176 memcpy(&field_status, response, SIM_MIN_EF_ST_LEN);
3177
3178 else
3179 return NO_BDN_SIM;
3180
3181 if ((field_status.file_status & 1) EQ 0)
3182 return BDN_DISABLED;
3183 else
3184 return BDN_ENABLED;
3185
3186 }
3187
3188 /*
3189 +--------------------------------------------------------------------+
3190 | PROJECT : GSM-PS (6302) MODULE : SIM_APP |
3191 | STATE : code ROUTINE : app_fdn_capability_request |
3192 +--------------------------------------------------------------------+
3193
3194 PURPOSE : Checks the FDN capability of the SIM card.
3195
3196 */
3197
3198 GLOBAL UBYTE app_fdn_capability_request (void)
3199 {
3200 T_FIELD_STATUS field_status;
3201 UBYTE response[SIMDRV_MAX_RESULT];
3202
3203 TRACE_FUNCTION ("app_fdn_capability_request()");
3204
3205 /*
3206 * check service in sim service table
3207 */
3208 if (SIM_IS_FLAG_CLEARED (SERVICE_3_SUPPORT))
3209 return NO_FDN_SIM;
3210
3211 /*
3212 * FDN is allocated and activated. Check against ADN.
3213 * Only ADN or FDN is possible.
3214 */
3215 if (SIM_IS_FLAG_CLEARED (SERVICE_2_SUPPORT))
3216 return FDN_ENABLED;
3217
3218 /*
3219 * Select ADN field and check invalidation flag
3220 */
3221 /* Currently selected EF information is reset to force the selection */
3222 sim_data.act_field = NOT_PRESENT_16BIT;
3223
3224 if (FKT_Select (SIM_ADN, FALSE, NULL, response, SIM_MIN_EF_ST_LEN) EQ SIM_NO_ERROR)
3225
3226 memcpy(&field_status, response, SIM_MIN_EF_ST_LEN);
3227
3228 else
3229 return FDN_ENABLED;
3230
3231 if ((field_status.file_status & 1) EQ 0)
3232 return FDN_ENABLED;
3233 else
3234 return FDN_DISABLED;
3235 }
3236
3237
3238 /*
3239 +--------------------------------------------------------------------+
3240 | PROJECT : GSM-PS (6302) MODULE : SIM_APP |
3241 | STATE : code ROUTINE : app_rehabilitate_imsi_loci |
3242 +--------------------------------------------------------------------+
3243
3244 PURPOSE : Tries to rehabilitate IMSI and location information.
3245
3246 */
3247
3248 GLOBAL UBYTE app_rehabilitate_imsi_loci (void)
3249 {
3250 USHORT error;
3251 TRACE_FUNCTION ("app_rehabilitate_imsi_loci()");
3252
3253 /*
3254 * rehabilitate IMSI
3255 */
3256 error = FKT_Select (SIM_LOCI, FALSE, NULL, NULL, 0);
3257 if (error EQ SIM_NO_ERROR OR error EQ SIM_NO_ERR_FILE_ALREADY_SELECTED)
3258
3259 {
3260 if (FKT_Rehabilitate () NEQ SIM_NO_ERROR)
3261 return FALSE;
3262 }
3263 else
3264 return FALSE;
3265
3266 /*
3267 * rehabilitate Location Information
3268 */
3269 if (FKT_Select (SIM_IMSI, FALSE, NULL, NULL, 0) EQ SIM_NO_ERROR)
3270 {
3271 if (FKT_Rehabilitate () NEQ SIM_NO_ERROR)
3272 return FALSE;
3273 }
3274 else
3275 return FALSE;
3276
3277 return TRUE;
3278 }
3279
3280 /*
3281 +--------------------------------------------------------------------+
3282 | PROJECT : GSM-PS (6302) MODULE : SIM_APP |
3283 | STATE : code ROUTINE : app_start_status_timer |
3284 +--------------------------------------------------------------------+
3285
3286 PURPOSE : (Re-)Start the timer for periodical status requests to the
3287 SIM card. If parameter 'condx' is set TRUE, then the timer
3288 is (re-)started regardless of the SIM being a test SIM, or
3289 not. Also entry point for SIM toolkit commands.
3290 */
3291
3292 GLOBAL void app_start_status_timer (BOOL condx)
3293 {
3294 T_TIME t_val;
3295 TRACE_FUNCTION ("app_start_status_timer()");
3296 /*
3297 * start status timer if call is active and SIM is inserted
3298 * for periodic status polling of SIM toolkit polling
3299 */
3300 if (SIM_IS_FLAG_SET (SIM_INSERT))
3301 {
3302 if (SIM_IS_FLAG_SET (CALL_ACTIVE)
3303 #if defined SIM_TOOLKIT
3304 OR (SIM_IS_FLAG_SET (PRO_ACTIVE_SIM) AND
3305 (SIM_IS_FLAG_CLEARED (TEST_MODE_POLLING) OR condx))
3306 #endif
3307 #ifdef TI_PS_FF_SIM_POLL_ALWAYS
3308 OR SIM_IS_FLAG_CLEARED (PRO_ACTIVE_SIM)
3309 #endif
3310 )
3311 { /* when idle polling is enabled, use that timer value (as long as
3312 * it's not more than 30s); else, we're only SIM presence
3313 * detecting, during the call, with an interval of those 30s.
3314 * This will be disabled, at the end of the call, again.
3315 */
3316 #if defined SIM_TOOLKIT
3317 if (sim_data.idle_polling)
3318 {
3319 t_val = (SIM_IS_FLAG_SET (CALL_ACTIVE) AND
3320 sim_data.status_time > THIRTY_SECONDS)?
3321 THIRTY_SECONDS: sim_data.status_time;
3322 }
3323 else
3324 #endif
3325 {
3326 t_val = THIRTY_SECONDS;
3327 }
3328 /*
3329 * Start Status Polling during Call
3330 */
3331 TIMER_PSTART (sim_handle, SIM_TIMER, t_val, t_val);
3332 }
3333 #if defined SIM_TOOLKIT
3334 sim_data.chk_sat_avail = TRUE;
3335 /* stk_proactive_polling();*/
3336 #endif
3337 }
3338 }
3339
3340 /*
3341 +--------------------------------------------------------------------+
3342 | PROJECT : GSM-PS (6302) MODULE : SIM_APP |
3343 | STATE : code ROUTINE : app_check_access_conditions |
3344 +--------------------------------------------------------------------+
3345
3346 PURPOSE : The function checks the access conditions. It sets the
3347 last requested pin number derived from the field status
3348 of the selected file. It returns whether access is
3349 possible or not.
3350 */
3351
3352 GLOBAL BOOL app_check_access_conditions (UBYTE proc, T_FIELD_STATUS *field_status)
3353 {
3354 UBYTE access;
3355
3356 TRACE_FUNCTION ("app_check_access_conditions()");
3357
3358 switch (proc)
3359 {
3360 case ACCESS_READ:
3361 access = field_status->access_1 >> 4;
3362 break;
3363 case ACCESS_UPDATE:
3364 access = field_status->access_1 & 0x0F;
3365 break;
3366 case ACCESS_INCREASE:
3367 access = field_status->access_2 >> 4;
3368 break;
3369 case ACCESS_REHABILITATE:
3370 access = field_status->access_3 >> 4;
3371 break;
3372 case ACCESS_INVALIDATE:
3373 access = field_status->access_3 & 0x0F;
3374 break;
3375 default:
3376 sim_data.last_requested_pin_no = LRP_NEVER;
3377 return FALSE;
3378 }
3379
3380 switch (access)
3381 {
3382 case ALWAYS:
3383 case PIN_1:
3384 case PIN_2:
3385 sim_data.last_requested_pin_no = access;
3386 return TRUE;
3387 default: /* ADM or NEVER */
3388 sim_data.last_requested_pin_no = LRP_NEVER;
3389 return FALSE;
3390 }
3391 }
3392
3393 /*
3394 +--------------------------------------------------------------------+
3395 | PROJECT : GSM-PS (6302) MODULE : SIM_APP |
3396 | STATE : code ROUTINE : app_sim_access_req |
3397 +--------------------------------------------------------------------+
3398
3399 PURPOSE : Process the primitive SIM_ACCESS_REQ.
3400
3401 */
3402
3403 GLOBAL void app_sim_access_req (T_SIM_ACCESS_REQ * sim_access_req_org)
3404 {
3405 USHORT result;
3406 USHORT offset;
3407 USHORT size = 0,length;
3408 USHORT rcvLen = 0;
3409
3410 #ifdef TI_PS_UICC_CHIPSET_15
3411 T_SIMDRV_cmd_header cmd_header;
3412 U8 reader_id = SIMDRV_VAL_READER_ID__RANGE_MIN;
3413 T_SIMDRV_data_info data_info;
3414 T_SIMDRV_result_info result_info;
3415 U8 offset_high;
3416 U8 offset_low;
3417 #endif
3418
3419 static UBYTE get_resp[SIM_TPDU_HEADER_LEN] = {0x00, 0xC0, 0x00, 0x00, 0x00};
3420 T_SIM_ACCESS_CNF *sim_access_cnf;
3421 PPASS (sim_access_req_org, sim_access_req, SIM_ACCESS_REQ);
3422
3423 sim_access_cnf = P_ALLOC (SIM_ACCESS_CNF);
3424
3425 TRACE_FUNCTION ("app_sim_access_req()");
3426
3427 /*
3428 * initialize answer
3429 */
3430 sim_access_cnf->req_id = sim_access_req->req_id;
3431 sim_access_cnf->c_trans_data = 0;
3432 sim_access_cnf->sw1 = sim_access_cnf->sw2 = 0;
3433 memset (sim_access_cnf->trans_data, 0, sizeof (sim_access_cnf->trans_data));
3434 sim_data.sw1 = sim_data.sw2 = 0; /* delete previous result code */
3435
3436 if (SIM_IS_FLAG_SET (SIM_INSERT))
3437 {
3438 /*
3439 * if SIM is inserted, try to select the SIM card.
3440 */
3441 switch (sim_access_req->sim_command)
3442 {
3443 case SIM_GET_RESPONSE:
3444 sim_data.act_directory = NOT_PRESENT_16BIT;
3445 sim_data.act_field = NOT_PRESENT_16BIT;
3446 case SIM_READ_BINARY:
3447 case SIM_READ_RECORD:
3448 case SIM_UPDATE_BINARY:
3449 case SIM_UPDATE_RECORD:
3450 length = (sim_access_req->p3 > 0)?
3451 sim_access_req->p3: NOT_PRESENT_16BIT;
3452 /* Access request coming from AT Command is only for standard files. Hence
3453 path info can be set as NULL */
3454 sim_access_cnf->cause = FKT_Select (sim_access_req->datafield, FALSE, NULL,sim_access_cnf->trans_data, length);
3455 if(sim_access_cnf->cause EQ SIM_NO_ERR_FILE_ALREADY_SELECTED)
3456 sim_access_cnf->cause = SIM_NO_ERROR;
3457 sim_access_cnf->c_trans_data = (USHORT)sim_data.sim_data_len - SIM_TI_DRV_X_BYTES;
3458 sim_access_cnf->sw1 = (UBYTE)(sim_access_cnf->cause >> 8);
3459 sim_access_cnf->sw2 = (UBYTE)sim_access_cnf->cause;
3460 break;
3461 case SIM_TRANSP_CMD:
3462 if (sim_access_req->c_trans_data < 4 OR sim_access_req->c_trans_data > 261
3463 #ifndef ALLOW_CSIM_GSM
3464 OR sim_access_req->trans_data[0] EQ GSM_CLASS
3465 #endif
3466 )
3467 {
3468 sim_access_cnf->cause = SIM_CAUSE_PARAM_WRONG;
3469 break;
3470 }
3471 /* no break */
3472 case SIM_STATUS:
3473 sim_access_cnf->cause = SIM_NO_ERROR;
3474 break;
3475 default:
3476 sim_access_cnf->cause = SIM_CAUSE_PARAM_WRONG;
3477 break;
3478 }
3479 if (sim_access_cnf->cause EQ SIM_NO_ERROR)
3480 {
3481 /*
3482 * switch depending on SIM command
3483 */
3484 switch (sim_access_req->sim_command)
3485 {
3486 case SIM_READ_BINARY:
3487 /*
3488 * calculate offset from P1 and P2
3489 */
3490 offset = (sim_access_req->p1 << 8) + sim_access_req->p2;
3491 /*
3492 * call SIM driver
3493 */
3494
3495 #ifndef TI_PS_UICC_CHIPSET_15
3496 result= SIM_ReadBinary (sim_access_cnf->trans_data,
3497 offset,
3498 (USHORT)sim_access_req->p3,
3499 &size);
3500 #else /* !TI_PS_UICC_CHIPSET_15 */
3501 offset_high = (U8)((offset &0x7F00)>>8); /* to make the 8th bit 0 as per 102.221 */
3502 offset_low = (U8)(offset & 0x00FF);
3503 reader_id = SIMDRV_VAL_READER_ID__RANGE_MIN;
3504 cmd_header.cla = SIMDRV_GSM_CLASS_BYTE;
3505 cmd_header.ins = SIMDRV_INS_READ_BINARY;
3506 cmd_header.p1 =offset_high ;
3507 cmd_header.p2 =offset_low ;
3508 data_info.data = NULL;
3509 data_info.c_data = 0;
3510 result_info.result = (U8 *)sim_access_cnf->trans_data;
3511 result_info.c_result = size;
3512 result_info.len = (USHORT)sim_access_req->p3;
3513
3514 result= simdrv_xch_apdu (reader_id,cmd_header,data_info,&result_info);
3515 size = result_info.c_result; /* c_result will be updated by SIMDRV */
3516 #endif /* !TI_PS_UICC_CHIPSET_15 */
3517
3518 /*
3519 * fill response primitive
3520 */
3521 sim_access_cnf->c_trans_data = (USHORT)size - SIM_TI_DRV_X_BYTES;
3522 sim_access_cnf->sw1 = (UBYTE)(result >> 8);
3523 sim_access_cnf->sw2 = (UBYTE)result;
3524 break;
3525
3526 case SIM_READ_RECORD:
3527 /*
3528 * call SIM driver
3529 */
3530 #ifndef TI_PS_UICC_CHIPSET_15
3531 result = SIM_ReadRecord (sim_access_cnf->trans_data,
3532 sim_access_req->p2,
3533 sim_access_req->p1,
3534 (USHORT)sim_access_req->p3,
3535 &size);
3536 #else /* !TI_PS_UICC_CHIPSET_15 */
3537 reader_id = SIMDRV_VAL_READER_ID__RANGE_MIN;
3538 cmd_header.cla = SIMDRV_GSM_CLASS_BYTE ;
3539 cmd_header.ins = SIMDRV_INS_READ_RECORD;
3540 cmd_header.p1 = (U8)sim_access_req->p1;
3541 cmd_header.p2 = (U8)sim_access_req->p2;
3542 data_info.data = NULL;
3543 data_info.c_data = 0;
3544 result_info.result = (U8 *)sim_access_cnf->trans_data ;
3545 result_info.c_result = size;
3546 result_info.len =(USHORT)sim_access_req->p3;
3547
3548 result= simdrv_xch_apdu (reader_id,cmd_header,data_info, &result_info);
3549 size = result_info.c_result; /* c_result will be updated by SIMDRV */
3550 #endif /* !TI_PS_UICC_CHIPSET_15 */
3551 /*
3552 * fill response primitive
3553 */
3554 sim_access_cnf->c_trans_data = (USHORT)size - SIM_TI_DRV_X_BYTES;
3555 sim_access_cnf->sw1 = (UBYTE)(result >> 8);
3556 sim_access_cnf->sw2 = (UBYTE)result;
3557 break;
3558
3559 case SIM_GET_RESPONSE:
3560 /*
3561 * call SIM driver
3562 */
3563 #ifndef TI_PS_UICC_CHIPSET_15
3564 length = (sim_access_req->p3 > 0)?
3565 sim_access_req->p3: sim_data.sim_data_len;
3566
3567 result = SIM_GetResponse (sim_access_cnf->trans_data,
3568 length,
3569 &size);
3570 sim_access_cnf->c_trans_data = (USHORT)size - SIM_TI_DRV_X_BYTES;
3571 sim_access_cnf->sw1 = (UBYTE)(result >> 8);
3572 sim_access_cnf->sw2 = (UBYTE)result;
3573 #endif
3574 break;
3575
3576 case SIM_UPDATE_BINARY:
3577 /*
3578 * calculate offset from P1 and P2
3579 */
3580 offset = (sim_access_req->p1 << 8) + sim_access_req->p2;
3581 /*
3582 * call SIM driver
3583 */
3584 #ifndef TI_PS_UICC_CHIPSET_15
3585 result= SIM_UpdateBinary (sim_access_cnf->trans_data,
3586 sim_access_req->trans_data,
3587 offset,
3588 (USHORT)sim_access_req->p3,
3589 &size);
3590
3591 #else /* !TI_PS_UICC_CHIPSET_15 */
3592 offset_high = (U8)((offset &0x7F00)>>8);/*to make the 8th bit 0 as per 102.221*/
3593 offset_low = (U8)(offset & 0x00FF);
3594 reader_id = SIMDRV_VAL_READER_ID__RANGE_MIN;
3595 cmd_header.cla = SIMDRV_GSM_CLASS_BYTE ;
3596 cmd_header.ins = SIMDRV_INS_UPDATE_BINARY;
3597 cmd_header.p1 = offset_high;
3598 cmd_header.p2 = offset_low;
3599 data_info.data = (U8 *)sim_access_req->trans_data;
3600 data_info.c_data = (U8)sim_access_req->p3;
3601 result_info.result = sim_access_cnf->trans_data;
3602 result_info.c_result = size;
3603 result_info.len = NOT_PRESENT_16BIT;
3604
3605 result= simdrv_xch_apdu (reader_id,cmd_header,data_info,&result_info);
3606 size = result_info.c_result; /* c_result will be updated by SIMDRV */
3607 #endif /* !TI_PS_UICC_CHIPSET_15 */
3608 /*
3609 * fill response primitive
3610 */
3611 sim_access_cnf->sw1 = (UBYTE)(result >> 8);
3612 sim_access_cnf->sw2 = (UBYTE)result;
3613 break;
3614
3615 case SIM_UPDATE_RECORD:
3616 /*
3617 * call SIM driver
3618 */
3619 #ifndef TI_PS_UICC_CHIPSET_15
3620 result = SIM_UpdateRecord (sim_access_cnf->trans_data,
3621 sim_access_req->trans_data,
3622 sim_access_req->p2,
3623 sim_access_req->p1,
3624 (USHORT)sim_access_req->p3,
3625 &size);
3626
3627 #else /* !TI_PS_UICC_CHIPSET_15 */
3628 reader_id = SIMDRV_VAL_READER_ID__RANGE_MIN;
3629 cmd_header.cla = SIMDRV_GSM_CLASS_BYTE ;
3630 cmd_header.ins = SIMDRV_INS_UPDATE_RECORD;
3631 cmd_header.p1 = (U8)sim_access_req->p1;
3632 cmd_header.p2 = (U8)sim_access_req->p2;
3633 data_info.data = (U8*)sim_access_req->trans_data;
3634 data_info.c_data = (U8)sim_access_req->p3;
3635 result_info.result = sim_access_cnf->trans_data;
3636 result_info.c_result = size;
3637 result_info.len = NOT_PRESENT_16BIT;
3638
3639 result= simdrv_xch_apdu (reader_id,cmd_header,data_info,&result_info);
3640 size = result_info.c_result; /* c_result will be updated by SIMDRV */
3641 #endif /* !TI_PS_UICC_CHIPSET_15 */
3642 /*
3643 * fill response primitive
3644 */
3645 sim_access_cnf->sw1 = (UBYTE)(result >> 8);
3646 sim_access_cnf->sw2 = (UBYTE)result;
3647 break;
3648
3649 case SIM_STATUS:
3650 /*
3651 * call SIM driver
3652 */
3653 length = (sim_access_req->p3 > 0)?
3654 (USHORT)sim_access_req->p3: sim_data.dir_status_len;
3655
3656 #ifndef TI_PS_UICC_CHIPSET_15
3657 result = SIM_Status_Extended (sim_access_cnf->trans_data,
3658 length,
3659 &size);
3660 #else /* !TI_PS_UICC_CHIPSET_15 */
3661 reader_id = SIMDRV_VAL_READER_ID__RANGE_MIN;
3662
3663 cmd_header.cla = SIMDRV_GSM_CLASS_BYTE;
3664 cmd_header.ins = SIMDRV_INS_STATUS;
3665 cmd_header.p1 = 0;
3666 cmd_header.p2 = 0;
3667
3668 data_info.data = NULL;
3669 data_info.c_data = 0;
3670
3671 result_info.result = (U8 *)sim_access_cnf->trans_data;
3672 result_info.len = length;
3673 result_info.c_result = size;
3674
3675 result = simdrv_xch_apdu(reader_id, cmd_header, data_info, &result_info);
3676 size = result_info.c_result; /* c_result will be updated by SIMDRV */
3677 #endif /* !TI_PS_UICC_CHIPSET_15 */
3678
3679 sim_access_cnf->c_trans_data = (USHORT)size - SIM_TI_DRV_X_BYTES;
3680 sim_access_cnf->sw1 = (UBYTE)(result >> 8);
3681 sim_access_cnf->sw2 = (UBYTE)result;
3682 break;
3683
3684 case SIM_TRANSP_CMD:
3685 /*
3686 * transparent SIM access
3687 */
3688 #ifdef TI_PS_UICC_CHIPSET_15
3689 #ifdef _SIMULATION_
3690 sim_command_type = SIM_TRANSP_CMD;
3691 #endif
3692 #endif
3693 if (sim_access_req->c_trans_data EQ 4)
3694 {
3695 sim_access_req->trans_data[4] = '\0';
3696 sim_access_req->c_trans_data = 5;
3697
3698 #ifndef TI_PS_UICC_CHIPSET_15
3699 result = SIM_XchTPDU (sim_access_req->trans_data,
3700 sim_access_req->c_trans_data,
3701 sim_access_cnf->trans_data,
3702 0, &sim_access_cnf->c_trans_data);
3703 #else /* !TI_PS_UICC_CHIPSET_15 */
3704 cmd_header.cla = sim_access_req->trans_data[0];
3705 cmd_header.ins = sim_access_req->trans_data[1];
3706 cmd_header.p1 = sim_access_req->trans_data[2];
3707 cmd_header.p2 = sim_access_req->trans_data[3];
3708
3709 data_info.data = &sim_access_req->trans_data[5];
3710 data_info.c_data = (U8)sim_access_req->c_trans_data;
3711
3712 result_info.result = sim_access_cnf->trans_data;
3713 result_info.len = (USHORT)sim_access_req->trans_data[4];
3714 result_info.c_result = sim_access_cnf->c_trans_data;
3715
3716 result = simdrv_xch_apdu (reader_id, cmd_header, data_info, &result_info);
3717 sim_access_cnf->c_trans_data = result_info.c_result;
3718 #endif /* !TI_PS_UICC_CHIPSET_15 */
3719
3720 }
3721 else if (sim_access_req->c_trans_data EQ 5)
3722 {
3723 rcvLen = (USHORT)sim_access_req->trans_data[4];
3724 if (rcvLen EQ 0)
3725 rcvLen = 256;
3726 #ifndef TI_PS_UICC_CHIPSET_15
3727 result = SIM_XchTPDU (sim_access_req->trans_data,
3728 sim_access_req->c_trans_data,
3729 sim_access_cnf->trans_data,
3730 rcvLen, &sim_access_cnf->c_trans_data);
3731 #else /* !TI_PS_UICC_CHIPSET_15 */
3732 cmd_header.cla = sim_access_req->trans_data[0];
3733 cmd_header.ins = sim_access_req->trans_data[1];
3734 cmd_header.p1 = sim_access_req->trans_data[2];
3735 cmd_header.p2 = sim_access_req->trans_data[3];
3736
3737 data_info.data = &sim_access_req->trans_data[5];
3738 data_info.c_data = (U8)sim_access_req->c_trans_data;
3739
3740 result_info.result = sim_access_cnf->trans_data;
3741 result_info.len = (USHORT)sim_access_req->trans_data[4];
3742 result_info.c_result = sim_access_cnf->c_trans_data;
3743
3744 result = simdrv_xch_apdu (reader_id, cmd_header, data_info, &result_info);
3745 sim_access_cnf->c_trans_data = result_info.c_result;
3746 #endif /* !TI_PS_UICC_CHIPSET_15 */
3747 }
3748 else
3749 {
3750 if (sim_access_req->c_trans_data EQ ((USHORT)sim_access_req->trans_data[4] + 6))
3751 {
3752 rcvLen = (USHORT)sim_access_req->trans_data[--sim_access_req->c_trans_data];
3753 if (rcvLen EQ 0)
3754 rcvLen = 256;
3755 }
3756 #ifndef TI_PS_UICC_CHIPSET_15
3757 result = SIM_XchTPDU (sim_access_req->trans_data,
3758 sim_access_req->c_trans_data,
3759 sim_access_cnf->trans_data,
3760 0, &sim_access_cnf->c_trans_data);
3761 #else /* !TI_PS_UICC_CHIPSET_15 */
3762 cmd_header.cla = sim_access_req->trans_data[0];
3763 cmd_header.ins = sim_access_req->trans_data[1];
3764 cmd_header.p1 = sim_access_req->trans_data[2];
3765 cmd_header.p2 = sim_access_req->trans_data[3];
3766
3767 data_info.data = &sim_access_req->trans_data[5];
3768 data_info.c_data = (U8)sim_access_req->c_trans_data;
3769
3770 result_info.result = sim_access_cnf->trans_data;
3771 result_info.len = (USHORT)sim_access_req->trans_data[4];
3772 result_info.c_result = sim_access_cnf->c_trans_data;
3773
3774 result = simdrv_xch_apdu (reader_id, cmd_header, data_info, &result_info);
3775 sim_access_cnf->c_trans_data = result_info.c_result;
3776 #endif /* !TI_PS_UICC_CHIPSET_15 */
3777 {
3778 USHORT sw1, sw2;
3779
3780 sw1 = (result >> 8);
3781 sw2 = result & 0xFF;
3782
3783 if (sw1 EQ 0x61)
3784 {
3785 if ((rcvLen <= 0) OR (sw2 < rcvLen))
3786 rcvLen = sw2;
3787 }
3788 else if (sw1 NEQ 0x90)
3789 {
3790 rcvLen = 0;
3791 }
3792 if (rcvLen > 0)
3793 {
3794 TRACE_EVENT_P2 ("SW1=%02X SW2=%02X", (int)sw1, (int)sw2);
3795
3796 get_resp[0] = sim_access_req->trans_data[0];
3797 get_resp[4] = (UBYTE)rcvLen;
3798
3799 #ifndef TI_PS_UICC_CHIPSET_15
3800 result = SIM_XchTPDU (get_resp, SIM_TPDU_HEADER_LEN,
3801 sim_access_cnf->trans_data,
3802 rcvLen,
3803 &sim_access_cnf->c_trans_data);
3804 #else /* !TI_PS_UICC_CHIPSET_15 */
3805 cmd_header.cla = get_resp[0];
3806 cmd_header.ins = get_resp[1];
3807 cmd_header.p1 = get_resp[2];
3808 cmd_header.p2 = get_resp[3];
3809
3810 data_info.data = &get_resp[5];
3811 data_info.c_data = SIM_TPDU_HEADER_LEN;
3812
3813 result_info.result = sim_access_cnf->trans_data;
3814 result_info.len = (USHORT)get_resp[4];
3815 result_info.c_result = sim_access_cnf->c_trans_data;
3816
3817 result = simdrv_xch_apdu (reader_id, cmd_header, data_info, &result_info);
3818 sim_access_cnf->c_trans_data = result_info.c_result;
3819 #endif /* !TI_PS_UICC_CHIPSET_15 */
3820
3821 }
3822 }
3823 }
3824 size = (sim_access_cnf->c_trans_data -= SIM_TI_DRV_X_BYTES);
3825
3826 if ((result & 0xF000) EQ 0x6000 OR
3827 (result & 0xF000) EQ 0x9000)
3828 {
3829 sim_access_cnf->sw1 = (UBYTE)(result >> 8);
3830 sim_access_cnf->sw2 = (UBYTE)result;
3831 }
3832 else if ((result & 0xFF00) EQ 0)
3833 {
3834 sim_access_cnf->cause = CAUSE_MAKE(DEFBY_CONDAT, ORIGSIDE_MS,
3835 SIM_ORIGINATING_ENTITY, result);
3836 }
3837 else
3838 {
3839 sim_access_cnf->cause = SIM_CAUSE_OTHER_ERROR;
3840 }
3841 break;
3842
3843 default:
3844 sim_access_cnf->cause = SIM_CAUSE_PARAM_WRONG;
3845 break;
3846 }
3847 TRACE_EVENT_P3 ("SW1=%02X SW2=%02X SIZE=%d", sim_access_cnf->sw1,
3848 sim_access_cnf->sw2, (int)size);
3849 /*
3850 * start status timer again
3851 */
3852 app_start_status_timer (FALSE);
3853 }
3854 else
3855 {
3856 sim_access_cnf->sw1 = sim_data.sw1;
3857 sim_access_cnf->sw2 = sim_data.sw2;
3858 }
3859 }
3860 else
3861 /*
3862 * sim is not inserted
3863 */
3864 sim_access_cnf->cause = SIM_CAUSE_CARD_REMOVED;
3865
3866 /*
3867 * free incoming primitive
3868 */
3869 PFREE (sim_access_req);
3870
3871 /*
3872 * send result to MMI
3873 */
3874 PSENDX (MMI, sim_access_cnf);
3875 }
3876
3877
3878 #endif