Skip to content

Commit

Permalink
Introduce SC_CARDCTL_GET_MODEL
Browse files Browse the repository at this point in the history
Card model can now alternatively be set by card driver via the
sc_card_ctl() SC_CARDCTL_GET_MODEL call and not just via the configuration file
  • Loading branch information
llogar committed Jun 24, 2024
1 parent 1685f37 commit f6b135f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/libopensc/card-eoi.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ static struct {
{384, {{1, 3, 132, 0, 34, -1}}}
};

static char *eoi_model = "ChipDocLite";

/* The description of the driver. */
static struct sc_card_driver eoi_drv =
{
Expand Down Expand Up @@ -417,6 +419,25 @@ static int eoi_pin_cmd(struct sc_card *card, struct sc_pin_cmd_data *data, int *
LOG_FUNC_RETURN(card->ctx, sc_get_iso7816_driver()->ops->pin_cmd(card, data, tries_left));
}

static int
eoi_card_ctl(sc_card_t *card, unsigned long cmd, void *ptr)
{
int r = SC_SUCCESS;

LOG_FUNC_CALLED(card->ctx);
switch (cmd) {
case SC_CARDCTL_GET_MODEL:
if (!ptr)
r = SC_ERROR_INVALID_ARGUMENTS;
else
*(char **)ptr = eoi_model;
break;
default:
r = sc_get_iso7816_driver()->ops->card_ctl(card, cmd, ptr);
}
LOG_FUNC_RETURN(card->ctx, r);
}

#define ALREADY_PROCESSED 0x80000000

static int eoi_set_security_env(struct sc_card *card, const struct sc_security_env *env, int se_num)
Expand Down Expand Up @@ -545,6 +566,7 @@ struct sc_card_driver *sc_get_eoi_driver(void)
eoi_ops.select_file = eoi_select_file;
eoi_ops.logout = eoi_logout;
eoi_ops.pin_cmd = eoi_pin_cmd;
eoi_ops.card_ctl = eoi_card_ctl;
eoi_ops.set_security_env = eoi_set_security_env;
eoi_ops.compute_signature = eoi_compute_signature;

Expand Down
1 change: 1 addition & 0 deletions src/libopensc/cardctl.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ enum {
SC_CARDCTL_GET_CHV_REFERENCE_IN_SE,
SC_CARDCTL_PKCS11_INIT_TOKEN,
SC_CARDCTL_PKCS11_INIT_PIN,
SC_CARDCTL_GET_MODEL,

/*
* Cryptoflex specific calls
Expand Down
2 changes: 2 additions & 0 deletions src/pkcs11/framework-pkcs15.c
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,8 @@ pkcs15_init_token_info(struct sc_pkcs15_card *p15card, CK_TOKEN_INFO_PTR pToken)

if (model)
strcpy_bp(pToken->model, model, sizeof(pToken->model));
else if (sc_card_ctl(p15card->card, SC_CARDCTL_GET_MODEL, &model) == SC_SUCCESS)
strcpy_bp(pToken->model, model, sizeof(pToken->model));
else if (p15card->flags & SC_PKCS15_CARD_FLAG_EMULATED)
strcpy_bp(pToken->model, "PKCS#15 emulated", sizeof(pToken->model));
else
Expand Down

0 comments on commit f6b135f

Please sign in to comment.