/[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 1053 by rousseau, Fri Jul 9 13:21:44 2004 UTC revision 1771 by rousseau, Tue Nov 29 12:21:00 2005 UTC
# Line 1  Line 1 
1  /*  /*
2   * ccid_serial.c: communicate with a GemPC Twin smart card reader   * ccid_serial.c: communicate with a GemPC Twin smart card reader
3   * Copyright (C) 2001-2003 Ludovic Rousseau <ludovic.rousseau@free.fr>   * Copyright (C) 2001-2004 Ludovic Rousseau <ludovic.rousseau@free.fr>
4   *   *
5   * Thanks to Niki W. Waibel <niki.waibel@gmx.net> for a prototype version   * Thanks to Niki W. Waibel <niki.waibel@gmx.net> for a prototype version
6   *   *
7   * This program is free software; you can redistribute it and/or modify it      This library is free software; you can redistribute it and/or
8   * under the terms of the GNU General Public License as published by the      modify it under the terms of the GNU Lesser General Public
9   * Free Software Foundation; either version 2 of the License, or (at your      License as published by the Free Software Foundation; either
10   * option) any later version.      version 2.1 of the License, or (at your option) any later version.
11   *  
12   * This program is distributed in the hope that it will be useful, but      This library is distributed in the hope that it will be useful,
13   * WITHOUT ANY WARRANTY; without even the implied warranty of      but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15   * General Public License for more details.      Lesser General Public License for more details.
16   *  
17   * You should have received a copy of the GNU General Public License along      You should have received a copy of the GNU Lesser General Public
18   * with this program; if not, write to the Free Software Foundation, Inc.,      License along with this library; if not, write to the Free Software
19   * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
20   */   */
21    
22  /*  /*
# Line 32  Line 32 
32  #include <errno.h>  #include <errno.h>
33  #include <sys/time.h>  #include <sys/time.h>
34  #include <sys/types.h>  #include <sys/types.h>
35  #include <PCSC/ifdhandler.h>  #include <sys/ioctl.h>
36    #include <ifdhandler.h>
37    
38  #include "defs.h"  #include "defs.h"
39  #include "ccid_ifdhandler.h"  #include "ccid_ifdhandler.h"
# Line 42  Line 43 
43  #include "utils.h"  #include "utils.h"
44  #include "commands.h"  #include "commands.h"
45    
 /* communication timeout in seconds */  
 #define SERIAL_TIMEOUT 2  
   
46  #define SYNC 0x03  #define SYNC 0x03
47  #define CTRL_ACK 0x06  #define CTRL_ACK 0x06
48  #define CTRL_NAK 0x15  #define CTRL_NAK 0x15
# Line 107  typedef struct Line 105  typedef struct
105          /*          /*
106           * device used ("/dev/ttyS?" under Linux)           * device used ("/dev/ttyS?" under Linux)
107           */           */
108          char *device;          /*@null@*/ char *device;
109    
110          /*          /*
111           * serial communication buffer           * serial communication buffer
# Line 134  typedef struct Line 132  typedef struct
132  /* The _serialDevice structure must be defined before including ccid_serial.h */  /* The _serialDevice structure must be defined before including ccid_serial.h */
133  #include "ccid_serial.h"  #include "ccid_serial.h"
134    
135    unsigned int SerialDataRates[] = {
136                    10753,
137                    14337,
138                    15625,
139                    17204,
140                    20833,
141                    21505,
142                    23438,
143                    25806,
144                    28674,
145                    31250,
146                    32258,
147                    34409,
148                    39063,
149                    41667,
150                    43011,
151                    46875,
152                    52083,
153                    53763,
154                    57348,
155                    62500,
156                    64516,
157                    68817,
158                    71685,
159                    78125,
160                    83333,
161                    86022,
162                    93750,
163                    104167,
164                    107527,
165                    114695,
166                    125000,
167                    129032,
168                    143369,
169                    156250,
170                    166667,
171                    172043,
172                    215054,
173                    229391,
174                    250000,
175                    344086,
176                    0
177            };
178    
179  /* no need to initialize to 0 since it is static */  /* no need to initialize to 0 since it is static */
180  static _serialDevice serialDevice[PCSCLITE_MAX_READERS];  static _serialDevice serialDevice[CCID_DRIVER_MAX_READERS];
181    
182  /* unexported functions */  /* unexported functions */
183  static int ReadChunk(unsigned int lun, unsigned char *buffer, int buffer_length,  static int ReadChunk(unsigned int reader_index, unsigned char *buffer,
184          int min_length);          int buffer_length, int min_length);
185    
186  static int get_bytes(unsigned int lun, unsigned char *buffer, int length);  static int get_bytes(unsigned int reader_index, unsigned char *buffer,
187            int length);
188    
189    
190  /*****************************************************************************  /*****************************************************************************
# Line 149  static int get_bytes(unsigned int lun, u Line 192  static int get_bytes(unsigned int lun, u
192   *                              WriteSerial: Send bytes to the card reader   *                              WriteSerial: Send bytes to the card reader
193   *   *
194   *****************************************************************************/   *****************************************************************************/
195  status_t WriteSerial(unsigned int lun, unsigned int length, unsigned char *buffer)  status_t WriteSerial(unsigned int reader_index, unsigned int length,
196            unsigned char *buffer)
197  {  {
198          int i;          int i;
199          unsigned char lrc;          unsigned char lrc;
200          unsigned char low_level_buffer[GEMPCTWIN_MAXBUF];          unsigned char low_level_buffer[GEMPCTWIN_MAXBUF];
201    
 #ifdef DEBUG_LEVEL_COMM  
202          char debug_header[] = "-> 123456 ";          char debug_header[] = "-> 123456 ";
203    
204          sprintf(debug_header, "-> %06X ", lun);          sprintf(debug_header, "-> %06X ", reader_index);
 #endif  
205    
206          if (length > GEMPCTWIN_MAXBUF-3)          if (length > GEMPCTWIN_MAXBUF-3)
207          {          {
# Line 181  status_t WriteSerial(unsigned int lun, u Line 223  status_t WriteSerial(unsigned int lun, u
223                  lrc ^= low_level_buffer[i];                  lrc ^= low_level_buffer[i];
224          low_level_buffer[length+2] = lrc;          low_level_buffer[length+2] = lrc;
225    
 #ifdef DEBUG_LEVEL_COMM  
226          DEBUG_XXD(debug_header, low_level_buffer, length+3);          DEBUG_XXD(debug_header, low_level_buffer, length+3);
 #endif  
227    
228          if (write(serialDevice[LunToReaderIndex(lun)].fd, low_level_buffer,          if (write(serialDevice[reader_index].fd, low_level_buffer,
229                  length+3) != length+3)                  length+3) != length+3)
230          {          {
231                  DEBUG_CRITICAL2("write error: %s", strerror(errno));                  DEBUG_CRITICAL2("write error: %s", strerror(errno));
# Line 201  status_t WriteSerial(unsigned int lun, u Line 241  status_t WriteSerial(unsigned int lun, u
241   *                              ReadSerial: Receive bytes from the card reader   *                              ReadSerial: Receive bytes from the card reader
242   *   *
243   *****************************************************************************/   *****************************************************************************/
244  status_t ReadSerial(unsigned int lun, /*@unused@*/ unsigned int *length,  status_t ReadSerial(unsigned int reader_index,
245          unsigned char *buffer)          /*@unused@*/ unsigned int *length, unsigned char *buffer)
246  {  {
247          unsigned char c;          unsigned char c;
248          int rv;          int rv;
# Line 215  status_t ReadSerial(unsigned int lun, /* Line 255  status_t ReadSerial(unsigned int lun, /*
255    
256  start:  start:
257          DEBUG_COMM("start");          DEBUG_COMM("start");
258          if ((rv = get_bytes(lun, &c, 1)) != STATUS_SUCCESS)          if ((rv = get_bytes(reader_index, &c, 1)) != STATUS_SUCCESS)
259                  return rv;                  return rv;
260    
261          if (c == RDR_to_PC_NotifySlotChange)          if (c == RDR_to_PC_NotifySlotChange)
# Line 235  start: Line 275  start:
275    
276  slot_change:  slot_change:
277          DEBUG_COMM("slot change");          DEBUG_COMM("slot change");
278          if ((rv = get_bytes(lun, &c, 1)) != STATUS_SUCCESS)          if ((rv = get_bytes(reader_index, &c, 1)) != STATUS_SUCCESS)
279                  return rv;                  return rv;
280    
281          if (c == CARD_ABSENT)          if (c == CARD_ABSENT)
# Line 255  slot_change: Line 295  slot_change:
295    
296  sync:  sync:
297          DEBUG_COMM("sync");          DEBUG_COMM("sync");
298          if ((rv = get_bytes(lun, &c, 1)) != STATUS_SUCCESS)          if ((rv = get_bytes(reader_index, &c, 1)) != STATUS_SUCCESS)
299                  return rv;                  return rv;
300    
301          if (c == CTRL_ACK)          if (c == CTRL_ACK)
# Line 269  sync: Line 309  sync:
309    
310  nak:  nak:
311          DEBUG_COMM("nak");          DEBUG_COMM("nak");
312          if ((rv = get_bytes(lun, &c, 1)) != STATUS_SUCCESS)          if ((rv = get_bytes(reader_index, &c, 1)) != STATUS_SUCCESS)
313                  return rv;                  return rv;
314    
315          if (c != (SYNC ^ CTRL_NAK))          if (c != (SYNC ^ CTRL_NAK))
# Line 278  nak: Line 318  nak:
318                  return STATUS_COMM_ERROR;                  return STATUS_COMM_ERROR;
319          }          }
320          else          else
321                  goto start;          {
322                    DEBUG_COMM("NAK requested");
323                    return STATUS_COMM_NAK;
324            }
325    
326  ack:  ack:
327          DEBUG_COMM("ack");          DEBUG_COMM("ack");
328          /* normal CCID frame */          /* normal CCID frame */
329          if ((rv = get_bytes(lun, buffer, 5)) != STATUS_SUCCESS)          if ((rv = get_bytes(reader_index, buffer, 5)) != STATUS_SUCCESS)
330                  return rv;                  return rv;
331    
332          /* total frame size */          /* total frame size */
333          to_read = 10+dw2i(buffer, 1);          to_read = 10+dw2i(buffer, 1);
334    
335          DEBUG_COMM2("frame size: %d", to_read);          DEBUG_COMM2("frame size: %d", to_read);
336          if ((rv = get_bytes(lun, buffer+5, to_read-5)) != STATUS_SUCCESS)          if ((rv = get_bytes(reader_index, buffer+5, to_read-5)) != STATUS_SUCCESS)
337                  return rv;                  return rv;
338    
339  #ifdef DEBUG_LEVEL_COMM          DEBUG_XXD("frame: ", buffer, to_read);
                 DEBUG_XXD("frame: ", buffer, to_read);  
 #endif  
340    
341          /* lrc */          /* lrc */
342          DEBUG_COMM("lrc");          DEBUG_COMM("lrc");
343          if ((rv = get_bytes(lun, &c, 1)) != STATUS_SUCCESS)          if ((rv = get_bytes(reader_index, &c, 1)) != STATUS_SUCCESS)
344                  return rv;                  return rv;
345    
346          DEBUG_COMM2("lrc: 0x%02X", c);          DEBUG_COMM2("lrc: 0x%02X", c);
# Line 324  ack: Line 365  ack:
365   *                              get_bytes: get n bytes   *                              get_bytes: get n bytes
366   *   *
367   *****************************************************************************/   *****************************************************************************/
368  int get_bytes(unsigned int lun, unsigned char *buffer, int length)  int get_bytes(unsigned int reader_index, unsigned char *buffer, int length)
369  {  {
370          int offset = serialDevice[LunToReaderIndex(lun)].buffer_offset;          int offset = serialDevice[reader_index].buffer_offset;
371          int offset_last = serialDevice[LunToReaderIndex(lun)].buffer_offset_last;          int offset_last = serialDevice[reader_index].buffer_offset_last;
372    
373          DEBUG_COMM3("available: %d, needed: %d", offset_last-offset,          DEBUG_COMM3("available: %d, needed: %d", offset_last-offset,
374                  length);                  length);
# Line 335  int get_bytes(unsigned int lun, unsigned Line 376  int get_bytes(unsigned int lun, unsigned
376          if (offset + length <= offset_last)          if (offset + length <= offset_last)
377          {          {
378                  DEBUG_COMM("data available");                  DEBUG_COMM("data available");
379                  memcpy(buffer, serialDevice[LunToReaderIndex(lun)].buffer + offset, length);                  memcpy(buffer, serialDevice[reader_index].buffer + offset, length);
380                  serialDevice[LunToReaderIndex(lun)].buffer_offset += length;                  serialDevice[reader_index].buffer_offset += length;
381          }          }
382          else          else
383          {          {
# Line 348  int get_bytes(unsigned int lun, unsigned Line 389  int get_bytes(unsigned int lun, unsigned
389                  if (present > 0)                  if (present > 0)
390                  {                  {
391                          DEBUG_COMM2("some data available: %d", present);                          DEBUG_COMM2("some data available: %d", present);
392                          memcpy(buffer, serialDevice[LunToReaderIndex(lun)].buffer + offset,                          memcpy(buffer, serialDevice[reader_index].buffer + offset,
393                                  present);                                  present);
394                  }                  }
395    
396                  /* get fresh data */                  /* get fresh data */
397                  DEBUG_COMM2("get more data: %d", length - present);                  DEBUG_COMM2("get more data: %d", length - present);
398                  rv = ReadChunk(lun, serialDevice[LunToReaderIndex(lun)].buffer, sizeof(serialDevice[LunToReaderIndex(lun)].buffer), length - present);                  rv = ReadChunk(reader_index, serialDevice[reader_index].buffer,
399                            sizeof(serialDevice[reader_index].buffer), length - present);
400                  if (rv < 0)                  if (rv < 0)
401                          return STATUS_COMM_ERROR;                          return STATUS_COMM_ERROR;
402    
403                  /* fill the buffer */                  /* fill the buffer */
404                  memcpy(buffer + present, serialDevice[LunToReaderIndex(lun)].buffer,                  memcpy(buffer + present, serialDevice[reader_index].buffer,
405                          length - present);                          length - present);
406                  serialDevice[LunToReaderIndex(lun)].buffer_offset = length - present;                  serialDevice[reader_index].buffer_offset = length - present;
407                  serialDevice[LunToReaderIndex(lun)].buffer_offset_last = rv;                  serialDevice[reader_index].buffer_offset_last = rv;
408                  DEBUG_COMM3("offset: %d, last_offset: %d",                  DEBUG_COMM3("offset: %d, last_offset: %d",
409                          serialDevice[LunToReaderIndex(lun)].buffer_offset,                          serialDevice[reader_index].buffer_offset,
410                          serialDevice[LunToReaderIndex(lun)].buffer_offset_last);                          serialDevice[reader_index].buffer_offset_last);
411          }          }
412    
413          return STATUS_SUCCESS;          return STATUS_SUCCESS;
# Line 377  int get_bytes(unsigned int lun, unsigned Line 419  int get_bytes(unsigned int lun, unsigned
419   *                              ReadChunk: read a minimum number of bytes   *                              ReadChunk: read a minimum number of bytes
420   *   *
421   *****************************************************************************/   *****************************************************************************/
422  static int ReadChunk(unsigned int lun, unsigned char *buffer,  static int ReadChunk(unsigned int reader_index, unsigned char *buffer,
423          int buffer_length, int min_length)          int buffer_length, int min_length)
424  {  {
425          int fd = serialDevice[LunToReaderIndex(lun)].fd;          int fd = serialDevice[reader_index].fd;
426  # ifndef S_SPLINT_S  # ifndef S_SPLINT_S
427          fd_set fdset;          fd_set fdset;
428  # endif  # endif
429          struct timeval t;          struct timeval t;
430          int i, rv = 0;          int i, rv = 0;
431          int already_read;          int already_read;
 #ifdef DEBUG_LEVEL_COMM  
432          char debug_header[] = "<- 123456 ";          char debug_header[] = "<- 123456 ";
433    
434          sprintf(debug_header, "<- %06X ", lun);          sprintf(debug_header, "<- %06X ", reader_index);
 #endif  
435    
436          already_read = 0;          already_read = 0;
437          while (already_read < min_length)          while (already_read < min_length)
# Line 399  static int ReadChunk(unsigned int lun, u Line 439  static int ReadChunk(unsigned int lun, u
439                  /* use select() to, eventually, timeout */                  /* use select() to, eventually, timeout */
440                  FD_ZERO(&fdset);                  FD_ZERO(&fdset);
441                  FD_SET(fd, &fdset);                  FD_SET(fd, &fdset);
442                  t.tv_sec = SERIAL_TIMEOUT;                  t.tv_sec = serialDevice[reader_index].ccid.readTimeout;
443                  t.tv_usec = 0;                  t.tv_usec = 0;
444    
445                  i = select(fd+1, &fdset, NULL, NULL, &t);                  i = select(fd+1, &fdset, NULL, NULL, &t);
# Line 411  static int ReadChunk(unsigned int lun, u Line 451  static int ReadChunk(unsigned int lun, u
451                  else                  else
452                          if (i == 0)                          if (i == 0)
453                          {                          {
454                                  DEBUG_COMM2("Timeout! (%d sec)", SERIAL_TIMEOUT);                                  DEBUG_COMM2("Timeout! (%d sec)", serialDevice[reader_index].ccid.readTimeout);
455                                  return -1;                                  return -1;
456                          }                          }
457    
# Line 422  static int ReadChunk(unsigned int lun, u Line 462  static int ReadChunk(unsigned int lun, u
462                          return -1;                          return -1;
463                  }                  }
464    
 #ifdef DEBUG_LEVEL_COMM  
465                  DEBUG_XXD(debug_header, buffer + already_read, rv);                  DEBUG_XXD(debug_header, buffer + already_read, rv);
 #endif  
466    
467                  already_read += rv;                  already_read += rv;
468                  DEBUG_COMM3("read: %d, to read: %d", already_read,                  DEBUG_COMM3("read: %d, to read: %d", already_read,
# Line 440  static int ReadChunk(unsigned int lun, u Line 478  static int ReadChunk(unsigned int lun, u
478   *                              OpenSerial: open the port   *                              OpenSerial: open the port
479   *   *
480   *****************************************************************************/   *****************************************************************************/
481  status_t OpenSerial(unsigned int lun, int channel)  status_t OpenSerial(unsigned int reader_index, int channel)
482  {  {
483          char dev_name[FILENAME_MAX];          char dev_name[FILENAME_MAX];
484    
485          DEBUG_COMM3("Lun: %X, Channel: %d", lun, channel);          DEBUG_COMM3("Reader index: %X, Channel: %d", reader_index, channel);
486    
487          /*          /*
488           * Conversion of old-style ifd-hanler 1.0 CHANNELID           * Conversion of old-style ifd-hanler 1.0 CHANNELID
# Line 469  status_t OpenSerial(unsigned int lun, in Line 507  status_t OpenSerial(unsigned int lun, in
507    
508          sprintf(dev_name, "/dev/pcsc/%d", (int) channel);          sprintf(dev_name, "/dev/pcsc/%d", (int) channel);
509    
510          return OpenSerialByName(lun, dev_name);          return OpenSerialByName(reader_index, dev_name);
511  } /* OpenSerial */  } /* OpenSerial */
512    
513  /*****************************************************************************  /*****************************************************************************
# Line 477  status_t OpenSerial(unsigned int lun, in Line 515  status_t OpenSerial(unsigned int lun, in
515   *                              OpenSerialByName: open the port   *                              OpenSerialByName: open the port
516   *   *
517   *****************************************************************************/   *****************************************************************************/
518  status_t OpenSerialByName(unsigned int lun, char *dev_name)  status_t OpenSerialByName(unsigned int reader_index, char *dev_name)
519  {  {
520          struct termios current_termios;          struct termios current_termios;
521          int i;          int i;
522          unsigned int reader = LunToReaderIndex(lun);          unsigned int reader = reader_index;
523    
524          DEBUG_COMM3("Lun: %X, Device: %d", lun, dev_name);          DEBUG_COMM3("Reader index: %X, Device: %s", reader_index, dev_name);
525    
526          /* check if the same channel is not already used */          /* check if the same channel is not already used */
527          for (i=0; i<PCSCLITE_MAX_READERS; i++)          for (i=0; i<CCID_DRIVER_MAX_READERS; i++)
528          {          {
529                  if (serialDevice[i].device &&                  if (serialDevice[i].device &&
530                          strcmp(serialDevice[i].device, dev_name) == 0)                          strcmp(serialDevice[i].device, dev_name) == 0)
# Line 504  status_t OpenSerialByName(unsigned int l Line 542  status_t OpenSerialByName(unsigned int l
542                  return STATUS_UNSUCCESSFUL;                  return STATUS_UNSUCCESSFUL;
543          }          }
544    
545            /* Set RTS signal to low to prevent the smart card reader
546             * from sending its plug and play string. */
547            {
548                    int flags;
549    
550                    if (ioctl(serialDevice[reader].fd, TIOCMGET, &flags) < 0)
551                    {
552                            DEBUG_CRITICAL2("Get RS232 signals state failed: %s",
553                                    strerror(errno));
554                    }
555                    else
556                    {
557                            flags &= ~TIOCM_RTS;
558                            if (ioctl(serialDevice[reader].fd, TIOCMSET, &flags) < 0)
559                            {
560                                    DEBUG_CRITICAL2("Set RTS to low failed: %s", strerror(errno));
561                            }
562                            else
563                            {
564                                    DEBUG_COMM("Plug-n-Play inhibition successful");
565                            }
566                    }
567            }
568    
569          /* set channel used */          /* set channel used */
570          serialDevice[reader].device = strdup(dev_name);          serialDevice[reader].device = strdup(dev_name);
571    
# Line 548  status_t OpenSerialByName(unsigned int l Line 610  status_t OpenSerialByName(unsigned int l
610                  return STATUS_UNSUCCESSFUL;                  return STATUS_UNSUCCESSFUL;
611          }          }
612    
613          serialDevice[reader].ccid.bSeq = 0;          serialDevice[reader].ccid.real_bSeq = 0;
614            serialDevice[reader].ccid.pbSeq = &serialDevice[reader].ccid.real_bSeq;
615          serialDevice[reader].ccid.readerID = GEMPCTWIN;          serialDevice[reader].ccid.readerID = GEMPCTWIN;
616          serialDevice[reader].ccid.dwMaxCCIDMessageLength = 271;          serialDevice[reader].ccid.dwMaxCCIDMessageLength = 271;
617          serialDevice[reader].ccid.dwMaxIFSD = 254;          serialDevice[reader].ccid.dwMaxIFSD = 254;
# Line 556  status_t OpenSerialByName(unsigned int l Line 619  status_t OpenSerialByName(unsigned int l
619          serialDevice[reader].ccid.bPINSupport = 0x0;          serialDevice[reader].ccid.bPINSupport = 0x0;
620          serialDevice[reader].ccid.dwDefaultClock = 4000;          serialDevice[reader].ccid.dwDefaultClock = 4000;
621          serialDevice[reader].ccid.dwMaxDataRate = 344086;          serialDevice[reader].ccid.dwMaxDataRate = 344086;
622            serialDevice[reader].ccid.bMaxSlotIndex = 0;
623            serialDevice[reader].ccid.bCurrentSlotIndex = 0;
624            serialDevice[reader].ccid.arrayOfSupportedDataRates = SerialDataRates;
625    
626          serialDevice[reader].buffer_offset = 0;          serialDevice[reader].buffer_offset = 0;
627          serialDevice[reader].buffer_offset_last = 0;          serialDevice[reader].buffer_offset_last = 0;
# Line 563  status_t OpenSerialByName(unsigned int l Line 629  status_t OpenSerialByName(unsigned int l
629          /* perform a command to be sure a GemPC Twin reader is connected          /* perform a command to be sure a GemPC Twin reader is connected
630           * get the reader firmware */           * get the reader firmware */
631          {          {
632                  unsigned char tx_buffer[] = "\x02";                  unsigned char tx_buffer[] = { 0x02 };
633                  unsigned char rx_buffer[50];                  unsigned char rx_buffer[50];
634                  unsigned int rx_length = sizeof(rx_buffer);                  unsigned int rx_length = sizeof(rx_buffer);
635    
636                  if (IFD_SUCCESS != CmdEscape(lun, tx_buffer, sizeof(tx_buffer),                  /* 2 seconds timeout to not wait too long if no reader is connected */
637                    serialDevice[reader].ccid.readTimeout = 2;
638    
639                    if (IFD_SUCCESS != CmdEscape(reader_index, tx_buffer, sizeof(tx_buffer),
640                          rx_buffer, &rx_length))                          rx_buffer, &rx_length))
641                  {                  {
642                          DEBUG_CRITICAL("Get firmware failed. Maybe the reader is not co,,ected");                          DEBUG_CRITICAL("Get firmware failed. Maybe the reader is not connected");
643                          return STATUS_UNSUCCESSFUL;                          return STATUS_UNSUCCESSFUL;
644                  }                  }
645    
646                    /* normal timeout: 2 seconds */
647                    serialDevice[reader].ccid.readTimeout = DEFAULT_COM_READ_TIMEOUT ;
648    
649                  rx_buffer[rx_length] = '\0';                  rx_buffer[rx_length] = '\0';
650                  DEBUG_INFO2("Firmware: %s", rx_buffer);                  DEBUG_INFO2("Firmware: %s", rx_buffer);
651          }          }
652    
653            /* perform a command to configure GemPC Twin reader card movement
654             * notification to synchronous mode: the card movement is notified _after_
655             * the host command and _before_ the reader anwser */
656            {
657                    unsigned char tx_buffer[] = { 0x01, 0x01, 0x01};
658                    unsigned char rx_buffer[50];
659                    unsigned int rx_length = sizeof(rx_buffer);
660    
661                    if (IFD_SUCCESS != CmdEscape(reader_index, tx_buffer, sizeof(tx_buffer),
662                            rx_buffer, &rx_length))
663                    {
664                            DEBUG_CRITICAL("Change card movement notification failed.");
665                            return STATUS_UNSUCCESSFUL;
666                    }
667            }
668    
669          return STATUS_SUCCESS;          return STATUS_SUCCESS;
670  } /* OpenSerialByName */  } /* OpenSerialByName */
671    
# Line 587  status_t OpenSerialByName(unsigned int l Line 675  status_t OpenSerialByName(unsigned int l
675   *                              CloseSerial: close the port   *                              CloseSerial: close the port
676   *   *
677   *****************************************************************************/   *****************************************************************************/
678  status_t CloseSerial(unsigned int lun)  status_t CloseSerial(unsigned int reader_index)
679  {  {
680          unsigned int reader = LunToReaderIndex(lun);          unsigned int reader = reader_index;
681    
682          close(serialDevice[reader].fd);          close(serialDevice[reader].fd);
683          serialDevice[reader].fd = -1;          serialDevice[reader].fd = -1;
# Line 606  status_t CloseSerial(unsigned int lun) Line 694  status_t CloseSerial(unsigned int lun)
694   *                                      get_ccid_descriptor   *                                      get_ccid_descriptor
695   *   *
696   ****************************************************************************/   ****************************************************************************/
697  _ccid_descriptor *get_ccid_descriptor(unsigned int lun)  _ccid_descriptor *get_ccid_descriptor(unsigned int reader_index)
698  {  {
699          return &serialDevice[LunToReaderIndex(lun)].ccid;          return &serialDevice[reader_index].ccid;
700  } /* get_ccid_descriptor */  } /* get_ccid_descriptor */
701    
702    

Legend:
Removed from v.1053  
changed lines
  Added in v.1771

  ViewVC Help
Powered by ViewVC 1.1.5