Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin' into gsurkov/2792_ac_universal_…
Browse files Browse the repository at this point in the history
…remote
  • Loading branch information
gsurkov committed Sep 19, 2022
2 parents 6d27e7f + f5ff643 commit 2a8327d
Show file tree
Hide file tree
Showing 54 changed files with 1,692 additions and 101 deletions.
2 changes: 1 addition & 1 deletion .vscode/example/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@
"SConstruct": "python",
"*.fam": "python",
}
}
}
10 changes: 9 additions & 1 deletion applications/debug/unit_tests/subghz/subghz_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#define CAME_ATOMO_DIR_NAME EXT_PATH("subghz/assets/came_atomo")
#define NICE_FLOR_S_DIR_NAME EXT_PATH("subghz/assets/nice_flor_s")
#define TEST_RANDOM_DIR_NAME EXT_PATH("unit_tests/subghz/test_random_raw.sub")
#define TEST_RANDOM_COUNT_PARSE 232
#define TEST_RANDOM_COUNT_PARSE 233
#define TEST_TIMEOUT 10000

static SubGhzEnvironment* environment_handler;
Expand Down Expand Up @@ -434,6 +434,13 @@ MU_TEST(subghz_decoder_clemsa_test) {
"Test decoder " SUBGHZ_PROTOCOL_CLEMSA_NAME " error\r\n");
}

MU_TEST(subghz_decoder_oregon2_test) {
mu_assert(
subghz_decoder_test(
EXT_PATH("unit_tests/subghz/oregon2_raw.sub"), SUBGHZ_PROTOCOL_OREGON2_NAME),
"Test decoder " SUBGHZ_PROTOCOL_OREGON2_NAME " error\r\n");
}

//test encoders
MU_TEST(subghz_encoder_princeton_test) {
mu_assert(
Expand Down Expand Up @@ -595,6 +602,7 @@ MU_TEST_SUITE(subghz) {
MU_RUN_TEST(subghz_decoder_magellen_test);
MU_RUN_TEST(subghz_decoder_intertechno_v3_test);
MU_RUN_TEST(subghz_decoder_clemsa_test);
MU_RUN_TEST(subghz_decoder_oregon2_test);

MU_RUN_TEST(subghz_encoder_princeton_test);
MU_RUN_TEST(subghz_encoder_came_test);
Expand Down
2 changes: 1 addition & 1 deletion applications/main/lfrfid/views/lfrfid_view_read.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ static void lfrfid_view_read_draw_callback(Canvas* canvas, void* _model) {
LfRfidReadViewModel* model = _model;
canvas_set_color(canvas, ColorBlack);

canvas_draw_icon(canvas, 0, 8, &I_NFC_manual);
canvas_draw_icon(canvas, 0, 8, &I_NFC_manual_60x50);

canvas_set_font(canvas, FontPrimary);

Expand Down
5 changes: 5 additions & 0 deletions applications/main/nfc/nfc_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@

#include "rpc/rpc_app.h"

#include <m-array.h>

ARRAY_DEF(MfClassicUserKeys, char*, M_PTR_OPLIST);

#define NFC_TEXT_STORE_SIZE 128

typedef enum {
Expand All @@ -60,6 +64,7 @@ struct Nfc {
char text_store[NFC_TEXT_STORE_SIZE + 1];
string_t text_box_store;
uint8_t byte_input_store[6];
MfClassicUserKeys_t mfc_key_strs; // Used in MFC key listing

void* rpc_ctx;
NfcRpcState rpc_state;
Expand Down
3 changes: 3 additions & 0 deletions applications/main/nfc/scenes/nfc_scene_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ ADD_SCENE(nfc, mf_classic_menu, MfClassicMenu)
ADD_SCENE(nfc, mf_classic_emulate, MfClassicEmulate)
ADD_SCENE(nfc, mf_classic_keys, MfClassicKeys)
ADD_SCENE(nfc, mf_classic_keys_add, MfClassicKeysAdd)
ADD_SCENE(nfc, mf_classic_keys_list, MfClassicKeysList)
ADD_SCENE(nfc, mf_classic_keys_delete, MfClassicKeysDelete)
ADD_SCENE(nfc, mf_classic_keys_warn_duplicate, MfClassicKeysWarnDuplicate)
ADD_SCENE(nfc, mf_classic_dict_attack, MfClassicDictAttack)
ADD_SCENE(nfc, emv_read_success, EmvReadSuccess)
ADD_SCENE(nfc, emv_menu, EmvMenu)
Expand Down
9 changes: 7 additions & 2 deletions applications/main/nfc/scenes/nfc_scene_delete_success.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,13 @@ bool nfc_scene_delete_success_on_event(void* context, SceneManagerEvent event) {

if(event.type == SceneManagerEventTypeCustom) {
if(event.event == NfcCustomEventViewExit) {
consumed = scene_manager_search_and_switch_to_previous_scene(
nfc->scene_manager, NfcSceneFileSelect);
if(scene_manager_has_previous_scene(nfc->scene_manager, NfcSceneMfClassicKeys)) {
consumed = scene_manager_search_and_switch_to_previous_scene(
nfc->scene_manager, NfcSceneMfClassicKeys);
} else {
consumed = scene_manager_search_and_switch_to_previous_scene(
nfc->scene_manager, NfcSceneStart);
}
}
}
return consumed;
Expand Down
4 changes: 3 additions & 1 deletion applications/main/nfc/scenes/nfc_scene_device_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ void nfc_scene_device_info_on_enter(void* context) {
}
string_clear(country_name);
}
} else if(dev_data->protocol == NfcDeviceProtocolMifareClassic) {
} else if(
dev_data->protocol == NfcDeviceProtocolMifareClassic ||
dev_data->protocol == NfcDeviceProtocolMifareUl) {
string_set(temp_str, nfc->dev->dev_data.parsed_data);
}

Expand Down
5 changes: 4 additions & 1 deletion applications/main/nfc/scenes/nfc_scene_dict_not_found.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ bool nfc_scene_dict_not_found_on_event(void* context, SceneManagerEvent event) {

if(event.type == SceneManagerEventTypeCustom) {
if(event.event == NfcCustomEventViewExit) {
if(scene_manager_has_previous_scene(nfc->scene_manager, NfcSceneExtraActions)) {
if(scene_manager_has_previous_scene(nfc->scene_manager, NfcSceneMfClassicKeys)) {
consumed = scene_manager_search_and_switch_to_previous_scene(
nfc->scene_manager, NfcSceneMfClassicKeys);
} else if(scene_manager_has_previous_scene(nfc->scene_manager, NfcSceneExtraActions)) {
consumed = scene_manager_search_and_switch_to_previous_scene(
nfc->scene_manager, NfcSceneExtraActions);
} else {
Expand Down
2 changes: 1 addition & 1 deletion applications/main/nfc/scenes/nfc_scene_extra_actions.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ void nfc_scene_extra_actions_on_enter(void* context) {

submenu_add_item(
submenu,
"Mf Classic Keys",
"Mifare Classic Keys",
SubmenuIndexMfClassicKeys,
nfc_scene_extra_actions_submenu_callback,
nfc);
Expand Down
24 changes: 20 additions & 4 deletions applications/main/nfc/scenes/nfc_scene_mf_classic_keys.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,25 @@ void nfc_scene_mf_classic_keys_on_enter(void* context) {
}

widget_add_string_element(
nfc->widget, 0, 0, AlignLeft, AlignTop, FontPrimary, "MF Classic Keys");
nfc->widget, 0, 0, AlignLeft, AlignTop, FontPrimary, "Mifare Classic Keys");
char temp_str[32];
snprintf(temp_str, sizeof(temp_str), "Flipper dict: %ld", flipper_dict_keys_total);
snprintf(temp_str, sizeof(temp_str), "Flipper list: %ld", flipper_dict_keys_total);
widget_add_string_element(nfc->widget, 0, 20, AlignLeft, AlignTop, FontSecondary, temp_str);
snprintf(temp_str, sizeof(temp_str), "User dict: %ld", user_dict_keys_total);
snprintf(temp_str, sizeof(temp_str), "User list: %ld", user_dict_keys_total);
widget_add_string_element(nfc->widget, 0, 32, AlignLeft, AlignTop, FontSecondary, temp_str);
widget_add_button_element(
nfc->widget, GuiButtonTypeCenter, "Add", nfc_scene_mf_classic_keys_widget_callback, nfc);
widget_add_icon_element(nfc->widget, 90, 12, &I_Keychain);
widget_add_button_element(
nfc->widget, GuiButtonTypeLeft, "Back", nfc_scene_mf_classic_keys_widget_callback, nfc);
widget_add_icon_element(nfc->widget, 87, 13, &I_Keychain_39x36);
if(user_dict_keys_total > 0) {
widget_add_button_element(
nfc->widget,
GuiButtonTypeRight,
"List",
nfc_scene_mf_classic_keys_widget_callback,
nfc);
}

view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewWidget);
}
Expand All @@ -47,6 +57,12 @@ bool nfc_scene_mf_classic_keys_on_event(void* context, SceneManagerEvent event)
if(event.event == GuiButtonTypeCenter) {
scene_manager_next_scene(nfc->scene_manager, NfcSceneMfClassicKeysAdd);
consumed = true;
} else if(event.event == GuiButtonTypeLeft) {
scene_manager_previous_scene(nfc->scene_manager);
consumed = true;
} else if(event.event == GuiButtonTypeRight) {
scene_manager_next_scene(nfc->scene_manager, NfcSceneMfClassicKeysList);
consumed = true;
}
}

Expand Down
13 changes: 7 additions & 6 deletions applications/main/nfc/scenes/nfc_scene_mf_classic_keys_add.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,16 @@ bool nfc_scene_mf_classic_keys_add_on_event(void* context, SceneManagerEvent eve
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == NfcCustomEventByteInputDone) {
// Add key to dict
bool key_added = false;
MfClassicDict* dict = mf_classic_dict_alloc(MfClassicDictTypeUser);
if(dict) {
if(mf_classic_dict_add_key(dict, nfc->byte_input_store)) {
key_added = true;
if(mf_classic_dict_is_key_present(dict, nfc->byte_input_store)) {
scene_manager_next_scene(
nfc->scene_manager, NfcSceneMfClassicKeysWarnDuplicate);
} else if(mf_classic_dict_add_key(dict, nfc->byte_input_store)) {
scene_manager_next_scene(nfc->scene_manager, NfcSceneSaveSuccess);
} else {
scene_manager_next_scene(nfc->scene_manager, NfcSceneDictNotFound);
}
}
if(key_added) {
scene_manager_next_scene(nfc->scene_manager, NfcSceneSaveSuccess);
} else {
scene_manager_next_scene(nfc->scene_manager, NfcSceneDictNotFound);
}
Expand Down
77 changes: 77 additions & 0 deletions applications/main/nfc/scenes/nfc_scene_mf_classic_keys_delete.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#include "../nfc_i.h"

void nfc_scene_mf_classic_keys_delete_widget_callback(
GuiButtonType result,
InputType type,
void* context) {
Nfc* nfc = context;
if(type == InputTypeShort) {
view_dispatcher_send_custom_event(nfc->view_dispatcher, result);
}
}

void nfc_scene_mf_classic_keys_delete_on_enter(void* context) {
Nfc* nfc = context;
MfClassicDict* dict = mf_classic_dict_alloc(MfClassicDictTypeUser);
uint32_t key_index =
scene_manager_get_scene_state(nfc->scene_manager, NfcSceneMfClassicKeysDelete);
// Setup Custom Widget view
string_t key_str;
string_init(key_str);

widget_add_string_element(
nfc->widget, 64, 0, AlignCenter, AlignTop, FontPrimary, "Delete this key?");
widget_add_button_element(
nfc->widget,
GuiButtonTypeLeft,
"Cancel",
nfc_scene_mf_classic_keys_delete_widget_callback,
nfc);
widget_add_button_element(
nfc->widget,
GuiButtonTypeRight,
"Delete",
nfc_scene_mf_classic_keys_delete_widget_callback,
nfc);

mf_classic_dict_get_key_at_index_str(dict, key_str, key_index);
widget_add_string_element(
nfc->widget, 64, 32, AlignCenter, AlignCenter, FontSecondary, string_get_cstr(key_str));

string_clear(key_str);
mf_classic_dict_free(dict);

view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewWidget);
}

bool nfc_scene_mf_classic_keys_delete_on_event(void* context, SceneManagerEvent event) {
Nfc* nfc = context;
bool consumed = false;
uint32_t key_index =
scene_manager_get_scene_state(nfc->scene_manager, NfcSceneMfClassicKeysDelete);

if(event.type == SceneManagerEventTypeCustom) {
if(event.event == GuiButtonTypeLeft) {
consumed = scene_manager_search_and_switch_to_previous_scene(
nfc->scene_manager, NfcSceneMfClassicKeys);
} else if(event.event == GuiButtonTypeRight) {
MfClassicDict* dict = mf_classic_dict_alloc(MfClassicDictTypeUser);
if(mf_classic_dict_delete_index(dict, key_index)) {
scene_manager_next_scene(nfc->scene_manager, NfcSceneDeleteSuccess);
} else {
scene_manager_search_and_switch_to_previous_scene(
nfc->scene_manager, NfcSceneMfClassicKeys);
}
mf_classic_dict_free(dict);
consumed = true;
}
}

return consumed;
}

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

widget_reset(nfc->widget);
}
60 changes: 60 additions & 0 deletions applications/main/nfc/scenes/nfc_scene_mf_classic_keys_list.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#include "../nfc_i.h"

void nfc_scene_mf_classic_keys_list_submenu_callback(void* context, uint32_t index) {
Nfc* nfc = context;

view_dispatcher_send_custom_event(nfc->view_dispatcher, index);
}

void nfc_scene_mf_classic_keys_list_on_enter(void* context) {
Nfc* nfc = context;
Submenu* submenu = nfc->submenu;
MfClassicDict* dict = mf_classic_dict_alloc(MfClassicDictTypeUser);
uint32_t index = 0;
string_t temp_key;
MfClassicUserKeys_init(nfc->mfc_key_strs);
string_init(temp_key);
if(dict) {
mf_classic_dict_rewind(dict);
while(mf_classic_dict_get_next_key_str(dict, temp_key)) {
char* current_key = (char*)malloc(sizeof(char) * 13);
strncpy(current_key, string_get_cstr(temp_key), 12);
MfClassicUserKeys_push_back(nfc->mfc_key_strs, current_key);
FURI_LOG_D("ListKeys", "Key %d: %s", index, current_key);
submenu_add_item(
submenu,
current_key,
index++,
nfc_scene_mf_classic_keys_list_submenu_callback,
nfc);
}
}
submenu_set_header(submenu, "Select key to delete:");
mf_classic_dict_free(dict);
string_clear(temp_key);
view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewMenu);
}

bool nfc_scene_mf_classic_keys_list_on_event(void* context, SceneManagerEvent event) {
Nfc* nfc = context;
bool consumed = false;
if(event.type == SceneManagerEventTypeCustom) {
scene_manager_set_scene_state(
nfc->scene_manager, NfcSceneMfClassicKeysDelete, event.event);
scene_manager_next_scene(nfc->scene_manager, NfcSceneMfClassicKeysDelete);
consumed = true;
}
return consumed;
}

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

MfClassicUserKeys_it_t it;
for(MfClassicUserKeys_it(it, nfc->mfc_key_strs); !MfClassicUserKeys_end_p(it);
MfClassicUserKeys_next(it)) {
free(*MfClassicUserKeys_ref(it));
}
MfClassicUserKeys_clear(nfc->mfc_key_strs);
submenu_reset(nfc->submenu);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include "../nfc_i.h"

void nfc_scene_mf_classic_keys_warn_duplicate_popup_callback(void* context) {
Nfc* nfc = context;
view_dispatcher_send_custom_event(nfc->view_dispatcher, NfcCustomEventViewExit);
}

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

// Setup view
Popup* popup = nfc->popup;
popup_set_icon(popup, 72, 16, &I_DolphinCommon_56x48);
popup_set_header(popup, "Key already exists!", 64, 3, AlignCenter, AlignTop);
popup_set_text(
popup,
"Please enter a\n"
"different key.",
4,
24,
AlignLeft,
AlignTop);
popup_set_timeout(popup, 5000);
popup_set_context(popup, nfc);
popup_set_callback(popup, nfc_scene_mf_classic_keys_warn_duplicate_popup_callback);
popup_enable_timeout(popup);
view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewPopup);
}

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

if(event.type == SceneManagerEventTypeCustom) {
if(event.event == NfcCustomEventViewExit) {
consumed = scene_manager_search_and_switch_to_previous_scene(
nfc->scene_manager, NfcSceneMfClassicKeysAdd);
}
}
return consumed;
}

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

popup_reset(nfc->popup);
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void nfc_scene_mf_ultralight_read_auth_set_state(Nfc* nfc, NfcSceneMfUlReadState
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);
popup_set_icon(nfc->popup, 0, 8, &I_NFC_manual_60x50);
} else if(state == NfcSceneMfUlReadStateReading) {
popup_reset(nfc->popup);
popup_set_header(
Expand Down
Loading

0 comments on commit 2a8327d

Please sign in to comment.