From 0914b1eca773769731b766d728a7419b6559ffd0 Mon Sep 17 00:00:00 2001 From: Viktor Tarasov Date: Tue, 19 Jun 2012 18:04:37 +0200 Subject: [PATCH] libopensc: SM: not all the APDUs need to be wrapped For some cards some APDUs are always transmitted in a plain mode, even if SM session is opened. For these APDUs the 'get_sm_apdu' card's handler returns SUCCESS without wrapped APDU version. In such cases 'transmit' is called for the plain APDU. --- src/libopensc/apdu.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/libopensc/apdu.c b/src/libopensc/apdu.c index 1ea8e5d9..2c5c0908 100644 --- a/src/libopensc/apdu.c +++ b/src/libopensc/apdu.c @@ -475,8 +475,12 @@ sc_single_sm_transmit(struct sc_card *card, struct sc_apdu *apdu) rv = card->sm_ctx.ops.get_sm_apdu(card, apdu, &sm_apdu); LOG_TEST_RET(ctx, rv, "get SM APDU error"); - if (!sm_apdu) - LOG_TEST_RET(ctx, SC_ERROR_INTERNAL, "cannot get SM APDU"); + if (!sm_apdu) { + /* SM wrap of this APDU is ignored by card driver. + * Send plain APDU to the reader driver */ + rv = card->reader->ops->transmit(card->reader, apdu); + LOG_FUNC_RETURN(ctx, rv); + } /* check if SM APDU is still valid */ rv = sc_check_apdu(card, sm_apdu); @@ -507,6 +511,8 @@ sc_single_transmit(struct sc_card *card, struct sc_apdu *apdu) if (card->reader->ops->transmit == NULL) LOG_TEST_RET(card->ctx, SC_ERROR_NOT_SUPPORTED, "cannot transmit APDU"); + sc_log(ctx, "CLA:%X, INS:%X, P1:%X, P2:%X, data(%i) %p", + apdu->cla, apdu->ins, apdu->p1, apdu->p2, apdu->datalen, apdu->data); #ifdef ENABLE_SM if (card->sm_ctx.sm_mode == SM_MODE_TRANSMIT) return sc_single_sm_transmit(card, apdu);