Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into release-candidate
Browse files Browse the repository at this point in the history
  • Loading branch information
skotopes committed Mar 29, 2024
2 parents ad303c4 + 3084469 commit aebe071
Show file tree
Hide file tree
Showing 78 changed files with 552 additions and 382 deletions.
2 changes: 1 addition & 1 deletion .vscode/example/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"*.scons": "python",
"SConscript": "python",
"SConstruct": "python",
"*.fam": "python",
"*.fam": "python"
},
"clangd.arguments": [
// We might be able to tighten this a bit more to only include the correct toolchain.
Expand Down
7 changes: 7 additions & 0 deletions applications/main/lfrfid/lfrfid_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@ typedef enum {
LfRfidViewRead,
} LfRfidView;

typedef enum {
LfRfidMenuIndexRead,
LfRfidMenuIndexSaved,
LfRfidMenuIndexAddManually,
LfRfidMenuIndexExtraActions,
} LfRfidMenuIndex;

bool lfrfid_save_key(LfRfid* app);

bool lfrfid_load_key_from_file_select(LfRfid* app);
Expand Down
59 changes: 32 additions & 27 deletions applications/main/lfrfid/scenes/lfrfid_scene_delete_confirm.c
Original file line number Diff line number Diff line change
@@ -1,45 +1,50 @@
#include "../lfrfid_i.h"

#define LFRFID_SCENE_DELETE_MAX_HEX_WIDTH (7UL)

void lfrfid_scene_delete_confirm_on_enter(void* context) {
LfRfid* app = context;
Widget* widget = app->widget;

FuriString* tmp_string;
tmp_string = furi_string_alloc();
FuriString* display_text = furi_string_alloc_printf(
"\e#Delete %s?\e#\n"
"Hex: ",
furi_string_get_cstr(app->file_name));

widget_add_button_element(widget, GuiButtonTypeLeft, "Back", lfrfid_widget_callback, app);
widget_add_button_element(widget, GuiButtonTypeRight, "Delete", lfrfid_widget_callback, app);
const size_t data_size = protocol_dict_get_data_size(app->dict, app->protocol_id);
uint8_t* data = malloc(data_size);

protocol_dict_get_data(app->dict, app->protocol_id, data, data_size);

furi_string_printf(tmp_string, "Delete %s?", furi_string_get_cstr(app->file_name));
widget_add_string_element(
widget, 64, 0, AlignCenter, AlignTop, FontPrimary, furi_string_get_cstr(tmp_string));

furi_string_reset(tmp_string);
size_t size = protocol_dict_get_data_size(app->dict, app->protocol_id);
uint8_t* data = (uint8_t*)malloc(size);
protocol_dict_get_data(app->dict, app->protocol_id, data, size);
for(uint8_t i = 0; i < MIN(size, (size_t)8); i++) {
if(i != 0) {
furi_string_cat_printf(tmp_string, " ");
for(size_t i = 0; i < data_size; i++) {
if(i == LFRFID_SCENE_DELETE_MAX_HEX_WIDTH) {
furi_string_cat(display_text, " ...");
break;
}

furi_string_cat_printf(tmp_string, "%02X", data[i]);
furi_string_cat_printf(display_text, "%s%02X", i != 0 ? " " : "", data[i]);
}

furi_string_push_back(display_text, '\n');

free(data);

widget_add_string_element(
widget, 64, 19, AlignCenter, AlignTop, FontSecondary, furi_string_get_cstr(tmp_string));
widget_add_string_element(
widget,
64,
49,
AlignCenter,
AlignBottom,
FontSecondary,
protocol_dict_get_name(app->dict, app->protocol_id));
const char* protocol = protocol_dict_get_name(app->dict, app->protocol_id);
const char* manufacturer = protocol_dict_get_manufacturer(app->dict, app->protocol_id);

if(strcasecmp(protocol, manufacturer) != 0 && strcasecmp(manufacturer, "N/A") != 0) {
furi_string_cat_printf(display_text, "%s ", manufacturer);
}

furi_string_cat(display_text, protocol);

widget_add_text_box_element(
widget, 0, 0, 128, 64, AlignCenter, AlignTop, furi_string_get_cstr(display_text), true);
widget_add_button_element(widget, GuiButtonTypeLeft, "Cancel", lfrfid_widget_callback, app);
widget_add_button_element(widget, GuiButtonTypeRight, "Delete", lfrfid_widget_callback, app);

view_dispatcher_switch_to_view(app->view_dispatcher, LfRfidViewWidget);
furi_string_free(tmp_string);
furi_string_free(display_text);
}

bool lfrfid_scene_delete_confirm_on_event(void* context, SceneManagerEvent event) {
Expand Down
7 changes: 3 additions & 4 deletions applications/main/lfrfid/scenes/lfrfid_scene_delete_success.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ bool lfrfid_scene_delete_success_on_event(void* context, SceneManagerEvent event
LfRfid* app = context;
bool consumed = false;

if((event.type == SceneManagerEventTypeBack) ||
((event.type == SceneManagerEventTypeCustom) && (event.event == LfRfidEventPopupClosed))) {
scene_manager_search_and_switch_to_previous_scene(
app->scene_manager, LfRfidSceneSelectKey);
if(event.type == SceneManagerEventTypeBack || event.type == SceneManagerEventTypeCustom) {
// Always return to SceneSelectKey from here
scene_manager_search_and_switch_to_another_scene(app->scene_manager, LfRfidSceneSelectKey);
consumed = true;
}

Expand Down
29 changes: 15 additions & 14 deletions applications/main/lfrfid/scenes/lfrfid_scene_emulate.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,28 @@

void lfrfid_scene_emulate_on_enter(void* context) {
LfRfid* app = context;
Popup* popup = app->popup;
Widget* widget = app->widget;

popup_set_header(popup, "Emulating", 89, 30, AlignCenter, AlignTop);
if(!furi_string_empty(app->file_name)) {
popup_set_text(popup, furi_string_get_cstr(app->file_name), 89, 43, AlignCenter, AlignTop);
FuriString* display_text = furi_string_alloc_set("\e#Emulating\e#\n");

if(furi_string_empty(app->file_name)) {
furi_string_cat(display_text, "Unsaved\n");
furi_string_cat(display_text, protocol_dict_get_name(app->dict, app->protocol_id));
} else {
popup_set_text(
popup,
protocol_dict_get_name(app->dict, app->protocol_id),
89,
43,
AlignCenter,
AlignTop);
furi_string_cat(display_text, app->file_name);
}
popup_set_icon(popup, 0, 3, &I_RFIDDolphinSend_97x61);

widget_add_icon_element(widget, 0, 0, &I_NFC_dolphin_emulation_51x64);
widget_add_text_box_element(
widget, 55, 16, 67, 48, AlignCenter, AlignTop, furi_string_get_cstr(display_text), true);

furi_string_free(display_text);

lfrfid_worker_start_thread(app->lfworker);
lfrfid_worker_emulate_start(app->lfworker, (LFRFIDProtocol)app->protocol_id);
notification_message(app->notifications, &sequence_blink_start_magenta);

view_dispatcher_switch_to_view(app->view_dispatcher, LfRfidViewPopup);
view_dispatcher_switch_to_view(app->view_dispatcher, LfRfidViewWidget);
}

bool lfrfid_scene_emulate_on_event(void* context, SceneManagerEvent event) {
Expand All @@ -35,7 +36,7 @@ bool lfrfid_scene_emulate_on_event(void* context, SceneManagerEvent event) {
void lfrfid_scene_emulate_on_exit(void* context) {
LfRfid* app = context;
notification_message(app->notifications, &sequence_blink_stop);
popup_reset(app->popup);
widget_reset(app->widget);
lfrfid_worker_stop(app->lfworker);
lfrfid_worker_stop_thread(app->lfworker);
}
4 changes: 2 additions & 2 deletions applications/main/lfrfid/scenes/lfrfid_scene_exit_confirm.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ void lfrfid_scene_exit_confirm_on_enter(void* context) {
widget_add_button_element(widget, GuiButtonTypeLeft, "Exit", lfrfid_widget_callback, app);
widget_add_button_element(widget, GuiButtonTypeRight, "Stay", lfrfid_widget_callback, app);
widget_add_string_element(
widget, 64, 19, AlignCenter, AlignBottom, FontPrimary, "Exit to RFID Menu?");
widget, 64, 0, AlignCenter, AlignTop, FontPrimary, "Exit to RFID Menu?");
widget_add_string_element(
widget, 64, 31, AlignCenter, AlignBottom, FontSecondary, "All unsaved data will be lost!");
widget, 64, 13, AlignCenter, AlignTop, FontSecondary, "All unsaved data will be lost");

view_dispatcher_switch_to_view(app->view_dispatcher, LfRfidViewWidget);
}
Expand Down
3 changes: 3 additions & 0 deletions applications/main/lfrfid/scenes/lfrfid_scene_extra_actions.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ bool lfrfid_scene_extra_actions_on_event(void* context, SceneManagerEvent event)
consumed = true;
}
scene_manager_set_scene_state(app->scene_manager, LfRfidSceneExtraActions, event.event);

} else if(event.type == SceneManagerEventTypeBack) {
scene_manager_set_scene_state(app->scene_manager, LfRfidSceneExtraActions, 0);
}

return consumed;
Expand Down
34 changes: 18 additions & 16 deletions applications/main/lfrfid/scenes/lfrfid_scene_raw_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,39 @@ void lfrfid_scene_raw_info_on_enter(void* context) {
LfRfid* app = context;
Widget* widget = app->widget;

// FuriString* tmp_string;
// tmp_string = furi_string_alloc();

bool sd_exist = storage_sd_status(app->storage) == FSE_OK;
if(!sd_exist) {
widget_add_icon_element(widget, 0, 0, &I_SDQuestion_35x43);
if(storage_sd_status(app->storage) != FSE_OK) {
widget_add_icon_element(widget, 83, 22, &I_WarningDolphinFlip_45x42);
widget_add_string_element(
widget, 64, 0, AlignCenter, AlignTop, FontPrimary, "No SD Card!");
widget_add_string_multiline_element(
widget,
81,
4,
AlignCenter,
0,
13,
AlignLeft,
AlignTop,
FontSecondary,
"No SD card found.\nThis function will not\nwork without\nSD card.");
"Insert an SD card\n"
"to use this function");

widget_add_button_element(widget, GuiButtonTypeLeft, "Back", lfrfid_widget_callback, app);
} else {
widget_add_string_multiline_element(
widget_add_text_box_element(
widget,
0,
1,
0,
128,
64,
AlignLeft,
AlignTop,
FontSecondary,
"RAW RFID data reader\n1) Put the Flipper on your card\n2) Press OK\n3) Wait until data is read");
"\e#RAW RFID Data Reader\e#\n"
"1. Hold card next to Flipper\n"
"2. Press OK\n"
"3. Wait until data is read",
false);

widget_add_button_element(widget, GuiButtonTypeCenter, "OK", lfrfid_widget_callback, app);
}

view_dispatcher_switch_to_view(app->view_dispatcher, LfRfidViewWidget);
//furi_string_free(tmp_string);
}

bool lfrfid_scene_raw_info_on_event(void* context, SceneManagerEvent event) {
Expand Down
66 changes: 42 additions & 24 deletions applications/main/lfrfid/scenes/lfrfid_scene_raw_read.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "../lfrfid_i.h"

#define RAW_READ_TIME 5000
#define RAW_READ_TIME_MS (5000UL)

typedef struct {
FuriString* string_file_name;
Expand Down Expand Up @@ -29,31 +29,36 @@ void lfrfid_scene_raw_read_on_enter(void* context) {
LfRfid* app = context;
Popup* popup = app->popup;

LfRfidReadRawState* state = malloc(sizeof(LfRfidReadRawState));
scene_manager_set_scene_state(app->scene_manager, LfRfidSceneRawRead, (uint32_t)state);
state->string_file_name = furi_string_alloc();
popup_set_icon(popup, 0, 0, &I_NFC_dolphin_emulation_51x64);
popup_set_header(popup, "Reading ASK", 91, 16, AlignCenter, AlignTop);
popup_set_text(popup, "Don't move\nfor 5 sec.", 91, 29, AlignCenter, AlignTop);

popup_set_icon(popup, 0, 3, &I_RFIDDolphinReceive_97x61);
view_dispatcher_switch_to_view(app->view_dispatcher, LfRfidViewPopup);
lfrfid_worker_start_thread(app->lfworker);
lfrfid_make_app_folder(app);

LfRfidReadRawState* state = malloc(sizeof(LfRfidReadRawState));
state->string_file_name = furi_string_alloc();
state->timer = furi_timer_alloc(timer_callback, FuriTimerTypeOnce, app);
furi_timer_start(state->timer, RAW_READ_TIME);

scene_manager_set_scene_state(app->scene_manager, LfRfidSceneRawRead, (uint32_t)state);

furi_string_printf(
state->string_file_name,
"%s/%s%s",
LFRFID_SD_FOLDER,
furi_string_get_cstr(app->raw_file_name),
LFRFID_APP_RAW_ASK_EXTENSION);
popup_set_header(popup, "Reading\nRAW RFID\nASK", 89, 30, AlignCenter, AlignTop);

lfrfid_make_app_folder(app);

lfrfid_worker_start_thread(app->lfworker);
lfrfid_worker_read_raw_start(
app->lfworker,
furi_string_get_cstr(state->string_file_name),
LFRFIDWorkerReadTypeASKOnly,
lfrfid_read_callback,
app);

furi_timer_start(state->timer, RAW_READ_TIME_MS);
notification_message(app->notifications, &sequence_blink_start_cyan);

state->is_psk = false;
Expand All @@ -70,41 +75,53 @@ bool lfrfid_scene_raw_read_on_event(void* context, SceneManagerEvent event) {
furi_assert(state);

if(event.type == SceneManagerEventTypeCustom) {
if(event.event == LfRfidEventReadError) {
consumed = true;
state->error = true;
popup_set_header(
popup, "Reading\nRAW RFID\nFile error", 89, 30, AlignCenter, AlignTop);
notification_message(app->notifications, &sequence_blink_start_red);
if(event.event == LfRfidEventReadError || event.event == LfRfidEventReadOverrun) {
furi_timer_stop(state->timer);

popup_set_icon(popup, 83, 22, &I_WarningDolphinFlip_45x42);
popup_set_header(popup, "RAW Reading error!", 64, 0, AlignCenter, AlignTop);
popup_set_text(
popup, "This may be\ncaused by SD\ncard issues", 0, 13, AlignLeft, AlignTop);

notification_message(app->notifications, &sequence_blink_start_red);
state->error = true;

} else if(event.event == LfRfidEventReadDone) {
consumed = true;
if(!state->error) {
if(state->is_psk) {
notification_message(app->notifications, &sequence_success);
scene_manager_next_scene(app->scene_manager, LfRfidSceneRawSuccess);

} else {
popup_set_header(
popup, "Reading\nRAW RFID\nPSK", 89, 30, AlignCenter, AlignTop);
notification_message(app->notifications, &sequence_blink_start_yellow);
lfrfid_worker_stop(app->lfworker);
lfrfid_worker_stop_thread(app->lfworker);

state->is_psk = true;

furi_string_printf(
state->string_file_name,
"%s/%s%s",
LFRFID_SD_FOLDER,
furi_string_get_cstr(app->raw_file_name),
LFRFID_APP_RAW_PSK_EXTENSION);

lfrfid_worker_start_thread(app->lfworker);
lfrfid_worker_read_raw_start(
app->lfworker,
furi_string_get_cstr(state->string_file_name),
LFRFIDWorkerReadTypePSKOnly,
lfrfid_read_callback,
app);
furi_timer_start(state->timer, RAW_READ_TIME);
state->is_psk = true;

furi_timer_start(state->timer, RAW_READ_TIME_MS);

popup_set_header(popup, "Reading PSK", 91, 16, AlignCenter, AlignTop);
notification_message(app->notifications, &sequence_blink_start_yellow);
}
}
}

consumed = true;
}

return consumed;
Expand All @@ -115,12 +132,13 @@ void lfrfid_scene_raw_read_on_exit(void* context) {
LfRfidReadRawState* state =
(LfRfidReadRawState*)scene_manager_get_scene_state(app->scene_manager, LfRfidSceneRawRead);

notification_message(app->notifications, &sequence_blink_stop);
popup_reset(app->popup);
lfrfid_worker_stop(app->lfworker);
lfrfid_worker_stop_thread(app->lfworker);
furi_timer_free(state->timer);

furi_timer_free(state->timer);
furi_string_free(state->string_file_name);
free(state);

popup_reset(app->popup);
notification_message(app->notifications, &sequence_blink_stop);
}
Loading

0 comments on commit aebe071

Please sign in to comment.