# 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}"

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}.time_servers "${new_time_servers}"
    setprop dhcp.${intf}.ntp_servers  "${new_ntp_servers}"

    setprop dhcp.${intf}.result       "ok"
    setprop dhcp.fanvil.lease.read    "ok"
    ;;

EXPIRE|FAIL|IPV4LL|STOP)
    setprop dhcp.${intf}.ipaddress    ""
    setprop dhcp.${intf}.gateway      ""
    setprop dhcp.${intf}.mask         ""
    setprop dhcp.${intf}.leasetime    ""
    setprop dhcp.${intf}.server       ""
    setprop dhcp.${intf}.vendorInfo   ""
    setprop dhcp.${intf}.pid          ""
    setprop dhcp.${intf}.time_servers ""
    setprop dhcp.${intf}.ntp_servers  ""

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

RELEASE)
    setprop dhcp.${intf}.ipaddress    ""
    setprop dhcp.${intf}.gateway      ""
    setprop dhcp.${intf}.mask         ""
    setprop dhcp.${intf}.leasetime    ""
    setprop dhcp.${intf}.server       ""
    setprop dhcp.${intf}.vendorInfo   ""
    setprop dhcp.${intf}.pid          ""
    setprop dhcp.${intf}.time_servers ""
    setprop dhcp.${intf}.ntp_servers  ""

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