首页 文章

USB - 主机和设备之间是否存在初始握手?

提问于
浏览
1

我正在智能卡读卡器上使用 Wireshark 捕获USB流量 . 当我使用 PyScard 连接到阅读器时,在我通过 Build 连接发送任何APDU之前,使用批量操作来回发送一些数据包 .

我已经读过here,USB设备和主机之间存在初始握手,我想知道这是否是我在嗅探时看到的 .

使用wireshark,我得到以下内容:

  • 批量输出(主机到设备):

First packet

  • 批量输出(设备到主机):

Second packet

  • 批量输入(主机到设备):

third

  • 批量输入(设备到主机):

Fourth packet

这四个数据包被发送2-3次,然后我可以使用PyScard嗅探我发送的消息 .

我的目标是通过仅使用USB通信重现阅读器和主机之间的通信 . 所以:

  • Is there an initial handshake in USB communications?

  • Is that what I'm capturing?

  • How can I reproduce this USB communications?

谢谢<3

编辑14/03/2018 - David Grayson回答后的其他信息

我在这里捕获的不是“获取设备描述符”等部分 . 当我尝试打印设备的详细信息并且Wireshark识别并标记数据包时,会发生这种情况 .

我知道奇怪的操作,但这是我从wireshark得到的 . 我一直在做的解释是它们是请求 - 响应对:主机使用批量输出 endpoints 发送内容,然后在准备好时使用 endpoints 中的批量请求读取答案 . 我完全不知道,这正是它对我的看法 .

>> lsusb -v

Bus 001 Device 002: ID 0bda:0165 Realtek Semiconductor Corp. 
Couldn't open device, some information will be missing
Device Descriptor:

    bLength                
    bDescriptorType         1
    bcdUSB               2.00
    bDeviceClass            0 (Defined at Interface level)
    bDeviceSubClass         0 
    bDeviceProtocol         0 
    bMaxPacketSize0        64
    idVendor           0x0bda Realtek Semiconductor Corp.
    idProduct          0x0165 
    bcdDevice           61.23
    iManufacturer           1 
    iProduct                6 
    iSerial                 3 
    bNumConfigurations      1

Configuration Descriptor:
        bLength                 9
        bDescriptorType         2
        wTotalLength           93
        bNumInterfaces          1
        bConfigurationValue     1
        iConfiguration          4 
        bmAttributes         0xa0
          (Bus Powered)
          Remote Wakeup
        MaxPower              500mA

Interface Descriptor:
    bLength                 9
    bDescriptorType         4
    bInterfaceNumber        0
    bAlternateSetting       0
    bNumEndpoints           3
    bInterfaceClass        11 Chip/SmartCard
    bInterfaceSubClass      0 
    bInterfaceProtocol      0 
    iInterface              6 

ChipCard Interface Descriptor:
    bLength                54
    bDescriptorType        33
    bcdCCID              1.10  (Warning: Only accurate for version 1.0)
    nMaxSlotIndex           0
    bVoltageSupport         7  5.0V 3.0V 1.8V 
    dwProtocols             3  T=0 T=1
    dwDefaultClock       3750
    dwMaxiumumClock      7500
    bNumClockSupported      0
    dwDataRate          10080 bps
    dwMaxDataRate      312500 bps
    bNumDataRatesSupp.      0
    dwMaxIFSD             254
    dwSyncProtocols  00000000 
    dwMechanical     00000000 
    dwFeatures       00010030
    Auto clock change
    Auto baud rate change
    TPDU level exchange
    dwMaxCCIDMsgLen       271
    bClassGetResponse      00
    bClassEnvelope         00
    wlcdLayout           none
    bPINSupport             0 
    bMaxCCIDBusySlots       1

Endpoint Descriptor:
    bLength                 7
    bDescriptorType         5
    bEndpointAddress     0x83  EP 3 IN
    bmAttributes            3
      Transfer Type            Interrupt
      Synch Type               None
      Usage Type               Data
    wMaxPacketSize     0x0040  1x 64 bytes
    bInterval               8

Endpoint Descriptor:
    bLength                 7
    bDescriptorType         5
    bEndpointAddress     0x05  EP 5 OUT
    bmAttributes            2
      Transfer Type            Bulk
      Synch Type               None
      Usage Type               Data
    wMaxPacketSize     0x0200  1x 512 bytes
    bInterval               0

Endpoint Descriptor:
    bLength                 7
    bDescriptorType         5
    bEndpointAddress     0x86  EP 6 IN
    bmAttributes            2
      Transfer Type            Bulk
      Synch Type               None
      Usage Type               Data
    wMaxPacketSize     0x0200  1x 512 bytes
    bInterval               0

(截图是好的,它们看起来很像,但它们不一样)

1 回答

  • 2

    初始握手包括控制传输,如“获取设备描述符”,“获取配置描述符”和“设置地址”,这些都在USB 2.0规范的第9章中定义 .

    初始握手通常没有任何批量传输,但您的设备可能会使用一个在初始化时想要进行批量传输的驱动程序 . 由于它是一个智能卡读卡器,我想你的操作系统有一些驱动程序向它发送命令,以查看是否连接了任何智能卡,这些命令很可能通过批量传输而不是控制传输来实现 . 要了解有关这些命令的更多信息,您需要找到设备实现的USB类的文档和/或发送这些命令的驱动程序 .

    您的批量流量描述令人困惑 . 术语“Out”始终表示“Host to device”,因此它也不能表示“Device to host” . 术语“在”中始终表示“设备到主机”,因此它也不能表示“主机到设备” . 您发布了两个重复的屏幕截图 .

    为了在将来获得更好的响应,我认为您应该包含设备描述符的转储( lsusb -v ),改进您对流量的描述,说明流量被看到的 endpoints ,还说明您正在使用的操作系统并给出有关连接到设备的驱动程序的任何信息 .

相关问题