Extremely slow access point (dual wifi setup on Pine RockPro64)

Hi everyone,

Yesterday I spent a whole day setting up an access point with FreeBSD 13.1-RELEASE on a Pine RockPro64
board and at the moment while this setup works I'm experiencing very slow internet browsing.
I'm describing the hardware and setup that am using as well as all steps taken to have this working:

The Pine RockPro64 has attached two external wifi dongles based on the `rwtn` chipset.

One of them is the TP-Link TL-WN725N and the other one is: https://pine64.com/product/usb-wifi-802-11b-g-n-rtl8188eu/
which I purchased when I bought the board. Both dongles are rated 150 Mbps. Why have two wifis on the board?

My use case is probably not very common: I have a single internet connection provided by my mobile phone.
I always take this phone with me. When I'm at home all my computers use it as hotspot. Because
I also wanted to have a permanent wifi lan regardless I have internet access or not I'm using the
two wifi interfaces in the Pine board: One provides the permanent wifi lan (the access point) and the other interface
connects as a client to the mobile hotspot so all my computers can have internet access through the
Pine board acting as a router.

Here are the detailed steps that I've done to get it working. All following steps but #6 take place in the Pine board:

1. Setting up the interfaces (`/etc/rc.conf`):

Bash:
# wlan0 connects to the mobile hotspot.
wlans_rtwn0="wlan0"
ifconfig_wlan0="wpa syncdhcp"

# wlan1 is used as my local access point.
wlans_rtwn1="wlan1"
create_args_wlan1="wlanmode hostap"
ifconfig_wlan1="inet 192.168.200.1 netmask 255.255.255.0 hidessid ssid spectre mode 11g channel 9"

Then run: `service netif restart`.

Both interfaces come up correctly as shown here:

Bash:
wlan0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
    ether XX:XX:XX:XX:XX:XX
    inet 10.17.11.235 netmask 0xffffff00 broadcast 10.17.11.255
    groups: wlan
    ssid SkyDirect channel 6 (2437 MHz 11g ht/20) bssid XX:XX:XX:XX:XX:XX
    regdomain FCC country US authmode WPA2/802.11i privacy ON
    deftxkey UNDEF AES-CCM 3:128-bit txpower 30 bmiss 7 scanvalid 60
    protmode CTS ht20 ampdulimit 64k ampdudensity 2 shortgi -stbc -ldpc
    -uapsd wme roaming MANUAL
    parent interface: rtwn0
    media: IEEE 802.11 Wireless Ethernet MCS mode 11ng
    status: associated
    nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>
wlan1: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
    ether XX:XX:XX:XX:XX:XX
    inet 192.168.200.1 netmask 0xffffff00 broadcast 192.168.200.255
    groups: wlan
    ssid spectre channel 9 (2452 MHz 11g) bssid XX:XX:XX:XX:XX:XX
    regdomain FCC country US authmode WPA2/802.11i privacy MIXED
    deftxkey 2 AES-CCM 2:128-bit txpower 30 scanvalid 60 protmode CTS wme
    hidessid dtimperiod 1 -dfs
    parent interface: rtwn1
    media: IEEE 802.11 Wireless Ethernet autoselect mode 11g <hostap>
    status: running
    nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>


2. Setting up `hostapd` (`/etc/hostapd.conf`):

Bash:
interface=wlan1
debug=1
ctrl_interface=/var/run/hostapd
ctrl_interface_group=wheel
ssid=spectre
wpa=2
wpa_passphrase=PASSPHRASE
wpa_key_mgmt=WPA-PSK
wpa_pairwise=CCMP

Then run: `service hostapd onestart`.


3. Setting up `dnsmasq` (`/usr/local/etc/dnsmasq.conf`):

Bash:
domain-needed
no-resolv
server=1.1.1.1
except-interface=lo0,wlan0
local-service
dhcp-authoritative
interface=wlan1
dhcp-range=192.168.200.2,192.168.200.250

Then run: `service dnsmasq onestart`.

I'm using `dnsmasq` to let all clients get an IP through DHCP. I've adapted it from Vermaden's byhve
setup guide from here: https://vermaden.wordpress.com/2023/08/18/freebsd-bhyve-virtualization/


4. Setting up `pf` to perform NAT between the two interfaces (`/etc/pf.conf`):

Bash:
set skip on lo0

nat on wlan0 from {wlan1:network} to any ->(wlan0)

pass in all
pass out all

Now enable forwarding: `sysctl net.inet.ip.forwarding=1`.

Then run: `service pf onestart`.


5. Update `/etc/rc.conf` to start all services at boot time:

Bash:
hostapd_enable="YES"
dnsmasq_enable="YES"
gateway_enable="YES"
pf_enable="YES"


6. Configure one or more machines to connect to the Pine board access point (`/etc/wpa_supplicant.conf):

Bash:
ctrl_interface=/var/run/wpa_supplicant
eapol_version=2
ap_scan=1
fast_reauth=1

network={
    ssid="spectre"
    scan_ssid=1
    psk="PASSPHRASE"
    priority=1000
}

Now the nasty symptoms. When I try to navigate to a heavy website (using one of my machines that connects to the
Pine board access point) images for example load extremely slowly, as if I were using a PPP dialup connection from the 90's.

Websites that are light (HN for example) load relatively quickly. One thing that is really puzzling me is this:
when I browse to a heavy website, my SSH connection to the Pine board DEGRADES significantly to the point that
sometimes I have to cancel loading the website to actually continue using the SSH connection to the Pine board.

If I inspect the Firefox console (network tab) I can see a lot of these errors: NS_ERROR_NET_PARTIAL_TRANSFER, NS_ERROR_FAILURE,
NS_BINDING_ABORTED. None of this happens when I connect directly to the mobile hotspot.

When I run `netstat -r4` in the Pine board, this is what I see (it takes between 5 and 6 seconds to complete):

Bash:
Internet:
Destination        Gateway            Flags     Netif Expire
default            10.17.11.36        UGS       wlan0
10.17.11.0/24      link#3             U         wlan0
bluestar.local     link#3             UHS         lo0
localhost          link#2             UH          lo0
192.168.200.0/24   link#4             U         wlan1
bluestar.local     link#4             UHS         lo0

By the way I haven't mentioned so far, the Pine board is also running `avahi-daemon` as well as all my machines.
Mentioning this just in case, but I don't think it has anything to do with the setup.

Here are my thoughts:

* I'm not 100% sure if this a hardware problem. Dongles are relatively new and they seem
to work ok. One thing that I also tested is having one of the dongles a bit far away from the other
one through an USB cable extension, I thought that perhaps being so close to each other they could be
interfering (somehow) with one another. This was a silly assumption and produced no noticeable changes at all.

* Perhaps the given PF rule is not entirely correct and/or not performant?
The rule that I'm using was taken and adapted from this post: https://forums.freebsd.org/threads/pf-nat.77104/

* Do I need to adjust one or more networking settings through `sysctl`?

* Could it be a `dnsmasq` issue?

Which tools can I use to track down the problem? What things can I try to have a better insight?

My guess so far is that is either a `dnsmasq` and/or `pf` issue. I can't see any problems with the interface
and `hostapd` configuration.

Thanks in advance for reading this long post,
Lucas.
 
FreeBSD 13.1-RELEASE
End of life and not supported since July 2023. I suggest you go with 14.3 or try the soon to be finalized and released 15.0.

 
  • Like
Reactions: cy@
I have the same problem on my Raspberry Pi3.
I was using a Realtek RTL8188EUS usb Wi-Fi, and the connection kept degrading every time under not very heavy loads.
I couldn't figure out what the problem was... the driver, the configuration, or the hardware.
I tried switching to an Ethernet cable, and everything worked fine.
I'm still stuck with the Ethernet connection.
 
SirDice Thanks for your fast reply! I do understand that, though do I need to go to a new release to test if this still happens? Do the tools involved and/or FreeBSD changed significantly so the issue won't appear on a more recent release? I mean if I update and the issue persists, does that make the original post still valid? Just asking out of my ignorance as my initial thought was that this issue could be independent of a newer release.

Thanks again,
Lucas.
 
One of them is the TP-Link TL-WN725N and the other one is: https://pine64.com/product/usb-wifi-802-11b-g-n-rtl8188eu/
ah you use the same Chipset: Realtek RTL8188eu Chipset
this is my /boot/loader.conf
Code:
if_rtwn_load="YES"
if_rtwn_usb_load="YES"
if_rtwn_pci_load="YES"
legal.realtek.license_ack=1
rtwn-rtl8188eufw_load="YES"

wlan_load="YES"              # 802.11 support
wlan_wep_load="YES"          # 802.11 WEP support
wlan_ccmp_load="YES"         # 802.11 CCMP support
wlan_tkip_load="YES"         # 802.11 TKIP support
wlan_amrr_load="YES"         # AMRR transmit rate control algorithm

Maybe this will help you.
 
serjsk8 Thanks for supplying those lines. I'll compare them with what I currently have when I get back home. Is kind of relieving to also hear that someone else also has the same or a very similar issue. In the past while not with this config I experienced something kind of related: when configuring a `musicpd` server from time to time the streaming would choke badly at regular intervals. So I could listen music fine for a couple of minutes, then the connection would stall, then come back and so on. At that time I couldn't also figure out what was wrong and I went through `musicpd` documentation extensively thinking I was doing something incorrectly, but my setup was nothing more than a regular `musicpd` installation on a Raspberry Pi. While these are two completely different issues, they do somehow seem to relate each other: the connection seems to get stalled for some reason. `dmesg` never complained about anything and as I'm no network expert I could never dig the problem out.
 
serjsk8 I had most of the modules already loaded in my setup. `rtwn-rtl8188eufw` was not there so I loaded it. I'm currently stressing the connection with `wget` and streaming some random music from YouTube. `wget` doesn't ever reach beyond 500Kb/s and doing a `tail -f /var/log/messages` I can see these messages appearing almost every 1, 2 or 3 minutes:

Bash:
Nov  6 17:23:35 bluestar kernel: wlan0: link state changed to DOWN
Nov  6 17:23:35 bluestar wpa_supplicant[1279]: wlan0: CTRL-EVENT-DISCONNECTED bssid=XX:XX:XX:XX:XX:XX reason=0
Nov  6 17:23:37 bluestar wpa_supplicant[1279]: wlan0: Trying to associate with XX:XX:XX:XX:XX:XX (SSID='SkyDirect' freq=2437 MHz)
Nov  6 17:23:47 bluestar wpa_supplicant[1279]: wlan0: Authentication with XX:XX:XX:XX:XX:XX timed out.
Nov  6 17:23:47 bluestar wpa_supplicant[1279]: wlan0: CTRL-EVENT-DISCONNECTED bssid=XX:XX:XX:XX:XX:XX reason=3 locally_generated=1
Nov  6 17:23:47 bluestar wpa_supplicant[1279]: BSSID XX:XX:XX:XX:XX:XX ignore list count incremented to 2, ignoring for 10 seconds
Nov  6 17:23:47 bluestar wpa_supplicant[1279]: wlan0: CTRL-EVENT-DSCP-POLICY clear_all
Nov  6 17:23:49 bluestar wpa_supplicant[1279]: wlan0: Trying to associate with XX:XX:XX:XX:XX:XX (SSID='SkyDirect' freq=2437 MHz)
Nov  6 17:23:49 bluestar kernel: wlan0: link state changed to UP
Nov  6 17:23:49 bluestar wpa_supplicant[1279]: wlan0: Associated with XX:XX:XX:XX:XX:XX
Nov  6 17:23:49 bluestar dhclient[5282]: send_packet: No buffer space available
Nov  6 17:23:50 bluestar wpa_supplicant[1279]: wlan0: WPA: Key negotiation completed with XX:XX:XX:XX:XX:XX [PTK=CCMP GTK=CCMP]
Nov  6 17:23:50 bluestar wpa_supplicant[1279]: wlan0: CTRL-EVENT-CONNECTED - Connection to XX:XX:XX:XX:XX:XX completed [id=0 id_str=]
Nov  6 17:23:53 bluestar dhclient[6257]: New IP Address (wlan0): 10.17.11.235
Nov  6 17:23:53 bluestar dhclient[6261]: New Subnet Mask (wlan0): 255.255.255.0
Nov  6 17:23:53 bluestar dhclient[6265]: New Broadcast Address (wlan0): 10.17.11.255
Nov  6 17:23:53 bluestar dhclient[6269]: New Routers (wlan0): 10.17.11.36

According to https://www.toomanyatoms.com/computer/disconnection_codes.html reason 3 for CTRL-EVENT-DISCONNECTED is: "Deauthenticated because sending STA is leaving (or has left) the BSS" but not fully understand why is that happening. Any ideas?
 
`wget` doesn't ever reach beyond 500Kb/s
I had the same behavior, that's why I use Ethernet.
I also tried it with FreeBSD-RELEASE 13.x and I think with FreeBSD-RELEASE 14.x too.
Maybe you could try experimenting with the arguments in rc.conf
Code:
create_args_wlan0="country US regdomain FCC"
 
FWIW, your channels are not far enough apart.
Maybe it's not what causes your issues, 11g in general is quite slow.
 
Andriy I've updated my setup have both interfaces in `mode 11ng` and still no improvements at all. Why do think being in two different channels should be an issue? I selected channel 9 for `wlan1` because when I launched `wpa_cli` and issued a scan I saw that there were lots of access points in other channels. I checked downloading a big file from the pine board itself and it works absolutely fine. It peaks around 2.5Mb/s, but clients still face the same issue.
 
There have been a lot of WiFi improvements since 13.1. And, improvements to Arm64 support. Recommend you install 14.3. There have been a lot of improvements in rtwn(4) since then.
 
cy@ I'm doing that right now :-) I hope between today and tomorrow have it running again. For some reason I couldn't upgrade from 13.1, an integrity check kept popping up when running `freebsd-update` and I couldn't do much about, I was expecting to be able to run `freebsd-update` and bring it to 14.3 but no luck.
 
I'm no expert, and I use an entirely different NIC to you (iwlwifi0, which has it's own issues), but one issue I have is that my laptop ALWAYS connects to the 2.4GHz channels (usually channel 11) and is very, very slow. If I disable the 2.4GHz on my wireless router, the laptop connects at 5Ghz and is 10x faster (usually channel 48). I can then re-enable the 2.4GHz channels for those device that don't support 5GHz. (in the routers "smart" mode, devices should connect to either band and automatically choose the faster option) I note in your thread starter post that you are connecting to channels 6 and 9, both in the 2.4GHz band.

I really should look into whether there is a an option I can set to make driver prefer 5GHz. Or I can change my router so 2.4GHz and 5GHz are on different SSIDs, but that means going through all the devices and setting the 5GHz supporting ones to use that SSID instead, and I'm lazy :-)
 
dgmm Thanks for that insight! I was actually thinking that it could be related to realtek devices. Surprisingly, yesterday I tried to search for USB dongles based on Intel chipsets and couldn't find any (if they were available and not expensive I thought about buying and test them). Unfortunately a 5Ghz wireless network is not an option as I believe both my laptops cards only operate at 2.4Ghz.
 
Andriy I've updated my setup have both interfaces in `mode 11ng` and still no improvements at all. Why do think being in two different channels should be an issue? I selected channel 9 for `wlan1` because when I launched `wpa_cli` and issued a scan I saw that there were lots of access points in other channels. I checked downloading a big file from the pine board itself and it works absolutely fine. It peaks around 2.5Mb/s, but clients still face the same issue.
Sorry, I meant to say
> FWIW, your channels are not far enough apart.
Edited my comment now.

See https://www.intel.com/content/www/u...989/wireless/intel-killer-wi-fi-products.html for example.
 
Andriy Thanks for that info! Just tested all combinations (I can't select the channel for my mobile ap, which is 1). I tried : channels 1 - 1, 1 - 6 and finally 1 - 11. Performance is exactly is the same, still I think is good practice to avoid channel overlapping.
 
Yeah, I also tried different settings, but it didn’t make any difference.
Back then, I thought the problem was with my adapter — I had bought a very cheap USB adapter without an antenna.
But now it seems to me that the issue might be with the driver.
 
Back
Top