#!/bin/sh

insmod irda
insmod ircomm
insmod ircomm-tty
insmod sa1100_ir
sleep 1
ifconfig irda0 up
echo '1' > /proc/sys/net/irda/discovery

if [ ! -z "$1" ] ; then
	echo -n number:
	read NUMBER
	echo -n user:
	read PPPUSERNAME
	echo -n password:
	read PPPPASSWORD
else
	NUMBER=0917100000
	PPPUSERNAME=38591
	PPPPASSWORD=38591
fi

cat << _CHAT_ > /etc/ppp/chat
ABORT "BUSY"
ABORT "NO CARRIER"
"" "\d"
"" "ate1"
"" "atz"
OK "atdt$NUMBER"
CONNECT
_CHAT_


echo $PPPUSERNAME' * '$PPPPASSWORD > /etc/ppp/pap-secrets 

echo calling and connectiong...

while [ -z "$nick" ] ; do
	nick=`cat /proc/net/irda/discovery | grep nickname`
done

echo $nick

pppd /dev/ircomm0 115200 \
	defaultroute usepeerdns \
	noauth local lock \
	connect 'chat -e -f /etc/ppp/chat' \
	lcp-echo-failure 99 \
	user "$PPPUSERNAME"

sleep 1 # wait for a connection

ifconfig | grep -A 6 ppp # show the connection

sleep 1 # wait some more

rm /etc/ppp/pap-secrets # remove the file containing your password
rm /etc/ppp/chat	# remove chat script

ifconfig irda0 down
sleep 1
rmmod ircomm-tty
rmmod ircomm
rmmod sa1100_ir
rmmod irda
