Skip to content

Instantly share code, notes, and snippets.

@apla
Created October 25, 2023 18:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apla/aa35ef68862b2e8657920f8e7811ea63 to your computer and use it in GitHub Desktop.
Save apla/aa35ef68862b2e8657920f8e7811ea63 to your computer and use it in GitHub Desktop.
Beeline Smartbox Turbo+ OEM settings for OpenWrt firmware selector
#!/bin/sh
. /lib/functions.sh
. /lib/functions/system.sh
get_model_name () {
cat /proc/device-tree/compatible | tr -s '\000' '\n' | head -n 1
}
get_oem_data_parser () {
local brd=$(get_model_name)
brd=${brd//,/__}
brd=${brd//\//_}
echo "get_oem_data_${brd//-/_}"
}
get_mtd_cstr () {
local mtdname="$1"
local offset=$(($2))
local part
local mac_dirty
part=$(find_mtd_part "$mtdname")
if [[ -z $part ]]; then
echo "get_mtd_cstr: partition $mtdname not found!" >&2
return
fi
if [[ -z $offset ]]; then
echo "get_mtd_cstr: 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
}
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
}
get_device_oem_data () {
model_name=$(get_model_name)
local parser=$(get_oem_data_parser)
if [[ $(type -t $parser || echo fail) != "$parser" ]] ; then
. "/tmp/${model_name//\//-}.sh"
fi
set -e
$parser
set +e
}
apply_factory_defaults () {
if [[ ! -z $wlan_ssid ]] && uci get "wireless.@wifi-device[${wlan_phy_id}]" && uci get "wireless.@wifi-device[${wlan_phy_id}].disabled" ; then
uci -q batch << EOI
set wireless.@wifi-device[${wlan_phy_id}].disabled='0'
set wireless.@wifi-device[${wlan_phy_id}].country='${wlan_country}'
set wireless.@wifi-iface[${wlan_phy_id}].ssid='${wlan_ssid}'
set wireless.@wifi-iface[${wlan_phy_id}].encryption='${wlan_enc}'
set wireless.@wifi-iface[${wlan_phy_id}].key='${wlan_key}'
set wireless.@wifi-iface[${wlan_phy_id}].network='lan'
set wireless.@wifi-iface[${wlan_phy_id}].ieee80211r='1'
EOI
fi
if [[ ! -z $wlan_5ghz_ssid ]] && uci get "wireless.@wifi-device[${wlan_5ghz_phy_id}]" && uci get "wireless.@wifi-device[${wlan_5ghz_phy_id}].disabled" ; then
uci -q batch << EOI
set wireless.@wifi-device[${wlan_5ghz_phy_id}].disabled='0'
set wireless.@wifi-device[${wlan_5ghz_phy_id}].country='${wlan_country}'
set wireless.@wifi-iface[${wlan_5ghz_phy_id}].ssid='${wlan_5ghz_ssid}'
set wireless.@wifi-iface[${wlan_5ghz_phy_id}].encryption='${wlan_5ghz_enc:-$wlan_enc}'
set wireless.@wifi-iface[${wlan_5ghz_phy_id}].key='${wlan_5ghz_key:-$wlan_key}'
set wireless.@wifi-iface[${wlan_5ghz_phy_id}].network='lan'
set wireless.@wifi-iface[${wlan_5ghz_phy_id}].ieee80211r='1'
EOI
fi
uci commit wireless
service network restart
if [[ ! -z $root_password ]] ; then
set_factory_root_password "$root_password"
fi
if [[ ! -z $hostname ]] ; then
uci set system.@system[0].hostname="${hostname}"
# uci commit system
echo "${hostname}" > /proc/sys/kernel/hostname
/etc/init.d/system restart
fi
}
get_oem_data_beeline__smartbox_turbo_plus () {
local part="Factory"
wlan_phy_id=0
wlan_5ghz_phy_id=1
wlan_ssid=$(get_mtd_cstr "$part" 0x21080)
if [ "$wlan_ssid" != "${wlan_ssid#Beeline}" ] ; then
wlan_key=$(get_mtd_cstr "$part" 0x210a0)
wlan_5ghz_ssid="${wlan_ssid:0:8}5${wlan_ssid:9}"
hostname="${wlan_ssid:0:8}${wlan_ssid:11}"
serial_number=$(get_mtd_cstr "$part" 0x21010)
root_password="$serial_number"
else
wlan_ssid=
fi
}
wlan_country="RU"
wlan_enc="psk2"
get_device_oem_data
apply_factory_defaults
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment