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 # Latest change: Mon Jän 14 20:36:21 CET 2008 [mika]
8 ################################################################################
10 . /etc/grml/lsb-functions
11 . /etc/grml/script-functions
15 if ! modprobe -l | grep snd-bt-sco ; then
16 eerror "Sorry, could not find kernel module snd-bt-sco. Exiting." ; eend 1
17 ewarn "The kernel version you are using either does not support the snd-bt-sco module..."
18 ewarn "... yet or you should take a look at Debian package bluez-audio."
22 HCID_CONF='/etc/bluetooth/bt_headset.conf'
23 [ -n "$PIN" ] || PIN='0000'
27 einfo "Starting bluetooth support."
30 if ! [ -r "$HCID_CONF" ] ; then
31 ewarn "$HCID_CONF does not exist. Setting it up."
32 cat > $HCID_CONF <<EOF
33 # Bluetooth headset configuration file created by bt-audio.
37 # Automatically initialize new devices
40 # Security Manager mode
41 # none - Security manager disabled
42 # auto - Use local PIN for incoming connections
43 # user - Always ask user for a PIN
48 # none - Pairing disabled
49 # multi - Allow pairing with already paired devices
50 # once - Pair once and deny successive attempts
53 # Default PIN code for incoming connections
57 # Default settings for HCI devices
68 #pkt_type DH1,DM1,HV1;
70 # Inquiry and Page scan
71 iscan enable; pscan enable;
74 # none - no specific policy
75 # accept - always accept incoming connections
76 # master - become master on incoming connections,
77 # deny role switch on outgoing connections
81 # none - no specific policy
82 # rswitch - allow role switch
83 # hold - allow hold mode
84 # sniff - allow sniff mode
85 # park - allow park mode
86 lp rswitch,hold,sniff,park;
91 if pgrep dbus-daemon 1>/dev/null; then
92 einfo "dbus already running." ; eend 0
94 einfo "Starting dbus."
95 /etc/init.d/dbus start 1>/dev/null ; eend $?
98 if pgrep hcid 1>/dev/null; then
99 einfo "hicd already running." ; eend 0
101 einfo "Starting hcid."
103 if /usr/sbin/hcid -f $HCID_CONF 1>$HCIINFO 2>&1 ; then
107 eerror "hcid could not be started: `cat $HCIINFO`. Exiting."
114 einfo "Loading bluetooth modules:"
115 for module in bluetooth ohci1394 hci_usb snd-bt-sco ; do
117 einfo "$module" ; modprobe $module ; eend $?
121 einfo "Scanning for bluetooth audio device. Press the 'connect' button on the device!"
122 einfo "Scanning might take a while. Searching..."
126 if hcitool scan 1>${SUCCESS} 2>${ERROR} ; then
127 if ! grep -q ':' $SUCCESS ; then
128 eerror "Could not find any devices. Exiting." ; eend 1
131 ID=$(grep '[[:alnum:]][[:alnum:]]:' $SUCCESS | awk '{print $1}')
132 if [ -n "$ID" ] ; then
133 einfo "Success: connected device ${ID}." ; eend 0
134 logger -t "bluez-connect" "connected human input device ${ID}"
135 btsco -v $ID 1>/dev/null &
138 ewarn "Warning: searching for device succeded but no connection could be established."
142 eerror "Error: `cat $ERROR`" ; eend 1
145 rm -f $SUCCESS $ERROR
148 HCIDAEMON=$(pgrep hcid)
149 if [ -n "$HCIDAEMON" ] ; then
150 einfo "Stopping hcid."
152 eend $? # workaround because start-stop-daemon does not work :-/
154 einfo "No running hcid found, nothing to stop."
158 ewarn "Will not stop dbus as it might be used by other services." ; eend 0
160 einfo "Disconnecting all human input devices."
161 logger -t "bluez-connect" "disconnected all human input devices"
162 hidd --killall ; eend $?
164 restart|force-reload)
170 if [ -r /usr/share/centericq/sms.wav ] ; then
171 einfo "Trying to play /usr/share/centericq/sms.wav on headset:"
173 aplay -B 1000000 -D plughw:Headset /usr/share/centericq/sms.wav 1>/dev/null ; eend $?
175 eerror "/usr/share/centericq/sms.wav does not exist. Can not test sound." ; eend 1
179 einfo "$0 - checking status:"
181 if pgrep hcid 1>/dev/null ; then
182 einfo "hcid running." ; eend 0
183 if [ -d /proc/asound/Headset ] ; then
184 einfo "cat /proc/asound/Headset/*/info:"
185 cat /proc/asound/Headset/*/info ; eend $?
187 eerror "Directory /proc/asound/Headset does not exist." ; eend 1
190 eerror "hcid not running." ; eend 1
195 echo "Usage: $0 {start|stop|status|restart|force-reload|test}"
204 ## END OF FILE #################################################################