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

Modifying NUS - Make it bond with smart phones

Hi, I use the NUS most of the time.

(SDK 7.2 & S110 7.1 with IAR 7.1)

As you know, HID keyboard or mouse bond with centrals (smart phones).

After bonding, when using iOS devices for example, the bonded devices' information are left.

Bond Just like this picture.

However, when a device is only using the NUS does not leave the device's info.

  1. This is because the peripherals that only use NUS just pairs with the central,

not bonding, is it?

  1. Can I modify the NUS code (in SDK 7.2) in order to bond with the central?

If this is possible, what changes are needed?

The reason to make it bond is I want connect the peripheral to the central directly.

Or is there other ways to make this service to perform a direct advertising?

Or the only solution is to make an app that make it seems to connect each other automatically?

-Regards, Mango922

/**************/

Added : 7, July, 2015 :

Thanks for answering!

You said : the iOS/Android system won't show your device and bond to your

device if they are note(you mean "not"?) HID device.

Nexus 5

However, after downloading the NUS(didn't changed the service) example,

I checked with my Nexus 5 and I showed the device. It uses Android 5.1.1.

Anyway you mean, after I change the NUS to make it bond, it will still not appear at the

"Settings -> Bluetooth"?

// Edited, Feb. 25, 2016

I edited the ble_nus.c like this.

I call device_manager_init before ble_nus_init.

#define SEC_PARAM_BOND                   1       /**< Perform bonding. */
#define SEC_PARAM_MITM                   0       /**< Man In The Middle protection not required. */

// static uint32_t rx_char_add
BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM(&cccd_md.read_perm);
BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM(&cccd_md.write_perm);

BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM(&attr_md.read_perm);
BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM(&attr_md.write_perm);

// static uint32_t tx_char_add
BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM(&attr_md.read_perm);
BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM(&attr_md.write_perm);

Error 7

  • @Mango:

    1. Pair means encrypt the link, and bond is storing the key so next time the link can be re-encrypted. If the device is not bonded, you won't see it in the Bluetooth setting. NUS by default doesn't require bonding so there will be no bond by default. On the other hand, HID keyboard requires bonding, so that explains what you observed.

    2. Yes you can modify NUS to require bonding. To do that in the service declaration in the nRF51 firmware, instead of using BLE_GAP_CONN_SEC_MODE_SET_OPEN you should use BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM or other option depend on which type of bonding you want (Just work, Passkey, etc)

    Note that the iOS/Android system won't show your device and bond to your device if they are not HID device. You would need to have an app for that. For the NUS we have the nRF UART app.

  • Yes, I meant "not HID". On Android, they changed that from time to time, and also depends on the manufacturing vendors. As far as I remember Samsung device won't show it if it's not HID or bonded. But maybe in the newer version 5.1.1 they may have it.

    So it's not guaranted that your device will always show up in the Bluetooth setting if it's not bonded.

  • Hi Hung Bui, I asked this question quite a long time ago. I'm trying this now.

    About iOS/Android system won't show your device and bond to your device if they are not HID device. You would need to have an app for that,

    you mean that, even though I change the code, NUS cannot be bonded without using a custom app for the NUS?

    For instance, suppose I changed the code to make the NUS bond.

    Since the nRF UART 2.0 App is available, the app will discover and connect (bond) with this peripheral.

    However, after disconnecting it, do you mean that this peripheral cannot be connected automatically without the app?

    As you know, HID device bonds to the central (phones) directly without choosing them from the settings tab, if they had exchanged their IRK.

    Even though I change the code from the NUS example, this "auto connection" won't work?

  • @Hung Bui, about changing the BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM option,

    should I applyBLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM to other services?

    For instance, I'm planning to use BAS or DIS with NUS.

    Applying

    BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM(&bas_init_obj.battery_level_char_attr_md.cccd_write_perm);
    

    or

    BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM(&dis_init_obj.dis_attr_md.read_perm);
    

    will do the work?

    // Edited (Feb, 25, 2016)

    I took a reference.

    At ble_nus.h. I made some changes (check my question script.)

    However, rx_char_add returns NRF_ERROR_INVALID_PARAM (number 7).

  • About BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM(&cccd_md.read_perm);
    If I remember correctly CCCD read permission has to be open.

Related