diff --git a/applications/ReadMe.md b/applications/ReadMe.md index 2a373509c..15f97e395 100644 --- a/applications/ReadMe.md +++ b/applications/ReadMe.md @@ -55,7 +55,6 @@ External applications deployed to SD Card Background services providing system APIs to applications. - `applications.h` - Firmware application list header - - `bt` - BLE service and application - `cli` - Console service and API - `crypto` - Crypto cli tools diff --git a/applications/main/lfrfid/scenes/lfrfid_scene_clear_t5577.c b/applications/main/lfrfid/scenes/lfrfid_scene_clear_t5577.c index c58bf9e4f..2cf9a15e2 100644 --- a/applications/main/lfrfid/scenes/lfrfid_scene_clear_t5577.c +++ b/applications/main/lfrfid/scenes/lfrfid_scene_clear_t5577.c @@ -56,8 +56,8 @@ void lfrfid_scene_clear_t5577_on_enter(void* context) { lfrfid_clear_t5577_password_and_config_to_EM(app); notification_message(app->notifications, &sequence_success); - popup_set_header(popup, "Done!", 94, 10, AlignCenter, AlignTop); - popup_set_icon(popup, 0, 7, &I_RFIDDolphinSuccess_108x57); + popup_set_header(popup, "Success!", 75, 10, AlignLeft, AlignTop); + popup_set_icon(popup, 0, 9, &I_DolphinSuccess_91x55); popup_set_context(popup, app); popup_set_callback(popup, lfrfid_popup_timeout_callback); popup_set_timeout(popup, 1500); diff --git a/applications/main/nfc/application.fam b/applications/main/nfc/application.fam index 441123b89..f3a26db39 100644 --- a/applications/main/nfc/application.fam +++ b/applications/main/nfc/application.fam @@ -38,15 +38,6 @@ App( sources=["plugins/supported_cards/opal.c"], ) -App( - appid="mykey_parser", - apptype=FlipperAppType.PLUGIN, - entry_point="mykey_plugin_ep", - targets=["f7"], - requires=["nfc"], - sources=["plugins/supported_cards/mykey.c"], -) - App( appid="myki_parser", apptype=FlipperAppType.PLUGIN, @@ -65,6 +56,15 @@ App( sources=["plugins/supported_cards/troika.c"], ) +App( + appid="social_moscow_parser", + apptype=FlipperAppType.PLUGIN, + entry_point="social_moscow_plugin_ep", + targets=["f7"], + requires=["nfc"], + sources=["plugins/supported_cards/social_moscow.c"], +) + App( appid="plantain_parser", apptype=FlipperAppType.PLUGIN, @@ -83,15 +83,6 @@ App( sources=["plugins/supported_cards/two_cities.c"], ) -App( - appid="aime_parser", - apptype=FlipperAppType.PLUGIN, - entry_point="aime_plugin_ep", - targets=["f7"], - requires=["nfc"], - sources=["plugins/supported_cards/aime.c"], -) - App( appid="umarsh_parser", apptype=FlipperAppType.PLUGIN, @@ -101,15 +92,6 @@ App( sources=["plugins/supported_cards/umarsh.c"], ) -App( - appid="social_moscow_parser", - apptype=FlipperAppType.PLUGIN, - entry_point="social_moscow_plugin_ep", - targets=["f7"], - requires=["nfc"], - sources=["plugins/supported_cards/social_moscow.c"], -) - App( appid="metromoney_parser", apptype=FlipperAppType.PLUGIN, @@ -128,6 +110,15 @@ App( sources=["plugins/supported_cards/kazan.c"], ) +App( + appid="aime_parser", + apptype=FlipperAppType.PLUGIN, + entry_point="aime_plugin_ep", + targets=["f7"], + requires=["nfc"], + sources=["plugins/supported_cards/aime.c"], +) + App( appid="saflok_parser", apptype=FlipperAppType.PLUGIN, @@ -137,6 +128,42 @@ App( sources=["plugins/supported_cards/saflok.c"], ) +App( + appid="mykey_parser", + apptype=FlipperAppType.PLUGIN, + entry_point="mykey_plugin_ep", + targets=["f7"], + requires=["nfc"], + sources=["plugins/supported_cards/mykey.c"], +) + +App( + appid="zolotaya_korona_parser", + apptype=FlipperAppType.PLUGIN, + entry_point="zolotaya_korona_plugin_ep", + targets=["f7"], + requires=["nfc"], + sources=["plugins/supported_cards/zolotaya_korona.c"], +) + +App( + appid="hid_parser", + apptype=FlipperAppType.PLUGIN, + entry_point="hid_plugin_ep", + targets=["f7"], + requires=["nfc"], + sources=["plugins/supported_cards/hid.c"], +) + +App( + appid="washcity_parser", + apptype=FlipperAppType.PLUGIN, + entry_point="washcity_plugin_ep", + targets=["f7"], + requires=["nfc"], + sources=["plugins/supported_cards/washcity.c"], +) + App( appid="sonicare_parser", apptype=FlipperAppType.PLUGIN, @@ -164,24 +191,6 @@ App( sources=["plugins/supported_cards/microel.c"], ) -App( - appid="zolotaya_korona_parser", - apptype=FlipperAppType.PLUGIN, - entry_point="zolotaya_korona_plugin_ep", - targets=["f7"], - requires=["nfc"], - sources=["plugins/supported_cards/zolotaya_korona.c"], -) - -App( - appid="hid_parser", - apptype=FlipperAppType.PLUGIN, - entry_point="hid_plugin_ep", - targets=["f7"], - requires=["nfc"], - sources=["plugins/supported_cards/hid.c"], -) - App( appid="nfc_start", targets=["f7"], diff --git a/applications/main/nfc/plugins/supported_cards/kazan.c b/applications/main/nfc/plugins/supported_cards/kazan.c index e0179be5b..de47221ce 100644 --- a/applications/main/nfc/plugins/supported_cards/kazan.c +++ b/applications/main/nfc/plugins/supported_cards/kazan.c @@ -27,8 +27,7 @@ #include #include #include -#include -#include + #include #define TAG "Kazan" diff --git a/applications/main/nfc/plugins/supported_cards/metromoney.c b/applications/main/nfc/plugins/supported_cards/metromoney.c index b094d055a..bb34de330 100644 --- a/applications/main/nfc/plugins/supported_cards/metromoney.c +++ b/applications/main/nfc/plugins/supported_cards/metromoney.c @@ -24,7 +24,6 @@ #include #include #include -#include #define TAG "Metromoney" diff --git a/applications/main/nfc/plugins/supported_cards/umarsh.c b/applications/main/nfc/plugins/supported_cards/umarsh.c index a85c056f6..bf643d21c 100644 --- a/applications/main/nfc/plugins/supported_cards/umarsh.c +++ b/applications/main/nfc/plugins/supported_cards/umarsh.c @@ -32,8 +32,7 @@ #include #include #include -#include -#include + #include #define TAG "Umarsh" diff --git a/applications/main/nfc/plugins/supported_cards/washcity.c b/applications/main/nfc/plugins/supported_cards/washcity.c new file mode 100644 index 000000000..93b069093 --- /dev/null +++ b/applications/main/nfc/plugins/supported_cards/washcity.c @@ -0,0 +1,193 @@ +/* + * Parser for WashCity MarkItaly Card (Europe). + * + * Copyright 2023 Filipe Polido (YaBaPT) + * + * Based on MetroMoney by Leptoptilos + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#include "nfc_supported_card_plugin.h" + +#include "protocols/mf_classic/mf_classic.h" +#include + +#include +#include +#include + +#define TAG "WashCity" + +typedef struct { + uint64_t a; + uint64_t b; +} MfClassicKeyPair; + +static const MfClassicKeyPair washcity_1k_keys[] = { + {.a = 0xA0A1A2A3A4A5, .b = 0x010155010100}, // Sector 00 + {.a = 0xC78A3D0E1BCD, .b = 0xFFFFFFFFFFFF}, // Sector 01 + {.a = 0xC78A3D0E0000, .b = 0xFFFFFFFFFFFF}, // Sector 02 + {.a = 0xC78A3D0E0000, .b = 0xFFFFFFFFFFFF}, // Sector 03 + {.a = 0xC78A3D0E0000, .b = 0xFFFFFFFFFFFF}, // Sector 04 + {.a = 0xC78A3D0E0000, .b = 0xFFFFFFFFFFFF}, // Sector 05 + {.a = 0xC78A3D0E0000, .b = 0xFFFFFFFFFFFF}, // Sector 06 + {.a = 0xC78A3D0E0000, .b = 0xFFFFFFFFFFFF}, // Sector 07 + {.a = 0xC78A3D0E0000, .b = 0xFFFFFFFFFFFF}, // Sector 08 + {.a = 0x010155010100, .b = 0xFFFFFFFFFFFF}, // Sector 09 + {.a = 0x010155010100, .b = 0xFFFFFFFFFFFF}, // Sector 10 + {.a = 0x010155010100, .b = 0xFFFFFFFFFFFF}, // Sector 11 + {.a = 0x010155010100, .b = 0xFFFFFFFFFFFF}, // Sector 12 + {.a = 0x010155010100, .b = 0xFFFFFFFFFFFF}, // Sector 13 + {.a = 0x010155010100, .b = 0xFFFFFFFFFFFF}, // Sector 14 + {.a = 0x010155010100, .b = 0xFFFFFFFFFFFF}, // Sector 15 +}; + +static bool washcity_verify(Nfc* nfc) { + bool verified = false; + + do { + const uint8_t ticket_sector_number = 0; + const uint8_t ticket_block_number = + mf_classic_get_first_block_num_of_sector(ticket_sector_number) + 1; + FURI_LOG_D(TAG, "Verifying sector %u", ticket_sector_number); + + MfClassicKey key = {0}; + nfc_util_num2bytes(washcity_1k_keys[ticket_sector_number].a, COUNT_OF(key.data), key.data); + + MfClassicAuthContext auth_context; + MfClassicError error = mf_classic_poller_sync_auth( + nfc, ticket_block_number, &key, MfClassicKeyTypeA, &auth_context); + if(error != MfClassicErrorNone) { + FURI_LOG_D(TAG, "Failed to read block %u: %d", ticket_block_number, error); + break; + } + + verified = true; + } while(false); + + return verified; +} + +static bool washcity_read(Nfc* nfc, NfcDevice* device) { + furi_assert(nfc); + furi_assert(device); + + bool is_read = false; + + MfClassicData* data = mf_classic_alloc(); + nfc_device_copy_data(device, NfcProtocolMfClassic, data); + + do { + MfClassicType type = MfClassicTypeMini; + MfClassicError error = mf_classic_poller_sync_detect_type(nfc, &type); + if(error != MfClassicErrorNone) break; + + data->type = type; + if(type != MfClassicType1k) break; + + MfClassicDeviceKeys keys = { + .key_a_mask = 0, + .key_b_mask = 0, + }; + for(size_t i = 0; i < mf_classic_get_total_sectors_num(data->type); i++) { + nfc_util_num2bytes(washcity_1k_keys[i].a, sizeof(MfClassicKey), keys.key_a[i].data); + FURI_BIT_SET(keys.key_a_mask, i); + nfc_util_num2bytes(washcity_1k_keys[i].b, sizeof(MfClassicKey), keys.key_b[i].data); + FURI_BIT_SET(keys.key_b_mask, i); + } + + error = mf_classic_poller_sync_read(nfc, &keys, data); + if(error != MfClassicErrorNone) { + FURI_LOG_W(TAG, "Failed to read data"); + break; + } + + nfc_device_set_data(device, NfcProtocolMfClassic, data); + + is_read = true; + } while(false); + + mf_classic_free(data); + + return is_read; +} + +static bool washcity_parse(const NfcDevice* device, FuriString* parsed_data) { + furi_assert(device); + + const MfClassicData* data = nfc_device_get_data(device, NfcProtocolMfClassic); + + bool parsed = false; + + do { + // Verify key + const uint8_t ticket_sector_number = 1; + const uint8_t ticket_block_number = 0; + + const MfClassicSectorTrailer* sec_tr = + mf_classic_get_sector_trailer_by_sector(data, ticket_sector_number); + + const uint64_t key = nfc_util_bytes2num(sec_tr->key_a.data, COUNT_OF(sec_tr->key_a.data)); + if(key != washcity_1k_keys[ticket_sector_number].a) break; + + // Parse data + const uint8_t start_block_num = + mf_classic_get_first_block_num_of_sector(ticket_sector_number); + + const uint8_t* block_start_ptr = + &data->block[start_block_num + ticket_block_number].data[0]; + + uint32_t balance = nfc_util_bytes2num(block_start_ptr + 2, 2); + + uint32_t balance_usd = balance / 100; + uint8_t balance_cents = balance % 100; + + size_t uid_len = 0; + const uint8_t* uid = mf_classic_get_uid(data, &uid_len); + + // Card Number is printed in HEX (equal to UID) + uint64_t card_number = nfc_util_bytes2num(uid, uid_len); + + furi_string_printf( + parsed_data, + "\e#WashCity\nCard number: %0*llX\nBalance: %lu.%02u USD", + uid_len * 2, + card_number, + balance_usd, + balance_cents); + parsed = true; + } while(false); + + return parsed; +} + +/* Actual implementation of app<>plugin interface */ +static const NfcSupportedCardsPlugin washcity_plugin = { + .protocol = NfcProtocolMfClassic, + .verify = washcity_verify, + .read = washcity_read, + .parse = washcity_parse, +}; + +/* Plugin descriptor to comply with basic plugin specification */ +static const FlipperAppPluginDescriptor washcity_plugin_descriptor = { + .appid = NFC_SUPPORTED_CARD_PLUGIN_APP_ID, + .ep_api_version = NFC_SUPPORTED_CARD_PLUGIN_API_VERSION, + .entry_point = &washcity_plugin, +}; + +/* Plugin entry point - must return a pointer to const descriptor */ +const FlipperAppPluginDescriptor* washcity_plugin_ep() { + return &washcity_plugin_descriptor; +} \ No newline at end of file diff --git a/applications/main/nfc/plugins/supported_cards/zolotaya_korona.c b/applications/main/nfc/plugins/supported_cards/zolotaya_korona.c index 1c48f967a..030b21de6 100644 --- a/applications/main/nfc/plugins/supported_cards/zolotaya_korona.c +++ b/applications/main/nfc/plugins/supported_cards/zolotaya_korona.c @@ -29,8 +29,6 @@ #include #include #include -#include -#include #define TAG "Zolotaya Korona" diff --git a/applications/main/nfc/scenes/nfc_scene_set_type.c b/applications/main/nfc/scenes/nfc_scene_set_type.c index e33660080..ff82587df 100644 --- a/applications/main/nfc/scenes/nfc_scene_set_type.c +++ b/applications/main/nfc/scenes/nfc_scene_set_type.c @@ -53,6 +53,15 @@ bool nfc_scene_set_type_on_event(void* context, SceneManagerEvent event) { nfc_scene_set_type_init_edit_data(instance->iso14443_3a_edit_data, 4); scene_manager_next_scene(instance->scene_manager, NfcSceneSetSak); consumed = true; + } else if( + (event.event == NfcDataGeneratorTypeMfClassic1k_4b) || + (event.event == NfcDataGeneratorTypeMfClassic1k_7b) || + (event.event == NfcDataGeneratorTypeMfClassic4k_4b) || + (event.event == NfcDataGeneratorTypeMfClassic4k_7b) || + (event.event == NfcDataGeneratorTypeMfClassicMini)) { + nfc_data_generator_fill_data(event.event, instance->nfc_device); + scene_manager_next_scene(instance->scene_manager, NfcSceneSetUid); + consumed = true; } else { nfc_data_generator_fill_data(event.event, instance->nfc_device); scene_manager_set_scene_state( diff --git a/applications/main/nfc/scenes/nfc_scene_set_uid.c b/applications/main/nfc/scenes/nfc_scene_set_uid.c index df8a4dc72..7376ce0bc 100644 --- a/applications/main/nfc/scenes/nfc_scene_set_uid.c +++ b/applications/main/nfc/scenes/nfc_scene_set_uid.c @@ -2,6 +2,29 @@ #include "../helpers/protocol_support/nfc_protocol_support_gui_common.h" +// Sync UID from #UID to block 0 data +void mfclassic_sync_uid(NfcDevice* instance) { + size_t uid_len; + const uint8_t* uid = nfc_device_get_uid(instance, &uid_len); + + MfClassicData* mfc_data = (MfClassicData*)nfc_device_get_data(instance, NfcProtocolMfClassic); + uint8_t* block = mfc_data->block[0].data; + + // Sync UID + for(uint8_t i = 0; i < (uint8_t)uid_len; i++) { + block[i] = uid[i]; + } + + if(uid_len == 4) { + // Calculate BCC + block[uid_len] = 0; + + for(uint8_t i = 0; i < (uint8_t)uid_len; i++) { + block[uid_len] ^= block[i]; + } + } +} + static void nfc_scene_set_uid_byte_input_changed_callback(void* context) { NfcApp* instance = context; // Retrieve previously saved UID length @@ -45,6 +68,9 @@ bool nfc_scene_set_uid_on_event(void* context, SceneManagerEvent event) { consumed = true; } } else { + if(nfc_device_get_protocol(instance->nfc_device) == NfcProtocolMfClassic) + mfclassic_sync_uid(instance->nfc_device); + scene_manager_next_scene(instance->scene_manager, NfcSceneSaveName); consumed = true; } diff --git a/applications/system/hid_app/views/hid_mouse_jiggler.c b/applications/system/hid_app/views/hid_mouse_jiggler.c index 3da969aae..09c14c668 100644 --- a/applications/system/hid_app/views/hid_mouse_jiggler.c +++ b/applications/system/hid_app/views/hid_mouse_jiggler.c @@ -82,7 +82,7 @@ static void hid_mouse_jiggler_timer_callback(void* context) { model->counter++; hid_hal_mouse_move( hid_mouse_jiggler->hid, - (model->counter % 2 == 0) ? MOUSE_MOVE_TINY : -MOUSE_MOVE_TINY, + (model->counter % 2 == 0) ? MOUSE_MOVE_SHORT : -MOUSE_MOVE_SHORT, 0); } }, diff --git a/applications/system/hid_app/views/hid_mouse_jiggler.h b/applications/system/hid_app/views/hid_mouse_jiggler.h index c1f77251e..025a86385 100644 --- a/applications/system/hid_app/views/hid_mouse_jiggler.h +++ b/applications/system/hid_app/views/hid_mouse_jiggler.h @@ -2,7 +2,7 @@ #include -#define MOUSE_MOVE_TINY 1 +#define MOUSE_MOVE_SHORT 5 typedef struct Hid Hid; typedef struct HidMouseJiggler HidMouseJiggler; diff --git a/applications/system/hid_app/views/hid_ptt.c b/applications/system/hid_app/views/hid_ptt.c index 3d5879f2b..1d71490a2 100644 --- a/applications/system/hid_app/views/hid_ptt.c +++ b/applications/system/hid_app/views/hid_ptt.c @@ -104,11 +104,7 @@ static void hid_ptt_trigger_camera_linux_zoom(HidPushToTalk* hid_ptt) { hid_hal_keyboard_press(hid_ptt->hid, KEY_MOD_LEFT_ALT | HID_KEYBOARD_V); hid_hal_keyboard_release(hid_ptt->hid, KEY_MOD_LEFT_ALT | HID_KEYBOARD_V); } -static void hid_ptt_trigger_hand_macos_zoom(HidPushToTalk* hid_ptt) { - hid_hal_keyboard_press(hid_ptt->hid, KEY_MOD_LEFT_GUI | HID_KEYBOARD_Y); - hid_hal_keyboard_release(hid_ptt->hid, KEY_MOD_LEFT_GUI | HID_KEYBOARD_Y); -} -static void hid_ptt_trigger_hand_linux_zoom(HidPushToTalk* hid_ptt) { +static void hid_ptt_trigger_hand_zoom(HidPushToTalk* hid_ptt) { hid_hal_keyboard_press(hid_ptt->hid, KEY_MOD_LEFT_ALT | HID_KEYBOARD_Y); hid_hal_keyboard_release(hid_ptt->hid, KEY_MOD_LEFT_ALT | HID_KEYBOARD_Y); } @@ -427,7 +423,7 @@ static void hid_ptt_menu_callback( case HidPushToTalkAppIndexZoom: model->callback_trigger_mute = hid_ptt_trigger_mute_macos_zoom; model->callback_trigger_camera = hid_ptt_trigger_camera_macos_zoom; - model->callback_trigger_hand = hid_ptt_trigger_hand_macos_zoom; + model->callback_trigger_hand = hid_ptt_trigger_hand_zoom; model->callback_start_ptt = hid_ptt_start_ptt_meet_zoom; model->callback_stop_ptt = hid_ptt_stop_ptt_meet_zoom; break; @@ -495,7 +491,7 @@ static void hid_ptt_menu_callback( case HidPushToTalkAppIndexZoom: model->callback_trigger_mute = hid_ptt_trigger_mute_linux_zoom; model->callback_trigger_camera = hid_ptt_trigger_camera_linux_zoom; - model->callback_trigger_hand = hid_ptt_trigger_hand_linux_zoom; + model->callback_trigger_hand = hid_ptt_trigger_hand_zoom; model->callback_start_ptt = hid_ptt_start_ptt_meet_zoom; model->callback_stop_ptt = hid_ptt_stop_ptt_meet_zoom; break;