Changeset 1257
- Timestamp:
- 01/16/10 21:09:44 (14 years ago)
- Location:
- branches/monitor-improvement
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/monitor-improvement/csctapi/cardterminal.c
r1240 r1257 49 49 static char CardTerminal_GetStatus (CardTerminal * ct, APDU_Cmd * cmd, APDU_Rsp ** rsp); 50 50 51 static char CardTerminal_SetParity ( CardTerminal * ct,APDU_Cmd * cmd, APDU_Rsp ** rsp);51 static char CardTerminal_SetParity (APDU_Cmd * cmd, APDU_Rsp ** rsp); 52 52 53 53 static char CardTerminal_EjectICC (CardTerminal * ct, APDU_Cmd * cmd, APDU_Rsp ** rsp); … … 71 71 } 72 72 73 char CardTerminal_Init (CardTerminal * ct , int reader_type, int mhz, int cardmhz)73 char CardTerminal_Init (CardTerminal * ct) 74 74 { 75 75 char ret; 76 76 int i; 77 77 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 85 78 /* Initialise serial port */ 86 if (ICC_Async_Device_Init ()) { 87 printf("ERROR in initializing device\n"); 79 if (ICC_Async_Device_Init ()) 88 80 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 97 82 /* Cearte all reader slots */ 98 83 ct->num_slots = 0; … … 111 96 112 97 /* Initialise slot */ 113 ret = CT_Slot_Init (ct->slots[i], ct->io,i);98 ret = CT_Slot_Init (ct->slots[i], i); 114 99 115 100 if (ret != OK) … … 133 118 } 134 119 135 IO_Serial_Close (ct->io); 136 free (ct->io); 137 ct->io = NULL; 120 IO_Serial_Close (); 138 121 } 139 122 #ifdef HAVE_PTHREAD_H … … 177 160 ret = CardTerminal_GetStatus (ct, cmd, rsp); 178 161 else if (ins == CTBCS_INS_PARITY) /* Get Status */ 179 ret = CardTerminal_SetParity (c t, cmd, rsp);162 ret = CardTerminal_SetParity (cmd, rsp); 180 163 else if (ins == CTBCS_INS_EJECT) /* Eject ICC */ 181 164 ret = CardTerminal_EjectICC (ct, cmd, rsp); … … 213 196 } 214 197 215 if (ct->io != NULL) 216 { 217 if (!IO_Serial_Close (ct->io)) 198 if (!IO_Serial_Close ()) 218 199 ret = ERR_TRANS; 219 200 220 free (ct->io);221 }222 223 201 CardTerminal_Clear (ct); 224 202 … … 296 274 297 275 /* Initialise this slot */ 298 ret = CT_Slot_Init (ct->slots[sn], ct->io,sn);276 ret = CT_Slot_Init (ct->slots[sn],sn); 299 277 300 278 if (ret != OK) … … 690 668 } 691 669 692 static char CardTerminal_SetParity ( CardTerminal * ct,APDU_Cmd * cmd, APDU_Rsp ** rsp)670 static char CardTerminal_SetParity (APDU_Cmd * cmd, APDU_Rsp ** rsp) 693 671 { 694 672 BYTE buffer[2], p1, p2; … … 858 836 int i; 859 837 860 ct->io = NULL;861 838 ct->num_slots = 0; 862 839 -
branches/monitor-improvement/csctapi/cardterminal.h
r1210 r1257 49 49 typedef struct 50 50 { 51 IO_Serial * io; /* Serial device */52 51 CT_Slot * slots[CARDTERMINAL_MAX_SLOTS]; /* Array of CT_Slot's */ 53 52 unsigned int num_slots; /* Number of CT_Slot's */ … … 68 67 /* Intialice a CardTerminal in a given port */ 69 68 extern char 70 CardTerminal_Init (CardTerminal * ct , int reader_type, int mhz, int cardmhz);69 CardTerminal_Init (CardTerminal * ct); 71 70 72 71 /* Send a CT-BCS command to a CardTerminal */ -
branches/monitor-improvement/csctapi/ct_slot.c
r1228 r1257 64 64 } 65 65 66 char CT_Slot_Init (CT_Slot * slot, IO_Serial * io,int sn)66 char CT_Slot_Init (CT_Slot * slot, int sn) 67 67 { 68 68 slot->ifd = IFD_Towitoko_New(); … … 71 71 return ERR_MEMORY; 72 72 73 if (IFD_Towitoko_Init (slot->ifd, io,sn) != IFD_TOWITOKO_OK)73 if (IFD_Towitoko_Init (slot->ifd, sn) != IFD_TOWITOKO_OK) 74 74 { 75 75 IFD_Towitoko_Delete (slot->ifd); -
branches/monitor-improvement/csctapi/ct_slot.h
r1180 r1257 71 71 /* Intialice a CT_Slot */ 72 72 extern char 73 CT_Slot_Init (CT_Slot * slot, IO_Serial * io,int sn);73 CT_Slot_Init (CT_Slot * slot, int sn); 74 74 75 75 /* Check for card inserted */ -
branches/monitor-improvement/csctapi/ctapi.c
r1210 r1257 50 50 */ 51 51 52 char CT_init (unsigned short ctn , int reader_type, int mhz, int cardmhz)52 char CT_init (unsigned short ctn) 53 53 { 54 54 CardTerminal *ct; … … 69 69 { 70 70 /* Initialize CardTerminal */ 71 ret = CardTerminal_Init (ct , reader_type, mhz, cardmhz);71 ret = CardTerminal_Init (ct); 72 72 73 73 /* Add CardTerminal to list */ -
branches/monitor-improvement/csctapi/ctapi.h
r1210 r1257 20 20 21 21 extern 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 */ 26 23 ); 27 24 -
branches/monitor-improvement/csctapi/icc_async.c
r1250 r1257 65 65 int ICC_Async_Device_Init () 66 66 { 67 67 68 wr = 0; 68 69 #ifdef DEBUG_IO 69 70 printf ("IO: Opening serial port %s\n", reader[ridx].device); … … 95 96 } 96 97 #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 98 105 return ICC_ASYNC_OK; 99 106 } … … 211 218 212 219 /* Initialize Baudrate */ 213 if ( IFD_Towitoko_SetBaudrate (ifd, ICC_ASYNC_BAUDRATE)!= IFD_TOWITOKO_OK)220 if (!Phoenix_SetBaudrate (ICC_ASYNC_BAUDRATE)) 214 221 return ICC_ASYNC_IFD_ERROR; 215 222 … … 238 245 else 239 246 #endif 240 if ( IFD_Towitoko_ResetAsyncICC (ifd, &(icc->atr)) != IFD_TOWITOKO_OK)247 if (!Phoenix_Reset(&(icc->atr))) 241 248 { 242 249 icc->atr = NULL; … … 277 284 if (!IO_Serial_SetParity (PARITY_ODD)) 278 285 return ICC_ASYNC_IFD_ERROR; 279 icc->ifd->io->parity = PARITY_ODD;280 286 } 281 287 else if(icc->protocol_type == ATR_PROTOCOL_TYPE_T14) … … 283 289 if (!IO_Serial_SetParity (PARITY_NONE)) 284 290 return ICC_ASYNC_IFD_ERROR; 285 icc->ifd->io->parity = PARITY_NONE;286 291 } 287 292 else … … 289 294 if (!IO_Serial_SetParity (PARITY_EVEN)) 290 295 return ICC_ASYNC_IFD_ERROR; 291 icc->ifd->io->parity = PARITY_EVEN;292 296 } 293 297 #ifdef COOL 294 298 if (reader[ridx].typ != R_INTERNAL) 295 299 #endif 296 IO_Serial_Flush( ifd->io);300 IO_Serial_Flush(); 297 301 return ICC_ASYNC_OK; 298 302 #else … … 354 358 { 355 359 icc->baudrate = baudrate; 356 if ( IFD_Towitoko_SetBaudrate (icc->ifd, baudrate) != IFD_TOWITOKO_OK)360 if (!Phoenix_SetBaudrate (baudrate)) 357 361 return ICC_ASYNC_IFD_ERROR; 358 362 -
branches/monitor-improvement/csctapi/ifd_phoenix.c
r1228 r1257 11 11 #include "atr.h" 12 12 #include "ifd_towitoko.h" //FIXME 13 14 #define OK 1 13 #include <termios.h> 14 15 #define OK 1 15 16 #define ERROR 0 16 17 … … 45 46 46 47 int 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; 49 124 } 50 125 … … 69 144 if (gpio_detect) set_gpio1(0); 70 145 #endif 71 for (sent = 0; sent < size; sent = sent + to_send) 146 for (sent = 0; sent < size; sent = sent + to_send) 72 147 { 73 148 /* Calculate number of bytes to send */ … … 143 218 } 144 219 145 int Phoenix_SetBaudrate (int mhz) 146 { 147 return OK; 148 } 220 int 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 146 146 } 147 147 148 int IFD_Towitoko_Init (IFD * ifd, IO_Serial * io,BYTE slot)148 int IFD_Towitoko_Init (IFD * ifd, BYTE slot) 149 149 { 150 150 int ret; … … 173 173 if(reader[ridx].typ == R_INTERNAL) 174 174 { 175 ifd->io = io;176 175 ifd->slot = slot; 177 176 ifd->type = IFD_TOWITOKO_MULTICAM; … … 181 180 182 181 /* 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; 196 184 197 185 /* Default ifd settings */ 198 186 199 ifd->io = io;200 187 ifd->slot = slot; 201 188 ifd->type = IFD_TOWITOKO_MULTICAM; 202 189 203 ret = IFD_Towitoko_SetBaudrate (ifd, IFD_TOWITOKO_BAUDRATE); 204 205 if (ret != IFD_TOWITOKO_OK) 190 if (!Phoenix_SetBaudrate(IFD_TOWITOKO_BAUDRATE)) 206 191 { 207 192 IFD_Towitoko_Clear (ifd); 208 return ret;193 return IFD_TOWITOKO_IO_ERROR; 209 194 } 210 195 211 196 if (!IO_Serial_SetParity (PARITY_EVEN)) 197 { 198 IFD_Towitoko_Clear (ifd); 212 199 return IFD_TOWITOKO_IO_ERROR; 213 214 if (ret != IFD_TOWITOKO_OK)215 {216 IFD_Towitoko_Clear (ifd);217 return ret;218 200 } 219 201 … … 226 208 else 227 209 { 228 IO_Serial_Flush( ifd->io);210 IO_Serial_Flush(); 229 211 } 230 212 … … 234 216 int IFD_Towitoko_Close (IFD * ifd) 235 217 { 236 int ret;237 238 218 #ifdef USE_GPIO 239 219 if(gpio_detect) … … 255 235 } 256 236 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) 237 int IFD_Towitoko_ActivateICC () 301 238 { 302 239 #ifdef DEBUG_IFD … … 335 272 } 336 273 337 int IFD_Towitoko_DeactivateICC ( IFD * ifd)274 int IFD_Towitoko_DeactivateICC () 338 275 { 339 276 #ifdef DEBUG_IFD … … 367 304 368 305 //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_IFD374 printf ("IFD: Resetting card:\n");375 #endif376 377 int ret;378 int parity;379 int i;380 int par[3] = {PARITY_EVEN, PARITY_ODD, PARITY_NONE};381 #ifdef HAVE_NANOSLEEP382 struct timespec req_ts;383 req_ts.tv_sec = 0;384 req_ts.tv_nsec = 50000000;385 #endif386 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_GPIO400 if (gpio_detect)401 {402 set_gpio(0);403 set_gpio1(0);404 }405 else406 #endif407 IO_Serial_RTS_Set();408 409 #ifdef HAVE_NANOSLEEP410 nanosleep (&req_ts, NULL);411 #else412 usleep (50000L);413 #endif414 #ifdef USE_GPIO415 if (gpio_detect)416 {417 set_gpio_input();418 set_gpio1(1);419 }420 else421 #endif422 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 else437 {438 ATR_Delete (*atr);439 (*atr) = NULL;440 #ifdef USE_GPIO441 if (gpio_detect) set_gpio1(0);442 #endif443 }444 }445 446 IO_Serial_Flush();447 448 /*449 //PLAYGROUND faking ATR for test purposes only450 //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 ATR456 (*atr) = ATR_New ();457 ATR_InitFromArray ((*atr), atr_test, sizeof(atr_test));458 //END OF PLAYGROUND459 */460 461 return ret;462 }463 306 464 307 BYTE IFD_Towitoko_GetType (IFD * ifd) … … 551 394 static void IFD_Towitoko_Clear (IFD * ifd) 552 395 { 553 ifd->io = NULL;554 396 ifd->slot = 0x00; 555 397 ifd->type = 0x00; -
branches/monitor-improvement/csctapi/ifd_towitoko.h
r1240 r1257 93 93 typedef struct 94 94 { 95 IO_Serial *io; /* Handle of serial device */96 95 BYTE slot; /* Chipdrive Twin Slot */ 97 96 BYTE type; /* Reader type code */ … … 111 110 112 111 /* Handling of the drive associated with this IFD */ 113 extern int IFD_Towitoko_Init (IFD * ifd, IO_Serial * io,BYTE slot);112 extern int IFD_Towitoko_Init (IFD * ifd, BYTE slot); 114 113 extern int IFD_Towitoko_Close (IFD * ifd); 115 114 116 115 /* Handling of this IFD */ 117 116 extern int IFD_Towitoko_SetBaudrate (IFD * ifd, unsigned long baudrate); 118 extern int IFD_Towitoko_GetBaudrate (IFD * ifd, unsigned long *baudrate);119 117 120 118 /* General handling of ICC inserted in this IFD */ 121 extern int IFD_Towitoko_ActivateICC ( IFD * ifd);122 extern int IFD_Towitoko_DeactivateICC ( IFD * ifd);119 extern int IFD_Towitoko_ActivateICC (); 120 extern int IFD_Towitoko_DeactivateICC (); 123 121 124 122 /* Asynchronous ICC handling functions */ 125 extern int IFD_Towitoko_ResetAsyncICC ( IFD * ifd,ATR ** atr);123 extern int IFD_Towitoko_ResetAsyncICC (ATR ** atr); 126 124 127 125 /* Atributes of the drive associated with this IFD */ -
branches/monitor-improvement/csctapi/io_serial.c
r1250 r1257 63 63 64 64 static 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);69 65 70 66 static int _in_echo_read = 0; … … 157 153 */ 158 154 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 155 bool IO_Serial_SetBitrate (unsigned long bitrate, struct termios * tio) 156 { 467 157 /* Set the bitrate */ 468 158 #ifdef OS_LINUX 469 159 if (reader[ridx].mhz == reader[ridx].cardmhz) 470 160 #endif 471 { //no overclo cking472 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); 475 165 } 476 166 #ifdef OS_LINUX … … 479 169 struct serial_struct nuts; 480 170 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; 482 172 nuts.custom_divisor = (nuts.baud_base + (custom_baud/2))/ custom_baud; 483 173 cs_debug("custom baudrate: cardmhz=%d mhz=%d custom_baud=%d baud_base=%d divisor=%d -> effective baudrate %d", … … 486 176 nuts.flags |= ASYNC_SPD_CUST; 487 177 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)); 490 180 } 491 181 #endif 492 182 return TRUE; 183 } 184 185 bool 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 493 197 /* Set the character size */ 494 switch (io->bits)198 switch (bits) 495 199 { 496 200 case 5: … … 512 216 513 217 /* Set the parity */ 514 switch ( io->parity)218 switch (parity) 515 219 { 516 220 case PARITY_ODD: … … 530 234 531 235 /* Set the number of stop bits */ 532 switch ( io->stopbits)236 switch (stopbits) 533 237 { 534 238 case 1: … … 554 258 newtio.c_cc[VTIME] = 0; 555 259 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; 591 264 592 265 IO_Serial_Ioctl_Lock(1); … … 594 267 IO_Serial_DTR_RTS(1, dtr == IO_SERIAL_HIGH); 595 268 IO_Serial_Ioctl_Lock(0); 269 270 return TRUE; 271 } 272 273 bool 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; 596 287 597 288 #ifdef DEBUG_IO … … 671 362 } 672 363 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 }679 364 680 365 bool IO_Serial_Read (unsigned timeout, unsigned size, BYTE * data) … … 837 522 } 838 523 839 bool IO_Serial_Close ( IO_Serial * io)524 bool IO_Serial_Close () 840 525 { 841 526 … … 850 535 return FALSE; 851 536 852 IO_Serial_Clear (io);537 wr = 0; 853 538 854 539 return TRUE; … … 1031 716 } 1032 717 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; 718 bool 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 1066 729 return TRUE; 1067 730 } -
branches/monitor-improvement/csctapi/io_serial.h
r1240 r1257 48 48 #define IO_SERIAL_PNPID_SIZE 256 49 49 50 /*51 * Exported datatypes definition52 */53 54 /* IO_Serial exported datatype */55 typedef struct56 {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 71 50 int wr; //FIXME should be in ifd_phoenix.c or .h 72 51 … … 76 55 77 56 /* IO_Serial creation and deletion */ 78 //extern void IO_Serial_Reopen (IO_Serial * io);79 57 extern void IO_Serial_Flush (); 80 extern IO_Serial *IO_Serial_New (int mhz, int cardmhz);81 extern void IO_Serial_Delete (IO_Serial * io);82 58 83 59 /* Initialization and closing */ 84 extern bool IO_Serial_Init (IO_Serial * io, int reader_type);85 extern bool IO_Serial_Close ( IO_Serial * io);60 extern bool IO_Serial_InitPnP (void); 61 extern bool IO_Serial_Close (); 86 62 87 63 /* Transmission properties */ 88 extern bool IO_Serial_SetPropertiesOld (IO_Serial * io);89 extern bool IO_Serial_GetPropertiesOld (IO_Serial * io);90 64 extern bool IO_Serial_DTR_RTS(int, int); 91 65 #if defined(TUXBOX) && defined(PPC) … … 99 73 extern bool IO_Serial_Write (unsigned delay, unsigned size, BYTE * data); 100 74 101 /* Serial port atributes */102 extern void IO_Serial_GetPnPId (IO_Serial * io, BYTE * pnp_id, unsigned *length);103 104 75 #endif /* IO_SERIAL */ -
branches/monitor-improvement/globals.h
r1256 r1257 411 411 int card_status; //highlevel status 412 412 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 structure413 unsigned long baudrate; //we are storing the (for overclocking uncorrected) baudrate to prevent unnecessary conversions from/to termios structure 414 414 struct s_module ph; 415 415 uchar ncd_key[16]; -
branches/monitor-improvement/reader-common.c
r1240 r1257 309 309 cs_ptyp=D_DEVICE; 310 310 #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) 312 313 cs_log("[tuxbox] Cannot open device: %s", device); 313 314 #else 314 if ((rc=CT_init(1 , reader[ridx].typ,reader[ridx].mhz,reader[ridx].cardmhz))!=OK)315 if ((rc=CT_init(1))!=OK) 315 316 cs_log("Cannot open device: %s", device); 316 317 #endif
Note:
See TracChangeset
for help on using the changeset viewer.