Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force Bluetooth LE "Just Works" Pairing in Android

I have an embedded system running a GATT server that I am trying to connect to via Android. The task is simple: connect to the GATT server, navigate characteristics, and validate read/write capabilities. The problem is when I try and connect with an Android app, it attempts to pair with a "Passkey" instead of with "Just Works" [https://developer.bluetooth.org/TechnologyOverview/Pages/LE-Security.aspx]. This isn't acceptable as my embedded device does not have any method of displaying a key to the user to use for pairing. So the connection method must be Just Works.

I have tried numerous apps from the Play store and all of them only attempt to pair with Passkey. But this is the current one I am working with: https://play.google.com/store/apps/details?id=com.macdom.ble.blescanner

I have this working using the LightBlue application (supported in OS X and iOS). So I know my peripheral (GATT server) is working: advertising, connectable, characteristic accessible, etc.

How do I force Android to use Just Works instead of Passkey pairing? Is there a peripheral configuration I'm missing?

Thanks

like image 774
linsek Avatar asked Feb 03 '15 19:02

linsek


1 Answers

The root of the issue was the mode the Linux interface was in. Bluetooth devices that support both BR/EDR (Classic) and LE by default are in dual-mode. That is, they can operate as a Classic or LE device. I do not have insight into the Android API and have not attempted to develop an Android app that can detect a dual-mode device and choose to connect as LE using Just Working pairing. But I was able to disable BR/EDR on the interface and validate Android detected it during scan as an LE only (single-mode) interface. The Android app then connected seamlessly using Just Working pairing.

Here is how I disabled BR/EDR on the interface:

$ sudo hciconfig hci0 down
$ sudo ./btmgmt bredr off
hci0 Set BR/EDR complete, settings: connectable bondable le 
$ sudo hciconfig hci0 up
$ sudo hciconfig hci0 leadv

You can build the btmgmt application in Linux by downloading and building Bluez. The btmgmt application is built conditionally on the --enable-experimental config parameter.

UPDATE: Another approach is instead of modifying the interface capabilities, just modify the broadcasted interface capabilities. This is done through the advertisement flags. Modify the flags to broadcast that BR/EDR is not supported. This is bit 2 and would creates a flags broadcast of 0x04. (See Bluetooth SIG doc CSS v4: Part A, Section 1.3.2)

like image 108
linsek Avatar answered Sep 29 '22 00:09

linsek