Automatically use usb_modeswitch for Wifi USB

I've recently purchased a Wifi Dongle containing a Realtek rtl8811CU chipset. I'm using Ubuntu 18.04 LTS.

Luckily, after finding this Github repo, I could compile it and install the driver without any problem.

However, every time I connect the dongle, is detected as a Disk, and I need to run usb_modeswitch to make it work:

$ lsusb
 [...]
 Bus 001 Device 013: ID 0bda:1a2b Realtek Semiconductor Corp. 
$ sudo usb_modeswitch -KW -v 0bda -p 1a2b
$ lsusb
 [...]
 Bus 001 Device 014: ID 0bda:c811 Realtek Semiconductor Corp.

The device ID changes and now I can correctly use my Wifi dongle.

I've tried to add this entry, to the udev rules, located in /lib/udev/rules.d/40-usb_modeswitch.rules, supposedly to run the command every time the device is detected:

 # Realtek 8211CU Wifi AC USB
 ATTR{idVendor}=="0bda", ATTR{idProduct}=="1a2b", RUN+="usb_modeswitch '/%k'"

But then I recconect, and nothing happens.

I've checked that maybe you need a service to do this, but it seems that cannot be activated.

$ systemctl --all | grep usb_modeswitch
● [email protected]    loaded    failed   failed    USB_ModeSwitch_1-4.1                                                            
system-usb_modeswitch.slice       loaded    active   active    system-usb_modeswitch.slice    

$ systemctl status [email protected][email protected] - USB_ModeSwitch_1-4.1
Loaded: loaded (/lib/systemd/system/[email protected]; static; vendor preset: enabled)
Active: failed (Result: exit-code) since Thu 2018-10-04 11:49:17 CDT; 2min 5s ago
    Docs: man:usb_modeswitch_dispatcher(1)
Process: 32216 ExecStart=/usr/sbin/usb_modeswitch_dispatcher --switch-mode 1-4.1 (code=exited, status=1/FAILURE)
Main PID: 32216 (code=exited, status=1/FAILURE)

oct 04 11:49:17  systemd[1]: Starting USB_ModeSwitch_1-4.1...
oct 04 11:49:17  usb_modeswitch_dispatcher[32216]: Could not read attribute: No such file or directory
oct 04 11:49:17  usb_modeswitch_dispatcher[32216]: Could not read attribute: No such file or directory
oct 04 11:49:17  systemd[1]: [email protected]: Main process exited, code=exited, status=1/FAILURE
oct 04 11:49:17  systemd[1]: [email protected]: Failed with result 'exit-code'.
oct 04 11:49:17  systemd[1]: Failed to start USB_ModeSwitch_1-4.1.

Seems that there is a problem with the Ubuntu wrapper, does anyone knows how I can investigate further? I'm new to systemd and udev rules, so I'm not really sure where to find more logs or debug features.


Solution 1:

I've found the way to do it. I've modified the file /lib/udev/rules.d/40-usb_modeswitch.rules appending before the line LABEL="modeswitch_rules_end" the following:

# Realtek 8211CU Wifi AC USB
ATTR{idVendor}=="0bda", ATTR{idProduct}=="1a2b", RUN+="/usr/sbin/usb_modeswitch -K -v 0bda -p 1a2b"

After that, every time I connected the wifi dongle, the disk doesn't appear and automatically the Wifi is detected. Maybe it's not the cleanest method, but it works.

Solution 2:

Have you tried live usb without install to try if it's a problem with your Ubuntu downloaded? I recommend you try XUbuntu 18.04 live version to confirm if the wifi works in your laptop, you can download from here and try it and tell us if it works or still can't detected your dongle, I'm using XUbuntu 18.04, it reconigzes my dongle usb although in screen appears two wifis icons (1 for dongle usb and other for my other default wifi) but it works for me:

https://xubuntu.org/download