GW102 Development Manual

WiFi Function

The gateway supports WiFi 2.4G wireless functionality and has a built-in WiFi module that can connect to other WiFi hotspots.

The actual picture of the WiFi antenna connector is as follows:

The gateway is equipped with the M8188FU version of WiFi by default. If you need WiFi functionality of other versions, please contact technical support to place an order.

M8188FU Version

Preparation The WiFi module connects to the system through a USB signal. Use lsusb to check whether the USB bus has recognized the device.

root@gw102d512e4:~# lsusb
Bus 002 Device 003: ID 0bda:f179 Realtek Semiconductor Corp.
Bus 001 Device 002: ID 1782:4d11 Spreadtrum Communications Inc.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 002: ID 1a40:0101 Terminus Technology Inc. Hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Here, 0bda:f179 Realtek Semiconductor is the WiFi device, which indicates that it has been recognized successfully.

Q35343 Version

Q35343 is a HiSilicon WiFi module that supports 3 functions: BT SLE, NearLink SLE, and WiFi 2.4GHz.

Check USB device

root@gw102d512e4:~# lsusb
Bus 002 Device 003: ID ffff:3733
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 002: ID 1a40:0101 Terminus Technology Inc. Hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Here, ffff:3733 is the device ID of Q35343.

Check whether the WiFi driver has been loaded successfully and whether the wlan0 device exists.

root@gw102d512e4:~# dmesg| grep rtl8188
[ 1073.079427] usbcore: registered new interface driver rtl8188eu
root@i2x-6ub-gw:~# ifconfig wlan0
wlan0     Link encap:Ethernet  HWaddr 00:13:EF:F5:35:6A
          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)

The above two points confirm that the USB WiFi module has been recognized by the system and that the driver is also working normally.

Connect to a network using the wpa_supplicant command Before connecting, configure the WiFi access information, WiFi hotspot name, and password. wpa_passphrase can conveniently generate the required configuration file. Here, for example, the WiFi name we need to connect to is i2SOM, and the password is helloworld.

root@gw102d512e4:~# wpa_passphrase "i2SOM" > wifi.conf
helloworld

Then use the wpa_supplicant command to connect to the WiFi network.

root@gw102d512e4:~# wpa_supplicant -B -c wifi.conf -i wlan0
Successfully initialized wpa_supplicant

Do not execute the wpa_supplicant command multiple times. You can use the ps command to check whether a wpa_supplicant command is already running.

If so, you can use the kill command to terminate the corresponding process.

By default, the gateway configures the wlan0 device in systemd to obtain an IP address via DHCP. The configuration file content is as follows:

root@gw102d512e4:~# cat /etc/systemd/network/wlan0.network
[Match]
Name=wlan0

[Network]
DHCP=yes

It can also be changed to a static IP address by modifying the content as follows:

root@gw102d512e4:~# cat /etc/systemd/network/wlan0.network
[Match]
Name=wlan0

[Network]
Address=192.168.8.100/24

If the wlan0 device is not configured in systemd, you can also use udhcpc to manually obtain an IP address from the gateway device of the connected network.

root@gw102d512e4:~# udhcpc -i wlan0
udhcpc: started, v1.29.2
udhcpc: sending discover
udhcpc: sending discover
udhcpc: sending select for 192.168.2.122
udhcpc: lease of 192.168.2.122 obtained, lease time 86400
/etc/udhcpc.d/50default: Adding DNS 192.168.2.1

Now you can use the ping command to test connectivity with other devices in the WiFi network.

If you need to access the Internet, you can set the DNS address.

root@gw102d512e4:~# echo "nameserver 114.114.114.114" > /etc/resolv.conf
root@gw102d512e4:~# echo "nameserver 8.8.8.8" >> /etc/resolv.conf

root@gw102d512e4:~# ping baidu.com
PING baidu.com (220.181.38.148) 56(84) bytes of data.
64 bytes from 220.181.38.148 (220.181.38.148): icmp_seq=1 ttl=52 time=21.2 ms
64 bytes from 220.181.38.148 (220.181.38.148): icmp_seq=2 ttl=52 time=21.1 ms
64 bytes from 220.181.38.148 (220.181.38.148): icmp_seq=3 ttl=52 time=21.2 ms

Use the wpa_supplicant service with systemd The wpa_supplicant service uses the /etc/wpa_supplicant/wpa_supplicant-wlan0.conf file as its configuration file by default. If it does not exist, manually create the directory and corresponding file. The file content is as follows:

root@gw102d512e4:~# cat /etc/wpa_supplicant/wpa_supplicant-wlan0.conf
ctrl_interface=/var/run/wpa_supplicant
ctrl_interface_group=0
update_config=1

network={
}

Start the wpa_supplicant service using systemd.

systemctl enable wpa_supplicant@wlan0
/etc/systemd/system/multi-user.target.wants/wpa_supplicant@wlan0.service
systemctl start wpa_supplicant@wlan0

Check whether the service started successfully.

Use the systemctl status command to check whether the service has abnormal exit information; if not, it started normally.

systemctl restart systemd-networkd

Use the ps command to check whether the wpa_supplicant process is running.

root@gw102d512e4:~# ps | grep wpa_supplicant
  932 root      8992 S    /usr/sbin/wpa_supplicant -c/etc/wpa_supplicant/wpa_supplicant-wlan0.conf -iwlan0
 1085 root      2388 S    grep wpa_supplicant

The above indicates that the wpa_supplicant service is already running.

The wpa_supplicant service runs in the background. You can configure the network via the wpa_cli command.

Search for and view connectable WiFi networks in the current environment.

wpa_cli -i wlan0 scan wpa_cli -i wlan0 scan_result scan searches, and scan_result displays the search results.

Check current network connection status.

wpa_cli -i wlan0 status View configured WiFi settings. There can be multiple configurations, each distinguished by a network id.

Get configured WiFi settings.

wpa_cli -i wlan0 list_networks

Create a new WiFi configuration; it returns a network id, such as 0, 1, or 2.

wpa_cli -i wlan0 add_network

Set the WiFi SSID name.

wpa_cli -i wlan0 set_network 0 ssid '"TP-LINK"'

Set the WiFi BSSID name. If the WiFi name contains spaces or special characters, it is recommended to use BSSID to connect to the network.

wpa_cli -i wlan0 bssid 0 00:11:22:33:44:55

If the encryption method to connect is [WPA-PSK-CCMP+TKIP][WPA2-PSK-CCMP+TKIP][ESS] (WPA encryption)

wpa_cli -i wlan0 set_network 0 psk '"psk"'

If the encryption method to connect is [WEP][ESS] (WEP encryption)

wpa_cli -i wlan0 set_network 0 key_mgmt NONE
wpa_cli -i wlan0 set_network 0 wep_key0 '"psk"'

If the encryption method to connect is [ESS] (no encryption)

wpa_cli -i wlan0 set_network 0 key_mgmt NONE
wpa_cli -i wlan0 enable_network 0

Newly configured WiFi is disabled by default. Enable it. After enabling, if not connected to WiFi, the newly added visible WiFi will automatically connect.

wpa_cli -i wlan0 enable_network 0

Save the WiFi configuration. It is best to save after enabling WiFi; otherwise, the saved WiFi is disabled by default.

wpa_cli -i wlan0 save_config

If there are multiple WiFi configurations, you can select a WiFi configuration with the following command.

wpa_cli -i wlan0 select_network 0

Connect to a 5G Network Using Commands

wpa_passphrase "test5g" "12345678" > wifi.conf

cat wifi.conf
network={
	ssid="test5g"
	#psk="12345678"
	psk=21860937e0658a89d29089b9b034fffd21143c3af47b6f19e29795abe6f46d75
	freq_list=5180 5200 5220 5240 5260 5280 5300 5320 5500 5520 5540 5560 5580 5600 5620 5640 5660 5680 5700 5745 5765 5785 5805 5825
}

After generating the WiFi configuration with wpa_passphrase, you need to manually add freq_list to force use of the 5G band.

Use the wpa_supplicant command to connect to the network.

wpa_supplicant -B -i wlan0 -c wifi.conf

CONCURRENT Mode

In this mode, two network devices, wlan0 and wlan1, are registered, but there is only one hardware device. The WiFi function of the GW102 gateway supports only the following combinations.

  1. Station mode + Station mode
  2. Station mode + AP mode
  3. Station mode + P2P mode

It is recommended to use the Station function on wlan0 and the AP or P2P function on wlan1.