Hello,
I try to add to my project the bond functionality based on the glucose demo app. I added ble_bongmngr.c , pstorage.c to my project, initialize it...
When i try to bond from Master Control panel, it disconnect with this message: [17:27:07.0] BondToDevice() [17:27:10.1] Lost connection to device. Reason: BTLE_CONNECTION_TIMEOUT [17:27:10.1] SERVER: Received packet <HciEvent: eventCode=0x0A> - <HciEvent: eventCode=0x0A> [17:27:10.1] SERVER: Received Link Loss [17:27:10.1] Error: No connection
in main.c
static void ble_evt_dispatch(ble_evt_t * p_ble_evt)
{
ble_bondmngr_on_ble_evt(p_ble_evt);
ble_gls_on_ble_evt(&m_gls, p_ble_evt);
ble_bas_on_ble_evt(&m_bas, p_ble_evt);
ble_conn_params_on_ble_evt(p_ble_evt);
on_ble_evt(p_ble_evt);
}
static void bond_manager_init(void)
{
uint32_t err_code;
ble_bondmngr_init_t bond_init_data;
bool bonds_delete;
// Initialize persistent storage module.
err_code = pstorage_init();
APP_ERROR_CHECK(err_code);
// Clear all bonded centrals if the Bonds Delete button is pushed.
// err_code = app_button_is_pushed(BONDMNGR_DELETE_BUTTON_PIN_NO, &bonds_delete);
//APP_ERROR_CHECK(err_code);
bonds_delete = true ;
// Initialize the Bond Manager.
bond_init_data.flash_page_num_bond = FLASH_PAGE_BOND;
bond_init_data.flash_page_num_sys_attr = FLASH_PAGE_SYS_ATTR;
bond_init_data.evt_handler = NULL;
bond_init_data.error_handler = bond_manager_error_handler;
bond_init_data.bonds_delete = bonds_delete;
err_code = ble_bondmngr_init(&bond_init_data);
APP_ERROR_CHECK(err_code);
}
static void on_ble_evt(ble_evt_t * p_ble_evt)
{
uint32_t err_code = NRF_SUCCESS;
static ble_gap_evt_auth_status_t m_auth_status;
ble_gap_enc_info_t * p_enc_info;
switch (p_ble_evt->header.evt_id)
{
case BLE_GAP_EVT_CONNECTED:
//nrf_gpio_pin_set(CONNECTED_LED_PIN_NO);
//nrf_gpio_pin_clear(ADVERTISING_LED_PIN_NO);
m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
err_code = app_button_enable();
break;
case BLE_GAP_EVT_DISCONNECTED:
//nrf_gpio_pin_clear(CONNECTED_LED_PIN_NO);
m_conn_handle = BLE_CONN_HANDLE_INVALID;
// Since we are not in a connection and have not started advertising, store bonds.
err_code = ble_bondmngr_bonded_centrals_store();
APP_ERROR_CHECK(err_code);
advertising_start();
break;
case BLE_GAP_EVT_SEC_PARAMS_REQUEST:
// If the display is not available, do not use MITM.
m_sec_params.mitm = 0;
m_sec_params.io_caps = BLE_GAP_IO_CAPS_NONE;
err_code = sd_ble_gap_sec_params_reply(m_conn_handle,
BLE_GAP_SEC_STATUS_SUCCESS,
&m_sec_params);
APP_ERROR_CHECK(err_code);
break;
case BLE_GATTS_EVT_SYS_ATTR_MISSING:
err_code = sd_ble_gatts_sys_attr_set(m_conn_handle, NULL, 0);
break;
case BLE_GAP_EVT_AUTH_STATUS:
//m_auth_status = p_ble_evt->evt.gap_evt.params.auth_status;
//break;
case BLE_GAP_EVT_SEC_INFO_REQUEST:
p_enc_info = &m_auth_status.periph_keys.enc_info;
if (p_enc_info->div == p_ble_evt->evt.gap_evt.params.sec_info_request.div)
{
err_code = sd_ble_gap_sec_info_reply(m_conn_handle, p_enc_info, NULL);
}
else
{
// No keys found for this device
err_code = sd_ble_gap_sec_info_reply(m_conn_handle, NULL, NULL);
}
break;
case BLE_GAP_EVT_TIMEOUT:
if (p_ble_evt->evt.gap_evt.params.timeout.src == BLE_GAP_TIMEOUT_SRC_ADVERTISEMENT)
{
//nrf_gpio_pin_clear(ADVERTISING_LED_PIN_NO);
// Go to system-off mode (this function will not return; wakeup will cause a reset)
err_code = sd_power_system_off();
APP_ERROR_CHECK(err_code);
// err_code = sd_power_system_off();
}
break;
case BLE_GAP_EVT_RSSI_CHANGED:
//err_code = app_fifo_put(&rssi_fifo, p_ble_evt->evt.gap_evt.params.rssi_changed.rssi);
//if ( err_code == NRF_ERROR_NO_MEM){
rssi_check(p_ble_evt->evt.gap_evt.params.rssi_changed.rssi);
//}
break;
case BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST:
{
uint8_t test_buffer[20];
ble_gatts_rw_authorize_reply_params_t reply;
memset(&reply, 0, sizeof(ble_gatts_rw_authorize_reply_params_t));
reply.type = BLE_GATTS_AUTHORIZE_TYPE_WRITE;
for(uint8_t i = 0 ; i < p_ble_evt->evt.gatts_evt.params.authorize_request.request.write.len; i++)
test_buffer[i] = p_ble_evt->evt.gatts_evt.params.authorize_request.request.write.data[i];
// This is a test function. Master will get this error when first byte is not 0x12.
if (test_buffer[0] != 0x12)
reply.params.write.gatt_status = BLE_GATT_STATUS_ATTERR_WRITE_NOT_PERMITTED;
err_code = sd_ble_gatts_rw_authorize_reply(p_ble_evt->evt.gap_evt.conn_handle, &reply);
}
default:
break;
}
APP_ERROR_CHECK(err_code);
}
Did I forget something?