#!/bin/sh

# Defaults
CONFIG=/etc/ppp/pppoe.conf

if [ ! -f "$CONFIG" -o ! -r "$CONFIG" ] ; then
    echo "$0: Cannot read configuration file '$CONFIG'" >& 2
    exit 1
fi

. $CONFIG
. /usr/bin/scriptlib

PIDFILE_START="$PIDFILE.start"
PIDFILE_CONNECT="$PIDFILE.connect"
PIDFILE_PPPD="/var/run/ppp-pppoe.pid"


if [ "$DEMAND" != "no" ] ; then
    echo "Note: You have enabled demand-connection; pppoe-status may be inaccurate."
fi


# If no PIDFILE_PPPD, something fishy!
if [ ! -r "$PIDFILE_PPPD" ] ; then
    echo "pppoe-status: Link is down (can't read pppd PID file $PIDFILE_PPPD)"
    exit 1
fi

sl_get_ppp_PID_IFname $PIDFILE_PPPD PPP_PID PPP_IF
if [ $? = 0 ] ; then

	# check the cnt status is CONNECT 
	CNTSTATUS=`rdcsman 0x80040700 u16`
	[ $CNTSTATUS -ne 2 ] && echo "CNTSTATUS=$CNTSTATUS" && exit 1
	echo "$0: IF=$PPP_IF  PID=$PPP_PID"
	echo "pppoe-status: Link is up and running on interface $IF"
	exit 0
fi	    			


echo "pppoe-status: Link is down -- could not find interface corresponding to"
exit 1			    
		
