Adding support for standard USB Smartcard Readers (#769)

* add PCSC reader support to 'sc raw' and all 'emv' commands
* move all APDU -> TPDU mapping to ExchangeAPDUSC()
* print "PSE" instead of "PPSE" when using contact interface
* fix some #defines in protocols.h
* DropField only when using contactless
* some refactoring
This commit is contained in:
pwpiwi 2019-02-01 21:12:20 +01:00 committed by GitHub
commit 6b5105bea9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 388 additions and 311 deletions

View file

@ -175,3 +175,41 @@ bool pcscGetATR(smart_card_atr_t *card)
return true;
}
void pcscTransmit(uint8_t *data, uint32_t data_len, uint32_t flags, uint8_t *response, int *response_len)
{
LPCSCARD_IO_REQUEST protocol;
if (flags & SC_RAW_T0) {
protocol = SCARD_PCI_T0;
} else {
protocol = SCARD_PCI_RAW;
}
// TODO: tracing
// if ((flags & SC_CONNECT))
// clear_trace();
// set_tracing(true);
if ((flags & SC_CONNECT || flags & SC_SELECT)) {
LONG res = SCardConnect(SC_Context, AlternativeSmartcardReader, SCARD_SHARE_SHARED,
SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1, &SC_Card, &SC_Protocol);
if (res != SCARD_S_SUCCESS) {
*response_len = -1;
return;
}
}
if ((flags & SC_RAW) || (flags & SC_RAW_T0)) {
// TODO: tracing
// LogTrace(data, arg1, 0, 0, NULL, true);
DWORD len = *response_len;
LONG res = SCardTransmit(SC_Card, protocol, data, data_len, NULL, response, &len);
if (res != SCARD_S_SUCCESS) {
*response_len = -1;
} else {
*response_len = len;
}
}
}