+#include "cmdhf14a.h" // DropField()
+#include "mifare.h"
+#include "util.h"
+#include "util_posix.h"
+#include "protocols.h"
+#include "taginfo.h"
+#include "crypto/libpcrypto.h"
+
+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 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)
+};
+
+// known public keys for the originality check (source: https://github.com/alexbatalov/node-nxp-originality-verifier)
+uint8_t public_keys[2][33] = {{0x04,0x49,0x4e,0x1a,0x38,0x6d,0x3d,0x3c,0xfe,0x3d,0xc1,0x0e,0x5d,0xe6,0x8a,0x49,0x9b, // UL and NDEF
+ 0x1c,0x20,0x2d,0xb5,0xb1,0x32,0x39,0x3e,0x89,0xed,0x19,0xfe,0x5b,0xe8,0xbc,0x61},
+ {0x04,0x90,0x93,0x3b,0xdc,0xd6,0xe9,0x9b,0x4e,0x25,0x5e,0x3d,0xa5,0x53,0x89,0xa8,0x27, // UL EV1
+ 0x56,0x4e,0x11,0x71,0x8e,0x01,0x72,0x92,0xfa,0xf2,0x32,0x26,0xa9,0x66,0x14,0xb8}
+};