static void gap_params_init(void)
{
uint32_t err_code;
ble_gap_conn_params_t gap_conn_params;
ble_gap_conn_sec_mode_t sec_mode;
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode);
char name[50] = {0};
uint16_t name_len = 0;
memset(name, 0 , sizeof(name));
name_len = 0;
memcpy(&name[name_len],(uint8_t *)MANUFACTURER_VER,strlen(MANUFACTURER_VER));
name_len += strlen(MANUFACTURER_VER);
name[name_len] = '-';
name_len += 1;
memcpy(&name[name_len],(const uint8_t *)DEVICE_NAME,strlen(DEVICE_NAME));
name_len += strlen(DEVICE_NAME);
memcpy(&name[name_len],(const uint8_t *)FIRMWARE_VER,strlen(FIRMWARE_VER));
name_len += strlen(FIRMWARE_VER);
if(name_len >= sizeof(name)) name_len = sizeof(name);
err_code = sd_ble_gap_device_name_set(&sec_mode,
(const uint8_t *) name,
name_len);
// err_code = sd_ble_gap_device_name_set(&sec_mode,
// (const uint8_t *) DEVICE_NAME,
// strlen(DEVICE_NAME));
APP_ERROR_CHECK(err_code);
memset(&gap_conn_params, 0, sizeof(gap_conn_params));
gap_conn_params.min_conn_interval = MIN_CONN_INTERVAL;
gap_conn_params.max_conn_interval = MAX_CONN_INTERVAL;
gap_conn_params.slave_latency = SLAVE_LATENCY;
gap_conn_params.conn_sup_timeout = CONN_SUP_TIMEOUT;
err_code = sd_ble_gap_ppcp_set(&gap_conn_params);
APP_ERROR_CHECK(err_code);
//==========================================================
#ifdef MITM_PROTECT_SUPPORT
uint8_t passkey[]="123456";
m_static_pin_option.gap_opt.passkey.p_passkey = passkey;
err_code = sd_ble_opt_set(BLE_GAP_OPT_PASSKEY, &m_static_pin_option);
APP_ERROR_CHECK(err_code);
#endif
}SDK14.0+NRF52832: firstly I init the passkey in the function gap_params_init as above.I want to change the passkey and can save the new passkey to flash, but when I input one new passkey and call the function sd_ble_opt_set again, error occurs(err_code=7).
void update_secon_code(uint8_t new_passkey[])
{
uint32_t err_code = NRF_SUCCESS;
m_static_pin_option.gap_opt.passkey.p_passkey = new_passkey;
err_code = sd_ble_opt_set(BLE_GAP_OPT_PASSKEY, &m_static_pin_option);
NRF_LOG_PRINTF("update_secon_code:err=%x\n", err_code); //return err_code=7
APP_ERROR_CHECK(err_code);
}
My question is how to change the passkey?