mirror of
https://github.com/genodelabs/genode.git
synced 2025-04-08 11:55:24 +00:00
parent
4796f761b8
commit
2a71c8fa82
@ -2,7 +2,7 @@ PCSC_LITE_DIR := $(call select_from_ports,pcsc-lite)/src/lib/pcsc-lite
|
||||
|
||||
include $(call select_from_repositories,lib/import/import-pcsc-lite.mk)
|
||||
|
||||
LIBS += ccid libc
|
||||
LIBS += ccid libc libusb
|
||||
|
||||
# find 'config.h'
|
||||
INC_DIR += $(REP_DIR)/src/lib/pcsc-lite
|
||||
|
@ -112,9 +112,6 @@ append config {
|
||||
<rom name="Info.plist"/>
|
||||
</dir>
|
||||
</dir>
|
||||
<inline name="config.pcsc-lite">
|
||||
<config vendor_id="} [smartcard_vendor_id] {" product_id="} [smartcard_product_id] {"/>
|
||||
</inline>
|
||||
</vfs>
|
||||
<libc stdout="/dev/log" stderr="/dev/log" rtc="/dev/rtc"/>
|
||||
</config>
|
||||
|
@ -1,12 +1,4 @@
|
||||
The USB card reader to be used by an application must be configured with its
|
||||
vendor id and product id in a file '/config.pcsc-lite':
|
||||
|
||||
<config>
|
||||
<libc>
|
||||
<vfs>
|
||||
<inline name="config.pcsc-lite">
|
||||
<config vendor_id="0xXXXX" product_id="0xXXXX"/>
|
||||
</inline>
|
||||
</vfs>
|
||||
</libc>
|
||||
</config>
|
||||
The library uses the first (and currently the only) USB device reported by
|
||||
libusb as smartcard reader. The actual selection of the USB device to use is
|
||||
done by the USB driver according to its configured policy for the 'Usb' session
|
||||
with the label 'usb_device', which is used by libusb to access the device.
|
||||
|
@ -21,6 +21,9 @@
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/* libusb includes */
|
||||
#include <libusb.h>
|
||||
|
||||
/* pcsc-lite includes */
|
||||
extern "C" {
|
||||
#include <debuglog.h>
|
||||
@ -42,39 +45,38 @@ struct Pcsc_lite_initializer
|
||||
(void)DebugLogSetCategory(DEBUG_CATEGORY_APDU);
|
||||
}
|
||||
|
||||
unsigned int vendor_id = 0x0000;
|
||||
unsigned int product_id = 0x0000;
|
||||
/*
|
||||
* Find out vendor id and product id of the connected USB device
|
||||
* and add it as reader.
|
||||
*/
|
||||
|
||||
int fd = open("/config.pcsc-lite", O_RDONLY);
|
||||
libusb_context *ctx = nullptr;
|
||||
|
||||
if (fd < 0) {
|
||||
Genode::error("Could not open 'config.pcsc-lite'");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
char config[128];
|
||||
if (read(fd, config, sizeof(config)) < 0) {
|
||||
Genode::error("Could not read 'config.pcsc-lite'");
|
||||
libusb_init(&ctx);
|
||||
|
||||
libusb_device **devs = nullptr;
|
||||
|
||||
if (libusb_get_device_list(ctx, &devs) < 1) {
|
||||
Genode::error("Could not find a USB device.");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
try {
|
||||
struct libusb_device_descriptor device_descriptor;
|
||||
|
||||
Genode::Xml_node config_node(config);
|
||||
|
||||
vendor_id = config_node.attribute_value("vendor_id", 0U);
|
||||
product_id = config_node.attribute_value("product_id", 0U);
|
||||
|
||||
} catch (...) {
|
||||
Genode::error("Error parsing 'config.pcsc-lite'");
|
||||
if (libusb_get_device_descriptor(devs[0], &device_descriptor) < 0) {
|
||||
Genode::error("Could not read the device descriptor of the "
|
||||
"USB device.");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
close(fd);
|
||||
libusb_free_device_list(devs, 1);
|
||||
|
||||
libusb_exit(ctx);
|
||||
|
||||
char device[14];
|
||||
|
||||
snprintf(device, sizeof(device), "usb:%04x/%04x", vendor_id, product_id);
|
||||
snprintf(device, sizeof(device), "usb:%04x/%04x",
|
||||
device_descriptor.idVendor, device_descriptor.idProduct);
|
||||
|
||||
RFAllocateReaderSpace(0);
|
||||
(void)RFAddReader("CCID", 0, "/", device);
|
||||
|
Loading…
x
Reference in New Issue
Block a user