summaryrefslogtreecommitdiffstats
path: root/connect/dun/dun-name.sh.example
blob: 7eb570b9e4ee5e2f745be7040d806d87e8fc1271 (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
# example rfcomm DUN config script

dun_prepare()
{
	example_rfcomm_dev="$(get_unused_dev_node rfcomm)"
	[ -n "$example_rfcomm_dev" ] || die "Failed to get rfcomm devnode"
	example_rfcomm_pid=
	example_rfcomm_log="$(mktemp /tmp/example.rfcomm.log.XXXXXX)"
	[ -w "$example_rfcomm_log" ] || die "Failed to create example rfcomm log"
	example_hci_dev="hci0"
	example_chatscript="$(mktemp /tmp/example.chatscript.XXXXXX)"
	[ -w "$example_chatscript" ] || die "Failed to create example chatscript"
	example_pppd_pid=
	example_pppd_log="$(mktemp /tmp/example.pppd.log.XXXXXX)"
	[ -w "$example_pppd_log" ] || die "Failed to create example pppd log"
	example_pppd_linkname="example-dun-$$"
}

dun_stop()
{
	pppd_kill "example" "$example_pppd_pid" "$example_pppd_log"
	example_pppd_pid=

	rfcomm_kill "example" "$example_rfcomm_pid" "$example_rfcomm_log"
	example_rfcomm_pid=

	hci_dev_down "$example_hci_dev"
}

dun_start()
{
	hci_dev_up "$example_hci_dev"

	# Connect rfcomm
	rfcomm connect "$example_rfcomm_dev" \
		"AA:BB:CC:DD:EE:FF" \
		> "$example_rfcomm_log" 2>&1 &
	example_rfcomm_pid=$!
	rfcomm_wait_connect example "$example_rfcomm_pid" "$example_rfcomm_log"

	# Connect pppd
	#TODO Adjust the APN to your provider!
	make_chatscript "internet.t-d1.de" > "$example_chatscript"
	pppd "$example_rfcomm_dev" \
		115200 \
		logfile "$example_pppd_log" \
		linkname "$example_pppd_linkname" \
		debug \
		lock \
		show-password \
		noauth \
		defaultroute \
		noipdefault \
		crtscts \
		local \
		ipcp-accept-local \
		maxfail 10 \
		"lcp-echo-failure" 0 \
		"lcp-echo-interval" 0 \
		novj \
		nobsdcomp \
		novjccomp \
		nopcomp \
		noaccomp \
		mtu 1500 \
		mru 1500 \
		persist \
		passive \
		connect "/usr/sbin/chat -v -f $example_chatscript"
	sleep 0.5
	example_pppd_pid="$(cat "/var/run/ppp-${example_pppd_linkname}.pid")"
	[ -n "$example_pppd_pid" ] || die "Failed to get pppd pid"
	pppd_wait_connect example "$example_pppd_pid" "$example_pppd_log"
}

dun_destroy()
{
	rm -f "$example_rfcomm_log" "$example_pppd_log" "$example_chatscript"
}
bues.ch cgit interface