mirror of
git://git.gnupg.org/gnupg.git
synced 2025-03-28 22:49:59 +01: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:
parent
d26c51825e
commit
c7ec9c4224
@ -1117,7 +1117,7 @@ find_endpoint (const struct libusb_interface_descriptor *ifcdesc, int mode)
|
|||||||
for other reasons. */
|
for other reasons. */
|
||||||
static int
|
static int
|
||||||
scan_or_find_usb_device (int scan_mode,
|
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,
|
const char *readerid,
|
||||||
struct libusb_device *dev,
|
struct libusb_device *dev,
|
||||||
char **r_rid,
|
char **r_rid,
|
||||||
@ -1133,12 +1133,12 @@ scan_or_find_usb_device (int scan_mode,
|
|||||||
int set_no;
|
int set_no;
|
||||||
const struct libusb_interface_descriptor *ifcdesc;
|
const struct libusb_interface_descriptor *ifcdesc;
|
||||||
char *rid;
|
char *rid;
|
||||||
libusb_device_handle *idev;
|
libusb_device_handle *idev = NULL;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
err = libusb_get_device_descriptor (dev, desc);
|
err = libusb_get_device_descriptor (dev, desc);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
return err;
|
return 0;
|
||||||
|
|
||||||
*r_idev = NULL;
|
*r_idev = NULL;
|
||||||
|
|
||||||
@ -1150,7 +1150,7 @@ scan_or_find_usb_device (int scan_mode,
|
|||||||
if (err < 0)
|
if (err < 0)
|
||||||
{
|
{
|
||||||
if (err == LIBUSB_ERROR_NO_MEM)
|
if (err == LIBUSB_ERROR_NO_MEM)
|
||||||
return err;
|
return 0;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1176,6 +1176,11 @@ scan_or_find_usb_device (int scan_mode,
|
|||||||
&& desc->idVendor == VENDOR_CHERRY
|
&& desc->idVendor == VENDOR_CHERRY
|
||||||
&& desc->idProduct == CHERRY_ST2000)))
|
&& desc->idProduct == CHERRY_ST2000)))
|
||||||
{
|
{
|
||||||
|
++*count;
|
||||||
|
if (!scan_mode
|
||||||
|
&& ((readerno > 0 && readerno != *count - 1)))
|
||||||
|
continue;
|
||||||
|
|
||||||
err = libusb_open (dev, &idev);
|
err = libusb_open (dev, &idev);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
{
|
{
|
||||||
@ -1184,12 +1189,18 @@ scan_or_find_usb_device (int scan_mode,
|
|||||||
continue; /* with next setting. */
|
continue; /* with next setting. */
|
||||||
}
|
}
|
||||||
|
|
||||||
rid = make_reader_id (idev,
|
rid = make_reader_id (idev, desc->idVendor, desc->idProduct,
|
||||||
desc->idVendor,
|
|
||||||
desc->idProduct,
|
|
||||||
desc->iSerialNumber);
|
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)
|
if (scan_mode)
|
||||||
{
|
{
|
||||||
char *p;
|
char *p;
|
||||||
@ -1214,15 +1225,13 @@ scan_or_find_usb_device (int scan_mode,
|
|||||||
*rid_list = p;
|
*rid_list = p;
|
||||||
}
|
}
|
||||||
else /* Out of memory. */
|
else /* Out of memory. */
|
||||||
|
{
|
||||||
|
libusb_free_config_descriptor (config);
|
||||||
free (rid);
|
free (rid);
|
||||||
|
return 0;
|
||||||
rid = NULL;
|
|
||||||
++*count;
|
|
||||||
}
|
}
|
||||||
else if (!*readerno
|
}
|
||||||
|| (*readerno < 0
|
else
|
||||||
&& readerid
|
|
||||||
&& !strcmp (readerid, rid)))
|
|
||||||
{
|
{
|
||||||
/* We found the requested reader. */
|
/* We found the requested reader. */
|
||||||
if (ifcdesc_extra && ifcdesc_extra_len)
|
if (ifcdesc_extra && ifcdesc_extra_len)
|
||||||
@ -1263,21 +1272,10 @@ scan_or_find_usb_device (int scan_mode,
|
|||||||
libusb_free_config_descriptor (config);
|
libusb_free_config_descriptor (config);
|
||||||
return 1; /* Found requested device. */
|
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);
|
libusb_close (idev);
|
||||||
idev = NULL;
|
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++)
|
for (i = 0; i < n; i++)
|
||||||
{
|
{
|
||||||
dev = dev_list[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,
|
readerid,
|
||||||
dev,
|
dev,
|
||||||
r_rid,
|
r_rid,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user