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; }