Changeset 487
- Timestamp:
- 11/02/09 19:05:56 (11 years ago)
- Location:
- branches/merlin/csctapi
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/merlin/csctapi/ifd_towitoko.c
r444 r487 151 151 { 152 152 IO_Serial_Properties props; 153 SR_Config sr_config;154 153 int ret; 155 154 … … 195 194 } 196 195 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)) 210 197 return IFD_TOWITOKO_IO_ERROR; 211 198 … … 270 257 { 271 258 IO_Serial_Properties props; 272 SR_Config sr_config; 273 259 274 260 if (ifd->io->reader_type == RTYP_SCI) { 275 261 return IFD_TOWITOKO_OK; … … 287 273 288 274 /* Get current settings */ 289 if (!IO_Serial_GetProperties(ifd->io, &props , &sr_config))275 if (!IO_Serial_GetProperties(ifd->io, &props)) 290 276 return IFD_TOWITOKO_IO_ERROR; 291 277 … … 297 283 props.input_bitrate = baudrate; 298 284 299 if (!IO_Serial_SetProperties(ifd->io, &props , &sr_config))285 if (!IO_Serial_SetProperties(ifd->io, &props)) 300 286 return IFD_TOWITOKO_IO_ERROR; 301 287 … … 306 292 { 307 293 IO_Serial_Properties props; 308 SR_Config sr_config; 309 294 310 295 if (ifd->io->reader_type == RTYP_SCI) { 311 296 return IFD_TOWITOKO_OK; … … 313 298 314 299 /* Get current settings */ 315 if (!IO_Serial_GetProperties(ifd->io, &props , &sr_config))300 if (!IO_Serial_GetProperties(ifd->io, &props)) 316 301 return IFD_TOWITOKO_IO_ERROR; 317 302 … … 324 309 { 325 310 IO_Serial_Properties props; 326 SR_Config sr_config; 327 311 328 312 if (ifd->io->reader_type == RTYP_SCI) { 329 313 return IFD_TOWITOKO_OK; … … 337 321 338 322 /* Get current settings */ 339 if (!IO_Serial_GetProperties(ifd->io, &props , &sr_config))323 if (!IO_Serial_GetProperties(ifd->io, &props)) 340 324 return IFD_TOWITOKO_IO_ERROR; 341 325 … … 343 327 props.parity = parity; 344 328 345 if (!IO_Serial_SetProperties(ifd->io, &props , &sr_config))329 if (!IO_Serial_SetProperties(ifd->io, &props)) 346 330 return IFD_TOWITOKO_IO_ERROR; 347 331 } … … 637 621 #endif 638 622 { 639 double tmp_param;640 BYTE tmp;641 642 623 int ret; 643 624 int parity; … … 720 701 IFD_Towitoko_SetParity(ifd, IFD_TOWITOKO_PARITY_NONE); 721 702 #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 738 703 return ret; 739 704 } -
branches/merlin/csctapi/io_serial.c
r451 r487 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 , SR_Config *sr_config);70 71 static void IO_Serial_SetPropertiesCache(IO_Serial * io, IO_Serial_Properties * props , SR_Config *sr_config);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); 72 72 73 73 static void IO_Serial_ClearPropertiesCache(IO_Serial * io); 74 75 static bool IO_Serial_Set_Smartreader_Config(IO_Serial * io, SR_Config *sr_config);76 74 77 75 static int _in_echo_read = 0; … … 218 216 } 219 217 220 bool IO_Serial_GetProperties(IO_Serial * io, IO_Serial_Properties * props , SR_Config *sr_config)218 bool IO_Serial_GetProperties(IO_Serial * io, IO_Serial_Properties * props) 221 219 { 222 220 struct termios currtio; … … 229 227 #endif 230 228 231 if (IO_Serial_GetPropertiesCache(io, props ,sr_config))229 if (IO_Serial_GetPropertiesCache(io, props)) 232 230 return TRUE; 233 231 … … 291 289 props->rts = ((mctl & TIOCM_RTS) ? IO_SERIAL_HIGH : IO_SERIAL_LOW); 292 290 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); 306 292 307 293 #ifdef DEBUG_IO … … 312 298 } 313 299 314 bool IO_Serial_SetProperties(IO_Serial * io, IO_Serial_Properties * props , SR_Config *sr_config)300 bool IO_Serial_SetProperties(IO_Serial * io, IO_Serial_Properties * props) 315 301 { 316 302 struct termios newtio; … … 340 326 int output_speed = IO_Serial_Bitrate_to_Speed(props->output_bitrate); 341 327 int input_speed = IO_Serial_Bitrate_to_Speed(props->input_bitrate); 342 #ifdef DEBUG_IO343 printf("IO: output_speed = %d\n",output_speed);344 printf("IO: input_speed = %d\n",input_speed);345 346 #endif347 328 cfsetospeed(&newtio, output_speed); 348 329 cfsetispeed(&newtio, input_speed); … … 395 376 reader_serial_bitrate_effective = effective_bitrate; 396 377 397 # ifdef DEBUG_IO398 printf("IO: standard bitrate being set to %d\n",IO_Serial_Bitrate_to_Speed(standard_bitrate));399 400 # endif401 378 /* Set the standard bitrate value */ 402 379 cfsetospeed(&newtio, IO_Serial_Bitrate_to_Speed(standard_bitrate)); … … 404 381 } 405 382 #endif 406 407 if (io->reader_type == RTYP_SMARTREADER) {408 #ifdef DEBUG_IO409 printf("IO: Smartreader+ .. setting config with a frequency of %2.2fMHz\n", (float) io->frequency / 1000000);410 #endif411 if (!IO_Serial_Set_Smartreader_Config(io,sr_config)) {412 #ifdef DEBUG_IO413 printf("IO: Smartreader+ .. ERROR setting configuration\n");414 #endif415 return FALSE;416 }417 }418 383 419 384 /* Set the character size */ … … 489 454 IO_Serial_Ioctl_Lock(io, 0); 490 455 491 IO_Serial_SetPropertiesCache(io, props , sr_config);456 IO_Serial_SetPropertiesCache(io, props); 492 457 493 458 #ifdef DEBUG_IO … … 666 631 { 667 632 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; 681 699 } 682 } 683 return B0; 700 } 701 702 return result; 684 703 } 685 704 … … 883 902 } 884 903 885 static void IO_Serial_SetPropertiesCache(IO_Serial * io, IO_Serial_Properties * props , SR_Config *sr_config)904 static void IO_Serial_SetPropertiesCache(IO_Serial * io, IO_Serial_Properties * props) 886 905 { 887 906 #ifdef SCI_DEV … … 892 911 if (io->props == NULL) 893 912 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 898 913 #ifdef DEBUG_IO 899 914 printf("IO: Catching properties\n"); … … 901 916 902 917 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 920 static bool IO_Serial_GetPropertiesCache(IO_Serial * io, IO_Serial_Properties * props) 921 { 922 if (io->props != NULL) { 914 923 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; 943 931 } 944 932 … … 957 945 { 958 946 IO_Serial_Properties props; 959 SR_Config srConfig;960 961 947 int i = 0; 962 948 … … 975 961 } 976 962 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)) 988 964 return FALSE; 989 965 … … 994 970 return TRUE; 995 971 } 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_IO1008 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 # endif1010 1011 // Set SmartReader+ in CMD mode.1012 struct termios term;1013 if(tcgetattr(io->fd,&term)==-1)1014 {1015 # ifdef DEBUG_IO1016 printf("%s: tcgetattr failed: %s",io->device,strerror(errno));1017 #endif1018 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_IO1026 printf("%s: tcsetattr failed: %s",io->device,strerror(errno));1027 #endif1028 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_IO1058 printf("%s: tcsendbreak failed: %s",io->device,strerror(errno));1059 #endif1060 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_IO1072 printf("%s: tcsetattr failed: %s",io->device,strerror(errno));1073 #endif1074 return FALSE;1075 }1076 return TRUE;1077 }1078 1079 -
branches/merlin/csctapi/io_serial.h
r440 r487 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 76 67 /* IO_Serial exported datatype */ 77 68 typedef struct { … … 84 75 unsigned long frequency; /* Frequency (Hz) */ 85 76 int wr; 86 SR_Config *SmartReaderConf;87 77 } IO_Serial; 88 78 … … 102 92 103 93 /* 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);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); 106 96 extern bool IO_Serial_DTR_RTS(IO_Serial * io, int, int); 107 97
Note:
See TracChangeset
for help on using the changeset viewer.