libopensc: Now 'cache-valid' flag is a member of 'sc_card_cache' ...
add 'current_ef' and 'current_df' member to 'sc_card_cache'. The main purpose of this is to reduce number of APDU transactions. git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5002 c6295689-39f2-0310-b995-f0e70906c6a9
This commit is contained in:
parent
891f98363b
commit
92c3e59e16
|
@ -393,7 +393,7 @@ static int atrust_acos_select_file(struct sc_card *card,
|
|||
sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL,
|
||||
"current path (%s, %s): %s (len: %u)\n",
|
||||
(card->cache.current_path.type==SC_PATH_TYPE_DF_NAME?"aid":"path"),
|
||||
(card->cache_valid?"valid":"invalid"), pbuf,
|
||||
(card->cache.valid?"valid":"invalid"), pbuf,
|
||||
card->cache.current_path.len);
|
||||
|
||||
memcpy(path, in_path->value, in_path->len);
|
||||
|
@ -409,7 +409,7 @@ static int atrust_acos_select_file(struct sc_card *card,
|
|||
else if (in_path->type == SC_PATH_TYPE_DF_NAME)
|
||||
{ /* SELECT DF with AID */
|
||||
/* Select with 1-16byte Application-ID */
|
||||
if (card->cache_valid
|
||||
if (card->cache.valid
|
||||
&& card->cache.current_path.type == SC_PATH_TYPE_DF_NAME
|
||||
&& card->cache.current_path.len == pathlen
|
||||
&& memcmp(card->cache.current_path.value, pathbuf, pathlen) == 0 )
|
||||
|
@ -449,7 +449,7 @@ static int atrust_acos_select_file(struct sc_card *card,
|
|||
}
|
||||
|
||||
/* check current working directory */
|
||||
if (card->cache_valid
|
||||
if (card->cache.valid
|
||||
&& card->cache.current_path.type == SC_PATH_TYPE_PATH
|
||||
&& card->cache.current_path.len >= 2
|
||||
&& card->cache.current_path.len <= pathlen )
|
||||
|
@ -461,7 +461,7 @@ static int atrust_acos_select_file(struct sc_card *card,
|
|||
bMatch += 2;
|
||||
}
|
||||
|
||||
if ( card->cache_valid && bMatch >= 0 )
|
||||
if ( card->cache.valid && bMatch >= 0 )
|
||||
{
|
||||
if ( pathlen - bMatch == 2 )
|
||||
/* we are in the rigth directory */
|
||||
|
|
|
@ -489,7 +489,7 @@ static int entersafe_select_aid(sc_card_t *card,
|
|||
{
|
||||
int r = 0;
|
||||
|
||||
if (card->cache_valid
|
||||
if (card->cache.valid
|
||||
&& card->cache.current_path.type == SC_PATH_TYPE_DF_NAME
|
||||
&& card->cache.current_path.len == in_path->len
|
||||
&& memcmp(card->cache.current_path.value, in_path->value, in_path->len)==0 )
|
||||
|
@ -557,7 +557,7 @@ static int entersafe_select_path(sc_card_t *card,
|
|||
}
|
||||
|
||||
/* check current working directory */
|
||||
if (card->cache_valid
|
||||
if (card->cache.valid
|
||||
&& card->cache.current_path.type == SC_PATH_TYPE_PATH
|
||||
&& card->cache.current_path.len >= 2
|
||||
&& card->cache.current_path.len <= pathlen )
|
||||
|
@ -569,7 +569,7 @@ static int entersafe_select_path(sc_card_t *card,
|
|||
bMatch += 2;
|
||||
}
|
||||
|
||||
if ( card->cache_valid && bMatch > 2 )
|
||||
if ( card->cache.valid && bMatch > 2 )
|
||||
{
|
||||
if ( pathlen - bMatch == 2 )
|
||||
{
|
||||
|
@ -646,7 +646,7 @@ static int entersafe_select_file(sc_card_t *card,
|
|||
sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL,
|
||||
"current path (%s, %s): %s (len: %u)\n",
|
||||
(card->cache.current_path.type==SC_PATH_TYPE_DF_NAME?"aid":"path"),
|
||||
(card->cache_valid?"valid":"invalid"), pbuf,
|
||||
(card->cache.valid?"valid":"invalid"), pbuf,
|
||||
card->cache.current_path.len);
|
||||
|
||||
switch(in_path->type)
|
||||
|
@ -951,14 +951,25 @@ static int entersafe_pin_cmd(sc_card_t *card, struct sc_pin_cmd_data *data,
|
|||
|
||||
if(data->cmd!=SC_PIN_CMD_UNBLOCK)
|
||||
{
|
||||
|
||||
data->pin1.pad_length = 0x10;
|
||||
data->pin1.offset = 5;
|
||||
data->pin1.pad_char = 0x00;
|
||||
data->pin1.max_length = 0x08;
|
||||
data->pin1.min_length = 4;
|
||||
|
||||
r = iso_ops->pin_cmd(card,data,tries_left);
|
||||
sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "Verify rv:%i", r);
|
||||
}
|
||||
else
|
||||
{
|
||||
{/*verify*/
|
||||
sc_apdu_t apdu;
|
||||
u8 sbuf[0x10]={0};
|
||||
|
||||
//u8 sbuf[0x10]={0};
|
||||
//
|
||||
u8 sbuf[0x40];
|
||||
memset(sbuf, 0xFF, sizeof(sbuf));
|
||||
//
|
||||
memcpy(sbuf,data->pin1.data,data->pin1.len);
|
||||
sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT,0x20,0x00,data->pin_reference+1);
|
||||
apdu.lc = apdu.datalen = sizeof(sbuf);
|
||||
|
@ -1005,7 +1016,7 @@ static int entersafe_erase_card(sc_card_t *card)
|
|||
r = entersafe_transmit_apdu(card, &apdu,0,0,0,0);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
/* invalidate cache */
|
||||
card->cache_valid = 0;
|
||||
card->cache.valid = 0;
|
||||
|
||||
sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0xEE, 0x00, 0x00);
|
||||
apdu.cla=0x84;
|
||||
|
|
|
@ -961,7 +961,7 @@ static int flex_create_file(sc_card_t *card, sc_file_t *file)
|
|||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Card returned error");
|
||||
if (card->cache_valid) {
|
||||
if (card->cache.valid) {
|
||||
u8 file_id[2];
|
||||
|
||||
file_id[0] = file->id >> 8;
|
||||
|
|
|
@ -1618,7 +1618,7 @@ auth_pin_verify_pinpad(struct sc_card *card, int pin_reference, int *tries_left)
|
|||
pin_cmd.pin1.offset = 5;
|
||||
pin_cmd.pin1.data = ffs;
|
||||
pin_cmd.pin1.len = OBERTHUR_AUTH_MAX_LENGTH_PIN;
|
||||
pin_cmd.pin1.pad_length = 0;
|
||||
pin_cmd.pin1.pad_length = OBERTHUR_AUTH_MAX_LENGTH_PIN;
|
||||
|
||||
rv = iso_drv->ops->pin_cmd(card, &pin_cmd, tries_left);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, rv, "PIN CMD 'VERIFY' with pinpad failed");
|
||||
|
@ -1960,19 +1960,24 @@ auth_create_reference_data (struct sc_card *card,
|
|||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_INVALID_ARGUMENTS, "Invalid PUK options");
|
||||
|
||||
len = 0;
|
||||
sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "len %i", len);
|
||||
sbuf[len++] = args->pin_tries;
|
||||
sbuf[len++] = pin_info.pad_length;
|
||||
sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "len %i", len);
|
||||
memset(sbuf + len, pin_info.pad_char, pin_info.pad_length);
|
||||
memcpy(sbuf + len, args->pin, args->pin_len);
|
||||
len += pin_info.pad_length;
|
||||
sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "len %i", len);
|
||||
|
||||
if (args->puk && args->puk_len) {
|
||||
sbuf[len++] = args->puk_tries;
|
||||
sbuf[len++] = args->puk_len / puk_info.pad_length;
|
||||
sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "len %i", len);
|
||||
memcpy(sbuf + len, args->puk, args->puk_len);
|
||||
len += args->puk_len;
|
||||
}
|
||||
|
||||
sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "len %i", len);
|
||||
sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x24, 1, args->ref & ~OBERTHUR_PIN_LOCAL);
|
||||
apdu.data = sbuf;
|
||||
apdu.datalen = len;
|
||||
|
|
|
@ -375,7 +375,7 @@ static int starcos_select_file(sc_card_t *card,
|
|||
sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL,
|
||||
"current path (%s, %s): %s (len: %u)\n",
|
||||
(card->cache.current_path.type==SC_PATH_TYPE_DF_NAME?"aid":"path"),
|
||||
(card->cache_valid?"valid":"invalid"), pbuf,
|
||||
(card->cache.valid?"valid":"invalid"), pbuf,
|
||||
card->cache.current_path.len);
|
||||
|
||||
memcpy(path, in_path->value, in_path->len);
|
||||
|
@ -391,7 +391,7 @@ static int starcos_select_file(sc_card_t *card,
|
|||
else if (in_path->type == SC_PATH_TYPE_DF_NAME)
|
||||
{ /* SELECT DF with AID */
|
||||
/* Select with 1-16byte Application-ID */
|
||||
if (card->cache_valid
|
||||
if (card->cache.valid
|
||||
&& card->cache.current_path.type == SC_PATH_TYPE_DF_NAME
|
||||
&& card->cache.current_path.len == pathlen
|
||||
&& memcmp(card->cache.current_path.value, pathbuf, pathlen) == 0 )
|
||||
|
@ -431,7 +431,7 @@ static int starcos_select_file(sc_card_t *card,
|
|||
}
|
||||
|
||||
/* check current working directory */
|
||||
if (card->cache_valid
|
||||
if (card->cache.valid
|
||||
&& card->cache.current_path.type == SC_PATH_TYPE_PATH
|
||||
&& card->cache.current_path.len >= 2
|
||||
&& card->cache.current_path.len <= pathlen )
|
||||
|
@ -443,7 +443,7 @@ static int starcos_select_file(sc_card_t *card,
|
|||
bMatch += 2;
|
||||
}
|
||||
|
||||
if ( card->cache_valid && bMatch >= 0 )
|
||||
if ( card->cache.valid && bMatch >= 0 )
|
||||
{
|
||||
if ( pathlen - bMatch == 2 )
|
||||
/* we are in the rigth directory */
|
||||
|
@ -859,7 +859,7 @@ static int starcos_erase_card(sc_card_t *card)
|
|||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
/* invalidate cache */
|
||||
card->cache_valid = 0;
|
||||
card->cache.valid = 0;
|
||||
if (apdu.sw1 == 0x69 && apdu.sw2 == 0x85)
|
||||
/* no MF to delete, ignore error */
|
||||
return SC_SUCCESS;
|
||||
|
|
|
@ -277,7 +277,7 @@ int sc_reset(sc_card_t *card, int do_cold_reset)
|
|||
r = card->reader->ops->reset(card->reader, do_cold_reset);
|
||||
/* invalidate cache */
|
||||
memset(&card->cache, 0, sizeof(card->cache));
|
||||
card->cache_valid = 0;
|
||||
card->cache.valid = 0;
|
||||
|
||||
r2 = sc_mutex_unlock(card->ctx, card->mutex);
|
||||
if (r2 != SC_SUCCESS) {
|
||||
|
@ -305,12 +305,12 @@ int sc_lock(sc_card_t *card)
|
|||
if (r == SC_ERROR_CARD_RESET || r == SC_ERROR_READER_REATTACHED) {
|
||||
/* invalidate cache */
|
||||
memset(&card->cache, 0, sizeof(card->cache));
|
||||
card->cache_valid = 0;
|
||||
card->cache.valid = 0;
|
||||
r = card->reader->ops->lock(card->reader);
|
||||
}
|
||||
}
|
||||
if (r == 0)
|
||||
card->cache_valid = 1;
|
||||
card->cache.valid = 1;
|
||||
}
|
||||
if (r == 0)
|
||||
card->lock_count++;
|
||||
|
@ -338,7 +338,7 @@ int sc_unlock(sc_card_t *card)
|
|||
#ifdef INVALIDATE_CARD_CACHE_IN_UNLOCK
|
||||
/* invalidate cache */
|
||||
memset(&card->cache, 0, sizeof(card->cache));
|
||||
card->cache_valid = 0;
|
||||
card->cache.valid = 0;
|
||||
sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "cache invalidated");
|
||||
#endif
|
||||
/* release reader lock */
|
||||
|
|
|
@ -220,6 +220,11 @@ typedef struct sc_app_info {
|
|||
|
||||
struct sc_card_cache {
|
||||
struct sc_path current_path;
|
||||
|
||||
struct sc_file *current_ef;
|
||||
struct sc_file *current_df;
|
||||
|
||||
int valid;
|
||||
};
|
||||
|
||||
#define SC_PROTO_T0 0x00000001
|
||||
|
@ -433,7 +438,6 @@ typedef struct sc_card {
|
|||
int max_pin_len;
|
||||
|
||||
struct sc_card_cache cache;
|
||||
int cache_valid;
|
||||
|
||||
sc_serial_number_t serialnr;
|
||||
|
||||
|
|
Loading…
Reference in New Issue