Page MenuHomeFreeBSD

user friendly script as a frontend to bluetooth daemons
ClosedPublic

Authored by erdgeist_erdgeist.org on Oct 2 2015, 10:05 AM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Nov 22, 10:39 AM
Unknown Object (File)
Fri, Nov 15, 6:57 PM
Unknown Object (File)
Fri, Nov 15, 1:39 PM
Unknown Object (File)
Fri, Nov 15, 1:54 AM
Unknown Object (File)
Thu, Nov 14, 6:55 AM
Unknown Object (File)
Tue, Nov 12, 11:22 PM
Unknown Object (File)
Tue, Nov 12, 7:25 PM
Unknown Object (File)
Tue, Nov 12, 6:07 PM

Details

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

Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

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 - subversion.

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
emax edited edge metadata.

looks believable

This revision is now accepted and ready to land.Oct 8 2015, 4:56 PM

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 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 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 edited edge metadata.
This revision is now accepted and ready to land.Apr 29 2016, 5:06 PM

This looks nice, what's the status?

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.

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.

This revision now requires review to proceed.Jan 7 2019, 3:57 AM
This revision is now accepted and ready to land.Jan 7 2019, 4:33 PM
This revision was automatically updated to reflect the committed changes.