WiFi client on Mars Board - FrankBau/meta-marsboard-bsp GitHub Wiki
This was tested with Edimax Technology Co., Ltd EW-7811Un 802.11n Wireless Adapter [Realtek RTL8188CUS] USB Dongle (USB ID 7392:7811).
Setting up a Wireless Client
On the build host in a bitbake shell enable Realtek RTL8192CU/RTL8188CU USB Wireless Network Adapter in the Linux kernel config:
$ bitbake -c menuconfig virtual/kernel
Device Drivers
[*] USB support
{M} USB Wireless Device Management support
[*] Network device support --->
[*] Wireless LAN --->
<M> Realtek rtlwifi family of devices --->
<M> Realtek RTL8192CU/RTL8188CU USB Wireless Network Adapter
You also need to copy the firmware (e.g. from the Linux host) to the SD card:
sudo cp '/lib/firmware/rtlwifi'/rtl81* '/media/...
or add linux-firmware
to your bitbake image.
wpa_supplicant -iwlan0 -c/etc/wpa_supplicant.conf -B
Boot your target from the SD card and check that the WiFi Dongle is present:
root@marsboard:~# lsusb
Bus 001 Device 003: ID 7392:7811 <--- EW-7811Un 802.11n Wireless Adapter
Bus 001 Device 002: ID 1a40:0101 <--- on-board USB hub
Bus 001 Device 001: ID 1d6b:0002 <--- Linux root hub
Check that driver is loaded (rtl chipset used in this example):
root@marsboard:~# dmesg | grep rtl
[ 3.370008] macaddr_acl=0
[ 3.509996] rtl8192cu: MAC address: 74:da:38:64:34:6f
[ 3.513928] rtl8192cu: Board Type 0
[ 3.516484] rtl_usb: rx_max_size 15360, rx_urb_num 8, in_ep 1
[ 3.521339] rtl8192cu: Loading firmware rtlwifi/rtl8192cufw_TMSC.bin
[ 3.582235] ieee80211 phy0: Selected rate control algorithm 'rtl_rc'
[ 3.583606] usbcore: registered new interface driver rtl8192cu
Unblock RF transmission (rfkill)
root@marsboard:~# rfkill unblock all
root@marsboard:~# ifconfig wlan0
wlan0 Link encap:Ethernet HWaddr 74:DA:38:64:34:6F
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
To make your changes permanent, prevent rfkill kernel module loading
by adding a new line rfkill
to file `/etc/modprobe.d/blacklist.conf'
Scan the available networks with
root@marsboard:~# iw wlan0 scan | grep SSID
Choose your favorite WiFi network. In a private setting, you have
typically to enter only a password (PSK: private shared key) to join the network.
Edit /etc/wpa_supplicant.conf
accordingly:
ctrl_interface=/var/run/wpa_supplicant
ctrl_interface_group=0
update_config=1
network={
proto=WPA
key_mgmt=WPA-PSK
ssid="my favorite WiFi network"
psk="my favorite WiFi network's secret password"
}
Note: storing the plaintext password in a file is unsafe! It's just for testing, there are more advanced ways to handle WiFi passwords, see wpa_passphrase
command.
In a corporate setiing, you might have a WPA-EAP network like the popular educational euduroam network. Check this for configuring eduroam: https://www.cms.hu-berlin.de/de/dl/netze/wlan/config/eduroam/linux
Now, check or edit /etc/network/interfaces
to contain the following lines:
# Wireless interfaces
auto wlan0
iface wlan0 inet dhcp
wireless_mode managed
wireless_essid any
wpa-driver wext
wpa-conf /etc/wpa_supplicant.conf
For testing, stop and (re)start the network services:
/etc/init.d/networking stop
/etc/init.d/networking start
For the first time, you will start wpa_supplicant manually and watch the output. So, first kill any existing wpa_supplicant processes:
root@marsboard:~# killall wpa_supplicant
and start it again from the command line as a background process: macaddr_acl=0 auth_algs=1 ignore_broadcast_ssid=0 wpa=3 wpa_passphrase=testtest wpa_key_mgmt=WPA-PSK wpa_pairwise=TKIP rsn_pairwise=CCMP
root@marsboard:~# wpa_supplicant -iwlan0 -c/etc/wpa_supplicant.conf -B
The output will be something like:
Successfully initialized wpa_supplicant
rtl8192cu: MAC auto ON okay!
rtl8192cu: Tx queue select: 0x05
IPv6: ADDRCONF(NETDEV_UP): wlan0: link is not ready
wlan0: SME: Trying to authenticatwlan0: authenticate with 9c:d6:43:xx:xx:xx (SSID='my favorite WiFi network' freq=2437 MHz)
wlan0: send auth to 9c:d6:43:xx:xx:xx (try 1/3)
wlan0: authenticated
wlan0: Trying to associate with 9c:d6:43:xx:xx:xx (SSID='my favorite WiFi network' freq=2437 MHz)
wlan0: associate with 9c:d6:43:xx:xx:xx (try 1/3)
wlan0: RX AssocResp from 9c:d6:43:xx:xx:xx (capab=0x431 status=0 aid=1)
IPv6: ADDRCONF(NETDEV_CHANGE): wlan0: link becomes ready
wlan0: associated
wlan0: Associated with 9c:d6:43:xx:xx:xx
wlan0: WPA: Key negotiation completed with 9c:d6:43:xx:xx:xx [PTK=CCMP GTK=TKIP]
wlan0: CTRL-EVENT-CONNECTED - Connection to 9c:d6:43:xx:xx:xx completed [id=0 id_str=]
Optionally use wpa_cli like wpa_cli status
to get moire info about the wlan0 connection.
Finally, get a dhcp lease:
root@marsboard:~# udhcpc -i wlan0
udhcpc (v1.24.1) started
Sending discover...
Sending select for 192.168.2.148...
Lease of 192.168.2.148 obtained, lease time 1814400
/etc/udhcpc.d/50default: Adding DNS 192.168.2.1
Now, your WiFi connection is ready:
root@marsboard:~# ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8): 56 data bytes
64 bytes from 8.8.8.8: seq=0 ttl=47 time=32.843 ms
64 bytes from 8.8.8.8: seq=1 ttl=47 time=44.033 ms
64 bytes from 8.8.8.8: seq=2 ttl=47 time=33.061 ms