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
11 . /etc/grml/script-functions
15 HCID_CONF='/etc/bluetooth/bt_headset.conf'
16 [ -n "$PIN" ] || PIN='0000'
20 einfo "Starting bluetooth support."
23 if ! [ -r "$HCID_CONF" ] ; then
24 ewarn "$HCID_CONF does not exist. Setting it up."
25 cat > $HCID_CONF <<EOF
26 # Bluetooth headset configuration file created by bt-audio.
30 # Automatically initialize new devices
33 # Security Manager mode
34 # none - Security manager disabled
35 # auto - Use local PIN for incoming connections
36 # user - Always ask user for a PIN
41 # none - Pairing disabled
42 # multi - Allow pairing with already paired devices
43 # once - Pair once and deny successive attempts
46 # Default PIN code for incoming connections
50 # Default settings for HCI devices
61 #pkt_type DH1,DM1,HV1;
63 # Inquiry and Page scan
64 iscan enable; pscan enable;
67 # none - no specific policy
68 # accept - always accept incoming connections
69 # master - become master on incoming connections,
70 # deny role switch on outgoing connections
74 # none - no specific policy
75 # rswitch - allow role switch
76 # hold - allow hold mode
77 # sniff - allow sniff mode
78 # park - allow park mode
79 lp rswitch,hold,sniff,park;
84 if pgrep dbus-daemon 1>/dev/null; then
85 einfo "dbus already running." ; eend 0
87 einfo "Starting dbus."
88 /etc/init.d/dbus start 1>/dev/null ; eend $?
91 if pgrep hcid 1>/dev/null; then
92 einfo "hicd already running." ; eend 0
94 einfo "Starting hcid."
96 if /usr/sbin/hcid -f $HCID_CONF 1>$HCIINFO 2>&1 ; then
100 eerror "hcid could not be started: `cat $HCIINFO`. Exiting."
107 einfo "Loading bluetooth modules:"
108 for module in bluetooth ohci1394 hci_usb snd-bt-sco ; do
110 einfo "$module" ; modprobe $module ; eend $?
114 einfo "Scanning for bluetooth audio device. Press the 'connect' button on the device!"
115 einfo "Scanning might take a while. Searching..."
119 if hcitool scan 1>${SUCCESS} 2>${ERROR} ; then
120 if ! grep -q ':' $SUCCESS ; then
121 eerror "Could not find any devices. Exiting." ; eend 1
124 ID=$(grep '[[:alnum:]][[:alnum:]]:' $SUCCESS | awk '{print $1}')
125 if [ -n "$ID" ] ; then
126 einfo "Success: connected device ${ID}." ; eend 0
127 logger -t "bluez-connect" "connected human input device ${ID}"
128 btsco -v $ID 1>/dev/null &
131 ewarn "Warning: searching for device succeded but no connection could be established."
135 eerror "Error: `cat $ERROR`" ; eend 1
138 rm -f $SUCCESS $ERROR
141 HCIDAEMON=$(pgrep hcid)
142 if [ -n "$HCIDAEMON" ] ; then
143 einfo "Stopping hcid."
145 eend $? # workaround because start-stop-daemon does not work :-/
147 einfo "No running hcid found, nothing to stop."
151 ewarn "Will not stop dbus as it might be used by other services." ; eend 0
153 einfo "Disconnecting all human input devices."
154 logger -t "bluez-connect" "disconnected all human input devices"
155 hidd --killall ; eend $?
157 restart|force-reload)
163 if [ -r /usr/share/centericq/sms.wav ] ; then
164 einfo "Trying to play /usr/share/centericq/sms.wav on headset:"
166 aplay -B 1000000 -D plughw:Headset /usr/share/centericq/sms.wav 1>/dev/null ; eend $?
168 eerror "/usr/share/centericq/sms.wav does not exist. Can not test sound." ; eend 1
172 einfo "$0 - checking status:"
174 if pgrep hcid 1>/dev/null ; then
175 einfo "hcid running." ; eend 0
176 if [ -d /proc/asound/Headset ] ; then
177 einfo "cat /proc/asound/Headset/*/info:"
178 cat /proc/asound/Headset/*/info ; eend $?
180 eerror "Directory /proc/asound/Headset does not exist." ; eend 1
183 eerror "hcid not running." ; eend 1
188 echo "Usage: $0 {start|stop|status|restart|force-reload|test}"
197 ## END OF FILE #################################################################