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

nRF52840 Enable Pairing with Static Passkey

Hi,

I am working on the ble_app_template project.

1-How can I enable simple pairing without NFC?
2-Also how can I set pairing code?
3-Is the write way to secure characteristics?

    attr_md.rd_auth    = 1;
    attr_md.wr_auth    = 1;
 

Thanks!

Parents Reply
  • Sorry,  I'm bothering you. :|

    One last thing:

    "When you configure the characteristic with BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM(), the central/client will receive a Insufficient Authorization when it tries to read/write to the characteristic. After that the default behavior is that the central will initiate the pairing/bonding process. And the link will be encrypted after that. "

    Now after setting this BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM my link will be encrypted?


    The error NRF_ERROR_INVALID_STATE coming from the main.c Line 670 nrf_ble_qwr_conn_handle_assign () means If the given context has not been initialized.

    I have solved this issue.


    If you want the device to send the pairing request to mobile to allow pairing, you can add the code in the BLE_GAP_EVT_CONNECTED event. If the users cancel the pairing request from the peripheral on mobile, they cannot read/write characteristics.

    I have added this part and get this error sometimes when I unpair on try to repair.
    "couldn't pair with the device because of incorrect PIN or Passkey"



Children
  • Hi,

    Muqarrab said:
    Now after setting this BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM my link will be encrypted?

    No, it sets the characteristic accessible when the link is encrypted by pair. 

    Muqarrab said:
    I have solved this issue.

     Good. 

    Muqarrab said:
    I have added this part and get this error sometimes when I unpair on try to repair.
    "couldn't pair with the device because of incorrect PIN or Passkey"

    How do you delete bonding information on the nRF side and on the phone side? As long as the bonding information has been deleted on both sides, then they should pair again in exactly the same way as they did initially. However, if the bonding data is only deleted on one side, then this has to be explicitly allowed.

    You'll need to delete the bonds from your nRF. You should be able to do so by pressing button 2 while the nRF is asleep according to the BSP BLE Button Assignments.

    If you want the nRF to allow re-pairing when only the phone has deleted the bonding data, you have to set ".allow_repairing = true" in the handling of the PM_EVT_CONN_SEC_CONFIG_REQ event. as this post.

    -Amanda H.

  • Hi,

    No, it sets the characteristic accessible when the link is encrypted by pair. 

    I have set this BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM and now can read/write characteristic, that means my link is encrypted by pair?



    If you want the nRF to allow re-pairing when only the phone has deleted the bonding data, you have to set ".allow_repairing = true" in the handling of the PM_EVT_CONN_SEC_CONFIG_REQ event. as this post.

    I have added the mentioned code. But still getting the following issue. Sweat

    static void pm_evt_handler(pm_evt_t const * p_evt)
    {
        pm_handler_on_pm_evt(p_evt);
        pm_handler_flash_clean(p_evt);
    
        switch (p_evt->evt_id)
        {
            case PM_EVT_PEERS_DELETE_SUCCEEDED:
                advertising_start(false);
            break;
    
            case PM_EVT_CONN_SEC_CONFIG_REQ:
            {
                // Allow pairing request from an already bonded peer.
                pm_conn_sec_config_t conn_sec_config = {.allow_repairing = true};
                pm_conn_sec_config_reply(p_evt->conn_handle, &conn_sec_config);
            } 
            break;
    
            default:
                break;
        }
    }

     

  • Hi, 

    Muqarrab said:
    I have set this BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM and now can read/write characteristic, that means my link is encrypted by pair?

    In the Template example, it is set to Just Works bonding to encrypted the link if you enable the bond function from the app.

    #define SEC_PARAM_BOND                  1                                       /**< Perform bonding. */
    #define SEC_PARAM_MITM                  0                                       /**< Man In The Middle protection not required. */
    #define SEC_PARAM_LESC                  0                                       /**< LE Secure Connections not enabled. */
    #define SEC_PARAM_KEYPRESS              0                                       /**< Keypress notifications not enabled. */
    #define SEC_PARAM_IO_CAPABILITIES       BLE_GAP_IO_CAPS_NONE                    /**< No I/O capabilities. */
    #define SEC_PARAM_OOB                   0                                       /**< Out Of Band data not available. */
    #define SEC_PARAM_MIN_KEY_SIZE          7                                       /**< Minimum encryption key size. */
    #define SEC_PARAM_MAX_KEY_SIZE          16                                      /**< Maximum encryption key size. */

    Muqarrab said:
    I have added the mentioned code. But still getting the following issue.

    Remove the pairing request part in the BLE_GAP_EVT_CONNECTED event. Then, if you delete bond information after the first bond, the next connection will pop up the allow to pair window. That can fix the issue. 

    -Amanda H.

  • Thank you so much, @amanda Hsieh
    Problem Solved.
    JUST last thing sometimes I don't get pairing request in mobile but my mobile is bonded with the device. So I don't need to worry about that?

  • Hi, 

    You need to bond from the mobile to encrypted the link, then you could access the secured characteristics. 

    -Amanda H.

Related