Skip to content
Advertisement

USB – Is there an initial handshake between host and device?

I’m capturing USB traffic using Wireshark on a smart card reader. When I connect to the reader using PyScard, some packets are sent back and forth using bulk operations before I send any APDU just by establishing the connection.

I have read here that there is an initial handshake between a USB device and the host and I wonder if that is what I see while sniffing.

Using wireshark, I get the following:

  1. Bulk out (host to device):

First packet

  1. Bulk out (device to host):

Second packet

  1. Bulk in (host to device):

third

  1. Bulk in (device to host):

Fourth packet

These four packets are sent 2-3 times and then I can sniff the messages I send using PyScard.

My goal here is to reproduce the communication between the reader and the host by using only USB communications. So:

  1. Is there an initial handshake in USB communications?

  2. Is that what I’m capturing?

  3. How can I reproduce this USB communications?

Thanks <3


Edit 14/03/2018 – Additional information following David Grayson’s answer

What I am capturing here is not the part of “Get Device Descriptor”, etc. This happens when I try to print the device’s details and Wireshark recognises and labels the packets as so.

I’m aware of the weird operations but it is what I’m getting from wireshark. The interpretation I’ve been doing is that they’re request-response pairs: the host sends something using bulk out endpoint and then asks to read the answer by using bulk in endpoint when it is ready to do so. I have absolutely no idea, it’s just what it looks to me.

JavaScript

(The screenshots are ok, they look alike but they’re not the same)

Advertisement

Answer

The initial handshake consists of controls transfers like “Get Device Descriptor”, “Get Configuration Descriptor” and “Set Address”, which are defined in Chapter 9 of the USB 2.0 specification.

The initial handshake usually does not have any bulk transfers, but it is possible that your device uses a driver which wants to do some bulk transfers when it gets initialized. Since it is a smart card reader, I imagine your operating system has some driver that sends commands to it in order to see if any smart cards are connected, and those commands could very well be implemented with bulk transfers instead of control transfers. To learn more about these commands, you would need to find the documentation of the USB class that your device implements and/or the driver that is sending these commands.

The description of your bulk traffic is confusing. The term “Out” always means “Host to device” so it cannot mean “Device to host” also. The term “In” always means “Device to host” so it cannot mean “Host to device” also. You posted two duplicate screenshots.

To get better responses in the future, I think you should include a dump of your device’s descriptors (lsusb -v), improve your description of the traffic, say what endpoints the traffic was seen on, and also say what operating system you are using and give any information you have about the drivers that are attached to your device.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement