LicheeRV Nano RNDIS interface not registering on Windows 10/11
Less of an issue and more of a currently documented fact - after enabling the RNDIS gadget, Windows will not automatically install the correct RNDIS driver and enable the interface - you have to manually set the driver per instructions here: https://wiki.sipeed.com/hardware/en/lichee/RV_Nano/5_peripheral.html#USB-RNDIS-Network-Port
However if I change the compatible class/subclass/protocol to E0/01/03 respectively then this "just works" on windows - no need to explicitly override the driver, Windows auto-detects and installs the driver by itself.
I was able to make this change by adding the three additional lines to run_usb.sh immediately after Label/data is set: https://github.com/sipeed/LicheeRV-Nano-Build/blob/main/ramdisk/rootfs/common_uclibc/etc/run_usb.sh#L146
....
echo "XYZ Device" >$CVI_FUNC/rndis.usb$FUNC_NUM/os_desc/interface.rndis/Label/data
echo "E0" >$CVI_FUNC/rndis.usb$FUNC_NUM/class
echo "01" >$CVI_FUNC/rndis.usb$FUNC_NUM/subclass
echo "03" >$CVI_FUNC/rndis.usb$FUNC_NUM/protocol
I have tested this change on Windows 11 24H2 and Ubuntu 22.04 and the gadget registers correctly. I have not tested this on macOS or other linux and windows versions, but I have reasonable belief that it should work everywhere.
So open questions:
- Is there a reason this wasn't done before?
- The source repo has four different copies of run_usb.sh common_uclibc and three different overlay versions - which one ultimately makes it into the image, and would it make sense to patch all of them?
Just create /boot/usb.rndis or /boot/usb/ncm and reboot, https://github.com/sipeed/LicheeRV-Nano-Build/blob/main/buildroot/board/cvitek/SG200X/overlay/etc/init.d/S08usbdev this script will do all for you, >=win11 use NCM, <win11 use RNDIS, no futher manually operation you need to do(the documentation out of date)
Oh that approach is much nicer - it both has the correct defaults and has an easier way to customize - thank you @Neutree
I began debugging this a while ago and went back to check that the relevant files (run_usb.sh hadn't changed) but didn't bother to check that there wasn't a whole different way of initializing the USB gadget that fixes my issue.
Following along with the same approach in S08usbdev can you support setting host_addr and dev_addr as well? The equivalent lines I used in run_usb.sh are:
echo "00:22:82:ab:fd:22" >$CVI_FUNC/rndis.usb$FUNC_NUM/host_addr
echo "00:22:82:cd:fc:22" >$CVI_FUNC/rndis.usb$FUNC_NUM/dev_addr
This becomes really important when plugging the USB gadget into another modern linux machine - if the addresses are left to be randomly generated on each boot, then the interface name also changes on the computer where the gadget is plugged into. The usual approach of setting g_ether dev_addr and host_addr module properties (either via kernel cmdline or modprobe.d) don't seem to work - I guess because g_ether is compiled in rather than loaded as a module? But setting it via configfs before gadget initialization does work great.
https://github.com/sipeed/LicheeRV-Nano-Build/blob/main/buildroot/board/cvitek/SG200X/overlay/etc/init.d/S30gadget_nic
Maybe I'm misreading above, but doesn't /boot/usb.rndis.mac and /boot/usb.ncm.mac set the MAC address of the usb0 interface as viewed by the LicheeRV Nano linux instance?
How would I set the MAC address of the rndis/ncm device as viewed by the the machine I'm plugging my LicheeRV into? Or are they always the same MAC address with above init script?