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

Secure connection between nRF51822 and Android Smartphone?

Hello, i'm programming an android app to connect to the nRF51822 (peripheral). Without any security or pairing settings everything works fine. The Problem: Any kind of authentication and encryption is needed, but in the final Product the nRF51822 has no display or keyboard. Is there any way to establish a secure, authenticated connection to the Chip under that conditions?

In addition to the problem, what is the difference between the "Properties" and the "Permissions" of a Characteristic and what are they used for?

Parents
  • Thank you for your helpful answer, Hung Bui.

    Unfortunately I don't get a "Insufficient Authentication" error (Code 5) in the Android app, instead there occurs error code 137 (0x89: GATT_AUTH_FAIL?). Although the solution works anyway it would be interesting to know what's the reason for this!?

    I have one more (off topic) question: Is there any way to abort the connection to an already paired device?

Reply
  • Thank you for your helpful answer, Hung Bui.

    Unfortunately I don't get a "Insufficient Authentication" error (Code 5) in the Android app, instead there occurs error code 137 (0x89: GATT_AUTH_FAIL?). Although the solution works anyway it would be interesting to know what's the reason for this!?

    I have one more (off topic) question: Is there any way to abort the connection to an already paired device?

Children
  • Chris: Could you let me know how do you initiate the bonding procedure ? We, actually, randomly had that error for no reason. It's pretty hard to find the root cause, more likely it's a Android stack's bug.

    Regarding your question do you means to delete bonding or to disconnect a connection with a paired device. I don't see any issue to disconnect to a paired device. You can just call mBluetoothGatt.disconnect(); To remove a paired device, you would need to unpair it from Android Bluetooth setting panel

  • I tried it the way you described:

    1. Android device tries to read a Characteristic which permissions (read/write) are set to BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM. That returns 137 (sometimes 133 with Connection loss). By the way, I recognized that MasterControlPanel gets the right error.
    2. After that a Broadcast Receiver on the Android device is waiting for a BluetoothDevice.ACTION_BOND_STATE_CHANGED with state == BluetoothDevice.BOND_BONDED.
    3. By this event the App tires to read the initial Characteristic again. If this returns GATT_SUCCESS, the app state is set to connected.

    After the bonding process the user has to identify by a numeric code and if this fails i want to disonnect from the nRF51822 (peripheral). The disconnect has to be initiated by the nRF51822, is that possible?

  • Hi Chris,

    It's not normal to have error 137 or 133 when bonding. We did have that with Nexus devices running Android 4.3, however the update to Android 4.4.2 fixed that. Which central device did you use ?

    To request a passkey when bonding, you would need to declare the IO capability of the device (by SEC_PARAM_IO_CAPABILITIES) it could be keyboard, or LCD or both. You can have a look at the ble_app_gls example, that use the nRF6350 LCD module to display the passcode.

    If the passcode entered from the phone is wrong, the nRF51822 will send SMP Pairing Failed packet and the connection will be terminated (from both side).

  • For development i'm running android 4.4.2 in a VirtualBox. But although I still get the wrong error code now everything is working fine. Thank you for your help and the good Support.

Related