Sichang--Wireless Configuration Brief

Brief description of Wireless configuration

1 compile

1.1 Compile for the first time

​ If you need to add a wifi module when compiling for the first time, please check the configuration of the required version, which is located in the openwrt-18.06/target/linux/siflower/ folder, for example, sf19a28_ac28_fullmask_def.config is the configuration of the ac28 version . Check the configuration and make corresponding modifications: (The configuration files of all versions supported by Sichang are in this path)

CONFIG_PACKAGE_dnsmasq=y
CONFIG_PACKAGE_wireless-regdb=y
CONFIG_PACKAGE_kmod-cfg80211=y
CONFIG_PACKAGE_kmod-mac80211=y
CONFIG_PACKAGE_MAC80211_DEBUGFS=y
CONFIG_PACKAGE_MAC80211_MESH=y
CONFIG_PACKAGE_kmod-sf_smac=y
CONFIG_PACKAGE_SFSMAC_DBGINFO_ALLOCS=y
CONFIG_PACKAGE_SFUMAC_WIFI_TEST_SCRIPTS=y
CONFIG_PACKAGE_SFUMAC_WIFI_ATE_TOOLS=y
CONFIG_PACKAGE_SFUMAC_FMAC=y
CONFIG_PACKAGE_libiwinfo=y
CONFIG_PACKAGE_hostapd-common=y
CONFIG_PACKAGE_iw=y
CONFIG_WPA_MSG_MIN_PRIORITY=3
CONFIG_DRIVER_11N_SUPPORT=y
CONFIG_DRIVER_11AC_SUPPORT=y
CONFIG_PACKAGE_wpad-mini=y
CONFIG_PACKAGE_iwinfo=y

After the modification is completed, if you compile the ac28 image, you can use ./make.sh ac28 in the openwrt-18.06 directory to compile it. After the compilation is completed, you can get the image in the current directory.

1.2 Non-first compilation

If it is not the first time to compile, then you can use make menuconfig and select the following: (configured by default, you can directly make -j V=s)

Kernel modules ---> Wireless Drivers--->kmod-sf_smac  
Network--->hostapd-common
Utilities--->iwinfo  
Base system--->dnsmasq

After the modification is completed, save it, use make -j V=s in the openwrt-18.06 directory to compile, and the mirror image is located in bin/siflower/openwrt-siflower-sf16a18-mpw0-squashfs-sysupgrade.bin.

2 wifi configuration

The wifi configuration in the 1806 sdk follows the original wifi configuration of openwrt,
can refer to openwrt-wifi configuration.
The location of the configuration file in the image is /etc/config/wireless, and the typical configuration is as follows:

[External link picture transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the picture and upload it directly (img-rTxXba7R-1671777490458)(https://developers.siflower.cn/document/picture_download?pictureId=5c6d004e5466e40001704766)]

The configuration is divided into two layers. The wifi-device corresponds to the specific wifi driver device. Our hardware supports 2.4G and 5G devices.
wifi-iface corresponds to a single wifi interface, corresponding to a single ssid,
Multiple wifi-iface s can be configured under one wifi-device, up to 4 are supported.

2.1 Description of configuration options

2.1.1 wifi-device configuration options

Note: When the default value is "/", it means that this option does not necessarily appear, and it will only appear when certain settings are made; when the default value is "-", it means that there is a difference between 2.4G and 5G, which will be described in the description Be explained.

optionsvalue typeDefaultsdescribe
wifi-devicestringradio0drive device name
typestringmac80211The driver type is currently fixed as "mac80211".
countrystringCNCountry code, 2 uppercase letters, the default is CN, which means China (China), and the country code will affect the channel and transmit power.
channelstring/int-Channel, the default 2.4G is channel 1. When the value is "auto", it means that the optimal channel is automatically selected. Different countries have different channel restrictions. For example, the 2.4G channel in China is 1~13, and the 5G channel is 36~64, 149~165.
txpower_lvlint2Transmit power, can be set to 0, 1, 2. The larger the value, the greater the power.
max_all_num_staint64The maximum number of devices that the driver can connect to
netisolateboolean0Device isolation, if set to 1, devices under this device cannot access other bssid devices in the same bridge.
noscanboolean0When the value is 1, it means that the surrounding channels are not scanned.
pathstring-The nodes corresponding to the drivers under /sys/devices/ are generally not modified. The default is "platform/11000000.wifi-lb" for 2.4G and "platform/17800000.wifi-hb" for 5G.
htmodestring20MHzBandwidth mode, 2.4G supports 20MHz/40MHz, 5G supports 20MHz/40MHz/80MHz.
hwmodestring-wifi working mode, 2.4G supports 11b/11g/11n, 5G supports 11n/11a/11ac, the final mode is determined by htmode and hwmode
disabledboolean00 means enable the driver device, 1 means disable the driver device.
ht_coexboolean/When the value is 1, it means that the bandwidth of 20MHZ/40MHZ coexists, which has a certain relationship with htmode

2.1.2 wifi-iface configuration options

optionsvalue typeDefaultsdescribe
wifi-ifacestringdefault_radio0wifi-iface node name
devicestring-Corresponding to the wifi-device driver name, the default is radio0 for 2.4G and radio1 for 5G.
ifnamestringwlan0The name of the network card (iface), the corresponding name will be displayed when using ifconfig.
networkstringlanCorresponding bridge (bridge) name, if you need to add wifi to the lan port, configure this value as lan.
modestringap (sta,minotor)ap corresponds to the hotspot, sta corresponds to the station (station), and monitor corresponds to the monitoring mode. The default is ap mode.
ssidstringSiWIFi-****The name of wifi, up to 32 characters. Chinese is supported, but it will be displayed as "..." on the serial port. The numbers in the default name are derived from the mac address.
encryptionstringnoneEncryption method, "none" means no encryption, if you want to encrypt, it is recommended to change to "psk2+ccmp"
keystring12345678Wi-Fi password, psk2 needs to set more than 8 digits. This option does not take effect when the encryption method is not encrypted (none), while other encryption methods must be configured with a password.
hiddenboolean0Whether to hide hotspots, 1 means hidden, 0 means not hidden. After hiding, the device can only connect to wifi by manually adding SSID.
wpa_group_rekeyint3600Interval in seconds to refresh GTK (broadcast/multicast encryption keys). If this option is not set, the default is 86400 seconds (once per day) when using CCMP/GCMP as the group cipher, and 600 seconds (once every 10 minutes) when using TKIP as the group cipher.
isolateboolean0Whether the devices connected to this wifi are isolated, 1 means isolated, 0 means not isolated.
groupint-Groups in the bridge, different group s cannot access each other in the bridge. The default is 0 for 2.4G and 1 for 5G.
netisolateboolean0If it is set to 1, devices under this bssid cannot access devices of other bssids in the same bridge.

2.1.3 How to modify the default configuration of wifi in the source code

Just modify the package/kernel/mac80211/files/lib/wifi/mac80211.sh file.

#!/bin/sh
append DRIVERS "mac80211"

lookup_phy() {
	[ -n "$phy" ] && {
		[ -d /sys/class/ieee80211/$phy ] && return
	}

	local devpath
	config_get devpath "$device" path
	[ -n "$devpath" ] && {
		for phy in $(ls /sys/class/ieee80211 2>/dev/null); do
			case "$(readlink -f /sys/class/ieee80211/$phy/device)" in
				*$devpath) return;;
			esac
		done
	}

	local macaddr="$(config_get "$device" macaddr | tr 'A-Z' 'a-z')"
	[ -n "$macaddr" ] && {
		for _phy in /sys/class/ieee80211/*; do
			[ -e "$_phy" ] || continue

			[ "$macaddr" = "$(cat ${_phy}/macaddress)" ] || continue
			phy="${_phy##*/}"
			return
		done
	}
	phy=
	return
}

find_mac80211_phy() {
	local device="$1"

	config_get phy "$device" phy
	lookup_phy
	[ -n "$phy" -a -d "/sys/class/ieee80211/$phy" ] || {
		echo "PHY for wifi device $1 not found"
		return 1
	}
	config_set "$device" phy "$phy"

	config_get macaddr "$device" macaddr
	[ -z "$macaddr" ] && {
		config_set "$device" macaddr "$(cat /sys/class/ieee80211/${phy}/macaddress)"
	}

	return 0
}

check_mac80211_device() {
	config_get phy "$1" phy
	[ -z "$phy" ] && {
		find_mac80211_phy "$1" >/dev/null || return 0
		config_get phy "$1" phy
	}
	[ "$phy" = "$dev" ] && found=1
}

detect_mac80211() {
	devidx=0
	config_load wireless
	while :; do
		config_get type "radio$devidx" type
		[ -n "$type" ] || break
		devidx=$(($devidx + 1))
	done

	for _dev in /sys/class/ieee80211/*; do
		[ -e "$_dev" ] || continue

		dev="${_dev##*/}"

		found=0
		config_foreach check_mac80211_device wifi-device
		[ "$found" -gt 0 ] && continue

		mode_band="g"
		channel="1"
		htmode=""
		ht_capab=""
		ssidprefix="-2.4G"
		noscan="0"
		band="2.4G"
		htcodex="0"
		txpower="20"


		iw phy "$dev" info | grep -q 'Capabilities:' && htmode=HT20

		iw phy "$dev" info | grep -q '5180 MHz' && {
			mode_band="a"
			channel="161"
			ssidprefix=""
			band="5G"
			txpower="25"
			iw phy "$dev" info | grep -q 'VHT Capabilities' && htmode="VHT80"
		}

		[ -n "$htmode" ] && ht_capab="set wireless.radio${devidx}.htmode=$htmode"

		if [ -x /usr/bin/readlink -a -h /sys/class/ieee80211/${dev} ]; then
			path="$(readlink -f /sys/class/ieee80211/${dev}/device)"
		else
			path=""
		fi
		if [ -n "$path" ]; then
			path="${path##/sys/devices/}"
			case "$path" in
				platform*/pci*) path="${path##platform/}";;
			esac
			dev_id="set wireless.radio${devidx}.path='$path'"
		else
			dev_id="set wireless.radio${devidx}.macaddr=$(cat /sys/class/ieee80211/${dev}/macaddress)"
		fi
		[ -f "/sys/devices/factory-read/countryid" ] && {
			country=`cat /sys/devices/factory-read/countryid`
		}
		ssid=SiWiFi-`cat /sys/class/ieee80211/${dev}/macaddress | cut -c 13- | sed 's/://g'`$ssidprefix
		ssid_lease=SiWiFi-lease-$ssidprefix`cat /sys/class/ieee80211/${dev}/macaddress | cut -c 13- | sed 's/://g'`
		if [ ! -n "$country" ]; then
			country='CN'
		fi

		txpower_lvl=2
		[ -f "/etc/ext_pa_exist" ] && {
			txpower_lvl=1
		}
		uci -q batch <<-EOF
			set wireless.radio${devidx}=wifi-device
			set wireless.radio${devidx}.type=mac80211
			set wireless.radio${devidx}.country=${country}
			set wireless.radio${devidx}.txpower_lvl=${txpower_lvl}
			set wireless.radio${devidx}.txpower=${txpower}
			set wireless.radio${devidx}.channel=${channel}
			set wireless.radio${devidx}.band=${band}
			set wireless.radio${devidx}.hwmode=11${mode_band}
			set wireless.radio${devidx}.noscan=${noscan}
			set wireless.radio${devidx}.netisolate=0
			set wireless.radio${devidx}.max_all_num_sta=64
			set wireless.radio${devidx}.ht_coex=${ht_coex}
			${dev_id}
			${ht_capab}
			set wireless.radio${devidx}.disabled=0

			set wireless.default_radio${devidx}=wifi-iface
			set wireless.default_radio${devidx}.device=radio${devidx}
			set wireless.default_radio${devidx}.network=lan
			set wireless.default_radio${devidx}.mode=ap
			set wireless.default_radio${devidx}.ssid=${ssid}
			set wireless.default_radio${devidx}.encryption=none
			set wireless.default_radio${devidx}.key=12345678
			set wireless.default_radio${devidx}.hidden=0
			set wireless.default_radio${devidx}.ifname=wlan${devidx}
			set wireless.default_radio${devidx}.wpa_group_rekey=36000
			set wireless.default_radio${devidx}.isolate=0
			set wireless.default_radio${devidx}.group=1
			set wireless.default_radio${devidx}.disable_input=0
			set wireless.default_radio${devidx}.wps_pushbutton=1
			set wireless.default_radio${devidx}.wps_label=0

			set wireless.guest_radio${devidx}=wifi-iface
			set wireless.guest_radio${devidx}.device=radio${devidx}
			set wireless.guest_radio${devidx}.network=guest
			set wireless.guest_radio${devidx}.mode=ap
			set wireless.guest_radio${devidx}.ssid=${ssid}-guest
			set wireless.guest_radio${devidx}.encryption=none
			set wireless.guest_radio${devidx}.hidden=0
			set wireless.guest_radio${devidx}.ifname=wlan${devidx}-guest
			set wireless.guest_radio${devidx}.isolate=1
			set wireless.guest_radio${devidx}.group=1
			set wireless.guest_radio${devidx}.netisolate=0
			set wireless.guest_radio${devidx}.disable_input=0
			set wireless.guest_radio${devidx}.disabled=1
EOF
		uci -q commit wireless

			if [ "$devidx" == "0" ]; then
				uci -q batch <<-EOF
				set wireless.lease_radio${devidx}=wifi-iface
				set wireless.lease_radio${devidx}.device=radio${devidx}
				set wireless.lease_radio${devidx}.network=lease
				set wireless.lease_radio${devidx}.mode=ap
				set wireless.lease_radio${devidx}.ssid=${ssid_lease}
				set wireless.lease_radio${devidx}.encryption=none
				set wireless.lease_radio${devidx}.hidden=0
				set wireless.lease_radio${devidx}.ifname=wlan${devidx}-lease
				set wireless.lease_radio${devidx}.isolate=1
				set wireless.lease_radio${devidx}.group=1
				set wireless.lease_radio${devidx}.netisolate=0
				set wireless.lease_radio${devidx}.disable_input=0
				set wireless.lease_radio${devidx}.maxassoc=64
				set wireless.lease_radio${devidx}.disabled=1
				EOF
				uci -q commit wireless
			fi

		devidx=$(($devidx + 1))
	done
}

2.1.4 Correspondence between htmode and hwmode

Different hwmode s determine the configurable options of htmode. The following table lists the corresponding relationships of different modes.

2.1.4.1 2.4G configuration
2.4G modeconfigurationdescribe
11boption hwmode 11boption htmode must be deleted in this mode
option ht_coex must be deleted in this mode
11goption hwmode 11goption htmode must be deleted in this mode
option ht_coex must be deleted in this mode
11noption hwmode 11g option htmode HT20 (or option htmode HT40) option ht_coex 1When the value of ht_coex is 1, it is in 20MHz/40MHz hybrid mode;
When the value of ht_coex is 0, the value of htmode is the bandwidth
2.1.4.2 5G configuration
5G modeconfigurationdescribe
11aoption hwmode 11aoption htmode must be deleted in this mode
option ht_coex must be deleted in this mode
11noption hwmode 11a option htmode HT20 (or option htmode HT40) option ht_coex 1When the value of ht_coex is 1, it is in 20MHz/40MHz hybrid mode;
When the value of ht_coex is 0, the value of htmode is the bandwidth
11acoption hwmode 11a option htmode VHT20 (or option htmode VHT40 or option htmode VHT80)option ht_coex must be deleted in this mode

2.1.5 encryption encryption method

valueWPA versionkey encryption protocol
psk2+tkip+ccmp psk2+tkip+aesWPA2 Personal (PSK)TKIP, CCMP
psk2+tkipWPA2 Personal (PSK)TKIP
psk2+ccmp psk2+aes psk2WPA2 Personal (PSK)CCMP
psk+tkip+ccmp psk+tkip+aesWPA Personal (PSK)TKIP, CCMP
psk+tkipWPA Personal (PSK)TKIP
psk+ccmp psk+aes pskWPA Personal (PSK)CCMP
psk-mixed+tkip+ccmp psk-mixed+tkip+aesWPA/WPA2 Personal (PSK) mixed modeTKIP, CCMP
psk-mixed+tkipWPA/WPA2 Personal (PSK) mixed modeTKIP
psk-mixed+ccmp psk-mixed+aes psk-mixedWPA/WPA2 Personal (PSK) mixed modeCCMP
wepWEPnone

3. wifi configuration after firmware burning

3.1 How to modify wifi configuration

​ Directly modify the configuration file /etc/config/wireless and save it and execute **wifi reload**

​ The wifi command execution script is located in /sbin/wifi, and the relevant usage methods are shown in the table below

instructionparameterdescribe
wifi-Without any parameters, re-enable "all wifi"
wificonfigRegenerate the file "/etc/config/wireless" if it does not exist
wifireloadRe-enable "wifi with changed configuration"
wifidownturn off all wifi
wifiupenable all wifi
wifistatusPrint wifi information in the form of json string

3.2 View wifi information

Use the "iw" command to view wifi-related information, and the common iw commands are listed below.

instructionparameterdescribeexample
iwinfo/List all wireless network informationiwinfo
iw infoList individual wifi informationiw wlan0 info
iwlistList all wireless device informationiw list
iw scanScan surrounding signalsiw wlan1 scan
iw station dumpList all devices connected to this wifiiw wlan0 station sump

3.3 Adding AP nodes

Just add a paragraph in /etc/config/wireless, the simplest configuration is as follows:

  config wifi-iface
        option device 'radio0'
        option network 'lan'  
        option mode 'ap'
        option ssid 'SiWiFi-new-ap'
        option encryption 'psk2+ccmp'
        option key '12345678'
        option ifname 'wlan0-1'

3.4 Add new sta node

Just add a paragraph in /etc/config/wireless, the example is as follows:

config wifi-iface
        option key '12345678'
        option ifname 'sfi0'
        option network 'wwan'
        option encryption 'psk2+ccmp'
        option device 'radio0'
        option mode 'sta'
        option bssid 'A8:5A:F3:00:02:3F'
        option ssid 'SiWiFi-023c-2.4G-8_1'

4.wifi configuration effective process

4.1 How to modify the default configuration?

​ The script to generate the default configuration on the board is lib/wifi/mac80211.sh, which is located in package/kernel/mac80211/files/lib/wifi/mac80211.sh in the source code. This script is used to generate /etc/config/wirelesss

4.2 Where is the default configuration applied after it is generated?

​ /etc/config/wirelesss will be used by netifd and hostapd.
​ For netifd, the configuration of wireless will be read directly;
​ For hostapd, the configuration will be read by the script /lib/netifd/wireless/mac80211.sh, and the configuration file /var/run/hostapd-phy.conf will be generated for use by hostapd. The script is located in package/kernel/mac80211 in the source code /files/lib/netifd/wireless/mac80211.sh*.

4.3 wifi configuration flowchart

5 wifi driver module

The directory where the wifi module is stored on the board is /lib/modules/4.14.90/, and these modules will be automatically loaded sequentially during the board startup process

5.1 wifi driver related module loading process

5.2 Related commands of wifi driver module

instructionparameterdescribe
insmod"module name" ...To load the module, a simple command such as insmod /lib/modules/4.14.90/startcore.ko (or insmod startcore.ko or insmod startcore). It should be noted that some modules need to be loaded with more parameters, and it is recommended to use the sfwifi command for module operations.
rmmod"module name" ...unload the module
modinfo"module name" ...Display information about the module
sfwifiremoveRemove wifi driver related modules, including sf16a18_rf.ko, startcore.ko, sf16a18_fmac.ko
sfwifireloadReload the wifi driver module
sfwifiresetRestart wifi driver related modules

Tags: Linux openwrt 5g

Posted by clarencek on Sat, 24 Dec 2022 09:01:29 +1030