I\'ve been searching the internet and haven\'t seen anything in the way of how to exactly implement OOB pairing. I was hoping somebody here could point me to some example code t
I have my issue 95% solved but I have hit a small road block. First I'll update this post with a more concrete answer to the original question and post my question at the end.
To recap, my task is to use out of band (oob) pairing to securely pair an android tablet using Honeycomb 3.2 to a beagle board through USB. I can't post specific code, but I'll give you all the steps needed to get this done.
On the beagle board, I have the bluez 4.96 stack installed with the dbusoob plugin installed. To confirm this is set up correctly install 2 Bluetooth dongles on the beagle board and run the OOB Test Code found in in the bluez archive in the test folder. This is a python script. The script should successfully pair the 2 Bluetooth dongles, if not bluez is probably not setup correctly.
To get USB communications with a tablet working you need to install mtpfs and mtp-tools. These are used to mount your tablet. They way I solved getting OOB information between the 2 devices were to mount the tablet on the beagle board. Once mounted the tablet and beagle board can write out a file with the information needed.
On the android side OOB is not supported in the public API so things get tricky. I believe this is because Honeycomb 3.2 does not have a bluez stack that officially supports OOB bonding, but Google has some kind of implementation coded in. I believe this because if you look at gingerbread source code for the Bluetooth Adapter and Bluetooth Device classes you can see OOB methods available but not exposed through the documented API.
These methods are still public so you can call them through reflection. Using reflection you can also get all of the method signatures in a class. This is how I figured out what methods I had available to me.
Beware though that many are not documented and it's not obvious what some do. The important ones to make note of are the readOutOfBandData() in the adapter class and setDeviceOutOfandData() in the device class.
Another gotcha you might run into is when you write your oob data to a file on the tablet to be read by the beagle board. Since android uses mtp you must index your file after it is written to the internal sdcard storage. To solve this you need to make use of the MediaScannerConnection class and the scanFile() method.
Hopefully the above helps anybody else with this same issue.
Now on to my question. I have my android application working great and my beagle board code is the testOOB example updated to have one end read OOB information from a file. Now the issue I see is when executed everybody sees each other great, but on the tablet I still get a message asking if I want to pair with device xyz. There are no keys or numbers. It just asks "Pair with Device XYZ" or something along those lines.
If I press "pair" it's all paired from the tablets point of view, BUT the python script returns that the paring failed. The python script on the beagle board is calling the actual method to do the bonding between the devices. Even when I have the android initiate the createBond call I see the same outcome. I can guarantee that I have set the required OOB data on both ends before trying to pair in both cases so that doesn't seem to be it.
So my issues that I'm hoping somebody can help me with are:
1) Why do I even get a message on android if the OOB data is exchanged properly? Is there another call I'm missing and on which end?
2) Why does the beagle board python script return paring failed even thought I press "pair" popup displayed on the tablet. The tablet and blues monitor both show the devices as paired. Some again I'm leaning towards the idea that I am missing something.
Thanks to anybody that can help :)
EDIT:
To add more information here is the logcat output:
D/UIBluetooth( 4363): !!!!!! Start Bond !!!!!!
D/BluetoothService( 1703): Setting out of band data for: 00:02:76:24:C2:8F:[-37, -1, 65, -42, -121, -75, -60, -4, -47, -86, -88, 14, 64, 83, 16, 96]:[-112, 34, 121, -97, 15, -54, -83, -
93, 104, -83, -124, -25, 89, 114, 66, 62]
D/BluetoothBondState( 1703): 00:02:76:24:C2:8F bond state 10 -> 11 (0)
D/UIBluetooth( 4363): createOobBond Successful
V/BluetoothEventManager( 2174): Received android.bluetooth.device.action.BOND_STATE_CHANGED
D/BluetoothEventLoop( 1703): Property Changed: Devices : 1
D/BluetoothEventLoop( 1703): Device property changed: 00:02:76:24:C2:8F property: Connected value: true
I/BluetoothEventLoop.cpp( 1703): agent_event_filter: Received method org.bluez.Agent:RequestOobData
I/BluetoothEventLoop.cpp( 1703): agent_event_filter: Received method org.bluez.Agent:RequestOobData
The last two line seems to be triggering the popup on Android to either Pair/Cancel with the Device in questions. I would like Android to know to just auto bond and not even ask. I could be missing a call or doing something out of order for all I know. The last thing I do in my code is to create the bond which seems to be the obvious place to do it....
Thanks for any suggestions!