summaryrefslogtreecommitdiffstats
path: root/etc/rc.d/rfcomm_pppd_server
blob: f666684cff095fcaefd11c523f22f9f201737b1d (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
120
121
122
#!/bin/sh
#
# $FreeBSD$
#

# PROVIDE: rfcomm_pppd_server
# REQUIRE: DAEMON sdpd
# BEFORE: LOGIN
# KEYWORD: nojail

. /etc/rc.subr

name="rfcomm_pppd_server"
rcvar=`set_rcvar`
command="/usr/sbin/rfcomm_pppd"
start_cmd="rfcomm_pppd_server_start"
stop_cmd="rfcomm_pppd_server_stop"
required_modules="ng_btsocket"

rfcomm_pppd_server_start_profile()
{
	local _profile _profile_cleaned _punct _punct_c
	local _bdaddr _channel _x

	_profile=$1
	_profile_cleaned=$1

	_punct=". - / +"
	for _punct_c in ${_punct} ; do
		_profile_cleaned=`ltr ${_profile_cleaned} ${_punct_c} '_'`
	done

	rc_flags=""

	# Check for RFCOMM PPP profile bdaddr override
	#
	eval _bdaddr=\$rfcomm_pppd_server_${_profile_cleaned}_bdaddr
	if [ -n "${_bdaddr}" ]; then
		rc_flags="${rc_flags} -a ${_bdaddr}"
	fi

	# Check for RFCOMM PPP profile channel override
	#
	eval _channel=\$rfcomm_pppd_server_${_profile_cleaned}_channel
	if [ -z "${_channel}" ]; then
		_channel=1
	fi
	rc_flags="${rc_flags} -C ${_channel}"

	# Check for RFCOMM PPP profile register SP override
	#
	eval _x=\$rfcomm_pppd_server_${_profile_cleaned}_register_sp
	if [ -n "${_x}" ]; then
		if checkyesno "rfcomm_pppd_server_${_profile_cleaned}_register_sp" ; then
			rc_flags="${rc_flags} -S"
		fi
	fi

	# Check for RFCOMM PPP profile register DUN override
	#
	eval _x=\$rfcomm_pppd_server_${_profile_cleaned}_register_dun
	if [ -n "${_x}" ]; then
		if checkyesno "rfcomm_pppd_server_${_profile_cleaned}_register_dun" ; then
			rc_flags="${rc_flags} -D"
		fi
	fi

	# Run!
	#
	$command -s ${rc_flags} -l ${_profile}
}

rfcomm_pppd_server_stop_profile()
{
	local _profile

	_profile=$1

	/bin/pkill -f "^${command}.*[[:space:]]${_profile}\$" || \
		echo -n "(not running)"
}

rfcomm_pppd_server_start()
{
	local _profile _p

	_profile=$*
	if [ -z "${_profile}" ]; then
		_profile=${rfcomm_pppd_server_profile}
	fi

	echo -n "Starting RFCOMM PPP profile:"

	for _p in ${_profile} ; do
		echo -n " ${_p}"
		rfcomm_pppd_server_start_profile ${_p}
	done

	echo "."
}

rfcomm_pppd_server_stop()
{
	local _profile _p

	_profile=$*
	if [ -z "${_profile}" ]; then
		_profile=${rfcomm_pppd_server_profile}
	fi

	echo -n "Stopping RFCOMM PPP profile:"

	for _p in ${_profile} ; do
		echo -n " ${_p}"
		rfcomm_pppd_server_stop_profile ${_p}
	done

	echo "."
}

load_rc_config $name
run_rc_command $*
OpenPOWER on IntegriCloud