include: fix mix of spaces & tabs

This commit is contained in:
Philippe Teuwen 2019-03-09 18:41:30 +01:00
commit 9502b54aa0
9 changed files with 791 additions and 791 deletions

File diff suppressed because it is too large Load diff

View file

@ -71,44 +71,44 @@ extern uint32_t FLASHMEM_SPIBAUDRATE;
#ifndef FLASH_MEM_ID_LEN
# define FLASH_MEM_ID_LEN 8
# define FLASH_MEM_ID_LEN 8
#endif
#ifndef FLASH_MEM_SIGNATURE_LEN
# define FLASH_MEM_SIGNATURE_LEN 128
# define FLASH_MEM_SIGNATURE_LEN 128
#endif
#ifndef FLASH_MEM_SIGNATURE_OFFSET
# define FLASH_MEM_SIGNATURE_OFFSET (FLASH_MEM_MAX_SIZE - FLASH_MEM_SIGNATURE_LEN)
# define FLASH_MEM_SIGNATURE_OFFSET (FLASH_MEM_MAX_SIZE - FLASH_MEM_SIGNATURE_LEN)
#endif
#ifdef WITH_FLASH
#ifndef T55XX_CONFIG_LEN
# define T55XX_CONFIG_LEN sizeof( t55xx_config )
#endif
#ifndef T55XX_CONFIG_LEN
# define T55XX_CONFIG_LEN sizeof( t55xx_config )
#endif
#ifndef T55XX_CONFIG_OFFSET
# define T55XX_CONFIG_OFFSET (FLASH_MEM_MAX_4K_SECTOR - 0x2000)
#endif
#ifndef T55XX_CONFIG_OFFSET
# define T55XX_CONFIG_OFFSET (FLASH_MEM_MAX_4K_SECTOR - 0x2000)
#endif
#ifndef DEFAULT_T55XX_KEYS_OFFSET
# define DEFAULT_T55XX_KEYS_OFFSET (FLASH_MEM_MAX_4K_SECTOR - 0x3000)
#endif
#ifndef DEFAULT_T55XX_KEYS_OFFSET
# define DEFAULT_T55XX_KEYS_OFFSET (FLASH_MEM_MAX_4K_SECTOR - 0x3000)
#endif
#ifndef DEFAULT_MF_KEYS_OFFSET
# define DEFAULT_MF_KEYS_OFFSET (FLASH_MEM_MAX_4K_SECTOR - 0x4000)
#endif
#ifndef DEFAULT_MF_KEYS_OFFSET
# define DEFAULT_MF_KEYS_OFFSET (FLASH_MEM_MAX_4K_SECTOR - 0x4000)
#endif
#ifndef DEFAULT_ICLASS_KEYS_OFFSET
# define DEFAULT_ICLASS_KEYS_OFFSET (FLASH_MEM_MAX_4K_SECTOR - 0x5000)
#endif
#ifndef DEFAULT_ICLASS_KEYS_OFFSET
# define DEFAULT_ICLASS_KEYS_OFFSET (FLASH_MEM_MAX_4K_SECTOR - 0x5000)
#endif
#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];
uint8_t magic[4];
uint8_t flashid[FLASH_MEM_ID_LEN];
uint8_t signature[FLASH_MEM_SIGNATURE_LEN];
} __attribute__((__packed__)) rdv40_validation_t;

View file

@ -9,45 +9,45 @@
#ifndef __CONFIG_GPIO_H
#define __CONFIG_GPIO_H
#define GPIO_LED_A AT91C_PIO_PA0
#define GPIO_PA1 AT91C_PIO_PA1
#define GPIO_LED_D AT91C_PIO_PA2
#define GPIO_NVDD_ON AT91C_PIO_PA3
#define GPIO_FPGA_NINIT AT91C_PIO_PA4
#define GPIO_PA5 AT91C_PIO_PA5
#define GPIO_PCK0 AT91C_PA6_PCK0
#define GPIO_LRST AT91C_PIO_PA7
#define GPIO_LED_B AT91C_PIO_PA8
#define GPIO_LED_C AT91C_PIO_PA9
#define GPIO_LED_A AT91C_PIO_PA0
#define GPIO_PA1 AT91C_PIO_PA1
#define GPIO_LED_D AT91C_PIO_PA2
#define GPIO_NVDD_ON AT91C_PIO_PA3
#define GPIO_FPGA_NINIT AT91C_PIO_PA4
#define GPIO_PA5 AT91C_PIO_PA5
#define GPIO_PCK0 AT91C_PA6_PCK0
#define GPIO_LRST AT91C_PIO_PA7
#define GPIO_LED_B AT91C_PIO_PA8
#define GPIO_LED_C AT91C_PIO_PA9
// defines for flash mem, or rdv40 ?
// flashmem hooked on PA10
//#define GPIO_NCS2 AT91C_PIO_PA1
#define GPIO_NCS2 AT91C_PA10_NPCS2
#define GPIO_NCS0 AT91C_PA11_NPCS0
//#define GPIO_NCS2 AT91C_PIO_PA1
#define GPIO_NCS2 AT91C_PA10_NPCS2
#define GPIO_NCS0 AT91C_PA11_NPCS0
#define GPIO_MISO AT91C_PA12_MISO
#define GPIO_MOSI AT91C_PA13_MOSI
#define GPIO_SPCK AT91C_PA14_SPCK
#define GPIO_SSC_FRAME AT91C_PA15_TF
#define GPIO_SSC_CLK AT91C_PA16_TK
#define GPIO_SSC_DOUT AT91C_PA17_TD
#define GPIO_SSC_DIN AT91C_PA18_RD
#define GPIO_MUXSEL_HIPKD AT91C_PIO_PA19
#define GPIO_MUXSEL_LOPKD AT91C_PIO_PA20
#define GPIO_MISO AT91C_PA12_MISO
#define GPIO_MOSI AT91C_PA13_MOSI
#define GPIO_SPCK AT91C_PA14_SPCK
#define GPIO_SSC_FRAME AT91C_PA15_TF
#define GPIO_SSC_CLK AT91C_PA16_TK
#define GPIO_SSC_DOUT AT91C_PA17_TD
#define GPIO_SSC_DIN AT91C_PA18_RD
#define GPIO_MUXSEL_HIPKD AT91C_PIO_PA19
#define GPIO_MUXSEL_LOPKD AT91C_PIO_PA20
// RDV40 has no HIRAW/LORAW, its used for FPC
#define GPIO_MUXSEL_HIRAW AT91C_PIO_PA21
#define GPIO_MUXSEL_LORAW AT91C_PIO_PA22
#define GPIO_MUXSEL_HIRAW AT91C_PIO_PA21
#define GPIO_MUXSEL_LORAW AT91C_PIO_PA22
#define GPIO_BUTTON AT91C_PIO_PA23
#define GPIO_USB_PU AT91C_PIO_PA24
#define GPIO_RELAY AT91C_PIO_PA25
#define GPIO_FPGA_ON AT91C_PIO_PA26
#define GPIO_FPGA_DONE AT91C_PIO_PA27
#define GPIO_FPGA_NPROGRAM AT91C_PIO_PA28
#define GPIO_FPGA_CCLK AT91C_PIO_PA29
#define GPIO_FPGA_DIN AT91C_PIO_PA30
#define GPIO_FPGA_DOUT AT91C_PIO_PA31
#define GPIO_BUTTON AT91C_PIO_PA23
#define GPIO_USB_PU AT91C_PIO_PA24
#define GPIO_RELAY AT91C_PIO_PA25
#define GPIO_FPGA_ON AT91C_PIO_PA26
#define GPIO_FPGA_DONE AT91C_PIO_PA27
#define GPIO_FPGA_NPROGRAM AT91C_PIO_PA28
#define GPIO_FPGA_CCLK AT91C_PIO_PA29
#define GPIO_FPGA_DIN AT91C_PIO_PA30
#define GPIO_FPGA_DOUT AT91C_PIO_PA31
#endif

View file

@ -20,36 +20,36 @@
#endif
typedef enum {
RHTSF_CHALLENGE = 01,
RHTSF_KEY = 02,
WHTSF_CHALLENGE = 03,
WHTSF_KEY = 04,
RHT2F_PASSWORD = 21,
RHT2F_AUTHENTICATE = 22,
RHT2F_CRYPTO = 23,
WHT2F_CRYPTO = 24,
RHT2F_TEST_AUTH_ATTEMPTS = 25,
RHT2F_UID_ONLY = 26,
RHTSF_CHALLENGE = 01,
RHTSF_KEY = 02,
WHTSF_CHALLENGE = 03,
WHTSF_KEY = 04,
RHT2F_PASSWORD = 21,
RHT2F_AUTHENTICATE = 22,
RHT2F_CRYPTO = 23,
WHT2F_CRYPTO = 24,
RHT2F_TEST_AUTH_ATTEMPTS = 25,
RHT2F_UID_ONLY = 26,
} hitag_function;
typedef struct {
byte_t password[4];
byte_t password[4];
} PACKED rht2d_password;
typedef struct {
byte_t NrAr[8];
byte_t data[4];
byte_t NrAr[8];
byte_t data[4];
} PACKED rht2d_authenticate;
typedef struct {
byte_t key[6];
byte_t data[4];
byte_t key[6];
byte_t data[4];
} PACKED rht2d_crypto;
typedef union {
rht2d_password pwd;
rht2d_authenticate auth;
rht2d_crypto crypto;
rht2d_password pwd;
rht2d_authenticate auth;
rht2d_crypto crypto;
} hitag_data;
#endif

View file

@ -18,57 +18,57 @@
//protocol-state
typedef enum PROTO_STATE {
HT_READY=0,
HT_INIT,
HT_AUTHENTICATE,
HT_SELECTED,
HT_QUIET,
HT_TTF,
HT_FAIL} PSTATE;
HT_READY=0,
HT_INIT,
HT_AUTHENTICATE,
HT_SELECTED,
HT_QUIET,
HT_TTF,
HT_FAIL} PSTATE;
//tag-state
typedef enum TAG_STATE {
HT_NO_OP=0,
HT_READING_PAGE,
HT_WRITING_PAGE_ACK,
HT_WRITING_PAGE_DATA,
HT_WRITING_BLOCK_DATA} TSATE;
HT_NO_OP=0,
HT_READING_PAGE,
HT_WRITING_PAGE_ACK,
HT_WRITING_PAGE_DATA,
HT_WRITING_BLOCK_DATA} TSATE;
//number of start-of-frame bits
typedef enum SOF_TYPE {
HT_STANDARD=0,
HT_ADVANCED,
HT_FAST_ADVANCED,
HT_ONE,
HT_NO_BITS} stype;
HT_STANDARD=0,
HT_ADVANCED,
HT_FAST_ADVANCED,
HT_ONE,
HT_NO_BITS} stype;
struct hitagS_tag {
PSTATE pstate; //protocol-state
TSATE tstate; //tag-state
uint32_t uid;
uint32_t pages[16][4];
uint64_t key;
byte_t pwdl0, pwdl1, pwdh0;
//con0
int max_page;
stype mode;
//con1
bool auth; //0=Plain 1=Auth
bool TTFC; //Transponder Talks first coding. 0=Manchester 1=Biphase
int TTFDR; //data rate in TTF Mode
int TTFM; //the number of pages that are sent to the RWD
bool LCON; //0=con1/2 read write 1=con1 read only and con2 OTP
bool LKP; //0=page2/3 read write 1=page2/3 read only in Plain mode and no access in authenticate mode
//con2
//0=read write 1=read only
bool LCK7; //page4/5
bool LCK6; //page6/7
bool LCK5; //page8-11
bool LCK4; //page12-15
bool LCK3; //page16-23
bool LCK2; //page24-31
bool LCK1; //page32-47
bool LCK0; //page48-63
PSTATE pstate; //protocol-state
TSATE tstate; //tag-state
uint32_t uid;
uint32_t pages[16][4];
uint64_t key;
byte_t pwdl0, pwdl1, pwdh0;
//con0
int max_page;
stype mode;
//con1
bool auth; //0=Plain 1=Auth
bool TTFC; //Transponder Talks first coding. 0=Manchester 1=Biphase
int TTFDR; //data rate in TTF Mode
int TTFM; //the number of pages that are sent to the RWD
bool LCON; //0=con1/2 read write 1=con1 read only and con2 OTP
bool LKP; //0=page2/3 read write 1=page2/3 read only in Plain mode and no access in authenticate mode
//con2
//0=read write 1=read only
bool LCK7; //page4/5
bool LCK6; //page6/7
bool LCK5; //page8-11
bool LCK4; //page12-15
bool LCK3; //page16-23
bool LCK2; //page24-31
bool LCK1; //page32-47
bool LCK0; //page48-63
} ;
#endif

View file

@ -17,11 +17,11 @@
// LEGIC
//-----------------------------------------------------------------------------
typedef struct {
uint8_t uid[4];
uint32_t tagtype;
uint8_t cmdsize;
uint8_t addrsize;
uint16_t cardsize;
uint8_t uid[4];
uint32_t tagtype;
uint8_t cmdsize;
uint8_t addrsize;
uint16_t cardsize;
} legic_card_select_t;
#endif // _LEGIC_H_

View file

@ -13,111 +13,111 @@
#include "common.h"
#define MF_KEY_A 0
#define MF_KEY_B 1
#define MF_KEY_A 0
#define MF_KEY_B 1
#define MF_MAD1_SECTOR 0x00
#define MF_MAD2_SECTOR 0x10
#define MF_MAD1_SECTOR 0x00
#define MF_MAD2_SECTOR 0x10
//-----------------------------------------------------------------------------
// ISO 14443A
//-----------------------------------------------------------------------------
typedef struct {
byte_t uid[10];
byte_t uidlen;
byte_t atqa[2];
byte_t sak;
byte_t ats_len;
byte_t ats[256];
byte_t uid[10];
byte_t uidlen;
byte_t atqa[2];
byte_t sak;
byte_t ats_len;
byte_t ats[256];
} __attribute__((__packed__)) iso14a_card_select_t;
typedef enum ISO14A_COMMAND {
ISO14A_CONNECT = (1 << 0),
ISO14A_NO_DISCONNECT = (1 << 1),
ISO14A_APDU = (1 << 2),
ISO14A_RAW = (1 << 3),
ISO14A_REQUEST_TRIGGER = (1 << 4),
ISO14A_APPEND_CRC = (1 << 5),
ISO14A_SET_TIMEOUT = (1 << 6),
ISO14A_NO_SELECT = (1 << 7),
ISO14A_TOPAZMODE = (1 << 8),
ISO14A_NO_RATS = (1 << 9),
ISO14A_SEND_CHAINING = (1 << 10)
ISO14A_CONNECT = (1 << 0),
ISO14A_NO_DISCONNECT = (1 << 1),
ISO14A_APDU = (1 << 2),
ISO14A_RAW = (1 << 3),
ISO14A_REQUEST_TRIGGER = (1 << 4),
ISO14A_APPEND_CRC = (1 << 5),
ISO14A_SET_TIMEOUT = (1 << 6),
ISO14A_NO_SELECT = (1 << 7),
ISO14A_TOPAZMODE = (1 << 8),
ISO14A_NO_RATS = (1 << 9),
ISO14A_SEND_CHAINING = (1 << 10)
} iso14a_command_t;
typedef struct {
uint8_t* response;
size_t response_n;
uint8_t* modulation;
size_t modulation_n;
uint32_t ProxToAirDuration;
uint8_t* response;
size_t response_n;
uint8_t* modulation;
size_t modulation_n;
uint32_t ProxToAirDuration;
} tag_response_info_t;
//-----------------------------------------------------------------------------
// ISO 14443B
//-----------------------------------------------------------------------------
typedef struct {
byte_t uid[10];
byte_t uidlen;
byte_t atqb[7];
byte_t chipid;
byte_t cid;
byte_t uid[10];
byte_t uidlen;
byte_t atqb[7];
byte_t chipid;
byte_t cid;
} __attribute__((__packed__)) iso14b_card_select_t;
typedef enum ISO14B_COMMAND {
ISO14B_CONNECT = (1 << 0),
ISO14B_DISCONNECT = (1 << 1),
ISO14B_APDU = (1 << 2),
ISO14B_RAW = (1 << 3),
ISO14B_REQUEST_TRIGGER = (1 << 4),
ISO14B_APPEND_CRC = (1 << 5),
ISO14B_SELECT_STD = (1 << 6),
ISO14B_SELECT_SR = (1 << 7)
ISO14B_CONNECT = (1 << 0),
ISO14B_DISCONNECT = (1 << 1),
ISO14B_APDU = (1 << 2),
ISO14B_RAW = (1 << 3),
ISO14B_REQUEST_TRIGGER = (1 << 4),
ISO14B_APPEND_CRC = (1 << 5),
ISO14B_SELECT_STD = (1 << 6),
ISO14B_SELECT_SR = (1 << 7)
} iso14b_command_t;
typedef enum ISO15_COMMAND {
ISO15_CONNECT = (1 << 0),
ISO15_NO_DISCONNECT = (1 << 1),
ISO15_RAW = (1 << 2),
ISO15_APPEND_CRC = (1 << 3),
ISO15_HIGH_SPEED = (1 << 4),
ISO15_READ_RESPONSE = (1 << 5)
ISO15_CONNECT = (1 << 0),
ISO15_NO_DISCONNECT = (1 << 1),
ISO15_RAW = (1 << 2),
ISO15_APPEND_CRC = (1 << 3),
ISO15_HIGH_SPEED = (1 << 4),
ISO15_READ_RESPONSE = (1 << 5)
} iso15_command_t;
//-----------------------------------------------------------------------------
// "hf 14a sim x", "hf mf sim x" attacks
//-----------------------------------------------------------------------------
typedef struct {
uint32_t cuid;
uint32_t nonce;
uint32_t ar;
uint32_t nr;
uint32_t at;
uint32_t nonce2;
uint32_t ar2;
uint32_t nr2;
uint8_t sector;
uint8_t keytype;
enum {
EMPTY,
FIRST,
SECOND,
} state;
uint32_t cuid;
uint32_t nonce;
uint32_t ar;
uint32_t nr;
uint32_t at;
uint32_t nonce2;
uint32_t ar2;
uint32_t nr2;
uint8_t sector;
uint8_t keytype;
enum {
EMPTY,
FIRST,
SECOND,
} state;
} nonces_t;
//-----------------------------------------------------------------------------
// ISO 7618 Smart Card
//-----------------------------------------------------------------------------
typedef struct {
uint8_t atr_len;
uint8_t atr[30];
uint8_t atr_len;
uint8_t atr[30];
} __attribute__((__packed__)) smart_card_atr_t;
typedef enum SMARTCARD_COMMAND {
SC_CONNECT = (1 << 0),
SC_NO_DISCONNECT = (1 << 1),
SC_RAW = (1 << 2),
SC_SELECT = (1 << 3),
SC_RAW_T0 = (1 << 4),
SC_CONNECT = (1 << 0),
SC_NO_DISCONNECT = (1 << 1),
SC_RAW = (1 << 2),
SC_SELECT = (1 << 3),
SC_RAW_T0 = (1 << 4),
} smartcard_command_t;
//-----------------------------------------------------------------------------
@ -128,34 +128,34 @@ typedef enum SMARTCARD_COMMAND {
// mc1 mc2 u1 u2 u3 u4 u5 u6
// PMm = Product manufacturer
// icCode =
// ic1 = ROM
// ic2 = IC
// ic1 = ROM
// ic2 = IC
// maximum response time =
// B3(request service)
// B4(request response)
// B5(authenticate)
// B6(read)
// B7(write)
// B8()
// B3(request service)
// B4(request response)
// B5(authenticate)
// B6(read)
// B7(write)
// B8()
// ServiceCode 2bytes (access-rights)
// FileSystem = 1 Block = 16 bytes
typedef struct {
uint8_t IDm[8];
uint8_t code[2];
uint8_t uid[6];
uint8_t PMm[8];
uint8_t iccode[2];
uint8_t mrt[6];
uint8_t servicecode[2];
uint8_t IDm[8];
uint8_t code[2];
uint8_t uid[6];
uint8_t PMm[8];
uint8_t iccode[2];
uint8_t mrt[6];
uint8_t servicecode[2];
} __attribute__((__packed__)) felica_card_select_t;
typedef enum FELICA_COMMAND {
FELICA_CONNECT = (1 << 0),
FELICA_NO_DISCONNECT = (1 << 1),
FELICA_RAW = (1 << 3),
FELICA_APPEND_CRC = (1 << 5),
FELICA_NO_SELECT = (1 << 6),
FELICA_CONNECT = (1 << 0),
FELICA_NO_DISCONNECT = (1 << 1),
FELICA_RAW = (1 << 3),
FELICA_APPEND_CRC = (1 << 5),
FELICA_NO_SELECT = (1 << 6),
} felica_command_t;
#endif // _MIFARE_H_

View file

@ -16,56 +16,56 @@
#include "config_gpio.h"
#include "usb_cmd.h"
#define WDT_HIT() AT91C_BASE_WDTC->WDTC_WDCR = 0xa5000001
#define WDT_HIT() AT91C_BASE_WDTC->WDTC_WDCR = 0xa5000001
#define PWM_CH_MODE_PRESCALER(x) ((x) << 0)
#define PWM_CHANNEL(x) (1 << (x))
#define PWM_CH_MODE_PRESCALER(x) ((x) << 0)
#define PWM_CHANNEL(x) (1 << (x))
#define ADC_CHAN_LF 4
#define ADC_CHAN_HF 5
#define ADC_CHAN_HF_RDV40 7
#define ADC_MODE_PRESCALE(x) ((x) << 8)
#define ADC_MODE_STARTUP_TIME(x) ((x) << 16)
#define ADC_MODE_SAMPLE_HOLD_TIME(x) ((x) << 24)
#define ADC_CHANNEL(x) (1 << (x))
#define ADC_END_OF_CONVERSION(x) (1 << (x))
#define ADC_CHAN_LF 4
#define ADC_CHAN_HF 5
#define ADC_CHAN_HF_RDV40 7
#define ADC_MODE_PRESCALE(x) ((x) << 8)
#define ADC_MODE_STARTUP_TIME(x) ((x) << 16)
#define ADC_MODE_SAMPLE_HOLD_TIME(x) ((x) << 24)
#define ADC_CHANNEL(x) (1 << (x))
#define ADC_END_OF_CONVERSION(x) (1 << (x))
#define SSC_CLOCK_MODE_START(x) ((x) << 8)
#define SSC_FRAME_MODE_WORDS_PER_TRANSFER(x) ((x) << 8)
#define SSC_CLOCK_MODE_SELECT(x) ((x) << 0)
#define SSC_FRAME_MODE_BITS_IN_WORD(x) (((x)-1) << 0)
#define SSC_CLOCK_MODE_START(x) ((x) << 8)
#define SSC_FRAME_MODE_WORDS_PER_TRANSFER(x) ((x) << 8)
#define SSC_CLOCK_MODE_SELECT(x) ((x) << 0)
#define SSC_FRAME_MODE_BITS_IN_WORD(x) (((x)-1) << 0)
#define MC_FLASH_COMMAND_KEY ((0x5a) << 24)
#define MC_FLASH_MODE_FLASH_WAIT_STATES(x) ((x) << 8)
#define MC_FLASH_MODE_MASTER_CLK_IN_MHZ(x) (((x)+((x)/2)) << 16)
#define MC_FLASH_COMMAND_PAGEN(x) ((x) << 8)
#define MC_FLASH_COMMAND_KEY ((0x5a) << 24)
#define MC_FLASH_MODE_FLASH_WAIT_STATES(x) ((x) << 8)
#define MC_FLASH_MODE_MASTER_CLK_IN_MHZ(x) (((x)+((x)/2)) << 16)
#define MC_FLASH_COMMAND_PAGEN(x) ((x) << 8)
#define RST_CONTROL_KEY (0xa5 << 24)
#define RST_CONTROL_KEY (0xa5 << 24)
#define PMC_MAIN_OSC_STARTUP_DELAY(x) ((x) << 8)
#define PMC_PLL_DIVISOR(x) (x)
#define PMC_PLL_MULTIPLIER(x) (((x)-1) << 16)
#define PMC_PLL_COUNT_BEFORE_LOCK(x) (((x) & 0x3F) << 8) // 6bit register 0011 1111
#define PMC_PLL_FREQUENCY_RANGE(x) (((x) & 0x3) << 14) // 2bit register
#define PMC_PLL_USB_DIVISOR(x) ((x) << 28)
#define PMC_MAIN_OSC_STARTUP_DELAY(x) ((x) << 8)
#define PMC_PLL_DIVISOR(x) (x)
#define PMC_PLL_MULTIPLIER(x) (((x)-1) << 16)
#define PMC_PLL_COUNT_BEFORE_LOCK(x) (((x) & 0x3F) << 8) // 6bit register 0011 1111
#define PMC_PLL_FREQUENCY_RANGE(x) (((x) & 0x3) << 14) // 2bit register
#define PMC_PLL_USB_DIVISOR(x) ((x) << 28)
#define UDP_INTERRUPT_ENDPOINT(x) (1 << (x))
#define UDP_CSR_BYTES_RECEIVED(x) (((x) >> 16) & 0x7ff)
#define UDP_INTERRUPT_ENDPOINT(x) (1 << (x))
#define UDP_CSR_BYTES_RECEIVED(x) (((x) >> 16) & 0x7ff)
//**************************************************************
#define LOW(x) AT91C_BASE_PIOA->PIO_CODR |= (x)
#define HIGH(x) AT91C_BASE_PIOA->PIO_SODR |= (x)
#define LOW(x) AT91C_BASE_PIOA->PIO_CODR |= (x)
#define HIGH(x) AT91C_BASE_PIOA->PIO_SODR |= (x)
#define GETBIT(x) (AT91C_BASE_PIOA->PIO_ODSR & (x)) ? 1:0
#define GETBIT(x) (AT91C_BASE_PIOA->PIO_ODSR & (x)) ? 1:0
#define SETBIT(x, y) (y) ? (HIGH(x)):(LOW(x))
#define INVBIT(x) SETBIT((x), !(GETBIT(x)))
#define INVBIT(x) SETBIT((x), !(GETBIT(x)))
// Setup for SPI current modes
#define SPI_FPGA_MODE 0
#define SPI_LCD_MODE 1
#define SPI_MEM_MODE 2
#define SPI_FPGA_MODE 0
#define SPI_LCD_MODE 1
#define SPI_MEM_MODE 2
#ifndef COTAG_BITS
#define COTAG_BITS 264
@ -73,25 +73,25 @@
//#define PACKED __attribute__((__packed__))
#define LED_A_ON() HIGH(GPIO_LED_A)
#define LED_A_OFF() LOW(GPIO_LED_A)
#define LED_A_INV() INVBIT(GPIO_LED_A)
#define LED_B_ON() HIGH(GPIO_LED_B)
#define LED_B_OFF() LOW(GPIO_LED_B)
#define LED_B_INV() INVBIT(GPIO_LED_B)
#define LED_C_ON() HIGH(GPIO_LED_C)
#define LED_C_OFF() LOW(GPIO_LED_C)
#define LED_C_INV() INVBIT(GPIO_LED_C)
#define LED_D_ON() HIGH(GPIO_LED_D)
#define LED_D_OFF() LOW(GPIO_LED_D)
#define LED_D_INV() INVBIT(GPIO_LED_D)
#define LED_A_ON() HIGH(GPIO_LED_A)
#define LED_A_OFF() LOW(GPIO_LED_A)
#define LED_A_INV() INVBIT(GPIO_LED_A)
#define LED_B_ON() HIGH(GPIO_LED_B)
#define LED_B_OFF() LOW(GPIO_LED_B)
#define LED_B_INV() INVBIT(GPIO_LED_B)
#define LED_C_ON() HIGH(GPIO_LED_C)
#define LED_C_OFF() LOW(GPIO_LED_C)
#define LED_C_INV() INVBIT(GPIO_LED_C)
#define LED_D_ON() HIGH(GPIO_LED_D)
#define LED_D_OFF() LOW(GPIO_LED_D)
#define LED_D_INV() INVBIT(GPIO_LED_D)
// SPI
#define SCK_LOW LOW(GPIO_SPCK)
#define SCK_HIGH HIGH(GPIO_SPCK)
#define MOSI_HIGH HIGH(GPIO_MOSI)
#define MOSI_LOW LOW(GPIO_MOSI)
#define MISO_VALUE (AT91C_BASE_PIOA->PIO_PDSR & GPIO_MISO)
#define SCK_LOW LOW(GPIO_SPCK)
#define SCK_HIGH HIGH(GPIO_SPCK)
#define MOSI_HIGH HIGH(GPIO_MOSI)
#define MOSI_LOW LOW(GPIO_MOSI)
#define MISO_VALUE (AT91C_BASE_PIOA->PIO_PDSR & GPIO_MISO)
// fpga
#define NCS_0_LOW LOW(GPIO_NCS0)
@ -101,35 +101,35 @@
#define NCS_1_LOW LOW(GPIO_NCS2)
#define NCS_1_HIGH HIGH(GPIO_NCS2)
#define RELAY_ON() HIGH(GPIO_RELAY)
#define RELAY_OFF() LOW(GPIO_RELAY)
#define BUTTON_PRESS() !((AT91C_BASE_PIOA->PIO_PDSR & GPIO_BUTTON) == GPIO_BUTTON)
#define RELAY_ON() HIGH(GPIO_RELAY)
#define RELAY_OFF() LOW(GPIO_RELAY)
#define BUTTON_PRESS() !((AT91C_BASE_PIOA->PIO_PDSR & GPIO_BUTTON) == GPIO_BUTTON)
//NVDD goes LOW when USB is attached.
#define USB_ATTACHED() !((AT91C_BASE_PIOA->PIO_PDSR & GPIO_NVDD_ON) == GPIO_NVDD_ON)
#define USB_ATTACHED() !((AT91C_BASE_PIOA->PIO_PDSR & GPIO_NVDD_ON) == GPIO_NVDD_ON)
#define VERSION_INFORMATION_MAGIC 0x56334d50
struct version_information {
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 */
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 */
} __attribute__((packed));
#define COMMON_AREA_MAGIC 0x43334d50
#define COMMON_AREA_COMMAND_NONE 0
#define COMMON_AREA_COMMAND_ENTER_FLASH_MODE 1
struct common_area {
int magic; /* Magic sequence, to distinguish against random uninitialized memory */
char version; /* Must be 1 */
char command;
struct {
unsigned int bootrom_present:1; /* Set when a bootrom that is capable of parsing the common area is present */
unsigned int osimage_present:1; /* Set when a osimage that is capable of parsing the common area is present */
} __attribute__((packed)) flags;
int arg1, arg2;
int magic; /* Magic sequence, to distinguish against random uninitialized memory */
char version; /* Must be 1 */
char command;
struct {
unsigned int bootrom_present:1; /* Set when a bootrom that is capable of parsing the common area is present */
unsigned int osimage_present:1; /* Set when a osimage that is capable of parsing the common area is present */
} __attribute__((packed)) flags;
int arg1, arg2;
} __attribute__((packed));
#endif

View file

@ -36,19 +36,19 @@ typedef struct {
} PACKED UsbCommand;
// A struct used to send sample-configs over USB
typedef struct{
uint8_t decimation;
uint8_t bits_per_sample;
bool averaging;
int divisor;
int trigger_threshold;
uint8_t decimation;
uint8_t bits_per_sample;
bool averaging;
int divisor;
int trigger_threshold;
} sample_config;
typedef struct{
uint16_t start_gap;
uint16_t write_gap;
uint16_t write_0;
uint16_t write_1;
uint16_t read_gap;
uint16_t start_gap;
uint16_t write_gap;
uint16_t write_0;
uint16_t write_1;
uint16_t read_gap;
} t55xx_config;
// For the bootloader
@ -69,35 +69,35 @@ typedef struct{
#define CMD_BUFF_CLEAR 0x0105
#define CMD_READ_MEM 0x0106
#define CMD_VERSION 0x0107
#define CMD_STATUS 0x0108
#define CMD_PING 0x0109
#define CMD_STATUS 0x0108
#define CMD_PING 0x0109
#define CMD_DOWNLOAD_EML_BIGBUF 0x0110
#define CMD_DOWNLOADED_EML_BIGBUF 0x0111
#define CMD_DOWNLOAD_EML_BIGBUF 0x0110
#define CMD_DOWNLOADED_EML_BIGBUF 0x0111
// RDV40, Flash memory operations
#define CMD_FLASHMEM_READ 0x0120
#define CMD_FLASHMEM_WRITE 0x0121
#define CMD_FLASHMEM_WIPE 0x0122
#define CMD_FLASHMEM_DOWNLOAD 0x0123
#define CMD_FLASHMEM_DOWNLOADED 0x0124
#define CMD_FLASHMEM_INFO 0x0125
#define CMD_FLASHMEM_READ 0x0120
#define CMD_FLASHMEM_WRITE 0x0121
#define CMD_FLASHMEM_WIPE 0x0122
#define CMD_FLASHMEM_DOWNLOAD 0x0123
#define CMD_FLASHMEM_DOWNLOADED 0x0124
#define CMD_FLASHMEM_INFO 0x0125
#define CMD_FLASHMEM_SET_SPIBAUDRATE 0x0126
// RDV40, Smart card operations
#define CMD_SMART_RAW 0x0140
#define CMD_SMART_UPGRADE 0x0141
#define CMD_SMART_UPLOAD 0x0142
#define CMD_SMART_ATR 0x0143
#define CMD_SMART_SETBAUD 0x0144
#define CMD_SMART_SETCLOCK 0x0145
#define CMD_SMART_RAW 0x0140
#define CMD_SMART_UPGRADE 0x0141
#define CMD_SMART_UPLOAD 0x0142
#define CMD_SMART_ATR 0x0143
#define CMD_SMART_SETBAUD 0x0144
#define CMD_SMART_SETCLOCK 0x0145
// RDV40, FPC serial
#define CMD_FPC_SEND 0x0160
#define CMD_FPC_READ 0x0161
#define CMD_FPC_SEND 0x0160
#define CMD_FPC_READ 0x0161
// For low-frequency tags
#define CMD_READ_TI_TYPE 0x0202
@ -136,9 +136,9 @@ typedef struct{
#define CMD_PSK_SIM_TAG 0x0220
#define CMD_AWID_DEMOD_FSK 0x0221
#define CMD_VIKING_CLONE_TAG 0x0222
#define CMD_T55XX_WAKEUP 0x0224
#define CMD_COTAG 0x0225
#define CMD_SET_LF_T55XX_CONFIG 0x0226
#define CMD_T55XX_WAKEUP 0x0224
#define CMD_COTAG 0x0225
#define CMD_SET_LF_T55XX_CONFIG 0x0226
#define CMD_T55XX_CHKPWDS 0x0230
@ -162,13 +162,13 @@ typedef struct{
#define CMD_READER_HITAG 0x0372
// For HitagS
#define CMD_TEST_HITAGS_TRACES 0x0367
#define CMD_SIMULATE_HITAG_S 0x0368
#define CMD_READ_HITAG_S 0x0373
#define CMD_WR_HITAG_S 0x0375
#define CMD_EMU_HITAG_S 0x0376
#define CMD_TEST_HITAGS_TRACES 0x0367
#define CMD_SIMULATE_HITAG_S 0x0368
#define CMD_READ_HITAG_S 0x0373
#define CMD_WR_HITAG_S 0x0375
#define CMD_EMU_HITAG_S 0x0376
#define CMD_ANTIFUZZ_ISO_14443a 0x0380
#define CMD_ANTIFUZZ_ISO_14443a 0x0380
#define CMD_SIMULATE_TAG_ISO_14443B 0x0381
#define CMD_SNOOP_ISO_14443B 0x0382
@ -185,9 +185,9 @@ typedef struct{
#define CMD_EPA_PACE_COLLECT_NONCE 0x038A
#define CMD_EPA_PACE_REPLAY 0x038B
#define CMD_LEGIC_INFO 0x03BC
#define CMD_LEGIC_ESET 0x03BD
#define CMD_LEGIC_EGET 0x03BE
#define CMD_LEGIC_INFO 0x03BC
#define CMD_LEGIC_ESET 0x03BD
#define CMD_LEGIC_EGET 0x03BE
#define CMD_ICLASS_READCHECK 0x038F
#define CMD_ICLASS_CLONE 0x0390
@ -236,19 +236,19 @@ typedef struct{
#define CMD_READER_MIFARE 0x0611
#define CMD_MIFARE_NESTED 0x0612
#define CMD_MIFARE_ACQUIRE_ENCRYPTED_NONCES 0x0613
#define CMD_MIFARE_ACQUIRE_NONCES 0x0614
#define CMD_MIFARE_ACQUIRE_NONCES 0x0614
#define CMD_MIFARE_READBL 0x0620
#define CMD_MIFAREU_READBL 0x0720
#define CMD_MIFARE_READSC 0x0621
#define CMD_MIFAREU_READCARD 0x0721
#define CMD_MIFARE_WRITEBL 0x0622
#define CMD_MIFAREU_WRITEBL 0x0722
#define CMD_MIFAREU_WRITEBL_COMPAT 0x0723
#define CMD_MIFAREU_WRITEBL 0x0722
#define CMD_MIFAREU_WRITEBL_COMPAT 0x0723
#define CMD_MIFARE_CHKKEYS 0x0623
#define CMD_MIFARE_SETMOD 0x0624
#define CMD_MIFARE_CHKKEYS_FAST 0x0625
#define CMD_MIFARE_CHKKEYS_FAST 0x0625
#define CMD_MIFARE_SNIFFER 0x0630
//ultralightC
@ -265,8 +265,8 @@ typedef struct{
#define CMD_MIFARE_DESFIRE_INFO 0x072d
#define CMD_MIFARE_DESFIRE 0x072e
#define CMD_MIFARE_COLLECT_NONCES 0x072f
#define CMD_MIFARE_NACK_DETECT 0x0730
#define CMD_MIFARE_COLLECT_NONCES 0x072f
#define CMD_MIFARE_NACK_DETECT 0x0730
#define CMD_HF_SNIFFER 0x0800
@ -284,46 +284,46 @@ typedef struct{
#define CMD_UNKNOWN 0xFFFF
//Mifare simulation flags
#define FLAG_INTERACTIVE 0x01
#define FLAG_4B_UID_IN_DATA 0x02
#define FLAG_7B_UID_IN_DATA 0x04
#define FLAG_10B_UID_IN_DATA 0x08
#define FLAG_UID_IN_EMUL 0x10
#define FLAG_NR_AR_ATTACK 0x20
//#define FLAG_RANDOM_NONCE 0x40
#define FLAG_INTERACTIVE 0x01
#define FLAG_4B_UID_IN_DATA 0x02
#define FLAG_7B_UID_IN_DATA 0x04
#define FLAG_10B_UID_IN_DATA 0x08
#define FLAG_UID_IN_EMUL 0x10
#define FLAG_NR_AR_ATTACK 0x20
//#define FLAG_RANDOM_NONCE 0x40
//Iclass reader flags
#define FLAG_ICLASS_READER_ONLY_ONCE 0x01
#define FLAG_ICLASS_READER_CC 0x02
#define FLAG_ICLASS_READER_CSN 0x04
#define FLAG_ICLASS_READER_CONF 0x08
#define FLAG_ICLASS_READER_AIA 0x10
#define FLAG_ICLASS_READER_ONE_TRY 0x20
#define FLAG_ICLASS_READER_CEDITKEY 0x40
#define FLAG_ICLASS_READER_ONLY_ONCE 0x01
#define FLAG_ICLASS_READER_CC 0x02
#define FLAG_ICLASS_READER_CSN 0x04
#define FLAG_ICLASS_READER_CONF 0x08
#define FLAG_ICLASS_READER_AIA 0x10
#define FLAG_ICLASS_READER_ONE_TRY 0x20
#define FLAG_ICLASS_READER_CEDITKEY 0x40
// Dbprintf flags
#define FLAG_RAWPRINT 0x0111
#define FLAG_NOOPT 0x0000
#define FLAG_NOLOG 0x0001
#define FLAG_NONEWLINE 0x0010
#define FLAG_NOPROMPT 0x0100
#define FLAG_RAWPRINT 0x0111
#define FLAG_NOOPT 0x0000
#define FLAG_NOLOG 0x0001
#define FLAG_NONEWLINE 0x0010
#define FLAG_NOPROMPT 0x0100
// CMD_DEVICE_INFO response packet has flags in arg[0], flag definitions:
/* Whether a bootloader that understands the common_area is present */
#define DEVICE_INFO_FLAG_BOOTROM_PRESENT (1<<0)
#define DEVICE_INFO_FLAG_BOOTROM_PRESENT (1<<0)
/* Whether a osimage that understands the common_area is present */
#define DEVICE_INFO_FLAG_OSIMAGE_PRESENT (1<<1)
#define DEVICE_INFO_FLAG_OSIMAGE_PRESENT (1<<1)
/* Set if the bootloader is currently executing */
#define DEVICE_INFO_FLAG_CURRENT_MODE_BOOTROM (1<<2)
#define DEVICE_INFO_FLAG_CURRENT_MODE_BOOTROM (1<<2)
/* Set if the OS is currently executing */
#define DEVICE_INFO_FLAG_CURRENT_MODE_OS (1<<3)
#define DEVICE_INFO_FLAG_CURRENT_MODE_OS (1<<3)
/* Set if this device understands the extend start flash command */
#define DEVICE_INFO_FLAG_UNDERSTANDS_START_FLASH (1<<4)
#define DEVICE_INFO_FLAG_UNDERSTANDS_START_FLASH (1<<4)
/* CMD_START_FLASH may have three arguments: start of area to flash,
end of area to flash, optional magic.