Skip to content

Commit

Permalink
SCARD_ATTR_CHANNEL_ID: use port number instead of device address
Browse files Browse the repository at this point in the history
The device address field is a number that is increasing after each USB
device plug-in. It is NOT related to a physical USB port.

It is the Device: number returned by lsusb(1):
Bus 001 Device 021: ID 08e6:3437 Gemalto (was Gemplus) GemPC Twin SmartCard Reader

The port number is related to a USB physical port and is stable if you
unplug and replug a USB device on the same port.

According to libusb_get_port_number() API documentation:
  Get the number of the port that a device is connected to. Unless the
  OS does something funky, or you are hot-plugging USB extension cards,
  the port number returned by this call is usually guaranteed to be
  uniquely tied to a physical port, meaning that different devices
  plugged on the same physical port should return the same port number.

  But outside of this, there is no guarantee that the port number
  returned by this call will remain the same, or even match the order in
  which ports have been numbered by the HUB/HCD manufacturer.
  • Loading branch information
LudovicRousseau committed Apr 15, 2020
1 parent 4c8c809 commit 810b550
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/ccid_usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ typedef struct
uint8_t bus_number;
uint8_t device_address;
int interface;
uint8_t port_number;

/*
* Endpoints
Expand Down Expand Up @@ -697,6 +698,7 @@ status_t OpenUSBByName(unsigned int reader_index, /*@null@*/ char *device)
usbDevice[reader_index].real_nb_opened_slots = 1;
usbDevice[reader_index].nb_opened_slots = &usbDevice[reader_index].real_nb_opened_slots;
usbDevice[reader_index].polling_transfer = NULL;
usbDevice[reader_index].port_number = libusb_get_port_number(dev);

/* CCID common informations */
usbDevice[reader_index].ccid.real_bSeq = 0;
Expand Down Expand Up @@ -1104,7 +1106,7 @@ EXTERNAL uint8_t get_ccid_usb_bus_number(int reader_index) {
}

EXTERNAL uint8_t get_ccid_usb_device_address(int reader_index) {
return usbDevice[reader_index].device_address;
return usbDevice[reader_index].port_number;
}

/*****************************************************************************
Expand Down

0 comments on commit 810b550

Please sign in to comment.