2010-07-13 21:39:30 +08:00
|
|
|
//-----------------------------------------------------------------------------
|
2022-01-07 08:58:03 +08:00
|
|
|
// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details.
|
2010-07-13 21:39:30 +08:00
|
|
|
//
|
2022-01-07 08:58:03 +08:00
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
2018-05-06 15:26:06 +08:00
|
|
|
//
|
2022-01-07 08:58:03 +08:00
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// See LICENSE.txt for the text of the license.
|
2010-07-13 21:39:30 +08:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Interlib Definitions
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#ifndef __COMMON_H
|
|
|
|
#define __COMMON_H
|
|
|
|
|
2011-06-07 22:30:07 +08:00
|
|
|
#include <stdint.h>
|
2019-08-08 22:57:33 +08:00
|
|
|
#include <stddef.h>
|
2012-12-05 07:39:18 +08:00
|
|
|
#include <stdbool.h>
|
2019-07-16 19:50:38 +08:00
|
|
|
|
2023-01-01 05:30:07 +08:00
|
|
|
#ifdef _WIN32
|
2023-01-09 04:56:38 +08:00
|
|
|
#define ABOVE "../"
|
|
|
|
#define PATHSEP "/"
|
2023-01-01 05:30:07 +08:00
|
|
|
#else
|
|
|
|
#define ABOVE "../"
|
2019-08-31 03:36:10 +08:00
|
|
|
#define PATHSEP "/"
|
2023-01-01 05:30:07 +08:00
|
|
|
#endif
|
|
|
|
|
2019-08-31 03:36:10 +08:00
|
|
|
// PM3 share path relative to executable when installed
|
|
|
|
#define PM3_SHARE_RELPATH ".." PATHSEP "share" PATHSEP "proxmark3" PATHSEP
|
|
|
|
|
|
|
|
// PM3_USER_DIRECTORY will be expanded from $HOME, e.g. ~/.proxmark3/
|
|
|
|
#define PM3_USER_DIRECTORY PATHSEP ".proxmark3" PATHSEP
|
2019-08-23 01:36:20 +08:00
|
|
|
|
2019-08-24 04:07:45 +08:00
|
|
|
// PM3 subdirectories:
|
2020-05-26 17:30:37 +08:00
|
|
|
#define PYTHON_SCRIPTS_SUBDIR "pyscripts" PATHSEP
|
2019-09-05 05:29:03 +08:00
|
|
|
#define CMD_SCRIPTS_SUBDIR "cmdscripts" PATHSEP
|
2019-08-31 03:36:10 +08:00
|
|
|
#define DICTIONARIES_SUBDIR "dictionaries" PATHSEP
|
|
|
|
#define LUA_LIBRARIES_SUBDIR "lualibs" PATHSEP
|
|
|
|
#define LUA_SCRIPTS_SUBDIR "luascripts" PATHSEP
|
|
|
|
#define RESOURCES_SUBDIR "resources" PATHSEP
|
|
|
|
#define TRACES_SUBDIR "traces" PATHSEP
|
2020-05-24 07:20:43 +08:00
|
|
|
#define LOGS_SUBDIR "logs" PATHSEP
|
2019-09-10 01:55:27 +08:00
|
|
|
#define FIRMWARES_SUBDIR "firmware" PATHSEP
|
2020-05-24 07:03:23 +08:00
|
|
|
#define BOOTROM_SUBDIR "bootrom" PATHSEP "obj" PATHSEP
|
|
|
|
#define FULLIMAGE_SUBDIR "armsrc" PATHSEP "obj" PATHSEP
|
2019-08-24 04:07:45 +08:00
|
|
|
|
2019-07-16 19:50:38 +08:00
|
|
|
#define PACKED __attribute__((packed))
|
|
|
|
|
2020-05-20 21:53:47 +08:00
|
|
|
#define VERSION_INFORMATION_MAGIC 0x56334d50 // "PM3V"
|
2021-08-22 02:11:14 +08:00
|
|
|
struct version_information_t {
|
2020-05-20 21:53:47 +08:00
|
|
|
int magic; /* Magic sequence to identify this as a correct version information structure. Must be VERSION_INFORMATION_MAGIC */
|
|
|
|
char versionversion; /* Must be 1 */
|
|
|
|
char present; /* 1 if the version information could be created at compile time, otherwise 0 and the remaining fields (except for magic) are empty */
|
|
|
|
char clean; /* 1: Tree was clean, no local changes. 0: Tree was unclean. 2: Couldn't be determined */
|
|
|
|
char gitversion[50]; /* String with the git revision */
|
|
|
|
char buildtime[30]; /* string with the build time */
|
2023-01-09 04:56:38 +08:00
|
|
|
char armsrc[10]; /* sha256sum of sha256sum of armsrc && common_arm files */
|
2020-05-20 21:53:47 +08:00
|
|
|
} PACKED;
|
|
|
|
|
2017-01-25 07:33:03 +08:00
|
|
|
// debug
|
2019-06-06 16:05:09 +08:00
|
|
|
#define DBG_NONE 0 // no messages
|
|
|
|
#define DBG_ERROR 1 // errors only
|
|
|
|
#define DBG_INFO 2 // errors + info messages
|
|
|
|
#define DBG_DEBUG 3 // errors + info + debug messages
|
|
|
|
#define DBG_EXTENDED 4 // errors + info + debug + breaking debug messages
|
2021-08-22 05:02:27 +08:00
|
|
|
extern int g_dbglevel;
|
2017-01-25 07:33:03 +08:00
|
|
|
|
2021-03-08 06:43:53 +08:00
|
|
|
// tear-off
|
2021-08-22 05:02:27 +08:00
|
|
|
extern uint16_t g_tearoff_delay_us;
|
|
|
|
extern bool g_tearoff_enabled;
|
2021-03-08 06:43:53 +08:00
|
|
|
|
2017-01-25 07:33:03 +08:00
|
|
|
// reader voltage field detector
|
|
|
|
#define MF_MINFIELDV 4000
|
|
|
|
|
2013-03-14 23:03:04 +08:00
|
|
|
#ifndef MIN
|
|
|
|
# define MIN(a, b) (((a) < (b)) ? (a) : (b))
|
|
|
|
#endif
|
2016-03-13 14:16:42 +08:00
|
|
|
|
2013-03-14 23:03:04 +08:00
|
|
|
#ifndef MAX
|
|
|
|
# define MAX(a, b) (((a) > (b)) ? (a) : (b))
|
|
|
|
#endif
|
2013-02-28 23:11:52 +08:00
|
|
|
|
2016-03-13 14:16:42 +08:00
|
|
|
#ifndef ABS
|
|
|
|
# define ABS(a) ( ((a)<0) ? -(a) : (a) )
|
|
|
|
#endif
|
2020-06-08 01:46:41 +08:00
|
|
|
|
|
|
|
|
2020-06-08 17:07:45 +08:00
|
|
|
//#define RAMFUNC __attribute((long_call, section(".ramfunc")))
|
2020-06-08 01:46:41 +08:00
|
|
|
#define RAMFUNC __attribute((long_call, section(".ramfunc"))) __attribute__((target("arm")))
|
2017-03-02 04:51:23 +08:00
|
|
|
|
2019-07-16 19:50:38 +08:00
|
|
|
#ifndef ROTR
|
|
|
|
# define ROTR(x,n) (((uintmax_t)(x) >> (n)) | ((uintmax_t)(x) << ((sizeof(x) * 8) - (n))))
|
2018-05-06 15:26:06 +08:00
|
|
|
#endif
|
|
|
|
|
2020-03-13 19:09:49 +08:00
|
|
|
#ifndef PM3_ROTL
|
|
|
|
# define PM3_ROTL(x,n) (((uintmax_t)(x) << (n)) | ((uintmax_t)(x) >> ((sizeof(x) * 8) - (n))))
|
2018-05-06 15:26:06 +08:00
|
|
|
#endif
|
|
|
|
|
2019-07-16 19:50:38 +08:00
|
|
|
// endian change for 64bit
|
|
|
|
#ifdef __GNUC__
|
|
|
|
#ifndef BSWAP_64
|
|
|
|
#define BSWAP_64(x) __builtin_bswap64(x)
|
2018-09-23 11:29:55 +08:00
|
|
|
#endif
|
2019-07-16 19:50:38 +08:00
|
|
|
#else
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
#ifndef BSWAP_64
|
|
|
|
#define BSWAP_64(x) _byteswap_uint64(x)
|
2018-05-06 15:26:06 +08:00
|
|
|
#endif
|
2019-07-16 19:50:38 +08:00
|
|
|
#else
|
|
|
|
#ifndef BSWAP_64
|
|
|
|
#define BSWAP_64(x) \
|
|
|
|
(((uint64_t)(x) << 56) | \
|
|
|
|
(((uint64_t)(x) << 40) & 0xff000000000000ULL) | \
|
|
|
|
(((uint64_t)(x) << 24) & 0xff0000000000ULL) | \
|
|
|
|
(((uint64_t)(x) << 8) & 0xff00000000ULL) | \
|
|
|
|
(((uint64_t)(x) >> 8) & 0xff000000ULL) | \
|
|
|
|
(((uint64_t)(x) >> 24) & 0xff0000ULL) | \
|
|
|
|
(((uint64_t)(x) >> 40) & 0xff00ULL) | \
|
|
|
|
((uint64_t)(x) >> 56))
|
2018-05-06 15:26:06 +08:00
|
|
|
#endif
|
|
|
|
#endif
|
2019-03-10 07:00:59 +08:00
|
|
|
#endif
|
2018-09-23 11:29:55 +08:00
|
|
|
|
2019-07-16 19:50:38 +08:00
|
|
|
// endian change for 32bit
|
|
|
|
#ifdef __GNUC__
|
|
|
|
#ifndef BSWAP_32
|
|
|
|
#define BSWAP_32(x) __builtin_bswap32(x)
|
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
#ifndef BSWAP_32
|
|
|
|
#define BSWAP_32(x) _byteswap_ulong(x)
|
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
#ifndef BSWAP_32
|
|
|
|
# define BSWAP_32(x) \
|
|
|
|
((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \
|
|
|
|
(((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24))
|
|
|
|
#endif
|
2019-03-10 07:00:59 +08:00
|
|
|
#endif
|
|
|
|
#endif
|
2019-03-09 15:59:13 +08:00
|
|
|
|
2021-06-22 13:49:17 +08:00
|
|
|
// convert 2 bytes to U16 in little endian
|
2021-05-17 05:03:13 +08:00
|
|
|
#ifndef BYTES2UINT16
|
|
|
|
# define BYTES2UINT16(x) ((x[1] << 8) | (x[0]))
|
|
|
|
#endif
|
2021-06-22 13:49:17 +08:00
|
|
|
// convert 4 bytes to U32 in little endian
|
2021-05-17 05:03:13 +08:00
|
|
|
#ifndef BYTES2UINT32
|
|
|
|
# define BYTES2UINT32(x) ((x[3] << 24) | (x[2] << 16) | (x[1] << 8) | (x[0]))
|
|
|
|
#endif
|
|
|
|
|
2021-06-22 13:49:17 +08:00
|
|
|
// convert 4 bytes to U32 in big endian
|
|
|
|
#ifndef BYTES2UINT32_BE
|
|
|
|
# define BYTES2UINT32_BE(x) ((x[0] << 24) | (x[1] << 16) | (x[2] << 8) | (x[3]))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2019-07-16 19:50:38 +08:00
|
|
|
#define EVEN 0
|
|
|
|
#define ODD 1
|
|
|
|
|
|
|
|
// Nibble logic
|
|
|
|
#ifndef NIBBLE_HIGH
|
2022-02-19 07:15:34 +08:00
|
|
|
# define NIBBLE_HIGH(b) ( ((b) & 0xF0) >> 4 )
|
2019-03-10 07:00:59 +08:00
|
|
|
#endif
|
2019-03-09 15:59:13 +08:00
|
|
|
|
2019-07-16 19:50:38 +08:00
|
|
|
#ifndef NIBBLE_LOW
|
2022-02-19 07:15:34 +08:00
|
|
|
# define NIBBLE_LOW(b) ((b) & 0x0F )
|
2019-03-10 07:00:59 +08:00
|
|
|
#endif
|
2018-05-06 15:26:06 +08:00
|
|
|
|
2019-07-16 19:50:38 +08:00
|
|
|
#ifndef CRUMB
|
|
|
|
# define CRUMB(b,p) (((b & (0x3 << p) ) >> p ) & 0xF)
|
|
|
|
#endif
|
2019-05-24 06:50:24 +08:00
|
|
|
|
2019-07-16 19:50:38 +08:00
|
|
|
#ifndef SWAP_NIBBLE
|
|
|
|
# define SWAP_NIBBLE(b) ( (NIBBLE_LOW(b)<< 4) | NIBBLE_HIGH(b))
|
|
|
|
#endif
|
2019-05-24 06:50:24 +08:00
|
|
|
|
2019-07-16 19:50:38 +08:00
|
|
|
// Binary Encoded Digit
|
|
|
|
#ifndef BCD2DEC
|
|
|
|
# define BCD2DEC(bcd) HornerScheme(bcd, 0x10, 10)
|
|
|
|
#endif
|
2018-05-06 15:26:06 +08:00
|
|
|
|
2019-07-16 19:50:38 +08:00
|
|
|
#ifndef DEC2BCD
|
|
|
|
# define DEC2BCD(dec) HornerScheme(dec, 10, 0x10)
|
|
|
|
#endif
|
2017-03-02 04:51:23 +08:00
|
|
|
|
2019-12-24 18:30:46 +08:00
|
|
|
// bit stream operations
|
|
|
|
#define TEST_BIT(data, i) (*(data + (i / 8)) >> (7 - (i % 8))) & 1
|
|
|
|
#define SET_BIT(data, i) *(data + (i / 8)) |= (1 << (7 - (i % 8)))
|
|
|
|
#define CLEAR_BIT(data, i) *(data + (i / 8)) &= ~(1 << (7 - (i % 8)))
|
|
|
|
#define FLIP_BIT(data, i) *(data + (i / 8)) ^= (1 << (7 - (i % 8)))
|
|
|
|
|
2023-11-14 10:34:50 +08:00
|
|
|
// time for decompressing and loading the image to the FPGA
|
|
|
|
#define FPGA_LOAD_WAIT_TIME (1500)
|
|
|
|
|
2023-11-14 01:40:31 +08:00
|
|
|
// GCC extension
|
|
|
|
// from client/deps/tinycbor/compilersupport_p.h
|
|
|
|
#ifdef __GNUC__
|
|
|
|
#ifndef likely
|
|
|
|
# define likely(x) __builtin_expect(!!(x), 1)
|
|
|
|
#endif
|
|
|
|
#ifndef unlikely
|
|
|
|
# define unlikely(x) __builtin_expect(!!(x), 0)
|
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
# define likely(x) (x)
|
|
|
|
# define unlikely(x) (x)
|
|
|
|
#endif
|
|
|
|
|
2019-03-12 07:12:26 +08:00
|
|
|
#endif
|