Changeset 1960


Ignore:
Timestamp:
04/05/10 19:30:24 (12 years ago)
Author:
merek
Message:

Merge from UMP r1987-r1994

Location:
trunk
Files:
1 added
1 deleted
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/csctapi/icc_async.c

    r1951 r1960  
    2929#include "defines.h"
    3030#include "icc_async.h"
    31 #include "ifd.h"
    3231#include "mc_global.h"
    3332#include "protocol_t0.h"
    3433#include "protocol_t1.h"
    3534#include "io_serial.h"
    36 
    37 extern struct termios stored_termio[8]; //FIXME no globals please
     35#include "ifd_cool.h"
     36#include "ifd_phoenix.h"
     37#include "ifd_sc8in1.h"
     38#include "ifd_sci.h"
     39#include "ifd_smartreader.h"
     40
    3841// Default T0/T14 settings
    3942#define DEFAULT_WI      10
     
    138141        Sc8in1_GetStatus(reader, &i); //Initialize cardstatus
    139142    }
    140      if (reader->typ <= R_MOUSE)
    141       if (Phoenix_Init(reader)) {
    142             cs_log("ERROR: Phoenix_Init returns error");
    143             Phoenix_Close (reader);
    144             return ERROR;
     143
     144    if (reader->typ <= R_MOUSE)
     145        if (Phoenix_Init(reader)) {
     146                cs_log("ERROR: Phoenix_Init returns error");
     147                Phoenix_Close (reader);
     148                return ERROR;
    145149        }
    146     if (reader->typ == R_SC8in1) {
    147         struct termios termio;
    148         tcgetattr(reader->handle,&termio);
    149         int i;
    150         for (i=0; i<8; i++)
    151           //init all stored termios to default comm settings after device init, before ATR
    152           memcpy(&stored_termio[i],&termio,sizeof(termio));
    153     }
     150
     151    if (reader->typ == R_SC8in1)
     152        call(Sc8in1_Init(reader));
     153
    154154 cs_debug_mask (D_IFD, "IFD: Device %s succesfully opened\n", reader->device);
    155155 return OK;
  • trunk/csctapi/ifd_phoenix.c

    r1952 r1960  
    163163            while(n<PHOENIX_MAX_ATR_SIZE && !IO_Serial_Read(reader, ATR_TIMEOUT, 1, buf+n))
    164164                n++;
    165             if(n==0) {
    166                 cs_log("WARNING: 0 characters found in ATR");
    167                 //FIXME: No parity switching was done if we exit here
    168                 //return ERROR;
    169             }
     165            if(n==0)
     166                continue;
    170167            if (ATR_InitFromArray (atr, buf, n) == ATR_OK)
    171168                ret = OK;
  • trunk/csctapi/ifd_sc8in1.c

    r1953 r1960  
    2828#include "icc_async.h"
    2929
    30 struct termios stored_termio[8];//FIXME no globals please
     30static struct termios stored_termio[8];//FIXME no globals please
     31static int current_slot; //FIXME should not be a global, but one per SC8in1
     32static unsigned char cardstatus; //FIXME not global but one per SC8in1  //if not static, the threads dont share same cardstatus!
     33
    3134#define MAX_TRANSMIT            255
    3235
    33 static int readsc8in1(struct s_reader * reader) {
    34   // Reads the card status
    35   //
    36   // the bits in the return bytes:
    37   // bit0=1 means Slot1=Smartcard inside
    38   // bit1=1 means Slot2=Smartcard inside
    39   // bit2=1 means Slot3=Smartcard inside
    40   // bit3=1 means Slot4=Smartcard inside
    41   // bit4=1 means Slot5=Smartcard inside
    42   // bit5=1 means Slot6=Smartcard inside
    43   // bit6=1 means Slot7=Smartcard inside
    44   // bit7=1 means Slot8=Smartcard inside
    45   int res;
    46   unsigned char tmp[128];
     36static int sc8in1_command(struct s_reader * reader, unsigned char * buff, unsigned short lenwrite, unsigned short lenread)
     37{
    4738  struct termios termio, termiobackup;
    4839
     
    6152  if (tcsetattr(reader->handle,TCSANOW,&termio) < 0) {
    6253    cs_log("ERROR: SC8in1 readsc8in1 set RS232 attributes\n");
    63     return(-1);
     54    return ERROR;
    6455  }
    65   // get SC8in1 info
    66   tmp[0]=0x47;
    67   IO_Serial_Write (reader, 0, 1, tmp);
     56  IO_Serial_Write (reader, 0, lenwrite, buff);
    6857  tcdrain(reader->handle);
    69   res=IO_Serial_Read (reader, 1000, 8, tmp);
    70 
    71   if ( res==ERROR ) {
     58  if (IO_Serial_Read (reader, 1000, lenread, buff) == ERROR) {
    7259    cs_log("READSC8in1 read error");
    73     return(-1); // ERROR !
     60    return ERROR;
    7461  }
    7562
    7663  // switch SC8in1 to normal mode
    77   tcdrain(reader->handle);
     64  //cs_sleepms(10); FIXME do I need this?
    7865  IO_Serial_DTR_Clr(reader);
    7966
     
    8269  if (tcsetattr(reader->handle,TCSANOW,&termio) < 0) {
    8370    cs_log("ERROR: SC8in1 readsc8in1 restore RS232 attributes\n");
    84     return(-1);
     71    return ERROR;
    8572  }
     73    return OK;
     74}
    8675
    87   if (tmp[0]!=0x90) return(-1); // ERROR !
     76static int readsc8in1(struct s_reader * reader)
     77{
     78  // Reads the card status
     79  //
     80  // the bits in the return bytes:
     81  // bit0=1 means Slot1=Smartcard inside
     82  // bit1=1 means Slot2=Smartcard inside
     83  // bit2=1 means Slot3=Smartcard inside
     84  // bit3=1 means Slot4=Smartcard inside
     85  // bit4=1 means Slot5=Smartcard inside
     86  // bit5=1 means Slot6=Smartcard inside
     87  // bit6=1 means Slot7=Smartcard inside
     88  // bit7=1 means Slot8=Smartcard inside
     89  unsigned char buf[10];
     90  buf[0]=0x47;
     91    if (sc8in1_command(reader, buf, 1, 8) < 0) return (-1);
     92  if (buf[0]!=0x90) return(-1);
    8893
    8994  // return result byte
    90   return(tmp[1]);
     95  return(buf[1]);
    9196}
    9297
    93 int selectslot(struct s_reader * reader, int slot) {
     98int Sc8in1_Selectslot(struct s_reader * reader, int slot) {
    9499  // selects the Smartcard Socket "slot"
    95100  //
    96101    if (slot == current_slot)
    97         return(0);
     102        return OK;
    98103    cs_log("SC8in1: select slot %i", slot);
    99104  int res;
     
    113118  if (tcsetattr(reader->handle,TCSANOW,&termio) < 0) {
    114119    cs_log("ERROR: SC8in1 selectslot set RS232 attributes\n");
    115     return(-1);
     120    return ERROR;
    116121  }
    117122    tcflush(reader->handle, TCIOFLUSH);
     
    132137  if (tcsetattr(reader->handle,TCSANOW,&termio) < 0) {
    133138    cs_log("ERROR: SC8in1 selectslot restore RS232 attributes\n");
    134     return(-1);
     139    return ERROR;
    135140  }
    136141    //cs_sleepms(10); //FIXME do I need this?
    137   return(0);
     142  return OK;
     143}
     144
     145int Sc8in1_Init(struct s_reader * reader)
     146{
     147    //additional init, Phoenix_Init is also called for Sc8in1 !
     148    struct termios termio;
     149    tcgetattr(reader->handle,&termio);
     150    int i;
     151    for (i=0; i<8; i++)
     152        //init all stored termios to default comm settings after device init, before ATR
     153        memcpy(&stored_termio[i],&termio,sizeof(termio));
     154    return OK;
    138155}
    139156
  • trunk/csctapi/ifd_sc8in1.h

    r1926 r1960  
    1919#include <pthread.h>
    2020
     21int Sc8in1_Init (struct s_reader * reader);
    2122int Sc8in1_GetStatus (struct s_reader * reader, int * status);
     23int Sc8in1_Card_Changed (struct s_reader * reader);
     24int Sc8in1_Selectslot(struct s_reader * reader, int slot);
    2225
    23 pthread_mutex_t sc8in1; //semaphore for SC8in1, FIXME should not be global, but one per SC8in1
    24 //not sure why mutex seems to be global for all threads in one reader, and variables below only if they are defined static ...
    25 static int current_slot; //FIXME should not be a global, but one per SC8in1
    26 static unsigned char cardstatus; //FIXME not global but one per SC8in1  //if not static, the threads dont share same cardstatus!
     26static pthread_mutex_t sc8in1; //semaphore for SC8in1, FIXME should not be global, but one per SC8in1
  • trunk/csctapi/ifd_sci.c

    r1926 r1960  
    44*/
    55
    6 #include "atr.h"
    7 #include "../globals.h"
     6#include "ifd_sci.h"
    87
    98#ifdef SCI_DEV
  • trunk/reader-common.c

    r1953 r1960  
    44#include "atr.h"
    55#include "icc_async_exports.h"
     6#include "csctapi/ifd_sc8in1.h"
    67
    78static int cs_ptyp_orig; //reinit=1,
    8 extern int Sc8in1_Card_Changed (struct s_reader * reader);
    9 extern int selectslot(struct s_reader * reader, int slot);
    10 extern pthread_mutex_t sc8in1; //FIXME
    119
    1210#define SC_IRDETO 1
     
    7674        pthread_mutex_lock(&sc8in1);
    7775        cs_debug("SC8in1: locked for CardWrite of slot %i", reader->slot);
    78         selectslot(reader, reader->slot);
     76        Sc8in1_Selectslot(reader, reader->slot);
    7977    }
    8078    rc=ICC_Async_CardWrite(reader, buf, (unsigned short)l, cta_res, p_cta_lr);
     
    142140        pthread_mutex_lock(&sc8in1);
    143141        cs_debug_mask(D_ATR, "SC8in1: locked for Activation of slot %i", reader->slot);
    144         selectslot(reader, reader->slot);
     142        Sc8in1_Selectslot(reader, reader->slot);
    145143    }
    146144  for (i=0; i<5; i++) {
Note: See TracChangeset for help on using the changeset viewer.