/[pcsclite]/trunk/Drivers/ccid/src/ccid_serial.c
ViewVC logotype

Diff of /trunk/Drivers/ccid/src/ccid_serial.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 608 by rousseau, Thu Jan 15 08:30:31 2004 UTC revision 877 by rousseau, Mon May 17 14:35:51 2004 UTC
# Line 33  Line 33 
33  #include <sys/time.h>  #include <sys/time.h>
34  #include <sys/types.h>  #include <sys/types.h>
35    
36  #include "pcscdefines.h"  #include "defs.h"
37    #include "ccid_ifdhandler.h"
38  #include "config.h"  #include "config.h"
39  #include "debug.h"  #include "debug.h"
40  #include "ccid.h"  #include "ccid.h"
# Line 102  typedef struct Line 103  typedef struct
103          int fd;          int fd;
104    
105          /*          /*
106           * channel used (1..4)           * device used ("/dev/ttyS?" under Linux)
107           */           */
108          int channel;          char *device;
109    
110          /*          /*
111           * serial communication buffer           * serial communication buffer
# Line 132  typedef struct Line 133  typedef struct
133  #include "ccid_serial.h"  #include "ccid_serial.h"
134    
135  static _serialDevice serialDevice[PCSCLITE_MAX_READERS] = {  static _serialDevice serialDevice[PCSCLITE_MAX_READERS] = {
136          [ 0 ... (PCSCLITE_MAX_READERS-1) ] = { -1, -1 }          [ 0 ... (PCSCLITE_MAX_READERS-1) ] = { -1, NULL }
137  };  };
138    
139  /*****************************************************************************  /*****************************************************************************
# Line 229  slot_change: Line 230  slot_change:
230                  return rv;                  return rv;
231    
232          if (c == CARD_ABSENT)          if (c == CARD_ABSENT)
233            {
234                  DEBUG_COMM("Card removed");                  DEBUG_COMM("Card removed");
235            }
236          else          else
237                  if (c == CARD_PRESENT)                  if (c == CARD_PRESENT)
238                    {
239                          DEBUG_COMM("Card inserted");                          DEBUG_COMM("Card inserted");
240                    }
241                  else                  else
242                    {
243                          DEBUG_COMM2("Unknown card movement: %d", buffer[3]);                          DEBUG_COMM2("Unknown card movement: %d", buffer[3]);
244                    }
245          goto start;          goto start;
246    
247  sync:  sync:
# Line 427  int ReadChunk(int lun, unsigned char *bu Line 434  int ReadChunk(int lun, unsigned char *bu
434  status_t OpenSerial(int lun, int channel)  status_t OpenSerial(int lun, int channel)
435  {  {
436          char dev_name[FILENAME_MAX];          char dev_name[FILENAME_MAX];
         struct termios current_termios;  
         int i;  
         int reader = LunToReaderIndex(lun);  
437    
438          DEBUG_COMM3("Lun: %X, Channel: %d", lun, channel);          DEBUG_COMM3("Lun: %X, Channel: %d", lun, channel);
439    
# Line 456  status_t OpenSerial(int lun, int channel Line 460  status_t OpenSerial(int lun, int channel
460    
461          sprintf(dev_name, "/dev/pcsc/%d", (int) channel);          sprintf(dev_name, "/dev/pcsc/%d", (int) channel);
462    
463            return OpenSerialByName(lun, dev_name);
464    } /* OpenSerial */
465    
466    /*****************************************************************************
467     *
468     *                              OpenSerialByName: open the port
469     *
470     *****************************************************************************/
471    status_t OpenSerialByName(int lun, char *dev_name)
472    {
473            struct termios current_termios;
474            int i;
475            int reader = LunToReaderIndex(lun);
476    
477            DEBUG_COMM3("Lun: %X, Device: %d", lun, dev_name);
478    
479          /* check if the same channel is not already used */          /* check if the same channel is not already used */
480          for (i=0; i<PCSCLITE_MAX_READERS; i++)          for (i=0; i<PCSCLITE_MAX_READERS; i++)
481          {          {
482                  if (serialDevice[i].channel == channel)                  if (serialDevice[i].device &&
483                            strcmp(serialDevice[i].device, dev_name) == 0)
484                  {                  {
485                          DEBUG_CRITICAL2("Channel %s already in use", dev_name);                          DEBUG_CRITICAL2("Device %s already in use", dev_name);
486                          return STATUS_UNSUCCESSFUL;                          return STATUS_UNSUCCESSFUL;
487                  }                  }
488          }          }
# Line 475  status_t OpenSerial(int lun, int channel Line 496  status_t OpenSerial(int lun, int channel
496          }          }
497    
498          /* set channel used */          /* set channel used */
499          serialDevice[reader].channel = channel;          serialDevice[reader].device = strdup(dev_name);
500    
501          /* empty in and out serial buffers */          /* empty in and out serial buffers */
502          if (tcflush(serialDevice[reader].fd, TCIOFLUSH))          if (tcflush(serialDevice[reader].fd, TCIOFLUSH))
# Line 521  status_t OpenSerial(int lun, int channel Line 542  status_t OpenSerial(int lun, int channel
542          serialDevice[reader].ccid.bSeq = 0;          serialDevice[reader].ccid.bSeq = 0;
543          serialDevice[reader].ccid.readerID = GEMPCTWIN;          serialDevice[reader].ccid.readerID = GEMPCTWIN;
544          serialDevice[reader].ccid.dwMaxCCIDMessageLength = 271;          serialDevice[reader].ccid.dwMaxCCIDMessageLength = 271;
545            serialDevice[reader].ccid.dwMaxIFSD = 254;
546          serialDevice[reader].ccid.dwFeatures = 0x00010230;          serialDevice[reader].ccid.dwFeatures = 0x00010230;
547            serialDevice[reader].ccid.dwDefaultClock = 4000;
548            serialDevice[reader].ccid.dwMaxDataRate = 344086;
549    
550          serialDevice[reader].buffer_offset = 0;          serialDevice[reader].buffer_offset = 0;
551          serialDevice[reader].buffer_offset_last = 0;          serialDevice[reader].buffer_offset_last = 0;
552    
         ccid_open_hack(lun);  
   
553          return STATUS_SUCCESS;          return STATUS_SUCCESS;
554  } /* OpenSerial */  } /* OpenSerialByName */
555    
556    
557  /*****************************************************************************  /*****************************************************************************
# Line 542  status_t CloseSerial(int lun) Line 564  status_t CloseSerial(int lun)
564          int reader = LunToReaderIndex(lun);          int reader = LunToReaderIndex(lun);
565    
566          close(serialDevice[reader].fd);          close(serialDevice[reader].fd);
   
567          serialDevice[reader].fd = -1;          serialDevice[reader].fd = -1;
568          serialDevice[reader].channel = -1;  
569            free(serialDevice[reader].device);
570            serialDevice[reader].device = NULL;
571    
572          return STATUS_SUCCESS;          return STATUS_SUCCESS;
573  } /* CloseSerial */  } /* CloseSerial */

Legend:
Removed from v.608  
changed lines
  Added in v.877

  ViewVC Help
Powered by ViewVC 1.1.5