Changeset 487


Ignore:
Timestamp:
Nov 2, 2009, 7:05:56 PM (10 years ago)
Author:
Merlin
Message:

Temporarily removed smartreader stuffs, small change in IO_Serial_Bitrate_to_Speed()

Location:
branches/merlin/csctapi
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/merlin/csctapi/ifd_towitoko.c

    r444 r487  
    151151{
    152152    IO_Serial_Properties props;
    153     SR_Config sr_config;
    154153    int ret;
    155154
     
    195194    }
    196195
    197     // set smartreader+ default values
    198     // for Irdeto card, the Frequency is 6.00MHz and the F parameter need to be set to 558
    199     // test have shown that an irdeto card still reply to an ATR at 9600 with a Freq of 3.5712 MHz
    200     // we need to do more test to see if this work with irdeto cards so I'm reverting my changes
    201     // to use the original default smartreader+ values
    202     sr_config.F=372;
    203     sr_config.D=1.0;
    204     sr_config.fs=3571200;
    205     sr_config.N=0;
    206     sr_config.T=0;
    207     sr_config.inv=0;
    208 
    209     if (!IO_Serial_SetProperties(io, &props, &sr_config))
     196    if (!IO_Serial_SetProperties(io, &props))
    210197        return IFD_TOWITOKO_IO_ERROR;
    211198
     
    270257{
    271258    IO_Serial_Properties props;
    272     SR_Config sr_config;
    273    
     259
    274260    if (ifd->io->reader_type == RTYP_SCI) {
    275261        return IFD_TOWITOKO_OK;
     
    287273
    288274    /* Get current settings */
    289     if (!IO_Serial_GetProperties(ifd->io, &props, &sr_config))
     275    if (!IO_Serial_GetProperties(ifd->io, &props))
    290276        return IFD_TOWITOKO_IO_ERROR;
    291277
     
    297283    props.input_bitrate = baudrate;
    298284
    299     if (!IO_Serial_SetProperties(ifd->io, &props, &sr_config))
     285    if (!IO_Serial_SetProperties(ifd->io, &props))
    300286        return IFD_TOWITOKO_IO_ERROR;
    301287
     
    306292{
    307293    IO_Serial_Properties props;
    308     SR_Config sr_config;
    309    
     294
    310295    if (ifd->io->reader_type == RTYP_SCI) {
    311296        return IFD_TOWITOKO_OK;
     
    313298
    314299    /* Get current settings */
    315     if (!IO_Serial_GetProperties(ifd->io, &props, &sr_config))
     300    if (!IO_Serial_GetProperties(ifd->io, &props))
    316301        return IFD_TOWITOKO_IO_ERROR;
    317302
     
    324309{
    325310    IO_Serial_Properties props;
    326     SR_Config sr_config;
    327    
     311
    328312    if (ifd->io->reader_type == RTYP_SCI) {
    329313        return IFD_TOWITOKO_OK;
     
    337321
    338322    /* Get current settings */
    339     if (!IO_Serial_GetProperties(ifd->io, &props, &sr_config))
     323    if (!IO_Serial_GetProperties(ifd->io, &props))
    340324        return IFD_TOWITOKO_IO_ERROR;
    341325
     
    343327        props.parity = parity;
    344328
    345         if (!IO_Serial_SetProperties(ifd->io, &props, &sr_config))
     329        if (!IO_Serial_SetProperties(ifd->io, &props))
    346330            return IFD_TOWITOKO_IO_ERROR;
    347331    }
     
    637621#endif
    638622    {
    639         double tmp_param;
    640         BYTE tmp;
    641        
    642623        int ret;
    643624        int parity;
     
    720701        IFD_Towitoko_SetParity(ifd, IFD_TOWITOKO_PARITY_NONE);
    721702#endif
    722         // if we get here we have a valid ATR and can init the IO->SmartReaderConf strcture.
    723         ATR_GetParameter((*atr), ATR_PARAMETER_F, &tmp_param);
    724         ((ifd->io)->SmartReaderConf)->F=(int)tmp_param;
    725        
    726         ATR_GetParameter((*atr), ATR_PARAMETER_D, &tmp_param);
    727         ((ifd->io)->SmartReaderConf)->D=(float)tmp_param;
    728 
    729         ((ifd->io)->SmartReaderConf)->fs = (ifd->io)->frequency;
    730 
    731         ATR_GetParameter((*atr), ATR_PARAMETER_N, &tmp_param);
    732         ((ifd->io)->SmartReaderConf)->N=(int)tmp_param;
    733 
    734         ATR_GetProtocolType((*atr), 2, &tmp);
    735         ((ifd->io)->SmartReaderConf)->T = (int)tmp_param && 0xFF;
    736         ATR_GetConvention((*atr), &((ifd->io)->SmartReaderConf)->inv);
    737 
    738703        return ret;
    739704    }
  • branches/merlin/csctapi/io_serial.c

    r451 r487  
    6767static void IO_Serial_Clear(IO_Serial * io);
    6868
    69 static bool IO_Serial_GetPropertiesCache(IO_Serial * io, IO_Serial_Properties * props, SR_Config *sr_config);
    70 
    71 static void IO_Serial_SetPropertiesCache(IO_Serial * io, IO_Serial_Properties * props, SR_Config *sr_config);
     69static bool IO_Serial_GetPropertiesCache(IO_Serial * io, IO_Serial_Properties * props);
     70
     71static void IO_Serial_SetPropertiesCache(IO_Serial * io, IO_Serial_Properties * props);
    7272
    7373static void IO_Serial_ClearPropertiesCache(IO_Serial * io);
    74 
    75 static bool IO_Serial_Set_Smartreader_Config(IO_Serial * io, SR_Config *sr_config);
    7674
    7775static int _in_echo_read = 0;
     
    218216}
    219217
    220 bool IO_Serial_GetProperties(IO_Serial * io, IO_Serial_Properties * props, SR_Config *sr_config)
     218bool IO_Serial_GetProperties(IO_Serial * io, IO_Serial_Properties * props)
    221219{
    222220    struct termios currtio;
     
    229227#endif
    230228
    231     if (IO_Serial_GetPropertiesCache(io, props,sr_config))
     229    if (IO_Serial_GetPropertiesCache(io, props))
    232230        return TRUE;
    233231
     
    291289    props->rts = ((mctl & TIOCM_RTS) ? IO_SERIAL_HIGH : IO_SERIAL_LOW);
    292290
    293     // set smartreader+ default values
    294     // for Irdeto card, the Frequency is 6.00MHz and the F parameter need to be set to 558
    295     // test have shown that an irdeto card still reply to an ATR at 9600 with a Freq of 3.5712 MHz
    296     // we need to do more test to see if this work with irdeto cards so I'm reverting my changes
    297     // to use the original default smartreader+ values
    298     sr_config->F=372;
    299     sr_config->D=1.0;
    300     sr_config->fs=3571200;
    301     sr_config->N=0;
    302     sr_config->T=0;
    303     sr_config->inv=0;
    304    
    305     IO_Serial_SetPropertiesCache(io, props, sr_config);
     291    IO_Serial_SetPropertiesCache(io, props);
    306292
    307293#ifdef DEBUG_IO
     
    312298}
    313299
    314 bool IO_Serial_SetProperties(IO_Serial * io, IO_Serial_Properties * props, SR_Config *sr_config)
     300bool IO_Serial_SetProperties(IO_Serial * io, IO_Serial_Properties * props)
    315301{
    316302    struct termios newtio;
     
    340326        int output_speed = IO_Serial_Bitrate_to_Speed(props->output_bitrate);
    341327        int input_speed = IO_Serial_Bitrate_to_Speed(props->input_bitrate);
    342 #ifdef DEBUG_IO
    343         printf("IO: output_speed = %d\n",output_speed);
    344         printf("IO: input_speed = %d\n",input_speed);
    345        
    346 #endif
    347328        cfsetospeed(&newtio, output_speed);
    348329        cfsetispeed(&newtio, input_speed);
     
    395376        reader_serial_bitrate_effective = effective_bitrate;
    396377
    397 # ifdef DEBUG_IO
    398         printf("IO: standard bitrate being set to %d\n",IO_Serial_Bitrate_to_Speed(standard_bitrate));
    399        
    400 # endif
    401378        /* Set the standard bitrate value */
    402379        cfsetospeed(&newtio, IO_Serial_Bitrate_to_Speed(standard_bitrate));
     
    404381    }
    405382#endif
    406 
    407     if (io->reader_type == RTYP_SMARTREADER) {
    408 #ifdef DEBUG_IO
    409         printf("IO: Smartreader+ .. setting config with a frequency of %2.2fMHz\n", (float) io->frequency / 1000000);
    410 #endif
    411         if (!IO_Serial_Set_Smartreader_Config(io,sr_config)) {
    412 #ifdef DEBUG_IO
    413             printf("IO: Smartreader+ ..  ERROR setting configuration\n");
    414 #endif
    415             return FALSE;
    416         }
    417     }
    418383
    419384    /* Set the character size */
     
    489454    IO_Serial_Ioctl_Lock(io, 0);
    490455
    491     IO_Serial_SetPropertiesCache(io, props, sr_config);
     456    IO_Serial_SetPropertiesCache(io, props);
    492457
    493458#ifdef DEBUG_IO
     
    666631{
    667632    static const struct BaudRates { int real; speed_t apival; } BaudRateTab[] = {
    668         {   200, B200   }, {  300, B300  }, {  600, B600  },
    669         {   1200, B1200   }, {  2400, B2400  }, {  4800, B4800  },
    670         {   9600, B9600   }, {  19200, B19200  }, {  38400, B38400  },
    671         {  57600, B57600  }, { 115200, B115200 }, { 230400, B230400 }
    672     };
    673 
    674     int i;
    675    
    676     for(i=0; i<(int)(sizeof(BaudRateTab)/sizeof(struct BaudRates)); i++) {
    677         int b=BaudRateTab[i].real;
    678         int d=((b-bitrate)*10000)/b;
    679         if(abs(d)<=300) {
    680             return BaudRateTab[i].apival;
     633#ifdef B50
     634        {     50, B50     },
     635#endif
     636#ifdef B75
     637        {     75, B75     },
     638#endif
     639#ifdef B110
     640        {    110, B110    },
     641#endif
     642#ifdef B134
     643        {    134, B134    },
     644#endif
     645#ifdef B150
     646        {    150, B150    },
     647#endif
     648#ifdef B200
     649        {    200, B200    },
     650#endif
     651#ifdef B300
     652        {    300, B300    },
     653#endif
     654#ifdef B600
     655        {    600, B600    },
     656#endif
     657#ifdef B1200
     658        {   1200, B1200   },
     659#endif
     660#ifdef B1800
     661        {   1800, B1800   },
     662#endif
     663#ifdef B2400
     664        {   2400, B2400   },
     665#endif
     666#ifdef B4800
     667        {   4800, B4800   },
     668#endif
     669#ifdef B9600
     670        {   9600, B9600   },
     671#endif
     672#ifdef B19200
     673        {  19200, B19200  },
     674#endif
     675#ifdef B38400
     676        {  38400, B38400  },
     677#endif
     678#ifdef B57600
     679        {  57600, B57600  },
     680#endif
     681#ifdef B115200
     682        { 115200, B115200 },
     683#endif
     684#ifdef B230400
     685        { 230400, B230400 },
     686#endif
     687    };
     688
     689    speed_t result = B0;
     690    int i, d_result = bitrate;
     691
     692    for ( i = 0 ; i < (int)(sizeof(BaudRateTab)/sizeof(struct BaudRates)) ; i++) {
     693        int d = abs(BaudRateTab[i].real - bitrate);
     694        if (d < d_result) {
     695            result = BaudRateTab[i].apival;
     696            d_result = d;
     697        } else {
     698            break;
    681699        }
    682     }
    683     return B0;
     700    }
     701
     702    return result;
    684703}
    685704
     
    883902}
    884903
    885 static void IO_Serial_SetPropertiesCache(IO_Serial * io, IO_Serial_Properties * props, SR_Config *sr_config)
     904static void IO_Serial_SetPropertiesCache(IO_Serial * io, IO_Serial_Properties * props)
    886905{
    887906#ifdef SCI_DEV
     
    892911    if (io->props == NULL)
    893912        io->props = (IO_Serial_Properties *) malloc(sizeof (IO_Serial_Properties));
    894 
    895     if (io->SmartReaderConf == NULL)
    896         io->SmartReaderConf = (SR_Config *) malloc(sizeof (SR_Config));
    897 
    898913#ifdef DEBUG_IO
    899914    printf("IO: Catching properties\n");
     
    901916
    902917    memcpy(io->props, props, sizeof (IO_Serial_Properties));
    903     memcpy(io->SmartReaderConf, sr_config, sizeof (SR_Config));
    904 }
    905 
    906 static bool IO_Serial_GetPropertiesCache(IO_Serial * io, IO_Serial_Properties * props, SR_Config *sr_config)
    907 {
    908     bool ok_props, ok_sr;
    909    
    910     ok_props=FALSE;
    911     ok_sr=FALSE;
    912     if (io->props != NULL)
    913         {
     918}
     919
     920static bool IO_Serial_GetPropertiesCache(IO_Serial * io, IO_Serial_Properties * props)
     921{
     922    if (io->props != NULL) {
    914923        memcpy(props, io->props, sizeof (IO_Serial_Properties));
    915 #  ifdef DEBUG_IO
    916         printf("IO: Getting properties (catched): %ld bps; %d bits/byte; %s parity; %d stopbits; dtr=%d; rts=%d\n",
    917                 props->input_bitrate, props->bits,
    918                 props->parity == IO_SERIAL_PARITY_EVEN ? "Even" : props->parity == IO_SERIAL_PARITY_ODD ? "Odd" : "None",
    919                 props->stopbits,
    920                 props->dtr,
    921                 props->rts);
    922 #  endif
    923         ok_props=TRUE;
    924         }
    925 
    926     if (io->SmartReaderConf != NULL)
    927         {
    928         memcpy(sr_config, io->SmartReaderConf, sizeof (SR_Config));
    929 #  ifdef DEBUG_IO
    930         printf("IO: Getting SmartReader+ config (catched): F=%d; D=%f; fs=%d; N=%d; T=%d; inv=%d \n",
    931                 sr_config->F,
    932                 sr_config->D,
    933                 sr_config->fs,
    934                 sr_config->N,
    935                 sr_config->T,
    936                 sr_config->inv);
    937 #  endif
    938         ok_sr=TRUE;
    939         }
    940 
    941 
    942     return ok_props && ok_sr;
     924#ifdef DEBUG_IO
     925               printf("IO: Getting properties (catched): %ld bps; %d bits/byte; %s parity; %d stopbits; dtr=%d; rts=%d\n", props->input_bitrate, props->bits, props->parity == IO_SERIAL_PARITY_EVEN ? "Even" : props->parity == IO_SERIAL_PARITY_ODD ? "Odd" : "None", props->stopbits, props->dtr, props->rts);
     926#endif
     927        return TRUE;
     928    }
     929
     930    return FALSE;
    943931}
    944932
     
    957945{
    958946    IO_Serial_Properties props;
    959     SR_Config srConfig;
    960    
    961947    int i = 0;
    962948
     
    975961    }
    976962
    977     // set smartreader+ default values
    978     // use the frequency to get F for the smartreader
    979     // to make sure the ATR is sent at 9600.
    980     srConfig.F=io->frequency/9600;
    981     srConfig.D=1.0;
    982     srConfig.fs=io->frequency;
    983     srConfig.N=0;
    984     srConfig.T=0;
    985     srConfig.inv=0;
    986    
    987     if (!IO_Serial_SetProperties(io, &props, &srConfig))
     963    if (!IO_Serial_SetProperties(io, &props))
    988964        return FALSE;
    989965
     
    994970    return TRUE;
    995971}
    996 
    997 static bool IO_Serial_Set_Smartreader_Config(IO_Serial * io, SR_Config *sr_config)
    998 {
    999     int F=sr_config->F;
    1000     float D=sr_config->D;
    1001     int fs=sr_config->fs;
    1002     int N=sr_config->N;
    1003     int T=sr_config->T;
    1004     int inv=sr_config->inv;
    1005 
    1006     fs/=1000; // convert to kHz.
    1007 #  ifdef DEBUG_IO
    1008     printf("IO: Smartreader+ on %s: SR+ options F=%d D=%f fs=%d N=%d T=%d inv=%d\n",io->device,F,D,fs,N,T,inv);
    1009 #  endif
    1010 
    1011     // Set SmartReader+ in CMD mode.
    1012     struct termios term;
    1013     if(tcgetattr(io->fd,&term)==-1)
    1014         {
    1015 #  ifdef DEBUG_IO
    1016         printf("%s: tcgetattr failed: %s",io->device,strerror(errno));
    1017 #endif
    1018         return FALSE;
    1019         }
    1020 
    1021     term.c_cflag&=~CSIZE;
    1022     term.c_cflag|=CS5;
    1023     if(tcsetattr(io->fd,TCSADRAIN,&term)==-1)
    1024         {
    1025 #  ifdef DEBUG_IO
    1026         printf("%s: tcsetattr failed: %s",io->device,strerror(errno));
    1027 #endif
    1028         return FALSE;
    1029         }
    1030     // Write SmartReader+ configuration commands.
    1031     unsigned char cmd[16];
    1032 
    1033     //XXX how is (int)D supposed to work for fractional values e.g. 0.125 ??
    1034     cmd[0]=1; cmd[1]=F>>8; cmd[2]=F; cmd[3]=(int)D;
    1035     if(!IO_Serial_Write(io, 0, 4, cmd))
    1036         return FALSE;
    1037 
    1038     cmd[0]=2; cmd[1]=fs>>8; cmd[2]=fs;
    1039     if(!IO_Serial_Write(io, 0, 3, cmd))
    1040         return FALSE;
    1041 
    1042     cmd[0]=3; cmd[1]=N;
    1043     if(!IO_Serial_Write(io, 0, 2, cmd))
    1044         return FALSE;
    1045 
    1046     cmd[0]=4; cmd[1]=T;
    1047     if(!IO_Serial_Write(io, 0, 2, cmd))
    1048         return FALSE;
    1049 
    1050     cmd[0]=5; cmd[1]=inv;
    1051     if(!IO_Serial_Write(io, 0, 2, cmd))
    1052         return FALSE;
    1053 
    1054     // Send zero bits for 0.25 - 0.5 seconds.
    1055     if(tcsendbreak(io->fd,0)==-1)
    1056         {
    1057 #  ifdef DEBUG_IO
    1058         printf("%s: tcsendbreak failed: %s",io->device,strerror(errno));
    1059 #endif
    1060         return FALSE;
    1061         }
    1062     // We're entering SmartReader+ mode; speed up serial communication.
    1063     // B230400 is the highest setting that sticks.
    1064     cfsetispeed(&term,B230400);
    1065     cfsetospeed(&term,B230400);
    1066     // Set SmartReader+ in DATA mode.
    1067     term.c_cflag&=~CSIZE;
    1068     term.c_cflag|=CS8;
    1069     if(tcsetattr(io->fd,TCSADRAIN,&term)==-1)
    1070         {
    1071 #  ifdef DEBUG_IO
    1072         printf("%s: tcsetattr failed: %s",io->device,strerror(errno));
    1073 #endif
    1074         return FALSE;
    1075         }
    1076     return TRUE;
    1077 }
    1078 
    1079 
  • branches/merlin/csctapi/io_serial.h

    r440 r487  
    6565} IO_Serial_Properties;
    6666
    67 typedef struct {
    68     int F;
    69     float D;
    70     int fs;
    71     int N;
    72     int T;
    73     int inv;
    74 } SR_Config;
    75 
    7667/* IO_Serial exported datatype */
    7768typedef struct {
     
    8475    unsigned long frequency;    /* Frequency (Hz) */
    8576    int wr;
    86     SR_Config *SmartReaderConf;
    8777} IO_Serial;
    8878
     
    10292
    10393/* Transmission properties */
    104 extern bool IO_Serial_SetProperties(IO_Serial * io, IO_Serial_Properties * props, SR_Config *sr_config);
    105 extern bool IO_Serial_GetProperties(IO_Serial * io, IO_Serial_Properties * props, SR_Config *sr_config);
     94extern bool IO_Serial_SetProperties(IO_Serial * io, IO_Serial_Properties * props);
     95extern bool IO_Serial_GetProperties(IO_Serial * io, IO_Serial_Properties * props);
    10696extern bool IO_Serial_DTR_RTS(IO_Serial * io, int, int);
    10797
Note: See TracChangeset for help on using the changeset viewer.