diff 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
line wrap: on
line diff
--- a/src/cs/drivers/drv_app/sim/sim.c	Tue Jan 19 06:10:27 2021 +0000
+++ b/src/cs/drivers/drv_app/sim/sim.c	Sat Jan 30 06:34:22 2021 +0000
@@ -2,23 +2,23 @@
  * SIM.C
  *
  * Pole Star SIM
- *                 
+ *
  * Target : ARM
  *
  *
- * SIM card driver. This module contents all functions 
+ * SIM card driver. This module contents all functions
  * included in specifications GSM 11.11 V4.10
  *
  *
  * Copyright (c) Texas Instruments 1995-1997
  *
  */
-                                        
+
 #define SIM_C   1
 
 #ifndef _WINDOWS
-	#include "l1sw.cfg" 
-	#include "chipset.cfg" 
+	#include "l1sw.cfg"
+	#include "chipset.cfg"
 #endif
 
 #include "main/sys_types.h"
@@ -64,7 +64,7 @@
 /* working buffer for chronology calls */
 SYS_UWORD8  SIM_dbg_cmd[SIM_DBG_CMD];
 /* index for positionning in working buffer for chronology calls */
-SYS_UWORD16  SIM_dbg_cmd_cmpt;       
+SYS_UWORD16  SIM_dbg_cmd_cmpt;
 /* working variable to calculate the TDMA ecart */
 SYS_UWORD16 SIM_dbg_tdma_diff;
 /* working variable to store the maximum TDMA frame between two characters */
@@ -93,7 +93,7 @@
  *    SIM_WriteBuffer
  *    SIM_Command
  *    SIM_Reset
- *    
+ *
  */
 
 
@@ -105,7 +105,7 @@
  *   return the line, write first byte and let interrupt handler do the rest
  * return the line, write first byte and let interrupt handler do the rest
  *
- * Parameters : 
+ * Parameters :
  *   SIM_PORT *p : buffer for received chars
  *   offset      : starting point for reading data.
  *   n           : number of chars to read.
@@ -128,23 +128,23 @@
    if ((p->xIn - p->xOut) == 1)        //if only one char is transmitted
    {                                   //need to wait a minimum of 1 ETU
         ind_os_sleep (1);                  //for IO line to stay in TX mode
-   } 
-   // Write first byte 
+   }
+   // Write first byte
    p->c->tx = *(p->xOut);              // transmit
 
    if ((p->xIn - p->xOut) == 1)        //if only one char to transmit
    {                                   // return the direction to rx
         p->conf1 &= ~SIM_CONF1_TXRX;   //to be able to receive ACK char
-        p->c->conf1 = p->conf1;        
+        p->c->conf1 = p->conf1;
 
    }
 }
 
 /*
  * SIM_Result
- *    
+ *
  * Parameters : SIM port, buffer for received chars, pointer to receive size
- * 
+ *
  * Return the result code (SW1/SW2) at the end of the string
  */
 SYS_UWORD16 SIM_Result(SIM_PORT *p, SYS_UWORD8 *rP, SYS_UWORD16 *lenP, SYS_UWORD8 offset)
@@ -152,11 +152,11 @@
    SYS_UWORD8 sw1, sw2;
    SYS_UWORD8 verdict;
    SYS_UWORD16 len;
-   
+
    // Check if all characters were transmitted
    if (p->xIn - 1 != p->xOut)
       return (SIM_ERR_XMIT);
-   
+
    len = p->rx_index;
    *lenP = len - offset;
    if ((*lenP == 0) && (p->apdu_ans_length == 256))
@@ -166,7 +166,7 @@
    {
        verdict = SIM_Memcpy(rP, ((p->rbuf) + offset), 256 - offset);
        if (verdict != 0)
-       { 
+       {
            return (verdict);
        }
    }
@@ -178,8 +178,8 @@
            return (verdict);
        }
    }
-   
-   // change to remove SW1 and SW2 bytes from the receive buffer of data 
+
+   // change to remove SW1 and SW2 bytes from the receive buffer of data
    sw1 = p->rSW12[0];
    sw2 = p->rSW12[1];
 
@@ -204,7 +204,7 @@
  *             SIM_ERR_LEN  : the answer is not corresponding to a
  *                            correct answer of T=0 protocol
  * 06/11/2002	JYT
- *		Modified to be base command function. New SIM_Command() created to call it 
+ *		Modified to be base command function. New SIM_Command() created to call it
  * 		with wrapper. Created to manage retries on Internals errors of the driver.
  */
 
@@ -326,7 +326,7 @@
 
 
 /* Main function to manage the retry mechanism */
-SYS_UWORD16 SIM_Command(SIM_PORT *p, SYS_UWORD16 n, SYS_UWORD8 *dP, SYS_UWORD16 *lP) {   
+SYS_UWORD16 SIM_Command(SIM_PORT *p, SYS_UWORD16 n, SYS_UWORD8 *dP, SYS_UWORD16 *lP) {
 	int res;
 
 #ifdef SIM_DEBUG_TRACE
@@ -363,18 +363,18 @@
 
 
 
-                                
+
 /*
  * SIM_ByteReverse
  *
  * Reverse a byte, both up/down (1 <> 0) and left/right (0001 <> 1000)
- * 
+ *
  */
 SYS_UWORD8 SIM_ByteReverse(SYS_UWORD8 b)
 {
     SYS_UWORD8 bh, bl;
     int i;
-    const SYS_UWORD8 Reverse[] = {0x0, 0x8, 0x4, 0xC, 0x2, 0xA, 0x6, 0xE, 
+    const SYS_UWORD8 Reverse[] = {0x0, 0x8, 0x4, 0xC, 0x2, 0xA, 0x6, 0xE,
                                     0x1, 0x9, 0x5, 0xD, 0x3, 0xB, 0x7, 0xF };
 
     // Up/Down
@@ -383,10 +383,10 @@
     // left / right (by nibble)
     bh = (b >> 4) & 0xF;
     bl = b & 0xF;
-      
+
     b = (Reverse[bl]) << 4 | Reverse[bh];
     return(b);
-   
+
 }
 
 /*
@@ -409,20 +409,20 @@
 /*
  * SIM_Reset
  *
- * Reset SIM card 
+ * Reset SIM card
  * Call-back SIM insert if successful
  * or SIM remove otherwise
  *
  * Returns 0 for success, or
  *         SIM_ERR_NOCARD : no card
  *         SIM_ERR_NATR   : no answer to reset
- *         SIM_ERR_NOINT  : no 
+ *         SIM_ERR_NOINT  : no
  *         SIM_ERR_READ   : unknown data return by the card
  *         SIM_ERR_CARDREJECT : card not accepted
  *
  * 29/01/02, JYT, adding of low voltage managment for IOTA device
  * 06/10/03, JYT, Split of Reset to handle Restart
- */ 
+ */
 SYS_UWORD16 SIM_Reset(SIM_CARD *cP)
 {
 	return(SIM_Reset_Restart_Internal(cP, 1));
@@ -437,17 +437,17 @@
 /*
  * SIM_Restart
  *
- * Restart SIM card 
+ * Restart SIM card
  *
  * Returns 0 for success, or
  *         SIM_ERR_NOCARD : no card
  *         SIM_ERR_NATR   : no answer to reset
- *         SIM_ERR_NOINT  : no 
+ *         SIM_ERR_NOINT  : no
  *         SIM_ERR_READ   : unknown data return by the card
  *         SIM_ERR_CARDREJECT : card not accepted
  *
  * 06/10/03, JYT, Split of Reset to handle Restart
- */ 
+ */
 SYS_UWORD16 SIM_Restart(SIM_CARD *cP)
 {
 	return(SIM_Reset_Restart_Internal(cP, 0));
@@ -457,20 +457,20 @@
 /*
  * SIM_Reset_Restart_Internal
  *
- * Reset SIM card 
+ * Reset SIM card
  * Call-back SIM insert if successful
  * or SIM remove otherwise
- *							  
+ *
  * Returns 0 for success, or
  *         SIM_ERR_NOCARD : no card
  *         SIM_ERR_NATR   : no answer to reset
- *         SIM_ERR_NOINT  : no 
+ *         SIM_ERR_NOINT  : no
  *         SIM_ERR_READ   : unknown data return by the card
  *         SIM_ERR_CARDREJECT : card not accepted
  *
  * 29/01/02, JYT, adding of low voltage managment for IOTA device
  * 06/10/03, JYT, Split of Reset to handle Restart, ResetFlag added.
- */ 
+ */
 SYS_UWORD16 SIM_Reset_Restart_Internal(SIM_CARD *cP, SYS_UWORD8 ResetFlag)
 {
     SIM_PORT        *p;
@@ -484,7 +484,7 @@
 	memset(SIM_dbg_cmd, 0x00, SIM_DBG_CMD);
 #endif
 
-    // Initialize pointers 
+    // Initialize pointers
     p = &(Sim[0]);
 
 // begin of JYT modifications
@@ -503,8 +503,8 @@
     p->SWcount       = 0;
     p->Freq_Algo     = 0;
     p->PTS_Try       = 0;            //use to calculate how many PTS try were already done
-    
-    // Initialize pointers 
+
+    // Initialize pointers
     p->xIn   = p->xOut = p->xbuf;
     p->rx_index        = 0;
     p->errorSIM        = 0;
@@ -514,14 +514,14 @@
     BackValue = SIM_ManualStart(p);
     if (BackValue != 0)
         return ((SYS_UWORD16)BackValue);
-    
-      
-    p->c->conf1 = p->conf1 &= ~SIM_CONF1_BYPASS;      //switch to automatic mode             
+
+
+    p->c->conf1 = p->conf1 &= ~SIM_CONF1_BYPASS;      //switch to automatic mode
 
 //#else //SW_WRK_AROUND_H_S == 0 // Automatic procedure -> fails with test 27.11.2.1
 //
 //                                  // Mask all interrupts
-//    p->c->maskit = SIM_MASK_NATR | SIM_MASK_WT | SIM_MASK_OV | 
+//    p->c->maskit = SIM_MASK_NATR | SIM_MASK_WT | SIM_MASK_OV |
 //                   SIM_MASK_TX | SIM_MASK_RX | SIM_MASK_CD;
 //
 //
@@ -530,7 +530,7 @@
 //
 //    p->c->cmd = (p->c->cmd & MASK_CMD) | SIM_CMD_STOP;
 //    ind_os_sleep(1);
-//                      
+//
 //    p->c->cmd = (p->c->cmd & MASK_CMD) | SIM_CMD_SWRST;    // Set START bit and wait a while
 //    ind_os_sleep(1);
 //                                  // Unmask all sources of interrupts except WT, OV, and NATR
@@ -548,7 +548,7 @@
 //        #endif
 //    p->c->cmd = (p->c->cmd & MASK_CMD) | SIM_CMD_START;
 //
-//#endif 
+//#endif
 
 /*-----------------------------------------------------------*/
 
@@ -566,7 +566,7 @@
             }
             // ATR received but wrong characters value
             // Comply with Test 27.11.2.4.5 and Test 27.11.1.3
-            else if (BackValue == SIM_ERR_CARDREJECT)            
+            else if (BackValue == SIM_ERR_CARDREJECT)
                 {
                 if (ATR_Attempt >= 3)
             {
@@ -577,24 +577,24 @@
                 ATR_Attempt++;
                 SIM_WARMReset(p);    // assert a reset during at least 400 ETU
         }
-            else if (BackValue != 0) //SIM_ERR_WAIT           
+            else if (BackValue != 0) //SIM_ERR_WAIT
         {
                 if (ATR_Attempt == 3)
                 {    // switch to 5V (ANALOG1) or 3V (ANALOG2) if card send wrong ATR 3 consecutive times
                      // Apply 3 consecutive resets at 5V (ANALOG1) or 3V (ANALOG2)
-                     // fix prb for old chinese card not GSM compliant   
-
-                     if ((BackValue = SIM_SwitchVolt(ResetFlag)) != SIM_OK) 
+                     // fix prb for old chinese card not GSM compliant
+
+                     if ((BackValue = SIM_SwitchVolt(ResetFlag)) != SIM_OK)
                      {
                      	// SIM cannot be supplied at 3V (ANALOG2), because of an Hardware failure
                      	SIM_PowerOff ();
                         return((SYS_UWORD16)BackValue);
-                     }   
-                     
-                     ATR_Attempt++;  
-                     goto COLD_RESET;  
+                     }
+
+                     ATR_Attempt++;
+                     goto COLD_RESET;
                 }
-                if (ATR_Attempt >= 6) 
+                if (ATR_Attempt >= 6)
                 {
                     SIM_PowerOff ();
                     return ((SYS_UWORD16)BackValue);
@@ -603,17 +603,17 @@
                 ATR_Attempt++;
                 SIM_WARMReset(p);    // assert a reset during at least 400 ETU
             }
-            
+
             else
             {
-                ATR_Attempt = 0;    
+                ATR_Attempt = 0;
             }
         }
 /*-----------------------------------------------------------*/
 // PTS procedure
         BackValue = SIM_PTSprocedure(cP,p);      //assert PTS if needed
 //        need upgrade with FIFO use to avoid CPU overloading
-              
+
         if (BackValue)
         {
             if (BackValue == SIM_ERR_CARDREJECT)
@@ -621,10 +621,10 @@
                 SIM_PowerOff ();      //must be done by protocol stack
                 return (SIM_ERR_CARDREJECT);
             }
-            if (p->PTS_Try <= 4)     //else error treatement  
+            if (p->PTS_Try <= 4)     //else error treatement
             {
                 SIM_WARMReset(p);    // assert a reset during at least 400 ETU
-            }            
+            }
         }
         else
         {
@@ -653,59 +653,59 @@
     {
 #if ((SIM_TYPE == SIM_TYPE_3V ) || (SIM_TYPE == SIM_TYPE_1_8_3V) || (SIM_TYPE == SIM_TYPE_1_8V))
         SIM_PowerOff ();                 // required by ETSI if 5V only card is detected and 3V only ME chosen
-        return (SIM_ERR_CARDREJECT);     // Test 27.17.1.5.2    
-#elif (SIM_TYPE == SIM_TYPE_3_5V)  
+        return (SIM_ERR_CARDREJECT);     // Test 27.17.1.5.2
+#elif (SIM_TYPE == SIM_TYPE_3_5V)
         if (CurrentVolt == SIM_3V) //if 5V only SIM present -> the ME may switch to 5V operation
         {
             if ((BackValue = SIM_SwitchVolt(ResetFlag)) != SIM_OK) // switch to 5V
             {
                SIM_PowerOff ();
                return ((SYS_UWORD16)BackValue);
-            }	
+            }
             ATR_Attempt      = 1;
-            goto COLD_RESET;            // Test 27.17.1.5.3 
+            goto COLD_RESET;            // Test 27.17.1.5.3
         }
-#endif              
+#endif
     }
-    else 
+    else
     {
        if ((p->FileC & SIM_MASK_INFO_VOLT) == SIM_3V)
        {
 #if (SIM_TYPE == SIM_TYPE_1_8V)
         SIM_PowerOff ();                 // required by ETSI if 3V only card is detected and 1.8V only ME chosen
-        return (SIM_ERR_CARDREJECT);     // Test 27.17.1.5.2    
-#elif (SIM_TYPE == SIM_TYPE_1_8_3V)  
+        return (SIM_ERR_CARDREJECT);     // Test 27.17.1.5.2
+#elif (SIM_TYPE == SIM_TYPE_1_8_3V)
         if (CurrentVolt == SIM_1_8V) //if 3V only SIM present -> the ME may switch to 3V operation
         {
             if ((BackValue = SIM_SwitchVolt(ResetFlag)) != SIM_OK) // switch to 3V
             {
                SIM_PowerOff ();
                return ((SYS_UWORD16)BackValue);
-            }	
+            }
             ATR_Attempt      = 1;
-            goto COLD_RESET;            // Test 27.17.1.5.3 
+            goto COLD_RESET;            // Test 27.17.1.5.3
         }
-#endif                     	
+#endif
        }
-       else 
+       else
        {
           if ((p->FileC & SIM_MASK_INFO_VOLT) == SIM_1_8V)
           {
 #if (SIM_TYPE == SIM_TYPE_5V)
               SIM_PowerOff ();                 // required by ETSI if 5V only card is detected and 3V only ME chosen
-              return (SIM_ERR_CARDREJECT);     // Test 27.17.1.5.2    
-#endif                        	
+              return (SIM_ERR_CARDREJECT);     // Test 27.17.1.5.2
+#endif
           }
-          else 
+          else
           {
        	      // future class of sim card voltage !!!!!! never use it
        	      SIM_PowerOff ();                 // Rec. 11.18
-              return (SIM_ERR_CARDREJECT);     
-          }          
+              return (SIM_ERR_CARDREJECT);
+          }
        }
-    }      
-
-    SIM_Interpret_FileCharacteristics(p);      //find which frequency (13/4 or 13/8 Mhz) 
+    }
+
+    SIM_Interpret_FileCharacteristics(p);      //find which frequency (13/4 or 13/8 Mhz)
 
     if(p->errorSIM)
     {
@@ -716,7 +716,7 @@
     //enable starting of the os timer for sleep mode
     if (ResetFlag) {
     if (p->InsertFunc != NULL)
-       (p->InsertFunc)(cP);   
+       (p->InsertFunc)(cP);
 	}
 
      return(0);
@@ -746,26 +746,26 @@
 //!!
     p->c->conf1 = p->conf1 = 0x8004;   //set conf1 to automatic mode SIO low
     //enable sim interface clock module
-    p->c->cmd = SIM_CMD_CLKEN;    
+    p->c->cmd = SIM_CMD_CLKEN;
 
 //#if (SW_WRK_AROUND_H_S == 1)
 
     // Mask all interrupts
-    p->c->maskit = SIM_MASK_NATR | SIM_MASK_WT | SIM_MASK_OV | 
+    p->c->maskit = SIM_MASK_NATR | SIM_MASK_WT | SIM_MASK_OV |
            SIM_MASK_TX | SIM_MASK_RX | SIM_MASK_CD;
 
     // Unmask interrupt controller
     IQ_Unmask (IQ_SIM);
 
     p->c->cmd = (p->c->cmd & MASK_CMD) | SIM_CMD_STOP;
-    ind_os_sleep (4);                           //wait 5 TDMA due to SVCC falling down duration 
+    ind_os_sleep (4);                           //wait 5 TDMA due to SVCC falling down duration
 
     p->c->cmd = (p->c->cmd & MASK_CMD) | SIM_CMD_SWRST;
-    ind_os_sleep (1);                           //wait 5 TDMA due to SVCC falling down duration 
+    ind_os_sleep (1);                           //wait 5 TDMA due to SVCC falling down duration
 
 
     p->c->conf2  = 0x0940;
-    
+
     i = p->c->it;
     // Unmask all sources of interrupts except WT and OV and NATR
     p->c->maskit = SIM_MASK_WT | SIM_MASK_OV | SIM_MASK_NATR;
@@ -778,14 +778,14 @@
     p->c->conf1 = p->conf1 |= SIM_CONF1_SVCCLEV;
     ind_os_sleep(1);
 
-    #if(ANLG_FAM == 1) 
+    #if(ANLG_FAM == 1)
       //set OMEGA to 3V mode
       //enable VCC
       ABB_wa_VRPC (ABB_Read_Register_on_page(PAGE1,VRPCCTRL1) | MODE_ENA_SIMLDOEN);
       ind_os_sleep(1);
       ABB_wa_VRPC (ABB_Read_Register_on_page(PAGE1,VRPCCTRL1) | MODE_ENA_SIMEN);
       ind_os_sleep(1);
-    #elif(ANLG_FAM == 2) 
+    #elif(ANLG_FAM == 2)
       //set IOTA to 3V mode
       //enable VCC
       ABB_wa_VRPC (ABB_Read_Register_on_page(PAGE1,VRPCSIM) | MODE_ENA_SIMEN);
@@ -816,8 +816,8 @@
     {
         ind_os_sleep (1);
         i++;
-    }        
-      
+    }
+
     if ((p->rx_index == 0) && (i >= 3))         //external reset card ATR treatement
     {
         i = 0;
@@ -833,7 +833,7 @@
 
     return (0);
 }
- 
+
 /* SIM manual stop
 *
 *  purpose : manage manual start of the SIM interface
@@ -846,7 +846,7 @@
 // to write
 }
 
-/* Power off SIM == SIM_CMD_STOP 
+/* Power off SIM == SIM_CMD_STOP
 *  input  : none
 *  output : none
 */
@@ -858,7 +858,7 @@
 
 
 
-    // Initialize pointers 
+    // Initialize pointers
     p = &(Sim[0]);
 
 
@@ -868,11 +868,11 @@
 
     ind_os_sleep(5);    //wait for falling of SIM signals (RESET/CLK/IO)
 
-    #if(ANLG_FAM == 1) 
+    #if(ANLG_FAM == 1)
       //disable VCC : disable level shifter then SVDD
       ABB_wa_VRPC (ABB_Read_Register_on_page(PAGE1,VRPCCTRL1) & MODE_DIS_SIMEN);
       ABB_wa_VRPC (ABB_Read_Register_on_page(PAGE1,VRPCCTRL1) & MODE_DIS_SIMLDOEN);
-    #elif(ANLG_FAM == 2) 
+    #elif(ANLG_FAM == 2)
       //disable VCC : disable level shifter then SVDD
       ABB_wa_VRPC (ABB_Read_Register_on_page(PAGE1,VRPCSIM) & MODE_DIS_SIMEN);
       ABB_wa_VRPC (ABB_Read_Register_on_page(PAGE1,VRPCSIM) & MODE_DIS_SIMLDOEN);
@@ -922,7 +922,7 @@
     /* FreeCalypso addition */
     ffs_file_read("/etc/SIM_spenh", &SIM_allow_speed_enhancement, 1);
 
-    // Initialize registers 
+    // Initialize registers
     p = &(Sim[0]);
     p->c = (SIM_CONTROLLER *) SIM_CMD;
 
@@ -934,7 +934,7 @@
     //timer start only with NU_Control_Timer function
     //waiting time set to 2.3s
     SIM_sleep_status = SIM_SLEEP_NONE;
-    
+
 #ifdef SIM_RETRY
     SimRetries = 0;
 #endif
@@ -954,7 +954,7 @@
 {
     SIM_PORT *p;
 
-    // Initialize pointers 
+    // Initialize pointers
     p = &(Sim[0]);
 
     p->InsertFunc = Insert;
@@ -968,7 +968,7 @@
  * High level routines : mapped to GSM 11.11 function calls
  *
  * Uses a Nucleus semaphore to ensure no simultaneous access to SIM and buffer
- *    
+ *
  * Each routine does :
  *    write command
  *    sleep long enough for the expected transmission and reception
@@ -977,9 +977,9 @@
  *    SYS_UWORD8 *result :  pointer to the string return by the SIM card
  *    SYS_UWORD8 *rcvSize : size of the string return by the SIM card
  *
- *    other parameters : parameters needed by the SIM card to 
+ *    other parameters : parameters needed by the SIM card to
  *                       execute the function.
- *   
+ *
  */
 //unsigned char SIM_flag = 0;
 
@@ -993,19 +993,19 @@
 {
     SIM_PORT *p;
     int res;
-	
+
     p = &(Sim[0]);
 
     p->xbuf[0] = GSM_CLASS;
-    p->xbuf[1] = SIM_SELECT; 
+    p->xbuf[1] = SIM_SELECT;
     p->xbuf[2] = 0;
     p->xbuf[3] = 0;
-    p->xbuf[4] = 2; 
+    p->xbuf[4] = 2;
     p->xbuf[5] = id >> 8;       // high byte
     p->xbuf[6] = id & 0xFF;     // low byte
 
 
-    res = SIM_Command(p, 2, dat, rcvSize);   
+    res = SIM_Command(p, 2, dat, rcvSize);
     /* Change from to 10 to 15 for specific SIM card (Racal) */
 
 //	if (id == 0x6F07)
@@ -1032,7 +1032,7 @@
 
 /*
  * SIM_Status
- *    
+ *
  *  Returns data received from card and number of bytes received
  */
 SYS_UWORD16 SIM_Status(SYS_UWORD8 *dat, SYS_UWORD16 *rcvSize)
@@ -1048,7 +1048,7 @@
     p->xbuf[1] = SIM_STATUS;
     p->xbuf[2] = 0;
     p->xbuf[3] = 0;
-    p->xbuf[4] = len; 
+    p->xbuf[4] = len;
 
     res = SIM_Command(p, 0, dat, rcvSize);
 
@@ -1072,7 +1072,7 @@
 
 /*
  * SIM_Status_Extended
- *    
+ *
  *  Returns data received from card and number of bytes received
  *  Add extra parameter len : number of returned byte
  */
@@ -1088,7 +1088,7 @@
     p->xbuf[1] = SIM_STATUS;
     p->xbuf[2] = 0;
     p->xbuf[3] = 0;
-    p->xbuf[4] = (SYS_UWORD8)llen; 
+    p->xbuf[4] = (SYS_UWORD8)llen;
 
     res = SIM_Command(p, 0, dat, rcvSize);
 
@@ -1126,9 +1126,9 @@
 
     p->xbuf[0] = GSM_CLASS;
     p->xbuf[1] = SIM_READ_BINARY;
-    p->xbuf[2] = offset >> 8; 
-    p->xbuf[3] = offset & 0xFF; 
-    p->xbuf[4] = (SYS_UWORD8)llen; 
+    p->xbuf[2] = offset >> 8;
+    p->xbuf[3] = offset & 0xFF;
+    p->xbuf[4] = (SYS_UWORD8)llen;
 
     res = SIM_Command(p, 0, dat, rcvSize);
 
@@ -1136,7 +1136,7 @@
 //		SIM_flag = 0;
 //		dat[0] = 0x08;
 //	}
-		
+
 #ifdef SIM_DEBUG_TRACE
 	SIM_dbg_write_trace((SYS_UWORD8 *)"ADCMD", 5);
 	SIM_dbg_write_trace(p->xbuf, 5);
@@ -1178,9 +1178,9 @@
 
     p->xbuf[0] = GSM_CLASS;
     p->xbuf[1] = SIM_VERIFY_CHV;
-    p->xbuf[2] = 0; 
-    p->xbuf[3] = chvType; 
-    p->xbuf[4] = len; 
+    p->xbuf[2] = 0;
+    p->xbuf[3] = chvType;
+    p->xbuf[4] = len;
     for (i=0;i<8;i++)
     {
       p->xbuf[5+i] = *(dat+i);
@@ -1231,9 +1231,9 @@
 
     p->xbuf[0] = GSM_CLASS;
     p->xbuf[1] = SIM_RUN_GSM_ALGO;
-    p->xbuf[2] = 0; 
-    p->xbuf[3] = 0; 
-    p->xbuf[4] = len; 
+    p->xbuf[2] = 0;
+    p->xbuf[3] = 0;
+    p->xbuf[4] = len;
 
     for (i=0;i<len;i++)
     {
@@ -1285,9 +1285,9 @@
 
     p->xbuf[0] = GSM_CLASS;
     p->xbuf[1] = SIM_GET_RESPONSE;
-    p->xbuf[2] = 0; 
-    p->xbuf[3] = 0; 
-    p->xbuf[4] = (SYS_UWORD8)llen; 
+    p->xbuf[2] = 0;
+    p->xbuf[3] = 0;
+    p->xbuf[4] = (SYS_UWORD8)llen;
 
     res = SIM_Command(p, 0, dat, rcvSize);
 
@@ -1331,9 +1331,9 @@
 
     p->xbuf[0] = GSM_CLASS;
     p->xbuf[1] = SIM_CHANGE_CHV;
-    p->xbuf[2] = 0; 
-    p->xbuf[3] = chvType; 
-    p->xbuf[4] = (SYS_UWORD8)len; 
+    p->xbuf[2] = 0;
+    p->xbuf[3] = chvType;
+    p->xbuf[4] = (SYS_UWORD8)len;
 
     // Copy bytes to buffer
     for (i=0;i<8;i++)
@@ -1386,14 +1386,14 @@
     len = 8;
     p->xbuf[0] = GSM_CLASS;
     p->xbuf[1] = SIM_DISABLE_CHV;
-    p->xbuf[2] = 0; 
-    p->xbuf[3] = 1; 
-    p->xbuf[4] = 8; 
+    p->xbuf[2] = 0;
+    p->xbuf[3] = 1;
+    p->xbuf[4] = 8;
     for (i=0;i<8;i++)
     {
       p->xbuf[5+i] = *(dat+i);
     }
-    res = SIM_Command(p, len, result, lP);        
+    res = SIM_Command(p, len, result, lP);
 
 #ifdef SIM_DEBUG_TRACE
 	SIM_dbg_write_trace((SYS_UWORD8 *)"AICMD", 5);
@@ -1437,9 +1437,9 @@
 
     p->xbuf[0] = GSM_CLASS;
     p->xbuf[1] = SIM_ENABLE_CHV;
-    p->xbuf[2] = 0; 
-    p->xbuf[3] = 1; 
-    p->xbuf[4] = (SYS_UWORD8)len; 
+    p->xbuf[2] = 0;
+    p->xbuf[3] = 1;
+    p->xbuf[4] = (SYS_UWORD8)len;
 
     for (i=0;i<len;i++)
     {
@@ -1478,7 +1478,7 @@
  * Unblock the specified CHV (chvType) and store a new CHV
  */
 SYS_UWORD16 SIM_UnblockCHV(SYS_UWORD8 *result, SYS_UWORD8 *unblockChv, SYS_UWORD8 *newChv,
-                      SYS_UWORD8 chvType, SYS_UWORD16 *lP) 
+                      SYS_UWORD8 chvType, SYS_UWORD16 *lP)
 {
     SIM_PORT *p;
     int len;
@@ -1492,7 +1492,7 @@
     p->xbuf[1] = SIM_UNBLOCK_CHV;
     p->xbuf[2] = 0;
     p->xbuf[3] = chvType;
-    p->xbuf[4] = (SYS_UWORD8)len; 
+    p->xbuf[4] = (SYS_UWORD8)len;
     for (i=0;i<8;i++)
     {
       p->xbuf[5+i] = *(unblockChv+i);
@@ -1540,9 +1540,9 @@
 
     p->xbuf[0] = GSM_CLASS;
     p->xbuf[1] = SIM_INVALIDATE;
-    p->xbuf[2] = 0; 
-    p->xbuf[3] = 0; 
-    p->xbuf[4] = 0; 
+    p->xbuf[2] = 0;
+    p->xbuf[3] = 0;
+    p->xbuf[4] = 0;
 
     res = SIM_Command(p, 0, rP, lP);
 
@@ -1582,11 +1582,11 @@
 
     p->xbuf[0] = GSM_CLASS;
     p->xbuf[1] = SIM_REHABILITATE;
-    p->xbuf[2] = 0; 
-    p->xbuf[3] = 0; 
+    p->xbuf[2] = 0;
+    p->xbuf[3] = 0;
     p->xbuf[4] = 0;
 
-    res = SIM_Command(p, 0, rP, lP);        
+    res = SIM_Command(p, 0, rP, lP);
 
 #ifdef SIM_DEBUG_TRACE
 	SIM_dbg_write_trace((SYS_UWORD8 *)"AMCMD", 5);
@@ -1628,15 +1628,15 @@
 
     p->xbuf[0] = GSM_CLASS;
     p->xbuf[1] = SIM_UPDATE_BINARY;
-    p->xbuf[2] = offset >> 8; 
-    p->xbuf[3] = offset & 0xFF; 
-    p->xbuf[4] = (SYS_UWORD8)llen; 
+    p->xbuf[2] = offset >> 8;
+    p->xbuf[3] = offset & 0xFF;
+    p->xbuf[4] = (SYS_UWORD8)llen;
 
     for (i=0;i<llen;i++)
     {
       p->xbuf[5+i] = *(dat+i);
     }
-    res = SIM_Command(p, llen, result, rcvSize);        
+    res = SIM_Command(p, llen, result, rcvSize);
 
 #ifdef SIM_DEBUG_TRACE
 	SIM_dbg_write_trace((SYS_UWORD8 *)"ANCMD", 5);
@@ -1677,11 +1677,11 @@
 
     p->xbuf[0] = GSM_CLASS;
     p->xbuf[1] = SIM_READ_RECORD;
-    p->xbuf[2] = recNum; 
-    p->xbuf[3] = mode; 
-    p->xbuf[4] = (SYS_UWORD8)llen; 
-
-    res = SIM_Command(p, 0, dat, rcvSize);        
+    p->xbuf[2] = recNum;
+    p->xbuf[3] = mode;
+    p->xbuf[4] = (SYS_UWORD8)llen;
+
+    res = SIM_Command(p, 0, dat, rcvSize);
 
 #ifdef SIM_DEBUG_TRACE
 	SIM_dbg_write_trace((SYS_UWORD8 *)"AOCMD", 5);
@@ -1842,16 +1842,16 @@
 
     p->xbuf[0] = GSM_CLASS;
     p->xbuf[1] = SIM_UPDATE_RECORD;
-    p->xbuf[2] = recNum; 
-    p->xbuf[3] = mode; 
-    p->xbuf[4] = (SYS_UWORD8)llen; 
+    p->xbuf[2] = recNum;
+    p->xbuf[3] = mode;
+    p->xbuf[4] = (SYS_UWORD8)llen;
 
     for (i=0;i<llen;i++)
     {
         p->xbuf[5+i] = *(dat+i);
     }
 
-    res = SIM_Command(p, llen, result, rcvSize);        
+    res = SIM_Command(p, llen, result, rcvSize);
 
 #ifdef SIM_DEBUG_TRACE
 	SIM_dbg_write_trace((SYS_UWORD8 *)"APCMD", 5);
@@ -1905,16 +1905,16 @@
 
    p->xbuf[0] = GSM_CLASS;
    p->xbuf[1] = SIM_SEEK;
-   p->xbuf[2] = 0; 
-   p->xbuf[3] = mode; 
-   p->xbuf[4] = (SYS_UWORD8)llen; 
+   p->xbuf[2] = 0;
+   p->xbuf[3] = mode;
+   p->xbuf[4] = (SYS_UWORD8)llen;
 
    for (i=0;i<llen;i++)
    {
       p->xbuf[5+i] = *(dat+i);
    }
 
-   res = SIM_Command(p, llen, result, rcvSize);        
+   res = SIM_Command(p, llen, result, rcvSize);
 
 #ifdef SIM_DEBUG_TRACE
 	SIM_dbg_write_trace((SYS_UWORD8 *)"AQCMD", 5);
@@ -1956,16 +1956,16 @@
 
     p->xbuf[0] = GSM_CLASS;
     p->xbuf[1] = SIM_INCREASE;
-    p->xbuf[2] = 0; 
-    p->xbuf[3] = 0; 
-    p->xbuf[4] = 3; 
+    p->xbuf[2] = 0;
+    p->xbuf[3] = 0;
+    p->xbuf[4] = 3;
 
     for (i=0;i<3;i++)
     {
         p->xbuf[5+i] = *(dat+i);
     }
 
-    res = SIM_Command(p, len, result, rcvSize);        
+    res = SIM_Command(p, len, result, rcvSize);
 
 #ifdef SIM_DEBUG_TRACE
 	SIM_dbg_write_trace((SYS_UWORD8 *)"ARCMD", 5);
@@ -2005,16 +2005,16 @@
 
     p->xbuf[0] = GSM_CLASS;
     p->xbuf[1] = SIM_TERMINAL_PROFILE;
-    p->xbuf[2] = 0; 
-    p->xbuf[3] = 0; 
-    p->xbuf[4] = (SYS_UWORD8)llen; 
+    p->xbuf[2] = 0;
+    p->xbuf[3] = 0;
+    p->xbuf[4] = (SYS_UWORD8)llen;
 
     for (i=0;i<llen;i++)
     {
         p->xbuf[5+i] = *(dat+i);
     }
 
-    res = SIM_Command(p, llen, result, rcvSize);        
+    res = SIM_Command(p, llen, result, rcvSize);
 
 #ifdef SIM_DEBUG_TRACE
 	SIM_dbg_write_trace((SYS_UWORD8 *)"ASCMD", 5);
@@ -2051,12 +2051,12 @@
 
     p->xbuf[0] = GSM_CLASS;
     p->xbuf[1] = SIM_FETCH;
-    p->xbuf[2] = 0; 
-    p->xbuf[3] = 0; 
-    p->xbuf[4] = (SYS_UWORD8)llen; 
-
-
-    res = SIM_Command(p, 0, result, rcvSize);        
+    p->xbuf[2] = 0;
+    p->xbuf[3] = 0;
+    p->xbuf[4] = (SYS_UWORD8)llen;
+
+
+    res = SIM_Command(p, 0, result, rcvSize);
 
 #ifdef SIM_DEBUG_TRACE
 	SIM_dbg_write_trace((SYS_UWORD8 *)"ATCMD", 5);
@@ -2096,16 +2096,16 @@
 
     p->xbuf[0] = GSM_CLASS;
     p->xbuf[1] = SIM_TERMINAL_RESPONSE;
-    p->xbuf[2] = 0; 
-    p->xbuf[3] = 0; 
-    p->xbuf[4] = (SYS_UWORD8)llen; 
+    p->xbuf[2] = 0;
+    p->xbuf[3] = 0;
+    p->xbuf[4] = (SYS_UWORD8)llen;
 
     for (i=0;i<llen;i++)
     {
         p->xbuf[5+i] = *(dat+i);
     }
 
-    res = SIM_Command(p, llen, result, rcvSize);        
+    res = SIM_Command(p, llen, result, rcvSize);
 
 #ifdef SIM_DEBUG_TRACE
 	SIM_dbg_write_trace((SYS_UWORD8 *)"AUCMD", 5);
@@ -2142,16 +2142,16 @@
 
     p->xbuf[0] = GSM_CLASS;
     p->xbuf[1] = SIM_ENVELOPE;
-    p->xbuf[2] = 0; 
-    p->xbuf[3] = 0; 
-    p->xbuf[4] = (SYS_UWORD8)llen; 
+    p->xbuf[2] = 0;
+    p->xbuf[3] = 0;
+    p->xbuf[4] = (SYS_UWORD8)llen;
 
     for (i=0;i<llen;i++)
     {
         p->xbuf[5+i] = *(dat+i);
     }
 
-    res = SIM_Command(p, llen, result, rcvSize);        
+    res = SIM_Command(p, llen, result, rcvSize);
 
 #ifdef SIM_DEBUG_TRACE
 	SIM_dbg_write_trace((SYS_UWORD8 *)"AVCMD", 5);
@@ -2198,9 +2198,9 @@
 
     p->xbuf[0] = dat[0];
     p->xbuf[1] = dat[1];
-    p->xbuf[2] = dat[2]; 
-    p->xbuf[3] = dat[3]; 
-    p->xbuf[4] = dat[4]; 
+    p->xbuf[2] = dat[2];
+    p->xbuf[3] = dat[3];
+    p->xbuf[4] = dat[4];
 
     for (i=5;i<trxLen;i++)
     {
@@ -2210,11 +2210,11 @@
 	// enable the WIM behavior of the sim driver
    	p->apdu_ans_length = rcvLen;
 
-    res = SIM_Command(p, (trxLen - 5), result, rcvSize);        
+    res = SIM_Command(p, (trxLen - 5), result, rcvSize);
 
 	// disable the WIM behavior of the sim driver
    	p->apdu_ans_length = 0;
-	
+
 #ifdef SIM_DEBUG_TRACE
 	SIM_dbg_write_trace((SYS_UWORD8 *)"AWCMD", 5);
 	SIM_dbg_write_trace(p->xbuf, trxLen);
@@ -2262,18 +2262,18 @@
     //analyse the nature of the command to execute
 
     if (
-    	(p->xbuf[1] == 0x12) || 
-    	(p->xbuf[1] == 0xB2) || 
-    	(p->xbuf[1] == 0xB0) || 
-    	(p->xbuf[1] == 0xF2) || 
-    	(p->xbuf[1] == 0xC0) || 
+    	(p->xbuf[1] == 0x12) ||
+    	(p->xbuf[1] == 0xB2) ||
+    	(p->xbuf[1] == 0xB0) ||
+    	(p->xbuf[1] == 0xF2) ||
+    	(p->xbuf[1] == 0xC0) ||
     	(p->apdu_ans_length != 0)
-       )       
+       )
     //FETCH, READ_RECORD, READ_BINARY, STATUS, GET_RESPONSE commands == receive command
     {
         if (p->xbuf[4] == 0)                    //if P3 == 0 when sending receive command
         {
-            p->expected_data = 256; 
+            p->expected_data = 256;
         }
         else
         {
@@ -2320,8 +2320,8 @@
     res = SIM_Select(DF_GSM, ubuf, &sz);
     if ((res & 0xFF00) != 0x9F00)
     {
-        res = SIM_Select(DF_DCS1800, ubuf, &sz);                                        
-        if ((res & 0xFF00) != 0x9F00)                                
+        res = SIM_Select(DF_DCS1800, ubuf, &sz);
+        if ((res & 0xFF00) != 0x9F00)
         {
             return (1);
         }
@@ -2332,23 +2332,23 @@
 
     p->FileC = ubuf[13];
     return (0);
-}  
-  
+}
+
 /*
 * Use to determine value of b2 in file caracteristics contained in response
 * of SELECT Master File command
 * return    0 if no preferred speed during authentication
-*           1 if 13/4Mhz mandatory 
+*           1 if 13/4Mhz mandatory
 *
 *
 */
- 
+
 void SIM_Interpret_FileCharacteristics(SIM_PORT *p)
 {
     //interpret b2 bit for operating authentication speed
-    if((p->conf1 & 0x0020) && (p->FileC & 0x02))  
+    if((p->conf1 & 0x0020) && (p->FileC & 0x02))
     {
-        p->Freq_Algo = 1;                                 
+        p->Freq_Algo = 1;
     }
 
     //interpret Clock stop behavior
@@ -2358,7 +2358,7 @@
 	if ((p->FileC & SIM_CLK_STOP_MASK) == SIM_CLK_STOP_NOT_ALLWD) {
 		/* Sim Clock Stop Not Allowed */
 		SIM_sleep_status = SIM_SLEEP_NOT_ALLOWED;
-		/* There is not need to modifiy p->conf1 */ 
+		/* There is not need to modifiy p->conf1 */
         status_os_sim = NU_Delete_Timer (&SIM_timer);
 	}
 	else {
@@ -2379,7 +2379,7 @@
 #else
 				/* Sim Clock Stop Not Allowed because the interface do not support this level */
 				SIM_sleep_status = SIM_SLEEP_NOT_ALLOWED;
-				/* There is not need to modifiy p->conf1 */ 
+				/* There is not need to modifiy p->conf1 */
 		        status_os_sim = NU_Delete_Timer (&SIM_timer);
 #endif
 			}
@@ -2416,7 +2416,7 @@
     SYS_UWORD8            err;
 
     p->xbuf[0]       = 0xFF;                        //character of PTS proc to send
-    p->xbuf[1]       = 0; 
+    p->xbuf[1]       = 0;
     p->xbuf[2]       = 0xFF;
     p->xbuf[3]       = 0x7B;
 
@@ -2428,15 +2428,15 @@
 
     if (p->PTS_Try > 4)
     {
-        return (SIM_ERR_CARDREJECT);  
+        return (SIM_ERR_CARDREJECT);
     }                       // at the fourth attempt, PTS procedure is unusefull. Use default value.
                             //TA1 present?  Test 27.11.2.6
     else if ( p->PTS_Try == 4)
     {
         SIM_Calcetu (p);
-        return (0);    
+        return (0);
     }
-    
+
     if(cP->AtrData[1] & 0x10)
     {
         TA1 = cP->AtrData[2];
@@ -2469,7 +2469,7 @@
         return (0);
     }                       //if TA1 != 0x11 and 0x94, need to send PTS request
                             //transmit request of speed enhancement : PTS
-    SIM_WriteBuffer(p, 0, n);    
+    SIM_WriteBuffer(p, 0, n);
 
     p->moderx = 0;          //mode of normal reception
     p->expected_data = n;
@@ -2479,8 +2479,8 @@
       return (err);
     }
                             //should received same chars as PTS request
-    if ((p->rbuf[0] != p->xbuf[0]) || (p->rbuf[1] != p->xbuf[1]) || 
-    (p->rbuf[2] != p->xbuf[2])) 
+    if ((p->rbuf[0] != p->xbuf[0]) || (p->rbuf[1] != p->xbuf[1]) ||
+    (p->rbuf[2] != p->xbuf[2]))
     {
       return(SIM_ERR_READ);
     }
@@ -2491,8 +2491,8 @@
         if (p->rbuf[3] != p->xbuf[3])
         {
             return(SIM_ERR_READ);
-        }   
-        
+        }
+
         //correct response from SIM : with speed enhanced
         p->c->conf1 = p->conf1 |= SIM_CONF1_ETU; //set F=512 D=8
     }
@@ -2549,12 +2549,12 @@
         p->c->conf1 = p->conf1 |= SIM_CONF1_SCLKEN;
         // WCS patch for NU_Sleep(0) bug
         if (p->startclock > 0)
-		ind_os_sleep (p->startclock);    
+		ind_os_sleep (p->startclock);
         // End WCS patch
         SIM_sleep_status = SIM_SLEEP_DESACT;
-    }    
+    }
 }
-               
+
 /*
 *  procedure to parse ATR dynamically
 *  input     p pointer of type SIM_PORT
@@ -2575,13 +2575,13 @@
     SYS_UWORD16          mask;
     SYS_UWORD16          returncode;
     SYS_UWORD8            i;
-    SYS_UWORD8            firstprotocol;    
+    SYS_UWORD8            firstprotocol;
     SYS_UWORD8            Tx,T;
     SYS_UWORD8            TDi;
     SYS_UWORD8            position_of_TC1, position_of_TB1;
     SYS_UWORD8            another_protocol_present;
     SYS_UWORD16            wait80000clk;
-        
+
     i               = 0;
     //wait for TS and T0
     p->moderx       = 0;
@@ -2597,9 +2597,9 @@
     {
         return returncode;
     }
-    
+
     //wait for T0
-    p->expected_data++; 
+    p->expected_data++;
     if (returncode = SIM_Waitforchars (p, p->etu9600))
     {
         return returncode;
@@ -2613,7 +2613,7 @@
     }
         /*-----------------------------------------------------------*/
         /*              Inverse convention card                      */
-            // If first byte is correct for inverse card, return success 
+            // If first byte is correct for inverse card, return success
     else if (((p->rbuf[0] & 0x0F) == 0x03) && (p->rx_index != 0))
     {
         cP->Inverse = 1;
@@ -2633,7 +2633,7 @@
 
     HistChar        = Tx & 0x0F;        //get K, number of transmitted historical character
 
-    
+
     while (TDi != 0)
     {
         while (mask < 0x100)            //monitors interface chars
@@ -2645,18 +2645,18 @@
                                         //wait for TC1 and save its position
             if ((firstprotocol == 0) && ((Tx & 0x40) == mask))
             {
-                position_of_TC1 = InterfChar - 1;            
+                position_of_TC1 = InterfChar - 1;
             }
 			if ((firstprotocol == 0) && ((Tx & 0x20) == mask))
             {
-                position_of_TB1 = InterfChar - 1;            
+                position_of_TB1 = InterfChar - 1;
             }
 
             mask = mask << 1;
         }
 
         p->expected_data = InterfChar;     //wait for TAi,TBi,TCi,TDi if present
-        
+
         if (returncode = SIM_Waitforchars (p, p->etu9600))
         {
             return returncode;
@@ -2668,8 +2668,8 @@
             T = SIM_Translate_atr_char (p->rbuf[position_of_TC1], cP);
 
             if ((T != 0) && (T != 255)) //test 27.11.1.3
-            {                           //return Error in case of bad TC1 value            
-                return (SIM_ERR_CARDREJECT);            
+            {                           //return Error in case of bad TC1 value
+                return (SIM_ERR_CARDREJECT);
             }
         }
                                         //need to monitor if TB1 present and if differente from 0 on first protocol
@@ -2677,28 +2677,28 @@
         {
             T = SIM_Translate_atr_char (p->rbuf[position_of_TB1], cP);
 
-            if (T != 0) //ITU 
-            {                           //return Error in case of bad TB1 value            
-                return (SIM_ERR_CARDREJECT);            
+            if (T != 0) //ITU
+            {                           //return Error in case of bad TB1 value
+                return (SIM_ERR_CARDREJECT);
             }
         }
 
         if ((Tx & 0x80) == 0x80)        //TDi byte on first protocol must be 0
         {                               //get new TD char
             Tx = SIM_Translate_atr_char (p->rbuf[InterfChar - 1], cP);
-          
+
             if ((Tx & 0x0F) != 0)
             {
-                if (firstprotocol == 0) //if first protocol received is not T=0, card is rejected   
+                if (firstprotocol == 0) //if first protocol received is not T=0, card is rejected
                 {
                     return (SIM_ERR_CARDREJECT);            //protocol other than T=0
-                }    
+                }
                 else
                 {                       //if an another protocol T != 0 present, need to wait for TCK char
-                    another_protocol_present = 1;                
+                    another_protocol_present = 1;
                 }
             }
-            mask = 0x10;    
+            mask = 0x10;
             firstprotocol++;            //indicate another protocol T
         }
         else
@@ -2708,7 +2708,7 @@
     }
                                         //add TCK if necessary
     p->expected_data =  HistChar + InterfChar + another_protocol_present;
- 
+
     if (returncode = SIM_Waitforchars (p, p->etu9600))
     {
         return returncode;
@@ -2718,17 +2718,17 @@
 
     if (cP->Inverse)        //inverse card
     {
-        // Copy ATR data       
+        // Copy ATR data
         for (i=0;i<cP->AtrSize;i++)
         {
-            cP->AtrData[i] = SIM_ByteReverse(p->rbuf[i]);    
+            cP->AtrData[i] = SIM_ByteReverse(p->rbuf[i]);
         }
         p->c->conf1 = p->conf1 |= SIM_CONF1_CONV | SIM_CONF1_CHKPAR;
     }
     else                    //direct card
     {
         p->c->conf1 = p->conf1 |= SIM_CONF1_CHKPAR; //0x0409
-        // Copy ATR data       
+        // Copy ATR data
         for (i=0;i<cP->AtrSize;i++)
         {
             cP->AtrData[i] = p->rbuf[i];
@@ -2739,7 +2739,7 @@
 }
 
 /*
- ** SIM_Translate_atr_char 
+ ** SIM_Translate_atr_char
  *
  *  FILENAME: sim.c
  *
@@ -2757,7 +2757,7 @@
 
     if (cP->Inverse)
     {
-        translated = SIM_ByteReverse(input);    
+        translated = SIM_ByteReverse(input);
     }
     else
     {
@@ -2773,7 +2773,7 @@
 * input p          sim port
 *       max_wait   max number of TDMA to wait between 2 characters
 * output
-*       error code 0 if OK      
+*       error code 0 if OK
 */
 
 
@@ -2787,7 +2787,7 @@
         p->ack = 0;
         countT = 0;
 
-        while((p->ack == 0) && (p->moderx == 6)) 
+        while((p->ack == 0) && (p->moderx == 6))
         {                               //if p->moderx change from 6 to 5, need to wait for SW1 and SW2
 
             ind_os_sleep(1);
@@ -2811,15 +2811,15 @@
         if (p->moderx == 6)             //if transition to moderx = 5 in synchronous part
         {                               //need to quit for SW1/SW2 reception
             return (0);
-        }    
+        }
     }
-    
+
     if ((p->moderx != 6) && (p->moderx != 5))   //treatement of mode 0, 1, 2, 3, 4
-    {        
+    {
         countT = 0;
         old_nb_char = p->rx_index;
 											   //leave while if moderx == 5
-        while((p->rx_index < p->expected_data) && (p->moderx != 5)) 
+        while((p->rx_index < p->expected_data) && (p->moderx != 5))
         {
             ind_os_sleep(1);
             countT++;                   //implementation of software Waiting time overflow
@@ -2855,7 +2855,7 @@
         countT = 0;
         old_nb_char = p->SWcount;
 
-        while(p->SWcount < 2) 
+        while(p->SWcount < 2)
         {                               //if p->moderx change from 6 to 5, need to wait for SW1 and SW2
 
             ind_os_sleep(1);
@@ -2888,7 +2888,7 @@
 	{
 		return (SIM_ERR_ABNORMAL_CASE1);
 	}
-	
+
 }
 
 
@@ -2915,7 +2915,7 @@
             p->etu9600     = 1815;   // old = 500, increase of 363%
             p->etu400      = 28;
             p->stopclock   = 94;
-            p->startclock = 38; 
+            p->startclock = 38;
         }
     }
     else                                //clock input is 13/4 Mhz
@@ -2925,16 +2925,16 @@
             p->etu9600     = 159;   // old = 44, increase of 363%
             p->etu400      = 3;
             p->stopclock   = 9;
-            p->startclock = 4; 
+            p->startclock = 4;
         }
         else                            //etu period is 372/1*Tsclk
         {
             p->etu9600     = 907;  // old = 250, increase of 363%
             p->etu400      = 14;
             p->stopclock   = 47;
-            p->startclock = 19; 
+            p->startclock = 19;
         }
-    }  
+    }
 }
 
 
@@ -2946,7 +2946,7 @@
  *
  */
 
-SYS_UWORD8 SIM_StartVolt (SYS_UWORD8 ResetFlag) 
+SYS_UWORD8 SIM_StartVolt (SYS_UWORD8 ResetFlag)
 {
 	SYS_UWORD8 abbmask;
 
@@ -2989,7 +2989,7 @@
     {
 		if (ABB_Read_Register_on_page(PAGE1,VRPCSIM) & 0x04) // test RSIMRSU
             return(SIM_OK);
-        ind_os_sleep(1);	
+        ind_os_sleep(1);
     }
     // IOTA failure activation
     return(SIM_ERR_HARDWARE_FAIL);
@@ -3003,7 +3003,7 @@
     {
 		if (ABB_Read_Register_on_page(PAGE1,VRPCSIM) & 0x04) // test RSIMRSU
             return(SIM_OK);
-        ind_os_sleep(1);	
+        ind_os_sleep(1);
     }
     // IOTA failure activation
     return(SIM_ERR_HARDWARE_FAIL);
@@ -3064,14 +3064,14 @@
 {
     SYS_UWORD8 count = 0;
    	SYS_UWORD8 abbmask;
-        
+
     SIM_PowerOff();
 
     #if(ANLG_FAM == 1)
       #if (SIM_TYPE == SIM_TYPE_3_5V)    // shut down VCC from ABB and prepare to start at 5V mode
 	if (ResetFlag) {
 		abbmask = MODE5V_OMEGA;
-        CurrentVolt   = SIM_5V;  
+        CurrentVolt   = SIM_5V;
 	}
 	else {
 		if (CurrentVolt == SIM_3V)
@@ -3086,7 +3086,7 @@
       #if (SIM_TYPE == SIM_TYPE_1_8_3V)  // shut down VCC from ABB and prepare to start at 3V mode
 	if (ResetFlag) {
 		abbmask = MODE_INIT_IOTA_3V;
-        CurrentVolt   = SIM_3V; 
+        CurrentVolt   = SIM_3V;
 	}
 	else {
 		if (CurrentVolt == SIM_1_8V)
@@ -3099,7 +3099,7 @@
        {
           if (ABB_Read_Register_on_page(PAGE1,VRPCSIM) & 0x04)
                return(SIM_OK);
-           ind_os_sleep(1);	
+           ind_os_sleep(1);
        }
        // IOTA failure activation
        return(SIM_ERR_HARDWARE_FAIL);
@@ -3108,7 +3108,7 @@
       #if (SIM_TYPE == SIM_TYPE_1_8_3V)  // shut down VCC from ABB and prepare to start at 3V mode
 	if (ResetFlag) {
 		abbmask = MODE_INIT_SYREN_3V;
-        CurrentVolt   = SIM_3V; 
+        CurrentVolt   = SIM_3V;
 	}
 	else {
 		if (CurrentVolt == SIM_1_8V)
@@ -3138,7 +3138,7 @@
 
     for (i = 0; i < len; i++)
           {
-         if (i == RSIMBUFSIZE) 
+         if (i == RSIMBUFSIZE)
           {
                return (SIM_ERR_BUFF_OVERFL);
           }
@@ -3154,15 +3154,15 @@
 
 /*
  * SIM_SleepStatus
- * 
+ *
  * Return SIM status for sleep manager
- * 
+ *
  */
 SYS_BOOL SIM_SleepStatus(void)
 {
 	if ((SIM_sleep_status == SIM_SLEEP_ACT) ||  (SIM_sleep_status == SIM_SLEEP_NONE))
 		return(1);		 // SIM is ready for deep sleep
-	else 
+	else
 		return(0);
 }