Problems with Wifi USB dongle RTL8188EU on Raspberry Pi 3

Hello,
I recently installed FreeBSD 14.2 on my Raspberry Pi 3. As expected the onboard wifi is not usabled. So I tried to use a RTL8188EU wifi USB dongle.
The dmesg command shows the following lines:
rtwn0 on uhub1
rtwn0: <Realtek Edimax N150 Adapter, class 0/0, rev 2.00/0.00, addr 4> on usbus1
rtwn0: MAC/BB RTL8188EU, RF 6052 1T1R
So FreeBSD at least sees the rtl8188EU wifi dongle.
In the Hardware Notes for 14.2 for wlan it seems to be listed as supported (D-Link DWA-121 rev C1A (N150 Nano) RTL8188EU USB 2.0).
/sbin/ifconfig does not show the wlan but just the lan ue0 and the loopback lo0.

I am not sure if I need to manually load kernel module?

I tried bsdconfig and there "Networking Management" and there "Wireless Networks". Then I got the error message:
WARNING! No wireless devices found.
I tested this wifi dongle on Raspbian Linux (Debian) and there it works fine. Afterwards I even tried another RTL wifi dongle (RTL8188CUS) but without success, too. Here the dmesg output:
rtwn0 on uhub1
rtwn0: <Realtek 802.11n WLAN Adapter, class 0/0, rev 2.00/2.00, addr 4> on usbus1
rtwn0: MAC/BB RTL8188CUS, RF 6052 1T1R
The wifi dongle should be the "Edimax EW-7811Un RTL8188CUS USB 2.0" that should be supported, too.
What need to be done to get these supported USB wireless network adapters to run? Is it a special problem on Raspberry PI 3?
I am happy for any advice.

Kind regards,
Roland
 
I've successfully used an Edimax EW-7811Un on Raspberry PI 4 without issue. You can find them cheap on Ebay. I purchased about 10 of them when I first moved to FreeBSD.
 
Someone had this work for them on a different USB wifi device on Discord.
  1. Boot without it plugged in.
  2. After a successful boot, then plug the device in
  3. Try to configure wireless using bsdconfig.
Maybe that will work?
 
I've successfully used an Edimax EW-7811Un on Raspberry PI 4 without issue. You can find them cheap on Ebay. I purchased about 10 of them when I first moved to FreeBSD.
Thank you for your answer. I am almost sure that I have this Edimax EW-7811Un and that all the USB Donlges I have should be in general supported.
I'll do some further experiments. Which FreeBSD version do you use?
I use 14.2 arm64. The output of uname -a is:
FreeBSD mars 14.2-RELEASE FreeBSD 14.2-RELEASE releng/14.2-n269506-c8918d6c7412 GENERIC arm64
I find out that kldstat is the command to show the loaded kernel modules like the linux command <cmd>lsmod</cmd>
The output is:
Id Refs Address Size Name
1 30 0xffff000000000000 13358c8 kernel
2 1 0xffff000001337000 25478 umodem.ko
3 2 0xffff00000135d000 28630 ucom.ko
4 1 0xffff0000aa200000 36000 if_rtwn_usb.ko
5 2 0xffff0000aa236000 79000 wlan.ko
6 1 0xffff0000aa2af000 3f000 rtwn.ko
7 1 0xffff0000aa2ee000 24000 uhid.ko
8 1 0xffff0000aa312000 26000 ums.ko
9 1 0xffff0000aa338000 25000 wmt.ko
I am not an expert on FreeBSD kernel modules but that looks good but hopefully something is missing?
What is the output of kldstat on your Raspberry Pi 4 and what does dmesg show when you plug in the Edimax EW-7811Un USB dongle?
Kind regards,
Roland
 
Someone had this work for them on a different USB wifi device on Discord.
  1. Boot without it plugged in.
  2. After a successful boot, then plug the device in
  3. Try to configure wireless using bsdconfig.
Maybe that will work?
Hello delta0,
now I booted without the USD wifi device and without the logithec keyboad dongle.
The output of kldstat is:
mars: # kldstat
Id Refs Address Size Name
1 6 0xffff000000000000 13358c8 kernel
2 1 0xffff000001337000 25478 umodem.ko
3 2 0xffff00000135d000 28630 ucom.ko
mars: #
After pluging in the Edimax wifi dongle the following dmesg lines were added:
ugen1.4: <Realtek 802.11n WLAN Adapter> at usbus1
rtwn0 on uhub1
rtwn0: <Realtek 802.11n WLAN Adapter, class 0/0, rev 2.00/2.00, addr 4> on usbus1
rtwn0: MAC/BB RTL8188CUS, RF 6052 1T1R
Now the output of kldstat is:
Id Refs Address Size Name
1 16 0xffff000000000000 13358c8 kernel
2 1 0xffff000001337000 25478 umodem.ko
3 2 0xffff00000135d000 28630 ucom.ko
4 1 0xffff0000aa600000 36000 if_rtwn_usb.ko
5 2 0xffff0000aa636000 79000 wlan.ko
6 1 0xffff0000aa6af000 3f000 rtwn.ko
That seems to be good.
The command /sbin/ifconfig -a still shows no wlan:
mars: # /sbin/ifconfig -a
lo0: flags=1008049<UP,LOOPBACK,RUNNING,MULTICAST,LOWER_UP> metric 0 mtu 16384
options=680003<RXCSUM,TXCSUM,LINKSTATE,RXCSUM_IPV6,TXCSUM_IPV6>
inet 127.0.0.1 netmask 0xff000000
inet6 ::1 prefixlen 128
inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1
groups: lo
nd6 options=23<PERFORMNUD,ACCEPT_RTADV,AUTO_LINKLOCAL>
ue0: flags=1008843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST,LOWER_UP> metric 0 mtu 1500
options=80009<RXCSUM,VLAN_MTU,LINKSTATE>
ether b8:27:eb:80:89:92
inet 192.168.178.87 netmask 0xffffff00 broadcast 192.168.178.255
inet6 fe80::ba27:ebff:fe80:8992%ue0 prefixlen 64 scopeid 0x2
media: Ethernet autoselect (100baseTX <full-duplex>)
status: active
nd6 options=23<PERFORMNUD,ACCEPT_RTADV,AUTO_LINKLOCAL>
mars: #
On Rasbian linux there would be a wlan entry shown without ip adress. Then in the old version a wpa_supplicant.conf file was needed with the correct entries. I'm not sure how it should be on FreeBSD.
The bsdconfig show the following results/error message (see attached screenshots)

What am I missing? What could I do to get the devices found. Is there another file I have to edit?

Kind regards,
Roland
 

Attachments

  • bsdconfig_networking.jpg
    bsdconfig_networking.jpg
    51.6 KB · Views: 20
  • bsdconfig_no_wireless_devices_found.jpg
    bsdconfig_no_wireless_devices_found.jpg
    31.9 KB · Views: 19
What does sysctl net.wlan.devices show while usb wifi is plugged in?

If it show something, you may need to configure it in /etc/rc.conf and /etc/wpa_supplicant.conf. For example,

Code:
% sysctl net.wlan.devices
net.wlan.devices: ath0

% grep wlan /etc/rc.conf
wlans_ath0="wlan0"
ifconfig_wlan0="WPA SYNCDHCP"
create_args_wlan0="country TR regdomain ETSI"

% sudo cat /etc/wpa_supplicant.conf
Password:
ctrl_interface=/var/run/wpa_supplicant
eapol_version=2
ap_scan=1
fast_reauth=1

network={
        ssid="example-wifi-name"
        scan_ssid=0
        psk="example-wifi-password"
        priority=5
}
network={
        priority=0
        key_mgmt=NONE
}
 
What does sysctl net.wlan.devices show while usb wifi is plugged in?

If it show something, you may need to configure it in /etc/rc.conf and /etc/wpa_supplicant.conf. For example,

Code:
% sysctl net.wlan.devices
net.wlan.devices: ath0

% grep wlan /etc/rc.conf
wlans_ath0="wlan0"
ifconfig_wlan0="WPA SYNCDHCP"
create_args_wlan0="country TR regdomain ETSI"

% sudo cat /etc/wpa_supplicant.conf
Password:
ctrl_interface=/var/run/wpa_supplicant
eapol_version=2
ap_scan=1
fast_reauth=1

network={
        ssid="example-wifi-name"
        scan_ssid=0
        psk="example-wifi-password"
        priority=5
}
network={
        priority=0
        key_mgmt=NONE
}
Hello Joseph,
thank you very much. The command sysctl net.wlan.devices shows rtwn0 as result.
roland@mars:~ % sysctl net.wlan.devices
net.wlan.devices: rtwn0
roland@mars:~ %
On Linux there is the file /etc/network/interfaces with the content:
# interfaces(5) file used by ifup(8) and ifdown(8)
# Include files from /etc/network/interfaces.d:
source /etc/network/interfaces.d/*

allow-hotplug wlan0
iface wlan0 inet dhcp
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp
Here on FreeBSD it seems that /etc/rc.cong does this. Thank you very much.
I tried the command ifconfig wlan create wlandev rtwn0. That worked.
Afterwards /sbin/ifconfig wlan0 shows the following:
mars: # /sbin/ifconfig wlan0
wlan0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
options=0
ether 74:da:38:e2:35:03
groups: wlan
ssid "" channel 7 (2442 MHz 11g ht/20)
regdomain FCC country US authmode WPA1+WPA2/802.11i privacy MIXED
deftxkey UNDEF txpower 30 bmiss 7 scanvalid 60 protmode CTS ht20
ampdulimit 8k ampdudensity 16 shortgi -stbc -ldpc -uapsd wme
roaming MANUAL
parent interface: rtwn0
media: IEEE 802.11 Wireless Ethernet autoselect (autoselect)
status: no carrier
nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>
mars: #
Super! :)
So I added to /etc/rc.conf the line:
wlans_rtwn0="wlan0"
No I adapted the file /etc/wpa_supplicant.conf like that:
ctrl_interface=/var/run/wpa_supplicant
eapol_version=2
ap_scan=1
fast_reauth=1

network={
ssid="FRITZ!Box 7390"
scan_ssid=0
psk="wifi password"
priority=5
}
network={
priority=0
key_mgmt=NONE
}
For psk I use the real wifi password. Now something strange happens: After reboot /sbin/ifconfig wlan0 shows:
mars: # /sbin/ifconfig wlan0
wlan0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
options=0
ether 74:da:38:e2:35:03
inet 192.168.178.29 netmask 0xffffff00 broadcast 192.168.178.255
inet6 fe80::76da:38ff:fee2:3503%wlan0 prefixlen 64 scopeid 0x3
groups: wlan
ssid "Vodafone Homespot" channel 7 (2442 MHz 11g ht/20) bssid 9e:ed:6f:95:f8:2d
regdomain FCC country US authmode OPEN privacy OFF txpower 30 bmiss 7
scanvalid 60 protmode CTS ht20 ampdulimit 64k shortgi -stbc -ldpc
-uapsd wme
parent interface: rtwn0
media: IEEE 802.11 Wireless Ethernet DS/1Mbps mode 11ng
status: associated
nd6 options=23<PERFORMNUD,ACCEPT_RTADV,AUTO_LINKLOCAL>
mars: #
So the shown ssid is wrong. For some strange reason I got an IP adress. I have to check if your line for /etc/rc.conf
create_args_wlan0="country DE"

help me. I will do two tests and then will stop it for today. I am already very close to fix it.
Kind regards,
Roland
 
You are welcome, now if you haven't, you need to set your WiFi access point in the /etc/wpa_supplicant.conf. You also need this line below in /etc/rc.conf.

ifconfig_wlan0="WPA SYNCDHCP"

On FreeBSD, AFAIK, /etc/rc.conf, /boot/loader.conf and /etc/sysctl.conf configuration files are used for system configuration. At least, these are the files i use to configure my system as i like.
 
You are welcome, now if you haven't, you need to set your WiFi access point in the /etc/wpa_supplicant.conf. You also need this line below in /etc/rc.conf.

ifconfig_wlan0="WPA SYNCDHCP"

On FreeBSD, AFAIK, /etc/rc.conf, /boot/loader.conf and /etc/sysctl.conf configuration files are used for system configuration. At least, these are the files i use to configure my system as i like.
Thank you very much. :-) It works now. Now the correct ssid is shown.
The /sbin/ifconfig wlan0 shows:
roland@mars:~ % /sbin/ifconfig wlan0
wlan0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
options=0
ether 74:da:38:e2:35:03
inet 192.168.178.29 netmask 0xffffff00 broadcast 192.168.178.255
inet6 fe80::76da:38ff:fee2:3503%wlan0 prefixlen 64 scopeid 0x3
groups: wlan
ssid "FRITZ!Box 7390" channel 1 (2412 MHz 11g ht/20) bssid c0:25:06:f1:82:28
regdomain ETSI country DE authmode WPA2/802.11i privacy ON
deftxkey UNDEF TKIP 2:128-bit TKIP 3:128-bit txpower 30 bmiss 7
scanvalid 60 protmode CTS ht20 ampdulimit 64k ampdudensity 8 shortgi
-stbc -ldpc -uapsd wme roaming MANUAL
parent interface: rtwn0
media: IEEE 802.11 Wireless Ethernet DS/1Mbps mode 11ng
status: associated
nd6 options=23<PERFORMNUD,ACCEPT_RTADV,AUTO_LINKLOCAL>
roland@mars:~ %
The file /etc/rc.conf has now the following three extra lines at the end:
wlans_rtwn0="wlan0"
create_args_wlan0="country DE"
ifconfig_wlan0="WPA SYNCDHCP"
For /etc/wpa_supplicant.conf I will tomorrow try to reduce it as I added some extra lines. I am very happy that I was able with your help to get the usb wifi dongle to work.

For everyone:
I wish you a good change of the year into a very good year 2025. For 2025 healthiness, happiness, luck, peace, and a lot of fun with FreeBSD, too.
Kind regards,
Roland
 
Thank you very much. :-) It works now. Now the correct ssid is shown.
The /sbin/ifconfig wlan0 shows:

The file /etc/rc.conf has now the following three extra lines at the end:

For /etc/wpa_supplicant.conf I will tomorrow try to reduce it as I added some extra lines. I am very happy that I was able with your help to get the usb wifi dongle to work.

For everyone:
I wish you a good change of the year into a very good year 2025. For 2025 healthiness, happiness, luck, peace, and a lot of fun with FreeBSD, too.
Kind regards,
Roland
You are welcome, i am glad it worked for you.

I wish you the same too, thanks!
 
Can you try this patch?

Code:
From c83aa81d394b7f1e850bf698977985c8e00e747d Mon Sep 17 00:00:00 2001
From: Cy Schubert <cy@FreeBSD.org>
Date: Mon, 9 Jan 2023 12:54:00 -0800
Subject: [PATCH] rtwn: Fix RTL8188EU & RTL8192EU cannot associate in STA mode

On some systems RTL8188EU and RTL8192EU will fail to associate in STA
mode while others it will work fine. On the systems RTL8192EU fails to
associate in STA mode, it works perfectly fine in AP mode. This points
to a USB timing issue when selecting a channel while in STA mode.

While here fix RTL8192EU power off and power on hang for the same reason.

PR:             247528
Reported by:    Mc James <realmcjames@protonmail.ch>,
                rkoberman@gmail.com, many
Reviewed by:
Tested by:      titus@edc.ro
Approved by:
Concept by:     titus@edc.ro
MFC after:
Relnotes:
Differential Revision:
---
 sys/dev/rtwn/rtl8188e/r88e_reg.h         |  1 +
 sys/dev/rtwn/rtl8188e/usb/r88eu_attach.c |  2 ++
 sys/dev/rtwn/rtl8188e/usb/r88eu_init.c   | 15 +++++++++++-
 sys/dev/rtwn/rtl8192c/r92c_chan.c        |  8 ++++++
 sys/dev/rtwn/rtl8192c/r92c_reg.h         |  2 ++
 sys/dev/rtwn/rtl8192c/usb/r92cu_attach.c |  1 +
 sys/dev/rtwn/rtl8192e/r92e_chan.c        |  6 +++++
 sys/dev/rtwn/rtl8192e/r92e_init.c        | 31 ++++++++++++++++++++++--
 sys/dev/rtwn/rtl8192e/r92e_reg.h         |  1 +
 sys/dev/rtwn/rtl8192e/usb/r92eu_attach.c |  1 +
 sys/dev/rtwn/usb/rtwn_usb_attach.c       |  5 ++++
 sys/dev/rtwn/usb/rtwn_usb_reg.c          |  4 +++
 sys/dev/rtwn/usb/rtwn_usb_var.h          |  4 +++
 13 files changed, 78 insertions(+), 3 deletions(-)

diff --git a/sys/dev/rtwn/rtl8188e/r88e_reg.h b/sys/dev/rtwn/rtl8188e/r88e_reg.h
index d9f236cddbb6..bed88c4604f6 100644
--- a/sys/dev/rtwn/rtl8188e/r88e_reg.h
+++ b/sys/dev/rtwn/rtl8188e/r88e_reg.h
@@ -121,5 +121,6 @@
 
 /* Bits for R88E_XCK_OUT_CTRL. */
 #define R88E_XCK_OUT_CTRL_EN   1
+#define R88E_USB_DELAY_US_DEF  1000
 
 #endif /* R88E_REG_H */
diff --git a/sys/dev/rtwn/rtl8188e/usb/r88eu_attach.c b/sys/dev/rtwn/rtl8188e/usb/r88eu_attach.c
index 2d4713e92bd2..672cdb79f175 100644
--- a/sys/dev/rtwn/rtl8188e/usb/r88eu_attach.c
+++ b/sys/dev/rtwn/rtl8188e/usb/r88eu_attach.c
@@ -58,6 +58,7 @@
 #include <dev/rtwn/rtl8188e/r88e_rom_image.h>  /* for 'macaddr' field */
 
 #include <dev/rtwn/rtl8188e/usb/r88eu.h>
+#include <dev/rtwn/rtl8188e/r88e_reg.h>
 
 static struct rtwn_r88e_txpwr r88e_txpwr;
 
@@ -122,6 +123,7 @@ r88eu_attach(struct rtwn_usb_softc *uc)
        /* USB part. */
        uc->uc_align_rx                 = r92cu_align_rx;
        uc->tx_agg_desc_num             = 6;
+       uc->uc_delay_us                 = R88E_USB_DELAY_US_DEF;
 
        /* Common part. */
        sc->sc_flags                    = RTWN_FLAG_EXT_HDR;
diff --git a/sys/dev/rtwn/rtl8188e/usb/r88eu_init.c b/sys/dev/rtwn/rtl8188e/usb/r88eu_init.c
index f4f936493cda..510a820b71ad 100644
--- a/sys/dev/rtwn/rtl8188e/usb/r88eu_init.c
+++ b/sys/dev/rtwn/rtl8188e/usb/r88eu_init.c
@@ -48,6 +48,8 @@
 #include <dev/rtwn/rtl8192c/r92c.h>
 #include <dev/rtwn/rtl8192c/r92c_var.h>
 
+#include <dev/rtwn/usb/rtwn_usb_var.h>
+
 #include <dev/rtwn/rtl8188e/usb/r88eu.h>
 #include <dev/rtwn/rtl8188e/usb/r88eu_reg.h>
 
@@ -76,8 +78,12 @@ r88eu_power_on(struct rtwn_softc *sc)
        if (res != 0)           \
                return (EIO);   \
 } while(0)
+       struct rtwn_usb_softc *uc;
        int ntries;
 
+       if ((uc = RTWN_USB_SOFTC(sc)) != NULL)
+               uc->uc_write_delay = 1;
+
        /* Wait for power ready bit. */
        for (ntries = 0; ntries < 5000; ntries++) {
                if (rtwn_read_4(sc, R92C_APS_FSMCO) & R92C_APS_FSMCO_SUS_HOST)
@@ -85,6 +91,8 @@ r88eu_power_on(struct rtwn_softc *sc)
                rtwn_delay(sc, 10);
        }
        if (ntries == 5000) {
+               if (uc != NULL)
+                       uc->uc_write_delay = 0;
                device_printf(sc->sc_dev,
                    "timeout waiting for chip power up\n");
                return (ETIMEDOUT);
@@ -112,7 +120,10 @@ r88eu_power_on(struct rtwn_softc *sc)
                        break;
                rtwn_delay(sc, 10);
        }
-       if (ntries == 5000)
+       if (ntries == 5000) {
+               if (uc != NULL)
+                       uc->uc_write_delay = 0;
+       }
                return (ETIMEDOUT);
 
        /* Enable LDO normal mode. */
@@ -128,6 +139,8 @@ r88eu_power_on(struct rtwn_softc *sc)
            ((sc->sc_hwcrypto != RTWN_CRYPTO_SW) ? R92C_CR_ENSEC : 0) |
            R92C_CR_CALTMR_EN));
 
+       if (uc != NULL)
+               uc->uc_write_delay = 0;
        return (0);
 #undef RTWN_CHK
 }
diff --git a/sys/dev/rtwn/rtl8192c/r92c_chan.c b/sys/dev/rtwn/rtl8192c/r92c_chan.c
index f93159a3c94e..f22916b312f2 100644
--- a/sys/dev/rtwn/rtl8192c/r92c_chan.c
+++ b/sys/dev/rtwn/rtl8192c/r92c_chan.c
@@ -52,6 +52,7 @@
 #include <dev/rtwn/rtl8192c/r92c_priv.h>
 #include <dev/rtwn/rtl8192c/r92c_reg.h>
 #include <dev/rtwn/rtl8192c/r92c_var.h>
+#include <dev/rtwn/usb/rtwn_usb_var.h>
 
 void
 r92c_dump_txpower(struct rtwn_softc *sc, int chain,
@@ -361,9 +362,13 @@ void
 r92c_set_chan(struct rtwn_softc *sc, struct ieee80211_channel *c)
 {
        struct r92c_softc *rs = sc->sc_priv;
+       struct rtwn_usb_softc *uc;
        u_int chan;
        int i;
 
+       if ((uc = RTWN_USB_SOFTC(sc)) != NULL)
+               uc->uc_write_delay = 1;
+
        chan = rtwn_chan2centieee(c);
 
        /* Set Tx power for this new channel. */
@@ -377,6 +382,9 @@ r92c_set_chan(struct rtwn_softc *sc, struct ieee80211_channel *c)
                r92c_set_bw40(sc, chan, IEEE80211_IS_CHAN_HT40U(c));
        else
                rtwn_r92c_set_bw20(sc, chan);
+
+       if (uc != NULL)
+               uc->uc_write_delay = 0;
 }
 
 void
diff --git a/sys/dev/rtwn/rtl8192c/r92c_reg.h b/sys/dev/rtwn/rtl8192c/r92c_reg.h
index e6d232a88834..bc75f5444d9c 100644
--- a/sys/dev/rtwn/rtl8192c/r92c_reg.h
+++ b/sys/dev/rtwn/rtl8192c/r92c_reg.h
@@ -926,4 +926,6 @@
 #define R92C_RF_T_METER_VAL_M  0x1f
 #define R92C_RF_T_METER_VAL_S  0
 
+#define R92C_USB_DELAY_US_DEF  1000
+
 #endif /* R92C_REG_H */
diff --git a/sys/dev/rtwn/rtl8192c/usb/r92cu_attach.c b/sys/dev/rtwn/rtl8192c/usb/r92cu_attach.c
index cd350c7fcd8a..3ed581fe3634 100644
--- a/sys/dev/rtwn/rtl8192c/usb/r92cu_attach.c
+++ b/sys/dev/rtwn/rtl8192c/usb/r92cu_attach.c
@@ -151,6 +151,7 @@ r92cu_attach(struct rtwn_usb_softc *uc)
        /* USB part. */
        uc->uc_align_rx                 = r92cu_align_rx;
        uc->tx_agg_desc_num             = 6;
+       uc->uc_delay_us                 = R92C_USB_DELAY_US_DEF;
 
        /* Common part. */
        sc->sc_flags                    = RTWN_FLAG_CAM_FIXED;
diff --git a/sys/dev/rtwn/rtl8192e/r92e_chan.c b/sys/dev/rtwn/rtl8192e/r92e_chan.c
index 4c7121a80c89..b6e208220c3a 100644
--- a/sys/dev/rtwn/rtl8192e/r92e_chan.c
+++ b/sys/dev/rtwn/rtl8192e/r92e_chan.c
@@ -60,6 +60,7 @@
 #include <dev/rtwn/rtl8192e/r92e.h>
 #include <dev/rtwn/rtl8192e/r92e_reg.h>
 #include <dev/rtwn/rtl8192e/r92e_var.h>
+#include <dev/rtwn/usb/rtwn_usb_var.h>
 
 static int
 r92e_get_power_group(struct rtwn_softc *sc, struct ieee80211_channel *c)
@@ -235,9 +236,12 @@ void
 r92e_set_chan(struct rtwn_softc *sc, struct ieee80211_channel *c)
 {
        struct r92e_softc *rs = sc->sc_priv;
+       struct rtwn_usb_softc *uc;
        u_int chan;
        int i;
 
+       if ((uc = RTWN_USB_SOFTC(sc)) != NULL)
+               uc->uc_write_delay = 1;
        chan = rtwn_chan2centieee(c);
 
        for (i = 0; i < sc->nrxchains; i++) {
@@ -252,4 +256,6 @@ r92e_set_chan(struct rtwn_softc *sc, struct ieee80211_channel *c)
 
        /* Set Tx power for this new channel. */
        r92e_set_txpower(sc, c);
+       if (uc != NULL)
+               uc->uc_write_delay = 0;
 }
diff --git a/sys/dev/rtwn/rtl8192e/r92e_init.c b/sys/dev/rtwn/rtl8192e/r92e_init.c
index 925221bdabb1..11c51df63ade 100644
--- a/sys/dev/rtwn/rtl8192e/r92e_init.c
+++ b/sys/dev/rtwn/rtl8192e/r92e_init.c
@@ -53,6 +53,8 @@
 
 #include <dev/rtwn/if_rtwn_debug.h>
 
+#include <dev/rtwn/usb/rtwn_usb_var.h>
+
 #include <dev/rtwn/rtl8192c/r92c.h>
 
 #include <dev/rtwn/rtl8192e/r92e.h>
@@ -224,8 +226,12 @@ r92e_power_on(struct rtwn_softc *sc)
        if (res != 0)           \
                return (EIO);   \
 } while(0)
+       struct rtwn_usb_softc *uc;
        int ntries;
 
+       if ((uc = RTWN_USB_SOFTC(sc)) != NULL)
+               uc->uc_write_delay = 1;
+
        if (rtwn_read_4(sc, R92C_SYS_CFG) & R92C_SYS_CFG_TRP_BT_EN)
                RTWN_CHK(rtwn_write_1(sc, R92C_LDO_SWR_CTRL, 0xc3));
        else {
@@ -252,6 +258,8 @@ r92e_power_on(struct rtwn_softc *sc)
                rtwn_delay(sc, 10);
        }
        if (ntries == 5000) {
+               if (uc != NULL)
+                       uc->uc_write_delay = 0;
                device_printf(sc->sc_dev,
                    "timeout waiting for chip power up\n");
                return (ETIMEDOUT);
@@ -269,8 +277,11 @@ r92e_power_on(struct rtwn_softc *sc)
                        break;
                rtwn_delay(sc, 10);
        }
-       if (ntries == 5000)
+       if (ntries == 5000) {
+               if (uc != NULL)
+                       uc->uc_write_delay = 0;
                return (ETIMEDOUT);
+       }
 
        /* Enable MAC DMA/WMAC/SCHEDULE/SEC blocks. */
        RTWN_CHK(rtwn_write_2(sc, R92C_CR, 0));
@@ -281,18 +292,27 @@ r92e_power_on(struct rtwn_softc *sc)
            ((sc->sc_hwcrypto != RTWN_CRYPTO_SW) ? R92C_CR_ENSEC : 0) |
            R92C_CR_CALTMR_EN));
 
+       if (uc != NULL)
+               uc->uc_write_delay = 0;
        return (0);
 }
 
 void
 r92e_power_off(struct rtwn_softc *sc)
 {
+       struct rtwn_usb_softc *uc;
        int error, ntries;
 
+       if ((uc = RTWN_USB_SOFTC(sc)) != NULL)
+               uc->uc_write_delay = 1;
+
        /* Stop Rx. */
        error = rtwn_write_1(sc, R92C_CR, 0);
-       if (error == ENXIO)     /* hardware gone */
+       if (error == ENXIO) {   /* hardware gone */
+               if (uc != NULL)
+                       uc->uc_write_delay = 0;
                return;
+       }
 
        /* Move card to Low Power state. */
        /* Block all Tx queues. */
@@ -306,6 +326,8 @@ r92e_power_off(struct rtwn_softc *sc)
                rtwn_delay(sc, 10);
        }
        if (ntries == 5000) {
+               if (uc != NULL)
+                       uc->uc_write_delay = 0;
                device_printf(sc->sc_dev, "%s: failed to block Tx queues\n",
                    __func__);
                return;
@@ -363,6 +385,8 @@ r92e_power_off(struct rtwn_softc *sc)
                rtwn_delay(sc, 10);
        }
        if (ntries == 5000) {
+               if (uc != NULL)
+                       uc->uc_write_delay = 0;
                device_printf(sc->sc_dev, "%s: could not turn off MAC\n",
                    __func__);
                return;
@@ -385,4 +409,7 @@ r92e_power_off(struct rtwn_softc *sc)
        /* Enable SW LPS. */
        rtwn_setbits_1_shift(sc, R92C_APS_FSMCO, 0,
            R92C_APS_FSMCO_APFM_RSM, 1);
+
+       if (uc != NULL)
+               uc->uc_write_delay = 0;
 }
diff --git a/sys/dev/rtwn/rtl8192e/r92e_reg.h b/sys/dev/rtwn/rtl8192e/r92e_reg.h
index 5106bcf9d5f0..edcc2fcb2d57 100644
--- a/sys/dev/rtwn/rtl8192e/r92e_reg.h
+++ b/sys/dev/rtwn/rtl8192e/r92e_reg.h
@@ -41,5 +41,6 @@
 /* Bits for R92E_AFE_XTAL_CTRL. */
 #define R92E_AFE_XTAL_CTRL_ADDR_M      0x00fff000
 #define R92E_AFE_XTAL_CTRL_ADDR_S      12
+#define R92E_USB_DELAY_US_DEF          1000
 
 #endif /* R92E_REG_H */
diff --git a/sys/dev/rtwn/rtl8192e/usb/r92eu_attach.c b/sys/dev/rtwn/rtl8192e/usb/r92eu_attach.c
index a11a6bb79c5d..35741e58a11e 100644
--- a/sys/dev/rtwn/rtl8192e/usb/r92eu_attach.c
+++ b/sys/dev/rtwn/rtl8192e/usb/r92eu_attach.c
@@ -100,6 +100,7 @@ r92eu_attach(struct rtwn_usb_softc *uc)
        /* USB part. */
        uc->uc_align_rx                 = r12au_align_rx;
        uc->tx_agg_desc_num             = 3;
+       uc->uc_delay_us                 = R92E_USB_DELAY_US_DEF;
 
        /* Common part. */
        sc->sc_flags                    = RTWN_FLAG_EXT_HDR;
diff --git a/sys/dev/rtwn/usb/rtwn_usb_attach.c b/sys/dev/rtwn/usb/rtwn_usb_attach.c
index 4958939a768a..30d4da75cf8f 100644
--- a/sys/dev/rtwn/usb/rtwn_usb_attach.c
+++ b/sys/dev/rtwn/usb/rtwn_usb_attach.c
@@ -377,6 +377,11 @@ rtwn_usb_sysctlattach(struct rtwn_softc *sc)
                uc->uc_rx_buf_size = RTWN_USB_RXBUFSZ_MIN;
        if (uc->uc_rx_buf_size > RTWN_USB_RXBUFSZ_MAX)
                uc->uc_rx_buf_size = RTWN_USB_RXBUFSZ_MAX;
+
+       uc->uc_delay_us = RTWN_USB_DELAY_US_DEF;
+       SYSCTL_ADD_INT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO,
+           "delay_us", CTLFLAG_RWTUN, &uc->uc_delay_us,
+           uc->uc_delay_us, "RTWN USB set channel delay microseconds");
 }
 
 static int
diff --git a/sys/dev/rtwn/usb/rtwn_usb_reg.c b/sys/dev/rtwn/usb/rtwn_usb_reg.c
index 5a992379e248..ba178b1265c4 100644
--- a/sys/dev/rtwn/usb/rtwn_usb_reg.c
+++ b/sys/dev/rtwn/usb/rtwn_usb_reg.c
@@ -88,12 +88,16 @@ rtwn_usb_write_region_1(struct rtwn_softc *sc, uint16_t addr, uint8_t *buf,
     int len)
 {
        usb_device_request_t req;
+       struct rtwn_usb_softc *uc;
 
        req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
        req.bRequest = R92C_REQ_REGS;
        USETW(req.wValue, addr);
        USETW(req.wIndex, 0);
        USETW(req.wLength, len);
+       uc = RTWN_USB_SOFTC(sc);
+       if (uc->uc_write_delay == 1)
+               (sc->sc_delay)(sc,uc->uc_delay_us);
        return (rtwn_do_request(sc, &req, buf));
 }
 
diff --git a/sys/dev/rtwn/usb/rtwn_usb_var.h b/sys/dev/rtwn/usb/rtwn_usb_var.h
index 27cd2b4e2762..2ff0ba852eed 100644
--- a/sys/dev/rtwn/usb/rtwn_usb_var.h
+++ b/sys/dev/rtwn/usb/rtwn_usb_var.h
@@ -27,6 +27,7 @@
 #define RTWN_USB_RXBUFSZ_DEF           (24)
 #define RTWN_USB_RXBUFSZ_MAX           (64)
 #define RTWN_USB_TXBUFSZ               (16 * 1024)
+#define RTWN_USB_DELAY_US_DEF          0
 
 #define RTWN_IFACE_INDEX               0
 
@@ -82,6 +83,9 @@ struct rtwn_usb_softc {
        int                     tx_agg_desc_num;
 
        uint8_t                 wme2qid[4];
+
+       int                     uc_delay_us;
+       int                     uc_write_delay;
 };
 #define RTWN_USB_SOFTC(sc)     ((struct rtwn_usb_softc *)(sc))
 
--
2.47.1
 
Hello cy@,
thank you for your information about a fix. Currently I have to check whether all my wifi dongles works or have a problem and it I can reproduce the problem without fix.
The current wifi dongle that is in my Raspberry PI is a RTL8188CUS but I have one or two RTL8188EU wifi dongles, too.
What do I have to do to reproduce the bug without your fix?
By the way, all wifi dongles work on Raspbian (Debian) 11 or newer. In former times there was the kernel module of Larry Finger needed.

In case I can reproduce the wifi problems on my Raspberry Pis on FreeBSD, could you describe me or send me a link, that describes how to compile a kernel module (how to get the kernel sources) on FreeBSD?
In the early 2000s I used FreeBSD and NetBSD for a while, but I forgot a lot of BSD basic knowledge. At my new job I mainly used Linux. So I mainly used Linux at home and started FreeBSD in the Christmas times 2024 on my Raspberry Pi again. So I have some "unix" knowledge (mostly Linux, some Solaris and bit Sun OS 4 knowledge but little FreeBSD knowledge), I am able to read, write and compile C or C++ code but I have to learn (again) many "simple" FreeBSD basics like getting the kernel sources.
Kind regards,
Roland
 
Hello,
after the message from cy@ I tested 5 wifi dongles and four of them seems to work fine. There is only a strange message shown in console and dmesg: ieee80211_load_module: load the wlan_amrr module by hand for now.
What is the problem and what should be done?

(The one, that didn't work, didn't work in an old Rasberry Pi with Rasbian Linux, too. The linux command lsusb showed for the problematic wifi dongle:
"Bus 001 Device 005: ID 0bda:f179 Realtek Semiconductor Corp. RTL8188FTV 802.11b/g/n 1T1R 2.4G WLAN Adapter")

So my results of my four wifi dongles.:

Wlan 1 Edimax (old version RTL8188CUS)
Relevant output of dmesg:
ugen1.5: <Realtek 802.11n WLAN Adapter> at usbus1
rtwn0 on uhub1
rtwn0: <Realtek 802.11n WLAN Adapter, class 0/0, rev 2.00/2.00, addr 5> on usbus1
rtwn0: MAC/BB RTL8188CUS, RF 6052 1T1R
ieee80211_load_module: load the wlan_amrr module by hand for now.
wlan0: Ethernet address: 74:da:38:e2:35:03
wlan0: link state changed to UP
Output of /sbin/ifconfig wlan0
roland@mars:~ % /sbin/ifconfig wlan0
wlan0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
options=0
ether 74:da:38:e2:35:03
inet 192.168.178.29 netmask 0xffffff00 broadcast 192.168.178.255
inet6 fe80::76da:38ff:fee2:3503%wlan0 prefixlen 64 scopeid 0x3
groups: wlan
ssid "FRITZ!Box 7390" channel 1 (2412 MHz 11g ht/20) bssid c0:25:06:f1:82:28
regdomain ETSI country DE authmode WPA2/802.11i privacy ON
deftxkey UNDEF TKIP 2:128-bit TKIP 3:128-bit txpower 30 bmiss 7
scanvalid 60 protmode CTS ht20 ampdulimit 64k ampdudensity 8 shortgi
-stbc -ldpc -uapsd wme roaming MANUAL
parent interface: rtwn0
media: IEEE 802.11 Wireless Ethernet DS/1Mbps mode 11ng
status: associated
nd6 options=23<PERFORMNUD,ACCEPT_RTADV,AUTO_LINKLOCAL>

Wlan 2 (Edimax new version RTL8188EU, Realtek Edimax N150 Adapter)
Relevant output of dmesg:
ugen1.5: <Realtek Edimax N150 Adapter> at usbus1
rtwn0 on uhub1
rtwn0: <Realtek Edimax N150 Adapter, class 0/0, rev 2.00/0.00, addr 5> on usbus1
rtwn0: MAC/BB RTL8188EU, RF 6052 1T1R
ieee80211_load_module: load the wlan_amrr module by hand for now.
wlan0: Ethernet address: 08:be:ac:3d:22:42
wlan0: link state changed to UP
Output of /sbin/ifconfig wlan0
wlan0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
options=0
ether 08:be:ac:3d:22:42
inet 192.168.178.71 netmask 0xffffff00 broadcast 192.168.178.255
inet6 fe80::abe:acff:fe3d:2242%wlan0 prefixlen 64 scopeid 0x3
groups: wlan
ssid "FRITZ!Box 7390" channel 1 (2412 MHz 11g ht/20) bssid c0:25:06:f1:82:28
regdomain ETSI country DE authmode WPA2/802.11i privacy ON
deftxkey UNDEF TKIP 3:128-bit txpower 30 bmiss 7 scanvalid 60
protmode CTS ht20 ampdulimit 64k ampdudensity 8 shortgi -stbc -ldpc
-uapsd wme roaming MANUAL
parent interface: rtwn0
media: IEEE 802.11 Wireless Ethernet DS/1Mbps mode 11ng
status: associated
nd6 options=23<PERFORMNUD,ACCEPT_RTADV,AUTO_LINKLOCAL>

Wlan 3 (tp-link)
Relevant output of dmesg:
ugen1.5: <Realtek 802.11n NIC> at usbus1
rtwn0 on uhub1
rtwn0: <Realtek 802.11n NIC, class 0/0, rev 2.00/0.00, addr 5> on usbus1
rtwn0: MAC/BB RTL8188EU, RF 6052 1T1R
ieee80211_load_module: load the wlan_amrr module by hand for now.
wlan0: Ethernet address: 48:22:54:c7:00:fa
wlan0: link state changed to UP
Output of /sbin/ifconfig wlan0
roland@mars:~ % /sbin/ifconfig wlan0
wlan0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
options=0
ether 48:22:54:c7:00:fa
inet 192.168.178.51 netmask 0xffffff00 broadcast 192.168.178.255
inet6 fe80::4a22:54ff:fec7:fa%wlan0 prefixlen 64 scopeid 0x3
groups: wlan
ssid "FRITZ!Box 7390" channel 1 (2412 MHz 11g ht/20) bssid c0:25:06:f1:82:28
regdomain ETSI country DE authmode WPA2/802.11i privacy ON
deftxkey UNDEF TKIP 2:128-bit txpower 30 bmiss 7 scanvalid 60
protmode CTS ht20 ampdulimit 64k ampdudensity 8 shortgi -stbc -ldpc
-uapsd wme roaming MANUAL
parent interface: rtwn0
media: IEEE 802.11 Wireless Ethernet DS/1Mbps mode 11ng
status: associated
nd6 options=23<PERFORMNUD,ACCEPT_RTADV,AUTO_LINKLOCAL>
roland@mars:~ %

Wlan 4 ( tp-link )
Relevant output of dmesg:
ugen1.5: <Realtek 802.11n NIC> at usbus1
rtwn0 on uhub1
rtwn0: <Realtek 802.11n NIC, class 0/0, rev 2.00/0.00, addr 5> on usbus1
rtwn0: MAC/BB RTL8188EU, RF 6052 1T1R
ieee80211_load_module: load the wlan_amrr module by hand for now.
wlan0: Ethernet address: 40:ed:00:b8:47:8c
wlan0: link state changed to UP
Output of /sbin/ifconfig wlan0
roland@mars:~ % /sbin/ifconfig wlan0
wlan0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
options=0
ether 40:ed:00:b8:47:8c
inet 192.168.178.69 netmask 0xffffff00 broadcast 192.168.178.255
inet6 fe80::42ed:ff:feb8:478c%wlan0 prefixlen 64 scopeid 0x3
groups: wlan
ssid "FRITZ!Box 7390" channel 1 (2412 MHz 11g ht/20) bssid c0:25:06:f1:82:28
regdomain ETSI country DE authmode WPA2/802.11i privacy ON
deftxkey UNDEF TKIP 2:128-bit txpower 30 bmiss 7 scanvalid 60
protmode CTS ht20 ampdulimit 64k ampdudensity 8 shortgi -stbc -ldpc
-uapsd wme roaming MANUAL
parent interface: rtwn0
media: IEEE 802.11 Wireless Ethernet DS/1Mbps mode 11ng
status: associated
nd6 options=23<PERFORMNUD,ACCEPT_RTADV,AUTO_LINKLOCAL>
roland@mars:~ %

So all four wifi dongles seems to work fine.
What's a little bit strange ist the line in dmesg or console:
ieee80211_load_module: load the wlan_amrr module by hand for now.
It works without loading the wlan_amrr module. What is the problem and what needs to be done?

Kind regards,
Roland
 
Hello,
an update for my tests. I tested now one of my wifi dongles on FreeBSD 13.4, too on a 32 Bit Raspberry Pi 2 (using https://download.freebsd.org/releas...eeBSD-13.4-RELEASE-arm-armv7-GENERICSD.img.xz).
Here the steps that should work on FreeBSD 13.* and 14.*:

1. Run the command sysctl net.wlan.devices
In my case the result was:
net.wlan.devices: rtwn0
This device is used later.

2. Edit the file /etc/rc.conf and add or edit the following lines:
wlans_rtwn0="wlan0"
create_args_wlan0="country DE"
ifconfig_wlan0="WPA SYNCDHCP"
In the line with wlans_rtwn0 the rtwn0 needs to adapted corresponding to the result you got in step 1 with the command sysctl net.wlan.devices.
In the second line the correct country needs to be set. I use DE for Germany.

3. Configuring the wpa_supplicant settings.
After reboot the wlan0 is already visible when running /sbin/ifconfig and needs to configured now. At this moment there still exist no /etc/wpa_supplicant.conf. So I started bsdconfig and choose "Network Management" and then "Wireless Networks" there my wlan router is visible. I somehow wasn't able to select it. Could anybody else test it?

Afterwards an prepared /etc/wpa_supplicant.conf was created with the following lines:
ctrl_interface=/var/run/wpa_supplicant
eapol_version=2
ap_scan=1
fast_reauth=1

Afterwards I add the network e.g.
network={
ssid="FRITZ!Box 7390"
psk="<password key>"
}

That was enough and it works so far.
merkur # /sbin/ifconfig wlan0
wlan0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
ether 08:be:ac:3d:22:42
inet6 fe80::abe:acff:fe3d:2242%wlan0 prefixlen 64 scopeid 0x3
inet 192.168.178.71 netmask 0xffffff00 broadcast 192.168.178.255
groups: wlan
ssid "FRITZ!Box 7390" channel 1 (2412 MHz 11g ht/20) bssid c0:25:06:f1:82:28
regdomain ETSI country DE authmode WPA2/802.11i privacy ON
deftxkey UNDEF TKIP 2:128-bit TKIP 3:128-bit txpower 30 bmiss 7
scanvalid 60 protmode CTS ht20 ampdulimit 64k ampdudensity 8 shortgi
-stbc -ldpc -uapsd wme roaming MANUAL
parent interface: rtwn0
media: IEEE 802.11 Wireless Ethernet DS/1Mbps mode 11ng
status: associated
nd6 options=23<PERFORMNUD,ACCEPT_RTADV,AUTO_LINKLOCAL>
merkur #

I am not sure if the output shows some problems. On Linux there is less output. What is still odd that dmesg shows the line
ieee80211_load_module: load the wlan_amrr module by hand for now.

This is independant from FreeBSD 13.4 or FreeBSD 14.2 and independent of 32 Bit or 64 bit. That is consistent but I don't understand what needs to be done. The wlan works but maybe there is still a problem because one kernel module is not loaded?
It seems to make no difference whether I load wlan_amrr with kldload wlan_amrr or not. Am I missing something?

Kind regards,
Roland
 
Back
Top