unleashed-firmware/applications/bt/bt_service/bt_keys_storage.c
あく 389ff92cc1
Naming and coding style convention, new linter tool. (#945)
* Makefile, Scripts: new linter
* About: remove ID from IC
* Firmware: remove double define for DIVC/DIVR
* Scripts: check folder names too. Docker: replace syntax check with make lint.
* Reformat Sources and Migrate to new file naming convention
* Docker: symlink clang-format-12 to clang-format
* Add coding style guide
2022-01-05 19:10:18 +03:00

41 lines
1.3 KiB
C

#include "bt_keys_storage.h"
#include <furi.h>
#include <file_worker.h>
#define BT_KEYS_STORAGE_TAG "bt keys storage"
#define BT_KEYS_STORAGE_PATH "/int/bt.keys"
bool bt_load_key_storage(Bt* bt) {
furi_assert(bt);
bool file_loaded = false;
furi_hal_bt_get_key_storage_buff(&bt->bt_keys_addr_start, &bt->bt_keys_size);
FileWorker* file_worker = file_worker_alloc(true);
if(file_worker_open(file_worker, BT_KEYS_STORAGE_PATH, FSAM_READ, FSOM_OPEN_EXISTING)) {
furi_hal_bt_nvm_sram_sem_acquire();
if(file_worker_read(file_worker, bt->bt_keys_addr_start, bt->bt_keys_size)) {
file_loaded = true;
}
furi_hal_bt_nvm_sram_sem_release();
}
file_worker_free(file_worker);
return file_loaded;
}
bool bt_save_key_storage(Bt* bt) {
furi_assert(bt);
furi_assert(bt->bt_keys_addr_start);
bool file_saved = false;
FileWorker* file_worker = file_worker_alloc(true);
if(file_worker_open(file_worker, BT_KEYS_STORAGE_PATH, FSAM_WRITE, FSOM_OPEN_ALWAYS)) {
furi_hal_bt_nvm_sram_sem_acquire();
if(file_worker_write(file_worker, bt->bt_keys_addr_start, bt->bt_keys_size)) {
file_saved = true;
}
furi_hal_bt_nvm_sram_sem_release();
}
file_worker_free(file_worker);
return file_saved;
}