Last active
March 16, 2020 19:34
-
-
Save apla/a81cad0a1dc9fedfeff19941116da369 to your computer and use it in GitHub Desktop.
OpenWrt preconfigured wlan
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
. /lib/functions.sh | |
. /lib/functions/system.sh | |
get_board_name () { | |
cat /proc/device-tree/compatible | tr -s '\000' '\n' | head -n 1 | |
} | |
mtd_get_cstring () { | |
local mtdname="$1" | |
local offset=$(($2)) | |
local part | |
local mac_dirty | |
part=$(find_mtd_part "$mtdname") | |
if [ -z "$part" ]; then | |
echo "mtd_get_cstring: partition $mtdname not found!" >&2 | |
return | |
fi | |
if [ -z "$offset" ]; then | |
echo "mtd_get_cstring: offset missing" >&2 | |
return | |
fi | |
cstring=$(dd if="$part" skip="$offset" count=1 bs=32b iflag=skip_bytes 2>/dev/null | tr -s '\000' '\n' | head -n1) | |
echo $cstring | |
} | |
apply_factory_defaults () { | |
local board=$(get_board_name) | |
case $board in | |
beeline,smartbox-turbo-plus) | |
wlan0_ssid=$(mtd_get_cstring factory 0x21080) | |
if [ "$wlan0_ssid" != "${wlan0_ssid#Beeline}" ] ; then | |
wlan1_ssid=${wlan0_ssid:0:8}5${wlan0_ssid:9} | |
wlan_key=$(mtd_get_cstring factory 0x210a0) | |
serial_number=$(mtd_get_cstring factory 0x21010) | |
root_password="$serial_number" | |
radio_disabled=0 | |
radio_country=RU | |
else | |
wlan0_ssid= | |
fi | |
;; | |
esac | |
: > /etc/factory_80211 | |
known_vars="wlan_ssid wlan0_ssid wlan1_ssid wlan_key wlan0_key wlan1_key radio_disabled radio_country" | |
for var_name in $known_vars ; do | |
eval var_value=\$$var_name | |
if [ ! -z "$var_value" ] ; then | |
echo $var_name=\"$var_value\" >>/etc/factory_80211 | |
fi | |
done | |
set_factory_root_password $root_password | |
} | |
apply_factory_defaults | |
set_factory_root_password () { | |
factory_root_password=$1 | |
root_shadow=$(cat /etc/shadow | grep '^root' | cut -d ':' -f 2) | |
if [ "x$root_shadow" == "x" -a "x$factory_root_password" != "x" ] ; then | |
echo -e "$factory_root_password\n$factory_root_password" | passwd root | |
fi | |
} | |
exit 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
wlan0_ssid="Beeline_2G_FF4812" | |
wlan1_ssid="Beeline_5G_FF4812" | |
wlan_key="GJKPpAbsE" | |
wlan_encryption="psk2" | |
radio_country="RU" | |
radio_disabled=0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment