Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix wrong BOS response length in Linux, fix #45 #49

Merged
merged 1 commit into from
Dec 7, 2022

Conversation

ycwan9
Copy link
Contributor

@ycwan9 ycwan9 commented Dec 7, 2022

Linux 在 USB 枚举中请求 BOS 时会先发一个 wLength 为 5 的 get descriptor request BOS 包,来获取 BOS 的前 5 字节中的长度信息,然后在下一个 request 中获取 BOS 全文。

因此在发送 BOS response 时要考虑 request 的 wLength 进行截断。

若返回的数据长度比 wLength 大的话会导致 usbip 中的 usbip_recv_xbuff 出错,即日志中的

recv xbuf, 0

Linux first sends a get BOS request with wLength=5, and then request the full BOS in the next packet. Replying the whole BOS results a driver error.
@windowsair
Copy link
Owner

感谢您的pr!

bos应该是usb3.0的特性,这个目前没有默认开启。您已经在linux下测试成功usb3.0了吗?

@ycwan9
Copy link
Contributor Author

ycwan9 commented Dec 7, 2022

我在 Linux 中 USB 2.0 (high-speed) 下测试成功,可以走 CMSIS-DAP v2。

这个 BOS 的机制在 2.0 就会被触发,在原版 stm32 的 daplink 枚举时也能看到这个包。

我感觉 usbip 这个 wLength 的判断对任何包都会有,只不过软件中只有 BOS 这块出了错。

@ycwan9
Copy link
Contributor Author

ycwan9 commented Dec 7, 2022

USB 3.0 我目前没有试过

@windowsair
Copy link
Owner

那应该是系统的行为不同,在windows下,设备如果不是usb3.0的就不会主动请求bos。

Linux下不修改似乎也无影响?因为如果一个2.0设备对于bos产生错误响应,系统不应该认为这是一个致命错误

@ycwan9
Copy link
Contributor Author

ycwan9 commented Dec 7, 2022

不是,我这边就直接失败后断开连接了

$ uname -r
5.15.0-56-generic
kernel: vhci_hcd vhci_hcd.0: pdev(0) rhport(0) sockfd(3)
kernel: vhci_hcd vhci_hcd.0: devid(65537) speed(3) speed_str(high-speed)
kernel: vhci_hcd vhci_hcd.0: Device attached
kernel: usb 3-1: new high-speed USB device number 8 using vhci_hcd
kernel: usb 3-1: SetAddress Request (8) to port 0
kernel: usb 3-1: recv xbuf, 0
kernel: vhci_hcd: stop threads
kernel: vhci_hcd: release socket
kernel: vhci_hcd: disconnect device
kernel: usb 3-1: unable to get BOS descriptor or descriptor too short
kernel: usb 3-1: enqueue for inactive port 0
kernel: usb 3-1: enqueue for inactive port 0
kernel: usb 3-1: enqueue for inactive port 0
kernel: usb 3-1: unable to read config index 0 descriptor/start: -19
kernel: vhci_hcd: vhci_device speed not set

@ycwan9
Copy link
Contributor Author

ycwan9 commented Dec 7, 2022

这里不是 BOS 出错,是 usbip 认为产生了一个格式错误的包

https://github.com/torvalds/linux/blob/v6.0/drivers/usb/usbip/usbip_common.c#L704

@windowsair
Copy link
Owner

好的,已经合入,感谢您的pr!

@windowsair windowsair merged commit 64faa69 into windowsair:master Dec 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants