Hello all,
Currently I´m developing a code to be load to the SDK to act as a master in a BLE communication. The peripheral is a BLE thermoter that, in order to preform bonding, displays a random pin to be entered. When the event BLE_GAP_EVT_AUTH_KEY_REQUEST happens, I rise a flag that stops the infinite loop in the main and receive the passkey via UART. Using the function sd_ble_gap_auth_key_reply, I send the corresponding pin and then the bond should be established. However, nothing happens and I get the following errors:
<info> app: Error code: 3002
<info> peer_manager_handler: Connection security failed: role: Central, conn_handle: 0x0, procedure: Bonding, error: 1
<debug> app: PM_EVT_CONN_SEC_FAILED
<info> app: BLE_GAP_EVT_AUTH_STATUS: status=0x1 bond=0x0 lv4: 0 kdist_own:0x0 kdist_peer:0x0
<info> app: Disconnected, reason 0x13.
I am attaching the main of the code so you can take a better look
int main(void)
{
bool erase_bonds;
uint8_t i = 0;
uint8_t therm_passkey [6] = {};
// Initialize.
log_init();
uart_init();
timer_init();
power_management_init();
buttons_leds_init(&erase_bonds);
ble_stack_init();
gatt_init();
peer_manager_init();
db_discovery_init();
hrs_c_init();
bas_c_init();
hts_c_init();
scan_init();
pairing_init(&m_scan);
// Start execution.
NRF_LOG_INFO("Health Thermometer collector example started.\n");
scanning_start(&erase_bonds);
// Enter main loop.
for (;;)
{
/* This part of the code will be called once the event: "BLE_GAP_EVT_AUTH_KEY_REQUEST" is triggered. */
if(f_pin)
{
uint32_t err_code;
uint8_t cr;
while (app_uart_get(&cr) != NRF_SUCCESS);
while (app_uart_put(cr) != NRF_SUCCESS);
if (cr == '\r' || cr == '\n')
{
printf("PASSWORD %.6s \n",(char *) therm_passkey);
f_pin = false;
err_code = sd_ble_gap_auth_key_reply(g_p_ble_evt->evt.gap_evt.conn_handle,BLE_GAP_AUTH_KEY_TYPE_PASSKEY,therm_passkey);
NRF_LOG_INFO("Error code: %x", err_code);
i = 0;
continue;
}
therm_passkey[i++] = cr;
}
idle_state_handle();
}
}