1 //-----------------------------------------------------------------------------
2 // Hagen Fritsch - June 2010
4 // This code is licensed to you under the terms of the GNU GPL, version 2 or,
5 // at your option, any later version. See the LICENSE.txt file for the text of
8 //-----------------------------------------------------------------------------
9 // Interlib Definitions
10 //-----------------------------------------------------------------------------
20 // PM3 share path relative to executable when installed
21 #define PM3_SHARE_RELPATH ".." PATHSEP "share" PATHSEP "proxmark3" PATHSEP
23 // PM3_USER_DIRECTORY will be expanded from $HOME, e.g. ~/.proxmark3/
24 #define PM3_USER_DIRECTORY PATHSEP ".proxmark3" PATHSEP
26 // PM3 subdirectories:
27 #define PYTHON_SCRIPTS_SUBDIR "pyscripts" PATHSEP
28 #define CMD_SCRIPTS_SUBDIR "cmdscripts" PATHSEP
29 #define DICTIONARIES_SUBDIR "dictionaries" PATHSEP
30 #define LUA_LIBRARIES_SUBDIR "lualibs" PATHSEP
31 #define LUA_SCRIPTS_SUBDIR "luascripts" PATHSEP
32 #define RESOURCES_SUBDIR "resources" PATHSEP
33 #define TRACES_SUBDIR "traces" PATHSEP
34 #define LOGS_SUBDIR "logs" PATHSEP
35 #define FIRMWARES_SUBDIR "firmware" PATHSEP
36 #define BOOTROM_SUBDIR "bootrom" PATHSEP "obj" PATHSEP
37 #define FULLIMAGE_SUBDIR "armsrc" PATHSEP "obj" PATHSEP
39 #define PACKED __attribute__((packed))
41 #define VERSION_INFORMATION_MAGIC 0x56334d50 // "PM3V"
42 struct version_information
{
43 int magic
; /* Magic sequence to identify this as a correct version information structure. Must be VERSION_INFORMATION_MAGIC */
44 char versionversion
; /* Must be 1 */
45 char present
; /* 1 if the version information could be created at compile time, otherwise 0 and the remaining fields (except for magic) are empty */
46 char clean
; /* 1: Tree was clean, no local changes. 0: Tree was unclean. 2: Couldn't be determined */
47 char gitversion
[50]; /* String with the git revision */
48 char buildtime
[30]; /* string with the build time */
52 #define DBG_NONE 0 // no messages
53 #define DBG_ERROR 1 // errors only
54 #define DBG_INFO 2 // errors + info messages
55 #define DBG_DEBUG 3 // errors + info + debug messages
56 #define DBG_EXTENDED 4 // errors + info + debug + breaking debug messages
60 extern uint16_t tearoff_delay_us
;
61 extern bool tearoff_enabled
;
63 // reader voltage field detector
64 #define MF_MINFIELDV 4000
67 # define MIN(a, b) (((a) < (b)) ? (a) : (b))
71 # define MAX(a, b) (((a) > (b)) ? (a) : (b))
75 # define ABS(a) ( ((a)<0) ? -(a) : (a) )
79 //#define RAMFUNC __attribute((long_call, section(".ramfunc")))
80 #define RAMFUNC __attribute((long_call, section(".ramfunc"))) __attribute__((target("arm")))
83 # define ROTR(x,n) (((uintmax_t)(x) >> (n)) | ((uintmax_t)(x) << ((sizeof(x) * 8) - (n))))
87 # define PM3_ROTL(x,n) (((uintmax_t)(x) << (n)) | ((uintmax_t)(x) >> ((sizeof(x) * 8) - (n))))
90 // endian change for 64bit
93 #define BSWAP_64(x) __builtin_bswap64(x)
98 #define BSWAP_64(x) _byteswap_uint64(x)
102 #define BSWAP_64(x) \
103 (((uint64_t)(x) << 56) | \
104 (((uint64_t)(x) << 40) & 0xff000000000000ULL) | \
105 (((uint64_t)(x) << 24) & 0xff0000000000ULL) | \
106 (((uint64_t)(x) << 8) & 0xff00000000ULL) | \
107 (((uint64_t)(x) >> 8) & 0xff000000ULL) | \
108 (((uint64_t)(x) >> 24) & 0xff0000ULL) | \
109 (((uint64_t)(x) >> 40) & 0xff00ULL) | \
110 ((uint64_t)(x) >> 56))
115 // endian change for 32bit
118 #define BSWAP_32(x) __builtin_bswap32(x)
123 #define BSWAP_32(x) _byteswap_ulong(x)
127 # define BSWAP_32(x) \
128 ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \
129 (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24))
134 // convert 2 bytes to U16
136 # define BYTES2UINT16(x) ((x[1] << 8) | (x[0]))
138 // convert 4 bytes to U32
140 # define BYTES2UINT32(x) ((x[3] << 24) | (x[2] << 16) | (x[1] << 8) | (x[0]))
148 # define NIBBLE_HIGH(b) ( (b & 0xF0) >> 4 )
152 # define NIBBLE_LOW(b) ( b & 0x0F )
156 # define CRUMB(b,p) (((b & (0x3 << p) ) >> p ) & 0xF)
160 # define SWAP_NIBBLE(b) ( (NIBBLE_LOW(b)<< 4) | NIBBLE_HIGH(b))
163 // Binary Encoded Digit
165 # define BCD2DEC(bcd) HornerScheme(bcd, 0x10, 10)
169 # define DEC2BCD(dec) HornerScheme(dec, 10, 0x10)
172 // bit stream operations
173 #define TEST_BIT(data, i) (*(data + (i / 8)) >> (7 - (i % 8))) & 1
174 #define SET_BIT(data, i) *(data + (i / 8)) |= (1 << (7 - (i % 8)))
175 #define CLEAR_BIT(data, i) *(data + (i / 8)) &= ~(1 << (7 - (i % 8)))
176 #define FLIP_BIT(data, i) *(data + (i / 8)) ^= (1 << (7 - (i % 8)))