Changeset 1257


Ignore:
Timestamp:
01/16/10 21:09:44 (11 years ago)
Author:
alno
Message:

WebIf:

  • Merged Rev 1252-1253 of trunk
Location:
branches/monitor-improvement
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • branches/monitor-improvement/csctapi/cardterminal.c

    r1240 r1257  
    4949static char CardTerminal_GetStatus (CardTerminal * ct, APDU_Cmd * cmd, APDU_Rsp ** rsp);
    5050
    51 static char CardTerminal_SetParity (CardTerminal * ct, APDU_Cmd * cmd, APDU_Rsp ** rsp);
     51static char CardTerminal_SetParity (APDU_Cmd * cmd, APDU_Rsp ** rsp);
    5252
    5353static char CardTerminal_EjectICC (CardTerminal * ct, APDU_Cmd * cmd, APDU_Rsp ** rsp);
     
    7171}
    7272
    73 char CardTerminal_Init (CardTerminal * ct, int reader_type, int mhz, int cardmhz)
     73char CardTerminal_Init (CardTerminal * ct)
    7474{
    7575    char ret;
    7676    int i;
    7777   
    78     /* Create a new IO_Serial */
    79     ct->io = IO_Serial_New (mhz, cardmhz);
    80    
    81     /* Memory error */
    82     if (ct->io == NULL)
    83         return ERR_MEMORY;
    84    
    8578    /* Initialise serial port */
    86     if (ICC_Async_Device_Init ()) {
    87         printf("ERROR in initializing device\n");
     79    if (ICC_Async_Device_Init ())
    8880        return ERR_TRANS;
    89     }
    90     if (!IO_Serial_Init(ct->io, reader_type))
    91     {
    92         free (ct->io);
    93         ct->io = NULL;
    94         return ERR_TRANS;
    95     }
    96    
     81
    9782    /* Cearte all reader slots */
    9883    ct->num_slots = 0;
     
    11196       
    11297        /* Initialise slot */
    113         ret = CT_Slot_Init (ct->slots[i], ct->io, i);
     98        ret = CT_Slot_Init (ct->slots[i], i);
    11499       
    115100        if (ret != OK)
     
    133118        }
    134119       
    135         IO_Serial_Close (ct->io);
    136         free (ct->io);
    137         ct->io = NULL;
     120        IO_Serial_Close ();
    138121    }
    139122#ifdef HAVE_PTHREAD_H
     
    177160            ret = CardTerminal_GetStatus (ct, cmd, rsp);
    178161        else if (ins == CTBCS_INS_PARITY) /* Get Status */
    179             ret = CardTerminal_SetParity (ct, cmd, rsp);
     162            ret = CardTerminal_SetParity (cmd, rsp);
    180163        else if (ins == CTBCS_INS_EJECT) /* Eject ICC */
    181164            ret = CardTerminal_EjectICC (ct, cmd, rsp);
     
    213196    }
    214197   
    215     if (ct->io != NULL)
    216     {
    217         if (!IO_Serial_Close (ct->io))
     198        if (!IO_Serial_Close ())
    218199            ret = ERR_TRANS;
    219200       
    220         free (ct->io);
    221     }
    222    
    223201    CardTerminal_Clear (ct);
    224202   
     
    296274           
    297275            /* Initialise this slot */
    298             ret = CT_Slot_Init (ct->slots[sn],ct->io,sn);
     276            ret = CT_Slot_Init (ct->slots[sn],sn);
    299277           
    300278            if (ret != OK)
     
    690668}
    691669
    692 static char CardTerminal_SetParity (CardTerminal * ct, APDU_Cmd * cmd, APDU_Rsp ** rsp)
     670static char CardTerminal_SetParity (APDU_Cmd * cmd, APDU_Rsp ** rsp)
    693671{
    694672    BYTE buffer[2], p1, p2;
     
    858836    int i;
    859837   
    860     ct->io = NULL;
    861838    ct->num_slots = 0;
    862839   
  • branches/monitor-improvement/csctapi/cardterminal.h

    r1210 r1257  
    4949typedef struct
    5050{
    51   IO_Serial * io;               /* Serial device */
    5251  CT_Slot * slots[CARDTERMINAL_MAX_SLOTS];  /* Array of CT_Slot's */
    5352  unsigned int num_slots;               /* Number of CT_Slot's */
     
    6867/* Intialice a CardTerminal in a given port */
    6968extern char
    70 CardTerminal_Init (CardTerminal * ct, int reader_type, int mhz, int cardmhz);
     69CardTerminal_Init (CardTerminal * ct);
    7170
    7271/* Send a CT-BCS command to a CardTerminal */
  • branches/monitor-improvement/csctapi/ct_slot.c

    r1228 r1257  
    6464}
    6565
    66 char CT_Slot_Init (CT_Slot * slot, IO_Serial * io, int sn)
     66char CT_Slot_Init (CT_Slot * slot, int sn)
    6767{
    6868    slot->ifd = IFD_Towitoko_New();
     
    7171        return ERR_MEMORY;
    7272   
    73     if (IFD_Towitoko_Init (slot->ifd, io, sn) != IFD_TOWITOKO_OK)
     73    if (IFD_Towitoko_Init (slot->ifd, sn) != IFD_TOWITOKO_OK)
    7474    {
    7575        IFD_Towitoko_Delete (slot->ifd);
  • branches/monitor-improvement/csctapi/ct_slot.h

    r1180 r1257  
    7171/* Intialice a CT_Slot */
    7272extern char
    73 CT_Slot_Init (CT_Slot * slot, IO_Serial * io, int sn);
     73CT_Slot_Init (CT_Slot * slot, int sn);
    7474
    7575/* Check for card inserted */
  • branches/monitor-improvement/csctapi/ctapi.c

    r1210 r1257  
    5050 */
    5151
    52 char CT_init (unsigned short ctn, int reader_type, int mhz, int cardmhz)
     52char CT_init (unsigned short ctn)
    5353{
    5454    CardTerminal *ct;
     
    6969        {   
    7070            /* Initialize CardTerminal */
    71             ret = CardTerminal_Init (ct, reader_type, mhz, cardmhz);
     71            ret = CardTerminal_Init (ct);
    7272           
    7373            /* Add CardTerminal to list */
  • branches/monitor-improvement/csctapi/ctapi.h

    r1210 r1257  
    2020
    2121extern char CT_init (
    22       unsigned short Ctn,                  /* Terminal Number */
    23       int reader_type,                      /* reader type (mouse, smartreader) */
    24       int mhz,
    25       int cardmhz
     22      unsigned short Ctn                  /* Terminal Number */
    2623      );
    2724
  • branches/monitor-improvement/csctapi/icc_async.c

    r1250 r1257  
    6565int ICC_Async_Device_Init ()
    6666{
    67    
     67
     68    wr = 0;
    6869#ifdef DEBUG_IO
    6970    printf ("IO: Opening serial port %s\n", reader[ridx].device);
     
    9596        }
    9697#endif
    97        
     98
     99    if (reader[ridx].typ != R_INTERNAL) { //FIXME move to ifd_phoenix.c
     100        if(!IO_Serial_InitPnP ())
     101            return ICC_ASYNC_IFD_ERROR;
     102        IO_Serial_Flush();
     103    }
     104
    98105    return ICC_ASYNC_OK;
    99106}
     
    211218
    212219    /* Initialize Baudrate */
    213     if (IFD_Towitoko_SetBaudrate (ifd, ICC_ASYNC_BAUDRATE)!= IFD_TOWITOKO_OK)
     220    if (!Phoenix_SetBaudrate (ICC_ASYNC_BAUDRATE))
    214221        return ICC_ASYNC_IFD_ERROR;
    215222   
     
    238245    else
    239246#endif
    240     if (IFD_Towitoko_ResetAsyncICC (ifd, &(icc->atr)) != IFD_TOWITOKO_OK)
     247    if (!Phoenix_Reset(&(icc->atr)))
    241248    {
    242249        icc->atr = NULL;
     
    277284        if (!IO_Serial_SetParity (PARITY_ODD))
    278285            return ICC_ASYNC_IFD_ERROR;
    279         icc->ifd->io->parity = PARITY_ODD;
    280286    }
    281287    else if(icc->protocol_type == ATR_PROTOCOL_TYPE_T14)
     
    283289        if (!IO_Serial_SetParity (PARITY_NONE))
    284290            return ICC_ASYNC_IFD_ERROR;     
    285         icc->ifd->io->parity = PARITY_NONE;
    286291    }
    287292    else
     
    289294        if (!IO_Serial_SetParity (PARITY_EVEN))
    290295            return ICC_ASYNC_IFD_ERROR;     
    291         icc->ifd->io->parity = PARITY_EVEN;
    292296    }
    293297#ifdef COOL
    294298    if (reader[ridx].typ != R_INTERNAL)
    295299#endif
    296     IO_Serial_Flush(ifd->io);
     300    IO_Serial_Flush();
    297301    return ICC_ASYNC_OK;
    298302#else
     
    354358{
    355359    icc->baudrate = baudrate;
    356     if (IFD_Towitoko_SetBaudrate (icc->ifd, baudrate) !=  IFD_TOWITOKO_OK)
     360    if (!Phoenix_SetBaudrate (baudrate))
    357361      return ICC_ASYNC_IFD_ERROR;
    358362   
  • branches/monitor-improvement/csctapi/ifd_phoenix.c

    r1228 r1257  
    1111#include "atr.h"
    1212#include "ifd_towitoko.h" //FIXME
    13 
    14 #define OK      1
     13#include <termios.h>
     14
     15#define OK      1
    1516#define ERROR 0
    1617
     
    4546
    4647int Phoenix_Reset (ATR ** atr)
    47 {   
    48         return OK;
     48{   
     49
     50#ifdef DEBUG_IFD
     51    printf ("IFD: Resetting card:\n");
     52#endif
     53
     54        int ret;
     55        int i;
     56        int parity[3] = {PARITY_EVEN, PARITY_ODD, PARITY_NONE};
     57#ifdef HAVE_NANOSLEEP
     58        struct timespec req_ts;
     59        req_ts.tv_sec = 0;
     60        req_ts.tv_nsec = 50000000;
     61#endif
     62       
     63        (*atr) = NULL;
     64        for(i=0; i<3; i++) {
     65            IO_Serial_Flush();
     66            if (!IO_Serial_SetParity (parity[i]))
     67                return ERROR;
     68
     69            ret = ERROR;
     70            IO_Serial_Ioctl_Lock(1);
     71#ifdef USE_GPIO
     72            if (gpio_detect){
     73                set_gpio(0);
     74                set_gpio1(0);
     75            }
     76            else
     77#endif
     78                IO_Serial_RTS_Set();
     79#ifdef HAVE_NANOSLEEP
     80            nanosleep (&req_ts, NULL);
     81#else
     82            usleep (50000L);
     83#endif
     84#ifdef USE_GPIO
     85            if (gpio_detect) {
     86                set_gpio_input();
     87                set_gpio1(1);
     88            }
     89            else
     90#endif
     91                IO_Serial_RTS_Clr();
     92            IO_Serial_Ioctl_Lock(0);
     93            (*atr) = ATR_New ();
     94            if(ATR_InitFromStream ((*atr), IFD_TOWITOKO_ATR_TIMEOUT) == ATR_OK)
     95                ret = OK;
     96            // Succesfully retrieve ATR
     97            if (ret == OK)
     98                break;
     99            else
     100            {
     101                ATR_Delete (*atr);
     102                (*atr) = NULL;
     103#ifdef USE_GPIO
     104                if (gpio_detect) set_gpio1(0);
     105#endif
     106            }
     107        }
     108        IO_Serial_Flush();
     109
     110/*
     111        //PLAYGROUND faking ATR for test purposes only
     112        //
     113        // sky 919 unsigned char atr_test[] = { 0x3F, 0xFF, 0x13, 0x25, 0x03, 0x10, 0x80, 0x33, 0xB0, 0x0E, 0x69, 0xFF, 0x4A, 0x50, 0x70, 0x00, 0x00, 0x49, 0x54, 0x02, 0x00, 0x00 };
     114        // HD+ unsigned char atr_test[] = { 0x3F, 0xFF, 0x95, 0x00, 0xFF, 0x91, 0x81, 0x71, 0xFE, 0x47, 0x00, 0x44, 0x4E, 0x41, 0x53, 0x50, 0x31, 0x34, 0x32, 0x20, 0x52, 0x65, 0x76, 0x47, 0x43, 0x34, 0x63 };
     115        // S02 = irdeto unsigned char atr_test[] = { 0x3B, 0x9F, 0x21, 0x0E, 0x49, 0x52, 0x44, 0x45, 0x54, 0x4F, 0x20, 0x41, 0x43, 0x53, 0x03};
     116        //cryptoworks   unsigned char atr_test[] = { 0x3B, 0x78, 0x12, 0x00, 0x00, 0x65, 0xC4, 0x05, 0xFF, 0x8F, 0xF1, 0x90, 0x00 };
     117        ATR_Delete(*atr); //throw away actual ATR
     118        (*atr) = ATR_New ();
     119        ATR_InitFromArray ((*atr), atr_test, sizeof(atr_test));
     120        //END OF PLAYGROUND
     121*/
     122       
     123        return ret;
    49124}
    50125
     
    69144    if (gpio_detect) set_gpio1(0);
    70145#endif
    71     for (sent = 0; sent < size; sent = sent + to_send) 
     146    for (sent = 0; sent < size; sent = sent + to_send)
    72147    {
    73148        /* Calculate number of bytes to send */
     
    143218}
    144219
    145 int Phoenix_SetBaudrate (int mhz)
    146 {
    147     return OK;
    148 }
     220int Phoenix_SetBaudrate (unsigned long baudrate)
     221{
     222    if(reader[ridx].typ == R_INTERNAL)
     223        return OK;
     224
     225#ifdef DEBUG_IFD
     226    printf ("IFD: Setting baudrate to %lu\n", baudrate);
     227#endif
     228    if (reader[ridx].baudrate   == baudrate)
     229        return OK;
     230
     231    /* Get current settings */
     232    struct termios tio;
     233    if (tcgetattr (reader[ridx].handle, &tio) != 0)
     234        return ERROR;
     235   
     236    //write baudrate here!
     237    if (!IO_Serial_SetBitrate (baudrate, &tio))
     238        return ERROR;
     239   
     240    if (!IO_Serial_SetProperties(tio))
     241        return ERROR;
     242   
     243    reader[ridx].baudrate = baudrate;
     244   
     245    return OK;
     246}
  • branches/monitor-improvement/csctapi/ifd_towitoko.c

    r1240 r1257  
    146146}
    147147
    148 int IFD_Towitoko_Init (IFD * ifd, IO_Serial * io, BYTE slot)
     148int IFD_Towitoko_Init (IFD * ifd, BYTE slot)
    149149{
    150150    int ret;
     
    173173    if(reader[ridx].typ == R_INTERNAL)
    174174    {
    175         ifd->io = io;
    176175        ifd->slot = slot;
    177176        ifd->type = IFD_TOWITOKO_MULTICAM;
     
    181180   
    182181    /* Default serial port settings */
    183     io->input_bitrate = IFD_TOWITOKO_BAUDRATE;
    184     io->output_bitrate = IFD_TOWITOKO_BAUDRATE;
    185     io->bits = 8;
    186     io->stopbits = 2;
    187     io->parity = PARITY_EVEN;
    188     io->dtr = IO_SERIAL_HIGH;
    189 //  io->dtr = IO_SERIAL_LOW;
    190 //  io->rts = IO_SERIAL_HIGH;
    191     io->rts = IO_SERIAL_LOW;
    192    
    193        
    194     if (!IO_Serial_SetPropertiesOld (io))
    195         return IFD_TOWITOKO_IO_ERROR;
     182    if (!IO_Serial_SetParams (IFD_TOWITOKO_BAUDRATE, 8, PARITY_EVEN, 2, IO_SERIAL_HIGH, IO_SERIAL_LOW))
     183        return FALSE;
    196184       
    197185    /* Default ifd settings */
    198186   
    199     ifd->io = io;
    200187    ifd->slot = slot;
    201188    ifd->type = IFD_TOWITOKO_MULTICAM;
    202189   
    203     ret = IFD_Towitoko_SetBaudrate (ifd, IFD_TOWITOKO_BAUDRATE);
    204    
    205     if (ret != IFD_TOWITOKO_OK)
     190    if (!Phoenix_SetBaudrate(IFD_TOWITOKO_BAUDRATE))
    206191    {
    207192        IFD_Towitoko_Clear (ifd);
    208         return ret;
     193        return IFD_TOWITOKO_IO_ERROR;
    209194    }
    210195   
    211196    if (!IO_Serial_SetParity (PARITY_EVEN))
     197    {
     198        IFD_Towitoko_Clear (ifd);
    212199        return IFD_TOWITOKO_IO_ERROR;
    213    
    214     if (ret != IFD_TOWITOKO_OK)
    215     {
    216         IFD_Towitoko_Clear (ifd);
    217         return ret;
    218200    }
    219201   
     
    226208    else
    227209    {   
    228         IO_Serial_Flush(ifd->io);
     210        IO_Serial_Flush();
    229211    }
    230212   
     
    234216int IFD_Towitoko_Close (IFD * ifd)
    235217{
    236     int ret;
    237 
    238218#ifdef USE_GPIO
    239219    if(gpio_detect)
     
    255235}
    256236
    257 int IFD_Towitoko_SetBaudrate (IFD * ifd, unsigned long baudrate)
    258 {
    259     if(reader[ridx].typ == R_INTERNAL)
    260     {
    261         return IFD_TOWITOKO_OK;
    262     }
    263 #ifdef DEBUG_IFD
    264     printf ("IFD: Setting baudrate to %lu\n", baudrate);
    265 #endif
    266     /* Get current settings */
    267     if (!IO_Serial_GetPropertiesOld (ifd->io))
    268         return IFD_TOWITOKO_IO_ERROR;
    269    
    270     if (ifd->io->output_bitrate == baudrate)
    271         return IFD_TOWITOKO_OK;
    272 
    273    
    274     /* Set serial device bitrate */
    275     ifd->io->output_bitrate = baudrate;
    276     ifd->io->input_bitrate = baudrate;
    277    
    278     if (!IO_Serial_SetPropertiesOld (ifd->io))
    279         return IFD_TOWITOKO_IO_ERROR;
    280    
    281     return IFD_TOWITOKO_OK;
    282 }
    283 
    284 int IFD_Towitoko_GetBaudrate (IFD * ifd, unsigned long *baudrate)
    285 {
    286     if(reader[ridx].typ == R_INTERNAL)
    287     {
    288         return IFD_TOWITOKO_OK;
    289     }
    290    
    291     /* Get current settings */
    292     if (!IO_Serial_GetPropertiesOld (ifd->io))
    293         return IFD_TOWITOKO_IO_ERROR;
    294    
    295     (*baudrate) = ifd->io->output_bitrate;
    296    
    297     return IFD_TOWITOKO_OK;
    298 }
    299 
    300 int IFD_Towitoko_ActivateICC (IFD * ifd)
     237int IFD_Towitoko_ActivateICC ()
    301238{
    302239#ifdef DEBUG_IFD
     
    335272}
    336273
    337 int IFD_Towitoko_DeactivateICC (IFD * ifd)
     274int IFD_Towitoko_DeactivateICC ()
    338275{
    339276#ifdef DEBUG_IFD
     
    367304
    368305//extern void print_hex_data(unsigned char *data, int len);
    369 
    370 int IFD_Towitoko_ResetAsyncICC (IFD * ifd, ATR ** atr)
    371 {   
    372 
    373 #ifdef DEBUG_IFD
    374     printf ("IFD: Resetting card:\n");
    375 #endif
    376 
    377         int ret;
    378         int parity;
    379         int i;
    380         int par[3] = {PARITY_EVEN, PARITY_ODD, PARITY_NONE};
    381 #ifdef HAVE_NANOSLEEP
    382         struct timespec req_ts;
    383         req_ts.tv_sec = 0;
    384         req_ts.tv_nsec = 50000000;
    385 #endif
    386        
    387         (*atr) = NULL;
    388         for(i=0; i<3; i++)
    389         {
    390             parity = par[i];
    391             IO_Serial_Flush();
    392 
    393             if (!IO_Serial_SetParity (parity))
    394                 return IFD_TOWITOKO_IO_ERROR;
    395 
    396             ret = IFD_TOWITOKO_IO_ERROR;
    397 
    398             IO_Serial_Ioctl_Lock(1);
    399 #ifdef USE_GPIO
    400             if (gpio_detect)
    401             {
    402                 set_gpio(0);
    403                 set_gpio1(0);
    404             }
    405             else
    406 #endif
    407                 IO_Serial_RTS_Set();
    408 
    409 #ifdef HAVE_NANOSLEEP
    410             nanosleep (&req_ts, NULL);
    411 #else
    412             usleep (50000L);
    413 #endif
    414 #ifdef USE_GPIO
    415             if (gpio_detect)
    416             {
    417                 set_gpio_input();
    418                 set_gpio1(1);
    419             }
    420             else
    421 #endif
    422                 IO_Serial_RTS_Clr();
    423            
    424             IO_Serial_Ioctl_Lock(0);
    425 
    426             (*atr) = ATR_New ();
    427 
    428             if(ATR_InitFromStream ((*atr), IFD_TOWITOKO_ATR_TIMEOUT) == ATR_OK)
    429                 ret = IFD_TOWITOKO_OK;
    430 
    431             /* Succesfully retrive ATR */
    432             if (ret == IFD_TOWITOKO_OK)
    433             {           
    434                 break;
    435             }
    436             else
    437             {
    438                 ATR_Delete (*atr);
    439                 (*atr) = NULL;
    440 #ifdef USE_GPIO
    441                 if (gpio_detect) set_gpio1(0);
    442 #endif
    443             }   
    444         }
    445    
    446         IO_Serial_Flush();
    447 
    448 /*
    449         //PLAYGROUND faking ATR for test purposes only
    450         //
    451         // sky 919 unsigned char atr_test[] = { 0x3F, 0xFF, 0x13, 0x25, 0x03, 0x10, 0x80, 0x33, 0xB0, 0x0E, 0x69, 0xFF, 0x4A, 0x50, 0x70, 0x00, 0x00, 0x49, 0x54, 0x02, 0x00, 0x00 };
    452         // HD+ unsigned char atr_test[] = { 0x3F, 0xFF, 0x95, 0x00, 0xFF, 0x91, 0x81, 0x71, 0xFE, 0x47, 0x00, 0x44, 0x4E, 0x41, 0x53, 0x50, 0x31, 0x34, 0x32, 0x20, 0x52, 0x65, 0x76, 0x47, 0x43, 0x34, 0x63 };
    453         // S02 = irdeto unsigned char atr_test[] = { 0x3B, 0x9F, 0x21, 0x0E, 0x49, 0x52, 0x44, 0x45, 0x54, 0x4F, 0x20, 0x41, 0x43, 0x53, 0x03};
    454         //cryptoworks   unsigned char atr_test[] = { 0x3B, 0x78, 0x12, 0x00, 0x00, 0x65, 0xC4, 0x05, 0xFF, 0x8F, 0xF1, 0x90, 0x00 };
    455         ATR_Delete(*atr); //throw away actual ATR
    456         (*atr) = ATR_New ();
    457         ATR_InitFromArray ((*atr), atr_test, sizeof(atr_test));
    458         //END OF PLAYGROUND
    459 */
    460        
    461         return ret;
    462 }
    463306
    464307BYTE IFD_Towitoko_GetType (IFD * ifd)
     
    551394static void IFD_Towitoko_Clear (IFD * ifd)
    552395{
    553     ifd->io = NULL;
    554396    ifd->slot = 0x00;
    555397    ifd->type = 0x00;
  • branches/monitor-improvement/csctapi/ifd_towitoko.h

    r1240 r1257  
    9393typedef struct
    9494{
    95   IO_Serial *io;        /* Handle of serial device */
    9695  BYTE slot;            /* Chipdrive Twin Slot */
    9796  BYTE type;            /* Reader type code */
     
    111110
    112111/* Handling of the drive associated with this IFD */
    113 extern int IFD_Towitoko_Init (IFD * ifd, IO_Serial * io, BYTE slot);
     112extern int IFD_Towitoko_Init (IFD * ifd, BYTE slot);
    114113extern int IFD_Towitoko_Close (IFD * ifd);
    115114
    116115/* Handling of this IFD */
    117116extern int IFD_Towitoko_SetBaudrate (IFD * ifd, unsigned long baudrate);
    118 extern int IFD_Towitoko_GetBaudrate (IFD * ifd, unsigned long *baudrate);
    119117
    120118/* General handling of ICC inserted in this IFD */
    121 extern int IFD_Towitoko_ActivateICC (IFD * ifd);
    122 extern int IFD_Towitoko_DeactivateICC (IFD * ifd);
     119extern int IFD_Towitoko_ActivateICC ();
     120extern int IFD_Towitoko_DeactivateICC ();
    123121
    124122/* Asynchronous ICC handling functions */
    125 extern int IFD_Towitoko_ResetAsyncICC (IFD * ifd, ATR ** atr);
     123extern int IFD_Towitoko_ResetAsyncICC (ATR ** atr);
    126124
    127125/* Atributes of the drive associated with this IFD */
  • branches/monitor-improvement/csctapi/io_serial.c

    r1250 r1257  
    6363
    6464static bool IO_Serial_WaitToWrite (unsigned delay_ms, unsigned timeout_ms);
    65 
    66 static bool IO_Serial_InitPnP (IO_Serial * io);
    67 
    68 static void IO_Serial_Clear (IO_Serial * io);
    6965
    7066static int _in_echo_read = 0;
     
    157153 */
    158154
    159 IO_Serial * IO_Serial_New (int mhz, int cardmhz)
    160 {
    161     IO_Serial *io;
    162 
    163     io = (IO_Serial *) malloc (sizeof (IO_Serial));
    164 
    165     if (io != NULL)
    166         IO_Serial_Clear (io);
    167 
    168     return io;
    169 }
    170 
    171 bool IO_Serial_Init (IO_Serial * io, int reader_type)
    172 {
    173     reader[ridx].typ = reader_type;
    174     if (reader[ridx].typ != R_INTERNAL)
    175         IO_Serial_InitPnP (io);
    176 
    177     if(reader[ridx].typ!=R_INTERNAL)
    178         IO_Serial_Flush();
    179 
    180     return TRUE;
    181 }
    182 
    183 bool IO_Serial_GetPropertiesOld (IO_Serial * io)
    184 {
    185     struct termios currtio;
    186     speed_t i_speed, o_speed;
    187     unsigned int mctl;
    188 
    189 #ifdef SCI_DEV
    190     if(reader[ridx].typ == R_INTERNAL)
    191         return FALSE;
    192 #endif
    193 
    194     if (io->input_bitrate != 0 && io->output_bitrate != 0) //properties are already filled
    195       return TRUE;
    196 
    197     if (tcgetattr (reader[ridx].handle, &currtio) != 0)
    198         return FALSE;
    199 
    200     o_speed = cfgetospeed (&currtio);
    201 
    202     switch (o_speed)
    203     {
    204 #ifdef B0
    205         case B0:
    206             io->output_bitrate = 0;
    207             break;
    208 #endif
    209 #ifdef B50
    210         case B50:
    211             io->output_bitrate = 50;
    212             break;
    213 #endif
    214 #ifdef B75
    215         case B75:
    216             io->output_bitrate = 75;
    217             break;
    218 #endif
    219 #ifdef B110
    220         case B110:
    221             io->output_bitrate = 110;
    222             break;
    223 #endif
    224 #ifdef B134
    225         case B134:
    226             io->output_bitrate = 134;
    227             break;
    228 #endif
    229 #ifdef B150
    230         case B150:
    231             io->output_bitrate = 150;
    232             break;
    233 #endif
    234 #ifdef B200
    235         case B200:
    236             io->output_bitrate = 200;
    237             break;
    238 #endif
    239 #ifdef B300
    240         case B300:
    241             io->output_bitrate = 300;
    242             break;
    243 #endif
    244 #ifdef B600
    245         case B600:
    246             io->output_bitrate = 600;
    247             break;
    248 #endif
    249 #ifdef B1200
    250         case B1200:
    251             io->output_bitrate = 1200;
    252             break;
    253 #endif
    254 #ifdef B1800
    255         case B1800:
    256             io->output_bitrate = 1800;
    257             break;
    258 #endif
    259 #ifdef B2400
    260         case B2400:
    261             io->output_bitrate = 2400;
    262             break;
    263 #endif
    264 #ifdef B4800
    265         case B4800:
    266             io->output_bitrate = 4800;
    267             break;
    268 #endif
    269 #ifdef B9600
    270         case B9600:
    271             io->output_bitrate = 9600;
    272             break;
    273 #endif
    274 #ifdef B19200
    275         case B19200:
    276             io->output_bitrate = 19200;
    277             break;
    278 #endif
    279 #ifdef B38400
    280         case B38400:
    281             io->output_bitrate = 38400;
    282             break;
    283 #endif
    284 #ifdef B57600
    285         case B57600:
    286             io->output_bitrate = 57600;
    287             break;
    288 #endif
    289 #ifdef B115200
    290         case B115200:
    291             io->output_bitrate = 115200;
    292             break;
    293 #endif
    294 #ifdef B230400
    295         case B230400:
    296             io->output_bitrate = 230400;
    297             break;
    298 #endif
    299         default:
    300             io->output_bitrate = 1200;
    301             break;
    302     }
    303 
    304     i_speed = cfgetispeed (&currtio);
    305 
    306     switch (i_speed)
    307     {
    308 #ifdef B0
    309         case B0:
    310             io->input_bitrate = 0;
    311             break;
    312 #endif
    313 #ifdef B50
    314         case B50:
    315             io->input_bitrate = 50;
    316             break;
    317 #endif
    318 #ifdef B75
    319         case B75:
    320             io->input_bitrate = 75;
    321             break;
    322 #endif
    323 #ifdef B110
    324         case B110:
    325             io->input_bitrate = 110;
    326             break;
    327 #endif
    328 #ifdef B134
    329         case B134:
    330             io->input_bitrate = 134;
    331             break;
    332 #endif
    333 #ifdef B150
    334         case B150:
    335             io->input_bitrate = 150;
    336             break;
    337 #endif
    338 #ifdef B200
    339         case B200:
    340             io->input_bitrate = 200;
    341             break;
    342 #endif
    343 #ifdef B300
    344         case B300:
    345             io->input_bitrate = 300;
    346             break;
    347 #endif
    348 #ifdef B600
    349         case B600:
    350             io->input_bitrate = 600;
    351             break;
    352 #endif
    353 #ifdef B1200
    354         case B1200:
    355             io->input_bitrate = 1200;
    356             break;
    357 #endif
    358 #ifdef B1800
    359         case B1800:
    360             io->input_bitrate = 1800;
    361             break;
    362 #endif
    363 #ifdef B2400
    364         case B2400:
    365             io->input_bitrate = 2400;
    366             break;
    367 #endif
    368 #ifdef B4800
    369         case B4800:
    370             io->input_bitrate = 4800;
    371             break;
    372 #endif
    373 #ifdef B9600
    374         case B9600:
    375             io->input_bitrate = 9600;
    376             break;
    377 #endif
    378 #ifdef B19200
    379         case B19200:
    380             io->input_bitrate = 19200;
    381             break;
    382 #endif
    383 #ifdef B38400
    384         case B38400:
    385             io->input_bitrate = 38400;
    386             break;
    387 #endif
    388 #ifdef B57600
    389         case B57600:
    390             io->input_bitrate = 57600;
    391             break;
    392 #endif
    393 #ifdef B115200
    394         case B115200:
    395             io->input_bitrate = 115200;
    396             break;
    397 #endif
    398 #ifdef B230400
    399         case B230400:
    400             io->input_bitrate = 230400;
    401             break;
    402 #endif
    403         default:
    404             io->input_bitrate = 1200;
    405             break;
    406     }
    407 
    408     switch (currtio.c_cflag & CSIZE)
    409     {
    410         case CS5:
    411             io->bits = 5;
    412             break;
    413         case CS6:
    414             io->bits = 6;
    415             break;
    416         case CS7:
    417             io->bits = 7;
    418             break;
    419         case CS8:
    420             io->bits = 8;
    421             break;
    422     }
    423 
    424     if (((currtio.c_cflag) & PARENB) == PARENB)
    425     {
    426         if (((currtio.c_cflag) & PARODD) == PARODD)
    427             io->parity = PARITY_ODD;
    428         else
    429             io->parity = PARITY_EVEN;
    430     }
    431     else
    432     {
    433         io->parity = PARITY_NONE;
    434     }
    435 
    436     if (((currtio.c_cflag) & CSTOPB) == CSTOPB)
    437         io->stopbits = 2;
    438     else
    439         io->stopbits = 1;
    440 
    441     if (ioctl (reader[ridx].handle, TIOCMGET, &mctl) < 0)
    442         return FALSE;
    443 
    444     io->dtr = ((mctl & TIOCM_DTR) ? IO_SERIAL_HIGH : IO_SERIAL_LOW);
    445     io->rts = ((mctl & TIOCM_RTS) ? IO_SERIAL_HIGH : IO_SERIAL_LOW);
    446 
    447 #ifdef DEBUG_IO
    448     printf("IO: Getting properties: %ld bps; %d bits/byte; %s parity; %d stopbits; dtr=%d; rts=%d\n", io->input_bitrate, io->bits, io->parity == PARITY_EVEN ? "Even" : io->parity == PARITY_ODD ? "Odd" : "None", io->stopbits, io->dtr, io->rts);
    449 #endif
    450 
    451     return TRUE;
    452 }
    453 
    454 bool IO_Serial_SetPropertiesOld (IO_Serial * io)
    455 {
    456    struct termios newtio;
    457 
    458 #ifdef SCI_DEV
    459    if(reader[ridx].typ == R_INTERNAL)
    460       return FALSE;
    461 #endif
    462 
    463    //   printf("IO: Setting properties: reader_type%d, %ld bps; %d bits/byte; %s parity; %d stopbits; dtr=%d; rts=%d\n", reader[ridx].typ, io->input_bitrate, io->bits, io->parity == PARITY_EVEN ? "Even" : io->parity == PARITY_ODD ? "Odd" : "None", io->stopbits, io->dtr, io->rts);
    464    memset (&newtio, 0, sizeof (newtio));
    465 
    466 
     155bool IO_Serial_SetBitrate (unsigned long bitrate, struct termios * tio)
     156{
    467157   /* Set the bitrate */
    468158#ifdef OS_LINUX
    469159   if (reader[ridx].mhz == reader[ridx].cardmhz)
    470160#endif
    471    { //no overclocking
    472      cfsetospeed(&newtio, IO_Serial_Bitrate(io->output_bitrate));
    473      cfsetispeed(&newtio, IO_Serial_Bitrate(io->input_bitrate));
    474      cs_debug("standard baudrate: cardmhz=%d mhz=%d -> effective baudrate %lu", reader[ridx].cardmhz, reader[ridx].mhz, io->output_bitrate);
     161   { //no overcloking
     162     cfsetospeed(tio, IO_Serial_Bitrate(bitrate));
     163     cfsetispeed(tio, IO_Serial_Bitrate(bitrate));
     164     cs_debug("standard baudrate: cardmhz=%d mhz=%d -> effective baudrate %lu", reader[ridx].cardmhz, reader[ridx].mhz, bitrate);
    475165   }
    476166#ifdef OS_LINUX
     
    479169    struct serial_struct nuts;
    480170    ioctl(reader[ridx].handle, TIOCGSERIAL, &nuts);
    481     int custom_baud = io->output_bitrate * reader[ridx].mhz / reader[ridx].cardmhz;
     171    int custom_baud = bitrate * reader[ridx].mhz / reader[ridx].cardmhz;
    482172    nuts.custom_divisor = (nuts.baud_base + (custom_baud/2))/ custom_baud;
    483173    cs_debug("custom baudrate: cardmhz=%d mhz=%d custom_baud=%d baud_base=%d divisor=%d -> effective baudrate %d",
     
    486176    nuts.flags |= ASYNC_SPD_CUST;
    487177    ioctl(reader[ridx].handle, TIOCSSERIAL, &nuts);
    488     cfsetospeed(&newtio, IO_Serial_Bitrate(38400));
    489     cfsetispeed(&newtio, IO_Serial_Bitrate(38400));
     178    cfsetospeed(tio, IO_Serial_Bitrate(38400));
     179    cfsetispeed(tio, IO_Serial_Bitrate(38400));
    490180   }
    491181#endif
    492 
     182    return TRUE;
     183}
     184
     185bool IO_Serial_SetParams (unsigned long bitrate, unsigned bits, int parity, unsigned stopbits, int dtr, int rts)
     186{
     187     struct termios newtio;
     188   
     189     if(reader[ridx].typ == R_INTERNAL)
     190            return FALSE;
     191     
     192     memset (&newtio, 0, sizeof (newtio));
     193
     194    if (!IO_Serial_SetBitrate (bitrate, & newtio))
     195        return FALSE;
     196               
    493197   /* Set the character size */
    494    switch (io->bits)
     198     switch (bits)
    495199   {
    496200        case 5:
     
    512216
    513217    /* Set the parity */
    514     switch (io->parity)
     218    switch (parity)
    515219    {
    516220        case PARITY_ODD:
     
    530234
    531235    /* Set the number of stop bits */
    532     switch (io->stopbits)
     236    switch (stopbits)
    533237    {
    534238        case 1:
     
    554258    newtio.c_cc[VTIME] = 0;
    555259
    556 //  tcdrain(reader[ridx].handle);
    557     if (tcsetattr (reader[ridx].handle, TCSANOW, &newtio) < 0)
    558         return FALSE;
    559 //  tcflush(reader[ridx].handle, TCIOFLUSH);
    560 //  if (tcsetattr (reader[ridx].handle, TCSAFLUSH, &newtio) < 0)
    561 //      return FALSE;
    562 
    563     IO_Serial_Ioctl_Lock(1);
    564     IO_Serial_DTR_RTS(0, io->rts == IO_SERIAL_HIGH);
    565     IO_Serial_DTR_RTS(1, io->dtr == IO_SERIAL_HIGH);
    566     IO_Serial_Ioctl_Lock(0);
    567 
    568 #ifdef DEBUG_IO
    569     printf("IO: Setting properties: reader_type%d, %ld bps; %d bits/byte; %s parity; %d stopbits; dtr=%d; rts=%d\n", reader[ridx].typ, io->input_bitrate, io->bits, io->parity == PARITY_EVEN ? "Even" : io->parity == PARITY_ODD ? "Odd" : "None", io->stopbits, io->dtr, io->rts);
    570 #endif
    571     return TRUE;
    572 }
    573 
    574 bool IO_Serial_SetProperties (struct termios newtio)
    575 {
    576    if(reader[ridx].typ == R_INTERNAL)
    577       return FALSE;
    578 
    579     if (tcsetattr (reader[ridx].handle, TCSANOW, &newtio) < 0)
    580         return FALSE;
    581 //  tcflush(reader[ridx].handle, TCIOFLUSH);
    582 //  if (tcsetattr (reader[ridx].handle, TCSAFLUSH, &newtio) < 0)
    583 //      return FALSE;
    584 
    585     unsigned int mctl;
    586     if (ioctl (reader[ridx].handle, TIOCMGET, &mctl) < 0)
    587         return FALSE;
    588 
    589     int dtr = ((mctl & TIOCM_DTR) ? IO_SERIAL_HIGH : IO_SERIAL_LOW);
    590     int rts = ((mctl & TIOCM_RTS) ? IO_SERIAL_HIGH : IO_SERIAL_LOW);
     260    if (!IO_Serial_SetProperties(newtio))
     261        return FALSE;
     262
     263    reader[ridx].baudrate = bitrate;
    591264
    592265    IO_Serial_Ioctl_Lock(1);
     
    594267    IO_Serial_DTR_RTS(1, dtr == IO_SERIAL_HIGH);
    595268    IO_Serial_Ioctl_Lock(0);
     269
     270    return TRUE;
     271}
     272
     273bool IO_Serial_SetProperties (struct termios newtio)
     274{
     275   if(reader[ridx].typ == R_INTERNAL)
     276      return FALSE;
     277
     278    if (tcsetattr (reader[ridx].handle, TCSANOW, &newtio) < 0)
     279        return FALSE;
     280//  tcflush(reader[ridx].handle, TCIOFLUSH);
     281//  if (tcsetattr (reader[ridx].handle, TCSAFLUSH, &newtio) < 0)
     282//      return FALSE;
     283
     284    unsigned int mctl;
     285    if (ioctl (reader[ridx].handle, TIOCMGET, &mctl) < 0)
     286        return FALSE;
    596287
    597288#ifdef DEBUG_IO
     
    671362}
    672363
    673 
    674 void IO_Serial_GetPnPId (IO_Serial * io, BYTE * pnp_id, unsigned *length)
    675 {
    676     (*length) = io->PnP_id_size;
    677     memcpy (pnp_id, io->PnP_id, io->PnP_id_size);
    678 }
    679364
    680365bool IO_Serial_Read (unsigned timeout, unsigned size, BYTE * data)
     
    837522}
    838523
    839 bool IO_Serial_Close (IO_Serial * io)
     524bool IO_Serial_Close ()
    840525{
    841526
     
    850535        return FALSE;
    851536
    852     IO_Serial_Clear (io);
     537    wr = 0;
    853538
    854539    return TRUE;
     
    1031716}
    1032717
    1033 static void IO_Serial_Clear (IO_Serial * io)
    1034 {
    1035     memset (io->PnP_id, 0, IO_SERIAL_PNPID_SIZE);
    1036     io->PnP_id_size = 0;
    1037     wr = 0;
    1038     //modifyable properties:
    1039     io->input_bitrate = 0;
    1040     io->output_bitrate = 0;
    1041     io->bits = 0;
    1042     io->stopbits = 0;
    1043     io->parity = 0;
    1044     io->dtr = 0;
    1045     io->rts = 0;
    1046 }
    1047 
    1048 static bool IO_Serial_InitPnP (IO_Serial * io)
    1049 {
    1050     int i = 0;
    1051     io->input_bitrate = 1200;
    1052     io->output_bitrate = 1200;
    1053     io->parity = PARITY_NONE;
    1054     io->bits = 7;
    1055     io->stopbits = 1;
    1056     io->dtr = IO_SERIAL_HIGH;
    1057     io->rts = IO_SERIAL_LOW;
    1058 
    1059     if (!IO_Serial_SetPropertiesOld (io))
    1060         return FALSE;
    1061 
    1062     while ((i < IO_SERIAL_PNPID_SIZE) && IO_Serial_Read (200, 1, &(io->PnP_id[i])))
    1063       i++;
    1064 
    1065     io->PnP_id_size = i;
     718bool IO_Serial_InitPnP ()
     719{
     720    unsigned int PnP_id_size = 0;
     721    BYTE PnP_id[IO_SERIAL_PNPID_SIZE];  /* PnP Id of the serial device */
     722
     723  if (!IO_Serial_SetParams (1200, 7, PARITY_NONE, 1, IO_SERIAL_HIGH, IO_SERIAL_LOW))
     724        return FALSE;
     725
     726    while ((PnP_id_size < IO_SERIAL_PNPID_SIZE) && IO_Serial_Read (200, 1, &(PnP_id[PnP_id_size])))
     727      PnP_id_size++;
     728
    1066729        return TRUE;
    1067730}
  • branches/monitor-improvement/csctapi/io_serial.h

    r1240 r1257  
    4848#define IO_SERIAL_PNPID_SIZE        256
    4949
    50 /*
    51  * Exported datatypes definition
    52  */
    53 
    54 /* IO_Serial exported datatype */
    55 typedef struct
    56 {
    57     /* Settings that can be modified */
    58     unsigned long input_bitrate;
    59     unsigned long  output_bitrate;
    60     unsigned bits;
    61     unsigned stopbits;
    62     int parity;
    63     int dtr;
    64     int rts;   
    65     /* end settings that can be modified */
    66     BYTE PnP_id[IO_SERIAL_PNPID_SIZE];  /* PnP Id of the serial device */
    67     unsigned PnP_id_size;           /* Length of PnP Id */
    68 }
    69 IO_Serial;
    70 
    7150int wr; //FIXME should be in ifd_phoenix.c or .h
    7251
     
    7655
    7756/* IO_Serial creation and deletion */
    78 //extern void IO_Serial_Reopen (IO_Serial * io);
    7957extern void IO_Serial_Flush ();
    80 extern IO_Serial *IO_Serial_New (int mhz, int cardmhz);
    81 extern void IO_Serial_Delete (IO_Serial * io);
    8258
    8359/* Initialization and closing */
    84 extern bool IO_Serial_Init (IO_Serial * io, int reader_type);
    85 extern bool IO_Serial_Close (IO_Serial * io);
     60extern bool IO_Serial_InitPnP (void);
     61extern bool IO_Serial_Close ();
    8662
    8763/* Transmission properties */
    88 extern bool IO_Serial_SetPropertiesOld (IO_Serial * io);
    89 extern bool IO_Serial_GetPropertiesOld (IO_Serial * io);
    9064extern bool IO_Serial_DTR_RTS(int, int);
    9165#if defined(TUXBOX) && defined(PPC)
     
    9973extern bool IO_Serial_Write (unsigned delay, unsigned size, BYTE * data);
    10074
    101 /* Serial port atributes */
    102 extern void IO_Serial_GetPnPId (IO_Serial * io, BYTE * pnp_id, unsigned *length);
    103 
    10475#endif /* IO_SERIAL */
  • branches/monitor-improvement/globals.h

    r1256 r1257  
    411411  int       card_status; //highlevel status
    412412  unsigned short status; //lowlevel status: states whether card inserted and/or change of status FIXME look at integration with pcsc_has_card/detect/card_status
    413     unsigned long baudrate; //we are storing baudrate to prevent unnecessary conversions from/to termios structure
     413    unsigned long baudrate; //we are storing the (for overclocking uncorrected) baudrate to prevent unnecessary conversions from/to termios structure
    414414  struct    s_module ph;
    415415  uchar     ncd_key[16];
  • branches/monitor-improvement/reader-common.c

    r1240 r1257  
    309309  cs_ptyp=D_DEVICE;
    310310#ifdef TUXBOX
    311   if ((rc=CT_init(1, reader_device_type(device),reader[ridx].mhz,reader[ridx].cardmhz))!=OK)
     311    reader[ridx].typ = reader_device_type(device);
     312  if ((rc=CT_init(1))!=OK)
    312313    cs_log("[tuxbox] Cannot open device: %s", device);
    313314#else
    314   if ((rc=CT_init(1, reader[ridx].typ,reader[ridx].mhz,reader[ridx].cardmhz))!=OK)
     315  if ((rc=CT_init(1))!=OK)
    315316    cs_log("Cannot open device: %s", device);
    316317#endif
Note: See TracChangeset for help on using the changeset viewer.