OpenWrt Forum Archive

Topic: bluetooth pairing problem

The content of this topic has been archived on 2 May 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

I'm trying to get a bluetooth handsfree device working with OpenWRT 8.09.1, running on the brcm2.4 version. I installed bluetooth software (bluez-utils, bluez-libs, kmod-bluetooth; and their dependencies), and am now stuck when trying to pair the bluetooth device and the OpenWRT machine.

After poking around the forums, it seems like the method for exchanging PINs has changed over the years, but I haven't found any mention of how it's done today. Right now there is a small script called "givepin" distributed with the bluez-utils package, but it doesn't actually get installed when the bluez-utils package is installed, and may have been used with the old pin_helper option in hcid.conf (?). And 18 months ago, florian disabled installation of the passkey-agent program that ships with bluez v.3.36, saying that it was useless. (seen here: … /Makefile). I've seen plenty of people setting up PINs and pairing with devices by using GUI programs on desktop versions of linux, but I can't find the command line equivalent for OpenWRT.

What is the proper way to pair with a bluetooth device that has no keypad (and no display) ?

And to cover the basic question, yes I think my hardware is operating correctly, and the drivers are installed ok. The USB dongle works fine on a desktop linux machine, and its address shows up when running the command "hcitool dev" on the OpenWRT machine. And I can see the target device listed in the results of a "hcitool scan"

And I can't use the python agent script suggested by this thread because I don't have any more room to install python.

Thanks for your help!

here is a solution to my question:

the PIN code can indeed be supplied by the bluez-util package's passkey-agent program, running as a daemon. To create a working version of this program, I needed to apply a minor patch to passkey-agent.c to add some brackets around an if-else clause, and I needed to make some changes to the package's Makefile. With those two changes, the passkey-agent can be installed and then run as a daemon with this command to supply a PIN of "0000" to every device that requests a PIN from the default bluetooth adapter:
passkey-agent --default 0000 &

the syslog then shows this sort of message:
Oct 29 09:40:21 <host> hcid[<pid>]: Default passkey agent (:1.1, /org/bluez/passkey_agent_<pid>) registered

if passkey-agent is not patched, the syslog will fill up with messages like this one:
Oct 29 08:58:09 <host> daemon.err hcid[<pid>]: register_passkey_agent called without any adapter info!

I will send a more detailed message to the dev list... in any case, the two patches are copied below.

--- Makefile
+++ Makefile
@@ -41,6 +41,7 @@
    --enable-network \
    --enable-usb \
    --enable-input \
+    --enable-test \
    --disable-audio \
    --with-bluez="$(STAGING_DIR)/usr/include" \
    --with-usb=yes \
@@ -58,9 +59,16 @@

define Package/bluez-utils/install
    $(INSTALL_DIR) $(1)/usr/bin
-    $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/* $(1)/usr/bin/
+    $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/ciptool $(1)/usr/bin/
+    $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/hcitool $(1)/usr/bin/
+    $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/l2ping $(1)/usr/bin/
+    $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/rfcomm $(1)/usr/bin/
+    $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/sdptool $(1)/usr/bin/
    $(INSTALL_DIR) $(1)/usr/sbin
-    $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/* $(1)/usr/sbin/
+    $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/hciattach $(1)/usr/sbin/
+    $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/hciconfig $(1)/usr/sbin/
+    $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/hcid $(1)/usr/sbin/
+    $(INSTALL_BIN) $(PKG_INSTALL_DIR)/../test/passkey-agent $(1)/usr/sbin/
    $(INSTALL_DIR) $(1)/etc/bluetooth
    $(CP) $(PKG_INSTALL_DIR)/../hcid/hcid.conf $(1)/etc/bluetooth/
    $(CP) $(PKG_INSTALL_DIR)/../rfcomm/rfcomm.conf $(1)/etc/bluetooth/
--- a/test/passkey-agent.c
+++ b/test/passkey-agent.c
@@ -223,12 +223,13 @@
        return -1;

-    if (use_default)
+    if (use_default) {
        dbus_message_append_args(msg, DBUS_TYPE_STRING, &agent_path,
-    else
+    } else {
        dbus_message_append_args(msg, DBUS_TYPE_STRING, &agent_path,
                DBUS_TYPE_STRING, &address, DBUS_TYPE_INVALID);
+    }


another solution:

create a pincodes file here (where is the address of the bluetooth adapter):
with a line for each device specifying the device address and PIN code to use, eg
00:22:33:44:55:66 0000

when this file exists, passkey-agent is not necessary.

The discussion might have continued from here.