Honeycomb 3.2 通过 OOB 蓝牙绑定到非 Android 设备

发布于 2024-11-30 20:34:25 字数 3714 浏览 0 评论 0原文

我正在尝试将 Android 平板电脑安全地绑定到 Beagle 板以进行蓝牙通信。目标是在平板电脑 GUI 上无需任何用户交互即可绑定两个设备。我发现带外(OOB)绑定是我想要的用户,并且构建了基本上可以工作的代码,但是我在 Android 方面遇到了一些我没有预料到的问题。

在 Android 上,我通过 BluetoothDevicesBluetoothAdaper 类中的反射使用提供的方法。这很好,因为该应用程序是定制的,不针对 Android 市场或任何公共市场。这些方法没有通过公共 API 公开,因此我发现关于它们的文档很少。

希望 Ice Cream 推出时能够有一个真正的 OOB API,但现在我必须让它与 Honeycomb 一起工作。我将描述我的设置,然后我将根据设置提出问题。

因此,beagle 板正在运行最新的 bluez 堆栈,版本 4.96。我运行了 test-oob 源代码附带的示例代码,它运行得很好。除了执行脚本之外,不需要用户交互即可完成绑定。我通过在 beagle 板上使用 2 个 USB 蓝牙适配器并运行 python 脚本来完成此操作。

现在我想我有一个工作示例,我应该能够以类似的方式绑定到 Android 平板电脑。我决定使用 USB 作为安全传输 OOB 数据的介质,因为需要建立物理连接,并且我想要配对的设备不会有任何问题。我在交换数据方面没有任何问题,因此我不会对此进行更多讨论。我会说,beagle 板正在安装平板电脑,并且 OOB 数据写入/读取到唯一命名的文件。

在测试 OOB 示例代码中,以下几行基本上是 OOB 的执行方式。

oob0 = oob_adapter0.ReadLocalData()

oob1 = oob_adapter1.ReadLocalData()

oob_adapter0.AddRemoteData(adapter1_address, oob1[0], oob1[1])
oob_adapter1.AddRemoteData(adapter0_address, oob0[0], oob0[1])

adapter0.CreatePairedDevice(adapter1_address, "/test/agent_oob", "DisplayYesNo",
reply_handler=create_device_reply, error_handler=create_device_error)

我理解这段代码是因为每个蓝牙适配器都有它想要配对的适配器的 OOB 知识。债券已经建立,我们就完成了。

因此,要使用 Android 执行此操作,基本上 oob_adapter0 将添加通过 USB 接收的 Android 数据,并且在 Android 代码中,设备适配器将设置 beagle 板 OOB 数据。

我在Android中使用的方法是:

readOutOfBandData()

上面的方法获取平板电脑蓝牙适配器的OOB数据。此信息将发送到 beagle 板并使用 oob_adapter0.AddRemoteData 以及 Android 蓝牙适配器 MAC 地址进行设置。

getRemoteDevice(Beagle Board MAC Address)

上面的方法基本上返回了一个指向 beagle 板的蓝牙设备。

setDeviceOutOfBandData(Beagle Board OOB Data)

上述方法设置在绑定/配对期间要使用的远程设备的带外数据。调用 getRemoteDevice() 返回的蓝牙设备用作对象。

我执行这些方法,然后向 Beagle 板发出信号开始配对。然后,beagle 板将与 Android 设备配对,但在 Android 上,我会弹出一个窗口,显示“设备 XYZ 想要配对”,并让用户选择“配对”或“不配对”,我没想到会弹出此窗口这是 Andoird 自己做的事情。我没有像预期的那样在小猎犬板上得到任何东西。我觉得我复制了 test-oob 脚本,该脚本没有产生任何弹出窗口要求用户确认配对。所以我不确定问题是什么。

然后我想,如果平板电脑是发起配对的设备怎么办,但是平板电脑上弹出窗口询问相同的问题时也会出现同样的问题。

因此,我更多地研究了我的 Android 代码,经过反复试验,我意识到 Android 根本不需要设置任何 OOB 数据。只要 beagle 板具有平板电脑 OOB 信息,配对就会完成,无需用户交互。

哇,我得到了想要的输出,但不是以我理解的 OOB 方式。此外,即使我现在已配对,beagle 板上的 createPariedDevice() 调用仍然返回配对失败。该方法是否正在等待我没有执行的调用?另外为什么Android在配对前不需要知道beagle板OOB信息?

此外,当您导航到蓝牙设置时,beagle 板不会列为已配对设备,但已配对。如果我将蓝牙关闭然后打开并扫描蓝牙设备,配对的 beagle 板最终将显示为配对设备。我还可以在 beagle 板上的蓝牙监视器上看到它已配对并与平板电脑通信。

我尝试了相反的方法,Android 知道 beagle 板 OOB 信息并通过 createBondOutOfBand() 启动绑定过程,但 beagle 板不知道 Android 平板电脑 OOB 信息。此案例产生弹出窗口询问“我想与 beagle 板配对”的结果。因此,这与双方都知道OOB信息并且beagle板发起配对的情况相同。

所以我觉得我的设置中的某些内容不是 100% 正确,而且我无法理解为什么。关于如何正确执行此操作的信息也很少。

我也使用了这些方法

setTrust(boolean) and setPairingConfirmation(boolean)

,但它们似乎没有影响任何事情,因为我会根据上述情况是否会弹出窗口。因此,弹出窗口似乎与上述方法无关。

我注意到有一个名为:的方法,

setRemoteOutOfBandData()

但我没有看到它的用途,并且真的不知道它需要什么。除了不需要任何增强的 setRemoteOutOfBandData() 之外,此方法与 setDeviceOutOfBandData(Beagle Board OOB 数据)有何不同?

所以我的问题是:

  1. 当我复制 test-oob 脚本示例时,为什么 Android 平板电脑上会显示弹出窗口,询问我是否要配对。我觉得两个设备都知道彼此的 OOB 信息,因此 Aandroid 不应该询问我是否想与 beagle 板配对。

  2. 为什么当我从 Android 平板电脑代码中删除 beagle board 信息时,配对无需任何用户交互即可完成?对我来说,这种情况应该是询问我是否想要配对,因为 Android 代码没有有关 beagle 板的信息,不应该接受它。虽然 Beagle 板具有来自平板电脑的正确 OOB 信息,但感觉不正确。也许我只是对 OOB 了解不够,这是正确的。

    1. 如果情况是问题 2 是预期的并且正常操作过程,那么为什么 Android 设备不知道它已与 beagle 板配对,而不需要扫描设备并关闭蓝牙然后再打开?我是否需要调用另一种方法才能让它被看到我不知道?这里有些东西似乎不太正确。

I'm trying to securely bond an Android tablet to a beagle board for Bluetooth communications. The goal is to bond both devices without any user interaction on the tablet GUI. I've found out of band (OOB) bonding to be what I want to user and have constructed code the basically works, but I am having some issues on the Android side that I didn't expect.

On Android I am using supplied methods via reflection in the BluetoothDevices and BluetoothAdaper classes. This is fine because the app is custom and NOT targeted for the Android market or anything public. These methods are not exposed through the public API and thus I find very little documentation about them.

Hopefully Ice Cream will have a real OOB API when it comes out, but for now I have to get this working with Honeycomb. I'll describe what I have setup and then I'll ask questions I have based on the setup.

So the beagle board is running the latest bluez stack, version 4.96. I ran the test-oob example code that comes with the source and it worked perfectly. No user interaction was needed for the bonding to complete with the exception of executing the script. I accomplished this by using 2 USB bluetooth dongles on the beagle board and running the python script.

Now I figure I have a working example I should be able to bond to an Android tablet in a similar way. I decided to use USB as the medium to transfer the OOB data securely as a physical connection would need to be made and there would be no issues on which devices I wanted to pair to. I don't have any issues with exchanging data so I won't talk much more about this. I will say that the beagle board is mounting the tablet and OOB data is written/read to/from uniquly named files.

In the test OOB example code the following lines is basically the how OOB is performed.

oob0 = oob_adapter0.ReadLocalData()

oob1 = oob_adapter1.ReadLocalData()

oob_adapter0.AddRemoteData(adapter1_address, oob1[0], oob1[1])
oob_adapter1.AddRemoteData(adapter0_address, oob0[0], oob0[1])

adapter0.CreatePairedDevice(adapter1_address, "/test/agent_oob", "DisplayYesNo",
reply_handler=create_device_reply, error_handler=create_device_error)

I understand this code as each Bluetooth adapter has the OOB knowledge of the adapter it wants to pair to. The bond is created and we are done.

So to do this with Android basically oob_adapter0 will add the Android data received via USB and within Android code the device adapter would set the beagle board OOB data.

The methods I'm using in Android are:

readOutOfBandData()

The above method gets the OOB data of the tablet bluetooth adapter. This information is sent to the beagle board and set withing oob_adapter0.AddRemoteData along with the Android Bluetooth adapter MAC address.

getRemoteDevice(Beagle Board MAC Address)

The above method basically returns me a BluetoothDevices that points to the beagle board.

setDeviceOutOfBandData(Beagle Board OOB Data)

The above method sets the Out Of Band data for a remote device to be used during bonding/pairing. The returned Bluetooth device from the call to getRemoteDevice() is used as the object.

I execute these methods and then signal the beagle board to start pairing. The beagle board will then pair with the Android device, BUT on Android I get a pop up that says "Devices XYZ wants to Pair" and makes the user select "Pair" or "Don't Pair" I did not expect this pop up and it is something Andoird is doing on it's own. I do not get anything on the beagle board as expected. I feel like I duplicated the test-oob script which produced no pop ups asking the user to confirm paring. So I'm not sure what the issue is.

I then thought well what if the tablet was the device that initiated the pair, but same issue occurs with the pop up on the tablet asking the same questions.

So I played with my Android code more and after trial and error came to the realization that Android did not need to set any OOB data at all. As long as the beagle board had the tablet OOB information the pairing would complete with no user interaction required.

Woot, I got my desired output but not in the way I understood OOB. Also the createPariedDevice() call on the beagle board still returned pair failed, even though I am now paired. Is the method expecting a call I am not doing? Also why does Android not need to know about the beagle board OOB information before pairing?

Also when you navigate to the Bluetooth settings the beagle board is not listed as a paired device, BUT it is paired. If I do a combination of turning Bluetooth off and then on and doing a scan for Bluetooth devices the paired beagle board will eventually show up as a paired device. I can also see on the beagle board Bluetooth monitor that it is paired and communicating with the tablet.

I tried this the opposite way, Android knows about the beagle board OOB information and initiated the bonding process via createBondOutOfBand(), but the beagle board didn't know the Android tablet OOB information. This case produces the result of a pop-up asking of I wanted to pair with the beagle board. Thus it is the same as the case where OOB information is know on both sides and the beagle board initiated the pairing.

So I feel something in my setup is not 100% correct and I am failing to understand why. There is also not much information out there on how to properly do this.

I also played with the methods

setTrust(boolean) and setPairingConfirmation(boolean)

But they didn't seem to affect anything as I would get the pop-up or not based on the situations above. Thus the pop-up didn't seem to be associated to the above methods.

I noticed there was a method named:

setRemoteOutOfBandData()

But I didn't see a use for it and really couldn't figure out what it was needed for. How does this method differ from setDeviceOutOfBandData(Beagle Board OOB Data) outside of setRemoteOutOfBandData() not needing any augments?

So my questions are:

  1. Why does the pop-up display on the Android tablet asking if I want to pair, when I have duplicated the test-oob script example. I feel both devices know about each others OOB information and thus there shouldn't be a question asked by Aandroid on if I wanted to pair with the beagle board.

  2. Why when I removed the beagle board information from the Android tablet code that pairing completes without any user interaction? To me this situation should be asking if I wanted to pair because the Android code has no information about the beagle board and should not accept it. Granted the beagle board has the proper OOB information from the tablet, but it doesn't feel correct. Maybe I just don't know enough about OOB and this is correct.

    1. If the situation is question 2 is expected and normal operation procedure, then why does the Android devices not know it is paired to the beagle board without needing to play with scanning for devices and turning Bluetooth off and then on? Is there another method I need to call to make it be seen that I don't know about? Something just doesn't seem correct here.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文