View | Details | Raw Unified | Return to bug 248584 | Differences between
and this patch

Collapse All | Expand All

(-)head/libexec/rc/rc.d/btpand (+173 lines)
Line 0 Link Here
1
#! /bin/sh
2
#
3
# $FreeBSD$
4
#
5
6
# PROVIDE: btpand
7
# REQUIRE: FILESYSTEMS NETWORKING
8
# REQUIRE: netif bluetooth
9
# BEFORE:
10
# KEYWORD: shutdown
11
12
. /etc/rc.subr
13
. /etc/network.subr
14
15
name="btpand"
16
desc="Bluetooth PAN daemon"
17
rcvar="btpand_enable"
18
start_precmd="btpand_start_precmd"
19
stop_postcmd="btpand_stop_postcmd"
20
required_modules=""
21
required_vars=""
22
23
load_rc_config "${name}"
24
25
hccontrol="${bluetooth_hccontrol:-/usr/sbin/hccontrol}"
26
27
: ${btpand_enable="NO"}
28
: ${btpand_tapif="tap0"}
29
: ${btpand_device=""}
30
: ${btpand_service="PANU"}
31
: ${btpand_remote=""}
32
33
command="/usr/sbin/${name}"
34
pidfile="/var/run/${btpand_tapif}.pid"
35
36
btpand_bdaddr ()
37
{
38
	local - hci_node_name
39
	hci_node_name="${1:+-n ${1}hci}"
40
	${hccontrol} ${hci_node_name} -N read_bd_addr | cut -f 2 -w
41
}
42
43
btpand_device ()
44
{
45
	case "${1}" in	# (
46
	'')
47
		return 1
48
		;;	# (
49
	uart*|btccc*|ubt*)
50
		btpand_bdaddr "${1}"
51
		;;	# (
52
	[0-9A-Fa-f][0-9A-Fa-f]:[0-9A-Fa-f][0-9A-Fa-f]:[0-9A-Fa-f][0-9A-Fa-f]:[0-9A-Fa-f][0-9A-Fa-f]:[0-9A-Fa-f][0-9A-Fa-f]:[0-9A-Fa-f][0-9A-Fa-f]|*)
53
		 # bdaddr or /etc/bluetooth/hosts
54
		echo "${1}"
55
		;;
56
	esac
57
}
58
59
btpand_start_precmd ()
60
{
61
	local -
62
	# tap(4): to keep configured addresses when btpand stopped
63
	${IFCONFIG_CMD} ${btpand_tapif} link0
64
}
65
66
btpand_stop_postcmd ()
67
{
68
	local -
69
	if [ -f "${pidfile}" ] ; then
70
		rm -f -- "${pidfile}"
71
	fi
72
}
73
74
btpand_setup_flags ()
75
{
76
	if ! ifexists ${btpand_tapif} ; then
77
		warn
78
		return 1
79
	fi
80
	btpand_flags="${btpand_flags:-}${btpand_tapif:+ -i ${btpand_tapif}}"
81
82
	if ! btpand_device=$(btpand_device "${btpand_device}") ; then
83
		warn
84
		return 1
85
	fi
86
	btpand_flags="${btpand_flags:-}${btpand_device:+ -d ${btpand_device}}"
87
88
	case "${btpand_service}" in	# (
89
	[Nn][Aa][Pp])
90
		btpand_flags="${btpand_flags:-}${btpand_service:+ -s NAP}"
91
		;;	# (
92
	[Gg][Nn])
93
		btpand_flags="${btpand_flags:-}${btpand_service:+ -s GN}"
94
		;;	# (
95
	[Pp][Aa][Nn][Uu])
96
		btpand_flags="${btpand_flags:-}${btpand_service:+ -s PANU}"
97
		;;	# (
98
	*)
99
		warn "unsupported PAN service. use PANU."
100
		btpand_flags="${btpand_flags:-}${btpand_service:+ -s PANU}"
101
		;;
102
	esac
103
104
	# PANU client
105
	btpand_flags="${btpand_flags:-}${btpand_remote:+ -a ${btpand_remote}}"
106
}
107
108
btpand_run_rc_command_profile ()
109
{
110
	local -
111
	local command command_args pidfile rcvar
112
	local _rc_restart_done
113
	local btpand_flags
114
	local btpand_tapif btpand_device btpand_service
115
	local profile _return
116
117
	profile="$1"
118
	shift 1
119
120
	eval "rcvar=\"btpand_${profile}_enable\""
121
	eval "btpand_flags=\"\${btpand_${profile}_flags:-${btpand_flags}}\""
122
	eval "btpand_tapif=\"\${btpand_${profile}_tapif:-${btpand_tapif}}\""
123
	eval "btpand_device=\"\${btpand_${profile}_device:-${btpand_device}}\""
124
	eval "btpand_service=\"\${btpand_${profile}_service:-${btpand_service}}\""
125
	eval "btpand_remote=\"\${btpand_${profile}_remote:-${btpand_remote}}\""
126
	eval "pidfile=\"/var/run/${btpand_tapif}.pid\""
127
	eval "_rc_restart_done=\"\${_rc_restart_done_btpand_${profile}:-false}\""
128
129
	if ! btpand_setup_flags ; then
130
		return 1
131
	fi
132
133
	run_rc_command ${1+"$@"}
134
	_return="${?}"
135
136
	eval "_rc_restart_done_btpand_${profile}=\"\${_rc_restart_done:-false}\""
137
138
	return "${_return}"
139
}
140
141
if [ -n "${btpand_profiles}" ] ; then
142
	btpand_rc_arg="$1"
143
	if [ ${#} -gt 0 ] ; then
144
		shift 1
145
	fi
146
147
	btpand_profiles="$(echo ${btpand_profiles})"
148
	btpand_run_profiles=""
149
	if [ -n "$*" ] ; then
150
		for profile
151
		do
152
			case " ${btpand_profiles} " in	# (
153
			" ${profile} ")
154
				btpand_run_profiles="${btpand_run_profiles:+${btpand_run_profiles} }${profile}"
155
				;;
156
			esac
157
		done
158
	else
159
		btpand_run_profiles="${btpand_profiles}"
160
	fi
161
162
	for profile in ${btpand_run_profiles}
163
	do
164
		echo "===> btpand profile: ${profile}"
165
		btpand_run_rc_command_profile "${profile}" "${btpand_rc_arg}"
166
	done
167
else
168
	if ! btpand_setup_flags ; then
169
		return 1
170
	fi
171
172
	run_rc_command ${1+"$@"}
173
fi

Return to bug 248584