#!/bin/sh
#
# Start conf check
#

CheckAPExist(){

	if [ "$AP_CHANNEL_LITE" == "0" ]; then
		AP1mode=`/usr/local/sbin/wifi_ap_broadcast_check.sh AP5G`
		AP2mode=`/usr/local/sbin/wifi_ap_broadcast_check.sh AP2G4`
	
		if [ "${AP1mode}" == "0" ] && [ "${AP2mode}" == "0" ]; then
			/sbin/wifi-restart AP
		elif [ "$AP1mode" == "1" ] && [ "$AP2mode" == "0" ]; then
			/usr/local/sbin/wifi_ap_set_config.sh --ism_band 2.4 --enabled EnabledHomeNetwork
		elif [ "$AP1mode" == "0" ] && [ "$AP2mode" == "1" ]; then
			/usr/local/sbin/wifi_ap_set_config.sh --ism_band 5 --enabled EnabledHomeNetwork
		fi
	elif [ "$AP_CHANNEL_LITE" == "2" ]; then	
		AP2mode=`/usr/local/sbin/wifi_ap_broadcast_check.sh AP2G4`
		if [ "$AP2mode" == "0" ]; then
			/usr/local/sbin/wifi_ap_set_config.sh --ism_band 2.4 --enabled EnabledHomeNetwork
		fi
	elif [ "$AP_CHANNEL_LITE" == "5" ]; then
		AP1mode=`/usr/local/sbin/wifi_ap_broadcast_check.sh AP5G`
		if [ "$AP1mode" == "0" ]; then
			/usr/local/sbin/wifi_ap_set_config.sh --ism_band 5 --enabled EnabledHomeNetwork
		fi
	fi
}

case "$1" in
  start)
  	iwlist wlan1 scan
	/sbin/AutoChan.sh all booting
	/usr/local/sbin/wifi_ap_get_config.sh updateconfig > /dev/null 2>&1 &
	CheckAPExist
	;;
  stop)
	;;
  restart|reload)
	;;
	
  *)
	echo "Usage: $0 {start|stop|restart}"
	exit 1
esac

exit $?
