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

Failing to Pair / Bond with nRF Connect on Android or Win 10

 I am trying to do just bonding when I receive the BLE_GAP_EVT_SEC_PARAMS_REQUEST event as described in the sequence chart in this link infocenter.nordicsemi.com/index.jsp unfortunately I always get NRF_ERROR_INVALID_PARAM. Not really sure what I am doing wrong here.

Here is the RTT Viewer log

0> <info> app: Event id=16
0> <info> app: Connected.
0> <info> app: Event id=19
0> <info> app: BLE_GAP_EVT_SEC_PARAMS_REQUEST
0> <error> app: ERROR 7 [NRF_ERROR_INVALID_PARAM] at ./helpers/ble/nrf52_ble.c:136
0> PC at: 0x000357D5
0> <error> app: End of error report

#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 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. */


memset(&m_sec_param, 0, sizeof(ble_gap_sec_params_t));

// Security parameters to be used for all security procedures.
m_sec_param.bond           = SEC_PARAM_BOND;
m_sec_param.mitm           = SEC_PARAM_MITM;
m_sec_param.lesc           = SEC_PARAM_LESC;
m_sec_param.keypress       = SEC_PARAM_KEYPRESS;
m_sec_param.io_caps        = SEC_PARAM_IO_CAPABILITIES;
m_sec_param.oob            = SEC_PARAM_OOB;
m_sec_param.min_key_size   = SEC_PARAM_MIN_KEY_SIZE;
m_sec_param.max_key_size   = SEC_PARAM_MAX_KEY_SIZE;
m_sec_param.kdist_own.enc  = 1;
m_sec_param.kdist_own.id   = 1;
m_sec_param.kdist_peer.enc = 1;
m_sec_param.kdist_peer.id  = 1;

err_code = pm_sec_params_set(&m_sec_param);
APP_ERROR_CHECK(err_code);



case BLE_GAP_EVT_SEC_PARAMS_REQUEST:
	NRF_LOG_INFO("BLE_GAP_EVT_SEC_PARAMS_REQUEST");
	memset(&m_sec_keyset, 0, sizeof(ble_gap_sec_keyset_t));
	m_sec_keyset.keys_own.
	err_code = sd_ble_gap_sec_params_reply(m_p_service->conn_handle,
										   BLE_GAP_SEC_STATUS_SUCCESS,
										   &m_sec_param,
										   &m_sec_keyset);
	APP_ERROR_CHECK(err_code);
	break;

  • Hi,

    If you have included the peer_manager, then this event is already handled by the peer_manager.

    Best regards,
    Kenneth

  • Yes, I have included Peer manager. My expectation was that the Peer manager would handle this based on the settings during initialization, but that doesn't seem to be the case. I tried that first from nRF Connect on Android and this is the log from RTT Viewer. The nRF Connect would show "Bonding" and a spinner for a long time and 

    nRF Connect Android successful connect, Bonding failed

    0> <info> app: Connected.
    0> <info> app: GATT ATT MTU on connection 0x0 changed to 247.
    0> <info> app: Event id=58
    0> <info> app: BLE_GATTC_EVT_EXCHANGE_MTU_RSP. Current MTU=247
    0> <info> app: Event id=18
    0> <info> app: BLE_GAP_EVT_CONN_PARAM_UPDATE
    0> <info> app: Event id=18
    0> <info> app: BLE_GAP_EVT_CONN_PARAM_UPDATE
    0> <info> app: Event id=19
    0> <info> app: Event id=18
    0> <info> app: BLE_GAP_EVT_CONN_PARAM_UPDATE
    0> <info> app: Fast advertising.
    0> <info> app: Event id=17
    0> <info> app: Disconnected, reason 19.

    Same thing happens with Win 10 as well and here is the log. Win 10 will not even pair if I do not handle the event and put BLE_GAP_SEC_STATUS_PAIRING_NOT_SUPP as the status in sd_ble_gap_sec_params_reply. Nothing else works.

    Win 10 failed pairing

    0> <info> app: Connected.
    0> <info> app: Event id=85
    0> <info> app: BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST. MTU=247
    0> <info> app: Event id=19
    0> <info> app: GATT ATT MTU on connection 0x0 changed to 247.
    0> <info> app: Event id=58
    0> <info> app: BLE_GATTC_EVT_EXCHANGE_MTU_RSP. Current MTU=525
    0> <info> app: Fast advertising.
    0> <info> app: Event id=17
    0> <info> app: Disconnected, reason 19.

    Win 10 Successful pairing.

    0> <info> app: Connected.
    0> <info> app: Event id=85
    0> <info> app: BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST. MTU=247
    0> <info> app: Event id=19
    0> <info> app: BLE_GAP_EVT_SEC_PARAMS_REQUEST
    0> <info> app: GATT ATT MTU on connection 0x0 changed to 247.
    0> <info> app: Event id=58
    0> <info> app: BLE_GATTC_EVT_EXCHANGE_MTU_RSP. Current MTU=525
    0> <info> app: Event id=25
    0> <info> app: BLE_GAP_EVT_AUTH_STATUS: status=0x85 bond=0x0 lv4: 0 kdist_own:0x0 kdist_peer:0x0
    0> <info> app: Event id=18
    0> <info> app: BLE_GAP_EVT_CONN_PARAM_UPDATE
    0> <info> app: Event id=82
    0> <info> app: BLE_GATTS_EVT_SYS_ATTR_MISSING
    0> <info> app: Event id=18
    0> <info> app: BLE_GAP_EVT_CONN_PARAM_UPDATE
    0> <info> app: Fast advertising.
    0> <info> app: Event id=17
    0> <info> app: Disconnected, reason 19.

    I tried with both SEC_PARAM_LESC 0 and 1, no difference.

  • I suggest to take a look at the (BLE peripheral) hid examples (keyboard and mouse), that include bonding with peer manager.

    Best regards,
    Kenneth

Related