nfc_magic_scene_file_select.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #include "../nfc_magic_i.h"
  2. static bool nfc_magic_scene_file_select_is_file_suitable(NfcMagic* nfc_magic) {
  3. NfcDevice* nfc_dev = nfc_magic->source_dev;
  4. if(nfc_dev->format == NfcDeviceSaveFormatMifareClassic) {
  5. switch(nfc_magic->dev->type) {
  6. case MagicTypeClassicGen1:
  7. case MagicTypeClassicDirectWrite:
  8. case MagicTypeClassicAPDU:
  9. if((nfc_dev->dev_data.mf_classic_data.type != MfClassicType1k) ||
  10. (nfc_dev->dev_data.nfc_data.uid_len != nfc_magic->dev->uid_len)) {
  11. return false;
  12. }
  13. return true;
  14. case MagicTypeGen4:
  15. return true;
  16. default:
  17. return false;
  18. }
  19. } else if(
  20. (nfc_dev->format == NfcDeviceSaveFormatMifareUl) &&
  21. (nfc_dev->dev_data.nfc_data.uid_len == 7)) {
  22. switch(nfc_magic->dev->type) {
  23. case MagicTypeUltralightGen1:
  24. case MagicTypeUltralightDirectWrite:
  25. case MagicTypeUltralightC_Gen1:
  26. case MagicTypeUltralightC_DirectWrite:
  27. case MagicTypeGen4:
  28. switch(nfc_dev->dev_data.mf_ul_data.type) {
  29. case MfUltralightTypeNTAGI2C1K:
  30. case MfUltralightTypeNTAGI2C2K:
  31. case MfUltralightTypeNTAGI2CPlus1K:
  32. case MfUltralightTypeNTAGI2CPlus2K:
  33. return false;
  34. default:
  35. return true;
  36. }
  37. default:
  38. return false;
  39. }
  40. }
  41. return false;
  42. }
  43. void nfc_magic_scene_file_select_on_enter(void* context) {
  44. NfcMagic* nfc_magic = context;
  45. // Process file_select return
  46. nfc_device_set_loading_callback(
  47. nfc_magic->source_dev, nfc_magic_show_loading_popup, nfc_magic);
  48. if(!furi_string_size(nfc_magic->source_dev->load_path)) {
  49. furi_string_set_str(nfc_magic->source_dev->load_path, NFC_APP_FOLDER);
  50. }
  51. if(nfc_file_select(nfc_magic->source_dev)) {
  52. if(nfc_magic_scene_file_select_is_file_suitable(nfc_magic)) {
  53. scene_manager_next_scene(nfc_magic->scene_manager, NfcMagicSceneWriteConfirm);
  54. } else {
  55. scene_manager_next_scene(nfc_magic->scene_manager, NfcMagicSceneWrongCard);
  56. }
  57. } else {
  58. scene_manager_previous_scene(nfc_magic->scene_manager);
  59. }
  60. }
  61. bool nfc_magic_scene_file_select_on_event(void* context, SceneManagerEvent event) {
  62. UNUSED(context);
  63. UNUSED(event);
  64. return false;
  65. }
  66. void nfc_magic_scene_file_select_on_exit(void* context) {
  67. NfcMagic* nfc_magic = context;
  68. nfc_device_set_loading_callback(nfc_magic->source_dev, NULL, nfc_magic);
  69. }