1 //-----------------------------------------------------------------------------
2 // Copyright (C) Proxmark3 contributors. See AUTHORS.md for details.
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // See LICENSE.txt for the text of the license.
15 //-----------------------------------------------------------------------------
16 // Interlib Definitions
17 //-----------------------------------------------------------------------------
34 // PM3 share path relative to executable when installed
35 #define PM3_SHARE_RELPATH ".." PATHSEP "share" PATHSEP "proxmark3" PATHSEP
37 // PM3_USER_DIRECTORY will be expanded from $HOME, e.g. ~/.proxmark3/
38 #define PM3_USER_DIRECTORY PATHSEP ".proxmark3" PATHSEP
40 // PM3 subdirectories:
41 #define PYTHON_SCRIPTS_SUBDIR "pyscripts" PATHSEP
42 #define CMD_SCRIPTS_SUBDIR "cmdscripts" PATHSEP
43 #define DICTIONARIES_SUBDIR "dictionaries" PATHSEP
44 #define LUA_LIBRARIES_SUBDIR "lualibs" PATHSEP
45 #define LUA_SCRIPTS_SUBDIR "luascripts" PATHSEP
46 #define RESOURCES_SUBDIR "resources" PATHSEP
47 #define TRACES_SUBDIR "traces" PATHSEP
48 #define LOGS_SUBDIR "logs" PATHSEP
49 #define FIRMWARES_SUBDIR "firmware" PATHSEP
50 #define BOOTROM_SUBDIR "bootrom" PATHSEP "obj" PATHSEP
51 #define FULLIMAGE_SUBDIR "armsrc" PATHSEP "obj" PATHSEP
53 #define PACKED __attribute__((packed))
55 #define VERSION_INFORMATION_MAGIC 0x56334d50 // "PM3V"
56 struct version_information_t
{
57 int magic
; /* Magic sequence to identify this as a correct version information structure. Must be VERSION_INFORMATION_MAGIC */
58 char versionversion
; /* Must be 1 */
59 char present
; /* 1 if the version information could be created at compile time, otherwise 0 and the remaining fields (except for magic) are empty */
60 char clean
; /* 1: Tree was clean, no local changes. 0: Tree was unclean. 2: Couldn't be determined */
61 char gitversion
[50]; /* String with the git revision */
62 char buildtime
[30]; /* string with the build time */
63 char armsrc
[10]; /* sha256sum of sha256sum of armsrc && common_arm files */
67 #define DBG_NONE 0 // no messages
68 #define DBG_ERROR 1 // errors only
69 #define DBG_INFO 2 // errors + info messages
70 #define DBG_DEBUG 3 // errors + info + debug messages
71 #define DBG_EXTENDED 4 // errors + info + debug + breaking debug messages
72 extern int g_dbglevel
;
75 extern uint16_t g_tearoff_delay_us
;
76 extern bool g_tearoff_enabled
;
78 // reader voltage field detector
79 #define MF_MINFIELDV 4000
82 # define MIN(a, b) (((a) < (b)) ? (a) : (b))
86 # define MAX(a, b) (((a) > (b)) ? (a) : (b))
90 # define ABS(a) ( ((a)<0) ? -(a) : (a) )
94 //#define RAMFUNC __attribute((long_call, section(".ramfunc")))
95 #define RAMFUNC __attribute((long_call, section(".ramfunc"))) __attribute__((target("arm")))
98 # define ROTR(x,n) (((uintmax_t)(x) >> (n)) | ((uintmax_t)(x) << ((sizeof(x) * 8) - (n))))
102 # define PM3_ROTL(x,n) (((uintmax_t)(x) << (n)) | ((uintmax_t)(x) >> ((sizeof(x) * 8) - (n))))
105 // endian change for 64bit
108 #define BSWAP_64(x) __builtin_bswap64(x)
113 #define BSWAP_64(x) _byteswap_uint64(x)
117 #define BSWAP_64(x) \
118 (((uint64_t)(x) << 56) | \
119 (((uint64_t)(x) << 40) & 0xff000000000000ULL) | \
120 (((uint64_t)(x) << 24) & 0xff0000000000ULL) | \
121 (((uint64_t)(x) << 8) & 0xff00000000ULL) | \
122 (((uint64_t)(x) >> 8) & 0xff000000ULL) | \
123 (((uint64_t)(x) >> 24) & 0xff0000ULL) | \
124 (((uint64_t)(x) >> 40) & 0xff00ULL) | \
125 ((uint64_t)(x) >> 56))
130 // endian change for 48bit
132 #define BSWAP_48(x) \
133 (((uint64_t)(x) << 40) & 0x0000ff0000000000ULL) | \
134 (((uint64_t)(x) << 24) & 0x000000ff00000000ULL) | \
135 (((uint64_t)(x) << 8) & 0x00000000ff000000ULL) | \
136 (((uint64_t)(x) >> 8) & 0x000000000ff0000ULL) | \
137 (((uint64_t)(x) >> 24) & 0x00000000000ff00ULL) | \
138 (((uint64_t)(x) >> 40) & 0x0000000000000ffULL)
141 // endian change for 32bit
144 #define BSWAP_32(x) __builtin_bswap32(x)
149 #define BSWAP_32(x) _byteswap_ulong(x)
153 # define BSWAP_32(x) \
154 ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \
155 (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24))
160 // convert 2 bytes to U16 in little endian
162 # define BYTES2UINT16(x) (((x)[1] << 8) | ((x)[0]))
164 // convert 4 bytes to U32 in little endian
166 # define BYTES2UINT32(x) (((x)[3] << 24) | ((x)[2] << 16) | ((x)[1] << 8) | ((x)[0]))
169 // convert 4 bytes to U32 in big endian
170 #ifndef BYTES2UINT32_BE
171 # define BYTES2UINT32_BE(x) (((x)[0] << 24) | ((x)[1] << 16) | ((x)[2] << 8) | ((x)[3]))
180 # define NIBBLE_HIGH(b) ( ((b) & 0xF0) >> 4 )
184 # define NIBBLE_LOW(b) ((b) & 0x0F )
188 # define CRUMB(b,p) ((((b) & (0x3 << (p)) ) >> (p) ) & 0xF)
192 # define SWAP_NIBBLE(b) ( (NIBBLE_LOW(b)<< 4) | NIBBLE_HIGH(b))
195 // Binary Encoded Digit
197 # define BCD2DEC(bcd) HornerScheme((bcd), 0x10, 10)
201 # define DEC2BCD(dec) HornerScheme((dec), 10, 0x10)
204 // bit stream operations
205 #define TEST_BIT(data, i) (*((data) + ((i) / 8)) >> (7 - ((i) % 8))) & 1
206 #define SET_BIT(data, i) *((data) + ((i) / 8)) |= (1 << (7 - ((i) % 8)))
207 #define CLEAR_BIT(data, i) *((data) + ((i) / 8)) &= ~(1 << (7 - ((i) % 8)))
208 #define FLIP_BIT(data, i) *((data) + ((i) / 8)) ^= (1 << (7 - ((i) % 8)))
210 // time for decompressing and loading the image to the FPGA
211 #define FPGA_LOAD_WAIT_TIME (1500)
214 // from client/deps/tinycbor/compilersupport_p.h
217 # define likely(x) __builtin_expect(!!(x), 1)
220 # define unlikely(x) __builtin_expect(!!(x), 0)
223 # define likely(x) (x)
224 # define unlikely(x) (x)