scd: Minor code reorganization

* scd/ccid-driver.c: Move struct defines to the top.
(MAX_DEVICE): Rename to CCID_MAX_DEVICE.
This commit is contained in:
Werner Koch 2022-04-14 10:25:15 +02:00
parent c4b14be48f
commit 58532fe56c
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B
1 changed files with 22 additions and 17 deletions

View File

@ -111,6 +111,10 @@
/* CCID command timeout. */ /* CCID command timeout. */
#define CCID_CMD_TIMEOUT (5*1000) #define CCID_CMD_TIMEOUT (5*1000)
/* Number of supported devices. See MAX_READER in apdu.c. */
#define CCID_MAX_DEVICE 4
/* Depending on how this source is used we either define our error /* Depending on how this source is used we either define our error
output to go to stderr or to the GnuPG based logging functions. We output to go to stderr or to the GnuPG based logging functions. We
use the latter when GNUPG_MAJOR_VERSION or GNUPG_SCD_MAIN_HEADER use the latter when GNUPG_MAJOR_VERSION or GNUPG_SCD_MAIN_HEADER
@ -261,6 +265,19 @@ struct ccid_driver_s
}; };
/* Object to keep infos about found ccid devices. */
struct ccid_dev_table {
int n; /* Index to ccid_usb_dev_list */
int interface_number;
int setting_number;
unsigned char *ifcdesc_extra;
int ep_bulk_out;
int ep_bulk_in;
int ep_intr;
size_t ifcdesc_extra_len;
};
static int initialized_usb; /* Tracks whether USB has been initialized. */ static int initialized_usb; /* Tracks whether USB has been initialized. */
static int debug_level; /* Flag to control the debug output. static int debug_level; /* Flag to control the debug output.
0 = No debugging 0 = No debugging
@ -270,6 +287,10 @@ static int debug_level; /* Flag to control the debug output.
*/ */
static int ccid_usb_thread_is_alive; static int ccid_usb_thread_is_alive;
static libusb_device **ccid_usb_dev_list;
static struct ccid_dev_table ccid_dev_table[CCID_MAX_DEVICE];
static unsigned int compute_edc (const unsigned char *data, size_t datalen, static unsigned int compute_edc (const unsigned char *data, size_t datalen,
int use_crc); int use_crc);
@ -1323,22 +1344,6 @@ ccid_vendor_specific_pinpad_setup (ccid_driver_t handle)
} }
#define MAX_DEVICE 4 /* See MAX_READER in apdu.c. */
struct ccid_dev_table {
int n; /* Index to ccid_usb_dev_list */
int interface_number;
int setting_number;
unsigned char *ifcdesc_extra;
int ep_bulk_out;
int ep_bulk_in;
int ep_intr;
size_t ifcdesc_extra_len;
};
static libusb_device **ccid_usb_dev_list;
static struct ccid_dev_table ccid_dev_table[MAX_DEVICE];
gpg_error_t gpg_error_t
ccid_dev_scan (int *idx_max_p, void **t_p) ccid_dev_scan (int *idx_max_p, void **t_p)
{ {
@ -1423,7 +1428,7 @@ ccid_dev_scan (int *idx_max_p, void **t_p)
ccid_dev_table[idx].ep_intr = find_endpoint (ifcdesc, 2); ccid_dev_table[idx].ep_intr = find_endpoint (ifcdesc, 2);
idx++; idx++;
if (idx >= MAX_DEVICE) if (idx >= CCID_MAX_DEVICE)
{ {
libusb_free_config_descriptor (config); libusb_free_config_descriptor (config);
err = 0; err = 0;