1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-06-09 23:39:51 +02:00

scd: Improve internal CCID driver.

* scd/ccid-driver.c (scan_or_find_usb_device): Fix return value.
Support device with multiple CCID interfaces.  Fix the case with
READERNO.  Support partial string match of "reader-port" like PC/SC
driver.

--

I don't know any device with multiple CCID interfaces, though.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
This commit is contained in:
NIIBE Yutaka 2016-12-27 11:58:54 +09:00
parent d26c51825e
commit c7ec9c4224

View File

@ -1117,7 +1117,7 @@ find_endpoint (const struct libusb_interface_descriptor *ifcdesc, int mode)
for other reasons. */
static int
scan_or_find_usb_device (int scan_mode,
int *readerno, int *count, char **rid_list,
int readerno, int *count, char **rid_list,
const char *readerid,
struct libusb_device *dev,
char **r_rid,
@ -1133,12 +1133,12 @@ scan_or_find_usb_device (int scan_mode,
int set_no;
const struct libusb_interface_descriptor *ifcdesc;
char *rid;
libusb_device_handle *idev;
libusb_device_handle *idev = NULL;
int err;
err = libusb_get_device_descriptor (dev, desc);
if (err < 0)
return err;
return 0;
*r_idev = NULL;
@ -1150,7 +1150,7 @@ scan_or_find_usb_device (int scan_mode,
if (err < 0)
{
if (err == LIBUSB_ERROR_NO_MEM)
return err;
return 0;
continue;
}
@ -1176,6 +1176,11 @@ scan_or_find_usb_device (int scan_mode,
&& desc->idVendor == VENDOR_CHERRY
&& desc->idProduct == CHERRY_ST2000)))
{
++*count;
if (!scan_mode
&& ((readerno > 0 && readerno != *count - 1)))
continue;
err = libusb_open (dev, &idev);
if (err < 0)
{
@ -1184,12 +1189,18 @@ scan_or_find_usb_device (int scan_mode,
continue; /* with next setting. */
}
rid = make_reader_id (idev,
desc->idVendor,
desc->idProduct,
rid = make_reader_id (idev, desc->idVendor, desc->idProduct,
desc->iSerialNumber);
if (rid)
if (!rid)
{
libusb_free_config_descriptor (config);
return 0;
}
if (!scan_mode && readerno == -1 && readerid
&& strncmp (rid, readerid, strlen (readerid)))
continue;
if (scan_mode)
{
char *p;
@ -1214,15 +1225,13 @@ scan_or_find_usb_device (int scan_mode,
*rid_list = p;
}
else /* Out of memory. */
{
libusb_free_config_descriptor (config);
free (rid);
rid = NULL;
++*count;
return 0;
}
else if (!*readerno
|| (*readerno < 0
&& readerid
&& !strcmp (readerid, rid)))
}
else
{
/* We found the requested reader. */
if (ifcdesc_extra && ifcdesc_extra_len)
@ -1263,21 +1272,10 @@ scan_or_find_usb_device (int scan_mode,
libusb_free_config_descriptor (config);
return 1; /* Found requested device. */
}
else
{
/* This is not yet the reader we want.
fixme: We should avoid the extra usb_open
in this case. */
if (*readerno >= 0)
--*readerno;
}
free (rid);
}
free (rid);
libusb_close (idev);
idev = NULL;
libusb_free_config_descriptor (config);
return 0;
}
}
}
@ -1371,7 +1369,7 @@ scan_or_find_devices (int readerno, const char *readerid,
for (i = 0; i < n; i++)
{
dev = dev_list[i];
if (scan_or_find_usb_device (scan_mode, &readerno, &count, &rid_list,
if (scan_or_find_usb_device (scan_mode, readerno, &count, &rid_list,
readerid,
dev,
r_rid,