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.

--

Backport from master commit of:

	f44aa290c1368a3119b2323664c0f356195c4206

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

View File

@ -67,7 +67,7 @@
#include "ccid-driver.h"
struct dev_list {
struct ccid_dev_table *ccid_table;
void *table;
const char *portstr;
int idx;
int idx_max;
@ -1534,7 +1534,7 @@ open_ccid_reader (struct dev_list *dl)
return -1;
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);
if (!err)
{
@ -1893,14 +1893,14 @@ apdu_dev_list_start (const char *portstr, struct dev_list **l_p)
#ifdef HAVE_LIBUSB
if (opt.disable_ccid)
{
dl->ccid_table = NULL;
dl->table = NULL;
dl->idx_max = 1;
}
else
{
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)
return err;
@ -1922,7 +1922,7 @@ apdu_dev_list_start (const char *portstr, struct dev_list **l_p)
}
}
#else
dl->ccid_table = NULL;
dl->table = NULL;
dl->idx_max = 1;
#endif /* HAVE_LIBUSB */
@ -1934,8 +1934,8 @@ void
apdu_dev_list_finish (struct dev_list *dl)
{
#ifdef HAVE_LIBUSB
if (dl->ccid_table)
ccid_dev_scan_finish (dl->ccid_table, dl->idx_max);
if (dl->table)
ccid_dev_scan_finish (dl->table, dl->idx_max);
#endif
xfree (dl);
npth_mutex_unlock (&reader_table_lock);
@ -2051,7 +2051,7 @@ apdu_open_reader (struct dev_list *dl, int app_empty)
int slot;
#ifdef HAVE_LIBUSB
if (dl->ccid_table)
if (dl->table)
{ /* CCID readers. */
int readerno;
@ -2088,7 +2088,7 @@ apdu_open_reader (struct dev_list *dl, int app_empty)
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)
log_debug ("apdu_open_reader: BAI=%x\n", bai);

View File

@ -1308,7 +1308,7 @@ static libusb_device **ccid_usb_dev_list;
static struct ccid_dev_table ccid_dev_table[MAX_DEVICE];
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;
libusb_device *dev;
@ -1435,9 +1435,10 @@ ccid_dev_scan (int *idx_max_p, struct ccid_dev_table **t_p)
}
void
ccid_dev_scan_finish (struct ccid_dev_table *tbl, int max)
ccid_dev_scan_finish (void *tbl0, int max)
{
int i;
struct ccid_dev_table *tbl = tbl0;
for (i = 0; i < max; i++)
{
@ -1456,12 +1457,13 @@ ccid_dev_scan_finish (struct ccid_dev_table *tbl, int max)
}
unsigned int
ccid_get_BAI (int idx, struct ccid_dev_table *tbl)
ccid_get_BAI (int idx, void *tbl0)
{
int n;
int bus, addr, intf;
unsigned int bai;
libusb_device *dev;
struct ccid_dev_table *tbl = tbl0;
n = tbl[idx].n;
dev = ccid_usb_dev_list[n];
@ -1565,7 +1567,7 @@ ccid_usb_thread (void *arg)
static int
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)
{
libusb_device *dev;
@ -1577,6 +1579,7 @@ ccid_open_usb_reader (const char *spec_reader_name,
int n;
int bus, addr;
unsigned int bai;
struct ccid_dev_table *ccid_table = ccid_table0;
n = ccid_table[idx].n;
ifc_no = ccid_table[idx].interface_number;
@ -1707,9 +1710,11 @@ ccid_open_usb_reader (const char *spec_reader_name,
pointer to be used as handle in HANDLE. Returns 0 on success. */
int
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)
{
struct ccid_dev_table *ccid_table = ccid_table0;
*handle = calloc (1, sizeof **handle);
if (!*handle)
{

View File

@ -124,12 +124,12 @@ struct ccid_dev_table;
int ccid_set_debug_level (int level);
char *ccid_get_reader_list (void);
gpg_error_t ccid_dev_scan (int *idx_max, struct ccid_dev_table **t_p);
void ccid_dev_scan_finish (struct ccid_dev_table *tbl, int max);
unsigned int ccid_get_BAI (int, struct ccid_dev_table *tbl);
gpg_error_t ccid_dev_scan (int *idx_max, void **t_p);
void ccid_dev_scan_finish (void *tbl0, int max);
unsigned int ccid_get_BAI (int, void *tbl0);
int ccid_compare_BAI (ccid_driver_t handle, unsigned int);
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);
int ccid_set_progress_cb (ccid_driver_t handle,
void (*cb)(void *, const char *, int, int, int),