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

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