Changeset 440
- Timestamp:
- 09/21/09 06:55:00 (15 years ago)
- Location:
- branches/merlin
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/merlin/csctapi/atr.c
r279 r440 33 33 */ 34 34 35 static unsigned long atr_fs_table[16] = { 0, 5000000L, 6000000L, 8000000L, 12000000L, 16000000L, 20000000L, 0, 0, 5000000L, 7500000L, 10000000L, 15000000L, 20000000L, 0, 0 }; 35 // static unsigned long atr_fs_table[16] = { 0, 5000000L, 6000000L, 8000000L, 12000000L, 16000000L, 20000000L, 0, 0, 5000000L, 7500000L, 10000000L, 15000000L, 20000000L, 0, 0 }; 36 static unsigned long atr_fs_table[16] = {3571200L, 5000000L, 6000000L, 8000000L, 12000000L, 16000000L, 20000000L , 0L, 0L, 5000000L, 7500000L, 10000000L, 15000000L, 20000000L , 0L, 0L}; 36 37 37 38 static unsigned atr_num_ib_table[16] = { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4 }; … … 41 42 */ 42 43 43 unsigned atr_f_table[16] = { 0, 372, 558, 744, 1116, 1488, 1860, 0, 0, 512, 768, 1024, 1536, 2048, 0, 0 }; 44 // unsigned atr_f_table[16] = { 0, 372, 558, 744, 1116, 1488, 1860, 0, 0, 512, 768, 1024, 1536, 2048, 0, 0 }; 45 unsigned atr_f_table[16] = {372,372,558,744,1116,1488,1860,0,0,512,768,1024,1536,2048,0,0}; 44 46 45 47 double atr_d_table[16] = { 0, 1, 2, 4, 8, 16, 0, 0, 0, 0, 0.5, 0.25, 125, 0.0625, 0.03125, 0.015625 }; -
branches/merlin/csctapi/config.h
r349 r440 11 11 /* Debug CT-API */ 12 12 /* #undef DEBUG_CTAPI */ 13 //#define DEBUG_CTAPI 113 #define DEBUG_CTAPI 1 14 14 15 15 /* Debug Integrated Circuit Card */ 16 16 17 17 /* #undef DEBUG_ICC */ 18 //#define DEBUG_ICC 118 #define DEBUG_ICC 1 19 19 20 20 /* Debug Interface Device */ 21 21 22 22 /* #undef DEBUG_IFD */ 23 //#define DEBUG_IFD 123 #define DEBUG_IFD 1 24 24 25 25 /* Debug IFD Handler */ 26 26 27 27 /* #undef DEBUG_IFDH */ 28 //#define DEBUG_IFDH 128 #define DEBUG_IFDH 1 29 29 30 30 /* Debug Input/Output */ 31 31 32 32 /* #undef DEBUG_IO */ 33 //#define DEBUG_IO 133 #define DEBUG_IO 1 34 34 35 35 /* Debug Protocol */ 36 36 37 37 /* #undef DEBUG_PROTOCOL */ 38 //#define DEBUG_PROTOCOL 138 #define DEBUG_PROTOCOL 1 39 39 40 40 //#define PROTOCOL_T0_ISO 1 41 //#define PROTOCOL_T1_ISO 141 #define PROTOCOL_T1_ISO 1 42 42 43 43 -
branches/merlin/csctapi/ifd_towitoko.c
r348 r440 151 151 { 152 152 IO_Serial_Properties props; 153 SR_Config sr_config; 153 154 int ret; 154 155 … … 194 195 } 195 196 196 if (!IO_Serial_SetProperties(io, &props)) 197 // set smartreader+ default values 198 sr_config.F=372; 199 sr_config.D=1.0; 200 sr_config.fs=3571200; 201 sr_config.N=0; 202 sr_config.T=0; 203 sr_config.inv=0; 204 205 if (!IO_Serial_SetProperties(io, &props, &sr_config)) 197 206 return IFD_TOWITOKO_IO_ERROR; 198 207 … … 257 266 { 258 267 IO_Serial_Properties props; 259 268 SR_Config sr_config; 269 260 270 if (ifd->io->reader_type == RTYP_SCI) { 261 271 return IFD_TOWITOKO_OK; … … 273 283 274 284 /* Get current settings */ 275 if (!IO_Serial_GetProperties(ifd->io, &props ))285 if (!IO_Serial_GetProperties(ifd->io, &props, &sr_config)) 276 286 return IFD_TOWITOKO_IO_ERROR; 277 287 … … 283 293 props.input_bitrate = baudrate; 284 294 285 if (!IO_Serial_SetProperties(ifd->io, &props ))295 if (!IO_Serial_SetProperties(ifd->io, &props, &sr_config)) 286 296 return IFD_TOWITOKO_IO_ERROR; 287 297 … … 292 302 { 293 303 IO_Serial_Properties props; 294 304 SR_Config sr_config; 305 295 306 if (ifd->io->reader_type == RTYP_SCI) { 296 307 return IFD_TOWITOKO_OK; … … 298 309 299 310 /* Get current settings */ 300 if (!IO_Serial_GetProperties(ifd->io, &props ))311 if (!IO_Serial_GetProperties(ifd->io, &props, &sr_config)) 301 312 return IFD_TOWITOKO_IO_ERROR; 302 313 … … 309 320 { 310 321 IO_Serial_Properties props; 311 322 SR_Config sr_config; 323 312 324 if (ifd->io->reader_type == RTYP_SCI) { 313 325 return IFD_TOWITOKO_OK; … … 321 333 322 334 /* Get current settings */ 323 if (!IO_Serial_GetProperties(ifd->io, &props ))335 if (!IO_Serial_GetProperties(ifd->io, &props, &sr_config)) 324 336 return IFD_TOWITOKO_IO_ERROR; 325 337 … … 327 339 props.parity = parity; 328 340 329 if (!IO_Serial_SetProperties(ifd->io, &props ))341 if (!IO_Serial_SetProperties(ifd->io, &props, &sr_config)) 330 342 return IFD_TOWITOKO_IO_ERROR; 331 343 } … … 621 633 #endif 622 634 { 635 double tmp_param; 636 BYTE tmp; 637 623 638 int ret; 624 639 int parity; … … 701 716 IFD_Towitoko_SetParity(ifd, IFD_TOWITOKO_PARITY_NONE); 702 717 #endif 718 // if we get here we have a valid ATR and can init the IO->SmartReaderConf strcture. 719 ATR_GetParameter((*atr), ATR_PARAMETER_F, &tmp_param); 720 ((ifd->io)->SmartReaderConf)->F=(int)tmp_param; 721 722 ATR_GetParameter((*atr), ATR_PARAMETER_D, &tmp_param); 723 ((ifd->io)->SmartReaderConf)->D=(float)tmp_param; 724 725 ((ifd->io)->SmartReaderConf)->fs = (ifd->io)->frequency; 726 727 ATR_GetParameter((*atr), ATR_PARAMETER_N, &tmp_param); 728 ((ifd->io)->SmartReaderConf)->N=(int)tmp_param; 729 730 ATR_GetProtocolType((*atr), 2, &tmp); 731 ((ifd->io)->SmartReaderConf)->T = (int)tmp_param && 0xFF; 732 ATR_GetConvention((*atr), &((ifd->io)->SmartReaderConf)->inv); 733 703 734 return ret; 704 735 } -
branches/merlin/csctapi/io_serial.c
r436 r440 67 67 static void IO_Serial_Clear(IO_Serial * io); 68 68 69 static bool IO_Serial_GetPropertiesCache(IO_Serial * io, IO_Serial_Properties * props );70 71 static void IO_Serial_SetPropertiesCache(IO_Serial * io, IO_Serial_Properties * props );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); 72 72 73 73 static void IO_Serial_ClearPropertiesCache(IO_Serial * io); 74 74 75 static bool IO_Serial_Set_Smartreader_ Freq(IO_Serial * io);75 static bool IO_Serial_Set_Smartreader_Config(IO_Serial * io, SR_Config *sr_config); 76 76 77 77 static int _in_echo_read = 0; … … 218 218 } 219 219 220 bool IO_Serial_GetProperties(IO_Serial * io, IO_Serial_Properties * props )220 bool IO_Serial_GetProperties(IO_Serial * io, IO_Serial_Properties * props, SR_Config *sr_config) 221 221 { 222 222 struct termios currtio; … … 229 229 #endif 230 230 231 if (IO_Serial_GetPropertiesCache(io, props ))231 if (IO_Serial_GetPropertiesCache(io, props,sr_config)) 232 232 return TRUE; 233 233 … … 291 291 props->rts = ((mctl & TIOCM_RTS) ? IO_SERIAL_HIGH : IO_SERIAL_LOW); 292 292 293 IO_Serial_SetPropertiesCache(io, props); 293 // set smartreader+ default values 294 sr_config->F=372; 295 sr_config->D=1.0; 296 sr_config->fs=3571200; 297 sr_config->N=0; 298 sr_config->T=0; 299 sr_config->inv=0; 300 301 IO_Serial_SetPropertiesCache(io, props, sr_config); 294 302 295 303 #ifdef DEBUG_IO … … 300 308 } 301 309 302 bool IO_Serial_SetProperties(IO_Serial * io, IO_Serial_Properties * props )310 bool IO_Serial_SetProperties(IO_Serial * io, IO_Serial_Properties * props, SR_Config *sr_config) 303 311 { 304 312 struct termios newtio; … … 386 394 if (io->reader_type == RTYP_SMARTREADER) { 387 395 #ifdef DEBUG_IO 388 printf("IO: S MARTREADER .. switching to frequency to%2.2fMHz\n", (float) io->frequency / 1000000);389 #endif 390 if (!IO_Serial_Set_Smartreader_ Freq(io)) {391 #ifdef DEBUG_IO 392 printf("IO: S MARTREADER .. ERROR switching to %2.2fMHz\n", (float) io->frequency / 1000000);396 printf("IO: Smartreader+ .. setting config with a frequency of %2.2fMHz\n", (float) io->frequency / 1000000); 397 #endif 398 if (!IO_Serial_Set_Smartreader_Config(io,sr_config)) { 399 #ifdef DEBUG_IO 400 printf("IO: Smartreader+ .. ERROR setting configuration\n"); 393 401 #endif 394 402 return FALSE; … … 468 476 IO_Serial_Ioctl_Lock(io, 0); 469 477 470 IO_Serial_SetPropertiesCache(io, props );478 IO_Serial_SetPropertiesCache(io, props, sr_config); 471 479 472 480 #ifdef DEBUG_IO … … 862 870 } 863 871 864 static void IO_Serial_SetPropertiesCache(IO_Serial * io, IO_Serial_Properties * props )872 static void IO_Serial_SetPropertiesCache(IO_Serial * io, IO_Serial_Properties * props, SR_Config *sr_config) 865 873 { 866 874 #ifdef SCI_DEV … … 871 879 if (io->props == NULL) 872 880 io->props = (IO_Serial_Properties *) malloc(sizeof (IO_Serial_Properties)); 881 882 if (io->SmartReaderConf == NULL) 883 io->SmartReaderConf = (SR_Config *) malloc(sizeof (SR_Config)); 884 873 885 #ifdef DEBUG_IO 874 886 printf("IO: Catching properties\n"); … … 876 888 877 889 memcpy(io->props, props, sizeof (IO_Serial_Properties)); 878 } 879 880 static bool IO_Serial_GetPropertiesCache(IO_Serial * io, IO_Serial_Properties * props) 881 { 882 if (io->props != NULL) { 890 memcpy(io->SmartReaderConf, sr_config, sizeof (SR_Config)); 891 } 892 893 static bool IO_Serial_GetPropertiesCache(IO_Serial * io, IO_Serial_Properties * props, SR_Config *sr_config) 894 { 895 bool ok_props, ok_sr; 896 897 ok_props=FALSE; 898 ok_sr=FALSE; 899 if (io->props != NULL) 900 { 883 901 memcpy(props, io->props, sizeof (IO_Serial_Properties)); 884 #if 0885 902 # ifdef DEBUG_IO 886 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, 887 props->rts); 903 printf("IO: Getting properties (catched): %ld bps; %d bits/byte; %s parity; %d stopbits; dtr=%d; rts=%d\n", 904 props->input_bitrate, props->bits, 905 props->parity == IO_SERIAL_PARITY_EVEN ? "Even" : props->parity == IO_SERIAL_PARITY_ODD ? "Odd" : "None", 906 props->stopbits, 907 props->dtr, 908 props->rts); 888 909 # endif 889 #endif 890 return TRUE; 891 } 892 893 return FALSE; 910 ok_props=TRUE; 911 } 912 913 if (io->SmartReaderConf != NULL) 914 { 915 memcpy(sr_config, io->SmartReaderConf, sizeof (SR_Config)); 916 # ifdef DEBUG_IO 917 printf("IO: Getting SmartReader+ config (catched): F=%d; D=%f; fs=%d; N=%d; T=%d; inv=%d \n", 918 sr_config->F, 919 sr_config->D, 920 sr_config->fs, 921 sr_config->N, 922 sr_config->T, 923 sr_config->inv); 924 # endif 925 ok_sr=TRUE; 926 } 927 928 929 return ok_props && ok_sr; 894 930 } 895 931 … … 908 944 { 909 945 IO_Serial_Properties props; 946 SR_Config srConfig; 947 910 948 int i = 0; 911 949 … … 924 962 } 925 963 926 if (!IO_Serial_SetProperties(io, &props)) 964 // set smartreader+ default values 965 srConfig.F=372; 966 srConfig.D=1.0; 967 srConfig.fs=3571200; 968 srConfig.N=0; 969 srConfig.T=0; 970 srConfig.inv=0; 971 972 if (!IO_Serial_SetProperties(io, &props, &srConfig)) 927 973 return FALSE; 928 974 … … 934 980 } 935 981 936 static bool IO_Serial_Set_Smartreader_Freq(IO_Serial * io) 937 { 982 static bool IO_Serial_Set_Smartreader_Config(IO_Serial * io, SR_Config *sr_config) 983 { 984 int F=sr_config->F; 985 float D=sr_config->D; 986 int fs=sr_config->fs; 987 int N=sr_config->N; 988 int T=sr_config->T; 989 int inv=sr_config->inv; 990 991 fs/=1000; // convert to kHz. 992 # ifdef DEBUG_IO 993 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); 994 # endif 995 996 // Set SmartReader+ in CMD mode. 938 997 struct termios term; 939 struct termios orig; 940 unsigned char fi_di[4] = { 0x01, 0x01, 0x74, 0x01 }; 941 unsigned char fr[3] = { 0x02, 0x00, 0x00 }; 942 unsigned char nn[2] = { 0x03, 0x00 }; 943 unsigned char pr[2] = { 0x04, 0x00 }; 944 unsigned char in[2] = { 0x05, 0x00 }; 945 946 orig = term; 947 948 /* set smartreader in CMD mode */ 949 tcgetattr(io->fd, &term); 950 951 term.c_cflag &= ~CSIZE; 952 term.c_cflag |= CS5; 953 cfsetospeed(&term, 9600); 954 cfsetispeed(&term, 9600); 955 tcsetattr(io->fd, TCSANOW, &term); 956 957 // our freq comes in as Hz and it needs this to be in KHz for the FR command 958 unsigned long freq = io->frequency / 1000; 959 fr[1] = (unsigned char) ((freq & 0xff00) >> 8); 960 fr[2] = (unsigned char) (freq & 0x00ff); 961 962 // Irdeto card supposedly need NN set to 1 .. to be confirmed 963 // if (irdeto_mode) TODO: use NN from ATR 964 nn[1] = 0x01; 965 966 // send the commands 967 IO_Serial_Write(io, 0, 4, fi_di); 968 IO_Serial_Flush(io); 969 970 IO_Serial_Write(io, 0, 3, fr); 971 IO_Serial_Flush(io); 972 973 IO_Serial_Write(io, 0, 2, nn); 974 IO_Serial_Flush(io); 975 976 IO_Serial_Write(io, 0, 2, pr); 977 IO_Serial_Flush(io); 978 979 IO_Serial_Write(io, 0, 2, in); 980 IO_Serial_Flush(io); 981 982 /* set smartreader in DATA mode */ 983 tcgetattr(io->fd, &orig); 984 orig.c_cflag &= ~CSIZE; 985 orig.c_cflag |= CS8; 986 tcsetattr(io->fd, TCSANOW, &orig); 987 998 if(tcgetattr(io->fd,&term)==-1) 999 { 1000 # ifdef DEBUG_IO 1001 printf("%s: tcgetattr failed: %s",io->device,strerror(errno)); 1002 #endif 1003 return FALSE; 1004 } 1005 1006 term.c_cflag&=~CSIZE; 1007 term.c_cflag|=CS5; 1008 if(tcsetattr(io->fd,TCSADRAIN,&term)==-1) 1009 { 1010 # ifdef DEBUG_IO 1011 printf("%s: tcsetattr failed: %s",io->device,strerror(errno)); 1012 #endif 1013 return FALSE; 1014 } 1015 // Write SmartReader+ configuration commands. 1016 unsigned char cmd[16]; 1017 1018 //XXX how is (int)D supposed to work for fractional values e.g. 0.125 ?? 1019 cmd[0]=1; cmd[1]=F>>8; cmd[2]=F; cmd[3]=(int)D; 1020 if(!IO_Serial_Write(io, 0, 4, cmd)) 1021 return FALSE; 1022 1023 cmd[0]=2; cmd[1]=fs>>8; cmd[2]=fs; 1024 if(!IO_Serial_Write(io, 0, 3, cmd)) 1025 return FALSE; 1026 1027 cmd[0]=3; cmd[1]=N; 1028 if(!IO_Serial_Write(io, 0, 2, cmd)) 1029 return FALSE; 1030 1031 cmd[0]=4; cmd[1]=T; 1032 if(!IO_Serial_Write(io, 0, 2, cmd)) 1033 return FALSE; 1034 1035 cmd[0]=5; cmd[1]=inv; 1036 if(!IO_Serial_Write(io, 0, 2, cmd)) 1037 return FALSE; 1038 1039 // Send zero bits for 0.25 - 0.5 seconds. 1040 if(tcsendbreak(io->fd,0)==-1) 1041 { 1042 # ifdef DEBUG_IO 1043 printf("%s: tcsendbreak failed: %s",io->device,strerror(errno)); 1044 #endif 1045 return FALSE; 1046 } 1047 // We're entering SmartReader+ mode; speed up serial communication. 1048 // B230400 is the highest setting that sticks. 1049 cfsetispeed(&term,B230400); 1050 cfsetospeed(&term,B230400); 1051 // Set SmartReader+ in DATA mode. 1052 term.c_cflag&=~CSIZE; 1053 term.c_cflag|=CS8; 1054 if(tcsetattr(io->fd,TCSADRAIN,&term)==-1) 1055 { 1056 # ifdef DEBUG_IO 1057 printf("%s: tcsetattr failed: %s",io->device,strerror(errno)); 1058 #endif 1059 return FALSE; 1060 } 988 1061 return TRUE; 989 1062 } 1063 1064 -
branches/merlin/csctapi/io_serial.h
r346 r440 65 65 } IO_Serial_Properties; 66 66 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 67 76 /* IO_Serial exported datatype */ 68 77 typedef struct { … … 75 84 unsigned long frequency; /* Frequency (Hz) */ 76 85 int wr; 86 SR_Config *SmartReaderConf; 77 87 } IO_Serial; 78 88 … … 92 102 93 103 /* Transmission properties */ 94 extern bool IO_Serial_SetProperties(IO_Serial * io, IO_Serial_Properties * props );95 extern bool IO_Serial_GetProperties(IO_Serial * io, IO_Serial_Properties * props );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); 96 106 extern bool IO_Serial_DTR_RTS(IO_Serial * io, int, int); 97 107 -
branches/merlin/csctapi/pps.c
r430 r440 117 117 #ifndef PPS_USE_DEFAULT_TIMINGS 118 118 atr = ICC_Async_GetAtr(pps->icc); 119 119 printf("atr.lenght = %u\n",atr->length); 120 printf("atr.TS = %u\n",atr->TS); 121 printf("atr.T0 = %u\n",atr->T0); 122 printf("atr.TA = %u\n",atr->ib[0][ATR_INTERFACE_BYTE_TA].value); 123 printf("atr.FI = %u\n",(atr->ib[0][ATR_INTERFACE_BYTE_TA].value & 0xF0) >> 4); 124 printf("atr.DI = %u\n",(atr->ib[0][ATR_INTERFACE_BYTE_TA].value & 0x0F)); 125 120 126 ATR_GetParameter(atr, ATR_PARAMETER_N, &(pps->parameters.n)); 121 127 ATR_GetParameter(atr, ATR_PARAMETER_D, &(pps->parameters.d)); 122 128 ATR_GetParameter(atr, ATR_PARAMETER_F, &(pps->parameters.f)); 129 printf("pps->parameters.n %f\n",pps->parameters.n); 130 printf("pps->parameters.d %f\n",pps->parameters.d); 131 printf("pps->parameters.f %f\n",pps->parameters.f); 123 132 133 124 134 // for some unknown reason (for now): 125 135 // ATR_GetParameter(atr, ATR_PARAMETER_D, &(pps->parameters.d)); … … 127 137 // this totaly breaks on OS X 128 138 // so for now we're commenting the PPS_InitICC call. 129 130 139 //ret = PPS_InitICC(pps); 131 140 -
branches/merlin/src/reader/common.c
r399 r440 116 116 { 117 117 int rc = 0; 118 119 if ((reader->type & R_IS_SERIAL) != 0) {118 if ((reader->type & R_IS_SERIAL) != 0) { 119 printf("reader_common_init\n"); 120 120 rc = reader_serial_init(reader); 121 121 log_normal("Reader: Initialized serial reader %s (%s @ %2.2f Mhz %s%s)", reader->label, reader->device, (float) reader->frequency / 1000000, reader->detect & 0x80 ? "!" : "", RDR_CD_TXT[reader->detect & 0x7f]);
Note:
See TracChangeset
for help on using the changeset viewer.