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 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
|
#! /bin/sh
#
# bluez-utils Bluetooth subsystem starting and stopping
#
# Edd Dumbill <ejad@debian.org>
#
# startup control over dund and pand can be changed by
# editing /etc/default/bluez-utils
PATH=/sbin:/bin:/usr/sbin:/usr/bin
DESC=bluez-utils
HCID=/usr/sbin/hcid
HCIATTACH=/usr/sbin/hciattach
HCID_NAME=hcid
HID2HCI=/usr/sbin/hid2hci
UART_CONF=/etc/bluetooth/uart
RFCOMM=/usr/bin/rfcomm
RFCOMM_NAME=rfcomm
RFCOMM_CONF=/etc/bluetooth/rfcomm.conf
SDPD=/usr/sbin/sdpd
SDPD_NAME=sdpd
DUND_DAEMON=/usr/bin/dund
DUND_NAME=dund
PAND_DAEMON=/usr/bin/pand
PAND_NAME=pand
HIDD_DAEMON=/usr/bin/hidd
HIDD_NAME=hidd
DUND_ENABLED=0
PAND_ENABLED=0
HIDD_ENABLED=0
DUND_OPTIONS=""
PAND_OPTIONS=""
HIDD_OPTIONS="--master --server"
test -f /etc/default/bluez-utils && . /etc/default/bluez-utils
# test for essential daemons
test -x $HCID || exit 0
test -x $HCIATTACH || exit 0
test -x $RFCOMM || exit 0
test -x $SDPD || exit 0
# disable nonessential daemons if not present
if test "$DUND_ENABLED" != "0"; then
if ! test -f $DUND_DAEMON; then
DUND_ENABLED=0
fi
fi
if test "$PAND_ENABLED" != "0"; then
if ! test -f $PAND_DAEMON; then
PAND_ENABLED=0
fi
fi
if test "$HIDD_ENABLED" != "0"; then
if ! test -f $HIDD_DAEMON; then
HIDD_ENABLED=0
fi
fi
set -e
enable_hci_input()
{
#echo "Switching on Bluetooth input devices."
$HID2HCI --tohci > /dev/null 2>&1
}
disable_hci_input()
{
#echo "Switching Bluetooth input devices back to HCI mode."
$HID2HCI --tohid > /dev/null 2>&1
}
start_pan()
{
if test "$DUND_ENABLED" != "0"; then
start-stop-daemon --start --quiet --exec $DUND_DAEMON -- $DUND_OPTIONS
echo -n " $DUND_NAME"
fi
if test "$PAND_ENABLED" != "0"; then
start-stop-daemon --start --quiet --exec $PAND_DAEMON -- $PAND_OPTIONS
echo -n " $PAND_NAME"
fi
}
stop_pan()
{
if test "$DUND_ENABLED" != "0"; then
start-stop-daemon --stop --quiet --exec $DUND_DAEMON || true
echo -n " $DUND_NAME"
fi
if test "$PAND_ENABLED" != "0"; then
start-stop-daemon --stop --quiet --exec $PAND_DAEMON || true
echo -n " $PAND_NAME"
fi
}
start_hid()
{
if test "$HIDD_ENABLED" != "0"; then
start-stop-daemon --start --quiet --exec $HIDD_DAEMON -- $HIDD_OPTIONS
echo -n " $HIDD_NAME"
fi
}
stop_hid()
{
if test "$HIDD_ENABLED" != "0"; then
$HIDD_DAEMON --killall
start-stop-daemon --stop --quiet --exec $HIDD_DAEMON || true
echo -n " $HIDD_NAME"
fi
}
start_uarts()
{
[ -f $HCIATTACH ] && [ -f $UART_CONF ] || return
grep -v '^#' $UART_CONF | while read i; do
$HCIATTACH $i
done
}
stop_uarts()
{
killall hciattach > /dev/null 2>&1 || true
}
start_rfcomm()
{
if [ -x $RFCOMM ] && [ -f $RFCOMM_CONF ] ; then
# rfcomm must always succeed for now: users
# may not yet have an rfcomm-enabled kernel
$RFCOMM -f $RFCOMM_CONF bind all || true
echo -n " $RFCOMM_NAME"
fi
}
stop_rfcomm()
{
if [ -x $RFCOMM ] ; then
echo -n " $RFCOMM_NAME"
$RFCOMM unbind all || true
fi
}
restart_rfcomm()
{
if [ -x $RFCOMM ] && [ -f $RFCOMM_CONF ] ; then
$RFCOMM unbind all || true
$RFCOMM -f $RFCOMM_CONF bind all || true
echo -n " $RFCOMM_NAME"
fi
}
case "$1" in
start)
echo -n "Starting $DESC:"
start-stop-daemon --start --quiet --exec $HCID || true
echo -n " $HCID_NAME"
start_uarts || true
start-stop-daemon --start --quiet --exec $SDPD || true
echo -n " $SDPD_NAME"
start_hid || true
enable_hci_input || true
start_rfcomm || true
start_pan || true
echo "."
;;
stop)
echo -n "Stopping $DESC:"
stop_pan || true
stop_rfcomm || true
disable_hci_input || true
stop_hid || true
start-stop-daemon --stop --quiet --exec $SDPD || true
echo -n " $SDPD_NAME"
start-stop-daemon --stop --quiet --exec $HCID || true
echo -n " $HCID_NAME"
stop_uarts || true
echo "."
;;
restart|force-reload)
echo -n "Restarting $DESC:"
stop_hid || true
stop_pan || true
start-stop-daemon --stop --quiet --exec $SDPD || true
start-stop-daemon --stop --quiet --exec $HCID || true
sleep 1
start-stop-daemon --start --quiet --exec $HCID || true
start-stop-daemon --start --quiet --exec $SDPD || true
echo -n " $HCID_NAME"
echo -n " $SDPD_NAME"
start_pan || true
start_hid || true
restart_rfcomm
echo "."
;;
*)
N=/etc/init.d/bluez-utils
# echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
echo "Usage: $N {start|stop|restart|force-reload}" >&2
exit 1
;;
esac
exit 0
|