[OpenWrt-Devel] wlan factory defaults

Piotr Dymacz pepe2k at gmail.com
Mon Nov 11 13:35:52 EST 2019


Hi Ivan,

On 11.11.2019 19:09, Ivan Baktsheev wrote:
> 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:

IMHO, that would be just too much bloat. OpenWrt is a generic platform 
(or a distribution), thus _personally_ I don't think we should support 
all the different ways vendors use to keep their software settings. 
Otherwise, we end up with bunch of scripts fetching data for various 
devices and that wouldn't get ever unified and probably at some point, 
unmaintainable. What's more, we can't trust values stored in vendor 
settings - in worse case, without sophisticated data verification, we 
might end up with broken uci configuration.

-- 
Cheers,
Piotr

> 
> 
> 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
> 


_______________________________________________
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