This script currently allows scanning for nearby devices, adds one to /etc/bluetooth/hosts, adds an entry to hcsecd's conf and if it is a HID, add an entry to bthidd's configs, as well.
Details
Diff Detail
- Repository
- rS FreeBSD src repository - subversion
- Lint
Lint Not Applicable - Unit
Tests Not Applicable
Event Timeline
Looks good to me. But I only tested a connection to my mobile phone. Entries in /etc/bluetooth/{hosts,hcsecd.conf} were created successfully.
I'll try with some HID devices later.
With an Apple Trackpad I see this error:
Writing pairing information description block to /etc/bluetooth/hcsecd.conf. (Notice: To get PIN, you might want to put device in pairing mode, first.) Enter PIN [nopin]: 0000 Stopping hcsecd. Waiting for PIDS: 63043. Starting hcsecd. This device provides human interface device services. Do you want to set it up? [yes]: Warning: bthidd is not enabled on your system. This daemon manages bluetooth HID devices. Enable bthidd? [yes]: bthidd_enable: NO -> YES Could not open config file '/etc/bluetooth/bthidd.conf'. No such file or directory (2) Writing HID descriptor block to /etc/bluetooth/bthidd.conf ... failed.
After touching the file manually I see this:
Select which device you want to pair with [1-2, 0 to rescan]: 1 Warning: An entry for device 84:fc:fe:dd:98:8c is already present in /etc/bluetooth/hcsecd.conf. If you want to modifiy pairing information, edit this file and run the command service hcsecd restart Continue? [yes]: This device provides human interface device services. Do you want to set it up? [yes]: Writing HID descriptor block to /etc/bluetooth/bthidd.conf ... Ignoring duplicated entry for bdaddr 84:fc:fe:dd:98:8c failed.
So, it was added to bthidd.conf, but bthidd was not started:
# service bthidd status bthidd is not running.
After manually starting bthidd I can now use the Trackpad.
On to the Apple wireless keyboard. Here bluetooth-config states, that bthidd already knows about the keyboard which is not the case:
Do you want to set it up? [yes]: + /usr/sbin/service bthidd enabled + /usr/sbin/bthidcontrol -a 28:37:37:30:db:65 known + bthidd_known='84:fc:fe:dd:98:8c Trackpad' + [ '84:fc:fe:dd:98:8c Trackpad' ] + printf 'Notice: Device %s already known to bthidd.\n' 28:37:37:30:db:65 Notice: Device 28:37:37:30:db:65 already known to bthidd.
Running the command in question manually:
# /usr/sbin/bthidcontrol -a 28:37:37:30:db:65 known 84:fc:fe:dd:98:8c Trackpad
So bthidcontrol is asked about the address of the keyboard and returns the address and name of the trackpad.
This patch makes it work:
--- ./bluetooth-config 2015-10-03 13:20:23.833301000 +0200 +++ ./bluetooth-config.orig 2015-10-03 13:15:22.591997000 +0200 @@ -211,7 +211,7 @@ fi # Check if bthidd already knows about this device - bthidd_known=$( /usr/sbin/bthidcontrol -a "${bdaddress}" known | grep "${bdaddress}" ) + bthidd_known=$( /usr/sbin/bthidcontrol -a "${bdaddress}" known ) if [ "${bthidd_known}" ]; then printf "Notice: Device %s already known to bthidd.\n" "${bdaddress}" else @@ -220,7 +220,7 @@ /usr/sbin/bthidcontrol -a "${bdaddress}" query >> "${bthidd_config}" # Re-read config to see if we succeeded adding the device - bthidd_known=$( /usr/sbin/bthidcontrol -a "${bdaddress}" known | grep "${bdaddress}" ) + bthidd_known=$( /usr/sbin/bthidcontrol -a "${bdaddress}" known ) if ! [ "${bthidd_known}" ]; then printf "failed.\n" else
For https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=203745 (A2DP support) I successfully used the bluetooth-config script to pair with a BT speaker.
Suggestions for improvements:
- script must be run as root (or equivalent), exit with message to that effect if run as normal user
- check /etc/rc.conf (or use sysrc?) to test whether sdpd_enable, hcsecd_enable, and bthidd_enable are set
- script seems to always give "Writing HID descriptor block to /etc/bluetooth/bthidd.conf ... failed." if there is anything in that file, or even if it exists as an empty file. the code that adds an entry to bthidd.conf should also check whether one already exists for the "new" device.
- if only one new device is discovered, the script shows a range of "1-1", confusing for the user.
swills@ suggested that hccontrol -n ubt0hci create_connection device_friendly_name must also be run at some point, and this worked for me with a Logitech BT mouse. (In the past, I have had BT devices work, but only until a reboot of the machine, then they never work again.)
It's also not clear how to reconnect after the mouse has been turned off. I'm not sure whether these are messages that this script could display on exit or possibly as part of the help output. Definitely in a man page, though.
Added a man page, added the (required) scan command (for later extensibility), do syntax checks before super user checks, simplify interface if there's only one device found.