summaryrefslogtreecommitdiffstats
path: root/scripts/bluetooth.rc.deb
blob: 4c216c31aef2e78851e2d1d9acb30245ca108b92 (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
#! /bin/sh
#
# bluetooth	Bluetooth subsystem starting and stopping
#

NAME=bluetooth
DESC="Bluetooth subsystem"
PATH=/sbin:/bin:/usr/sbin:/usr/bin
HCID=/usr/sbin/hcid
HCID_CONF=/etc/bluetooth/hcid.conf
HCIATTACH=/usr/sbin/hciattach
UART_CONF=/etc/bluetooth/uart
SDPD=/usr/sbin/sdpd
RFCOMM=/usr/bin/rfcomm
RFCOMM_CONF=/etc/bluetooth/rfcomm.conf

set -e

start_uarts() 
{
	[ -x $HCIATTACH -a -f $UART_CONF ] || return
	grep -v '^#' $UART_CONF | while read i; do
		$HCIATTACH $i
	done
}

stop_uarts()
{
	killall $HCIATTACH > /dev/null 2>&1 || true
}

case "$1" in
  start)
	echo -n "Starting $DESC:"
	if [ -x $HCID -a -f $HCID_CONF ] ; then
		$HCID -f $HCID_CONF
		echo -n " hcid"
	fi
	if [ -x $SDPD ] ; then
		$SDPD
		echo -n " sdpd"
	fi
	if [ -x $RFCOMM -a -f $RFCOMM_CONF ] ; then
		$RFCOMM -f $RFCOMM_CONF bind all
		echo -n " rfcomm"
	fi
	echo "."
	start_uarts || true
	;;
  stop)
	echo -n "Stopping $DESC:"
	if [ -x $RFCOMM ] ; then
		echo -n " rfcomm"
		$RFCOMM release all
	fi
	echo -n " sdpd"
	killall $SDPD > /dev/null 2>&1 || true
	echo -n " hcid"
	killall $HCID > /dev/null 2>&1 || true
	echo "."
	stop_uarts
	;;
  restart|force-reload)
	echo -n "Restarting $DESC:"
	echo -n " hcid"
	killall $HCID > /dev/null 2>&1 || true
	sleep 1
	if [ -x $HCID -a -f $HCID_CONF ] ; then
		$HCID -f $HCID_CONF
	fi
	echo -n " sdpd"
	killall $SDPD > /dev/null 2>&1 || true
	sleep 1
	if [ -x $SDPD ] ; then
		$SDPD
	fi
	echo "."
	;;
  *)
	N=/etc/init.d/bluetooth
	echo "Usage: $N {start|stop|restart|force-reload}" >&2
	exit 1
	;;
esac

exit 0