added option to scan for available readers
git-svn-id: https://vsmartcard.svn.sourceforge.net/svnroot/vsmartcard@77 96b47cad-a561-4643-ad3b-153ac7d7599c
This commit is contained in:
32
ccid/ccid.c
32
ccid/ccid.c
@@ -1313,3 +1313,35 @@ int ccid_testpace(u8 pin_id, const char *pin, size_t pinlen)
|
||||
|
||||
return SC_ERROR_SLOT_NOT_FOUND;
|
||||
}
|
||||
|
||||
int ccid_list_readers(int verbose)
|
||||
{
|
||||
static sc_context_t *ctx = NULL;
|
||||
|
||||
int r;
|
||||
r = sc_context_create(&ctx, NULL);
|
||||
if (r) {
|
||||
fprintf(stderr, "Failed to establish context: %s\n", sc_strerror(r));
|
||||
return 1;
|
||||
}
|
||||
ctx->debug = verbose;
|
||||
|
||||
unsigned int i, rcount = sc_ctx_get_reader_count(ctx);
|
||||
|
||||
if (rcount == 0) {
|
||||
printf("No smart card readers found.\n");
|
||||
return 0;
|
||||
}
|
||||
printf("Readers known about:\n");
|
||||
printf("Nr. Driver Name\n");
|
||||
for (i = 0; i < rcount; i++) {
|
||||
sc_reader_t *screader = sc_ctx_get_reader(ctx, i);
|
||||
printf("%-7d%-11s%s\n", i, screader->driver->short_name,
|
||||
screader->name);
|
||||
}
|
||||
|
||||
if (ctx)
|
||||
sc_release_context(ctx);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -265,6 +265,7 @@ struct hid_class_descriptor {
|
||||
__u8 bNumDescriptors;
|
||||
} __attribute__ ((packed));
|
||||
|
||||
int ccid_list_readers(int verbose);
|
||||
int ccid_initialize(int reader_id, int verbose);
|
||||
void ccid_shutdown();
|
||||
|
||||
|
||||
12
ccid/usb.c
12
ccid/usb.c
@@ -57,6 +57,7 @@ static int verbose = 0;
|
||||
static int debug = 0;
|
||||
static int dohid = 0;
|
||||
static int doint = 0;
|
||||
static int dolist = 0;
|
||||
static u8 dopacetest = 0;
|
||||
static int usb_reader_num = -1;
|
||||
static const char *pin;
|
||||
@@ -64,6 +65,7 @@ static const char *pin;
|
||||
#define OPT_HELP 'h'
|
||||
#define OPT_INTERRUPT 'n'
|
||||
#define OPT_READER 'r'
|
||||
#define OPT_LIST 'l'
|
||||
#define OPT_SERIAL 's'
|
||||
#define OPT_PIN 'i'
|
||||
#define OPT_PUK 'u'
|
||||
@@ -78,6 +80,7 @@ static const struct option options[] = {
|
||||
/*{ "hid", no_argument, &dohid, 1 },*/
|
||||
{ "help", no_argument, NULL, OPT_HELP },
|
||||
{ "reader", required_argument, NULL, OPT_READER },
|
||||
{ "list-reader", no_argument, NULL, OPT_LIST },
|
||||
{ "test-pin", optional_argument, NULL, OPT_PIN },
|
||||
{ "test-puk", optional_argument, NULL, OPT_PUK },
|
||||
{ "test-can", optional_argument, NULL, OPT_CAN },
|
||||
@@ -94,6 +97,7 @@ static const char *option_help[] = {
|
||||
/*"Emulate HID device",*/
|
||||
"Print help and exit",
|
||||
"Number of reader to use (default: auto-detect)",
|
||||
"Lists all configured readers",
|
||||
"Run PACE with PIN",
|
||||
"Run PACE with PUK",
|
||||
"Run PACE with CAN",
|
||||
@@ -1768,7 +1772,7 @@ main (int argc, char **argv)
|
||||
}
|
||||
|
||||
while (1) {
|
||||
c = getopt_long(argc, argv, "hnr:s:i::u::a::z::p:e:vo", options, &long_optind);
|
||||
c = getopt_long(argc, argv, "hnr:ls:i::u::a::z::p:e:vo", options, &long_optind);
|
||||
if (c == -1)
|
||||
break;
|
||||
if (c == '?' || c == OPT_HELP) {
|
||||
@@ -1780,6 +1784,9 @@ main (int argc, char **argv)
|
||||
if (sscanf(optarg, "%d", &usb_reader_num) != 1)
|
||||
parse_error(argv[0], optarg, long_optind);
|
||||
break;
|
||||
case OPT_LIST:
|
||||
dolist++;
|
||||
break;
|
||||
case OPT_SERIAL:
|
||||
if (sscanf(optarg, "%56s", serial) != 1)
|
||||
parse_error(argv[0], optarg, long_optind);
|
||||
@@ -1823,6 +1830,9 @@ main (int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
if (dolist)
|
||||
return ccid_list_readers(verbose);
|
||||
|
||||
if (ccid_initialize(usb_reader_num, verbose) < 0) {
|
||||
perror("Can't initialize ccid");
|
||||
return 1;
|
||||
|
||||
Reference in New Issue
Block a user