Changeset 1962
- Timestamp:
- 04/05/10 21:19:09 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/csctapi/ifd_sc8in1.c
r1960 r1962 31 31 static int current_slot; //FIXME should not be a global, but one per SC8in1 32 32 static unsigned char cardstatus; //FIXME not global but one per SC8in1 //if not static, the threads dont share same cardstatus! 33 static unsigned char sc8in1_clock[2]; 34 static unsigned short is_mcr; 33 35 34 36 #define MAX_TRANSMIT 255 … … 51 53 termio.c_cflag = B9600|CS8|CREAD|CLOCAL; 52 54 if (tcsetattr(reader->handle,TCSANOW,&termio) < 0) { 53 cs_log("ERROR: SC8in1 readsc8in1 set RS232 attributes\n"); 54 return ERROR; 55 } 56 IO_Serial_Write (reader, 0, lenwrite, buff); 55 cs_log("ERROR: SC8in1 Command error in set RS232 attributes\n"); 56 return ERROR; 57 } 58 cs_ddump_mask (D_DEVICE, buff, lenwrite, "IO: Sending: "); 59 write(reader->handle, buff, lenwrite); //dont use IO_Serial_Write since mcr commands dont echo back 57 60 tcdrain(reader->handle); 58 61 if (IO_Serial_Read (reader, 1000, lenread, buff) == ERROR) { 59 cs_log(" READSC8in1read error");62 cs_log("SC8in1 Command read error"); 60 63 return ERROR; 61 64 } … … 68 71 memcpy(&termio,&termiobackup,sizeof(termio)); 69 72 if (tcsetattr(reader->handle,TCSANOW,&termio) < 0) { 70 cs_log("ERROR: SC8in1 readsc8in1restore RS232 attributes\n");73 cs_log("ERROR: SC8in1 Command error in restore RS232 attributes\n"); 71 74 return ERROR; 72 75 } … … 90 93 buf[0]=0x47; 91 94 if (sc8in1_command(reader, buf, 1, 8) < 0) return (-1); 92 if (buf[ 0]!=0x90) return(-1);95 if (buf[1]!=0x90) return(-1); 93 96 94 97 // return result byte 95 return(buf[ 1]);98 return(buf[2]); 96 99 } 97 100 … … 147 150 //additional init, Phoenix_Init is also called for Sc8in1 ! 148 151 struct termios termio; 152 int i; 149 153 tcgetattr(reader->handle,&termio); 150 int i;151 154 for (i=0; i<8; i++) 152 155 //init all stored termios to default comm settings after device init, before ATR 153 156 memcpy(&stored_termio[i],&termio,sizeof(termio)); 157 unsigned char buff[] = { 0x74 }; 158 sc8in1_command(reader, buff, 1, 1); 159 if (buff[0] == 4 || buff[0] == 8) { 160 is_mcr = (unsigned short) buff[0]; 161 cs_log("SC8in1: device MCR%i detected", is_mcr); 162 } 163 else 164 is_mcr = 0; 165 tcflush(reader->handle, TCIOFLUSH); // a non MCR reader might give longer answer 154 166 return OK; 155 167 } … … 172 184 pthread_mutex_lock(&sc8in1); 173 185 cs_debug("SC8in1: locked for Getstatus for slot %i",reader->slot); 174 int i=readsc8in1(reader); 186 int i=readsc8in1(reader); //read cardstatus 175 187 pthread_mutex_unlock(&sc8in1); 176 188 cs_debug("SC8in1: unlocked for Getstatus for slot %i",reader->slot); … … 183 195 return OK; 184 196 } 197 198 int MCR_SetClockrate (struct s_reader * reader, int mhz) 199 { 200 unsigned short speed, shift, mask; 201 switch (mhz) { 202 case 357: 203 case 358: 204 speed = 0; 205 break; 206 case 368: 207 case 369: 208 speed = 1; 209 break; 210 case 600: 211 speed = 2; 212 break; 213 case 800: 214 speed = 3; 215 break; 216 default: 217 speed = 0; 218 cs_log("ERROR Sc8in1, cannot set clockspeed to %i", mhz); 219 break; 220 } 221 if (reader->slot >= 5) 222 shift = (reader->slot - 5) * 2; 223 else 224 shift = (reader->slot - 1) * 2; 225 speed = speed << shift; 226 mask = 3 << shift; 227 228 if (reader->slot >= 5) { 229 sc8in1_clock[0] &= mask; 230 sc8in1_clock[0] |= speed; 231 } 232 else { 233 sc8in1_clock[1] &= mask; 234 sc8in1_clock[1] |= speed; 235 } 236 return OK; 237 }
Note:
See TracChangeset
for help on using the changeset viewer.