Random Key pairing with peripheral

We have peripheral, and  we want to connect it using NRF 52840.

when we are bonding this using nrf connect app we get a pop up with random key and using pair we can pair with the device.

now we want to connect this device in nrf52840.

what setting and API and setting we should use for authenticating such connection.

I have used below security parameters after getting connected.


sec_params_ota.bond           = 1;              // Enable bonding
sec_params_ota.mitm           = 1;              // Require MITM protection (numeric comparison or passkey)
sec_params_ota.lesc           = 1;              // Enable LE Secure Connections
sec_params_ota.keypress       = 0;              // Optional: enable keypress notifications
sec_params_ota.io_caps        = BLE_GAP_IO_CAPS_DISPLAY_YESNO;  // For Numeric Comparison
sec_params_ota.oob            = 0;              // No OOB data
sec_params_ota.min_key_size   = 7;              // Minimum key size (7 to 16)
sec_params_ota.max_key_size   = 16;             // Max key size
sec_params_ota.kdist_own.enc  = 1;
sec_params_ota.kdist_own.id   = 1;
sec_params_ota.kdist_peer.enc = 1;
sec_params_ota.kdist_peer.id  = 1;

 ret_code_t  err_code = sd_ble_gap_authenticate(conn_handle, &sec_params_ota);
  if (err_code != NRF_SUCCESS)
   {
             NRF_LOG_ERROR("Failed to start authentication: %d", err_code);
     }
 

here i am not getting any error.

Related