#include "proxmark3.h"
#include "apps.h"
+#include "util.h"
+
#include "legicrf.h"
+
#ifdef WITH_LCD
-#include "fonts.h"
-#include "LCD.h"
+# include "fonts.h"
+# include "LCD.h"
#endif
#define va_list __builtin_va_list
// is the order in which they go out on the wire.
//=============================================================================
-BYTE ToSend[512];
+uint8_t ToSend[512];
int ToSendMax;
static int ToSendBit;
struct common_area common_area __attribute__((section(".commonarea")));
}
memcpy(c.d.asBytes, str, c.arg[0]);
- UsbSendPacket((BYTE *)&c, sizeof(c));
+ UsbSendPacket((uint8_t *)&c, sizeof(c));
// TODO fix USB so stupid things like this aren't req'd
SpinDelay(50);
}
c.arg[1] = x2;
c.arg[2] = x3;
- UsbSendPacket((BYTE *)&c, sizeof(c));
+ UsbSendPacket((uint8_t *)&c, sizeof(c));
// XXX
SpinDelay(50);
}
//-----------------------------------------------------------------------------
static int ReadAdc(int ch)
{
- DWORD d;
+ uint32_t d;
AT91C_BASE_ADC->ADC_CR = AT91C_ADC_SWRST;
AT91C_BASE_ADC->ADC_MR =
void MeasureAntennaTuning(void)
{
- BYTE *dest = (BYTE *)BigBuf;
+ uint8_t *dest = (uint8_t *)BigBuf;
int i, ptr = 0, adcval = 0, peak = 0, peakv = 0, peakf = 0;;
int vLf125 = 0, vLf134 = 0, vHf = 0; // in mV
c.arg[0] = (vLf125 << 0) | (vLf134 << 16);
c.arg[1] = vHf;
c.arg[2] = peakf | (peakv << 16);
- UsbSendPacket((BYTE *)&c, sizeof(c));
+ UsbSendPacket((uint8_t *)&c, sizeof(c));
}
void MeasureAntennaTuningHf(void)
void SimulateTagHfListen(void)
{
- BYTE *dest = (BYTE *)BigBuf;
+ uint8_t *dest = (uint8_t *)BigBuf;
int n = sizeof(BigBuf);
- BYTE v = 0;
+ uint8_t v = 0;
int i;
int p = 0;
AT91C_BASE_SSC->SSC_THR = 0xff;
}
if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
- BYTE r = (BYTE)AT91C_BASE_SSC->SSC_RHR;
+ uint8_t r = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
v <<= 1;
if(r & 1) {
void ReadMem(int addr)
{
- const BYTE *data = ((BYTE *)addr);
+ const uint8_t *data = ((uint8_t *)addr);
Dbprintf("%x: %02x %02x %02x %02x %02x %02x %02x %02x",
addr, data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7]);
}
}
-void UsbPacketReceived(BYTE *packet, int len)
+void UsbPacketReceived(uint8_t *packet, int len)
{
UsbCommand *c = (UsbCommand *)packet;
UsbCommand ack;
#ifdef WITH_LF
case CMD_ACQUIRE_RAW_ADC_SAMPLES_125K:
AcquireRawAdcSamples125k(c->arg[0]);
- UsbSendPacket((BYTE*)&ack, sizeof(ack));
+ UsbSendPacket((uint8_t*)&ack, sizeof(ack));
break;
#endif
n.cmd = CMD_DOWNLOADED_RAW_BITS_TI_TYPE;
}
n.arg[0] = c->arg[0];
- memcpy(n.d.asDwords, BigBuf+c->arg[0], 12*sizeof(DWORD));
- UsbSendPacket((BYTE *)&n, sizeof(n));
+ memcpy(n.d.asDwords, BigBuf+c->arg[0], 12*sizeof(uint32_t));
+ UsbSendPacket((uint8_t *)&n, sizeof(n));
break;
}
case CMD_DOWNLOADED_SIM_SAMPLES_125K: {
- BYTE *b = (BYTE *)BigBuf;
+ uint8_t *b = (uint8_t *)BigBuf;
memcpy(b+c->arg[0], c->d.asBytes, 48);
//Dbprintf("copied 48 bytes to %i",b+c->arg[0]);
- UsbSendPacket((BYTE*)&ack, sizeof(ack));
+ UsbSendPacket((uint8_t*)&ack, sizeof(ack));
break;
}
c.cmd = CMD_DEVICE_INFO;
c.arg[0] = DEVICE_INFO_FLAG_OSIMAGE_PRESENT | DEVICE_INFO_FLAG_CURRENT_MODE_OS;
if(common_area.flags.bootrom_present) c.arg[0] |= DEVICE_INFO_FLAG_BOOTROM_PRESENT;
- UsbSendPacket((BYTE*)&c, sizeof(c));
+ UsbSendPacket((uint8_t*)&c, sizeof(c));
}
break;
default:
#ifndef __APPS_H
#define __APPS_H
-#include "stdint.h"
-#include "stddef.h"
+#include <stdint.h>
+#include <stddef.h>
typedef unsigned char byte_t;
// The large multi-purpose buffer, typically used to hold A/D samples,
// maybe processed in some way.
-DWORD BigBuf[8000];
+uint32_t BigBuf[8000];
/// appmain.h
void ReadMem(int addr);
void ToSendStuffBit(int b);
void ToSendReset(void);
void ListenReaderField(int limit);
-void AcquireRawAdcSamples125k(BOOL at134khz);
+void AcquireRawAdcSamples125k(int at134khz);
void DoAcquisition125k(void);
extern int ToSendMax;
-extern BYTE ToSend[];
-extern DWORD BigBuf[];
+extern uint8_t ToSend[];
+extern uint32_t BigBuf[];
/// fpga.h
-void FpgaSendCommand(WORD cmd, WORD v);
-void FpgaWriteConfWord(BYTE v);
+void FpgaSendCommand(uint16_t cmd, uint16_t v);
+void FpgaWriteConfWord(uint8_t v);
void FpgaDownloadAndGo(void);
void FpgaGatherVersion(char *dst, int len);
void FpgaSetupSsc(void);
void SetupSpi(int mode);
-void FpgaSetupSscDma(BYTE *buf, int len);
-void SetAdcMuxFor(DWORD whichGpio);
+void FpgaSetupSscDma(uint8_t *buf, int len);
+void SetAdcMuxFor(uint32_t whichGpio);
// Definitions for the FPGA commands.
#define FPGA_CMD_SET_CONFREG (1<<12)
#define FPGA_HF_ISO14443A_READER_MOD (4<<0)
/// lfops.h
-void AcquireRawAdcSamples125k(BOOL at134khz);
-void ModThenAcquireRawAdcSamples125k(int delay_off,int period_0,int period_1,BYTE *command);
+void AcquireRawAdcSamples125k(int at134khz);
+void ModThenAcquireRawAdcSamples125k(int delay_off,int period_0,int period_1,uint8_t *command);
void ReadTItag(void);
-void WriteTItag(DWORD idhi, DWORD idlo, WORD crc);
+void WriteTItag(uint32_t idhi, uint32_t idlo, uint16_t crc);
void AcquireTiType(void);
void AcquireRawBitsTI(void);
void SimulateTagLowFrequency(int period, int gap, int ledcontrol);
/// iso14443.h
void SimulateIso14443Tag(void);
-void AcquireRawAdcSamplesIso14443(DWORD parameter);
-void ReadSRI512Iso14443(DWORD parameter);
-void ReadSRIX4KIso14443(DWORD parameter);
-void ReadSTMemoryIso14443(DWORD parameter,DWORD dwLast);
+void AcquireRawAdcSamplesIso14443(uint32_t parameter);
+void ReadSRI512Iso14443(uint32_t parameter);
+void ReadSRIX4KIso14443(uint32_t parameter);
+void ReadSTMemoryIso14443(uint32_t parameter,uint32_t dwLast);
void SnoopIso14443(void);
/// iso14443a.h
void SnoopIso14443a(void);
void SimulateIso14443aTag(int tagType, int TagUid); // ## simulate iso14443a tag
-void ReaderIso14443a(DWORD parameter);
-void ReaderMifare(DWORD parameter);
+void ReaderIso14443a(uint32_t parameter);
+void ReaderMifare(uint32_t parameter);
/// iso15693.h
void AcquireRawAdcSamplesIso15693(void);
-void ReaderIso15693(DWORD parameter); // Simulate an ISO15693 reader - greg
-void SimTagIso15693(DWORD parameter); // simulate an ISO15693 tag - greg
+void ReaderIso15693(uint32_t parameter); // Simulate an ISO15693 reader - greg
+void SimTagIso15693(uint32_t parameter); // simulate an ISO15693 tag - greg
/// util.h
-#define LED_RED 1
-#define LED_ORANGE 2
-#define LED_GREEN 4
-#define LED_RED2 8
-#define BUTTON_HOLD 1
-#define BUTTON_NO_CLICK 0
-#define BUTTON_SINGLE_CLICK -1
-#define BUTTON_DOUBLE_CLICK -2
-#define BUTTON_ERROR -99
-int strlen(char *str);
-void *memcpy(void *dest, const void *src, int len);
-void *memset(void *dest, int c, int len);
-int memcmp(const void *av, const void *bv, int len);
-char *strncat(char *dest, const char *src, unsigned int n);
-void num_to_bytes(uint64_t n, size_t len, byte_t* dest);
-uint64_t bytes_to_num(byte_t* src, size_t len);
-
-void SpinDelay(int ms);
-void SpinDelayUs(int us);
-void LED(int led, int ms);
-void LEDsoff();
-int BUTTON_CLICKED(int ms);
-int BUTTON_HELD(int ms);
-void FormatVersionInformation(char *dst, int len, const char *prefix, void *version_information);
#endif
//-----------------------------------------------------------------------------
#include "proxmark3.h"
#include "apps.h"
+#include "util.h"
//-----------------------------------------------------------------------------
// Set up the Serial Peripheral Interface as master
// ourselves, not to another buffer). The stuff to manipulate those buffers
// is in apps.h, because it should be inlined, for speed.
//-----------------------------------------------------------------------------
-void FpgaSetupSscDma(BYTE *buf, int len)
+void FpgaSetupSscDma(uint8_t *buf, int len)
{
- AT91C_BASE_PDC_SSC->PDC_RPR = (DWORD)buf;
+ AT91C_BASE_PDC_SSC->PDC_RPR = (uint32_t) buf;
AT91C_BASE_PDC_SSC->PDC_RCR = len;
- AT91C_BASE_PDC_SSC->PDC_RNPR = (DWORD)buf;
+ AT91C_BASE_PDC_SSC->PDC_RNPR = (uint32_t) buf;
AT91C_BASE_PDC_SSC->PDC_RNCR = len;
AT91C_BASE_PDC_SSC->PDC_PTCR = AT91C_PDC_RXTEN;
}
}
if(bytereversal) {
- /* This is only supported for DWORD aligned images */
- if( ((int)FpgaImage % sizeof(DWORD)) == 0 ) {
+ /* This is only supported for uint32_t aligned images */
+ if( ((int)FpgaImage % sizeof(uint32_t)) == 0 ) {
i=0;
while(FpgaImageLen-->0)
DownloadFPGA_byte(FpgaImage[(i++)^0x3]);
/* Fallback for the old flash image format: Check for the magic marker 0xFFFFFFFF
* 0xAA995566 at address 0x102000. This is raw bitstream with a size of 336,768 bits
- * = 10,524 DWORDs, stored as DWORDS e.g. little-endian in memory, but each DWORD
+ * = 10,524 uint32_t, stored as uint32_t e.g. little-endian in memory, but each DWORD
* is still to be transmitted in MSBit first order. Set the invert flag to indicate
* that the DownloadFPGA function should invert every 4 byte sequence when doing
* the bytewise download.
*/
- if( *(DWORD*)0x102000 == 0xFFFFFFFF && *(DWORD*)0x102004 == 0xAA995566 )
+ if( *(uint32_t*)0x102000 == 0xFFFFFFFF && *(uint32_t*)0x102004 == 0xAA995566 )
DownloadFPGA((char*)0x102000, 10524*4, 1);
}
// The bit format is: C3 C2 C1 C0 D11 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0
// where C is the 4 bit command and D is the 12 bit data
//-----------------------------------------------------------------------------
-void FpgaSendCommand(WORD cmd, WORD v)
+void FpgaSendCommand(uint16_t cmd, uint16_t v)
{
SetupSpi(SPI_FPGA_MODE);
while ((AT91C_BASE_SPI->SPI_SR & AT91C_SPI_TXEMPTY) == 0); // wait for the transfer to complete
// vs. clone vs. etc.). This is now a special case of FpgaSendCommand() to
// avoid changing this function's occurence everywhere in the source code.
//-----------------------------------------------------------------------------
-void FpgaWriteConfWord(BYTE v)
+void FpgaWriteConfWord(uint8_t v)
{
FpgaSendCommand(FPGA_CMD_SET_CONFREG, v);
}
// closable, but should only close one at a time. Not an FPGA thing, but
// the samples from the ADC always flow through the FPGA.
//-----------------------------------------------------------------------------
-void SetAdcMuxFor(DWORD whichGpio)
+void SetAdcMuxFor(uint32_t whichGpio)
{
AT91C_BASE_PIOA->PIO_OER =
GPIO_MUXSEL_HIPKD |
*/
#include "proxmark3.h"
-#include <stdint.h>
-
#include "apps.h"
+#include "util.h"
+
#include "hitag2.h"
struct hitag2_cipher_state {
//-----------------------------------------------------------------------------
#include "proxmark3.h"
#include "apps.h"
-#include "iso14443crc.h"
+#include "util.h"
+#include "iso14443crc.h"
-//static void GetSamplesFor14443(BOOL weTx, int n);
+//static void GetSamplesFor14443(int weTx, int n);
#define DEMOD_TRACE_SIZE 4096
#define READER_TAG_BUFFER_SIZE 2048
// that here) so that they can be transmitted to the reader. Doesn't transmit
// them yet, just leaves them ready to send in ToSend[].
//-----------------------------------------------------------------------------
-static void CodeIso14443bAsTag(const BYTE *cmd, int len)
+static void CodeIso14443bAsTag(const uint8_t *cmd, int len)
{
int i;
for(i = 0; i < len; i++) {
int j;
- BYTE b = cmd[i];
+ uint8_t b = cmd[i];
// Start bit
ToSendStuffBit(0);
STATE_RECEIVING_DATA,
STATE_ERROR_WAIT
} state;
- WORD shiftReg;
+ uint16_t shiftReg;
int bitCnt;
int byteCnt;
int byteCntMax;
int posCnt;
- BYTE *output;
+ uint8_t *output;
} Uart;
/* Receive & handle a bit coming from the reader.
* Returns: true if we received a EOF
* false if we are still waiting for some more
*/
-static BOOL Handle14443UartBit(int bit)
+static int Handle14443UartBit(int bit)
{
switch(Uart.state) {
case STATE_UNSYNCD:
// Assume that we're called with the SSC (to the FPGA) and ADC path set
// correctly.
//-----------------------------------------------------------------------------
-static BOOL GetIso14443CommandFromReader(BYTE *received, int *len, int maxLen)
+static int GetIso14443CommandFromReader(uint8_t *received, int *len, int maxLen)
{
- BYTE mask;
+ uint8_t mask;
int i, bit;
// Set FPGA mode to "simulated ISO 14443 tag", no modulation (listen
AT91C_BASE_SSC->SSC_THR = 0x00;
}
if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
- BYTE b = (BYTE)AT91C_BASE_SSC->SSC_RHR;
+ uint8_t b = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
mask = 0x80;
for(i = 0; i < 8; i++, mask >>= 1) {
//-----------------------------------------------------------------------------
void SimulateIso14443Tag(void)
{
- static const BYTE cmd1[] = { 0x05, 0x00, 0x08, 0x39, 0x73 };
- static const BYTE response1[] = {
+ static const uint8_t cmd1[] = { 0x05, 0x00, 0x08, 0x39, 0x73 };
+ static const uint8_t response1[] = {
0x50, 0x82, 0x0d, 0xe1, 0x74, 0x20, 0x38, 0x19, 0x22,
0x00, 0x21, 0x85, 0x5e, 0xd7
};
- BYTE *resp;
+ uint8_t *resp;
int respLen;
- BYTE *resp1 = (((BYTE *)BigBuf) + 800);
+ uint8_t *resp1 = (((uint8_t *)BigBuf) + 800);
int resp1Len;
- BYTE *receivedCmd = (BYTE *)BigBuf;
+ uint8_t *receivedCmd = (uint8_t *)BigBuf;
int len;
int i;
cmdsRecvd = 0;
for(;;) {
- BYTE b1, b2;
+ uint8_t b1, b2;
if(!GetIso14443CommandFromReader(receivedCmd, &len, 100)) {
Dbprintf("button pressed, received %d commands", cmdsRecvd);
i = 0;
for(;;) {
if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY)) {
- BYTE b = resp[i];
+ uint8_t b = resp[i];
AT91C_BASE_SSC->SSC_THR = b;
}
}
if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
- volatile BYTE b = (BYTE)AT91C_BASE_SSC->SSC_RHR;
+ volatile uint8_t b = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
(void)b;
}
}
int thisBit;
int metric;
int metricN;
- WORD shiftReg;
- BYTE *output;
+ uint16_t shiftReg;
+ uint8_t *output;
int len;
int sumI;
int sumQ;
* false if we are still waiting for some more
*
*/
-static BOOL Handle14443SamplesDemod(int ci, int cq)
+static int Handle14443SamplesDemod(int ci, int cq)
{
int v;
Demod.bitCount++;
if(Demod.bitCount == 10) {
- WORD s = Demod.shiftReg;
+ uint16_t s = Demod.shiftReg;
if((s & 0x200) && !(s & 0x001)) {
- BYTE b = (s >> 1);
+ uint8_t b = (s >> 1);
Demod.output[Demod.len] = b;
Demod.len++;
Demod.state = DEMOD_AWAITING_START_BIT;
* set to 'FALSE' if we behave like a snooper
* quiet: set to 'TRUE' to disable debug output
*/
-static void GetSamplesFor14443Demod(BOOL weTx, int n, BOOL quiet)
+static void GetSamplesFor14443Demod(int weTx, int n, int quiet)
{
int max = 0;
- BOOL gotFrame = FALSE;
+ int gotFrame = FALSE;
//# define DMA_BUFFER_SIZE 8
- SBYTE *dmaBuf;
+ int8_t *dmaBuf;
int lastRxCounter;
- SBYTE *upTo;
+ int8_t *upTo;
int ci, cq;
// Clear out the state of the "UART" that receives from the tag.
memset(BigBuf, 0x44, 400);
- Demod.output = (BYTE *)BigBuf;
+ Demod.output = (uint8_t *)BigBuf;
Demod.len = 0;
Demod.state = DEMOD_UNSYNCD;
// And the UART that receives from the reader
- Uart.output = (((BYTE *)BigBuf) + 1024);
+ Uart.output = (((uint8_t *)BigBuf) + 1024);
Uart.byteCntMax = 100;
Uart.state = STATE_UNSYNCD;
// Setup for the DMA.
- dmaBuf = (SBYTE *)(BigBuf + 32);
+ dmaBuf = (int8_t *)(BigBuf + 32);
upTo = dmaBuf;
lastRxCounter = DMA_BUFFER_SIZE;
- FpgaSetupSscDma((BYTE *)dmaBuf, DMA_BUFFER_SIZE);
+ FpgaSetupSscDma((uint8_t *)dmaBuf, DMA_BUFFER_SIZE);
// Signal field is ON with the appropriate LED:
if (weTx) LED_D_ON(); else LED_D_OFF();
upTo += 2;
if(upTo - dmaBuf > DMA_BUFFER_SIZE) {
upTo -= DMA_BUFFER_SIZE;
- AT91C_BASE_PDC_SSC->PDC_RNPR = (DWORD)upTo;
+ AT91C_BASE_PDC_SSC->PDC_RNPR = (uint32_t) upTo;
AT91C_BASE_PDC_SSC->PDC_RNCR = DMA_BUFFER_SIZE;
}
lastRxCounter -= 2;
// samples from the FPGA, which we will later do some signal processing on,
// to get the bits.
//-----------------------------------------------------------------------------
-/*static void GetSamplesFor14443(BOOL weTx, int n)
+/*static void GetSamplesFor14443(int weTx, int n)
{
- BYTE *dest = (BYTE *)BigBuf;
+ uint8_t *dest = (uint8_t *)BigBuf;
int c;
FpgaWriteConfWord(
AT91C_BASE_SSC->SSC_THR = 0x43;
}
if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
- SBYTE b;
- b = (SBYTE)AT91C_BASE_SSC->SSC_RHR;
+ int8_t b;
+ b = (int8_t)AT91C_BASE_SSC->SSC_RHR;
- dest[c++] = (BYTE)b;
+ dest[c++] = (uint8_t)b;
if(c >= n) {
break;
c++;
}
if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
- volatile DWORD r = AT91C_BASE_SSC->SSC_RHR;
+ volatile uint32_t r = AT91C_BASE_SSC->SSC_RHR;
(void)r;
}
WDT_HIT();
}
}
if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
- volatile DWORD r = AT91C_BASE_SSC->SSC_RHR;
+ volatile uint32_t r = AT91C_BASE_SSC->SSC_RHR;
(void)r;
}
WDT_HIT();
// Code a layer 2 command (string of octets, including CRC) into ToSend[],
// so that it is ready to transmit to the tag using TransmitFor14443().
//-----------------------------------------------------------------------------
-void CodeIso14443bAsReader(const BYTE *cmd, int len)
+void CodeIso14443bAsReader(const uint8_t *cmd, int len)
{
int i, j;
- BYTE b;
+ uint8_t b;
ToSendReset();
// The command name is misleading, it actually decodes the reponse in HEX
// into the output buffer (read the result using hexsamples, not hisamples)
//-----------------------------------------------------------------------------
-void AcquireRawAdcSamplesIso14443(DWORD parameter)
+void AcquireRawAdcSamplesIso14443(uint32_t parameter)
{
- BYTE cmd1[] = { 0x05, 0x00, 0x08, 0x39, 0x73 };
+ uint8_t cmd1[] = { 0x05, 0x00, 0x08, 0x39, 0x73 };
// Make sure that we start from off, since the tags are stateful;
// confusing things will happen if we don't reset them between reads.
//
// I tried to be systematic and check every answer of the tag, every CRC, etc...
//-----------------------------------------------------------------------------
-void ReadSRI512Iso14443(DWORD parameter)
+void ReadSRI512Iso14443(uint32_t parameter)
{
ReadSTMemoryIso14443(parameter,0x0F);
}
-void ReadSRIX4KIso14443(DWORD parameter)
+void ReadSRIX4KIso14443(uint32_t parameter)
{
ReadSTMemoryIso14443(parameter,0x7F);
}
-void ReadSTMemoryIso14443(DWORD parameter,DWORD dwLast)
+void ReadSTMemoryIso14443(uint32_t parameter,uint32_t dwLast)
{
- BYTE i = 0x00;
+ uint8_t i = 0x00;
// Make sure that we start from off, since the tags are stateful;
// confusing things will happen if we don't reset them between reads.
SpinDelay(200);
// First command: wake up the tag using the INITIATE command
- BYTE cmd1[] = { 0x06, 0x00, 0x97, 0x5b};
+ uint8_t cmd1[] = { 0x06, 0x00, 0x97, 0x5b};
CodeIso14443bAsReader(cmd1, sizeof(cmd1));
TransmitFor14443();
// LED_A_ON();
// We won't start recording the frames that we acquire until we trigger;
// a good trigger condition to get started is probably when we see a
// response from the tag.
- BOOL triggered = FALSE;
+ int triggered = FALSE;
// The command (reader -> tag) that we're working on receiving.
- BYTE *receivedCmd = (BYTE *)(BigBuf) + DEMOD_TRACE_SIZE;
+ uint8_t *receivedCmd = (uint8_t *)(BigBuf) + DEMOD_TRACE_SIZE;
// The response (tag -> reader) that we're working on receiving.
- BYTE *receivedResponse = (BYTE *)(BigBuf) + DEMOD_TRACE_SIZE + READER_TAG_BUFFER_SIZE;
+ uint8_t *receivedResponse = (uint8_t *)(BigBuf) + DEMOD_TRACE_SIZE + READER_TAG_BUFFER_SIZE;
// As we receive stuff, we copy it from receivedCmd or receivedResponse
// into trace, along with its length and other annotations.
- BYTE *trace = (BYTE *)BigBuf;
+ uint8_t *trace = (uint8_t *)BigBuf;
int traceLen = 0;
// The DMA buffer, used to stream samples from the FPGA.
- SBYTE *dmaBuf = (SBYTE *)(BigBuf) + DEMOD_TRACE_SIZE + READER_TAG_BUFFER_SIZE + TAG_READER_BUFFER_SIZE;
+ int8_t *dmaBuf = (int8_t *)(BigBuf) + DEMOD_TRACE_SIZE + READER_TAG_BUFFER_SIZE + TAG_READER_BUFFER_SIZE;
int lastRxCounter;
- SBYTE *upTo;
+ int8_t *upTo;
int ci, cq;
int maxBehindBy = 0;
FpgaSetupSsc();
upTo = dmaBuf;
lastRxCounter = DMA_BUFFER_SIZE;
- FpgaSetupSscDma((BYTE *)dmaBuf, DMA_BUFFER_SIZE);
+ FpgaSetupSscDma((uint8_t *)dmaBuf, DMA_BUFFER_SIZE);
// And now we loop, receiving samples.
for(;;) {
// Blink the LED while Snooping
if(upTo - dmaBuf > DMA_BUFFER_SIZE) {
upTo -= DMA_BUFFER_SIZE;
lastRxCounter += DMA_BUFFER_SIZE;
- AT91C_BASE_PDC_SSC->PDC_RNPR = (DWORD) upTo;
+ AT91C_BASE_PDC_SSC->PDC_RNPR = (uint32_t) upTo;
AT91C_BASE_PDC_SSC->PDC_RNCR = DMA_BUFFER_SIZE;
}
//-----------------------------------------------------------------------------
#include "proxmark3.h"
#include "apps.h"
+#include "util.h"
#include "iso14443crc.h"
-static BYTE *trace = (BYTE *) BigBuf;
+static uint8_t *trace = (uint8_t *) BigBuf;
static int traceLen = 0;
static int rsamples = 0;
-static BOOL tracing = TRUE;
+static int tracing = TRUE;
typedef enum {
SEC_D = 1,
SEC_Z = 6
} SecType;
-static const BYTE OddByteParity[256] = {
+static const uint8_t OddByteParity[256] = {
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
// Generate the parity value for a byte sequence
//
//-----------------------------------------------------------------------------
-DWORD GetParity(const BYTE * pbtCmd, int iLen)
+uint32_t GetParity(const uint8_t * pbtCmd, int iLen)
{
int i;
- DWORD dwPar = 0;
+ uint32_t dwPar = 0;
// Generate the encrypted data
for (i = 0; i < iLen; i++) {
return dwPar;
}
-static void AppendCrc14443a(BYTE* data, int len)
+static void AppendCrc14443a(uint8_t* data, int len)
{
ComputeCrc14443(CRC_14443_A,data,len,data+len,data+len+1);
}
-BOOL LogTrace(const BYTE * btBytes, int iLen, int iSamples, DWORD dwParity, BOOL bReader)
+int LogTrace(const uint8_t * btBytes, int iLen, int iSamples, uint32_t dwParity, int bReader)
{
// Return when trace is full
if (traceLen >= TRACE_LENGTH) return FALSE;
return TRUE;
}
-BOOL LogTraceInfo(byte_t* data, size_t len)
+int LogTraceInfo(byte_t* data, size_t len)
{
return LogTrace(data,len,0,GetParity(data,len),TRUE);
}
STATE_MILLER_Z,
STATE_ERROR_WAIT
} state;
- WORD shiftReg;
+ uint16_t shiftReg;
int bitCnt;
int byteCnt;
int byteCntMax;
DROP_FIRST_HALF,
DROP_SECOND_HALF
} drop;
- BYTE *output;
+ uint8_t *output;
} Uart;
-static BOOL MillerDecoding(int bit)
+static int MillerDecoding(int bit)
{
int error = 0;
int bitright;
Uart.bitBuffer ^= bit;
}
- BOOL EOC = FALSE;
+ int EOC = FALSE;
if(Uart.state != STATE_UNSYNCD) {
Uart.posCnt++;
int posCount;
int syncBit;
int parityBits;
- WORD shiftReg;
+ uint16_t shiftReg;
int buffer;
int buff;
int samples;
SUB_FIRST_HALF,
SUB_SECOND_HALF
} sub;
- BYTE *output;
+ uint8_t *output;
} Demod;
-static BOOL ManchesterDecoding(int v)
+static int ManchesterDecoding(int v)
{
int bit;
int modulation;
// We won't start recording the frames that we acquire until we trigger;
// a good trigger condition to get started is probably when we see a
// response from the tag.
- BOOL triggered = TRUE; // FALSE to wait first for card
+ int triggered = TRUE; // FALSE to wait first for card
// The command (reader -> tag) that we're receiving.
// The length of a received command will in most cases be no more than 18 bytes.
// So 32 should be enough!
- BYTE *receivedCmd = (((BYTE *)BigBuf) + RECV_CMD_OFFSET);
+ uint8_t *receivedCmd = (((uint8_t *)BigBuf) + RECV_CMD_OFFSET);
// The response (tag -> reader) that we're receiving.
- BYTE *receivedResponse = (((BYTE *)BigBuf) + RECV_RES_OFFSET);
+ uint8_t *receivedResponse = (((uint8_t *)BigBuf) + RECV_RES_OFFSET);
// As we receive stuff, we copy it from receivedCmd or receivedResponse
// into trace, along with its length and other annotations.
- //BYTE *trace = (BYTE *)BigBuf;
+ //uint8_t *trace = (uint8_t *)BigBuf;
//int traceLen = 0;
// The DMA buffer, used to stream samples from the FPGA
- SBYTE *dmaBuf = ((SBYTE *)BigBuf) + DMA_BUFFER_OFFSET;
+ int8_t *dmaBuf = ((int8_t *)BigBuf) + DMA_BUFFER_OFFSET;
int lastRxCounter;
- SBYTE *upTo;
+ int8_t *upTo;
int smpl;
int maxBehindBy = 0;
FpgaSetupSsc();
upTo = dmaBuf;
lastRxCounter = DMA_BUFFER_SIZE;
- FpgaSetupSscDma((BYTE *)dmaBuf, DMA_BUFFER_SIZE);
+ FpgaSetupSscDma((uint8_t *)dmaBuf, DMA_BUFFER_SIZE);
LED_A_ON();
if(upTo - dmaBuf > DMA_BUFFER_SIZE) {
upTo -= DMA_BUFFER_SIZE;
lastRxCounter += DMA_BUFFER_SIZE;
- AT91C_BASE_PDC_SSC->PDC_RNPR = (DWORD)upTo;
+ AT91C_BASE_PDC_SSC->PDC_RNPR = (uint32_t) upTo;
AT91C_BASE_PDC_SSC->PDC_RNCR = DMA_BUFFER_SIZE;
}
//-----------------------------------------------------------------------------
// Prepare tag messages
//-----------------------------------------------------------------------------
-static void CodeIso14443aAsTag(const BYTE *cmd, int len)
+static void CodeIso14443aAsTag(const uint8_t *cmd, int len)
{
int i;
int oddparity;
for(i = 0; i < len; i++) {
int j;
- BYTE b = cmd[i];
+ uint8_t b = cmd[i];
// Data bits
oddparity = 0x01;
// Stop when button is pressed
// Or return TRUE when command is captured
//-----------------------------------------------------------------------------
-static BOOL GetIso14443aCommandFromReader(BYTE *received, int *len, int maxLen)
+static int GetIso14443aCommandFromReader(uint8_t *received, int *len, int maxLen)
{
// Set FPGA mode to "simulated ISO 14443 tag", no modulation (listen
// only, since we are receiving, not transmitting).
AT91C_BASE_SSC->SSC_THR = 0x00;
}
if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
- BYTE b = (BYTE)AT91C_BASE_SSC->SSC_RHR;
+ uint8_t b = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
if(MillerDecoding((b & 0xf0) >> 4)) {
*len = Uart.byteCnt;
return TRUE;
// This function contains the tag emulation
// Prepare protocol messages
- // static const BYTE cmd1[] = { 0x26 };
-// static const BYTE response1[] = { 0x02, 0x00 }; // Says: I am Mifare 4k - original line - greg
+ // static const uint8_t cmd1[] = { 0x26 };
+// static const uint8_t response1[] = { 0x02, 0x00 }; // Says: I am Mifare 4k - original line - greg
//
- static const BYTE response1[] = { 0x44, 0x03 }; // Says: I am a DESFire Tag, ph33r me
-// static const BYTE response1[] = { 0x44, 0x00 }; // Says: I am a ULTRALITE Tag, 0wn me
+ static const uint8_t response1[] = { 0x44, 0x03 }; // Says: I am a DESFire Tag, ph33r me
+// static const uint8_t response1[] = { 0x44, 0x00 }; // Says: I am a ULTRALITE Tag, 0wn me
// UID response
- // static const BYTE cmd2[] = { 0x93, 0x20 };
- //static const BYTE response2[] = { 0x9a, 0xe5, 0xe4, 0x43, 0xd8 }; // original value - greg
+ // static const uint8_t cmd2[] = { 0x93, 0x20 };
+ //static const uint8_t response2[] = { 0x9a, 0xe5, 0xe4, 0x43, 0xd8 }; // original value - greg
// my desfire
- static const BYTE response2[] = { 0x88, 0x04, 0x21, 0x3f, 0x4d }; // known uid - note cascade (0x88), 2nd byte (0x04) = NXP/Phillips
+ static const uint8_t response2[] = { 0x88, 0x04, 0x21, 0x3f, 0x4d }; // known uid - note cascade (0x88), 2nd byte (0x04) = NXP/Phillips
// When reader selects us during cascade1 it will send cmd3
-//BYTE response3[] = { 0x04, 0x00, 0x00 }; // SAK Select (cascade1) successful response (ULTRALITE)
-BYTE response3[] = { 0x24, 0x00, 0x00 }; // SAK Select (cascade1) successful response (DESFire)
+//uint8_t response3[] = { 0x04, 0x00, 0x00 }; // SAK Select (cascade1) successful response (ULTRALITE)
+uint8_t response3[] = { 0x24, 0x00, 0x00 }; // SAK Select (cascade1) successful response (DESFire)
ComputeCrc14443(CRC_14443_A, response3, 1, &response3[1], &response3[2]);
// send cascade2 2nd half of UID
-static const BYTE response2a[] = { 0x51, 0x48, 0x1d, 0x80, 0x84 }; // uid - cascade2 - 2nd half (4 bytes) of UID+ BCCheck
+static const uint8_t response2a[] = { 0x51, 0x48, 0x1d, 0x80, 0x84 }; // uid - cascade2 - 2nd half (4 bytes) of UID+ BCCheck
// NOTE : THE CRC on the above may be wrong as I have obfuscated the actual UID
// When reader selects us during cascade2 it will send cmd3a
-//BYTE response3a[] = { 0x00, 0x00, 0x00 }; // SAK Select (cascade2) successful response (ULTRALITE)
-BYTE response3a[] = { 0x20, 0x00, 0x00 }; // SAK Select (cascade2) successful response (DESFire)
+//uint8_t response3a[] = { 0x00, 0x00, 0x00 }; // SAK Select (cascade2) successful response (ULTRALITE)
+uint8_t response3a[] = { 0x20, 0x00, 0x00 }; // SAK Select (cascade2) successful response (DESFire)
ComputeCrc14443(CRC_14443_A, response3a, 1, &response3a[1], &response3a[2]);
- static const BYTE response5[] = { 0x00, 0x00, 0x00, 0x00 }; // Very random tag nonce
+ static const uint8_t response5[] = { 0x00, 0x00, 0x00, 0x00 }; // Very random tag nonce
- BYTE *resp;
+ uint8_t *resp;
int respLen;
// Longest possible response will be 16 bytes + 2 CRC = 18 bytes
// Respond with card type
- BYTE *resp1 = (((BYTE *)BigBuf) + 800);
+ uint8_t *resp1 = (((uint8_t *)BigBuf) + 800);
int resp1Len;
// Anticollision cascade1 - respond with uid
- BYTE *resp2 = (((BYTE *)BigBuf) + 970);
+ uint8_t *resp2 = (((uint8_t *)BigBuf) + 970);
int resp2Len;
// Anticollision cascade2 - respond with 2nd half of uid if asked
// we're only going to be asked if we set the 1st byte of the UID (during cascade1) to 0x88
- BYTE *resp2a = (((BYTE *)BigBuf) + 1140);
+ uint8_t *resp2a = (((uint8_t *)BigBuf) + 1140);
int resp2aLen;
// Acknowledge select - cascade 1
- BYTE *resp3 = (((BYTE *)BigBuf) + 1310);
+ uint8_t *resp3 = (((uint8_t *)BigBuf) + 1310);
int resp3Len;
// Acknowledge select - cascade 2
- BYTE *resp3a = (((BYTE *)BigBuf) + 1480);
+ uint8_t *resp3a = (((uint8_t *)BigBuf) + 1480);
int resp3aLen;
// Response to a read request - not implemented atm
- BYTE *resp4 = (((BYTE *)BigBuf) + 1550);
+ uint8_t *resp4 = (((uint8_t *)BigBuf) + 1550);
int resp4Len;
// Authenticate response - nonce
- BYTE *resp5 = (((BYTE *)BigBuf) + 1720);
+ uint8_t *resp5 = (((uint8_t *)BigBuf) + 1720);
int resp5Len;
- BYTE *receivedCmd = (BYTE *)BigBuf;
+ uint8_t *receivedCmd = (uint8_t *)BigBuf;
int len;
int i;
int u;
- BYTE b;
+ uint8_t b;
// To control where we are in the protocol
int order = 0;
int cmdsRecvd = 0;
- BOOL fdt_indicator;
+ int fdt_indicator;
memset(receivedCmd, 0x44, 400);
fdt_indicator = FALSE;
for(;;) {
if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
- volatile BYTE b = (BYTE)AT91C_BASE_SSC->SSC_RHR;
+ volatile uint8_t b = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
(void)b;
}
if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY)) {
//-----------------------------------------------------------------------------
// Transmit the command (to the tag) that was placed in ToSend[].
//-----------------------------------------------------------------------------
-static void TransmitFor14443a(const BYTE *cmd, int len, int *samples, int *wait)
+static void TransmitFor14443a(const uint8_t *cmd, int len, int *samples, int *wait)
{
int c;
c++;
}
if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
- volatile DWORD r = AT91C_BASE_SSC->SSC_RHR;
+ volatile uint32_t r = AT91C_BASE_SSC->SSC_RHR;
(void)r;
}
WDT_HIT();
}
}
if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
- volatile DWORD r = AT91C_BASE_SSC->SSC_RHR;
+ volatile uint32_t r = AT91C_BASE_SSC->SSC_RHR;
(void)r;
}
WDT_HIT();
// To generate an arbitrary stream from reader
//
//-----------------------------------------------------------------------------
-void ArbitraryFromReader(const BYTE *cmd, int parity, int len)
+void ArbitraryFromReader(const uint8_t *cmd, int parity, int len)
{
int i;
int j;
int last;
- BYTE b;
+ uint8_t b;
ToSendReset();
// Code a 7-bit command without parity bit
// This is especially for 0x26 and 0x52 (REQA and WUPA)
//-----------------------------------------------------------------------------
-void ShortFrameFromReader(const BYTE bt)
+void ShortFrameFromReader(const uint8_t bt)
{
int j;
int last;
- BYTE b;
+ uint8_t b;
ToSendReset();
// Prepare reader command to send to FPGA
//
//-----------------------------------------------------------------------------
-void CodeIso14443aAsReaderPar(const BYTE * cmd, int len, DWORD dwParity)
+void CodeIso14443aAsReaderPar(const uint8_t * cmd, int len, uint32_t dwParity)
{
int i, j;
int last;
- BYTE b;
+ uint8_t b;
ToSendReset();
// If a response is captured return TRUE
// If it takes to long return FALSE
//-----------------------------------------------------------------------------
-static BOOL GetIso14443aAnswerFromTag(BYTE *receivedResponse, int maxLen, int *samples, int *elapsed) //BYTE *buffer
+static int GetIso14443aAnswerFromTag(uint8_t *receivedResponse, int maxLen, int *samples, int *elapsed) //uint8_t *buffer
{
// buffer needs to be 512 bytes
int c;
Demod.len = 0;
Demod.state = DEMOD_UNSYNCD;
- BYTE b;
+ uint8_t b;
if (elapsed) *elapsed = 0;
c = 0;
}
if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
if(c < 512) { c++; } else { return FALSE; }
- b = (BYTE)AT91C_BASE_SSC->SSC_RHR;
+ b = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
if(ManchesterDecoding((b & 0xf0) >> 4)) {
*samples = ((c - 1) << 3) + 4;
return TRUE;
}
}
-void ReaderTransmitShort(const BYTE* bt)
+void ReaderTransmitShort(const uint8_t* bt)
{
int wait = 0;
int samples = 0;
if (tracing) LogTrace(bt,1,0,GetParity(bt,1),TRUE);
}
-void ReaderTransmitPar(BYTE* frame, int len, DWORD par)
+void ReaderTransmitPar(uint8_t* frame, int len, uint32_t par)
{
int wait = 0;
int samples = 0;
// This is tied to other size changes
- // BYTE* frame_addr = ((BYTE*)BigBuf) + 2024;
+ // uint8_t* frame_addr = ((uint8_t*)BigBuf) + 2024;
CodeIso14443aAsReaderPar(frame,len,par);
// Select the card
}
-void ReaderTransmit(BYTE* frame, int len)
+void ReaderTransmit(uint8_t* frame, int len)
{
// Generate parity and redirect
ReaderTransmitPar(frame,len,GetParity(frame,len));
}
-BOOL ReaderReceive(BYTE* receivedAnswer)
+int ReaderReceive(uint8_t* receivedAnswer)
{
int samples = 0;
if (!GetIso14443aAnswerFromTag(receivedAnswer,100,&samples,0)) return FALSE;
// Read an ISO 14443a tag. Send out commands and store answers.
//
//-----------------------------------------------------------------------------
-void ReaderIso14443a(DWORD parameter)
+void ReaderIso14443a(uint32_t parameter)
{
// Anticollision
- BYTE wupa[] = { 0x52 };
- BYTE sel_all[] = { 0x93,0x20 };
- BYTE sel_uid[] = { 0x93,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00 };
- BYTE sel_all_c2[] = { 0x95,0x20 };
- BYTE sel_uid_c2[] = { 0x95,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00 };
+ uint8_t wupa[] = { 0x52 };
+ uint8_t sel_all[] = { 0x93,0x20 };
+ uint8_t sel_uid[] = { 0x93,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00 };
+ uint8_t sel_all_c2[] = { 0x95,0x20 };
+ uint8_t sel_uid_c2[] = { 0x95,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00 };
// Mifare AUTH
- BYTE mf_auth[] = { 0x60,0x00,0xf5,0x7b };
-// BYTE mf_nr_ar[] = { 0x00,0x00,0x00,0x00 };
+ uint8_t mf_auth[] = { 0x60,0x00,0xf5,0x7b };
+// uint8_t mf_nr_ar[] = { 0x00,0x00,0x00,0x00 };
- BYTE* receivedAnswer = (((BYTE *)BigBuf) + 3560); // was 3560 - tied to other size changes
+ uint8_t* receivedAnswer = (((uint8_t *)BigBuf) + 3560); // was 3560 - tied to other size changes
traceLen = 0;
// Setup SSC
// Read an ISO 14443a tag. Send out commands and store answers.
//
//-----------------------------------------------------------------------------
-void ReaderMifare(DWORD parameter)
+void ReaderMifare(uint32_t parameter)
{
// Anticollision
- BYTE wupa[] = { 0x52 };
- BYTE sel_all[] = { 0x93,0x20 };
- BYTE sel_uid[] = { 0x93,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00 };
+ uint8_t wupa[] = { 0x52 };
+ uint8_t sel_all[] = { 0x93,0x20 };
+ uint8_t sel_uid[] = { 0x93,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00 };
// Mifare AUTH
- BYTE mf_auth[] = { 0x60,0x00,0xf5,0x7b };
- BYTE mf_nr_ar[] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 };
+ uint8_t mf_auth[] = { 0x60,0x00,0xf5,0x7b };
+ uint8_t mf_nr_ar[] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 };
- BYTE* receivedAnswer = (((BYTE *)BigBuf) + 3560); // was 3560 - tied to other size changes
+ uint8_t* receivedAnswer = (((uint8_t *)BigBuf) + 3560); // was 3560 - tied to other size changes
traceLen = 0;
tracing = false;
byte_t par = 0;
byte_t par_mask = 0xff;
byte_t par_low = 0;
- BOOL led_on = TRUE;
+ int led_on = TRUE;
tracing = FALSE;
byte_t nt[4];
//-----------------------------------------------------------------------------
#include "proxmark3.h"
+#include "util.h"
#include "apps.h"
// FROM winsrc\prox.h //////////////////////////////////
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
};
-static void CodeIso15693AsReader(BYTE *cmd, int n)
+static void CodeIso15693AsReader(uint8_t *cmd, int n)
{
int i, j;
//-----------------------------------------------------------------------------
// The CRC used by ISO 15693.
//-----------------------------------------------------------------------------
-static WORD Crc(BYTE *v, int n)
+static uint16_t Crc(uint8_t *v, int n)
{
- DWORD reg;
+ uint32_t reg;
int i, j;
reg = 0xffff;
for(i = 0; i < n; i++) {
- reg = reg ^ ((DWORD)v[i]);
+ reg = reg ^ ((uint32_t)v[i]);
for (j = 0; j < 8; j++) {
if (reg & 0x0001) {
reg = (reg >> 1) ^ 0x8408;
//-----------------------------------------------------------------------------
static void BuildIdentifyRequest(void)
{
- BYTE cmd[5];
+ uint8_t cmd[5];
- WORD crc;
+ uint16_t crc;
// one sub-carrier, inventory, 1 slot, fast rate
// AFI is at bit 5 (1<<4) when doing an INVENTORY
cmd[0] = (1 << 2) | (1 << 5) | (1 << 1);
CodeIso15693AsReader(cmd, sizeof(cmd));
}
-static void __attribute__((unused)) BuildSysInfoRequest(BYTE *uid)
+static void __attribute__((unused)) BuildSysInfoRequest(uint8_t *uid)
{
- BYTE cmd[12];
+ uint8_t cmd[12];
- WORD crc;
+ uint16_t crc;
// If we set the Option_Flag in this request, the VICC will respond with the secuirty status of the block
// followed by teh block data
// one sub-carrier, inventory, 1 slot, fast rate
CodeIso15693AsReader(cmd, sizeof(cmd));
}
-static void BuildSelectRequest( BYTE uid[])
+static void BuildSelectRequest( uint8_t uid[])
{
// uid[6]=0x31; // this is getting ignored - the uid array is not happening...
- BYTE cmd[12];
+ uint8_t cmd[12];
- WORD crc;
+ uint16_t crc;
// one sub-carrier, inventory, 1 slot, fast rate
//cmd[0] = (1 << 2) | (1 << 5) | (1 << 1); // INVENTROY FLAGS
cmd[0] = (1 << 4) | (1 << 5) | (1 << 1); // Select and addressed FLAGS
CodeIso15693AsReader(cmd, sizeof(cmd));
}
-static void __attribute__((unused)) BuildReadBlockRequest(BYTE *uid, BYTE blockNumber )
+static void __attribute__((unused)) BuildReadBlockRequest(uint8_t *uid, uint8_t blockNumber )
{
- BYTE cmd[13];
+ uint8_t cmd[13];
- WORD crc;
+ uint16_t crc;
// If we set the Option_Flag in this request, the VICC will respond with the secuirty status of the block
// followed by teh block data
// one sub-carrier, inventory, 1 slot, fast rate
CodeIso15693AsReader(cmd, sizeof(cmd));
}
-static void __attribute__((unused)) BuildReadMultiBlockRequest(BYTE *uid)
+static void __attribute__((unused)) BuildReadMultiBlockRequest(uint8_t *uid)
{
- BYTE cmd[14];
+ uint8_t cmd[14];
- WORD crc;
+ uint16_t crc;
// If we set the Option_Flag in this request, the VICC will respond with the secuirty status of the block
// followed by teh block data
// one sub-carrier, inventory, 1 slot, fast rate
CodeIso15693AsReader(cmd, sizeof(cmd));
}
-static void __attribute__((unused)) BuildArbitraryRequest(BYTE *uid,BYTE CmdCode)
+static void __attribute__((unused)) BuildArbitraryRequest(uint8_t *uid,uint8_t CmdCode)
{
- BYTE cmd[14];
+ uint8_t cmd[14];
- WORD crc;
+ uint16_t crc;
// If we set the Option_Flag in this request, the VICC will respond with the secuirty status of the block
// followed by teh block data
// one sub-carrier, inventory, 1 slot, fast rate
CodeIso15693AsReader(cmd, sizeof(cmd));
}
-static void __attribute__((unused)) BuildArbitraryCustomRequest(BYTE uid[], BYTE CmdCode)
+static void __attribute__((unused)) BuildArbitraryCustomRequest(uint8_t uid[], uint8_t CmdCode)
{
- BYTE cmd[14];
+ uint8_t cmd[14];
- WORD crc;
+ uint16_t crc;
// If we set the Option_Flag in this request, the VICC will respond with the secuirty status of the block
// followed by teh block data
// one sub-carrier, inventory, 1 slot, fast rate
static void BuildInventoryResponse(void)
{
- BYTE cmd[12];
+ uint8_t cmd[12];
- WORD crc;
+ uint16_t crc;
// one sub-carrier, inventory, 1 slot, fast rate
// AFI is at bit 5 (1<<4) when doing an INVENTORY
cmd[0] = 0; //(1 << 2) | (1 << 5) | (1 << 1);
//-----------------------------------------------------------------------------
// Transmit the command (to the tag) that was placed in ToSend[].
//-----------------------------------------------------------------------------
-static void TransmitTo15693Tag(const BYTE *cmd, int len, int *samples, int *wait)
+static void TransmitTo15693Tag(const uint8_t *cmd, int len, int *samples, int *wait)
{
int c;
// c++;
// }
// if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
-// volatile DWORD r = AT91C_BASE_SSC->SSC_RHR;
+// volatile uint32_t r = AT91C_BASE_SSC->SSC_RHR;
// (void)r;
// }
// WDT_HIT();
}
}
if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
- volatile DWORD r = AT91C_BASE_SSC->SSC_RHR;
+ volatile uint32_t r = AT91C_BASE_SSC->SSC_RHR;
(void)r;
}
WDT_HIT();
//-----------------------------------------------------------------------------
// Transmit the command (to the reader) that was placed in ToSend[].
//-----------------------------------------------------------------------------
-static void TransmitTo15693Reader(const BYTE *cmd, int len, int *samples, int *wait)
+static void TransmitTo15693Reader(const uint8_t *cmd, int len, int *samples, int *wait)
{
int c;
}
}
if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
- volatile DWORD r = AT91C_BASE_SSC->SSC_RHR;
+ volatile uint32_t r = AT91C_BASE_SSC->SSC_RHR;
(void)r;
}
WDT_HIT();
*samples = (c + *wait) << 3;
}
-static int GetIso15693AnswerFromTag(BYTE *receivedResponse, int maxLen, int *samples, int *elapsed)
+static int GetIso15693AnswerFromTag(uint8_t *receivedResponse, int maxLen, int *samples, int *elapsed)
{
int c = 0;
- BYTE *dest = (BYTE *)BigBuf;
+ uint8_t *dest = (uint8_t *)BigBuf;
int getNext = 0;
- SBYTE prev = 0;
+ int8_t prev = 0;
// NOW READ RESPONSE
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_RX_XCORR);
AT91C_BASE_SSC->SSC_THR = 0x43;
}
if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
- SBYTE b;
- b = (SBYTE)AT91C_BASE_SSC->SSC_RHR;
+ int8_t b;
+ b = (int8_t)AT91C_BASE_SSC->SSC_RHR;
// The samples are correlations against I and Q versions of the
// tone that the tag AM-modulates, so every other sample is I,
// every other is Q. We just want power, so abs(I) + abs(Q) is
// close to what we want.
if(getNext) {
- SBYTE r;
+ int8_t r;
if(b < 0) {
r = -b;
r += prev;
}
- dest[c++] = (BYTE)r;
+ dest[c++] = (uint8_t)r;
if(c >= 2000) {
break;
i = maxPos + arraylen(FrameSOF)/skip;
- BYTE outBuf[20];
+ uint8_t outBuf[20];
memset(outBuf, 0, sizeof(outBuf));
- BYTE mask = 0x01;
+ uint8_t mask = 0x01;
for(;;) {
int corr0 = 0, corr1 = 0, corrEOF = 0;
for(j = 0; j < arraylen(Logic0); j += skip) {
DbpString("error, uneven octet! (discard extra bits!)");
/// DbpString(" mask=%02x", mask);
}
-// BYTE str1 [8];
+// uint8_t str1 [8];
// itoa(k,str1);
// strcat(str1," octets read");
}
// Now the GetISO15693 message from sniffing command
-static int GetIso15693AnswerFromSniff(BYTE *receivedResponse, int maxLen, int *samples, int *elapsed)
+static int GetIso15693AnswerFromSniff(uint8_t *receivedResponse, int maxLen, int *samples, int *elapsed)
{
int c = 0;
- BYTE *dest = (BYTE *)BigBuf;
+ uint8_t *dest = (uint8_t *)BigBuf;
int getNext = 0;
- SBYTE prev = 0;
+ int8_t prev = 0;
// NOW READ RESPONSE
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_RX_XCORR);
AT91C_BASE_SSC->SSC_THR = 0x43;
}
if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
- SBYTE b;
- b = (SBYTE)AT91C_BASE_SSC->SSC_RHR;
+ int8_t b;
+ b = (int8_t)AT91C_BASE_SSC->SSC_RHR;
// The samples are correlations against I and Q versions of the
// tone that the tag AM-modulates, so every other sample is I,
// every other is Q. We just want power, so abs(I) + abs(Q) is
// close to what we want.
if(getNext) {
- SBYTE r;
+ int8_t r;
if(b < 0) {
r = -b;
r += prev;
}
- dest[c++] = (BYTE)r;
+ dest[c++] = (uint8_t)r;
if(c >= 20000) {
break;
i = maxPos + arraylen(FrameSOF)/skip;
- BYTE outBuf[20];
+ uint8_t outBuf[20];
memset(outBuf, 0, sizeof(outBuf));
- BYTE mask = 0x01;
+ uint8_t mask = 0x01;
for(;;) {
int corr0 = 0, corr1 = 0, corrEOF = 0;
for(j = 0; j < arraylen(Logic0); j += skip) {
DbpString("error, uneven octet! (discard extra bits!)");
/// DbpString(" mask=%02x", mask);
}
-// BYTE str1 [8];
+// uint8_t str1 [8];
// itoa(k,str1);
// strcat(str1," octets read");
void AcquireRawAdcSamplesIso15693(void)
{
int c = 0;
- BYTE *dest = (BYTE *)BigBuf;
+ uint8_t *dest = (uint8_t *)BigBuf;
int getNext = 0;
- SBYTE prev = 0;
+ int8_t prev = 0;
BuildIdentifyRequest();
}
}
if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
- volatile DWORD r = AT91C_BASE_SSC->SSC_RHR;
+ volatile uint32_t r = AT91C_BASE_SSC->SSC_RHR;
(void)r;
}
WDT_HIT();
AT91C_BASE_SSC->SSC_THR = 0x43;
}
if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
- SBYTE b;
- b = (SBYTE)AT91C_BASE_SSC->SSC_RHR;
+ int8_t b;
+ b = (int8_t)AT91C_BASE_SSC->SSC_RHR;
// The samples are correlations against I and Q versions of the
// tone that the tag AM-modulates, so every other sample is I,
// every other is Q. We just want power, so abs(I) + abs(Q) is
// close to what we want.
if(getNext) {
- SBYTE r;
+ int8_t r;
if(b < 0) {
r = -b;
r += prev;
}
- dest[c++] = (BYTE)r;
+ dest[c++] = (uint8_t)r;
if(c >= 2000) {
break;
// Simulate an ISO15693 reader, perform anti-collision and then attempt to read a sector
// all demodulation performed in arm rather than host. - greg
//-----------------------------------------------------------------------------
-void ReaderIso15693(DWORD parameter)
+void ReaderIso15693(uint32_t parameter)
{
LED_A_ON();
LED_B_ON();
//DbpString(parameter);
- //BYTE *answer0 = (((BYTE *)BigBuf) + 3560); // allow 100 bytes per reponse (way too much)
- BYTE *answer1 = (((BYTE *)BigBuf) + 3660); //
- BYTE *answer2 = (((BYTE *)BigBuf) + 3760);
- BYTE *answer3 = (((BYTE *)BigBuf) + 3860);
- //BYTE *TagUID= (((BYTE *)BigBuf) + 3960); // where we hold the uid for hi15reader
+ //uint8_t *answer0 = (((uint8_t *)BigBuf) + 3560); // allow 100 bytes per reponse (way too much)
+ uint8_t *answer1 = (((uint8_t *)BigBuf) + 3660); //
+ uint8_t *answer2 = (((uint8_t *)BigBuf) + 3760);
+ uint8_t *answer3 = (((uint8_t *)BigBuf) + 3860);
+ //uint8_t *TagUID= (((uint8_t *)BigBuf) + 3960); // where we hold the uid for hi15reader
// int answerLen0 = 0;
int answerLen1 = 0;
int answerLen2 = 0;
// FIRST WE RUN AN INVENTORY TO GET THE TAG UID
// THIS MEANS WE CAN PRE-BUILD REQUESTS TO SAVE CPU TIME
- BYTE TagUID[7]; // where we hold the uid for hi15reader
+ uint8_t TagUID[7]; // where we hold the uid for hi15reader
// BuildIdentifyRequest();
// //TransmitTo15693Tag(ToSend,ToSendMax+3,&tsamples, &wait);
// Simulate an ISO15693 TAG, perform anti-collision and then print any reader commands
// all demodulation performed in arm rather than host. - greg
//-----------------------------------------------------------------------------
-void SimTagIso15693(DWORD parameter)
+void SimTagIso15693(uint32_t parameter)
{
LED_A_ON();
LED_B_ON();
LED_C_OFF();
LED_D_OFF();
- BYTE *answer1 = (((BYTE *)BigBuf) + 3660); //
+ uint8_t *answer1 = (((uint8_t *)BigBuf) + 3660); //
int answerLen1 = 0;
// Blank arrays
*/
#include "proxmark3.h"
-
#include "apps.h"
-#include "legicrf.h"
-#include <stdint.h>
+#include "util.h"
+#include "legicrf.h"
#include "legic_prng.h"
#include "crc.h"
//-----------------------------------------------------------------------------
#include "proxmark3.h"
#include "apps.h"
+#include "util.h"
#include "hitag2.h"
#include "crc16.h"
-void AcquireRawAdcSamples125k(BOOL at134khz)
+void AcquireRawAdcSamples125k(int at134khz)
{
if (at134khz)
FpgaSendCommand(FPGA_CMD_SET_DIVISOR, 88); //134.8Khz
// split into two routines so we can avoid timing issues after sending commands //
void DoAcquisition125k(void)
{
- BYTE *dest = (BYTE *)BigBuf;
+ uint8_t *dest = (uint8_t *)BigBuf;
int n = sizeof(BigBuf);
int i;
LED_D_ON();
}
if (AT91C_BASE_SSC->SSC_SR & AT91C_SSC_RXRDY) {
- dest[i] = (BYTE)AT91C_BASE_SSC->SSC_RHR;
+ dest[i] = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
i++;
LED_D_OFF();
if (i >= n) break;
dest[0], dest[1], dest[2], dest[3], dest[4], dest[5], dest[6], dest[7]);
}
-void ModThenAcquireRawAdcSamples125k(int delay_off, int period_0, int period_1, BYTE *command)
+void ModThenAcquireRawAdcSamples125k(int delay_off, int period_0, int period_1, uint8_t *command)
{
- BOOL at134khz;
+ int at134khz;
/* Make sure the tag is reset */
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
// int n = GraphTraceLen;
// 128 bit shift register [shift3:shift2:shift1:shift0]
- DWORD shift3 = 0, shift2 = 0, shift1 = 0, shift0 = 0;
+ uint32_t shift3 = 0, shift2 = 0, shift1 = 0, shift0 = 0;
int i, cycles=0, samples=0;
// how many sample points fit in 16 cycles of each frequency
- DWORD sampleslo = (FSAMPLE<<4)/FREQLO, sampleshi = (FSAMPLE<<4)/FREQHI;
+ uint32_t sampleslo = (FSAMPLE<<4)/FREQLO, sampleshi = (FSAMPLE<<4)/FREQHI;
// when to tell if we're close enough to one freq or another
- DWORD threshold = (sampleslo - sampleshi + 1)>>1;
+ uint32_t threshold = (sampleslo - sampleshi + 1)>>1;
// TI tags charge at 134.2Khz
FpgaSendCommand(FPGA_CMD_SET_DIVISOR, 88); //134.8Khz
// i'm 99% sure the crc algorithm is correct, but it may need to eat the
// bytes in reverse or something
// calculate CRC
- DWORD crc=0;
+ uint32_t crc=0;
crc = update_crc16(crc, (shift0)&0xff);
crc = update_crc16(crc, (shift0>>8)&0xff);
}
}
-void WriteTIbyte(BYTE b)
+void WriteTIbyte(uint8_t b)
{
int i = 0;
{
int i, j, n;
// tag transmission is <20ms, sampling at 2M gives us 40K samples max
- // each sample is 1 bit stuffed into a DWORD so we need 1250 DWORDS
+ // each sample is 1 bit stuffed into a uint32_t so we need 1250 uint32_t
#define TIBUFLEN 1250
// clear buffer
// arguments: 64bit data split into 32bit idhi:idlo and optional 16bit crc
// if crc provided, it will be written with the data verbatim (even if bogus)
// if not provided a valid crc will be computed from the data and written.
-void WriteTItag(DWORD idhi, DWORD idlo, WORD crc)
+void WriteTItag(uint32_t idhi, uint32_t idlo, uint16_t crc)
{
if(crc == 0) {
crc = update_crc16(crc, (idlo)&0xff);
void SimulateTagLowFrequency(int period, int gap, int ledcontrol)
{
int i;
- BYTE *tab = (BYTE *)BigBuf;
+ uint8_t *tab = (uint8_t *)BigBuf;
FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_SIMULATOR);
// compose fc/8 fc/10 waveform
static void fc(int c, int *n) {
- BYTE *dest = (BYTE *)BigBuf;
+ uint8_t *dest = (uint8_t *)BigBuf;
int idx;
// for when we want an fc8 pattern every 4 logical bits
// loop to capture raw HID waveform then FSK demodulate the TAG ID from it
void CmdHIDdemodFSK(int findone, int *high, int *low, int ledcontrol)
{
- BYTE *dest = (BYTE *)BigBuf;
+ uint8_t *dest = (uint8_t *)BigBuf;
int m=0, n=0, i=0, idx=0, found=0, lastval=0;
- DWORD hi=0, lo=0;
+ uint32_t hi=0, lo=0;
FpgaSendCommand(FPGA_CMD_SET_DIVISOR, 95); //125Khz
FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_READER);
LED_D_ON();
}
if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
- dest[i] = (BYTE)AT91C_BASE_SSC->SSC_RHR;
+ dest[i] = (uint8_t)AT91C_BASE_SSC->SSC_RHR;
// we don't care about actual value, only if it's more or less than a
// threshold essentially we capture zero crossings for later analysis
if(dest[i] < 127) dest[i] = 0; else dest[i] = 1;
* @(#)subr_prf.c 8.3 (Berkeley) 1/21/94
*/
-typedef unsigned long size_t;
-typedef long ssize_t;
-#ifdef __64BIT__
-typedef unsigned long long uintmax_t;
-typedef long long intmax_t;
-#else
-typedef unsigned int uintmax_t;
-typedef int intmax_t;
-#endif
+#include <stddef.h>
+#include <stdarg.h>
+#include "printf.h"
+#include "util.h"
+
+typedef uint32_t uintmax_t;
+typedef int32_t intmax_t;
+
typedef unsigned char u_char;
typedef unsigned int u_int;
typedef unsigned long u_long;
typedef unsigned short u_short;
typedef unsigned long long u_quad_t;
typedef long long quad_t;
-typedef unsigned long uintptr_t;
-typedef long ptrdiff_t;
-#define NULL ((void*)0)
+
+typedef int ssize_t;
+
#define NBBY 8 /* number of bits in a byte */
+
char const hex2ascii_data[] = "0123456789abcdefghijklmnopqrstuvwxyz";
#define hex2ascii(hex) (hex2ascii_data[hex])
-#define va_list __builtin_va_list
-#define va_start __builtin_va_start
-#define va_arg __builtin_va_arg
-#define va_end __builtin_va_end
#define toupper(c) ((c) - 0x20 * (((c) >= 'a') && ((c) <= 'z')))
-static size_t
-strlen(const char *s)
-{
- size_t l = 0;
- while (*s++)
- l++;
- return l;
-}
/* Max number conversion buffer length: a u_quad_t in base 2, plus NUL byte. */
#define MAXNBUF (sizeof(intmax_t) * NBBY + 1)
#undef PCHAR
}
+int vsprintf(char *dest, const char *fmt, va_list ap)
+{
+ return kvsprintf(fmt, dest, 10, ap);
+}
+
int
sprintf(char *dest, const char *fmt, ...)
{
--- /dev/null
+#ifndef __PRINTF_H
+#define __PRINTF_H
+
+#include <stdarg.h>
+
+int kvsprintf(const char *format, void *arg, int radix, va_list ap) __attribute__ ((format (printf, 1, 0)));
+int vsprintf(char *str, const char *format, va_list ap) __attribute__ ((format (printf, 2, 0)));
+int sprintf(char *str, const char *format, ...) __attribute__ ((format (printf, 2, 3)));
+
+
+
+#endif
\ No newline at end of file
// Jonathan Westhues, Sept 2005
//-----------------------------------------------------------------------------
#include "proxmark3.h"
-#include "apps.h"
+#include "util.h"
void *memcpy(void *dest, const void *src, int len)
{
- BYTE *d = dest;
- const BYTE *s = src;
+ uint8_t *d = dest;
+ const uint8_t *s = src;
while((len--) > 0) {
*d = *s;
d++;
void *memset(void *dest, int c, int len)
{
- BYTE *d = dest;
+ uint8_t *d = dest;
while((len--) > 0) {
*d = c;
d++;
int memcmp(const void *av, const void *bv, int len)
{
- const BYTE *a = av;
- const BYTE *b = bv;
+ const uint8_t *a = av;
+ const uint8_t *b = bv;
while((len--) > 0) {
if(*a != *b) {
return 0;
}
-int strlen(char *str)
+int strlen(const char *str)
{
int l = 0;
while(*str) {
return dest;
}
-void num_to_bytes(uint64_t n, size_t len, byte_t* dest)
+void num_to_bytes(uint64_t n, size_t len, uint8_t* dest)
{
while (len--) {
- dest[len] = (byte_t) n;
+ dest[len] = (uint8_t) n;
n >>= 8;
}
}
-uint64_t bytes_to_num(byte_t* src, size_t len)
+uint64_t bytes_to_num(uint8_t* src, size_t len)
{
uint64_t num = 0;
while (len--)
AT91C_BASE_PWMC_CH0->PWMC_CDTYR = 0;
AT91C_BASE_PWMC_CH0->PWMC_CPRDR = 0xffff;
- WORD start = AT91C_BASE_PWMC_CH0->PWMC_CCNTR;
+ uint16_t start = AT91C_BASE_PWMC_CH0->PWMC_CCNTR;
int letoff = 0;
for(;;)
{
- WORD now = AT91C_BASE_PWMC_CH0->PWMC_CCNTR;
+ uint16_t now = AT91C_BASE_PWMC_CH0->PWMC_CCNTR;
// We haven't let off the button yet
if (!letoff)
// Still haven't let it off
else
// Have we held down a full second?
- if (now == (WORD)(start + ticks))
+ if (now == (uint16_t)(start + ticks))
return BUTTON_HOLD;
}
// Have we ran out of time to double click?
else
- if (now == (WORD)(start + ticks))
+ if (now == (uint16_t)(start + ticks))
// At least we did a single click
return BUTTON_SINGLE_CLICK;
AT91C_BASE_PWMC_CH0->PWMC_CDTYR = 0;
AT91C_BASE_PWMC_CH0->PWMC_CPRDR = 0xffff;
- WORD start = AT91C_BASE_PWMC_CH0->PWMC_CCNTR;
+ uint16_t start = AT91C_BASE_PWMC_CH0->PWMC_CCNTR;
for(;;)
{
- WORD now = AT91C_BASE_PWMC_CH0->PWMC_CCNTR;
+ uint16_t now = AT91C_BASE_PWMC_CH0->PWMC_CCNTR;
// As soon as our button let go, we didn't hold long enough
if (!BUTTON_PRESS())
// Have we waited the full second?
else
- if (now == (WORD)(start + ticks))
+ if (now == (uint16_t)(start + ticks))
return BUTTON_HOLD;
WDT_HIT();
AT91C_BASE_PWMC_CH0->PWMC_CDTYR = 0;
AT91C_BASE_PWMC_CH0->PWMC_CPRDR = 0xffff;
- WORD start = AT91C_BASE_PWMC_CH0->PWMC_CCNTR;
+ uint16_t start = AT91C_BASE_PWMC_CH0->PWMC_CCNTR;
for(;;) {
- WORD now = AT91C_BASE_PWMC_CH0->PWMC_CCNTR;
- if (now == (WORD)(start + ticks))
+ uint16_t now = AT91C_BASE_PWMC_CH0->PWMC_CCNTR;
+ if (now == (uint16_t)(start + ticks))
return;
WDT_HIT();
--- /dev/null
+#ifndef __UTIL_H
+#define __UTIL_H
+
+#include <stddef.h>
+#include <stdint.h>
+
+#define LED_RED 1
+#define LED_ORANGE 2
+#define LED_GREEN 4
+#define LED_RED2 8
+#define BUTTON_HOLD 1
+#define BUTTON_NO_CLICK 0
+#define BUTTON_SINGLE_CLICK -1
+#define BUTTON_DOUBLE_CLICK -2
+#define BUTTON_ERROR -99
+int strlen(const char *str);
+void *memcpy(void *dest, const void *src, int len);
+void *memset(void *dest, int c, int len);
+int memcmp(const void *av, const void *bv, int len);
+char *strncat(char *dest, const char *src, unsigned int n);
+void num_to_bytes(uint64_t n, size_t len, uint8_t* dest);
+uint64_t bytes_to_num(uint8_t* src, size_t len);
+
+void SpinDelay(int ms);
+void SpinDelayUs(int us);
+void LED(int led, int ms);
+void LEDsoff();
+int BUTTON_CLICKED(int ms);
+int BUTTON_HELD(int ms);
+void FormatVersionInformation(char *dst, int len, const char *prefix, void *version_information);
+
+#endif
\ No newline at end of file
for(;;);
}
-void UsbPacketReceived(BYTE *packet, int len)
+void UsbPacketReceived(uint8_t *packet, int len)
{
int i, dont_ack=0;
UsbCommand *c = (UsbCommand *)packet;
- volatile DWORD *p;
+ volatile uint32_t *p;
if(len != sizeof(*c)) {
Fatal();
/* The temporary write buffer of the embedded flash controller is mapped to the
* whole memory region, only the last 8 bits are decoded.
*/
- p = (volatile DWORD *)&_flash_start;
+ p = (volatile uint32_t *)&_flash_start;
for(i = 0; i < 12; i++) {
p[i+c->arg[0]] = c->d.asDwords[i];
}
break;
case CMD_FINISH_WRITE:
- p = (volatile DWORD *)&_flash_start;
+ p = (volatile uint32_t *)&_flash_start;
for(i = 0; i < 4; i++) {
p[i+60] = c->d.asDwords[i];
}
{
int i;
- volatile DWORD *s = (volatile DWORD *)&__bootphase2_src_start__;
- volatile DWORD *d = (volatile DWORD *)&__bootphase2_start__;
+ volatile uint32_t *s = (volatile uint32_t *)&__bootphase2_src_start__;
+ volatile uint32_t *d = (volatile uint32_t *)&__bootphase2_start__;
unsigned int l = (int)&__bootphase2_end__ - (int)&__bootphase2_start__;
- for(i = 0; i < l/sizeof(DWORD); i++) *d++ = *s++;
+ for(i = 0; i < l/sizeof(uint32_t); i++) *d++ = *s++;
}
#define USB_REPORT_PACKET_SIZE 64
typedef struct PACKED {
- BYTE bmRequestType;
- BYTE bRequest;
- WORD wValue;
- WORD wIndex;
- WORD wLength;
+ uint8_t bmRequestType;
+ uint8_t bRequest;
+ uint16_t wValue;
+ uint16_t wIndex;
+ uint16_t wLength;
} UsbSetupData;
#define USB_REQUEST_GET_STATUS 0
#define USB_DEVICE_CLASS_HID 0x03
-static const BYTE HidReportDescriptor[] = {
+static const uint8_t HidReportDescriptor[] = {
0x06,0xA0,0xFF, // Usage Page (vendor defined) FFA0
0x09,0x01, // Usage (vendor defined)
0xA1,0x01, // Collection (Application)
0xC0, // End Collection
};
-static const BYTE DeviceDescriptor[] = {
+static const uint8_t DeviceDescriptor[] = {
0x12, // Descriptor length (18 bytes)
0x01, // Descriptor type (Device)
0x10,0x01, // Complies with USB Spec. Release (0110h = release 1.10)
0x01, // Number of possible configurations (1)
};
-static const BYTE ConfigurationDescriptor[] = {
+static const uint8_t ConfigurationDescriptor[] = {
0x09, // Descriptor length (9 bytes)
0x02, // Descriptor type (Configuration)
0x29,0x00, // Total data length (41 bytes)
0x01, // Polling interval (1 ms)
};
-static const BYTE StringDescriptor0[] = {
+static const uint8_t StringDescriptor0[] = {
0x04, // Length
0x03, // Type is string
0x09, // English
0x04, // US
};
-static const BYTE StringDescriptor1[] = {
+static const uint8_t StringDescriptor1[] = {
24, // Length
0x03, // Type is string
'J', 0x00,
's', 0x00,
};
-static const BYTE StringDescriptor2[] = {
+static const uint8_t StringDescriptor2[] = {
54, // Length
0x03, // Type is string
'P', 0x00,
't', 0x00,
};
-static const BYTE * const StringDescriptors[] = {
+static const uint8_t * const StringDescriptors[] = {
StringDescriptor0,
StringDescriptor1,
StringDescriptor2,
};
-static BYTE UsbBuffer[64];
+static uint8_t UsbBuffer[64];
static int UsbSoFarCount;
-static BYTE CurrentConfiguration;
+static uint8_t CurrentConfiguration;
-static void UsbSendEp0(const BYTE *data, int len)
+static void UsbSendEp0(const uint8_t *data, int len)
{
int thisTime, i;
UsbSetupData usd;
for(i = 0; i < sizeof(usd); i++) {
- ((BYTE *)&usd)[i] = AT91C_BASE_UDP->UDP_FDR[0];
+ ((uint8_t *)&usd)[i] = AT91C_BASE_UDP->UDP_FDR[0];
}
if(usd.bmRequestType & 0x80) {
switch(usd.bRequest) {
case USB_REQUEST_GET_DESCRIPTOR:
if((usd.wValue >> 8) == USB_DESCRIPTOR_TYPE_DEVICE) {
- UsbSendEp0((BYTE *)&DeviceDescriptor,
+ UsbSendEp0((uint8_t *)&DeviceDescriptor,
min(sizeof(DeviceDescriptor), usd.wLength));
} else if((usd.wValue >> 8) == USB_DESCRIPTOR_TYPE_CONFIGURATION) {
- UsbSendEp0((BYTE *)&ConfigurationDescriptor,
+ UsbSendEp0((uint8_t *)&ConfigurationDescriptor,
min(sizeof(ConfigurationDescriptor), usd.wLength));
} else if((usd.wValue >> 8) == USB_DESCRIPTOR_TYPE_STRING) {
- const BYTE *s = StringDescriptors[usd.wValue & 0xff];
+ const uint8_t *s = StringDescriptors[usd.wValue & 0xff];
UsbSendEp0(s, min(s[0], usd.wLength));
} else if((usd.wValue >> 8) == USB_DESCRIPTOR_TYPE_HID_REPORT) {
- UsbSendEp0((BYTE *)&HidReportDescriptor,
+ UsbSendEp0((uint8_t *)&HidReportDescriptor,
min(sizeof(HidReportDescriptor), usd.wLength));
} else {
- *((DWORD *)0x00200000) = usd.wValue;
+ *((uint32_t *)0x00200000) = usd.wValue;
}
break;
case USB_REQUEST_GET_STATUS: {
if(usd.bmRequestType & 0x80) {
- WORD w = 0;
- UsbSendEp0((BYTE *)&w, sizeof(w));
+ uint16_t w = 0;
+ UsbSendEp0((uint8_t *)&w, sizeof(w));
}
break;
}
break;
case USB_REQUEST_GET_INTERFACE: {
- BYTE b = 0;
+ uint8_t b = 0;
UsbSendEp0(&b, sizeof(b));
break;
}
}
}
-void UsbSendPacket(BYTE *packet, int len)
+void UsbSendPacket(uint8_t *packet, int len)
{
int i, thisTime;
}
}
-BOOL UsbConnected()
+int UsbConnected()
{
if (AT91C_BASE_UDP->UDP_GLBSTATE & AT91C_UDP_CONFG)
return TRUE;
return FALSE;
}
-BOOL UsbPoll(BOOL blinkLeds)
+int UsbPoll(int blinkLeds)
{
- BOOL ret = FALSE;
+ int ret = FALSE;
if(AT91C_BASE_UDP->UDP_ISR & AT91C_UDP_ENDBUSRES) {
AT91C_BASE_UDP->UDP_ICR = AT91C_UDP_ENDBUSRES;
#define __PROXMARK3_H
// Might as well have the hardware-specific defines everywhere.
-#include <at91sam7s512.h>
-#include <config_gpio.h>
+#include "at91sam7s512.h"
+#include "config_gpio.h"
#define WDT_HIT() AT91C_BASE_WDTC->WDTC_WDCR = 0xa5000001
#define SPI_FPGA_MODE 0
#define SPI_LCD_MODE 1
-typedef unsigned long DWORD;
-typedef signed long SDWORD;
-typedef unsigned long long QWORD;
-typedef int BOOL;
-typedef unsigned char BYTE;
-typedef signed char SBYTE;
-typedef unsigned short WORD;
-typedef signed short SWORD;
#define TRUE 1
#define FALSE 0
//--------------------------------
// USB declarations
-void UsbSendPacket(BYTE *packet, int len);
-BOOL UsbConnected();
-BOOL UsbPoll(BOOL blinkLeds);
+void UsbSendPacket(uint8_t *packet, int len);
+int UsbConnected();
+int UsbPoll(int blinkLeds);
void UsbStart(void);
// This function is provided by the apps/bootrom, and called from UsbPoll
// if data are available.
-void UsbPacketReceived(BYTE *packet, int len);
+void UsbPacketReceived(uint8_t *packet, int len);
#define VERSION_INFORMATION_MAGIC 0x56334d50
struct version_information {