mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-20 21:33:47 -07:00
added PACKED attribute for structures and reorganize include folder
This commit is contained in:
parent
19469fc676
commit
20d13d5509
18 changed files with 204 additions and 183 deletions
125
include/common.h
125
include/common.h
|
@ -19,9 +19,20 @@ extern "C" {
|
|||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <at91sam7s512.h>
|
||||
|
||||
typedef unsigned char byte_t;
|
||||
|
||||
#ifdef _MSC_VER
|
||||
typedef DWORD uint32_t;
|
||||
typedef BYTE uint8_t;
|
||||
#define PACKED
|
||||
// stuff
|
||||
#else
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#define PACKED __attribute__((packed))
|
||||
#endif
|
||||
|
||||
// debug
|
||||
#define DBG_NONE 0 // no messages
|
||||
#define DBG_ERROR 1 // errors only
|
||||
|
@ -30,9 +41,6 @@ typedef unsigned char byte_t;
|
|||
#define DBG_EXTENDED 4 // errors + info + debug + breaking debug messages
|
||||
extern int DBGLEVEL;
|
||||
|
||||
// Flashmem spi baudrate
|
||||
extern uint32_t FLASHMEM_SPIBAUDRATE;
|
||||
|
||||
// reader voltage field detector
|
||||
#define MF_MINFIELDV 4000
|
||||
|
||||
|
@ -49,74 +57,87 @@ extern uint32_t FLASHMEM_SPIBAUDRATE;
|
|||
#endif
|
||||
#define RAMFUNC __attribute((long_call, section(".ramfunc")))
|
||||
|
||||
// RDV40 Section
|
||||
// 256kb divided into 4k sectors.
|
||||
//
|
||||
// 0x3F000 - 1 4kb sector = signature
|
||||
// 0x3E000 - 1 4kb sector = settings
|
||||
// 0x3D000 - 1 4kb sector = default T55XX keys dictionary
|
||||
// 0x3B000 - 1 4kb sector = default ICLASS keys dictionary
|
||||
// 0x39000 - 2 4kb sectors = default MFC keys dictionary
|
||||
//
|
||||
#ifndef FLASH_MEM_BLOCK_SIZE
|
||||
# define FLASH_MEM_BLOCK_SIZE 256
|
||||
#ifndef ROTR
|
||||
# define ROTR(x,n) (((uintmax_t)(x) >> (n)) | ((uintmax_t)(x) << ((sizeof(x) * 8) - (n))))
|
||||
#endif
|
||||
|
||||
#ifndef FLASH_MEM_MAX_SIZE
|
||||
# define FLASH_MEM_MAX_SIZE 0x40000 // (262144)
|
||||
#ifndef ROTL
|
||||
# define ROTL(x,n) (((uintmax_t)(x) << (n)) | ((uintmax_t)(x) >> ((sizeof(x) * 8) - (n))))
|
||||
#endif
|
||||
|
||||
#ifndef FLASH_MEM_MAX_4K_SECTOR
|
||||
# define FLASH_MEM_MAX_4K_SECTOR 0x3F000
|
||||
// endian change for 64bit
|
||||
#ifdef __GNUC__
|
||||
#ifndef BSWAP_64
|
||||
#define BSWAP_64(x) __builtin_bswap64(x)
|
||||
#endif
|
||||
#else
|
||||
#ifdef _MSC_VER
|
||||
#ifndef BSWAP_64
|
||||
#define BSWAP_64(x) _byteswap_uint64(x)
|
||||
#endif
|
||||
#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))
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef FLASH_MEM_ID_LEN
|
||||
# define FLASH_MEM_ID_LEN 8
|
||||
// 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
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef FLASH_MEM_SIGNATURE_LEN
|
||||
# define FLASH_MEM_SIGNATURE_LEN 128
|
||||
#define EVEN 0
|
||||
#define ODD 1
|
||||
|
||||
// Nibble logic
|
||||
#ifndef NIBBLE_HIGH
|
||||
# define NIBBLE_HIGH(b) ( (b & 0xF0) >> 4 )
|
||||
#endif
|
||||
|
||||
#ifndef FLASH_MEM_SIGNATURE_OFFSET
|
||||
// -1 for historical compatibility with already released Proxmark3 RDV4.0 devices
|
||||
# define FLASH_MEM_SIGNATURE_OFFSET (FLASH_MEM_MAX_SIZE - FLASH_MEM_SIGNATURE_LEN - 1)
|
||||
#ifndef NIBBLE_LOW
|
||||
# define NIBBLE_LOW(b) ( b & 0x0F )
|
||||
#endif
|
||||
|
||||
#ifndef T55XX_CONFIG_LEN
|
||||
# define T55XX_CONFIG_LEN sizeof( t55xx_config )
|
||||
#ifndef CRUMB
|
||||
# define CRUMB(b,p) (((b & (0x3 << p) ) >> p ) & 0xF)
|
||||
#endif
|
||||
|
||||
#ifndef T55XX_CONFIG_OFFSET
|
||||
# define T55XX_CONFIG_OFFSET (FLASH_MEM_MAX_4K_SECTOR - 0x2000)
|
||||
#ifndef SWAP_NIBBLE
|
||||
# define SWAP_NIBBLE(b) ( (NIBBLE_LOW(b)<< 4) | NIBBLE_HIGH(b))
|
||||
#endif
|
||||
|
||||
// Reserved space for T55XX PWD = 4 kb
|
||||
#ifndef DEFAULT_T55XX_KEYS_OFFSET
|
||||
# define DEFAULT_T55XX_KEYS_OFFSET (FLASH_MEM_MAX_4K_SECTOR - 0x3000)
|
||||
// Binary Encoded Digit
|
||||
#ifndef BCD2DEC
|
||||
# define BCD2DEC(bcd) HornerScheme(bcd, 0x10, 10)
|
||||
#endif
|
||||
|
||||
// Reserved space for iClass keys = 4 kb
|
||||
#ifndef DEFAULT_ICLASS_KEYS_OFFSET
|
||||
# define DEFAULT_ICLASS_KEYS_OFFSET (FLASH_MEM_MAX_4K_SECTOR - 0x4000)
|
||||
#ifndef DEC2BCD
|
||||
# define DEC2BCD(dec) HornerScheme(dec, 10, 0x10)
|
||||
#endif
|
||||
|
||||
// Reserved space for MIFARE Keys = 8 kb
|
||||
#ifndef DEFAULT_MF_KEYS_OFFSET
|
||||
# define DEFAULT_MF_KEYS_OFFSET (FLASH_MEM_MAX_4K_SECTOR - 0x6000)
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
// RDV40, validation structure to help identifying that client/firmware is talking with RDV40
|
||||
typedef struct {
|
||||
uint8_t magic[4];
|
||||
uint8_t flashid[FLASH_MEM_ID_LEN];
|
||||
uint8_t signature[FLASH_MEM_SIGNATURE_LEN];
|
||||
} __attribute__((__packed__)) rdv40_validation_t;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue