[OpenWrt-Devel] wlan factory defaults

Ivan Baktsheev dot.and.thing at gmail.com
Mon Nov 11 13:09:42 EST 2019


Hi,

I want to add new device, but as of now I can upload firmware wirelessly and then I need to connect using wired connection, because in stock OpenWrt image wireless is disabled.

For my router (and probably many others) default WiFi SSID stored in factory partition and it’s quite easy to extract. Unfortunately, wireless setup takes place in different time than wired/gpio/leds setup from /etc/board.d and defaults are hardcoded in /lib/wifi/mac80211.sh

Currently, I have /etc/board.d/04_factory_defaults, which extracts factory defaults for root password and WiFi. WiFi settings written into /etc/factory_80211, which then read at /lib/wifi/mac80211.sh

I would like to integrate this into OpenWrt, please take a look at full example at https://gist.github.com/apla/a81cad0a1dc9fedfeff19941116da369 and share your thoughts. Diff for /lib/wifi/mac80211.sh: 


diff --git a/package/kernel/mac80211/files/lib/wifi/mac80211.sh b/package/kernel/mac80211/files/lib/wifi/mac80211.sh
index be9c537..3c88c81 100644
--- a/package/kernel/mac80211/files/lib/wifi/mac80211.sh
+++ b/package/kernel/mac80211/files/lib/wifi/mac80211.sh
@@ -1,10 +1,12 @@
 #!/bin/sh
 . /lib/netifd/mac80211.sh
 
 append DRIVERS "mac80211"
 
+. /etc/factory_80211
+
 lookup_phy() {
 	[ -n "$phy" ] && {
 		[ -d /sys/class/ieee80211/$phy ] && return
 	}
 
@@ -95,25 +97,49 @@ detect_mac80211() {
 			dev_id="set wireless.radio${devidx}.path='$path'"
 		else
 			dev_id="set wireless.radio${devidx}.macaddr=$(cat /sys/class/ieee80211/${dev}/macaddress)"
 		fi
 
+		eval radio_i_disabled=\$radio${devidx}_disabled
+		radio_i_disabled=${radio_i_disabled:-${radio_disabled:-1}}
+		eval radio_i_country=\$radio${devidx}_country
+		radio_i_country=${radio_i_country:-$radio_country}
+		if [ ! -z "$radio_i_country" ] ; then
+			uci_radio_country="set wireless.radio${devidx}.country=${radio_i_country}"
+		else
+			uci_radio_country=
+		fi
+
+		eval wlan_i_ssid=\$wlan${devidx}_ssid
+		wlan_i_ssid=${wlan_i_ssid:-${wlan_ssid:-OpenWrt}}
+		eval wlan_i_encryption=\$wlan${devidx}_encryption
+		wlan_i_encryption=${wlan_i_encryption:-${wlan_encryption:-none}}
+		eval wlan_i_key=\$wlan${devidx}_key
+		wlan_i_key=${wlan_i_key:-$wlan_key}
+		if [ ! -z "$wlan_i_key" ] ; then
+			uci_wlan_key="set wireless.default_radio${devidx}.key=${wlan_i_key}"
+		else
+			uci_wlan_key=
+		fi
+
 		uci -q batch <<-EOF
 			set wireless.radio${devidx}=wifi-device
 			set wireless.radio${devidx}.type=mac80211
 			set wireless.radio${devidx}.channel=${channel}
 			set wireless.radio${devidx}.hwmode=11${mode_band}
 			${dev_id}
 			${ht_capab}
-			set wireless.radio${devidx}.disabled=1
+			set wireless.radio${devidx}.disabled=${radio_i_disabled}
+			${uci_radio_country}
 
 			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=OpenWrt
-			set wireless.default_radio${devidx}.encryption=none
+			set wireless.default_radio${devidx}.ssid=${wlan_i_ssid}
+			set wireless.default_radio${devidx}.encryption=${wlan_i_encryption}
+			${uci_wlan_key}
 EOF
 		uci -q commit wireless
 
 		devidx=$(($devidx + 1))
 	done
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


More information about the openwrt-devel mailing list