comparison src/cs/drivers/drv_app/sim/sim.c @ 189:b37e6c916df1

../drv_app/sim/*: rm trailing white space
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 30 Jan 2021 06:34:22 +0000
parents 4e78acac3d88
children c1205c437943
comparison
equal deleted inserted replaced
188:92abb46dc1ba 189:b37e6c916df1
1 /* 1 /*
2 * SIM.C 2 * SIM.C
3 * 3 *
4 * Pole Star SIM 4 * Pole Star SIM
5 * 5 *
6 * Target : ARM 6 * Target : ARM
7 * 7 *
8 * 8 *
9 * SIM card driver. This module contents all functions 9 * SIM card driver. This module contents all functions
10 * included in specifications GSM 11.11 V4.10 10 * included in specifications GSM 11.11 V4.10
11 * 11 *
12 * 12 *
13 * Copyright (c) Texas Instruments 1995-1997 13 * Copyright (c) Texas Instruments 1995-1997
14 * 14 *
15 */ 15 */
16 16
17 #define SIM_C 1 17 #define SIM_C 1
18 18
19 #ifndef _WINDOWS 19 #ifndef _WINDOWS
20 #include "l1sw.cfg" 20 #include "l1sw.cfg"
21 #include "chipset.cfg" 21 #include "chipset.cfg"
22 #endif 22 #endif
23 23
24 #include "main/sys_types.h" 24 #include "main/sys_types.h"
25 25
26 #include "memif/mem.h" 26 #include "memif/mem.h"
62 /* size of buffer tracing the chronology of calls */ 62 /* size of buffer tracing the chronology of calls */
63 #define SIM_DBG_CMD 7500 63 #define SIM_DBG_CMD 7500
64 /* working buffer for chronology calls */ 64 /* working buffer for chronology calls */
65 SYS_UWORD8 SIM_dbg_cmd[SIM_DBG_CMD]; 65 SYS_UWORD8 SIM_dbg_cmd[SIM_DBG_CMD];
66 /* index for positionning in working buffer for chronology calls */ 66 /* index for positionning in working buffer for chronology calls */
67 SYS_UWORD16 SIM_dbg_cmd_cmpt; 67 SYS_UWORD16 SIM_dbg_cmd_cmpt;
68 /* working variable to calculate the TDMA ecart */ 68 /* working variable to calculate the TDMA ecart */
69 SYS_UWORD16 SIM_dbg_tdma_diff; 69 SYS_UWORD16 SIM_dbg_tdma_diff;
70 /* working variable to store the maximum TDMA frame between two characters */ 70 /* working variable to store the maximum TDMA frame between two characters */
71 SYS_UWORD16 SIM_dbg_max_interchardelay; 71 SYS_UWORD16 SIM_dbg_max_interchardelay;
72 /* working variable used in each L2/L3 access function */ 72 /* working variable used in each L2/L3 access function */
91 /* 91 /*
92 * Low level routines : mapped to hardware 92 * Low level routines : mapped to hardware
93 * SIM_WriteBuffer 93 * SIM_WriteBuffer
94 * SIM_Command 94 * SIM_Command
95 * SIM_Reset 95 * SIM_Reset
96 * 96 *
97 */ 97 */
98 98
99 99
100 100
101 /* 101 /*
103 * 103 *
104 * Write n bytes to SIM card in interrupt mode: 104 * Write n bytes to SIM card in interrupt mode:
105 * return the line, write first byte and let interrupt handler do the rest 105 * return the line, write first byte and let interrupt handler do the rest
106 * return the line, write first byte and let interrupt handler do the rest 106 * return the line, write first byte and let interrupt handler do the rest
107 * 107 *
108 * Parameters : 108 * Parameters :
109 * SIM_PORT *p : buffer for received chars 109 * SIM_PORT *p : buffer for received chars
110 * offset : starting point for reading data. 110 * offset : starting point for reading data.
111 * n : number of chars to read. 111 * n : number of chars to read.
112 */ 112 */
113 void SIM_WriteBuffer(SIM_PORT *p, SYS_UWORD16 offset, SYS_UWORD16 n) 113 void SIM_WriteBuffer(SIM_PORT *p, SYS_UWORD16 offset, SYS_UWORD16 n)
126 p->xIn = p->xbuf + offset + n; 126 p->xIn = p->xbuf + offset + n;
127 127
128 if ((p->xIn - p->xOut) == 1) //if only one char is transmitted 128 if ((p->xIn - p->xOut) == 1) //if only one char is transmitted
129 { //need to wait a minimum of 1 ETU 129 { //need to wait a minimum of 1 ETU
130 ind_os_sleep (1); //for IO line to stay in TX mode 130 ind_os_sleep (1); //for IO line to stay in TX mode
131 } 131 }
132 // Write first byte 132 // Write first byte
133 p->c->tx = *(p->xOut); // transmit 133 p->c->tx = *(p->xOut); // transmit
134 134
135 if ((p->xIn - p->xOut) == 1) //if only one char to transmit 135 if ((p->xIn - p->xOut) == 1) //if only one char to transmit
136 { // return the direction to rx 136 { // return the direction to rx
137 p->conf1 &= ~SIM_CONF1_TXRX; //to be able to receive ACK char 137 p->conf1 &= ~SIM_CONF1_TXRX; //to be able to receive ACK char
138 p->c->conf1 = p->conf1; 138 p->c->conf1 = p->conf1;
139 139
140 } 140 }
141 } 141 }
142 142
143 /* 143 /*
144 * SIM_Result 144 * SIM_Result
145 * 145 *
146 * Parameters : SIM port, buffer for received chars, pointer to receive size 146 * Parameters : SIM port, buffer for received chars, pointer to receive size
147 * 147 *
148 * Return the result code (SW1/SW2) at the end of the string 148 * Return the result code (SW1/SW2) at the end of the string
149 */ 149 */
150 SYS_UWORD16 SIM_Result(SIM_PORT *p, SYS_UWORD8 *rP, SYS_UWORD16 *lenP, SYS_UWORD8 offset) 150 SYS_UWORD16 SIM_Result(SIM_PORT *p, SYS_UWORD8 *rP, SYS_UWORD16 *lenP, SYS_UWORD8 offset)
151 { 151 {
152 SYS_UWORD8 sw1, sw2; 152 SYS_UWORD8 sw1, sw2;
153 SYS_UWORD8 verdict; 153 SYS_UWORD8 verdict;
154 SYS_UWORD16 len; 154 SYS_UWORD16 len;
155 155
156 // Check if all characters were transmitted 156 // Check if all characters were transmitted
157 if (p->xIn - 1 != p->xOut) 157 if (p->xIn - 1 != p->xOut)
158 return (SIM_ERR_XMIT); 158 return (SIM_ERR_XMIT);
159 159
160 len = p->rx_index; 160 len = p->rx_index;
161 *lenP = len - offset; 161 *lenP = len - offset;
162 if ((*lenP == 0) && (p->apdu_ans_length == 256)) 162 if ((*lenP == 0) && (p->apdu_ans_length == 256))
163 *lenP = 256; 163 *lenP = 256;
164 164
165 if (p->expected_data == 256) 165 if (p->expected_data == 256)
166 { 166 {
167 verdict = SIM_Memcpy(rP, ((p->rbuf) + offset), 256 - offset); 167 verdict = SIM_Memcpy(rP, ((p->rbuf) + offset), 256 - offset);
168 if (verdict != 0) 168 if (verdict != 0)
169 { 169 {
170 return (verdict); 170 return (verdict);
171 } 171 }
172 } 172 }
173 else if ((len != 0) && (len >= offset)) 173 else if ((len != 0) && (len >= offset))
174 { 174 {
176 if (verdict != 0) 176 if (verdict != 0)
177 { 177 {
178 return (verdict); 178 return (verdict);
179 } 179 }
180 } 180 }
181 181
182 // change to remove SW1 and SW2 bytes from the receive buffer of data 182 // change to remove SW1 and SW2 bytes from the receive buffer of data
183 sw1 = p->rSW12[0]; 183 sw1 = p->rSW12[0];
184 sw2 = p->rSW12[1]; 184 sw2 = p->rSW12[1];
185 185
186 return((sw1 << 8) | sw2); 186 return((sw1 << 8) | sw2);
187 } 187 }
202 * Returns an error code : 202 * Returns an error code :
203 * SIM_ERR_READ : no answer from the card to a command 203 * SIM_ERR_READ : no answer from the card to a command
204 * SIM_ERR_LEN : the answer is not corresponding to a 204 * SIM_ERR_LEN : the answer is not corresponding to a
205 * correct answer of T=0 protocol 205 * correct answer of T=0 protocol
206 * 06/11/2002 JYT 206 * 06/11/2002 JYT
207 * Modified to be base command function. New SIM_Command() created to call it 207 * Modified to be base command function. New SIM_Command() created to call it
208 * with wrapper. Created to manage retries on Internals errors of the driver. 208 * with wrapper. Created to manage retries on Internals errors of the driver.
209 */ 209 */
210 210
211 SYS_UWORD16 SIM_Command_Base(SIM_PORT *p, SYS_UWORD16 n, SYS_UWORD8 *dP, SYS_UWORD16 *lP) 211 SYS_UWORD16 SIM_Command_Base(SIM_PORT *p, SYS_UWORD16 n, SYS_UWORD8 *dP, SYS_UWORD16 *lP)
212 { 212 {
324 return(res); 324 return(res);
325 } 325 }
326 326
327 327
328 /* Main function to manage the retry mechanism */ 328 /* Main function to manage the retry mechanism */
329 SYS_UWORD16 SIM_Command(SIM_PORT *p, SYS_UWORD16 n, SYS_UWORD8 *dP, SYS_UWORD16 *lP) { 329 SYS_UWORD16 SIM_Command(SIM_PORT *p, SYS_UWORD16 n, SYS_UWORD8 *dP, SYS_UWORD16 *lP) {
330 int res; 330 int res;
331 331
332 #ifdef SIM_DEBUG_TRACE 332 #ifdef SIM_DEBUG_TRACE
333 memset(SIM_dbg_null, 0x00, SIM_DBG_NULL); 333 memset(SIM_dbg_null, 0x00, SIM_DBG_NULL);
334 SIM_dbg_tdma_diff = 0; 334 SIM_dbg_tdma_diff = 0;
361 361
362 362
363 363
364 364
365 365
366 366
367 /* 367 /*
368 * SIM_ByteReverse 368 * SIM_ByteReverse
369 * 369 *
370 * Reverse a byte, both up/down (1 <> 0) and left/right (0001 <> 1000) 370 * Reverse a byte, both up/down (1 <> 0) and left/right (0001 <> 1000)
371 * 371 *
372 */ 372 */
373 SYS_UWORD8 SIM_ByteReverse(SYS_UWORD8 b) 373 SYS_UWORD8 SIM_ByteReverse(SYS_UWORD8 b)
374 { 374 {
375 SYS_UWORD8 bh, bl; 375 SYS_UWORD8 bh, bl;
376 int i; 376 int i;
377 const SYS_UWORD8 Reverse[] = {0x0, 0x8, 0x4, 0xC, 0x2, 0xA, 0x6, 0xE, 377 const SYS_UWORD8 Reverse[] = {0x0, 0x8, 0x4, 0xC, 0x2, 0xA, 0x6, 0xE,
378 0x1, 0x9, 0x5, 0xD, 0x3, 0xB, 0x7, 0xF }; 378 0x1, 0x9, 0x5, 0xD, 0x3, 0xB, 0x7, 0xF };
379 379
380 // Up/Down 380 // Up/Down
381 b = ~ b; 381 b = ~ b;
382 382
383 // left / right (by nibble) 383 // left / right (by nibble)
384 bh = (b >> 4) & 0xF; 384 bh = (b >> 4) & 0xF;
385 bl = b & 0xF; 385 bl = b & 0xF;
386 386
387 b = (Reverse[bl]) << 4 | Reverse[bh]; 387 b = (Reverse[bl]) << 4 | Reverse[bh];
388 return(b); 388 return(b);
389 389
390 } 390 }
391 391
392 /* 392 /*
393 * SIM_TxParityErrors 393 * SIM_TxParityErrors
394 * 394 *
407 407
408 408
409 /* 409 /*
410 * SIM_Reset 410 * SIM_Reset
411 * 411 *
412 * Reset SIM card 412 * Reset SIM card
413 * Call-back SIM insert if successful 413 * Call-back SIM insert if successful
414 * or SIM remove otherwise 414 * or SIM remove otherwise
415 * 415 *
416 * Returns 0 for success, or 416 * Returns 0 for success, or
417 * SIM_ERR_NOCARD : no card 417 * SIM_ERR_NOCARD : no card
418 * SIM_ERR_NATR : no answer to reset 418 * SIM_ERR_NATR : no answer to reset
419 * SIM_ERR_NOINT : no 419 * SIM_ERR_NOINT : no
420 * SIM_ERR_READ : unknown data return by the card 420 * SIM_ERR_READ : unknown data return by the card
421 * SIM_ERR_CARDREJECT : card not accepted 421 * SIM_ERR_CARDREJECT : card not accepted
422 * 422 *
423 * 29/01/02, JYT, adding of low voltage managment for IOTA device 423 * 29/01/02, JYT, adding of low voltage managment for IOTA device
424 * 06/10/03, JYT, Split of Reset to handle Restart 424 * 06/10/03, JYT, Split of Reset to handle Restart
425 */ 425 */
426 SYS_UWORD16 SIM_Reset(SIM_CARD *cP) 426 SYS_UWORD16 SIM_Reset(SIM_CARD *cP)
427 { 427 {
428 return(SIM_Reset_Restart_Internal(cP, 1)); 428 return(SIM_Reset_Restart_Internal(cP, 1));
429 } 429 }
430 430
435 435
436 436
437 /* 437 /*
438 * SIM_Restart 438 * SIM_Restart
439 * 439 *
440 * Restart SIM card 440 * Restart SIM card
441 * 441 *
442 * Returns 0 for success, or 442 * Returns 0 for success, or
443 * SIM_ERR_NOCARD : no card 443 * SIM_ERR_NOCARD : no card
444 * SIM_ERR_NATR : no answer to reset 444 * SIM_ERR_NATR : no answer to reset
445 * SIM_ERR_NOINT : no 445 * SIM_ERR_NOINT : no
446 * SIM_ERR_READ : unknown data return by the card 446 * SIM_ERR_READ : unknown data return by the card
447 * SIM_ERR_CARDREJECT : card not accepted 447 * SIM_ERR_CARDREJECT : card not accepted
448 * 448 *
449 * 06/10/03, JYT, Split of Reset to handle Restart 449 * 06/10/03, JYT, Split of Reset to handle Restart
450 */ 450 */
451 SYS_UWORD16 SIM_Restart(SIM_CARD *cP) 451 SYS_UWORD16 SIM_Restart(SIM_CARD *cP)
452 { 452 {
453 return(SIM_Reset_Restart_Internal(cP, 0)); 453 return(SIM_Reset_Restart_Internal(cP, 0));
454 } 454 }
455 455
456 456
457 /* 457 /*
458 * SIM_Reset_Restart_Internal 458 * SIM_Reset_Restart_Internal
459 * 459 *
460 * Reset SIM card 460 * Reset SIM card
461 * Call-back SIM insert if successful 461 * Call-back SIM insert if successful
462 * or SIM remove otherwise 462 * or SIM remove otherwise
463 * 463 *
464 * Returns 0 for success, or 464 * Returns 0 for success, or
465 * SIM_ERR_NOCARD : no card 465 * SIM_ERR_NOCARD : no card
466 * SIM_ERR_NATR : no answer to reset 466 * SIM_ERR_NATR : no answer to reset
467 * SIM_ERR_NOINT : no 467 * SIM_ERR_NOINT : no
468 * SIM_ERR_READ : unknown data return by the card 468 * SIM_ERR_READ : unknown data return by the card
469 * SIM_ERR_CARDREJECT : card not accepted 469 * SIM_ERR_CARDREJECT : card not accepted
470 * 470 *
471 * 29/01/02, JYT, adding of low voltage managment for IOTA device 471 * 29/01/02, JYT, adding of low voltage managment for IOTA device
472 * 06/10/03, JYT, Split of Reset to handle Restart, ResetFlag added. 472 * 06/10/03, JYT, Split of Reset to handle Restart, ResetFlag added.
473 */ 473 */
474 SYS_UWORD16 SIM_Reset_Restart_Internal(SIM_CARD *cP, SYS_UWORD8 ResetFlag) 474 SYS_UWORD16 SIM_Reset_Restart_Internal(SIM_CARD *cP, SYS_UWORD8 ResetFlag)
475 { 475 {
476 SIM_PORT *p; 476 SIM_PORT *p;
477 unsigned int ATR_Attempt; 477 unsigned int ATR_Attempt;
478 SYS_UWORD8 BackValue; 478 SYS_UWORD8 BackValue;
482 memset(SIM_dbg_null, 0x00, SIM_DBG_NULL); 482 memset(SIM_dbg_null, 0x00, SIM_DBG_NULL);
483 SIM_dbg_cmd_cmpt = 0; 483 SIM_dbg_cmd_cmpt = 0;
484 memset(SIM_dbg_cmd, 0x00, SIM_DBG_CMD); 484 memset(SIM_dbg_cmd, 0x00, SIM_DBG_CMD);
485 #endif 485 #endif
486 486
487 // Initialize pointers 487 // Initialize pointers
488 p = &(Sim[0]); 488 p = &(Sim[0]);
489 489
490 // begin of JYT modifications 490 // begin of JYT modifications
491 if ( (BackValue = SIM_StartVolt(ResetFlag)) != SIM_OK) 491 if ( (BackValue = SIM_StartVolt(ResetFlag)) != SIM_OK)
492 return((SYS_UWORD16)BackValue); 492 return((SYS_UWORD16)BackValue);
501 COLD_RESET: 501 COLD_RESET:
502 502
503 p->SWcount = 0; 503 p->SWcount = 0;
504 p->Freq_Algo = 0; 504 p->Freq_Algo = 0;
505 p->PTS_Try = 0; //use to calculate how many PTS try were already done 505 p->PTS_Try = 0; //use to calculate how many PTS try were already done
506 506
507 // Initialize pointers 507 // Initialize pointers
508 p->xIn = p->xOut = p->xbuf; 508 p->xIn = p->xOut = p->xbuf;
509 p->rx_index = 0; 509 p->rx_index = 0;
510 p->errorSIM = 0; 510 p->errorSIM = 0;
511 p->moderx = 0; 511 p->moderx = 0;
512 p->null_received = 0; 512 p->null_received = 0;
513 513
514 BackValue = SIM_ManualStart(p); 514 BackValue = SIM_ManualStart(p);
515 if (BackValue != 0) 515 if (BackValue != 0)
516 return ((SYS_UWORD16)BackValue); 516 return ((SYS_UWORD16)BackValue);
517 517
518 518
519 p->c->conf1 = p->conf1 &= ~SIM_CONF1_BYPASS; //switch to automatic mode 519 p->c->conf1 = p->conf1 &= ~SIM_CONF1_BYPASS; //switch to automatic mode
520 520
521 //#else //SW_WRK_AROUND_H_S == 0 // Automatic procedure -> fails with test 27.11.2.1 521 //#else //SW_WRK_AROUND_H_S == 0 // Automatic procedure -> fails with test 27.11.2.1
522 // 522 //
523 // // Mask all interrupts 523 // // Mask all interrupts
524 // p->c->maskit = SIM_MASK_NATR | SIM_MASK_WT | SIM_MASK_OV | 524 // p->c->maskit = SIM_MASK_NATR | SIM_MASK_WT | SIM_MASK_OV |
525 // SIM_MASK_TX | SIM_MASK_RX | SIM_MASK_CD; 525 // SIM_MASK_TX | SIM_MASK_RX | SIM_MASK_CD;
526 // 526 //
527 // 527 //
528 // IQ_Unmask (IQ_SIM); // Unmask interrupt controller 528 // IQ_Unmask (IQ_SIM); // Unmask interrupt controller
529 // 529 //
530 // 530 //
531 // p->c->cmd = (p->c->cmd & MASK_CMD) | SIM_CMD_STOP; 531 // p->c->cmd = (p->c->cmd & MASK_CMD) | SIM_CMD_STOP;
532 // ind_os_sleep(1); 532 // ind_os_sleep(1);
533 // 533 //
534 // p->c->cmd = (p->c->cmd & MASK_CMD) | SIM_CMD_SWRST; // Set START bit and wait a while 534 // p->c->cmd = (p->c->cmd & MASK_CMD) | SIM_CMD_SWRST; // Set START bit and wait a while
535 // ind_os_sleep(1); 535 // ind_os_sleep(1);
536 // // Unmask all sources of interrupts except WT, OV, and NATR 536 // // Unmask all sources of interrupts except WT, OV, and NATR
537 // p->c->maskit = SIM_MASK_OV | SIM_MASK_WT | SIM_MASK_NATR; 537 // p->c->maskit = SIM_MASK_OV | SIM_MASK_WT | SIM_MASK_NATR;
538 // 538 //
546 // #elif(ANLG_FAM == 2) 546 // #elif(ANLG_FAM == 2)
547 // SPIABB_wa_VRPC (SPIRead_ABB_Register (PAGE1,VRPCSIM) | MODE_ENA_VCC); 547 // SPIABB_wa_VRPC (SPIRead_ABB_Register (PAGE1,VRPCSIM) | MODE_ENA_VCC);
548 // #endif 548 // #endif
549 // p->c->cmd = (p->c->cmd & MASK_CMD) | SIM_CMD_START; 549 // p->c->cmd = (p->c->cmd & MASK_CMD) | SIM_CMD_START;
550 // 550 //
551 //#endif 551 //#endif
552 552
553 /*-----------------------------------------------------------*/ 553 /*-----------------------------------------------------------*/
554 554
555 while (p->PTS_Try != 5) 555 while (p->PTS_Try != 5)
556 { 556 {
564 SIM_PowerOff (); 564 SIM_PowerOff ();
565 return (SIM_ERR_NOCARD); 565 return (SIM_ERR_NOCARD);
566 } 566 }
567 // ATR received but wrong characters value 567 // ATR received but wrong characters value
568 // Comply with Test 27.11.2.4.5 and Test 27.11.1.3 568 // Comply with Test 27.11.2.4.5 and Test 27.11.1.3
569 else if (BackValue == SIM_ERR_CARDREJECT) 569 else if (BackValue == SIM_ERR_CARDREJECT)
570 { 570 {
571 if (ATR_Attempt >= 3) 571 if (ATR_Attempt >= 3)
572 { 572 {
573 SIM_PowerOff (); 573 SIM_PowerOff ();
574 return ((SYS_UWORD16)BackValue); 574 return ((SYS_UWORD16)BackValue);
575 } 575 }
576 576
577 ATR_Attempt++; 577 ATR_Attempt++;
578 SIM_WARMReset(p); // assert a reset during at least 400 ETU 578 SIM_WARMReset(p); // assert a reset during at least 400 ETU
579 } 579 }
580 else if (BackValue != 0) //SIM_ERR_WAIT 580 else if (BackValue != 0) //SIM_ERR_WAIT
581 { 581 {
582 if (ATR_Attempt == 3) 582 if (ATR_Attempt == 3)
583 { // switch to 5V (ANALOG1) or 3V (ANALOG2) if card send wrong ATR 3 consecutive times 583 { // switch to 5V (ANALOG1) or 3V (ANALOG2) if card send wrong ATR 3 consecutive times
584 // Apply 3 consecutive resets at 5V (ANALOG1) or 3V (ANALOG2) 584 // Apply 3 consecutive resets at 5V (ANALOG1) or 3V (ANALOG2)
585 // fix prb for old chinese card not GSM compliant 585 // fix prb for old chinese card not GSM compliant
586 586
587 if ((BackValue = SIM_SwitchVolt(ResetFlag)) != SIM_OK) 587 if ((BackValue = SIM_SwitchVolt(ResetFlag)) != SIM_OK)
588 { 588 {
589 // SIM cannot be supplied at 3V (ANALOG2), because of an Hardware failure 589 // SIM cannot be supplied at 3V (ANALOG2), because of an Hardware failure
590 SIM_PowerOff (); 590 SIM_PowerOff ();
591 return((SYS_UWORD16)BackValue); 591 return((SYS_UWORD16)BackValue);
592 } 592 }
593 593
594 ATR_Attempt++; 594 ATR_Attempt++;
595 goto COLD_RESET; 595 goto COLD_RESET;
596 } 596 }
597 if (ATR_Attempt >= 6) 597 if (ATR_Attempt >= 6)
598 { 598 {
599 SIM_PowerOff (); 599 SIM_PowerOff ();
600 return ((SYS_UWORD16)BackValue); 600 return ((SYS_UWORD16)BackValue);
601 } 601 }
602 602
603 ATR_Attempt++; 603 ATR_Attempt++;
604 SIM_WARMReset(p); // assert a reset during at least 400 ETU 604 SIM_WARMReset(p); // assert a reset during at least 400 ETU
605 } 605 }
606 606
607 else 607 else
608 { 608 {
609 ATR_Attempt = 0; 609 ATR_Attempt = 0;
610 } 610 }
611 } 611 }
612 /*-----------------------------------------------------------*/ 612 /*-----------------------------------------------------------*/
613 // PTS procedure 613 // PTS procedure
614 BackValue = SIM_PTSprocedure(cP,p); //assert PTS if needed 614 BackValue = SIM_PTSprocedure(cP,p); //assert PTS if needed
615 // need upgrade with FIFO use to avoid CPU overloading 615 // need upgrade with FIFO use to avoid CPU overloading
616 616
617 if (BackValue) 617 if (BackValue)
618 { 618 {
619 if (BackValue == SIM_ERR_CARDREJECT) 619 if (BackValue == SIM_ERR_CARDREJECT)
620 { 620 {
621 SIM_PowerOff (); //must be done by protocol stack 621 SIM_PowerOff (); //must be done by protocol stack
622 return (SIM_ERR_CARDREJECT); 622 return (SIM_ERR_CARDREJECT);
623 } 623 }
624 if (p->PTS_Try <= 4) //else error treatement 624 if (p->PTS_Try <= 4) //else error treatement
625 { 625 {
626 SIM_WARMReset(p); // assert a reset during at least 400 ETU 626 SIM_WARMReset(p); // assert a reset during at least 400 ETU
627 } 627 }
628 } 628 }
629 else 629 else
630 { 630 {
631 p->PTS_Try = 5; 631 p->PTS_Try = 5;
632 } 632 }
651 651
652 if ((p->FileC & SIM_MASK_INFO_VOLT) == SIM_5V) 652 if ((p->FileC & SIM_MASK_INFO_VOLT) == SIM_5V)
653 { 653 {
654 #if ((SIM_TYPE == SIM_TYPE_3V ) || (SIM_TYPE == SIM_TYPE_1_8_3V) || (SIM_TYPE == SIM_TYPE_1_8V)) 654 #if ((SIM_TYPE == SIM_TYPE_3V ) || (SIM_TYPE == SIM_TYPE_1_8_3V) || (SIM_TYPE == SIM_TYPE_1_8V))
655 SIM_PowerOff (); // required by ETSI if 5V only card is detected and 3V only ME chosen 655 SIM_PowerOff (); // required by ETSI if 5V only card is detected and 3V only ME chosen
656 return (SIM_ERR_CARDREJECT); // Test 27.17.1.5.2 656 return (SIM_ERR_CARDREJECT); // Test 27.17.1.5.2
657 #elif (SIM_TYPE == SIM_TYPE_3_5V) 657 #elif (SIM_TYPE == SIM_TYPE_3_5V)
658 if (CurrentVolt == SIM_3V) //if 5V only SIM present -> the ME may switch to 5V operation 658 if (CurrentVolt == SIM_3V) //if 5V only SIM present -> the ME may switch to 5V operation
659 { 659 {
660 if ((BackValue = SIM_SwitchVolt(ResetFlag)) != SIM_OK) // switch to 5V 660 if ((BackValue = SIM_SwitchVolt(ResetFlag)) != SIM_OK) // switch to 5V
661 { 661 {
662 SIM_PowerOff (); 662 SIM_PowerOff ();
663 return ((SYS_UWORD16)BackValue); 663 return ((SYS_UWORD16)BackValue);
664 } 664 }
665 ATR_Attempt = 1; 665 ATR_Attempt = 1;
666 goto COLD_RESET; // Test 27.17.1.5.3 666 goto COLD_RESET; // Test 27.17.1.5.3
667 } 667 }
668 #endif 668 #endif
669 } 669 }
670 else 670 else
671 { 671 {
672 if ((p->FileC & SIM_MASK_INFO_VOLT) == SIM_3V) 672 if ((p->FileC & SIM_MASK_INFO_VOLT) == SIM_3V)
673 { 673 {
674 #if (SIM_TYPE == SIM_TYPE_1_8V) 674 #if (SIM_TYPE == SIM_TYPE_1_8V)
675 SIM_PowerOff (); // required by ETSI if 3V only card is detected and 1.8V only ME chosen 675 SIM_PowerOff (); // required by ETSI if 3V only card is detected and 1.8V only ME chosen
676 return (SIM_ERR_CARDREJECT); // Test 27.17.1.5.2 676 return (SIM_ERR_CARDREJECT); // Test 27.17.1.5.2
677 #elif (SIM_TYPE == SIM_TYPE_1_8_3V) 677 #elif (SIM_TYPE == SIM_TYPE_1_8_3V)
678 if (CurrentVolt == SIM_1_8V) //if 3V only SIM present -> the ME may switch to 3V operation 678 if (CurrentVolt == SIM_1_8V) //if 3V only SIM present -> the ME may switch to 3V operation
679 { 679 {
680 if ((BackValue = SIM_SwitchVolt(ResetFlag)) != SIM_OK) // switch to 3V 680 if ((BackValue = SIM_SwitchVolt(ResetFlag)) != SIM_OK) // switch to 3V
681 { 681 {
682 SIM_PowerOff (); 682 SIM_PowerOff ();
683 return ((SYS_UWORD16)BackValue); 683 return ((SYS_UWORD16)BackValue);
684 } 684 }
685 ATR_Attempt = 1; 685 ATR_Attempt = 1;
686 goto COLD_RESET; // Test 27.17.1.5.3 686 goto COLD_RESET; // Test 27.17.1.5.3
687 } 687 }
688 #endif 688 #endif
689 } 689 }
690 else 690 else
691 { 691 {
692 if ((p->FileC & SIM_MASK_INFO_VOLT) == SIM_1_8V) 692 if ((p->FileC & SIM_MASK_INFO_VOLT) == SIM_1_8V)
693 { 693 {
694 #if (SIM_TYPE == SIM_TYPE_5V) 694 #if (SIM_TYPE == SIM_TYPE_5V)
695 SIM_PowerOff (); // required by ETSI if 5V only card is detected and 3V only ME chosen 695 SIM_PowerOff (); // required by ETSI if 5V only card is detected and 3V only ME chosen
696 return (SIM_ERR_CARDREJECT); // Test 27.17.1.5.2 696 return (SIM_ERR_CARDREJECT); // Test 27.17.1.5.2
697 #endif 697 #endif
698 } 698 }
699 else 699 else
700 { 700 {
701 // future class of sim card voltage !!!!!! never use it 701 // future class of sim card voltage !!!!!! never use it
702 SIM_PowerOff (); // Rec. 11.18 702 SIM_PowerOff (); // Rec. 11.18
703 return (SIM_ERR_CARDREJECT); 703 return (SIM_ERR_CARDREJECT);
704 } 704 }
705 } 705 }
706 } 706 }
707 707
708 SIM_Interpret_FileCharacteristics(p); //find which frequency (13/4 or 13/8 Mhz) 708 SIM_Interpret_FileCharacteristics(p); //find which frequency (13/4 or 13/8 Mhz)
709 709
710 if(p->errorSIM) 710 if(p->errorSIM)
711 { 711 {
712 return(p->errorSIM); 712 return(p->errorSIM);
713 } 713 }
714 714
715 status_os_sim = NU_Control_Timer (&SIM_timer, NU_ENABLE_TIMER); 715 status_os_sim = NU_Control_Timer (&SIM_timer, NU_ENABLE_TIMER);
716 //enable starting of the os timer for sleep mode 716 //enable starting of the os timer for sleep mode
717 if (ResetFlag) { 717 if (ResetFlag) {
718 if (p->InsertFunc != NULL) 718 if (p->InsertFunc != NULL)
719 (p->InsertFunc)(cP); 719 (p->InsertFunc)(cP);
720 } 720 }
721 721
722 return(0); 722 return(0);
723 } 723 }
724 724
744 volatile int i; 744 volatile int i;
745 745
746 //!! 746 //!!
747 p->c->conf1 = p->conf1 = 0x8004; //set conf1 to automatic mode SIO low 747 p->c->conf1 = p->conf1 = 0x8004; //set conf1 to automatic mode SIO low
748 //enable sim interface clock module 748 //enable sim interface clock module
749 p->c->cmd = SIM_CMD_CLKEN; 749 p->c->cmd = SIM_CMD_CLKEN;
750 750
751 //#if (SW_WRK_AROUND_H_S == 1) 751 //#if (SW_WRK_AROUND_H_S == 1)
752 752
753 // Mask all interrupts 753 // Mask all interrupts
754 p->c->maskit = SIM_MASK_NATR | SIM_MASK_WT | SIM_MASK_OV | 754 p->c->maskit = SIM_MASK_NATR | SIM_MASK_WT | SIM_MASK_OV |
755 SIM_MASK_TX | SIM_MASK_RX | SIM_MASK_CD; 755 SIM_MASK_TX | SIM_MASK_RX | SIM_MASK_CD;
756 756
757 // Unmask interrupt controller 757 // Unmask interrupt controller
758 IQ_Unmask (IQ_SIM); 758 IQ_Unmask (IQ_SIM);
759 759
760 p->c->cmd = (p->c->cmd & MASK_CMD) | SIM_CMD_STOP; 760 p->c->cmd = (p->c->cmd & MASK_CMD) | SIM_CMD_STOP;
761 ind_os_sleep (4); //wait 5 TDMA due to SVCC falling down duration 761 ind_os_sleep (4); //wait 5 TDMA due to SVCC falling down duration
762 762
763 p->c->cmd = (p->c->cmd & MASK_CMD) | SIM_CMD_SWRST; 763 p->c->cmd = (p->c->cmd & MASK_CMD) | SIM_CMD_SWRST;
764 ind_os_sleep (1); //wait 5 TDMA due to SVCC falling down duration 764 ind_os_sleep (1); //wait 5 TDMA due to SVCC falling down duration
765 765
766 766
767 p->c->conf2 = 0x0940; 767 p->c->conf2 = 0x0940;
768 768
769 i = p->c->it; 769 i = p->c->it;
770 // Unmask all sources of interrupts except WT and OV and NATR 770 // Unmask all sources of interrupts except WT and OV and NATR
771 p->c->maskit = SIM_MASK_WT | SIM_MASK_OV | SIM_MASK_NATR; 771 p->c->maskit = SIM_MASK_WT | SIM_MASK_OV | SIM_MASK_NATR;
772 772
773 773
776 ind_os_sleep(1); 776 ind_os_sleep(1);
777 777
778 p->c->conf1 = p->conf1 |= SIM_CONF1_SVCCLEV; 778 p->c->conf1 = p->conf1 |= SIM_CONF1_SVCCLEV;
779 ind_os_sleep(1); 779 ind_os_sleep(1);
780 780
781 #if(ANLG_FAM == 1) 781 #if(ANLG_FAM == 1)
782 //set OMEGA to 3V mode 782 //set OMEGA to 3V mode
783 //enable VCC 783 //enable VCC
784 ABB_wa_VRPC (ABB_Read_Register_on_page(PAGE1,VRPCCTRL1) | MODE_ENA_SIMLDOEN); 784 ABB_wa_VRPC (ABB_Read_Register_on_page(PAGE1,VRPCCTRL1) | MODE_ENA_SIMLDOEN);
785 ind_os_sleep(1); 785 ind_os_sleep(1);
786 ABB_wa_VRPC (ABB_Read_Register_on_page(PAGE1,VRPCCTRL1) | MODE_ENA_SIMEN); 786 ABB_wa_VRPC (ABB_Read_Register_on_page(PAGE1,VRPCCTRL1) | MODE_ENA_SIMEN);
787 ind_os_sleep(1); 787 ind_os_sleep(1);
788 #elif(ANLG_FAM == 2) 788 #elif(ANLG_FAM == 2)
789 //set IOTA to 3V mode 789 //set IOTA to 3V mode
790 //enable VCC 790 //enable VCC
791 ABB_wa_VRPC (ABB_Read_Register_on_page(PAGE1,VRPCSIM) | MODE_ENA_SIMEN); 791 ABB_wa_VRPC (ABB_Read_Register_on_page(PAGE1,VRPCSIM) | MODE_ENA_SIMEN);
792 ind_os_sleep(1); 792 ind_os_sleep(1);
793 #elif(ANLG_FAM == 3) 793 #elif(ANLG_FAM == 3)
814 i = 0; 814 i = 0;
815 while ((p->rx_index == 0) && (i < 3)) //wait 40000*Tsclk 815 while ((p->rx_index == 0) && (i < 3)) //wait 40000*Tsclk
816 { 816 {
817 ind_os_sleep (1); 817 ind_os_sleep (1);
818 i++; 818 i++;
819 } 819 }
820 820
821 if ((p->rx_index == 0) && (i >= 3)) //external reset card ATR treatement 821 if ((p->rx_index == 0) && (i >= 3)) //external reset card ATR treatement
822 { 822 {
823 i = 0; 823 i = 0;
824 824
825 p->c->conf1 = p->conf1 |= SIM_CONF1_SRSTLEV;//set reset level to high level 825 p->c->conf1 = p->conf1 |= SIM_CONF1_SRSTLEV;//set reset level to high level
831 } 831 }
832 } 832 }
833 833
834 return (0); 834 return (0);
835 } 835 }
836 836
837 /* SIM manual stop 837 /* SIM manual stop
838 * 838 *
839 * purpose : manage manual start of the SIM interface 839 * purpose : manage manual start of the SIM interface
840 * input : pointer on sim structure SIM_PORT 840 * input : pointer on sim structure SIM_PORT
841 * output : none 841 * output : none
844 void SIM_ManualStop (SIM_PORT *p) 844 void SIM_ManualStop (SIM_PORT *p)
845 { 845 {
846 // to write 846 // to write
847 } 847 }
848 848
849 /* Power off SIM == SIM_CMD_STOP 849 /* Power off SIM == SIM_CMD_STOP
850 * input : none 850 * input : none
851 * output : none 851 * output : none
852 */ 852 */
853 853
854 void SIM_PowerOff(void) 854 void SIM_PowerOff(void)
856 SIM_PORT *p; 856 SIM_PORT *p;
857 volatile SYS_UWORD16 cmd; 857 volatile SYS_UWORD16 cmd;
858 858
859 859
860 860
861 // Initialize pointers 861 // Initialize pointers
862 p = &(Sim[0]); 862 p = &(Sim[0]);
863 863
864 864
865 // Reset and wait a while 865 // Reset and wait a while
866 cmd = p->c->cmd; 866 cmd = p->c->cmd;
867 p->c->cmd = (cmd & MASK_CMD) | SIM_CMD_STOP; 867 p->c->cmd = (cmd & MASK_CMD) | SIM_CMD_STOP;
868 868
869 ind_os_sleep(5); //wait for falling of SIM signals (RESET/CLK/IO) 869 ind_os_sleep(5); //wait for falling of SIM signals (RESET/CLK/IO)
870 870
871 #if(ANLG_FAM == 1) 871 #if(ANLG_FAM == 1)
872 //disable VCC : disable level shifter then SVDD 872 //disable VCC : disable level shifter then SVDD
873 ABB_wa_VRPC (ABB_Read_Register_on_page(PAGE1,VRPCCTRL1) & MODE_DIS_SIMEN); 873 ABB_wa_VRPC (ABB_Read_Register_on_page(PAGE1,VRPCCTRL1) & MODE_DIS_SIMEN);
874 ABB_wa_VRPC (ABB_Read_Register_on_page(PAGE1,VRPCCTRL1) & MODE_DIS_SIMLDOEN); 874 ABB_wa_VRPC (ABB_Read_Register_on_page(PAGE1,VRPCCTRL1) & MODE_DIS_SIMLDOEN);
875 #elif(ANLG_FAM == 2) 875 #elif(ANLG_FAM == 2)
876 //disable VCC : disable level shifter then SVDD 876 //disable VCC : disable level shifter then SVDD
877 ABB_wa_VRPC (ABB_Read_Register_on_page(PAGE1,VRPCSIM) & MODE_DIS_SIMEN); 877 ABB_wa_VRPC (ABB_Read_Register_on_page(PAGE1,VRPCSIM) & MODE_DIS_SIMEN);
878 ABB_wa_VRPC (ABB_Read_Register_on_page(PAGE1,VRPCSIM) & MODE_DIS_SIMLDOEN); 878 ABB_wa_VRPC (ABB_Read_Register_on_page(PAGE1,VRPCSIM) & MODE_DIS_SIMLDOEN);
879 #elif(ANLG_FAM == 3) 879 #elif(ANLG_FAM == 3)
880 //disable VCC : disable level shifter then SVDD 880 //disable VCC : disable level shifter then SVDD
920 volatile SYS_UWORD32 dum; 920 volatile SYS_UWORD32 dum;
921 921
922 /* FreeCalypso addition */ 922 /* FreeCalypso addition */
923 ffs_file_read("/etc/SIM_spenh", &SIM_allow_speed_enhancement, 1); 923 ffs_file_read("/etc/SIM_spenh", &SIM_allow_speed_enhancement, 1);
924 924
925 // Initialize registers 925 // Initialize registers
926 p = &(Sim[0]); 926 p = &(Sim[0]);
927 p->c = (SIM_CONTROLLER *) SIM_CMD; 927 p->c = (SIM_CONTROLLER *) SIM_CMD;
928 928
929 p->errorSIM = 0; 929 p->errorSIM = 0;
930 dum = (volatile SYS_UWORD32) SIM_Dummy; // to force linking SIM32 930 dum = (volatile SYS_UWORD32) SIM_Dummy; // to force linking SIM32
932 status_os_sim = NU_Create_Timer (&SIM_timer, "SIM_sleep_timer", &SIM_SleepMode_In, 932 status_os_sim = NU_Create_Timer (&SIM_timer, "SIM_sleep_timer", &SIM_SleepMode_In,
933 0, SIM_SLEEP_WAITING_TIME, 0, NU_DISABLE_TIMER); 933 0, SIM_SLEEP_WAITING_TIME, 0, NU_DISABLE_TIMER);
934 //timer start only with NU_Control_Timer function 934 //timer start only with NU_Control_Timer function
935 //waiting time set to 2.3s 935 //waiting time set to 2.3s
936 SIM_sleep_status = SIM_SLEEP_NONE; 936 SIM_sleep_status = SIM_SLEEP_NONE;
937 937
938 #ifdef SIM_RETRY 938 #ifdef SIM_RETRY
939 SimRetries = 0; 939 SimRetries = 0;
940 #endif 940 #endif
941 } 941 }
942 942
952 952
953 SYS_UWORD16 SIM_Register(void (Insert(SIM_CARD *cP)), void (Remove(void))) 953 SYS_UWORD16 SIM_Register(void (Insert(SIM_CARD *cP)), void (Remove(void)))
954 { 954 {
955 SIM_PORT *p; 955 SIM_PORT *p;
956 956
957 // Initialize pointers 957 // Initialize pointers
958 p = &(Sim[0]); 958 p = &(Sim[0]);
959 959
960 p->InsertFunc = Insert; 960 p->InsertFunc = Insert;
961 p->RemoveFunc = Remove; 961 p->RemoveFunc = Remove;
962 962
966 966
967 /* 967 /*
968 * High level routines : mapped to GSM 11.11 function calls 968 * High level routines : mapped to GSM 11.11 function calls
969 * 969 *
970 * Uses a Nucleus semaphore to ensure no simultaneous access to SIM and buffer 970 * Uses a Nucleus semaphore to ensure no simultaneous access to SIM and buffer
971 * 971 *
972 * Each routine does : 972 * Each routine does :
973 * write command 973 * write command
974 * sleep long enough for the expected transmission and reception 974 * sleep long enough for the expected transmission and reception
975 * return rest code 975 * return rest code
976 * 976 *
977 * SYS_UWORD8 *result : pointer to the string return by the SIM card 977 * SYS_UWORD8 *result : pointer to the string return by the SIM card
978 * SYS_UWORD8 *rcvSize : size of the string return by the SIM card 978 * SYS_UWORD8 *rcvSize : size of the string return by the SIM card
979 * 979 *
980 * other parameters : parameters needed by the SIM card to 980 * other parameters : parameters needed by the SIM card to
981 * execute the function. 981 * execute the function.
982 * 982 *
983 */ 983 */
984 //unsigned char SIM_flag = 0; 984 //unsigned char SIM_flag = 0;
985 985
986 986
987 /* 987 /*
991 */ 991 */
992 SYS_UWORD16 SIM_Select(SYS_UWORD16 id, SYS_UWORD8 *dat, SYS_UWORD16 *rcvSize) 992 SYS_UWORD16 SIM_Select(SYS_UWORD16 id, SYS_UWORD8 *dat, SYS_UWORD16 *rcvSize)
993 { 993 {
994 SIM_PORT *p; 994 SIM_PORT *p;
995 int res; 995 int res;
996 996
997 p = &(Sim[0]); 997 p = &(Sim[0]);
998 998
999 p->xbuf[0] = GSM_CLASS; 999 p->xbuf[0] = GSM_CLASS;
1000 p->xbuf[1] = SIM_SELECT; 1000 p->xbuf[1] = SIM_SELECT;
1001 p->xbuf[2] = 0; 1001 p->xbuf[2] = 0;
1002 p->xbuf[3] = 0; 1002 p->xbuf[3] = 0;
1003 p->xbuf[4] = 2; 1003 p->xbuf[4] = 2;
1004 p->xbuf[5] = id >> 8; // high byte 1004 p->xbuf[5] = id >> 8; // high byte
1005 p->xbuf[6] = id & 0xFF; // low byte 1005 p->xbuf[6] = id & 0xFF; // low byte
1006 1006
1007 1007
1008 res = SIM_Command(p, 2, dat, rcvSize); 1008 res = SIM_Command(p, 2, dat, rcvSize);
1009 /* Change from to 10 to 15 for specific SIM card (Racal) */ 1009 /* Change from to 10 to 15 for specific SIM card (Racal) */
1010 1010
1011 // if (id == 0x6F07) 1011 // if (id == 0x6F07)
1012 // SIM_flag = 1; 1012 // SIM_flag = 1;
1013 1013
1030 } 1030 }
1031 1031
1032 1032
1033 /* 1033 /*
1034 * SIM_Status 1034 * SIM_Status
1035 * 1035 *
1036 * Returns data received from card and number of bytes received 1036 * Returns data received from card and number of bytes received
1037 */ 1037 */
1038 SYS_UWORD16 SIM_Status(SYS_UWORD8 *dat, SYS_UWORD16 *rcvSize) 1038 SYS_UWORD16 SIM_Status(SYS_UWORD8 *dat, SYS_UWORD16 *rcvSize)
1039 { 1039 {
1040 SIM_PORT *p; 1040 SIM_PORT *p;
1046 1046
1047 p->xbuf[0] = GSM_CLASS; 1047 p->xbuf[0] = GSM_CLASS;
1048 p->xbuf[1] = SIM_STATUS; 1048 p->xbuf[1] = SIM_STATUS;
1049 p->xbuf[2] = 0; 1049 p->xbuf[2] = 0;
1050 p->xbuf[3] = 0; 1050 p->xbuf[3] = 0;
1051 p->xbuf[4] = len; 1051 p->xbuf[4] = len;
1052 1052
1053 res = SIM_Command(p, 0, dat, rcvSize); 1053 res = SIM_Command(p, 0, dat, rcvSize);
1054 1054
1055 #ifdef SIM_DEBUG_TRACE 1055 #ifdef SIM_DEBUG_TRACE
1056 SIM_dbg_write_trace((SYS_UWORD8 *)"ABCMD", 5); 1056 SIM_dbg_write_trace((SYS_UWORD8 *)"ABCMD", 5);
1070 return(res); 1070 return(res);
1071 } 1071 }
1072 1072
1073 /* 1073 /*
1074 * SIM_Status_Extended 1074 * SIM_Status_Extended
1075 * 1075 *
1076 * Returns data received from card and number of bytes received 1076 * Returns data received from card and number of bytes received
1077 * Add extra parameter len : number of returned byte 1077 * Add extra parameter len : number of returned byte
1078 */ 1078 */
1079 SYS_UWORD16 SIM_Status_Extended(SYS_UWORD8 *dat, SYS_UWORD16 len, SYS_UWORD16 *rcvSize) 1079 SYS_UWORD16 SIM_Status_Extended(SYS_UWORD8 *dat, SYS_UWORD16 len, SYS_UWORD16 *rcvSize)
1080 { 1080 {
1086 1086
1087 p->xbuf[0] = GSM_CLASS; 1087 p->xbuf[0] = GSM_CLASS;
1088 p->xbuf[1] = SIM_STATUS; 1088 p->xbuf[1] = SIM_STATUS;
1089 p->xbuf[2] = 0; 1089 p->xbuf[2] = 0;
1090 p->xbuf[3] = 0; 1090 p->xbuf[3] = 0;
1091 p->xbuf[4] = (SYS_UWORD8)llen; 1091 p->xbuf[4] = (SYS_UWORD8)llen;
1092 1092
1093 res = SIM_Command(p, 0, dat, rcvSize); 1093 res = SIM_Command(p, 0, dat, rcvSize);
1094 1094
1095 #ifdef SIM_DEBUG_TRACE 1095 #ifdef SIM_DEBUG_TRACE
1096 SIM_dbg_write_trace((SYS_UWORD8 *)"ACCMD", 5); 1096 SIM_dbg_write_trace((SYS_UWORD8 *)"ACCMD", 5);
1124 1124
1125 p = &(Sim[0]); 1125 p = &(Sim[0]);
1126 1126
1127 p->xbuf[0] = GSM_CLASS; 1127 p->xbuf[0] = GSM_CLASS;
1128 p->xbuf[1] = SIM_READ_BINARY; 1128 p->xbuf[1] = SIM_READ_BINARY;
1129 p->xbuf[2] = offset >> 8; 1129 p->xbuf[2] = offset >> 8;
1130 p->xbuf[3] = offset & 0xFF; 1130 p->xbuf[3] = offset & 0xFF;
1131 p->xbuf[4] = (SYS_UWORD8)llen; 1131 p->xbuf[4] = (SYS_UWORD8)llen;
1132 1132
1133 res = SIM_Command(p, 0, dat, rcvSize); 1133 res = SIM_Command(p, 0, dat, rcvSize);
1134 1134
1135 // if (SIM_flag) { 1135 // if (SIM_flag) {
1136 // SIM_flag = 0; 1136 // SIM_flag = 0;
1137 // dat[0] = 0x08; 1137 // dat[0] = 0x08;
1138 // } 1138 // }
1139 1139
1140 #ifdef SIM_DEBUG_TRACE 1140 #ifdef SIM_DEBUG_TRACE
1141 SIM_dbg_write_trace((SYS_UWORD8 *)"ADCMD", 5); 1141 SIM_dbg_write_trace((SYS_UWORD8 *)"ADCMD", 5);
1142 SIM_dbg_write_trace(p->xbuf, 5); 1142 SIM_dbg_write_trace(p->xbuf, 5);
1143 SIM_dbg_write_trace((SYS_UWORD8 *)"ADANS", 5); 1143 SIM_dbg_write_trace((SYS_UWORD8 *)"ADANS", 5);
1144 SIM_dbg_tmp[0] = (SYS_UWORD8)(*rcvSize>>8); 1144 SIM_dbg_tmp[0] = (SYS_UWORD8)(*rcvSize>>8);
1176 p = &(Sim[0]); 1176 p = &(Sim[0]);
1177 len = 8; 1177 len = 8;
1178 1178
1179 p->xbuf[0] = GSM_CLASS; 1179 p->xbuf[0] = GSM_CLASS;
1180 p->xbuf[1] = SIM_VERIFY_CHV; 1180 p->xbuf[1] = SIM_VERIFY_CHV;
1181 p->xbuf[2] = 0; 1181 p->xbuf[2] = 0;
1182 p->xbuf[3] = chvType; 1182 p->xbuf[3] = chvType;
1183 p->xbuf[4] = len; 1183 p->xbuf[4] = len;
1184 for (i=0;i<8;i++) 1184 for (i=0;i<8;i++)
1185 { 1185 {
1186 p->xbuf[5+i] = *(dat+i); 1186 p->xbuf[5+i] = *(dat+i);
1187 } 1187 }
1188 res = SIM_Command(p, 8, result, rcvSize); 1188 res = SIM_Command(p, 8, result, rcvSize);
1229 1229
1230 len = 16; 1230 len = 16;
1231 1231
1232 p->xbuf[0] = GSM_CLASS; 1232 p->xbuf[0] = GSM_CLASS;
1233 p->xbuf[1] = SIM_RUN_GSM_ALGO; 1233 p->xbuf[1] = SIM_RUN_GSM_ALGO;
1234 p->xbuf[2] = 0; 1234 p->xbuf[2] = 0;
1235 p->xbuf[3] = 0; 1235 p->xbuf[3] = 0;
1236 p->xbuf[4] = len; 1236 p->xbuf[4] = len;
1237 1237
1238 for (i=0;i<len;i++) 1238 for (i=0;i<len;i++)
1239 { 1239 {
1240 p->xbuf[5+i] = *(dat+i); 1240 p->xbuf[5+i] = *(dat+i);
1241 } 1241 }
1283 1283
1284 p = &(Sim[0]); 1284 p = &(Sim[0]);
1285 1285
1286 p->xbuf[0] = GSM_CLASS; 1286 p->xbuf[0] = GSM_CLASS;
1287 p->xbuf[1] = SIM_GET_RESPONSE; 1287 p->xbuf[1] = SIM_GET_RESPONSE;
1288 p->xbuf[2] = 0; 1288 p->xbuf[2] = 0;
1289 p->xbuf[3] = 0; 1289 p->xbuf[3] = 0;
1290 p->xbuf[4] = (SYS_UWORD8)llen; 1290 p->xbuf[4] = (SYS_UWORD8)llen;
1291 1291
1292 res = SIM_Command(p, 0, dat, rcvSize); 1292 res = SIM_Command(p, 0, dat, rcvSize);
1293 1293
1294 #ifdef SIM_DEBUG_TRACE 1294 #ifdef SIM_DEBUG_TRACE
1295 SIM_dbg_write_trace((SYS_UWORD8 *)"AGCMD", 5); 1295 SIM_dbg_write_trace((SYS_UWORD8 *)"AGCMD", 5);
1329 p = &(Sim[0]); 1329 p = &(Sim[0]);
1330 len = 16; 1330 len = 16;
1331 1331
1332 p->xbuf[0] = GSM_CLASS; 1332 p->xbuf[0] = GSM_CLASS;
1333 p->xbuf[1] = SIM_CHANGE_CHV; 1333 p->xbuf[1] = SIM_CHANGE_CHV;
1334 p->xbuf[2] = 0; 1334 p->xbuf[2] = 0;
1335 p->xbuf[3] = chvType; 1335 p->xbuf[3] = chvType;
1336 p->xbuf[4] = (SYS_UWORD8)len; 1336 p->xbuf[4] = (SYS_UWORD8)len;
1337 1337
1338 // Copy bytes to buffer 1338 // Copy bytes to buffer
1339 for (i=0;i<8;i++) 1339 for (i=0;i<8;i++)
1340 { 1340 {
1341 p->xbuf[5+i] = *(oldChv+i); 1341 p->xbuf[5+i] = *(oldChv+i);
1384 p = &(Sim[0]); 1384 p = &(Sim[0]);
1385 1385
1386 len = 8; 1386 len = 8;
1387 p->xbuf[0] = GSM_CLASS; 1387 p->xbuf[0] = GSM_CLASS;
1388 p->xbuf[1] = SIM_DISABLE_CHV; 1388 p->xbuf[1] = SIM_DISABLE_CHV;
1389 p->xbuf[2] = 0; 1389 p->xbuf[2] = 0;
1390 p->xbuf[3] = 1; 1390 p->xbuf[3] = 1;
1391 p->xbuf[4] = 8; 1391 p->xbuf[4] = 8;
1392 for (i=0;i<8;i++) 1392 for (i=0;i<8;i++)
1393 { 1393 {
1394 p->xbuf[5+i] = *(dat+i); 1394 p->xbuf[5+i] = *(dat+i);
1395 } 1395 }
1396 res = SIM_Command(p, len, result, lP); 1396 res = SIM_Command(p, len, result, lP);
1397 1397
1398 #ifdef SIM_DEBUG_TRACE 1398 #ifdef SIM_DEBUG_TRACE
1399 SIM_dbg_write_trace((SYS_UWORD8 *)"AICMD", 5); 1399 SIM_dbg_write_trace((SYS_UWORD8 *)"AICMD", 5);
1400 SIM_dbg_write_trace(p->xbuf, 8+5); 1400 SIM_dbg_write_trace(p->xbuf, 8+5);
1401 SIM_dbg_write_trace((SYS_UWORD8 *)"AIANS", 5); 1401 SIM_dbg_write_trace((SYS_UWORD8 *)"AIANS", 5);
1435 1435
1436 len = 8; 1436 len = 8;
1437 1437
1438 p->xbuf[0] = GSM_CLASS; 1438 p->xbuf[0] = GSM_CLASS;
1439 p->xbuf[1] = SIM_ENABLE_CHV; 1439 p->xbuf[1] = SIM_ENABLE_CHV;
1440 p->xbuf[2] = 0; 1440 p->xbuf[2] = 0;
1441 p->xbuf[3] = 1; 1441 p->xbuf[3] = 1;
1442 p->xbuf[4] = (SYS_UWORD8)len; 1442 p->xbuf[4] = (SYS_UWORD8)len;
1443 1443
1444 for (i=0;i<len;i++) 1444 for (i=0;i<len;i++)
1445 { 1445 {
1446 p->xbuf[5+i] = *(dat+i); 1446 p->xbuf[5+i] = *(dat+i);
1447 } 1447 }
1476 * SIM_UnblockCHV 1476 * SIM_UnblockCHV
1477 * 1477 *
1478 * Unblock the specified CHV (chvType) and store a new CHV 1478 * Unblock the specified CHV (chvType) and store a new CHV
1479 */ 1479 */
1480 SYS_UWORD16 SIM_UnblockCHV(SYS_UWORD8 *result, SYS_UWORD8 *unblockChv, SYS_UWORD8 *newChv, 1480 SYS_UWORD16 SIM_UnblockCHV(SYS_UWORD8 *result, SYS_UWORD8 *unblockChv, SYS_UWORD8 *newChv,
1481 SYS_UWORD8 chvType, SYS_UWORD16 *lP) 1481 SYS_UWORD8 chvType, SYS_UWORD16 *lP)
1482 { 1482 {
1483 SIM_PORT *p; 1483 SIM_PORT *p;
1484 int len; 1484 int len;
1485 int i; 1485 int i;
1486 int res; 1486 int res;
1490 1490
1491 p->xbuf[0] = GSM_CLASS; 1491 p->xbuf[0] = GSM_CLASS;
1492 p->xbuf[1] = SIM_UNBLOCK_CHV; 1492 p->xbuf[1] = SIM_UNBLOCK_CHV;
1493 p->xbuf[2] = 0; 1493 p->xbuf[2] = 0;
1494 p->xbuf[3] = chvType; 1494 p->xbuf[3] = chvType;
1495 p->xbuf[4] = (SYS_UWORD8)len; 1495 p->xbuf[4] = (SYS_UWORD8)len;
1496 for (i=0;i<8;i++) 1496 for (i=0;i<8;i++)
1497 { 1497 {
1498 p->xbuf[5+i] = *(unblockChv+i); 1498 p->xbuf[5+i] = *(unblockChv+i);
1499 } 1499 }
1500 for (i=0;i<8;i++) 1500 for (i=0;i<8;i++)
1538 1538
1539 p = &(Sim[0]); 1539 p = &(Sim[0]);
1540 1540
1541 p->xbuf[0] = GSM_CLASS; 1541 p->xbuf[0] = GSM_CLASS;
1542 p->xbuf[1] = SIM_INVALIDATE; 1542 p->xbuf[1] = SIM_INVALIDATE;
1543 p->xbuf[2] = 0; 1543 p->xbuf[2] = 0;
1544 p->xbuf[3] = 0; 1544 p->xbuf[3] = 0;
1545 p->xbuf[4] = 0; 1545 p->xbuf[4] = 0;
1546 1546
1547 res = SIM_Command(p, 0, rP, lP); 1547 res = SIM_Command(p, 0, rP, lP);
1548 1548
1549 #ifdef SIM_DEBUG_TRACE 1549 #ifdef SIM_DEBUG_TRACE
1550 SIM_dbg_write_trace((SYS_UWORD8 *)"ALCMD", 5); 1550 SIM_dbg_write_trace((SYS_UWORD8 *)"ALCMD", 5);
1580 1580
1581 p = &(Sim[0]); 1581 p = &(Sim[0]);
1582 1582
1583 p->xbuf[0] = GSM_CLASS; 1583 p->xbuf[0] = GSM_CLASS;
1584 p->xbuf[1] = SIM_REHABILITATE; 1584 p->xbuf[1] = SIM_REHABILITATE;
1585 p->xbuf[2] = 0; 1585 p->xbuf[2] = 0;
1586 p->xbuf[3] = 0; 1586 p->xbuf[3] = 0;
1587 p->xbuf[4] = 0; 1587 p->xbuf[4] = 0;
1588 1588
1589 res = SIM_Command(p, 0, rP, lP); 1589 res = SIM_Command(p, 0, rP, lP);
1590 1590
1591 #ifdef SIM_DEBUG_TRACE 1591 #ifdef SIM_DEBUG_TRACE
1592 SIM_dbg_write_trace((SYS_UWORD8 *)"AMCMD", 5); 1592 SIM_dbg_write_trace((SYS_UWORD8 *)"AMCMD", 5);
1593 SIM_dbg_write_trace(p->xbuf, 5); 1593 SIM_dbg_write_trace(p->xbuf, 5);
1594 SIM_dbg_write_trace((SYS_UWORD8 *)"AMANS", 5); 1594 SIM_dbg_write_trace((SYS_UWORD8 *)"AMANS", 5);
1626 1626
1627 p = &(Sim[0]); 1627 p = &(Sim[0]);
1628 1628
1629 p->xbuf[0] = GSM_CLASS; 1629 p->xbuf[0] = GSM_CLASS;
1630 p->xbuf[1] = SIM_UPDATE_BINARY; 1630 p->xbuf[1] = SIM_UPDATE_BINARY;
1631 p->xbuf[2] = offset >> 8; 1631 p->xbuf[2] = offset >> 8;
1632 p->xbuf[3] = offset & 0xFF; 1632 p->xbuf[3] = offset & 0xFF;
1633 p->xbuf[4] = (SYS_UWORD8)llen; 1633 p->xbuf[4] = (SYS_UWORD8)llen;
1634 1634
1635 for (i=0;i<llen;i++) 1635 for (i=0;i<llen;i++)
1636 { 1636 {
1637 p->xbuf[5+i] = *(dat+i); 1637 p->xbuf[5+i] = *(dat+i);
1638 } 1638 }
1639 res = SIM_Command(p, llen, result, rcvSize); 1639 res = SIM_Command(p, llen, result, rcvSize);
1640 1640
1641 #ifdef SIM_DEBUG_TRACE 1641 #ifdef SIM_DEBUG_TRACE
1642 SIM_dbg_write_trace((SYS_UWORD8 *)"ANCMD", 5); 1642 SIM_dbg_write_trace((SYS_UWORD8 *)"ANCMD", 5);
1643 SIM_dbg_write_trace(p->xbuf, llen+5); 1643 SIM_dbg_write_trace(p->xbuf, llen+5);
1644 SIM_dbg_write_trace((SYS_UWORD8 *)"ANANS", 5); 1644 SIM_dbg_write_trace((SYS_UWORD8 *)"ANANS", 5);
1675 1675
1676 p = &(Sim[0]); 1676 p = &(Sim[0]);
1677 1677
1678 p->xbuf[0] = GSM_CLASS; 1678 p->xbuf[0] = GSM_CLASS;
1679 p->xbuf[1] = SIM_READ_RECORD; 1679 p->xbuf[1] = SIM_READ_RECORD;
1680 p->xbuf[2] = recNum; 1680 p->xbuf[2] = recNum;
1681 p->xbuf[3] = mode; 1681 p->xbuf[3] = mode;
1682 p->xbuf[4] = (SYS_UWORD8)llen; 1682 p->xbuf[4] = (SYS_UWORD8)llen;
1683 1683
1684 res = SIM_Command(p, 0, dat, rcvSize); 1684 res = SIM_Command(p, 0, dat, rcvSize);
1685 1685
1686 #ifdef SIM_DEBUG_TRACE 1686 #ifdef SIM_DEBUG_TRACE
1687 SIM_dbg_write_trace((SYS_UWORD8 *)"AOCMD", 5); 1687 SIM_dbg_write_trace((SYS_UWORD8 *)"AOCMD", 5);
1688 SIM_dbg_write_trace(p->xbuf, llen+5); 1688 SIM_dbg_write_trace(p->xbuf, llen+5);
1689 SIM_dbg_write_trace((SYS_UWORD8 *)"AOANS", 5); 1689 SIM_dbg_write_trace((SYS_UWORD8 *)"AOANS", 5);
1840 1840
1841 p = &(Sim[0]); 1841 p = &(Sim[0]);
1842 1842
1843 p->xbuf[0] = GSM_CLASS; 1843 p->xbuf[0] = GSM_CLASS;
1844 p->xbuf[1] = SIM_UPDATE_RECORD; 1844 p->xbuf[1] = SIM_UPDATE_RECORD;
1845 p->xbuf[2] = recNum; 1845 p->xbuf[2] = recNum;
1846 p->xbuf[3] = mode; 1846 p->xbuf[3] = mode;
1847 p->xbuf[4] = (SYS_UWORD8)llen; 1847 p->xbuf[4] = (SYS_UWORD8)llen;
1848 1848
1849 for (i=0;i<llen;i++) 1849 for (i=0;i<llen;i++)
1850 { 1850 {
1851 p->xbuf[5+i] = *(dat+i); 1851 p->xbuf[5+i] = *(dat+i);
1852 } 1852 }
1853 1853
1854 res = SIM_Command(p, llen, result, rcvSize); 1854 res = SIM_Command(p, llen, result, rcvSize);
1855 1855
1856 #ifdef SIM_DEBUG_TRACE 1856 #ifdef SIM_DEBUG_TRACE
1857 SIM_dbg_write_trace((SYS_UWORD8 *)"APCMD", 5); 1857 SIM_dbg_write_trace((SYS_UWORD8 *)"APCMD", 5);
1858 SIM_dbg_write_trace(p->xbuf, llen+5); 1858 SIM_dbg_write_trace(p->xbuf, llen+5);
1859 SIM_dbg_write_trace((SYS_UWORD8 *)"APANS", 5); 1859 SIM_dbg_write_trace((SYS_UWORD8 *)"APANS", 5);
1903 1903
1904 p = &(Sim[0]); 1904 p = &(Sim[0]);
1905 1905
1906 p->xbuf[0] = GSM_CLASS; 1906 p->xbuf[0] = GSM_CLASS;
1907 p->xbuf[1] = SIM_SEEK; 1907 p->xbuf[1] = SIM_SEEK;
1908 p->xbuf[2] = 0; 1908 p->xbuf[2] = 0;
1909 p->xbuf[3] = mode; 1909 p->xbuf[3] = mode;
1910 p->xbuf[4] = (SYS_UWORD8)llen; 1910 p->xbuf[4] = (SYS_UWORD8)llen;
1911 1911
1912 for (i=0;i<llen;i++) 1912 for (i=0;i<llen;i++)
1913 { 1913 {
1914 p->xbuf[5+i] = *(dat+i); 1914 p->xbuf[5+i] = *(dat+i);
1915 } 1915 }
1916 1916
1917 res = SIM_Command(p, llen, result, rcvSize); 1917 res = SIM_Command(p, llen, result, rcvSize);
1918 1918
1919 #ifdef SIM_DEBUG_TRACE 1919 #ifdef SIM_DEBUG_TRACE
1920 SIM_dbg_write_trace((SYS_UWORD8 *)"AQCMD", 5); 1920 SIM_dbg_write_trace((SYS_UWORD8 *)"AQCMD", 5);
1921 SIM_dbg_write_trace(p->xbuf, llen+5); 1921 SIM_dbg_write_trace(p->xbuf, llen+5);
1922 SIM_dbg_write_trace((SYS_UWORD8 *)"AQANS", 5); 1922 SIM_dbg_write_trace((SYS_UWORD8 *)"AQANS", 5);
1954 1954
1955 len = 3; 1955 len = 3;
1956 1956
1957 p->xbuf[0] = GSM_CLASS; 1957 p->xbuf[0] = GSM_CLASS;
1958 p->xbuf[1] = SIM_INCREASE; 1958 p->xbuf[1] = SIM_INCREASE;
1959 p->xbuf[2] = 0; 1959 p->xbuf[2] = 0;
1960 p->xbuf[3] = 0; 1960 p->xbuf[3] = 0;
1961 p->xbuf[4] = 3; 1961 p->xbuf[4] = 3;
1962 1962
1963 for (i=0;i<3;i++) 1963 for (i=0;i<3;i++)
1964 { 1964 {
1965 p->xbuf[5+i] = *(dat+i); 1965 p->xbuf[5+i] = *(dat+i);
1966 } 1966 }
1967 1967
1968 res = SIM_Command(p, len, result, rcvSize); 1968 res = SIM_Command(p, len, result, rcvSize);
1969 1969
1970 #ifdef SIM_DEBUG_TRACE 1970 #ifdef SIM_DEBUG_TRACE
1971 SIM_dbg_write_trace((SYS_UWORD8 *)"ARCMD", 5); 1971 SIM_dbg_write_trace((SYS_UWORD8 *)"ARCMD", 5);
1972 SIM_dbg_write_trace(p->xbuf, 3+5); 1972 SIM_dbg_write_trace(p->xbuf, 3+5);
1973 SIM_dbg_write_trace((SYS_UWORD8 *)"ARANS", 5); 1973 SIM_dbg_write_trace((SYS_UWORD8 *)"ARANS", 5);
2003 2003
2004 p = &(Sim[0]); 2004 p = &(Sim[0]);
2005 2005
2006 p->xbuf[0] = GSM_CLASS; 2006 p->xbuf[0] = GSM_CLASS;
2007 p->xbuf[1] = SIM_TERMINAL_PROFILE; 2007 p->xbuf[1] = SIM_TERMINAL_PROFILE;
2008 p->xbuf[2] = 0; 2008 p->xbuf[2] = 0;
2009 p->xbuf[3] = 0; 2009 p->xbuf[3] = 0;
2010 p->xbuf[4] = (SYS_UWORD8)llen; 2010 p->xbuf[4] = (SYS_UWORD8)llen;
2011 2011
2012 for (i=0;i<llen;i++) 2012 for (i=0;i<llen;i++)
2013 { 2013 {
2014 p->xbuf[5+i] = *(dat+i); 2014 p->xbuf[5+i] = *(dat+i);
2015 } 2015 }
2016 2016
2017 res = SIM_Command(p, llen, result, rcvSize); 2017 res = SIM_Command(p, llen, result, rcvSize);
2018 2018
2019 #ifdef SIM_DEBUG_TRACE 2019 #ifdef SIM_DEBUG_TRACE
2020 SIM_dbg_write_trace((SYS_UWORD8 *)"ASCMD", 5); 2020 SIM_dbg_write_trace((SYS_UWORD8 *)"ASCMD", 5);
2021 SIM_dbg_write_trace(p->xbuf, llen+5); 2021 SIM_dbg_write_trace(p->xbuf, llen+5);
2022 SIM_dbg_write_trace((SYS_UWORD8 *)"ASANS", 5); 2022 SIM_dbg_write_trace((SYS_UWORD8 *)"ASANS", 5);
2049 2049
2050 p = &(Sim[0]); 2050 p = &(Sim[0]);
2051 2051
2052 p->xbuf[0] = GSM_CLASS; 2052 p->xbuf[0] = GSM_CLASS;
2053 p->xbuf[1] = SIM_FETCH; 2053 p->xbuf[1] = SIM_FETCH;
2054 p->xbuf[2] = 0; 2054 p->xbuf[2] = 0;
2055 p->xbuf[3] = 0; 2055 p->xbuf[3] = 0;
2056 p->xbuf[4] = (SYS_UWORD8)llen; 2056 p->xbuf[4] = (SYS_UWORD8)llen;
2057 2057
2058 2058
2059 res = SIM_Command(p, 0, result, rcvSize); 2059 res = SIM_Command(p, 0, result, rcvSize);
2060 2060
2061 #ifdef SIM_DEBUG_TRACE 2061 #ifdef SIM_DEBUG_TRACE
2062 SIM_dbg_write_trace((SYS_UWORD8 *)"ATCMD", 5); 2062 SIM_dbg_write_trace((SYS_UWORD8 *)"ATCMD", 5);
2063 SIM_dbg_write_trace(p->xbuf, 5); 2063 SIM_dbg_write_trace(p->xbuf, 5);
2064 SIM_dbg_write_trace((SYS_UWORD8 *)"ATANS", 5); 2064 SIM_dbg_write_trace((SYS_UWORD8 *)"ATANS", 5);
2094 2094
2095 p = &(Sim[0]); 2095 p = &(Sim[0]);
2096 2096
2097 p->xbuf[0] = GSM_CLASS; 2097 p->xbuf[0] = GSM_CLASS;
2098 p->xbuf[1] = SIM_TERMINAL_RESPONSE; 2098 p->xbuf[1] = SIM_TERMINAL_RESPONSE;
2099 p->xbuf[2] = 0; 2099 p->xbuf[2] = 0;
2100 p->xbuf[3] = 0; 2100 p->xbuf[3] = 0;
2101 p->xbuf[4] = (SYS_UWORD8)llen; 2101 p->xbuf[4] = (SYS_UWORD8)llen;
2102 2102
2103 for (i=0;i<llen;i++) 2103 for (i=0;i<llen;i++)
2104 { 2104 {
2105 p->xbuf[5+i] = *(dat+i); 2105 p->xbuf[5+i] = *(dat+i);
2106 } 2106 }
2107 2107
2108 res = SIM_Command(p, llen, result, rcvSize); 2108 res = SIM_Command(p, llen, result, rcvSize);
2109 2109
2110 #ifdef SIM_DEBUG_TRACE 2110 #ifdef SIM_DEBUG_TRACE
2111 SIM_dbg_write_trace((SYS_UWORD8 *)"AUCMD", 5); 2111 SIM_dbg_write_trace((SYS_UWORD8 *)"AUCMD", 5);
2112 SIM_dbg_write_trace(p->xbuf, llen+5); 2112 SIM_dbg_write_trace(p->xbuf, llen+5);
2113 SIM_dbg_write_trace((SYS_UWORD8 *)"AUANS", 5); 2113 SIM_dbg_write_trace((SYS_UWORD8 *)"AUANS", 5);
2140 2140
2141 p = &(Sim[0]); 2141 p = &(Sim[0]);
2142 2142
2143 p->xbuf[0] = GSM_CLASS; 2143 p->xbuf[0] = GSM_CLASS;
2144 p->xbuf[1] = SIM_ENVELOPE; 2144 p->xbuf[1] = SIM_ENVELOPE;
2145 p->xbuf[2] = 0; 2145 p->xbuf[2] = 0;
2146 p->xbuf[3] = 0; 2146 p->xbuf[3] = 0;
2147 p->xbuf[4] = (SYS_UWORD8)llen; 2147 p->xbuf[4] = (SYS_UWORD8)llen;
2148 2148
2149 for (i=0;i<llen;i++) 2149 for (i=0;i<llen;i++)
2150 { 2150 {
2151 p->xbuf[5+i] = *(dat+i); 2151 p->xbuf[5+i] = *(dat+i);
2152 } 2152 }
2153 2153
2154 res = SIM_Command(p, llen, result, rcvSize); 2154 res = SIM_Command(p, llen, result, rcvSize);
2155 2155
2156 #ifdef SIM_DEBUG_TRACE 2156 #ifdef SIM_DEBUG_TRACE
2157 SIM_dbg_write_trace((SYS_UWORD8 *)"AVCMD", 5); 2157 SIM_dbg_write_trace((SYS_UWORD8 *)"AVCMD", 5);
2158 SIM_dbg_write_trace(p->xbuf, llen+5); 2158 SIM_dbg_write_trace(p->xbuf, llen+5);
2159 SIM_dbg_write_trace((SYS_UWORD8 *)"AVANS", 5); 2159 SIM_dbg_write_trace((SYS_UWORD8 *)"AVANS", 5);
2196 2196
2197 p = &(Sim[0]); 2197 p = &(Sim[0]);
2198 2198
2199 p->xbuf[0] = dat[0]; 2199 p->xbuf[0] = dat[0];
2200 p->xbuf[1] = dat[1]; 2200 p->xbuf[1] = dat[1];
2201 p->xbuf[2] = dat[2]; 2201 p->xbuf[2] = dat[2];
2202 p->xbuf[3] = dat[3]; 2202 p->xbuf[3] = dat[3];
2203 p->xbuf[4] = dat[4]; 2203 p->xbuf[4] = dat[4];
2204 2204
2205 for (i=5;i<trxLen;i++) 2205 for (i=5;i<trxLen;i++)
2206 { 2206 {
2207 p->xbuf[i] = dat[i]; 2207 p->xbuf[i] = dat[i];
2208 } 2208 }
2209 2209
2210 // enable the WIM behavior of the sim driver 2210 // enable the WIM behavior of the sim driver
2211 p->apdu_ans_length = rcvLen; 2211 p->apdu_ans_length = rcvLen;
2212 2212
2213 res = SIM_Command(p, (trxLen - 5), result, rcvSize); 2213 res = SIM_Command(p, (trxLen - 5), result, rcvSize);
2214 2214
2215 // disable the WIM behavior of the sim driver 2215 // disable the WIM behavior of the sim driver
2216 p->apdu_ans_length = 0; 2216 p->apdu_ans_length = 0;
2217 2217
2218 #ifdef SIM_DEBUG_TRACE 2218 #ifdef SIM_DEBUG_TRACE
2219 SIM_dbg_write_trace((SYS_UWORD8 *)"AWCMD", 5); 2219 SIM_dbg_write_trace((SYS_UWORD8 *)"AWCMD", 5);
2220 SIM_dbg_write_trace(p->xbuf, trxLen); 2220 SIM_dbg_write_trace(p->xbuf, trxLen);
2221 SIM_dbg_write_trace((SYS_UWORD8 *)"AWANS", 5); 2221 SIM_dbg_write_trace((SYS_UWORD8 *)"AWANS", 5);
2222 SIM_dbg_tmp[0] = (SYS_UWORD8)(*rcvSize >> 8); 2222 SIM_dbg_tmp[0] = (SYS_UWORD8)(*rcvSize >> 8);
2260 2260
2261 2261
2262 //analyse the nature of the command to execute 2262 //analyse the nature of the command to execute
2263 2263
2264 if ( 2264 if (
2265 (p->xbuf[1] == 0x12) || 2265 (p->xbuf[1] == 0x12) ||
2266 (p->xbuf[1] == 0xB2) || 2266 (p->xbuf[1] == 0xB2) ||
2267 (p->xbuf[1] == 0xB0) || 2267 (p->xbuf[1] == 0xB0) ||
2268 (p->xbuf[1] == 0xF2) || 2268 (p->xbuf[1] == 0xF2) ||
2269 (p->xbuf[1] == 0xC0) || 2269 (p->xbuf[1] == 0xC0) ||
2270 (p->apdu_ans_length != 0) 2270 (p->apdu_ans_length != 0)
2271 ) 2271 )
2272 //FETCH, READ_RECORD, READ_BINARY, STATUS, GET_RESPONSE commands == receive command 2272 //FETCH, READ_RECORD, READ_BINARY, STATUS, GET_RESPONSE commands == receive command
2273 { 2273 {
2274 if (p->xbuf[4] == 0) //if P3 == 0 when sending receive command 2274 if (p->xbuf[4] == 0) //if P3 == 0 when sending receive command
2275 { 2275 {
2276 p->expected_data = 256; 2276 p->expected_data = 256;
2277 } 2277 }
2278 else 2278 else
2279 { 2279 {
2280 p->expected_data = p->xbuf[4]; 2280 p->expected_data = p->xbuf[4];
2281 } 2281 }
2318 SYS_UWORD16 sz; 2318 SYS_UWORD16 sz;
2319 2319
2320 res = SIM_Select(DF_GSM, ubuf, &sz); 2320 res = SIM_Select(DF_GSM, ubuf, &sz);
2321 if ((res & 0xFF00) != 0x9F00) 2321 if ((res & 0xFF00) != 0x9F00)
2322 { 2322 {
2323 res = SIM_Select(DF_DCS1800, ubuf, &sz); 2323 res = SIM_Select(DF_DCS1800, ubuf, &sz);
2324 if ((res & 0xFF00) != 0x9F00) 2324 if ((res & 0xFF00) != 0x9F00)
2325 { 2325 {
2326 return (1); 2326 return (1);
2327 } 2327 }
2328 } 2328 }
2329 res = SIM_GetResponse( ubuf, res & 0x00FF , &sz); 2329 res = SIM_GetResponse( ubuf, res & 0x00FF , &sz);
2330 if (res != 0x9000) 2330 if (res != 0x9000)
2331 return (1); 2331 return (1);
2332 2332
2333 p->FileC = ubuf[13]; 2333 p->FileC = ubuf[13];
2334 return (0); 2334 return (0);
2335 } 2335 }
2336 2336
2337 /* 2337 /*
2338 * Use to determine value of b2 in file caracteristics contained in response 2338 * Use to determine value of b2 in file caracteristics contained in response
2339 * of SELECT Master File command 2339 * of SELECT Master File command
2340 * return 0 if no preferred speed during authentication 2340 * return 0 if no preferred speed during authentication
2341 * 1 if 13/4Mhz mandatory 2341 * 1 if 13/4Mhz mandatory
2342 * 2342 *
2343 * 2343 *
2344 */ 2344 */
2345 2345
2346 void SIM_Interpret_FileCharacteristics(SIM_PORT *p) 2346 void SIM_Interpret_FileCharacteristics(SIM_PORT *p)
2347 { 2347 {
2348 //interpret b2 bit for operating authentication speed 2348 //interpret b2 bit for operating authentication speed
2349 if((p->conf1 & 0x0020) && (p->FileC & 0x02)) 2349 if((p->conf1 & 0x0020) && (p->FileC & 0x02))
2350 { 2350 {
2351 p->Freq_Algo = 1; 2351 p->Freq_Algo = 1;
2352 } 2352 }
2353 2353
2354 //interpret Clock stop behavior 2354 //interpret Clock stop behavior
2355 // modified by J. Yp-Tcha to integrate all the behaviors required by ETSI. 2355 // modified by J. Yp-Tcha to integrate all the behaviors required by ETSI.
2356 // 18/11/2002 : TI Chip always allowed low level, high level is hard dependant 2356 // 18/11/2002 : TI Chip always allowed low level, high level is hard dependant
2357 2357
2358 if ((p->FileC & SIM_CLK_STOP_MASK) == SIM_CLK_STOP_NOT_ALLWD) { 2358 if ((p->FileC & SIM_CLK_STOP_MASK) == SIM_CLK_STOP_NOT_ALLWD) {
2359 /* Sim Clock Stop Not Allowed */ 2359 /* Sim Clock Stop Not Allowed */
2360 SIM_sleep_status = SIM_SLEEP_NOT_ALLOWED; 2360 SIM_sleep_status = SIM_SLEEP_NOT_ALLOWED;
2361 /* There is not need to modifiy p->conf1 */ 2361 /* There is not need to modifiy p->conf1 */
2362 status_os_sim = NU_Delete_Timer (&SIM_timer); 2362 status_os_sim = NU_Delete_Timer (&SIM_timer);
2363 } 2363 }
2364 else { 2364 else {
2365 if ((p->FileC & SIM_CLK_STOP_MASK) == SIM_CLK_STOP_ALLWD) { 2365 if ((p->FileC & SIM_CLK_STOP_MASK) == SIM_CLK_STOP_ALLWD) {
2366 /* Sim Clock Stop Allowed, no prefered level */ 2366 /* Sim Clock Stop Allowed, no prefered level */
2377 SIM_sleep_status = SIM_SLEEP_DESACT; 2377 SIM_sleep_status = SIM_SLEEP_DESACT;
2378 p->c->conf1 = p->conf1 |= SIM_CONF1_SCLKLEV; 2378 p->c->conf1 = p->conf1 |= SIM_CONF1_SCLKLEV;
2379 #else 2379 #else
2380 /* Sim Clock Stop Not Allowed because the interface do not support this level */ 2380 /* Sim Clock Stop Not Allowed because the interface do not support this level */
2381 SIM_sleep_status = SIM_SLEEP_NOT_ALLOWED; 2381 SIM_sleep_status = SIM_SLEEP_NOT_ALLOWED;
2382 /* There is not need to modifiy p->conf1 */ 2382 /* There is not need to modifiy p->conf1 */
2383 status_os_sim = NU_Delete_Timer (&SIM_timer); 2383 status_os_sim = NU_Delete_Timer (&SIM_timer);
2384 #endif 2384 #endif
2385 } 2385 }
2386 else { 2386 else {
2387 /* by default, Low Level is allowed */ 2387 /* by default, Low Level is allowed */
2414 SYS_UWORD8 TA1; 2414 SYS_UWORD8 TA1;
2415 SYS_UWORD8 n; 2415 SYS_UWORD8 n;
2416 SYS_UWORD8 err; 2416 SYS_UWORD8 err;
2417 2417
2418 p->xbuf[0] = 0xFF; //character of PTS proc to send 2418 p->xbuf[0] = 0xFF; //character of PTS proc to send
2419 p->xbuf[1] = 0; 2419 p->xbuf[1] = 0;
2420 p->xbuf[2] = 0xFF; 2420 p->xbuf[2] = 0xFF;
2421 p->xbuf[3] = 0x7B; 2421 p->xbuf[3] = 0x7B;
2422 2422
2423 //TA1,TB1,TC1,TD1 present in ATR ? 2423 //TA1,TB1,TC1,TD1 present in ATR ?
2424 2424
2426 2426
2427 p->PTS_Try++; 2427 p->PTS_Try++;
2428 2428
2429 if (p->PTS_Try > 4) 2429 if (p->PTS_Try > 4)
2430 { 2430 {
2431 return (SIM_ERR_CARDREJECT); 2431 return (SIM_ERR_CARDREJECT);
2432 } // at the fourth attempt, PTS procedure is unusefull. Use default value. 2432 } // at the fourth attempt, PTS procedure is unusefull. Use default value.
2433 //TA1 present? Test 27.11.2.6 2433 //TA1 present? Test 27.11.2.6
2434 else if ( p->PTS_Try == 4) 2434 else if ( p->PTS_Try == 4)
2435 { 2435 {
2436 SIM_Calcetu (p); 2436 SIM_Calcetu (p);
2437 return (0); 2437 return (0);
2438 } 2438 }
2439 2439
2440 if(cP->AtrData[1] & 0x10) 2440 if(cP->AtrData[1] & 0x10)
2441 { 2441 {
2442 TA1 = cP->AtrData[2]; 2442 TA1 = cP->AtrData[2];
2443 } 2443 }
2444 else //if TA1 not present, return 2444 else //if TA1 not present, return
2467 { 2467 {
2468 SIM_Calcetu (p); 2468 SIM_Calcetu (p);
2469 return (0); 2469 return (0);
2470 } //if TA1 != 0x11 and 0x94, need to send PTS request 2470 } //if TA1 != 0x11 and 0x94, need to send PTS request
2471 //transmit request of speed enhancement : PTS 2471 //transmit request of speed enhancement : PTS
2472 SIM_WriteBuffer(p, 0, n); 2472 SIM_WriteBuffer(p, 0, n);
2473 2473
2474 p->moderx = 0; //mode of normal reception 2474 p->moderx = 0; //mode of normal reception
2475 p->expected_data = n; 2475 p->expected_data = n;
2476 2476
2477 if (err = SIM_Waitforchars (p, p->etu9600)) 2477 if (err = SIM_Waitforchars (p, p->etu9600))
2478 { 2478 {
2479 return (err); 2479 return (err);
2480 } 2480 }
2481 //should received same chars as PTS request 2481 //should received same chars as PTS request
2482 if ((p->rbuf[0] != p->xbuf[0]) || (p->rbuf[1] != p->xbuf[1]) || 2482 if ((p->rbuf[0] != p->xbuf[0]) || (p->rbuf[1] != p->xbuf[1]) ||
2483 (p->rbuf[2] != p->xbuf[2])) 2483 (p->rbuf[2] != p->xbuf[2]))
2484 { 2484 {
2485 return(SIM_ERR_READ); 2485 return(SIM_ERR_READ);
2486 } 2486 }
2487 2487
2488 2488
2489 if (n == 4) 2489 if (n == 4)
2490 { 2490 {
2491 if (p->rbuf[3] != p->xbuf[3]) 2491 if (p->rbuf[3] != p->xbuf[3])
2492 { 2492 {
2493 return(SIM_ERR_READ); 2493 return(SIM_ERR_READ);
2494 } 2494 }
2495 2495
2496 //correct response from SIM : with speed enhanced 2496 //correct response from SIM : with speed enhanced
2497 p->c->conf1 = p->conf1 |= SIM_CONF1_ETU; //set F=512 D=8 2497 p->c->conf1 = p->conf1 |= SIM_CONF1_ETU; //set F=512 D=8
2498 } 2498 }
2499 2499
2500 SIM_Calcetu (p); 2500 SIM_Calcetu (p);
2547 if (SIM_sleep_status == SIM_SLEEP_ACT) 2547 if (SIM_sleep_status == SIM_SLEEP_ACT)
2548 { 2548 {
2549 p->c->conf1 = p->conf1 |= SIM_CONF1_SCLKEN; 2549 p->c->conf1 = p->conf1 |= SIM_CONF1_SCLKEN;
2550 // WCS patch for NU_Sleep(0) bug 2550 // WCS patch for NU_Sleep(0) bug
2551 if (p->startclock > 0) 2551 if (p->startclock > 0)
2552 ind_os_sleep (p->startclock); 2552 ind_os_sleep (p->startclock);
2553 // End WCS patch 2553 // End WCS patch
2554 SIM_sleep_status = SIM_SLEEP_DESACT; 2554 SIM_sleep_status = SIM_SLEEP_DESACT;
2555 } 2555 }
2556 } 2556 }
2557 2557
2558 /* 2558 /*
2559 * procedure to parse ATR dynamically 2559 * procedure to parse ATR dynamically
2560 * input p pointer of type SIM_PORT 2560 * input p pointer of type SIM_PORT
2561 * output return error code 2561 * output return error code
2562 * SIM_ERR_WAIT, p->errorSIM 2562 * SIM_ERR_WAIT, p->errorSIM
2573 volatile SYS_UWORD8 InterfChar; 2573 volatile SYS_UWORD8 InterfChar;
2574 SYS_UWORD16 countT; 2574 SYS_UWORD16 countT;
2575 SYS_UWORD16 mask; 2575 SYS_UWORD16 mask;
2576 SYS_UWORD16 returncode; 2576 SYS_UWORD16 returncode;
2577 SYS_UWORD8 i; 2577 SYS_UWORD8 i;
2578 SYS_UWORD8 firstprotocol; 2578 SYS_UWORD8 firstprotocol;
2579 SYS_UWORD8 Tx,T; 2579 SYS_UWORD8 Tx,T;
2580 SYS_UWORD8 TDi; 2580 SYS_UWORD8 TDi;
2581 SYS_UWORD8 position_of_TC1, position_of_TB1; 2581 SYS_UWORD8 position_of_TC1, position_of_TB1;
2582 SYS_UWORD8 another_protocol_present; 2582 SYS_UWORD8 another_protocol_present;
2583 SYS_UWORD16 wait80000clk; 2583 SYS_UWORD16 wait80000clk;
2584 2584
2585 i = 0; 2585 i = 0;
2586 //wait for TS and T0 2586 //wait for TS and T0
2587 p->moderx = 0; 2587 p->moderx = 0;
2588 p->expected_data= 1; 2588 p->expected_data= 1;
2589 firstprotocol = 0; 2589 firstprotocol = 0;
2595 //wait for first character TS of ATR sequence. It should arrive before 80000sclk 2595 //wait for first character TS of ATR sequence. It should arrive before 80000sclk
2596 if (returncode = SIM_Waitforchars (p, wait80000clk)) 2596 if (returncode = SIM_Waitforchars (p, wait80000clk))
2597 { 2597 {
2598 return returncode; 2598 return returncode;
2599 } 2599 }
2600 2600
2601 //wait for T0 2601 //wait for T0
2602 p->expected_data++; 2602 p->expected_data++;
2603 if (returncode = SIM_Waitforchars (p, p->etu9600)) 2603 if (returncode = SIM_Waitforchars (p, p->etu9600))
2604 { 2604 {
2605 return returncode; 2605 return returncode;
2606 } 2606 }
2607 2607
2611 { 2611 {
2612 cP->Inverse = 0; 2612 cP->Inverse = 0;
2613 } 2613 }
2614 /*-----------------------------------------------------------*/ 2614 /*-----------------------------------------------------------*/
2615 /* Inverse convention card */ 2615 /* Inverse convention card */
2616 // If first byte is correct for inverse card, return success 2616 // If first byte is correct for inverse card, return success
2617 else if (((p->rbuf[0] & 0x0F) == 0x03) && (p->rx_index != 0)) 2617 else if (((p->rbuf[0] & 0x0F) == 0x03) && (p->rx_index != 0))
2618 { 2618 {
2619 cP->Inverse = 1; 2619 cP->Inverse = 1;
2620 } 2620 }
2621 else 2621 else
2631 2631
2632 Tx = SIM_Translate_atr_char (p->rbuf[1], cP); 2632 Tx = SIM_Translate_atr_char (p->rbuf[1], cP);
2633 2633
2634 HistChar = Tx & 0x0F; //get K, number of transmitted historical character 2634 HistChar = Tx & 0x0F; //get K, number of transmitted historical character
2635 2635
2636 2636
2637 while (TDi != 0) 2637 while (TDi != 0)
2638 { 2638 {
2639 while (mask < 0x100) //monitors interface chars 2639 while (mask < 0x100) //monitors interface chars
2640 { 2640 {
2641 if ((Tx & mask) == mask) //monitors if interface character TAx,TBx,TCx,TDc present 2641 if ((Tx & mask) == mask) //monitors if interface character TAx,TBx,TCx,TDc present
2643 InterfChar++; 2643 InterfChar++;
2644 } 2644 }
2645 //wait for TC1 and save its position 2645 //wait for TC1 and save its position
2646 if ((firstprotocol == 0) && ((Tx & 0x40) == mask)) 2646 if ((firstprotocol == 0) && ((Tx & 0x40) == mask))
2647 { 2647 {
2648 position_of_TC1 = InterfChar - 1; 2648 position_of_TC1 = InterfChar - 1;
2649 } 2649 }
2650 if ((firstprotocol == 0) && ((Tx & 0x20) == mask)) 2650 if ((firstprotocol == 0) && ((Tx & 0x20) == mask))
2651 { 2651 {
2652 position_of_TB1 = InterfChar - 1; 2652 position_of_TB1 = InterfChar - 1;
2653 } 2653 }
2654 2654
2655 mask = mask << 1; 2655 mask = mask << 1;
2656 } 2656 }
2657 2657
2658 p->expected_data = InterfChar; //wait for TAi,TBi,TCi,TDi if present 2658 p->expected_data = InterfChar; //wait for TAi,TBi,TCi,TDi if present
2659 2659
2660 if (returncode = SIM_Waitforchars (p, p->etu9600)) 2660 if (returncode = SIM_Waitforchars (p, p->etu9600))
2661 { 2661 {
2662 return returncode; 2662 return returncode;
2663 } 2663 }
2664 2664
2666 if ((firstprotocol == 0) && (position_of_TC1 != 0)) 2666 if ((firstprotocol == 0) && (position_of_TC1 != 0))
2667 { 2667 {
2668 T = SIM_Translate_atr_char (p->rbuf[position_of_TC1], cP); 2668 T = SIM_Translate_atr_char (p->rbuf[position_of_TC1], cP);
2669 2669
2670 if ((T != 0) && (T != 255)) //test 27.11.1.3 2670 if ((T != 0) && (T != 255)) //test 27.11.1.3
2671 { //return Error in case of bad TC1 value 2671 { //return Error in case of bad TC1 value
2672 return (SIM_ERR_CARDREJECT); 2672 return (SIM_ERR_CARDREJECT);
2673 } 2673 }
2674 } 2674 }
2675 //need to monitor if TB1 present and if differente from 0 on first protocol 2675 //need to monitor if TB1 present and if differente from 0 on first protocol
2676 if ((firstprotocol == 0) && (position_of_TB1 != 0)) 2676 if ((firstprotocol == 0) && (position_of_TB1 != 0))
2677 { 2677 {
2678 T = SIM_Translate_atr_char (p->rbuf[position_of_TB1], cP); 2678 T = SIM_Translate_atr_char (p->rbuf[position_of_TB1], cP);
2679 2679
2680 if (T != 0) //ITU 2680 if (T != 0) //ITU
2681 { //return Error in case of bad TB1 value 2681 { //return Error in case of bad TB1 value
2682 return (SIM_ERR_CARDREJECT); 2682 return (SIM_ERR_CARDREJECT);
2683 } 2683 }
2684 } 2684 }
2685 2685
2686 if ((Tx & 0x80) == 0x80) //TDi byte on first protocol must be 0 2686 if ((Tx & 0x80) == 0x80) //TDi byte on first protocol must be 0
2687 { //get new TD char 2687 { //get new TD char
2688 Tx = SIM_Translate_atr_char (p->rbuf[InterfChar - 1], cP); 2688 Tx = SIM_Translate_atr_char (p->rbuf[InterfChar - 1], cP);
2689 2689
2690 if ((Tx & 0x0F) != 0) 2690 if ((Tx & 0x0F) != 0)
2691 { 2691 {
2692 if (firstprotocol == 0) //if first protocol received is not T=0, card is rejected 2692 if (firstprotocol == 0) //if first protocol received is not T=0, card is rejected
2693 { 2693 {
2694 return (SIM_ERR_CARDREJECT); //protocol other than T=0 2694 return (SIM_ERR_CARDREJECT); //protocol other than T=0
2695 } 2695 }
2696 else 2696 else
2697 { //if an another protocol T != 0 present, need to wait for TCK char 2697 { //if an another protocol T != 0 present, need to wait for TCK char
2698 another_protocol_present = 1; 2698 another_protocol_present = 1;
2699 } 2699 }
2700 } 2700 }
2701 mask = 0x10; 2701 mask = 0x10;
2702 firstprotocol++; //indicate another protocol T 2702 firstprotocol++; //indicate another protocol T
2703 } 2703 }
2704 else 2704 else
2705 { 2705 {
2706 TDi = 0; 2706 TDi = 0;
2707 } 2707 }
2708 } 2708 }
2709 //add TCK if necessary 2709 //add TCK if necessary
2710 p->expected_data = HistChar + InterfChar + another_protocol_present; 2710 p->expected_data = HistChar + InterfChar + another_protocol_present;
2711 2711
2712 if (returncode = SIM_Waitforchars (p, p->etu9600)) 2712 if (returncode = SIM_Waitforchars (p, p->etu9600))
2713 { 2713 {
2714 return returncode; 2714 return returncode;
2715 } 2715 }
2716 2716
2717 cP->AtrSize = p->rx_index; 2717 cP->AtrSize = p->rx_index;
2718 2718
2719 if (cP->Inverse) //inverse card 2719 if (cP->Inverse) //inverse card
2720 { 2720 {
2721 // Copy ATR data 2721 // Copy ATR data
2722 for (i=0;i<cP->AtrSize;i++) 2722 for (i=0;i<cP->AtrSize;i++)
2723 { 2723 {
2724 cP->AtrData[i] = SIM_ByteReverse(p->rbuf[i]); 2724 cP->AtrData[i] = SIM_ByteReverse(p->rbuf[i]);
2725 } 2725 }
2726 p->c->conf1 = p->conf1 |= SIM_CONF1_CONV | SIM_CONF1_CHKPAR; 2726 p->c->conf1 = p->conf1 |= SIM_CONF1_CONV | SIM_CONF1_CHKPAR;
2727 } 2727 }
2728 else //direct card 2728 else //direct card
2729 { 2729 {
2730 p->c->conf1 = p->conf1 |= SIM_CONF1_CHKPAR; //0x0409 2730 p->c->conf1 = p->conf1 |= SIM_CONF1_CHKPAR; //0x0409
2731 // Copy ATR data 2731 // Copy ATR data
2732 for (i=0;i<cP->AtrSize;i++) 2732 for (i=0;i<cP->AtrSize;i++)
2733 { 2733 {
2734 cP->AtrData[i] = p->rbuf[i]; 2734 cP->AtrData[i] = p->rbuf[i];
2735 } 2735 }
2736 } 2736 }
2737 2737
2738 return (0); 2738 return (0);
2739 } 2739 }
2740 2740
2741 /* 2741 /*
2742 ** SIM_Translate_atr_char 2742 ** SIM_Translate_atr_char
2743 * 2743 *
2744 * FILENAME: sim.c 2744 * FILENAME: sim.c
2745 * 2745 *
2746 * PARAMETERS: input char to translate 2746 * PARAMETERS: input char to translate
2747 * cP sim structure (indicates if inverse card present) 2747 * cP sim structure (indicates if inverse card present)
2755 { 2755 {
2756 SYS_UWORD8 translated; 2756 SYS_UWORD8 translated;
2757 2757
2758 if (cP->Inverse) 2758 if (cP->Inverse)
2759 { 2759 {
2760 translated = SIM_ByteReverse(input); 2760 translated = SIM_ByteReverse(input);
2761 } 2761 }
2762 else 2762 else
2763 { 2763 {
2764 translated = input; //get character next char T0 2764 translated = input; //get character next char T0
2765 } 2765 }
2771 /* 2771 /*
2772 * SIM_Waitforchars is used for waiting nbchar characters from SIM 2772 * SIM_Waitforchars is used for waiting nbchar characters from SIM
2773 * input p sim port 2773 * input p sim port
2774 * max_wait max number of TDMA to wait between 2 characters 2774 * max_wait max number of TDMA to wait between 2 characters
2775 * output 2775 * output
2776 * error code 0 if OK 2776 * error code 0 if OK
2777 */ 2777 */
2778 2778
2779 2779
2780 SYS_UWORD16 SIM_Waitforchars (SIM_PORT *p, SYS_UWORD16 max_wait) 2780 SYS_UWORD16 SIM_Waitforchars (SIM_PORT *p, SYS_UWORD16 max_wait)
2781 { 2781 {
2785 if (p->moderx == 6) //use for reception of ACK when command need to transmit rest of data 2785 if (p->moderx == 6) //use for reception of ACK when command need to transmit rest of data
2786 { 2786 {
2787 p->ack = 0; 2787 p->ack = 0;
2788 countT = 0; 2788 countT = 0;
2789 2789
2790 while((p->ack == 0) && (p->moderx == 6)) 2790 while((p->ack == 0) && (p->moderx == 6))
2791 { //if p->moderx change from 6 to 5, need to wait for SW1 and SW2 2791 { //if p->moderx change from 6 to 5, need to wait for SW1 and SW2
2792 2792
2793 ind_os_sleep(1); 2793 ind_os_sleep(1);
2794 countT++; //implementation of software Waiting time overflow 2794 countT++; //implementation of software Waiting time overflow
2795 2795
2809 } 2809 }
2810 } 2810 }
2811 if (p->moderx == 6) //if transition to moderx = 5 in synchronous part 2811 if (p->moderx == 6) //if transition to moderx = 5 in synchronous part
2812 { //need to quit for SW1/SW2 reception 2812 { //need to quit for SW1/SW2 reception
2813 return (0); 2813 return (0);
2814 } 2814 }
2815 } 2815 }
2816 2816
2817 if ((p->moderx != 6) && (p->moderx != 5)) //treatement of mode 0, 1, 2, 3, 4 2817 if ((p->moderx != 6) && (p->moderx != 5)) //treatement of mode 0, 1, 2, 3, 4
2818 { 2818 {
2819 countT = 0; 2819 countT = 0;
2820 old_nb_char = p->rx_index; 2820 old_nb_char = p->rx_index;
2821 //leave while if moderx == 5 2821 //leave while if moderx == 5
2822 while((p->rx_index < p->expected_data) && (p->moderx != 5)) 2822 while((p->rx_index < p->expected_data) && (p->moderx != 5))
2823 { 2823 {
2824 ind_os_sleep(1); 2824 ind_os_sleep(1);
2825 countT++; //implementation of software Waiting time overflow 2825 countT++; //implementation of software Waiting time overflow
2826 2826
2827 if (p->null_received) //if NULL char received, wait for next procedure char 2827 if (p->null_received) //if NULL char received, wait for next procedure char
2853 if (p->moderx == 5) //use for reception of SW1 SW2 2853 if (p->moderx == 5) //use for reception of SW1 SW2
2854 { 2854 {
2855 countT = 0; 2855 countT = 0;
2856 old_nb_char = p->SWcount; 2856 old_nb_char = p->SWcount;
2857 2857
2858 while(p->SWcount < 2) 2858 while(p->SWcount < 2)
2859 { //if p->moderx change from 6 to 5, need to wait for SW1 and SW2 2859 { //if p->moderx change from 6 to 5, need to wait for SW1 and SW2
2860 2860
2861 ind_os_sleep(1); 2861 ind_os_sleep(1);
2862 countT++; //implementation of software Waiting time overflow 2862 countT++; //implementation of software Waiting time overflow
2863 2863
2886 } 2886 }
2887 else //treatement of abnormal case of the asynchronous state machine 2887 else //treatement of abnormal case of the asynchronous state machine
2888 { 2888 {
2889 return (SIM_ERR_ABNORMAL_CASE1); 2889 return (SIM_ERR_ABNORMAL_CASE1);
2890 } 2890 }
2891 2891
2892 } 2892 }
2893 2893
2894 2894
2895 2895
2896 /* 2896 /*
2913 else //etu period is 372/1*Tsclk 2913 else //etu period is 372/1*Tsclk
2914 { 2914 {
2915 p->etu9600 = 1815; // old = 500, increase of 363% 2915 p->etu9600 = 1815; // old = 500, increase of 363%
2916 p->etu400 = 28; 2916 p->etu400 = 28;
2917 p->stopclock = 94; 2917 p->stopclock = 94;
2918 p->startclock = 38; 2918 p->startclock = 38;
2919 } 2919 }
2920 } 2920 }
2921 else //clock input is 13/4 Mhz 2921 else //clock input is 13/4 Mhz
2922 { 2922 {
2923 if (p->conf1 & SIM_CONF1_ETU) //etu period is 512/8*Tsclk 2923 if (p->conf1 & SIM_CONF1_ETU) //etu period is 512/8*Tsclk
2924 { 2924 {
2925 p->etu9600 = 159; // old = 44, increase of 363% 2925 p->etu9600 = 159; // old = 44, increase of 363%
2926 p->etu400 = 3; 2926 p->etu400 = 3;
2927 p->stopclock = 9; 2927 p->stopclock = 9;
2928 p->startclock = 4; 2928 p->startclock = 4;
2929 } 2929 }
2930 else //etu period is 372/1*Tsclk 2930 else //etu period is 372/1*Tsclk
2931 { 2931 {
2932 p->etu9600 = 907; // old = 250, increase of 363% 2932 p->etu9600 = 907; // old = 250, increase of 363%
2933 p->etu400 = 14; 2933 p->etu400 = 14;
2934 p->stopclock = 47; 2934 p->stopclock = 47;
2935 p->startclock = 19; 2935 p->startclock = 19;
2936 } 2936 }
2937 } 2937 }
2938 } 2938 }
2939 2939
2940 2940
2941 2941
2942 2942
2944 /* 2944 /*
2945 * Set the level shifter voltage for start up sequence 2945 * Set the level shifter voltage for start up sequence
2946 * 2946 *
2947 */ 2947 */
2948 2948
2949 SYS_UWORD8 SIM_StartVolt (SYS_UWORD8 ResetFlag) 2949 SYS_UWORD8 SIM_StartVolt (SYS_UWORD8 ResetFlag)
2950 { 2950 {
2951 SYS_UWORD8 abbmask; 2951 SYS_UWORD8 abbmask;
2952 2952
2953 #if(ANLG_FAM == 1) 2953 #if(ANLG_FAM == 1)
2954 // we assume that in SIM_TYPE_5V there is nothing to do because it is the reset value 2954 // we assume that in SIM_TYPE_5V there is nothing to do because it is the reset value
2987 ABB_wa_VRPC ((ABB_Read_Register_on_page(PAGE1,VRPCSIM) & 0xF4) | abbmask); 2987 ABB_wa_VRPC ((ABB_Read_Register_on_page(PAGE1,VRPCSIM) & 0xF4) | abbmask);
2988 while(count++ < 5) 2988 while(count++ < 5)
2989 { 2989 {
2990 if (ABB_Read_Register_on_page(PAGE1,VRPCSIM) & 0x04) // test RSIMRSU 2990 if (ABB_Read_Register_on_page(PAGE1,VRPCSIM) & 0x04) // test RSIMRSU
2991 return(SIM_OK); 2991 return(SIM_OK);
2992 ind_os_sleep(1); 2992 ind_os_sleep(1);
2993 } 2993 }
2994 // IOTA failure activation 2994 // IOTA failure activation
2995 return(SIM_ERR_HARDWARE_FAIL); 2995 return(SIM_ERR_HARDWARE_FAIL);
2996 #endif 2996 #endif
2997 // 3V only 2997 // 3V only
3001 ABB_wa_VRPC ((ABB_Read_Register_on_page(PAGE1,VRPCSIM) & 0xF4) | abbmask); 3001 ABB_wa_VRPC ((ABB_Read_Register_on_page(PAGE1,VRPCSIM) & 0xF4) | abbmask);
3002 while(count++ < 5) 3002 while(count++ < 5)
3003 { 3003 {
3004 if (ABB_Read_Register_on_page(PAGE1,VRPCSIM) & 0x04) // test RSIMRSU 3004 if (ABB_Read_Register_on_page(PAGE1,VRPCSIM) & 0x04) // test RSIMRSU
3005 return(SIM_OK); 3005 return(SIM_OK);
3006 ind_os_sleep(1); 3006 ind_os_sleep(1);
3007 } 3007 }
3008 // IOTA failure activation 3008 // IOTA failure activation
3009 return(SIM_ERR_HARDWARE_FAIL); 3009 return(SIM_ERR_HARDWARE_FAIL);
3010 #endif 3010 #endif
3011 #endif 3011 #endif
3062 3062
3063 SYS_UWORD8 SIM_SwitchVolt (SYS_UWORD8 ResetFlag) 3063 SYS_UWORD8 SIM_SwitchVolt (SYS_UWORD8 ResetFlag)
3064 { 3064 {
3065 SYS_UWORD8 count = 0; 3065 SYS_UWORD8 count = 0;
3066 SYS_UWORD8 abbmask; 3066 SYS_UWORD8 abbmask;
3067 3067
3068 SIM_PowerOff(); 3068 SIM_PowerOff();
3069 3069
3070 #if(ANLG_FAM == 1) 3070 #if(ANLG_FAM == 1)
3071 #if (SIM_TYPE == SIM_TYPE_3_5V) // shut down VCC from ABB and prepare to start at 5V mode 3071 #if (SIM_TYPE == SIM_TYPE_3_5V) // shut down VCC from ABB and prepare to start at 5V mode
3072 if (ResetFlag) { 3072 if (ResetFlag) {
3073 abbmask = MODE5V_OMEGA; 3073 abbmask = MODE5V_OMEGA;
3074 CurrentVolt = SIM_5V; 3074 CurrentVolt = SIM_5V;
3075 } 3075 }
3076 else { 3076 else {
3077 if (CurrentVolt == SIM_3V) 3077 if (CurrentVolt == SIM_3V)
3078 abbmask = MODE_INIT_OMEGA_3V; 3078 abbmask = MODE_INIT_OMEGA_3V;
3079 else 3079 else
3084 #endif 3084 #endif
3085 #elif(ANLG_FAM == 2) 3085 #elif(ANLG_FAM == 2)
3086 #if (SIM_TYPE == SIM_TYPE_1_8_3V) // shut down VCC from ABB and prepare to start at 3V mode 3086 #if (SIM_TYPE == SIM_TYPE_1_8_3V) // shut down VCC from ABB and prepare to start at 3V mode
3087 if (ResetFlag) { 3087 if (ResetFlag) {
3088 abbmask = MODE_INIT_IOTA_3V; 3088 abbmask = MODE_INIT_IOTA_3V;
3089 CurrentVolt = SIM_3V; 3089 CurrentVolt = SIM_3V;
3090 } 3090 }
3091 else { 3091 else {
3092 if (CurrentVolt == SIM_1_8V) 3092 if (CurrentVolt == SIM_1_8V)
3093 abbmask = MODE_INIT_IOTA_1_8V; 3093 abbmask = MODE_INIT_IOTA_1_8V;
3094 else 3094 else
3097 ABB_wa_VRPC ((ABB_Read_Register_on_page(PAGE1,VRPCSIM) & 0xF4) | abbmask); 3097 ABB_wa_VRPC ((ABB_Read_Register_on_page(PAGE1,VRPCSIM) & 0xF4) | abbmask);
3098 while(count++ < 5) 3098 while(count++ < 5)
3099 { 3099 {
3100 if (ABB_Read_Register_on_page(PAGE1,VRPCSIM) & 0x04) 3100 if (ABB_Read_Register_on_page(PAGE1,VRPCSIM) & 0x04)
3101 return(SIM_OK); 3101 return(SIM_OK);
3102 ind_os_sleep(1); 3102 ind_os_sleep(1);
3103 } 3103 }
3104 // IOTA failure activation 3104 // IOTA failure activation
3105 return(SIM_ERR_HARDWARE_FAIL); 3105 return(SIM_ERR_HARDWARE_FAIL);
3106 #endif 3106 #endif
3107 #elif(ANLG_FAM == 3) 3107 #elif(ANLG_FAM == 3)
3108 #if (SIM_TYPE == SIM_TYPE_1_8_3V) // shut down VCC from ABB and prepare to start at 3V mode 3108 #if (SIM_TYPE == SIM_TYPE_1_8_3V) // shut down VCC from ABB and prepare to start at 3V mode
3109 if (ResetFlag) { 3109 if (ResetFlag) {
3110 abbmask = MODE_INIT_SYREN_3V; 3110 abbmask = MODE_INIT_SYREN_3V;
3111 CurrentVolt = SIM_3V; 3111 CurrentVolt = SIM_3V;
3112 } 3112 }
3113 else { 3113 else {
3114 if (CurrentVolt == SIM_1_8V) 3114 if (CurrentVolt == SIM_1_8V)
3115 abbmask = MODE_INIT_SYREN_1_8V; 3115 abbmask = MODE_INIT_SYREN_1_8V;
3116 else 3116 else
3136 { 3136 {
3137 SYS_UWORD16 i; //unsigned short type counter chosen for copy of 256 bytes 3137 SYS_UWORD16 i; //unsigned short type counter chosen for copy of 256 bytes
3138 3138
3139 for (i = 0; i < len; i++) 3139 for (i = 0; i < len; i++)
3140 { 3140 {
3141 if (i == RSIMBUFSIZE) 3141 if (i == RSIMBUFSIZE)
3142 { 3142 {
3143 return (SIM_ERR_BUFF_OVERFL); 3143 return (SIM_ERR_BUFF_OVERFL);
3144 } 3144 }
3145 else 3145 else
3146 { 3146 {
3152 3152
3153 3153
3154 3154
3155 /* 3155 /*
3156 * SIM_SleepStatus 3156 * SIM_SleepStatus
3157 * 3157 *
3158 * Return SIM status for sleep manager 3158 * Return SIM status for sleep manager
3159 * 3159 *
3160 */ 3160 */
3161 SYS_BOOL SIM_SleepStatus(void) 3161 SYS_BOOL SIM_SleepStatus(void)
3162 { 3162 {
3163 if ((SIM_sleep_status == SIM_SLEEP_ACT) || (SIM_sleep_status == SIM_SLEEP_NONE)) 3163 if ((SIM_sleep_status == SIM_SLEEP_ACT) || (SIM_sleep_status == SIM_SLEEP_NONE))
3164 return(1); // SIM is ready for deep sleep 3164 return(1); // SIM is ready for deep sleep
3165 else 3165 else
3166 return(0); 3166 return(0);
3167 } 3167 }
3168 3168
3169 3169
3170 3170