#!/bin/sh

# Source function library.
. /etc/rc.d/init.d/functions

# set to correct product (USB or PCI)
UNICORN="unicorn_pci_eth"
#UNICORN="unicorn_usb_eth"

# ANSI=1,G.lite=2,MULTI=3,G.dmt=4,
MODULATION=1

# default VPI, VCI and encapsulation
VPI=8
VCI=35

# standard setting for PPP over Ethernet
PROTOCOL=pppoe
ENCAPS=llc-encaps

# standard setting for PPP over ATM
#PROTOCOL=pppoatm
#ENCAPS=vc-encaps


echo -n "$1 $UNICORN $PROTOCOL $VPI.$VCI $ENCAPS"

stop () {
	killproc pppd >/dev/null 2>&1
	/sbin/ifconfig dsl0 down >/dev/null 2>&1
	/sbin/modprobe -r $UNICORN >/dev/null 2>&1
	return $?
}

start() {
	/sbin/modprobe $UNICORN PROTOCOL=$PROTOCOL ActivationMode=$MODULATION VPI=$VPI VCI=$VCI >/dev/null 2>&1
   	[ ! "$?" = 0 ] && return $?
	/sbin/ifconfig dsl0 up
	[ ! "$?" = 0 ] && return $?
	echo -n "start rp-pppoe"
	pppd pty 'pppoe -I dsl0 -m 1452'
	[ ! "$?" = 0 ] && return $?
	return 0
}

case "$1" in
    stop)
	stop
	;;
    
    start)
	start
	;;	
    
    restart)
	stop
	start
	;;
    
    *)
	echo $"Usage: $0 {start|stop|restart}"
	exit 1
esac

RETVAL=$?
if [ $RETVAL = 0 ]; then
    echo_success
else 
    echo_failure
fi
echo
exit $RETVAL
