Changeset 1280


Ignore:
Timestamp:
01/18/10 17:53:21 (11 years ago)
Author:
rorothetroll
Message:

resync with trunk

Location:
branches/smartreader/csctapi
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • branches/smartreader/csctapi/config.h

    r1186 r1280  
    9191/* #undef ICC_TYPE_SYNC */
    9292
    93 /* Smartcard with direct convention */
    94 /* #undef IFD_TOWITOKO_CONVENTION_DIRECT */
    95 
    96 /* Smartcard with inverse convention */
    97 /* #undef IFD_TOWITOKO_CONVENTION_INVERSE */
    98 
    9993/* ATR for asynchronous cards is cheked */
    10094#define IFD_TOWITOKO_STRICT_ATR_CHECK 1
  • branches/smartreader/csctapi/ct_slot.c

    r1271 r1280  
    121121    unsigned buffer_len  = 0;
    122122   
    123     /* Initiaice ICC */
    124     slot->icc = ICC_Async_New ();
    125    
    126     if (slot->icc == NULL)
    127         return ERR_MEMORY;
    128    
    129     if (ICC_Async_Init (slot->icc) != ICC_ASYNC_OK)
    130     {
    131         ICC_Async_Delete (slot->icc);
    132                
    133         slot->icc = NULL;
    134         slot->icc_type = CT_SLOT_NULL;
     123    if (ICC_Async_Init () != ICC_ASYNC_OK)
     124    {
    135125        return ERR_TRANS;
    136126       
     
    148138    if (slot->icc_type == CT_SLOT_ICC_ASYNC)
    149139    {
    150         pps = PPS_New((ICC_Async *) slot->icc);
     140        pps = PPS_New();
    151141       
    152142        if (pps == NULL)
    153143        {
    154             ICC_Async_Close ((ICC_Async *) slot->icc);
    155             ICC_Async_Delete ((ICC_Async *) slot->icc);
     144            ICC_Async_Close ();
    156145           
    157146            slot->icc = NULL;
     
    169158            PPS_Delete (pps);
    170159           
    171             ICC_Async_Close ((ICC_Async *) slot->icc);
    172             ICC_Async_Delete ((ICC_Async *) slot->icc);
     160            ICC_Async_Close ();
    173161           
    174162            slot->icc = NULL;
     
    222210    if (slot->icc_type == CT_SLOT_ICC_ASYNC)
    223211    {
    224         if (ICC_Async_Close ((ICC_Async *) slot->icc) != ICC_ASYNC_OK)
    225             ret = ERR_TRANS;
    226        
    227         ICC_Async_Delete ((ICC_Async *) slot->icc);
     212        if (ICC_Async_Close () != ICC_ASYNC_OK)
     213            ret = ERR_TRANS;
    228214    }
    229215   
     
    241227    if (slot->protocol_type == CT_SLOT_PROTOCOL_T0) /* T=0 protocol ICC */
    242228    {
    243         if (Protocol_T0_Command ((Protocol_T0 *) slot->protocol, cmd, rsp) != PROTOCOL_T0_OK)
     229        if (Protocol_T0_Command ( cmd, rsp) != PROTOCOL_T0_OK)
    244230            ret = ERR_TRANS;
    245231        else
     
    255241    else if (slot->protocol_type == CT_SLOT_PROTOCOL_T14) /* T=14 protocol ICC */
    256242    {
    257         if (Protocol_T14_Command ((Protocol_T14 *) slot->protocol, cmd, rsp) != PROTOCOL_T14_OK)
     243        if (Protocol_T14_Command (cmd, rsp) != PROTOCOL_T14_OK)
    258244            ret = ERR_TRANS;
    259245        else
     
    290276{
    291277    if (slot->icc_type == CT_SLOT_ICC_ASYNC)
    292         return ((void *) ICC_Async_GetAtr((ICC_Async *) slot->icc));
     278        return ((void *) atr );
     279        //return ((void *) ICC_Async_GetAtr((ICC_Async *) slot->icc));
    293280   
    294281    return NULL;
     
    338325    if (slot->icc_type == CT_SLOT_ICC_ASYNC)
    339326    {
    340         if (ICC_Async_Close ((ICC_Async *) slot->icc) != ICC_ASYNC_OK)
    341             ret = ERR_TRANS;
    342        
    343         ICC_Async_Delete ((ICC_Async *) slot->icc);
     327        if (ICC_Async_Close () != ICC_ASYNC_OK)
     328            ret = ERR_TRANS;
    344329    }
    345330   
  • branches/smartreader/csctapi/icc_async.c

    r1271 r1280  
    4343
    4444static void ICC_Async_InvertBuffer (unsigned size, BYTE * buffer);
    45 static void ICC_Async_Clear (ICC_Async * icc);
     45static void ICC_Async_Clear ();
    4646
    4747int fdmc=(-1);
     
    5050 * Exported functions definition
    5151 */
    52 
    53 ICC_Async *ICC_Async_New (void)
    54 {
    55     ICC_Async *icc;
    56    
    57     /* Allocate memory */
    58     icc = (ICC_Async *) malloc (sizeof (ICC_Async));
    59    
    60     if (icc != NULL)
    61         ICC_Async_Clear (icc);
    62    
    63     return icc;
    64 }
    6552
    6653int ICC_Async_Device_Init ()
     
    196183}
    197184
    198 int ICC_Async_Init (ICC_Async * icc)
     185int ICC_Async_Init ()
    199186{
    200187#ifndef ICC_TYPE_SYNC
     
    211198    /* Reset ICC */
    212199    if (reader[ridx].typ == R_INTERNAL) {
    213         if (!Sci_Reset(&(icc->atr)))
    214         {
    215             icc->atr = NULL;
     200        if (!Sci_Reset(&(atr)))
     201        {
     202            atr = NULL;
    216203            return ICC_ASYNC_IFD_ERROR;
    217204        }
     
    221208#ifdef COOL
    222209    if (reader[ridx].typ == R_INTERNAL) {
    223         if (!Cool_Reset(&(icc->atr)))
    224         {
    225             icc->atr = NULL;
    226             return ICC_ASYNC_IFD_ERROR;
    227         }
    228     }
    229     else
    230 #endif
    231     if (!Phoenix_Reset(&(icc->atr)))
    232     {
    233         icc->atr = NULL;
     210        if (!Cool_Reset(&(atr)))
     211        {
     212            atr = NULL;
     213            return ICC_ASYNC_IFD_ERROR;
     214        }
     215    }
     216    else
     217#endif
     218    if (!Phoenix_Reset(&(atr)))
     219    {
     220        atr = NULL;
    234221        return ICC_ASYNC_IFD_ERROR;
    235222    }
    236223    /* Get ICC convention */
    237     if (ATR_GetConvention (icc->atr, &(icc->convention)) != ATR_OK)
    238     {
    239         ATR_Delete (icc->atr);
    240         icc->atr = NULL;
    241         icc->convention = 0;
     224    if (ATR_GetConvention (atr, &(convention)) != ATR_OK)
     225    {
     226        ATR_Delete (atr);
     227        atr = NULL;
     228        convention = 0;
    242229       
    243230        return ICC_ASYNC_ATR_ERROR;
    244231    }
    245232   
    246     icc->protocol_type = ATR_PROTOCOL_TYPE_T0;
    247    
    248     ATR_GetNumberOfProtocols (icc->atr, &np);
     233    protocol_type = ATR_PROTOCOL_TYPE_T0;
     234   
     235    ATR_GetNumberOfProtocols (atr, &np);
    249236   
    250237    /*
     
    253240    */
    254241/*  if (np>1)
    255         ATR_GetProtocolType (icc->atr, 1, &(icc->protocol_type));
     242        ATR_GetProtocolType (atr, 1, &(protocol_type));
    256243   
    257244#ifdef DEBUG_ICC
    258     printf("ICC: Detected %s convention processor card T=%d\n",(icc->convention == ATR_CONVENTION_DIRECT ? "direct" : "inverse"), icc->protocol_type);
     245    printf("ICC: Detected %s convention processor card T=%d\n",(convention == ATR_CONVENTION_DIRECT ? "direct" : "inverse"), protocol_type);
    259246#endif
    260247    *///really should let PPS handle this
    261248   
    262249    /* Initialize member variables */
    263     icc->baudrate = ICC_ASYNC_BAUDRATE;
    264    
    265     if (icc->convention == ATR_CONVENTION_INVERSE)
     250    if (convention == ATR_CONVENTION_INVERSE)
    266251    {
    267252        if (!IO_Serial_SetParity (PARITY_ODD))
    268253            return ICC_ASYNC_IFD_ERROR;
    269254    }
    270     else if(icc->protocol_type == ATR_PROTOCOL_TYPE_T14)
     255    else if(protocol_type == ATR_PROTOCOL_TYPE_T14)
    271256    {
    272257        if (!IO_Serial_SetParity (PARITY_NONE))
     
    288273}
    289274
    290 int ICC_Async_SetTimings (ICC_Async * icc, ICC_Async_Timings * timings)
    291 {
    292     icc->timings.block_delay = timings->block_delay;
    293     icc->timings.char_delay = timings->char_delay;
    294     icc->timings.block_timeout = timings->block_timeout;
    295     icc->timings.char_timeout = timings->char_timeout;
    296 /*  if (icc->protocol_type == ATR_PROTOCOL_TYPE_T1)
     275int ICC_Async_SetTimings ()
     276{
     277/*  if (protocol_type == ATR_PROTOCOL_TYPE_T1)
    297278        cs_debug("SetTimings: T1: chardelay %d, chartimeout CWT %d, blockdelay BGT??? %d, blocktimeout BWT %d",timings->char_delay,timings->char_timeout, timings->block_delay, timings->block_timeout);
    298279    else
     
    307288        if (ioctl(reader[ridx].handle, IOCTL_GET_PARAMETERS, &params) < 0 )
    308289            return ICC_ASYNC_IFD_ERROR;
    309         switch (icc->protocol_type) {
     290        switch (protocol_type) {
    310291            case ATR_PROTOCOL_TYPE_T1:
    311                 params.BWT = icc->timings.block_timeout;
    312                 params.CWT = icc->timings.char_timeout;
    313                 //params.BGT = icc->timings.block_delay; load into params.EGT??
     292                params.BWT = icc_timings.block_timeout;
     293                params.CWT = icc_timings.char_timeout;
     294                //params.BGT = icc_timings.block_delay; load into params.EGT??
    314295                break;
    315296            case ATR_PROTOCOL_TYPE_T0:
    316297            case ATR_PROTOCOL_TYPE_T14:
    317298            default:
    318             params.WWT = icc->timings.char_timeout;
     299            params.WWT = icc_timings.char_timeout;
    319300                break;
    320301        }
     
    328309}
    329310
    330 int ICC_Async_GetTimings (ICC_Async * icc, ICC_Async_Timings * timings)
    331 {
    332     timings->block_delay = icc->timings.block_delay;
    333     timings->char_delay = icc->timings.char_delay;
    334     timings->block_timeout = icc->timings.block_timeout;
    335     timings->char_timeout = icc->timings.char_timeout;
    336    
    337     return ICC_ASYNC_OK;
    338 }
    339 
    340 int ICC_Async_SetBaudrate (ICC_Async * icc, unsigned long baudrate)
    341 {
    342     icc->baudrate = baudrate;
     311int ICC_Async_SetBaudrate (unsigned long baudrate)
     312{
    343313    if (!Phoenix_SetBaudrate (baudrate))
    344314      return ICC_ASYNC_IFD_ERROR;
     
    347317}
    348318
    349 int ICC_Async_GetBaudrate (ICC_Async * icc, unsigned long * baudrate)
    350 {
    351     (*baudrate) = icc->baudrate;
     319int ICC_Async_GetBaudrate (unsigned long * baudrate)
     320{
     321    (*baudrate) = reader[ridx].baudrate;
    352322    return ICC_ASYNC_OK; 
    353323}
    354324
    355 int ICC_Async_Transmit (ICC_Async * icc, unsigned size, BYTE * data)
     325int ICC_Async_Transmit (unsigned size, BYTE * data)
    356326{
    357327    BYTE *buffer = NULL, *sent;
    358328    IFD_Timings timings;
    359329   
    360     if (icc->convention == ATR_CONVENTION_INVERSE && reader[ridx].typ != R_INTERNAL)
     330    if (convention == ATR_CONVENTION_INVERSE && reader[ridx].typ != R_INTERNAL)
    361331    {
    362332        buffer = (BYTE *) calloc(sizeof (BYTE), size);
     
    370340    }
    371341   
    372     timings.block_delay = icc->timings.block_delay;
    373     timings.char_delay = icc->timings.char_delay;
     342    timings.block_delay = icc_timings.block_delay;
     343    timings.char_delay = icc_timings.char_delay;
    374344   
    375345#ifdef COOL
     
    383353        return ICC_ASYNC_IFD_ERROR;
    384354   
    385     if (icc->convention == ATR_CONVENTION_INVERSE)
     355    if (convention == ATR_CONVENTION_INVERSE)
    386356        free (buffer);
    387357   
     
    389359}
    390360
    391 int ICC_Async_Receive (ICC_Async * icc, unsigned size, BYTE * data)
     361int ICC_Async_Receive (unsigned size, BYTE * data)
    392362{
    393363    IFD_Timings timings;
    394364   
    395     timings.block_timeout = icc->timings.block_timeout;
    396     timings.char_timeout = icc->timings.char_timeout;
     365    timings.block_timeout = icc_timings.block_timeout;
     366    timings.char_timeout = icc_timings.char_timeout;
    397367   
    398368#ifdef COOL
     
    407377#endif
    408378   
    409     if (icc->convention == ATR_CONVENTION_INVERSE && reader[ridx].typ != R_INTERNAL)
     379    if (convention == ATR_CONVENTION_INVERSE && reader[ridx].typ != R_INTERNAL)
    410380        ICC_Async_InvertBuffer (size, data);
    411381   
     
    413383}
    414384
    415 ATR * ICC_Async_GetAtr (ICC_Async * icc)
    416 {
    417     return icc->atr;
    418 }
    419 
    420 int ICC_Async_Close (ICC_Async * icc)
     385int ICC_Async_Close ()
    421386{
    422387#ifdef SCI_DEV
     
    427392   
    428393    /* Delete atr */
    429     ATR_Delete (icc->atr);
    430    
    431     ICC_Async_Clear (icc);
     394    ATR_Delete (atr);
     395   
     396    ICC_Async_Clear ();
    432397   
    433398    return ICC_ASYNC_OK;
     
    447412}
    448413
    449 void ICC_Async_Delete (ICC_Async * icc)
    450 {
    451     free (icc);
    452 }
    453 
    454414/*
    455415 * Not exported functions definition
     
    464424}
    465425
    466 static void ICC_Async_Clear (ICC_Async * icc)
    467 {
    468     icc->atr = NULL;
    469     icc->baudrate = 0L;
    470     icc->convention = 0;
    471     icc->protocol_type = -1;
    472     icc->timings.block_delay = 0;
    473     icc->timings.char_delay = 0;
    474     icc->timings.block_timeout = 0;
    475     icc->timings.char_timeout = 0;
    476 }
     426static void ICC_Async_Clear ()
     427{
     428    atr = NULL;
     429    convention = 0;
     430    protocol_type = -1;
     431    icc_timings.block_delay = 0;
     432    icc_timings.char_delay = 0;
     433    icc_timings.block_timeout = 0;
     434    icc_timings.char_timeout = 0;
     435}
  • branches/smartreader/csctapi/icc_async.h

    r1271 r1280  
    5858}
    5959ICC_Async_Timings;
    60 
     60/*
    6161typedef struct
    6262{
    63   ATR *atr;                     /* Answer to reset of this ICC */
    64   int convention;               /* Convention of this ICC */
    65   unsigned long baudrate;   /* Current baudrate (bps) for transmiting to this ICC */
    66   ICC_Async_Timings timings;    /* Current timings for transmiting to this ICC */
    67   BYTE protocol_type;       /* Type of protocol */
    6863}
    6964ICC_Async;
     65*/
     66ATR *atr;                     /* Answer to reset of this ICC */
     67int convention;               /* Convention of this ICC */
     68BYTE protocol_type;     /* Type of protocol */
     69ICC_Async_Timings icc_timings;    /* Current timings for transmiting to this ICC */
    7070
    7171/*
     
    7373 */
    7474
    75 /* Creation and Deletion */
    76 extern ICC_Async * ICC_Async_New (void);
    77 extern void ICC_Async_Delete (ICC_Async * icc);
    78 
    7975/* Initialization and Deactivation */
    80 extern int ICC_Async_Init (ICC_Async * icc);
    81 extern int ICC_Async_Close (ICC_Async * icc);
     76extern int ICC_Async_Init ();
     77extern int ICC_Async_Close ();
    8278
    8379/* Attributes */
    84 extern int ICC_Async_SetTimings (ICC_Async * icc, ICC_Async_Timings * timings);
    85 extern int ICC_Async_GetTimings (ICC_Async * icc, ICC_Async_Timings * timings);
    86 extern int ICC_Async_SetBaudrate (ICC_Async * icc, unsigned long baudrate);
    87 extern int ICC_Async_GetBaudrate (ICC_Async * icc, unsigned long * baudrate);
    88 extern ATR *ICC_Async_GetAtr (ICC_Async * icc);
     80extern int ICC_Async_SetTimings ();
     81extern int ICC_Async_SetBaudrate (unsigned long baudrate);
     82extern int ICC_Async_GetBaudrate (unsigned long * baudrate);
    8983extern unsigned long ICC_Async_GetClockRate ();
    9084
    9185/* Operations */
    92 extern int ICC_Async_Transmit (ICC_Async * icc, unsigned size, BYTE * buffer);
    93 extern int ICC_Async_Receive (ICC_Async * icc, unsigned size, BYTE * buffer);
     86extern int ICC_Async_Transmit (unsigned size, BYTE * buffer);
     87extern int ICC_Async_Receive (unsigned size, BYTE * buffer);
    9488
    9589#endif /* _ICC_ASYNC_ */
  • branches/smartreader/csctapi/ifd_phoenix.c

    r1271 r1280  
    283283int Phoenix_SetBaudrate (unsigned long baudrate)
    284284{
    285     if(reader[ridx].typ == R_INTERNAL)
    286         return OK;
    287 
    288285#ifdef DEBUG_IFD
    289286    printf ("IFD: Setting baudrate to %lu\n", baudrate);
    290287#endif
    291     if (reader[ridx].baudrate   == baudrate)
    292         return OK;
    293 
    294     /* Get current settings */
    295     struct termios tio;
    296     if (tcgetattr (reader[ridx].handle, &tio) != 0)
    297         return ERROR;
    298    
    299     //write baudrate here!
    300     if (!IO_Serial_SetBitrate (baudrate, &tio))
    301         return ERROR;
    302    
    303     if (!IO_Serial_SetProperties(tio))
    304         return ERROR;
    305    
     288    if ((reader[ridx].typ != R_INTERNAL) && (reader[ridx].baudrate  != baudrate))
     289    {
     290        /* Get current settings */
     291        struct termios tio;
     292        if (tcgetattr (reader[ridx].handle, &tio) != 0)
     293            return ERROR;
     294   
     295        //write baudrate here!
     296        if (!IO_Serial_SetBitrate (baudrate, &tio))
     297            return ERROR;
     298   
     299        if (!IO_Serial_SetProperties(tio))
     300            return ERROR;
     301    }
    306302    reader[ridx].baudrate = baudrate;
    307    
    308303    return OK;
    309304}
  • branches/smartreader/csctapi/pps.c

    r1239 r1280  
    5151 */
    5252
    53 static int PPS_Exchange (PPS * pps, BYTE * params, unsigned *length);
     53static int PPS_Exchange (BYTE * params, unsigned *length);
    5454
    5555static bool PPS_Match (BYTE * request, unsigned len_request, BYTE * reply, unsigned len_reply);
     
    6767 */
    6868
    69 PPS * PPS_New (ICC_Async * icc)
     69PPS * PPS_New ()
    7070{
    7171    PPS *pps;
     
    7575    if (pps != NULL)
    7676    {
    77         pps->icc = icc;
    7877        pps->protocol = NULL;
    7978        pps->parameters.t = PPS_DEFAULT_PROTOCOL;
     
    10099    //also from FI -> F is easy, other way around not
    101100   
    102     ATR *atr;
    103101    int ret;
    104102    bool PPS_success;
     
    107105    if ((*length) > 0)
    108106    {
    109         ret = PPS_Exchange (pps, params, length);
     107        ret = PPS_Exchange (params, length);
    110108       
    111109        /* Get parameters from PPS handsake */
     
    136134    PPS_success = PPS_OK;
    137135    int protocol_selected = 0; //stores which TAi,TBi etc. bytes must be used 0 means not set
    138     atr = ICC_Async_GetAtr (pps->icc);
    139136    if ((*length) <= 0 || !PPS_success) // If not by command, or PPS Exchange by command failed: Try PPS Exchange by ATR or Get parameters from ATR
    140137    {
     
    225222            //req[3]=PPS_GetPCK(req,sizeof(req)-1); will be set by PPS_Exchange
    226223                unsigned int len = sizeof(req);
    227                 ret = PPS_Exchange (pps, req, &len);
     224                ret = PPS_Exchange (req, &len);
    228225            if (ret == PPS_OK) {
    229226                    pps->parameters.FI = req[2] >> 4;
     
    275272    }
    276273
    277     pps->icc->protocol_type = pps->parameters.t;
     274    protocol_type = pps->parameters.t;
    278275   
    279276#ifdef DEBUG_PROTOCOL
     
    319316 */
    320317
    321 static int PPS_Exchange (PPS * pps, BYTE * params, unsigned *length)
     318static int PPS_Exchange (BYTE * params, unsigned *length)
    322319{
    323320    BYTE confirm[PPS_MAX_LENGTH];
     
    363360        return PPS_HANDSAKE_ERROR;
    364361#else
    365     if (ICC_Async_Transmit (pps->icc, len_request, params) != ICC_ASYNC_OK)
     362    if (ICC_Async_Transmit (len_request, params) != ICC_ASYNC_OK)
    366363        return PPS_ICC_ERROR;
    367364   
    368365    /* Get PPS confirm */
    369     if (ICC_Async_Receive (pps->icc, 2, confirm) != ICC_ASYNC_OK)
     366    if (ICC_Async_Receive (2, confirm) != ICC_ASYNC_OK)
    370367        return PPS_ICC_ERROR;
    371368   
    372369    len_confirm = PPS_GetLength (confirm);
    373370   
    374     if (ICC_Async_Receive (pps->icc, len_confirm - 2, confirm + 2) != ICC_ASYNC_OK)
     371    if (ICC_Async_Receive (len_confirm - 2, confirm + 2) != ICC_ASYNC_OK)
    375372        return PPS_ICC_ERROR;
    376373   
     
    439436        if (ioctl(reader[ridx].handle, IOCTL_GET_PARAMETERS, &params) < 0 )
    440437            return PPS_ICC_ERROR;
    441 
    442         ATR *atr = ICC_Async_GetAtr (pps->icc);
    443438
    444439        params.T = pps->parameters.t;
     
    489484   
    490485
    491     if (ICC_Async_SetBaudrate (pps->icc, baudrate) != ICC_ASYNC_OK)
     486    if (ICC_Async_SetBaudrate (baudrate) != ICC_ASYNC_OK)
    492487        return PPS_ICC_ERROR;
    493488   
     
    506501        if ((pps->protocol) != NULL)
    507502        {
    508             ret = Protocol_T0_Init ((Protocol_T0 *) pps->protocol, (ICC_Async *) pps->icc, &(pps->parameters), selected_protocol);
     503            ret = Protocol_T0_Init ((Protocol_T0 *) pps->protocol, &(pps->parameters), selected_protocol);
    509504           
    510505            if (ret != PROTOCOL_T0_OK)
     
    524519        if (pps->protocol != NULL)
    525520        {
    526             ret = Protocol_T1_Init ((Protocol_T1 *) pps->protocol, (ICC_Async *) pps->icc, selected_protocol);
     521            ret = Protocol_T1_Init ((Protocol_T1 *) pps->protocol, selected_protocol);
    527522           
    528523            if (ret != PROTOCOL_T1_OK)
     
    542537        if ((pps->protocol) != NULL)
    543538        {
    544             ret = Protocol_T14_Init ((Protocol_T14 *) pps->protocol, (ICC_Async *) pps->icc, &(pps->parameters), selected_protocol);
     539            ret = Protocol_T14_Init ((Protocol_T14 *) pps->protocol, &(pps->parameters), selected_protocol);
    545540           
    546541            if (ret != PROTOCOL_T14_OK)
  • branches/smartreader/csctapi/pps.h

    r842 r1280  
    5353typedef struct
    5454{
    55   ICC_Async *icc;
    5655  void *protocol;
    5756  PPS_ProtocolParameters parameters;
     
    6463
    6564/* Create PPS context */
    66 extern PPS *PPS_New (ICC_Async * icc);
     65extern PPS *PPS_New ();
    6766
    6867/* Perform protcol type selection and return confirm */
  • branches/smartreader/csctapi/protocol_t0.c

    r1239 r1280  
    5555static void Protocol_T14_Clear (Protocol_T14 * t14);
    5656
    57 static int Protocol_T0_Case1 (Protocol_T0 * t0, APDU_Cmd * cmd, APDU_Rsp ** rsp);
    58 
    59 static int Protocol_T0_Case2S (Protocol_T0 * t0, APDU_Cmd * cmd, APDU_Rsp ** rsp);
    60 static int Protocol_T14_Case2S (Protocol_T14 * t14, APDU_Cmd * cmd, APDU_Rsp ** rsp);
    61 
    62 static int Protocol_T0_Case3S (Protocol_T0 * t0, APDU_Cmd * cmd, APDU_Rsp ** rsp);
    63 static int Protocol_T14_Case3S (Protocol_T14 * t14, APDU_Cmd * cmd, APDU_Rsp ** rsp);
    64 
    65 static int Protocol_T0_Case4S (Protocol_T0 * t0, APDU_Cmd * cmd, APDU_Rsp ** rsp);
    66 
    67 static int Protocol_T0_Case2E (Protocol_T0 * t0, APDU_Cmd * cmd, APDU_Rsp ** rsp);
    68 
    69 static int Protocol_T0_Case3E (Protocol_T0 * t0, APDU_Cmd * cmd, APDU_Rsp ** rsp);
    70 
    71 static int Protocol_T0_Case4E (Protocol_T0 * t0, APDU_Cmd * cmd, APDU_Rsp ** rsp);
    72 
    73 static int Protocol_T0_ExchangeTPDU (Protocol_T0 * t0, APDU_Cmd * cmd, APDU_Rsp ** rsp);
    74 static int Protocol_T14_ExchangeTPDU (Protocol_T14 * t14, APDU_Cmd * cmd, APDU_Rsp ** rsp);
     57static int Protocol_T0_Case1 (APDU_Cmd * cmd, APDU_Rsp ** rsp);
     58
     59static int Protocol_T0_Case2S (APDU_Cmd * cmd, APDU_Rsp ** rsp);
     60static int Protocol_T14_Case2S (APDU_Cmd * cmd, APDU_Rsp ** rsp);
     61
     62static int Protocol_T0_Case3S (APDU_Cmd * cmd, APDU_Rsp ** rsp);
     63static int Protocol_T14_Case3S (APDU_Cmd * cmd, APDU_Rsp ** rsp);
     64
     65static int Protocol_T0_Case4S (APDU_Cmd * cmd, APDU_Rsp ** rsp);
     66
     67static int Protocol_T0_Case2E (APDU_Cmd * cmd, APDU_Rsp ** rsp);
     68
     69static int Protocol_T0_Case3E (APDU_Cmd * cmd, APDU_Rsp ** rsp);
     70
     71static int Protocol_T0_Case4E (APDU_Cmd * cmd, APDU_Rsp ** rsp);
     72
     73static int Protocol_T0_ExchangeTPDU (APDU_Cmd * cmd, APDU_Rsp ** rsp);
     74static int Protocol_T14_ExchangeTPDU (APDU_Cmd * cmd, APDU_Rsp ** rsp);
    7575
    7676/*
     
    102102}
    103103
    104 int Protocol_T0_Init (Protocol_T0 * t0, ICC_Async * icc, PPS_ProtocolParameters * params, int selected_protocol)
    105 {
    106     ICC_Async_Timings timings;
     104int Protocol_T0_Init (Protocol_T0 * t0, PPS_ProtocolParameters * params, int selected_protocol)
     105{
    107106    BYTE wi;
    108 #ifndef PROTOCOL_T0_USE_DEFAULT_TIMINGS
    109     ATR *atr = ICC_Async_GetAtr (icc);
    110 #endif
    111    
    112     /* Set ICC */
    113     t0->icc = icc;
    114107   
    115108    /* Integer value WI  = TC2, by default 10 */
     
    124117   
    125118    /* Set timings */
    126     ICC_Async_GetTimings (t0->icc, &timings);
    127    
    128     timings.block_timeout = t0->wwt;
    129     timings.char_timeout = t0->wwt;
    130    
    131     ICC_Async_SetTimings (t0->icc, &timings);
     119    icc_timings.block_timeout = t0->wwt;
     120    icc_timings.char_timeout = t0->wwt;
     121    ICC_Async_SetTimings ();
    132122   
    133123#ifdef DEBUG_PROTOCOL
     
    138128}
    139129
    140 int Protocol_T14_Init (Protocol_T14 * t14, ICC_Async * icc, PPS_ProtocolParameters * params, int selected_protocol)
    141 {
    142     ICC_Async_Timings timings;
     130int Protocol_T14_Init (Protocol_T14 * t14, PPS_ProtocolParameters * params, int selected_protocol)
     131{
    143132    BYTE wi;
    144 #ifndef PROTOCOL_T14_USE_DEFAULT_TIMINGS
    145     ATR *atr = ICC_Async_GetAtr (icc);
    146 #endif
    147    
    148     /* Set ICC */
    149     t14->icc = icc;
    150133   
    151134    /* Integer value WI  = TC2, by default 10 */
     
    161144   
    162145    /* Set timings */
    163     ICC_Async_GetTimings (t14->icc, &timings);
    164    
    165     timings.block_timeout = t14->wwt;
    166     timings.char_timeout = t14->wwt;
    167    
    168     ICC_Async_SetTimings (t14->icc, &timings);
    169    
     146    icc_timings.block_timeout = t14->wwt;
     147    icc_timings.char_timeout = t14->wwt;
     148    ICC_Async_SetTimings ();
     149
    170150#ifdef DEBUG_PROTOCOL
    171151    printf ("Protocol: T=14: WWT=%d\n", (int)(t14->wwt));
     
    175155}
    176156
    177 int Protocol_T0_Command (Protocol_T0 * t0, APDU_Cmd * cmd, APDU_Rsp ** rsp)
     157int Protocol_T0_Command (APDU_Cmd * cmd, APDU_Rsp ** rsp)
    178158{
    179159    int cmd_case, ret;
     
    187167   
    188168    if (cmd_case == APDU_CASE_1)
    189         ret = Protocol_T0_Case1 (t0, cmd, rsp);
     169        ret = Protocol_T0_Case1 (cmd, rsp);
    190170    else if (cmd_case == APDU_CASE_2S)
    191         ret = Protocol_T0_Case2S (t0, cmd, rsp);
     171        ret = Protocol_T0_Case2S (cmd, rsp);
    192172    else if (cmd_case == APDU_CASE_3S)
    193         ret = Protocol_T0_Case3S (t0, cmd, rsp);
     173        ret = Protocol_T0_Case3S (cmd, rsp);
    194174    else if (cmd_case == APDU_CASE_4S)
    195         ret = Protocol_T0_Case4S (t0, cmd, rsp);
     175        ret = Protocol_T0_Case4S (cmd, rsp);
    196176    else if (cmd_case == APDU_CASE_2E)
    197         ret = Protocol_T0_Case2E (t0, cmd, rsp);
     177        ret = Protocol_T0_Case2E (cmd, rsp);
    198178    else if (cmd_case == APDU_CASE_3E)
    199         ret = Protocol_T0_Case3E (t0, cmd, rsp);
     179        ret = Protocol_T0_Case3E (cmd, rsp);
    200180    else if (cmd_case == APDU_CASE_4E)
    201         ret = Protocol_T0_Case4E (t0, cmd, rsp);
     181        ret = Protocol_T0_Case4E (cmd, rsp);
    202182    else
    203183    {
     
    211191}
    212192
    213 int Protocol_T14_Command (Protocol_T14 * t14, APDU_Cmd * cmd, APDU_Rsp ** rsp)
     193int Protocol_T14_Command (APDU_Cmd * cmd, APDU_Rsp ** rsp)
    214194{
    215195    int cmd_case, ret;
     
    224204    if (cmd_case == APDU_CASE_2S)
    225205    {
    226         ret = Protocol_T14_Case2S (t14, cmd, rsp);
     206        ret = Protocol_T14_Case2S (cmd, rsp);
    227207    }
    228208    else if (cmd_case == APDU_CASE_3S)
    229209    {
    230         ret = Protocol_T14_Case3S (t14, cmd, rsp);
     210        ret = Protocol_T14_Case3S (cmd, rsp);
    231211    }
    232212    else
     
    269249 */
    270250
    271 static int Protocol_T0_Case1 (Protocol_T0 * t0, APDU_Cmd * cmd, APDU_Rsp ** rsp)
     251static int Protocol_T0_Case1 (APDU_Cmd * cmd, APDU_Rsp ** rsp)
    272252{
    273253    int ret;
     
    282262   
    283263    /* Send command TPDU */
    284     ret = Protocol_T0_ExchangeTPDU (t0, tpdu_cmd, rsp);
     264    ret = Protocol_T0_ExchangeTPDU(tpdu_cmd, rsp);
    285265   
    286266    /* Delete command TPDU */
     
    291271
    292272
    293 static int Protocol_T0_Case2S (Protocol_T0 * t0, APDU_Cmd * cmd, APDU_Rsp ** rsp)
     273static int Protocol_T0_Case2S (APDU_Cmd * cmd, APDU_Rsp ** rsp)
    294274{
    295275    int ret;
    296276   
    297277    /* Send command TPDU */
    298     ret = Protocol_T0_ExchangeTPDU (t0, cmd, rsp);
     278    ret = Protocol_T0_ExchangeTPDU(cmd, rsp);
    299279   
    300280    return ret;
    301281}
    302282
    303 static int Protocol_T14_Case2S (Protocol_T14 * t14, APDU_Cmd * cmd, APDU_Rsp ** rsp)
     283static int Protocol_T14_Case2S (APDU_Cmd * cmd, APDU_Rsp ** rsp)
    304284{
    305285    int ret;
    306286   
    307287    /* Send command TPDU */
    308     ret = Protocol_T14_ExchangeTPDU (t14, cmd, rsp);
     288    ret = Protocol_T14_ExchangeTPDU(cmd, rsp);
    309289   
    310290    return ret;
    311291}
    312292
    313 static int Protocol_T0_Case3S (Protocol_T0 * t0, APDU_Cmd * cmd, APDU_Rsp ** rsp)
     293static int Protocol_T0_Case3S (APDU_Cmd * cmd, APDU_Rsp ** rsp)
    314294{
    315295    int ret;
     
    321301   
    322302    /* Send command TPDU */
    323     ret = Protocol_T0_ExchangeTPDU (t0, cmd, (&tpdu_rsp));
     303    ret = Protocol_T0_ExchangeTPDU(cmd, (&tpdu_rsp));
    324304   
    325305    if (ret == PROTOCOL_T0_OK)
     
    344324           
    345325            /* Re-issue command TPDU */
    346             ret = Protocol_T0_ExchangeTPDU (t0, tpdu_cmd, rsp);
     326            ret = Protocol_T0_ExchangeTPDU(tpdu_cmd, rsp);
    347327           
    348328            /* Delete command TPDU */
     
    375355                tpdu_cmd = APDU_Cmd_New (buffer, 5);
    376356               
    377                 ret = Protocol_T0_ExchangeTPDU (t0, tpdu_cmd, (&tpdu_rsp));
     357                ret = Protocol_T0_ExchangeTPDU(tpdu_cmd, (&tpdu_rsp));
    378358               
    379359                /* Delete command TPDU */
     
    414394}
    415395
    416 static int Protocol_T14_Case3S (Protocol_T14 * t14, APDU_Cmd * cmd, APDU_Rsp ** rsp)
     396static int Protocol_T14_Case3S (APDU_Cmd * cmd, APDU_Rsp ** rsp)
    417397{
    418398    int ret;
    419399   
    420400    /* Send command TPDU */
    421     ret = Protocol_T14_ExchangeTPDU (t14, cmd, rsp);
     401    ret = Protocol_T14_ExchangeTPDU(cmd, rsp);
    422402   
    423403    return ret;
    424404}
    425405
    426 static int Protocol_T0_Case4S (Protocol_T0 * t0, APDU_Cmd * cmd, APDU_Rsp ** rsp)
     406static int Protocol_T0_Case4S (APDU_Cmd * cmd, APDU_Rsp ** rsp)
    427407{
    428408    int ret;
     
    437417   
    438418    /* Send command TPDU */
    439     ret = Protocol_T0_ExchangeTPDU (t0, tpdu_cmd, (&tpdu_rsp));
     419    ret = Protocol_T0_ExchangeTPDU(tpdu_cmd, (&tpdu_rsp));
    440420   
    441421    /* Delete command TPDU */
     
    465445           
    466446            /* Issue Get Reponse command */
    467             ret = Protocol_T0_ExchangeTPDU (t0, tpdu_cmd, rsp);
     447            ret = Protocol_T0_ExchangeTPDU(tpdu_cmd, rsp);
    468448           
    469449            /* Delete command TPDU */
     
    504484
    505485
    506 static int Protocol_T0_Case2E (Protocol_T0 * t0, APDU_Cmd * cmd, APDU_Rsp ** rsp)
     486static int Protocol_T0_Case2E (APDU_Cmd * cmd, APDU_Rsp ** rsp)
    507487{
    508488    int ret = PROTOCOL_T0_OK;
     
    526506       
    527507        /* Send command TPDU */
    528         ret = Protocol_T0_ExchangeTPDU (t0, tpdu_cmd, rsp);
     508        ret = Protocol_T0_ExchangeTPDU(tpdu_cmd, rsp);
    529509       
    530510        /* Delete command TPDU */
     
    548528           
    549529            /* Send envelope command TPDU */
    550             ret = Protocol_T0_ExchangeTPDU (t0, tpdu_cmd, (&tpdu_rsp));
     530            ret = Protocol_T0_ExchangeTPDU(tpdu_cmd, (&tpdu_rsp));
    551531           
    552532            /* Delete command TPDU */
     
    588568
    589569
    590 static int Protocol_T0_Case3E (Protocol_T0 * t0, APDU_Cmd * cmd, APDU_Rsp ** rsp)
     570static int Protocol_T0_Case3E (APDU_Cmd * cmd, APDU_Rsp ** rsp)
    591571{
    592572    int ret;
     
    608588       
    609589        /* Send command TPDU */
    610         ret = Protocol_T0_Case3S (t0, tpdu_cmd, rsp);
     590        ret = Protocol_T0_Case3S (tpdu_cmd, rsp);
    611591       
    612592        /* Delete command TPDU */
     
    625605       
    626606        /* Send command TPDU */
    627         ret = Protocol_T0_ExchangeTPDU (t0, tpdu_cmd, (&tpdu_rsp));
     607        ret = Protocol_T0_ExchangeTPDU(tpdu_cmd, (&tpdu_rsp));
    628608       
    629609        /* Delete command TPDU */
     
    650630               
    651631                /* Re-issue command TPDU */
    652                 ret = Protocol_T0_ExchangeTPDU (t0, tpdu_cmd, rsp);
     632                ret = Protocol_T0_ExchangeTPDU(tpdu_cmd, rsp);
    653633               
    654634                /* Delete command TPDU */
     
    676656                   
    677657                    /* Issue Get Response command TPDU */
    678                     ret = Protocol_T0_ExchangeTPDU (t0, tpdu_cmd, (&tpdu_rsp));
     658                    ret = Protocol_T0_ExchangeTPDU(tpdu_cmd, (&tpdu_rsp));
    679659                   
    680660                    /* Delete command TPDU */
     
    714694
    715695
    716 static int Protocol_T0_Case4E (Protocol_T0 * t0, APDU_Cmd * cmd, APDU_Rsp ** rsp)
     696static int Protocol_T0_Case4E (APDU_Cmd * cmd, APDU_Rsp ** rsp)
    717697{
    718698    int ret;
     
    736716       
    737717        /* Send command TPDU */
    738         ret = Protocol_T0_ExchangeTPDU (t0, tpdu_cmd, (&tpdu_rsp));
     718        ret = Protocol_T0_ExchangeTPDU(tpdu_cmd, (&tpdu_rsp));
    739719       
    740720        /* Delete command TPDU */
     
    743723    else /* 4E2 */
    744724    {
    745         ret = Protocol_T0_Case2E (t0, cmd, (&tpdu_rsp));
     725        ret = Protocol_T0_Case2E (cmd, (&tpdu_rsp));
    746726    }
    747727   
     
    773753           
    774754            /* Issue Case 3E get response command */
    775             ret = Protocol_T0_Case3E (t0, gr_cmd, rsp);
     755            ret = Protocol_T0_Case3E (gr_cmd, rsp);
    776756           
    777757            /* Delete Get Response command APDU */
     
    800780           
    801781            /* Issue Case 3E get response command */
    802             ret = Protocol_T0_Case3E (t0, gr_cmd, rsp);
     782            ret = Protocol_T0_Case3E (gr_cmd, rsp);
    803783           
    804784            /* Delete Get Response command APDU */
     
    810790
    811791
    812 static int Protocol_T0_ExchangeTPDU (Protocol_T0 * t0, APDU_Cmd * cmd, APDU_Rsp ** rsp)
     792static int Protocol_T0_ExchangeTPDU (APDU_Cmd * cmd, APDU_Rsp ** rsp)
    813793{
    814794    BYTE buffer[PROTOCOL_T0_MAX_SHORT_RESPONSE];
     
    828808   
    829809    /* Send header bytes */
    830     if (ICC_Async_Transmit (t0->icc, 5, APDU_Cmd_Header (cmd)) != ICC_ASYNC_OK)
     810    if (ICC_Async_Transmit (5, APDU_Cmd_Header (cmd)) != ICC_ASYNC_OK)
    831811    {
    832812        (*rsp) = NULL;
     
    848828    {
    849829        /* Read one procedure byte */
    850         if (ICC_Async_Receive (t0->icc, 1, buffer + recv) != ICC_ASYNC_OK)
     830        if (ICC_Async_Receive (1, buffer + recv) != ICC_ASYNC_OK)
    851831        {
    852832            ret = PROTOCOL_T0_ICC_ERROR;
     
    876856           
    877857            /* Read SW2 byte */
    878             if (ICC_Async_Receive (t0->icc, 1, buffer + recv) != ICC_ASYNC_OK)
     858            if (ICC_Async_Receive (1, buffer + recv) != ICC_ASYNC_OK)
    879859            {
    880860                ret = PROTOCOL_T0_ICC_ERROR;
     
    898878                    return PROTOCOL_T0_ERROR;
    899879                               
    900                 if (ICC_Async_Transmit(t0->icc, MAX (Lc - sent, 0), data + sent) != ICC_ASYNC_OK) /* Send remaining data bytes */
     880                if (ICC_Async_Transmit(MAX (Lc - sent, 0), data + sent) != ICC_ASYNC_OK) /* Send remaining data bytes */
    901881                {
    902882                    ret = PROTOCOL_T0_ICC_ERROR;
     
    917897               
    918898                /* Read remaining data bytes */
    919                 if (ICC_Async_Receive(t0->icc, MAX (Le - recv, 0), buffer + recv) != ICC_ASYNC_OK)
     899                if (ICC_Async_Receive(MAX (Le - recv, 0), buffer + recv) != ICC_ASYNC_OK)
    920900                {//printf("error %d\n", (int)Le);
    921901                    ret = PROTOCOL_T0_ICC_ERROR;
     
    939919                               
    940920                /* Send next data byte */
    941                 if (ICC_Async_Transmit (t0->icc, 1, data + sent) !=ICC_ASYNC_OK)
     921                if (ICC_Async_Transmit (1, data + sent) !=ICC_ASYNC_OK)
    942922                {
    943923                    ret = PROTOCOL_T0_ICC_ERROR;
     
    954934               
    955935                /* Read next data byte */
    956                 if (ICC_Async_Receive (t0->icc, 1, buffer + recv) != ICC_ASYNC_OK)
     936                if (ICC_Async_Receive (1, buffer + recv) != ICC_ASYNC_OK)
    957937                {
    958938                    ret = PROTOCOL_T0_ICC_ERROR;
     
    979959}
    980960
    981 static int Protocol_T14_ExchangeTPDU (Protocol_T14 * t14, APDU_Cmd * cmd, APDU_Rsp ** rsp)
     961static int Protocol_T14_ExchangeTPDU (APDU_Cmd * cmd, APDU_Rsp ** rsp)
    982962{
    983963    BYTE buffer[PROTOCOL_T14_MAX_SHORT_RESPONSE];
     
    1004984    {
    1005985        /* Send 0x01 byte */
    1006         if (ICC_Async_Transmit (t14->icc, 1, &b1) != ICC_ASYNC_OK)
     986        if (ICC_Async_Transmit (1, &b1) != ICC_ASYNC_OK)
    1007987        {
    1008988            (*rsp) = NULL;
     
    1011991       
    1012992        /* Send apdu */
    1013         if (ICC_Async_Transmit (t14->icc, cmd_len, cmd_raw) != ICC_ASYNC_OK)
     993        if (ICC_Async_Transmit (cmd_len, cmd_raw) != ICC_ASYNC_OK)
    1014994        {
    1015995            (*rsp) = NULL;
     
    1018998       
    1019999        /* Send xor byte */
    1020         if (ICC_Async_Transmit (t14->icc, 1, &ixor) != ICC_ASYNC_OK)
     1000        if (ICC_Async_Transmit (1, &ixor) != ICC_ASYNC_OK)
    10211001        {
    10221002            (*rsp) = NULL;
     
    10311011       
    10321012        /* Send apdu */
    1033         if (ICC_Async_Transmit (t14->icc, cmd_len+2, buffer) != ICC_ASYNC_OK)
     1013        if (ICC_Async_Transmit (cmd_len+2, buffer) != ICC_ASYNC_OK)
    10341014        {
    10351015            (*rsp) = NULL;
     
    10681048        }
    10691049        /* Read one procedure byte */
    1070         if (ICC_Async_Receive (t14->icc, 8, buffer) != ICC_ASYNC_OK)
     1050        if (ICC_Async_Receive (8, buffer) != ICC_ASYNC_OK)
    10711051        {
    10721052            ret = PROTOCOL_T14_ICC_ERROR;
     
    10791059            if(recv)
    10801060            {
    1081                 if (ICC_Async_Receive (t14->icc, recv, buffer + 8) != ICC_ASYNC_OK)
     1061                if (ICC_Async_Receive (recv, buffer + 8) != ICC_ASYNC_OK)
    10821062                {
    10831063                    ret = PROTOCOL_T14_ICC_ERROR;
     
    10861066            }
    10871067           
    1088             if (ICC_Async_Receive (t14->icc, 1, &ixor) != ICC_ASYNC_OK)
     1068            if (ICC_Async_Receive (1, &ixor) != ICC_ASYNC_OK)
    10891069            {
    10901070                ret = PROTOCOL_T14_ICC_ERROR;
     
    11241104static void Protocol_T0_Clear (Protocol_T0 * t0)
    11251105{
    1126     t0->icc = NULL;
    11271106    t0->wwt = 0;
    11281107}
     
    11301109static void Protocol_T14_Clear (Protocol_T14 * t14)
    11311110{
    1132     t14->icc = NULL;
    11331111    t14->wwt = 0;
    11341112}
  • branches/smartreader/csctapi/protocol_t0.h

    r842 r1280  
    5656typedef struct
    5757{
    58   ICC_Async *icc;       /* Asynchrosous integrated cirtuit card */
    5958  unsigned long wwt;        /* Work waiting time (ms) */
    6059}
     
    6463typedef struct
    6564{
    66   ICC_Async *icc;       /* Asynchrosous integrated cirtuit card */
    6765  unsigned long wwt;        /* Work waiting time (ms) */
    6866}
     
    8280
    8381/* Initialise a protocol handler */
    84 extern int Protocol_T0_Init (Protocol_T0 * t0, ICC_Async * icc, PPS_ProtocolParameters * params, int selected_protocol);
    85 extern int Protocol_T14_Init (Protocol_T14 * t14, ICC_Async * icc, PPS_ProtocolParameters * params, int selected_protocol);
     82extern int Protocol_T0_Init (Protocol_T0 * t0, PPS_ProtocolParameters * params, int selected_protocol);
     83extern int Protocol_T14_Init (Protocol_T14 * t14, PPS_ProtocolParameters * params, int selected_protocol);
    8684
    8785/* Send a command and return a response */
    88 extern int Protocol_T0_Command (Protocol_T0 * t0, APDU_Cmd * cmd, APDU_Rsp ** rsp);
    89 extern int Protocol_T14_Command (Protocol_T14 * t14, APDU_Cmd * cmd, APDU_Rsp ** rsp);
     86extern int Protocol_T0_Command (APDU_Cmd * cmd, APDU_Rsp ** rsp);
     87extern int Protocol_T14_Command (APDU_Cmd * cmd, APDU_Rsp ** rsp);
    9088
    9189/* Close a protocol handler */
  • branches/smartreader/csctapi/protocol_t1.c

    r1225 r1280  
    4949
    5050static int
    51 Protocol_T1_SendBlock (Protocol_T1 * t1, T1_Block * block);
     51Protocol_T1_SendBlock (T1_Block * block);
    5252
    5353static int
     
    5555
    5656static int
    57 Protocol_T1_UpdateBWT (Protocol_T1 * t1, unsigned short bwt);
     57Protocol_T1_UpdateBWT (unsigned short bwt);
    5858
    5959/*
     
    7575
    7676int
    77 Protocol_T1_Init (Protocol_T1 * t1, ICC_Async * icc, int selected_protocol)
    78 {
    79   ICC_Async_Timings timings;
     77Protocol_T1_Init (Protocol_T1 * t1, int selected_protocol)
     78{
    8079  BYTE ta, tb, tc, cwi, bwi;
    8180  unsigned long baudrate;
    8281  double work_etu;
    83   ATR *atr;
    8482  int i;
    85 
    86   /* Set ICC */
    87   t1->icc = icc;
    88 
    89   /* Get ATR of the card */
    90   atr = ICC_Async_GetAtr (t1->icc);
    9183
    9284  /* Set IFSC */
     
    121113 
    122114  /* Work etu  = (1000 / baudrate) milliseconds */
    123   ICC_Async_GetBaudrate (t1->icc, &baudrate);
     115  ICC_Async_GetBaudrate (&baudrate);
    124116  work_etu = 1000 / (double)baudrate;
    125117
     
    152144 
    153145  /* Set timings */
    154   ICC_Async_GetTimings (t1->icc, &timings);
    155 
    156   timings.block_timeout = t1->bwt;
    157   timings.char_timeout = t1->cwt;
    158   timings.block_delay = t1->bgt;
    159 
    160   ICC_Async_SetTimings (t1->icc, &timings);
     146  icc_timings.block_timeout = t1->bwt;
     147  icc_timings.char_timeout = t1->cwt;
     148  icc_timings.block_delay = t1->bgt;
     149    ICC_Async_SetTimings ();
    161150
    162151#ifdef DEBUG_PROTOCOL
     
    188177#endif
    189178      /* Send IFSD request */
    190       ret = Protocol_T1_SendBlock (t1, block);
     179      ret = Protocol_T1_SendBlock (block);
    191180
    192181      /* Delete block */
     
    233222
    234223  /* Send a block */
    235   ret = Protocol_T1_SendBlock (t1, block);
     224  ret = Protocol_T1_SendBlock (block);
    236225
    237226  /* Delete I-block */
     
    274263#endif
    275264              /* Send a block */
    276               ret = Protocol_T1_SendBlock (t1, block);
     265              ret = Protocol_T1_SendBlock (block);
    277266
    278267              /* Delete I-block */
     
    304293    {
    305294      if (wtx > 1)
    306         Protocol_T1_UpdateBWT (t1, wtx * (t1->bwt));         
     295        Protocol_T1_UpdateBWT (wtx * (t1->bwt));         
    307296
    308297      /* Receive a block */
     
    311300      if (wtx > 1)
    312301        {
    313           Protocol_T1_UpdateBWT (t1, t1->bwt);         
     302          Protocol_T1_UpdateBWT (t1->bwt);         
    314303          wtx = 0;
    315304        }
     
    348337#endif                   
    349338                  /* Send R-Block */
    350                   ret = Protocol_T1_SendBlock (t1, block);
     339                  ret = Protocol_T1_SendBlock (block);
    351340
    352341                  /* Delete I-block */
     
    372361#endif                   
    373362              /* Send WTX response */
    374               ret = Protocol_T1_SendBlock (t1, block);
     363              ret = Protocol_T1_SendBlock (block);
    375364                 
    376365              /* Delete block */
     
    413402
    414403static int
    415 Protocol_T1_SendBlock (Protocol_T1 * t1, T1_Block * block)
     404Protocol_T1_SendBlock (T1_Block * block)
    416405{
    417406  BYTE *buffer;
     
    423412      length = T1_Block_RawLen (block);
    424413
    425       if (ICC_Async_Transmit (t1->icc, length, buffer) != ICC_ASYNC_OK)
     414      if (ICC_Async_Transmit (length, buffer) != ICC_ASYNC_OK)
    426415        {
    427416          ret = PROTOCOL_T1_ICC_ERROR;
     
    442431
    443432  /* Receive four mandatory bytes */
    444   if (ICC_Async_Receive (t1->icc, 4, buffer) != ICC_ASYNC_OK)
     433  if (ICC_Async_Receive (4, buffer) != ICC_ASYNC_OK)
    445434    {
    446435      ret = PROTOCOL_T1_ICC_ERROR;
     
    453442        {
    454443          /* Set timings to read the remaining block */
    455           Protocol_T1_UpdateBWT (t1, t1->cwt);
     444          Protocol_T1_UpdateBWT (t1->cwt);
    456445
    457446          /* Receive remaining bytes */
    458           if (ICC_Async_Receive (t1->icc, buffer[2], buffer + 4) !=
     447          if (ICC_Async_Receive (buffer[2], buffer + 4) !=
    459448              ICC_ASYNC_OK)
    460449            {
     
    470459
    471460          /* Restore timings */
    472           Protocol_T1_UpdateBWT (t1, t1->bwt);
     461          Protocol_T1_UpdateBWT (t1->bwt);
    473462        }
    474463      else
     
    485474Protocol_T1_Clear (Protocol_T1 * t1)
    486475{
    487   t1->icc = NULL;
    488476  t1->ifsc = 0;
    489477  t1->ifsd = 0;
     
    496484
    497485static int
    498 Protocol_T1_UpdateBWT (Protocol_T1 * t1, unsigned short bwt)
    499 {
    500   ICC_Async_Timings timings;
    501  
    502   ICC_Async_GetTimings (t1->icc, &timings);
    503 
    504   timings.block_timeout = bwt;
    505 
    506   ICC_Async_SetTimings (t1->icc, &timings);
     486Protocol_T1_UpdateBWT (unsigned short bwt)
     487{
     488  icc_timings.block_timeout = bwt;
     489    ICC_Async_SetTimings ();
    507490
    508491  return PROTOCOL_T1_OK;
  • branches/smartreader/csctapi/protocol_t1.h

    r1127 r1280  
    4848typedef struct
    4949{
    50   ICC_Async *icc;       /* Asynchronous integrated cirtuit card */
    5150  unsigned short ifsc;  /* Information field size for the ICC */
    5251  unsigned short ifsd;  /* Information field size for the IFD */
     
    7372/* Initialise a protocol handler */
    7473extern int
    75 Protocol_T1_Init (Protocol_T1 * t1, ICC_Async * icc, int selected_protocol);
     74Protocol_T1_Init (Protocol_T1 * t1, int selected_protocol);
    7675
    7776/* Send a command and return a response */
Note: See TracChangeset for help on using the changeset viewer.