summaryrefslogtreecommitdiff
path: root/package/ppp/files/ppp.pre-up
blob: c83a091771ac54bfa8e8c96d458afcc44b485408 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/bin/sh

[ "$METHOD" == "ppp" ] || exit 0
[ "$IF_USE_TEMPLATE" ] || exit 0

[ -d /var/lock ] || mkdir /var/lock

[ -f "/etc/ppp/templates/$IF_USE_TEMPLATE" ] || {
	logger "$0: requested template '/etc/ppp/templates/$IF_USE_TEMPLATE' not found."
	exit 1
}

IDLEOPTIONS="persist\nmaxfail 0"
if [ "$IF_PPP_IDLETIME" -gt 0 ]; then
	IDLEOTPIONS="idletime $IF_PPP_IDLETIME"
fi

if [ "$IF_PPP_MTU" -gt 0 ] ; then 
	NETWORKOPTIONS="mtu $IF_PPP_MTU\nmru $IF_PPP_MTU"
fi

REPLACE="
	s,#IDLEOPTIONS#,$IDLEOPTIONS,
	s,#ENCAPS#,$IF_PPP_ENCAPS,
	s,#VPI#,$IF_PPP_VPI,
	s,#VCI#,$IF_PPP_VCI,
	s,#USERNAME#,$IF_PPP_USERNAME,
	s,#PASSWORD#,$IF_PPP_PASSWORD,
	s,#DEVICE#,$IF_PPP_DEVICE,
	s,#MODEMIP#,$IF_PPP_MODEMIP,
	s,#NETWORKOPTIONS#,$NETWORKOPTIONS,
"

sed "$REPLACE" < /etc/ppp/templates/$IF_USE_TEMPLATE > /etc/ppp/peers/$IF_PROVIDER

[ "$IF_PPP_ENCAPS" ] || encap=0
[ "$IF_PPP_PAYLOAD" ] || payload=1
[ "$IF_PPP_VPI" ] || $IF_PPP_VPI=1
[ "$IF_PPP_VCI" ] || $IF_PPP_VCI=32

case "$IF_PPP_PAYLOAD" in
bridged)
	payload=1
	;;
routed)
	payload=0
	;;
*)
	echo "Wrong payload, use either bridged or routed"
	exit 1
	;;
esac

case "$IF_PPP_ENCAPS" in
llc)
	encap=0
	;;
vc)
	encap=1
	;;
*)
	echo "Wrong Encapsulation use either llc or vc"
	exit 1
	;;
esac

case "$IF_PPP_DEVICE" in
nas*)
	count=$(echo $IF_PPP_DEVICE|sed -e "s/nas//")
	br2684ctl -b -c $count -e $encap -p $payload -a $IF_PPP_VPI.$IF_PPP_VCI
	ip link set up dev $IF_PPP_DEVICE
	;;
esac

case "$IF_USE_TEMPLATE" in
umts)
	# set UMTS-LED to green (bit 3)
	LED=$(cat /proc/sys/diag)
	echo $((LED | 8)) > /proc/sys/diag

	# wait for card to initialize
	COUNT=0
	while [ $((COUNT++)) -lt 20 ]; do
		[ -c "$IF_PPP_DEVICE" ] && break
		[ $COUNT -eq 20 ] && {
			logger "$0: '$IF_PPP_DEVICE' not found"
			exit 1
		}
		sleep 1
	done

	# wait till the SIM is ready
	comgt -s /etc/comgt/waitready.comgt -d $IF_PPP_DEVICE || exit 1

	# set pincode
	if [ "$IF_UMTS_PINCODE" ]; then
		COMGTPIN="$IF_UMTS_PINCODE" comgt PIN -d $IF_PPP_DEVICE || ERROR=1
	fi

	# set APN
	COMGTAPN="$IF_UMTS_APN" comgt APN -d $IF_PPP_DEVICE || ERROR=1

	# set umts/gprs mode if available (Option cards only)
	case "$IF_UMTS_MODE" in
		gprs_only)	comgt 2G -d $IF_PPP_DEVICE ;;
		umts_only)	comgt 3G -d $IF_PPP_DEVICE ;;
		umts_first)	comgt 3G2G -d $IF_PPP_DEVICE ;;
		"")		;;
		*)		echo "unknown umts-mode, exiting"
				ERROR=1
				;;
	esac

	if [ "$ERROR" == "1" ]; then
		echo "$LED" > /proc/sys/diag
		exit 1
	fi
	;;
esac