This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to bond devices using the Android BLE library

Hi there,

This is actually a question re. the Android BLE library (https://github.com/NordicSemiconductor/Android-BLE-Library), so please re-direct me if necessary.

My question is in relation to bonding. I use the BLE library to connect to another Android device with the peripheral role. The GATT service on the peripheral has a characteristic requiring encryption. Therefore, when I use the BLE library to read the peripheral's characteristics, a pairing UI sequence ensues. However... the peripheral first displays a pairing dialog without the central device displaying one. If I then accept the peripheral's pairing request dialog then both the peripheral and the central (BLE library) devices display a dialog.

I experienced this behaviour prior to using the BLE library, when I used the Android APIs directly on the central device, so I don't think this is an issue with the BLE library per se.

I'm left wondering how others go about the process of bonding though. I've been working on getting bonding to work nicely on Android for a couple of weeks now, and Android is winning. Do people rely on users using the Android pairing UI of settings, or are they successful in using the BLE library to bond from the central device?

Thanks for any guidance.

Cheers,

-C

Parents
  • Thanks Emil. So, given bonding is required for reconnecting over a long period, how do most go about bonding using the BLE library? Do they use the ensureBonding call (which I’m still unsure of how/where it should be used) or do they rely on the user navigating to the system settings and doing it there?

  • ensureBond() can be used after connection. However, I would recommend using createBondInsecure() and using MITM in bonding (not Just Works). With MITM (e.g. bonding using PIN), the Android seems to request security on each connection. If an intruder pretends to be your device, the connection will time out and will not be successful. Also, seams like this also prevents from connecting to your device after bond info was removed from it, until you remove bonding the m from the phone as well.

    Ensure bond method will remove bonding in each connection and request new one each time, so your device needs a) allow that b) must remove all data every time new device bonds, as anyone would be able to connect and bond and read data.

    With createBondInsecure you may allow only one pairing on the device. Make sure you set right permissions on your characteristics so no one can read anything without being bonded.

Reply
  • ensureBond() can be used after connection. However, I would recommend using createBondInsecure() and using MITM in bonding (not Just Works). With MITM (e.g. bonding using PIN), the Android seems to request security on each connection. If an intruder pretends to be your device, the connection will time out and will not be successful. Also, seams like this also prevents from connecting to your device after bond info was removed from it, until you remove bonding the m from the phone as well.

    Ensure bond method will remove bonding in each connection and request new one each time, so your device needs a) allow that b) must remove all data every time new device bonds, as anyone would be able to connect and bond and read data.

    With createBondInsecure you may allow only one pairing on the device. Make sure you set right permissions on your characteristics so no one can read anything without being bonded.

Children
No Data
Related