I have found old Edimax N150 Wi-Fi USB network interface and would like to use it in FreeBSD 14.2. for some IoT project. I have not used Wi-Fi on FreeBSD for ages, so let's try it.
It is worth to mention that Wi-Fi network interface can be in three different modes
- Station (client) - ifconfig wlan0 mode sta
- Monitor - ifconfig wlan0 mode monitor
- Access Point - ifconfig wlan0 mode hostap
Access Point (ifconfig wlan0 mode hostap) is great in situations you would like to allow multiple Stations to connect, but the rtwn driver in FreeBSD does not support Access Point (hostap) mode.
Monitor mode on a wireless interface (ifconfig wlan0 mode monitor) is a special mode used primarily for passive packet capturing and wireless debugging, not for normal network communication. This mode should be supported by rtwn driver in FreeBSD, but I did not tested.
Station/Client (sta) mode is supported and it is actually the only mode we will cover in this blog post.
Let's do a configuration, setup, and some performance tests ...
Configuration and Setup
wlan0 as Wi-Fi network interface
By checking dmesg, we realize that Edimax N150 is actually using Realtek RTL8188CUS chip, which should be supported by the rtwn_usb driver in FreeBSD.
rtwn0 on uhub1
rtwn0: <Realtek 802.11n WLAN Adapter, class 0/0, rev 2.00/2.00, addr 2> on usbus0
rtwn0: MAC/BB RTL8188CUS, RF 6052 1T1R
It is important to say, taht Realtek RTL8188CUS does NOT support 5 GHz Wi-Fi, therefore only 2.4 GHz band can be used.
What you also realize is the fact, that we do not see any Wi-Fi network interface in ifconfig list of interfaces ...
root@kuna:~ #
ifconfig -a
em0: flags=1008843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST,LOWER_UP> metric 0 mtu 1500 options=4e524bb<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,JUMBO_MTU,VLAN_HWCSUM,LRO,WOL_MAGIC,VLAN_HWFILTER,VLAN_HWTSO,RXCSUM_IPV6,TXCSUM_IPV6,HWSTATS,MEXTPG> ether b8:ae:ed:71:63:df inet 192.168.4.188 netmask 0xffffff00 broadcast 192.168.4.255 media: Ethernet autoselect (1000baseT <full-duplex>) status: active nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL> 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 0x2 groups: lo nd6 options=21<PERFORMNUD,AUTO_LINKLOCAL> root@kuna:~ #
We can double check that, kernel modules if_rtwn_usb and rtwn are loaded ...
root@kuna:~ # kldstat | grep rtwn 4 1 0xffffffff82828000 dff7 if_rtwn_usb.ko 5 1 0xffffffff82836000 19140
rtwn.ko
root@kuna:~ #
Wi-Fi device is also visible as USB device ugen0.3 ... it refers to a USB Generic device attached to USB controller 0 as device number 3.
root@kuna:~ # usbconfig ugen1.1: <Intel EHCI root HUB> at usbus1, cfg=0 md=HOST spd=HIGH (480Mbps) pwr=SAVE (0mA) ugen0.1: <Intel XHCI root HUB> at usbus0, cfg=0 md=HOST spd=SUPER (5.0Gbps) pwr=SAVE (0mA) ugen0.2: <QuietKey Keyboard Dell Computer Corp.> at usbus0, cfg=0 md=HOST spd=LOW (1.5Mbps) pwr=ON (100mA) ugen1.2: <Integrated Rate Matching Hub Intel Corp.> at usbus1, cfg=0 md=HOST spd=HIGH (480Mbps) pwr=SAVE (0mA) ugen0.3:
<EW-7811Un 802.11n Wireless Adapter [Realtek RTL8188CUS] Edimax Technology Co., Ltd> at usbus0, cfg=0 md=HOST spd=HIGH (480Mbps) pwr=ON (500mA)
root@kuna:~ #
To be able to use wlan (Wi-Fi LAN) network interface, we have to create one. It can be done manualy from console by following command
ifconfig wlan0 create wlandev rtwn0
but if we want to do it automatically during the boot process, we have to add following two lines to /etc/rc.conf
wlans_rtwn0="wlan0" # Equivalent to: ifconfig wlan0 create wlandev rtwn0
ifconfig_wlan0="WPA DHCP country CZ"
That's enough to have wlan0 network interface on top of parent interface rtwn0.
Wi-Fi Client Connection Manager
That's where wpa_supplicant come into play. WPA (Wi-Fi Protected Access) is a security protocol developed by the Wi-Fi Alliance to secure wireless networks. A supplicant is the client device or software that requests access to a secure network.
The role of wpa_supplicant is to manage Wi-Fi client connections in Unix-like operating systems including FreeBSD. In FreeBSD we do not use wpa_supplicant directly, but it is used indirectly through /etc/rc.d/netif, which is a FreeBSD rc startup script responsible for configuring network interfaces during system boot or when manually invoked.
The only what we have to do is to create config file /etc/wpa_supplicant.conf with following content ...
network={
ssid="YourSSID"
psk="Your PreShared Key in correct format"
}
It is worth to mention, that WPA PreShared Key must be generated by the command wpa_passphrase and generated PSK has to be used in /etc/wpa_supplicant.conf
root@kuna:/etc #
wpa_passphrase PASNET YourPassword
network={ ssid="PASNET" #psk="YourPassword" psk=cce6e5a21451d52d430935b7ac315278f8c37b40cf453ac98b3f252c0faadde1 } root@kuna:/etc #
If we have wlan0 interface configured in /etc/rc.conf as discussed above ...
ifconfig_wlan0="WPA DHCP country CZ"
... your system will try to connect to Wi-Fi network automatically during the boot.
If you do not want connect to Wi-Fi automatically, you have to add NOAUTO option to ifconfig_wlan0 config line in /etc/rc.conf configuration file
ifconfig_wlan0="WPA DHCP NOAUTO country CZ"
With the NOAUTO option enabled, you must manually bring up the wlan0 interface to connect to the configured Wi-Fi network.
service netif
start
wlan0
and when wlan0 interface is up and associated, you can initiate DHCP Client (dhclient) ask your DHCP Server for network information like IP settings, default route, DNS, etc.
service dhclient
restart
wlan0
To disconnect from Wi-Fi Access Point use following command
service netif
stop
wlan0
FreeBSD Wi-Fi Related Useful Commands
sysctl
root@kuna:~ #
sysctl net.wlan.devices
net.wlan.devices: rtwn0 root@kuna:~ #
ifconfig
Old good ifconfig can be used to manage Wi-Fi from console.
Wi-Fi interface (fro exaple wlan0) is always created (aka cloned) on top of parent interface (rtwn0) in our case. /etc/rc.conf should be configures to create such wlan0 interface during the boot process, but sometime is good to know how to create wlan0 manually.
Let's create wlan0 interface
ifconfig wlan0 create wlandev rtwn0 wlanmode sta
ifconfig wlan0 up
We can also delete wlan0 interface if needed
ifconfig wlan0 destroy
We can scan available SSIDs.
ifconfig wlan0 list scan
root@kuna:~ #
ifconfig wlan0 list scan
SSID/MESH ID BSSID CHAN RATE S:N INT CAPS PASNET.IoT 84:16:f9:b7:02:4a 11 54M -89:-95 100 EPS RSN HTCAP WME PASNET f0:21:e0:9d:e3:c6 6 54M -73:-95 100 EPS RSN BSSLOAD HTCAP VHTCAP VHTOPMODE VHTPWRENV WME PASNET f0:21:e0:e6:d2:d4 6 54M -91:-95 100 EPS RSN BSSLOAD HTCAP VHTCAP VHTOPMODE VHTPWRENV WME 46b272 f0:21:e0:9d:e3:c4 6 54M -73:-95 100 P RSN HTCAP MESHCONF VHTCAP VHTOPMODE f0:21:e0:9d:e3:c8 6 54M -74:-95 100 ES HTCAP VHTCAP VHTOPMODE VHTPWRENV WME PASNET f0:21:e0:e5:f3:84 6 54M -91:-95 100 EPS RSN BSSLOAD HTCAP VHTCAP VHTOPMODE VHTPWRENV WME root@kuna:~ #
- Signal = -73 dBm → This is the strength of the WiFi signal received. Lower absolute values (closer to 0) mean stronger signal. For example, -50 dBm is excellent, -85 dBm is quite weak.
- Noise = -95 dBm → This is the background noise level. Lower is better here too, since it means less interference.
SNR = Signal - Noise
SNR = (-73) - (-95) = 22 dB
- 0–10 dB → Very poor. Connection may be unreliable or very slow.
- 10–20 dB → Poor. Some basic connectivity, but likely packet loss or low speeds.
- 20–40 dB → Fair to good. Usable for web browsing or video streaming.
- 40+ dB → Excellent. Strong, reliable connection.
root@kuna:/etc #
ifconfig wlan0 list regdomain
:regdomain FCC country US anywhere -ecm Channel 1 : 2412 MHz 11b Channel 6 : 2437 MHz 11g ht/20 Channel 1 : 2412 MHz 11g Channel 7 : 2442 MHz 11b Channel 1 : 2412 MHz 11g ht/20 Channel 7 : 2442 MHz 11g Channel 2 : 2417 MHz 11b Channel 7 : 2442 MHz 11g ht/20 Channel 2 : 2417 MHz 11g Channel 8 : 2447 MHz 11b Channel 2 : 2417 MHz 11g ht/20 Channel 8 : 2447 MHz 11g Channel 3 : 2422 MHz 11b Channel 8 : 2447 MHz 11g ht/20 Channel 3 : 2422 MHz 11g Channel 9 : 2452 MHz 11b Channel 3 : 2422 MHz 11g ht/20 Channel 9 : 2452 MHz 11g Channel 4 : 2427 MHz 11b Channel 9 : 2452 MHz 11g ht/20 Channel 4 : 2427 MHz 11g Channel 10 : 2457 MHz 11b Channel 4 : 2427 MHz 11g ht/20 Channel 10 : 2457 MHz 11g Channel 5 : 2432 MHz 11b Channel 10 : 2457 MHz 11g ht/20 Channel 5 : 2432 MHz 11g Channel 11 : 2462 MHz 11b Channel 5 : 2432 MHz 11g ht/20 Channel 11 : 2462 MHz 11g Channel 6 : 2437 MHz 11b Channel 11 : 2462 MHz 11g ht/20 Channel 6 : 2437 MHz 11g root@kuna:/etc #
root@kuna:/etc #
ifconfig wlan0 country CZ
root@kuna:/etc #
root@kuna:/etc #
ifconfig wlan0 list regdomain
:regdomain ETSI country CZ anywhere -ecm Channel 1 : 2412 MHz 11b Channel 6 : 2437 MHz 11g ht/20 Channel 1 : 2412 MHz 11g Channel 7 : 2442 MHz 11b Channel 1 : 2412 MHz 11g ht/20 Channel 7 : 2442 MHz 11g Channel 2 : 2417 MHz 11b Channel 7 : 2442 MHz 11g ht/20 Channel 2 : 2417 MHz 11g Channel 8 : 2447 MHz 11b Channel 2 : 2417 MHz 11g ht/20 Channel 8 : 2447 MHz 11g Channel 3 : 2422 MHz 11b Channel 8 : 2447 MHz 11g ht/20 Channel 3 : 2422 MHz 11g Channel 9 : 2452 MHz 11b Channel 3 : 2422 MHz 11g ht/20 Channel 9 : 2452 MHz 11g Channel 4 : 2427 MHz 11b Channel 9 : 2452 MHz 11g ht/20 Channel 4 : 2427 MHz 11g Channel 10 : 2457 MHz 11b Channel 4 : 2427 MHz 11g ht/20 Channel 10 : 2457 MHz 11g Channel 5 : 2432 MHz 11b Channel 10 : 2457 MHz 11g ht/20 Channel 5 : 2432 MHz 11g Channel 11 : 2462 MHz 11b Channel 5 : 2432 MHz 11g ht/20 Channel 11 : 2462 MHz 11g Channel 6 : 2437 MHz 11b Channel 11 : 2462 MHz 11g ht/20 Channel 6 : 2437 MHz 11g root@kuna:/etc #
wpa_passphrase
NOTE! Such generated psk (Pre-Shared Key) must be added into your /etc/wpa_supplicant.conf config file and not the PreSharedKey in ASCII format, you typically know.root@kuna:/etc #
wpa_passphrase PASNET YourPassword
network={ ssid="PASNET" #psk="YourPassword" psk=cce6e5a21451d52d430935b7ac315278f8c37b40cf453ac98b3f252c0faadde1 } root@kuna:/etc #
wpa_supplicant
wpa_supplicant -i wlan0 -c /etc/wpa_supplicant.conf -d
wifimgr
If you have Graphical Desktop Environment you can install wifimgr. It is a graphical (GUI) tool built using the Qt toolkit for managing wireless networks on FreeBSD.
pkg install -y wifimgr
However, WiFiMgr is a separate topic that I may cover in a future post when discussing FreeBSD-based desktop environments.
Network Performance
As FreeBSD Wi-Fi Client is connected to my Acces Point, we can check network details of wlan0 interface with following comamnd.
root@kuna:~ #
ifconfig wlan0
wlan0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500 options=0 ether 74:da:38:d3:86:80 inet 10.0.4.200 netmask 0xfffffc00 broadcast 10.0.7.255 groups: wlan ssid PASNET channel 6 (2437 MHz 11g ht/20) bssid f0:21:e0:9d:e3:c6 regdomain ETSI country CZ authmode WPA2/802.11i privacy ON deftxkey UNDEF AES-CCM 2:128-bit txpower 30 bmiss 7 scanvalid 60 protmode CTS ht20 ampdulimit 64k 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>
We can see that the Wi-Fi Client uses 2.4 GHz Frequency band and Wi-Fi Standard 802.11g (11g).
- iperf
- network upload throughput ~290 Kb/s (36 KB/s)
- network download (-R) throughput ~7.84 Mb/s (980 KB/s)
- iperf3
- network upload throughput ~261 Kb/s (32 KB/s)
- network download (-R) throughput ~7.85 Mb/s (980 KB/s)
- fetch
- download thtoughput ~7.7 Mb/s (960 KB/s)
- speedtest (ookla)
- download throughput ~ 8.06 Mb/s (1 MB/s)
Conclusion
If time permits, I’ll conduct a similar test on Linux for comparison.
No comments:
Post a Comment