/[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 612 by rousseau, Thu Jan 15 13:45:37 2004 UTC revision 649 by rousseau, Tue Jan 27 13:32:55 2004 UTC
# Line 102  typedef struct Line 102  typedef struct
102          int fd;          int fd;
103    
104          /*          /*
105           * channel used (1..4)           * device used ("/dev/ttyS?" under Linux)
106           */           */
107          int channel;          char *device;
108    
109          /*          /*
110           * serial communication buffer           * serial communication buffer
# Line 132  typedef struct Line 132  typedef struct
132  #include "ccid_serial.h"  #include "ccid_serial.h"
133    
134  static _serialDevice serialDevice[PCSCLITE_MAX_READERS] = {  static _serialDevice serialDevice[PCSCLITE_MAX_READERS] = {
135          [ 0 ... (PCSCLITE_MAX_READERS-1) ] = { -1, -1 }          [ 0 ... (PCSCLITE_MAX_READERS-1) ] = { -1, NULL }
136  };  };
137    
138  /*****************************************************************************  /*****************************************************************************
# Line 427  int ReadChunk(int lun, unsigned char *bu Line 427  int ReadChunk(int lun, unsigned char *bu
427  status_t OpenSerial(int lun, int channel)  status_t OpenSerial(int lun, int channel)
428  {  {
429          char dev_name[FILENAME_MAX];          char dev_name[FILENAME_MAX];
         struct termios current_termios;  
         int i;  
         int reader = LunToReaderIndex(lun);  
430    
431          DEBUG_COMM3("Lun: %X, Channel: %d", lun, channel);          DEBUG_COMM3("Lun: %X, Channel: %d", lun, channel);
432    
# Line 456  status_t OpenSerial(int lun, int channel Line 453  status_t OpenSerial(int lun, int channel
453    
454          sprintf(dev_name, "/dev/pcsc/%d", (int) channel);          sprintf(dev_name, "/dev/pcsc/%d", (int) channel);
455    
456            return OpenSerialByName(lun, dev_name);
457    } /* OpenSerial */
458    
459    /*****************************************************************************
460     *
461     *                              OpenSerialByName: open the port
462     *
463     *****************************************************************************/
464    status_t OpenSerialByName(int lun, char *dev_name)
465    {
466            struct termios current_termios;
467            int i;
468            int reader = LunToReaderIndex(lun);
469    
470            DEBUG_COMM3("Lun: %X, Device: %d", lun, dev_name);
471    
472          /* check if the same channel is not already used */          /* check if the same channel is not already used */
473          for (i=0; i<PCSCLITE_MAX_READERS; i++)          for (i=0; i<PCSCLITE_MAX_READERS; i++)
474          {          {
475                  if (serialDevice[i].channel == channel)                  if (serialDevice[i].device &&
476                            strcmp(serialDevice[i].device, dev_name) == 0)
477                  {                  {
478                          DEBUG_CRITICAL2("Channel %s already in use", dev_name);                          DEBUG_CRITICAL2("Device %s already in use", dev_name);
479                          return STATUS_UNSUCCESSFUL;                          return STATUS_UNSUCCESSFUL;
480                  }                  }
481          }          }
# Line 475  status_t OpenSerial(int lun, int channel Line 489  status_t OpenSerial(int lun, int channel
489          }          }
490    
491          /* set channel used */          /* set channel used */
492          serialDevice[reader].channel = channel;          serialDevice[reader].device = strdup(dev_name);
493    
494          /* empty in and out serial buffers */          /* empty in and out serial buffers */
495          if (tcflush(serialDevice[reader].fd, TCIOFLUSH))          if (tcflush(serialDevice[reader].fd, TCIOFLUSH))
# Line 527  status_t OpenSerial(int lun, int channel Line 541  status_t OpenSerial(int lun, int channel
541          serialDevice[reader].buffer_offset_last = 0;          serialDevice[reader].buffer_offset_last = 0;
542    
543          return STATUS_SUCCESS;          return STATUS_SUCCESS;
544  } /* OpenSerial */  } /* OpenSerialByName */
545    
546    
547  /*****************************************************************************  /*****************************************************************************
# Line 540  status_t CloseSerial(int lun) Line 554  status_t CloseSerial(int lun)
554          int reader = LunToReaderIndex(lun);          int reader = LunToReaderIndex(lun);
555    
556          close(serialDevice[reader].fd);          close(serialDevice[reader].fd);
   
557          serialDevice[reader].fd = -1;          serialDevice[reader].fd = -1;
558          serialDevice[reader].channel = -1;  
559            free(serialDevice[reader].device);
560            serialDevice[reader].device = NULL;
561    
562          return STATUS_SUCCESS;          return STATUS_SUCCESS;
563  } /* CloseSerial */  } /* CloseSerial */

Legend:
Removed from v.612  
changed lines
  Added in v.649

  ViewVC Help
Powered by ViewVC 1.1.5