[Pcsclite-cvs-commit] r6783 - trunk/Drivers/ccid/src
ludovic.rousseau at free.fr
ludovic.rousseau at free.fr
Thu Oct 24 09:36:52 UTC 2013
Author: rousseau
Date: 2013-10-24 09:36:52 +0000 (Thu, 24 Oct 2013)
New Revision: 6783
Modified:
trunk/Drivers/ccid/src/ccid.c
trunk/Drivers/ccid/src/ccid_serial.c
trunk/Drivers/ccid/src/commands.c
trunk/Drivers/ccid/src/commands.h
trunk/Drivers/ccid/src/ifdhandler.c
Log:
Add a timeout parameter to CmdEscape()
Not all commands need the same timeout. For example the CmdEscape() used
in ccid_serial.c to check if the reader is alive should have a short
timeout.
The timeout was forced to 30 seconds inside CmdEscape() so it was not
possible to use a different value. The patch fixes this.
Modified: trunk/Drivers/ccid/src/ccid.c
===================================================================
--- trunk/Drivers/ccid/src/ccid.c 2013-10-24 08:51:11 UTC (rev 6782)
+++ trunk/Drivers/ccid/src/ccid.c 2013-10-24 09:36:52 UTC (rev 6783)
@@ -200,7 +200,7 @@
RESPONSECODE ret;
ret = CmdEscape(reader_index, cmd, sizeof cmd,
- (unsigned char*)gf_features, &len_features);
+ (unsigned char*)gf_features, &len_features, 0);
if ((IFD_SUCCESS == ret) &&
(len_features == sizeof *gf_features))
{
@@ -242,7 +242,7 @@
unsigned char res[10];
unsigned int length_res = sizeof(res);
- if (CmdEscape(reader_index, cmd, sizeof(cmd), res, &length_res) == IFD_SUCCESS)
+ if (CmdEscape(reader_index, cmd, sizeof(cmd), res, &length_res, 0) == IFD_SUCCESS)
{
ccid_descriptor->dwFeatures &= ~CCID_CLASS_EXCHANGE_MASK;
ccid_descriptor->dwFeatures |= CCID_CLASS_SHORT_APDU;
@@ -427,7 +427,7 @@
}
(void)sleep(1);
- if (IFD_SUCCESS == CmdEscape(reader_index, cmd, sizeof(cmd), res, &length_res))
+ if (IFD_SUCCESS == CmdEscape(reader_index, cmd, sizeof(cmd), res, &length_res, 0))
{
DEBUG_COMM("l10n string loaded successfully");
}
@@ -467,8 +467,8 @@
unsigned char res[20];
unsigned int length_res = sizeof(res);
- if ((IFD_SUCCESS == CmdEscape(reader_index, cmd1, sizeof(cmd1), res, &length_res))
- && (IFD_SUCCESS == CmdEscape(reader_index, cmd2, sizeof(cmd2), res, &length_res)))
+ if ((IFD_SUCCESS == CmdEscape(reader_index, cmd1, sizeof(cmd1), res, &length_res, 0))
+ && (IFD_SUCCESS == CmdEscape(reader_index, cmd2, sizeof(cmd2), res, &length_res, 0)))
{
DEBUG_COMM("SCM SCR331-DI contactless detected");
}
Modified: trunk/Drivers/ccid/src/ccid_serial.c
===================================================================
--- trunk/Drivers/ccid/src/ccid_serial.c 2013-10-24 08:51:11 UTC (rev 6782)
+++ trunk/Drivers/ccid/src/ccid_serial.c 2013-10-24 09:36:52 UTC (rev 6783)
@@ -760,19 +760,14 @@
unsigned int rx_length = sizeof(rx_buffer);
/* 2 seconds timeout to not wait too long if no reader is connected */
- serialDevice[reader].ccid.readTimeout = 2*1000;
-
if (IFD_SUCCESS != CmdEscape(reader_index, tx_buffer, sizeof(tx_buffer),
- rx_buffer, &rx_length))
+ rx_buffer, &rx_length, 2*1000))
{
DEBUG_CRITICAL("Get firmware failed. Maybe the reader is not connected");
(void)CloseSerial(reader_index);
return STATUS_UNSUCCESSFUL;
}
- /* normal timeout: 2 seconds */
- serialDevice[reader].ccid.readTimeout = DEFAULT_COM_READ_TIMEOUT ;
-
rx_buffer[rx_length] = '\0';
DEBUG_INFO2("Firmware: %s", rx_buffer);
}
@@ -786,7 +781,7 @@
unsigned int rx_length = sizeof(rx_buffer);
if (IFD_SUCCESS != CmdEscape(reader_index, tx_buffer, sizeof(tx_buffer),
- rx_buffer, &rx_length))
+ rx_buffer, &rx_length, 0))
{
DEBUG_CRITICAL("Change card movement notification failed.");
(void)CloseSerial(reader_index);
Modified: trunk/Drivers/ccid/src/commands.c
===================================================================
--- trunk/Drivers/ccid/src/commands.c 2013-10-24 08:51:11 UTC (rev 6782)
+++ trunk/Drivers/ccid/src/commands.c 2013-10-24 09:36:52 UTC (rev 6783)
@@ -245,7 +245,7 @@
unsigned int res_length = sizeof(res_tmp);
if ((return_value = CmdEscape(reader_index, cmd_tmp,
- sizeof(cmd_tmp), res_tmp, &res_length)) != IFD_SUCCESS)
+ sizeof(cmd_tmp), res_tmp, &res_length, 0)) != IFD_SUCCESS)
return return_value;
/* avoid looping if we can't switch mode */
@@ -455,7 +455,7 @@
/* the SPR532 will append the PIN code without any padding */
return_value = CmdEscape(reader_index, cmd_tmp, sizeof(cmd_tmp),
- res_tmp, &res_length);
+ res_tmp, &res_length, 0);
if (return_value != IFD_SUCCESS)
return return_value;
@@ -805,7 +805,7 @@
****************************************************************************/
RESPONSECODE CmdEscape(unsigned int reader_index,
const unsigned char TxBuffer[], unsigned int TxLength,
- unsigned char RxBuffer[], unsigned int *RxLength)
+ unsigned char RxBuffer[], unsigned int *RxLength, unsigned int timeout)
{
unsigned char *cmd_in, *cmd_out;
status_t res;
@@ -814,8 +814,12 @@
int old_read_timeout;
_ccid_descriptor *ccid_descriptor = get_ccid_descriptor(reader_index);
- old_read_timeout = ccid_descriptor -> readTimeout;
- ccid_descriptor -> readTimeout = 30*1000; /* 30 seconds */
+ /* a value of 0 do not change the default read timeout */
+ if (timeout > 0)
+ {
+ old_read_timeout = ccid_descriptor -> readTimeout;
+ ccid_descriptor -> readTimeout = timeout;
+ }
again:
/* allocate buffers */
@@ -909,7 +913,9 @@
free(cmd_out);
end:
- ccid_descriptor -> readTimeout = old_read_timeout;
+ if (timeout > 0)
+ ccid_descriptor -> readTimeout = old_read_timeout;
+
return return_value;
} /* Escape */
Modified: trunk/Drivers/ccid/src/commands.h
===================================================================
--- trunk/Drivers/ccid/src/commands.h 2013-10-24 08:51:11 UTC (rev 6782)
+++ trunk/Drivers/ccid/src/commands.h 2013-10-24 09:36:52 UTC (rev 6783)
@@ -39,7 +39,7 @@
RESPONSECODE CmdEscape(unsigned int reader_index,
const unsigned char TxBuffer[], unsigned int TxLength,
- unsigned char RxBuffer[], unsigned int *RxLength);
+ unsigned char RxBuffer[], unsigned int *RxLength, unsigned int timeout);
RESPONSECODE CmdPowerOff(unsigned int reader_index);
Modified: trunk/Drivers/ccid/src/ifdhandler.c
===================================================================
--- trunk/Drivers/ccid/src/ifdhandler.c 2013-10-24 08:51:11 UTC (rev 6782)
+++ trunk/Drivers/ccid/src/ifdhandler.c 2013-10-24 09:36:52 UTC (rev 6783)
@@ -1397,8 +1397,9 @@
unsigned int iBytesReturned;
iBytesReturned = RxLength;
- return_value = CmdEscape(reader_index, TxBuffer, TxLength, RxBuffer,
- &iBytesReturned);
+ /* 30 seconds timeout for long commands */
+ return_value = CmdEscape(reader_index, TxBuffer, TxLength,
+ RxBuffer, &iBytesReturned, 30*1000);
*pdwBytesReturned = iBytesReturned;
}
}
@@ -1543,7 +1544,7 @@
unsigned int len;
len = sizeof(firmware);
- ret = CmdEscape(reader_index, cmd, sizeof(cmd), firmware, &len);
+ ret = CmdEscape(reader_index, cmd, sizeof(cmd), firmware, &len, 0);
if (IFD_SUCCESS == ret)
{
@@ -1670,8 +1671,8 @@
/* we just transmit the buffer as a CCID Escape command */
iBytesReturned = RxLength;
- return_value = CmdEscape(reader_index, TxBuffer, TxLength, RxBuffer,
- &iBytesReturned);
+ return_value = CmdEscape(reader_index, TxBuffer, TxLength,
+ RxBuffer, &iBytesReturned, 0);
*pdwBytesReturned = iBytesReturned;
}
}
@@ -1792,7 +1793,7 @@
if (! (LogLevel & DEBUG_LEVEL_PERIODIC))
LogLevel &= ~DEBUG_LEVEL_COMM;
- ret = CmdEscape(reader_index, cmd, sizeof(cmd), res, &length_res);
+ ret = CmdEscape(reader_index, cmd, sizeof(cmd), res, &length_res, 0);
/* set back the old LogLevel */
LogLevel = oldLogLevel;
More information about the Pcsclite-cvs-commit
mailing list