#!/bin/sh 

. /etc/wlan/wifi_conf

factory_mode=`/bin/config get factory_mode`
if [ "x$factory_mode" = "x1" ]; then
	echo "[set_txpower]: will not set power on factory mode" > /dev/console
	return 0
fi

have_set_txpower=$(/bin/config get have_set_txpower)  # default is NULL; it means power never be set until now

if [ "$is_dual_band" = "0" ]; then 
	wl2_plcphdr=`/bin/config get wla_tpscale`
	wl1_plcphdr=`/bin/config get wl_tpscale`
	wl0_plcphdr=`/bin/config get wla_2nd_tpscale`
else
	wl0_plcphdr=`/bin/config get wl_tpscale`
	wl1_plcphdr=`/bin/config get wla_tpscale`
fi

if [ "x$have_set_txpower" != "x1" ]; then
	# need to wait power stable when DUT bootup
	if [ ! -f /tmp/have_set_txpower ]; then
		touch /tmp/have_set_txpower
		sleep 20
	fi
fi

# need to set power every time, because GUI will only change tpscale, not change region
value=100
case $wl0_plcphdr in
	100) value=100 ;;
	75) value=70 ;;
	50) value=50 ;;
	25) value=20 ;;
esac
wl -i wl0 txpwr_percent $value || echo "=====set wl0 txpwr_pecent($value) command fail!" >/dev/console && echo "=====set wl0 txpwr_percent($value) command success!" >/dev/console


case $wl1_plcphdr in
	100) value=100 ;;
	75) value=70 ;;
	50) value=50 ;;
	25) value=20 ;;
esac
wl -i wl1 txpwr_percent $value || echo "=====set wl1 txpwr_pecent($value) command fail!" >/dev/console && echo "=====set wl1 txpwr_percent($value) command success!" >/dev/console

if [ "$is_dual_band" = "0" ]; then 
	case $wl2_plcphdr in
		100) value=100 ;;
		75) value=70 ;;
		50) value=50 ;;
		25) value=20 ;;
	esac
	wl -i wl2 txpwr_percent $value || echo "=====set wl2 txpwr_pecent($value) command fail!" >/dev/console && echo "=====set wl2 txpwr_percent($value) command success!" >/dev/console
fi

