diff --git a/applications/external/mifare_fuzzer/mifare_fuzzer_worker.c b/applications/external/mifare_fuzzer/mifare_fuzzer_worker.c index cc2ba138f..a1b54d781 100644 --- a/applications/external/mifare_fuzzer/mifare_fuzzer_worker.c +++ b/applications/external/mifare_fuzzer/mifare_fuzzer_worker.c @@ -50,7 +50,7 @@ int32_t mifare_fuzzer_worker_task(void* context) { furi_hal_nfc_exit_sleep(); while(mifare_fuzzer_worker->state == MifareFuzzerWorkerStateEmulate) { furi_hal_nfc_listen( - params.uid, params.uid_len, params.a_data.atqa, params.a_data.sak, false, 500); + params.uid, params.uid_len, params.atqa, params.sak, false, 500); furi_delay_ms(50); } furi_hal_nfc_sleep(); diff --git a/applications/external/mifare_fuzzer/scenes/mifare_fuzzer_scene_emulator.c b/applications/external/mifare_fuzzer/scenes/mifare_fuzzer_scene_emulator.c index 4e4be5dfd..d2e05b7e6 100644 --- a/applications/external/mifare_fuzzer/scenes/mifare_fuzzer_scene_emulator.c +++ b/applications/external/mifare_fuzzer/scenes/mifare_fuzzer_scene_emulator.c @@ -42,9 +42,9 @@ void mifare_fuzzer_scene_emulator_on_enter(void* context) { app->emulator_view, emulator->ticks_between_cards); // init default card data FuriHalNfcDevData nfc_dev_data; - nfc_dev_data.a_data.atqa[0] = 0x00; - nfc_dev_data.a_data.atqa[1] = 0x00; - nfc_dev_data.a_data.sak = 0x00; + nfc_dev_data.atqa[0] = 0x00; + nfc_dev_data.atqa[1] = 0x00; + nfc_dev_data.sak = 0x00; if(app->card == MifareCardUltralight) { nfc_dev_data.uid_len = 0x07; } else { @@ -84,19 +84,19 @@ bool mifare_fuzzer_scene_emulator_on_event(void* context, SceneManagerEvent even // Set card type // TODO: Move somewhere else, I do not like this to be there if(app->card == MifareCardClassic1k) { - nfc_dev_data.a_data.atqa[0] = 0x04; - nfc_dev_data.a_data.atqa[1] = 0x00; - nfc_dev_data.a_data.sak = 0x08; + nfc_dev_data.atqa[0] = 0x04; + nfc_dev_data.atqa[1] = 0x00; + nfc_dev_data.sak = 0x08; nfc_dev_data.uid_len = 0x04; } else if(app->card == MifareCardClassic4k) { - nfc_dev_data.a_data.atqa[0] = 0x02; - nfc_dev_data.a_data.atqa[1] = 0x00; - nfc_dev_data.a_data.sak = 0x18; + nfc_dev_data.atqa[0] = 0x02; + nfc_dev_data.atqa[1] = 0x00; + nfc_dev_data.sak = 0x18; nfc_dev_data.uid_len = 0x04; } else if(app->card == MifareCardUltralight) { - nfc_dev_data.a_data.atqa[0] = 0x44; - nfc_dev_data.a_data.atqa[1] = 0x00; - nfc_dev_data.a_data.sak = 0x00; + nfc_dev_data.atqa[0] = 0x44; + nfc_dev_data.atqa[1] = 0x00; + nfc_dev_data.sak = 0x00; nfc_dev_data.uid_len = 0x07; } diff --git a/applications/external/mifare_nested/mifare_nested_worker.c b/applications/external/mifare_nested/mifare_nested_worker.c index 884dd1685..0b8097653 100644 --- a/applications/external/mifare_nested/mifare_nested_worker.c +++ b/applications/external/mifare_nested/mifare_nested_worker.c @@ -708,8 +708,7 @@ void mifare_nested_worker_collect_nonces_static(MifareNestedWorker* mifare_neste FuriString* folder_path = furi_string_alloc(); FuriHalNfcDevData data = {}; nested_get_data(&data); - MfClassicType type = mifare_nested_worker_get_tag_type( - data.a_data.atqa[0], data.a_data.atqa[1], data.a_data.sak); + MfClassicType type = mifare_nested_worker_get_tag_type(data.atqa[0], data.atqa[1], data.sak); uint64_t key = 0; // Found key for attack uint32_t found_key_type = 0; uint32_t key_block = 0; @@ -872,8 +871,7 @@ void mifare_nested_worker_collect_nonces_hard(MifareNestedWorker* mifare_nested_ FuriString* folder_path = furi_string_alloc(); FuriHalNfcDevData data = {}; nested_get_data(&data); - MfClassicType type = mifare_nested_worker_get_tag_type( - data.a_data.atqa[0], data.a_data.atqa[1], data.a_data.sak); + MfClassicType type = mifare_nested_worker_get_tag_type(data.atqa[0], data.atqa[1], data.sak); uint64_t key = 0; // Found key for attack uint32_t found_key_type = 0; uint32_t key_block = 0; @@ -1122,8 +1120,7 @@ void mifare_nested_worker_collect_nonces(MifareNestedWorker* mifare_nested_worke FuriString* folder_path = furi_string_alloc(); FuriHalNfcDevData data = {}; nested_get_data(&data); - MfClassicType type = mifare_nested_worker_get_tag_type( - data.a_data.atqa[0], data.a_data.atqa[1], data.a_data.sak); + MfClassicType type = mifare_nested_worker_get_tag_type(data.atqa[0], data.atqa[1], data.sak); uint64_t key = 0; // Found key for attack uint32_t found_key_type = 0; uint32_t key_block = 0; @@ -1257,7 +1254,7 @@ void mifare_nested_worker_collect_nonces(MifareNestedWorker* mifare_nested_worke MifareNestedWorkerEventNoTagDetected, mifare_nested_worker->context); while(mifare_nested_worker->state == MifareNestedWorkerStateCollecting && - lost_tag_data.a_data.cuid != data.a_data.cuid) { + lost_tag_data.cuid != data.cuid) { furi_delay_ms(250); nested_get_data(&lost_tag_data); } @@ -1497,8 +1494,7 @@ void mifare_nested_worker_check_keys(MifareNestedWorker* mifare_nested_worker) { FuriString* path = furi_string_alloc(); FuriHalNfcDevData data = {}; nested_get_data(&data); - MfClassicType type = mifare_nested_worker_get_tag_type( - data.a_data.atqa[0], data.a_data.atqa[1], data.a_data.sak); + MfClassicType type = mifare_nested_worker_get_tag_type(data.atqa[0], data.atqa[1], data.sak); NestedCheckKeyResult result = NestedCheckKeyNoTag; FuriHalNfcTxRxContext tx_rx = {}; uint32_t key_count = 0; @@ -1714,4 +1710,4 @@ void mifare_nested_worker_check_keys(MifareNestedWorker* mifare_nested_worker) { MifareNestedWorkerEventKeysFound, mifare_nested_worker->context); return; -} +} \ No newline at end of file diff --git a/applications/external/nfc_magic/nfc_magic_worker.c b/applications/external/nfc_magic/nfc_magic_worker.c index 25af77049..86f521b2b 100644 --- a/applications/external/nfc_magic/nfc_magic_worker.c +++ b/applications/external/nfc_magic/nfc_magic_worker.c @@ -186,9 +186,9 @@ void nfc_magic_worker_write(NfcMagicWorker* nfc_magic_worker) { } gen4_config[7] = 0x00; memset(gen4_config + 8, 0, 16); - gen4_config[24] = dev_data->nfc_data.a_data.atqa[0]; - gen4_config[25] = dev_data->nfc_data.a_data.atqa[1]; - gen4_config[26] = dev_data->nfc_data.a_data.sak; + gen4_config[24] = dev_data->nfc_data.atqa[0]; + gen4_config[25] = dev_data->nfc_data.atqa[1]; + gen4_config[26] = dev_data->nfc_data.sak; furi_hal_nfc_sleep(); furi_hal_nfc_activate_nfca(200, &cuid); @@ -308,7 +308,7 @@ void nfc_magic_worker_check(NfcMagicWorker* nfc_magic_worker) { } if(furi_hal_nfc_detect(&nfc_data, 200)) { - magic_dev->cuid = nfc_data.a_data.cuid; + magic_dev->cuid = nfc_data.cuid; magic_dev->uid_len = nfc_data.uid_len; } else { // wrong BCC @@ -320,7 +320,7 @@ void nfc_magic_worker_check(NfcMagicWorker* nfc_magic_worker) { magic_deactivate(); magic_activate(); if(furi_hal_nfc_detect(&nfc_data, 200)) { - magic_dev->cuid = nfc_data.a_data.cuid; + magic_dev->cuid = nfc_data.cuid; magic_dev->uid_len = nfc_data.uid_len; if(magic_gen4_get_cfg(magic_dev->password, gen4_config)) { magic_dev->type = MagicTypeGen4; diff --git a/applications/main/nfc/nfc_cli.c b/applications/main/nfc/nfc_cli.c index aa3f74c36..0b7e75475 100644 --- a/applications/main/nfc/nfc_cli.c +++ b/applications/main/nfc/nfc_cli.c @@ -34,25 +34,13 @@ static void nfc_cli_detect(Cli* cli, FuriString* args) { while(!cmd_exit) { cmd_exit |= cli_cmd_interrupt_received(cli); if(furi_hal_nfc_detect(&dev_data, 400)) { - if(dev_data.type == FuriHalNfcTypeA) { - printf("UID length: %d, UID:", dev_data.uid_len); - for(size_t i = 0; i < dev_data.uid_len; i++) { - printf("%02X", dev_data.uid[i]); - } - printf("\r\n"); - break; - } else if(dev_data.type == FuriHalNfcTypeF) { - printf("IDm:"); - for(size_t i = 0; i < 8; i++) { - printf("%02X", dev_data.uid[i]); - } - printf(", PMm:"); - for(size_t i = 0; i < 8; i++) { - printf("%02X", dev_data.f_data.pmm[i]); - } - printf("\r\n"); - break; + printf("Found: %s ", nfc_get_dev_type(dev_data.type)); + printf("UID length: %d, UID:", dev_data.uid_len); + for(size_t i = 0; i < dev_data.uid_len; i++) { + printf("%02X", dev_data.uid[i]); } + printf("\r\n"); + break; } furi_hal_nfc_sleep(); furi_delay_ms(50); @@ -75,17 +63,13 @@ static void nfc_cli_emulate(Cli* cli, FuriString* args) { FuriHalNfcDevData params = { .uid = {0x36, 0x9C, 0xe7, 0xb1, 0x0A, 0xC1, 0x34}, .uid_len = 7, - .a_data = - { - .atqa = {0x44, 0x00}, - .sak = 0x00, - }, + .atqa = {0x44, 0x00}, + .sak = 0x00, .type = FuriHalNfcTypeA, }; while(!cli_cmd_interrupt_received(cli)) { - if(furi_hal_nfc_listen( - params.uid, params.uid_len, params.a_data.atqa, params.a_data.sak, false, 100)) { + if(furi_hal_nfc_listen(params.uid, params.uid_len, params.atqa, params.sak, false, 100)) { printf("Reader detected\r\n"); furi_hal_nfc_sleep(); } diff --git a/applications/main/nfc/nfc_i.h b/applications/main/nfc/nfc_i.h index 7331b9405..f7e489902 100644 --- a/applications/main/nfc/nfc_i.h +++ b/applications/main/nfc/nfc_i.h @@ -39,23 +39,13 @@ #include "rpc/rpc_app.h" -#include #include -ARRAY_DEF(FelicaAreaPath, FelicaArea*, M_PTR_OPLIST) -ARRAY_DEF(MfClassicUserKeys, char*, M_PTR_OPLIST) +ARRAY_DEF(MfClassicUserKeys, char*, M_PTR_OPLIST); #define NFC_TEXT_STORE_SIZE 128 #define NFC_APP_FOLDER ANY_PATH("nfc") -typedef struct { - FelicaSystem* selected_system; - - FelicaAreaPath_t selected_areas; - - FelicaService* selected_service; -} FelicaSelectState; - typedef enum { NfcRpcStateIdle, NfcRpcStateEmulating, @@ -75,7 +65,6 @@ struct Nfc { FuriString* text_box_store; uint8_t byte_input_store[6]; MfClassicUserKeys_t mfc_key_strs; // Used in MFC key listing - FelicaSelectState felica_select; void* rpc_ctx; NfcRpcState rpc_state; diff --git a/applications/main/nfc/scenes/nfc_scene_config.h b/applications/main/nfc/scenes/nfc_scene_config.h index 5414e11a2..f11d14798 100644 --- a/applications/main/nfc/scenes/nfc_scene_config.h +++ b/applications/main/nfc/scenes/nfc_scene_config.h @@ -21,8 +21,6 @@ ADD_SCENE(nfc, nfcv_unlock, NfcVUnlock) ADD_SCENE(nfc, nfcv_emulate, NfcVEmulate) ADD_SCENE(nfc, nfcv_sniff, NfcVSniff) ADD_SCENE(nfc, nfcv_read_success, NfcVReadSuccess) -ADD_SCENE(nfc, nfcf_read_success, NfcfReadSuccess) -ADD_SCENE(nfc, nfcf_menu, NfcfMenu) ADD_SCENE(nfc, mf_ultralight_read_success, MfUltralightReadSuccess) ADD_SCENE(nfc, mf_ultralight_data, MfUltralightData) ADD_SCENE(nfc, mf_ultralight_menu, MfUltralightMenu) @@ -55,10 +53,6 @@ ADD_SCENE(nfc, mf_classic_update_success, MfClassicUpdateSuccess) ADD_SCENE(nfc, mf_classic_wrong_card, MfClassicWrongCard) ADD_SCENE(nfc, emv_read_success, EmvReadSuccess) ADD_SCENE(nfc, emv_menu, EmvMenu) -ADD_SCENE(nfc, felica_read_success, FelicaReadSuccess) -ADD_SCENE(nfc, felica_menu, FelicaMenu) -ADD_SCENE(nfc, felica_info_select, FelicaInfoSelect) -ADD_SCENE(nfc, felica_service_data, FelicaServiceData) ADD_SCENE(nfc, emulate_apdu_sequence, EmulateApduSequence) ADD_SCENE(nfc, device_info, DeviceInfo) ADD_SCENE(nfc, delete, Delete) diff --git a/applications/main/nfc/scenes/nfc_scene_delete.c b/applications/main/nfc/scenes/nfc_scene_delete.c index 8b712e948..0808db45a 100644 --- a/applications/main/nfc/scenes/nfc_scene_delete.c +++ b/applications/main/nfc/scenes/nfc_scene_delete.c @@ -44,8 +44,6 @@ void nfc_scene_delete_on_enter(void* context) { } else if(protocol == NfcDeviceProtocolNfcV) { furi_string_set(temp_str, "ISO15693 tag"); nfc_type = "NFC-V"; - } else if(protocol == NfcDeviceProtocolFelica) { - furi_string_set(temp_str, "FeliCa"); } else { furi_string_set(temp_str, "Unknown ISO tag"); } diff --git a/applications/main/nfc/scenes/nfc_scene_felica_info_select.c b/applications/main/nfc/scenes/nfc_scene_felica_info_select.c deleted file mode 100644 index 7a59521fa..000000000 --- a/applications/main/nfc/scenes/nfc_scene_felica_info_select.c +++ /dev/null @@ -1,152 +0,0 @@ -#include "../nfc_i.h" -#include - -void nfc_scene_felica_info_select_submenu_callback(void* context, uint32_t index) { - Nfc* nfc = context; - - view_dispatcher_send_custom_event(nfc->view_dispatcher, index); -} - -void nfc_scene_felica_info_select_on_enter(void* context) { - Nfc* nfc = context; - Submenu* submenu = nfc->submenu; - FelicaData* data = &nfc->dev->dev_data.felica_data; - FelicaSelectState* state = &nfc->felica_select; - - FelicaAreaPath_init(nfc->felica_select.selected_areas); - - submenu_add_item(submenu, "[Actions]", 0, nfc_scene_felica_info_select_submenu_callback, nfc); - uint8_t i = 1; - if(state->selected_system == NULL || state->selected_system->code == LITE_SYSTEM_CODE) { - submenu_set_header(submenu, "Systems"); - for - M_EACH(current_system, data->systems, FelicaSystemArray_t) { - FuriString* system_name = felica_get_system_name(current_system); - submenu_add_item( - submenu, - furi_string_get_cstr(system_name), - i++, - nfc_scene_felica_info_select_submenu_callback, - nfc); - furi_string_free(system_name); - } - } else { - FelicaSystem* system = state->selected_system; - FuriString* header = furi_string_alloc_printf("%04X/", system->code); - - FelicaNode* root = &system->root; - furi_assert(root->type == FelicaNodeTypeArea); - FelicaArea* area = root->area; - if(FelicaAreaPath_size(state->selected_areas) > 0) { - FelicaAreaPath_it_t it; - for(FelicaAreaPath_it(it, state->selected_areas); !FelicaAreaPath_end_p(it); - FelicaAreaPath_next(it)) { - FelicaArea* ancestor = *FelicaAreaPath_ref(it); - furi_string_cat_printf(header, "%d/", ancestor->number); - } - area = *FelicaAreaPath_back(state->selected_areas); - } - furi_string_cat(header, "Areas"); - - submenu_set_header(submenu, furi_string_get_cstr(header)); - furi_string_free(header); - - for - M_EACH(node, area->nodes, FelicaNodeArray_t) { - FuriString* node_name = furi_string_alloc(); - if(node->type == FelicaNodeTypeArea) { - furi_string_printf(node_name, "Area %d", node->area->number); - submenu_add_item( - submenu, - furi_string_get_cstr(node_name), - i++, - nfc_scene_felica_info_select_submenu_callback, - nfc); - } else { - uint16_t service_code = node->service->number << 6; - furi_string_printf(node_name, "Service %04X", service_code); - submenu_add_item( - submenu, - furi_string_get_cstr(node_name), - i++, - nfc_scene_felica_info_select_submenu_callback, - nfc); - } - - furi_string_free(node_name); - } - } - - state->selected_service = NULL; - submenu_set_selected_item( - nfc->submenu, scene_manager_get_scene_state(nfc->scene_manager, NfcSceneFelicaInfoSelect)); - - view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewMenu); -} - -bool nfc_scene_felica_info_select_on_event(void* context, SceneManagerEvent event) { - Nfc* nfc = context; - FelicaData* data = &nfc->dev->dev_data.felica_data; - FelicaSelectState* state = &nfc->felica_select; - bool consumed = false; - - if(event.type == SceneManagerEventTypeCustom) { - uint8_t index = event.event; - scene_manager_set_scene_state(nfc->scene_manager, NfcSceneMfUltralightMenu, index); - - if(index == 0) { - return false; - } - - index -= 1; - if(state->selected_system == NULL) { - state->selected_system = FelicaSystemArray_get(data->systems, index); - if(state->selected_system->code == LITE_SYSTEM_CODE) { - scene_manager_next_scene(nfc->scene_manager, NfcSceneFelicaServiceData); - } else { - scene_manager_next_scene(nfc->scene_manager, NfcSceneFelicaInfoSelect); - } - consumed = true; - } else { - FelicaNode* selected_node = NULL; - - FelicaNode* root = &(state->selected_system->root); - furi_assert(root->type == FelicaNodeTypeArea); - - if(FelicaAreaPath_size(state->selected_areas) == 0) { - selected_node = FelicaNodeArray_get(root->area->nodes, index); - } else { - FelicaArea* current_area = *FelicaAreaPath_back(state->selected_areas); - selected_node = FelicaNodeArray_get(current_area->nodes, index); - } - - if(selected_node->type == FelicaNodeTypeArea) { - FelicaAreaPath_push_back(state->selected_areas, selected_node->area); - scene_manager_next_scene(nfc->scene_manager, NfcSceneFelicaInfoSelect); - consumed = true; - } else if(selected_node->type == FelicaNodeTypeService) { - state->selected_service = selected_node->service; - scene_manager_next_scene(nfc->scene_manager, NfcSceneFelicaServiceData); - consumed = true; - } - } - } else if(event.type == SceneManagerEventTypeBack) { - if(FelicaAreaPath_size(state->selected_areas) <= 1) { - FelicaAreaPath_clear(state->selected_areas); - state->selected_system = NULL; - } else { - FelicaAreaPath_pop_back(NULL, state->selected_areas); - } - consumed = scene_manager_previous_scene(nfc->scene_manager); - } - - return consumed; -} - -void nfc_scene_felica_info_select_on_exit(void* context) { - Nfc* nfc = context; - - // Clear view - FelicaAreaPath_clear(nfc->felica_select.selected_areas); - submenu_reset(nfc->submenu); -} diff --git a/applications/main/nfc/scenes/nfc_scene_felica_menu.c b/applications/main/nfc/scenes/nfc_scene_felica_menu.c deleted file mode 100644 index b8e653e20..000000000 --- a/applications/main/nfc/scenes/nfc_scene_felica_menu.c +++ /dev/null @@ -1,87 +0,0 @@ -#include "../nfc_i.h" -#include - -enum SubmenuIndex { - /* - SubmenuIndexUnlock, - */ - SubmenuIndexSave, - /* - SubmenuIndexEmulate, - */ - SubmenuIndexInfo, -}; - -void nfc_scene_felica_menu_submenu_callback(void* context, uint32_t index) { - Nfc* nfc = context; - - view_dispatcher_send_custom_event(nfc->view_dispatcher, index); -} - -void nfc_scene_felica_menu_on_enter(void* context) { - Nfc* nfc = context; - Submenu* submenu = nfc->submenu; - // FelicaData* data = &nfc->dev->dev_data.felica_data; - - /* - submenu_add_item( - submenu, "Unlock", SubmenuIndexUnlock, nfc_scene_felica_menu_submenu_callback, nfc); - */ - submenu_add_item( - submenu, "Save", SubmenuIndexSave, nfc_scene_felica_menu_submenu_callback, nfc); - /* - submenu_add_item( - submenu, "Emulate", SubmenuIndexEmulate, nfc_scene_felica_menu_submenu_callback, nfc); - */ - submenu_add_item( - submenu, "Info", SubmenuIndexInfo, nfc_scene_felica_menu_submenu_callback, nfc); - - submenu_set_selected_item( - nfc->submenu, scene_manager_get_scene_state(nfc->scene_manager, NfcSceneFelicaMenu)); - - view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewMenu); -} - -bool nfc_scene_felica_menu_on_event(void* context, SceneManagerEvent event) { - Nfc* nfc = context; - bool consumed = false; - - if(event.type == SceneManagerEventTypeCustom) { - if(event.event == SubmenuIndexSave) { - nfc->dev->format = NfcDeviceSaveFormatFelica; - // Clear device name - nfc_device_set_name(nfc->dev, ""); - scene_manager_next_scene(nfc->scene_manager, NfcSceneSaveName); - consumed = true; - /* - } else if(event.event == SubmenuIndexEmulate) { - scene_manager_next_scene(nfc->scene_manager, NfcSceneFelicaEmulate); - if(scene_manager_has_previous_scene(nfc->scene_manager, NfcSceneSetType)) { - dolphin_deed(DolphinDeedNfcAddEmulate); - } else { - dolphin_deed(DolphinDeedNfcEmulate); - } - consumed = true; - } else if(event.event == SubmenuIndexUnlock) { - scene_manager_next_scene(nfc->scene_manager, NfcSceneFelicaUnlockMenu); - consumed = true; - */ - } else if(event.event == SubmenuIndexInfo) { - scene_manager_next_scene(nfc->scene_manager, NfcSceneFelicaInfoSelect); - consumed = true; - } - scene_manager_set_scene_state(nfc->scene_manager, NfcSceneFelicaMenu, event.event); - - } else if(event.type == SceneManagerEventTypeBack) { - consumed = scene_manager_previous_scene(nfc->scene_manager); - } - - return consumed; -} - -void nfc_scene_felica_menu_on_exit(void* context) { - Nfc* nfc = context; - - // Clear view - submenu_reset(nfc->submenu); -} diff --git a/applications/main/nfc/scenes/nfc_scene_felica_read_success.c b/applications/main/nfc/scenes/nfc_scene_felica_read_success.c deleted file mode 100644 index 79dd82297..000000000 --- a/applications/main/nfc/scenes/nfc_scene_felica_read_success.c +++ /dev/null @@ -1,81 +0,0 @@ -#include "../nfc_i.h" - -void nfc_scene_felica_read_success_widget_callback( - GuiButtonType result, - InputType type, - void* context) { - furi_assert(context); - Nfc* nfc = context; - - if(type == InputTypeShort) { - view_dispatcher_send_custom_event(nfc->view_dispatcher, result); - } -} - -void nfc_scene_felica_read_success_on_enter(void* context) { - Nfc* nfc = context; - FelicaData* felica_data = &nfc->dev->dev_data.felica_data; - - // Setup view - Widget* widget = nfc->widget; - widget_add_button_element( - widget, GuiButtonTypeLeft, "Retry", nfc_scene_felica_read_success_widget_callback, nfc); - widget_add_button_element( - widget, GuiButtonTypeRight, "More", nfc_scene_felica_read_success_widget_callback, nfc); - - FuriString* temp_str = NULL; - if(furi_string_size(nfc->dev->dev_data.parsed_data)) { - temp_str = furi_string_alloc_set(nfc->dev->dev_data.parsed_data); - } else { - temp_str = furi_string_alloc_printf("\e#%s", nfc_felica_type(felica_data->type)); - - for - M_EACH(current_system, felica_data->systems, FelicaSystemArray_t) { - furi_string_cat_printf( - temp_str, "\nSystem %04X (#%d):", current_system->code, current_system->number); - furi_string_cat_printf(temp_str, "\nIDm:\n "); - for(size_t i = 0; i < 8; i++) { - furi_string_cat_printf(temp_str, "%02X", current_system->idm[i]); - } - furi_string_cat_printf(temp_str, "\nPMm:\n "); - for(size_t i = 0; i < 8; i++) { - furi_string_cat_printf(temp_str, "%02X", current_system->pmm[i]); - } - } - } - - widget_add_text_scroll_element(widget, 0, 0, 128, 52, furi_string_get_cstr(temp_str)); - furi_string_free(temp_str); - - notification_message_block(nfc->notifications, &sequence_set_green_255); - - view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewWidget); -} - -bool nfc_scene_felica_read_success_on_event(void* context, SceneManagerEvent event) { - Nfc* nfc = context; - bool consumed = false; - - if(event.type == SceneManagerEventTypeCustom) { - if(event.event == GuiButtonTypeLeft) { - scene_manager_next_scene(nfc->scene_manager, NfcSceneRetryConfirm); - consumed = true; - } else if(event.event == GuiButtonTypeRight) { - scene_manager_next_scene(nfc->scene_manager, NfcSceneFelicaMenu); - consumed = true; - } - } else if(event.type == SceneManagerEventTypeBack) { - scene_manager_next_scene(nfc->scene_manager, NfcSceneExitConfirm); - consumed = true; - } - return consumed; -} - -void nfc_scene_felica_read_success_on_exit(void* context) { - Nfc* nfc = context; - - notification_message_block(nfc->notifications, &sequence_reset_green); - - // Clear view - widget_reset(nfc->widget); -} diff --git a/applications/main/nfc/scenes/nfc_scene_felica_service_data.c b/applications/main/nfc/scenes/nfc_scene_felica_service_data.c deleted file mode 100644 index 5153d7d37..000000000 --- a/applications/main/nfc/scenes/nfc_scene_felica_service_data.c +++ /dev/null @@ -1,104 +0,0 @@ -#include "../nfc_i.h" - -void nfc_scene_felica_service_data_on_enter(void* context) { - Nfc* nfc = context; - FelicaSelectState* select_state = &nfc->felica_select; - FelicaSystem* system = select_state->selected_system; - //FelicaService* service = select_state->selected_service; - TextBox* text_box = nfc->text_box; - - if(system->code == LITE_SYSTEM_CODE) { - FelicaLiteInfo* lite_info = &system->lite_info; - uint8_t* data; - text_box_set_font(text_box, TextBoxFontHex); - furi_string_cat_str(nfc->text_box_store, "S_PAD:\n"); - for(int i = 0; i < REG_LITE_BLOCK; i++) { - data = lite_info->S_PAD[i]; - for(uint16_t i = 0; i < FELICA_BLOCK_SIZE; i += 2) { - if(!(i % 8) && i) { - furi_string_push_back(nfc->text_box_store, '\n'); - } - if(data != NULL) { - furi_string_cat_printf(nfc->text_box_store, "%02X%02X ", data[i], data[i + 1]); - } else { - furi_string_cat_printf(nfc->text_box_store, "???? "); - } - } - } - - furi_string_cat_str(nfc->text_box_store, "REG:\n"); - data = lite_info->REG; - for(uint16_t i = 0; i < FELICA_BLOCK_SIZE; i += 2) { - if(!(i % 8) && i) { - furi_string_push_back(nfc->text_box_store, '\n'); - } - if(data != NULL) { - furi_string_cat_printf(nfc->text_box_store, "%02X%02X ", data[i], data[i + 1]); - } else { - furi_string_cat_printf(nfc->text_box_store, "???? "); - } - } - - furi_string_cat_str(nfc->text_box_store, "MAC:\n"); - data = lite_info->MAC; - for(uint16_t i = 0; i < 8; i += 2) { - if(!(i % 8) && i) { - furi_string_push_back(nfc->text_box_store, '\n'); - } - furi_string_cat_printf(nfc->text_box_store, "%02X%02X ", data[i], data[i + 1]); - } - - furi_string_cat_printf(nfc->text_box_store, "DFC: %04X\n", lite_info->data_format_code); - - furi_string_cat_str(nfc->text_box_store, "ID data:\n"); - data = lite_info->ID_value; - for(uint16_t i = 0; i < 6; i += 2) { - furi_string_cat_printf(nfc->text_box_store, "%02X%02X ", data[i], data[i + 1]); - } - furi_string_cat_str(nfc->text_box_store, "\n"); - - furi_string_cat_printf(nfc->text_box_store, "CKV: %04X\n", lite_info->card_key_version); - - furi_string_cat_str(nfc->text_box_store, "MC:\n"); - data = lite_info->memory_config; - for(uint16_t i = 0; i < FELICA_BLOCK_SIZE; i += 2) { - if(!(i % 8) && i) { - furi_string_push_back(nfc->text_box_store, '\n'); - } - furi_string_cat_printf(nfc->text_box_store, "%02X%02X ", data[i], data[i + 1]); - } - - furi_string_cat_printf(nfc->text_box_store, "WCNT: %06lX\n", lite_info->write_count); - - furi_string_cat_str(nfc->text_box_store, "MAC_A:\n"); - data = lite_info->MAC_A; - for(uint16_t i = 0; i < 8; i += 2) { - if(!(i % 8) && i) { - furi_string_push_back(nfc->text_box_store, '\n'); - } - furi_string_cat_printf(nfc->text_box_store, "%02X%02X ", data[i], data[i + 1]); - } - } - text_box_set_text(text_box, furi_string_get_cstr(nfc->text_box_store)); - - view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewTextBox); -} - -bool nfc_scene_felica_service_data_on_event(void* context, SceneManagerEvent event) { - Nfc* nfc = context; - bool consumed = false; - - if(event.type == SceneManagerEventTypeBack) { - consumed = scene_manager_previous_scene(nfc->scene_manager); - } - - return consumed; -} - -void nfc_scene_felica_service_data_on_exit(void* context) { - Nfc* nfc = context; - - // Clean view - text_box_reset(nfc->text_box); - furi_string_reset(nfc->text_box_store); -} \ No newline at end of file diff --git a/applications/main/nfc/scenes/nfc_scene_nfc_data_info.c b/applications/main/nfc/scenes/nfc_scene_nfc_data_info.c index 4c2bfc678..bc64c65bf 100644 --- a/applications/main/nfc/scenes/nfc_scene_nfc_data_info.c +++ b/applications/main/nfc/scenes/nfc_scene_nfc_data_info.c @@ -1,5 +1,4 @@ #include "../nfc_i.h" -#include void nfc_scene_nfc_data_info_widget_callback(GuiButtonType result, InputType type, void* context) { Nfc* nfc = context; @@ -89,7 +88,6 @@ void nfc_scene_nfc_data_info_on_enter(void* context) { Nfc* nfc = context; Widget* widget = nfc->widget; FuriHalNfcDevData* nfc_data = &nfc->dev->dev_data.nfc_data; - FuriHalNfcType type = nfc_data->type; NfcDeviceData* dev_data = &nfc->dev->dev_data; NfcProtocol protocol = dev_data->protocol; uint8_t text_scroll_height = 0; @@ -141,8 +139,6 @@ void nfc_scene_nfc_data_info_on_enter(void* context) { furi_string_cat_printf(temp_str, "\e#ISO15693 (unknown)\n"); break; } - } else if(protocol == NfcDeviceProtocolFelica) { - furi_string_cat_printf(temp_str, "\e#%s\n", nfc_felica_type(dev_data->felica_data.type)); } else { furi_string_cat_printf(temp_str, "\e#Unknown ISO tag\n"); } @@ -200,72 +196,16 @@ void nfc_scene_nfc_data_info_on_enter(void* context) { furi_string_cat_printf(temp_str, " %s\n", status); } - } else if(type == FuriHalNfcTypeF) { - // Set NFC-F data - furi_string_cat_printf(temp_str, "ISO 18092 (NFC-F)\n"); - furi_string_cat_printf(temp_str, "CIN:"); - // NFC-F Card Identification Number (CIN) starts at "UID" byte 2. - for(size_t i = 2; i < nfc_data->uid_len; i++) { - furi_string_cat_printf(temp_str, " %02X", nfc_data->uid[i]); - } - // The first 2 bytes of the "UID" are Manufacturer Code (MC) - furi_string_cat_printf( - temp_str, - "\nMC: %02X %02X ROM: %02X IC: %02X\n\n", - nfc_data->uid[0], - nfc_data->uid[1], - nfc_data->f_data.pmm[0], - nfc_data->f_data.pmm[1]); - - furi_string_cat_printf(temp_str, "MRT (1 node/blk):\n"); - furi_string_cat_printf( - temp_str, - "- ReqSvc: %" PRIuLEAST32 "us\n", - felica_estimate_timing_us(nfc_data->f_data.pmm[FELICA_PMM_VARIABLE_MRT], 1)); - furi_string_cat_printf( - temp_str, - "- Fixed: %" PRIuLEAST32 "us\n", - felica_estimate_timing_us(nfc_data->f_data.pmm[FELICA_PMM_FIXED_MRT], 0)); - furi_string_cat_printf( - temp_str, - "- Auth1: %" PRIuLEAST32 "us\n", - felica_estimate_timing_us(nfc_data->f_data.pmm[FELICA_PMM_MUTUAL_AUTH_MRT], 1)); - furi_string_cat_printf( - temp_str, - "- Auth2: %" PRIuLEAST32 "us\n", - felica_estimate_timing_us(nfc_data->f_data.pmm[FELICA_PMM_MUTUAL_AUTH_MRT], 0)); - furi_string_cat_printf( - temp_str, - "- Read: %" PRIuLEAST32 "us\n", - felica_estimate_timing_us(nfc_data->f_data.pmm[FELICA_PMM_READ_MRT], 1)); - furi_string_cat_printf( - temp_str, - "- Write: %" PRIuLEAST32 "us\n", - felica_estimate_timing_us(nfc_data->f_data.pmm[FELICA_PMM_WRITE_MRT], 1)); - furi_string_cat_printf( - temp_str, - "- Other: %" PRIuLEAST32 "us\n\n", - felica_estimate_timing_us(nfc_data->f_data.pmm[FELICA_PMM_OTHER_MRT], 0)); - - furi_string_cat_printf(temp_str, "IDm:"); - for(size_t i = 0; i < nfc_data->uid_len; i++) { - furi_string_cat_printf(temp_str, " %02X", nfc_data->uid[i]); - } - furi_string_cat_printf(temp_str, "\nPMm:"); - for(size_t i = 0; i < sizeof(nfc_data->f_data.pmm); i++) { - furi_string_cat_printf(temp_str, " %02X", nfc_data->f_data.pmm[i]); - } } else { - // Set tag general data - char iso_type = FURI_BIT(nfc_data->a_data.sak, 5) ? '4' : '3'; + char iso_type = FURI_BIT(nfc_data->sak, 5) ? '4' : '3'; furi_string_cat_printf(temp_str, "ISO 14443-%c (NFC-A)\n", iso_type); furi_string_cat_printf(temp_str, "UID:"); for(size_t i = 0; i < nfc_data->uid_len; i++) { furi_string_cat_printf(temp_str, " %02X", nfc_data->uid[i]); } furi_string_cat_printf( - temp_str, "\nATQA: %02X %02X ", nfc_data->a_data.atqa[1], nfc_data->a_data.atqa[0]); - furi_string_cat_printf(temp_str, " SAK: %02X", nfc_data->a_data.sak); + temp_str, "\nATQA: %02X %02X ", nfc_data->atqa[1], nfc_data->atqa[0]); + furi_string_cat_printf(temp_str, " SAK: %02X", nfc_data->sak); } // Set application specific data diff --git a/applications/main/nfc/scenes/nfc_scene_nfca_read_success.c b/applications/main/nfc/scenes/nfc_scene_nfca_read_success.c index 74fff367f..a38f31a98 100644 --- a/applications/main/nfc/scenes/nfc_scene_nfca_read_success.c +++ b/applications/main/nfc/scenes/nfc_scene_nfca_read_success.c @@ -24,15 +24,14 @@ void nfc_scene_nfca_read_success_on_enter(void* context) { notification_message_block(nfc->notifications, &sequence_set_green_255); - char iso_type = FURI_BIT(data->a_data.sak, 5) ? '4' : '3'; + char iso_type = FURI_BIT(data->sak, 5) ? '4' : '3'; furi_string_cat_printf(temp_str, "ISO 14443-%c (NFC-A)\n", iso_type); furi_string_cat_printf(temp_str, "UID:"); for(size_t i = 0; i < data->uid_len; i++) { furi_string_cat_printf(temp_str, " %02X", data->uid[i]); } - furi_string_cat_printf( - temp_str, "\nATQA: %02X %02X ", data->a_data.atqa[1], data->a_data.atqa[0]); - furi_string_cat_printf(temp_str, " SAK: %02X", data->a_data.sak); + furi_string_cat_printf(temp_str, "\nATQA: %02X %02X ", data->atqa[1], data->atqa[0]); + furi_string_cat_printf(temp_str, " SAK: %02X", data->sak); widget_add_text_scroll_element(widget, 0, 0, 128, 52, furi_string_get_cstr(temp_str)); furi_string_free(temp_str); diff --git a/applications/main/nfc/scenes/nfc_scene_nfcf_menu.c b/applications/main/nfc/scenes/nfc_scene_nfcf_menu.c deleted file mode 100644 index 69815dab1..000000000 --- a/applications/main/nfc/scenes/nfc_scene_nfcf_menu.c +++ /dev/null @@ -1,80 +0,0 @@ -#include "../nfc_i.h" -#include - -enum SubmenuIndex { - /* - SubmenuIndexSave, - SubmenuIndexEmulate, - */ - SubmenuIndexInfo, -}; - -void nfc_scene_nfcf_menu_submenu_callback(void* context, uint32_t index) { - Nfc* nfc = context; - - view_dispatcher_send_custom_event(nfc->view_dispatcher, index); -} - -void nfc_scene_nfcf_menu_on_enter(void* context) { - Nfc* nfc = context; - Submenu* submenu = nfc->submenu; - // FelicaData* data = &nfc->dev->dev_data.felica_data; - - /* - submenu_add_item( - submenu, "Save IDm", SubmenuIndexSave, nfc_scene_felica_menu_submenu_callback, nfc); - submenu_add_item( - submenu, "Emulate IDm", SubmenuIndexEmulate, nfc_scene_felica_menu_submenu_callback, nfc); - */ - submenu_add_item(submenu, "Info", SubmenuIndexInfo, nfc_scene_nfcf_menu_submenu_callback, nfc); - - submenu_set_selected_item( - nfc->submenu, scene_manager_get_scene_state(nfc->scene_manager, NfcSceneNfcfMenu)); - - view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewMenu); -} - -bool nfc_scene_nfcf_menu_on_event(void* context, SceneManagerEvent event) { - Nfc* nfc = context; - bool consumed = false; - - if(event.type == SceneManagerEventTypeCustom) { - /* - if(event.event == SubmenuIndexSave) { - nfc->dev->format = NfcDeviceSaveFormatFelica; - // Clear device name - nfc_device_set_name(nfc->dev, ""); - scene_manager_next_scene(nfc->scene_manager, NfcSceneSaveName); - consumed = true; - } else if(event.event == SubmenuIndexEmulate) { - scene_manager_next_scene(nfc->scene_manager, NfcSceneFelicaEmulate); - if(scene_manager_has_previous_scene(nfc->scene_manager, NfcSceneSetType)) { - dolphin_deed(DolphinDeedNfcAddEmulate); - } else { - dolphin_deed(DolphinDeedNfcEmulate); - } - consumed = true; - } else if(event.event == SubmenuIndexUnlock) { - scene_manager_next_scene(nfc->scene_manager, NfcSceneFelicaUnlockMenu); - consumed = true; - } else - */ - if(event.event == SubmenuIndexInfo) { - scene_manager_next_scene(nfc->scene_manager, NfcSceneNfcDataInfo); - consumed = true; - } - scene_manager_set_scene_state(nfc->scene_manager, NfcSceneNfcfMenu, event.event); - - } else if(event.type == SceneManagerEventTypeBack) { - consumed = scene_manager_previous_scene(nfc->scene_manager); - } - - return consumed; -} - -void nfc_scene_nfcf_menu_on_exit(void* context) { - Nfc* nfc = context; - - // Clear view - submenu_reset(nfc->submenu); -} diff --git a/applications/main/nfc/scenes/nfc_scene_nfcf_read_success.c b/applications/main/nfc/scenes/nfc_scene_nfcf_read_success.c deleted file mode 100644 index da695ba83..000000000 --- a/applications/main/nfc/scenes/nfc_scene_nfcf_read_success.c +++ /dev/null @@ -1,88 +0,0 @@ -#include "../nfc_i.h" -#include "nfc_device.h" - -void nfc_scene_nfcf_read_success_widget_callback( - GuiButtonType result, - InputType type, - void* context) { - furi_assert(context); - Nfc* nfc = context; - - if(type == InputTypeShort) { - view_dispatcher_send_custom_event(nfc->view_dispatcher, result); - } -} - -void nfc_scene_nfcf_read_success_on_enter(void* context) { - Nfc* nfc = context; - - FuriHalNfcDevData* data = &nfc->dev->dev_data.nfc_data; - NfcDeviceData* dev_data = &nfc->dev->dev_data; - - // Setup view - Widget* widget = nfc->widget; - widget_add_button_element( - widget, GuiButtonTypeLeft, "Retry", nfc_scene_nfcf_read_success_widget_callback, nfc); - widget_add_button_element( - widget, GuiButtonTypeRight, "More", nfc_scene_nfcf_read_success_widget_callback, nfc); - - FuriString* temp_str = furi_string_alloc(); - - if(dev_data->protocol == NfcDeviceProtocolFelica) { - furi_string_cat_printf(temp_str, "\e#%s", nfc_felica_type(dev_data->felica_data.type)); - } else { - furi_string_cat_printf(temp_str, "\e#Unknown ISO tag"); - } - - furi_string_cat_printf(temp_str, "\nISO 18092 (NFC-F)"); - - furi_string_cat_printf(temp_str, "\nCIN:"); - // NFC-F Card Identification Number (CIN) starts at "UID" byte 2. - for(size_t i = 2; i < data->uid_len; i++) { - furi_string_cat_printf(temp_str, " %02X", data->uid[i]); - } - - // The first 2 bytes of the "UID" are Manufacturer Code (MC) - furi_string_cat_printf( - temp_str, - "\nMC: %02X %02X ROM: %02X IC: %02X", - data->uid[0], - data->uid[1], - data->f_data.pmm[0], - data->f_data.pmm[1]); - - widget_add_text_scroll_element(widget, 0, 0, 128, 52, furi_string_get_cstr(temp_str)); - furi_string_free(temp_str); - - notification_message_block(nfc->notifications, &sequence_set_green_255); - - view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewWidget); -} - -bool nfc_scene_nfcf_read_success_on_event(void* context, SceneManagerEvent event) { - Nfc* nfc = context; - bool consumed = false; - - if(event.type == SceneManagerEventTypeCustom) { - if(event.event == GuiButtonTypeLeft) { - scene_manager_next_scene(nfc->scene_manager, NfcSceneRetryConfirm); - consumed = true; - } else if(event.event == GuiButtonTypeRight) { - scene_manager_next_scene(nfc->scene_manager, NfcSceneNfcfMenu); - consumed = true; - } - } else if(event.type == SceneManagerEventTypeBack) { - scene_manager_next_scene(nfc->scene_manager, NfcSceneExitConfirm); - consumed = true; - } - return consumed; -} - -void nfc_scene_nfcf_read_success_on_exit(void* context) { - Nfc* nfc = context; - - notification_message_block(nfc->notifications, &sequence_reset_green); - - // Clear view - widget_reset(nfc->widget); -} diff --git a/applications/main/nfc/scenes/nfc_scene_read.c b/applications/main/nfc/scenes/nfc_scene_read.c index 45b0f4a7e..f254e08f8 100644 --- a/applications/main/nfc/scenes/nfc_scene_read.c +++ b/applications/main/nfc/scenes/nfc_scene_read.c @@ -57,6 +57,7 @@ bool nfc_scene_read_on_event(void* context, SceneManagerEvent event) { if(event.type == SceneManagerEventTypeCustom) { if((event.event == NfcWorkerEventReadUidNfcB) || + (event.event == NfcWorkerEventReadUidNfcF) || (event.event == NfcWorkerEventReadUidNfcV)) { notification_message(nfc->notifications, &sequence_success); scene_manager_next_scene(nfc->scene_manager, NfcSceneReadCardSuccess); @@ -101,16 +102,6 @@ bool nfc_scene_read_on_event(void* context, SceneManagerEvent event) { scene_manager_next_scene(nfc->scene_manager, NfcSceneDictNotFound); } consumed = true; - } else if(event.event == NfcWorkerEventReadUidNfcF) { - notification_message(nfc->notifications, &sequence_success); - scene_manager_next_scene(nfc->scene_manager, NfcSceneNfcfReadSuccess); - dolphin_deed(DolphinDeedNfcReadSuccess); - consumed = true; - } else if(event.event == NfcWorkerEventReadFelica) { - notification_message(nfc->notifications, &sequence_success); - scene_manager_next_scene(nfc->scene_manager, NfcSceneFelicaReadSuccess); - dolphin_deed(DolphinDeedNfcReadSuccess); - consumed = true; } else if(event.event == NfcWorkerEventCardDetected) { nfc_scene_read_set_state(nfc, NfcSceneReadStateReading); nfc_blink_detect_start(nfc); diff --git a/applications/main/nfc/scenes/nfc_scene_read_card_type.c b/applications/main/nfc/scenes/nfc_scene_read_card_type.c index ed33515d4..94262aa1e 100644 --- a/applications/main/nfc/scenes/nfc_scene_read_card_type.c +++ b/applications/main/nfc/scenes/nfc_scene_read_card_type.c @@ -7,8 +7,6 @@ enum SubmenuIndex { SubmenuIndexReadMfUltralight, SubmenuIndexReadEMV, SubmenuIndexReadNFCA, - SubmenuIndexReadFelica, - SubmenuIndexReadNFCF, }; void nfc_scene_read_card_type_submenu_callback(void* context, uint32_t index) { @@ -51,18 +49,6 @@ void nfc_scene_read_card_type_on_enter(void* context) { SubmenuIndexReadNFCA, nfc_scene_read_card_type_submenu_callback, nfc); - submenu_add_item( - submenu, - "Read FeliCa", - SubmenuIndexReadFelica, - nfc_scene_read_card_type_submenu_callback, - nfc); - submenu_add_item( - submenu, - "Read NFC-F data", - SubmenuIndexReadNFCF, - nfc_scene_read_card_type_submenu_callback, - nfc); uint32_t state = scene_manager_get_scene_state(nfc->scene_manager, NfcSceneReadCardType); submenu_set_selected_item(submenu, state); @@ -99,16 +85,6 @@ bool nfc_scene_read_card_type_on_event(void* context, SceneManagerEvent event) { scene_manager_next_scene(nfc->scene_manager, NfcSceneRead); consumed = true; } - if(event.event == SubmenuIndexReadFelica) { - nfc->dev->dev_data.read_mode = NfcReadModeFelica; - scene_manager_next_scene(nfc->scene_manager, NfcSceneRead); - consumed = true; - } - if(event.event == SubmenuIndexReadNFCF) { - nfc->dev->dev_data.read_mode = NfcReadModeNFCF; - scene_manager_next_scene(nfc->scene_manager, NfcSceneRead); - consumed = true; - } scene_manager_set_scene_state(nfc->scene_manager, NfcSceneReadCardType, event.event); } return consumed; diff --git a/applications/main/nfc/scenes/nfc_scene_set_atqa.c b/applications/main/nfc/scenes/nfc_scene_set_atqa.c index f26ce8436..d079b3804 100644 --- a/applications/main/nfc/scenes/nfc_scene_set_atqa.c +++ b/applications/main/nfc/scenes/nfc_scene_set_atqa.c @@ -17,7 +17,7 @@ void nfc_scene_set_atqa_on_enter(void* context) { nfc_scene_set_atqa_byte_input_callback, NULL, nfc, - nfc->dev->dev_data.nfc_data.a_data.atqa, + nfc->dev->dev_data.nfc_data.atqa, 2); view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewByteInput); } diff --git a/applications/main/nfc/scenes/nfc_scene_set_sak.c b/applications/main/nfc/scenes/nfc_scene_set_sak.c index 98bd6441a..60a1e1494 100644 --- a/applications/main/nfc/scenes/nfc_scene_set_sak.c +++ b/applications/main/nfc/scenes/nfc_scene_set_sak.c @@ -17,7 +17,7 @@ void nfc_scene_set_sak_on_enter(void* context) { nfc_scene_set_sak_byte_input_callback, NULL, nfc, - &nfc->dev->dev_data.nfc_data.a_data.sak, + &nfc->dev->dev_data.nfc_data.sak, 1); view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewByteInput); } diff --git a/firmware/targets/f7/furi_hal/furi_hal_nfc.c b/firmware/targets/f7/furi_hal/furi_hal_nfc.c index cdf31954f..b249c8658 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_nfc.c +++ b/firmware/targets/f7/furi_hal/furi_hal_nfc.c @@ -134,36 +134,21 @@ bool furi_hal_nfc_detect(FuriHalNfcDevData* nfc_data, uint32_t timeout) { if(detected) { if(dev_list[0].type == RFAL_NFC_LISTEN_TYPE_NFCA) { nfc_data->type = FuriHalNfcTypeA; - nfc_data->a_data.atqa[0] = dev_list[0].dev.nfca.sensRes.anticollisionInfo; - nfc_data->a_data.atqa[1] = dev_list[0].dev.nfca.sensRes.platformInfo; - nfc_data->a_data.sak = dev_list[0].dev.nfca.selRes.sak; + nfc_data->atqa[0] = dev_list[0].dev.nfca.sensRes.anticollisionInfo; + nfc_data->atqa[1] = dev_list[0].dev.nfca.sensRes.platformInfo; + nfc_data->sak = dev_list[0].dev.nfca.selRes.sak; uint8_t* cuid_start = dev_list[0].nfcid; if(dev_list[0].nfcidLen == 7) { cuid_start = &dev_list[0].nfcid[3]; } - nfc_data->a_data.cuid = (cuid_start[0] << 24) | (cuid_start[1] << 16) | - (cuid_start[2] << 8) | (cuid_start[3]); + nfc_data->cuid = (cuid_start[0] << 24) | (cuid_start[1] << 16) | (cuid_start[2] << 8) | + (cuid_start[3]); } else if( dev_list[0].type == RFAL_NFC_LISTEN_TYPE_NFCB || dev_list[0].type == RFAL_NFC_LISTEN_TYPE_ST25TB) { nfc_data->type = FuriHalNfcTypeB; } else if(dev_list[0].type == RFAL_NFC_LISTEN_TYPE_NFCF) { nfc_data->type = FuriHalNfcTypeF; - furi_assert(dev_list[0].nfcidLen == RFAL_NFCF_NFCID2_LEN); - memcpy( - &nfc_data->f_data.pmm[0], - dev_list[0].dev.nfcf.sensfRes.PAD0, - RFAL_NFCF_SENSF_RES_PAD0_LEN); - memcpy( - &nfc_data->f_data.pmm[RFAL_NFCF_SENSF_RES_PAD0_LEN], - dev_list[0].dev.nfcf.sensfRes.PAD1, - RFAL_NFCF_SENSF_RES_PAD1_LEN); - nfc_data->f_data.pmm[RFAL_NFCF_SENSF_RES_PAD0_LEN + RFAL_NFCF_SENSF_RES_PAD1_LEN] = - dev_list[0].dev.nfcf.sensfRes.MRTIcheck; - nfc_data->f_data.pmm[RFAL_NFCF_SENSF_RES_PAD0_LEN + RFAL_NFCF_SENSF_RES_PAD1_LEN + 1] = - dev_list[0].dev.nfcf.sensfRes.MRTIupdate; - nfc_data->f_data.pmm[RFAL_NFCF_SENSF_RES_PAD0_LEN + RFAL_NFCF_SENSF_RES_PAD1_LEN + 2] = - dev_list[0].dev.nfcf.sensfRes.PAD2; } else if(dev_list[0].type == RFAL_NFC_LISTEN_TYPE_NFCV) { nfc_data->type = FuriHalNfcTypeV; } @@ -386,15 +371,15 @@ void furi_hal_nfc_listen_start(FuriHalNfcDevData* nfc_data) { // Write PT Memory uint8_t pt_memory[15] = {}; memcpy(pt_memory, nfc_data->uid, nfc_data->uid_len); - pt_memory[10] = nfc_data->a_data.atqa[0]; - pt_memory[11] = nfc_data->a_data.atqa[1]; + pt_memory[10] = nfc_data->atqa[0]; + pt_memory[11] = nfc_data->atqa[1]; if(nfc_data->uid_len == 4) { - pt_memory[12] = nfc_data->a_data.sak & ~FURI_HAL_NFC_UID_INCOMPLETE; + pt_memory[12] = nfc_data->sak & ~FURI_HAL_NFC_UID_INCOMPLETE; } else { pt_memory[12] = FURI_HAL_NFC_UID_INCOMPLETE; } - pt_memory[13] = nfc_data->a_data.sak & ~FURI_HAL_NFC_UID_INCOMPLETE; - pt_memory[14] = nfc_data->a_data.sak & ~FURI_HAL_NFC_UID_INCOMPLETE; + pt_memory[13] = nfc_data->sak & ~FURI_HAL_NFC_UID_INCOMPLETE; + pt_memory[14] = nfc_data->sak & ~FURI_HAL_NFC_UID_INCOMPLETE; st25r3916WritePTMem(pt_memory, sizeof(pt_memory)); // Go to sense diff --git a/firmware/targets/f7/furi_hal/furi_hal_nfc.h b/firmware/targets/f7/furi_hal/furi_hal_nfc.h index e970f345d..c87f04a9a 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_nfc.h +++ b/firmware/targets/f7/furi_hal/furi_hal_nfc.h @@ -69,25 +69,14 @@ typedef enum { FuriHalNfcInterfaceNfcDep, } FuriHalNfcInterface; -typedef struct { - uint32_t cuid; - uint8_t atqa[2]; - uint8_t sak; -} FuriHalNfcADevData; - -typedef struct { - uint8_t pmm[8]; -} FuriHalNfcFDevData; - typedef struct { FuriHalNfcType type; FuriHalNfcInterface interface; uint8_t uid_len; uint8_t uid[10]; - union { - FuriHalNfcADevData a_data; - FuriHalNfcFDevData f_data; - }; + uint32_t cuid; + uint8_t atqa[2]; + uint8_t sak; } FuriHalNfcDevData; typedef void ( diff --git a/lib/nfc/helpers/nfc_generators.c b/lib/nfc/helpers/nfc_generators.c index 90bfbec9d..50c89aba8 100644 --- a/lib/nfc/helpers/nfc_generators.c +++ b/lib/nfc/helpers/nfc_generators.c @@ -83,9 +83,9 @@ static void nfc_generate_mf_ul_common(NfcDeviceData* data) { data->nfc_data.interface = FuriHalNfcInterfaceRf; data->nfc_data.uid_len = 7; nfc_generate_mf_ul_uid(data->nfc_data.uid); - data->nfc_data.a_data.atqa[0] = 0x44; - data->nfc_data.a_data.atqa[1] = 0x00; - data->nfc_data.a_data.sak = 0x00; + data->nfc_data.atqa[0] = 0x44; + data->nfc_data.atqa[1] = 0x00; + data->nfc_data.sak = 0x00; data->protocol = NfcDeviceProtocolMifareUl; } @@ -94,15 +94,9 @@ static void data->nfc_data.type = FuriHalNfcTypeA; data->nfc_data.interface = FuriHalNfcInterfaceRf; data->nfc_data.uid_len = uid_len; - data->nfc_data.a_data.atqa[0] = 0x44; - data->nfc_data.a_data.atqa[1] = 0x00; - data->nfc_data.a_data.sak = 0x08; - nfc_generate_mf_classic_block_0( - data->mf_classic_data.block[0].value, - uid_len, - data->nfc_data.a_data.sak, - data->nfc_data.a_data.atqa[0], - data->nfc_data.a_data.atqa[1]); + data->nfc_data.atqa[0] = 0x44; + data->nfc_data.atqa[1] = 0x00; + data->nfc_data.sak = 0x08; data->protocol = NfcDeviceProtocolMifareClassic; data->mf_classic_data.type = type; } @@ -256,9 +250,9 @@ static void mful->data_size = num_pages * 4; mful->data_read = mful->data_size; memcpy(mful->data, data->nfc_data.uid, data->nfc_data.uid_len); - mful->data[7] = data->nfc_data.a_data.sak; - mful->data[8] = data->nfc_data.a_data.atqa[0]; - mful->data[9] = data->nfc_data.a_data.atqa[1]; + mful->data[7] = data->nfc_data.sak; + mful->data[8] = data->nfc_data.atqa[0]; + mful->data[9] = data->nfc_data.atqa[1]; uint16_t config_register_page; uint16_t session_register_page; @@ -364,7 +358,7 @@ void nfc_generate_mf_classic(NfcDeviceData* data, uint8_t uid_len, MfClassicType mf_classic_set_block_read(mfc, i, &mfc->block[i]); } // Set SAK to 18 - data->nfc_data.a_data.sak = 0x18; + data->nfc_data.sak = 0x18; } else if(type == MfClassicType1k) { // Set every block to 0xFF for(uint16_t i = 1; i < MF_CLASSIC_1K_TOTAL_SECTORS_NUM * 4; i += 1) { @@ -376,7 +370,7 @@ void nfc_generate_mf_classic(NfcDeviceData* data, uint8_t uid_len, MfClassicType mf_classic_set_block_read(mfc, i, &mfc->block[i]); } // Set SAK to 08 - data->nfc_data.a_data.sak = 0x08; + data->nfc_data.sak = 0x08; } else if(type == MfClassicTypeMini) { // Set every block to 0xFF for(uint16_t i = 1; i < MF_MINI_TOTAL_SECTORS_NUM * 4; i += 1) { @@ -388,15 +382,15 @@ void nfc_generate_mf_classic(NfcDeviceData* data, uint8_t uid_len, MfClassicType mf_classic_set_block_read(mfc, i, &mfc->block[i]); } // Set SAK to 09 - data->nfc_data.a_data.sak = 0x09; + data->nfc_data.sak = 0x09; } nfc_generate_mf_classic_block_0( data->mf_classic_data.block[0].value, uid_len, - data->nfc_data.a_data.sak, - data->nfc_data.a_data.atqa[0], - data->nfc_data.a_data.atqa[1]); + data->nfc_data.sak, + data->nfc_data.atqa[0], + data->nfc_data.atqa[1]); mfc->type = type; } diff --git a/lib/nfc/helpers/reader_analyzer.c b/lib/nfc/helpers/reader_analyzer.c index c8f9c2c7e..e01e60d49 100644 --- a/lib/nfc/helpers/reader_analyzer.c +++ b/lib/nfc/helpers/reader_analyzer.c @@ -56,11 +56,13 @@ struct ReaderAnalyzer { static FuriHalNfcDevData reader_analyzer_nfc_data[] = { [ReaderAnalyzerNfcDataMfClassic] = - {.interface = FuriHalNfcInterfaceRf, + {.sak = 0x08, + .atqa = {0x44, 0x00}, + .interface = FuriHalNfcInterfaceRf, .type = FuriHalNfcTypeA, .uid_len = READER_ANALYZER_UID_SIZE, .uid = {0x04, 0x77, 0x70, 0x2A, 0x23, 0x4F, 0x80}, - .a_data = {.sak = 0x08, .atqa = {0x44, 0x00}, .cuid = 0x2A234F80}}, + .cuid = 0x2A234F80}, }; void reader_analyzer_parse(ReaderAnalyzer* instance, uint8_t* buffer, size_t size) { @@ -122,7 +124,7 @@ ReaderAnalyzer* reader_analyzer_alloc() { reader_analyzer_nfc_data[ReaderAnalyzerNfcDataMfClassic].uid, Uid.full_uid, READER_ANALYZER_UID_SIZE); - reader_analyzer_nfc_data[ReaderAnalyzerNfcDataMfClassic].a_data.cuid = + reader_analyzer_nfc_data[ReaderAnalyzerNfcDataMfClassic].cuid = nfc_util_bytes2num(Uid.uid_converter.cuid, READER_ANALYZER_CUID_SIZE); instance->nfc_data = reader_analyzer_nfc_data[ReaderAnalyzerNfcDataMfClassic]; @@ -156,7 +158,7 @@ void reader_analyzer_start(ReaderAnalyzer* instance, ReaderAnalyzerMode mode) { instance->debug_log = nfc_debug_log_alloc(); } if(mode & ReaderAnalyzerModeMfkey) { - instance->mfkey32 = mfkey32_alloc(instance->nfc_data.a_data.cuid); + instance->mfkey32 = mfkey32_alloc(instance->nfc_data.cuid); if(instance->mfkey32) { mfkey32_set_callback(instance->mfkey32, reader_analyzer_mfkey_callback, instance); } diff --git a/lib/nfc/nfc_device.c b/lib/nfc/nfc_device.c index 38bb767cd..cd9eb336c 100644 --- a/lib/nfc/nfc_device.c +++ b/lib/nfc/nfc_device.c @@ -20,7 +20,6 @@ static const uint32_t nfc_keys_file_version = 1; // Protocols format versions static const uint32_t nfc_mifare_classic_data_format_version = 2; static const uint32_t nfc_mifare_ultralight_data_format_version = 1; -static const uint32_t nfc_felica_data_format_version = 1; NfcDevice* nfc_device_alloc() { NfcDevice* nfc_dev = malloc(sizeof(NfcDevice)); @@ -61,8 +60,6 @@ static void nfc_device_prepare_format_string(NfcDevice* dev, FuriString* format_ furi_string_set(format_string, "Mifare DESFire"); } else if(dev->format == NfcDeviceSaveFormatNfcV) { furi_string_set(format_string, "ISO15693"); - } else if(dev->format == NfcDeviceSaveFormatFelica) { - furi_string_set(format_string, "FeliCa"); } else { furi_string_set(format_string, "Unknown"); } @@ -1129,211 +1126,6 @@ static bool nfc_device_save_mifare_classic_data(FlipperFormat* file, NfcDevice* return saved; } -static bool nfc_device_save_felica_lite(FlipperFormat* file, FelicaLiteInfo* info) { - bool saved = false; - FuriString* key = furi_string_alloc(); - FuriString* temp = furi_string_alloc(); - - do { - flipper_format_write_comment_cstr(file, "Lite(-S) System"); - flipper_format_write_hex( - file, "Data Format Code", (uint8_t*)&info->data_format_code, sizeof(uint16_t)); - flipper_format_write_hex(file, "ID Arbitrary Value", info->ID_value, 6); - flipper_format_write_hex(file, "Memory Config", info->memory_config, FELICA_BLOCK_SIZE); - - for(uint8_t block_num = 0; block_num < 14; block_num++) { - furi_string_reset(temp); - for(size_t i = 0; i < FELICA_BLOCK_SIZE; i++) { - if(info->S_PAD[block_num] != NULL) { - furi_string_cat_printf(temp, "%02X ", info->S_PAD[block_num][i]); - } else { - furi_string_cat_printf(temp, "?? "); - } - } - - furi_string_printf(key, "S_PAD%d", block_num); - flipper_format_write_string(file, furi_string_get_cstr(key), temp); - } - - furi_string_reset(temp); - for(size_t i = 0; i < FELICA_BLOCK_SIZE; i++) { - if(info->REG != NULL) { - furi_string_cat_printf(temp, "%02X ", info->REG[i]); - } else { - furi_string_cat_printf(temp, "?? "); - } - } - flipper_format_write_string(file, "REG", temp); - - flipper_format_write_hex( - file, "Card Key Version", (uint8_t*)&info->card_key_version, sizeof(uint16_t)); - furi_string_reset(temp); - for(size_t i = 0; i < FELICA_BLOCK_SIZE; i++) { - if(info->REG != NULL) { - furi_string_cat_printf(temp, "%02X ", info->card_key_1[i]); - } else { - furi_string_cat_printf(temp, "?? "); - } - } - flipper_format_write_string(file, "Card Key 1", temp); - - furi_string_reset(temp); - for(size_t i = 0; i < FELICA_BLOCK_SIZE; i++) { - if(info->REG != NULL) { - furi_string_cat_printf(temp, "%02X ", info->card_key_2[i]); - } else { - furi_string_cat_printf(temp, "?? "); - } - } - flipper_format_write_string(file, "Card Key 2", temp); - - flipper_format_write_hex(file, "Fixed Challenge MAC Response", info->MAC, 8); - - flipper_format_write_bool(file, "Is Lite-S", &info->is_lite_s, 1); - if(info->is_lite_s) { - flipper_format_write_hex(file, "Fixed Challenge MAC-A Response", info->MAC_A, 8); - flipper_format_write_uint32(file, "Write Count", &info->write_count, 1); - } - - } while(false); - - furi_string_free(temp); - furi_string_free(key); - return saved; -} - -static bool nfc_device_save_felica_node(FlipperFormat* file, FelicaNode* node); - -static bool nfc_device_save_felica_area(FlipperFormat* file, FelicaArea* area) { - bool saved = false; - FuriString* prefix = furi_string_alloc_printf("Area %d", area->number); - FuriString* key = furi_string_alloc(); - - do { - furi_string_printf(key, "%s Can Create Subareas", furi_string_get_cstr(prefix)); - flipper_format_write_bool(file, furi_string_get_cstr(key), &area->can_create_subareas, 1); - furi_string_printf(key, "%s End Service Code", furi_string_get_cstr(prefix)); - flipper_format_write_hex( - file, furi_string_get_cstr(key), (uint8_t*)&area->end_service_code, sizeof(uint16_t)); - - bool node_saved = true; - for - M_EACH(node, area->nodes, FelicaNodeArray_t) { - if(nfc_device_save_felica_node(file, node)) { - node_saved = false; - break; - } - } - - if(!node_saved) break; - saved = true; - } while(false); - - furi_string_free(prefix); - furi_string_free(key); - return saved; -} - -static bool nfc_device_save_felica_service(FlipperFormat* file, FelicaService* service) { - bool saved = false; - FuriString* prefix = furi_string_alloc_printf("Service %d", service->number); - FuriString* key = furi_string_alloc(); - - do { - furi_string_printf(key, "%s Is Extended Overlap", furi_string_get_cstr(prefix)); - flipper_format_write_bool( - file, furi_string_get_cstr(key), &service->is_extended_overlap, 1); - if(service->is_extended_overlap) { - furi_string_printf(key, "%s Overlap Target", furi_string_get_cstr(prefix)); - flipper_format_write_hex( - file, - furi_string_get_cstr(key), - (uint8_t*)&service->overlap_target, - sizeof(uint16_t)); - - furi_string_printf(key, "%s Block Start", furi_string_get_cstr(prefix)); - const uint32_t block_start = service->block_start; - flipper_format_write_uint32(file, furi_string_get_cstr(key), &block_start, 1); - - furi_string_printf(key, "%s Block Count", furi_string_get_cstr(prefix)); - const uint32_t block_count = service->block_count; - flipper_format_write_uint32(file, furi_string_get_cstr(key), &block_count, 1); - - uint32_t i = 0; - for - M_EACH(block, service->blocks, FelicaBlockArray_t) { - furi_string_printf(key, "%s Block %ld", furi_string_get_cstr(prefix), i); - flipper_format_write_hex( - file, furi_string_get_cstr(key), block->data, FELICA_BLOCK_SIZE); - } - } else { - furi_string_printf(key, "%s Block Count", furi_string_get_cstr(prefix)); - uint32_t block_count = FelicaBlockArray_size(service->blocks); - flipper_format_write_uint32(file, furi_string_get_cstr(key), &block_count, 1); - uint32_t i = 0; - for - M_EACH(block, service->blocks, FelicaBlockArray_t) { - furi_string_printf(key, "%s Block %ld", furi_string_get_cstr(prefix), i); - flipper_format_write_hex( - file, furi_string_get_cstr(key), block->data, FELICA_BLOCK_SIZE); - } - } - - saved = true; - } while(false); - - furi_string_free(prefix); - furi_string_free(key); - return saved; -} - -static bool nfc_device_save_felica_node(FlipperFormat* file, FelicaNode* node) { - bool saved = false; - - do { - if(node->type == FelicaNodeTypeArea) { - if(!nfc_device_save_felica_area(file, node->area)) { - saved = false; - break; - } - } else if(node->type == FelicaNodeTypeService) { - if(!nfc_device_save_felica_service(file, node->service)) { - saved = false; - break; - } - } - - saved = true; - } while(false); - - return saved; -} - -static bool nfc_device_save_felica_data(FlipperFormat* file, NfcDevice* dev) { - bool saved = false; - FelicaData* data = &dev->dev_data.felica_data; - // Save FeliCa specific data - do { - if(!flipper_format_write_comment_cstr(file, "FeliCa specific data")) break; - if(!flipper_format_write_uint32( - file, "Data format version", &nfc_felica_data_format_version, 1)) - break; - - for - M_EACH(system, data->systems, FelicaSystemArray_t) { - flipper_format_write_hex(file, "System", &system->number, sizeof(uint8_t)); - flipper_format_write_hex(file, "Code", (uint8_t*)&system->code, sizeof(uint16_t)); - if(system->code == LITE_SYSTEM_CODE) { - nfc_device_save_felica_lite(file, &system->lite_info); - } else { - nfc_device_save_felica_node(file, &system->root); - } - } - } while(false); - - return saved; -} - static void nfc_device_load_mifare_classic_block( FuriString* block_str, MfClassicData* data, @@ -1622,43 +1414,39 @@ bool nfc_device_save(NfcDevice* dev, const char* dev_name) { if(!flipper_format_write_header_cstr(file, nfc_file_header, nfc_file_version)) break; // Write nfc device type if(!flipper_format_write_comment_cstr( - file, - "Nfc device type can be UID, Mifare Ultralight, Mifare Classic, FeliCa or ISO15693")) + file, "Nfc device type can be UID, Mifare Ultralight, Mifare Classic or ISO15693")) break; nfc_device_prepare_format_string(dev, temp_str); if(!flipper_format_write_string(file, "Device type", temp_str)) break; - if(data->type == FuriHalNfcTypeA) { - if(!flipper_format_write_comment_cstr(file, "UID is common for all formats")) break; - if(!flipper_format_write_hex(file, "UID", data->uid, data->uid_len)) break; + // Write UID + if(!flipper_format_write_comment_cstr(file, "UID is common for all formats")) break; + if(!flipper_format_write_hex(file, "UID", data->uid, data->uid_len)) break; - if(dev->format != NfcDeviceSaveFormatNfcV) { - // Write ATQA, SAK - if(!flipper_format_write_comment_cstr(file, "ISO14443 specific fields")) break; - // Save ATQA in MSB order for correct companion apps display - uint8_t atqa[2] = {data->a_data.atqa[1], data->a_data.atqa[0]}; - if(!flipper_format_write_hex(file, "ATQA", atqa, 2)) break; - if(!flipper_format_write_hex(file, "SAK", &data->a_data.sak, 1)) break; - } - - // Save more data if necessary - if(dev->format == NfcDeviceSaveFormatMifareUl) { - if(!nfc_device_save_mifare_ul_data(file, dev)) break; - } else if(dev->format == NfcDeviceSaveFormatMifareDesfire) { - if(!nfc_device_save_mifare_df_data(file, dev)) break; - } else if(dev->format == NfcDeviceSaveFormatNfcV) { - if(!nfc_device_save_nfcv_data(file, dev)) break; - } else if(dev->format == NfcDeviceSaveFormatBankCard) { - if(!nfc_device_save_bank_card_data(file, dev)) break; - } else if(dev->format == NfcDeviceSaveFormatMifareClassic) { - // Save data - if(!nfc_device_save_mifare_classic_data(file, dev)) break; - // Save keys cache - if(!nfc_device_save_mifare_classic_keys(dev)) break; - } - saved = true; - } else if(data->type == FuriHalNfcTypeF) { - if(!nfc_device_save_felica_data(file, dev)) break; + if(dev->format != NfcDeviceSaveFormatNfcV) { + // Write ATQA, SAK + if(!flipper_format_write_comment_cstr(file, "ISO14443 specific fields")) break; + // Save ATQA in MSB order for correct companion apps display + uint8_t atqa[2] = {data->atqa[1], data->atqa[0]}; + if(!flipper_format_write_hex(file, "ATQA", atqa, 2)) break; + if(!flipper_format_write_hex(file, "SAK", &data->sak, 1)) break; } + + // Save more data if necessary + if(dev->format == NfcDeviceSaveFormatMifareUl) { + if(!nfc_device_save_mifare_ul_data(file, dev)) break; + } else if(dev->format == NfcDeviceSaveFormatMifareDesfire) { + if(!nfc_device_save_mifare_df_data(file, dev)) break; + } else if(dev->format == NfcDeviceSaveFormatNfcV) { + if(!nfc_device_save_nfcv_data(file, dev)) break; + } else if(dev->format == NfcDeviceSaveFormatBankCard) { + if(!nfc_device_save_bank_card_data(file, dev)) break; + } else if(dev->format == NfcDeviceSaveFormatMifareClassic) { + // Save data + if(!nfc_device_save_mifare_classic_data(file, dev)) break; + // Save keys cache + if(!nfc_device_save_mifare_classic_keys(dev)) break; + } + saved = true; } while(0); if(!saved) { //-V547 @@ -1731,22 +1519,22 @@ static bool nfc_device_load_data(NfcDevice* dev, FuriString* path, bool show_dia if(!flipper_format_read_hex(file, "UID", data->uid, data->uid_len)) break; if(dev->format != NfcDeviceSaveFormatNfcV) { if(version == version_with_lsb_atqa) { - if(!flipper_format_read_hex(file, "ATQA", data->a_data.atqa, 2)) break; + if(!flipper_format_read_hex(file, "ATQA", data->atqa, 2)) break; } else { uint8_t atqa[2] = {}; if(!flipper_format_read_hex(file, "ATQA", atqa, 2)) break; - data->a_data.atqa[0] = atqa[1]; - data->a_data.atqa[1] = atqa[0]; + data->atqa[0] = atqa[1]; + data->atqa[1] = atqa[0]; } - if(!flipper_format_read_hex(file, "SAK", &data->a_data.sak, 1)) break; + if(!flipper_format_read_hex(file, "SAK", &data->sak, 1)) break; } // Load CUID uint8_t* cuid_start = data->uid; if(data->uid_len == 7) { cuid_start = &data->uid[3]; } - data->a_data.cuid = (cuid_start[0] << 24) | (cuid_start[1] << 16) | (cuid_start[2] << 8) | - (cuid_start[3]); + data->cuid = (cuid_start[0] << 24) | (cuid_start[1] << 16) | (cuid_start[2] << 8) | + (cuid_start[3]); // Parse other data if(dev->format == NfcDeviceSaveFormatMifareUl) { if(!nfc_device_load_mifare_ul_data(file, dev)) break; @@ -1842,8 +1630,6 @@ void nfc_device_data_clear(NfcDeviceData* dev_data) { mf_ul_reset(&dev_data->mf_ul_data); } else if(dev_data->protocol == NfcDeviceProtocolEMV) { memset(&dev_data->emv_data, 0, sizeof(EmvData)); - } else if(dev_data->protocol == NfcDeviceProtocolFelica) { - felica_clear(&dev_data->felica_data); } memset(&dev_data->nfc_data, 0, sizeof(FuriHalNfcDevData)); dev_data->protocol = NfcDeviceProtocolUnknown; diff --git a/lib/nfc/nfc_device.h b/lib/nfc/nfc_device.h index 793f733e4..6617171e7 100644 --- a/lib/nfc/nfc_device.h +++ b/lib/nfc/nfc_device.h @@ -12,8 +12,6 @@ #include #include #include -#include -#include #ifdef __cplusplus extern "C" { @@ -35,7 +33,6 @@ typedef enum { NfcDeviceProtocolMifareClassic, NfcDeviceProtocolMifareDesfire, NfcDeviceProtocolNfcV, - NfcDeviceProtocolFelica, } NfcProtocol; typedef enum { @@ -45,7 +42,6 @@ typedef enum { NfcDeviceSaveFormatMifareClassic, NfcDeviceSaveFormatMifareDesfire, NfcDeviceSaveFormatNfcV, - NfcDeviceSaveFormatFelica, } NfcDeviceSaveFormat; typedef struct { @@ -65,8 +61,6 @@ typedef enum { NfcReadModeMfDesfire, NfcReadModeEMV, NfcReadModeNFCA, - NfcReadModeFelica, - NfcReadModeNFCF, } NfcReadMode; typedef struct { @@ -84,7 +78,6 @@ typedef struct { MfClassicData mf_classic_data; MifareDesfireData mf_df_data; NfcVData nfcv_data; - FelicaData felica_data; }; FuriString* parsed_data; } NfcDeviceData; diff --git a/lib/nfc/nfc_types.c b/lib/nfc/nfc_types.c index de44f4703..96b92640f 100644 --- a/lib/nfc/nfc_types.c +++ b/lib/nfc/nfc_types.c @@ -67,63 +67,3 @@ const char* nfc_mf_classic_type(MfClassicType type) { return "Mifare Classic"; } } - -const char* nfc_felica_type(FelicaICType type) { - if(type == FelicaICType576B) { - return "FeliCa Classic 576B"; - } else if(type == FelicaICType2K) { - return "FeliCa Classic 2K"; - } else if(type == FelicaICType4K) { - return "FeliCa Classic 4K"; - } else if(type == FelicaICTypeFRAM_4K) { - return "FeliCa Classic 4K (FRAM)"; - } else if(type == FelicaICTypeFRAM_9K) { - return "FeliCa Classic 9K"; - } else if(type == FelicaICTypeEMV_16K) { - return "FeliCa Classic EMV 16K"; - } else if(type == FelicaICTypeEMV_32K) { - return "FeliCa Classic EMV 32K"; - } else if(type == FelicaICTypeEMV_36K) { - return "FeliCa Classic EMV 36K"; - } else if(type == FelicaICTypeEMV_36K) { - return "FeliCa Classic EMV 36K"; - } else if(type == FelicaICTypeSD1WithDES) { - return "FeliCa SD1 (DES compatible)"; - } else if(type == FelicaICTypeSD1) { - return "FeliCa SD1"; - } else if(type == FelicaICTypeRC_SA08) { - return "FeliCa RC-SA08"; - } else if(type == FelicaICTypeSD2WithDES) { - return "FeliCa SD2 (DES compatible)"; - } else if(type == FelicaICTypeSD2_4K) { - return "FeliCa SD2 4K"; - } else if(type == FelicaICTypeSD2_6K) { - return "FeliCa SD2 6K"; - } else if(type == FelicaICTypeRC_SA24_6K) { - return "FeliCa RC-SA24 6K"; - } else if(type == FelicaICTypeRC_SA24_10K) { - return "FeliCa RC-SA24 6K"; - } else if(type == FelicaICTypeMobileIC_V1) { - return "Mobile FeliCa v1"; - } else if(type == FelicaICTypeMobileIC_V2) { - return "Mobile FeliCa v2"; - } else if(type == FelicaICTypeMobileIC_V3) { - return "Mobile FeliCa v3"; - } else if(type == FelicaICTypeMobileIC_V4) { - return "Mobile FeliCa v4"; - } else if(type == FelicaICTypeMobileIC_V4_1) { - return "Mobile FeliCa v4.1"; - } else if(type == FelicaICTypeLite) { - return "FeliCa Lite"; - } else if(type == FelicaICTypeLiteS) { - return "FeliCa Lite-S"; - } else if(type == FelicaICTypeLink) { - return "FeliCa Link"; - } else if(type == FelicaICTypePlug) { - return "FeliCa Plug"; - } else if(type == FelicaICTypeSuica) { - return "FeliCa (SuiCa)"; - } else { - return "FeliCa"; - } -} diff --git a/lib/nfc/nfc_types.h b/lib/nfc/nfc_types.h index 206d99fde..19dc15759 100644 --- a/lib/nfc/nfc_types.h +++ b/lib/nfc/nfc_types.h @@ -14,7 +14,6 @@ const char* nfc_mf_ul_type(MfUltralightType type, bool full_name); const char* nfc_mf_classic_type(MfClassicType type); -const char* nfc_felica_type(FelicaICType type); #ifdef __cplusplus } #endif diff --git a/lib/nfc/nfc_worker.c b/lib/nfc/nfc_worker.c index bc97d743d..77be3fb0d 100644 --- a/lib/nfc/nfc_worker.c +++ b/lib/nfc/nfc_worker.c @@ -545,20 +545,20 @@ static bool nfc_worker_read_bank_card(NfcWorker* nfc_worker, FuriHalNfcTxRxConte static bool nfc_worker_read_nfca(NfcWorker* nfc_worker, FuriHalNfcTxRxContext* tx_rx) { FuriHalNfcDevData* nfc_data = &nfc_worker->dev_data->nfc_data; - FuriHalNfcADevData* a_data = &nfc_data->a_data; bool card_read = false; furi_hal_nfc_sleep(); - if(mf_ul_check_card_type(a_data)) { + if(mf_ul_check_card_type(nfc_data->atqa[0], nfc_data->atqa[1], nfc_data->sak)) { FURI_LOG_I(TAG, "Mifare Ultralight / NTAG detected"); nfc_worker->dev_data->protocol = NfcDeviceProtocolMifareUl; card_read = nfc_worker_read_mf_ultralight(nfc_worker, tx_rx); - } else if(mf_classic_check_card_type(a_data)) { + } else if(mf_classic_check_card_type(nfc_data->atqa[0], nfc_data->atqa[1], nfc_data->sak)) { FURI_LOG_I(TAG, "Mifare Classic detected"); nfc_worker->dev_data->protocol = NfcDeviceProtocolMifareClassic; - nfc_worker->dev_data->mf_classic_data.type = mf_classic_get_classic_type(a_data); + nfc_worker->dev_data->mf_classic_data.type = + mf_classic_get_classic_type(nfc_data->atqa[0], nfc_data->atqa[1], nfc_data->sak); card_read = nfc_worker_read_mf_classic(nfc_worker, tx_rx); - } else if(mf_df_check_card_type(a_data)) { + } else if(mf_df_check_card_type(nfc_data->atqa[0], nfc_data->atqa[1], nfc_data->sak)) { FURI_LOG_I(TAG, "Mifare DESFire detected"); nfc_worker->dev_data->protocol = NfcDeviceProtocolMifareDesfire; if(!nfc_worker_read_mf_desfire(nfc_worker, tx_rx)) { @@ -582,46 +582,6 @@ static bool nfc_worker_read_nfca(NfcWorker* nfc_worker, FuriHalNfcTxRxContext* t return card_read; } -static bool nfc_worker_read_felica(NfcWorker* nfc_worker, FuriHalNfcTxRxContext* tx_rx) { - bool read_success = false; - FuriHalNfcDevData* nfc_data = &nfc_worker->dev_data->nfc_data; - FelicaData* data = &nfc_worker->dev_data->felica_data; - - if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug)) { - reader_analyzer_prepare_tx_rx(nfc_worker->reader_analyzer, tx_rx, false); - reader_analyzer_start(nfc_worker->reader_analyzer, ReaderAnalyzerModeDebugLog); - } - - do { - if(!furi_hal_nfc_detect(&nfc_worker->dev_data->nfc_data, 300)) break; - if(!felica_read_card(tx_rx, data, nfc_data->uid, nfc_data->f_data.pmm)) break; - read_success = true; - } while(false); - - if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug)) { - reader_analyzer_stop(nfc_worker->reader_analyzer); - } - - return read_success; -} - -static bool nfc_worker_read_nfcf(NfcWorker* nfc_worker, FuriHalNfcTxRxContext* tx_rx) { - FuriHalNfcDevData* nfc_data = &nfc_worker->dev_data->nfc_data; - FuriHalNfcFDevData* f_data = &nfc_data->f_data; - - bool card_read = false; - furi_hal_nfc_sleep(); - if(felica_check_ic_type(f_data->pmm)) { - FURI_LOG_I(TAG, "FeliCa detected"); - nfc_worker->dev_data->protocol = NfcDeviceProtocolFelica; - nfc_worker->dev_data->felica_data.type = felica_get_ic_type(f_data->pmm); - card_read = nfc_worker_read_felica(nfc_worker, tx_rx); - } else { - nfc_worker->dev_data->protocol = NfcDeviceProtocolUnknown; - } - return card_read; -} - void nfc_worker_read(NfcWorker* nfc_worker) { furi_assert(nfc_worker); furi_assert(nfc_worker->callback); @@ -666,11 +626,6 @@ void nfc_worker_read(NfcWorker* nfc_worker) { event = NfcWorkerEventReadUidNfcB; break; } else if(nfc_data->type == FuriHalNfcTypeF) { - nfc_worker->callback(NfcWorkerEventCardDetected, nfc_worker->context); - if(nfc_worker_read_nfcf(nfc_worker, &tx_rx)) { - event = NfcWorkerEventReadFelica; - break; - } event = NfcWorkerEventReadUidNfcF; break; } else if(nfc_data->type == FuriHalNfcTypeV) { @@ -719,8 +674,8 @@ void nfc_worker_read_type(NfcWorker* nfc_worker) { if(nfc_data->type == FuriHalNfcTypeA) { if(read_mode == NfcReadModeMfClassic) { nfc_worker->dev_data->protocol = NfcDeviceProtocolMifareClassic; - nfc_worker->dev_data->mf_classic_data.type = - mf_classic_get_classic_type(&nfc_data->a_data); + nfc_worker->dev_data->mf_classic_data.type = mf_classic_get_classic_type( + nfc_data->atqa[0], nfc_data->atqa[1], nfc_data->sak); if(nfc_worker_read_mf_classic(nfc_worker, &tx_rx)) { FURI_LOG_D(TAG, "Card read"); dev_data->protocol = NfcDeviceProtocolMifareClassic; @@ -756,21 +711,6 @@ void nfc_worker_read_type(NfcWorker* nfc_worker) { event = NfcWorkerEventReadUidNfcA; break; } - } else if(nfc_data->type == FuriHalNfcTypeF) { - if(read_mode == NfcReadModeFelica) { - nfc_worker->dev_data->protocol = NfcDeviceProtocolFelica; - if(nfc_worker_read_felica(nfc_worker, &tx_rx)) { - nfc_worker->dev_data->protocol = NfcDeviceProtocolFelica; - if(nfc_worker_read_felica(nfc_worker, &tx_rx)) { - event = NfcWorkerEventReadFelica; - break; - } - } - } else if(read_mode == NfcReadModeNFCF) { - nfc_worker->dev_data->protocol = NfcDeviceProtocolUnknown; - event = NfcWorkerEventReadUidNfcF; - break; - } } } else { if(!card_not_detected_notified) { @@ -796,8 +736,7 @@ void nfc_worker_emulate_uid(NfcWorker* nfc_worker) { // Need to save ATS to support ISO-14443A-4 emulation while(nfc_worker->state == NfcWorkerStateUidEmulate) { - if(furi_hal_nfc_listen( - data->uid, data->uid_len, data->a_data.atqa, data->a_data.sak, false, 100)) { + if(furi_hal_nfc_listen(data->uid, data->uid_len, data->atqa, data->sak, false, 100)) { if(furi_hal_nfc_tx_rx(&tx_rx, 100)) { reader_data->size = tx_rx.rx_bits / 8; if(reader_data->size > 0) { @@ -818,11 +757,8 @@ void nfc_worker_emulate_apdu(NfcWorker* nfc_worker) { FuriHalNfcDevData params = { .uid = {0xCF, 0x72, 0xd4, 0x40}, .uid_len = 4, - .a_data = - { - .atqa = {0x00, 0x04}, - .sak = 0x20, - }, + .atqa = {0x00, 0x04}, + .sak = 0x20, .type = FuriHalNfcTypeA, }; @@ -832,8 +768,7 @@ void nfc_worker_emulate_apdu(NfcWorker* nfc_worker) { } while(nfc_worker->state == NfcWorkerStateEmulateApdu) { //-V1044 - if(furi_hal_nfc_listen( - params.uid, params.uid_len, params.a_data.atqa, params.a_data.sak, false, 300)) { + if(furi_hal_nfc_listen(params.uid, params.uid_len, params.atqa, params.sak, false, 300)) { FURI_LOG_D(TAG, "POS terminal detected"); if(emv_card_emulation(&tx_rx)) { FURI_LOG_D(TAG, "EMV card emulated"); @@ -876,8 +811,8 @@ void nfc_worker_emulate_mf_ultralight(NfcWorker* nfc_worker) { furi_hal_nfc_emulate_nfca( nfc_data->uid, nfc_data->uid_len, - nfc_data->a_data.atqa, - nfc_data->a_data.sak, + nfc_data->atqa, + nfc_data->sak, mf_ul_prepare_emulation_response, &emulator, 5000); @@ -1209,7 +1144,8 @@ void nfc_worker_write_mf_classic(NfcWorker* nfc_worker) { } FURI_LOG_I(TAG, "Check mf classic type"); - MfClassicType type = mf_classic_get_classic_type(&nfc_data.a_data); + MfClassicType type = + mf_classic_get_classic_type(nfc_data.atqa[0], nfc_data.atqa[1], nfc_data.sak); if(type != nfc_worker->dev_data->mf_classic_data.type) { FURI_LOG_E(TAG, "Wrong mf classic type"); nfc_worker->callback(NfcWorkerEventWrongCard, nfc_worker->context); @@ -1281,7 +1217,8 @@ void nfc_worker_update_mf_classic(NfcWorker* nfc_worker) { } FURI_LOG_I(TAG, "Check MF classic type"); - MfClassicType type = mf_classic_get_classic_type(&nfc_data.a_data); + MfClassicType type = + mf_classic_get_classic_type(nfc_data.atqa[0], nfc_data.atqa[1], nfc_data.sak); if(type != nfc_worker->dev_data->mf_classic_data.type) { FURI_LOG_E(TAG, "MF classic type mismatch"); nfc_worker->callback(NfcWorkerEventWrongCard, nfc_worker->context); @@ -1343,7 +1280,7 @@ void nfc_worker_mf_ultralight_read_auth(NfcWorker* nfc_worker) { while(nfc_worker->state == NfcWorkerStateReadMfUltralightReadAuth) { furi_hal_nfc_sleep(); if(furi_hal_nfc_detect(nfc_data, 300) && nfc_data->type == FuriHalNfcTypeA) { - if(mf_ul_check_card_type(&nfc_data->a_data)) { + if(mf_ul_check_card_type(nfc_data->atqa[0], nfc_data->atqa[1], nfc_data->sak)) { nfc_worker->callback(NfcWorkerEventCardDetected, nfc_worker->context); if(data->auth_method == MfUltralightAuthMethodManual || data->auth_method == MfUltralightAuthMethodAuto) { diff --git a/lib/nfc/nfc_worker.h b/lib/nfc/nfc_worker.h index 3407a2d7c..ec740d15d 100644 --- a/lib/nfc/nfc_worker.h +++ b/lib/nfc/nfc_worker.h @@ -42,7 +42,6 @@ typedef enum { NfcWorkerEventReadUidNfcV, NfcWorkerEventReadUidNfcF, NfcWorkerEventReadUidNfcA, - NfcWorkerEventReadFelica, NfcWorkerEventReadMfUltralight, NfcWorkerEventReadMfDesfire, NfcWorkerEventReadMfClassicDone, diff --git a/lib/nfc/nfc_worker_i.h b/lib/nfc/nfc_worker_i.h index eda42c313..d13d3c5c8 100644 --- a/lib/nfc/nfc_worker_i.h +++ b/lib/nfc/nfc_worker_i.h @@ -11,7 +11,6 @@ #include #include #include -#include #include #include #include diff --git a/lib/nfc/parsers/plantain_4k_parser.c b/lib/nfc/parsers/plantain_4k_parser.c index 3990461fc..19da0b5eb 100644 --- a/lib/nfc/parsers/plantain_4k_parser.c +++ b/lib/nfc/parsers/plantain_4k_parser.c @@ -70,8 +70,8 @@ bool plantain_4k_parser_read(NfcWorker* nfc_worker, FuriHalNfcTxRxContext* tx_rx furi_assert(nfc_worker); MfClassicReader reader = {}; - FuriHalNfcADevData* nfc_a_data = &nfc_worker->dev_data->nfc_data.a_data; - reader.type = mf_classic_get_classic_type(nfc_a_data); + FuriHalNfcDevData* nfc_data = &nfc_worker->dev_data->nfc_data; + reader.type = mf_classic_get_classic_type(nfc_data->atqa[0], nfc_data->atqa[1], nfc_data->sak); for(size_t i = 0; i < COUNT_OF(plantain_keys_4k); i++) { mf_classic_reader_add_sector( &reader, diff --git a/lib/nfc/parsers/plantain_parser.c b/lib/nfc/parsers/plantain_parser.c index 758b038e8..2e4091dda 100644 --- a/lib/nfc/parsers/plantain_parser.c +++ b/lib/nfc/parsers/plantain_parser.c @@ -45,8 +45,8 @@ bool plantain_parser_read(NfcWorker* nfc_worker, FuriHalNfcTxRxContext* tx_rx) { furi_assert(nfc_worker); MfClassicReader reader = {}; - FuriHalNfcADevData* nfc_a_data = &nfc_worker->dev_data->nfc_data.a_data; - reader.type = mf_classic_get_classic_type(nfc_a_data); + FuriHalNfcDevData* nfc_data = &nfc_worker->dev_data->nfc_data; + reader.type = mf_classic_get_classic_type(nfc_data->atqa[0], nfc_data->atqa[1], nfc_data->sak); for(size_t i = 0; i < COUNT_OF(plantain_keys); i++) { mf_classic_reader_add_sector( &reader, plantain_keys[i].sector, plantain_keys[i].key_a, plantain_keys[i].key_b); diff --git a/lib/nfc/parsers/troika_4k_parser.c b/lib/nfc/parsers/troika_4k_parser.c index af4b4b3d1..d248feb17 100644 --- a/lib/nfc/parsers/troika_4k_parser.c +++ b/lib/nfc/parsers/troika_4k_parser.c @@ -67,8 +67,8 @@ bool troika_4k_parser_read(NfcWorker* nfc_worker, FuriHalNfcTxRxContext* tx_rx) furi_assert(nfc_worker); MfClassicReader reader = {}; - FuriHalNfcADevData* nfc_a_data = &nfc_worker->dev_data->nfc_data.a_data; - reader.type = mf_classic_get_classic_type(nfc_a_data); + FuriHalNfcDevData* nfc_data = &nfc_worker->dev_data->nfc_data; + reader.type = mf_classic_get_classic_type(nfc_data->atqa[0], nfc_data->atqa[1], nfc_data->sak); for(size_t i = 0; i < COUNT_OF(troika_4k_keys); i++) { mf_classic_reader_add_sector( &reader, troika_4k_keys[i].sector, troika_4k_keys[i].key_a, troika_4k_keys[i].key_b); diff --git a/lib/nfc/parsers/troika_parser.c b/lib/nfc/parsers/troika_parser.c index 17de0d8a5..6d8ae98f3 100644 --- a/lib/nfc/parsers/troika_parser.c +++ b/lib/nfc/parsers/troika_parser.c @@ -43,8 +43,8 @@ bool troika_parser_read(NfcWorker* nfc_worker, FuriHalNfcTxRxContext* tx_rx) { furi_assert(nfc_worker); MfClassicReader reader = {}; - FuriHalNfcADevData* nfc_a_data = &nfc_worker->dev_data->nfc_data.a_data; - reader.type = mf_classic_get_classic_type(nfc_a_data); + FuriHalNfcDevData* nfc_data = &nfc_worker->dev_data->nfc_data; + reader.type = mf_classic_get_classic_type(nfc_data->atqa[0], nfc_data->atqa[1], nfc_data->sak); for(size_t i = 0; i < COUNT_OF(troika_keys); i++) { mf_classic_reader_add_sector( diff --git a/lib/nfc/parsers/two_cities.c b/lib/nfc/parsers/two_cities.c index b6a8bc552..d6d4279dd 100644 --- a/lib/nfc/parsers/two_cities.c +++ b/lib/nfc/parsers/two_cities.c @@ -71,8 +71,8 @@ bool two_cities_parser_read(NfcWorker* nfc_worker, FuriHalNfcTxRxContext* tx_rx) furi_assert(nfc_worker); MfClassicReader reader = {}; - FuriHalNfcADevData* nfc_a_data = &nfc_worker->dev_data->nfc_data.a_data; - reader.type = mf_classic_get_classic_type(nfc_a_data); + FuriHalNfcDevData* nfc_data = &nfc_worker->dev_data->nfc_data; + reader.type = mf_classic_get_classic_type(nfc_data->atqa[0], nfc_data->atqa[1], nfc_data->sak); for(size_t i = 0; i < COUNT_OF(two_cities_keys_4k); i++) { mf_classic_reader_add_sector( &reader, diff --git a/lib/nfc/protocols/felica.c b/lib/nfc/protocols/felica.c deleted file mode 100644 index 182893527..000000000 --- a/lib/nfc/protocols/felica.c +++ /dev/null @@ -1,943 +0,0 @@ -#include -#include -#include -#include "felica.h" -#include "nfc_util.h" -#include -#include "furi_hal_nfc.h" - -#define TAG "FeliCa" - -bool felica_check_ic_type(uint8_t* PMm) { - uint8_t rom_type = PMm[0]; - uint8_t ic_type = PMm[1]; - - bool is_valid_ic = false; - if(ic_type == 0xff) { // RC-S967 in nfc-dep - is_valid_ic = true; - } else if(ic_type == 0xf2) { // RC-S732? - is_valid_ic = true; - } else if(ic_type == 0xf0 || ic_type == 0xf1) { // Lite(S) - is_valid_ic = true; - } else if(ic_type == 0xe1) { // RC-S967 in plug mode - is_valid_ic = true; - } else if(ic_type == 0xe0) { // RC-S926 - is_valid_ic = true; - } else if(ic_type >= 0x44 && ic_type <= 0x48) { // SD2 - is_valid_ic = true; - } else if(ic_type == 0x3e && rom_type == 0x03) { // RC-SA08 - return true; - } else if(ic_type == 0x35) { // RC-SA01 - is_valid_ic = true; - } else if(ic_type == 0x32) { // RC-SA00 - is_valid_ic = true; - } else if(ic_type == 0x31) { // Suica/PASMO - is_valid_ic = true; - } else if(ic_type == 0x20) { // RC-S962 - is_valid_ic = true; - } else if(ic_type >= 0x10 && ic_type <= 0x1f) { // Mobile IC version 2/3 - is_valid_ic = true; - } else if(ic_type == 0x0d) { // RC-S960 - is_valid_ic = true; - } else if(ic_type == 0x0c) { // RC-S954 - is_valid_ic = true; - } else if(ic_type == 0x0b) { // Old Suica? - is_valid_ic = true; - } else if(ic_type == 0x09) { // RC-S953 - is_valid_ic = true; - } else if(ic_type == 0x08) { // RC-S952 - is_valid_ic = true; - } else if(ic_type == 0x06 || ic_type == 0x07) { // Mobile IC version 1 - is_valid_ic = true; - } else if(ic_type == 0x02) { // RC-S919 - is_valid_ic = true; - } else if(ic_type == 0x01) { // RC-S915 - is_valid_ic = true; - } else if(ic_type == 0x00) { // RC-S830 - is_valid_ic = true; - } - - if(!is_valid_ic) { - return false; - } - - // need more samples to confirm below - /* - if (rom_type != 0x01) { - return false; - } - */ - - return true; -} - -FelicaICType felica_get_ic_type(uint8_t* PMm) { - uint8_t rom_type = PMm[0]; - uint8_t ic_type = PMm[1]; - - UNUSED(rom_type); - switch(ic_type) { - case 0xff: - return FelicaICTypeLink; - case 0xf2: - return FelicaICTypeLink; - case 0xf1: - return FelicaICTypeLiteS; - case 0xf0: - return FelicaICTypeLite; - case 0xe1: - return FelicaICTypeLink; - case 0xe0: - return FelicaICTypePlug; - case 0x48: - return FelicaICTypeSD2_6K; - case 0x47: - return FelicaICTypeRC_SA24_6K; - case 0x46: - return FelicaICTypeSD2_4K; - case 0x45: - case 0x44: - return FelicaICTypeSD2WithDES; - case 0x3e: - return FelicaICTypeRC_SA08; - case 0x35: - return FelicaICTypeSD1; - case 0x32: - return FelicaICTypeSD1WithDES; - case 0x31: - return FelicaICTypeSuica; - case 0x20: - return FelicaICTypeFRAM_4K; - case 0x1f: - case 0x1e: - case 0x1d: - case 0x1c: - case 0x1b: - case 0x1a: - case 0x19: - case 0x18: - return FelicaICTypeMobileIC_V4_1; - case 0x17: - return FelicaICTypeMobileIC_V4; - case 0x16: - case 0x15: - case 0x14: - return FelicaICTypeMobileIC_V3; - case 0x13: - case 0x12: - case 0x11: - case 0x10: - return FelicaICTypeMobileIC_V2; - case 0x0d: - return FelicaICTypeFRAM_9K; - case 0x0c: - return FelicaICTypeEMV_36K; - case 0x0b: // Old Suica? - return FelicaICTypeSuica; - case 0x09: - return FelicaICTypeEMV_16K; - case 0x08: - return FelicaICTypeEMV_32K; - case 0x07: - case 0x06: - return FelicaICTypeMobileIC_V1; - case 0x02: - return FelicaICType576B; - case 0x01: - return FelicaICType4K; - case 0x00: - return FelicaICType2K; - } - - return FelicaICType2K; -} - -// static void felica_lite_diversify_key(uint8_t* id_block, uint8_t* master_key, uint8_t* card_key) { -// uint8_t ZERO[8] = {0}; -// uint8_t L[8]; -// mbedtls_des3_context ctx; -// mbedtls_des3_init(&ctx); -// mbedtls_des3_set3key_enc(&ctx, master_key); -// mbedtls_des3_crypt_ecb(&ctx, ZERO, L); -// mbedtls_des3_free(&ctx); - -// uint8_t K1[8]; -// for(int i = 0; i < 8; i++) { -// K1[i] = L[i] << 1; -// if(i < 7) { -// K1[i] |= (L[i + 1] >> 7); -// } -// } - -// if((L[0] ^ 0x80) == 0) { -// K1[7] ^= 0x1B; -// } - -// uint8_t M1[8]; -// uint8_t M2[8]; -// memcpy(M1, id_block, 8); -// memcpy(M2, id_block + 8, 8); -// for(int i = 0; i < 8; i++) { -// M2[i] ^= K1[i]; -// } - -// uint8_t C1[8]; -// mbedtls_des3_init(&ctx); -// mbedtls_des3_set3key_enc(&ctx, master_key); -// mbedtls_des3_crypt_ecb(&ctx, M1, C1); -// for(int i = 0; i < 8; i++) { -// C1[i] ^= M2[i]; -// } - -// mbedtls_des3_crypt_ecb(&ctx, C1, card_key); // T - -// M1[0] ^= 0x80; // M'1 -// mbedtls_des3_crypt_ecb(&ctx, M1, C1); // C'1 -// for(int i = 0; i < 8; i++) { -// C1[i] ^= M2[i]; -// } - -// mbedtls_des3_crypt_ecb(&ctx, C1, card_key + 8); // T' -// mbedtls_des3_free(&ctx); -// } - -// static void felica_lite_generate_session_key( -// uint8_t* random_challenge, -// uint8_t* card_key, -// uint8_t* session_key) { -// uint8_t RC1[8]; -// uint8_t RC2[8]; -// uint8_t CK[16]; - -// for(int i = 0; i < 8; i++) { -// RC1[i] = random_challenge[7 - i]; -// RC2[i] = random_challenge[i]; -// CK[i] = card_key[7 - i]; -// CK[i + 8] = card_key[15 - i]; -// } - -// mbedtls_des3_context ctx; - -// uint8_t SK1[8]; -// mbedtls_des3_init(&ctx); -// mbedtls_des3_set2key_enc(&ctx, CK); -// mbedtls_des3_crypt_ecb(&ctx, RC1, SK1); - -// uint8_t SK2[8]; -// for(int i = 0; i < 8; i++) { -// RC2[i] ^= SK1[i]; -// } -// mbedtls_des3_crypt_ecb(&ctx, RC2, SK2); -// mbedtls_des3_free(&ctx); - -// for(int i = 0; i < 8; i++) { -// session_key[i] = SK1[7 - i]; -// session_key[i + 8] = SK2[7 - i]; -// } -// } - -// static void felica_lite_calculate_mac( -// uint8_t* random_challenge, -// uint8_t* session_key, -// uint8_t* block_data, -// size_t block_count, -// uint8_t* MAC) { -// uint8_t SK[16]; - -// for(int i = 0; i < 8; i++) { -// MAC[i] = random_challenge[7 - i]; -// SK[i] = session_key[7 - i]; -// SK[i + 8] = session_key[15 - i]; -// } - -// mbedtls_des3_context ctx; -// mbedtls_des3_init(&ctx); -// mbedtls_des3_set3key_enc(&ctx, SK); - -// for(size_t block_num = 0; block_num < block_count; block_num++) { -// for(int i = 0; i < 8; i++) { -// MAC[i] ^= block_data[block_num * FELICA_BLOCK_SIZE + 7 - i]; -// } - -// uint8_t intermediate[8]; -// mbedtls_des3_crypt_ecb(&ctx, MAC, intermediate); -// for(int i = 0; i < 8; i++) { -// intermediate[i] ^= block_data[block_num * FELICA_BLOCK_SIZE + 15 - i]; -// } - -// mbedtls_des3_crypt_ecb(&ctx, intermediate, MAC); -// } - -// mbedtls_des3_free(&ctx); -// } - -// static void felica_lite_calculate_mac_a( -// uint8_t* random_challenge, -// uint8_t* session_key, -// uint8_t* iv, -// uint8_t* block_data, -// size_t block_count, -// uint8_t* MAC_A) { -// uint8_t SK[16]; -// uint8_t intermediate_a[8]; -// uint8_t intermediate_b[8]; - -// for(int i = 0; i < 8; i++) { -// intermediate_a[i] = iv[7 - 1] ^ random_challenge[7 - i]; -// SK[i] = session_key[7 - i]; -// SK[i + 8] = session_key[15 - i]; -// } - -// mbedtls_des3_context ctx; -// mbedtls_des3_init(&ctx); -// mbedtls_des3_set3key_enc(&ctx, SK); -// mbedtls_des3_crypt_ecb(&ctx, intermediate_a, intermediate_b); - -// for(size_t block_num = 0; block_num < block_count; block_num++) { -// for(int i = 0; i < 8; i++) { -// intermediate_b[i] ^= block_data[block_num * FELICA_BLOCK_SIZE + 7 - i]; -// } - -// mbedtls_des3_crypt_ecb(&ctx, intermediate_b, intermediate_a); -// for(int i = 0; i < 8; i++) { -// intermediate_a[i] ^= block_data[block_num * FELICA_BLOCK_SIZE + 7 - i]; -// } - -// mbedtls_des3_crypt_ecb(&ctx, intermediate_a, intermediate_b); -// } - -// for(int i = 0; i < 8; i++) { -// MAC_A[i] = intermediate_b[7 - 1]; -// } -// } - -// static void felica_lite_calculate_mac_a_for_write( -// uint8_t* random_challenge, -// uint8_t* session_key, -// uint32_t write_count, -// uint8_t block_number, -// uint8_t* block_data, -// uint8_t* MAC_A) { -// uint8_t iv[8]; -// nfc_util_num2bytes(write_count, 3, iv); -// iv[3] = 0x00; -// iv[4] = block_number; -// iv[5] = 0x00; -// iv[6] = 0x91; -// iv[7] = 0x00; - -// uint8_t SK[16]; -// for(int i = 0; i < 8; i++) { -// SK[i] = session_key[i + 8]; -// SK[i + 8] = session_key[i]; -// } - -// felica_lite_calculate_mac_a(random_challenge, SK, iv, block_data, 1, MAC_A); -// } - -// static void felica_lite_calculate_mac_a_for_read( -// uint8_t* random_challenge, -// uint8_t* session_key, -// uint8_t* block_list, -// uint8_t block_list_count, -// uint8_t* block_data, -// uint8_t block_count, -// uint8_t* MAC_A) { -// uint8_t iv[8] = {0}; - -// uint8_t block_list_to_write = MIN(block_list_count, 4); -// for(int i = 0; i < block_list_to_write; i++) { -// iv[i * 2] = block_list[i]; -// } -// if(block_list_to_write < 4) { -// iv[6] = 0xFF; -// iv[7] = 0xFF; -// } -// if(block_list_to_write < 3) { -// iv[4] = 0xFF; -// iv[5] = 0xFF; -// } - -// felica_lite_calculate_mac_a(random_challenge, session_key, iv, block_data, block_count, MAC_A); -// } - -/** Parse common FeliCa response headers. - * - * This parses and validates the most commonly occurring response header types. - * - * The header needs to match the (length, res, idm) format, and also (sf1, sf2) when always_succeed - * is set to false. - * - * @param buf RX buffer. - * @param len RX buffer length. - * @param reader The FeliCa reader context. - * @param expected_resp Expected response code. Must be an odd number. - * @param always_succeed When set to true, skip status flags (sf1 and sf2) parsing. - * @return The number of bytes parsed, or 0 when response is invalid or status flags are set. - */ -static uint8_t felica_consume_unencrypted_header( - uint8_t* buf, - uint8_t len, - FelicaReader* reader, - uint8_t expected_resp, - bool always_succeed) { - furi_assert(expected_resp & 1); - furi_assert(buf != NULL); - furi_assert(reader != NULL); - - uint8_t header_size = always_succeed ? 10 : 12; - if(len < header_size) { - FURI_LOG_E(TAG, "Malformed header: too short."); - return 0; - } - if(buf[1] != expected_resp) { - FURI_LOG_E(TAG, "Expecting %u, got %u.", expected_resp, buf[1]); - return 0; - } - if(memcmp(&buf[2], reader->current_idm, 8) != 0) { - FURI_LOG_E(TAG, "IDm mismatch."); - return 0; - } - if(always_succeed) { - reader->status_flags[0] = buf[10]; - reader->status_flags[1] = buf[11]; - if(reader->status_flags[0] != 0 || reader->status_flags[1] != 0) { - FURI_LOG_W( - TAG, "SF1: %02X SF2: %02X", reader->status_flags[0], reader->status_flags[1]); - return 0; - } - } - return header_size; -} - -uint8_t felica_prepare_unencrypted_read( - uint8_t* dest, - const FelicaReader* reader, - const uint16_t* service_code_list, - uint8_t service_count, - const uint32_t* block_list, - uint8_t block_count) { - dest[0] = FELICA_UNENCRYPTED_READ_CMD; - memcpy(&dest[1], reader->current_idm, 8); - - dest[9] = service_count; - uint8_t msg_len = 10; - for(int i = 0; i < service_count; i++) { - uint16_t service_code = service_code_list[i]; - dest[msg_len++] = service_code & 0xFF; - dest[msg_len++] = service_code >> 8; - } - - dest[msg_len++] = block_count; - for(int i = 0; i < block_count; i++) { - uint16_t block_num = block_list[i]; - dest[msg_len++] = block_num & 0xFF; - dest[msg_len++] = block_num >> 8; - } - - return msg_len; -} - -uint8_t felica_lite_prepare_unencrypted_read( - uint8_t* dest, - const FelicaReader* reader, - bool is_read_only, - const uint8_t* block_list, - uint8_t block_count) { - dest[0] = FELICA_UNENCRYPTED_READ_CMD; - memcpy(&dest[1], reader->current_idm, 8); - - dest[9] = 1; - uint8_t msg_len = 10; - uint8_t service_code = - FelicaServiceTypeRandom | - ((is_read_only) ? FelicaServiceAttributeUnauthRO : FelicaServiceAttributeUnauthRO); - - dest[msg_len++] = service_code & 0xFF; - dest[msg_len++] = service_code >> 8; - - dest[msg_len++] = block_count; - for(int i = 0; i < block_count; i++) { - dest[msg_len++] = IS_2_BYTE_BLOCK_LIST_ELEMENT; - dest[msg_len++] = block_list[i]; - } - - return msg_len; -} - -uint16_t felica_parse_unencrypted_read( - uint8_t* buf, - uint8_t len, - FelicaReader* reader, - uint8_t* out, - uint16_t out_len) { - uint8_t consumed = - felica_consume_unencrypted_header(buf, len, reader, FELICA_UNENCRYPTED_READ_RES, false); - if(!consumed) { - return 0; - } - len -= consumed; - buf += consumed; - - if(len < 1) { - return 0; - } - uint16_t data_length = *buf * FELICA_BLOCK_SIZE; - len--; - buf++; - - if(len < data_length || out_len < data_length) { - return 0; - } - - memcpy(out, buf, data_length); - - return data_length; -} - -uint8_t felica_prepare_unencrypted_write( - uint8_t* dest, - FelicaReader* reader, - const uint16_t* service_code_list, - uint8_t service_count, - const uint32_t* block_list, - uint8_t block_count, - const uint8_t* block_data) { - dest[0] = FELICA_UNENCRYPTED_WRITE_CMD; - memcpy(&dest[1], reader->current_idm, 8); - - dest[9] = service_count; - uint8_t msg_len = 10; - for(int i = 0; i < service_count; i++) { - uint16_t service_code = service_code_list[i]; - dest[msg_len++] = service_code & 0xFF; - dest[msg_len++] = service_code >> 8; - } - - dest[msg_len++] = block_count; - for(int i = 0; i < block_count; i++) { - uint16_t block_num = block_list[i]; - dest[msg_len++] = block_num & 0xFF; - dest[msg_len++] = block_num >> 8; - } - - uint16_t data_length = block_count * FELICA_BLOCK_SIZE; - memcpy(dest + msg_len, block_data, data_length); - msg_len += data_length; - return msg_len; -} - -uint8_t felica_lite_prepare_unencrypted_write( - uint8_t* dest, - const FelicaReader* reader, - const uint8_t* block_list, - uint8_t block_count, - const uint8_t* block_data) { - dest[0] = FELICA_UNENCRYPTED_WRITE_CMD; - memcpy(&dest[1], reader->current_idm, 8); - - dest[9] = 1; - uint8_t msg_len = 10; - uint8_t service_code = FelicaServiceTypeRandom | FelicaServiceAttributeUnauthRW; - dest[msg_len++] = service_code & 0xFF; - dest[msg_len++] = service_code >> 8; - - dest[msg_len++] = block_count; - for(int i = 0; i < block_count; i++) { - dest[msg_len++] = block_list[i]; - dest[msg_len++] = IS_2_BYTE_BLOCK_LIST_ELEMENT; - } - - uint16_t data_length = block_count * FELICA_BLOCK_SIZE; - memcpy(dest + msg_len, block_data, data_length); - msg_len += data_length; - return msg_len; -} - -bool felica_parse_unencrypted_write(uint8_t* buf, uint8_t len, FelicaReader* reader) { - uint8_t consumed = - felica_consume_unencrypted_header(buf, len, reader, FELICA_UNENCRYPTED_WRITE_RES, false); - if(!consumed) { - return false; - } - return true; -} - -uint8_t felica_prepare_request_system_code(uint8_t* dest, FelicaReader* reader) { - dest[0] = FELICA_REQUEST_SYSTEM_CODE_CMD; - memcpy(&dest[1], reader->current_idm, 8); - return 9; -} - -bool felica_parse_request_system_code( - uint8_t* buf, - uint8_t len, - FelicaReader* reader, - FelicaSystemArray_t* systems) { - uint8_t consumed = - felica_consume_unencrypted_header(buf, len, reader, FELICA_REQUEST_SYSTEM_CODE_RES, true); - if(consumed == 0) { - return false; - } - len -= consumed; - buf += consumed; - - uint8_t entries = *buf; - len--; - buf++; - - if(len < 2 * entries) { - FURI_LOG_E(TAG, "FELICA_REQUEST_SYSTEM_CODE_RES: Response too short"); - return false; - } - - for(uint8_t idx = 0; idx < entries; idx++) { - FelicaSystem* system = FelicaSystemArray_push_new(*systems); - furi_assert(system != NULL); - - // Set system code - system->number = idx; - system->code = buf[2 * idx] | (buf[2 * idx + 1] << 8); - - FURI_LOG_D(TAG, "Found system code %04X", system->code); - - // Fill in IDm and PMm - memcpy(system->idm, reader->current_idm, 8); - memcpy(system->pmm, reader->current_pmm, 8); - - // Set system index field in IDm - system->idm[0] &= 0x0f; - system->idm[0] |= ((idx & 0xf) << 4); - } - - return true; -} - -static FelicaSystem* felica_gen_monolithic_system_code( - FelicaReader* reader, - FelicaSystemArray_t* systems, - uint16_t system_code) { - FelicaSystem* system = FelicaSystemArray_push_new(*systems); - furi_assert(reader != NULL); - furi_assert(system != NULL); - - memcpy(system->idm, reader->current_idm, 8); - memcpy(system->pmm, reader->current_pmm, 8); - system->code = system_code; - - return system; -} - -bool felica_lite_can_read_without_mac(uint8_t* mc_r_restr, uint8_t block_number) { - if(block_number > REG_LITE_BLOCK) { - return true; - } - uint8_t byte = mc_r_restr[block_number < 8 ? 0 : 1]; - return ((byte >> (block_number % 8)) & 1) == 0; -} - -void felica_define_normal_block(FelicaService* service, uint16_t number, uint8_t* data) { - FelicaBlock* block = FelicaBlockArray_safe_get(service->blocks, number); - memcpy(block->data, data, FELICA_BLOCK_SIZE); -} - -void felica_push_normal_block(FelicaService* service, uint8_t* data) { - FelicaBlock* block = FelicaBlockArray_push_new(service->blocks); - memcpy(block->data, data, FELICA_BLOCK_SIZE); -} - -bool felica_lite_dump_data( - FuriHalNfcTxRxContext* tx_rx, - FelicaReader* reader, - FelicaData* data, - FelicaSystem* system) { - const uint8_t fixed_blocks[] = { - SYS_CODE_LITE_BLOCK, - DEVICE_ID_LITE_BLOCK, - ID_LITE_BLOCK, - RC_LITE_BLOCK, - CARD_KEY_LITE_BLOCK, - MAC_LITE_BLOCK, - CARD_KEY_VER_LITE_BLOCK, - MEM_CONFIG_LITE_BLOCK, - }; - - uint8_t block_data[FELICA_BLOCK_SIZE * 4]; - - tx_rx->tx_bits = - 8 * felica_lite_prepare_unencrypted_read(tx_rx->tx_data, reader, true, fixed_blocks, 1); - if(!furi_hal_nfc_tx_rx_full(tx_rx)) { - FURI_LOG_W(TAG, "Bad exchange verifying Lite system code"); - return false; - } - if(felica_parse_unencrypted_read( - tx_rx->rx_data, tx_rx->rx_bits / 8, reader, block_data, sizeof(block_data)) != - FELICA_BLOCK_SIZE) { - FURI_LOG_W(TAG, "Bad response to Read without Encryption (SYS_C)"); - return false; - } - if(nfc_util_bytes2num(block_data, 2) != LITE_SYSTEM_CODE) { - FURI_LOG_W(TAG, "Unexpected SYS_C value"); - return false; - } - - tx_rx->tx_bits = 8 * felica_lite_prepare_unencrypted_read( - tx_rx->tx_data, reader, true, &fixed_blocks[1], 1); - if(!furi_hal_nfc_tx_rx_full(tx_rx)) { - FURI_LOG_W(TAG, "Bad exchange reading D_ID"); - return false; - } - if(felica_parse_unencrypted_read( - tx_rx->rx_data, tx_rx->rx_bits / 8, reader, block_data, sizeof(block_data)) != - FELICA_BLOCK_SIZE) { - FURI_LOG_W(TAG, "Bad response to Read without Encryption (D_ID)"); - return false; - } - if(memcmp(system->idm, block_data, 8) != 0 || memcmp(system->pmm, block_data + 8, 8) != 0) { - FURI_LOG_W(TAG, "Mismatching values for D_ID"); - return false; - } - - FelicaLiteInfo* lite_info = &system->lite_info; - lite_info->card_key_1 = NULL; - lite_info->card_key_2 = NULL; - - tx_rx->tx_bits = 8 * felica_lite_prepare_unencrypted_read( - tx_rx->tx_data, reader, true, &fixed_blocks[2], 1); - if(!furi_hal_nfc_tx_rx_full(tx_rx)) { - FURI_LOG_W(TAG, "Bad exchange reading ID"); - return false; - } - if(felica_parse_unencrypted_read( - tx_rx->rx_data, tx_rx->rx_bits / 8, reader, block_data, sizeof(block_data)) != - FELICA_BLOCK_SIZE) { - FURI_LOG_W(TAG, "Bad response to Read without Encryption (ID)"); - return false; - } - lite_info->data_format_code = nfc_util_bytes2num(block_data + 8, 2); - memcpy(lite_info->ID_value, block_data + 10, 6); - FURI_LOG_I(TAG, "ID:"); - for(int i = 0; i < FELICA_BLOCK_SIZE; i++) { - FURI_LOG_I(TAG, "%02X", block_data[i]); - } - - memset(block_data, 0, FELICA_BLOCK_SIZE); - tx_rx->tx_bits = 8 * felica_lite_prepare_unencrypted_write( - tx_rx->tx_data, reader, &fixed_blocks[3], 1, block_data); - if(!furi_hal_nfc_tx_rx_full(tx_rx)) { - FURI_LOG_W(TAG, "Bad exchange writing random challenge"); - return false; - } - if(!felica_parse_unencrypted_write(tx_rx->rx_data, tx_rx->rx_bits / 8, reader)) { - FURI_LOG_W(TAG, "Bad response to Write without Encryption (RC)"); - return false; - } - - tx_rx->tx_bits = 8 * felica_lite_prepare_unencrypted_read( - tx_rx->tx_data, reader, true, &fixed_blocks[4], 2); - if(!furi_hal_nfc_tx_rx_full(tx_rx)) { - FURI_LOG_W(TAG, "Bad exchange reading CK and MAC"); - return false; - } - if(felica_parse_unencrypted_read( - tx_rx->rx_data, tx_rx->rx_bits / 8, reader, block_data, sizeof(block_data)) != - FELICA_BLOCK_SIZE * 2) { - FURI_LOG_W(TAG, "Bad response to Read without Encryption (CK, MAC)"); - return false; - } - memcpy(lite_info->MAC, block_data + FELICA_BLOCK_SIZE, 8); - FURI_LOG_I(TAG, "MAC:"); - for(int i = 0; i < FELICA_BLOCK_SIZE; i++) { - FURI_LOG_I(TAG, "%02X", block_data[i + FELICA_BLOCK_SIZE]); - } - - tx_rx->tx_bits = 8 * felica_lite_prepare_unencrypted_read( - tx_rx->tx_data, reader, true, &fixed_blocks[6], 2); - if(!furi_hal_nfc_tx_rx_full(tx_rx)) { - FURI_LOG_W(TAG, "Bad exchange reading CKV and MC"); - return false; - } - if(felica_parse_unencrypted_read( - tx_rx->rx_data, tx_rx->rx_bits / 8, reader, block_data, sizeof(block_data)) != - FELICA_BLOCK_SIZE * 2) { - FURI_LOG_W(TAG, "Bad response to Read without Encryption (CKV, MC)"); - return false; - } - lite_info->card_key_version = nfc_util_bytes2num(block_data, 2); - memcpy(lite_info->memory_config, block_data + FELICA_BLOCK_SIZE, FELICA_BLOCK_SIZE); - - // Read SPAD and REG accordingly to MC - uint8_t* mc_data = lite_info->memory_config; - for(uint8_t block_number = 0; block_number <= REG_LITE_BLOCK; block_number++) { - if(!felica_lite_can_read_without_mac(mc_data + 6, block_number)) { - if(block_number < REG_LITE_BLOCK) { - lite_info->S_PAD[block_number] = NULL; - } else { - lite_info->REG = NULL; - } - continue; - } - - tx_rx->tx_bits = 8 * felica_lite_prepare_unencrypted_read( - tx_rx->tx_data, reader, true, &block_number, 1); - if(!furi_hal_nfc_tx_rx_full(tx_rx)) { - FURI_LOG_W(TAG, "Bad exchange reading blocks"); - return false; - } - if(felica_parse_unencrypted_read( - tx_rx->rx_data, tx_rx->rx_bits / 8, reader, block_data, sizeof(block_data)) != - FELICA_BLOCK_SIZE) { - FURI_LOG_W(TAG, "Bad response to Read without Encryption (block %d)", block_number); - return false; - } - uint8_t* block = malloc(FELICA_BLOCK_SIZE); - memcpy(block, block_data, FELICA_BLOCK_SIZE); - if(block_number < REG_LITE_BLOCK) { - lite_info->S_PAD[block_number] = block; - } else { - lite_info->REG = block; - } - } - if(data->type == FelicaICTypeLiteS) { - lite_info->is_lite_s = true; - const uint8_t fixed_s_blocks[] = { - CARD_KEY_LITE_BLOCK, - MAC_A_LITE_BLOCK, - WRITE_COUNT_LITE_BLOCK, - CRC_CHECK_LITE_BLOCK, - }; - - tx_rx->tx_bits = 8 * felica_lite_prepare_unencrypted_read( - tx_rx->tx_data, reader, true, fixed_s_blocks, 2); - if(!furi_hal_nfc_tx_rx_full(tx_rx)) { - FURI_LOG_W(TAG, "Bad exchange reading ID with MAC_A"); - return false; - } - if(felica_parse_unencrypted_read( - tx_rx->rx_data, tx_rx->rx_bits / 8, reader, block_data, sizeof(block_data)) != - FELICA_BLOCK_SIZE * 2) { - FURI_LOG_W(TAG, "Bad response to Read without Encryption (CK, MAC_A)"); - return false; - } - memcpy(lite_info->MAC_A, block_data + FELICA_BLOCK_SIZE, FELICA_BLOCK_SIZE); - - tx_rx->tx_bits = 8 * felica_lite_prepare_unencrypted_read( - tx_rx->tx_data, reader, true, &fixed_s_blocks[2], 2); - if(!furi_hal_nfc_tx_rx_full(tx_rx)) { - FURI_LOG_W(TAG, "Bad exchange reading ID with MAC_A"); - return false; - } - if(felica_parse_unencrypted_read( - tx_rx->rx_data, tx_rx->rx_bits / 8, reader, block_data, sizeof(block_data)) != - FELICA_BLOCK_SIZE * 2) { - FURI_LOG_W(TAG, "Bad response to Read without Encryption (WC, CRC_CHECK)"); - return false; - } - lite_info->write_count = nfc_util_bytes2num(block_data, 3); - lite_info->crc_valid = block_data[FELICA_BLOCK_SIZE] == 0x00; - } - - return true; -} - -bool felica_std_request_system_code( - FuriHalNfcTxRxContext* tx_rx, - FelicaReader* reader, - FelicaSystemArray_t* systems) { - tx_rx->tx_bits = 8 * felica_prepare_request_system_code(tx_rx->tx_data, reader); - if(!furi_hal_nfc_tx_rx_full(tx_rx)) { - FURI_LOG_E(TAG, "Bad exchange requesting system code"); - return false; - } - if(!felica_parse_request_system_code(tx_rx->rx_data, tx_rx->rx_bits / 8, reader, systems)) { - FURI_LOG_E(TAG, "Bad response to Request System Code command"); - return false; - } - return true; -} - -bool felica_read_card( - FuriHalNfcTxRxContext* tx_rx, - FelicaData* data, - uint8_t* polled_idm, - uint8_t* polled_pmm) { - furi_assert(tx_rx); - furi_assert(polled_idm); - furi_assert(polled_pmm); - - bool card_read = false; - do { - FelicaReader reader; - memcpy(reader.current_idm, polled_idm, 8); - memcpy(reader.current_pmm, polled_pmm, 8); - - FelicaSystemArray_init(data->systems); - - if(data->type == FelicaICTypeLite || data->type == FelicaICTypeLiteS) { - FURI_LOG_I(TAG, "Reading Felica Lite system"); - FelicaSystem* lite_system = - felica_gen_monolithic_system_code(&reader, &(data->systems), LITE_SYSTEM_CODE); - felica_lite_dump_data(tx_rx, &reader, data, lite_system); - card_read = true; - break; - } - FURI_LOG_I(TAG, "Reading Felica Standard system"); - } while(false); - - return card_read; -} - -void felica_service_clear(FelicaService* service) { - FelicaBlockArray_clear(service->blocks); -} - -void felica_lite_clear(FelicaLiteInfo* lite_info) { - for(int i = 0; i < REG_LITE_BLOCK; i++) { - uint8_t* block = lite_info->S_PAD[i]; - if(block != NULL) { - free(block); - } - } - - if(lite_info->REG != NULL) { - free(lite_info->REG); - } - - if(lite_info->card_key_1 != NULL) { - free(lite_info->card_key_1); - } - if(lite_info->card_key_2 != NULL) { - free(lite_info->card_key_2); - } -} - -void felica_node_clear(FelicaNode* node); - -void felica_area_clear(FelicaArea* area) { - for - M_EACH(node, area->nodes, FelicaNodeArray_t) { - felica_node_clear(node); - } - FelicaNodeArray_clear(area->nodes); -} - -void felica_node_clear(FelicaNode* node) { - if(node->type == FelicaNodeTypeArea) { - felica_area_clear(node->area); - } else if(node->type == FelicaNodeTypeService) { - felica_service_clear(node->service); - } -} - -void felica_clear(FelicaData* data) { - for - M_EACH(system, data->systems, FelicaSystemArray_t) { - if(system->code == LITE_SYSTEM_CODE) { - felica_lite_clear(&system->lite_info); - } else { - felica_node_clear(&system->root); - FelicaPublicServiceDict_clear(system->public_services); - } - } - FelicaSystemArray_clear(data->systems); -} diff --git a/lib/nfc/protocols/felica.h b/lib/nfc/protocols/felica.h deleted file mode 100644 index 876596bb5..000000000 --- a/lib/nfc/protocols/felica.h +++ /dev/null @@ -1,320 +0,0 @@ -#pragma once - -#include -#include -#include - -#define NFCF_F_SIG (13560000.0) -#define MRT_T_SIG 302064.89 //ns, 256 * 16 / NFC_F_SIG * 1e9 -#define MRT_T_SIG_x4 1208259.56 //ns, MRT_T_SIG * (4 ** 1) -#define MRT_T_SIG_x16 4833038.24 //ns, MRT_T_SIG * (4 ** 2) -#define MRT_T_SIG_x64 19332152.96 //ns, MRT_T_SIG * (4 ** 2) - -#define FELICA_PMM_MRT_BASE 2 - -#define FELICA_VARIABLE_MRT 0 -#define FELICA_FIXED_MRT 1 -#define FELICA_MUTUAL_AUTH_MRT 2 -#define FELICA_READ_MRT 3 -#define FELICA_WRITE_MRT 4 -#define FELICA_OTHER_MRT 5 - -#define FELICA_PMM_VARIABLE_MRT (FELICA_PMM_MRT_BASE + FELICA_VARIABLE_MRT) -#define FELICA_PMM_FIXED_MRT (FELICA_PMM_MRT_BASE + FELICA_FIXED_MRT) -#define FELICA_PMM_MUTUAL_AUTH_MRT (FELICA_PMM_MRT_BASE + FELICA_MUTUAL_AUTH_MRT) -#define FELICA_PMM_READ_MRT (FELICA_PMM_MRT_BASE + FELICA_READ_MRT) -#define FELICA_PMM_WRITE_MRT (FELICA_PMM_MRT_BASE + FELICA_WRITE_MRT) -#define FELICA_PMM_OTHER_MRT (FELICA_PMM_MRT_BASE + FELICA_OTHER_MRT) - -#define FELICA_BLOCK_SIZE 16 - -#define CYBERNET_SYSTEM_CODE 0x0003 -#define NDEF_SYSTEM_CODE 0x12fc -#define HCE_F_SYSTEM_CODE 0x4000 -#define OCTOPUS_SYSTEM_CODE 0x8008 -#define IRUCA_SYSTEM_CODE 0x80de -#define EDY_SYSTEM_CODE 0x811d -#define PASPY_SYSTEM_CODE 0x8592 -#define BLACKBOARD_SYSTEM_CODE 0x8620 -#define SAPICA_SYSTEM_CODE 0x865e -#define SUICA_SYSTEM_CODE 0x86a7 -#define LITE_SYSTEM_CODE 0x88b4 -#define RYUTO_SYSTEM_CODE 0x8b5d -#define OKICA_SYSTEM_CODE 0x8fc1 -#define SECURE_ID_SYSTEM_CODE 0x957a -#define COMMON_AREA_SYSTEM_CODE 0xfe00 -#define PLUG_SYSTEM_CODE 0xfee1 - -#define REG_LITE_BLOCK 0x0e -#define RC_LITE_BLOCK 0x80 -#define MAC_LITE_BLOCK 0x81 -#define ID_LITE_BLOCK 0x82 -#define DEVICE_ID_LITE_BLOCK 0x83 -#define SERVICE_CODE_LITE_BLOCK 0x84 -#define SYS_CODE_LITE_BLOCK 0x85 -#define CARD_KEY_VER_LITE_BLOCK 0x86 -#define CARD_KEY_LITE_BLOCK 0x87 -#define MEM_CONFIG_LITE_BLOCK 0x88 -#define WRITE_COUNT_LITE_BLOCK 0x90 -#define MAC_A_LITE_BLOCK 0x91 -#define STATE_LITE_BLOCK 0x92 -#define CRC_CHECK_LITE_BLOCK 0xA0 - -#define IS_2_BYTE_BLOCK_LIST_ELEMENT 0x80 - -#define FELICA_UNENCRYPTED_READ_CMD 0x06 -#define FELICA_UNENCRYPTED_WRITE_CMD 0x08 -#define FELICA_SEARCH_SERVICE_CODE_CMD 0x0a -#define FELICA_REQUEST_SYSTEM_CODE_CMD 0x0c - -#define FELICA_UNENCRYPTED_READ_RES 0x07 -#define FELICA_UNENCRYPTED_WRITE_RES 0x09 -#define FELICA_SEARCH_SERVICE_CODE_RES 0x0b -#define FELICA_REQUEST_SYSTEM_CODE_RES 0x0d - -typedef enum { - FelicaICTypeRC_SA24_10K, // RC-SA24/1x - FelicaICTypeRC_SA24_6K, // RC-SA24/1x1 - FelicaICTypeSD2_6K, // RC-SA21/2x1 - FelicaICTypeSD2_4K, // RC-SA21/2 - FelicaICTypeSD2WithDES, // RC-SA20/1, RC-SA20/2 - FelicaICTypeRC_SA08, // Certifications exist, prototype? - FelicaICTypeSD1, // RC-SA01 - FelicaICTypeSD1WithDES, // RC-SA00 - FelicaICTypeFRAM_4K, // RC-S962 - FelicaICTypeFRAM_9K, // RC-S960 - FelicaICTypeEMV_36K, // RC-S954 - FelicaICTypeEMV_16K, // RC-S953 - FelicaICTypeEMV_32K, // RC-S952 - FelicaICType576B, // RC-S919 - FelicaICType4K, // RC-S915 - FelicaICType2K, // RC-S830 series cards, chip name unknown, - FelicaICTypeMobileIC_V4_1, - FelicaICTypeMobileIC_V4, - FelicaICTypeMobileIC_V3, - FelicaICTypeMobileIC_V2, - FelicaICTypeMobileIC_V1, - FelicaICTypeLite, // RC-S965 - FelicaICTypeLiteS, // RC-S966 - FelicaICTypeLink, // RC-S967, - FelicaICTypePlug, // RC-S926 - FelicaICTypeSuica, // https://www.tuv-nederland.nl/assets/files/cerfiticaten/2019/07/cr-nscib-cc-10-30076-cr.pdf -} FelicaICType; - -typedef enum { - FelicaServiceTypeRandom = (0b0010 << 2), - FelicaServiceTypeCyclic = (0b0011 << 2), - FelicaServiceTypePurse = (0b010 << 3), -} FelicaServiceType; -typedef enum { - FelicaServiceAttributeAuthRW = 0b00, - FelicaServiceAttributeUnauthRW = 0b01, - FelicaServiceAttributeAuthRO = 0b10, - FelicaServiceAttributeUnauthRO = 0b11, - - FelicaServiceAttributeAuthDirectAccess = 0b000, - FelicaServiceAttributeUnauthDirectAccess = 0b001, - FelicaServiceAttributeAuthCashbackDecrement = 0b010, - FelicaServiceAttributeUnauthCashbackDecrement = 0b011, - FelicaServiceAttributeAuthDecrement = 0b100, - FelicaServiceAttributeUnauthDecrement = 0b101, - FelicaServiceAttributeAuthPurseRO = 0b110, - FelicaServiceAttributeUnauthPurseRO = 0b111, -} FelicaServiceAttribute; - -DICT_SET_DEF( - FelicaServiceAttributeList, - FelicaServiceAttribute, - M_ENUM_OPLIST(FelicaServiceAttribute, FelicaServiceAttributeAuthRW)) - -typedef struct { - uint8_t data[FELICA_BLOCK_SIZE]; -} FelicaBlock; - -ARRAY_DEF(FelicaBlockArray, FelicaBlock, M_POD_OPLIST) -#define M_OPL_FelicaBlockArray_t() ARRAY_OPLIST(FelicaBlockArray, M_POD_OPLIST) - -typedef struct { - uint16_t number; - FelicaServiceAttributeList_t access_control_list; // accounts for overlap services - bool is_extended_overlap; // We don't know much about this currently. will always be false - union { - // TODO change this to use FelicaBlockArray_t - FelicaBlockArray_t blocks; - struct { - uint16_t overlap_target; - uint8_t block_start; - uint8_t block_count; - }; - }; -} FelicaService; - -typedef enum { - FelicaNodeTypeArea, - FelicaNodeTypeService, -} FelicaNodeType; - -struct _FelicaArea_t; -typedef struct _FelicaArea_t FelicaArea; - -struct _FelicaNode_s; -typedef struct _FelicaNode_s FelicaNode; - -struct _FelicaNode_s { - /** Node type. */ - FelicaNodeType type; - /** Borrowed pointer to its parent node. */ - FelicaNode* parent; - union { - /** (Area/dir type only) The area struct. */ - FelicaArea* area; - /** (Service/file type only) The service struct. */ - FelicaService* service; - }; -}; - -// TODO properly remove this -//ARRAY_DEF(FelicaNodeList, FelicaNode*, M_PTR_OPLIST) -ARRAY_DEF(FelicaNodeArray, FelicaNode, M_POD_OPLIST) -#define M_OPL_FelicaNodeArray_t() ARRAY_OPLIST(FelicaNodeArray, M_POD_OPLIST) - -ARRAY_DEF(FelicaNodeRefArray, FelicaNode*, M_PTR_OPLIST) -#define M_OPL_FelicaNodeRefArray_t() ARRAY_OPLIST(FelicaNodeRefArray, M_PTR_OPLIST) - -// { service_number: service_ptr_in_tree } -DICT_DEF2(FelicaPublicServiceDict, uint16_t, M_DEFAULT_OPLIST, FelicaService*, M_PTR_OPLIST) -#define M_OPL_FelicaPublicServiceDict_t() \ - DICT_OPLIST(FelicaPublicServiceDict, M_DEFAULT_OPLIST, M_PTR_OPLIST) - -struct _FelicaArea_t { - uint16_t number; - bool can_create_subareas; - uint16_t end_service_code; - - FelicaNodeArray_t nodes; -}; - -typedef struct { - uint8_t* S_PAD[14]; - uint8_t* REG; - // MACs of all zero bytes (read from CK) - uint8_t MAC[8]; - uint16_t data_format_code; - uint8_t ID_value[6]; - uint8_t* card_key_1; - uint8_t* card_key_2; - uint16_t card_key_version; - uint8_t memory_config[FELICA_BLOCK_SIZE]; - - bool is_lite_s; - // Lite-S only - uint8_t MAC_A[8]; - uint32_t write_count; - bool crc_valid; -} FelicaLiteInfo; - -typedef struct _FelicaSystem_t { - /** FeliCa system index. */ - uint8_t number; - /** If the system belongs to a FeliCa Lite (and be its only system). */ - bool is_lite; - /** FeliCa system code. */ - uint16_t code; - /** System IDm with system index bitfield properly set. */ - uint8_t idm[8]; - /** Cached card PMm. */ - uint8_t pmm[8]; - - union { - /** (For FeliCa Lite only) Card content. */ - FelicaLiteInfo lite_info; - struct { - /** (For FeliCa Standard only) The root of the raw filesystem tree. */ - FelicaNode root; - /** (For FeliCa Standard only) Shortcut for all publicly accessible services for quick - * access by card parsers. */ - FelicaPublicServiceDict_t public_services; - }; - }; -} FelicaSystem; - -// TODO properly remove this -//ARRAY_DEF(FelicaSystemList, FelicaSystem*, M_PTR_OPLIST) -ARRAY_DEF(FelicaSystemArray, FelicaSystem, M_POD_OPLIST) -#define M_OPL_FelicaSystemArray_t() ARRAY_OPLIST(FelicaSystemArray, M_POD_OPLIST) - -typedef struct { - FelicaICType type; - uint8_t subtype; - FelicaSystemArray_t systems; -} FelicaData; - -typedef struct { - uint8_t current_idm[8]; - uint8_t current_pmm[8]; - - uint8_t status_flags[2]; -} FelicaReader; - -bool felica_check_ic_type(uint8_t* PMm); -FelicaICType felica_get_ic_type(uint8_t* PMm); - -uint8_t felica_prepare_unencrypted_read( - uint8_t* dest, - const FelicaReader* reader, - const uint16_t* service_code_list, - uint8_t service_count, - const uint32_t* block_list, - uint8_t block_count); -uint8_t felica_lite_prepare_unencrypted_read( - uint8_t* dest, - const FelicaReader* reader, - bool is_read_only, - const uint8_t* block_list, - uint8_t block_count); -uint16_t felica_parse_unencrypted_read( - uint8_t* buf, - uint8_t len, - FelicaReader* reader, - uint8_t* out, - uint16_t out_len); - -uint8_t felica_prepare_unencrypted_write( - uint8_t* dest, - FelicaReader* reader, - const uint16_t* service_code_list, - uint8_t service_count, - const uint32_t* block_list, - uint8_t block_count, - const uint8_t* block_data); -uint8_t felica_lite_prepare_unencrypted_write( - uint8_t* dest, - const FelicaReader* reader, - const uint8_t* block_list, - uint8_t block_count, - const uint8_t* block_data); -bool felica_parse_unencrypted_write(uint8_t* buf, uint8_t len, FelicaReader* reader); - -void felica_define_normal_block(FelicaService* service, uint16_t number, uint8_t* data); -void felica_push_normal_block(FelicaService* service, uint8_t* data); - -/** Dump a FeliCa Lite or Lite-S tag. - * - * @param tx_rx NFC context. - * @param reader FeliCa reader context. - * @param data Output data object. - * @param system FeliCa system description. - * @return true if successful. - */ -bool felica_lite_dump_data( - FuriHalNfcTxRxContext* tx_rx, - FelicaReader* reader, - FelicaData* data, - FelicaSystem* system); - -bool felica_read_card( - FuriHalNfcTxRxContext* tx_rx, - FelicaData* data, - uint8_t* polled_idm, - uint8_t* polled_pmm); -void felica_clear(FelicaData* data); \ No newline at end of file diff --git a/lib/nfc/protocols/felica_util.c b/lib/nfc/protocols/felica_util.c deleted file mode 100644 index 47f66fcc5..000000000 --- a/lib/nfc/protocols/felica_util.c +++ /dev/null @@ -1,67 +0,0 @@ -#include "./felica.h" -#include - -static const uint32_t TIME_CONSTANT_US = 302; - -// TODO move this to felica.c -uint_least32_t felica_estimate_timing_us(uint_least8_t timing, uint_least8_t units) { - uint_least32_t base_cost_factor = 1 + (timing & 0x7); - uint_least32_t unit_cost_factor = 1 + ((timing >> 3) & 0x7); - uint_least32_t scale = 1 << ((timing >> 6) * 2); - return TIME_CONSTANT_US * scale * (base_cost_factor + unit_cost_factor * units); -} - -bool felica_lite_is_issued(FelicaLiteInfo* lite_info) { - // System blocks aren't writable? - if(lite_info->memory_config[2] == 0x00) { - return false; - } - - // MC is not writable? - if(lite_info->memory_config[1] & 0x80) { - return false; - } - - return true; -} - -FuriString* felica_get_system_name(FelicaSystem* system) { - uint16_t code = system->code; - - const char* prefix; - if(code == SUICA_SYSTEM_CODE) { - prefix = "SuiCa"; - } else if(code == NDEF_SYSTEM_CODE) { - prefix = "NDEF"; - } else if(code == HCE_F_SYSTEM_CODE) { - prefix = "HCE-F"; - } else if(code == OCTOPUS_SYSTEM_CODE) { - prefix = "Octopus"; - } else if(code == EDY_SYSTEM_CODE) { - prefix = "Edy"; - } else if(code == PASPY_SYSTEM_CODE) { - prefix = "PASPY"; - } else if(code == BLACKBOARD_SYSTEM_CODE) { - prefix = "Blackboard"; - } else if(code == SAPICA_SYSTEM_CODE) { - prefix = "SAPICA"; - } else if(code == LITE_SYSTEM_CODE) { - prefix = "FeliCa Lite"; - } else if(code == RYUTO_SYSTEM_CODE) { - prefix = "Ryuto"; - } else if(code == OKICA_SYSTEM_CODE) { - prefix = "OKICA"; - } else if(code == SECURE_ID_SYSTEM_CODE) { - prefix = "FeliCa Secure ID"; - } else if(code == IRUCA_SYSTEM_CODE) { - prefix = "IruCa"; - } else if(code == COMMON_AREA_SYSTEM_CODE) { - prefix = "Common Area"; - } else if(code == PLUG_SYSTEM_CODE) { - prefix = "FeliCa Plug"; - } else { - return furi_string_alloc_printf("System %04X", code); - } - - return furi_string_alloc_printf("%s (%04X)", prefix, code); -} \ No newline at end of file diff --git a/lib/nfc/protocols/felica_util.h b/lib/nfc/protocols/felica_util.h deleted file mode 100644 index 653ba4501..000000000 --- a/lib/nfc/protocols/felica_util.h +++ /dev/null @@ -1,14 +0,0 @@ -#include "./felica.h" - -#ifdef __cplusplus -extern "C" { -#endif - -uint_least32_t felica_estimate_timing_us(uint_least8_t timing, uint_least8_t units); -bool felica_lite_is_issued(FelicaLiteInfo* lite_info); -FuriString* felica_get_system_name(FelicaSystem* system); -FuriString* felica_get_service_name(FelicaService* service); - -#ifdef __cplusplus -} -#endif diff --git a/lib/nfc/protocols/mifare_classic.c b/lib/nfc/protocols/mifare_classic.c index 8fd396cff..e8683d6c0 100644 --- a/lib/nfc/protocols/mifare_classic.c +++ b/lib/nfc/protocols/mifare_classic.c @@ -374,10 +374,7 @@ bool mf_classic_is_value_block(MfClassicData* data, uint8_t block_num) { data, block_num, MfClassicKeyB, MfClassicActionDataDec)); } -bool mf_classic_check_card_type(FuriHalNfcADevData* data) { - uint8_t ATQA0 = data->atqa[0]; - uint8_t ATQA1 = data->atqa[1]; - uint8_t SAK = data->sak; +bool mf_classic_check_card_type(uint8_t ATQA0, uint8_t ATQA1, uint8_t SAK) { if((ATQA0 == 0x44 || ATQA0 == 0x04) && (SAK == 0x08 || SAK == 0x88 || SAK == 0x09 || SAK == 0x89)) { return true; @@ -391,10 +388,7 @@ bool mf_classic_check_card_type(FuriHalNfcADevData* data) { } } -MfClassicType mf_classic_get_classic_type(FuriHalNfcADevData* data) { - uint8_t ATQA0 = data->atqa[0]; - uint8_t ATQA1 = data->atqa[1]; - uint8_t SAK = data->sak; +MfClassicType mf_classic_get_classic_type(uint8_t ATQA0, uint8_t ATQA1, uint8_t SAK) { if((ATQA0 == 0x44 || ATQA0 == 0x04)) { if((SAK == 0x08 || SAK == 0x88)) { return MfClassicType1k; diff --git a/lib/nfc/protocols/mifare_classic.h b/lib/nfc/protocols/mifare_classic.h index 60d9ab743..7efe81b8c 100644 --- a/lib/nfc/protocols/mifare_classic.h +++ b/lib/nfc/protocols/mifare_classic.h @@ -98,9 +98,9 @@ typedef struct { const char* mf_classic_get_type_str(MfClassicType type); -bool mf_classic_check_card_type(FuriHalNfcADevData* data); +bool mf_classic_check_card_type(uint8_t ATQA0, uint8_t ATQA1, uint8_t SAK); -MfClassicType mf_classic_get_classic_type(FuriHalNfcADevData* data); +MfClassicType mf_classic_get_classic_type(uint8_t ATQA0, uint8_t ATQA1, uint8_t SAK); uint8_t mf_classic_get_total_sectors_num(MfClassicType type); diff --git a/lib/nfc/protocols/mifare_common.c b/lib/nfc/protocols/mifare_common.c index 1f336cb51..5277cc8cd 100644 --- a/lib/nfc/protocols/mifare_common.c +++ b/lib/nfc/protocols/mifare_common.c @@ -1,10 +1,6 @@ #include "mifare_common.h" -#include "furi_hal_nfc.h" -MifareType mifare_common_get_type(FuriHalNfcADevData* data) { - uint8_t ATQA0 = data->atqa[0]; - uint8_t ATQA1 = data->atqa[1]; - uint8_t SAK = data->sak; +MifareType mifare_common_get_type(uint8_t ATQA0, uint8_t ATQA1, uint8_t SAK) { MifareType type = MifareTypeUnknown; if((ATQA0 == 0x44) && (ATQA1 == 0x00) && (SAK == 0x00)) { diff --git a/lib/nfc/protocols/mifare_common.h b/lib/nfc/protocols/mifare_common.h index e60a97bd0..2b694d906 100644 --- a/lib/nfc/protocols/mifare_common.h +++ b/lib/nfc/protocols/mifare_common.h @@ -1,7 +1,6 @@ #pragma once #include -#include "furi_hal_nfc.h" typedef enum { MifareTypeUnknown, @@ -10,4 +9,4 @@ typedef enum { MifareTypeDesfire, } MifareType; -MifareType mifare_common_get_type(FuriHalNfcADevData* data); +MifareType mifare_common_get_type(uint8_t ATQA0, uint8_t ATQA1, uint8_t SAK); diff --git a/lib/nfc/protocols/mifare_desfire.c b/lib/nfc/protocols/mifare_desfire.c index 0c43169a9..e0ead737f 100644 --- a/lib/nfc/protocols/mifare_desfire.c +++ b/lib/nfc/protocols/mifare_desfire.c @@ -258,11 +258,7 @@ void mf_df_cat_file(MifareDesfireFile* file, FuriString* out) { } } -bool mf_df_check_card_type(FuriHalNfcADevData* data) { - uint8_t ATQA0 = data->atqa[0]; - uint8_t ATQA1 = data->atqa[1]; - uint8_t SAK = data->sak; - +bool mf_df_check_card_type(uint8_t ATQA0, uint8_t ATQA1, uint8_t SAK) { return ATQA0 == 0x44 && ATQA1 == 0x03 && SAK == 0x20; } diff --git a/lib/nfc/protocols/mifare_desfire.h b/lib/nfc/protocols/mifare_desfire.h index 7d5915b76..8faa98ec2 100644 --- a/lib/nfc/protocols/mifare_desfire.h +++ b/lib/nfc/protocols/mifare_desfire.h @@ -132,7 +132,7 @@ void mf_df_cat_application_info(MifareDesfireApplication* app, FuriString* out); void mf_df_cat_application(MifareDesfireApplication* app, FuriString* out); void mf_df_cat_file(MifareDesfireFile* file, FuriString* out); -bool mf_df_check_card_type(FuriHalNfcADevData* data); +bool mf_df_check_card_type(uint8_t ATQA0, uint8_t ATQA1, uint8_t SAK); MifareDesfireApplication* mf_df_get_application(MifareDesfireData* data, const uint8_t (*aid)[3]); MifareDesfireFile* mf_df_get_file(MifareDesfireApplication* app, uint8_t id); diff --git a/lib/nfc/protocols/mifare_ultralight.c b/lib/nfc/protocols/mifare_ultralight.c index 750ede8d7..266b6e2e2 100644 --- a/lib/nfc/protocols/mifare_ultralight.c +++ b/lib/nfc/protocols/mifare_ultralight.c @@ -33,12 +33,11 @@ uint32_t mf_ul_pwdgen_amiibo(FuriHalNfcDevData* data) { return pwd; } -bool mf_ul_check_card_type(FuriHalNfcADevData* data) { - uint8_t ATQA0 = data->atqa[0]; - uint8_t ATQA1 = data->atqa[1]; - uint8_t SAK = data->sak; - - return ((ATQA0 == 0x44) && (ATQA1 == 0x00) && (SAK == 0x00)); +bool mf_ul_check_card_type(uint8_t ATQA0, uint8_t ATQA1, uint8_t SAK) { + if((ATQA0 == 0x44) && (ATQA1 == 0x00) && (SAK == 0x00)) { + return true; + } + return false; } void mf_ul_reset(MfUltralightData* data) { diff --git a/lib/nfc/protocols/mifare_ultralight.h b/lib/nfc/protocols/mifare_ultralight.h index 64d61da56..9cb7ca535 100644 --- a/lib/nfc/protocols/mifare_ultralight.h +++ b/lib/nfc/protocols/mifare_ultralight.h @@ -207,7 +207,7 @@ typedef struct { void mf_ul_reset(MfUltralightData* data); -bool mf_ul_check_card_type(FuriHalNfcADevData* data); +bool mf_ul_check_card_type(uint8_t ATQA0, uint8_t ATQA1, uint8_t SAK); bool mf_ultralight_read_version( FuriHalNfcTxRxContext* tx_rx,