如何强制蓝牙LE"Just Works"在Android中配对 [英] How to force Bluetooth LE "Just Works" Pairing in Android

查看:358
本文介绍了如何强制蓝牙LE"Just Works"在Android中配对的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个运行GATT服务器的嵌入式系统,我正尝试通过Android连接该服务器.任务很简单:连接到GATT服务器,浏览特征并验证读/写功能.问题是当我尝试与Android应用程序连接时,它尝试与"Passkey"(而不是"Just Works")配对[

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.

我尝试了Play商店中的许多应用程序,但所有这些应用程序都仅尝试与Passkey配对.但这是我正在使用的最新版本: https://play.google.com/store/apps/details?id=com.macdom.ble.blescanner

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

我使用LightBlue应用程序(在OS X和iOS中受支持)进行此工作.因此,我知道我的外围设备(GATT服务器)正在工作:广告,可连接的,可访问的特性等.

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.

如何强制Android使用Just Works代替配对密码"?我缺少外围设备配置吗?

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

谢谢

推荐答案

问题的根源是Linux接口所处的模式.默认情况下,同时支持BR/EDR(经典)和LE的蓝牙设备采用双模式.模式.也就是说,它们可以作为Classic或LE设备运行.我不了解Android API,也没有尝试开发可检测双模设备并选择使用Just Working配对以LE身份连接的Android应用.但是我能够在界面上禁用BR/EDR并验证Android在扫描过程中是否将其检测为仅LE(单模)界面.然后,Android应用程序使用Just Working配对无缝连接.

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.

这是我在界面上禁用BR/EDR的方式:

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

您可以通过下载并构建Bluez在Linux中构建btmgmt应用程序.btmgmt应用程序有条件地基于-enable-experimental 配置参数构建.

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.

更新:另一种方法是修改广播的接口功能,而不是修改接口功能.这是通过广告标记完成的.修改标志以广播不支持BR/EDR的信息.这是位2,将创建标志广播0x04.(请参阅Bluetooth SIG doc CSS v4:A部分的第1.3.2节)

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)

这篇关于如何强制蓝牙LE"Just Works"在Android中配对的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆