Revert r4668. Change the way limitations on max send and receive sizes are set.

See http://www.opensc-project.org/pipermail/opensc-devel/2010-September/014836.html

git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@4706 c6295689-39f2-0310-b995-f0e70906c6a9
This commit is contained in:
martin 2010-09-09 18:58:44 +00:00
parent ac0a8dbb15
commit a5ca648afd
14 changed files with 30 additions and 53 deletions

View File

@ -270,7 +270,7 @@ static int sc_check_apdu(sc_card_t *card, const sc_apdu_t *apdu)
{
if ((apdu->cse & ~SC_APDU_SHORT_MASK) == 0) {
/* length check for short APDU */
if (apdu->le > card->max_recv_size || (apdu->lc > card->max_send_size &&
if (apdu->le > 256 || (apdu->lc > 255 &&
(apdu->flags & SC_APDU_FLAGS_CHAINING) == 0))
goto error;
} else if ((apdu->cse & SC_APDU_EXT) != 0) {
@ -361,7 +361,7 @@ static void sc_detect_apdu_cse(const sc_card_t *card, sc_apdu_t *apdu)
* short APDUs and the card supports extended APDUs
* use extended APDUs (unless Lc is greater than
* 255 and command chaining is activated) */
if ((apdu->le > card->max_recv_size || (apdu->lc > card->max_send_size && (apdu->flags & SC_APDU_FLAGS_CHAINING) == 0)) &&
if ((apdu->le > 256 || (apdu->lc > 255 && (apdu->flags & SC_APDU_FLAGS_CHAINING) == 0)) &&
(card->caps & SC_CARD_CAP_APDU_EXT) != 0)
btype |= SC_APDU_EXT;
apdu->cse = btype;
@ -407,7 +407,7 @@ static int do_single_transmit(sc_card_t *card, sc_apdu_t *apdu)
* response buffer size is larger than the new Le = SW2)
*/
if (apdu->sw1 == 0x6C && (apdu->flags & SC_APDU_FLAGS_NO_RETRY_WL) == 0) {
size_t nlen = apdu->sw2 != 0 ? (size_t)apdu->sw2 : card->max_recv_size;
size_t nlen = apdu->sw2 != 0 ? (size_t)apdu->sw2 : 256;
if (olen >= nlen) {
/* don't try again if it doesn't work this time */
apdu->flags |= SC_APDU_FLAGS_NO_GET_RESP;
@ -540,9 +540,7 @@ int sc_transmit_apdu(sc_card_t *card, sc_apdu_t *apdu)
* bytes using command chaining */
size_t len = apdu->datalen;
const u8 *buf = apdu->data;
size_t max_send_size = ((card->max_send_size > 0) ?
card->max_send_size :
card->reader->driver->max_send_size);
size_t max_send_size = card->max_send_size > 0 ? card->max_send_size : 255;
while (len != 0) {
size_t plen;

View File

@ -65,10 +65,8 @@ akis_init(sc_card_t *card)
card->name = "AKIS";
card->cla = 0x00;
card->max_pin_len = 16;
if (card->max_recv_size > 244)
card->max_recv_size = 244;
if (card->max_send_size > 244)
card->max_send_size = 244;
card->max_recv_size = 244;
card->max_send_size = 244;
flags = SC_ALGORITHM_RSA_RAW | SC_ALGORITHM_RSA_PAD_PKCS1;
_sc_card_add_rsa_alg(card, 2048, flags, 0);

View File

@ -127,10 +127,8 @@ static int atrust_acos_init(struct sc_card *card)
_sc_card_add_rsa_alg(card, 1536, flags, 0x10001);
/* we need read_binary&friends with max 128 bytes per read */
if (card->max_send_size > 128)
card->max_send_size = 128;
if (card->max_recv_size > 128)
card->max_recv_size = 128;
card->max_send_size = 128;
card->max_recv_size = 128;
return 0;
}

View File

@ -134,10 +134,8 @@ static int entersafe_init(sc_card_t *card)
card->caps = SC_CARD_CAP_RNG;
/* we need read_binary&friends with max 224 bytes per read */
if (card->max_send_size > 224)
card->max_send_size = 224;
if (card->max_recv_size > 224)
card->max_recv_size = 224;
card->max_send_size = 224;
card->max_recv_size = 224;
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE,SC_SUCCESS);
}

View File

@ -201,12 +201,8 @@ gpk_init(sc_card_t *card)
/* State that we have an RNG */
card->caps |= SC_CARD_CAP_RNG;
/* Make sure max send/receive size is 4 byte aligned. */
card->max_send_size &= ~3;
if (card->max_recv_size >= 256)
card->max_recv_size = 252;
else
card->max_recv_size &= ~3;
/* Make sure max send/receive size is 4 byte aligned and <256. */
card->max_recv_size = 252;
return 0;
}

View File

@ -706,7 +706,7 @@ do_select(sc_card_t * card, u8 kind,
apdu.lc = apdu.datalen;
apdu.resp = resbuf;
apdu.resplen = sizeof(resbuf);
apdu.le = card->max_recv_size;
apdu.le = sizeof(resbuf);
r = sc_transmit_apdu(card, &apdu);
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");

View File

@ -69,10 +69,8 @@ static int miocos_init(sc_card_t *card)
/* read_binary and friends shouldn't do more than 244 bytes
* per operation */
if (card->max_send_size > 244)
card->max_send_size = 244;
if (card->max_recv_size > 244)
card->max_recv_size = 244;
card->max_send_size = 244;
card->max_recv_size = 244;
return 0;
}

View File

@ -495,8 +495,6 @@ static int muscle_init(sc_card_t *card)
_sc_card_add_rsa_alg(card, 1024, flags, 0);
_sc_card_add_rsa_alg(card, 2048, flags, 0);
}
card->max_recv_size = 1024 * 64;
card->max_send_size = 1024 * 64;
return SC_SUCCESS;
}

View File

@ -105,10 +105,8 @@ static int myeid_init(struct sc_card *card)
/* State that we have an RNG */
card->caps |= SC_CARD_CAP_RNG;
if (card->max_recv_size > 255)
card->max_recv_size = 255;
if (card->max_send_size > 255)
card->max_send_size = 255;
card->max_recv_size = 255;
card->max_send_size = 255;
return 0;
}

View File

@ -273,7 +273,7 @@ static int piv_general_io(sc_card_t *card, int ins, int p1, int p2,
if (recvbuf) {
apdu.resp = rbuf;
apdu.le = (card->max_recv_size <= rbuflen)? card->max_recv_size : rbuflen;
apdu.le = (card->max_recv_size > 0 && card->max_recv_size <= rbuflen)? card->max_recv_size : rbuflen;
apdu.resplen = rbuflen;
} else {
apdu.resp = rbuf;
@ -1871,9 +1871,6 @@ static int piv_init(sc_card_t *card)
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_OUT_OF_MEMORY);
priv->aid_file = sc_file_new();
priv->selected_obj = -1;
/* priv->max_recv_size = 256; */
/* priv->max_recv_size = card->max_recv_size; */
/* priv->max_send_size = card->max_send_size; */
sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "Max send = %d recv = %d\n",
card->max_send_size, card->max_recv_size);

View File

@ -111,10 +111,8 @@ static int starcos_init(sc_card_t *card)
card->caps = SC_CARD_CAP_RNG;
/* we need read_binary&friends with max 128 bytes per read */
if (card->max_send_size > 128)
card->max_send_size = 128;
if (card->max_recv_size > 128)
card->max_recv_size = 128;
card->max_send_size = 128;
card->max_recv_size = 128;
return 0;
}

View File

@ -129,10 +129,6 @@ int sc_connect_card(sc_reader_t *reader, sc_card_t **card_out)
card->reader = reader;
card->ctx = ctx;
/* These can be overridden by the card driver */
card->max_send_size = reader->driver->max_send_size;
card->max_recv_size = reader->driver->max_recv_size;
memcpy(card->atr, reader->atr, reader->atr_len);
card->atr_len = reader->atr_len;
@ -222,6 +218,12 @@ int sc_connect_card(sc_reader_t *reader, sc_card_t **card_out)
card->name = card->driver->name;
*card_out = card;
/* Override card limitations with reader limitations */
if (reader->driver->max_recv_size > 0)
card->max_recv_size = reader->driver->max_recv_size < card->max_recv_size ? reader->driver->max_recv_size : card->max_recv_size;
if (reader->driver->max_send_size > 0)
card->max_send_size = reader->driver->max_send_size < card->max_send_size ? reader->driver->max_send_size : card->max_send_size;
sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "card info: %s, %i, 0x%X\n",
card->name, card->type, card->flags);
SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_NORMAL, 0);

View File

@ -453,7 +453,7 @@ static int iso7816_select_file(sc_card_t *card,
if (file_out != NULL) {
apdu.resp = buf;
apdu.resplen = sizeof(buf);
apdu.le = card->max_recv_size;
apdu.le = card->max_recv_size > 0 ? card->max_recv_size : 256;
} else
apdu.cse = (apdu.lc == 0) ? SC_APDU_CASE_1 : SC_APDU_CASE_3_SHORT;
@ -611,7 +611,7 @@ static int iso7816_get_response(sc_card_t *card, size_t *count, u8 *buf)
size_t rlen;
/* request at most max_recv_size bytes */
if (*count > card->max_recv_size)
if (card->max_recv_size > 0 && *count > card->max_recv_size)
rlen = card->max_recv_size;
else
rlen = *count;

View File

@ -213,10 +213,8 @@ static int sc_pkcs15emu_gemsafeGPK_init(sc_pkcs15_card_t *p15card)
SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
/* need to limit to 248 */
if (card->max_send_size > 248)
card->max_send_size = 248;
if (card->max_recv_size > 248)
card->max_recv_size = 248;
card->max_send_size = 248;
card->max_recv_size = 248;
/* could read this off card if needed */