Hi DevZone,
My customer is using nRF5 SDK v17.1.0 with LESC Numeric Comparison pairing. They have encountered an issue during the pairing process: when the central (phone) initiates pairing, the
peripheral correctly displays the passkey. However, if the pairing request is rejected on the peripheral side, the pairing dialog box on the central side does not disappear. According to the
customer, BLE chips from other vendors do not exhibit this behavior.
I replicated and tested this issue using a standard nRF5 SDK v17.1.0 example on an nRF52832 DK.
The results confirmed that when the peripheral rejects the pairing, the pairing dialog box on the phone remains visible. Interestingly, when I ran the same test using NCS 3.4, the pairing dialog dismissed normally as expected.
After further investigation, I noticed that in NCS, if the peripheral rejects the pairing, it explicitly sends an SMP Pairing Failed packet. However, in the nRF5 SDK, even though the corresponding code logic triggers key_type = BLE_GAP_AUTH_KEY_TYPE_NONE, the device does not actually send the SMP Pairing Failed (Reason: 0x04 - Confirm Value Failed) command.
static ret_code_t num_comp_reply(uint16_t conn_handle, bool accept)
{
uint8_t key_type;
ret_code_t err_code;
if (accept)
{
NRF_LOG_INFO("Numeric match confirmed. Conn handle: %d", conn_handle);
key_type = BLE_GAP_AUTH_KEY_TYPE_PASSKEY;
}
else
{
NRF_LOG_INFO("Numeric match rejected. Conn handle: %d", conn_handle);
key_type = BLE_GAP_AUTH_KEY_TYPE_NONE;
// Must be set before the reply: replying with BLE_GAP_AUTH_KEY_TYPE_NONE makes the
// SoftDevice send an SMP Pairing Failed PDU (Numeric Comparison Failed) and raise
// BLE_GAP_EVT_AUTH_STATUS, which in turn produces PM_EVT_CONN_SEC_FAILED.
m_num_comp_rejected_locally = true;
}
err_code = sd_ble_gap_auth_key_reply(conn_handle, key_type, NULL);
// Do NOT use APP_ERROR_CHECK() here: a failure must stay visible instead of
// resetting the chip, because on an error nothing is transmitted and the SMP
// request is still pending.
if (err_code == NRF_SUCCESS)
{
NRF_LOG_INFO("sd_ble_gap_auth_key_reply(key_type=%d) OK", key_type);
}
else
{
m_num_comp_rejected_locally = false;
NRF_LOG_ERROR("sd_ble_gap_auth_key_reply(key_type=%d) failed: 0x%x (%s)",
key_type, err_code, nrf_log_push((char *)nrf_strerror_get(err_code)));
NRF_LOG_ERROR("Nothing was sent on air; the SMP request is still pending.");
printf("\r\nauth_key_reply failed: 0x%lx\r\n", (unsigned long)err_code);
}
return err_code;
}
NCS 3.4 Test Result: When the peripheral rejects the pairing request, the pairing dialog box on the phone disappears normally.
nRF5 SDK 17.10 Test Result: When the peripheral rejects the pairing request, the pairing dialog box on the phone fails to disappear.
The test project for NRF5 SDK(nrf5sdk 17.10,SEGGER Embedded Studio for ARM v5.68)
The test project on NCS3.4.0
Question:
I would like to confirm whether the nRF5 SDK SoftDevice itself inherently does not support sending this SMP Pairing Failed command in this scenario?
