tools: remove slots; implement change in sc_disconnect_card(); convert util_connect_card()/--wait to support the changes in r3931
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@3933 c6295689-39f2-0310-b995-f0e70906c6a9
This commit is contained in:
parent
e191142d04
commit
5a0cc50123
|
@ -40,7 +40,7 @@ pkcs15_init_LDADD = $(OPTIONAL_OPENSSL_LIBS) \
|
|||
$(top_builddir)/src/pkcs15init/libpkcs15init.la
|
||||
cardos_tool_SOURCES = cardos-tool.c util.c
|
||||
cardos_tool_LDADD = $(OPTIONAL_OPENSSL_LIBS)
|
||||
eidenv_SOURCES = eidenv.c
|
||||
eidenv_SOURCES = eidenv.c util.c
|
||||
netkey_tool_SOURCES = netkey-tool.c
|
||||
netkey_tool_LDADD = $(OPTIONAL_OPENSSL_LIBS)
|
||||
rutoken_tool_SOURCES = rutoken-tool.c util.c
|
||||
|
|
|
@ -44,8 +44,9 @@
|
|||
|
||||
static const char *app_name = "cardos-tool";
|
||||
|
||||
static int opt_reader = -1, opt_debug = 0, opt_wait = 0;
|
||||
static int opt_debug = 0, opt_wait = 0;
|
||||
static int verbose = 0;
|
||||
static char *opt_reader = NULL;
|
||||
|
||||
static const struct option options[] = {
|
||||
{"info", 0, NULL, 'i'},
|
||||
|
@ -379,7 +380,7 @@ static int cardos_sm4h(const unsigned char *in, size_t inlen, unsigned char
|
|||
unsigned char *mac_input, *enc_input;
|
||||
DES_key_schedule ks_a, ks_b;
|
||||
DES_cblock des_in,des_out;
|
||||
int i,j;
|
||||
unsigned int i,j;
|
||||
|
||||
if (keylen != 16) {
|
||||
printf("key has wrong size, need 16 bytes, got %zd. aborting.\n",
|
||||
|
@ -1098,7 +1099,7 @@ int main(int argc, char *const argv[])
|
|||
action_count++;
|
||||
break;
|
||||
case 'r':
|
||||
opt_reader = atoi(optarg);
|
||||
opt_reader = optarg;
|
||||
break;
|
||||
case 'v':
|
||||
verbose++;
|
||||
|
@ -1137,7 +1138,7 @@ int main(int argc, char *const argv[])
|
|||
}
|
||||
}
|
||||
|
||||
err = util_connect_card(ctx, &card, opt_reader, 0, opt_wait, verbose);
|
||||
err = util_connect_card(ctx, &card, opt_reader, opt_wait, verbose);
|
||||
if (err)
|
||||
goto end;
|
||||
|
||||
|
@ -1162,7 +1163,7 @@ int main(int argc, char *const argv[])
|
|||
end:
|
||||
if (card) {
|
||||
sc_unlock(card);
|
||||
sc_disconnect_card(card, 0);
|
||||
sc_disconnect_card(card);
|
||||
}
|
||||
if (ctx)
|
||||
sc_release_context(ctx);
|
||||
|
|
|
@ -1180,14 +1180,14 @@ int main(int argc, char * const argv[])
|
|||
err = 1;
|
||||
goto end;
|
||||
}
|
||||
if (sc_detect_card_presence(screader, 0) <= 0) {
|
||||
if (sc_detect_card_presence(screader) <= 0) {
|
||||
fprintf(stderr, "Card not present.\n");
|
||||
err = 3;
|
||||
goto end;
|
||||
}
|
||||
if (verbose)
|
||||
fprintf(stderr, "Connecting to card in reader %s...\n", screader->name);
|
||||
r = sc_connect_card(screader, 0, &card);
|
||||
r = sc_connect_card(screader, &card);
|
||||
if (r) {
|
||||
fprintf(stderr, "Failed to connect to card: %s\n", sc_strerror(r));
|
||||
err = 1;
|
||||
|
@ -1237,7 +1237,7 @@ int main(int argc, char * const argv[])
|
|||
end:
|
||||
if (card) {
|
||||
sc_unlock(card);
|
||||
sc_disconnect_card(card, 0);
|
||||
sc_disconnect_card(card);
|
||||
}
|
||||
if (ctx)
|
||||
sc_release_context(ctx);
|
||||
|
|
|
@ -35,17 +35,19 @@
|
|||
#include "../libopensc/cards.h"
|
||||
#include "../libopensc/esteid.h"
|
||||
|
||||
static int reader_num = 0;
|
||||
static char *opt_reader = NULL;
|
||||
static int stats = 0;
|
||||
static int opt_wait = 0;
|
||||
static char *exec_program = NULL;
|
||||
static int exit_status = EXIT_FAILURE;
|
||||
|
||||
static const struct option options[] = {
|
||||
{"reader", required_argument, NULL, 'r'},
|
||||
{"print", no_argument, NULL, 'n'},
|
||||
{"print", no_argument, NULL, 'p'},
|
||||
{"exec", required_argument, NULL, 'x'},
|
||||
{"stats", no_argument, NULL, 't'},
|
||||
{"help", no_argument, NULL, 'h'},
|
||||
{"wait", no_argument, NULL, 'w'},
|
||||
{"version", no_argument, NULL, 'V'},
|
||||
{NULL, 0, NULL, 0}
|
||||
};
|
||||
|
@ -93,7 +95,8 @@ static void show_help(void)
|
|||
"-h --help - show this text and exit\n"
|
||||
"-v --version - show version and exit\n"
|
||||
"-r --reader - the reader to use\n"
|
||||
"-n --print - print the datafile\n"
|
||||
"-w --wait - wait for a card to be inserted\n"
|
||||
"-p --print - print the datafile\n"
|
||||
"-t --stats - show usage counts of keys\n"
|
||||
"-x --exec - execute a program with data in env vars.\n");
|
||||
}
|
||||
|
@ -102,11 +105,11 @@ static void decode_options(int argc, char **argv)
|
|||
{
|
||||
int c;
|
||||
|
||||
while ((c = getopt_long(argc, argv,"ptr:x:hV", options, (int *) 0)) != EOF) {
|
||||
while ((c = getopt_long(argc, argv,"pwtr:x:hV", options, (int *) 0)) != EOF) {
|
||||
|
||||
switch (c) {
|
||||
case 'r':
|
||||
reader_num = atoi(optarg);
|
||||
opt_reader = optarg;
|
||||
break;
|
||||
case 't':
|
||||
stats = !stats;
|
||||
|
@ -120,7 +123,10 @@ static void decode_options(int argc, char **argv)
|
|||
show_help();
|
||||
exit(EXIT_SUCCESS);
|
||||
break;
|
||||
case 'n':
|
||||
case 'p':
|
||||
break;
|
||||
case 'w':
|
||||
opt_wait = 1;
|
||||
break;
|
||||
case 'V':
|
||||
show_version();
|
||||
|
@ -375,7 +381,6 @@ int main(int argc, char **argv)
|
|||
{
|
||||
sc_context_t *ctx = NULL;
|
||||
sc_context_param_t ctx_param;
|
||||
sc_reader_t *reader = NULL;
|
||||
sc_card_t *card = NULL;
|
||||
int r;
|
||||
|
||||
|
@ -393,13 +398,7 @@ int main(int argc, char **argv)
|
|||
sc_strerror(r));
|
||||
return 1;
|
||||
}
|
||||
if (reader_num > (int)sc_ctx_get_reader_count(ctx)) {
|
||||
fprintf(stderr, "Illegal reader number. Only %d reader(s) configured.\n", sc_ctx_get_reader_count(ctx));
|
||||
return 1;
|
||||
}
|
||||
reader = sc_ctx_get_reader(ctx, (unsigned int)reader_num);
|
||||
|
||||
r = sc_connect_card(reader, 0, &card);
|
||||
r = util_connect_card(ctx, &card, opt_reader, opt_wait, 0);
|
||||
if (r) {
|
||||
fprintf(stderr, "Failed to connect to card: %s\n", sc_strerror(r));
|
||||
return 1;
|
||||
|
@ -424,7 +423,7 @@ int main(int argc, char **argv)
|
|||
if (exec_program) {
|
||||
char *const largv[] = {exec_program, NULL};
|
||||
sc_unlock(card);
|
||||
sc_disconnect_card(card, 0);
|
||||
sc_disconnect_card(card);
|
||||
sc_release_context(ctx);
|
||||
execv(exec_program, largv);
|
||||
/* we should not get here */
|
||||
|
@ -434,7 +433,7 @@ int main(int argc, char **argv)
|
|||
|
||||
out:
|
||||
sc_unlock(card);
|
||||
sc_disconnect_card(card, 0);
|
||||
sc_disconnect_card(card);
|
||||
sc_release_context(ctx);
|
||||
exit(exit_status);
|
||||
}
|
||||
|
|
|
@ -559,19 +559,13 @@ int main(
|
|||
exit(1);
|
||||
}
|
||||
|
||||
printf("%d Reader detected\n", sc_ctx_get_reader_count(ctx));
|
||||
for(i=0; i < sc_ctx_get_reader_count(ctx); ++i){
|
||||
sc_reader_t *myreader = sc_ctx_get_reader(ctx, i);
|
||||
printf("%lu: %s, Driver: %s, %d Slot(s)\n",
|
||||
(unsigned long) i, myreader->name,
|
||||
myreader->driver->name, myreader->slot_count);
|
||||
}
|
||||
printf("%d Readers detected\n", sc_ctx_get_reader_count(ctx));
|
||||
if(reader < 0 || reader >= (int)sc_ctx_get_reader_count(ctx)){
|
||||
fprintf(stderr,"Cannot open reader %d\n", reader);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if((r = sc_connect_card(sc_ctx_get_reader(ctx, 0), 0, &card))<0){
|
||||
if((r = sc_connect_card(sc_ctx_get_reader(ctx, 0), &card))<0){
|
||||
fprintf(stderr,"Connect-Card failed: %s\n", sc_strerror(r));
|
||||
exit(1);
|
||||
}
|
||||
|
@ -621,7 +615,7 @@ int main(
|
|||
if(do_unblock+do_change+do_nullpin+do_readcert==0) show_certs(card);
|
||||
|
||||
sc_unlock(card);
|
||||
sc_disconnect_card(card,0);
|
||||
sc_disconnect_card(card);
|
||||
sc_release_context(ctx);
|
||||
|
||||
exit(0);
|
||||
|
|
|
@ -38,8 +38,9 @@
|
|||
|
||||
static const char *app_name = "opensc-explorer";
|
||||
|
||||
static int opt_reader = -1, opt_wait = 0, verbose = 0;
|
||||
static int opt_wait = 0, verbose = 0;
|
||||
static const char *opt_driver = NULL;
|
||||
static const char *opt_reader = NULL;
|
||||
|
||||
static sc_file_t *current_file = NULL;
|
||||
static sc_path_t current_path;
|
||||
|
@ -74,7 +75,7 @@ static void die(int ret)
|
|||
sc_file_free(current_file);
|
||||
if (card) {
|
||||
sc_unlock(card);
|
||||
sc_disconnect_card(card, 0);
|
||||
sc_disconnect_card(card);
|
||||
}
|
||||
if (ctx)
|
||||
sc_release_context(ctx);
|
||||
|
@ -635,7 +636,7 @@ static int do_verify(int argc, char **argv)
|
|||
}
|
||||
|
||||
if (argc < 2) {
|
||||
if (!(card->reader->slot[0].capabilities & SC_SLOT_CAP_PIN_PAD)) {
|
||||
if (!(card->reader->capabilities & SC_READER_CAP_PIN_PAD)) {
|
||||
printf("Card reader or driver doesn't support PIN PAD\n");
|
||||
return -1;
|
||||
}
|
||||
|
@ -1567,7 +1568,7 @@ int main(int argc, char * const argv[])
|
|||
util_print_usage_and_die(app_name, options, option_help);
|
||||
switch (c) {
|
||||
case 'r':
|
||||
opt_reader = atoi(optarg);
|
||||
opt_reader = optarg;
|
||||
break;
|
||||
case 'c':
|
||||
opt_driver = optarg;
|
||||
|
@ -1602,7 +1603,7 @@ int main(int argc, char * const argv[])
|
|||
}
|
||||
}
|
||||
|
||||
err = util_connect_card(ctx, &card, opt_reader, 0, opt_wait, 0);
|
||||
err = util_connect_card(ctx, &card, opt_reader, opt_wait, 0);
|
||||
if (err)
|
||||
goto end;
|
||||
|
||||
|
|
|
@ -36,9 +36,9 @@
|
|||
|
||||
static const char *app_name = "opensc-tool";
|
||||
|
||||
static int opt_reader = -1,
|
||||
opt_wait = 0;
|
||||
static int opt_wait = 0;
|
||||
static char ** opt_apdus;
|
||||
static char *opt_reader;
|
||||
static int opt_apdu_count = 0;
|
||||
static int verbose = 0;
|
||||
|
||||
|
@ -262,7 +262,7 @@ static int list_readers(void)
|
|||
for (i = 0; i < rcount; i++) {
|
||||
sc_reader_t *screader = sc_ctx_get_reader(ctx, i);
|
||||
printf("%-7d%-11s%-10s%s\n", i, screader->driver->short_name,
|
||||
screader->slot[0].capabilities & SC_SLOT_CAP_PIN_PAD ? "PINpad":"",
|
||||
screader->capabilities & SC_READER_CAP_PIN_PAD ? "PINpad":"",
|
||||
screader->name);
|
||||
}
|
||||
return 0;
|
||||
|
@ -616,7 +616,7 @@ int main(int argc, char * const argv[])
|
|||
action_count++;
|
||||
break;
|
||||
case 'r':
|
||||
opt_reader = atoi(optarg);
|
||||
opt_reader = optarg;
|
||||
break;
|
||||
case 'v':
|
||||
verbose++;
|
||||
|
@ -689,7 +689,7 @@ int main(int argc, char * const argv[])
|
|||
}
|
||||
}
|
||||
|
||||
err = util_connect_card(ctx, &card, opt_reader, 0, opt_wait, verbose);
|
||||
err = util_connect_card(ctx, &card, opt_reader, opt_wait, verbose);
|
||||
if (err)
|
||||
goto end;
|
||||
|
||||
|
@ -730,7 +730,7 @@ int main(int argc, char * const argv[])
|
|||
end:
|
||||
if (card) {
|
||||
sc_unlock(card);
|
||||
sc_disconnect_card(card, 0);
|
||||
sc_disconnect_card(card);
|
||||
}
|
||||
if (ctx)
|
||||
sc_release_context(ctx);
|
||||
|
|
|
@ -43,9 +43,9 @@
|
|||
|
||||
static const char *app_name = "piv-tool";
|
||||
|
||||
static int opt_reader = -1,
|
||||
opt_wait = 0;
|
||||
static int opt_wait = 0;
|
||||
static char ** opt_apdus;
|
||||
static char * opt_reader;
|
||||
static int opt_apdu_count = 0;
|
||||
static int verbose = 0;
|
||||
|
||||
|
@ -426,7 +426,7 @@ int main(int argc, char * const argv[])
|
|||
out_file = optarg;
|
||||
break;
|
||||
case 'r':
|
||||
opt_reader = atoi(optarg);
|
||||
opt_reader = optarg;
|
||||
break;
|
||||
case 'v':
|
||||
verbose++;
|
||||
|
@ -475,7 +475,7 @@ int main(int argc, char * const argv[])
|
|||
}
|
||||
}
|
||||
|
||||
err = util_connect_card(ctx, &card, opt_reader, 0, opt_wait, verbose);
|
||||
err = util_connect_card(ctx, &card, opt_reader, opt_wait, verbose);
|
||||
if (err)
|
||||
goto end;
|
||||
|
||||
|
@ -517,7 +517,7 @@ end:
|
|||
BIO_free(bp);
|
||||
if (card) {
|
||||
sc_unlock(card);
|
||||
sc_disconnect_card(card, 0);
|
||||
sc_disconnect_card(card);
|
||||
}
|
||||
if (ctx)
|
||||
sc_release_context(ctx);
|
||||
|
|
|
@ -40,7 +40,8 @@
|
|||
|
||||
static const char *app_name = "pkcs15-crypt";
|
||||
|
||||
static int opt_reader = -1, verbose = 0, opt_wait = 0, opt_raw = 0;
|
||||
static int verbose = 0, opt_wait = 0, opt_raw = 0;
|
||||
static char * opt_reader;
|
||||
static char * opt_pincode = NULL, * opt_key_id = NULL;
|
||||
static char * opt_input = NULL, * opt_output = NULL;
|
||||
static int opt_crypt_flags = 0;
|
||||
|
@ -466,7 +467,7 @@ static int get_key(unsigned int usage, sc_pkcs15_object_t **result)
|
|||
|
||||
pincode = get_pin(pin);
|
||||
if (((pincode == NULL || *pincode == '\0')) &&
|
||||
!(p15card->card->slot->capabilities & SC_SLOT_CAP_PIN_PAD))
|
||||
!(p15card->card->reader->capabilities & SC_READER_CAP_PIN_PAD))
|
||||
return 5;
|
||||
|
||||
r = sc_pkcs15_verify_pin(p15card, (struct sc_pkcs15_pin_info *) pin->data,
|
||||
|
@ -513,7 +514,7 @@ int main(int argc, char * const argv[])
|
|||
action_count++;
|
||||
break;
|
||||
case 'r':
|
||||
opt_reader = atoi(optarg);
|
||||
opt_reader = optarg;
|
||||
break;
|
||||
case 'i':
|
||||
opt_input = optarg;
|
||||
|
@ -571,7 +572,7 @@ int main(int argc, char * const argv[])
|
|||
if (verbose > 1)
|
||||
ctx->debug = verbose-1;
|
||||
|
||||
err = util_connect_card(ctx, &card, opt_reader, 0, opt_wait, verbose);
|
||||
err = util_connect_card(ctx, &card, opt_reader, opt_wait, verbose);
|
||||
if (err)
|
||||
goto end;
|
||||
|
||||
|
@ -607,7 +608,7 @@ end:
|
|||
#if 1
|
||||
sc_unlock(card);
|
||||
#endif
|
||||
sc_disconnect_card(card, 0);
|
||||
sc_disconnect_card(card);
|
||||
}
|
||||
if (ctx)
|
||||
sc_release_context(ctx);
|
||||
|
|
|
@ -79,7 +79,7 @@ typedef int (*pkcs15_encoder)(sc_context_t *,
|
|||
struct sc_pkcs15_card *, u8 **, size_t *);
|
||||
|
||||
/* Local functions */
|
||||
static int open_reader_and_card(int);
|
||||
static int open_reader_and_card(char *);
|
||||
static int do_assert_pristine(sc_card_t *);
|
||||
static int do_erase(sc_card_t *, struct sc_profile *);
|
||||
static int do_delete_objects(struct sc_profile *, unsigned int myopt_delete_flags);
|
||||
|
@ -310,9 +310,9 @@ struct secret {
|
|||
static sc_context_t * ctx = NULL;
|
||||
static sc_card_t * card = NULL;
|
||||
static struct sc_pkcs15_card * p15card = NULL;
|
||||
static char * opt_reader = NULL;
|
||||
static unsigned int opt_actions;
|
||||
static int opt_reader = -1,
|
||||
opt_extractable = 0,
|
||||
static int opt_extractable = 0,
|
||||
opt_unprotected = 0,
|
||||
opt_authority = 0,
|
||||
opt_softkeygen = 0,
|
||||
|
@ -489,14 +489,14 @@ out:
|
|||
}
|
||||
if (card) {
|
||||
sc_unlock(card);
|
||||
sc_disconnect_card(card, 0);
|
||||
sc_disconnect_card(card);
|
||||
}
|
||||
sc_release_context(ctx);
|
||||
return r < 0? 1 : 0;
|
||||
}
|
||||
|
||||
static int
|
||||
open_reader_and_card(int reader)
|
||||
open_reader_and_card(char *reader)
|
||||
{
|
||||
int r;
|
||||
sc_context_param_t ctx_param;
|
||||
|
@ -515,7 +515,7 @@ open_reader_and_card(int reader)
|
|||
ctx->debug_file = stderr;
|
||||
}
|
||||
|
||||
if (util_connect_card(ctx, &card, reader, 0, opt_wait, verbose))
|
||||
if (util_connect_card(ctx, &card, reader, opt_wait, verbose))
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
|
@ -2524,7 +2524,7 @@ handle_option(const struct option *opt)
|
|||
opt_card_profile = optarg;
|
||||
break;
|
||||
case 'r':
|
||||
opt_reader = atoi(optarg);
|
||||
opt_reader = optarg;
|
||||
break;
|
||||
case 'u':
|
||||
parse_x509_usage(optarg, &opt_x509_usage);
|
||||
|
|
|
@ -42,9 +42,10 @@ typedef unsigned __int32 uint32_t;
|
|||
|
||||
static const char *app_name = "pkcs15-tool";
|
||||
|
||||
static int opt_reader = -1, opt_wait = 0;
|
||||
static int opt_wait = 0;
|
||||
static int opt_no_cache = 0;
|
||||
static char * opt_auth_id;
|
||||
static char * opt_reader = NULL;
|
||||
static char * opt_cert = NULL;
|
||||
static char * opt_data = NULL;
|
||||
static char * opt_pubkey = NULL;
|
||||
|
@ -987,7 +988,7 @@ static int unblock_pin(void)
|
|||
u8 *pin, *puk;
|
||||
int r, pinpad_present = 0;
|
||||
|
||||
pinpad_present = p15card->card->reader->slot[0].capabilities & SC_SLOT_CAP_PIN_PAD;
|
||||
pinpad_present = p15card->card->reader->capabilities & SC_READER_CAP_PIN_PAD;
|
||||
|
||||
if (!(pin_obj = get_pin_info()))
|
||||
return 2;
|
||||
|
@ -1050,7 +1051,7 @@ static int change_pin(void)
|
|||
u8 *pincode, *newpin;
|
||||
int r, pinpad_present = 0;
|
||||
|
||||
pinpad_present = p15card->card->reader->slot[0].capabilities & SC_SLOT_CAP_PIN_PAD;
|
||||
pinpad_present = p15card->card->reader->capabilities & SC_READER_CAP_PIN_PAD;
|
||||
|
||||
if (!(pin_obj = get_pin_info()))
|
||||
return 2;
|
||||
|
@ -1516,7 +1517,7 @@ int main(int argc, char * const argv[])
|
|||
action_count++;
|
||||
break;
|
||||
case OPT_READER:
|
||||
opt_reader = atoi(optarg);
|
||||
opt_reader = optarg;
|
||||
break;
|
||||
case OPT_PIN:
|
||||
opt_pin = (u8 *) optarg;
|
||||
|
@ -1559,7 +1560,7 @@ int main(int argc, char * const argv[])
|
|||
if (verbose > 1 )
|
||||
ctx->debug = verbose-1;
|
||||
|
||||
err = util_connect_card(ctx, &card, opt_reader, 0, opt_wait, verbose);
|
||||
err = util_connect_card(ctx, &card, opt_reader, opt_wait, verbose);
|
||||
if (err)
|
||||
goto end;
|
||||
|
||||
|
@ -1659,7 +1660,7 @@ end:
|
|||
sc_pkcs15_unbind(p15card);
|
||||
if (card) {
|
||||
sc_unlock(card);
|
||||
sc_disconnect_card(card, 0);
|
||||
sc_disconnect_card(card);
|
||||
}
|
||||
if (ctx)
|
||||
sc_release_context(ctx);
|
||||
|
|
|
@ -389,9 +389,9 @@ static int generate_gostkey(sc_card_t *card, u8 keyid, u8 keyoptions)
|
|||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
int opt_reader = -1;
|
||||
int opt_wait = 0;
|
||||
const char *opt_pin = NULL;
|
||||
const char *opt_reader = NULL;
|
||||
int opt_key = 0;
|
||||
int opt_is_iv = 0;
|
||||
u8 opt_keytype = SC_RUTOKEN_OPTIONS_GOST_CRYPT_PZ;
|
||||
|
@ -416,7 +416,7 @@ int main(int argc, char* argv[])
|
|||
case '?':
|
||||
util_print_usage_and_die(app_name, options, option_help);
|
||||
case 'r':
|
||||
opt_reader = atoi(optarg);
|
||||
opt_reader = optarg;
|
||||
break;
|
||||
case 'w':
|
||||
opt_wait = 1;
|
||||
|
@ -488,7 +488,7 @@ int main(int argc, char* argv[])
|
|||
}
|
||||
ctx->debug = opt_debug;
|
||||
|
||||
if (util_connect_card(ctx, &card, opt_reader, 0, opt_wait, opt_debug) != 0)
|
||||
if (util_connect_card(ctx, &card, opt_reader, opt_wait, opt_debug) != 0)
|
||||
err = -1;
|
||||
|
||||
if (err == 0 && opt_pin) {
|
||||
|
@ -543,7 +543,7 @@ int main(int argc, char* argv[])
|
|||
if (card) {
|
||||
/* sc_lock and sc_connect_card in util_connect_card */
|
||||
sc_unlock(card);
|
||||
sc_disconnect_card(card, 0);
|
||||
sc_disconnect_card(card);
|
||||
}
|
||||
if (ctx)
|
||||
sc_release_context(ctx);
|
||||
|
|
|
@ -8,73 +8,57 @@
|
|||
#include "util.h"
|
||||
|
||||
int util_connect_card(sc_context_t *ctx, sc_card_t **cardp,
|
||||
int reader_id, int slot_id, int wait, int verbose)
|
||||
char *reader_id, int wait, int verbose)
|
||||
{
|
||||
sc_reader_t *reader;
|
||||
sc_reader_t *reader, *found;
|
||||
sc_card_t *card;
|
||||
int r;
|
||||
int r, tmp_reader_num;
|
||||
|
||||
if (wait) {
|
||||
sc_reader_t *readers[16];
|
||||
int slots[16];
|
||||
unsigned int i;
|
||||
int j, k, found;
|
||||
unsigned int event;
|
||||
|
||||
for (i = k = 0; i < sc_ctx_get_reader_count(ctx); i++) {
|
||||
if (reader_id >= 0 && (unsigned int)reader_id != i)
|
||||
continue;
|
||||
reader = sc_ctx_get_reader(ctx, i);
|
||||
for (j = 0; j < reader->slot_count; j++, k++) {
|
||||
readers[k] = reader;
|
||||
slots[k] = j;
|
||||
}
|
||||
}
|
||||
|
||||
printf("Waiting for card to be inserted...\n");
|
||||
r = sc_wait_for_event(readers, slots, k,
|
||||
SC_EVENT_CARD_INSERTED,
|
||||
&found, &event, -1);
|
||||
r = sc_wait_for_event(ctx, SC_EVENT_CARD_INSERTED, &found, &event, -1);
|
||||
if (r < 0) {
|
||||
fprintf(stderr,
|
||||
"Error while waiting for card: %s\n",
|
||||
sc_strerror(r));
|
||||
fprintf(stderr, "Error while waiting for card: %s\n", sc_strerror(r));
|
||||
return 3;
|
||||
}
|
||||
|
||||
reader = readers[found];
|
||||
slot_id = slots[found];
|
||||
reader = found;
|
||||
} else {
|
||||
if (sc_ctx_get_reader_count(ctx) == 0) {
|
||||
fprintf(stderr,
|
||||
"No smart card readers found.\n");
|
||||
return 1;
|
||||
}
|
||||
if (reader_id < 0) {
|
||||
if (!reader_id) {
|
||||
unsigned int i;
|
||||
/* Automatically try to skip to a reader with a card if reader not specified */
|
||||
for (i = 0; i < sc_ctx_get_reader_count(ctx); i++) {
|
||||
reader = sc_ctx_get_reader(ctx, i);
|
||||
if (sc_detect_card_presence(reader, 0) & SC_SLOT_CARD_PRESENT) {
|
||||
reader_id = i;
|
||||
if (sc_detect_card_presence(reader) & SC_READER_CARD_PRESENT) {
|
||||
fprintf(stderr, "Using reader with a card: %s\n", reader->name);
|
||||
goto autofound;
|
||||
}
|
||||
}
|
||||
reader_id = 0;
|
||||
/* If no reader had a card, default to the first reader */
|
||||
reader = sc_ctx_get_reader(ctx, 0);
|
||||
} else {
|
||||
/* Get the reader by name if possible */
|
||||
if (!sscanf(reader_id, "%d", &tmp_reader_num)) {
|
||||
reader = sc_ctx_get_reader_by_name(ctx, reader_id);
|
||||
} else {
|
||||
reader = sc_ctx_get_reader(ctx, tmp_reader_num);
|
||||
}
|
||||
}
|
||||
autofound:
|
||||
if ((unsigned int)reader_id >= sc_ctx_get_reader_count(ctx)) {
|
||||
if (!reader) {
|
||||
fprintf(stderr,
|
||||
"Illegal reader number. "
|
||||
"Only %d reader(s) configured.\n",
|
||||
sc_ctx_get_reader_count(ctx));
|
||||
"Reader \"%s\" not found (%d reader(s) detected)\n", reader_id, sc_ctx_get_reader_count(ctx));
|
||||
return 1;
|
||||
}
|
||||
|
||||
reader = sc_ctx_get_reader(ctx, reader_id);
|
||||
slot_id = 0;
|
||||
if (sc_detect_card_presence(reader, 0) <= 0) {
|
||||
if (sc_detect_card_presence(reader) <= 0) {
|
||||
fprintf(stderr, "Card not present.\n");
|
||||
return 3;
|
||||
}
|
||||
|
@ -82,7 +66,7 @@ autofound:
|
|||
|
||||
if (verbose)
|
||||
printf("Connecting to card in reader %s...\n", reader->name);
|
||||
if ((r = sc_connect_card(reader, slot_id, &card)) < 0) {
|
||||
if ((r = sc_connect_card(reader, &card)) < 0) {
|
||||
fprintf(stderr,
|
||||
"Failed to connect to card: %s\n",
|
||||
sc_strerror(r));
|
||||
|
@ -96,7 +80,7 @@ autofound:
|
|||
fprintf(stderr,
|
||||
"Failed to lock card: %s\n",
|
||||
sc_strerror(r));
|
||||
sc_disconnect_card(card, 0);
|
||||
sc_disconnect_card(card);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -33,8 +33,7 @@ void util_warn(const char *fmt, ...);
|
|||
void util_error(const char *fmt, ...);
|
||||
void util_fatal(const char *fmt, ...);
|
||||
/* All singing all dancing card connect routine */
|
||||
int util_connect_card(struct sc_context *, struct sc_card **,
|
||||
int reader_id, int slot_id, int wait, int verbose);
|
||||
int util_connect_card(struct sc_context *, struct sc_card **, char *reader_id, int wait, int verbose);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -102,7 +102,7 @@ static int verify_pin(sc_card_t *card, int pin_reference, char *pin_value)
|
|||
|
||||
data.flags = SC_PIN_CMD_NEED_PADDING;
|
||||
|
||||
if (card->slot->capabilities & SC_SLOT_CAP_PIN_PAD)
|
||||
if (card->reader->capabilities & SC_READER_CAP_PIN_PAD)
|
||||
{
|
||||
printf("Please enter PIN on the reader's pin pad.\n");
|
||||
data.pin1.prompt = "Please enter PIN";
|
||||
|
@ -155,7 +155,7 @@ static int change_pin(sc_card_t *card,
|
|||
|
||||
data.flags = SC_PIN_CMD_NEED_PADDING;
|
||||
|
||||
if (card->slot->capabilities & SC_SLOT_CAP_PIN_PAD)
|
||||
if (card->reader->capabilities & SC_READER_CAP_PIN_PAD)
|
||||
{
|
||||
printf("Please enter PIN on the reader's pin pad.\n");
|
||||
data.pin1.prompt = "Please enter PIN";
|
||||
|
@ -213,7 +213,7 @@ static int debloque_pin(sc_card_t *card,
|
|||
|
||||
data.flags = SC_PIN_CMD_NEED_PADDING;
|
||||
|
||||
if (card->slot->capabilities & SC_SLOT_CAP_PIN_PAD)
|
||||
if (card->reader->capabilities & SC_READER_CAP_PIN_PAD)
|
||||
{
|
||||
printf("Please enter PIN on the reader's pin pad.\n");
|
||||
data.pin1.prompt = "Please enter PIN";
|
||||
|
@ -497,9 +497,9 @@ int main(int argc, char *argv[])
|
|||
for(i = 0; i<sc_ctx_get_reader_count(ctx); i++)
|
||||
{
|
||||
lecteur = sc_ctx_get_reader(ctx, i);
|
||||
if(sc_detect_card_presence(lecteur, 0))
|
||||
if(sc_detect_card_presence(lecteur))
|
||||
{
|
||||
r = sc_connect_card(lecteur, 0, &card);
|
||||
r = sc_connect_card(lecteur, &card);
|
||||
if(r>=0)
|
||||
{
|
||||
printf("card->name = %s\n", card->name);
|
||||
|
@ -508,7 +508,7 @@ int main(int argc, char *argv[])
|
|||
card_presente = 1;
|
||||
break;
|
||||
}
|
||||
sc_disconnect_card(card,0);
|
||||
sc_disconnect_card(card);
|
||||
card = NULL;
|
||||
}
|
||||
}
|
||||
|
@ -519,14 +519,14 @@ int main(int argc, char *argv[])
|
|||
if(no_lecteur < sc_ctx_get_reader_count(ctx))
|
||||
{
|
||||
lecteur = sc_ctx_get_reader(ctx, no_lecteur);
|
||||
r = sc_connect_card(lecteur, 0, &card);
|
||||
r = sc_connect_card(lecteur, &card);
|
||||
if(r>=0)
|
||||
{
|
||||
card_presente = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
sc_disconnect_card(card,0);
|
||||
sc_disconnect_card(card);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -943,7 +943,7 @@ out:
|
|||
if (card)
|
||||
{
|
||||
sc_unlock(card);
|
||||
sc_disconnect_card(card, 0);
|
||||
sc_disconnect_card(card);
|
||||
}
|
||||
|
||||
if (ctx)
|
||||
|
|
Loading…
Reference in New Issue