Skip to content

Commit

Permalink
PHSetProtocol(): negotiate PTS also for the backup protocol
Browse files Browse the repository at this point in the history
If the first call to IFDSetPTS() fails with IFD_PROTOCOL_NOT_SUPPORTED
or IFD_ERROR_NOT_SUPPORTED and another protocol can be negotiated then
we call IFDSetPTS() with this second/backup protocol instead of doing
nothing.

This allows the driver to correctly configure the reader with the
selected protocol.

This happens if a card supports both T=0 and T=1, the application uses
SCARD_PROTOCOL_ANY but the reader only supports T=0.
1. The first protocol tried is T=1 (preferred over T=0).
2. If the T=1 PTS negotiation fails then we try T=0.
3. If the T=0 PTS negotiation fails then we report an error.

The step 3 was missing.
  • Loading branch information
LudovicRousseau committed Nov 29, 2023
1 parent 720af2d commit 0575a26
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/prothandler.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ DWORD PHSetProtocol(struct ReaderContext * rContext,
/* App wants unsupported protocol */
return SET_PROTOCOL_WRONG_ARGUMENT;

again:
Log2(PCSC_LOG_INFO, "Attempting PTS to T=%d",
(SCARD_PROTOCOL_T0 == ucChosen ? 0 : 1));
rv = IFDSetPTS(rContext, ucChosen, 0x00, 0x00, 0x00, 0x00);
Expand All @@ -124,6 +125,14 @@ DWORD PHSetProtocol(struct ReaderContext * rContext,
Log3(PCSC_LOG_INFO,
"Set PTS failed (%ld). Using T=%d", rv,
(SCARD_PROTOCOL_T0 == protocol) ? 0 : 1);

/* try again with the other protocol */
ucChosen = protocol;

/* but no other protocol should be tried after that */
dwPreferred = protocol;

goto again;
}
else
{
Expand Down

0 comments on commit 0575a26

Please sign in to comment.