2021-11-04 17:26:41 +00:00
|
|
|
#include "bt_keys_storage.h"
|
2022-04-21 15:36:53 +00:00
|
|
|
|
2021-11-04 17:26:41 +00:00
|
|
|
#include <furi.h>
|
2022-04-21 15:36:53 +00:00
|
|
|
#include <lib/toolbox/saved_struct.h>
|
2022-07-26 12:21:51 +00:00
|
|
|
#include <storage/storage.h>
|
2021-11-04 17:26:41 +00:00
|
|
|
|
2022-07-26 12:21:51 +00:00
|
|
|
#define BT_KEYS_STORAGE_PATH INT_PATH(BT_KEYS_STORAGE_FILE_NAME)
|
2022-04-21 15:36:53 +00:00
|
|
|
#define BT_KEYS_STORAGE_VERSION (0)
|
|
|
|
#define BT_KEYS_STORAGE_MAGIC (0x18)
|
2021-11-04 17:26:41 +00:00
|
|
|
|
2022-04-21 15:36:53 +00:00
|
|
|
bool bt_keys_storage_load(Bt* bt) {
|
2021-11-04 17:26:41 +00:00
|
|
|
furi_assert(bt);
|
|
|
|
bool file_loaded = false;
|
2022-04-21 15:36:53 +00:00
|
|
|
|
2021-11-04 17:26:41 +00:00
|
|
|
furi_hal_bt_get_key_storage_buff(&bt->bt_keys_addr_start, &bt->bt_keys_size);
|
2022-04-21 15:36:53 +00:00
|
|
|
furi_hal_bt_nvm_sram_sem_acquire();
|
|
|
|
file_loaded = saved_struct_load(
|
|
|
|
BT_KEYS_STORAGE_PATH,
|
|
|
|
bt->bt_keys_addr_start,
|
|
|
|
bt->bt_keys_size,
|
|
|
|
BT_KEYS_STORAGE_MAGIC,
|
|
|
|
BT_KEYS_STORAGE_VERSION);
|
|
|
|
furi_hal_bt_nvm_sram_sem_release();
|
2021-11-04 17:26:41 +00:00
|
|
|
|
|
|
|
return file_loaded;
|
|
|
|
}
|
|
|
|
|
2022-04-21 15:36:53 +00:00
|
|
|
bool bt_keys_storage_save(Bt* bt) {
|
2021-11-04 17:26:41 +00:00
|
|
|
furi_assert(bt);
|
|
|
|
furi_assert(bt->bt_keys_addr_start);
|
|
|
|
bool file_saved = false;
|
2022-04-21 15:36:53 +00:00
|
|
|
|
|
|
|
furi_hal_bt_nvm_sram_sem_acquire();
|
|
|
|
file_saved = saved_struct_save(
|
|
|
|
BT_KEYS_STORAGE_PATH,
|
|
|
|
bt->bt_keys_addr_start,
|
|
|
|
bt->bt_keys_size,
|
|
|
|
BT_KEYS_STORAGE_MAGIC,
|
|
|
|
BT_KEYS_STORAGE_VERSION);
|
|
|
|
furi_hal_bt_nvm_sram_sem_release();
|
|
|
|
|
2021-11-04 17:26:41 +00:00
|
|
|
return file_saved;
|
|
|
|
}
|
2022-01-21 17:32:03 +00:00
|
|
|
|
2022-04-21 15:36:53 +00:00
|
|
|
bool bt_keys_storage_delete(Bt* bt) {
|
2022-01-21 17:32:03 +00:00
|
|
|
furi_assert(bt);
|
|
|
|
bool delete_succeed = false;
|
2022-02-07 13:37:56 +00:00
|
|
|
bool bt_is_active = furi_hal_bt_is_active();
|
2022-01-21 17:32:03 +00:00
|
|
|
|
|
|
|
furi_hal_bt_stop_advertising();
|
|
|
|
delete_succeed = furi_hal_bt_clear_white_list();
|
2022-02-07 13:37:56 +00:00
|
|
|
if(bt_is_active) {
|
2022-01-21 17:32:03 +00:00
|
|
|
furi_hal_bt_start_advertising();
|
|
|
|
}
|
|
|
|
|
|
|
|
return delete_succeed;
|
|
|
|
}
|