Changeset 1283


Ignore:
Timestamp:
Jan 19, 2010, 10:41:35 AM (10 years ago)
Author:
dingo35
Message:

Remove dynamic data structures for T0, T1 and T14 protocols

Location:
trunk/csctapi
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/csctapi/ct_slot.c

    r1279 r1283  
    183183    ret = OK;
    184184   
    185     if (slot->protocol_type == CT_SLOT_PROTOCOL_T0)
    186     {
    187         if (Protocol_T0_Close ((Protocol_T0 *) slot->protocol) != PROTOCOL_T0_OK)
    188             ret = ERR_TRANS;
    189        
    190         Protocol_T0_Delete ((Protocol_T0 *) slot->protocol);
    191     }
    192     else if (slot->protocol_type == CT_SLOT_PROTOCOL_T1)
    193     {
    194         if (Protocol_T1_Close ((Protocol_T1 *) slot->protocol) != PROTOCOL_T1_OK)
    195             ret = ERR_TRANS;
    196        
    197         Protocol_T1_Delete ((Protocol_T1 *) slot->protocol);
    198     }
    199     else if (slot->protocol_type == CT_SLOT_PROTOCOL_T14)
    200     {
    201         if (Protocol_T14_Close ((Protocol_T14 *) slot->protocol) != PROTOCOL_T14_OK)
    202             ret = ERR_TRANS;
    203        
    204         Protocol_T14_Delete ((Protocol_T14 *) slot->protocol);
    205     }
    206    
    207185    slot->protocol = NULL;
    208186    slot->protocol_type = CT_SLOT_NULL;
     
    227205    if (slot->protocol_type == CT_SLOT_PROTOCOL_T0) /* T=0 protocol ICC */
    228206    {
    229         if (Protocol_T0_Command ( cmd, rsp) != PROTOCOL_T0_OK)
     207        if (Protocol_T0_Command (cmd, rsp) != PROTOCOL_T0_OK)
    230208            ret = ERR_TRANS;
    231209        else
     
    234212    else if (slot->protocol_type == CT_SLOT_PROTOCOL_T1) /* T=1 protocol ICC */
    235213    {
    236         if (Protocol_T1_Command ((Protocol_T1 *) slot->protocol, cmd, rsp) != PROTOCOL_T1_OK)
     214        if (Protocol_T1_Command (cmd, rsp) != PROTOCOL_T1_OK)
    237215            ret = ERR_TRANS;
    238216        else
     
    300278   
    301279    ret = OK;
    302    
    303     if (slot->protocol_type == CT_SLOT_PROTOCOL_T0)
    304     {
    305         if (Protocol_T0_Close ((Protocol_T0 *) slot->protocol) != PROTOCOL_T0_OK)
    306             ret = ERR_TRANS;
    307        
    308         Protocol_T0_Delete ((Protocol_T0 *) slot->protocol);
    309     }
    310     else if (slot->protocol_type == CT_SLOT_PROTOCOL_T1)
    311     {
    312         if (Protocol_T1_Close ((Protocol_T1 *) slot->protocol) != PROTOCOL_T1_OK)
    313             ret = ERR_TRANS;
    314        
    315         Protocol_T1_Delete ((Protocol_T1 *) slot->protocol);
    316     }
    317     else if (slot->protocol_type == CT_SLOT_PROTOCOL_T14)
    318     {
    319         if (Protocol_T14_Close ((Protocol_T14 *) slot->protocol) != PROTOCOL_T14_OK)
    320             ret = ERR_TRANS;
    321        
    322         Protocol_T14_Delete ((Protocol_T14 *) slot->protocol);
    323     }
    324280   
    325281    if (slot->icc_type == CT_SLOT_ICC_ASYNC)
  • trunk/csctapi/pps.c

    r1279 r1283  
    5757static unsigned PPS_GetLength (BYTE * block);
    5858
    59 static int PPS_InitICC (PPS * pps);
    60 
    61 static int PPS_InitProtocol (PPS * pps, int protocol_selected);
     59static int PPS_InitICC ();
     60
     61static int PPS_InitProtocol ();
    6262
    6363static BYTE PPS_GetPCK (BYTE * block, unsigned length);
     
    7575    if (pps != NULL)
    7676    {
    77         pps->protocol = NULL;
    78         pps->parameters.t = PPS_DEFAULT_PROTOCOL;
    79         pps->parameters.FI = ATR_DEFAULT_FI;
    80         pps->parameters.d = ATR_DEFAULT_D;
    81         pps->parameters.n = ATR_DEFAULT_N;
     77        protocol = NULL;
     78        parameters.t = PPS_DEFAULT_PROTOCOL;
     79        parameters.FI = ATR_DEFAULT_FI;
     80        parameters.d = ATR_DEFAULT_D;
     81        parameters.n = ATR_DEFAULT_N;
    8282    }
    8383   
     
    110110        if (ret == PPS_OK)
    111111        {
    112             pps->parameters.t = params[1] & 0x0F;
     112            parameters.t = params[1] & 0x0F;
    113113           
    114114            if (PPS_HAS_PPS1 (params))
    115115            {
    116                 pps->parameters.FI = (params[2] >> 4);
    117                 pps->parameters.d = atr_d_table[(params[2] & 0x0F)];
     116                parameters.FI = (params[2] >> 4);
     117                parameters.d = atr_d_table[(params[2] & 0x0F)];
    118118            }
    119119           
     
    186186
    187187//If more than one protocol type and/or TA1 parameter values other than the default values and/or N equeal to 255 is/are indicated in the answer to reset, the card shall know unambiguously, after having sent the answer to reset, which protocol type or/and transmission parameter values (FI, D, N) will be used. Consequently a selection of the protocol type and/or the transmission parameters values shall be specified.
    188         ATR_GetParameter (atr, ATR_PARAMETER_N, &(pps->parameters.n));
    189         ATR_GetProtocolType(atr,1,&(pps->parameters.t)); //get protocol from TD1
     188        ATR_GetParameter (atr, ATR_PARAMETER_N, &(parameters.n));
     189        ATR_GetProtocolType(atr,1,&(parameters.t)); //get protocol from TD1
    190190        BYTE TA2;
    191191        bool SpecificMode = (ATR_GetInterfaceByte (atr, 2, ATR_INTERFACE_BYTE_TA, &TA2) == ATR_OK); //if TA2 present, specific mode, else negotiable mode
    192192        if (SpecificMode) {
    193             pps->parameters.t = TA2 & 0x0F;
     193            parameters.t = TA2 & 0x0F;
    194194            if ((TA2 & 0x10) != 0x10) { //bit 5 set to 0 means F and D explicitly defined in interface characters
    195195                BYTE TA1;
    196196                if (ATR_GetInterfaceByte (atr, 1 , ATR_INTERFACE_BYTE_TA, &TA1) == ATR_OK) {
    197                     pps->parameters.FI = TA1 >> 4;
    198                     ATR_GetParameter (atr, ATR_PARAMETER_D, &(pps->parameters.d));
     197                    parameters.FI = TA1 >> 4;
     198                    ATR_GetParameter (atr, ATR_PARAMETER_D, &(parameters.d));
    199199                }
    200200                else {
    201                     pps->parameters.FI = ATR_DEFAULT_FI;
    202                     pps->parameters.d = ATR_DEFAULT_D;
     201                    parameters.FI = ATR_DEFAULT_FI;
     202                    parameters.d = ATR_DEFAULT_D;
    203203                }
    204204            }
    205205            else {
    206206                cs_log("Specific mode: speed 'implicitly defined', not sure how to proceed, assuming default values");
    207                 pps->parameters.FI = ATR_DEFAULT_FI;
    208                 pps->parameters.d = ATR_DEFAULT_D;
    209             }
    210             cs_debug("Specific mode: T%i, F=%.0f, D=%.6f, N=%.0f\n", pps->parameters.t, (double) atr_f_table[pps->parameters.FI], pps->parameters.d, pps->parameters.n);
     207                parameters.FI = ATR_DEFAULT_FI;
     208                parameters.d = ATR_DEFAULT_D;
     209            }
     210            cs_debug("Specific mode: T%i, F=%.0f, D=%.6f, N=%.0f\n", parameters.t, (double) atr_f_table[parameters.FI], parameters.d, parameters.n);
    211211        }
    212212        else { //negotiable mode
    213213
    214             bool NeedsPTS = ((pps->parameters.t != 14) && (numprottype > 1 || (atr->ib[0][ATR_INTERFACE_BYTE_TA].present == TRUE && atr->ib[0][ATR_INTERFACE_BYTE_TA].value != 0x11) || pps->parameters.n == 255)); //needs PTS according to ISO 7816 , SCI gets stuck on our PTS
     214            bool NeedsPTS = ((parameters.t != 14) && (numprottype > 1 || (atr->ib[0][ATR_INTERFACE_BYTE_TA].present == TRUE && atr->ib[0][ATR_INTERFACE_BYTE_TA].value != 0x11) || parameters.n == 255)); //needs PTS according to ISO 7816 , SCI gets stuck on our PTS
    215215            if (NeedsPTS) {
    216216                //             PTSS  PTS0  PTS1  PTS2  PTS3  PCK
    217217                //             PTSS  PTS0  PTS1  PCK
    218218                BYTE req[] = { 0xFF, 0x10, 0x00, 0x00 }; //we currently do not support PTS2, standard guardtimes
    219                 req[1]=0x10 | pps->parameters.t; //PTS0 always flags PTS1 to be sent always
     219                req[1]=0x10 | parameters.t; //PTS0 always flags PTS1 to be sent always
    220220                if (ATR_GetInterfaceByte (atr, 1, ATR_INTERFACE_BYTE_TA, &req[2]) != ATR_OK)  //PTS1
    221221                    req[2] = 0x11; //defaults FI and DI to 1
     
    224224                ret = PPS_Exchange (req, &len);
    225225            if (ret == PPS_OK) {
    226                     pps->parameters.FI = req[2] >> 4;
     226                    parameters.FI = req[2] >> 4;
    227227                    BYTE DI = req[2] & 0x0F;
    228                     pps->parameters.d = (double) (atr_d_table[DI]);
     228                    parameters.d = (double) (atr_d_table[DI]);
    229229                    PPS_success = TRUE;
    230                     cs_debug("PTS Succesfull, selected protocol: T%i, F=%.0f, D=%.6f, N=%.0f\n", pps->parameters.t, (double) atr_f_table[pps->parameters.FI], pps->parameters.d, pps->parameters.n);
     230                    cs_debug("PTS Succesfull, selected protocol: T%i, F=%.0f, D=%.6f, N=%.0f\n", parameters.t, (double) atr_f_table[parameters.FI], parameters.d, parameters.n);
    231231                }
    232232                else
     
    239239                BYTE TA1;
    240240                if (ATR_GetInterfaceByte (atr, 1 , ATR_INTERFACE_BYTE_TA, &TA1) == ATR_OK) {
    241                     pps->parameters.FI = TA1 >> 4;
    242                     ATR_GetParameter (atr, ATR_PARAMETER_D, &(pps->parameters.d));
     241                    parameters.FI = TA1 >> 4;
     242                    ATR_GetParameter (atr, ATR_PARAMETER_D, &(parameters.d));
    243243                }
    244244                else { //do not obey TA1
    245                     pps->parameters.FI = ATR_DEFAULT_FI;
    246                     pps->parameters.d = ATR_DEFAULT_D;
     245                    parameters.FI = ATR_DEFAULT_FI;
     246                    parameters.d = ATR_DEFAULT_D;
    247247                }
    248                 ATR_GetProtocolType (atr, 1, &(pps->parameters.t));
     248                ATR_GetProtocolType (atr, 1, &(parameters.t));
    249249                protocol_selected = 1;
    250250   
    251251                if (NeedsPTS) {
    252                     if ((pps->parameters.d == 32) || (pps->parameters.d == 12) || (pps->parameters.d == 20))
    253                         pps->parameters.d = 0; //behave conform "old" atr_d_table; viaccess cards that fail PTS need this
     252                    if ((parameters.d == 32) || (parameters.d == 12) || (parameters.d == 20))
     253                        parameters.d = 0; //behave conform "old" atr_d_table; viaccess cards that fail PTS need this
    254254                }
    255255                /////Here all non-ISO behaviour
    256256                /////End  all non-ISO behaviour
    257257
    258                 cs_debug("No PTS %s, selected protocol T%i, F=%.0f, D=%.6f, N=%.0f\n", NeedsPTS?"happened":"needed", pps->parameters.t, (double) atr_f_table[pps->parameters.FI], pps->parameters.d, pps->parameters.n);
     258                cs_debug("No PTS %s, selected protocol T%i, F=%.0f, D=%.6f, N=%.0f\n", NeedsPTS?"happened":"needed", parameters.t, (double) atr_f_table[parameters.FI], parameters.d, parameters.n);
    259259            }
    260260        }//end negotiable mode
     
    262262       
    263263    //make sure no zero values
    264     double F =  (double) atr_f_table[pps->parameters.FI];
     264    double F =  (double) atr_f_table[parameters.FI];
    265265    if (!F) {
    266         pps->parameters.FI = ATR_DEFAULT_FI;
    267         cs_log("Warning: F=0 is invalid, forcing FI=%d", pps->parameters.FI);
    268     }
    269     if (!pps->parameters.d) {
    270         pps->parameters.d = ATR_DEFAULT_D;
    271         cs_log("Warning: D=0 is invalid, forcing D=%.0f",pps->parameters.d);
    272     }
    273 
    274     protocol_type = pps->parameters.t;
     266        parameters.FI = ATR_DEFAULT_FI;
     267        cs_log("Warning: F=0 is invalid, forcing FI=%d", parameters.FI);
     268    }
     269    if (!parameters.d) {
     270        parameters.d = ATR_DEFAULT_D;
     271        cs_log("Warning: D=0 is invalid, forcing D=%.0f",parameters.d);
     272    }
     273
     274    protocol_type = parameters.t;
    275275   
    276276#ifdef DEBUG_PROTOCOL
    277277    printf("PPS: T=%i, F=%.0f, D=%.6f, N=%.0f\n",
    278     pps->parameters.t,
     278    parameters.t,
    279279    F,
    280     pps->parameters.d,
    281     pps->parameters.n);
     280    parameters.d,
     281    parameters.n);
    282282#endif
    283283
     
    288288   
    289289    /* Initialize selected protocol with selected parameters */
    290     if (pps->parameters.t == 1)
    291         ret = PPS_InitProtocol (pps, 3); //FIXME in practice most T1 cards carry timing parameters in TA3, TB3 and TC3
    292     else
    293         ret = PPS_InitProtocol (pps, 2); //FIXME T0 cards carry timing parameters in TC2
    294    
    295     return ret;
    296 }
    297 
    298 void * PPS_GetProtocol (PPS * pps)
    299 {
    300     return pps->protocol;
    301 }
    302 
    303 PPS_ProtocolParameters *PPS_GetProtocolParameters (PPS * pps)
     290    return PPS_InitProtocol ();
     291}
     292
     293void * PPS_GetProtocol ()
     294{
     295    return protocol;
     296}
     297
     298PPS_ProtocolParameters *PPS_GetProtocolParameters ()
    304299{
    305300    /* User must Remember not to reference this struct after removing PPS */
    306     return &(pps->parameters);
     301    return &(parameters);
    307302}
    308303
     
    423418}
    424419
    425 static int PPS_InitICC (PPS * pps)
     420static int PPS_InitICC ()
    426421{
    427422#ifdef SCI_DEV
     
    437432            return PPS_ICC_ERROR;
    438433
    439         params.T = pps->parameters.t;
    440         params.fs = atr_fs_table[pps->parameters.FI] / 1000000;
    441         double F =  (double) atr_f_table[pps->parameters.FI];
     434        params.T = parameters.t;
     435        params.fs = atr_fs_table[parameters.FI] / 1000000;
     436        double F =  (double) atr_f_table[parameters.FI];
    442437        //for Irdeto T14 cards, do not set ETU
    443438    if (!(atr->hbn >= 6 && !memcmp(atr->hb, "IRDETO", 6) && params.T == 14))
    444           params.ETU = F / pps->parameters.d;
    445         if (pps->parameters.n == 255) //only for T0 or also for T1?
     439          params.ETU = F / parameters.d;
     440        if (parameters.n == 255) //only for T0 or also for T1?
    446441            params.EGT = 0;
    447442        else
    448             params.EGT = pps->parameters.n;
     443            params.EGT = parameters.n;
    449444
    450445        double a;
     
    462457#elif COOL
    463458    if(reader[ridx].typ == R_INTERNAL) {
    464         int mhz = atr_fs_table[pps->parameters.FI] / 10000;
     459        int mhz = atr_fs_table[parameters.FI] / 10000;
    465460        if (!Cool_SetBaudrate(mhz))
    466461            return PPS_ICC_ERROR;
     
    473468    {
    474469    unsigned long baudrate;
    475     double F =  (double) atr_f_table[pps->parameters.FI];
    476     if (pps->parameters.t == 14)
     470    double F =  (double) atr_f_table[parameters.FI];
     471    if (parameters.t == 14)
    477472        baudrate = 9600;
    478473    else
    479         baudrate = pps->parameters.d * ICC_Async_GetClockRate () / F;
     474        baudrate = parameters.d * ICC_Async_GetClockRate () / F;
    480475
    481476#ifdef DEBUG_PROTOCOL
     
    491486}
    492487
    493 static int PPS_InitProtocol (PPS * pps, int selected_protocol)
     488static int PPS_InitProtocol ()
    494489{
    495490    int ret;
    496491   
    497     if (pps->parameters.t == ATR_PROTOCOL_TYPE_T0)
    498     {
    499         pps->protocol = Protocol_T0_New ();
    500        
    501         if ((pps->protocol) != NULL)
    502         {
    503             ret = Protocol_T0_Init ((Protocol_T0 *) pps->protocol, &(pps->parameters), selected_protocol);
     492    if (parameters.t == ATR_PROTOCOL_TYPE_T0)
     493    {
     494            ret = Protocol_T0_Init (&(parameters));
    504495           
    505496            if (ret != PROTOCOL_T0_OK)
    506497            {
    507                 Protocol_T0_Delete ((Protocol_T0 *) pps->protocol);
    508                 pps->protocol = NULL;
     498                protocol = NULL;
    509499                return PPS_PROTOCOL_ERROR;
    510500            }
    511501           
    512502            return PPS_OK;
    513         }       
    514     }
    515     else if (pps->parameters.t == ATR_PROTOCOL_TYPE_T1)
    516     {
    517         pps->protocol = Protocol_T1_New ();
    518        
    519         if (pps->protocol != NULL)
    520         {
    521             ret = Protocol_T1_Init ((Protocol_T1 *) pps->protocol, selected_protocol);
     503    }
     504    else if (parameters.t == ATR_PROTOCOL_TYPE_T1)
     505    {
     506            ret = Protocol_T1_Init ();
    522507           
    523508            if (ret != PROTOCOL_T1_OK)
    524509            {
    525                 Protocol_T1_Delete ((Protocol_T1 *) pps->protocol);
    526                 pps->protocol = NULL;
     510                protocol = NULL;
    527511                return PPS_PROTOCOL_ERROR;
    528512            }
    529513           
    530514            return PPS_OK;
    531         }
    532     }
    533     else if (pps->parameters.t == ATR_PROTOCOL_TYPE_T14)
    534     {
    535         pps->protocol = Protocol_T14_New ();
    536        
    537         if ((pps->protocol) != NULL)
    538         {
    539             ret = Protocol_T14_Init ((Protocol_T14 *) pps->protocol, &(pps->parameters), selected_protocol);
     515    }
     516    else if (parameters.t == ATR_PROTOCOL_TYPE_T14)
     517    {
     518            ret = Protocol_T14_Init (&(parameters));
    540519           
    541520            if (ret != PROTOCOL_T14_OK)
    542521            {
    543                 Protocol_T14_Delete ((Protocol_T14 *) pps->protocol);
    544                 pps->protocol = NULL;
     522                protocol = NULL;
    545523                return PPS_PROTOCOL_ERROR;
    546524            }
    547525           
    548526            return PPS_OK;
    549         }       
    550527    }
    551528    else
    552529    {
    553         pps->protocol = NULL;
     530        protocol = NULL;
    554531    }
    555532   
  • trunk/csctapi/pps.h

    r1279 r1283  
    5353typedef struct
    5454{
    55   void *protocol;
    56   PPS_ProtocolParameters parameters;
    5755}
    5856PPS;
     57
     58void *protocol;
     59PPS_ProtocolParameters parameters;
    5960
    6061/*
     
    6970
    7071/* Get protocol handler */
    71 extern void *PPS_GetProtocol (PPS * pps);
     72extern void *PPS_GetProtocol ();
    7273
    7374/* Get protocol parameters */
    74 extern PPS_ProtocolParameters *PPS_GetProtocolParameters (PPS * pps);
     75extern PPS_ProtocolParameters *PPS_GetProtocolParameters ();
    7576
    7677/* Delete PPS context */
  • trunk/csctapi/protocol_t0.c

    r1279 r1283  
    5252 */
    5353
    54 static void Protocol_T0_Clear (Protocol_T0 * t0);
    55 static void Protocol_T14_Clear (Protocol_T14 * t14);
    56 
    5754static int Protocol_T0_Case1 (APDU_Cmd * cmd, APDU_Rsp ** rsp);
    5855
     
    7875 */
    7976
    80 Protocol_T0 * Protocol_T0_New (void)
    81 {
    82     Protocol_T0 *t0;
    83    
    84     t0 = (Protocol_T0 *) malloc (sizeof (Protocol_T0));
    85    
    86     if (t0 != NULL)
    87         Protocol_T0_Clear (t0);
    88    
    89     return t0;
    90 }
    91 
    92 Protocol_T14 * Protocol_T14_New (void)
    93 {
    94     Protocol_T14 *t14;
    95    
    96     t14 = (Protocol_T14 *) malloc (sizeof (Protocol_T14));
    97    
    98     if (t14 != NULL)
    99         Protocol_T14_Clear (t14);
    100    
    101     return t14;
    102 }
    103 
    104 int Protocol_T0_Init (Protocol_T0 * t0, PPS_ProtocolParameters * params, int selected_protocol)
     77int Protocol_T0_Init (PPS_ProtocolParameters * params)
    10578{
    10679    BYTE wi;
     
    10881    /* Integer value WI  = TC2, by default 10 */
    10982#ifndef PROTOCOL_T0_USE_DEFAULT_TIMINGS
    110     if (ATR_GetInterfaceByte (atr, selected_protocol, ATR_INTERFACE_BYTE_TC, &(wi)) != ATR_OK)
     83    if (ATR_GetInterfaceByte (atr, 2, ATR_INTERFACE_BYTE_TC, &(wi)) != ATR_OK)
    11184#endif
    11285    wi = PROTOCOL_T0_DEFAULT_WI;
     
    11487    /* WWT = 960 * WI * (Fi / f) * 1000 milliseconds */
    11588    double F =  (double) atr_f_table[params->FI];
    116     t0->wwt = (long unsigned int) (960 * wi * (F / ICC_Async_GetClockRate ()) * 1000);
     89    unsigned long wwt = (long unsigned int) (960 * wi * (F / ICC_Async_GetClockRate ()) * 1000);
    11790   
    11891    /* Set timings */
    119     icc_timings.block_timeout = t0->wwt;
    120     icc_timings.char_timeout = t0->wwt;
     92    icc_timings.block_timeout = wwt;
     93    icc_timings.char_timeout = wwt;
    12194    ICC_Async_SetTimings ();
    12295   
    12396#ifdef DEBUG_PROTOCOL
    124     printf ("Protocol: T=0: WWT=%d, Clockrate=%lu\n", (int)(t0->wwt),ICC_Async_GetClockRate());
     97    printf ("Protocol: T=0: WWT=%d, Clockrate=%lu\n", (int)(wwt),ICC_Async_GetClockRate());
    12598#endif
    12699   
     
    128101}
    129102
    130 int Protocol_T14_Init (Protocol_T14 * t14, PPS_ProtocolParameters * params, int selected_protocol)
     103int Protocol_T14_Init (PPS_ProtocolParameters * params)
    131104{
    132105    BYTE wi;
     
    134107    /* Integer value WI  = TC2, by default 10 */
    135108#ifndef PROTOCOL_T14_USE_DEFAULT_TIMINGS
    136     if (ATR_GetInterfaceByte (atr, selected_protocol, ATR_INTERFACE_BYTE_TC, &(wi)) != ATR_OK)
     109    if (ATR_GetInterfaceByte (atr, 2, ATR_INTERFACE_BYTE_TC, &(wi)) != ATR_OK)
    137110#endif
    138111    wi = PROTOCOL_T14_DEFAULT_WI;
     
    140113    /* WWT = 960 * WI * (Fi / f) * 1000 milliseconds */
    141114    double F =  (double) atr_f_table[params->FI];
    142     t14->wwt = (long unsigned int) (960 * wi * (F / ICC_Async_GetClockRate ()) * 1000);
    143     t14->wwt >>= 1;
     115    unsigned long wwt = (long unsigned int) (960 * wi * (F / ICC_Async_GetClockRate ()) * 1000);
     116    wwt >>= 1;
    144117   
    145118    /* Set timings */
    146     icc_timings.block_timeout = t14->wwt;
    147     icc_timings.char_timeout = t14->wwt;
     119    icc_timings.block_timeout = wwt;
     120    icc_timings.char_timeout = wwt;
    148121    ICC_Async_SetTimings ();
    149122
    150123#ifdef DEBUG_PROTOCOL
    151     printf ("Protocol: T=14: WWT=%d\n", (int)(t14->wwt));
     124    printf ("Protocol: T=14: WWT=%d\n", (int)(wwt));
    152125#endif
    153126   
     
    219192   
    220193    return ret;
    221 }
    222 
    223 int Protocol_T0_Close (Protocol_T0 * t0)
    224 {
    225     Protocol_T0_Clear (t0);
    226    
    227     return PROTOCOL_T0_OK;
    228 }
    229 
    230 int Protocol_T14_Close (Protocol_T14 * t14)
    231 {
    232     Protocol_T14_Clear (t14);
    233    
    234     return PROTOCOL_T14_OK;
    235 }
    236 
    237 void Protocol_T0_Delete (Protocol_T0 * t0)
    238 {
    239     free (t0);
    240 }
    241 
    242 void Protocol_T14_Delete (Protocol_T14 * t14)
    243 {
    244     free (t14);
    245194}
    246195
     
    11011050    return (ret);
    11021051}
    1103 
    1104 static void Protocol_T0_Clear (Protocol_T0 * t0)
    1105 {
    1106     t0->wwt = 0;
    1107 }
    1108 
    1109 static void Protocol_T14_Clear (Protocol_T14 * t14)
    1110 {
    1111     t14->wwt = 0;
    1112 }
  • trunk/csctapi/protocol_t0.h

    r1279 r1283  
    5353 */
    5454
    55 /* T=0 Protocol handler */
    56 typedef struct
    57 {
    58   unsigned long wwt;        /* Work waiting time (ms) */
    59 }
    60 Protocol_T0;
    61 
    62 /* T=14 Protocol handler */
    63 typedef struct
    64 {
    65   unsigned long wwt;        /* Work waiting time (ms) */
    66 }
    67 Protocol_T14;
    68 
    6955/*
    7056 * Exported functions declaration
    7157 */
    7258
    73 /* Create a new protocol handler */
    74 extern Protocol_T0 *Protocol_T0_New (void);
    75 extern Protocol_T14 *Protocol_T14_New (void);
    76 
    77 /* Delete a protocol handler */
    78 extern void Protocol_T0_Delete (Protocol_T0 * t0);
    79 extern void Protocol_T14_Delete (Protocol_T14 * t14);
    80 
    8159/* Initialise a protocol handler */
    82 extern int Protocol_T0_Init (Protocol_T0 * t0, PPS_ProtocolParameters * params, int selected_protocol);
    83 extern int Protocol_T14_Init (Protocol_T14 * t14, PPS_ProtocolParameters * params, int selected_protocol);
     60extern int Protocol_T0_Init (PPS_ProtocolParameters * params);
     61extern int Protocol_T14_Init (PPS_ProtocolParameters * params);
    8462
    8563/* Send a command and return a response */
     
    8765extern int Protocol_T14_Command (APDU_Cmd * cmd, APDU_Rsp ** rsp);
    8866
    89 /* Close a protocol handler */
    90 extern int Protocol_T0_Close (Protocol_T0 * t0);
    91 extern int Protocol_T14_Close (Protocol_T14 * t14);
    92 
    9367#endif /* _PROTOCOL_T0_ */
    9468
  • trunk/csctapi/protocol_t1.c

    r1279 r1283  
    4545 */
    4646
    47 static void
    48 Protocol_T1_Clear (Protocol_T1 * t1);
    49 
    5047static int
    5148Protocol_T1_SendBlock (T1_Block * block);
    5249
    5350static int
    54 Protocol_T1_ReceiveBlock (Protocol_T1 * t1, T1_Block ** block);
     51Protocol_T1_ReceiveBlock (T1_Block ** block);
    5552
    5653static int
     
    6158 */
    6259
    63 Protocol_T1 *
    64 Protocol_T1_New (void)
    65 {
    66   Protocol_T1 *t1;
    67 
    68   t1 = (Protocol_T1 *) malloc (sizeof (Protocol_T1));
    69 
    70   if (t1 != NULL)
    71     Protocol_T1_Clear (t1);
    72 
    73   return t1;
    74 }
    75 
    7660int
    77 Protocol_T1_Init (Protocol_T1 * t1, int selected_protocol)
     61Protocol_T1_Init (int selected_protocol)
    7862{
    7963  BYTE ta, tb, tc, cwi, bwi;
     
    8468  /* Set IFSC */
    8569  if (ATR_GetInterfaceByte (atr, selected_protocol, ATR_INTERFACE_BYTE_TA, &ta) == ATR_NOT_FOUND)
    86     t1->ifsc = PROTOCOL_T1_DEFAULT_IFSC;
     70    ifsc = PROTOCOL_T1_DEFAULT_IFSC;
    8771  else if ((ta != 0x00) && (ta != 0xFF))
    88     t1->ifsc = ta;
     72    ifsc = ta;
    8973  else
    90     t1->ifsc = PROTOCOL_T1_DEFAULT_IFSC;
     74    ifsc = PROTOCOL_T1_DEFAULT_IFSC;
    9175
    9276  /* Towitoko does not allow IFSC > 251 */
    93   t1->ifsc = MIN (t1->ifsc, PROTOCOL_T1_MAX_IFSC);
     77  ifsc = MIN (ifsc, PROTOCOL_T1_MAX_IFSC);
    9478
    9579  /* Set IFSD */
    96   t1->ifsd = PROTOCOL_T1_DEFAULT_IFSD;
     80  ifsd = PROTOCOL_T1_DEFAULT_IFSD;
    9781
    9882#ifndef PROTOCOL_T1_USE_DEFAULT_TIMINGS
     
    117101
    118102  /* Set CWT = (2^CWI + 11) work etu */
    119   t1->cwt = 1;
     103  cwt = 1;
    120104
    121105  for (i = 0; i < cwi ; i++)
    122     t1->cwt *= 2;
    123 
    124   t1->cwt = (unsigned short) ((t1->cwt + 11) * work_etu);
     106    cwt *= 2;
     107
     108  cwt = (unsigned short) ((cwt + 11) * work_etu);
    125109
    126110  /* Set BWT = (2^BWI * 960 + 11) work etu */
    127   t1->bwt = 1;
     111  bwt = 1;
    128112  for (i = 0; i < bwi; i++)
    129     t1->bwt *= 2;
    130 
    131   t1->bwt = (unsigned short) ((t1->bwt * 960 + 11) * work_etu);
     113    bwt *= 2;
     114
     115  bwt = (unsigned short) ((bwt * 960 + 11) * work_etu);
    132116
    133117  /* Set BGT = 22 * work etu */
    134   t1->bgt = (unsigned short) (22 * work_etu);
     118  bgt = (unsigned short) (22 * work_etu);
    135119
    136120  /* Set the error detection code type */
    137121  if (ATR_GetInterfaceByte (atr, selected_protocol, ATR_INTERFACE_BYTE_TC, &tc) == ATR_NOT_FOUND)
    138     t1->edc = PROTOCOL_T1_EDC_LRC;
     122    edc = PROTOCOL_T1_EDC_LRC;
    139123  else
    140     t1->edc = tc & 0x01;
     124    edc = tc & 0x01;
    141125
    142126  /* Set initial send sequence (NS) */
    143   t1->ns = 1;
     127  ns = 1;
    144128 
    145129  /* Set timings */
    146   icc_timings.block_timeout = t1->bwt;
    147   icc_timings.char_timeout = t1->cwt;
    148   icc_timings.block_delay = t1->bgt;
     130  icc_timings.block_timeout = bwt;
     131  icc_timings.char_timeout = cwt;
     132  icc_timings.block_delay = bgt;
    149133    ICC_Async_SetTimings ();
    150134
    151135#ifdef DEBUG_PROTOCOL
    152136  printf ("Protocol: T=1: IFSC=%d, IFSD=%d, CWT=%d, BWT=%d, BGT=%d, EDC=%s\n",
    153           t1->ifsc, t1->ifsd, t1->cwt, t1->bwt, t1->bgt,
    154           (t1->edc == PROTOCOL_T1_EDC_LRC) ? "LRC" : "CRC");
     137          ifsc, ifsd, cwt, bwt, t1->bgt,
     138          (edc == PROTOCOL_T1_EDC_LRC) ? "LRC" : "CRC");
    155139#endif
    156140
     
    159143
    160144int
    161 Protocol_T1_Command (Protocol_T1 * t1, APDU_Cmd * cmd, APDU_Rsp ** rsp)
     145Protocol_T1_Command (APDU_Cmd * cmd, APDU_Rsp ** rsp)
    162146{
    163147  T1_Block *block;
     
    183167
    184168      /* Receive a block */
    185       ret = Protocol_T1_ReceiveBlock (t1, &block);
     169      ret = Protocol_T1_ReceiveBlock (&block);
    186170
    187171      if (ret == PROTOCOL_T1_OK)
     
    194178              /* Update IFSD value */
    195179              inf = (*T1_Block_GetInf (block));
    196               t1->ifsd = inf;
     180              ifsd = inf;
    197181#ifdef DEBUG_PROTOCOL
    198182              printf ("Protocol: Received block S(IFS response, %d)\n", inf);
     
    206190  /* Calculate the number of bytes to send */
    207191  counter = 0;
    208   bytes = MIN (APDU_Cmd_RawLen (cmd), t1->ifsc);
     192  bytes = MIN (APDU_Cmd_RawLen (cmd), ifsc);
    209193
    210194  /* See if chaining is needed */
    211   more = (APDU_Cmd_RawLen (cmd) > t1->ifsc);
     195  more = (APDU_Cmd_RawLen (cmd) > ifsc);
    212196
    213197  /* Increment ns */
    214   t1->ns = (t1->ns + 1) %2;
     198  ns = (ns + 1) %2;
    215199
    216200  /* Create an I-Block */
    217   block = T1_Block_NewIBlock (bytes, APDU_Cmd_Raw (cmd), t1->ns, more);
    218 
    219 #ifdef DEBUG_PROTOCOL
    220   printf ("Sending block I(%d,%d)\n", t1->ns, more);
     201  block = T1_Block_NewIBlock (bytes, APDU_Cmd_Raw (cmd), ns, more);
     202
     203#ifdef DEBUG_PROTOCOL
     204  printf ("Sending block I(%d,%d)\n", ns, more);
    221205#endif
    222206
     
    230214    {
    231215      /* Receive a block */
    232       ret = Protocol_T1_ReceiveBlock (t1, &block);
     216      ret = Protocol_T1_ReceiveBlock (&block);
    233217
    234218      if (ret == PROTOCOL_T1_OK)
     
    246230 
    247231              /* Increment ns  */
    248               t1->ns = (t1->ns + 1) % 2;
     232              ns = (ns + 1) % 2;
    249233
    250234              /* Calculate the number of bytes to send */
    251235              counter += bytes;
    252               bytes = MIN (APDU_Cmd_RawLen (cmd) - counter, t1->ifsc);
     236              bytes = MIN (APDU_Cmd_RawLen (cmd) - counter, ifsc);
    253237
    254238              /* See if chaining is needed */
    255               more = (APDU_Cmd_RawLen (cmd) - counter > t1->ifsc);
     239              more = (APDU_Cmd_RawLen (cmd) - counter > ifsc);
    256240
    257241              /* Create an I-Block */
    258242              block =
    259243                T1_Block_NewIBlock (bytes, APDU_Cmd_Raw (cmd) + counter,
    260                                     t1->ns, more);
    261 #ifdef DEBUG_PROTOCOL
    262               printf ("Protocol: Sending block I(%d,%d)\n", t1->ns, more);
     244                                    ns, more);
     245#ifdef DEBUG_PROTOCOL
     246              printf ("Protocol: Sending block I(%d,%d)\n", ns, more);
    263247#endif
    264248              /* Send a block */
     
    293277    {
    294278      if (wtx > 1)
    295         Protocol_T1_UpdateBWT (wtx * (t1->bwt));         
     279        Protocol_T1_UpdateBWT (wtx * (bwt));         
    296280
    297281      /* Receive a block */
    298       ret = Protocol_T1_ReceiveBlock (t1, &block);
     282      ret = Protocol_T1_ReceiveBlock (&block);
    299283
    300284      if (wtx > 1)
    301285        {
    302           Protocol_T1_UpdateBWT (t1->bwt);         
     286          Protocol_T1_UpdateBWT (bwt);         
    303287          wtx = 0;
    304288        }
     
    383367}
    384368
    385 int
    386 Protocol_T1_Close (Protocol_T1 * t1)
    387 {
    388   Protocol_T1_Clear (t1);
    389 
    390   return PROTOCOL_T1_OK;
    391 }
    392 
    393 void
    394 Protocol_T1_Delete (Protocol_T1 * t1)
    395 {
    396   free (t1);
    397 }
    398 
    399369/*
    400370 * Not exported functions definition
     
    425395
    426396static int
    427 Protocol_T1_ReceiveBlock (Protocol_T1 * t1, T1_Block ** block)
     397Protocol_T1_ReceiveBlock (T1_Block ** block)
    428398{
    429399  BYTE buffer[T1_BLOCK_MAX_SIZE];
     
    442412        {
    443413          /* Set timings to read the remaining block */
    444           Protocol_T1_UpdateBWT (t1->cwt);
     414          Protocol_T1_UpdateBWT (cwt);
    445415
    446416          /* Receive remaining bytes */
     
    459429
    460430          /* Restore timings */
    461           Protocol_T1_UpdateBWT (t1->bwt);
     431          Protocol_T1_UpdateBWT (bwt);
    462432        }
    463433      else
     
    469439
    470440  return ret;
    471 }
    472 
    473 static void
    474 Protocol_T1_Clear (Protocol_T1 * t1)
    475 {
    476   t1->ifsc = 0;
    477   t1->ifsd = 0;
    478   t1->bgt = 0;
    479   t1->bwt = 0;
    480   t1->cwt = 0;
    481   t1->edc = 0;
    482   t1->ns = 0;
    483441}
    484442
  • trunk/csctapi/protocol_t1.h

    r1279 r1283  
    4545 */
    4646
    47 /* T=1 Protocol context */
    48 typedef struct
    49 {
    50   unsigned short ifsc;  /* Information field size for the ICC */
    51   unsigned short ifsd;  /* Information field size for the IFD */
    52   unsigned short bgt;   /* Block guard time */
    53   unsigned short bwt;   /* Block waiting time */
    54   unsigned short cwt;   /* Character waiting time */
    55   int edc;              /* Type of error detection code */
    56   BYTE ns;              /* Send sequence number */
    57 }
    58 Protocol_T1;
    59 
     47unsigned short ifsc;  /* Information field size for the ICC */
     48unsigned short ifsd;  /* Information field size for the IFD */
     49unsigned short bgt;   /* Block guard time */
     50unsigned short bwt;   /* Block waiting time */
     51unsigned short cwt;   /* Character waiting time */
     52int edc;              /* Type of error detection code */
     53BYTE ns;              /* Send sequence number */
    6054/*
    6155 * Exported functions declaration
    6256 */
    6357
    64 /* Create a new protocol handler */
    65 extern Protocol_T1 *
    66 Protocol_T1_New (void);
    67 
    68 /* Delete a protocol handler */
    69 extern void
    70 Protocol_T1_Delete (Protocol_T1 * t1);
    71 
    7258/* Initialise a protocol handler */
    7359extern int
    74 Protocol_T1_Init (Protocol_T1 * t1, int selected_protocol);
     60Protocol_T1_Init ();
    7561
    7662/* Send a command and return a response */
    7763extern int
    78 Protocol_T1_Command (Protocol_T1 * t1, APDU_Cmd * cmd, APDU_Rsp ** rsp);
    79 
    80 /* Close a protocol handler */
    81 extern int
    82 Protocol_T1_Close (Protocol_T1 * t1);
     64Protocol_T1_Command (APDU_Cmd * cmd, APDU_Rsp ** rsp);
    8365
    8466#endif /* _PROTOCOL_T1_ */
Note: See TracChangeset for help on using the changeset viewer.