# This script is for option 66, 67 and 150 to set properties that contain the
# tftp server addresses and boot file name given by the DHCP server.
# Author: jay
# Date: 2013/08/22

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

set_tftp_props()
{
    #setprop dhcp.${intf}.tftpsname "${new_tftp_server_name}"
    #setprop dhcp.${intf}.tftpserverlist "${new_tftp_server_ip}"
    #setprop dhcp.${intf}.bootfile_name "${new_bootfile_name}"
    if [[ ${#new_tftp_server_name} -gt ${PROPERTY_VALUE_MAX} ]]
        then
        setprop dhcp.tftpsname ""
        else
        setprop dhcp.tftpsname "${new_tftp_server_name}"
    fi

    if [[ ${#new_tftp_server_ip} -gt ${PROPERTY_VALUE_MAX} ]]
        then
        setprop dhcp.tftpserverlist ""
        else
        setprop dhcp.tftpserverlist "${new_tftp_server_ip}"
    fi

    if [[ ${#new_bootfile_name} -gt ${PROPERTY_VALUE_MAX} ]]
        then
        setprop dhcp.bootfile_name ""
        else
        setprop dhcp.bootfile_name "${new_bootfile_name}"
    fi
}

unset_tftp_props()
{
    setprop dhcp.tftpsname ""
    setprop dhcp.tftpserverlist ""
    setprop dhcp.bootfile_name ""
}

case "${reason}" in
BOUND|INFORM|REBIND|REBOOT|RENEW|TIMEOUT)       set_tftp_props;;
EXPIRE|FAIL|IPV4LL|RELEASE|STOP)                unset_tftp_props;;
esac
