| 42 |
#include "utils.h" |
#include "utils.h" |
| 43 |
#include "commands.h" |
#include "commands.h" |
| 44 |
|
|
|
/* communication timeout in seconds |
|
|
* the value is set at the end of OpenSerialByName() */ |
|
|
int SerialTimeout; |
|
|
|
|
| 45 |
#define SYNC 0x03 |
#define SYNC 0x03 |
| 46 |
#define CTRL_ACK 0x06 |
#define CTRL_ACK 0x06 |
| 47 |
#define CTRL_NAK 0x15 |
#define CTRL_NAK 0x15 |
| 443 |
/* use select() to, eventually, timeout */ |
/* use select() to, eventually, timeout */ |
| 444 |
FD_ZERO(&fdset); |
FD_ZERO(&fdset); |
| 445 |
FD_SET(fd, &fdset); |
FD_SET(fd, &fdset); |
| 446 |
t.tv_sec = SerialTimeout; |
t.tv_sec = serialDevice[reader_index].ccid.readTimeout; |
| 447 |
t.tv_usec = 0; |
t.tv_usec = 0; |
| 448 |
|
|
| 449 |
i = select(fd+1, &fdset, NULL, NULL, &t); |
i = select(fd+1, &fdset, NULL, NULL, &t); |
| 455 |
else |
else |
| 456 |
if (i == 0) |
if (i == 0) |
| 457 |
{ |
{ |
| 458 |
DEBUG_COMM2("Timeout! (%d sec)", SerialTimeout); |
DEBUG_COMM2("Timeout! (%d sec)", serialDevice[reader_index].ccid.readTimeout); |
| 459 |
return -1; |
return -1; |
| 460 |
} |
} |
| 461 |
|
|
| 616 |
unsigned int rx_length = sizeof(rx_buffer); |
unsigned int rx_length = sizeof(rx_buffer); |
| 617 |
|
|
| 618 |
/* 2 seconds timeout to not wait too long if no reader is connected */ |
/* 2 seconds timeout to not wait too long if no reader is connected */ |
| 619 |
SerialTimeout = 2; |
serialDevice[reader].ccid.readTimeout = 2; |
| 620 |
|
|
| 621 |
if (IFD_SUCCESS != CmdEscape(reader_index, tx_buffer, sizeof(tx_buffer), |
if (IFD_SUCCESS != CmdEscape(reader_index, tx_buffer, sizeof(tx_buffer), |
| 622 |
rx_buffer, &rx_length)) |
rx_buffer, &rx_length)) |
| 625 |
return STATUS_UNSUCCESSFUL; |
return STATUS_UNSUCCESSFUL; |
| 626 |
} |
} |
| 627 |
|
|
| 628 |
/* normal timeout: 1 minute to allow long time APDU */ |
/* normal timeout: 2 seconds */ |
| 629 |
SerialTimeout = 60; |
serialDevice[reader].ccid.readTimeout = DEFAULT_COM_READ_TIMEOUT ; |
| 630 |
|
|
| 631 |
rx_buffer[rx_length] = '\0'; |
rx_buffer[rx_length] = '\0'; |
| 632 |
DEBUG_INFO2("Firmware: %s", rx_buffer); |
DEBUG_INFO2("Firmware: %s", rx_buffer); |