- added support for T=1 protocol
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@201 c6295689-39f2-0310-b995-f0e70906c6a9
This commit is contained in:
parent
1e909781d7
commit
1fb23e7623
|
@ -130,6 +130,34 @@ static int sc_check_apdu(struct sc_context *ctx, const struct sc_apdu *apdu)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static unsigned int pcsc_proto_to_opensc(DWORD proto)
|
||||
{
|
||||
switch (proto) {
|
||||
case SCARD_PROTOCOL_T0:
|
||||
return SC_PROTO_T0;
|
||||
case SCARD_PROTOCOL_T1:
|
||||
return SC_PROTO_T1;
|
||||
case SCARD_PROTOCOL_RAW:
|
||||
return SC_PROTO_RAW;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static DWORD opensc_proto_to_pcsc(unsigned int proto)
|
||||
{
|
||||
switch (proto) {
|
||||
case SC_PROTO_T0:
|
||||
return SCARD_PROTOCOL_T0;
|
||||
case SC_PROTO_T1:
|
||||
return SCARD_PROTOCOL_T1;
|
||||
case SC_PROTO_RAW:
|
||||
return SCARD_PROTOCOL_RAW;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static int sc_transceive_t0(struct sc_card *card, struct sc_apdu *apdu)
|
||||
{
|
||||
SCARD_IO_REQUEST sSendPci, sRecvPci;
|
||||
|
@ -173,9 +201,9 @@ static int sc_transceive_t0(struct sc_card *card, struct sc_apdu *apdu)
|
|||
break;
|
||||
}
|
||||
|
||||
sSendPci.dwProtocol = SCARD_PROTOCOL_T0;
|
||||
sSendPci.dwProtocol = opensc_proto_to_pcsc(card->protocol);
|
||||
sSendPci.cbPciLength = 0;
|
||||
sRecvPci.dwProtocol = SCARD_PROTOCOL_T0;
|
||||
sRecvPci.dwProtocol = opensc_proto_to_pcsc(card->protocol);
|
||||
sRecvPci.cbPciLength = 0;
|
||||
|
||||
dwSendLength = data - s;
|
||||
|
@ -357,13 +385,20 @@ int sc_connect_card(struct sc_context *ctx,
|
|||
SC_FUNC_RETURN(ctx, 1, SC_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
rv = SCardConnect(ctx->pcsc_ctx, ctx->readers[reader],
|
||||
SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0,
|
||||
SCARD_SHARE_SHARED, SCARD_PROTOCOL_ANY,
|
||||
&card_handle, &active_proto);
|
||||
if (rv != 0) {
|
||||
error(ctx, "SCardConnect failed: %s\n", pcsc_stringify_error(rv));
|
||||
r = -1; /* FIXME: invent a real error value */
|
||||
goto err;
|
||||
}
|
||||
|
||||
card->protocol = pcsc_proto_to_opensc(active_proto);
|
||||
if (card->protocol == 0) {
|
||||
error(ctx, "Unknown protocol (%X) selected.\n", active_proto);
|
||||
r = SC_ERROR_RESOURCE_MANAGER;
|
||||
goto err;
|
||||
}
|
||||
card->reader = reader;
|
||||
card->ctx = ctx;
|
||||
card->pcsc_card = card_handle;
|
||||
|
|
|
@ -251,10 +251,16 @@ struct sc_card_cache {
|
|||
*/
|
||||
/* none yet */
|
||||
|
||||
#define SC_PROTO_T0 0x00000001
|
||||
#define SC_PROTO_T1 0x00000002
|
||||
#define SC_PROTO_RAW 0x00001000
|
||||
#define SC_PROTO_ANY 0xFFFFFFFF
|
||||
|
||||
struct sc_card {
|
||||
struct sc_context *ctx;
|
||||
|
||||
SCARDHANDLE pcsc_card;
|
||||
unsigned int protocol;
|
||||
int reader;
|
||||
unsigned long caps, flags;
|
||||
int cla;
|
||||
|
|
Loading…
Reference in New Issue