#!/bin/sh

net_detect ()
{
    echo "do control firmware ping..." > /dev/console
    ping -c 2 www.netgear.com > /tmp/firmware_ping_result 2> /dev/null

    result=`cat /tmp/firmware_ping_result`

    if [ "x$result" = "x" -o "x$(echo $result |grep "100% packet loss")" != "x" ]; then
		ping_status=0
	fi
}

ping_status=1
wanport_status=`cat /tmp/port_status` 2> /dev/null
if [ "$wanport_status" != "1" ]; then
	ping_status=0
else
	net_detect
fi
echo $ping_status > /tmp/control_firmware_status
