MX пре 2 година
родитељ
комит
58ffc023f1
4 измењених фајлова са 14 додато и 7 уклоњено
  1. BIN
      assets/125_10px.png
  2. 1 1
      lib/magic/gen4.c
  3. 3 1
      lib/magic/gen4.h
  4. 10 5
      nfc_magic_worker.c

BIN
assets/125_10px.png


+ 1 - 1
lib/magic/gen4.c

@@ -17,7 +17,7 @@
 #define MAGIC_BUFFER_SIZE (40)
 
 const uint8_t MAGIC_DEFAULT_CONFIG[] = {
-    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x09, 0x78, 0x00, 0x91, 0x02, 0xDA, 0xBC, 0x19, 0x10, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x04, 0x00, 0x08, 0x00
+    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x09, 0x78, 0x00, 0x91, 0x02, 0xDA, 0xBC, 0x19, 0x10, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x04, 0x00, 0x08, 0x00, 0x6b, 0x02
 };
 
 const uint8_t MAGIC_DEFAULT_BLOCK0[] = {

+ 3 - 1
lib/magic/gen4.h

@@ -3,7 +3,7 @@
 #include <lib/nfc/protocols/mifare_classic.h>
 
 #define MAGIC_GEN4_DEFAULT_PWD 0x00000000
-#define MAGIC_GEN4_CONFIG_LEN 32
+#define MAGIC_GEN4_CONFIG_LEN 30
 
 #define NFCID1_SINGLE_SIZE 4
 #define NFCID1_DOUBLE_SIZE 7
@@ -33,6 +33,8 @@ typedef enum {
     MagicGen4ShadowModeHighSpeedIgnore = 0x03
 } MagicGen4ShadowMode;
 
+extern const uint8_t MAGIC_DEFAULT_CONFIG[];
+
 bool magic_gen4_get_cfg(uint32_t pwd, uint8_t* config);
 
 bool magic_gen4_set_cfg(uint32_t pwd, const uint8_t* config, uint8_t config_length, bool fuse);

+ 10 - 5
nfc_magic_worker.c

@@ -131,13 +131,17 @@ void nfc_magic_worker_write(NfcMagicWorker* nfc_magic_worker) {
                 }
             } else if(magic_dev->type == MagicTypeGen4) {
                 if(furi_hal_nfc_detect(&nfc_data, 200)) {
-                    uint8_t gen4_config[28];
+                    uint8_t gen4_config[MAGIC_GEN4_CONFIG_LEN];
+                    memcpy(gen4_config, MAGIC_DEFAULT_CONFIG, MAGIC_GEN4_CONFIG_LEN);
                     uint32_t password = magic_dev->password;
-
                     uint32_t cuid;
+                    size_t block_count = 64;
+                    MfClassicData* mfc_data;
                     if(dev_protocol == NfcDeviceProtocolMifareClassic) {
                         gen4_config[0] = 0x00;
                         gen4_config[27] = 0x00;
+                        mfc_data = &dev_data->mf_classic_data;
+                        if(mfc_data->type == MfClassicType4k) block_count = 256;
                     } else if(dev_protocol == NfcDeviceProtocolMifareUl) {
                         MfUltralightData* mf_ul_data = &dev_data->mf_ul_data;
                         gen4_config[0] = 0x01;
@@ -158,6 +162,7 @@ void nfc_magic_worker_write(NfcMagicWorker* nfc_magic_worker) {
                         case MfUltralightTypeNTAGI2CPlus1K:
                         case MfUltralightTypeNTAGI2CPlus2K:
                             gen4_config[27] = MagicGen4UltralightModeNTAG;
+                            block_count = 64 * 2;
                             break;
                         }
                     }
@@ -190,6 +195,9 @@ void nfc_magic_worker_write(NfcMagicWorker* nfc_magic_worker) {
                     gen4_config[25] = dev_data->nfc_data.atqa[1];
                     gen4_config[26] = dev_data->nfc_data.sak;
 
+                    gen4_config[28] = block_count;
+                    gen4_config[29] = 0x01;
+
                     furi_hal_nfc_sleep();
                     furi_hal_nfc_activate_nfca(200, &cuid);
                     if(!magic_gen4_set_cfg(password, gen4_config, sizeof(gen4_config), false)) {
@@ -199,9 +207,6 @@ void nfc_magic_worker_write(NfcMagicWorker* nfc_magic_worker) {
                         break;
                     }
                     if(dev_protocol == NfcDeviceProtocolMifareClassic) {
-                        MfClassicData* mfc_data = &dev_data->mf_classic_data;
-                        size_t block_count = 64;
-                        if(mfc_data->type == MfClassicType4k) block_count = 256;
                         for(size_t i = 0; i < block_count; i++) {
                             FURI_LOG_D(TAG, "Writing block %d", i);
                             if(!magic_gen4_write_blk(password, i, mfc_data->block[i].value)) {