nfc_magic_scene_file_select.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #include "../nfc_magic_app_i.h"
  2. #include <nfc/protocols/mf_classic/mf_classic.h>
  3. static bool nfc_magic_scene_file_select_is_file_suitable(NfcMagicApp* instance) {
  4. NfcProtocol protocol = nfc_device_get_protocol(instance->source_dev);
  5. size_t uid_len = 0;
  6. nfc_device_get_uid(instance->source_dev, &uid_len);
  7. bool suitable = false;
  8. if(instance->protocol == NfcMagicProtocolGen1) {
  9. if((uid_len == 4) && (protocol == NfcProtocolMfClassic)) {
  10. const MfClassicData* mfc_data =
  11. nfc_device_get_data(instance->source_dev, NfcProtocolMfClassic);
  12. if(mfc_data->type == MfClassicType1k) {
  13. suitable = true;
  14. }
  15. }
  16. } else if(instance->protocol == NfcMagicProtocolGen4) {
  17. if(protocol == NfcProtocolMfClassic) {
  18. suitable = true;
  19. } else if(protocol == NfcProtocolMfUltralight) {
  20. const MfUltralightData* mfu_data =
  21. nfc_device_get_data(instance->source_dev, NfcProtocolMfUltralight);
  22. const Iso14443_3aData* iso3_data = mfu_data->iso14443_3a_data;
  23. if(iso3_data->uid_len == 7) {
  24. MfUltralightType mfu_type = mfu_data->type;
  25. suitable = (mfu_type != MfUltralightTypeNTAGI2C1K) &&
  26. (mfu_type != MfUltralightTypeNTAGI2C2K) &&
  27. (mfu_type != MfUltralightTypeNTAGI2CPlus1K) &&
  28. (mfu_type != MfUltralightTypeNTAGI2CPlus2K);
  29. }
  30. }
  31. }
  32. return suitable;
  33. }
  34. void nfc_magic_scene_file_select_on_enter(void* context) {
  35. NfcMagicApp* instance = context;
  36. if(nfc_magic_load_from_file_select(instance)) {
  37. if(nfc_magic_scene_file_select_is_file_suitable(instance)) {
  38. scene_manager_next_scene(instance->scene_manager, NfcMagicSceneWriteConfirm);
  39. } else {
  40. scene_manager_next_scene(instance->scene_manager, NfcMagicSceneWrongCard);
  41. }
  42. } else {
  43. scene_manager_previous_scene(instance->scene_manager);
  44. }
  45. }
  46. bool nfc_magic_scene_file_select_on_event(void* context, SceneManagerEvent event) {
  47. UNUSED(context);
  48. UNUSED(event);
  49. return false;
  50. }
  51. void nfc_magic_scene_file_select_on_exit(void* context) {
  52. UNUSED(context);
  53. }