FreeSpacenav / spacenavd

Free user-space driver for 6-dof space-mice.
http://spacenav.sourceforge.net
GNU General Public License v3.0
274 stars 55 forks source link

USB device found but not supported #111

Closed GarmischWg closed 1 month ago

GarmischWg commented 1 month ago

I am working with the spacemouse inside WSL2 and docker.

Using usbipd on windows, i am able to pass in the use device into the container.

The container is running in privillaged mode and all devices including usb devices has been passthrough to the container.

volumes:
      - /tmp/.X11-unix:/tmp/.X11-unix
      - /mnt/wslg:/mnt/wslg
      - ./src:/catkin_ws/src
      - /dev:/dev
    devices:
      - /dev/bus/usb:/dev/bus/usb
    privileged: true
    network_mode: host
    stdin_open: true
    tty: true

However, when launching spacenavd, i got the following error:

root@Tower01:/catkin_ws# spacenavd -v -d
Spacenav daemon 0.6
failed to open config file /etc/spnavrc: No such file or directory. using defaults.
Device detection, parsing /proc/bus/input/devices
found usb device [256f:c652]: "3Dconnexion 3Dconnexion Universal Receiver" ((null)) 
failed to find any supported devices
trying to open X11 display ":0"
   XAUTHORITY=/root/.Xauthority
^Cclosing X11 connection to display ":0"

It is normal that it cannot connect to a display, due to it being inside WSL. But it is able to find the "3Dconnexion Universal Receiver" yet it states that it is not supported.

Subsequent attempts in debugging shows that the device is indeed detected inside the container, with all permissions granted:

root@Tower01:/catkin_ws# lsusb
Bus 002 Device 001: ID 1d6b:0003  
Bus 001 Device 002: ID 256f:c652 3Dconnexion 3Dconnexion Universal Receiver
Bus 001 Device 001: ID 1d6b:0002  

root@Tower01:/catkin_ws# ls -l /dev/bus/usb/001/002
crwxrwxrwx 1 root root 189, 1 Sep  4 09:16 /dev/bus/usb/001/002
# Bad practice, i know

root@Tower01:/catkin_ws# dmesg | grep -i 3dconnexion
[   16.794471] usb 1-1: Product: 3Dconnexion Universal Receiver
[   16.794472] usb 1-1: Manufacturer: 3Dconnexion
[   16.810355] input: 3Dconnexion 3Dconnexion Universal Receiver as /devices/platform/vhci_hcd.0/usb1/1-1/1-1:1.0/0003:256F:C652.0001/input/input1
[   16.810360] hid-generic 0003:256F:C652.0001: input: USB HID v1.11 Multi-Axis Controller [3Dconnexion 3Dconnexion Universal Receiver] on usb-vhci_hcd.0-1/input0

root@Tower01:/catkin_ws# usb-devices 

T:  Bus=01 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#=  1 Spd=480 MxCh= 8
D:  Ver= 2.00 Cls=09(hub  ) Sub=00 Prot=01 MxPS=64 #Cfgs=  1
P:  Vendor=1d6b ProdID=0002 Rev=05.15
S:  Manufacturer=Linux 5.15.133.1-microsoft-standard-WSL2 vhci_hcd
S:  Product=USB/IP Virtual Host Controller
S:  SerialNumber=vhci_hcd.0
C:  #Ifs= 1 Cfg#= 1 Atr=e0 MxPwr=0mA
I:  If#=0x0 Alt= 0 #EPs= 1 Cls=09(hub  ) Sub=00 Prot=00 Driver=hub

T:  Bus=01 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#=  2 Spd=12  MxCh= 0
D:  Ver= 2.00 Cls=00(>ifc ) Sub=00 Prot=00 MxPS=32 #Cfgs=  1
P:  Vendor=256f ProdID=c652 Rev=01.06
S:  Manufacturer=3Dconnexion
S:  Product=3Dconnexion Universal Receiver
C:  #Ifs= 5 Cfg#= 1 Atr=80 MxPwr=98mA
I:  If#=0x0 Alt= 0 #EPs= 1 Cls=03(HID  ) Sub=00 Prot=00 Driver=usbhid
I:  If#=0x1 Alt= 0 #EPs= 1 Cls=03(HID  ) Sub=00 Prot=00 Driver=usbhid
I:  If#=0x2 Alt= 0 #EPs= 1 Cls=03(HID  ) Sub=00 Prot=00 Driver=usbhid
I:  If#=0x3 Alt= 0 #EPs= 1 Cls=03(HID  ) Sub=00 Prot=00 Driver=usbhid
I:  If#=0x4 Alt= 0 #EPs= 1 Cls=03(HID  ) Sub=00 Prot=00 Driver=usbhid

T:  Bus=02 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#=  1 Spd=5000 MxCh= 8
D:  Ver= 3.00 Cls=09(hub  ) Sub=00 Prot=03 MxPS= 9 #Cfgs=  1
P:  Vendor=1d6b ProdID=0003 Rev=05.15
S:  Manufacturer=Linux 5.15.133.1-microsoft-standard-WSL2 vhci_hcd
S:  Product=USB/IP Virtual Host Controller
S:  SerialNumber=vhci_hcd.0
C:  #Ifs= 1 Cfg#= 1 Atr=e0 MxPwr=0mA
I:  If#=0x0 Alt= 0 #EPs= 1 Cls=09(hub  ) Sub=00 Prot=00 Driver=hub
root@Tower01:/catkin_ws# usb-devices 

T:  Bus=01 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#=  1 Spd=480 MxCh= 8
D:  Ver= 2.00 Cls=09(hub  ) Sub=00 Prot=01 MxPS=64 #Cfgs=  1
P:  Vendor=1d6b ProdID=0002 Rev=05.15
S:  Manufacturer=Linux 5.15.133.1-microsoft-standard-WSL2 vhci_hcd
S:  Product=USB/IP Virtual Host Controller
S:  SerialNumber=vhci_hcd.0
C:  #Ifs= 1 Cfg#= 1 Atr=e0 MxPwr=0mA
I:  If#=0x0 Alt= 0 #EPs= 1 Cls=09(hub  ) Sub=00 Prot=00 Driver=hub

T:  Bus=01 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#=  2 Spd=12  MxCh= 0
D:  Ver= 2.00 Cls=00(>ifc ) Sub=00 Prot=00 MxPS=32 #Cfgs=  1
P:  Vendor=256f ProdID=c652 Rev=01.06
S:  Manufacturer=3Dconnexion
S:  Product=3Dconnexion Universal Receiver
C:  #Ifs= 5 Cfg#= 1 Atr=80 MxPwr=98mA
I:  If#=0x0 Alt= 0 #EPs= 1 Cls=03(HID  ) Sub=00 Prot=00 Driver=usbhid
I:  If#=0x1 Alt= 0 #EPs= 1 Cls=03(HID  ) Sub=00 Prot=00 Driver=usbhid
I:  If#=0x2 Alt= 0 #EPs= 1 Cls=03(HID  ) Sub=00 Prot=00 Driver=usbhid
I:  If#=0x3 Alt= 0 #EPs= 1 Cls=03(HID  ) Sub=00 Prot=00 Driver=usbhid
I:  If#=0x4 Alt= 0 #EPs= 1 Cls=03(HID  ) Sub=00 Prot=00 Driver=usbhid

T:  Bus=02 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#=  1 Spd=5000 MxCh= 8
D:  Ver= 3.00 Cls=09(hub  ) Sub=00 Prot=03 MxPS= 9 #Cfgs=  1
P:  Vendor=1d6b ProdID=0003 Rev=05.15
S:  Manufacturer=Linux 5.15.133.1-microsoft-standard-WSL2 vhci_hcd
S:  Product=USB/IP Virtual Host Controller
S:  SerialNumber=vhci_hcd.0
C:  #Ifs= 1 Cfg#= 1 Atr=e0 MxPwr=0mA
I:  If#=0x0 Alt= 0 #EPs= 1 Cls=09(hub  ) Sub=00 Prot=00 Driver=hub

This is the spacemouse that i bought: https://3dconnexion.com/us/product/spacemouse-wireless/

I have ran out of methods to debug this issue, any idea what is going on and how to solve it? Thank you very much.

GarmischWg commented 1 month ago

Here is more information regarding the setup:

jtsiomb commented 1 month ago

In the "found usb device" line, the null in the parenthesis signifies that it couldn't find which evdev device file corresponds to that device. Can you post the contents of /proc/bus/input/devices with the device plugged in?

GarmischWg commented 1 month ago

inside wsl, i find that /proc/bus/input/devices directory exists but is empty:

garmi@Tower01:~/main_ws/ros_env$ ls -l /proc/bus/input/devices 
-r--r--r-- 1 root root 0 Sep  4 22:58 /proc/bus/input/devices
garmi@Tower01:~/main_ws/ros_env$ lsusb
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 002: ID 256f:c652 3Dconnexion Universal Receiver
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

i took a look into another tutorial: https://github.com/NVlabs/spacemouse-extension And i realize that spacemouse never appeared in /dev directory, and i went ahead to create and modify /etc/udev/rules.d/99-spacemouse.rules with the following content: SUBSYSTEM=="usb", ATTRS{idVendor}=="256f", ATTRS{idProduct}=="c652", MODE="0666", SYMLINK+="spacemouse"

After that, when i run ls /dev, i can see spacemouse in the dev directory, but /proc/bus/input/devices is still empty

garmi@Tower01:~/main_ws/ros_env$ ls -l /proc/bus/input/devices 
-r--r--r-- 1 root root 0 Sep  4 22:58 /proc/bus/input/devices

Note that the above actions are done in WSL, not in the docker container.

GarmischWg commented 1 month ago

After further research, the problem seems to be on the WSL side, because /dev/input does not exist on WSL.

https://www.reddit.com/r/bashonubuntuonwindows/comments/ju64oa/wsl2_devinput/ https://github.com/microsoft/WSL/discussions/10474 https://github.com/microsoft/WSL/issues/7747

Given the limitation that WSL cannot have /dev/input and all usb device will only appear in /dev/bus/usb/ lrwxrwxrwx 1 root root 15 Sep 4 23:20 spacemouse -> bus/usb/001/005

i found that WSL in general has poor support for usb device and people have to rebuild the kernal inorder to use usb device inside WSL which i am not comfortable doing.

jtsiomb commented 1 month ago

I see. Spacenavd relies on evdev to talk to USB devices, if that's not available on WSL (or with the default kernel in any case), there's no way to use USB devices with spacenavd.