Skip to content

Commit db459f9

Browse files
Add backward version support on the client side
The client side (libpcsclite) now supports protocol version 4:5 (as before) and also 4:4. Protocol 4:5 was introduced with pcsc-lite 2.3.0 in Aug 2024. Protocol 4:4 was introduced with pcsc-lite 1.8.24 in Oct 2018. So now libpcsclite can work with a pcscd as old as 2018.
1 parent 4a507ac commit db459f9

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

src/winscard_clnt.c

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
135135

136136

137137
static bool sharing_shall_block = true;
138+
static int Protocol_version;
138139

139140
#define COLOR_RED "\33[01;31m"
140141
#define COLOR_GREEN "\33[32m"
@@ -568,6 +569,7 @@ static LONG SCardEstablishContextTH(DWORD dwScope,
568569
LONG rv;
569570
struct establish_struct scEstablishStruct;
570571
uint32_t dwClientID = 0;
572+
struct version_struct veStr;
571573

572574
(void)pvReserved1;
573575
(void)pvReserved2;
@@ -586,11 +588,12 @@ static LONG SCardEstablishContextTH(DWORD dwScope,
586588
return SCARD_E_NO_SERVICE;
587589
}
588590

591+
veStr.major = PROTOCOL_VERSION_MAJOR;
592+
veStr.minor = PROTOCOL_VERSION_MINOR;
593+
594+
connect_again:
589595
{ /* exchange client/server protocol versions */
590-
struct version_struct veStr;
591596

592-
veStr.major = PROTOCOL_VERSION_MAJOR;
593-
veStr.minor = PROTOCOL_VERSION_MINOR;
594597
veStr.rv = SCARD_S_SUCCESS;
595598

596599
rv = MessageSendWithHeader(CMD_VERSION, dwClientID, sizeof(veStr),
@@ -609,6 +612,23 @@ static LONG SCardEstablishContextTH(DWORD dwScope,
609612

610613
Log3(PCSC_LOG_INFO, "Server is protocol version %d:%d",
611614
veStr.major, veStr.minor);
615+
Log3(PCSC_LOG_INFO, "Client is protocol version %d:%d",
616+
PROTOCOL_VERSION_MAJOR, PROTOCOL_VERSION_MINOR);
617+
618+
if (SCARD_E_SERVICE_STOPPED == veStr.rv)
619+
{
620+
/* server complained about our protocol version? */
621+
if (PROTOCOL_VERSION_MAJOR == veStr.major)
622+
{
623+
if (PROTOCOL_VERSION_MINOR_CLIENT_BACKWARD <= veStr.minor)
624+
{
625+
/* try again with the protocol version proposed by
626+
* the server */
627+
Log1(PCSC_LOG_INFO, "Using backward compatibility");
628+
goto connect_again;
629+
}
630+
}
631+
}
612632

613633
if (veStr.rv != SCARD_S_SUCCESS)
614634
{
@@ -617,6 +637,9 @@ static LONG SCardEstablishContextTH(DWORD dwScope,
617637
}
618638
}
619639

640+
/* store protocol version of the server */
641+
Protocol_version = veStr.major * 1000 + veStr.minor;
642+
620643
again:
621644
/*
622645
* Try to establish an Application Context with the server
@@ -3634,6 +3657,10 @@ static LONG getReaderEvents(SCONTEXTMAP * currentContextMap, int *readerEvents)
36343657
LONG rv;
36353658
struct get_reader_events get_reader_events = {0};
36363659

3660+
/* CMD_GET_READER_EVENTS was added in protocol 4:5 */
3661+
if (Protocol_version < 4005)
3662+
return SCARD_E_UNSUPPORTED_FEATURE;
3663+
36373664
rv = MessageSendWithHeader(CMD_GET_READER_EVENTS, dwClientID, 0, NULL);
36383665
if (rv != SCARD_S_SUCCESS)
36393666
return rv;

src/winscard_msg.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5050
#define PROTOCOL_VERSION_MAJOR 4
5151
/** Minor version of the current message protocol */
5252
#define PROTOCOL_VERSION_MINOR 5
53+
/** Minor version the client also supports */
54+
#define PROTOCOL_VERSION_MINOR_CLIENT_BACKWARD 4
5355

5456
/**
5557
* @brief Information transmitted in \ref CMD_VERSION Messages.

0 commit comments

Comments
 (0)