Pairing Stubborn Bluetooth Devices in Fedora 10 & Ubuntu Ibex
Saturday, November 22nd, 2008If you’re having problems pairing Bluetooth devices with the latest BlueZ 4 GNOME software (bluez-gnome-1.8) try this script. This script offers a work-around for the problem of pairing Bluetooth audio devices like Sony’s SRS-BT100 with the latest BlueZ GNOME wizard. The following script forces the BlueZ 4 audio service to request a pincode from the user for a particular device. In the case of SRS-BT100, the pincode is hardcoded as ‘0000′. So just enter your device’s pincode when prompted by the GNOME Bluetooth applet and then start playing your favorite audio files. Note: this script adds an ALSA virtual device named ‘bt_audio’ to the user’s .asoundrc ALSA configuration file.
For more information on BlueZ, please consult www.bluez.org and wiki.bluez.org.
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 | #!/bin/bash # # Copyright (c) 2008 Technetra Corp # # Permission is hereby granted, free of charge, to any person # obtaining a copy of this software and associated documentation # files (the "Software"), to deal in the Software without # restriction, including without limitation the rights to use, # copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the # Software is furnished to do so, subject to the following # conditions: # # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES # OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR # OTHER DEALINGS IN THE SOFTWARE. # echo "Please place your Bluetooth audio device into pairing mode, then press <Enter>" read echo "Scanning for Bluetooth audio device..." scan=`hcitool scan | sed 's/^\s*//' | grep -v 'Scanning'` line=$scan if [[ "`echo "$scan" | wc -l`" -gt "1" ]]; then echo "select device:" save_ifs=$IFS IFS=" " select line in $scan; do #echo got $line break done IFS=$save_ifs fi BT_BDADDR=`echo $line | awk '{print $1}'` [[ -z "$BT_BDADDR" ]] && echo no bluetooth device found && exit echo "Selected bluetooth device: $BT_BDADDR" # => e.g., 00:11:22:33:44:55 echo "Writing new ~.asoundrc..." cat >> ~/.asoundrc <<EOD pcm.bt_audioraw { type bluetooth device $BT_BDADDR profile "auto" } pcm.bt_audio { type plug slave.pcm "bt_audioraw" hint { show on description "Bluetooth audio device" } } EOD echo "Getting default adapter..." _BT_ADAPTER=`dbus-send --system --print-reply --dest=org.bluez / \ org.bluez.Manager.DefaultAdapter|awk '/object path/ {print $3}'` BT_ADAPTER=${_BT_ADAPTER//\"/} echo "$BT_ADAPTER" echo "Removing any stale Bluetooth audio device:" _OLD_BT_DEVICE=`dbus-send --system --print-reply --dest=org.bluez $BT_ADAPTER \ org.bluez.Adapter.FindDevice string:$BT_BDADDR|awk '/object path/ {print $3}'` OLD_BT_DEVICE=${_OLD_BT_DEVICE//\"/} dbus-send --system --print-reply --dest=org.bluez $BT_ADAPTER \ org.bluez.Adapter.RemoveDevice objpath:$OLD_BT_DEVICE echo "Creating Bluetooth audio device:" _BT_DEVICE=`dbus-send --system --print-reply --dest=org.bluez $BT_ADAPTER \ org.bluez.Adapter.CreateDevice string:$BT_BDADDR|awk '/object path/ {print $3}'` BT_DEVICE=${_BT_DEVICE//\"/} echo "$BT_DEVICE" # optional: echo "Connecting -- BlueZ applet will prompt for pin..." # optional: dbus-send --system --print-reply --dest=org.bluez \ # optional: $BT_DEVICE org.bluez.AudioSink.Connect # # NOTE: if the above dbus-send is NOT executed, then a pairing # request for an A2DP device will be initiated the first time # the ALSA virtual device bt_audio is used. Otherwise, when # "AudioSink.Connect" is executed, a pairing request to the device # will be initiated immediately and then ALSA will subsequently use # this paired connection for playing sound through bt_audio. Executing # "AudioSink.Connect" is useful for preparing devices ahead of time # to avoid undesired delays and to avoid pairing mode timeouts. # # Also note that a device conforming to the headset profile (HSP) # does not support "AudioSink.Connect". However, this script (without # running "AudioSink.Connect") will still work because BlueZ will # request pairing when "Adapter.CreateDevice" is executed for HSP # devices. You can check out your device's specific capabilities # using sdptool. #echo "Test sound sample..." #aplay -D bt_audio your_sound_file.wav |
