3 # Purpose: connect bluetooth audio device (e.g. headset) to local system
4 # Authors: grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
5 # Bug-Reports: see http://grml.org/bugs/
6 # License: This file is licensed under the GPL v2.
7 ################################################################################
9 . /etc/grml/lsb-functions
10 . /etc/grml/script-functions
14 if ! modprobe -l | grep snd-bt-sco ; then
15 eerror "Sorry, could not find kernel module snd-bt-sco. Exiting." ; eend 1
16 ewarn "The kernel version you are using either does not support the snd-bt-sco module..."
17 ewarn "... yet or you should take a look at Debian package bluez-audio."
21 HCID_CONF='/etc/bluetooth/bt_headset.conf'
22 [ -n "$PIN" ] || PIN='0000'
26 einfo "Starting bluetooth support."
29 if ! [ -r "$HCID_CONF" ] ; then
30 ewarn "$HCID_CONF does not exist. Setting it up."
31 cat > $HCID_CONF <<EOF
32 # Bluetooth headset configuration file created by bt-audio.
36 # Automatically initialize new devices
39 # Security Manager mode
40 # none - Security manager disabled
41 # auto - Use local PIN for incoming connections
42 # user - Always ask user for a PIN
47 # none - Pairing disabled
48 # multi - Allow pairing with already paired devices
49 # once - Pair once and deny successive attempts
52 # Default PIN code for incoming connections
56 # Default settings for HCI devices
67 #pkt_type DH1,DM1,HV1;
69 # Inquiry and Page scan
70 iscan enable; pscan enable;
73 # none - no specific policy
74 # accept - always accept incoming connections
75 # master - become master on incoming connections,
76 # deny role switch on outgoing connections
80 # none - no specific policy
81 # rswitch - allow role switch
82 # hold - allow hold mode
83 # sniff - allow sniff mode
84 # park - allow park mode
85 lp rswitch,hold,sniff,park;
90 if pgrep dbus-daemon 1>/dev/null; then
91 einfo "dbus already running." ; eend 0
93 einfo "Starting dbus."
94 /etc/init.d/dbus start 1>/dev/null ; eend $?
97 if pgrep hcid 1>/dev/null; then
98 einfo "hicd already running." ; eend 0
100 einfo "Starting hcid."
102 if /usr/sbin/hcid -f $HCID_CONF 1>$HCIINFO 2>&1 ; then
106 eerror "hcid could not be started: `cat $HCIINFO`. Exiting."
113 einfo "Loading bluetooth modules:"
114 for module in bluetooth ohci1394 hci_usb snd-bt-sco ; do
116 einfo "$module" ; modprobe $module ; eend $?
120 einfo "Scanning for bluetooth audio device. Press the 'connect' button on the device!"
121 einfo "Scanning might take a while. Searching..."
125 if hcitool scan 1>${SUCCESS} 2>${ERROR} ; then
126 if ! grep -q ':' $SUCCESS ; then
127 eerror "Could not find any devices. Exiting." ; eend 1
130 ID=$(grep '[[:alnum:]][[:alnum:]]:' $SUCCESS | awk '{print $1}')
131 if [ -n "$ID" ] ; then
132 einfo "Success: connected device ${ID}." ; eend 0
133 logger -t "bluez-connect" "connected human input device ${ID}"
134 btsco -v $ID 1>/dev/null &
137 ewarn "Warning: searching for device succeded but no connection could be established."
141 eerror "Error: `cat $ERROR`" ; eend 1
144 rm -f $SUCCESS $ERROR
147 HCIDAEMON=$(pgrep hcid)
148 if [ -n "$HCIDAEMON" ] ; then
149 einfo "Stopping hcid."
151 eend $? # workaround because start-stop-daemon does not work :-/
153 einfo "No running hcid found, nothing to stop."
157 ewarn "Will not stop dbus as it might be used by other services." ; eend 0
159 einfo "Disconnecting all human input devices."
160 logger -t "bluez-connect" "disconnected all human input devices"
161 hidd --killall ; eend $?
163 restart|force-reload)
169 if [ -r /usr/share/centericq/sms.wav ] ; then
170 einfo "Trying to play /usr/share/centericq/sms.wav on headset:"
172 aplay -B 1000000 -D plughw:Headset /usr/share/centericq/sms.wav 1>/dev/null ; eend $?
174 eerror "/usr/share/centericq/sms.wav does not exist. Can not test sound." ; eend 1
178 einfo "$0 - checking status:"
180 if pgrep hcid 1>/dev/null ; then
181 einfo "hcid running." ; eend 0
182 if [ -d /proc/asound/Headset ] ; then
183 einfo "cat /proc/asound/Headset/*/info:"
184 cat /proc/asound/Headset/*/info ; eend $?
186 eerror "Directory /proc/asound/Headset does not exist." ; eend 1
189 eerror "hcid not running." ; eend 1
194 echo "Usage: $0 {start|stop|status|restart|force-reload|test}"
203 ## END OF FILE #################################################################