usb-usbd-hubdesc: usbd rejects hubs with 8, 16, ... ports
sys/src/cmd/usb/usbd/usbd.c checks the length of a USB 2 hub
descriptor as if its two port bitmaps had the same size:
nmap = 1 + h->nport/8;
if(nr < 7 + 2*nmap){
They do not (USB 2.0 table 11-13). DeviceRemovable has a reserved
bit 0 and one bit per port, nmap bytes. PortPwrCtrlMask has one
bit per port and no reserved bit, (nport+7)/8 bytes. The sizes
differ when the port count is a multiple of 8: an 8-port hub sends
a 10-byte descriptor, usbd wants 11 and prints
usbd: /dev/usb/epN.0: descr. too small
and every device behind the hub is lost.
The fix checks for the two sizes the specification gives, and
reads PortPwrCtrlMask with its own layout, port i at bit i-1, so
the loop stays within the descriptor.
Apply
cd /
ape/patch -p0 < /path/to/usb-usbd-hubdesc/usb-usbd-hubdesc.diff
Rebuild
cd /sys/src/cmd/usb && mk install
usbd is part of the kernel (bootdir), so rebuild and install
the kernel as well.
Verification
Attach a hub with 8 ports and a device behind it.
cat /dev/usb/ctl
Before: the hub's epN.0 is missing, usbd prints the line
above and the device behind it does not show up.
After: the hub and the device are listed.
|