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
123
124
125
126
127
128
129
130
131
132
133
134
|
#!/bin/sh
#
# $NetBSD: bluetooth,v 1.1 2011/05/27 09:28:42 plunky Exp $
#
# PROVIDE: bluetooth
# REQUIRE: DAEMON
# BEFORE: LOGIN
$_rc_subr_loaded . /etc/rc.subr
name="bluetooth"
rcvar=${name}
start_cmd="bluetooth_start"
stop_cmd="bluetooth_stop"
btattach_cmd="/usr/sbin/btattach"
btconfig_cmd="/usr/sbin/btconfig"
bthcid_cmd="/usr/sbin/bthcid"
btdevctl_cmd="/usr/sbin/btdevctl"
sdpd_cmd="/usr/sbin/sdpd"
btattach_conf="/etc/bluetooth/btattach.conf"
btdevctl_conf="/etc/bluetooth/btdevctl.conf"
required_files="${btattach_conf} ${btdevctl_conf}"
bluetooth_start()
{
#
# attach Bluetooth serial controllers
#
while read type tty speed flags; do
case ${type} in
\#*|"")
continue
;;
esac
echo "attaching Bluetooth controller to $(basename ${tty})"
${btattach_cmd} ${flags} ${type} ${tty} ${speed}
done < ${btattach_conf}
#
# enable Bluetooth controllers.
#
# If ${btconfig_devices} is set, it is treated as a list of devices
# to configure. Otherwise, all available devices will be configured
#
# For each device we are configuring, enable it with maximum security
# settings (not discoverable, not connectable, auth and encryption
# required for all connections), relaxed link policy settings and
# the link master role, set a class of device for Computer, then apply
# any options from the 'btconfig_<dev>' or 'btconfig_args' variables
# on top of settings relaxing the security requirements, so that these
# can be overridden (btconfig parses all command line options before
# acting)
#
echo -n "configuring Bluetooth controllers:"
for dev in ${btconfig_devices:-$(${btconfig_cmd} -l)}; do
echo -n " ${dev}"
eval args=\${btconfig_${dev}:-\${btconfig_args}}
${btconfig_cmd} ${dev} enable -iscan -pscan auth encrypt
${btconfig_cmd} ${dev} switch hold sniff park master
${btconfig_cmd} ${dev} class 0x000100
${btconfig_cmd} ${dev} iscan pscan -auth -encrypt ${args}
done
echo "."
#
# start Bluetooth Link Key/PIN Code manager
#
if checkyesno bthcid; then
echo "starting Bluetooth Link Key/PIN Code manager"
${bthcid_cmd} ${bthcid_flags}
fi
#
# attach local Bluetooth service drivers
#
while read -r service addr dev junk; do
case ${service} in
\#*|"")
continue
;;
esac
if [ -z ${dev} -o ${junk} ]; then
echo "${name}: invalid entry"
return 1
fi
echo "attaching Bluetooth ${service} service from \"${addr}\""
${btdevctl_cmd} -A -a ${addr} -d ${dev} -s ${service}
done < ${btdevctl_conf}
#
# start Bluetooth Service Discovery server
#
if checkyesno sdpd; then
echo "starting Bluetooth Service Discovery server"
${sdpd_cmd} ${sdpd_flags}
fi
}
bluetooth_stop()
{
#
# disable Bluetooth controllers, detaching local service drivers
#
echo -n "disabling Bluetooth controllers:"
for dev in ${btconfig_devices:-$(${btconfig_cmd} -l)}; do
echo -n " ${dev}"
${btconfig_cmd} ${dev} disable
done
echo "."
#
# halt Service Discovery server, Link Key/PIN Code manager,
# and detach Bluetooth serial controllers
#
p1=$(check_pidfile /var/run/bthcid.pid ${bthcid_cmd})
p2=$(check_process ${sdpd_cmd})
p3=$(check_process ${btattach_cmd})
if [ -n "${p1}${p2}${p3}" ]; then
for pid in ${p1} ${p2} ${p3}; do
kill ${sig_stop} ${pid}
done
wait_for_pids ${p1} ${p2} ${p3}
fi
}
load_rc_config ${name}
run_rc_command "$1"
|