I am a beginner to BLE Communication ,
Currently I am working on a project where I need to connect a peripheral device ( Central (nRF52840) ---> Peripheral (BLE device) ) Initial connection is successful and able to read service UUID's . but iam facing a issue with pairing once the connection is successful I receive this event BLE_GAP_EVT_SEC_REQUEST from bleEventHandler where i am trying to pass below security parameters like this
ble_gap_sec_params_t sec_params;
memset(&sec_params, 0, sizeof(ble_gap_sec_params_t));
// Security parameters
sec_params.bond = 1;
sec_params.mitm = 0;
sec_params.lesc = 0; // Legacy pairing
sec_params.keypress = 0;
sec_params.io_caps = BLE_GAP_IO_CAPS_NONE;
sec_params.oob = 0;
sec_params.min_key_size = 7;
sec_params.max_key_size = 16;
sec_params.kdist_own.enc = 1;
sec_params.kdist_own.id = 1;
sec_params.kdist_peer.enc = 1;
sec_params.kdist_peer.id = 1;
ret_code_t err_code = sd_ble_gap_authenticate(pBleEvent->evt.gap_evt.conn_handle,
&sec_params);
but the pairing keeps failing and gets disconnected and this is the log from central device
[INF] [BLE - UTIL] bleEventHandler : MTU Exchange Response received
[INF] [BLE - UTIL] bleEventHandler : PHY Update Request received
[INF] [BLE - UTIL] bleEventHandler : Unhandled event: 36
[INF] [BLE - UTIL] Security Request from peripheral
[ERR] [BLE - UTIL] Failed to initiate security: 8
[INF] [BLE - UTIL] bleEventHandler : Auth Status Event Received
[INF] [BLE - UTIL] bleEventHandler : Pairing not supported
[INF] [BLE - UTIL] Error Source: 0
[INF] [BLE - UTIL] Bonding: 0
[INF] [BLE - UTIL] LESC: 0
[INF] [BLE - UTIL] bleEventHandler : Unhandled event: 31
[INF] [BLE - UTIL] bleEventHandler : Disconnected, reason: 0x08
I tried using both using both
sd_ble_gap_authenticate()
and sd_ble_gap_sec_params_reply() and see the same error
Key Issues:
- Getting error code 8 (INVALID_STATE) when trying to initiate security
- Receiving "Pairing not supported" message
- Connection disconnects with reason 0x08