How to Identify USB devices on linux/ubuntu/debian

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

How to Identify USB devices on linux/ubuntu/debian

Uv Wildner
Hello,

I need to identify the USB device to which a card reader with a specific card is connected.
I am pulling my hair out but cannot find any API call that provides this information.

on Ludovic's blog I find this:
https://ludovicrousseau.blogspot.de/2010/05/what-is-in-pcsc-reader-name.html

That does not work on my system though!
ubuntu xenial 4.4.0-59-generic x86_64

When I list my card readers I get the list of readers like this from SCardListReaders():

SCM Microsystems Inc. SCR 3310 00 00
SCM Microsystems Inc. SCR 3310 01 00

OK, so the readers are enumerated.
However, I need to know the usb device id to be able to connect the reader with the right card to the correct virtualization environment.

Bus 002 Device 008: ID 04e6:5116 SCM Microsystems, Inc. SCR331-LC1 / SCR3310 SmartCard Reader
Bus 001 Device 005: ID 04e6:5116 SCM Microsystems, Inc. SCR331-LC1 / SCR3310 SmartCard Reader

I only know that the usb device id can change easily.

How do I find which USB device has been connected to the the instance of the SCardReader????

Any pointers greatly welcome.

_______________________________________________
Pcsclite-muscle mailing list
[hidden email]
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pcsclite-muscle
Reply | Threaded
Open this post in threaded view
|

Re: How to Identify USB devices on linux/ubuntu/debian

Frank Morgner-2
https://github.com/OpenSC/OpenSC/blob/master/src/libopensc/reader-pcsc.c#L950.

Am 27. Januar 2017 16:58:16 MEZ schrieb Uv Wildner <[hidden email]>:
Hello,

I need to identify the USB device to which a card reader with a specific card is connected.
I am pulling my hair out but cannot find any API call that provides this information.

on Ludovic's blog I find this:
https://ludovicrousseau.blogspot.de/2010/05/what-is-in-pcsc-reader-name.html

That does not work on my system though!
ubuntu xenial 4.4.0-59-generic x86_64

When I list my card readers I get the list of readers like this from SCardListReaders():

SCM Microsystems Inc. SCR 3310 00 00
SCM Microsystems Inc. SCR 3310 01 00

OK, so the readers are enumerated.
However, I need to know the usb device id to be able to connect the reader with the right card to the correct virtualization environment.

Bus 002 Device 008: ID 04e6:5116 SCM Microsystems, Inc. SCR331-LC1 / SCR3310 SmartCard Reader
Bus 001 Device 005: ID 04e6:5116 SCM Microsystems, Inc. SCR331-LC1 / SCR3310 SmartCard Reader

I only know that the usb device id can change easily.

How do I find which USB device has been connected to the the instance of the SCardReader????

Any pointers greatly welcome.

--
Frank Morgner
_______________________________________________
Pcsclite-muscle mailing list
[hidden email]
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pcsclite-muscle
Reply | Threaded
Open this post in threaded view
|

Re: How to Identify USB devices on linux/ubuntu/debian

Ludovic Rousseau
In reply to this post by Uv Wildner
2017-01-27 16:58 GMT+01:00 Uv Wildner <[hidden email]>:
Hello,

Hello,
 

I need to identify the USB device to which a card reader with a specific card is connected.
I am pulling my hair out but cannot find any API call that provides this information.

on Ludovic's blog I find this:

That does not work on my system though!
ubuntu xenial 4.4.0-59-generic x86_64

When I list my card readers I get the list of readers like this from SCardListReaders():

SCM Microsystems Inc. SCR 3310 00 00
SCM Microsystems Inc. SCR 3310 01 00

OK, so the readers are enumerated.
However, I need to know the usb device id to be able to connect the reader with the right card to the correct virtualization environment.

Bus 002 Device 008: ID 04e6:5116 SCM Microsystems, Inc. SCR331-LC1 / SCR3310 SmartCard Reader
Bus 001 Device 005: ID 04e6:5116 SCM Microsystems, Inc. SCR331-LC1 / SCR3310 SmartCard Reader

I only know that the usb device id can change easily.

How do I find which USB device has been connected to the the instance of the SCardReader????

Any pointers greatly welcome.

If your 2 readers are the exact same model and do not provide a serial number then I don't see a solution to differrentiate them.

My question: why do you need to do that?

If you know the ATR of your "specific card" then you can get the ATR from your 2 readers and know in which reader your card is present.
If you use 2 cards with the same ATR in each reader then this will not work.

Bye

--
 Dr. Ludovic Rousseau

_______________________________________________
Pcsclite-muscle mailing list
[hidden email]
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pcsclite-muscle
Reply | Threaded
Open this post in threaded view
|

Re: How to Identify USB devices on linux/ubuntu/debian

Uv Wildner
In reply to this post by Uv Wildner
Hello,

so the API does not provide for the USB device information. That's too bad. :(
I wonder where that information about the device to card reader mapping gets lost, as it obviously is needed somewhere in the stack?!?!

_______________________________________________
Pcsclite-muscle mailing list
[hidden email]
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pcsclite-muscle
Reply | Threaded
Open this post in threaded view
|

Re: How to Identify USB devices on linux/ubuntu/debian

Ludovic Rousseau
2017-01-30 13:28 GMT+01:00 Uv Wildner <[hidden email]>:
> Hello,

Hi,
 
> so the API does not provide for the USB device information. That's too bad. :(

A smart card reader is not always a USB device.
When PC/SC was designed smart card readers were serial devices connected to a serial port.

> I wonder where that information about the device to card reader mapping gets lost, as it obviously is needed somewhere in the stack?!?!

The information is present in pcsc-lite and in the CCID driver.
For example pcscd calls libccid with a parameter like "usb:08e6/3437:libudev:0:/dev/bus/usb/001/002"
http://pcsclite.alioth.debian.org/api/group__IFDHandler.html#gabb9fe35a68fa080ce9397f0b830b1e7e

My question was and still is: why do you need this information at the application level?

Bye

--
 Dr. Ludovic Rousseau

_______________________________________________
Pcsclite-muscle mailing list
[hidden email]
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pcsclite-muscle
Reply | Threaded
Open this post in threaded view
|

Re: How to Identify USB devices on linux/ubuntu/debian

Uv Wildner
I see, the stack introduces a level of abstraction which discards this information.

I will  try to workaround this by reinitializing the crypto parts each time.
I hope I can cover all my test cases like this.

So for the use case:

In an automated test setup I will be running a number  of containerized systems needing exactly one card reader containing the right card.

On the host level I am assigning a USB device to the container , inside the container I am just using the first card available.

When the (usb) device - card mapping is going wrong I will end up in encryption problems when the wrong card with the wrong key is connected to my current container.

Thanks a lot for the quick & efficient support!!!


From: "Ludovic Rousseau" <[hidden email]>
To: "pcsclite-muscle" <[hidden email]>
Sent: Monday, January 30, 2017 2:19:53 PM
Subject: Re: [Pcsclite-muscle] How to Identify USB devices on        linux/ubuntu/debian

2017-01-30 13:28 GMT+01:00 Uv Wildner <[hidden email]>:
> Hello,

Hi,
 
> so the API does not provide for the USB device information. That's too bad. :(

A smart card reader is not always a USB device.
When PC/SC was designed smart card readers were serial devices connected to a serial port.

> I wonder where that information about the device to card reader mapping gets lost, as it obviously is needed somewhere in the stack?!?!

The information is present in pcsc-lite and in the CCID driver.
For example pcscd calls libccid with a parameter like "usb:08e6/3437:libudev:0:/dev/bus/usb/001/002"
http://pcsclite.alioth.debian.org/api/group__IFDHandler.html#gabb9fe35a68fa080ce9397f0b830b1e7e

My question was and still is: why do you need this information at the application level?

Bye

--
 Dr. Ludovic Rousseau

_______________________________________________
Pcsclite-muscle mailing list
[hidden email]
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pcsclite-muscle

_______________________________________________
Pcsclite-muscle mailing list
[hidden email]
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pcsclite-muscle
Reply | Threaded
Open this post in threaded view
|

Re: How to Identify USB devices on linux/ubuntu/debian

Ludovic Rousseau


2017-01-30 14:41 GMT+01:00 Uv Wildner <[hidden email]>:
I see, the stack introduces a level of abstraction which discards this information.

I will  try to workaround this by reinitializing the crypto parts each time.
I hope I can cover all my test cases like this.

So for the use case:

In an automated test setup I will be running a number  of containerized systems needing exactly one card reader containing the right card.

On the host level I am assigning a USB device to the container , inside the container I am just using the first card available.

So each container will see exactly 1 smart card reader at the USB level.
Each container will have its own pcscd.
pcscd executed inside the container will list exactly 1 smart card reader at the PC/SC level.

Am I right?
 
When the (usb) device - card mapping is going wrong I will end up in encryption problems when the wrong card with the wrong key is connected to my current container.

Thanks a lot for the quick & efficient support!!!

You are welcome.

Bye
 
--
 Dr. Ludovic Rousseau

_______________________________________________
Pcsclite-muscle mailing list
[hidden email]
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pcsclite-muscle
Reply | Threaded
Open this post in threaded view
|

Re: How to Identify USB devices on linux/ubuntu/debian

Uv Wildner
Exactly,

however, I seem to have no control which reader with which card goes to each container.
As I mentioned before I am worried that this will kill a few of our test cases...
I will come back when I need and/or found a better solution.



From: "Ludovic Rousseau" <[hidden email]>
To: "pcsclite-muscle" <[hidden email]>
Sent: Monday, January 30, 2017 4:59:23 PM
Subject: Re: [Pcsclite-muscle] How to Identify USB devices on        linux/ubuntu/debian



2017-01-30 14:41 GMT+01:00 Uv Wildner <[hidden email]>:
I see, the stack introduces a level of abstraction which discards this information.

I will  try to workaround this by reinitializing the crypto parts each time.
I hope I can cover all my test cases like this.

So for the use case:

In an automated test setup I will be running a number  of containerized systems needing exactly one card reader containing the right card.

On the host level I am assigning a USB device to the container , inside the container I am just using the first card available.

So each container will see exactly 1 smart card reader at the USB level.
Each container will have its own pcscd.
pcscd executed inside the container will list exactly 1 smart card reader at the PC/SC level.

Am I right?
 
When the (usb) device - card mapping is going wrong I will end up in encryption problems when the wrong card with the wrong key is connected to my current container.

Thanks a lot for the quick & efficient support!!!

You are welcome.

Bye
 
--
 Dr. Ludovic Rousseau

_______________________________________________
Pcsclite-muscle mailing list
[hidden email]
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pcsclite-muscle

_______________________________________________
Pcsclite-muscle mailing list
[hidden email]
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pcsclite-muscle
Reply | Threaded
Open this post in threaded view
|

Re: How to Identify USB devices on linux/ubuntu/debian

Ludovic Rousseau


2017-01-30 18:26 GMT+01:00 Uv Wildner <[hidden email]>:
>
> Exactly,
>
> however, I seem to have no control which reader with which card goes to each container.

You have a problem with your container software if you can't specify what specific USB device is attached to what specific container.
The problem is really not at the PC/SC level.

Good luck

--
 Dr. Ludovic Rousseau

_______________________________________________
Pcsclite-muscle mailing list
[hidden email]
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pcsclite-muscle
Reply | Threaded
Open this post in threaded view
|

Re: How to Identify USB devices on linux/ubuntu/debian

Uv Wildner
Well its easy to specify the device for the docker container.... that's resolved already.

However, the IDs on the USB bus are not fixed for a physical device and cannot be used reliably for this.

So I don't know which card is in which physical USB device XXX on the bus.

But how can I find  the mapping from the physical device to a USB device id which I can give to the container to connect the right device.
This was my original question. How to find this mapping!

I can list the devices on the usb bus.

I can list the enumerated readers... and read the contents of the inserted cards.

How the cards read with an enumerated card reader name are connected to a physical reader AKA ID on the usb bus is hidden in the stack!
:(

As in your original answer... it does not seem possible.
At least not within the pcsclite library.

cheers


From: "Ludovic Rousseau" <[hidden email]>
To: "pcsclite-muscle" <[hidden email]>
Sent: Monday, January 30, 2017 6:42:02 PM
Subject: Re: [Pcsclite-muscle] How to Identify USB devices on        linux/ubuntu/debian



2017-01-30 18:26 GMT+01:00 Uv Wildner <[hidden email]>:
>
> Exactly,
>
> however, I seem to have no control which reader with which card goes to each container.

You have a problem with your container software if you can't specify what specific USB device is attached to what specific container.
The problem is really not at the PC/SC level.

Good luck

--
 Dr. Ludovic Rousseau

_______________________________________________
Pcsclite-muscle mailing list
[hidden email]
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pcsclite-muscle

_______________________________________________
Pcsclite-muscle mailing list
[hidden email]
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pcsclite-muscle
Reply | Threaded
Open this post in threaded view
|

Re: How to Identify USB devices on linux/ubuntu/debian

Ludovic Rousseau
2017-01-30 19:01 GMT+01:00 Uv Wildner <[hidden email]>:

>
> Well its easy to specify the device for the docker container.... that's resolved already.
>
> However, the IDs on the USB bus are not fixed for a physical device and cannot be used reliably for this.
>
> So I don't know which card is in which physical USB device XXX on the bus.
>
> But how can I find  the mapping from the physical device to a USB device id which I can give to the container to connect the right device.
> This was my original question. How to find this mapping!
>
> I can list the devices on the usb bus.
>
> I can list the enumerated readers... and read the contents of the inserted cards.
>
> How the cards read with an enumerated card reader name are connected to a physical reader AKA ID on the usb bus is hidden in the stack!
> :(
>
> As in your original answer... it does not seem possible.
> At least not within the pcsclite library.

I see your problem now.

Maybe you can use an "intelligent" USB hub that can control the power of each USB connector independently.
You power the USB devices one after the other and attach the newly found device in a new container.
Since you control what USB connector is powered up you know what smart card reader is concerned.

Could that work for you?

Bye

--
 Dr. Ludovic Rousseau

_______________________________________________
Pcsclite-muscle mailing list
[hidden email]
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pcsclite-muscle