I am attempting to change the passkey used in BLE Pairing/Bonding. In this case, I am using legacy pairing/bonding.
My idea is to have the central provide the passkey to the peripheral at runtime, using an unencrypted BLE service.
I would like the peripheral to read this characteristic, change it's passkey, and then set the key store with this passkey. The central would then provide this 6 digit key to the user to pair/bond. All other characteristics remain encrypted.
I am running into issues executing this idea however.
My code returns with a NRF_ERROR_INVALID_STATE. I am attempting to set the passkey during the BLE_GAP_EVT_PASSKEY_DISPLAY event.
This occurs when attempting to connect to an encrypted service/characteristic and hitting the following code:
case BLE_GAP_EVT_PASSKEY_DISPLAY: { uint8_t passkey[6] = "234567"; // Reply with an authentication key. // m_static_pin_option.gap_opt.passkey.p_passkey = passkey; // err_code = sd_ble_opt_set(BLE_GAP_OPT_PASSKEY, &m_static_pin_option); err_code = sd_ble_gap_auth_key_reply(p_ble_evt->evt.gap_evt.conn_handle, BLE_GAP_AUTH_KEY_TYPE_PASSKEY, (uint8_t *) passkey); APP_ERROR_CHECK(err_code); char passkey2[7]; memcpy(passkey2, p_ble_evt->evt.gap_evt.params.passkey_display.passkey, 6); passkey2[6] = 0; NRF_LOG_INFO("Passkey: %s", nrf_log_push(passkey2)); } break;
There is similar code provided here which sets the key during
devzone.nordicsemi.com/.../216040