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

Reject non-LESC pairing (not allowing Legacy pairing)

Hi,

I am working on a product based on an nRF52832 (SDK 15.3, Softdevice S112 v6.1).

For security purposes, I would like to restrict the pairing / bonding procedure to LE Secure connections. It should therefore forbid any pre-4.2 BLE device to connect to my product but that's ok.

To achieve that, I tried the following code :

        case BLE_GAP_EVT_SEC_PARAMS_REQUEST:
            NRF_LOG_DEBUG("BLE_GAP_EVT_SEC_PARAMS_REQUEST");
            if (p_ble_evt->evt.gap_evt.params.sec_params_request.peer_params.lesc == 0)
            {
                NRF_LOG_DEBUG("Legacy security request, not LESC");
                // Reject pairing
                err_code = sd_ble_gap_sec_params_reply(m_conn_handle, BLE_GAP_SEC_STATUS_PAIRING_NOT_SUPP, NULL, NULL);
                APP_ERROR_CHECK(err_code);
            }

Unfortunately, when I do that and try to connect with an old smartphone, I get the following error log :

<info> app: Connected<\r><\r><\n>
<debug> nrf_ble_gatt: ATT MTU updated to 247 bytes on connection 0x0 (response).<\r><\r><\n>
<info> app: Data len is set to 0xF4(244)<\r><\r><\n>
<debug> app: ATT MTU exchange completed. central 0xF7 peripheral 0xF7<\r><\r><\n>
<debug> peer_manager_handler: Event PM_EVT_CONN_SEC_START<\r><\r><\n>
<debug> peer_manager_handler: Connection security procedure started: role: Peripheral, conn_handle: 0, procedure: Bonding<\r><\r><\n>
<debug> peer_manager_handler: Event PM_EVT_CONN_SEC_PARAMS_REQ<\r><\r><\n>
<debug> peer_manager_handler: Security parameter request<\r><\r><\n>
<debug> app: BLE_GAP_EVT_SEC_PARAMS_REQUEST<\r><\r><\n>
<debug> app: Legacy security request, not LESC<\r><\r><\n>
<error> app: ERROR 8 [NRF_ERROR_INVALID_STATE] at C:\Workspace\loreal_b4_billy\billy_firmware\billy_ble\billy_connection.c:503<\r><\r><\n>
PC at: 0x00030A39<\r><\r><\n>
<error> app: End of error report<\r><\r><\n>

The documentation states that this error should happen if the function is called outside of the SEC_PARAMS_REQUEST event but I am indeed in this event so I don't understand the error.

Anyone has an idea ?

Thanks.

Parents Reply Children
Related