Skip to content

Commit

Permalink
Merge branch 'dev' into ntag-pwd-capture-rework
Browse files Browse the repository at this point in the history
  • Loading branch information
gornekich authored Aug 2, 2022
2 parents 0e2d6e6 + 4da6eba commit d5aad9d
Show file tree
Hide file tree
Showing 83 changed files with 629 additions and 215 deletions.
3 changes: 0 additions & 3 deletions applications/infrared/infrared.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,6 @@ static void infrared_free(Infrared* infrared) {
infrared_remote_free(infrared->remote);
infrared_worker_free(infrared->worker);

furi_record_close(RECORD_GUI);
infrared->gui = NULL;

furi_record_close(RECORD_NOTIFICATION);
infrared->notifications = NULL;

Expand Down
1 change: 1 addition & 0 deletions applications/nfc/scenes/nfc_scene_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ ADD_SCENE(nfc, emulate_apdu_sequence, EmulateApduSequence)
ADD_SCENE(nfc, device_info, DeviceInfo)
ADD_SCENE(nfc, delete, Delete)
ADD_SCENE(nfc, delete_success, DeleteSuccess)
ADD_SCENE(nfc, restore_original_confirm, RestoreOriginalConfirm)
ADD_SCENE(nfc, restore_original, RestoreOriginal)
ADD_SCENE(nfc, debug, Debug)
ADD_SCENE(nfc, field, Field)
Expand Down
14 changes: 4 additions & 10 deletions applications/nfc/scenes/nfc_scene_mf_desfire_read_success.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,12 @@ void nfc_scene_mf_desfire_read_success_on_enter(void* context) {
}
}

// TODO rework info view
nfc_text_store_set(
nfc,
"UID: %02X %02X %02X %02X %02X %02X %02X\n" NFC_SCENE_READ_SUCCESS_SHIFT
"%d%s bytes\n" NFC_SCENE_READ_SUCCESS_SHIFT "%d bytes free\n"
"%d application%s, %d file%s",
data->version.uid[0],
data->version.uid[1],
data->version.uid[2],
data->version.uid[3],
data->version.uid[4],
data->version.uid[5],
data->version.uid[6],
NFC_SCENE_READ_SUCCESS_SHIFT "Mifare DESFire\n" NFC_SCENE_READ_SUCCESS_SHIFT
"%d%s bytes\n" NFC_SCENE_READ_SUCCESS_SHIFT "%d bytes free\n"
"%d application%s, %d file%s",
1 << (data->version.sw_storage >> 1),
(data->version.sw_storage & 1) ? "+" : "",
data->free_memory ? data->free_memory->bytes : 0,
Expand Down
9 changes: 6 additions & 3 deletions applications/nfc/scenes/nfc_scene_read.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@ void nfc_scene_read_set_state(Nfc* nfc, NfcSceneReadState state) {
uint32_t curr_state = scene_manager_get_scene_state(nfc->scene_manager, NfcSceneRead);
if(curr_state != state) {
if(state == NfcSceneReadStateDetecting) {
popup_set_header(nfc->popup, "Detecting\nNFC card", 90, 24, AlignCenter, AlignTop);
popup_set_icon(nfc->popup, 5, 7, &I_NFC_manual);
popup_reset(nfc->popup);
popup_set_text(
nfc->popup, "Apply card to\nFlipper's back", 97, 24, AlignCenter, AlignTop);
popup_set_icon(nfc->popup, 0, 8, &I_NFC_manual);
} else if(state == NfcSceneReadStateReading) {
popup_reset(nfc->popup);
popup_set_header(
nfc->popup, "Reading card\nDon't move...", 85, 24, AlignCenter, AlignTop);
popup_set_icon(nfc->popup, 19, 23, &A_Loading_24);
popup_set_icon(nfc->popup, 12, 23, &A_Loading_24);
}
scene_manager_set_scene_state(nfc->scene_manager, NfcSceneRead, state);
}
Expand Down
8 changes: 7 additions & 1 deletion applications/nfc/scenes/nfc_scene_restore_original.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ bool nfc_scene_restore_original_on_event(void* context, SceneManagerEvent event)

if(event.type == SceneManagerEventTypeCustom) {
if(event.event == NfcCustomEventViewExit) {
consumed = scene_manager_previous_scene(nfc->scene_manager);
if(scene_manager_has_previous_scene(nfc->scene_manager, NfcSceneSavedMenu)) {
consumed = scene_manager_search_and_switch_to_previous_scene(
nfc->scene_manager, NfcSceneSavedMenu);
} else {
consumed = scene_manager_search_and_switch_to_previous_scene(
nfc->scene_manager, NfcSceneStart);
}
}
}
return consumed;
Expand Down
53 changes: 53 additions & 0 deletions applications/nfc/scenes/nfc_scene_restore_original_confirm.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#include "../nfc_i.h"

void nfc_scene_restore_original_confirm_dialog_callback(DialogExResult result, void* context) {
Nfc* nfc = context;

view_dispatcher_send_custom_event(nfc->view_dispatcher, result);
}

void nfc_scene_restore_original_confirm_on_enter(void* context) {
Nfc* nfc = context;
DialogEx* dialog_ex = nfc->dialog_ex;

dialog_ex_set_header(dialog_ex, "Restore card data?", 64, 0, AlignCenter, AlignTop);
dialog_ex_set_icon(dialog_ex, 5, 15, &I_Restoring);
dialog_ex_set_text(
dialog_ex, "It will be returned\nto its original state.", 47, 21, AlignLeft, AlignTop);
dialog_ex_set_left_button_text(dialog_ex, "Cancel");
dialog_ex_set_right_button_text(dialog_ex, "Restore");
dialog_ex_set_context(dialog_ex, nfc);
dialog_ex_set_result_callback(dialog_ex, nfc_scene_restore_original_confirm_dialog_callback);

view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewDialogEx);
}

bool nfc_scene_restore_original_confirm_on_event(void* context, SceneManagerEvent event) {
Nfc* nfc = context;
bool consumed = false;

if(event.type == SceneManagerEventTypeCustom) {
if(event.event == DialogExResultRight) {
if(!nfc_device_restore(nfc->dev, true)) {
scene_manager_search_and_switch_to_previous_scene(
nfc->scene_manager, NfcSceneStart);
} else {
scene_manager_next_scene(nfc->scene_manager, NfcSceneRestoreOriginal);
}
consumed = true;
} else if(event.event == DialogExResultLeft) {
consumed = scene_manager_previous_scene(nfc->scene_manager);
}
} else if(event.type == SceneManagerEventTypeBack) {
consumed = true;
}

return consumed;
}

void nfc_scene_restore_original_confirm_on_exit(void* context) {
Nfc* nfc = context;

// Clean view
dialog_ex_reset(nfc->dialog_ex);
}
8 changes: 4 additions & 4 deletions applications/nfc/scenes/nfc_scene_save_success.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ bool nfc_scene_save_success_on_event(void* context, SceneManagerEvent event) {

if(event.type == SceneManagerEventTypeCustom) {
if(event.event == NfcCustomEventViewExit) {
if(scene_manager_has_previous_scene(nfc->scene_manager, NfcSceneMfDesfireMenu)) {
if(scene_manager_has_previous_scene(nfc->scene_manager, NfcSceneSavedMenu)) {
consumed = scene_manager_search_and_switch_to_previous_scene(
nfc->scene_manager, NfcSceneMfDesfireMenu);
nfc->scene_manager, NfcSceneSavedMenu);
} else {
consumed = scene_manager_search_and_switch_to_previous_scene(
nfc->scene_manager, NfcSceneStart);
consumed = scene_manager_search_and_switch_to_another_scene(
nfc->scene_manager, NfcSceneFileSelect);
}
}
}
Expand Down
23 changes: 9 additions & 14 deletions applications/nfc/scenes/nfc_scene_saved_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

enum SubmenuIndex {
SubmenuIndexEmulate,
SubmenuIndexEdit,
SubmenuIndexRename,
SubmenuIndexDelete,
SubmenuIndexInfo,
SubmenuIndexRestoreOriginal,
Expand Down Expand Up @@ -33,22 +33,22 @@ void nfc_scene_saved_menu_on_enter(void* context) {
submenu_add_item(
submenu, "Emulate", SubmenuIndexEmulate, nfc_scene_saved_menu_submenu_callback, nfc);
}
submenu_add_item(
submenu, "Edit UID and Name", SubmenuIndexEdit, nfc_scene_saved_menu_submenu_callback, nfc);
submenu_add_item(
submenu, "Delete", SubmenuIndexDelete, nfc_scene_saved_menu_submenu_callback, nfc);
submenu_add_item(
submenu, "Info", SubmenuIndexInfo, nfc_scene_saved_menu_submenu_callback, nfc);
submenu_set_selected_item(
nfc->submenu, scene_manager_get_scene_state(nfc->scene_manager, NfcSceneSavedMenu));
if(nfc->dev->shadow_file_exist) {
submenu_add_item(
submenu,
"Restore original",
"Restore to original",
SubmenuIndexRestoreOriginal,
nfc_scene_saved_menu_submenu_callback,
nfc);
}
submenu_add_item(
submenu, "Rename", SubmenuIndexRename, nfc_scene_saved_menu_submenu_callback, nfc);
submenu_add_item(
submenu, "Delete", SubmenuIndexDelete, nfc_scene_saved_menu_submenu_callback, nfc);

view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewMenu);
}
Expand All @@ -68,8 +68,8 @@ bool nfc_scene_saved_menu_on_event(void* context, SceneManagerEvent event) {
scene_manager_next_scene(nfc->scene_manager, NfcSceneEmulateUid);
}
consumed = true;
} else if(event.event == SubmenuIndexEdit) {
scene_manager_next_scene(nfc->scene_manager, NfcSceneSetUid);
} else if(event.event == SubmenuIndexRename) {
scene_manager_next_scene(nfc->scene_manager, NfcSceneSaveName);
consumed = true;
} else if(event.event == SubmenuIndexDelete) {
scene_manager_next_scene(nfc->scene_manager, NfcSceneDelete);
Expand All @@ -78,12 +78,7 @@ bool nfc_scene_saved_menu_on_event(void* context, SceneManagerEvent event) {
scene_manager_next_scene(nfc->scene_manager, NfcSceneDeviceInfo);
consumed = true;
} else if(event.event == SubmenuIndexRestoreOriginal) {
if(!nfc_device_restore(nfc->dev, true)) {
scene_manager_search_and_switch_to_previous_scene(
nfc->scene_manager, NfcSceneStart);
} else {
scene_manager_next_scene(nfc->scene_manager, NfcSceneRestoreOriginal);
}
scene_manager_next_scene(nfc->scene_manager, NfcSceneRestoreOriginalConfirm);
consumed = true;
}
}
Expand Down
25 changes: 8 additions & 17 deletions applications/rpc/rpc_storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -594,23 +594,19 @@ static void rpc_system_storage_backup_create_process(const PB_Main* request, voi

FURI_LOG_D(TAG, "BackupCreate");

RpcSession* session = (RpcSession*)context;
RpcStorageSystem* rpc_storage = context;
RpcSession* session = rpc_storage->session;
furi_assert(session);

PB_Main* response = malloc(sizeof(PB_Main));
response->command_id = request->command_id;
response->has_next = false;

Storage* fs_api = furi_record_open(RECORD_STORAGE);

bool backup_ok =
lfs_backup_create(fs_api, request->content.storage_backup_create_request.archive_path);
response->command_status = backup_ok ? PB_CommandStatus_OK : PB_CommandStatus_ERROR;

furi_record_close(RECORD_STORAGE);

rpc_send_and_release(session, response);
free(response);
rpc_send_and_release_empty(
session, request->command_id, backup_ok ? PB_CommandStatus_OK : PB_CommandStatus_ERROR);
}

static void rpc_system_storage_backup_restore_process(const PB_Main* request, void* context) {
Expand All @@ -619,24 +615,19 @@ static void rpc_system_storage_backup_restore_process(const PB_Main* request, vo

FURI_LOG_D(TAG, "BackupRestore");

RpcSession* session = (RpcSession*)context;
RpcStorageSystem* rpc_storage = context;
RpcSession* session = rpc_storage->session;
furi_assert(session);

PB_Main* response = malloc(sizeof(PB_Main));
response->command_id = request->command_id;
response->has_next = false;
response->command_status = PB_CommandStatus_OK;

Storage* fs_api = furi_record_open(RECORD_STORAGE);

bool backup_ok =
lfs_backup_unpack(fs_api, request->content.storage_backup_restore_request.archive_path);
response->command_status = backup_ok ? PB_CommandStatus_OK : PB_CommandStatus_ERROR;

furi_record_close(RECORD_STORAGE);

rpc_send_and_release(session, response);
free(response);
rpc_send_and_release_empty(
session, request->command_id, backup_ok ? PB_CommandStatus_OK : PB_CommandStatus_ERROR);
}

void* rpc_system_storage_alloc(RpcSession* session) {
Expand Down
3 changes: 1 addition & 2 deletions applications/storage/storages/storage_ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ static FS_Error storage_ext_parse_error(SDError error);

static bool sd_mount_card(StorageData* storage, bool notify) {
bool result = false;
const uint8_t max_init_counts = 10;
uint8_t counter = max_init_counts;
uint8_t counter = BSP_SD_MaxMountRetryCount();
uint8_t bsp_result;
SDData* sd_data = storage->data;

Expand Down
4 changes: 2 additions & 2 deletions applications/subghz/helpers/subghz_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ typedef enum {
SubGhzViewIdTestPacket,
} SubGhzViewId;

struct SubGhzPesetDefinition {
struct SubGhzPresetDefinition {
string_t name;
uint32_t frequency;
uint8_t* data;
size_t data_size;
};

typedef struct SubGhzPesetDefinition SubGhzPesetDefinition;
typedef struct SubGhzPresetDefinition SubGhzPresetDefinition;
4 changes: 2 additions & 2 deletions applications/subghz/scenes/subghz_scene_receiver_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ static bool subghz_scene_receiver_info_update_parser(void* context) {
subghz->txrx->decoder_result,
subghz_history_get_raw_data(subghz->txrx->history, subghz->txrx->idx_menu_chosen));

SubGhzPesetDefinition* preset =
subghz_history_get_presset(subghz->txrx->history, subghz->txrx->idx_menu_chosen);
SubGhzPresetDefinition* preset =
subghz_history_get_preset_def(subghz->txrx->history, subghz->txrx->idx_menu_chosen);
subghz_preset_init(
subghz,
string_get_cstr(preset->name),
Expand Down
2 changes: 1 addition & 1 deletion applications/subghz/subghz.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ SubGhz* subghz_alloc() {
//init Worker & Protocol & History & KeyBoard
subghz->lock = SubGhzLockOff;
subghz->txrx = malloc(sizeof(SubGhzTxRx));
subghz->txrx->preset = malloc(sizeof(SubGhzPesetDefinition));
subghz->txrx->preset = malloc(sizeof(SubGhzPresetDefinition));
string_init(subghz->txrx->preset->name);
subghz_preset_init(
subghz, "AM650", subghz_setting_get_default_frequency(subghz->setting), NULL, 0);
Expand Down
8 changes: 4 additions & 4 deletions applications/subghz/subghz_history.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ typedef struct {
string_t item_str;
FlipperFormat* flipper_string;
uint8_t type;
SubGhzPesetDefinition* preset;
SubGhzPresetDefinition* preset;
} SubGhzHistoryItem;

ARRAY_DEF(SubGhzHistoryItemArray, SubGhzHistoryItem, M_POD_OPLIST)
Expand Down Expand Up @@ -61,7 +61,7 @@ uint32_t subghz_history_get_frequency(SubGhzHistory* instance, uint16_t idx) {
return item->preset->frequency;
}

SubGhzPesetDefinition* subghz_history_get_presset(SubGhzHistory* instance, uint16_t idx) {
SubGhzPresetDefinition* subghz_history_get_preset_def(SubGhzHistory* instance, uint16_t idx) {
furi_assert(instance);
SubGhzHistoryItem* item = SubGhzHistoryItemArray_get(instance->history->data, idx);
return item->preset;
Expand Down Expand Up @@ -139,7 +139,7 @@ void subghz_history_get_text_item_menu(SubGhzHistory* instance, string_t output,
bool subghz_history_add_to_history(
SubGhzHistory* instance,
void* context,
SubGhzPesetDefinition* preset) {
SubGhzPresetDefinition* preset) {
furi_assert(instance);
furi_assert(context);

Expand All @@ -159,7 +159,7 @@ bool subghz_history_add_to_history(
string_t text;
string_init(text);
SubGhzHistoryItem* item = SubGhzHistoryItemArray_push_raw(instance->history->data);
item->preset = malloc(sizeof(SubGhzPesetDefinition));
item->preset = malloc(sizeof(SubGhzPresetDefinition));
item->type = decoder_base->protocol->type;
item->preset->frequency = preset->frequency;
string_init(item->preset->name);
Expand Down
6 changes: 3 additions & 3 deletions applications/subghz/subghz_history.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void subghz_history_reset(SubGhzHistory* instance);
*/
uint32_t subghz_history_get_frequency(SubGhzHistory* instance, uint16_t idx);

SubGhzPesetDefinition* subghz_history_get_presset(SubGhzHistory* instance, uint16_t idx);
SubGhzPresetDefinition* subghz_history_get_preset_def(SubGhzHistory* instance, uint16_t idx);

/** Get preset to history[idx]
*
Expand Down Expand Up @@ -88,13 +88,13 @@ bool subghz_history_get_text_space_left(SubGhzHistory* instance, string_t output
*
* @param instance - SubGhzHistory instance
* @param context - SubGhzProtocolCommon context
* @param preset - SubGhzPesetDefinition preset
* @param preset - SubGhzPresetDefinition preset
* @return bool;
*/
bool subghz_history_add_to_history(
SubGhzHistory* instance,
void* context,
SubGhzPesetDefinition* preset);
SubGhzPresetDefinition* preset);

/** Get SubGhzProtocolCommonLoad to load into the protocol decoder bin data
*
Expand Down
6 changes: 4 additions & 2 deletions applications/subghz/subghz_i.c
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,10 @@ bool subghz_key_load(SubGhz* subghz, const char* file_path, bool show_dialog) {
subghz->txrx->decoder_result = subghz_receiver_search_decoder_base_by_name(
subghz->txrx->receiver, string_get_cstr(temp_str));
if(subghz->txrx->decoder_result) {
subghz_protocol_decoder_base_deserialize(
subghz->txrx->decoder_result, subghz->txrx->fff_data);
if(!subghz_protocol_decoder_base_deserialize(
subghz->txrx->decoder_result, subghz->txrx->fff_data)) {
break;
}
} else {
FURI_LOG_E(TAG, "Protocol not found");
break;
Expand Down
2 changes: 1 addition & 1 deletion applications/subghz/subghz_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ struct SubGhzTxRx {
SubGhzProtocolDecoderBase* decoder_result;
FlipperFormat* fff_data;

SubGhzPesetDefinition* preset;
SubGhzPresetDefinition* preset;
SubGhzHistory* history;
uint16_t idx_menu_chosen;
SubGhzTxRxState txrx_state;
Expand Down
Loading

0 comments on commit d5aad9d

Please sign in to comment.