1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-12-22 10:19:57 +01:00

scd: Clean up the structure for future fix of PC/SC.

* scd/apdu.c (struct dev_list): Rename from ccid_table, with void*.
(open_ccid_reader): Follow the change.
(apdu_dev_list_start, apdu_dev_list_finish): Likewise.
(apdu_open_reader): Likewise.
* scd/ccid-driver.c (ccid_dev_scan): Use void *.
(ccid_dev_scan_finish, ccid_get_BAI, ccid_open_usb_reader): Likewise.
* scd/ccid-driver.h: Change the APIs.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
This commit is contained in:
NIIBE Yutaka 2019-09-06 13:19:50 +09:00
parent c69a37dcbd
commit f44aa290c1
3 changed files with 23 additions and 18 deletions

View File

@ -55,7 +55,7 @@
#include "ccid-driver.h" #include "ccid-driver.h"
struct dev_list { struct dev_list {
struct ccid_dev_table *ccid_table; void *table;
const char *portstr; const char *portstr;
int idx; int idx;
int idx_max; int idx_max;
@ -1520,7 +1520,7 @@ open_ccid_reader (struct dev_list *dl)
return -1; return -1;
slotp = reader_table + slot; slotp = reader_table + slot;
err = ccid_open_reader (dl->portstr, dl->idx, dl->ccid_table, err = ccid_open_reader (dl->portstr, dl->idx, dl->table,
&slotp->ccid.handle, &slotp->rdrname); &slotp->ccid.handle, &slotp->rdrname);
if (!err) if (!err)
{ {
@ -1879,14 +1879,14 @@ apdu_dev_list_start (const char *portstr, struct dev_list **l_p)
#ifdef HAVE_LIBUSB #ifdef HAVE_LIBUSB
if (opt.disable_ccid) if (opt.disable_ccid)
{ {
dl->ccid_table = NULL; dl->table = NULL;
dl->idx_max = 1; dl->idx_max = 1;
} }
else else
{ {
gpg_error_t err; gpg_error_t err;
err = ccid_dev_scan (&dl->idx_max, &dl->ccid_table); err = ccid_dev_scan (&dl->idx_max, &dl->table);
if (err) if (err)
return err; return err;
@ -1908,7 +1908,7 @@ apdu_dev_list_start (const char *portstr, struct dev_list **l_p)
} }
} }
#else #else
dl->ccid_table = NULL; dl->table = NULL;
dl->idx_max = 1; dl->idx_max = 1;
#endif /* HAVE_LIBUSB */ #endif /* HAVE_LIBUSB */
@ -1920,8 +1920,8 @@ void
apdu_dev_list_finish (struct dev_list *dl) apdu_dev_list_finish (struct dev_list *dl)
{ {
#ifdef HAVE_LIBUSB #ifdef HAVE_LIBUSB
if (dl->ccid_table) if (dl->table)
ccid_dev_scan_finish (dl->ccid_table, dl->idx_max); ccid_dev_scan_finish (dl->table, dl->idx_max);
#endif #endif
xfree (dl); xfree (dl);
npth_mutex_unlock (&reader_table_lock); npth_mutex_unlock (&reader_table_lock);
@ -2037,7 +2037,7 @@ apdu_open_reader (struct dev_list *dl, int app_empty)
int slot; int slot;
#ifdef HAVE_LIBUSB #ifdef HAVE_LIBUSB
if (dl->ccid_table) if (dl->table)
{ /* CCID readers. */ { /* CCID readers. */
int readerno; int readerno;
@ -2074,7 +2074,7 @@ apdu_open_reader (struct dev_list *dl, int app_empty)
while (dl->idx < dl->idx_max) while (dl->idx < dl->idx_max)
{ {
unsigned int bai = ccid_get_BAI (dl->idx, dl->ccid_table); unsigned int bai = ccid_get_BAI (dl->idx, dl->table);
if (DBG_READER) if (DBG_READER)
log_debug ("apdu_open_reader: BAI=%x\n", bai); log_debug ("apdu_open_reader: BAI=%x\n", bai);

View File

@ -1276,7 +1276,7 @@ static libusb_device **ccid_usb_dev_list;
static struct ccid_dev_table ccid_dev_table[MAX_DEVICE]; static struct ccid_dev_table ccid_dev_table[MAX_DEVICE];
gpg_error_t gpg_error_t
ccid_dev_scan (int *idx_max_p, struct ccid_dev_table **t_p) ccid_dev_scan (int *idx_max_p, void **t_p)
{ {
ssize_t n; ssize_t n;
libusb_device *dev; libusb_device *dev;
@ -1403,9 +1403,10 @@ ccid_dev_scan (int *idx_max_p, struct ccid_dev_table **t_p)
} }
void void
ccid_dev_scan_finish (struct ccid_dev_table *tbl, int max) ccid_dev_scan_finish (void *tbl0, int max)
{ {
int i; int i;
struct ccid_dev_table *tbl = tbl0;
for (i = 0; i < max; i++) for (i = 0; i < max; i++)
{ {
@ -1424,12 +1425,13 @@ ccid_dev_scan_finish (struct ccid_dev_table *tbl, int max)
} }
unsigned int unsigned int
ccid_get_BAI (int idx, struct ccid_dev_table *tbl) ccid_get_BAI (int idx, void *tbl0)
{ {
int n; int n;
int bus, addr, intf; int bus, addr, intf;
unsigned int bai; unsigned int bai;
libusb_device *dev; libusb_device *dev;
struct ccid_dev_table *tbl = tbl0;
n = tbl[idx].n; n = tbl[idx].n;
dev = ccid_usb_dev_list[n]; dev = ccid_usb_dev_list[n];
@ -1537,7 +1539,7 @@ ccid_usb_thread (void *arg)
static int static int
ccid_open_usb_reader (const char *spec_reader_name, ccid_open_usb_reader (const char *spec_reader_name,
int idx, struct ccid_dev_table *ccid_table, int idx, void *ccid_table0,
ccid_driver_t *handle, char **rdrname_p) ccid_driver_t *handle, char **rdrname_p)
{ {
libusb_device *dev; libusb_device *dev;
@ -1549,6 +1551,7 @@ ccid_open_usb_reader (const char *spec_reader_name,
int n; int n;
int bus, addr; int bus, addr;
unsigned int bai; unsigned int bai;
struct ccid_dev_table *ccid_table = ccid_table0;
n = ccid_table[idx].n; n = ccid_table[idx].n;
ifc_no = ccid_table[idx].interface_number; ifc_no = ccid_table[idx].interface_number;
@ -1678,9 +1681,11 @@ ccid_open_usb_reader (const char *spec_reader_name,
pointer to be used as handle in HANDLE. Returns 0 on success. */ pointer to be used as handle in HANDLE. Returns 0 on success. */
int int
ccid_open_reader (const char *spec_reader_name, int idx, ccid_open_reader (const char *spec_reader_name, int idx,
struct ccid_dev_table *ccid_table, void *ccid_table0,
ccid_driver_t *handle, char **rdrname_p) ccid_driver_t *handle, char **rdrname_p)
{ {
struct ccid_dev_table *ccid_table = ccid_table0;
*handle = calloc (1, sizeof **handle); *handle = calloc (1, sizeof **handle);
if (!*handle) if (!*handle)
{ {

View File

@ -116,12 +116,12 @@ struct ccid_dev_table;
int ccid_set_debug_level (int level); int ccid_set_debug_level (int level);
char *ccid_get_reader_list (void); char *ccid_get_reader_list (void);
gpg_error_t ccid_dev_scan (int *idx_max, struct ccid_dev_table **t_p); gpg_error_t ccid_dev_scan (int *idx_max, void **t_p);
void ccid_dev_scan_finish (struct ccid_dev_table *tbl, int max); void ccid_dev_scan_finish (void *tbl0, int max);
unsigned int ccid_get_BAI (int, struct ccid_dev_table *tbl); unsigned int ccid_get_BAI (int, void *tbl0);
int ccid_compare_BAI (ccid_driver_t handle, unsigned int); int ccid_compare_BAI (ccid_driver_t handle, unsigned int);
int ccid_open_reader (const char *spec_reader_name, int ccid_open_reader (const char *spec_reader_name,
int idx, struct ccid_dev_table *ccid_table, int idx, void *ccid_table0,
ccid_driver_t *handle, char **rdrname_p); ccid_driver_t *handle, char **rdrname_p);
int ccid_set_progress_cb (ccid_driver_t handle, int ccid_set_progress_cb (ccid_driver_t handle,
void (*cb)(void *, const char *, int, int, int), void (*cb)(void *, const char *, int, int, int),