# This script runs last, after all network configuration
# has completed. It sets a property to let the framework
# know that setting up the interface is complete.

if [[ $interface == p2p* ]]
    then
    intf=p2p
    else
    intf=$interface
fi

# For debugging:
setprop dhcp.${intf}.reason "${reason}"

#HTC_WIFI_START
auto_ip()
{
	case "${reason}" in
	BOUND|INFORM|REBIND|REBOOT|RENEW|TIMEOUT|IPV4LL)
	    setprop dhcp.${intf}.ipaddress  "${new_ip_address}"
	    setprop dhcp.${intf}.gateway    "${new_routers%% *}"
	    setprop dhcp.${intf}.mask       "${new_subnet_mask}"
	    setprop dhcp.${intf}.leasetime  "${new_dhcp_lease_time}"
	    setprop dhcp.${intf}.server     "${new_dhcp_server_identifier}"
	    setprop dhcp.${intf}.vendorInfo "${new_vendor_encapsulated_options}"

    	setprop dhcp.${intf}.result "ok"
	    ;;

	EXPIRE|FAIL|STOP)
	    setprop dhcp.${intf}.result "failed"
	    ;;

	RELEASE)
	    setprop dhcp.${intf}.result "released"
	    ;;
	esac
}

no_auto_ip()
{
	case "${reason}" in
	BOUND|INFORM|REBIND|REBOOT|RENEW|TIMEOUT)
	    setprop dhcp.${intf}.ipaddress "${new_ip_address}"
	    setprop dhcp.${intf}.gateway   "${new_routers%% *}"
	    setprop dhcp.${intf}.mask      "${new_subnet_mask}"
	    setprop dhcp.${intf}.leasetime "${new_dhcp_lease_time}"
	    setprop dhcp.${intf}.server    "${new_dhcp_server_identifier}"
	    setprop dhcp.${intf}.vendorInfo "${new_vendor_encapsulated_options}"

	    setprop dhcp.${intf}.result "ok"
	    ;;

	EXPIRE|FAIL|IPV4LL|STOP)
	    setprop dhcp.${intf}.result "failed"
	    ;;

	RELEASE)
	    setprop dhcp.${intf}.result "released"
	    ;;
	esac
}


default()
{
	# For debugging:
	# setprop dhcp.${intf}.reason "default_${reason}"
	no_auto_ip
}

setprop dhcp.${intf}.ooxx "${autoip}"
case "${autoip}" in
ENABLE)
	auto_ip;;
DISABLE)
	no_auto_ip;;
*)
	default;;
esac
#HTC_WIFI_END
