Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to set up BLE bonding

Dear Nordic,

we are devepoling FW based on nRF52832, SDK 17.0.2. We have 2 devices:

BLE Central with SD S332

BLE Peripheral with SD S112

We setted up an open BLE communication, the data are exchanging fine. At this development stage we need to add the bonding feature because we need a thrusted communication between central an peripheral.

Could you please suggest us some clear documentation on how to set up the peer manager link well?

There are many questions here on the forum but unfortunately there are no adequate answers for our case. Could you give us the correct links to the documentation?
Please don't tell us to use your examples, we'd rather read a guide with clear explanations rather than having to debug examples that have little documentation.

Thanks for your help!

Parents
  • Hello,

    You can find documentation for peer manager here:
    https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.1.0/lib_peer_manager.html

    Honestly speaking, if you want to support bonding, then I strongly recommend that you start with an existing application that already support bonding (peer manager), and include the services and characteristics you want to that application (or even update the softdevice header files and ram/flash usage due to a different softdevice), instead of the other way around. The peer manager module have a lot of depencies and defines, and including all those to a new project is not something I recommend. Instead the nRF5 SDK have already done the work for you by providing applications that support bonding.

    Best regards,
    Kenneth

  • Dear Kenneth,

    I'm studying the docs. There is already some peer manager configuration in my code so i fixed it up following the documentation.

    I can't understand the parameters for "ble_gap_sec_params_t" settings struct:

    referring to Peer Manager - Usage - Security parameters there is some common configurations. I'm using the "Just Works bonding" settings and I can see my device advertising, when I connect it shows all the characteristic and I can read/write them without bonding my device with my phone.

    What are the right parameters to allow the connecton only with bonded devices?

    Thanks!

  • Typically when you init the services and characteristics you also define the security requirements to access them by using:

    /**@defgroup BLE_GAP_CONN_SEC_MODE_SET_MACROS GAP attribute security requirement setters
     *
     * See @ref ble_gap_conn_sec_mode_t.
     * @{ */
    /**@brief Set sec_mode pointed to by ptr to have no access rights.*/
    #define BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS(ptr)          do {(ptr)->sm = 0; (ptr)->lv = 0;} while(0)
    /**@brief Set sec_mode pointed to by ptr to require no protection, open link.*/
    #define BLE_GAP_CONN_SEC_MODE_SET_OPEN(ptr)               do {(ptr)->sm = 1; (ptr)->lv = 1;} while(0)
    /**@brief Set sec_mode pointed to by ptr to require encryption, but no MITM protection.*/
    #define BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM(ptr)        do {(ptr)->sm = 1; (ptr)->lv = 2;} while(0)
    /**@brief Set sec_mode pointed to by ptr to require encryption and MITM protection.*/
    #define BLE_GAP_CONN_SEC_MODE_SET_ENC_WITH_MITM(ptr)      do {(ptr)->sm = 1; (ptr)->lv = 3;} while(0)
    /**@brief Set sec_mode pointed to by ptr to require LESC encryption and MITM protection.*/
    #define BLE_GAP_CONN_SEC_MODE_SET_LESC_ENC_WITH_MITM(ptr) do {(ptr)->sm = 1; (ptr)->lv = 4;} while(0)
    /**@brief Set sec_mode pointed to by ptr to require signing or encryption, no MITM protection needed.*/
    #define BLE_GAP_CONN_SEC_MODE_SET_SIGNED_NO_MITM(ptr)     do {(ptr)->sm = 2; (ptr)->lv = 1;} while(0)
    /**@brief Set sec_mode pointed to by ptr to require signing or encryption with MITM protection.*/
    #define BLE_GAP_CONN_SEC_MODE_SET_SIGNED_WITH_MITM(ptr)   do {(ptr)->sm = 2; (ptr)->lv = 2;} while(0)
    /**@} */

    If you don't need bonding you use BLE_GAP_CONN_SEC_MODE_SET_OPEN(), if you need bonding you use BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM() or better.

  • Thanks for your reply.

    I setted BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM in the gap_params_init function but nothing changed:

    If I try to connect using nRF connect APP there is no bonding request.

    I can also read the device services and characteristic list, and I can read all the characteristics values.

    Is there something missing?

  • Maybe they have been previously bonded?

    Kenneth

Reply Children
Related