NFC refactoring (#3050)
"A long time ago in a galaxy far, far away...." we started NFC subsystem refactoring.
Starring:
- @gornekich - NFC refactoring project lead, architect, senior developer
- @gsurkov - architect, senior developer
- @RebornedBrain - senior developer
Supporting roles:
- @skotopes, @DrZlo13, @hedger - general architecture advisors, code review
- @Astrrra, @doomwastaken, @Hellitron, @ImagineVagon333 - quality assurance
Special thanks:
@bettse, @pcunning, @nxv, @noproto, @AloneLiberty and everyone else who has been helping us all this time and contributing valuable knowledges, ideas and source code.
2023-10-24 03:08:09 +00:00
|
|
|
#include "../nfc_app_i.h"
|
2021-07-02 13:44:10 +00:00
|
|
|
|
NFC refactoring (#3050)
"A long time ago in a galaxy far, far away...." we started NFC subsystem refactoring.
Starring:
- @gornekich - NFC refactoring project lead, architect, senior developer
- @gsurkov - architect, senior developer
- @RebornedBrain - senior developer
Supporting roles:
- @skotopes, @DrZlo13, @hedger - general architecture advisors, code review
- @Astrrra, @doomwastaken, @Hellitron, @ImagineVagon333 - quality assurance
Special thanks:
@bettse, @pcunning, @nxv, @noproto, @AloneLiberty and everyone else who has been helping us all this time and contributing valuable knowledges, ideas and source code.
2023-10-24 03:08:09 +00:00
|
|
|
#include "../helpers/protocol_support/nfc_protocol_support_gui_common.h"
|
2021-07-02 13:44:10 +00:00
|
|
|
|
2024-01-05 15:56:50 +00:00
|
|
|
// 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];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
NFC refactoring (#3050)
"A long time ago in a galaxy far, far away...." we started NFC subsystem refactoring.
Starring:
- @gornekich - NFC refactoring project lead, architect, senior developer
- @gsurkov - architect, senior developer
- @RebornedBrain - senior developer
Supporting roles:
- @skotopes, @DrZlo13, @hedger - general architecture advisors, code review
- @Astrrra, @doomwastaken, @Hellitron, @ImagineVagon333 - quality assurance
Special thanks:
@bettse, @pcunning, @nxv, @noproto, @AloneLiberty and everyone else who has been helping us all this time and contributing valuable knowledges, ideas and source code.
2023-10-24 03:08:09 +00:00
|
|
|
static void nfc_scene_set_uid_byte_input_changed_callback(void* context) {
|
|
|
|
NfcApp* instance = context;
|
|
|
|
// Retrieve previously saved UID length
|
|
|
|
const size_t uid_len = scene_manager_get_scene_state(instance->scene_manager, NfcSceneSetUid);
|
|
|
|
nfc_device_set_uid(instance->nfc_device, instance->byte_input_store, uid_len);
|
2021-07-02 13:44:10 +00:00
|
|
|
}
|
|
|
|
|
2021-09-21 09:34:16 +00:00
|
|
|
void nfc_scene_set_uid_on_enter(void* context) {
|
NFC refactoring (#3050)
"A long time ago in a galaxy far, far away...." we started NFC subsystem refactoring.
Starring:
- @gornekich - NFC refactoring project lead, architect, senior developer
- @gsurkov - architect, senior developer
- @RebornedBrain - senior developer
Supporting roles:
- @skotopes, @DrZlo13, @hedger - general architecture advisors, code review
- @Astrrra, @doomwastaken, @Hellitron, @ImagineVagon333 - quality assurance
Special thanks:
@bettse, @pcunning, @nxv, @noproto, @AloneLiberty and everyone else who has been helping us all this time and contributing valuable knowledges, ideas and source code.
2023-10-24 03:08:09 +00:00
|
|
|
NfcApp* instance = context;
|
|
|
|
|
|
|
|
size_t uid_len;
|
|
|
|
const uint8_t* uid = nfc_device_get_uid(instance->nfc_device, &uid_len);
|
|
|
|
|
|
|
|
memcpy(instance->byte_input_store, uid, uid_len);
|
|
|
|
// Save UID length for use in callback
|
|
|
|
scene_manager_set_scene_state(instance->scene_manager, NfcSceneSetUid, uid_len);
|
2021-07-02 13:44:10 +00:00
|
|
|
|
|
|
|
// Setup view
|
NFC refactoring (#3050)
"A long time ago in a galaxy far, far away...." we started NFC subsystem refactoring.
Starring:
- @gornekich - NFC refactoring project lead, architect, senior developer
- @gsurkov - architect, senior developer
- @RebornedBrain - senior developer
Supporting roles:
- @skotopes, @DrZlo13, @hedger - general architecture advisors, code review
- @Astrrra, @doomwastaken, @Hellitron, @ImagineVagon333 - quality assurance
Special thanks:
@bettse, @pcunning, @nxv, @noproto, @AloneLiberty and everyone else who has been helping us all this time and contributing valuable knowledges, ideas and source code.
2023-10-24 03:08:09 +00:00
|
|
|
ByteInput* byte_input = instance->byte_input;
|
2023-02-08 08:08:50 +00:00
|
|
|
byte_input_set_header_text(byte_input, "Enter UID in hex");
|
2021-07-02 13:44:10 +00:00
|
|
|
byte_input_set_result_callback(
|
|
|
|
byte_input,
|
NFC refactoring (#3050)
"A long time ago in a galaxy far, far away...." we started NFC subsystem refactoring.
Starring:
- @gornekich - NFC refactoring project lead, architect, senior developer
- @gsurkov - architect, senior developer
- @RebornedBrain - senior developer
Supporting roles:
- @skotopes, @DrZlo13, @hedger - general architecture advisors, code review
- @Astrrra, @doomwastaken, @Hellitron, @ImagineVagon333 - quality assurance
Special thanks:
@bettse, @pcunning, @nxv, @noproto, @AloneLiberty and everyone else who has been helping us all this time and contributing valuable knowledges, ideas and source code.
2023-10-24 03:08:09 +00:00
|
|
|
nfc_protocol_support_common_byte_input_done_callback,
|
|
|
|
nfc_scene_set_uid_byte_input_changed_callback,
|
|
|
|
instance,
|
|
|
|
instance->byte_input_store,
|
|
|
|
uid_len);
|
|
|
|
|
|
|
|
view_dispatcher_switch_to_view(instance->view_dispatcher, NfcViewByteInput);
|
2021-07-02 13:44:10 +00:00
|
|
|
}
|
|
|
|
|
2021-09-21 09:34:16 +00:00
|
|
|
bool nfc_scene_set_uid_on_event(void* context, SceneManagerEvent event) {
|
NFC refactoring (#3050)
"A long time ago in a galaxy far, far away...." we started NFC subsystem refactoring.
Starring:
- @gornekich - NFC refactoring project lead, architect, senior developer
- @gsurkov - architect, senior developer
- @RebornedBrain - senior developer
Supporting roles:
- @skotopes, @DrZlo13, @hedger - general architecture advisors, code review
- @Astrrra, @doomwastaken, @Hellitron, @ImagineVagon333 - quality assurance
Special thanks:
@bettse, @pcunning, @nxv, @noproto, @AloneLiberty and everyone else who has been helping us all this time and contributing valuable knowledges, ideas and source code.
2023-10-24 03:08:09 +00:00
|
|
|
NfcApp* instance = context;
|
2022-04-19 15:23:58 +00:00
|
|
|
bool consumed = false;
|
2021-07-02 13:44:10 +00:00
|
|
|
|
2023-08-10 11:48:42 +00:00
|
|
|
if(event.type == SceneManagerEventTypeCustom) {
|
2022-02-02 19:59:28 +00:00
|
|
|
if(event.event == NfcCustomEventByteInputDone) {
|
NFC refactoring (#3050)
"A long time ago in a galaxy far, far away...." we started NFC subsystem refactoring.
Starring:
- @gornekich - NFC refactoring project lead, architect, senior developer
- @gsurkov - architect, senior developer
- @RebornedBrain - senior developer
Supporting roles:
- @skotopes, @DrZlo13, @hedger - general architecture advisors, code review
- @Astrrra, @doomwastaken, @Hellitron, @ImagineVagon333 - quality assurance
Special thanks:
@bettse, @pcunning, @nxv, @noproto, @AloneLiberty and everyone else who has been helping us all this time and contributing valuable knowledges, ideas and source code.
2023-10-24 03:08:09 +00:00
|
|
|
if(scene_manager_has_previous_scene(instance->scene_manager, NfcSceneSavedMenu)) {
|
|
|
|
if(nfc_save(instance)) {
|
|
|
|
scene_manager_next_scene(instance->scene_manager, NfcSceneSaveSuccess);
|
2022-08-03 17:00:17 +00:00
|
|
|
consumed = true;
|
|
|
|
}
|
2023-08-10 11:48:42 +00:00
|
|
|
} else {
|
2024-01-05 15:56:50 +00:00
|
|
|
if(nfc_device_get_protocol(instance->nfc_device) == NfcProtocolMfClassic)
|
|
|
|
mfclassic_sync_uid(instance->nfc_device);
|
|
|
|
|
NFC refactoring (#3050)
"A long time ago in a galaxy far, far away...." we started NFC subsystem refactoring.
Starring:
- @gornekich - NFC refactoring project lead, architect, senior developer
- @gsurkov - architect, senior developer
- @RebornedBrain - senior developer
Supporting roles:
- @skotopes, @DrZlo13, @hedger - general architecture advisors, code review
- @Astrrra, @doomwastaken, @Hellitron, @ImagineVagon333 - quality assurance
Special thanks:
@bettse, @pcunning, @nxv, @noproto, @AloneLiberty and everyone else who has been helping us all this time and contributing valuable knowledges, ideas and source code.
2023-10-24 03:08:09 +00:00
|
|
|
scene_manager_next_scene(instance->scene_manager, NfcSceneSaveName);
|
2023-08-10 11:48:42 +00:00
|
|
|
consumed = true;
|
2022-08-03 17:00:17 +00:00
|
|
|
}
|
2021-07-12 18:56:14 +00:00
|
|
|
}
|
2021-07-02 13:44:10 +00:00
|
|
|
}
|
2022-11-10 16:20:35 +00:00
|
|
|
|
2022-04-19 15:23:58 +00:00
|
|
|
return consumed;
|
2021-07-02 13:44:10 +00:00
|
|
|
}
|
|
|
|
|
2021-09-21 09:34:16 +00:00
|
|
|
void nfc_scene_set_uid_on_exit(void* context) {
|
NFC refactoring (#3050)
"A long time ago in a galaxy far, far away...." we started NFC subsystem refactoring.
Starring:
- @gornekich - NFC refactoring project lead, architect, senior developer
- @gsurkov - architect, senior developer
- @RebornedBrain - senior developer
Supporting roles:
- @skotopes, @DrZlo13, @hedger - general architecture advisors, code review
- @Astrrra, @doomwastaken, @Hellitron, @ImagineVagon333 - quality assurance
Special thanks:
@bettse, @pcunning, @nxv, @noproto, @AloneLiberty and everyone else who has been helping us all this time and contributing valuable knowledges, ideas and source code.
2023-10-24 03:08:09 +00:00
|
|
|
NfcApp* instance = context;
|
2021-07-02 13:44:10 +00:00
|
|
|
|
|
|
|
// Clear view
|
NFC refactoring (#3050)
"A long time ago in a galaxy far, far away...." we started NFC subsystem refactoring.
Starring:
- @gornekich - NFC refactoring project lead, architect, senior developer
- @gsurkov - architect, senior developer
- @RebornedBrain - senior developer
Supporting roles:
- @skotopes, @DrZlo13, @hedger - general architecture advisors, code review
- @Astrrra, @doomwastaken, @Hellitron, @ImagineVagon333 - quality assurance
Special thanks:
@bettse, @pcunning, @nxv, @noproto, @AloneLiberty and everyone else who has been helping us all this time and contributing valuable knowledges, ideas and source code.
2023-10-24 03:08:09 +00:00
|
|
|
byte_input_set_result_callback(instance->byte_input, NULL, NULL, NULL, NULL, 0);
|
|
|
|
byte_input_set_header_text(instance->byte_input, "");
|
2021-07-02 13:44:10 +00:00
|
|
|
}
|