aboutsummaryrefslogtreecommitdiff
path: root/system/bluez-utils/rc.bluetooth.new
blob: f303055e79e2ec9361366d4afe6857c95b28b812 (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
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
#!/bin/sh
#
# Start/stop the Bluetooth daemons
#

set -e

PATH=/sbin:/bin:/usr/sbin:/usr/bin
NAME=rc.bluetooth
DESC="Bluetooth subsystem"

HCID_NAME=hcid
SDPD_NAME=sdpd
HIDD_NAME=hidd
HID2HCI_NAME=hid2hci
RFCOMM_NAME=rfcomm
PAND_NAME=pand
DUND_NAME=dund

HCID_EXEC="`which $HCID_NAME || true`"
SDPD_EXEC="`which $SDPD_NAME || true`"
HIDD_EXEC="`which $HIDD_NAME || true`"
HID2HCI_EXEC="`which $HID2HCI_NAME || true`"
RFCOMM_EXEC="`which $RFCOMM_NAME || true`"
PAND_EXEC="`which $PAND_NAME || true`"
DUND_EXEC="`which $DUND_NAME || true`"

HCID_ENABLE=true
SDPD_ENABLE=false
HIDD_ENABLE=false
HID2HCI_ENABLE=false
RFCOMM_ENABLE=false
DUND_ENABLE=false
PAND_ENABLE=false

HCID_CONFIG="/etc/bluetooth/hcid.conf"
RFCOMM_CONFIG="/etc/bluetooth/rfcomm.conf"

HIDD_OPTIONS=""
DUND_OPTIONS=""
PAND_OPTIONS=""

start() {
    echo -n "Starting $DESC:"
    if $HCID_ENABLE && [ -x "$HCID_EXEC" ] && [ -f "$HCID_CONFIG" ] ; then
	if $SDPD_ENABLE ; then
	    $HCID_EXEC -f $HCID_CONFIG
	else
	    $HCID_EXEC -s -f $HCID_CONFIG
	fi
	echo -n " $HCID_NAME"
    fi
    if $SDPD_ENABLE && [ -x "$SDPD_EXEC" ] ; then
	$SDPD_EXEC
	echo -n " $SDPD_NAME"
    fi
    if $HIDD_ENABLE && [ -x "$HIDD_EXEC" ] ; then
	$HIDD_EXEC $HIDD_OPTIONS --server || true
	echo -n " $HIDD_NAME"
    fi
    if $HID2HCI_ENABLE && [ -x "$HID2HCI_EXEC" ] ; then
	$HID2HCI_EXEC --tohci > /dev/null 2>&1 || true
	echo -n " $HID2HCI_NAME"
    fi
    if $RFCOMM_ENABLE && [ -x "$RFCOMM_EXEC" ] && [ -f "$RFCOMM_CONFIG" ] ; then
	$RFCOMM_EXEC -f $RFCOMM_CONFIG bind all || true
	echo -n " $RFCOMM_NAME"
    fi
    if $DUND_ENABLE && [ -x "$DUND_EXEC" ] && [ -n "$DUND_OPTIONS" ] ; then
	$DUND_EXEC $DUND_OPTIONS
	echo -n " $DUND_NAME"
    fi
    if $PAND_ENABLE && [ -x "$PAND_EXEC" ] && [ -n "$PAND_OPTIONS" ] ; then
	$PAND_EXEC $PAND_OPTIONS
	echo -n " $PAND_NAME"
    fi
    echo "."
}

stop() {
    echo -n "Stopping $DESC:"
    killall $PAND_NAME > /dev/null 2>&1 || true
    echo -n " $PAND_NAME"
    killall $DUND_NAME > /dev/null 2>&1 || true
    echo -n " $DUND_NAME"
    if [ -x "$RFCOMM_EXEC" ] ; then
	$RFCOMM_EXEC release all > /dev/null 2>&1 || true
	echo -n " $RFCOMM_NAME"
    fi
    killall $HIDD_NAME > /dev/null 2>&1 || true
    echo -n " $HIDD_NAME"
    killall $SDPD_NAME > /dev/null 2>&1 || true
    echo -n " $SDPD_NAME"
    killall $HCID_NAME > /dev/null 2>&1 || true
    echo -n " $HCID_NAME"
    echo "."
}

case "$1" in
    start)
	start
	;;
    stop)
	stop
	;;
    restart)
	stop
	start
	;;
    *)
	echo "Usage: $0 {start|stop|restart}" >&2
	exit 1
	;;
esac