Skip to content

Add support for rtl8821cu WiFi Dongle#1899

Merged
agners merged 4 commits intohome-assistant:devfrom
s-ol:rtl8821cu
May 16, 2022
Merged

Add support for rtl8821cu WiFi Dongle#1899
agners merged 4 commits intohome-assistant:devfrom
s-ol:rtl8821cu

Conversation

@s-ol
Copy link
Contributor

@s-ol s-ol commented May 12, 2022

Using the module source code from https://github.com/brektrou/rtl8821CU, which appears to be what Hardkernel use for their own images.

The dongle needs to be put into working mode using:

usb_modeswitch -KW -v 0bda -p 1a2b

I'm note sure where that would go right now, but it would be good to add that in an udev rule:

# SPDX-License-Identifier: GPL-2.0-or-later
# Copyright (C) 2018-present Team CoreELEC (https://coreelec.org)

# put wifi module from storage to wifi mode
SUBSYSTEM=="usb", ACTION=="add", ATTR{idVendor}=="0bda", ATTR{idProduct}=="1a2b", \
  RUN+="/bin/sh -c 'export usb_modeswitch=/storage/.kodi/addons/virtual.system-tools/bin/usb_modeswitch; [ -x ${usb_modeswitch} ] && ${usb_modeswitch} -KW -v ${ID_VENDOR_ID} -p ${ID_MODEL_ID} || echo usb_modeswitch: please install system-tools addon >/dev/kmsg'"

I've only enabled it for ODROID N2 right now since that's what I'm using, but if anyone lets me know what else to do I'm happy to change anything here.

See also this forum thread with more links: https://community.home-assistant.io/t/how-can-i-use-install-the-realtek-rtl8821cu-wifi-usb-dongle-on-home-assistant-os/416035/

ODROID WiFi module 5B uses the rtl8821cu chipset.

@homeassistant
Copy link

Hi @s-ol,

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

@s-ol
Copy link
Contributor Author

s-ol commented May 12, 2022

Hm, I just saw that there actually already is an udev ruleset at /usr/lib/udev/rules.d/40-usb_modeswitch.rules on my running instance that actually contains the right vendor/product ids:

# D-Link DWA-171 Wifi Dongle
ATTR{idVendor}=="0bda", ATTR{idProduct}=="1a2b", RUN+="usb_modeswitch '/%k'"

I don't know a lot about udev, but this looks exactly right, how come it isn't triggered?
I tried running udevadm monitor while plugging in the dongle and this is what I get:

KERNEL[1182.992695] add      /devices/platform/soc/ffe09000.usb/ff500000.usb/xhci-hcd.1.auto/usb1/1-1/1-1.2 (usb)
KERNEL[1182.992999] change   /devices/platform/soc/ffe09000.usb/ff500000.usb/xhci-hcd.1.auto/usb1/1-1/1-1.2 (usb)
KERNEL[1182.993109] add      /devices/platform/soc/ffe09000.usb/ff500000.usb/xhci-hcd.1.auto/usb1/1-1/1-1.2/1-1.2:1.0 (usb)
KERNEL[1182.993491] add      /devices/virtual/workqueue/scsi_tmf_0 (workqueue)
KERNEL[1182.993767] add      /devices/platform/soc/ffe09000.usb/ff500000.usb/xhci-hcd.1.auto/usb1/1-1/1-1.2/1-1.2:1.0/host0 (scsi)
KERNEL[1182.993851] add      /devices/platform/soc/ffe09000.usb/ff500000.usb/xhci-hcd.1.auto/usb1/1-1/1-1.2/1-1.2:1.0/host0/scsi_host/host0 (scsi_host)
KERNEL[1182.993975] bind     /devices/platform/soc/ffe09000.usb/ff500000.usb/xhci-hcd.1.auto/usb1/1-1/1-1.2/1-1.2:1.0 (usb)
KERNEL[1182.994102] bind     /devices/platform/soc/ffe09000.usb/ff500000.usb/xhci-hcd.1.auto/usb1/1-1/1-1.2 (usb)
UDEV  [1182.997972] add      /devices/virtual/workqueue/scsi_tmf_0 (workqueue)
UDEV  [1183.015834] add      /devices/platform/soc/ffe09000.usb/ff500000.usb/xhci-hcd.1.auto/usb1/1-1/1-1.2 (usb)
UDEV  [1183.035944] change   /devices/platform/soc/ffe09000.usb/ff500000.usb/xhci-hcd.1.auto/usb1/1-1/1-1.2 (usb)
UDEV  [1183.038000] add      /devices/platform/soc/ffe09000.usb/ff500000.usb/xhci-hcd.1.auto/usb1/1-1/1-1.2/1-1.2:1.0 (usb)
UDEV  [1183.039417] add      /devices/platform/soc/ffe09000.usb/ff500000.usb/xhci-hcd.1.auto/usb1/1-1/1-1.2/1-1.2:1.0/host0 (scsi)
UDEV  [1183.041047] add      /devices/platform/soc/ffe09000.usb/ff500000.usb/xhci-hcd.1.auto/usb1/1-1/1-1.2/1-1.2:1.0/host0/scsi_host/host0 (scsi_host)
UDEV  [1183.042299] bind     /devices/platform/soc/ffe09000.usb/ff500000.usb/xhci-hcd.1.auto/usb1/1-1/1-1.2/1-1.2:1.0 (usb)
UDEV  [1183.043676] bind     /devices/platform/soc/ffe09000.usb/ff500000.usb/xhci-hcd.1.auto/usb1/1-1/1-1.2 (usb)
KERNEL[1183.998688] add      /devices/platform/soc/ffe09000.usb/ff500000.usb/xhci-hcd.1.auto/usb1/1-1/1-1.2/1-1.2:1.0/host0/target0:0:0 (scsi)
KERNEL[1183.998846] add      /devices/platform/soc/ffe09000.usb/ff500000.usb/xhci-hcd.1.auto/usb1/1-1/1-1.2/1-1.2:1.0/host0/target0:0:0/0:0:0:0 (scsi)
KERNEL[1183.998991] add      /devices/platform/soc/ffe09000.usb/ff500000.usb/xhci-hcd.1.auto/usb1/1-1/1-1.2/1-1.2:1.0/host0/target0:0:0/0:0:0:0/scsi_device/0:0:0:0 (scsi_device)
KERNEL[1183.999170] add      /devices/platform/soc/ffe09000.usb/ff500000.usb/xhci-hcd.1.auto/usb1/1-1/1-1.2/1-1.2:1.0/host0/target0:0:0/0:0:0:0/bsg/0:0:0:0 (bsg)
UDEV  [1184.001067] add      /devices/platform/soc/ffe09000.usb/ff500000.usb/xhci-hcd.1.auto/usb1/1-1/1-1.2/1-1.2:1.0/host0/target0:0:0 (scsi)
UDEV  [1184.002988] add      /devices/platform/soc/ffe09000.usb/ff500000.usb/xhci-hcd.1.auto/usb1/1-1/1-1.2/1-1.2:1.0/host0/target0:0:0/0:0:0:0 (scsi)
UDEV  [1184.004950] add      /devices/platform/soc/ffe09000.usb/ff500000.usb/xhci-hcd.1.auto/usb1/1-1/1-1.2/1-1.2:1.0/host0/target0:0:0/0:0:0:0/scsi_device/0:0:0:0 (scsi_device)
UDEV  [1184.005245] add      /devices/platform/soc/ffe09000.usb/ff500000.usb/xhci-hcd.1.auto/usb1/1-1/1-1.2/1-1.2:1.0/host0/target0:0:0/0:0:0:0/bsg/0:0:0:0 (bsg)

@s-ol
Copy link
Contributor Author

s-ol commented May 12, 2022

Okay, figured that out too: it seems that the usb_modeswitch buildroot package fails to install the required systemd unit file usb_modeswitch@.service; this because it tests for presence of systemd at install time:

test -d $(SYSDIR) -a -e /usr/bin/systemctl && install --mode=644 usb_modeswitch@.service $(SYSDIR) || test 1

evidently this check fails and the file isn't installed. I guess this is an upstream bug though.

@s-ol
Copy link
Contributor Author

s-ol commented May 12, 2022

Adding this as buildroot/package/usb_modeswitch/0001-fix-systemd-detection.patch should do the trick:

diff --git a/Makefile b/Makefile
index 22bd0e0..72321a4 100755
--- a/Makefile
+++ b/Makefile
@@ -62,7 +62,7 @@
	install -D --mode=755 usb_modeswitch_dispatcher $(SBINDIR)/usb_modeswitch_dispatcher
	install -d $(DESTDIR)/var/lib/usb_modeswitch
	test -d $(UPSDIR) -a -e /sbin/initctl && install --mode=644 usb-modeswitch-upstart.conf $(UPSDIR) || test 1
-	test -d $(SYSDIR) -a \( -e /usr/bin/systemctl -o -e /bin/systemctl \) && install --mode=644 usb_modeswitch@.service $(SYSDIR) || test 1
+	test -d $(SYSDIR) -a \( -e /usr/bin/systemctl -o -e /bin/systemctl -o -e $(PREFIX)/bin/systemctl \) && install --mode=644 usb_modeswitch@.service $(SYSDIR) || test 1

 install: install-script

I'm not sure how close hassos tracks buildroot upstream, should this be included in buildroot-external for the time being to fast-track this PR?

Signed-off-by: s-ol <s+removethis@s-ol.nu>
@s-ol
Copy link
Contributor Author

s-ol commented May 14, 2022

The usb_modeswitch change is now in a PR at home-assistant/buildroot#2. With that PR merged and the submodule updated, the wifi dongle becomes plug and play :)

agners added 3 commits May 16, 2022 11:07
* buildroot ee56159464...666868435d (1):
  > Merge pull request home-assistant#2 from s-ol/fix-usb_modeswitch-systemd
@agners agners changed the title Add support for rtl8821cu wifi dongle (ODROID Wifi module 5B) Add support for rtl8821cu WiFi Dongle May 16, 2022
@agners agners merged commit e7e7c7a into home-assistant:dev May 16, 2022
agners added a commit that referenced this pull request May 19, 2022
* Add rtl8821cu driver

* buildroot ee56159464...666868435d (1):
  > Merge pull request #2 from s-ol/fix-usb_modeswitch-systemd

* Add rtl8821cu support to all boards

Signed-off-by: s-ol <s+removethis@s-ol.nu>
Co-authored-by: Stefan Agner <stefan@agner.ch>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants