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;