-#define MAX_UL_BLOCKS 0x0f
-#define MAX_ULC_BLOCKS 0x2f
-#define MAX_ULEV1a_BLOCKS 0x0b;
-#define MAX_ULEV1b_BLOCKS 0x20;
-
-uint8_t default_3des_keys[7][16] = {
- { 0x42,0x52,0x45,0x41,0x4b,0x4d,0x45,0x49,0x46,0x59,0x4f,0x55,0x43,0x41,0x4e,0x21 },// 3des std key
- { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 },// all zeroes
- { 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f },// 0x00-0x0F
- { 0x49,0x45,0x4D,0x4B,0x41,0x45,0x52,0x42,0x21,0x4E,0x41,0x43,0x55,0x4F,0x59,0x46 },// NFC-key
- { 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01 },// all ones
- { 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF },// all FF
- { 0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88,0x99,0xAA,0xBB,0xCC,0xDD,0xEE,0xFF } // 11 22 33
- };
-
-static int CmdHelp(const char *Cmd);
+typedef enum TAGTYPE_UL {
+ UNKNOWN = 0x000000,
+ UL = 0x000001,
+ UL_C = 0x000002,
+ UL_EV1_48 = 0x000004,
+ UL_EV1_128 = 0x000008,
+ NTAG = 0x000010,
+ NTAG_203 = 0x000020,
+ NTAG_210 = 0x000040,
+ NTAG_212 = 0x000080,
+ NTAG_213 = 0x000100,
+ NTAG_215 = 0x000200,
+ NTAG_216 = 0x000400,
+ MY_D = 0x000800,
+ MY_D_NFC = 0x001000,
+ MY_D_MOVE = 0x002000,
+ MY_D_MOVE_LEAN= 0x004000,
+ NTAG_I2C_1K = 0x008000,
+ NTAG_I2C_2K = 0x010000,
+ FUDAN_UL = 0x020000,
+ MAGIC = 0x040000,
+ UL_MAGIC = UL | MAGIC,
+ UL_C_MAGIC = UL_C | MAGIC,
+ UL_ERROR = 0xFFFFFF,
+} TagTypeUL_t;
+
+#define MAX_UL_BLOCKS 0x0f
+#define MAX_ULC_BLOCKS 0x2b
+#define MAX_ULEV1a_BLOCKS 0x13
+#define MAX_ULEV1b_BLOCKS 0x28
+#define MAX_NTAG_203 0x29
+#define MAX_NTAG_210 0x13
+#define MAX_NTAG_212 0x28
+#define MAX_NTAG_213 0x2c
+#define MAX_NTAG_215 0x86
+#define MAX_NTAG_216 0xe6
+#define MAX_MY_D_NFC 0xff
+#define MAX_MY_D_MOVE 0x25
+#define MAX_MY_D_MOVE_LEAN 0x0f
+
+#define PUBLIC_ECDA_KEYLEN 33
+static uint8_t public_ecda_key[PUBLIC_ECDA_KEYLEN] = {
+ 0x04, 0x49, 0x4e, 0x1a, 0x38, 0x6d, 0x3d, 0x3c,
+ 0xfe, 0x3d, 0xc1, 0x0e, 0x5d, 0xe6, 0x8a, 0x49,
+ 0x9b, 0x1c, 0x20, 0x2d, 0xb5, 0xb1, 0x32, 0x39,
+ 0x3e, 0x89, 0xed, 0x19, 0xfe, 0x5b, 0xe8, 0xbc,
+ 0x61
+};
+
+#define KEYS_3DES_COUNT 7
+static uint8_t default_3des_keys[KEYS_3DES_COUNT][16] = {
+ { 0x42,0x52,0x45,0x41,0x4b,0x4d,0x45,0x49,0x46,0x59,0x4f,0x55,0x43,0x41,0x4e,0x21 },// 3des std key
+ { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 },// all zeroes
+ { 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f },// 0x00-0x0F
+ { 0x49,0x45,0x4D,0x4B,0x41,0x45,0x52,0x42,0x21,0x4E,0x41,0x43,0x55,0x4F,0x59,0x46 },// NFC-key
+ { 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01 },// all ones
+ { 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF },// all FF
+ { 0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88,0x99,0xAA,0xBB,0xCC,0xDD,0xEE,0xFF } // 11 22 33
+};
+
+#define KEYS_PWD_COUNT 6
+static uint8_t default_pwd_pack[KEYS_PWD_COUNT][4] = {
+ {0xFF,0xFF,0xFF,0xFF}, // PACK 0x00,0x00 -- factory default
+ {0x4A,0xF8,0x4B,0x19}, // PACK 0xE5,0xBE -- italian bus (sniffed)
+ {0x33,0x6B,0xA1,0x19}, // PACK 0x9c,0x2d -- italian bus (sniffed)
+ {0xFF,0x90,0x6C,0xB2}, // PACK 0x12,0x9e -- italian bus (sniffed)
+ {0x46,0x1c,0xA3,0x19}, // PACK 0xE9,0x5A -- italian bus (sniffed)
+ {0x35,0x1C,0xD0,0x19}, // PACK 0x9A,0x5a -- italian bus (sniffed)
+};
+
+#define MAX_UL_TYPES 17
+static uint32_t UL_TYPES_ARRAY[MAX_UL_TYPES] = {UNKNOWN, UL, UL_C, UL_EV1_48, UL_EV1_128, NTAG, NTAG_203,
+ NTAG_210, NTAG_212, NTAG_213, NTAG_215, NTAG_216, MY_D, MY_D_NFC, MY_D_MOVE, MY_D_MOVE_LEAN, FUDAN_UL};
+
+static uint8_t UL_MEMORY_ARRAY[MAX_UL_TYPES] = {MAX_UL_BLOCKS, MAX_UL_BLOCKS, MAX_ULC_BLOCKS, MAX_ULEV1a_BLOCKS,
+ MAX_ULEV1b_BLOCKS, MAX_NTAG_203, MAX_NTAG_203, MAX_NTAG_210, MAX_NTAG_212, MAX_NTAG_213,
+ MAX_NTAG_215, MAX_NTAG_216, MAX_UL_BLOCKS, MAX_MY_D_NFC, MAX_MY_D_MOVE, MAX_MY_D_MOVE_LEAN, MAX_UL_BLOCKS};
+
+// get version nxp product type
+static char *getProductTypeStr( uint8_t id){
+
+ static char buf[20];
+ char *retStr = buf;
+
+ switch(id) {
+ case 3: sprintf(retStr, "%02X, Ultralight", id); break;
+ case 4: sprintf(retStr, "%02X, NTAG", id); break;
+ default: sprintf(retStr, "%02X, unknown", id); break;
+ }
+ return buf;
+}
+
+/*
+ The 7 MSBits (=n) code the storage size itself based on 2^n,
+ the LSBit is set to '0' if the size is exactly 2^n
+ and set to '1' if the storage size is between 2^n and 2^(n+1).
+*/
+static char *getUlev1CardSizeStr( uint8_t fsize ){
+
+ static char buf[40];
+ char *retStr = buf;
+ memset(buf, 0, sizeof(buf));
+
+ uint16_t usize = 1 << ((fsize >>1) + 1);
+ uint16_t lsize = 1 << (fsize >>1);
+
+ // is LSB set?
+ if ( fsize & 1 )
+ sprintf(retStr, "%02X, (%u <-> %u bytes)",fsize, usize, lsize);
+ else
+ sprintf(retStr, "%02X, (%u bytes)", fsize, lsize);
+ return buf;
+}