Skip to content
hasu@tmk edited this page Nov 18, 2024 · 22 revisions

Specification

https://www.usb.org/documents

HID

https://www.usb.org/document-library/device-class-definition-hid-111

HID Usage Tables

https://www.usb.org/document-library/hid-usage-tables-122

Mass Storage

https://www.usb.org/sites/default/files/usbmassbulk_10.pdf

Compliance Tools

https://www.usb.org/compliancetools

XHCICV

TBD on AB350M Pro4 Windows10(XHCI)

USB3CV

TBD on AB350M Pro4 Windows10(XHCI)

USB20CV

device CH9 HID description
USB-USB pass pass 2021-08-31 1ef45c
USB-USB pass SET_Protocol:fail 2020-12-24 2b74203b Mouse interface
IBMPC-USB pass pass 39273d
HHKB Alt pass pass 2021-08-17

on Lenovo ThinkPad X201s Windows10(EHCI).

HID Report Dump

usbhid-dump -eall -t10000 -d feed:caaa
005:017:000:STREAM             1609920650.369302
 00 00 04 00 00 00 00 00

005:017:000:STREAM             1609920650.489261
 00 00 00 00 00 00 00 00

005:017:000:STREAM             1609920650.721188
 00 00 04 00 00 00 00 00

USB Capture

logman

https://learn.microsoft.com/ja-jp/windows-hardware/drivers/usbcon/how-to-capture-a-usb-event-trace

https://github.com/MicrosoftDocs/windows-driver-docs/blob/staging/windows-driver-docs-pr/usbcon/how-to-capture-a-usb-event-trace.md

Wireshark

https://wiki.wireshark.org/CaptureSetup/USB

sudo modprobe usbmon
sudo setfacl -m u:$USER:r /dev/usbmon*

usbmon

https://www.kernel.org/doc/Documentation/usb/usbmon.txt

Bus state

https://www.usbmadesimple.co.uk/ums_3.htm

https://en.wikipedia.org/wiki/USB_(Communications)#Signaling_state

Bus State D+ D- Description
Differential 0 L H
Differential 1 H L
Single Ended 0 L L Disconnect(>=2us)
Single Ended 1 H H Illegal
Data J(Low) L H Idle / Connect
Data J(Full) H L Idle / Connect
Data K(Low) H L
Data K(Full) L H

STALL

The STALL packet indicates that the endpoint has halted, or a control pipe does not support a certain request.

The host must never issue a STALL handshake packet.

https://www.silabs.com/community/mcu/8-bit/knowledge-base.entry.html/2017/06/18/the_role_of_stallha-pQTe

Control Transfer

https://www.beyondlogic.org/usbnutshell/usb4.shtml#Control p.225 of USB Rev 2.0

Control transfer is comprised of two or three transaction stages.

Setup stage

Device returns ACK or no response on error. STALL and NAK can be used.

SETUP[h] - DATA0[h] - ACK[d]

Data stage

This is optional.

IN[h] - DATAx[d] - ACK[h]
OUT[h] - DATAx[h] - ACK[d]

Status stage

OUT[h] - DATA1(ZLP)[h] - ACK[d]
IN[h] - DATA1(ZLP)[d] - ACK[h]

STALL on Control Transfer

8.5.3

When a STALL handshake is sent by a control endpoint in either the Data or Status stages of a control transfer, a STALL handshake must be returned on all succeeding accesses to that endpoint until a SETUP PID is received. The endpoint is not required to return a STALL handshake after it receives a subsequent SETUP PID. For the default endpoint, if an ACK handshake is returned for the SETUP transaction, the host expects that the endpoint has automatically recovered from the condition that caused the STALL and the endpoint must operate normally.

8.5.3.4

Control pipes have the unique ability to return a STALL handshake due to function problems in control transfers. If the device is unable to complete a command, it returns a STALL in the Data and/or Status stages of the control transfer. Unlike the case of a functional stall, protocol stall does not indicate an error with the device. The protocol STALL condition lasts until the receipt of the next SETUP transaction, and the function will return STALL in response to any IN or OUT transaction on the pipe until the SETUP transaction is received. In general, protocol stall indicates that the request or its parameters are not understood by the device and thus provides a mechanism for extending USB requests. A control pipe may also support functional stall as well, but this is not recommended. This is a degenerative case, because a functional stall on a control pipe indicates that it has lost the ability to communicate with the host. If the control pipe does support functional stall, then it must possess a Halt feature, which can be set or cleared by the host. Chapter 9 details how to treat the special case of a Halt feature on a control pipe. A well-designed device will associate all of its functions and Halt features with non-control endpoints. The control pipes should be reserved for servicing USB requests.

Device Qualifier Descriptor

A high-speed capable device that has different device information for full-speed and high-speed must have a Device Qualifier Descriptor (USB_DEVICE_QUALIFIER_DESCRIPTOR). For example, if the device is currently operating at full-speed, the Device Qualifier returns information about how it would operate at high-speed and vice-versa.

https://www.keil.com/pack/doc/mw/USB/html/_u_s_b__device__qualifier__descriptor.html

"If the device is attached to a USB 1.1 hub, is operating at Full-Speed, and its USB Device Descriptor bcdUSB field is greater than or equal to 0x200, the hub driver will issue a GET_DESCRIPTOR for descriptor type DEVICE_QUALIFIER (6). The successful completion of the request indicates the device can support USB 2.0 high-speed operation."

https://www.microchip.com/forums/m688392.aspx

Hub

Class-specific Requests

11.24.2

Hub Class Requests:

Request bmRequestType bRequest wValue wIndex wLength Data
ClearHubFeature 00100000B CLEAR_ FEATURE Feature Selector Zero Zero None
ClearPortFeature 00100011B CLEAR_ FEATURE Feature Selector Selector, Port Zero None
ClearTTBuffer 00100011B CLEAR_TT_BUFFER Dev_Addr, EP_Num TT_port Zero None
GetHubDescriptor 10100000B GET_DESCRIPTOR Descriptor Type and Descriptor Index Zero or Language ID Descriptor Length Descriptor
GetHubStatus 10100000B GET_ STATUS Zero Zero Four Hub Status and Change Status
GetPortStatus 10100011B GET_ STATUS Zero Port Four Port Status and Change Status
ResetTT 00100011B RESET_TT Zero Port Zero None
SetHubDescriptor 00100000B SET_DESCRIPTOR Descriptor Type and Descriptor Index Zero or Language ID Descriptor Length Descriptor
SetHubFeature 00100000B SET_ FEATURE Feature Selector Zero Zero None
SetPortFeature 00100011B SET_ FEATURE Feature Selector Selector, Port Zero None
GetTTState 10100011B GET_TT_STATE TT_Flags Port TT State Length TT State
StopTT 00100011B STOP_TT Zero Port Zero None

Hub Class Request Codes:

bRequest Value
GET_ STATUS 0
CLEAR_ FEATURE 1
RESERVED 2
SET_ FEATURE 3
Reserved 4-5
GET_DESCRIPTOR 6
SET_DESCRIPTOR 7
CLEAR_TT_BUFFER 8
RESET_TT 9
GET_TT_STATE 10
STOP_TT 11

Hub Class Feature Selectors:

Recipient Value
C_HUB_LOCAL_POWER Hub 0
C_HUB_OVER_CURRENT Hub 1
PORT_CONNECTION Port 0
PORT_ENABLE Port 1
PORT_SUSPEND Port 2
PORT_OVER_CURRENT Port 3
PORT_RESET Port 4
PORT_POWER Port 8
PORT_LOW_SPEED Port 9
C_PORT_CONNECTION Port 16
C_PORT_ENABLE Port 17
C_PORT_SUSPEND Port 18
C_PORT_OVER_CURRENT Port 19
C_PORT_RESET Port 20
PORT_TEST Port 21
PORT_INDICATOR Port 22

Get Port Status

11.24.2.7

bmRequestType bRequest wValue wIndex wLength Data
10100011B GET_STATUS Zero Port Four Port Status and Change Status

wPortStatus:

bit Desc
0 Current Connect Status: ( PORT_CONNECTION )
1 Port Enabled/Disabled: ( PORT_ENABLE )
2 Suspend: ( PORT_SUSPEND )
3 Over-current: ( PORT_OVER_CURRENT )
4 Reset : ( PORT_RESET )
5-7 Reserved
8 Port Power: ( PORT_POWER )
9 Low- Speed Device Attached: ( PORT_LOW_SPEED )
10 High-speed Device Attached: ( PORT_HIGH_SPEED )
11 Port Test Mode : ( PORT_TEST )
12 Port Indicator Control: (PORT_INDICATOR)
13-15 Reserved

wPortChange:

bit Desc
0 Connect Status Change: ( C_PORT_CONNECTION )
1 Port Enable/Disable Change: ( C_PORT_ENABLE )
2 Suspend Change: ( C_PORT_SUSPEND )
3 Over-Current Indicator Change: ( C_PORT_OVER_CURRENT )
4 Reset Change: ( C_PORT_RESET )
5-15 Reserved These bits return 0 when read.

Clear Port Feature

11.24.2.2

bmRequestType bRequest wValue wIndex wLength Data
00100011B CLEAR_ FEATURE Feature Selector Selector, Port Zero None

Clearing a feature disables that feature or starts a process associated with the feature; refer to Table 11-17 for the feature selector definitions. If the feature selector is associated with a status change, clearing that status change acknowledges the change. This request format is used to clear the following features:

  • PORT_ENABLE
  • PORT_SUSPEND
  • PORT_POWER
  • PORT_INDICATOR
  • C_PORT_CONNECTION
  • C_PORT_RESET
  • C_PORT_ENABLE
  • C_PORT_SUSPEND
  • C_PORT_OVER_CURRENT

Terms

The following terms are defined by the USB specification and are included here to help facilitate this discussion:

https://www.netbsd.org/gallery/presentations/bsh/2016_AsiaBSDCon/netbsd_usbp.pdf

USB function

A USB function transmits or receives data or control information over the bus. Typically, a function is implemented as a separate peripheral device, but a physical package may implement multiple USB functions and an embedded hub with single USB port. From the viewpoint of system software, a USB function is same as a USB device.

USB interface

A USB interface is a related set of endpoints that present a single feature of the USB function to the host. A USB function can have multiple USB interfaces as shown in Figure 2. All USB interfaces in a USB function share single USB address.

Device endpoint

An endpoint is a uniquely identifiable portion of a USB device that is the terminus of a communication flow between the host and device.

Compound device

A USB device that has multiple USB functions in it. (Figure 1)

Composite device

A USB device that has multiple USB interfaces that are controlled independently of each other.

Linux USB

Restart host driver

echo -n "0000:00:14.0" | sudo tee /sys/bus/pci/drivers/xhci_hcd/unbind
sleep 5
echo -n "0000:00:14.0" | sudo tee /sys/bus/pci/drivers/xhci_hcd/bind
Clone this wiki locally