Hi there,
I have a project developed in SES, using nRF5 SDK v15.3.0 with only Just Works security without using LESC running on nRF52840. It has been running fine for 2 years. Recently, I have upgraded it to nRF5 SDK v17.1.0. Everything works fine.
Now we need to improve the security by adding LESC support.
I modify the code using the Glucose Application and (experimental) LE Secure Connections Multirole Example as reference.
1. sdk_config.h:
#define PM_LESC_ENABLED 1
#define NRF_BLE_LESC_ENABLED 1
2. Define the security parameters
3. Add nrf_ble_lesc_request_handler() in idle_state_handle(void) inside the main loop.
#define SEC_PARAM_BOND 1 /**< Perform bonding. */ #define SEC_PARAM_MITM 0 /**< Man In The Middle protection required. */ #define SEC_PARAM_LESC 1 /**< LE Secure Connections enabled. */ #define SEC_PARAM_KEYPRESS 0 /**< Keypress notifications not enabled. */ #define SEC_PARAM_IO_CAPABILITIES BLE_GAP_IO_CAPS_NONE /**< Display 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. */ #define PASSKEY_TXT "Passkey:" /**< Message to be displayed together with the pass-key. */ #define PASSKEY_TXT_LENGTH 8 /**< Length of message to be displayed together with the pass-key. */ #define PASSKEY_LENGTH 6 /**< Length of pass-key received by the stack for display. */ //...... static void idle_state_handle(void) { ret_code_t err_code; err_code = nrf_ble_lesc_request_handler(); APP_ERROR_CHECK(err_code); app_sched_execute(); if (NRF_LOG_PROCESS() == false) { nrf_pwr_mgmt_run(); } }
However, when the program is loaded on the target board, it always runs into a hard fault during bebug. The biggest difference with these examples is that I have used the App scheduler. The reason I use App scheduler is that a hardware interrupt takes quite some time to process. I don't want it to cause any issue to the soft device.
Is app scheduler not able to use with LESC? Any suggestions for me to modify / debug the code?
Thank you!
----------------
Hi there,
I did further investigation by modifying the Glucose Monitor example. Below is what I did to check if app scheduler can be used.
1. Add #include "app_scheduler.h"
2. Add below code
void check_if_put_bmr_to_sleep_seh(void *p_ev_data, uint16_t ev_size) { NRF_LOG_INFO("Reached 30 seconds! Reset clock counter to ZERO!"); } /**@brief Function to check if bmr should be put to sleep * * @details if m_clock_cnt >= 30; reset m_clock_cnt = 0; */ void check_if_put_bmr_to_sleep() { ret_code_t err_code; if (m_clock_cnt >= 30) { m_clock_cnt = 0; err_code = app_sched_event_put(0,0,check_if_put_bmr_to_sleep_seh); APP_ERROR_CHECK(err_code); } } /**@brief Function for the 1 second clock emulation. * * @details Run every 1 second, post status, determine ultra low power shutdown, determine timeout shutdown during operations */ void clock_em_eh(void *p_context) { UNUSED_PARAMETER(p_context); m_clock_cnt++; check_if_put_bmr_to_sleep(); } /**@brief Function for starting application timers. */ static void application_timers_start(void) { ret_code_t err_code; // Start application timers. err_code = app_timer_start(m_battery_timer_id, BATTERY_LEVEL_MEAS_INTERVAL, NULL); APP_ERROR_CHECK(err_code); // Start clock emulation timer err_code = app_timer_start(clock_em_tid, APP_TIMER_TICKS(1000), NULL); m_clock_cnt = 0; APP_ERROR_CHECK(err_code); }
3. After I started debugging in SES, I got the DH_key and had completed the connection. However, once the "app_sched_event_put(0,0,check_if_put_bmr_to_sleep_seh)" was executed the hardfault error (timer_expire) came out.
4. Does it imply that the app scheduler cannot be used with the lesc request handler?
5. In my project, I am using fstorage library to save 2 pages of data to flash upon completion of certain operations. Currently, I put the "save flash" operation in a function in the app scheduler queue. I also have an interrupt routine which may take up to 100 milliseconds to complete in the app scheduler queue. If the app scheduler cannot be used with lesc, and if I want to stay using nRF SDK, is there any good way to achieve it?
Thank you!