USB WIFI 5Ghz RTL8811AU / RTL8811CU

This post is a guide on how to prepare the firmware for a USB AC Wifi adapter with the RTL8811CU chipset.

I had read that the firmware of a USB Wifi adapter with the RTL8811au chipset would be supported by upcoming OSMC updates. Armed with this knowledge I order a Wifi USB adapter from Aliexpress for my rpi2 that was advertised as including the RTL8811au chipset. Once it arrived, the USB Wifi instead included the RTL8811cu, a different chipset. Most of the AC USB Wifi dongles seems pretty much similar so I suspect this is not a unique case of a RTL8811au advertised chipset arriving as a RTL8811cu. Anyway, I managed to build the firmware and my rpi2 is now able to connect to 5Ghz Wifi networks.

I followed the guide from the following github page: [url]https://github.com/brektrou/rtl8821CU[/url]

However, when running DKMS-install.sh it will break as some of the linux-headers files from OSMC are missing. To resolve this issue, go to kernel.org and download the kernel source.

I downloaded the kernel linux-4.19.146, extracted the tar and then copied the /include/linux to the folder where the firmware was being build (~/rtl8821CU in my case). I then replaced the OSMC kernel headers with the downloaded ones.

sudo apt install rbp2-headers-$(uname -r)
sudo rm -r /usr/src/rbp2-headers-$(uname -r)/include/linux/* 
sudo cp -ar ~/rtl8821CU/include/linux/* /usr/src/rbp2-headers-$(uname -r)/include/linux/
sudo ln -s /usr/src/rbp2-headers-$(uname -r) /lib/modules/$(uname -r)/build

After this, the command ./dkms-install.sh or make if not using dkms runs fine. Takes more than 20 mins to compile. The Pi 2 is not a powerful machine, be patient!

After it complied, I then was able to use the firmware.

 sudo modprobe 8821cu

My final issue was specific to my USB dongle. Whenever the Pi was rebooted, it mounted as media storage as it included a partition for Windows drivers. I sourced the code from [url]https://github.com/uzh-rpg/rpg_dwa171_wifidongle[/url] to stop mounting as USB media on boot. If your dongle doesn’t include a partition with Windows drivers you don’t need this.

Created a file stopmounting.sh and included the following:

#!/bin/bash

# Sudo check
if [ "$EUID" -ne 0 ]
  then echo "Please run this script with sudo"
  exit
fi

# Install usb-modeswitch package is not available
echo 'Check if usb-modeswtich package is installed'

if dpkg --get-selections | grep -q "^usb-modeswitch\s*install$"; then 
   echo 'Package usb-modeswtich already installed! Continuing...'
else
   echo 'Getting usb-modeswitch package'
   if apt install -y usb-modeswitch; then
        echo 'Package installed'
   else
        echo 'Could not get usb-modeswitch package. Exiting...'
        exit 
   fi  
fi

# Add script to switch usb mode
echo 'Adding script to switch USB mode to /usr/bin'

SCRIPT=/usr/bin/dwa171script
cat > $SCRIPT << EOL
#!/bin/bash
usb_modeswitch -KW -v 0bda -p 1a2b
EOL

# Make it executable
echo 'Making it executable'
   
if [ -e $SCRIPT ]; then
   chmod +x $SCRIPT
else
   echo "File $SCRIPT does not exist."   
fi

# Create rule to run script as dongle gets mounted
echo 'Adding udev rule'

cat > /etc/udev/rules.d/dwa171.rules << EOL
ATTRS{idVendor}=="0bda", ATTRS{idProduct}=="1a2b", RUN+="/usr/bin/dwa171script"
EOL

# Reload rules
echo 'Reloading udev rules'

udevadm control --reload-rules

# Done
echo 'Done, try plugging in the dongle'

Then made the file executable and ran the script.

sudo chmod +x stopmounting.sh
sudo ./stopmounting.sh

After this, it’s been plain sailing and no issues with connectivity so far.

I hope this helps people who are interested in having a USB Wifi 5Ghz dongle and were stuck with a RTL8811cu chipset.

1 Like

Thanks for the write-up.

The one comment I have is that you recommend using DKMS (Dynamic Kernel Module Support). Perhaps things will change in the move to Debian Buster but currently DKMS is not likely to work reliably on OSMC because:

  1. As you already mention, you need to download the kernel source code from kernel.org and use this to fix the OSMC kernel headers. This need for a manual step breaks the whole reason for DKMS, which is to (re)build kernel modules automatically when the kernel changes.

  2. Currently – and again this might change in Buster – there is no automatic mechanism for fetching the new OSMC kernel headers when a kernel update occurs.

  3. Last time I looked, there was also a need to run the following command (this is for the Pi2/3):
    sudo ln -s /usr/src/rbp2-headers-$(uname -r) /lib/modules/$(uname -r)/build
    Again, this might not be necessary when we move to Buster.

We’ll see how things fare with Buster, but you might want to consider amending the instructions to those for building without DKMS.

Thanks for the update and your comment 3. I did have to include it as well. I think I also forgot to mention that I needed first to download OSMC headers before copying the /include/Linux folder from kernel source code.

sudo apt install rbp2-headers-4.19.122-1-osmc

The guide above would work for the regular compilation. Rather than using dkms using the non-dkms guide from the github page would work after downloading osmc headers, copying the/include/linux folder from kernel source code and symlinking as per your comment 3. above.

I tested on a spare installation and make command ran fine after fixing the headers and symlinking.

Cheers