NFC: Add manually MF Classic UID desync bug fixed

This commit is contained in:
Methodius 2024-01-06 00:56:50 +09:00
parent 66756853a6
commit d1df26cc83
No known key found for this signature in database
GPG key ID: 122FA99A00B41679

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