force_protocol cleanup from Martin Paljak <martin@paljak.pri.ee>
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@2029 c6295689-39f2-0310-b995-f0e70906c6a9
This commit is contained in:
parent
609fb32a25
commit
3d75aeeaff
|
@ -83,11 +83,6 @@ app default {
|
|||
#
|
||||
max_send_size = 252;
|
||||
max_recv_size = 252;
|
||||
# Sometimes T=0 vs T=1 isses are easy to track down, if card supports both
|
||||
# protocols, and one method works and another not. Force the connection to
|
||||
# use a specific protocol. Possible value: t0, t1, raw.
|
||||
# force_protocol = t0;
|
||||
#
|
||||
}
|
||||
|
||||
# What card drivers to load at start-up
|
||||
|
@ -180,6 +175,19 @@ app default {
|
|||
# atr = 11:22:33:44;
|
||||
#}
|
||||
}
|
||||
|
||||
# Estonian ID card and Micardo driver currently play together with T=0 only.
|
||||
# In theory only the 'cold' ATR should be specified, as T=0 will be the preferred
|
||||
# protocol once you boot it up with T=0, but be paranoid.
|
||||
|
||||
# Generic format: card_atr <hex encoded ATR (case-sensitive!)>
|
||||
# Only parameter currently understood is force_protocol
|
||||
card_atr 3b:6e:00:ff:45:73:74:45:49:44:20:76:65:72:20:31:2e:30 {
|
||||
force_protocol = t0;
|
||||
}
|
||||
card_atr 3b:fe:94:00:ff:80:b1:fa:45:1f:03:45:73:74:45:49:44:20:76:65:72:20:31:2e:30:43 {
|
||||
force_protocol = t0;
|
||||
}
|
||||
}
|
||||
|
||||
# For applications that use SCAM (pam_opensc, sia_opensc)
|
||||
|
|
|
@ -260,25 +260,7 @@ static void load_reader_driver_options(sc_context_t *ctx,
|
|||
driver->max_recv_size = SC_APDU_CHOP_SIZE;
|
||||
if (conf_block != NULL) {
|
||||
const scconf_list *list;
|
||||
const char *forcestr;
|
||||
|
||||
if (scconf_get_bool(conf_block, "apdu_fix", 0))
|
||||
driver->apdu_masquerade |= SC_APDU_MASQUERADE_4AS3;
|
||||
/* protocol force in action, addon by -mp */
|
||||
forcestr=scconf_get_str(conf_block, "force_protocol",NULL);
|
||||
if (forcestr){
|
||||
sc_debug(ctx,"Protocol force in action : %s",forcestr);
|
||||
if (!strcmp(forcestr,"t0"))
|
||||
driver->forced_protocol = SC_PROTO_T0;
|
||||
else if (!strcmp(forcestr,"t1"))
|
||||
driver->forced_protocol = SC_PROTO_T1;
|
||||
else if (!strcmp(forcestr,"raw"))
|
||||
driver->forced_protocol = SC_PROTO_RAW;
|
||||
else
|
||||
sc_error(ctx,"Unknown protocol: %s in force_protocol; ignored.",forcestr);
|
||||
} else
|
||||
driver->forced_protocol = 0;
|
||||
|
||||
list = scconf_find_list(conf_block, "apdu_masquerade");
|
||||
if (list)
|
||||
driver->apdu_masquerade = 0;
|
||||
|
|
|
@ -260,7 +260,6 @@ struct sc_reader_driver {
|
|||
|
||||
size_t max_send_size, max_recv_size;
|
||||
int apdu_masquerade;
|
||||
unsigned int forced_protocol;
|
||||
void *dll;
|
||||
};
|
||||
#define SC_APDU_MASQUERADE_NONE 0x00
|
||||
|
|
|
@ -379,12 +379,13 @@ static int pcsc_wait_for_event(struct sc_reader **readers,
|
|||
|
||||
static int pcsc_connect(struct sc_reader *reader, struct sc_slot_info *slot)
|
||||
{
|
||||
DWORD active_proto, protocol;
|
||||
DWORD active_proto, protocol = SCARD_PROTOCOL_ANY;
|
||||
SCARDHANDLE card_handle;
|
||||
LONG rv;
|
||||
struct pcsc_private_data *priv = GET_PRIV_DATA(reader);
|
||||
struct pcsc_slot_data *pslot = GET_SLOT_DATA(slot);
|
||||
int r;
|
||||
scconf_block *conf_block = NULL;
|
||||
int r, i;
|
||||
|
||||
r = refresh_slot_attributes(reader, slot);
|
||||
if (r)
|
||||
|
@ -393,11 +394,39 @@ static int pcsc_connect(struct sc_reader *reader, struct sc_slot_info *slot)
|
|||
return SC_ERROR_CARD_NOT_PRESENT;
|
||||
|
||||
/* force a protocol, addon by -mp */
|
||||
if (reader->driver->forced_protocol) {
|
||||
protocol = opensc_proto_to_pcsc(reader->driver->forced_protocol);
|
||||
} else
|
||||
protocol = SCARD_PROTOCOL_ANY;
|
||||
for (i = 0; reader->ctx->conf_blocks[i] != NULL; i++) {
|
||||
scconf_block **blocks;
|
||||
char name[3 * SC_MAX_ATR_SIZE];
|
||||
|
||||
r = sc_bin_to_hex(slot->atr, slot->atr_len, name, sizeof(name), ':');
|
||||
assert(r == 0);
|
||||
sc_debug(reader->ctx, "Looking for a card_atr %s", name);
|
||||
blocks = scconf_find_blocks(reader->ctx->conf, reader->ctx->conf_blocks[i],
|
||||
"card_atr", name);
|
||||
conf_block = blocks[0];
|
||||
free(blocks);
|
||||
if (conf_block != NULL)
|
||||
break;
|
||||
}
|
||||
|
||||
if (conf_block != NULL) {
|
||||
const char *forcestr;
|
||||
|
||||
sc_debug(reader->ctx, "Found card_atr with current atr");
|
||||
forcestr = scconf_get_str(conf_block, "force_protocol", NULL);
|
||||
if (forcestr) {
|
||||
sc_debug(reader->ctx,"Protocol force in action: %s", forcestr);
|
||||
if (!strcmp(forcestr,"t0"))
|
||||
protocol = SCARD_PROTOCOL_T0;
|
||||
else if (!strcmp(forcestr,"t1"))
|
||||
protocol = SCARD_PROTOCOL_T1;
|
||||
else if (!strcmp(forcestr,"raw"))
|
||||
protocol = SCARD_PROTOCOL_RAW;
|
||||
else
|
||||
sc_error(reader->ctx,"Unknown force_protocol: %s (Ignored)", forcestr);
|
||||
}
|
||||
}
|
||||
|
||||
rv = SCardConnect(priv->pcsc_ctx, priv->reader_name,
|
||||
SCARD_SHARE_SHARED, protocol, &card_handle, &active_proto);
|
||||
if (rv != 0) {
|
||||
|
|
Loading…
Reference in New Issue