开发者

Honeycomb 3.2 Bluetooth Bonding via OOB to non Android Device

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.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜