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: Son Aug 06 20:30:34 CEST 2006 [mika]
8 ################################################################################
10 . /etc/grml/lsb-functions
12 if [ $UID != 0 ] ; then
13 eerror "Need root privileges. Please run $0 as user root." ; eend 1
17 HCID_CONF='/etc/bluetooth/bt_headset.conf'
18 [ -n "$PIN" ] || PIN='0000'
22 einfo "Starting bluetooth support."
25 if ! [ -r $HCID_CONF ] ; then
26 ewarn "$HCID_CONF does not exist. Setting it up."
27 cat > $HCID_CONF <<EOF
28 # Bluetooth headset configuration file created by bt-audio.
32 # Automatically initialize new devices
35 # Security Manager mode
36 # none - Security manager disabled
37 # auto - Use local PIN for incoming connections
38 # user - Always ask user for a PIN
43 # none - Pairing disabled
44 # multi - Allow pairing with already paired devices
45 # once - Pair once and deny successive attempts
48 # Default PIN code for incoming connections
52 # Default settings for HCI devices
63 #pkt_type DH1,DM1,HV1;
65 # Inquiry and Page scan
66 iscan enable; pscan enable;
69 # none - no specific policy
70 # accept - always accept incoming connections
71 # master - become master on incoming connections,
72 # deny role switch on outgoing connections
76 # none - no specific policy
77 # rswitch - allow role switch
78 # hold - allow hold mode
79 # sniff - allow sniff mode
80 # park - allow park mode
81 lp rswitch,hold,sniff,park;
86 if pgrep dbus-daemon 1>/dev/null; then
87 einfo "dbus already running." ; eend 0
89 einfo "Starting dbus."
90 /etc/init.d/dbus start 1>/dev/null ; eend $?
93 if pgrep hcid 1>/dev/null; then
94 einfo "hicd already running." ; eend 0
96 einfo "Starting hcid."
98 if /usr/sbin/hcid -f $HCID_CONF 1>$HCIINFO 2>&1 ; then
102 eerror "hcid could not be started: `cat $HCIINFO`. Exiting."
109 einfo "Loading bluetooth modules:"
110 for module in bluetooth ohci1394 hci_usb snd-bt-sco ; do
112 einfo "$module" ; modprobe $module ; eend $?
116 einfo "Scanning for bluetooth audio device. Press the 'connect' button on the device!"
117 einfo "Scanning might take a while. Searching..."
121 if hcitool scan 1>${SUCCESS} 2>${ERROR} ; then
122 if ! grep -q ':' $SUCCESS ; then
123 eerror "Could not find any devices. Exiting." ; eend 1
126 ID=$(grep '[[:alnum:]][[:alnum:]]:' $SUCCESS | awk '{print $1}')
127 if [ -n "$ID" ] ; then
128 einfo "Success: connected device ${ID}." ; eend 0
129 logger -t "bluez-connect" "connected human input device ${ID}"
130 btsco -v $ID 1>/dev/null &
133 ewarn "Warning: searching for device succeded but no connection could be established."
137 eerror "Error: `cat $ERROR`" ; eend 1
140 rm -f $SUCCESS $ERROR
143 einfo "Stopping hcid."
144 killall hcid ; eend $? # workaround because start-stop-daemon does not work :-/
145 ewarn "Will not stop dbus as it might be used by other services." ; eend 0
146 einfo "Disconnecting all human input devices."
147 logger -t "bluez-connect" "disconnected all human input devices"
148 hidd --killall ; eend $?
150 restart|force-reload)
156 if [ -r /usr/share/centericq/sms.wav ] ; then
157 einfo "Trying to play /usr/share/centericq/sms.wav on headset:"
159 aplay -B 1000000 -D plughw:Headset /usr/share/centericq/sms.wav 1>/dev/null ; eend $?
161 eerror "/usr/share/centericq/sms.wav does not exist. Can not test sound." ; eend 1
165 einfo "$0 - checking status:"
167 if pgrep hcid 1>/dev/null ; then
168 einfo "hcid running." ; eend 0
169 if [ -d /proc/asound/Headset ] ; then
170 einfo "cat /proc/asound/Headset/*/info:"
171 cat /proc/asound/Headset/*/info ; eend $?
173 eerror "Directory /proc/asound/Headset does not exist." ; eend 1
176 eerror "hcid not running." ; eend 1
181 echo "Usage: $0 {start|stop|status|restart|force-reload|test}"
190 ## END OF FILE #################################################################