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

I have a built-in system with a GATT server with which I am trying to connect via Android. The task is simple: connect to the GATT server, view the characteristics and check the read / write capabilities. The problem is that when I try to connect to the Android application, it tries to connect "Passkey" instead of "Just Works" [ https://developer.bluetooth.org/TechnologyOverview/Pages/LE-Security.aspx] . This is unacceptable since my built-in device does not have a way to display the key for the user to be used for pairing. So the connection method should just be Works.

I tried many applications from the Play store, and they all just tried to connect to Passkey. But this is the current work I'm working with: https://play.google.com/store/apps/details?id=com.macdom.ble.blescanner

It works for me using the LightBlue application (supported on OS X and iOS). Therefore, I know that my peripheral server (GATT server) works: advertising, connectivity, available features, etc.

How to get Android to use Just Works instead of pairing packages? Do I have a peripheral configuration?

thanks

+5
source share
1 answer

The root of the problem is the Linux interface mode. Bluetooth devices that support BR / EDR (Classic) and LE by default are in two modes. That is, they can work as a classic or LE device. I don’t have an understanding of the Android API and you didn’t try to develop an Android application that can detect a device with two modes and select a connection as LE using Just Working pairing. But I managed to disable BR / EDR on the interface and confirm that Android detected it during the scan as only a single-mode interface. After that, the Android application easily connected using Just Working pairing.

Here's 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 create the btmgmt application on Linux by downloading and building Bluez. The btmgmt application is built conditionally on the --enable-experimental configuration parameter.

UPDATE: Another approach is not to change the capabilities of an interface, but to simply change the capabilities of a broadcast interface. This is done through advertising flags. Change flags for translation that BR / EDR is not supported. This is bit 2, and it will generate flags in 0x04 format. (See Bluetooth SIG doc CSS v4 Section: Part A, Section 1.3.2)

+3
source

Source: https://habr.com/ru/post/1212563/


All Articles