简体   繁体   English

Android上的BLE外设配对引脚

[英]BLE peripheral pairing pin on android

I implemented a GATT Server and Client App on Android. 我在Android上实现了GATT服务器和客户端应用程序。 The connection is working and I forced pairing by adding PERMISSION_READ/WRITE_ENCRYPTED_MITM to all of the GattCharacteristics. 连接正常,我通过将PERMISSION_READ / WRITE_ENCRYPTED_MITM添加到所有GattCharacteristics来强制配对。

But the pairing behavior differs on different clients: 但是配对行为在不同的客户端上有所不同:

1) Pin is shown on the client/central (Android 5 on Samsung Galaxy S3) and should be insert on the server/peripheral (Android 7 on Nexus 5). 1)Pin显示在客户端/中央(Samsung Galaxy S3上的Android 5)上,应插入服务器/外围设备(Nexus 5上的Android 7)。

2) Passkey is shown on both devices client/central (Android 5 on Samsung Galaxy S3) and server/peripheral (Android 6 on Nexus 7) 2)密钥显示在客户端/中央设备(Samsung Galaxy S3上的Android 5)和服务器/外围设备(Nexus 7上的Android 6)上

3) Pairing with Windows or iOS fails with server/peripheral expecing a pin for input. 3)与Windows或iOS配对失败,服务器/外围设备需要输入引脚。

What I expected and want to happen is: 我期望和想要发生的是:

Pin is shown on the server/peripheral and has to be insert on client/central 引脚显示在服务器/外围设备上,必须插入客户端/中央

Is there any way to configure that behavior? 有没有办法配置这种行为?

Thanks in advance! 提前致谢!

EDIT 编辑

Here is my setup: 这是我的设置:

BluetoothGattService gattService = new BluetoothGattService(
    serviceUUID, BluetoothGattService.SERVICE_TYPE_PRIMARY);
gattService.addCharacteristic(new BluetoothGattCharacteristic(
    charReadUUID,
    BluetoothGattCharacteristic.PROPERTY_READ,
    BluetoothGattCharacteristic.PERMISSION_READ_ENCRYPTED_MITM
));
gattService.addCharacteristic(new BluetoothGattCharacteristic(
    charWriteUUID,
    BluetoothGattCharacteristic.PROPERTY_WRITE,
    BluetoothGattCharacteristic.PERMISSION_WRITE_ENCRYPTED_MITM
));
gattServer.addService(gattService);

...

AdvertiseSettings settings = new AdvertiseSettings.Builder()
    .setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_BALANCED)
    .setTxPowerLevel(AdvertiseSettings.ADVERTISE_TX_POWER_HIGH)
    .setConnectable(true)
    .build();

AdvertiseData data = new AdvertiseData.Builder()
    .setIncludeTxPowerLevel(false)
    .addServiceUuid(serviceUUID)
    .build();

BluetoothLeAdvertiser advertiser = adaper.getBluetoothLeAdvertiser()
advertiser.startAdvertising(settings, data, callback);

Summary: Set the I/O Capabilites of your client to "Keyboard Only". 摘要: 将客户端的I / O功能设置为“仅限键盘”。

Explanation: 说明:

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. 但是根据BLE CoreSpec,我可以告诉你应该发生什么。 First see CoreSpec V4.2, Vol. 首先看CoreSpec V4.2,Vol。 3, Part H, chap. 3,H部分,第二章。 2.3.5.1, table 2.7 & 2.8. 2.3.5.1,表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. 在那里定义了使用哪种配对,具体取决于认证要求和设备的I / O能力。

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: 如果使用传统配对(根据蓝牙V4.0配对),并且如果:

  • the server (responder) has a display AND 服务器(响应者)有一个显示AND
  • the client (initiator) has a keyboard AND 客户端(发起者)有一个键盘AND
  • server and client do NOT both have display AND keyboard. 服务器和客户端都没有显示和键盘。

(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. (如果不使用OOB数据并强制执行MITM,但我认为这是给定的。)请注意,如果客户端和服务器都有显示和键盘,则默认情况是客户端显示和服务器输入。 It would seem that if your protocol automatically handles pairing, it will also automatically chose the pairing method as defined in the CoreSpec. 看起来如果你的协议自动处理配对,它也会自动选择CoreSpec中定义的配对方法。

So what you see is corresponding to different I/O capabilities of different servers. 所以你看到的是对应不同服务器的不同I / O功能。 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). 您的客户端似乎有显示器和键盘,因此如果您使用带显示器和键盘的服务器,客户端将显示密钥,响应者将等待输入(适合您的情况1)。 For case 2, we have Numeric Comparison; 对于案例2,我们有数字比较; this is only possible if LE Secure Connections (pairing according to Bluetooth V4.2) is supported by both client and server. 只有当客户端和服务器都支持LE安全连接(根据蓝牙V4.2进行配对)时,才可以执行此操作。

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). 对于案例3,我不知道发生了什么,但它可能是Android系统和iOS系统之间不能很好地运行的问题(但我不知道为什么)。

Since pairing seems to be fully automized here, the only possibility to change things is to change the I/O capabilities. 由于配对似乎在这里完全自动化,因此改变事物的唯一可能性是改变I / O能力。 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.(*) 如果您不想在客户端上使用显示器,请将其I / O功能设置为“仅限键盘”,它将显示您期望的行为。(*)

(*) 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. 如果两个设备都支持LE Secure Connections,则建议您使用此新配对协议,因为它消除了旧协议的安全问题。 (I would however assume that in this case, the newer protocol is used automatically anyway.) (但我会假设在这种情况下,无论如何都会自动使用更新的协议。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM