在android中指定链接密钥而不进行配对

发布于 2024-10-08 15:35:19 字数 183 浏览 1 评论 0原文

我试图确定 android 中是否有一种方法可以将特定的链接密钥与现有的远程蓝牙设备实例相关联。

本质上,我想做的是与不可发现的蓝牙设备创建连接,而无需执行配对或重新配对过程。

我无法在标准配对过程中与设备建立链接密钥,因为我正在使用自定义专有配对机制。我更愿意在不使用本机代码的情况下完成此任务,但如果必须的话我会的。

I am trying to determine if there is a way in android to associate a specific link key with an already existing remote bluetooth device instance.

Essentially what I want to do is create a connection with a non-discoverable bluetooth device without going through the pairing or re-pairing procedure.

I am not able to establish the link key with the device in a standard pairing procedure because I am working with a custom proprietary pairing mechanism. I would prefer to accomplish this task without using native code, but if I have to then I will.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夏末染殇 2024-10-15 15:35:19

我需要自己解决这个问题。关键的一步是找到这段代码,它告诉我添加 android.将蓝牙包添加到我的项目中,然后添加文件 IBluetooth.aidl 和 IBluetoothCallback.aidl(您可以在链接中找到)。

实例化 IBluetooth 对象后,您就可以访问 BluetoothService 类,并且可以使用 IBluetooth.aidl 中的任何方法。我感兴趣的方法是

setPin(String address, byte[] pin)

使用它的问题是其他蓝牙代码期望已经调用配对对话框,并在 BluetoothEventLoop 类的 HashMap 中跟踪它。如果您在未发起配对请求的情况下尝试调用 setPin(),您将看到如下错误:

setPin(<address>) called but no native data available, ignoring. Maybe the PasskeyAgent Request was cancelled by the remote device or by bluez.

因此,我的解决方法(使用聊天示例)是启动连接线程来发起配对请求,然后休眠 500 毫秒以确保线程已启动,然后调用 setPin()。

I needed to solve this problem myself. The crucial step was finding this code, which told me to add the android.bluetooth package to my project, and add the files IBluetooth.aidl and IBluetoothCallback.aidl (which you'll find at the link).

Once you instantiate the IBluetooth object, you have access to the BluetoothService class, and can use any of the methods in IBluetooth.aidl. The method I was interested in was

setPin(String address, byte[] pin)

The problem with using it is the other Bluetooth code expects the pairing dialog to have been called already, and keeps track of that in a HashMap in the BluetoothEventLoop class. If you try calling setPin() without having initiated a pairing request, you'll see an error like this:

setPin(<address>) called but no native data available, ignoring. Maybe the PasskeyAgent Request was cancelled by the remote device or by bluez.

So the workaround for me (using the Chat example) was starting the connect thread to initiate the pairing request, then sleeping 500 ms to ensure the thread had started, then calling setPin().

渡你暖光 2024-10-15 15:35:19

没有公共 API 机制可以在不经过配对过程的情况下将链接密钥与设备关联起来。

配对后,一旦设备绑定,此关联就会自动创建(也称为绑定),然后进一步的连接将重新使用之前生成的链接密钥。

即使设备不可发现,如果您知道设备的蓝牙地址,您仍然应该能够与其连接/配对。

通过更改底层 android bluez 代码并连接以提供预生成的链接密钥等内部/私有机制在理论上是可能的,这将是一个困难的项目和自定义解决方案。
假设您有要提供/关联的链接键。注意 - 除了设备时钟等之外,链接密钥也是两个设备的设备地址的函数。
蓝牙

there is no public api mechanism to associate a link key with a device without going through the pairing process.

After pairing this association is automatically created (aka bonding) once devices are bonded then further connection will re-use the link key that was generated previously.

even if device is non-discoverable you should still be able to connect bond / pair with it, if you know the device bluetooth address.

internal / private mechanism by changing the underlying android bluez code, and hooking up to feed a pre-generated link key etc is theoretically possible and it will be a difficult project and a custom solution.
that is assuming that you have the link keys to feed / associate. note - link key is a function of the device address of both devices in addition to device clock etc.
bluetooth

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文