且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Android 上的 BLE 外设配对引脚

更新时间:2023-01-24 07:43:08

总结:将客户端的 I/O Capabilites 设置为Keyboard Only".

说明:

我不完全确定您的系统幕后"发生了什么.但是我可以告诉您根据 BLE CoreSpec 应该发生什么.首先参见 CoreSpec V4.2, Vol.3,H 部分,第.2.3.5.1,表2.7 &2.8.根据身份验证要求和设备的 I/O 功能,定义了使用哪种配对.

I am not fully sure what happens "under the hood" of your system. But I can tell you what should be happening according to the BLE CoreSpec. First see CoreSpec V4.2, Vol. 3, Part H, chap. 2.3.5.1, table 2.7 & 2.8. There it is defined which pairing is used, depending on the authentication requirements and the I/O capabilities of the devices.

您想要的是密码输入:响应者显示,发起者输入".如果使用传统配对(根据蓝牙 V4.0 配对),就会出现这种情况,并且如果:

What you want is described as "Passkey Entry: responder displays, initiator inputs". This is the case if legacy pairing (pairing according to Bluetooth V4.0) is used, and if:

  • 服务器(响应者)有一个显示和
  • 客户端(发起者)有一个键盘和
  • 服务器和客户端都没有显示器和键盘.

(如果没有使用 OOB 数据并且强制执行 MITM,但我假设这是给定的.)请注意,如果客户端和服务器都有显示器和键盘,则默认情况是客户端显示和服务器输入.看起来,如果您的协议自动处理配对,它也会自动选择 CoreSpec 中定义的配对方法.

(And if OOB data is not used and MITM is enforced, but I assume this as given.) Note that if both client and server have display and keyboard, the default case is that the client displays and the server inputs. It would seem that if your protocol automatically handles pairing, it will also automatically chose the pairing method as defined in the CoreSpec.

所以你看到的是对应不同服务器的不同I/O能力.您的客户端似乎有显示器和键盘,因此如果您使用带有显示器和键盘的服务器,客户端将显示密码,响应者将等待输入(适合您的情况 1).对于情况 2,我们有数值比较;这只有在客户端和服务器都支持 LE 安全连接(根据蓝牙 V4.2 配对)时才有可能.

So what you see is corresponding to different I/O capabilities of different servers. It seems that your client has display and keyboard, so if you use a server with display and keyboard, the client will display the passkey and the responder will wait for input (which fits to your case 1). For case 2, we have Numeric Comparison; this is only possible if LE Secure Connections (pairing according to Bluetooth V4.2) is supported by both client and server.

对于case 3,我不知道是怎么回事,但可能是Android系统和iOS系统不能很好地协同工作(但我不知道为什么).

For case 3, I don't know what is going on, but it may be a problem between an Android system and an iOS system not operating well together (but I have no idea why).

因为这里的配对似乎是完全自动化的,所以唯一的可能是改变 I/O 功能.应该有一个功能可以更改这些功能,请查看您的手册.如果您不想在客户端上使用显示器,请将其 I/O 功能设置为仅键盘",它将表现出您期望的行为.(*)

Since pairing seems to be fully automized here, the only possibility to change things is to change the I/O capabilities. There should be a function to change these capabilities, check your manual. If you do not want to use a display on the client, set its I/O capabilities to "Keyboard Only" and it will exhibit the behavior you expect.(*)

(*) 这仅在您使用传统配对时成立.如果两个设备都支持 LE 安全连接,建议您使用这个较新的配对协议,因为它消除了旧协议的安全问题.(不过,我会假设在这种情况下,无论如何都会自动使用较新的协议.)

(*) This holds only if you use legacy pairing. If both devices support LE Secure Connections, it is recommended that you use this newer pairing protocol, since it removes security issues with the old protocol. (I would however assume that in this case, the newer protocol is used automatically anyway.)