diff --git a/repos/libports/lib/mk/pcsc-lite.mk b/repos/libports/lib/mk/pcsc-lite.mk
index 441154afae..d119cfdb80 100644
--- a/repos/libports/lib/mk/pcsc-lite.mk
+++ b/repos/libports/lib/mk/pcsc-lite.mk
@@ -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
diff --git a/repos/libports/run/smartcard.run b/repos/libports/run/smartcard.run
index 3050d18244..520f6720d9 100644
--- a/repos/libports/run/smartcard.run
+++ b/repos/libports/run/smartcard.run
@@ -112,9 +112,6 @@ append config {
-
-
-
diff --git a/repos/libports/src/lib/pcsc-lite/README b/repos/libports/src/lib/pcsc-lite/README
index 192f438263..c67823651c 100644
--- a/repos/libports/src/lib/pcsc-lite/README
+++ b/repos/libports/src/lib/pcsc-lite/README
@@ -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':
-
-
-
-
-
-
-
-
-
-
+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.
diff --git a/repos/libports/src/lib/pcsc-lite/init.cc b/repos/libports/src/lib/pcsc-lite/init.cc
index f1d69fabc0..7d0c1610d9 100644
--- a/repos/libports/src/lib/pcsc-lite/init.cc
+++ b/repos/libports/src/lib/pcsc-lite/init.cc
@@ -21,6 +21,9 @@
#include
#include
+/* libusb includes */
+#include
+
/* pcsc-lite includes */
extern "C" {
#include
@@ -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);