user friendly script as a frontend to bluetooth daemons
AcceptedPublic

Authored by erdgeist_erdgeist.org on Oct 2 2015, 10:05 AM.

Details

Reviewers
lme
wblock
emax
Summary

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.

Diff Detail

Repository
rS FreeBSD src repository
Lint
Lint Skipped
Unit
Unit Tests Skipped
erdgeist_erdgeist.org retitled this revision from to user friendly script as a frontend to bluetooth daemons.
erdgeist_erdgeist.org updated this object.
erdgeist_erdgeist.org edited the test plan for this revision. (Show Details)
erdgeist_erdgeist.org added reviewers: emax, lme.
erdgeist_erdgeist.org set the repository for this revision to rS FreeBSD src repository.
lme edited edge metadata.Oct 2 2015, 12:24 PM

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.

lme added a comment.Oct 3 2015, 10:58 AM

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.

lme added a comment.Oct 3 2015, 11:08 AM

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.

lme added a comment.Oct 3 2015, 11:36 AM

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
emax accepted this revision.Oct 8 2015, 4:56 PM
emax edited edge metadata.

looks believable

This revision is now accepted and ready to land.Oct 8 2015, 4:56 PM
lme added a comment.Oct 20 2015, 8:46 AM

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.

erdgeist_erdgeist.org updated this object.
erdgeist_erdgeist.org edited edge metadata.

Incorporate fixes from lme.

This revision now requires review to proceed.Apr 23 2016, 6:48 PM
lme accepted this revision.Apr 24 2016, 12:52 PM
lme edited edge metadata.
This revision is now accepted and ready to land.Apr 24 2016, 12:52 PM
erdgeist_erdgeist.org edited edge metadata.

Spelling fixes by Warren Block.

This revision now requires review to proceed.Apr 24 2016, 7:24 PM
emax accepted this revision.Apr 25 2016, 11:26 PM
emax edited edge metadata.
This revision is now accepted and ready to land.Apr 25 2016, 11:26 PM
erdgeist_erdgeist.org edited edge metadata.

More spelling fixes from Warren Block.

This revision now requires review to proceed.Apr 26 2016, 12:46 AM
emax accepted this revision.Apr 29 2016, 5:06 PM
emax edited edge metadata.
This revision is now accepted and ready to land.Apr 29 2016, 5:06 PM
swills added a subscriber: swills.Aug 30 2017, 10:15 PM

This looks nice, what's the status?

wblock edited edge metadata.Sep 1 2017, 4:23 PM

Suggestions for improvements:

  1. script must be run as root (or equivalent), exit with message to that effect if run as normal user
  2. check /etc/rc.conf (or use sysrc?) to test whether sdpd_enable, hcsecd_enable, and bthidd_enable are set
  3. 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.
  4. 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.

kevans added a subscriber: kevans.Jan 17 2018, 4:47 AM