2022-01-05 16:10:18 +00:00
|
|
|
#include "lfrfid_app.h"
|
2022-05-27 11:19:21 +00:00
|
|
|
#include "assets_icons.h"
|
2022-07-20 10:56:33 +00:00
|
|
|
#include <core/common_defines.h>
|
2022-05-27 11:19:21 +00:00
|
|
|
#include "m-string.h"
|
2022-01-05 16:10:18 +00:00
|
|
|
#include "scene/lfrfid_app_scene_start.h"
|
|
|
|
#include "scene/lfrfid_app_scene_read.h"
|
|
|
|
#include "scene/lfrfid_app_scene_read_success.h"
|
2022-04-14 12:03:47 +00:00
|
|
|
#include "scene/lfrfid_app_scene_retry_confirm.h"
|
|
|
|
#include "scene/lfrfid_app_scene_exit_confirm.h"
|
|
|
|
#include "scene/lfrfid_app_scene_read_menu.h"
|
2022-01-05 16:10:18 +00:00
|
|
|
#include "scene/lfrfid_app_scene_write.h"
|
|
|
|
#include "scene/lfrfid_app_scene_write_success.h"
|
|
|
|
#include "scene/lfrfid_app_scene_emulate.h"
|
|
|
|
#include "scene/lfrfid_app_scene_save_name.h"
|
|
|
|
#include "scene/lfrfid_app_scene_save_success.h"
|
|
|
|
#include "scene/lfrfid_app_scene_select_key.h"
|
|
|
|
#include "scene/lfrfid_app_scene_saved_key_menu.h"
|
|
|
|
#include "scene/lfrfid_app_scene_save_data.h"
|
|
|
|
#include "scene/lfrfid_app_scene_save_type.h"
|
|
|
|
#include "scene/lfrfid_app_scene_saved_info.h"
|
|
|
|
#include "scene/lfrfid_app_scene_delete_confirm.h"
|
|
|
|
#include "scene/lfrfid_app_scene_delete_success.h"
|
2022-07-04 13:09:46 +00:00
|
|
|
#include "scene/lfrfid_app_scene_rpc.h"
|
2021-06-30 12:02:46 +00:00
|
|
|
|
2021-11-04 10:06:13 +00:00
|
|
|
#include <toolbox/path.h>
|
2022-02-18 19:53:46 +00:00
|
|
|
#include <flipper_format/flipper_format.h>
|
2021-06-30 12:02:46 +00:00
|
|
|
|
2022-08-02 12:54:12 +00:00
|
|
|
#include <rpc/rpc_app.h>
|
2022-07-04 13:09:46 +00:00
|
|
|
|
2022-07-26 12:21:51 +00:00
|
|
|
const char* LfRfidApp::app_folder = ANY_PATH("lfrfid");
|
2021-06-30 12:02:46 +00:00
|
|
|
const char* LfRfidApp::app_extension = ".rfid";
|
2021-10-06 09:40:28 +00:00
|
|
|
const char* LfRfidApp::app_filetype = "Flipper RFID key";
|
2021-06-28 14:42:30 +00:00
|
|
|
|
|
|
|
LfRfidApp::LfRfidApp()
|
|
|
|
: scene_controller{this}
|
|
|
|
, notification{"notification"}
|
2021-10-06 09:40:28 +00:00
|
|
|
, storage{"storage"}
|
|
|
|
, dialogs{"dialogs"}
|
2021-06-28 14:42:30 +00:00
|
|
|
, text_store(40) {
|
2022-05-27 11:19:21 +00:00
|
|
|
string_init_set_str(file_path, app_folder);
|
2021-06-28 14:42:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
LfRfidApp::~LfRfidApp() {
|
2022-05-27 11:19:21 +00:00
|
|
|
string_clear(file_path);
|
2022-07-04 13:09:46 +00:00
|
|
|
if(rpc_ctx) {
|
|
|
|
rpc_system_app_set_callback(rpc_ctx, NULL, NULL);
|
2022-07-25 14:16:45 +00:00
|
|
|
rpc_system_app_send_exited(rpc_ctx);
|
2022-07-04 13:09:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-02 12:54:12 +00:00
|
|
|
static void rpc_command_callback(RpcAppSystemEvent rpc_event, void* context) {
|
2022-07-04 13:09:46 +00:00
|
|
|
furi_assert(context);
|
|
|
|
LfRfidApp* app = static_cast<LfRfidApp*>(context);
|
|
|
|
|
2022-08-02 12:54:12 +00:00
|
|
|
if(rpc_event == RpcAppEventSessionClose) {
|
2022-07-04 13:09:46 +00:00
|
|
|
LfRfidApp::Event event;
|
2022-08-02 12:54:12 +00:00
|
|
|
event.type = LfRfidApp::EventType::RpcSessionClose;
|
2022-07-04 13:09:46 +00:00
|
|
|
app->view_controller.send_event(&event);
|
2022-08-02 12:54:12 +00:00
|
|
|
} else if(rpc_event == RpcAppEventAppExit) {
|
2022-07-04 13:09:46 +00:00
|
|
|
LfRfidApp::Event event;
|
|
|
|
event.type = LfRfidApp::EventType::Exit;
|
|
|
|
app->view_controller.send_event(&event);
|
2022-08-02 12:54:12 +00:00
|
|
|
} else if(rpc_event == RpcAppEventLoadFile) {
|
|
|
|
LfRfidApp::Event event;
|
|
|
|
event.type = LfRfidApp::EventType::RpcLoadFile;
|
|
|
|
app->view_controller.send_event(&event);
|
|
|
|
} else {
|
|
|
|
rpc_system_app_confirm(app->rpc_ctx, rpc_event, false);
|
2022-07-04 13:09:46 +00:00
|
|
|
}
|
2021-06-28 14:42:30 +00:00
|
|
|
}
|
|
|
|
|
2021-06-30 12:02:46 +00:00
|
|
|
void LfRfidApp::run(void* _args) {
|
|
|
|
const char* args = reinterpret_cast<const char*>(_args);
|
|
|
|
|
[FL-1191][FL-1524] Filesystem rework (#568)
* FS-Api: removed datetime manipulation functions and most of the file flags
* Filesystem: common proxy api
* Filesystem: renamed to Storage. Work has begun on a glue layer. Added functions for reentrance.
* Storage: sd mount and sd file open
* Storage: sd file close
* Storage: temporary test app
* Storage: free filedata on close
* Storage: sd file read and write
* Storage: added internal storage (LittleFS)
* Storage: renamed internal commands
* Storage: seek, tell, truncate, size, sync, eof
* Storage: error descriptions
* Storage: directory management api (open, close, read, rewind)
* Storage: common management api (stat, fs_stat, remove, rename, mkdir)
* Dolphin app and Notifications app now use raw storage.
* Storage: storage statuses renamed. Implemented sd card icon.
* Storage: added raw sd-card api.
* Storage settings: work started
* Assets: use new icons approach
* Storage settings: working storage settings
* Storage: completely redesigned api, no longer sticking out FS_Api
* Storage: more simplified api, getting error_id from file is hidden from user, pointer to api is hidden inside file
* Storage: cli info and format commands
* Storage-cli: file list
* Storage: a simpler and more reliable api
* FatFS: slightly lighter and faster config. Also disabled reentrancy and file locking functions. They moved to a storage service.
* Storage-cli: accommodate to the new cli api.
* Storage: filesystem api is separated into internal and common api.
* Cli: added the ability to print the list of free heap blocks
* Storage: uses a list instead of an array to store the StorageFile. Rewrote api calls to use semaphores instead of thread flags.
* Storage settings: added the ability to benchmark the SD card.
* Gui module file select: uses new storage api
* Apps: removed deprecated sd_card_test application
* Args lib: support for enquoted arguments
* Dialogs: a new gui app for simple non-asynchronous apps
* Dialogs: view holder for easy single view work
* File worker: use new storage api
* IButton and lfrrfid apps: save keys to any storage
* Apps: fix ibutton and lfrfid stack, remove sd_card_test.
* SD filesystem: app removed
* File worker: fixed api pointer type
* Subghz: loading assets using the new storage api
* NFC: use the new storage api
* Dialogs: the better api for the message element
* Archive: use new storage api
* Irda: changed assest path, changed app path
* FileWorker: removed unused file_buf_cnt
* Storage: copying and renaming files now works between storages
* Storage cli: read, copy, remove, rename commands
* Archive: removed commented code
* Storage cli: write command
* Applications: add SRV_STORAGE and SRV_DIALOGS
* Internal-storage: removed
* Storage: improved api
* Storage app: changed api pointer from StorageApp to Storage
* Storage: better file_id handling
* Storage: more consistent errors
* Loader: support for NULL icons
* Storage: do nothing with the lfs file or directory if it is not open
* Storage: fix typo
* Storage: minor float usage cleanup, rename some symbols.
* Storage: compact doxygen comments.
Co-authored-by: あく <alleteam@gmail.com>
2021-07-23 12:20:19 +00:00
|
|
|
make_app_folder();
|
|
|
|
|
2022-08-03 15:47:10 +00:00
|
|
|
if(args && strlen(args)) {
|
2022-07-04 13:09:46 +00:00
|
|
|
uint32_t rpc_ctx_ptr = 0;
|
|
|
|
if(sscanf(args, "RPC %lX", &rpc_ctx_ptr) == 1) {
|
|
|
|
rpc_ctx = (RpcAppSystem*)rpc_ctx_ptr;
|
|
|
|
rpc_system_app_set_callback(rpc_ctx, rpc_command_callback, this);
|
2022-07-25 14:16:45 +00:00
|
|
|
rpc_system_app_send_started(rpc_ctx);
|
2022-07-04 13:09:46 +00:00
|
|
|
scene_controller.add_scene(SceneType::Rpc, new LfRfidAppSceneRpc());
|
|
|
|
scene_controller.process(100, SceneType::Rpc);
|
|
|
|
} else {
|
|
|
|
string_set_str(file_path, args);
|
|
|
|
load_key_data(file_path, &worker.key, true);
|
|
|
|
scene_controller.add_scene(SceneType::Emulate, new LfRfidAppSceneEmulate());
|
|
|
|
scene_controller.process(100, SceneType::Emulate);
|
|
|
|
}
|
|
|
|
|
2021-06-30 12:02:46 +00:00
|
|
|
} else {
|
|
|
|
scene_controller.add_scene(SceneType::Start, new LfRfidAppSceneStart());
|
|
|
|
scene_controller.add_scene(SceneType::Read, new LfRfidAppSceneRead());
|
2022-04-14 12:03:47 +00:00
|
|
|
scene_controller.add_scene(SceneType::RetryConfirm, new LfRfidAppSceneRetryConfirm());
|
|
|
|
scene_controller.add_scene(SceneType::ExitConfirm, new LfRfidAppSceneExitConfirm());
|
2021-06-30 12:02:46 +00:00
|
|
|
scene_controller.add_scene(SceneType::ReadSuccess, new LfRfidAppSceneReadSuccess());
|
2022-04-14 12:03:47 +00:00
|
|
|
scene_controller.add_scene(SceneType::ReadKeyMenu, new LfRfidAppSceneReadKeyMenu());
|
2021-06-30 12:02:46 +00:00
|
|
|
scene_controller.add_scene(SceneType::Write, new LfRfidAppSceneWrite());
|
|
|
|
scene_controller.add_scene(SceneType::WriteSuccess, new LfRfidAppSceneWriteSuccess());
|
|
|
|
scene_controller.add_scene(SceneType::Emulate, new LfRfidAppSceneEmulate());
|
|
|
|
scene_controller.add_scene(SceneType::SaveName, new LfRfidAppSceneSaveName());
|
|
|
|
scene_controller.add_scene(SceneType::SaveSuccess, new LfRfidAppSceneSaveSuccess());
|
|
|
|
scene_controller.add_scene(SceneType::SelectKey, new LfRfidAppSceneSelectKey());
|
|
|
|
scene_controller.add_scene(SceneType::SavedKeyMenu, new LfRfidAppSceneSavedKeyMenu());
|
|
|
|
scene_controller.add_scene(SceneType::SaveData, new LfRfidAppSceneSaveData());
|
|
|
|
scene_controller.add_scene(SceneType::SaveType, new LfRfidAppSceneSaveType());
|
|
|
|
scene_controller.add_scene(SceneType::SavedInfo, new LfRfidAppSceneSavedInfo());
|
|
|
|
scene_controller.add_scene(SceneType::DeleteConfirm, new LfRfidAppSceneDeleteConfirm());
|
|
|
|
scene_controller.add_scene(SceneType::DeleteSuccess, new LfRfidAppSceneDeleteSuccess());
|
|
|
|
scene_controller.process(100);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LfRfidApp::save_key(RfidKey* key) {
|
|
|
|
bool result = false;
|
|
|
|
|
|
|
|
make_app_folder();
|
|
|
|
|
2022-05-27 11:19:21 +00:00
|
|
|
if(string_end_with_str_p(file_path, app_extension)) {
|
|
|
|
size_t filename_start = string_search_rchar(file_path, '/');
|
|
|
|
string_left(file_path, filename_start);
|
|
|
|
}
|
|
|
|
|
|
|
|
string_cat_printf(file_path, "/%s%s", key->get_name(), app_extension);
|
2021-06-30 12:02:46 +00:00
|
|
|
|
2022-05-27 11:19:21 +00:00
|
|
|
result = save_key_data(file_path, key);
|
2021-06-30 12:02:46 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LfRfidApp::load_key_from_file_select(bool need_restore) {
|
2022-05-27 11:19:21 +00:00
|
|
|
if(!need_restore) {
|
|
|
|
string_set_str(file_path, app_folder);
|
2021-06-30 12:02:46 +00:00
|
|
|
}
|
|
|
|
|
2022-05-27 11:19:21 +00:00
|
|
|
bool result = dialog_file_browser_show(
|
|
|
|
dialogs, file_path, file_path, app_extension, true, &I_125_10px, true);
|
|
|
|
|
2021-06-30 12:02:46 +00:00
|
|
|
if(result) {
|
2022-07-04 13:09:46 +00:00
|
|
|
result = load_key_data(file_path, &worker.key, true);
|
2021-06-30 12:02:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LfRfidApp::delete_key(RfidKey* key) {
|
2022-05-27 11:19:21 +00:00
|
|
|
UNUSED(key);
|
|
|
|
return storage_simply_remove(storage, string_get_cstr(file_path));
|
2021-06-30 12:02:46 +00:00
|
|
|
}
|
|
|
|
|
2022-07-04 13:09:46 +00:00
|
|
|
bool LfRfidApp::load_key_data(string_t path, RfidKey* key, bool show_dialog) {
|
2022-02-18 19:53:46 +00:00
|
|
|
FlipperFormat* file = flipper_format_file_alloc(storage);
|
2021-06-30 12:02:46 +00:00
|
|
|
bool result = false;
|
2021-10-06 09:40:28 +00:00
|
|
|
string_t str_result;
|
|
|
|
string_init(str_result);
|
2021-06-30 12:02:46 +00:00
|
|
|
|
2021-10-06 09:40:28 +00:00
|
|
|
do {
|
2022-05-27 11:19:21 +00:00
|
|
|
if(!flipper_format_file_open_existing(file, string_get_cstr(path))) break;
|
2021-06-30 12:02:46 +00:00
|
|
|
|
2021-10-06 09:40:28 +00:00
|
|
|
// header
|
|
|
|
uint32_t version;
|
2022-02-18 19:53:46 +00:00
|
|
|
if(!flipper_format_read_header(file, str_result, &version)) break;
|
2021-10-06 09:40:28 +00:00
|
|
|
if(string_cmp_str(str_result, app_filetype) != 0) break;
|
|
|
|
if(version != 1) break;
|
2021-06-30 12:02:46 +00:00
|
|
|
|
2021-10-06 09:40:28 +00:00
|
|
|
// key type
|
|
|
|
LfrfidKeyType type;
|
|
|
|
RfidKey loaded_key;
|
2021-06-30 12:02:46 +00:00
|
|
|
|
2022-02-18 19:53:46 +00:00
|
|
|
if(!flipper_format_read_string(file, "Key type", str_result)) break;
|
2021-10-06 09:40:28 +00:00
|
|
|
if(!lfrfid_key_get_string_type(string_get_cstr(str_result), &type)) break;
|
|
|
|
loaded_key.set_type(type);
|
2021-06-30 12:02:46 +00:00
|
|
|
|
2021-10-06 09:40:28 +00:00
|
|
|
// key data
|
|
|
|
uint8_t key_data[loaded_key.get_type_data_count()] = {};
|
2022-02-18 19:53:46 +00:00
|
|
|
if(!flipper_format_read_hex(file, "Data", key_data, loaded_key.get_type_data_count()))
|
|
|
|
break;
|
2021-10-06 09:40:28 +00:00
|
|
|
loaded_key.set_data(key_data, loaded_key.get_type_data_count());
|
2021-06-30 12:02:46 +00:00
|
|
|
|
2022-05-27 11:19:21 +00:00
|
|
|
path_extract_filename(path, str_result, true);
|
2021-10-06 09:40:28 +00:00
|
|
|
loaded_key.set_name(string_get_cstr(str_result));
|
2021-06-30 12:02:46 +00:00
|
|
|
|
2021-10-06 09:40:28 +00:00
|
|
|
*key = loaded_key;
|
|
|
|
result = true;
|
|
|
|
} while(0);
|
2021-06-30 12:02:46 +00:00
|
|
|
|
2022-02-18 19:53:46 +00:00
|
|
|
flipper_format_free(file);
|
2021-10-06 09:40:28 +00:00
|
|
|
string_clear(str_result);
|
|
|
|
|
2022-07-04 13:09:46 +00:00
|
|
|
if((!result) && (show_dialog)) {
|
2021-10-06 09:40:28 +00:00
|
|
|
dialog_message_show_storage_error(dialogs, "Cannot load\nkey file");
|
|
|
|
}
|
2021-06-30 12:02:46 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2022-05-27 11:19:21 +00:00
|
|
|
bool LfRfidApp::save_key_data(string_t path, RfidKey* key) {
|
2022-02-18 19:53:46 +00:00
|
|
|
FlipperFormat* file = flipper_format_file_alloc(storage);
|
2021-06-30 12:02:46 +00:00
|
|
|
bool result = false;
|
|
|
|
|
2021-10-06 09:40:28 +00:00
|
|
|
do {
|
2022-05-27 11:19:21 +00:00
|
|
|
if(!flipper_format_file_open_always(file, string_get_cstr(path))) break;
|
2022-02-18 19:53:46 +00:00
|
|
|
if(!flipper_format_write_header_cstr(file, app_filetype, 1)) break;
|
|
|
|
if(!flipper_format_write_comment_cstr(file, "Key type can be EM4100, H10301 or I40134"))
|
2021-11-04 10:06:13 +00:00
|
|
|
break;
|
2022-02-18 19:53:46 +00:00
|
|
|
if(!flipper_format_write_string_cstr(
|
2021-11-04 10:06:13 +00:00
|
|
|
file, "Key type", lfrfid_key_get_type_string(key->get_type())))
|
|
|
|
break;
|
2022-02-18 19:53:46 +00:00
|
|
|
if(!flipper_format_write_comment_cstr(
|
2021-11-04 10:06:13 +00:00
|
|
|
file, "Data size for EM4100 is 5, for H10301 is 3, for I40134 is 3"))
|
|
|
|
break;
|
2022-02-18 19:53:46 +00:00
|
|
|
if(!flipper_format_write_hex(file, "Data", key->get_data(), key->get_type_data_count()))
|
2021-10-06 09:40:28 +00:00
|
|
|
break;
|
|
|
|
result = true;
|
|
|
|
} while(0);
|
|
|
|
|
2022-02-18 19:53:46 +00:00
|
|
|
flipper_format_free(file);
|
2021-10-06 09:40:28 +00:00
|
|
|
|
|
|
|
if(!result) {
|
|
|
|
dialog_message_show_storage_error(dialogs, "Cannot save\nkey file");
|
2021-06-30 12:02:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LfRfidApp::make_app_folder() {
|
2021-10-06 09:40:28 +00:00
|
|
|
if(!storage_simply_mkdir(storage, app_folder)) {
|
|
|
|
dialog_message_show_storage_error(dialogs, "Cannot create\napp folder");
|
|
|
|
}
|
[FL-2399, FL-2261] Tickless sleep shenanigans (#1168)
* Disable USART in sleep
* Restore UART state on suspend/resume
* FuriHal: Enable stop mode and add insomnia to I2C and SPI
* Remove IDLE interrupt
* FuriHal: add FPU isr and disable all FPU interrupt, add core2 stop mode configuration on deep sleep
* FuriHal: tie stop mode debug with debug rtc flag
* FuriHal: adjust flash latency on clock switch, tie mcu debug with RTC debug flag
* FuriHal: move resource init to early stage
* Add EXTI pending check, enable debug traps with compile-time flag
* Wrap sleep debug functions in conditional compilation
* Remove erroneous changed
* Do not use CSS, remove it from everywhere
* Enable/disable USB on VBUS connect (prototype)
* FuriHal: add LPMS and DEEPSLEEP magic, workaround state inconsistency between cores
* FuriHal: honor c1 LMPS
* USB mode switch fix
* Applications: add flags and insomnia bypass system
* Correct spelling
* FuriHal: cleanup insomnia usage, reset sleep flags on wakeup, add shutdown api
* FuriHal: extra check on reinit request
* FuriHal: rename gpio_display_rst pin to gpio_display_rst_n
* FuriHal: add debug HAL
* FuriHal: add some magic to core2 reload procedure, fix issue with crash on ble keyboard exit
* FuriHal: cleanup ble glue, add BLE_GLUE_DEBUG flag
* FuriHal: ble reinit API, move os timer to LPTIM1 for deep sleep capability, shutdown that works
* FuriHal: take insomnia while shutdown
* Remove USB switch on/off on VBUS change
* Better tick skew handling
* Improve tick consistency under load
* Add USB_HP dummy IRQ handler
* Move interrupt check closer to sleep
* Clean up includes
* Re-enable Insomnia globally
* FuriHal: enable CSS
* FuriHal: remove questionable core2 clock shenanigans
* FuriHal: use core1 RCC registers in idle timer config
* FuriHal: return back CSS handlers, add lptim isr dispatching
Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
Co-authored-by: nminaylov <nm29719@gmail.com>
2022-04-29 13:29:51 +00:00
|
|
|
}
|