Merge pull request #690 from DarkFlippers/leptoptilos

NFC: Add manually MF Classic with custom UID
This commit is contained in:
MMX 2024-01-05 22:53:30 +03:00 committed by GitHub
commit 1d35110a98
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 0 deletions

View File

@ -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(

View File

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