uint32_t ble_bondmngr_bonded_masters_delete(void) { VERIFY_MODULE_INITIALIZED(); m_masters_in_db_count = 0; m_bond_info_in_flash_count = 0; m_sys_attr_in_flash_count = 0; return flash_pages_erase(); }
uint32_t ble_bondmngr_bonded_masters_delete(void) { if (!m_is_bondmngr_initialized) { return NRF_ERROR_INVALID_STATE; } m_masters_in_db_count = 0; m_bond_info_in_flash_count = 0; m_sys_attr_in_flash_count = 0; return flash_pages_erase(); }
uint32_t ble_bondmngr_init(ble_bondmngr_init_t * p_init) { uint32_t err_code; if (p_init->error_handler == NULL) { return NRF_ERROR_INVALID_PARAM; } if (BLE_BONDMNGR_MAX_BONDED_MASTERS > MAX_BONDS_IN_FLASH) { return NRF_ERROR_DATA_SIZE; } m_bondmngr_config = *p_init; memset(&m_master, 0, sizeof(master_t)); m_master.bond.master_handle = INVALID_MASTER_HANDLE; m_conn_handle = BLE_CONN_HANDLE_INVALID; m_masters_in_db_count = 0; m_bond_info_in_flash_count = 0; m_sys_attr_in_flash_count = 0; SECURITY_STATUS_RESET(); // Erase all stored masters if specified. if (m_bondmngr_config.bonds_delete) { err_code = flash_pages_erase(); if (err_code != NRF_SUCCESS) { return err_code; } } // Load bond manager data from flash. err_code = load_all_from_flash(); if (err_code != NRF_SUCCESS) { return err_code; } m_is_bondmngr_initialized = true; return NRF_SUCCESS; }
uint32_t ble_bondmngr_bonded_master_delete(uint16_t master_id) { if (!m_is_bondmngr_initialized) { return NRF_ERROR_INVALID_STATE; } int8_t master_handle_to_be_deleted = INVALID_MASTER_HANDLE; uint8_t i; // Search for the handle of the master. for (i = 0; i < m_masters_in_db_count; i++) { if (m_masters_db[i].bond.master_id_info.div == master_id) { master_handle_to_be_deleted = i; break; } } if (master_handle_to_be_deleted == INVALID_MASTER_HANDLE) { // Master ID not found. return NRF_ERROR_NOT_FOUND; } // Delete the master in RAM. for (i = master_handle_to_be_deleted; i < (m_masters_in_db_count - 1); i++) { // Overwrite the current master entry with the next one. m_masters_db[i] = m_masters_db[i + 1]; // Decrement the value of handle. m_masters_db[i].bond.master_handle--; m_masters_db[i].sys_attr.master_handle--; } // Clear the last database entry. memset(&(m_masters_db[m_masters_in_db_count - 1]), 0, sizeof(master_t)); m_masters_in_db_count--; uint32_t err_code; // Reinitialize the pointers to the memory where bonding info and System Attributes are stored // in flash. err_code = ble_flash_page_addr(m_bondmngr_config.flash_page_num_bond, &mp_flash_bond_info); if (err_code != NRF_SUCCESS) { return err_code; } err_code = ble_flash_page_addr(m_bondmngr_config.flash_page_num_sys_attr, &mp_flash_sys_attr); if (err_code != NRF_SUCCESS) { return err_code; } // Refresh the data in the flash memory (both Bonding Information and System Attributes). // Erase and rewrite bonding info and System Attributes. err_code = flash_pages_erase(); if (err_code != NRF_SUCCESS) { return err_code; } m_bond_info_in_flash_count = 0; m_sys_attr_in_flash_count = 0; for (i = 0; i < m_masters_in_db_count; i++) { err_code = bond_info_store(&(m_masters_db[i].bond)); if (err_code != NRF_SUCCESS) { return err_code; } } for (i = 0; i < m_masters_in_db_count; i++) { err_code = sys_attr_store(&(m_masters_db[i].sys_attr)); if (err_code != NRF_SUCCESS) { return err_code; } } update_whitelist(); return NRF_SUCCESS; }