xref: /freebsd/libexec/rc/rc.d/rfcomm_pppd_server (revision 734e82fe33aa764367791a7d603b383996c6b40b)
1#!/bin/sh
2#
3#
4
5# PROVIDE: rfcomm_pppd_server
6# REQUIRE: DAEMON sdpd
7# BEFORE: LOGIN
8# KEYWORD: nojail
9
10. /etc/rc.subr
11
12name="rfcomm_pppd_server"
13desc="RFCOMM PPP daemon"
14rcvar="rfcomm_pppd_server_enable"
15command="/usr/sbin/rfcomm_pppd"
16start_cmd="rfcomm_pppd_server_start"
17stop_cmd="rfcomm_pppd_server_stop"
18required_modules="ng_btsocket"
19
20rfcomm_pppd_server_start_profile()
21{
22	local _profile _profile_cleaned _punct _punct_c
23	local _bdaddr _channel _x
24
25	_profile=$1
26	_profile_cleaned=$1
27
28	_punct=". - / +"
29	for _punct_c in ${_punct} ; do
30		_profile_cleaned=`ltr ${_profile_cleaned} ${_punct_c} '_'`
31	done
32
33	rc_flags=""
34
35	# Check for RFCOMM PPP profile bdaddr override
36	#
37	eval _bdaddr=\$rfcomm_pppd_server_${_profile_cleaned}_bdaddr
38	if [ -n "${_bdaddr}" ]; then
39		rc_flags="${rc_flags} -a ${_bdaddr}"
40	fi
41
42	# Check for RFCOMM PPP profile channel override
43	#
44	eval _channel=\$rfcomm_pppd_server_${_profile_cleaned}_channel
45	if [ -z "${_channel}" ]; then
46		_channel=1
47	fi
48	rc_flags="${rc_flags} -C ${_channel}"
49
50	# Check for RFCOMM PPP profile register SP override
51	#
52	eval _x=\$rfcomm_pppd_server_${_profile_cleaned}_register_sp
53	if [ -n "${_x}" ]; then
54		if checkyesno "rfcomm_pppd_server_${_profile_cleaned}_register_sp" ; then
55			rc_flags="${rc_flags} -S"
56		fi
57	fi
58
59	# Check for RFCOMM PPP profile register DUN override
60	#
61	eval _x=\$rfcomm_pppd_server_${_profile_cleaned}_register_dun
62	if [ -n "${_x}" ]; then
63		if checkyesno "rfcomm_pppd_server_${_profile_cleaned}_register_dun" ; then
64			rc_flags="${rc_flags} -D"
65		fi
66	fi
67
68	# Run!
69	#
70	$command -s ${rc_flags} -l ${_profile}
71}
72
73rfcomm_pppd_server_stop_profile()
74{
75	local _profile
76
77	_profile=$1
78
79	/bin/pkill -f "^${command}.*[[:space:]]${_profile}\$" || \
80		echo -n "(not running)"
81}
82
83rfcomm_pppd_server_start()
84{
85	local _profile _p
86
87	_profile=$*
88	if [ -z "${_profile}" ]; then
89		_profile=${rfcomm_pppd_server_profile}
90	fi
91
92	startmsg -n "Starting RFCOMM PPP profile:"
93
94	for _p in ${_profile} ; do
95		startmsg -n " ${_p}"
96		rfcomm_pppd_server_start_profile ${_p}
97	done
98
99	startmsg "."
100}
101
102rfcomm_pppd_server_stop()
103{
104	local _profile _p
105
106	_profile=$*
107	if [ -z "${_profile}" ]; then
108		_profile=${rfcomm_pppd_server_profile}
109	fi
110
111	echo -n "Stopping RFCOMM PPP profile:"
112
113	for _p in ${_profile} ; do
114		echo -n " ${_p}"
115		rfcomm_pppd_server_stop_profile ${_p}
116	done
117
118	echo "."
119}
120
121load_rc_config $name
122run_rc_command $*
123