changing {} style to match majority of previous style

This commit is contained in:
Philippe Teuwen 2019-03-10 11:20:22 +01:00
commit 961d929f4d
320 changed files with 5502 additions and 10485 deletions

View file

@ -93,7 +93,7 @@ style:
find . \( -name "*.[ch]" -or -name "*.cpp" \) -exec astyle --formatted --mode=c --suffix=none \
--indent=spaces=4 --indent-switches --indent-preprocessor \
--keep-one-line-blocks --max-instatement-indent=60 \
--style=linux --pad-oper --unpad-paren --pad-header \
--style=google --pad-oper --unpad-paren --pad-header \
--align-pointer=name {} \;
# Dummy target to test for GNU make availability

View file

@ -34,14 +34,12 @@ static uint32_t traceLen = 0;
static bool tracing = true; //todo static?
// get the address of BigBuf
uint8_t *BigBuf_get_addr(void)
{
uint8_t *BigBuf_get_addr(void) {
return (uint8_t *)BigBuf;
}
// get the address of the emulator memory. Allocate part of Bigbuf for it, if not yet done
uint8_t *BigBuf_get_EM_addr(void)
{
uint8_t *BigBuf_get_EM_addr(void) {
// not yet allocated
if (emulator_memory == NULL)
emulator_memory = BigBuf_malloc(CARD_MEMORY_SIZE);
@ -50,33 +48,28 @@ uint8_t *BigBuf_get_EM_addr(void)
}
// clear ALL of BigBuf
void BigBuf_Clear(void)
{
void BigBuf_Clear(void) {
BigBuf_Clear_ext(true);
}
// clear ALL of BigBuf
void BigBuf_Clear_ext(bool verbose)
{
void BigBuf_Clear_ext(bool verbose) {
memset(BigBuf, 0, BIGBUF_SIZE);
if (verbose)
Dbprintf("Buffer cleared (%i bytes)", BIGBUF_SIZE);
}
void BigBuf_Clear_EM(void)
{
void BigBuf_Clear_EM(void) {
memset(BigBuf_get_EM_addr(), 0, CARD_MEMORY_SIZE);
}
void BigBuf_Clear_keep_EM(void)
{
void BigBuf_Clear_keep_EM(void) {
memset(BigBuf, 0, BigBuf_hi);
}
// allocate a chunk of memory from BigBuf. We allocate high memory first. The unallocated memory
// at the beginning of BigBuf is always for traces/samples
uint8_t *BigBuf_malloc(uint16_t chunksize)
{
uint8_t *BigBuf_malloc(uint16_t chunksize) {
if (BigBuf_hi - chunksize < 0)
return NULL; // no memory left
@ -86,16 +79,14 @@ uint8_t *BigBuf_malloc(uint16_t chunksize)
}
// free ALL allocated chunks. The whole BigBuf is available for traces or samples again.
void BigBuf_free(void)
{
void BigBuf_free(void) {
BigBuf_hi = BIGBUF_SIZE;
emulator_memory = NULL;
// shouldn't this empty BigBuf also?
}
// free allocated chunks EXCEPT the emulator memory
void BigBuf_free_keep_EM(void)
{
void BigBuf_free_keep_EM(void) {
if (emulator_memory != NULL)
BigBuf_hi = emulator_memory - (uint8_t *)BigBuf;
else
@ -104,8 +95,7 @@ void BigBuf_free_keep_EM(void)
// shouldn't this empty BigBuf also?
}
void BigBuf_print_status(void)
{
void BigBuf_print_status(void) {
Dbprintf("Memory");
Dbprintf(" BIGBUF_SIZE.............%d", BIGBUF_SIZE);
Dbprintf(" Available memory........%d", BigBuf_hi);
@ -115,26 +105,21 @@ void BigBuf_print_status(void)
}
// return the maximum trace length (i.e. the unallocated size of BigBuf)
uint16_t BigBuf_max_traceLen(void)
{
uint16_t BigBuf_max_traceLen(void) {
return BigBuf_hi;
}
void clear_trace(void)
{
void clear_trace(void) {
traceLen = 0;
}
void set_tracelen(uint32_t value)
{
void set_tracelen(uint32_t value) {
traceLen = value;
}
void set_tracing(bool enable)
{
void set_tracing(bool enable) {
tracing = enable;
}
bool get_tracing(void)
{
bool get_tracing(void) {
return tracing;
}
@ -142,8 +127,7 @@ bool get_tracing(void)
* Get the number of bytes traced
* @return
*/
uint32_t BigBuf_get_traceLen(void)
{
uint32_t BigBuf_get_traceLen(void) {
return traceLen;
}
@ -153,8 +137,7 @@ uint32_t BigBuf_get_traceLen(void)
by 'hf list raw', alternatively 'hf list <proto>' for protocol-specific
annotation of commands/responses.
**/
bool RAMFUNC LogTrace(const uint8_t *btBytes, uint16_t iLen, uint32_t timestamp_start, uint32_t timestamp_end, uint8_t *parity, bool readerToTag)
{
bool RAMFUNC LogTrace(const uint8_t *btBytes, uint16_t iLen, uint32_t timestamp_start, uint32_t timestamp_end, uint8_t *parity, bool readerToTag) {
if (!tracing) return false;
uint8_t *trace = BigBuf_get_addr();
@ -212,8 +195,7 @@ bool RAMFUNC LogTrace(const uint8_t *btBytes, uint16_t iLen, uint32_t timestamp_
return true;
}
int LogTraceHitag(const uint8_t *btBytes, int iBits, int iSamples, uint32_t dwParity, int readerToTag)
{
int LogTraceHitag(const uint8_t *btBytes, int iBits, int iSamples, uint32_t dwParity, int readerToTag) {
/**
Todo, rewrite the logger to use the generic functionality instead. It should be noted, however,
that this logger takes number of bits as argument, not number of bytes.
@ -255,8 +237,7 @@ int LogTraceHitag(const uint8_t *btBytes, int iBits, int iSamples, uint32_t dwPa
}
// Emulator memory
uint8_t emlSet(uint8_t *data, uint32_t offset, uint32_t length)
{
uint8_t emlSet(uint8_t *data, uint32_t offset, uint32_t length) {
uint8_t *mem = BigBuf_get_EM_addr();
if (offset + length < CARD_MEMORY_SIZE) {
memcpy(mem + offset, data, length);

View file

@ -7,8 +7,7 @@
//-----------------------------------------------------------------------------
#include "LCD.h"
void LCDSend(unsigned int data)
{
void LCDSend(unsigned int data) {
// 9th bit set for data, clear for command
while ((AT91C_BASE_SPI->SPI_SR & AT91C_SPI_TXEMPTY) == 0); // wait for the transfer to complete
// For clarity's sake we pass data with 9th bit clear and commands with 9th
@ -16,8 +15,7 @@ void LCDSend(unsigned int data)
AT91C_BASE_SPI->SPI_TDR = data ^ 0x100; // Send the data/command
}
void LCDSetXY(unsigned char x, unsigned char y)
{
void LCDSetXY(unsigned char x, unsigned char y) {
LCDSend(PPASET); // page start/end ram
LCDSend(y); // Start Page to display to
LCDSend(131); // End Page to display to
@ -27,15 +25,13 @@ void LCDSetXY(unsigned char x, unsigned char y)
LCDSend(131); // End Column to display to
}
void LCDSetPixel(unsigned char x, unsigned char y, unsigned char color)
{
void LCDSetPixel(unsigned char x, unsigned char y, unsigned char color) {
LCDSetXY(x, y); // Set position
LCDSend(PRAMWR); // Now write the pixel to the display
LCDSend(color); // Write the data in the specified Color
}
void LCDFill(unsigned char xs, unsigned char ys, unsigned char width, unsigned char height, unsigned char color)
{
void LCDFill(unsigned char xs, unsigned char ys, unsigned char width, unsigned char height, unsigned char color) {
unsigned char i, j;
for (i = 0; i < height; i++) { // Number of horizontal lines
@ -47,8 +43,7 @@ void LCDFill(unsigned char xs, unsigned char ys, unsigned char width, unsigned c
}
}
void LCDString(char *lcd_string, const char *font_style, unsigned char x, unsigned char y, unsigned char fcolor, unsigned char bcolor)
{
void LCDString(char *lcd_string, const char *font_style, unsigned char x, unsigned char y, unsigned char fcolor, unsigned char bcolor) {
unsigned int i;
unsigned char mask = 0, px, py, xme, yme, offset;
const char *data;
@ -85,8 +80,7 @@ void LCDString(char *lcd_string, const char *font_style, unsigned char x, unsign
} while (*lcd_string != '\0'); // keep spitting chars out until end of string
}
void LCDReset(void)
{
void LCDReset(void) {
LED_A_ON();
SetupSpi(SPI_LCD_MODE);
LOW(GPIO_LRST);
@ -97,8 +91,7 @@ void LCDReset(void)
LED_A_OFF();
}
void LCDInit(void)
{
void LCDInit(void) {
int i;
LCDReset();

View file

@ -27,8 +27,7 @@ from the client to view the stored quadlets.
// Maximum number of auth attempts per standalone session
#define MAX_PWDS_PER_SESSION 64
uint8_t FindOffsetInFlash()
{
uint8_t FindOffsetInFlash() {
uint8_t mem[4] = { 0x00, 0x00, 0x00, 0x00 };
uint8_t eom[4] = { 0xFF, 0xFF, 0xFF, 0xFF };
uint8_t memcnt = 0;
@ -44,8 +43,7 @@ uint8_t FindOffsetInFlash()
return 0; // wrap-around
}
void EraseMemory()
{
void EraseMemory() {
if (!FlashInit()) {
return;
}
@ -60,8 +58,7 @@ void EraseMemory()
}
// This is actually copied from SniffIso14443a
void RAMFUNC SniffAndStore(uint8_t param)
{
void RAMFUNC SniffAndStore(uint8_t param) {
iso14443a_setup(FPGA_HF_ISO14443A_SNIFFER);
@ -284,8 +281,7 @@ void RAMFUNC SniffAndStore(uint8_t param)
}
}
void RunMod()
{
void RunMod() {
StandAloneMode();

View file

@ -59,36 +59,31 @@ void cjPrintBigArray(const char *bigar, int len, uint8_t newlines, uint8_t debug
}
*/
void cjSetCursFRight()
{
void cjSetCursFRight() {
vtsend_cursor_position(NULL, 98, (currfline));
currfline++;
}
void cjSetCursRight()
{
void cjSetCursRight() {
vtsend_cursor_position(NULL, 59, (currline));
currline++;
}
void cjSetCursLeft()
{
void cjSetCursLeft() {
vtsend_cursor_position(NULL, 0, (curlline));
curlline++;
}
void cjTabulize() { DbprintfEx(FLAG_RAWPRINT, "\t\t\t"); }
void cjPrintKey(uint64_t key, uint8_t *foundKey, uint16_t sectorNo, uint8_t type)
{
void cjPrintKey(uint64_t key, uint8_t *foundKey, uint16_t sectorNo, uint8_t type) {
char tosendkey[13];
sprintf(tosendkey, "%02x%02x%02x%02x%02x%02x", foundKey[0], foundKey[1], foundKey[2], foundKey[3], foundKey[4], foundKey[5]);
cjSetCursRight();
DbprintfEx(FLAG_NOLOG, "SEC: %02x | KEY : %s | TYP: %d", sectorNo, tosendkey, type);
}
void ReadLastTagFromFlash()
{
void ReadLastTagFromFlash() {
SpinOff(0);
LED_A_ON();
LED_B_ON();
@ -135,8 +130,7 @@ void ReadLastTagFromFlash()
return;
}
void WriteTagToFlash(uint8_t index, size_t size)
{
void WriteTagToFlash(uint8_t index, size_t size) {
SpinOff(0);
LED_A_ON();
LED_B_ON();
@ -202,8 +196,7 @@ void WriteTagToFlash(uint8_t index, size_t size)
return;
}
void RunMod()
{
void RunMod() {
StandAloneMode();
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
@ -803,8 +796,7 @@ readysim:
* - *datain used as error return
* - tracing is falsed
*/
void e_MifareECardLoad(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain)
{
void e_MifareECardLoad(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain) {
MF_DBGLEVEL = MF_DBG_NONE;
uint8_t numSectors = arg0;
@ -888,8 +880,7 @@ void e_MifareECardLoad(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *dat
/* the chk function is a piwied(tm) check that will try all keys for
a particular sector. also no tracing no dbg */
int cjat91_saMifareChkKeys(uint8_t blockNo, uint8_t keyType, bool clearTrace, uint8_t keyCount, uint8_t *datain, uint64_t *key)
{
int cjat91_saMifareChkKeys(uint8_t blockNo, uint8_t keyType, bool clearTrace, uint8_t keyCount, uint8_t *datain, uint64_t *key) {
MF_DBGLEVEL = MF_DBG_NONE;
iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);
set_tracing(false);
@ -927,8 +918,7 @@ int cjat91_saMifareChkKeys(uint8_t blockNo, uint8_t keyType, bool clearTrace, ui
return -1;
}
void saMifareMakeTag(void)
{
void saMifareMakeTag(void) {
uint8_t cfail = 0;
cjSetCursLeft();
cjTabulize();
@ -999,8 +989,7 @@ void saMifareMakeTag(void)
// Matt's StandAlone mod.
// Work with "magic Chinese" card (email him: ouyangweidaxian@live.cn)
//-----------------------------------------------------------------------------
int saMifareCSetBlock(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain)
{
int saMifareCSetBlock(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain) {
// params
uint8_t needWipe = arg0;
// bit 0 - need get UID

View file

@ -42,8 +42,7 @@ uint32_t cuid;
// Matt's StandAlone mod.
// Work with "magic Chinese" card (email him: ouyangweidaxian@live.cn)
//-----------------------------------------------------------------------------
static int saMifareCSetBlock(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain)
{
static int saMifareCSetBlock(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain) {
// params
uint8_t needWipe = arg0;
// bit 0 - need get UID
@ -155,8 +154,7 @@ static int saMifareCSetBlock(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_
/* the chk function is a piwied(tm) check that will try all keys for
a particular sector. also no tracing no dbg */
static int saMifareChkKeys(uint8_t blockNo, uint8_t keyType, bool clearTrace, uint8_t keyCount, uint8_t *datain, uint64_t *key)
{
static int saMifareChkKeys(uint8_t blockNo, uint8_t keyType, bool clearTrace, uint8_t keyCount, uint8_t *datain, uint64_t *key) {
MF_DBGLEVEL = MF_DBG_NONE;
iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);
set_tracing(false);
@ -194,8 +192,7 @@ static int saMifareChkKeys(uint8_t blockNo, uint8_t keyType, bool clearTrace, ui
}
void RunMod()
{
void RunMod() {
StandAloneMode();
Dbprintf(">> Matty mifare chk/dump/sim a.k.a MattyRun Started <<");
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);

View file

@ -18,8 +18,7 @@ typedef struct {
} __attribute__((__packed__)) card_clone_t;
void RunMod()
{
void RunMod() {
StandAloneMode();
Dbprintf(">> Craig Young Mifare sniff UID/clone uid 2 magic/sim a.k.a YoungRun Started <<");
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);

View file

@ -27,8 +27,7 @@
#include "lf_hidbrute.h"
// samy's sniff and repeat routine for LF
void RunMod()
{
void RunMod() {
StandAloneMode();
Dbprintf(">> LF HID corporate bruteforce a.k.a CorporateBrute Started <<");
FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
@ -245,8 +244,7 @@ out:
}
// Function that calculate next value for the brutforce of HID corporate 1000
void hid_corporate_1000_calculate_checksum_and_set(uint32_t *high, uint32_t *low, uint32_t cardnum, uint32_t fc)
{
void hid_corporate_1000_calculate_checksum_and_set(uint32_t *high, uint32_t *low, uint32_t cardnum, uint32_t fc) {
uint32_t new_high = 0;
uint32_t new_low = 0;

View file

@ -12,8 +12,7 @@
#include "lf_proxbrute.h"
// samy's sniff and repeat routine for LF
void RunMod()
{
void RunMod() {
StandAloneMode();
Dbprintf(">> LF HID proxII bruteforce a.k.a ProxBrute Started (Brad Antoniewicz) <<");
FpgaDownloadAndGo(FPGA_BITSTREAM_LF);

View file

@ -11,8 +11,7 @@
#include "lf_samyrun.h"
// samy's sniff and repeat routine for LF
void RunMod()
{
void RunMod() {
StandAloneMode();
Dbprintf(">> LF HID Read/Clone/Sim a.k.a SamyRun Started <<");
FpgaDownloadAndGo(FPGA_BITSTREAM_LF);

View file

@ -680,8 +680,7 @@ static const unsigned int rcon[] = {
* Expand the cipher key into the encryption key schedule and return the
* number of rounds for the given cipher key size.
*/
int aes_setkey_enc(unsigned int rk[], const unsigned char cipherKey[], int keyBytes)
{
int aes_setkey_enc(unsigned int rk[], const unsigned char cipherKey[], int keyBytes) {
int i = 0;
unsigned int temp;
@ -766,8 +765,7 @@ int aes_setkey_enc(unsigned int rk[], const unsigned char cipherKey[], int keyBy
* Expand the cipher key into encryption and decryption key schedule and
* return the number of rounds for the given cipher key size.
*/
int AesGenKeySched(unsigned int rk[], unsigned int rrk[], const unsigned char cipherKey[], int keyBytes)
{
int AesGenKeySched(unsigned int rk[], unsigned int rrk[], const unsigned char cipherKey[], int keyBytes) {
int Nr, i;
// expand the cipher key
@ -821,8 +819,7 @@ int AesGenKeySched(unsigned int rk[], unsigned int rrk[], const unsigned char ci
/*
* Encrypt the plain text into cipher
*/
void AesEncBlk(AesCtx *pCtx, const unsigned char pt[], unsigned char ct[])
{
void AesEncBlk(AesCtx *pCtx, const unsigned char pt[], unsigned char ct[]) {
unsigned int s0, s1, s2, s3, t0, t1, t2, t3, *iv;
const unsigned int *rk;
int r;
@ -947,8 +944,7 @@ void AesEncBlk(AesCtx *pCtx, const unsigned char pt[], unsigned char ct[])
/*
* Decrypt the cipher into plain text
*/
void AesDecBlk(AesCtx *pCtx, const unsigned char ct[], unsigned char pt[])
{
void AesDecBlk(AesCtx *pCtx, const unsigned char ct[], unsigned char pt[]) {
unsigned int s0, s1, s2, s3, t0, t1, t2, t3, v0, v1, v2, v3, *iv;
const unsigned int *rk;
int r;
@ -1080,8 +1076,7 @@ void AesDecBlk(AesCtx *pCtx, const unsigned char ct[], unsigned char pt[])
/*
* initialize AES context
*/
int AesCtxIni(AesCtx *pCtx, unsigned char *pIV, unsigned char *pKey, unsigned int KeyLen, unsigned char Mode)
{
int AesCtxIni(AesCtx *pCtx, unsigned char *pIV, unsigned char *pKey, unsigned int KeyLen, unsigned char Mode) {
if (pKey == 0 || pCtx == 0 || (KeyLen != KEY128 && KeyLen != KEY192 && KeyLen != KEY256))
return -1;
@ -1105,8 +1100,7 @@ int AesCtxIni(AesCtx *pCtx, unsigned char *pIV, unsigned char *pKey, unsigned in
/*
* Encrypt plain text
*/
int AesEncrypt(AesCtx *pCtx, unsigned char *pData, unsigned char *pCipher, unsigned int DataLen)
{
int AesEncrypt(AesCtx *pCtx, unsigned char *pData, unsigned char *pCipher, unsigned int DataLen) {
int i;
if (pData == 0 || pCipher == 0 || pCtx == 0 || (DataLen & 0xf) != 0)
@ -1124,8 +1118,7 @@ int AesEncrypt(AesCtx *pCtx, unsigned char *pData, unsigned char *pCipher, unsig
/*
* Decrypt cipher
*/
int AesDecrypt(AesCtx *pCtx, unsigned char *pCipher, unsigned char *pData, unsigned int CipherLen)
{
int AesDecrypt(AesCtx *pCtx, unsigned char *pCipher, unsigned char *pData, unsigned int CipherLen) {
int i;
if (pData == 0 || pCipher == 0 || pCtx == 0 || (CipherLen & 0xf) != 0)
@ -1148,8 +1141,7 @@ int AesDecrypt(AesCtx *pCtx, unsigned char *pCipher, unsigned char *pData, unsig
#include <stdio.h>
int main()
{
int main() {
AesCtx ctx;
unsigned char iv[] = "INI VECTINI VECT";
unsigned char key[] = "This is a sample AESKey";

View file

@ -54,14 +54,12 @@ int ToSendMax = -1;
static int ToSendBit;
struct common_area common_area __attribute__((section(".commonarea")));
void ToSendReset(void)
{
void ToSendReset(void) {
ToSendMax = -1;
ToSendBit = 8;
}
void ToSendStuffBit(int b)
{
void ToSendStuffBit(int b) {
if (ToSendBit >= 8) {
ToSendMax++;
ToSend[ToSendMax] = 0;
@ -79,14 +77,12 @@ void ToSendStuffBit(int b)
}
}
void PrintToSendBuffer(void)
{
void PrintToSendBuffer(void) {
DbpString("Printing ToSendBuffer:");
Dbhexdump(ToSendMax, ToSend, 0);
}
void print_result(char *name, uint8_t *buf, size_t len)
{
void print_result(char *name, uint8_t *buf, size_t len) {
uint8_t *p = buf;
uint16_t tmp = len & 0xFFF0;
@ -114,29 +110,25 @@ void print_result(char *name, uint8_t *buf, size_t len)
// Debug print functions, to go out over USB, to the usual PC-side client.
//=============================================================================
void DbpStringEx(char *str, uint32_t cmd)
{
void DbpStringEx(char *str, uint32_t cmd) {
#if DEBUG
uint8_t len = strlen(str);
cmd_send(CMD_DEBUG_PRINT_STRING, len, cmd, 0, (uint8_t *)str, len);
#endif
}
void DbpString(char *str)
{
void DbpString(char *str) {
#if DEBUG
DbpStringEx(str, 0);
#endif
}
#if 0
void DbpIntegers(int x1, int x2, int x3)
{
void DbpIntegers(int x1, int x2, int x3) {
cmd_send(CMD_DEBUG_PRINT_INTEGERS, x1, x2, x3, 0, 0);
}
#endif
void DbprintfEx(uint32_t cmd, const char *fmt, ...)
{
void DbprintfEx(uint32_t cmd, const char *fmt, ...) {
#if DEBUG
// should probably limit size here; oh well, let's just use a big buffer
char output_string[128] = {0x00};
@ -149,8 +141,7 @@ void DbprintfEx(uint32_t cmd, const char *fmt, ...)
#endif
}
void Dbprintf(const char *fmt, ...)
{
void Dbprintf(const char *fmt, ...) {
#if DEBUG
// should probably limit size here; oh well, let's just use a big buffer
char output_string[128] = {0x00};
@ -165,8 +156,7 @@ void Dbprintf(const char *fmt, ...)
}
// prints HEX & ASCII
void Dbhexdump(int len, uint8_t *d, bool bAsci)
{
void Dbhexdump(int len, uint8_t *d, bool bAsci) {
#if DEBUG
int l = 0, i;
char ascii[9];
@ -201,8 +191,7 @@ void Dbhexdump(int len, uint8_t *d, bool bAsci)
// in ADC units (0 to 1023). Also a routine to average 32 samples and
// return that.
//-----------------------------------------------------------------------------
static uint16_t ReadAdc(int ch)
{
static uint16_t ReadAdc(int ch) {
// Note: ADC_MODE_PRESCALE and ADC_MODE_SAMPLE_HOLD_TIME are set to the maximum allowed value.
// AMPL_HI is are high impedance (10MOhm || 1MOhm) output, the input capacitance of the ADC is 12pF (typical). This results in a time constant
@ -228,8 +217,7 @@ static uint16_t ReadAdc(int ch)
}
// was static - merlok
uint16_t AvgAdc(int ch)
{
uint16_t AvgAdc(int ch) {
uint16_t a = 0;
for (uint8_t i = 0; i < 32; i++)
a += ReadAdc(ch);
@ -238,8 +226,7 @@ uint16_t AvgAdc(int ch)
return (a + 15) >> 5;
}
void MeasureAntennaTuning(void)
{
void MeasureAntennaTuning(void) {
uint8_t LF_Results[256];
uint32_t i, adcval = 0, peak = 0, peakv = 0, peakf = 0;
@ -304,8 +291,7 @@ void MeasureAntennaTuning(void)
LEDsoff();
}
void MeasureAntennaTuningHf(void)
{
void MeasureAntennaTuningHf(void) {
uint16_t volt = 0; // in mV
// Let the FPGA drive the high-frequency antenna around 13.56 MHz.
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
@ -327,8 +313,7 @@ void MeasureAntennaTuningHf(void)
DbprintfEx(FLAG_NOOPT, "\n[+] cancelled", 1);
}
void ReadMem(int addr)
{
void ReadMem(int 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]);
@ -338,8 +323,7 @@ void ReadMem(int addr)
extern struct version_information version_information;
/* bootrom version information is pointed to from _bootphase1_version_pointer */
extern char *_bootphase1_version_pointer, _flash_start, _flash_end, _bootrom_start, _bootrom_end, __data_src_start__;
void SendVersion(void)
{
void SendVersion(void) {
char temp[USB_CMD_DATA_SIZE]; /* Limited data payload in USB packets */
char VersionString[USB_CMD_DATA_SIZE] = { '\0' };
@ -377,8 +361,7 @@ void SendVersion(void)
// measure the USB Speed by sending SpeedTestBufferSize bytes to client and measuring the elapsed time.
// Note: this mimics GetFromBigbuf(), i.e. we have the overhead of the UsbCommand structure included.
void printUSBSpeed(void)
{
void printUSBSpeed(void) {
Dbprintf("USB Speed");
Dbprintf(" Sending USB packets to client...");
@ -405,8 +388,7 @@ void printUSBSpeed(void)
/**
* Prints runtime information about the PM3.
**/
void SendStatus(void)
{
void SendStatus(void) {
BigBuf_print_status();
Fpga_print_status();
#ifdef WITH_FLASH
@ -430,8 +412,7 @@ void SendStatus(void)
}
// Show some leds in a pattern to identify StandAlone mod is running
void StandAloneMode(void)
{
void StandAloneMode(void) {
DbpString("Stand-alone mode! No PC necessary.");
@ -444,8 +425,7 @@ void StandAloneMode(void)
}
// detection of which Standalone Modes is installed
// (iceman)
void printStandAloneModes(void)
{
void printStandAloneModes(void) {
DbpString("Installed StandAlone Mode");
@ -523,8 +503,7 @@ static const char LIGHT_SCHEME[] = {
};
static const int LIGHT_LEN = sizeof(LIGHT_SCHEME) / sizeof(LIGHT_SCHEME[0]);
void ListenReaderField(int limit)
{
void ListenReaderField(int limit) {
#define LF_ONLY 1
#define HF_ONLY 2
#define REPORT_CHANGE 10 // report new values only if they have changed at least by REPORT_CHANGE
@ -650,8 +629,7 @@ void ListenReaderField(int limit)
}
}
void UsbPacketReceived(uint8_t *packet, int len)
{
void UsbPacketReceived(uint8_t *packet, int len) {
UsbCommand *c = (UsbCommand *)packet;
//Dbprintf("received %d bytes, with command: 0x%04x and args: %d %d %d", len, c->cmd, c->arg[0], c->arg[1], c->arg[2]);
@ -1509,8 +1487,7 @@ void UsbPacketReceived(uint8_t *packet, int len)
}
}
void __attribute__((noreturn)) AppMain(void)
{
void __attribute__((noreturn)) AppMain(void) {
SpinDelay(100);
clear_trace();

View file

@ -1,27 +1,23 @@
#include "buzzer.h"
void Ring_BEE_ONCE(uint16_t music_note)
{
void Ring_BEE_ONCE(uint16_t music_note) {
BEE_ON();
SpinDelayUs(music_note);
BEE_OFF();
SpinDelayUs(music_note);
}
void ring_2_7khz(uint16_t count)
{
void ring_2_7khz(uint16_t count) {
Ring_BEE_TIME(n_2_7khz, count);
}
void Ring_BEE_TIME(uint16_t music_note, uint16_t count)
{
void Ring_BEE_TIME(uint16_t music_note, uint16_t count) {
for (uint16_t i = 0 ; i < count; i++)
Ring_BEE_ONCE(music_note);
SpinDelay(9);
}
void Ring_ALL(uint16_t count)
{
void Ring_ALL(uint16_t count) {
Ring_BEE_TIME(note_1, count);
Ring_BEE_TIME(note_2, count);
Ring_BEE_TIME(note_3, count);
@ -32,8 +28,7 @@ void Ring_ALL(uint16_t count)
SpinDelay(10);
}
void Ring_Little_Star(uint16_t count)
{
void Ring_Little_Star(uint16_t count) {
Ring_BEE_TIME(note_1, count);
Ring_BEE_TIME(note_1, count);
Ring_BEE_TIME(note_5, count);

View file

@ -202,8 +202,7 @@ const uint8_t shiftkeyinv_permtab[] = {
#define ROTTABLE_INV 0x3F7E
/******************************************************************************/
void permute(const uint8_t *ptable, const uint8_t *in, uint8_t *out)
{
void permute(const uint8_t *ptable, const uint8_t *in, uint8_t *out) {
uint8_t ob; /* in-bytes and out-bytes */
uint8_t byte, bit; /* counter for bit and byte */
ob = ptable[1];
@ -223,8 +222,7 @@ void permute(const uint8_t *ptable, const uint8_t *in, uint8_t *out)
/******************************************************************************/
void changeendian32(uint32_t *a)
{
void changeendian32(uint32_t *a) {
*a = (*a & 0x000000FF) << 24 |
(*a & 0x0000FF00) << 8 |
(*a & 0x00FF0000) >> 8 |
@ -233,8 +231,7 @@ void changeendian32(uint32_t *a)
/******************************************************************************/
static inline
void shiftkey(uint8_t *key)
{
void shiftkey(uint8_t *key) {
uint8_t k[7];
memcpy(k, key, 7);
permute((uint8_t *)shiftkey_permtab, k, key);
@ -242,8 +239,7 @@ void shiftkey(uint8_t *key)
/******************************************************************************/
static inline
void shiftkey_inv(uint8_t *key)
{
void shiftkey_inv(uint8_t *key) {
uint8_t k[7];
memcpy(k, key, 7);
permute((uint8_t *)shiftkeyinv_permtab, k, key);
@ -252,8 +248,7 @@ void shiftkey_inv(uint8_t *key)
/******************************************************************************/
static inline
uint64_t splitin6bitwords(uint64_t a)
{
uint64_t splitin6bitwords(uint64_t a) {
uint64_t ret = 0;
a &= 0x0000ffffffffffffLL;
permute((uint8_t *)splitin6bitword_permtab, (uint8_t *)&a, (uint8_t *)&ret);
@ -263,8 +258,7 @@ uint64_t splitin6bitwords(uint64_t a)
/******************************************************************************/
static inline
uint8_t substitute(uint8_t a, uint8_t *sbp)
{
uint8_t substitute(uint8_t a, uint8_t *sbp) {
uint8_t x;
x = sbp[a >> 1];
x = (a & 1) ? x & 0x0F : x >> 4;
@ -274,8 +268,7 @@ uint8_t substitute(uint8_t a, uint8_t *sbp)
/******************************************************************************/
uint32_t des_f(uint32_t r, uint8_t *kr)
{
uint32_t des_f(uint32_t r, uint8_t *kr) {
uint8_t i;
uint32_t t = 0, ret;
uint64_t data;
@ -312,8 +305,7 @@ typedef struct {
#define R (data.d.v32[1])
#define L (data.d.v32[0])
void des_enc(void *out, const void *in, const void *key)
{
void des_enc(void *out, const void *in, const void *key) {
uint8_t kr[6], k[7];
uint8_t i;
@ -346,8 +338,7 @@ void des_enc(void *out, const void *in, const void *key)
/******************************************************************************/
void des_dec(void *out, const void *in, const uint8_t *key)
{
void des_dec(void *out, const void *in, const uint8_t *key) {
uint8_t kr[6], k[7];
int8_t i;
@ -382,8 +373,7 @@ void des_dec(void *out, const void *in, const uint8_t *key)
/******************************************************************************/
void tdes_enc(void *out, void *in, const void *key)
{
void tdes_enc(void *out, void *in, const void *key) {
des_enc(out, in, (uint8_t *)key + 0);
des_dec(out, out, (uint8_t *)key + 8);
des_enc(out, out, (uint8_t *)key + 16);
@ -391,15 +381,13 @@ void tdes_enc(void *out, void *in, const void *key)
/******************************************************************************/
void tdes_dec(void *out, void *in, const uint8_t *key)
{
void tdes_dec(void *out, void *in, const uint8_t *key) {
des_dec(out, in, (uint8_t *)key + 16);
des_enc(out, out, (uint8_t *)key + 8);
des_dec(out, out, (uint8_t *)key + 0);
}
void tdes_2key_enc(void *out, const void *in, size_t length, const void *key, unsigned char iv[8])
{
void tdes_2key_enc(void *out, const void *in, size_t length, const void *key, unsigned char iv[8]) {
if (length % 8) return;
@ -423,8 +411,7 @@ void tdes_2key_enc(void *out, const void *in, size_t length, const void *key, un
}
}
void tdes_2key_dec(void *out, const void *in, size_t length, const void *key, unsigned char iv[8])
{
void tdes_2key_dec(void *out, const void *in, size_t length, const void *key, unsigned char iv[8]) {
if (length % 8) return;

View file

@ -31,15 +31,13 @@ static void xor(const uint8_t *ivect, uint8_t *data, const size_t len);
static size_t key_macing_length(desfirekey_t key);
// iceman, see memxor inside string.c, dest/src swapped..
static void xor(const uint8_t *ivect, uint8_t *data, const size_t len)
{
static void xor(const uint8_t *ivect, uint8_t *data, const size_t len) {
for (size_t i = 0; i < len; i++) {
data[i] ^= ivect[i];
}
}
void cmac_generate_subkeys(desfirekey_t key)
{
void cmac_generate_subkeys(desfirekey_t key) {
int kbs = key_block_size(key);
const uint8_t R = (kbs == 8) ? 0x1B : 0x87;
@ -68,8 +66,7 @@ void cmac_generate_subkeys(desfirekey_t key)
key->cmac_sk2[kbs - 1] ^= R;
}
void cmac(const desfirekey_t key, uint8_t *ivect, const uint8_t *data, size_t len, uint8_t *cmac)
{
void cmac(const desfirekey_t key, uint8_t *ivect, const uint8_t *data, size_t len, uint8_t *cmac) {
int kbs = key_block_size(key);
uint8_t *buffer = malloc(padded_data_length(len, kbs));
@ -91,8 +88,7 @@ void cmac(const desfirekey_t key, uint8_t *ivect, const uint8_t *data, size_t le
free(buffer);
}
size_t key_block_size(const desfirekey_t key)
{
size_t key_block_size(const desfirekey_t key) {
size_t block_size = 8;
switch (key->type) {
case T_DES:
@ -110,8 +106,7 @@ size_t key_block_size(const desfirekey_t key)
/*
* Size of MACing produced with the key.
*/
static size_t key_macing_length(const desfirekey_t key)
{
static size_t key_macing_length(const desfirekey_t key) {
size_t mac_length = MAC_LENGTH;
switch (key->type) {
case T_DES:
@ -129,8 +124,7 @@ static size_t key_macing_length(const desfirekey_t key)
/*
* Size required to store nbytes of data in a buffer of size n*block_size.
*/
size_t padded_data_length(const size_t nbytes, const size_t block_size)
{
size_t padded_data_length(const size_t nbytes, const size_t block_size) {
if ((!nbytes) || (nbytes % block_size))
return ((nbytes / block_size) + 1) * block_size;
else
@ -140,15 +134,13 @@ size_t padded_data_length(const size_t nbytes, const size_t block_size)
/*
* Buffer size required to MAC nbytes of data
*/
size_t maced_data_length(const desfirekey_t key, const size_t nbytes)
{
size_t maced_data_length(const desfirekey_t key, const size_t nbytes) {
return nbytes + key_macing_length(key);
}
/*
* Buffer size required to encipher nbytes of data and a two bytes CRC.
*/
size_t enciphered_data_length(const desfiretag_t tag, const size_t nbytes, int communication_settings)
{
size_t enciphered_data_length(const desfiretag_t tag, const size_t nbytes, int communication_settings) {
size_t crc_length = 0;
if (!(communication_settings & NO_CRC)) {
switch (DESFIRE(tag)->authentication_scheme) {
@ -166,8 +158,7 @@ size_t enciphered_data_length(const desfiretag_t tag, const size_t nbytes, int c
return padded_data_length(nbytes + crc_length, block_size);
}
void *mifare_cryto_preprocess_data(desfiretag_t tag, void *data, size_t *nbytes, size_t offset, int communication_settings)
{
void *mifare_cryto_preprocess_data(desfiretag_t tag, void *data, size_t *nbytes, size_t offset, int communication_settings) {
uint8_t *res = data;
uint8_t mac[4];
size_t edl;
@ -295,8 +286,7 @@ void *mifare_cryto_preprocess_data(desfiretag_t tag, void *data, size_t *nbytes,
}
void *mifare_cryto_postprocess_data(desfiretag_t tag, void *data, size_t *nbytes, int communication_settings)
{
void *mifare_cryto_postprocess_data(desfiretag_t tag, void *data, size_t *nbytes, int communication_settings) {
void *res = data;
size_t edl;
void *edata = NULL;
@ -521,8 +511,7 @@ void *mifare_cryto_postprocess_data(desfiretag_t tag, void *data, size_t *nbytes
}
void mifare_cypher_single_block(desfirekey_t key, uint8_t *data, uint8_t *ivect, MifareCryptoDirection direction, MifareCryptoOperation operation, size_t block_size)
{
void mifare_cypher_single_block(desfirekey_t key, uint8_t *data, uint8_t *ivect, MifareCryptoDirection direction, MifareCryptoOperation operation, size_t block_size) {
uint8_t ovect[MAX_CRYPTO_BLOCK_SIZE];
if (direction == MCD_SEND) {
@ -616,8 +605,7 @@ void mifare_cypher_single_block(desfirekey_t key, uint8_t *data, uint8_t *ivect,
* Because the tag may contain additional data, one may need to call this
* function with tag, key and ivect defined.
*/
void mifare_cypher_blocks_chained(desfiretag_t tag, desfirekey_t key, uint8_t *ivect, uint8_t *data, size_t data_size, MifareCryptoDirection direction, MifareCryptoOperation operation)
{
void mifare_cypher_blocks_chained(desfiretag_t tag, desfirekey_t key, uint8_t *ivect, uint8_t *data, size_t data_size, MifareCryptoDirection direction, MifareCryptoOperation operation) {
size_t block_size;
if (tag) {

View file

@ -21,8 +21,7 @@
static inline void update_key_schedules(desfirekey_t key);
static inline void update_key_schedules(desfirekey_t key)
{
static inline void update_key_schedules(desfirekey_t key) {
// DES_set_key ((DES_cblock *)key->data, &(key->ks1));
// DES_set_key ((DES_cblock *)(key->data + 8), &(key->ks2));
// if (T_3K3DES == key->type) {
@ -30,8 +29,7 @@ static inline void update_key_schedules(desfirekey_t key)
// }
}
void Desfire_des_key_new(const uint8_t value[8], desfirekey_t key)
{
void Desfire_des_key_new(const uint8_t value[8], desfirekey_t key) {
uint8_t data[8];
memcpy(data, value, 8);
for (int n = 0; n < 8; n++)
@ -39,8 +37,7 @@ void Desfire_des_key_new(const uint8_t value[8], desfirekey_t key)
Desfire_des_key_new_with_version(data, key);
}
void Desfire_des_key_new_with_version(const uint8_t value[8], desfirekey_t key)
{
void Desfire_des_key_new_with_version(const uint8_t value[8], desfirekey_t key) {
if (key != NULL) {
key->type = T_DES;
memcpy(key->data, value, 8);
@ -49,8 +46,7 @@ void Desfire_des_key_new_with_version(const uint8_t value[8], desfirekey_t key)
}
}
void Desfire_3des_key_new(const uint8_t value[16], desfirekey_t key)
{
void Desfire_3des_key_new(const uint8_t value[16], desfirekey_t key) {
uint8_t data[16];
memcpy(data, value, 16);
for (int n = 0; n < 8; n++)
@ -60,8 +56,7 @@ void Desfire_3des_key_new(const uint8_t value[16], desfirekey_t key)
Desfire_3des_key_new_with_version(data, key);
}
void Desfire_3des_key_new_with_version(const uint8_t value[16], desfirekey_t key)
{
void Desfire_3des_key_new_with_version(const uint8_t value[16], desfirekey_t key) {
if (key != NULL) {
key->type = T_3DES;
memcpy(key->data, value, 16);
@ -70,8 +65,7 @@ void Desfire_3des_key_new_with_version(const uint8_t value[16], desfirekey_t key
}
}
void Desfire_3k3des_key_new(const uint8_t value[24], desfirekey_t key)
{
void Desfire_3k3des_key_new(const uint8_t value[24], desfirekey_t key) {
uint8_t data[24];
memcpy(data, value, 24);
for (int n = 0; n < 8; n++)
@ -79,8 +73,7 @@ void Desfire_3k3des_key_new(const uint8_t value[24], desfirekey_t key)
Desfire_3k3des_key_new_with_version(data, key);
}
void Desfire_3k3des_key_new_with_version(const uint8_t value[24], desfirekey_t key)
{
void Desfire_3k3des_key_new_with_version(const uint8_t value[24], desfirekey_t key) {
if (key != NULL) {
key->type = T_3K3DES;
memcpy(key->data, value, 24);
@ -88,13 +81,11 @@ void Desfire_3k3des_key_new_with_version(const uint8_t value[24], desfirekey_t k
}
}
void Desfire_aes_key_new(const uint8_t value[16], desfirekey_t key)
{
void Desfire_aes_key_new(const uint8_t value[16], desfirekey_t key) {
Desfire_aes_key_new_with_version(value, 0, key);
}
void Desfire_aes_key_new_with_version(const uint8_t value[16], uint8_t version, desfirekey_t key)
{
void Desfire_aes_key_new_with_version(const uint8_t value[16], uint8_t version, desfirekey_t key) {
if (key != NULL) {
memcpy(key->data, value, 16);
@ -103,8 +94,7 @@ void Desfire_aes_key_new_with_version(const uint8_t value[16], uint8_t version,
}
}
uint8_t Desfire_key_get_version(desfirekey_t key)
{
uint8_t Desfire_key_get_version(desfirekey_t key) {
uint8_t version = 0;
for (int n = 0; n < 8; n++) {
@ -113,8 +103,7 @@ uint8_t Desfire_key_get_version(desfirekey_t key)
return version;
}
void Desfire_key_set_version(desfirekey_t key, uint8_t version)
{
void Desfire_key_set_version(desfirekey_t key, uint8_t version) {
for (int n = 0; n < 8; n++) {
uint8_t version_bit = ((version & (1 << (7 - n))) >> (7 - n));
key->data[n] &= 0xfe;
@ -129,8 +118,7 @@ void Desfire_key_set_version(desfirekey_t key, uint8_t version)
}
}
void Desfire_session_key_new(const uint8_t rnda[], const uint8_t rndb[], desfirekey_t authkey, desfirekey_t key)
{
void Desfire_session_key_new(const uint8_t rnda[], const uint8_t rndb[], desfirekey_t authkey, desfirekey_t key) {
uint8_t buffer[24];

View file

@ -103,8 +103,7 @@ static char iso_type = 0;
//-----------------------------------------------------------------------------
// Wrapper for sending APDUs to type A and B cards
//-----------------------------------------------------------------------------
int EPA_APDU(uint8_t *apdu, size_t length, uint8_t *response)
{
int EPA_APDU(uint8_t *apdu, size_t length, uint8_t *response) {
switch (iso_type) {
case 'a':
return iso14_apdu(apdu, (uint16_t) length, false, response, NULL);
@ -121,8 +120,7 @@ int EPA_APDU(uint8_t *apdu, size_t length, uint8_t *response)
//-----------------------------------------------------------------------------
// Closes the communication channel and turns off the field
//-----------------------------------------------------------------------------
void EPA_Finish()
{
void EPA_Finish() {
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
LEDsoff();
iso_type = 0;
@ -143,8 +141,7 @@ void EPA_Finish()
//-----------------------------------------------------------------------------
size_t EPA_Parse_CardAccess(uint8_t *data,
size_t length,
pace_version_info_t *pace_info)
{
pace_version_info_t *pace_info) {
size_t index = 0;
while (index <= length - 2) {
@ -162,10 +159,10 @@ size_t EPA_Parse_CardAccess(uint8_t *data,
else if (data[index] == 0x06) {
// is this a PACE OID?
if (data[index + 1] == 0x0A // length matches
&& memcmp(data + index + 2,
oid_pace_start,
sizeof(oid_pace_start)) == 0 // content matches
&& pace_info != NULL) {
&& memcmp(data + index + 2,
oid_pace_start,
sizeof(oid_pace_start)) == 0 // content matches
&& pace_info != NULL) {
// first, clear the pace_info struct
memset(pace_info, 0, sizeof(pace_version_info_t));
memcpy(pace_info->oid, data + index + 2, sizeof(pace_info->oid));
@ -210,8 +207,7 @@ size_t EPA_Parse_CardAccess(uint8_t *data,
// Returns -1 on failure or the length of the data on success
// TODO: for the moment this sends only 1 APDU regardless of the requested length
//-----------------------------------------------------------------------------
int EPA_Read_CardAccess(uint8_t *buffer, size_t max_length)
{
int EPA_Read_CardAccess(uint8_t *buffer, size_t max_length) {
// the response APDU of the card
// since the card doesn't always care for the expected length we send it,
// we reserve 262 bytes here just to be safe (256-byte APDU + SW + ISO frame)
@ -223,8 +219,8 @@ int EPA_Read_CardAccess(uint8_t *buffer, size_t max_length)
sizeof(apdu_select_binary_cardaccess),
response_apdu);
if (rapdu_length < 6
|| response_apdu[rapdu_length - 4] != 0x90
|| response_apdu[rapdu_length - 3] != 0x00) {
|| response_apdu[rapdu_length - 4] != 0x90
|| response_apdu[rapdu_length - 3] != 0x00) {
DbpString("Failed to select EF.CardAccess!");
return -1;
}
@ -234,8 +230,8 @@ int EPA_Read_CardAccess(uint8_t *buffer, size_t max_length)
sizeof(apdu_read_binary),
response_apdu);
if (rapdu_length <= 6
|| response_apdu[rapdu_length - 4] != 0x90
|| response_apdu[rapdu_length - 3] != 0x00) {
|| response_apdu[rapdu_length - 4] != 0x90
|| response_apdu[rapdu_length - 3] != 0x00) {
Dbprintf("Failed to read EF.CardAccess!");
return -1;
}
@ -252,8 +248,7 @@ int EPA_Read_CardAccess(uint8_t *buffer, size_t max_length)
// Abort helper function for EPA_PACE_Collect_Nonce
// sets relevant data in ack, sends the response
//-----------------------------------------------------------------------------
static void EPA_PACE_Collect_Nonce_Abort(uint8_t step, int func_return)
{
static void EPA_PACE_Collect_Nonce_Abort(uint8_t step, int func_return) {
// power down the field
EPA_Finish();
@ -264,8 +259,7 @@ static void EPA_PACE_Collect_Nonce_Abort(uint8_t step, int func_return)
//-----------------------------------------------------------------------------
// Acquire one encrypted PACE nonce
//-----------------------------------------------------------------------------
void EPA_PACE_Collect_Nonce(UsbCommand *c)
{
void EPA_PACE_Collect_Nonce(UsbCommand *c) {
/*
* ack layout:
* arg:
@ -337,8 +331,7 @@ void EPA_PACE_Collect_Nonce(UsbCommand *c)
// Returns the actual size of the nonce on success or a less-than-zero error
// code on failure.
//-----------------------------------------------------------------------------
int EPA_PACE_Get_Nonce(uint8_t requested_length, uint8_t *nonce)
{
int EPA_PACE_Get_Nonce(uint8_t requested_length, uint8_t *nonce) {
// build the APDU
uint8_t apdu[sizeof(apdu_general_authenticate_pace_get_nonce) + 1];
// copy the constant part
@ -355,8 +348,8 @@ int EPA_PACE_Get_Nonce(uint8_t requested_length, uint8_t *nonce)
response_apdu);
// check if the command succeeded
if (send_return < 6
|| response_apdu[send_return - 4] != 0x90
|| response_apdu[send_return - 3] != 0x00) {
|| response_apdu[send_return - 4] != 0x90
|| response_apdu[send_return - 3] != 0x00) {
return -1;
}
@ -380,8 +373,7 @@ int EPA_PACE_Get_Nonce(uint8_t requested_length, uint8_t *nonce)
// Initializes the PACE protocol by performing the "MSE: Set AT" step
// Returns 0 on success or a non-zero error code on failure
//-----------------------------------------------------------------------------
int EPA_PACE_MSE_Set_AT(pace_version_info_t pace_version_info, uint8_t password)
{
int EPA_PACE_MSE_Set_AT(pace_version_info_t pace_version_info, uint8_t password) {
// create the MSE: Set AT APDU
uint8_t apdu[23];
// the minimum length (will be increased as more data is added)
@ -423,8 +415,8 @@ int EPA_PACE_MSE_Set_AT(pace_version_info_t pace_version_info, uint8_t password)
response_apdu);
// check if the command succeeded
if (send_return != 6
|| response_apdu[send_return - 4] != 0x90
|| response_apdu[send_return - 3] != 0x00) {
|| response_apdu[send_return - 4] != 0x90
|| response_apdu[send_return - 3] != 0x00) {
return 1;
}
return 0;
@ -433,8 +425,7 @@ int EPA_PACE_MSE_Set_AT(pace_version_info_t pace_version_info, uint8_t password)
//-----------------------------------------------------------------------------
// Perform the PACE protocol by replaying given APDUs
//-----------------------------------------------------------------------------
void EPA_PACE_Replay(UsbCommand *c)
{
void EPA_PACE_Replay(UsbCommand *c) {
uint32_t timings[sizeof(apdu_lengths_replay) / sizeof(apdu_lengths_replay[0])] = {0};
// if an APDU has been passed, save it
@ -482,9 +473,9 @@ void EPA_PACE_Replay(UsbCommand *c)
timings[i] = GetCountUS();
// every step but the last one should succeed
if (i < sizeof(apdu_lengths_replay) - 1
&& (func_return < 6
|| response_apdu[func_return - 4] != 0x90
|| response_apdu[func_return - 3] != 0x00)) {
&& (func_return < 6
|| response_apdu[func_return - 4] != 0x90
|| response_apdu[func_return - 3] != 0x00)) {
EPA_Finish();
cmd_send(CMD_ACK, 3 + i, func_return, 0, timings, 20);
return;
@ -499,8 +490,7 @@ void EPA_PACE_Replay(UsbCommand *c)
// Set up a communication channel (Card Select, PPS)
// Returns 0 on success or a non-zero error code on failure
//-----------------------------------------------------------------------------
int EPA_Setup()
{
int EPA_Setup() {
int return_code = 0;
uint8_t uid[10];
uint8_t pps_response[3];

View file

@ -34,13 +34,11 @@ static uint8_t felica_select_card(felica_card_select_t *card);
static void TransmitFor18092_AsReader(uint8_t *frame, int len, uint32_t *timing, uint8_t power, uint8_t highspeed);
bool WaitForFelicaReply(uint16_t maxbytes);
void iso18092_set_timeout(uint32_t timeout)
{
void iso18092_set_timeout(uint32_t timeout) {
felica_timeout = timeout + (DELAY_AIR2ARM_AS_READER + DELAY_ARM2AIR_AS_READER) / (16 * 8) + 2;
}
uint32_t iso18092_get_timeout(void)
{
uint32_t iso18092_get_timeout(void) {
return felica_timeout - (DELAY_AIR2ARM_AS_READER + DELAY_ARM2AIR_AS_READER) / (16 * 8) - 2;
}
@ -79,22 +77,19 @@ static struct {
# define SYNC_16BIT 0xB24D
#endif
static void FelicaFrameReset()
{
static void FelicaFrameReset() {
FelicaFrame.state = STATE_UNSYNCD;
FelicaFrame.posCnt = 0;
FelicaFrame.crc_ok = false;
FelicaFrame.byte_offset = 0;
}
static void FelicaFrameinit(uint8_t *data)
{
static void FelicaFrameinit(uint8_t *data) {
FelicaFrame.framebytes = data;
FelicaFrameReset();
}
//shift byte into frame, reversing it at the same time
static void shiftInByte(uint8_t bt)
{
static void shiftInByte(uint8_t bt) {
uint8_t j;
for (j = 0; j < FelicaFrame.byte_offset; j++) {
FelicaFrame.framebytes[FelicaFrame.posCnt] = (FelicaFrame.framebytes[FelicaFrame.posCnt] << 1) + (bt & 1);
@ -108,8 +103,7 @@ static void shiftInByte(uint8_t bt)
}
}
static void Process18092Byte(uint8_t bt)
{
static void Process18092Byte(uint8_t bt) {
switch (FelicaFrame.state) {
case STATE_UNSYNCD: {
//almost any nonzero byte can be start of SYNC. SYNC should be preceded by zeros, but that is not alsways the case
@ -196,8 +190,7 @@ static void Process18092Byte(uint8_t bt)
* Currently does NOT do any collision handling.
* It expects 0-1 cards in the device's range.
*/
static uint8_t felica_select_card(felica_card_select_t *card)
{
static uint8_t felica_select_card(felica_card_select_t *card) {
// POLL command
// 0xB2 0x4B = sync code
@ -271,8 +264,7 @@ static uint8_t felica_select_card(felica_card_select_t *card)
// Felica standard has a different file system, AFAIK,
// 8-byte IDm, number of blocks, blocks numbers
// number of blocks limited to 4 for FelicaLite(S)
static void BuildFliteRdblk(uint8_t *idm, int blocknum, uint16_t *blocks)
{
static void BuildFliteRdblk(uint8_t *idm, int blocknum, uint16_t *blocks) {
if (blocknum > 4 || blocknum <= 0)
Dbprintf("Invalid number of blocks, %d != 4", blocknum);
@ -324,8 +316,7 @@ static void BuildFliteRdblk(uint8_t *idm, int blocknum, uint16_t *blocks)
AddCrc(frameSpace, c - 2);
}
static void TransmitFor18092_AsReader(uint8_t *frame, int len, uint32_t *timing, uint8_t power, uint8_t highspeed)
{
static void TransmitFor18092_AsReader(uint8_t *frame, int len, uint32_t *timing, uint8_t power, uint8_t highspeed) {
uint8_t flags = FPGA_MAJOR_MODE_ISO18092;
@ -389,8 +380,7 @@ static void TransmitFor18092_AsReader(uint8_t *frame, int len, uint32_t *timing,
// Wait for tag reply
// stop when button is pressed
// or return TRUE when command is captured
bool WaitForFelicaReply(uint16_t maxbytes)
{
bool WaitForFelicaReply(uint16_t maxbytes) {
uint32_t c = 0;
@ -440,8 +430,7 @@ bool WaitForFelicaReply(uint16_t maxbytes)
// Set up FeliCa communication (similar to iso14443a_setup)
// field is setup for "Sending as Reader"
static void iso18092_setup(uint8_t fpga_minor_mode)
{
static void iso18092_setup(uint8_t fpga_minor_mode) {
LEDsoff();
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
@ -485,8 +474,7 @@ static void iso18092_setup(uint8_t fpga_minor_mode)
// arg0 FeliCa flags
// arg1 len of commandbytes
// d.asBytes command bytes to send
void felica_sendraw(UsbCommand *c)
{
void felica_sendraw(UsbCommand *c) {
if (MF_DBGLEVEL > 3) Dbprintf("FeliCa_sendraw Enter");
@ -552,8 +540,7 @@ OUT:
if (MF_DBGLEVEL > 3) Dbprintf("FeliCa_sendraw Exit");
}
void felica_sniff(uint32_t samplesToSkip, uint32_t triggersToSkip)
{
void felica_sniff(uint32_t samplesToSkip, uint32_t triggersToSkip) {
int remFrames = (samplesToSkip) ? samplesToSkip : 0;
@ -624,8 +611,7 @@ void felica_sniff(uint32_t samplesToSkip, uint32_t triggersToSkip)
#define R_READBLK_LEN 0x21
//simulate NFC Tag3 card - for now only poll response works
// second half (4 bytes) of NDEF2 goes into nfcid2_0, first into nfcid2_1
void felica_sim_lite(uint64_t nfcid)
{
void felica_sim_lite(uint64_t nfcid) {
int i, curlen = 0;
uint8_t *curresp = 0;
@ -731,8 +717,7 @@ void felica_sim_lite(uint64_t nfcid)
DbpString("Felica Lite-S sim end");
}
void felica_dump_lite_s()
{
void felica_dump_lite_s() {
uint8_t ndef[8];
uint8_t poll[10] = { 0xb2, 0x4d, 0x06, FELICA_POLL_REQ, 0xff, 0xff, 0x00, 0x00, 0x09, 0x21};

View file

@ -13,15 +13,13 @@
uint32_t FLASHMEM_SPIBAUDRATE = FLASH_BAUD;
void FlashmemSetSpiBaudrate(uint32_t baudrate)
{
void FlashmemSetSpiBaudrate(uint32_t baudrate) {
FLASHMEM_SPIBAUDRATE = baudrate;
Dbprintf("Spi Baudrate : %dMhz", FLASHMEM_SPIBAUDRATE / 1000000);
}
// initialize
bool FlashInit()
{
bool FlashInit() {
FlashSetup(FLASHMEM_SPIBAUDRATE);
StartTicks();
@ -34,8 +32,7 @@ bool FlashInit()
return true;
}
void FlashSetup(uint32_t baudrate)
{
void FlashSetup(uint32_t baudrate) {
//WDT_DISABLE
AT91C_BASE_WDTC->WDTC_WDMR = AT91C_WDTC_WDDIS;
@ -130,8 +127,7 @@ void FlashSetup(uint32_t baudrate)
if (AT91C_BASE_SPI->SPI_RDR == 0) {};
}
void FlashStop(void)
{
void FlashStop(void) {
//Bof
//* Reset all the Chip Select register
AT91C_BASE_SPI->SPI_CSR[0] = 0;
@ -154,8 +150,7 @@ void FlashStop(void)
}
// send one byte over SPI
uint16_t FlashSendByte(uint32_t data)
{
uint16_t FlashSendByte(uint32_t data) {
// wait until SPI is ready for transfer
//if you are checking for incoming data returned then the TXEMPTY flag is redundant
@ -174,20 +169,17 @@ uint16_t FlashSendByte(uint32_t data)
}
// send last byte over SPI
uint16_t FlashSendLastByte(uint32_t data)
{
uint16_t FlashSendLastByte(uint32_t data) {
return FlashSendByte(data | AT91C_SPI_LASTXFER);
}
// read state register 1
uint8_t Flash_ReadStat1(void)
{
uint8_t Flash_ReadStat1(void) {
FlashSendByte(READSTAT1);
return FlashSendLastByte(0xFF);
}
bool Flash_CheckBusy(uint32_t timeout)
{
bool Flash_CheckBusy(uint32_t timeout) {
WaitUS(WINBOND_WRITE_DELAY);
StartCountUS();
uint32_t _time = GetCountUS();
@ -208,8 +200,7 @@ bool Flash_CheckBusy(uint32_t timeout)
}
// read ID out
uint8_t Flash_ReadID(void)
{
uint8_t Flash_ReadID(void) {
if (Flash_CheckBusy(BUSY_TIMEOUT)) return 0;
@ -231,8 +222,7 @@ uint8_t Flash_ReadID(void)
}
// read unique id for chip.
void Flash_UniqueID(uint8_t *uid)
{
void Flash_UniqueID(uint8_t *uid) {
if (Flash_CheckBusy(BUSY_TIMEOUT)) return;
@ -253,8 +243,7 @@ void Flash_UniqueID(uint8_t *uid)
uid[0] = FlashSendLastByte(0xFF);
}
uint16_t Flash_ReadData(uint32_t address, uint8_t *out, uint16_t len)
{
uint16_t Flash_ReadData(uint32_t address, uint8_t *out, uint16_t len) {
if (!FlashInit()) return 0;
@ -279,16 +268,14 @@ uint16_t Flash_ReadData(uint32_t address, uint8_t *out, uint16_t len)
return len;
}
void Flash_TransferAdresse(uint32_t address)
{
void Flash_TransferAdresse(uint32_t address) {
FlashSendByte((address >> 16) & 0xFF);
FlashSendByte((address >> 8) & 0xFF);
FlashSendByte((address >> 0) & 0xFF);
}
/* This ensure we can ReadData without having to cycle through initialization everytime */
uint16_t Flash_ReadDataCont(uint32_t address, uint8_t *out, uint16_t len)
{
uint16_t Flash_ReadDataCont(uint32_t address, uint8_t *out, uint16_t len) {
// length should never be zero
if (!len) return 0;
@ -314,8 +301,7 @@ uint16_t Flash_ReadDataCont(uint32_t address, uint8_t *out, uint16_t len)
////////////////////////////////////////
// Write data can only program one page. A page has 256 bytes.
// if len > 256, it might wrap around and overwrite pos 0.
uint16_t Flash_WriteData(uint32_t address, uint8_t *in, uint16_t len)
{
uint16_t Flash_WriteData(uint32_t address, uint8_t *in, uint16_t len) {
// length should never be zero
if (!len)
@ -361,8 +347,7 @@ uint16_t Flash_WriteData(uint32_t address, uint8_t *in, uint16_t len)
// length should never be zero
// Max 256 bytes write
// out-of-range
uint16_t Flash_WriteDataCont(uint32_t address, uint8_t *in, uint16_t len)
{
uint16_t Flash_WriteDataCont(uint32_t address, uint8_t *in, uint16_t len) {
if (!len)
return 0;
@ -392,8 +377,7 @@ uint16_t Flash_WriteDataCont(uint32_t address, uint8_t *in, uint16_t len)
// assumes valid start 256 based 00 address
//
uint16_t Flash_Write(uint32_t address, uint8_t *in, uint16_t len)
{
uint16_t Flash_Write(uint32_t address, uint8_t *in, uint16_t len) {
bool isok;
uint16_t res, bytes_sent = 0, bytes_remaining = len;
@ -424,8 +408,7 @@ out:
}
bool Flash_WipeMemoryPage(uint8_t page)
{
bool Flash_WipeMemoryPage(uint8_t page) {
if (!FlashInit()) {
if (MF_DBGLEVEL > 3) Dbprintf("Flash_WriteData init fail");
return false;
@ -441,8 +424,7 @@ bool Flash_WipeMemoryPage(uint8_t page)
return true;
}
// Wipes flash memory completely, fills with 0xFF
bool Flash_WipeMemory()
{
bool Flash_WipeMemory() {
if (!FlashInit()) {
if (MF_DBGLEVEL > 3) Dbprintf("Flash_WriteData init fail");
return false;
@ -469,16 +451,14 @@ bool Flash_WipeMemory()
}
// enable the flash write
void Flash_WriteEnable()
{
void Flash_WriteEnable() {
FlashSendLastByte(WRITEENABLE);
if (MF_DBGLEVEL > 3) Dbprintf("Flash Write enabled");
}
// erase 4K at one time
// execution time: 0.8ms / 800us
bool Flash_Erase4k(uint8_t block, uint8_t sector)
{
bool Flash_Erase4k(uint8_t block, uint8_t sector) {
if (block > MAX_BLOCKS || sector > MAX_SECTORS) return false;
@ -513,8 +493,7 @@ bool Flash_Erase32k(uint32_t address) {
// 0x01 00 00 -- 0x 01 FF FF == block 1
// 0x02 00 00 -- 0x 02 FF FF == block 2
// 0x03 00 00 -- 0x 03 FF FF == block 3
bool Flash_Erase64k(uint8_t block)
{
bool Flash_Erase64k(uint8_t block) {
if (block > MAX_BLOCKS) return false;
@ -526,13 +505,11 @@ bool Flash_Erase64k(uint8_t block)
}
// Erase chip
void Flash_EraseChip(void)
{
void Flash_EraseChip(void) {
FlashSendLastByte(CHIPERASE);
}
void Flashmem_print_status(void)
{
void Flashmem_print_status(void) {
DbpString("Flash memory");
Dbprintf(" Baudrate................%dMHz", FLASHMEM_SPIBAUDRATE / 1000000);

View file

@ -28,8 +28,7 @@ static uint32_t uncompressed_bytes_cnt;
// Used to write the FPGA config word
// May also be used to write to other SPI attached devices like an LCD
//-----------------------------------------------------------------------------
static void DisableSpi(void)
{
static void DisableSpi(void) {
//* Reset all the Chip Select register
AT91C_BASE_SPI->SPI_CSR[0] = 0;
AT91C_BASE_SPI->SPI_CSR[1] = 0;
@ -46,8 +45,7 @@ static void DisableSpi(void)
AT91C_BASE_SPI->SPI_CR = AT91C_SPI_SPIDIS;
}
void SetupSpi(int mode)
{
void SetupSpi(int mode) {
// PA1 -> SPI_NCS3 chip select (MEM)
// PA10 -> SPI_NCS2 chip select (LCD)
// PA11 -> SPI_NCS0 chip select (FPGA)
@ -120,8 +118,7 @@ void SetupSpi(int mode)
// Set up the synchronous serial port, with the one set of options that we
// always use when we are talking to the FPGA. Both RX and TX are enabled.
//-----------------------------------------------------------------------------
void FpgaSetupSsc(void)
{
void FpgaSetupSsc(void) {
// First configure the GPIOs, and get ourselves a clock.
AT91C_BASE_PIOA->PIO_ASR =
GPIO_SSC_FRAME |
@ -159,8 +156,7 @@ void FpgaSetupSsc(void)
// ourselves, not to another buffer). The stuff to manipulate those buffers
// is in apps.h, because it should be inlined, for speed.
//-----------------------------------------------------------------------------
bool FpgaSetupSscDma(uint8_t *buf, int len)
{
bool FpgaSetupSscDma(uint8_t *buf, int len) {
if (buf == NULL) return false;
FpgaDisableSscDma();
@ -176,8 +172,7 @@ bool FpgaSetupSscDma(uint8_t *buf, int len)
// Uncompress (inflate) the FPGA data. Returns one decompressed byte with
// each call.
//----------------------------------------------------------------------------
static int get_from_fpga_combined_stream(z_streamp compressed_fpga_stream, uint8_t *output_buffer)
{
static int get_from_fpga_combined_stream(z_streamp compressed_fpga_stream, uint8_t *output_buffer) {
if (fpga_image_ptr == compressed_fpga_stream->next_out) { // need more data
compressed_fpga_stream->next_out = output_buffer;
compressed_fpga_stream->avail_out = OUTPUT_BUFFER_LEN;
@ -199,8 +194,7 @@ static int get_from_fpga_combined_stream(z_streamp compressed_fpga_stream, uint8
// are combined into one big file:
// 288 bytes from FPGA file 1, followed by 288 bytes from FGPA file 2, etc.
//----------------------------------------------------------------------------
static int get_from_fpga_stream(int bitstream_version, z_streamp compressed_fpga_stream, uint8_t *output_buffer)
{
static int get_from_fpga_stream(int bitstream_version, z_streamp compressed_fpga_stream, uint8_t *output_buffer) {
while ((uncompressed_bytes_cnt / FPGA_INTERLEAVE_SIZE) % fpga_bitstream_num != (bitstream_version - 1)) {
// skip undesired data belonging to other bitstream_versions
get_from_fpga_combined_stream(compressed_fpga_stream, output_buffer);
@ -209,14 +203,12 @@ static int get_from_fpga_stream(int bitstream_version, z_streamp compressed_fpga
return get_from_fpga_combined_stream(compressed_fpga_stream, output_buffer);
}
static voidpf fpga_inflate_malloc(voidpf opaque, uInt items, uInt size)
{
static voidpf fpga_inflate_malloc(voidpf opaque, uInt items, uInt size) {
return BigBuf_malloc(items * size);
}
// free eventually allocated BigBuf memory
static void fpga_inflate_free(voidpf opaque, voidpf address)
{
static void fpga_inflate_free(voidpf opaque, voidpf address) {
BigBuf_free();
BigBuf_Clear_ext(false);
}
@ -224,8 +216,7 @@ static void fpga_inflate_free(voidpf opaque, voidpf address)
//----------------------------------------------------------------------------
// Initialize decompression of the respective (HF or LF) FPGA stream
//----------------------------------------------------------------------------
static bool reset_fpga_stream(int bitstream_version, z_streamp compressed_fpga_stream, uint8_t *output_buffer)
{
static bool reset_fpga_stream(int bitstream_version, z_streamp compressed_fpga_stream, uint8_t *output_buffer) {
uint8_t header[FPGA_BITSTREAM_FIXED_HEADER_SIZE];
uncompressed_bytes_cnt = 0;
@ -252,8 +243,7 @@ static bool reset_fpga_stream(int bitstream_version, z_streamp compressed_fpga_s
return false;
}
static void DownloadFPGA_byte(uint8_t w)
{
static void DownloadFPGA_byte(uint8_t w) {
#define SEND_BIT(x) { if(w & (1<<x) ) HIGH(GPIO_FPGA_DIN); else LOW(GPIO_FPGA_DIN); HIGH(GPIO_FPGA_CCLK); LOW(GPIO_FPGA_CCLK); }
SEND_BIT(7);
SEND_BIT(6);
@ -266,8 +256,7 @@ static void DownloadFPGA_byte(uint8_t w)
}
// Download the fpga image starting at current stream position with length FpgaImageLen bytes
static void DownloadFPGA(int bitstream_version, int FpgaImageLen, z_streamp compressed_fpga_stream, uint8_t *output_buffer)
{
static void DownloadFPGA(int bitstream_version, int FpgaImageLen, z_streamp compressed_fpga_stream, uint8_t *output_buffer) {
int i = 0;
AT91C_BASE_PIOA->PIO_OER = GPIO_FPGA_ON;
@ -349,8 +338,7 @@ static void DownloadFPGA(int bitstream_version, int FpgaImageLen, z_streamp comp
* (big endian), <length> bytes content. Except for section 'e' which has 4 bytes
* length.
*/
static int bitparse_find_section(int bitstream_version, char section_name, uint32_t *section_length, z_streamp compressed_fpga_stream, uint8_t *output_buffer)
{
static int bitparse_find_section(int bitstream_version, char section_name, uint32_t *section_length, z_streamp compressed_fpga_stream, uint8_t *output_buffer) {
int result = 0;
#define MAX_FPGA_BIT_STREAM_HEADER_SEARCH 100 // maximum number of bytes to search for the requested section
uint16_t numbytes = 0;
@ -399,8 +387,7 @@ static int bitparse_find_section(int bitstream_version, char section_name, uint3
// Check which FPGA image is currently loaded (if any). If necessary
// decompress and load the correct (HF or LF) image to the FPGA
//----------------------------------------------------------------------------
void FpgaDownloadAndGo(int bitstream_version)
{
void FpgaDownloadAndGo(int bitstream_version) {
// check whether or not the bitstream is already loaded
if (downloaded_bitstream == bitstream_version)
@ -439,8 +426,7 @@ void FpgaDownloadAndGo(int bitstream_version)
// 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(uint16_t cmd, uint16_t 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
AT91C_BASE_SPI->SPI_TDR = AT91C_SPI_LASTXFER | cmd | v; // send the data
@ -451,8 +437,7 @@ void FpgaSendCommand(uint16_t cmd, uint16_t v)
// 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(uint8_t v)
{
void FpgaWriteConfWord(uint8_t v) {
FpgaSendCommand(FPGA_CMD_SET_CONFREG, v);
}
@ -461,8 +446,7 @@ void FpgaWriteConfWord(uint8_t 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(uint32_t whichGpio)
{
void SetAdcMuxFor(uint32_t whichGpio) {
AT91C_BASE_PIOA->PIO_OER =
GPIO_MUXSEL_HIPKD |
GPIO_MUXSEL_LOPKD |
@ -485,14 +469,12 @@ void SetAdcMuxFor(uint32_t whichGpio)
HIGH(whichGpio);
}
void Fpga_print_status(void)
{
void Fpga_print_status(void) {
Dbprintf("Currently loaded FPGA image");
Dbprintf(" mode....................%s", fpga_version_information[downloaded_bitstream - 1]);
}
int FpgaGetCurrent(void)
{
int FpgaGetCurrent(void) {
return downloaded_bitstream;
}
@ -500,8 +482,7 @@ int FpgaGetCurrent(void)
// log message
// if HF, Disable SSC DMA
// turn off trace and leds off.
void switch_off(void)
{
void switch_off(void) {
if (MF_DBGLEVEL > 3) Dbprintf("switch_off");
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
if (downloaded_bitstream == FPGA_BITSTREAM_HF)

View file

@ -6,8 +6,7 @@
static void RAMFUNC optimizedSnoop(void);
static void RAMFUNC optimizedSnoop(void)
{
static void RAMFUNC optimizedSnoop(void) {
int n = BigBuf_max_traceLen() / sizeof(uint16_t); // take all memory
uint16_t *dest = (uint16_t *)BigBuf_get_addr();
@ -24,8 +23,7 @@ static void RAMFUNC optimizedSnoop(void)
set_tracelen(BigBuf_max_traceLen());
}
void HfSnoop(int samplesToSkip, int triggersToSkip)
{
void HfSnoop(int samplesToSkip, int triggersToSkip) {
BigBuf_free();
BigBuf_Clear();

View file

@ -108,8 +108,7 @@ static const u32 ht2_f4a = 0x2C79; // 0010 1100 0111 1001
static const u32 ht2_f4b = 0x6671; // 0110 0110 0111 0001
static const u32 ht2_f5c = 0x7907287B; // 0111 1001 0000 0111 0010 1000 0111 1011
static u32 _f20(const u64 x)
{
static u32 _f20(const u64 x) {
u32 i5;
i5 = ((ht2_f4a >> i4(x, 1, 2, 4, 5)) & 1) * 1
@ -121,8 +120,7 @@ static u32 _f20(const u64 x)
return (ht2_f5c >> i5) & 1;
}
static u64 _hitag2_init(const u64 key, const u32 serial, const u32 IV)
{
static u64 _hitag2_init(const u64 key, const u32 serial, const u32 IV) {
u32 i;
u64 x = ((key & 0xFFFF) << 32) + serial;
@ -133,8 +131,7 @@ static u64 _hitag2_init(const u64 key, const u32 serial, const u32 IV)
return x;
}
static u64 _hitag2_round(u64 *state)
{
static u64 _hitag2_round(u64 *state) {
u64 x = *state;
x = (x >> 1) +
@ -157,29 +154,25 @@ static u64 _hitag2_round(u64 *state)
// The inverse of the first 4 bytes is sent to the tag to authenticate.
// The rest is encrypted by XORing it with the subsequent keystream.
static u32 _hitag2_byte(u64 *x)
{
static u32 _hitag2_byte(u64 *x) {
u32 i, c;
for (i = 0, c = 0; i < 8; i++) c += (u32) _hitag2_round(x) << (i ^ 7);
return c;
}
static int hitag2_reset(void)
{
static int hitag2_reset(void) {
tag.state = TAG_STATE_RESET;
tag.crypto_active = 0;
return 0;
}
static int hitag2_init(void)
{
static int hitag2_init(void) {
hitag2_reset();
return 0;
}
static void hitag2_cipher_reset(struct hitag2_tag *tag, const uint8_t *iv)
{
static void hitag2_cipher_reset(struct hitag2_tag *tag, const uint8_t *iv) {
uint64_t key = ((uint64_t)tag->sectors[2][2]) |
((uint64_t)tag->sectors[2][3] << 8) |
((uint64_t)tag->sectors[1][0] << 16) |
@ -197,8 +190,7 @@ static void hitag2_cipher_reset(struct hitag2_tag *tag, const uint8_t *iv)
tag->cs = _hitag2_init(rev64(key), rev32(uid), rev32(iv_));
}
static int hitag2_cipher_authenticate(uint64_t *cs, const uint8_t *authenticator_is)
{
static int hitag2_cipher_authenticate(uint64_t *cs, const uint8_t *authenticator_is) {
uint8_t authenticator_should[4];
authenticator_should[0] = ~_hitag2_byte(cs);
authenticator_should[1] = ~_hitag2_byte(cs);
@ -207,8 +199,7 @@ static int hitag2_cipher_authenticate(uint64_t *cs, const uint8_t *authenticator
return (memcmp(authenticator_should, authenticator_is, 4) == 0);
}
static int hitag2_cipher_transcrypt(uint64_t *cs, uint8_t *data, unsigned int bytes, unsigned int bits)
{
static int hitag2_cipher_transcrypt(uint64_t *cs, uint8_t *data, unsigned int bytes, unsigned int bits) {
int i;
for (i = 0; i < bytes; i++) data[i] ^= _hitag2_byte(cs);
for (i = 0; i < bits; i++) data[bytes] ^= _hitag2_round(cs) << (7 - i);
@ -250,8 +241,7 @@ static int hitag2_cipher_transcrypt(uint64_t *cs, uint8_t *data, unsigned int by
#define HITAG_T_TAG_CAPTURE_FOUR_HALF 57
static void hitag_send_bit(int bit)
{
static void hitag_send_bit(int bit) {
LED_A_ON();
// Reset clock for the next bit
AT91C_BASE_TC0->TC_CCR = AT91C_TC_SWTRG;
@ -273,8 +263,7 @@ static void hitag_send_bit(int bit)
LED_A_OFF();
}
static void hitag_send_frame(const uint8_t *frame, size_t frame_len)
{
static void hitag_send_frame(const uint8_t *frame, size_t frame_len) {
// Send start of frame
for (size_t i = 0; i < 5; i++) {
hitag_send_bit(1);
@ -290,8 +279,7 @@ static void hitag_send_frame(const uint8_t *frame, size_t frame_len)
}
static void hitag2_handle_reader_command(uint8_t *rx, const size_t rxlen, uint8_t *tx, size_t *txlen)
{
static void hitag2_handle_reader_command(uint8_t *rx, const size_t rxlen, uint8_t *tx, size_t *txlen) {
uint8_t rx_air[HITAG_FRAME_LEN];
// Copy the (original) received frame how it is send over the air
@ -417,8 +405,7 @@ static void hitag2_handle_reader_command(uint8_t *rx, const size_t rxlen, uint8_
}
}
static void hitag_reader_send_bit(int bit)
{
static void hitag_reader_send_bit(int bit) {
LED_A_ON();
// Reset clock for the next bit
AT91C_BASE_TC0->TC_CCR = AT91C_TC_SWTRG;
@ -448,8 +435,7 @@ static void hitag_reader_send_bit(int bit)
}
static void hitag_reader_send_frame(const uint8_t *frame, size_t frame_len)
{
static void hitag_reader_send_frame(const uint8_t *frame, size_t frame_len) {
// Send the content of the frame
for (size_t i = 0; i < frame_len; i++) {
hitag_reader_send_bit((frame[i / 8] >> (7 - (i % 8))) & 1);
@ -466,8 +452,7 @@ static void hitag_reader_send_frame(const uint8_t *frame, size_t frame_len)
size_t blocknr;
static bool hitag2_password(uint8_t *rx, const size_t rxlen, uint8_t *tx, size_t *txlen)
{
static bool hitag2_password(uint8_t *rx, const size_t rxlen, uint8_t *tx, size_t *txlen) {
// Reset the transmission frame length
*txlen = 0;
@ -525,8 +510,7 @@ static bool hitag2_password(uint8_t *rx, const size_t rxlen, uint8_t *tx, size_t
return true;
}
static bool hitag2_write_page(uint8_t *rx, const size_t rxlen, uint8_t *tx, size_t *txlen)
{
static bool hitag2_write_page(uint8_t *rx, const size_t rxlen, uint8_t *tx, size_t *txlen) {
switch (writestate) {
case WRITE_STATE_START:
*txlen = 10;
@ -537,8 +521,8 @@ static bool hitag2_write_page(uint8_t *rx, const size_t rxlen, uint8_t *tx, size
case WRITE_STATE_PAGENUM_WRITTEN:
// Check if page number was received correctly
if ((rxlen == 10) &&
(rx[0] == (0x82 | (blocknr << 3) | ((blocknr ^ 7) >> 2))) &&
(rx[1] == (((blocknr & 0x3) ^ 0x3) << 6))) {
(rx[0] == (0x82 | (blocknr << 3) | ((blocknr ^ 7) >> 2))) &&
(rx[1] == (((blocknr & 0x3) ^ 0x3) << 6))) {
*txlen = 32;
memset(tx, 0, HITAG_FRAME_LEN);
memcpy(tx, writedata, 4);
@ -567,8 +551,7 @@ static bool hitag2_write_page(uint8_t *rx, const size_t rxlen, uint8_t *tx, size
return true;
}
static bool hitag2_crypto(uint8_t *rx, const size_t rxlen, uint8_t *tx, size_t *txlen, bool write)
{
static bool hitag2_crypto(uint8_t *rx, const size_t rxlen, uint8_t *tx, size_t *txlen, bool write) {
// Reset the transmission frame length
*txlen = 0;
@ -677,8 +660,7 @@ static bool hitag2_crypto(uint8_t *rx, const size_t rxlen, uint8_t *tx, size_t *
}
static bool hitag2_authenticate(uint8_t *rx, const size_t rxlen, uint8_t *tx, size_t *txlen)
{
static bool hitag2_authenticate(uint8_t *rx, const size_t rxlen, uint8_t *tx, size_t *txlen) {
// Reset the transmission frame length
*txlen = 0;
@ -721,8 +703,7 @@ static bool hitag2_authenticate(uint8_t *rx, const size_t rxlen, uint8_t *tx, si
}
static bool hitag2_test_auth_attempts(uint8_t *rx, const size_t rxlen, uint8_t *tx, size_t *txlen)
{
static bool hitag2_test_auth_attempts(uint8_t *rx, const size_t rxlen, uint8_t *tx, size_t *txlen) {
// Reset the transmission frame length
*txlen = 0;
@ -781,8 +762,7 @@ static bool hitag2_test_auth_attempts(uint8_t *rx, const size_t rxlen, uint8_t *
return true;
}
static bool hitag2_read_uid(uint8_t *rx, const size_t rxlen, uint8_t *tx, size_t *txlen)
{
static bool hitag2_read_uid(uint8_t *rx, const size_t rxlen, uint8_t *tx, size_t *txlen) {
// Reset the transmission frame length
*txlen = 0;
@ -822,8 +802,7 @@ static bool hitag2_read_uid(uint8_t *rx, const size_t rxlen, uint8_t *tx, size_t
return true;
}
void SnoopHitag(uint32_t type)
{
void SnoopHitag(uint32_t type) {
int frame_count;
int response;
int overflow;
@ -1041,8 +1020,7 @@ void SnoopHitag(uint32_t type)
// DbpString("All done");
}
void SimulateHitagTag(bool tag_mem_supplied, uint8_t *data)
{
void SimulateHitagTag(bool tag_mem_supplied, uint8_t *data) {
int frame_count;
int response;
int overflow;
@ -1233,8 +1211,7 @@ void SimulateHitagTag(bool tag_mem_supplied, uint8_t *data)
set_tracing(false);
}
void ReaderHitag(hitag_function htf, hitag_data *htd)
{
void ReaderHitag(hitag_function htf, hitag_data *htd) {
int frame_count = 0;
int response = 0;
uint8_t rx[HITAG_FRAME_LEN];
@ -1548,8 +1525,7 @@ void ReaderHitag(hitag_function htf, hitag_data *htd)
cmd_send(CMD_ACK, bSuccessful, 0, 0, 0, 0);
}
void WriterHitag(hitag_function htf, hitag_data *htd, int page)
{
void WriterHitag(hitag_function htf, hitag_data *htd, int page) {
int frame_count;
int response;
uint8_t rx[HITAG_FRAME_LEN];

View file

@ -65,8 +65,7 @@ static const u32 ht2_f5c = 0x7907287B; // 0111 1001 0000 0111 0010 1000 0
#define ht2bs_5c(a,b,c,d,e) (~((((((c^e)|d)&a)^b)&(c^b))^(((d^e)|a)&((d^b)|c))))
#define uf20bs u32
static u32 f20(const u64 x)
{
static u32 f20(const u64 x) {
u32 i5;
i5 = ((ht2_f4a >> i4(x, 1, 2, 4, 5)) & 1) * 1
@ -77,8 +76,7 @@ static u32 f20(const u64 x)
return (ht2_f5c >> i5) & 1;
}
static u64 hitag2_round(u64 *state)
{
static u64 hitag2_round(u64 *state) {
u64 x = *state;
x = (x >> 1)
@ -90,8 +88,7 @@ static u64 hitag2_round(u64 *state)
*state = x;
return f20(x);
}
static u64 hitag2_init(const u64 key, const u32 serial, const u32 IV)
{
static u64 hitag2_init(const u64 key, const u32 serial, const u32 IV) {
u32 i;
u64 x = ((key & 0xFFFF) << 32) + serial;
for (i = 0; i < 32; i++) {
@ -100,8 +97,7 @@ static u64 hitag2_init(const u64 key, const u32 serial, const u32 IV)
}
return x;
}
static u32 hitag2_byte(u64 *x)
{
static u32 hitag2_byte(u64 *x) {
u32 i, c;
for (i = 0, c = 0; i < 8; i++)
@ -148,8 +144,7 @@ static u32 hitag2_byte(u64 *x)
* Implementation of the crc8 calculation from Hitag S
* from http://www.proxmark.org/files/Documents/125%20kHz%20-%20Hitag/HitagS.V11.pdf
*/
void calc_crc(unsigned char *crc, unsigned char data, unsigned char Bitcount)
{
void calc_crc(unsigned char *crc, unsigned char data, unsigned char Bitcount) {
*crc ^= data; // crc = crc (exor) data
do {
if (*crc & 0x80) { // if (MSB-CRC == 1)
@ -161,8 +156,7 @@ void calc_crc(unsigned char *crc, unsigned char data, unsigned char Bitcount)
} while (--Bitcount);
}
static void hitag_send_bit(int bit)
{
static void hitag_send_bit(int bit) {
LED_A_ON();
// Reset clock for the next bit
AT91C_BASE_TC0->TC_CCR = AT91C_TC_SWTRG;
@ -264,8 +258,7 @@ static void hitag_send_bit(int bit)
}
}
static void hitag_send_frame(const byte_t *frame, size_t frame_len)
{
static void hitag_send_frame(const byte_t *frame, size_t frame_len) {
// Send start of frame
for (size_t i = 0; i < sof_bits; i++) {
@ -280,8 +273,7 @@ static void hitag_send_frame(const byte_t *frame, size_t frame_len)
LOW(GPIO_SSC_DOUT);
}
static void hitag_reader_send_bit(int bit)
{
static void hitag_reader_send_bit(int bit) {
//Dbprintf("BIT: %d",bit);
LED_A_ON();
// Reset clock for the next bit
@ -337,8 +329,7 @@ static void hitag_reader_send_bit(int bit)
LED_A_OFF();
}
static void hitag_reader_send_frame(const byte_t *frame, size_t frame_len)
{
static void hitag_reader_send_frame(const byte_t *frame, size_t frame_len) {
// Send the content of the frame
for (size_t i = 0; i < frame_len; i++) {
if (frame[0] == 0xf8) {
@ -360,8 +351,7 @@ static void hitag_reader_send_frame(const byte_t *frame, size_t frame_len)
/*
* to check if the right uid was selected
*/
static int check_select(byte_t *rx, uint32_t uid)
{
static int check_select(byte_t *rx, uint32_t uid) {
unsigned char resp[48];
int i;
uint32_t ans = 0x0;
@ -382,8 +372,7 @@ static int check_select(byte_t *rx, uint32_t uid)
* handles all commands from a reader
*/
static void hitagS_handle_reader_command(byte_t *rx, const size_t rxlen,
byte_t *tx, size_t *txlen)
{
byte_t *tx, size_t *txlen) {
byte_t rx_air[HITAG_FRAME_LEN];
byte_t page;
int i;
@ -679,7 +668,7 @@ static void hitagS_handle_reader_command(byte_t *rx, const size_t rxlen,
break;
}
if ((tag.LCON && page == 1)
|| (tag.LKP && (page == 2 || page == 3))) {
|| (tag.LKP && (page == 2 || page == 3))) {
//deny
*txlen = 0;
} else {
@ -732,8 +721,7 @@ static void hitagS_handle_reader_command(byte_t *rx, const size_t rxlen,
* to autenticate to a tag with the given key or challenge
*/
static int hitagS_handle_tag_auth(hitag_function htf, uint64_t key, uint64_t NrAr, byte_t *rx, const size_t rxlen, byte_t *tx,
size_t *txlen)
{
size_t *txlen) {
byte_t rx_air[HITAG_FRAME_LEN];
int response_bit[200];
int i, j, z, k;
@ -945,8 +933,7 @@ static int hitagS_handle_tag_auth(hitag_function htf, uint64_t key, uint64_t NrA
/*
* Emulates a Hitag S Tag with the given data from the .hts file
*/
void SimulateHitagSTag(bool tag_mem_supplied, byte_t *data)
{
void SimulateHitagSTag(bool tag_mem_supplied, byte_t *data) {
int frame_count;
int response;
int overflow;
@ -1172,8 +1159,7 @@ void SimulateHitagSTag(bool tag_mem_supplied, byte_t *data)
* If the key was given the password will be decrypted.
* Reads every page of a hitag S transpoder.
*/
void ReadHitagS(hitag_function htf, hitag_data *htd)
{
void ReadHitagS(hitag_function htf, hitag_data *htd) {
int i, j, z, k;
int frame_count;
int response_bit[200];
@ -1518,8 +1504,7 @@ void ReadHitagS(hitag_function htf, hitag_data *htd)
* Authenticates to the Tag with the given Key or Challenge.
* Writes the given 32Bit data into page_
*/
void WritePageHitagS(hitag_function htf, hitag_data *htd, int page_)
{
void WritePageHitagS(hitag_function htf, hitag_data *htd, int page_) {
int frame_count;
int response;
byte_t rx[HITAG_FRAME_LEN];
@ -1727,7 +1712,7 @@ void WritePageHitagS(hitag_function htf, hitag_data *htd, int page_)
// All timer values are in terms of T0 units
while (AT91C_BASE_TC0->TC_CV
< T0 * (t_wait + (HITAG_T_TAG_HALF_PERIOD * lastbit)))
< T0 * (t_wait + (HITAG_T_TAG_HALF_PERIOD * lastbit)))
;
// Transmit the reader frame
@ -1835,8 +1820,7 @@ void WritePageHitagS(hitag_function htf, hitag_data *htd, int page_)
* is not received correctly due to Antenna problems. This function
* detects these challenges.
*/
void check_challenges(bool file_given, byte_t *data)
{
void check_challenges(bool file_given, byte_t *data) {
int i, j, z, k;
byte_t uid_byte[4];
int frame_count;
@ -2060,7 +2044,7 @@ void check_challenges(bool file_given, byte_t *data)
// All timer values are in terms of T0 units
while (AT91C_BASE_TC0->TC_CV
< T0 * (t_wait + (HITAG_T_TAG_HALF_PERIOD * lastbit)))
< T0 * (t_wait + (HITAG_T_TAG_HALF_PERIOD * lastbit)))
;
// Transmit the reader frame

View file

@ -141,19 +141,16 @@ typedef struct {
} tUart;
static tUart Uart;
static void uart_reset(void)
{
static void uart_reset(void) {
Uart.frame_done = false;
Uart.synced = false;
Uart.frame = false;
}
static void uart_init(uint8_t *data)
{
static void uart_init(uint8_t *data) {
Uart.buf = data;
uart_reset();
}
static void uart_bit(uint8_t bit)
{
static void uart_bit(uint8_t bit) {
static uint8_t buf = 0xff;
static uint8_t n_buf;
static uint8_t msg_byte;
@ -208,8 +205,7 @@ static void uart_bit(uint8_t bit)
}
}
static void uart_samples(uint8_t byte)
{
static void uart_samples(uint8_t byte) {
static uint32_t buf;
static int window;
static int drop_next = 0;
@ -504,8 +500,7 @@ static RAMFUNC int OutOfNDecoding(int bit) {
// Manchester
//=============================================================================
static tDemod Demod;
static void DemodReset()
{
static void DemodReset() {
Demod.bitCount = 0;
Demod.posCount = 0;
Demod.syncBit = 0;
@ -519,8 +514,7 @@ static void DemodReset()
Demod.sub = SUB_NONE;
Demod.state = DEMOD_UNSYNCD;
}
static void DemodInit(uint8_t *data)
{
static void DemodInit(uint8_t *data) {
Demod.output = data;
DemodReset();
}
@ -546,8 +540,7 @@ Recorded Activity (TraceLen = 162 bytes)
2720 | 2720 | Rdr |0c | | IDENTIFY
3232 | 3232 | Tag |bb! d4! bb! 02 02 08 04 bb! | ok |
*/
static void uart_debug(int error, int bit)
{
static void uart_debug(int error, int bit) {
Demod.output[Demod.len] = 0xBB;
Demod.len++;
Demod.output[Demod.len] = error & 0xFF;
@ -583,8 +576,7 @@ static void uart_debug(int error, int bit)
*
* So for current implementation in ISO15693, its 330 µs from end of reader, to start of card.
*/
static RAMFUNC int ManchesterDecoding_iclass(uint32_t v)
{
static RAMFUNC int ManchesterDecoding_iclass(uint32_t v) {
int bit;
int modulation;
int error = 0;
@ -806,8 +798,7 @@ static RAMFUNC int ManchesterDecoding_iclass(uint32_t v)
// Finally, a `sniffer' for iClass communication
// Both sides of communication!
//=============================================================================
static void iclass_setup_sniff(void)
{
static void iclass_setup_sniff(void) {
if (MF_DBGLEVEL > 3) Dbprintf("iclass_setup_sniff Enter");
LEDsoff();
@ -860,8 +851,7 @@ static void iclass_setup_sniff(void)
// near the reader.
//-----------------------------------------------------------------------------
// turn off afterwards
void RAMFUNC SniffIClass(void)
{
void RAMFUNC SniffIClass(void) {
//int datalen = 0;
uint32_t previous_data = 0;
@ -983,8 +973,7 @@ void RAMFUNC SniffIClass(void)
switch_off();
}
void rotateCSN(uint8_t *originalCSN, uint8_t *rotatedCSN)
{
void rotateCSN(uint8_t *originalCSN, uint8_t *rotatedCSN) {
int i;
for (i = 0; i < 8; i++)
rotatedCSN[i] = (originalCSN[i] >> 3) | (originalCSN[(i + 1) % 8] << 5);
@ -996,8 +985,7 @@ void rotateCSN(uint8_t *originalCSN, uint8_t *rotatedCSN)
// Stop when button is pressed
// Or return TRUE when command is captured
//-----------------------------------------------------------------------------
static bool GetIClassCommandFromReader(uint8_t *received, int *len, int maxLen)
{
static bool GetIClassCommandFromReader(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).
// Signal field is off with the appropriate LED
@ -1029,8 +1017,7 @@ static bool GetIClassCommandFromReader(uint8_t *received, int *len, int maxLen)
return false;
}
static uint8_t encode4Bits(const uint8_t b)
{
static uint8_t encode4Bits(const uint8_t b) {
// OTA, the least significant bits first
// Manchester encoding added
// The columns are
@ -1080,8 +1067,7 @@ static uint8_t encode4Bits(const uint8_t b)
//-----------------------------------------------------------------------------
// Prepare tag messages
//-----------------------------------------------------------------------------
static void CodeIClassTagAnswer(const uint8_t *cmd, int len)
{
static void CodeIClassTagAnswer(const uint8_t *cmd, int len) {
/*
* SOF comprises 3 parts;
* * An unmodulated time of 56.64 us
@ -1135,8 +1121,7 @@ static void CodeIClassTagAnswer(const uint8_t *cmd, int len)
}
// Only SOF
static void CodeIClassTagSOF()
{
static void CodeIClassTagSOF() {
//So far a dummy implementation, not used
//int lastProxToAirDuration =0;
@ -1162,8 +1147,7 @@ static void CodeIClassTagSOF()
* @param datain
*/
// turn off afterwards
void SimulateIClass(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain)
{
void SimulateIClass(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain) {
if (MF_DBGLEVEL > 3) Dbprintf("[+] iClass_simulate Enter");
@ -1273,8 +1257,7 @@ out:
* @param csn - csn to use
* @param breakAfterMacReceived if true, returns after reader MAC has been received.
*/
int doIClassSimulation(int simulationMode, uint8_t *reader_mac_buf)
{
int doIClassSimulation(int simulationMode, uint8_t *reader_mac_buf) {
// free eventually allocated BigBuf memory
BigBuf_free_keep_EM();
@ -1641,8 +1624,7 @@ send:
* @param respLen
* @param delay
*/
static int SendIClassAnswer(uint8_t *resp, int respLen, uint16_t delay)
{
static int SendIClassAnswer(uint8_t *resp, int respLen, uint16_t delay) {
int i = 0;
volatile uint8_t b = 0;
@ -1680,8 +1662,7 @@ static int SendIClassAnswer(uint8_t *resp, int respLen, uint16_t delay)
//-----------------------------------------------------------------------------
// Transmit the command (to the tag) that was placed in ToSend[].
//-----------------------------------------------------------------------------
static void TransmitIClassCommand(const uint8_t *cmd, int len, int *samples, int *wait)
{
static void TransmitIClassCommand(const uint8_t *cmd, int len, int *samples, int *wait) {
int c = 0;
volatile uint32_t b;
@ -1737,8 +1718,7 @@ static void TransmitIClassCommand(const uint8_t *cmd, int len, int *samples, int
//-----------------------------------------------------------------------------
// Prepare iClass reader command to send to FPGA
//-----------------------------------------------------------------------------
void CodeIClassCommand(const uint8_t *cmd, int len)
{
void CodeIClassCommand(const uint8_t *cmd, int len) {
int i, j, k;
uint8_t b;
@ -1775,8 +1755,7 @@ void CodeIClassCommand(const uint8_t *cmd, int len)
ToSendMax++;
}
void ReaderTransmitIClass_ext(uint8_t *frame, int len, int wait)
{
void ReaderTransmitIClass_ext(uint8_t *frame, int len, int wait) {
int samples = 0;
@ -1792,8 +1771,7 @@ void ReaderTransmitIClass_ext(uint8_t *frame, int len, int wait)
LogTrace(frame, len, rsamples, rsamples, NULL, true);
}
void ReaderTransmitIClass(uint8_t *frame, int len)
{
void ReaderTransmitIClass(uint8_t *frame, int len) {
ReaderTransmitIClass_ext(frame, len, 330);
}
@ -1802,8 +1780,7 @@ void ReaderTransmitIClass(uint8_t *frame, int len)
// If a response is captured return TRUE
// If it takes too long return FALSE
//-----------------------------------------------------------------------------
static int GetIClassAnswer(uint8_t *receivedResponse, int maxLen, int *samples, int *elapsed)
{
static int GetIClassAnswer(uint8_t *receivedResponse, int maxLen, int *samples, int *elapsed) {
// buffer needs to be 512 bytes
// maxLen is not used...
@ -1854,8 +1831,7 @@ static int GetIClassAnswer(uint8_t *receivedResponse, int maxLen, int *samples,
return false;
}
int ReaderReceiveIClass(uint8_t *receivedAnswer)
{
int ReaderReceiveIClass(uint8_t *receivedAnswer) {
int samples = 0;
if (!GetIClassAnswer(receivedAnswer, 0, &samples, NULL))
@ -1871,8 +1847,7 @@ int ReaderReceiveIClass(uint8_t *receivedAnswer)
return Demod.len;
}
void setupIclassReader()
{
void setupIclassReader() {
LEDsoff();
@ -1899,8 +1874,7 @@ void setupIclassReader()
LED_A_ON();
}
bool sendCmdGetResponseWithRetries(uint8_t *command, size_t cmdsize, uint8_t *resp, uint8_t expected_size, uint8_t retries)
{
bool sendCmdGetResponseWithRetries(uint8_t *command, size_t cmdsize, uint8_t *resp, uint8_t expected_size, uint8_t retries) {
uint8_t got_n = 0;
while (retries-- > 0) {
@ -1929,8 +1903,7 @@ bool sendCmdGetResponseWithRetries(uint8_t *command, size_t cmdsize, uint8_t *re
* 1 = Got CSN
* 2 = Got CSN and CC
*/
uint8_t handshakeIclassTag_ext(uint8_t *card_data, bool use_credit_key)
{
uint8_t handshakeIclassTag_ext(uint8_t *card_data, bool use_credit_key) {
// act_all...
static uint8_t act_all[] = { ICLASS_CMD_ACTALL };
@ -1989,15 +1962,13 @@ uint8_t handshakeIclassTag_ext(uint8_t *card_data, bool use_credit_key)
read_status++;
return read_status;
}
uint8_t handshakeIclassTag(uint8_t *card_data)
{
uint8_t handshakeIclassTag(uint8_t *card_data) {
return handshakeIclassTag_ext(card_data, false);
}
// Reader iClass Anticollission
// turn off afterwards
void ReaderIClass(uint8_t arg0)
{
void ReaderIClass(uint8_t arg0) {
uint8_t card_data[6 * 8] = {0};
uint8_t last_csn[8] = {0, 0, 0, 0, 0, 0, 0, 0};
@ -2136,8 +2107,7 @@ void ReaderIClass(uint8_t arg0)
}
// turn off afterwards
void ReaderIClass_Replay(uint8_t arg0, uint8_t *MAC)
{
void ReaderIClass_Replay(uint8_t arg0, uint8_t *MAC) {
uint8_t cardsize = 0;
uint8_t mem = 0;
@ -2257,8 +2227,7 @@ void ReaderIClass_Replay(uint8_t arg0, uint8_t *MAC)
// not used. ?!? ( CMD_ICLASS_READCHECK)
// turn off afterwards
void iClass_ReadCheck(uint8_t blockNo, uint8_t keyType)
{
void iClass_ReadCheck(uint8_t blockNo, uint8_t keyType) {
uint8_t readcheck[] = { keyType, blockNo };
uint8_t resp[] = {0, 0, 0, 0, 0, 0, 0, 0};
size_t isOK = 0;
@ -2269,8 +2238,7 @@ void iClass_ReadCheck(uint8_t blockNo, uint8_t keyType)
// used with function select_and_auth (cmdhficlass.c)
// which needs to authenticate before doing more things like read/write
void iClass_Authentication(uint8_t *mac)
{
void iClass_Authentication(uint8_t *mac) {
uint8_t check[] = { ICLASS_CMD_CHECK, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
uint8_t resp[ICLASS_BUFFER_SIZE];
@ -2297,8 +2265,7 @@ typedef struct iclass_premac {
* - key loop only test one type of authtication key. Ie two calls needed
* to cover debit and credit key. (AA1/AA2)
*/
void iClass_Authentication_fast(uint64_t arg0, uint64_t arg1, uint8_t *datain)
{
void iClass_Authentication_fast(uint64_t arg0, uint64_t arg1, uint8_t *datain) {
uint8_t i = 0, isOK = 0;
uint8_t lastChunk = ((arg0 >> 8) & 0xFF);
bool use_credit_key = ((arg0 >> 16) & 0xFF);
@ -2381,8 +2348,7 @@ out:
// Tries to read block.
// retries 10times.
bool iClass_ReadBlock(uint8_t blockNo, uint8_t *data, uint8_t len)
{
bool iClass_ReadBlock(uint8_t blockNo, uint8_t *data, uint8_t len) {
uint8_t resp[10];
uint8_t cmd[] = {ICLASS_CMD_READ_OR_IDENTIFY, blockNo, 0x00, 0x00};
AddCrc(cmd + 1, 1);
@ -2394,8 +2360,7 @@ bool iClass_ReadBlock(uint8_t blockNo, uint8_t *data, uint8_t len)
// turn off afterwards
// readblock 8 + 2. only want 8.
void iClass_ReadBlk(uint8_t blockno)
{
void iClass_ReadBlk(uint8_t blockno) {
uint8_t data[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
bool isOK = iClass_ReadBlock(blockno, data, sizeof(data));
cmd_send(CMD_ACK, isOK, 0, 0, data, sizeof(data));
@ -2403,8 +2368,7 @@ void iClass_ReadBlk(uint8_t blockno)
}
// turn off afterwards
void iClass_Dump(uint8_t blockno, uint8_t numblks)
{
void iClass_Dump(uint8_t blockno, uint8_t numblks) {
uint8_t blockdata[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
bool isOK = false;
uint8_t blkCnt = 0;
@ -2438,8 +2402,7 @@ void iClass_Dump(uint8_t blockno, uint8_t numblks)
BigBuf_free();
}
bool iClass_WriteBlock_ext(uint8_t blockNo, uint8_t *data)
{
bool iClass_WriteBlock_ext(uint8_t blockNo, uint8_t *data) {
uint8_t resp[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
uint8_t write[] = { ICLASS_CMD_UPDATE, blockNo, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
@ -2462,16 +2425,14 @@ bool iClass_WriteBlock_ext(uint8_t blockNo, uint8_t *data)
}
// turn off afterwards
void iClass_WriteBlock(uint8_t blockNo, uint8_t *data)
{
void iClass_WriteBlock(uint8_t blockNo, uint8_t *data) {
bool isOK = iClass_WriteBlock_ext(blockNo, data);
cmd_send(CMD_ACK, isOK, 0, 0, 0, 0);
switch_off();
}
// turn off afterwards
void iClass_Clone(uint8_t startblock, uint8_t endblock, uint8_t *data)
{
void iClass_Clone(uint8_t startblock, uint8_t endblock, uint8_t *data) {
int i, written = 0;
int total_block = (endblock - startblock) + 1;
for (i = 0; i < total_block; i++) {

View file

@ -120,26 +120,22 @@ static uint32_t LastProxToAirDuration;
#define SEC_Y 0x00
#define SEC_Z 0xc0
void iso14a_set_trigger(bool enable)
{
void iso14a_set_trigger(bool enable) {
trigger = enable;
}
void iso14a_set_timeout(uint32_t timeout)
{
void iso14a_set_timeout(uint32_t timeout) {
iso14a_timeout = timeout + (DELAY_AIR2ARM_AS_READER + DELAY_ARM2AIR_AS_READER) / (16 * 8) + 2;
}
uint32_t iso14a_get_timeout(void)
{
uint32_t iso14a_get_timeout(void) {
return iso14a_timeout - (DELAY_AIR2ARM_AS_READER + DELAY_ARM2AIR_AS_READER) / (16 * 8) - 2;
}
//-----------------------------------------------------------------------------
// Generate the parity value for a byte sequence
//-----------------------------------------------------------------------------
void GetParity(const uint8_t *pbtCmd, uint16_t iLen, uint8_t *par)
{
void GetParity(const uint8_t *pbtCmd, uint16_t iLen, uint8_t *par) {
uint16_t paritybit_cnt = 0;
uint16_t paritybyte_cnt = 0;
uint8_t parityBits = 0;
@ -193,13 +189,11 @@ const bool Mod_Miller_LUT[] = {
#define IsMillerModulationNibble1(b) (Mod_Miller_LUT[(b & 0x000000F0) >> 4])
#define IsMillerModulationNibble2(b) (Mod_Miller_LUT[(b & 0x0000000F)])
tUart *GetUart()
{
tUart *GetUart() {
return &Uart;
}
void UartReset(void)
{
void UartReset(void) {
Uart.state = STATE_UNSYNCD;
Uart.bitCount = 0;
Uart.len = 0; // number of decoded data bytes
@ -213,16 +207,14 @@ void UartReset(void)
Uart.syncBit = 9999;
}
void UartInit(uint8_t *data, uint8_t *parity)
{
void UartInit(uint8_t *data, uint8_t *parity) {
Uart.output = data;
Uart.parity = parity;
UartReset();
}
// use parameter non_real_time to provide a timestamp. Set to 0 if the decoder should measure real time
RAMFUNC bool MillerDecoding(uint8_t bit, uint32_t non_real_time)
{
RAMFUNC bool MillerDecoding(uint8_t bit, uint32_t non_real_time) {
Uart.fourBits = (Uart.fourBits << 8) | bit;
if (Uart.state == STATE_UNSYNCD) { // not yet synced
@ -369,12 +361,10 @@ const bool Mod_Manchester_LUT[] = {
#define IsManchesterModulationNibble1(b) (Mod_Manchester_LUT[(b & 0x00F0) >> 4])
#define IsManchesterModulationNibble2(b) (Mod_Manchester_LUT[(b & 0x000F)])
tDemod *GetDemod()
{
tDemod *GetDemod() {
return &Demod;
}
void DemodReset(void)
{
void DemodReset(void) {
Demod.state = DEMOD_UNSYNCD;
Demod.len = 0; // number of decoded data bytes
Demod.parityLen = 0;
@ -390,16 +380,14 @@ void DemodReset(void)
Demod.samples = 0;
}
void DemodInit(uint8_t *data, uint8_t *parity)
{
void DemodInit(uint8_t *data, uint8_t *parity) {
Demod.output = data;
Demod.parity = parity;
DemodReset();
}
// use parameter non_real_time to provide a timestamp. Set to 0 if the decoder should measure real time
RAMFUNC int ManchesterDecoding(uint8_t bit, uint16_t offset, uint32_t non_real_time)
{
RAMFUNC int ManchesterDecoding(uint8_t bit, uint16_t offset, uint32_t non_real_time) {
Demod.twoBits = (Demod.twoBits << 8) | bit;
if (Demod.state == DEMOD_UNSYNCD) {
@ -499,8 +487,7 @@ RAMFUNC int ManchesterDecoding(uint8_t bit, uint16_t offset, uint32_t non_real_t
// near the reader.
// "hf 14a sniff"
//-----------------------------------------------------------------------------
void RAMFUNC SniffIso14443a(uint8_t param)
{
void RAMFUNC SniffIso14443a(uint8_t param) {
LEDsoff();
// param:
// bit 0 - trigger from first card answer
@ -663,8 +650,7 @@ void RAMFUNC SniffIso14443a(uint8_t param)
//-----------------------------------------------------------------------------
// Prepare tag messages
//-----------------------------------------------------------------------------
static void CodeIso14443aAsTagPar(const uint8_t *cmd, uint16_t len, uint8_t *parity, bool collision)
{
static void CodeIso14443aAsTagPar(const uint8_t *cmd, uint16_t len, uint8_t *parity, bool collision) {
//uint8_t localCol = 0;
ToSendReset();
@ -724,19 +710,16 @@ static void CodeIso14443aAsTagPar(const uint8_t *cmd, uint16_t len, uint8_t *par
ToSendMax++;
}
static void CodeIso14443aAsTagEx(const uint8_t *cmd, uint16_t len, bool collision)
{
static void CodeIso14443aAsTagEx(const uint8_t *cmd, uint16_t len, bool collision) {
uint8_t par[MAX_PARITY_SIZE] = {0};
GetParity(cmd, len, par);
CodeIso14443aAsTagPar(cmd, len, par, collision);
}
static void CodeIso14443aAsTag(const uint8_t *cmd, uint16_t len)
{
static void CodeIso14443aAsTag(const uint8_t *cmd, uint16_t len) {
CodeIso14443aAsTagEx(cmd, len, false);
}
static void Code4bitAnswerAsTag(uint8_t cmd)
{
static void Code4bitAnswerAsTag(uint8_t cmd) {
uint8_t b = cmd;
ToSendReset();
@ -777,8 +760,7 @@ static void Code4bitAnswerAsTag(uint8_t cmd)
// stop when button is pressed
// or return TRUE when command is captured
//-----------------------------------------------------------------------------
int GetIso14443aCommandFromReader(uint8_t *received, uint8_t *parity, int *len)
{
int GetIso14443aCommandFromReader(uint8_t *received, uint8_t *parity, int *len) {
// Set FPGA mode to "simulated ISO 14443 tag", no modulation (listen
// only, since we are receiving, not transmitting).
// Signal field is off with the appropriate LED
@ -805,8 +787,7 @@ int GetIso14443aCommandFromReader(uint8_t *received, uint8_t *parity, int *len)
return false;
}
bool prepare_tag_modulation(tag_response_info_t *response_info, size_t max_buffer_size)
{
bool prepare_tag_modulation(tag_response_info_t *response_info, size_t max_buffer_size) {
// Example response, answer to MIFARE Classic read block will be 16 bytes + 2 CRC = 18 bytes
// This will need the following byte array for a modulation sequence
// 144 data bits (18 * 8)
@ -844,8 +825,7 @@ bool prepare_tag_modulation(tag_response_info_t *response_info, size_t max_buffe
// 47 * 8 data bits, 47 * 1 parity bits, 10 start bits, 10 stop bits, 10 correction bits
#define ALLOCATED_TAG_MODULATION_BUFFER_SIZE 453
bool prepare_allocated_tag_modulation(tag_response_info_t *response_info)
{
bool prepare_allocated_tag_modulation(tag_response_info_t *response_info) {
// Retrieve and store the current buffer index
response_info->modulation = free_buffer_pointer;
@ -867,8 +847,7 @@ bool prepare_allocated_tag_modulation(tag_response_info_t *response_info)
// response to send, and send it.
// 'hf 14a sim'
//-----------------------------------------------------------------------------
void SimulateIso14443aTag(int tagType, int flags, uint8_t *data)
{
void SimulateIso14443aTag(int tagType, int flags, uint8_t *data) {
#define ATTACK_KEY_COUNT 8 // keep same as define in cmdhfmf.c -> readerAttack()
@ -1437,8 +1416,7 @@ void SimulateIso14443aTag(int tagType, int flags, uint8_t *data)
// prepare a delayed transfer. This simply shifts ToSend[] by a number
// of bits specified in the delay parameter.
void PrepareDelayedTransfer(uint16_t delay)
{
void PrepareDelayedTransfer(uint16_t delay) {
delay &= 0x07;
if (!delay) return;
@ -1469,8 +1447,7 @@ void PrepareDelayedTransfer(uint16_t delay)
// if == 0: transfer immediately and return time of transfer
// if != 0: delay transfer until time specified
//-------------------------------------------------------------------------------------
static void TransmitFor14443a(const uint8_t *cmd, uint16_t len, uint32_t *timing)
{
static void TransmitFor14443a(const uint8_t *cmd, uint16_t len, uint32_t *timing) {
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_ISO14443A | FPGA_HF_ISO14443A_READER_MOD);
@ -1516,8 +1493,7 @@ static void TransmitFor14443a(const uint8_t *cmd, uint16_t len, uint32_t *timing
//-----------------------------------------------------------------------------
// Prepare reader command (in bits, support short frames) to send to FPGA
//-----------------------------------------------------------------------------
void CodeIso14443aBitsAsReaderPar(const uint8_t *cmd, uint16_t bits, const uint8_t *parity)
{
void CodeIso14443aBitsAsReaderPar(const uint8_t *cmd, uint16_t bits, const uint8_t *parity) {
int i, j;
int last = 0;
uint8_t b;
@ -1596,8 +1572,7 @@ void CodeIso14443aBitsAsReaderPar(const uint8_t *cmd, uint16_t bits, const uint8
//-----------------------------------------------------------------------------
// Prepare reader command to send to FPGA
//-----------------------------------------------------------------------------
void CodeIso14443aAsReaderPar(const uint8_t *cmd, uint16_t len, const uint8_t *parity)
{
void CodeIso14443aAsReaderPar(const uint8_t *cmd, uint16_t len, const uint8_t *parity) {
CodeIso14443aBitsAsReaderPar(cmd, len * 8, parity);
}
@ -1606,8 +1581,7 @@ void CodeIso14443aAsReaderPar(const uint8_t *cmd, uint16_t len, const uint8_t *p
// Stop when button is pressed (return 1) or field was gone (return 2)
// Or return 0 when command is captured
//-----------------------------------------------------------------------------
int EmGetCmd(uint8_t *received, uint16_t *len, uint8_t *parity)
{
int EmGetCmd(uint8_t *received, uint16_t *len, uint8_t *parity) {
*len = 0;
uint32_t timer = 0, vtime = 0;
@ -1669,8 +1643,7 @@ int EmGetCmd(uint8_t *received, uint16_t *len, uint8_t *parity)
}
}
int EmSendCmd14443aRaw(uint8_t *resp, uint16_t respLen)
{
int EmSendCmd14443aRaw(uint8_t *resp, uint16_t respLen) {
volatile uint8_t b;
uint16_t i = 0;
uint32_t ThisTransferTime;
@ -1736,8 +1709,7 @@ int EmSendCmd14443aRaw(uint8_t *resp, uint16_t respLen)
return 0;
}
int EmSend4bit(uint8_t resp)
{
int EmSend4bit(uint8_t resp) {
Code4bitAnswerAsTag(resp);
int res = EmSendCmd14443aRaw(ToSend, ToSendMax);
// do the tracing for the previous reader request and this tag answer:
@ -1755,12 +1727,10 @@ int EmSend4bit(uint8_t resp)
par);
return res;
}
int EmSendCmdPar(uint8_t *resp, uint16_t respLen, uint8_t *par)
{
int EmSendCmdPar(uint8_t *resp, uint16_t respLen, uint8_t *par) {
return EmSendCmdParEx(resp, respLen, par, false);
}
int EmSendCmdParEx(uint8_t *resp, uint16_t respLen, uint8_t *par, bool collision)
{
int EmSendCmdParEx(uint8_t *resp, uint16_t respLen, uint8_t *par, bool collision) {
CodeIso14443aAsTagPar(resp, respLen, par, collision);
int res = EmSendCmd14443aRaw(ToSend, ToSendMax);
// do the tracing for the previous reader request and this tag answer:
@ -1776,20 +1746,17 @@ int EmSendCmdParEx(uint8_t *resp, uint16_t respLen, uint8_t *par, bool collision
par);
return res;
}
int EmSendCmd(uint8_t *resp, uint16_t respLen)
{
int EmSendCmd(uint8_t *resp, uint16_t respLen) {
return EmSendCmdEx(resp, respLen, false);
}
int EmSendCmdEx(uint8_t *resp, uint16_t respLen, bool collision)
{
int EmSendCmdEx(uint8_t *resp, uint16_t respLen, bool collision) {
uint8_t par[MAX_PARITY_SIZE] = {0x00};
GetParity(resp, respLen, par);
return EmSendCmdParEx(resp, respLen, par, collision);
}
bool EmLogTrace(uint8_t *reader_data, uint16_t reader_len, uint32_t reader_StartTime, uint32_t reader_EndTime, uint8_t *reader_Parity,
uint8_t *tag_data, uint16_t tag_len, uint32_t tag_StartTime, uint32_t tag_EndTime, uint8_t *tag_Parity)
{
uint8_t *tag_data, uint16_t tag_len, uint32_t tag_StartTime, uint32_t tag_EndTime, uint8_t *tag_Parity) {
// we cannot exactly measure the end and start of a received command from reader. However we know that the delay from
// end of the received command to start of the tag's (simulated by us) answer is n*128+20 or n*128+84 resp.
// with n >= 9. The start of the tags answer can be measured and therefore the end of the received command be calculated:
@ -1811,8 +1778,7 @@ bool EmLogTrace(uint8_t *reader_data, uint16_t reader_len, uint32_t reader_Start
// If a response is captured return TRUE
// If it takes too long return FALSE
//-----------------------------------------------------------------------------
static int GetIso14443aAnswerFromTag(uint8_t *receivedResponse, uint8_t *receivedResponsePar, uint16_t offset)
{
static int GetIso14443aAnswerFromTag(uint8_t *receivedResponse, uint8_t *receivedResponsePar, uint16_t offset) {
uint32_t c = 0;
// Set FPGA mode to "reader listen mode", no modulation (listen
@ -1843,8 +1809,7 @@ static int GetIso14443aAnswerFromTag(uint8_t *receivedResponse, uint8_t *receive
}
}
void ReaderTransmitBitsPar(uint8_t *frame, uint16_t bits, uint8_t *par, uint32_t *timing)
{
void ReaderTransmitBitsPar(uint8_t *frame, uint16_t bits, uint8_t *par, uint32_t *timing) {
CodeIso14443aBitsAsReaderPar(frame, bits, par);
// Send command to tag
@ -1854,37 +1819,32 @@ void ReaderTransmitBitsPar(uint8_t *frame, uint16_t bits, uint8_t *par, uint32_t
LogTrace(frame, nbytes(bits), (LastTimeProxToAirStart << 4) + DELAY_ARM2AIR_AS_READER, ((LastTimeProxToAirStart + LastProxToAirDuration) << 4) + DELAY_ARM2AIR_AS_READER, par, true);
}
void ReaderTransmitPar(uint8_t *frame, uint16_t len, uint8_t *par, uint32_t *timing)
{
void ReaderTransmitPar(uint8_t *frame, uint16_t len, uint8_t *par, uint32_t *timing) {
ReaderTransmitBitsPar(frame, len * 8, par, timing);
}
void ReaderTransmitBits(uint8_t *frame, uint16_t len, uint32_t *timing)
{
void ReaderTransmitBits(uint8_t *frame, uint16_t len, uint32_t *timing) {
// Generate parity and redirect
uint8_t par[MAX_PARITY_SIZE] = {0x00};
GetParity(frame, len / 8, par);
ReaderTransmitBitsPar(frame, len, par, timing);
}
void ReaderTransmit(uint8_t *frame, uint16_t len, uint32_t *timing)
{
void ReaderTransmit(uint8_t *frame, uint16_t len, uint32_t *timing) {
// Generate parity and redirect
uint8_t par[MAX_PARITY_SIZE] = {0x00};
GetParity(frame, len, par);
ReaderTransmitBitsPar(frame, len * 8, par, timing);
}
int ReaderReceiveOffset(uint8_t *receivedAnswer, uint16_t offset, uint8_t *parity)
{
int ReaderReceiveOffset(uint8_t *receivedAnswer, uint16_t offset, uint8_t *parity) {
if (!GetIso14443aAnswerFromTag(receivedAnswer, parity, offset))
return false;
LogTrace(receivedAnswer, Demod.len, Demod.startTime * 16 - DELAY_AIR2ARM_AS_READER, Demod.endTime * 16 - DELAY_AIR2ARM_AS_READER, parity, false);
return Demod.len;
}
int ReaderReceive(uint8_t *receivedAnswer, uint8_t *parity)
{
int ReaderReceive(uint8_t *receivedAnswer, uint8_t *parity) {
if (!GetIso14443aAnswerFromTag(receivedAnswer, parity, 0))
return false;
LogTrace(receivedAnswer, Demod.len, Demod.startTime * 16 - DELAY_AIR2ARM_AS_READER, Demod.endTime * 16 - DELAY_AIR2ARM_AS_READER, parity, false);
@ -1894,8 +1854,7 @@ int ReaderReceive(uint8_t *receivedAnswer, uint8_t *parity)
// This function misstreats the ISO 14443a anticollision procedure.
// by fooling the reader there is a collision and forceing the reader to
// increase the uid bytes. The might be an overflow, DoS will occure.
void iso14443a_antifuzz(uint32_t flags)
{
void iso14443a_antifuzz(uint32_t flags) {
// We need to listen to the high-frequency, peak-detected path.
iso14443a_setup(FPGA_HF_ISO14443A_TAGSIM_LISTEN);
@ -1968,8 +1927,7 @@ void iso14443a_antifuzz(uint32_t flags)
BigBuf_free_keep_EM();
}
static void iso14a_set_ATS_times(uint8_t *ats)
{
static void iso14a_set_ATS_times(uint8_t *ats) {
uint8_t tb1;
uint8_t fwi, sfgi;
@ -1996,8 +1954,7 @@ static void iso14a_set_ATS_times(uint8_t *ats)
}
}
static int GetATQA(uint8_t *resp, uint8_t *resp_par)
{
static int GetATQA(uint8_t *resp, uint8_t *resp_par) {
#define WUPA_RETRY_TIMEOUT 10 // 10ms
uint8_t wupa[] = { ISO14443A_CMD_WUPA }; // 0x26 - REQA 0x52 - WAKE-UP
@ -2026,8 +1983,7 @@ static int GetATQA(uint8_t *resp, uint8_t *resp_par)
// if anticollision is false, then the UID must be provided in uid_ptr[]
// and num_cascades must be set (1: 4 Byte UID, 2: 7 Byte UID, 3: 10 Byte UID)
// requests ATS unless no_rats is true
int iso14443a_select_card(byte_t *uid_ptr, iso14a_card_select_t *p_card, uint32_t *cuid_ptr, bool anticollision, uint8_t num_cascades, bool no_rats)
{
int iso14443a_select_card(byte_t *uid_ptr, iso14a_card_select_t *p_card, uint32_t *cuid_ptr, bool anticollision, uint8_t num_cascades, bool no_rats) {
uint8_t sel_all[] = { ISO14443A_CMD_ANTICOLL_OR_SELECT, 0x20 };
uint8_t sel_uid[] = { ISO14443A_CMD_ANTICOLL_OR_SELECT, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
@ -2184,8 +2140,7 @@ int iso14443a_select_card(byte_t *uid_ptr, iso14a_card_select_t *p_card, uint32_
return 1;
}
int iso14443a_fast_select_card(uint8_t *uid_ptr, uint8_t num_cascades)
{
int iso14443a_fast_select_card(uint8_t *uid_ptr, uint8_t num_cascades) {
uint8_t sel_all[] = { ISO14443A_CMD_ANTICOLL_OR_SELECT, 0x20 };
uint8_t sel_uid[] = { ISO14443A_CMD_ANTICOLL_OR_SELECT, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
uint8_t resp[5] = {0}; // theoretically. A usual RATS will be much smaller
@ -2237,8 +2192,7 @@ int iso14443a_fast_select_card(uint8_t *uid_ptr, uint8_t num_cascades)
return 1;
}
void iso14443a_setup(uint8_t fpga_minor_mode)
{
void iso14443a_setup(uint8_t fpga_minor_mode) {
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
// Set up the synchronous serial port
@ -2249,7 +2203,7 @@ void iso14443a_setup(uint8_t fpga_minor_mode)
LED_D_OFF();
// Signal field is on with the appropriate LED
if (fpga_minor_mode == FPGA_HF_ISO14443A_READER_MOD ||
fpga_minor_mode == FPGA_HF_ISO14443A_READER_LISTEN)
fpga_minor_mode == FPGA_HF_ISO14443A_READER_LISTEN)
LED_D_ON();
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_ISO14443A | fpga_minor_mode);
@ -2289,8 +2243,7 @@ b8 b7 b6 b5 b4 b3 b2 b1
b5,b6 = 00 - DESELECT
11 - WTX
*/
int iso14_apdu(uint8_t *cmd, uint16_t cmd_len, bool send_chaining, void *data, uint8_t *res)
{
int iso14_apdu(uint8_t *cmd, uint16_t cmd_len, bool send_chaining, void *data, uint8_t *res) {
uint8_t parity[MAX_PARITY_SIZE] = {0x00};
uint8_t real_cmd[cmd_len + 4];
@ -2340,9 +2293,9 @@ int iso14_apdu(uint8_t *cmd, uint16_t cmd_len, bool send_chaining, void *data, u
// if we received an I- or R(ACK)-Block with a block number equal to the
// current block number, toggle the current block number
if (len >= 3 // PCB+CRC = 3 bytes
&& ((data_bytes[0] & 0xC0) == 0 // I-Block
|| (data_bytes[0] & 0xD0) == 0x80) // R-Block with ACK bit set to 0
&& (data_bytes[0] & 0x01) == iso14_pcb_blocknum) { // equal block numbers
&& ((data_bytes[0] & 0xC0) == 0 // I-Block
|| (data_bytes[0] & 0xD0) == 0x80) // R-Block with ACK bit set to 0
&& (data_bytes[0] & 0x01) == iso14_pcb_blocknum) { // equal block numbers
iso14_pcb_blocknum ^= 1;
}
@ -2376,8 +2329,7 @@ int iso14_apdu(uint8_t *cmd, uint16_t cmd_len, bool send_chaining, void *data, u
// low :: len of commandbytes
// arg2 timeout
// d.asBytes command bytes to send
void ReaderIso14443a(UsbCommand *c)
{
void ReaderIso14443a(UsbCommand *c) {
iso14a_command_t param = c->arg[0];
size_t len = c->arg[1] & 0xffff;
size_t lenbits = c->arg[1] >> 16;
@ -2477,8 +2429,7 @@ OUT:
// Determine the distance between two nonces.
// Assume that the difference is small, but we don't know which is first.
// Therefore try in alternating directions.
int32_t dist_nt(uint32_t nt1, uint32_t nt2)
{
int32_t dist_nt(uint32_t nt1, uint32_t nt2) {
if (nt1 == nt2) return 0;
@ -2507,8 +2458,7 @@ int32_t dist_nt(uint32_t nt1, uint32_t nt2)
// Cloning MiFare Classic Rail and Building Passes, Anywhere, Anytime"
// (article by Nicolas T. Courtois, 2009)
//-----------------------------------------------------------------------------
void ReaderMifare(bool first_try, uint8_t block, uint8_t keytype)
{
void ReaderMifare(bool first_try, uint8_t block, uint8_t keytype) {
iso14443a_setup(FPGA_HF_ISO14443A_READER_MOD);
@ -2777,8 +2727,7 @@ void ReaderMifare(bool first_try, uint8_t block, uint8_t keytype)
* Mifare Classic NACK-bug detection
* Thanks to @doegox for the feedback and new approaches.
*/
void DetectNACKbug()
{
void DetectNACKbug() {
uint8_t mf_auth[] = {0x60, 0x00, 0xF5, 0x7B};
uint8_t mf_nr_ar[] = {0, 0, 0, 0, 0, 0, 0, 0};
uint8_t uid[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
@ -3013,8 +2962,7 @@ void DetectNACKbug()
*@param exitAfterNReads, exit simulation after n blocks have been read, 0 is inifite
* (unless reader attack mode enabled then it runs util it gets enough nonces to recover all keys attmpted)
*/
void Mifare1ksim(uint8_t flags, uint8_t exitAfterNReads, uint8_t arg2, uint8_t *datain)
{
void Mifare1ksim(uint8_t flags, uint8_t exitAfterNReads, uint8_t arg2, uint8_t *datain) {
int cardSTATE = MFEMUL_NOFIELD;
int _UID_LEN = 0; // 4, 7, 10
@ -3217,9 +3165,9 @@ void Mifare1ksim(uint8_t flags, uint8_t exitAfterNReads, uint8_t arg2, uint8_t *
}
// select card
if (len == 9 &&
(receivedCmd[0] == ISO14443A_CMD_ANTICOLL_OR_SELECT &&
receivedCmd[1] == 0x70 &&
memcmp(&receivedCmd[2], rUIDBCC1, 4) == 0)) {
(receivedCmd[0] == ISO14443A_CMD_ANTICOLL_OR_SELECT &&
receivedCmd[1] == 0x70 &&
memcmp(&receivedCmd[2], rUIDBCC1, 4) == 0)) {
// SAK 4b
EmSendCmd(sak_4, sizeof(sak_4));
@ -3251,9 +3199,9 @@ void Mifare1ksim(uint8_t flags, uint8_t exitAfterNReads, uint8_t arg2, uint8_t *
break;
}
if (len == 9 &&
(receivedCmd[0] == ISO14443A_CMD_ANTICOLL_OR_SELECT_2 &&
receivedCmd[1] == 0x70 &&
memcmp(&receivedCmd[2], rUIDBCC2, 4) == 0)) {
(receivedCmd[0] == ISO14443A_CMD_ANTICOLL_OR_SELECT_2 &&
receivedCmd[1] == 0x70 &&
memcmp(&receivedCmd[2], rUIDBCC2, 4) == 0)) {
EmSendCmd(sak_7, sizeof(sak_7));
switch (_UID_LEN) {
@ -3282,9 +3230,9 @@ void Mifare1ksim(uint8_t flags, uint8_t exitAfterNReads, uint8_t arg2, uint8_t *
break;
}
if (len == 9 &&
(receivedCmd[0] == ISO14443A_CMD_ANTICOLL_OR_SELECT_3 &&
receivedCmd[1] == 0x70 &&
memcmp(&receivedCmd[2], rUIDBCC3, 4) == 0)) {
(receivedCmd[0] == ISO14443A_CMD_ANTICOLL_OR_SELECT_3 &&
receivedCmd[1] == 0x70 &&
memcmp(&receivedCmd[2], rUIDBCC3, 4) == 0)) {
EmSendCmd(sak_10, sizeof(sak_10));
cardSTATE = MFEMUL_WORK;
@ -3459,11 +3407,11 @@ void Mifare1ksim(uint8_t flags, uint8_t exitAfterNReads, uint8_t arg2, uint8_t *
}
if (receivedCmd[0] == ISO14443A_CMD_READBLOCK ||
receivedCmd[0] == ISO14443A_CMD_WRITEBLOCK ||
receivedCmd[0] == MIFARE_CMD_INC ||
receivedCmd[0] == MIFARE_CMD_DEC ||
receivedCmd[0] == MIFARE_CMD_RESTORE ||
receivedCmd[0] == MIFARE_CMD_TRANSFER) {
receivedCmd[0] == ISO14443A_CMD_WRITEBLOCK ||
receivedCmd[0] == MIFARE_CMD_INC ||
receivedCmd[0] == MIFARE_CMD_DEC ||
receivedCmd[0] == MIFARE_CMD_RESTORE ||
receivedCmd[0] == MIFARE_CMD_TRANSFER) {
if (receivedCmd[1] >= 16 * 4) {
EmSend4bit(mf_crypto1_encrypt4bit(pcs, CARD_NACK_NA));
@ -3502,8 +3450,8 @@ void Mifare1ksim(uint8_t flags, uint8_t exitAfterNReads, uint8_t arg2, uint8_t *
}
// increment, decrement, restore
if (receivedCmd[0] == MIFARE_CMD_INC ||
receivedCmd[0] == MIFARE_CMD_DEC ||
receivedCmd[0] == MIFARE_CMD_RESTORE) {
receivedCmd[0] == MIFARE_CMD_DEC ||
receivedCmd[0] == MIFARE_CMD_RESTORE) {
if (MF_DBGLEVEL >= 4) Dbprintf("RECV 0x%02x inc(0xC1)/dec(0xC0)/restore(0xC2) block %d (%02x)", receivedCmd[0], receivedCmd[1], receivedCmd[1]);

View file

@ -77,8 +77,7 @@ static struct {
uint8_t *output;
} Uart;
static void UartReset()
{
static void UartReset() {
Uart.state = STATE_UNSYNCD;
Uart.shiftReg = 0;
Uart.bitCnt = 0;
@ -87,8 +86,7 @@ static void UartReset()
Uart.posCnt = 0;
}
static void UartInit(uint8_t *data)
{
static void UartInit(uint8_t *data) {
Uart.output = data;
UartReset();
// memset(Uart.output, 0x00, MAX_FRAME_SIZE);
@ -122,8 +120,7 @@ static struct {
} Demod;
// Clear out the state of the "UART" that receives from the tag.
static void DemodReset()
{
static void DemodReset() {
Demod.state = DEMOD_UNSYNCD;
Demod.bitCount = 0;
Demod.posCount = 0;
@ -136,8 +133,7 @@ static void DemodReset()
Demod.endTime = 0;
}
static void DemodInit(uint8_t *data)
{
static void DemodInit(uint8_t *data) {
Demod.output = data;
DemodReset();
// memset(Demod.output, 0x00, MAX_FRAME_SIZE);
@ -157,8 +153,7 @@ static void DemodInit(uint8_t *data)
* 13560000000 / 384000 = 35312 FWT
* @param timeout is in frame wait time, fwt, measured in ETUs
*/
static void iso14b_set_timeout(uint32_t timeout)
{
static void iso14b_set_timeout(uint32_t timeout) {
#define MAX_TIMEOUT 40542464 // 13560000Hz * 1000ms / (2^32-1) * (8*16)
if (timeout > MAX_TIMEOUT)
timeout = MAX_TIMEOUT;
@ -166,8 +161,7 @@ static void iso14b_set_timeout(uint32_t timeout)
iso14b_timeout = timeout;
if (MF_DBGLEVEL >= 3) Dbprintf("ISO14443B Timeout set to %ld fwt", iso14b_timeout);
}
static void iso14b_set_maxframesize(uint16_t size)
{
static void iso14b_set_maxframesize(uint16_t size) {
if (size > 256)
size = MAX_FRAME_SIZE;
@ -180,8 +174,7 @@ static void iso14b_set_maxframesize(uint16_t size)
// 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 uint8_t *cmd, int len)
{
static void CodeIso14443bAsTag(const uint8_t *cmd, int len) {
/* ISO 14443 B
*
* Reader to card | ASK - Amplitude Shift Keying Modulation (PCD to PICC for Type B) (NRZ-L encodig)
@ -323,8 +316,7 @@ static void CodeIso14443bAsTag(const uint8_t *cmd, int len)
* Returns: true if we received a EOF
* false if we are still waiting for some more
*/
static RAMFUNC int Handle14443bReaderUartBit(uint8_t bit)
{
static RAMFUNC int Handle14443bReaderUartBit(uint8_t bit) {
switch (Uart.state) {
case STATE_UNSYNCD:
if (!bit) {
@ -440,8 +432,7 @@ static RAMFUNC int Handle14443bReaderUartBit(uint8_t bit)
// Assume that we're called with the SSC (to the FPGA) and ADC path set
// correctly.
//-----------------------------------------------------------------------------
static int GetIso14443bCommandFromReader(uint8_t *received, uint16_t *len)
{
static int GetIso14443bCommandFromReader(uint8_t *received, uint16_t *len) {
// Set FPGA mode to "simulated ISO 14443B tag", no modulation (listen
// only, since we are receiving, not transmitting).
// Signal field is off with the appropriate LED
@ -493,8 +484,7 @@ static int GetIso14443bCommandFromReader(uint8_t *received, uint16_t *len)
return false;
}
void ClearFpgaShiftingRegisters(void)
{
void ClearFpgaShiftingRegisters(void) {
volatile uint8_t b;
@ -519,8 +509,7 @@ void ClearFpgaShiftingRegisters(void)
//AT91C_BASE_SSC->SSC_THR = 0xFF;
}
void WaitForFpgaDelayQueueIsEmpty(uint16_t delay)
{
void WaitForFpgaDelayQueueIsEmpty(uint16_t delay) {
// Ensure that the FPGA Delay Queue is empty before we switch to TAGSIM_LISTEN again:
uint8_t fpga_queued_bits = delay >> 3; // twich /8 ?? >>3,
for (uint8_t i = 0; i <= fpga_queued_bits / 8 + 1;) {
@ -531,8 +520,7 @@ void WaitForFpgaDelayQueueIsEmpty(uint16_t delay)
}
}
static void TransmitFor14443b_AsTag(uint8_t *response, uint16_t len)
{
static void TransmitFor14443b_AsTag(uint8_t *response, uint16_t len) {
volatile uint32_t b;
@ -570,8 +558,7 @@ static void TransmitFor14443b_AsTag(uint8_t *response, uint16_t len)
// Main loop of simulated tag: receive commands from reader, decide what
// response to send, and send it.
//-----------------------------------------------------------------------------
void SimulateIso14443bTag(uint32_t pupi)
{
void SimulateIso14443bTag(uint32_t pupi) {
// setup device.
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
@ -656,7 +643,7 @@ void SimulateIso14443bTag(uint32_t pupi)
// WUP in HALTED state
if (len == 5) {
if ((receivedCmd[0] == ISO14443B_REQB && (receivedCmd[2] & 0x8) == 0x8 && cardSTATE == SIM_HALTED) ||
receivedCmd[0] == ISO14443B_REQB) {
receivedCmd[0] == ISO14443B_REQB) {
LogTrace(receivedCmd, len, 0, 0, NULL, true);
cardSTATE = SIM_SELECTING;
}
@ -753,8 +740,7 @@ void SimulateIso14443bTag(uint32_t pupi)
* false if we are still waiting for some more
*
*/
static RAMFUNC int Handle14443bTagSamplesDemod(int ci, int cq)
{
static RAMFUNC int Handle14443bTagSamplesDemod(int ci, int cq) {
int v = 0, myI = ABS(ci), myQ = ABS(cq);
// The soft decision on the bit uses an estimate of just the
@ -958,8 +944,7 @@ static RAMFUNC int Handle14443bTagSamplesDemod(int ci, int cq)
* Demodulate the samples we received from the tag, also log to tracebuffer
* quiet: set to 'TRUE' to disable debug output
*/
static void GetTagSamplesFor14443bDemod()
{
static void GetTagSamplesFor14443bDemod() {
bool gotFrame = false, finished = false;
int lastRxCounter = ISO14443B_DMA_BUFFER_SIZE;
int ci = 0, cq = 0;
@ -1025,8 +1010,7 @@ static void GetTagSamplesFor14443bDemod()
//-----------------------------------------------------------------------------
// Transmit the command (to the tag) that was placed in ToSend[].
//-----------------------------------------------------------------------------
static void TransmitFor14443b_AsReader(void)
{
static void TransmitFor14443b_AsReader(void) {
int c;
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_TX | FPGA_HF_READER_TX_SHALLOW_MOD);
@ -1060,8 +1044,7 @@ static void TransmitFor14443b_AsReader(void)
// Code a layer 2 command (string of octets, including CRC) into ToSend[],
// so that it is ready to transmit to the tag using TransmitFor14443b().
//-----------------------------------------------------------------------------
static void CodeIso14443bAsReader(const uint8_t *cmd, int len)
{
static void CodeIso14443bAsReader(const uint8_t *cmd, int len) {
/*
* Reader data transmission:
* - no modulation ONES
@ -1142,8 +1125,7 @@ static void CodeIso14443bAsReader(const uint8_t *cmd, int len)
/*
* Convenience function to encode, transmit and trace iso 14443b comms
*/
static void CodeAndTransmit14443bAsReader(const uint8_t *cmd, int len)
{
static void CodeAndTransmit14443bAsReader(const uint8_t *cmd, int len) {
uint32_t time_start = GetCountSspClk();
@ -1159,8 +1141,7 @@ static void CodeAndTransmit14443bAsReader(const uint8_t *cmd, int len)
/* Sends an APDU to the tag
* TODO: check CRC and preamble
*/
uint8_t iso14443b_apdu(uint8_t const *message, size_t message_length, uint8_t *response)
{
uint8_t iso14443b_apdu(uint8_t const *message, size_t message_length, uint8_t *response) {
uint8_t message_frame[message_length + 4];
// PCB
@ -1194,8 +1175,7 @@ uint8_t iso14443b_apdu(uint8_t const *message, size_t message_length, uint8_t *r
/**
* SRx Initialise.
*/
uint8_t iso14443b_select_srx_card(iso14b_card_select_t *card)
{
uint8_t iso14443b_select_srx_card(iso14b_card_select_t *card) {
// INITIATE command: wake up the tag using the INITIATE
static const uint8_t init_srx[] = { ISO14443B_INITIATE, 0x00, 0x97, 0x5b };
// SELECT command (with space for CRC)
@ -1255,8 +1235,7 @@ uint8_t iso14443b_select_srx_card(iso14b_card_select_t *card)
* TODO: Support multiple cards (perform anticollision)
* TODO: Verify CRC checksums
*/
uint8_t iso14443b_select_card(iso14b_card_select_t *card)
{
uint8_t iso14443b_select_card(iso14b_card_select_t *card) {
// WUPB command (including CRC)
// Note: WUPB wakes up all tags, REQB doesn't wake up tags in HALT state
static const uint8_t wupb[] = { ISO14443B_REQB, 0x00, 0x08, 0x39, 0x73 };
@ -1328,8 +1307,7 @@ uint8_t iso14443b_select_card(iso14b_card_select_t *card)
// Set up ISO 14443 Type B communication (similar to iso14443a_setup)
// field is setup for "Sending as Reader"
void iso14443b_setup()
{
void iso14443b_setup() {
LEDsoff();
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
@ -1362,8 +1340,7 @@ void iso14443b_setup()
//
// I tried to be systematic and check every answer of the tag, every CRC, etc...
//-----------------------------------------------------------------------------
static bool ReadSTBlock(uint8_t block)
{
static bool ReadSTBlock(uint8_t block) {
uint8_t cmd[] = {ISO14443B_READ_BLK, block, 0x00, 0x00};
AddCrc14B(cmd, 2);
CodeAndTransmit14443bAsReader(cmd, sizeof(cmd));
@ -1381,8 +1358,7 @@ static bool ReadSTBlock(uint8_t block)
}
return true;
}
void ReadSTMemoryIso14443b(uint8_t numofblocks)
{
void ReadSTMemoryIso14443b(uint8_t numofblocks) {
// Make sure that we start from off, since the tags are stateful;
// confusing things will happen if we don't reset them between reads.
//switch_off();
@ -1431,8 +1407,7 @@ out:
SpinDelay(20);
}
static void iso1444b_setup_sniff(void)
{
static void iso1444b_setup_sniff(void) {
LEDsoff();
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
@ -1485,8 +1460,7 @@ static void iso1444b_setup_sniff(void)
* DMA Buffer - ISO14443B_DMA_BUFFER_SIZE
* Demodulated samples received - all the rest
*/
void RAMFUNC SniffIso14443b(void)
{
void RAMFUNC SniffIso14443b(void) {
uint32_t time_0 = 0, time_start = 0, time_stop = 0;
int ci = 0, cq = 0;
@ -1578,8 +1552,7 @@ void RAMFUNC SniffIso14443b(void)
switch_off();
}
void iso14b_set_trigger(bool enable)
{
void iso14b_set_trigger(bool enable) {
trigger = enable;
}
@ -1594,8 +1567,7 @@ void iso14b_set_trigger(bool enable)
* none
*
*/
void SendRawCommand14443B_Ex(UsbCommand *c)
{
void SendRawCommand14443B_Ex(UsbCommand *c) {
iso14b_command_t param = c->arg[0];
size_t len = c->arg[1] & 0xffff;
uint8_t *cmd = c->d.asBytes;

View file

@ -99,8 +99,7 @@ static void BuildInventoryResponse(uint8_t *cmdout, uint8_t *uid);
// resulting data rate is 26,48 kbit/s (fc/512)
// cmd ... data
// n ... length of data
static void CodeIso15693AsReader(uint8_t *cmd, int n)
{
static void CodeIso15693AsReader(uint8_t *cmd, int n) {
int i, j;
ToSendReset();
@ -179,8 +178,7 @@ static void CodeIso15693AsReader(uint8_t *cmd, int n)
// encode data using "1 out of 256" sheme
// data rate is 1,66 kbit/s (fc/8192)
// is designed for more robust communication over longer distances
static void CodeIso15693AsReader256(uint8_t *cmd, int n)
{
static void CodeIso15693AsReader256(uint8_t *cmd, int n) {
int i, j;
ToSendReset();
@ -222,8 +220,7 @@ static void CodeIso15693AsReader256(uint8_t *cmd, int n)
}
// Transmit the command (to the tag) that was placed in ToSend[].
static void TransmitTo15693Tag(const uint8_t *cmd, int len, int *samples, int *wait)
{
static void TransmitTo15693Tag(const uint8_t *cmd, int len, int *samples, int *wait) {
int c;
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_TX);
@ -258,8 +255,7 @@ static void TransmitTo15693Tag(const uint8_t *cmd, int len, int *samples, int *w
//-----------------------------------------------------------------------------
// Transmit the command (to the reader) that was placed in ToSend[].
//-----------------------------------------------------------------------------
static void TransmitTo15693Reader(const uint8_t *cmd, int len, int *samples, int *wait)
{
static void TransmitTo15693Reader(const uint8_t *cmd, int len, int *samples, int *wait) {
int c = 0;
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_SIMULATOR | FPGA_HF_SIMULATOR_MODULATE_424K);
@ -292,8 +288,7 @@ static void TransmitTo15693Reader(const uint8_t *cmd, int len, int *samples, int
//-----------------------------------------------------------------------------
// DEMODULATE tag answer
//-----------------------------------------------------------------------------
static int DemodAnswer(uint8_t *received, uint8_t *dest, uint16_t samplecount)
{
static int DemodAnswer(uint8_t *received, uint8_t *dest, uint16_t samplecount) {
int i, j;
int max = 0, maxPos = 0, skip = 4;
@ -386,8 +381,7 @@ static int DemodAnswer(uint8_t *received, uint8_t *dest, uint16_t samplecount)
// returns:
// number of decoded bytes
// logging enabled
static int GetIso15693AnswerFromTag(uint8_t *received, int *elapsed)
{
static int GetIso15693AnswerFromTag(uint8_t *received, int *elapsed) {
#define SIGNAL_BUFF_SIZE 15000
// get current clock
@ -441,8 +435,7 @@ static int GetIso15693AnswerFromTag(uint8_t *received, int *elapsed)
// Now the GetISO15693 message from sniffing command
// logging enable,
static int GetIso15693AnswerFromSniff(uint8_t *received, int *samples, int *elapsed)
{
static int GetIso15693AnswerFromSniff(uint8_t *received, int *samples, int *elapsed) {
bool getNext = false;
int counter = 0, ci = 0, cq = 0;
@ -490,8 +483,7 @@ static int GetIso15693AnswerFromSniff(uint8_t *received, int *samples, int *elap
// for the response. The response is not demodulated, just left in the buffer
// so that it can be downloaded to a PC and processed there.
//-----------------------------------------------------------------------------
void AcquireRawAdcSamplesIso15693(void)
{
void AcquireRawAdcSamplesIso15693(void) {
int c = 0, getNext = false;
int ci = 0, cq = 0;
@ -557,8 +549,7 @@ void AcquireRawAdcSamplesIso15693(void)
}
// switch_off, initreader, no logging
void RecordRawAdcSamplesIso15693(void)
{
void RecordRawAdcSamplesIso15693(void) {
int c = 0, getNext = false;
int ci = 0, cq = 0;
@ -598,8 +589,7 @@ void RecordRawAdcSamplesIso15693(void)
// Initialize the proxmark as iso15k reader
// (this might produces glitches that confuse some tags
void Iso15693InitReader(void)
{
void Iso15693InitReader(void) {
LEDsoff();
clear_trace();
set_tracing(true);
@ -631,8 +621,7 @@ void Iso15693InitReader(void)
// Encode (into the ToSend buffers) an identify request, which is the first
// thing that you must send to a tag to get a response.
static void BuildIdentifyRequest(uint8_t *out)
{
static void BuildIdentifyRequest(uint8_t *out) {
uint8_t cmd[CMD_ID_RESP] = {0, ISO15_CMD_INVENTORY, 0, 0, 0};
// flags
@ -676,8 +665,7 @@ static void BuildReadBlockRequest(uint8_t **out, uint8_t *uid, uint8_t blockNumb
*/
// Now the VICC>VCD responses when we are simulating a tag
static void BuildInventoryResponse(uint8_t *out, uint8_t *uid)
{
static void BuildInventoryResponse(uint8_t *out, uint8_t *uid) {
uint8_t cmd[CMD_INV_RESP] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
@ -708,8 +696,7 @@ static void BuildInventoryResponse(uint8_t *out, uint8_t *uid)
// If you do not need the answer use NULL for *recv[]
// return: lenght of received data
// logging enabled
int SendDataTag(uint8_t *send, int sendlen, bool init, int speed, uint8_t *outdata)
{
int SendDataTag(uint8_t *send, int sendlen, bool init, int speed, uint8_t *outdata) {
int t_samples = 0, wait = 0, elapsed = 0, answer_len = 0;
@ -747,8 +734,7 @@ int SendDataTag(uint8_t *send, int sendlen, bool init, int speed, uint8_t *outda
// Decodes a message from a tag and displays its metadata and content
#define DBD15STATLEN 48
void DbdecodeIso15693Answer(int len, uint8_t *d)
{
void DbdecodeIso15693Answer(int len, uint8_t *d) {
char status[DBD15STATLEN + 1] = {0};
if (len > 3) {
@ -812,8 +798,7 @@ void DbdecodeIso15693Answer(int len, uint8_t *d)
//-----------------------------------------------------------------------------
// ok
// parameter is unused !?!
void ReaderIso15693(uint32_t parameter)
{
void ReaderIso15693(uint32_t parameter) {
int answerLen1 = 0;
int tsamples = 0, wait = 0, elapsed = 0;
@ -877,8 +862,7 @@ void ReaderIso15693(uint32_t parameter)
// Simulate an ISO15693 TAG, perform anti-collision and then print any reader commands
// all demodulation performed in arm rather than host. - greg
void SimTagIso15693(uint32_t parameter, uint8_t *uid)
{
void SimTagIso15693(uint32_t parameter, uint8_t *uid) {
LEDsoff();
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
@ -932,8 +916,7 @@ void SimTagIso15693(uint32_t parameter, uint8_t *uid)
// Since there is no standardized way of reading the AFI out of a tag, we will brute force it
// (some manufactures offer a way to read the AFI, though)
void BruteforceIso15693Afi(uint32_t speed)
{
void BruteforceIso15693Afi(uint32_t speed) {
uint8_t data[7] = {0, 0, 0, 0, 0, 0, 0};
uint8_t buf[ISO15_MAX_FRAME];
@ -987,8 +970,7 @@ void BruteforceIso15693Afi(uint32_t speed)
// Allows to directly send commands to the tag via the client
// Has to increase dialog between device and client.
void DirectTag15693Command(uint32_t datalen, uint32_t speed, uint32_t recv, uint8_t *data)
{
void DirectTag15693Command(uint32_t datalen, uint32_t speed, uint32_t recv, uint8_t *data) {
bool init = true;
int buflen = 0;

View file

@ -56,8 +56,7 @@ static uint32_t last_frame_end; /* ts of last bit of previews rx or tx frame */
// I/O interface abstraction (FPGA -> ARM)
//-----------------------------------------------------------------------------
static inline uint8_t rx_byte_from_fpga()
{
static inline uint8_t rx_byte_from_fpga() {
for (;;) {
WDT_HIT();
@ -84,8 +83,7 @@ static inline uint8_t rx_byte_from_fpga()
//
// Note: The SSC receiver is never synchronized the calculation may be performed
// on a i/q pair from two subsequent correlations, but does not matter.
static inline int32_t sample_power()
{
static inline int32_t sample_power() {
int32_t q = (int8_t)rx_byte_from_fpga();
q = ABS(q);
int32_t i = (int8_t)rx_byte_from_fpga();
@ -101,8 +99,7 @@ static inline int32_t sample_power()
//
// Note: The demodulator would be drifting (18.9us * 5 != 100us), rx_frame
// has a delay loop that aligns rx_bit calls to the TAG tx timeslots.
static inline bool rx_bit()
{
static inline bool rx_bit() {
int32_t power;
for (size_t i = 0; i < 5; ++i) {
@ -121,8 +118,7 @@ static inline bool rx_bit()
// be circumvented, but the adventage over bitbang would be little.
//-----------------------------------------------------------------------------
static inline void tx_bit(bool bit)
{
static inline void tx_bit(bool bit) {
// insert pause
LOW(GPIO_SSC_DOUT);
last_frame_end += RWD_TIME_PAUSE;
@ -144,8 +140,7 @@ static inline void tx_bit(bool bit)
// present.
//-----------------------------------------------------------------------------
static void tx_frame(uint32_t frame, uint8_t len)
{
static void tx_frame(uint32_t frame, uint8_t len) {
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_TX);
// wait for next tx timeslot
@ -173,8 +168,7 @@ static void tx_frame(uint32_t frame, uint8_t len)
LogTrace(cmdbytes, sizeof(cmdbytes), last_frame_start, last_frame_end, NULL, true);
}
static uint32_t rx_frame(uint8_t len)
{
static uint32_t rx_frame(uint8_t len) {
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_RX_XCORR
| FPGA_HF_READER_RX_XCORR_848_KHZ
| FPGA_HF_READER_RX_XCORR_QUARTER);
@ -203,8 +197,7 @@ static uint32_t rx_frame(uint8_t len)
return frame;
}
static bool rx_ack()
{
static bool rx_ack() {
// change fpga into rx mode
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_RX_XCORR
| FPGA_HF_READER_RX_XCORR_848_KHZ
@ -244,8 +237,7 @@ static bool rx_ack()
// Legic Reader
//-----------------------------------------------------------------------------
static int init_card(uint8_t cardtype, legic_card_select_t *p_card)
{
static int init_card(uint8_t cardtype, legic_card_select_t *p_card) {
p_card->tagtype = cardtype;
switch (p_card->tagtype) {
@ -273,8 +265,7 @@ static int init_card(uint8_t cardtype, legic_card_select_t *p_card)
return 0;
}
static void init_reader(bool clear_mem)
{
static void init_reader(bool clear_mem) {
// configure FPGA
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_READER_RX_XCORR
@ -314,8 +305,7 @@ static void init_reader(bool clear_mem)
// - Transmit initialisation vector 7 bits
// - Receive card type 6 bits
// - Transmit Acknowledge 6 bits
static uint32_t setup_phase(uint8_t iv)
{
static uint32_t setup_phase(uint8_t iv) {
// init coordination timestamp
last_frame_end = GET_TICKS;
@ -348,15 +338,13 @@ static uint32_t setup_phase(uint8_t iv)
return card_type;
}
static uint8_t calc_crc4(uint16_t cmd, uint8_t cmd_sz, uint8_t value)
{
static uint8_t calc_crc4(uint16_t cmd, uint8_t cmd_sz, uint8_t value) {
crc_clear(&legic_crc);
crc_update(&legic_crc, (value << cmd_sz) | cmd, 8 + cmd_sz);
return crc_finish(&legic_crc);
}
static int16_t read_byte(uint16_t index, uint8_t cmd_sz)
{
static int16_t read_byte(uint16_t index, uint8_t cmd_sz) {
uint16_t cmd = (index << 1) | LEGIC_READ;
// read one byte
@ -385,8 +373,7 @@ static int16_t read_byte(uint16_t index, uint8_t cmd_sz)
// Transmit write command, wait until (3.6ms) the tag sends back an unencrypted
// ACK ('1' bit) and forward the prng time based.
bool write_byte(uint16_t index, uint8_t byte, uint8_t addr_sz)
{
bool write_byte(uint16_t index, uint8_t byte, uint8_t addr_sz) {
uint32_t cmd = index << 1 | LEGIC_WRITE; // prepare command
uint8_t crc = calc_crc4(cmd, addr_sz + 1, byte); // calculate crc
cmd |= byte << (addr_sz + 1); // append value
@ -408,8 +395,7 @@ bool write_byte(uint16_t index, uint8_t byte, uint8_t addr_sz)
//
// Only this functions are public / called from appmain.c
//-----------------------------------------------------------------------------
void LegicRfInfo(void)
{
void LegicRfInfo(void) {
// configure ARM and FPGA
init_reader(false);
@ -446,8 +432,7 @@ OUT:
StopTicks();
}
void LegicRfReader(uint16_t offset, uint16_t len, uint8_t iv)
{
void LegicRfReader(uint16_t offset, uint16_t len, uint8_t iv) {
// configure ARM and FPGA
init_reader(false);
@ -480,8 +465,7 @@ OUT:
StopTicks();
}
void LegicRfWriter(uint16_t offset, uint16_t len, uint8_t iv, uint8_t *data)
{
void LegicRfWriter(uint16_t offset, uint16_t len, uint8_t iv, uint8_t *data) {
// configure ARM and FPGA
init_reader(false);

View file

@ -58,8 +58,7 @@ static uint32_t last_frame_end; /* ts of last bit of previews rx or tx frame */
//-----------------------------------------------------------------------------
// Returns true if a pulse/pause is received within timeout
static inline bool wait_for(bool value, const uint32_t timeout)
{
static inline bool wait_for(bool value, const uint32_t timeout) {
while ((bool)(AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_DIN) != value) {
if (GetCountSspClk() > timeout) {
return false;
@ -77,8 +76,7 @@ static inline bool wait_for(bool value, const uint32_t timeout)
// - A bit length >80.2us is a 1
// - A bit length <80.2us is a 0
// - A bit length >148.6us is a code violation
static inline int8_t rx_bit()
{
static inline int8_t rx_bit() {
// backup ts for threshold calculation
uint32_t bit_start = last_frame_end;
@ -121,8 +119,7 @@ static inline int8_t rx_bit()
// Note: The Subcarrier is not disabled during bits to prevent glitches. This is
// not mandatory but results in a cleaner signal. tx_frame will disable
// the subcarrier when the frame is done.
static inline void tx_bit(bool bit)
{
static inline void tx_bit(bool bit) {
LED_C_ON();
if (bit) {
@ -149,8 +146,7 @@ static inline void tx_bit(bool bit)
// and depends only the command received (IV, ACK, READ or WRITE).
//-----------------------------------------------------------------------------
static void tx_frame(uint32_t frame, uint8_t len)
{
static void tx_frame(uint32_t frame, uint8_t len) {
// wait for next tx timeslot
last_frame_end += TAG_FRAME_WAIT;
legic_prng_forward(TAG_FRAME_WAIT / TAG_BIT_PERIOD - 1);
@ -174,8 +170,7 @@ static void tx_frame(uint32_t frame, uint8_t len)
LogTrace(cmdbytes, sizeof(cmdbytes), last_frame_start, last_frame_end, NULL, false);
}
static void tx_ack()
{
static void tx_ack() {
// wait for ack timeslot
last_frame_end += TAG_ACK_WAIT;
legic_prng_forward(TAG_ACK_WAIT / TAG_BIT_PERIOD - 1);
@ -203,8 +198,7 @@ static void tx_ack()
// - forward prng based on ts/TAG_BIT_PERIOD
// - receive the frame
// - detect end of frame (last pause)
static int32_t rx_frame(uint8_t *len)
{
static int32_t rx_frame(uint8_t *len) {
int32_t frame = 0;
// add 2 SSP clock cycles (1 for tx and 1 for rx pipeline delay)
@ -269,8 +263,7 @@ static int32_t rx_frame(uint8_t *len)
// Legic Simulator
//-----------------------------------------------------------------------------
static int32_t init_card(uint8_t cardtype, legic_card_select_t *p_card)
{
static int32_t init_card(uint8_t cardtype, legic_card_select_t *p_card) {
p_card->tagtype = cardtype;
switch (p_card->tagtype) {
@ -298,8 +291,7 @@ static int32_t init_card(uint8_t cardtype, legic_card_select_t *p_card)
return 0;
}
static void init_tag()
{
static void init_tag() {
// configure FPGA
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
FpgaWriteConfWord(FPGA_MAJOR_MODE_HF_SIMULATOR
@ -334,8 +326,7 @@ static void init_tag()
// - Receive initialisation vector 7 bits
// - Transmit card type 6 bits
// - Receive Acknowledge 6 bits
static int32_t setup_phase(legic_card_select_t *p_card)
{
static int32_t setup_phase(legic_card_select_t *p_card) {
uint8_t len = 0;
// init coordination timestamp
@ -396,15 +387,13 @@ static int32_t setup_phase(legic_card_select_t *p_card)
return 0;
}
static uint8_t calc_crc4(uint16_t cmd, uint8_t cmd_sz, uint8_t value)
{
static uint8_t calc_crc4(uint16_t cmd, uint8_t cmd_sz, uint8_t value) {
crc_clear(&legic_crc);
crc_update(&legic_crc, (value << cmd_sz) | cmd, 8 + cmd_sz);
return crc_finish(&legic_crc);
}
static int32_t connected_phase(legic_card_select_t *p_card)
{
static int32_t connected_phase(legic_card_select_t *p_card) {
uint8_t len = 0;
// wait for command
@ -458,8 +447,7 @@ static int32_t connected_phase(legic_card_select_t *p_card)
// Only this function is public / called from appmain.c
//-----------------------------------------------------------------------------
void LegicRfSimulate(uint8_t cardtype)
{
void LegicRfSimulate(uint8_t cardtype) {
// configure ARM and FPGA
init_tag();

View file

@ -61,8 +61,7 @@ Default LF T55xx config is set to:
*/
t55xx_config t_config = { 29 * 8, 17 * 8, 15 * 8, 47 * 8, 15 * 8 } ;
void printT55xxConfig(void)
{
void printT55xxConfig(void) {
Dbprintf("LF T55XX config");
Dbprintf(" [a] startgap............%d*8 (%d)", t_config.start_gap / 8, t_config.start_gap);
Dbprintf(" [b] writegap............%d*8 (%d)", t_config.write_gap / 8, t_config.write_gap);
@ -71,8 +70,7 @@ void printT55xxConfig(void)
Dbprintf(" [e] readgap.............%d*8 (%d)", t_config.read_gap / 8, t_config.read_gap);
}
void setT55xxConfig(uint8_t arg0, t55xx_config *c)
{
void setT55xxConfig(uint8_t arg0, t55xx_config *c) {
if (c->start_gap != 0) t_config.start_gap = c->start_gap;
if (c->write_gap != 0) t_config.write_gap = c->write_gap;
@ -116,13 +114,11 @@ void setT55xxConfig(uint8_t arg0, t55xx_config *c)
#endif
}
t55xx_config *getT55xxConfig(void)
{
t55xx_config *getT55xxConfig(void) {
return &t_config;
}
void loadT55xxConfig(void)
{
void loadT55xxConfig(void) {
#ifdef WITH_FLASH
if (!FlashInit()) {
return;
@ -160,8 +156,7 @@ void loadT55xxConfig(void)
* @param period_1
* @param command (in binary char array)
*/
void ModThenAcquireRawAdcSamples125k(uint32_t delay_off, uint32_t period_0, uint32_t period_1, uint8_t *command)
{
void ModThenAcquireRawAdcSamples125k(uint32_t delay_off, uint32_t period_0, uint32_t period_1, uint8_t *command) {
// start timer
StartTicks();
@ -266,8 +261,7 @@ void ModThenAcquireRawAdcSamples125k(uint32_t delay_off, uint32_t period_0, uint
[5555fe852c5555555555555555fe0000]
*/
void ReadTItag(void)
{
void ReadTItag(void) {
StartTicks();
// some hardcoded initial params
// when we read a TI tag we sample the zerocross line at 2Mhz
@ -397,8 +391,7 @@ void ReadTItag(void)
StopTicks();
}
void WriteTIbyte(uint8_t b)
{
void WriteTIbyte(uint8_t b) {
int i = 0;
// modulate 8 bits out to the antenna
@ -421,8 +414,7 @@ void WriteTIbyte(uint8_t b)
}
}
void AcquireTiType(void)
{
void AcquireTiType(void) {
int i, j, n;
// tag transmission is <20ms, sampling at 2M gives us 40K samples max
// each sample is 1 bit stuffed into a uint32_t so we need 1250 uint32_t
@ -504,8 +496,7 @@ void AcquireTiType(void)
// 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(uint32_t idhi, uint32_t idlo, uint16_t crc)
{
void WriteTItag(uint32_t idhi, uint32_t idlo, uint16_t crc) {
FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
if (crc == 0) {
crc = update_crc16(crc, (idlo) & 0xff);
@ -577,8 +568,7 @@ void WriteTItag(uint32_t idhi, uint32_t idlo, uint16_t crc)
// note: a call to FpgaDownloadAndGo(FPGA_BITSTREAM_LF) must be done before, but
// this may destroy the bigbuf so be sure this is called before calling SimulateTagLowFrequencyEx
void SimulateTagLowFrequencyEx(int period, int gap, int ledcontrol, int numcycles)
{
void SimulateTagLowFrequencyEx(int period, int gap, int ledcontrol, int numcycles) {
// start us timer
StartTicks();
@ -662,22 +652,19 @@ OUT:
LED_D_OFF();
}
void SimulateTagLowFrequency(int period, int gap, int ledcontrol)
{
void SimulateTagLowFrequency(int period, int gap, int ledcontrol) {
SimulateTagLowFrequencyEx(period, gap, ledcontrol, -1);
}
#define DEBUG_FRAME_CONTENTS 1
void SimulateTagLowFrequencyBidir(int divisor, int t0)
{
void SimulateTagLowFrequencyBidir(int divisor, int t0) {
}
// compose fc/5 fc/8 waveform (FSK1)
// compose fc/8 fc/10 waveform (FSK2)
// also manchester,
static void fc(int c, int *n)
{
static void fc(int c, int *n) {
uint8_t *dest = BigBuf_get_addr();
int idx;
@ -726,8 +713,7 @@ static void fc(int c, int *n)
// special start of frame marker containing invalid bit sequences
// this one is focused on HID, with manchester encoding.
static void fcSTT(int *n)
{
static void fcSTT(int *n) {
fc(8, n);
fc(8, n); // invalid
fc(8, n);
@ -739,8 +725,7 @@ static void fcSTT(int *n)
}
// compose fc/X fc/Y waveform (FSKx)
static void fcAll(uint8_t fc, int *n, uint8_t clock, uint16_t *modCnt)
{
static void fcAll(uint8_t fc, int *n, uint8_t clock, uint16_t *modCnt) {
uint8_t *dest = BigBuf_get_addr();
uint8_t halfFC = fc >> 1;
uint8_t wavesPerClock = clock / fc;
@ -773,8 +758,7 @@ static void fcAll(uint8_t fc, int *n, uint8_t clock, uint16_t *modCnt)
// prepare a waveform pattern in the buffer based on the ID given then
// simulate a HID tag until the button is pressed
void CmdHIDsimTAGEx(uint32_t hi, uint32_t lo, int ledcontrol, int numcycles)
{
void CmdHIDsimTAGEx(uint32_t hi, uint32_t lo, int ledcontrol, int numcycles) {
if (hi > 0xFFF) {
DbpString("[!] tags can only have 44 bits. - USE lf simfsk for larger tags");
@ -837,8 +821,7 @@ void CmdHIDsimTAGEx(uint32_t hi, uint32_t lo, int ledcontrol, int numcycles)
if (ledcontrol) LED_A_OFF();
}
void CmdHIDsimTAG(uint32_t hi, uint32_t lo, int ledcontrol)
{
void CmdHIDsimTAG(uint32_t hi, uint32_t lo, int ledcontrol) {
CmdHIDsimTAGEx(hi, lo, ledcontrol, -1);
DbpString("[!] simulation finished");
}
@ -846,8 +829,7 @@ void CmdHIDsimTAG(uint32_t hi, uint32_t lo, int ledcontrol)
// prepare a waveform pattern in the buffer based on the ID given then
// simulate a FSK tag until the button is pressed
// arg1 contains fcHigh and fcLow, arg2 contains STT marker and clock
void CmdFSKsimTAG(uint16_t arg1, uint16_t arg2, size_t size, uint8_t *bits)
{
void CmdFSKsimTAG(uint16_t arg1, uint16_t arg2, size_t size, uint8_t *bits) {
FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
// free eventually allocated BigBuf memory
@ -885,8 +867,7 @@ void CmdFSKsimTAG(uint16_t arg1, uint16_t arg2, size_t size, uint8_t *bits)
}
// compose ask waveform for one bit(ASK)
static void askSimBit(uint8_t c, int *n, uint8_t clock, uint8_t manchester)
{
static void askSimBit(uint8_t c, int *n, uint8_t clock, uint8_t manchester) {
uint8_t *dest = BigBuf_get_addr();
uint8_t halfClk = clock / 2;
// c = current bit 1 or 0
@ -899,8 +880,7 @@ static void askSimBit(uint8_t c, int *n, uint8_t clock, uint8_t manchester)
*n += clock;
}
static void biphaseSimBit(uint8_t c, int *n, uint8_t clock, uint8_t *phase)
{
static void biphaseSimBit(uint8_t c, int *n, uint8_t clock, uint8_t *phase) {
uint8_t *dest = BigBuf_get_addr();
uint8_t halfClk = clock / 2;
if (c) {
@ -913,8 +893,7 @@ static void biphaseSimBit(uint8_t c, int *n, uint8_t clock, uint8_t *phase)
*n += clock;
}
static void stAskSimBit(int *n, uint8_t clock)
{
static void stAskSimBit(int *n, uint8_t clock) {
uint8_t *dest = BigBuf_get_addr();
uint8_t halfClk = clock / 2;
//ST = .5 high .5 low 1.5 high .5 low 1 high
@ -927,8 +906,7 @@ static void stAskSimBit(int *n, uint8_t clock)
}
// args clock, ask/man or askraw, invert, transmission separator
void CmdASKsimTag(uint16_t arg1, uint16_t arg2, size_t size, uint8_t *BitStream)
{
void CmdASKsimTag(uint16_t arg1, uint16_t arg2, size_t size, uint8_t *BitStream) {
FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
set_tracing(false);
@ -973,8 +951,7 @@ void CmdASKsimTag(uint16_t arg1, uint16_t arg2, size_t size, uint8_t *BitStream)
}
//carrier can be 2,4 or 8
static void pskSimBit(uint8_t waveLen, int *n, uint8_t clk, uint8_t *curPhase, bool phaseChg)
{
static void pskSimBit(uint8_t waveLen, int *n, uint8_t clk, uint8_t *curPhase, bool phaseChg) {
uint8_t *dest = BigBuf_get_addr();
uint8_t halfWave = waveLen / 2;
//uint8_t idx;
@ -996,8 +973,7 @@ static void pskSimBit(uint8_t waveLen, int *n, uint8_t clk, uint8_t *curPhase, b
}
// args clock, carrier, invert,
void CmdPSKsimTag(uint16_t arg1, uint16_t arg2, size_t size, uint8_t *BitStream)
{
void CmdPSKsimTag(uint16_t arg1, uint16_t arg2, size_t size, uint8_t *BitStream) {
FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
set_tracing(false);
@ -1024,8 +1000,7 @@ void CmdPSKsimTag(uint16_t arg1, uint16_t arg2, size_t size, uint8_t *BitStream)
}
// loop to get raw HID waveform then FSK demodulate the TAG ID from it
void CmdHIDdemodFSK(int findone, uint32_t *high, uint32_t *low, int ledcontrol)
{
void CmdHIDdemodFSK(int findone, uint32_t *high, uint32_t *low, int ledcontrol) {
uint8_t *dest = BigBuf_get_addr();
size_t size = 0;
uint32_t hi2 = 0, hi = 0, lo = 0;
@ -1122,8 +1097,7 @@ void CmdHIDdemodFSK(int findone, uint32_t *high, uint32_t *low, int ledcontrol)
}
// loop to get raw HID waveform then FSK demodulate the TAG ID from it
void CmdAWIDdemodFSK(int findone, uint32_t *high, uint32_t *low, int ledcontrol)
{
void CmdAWIDdemodFSK(int findone, uint32_t *high, uint32_t *low, int ledcontrol) {
uint8_t *dest = BigBuf_get_addr();
@ -1218,8 +1192,7 @@ void CmdAWIDdemodFSK(int findone, uint32_t *high, uint32_t *low, int ledcontrol)
if (ledcontrol) LED_A_OFF();
}
void CmdEM410xdemod(int findone, uint32_t *high, uint64_t *low, int ledcontrol)
{
void CmdEM410xdemod(int findone, uint32_t *high, uint64_t *low, int ledcontrol) {
uint8_t *dest = BigBuf_get_addr();
size_t size = 0, idx = 0;
@ -1281,8 +1254,7 @@ void CmdEM410xdemod(int findone, uint32_t *high, uint64_t *low, int ledcontrol)
if (ledcontrol) LED_A_OFF();
}
void CmdIOdemodFSK(int findone, uint32_t *high, uint32_t *low, int ledcontrol)
{
void CmdIOdemodFSK(int findone, uint32_t *high, uint32_t *low, int ledcontrol) {
uint8_t *dest = BigBuf_get_addr();
@ -1382,23 +1354,20 @@ void CmdIOdemodFSK(int findone, uint32_t *high, uint32_t *low, int ledcontrol)
* Q5 tags seems to have issues when these values changes.
*/
void TurnReadLFOn(uint32_t delay)
{
void TurnReadLFOn(uint32_t delay) {
FpgaWriteConfWord(FPGA_MAJOR_MODE_LF_ADC | FPGA_LF_ADC_READER_FIELD);
// measure antenna strength.
//int adcval = ((MAX_ADC_LF_VOLTAGE * AvgAdc(ADC_CHAN_LF)) >> 10);
WaitUS(delay);
}
void TurnReadLF_off(uint32_t delay)
{
void TurnReadLF_off(uint32_t delay) {
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
WaitUS(delay);
}
// Write one bit to card
void T55xxWriteBit(int bit)
{
void T55xxWriteBit(int bit) {
if (!bit)
TurnReadLFOn(t_config.write_0);
else
@ -1408,8 +1377,7 @@ void T55xxWriteBit(int bit)
}
// Send T5577 reset command then read stream (see if we can identify the start of the stream)
void T55xxResetRead(void)
{
void T55xxResetRead(void) {
LED_A_ON();
//clear buffer now so it does not interfere with timing later
BigBuf_Clear_keep_EM();
@ -1441,8 +1409,7 @@ void T55xxResetRead(void)
}
// Write one card block in page 0, no lock
void T55xxWriteBlockExt(uint32_t Data, uint8_t Block, uint32_t Pwd, uint8_t arg)
{
void T55xxWriteBlockExt(uint32_t Data, uint8_t Block, uint32_t Pwd, uint8_t arg) {
LED_A_ON();
bool PwdMode = arg & 0x1;
uint8_t Page = (arg & 0x2) >> 1;
@ -1516,15 +1483,13 @@ void T55xxWriteBlockExt(uint32_t Data, uint8_t Block, uint32_t Pwd, uint8_t arg)
}
// Write one card block in page 0, no lock
void T55xxWriteBlock(uint32_t Data, uint8_t Block, uint32_t Pwd, uint8_t arg)
{
void T55xxWriteBlock(uint32_t Data, uint8_t Block, uint32_t Pwd, uint8_t arg) {
T55xxWriteBlockExt(Data, Block, Pwd, arg);
cmd_send(CMD_ACK, 0, 0, 0, 0, 0);
}
// Read one card block in page [page]
void T55xxReadBlock(uint16_t arg0, uint8_t Block, uint32_t Pwd)
{
void T55xxReadBlock(uint16_t arg0, uint8_t Block, uint32_t Pwd) {
LED_A_ON();
bool PwdMode = arg0 & 0x1;
uint8_t Page = (arg0 & 0x2) >> 1;
@ -1593,8 +1558,7 @@ void T55xxReadBlock(uint16_t arg0, uint8_t Block, uint32_t Pwd)
}
}
void T55xx_ChkPwds()
{
void T55xx_ChkPwds() {
DbpString("[+] T55XX Check pwds using flashmemory starting");
@ -1693,8 +1657,7 @@ OUT:
LEDsoff();
}
void T55xxWakeUp(uint32_t Pwd)
{
void T55xxWakeUp(uint32_t Pwd) {
LED_B_ON();
uint32_t i = 0;
@ -1722,16 +1685,14 @@ void T55xxWakeUp(uint32_t Pwd)
}
/*-------------- Cloning routines -----------*/
void WriteT55xx(uint32_t *blockdata, uint8_t startblock, uint8_t numblocks)
{
void WriteT55xx(uint32_t *blockdata, uint8_t startblock, uint8_t numblocks) {
// write last block first and config block last (if included)
for (uint8_t i = numblocks + startblock; i > startblock; i--)
T55xxWriteBlockExt(blockdata[i - 1], i - 1, 0, 0);
}
// Copy HID id to card and setup block 0 config
void CopyHIDtoT55x7(uint32_t hi2, uint32_t hi, uint32_t lo, uint8_t longFMT)
{
void CopyHIDtoT55x7(uint32_t hi2, uint32_t hi, uint32_t lo, uint8_t longFMT) {
uint32_t data[] = {0, 0, 0, 0, 0, 0, 0};
uint8_t last_block = 0;
@ -1775,8 +1736,7 @@ void CopyHIDtoT55x7(uint32_t hi2, uint32_t hi, uint32_t lo, uint8_t longFMT)
LED_D_OFF();
}
void CopyIOtoT55x7(uint32_t hi, uint32_t lo)
{
void CopyIOtoT55x7(uint32_t hi, uint32_t lo) {
uint32_t data[] = {T55x7_BITRATE_RF_64 | T55x7_MODULATION_FSK2a | (2 << T55x7_MAXBLOCK_SHIFT), hi, lo};
//TODO add selection of chip for Q5 or T55x7
// data[0] = T5555_SET_BITRATE(64) | T5555_MODULATION_FSK2 | T5555_INVERT_OUTPUT | 2 << T5555_MAXBLOCK_SHIFT;
@ -1789,8 +1749,7 @@ void CopyIOtoT55x7(uint32_t hi, uint32_t lo)
}
// Clone Indala 64-bit tag by UID to T55x7
void CopyIndala64toT55x7(uint32_t hi, uint32_t lo)
{
void CopyIndala64toT55x7(uint32_t hi, uint32_t lo) {
//Program the 2 data blocks for supplied 64bit UID
// and the Config for Indala 64 format (RF/32;PSK2 with RF/2;Maxblock=2)
uint32_t data[] = { T55x7_BITRATE_RF_32 | T55x7_MODULATION_PSK2 | (2 << T55x7_MAXBLOCK_SHIFT), hi, lo};
@ -1802,8 +1761,7 @@ void CopyIndala64toT55x7(uint32_t hi, uint32_t lo)
// T5567WriteBlock(0x603E1042,0);
}
// Clone Indala 224-bit tag by UID to T55x7
void CopyIndala224toT55x7(uint32_t uid1, uint32_t uid2, uint32_t uid3, uint32_t uid4, uint32_t uid5, uint32_t uid6, uint32_t uid7)
{
void CopyIndala224toT55x7(uint32_t uid1, uint32_t uid2, uint32_t uid3, uint32_t uid4, uint32_t uid5, uint32_t uid6, uint32_t uid7) {
//Program the 7 data blocks for supplied 224bit UID
uint32_t data[] = {0, uid1, uid2, uid3, uid4, uid5, uid6, uid7};
// and the block 0 for Indala224 format
@ -1816,8 +1774,7 @@ void CopyIndala224toT55x7(uint32_t uid1, uint32_t uid2, uint32_t uid3, uint32_t
// T5567WriteBlock(0x603E10E2,0);
}
// clone viking tag to T55xx
void CopyVikingtoT55xx(uint32_t block1, uint32_t block2, uint8_t Q5)
{
void CopyVikingtoT55xx(uint32_t block1, uint32_t block2, uint8_t Q5) {
uint32_t data[] = {T55x7_BITRATE_RF_32 | T55x7_MODULATION_MANCHESTER | (2 << T55x7_MAXBLOCK_SHIFT), block1, block2};
if (Q5) data[0] = T5555_SET_BITRATE(32) | T5555_MODULATION_MANCHESTER | 2 << T5555_MAXBLOCK_SHIFT;
// Program the data blocks for supplied ID and the block 0 config
@ -1830,8 +1787,7 @@ void CopyVikingtoT55xx(uint32_t block1, uint32_t block2, uint8_t Q5)
#define EM410X_HEADER 0x1FF
#define EM410X_ID_LENGTH 40
void WriteEM410x(uint32_t card, uint32_t id_hi, uint32_t id_lo)
{
void WriteEM410x(uint32_t card, uint32_t id_hi, uint32_t id_lo) {
int i, id_bit;
uint64_t id = EM410X_HEADER;
uint64_t rev_id = 0; // reversed ID
@ -1944,8 +1900,7 @@ uint8_t *fwd_write_ptr; //forwardlink bit pointer
// These timings work for 4469/4269/4305 (with the 55*8 above)
// WRITE_0 = 23*8 , 9*8
uint8_t Prepare_Cmd(uint8_t cmd)
{
uint8_t Prepare_Cmd(uint8_t cmd) {
*forward_ptr++ = 0; //start bit
*forward_ptr++ = 0; //second pause for 4050 code
@ -1965,8 +1920,7 @@ uint8_t Prepare_Cmd(uint8_t cmd)
// prepares address bits
// see EM4469 spec
//====================================================================
uint8_t Prepare_Addr(uint8_t addr)
{
uint8_t Prepare_Addr(uint8_t addr) {
register uint8_t line_parity;
@ -1987,8 +1941,7 @@ uint8_t Prepare_Addr(uint8_t addr)
// prepares data bits intreleaved with parity bits
// see EM4469 spec
//====================================================================
uint8_t Prepare_Data(uint16_t data_low, uint16_t data_hi)
{
uint8_t Prepare_Data(uint16_t data_low, uint16_t data_hi) {
register uint8_t line_parity;
register uint8_t column_parity;
@ -2025,8 +1978,7 @@ uint8_t Prepare_Data(uint16_t data_low, uint16_t data_hi)
// Requires: forwarLink_data filled with valid bits (1 bit per byte)
// fwd_bit_count set with number of bits to be sent
//====================================================================
void SendForward(uint8_t fwd_bit_count)
{
void SendForward(uint8_t fwd_bit_count) {
// iceman, 21.3us increments for the USclock verification.
// 55FC * 8us == 440us / 21.3 === 20.65 steps. could be too short. Go for 56FC instead
@ -2060,8 +2012,7 @@ void SendForward(uint8_t fwd_bit_count)
}
}
void EM4xLogin(uint32_t pwd)
{
void EM4xLogin(uint32_t pwd) {
uint8_t len;
forward_ptr = forwardLink_data;
len = Prepare_Cmd(FWD_CMD_LOGIN);
@ -2073,8 +2024,7 @@ void EM4xLogin(uint32_t pwd)
// 0000 0001 fail
}
void EM4xReadWord(uint8_t addr, uint32_t pwd, uint8_t usepwd)
{
void EM4xReadWord(uint8_t addr, uint32_t pwd, uint8_t usepwd) {
LED_A_ON();
uint8_t len;
@ -2106,8 +2056,7 @@ void EM4xReadWord(uint8_t addr, uint32_t pwd, uint8_t usepwd)
LED_A_OFF();
}
void EM4xWriteWord(uint32_t flag, uint32_t data, uint32_t pwd)
{
void EM4xWriteWord(uint32_t flag, uint32_t data, uint32_t pwd) {
LED_A_ON();
@ -2157,8 +2106,7 @@ pulse 3.6 msecs
This triggers a COTAG tag to response
*/
void Cotag(uint32_t arg0)
{
void Cotag(uint32_t arg0) {
#ifndef OFF
# define OFF(x) { FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); WaitUS((x)); }
#endif

View file

@ -18,8 +18,7 @@ Default LF config is set to:
*/
sample_config config = { 1, 8, 1, 95, 0 } ;
void printConfig()
{
void printConfig() {
Dbprintf("LF Sampling config");
Dbprintf(" [q] divisor.............%d (%d KHz)", config.divisor, 12000 / (config.divisor + 1));
Dbprintf(" [b] bps.................%d", config.bits_per_sample);
@ -39,8 +38,7 @@ void printConfig()
* @brief setSamplingConfig
* @param sc
*/
void setSamplingConfig(sample_config *sc)
{
void setSamplingConfig(sample_config *sc) {
if (sc->divisor != 0) config.divisor = sc->divisor;
if (sc->bits_per_sample != 0) config.bits_per_sample = sc->bits_per_sample;
if (sc->trigger_threshold != -1) config.trigger_threshold = sc->trigger_threshold;
@ -52,8 +50,7 @@ void setSamplingConfig(sample_config *sc)
printConfig();
}
sample_config *getSamplingConfig()
{
sample_config *getSamplingConfig() {
return &config;
}
@ -68,8 +65,7 @@ struct BitstreamOut {
* @param stream
* @param bit
*/
void pushBit(BitstreamOut *stream, uint8_t bit)
{
void pushBit(BitstreamOut *stream, uint8_t bit) {
int bytepos = stream->position >> 3; // divide by 8
int bitpos = stream->position & 7;
*(stream->buffer + bytepos) |= (bit > 0) << (7 - bitpos);
@ -84,8 +80,7 @@ void pushBit(BitstreamOut *stream, uint8_t bit)
* 0 or 95 ==> 125 KHz
*
**/
void LFSetupFPGAForADC(int divisor, bool lf_field)
{
void LFSetupFPGAForADC(int divisor, bool lf_field) {
FpgaDownloadAndGo(FPGA_BITSTREAM_LF);
if ((divisor == 1) || (divisor < 0) || (divisor > 255))
FpgaSendCommand(FPGA_CMD_SET_DIVISOR, 88); //134.8Khz
@ -121,8 +116,7 @@ void LFSetupFPGAForADC(int divisor, bool lf_field)
* @param silent - is true, now outputs are made. If false, dbprints the status
* @return the number of bits occupied by the samples.
*/
uint32_t DoAcquisition(uint8_t decimation, uint32_t bits_per_sample, bool averaging, int trigger_threshold, bool silent, int bufsize, uint32_t cancel_after)
{
uint32_t DoAcquisition(uint8_t decimation, uint32_t bits_per_sample, bool averaging, int trigger_threshold, bool silent, int bufsize, uint32_t cancel_after) {
uint8_t *dest = BigBuf_get_addr();
bufsize = (bufsize > 0 && bufsize < BigBuf_max_traceLen()) ? bufsize : BigBuf_max_traceLen();
@ -224,12 +218,10 @@ uint32_t DoAcquisition(uint8_t decimation, uint32_t bits_per_sample, bool averag
* @param silent
* @return number of bits sampled
*/
uint32_t DoAcquisition_default(int trigger_threshold, bool silent)
{
uint32_t DoAcquisition_default(int trigger_threshold, bool silent) {
return DoAcquisition(1, 8, 0, trigger_threshold, silent, 0, 0);
}
uint32_t DoAcquisition_config(bool silent, int sample_size)
{
uint32_t DoAcquisition_config(bool silent, int sample_size) {
return DoAcquisition(config.decimation
, config.bits_per_sample
, config.averaging
@ -239,13 +231,11 @@ uint32_t DoAcquisition_config(bool silent, int sample_size)
, 0);
}
uint32_t DoPartialAcquisition(int trigger_threshold, bool silent, int sample_size, uint32_t cancel_after)
{
uint32_t DoPartialAcquisition(int trigger_threshold, bool silent, int sample_size, uint32_t cancel_after) {
return DoAcquisition(1, 8, 0, trigger_threshold, silent, sample_size, cancel_after);
}
uint32_t ReadLF(bool activeField, bool silent, int sample_size)
{
uint32_t ReadLF(bool activeField, bool silent, int sample_size) {
if (!silent)
printConfig();
LFSetupFPGAForADC(config.divisor, activeField);
@ -256,8 +246,7 @@ uint32_t ReadLF(bool activeField, bool silent, int sample_size)
* Initializes the FPGA for reader-mode (field on), and acquires the samples.
* @return number of bits sampled
**/
uint32_t SampleLF(bool printCfg, int sample_size)
{
uint32_t SampleLF(bool printCfg, int sample_size) {
BigBuf_Clear_ext(false);
uint32_t ret = ReadLF(true, printCfg, sample_size);
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
@ -267,8 +256,7 @@ uint32_t SampleLF(bool printCfg, int sample_size)
* Initializes the FPGA for snoop-mode (field off), and acquires the samples.
* @return number of bits sampled
**/
uint32_t SnoopLF()
{
uint32_t SnoopLF() {
BigBuf_Clear_ext(false);
uint32_t ret = ReadLF(false, true, 0);
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
@ -279,8 +267,7 @@ uint32_t SnoopLF()
* acquisition of T55x7 LF signal. Similar to other LF, but adjusted with @marshmellows thresholds
* the data is collected in BigBuf.
**/
void doT55x7Acquisition(size_t sample_size)
{
void doT55x7Acquisition(size_t sample_size) {
#define T55xx_READ_UPPER_THRESHOLD 128+60 // 60 grph
#define T55xx_READ_LOWER_THRESHOLD 128-60 // -60 grph
@ -350,8 +337,7 @@ void doT55x7Acquisition(size_t sample_size)
#ifndef COTAG_BITS
#define COTAG_BITS 264
#endif
void doCotagAcquisition(size_t sample_size)
{
void doCotagAcquisition(size_t sample_size) {
uint8_t *dest = BigBuf_get_addr();
uint16_t bufsize = BigBuf_max_traceLen();
@ -401,8 +387,7 @@ void doCotagAcquisition(size_t sample_size)
}
}
uint32_t doCotagAcquisitionManchester()
{
uint32_t doCotagAcquisitionManchester() {
uint8_t *dest = BigBuf_get_addr();
uint16_t bufsize = BigBuf_max_traceLen();

View file

@ -38,8 +38,7 @@ static uint8_t dummy_answer = 0;
// Select, Authenticate, Read a MIFARE tag.
// read block
//-----------------------------------------------------------------------------
void MifareReadBlock(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain)
{
void MifareReadBlock(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain) {
// params
uint8_t blockNo = arg0;
uint8_t keyType = arg1;
@ -101,8 +100,7 @@ void MifareReadBlock(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain)
LEDsoff();
}
void MifareUC_Auth(uint8_t arg0, uint8_t *keybytes)
{
void MifareUC_Auth(uint8_t arg0, uint8_t *keybytes) {
bool turnOffField = (arg0 == 1);
@ -137,8 +135,7 @@ void MifareUC_Auth(uint8_t arg0, uint8_t *keybytes)
// Arg0 = BlockNo,
// Arg1 = UsePwd bool
// datain = PWD bytes,
void MifareUReadBlock(uint8_t arg0, uint8_t arg1, uint8_t *datain)
{
void MifareUReadBlock(uint8_t arg0, uint8_t arg1, uint8_t *datain) {
uint8_t blockNo = arg0;
byte_t dataout[16] = {0x00};
bool useKey = (arg1 == 1); //UL_C
@ -201,8 +198,7 @@ void MifareUReadBlock(uint8_t arg0, uint8_t arg1, uint8_t *datain)
// Select, Authenticate, Read a MIFARE tag.
// read sector (data = 4 x 16 bytes = 64 bytes, or 16 x 16 bytes = 256 bytes)
//-----------------------------------------------------------------------------
void MifareReadSector(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain)
{
void MifareReadSector(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain) {
// params
uint8_t sectorNo = arg0;
uint8_t keyType = arg1;
@ -268,8 +264,7 @@ void MifareReadSector(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain)
// arg1 = Pages (number of blocks)
// arg2 = useKey
// datain = KEY bytes
void MifareUReadCard(uint8_t arg0, uint16_t arg1, uint8_t arg2, uint8_t *datain)
{
void MifareUReadCard(uint8_t arg0, uint16_t arg1, uint8_t arg2, uint8_t *datain) {
LEDsoff();
LED_A_ON();
iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);
@ -368,8 +363,7 @@ void MifareUReadCard(uint8_t arg0, uint16_t arg1, uint8_t arg2, uint8_t *datain)
// Select, Authenticate, Write a MIFARE tag.
// read block
//-----------------------------------------------------------------------------
void MifareWriteBlock(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain)
{
void MifareWriteBlock(uint8_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain) {
// params
uint8_t blockNo = arg0;
uint8_t keyType = arg1;
@ -479,8 +473,7 @@ void MifareUWriteBlockCompat(uint8_t arg0, uint8_t *datain)
// 2 = use 0x1B authentication.
// datain : 4 first bytes is data to be written.
// : 4/16 next bytes is authentication key.
void MifareUWriteBlock(uint8_t arg0, uint8_t arg1, uint8_t *datain)
{
void MifareUWriteBlock(uint8_t arg0, uint8_t arg1, uint8_t *datain) {
uint8_t blockNo = arg0;
bool useKey = (arg1 == 1); //UL_C
bool usePwd = (arg1 == 2); //UL_EV1/NTAG
@ -543,8 +536,7 @@ void MifareUWriteBlock(uint8_t arg0, uint8_t arg1, uint8_t *datain)
set_tracing(false);
}
void MifareUSetPwd(uint8_t arg0, uint8_t *datain)
{
void MifareUSetPwd(uint8_t arg0, uint8_t *datain) {
uint8_t pwd[16] = {0x00};
byte_t blockdata[4] = {0x00};
@ -618,15 +610,13 @@ void MifareUSetPwd(uint8_t arg0, uint8_t *datain)
}
// Return 1 if the nonce is invalid else return 0
int valid_nonce(uint32_t Nt, uint32_t NtEnc, uint32_t Ks1, uint8_t *parity)
{
int valid_nonce(uint32_t Nt, uint32_t NtEnc, uint32_t Ks1, uint8_t *parity) {
return ((oddparity8((Nt >> 24) & 0xFF) == ((parity[0]) ^ oddparity8((NtEnc >> 24) & 0xFF) ^ BIT(Ks1, 16))) & \
(oddparity8((Nt >> 16) & 0xFF) == ((parity[1]) ^ oddparity8((NtEnc >> 16) & 0xFF) ^ BIT(Ks1, 8))) & \
(oddparity8((Nt >> 8) & 0xFF) == ((parity[2]) ^ oddparity8((NtEnc >> 8) & 0xFF) ^ BIT(Ks1, 0)))) ? 1 : 0;
}
void MifareAcquireNonces(uint32_t arg0, uint32_t arg1, uint32_t flags, uint8_t *datain)
{
void MifareAcquireNonces(uint32_t arg0, uint32_t arg1, uint32_t flags, uint8_t *datain) {
uint8_t uid[10] = {0x00};
uint8_t answer[MAX_MIFARE_FRAME_SIZE] = {0x00};
@ -734,8 +724,7 @@ void MifareAcquireNonces(uint32_t arg0, uint32_t arg1, uint32_t flags, uint8_t *
// Mifare Classic Cards" in Proceedings of the 22nd ACM SIGSAC Conference on
// Computer and Communications Security, 2015
//-----------------------------------------------------------------------------
void MifareAcquireEncryptedNonces(uint32_t arg0, uint32_t arg1, uint32_t flags, uint8_t *datain)
{
void MifareAcquireEncryptedNonces(uint32_t arg0, uint32_t arg1, uint32_t flags, uint8_t *datain) {
struct Crypto1State mpcs = {0, 0};
struct Crypto1State *pcs;
@ -862,8 +851,7 @@ void MifareAcquireEncryptedNonces(uint32_t arg0, uint32_t arg1, uint32_t flags,
// MIFARE nested authentication.
//
//-----------------------------------------------------------------------------
void MifareNested(uint32_t arg0, uint32_t arg1, uint32_t calibrate, uint8_t *datain)
{
void MifareNested(uint32_t arg0, uint32_t arg1, uint32_t calibrate, uint8_t *datain) {
// params
uint8_t blockNo = arg0 & 0xff;
uint8_t keyType = (arg0 >> 8) & 0xff;
@ -1101,8 +1089,7 @@ typedef struct chk_t {
// 2 = failed to select.
// 1 = wrong key
// 0 = correct key
uint8_t chkKey(struct chk_t *c)
{
uint8_t chkKey(struct chk_t *c) {
uint8_t i = 0, res = 2;
while (i < 5) {
// this part is from Piwi's faster nonce collecting part in Hardnested.
@ -1123,8 +1110,7 @@ uint8_t chkKey(struct chk_t *c)
return res;
}
uint8_t chkKey_readb(struct chk_t *c, uint8_t *keyb)
{
uint8_t chkKey_readb(struct chk_t *c, uint8_t *keyb) {
if (!iso14443a_fast_select_card(c->uid, c->cl))
return 2;
@ -1149,8 +1135,7 @@ uint8_t chkKey_readb(struct chk_t *c, uint8_t *keyb)
return res;
}
void chkKey_scanA(struct chk_t *c, struct sector_t *k_sector, uint8_t *found, uint8_t *sectorcnt, uint8_t *foundkeys)
{
void chkKey_scanA(struct chk_t *c, struct sector_t *k_sector, uint8_t *found, uint8_t *sectorcnt, uint8_t *foundkeys) {
for (uint8_t s = 0; s < *sectorcnt; s++) {
// skip already found A keys
@ -1168,8 +1153,7 @@ void chkKey_scanA(struct chk_t *c, struct sector_t *k_sector, uint8_t *found, ui
}
}
void chkKey_scanB(struct chk_t *c, struct sector_t *k_sector, uint8_t *found, uint8_t *sectorcnt, uint8_t *foundkeys)
{
void chkKey_scanB(struct chk_t *c, struct sector_t *k_sector, uint8_t *found, uint8_t *sectorcnt, uint8_t *foundkeys) {
for (uint8_t s = 0; s < *sectorcnt; s++) {
// skip already found B keys
@ -1189,8 +1173,7 @@ void chkKey_scanB(struct chk_t *c, struct sector_t *k_sector, uint8_t *found, ui
// loop all A keys,
// when A is found but not B, try to read B.
void chkKey_loopBonly(struct chk_t *c, struct sector_t *k_sector, uint8_t *found, uint8_t *sectorcnt, uint8_t *foundkeys)
{
void chkKey_loopBonly(struct chk_t *c, struct sector_t *k_sector, uint8_t *found, uint8_t *sectorcnt, uint8_t *foundkeys) {
// read Block B, if A is found.
for (uint8_t s = 0; s < *sectorcnt; ++s) {
@ -1228,8 +1211,7 @@ void chkKey_loopBonly(struct chk_t *c, struct sector_t *k_sector, uint8_t *found
// arg1 = clear trace
// arg2 = antal nycklar i keychunk
// datain = keys as array
void MifareChkKeys_fast(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain)
{
void MifareChkKeys_fast(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain) {
// first call or
uint8_t sectorcnt = arg0 & 0xFF; // 16;
@ -1533,8 +1515,7 @@ OUT:
}
}
void MifareChkKeys(uint16_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain)
{
void MifareChkKeys(uint16_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain) {
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
@ -1623,8 +1604,7 @@ void MifareChkKeys(uint16_t arg0, uint8_t arg1, uint8_t arg2, uint8_t *datain)
// MIFARE commands set debug level
//
//-----------------------------------------------------------------------------
void MifareSetDbgLvl(uint16_t arg0)
{
void MifareSetDbgLvl(uint16_t arg0) {
MF_DBGLEVEL = arg0;
Dbprintf("Debug level: %d", MF_DBGLEVEL);
}
@ -1637,21 +1617,18 @@ void MifareSetDbgLvl(uint16_t arg0)
// destroy the Emulator Memory.
//-----------------------------------------------------------------------------
void MifareEMemClr(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain)
{
void MifareEMemClr(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain) {
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
emlClearMem();
}
void MifareEMemSet(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain)
{
void MifareEMemSet(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain) {
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
if (arg2 == 0) arg2 = 16; // backwards compat... default bytewidth
emlSetMem_xt(datain, arg0, arg1, arg2); // data, block num, blocks count, block byte width
}
void MifareEMemGet(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain)
{
void MifareEMemGet(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain) {
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
byte_t buf[USB_CMD_DATA_SIZE] = {0x00};
emlGetMem(buf, arg0, arg1); // data, block num, blocks count (max 4)
@ -1665,8 +1642,7 @@ void MifareEMemGet(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain)
// Load a card into the emulator memory
//
//-----------------------------------------------------------------------------
void MifareECardLoad(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain)
{
void MifareECardLoad(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain) {
uint8_t numSectors = arg0;
uint8_t keyType = arg1;
uint64_t ui64Key = 0;
@ -1763,8 +1739,7 @@ uint8_t wupC1[] = { MIFARE_MAGICWUPC1 };
uint8_t wupC2[] = { MIFARE_MAGICWUPC2 };
uint8_t wipeC[] = { MIFARE_MAGICWIPEC };
void MifareCSetBlock(uint32_t arg0, uint32_t arg1, uint8_t *datain)
{
void MifareCSetBlock(uint32_t arg0, uint32_t arg1, uint8_t *datain) {
// params
uint8_t workFlags = arg0;
@ -1874,8 +1849,7 @@ void MifareCSetBlock(uint32_t arg0, uint32_t arg1, uint8_t *datain)
OnSuccessMagic();
}
void MifareCGetBlock(uint32_t arg0, uint32_t arg1, uint8_t *datain)
{
void MifareCGetBlock(uint32_t arg0, uint32_t arg1, uint8_t *datain) {
uint8_t workFlags = arg0;
uint8_t blockNo = arg1;
@ -1951,8 +1925,7 @@ void MifareCGetBlock(uint32_t arg0, uint32_t arg1, uint8_t *datain)
OnSuccessMagic();
}
void MifareCIdent()
{
void MifareCIdent() {
#define GEN_1A 1
#define GEN_1B 2
#define GEN_2 4
@ -2006,21 +1979,18 @@ OUT:
OnSuccessMagic();
}
void OnSuccessMagic()
{
void OnSuccessMagic() {
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
LEDsoff();
set_tracing(false);
}
void OnErrorMagic(uint8_t reason)
{
void OnErrorMagic(uint8_t reason) {
// ACK, ISOK, reason,0,0,0
cmd_send(CMD_ACK, 0, reason, 0, 0, 0);
OnSuccessMagic();
}
void MifareSetMod(uint8_t mod, uint8_t *key)
{
void MifareSetMod(uint8_t mod, uint8_t *key) {
uint64_t ui64Key = bytes_to_num(key, 6);
// variables
@ -2080,8 +2050,7 @@ void MifareSetMod(uint8_t mod, uint8_t *key)
//
// DESFIRE
//
void Mifare_DES_Auth1(uint8_t arg0, uint8_t *datain)
{
void Mifare_DES_Auth1(uint8_t arg0, uint8_t *datain) {
byte_t dataout[12] = {0x00};
uint8_t uid[10] = {0x00};
uint32_t cuid = 0;
@ -2107,8 +2076,7 @@ void Mifare_DES_Auth1(uint8_t arg0, uint8_t *datain)
cmd_send(CMD_ACK, 1, cuid, 0, dataout, sizeof(dataout));
}
void Mifare_DES_Auth2(uint32_t arg0, uint8_t *datain)
{
void Mifare_DES_Auth2(uint32_t arg0, uint8_t *datain) {
uint32_t cuid = arg0;
uint8_t key[16] = {0x00};
byte_t dataout[12] = {0x00};

View file

@ -16,8 +16,7 @@ static uint8_t deselect_cmd[] = {0xc2, 0xe0, 0xb4};
/* PCB CID CMD PAYLOAD */
//static uint8_t __res[MAX_FRAME_SIZE];
bool InitDesfireCard()
{
bool InitDesfireCard() {
iso14a_card_select_t card;
@ -41,8 +40,7 @@ enum {
BAR = 0x08,
} CmdOptions ;
void MifareSendCommand(uint8_t arg0, uint8_t arg1, uint8_t *datain)
{
void MifareSendCommand(uint8_t arg0, uint8_t arg1, uint8_t *datain) {
/* ARG0 contains flags.
0x01 = init card.
@ -86,8 +84,7 @@ void MifareSendCommand(uint8_t arg0, uint8_t arg1, uint8_t *datain)
cmd_send(CMD_ACK, 1, len, 0, resp, len);
}
void MifareDesfireGetInformation()
{
void MifareDesfireGetInformation() {
int len = 0;
iso14a_card_select_t card;
@ -170,8 +167,7 @@ void MifareDesfireGetInformation()
OnSuccess();
}
void MifareDES_Auth1(uint8_t mode, uint8_t algo, uint8_t keyno, uint8_t *datain)
{
void MifareDES_Auth1(uint8_t mode, uint8_t algo, uint8_t keyno, uint8_t *datain) {
int len = 0;
//uint8_t PICC_MASTER_KEY8[8] = { 0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47};
@ -503,8 +499,7 @@ void MifareDES_Auth1(uint8_t mode, uint8_t algo, uint8_t keyno, uint8_t *datain
// cmd = cmd bytes to send
// cmd_len = length of cmd
// dataout = pointer to response data array
int DesfireAPDU(uint8_t *cmd, size_t cmd_len, uint8_t *dataout)
{
int DesfireAPDU(uint8_t *cmd, size_t cmd_len, uint8_t *dataout) {
size_t len = 0;
size_t wrappedLen = 0;
@ -538,8 +533,7 @@ int DesfireAPDU(uint8_t *cmd, size_t cmd_len, uint8_t *dataout)
}
// CreateAPDU
size_t CreateAPDU(uint8_t *datain, size_t len, uint8_t *dataout)
{
size_t CreateAPDU(uint8_t *datain, size_t len, uint8_t *dataout) {
size_t cmdlen = MIN(len + 4, USB_CMD_DATA_SIZE - 1);
@ -563,16 +557,14 @@ size_t CreateAPDU(uint8_t *datain, size_t len, uint8_t *dataout)
// crc_update(&desfire_crc32, byte, 8);
// uint32_t crc = crc_finish(&desfire_crc32);
void OnSuccess()
{
void OnSuccess() {
pcb_blocknum = 0;
ReaderTransmit(deselect_cmd, 3, NULL);
mifare_ultra_halt();
switch_off();
}
void OnError(uint8_t reason)
{
void OnError(uint8_t reason) {
cmd_send(CMD_ACK, 0, reason, 0, 0, 0);
OnSuccess();
}

View file

@ -24,8 +24,7 @@ static uint32_t timerData = 0;
// if no activity for 2sec, it sends the collected data to the client.
//-----------------------------------------------------------------------------
// "hf mf sniff"
void RAMFUNC SniffMifare(uint8_t param)
{
void RAMFUNC SniffMifare(uint8_t param) {
// param:
// bit 0 - trigger from first card answer
// bit 1 - trigger from first reader 7-bit request
@ -177,8 +176,7 @@ void RAMFUNC SniffMifare(uint8_t param)
switch_off();
}
void MfSniffInit(void)
{
void MfSniffInit(void) {
memset(sniffUID, 0x00, sizeof(sniffUID));
memset(sniffATQA, 0x00, sizeof(sniffATQA));
memset(sniffBuf, 0x00, sizeof(sniffBuf));
@ -187,8 +185,7 @@ void MfSniffInit(void)
timerData = 0;
}
void MfSniffEnd(void)
{
void MfSniffEnd(void) {
LED_B_ON();
cmd_send(CMD_ACK, 0, 0, 0, 0, 0);
LED_B_OFF();
@ -308,8 +305,7 @@ bool RAMFUNC MfSniffLogic(const uint8_t *data, uint16_t len, uint8_t *parity, ui
}
*/
void RAMFUNC MfSniffSend()
{
void RAMFUNC MfSniffSend() {
uint16_t tracelen = BigBuf_get_traceLen();
uint16_t chunksize = 0;
int packlen = tracelen; // total number of bytes to send

View file

@ -13,8 +13,7 @@
int MF_DBGLEVEL = MF_DBG_ERROR;
// crypto1 helpers
void mf_crypto1_decryptEx(struct Crypto1State *pcs, uint8_t *data_in, int len, uint8_t *data_out)
{
void mf_crypto1_decryptEx(struct Crypto1State *pcs, uint8_t *data_in, int len, uint8_t *data_out) {
uint8_t bt = 0;
int i;
@ -31,13 +30,11 @@ void mf_crypto1_decryptEx(struct Crypto1State *pcs, uint8_t *data_in, int len, u
return;
}
void mf_crypto1_decrypt(struct Crypto1State *pcs, uint8_t *data, int len)
{
void mf_crypto1_decrypt(struct Crypto1State *pcs, uint8_t *data, int len) {
mf_crypto1_decryptEx(pcs, data, len, data);
}
void mf_crypto1_encrypt(struct Crypto1State *pcs, uint8_t *data, uint16_t len, uint8_t *par)
{
void mf_crypto1_encrypt(struct Crypto1State *pcs, uint8_t *data, uint16_t len, uint8_t *par) {
uint8_t bt = 0;
int i;
par[0] = 0;
@ -51,8 +48,7 @@ void mf_crypto1_encrypt(struct Crypto1State *pcs, uint8_t *data, uint16_t len, u
}
}
uint8_t mf_crypto1_encrypt4bit(struct Crypto1State *pcs, uint8_t data)
{
uint8_t mf_crypto1_encrypt4bit(struct Crypto1State *pcs, uint8_t data) {
uint8_t bt = 0;
bt |= (crypto1_bit(pcs, 0, 0) ^ BIT(data, 0)) << 0;
bt |= (crypto1_bit(pcs, 0, 0) ^ BIT(data, 1)) << 1;
@ -62,8 +58,7 @@ uint8_t mf_crypto1_encrypt4bit(struct Crypto1State *pcs, uint8_t data)
}
// send X byte basic commands
int mifare_sendcmd(uint8_t cmd, uint8_t *data, uint8_t data_size, uint8_t *answer, uint8_t *answer_parity, uint32_t *timing)
{
int mifare_sendcmd(uint8_t cmd, uint8_t *data, uint8_t data_size, uint8_t *answer, uint8_t *answer_parity, uint32_t *timing) {
uint8_t dcmd[data_size + 3];
dcmd[0] = cmd;
memcpy(dcmd + 1, data, data_size);
@ -78,8 +73,7 @@ int mifare_sendcmd(uint8_t cmd, uint8_t *data, uint8_t data_size, uint8_t *answe
}
// send 2 byte commands
int mifare_sendcmd_short(struct Crypto1State *pcs, uint8_t crypted, uint8_t cmd, uint8_t data, uint8_t *answer, uint8_t *answer_parity, uint32_t *timing)
{
int mifare_sendcmd_short(struct Crypto1State *pcs, uint8_t crypted, uint8_t cmd, uint8_t data, uint8_t *answer, uint8_t *answer_parity, uint32_t *timing) {
uint16_t pos, res;
uint8_t dcmd[4] = {cmd, data, 0x00, 0x00};
uint8_t ecmd[4] = {0x00, 0x00, 0x00, 0x00};
@ -119,13 +113,11 @@ int mifare_sendcmd_short(struct Crypto1State *pcs, uint8_t crypted, uint8_t cmd,
}
// mifare classic commands
int mifare_classic_auth(struct Crypto1State *pcs, uint32_t uid, uint8_t blockNo, uint8_t keyType, uint64_t ui64Key, uint8_t isNested)
{
int mifare_classic_auth(struct Crypto1State *pcs, uint32_t uid, uint8_t blockNo, uint8_t keyType, uint64_t ui64Key, uint8_t isNested) {
return mifare_classic_authex(pcs, uid, blockNo, keyType, ui64Key, isNested, NULL, NULL);
}
int mifare_classic_authex(struct Crypto1State *pcs, uint32_t uid, uint8_t blockNo, uint8_t keyType, uint64_t ui64Key, uint8_t isNested, uint32_t *ntptr, uint32_t *timing)
{
int mifare_classic_authex(struct Crypto1State *pcs, uint32_t uid, uint8_t blockNo, uint8_t keyType, uint64_t ui64Key, uint8_t isNested, uint32_t *ntptr, uint32_t *timing) {
int len;
uint32_t pos, nt, ntpp; // Supplied tag nonce
uint8_t par[1] = {0x00};
@ -203,8 +195,7 @@ int mifare_classic_authex(struct Crypto1State *pcs, uint32_t uid, uint8_t blockN
return 0;
}
int mifare_classic_readblock(struct Crypto1State *pcs, uint32_t uid, uint8_t blockNo, uint8_t *blockData)
{
int mifare_classic_readblock(struct Crypto1State *pcs, uint32_t uid, uint8_t blockNo, uint8_t *blockData) {
int len;
uint8_t bt[2] = {0x00, 0x00};
@ -233,8 +224,7 @@ int mifare_classic_readblock(struct Crypto1State *pcs, uint32_t uid, uint8_t blo
}
// mifare ultralight commands
int mifare_ul_ev1_auth(uint8_t *keybytes, uint8_t *pack)
{
int mifare_ul_ev1_auth(uint8_t *keybytes, uint8_t *pack) {
uint16_t len = 0;
uint8_t resp[4] = {0x00, 0x00, 0x00, 0x00};
@ -259,8 +249,7 @@ int mifare_ul_ev1_auth(uint8_t *keybytes, uint8_t *pack)
return 1;
}
int mifare_ultra_auth(uint8_t *keybytes)
{
int mifare_ultra_auth(uint8_t *keybytes) {
/// 3des2k
uint8_t random_a[8] = {1, 1, 1, 1, 1, 1, 1, 1};
@ -345,8 +334,7 @@ int mifare_ultra_auth(uint8_t *keybytes)
return 1;
}
int mifare_ultra_readblockEx(uint8_t blockNo, uint8_t *blockData)
{
int mifare_ultra_readblockEx(uint8_t blockNo, uint8_t *blockData) {
uint16_t len = 0;
uint8_t bt[2] = {0x00, 0x00};
uint8_t receivedAnswer[MAX_FRAME_SIZE] = {0x00};
@ -372,8 +360,7 @@ int mifare_ultra_readblockEx(uint8_t blockNo, uint8_t *blockData)
memcpy(blockData, receivedAnswer, 14);
return 0;
}
int mifare_ultra_readblock(uint8_t blockNo, uint8_t *blockData)
{
int mifare_ultra_readblock(uint8_t blockNo, uint8_t *blockData) {
#define MFU_MAX_RETRIES 5
uint8_t res;
@ -392,8 +379,7 @@ int mifare_ultra_readblock(uint8_t blockNo, uint8_t *blockData)
return res;
}
int mifare_classic_writeblock(struct Crypto1State *pcs, uint32_t uid, uint8_t blockNo, uint8_t *blockData)
{
int mifare_classic_writeblock(struct Crypto1State *pcs, uint32_t uid, uint8_t blockNo, uint8_t *blockData) {
// variables
uint16_t len = 0;
uint32_t pos = 0;
@ -471,8 +457,7 @@ int mifare_ultra_writeblock_compat(uint8_t blockNo, uint8_t *blockData) {
}
*/
int mifare_ultra_writeblock(uint8_t blockNo, uint8_t *blockData)
{
int mifare_ultra_writeblock(uint8_t blockNo, uint8_t *blockData) {
uint16_t len = 0;
uint8_t block[5] = {blockNo, 0x00, 0x00, 0x00, 0x00 };
uint8_t receivedAnswer[MAX_MIFARE_FRAME_SIZE] = {0x00};
@ -490,8 +475,7 @@ int mifare_ultra_writeblock(uint8_t blockNo, uint8_t *blockData)
}
return 0;
}
int mifare_classic_halt_ex(struct Crypto1State *pcs)
{
int mifare_classic_halt_ex(struct Crypto1State *pcs) {
uint8_t receivedAnswer[4] = {0x00, 0x00, 0x00, 0x00};
uint16_t len = mifare_sendcmd_short(pcs, (pcs == NULL) ? CRYPT_NONE : CRYPT_ALL, ISO14443A_CMD_HALT, 0x00, receivedAnswer, NULL, NULL);
if (len != 0) {
@ -500,13 +484,11 @@ int mifare_classic_halt_ex(struct Crypto1State *pcs)
}
return 0;
}
int mifare_classic_halt(struct Crypto1State *pcs, uint32_t uid)
{
int mifare_classic_halt(struct Crypto1State *pcs, uint32_t uid) {
return mifare_classic_halt_ex(pcs);
}
int mifare_ultra_halt()
{
int mifare_ultra_halt() {
uint16_t len = 0;
uint8_t receivedAnswer[4] = {0x00, 0x00, 0x00, 0x00};
len = mifare_sendcmd_short(NULL, CRYPT_NONE, ISO14443A_CMD_HALT, 0x00, receivedAnswer, NULL, NULL);
@ -520,13 +502,11 @@ int mifare_ultra_halt()
// Mifare Memory Structure: up to 32 Sectors with 4 blocks each (1k and 2k cards),
// plus evtl. 8 sectors with 16 blocks each (4k cards)
uint8_t NumBlocksPerSector(uint8_t sectorNo)
{
uint8_t NumBlocksPerSector(uint8_t sectorNo) {
return (sectorNo < 32) ? 4 : 16;
}
uint8_t FirstBlockOfSector(uint8_t sectorNo)
{
uint8_t FirstBlockOfSector(uint8_t sectorNo) {
if (sectorNo < 32)
return sectorNo * 4;
else
@ -535,47 +515,41 @@ uint8_t FirstBlockOfSector(uint8_t sectorNo)
}
// work with emulator memory
void emlSetMem(uint8_t *data, int blockNum, int blocksCount)
{
void emlSetMem(uint8_t *data, int blockNum, int blocksCount) {
emlSetMem_xt(data, blockNum, blocksCount, 16);
}
void emlSetMem_xt(uint8_t *data, int blockNum, int blocksCount, int blockBtWidth)
{
void emlSetMem_xt(uint8_t *data, int blockNum, int blocksCount, int blockBtWidth) {
uint8_t *emCARD = BigBuf_get_EM_addr();
memcpy(emCARD + blockNum * blockBtWidth, data, blocksCount * blockBtWidth);
}
void emlGetMem(uint8_t *data, int blockNum, int blocksCount)
{
void emlGetMem(uint8_t *data, int blockNum, int blocksCount) {
uint8_t *emCARD = BigBuf_get_EM_addr();
memcpy(data, emCARD + blockNum * 16, blocksCount * 16);
}
void emlGetMemBt(uint8_t *data, int bytePtr, int byteCount)
{
void emlGetMemBt(uint8_t *data, int bytePtr, int byteCount) {
uint8_t *emCARD = BigBuf_get_EM_addr();
memcpy(data, emCARD + bytePtr, byteCount);
}
int emlCheckValBl(int blockNum)
{
int emlCheckValBl(int blockNum) {
uint8_t *emCARD = BigBuf_get_EM_addr();
uint8_t *data = emCARD + blockNum * 16;
if ((data[0] != (data[4] ^ 0xff)) || (data[0] != data[8]) ||
(data[1] != (data[5] ^ 0xff)) || (data[1] != data[9]) ||
(data[2] != (data[6] ^ 0xff)) || (data[2] != data[10]) ||
(data[3] != (data[7] ^ 0xff)) || (data[3] != data[11]) ||
(data[12] != (data[13] ^ 0xff)) || (data[12] != data[14]) ||
(data[12] != (data[15] ^ 0xff))
(data[1] != (data[5] ^ 0xff)) || (data[1] != data[9]) ||
(data[2] != (data[6] ^ 0xff)) || (data[2] != data[10]) ||
(data[3] != (data[7] ^ 0xff)) || (data[3] != data[11]) ||
(data[12] != (data[13] ^ 0xff)) || (data[12] != data[14]) ||
(data[12] != (data[15] ^ 0xff))
)
return 1;
return 0;
}
int emlGetValBl(uint32_t *blReg, uint8_t *blBlock, int blockNum)
{
int emlGetValBl(uint32_t *blReg, uint8_t *blBlock, int blockNum) {
uint8_t *emCARD = BigBuf_get_EM_addr();
uint8_t *data = emCARD + blockNum * 16;
@ -587,8 +561,7 @@ int emlGetValBl(uint32_t *blReg, uint8_t *blBlock, int blockNum)
return 0;
}
int emlSetValBl(uint32_t blReg, uint8_t blBlock, int blockNum)
{
int emlSetValBl(uint32_t blReg, uint8_t blBlock, int blockNum) {
uint8_t *emCARD = BigBuf_get_EM_addr();
uint8_t *data = emCARD + blockNum * 16;
@ -605,16 +578,14 @@ int emlSetValBl(uint32_t blReg, uint8_t blBlock, int blockNum)
return 0;
}
uint64_t emlGetKey(int sectorNum, int keyType)
{
uint64_t emlGetKey(int sectorNum, int keyType) {
uint8_t key[6] = {0x00};
uint8_t *emCARD = BigBuf_get_EM_addr();
memcpy(key, emCARD + 16 * (FirstBlockOfSector(sectorNum) + NumBlocksPerSector(sectorNum) - 1) + keyType * 10, 6);
return bytes_to_num(key, 6);
}
void emlClearMem(void)
{
void emlClearMem(void) {
const uint8_t trailer[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 0x80, 0x69, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
const uint8_t uid[] = {0xe6, 0x84, 0x87, 0xf3, 0x16, 0x88, 0x04, 0x00, 0x46, 0x8e, 0x45, 0x55, 0x4d, 0x70, 0x41, 0x04};
uint8_t *emCARD = BigBuf_get_EM_addr();
@ -631,8 +602,7 @@ void emlClearMem(void)
// Mifare desfire commands
int mifare_sendcmd_special(struct Crypto1State *pcs, uint8_t crypted, uint8_t cmd, uint8_t *data, uint8_t *answer, uint8_t *answer_parity, uint32_t *timing)
{
int mifare_sendcmd_special(struct Crypto1State *pcs, uint8_t crypted, uint8_t cmd, uint8_t *data, uint8_t *answer, uint8_t *answer_parity, uint32_t *timing) {
uint8_t dcmd[5] = {cmd, data[0], data[1], 0x00, 0x00};
AddCrc14A(dcmd, 3);
@ -645,8 +615,7 @@ int mifare_sendcmd_special(struct Crypto1State *pcs, uint8_t crypted, uint8_t cm
return len;
}
int mifare_sendcmd_special2(struct Crypto1State *pcs, uint8_t crypted, uint8_t cmd, uint8_t *data, uint8_t *answer, uint8_t *answer_parity, uint32_t *timing)
{
int mifare_sendcmd_special2(struct Crypto1State *pcs, uint8_t crypted, uint8_t cmd, uint8_t *data, uint8_t *answer, uint8_t *answer_parity, uint32_t *timing) {
uint8_t dcmd[20] = {0x00};
dcmd[0] = cmd;
memcpy(dcmd + 1, data, 17);
@ -661,8 +630,7 @@ int mifare_sendcmd_special2(struct Crypto1State *pcs, uint8_t crypted, uint8_t c
return len;
}
int mifare_desfire_des_auth1(uint32_t uid, uint8_t *blockData)
{
int mifare_desfire_des_auth1(uint32_t uid, uint8_t *blockData) {
int len;
// load key, keynumber
@ -690,8 +658,7 @@ int mifare_desfire_des_auth1(uint32_t uid, uint8_t *blockData)
return 1;
}
int mifare_desfire_des_auth2(uint32_t uid, uint8_t *key, uint8_t *blockData)
{
int mifare_desfire_des_auth2(uint32_t uid, uint8_t *key, uint8_t *blockData) {
int len;
uint8_t data[17] = {MFDES_AUTHENTICATION_FRAME};

View file

@ -96,8 +96,7 @@ uint8_t xopt__select(bool x, bool y, uint8_t r)
}
*/
void opt_successor(const uint8_t *k, State *s, bool y, State *successor)
{
void opt_successor(const uint8_t *k, State *s, bool y, State *successor) {
uint8_t Tt = 1 & opt_T(s);
successor->t = (s->t >> 1);
@ -110,8 +109,7 @@ void opt_successor(const uint8_t *k, State *s, bool y, State *successor)
successor->l = successor->r + s->r;
}
void opt_suc(const uint8_t *k, State *s, uint8_t *in, uint8_t length, bool add32Zeroes)
{
void opt_suc(const uint8_t *k, State *s, uint8_t *in, uint8_t length, bool add32Zeroes) {
State x2;
int i;
uint8_t head = 0;
@ -150,8 +148,7 @@ void opt_suc(const uint8_t *k, State *s, uint8_t *in, uint8_t length, bool add32
}
}
void opt_output(const uint8_t *k, State *s, uint8_t *buffer)
{
void opt_output(const uint8_t *k, State *s, uint8_t *buffer) {
uint8_t times = 0;
uint8_t bout = 0;
State temp = {0, 0, 0, 0};
@ -177,8 +174,7 @@ void opt_output(const uint8_t *k, State *s, uint8_t *buffer)
}
}
void opt_MAC(uint8_t *k, uint8_t *input, uint8_t *out)
{
void opt_MAC(uint8_t *k, uint8_t *input, uint8_t *out) {
State _init = {
((k[0] ^ 0x4c) + 0xEC) & 0xFF,// l
((k[0] ^ 0x4c) + 0x21) & 0xFF,// r
@ -190,23 +186,20 @@ void opt_MAC(uint8_t *k, uint8_t *input, uint8_t *out)
opt_output(k, &_init, out);
}
uint8_t rev_byte(uint8_t b)
{
uint8_t rev_byte(uint8_t b) {
b = (b & 0xF0) >> 4 | (b & 0x0F) << 4;
b = (b & 0xCC) >> 2 | (b & 0x33) << 2;
b = (b & 0xAA) >> 1 | (b & 0x55) << 1;
return b;
}
void opt_reverse_arraybytecpy(uint8_t *dest, uint8_t *src, size_t len)
{
void opt_reverse_arraybytecpy(uint8_t *dest, uint8_t *src, size_t len) {
uint8_t i;
for (i = 0; i < len ; i++)
dest[i] = rev_byte(src[i]);
}
void opt_doReaderMAC(uint8_t *cc_nr_p, uint8_t *div_key_p, uint8_t mac[4])
{
void opt_doReaderMAC(uint8_t *cc_nr_p, uint8_t *div_key_p, uint8_t mac[4]) {
static uint8_t cc_nr[12];
opt_reverse_arraybytecpy(cc_nr, cc_nr_p, 12);
uint8_t dest [] = {0, 0, 0, 0, 0, 0, 0, 0};
@ -215,8 +208,7 @@ void opt_doReaderMAC(uint8_t *cc_nr_p, uint8_t *div_key_p, uint8_t mac[4])
opt_reverse_arraybytecpy(mac, dest, 4);
return;
}
void opt_doTagMAC(uint8_t *cc_p, const uint8_t *div_key_p, uint8_t mac[4])
{
void opt_doTagMAC(uint8_t *cc_p, const uint8_t *div_key_p, uint8_t mac[4]) {
static uint8_t cc_nr[8 + 4 + 4];
opt_reverse_arraybytecpy(cc_nr, cc_p, 12);
State _init = {
@ -241,8 +233,7 @@ void opt_doTagMAC(uint8_t *cc_p, const uint8_t *div_key_p, uint8_t mac[4])
* @param div_key_p
* @return the cipher state
*/
State opt_doTagMAC_1(uint8_t *cc_p, const uint8_t *div_key_p)
{
State opt_doTagMAC_1(uint8_t *cc_p, const uint8_t *div_key_p) {
static uint8_t cc_nr[8];
opt_reverse_arraybytecpy(cc_nr, cc_p, 8);
State _init = {
@ -263,8 +254,7 @@ State opt_doTagMAC_1(uint8_t *cc_p, const uint8_t *div_key_p)
* @param mac - where to store the MAC
* @param div_key_p - the key to use
*/
void opt_doTagMAC_2(State _init, uint8_t *nr, uint8_t mac[4], const uint8_t *div_key_p)
{
void opt_doTagMAC_2(State _init, uint8_t *nr, uint8_t mac[4], const uint8_t *div_key_p) {
static uint8_t _nr[4];
opt_reverse_arraybytecpy(_nr, nr, 4);
opt_suc(div_key_p, &_init, _nr, 4, true);

View file

@ -3,8 +3,7 @@
#define T0_PCF 8 //period for the pcf7931 in us
#define ALLOC 16
size_t DemodPCF7931(uint8_t **outBlocks)
{
size_t DemodPCF7931(uint8_t **outBlocks) {
uint8_t bits[256] = {0x00};
uint8_t blocks[8][16];
uint8_t *dest = BigBuf_get_addr();
@ -128,8 +127,7 @@ size_t DemodPCF7931(uint8_t **outBlocks)
return num_blocks;
}
bool IsBlock0PCF7931(uint8_t *block)
{
bool IsBlock0PCF7931(uint8_t *block) {
// assuming all RFU bits are set to 0
// if PAC is enabled password is set to 0
if (block[7] == 0x01) {
@ -142,8 +140,7 @@ bool IsBlock0PCF7931(uint8_t *block)
return false;
}
bool IsBlock1PCF7931(uint8_t *block)
{
bool IsBlock1PCF7931(uint8_t *block) {
// assuming all RFU bits are set to 0
if (block[10] == 0 && block[11] == 0 && block[12] == 0 && block[13] == 0)
if ((block[14] & 0x7f) <= 9 && block[15] <= 9)
@ -152,8 +149,7 @@ bool IsBlock1PCF7931(uint8_t *block)
return false;
}
void ReadPCF7931()
{
void ReadPCF7931() {
int found_blocks = 0; // successfully read blocks
int max_blocks = 8; // readable blocks
uint8_t memory_blocks[8][17]; // PCF content
@ -303,8 +299,7 @@ end:
cmd_send(CMD_ACK, 0, 0, 0, 0, 0);
}
static void RealWritePCF7931(uint8_t *pass, uint16_t init_delay, int32_t l, int32_t p, uint8_t address, uint8_t byte, uint8_t data)
{
static void RealWritePCF7931(uint8_t *pass, uint16_t init_delay, int32_t l, int32_t p, uint8_t address, uint8_t byte, uint8_t data) {
uint32_t tab[1024] = {0}; // data times frame
uint32_t u = 0;
uint8_t parity = 0;
@ -386,8 +381,7 @@ static void RealWritePCF7931(uint8_t *pass, uint16_t init_delay, int32_t l, int3
@param byte : address of the byte to write
@param data : data to write
*/
void WritePCF7931(uint8_t pass1, uint8_t pass2, uint8_t pass3, uint8_t pass4, uint8_t pass5, uint8_t pass6, uint8_t pass7, uint16_t init_delay, int32_t l, int32_t p, uint8_t address, uint8_t byte, uint8_t data)
{
void WritePCF7931(uint8_t pass1, uint8_t pass2, uint8_t pass3, uint8_t pass4, uint8_t pass5, uint8_t pass6, uint8_t pass7, uint16_t init_delay, int32_t l, int32_t p, uint8_t address, uint8_t byte, uint8_t data) {
Dbprintf("Initialization delay : %d us", init_delay);
Dbprintf("Offsets : %d us on the low pulses width, %d us on the low pulses positions", l, p);
Dbprintf("Password (LSB first on each byte): %02x %02x %02x %02x %02x %02x %02x", pass1, pass2, pass3, pass4, pass5, pass6, pass7);
@ -405,8 +399,7 @@ void WritePCF7931(uint8_t pass1, uint8_t pass2, uint8_t pass3, uint8_t pass4, ui
* @param tab : array of the data frame
*/
void SendCmdPCF7931(uint32_t *tab)
{
void SendCmdPCF7931(uint32_t *tab) {
uint16_t u = 0, tempo = 0;
Dbprintf("Sending data frame...");
@ -462,8 +455,7 @@ void SendCmdPCF7931(uint32_t *tab)
* @param l : offset on low pulse width
* @param p : offset on low pulse positioning
*/
bool AddBytePCF7931(uint8_t byte, uint32_t *tab, int32_t l, int32_t p)
{
bool AddBytePCF7931(uint8_t byte, uint32_t *tab, int32_t l, int32_t p) {
uint32_t u;
for (u = 0; u < 8; ++u) {
if (byte & (1 << u)) { //bit is 1
@ -482,8 +474,7 @@ bool AddBytePCF7931(uint8_t byte, uint32_t *tab, int32_t l, int32_t p)
* @param l : offset on low pulse width
* @param p : offset on low pulse positioning
*/
bool AddBitPCF7931(bool b, uint32_t *tab, int32_t l, int32_t p)
{
bool AddBitPCF7931(bool b, uint32_t *tab, int32_t l, int32_t p) {
uint8_t u = 0;
//we put the cursor at the last value of the array
@ -518,8 +509,7 @@ bool AddBitPCF7931(bool b, uint32_t *tab, int32_t l, int32_t p)
* @param c : delay of the last high pulse
* @param tab : array of the data frame
*/
bool AddPatternPCF7931(uint32_t a, uint32_t b, uint32_t c, uint32_t *tab)
{
bool AddPatternPCF7931(uint32_t a, uint32_t b, uint32_t c, uint32_t *tab) {
uint32_t u = 0;
for (u = 0; tab[u] != 0; u += 3) {} //we put the cursor at the last value of the array

View file

@ -59,8 +59,7 @@ char const hex2ascii_data[] = "0123456789abcdefghijklmnopqrstuvwxyz";
* The buffer pointed to by `nbuf' must have length >= MAXNBUF.
*/
static char *
ksprintn(char *nbuf, uintmax_t num, int base, int *lenp, int upper)
{
ksprintn(char *nbuf, uintmax_t num, int base, int *lenp, int upper) {
char *p, c;
p = nbuf;
@ -101,8 +100,7 @@ ksprintn(char *nbuf, uintmax_t num, int base, int *lenp, int upper)
* ("%*D", len, ptr, " " -> XX XX XX XX ...
*/
int
kvsprintf(char const *fmt, void *arg, int radix, va_list ap)
{
kvsprintf(char const *fmt, void *arg, int radix, va_list ap) {
#define PCHAR(c) {int cc=(c); *d++ = cc; retval++; }
char nbuf[MAXNBUF];
char *d;
@ -387,7 +385,7 @@ number:
tmp++;
if (!ladjust && padc != '0' && width
&& (width -= tmp) > 0)
&& (width -= tmp) > 0)
while (width--)
PCHAR(padc);
if (neg)
@ -430,14 +428,12 @@ number:
#undef PCHAR
}
int vsprintf(char *dest, const char *fmt, va_list ap)
{
int vsprintf(char *dest, const char *fmt, va_list ap) {
return kvsprintf(fmt, dest, 10, ap);
}
int
sprintf(char *dest, const char *fmt, ...)
{
sprintf(char *dest, const char *fmt, ...) {
/* http://www.pagetable.com/?p=298 */
int retval;
va_list ap;

View file

@ -21,8 +21,7 @@ static uint8_t *next_free_memory;
extern struct common_area common_area;
extern char __data_src_start__, __data_start__, __data_end__, __bss_start__, __bss_end__;
static voidpf inflate_malloc(voidpf opaque, uInt items, uInt size)
{
static voidpf inflate_malloc(voidpf opaque, uInt items, uInt size) {
uint8_t *allocated_memory;
allocated_memory = next_free_memory;
@ -30,13 +29,11 @@ static voidpf inflate_malloc(voidpf opaque, uInt items, uInt size)
return allocated_memory;
}
static void inflate_free(voidpf opaque, voidpf address)
{
static void inflate_free(voidpf opaque, voidpf address) {
// nothing to do
}
static void uncompress_data_section(void)
{
static void uncompress_data_section(void) {
z_stream data_section;
next_free_memory = BigBuf_get_addr();
@ -60,8 +57,7 @@ static void uncompress_data_section(void)
common_area.arg1 = data_section.total_in;
}
void __attribute__((section(".startos"))) Vector(void)
{
void __attribute__((section(".startos"))) Vector(void) {
/* Stack should have been set up by the bootloader */
// char *src;
char *dst, *end;

View file

@ -9,8 +9,7 @@
//-----------------------------------------------------------------------------
#include "string.h"
void *memcpy(void *dest, const void *src, int len)
{
void *memcpy(void *dest, const void *src, int len) {
uint8_t *d = dest;
const uint8_t *s = src;
while ((len--) > 0) {
@ -21,8 +20,7 @@ void *memcpy(void *dest, const void *src, int len)
return dest;
}
void *memset(void *dest, int c, int len)
{
void *memset(void *dest, int c, int len) {
uint8_t *d = dest;
while ((len--) > 0) {
*d = c;
@ -31,8 +29,7 @@ void *memset(void *dest, int c, int len)
return dest;
}
int memcmp(const void *av, const void *bv, int len)
{
int memcmp(const void *av, const void *bv, int len) {
const uint8_t *a = av;
const uint8_t *b = bv;
@ -46,14 +43,12 @@ int memcmp(const void *av, const void *bv, int len)
return 0;
}
void memxor(uint8_t *dest, uint8_t *src, size_t len)
{
void memxor(uint8_t *dest, uint8_t *src, size_t len) {
for (; len > 0; len--, dest++, src++)
*dest ^= *src;
}
int strlen(const char *str)
{
int strlen(const char *str) {
int l = 0;
while (*str) {
l++;
@ -62,8 +57,7 @@ int strlen(const char *str)
return l;
}
char *strncat(char *dest, const char *src, unsigned int n)
{
char *strncat(char *dest, const char *src, unsigned int n) {
unsigned int dest_len = strlen(dest);
unsigned int i;
@ -74,8 +68,7 @@ char *strncat(char *dest, const char *src, unsigned int n)
return dest;
}
char *strcat(char *dest, const char *src)
{
char *strcat(char *dest, const char *src) {
unsigned int dest_len = strlen(dest);
unsigned int i;
@ -88,8 +81,7 @@ char *strcat(char *dest, const char *src)
////////////////////////////////////////// code to do 'itoa'
/* reverse: reverse string s in place */
void strreverse(char s[])
{
void strreverse(char s[]) {
int c, i, j;
for (i = 0, j = strlen(s) - 1; i < j; i++, j--) {
@ -100,8 +92,7 @@ void strreverse(char s[])
}
/* itoa: convert n to characters in s */
void itoa(int n, char s[])
{
void itoa(int n, char s[]) {
int i, sign;
if ((sign = n) < 0) /* record sign */

View file

@ -11,8 +11,7 @@
#include "ticks.h"
// attempt at high resolution microsecond timer
// beware: timer counts in 21.3uS increments (1024/48Mhz)
void SpinDelayUs(int us)
{
void SpinDelayUs(int us) {
int ticks = (48 * us) >> 10;
// Borrow a PWM unit for my real-time clock
@ -34,8 +33,7 @@ void SpinDelayUs(int us)
}
}
void SpinDelay(int ms)
{
void SpinDelay(int ms) {
// convert to uS and call microsecond delay function
SpinDelayUs(ms * 1000);
}
@ -48,8 +46,7 @@ void SpinDelay(int ms)
// SpinDelay(1000);
// ti = GetTickCount() - ti;
// Dbprintf("timer(1s): %d t=%d", ti, GetTickCount());
void StartTickCount(void)
{
void StartTickCount(void) {
// This timer is based on the slow clock. The slow clock frequency is between 22kHz and 40kHz.
// We can determine the actual slow clock frequency by looking at the Main Clock Frequency Register.
uint16_t mainf = AT91C_BASE_PMC->PMC_MCFR & 0xffff; // = 16 * main clock frequency (16MHz) / slow clock frequency
@ -61,16 +58,14 @@ void StartTickCount(void)
/*
* Get the current count.
*/
uint32_t RAMFUNC GetTickCount(void)
{
uint32_t RAMFUNC GetTickCount(void) {
return AT91C_BASE_RTTC->RTTC_RTVR;// was * 2;
}
// -------------------------------------------------------------------------
// microseconds timer
// -------------------------------------------------------------------------
void StartCountUS(void)
{
void StartCountUS(void) {
AT91C_BASE_PMC->PMC_PCER |= (1 << AT91C_ID_TC0) | (1 << AT91C_ID_TC1);
AT91C_BASE_TCB->TCB_BMR = AT91C_TCB_TC0XC0S_NONE | AT91C_TCB_TC1XC1S_TIOA0 | AT91C_TCB_TC2XC2S_NONE;
@ -93,8 +88,7 @@ void StartCountUS(void)
while (AT91C_BASE_TC1->TC_CV > 0);
}
uint32_t RAMFUNC GetCountUS(void)
{
uint32_t RAMFUNC GetCountUS(void) {
//return (AT91C_BASE_TC1->TC_CV * 0x8000) + ((AT91C_BASE_TC0->TC_CV / 15) * 10);
// By suggestion from PwPiwi, http://www.proxmark.org/forum/viewtopic.php?pid=17548#p17548
return ((uint32_t)AT91C_BASE_TC1->TC_CV) * 0x8000 + (((uint32_t)AT91C_BASE_TC0->TC_CV) * 2) / 3;
@ -103,8 +97,7 @@ uint32_t RAMFUNC GetCountUS(void)
// -------------------------------------------------------------------------
// Timer for iso14443 commands. Uses ssp_clk from FPGA
// -------------------------------------------------------------------------
void StartCountSspClk(void)
{
void StartCountSspClk(void) {
AT91C_BASE_PMC->PMC_PCER |= (1 << AT91C_ID_TC0) | (1 << AT91C_ID_TC1) | (1 << AT91C_ID_TC2); // Enable Clock to all timers
AT91C_BASE_TCB->TCB_BMR = AT91C_TCB_TC0XC0S_TIOA1 // XC0 Clock = TIOA1
| AT91C_TCB_TC1XC1S_NONE // XC1 Clock = none
@ -161,16 +154,14 @@ void StartCountSspClk(void)
// Therefore need to wait quite some time before we can use the counter.
while (AT91C_BASE_TC2->TC_CV > 0);
}
void ResetSspClk(void)
{
void ResetSspClk(void) {
//enable clock of timer and software trigger
AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG;
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG;
AT91C_BASE_TC2->TC_CCR = AT91C_TC_CLKEN | AT91C_TC_SWTRG;
while (AT91C_BASE_TC2->TC_CV > 0);
}
uint32_t RAMFUNC GetCountSspClk(void)
{
uint32_t RAMFUNC GetCountSspClk(void) {
uint32_t tmp_count = (AT91C_BASE_TC2->TC_CV << 16) | AT91C_BASE_TC0->TC_CV;
if ((tmp_count & 0x0000ffff) == 0) //small chance that we may have missed an increment in TC2
return (AT91C_BASE_TC2->TC_CV << 16);
@ -181,8 +172,7 @@ uint32_t RAMFUNC GetCountSspClk(void)
// Timer for bitbanging, or LF stuff when you need a very precis timer
// 1us = 1.5ticks
// -------------------------------------------------------------------------
void StartTicks(void)
{
void StartTicks(void) {
// initialization of the timer
AT91C_BASE_PMC->PMC_PCER |= (1 << AT91C_ID_TC0) | (1 << AT91C_ID_TC1);
AT91C_BASE_TCB->TCB_BMR = AT91C_TCB_TC0XC0S_NONE | AT91C_TCB_TC1XC1S_TIOA0 | AT91C_TCB_TC2XC2S_NONE;
@ -215,8 +205,7 @@ void StartTicks(void)
while (AT91C_BASE_TC0->TC_CV > 0);
}
uint32_t GetTicks(void)
{
uint32_t GetTicks(void) {
uint32_t hi, lo;
do {
@ -229,8 +218,7 @@ uint32_t GetTicks(void)
// Wait - Spindelay in ticks.
// if called with a high number, this will trigger the WDT...
void WaitTicks(uint32_t ticks)
{
void WaitTicks(uint32_t ticks) {
if (ticks == 0) return;
ticks += GetTicks();
while (GetTicks() < ticks);
@ -238,18 +226,15 @@ void WaitTicks(uint32_t ticks)
// Wait / Spindelay in us (microseconds)
// 1us = 1.5ticks.
void WaitUS(uint16_t us)
{
void WaitUS(uint16_t us) {
WaitTicks((uint32_t)us * 3 / 2);
}
void WaitMS(uint16_t ms)
{
void WaitMS(uint16_t ms) {
WaitTicks((uint32_t)ms * 1500);
}
// stop clock
void StopTicks(void)
{
void StopTicks(void) {
AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKDIS;
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKDIS;
}

View file

@ -9,8 +9,7 @@
//-----------------------------------------------------------------------------
#include "util.h"
size_t nbytes(size_t nbits)
{
size_t nbytes(size_t nbits) {
return (nbits >> 3) + ((nbits % 8) > 0);
}
@ -19,8 +18,7 @@ size_t nbytes(size_t nbits)
Returns the value v with the bottom b [0,32] bits reflected.
Example: reflect(0x3e23L,3) == 0x3e26
*/
uint32_t reflect(uint32_t v, int b)
{
uint32_t reflect(uint32_t v, int b) {
uint32_t t = v;
for (int i = 0; i < b; ++i) {
if (t & 1)
@ -32,12 +30,10 @@ uint32_t reflect(uint32_t v, int b)
return v;
}
uint8_t reflect8(uint8_t b)
{
uint8_t reflect8(uint8_t b) {
return ((b * 0x80200802ULL) & 0x0884422110ULL) * 0x0101010101ULL >> 32;
}
uint16_t reflect16(uint16_t b)
{
uint16_t reflect16(uint16_t b) {
uint16_t v = 0;
v |= (b & 0x8000) >> 15;
v |= (b & 0x4000) >> 13;
@ -59,16 +55,14 @@ uint16_t reflect16(uint16_t b)
return v;
}
void num_to_bytes(uint64_t n, size_t len, uint8_t *dest)
{
void num_to_bytes(uint64_t n, size_t len, uint8_t *dest) {
while (len--) {
dest[len] = (uint8_t) n;
n >>= 8;
}
}
uint64_t bytes_to_num(uint8_t *src, size_t len)
{
uint64_t bytes_to_num(uint8_t *src, size_t len) {
uint64_t num = 0;
while (len--) {
num = (num << 8) | (*src);
@ -78,8 +72,7 @@ uint64_t bytes_to_num(uint8_t *src, size_t len)
}
// RotateLeft - Ultralight, Desfire
void rol(uint8_t *data, const size_t len)
{
void rol(uint8_t *data, const size_t len) {
uint8_t first = data[0];
for (size_t i = 0; i < len - 1; i++) {
data[i] = data[i + 1];
@ -87,22 +80,19 @@ void rol(uint8_t *data, const size_t len)
data[len - 1] = first;
}
void lsl(uint8_t *data, size_t len)
{
void lsl(uint8_t *data, size_t len) {
for (size_t n = 0; n < len - 1; n++) {
data[n] = (data[n] << 1) | (data[n + 1] >> 7);
}
data[len - 1] <<= 1;
}
int32_t le24toh(uint8_t data[3])
{
int32_t le24toh(uint8_t data[3]) {
return (data[2] << 16) | (data[1] << 8) | data[0];
}
//convert hex digit to integer
uint8_t hex2int(char hexchar)
{
uint8_t hex2int(char hexchar) {
switch (hexchar) {
case '0':
return 0;
@ -163,8 +153,7 @@ uint8_t hex2int(char hexchar)
}
}
void LEDsoff()
{
void LEDsoff() {
LED_A_OFF();
LED_B_OFF();
LED_C_OFF();
@ -172,8 +161,7 @@ void LEDsoff()
}
// LEDs: R(C) O(A) G(B) -- R(D) [1, 2, 4 and 8]
void LED(int led, int ms)
{
void LED(int led, int ms) {
if (led & LED_RED)
LED_C_ON();
if (led & LED_ORANGE)
@ -198,8 +186,7 @@ void LED(int led, int ms)
LED_D_OFF();
}
void SpinOff(uint32_t pause)
{
void SpinOff(uint32_t pause) {
LED_A_OFF();
LED_B_OFF();
LED_C_OFF();
@ -208,8 +195,7 @@ void SpinOff(uint32_t pause)
}
// 0=A, 1=B, 2=C, 3=D
void SpinErr(uint8_t led, uint32_t speed, uint8_t times)
{
void SpinErr(uint8_t led, uint32_t speed, uint8_t times) {
SpinOff(speed);
NTIME(times) {
switch (led) {
@ -230,8 +216,7 @@ void SpinErr(uint8_t led, uint32_t speed, uint8_t times)
}
}
void SpinDown(uint32_t speed)
{
void SpinDown(uint32_t speed) {
SpinOff(speed);
LED_D_ON();
SpinDelay(speed);
@ -247,8 +232,7 @@ void SpinDown(uint32_t speed)
LED_A_OFF();
}
void SpinUp(uint32_t speed)
{
void SpinUp(uint32_t speed) {
SpinOff(speed);
LED_A_ON();
SpinDelay(speed);
@ -269,8 +253,7 @@ void SpinUp(uint32_t speed)
// not clicked, or held down (for ms || 1sec)
// In general, don't use this function unless you expect a
// double click, otherwise it will waste 500ms -- use BUTTON_HELD instead
int BUTTON_CLICKED(int ms)
{
int BUTTON_CLICKED(int ms) {
// Up to 500ms in between clicks to mean a double click
int ticks = (48000 * (ms ? ms : 1000)) >> 10;
@ -328,8 +311,7 @@ int BUTTON_CLICKED(int ms)
}
// Determine if a button is held down
int BUTTON_HELD(int ms)
{
int BUTTON_HELD(int ms) {
// If button is held for one second
int ticks = (48000 * (ms ? ms : 1000)) >> 10;
@ -369,8 +351,7 @@ int BUTTON_HELD(int ms)
* verifies the magic properties, then stores a formatted string, prefixed by
* prefix in dst.
*/
void FormatVersionInformation(char *dst, int len, const char *prefix, void *version_information)
{
void FormatVersionInformation(char *dst, int len, const char *prefix, void *version_information) {
struct version_information *v = (struct version_information *)version_information;
dst[0] = 0;
strncat(dst, prefix, len - 1);

View file

@ -37,15 +37,13 @@
//#define UART_WRITE(P, BUF, SIZ) (P)->uart_write(BUF, SIZ, (P)->extobj)
#define UART_WRITE(BUF) DbprintfEx(FLAG_RAWPRINT, "%s", BUF)
int vtsend_init(vtsend_t *p, VTSEND_SERIAL_WRITE uart_write, void *extobj)
{
int vtsend_init(vtsend_t *p, VTSEND_SERIAL_WRITE uart_write, void *extobj) {
p->uart_write = uart_write;
p->extobj = extobj;
return 0;
}
int vtsend_cursor_position(vtsend_t *p, const int column, const int line)
{
int vtsend_cursor_position(vtsend_t *p, const int column, const int line) {
char buf[1 + 8];
buf[0] = ESC;
buf[1] = '[';
@ -60,8 +58,7 @@ int vtsend_cursor_position(vtsend_t *p, const int column, const int line)
return 0;
}
int vtsend_cursor_up(vtsend_t *p, const int n)
{
int vtsend_cursor_up(vtsend_t *p, const int n) {
char buf[1 + 5];
buf[0] = ESC;
buf[1] = '[';
@ -74,8 +71,7 @@ int vtsend_cursor_up(vtsend_t *p, const int n)
return 0;
}
int vtsend_cursor_down(vtsend_t *p, const int n)
{
int vtsend_cursor_down(vtsend_t *p, const int n) {
char buf[1 + 5];
buf[0] = ESC;
buf[1] = '[';
@ -88,8 +84,7 @@ int vtsend_cursor_down(vtsend_t *p, const int n)
return 0;
}
int vtsend_cursor_forward(vtsend_t *p, const int n)
{
int vtsend_cursor_forward(vtsend_t *p, const int n) {
char buf[1 + 5];
buf[0] = ESC;
buf[1] = '[';
@ -102,8 +97,7 @@ int vtsend_cursor_forward(vtsend_t *p, const int n)
return 0;
}
int vtsend_cursor_backward(vtsend_t *p, const int n)
{
int vtsend_cursor_backward(vtsend_t *p, const int n) {
char buf[1 + 5];
buf[0] = ESC;
buf[1] = '[';
@ -116,8 +110,7 @@ int vtsend_cursor_backward(vtsend_t *p, const int n)
return 0;
}
int vtsend_cursor_position_save(vtsend_t *p)
{
int vtsend_cursor_position_save(vtsend_t *p) {
char buf[1 + 3];
buf[0] = ESC;
buf[1] = '[';
@ -128,8 +121,7 @@ int vtsend_cursor_position_save(vtsend_t *p)
return 0;
}
int vtsend_cursor_position_restore(vtsend_t *p)
{
int vtsend_cursor_position_restore(vtsend_t *p) {
char buf[1 + 3];
buf[0] = ESC;
buf[1] = '[';
@ -140,8 +132,7 @@ int vtsend_cursor_position_restore(vtsend_t *p)
return 0;
}
int vtsend_erase_display(vtsend_t *p)
{
int vtsend_erase_display(vtsend_t *p) {
char buf[1 + 4];
buf[0] = ESC;
buf[1] = '[';
@ -153,8 +144,7 @@ int vtsend_erase_display(vtsend_t *p)
return 0;
}
int vtsend_erase_line(vtsend_t *p)
{
int vtsend_erase_line(vtsend_t *p) {
char buf[1 + 4];
buf[0] = ESC;
buf[1] = '[';
@ -166,8 +156,7 @@ int vtsend_erase_line(vtsend_t *p)
return 0;
}
int vtsend_set_color_foreground(vtsend_t *p, const int color)
{
int vtsend_set_color_foreground(vtsend_t *p, const int color) {
char buf[1 + 5];
buf[0] = ESC;
buf[1] = '[';
@ -180,8 +169,7 @@ int vtsend_set_color_foreground(vtsend_t *p, const int color)
return 0;
}
int vtsend_set_color_background(vtsend_t *p, const int color)
{
int vtsend_set_color_background(vtsend_t *p, const int color) {
char buf[1 + 5];
buf[0] = ESC;
buf[1] = '[';
@ -194,8 +182,7 @@ int vtsend_set_color_background(vtsend_t *p, const int color)
return 0;
}
int vtsend_set_attribute(vtsend_t *p, const int attr)
{
int vtsend_set_attribute(vtsend_t *p, const int attr) {
char buf[1 + 5];
buf[0] = ESC;
buf[1] = '[';
@ -208,8 +195,7 @@ int vtsend_set_attribute(vtsend_t *p, const int attr)
return 0;
}
int vtsend_set_scroll_region(vtsend_t *p, const int top, const int bottom)
{
int vtsend_set_scroll_region(vtsend_t *p, const int top, const int bottom) {
char buf[1 + 8];
buf[0] = ESC;
buf[1] = '[';
@ -225,8 +211,7 @@ int vtsend_set_scroll_region(vtsend_t *p, const int top, const int bottom)
return 0;
}
int vtsend_set_cursor(vtsend_t *p, const int visible)
{
int vtsend_set_cursor(vtsend_t *p, const int visible) {
if (visible) {
char buf[1 + 6];
buf[0] = ESC;
@ -253,8 +238,7 @@ int vtsend_set_cursor(vtsend_t *p, const int visible)
return 0;
}
int vtsend_reset(vtsend_t *p)
{
int vtsend_reset(vtsend_t *p) {
char buf[1 + 2];
buf[0] = ESC;
buf[1] = 'c';
@ -264,8 +248,7 @@ int vtsend_reset(vtsend_t *p)
return 0;
}
int vtsend_draw_box(vtsend_t *p, const int x1, const int y1, const int x2, const int y2)
{
int vtsend_draw_box(vtsend_t *p, const int x1, const int y1, const int x2, const int y2) {
int i;
vtsend_cursor_position(p, x1, y1);
@ -285,8 +268,7 @@ int vtsend_draw_box(vtsend_t *p, const int x1, const int y1, const int x2, const
return 0;
}
int vtsend_fill_box(vtsend_t *p, const int x1, const int y1, const int x2, const int y2)
{
int vtsend_fill_box(vtsend_t *p, const int x1, const int y1, const int x2, const int y2) {
int i, j;
for (i = y1; i <= y2; i++) {
vtsend_cursor_position(p, x1, i);

View file

@ -15,8 +15,7 @@ unsigned int start_addr, end_addr, bootrom_unlocked;
extern char _bootrom_start, _bootrom_end, _flash_start, _flash_end;
extern uint32_t _osimage_entry;
void DbpString(char *str)
{
void DbpString(char *str) {
byte_t len = 0;
while (str[len] != 0x00)
len++;
@ -24,8 +23,7 @@ void DbpString(char *str)
cmd_send(CMD_DEBUG_PRINT_STRING, len, 0, 0, (byte_t *)str, len);
}
static void ConfigClocks(void)
{
static void ConfigClocks(void) {
// we are using a 16 MHz crystal as the basis for everything
// slow clock runs at 32Khz typical regardless of crystal
@ -82,13 +80,11 @@ static void ConfigClocks(void)
while (!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY)) {};
}
static void Fatal(void)
{
static void Fatal(void) {
for (;;) {};
}
void UsbPacketReceived(uint8_t *packet, int len)
{
void UsbPacketReceived(uint8_t *packet, int len) {
int i, dont_ack = 0;
UsbCommand *c = (UsbCommand *)packet;
volatile uint32_t *p;
@ -175,8 +171,8 @@ void UsbPacketReceived(uint8_t *packet, int len)
* bootrom area. In any case they must be within the flash area.
*/
if ((bootrom_unlocked || ((cmd_start >= prot_end) || (cmd_end < prot_start))) &&
(cmd_start >= allow_start) &&
(cmd_end <= allow_end)) {
(cmd_start >= allow_start) &&
(cmd_end <= allow_end)) {
start_addr = cmd_start;
end_addr = cmd_end;
} else {
@ -197,8 +193,7 @@ void UsbPacketReceived(uint8_t *packet, int len)
cmd_send(CMD_ACK, arg0, 0, 0, 0, 0);
}
static void flash_mode(int externally_entered)
{
static void flash_mode(int externally_entered) {
start_addr = 0;
end_addr = 0;
bootrom_unlocked = 0;
@ -232,8 +227,7 @@ static void flash_mode(int externally_entered)
}
}
void BootROM(void)
{
void BootROM(void) {
//------------
// First set up all the I/O pins; GPIOs configured directly, other ones
// just need to be assigned to the appropriate peripheral.

View file

@ -12,8 +12,7 @@
#define HMAC_POS_DATA 0x008
#define HMAC_POS_TAG 0x1B4
void nfc3d_amiibo_calc_seed(const uint8_t *dump, uint8_t *key)
{
void nfc3d_amiibo_calc_seed(const uint8_t *dump, uint8_t *key) {
memcpy(key + 0x00, dump + 0x029, 0x02);
memset(key + 0x02, 0x00, 0x0E);
memcpy(key + 0x10, dump + 0x1D4, 0x08);
@ -21,16 +20,14 @@ void nfc3d_amiibo_calc_seed(const uint8_t *dump, uint8_t *key)
memcpy(key + 0x20, dump + 0x1E8, 0x20);
}
void nfc3d_amiibo_keygen(const nfc3d_keygen_masterkeys *masterKeys, const uint8_t *dump, nfc3d_keygen_derivedkeys *derivedKeys)
{
void nfc3d_amiibo_keygen(const nfc3d_keygen_masterkeys *masterKeys, const uint8_t *dump, nfc3d_keygen_derivedkeys *derivedKeys) {
uint8_t seed[NFC3D_KEYGEN_SEED_SIZE];
nfc3d_amiibo_calc_seed(dump, seed);
nfc3d_keygen(masterKeys, seed, derivedKeys);
}
void nfc3d_amiibo_cipher(const nfc3d_keygen_derivedkeys *keys, const uint8_t *in, uint8_t *out)
{
void nfc3d_amiibo_cipher(const nfc3d_keygen_derivedkeys *keys, const uint8_t *in, uint8_t *out) {
mbedtls_aes_context aes;
size_t nc_off = 0;
unsigned char nonce_counter[16];
@ -49,8 +46,7 @@ void nfc3d_amiibo_cipher(const nfc3d_keygen_derivedkeys *keys, const uint8_t *in
memcpy(out + 0x1D4, in + 0x1D4, 0x034);
}
void nfc3d_amiibo_tag_to_internal(const uint8_t *tag, uint8_t *intl)
{
void nfc3d_amiibo_tag_to_internal(const uint8_t *tag, uint8_t *intl) {
memcpy(intl + 0x000, tag + 0x008, 0x008);
memcpy(intl + 0x008, tag + 0x080, 0x020);
memcpy(intl + 0x028, tag + 0x010, 0x024);
@ -60,8 +56,7 @@ void nfc3d_amiibo_tag_to_internal(const uint8_t *tag, uint8_t *intl)
memcpy(intl + 0x1DC, tag + 0x054, 0x02C);
}
void nfc3d_amiibo_internal_to_tag(const uint8_t *intl, uint8_t *tag)
{
void nfc3d_amiibo_internal_to_tag(const uint8_t *intl, uint8_t *tag) {
memcpy(tag + 0x008, intl + 0x000, 0x008);
memcpy(tag + 0x080, intl + 0x008, 0x020);
memcpy(tag + 0x010, intl + 0x028, 0x024);
@ -71,8 +66,7 @@ void nfc3d_amiibo_internal_to_tag(const uint8_t *intl, uint8_t *tag)
memcpy(tag + 0x054, intl + 0x1DC, 0x02C);
}
bool nfc3d_amiibo_unpack(const nfc3d_amiibo_keys *amiiboKeys, const uint8_t *tag, uint8_t *plain)
{
bool nfc3d_amiibo_unpack(const nfc3d_amiibo_keys *amiiboKeys, const uint8_t *tag, uint8_t *plain) {
uint8_t internal[NFC3D_AMIIBO_SIZE];
nfc3d_keygen_derivedkeys dataKeys;
nfc3d_keygen_derivedkeys tagKeys;
@ -100,8 +94,7 @@ bool nfc3d_amiibo_unpack(const nfc3d_amiibo_keys *amiiboKeys, const uint8_t *tag
memcmp(plain + HMAC_POS_TAG, internal + HMAC_POS_TAG, 32) == 0;
}
void nfc3d_amiibo_pack(const nfc3d_amiibo_keys *amiiboKeys, const uint8_t *plain, uint8_t *tag)
{
void nfc3d_amiibo_pack(const nfc3d_amiibo_keys *amiiboKeys, const uint8_t *plain, uint8_t *tag) {
uint8_t cipher[NFC3D_AMIIBO_SIZE];
nfc3d_keygen_derivedkeys tagKeys;
nfc3d_keygen_derivedkeys dataKeys;
@ -137,8 +130,7 @@ void nfc3d_amiibo_pack(const nfc3d_amiibo_keys *amiiboKeys, const uint8_t *plain
nfc3d_amiibo_internal_to_tag(cipher, tag);
}
bool nfc3d_amiibo_load_keys(nfc3d_amiibo_keys *amiiboKeys, const char *path)
{
bool nfc3d_amiibo_load_keys(nfc3d_amiibo_keys *amiiboKeys, const char *path) {
FILE *f = fopen(path, "rb");
if (!f) {
return false;
@ -160,8 +152,7 @@ bool nfc3d_amiibo_load_keys(nfc3d_amiibo_keys *amiiboKeys, const char *path)
return true;
}
void nfc3d_amiibo_copy_app_data(const uint8_t *src, uint8_t *dst)
{
void nfc3d_amiibo_copy_app_data(const uint8_t *src, uint8_t *dst) {
//uint16_t *ami_nb_wr = (uint16_t*)(dst + 0x29);

View file

@ -14,8 +14,7 @@
static char *self;
void amiitool_usage()
{
void amiitool_usage() {
fprintf(stderr,
"amiitool build %i (commit %s-%08x)\n"
"by Marcos Del Sol Vives <marcos@dracon.es>\n"
@ -33,8 +32,7 @@ void amiitool_usage()
);
}
static bool LoadAmiikey(nfc3d_amiibo_keys keys, char *keyfile)
{
static bool LoadAmiikey(nfc3d_amiibo_keys keys, char *keyfile) {
if (!nfc3d_amiibo_load_keys(&keys, keyfile)) {
PrintAndLogEx(ERR, "Could not load keys from '%s'", keyfile);
@ -43,8 +41,7 @@ static bool LoadAmiikey(nfc3d_amiibo_keys keys, char *keyfile)
return true;
}
int main(int argc, char **argv)
{
int main(int argc, char **argv) {
self = argv[0];
char *infile = NULL;

View file

@ -10,8 +10,7 @@
#include <string.h>
#include <mbedtls/md.h>
void nfc3d_drbg_init(nfc3d_drbg_ctx *ctx, const uint8_t *hmacKey, size_t hmacKeySize, const uint8_t *seed, size_t seedSize)
{
void nfc3d_drbg_init(nfc3d_drbg_ctx *ctx, const uint8_t *hmacKey, size_t hmacKeySize, const uint8_t *seed, size_t seedSize) {
assert(ctx != NULL);
assert(hmacKey != NULL);
assert(seed != NULL);
@ -31,8 +30,7 @@ void nfc3d_drbg_init(nfc3d_drbg_ctx *ctx, const uint8_t *hmacKey, size_t hmacKey
mbedtls_md_hmac_starts(&ctx->hmacCtx, hmacKey, hmacKeySize);
}
void nfc3d_drbg_step(nfc3d_drbg_ctx *ctx, uint8_t *output)
{
void nfc3d_drbg_step(nfc3d_drbg_ctx *ctx, uint8_t *output) {
assert(ctx != NULL);
assert(output != NULL);
@ -53,14 +51,12 @@ void nfc3d_drbg_step(nfc3d_drbg_ctx *ctx, uint8_t *output)
mbedtls_md_hmac_finish(&ctx->hmacCtx, output);
}
void nfc3d_drbg_cleanup(nfc3d_drbg_ctx *ctx)
{
void nfc3d_drbg_cleanup(nfc3d_drbg_ctx *ctx) {
assert(ctx != NULL);
mbedtls_md_free(&ctx->hmacCtx);
}
void nfc3d_drbg_generate_bytes(const uint8_t *hmacKey, size_t hmacKeySize, const uint8_t *seed, size_t seedSize, uint8_t *output, size_t outputSize)
{
void nfc3d_drbg_generate_bytes(const uint8_t *hmacKey, size_t hmacKeySize, const uint8_t *seed, size_t seedSize, uint8_t *output, size_t outputSize) {
uint8_t temp[NFC3D_DRBG_OUTPUT_SIZE];
nfc3d_drbg_ctx rngCtx;

View file

@ -10,8 +10,7 @@
#include <stdio.h>
#include <string.h>
void nfc3d_keygen_prepare_seed(const nfc3d_keygen_masterkeys *baseKeys, const uint8_t *baseSeed, uint8_t *output, size_t *outputSize)
{
void nfc3d_keygen_prepare_seed(const nfc3d_keygen_masterkeys *baseKeys, const uint8_t *baseSeed, uint8_t *output, size_t *outputSize) {
assert(baseKeys != NULL);
assert(baseSeed != NULL);
assert(output != NULL);
@ -45,8 +44,7 @@ void nfc3d_keygen_prepare_seed(const nfc3d_keygen_masterkeys *baseKeys, const ui
*outputSize = output - start;
}
void nfc3d_keygen(const nfc3d_keygen_masterkeys *baseKeys, const uint8_t *baseSeed, nfc3d_keygen_derivedkeys *derivedKeys)
{
void nfc3d_keygen(const nfc3d_keygen_masterkeys *baseKeys, const uint8_t *baseSeed, nfc3d_keygen_derivedkeys *derivedKeys) {
uint8_t preparedSeed[NFC3D_DRBG_MAX_SEED_SIZE];
size_t preparedSeedSize;

View file

@ -17,8 +17,7 @@
break;\
}
int main(int argc, char **argv)
{
int main(int argc, char **argv) {
if (argc != 3 && argc != 4) {
printf("\n\tusage: cli <command 1> <command 2> [logfile (default cli.log)]\n");
printf("\n");

File diff suppressed because it is too large Load diff

View file

@ -19,8 +19,7 @@ char *programHint = NULL;
char *programHelp = NULL;
char buf[500] = {0};
int CLIParserInit(char *vprogramName, char *vprogramHint, char *vprogramHelp)
{
int CLIParserInit(char *vprogramName, char *vprogramHint, char *vprogramHelp) {
argtable = NULL;
argtableLen = 0;
programName = vprogramName;
@ -31,8 +30,7 @@ int CLIParserInit(char *vprogramName, char *vprogramHint, char *vprogramHelp)
return 0;
}
int CLIParserParseArg(int argc, char **argv, void *vargtable[], size_t vargtableLen, bool allowEmptyExec)
{
int CLIParserParseArg(int argc, char **argv, void *vargtable[], size_t vargtableLen, bool allowEmptyExec) {
int nerrors;
argtable = vargtable;
@ -81,13 +79,11 @@ enum ParserState {
#define isSpace(c)(c == ' ' || c == '\t')
int CLIParserParseString(const char *str, void *vargtable[], size_t vargtableLen, bool allowEmptyExec)
{
int CLIParserParseString(const char *str, void *vargtable[], size_t vargtableLen, bool allowEmptyExec) {
return CLIParserParseStringEx(str, vargtable, vargtableLen, allowEmptyExec, false);
}
int CLIParserParseStringEx(const char *str, void *vargtable[], size_t vargtableLen, bool allowEmptyExec, bool clueData)
{
int CLIParserParseStringEx(const char *str, void *vargtable[], size_t vargtableLen, bool allowEmptyExec, bool clueData) {
int argc = 0;
char *argv[200] = {NULL};
@ -147,8 +143,7 @@ int CLIParserParseStringEx(const char *str, void *vargtable[], size_t vargtableL
return CLIParserParseArg(argc, argv, vargtable, vargtableLen, allowEmptyExec);
}
void CLIParserFree()
{
void CLIParserFree() {
arg_freetable(argtable, argtableLen);
argtable = NULL;
@ -156,8 +151,7 @@ void CLIParserFree()
}
// convertors
int CLIParamHexToBuf(struct arg_str *argstr, uint8_t *data, int maxdatalen, int *datalen)
{
int CLIParamHexToBuf(struct arg_str *argstr, uint8_t *data, int maxdatalen, int *datalen) {
*datalen = 0;
int ibuf = 0;
@ -181,8 +175,7 @@ int CLIParamHexToBuf(struct arg_str *argstr, uint8_t *data, int maxdatalen, int
return 0;
}
int CLIParamStrToBuf(struct arg_str *argstr, uint8_t *data, int maxdatalen, int *datalen)
{
int CLIParamStrToBuf(struct arg_str *argstr, uint8_t *data, int maxdatalen, int *datalen) {
*datalen = 0;
if (!argstr->count)
return 0;

View file

@ -11,8 +11,7 @@
static int CmdHelp(const char *Cmd);
int usage_analyse_lcr(void)
{
int usage_analyse_lcr(void) {
PrintAndLogEx(NORMAL, "Specifying the bytes of a UID with a known LRC will find the last byte value");
PrintAndLogEx(NORMAL, "needed to generate that LRC with a rolling XOR. All bytes should be specified in HEX.");
PrintAndLogEx(NORMAL, "");
@ -26,8 +25,7 @@ int usage_analyse_lcr(void)
PrintAndLogEx(NORMAL, "expected output: Target (BA) requires final LRC XOR byte value: 5A");
return 0;
}
int usage_analyse_checksum(void)
{
int usage_analyse_checksum(void) {
PrintAndLogEx(NORMAL, "The bytes will be added with eachother and than limited with the applied mask");
PrintAndLogEx(NORMAL, "Finally compute ones' complement of the least significant bytes");
PrintAndLogEx(NORMAL, "");
@ -43,8 +41,7 @@ int usage_analyse_checksum(void)
PrintAndLogEx(NORMAL, "expected output: 0x61");
return 0;
}
int usage_analyse_crc(void)
{
int usage_analyse_crc(void) {
PrintAndLogEx(NORMAL, "A stub method to test different crc implementations inside the PM3 sourcecode. Just because you figured out the poly, doesn't mean you get the desired output");
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(NORMAL, "Usage: analyse crc [h] <bytes>");
@ -56,8 +53,7 @@ int usage_analyse_crc(void)
PrintAndLogEx(NORMAL, " analyse crc 137AF00A0A0D");
return 0;
}
int usage_analyse_nuid(void)
{
int usage_analyse_nuid(void) {
PrintAndLogEx(NORMAL, "Generate 4byte NUID from 7byte UID");
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(NORMAL, "Usage: analyse hid [h] <bytes>");
@ -69,8 +65,7 @@ int usage_analyse_nuid(void)
PrintAndLogEx(NORMAL, " analyse nuid 11223344556677");
return 0;
}
int usage_analyse_a(void)
{
int usage_analyse_a(void) {
PrintAndLogEx(NORMAL, "Iceman's personal garbage test command");
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(NORMAL, "Usage: analyse a [h] d <bytes>");
@ -83,8 +78,7 @@ int usage_analyse_a(void)
return 0;
}
static uint8_t calculateLRC(uint8_t *bytes, uint8_t len)
{
static uint8_t calculateLRC(uint8_t *bytes, uint8_t len) {
uint8_t LRC = 0;
for (uint8_t i = 0; i < len; i++)
LRC ^= bytes[i];
@ -108,8 +102,7 @@ static uint16_t shiftadd ( uint8_t* bytes, uint8_t len){
return 0;
}
*/
static uint16_t calcSumCrumbAdd(uint8_t *bytes, uint8_t len, uint32_t mask)
{
static uint16_t calcSumCrumbAdd(uint8_t *bytes, uint8_t len, uint32_t mask) {
uint16_t sum = 0;
for (uint8_t i = 0; i < len; i++) {
sum += CRUMB(bytes[i], 0);
@ -120,12 +113,10 @@ static uint16_t calcSumCrumbAdd(uint8_t *bytes, uint8_t len, uint32_t mask)
sum &= mask;
return sum;
}
static uint16_t calcSumCrumbAddOnes(uint8_t *bytes, uint8_t len, uint32_t mask)
{
static uint16_t calcSumCrumbAddOnes(uint8_t *bytes, uint8_t len, uint32_t mask) {
return (~calcSumCrumbAdd(bytes, len, mask) & mask);
}
static uint16_t calcSumNibbleAdd(uint8_t *bytes, uint8_t len, uint32_t mask)
{
static uint16_t calcSumNibbleAdd(uint8_t *bytes, uint8_t len, uint32_t mask) {
uint16_t sum = 0;
for (uint8_t i = 0; i < len; i++) {
sum += NIBBLE_LOW(bytes[i]);
@ -134,12 +125,10 @@ static uint16_t calcSumNibbleAdd(uint8_t *bytes, uint8_t len, uint32_t mask)
sum &= mask;
return sum;
}
static uint16_t calcSumNibbleAddOnes(uint8_t *bytes, uint8_t len, uint32_t mask)
{
static uint16_t calcSumNibbleAddOnes(uint8_t *bytes, uint8_t len, uint32_t mask) {
return (~calcSumNibbleAdd(bytes, len, mask) & mask);
}
static uint16_t calcSumCrumbXor(uint8_t *bytes, uint8_t len, uint32_t mask)
{
static uint16_t calcSumCrumbXor(uint8_t *bytes, uint8_t len, uint32_t mask) {
uint16_t sum = 0;
for (uint8_t i = 0; i < len; i++) {
sum ^= CRUMB(bytes[i], 0);
@ -150,8 +139,7 @@ static uint16_t calcSumCrumbXor(uint8_t *bytes, uint8_t len, uint32_t mask)
sum &= mask;
return sum;
}
static uint16_t calcSumNibbleXor(uint8_t *bytes, uint8_t len, uint32_t mask)
{
static uint16_t calcSumNibbleXor(uint8_t *bytes, uint8_t len, uint32_t mask) {
uint16_t sum = 0;
for (uint8_t i = 0; i < len; i++) {
sum ^= NIBBLE_LOW(bytes[i]);
@ -160,8 +148,7 @@ static uint16_t calcSumNibbleXor(uint8_t *bytes, uint8_t len, uint32_t mask)
sum &= mask;
return sum;
}
static uint16_t calcSumByteXor(uint8_t *bytes, uint8_t len, uint32_t mask)
{
static uint16_t calcSumByteXor(uint8_t *bytes, uint8_t len, uint32_t mask) {
uint16_t sum = 0;
for (uint8_t i = 0; i < len; i++) {
sum ^= bytes[i];
@ -169,8 +156,7 @@ static uint16_t calcSumByteXor(uint8_t *bytes, uint8_t len, uint32_t mask)
sum &= mask;
return sum;
}
static uint16_t calcSumByteAdd(uint8_t *bytes, uint8_t len, uint32_t mask)
{
static uint16_t calcSumByteAdd(uint8_t *bytes, uint8_t len, uint32_t mask) {
uint16_t sum = 0;
for (uint8_t i = 0; i < len; i++) {
sum += bytes[i];
@ -179,13 +165,11 @@ static uint16_t calcSumByteAdd(uint8_t *bytes, uint8_t len, uint32_t mask)
return sum;
}
// Ones complement
static uint16_t calcSumByteAddOnes(uint8_t *bytes, uint8_t len, uint32_t mask)
{
static uint16_t calcSumByteAddOnes(uint8_t *bytes, uint8_t len, uint32_t mask) {
return (~calcSumByteAdd(bytes, len, mask) & mask);
}
static uint16_t calcSumByteSub(uint8_t *bytes, uint8_t len, uint32_t mask)
{
static uint16_t calcSumByteSub(uint8_t *bytes, uint8_t len, uint32_t mask) {
uint8_t sum = 0;
for (uint8_t i = 0; i < len; i++) {
sum -= bytes[i];
@ -193,12 +177,10 @@ static uint16_t calcSumByteSub(uint8_t *bytes, uint8_t len, uint32_t mask)
sum &= mask;
return sum;
}
static uint16_t calcSumByteSubOnes(uint8_t *bytes, uint8_t len, uint32_t mask)
{
static uint16_t calcSumByteSubOnes(uint8_t *bytes, uint8_t len, uint32_t mask) {
return (~calcSumByteSub(bytes, len, mask) & mask);
}
static uint16_t calcSumNibbleSub(uint8_t *bytes, uint8_t len, uint32_t mask)
{
static uint16_t calcSumNibbleSub(uint8_t *bytes, uint8_t len, uint32_t mask) {
uint8_t sum = 0;
for (uint8_t i = 0; i < len; i++) {
sum -= NIBBLE_LOW(bytes[i]);
@ -207,14 +189,12 @@ static uint16_t calcSumNibbleSub(uint8_t *bytes, uint8_t len, uint32_t mask)
sum &= mask;
return sum;
}
static uint16_t calcSumNibbleSubOnes(uint8_t *bytes, uint8_t len, uint32_t mask)
{
static uint16_t calcSumNibbleSubOnes(uint8_t *bytes, uint8_t len, uint32_t mask) {
return (~calcSumNibbleSub(bytes, len, mask) & mask);
}
// BSD shift checksum 8bit version
static uint16_t calcBSDchecksum8(uint8_t *bytes, uint8_t len, uint32_t mask)
{
static uint16_t calcBSDchecksum8(uint8_t *bytes, uint8_t len, uint32_t mask) {
uint16_t sum = 0;
for (uint8_t i = 0; i < len; i++) {
sum = ((sum & 0xFF) >> 1) | ((sum & 0x1) << 7); // rotate accumulator
@ -225,8 +205,7 @@ static uint16_t calcBSDchecksum8(uint8_t *bytes, uint8_t len, uint32_t mask)
return sum;
}
// BSD shift checksum 4bit version
static uint16_t calcBSDchecksum4(uint8_t *bytes, uint8_t len, uint32_t mask)
{
static uint16_t calcBSDchecksum4(uint8_t *bytes, uint8_t len, uint32_t mask) {
uint16_t sum = 0;
for (uint8_t i = 0; i < len; i++) {
sum = ((sum & 0xF) >> 1) | ((sum & 0x1) << 3); // rotate accumulator
@ -241,8 +220,7 @@ static uint16_t calcBSDchecksum4(uint8_t *bytes, uint8_t len, uint32_t mask)
}
// measuring LFSR maximum length
int CmdAnalyseLfsr(const char *Cmd)
{
int CmdAnalyseLfsr(const char *Cmd) {
uint16_t start_state = 0; /* Any nonzero start state will work. */
uint16_t lfsr = start_state;
@ -264,8 +242,7 @@ int CmdAnalyseLfsr(const char *Cmd)
}
return 0;
}
int CmdAnalyseLCR(const char *Cmd)
{
int CmdAnalyseLCR(const char *Cmd) {
uint8_t data[50];
char cmdp = tolower(param_getchar(Cmd, 0));
if (strlen(Cmd) == 0 || cmdp == 'h') return usage_analyse_lcr();
@ -286,8 +263,7 @@ int CmdAnalyseLCR(const char *Cmd)
PrintAndLogEx(NORMAL, "Target [%02X] requires final LRC XOR byte value: 0x%02X", data[len - 1], finalXor);
return 0;
}
int CmdAnalyseCRC(const char *Cmd)
{
int CmdAnalyseCRC(const char *Cmd) {
char cmdp = tolower(param_getchar(Cmd, 0));
if (strlen(Cmd) == 0 || cmdp == 'h') return usage_analyse_crc();
@ -383,8 +359,7 @@ int CmdAnalyseCRC(const char *Cmd)
free(data);
return 0;
}
int CmdAnalyseCHKSUM(const char *Cmd)
{
int CmdAnalyseCHKSUM(const char *Cmd) {
uint8_t data[50];
uint8_t cmdp = 0;
@ -450,14 +425,12 @@ int CmdAnalyseCHKSUM(const char *Cmd)
return 0;
}
int CmdAnalyseDates(const char *Cmd)
{
int CmdAnalyseDates(const char *Cmd) {
// look for datestamps in a given array of bytes
PrintAndLogEx(NORMAL, "To be implemented. Feel free to contribute!");
return 0;
}
int CmdAnalyseTEASelfTest(const char *Cmd)
{
int CmdAnalyseTEASelfTest(const char *Cmd) {
uint8_t v[8], v_le[8];
memset(v, 0x00, sizeof(v));
@ -492,8 +465,7 @@ int CmdAnalyseTEASelfTest(const char *Cmd)
return 0;
}
char *pb(uint32_t b)
{
char *pb(uint32_t b) {
static char buf1[33] = {0};
static char buf2[33] = {0};
static char *s;
@ -513,8 +485,7 @@ char *pb(uint32_t b)
return s;
}
int CmdAnalyseA(const char *Cmd)
{
int CmdAnalyseA(const char *Cmd) {
int hexlen = 0;
uint8_t cmdp = 0;
@ -880,8 +851,7 @@ int CmdAnalyseA(const char *Cmd)
return 0;
}
void generate4bNUID(uint8_t *uid, uint8_t *nuid)
{
void generate4bNUID(uint8_t *uid, uint8_t *nuid) {
uint16_t crc;
uint8_t b1, b2;
@ -895,8 +865,7 @@ void generate4bNUID(uint8_t *uid, uint8_t *nuid)
nuid[3] = crc & 0xFF;
}
int CmdAnalyseNuid(const char *Cmd)
{
int CmdAnalyseNuid(const char *Cmd) {
uint8_t nuid[4] = {0};
uint8_t uid[7] = {0};
int len = 0;
@ -942,15 +911,13 @@ static command_t CommandTable[] = {
{NULL, NULL, 0, NULL}
};
int CmdAnalyse(const char *Cmd)
{
int CmdAnalyse(const char *Cmd) {
clearCommandBuffer();
CmdsParse(CommandTable, Cmd);
return 0;
}
int CmdHelp(const char *Cmd)
{
int CmdHelp(const char *Cmd) {
CmdsHelp(CommandTable);
return 0;
}

View file

@ -11,8 +11,7 @@
#define MAX_ARGS 20
int split(char *str, char *arr[MAX_ARGS])
{
int split(char *str, char *arr[MAX_ARGS]) {
int beginIndex = 0;
int endIndex;
int maxWords = MAX_ARGS;
@ -40,8 +39,7 @@ int split(char *str, char *arr[MAX_ARGS])
return wordCnt;
}
int CmdCrc(const char *Cmd)
{
int CmdCrc(const char *Cmd) {
char name[] = {"reveng "};
char Cmd2[100 + 7];
memcpy(Cmd2, name, 7);
@ -62,8 +60,7 @@ int CmdCrc(const char *Cmd)
//returns array of model names and the count of models returning
// as well as a width array for the width of each model
int GetModels(char *Models[], int *count, uint8_t *width)
{
int GetModels(char *Models[], int *count, uint8_t *width) {
/* default values */
static model_t model = MZERO;
@ -248,8 +245,7 @@ int GetModels(char *Models[], int *count, uint8_t *width)
//endian = {0 = calc default endian input and output, b = big endian input and output, B = big endian output, r = right justified
// l = little endian input and output, L = little endian output only, t = left justified}
//result = calculated crc hex string
int RunModel(char *inModel, char *inHexStr, bool reverse, char endian, char *result)
{
int RunModel(char *inModel, char *inHexStr, bool reverse, char endian, char *result) {
/* default values */
static model_t model = MZERO;
@ -368,8 +364,7 @@ int RunModel(char *inModel, char *inHexStr, bool reverse, char endian, char *res
}
//test call to RunModel
int CmdrevengTestC(const char *Cmd)
{
int CmdrevengTestC(const char *Cmd) {
int cmdp = 0;
char inModel[30] = {0x00};
char inHexStr[30] = {0x00};
@ -392,8 +387,7 @@ int CmdrevengTestC(const char *Cmd)
}
//returns a calloced string (needs to be freed)
char *SwapEndianStr(const char *inStr, const size_t len, const uint8_t blockSize)
{
char *SwapEndianStr(const char *inStr, const size_t len, const uint8_t blockSize) {
char *tmp = calloc(len + 1, sizeof(char));
for (uint8_t block = 0; block < (uint8_t)(len / blockSize); block++) {
for (size_t i = 0; i < blockSize; i += 2) {
@ -405,8 +399,7 @@ char *SwapEndianStr(const char *inStr, const size_t len, const uint8_t blockSize
}
// takes hex string in and searches for a matching result (hex string must include checksum)
int CmdrevengSearch(const char *Cmd)
{
int CmdrevengSearch(const char *Cmd) {
#define NMODELS 105

View file

@ -17,8 +17,7 @@ int g_DemodClock = 0;
static int CmdHelp(const char *Cmd);
int usage_data_printdemodbuf(void)
{
int usage_data_printdemodbuf(void) {
PrintAndLogEx(NORMAL, "Usage: data printdemodbuffer x o <offset> l <length>");
PrintAndLogEx(NORMAL, "Options:");
PrintAndLogEx(NORMAL, " h This help");
@ -27,8 +26,7 @@ int usage_data_printdemodbuf(void)
PrintAndLogEx(NORMAL, " l <length> enter length to print in # of bits or hex characters respectively");
return 0;
}
int usage_data_manrawdecode(void)
{
int usage_data_manrawdecode(void) {
PrintAndLogEx(NORMAL, "Usage: data manrawdecode [invert] [maxErr]");
PrintAndLogEx(NORMAL, " Takes 10 and 01 and converts to 0 and 1 respectively");
PrintAndLogEx(NORMAL, " --must have binary sequence in demodbuffer (run data askrawdemod first)");
@ -38,8 +36,7 @@ int usage_data_manrawdecode(void)
PrintAndLogEx(NORMAL, " Example: data manrawdecode = decode manchester bitstream from the demodbuffer");
return 0;
}
int usage_data_biphaserawdecode(void)
{
int usage_data_biphaserawdecode(void) {
PrintAndLogEx(NORMAL, "Usage: data biphaserawdecode [offset] [invert] [maxErr]");
PrintAndLogEx(NORMAL, " Converts 10 or 01 to 1 and 11 or 00 to 0");
PrintAndLogEx(NORMAL, " --must have binary sequence in demodbuffer (run data askrawdemod first)");
@ -53,8 +50,7 @@ int usage_data_biphaserawdecode(void)
PrintAndLogEx(NORMAL, " Example: data biphaserawdecode 1 1 = decode biphase bitstream from the demodbuffer, set offset, and invert output");
return 0;
}
int usage_data_rawdemod(void)
{
int usage_data_rawdemod(void) {
PrintAndLogEx(NORMAL, "Usage: data rawdemod [modulation] <help>|<options>");
PrintAndLogEx(NORMAL, " [modulation] as 2 char, 'ab' for ask/biphase, 'am' for ask/manchester, 'ar' for ask/raw, 'fs' for fsk, ...");
PrintAndLogEx(NORMAL, " 'nr' for nrz/direct, 'p1' for psk1, 'p2' for psk2");
@ -71,8 +67,7 @@ int usage_data_rawdemod(void)
PrintAndLogEx(NORMAL, " : data rawdemod p2 = demod GraphBuffer using: psk2 - autodetect");
return 0;
}
int usage_data_rawdemod_am(void)
{
int usage_data_rawdemod_am(void) {
PrintAndLogEx(NORMAL, "Usage: data rawdemod am <s> [clock] <invert> [maxError] [maxLen] [amplify]");
PrintAndLogEx(NORMAL, " ['s'] optional, check for Sequence Terminator");
PrintAndLogEx(NORMAL, " [set clock as integer] optional, if not set, autodetect");
@ -88,8 +83,7 @@ int usage_data_rawdemod_am(void)
PrintAndLogEx(NORMAL, " : data rawdemod am 64 1 0 = demod an ask/manchester tag from GraphBuffer using a clock of RF/64, inverting data and allowing 0 demod errors");
return 0;
}
int usage_data_rawdemod_ab(void)
{
int usage_data_rawdemod_ab(void) {
PrintAndLogEx(NORMAL, "Usage: data rawdemod ab [offset] [clock] <invert> [maxError] [maxLen] <amplify>");
PrintAndLogEx(NORMAL, " [offset], offset to begin biphase, default=0");
PrintAndLogEx(NORMAL, " [set clock as integer] optional, if not set, autodetect");
@ -112,8 +106,7 @@ int usage_data_rawdemod_ab(void)
PrintAndLogEx(NORMAL, " : data rawdemod ab 0 64 1 0 0 a = demod an ask/biph tag from GraphBuffer using a clock of RF/64, inverting data and allowing 0 demod errors, and amp");
return 0;
}
int usage_data_rawdemod_ar(void)
{
int usage_data_rawdemod_ar(void) {
PrintAndLogEx(NORMAL, "Usage: data rawdemod ar [clock] <invert> [maxError] [maxLen] [amplify]");
PrintAndLogEx(NORMAL, " [set clock as integer] optional, if not set, autodetect");
PrintAndLogEx(NORMAL, " <invert>, 1 to invert output");
@ -130,8 +123,7 @@ int usage_data_rawdemod_ar(void)
PrintAndLogEx(NORMAL, " : data rawdemod ar 64 1 0 0 a = demod an ask tag from GraphBuffer using a clock of RF/64, inverting data and allowing 0 demod errors, and amp");
return 0;
}
int usage_data_rawdemod_fs(void)
{
int usage_data_rawdemod_fs(void) {
PrintAndLogEx(NORMAL, "Usage: data rawdemod fs [clock] <invert> [fchigh] [fclow]");
PrintAndLogEx(NORMAL, " [set clock as integer] optional, omit for autodetect.");
PrintAndLogEx(NORMAL, " <invert>, 1 for invert output, can be used even if the clock is omitted");
@ -147,8 +139,7 @@ int usage_data_rawdemod_fs(void)
PrintAndLogEx(NORMAL, " : data rawdemod fs 50 1 10 8 = demod an fsk2a RF/50 tag from GraphBuffer");
return 0;
}
int usage_data_rawdemod_nr(void)
{
int usage_data_rawdemod_nr(void) {
PrintAndLogEx(NORMAL, "Usage: data rawdemod nr [clock] <0|1> [maxError]");
PrintAndLogEx(NORMAL, " [set clock as integer] optional, if not set, autodetect.");
PrintAndLogEx(NORMAL, " <invert>, 1 for invert output");
@ -161,8 +152,7 @@ int usage_data_rawdemod_nr(void)
PrintAndLogEx(NORMAL, " : data rawdemod nr 64 1 0 = demod a nrz/direct tag from GraphBuffer using a clock of RF/64, inverting data and allowing 0 demod errors");
return 0;
}
int usage_data_rawdemod_p1(void)
{
int usage_data_rawdemod_p1(void) {
PrintAndLogEx(NORMAL, "Usage: data rawdemod p1 [clock] <0|1> [maxError]");
PrintAndLogEx(NORMAL, " [set clock as integer] optional, if not set, autodetect.");
PrintAndLogEx(NORMAL, " <invert>, 1 for invert output");
@ -175,8 +165,7 @@ int usage_data_rawdemod_p1(void)
PrintAndLogEx(NORMAL, " : data rawdemod p1 64 1 0 = demod a psk1 tag from GraphBuffer using a clock of RF/64, inverting data and allowing 0 demod errors");
return 0;
}
int usage_data_rawdemod_p2(void)
{
int usage_data_rawdemod_p2(void) {
PrintAndLogEx(NORMAL, "Usage: data rawdemod p2 [clock] <0|1> [maxError]");
PrintAndLogEx(NORMAL, " [set clock as integer] optional, if not set, autodetect.");
PrintAndLogEx(NORMAL, " <invert>, 1 for invert output");
@ -189,8 +178,7 @@ int usage_data_rawdemod_p2(void)
PrintAndLogEx(NORMAL, " : data rawdemod p2 64 1 0 = demod a psk2 tag from GraphBuffer using a clock of RF/64, inverting output and allowing 0 demod errors");
return 0;
}
int usage_data_autocorr(void)
{
int usage_data_autocorr(void) {
PrintAndLogEx(NORMAL, "Autocorrelate is used to detect repeating sequences. We use it as detection of length in bits a message inside the signal is");
PrintAndLogEx(NORMAL, "Usage: data autocorr w <window> [g]");
PrintAndLogEx(NORMAL, "Options:");
@ -199,8 +187,7 @@ int usage_data_autocorr(void)
PrintAndLogEx(NORMAL, " g save back to GraphBuffer (overwrite)");
return 0;
}
int usage_data_undecimate(void)
{
int usage_data_undecimate(void) {
PrintAndLogEx(NORMAL, "Usage: data undec [factor]");
PrintAndLogEx(NORMAL, "This function performs un-decimation, by repeating each sample N times");
PrintAndLogEx(NORMAL, "Options:");
@ -209,8 +196,7 @@ int usage_data_undecimate(void)
PrintAndLogEx(NORMAL, "Example: 'data undec 3'");
return 0;
}
int usage_data_detectclock(void)
{
int usage_data_detectclock(void) {
PrintAndLogEx(NORMAL, "Usage: data detectclock [modulation] <clock>");
PrintAndLogEx(NORMAL, " [modulation as char], specify the modulation type you want to detect the clock of");
PrintAndLogEx(NORMAL, " <clock> , specify the clock (optional - to get best start position only)");
@ -222,28 +208,24 @@ int usage_data_detectclock(void)
PrintAndLogEx(NORMAL, " data detectclock n = detect the clock of an nrz/direct modulated wave in the GraphBuffer");
return 0;
}
int usage_data_hex2bin(void)
{
int usage_data_hex2bin(void) {
PrintAndLogEx(NORMAL, "Usage: data hex2bin <hex_digits>");
PrintAndLogEx(NORMAL, " This function will ignore all non-hexadecimal characters (but stop reading on whitespace)");
return 0;
}
int usage_data_bin2hex(void)
{
int usage_data_bin2hex(void) {
PrintAndLogEx(NORMAL, "Usage: data bin2hex <binary_digits>");
PrintAndLogEx(NORMAL, " This function will ignore all characters not 1 or 0 (but stop reading on whitespace)");
return 0;
}
int usage_data_buffclear(void)
{
int usage_data_buffclear(void) {
PrintAndLogEx(NORMAL, "This function clears the bigbuff on deviceside");
PrintAndLogEx(NORMAL, "Usage: data buffclear [h]");
PrintAndLogEx(NORMAL, "Options:");
PrintAndLogEx(NORMAL, " h This help");
return 0;
}
int usage_data_fsktonrz()
{
int usage_data_fsktonrz() {
PrintAndLogEx(NORMAL, "Usage: data fsktonrz c <clock> l <fc_low> f <fc_high>");
PrintAndLogEx(NORMAL, "Options:");
PrintAndLogEx(NORMAL, " h This help");
@ -255,8 +237,7 @@ int usage_data_fsktonrz()
//set the demod buffer with given array of binary (one bit per byte)
//by marshmellow
void setDemodBuf(uint8_t *buf, size_t size, size_t start_idx)
{
void setDemodBuf(uint8_t *buf, size_t size, size_t start_idx) {
if (buf == NULL) return;
if (size > MAX_DEMOD_BUF_LEN - start_idx)
@ -268,8 +249,7 @@ void setDemodBuf(uint8_t *buf, size_t size, size_t start_idx)
DemodBufferLen = size;
}
bool getDemodBuf(uint8_t *buf, size_t *size)
{
bool getDemodBuf(uint8_t *buf, size_t *size) {
if (buf == NULL) return false;
if (size == NULL) return false;
if (*size == 0) return false;
@ -282,41 +262,35 @@ bool getDemodBuf(uint8_t *buf, size_t *size)
// include <math.h>
// Root mean square
double rms(double *v, size_t n)
{
double rms(double *v, size_t n) {
double sum = 0.0;
for (size_t i = 0; i < n; i++)
sum += v[i] * v[i];
return sqrt(sum / n);
}
int cmp_int(const void *a, const void *b)
{
int cmp_int(const void *a, const void *b) {
if (*(const int *)a < * (const int *)b)
return -1;
else
return *(const int *)a > *(const int *)b;
}
int cmp_uint8(const void *a, const void *b)
{
int cmp_uint8(const void *a, const void *b) {
if (*(const uint8_t *)a < * (const uint8_t *)b)
return -1;
else
return *(const uint8_t *)a > *(const uint8_t *)b;
}
// Median of a array of values
double median_int(int *src, size_t size)
{
double median_int(int *src, size_t size) {
qsort(src, size, sizeof(int), cmp_int);
return 0.5 * (src[size / 2] + src[(size - 1) / 2]);
}
double median_uint8(uint8_t *src, size_t size)
{
double median_uint8(uint8_t *src, size_t size) {
qsort(src, size, sizeof(uint8_t), cmp_uint8);
return 0.5 * (src[size / 2] + src[(size - 1) / 2]);
}
// function to compute mean for a series
static double compute_mean(const int *data, size_t n)
{
static double compute_mean(const int *data, size_t n) {
double mean = 0.0;
for (size_t i = 0; i < n; i++)
mean += data[i];
@ -325,8 +299,7 @@ static double compute_mean(const int *data, size_t n)
}
// function to compute variance for a series
static double compute_variance(const int *data, size_t n)
{
static double compute_variance(const int *data, size_t n) {
double variance = 0.0;
double mean = compute_mean(data, n);
@ -362,8 +335,7 @@ static double compute_autoc(const int *data, size_t n, int lag) {
*/
// option '1' to save DemodBuffer any other to restore
void save_restoreDB(uint8_t saveOpt)
{
void save_restoreDB(uint8_t saveOpt) {
static uint8_t SavedDB[MAX_DEMOD_BUF_LEN];
static size_t SavedDBlen;
static bool DB_Saved = false;
@ -386,8 +358,7 @@ void save_restoreDB(uint8_t saveOpt)
}
}
int CmdSetDebugMode(const char *Cmd)
{
int CmdSetDebugMode(const char *Cmd) {
int demod = 0;
sscanf(Cmd, "%i", &demod);
g_debugMode = (uint8_t)demod;
@ -396,8 +367,7 @@ int CmdSetDebugMode(const char *Cmd)
//by marshmellow
// max output to 512 bits if we have more - should be plenty
void printDemodBuff(void)
{
void printDemodBuff(void) {
int len = DemodBufferLen;
if (len < 1) {
PrintAndLogEx(NORMAL, "(printDemodBuff) no bits found in demod buffer");
@ -408,8 +378,7 @@ void printDemodBuff(void)
PrintAndLogEx(NORMAL, "%s", sprint_bin_break(DemodBuffer, len, 16));
}
int CmdPrintDemodBuff(const char *Cmd)
{
int CmdPrintDemodBuff(const char *Cmd) {
char hex[512] = {0x00};
bool hexMode = false;
bool errors = false;
@ -466,8 +435,7 @@ int CmdPrintDemodBuff(const char *Cmd)
//by marshmellow
//this function strictly converts >1 to 1 and <1 to 0 for each sample in the graphbuffer
int CmdGetBitStream(const char *Cmd)
{
int CmdGetBitStream(const char *Cmd) {
CmdHpf(Cmd);
for (uint32_t i = 0; i < GraphTraceLen; i++)
GraphBuffer[i] = (GraphBuffer[i] >= 1) ? 1 : 0;
@ -482,8 +450,7 @@ int CmdGetBitStream(const char *Cmd)
//verbose will print results and demoding messages
//emSearch will auto search for EM410x format in bitstream
//askType switches decode: ask/raw = 0, ask/manchester = 1
int ASKDemod_ext(const char *Cmd, bool verbose, bool emSearch, uint8_t askType, bool *stCheck)
{
int ASKDemod_ext(const char *Cmd, bool verbose, bool emSearch, uint8_t askType, bool *stCheck) {
int invert = 0;
int clk = 0;
int maxErr = 100;
@ -569,8 +536,7 @@ int ASKDemod_ext(const char *Cmd, bool verbose, bool emSearch, uint8_t askType,
return 1;
}
int ASKDemod(const char *Cmd, bool verbose, bool emSearch, uint8_t askType)
{
int ASKDemod(const char *Cmd, bool verbose, bool emSearch, uint8_t askType) {
bool st = false;
return ASKDemod_ext(Cmd, verbose, emSearch, askType, &st);
}
@ -579,8 +545,7 @@ int ASKDemod(const char *Cmd, bool verbose, bool emSearch, uint8_t askType)
//takes 5 arguments - clock, invert, maxErr, maxLen as integers and amplify as char == 'a'
//attempts to demodulate ask while decoding manchester
//prints binary found and saves in graphbuffer for further commands
int Cmdaskmandemod(const char *Cmd)
{
int Cmdaskmandemod(const char *Cmd) {
char cmdp = tolower(param_getchar(Cmd, 0));
if (strlen(Cmd) > 45 || cmdp == 'h') return usage_data_rawdemod_am();
@ -596,8 +561,7 @@ int Cmdaskmandemod(const char *Cmd)
//by marshmellow
//manchester decode
//stricktly take 10 and 01 and convert to 0 and 1
int Cmdmandecoderaw(const char *Cmd)
{
int Cmdmandecoderaw(const char *Cmd) {
size_t size = 0;
int high = 0, low = 0;
int i = 0, errCnt = 0, invert = 0, maxErr = 20;
@ -652,8 +616,7 @@ int Cmdmandecoderaw(const char *Cmd)
//takes 2 arguments "offset" default = 0 if 1 it will shift the decode by one bit
// and "invert" default = 0 if 1 it will invert output
// the argument offset allows us to manually shift if the output is incorrect - [EDIT: now auto detects]
int CmdBiphaseDecodeRaw(const char *Cmd)
{
int CmdBiphaseDecodeRaw(const char *Cmd) {
size_t size = 0;
int offset = 0, invert = 0, maxErr = 20, errCnt = 0;
char cmdp = tolower(param_getchar(Cmd, 0));
@ -695,8 +658,7 @@ int CmdBiphaseDecodeRaw(const char *Cmd)
//by marshmellow
// - ASK Demod then Biphase decode GraphBuffer samples
int ASKbiphaseDemod(const char *Cmd, bool verbose)
{
int ASKbiphaseDemod(const char *Cmd, bool verbose) {
//ask raw demod GraphBuffer first
int offset = 0, clk = 0, invert = 0, maxErr = 0;
sscanf(Cmd, "%i %i %i %i", &offset, &clk, &invert, &maxErr);
@ -735,8 +697,7 @@ int ASKbiphaseDemod(const char *Cmd, bool verbose)
return 1;
}
//by marshmellow - see ASKbiphaseDemod
int Cmdaskbiphdemod(const char *Cmd)
{
int Cmdaskbiphdemod(const char *Cmd) {
char cmdp = tolower(param_getchar(Cmd, 0));
if (strlen(Cmd) > 25 || cmdp == 'h') return usage_data_rawdemod_ab();
@ -744,16 +705,14 @@ int Cmdaskbiphdemod(const char *Cmd)
}
//by marshmellow - see ASKDemod
int Cmdaskrawdemod(const char *Cmd)
{
int Cmdaskrawdemod(const char *Cmd) {
char cmdp = tolower(param_getchar(Cmd, 0));
if (strlen(Cmd) > 25 || cmdp == 'h') return usage_data_rawdemod_ar();
return ASKDemod(Cmd, true, false, 0);
}
int AutoCorrelate(const int *in, int *out, size_t len, int window, bool SaveGrph, bool verbose)
{
int AutoCorrelate(const int *in, int *out, size_t len, int window, bool SaveGrph, bool verbose) {
// sanity check
if (window > len) window = len;
@ -839,8 +798,7 @@ int AutoCorrelate(const int *in, int *out, size_t len, int window, bool SaveGrph
return retval;
}
int CmdAutoCorr(const char *Cmd)
{
int CmdAutoCorr(const char *Cmd) {
uint32_t window = 4000;
uint8_t cmdp = 0;
@ -875,8 +833,7 @@ int CmdAutoCorr(const char *Cmd)
return AutoCorrelate(GraphBuffer, GraphBuffer, GraphTraceLen, window, updateGrph, true);
}
int CmdBitsamples(const char *Cmd)
{
int CmdBitsamples(const char *Cmd) {
int cnt = 0;
uint8_t got[12288];
@ -898,8 +855,7 @@ int CmdBitsamples(const char *Cmd)
return 0;
}
int CmdBuffClear(const char *Cmd)
{
int CmdBuffClear(const char *Cmd) {
char cmdp = tolower(param_getchar(Cmd, 0));
if (cmdp == 'h') return usage_data_buffclear();
@ -910,8 +866,7 @@ int CmdBuffClear(const char *Cmd)
return 0;
}
int CmdDec(const char *Cmd)
{
int CmdDec(const char *Cmd) {
for (int i = 0; i < (GraphTraceLen / 2); ++i)
GraphBuffer[i] = GraphBuffer[i * 2];
GraphTraceLen /= 2;
@ -926,8 +881,7 @@ int CmdDec(const char *Cmd)
* @param Cmd
* @return
*/
int CmdUndec(const char *Cmd)
{
int CmdUndec(const char *Cmd) {
char cmdp = tolower(param_getchar(Cmd, 0));
if (cmdp == 'h') return usage_data_undecimate();
@ -952,8 +906,7 @@ int CmdUndec(const char *Cmd)
//by marshmellow
//shift graph zero up or down based on input + or -
int CmdGraphShiftZero(const char *Cmd)
{
int CmdGraphShiftZero(const char *Cmd) {
int shift = 0, shiftedVal = 0;
//set options from parameters entered with the command
sscanf(Cmd, "%i", &shift);
@ -974,8 +927,7 @@ int CmdGraphShiftZero(const char *Cmd)
return 0;
}
int AskEdgeDetect(const int *in, int *out, int len, int threshold)
{
int AskEdgeDetect(const int *in, int *out, int len, int threshold) {
int last = 0;
for (int i = 1; i < len; i++) {
if (in[i] - in[i - 1] >= threshold) //large jump up
@ -991,8 +943,7 @@ int AskEdgeDetect(const int *in, int *out, int len, int threshold)
//use large jumps in read samples to identify edges of waves and then amplify that wave to max
//similar to dirtheshold, threshold commands
//takes a threshold length which is the measured length between two samples then determines an edge
int CmdAskEdgeDetect(const char *Cmd)
{
int CmdAskEdgeDetect(const char *Cmd) {
int thresLen = 25;
int ans = 0;
sscanf(Cmd, "%i", &thresLen);
@ -1005,8 +956,7 @@ int CmdAskEdgeDetect(const char *Cmd)
/* Print our clock rate */
// uses data from graphbuffer
// adjusted to take char parameter for type of modulation to find the clock - by marshmellow.
int CmdDetectClockRate(const char *Cmd)
{
int CmdDetectClockRate(const char *Cmd) {
char cmdp = tolower(param_getchar(Cmd, 0));
if (strlen(Cmd) > 6 || strlen(Cmd) == 0 || cmdp == 'h')
return usage_data_detectclock();
@ -1033,8 +983,7 @@ int CmdDetectClockRate(const char *Cmd)
return clock;
}
char *GetFSKType(uint8_t fchigh, uint8_t fclow, uint8_t invert)
{
char *GetFSKType(uint8_t fchigh, uint8_t fclow, uint8_t invert) {
static char fType[8];
memset(fType, 0x00, 8);
char *fskType = fType;
@ -1063,8 +1012,7 @@ char *GetFSKType(uint8_t fchigh, uint8_t fclow, uint8_t invert)
//fsk raw demod and print binary
//takes 4 arguments - Clock, invert, fchigh, fclow
//defaults: clock = 50, invert=1, fchigh=10, fclow=8 (RF/10 RF/8 (fsk2a))
int FSKrawDemod(const char *Cmd, bool verbose)
{
int FSKrawDemod(const char *Cmd, bool verbose) {
//raw fsk demod no manchester decoding no start bit finding just get binary from wave
uint8_t rfLen, invert, fchigh, fclow;
@ -1130,8 +1078,7 @@ int FSKrawDemod(const char *Cmd, bool verbose)
//fsk raw demod and print binary
//takes 4 arguments - Clock, invert, fchigh, fclow
//defaults: clock = 50, invert=1, fchigh=10, fclow=8 (RF/10 RF/8 (fsk2a))
int CmdFSKrawdemod(const char *Cmd)
{
int CmdFSKrawdemod(const char *Cmd) {
char cmdp = tolower(param_getchar(Cmd, 0));
if (strlen(Cmd) > 20 || cmdp == 'h') return usage_data_rawdemod_fs();
@ -1140,8 +1087,7 @@ int CmdFSKrawdemod(const char *Cmd)
//by marshmellow
//attempt to psk1 demod graph buffer
int PSKDemod(const char *Cmd, bool verbose)
{
int PSKDemod(const char *Cmd, bool verbose) {
int invert = 0, clk = 0, maxErr = 100;
sscanf(Cmd, "%i %i %i", &clk, &invert, &maxErr);
if (clk == 1) {
@ -1182,8 +1128,7 @@ int PSKDemod(const char *Cmd, bool verbose)
return 1;
}
int CmdPSKIdteck(const char *Cmd)
{
int CmdPSKIdteck(const char *Cmd) {
if (!PSKDemod("", false)) {
PrintAndLogEx(DEBUG, "DEBUG: Error - Idteck PSKDemod failed");
@ -1247,8 +1192,7 @@ int CmdPSKIdteck(const char *Cmd)
// takes 3 arguments - clock, invert, maxErr as integers
// attempts to demodulate nrz only
// prints binary found and saves in demodbuffer for further commands
int NRZrawDemod(const char *Cmd, bool verbose)
{
int NRZrawDemod(const char *Cmd, bool verbose) {
int errCnt = 0, clkStartIdx = 0;
int invert = 0, clk = 0, maxErr = 100;
@ -1295,8 +1239,7 @@ int NRZrawDemod(const char *Cmd, bool verbose)
return 1;
}
int CmdNRZrawDemod(const char *Cmd)
{
int CmdNRZrawDemod(const char *Cmd) {
char cmdp = tolower(param_getchar(Cmd, 0));
if (strlen(Cmd) > 16 || cmdp == 'h') return usage_data_rawdemod_nr();
@ -1307,8 +1250,7 @@ int CmdNRZrawDemod(const char *Cmd)
// takes 3 arguments - clock, invert, maxErr as integers
// attempts to demodulate psk only
// prints binary found and saves in demodbuffer for further commands
int CmdPSK1rawDemod(const char *Cmd)
{
int CmdPSK1rawDemod(const char *Cmd) {
char cmdp = tolower(param_getchar(Cmd, 0));
if (strlen(Cmd) > 16 || cmdp == 'h') return usage_data_rawdemod_p1();
@ -1326,8 +1268,7 @@ int CmdPSK1rawDemod(const char *Cmd)
// by marshmellow
// takes same args as cmdpsk1rawdemod
int CmdPSK2rawDemod(const char *Cmd)
{
int CmdPSK2rawDemod(const char *Cmd) {
char cmdp = tolower(param_getchar(Cmd, 0));
if (strlen(Cmd) > 16 || cmdp == 'h') return usage_data_rawdemod_p2();
@ -1344,8 +1285,7 @@ int CmdPSK2rawDemod(const char *Cmd)
}
// by marshmellow - combines all raw demod functions into one menu command
int CmdRawDemod(const char *Cmd)
{
int CmdRawDemod(const char *Cmd) {
int ans = 0;
if (strlen(Cmd) > 35 || strlen(Cmd) < 2)
@ -1365,8 +1305,7 @@ int CmdRawDemod(const char *Cmd)
return ans;
}
void setClockGrid(int clk, int offset)
{
void setClockGrid(int clk, int offset) {
g_DemodStartIdx = offset;
g_DemodClock = clk;
PrintAndLogEx(DEBUG, "DEBUG: (setClockGrid) demodoffset %d, clk %d", offset, clk);
@ -1390,8 +1329,7 @@ void setClockGrid(int clk, int offset)
}
}
int CmdGrid(const char *Cmd)
{
int CmdGrid(const char *Cmd) {
sscanf(Cmd, "%i %i", &PlotGridX, &PlotGridY);
PlotGridXdefault = PlotGridX;
PlotGridYdefault = PlotGridY;
@ -1399,15 +1337,13 @@ int CmdGrid(const char *Cmd)
return 0;
}
int CmdSetGraphMarkers(const char *Cmd)
{
int CmdSetGraphMarkers(const char *Cmd) {
sscanf(Cmd, "%i %i", &CursorCPos, &CursorDPos);
RepaintGraphWindow();
return 0;
}
int CmdHexsamples(const char *Cmd)
{
int CmdHexsamples(const char *Cmd) {
int i, j, requested = 0, offset = 0;
char string_buf[25];
char *string_ptr = string_buf;
@ -1449,15 +1385,13 @@ int CmdHexsamples(const char *Cmd)
return 0;
}
int CmdHide(const char *Cmd)
{
int CmdHide(const char *Cmd) {
HideGraphWindow();
return 0;
}
//zero mean GraphBuffer
int CmdHpf(const char *Cmd)
{
int CmdHpf(const char *Cmd) {
uint8_t bits[GraphTraceLen];
size_t size = getFromGraphBuf(bits);
removeSignalOffset(bits, size);
@ -1470,15 +1404,13 @@ int CmdHpf(const char *Cmd)
return 0;
}
bool _headBit(BitstreamOut *stream)
{
bool _headBit(BitstreamOut *stream) {
int bytepos = stream->position >> 3; // divide by 8
int bitpos = (stream->position++) & 7; // mask out 00000111
return (*(stream->buffer + bytepos) >> (7 - bitpos)) & 1;
}
uint8_t getByte(uint8_t bits_per_sample, BitstreamOut *b)
{
uint8_t getByte(uint8_t bits_per_sample, BitstreamOut *b) {
uint8_t val = 0;
for (int i = 0 ; i < bits_per_sample; i++)
val |= (_headBit(b) << (7 - i));
@ -1486,8 +1418,7 @@ uint8_t getByte(uint8_t bits_per_sample, BitstreamOut *b)
return val;
}
int getSamples(int n, bool silent)
{
int getSamples(int n, bool silent) {
//If we get all but the last byte in bigbuf,
// we don't have to worry about remaining trash
// in the last byte in case the bits-per-sample
@ -1548,14 +1479,12 @@ int getSamples(int n, bool silent)
return 0;
}
int CmdSamples(const char *Cmd)
{
int CmdSamples(const char *Cmd) {
int n = strtol(Cmd, NULL, 0);
return getSamples(n, false);
}
int CmdTuneSamples(const char *Cmd)
{
int CmdTuneSamples(const char *Cmd) {
#define NON_VOLTAGE 1000
#define LF_UNUSABLE_V 2000
#define LF_MARGINAL_V 10000
@ -1654,8 +1583,7 @@ int CmdTuneSamples(const char *Cmd)
return 0;
}
int CmdLoad(const char *Cmd)
{
int CmdLoad(const char *Cmd) {
char filename[FILE_PATH_SIZE] = {0x00};
int len = 0;
@ -1698,8 +1626,7 @@ int CmdLoad(const char *Cmd)
}
// trim graph from the end
int CmdLtrim(const char *Cmd)
{
int CmdLtrim(const char *Cmd) {
// sanitycheck
if (GraphTraceLen <= 0) return 1;
@ -1713,8 +1640,7 @@ int CmdLtrim(const char *Cmd)
}
// trim graph from the beginning
int CmdRtrim(const char *Cmd)
{
int CmdRtrim(const char *Cmd) {
int ds = atoi(Cmd);
@ -1727,8 +1653,7 @@ int CmdRtrim(const char *Cmd)
}
// trim graph (middle) piece
int CmdMtrim(const char *Cmd)
{
int CmdMtrim(const char *Cmd) {
int start = 0, stop = 0;
sscanf(Cmd, "%i %i", &start, &stop);
@ -1744,8 +1669,7 @@ int CmdMtrim(const char *Cmd)
return 0;
}
int CmdNorm(const char *Cmd)
{
int CmdNorm(const char *Cmd) {
int i;
int max = INT_MIN, min = INT_MAX;
@ -1771,14 +1695,12 @@ int CmdNorm(const char *Cmd)
return 0;
}
int CmdPlot(const char *Cmd)
{
int CmdPlot(const char *Cmd) {
ShowGraphWindow();
return 0;
}
int CmdSave(const char *Cmd)
{
int CmdSave(const char *Cmd) {
int len = 0;
char filename[FILE_PATH_SIZE] = {0x00};
@ -1803,8 +1725,7 @@ int CmdSave(const char *Cmd)
return 0;
}
int CmdScale(const char *Cmd)
{
int CmdScale(const char *Cmd) {
CursorScaleFactor = atoi(Cmd);
if (CursorScaleFactor == 0) {
PrintAndLogEx(FAILED, "bad, can't have zero scale");
@ -1814,8 +1735,7 @@ int CmdScale(const char *Cmd)
return 0;
}
int directionalThreshold(const int *in, int *out, size_t len, int8_t up, int8_t down)
{
int directionalThreshold(const int *in, int *out, size_t len, int8_t up, int8_t down) {
int lastValue = in[0];
@ -1844,8 +1764,7 @@ int directionalThreshold(const int *in, int *out, size_t len, int8_t up, int8_t
return 0;
}
int CmdDirectionalThreshold(const char *Cmd)
{
int CmdDirectionalThreshold(const char *Cmd) {
int8_t up = param_get8(Cmd, 0);
int8_t down = param_get8(Cmd, 1);
@ -1863,8 +1782,7 @@ int CmdDirectionalThreshold(const char *Cmd)
return 0;
}
int CmdZerocrossings(const char *Cmd)
{
int CmdZerocrossings(const char *Cmd) {
// Zero-crossings aren't meaningful unless the signal is zero-mean.
CmdHpf("");
@ -1900,8 +1818,7 @@ int CmdZerocrossings(const char *Cmd)
* @param Cmd
* @return
*/
int Cmdbin2hex(const char *Cmd)
{
int Cmdbin2hex(const char *Cmd) {
int bg = 0, en = 0;
if (param_getptr(Cmd, &bg, &en, 0))
return usage_data_bin2hex();
@ -1931,8 +1848,7 @@ int Cmdbin2hex(const char *Cmd)
return 0;
}
int Cmdhex2bin(const char *Cmd)
{
int Cmdhex2bin(const char *Cmd) {
int bg = 0, en = 0;
if (param_getptr(Cmd, &bg, &en, 0)) return usage_data_hex2bin();
@ -1976,8 +1892,7 @@ static const int HighTone[] = {
1, 1, 1, 1, -1, -1, -1, -1, -1, // note one extra -1 to padd due to 50/8 remainder
};
*/
void GetHiLoTone(int *LowTone, int *HighTone, int clk, int LowToneFC, int HighToneFC)
{
void GetHiLoTone(int *LowTone, int *HighTone, int clk, int LowToneFC, int HighToneFC) {
int i, j = 0;
int Left_Modifier = ((clk % LowToneFC) % 2) + ((clk % LowToneFC) / 2);
int Right_Modifier = (clk % LowToneFC) / 2;
@ -2040,8 +1955,7 @@ void GetHiLoTone(int *LowTone, int *HighTone, int clk, int LowToneFC, int HighTo
//old CmdFSKdemod adapted by marshmellow
//converts FSK to clear NRZ style wave. (or demodulates)
int FSKToNRZ(int *data, int *dataLen, int clk, int LowToneFC, int HighToneFC)
{
int FSKToNRZ(int *data, int *dataLen, int clk, int LowToneFC, int HighToneFC) {
uint8_t ans = 0;
if (clk == 0 || LowToneFC == 0 || HighToneFC == 0) {
int firstClockEdge = 0;
@ -2102,8 +2016,7 @@ int FSKToNRZ(int *data, int *dataLen, int clk, int LowToneFC, int HighToneFC)
return 0;
}
int CmdFSKToNRZ(const char *Cmd)
{
int CmdFSKToNRZ(const char *Cmd) {
// take clk, fc_low, fc_high
// blank = auto;
bool errors = false;
@ -2143,8 +2056,7 @@ int CmdFSKToNRZ(const char *Cmd)
return ans;
}
int CmdDataIIR(const char *Cmd)
{
int CmdDataIIR(const char *Cmd) {
uint8_t k = param_get8(Cmd, 0);
//iceIIR_Butterworth(GraphBuffer, GraphTraceLen);
iceSimple_Filter(GraphBuffer, GraphTraceLen, k);
@ -2198,15 +2110,13 @@ static command_t CommandTable[] = {
{NULL, NULL, 0, NULL}
};
int CmdData(const char *Cmd)
{
int CmdData(const char *Cmd) {
clearCommandBuffer();
CmdsParse(CommandTable, Cmd);
return 0;
}
int CmdHelp(const char *Cmd)
{
int CmdHelp(const char *Cmd) {
CmdsHelp(CommandTable);
return 0;
}

View file

@ -26,8 +26,7 @@
static int CmdHelp(const char *Cmd);
int usage_flashmem_spibaud(void)
{
int usage_flashmem_spibaud(void) {
PrintAndLogEx(NORMAL, "Usage: mem spibaud [h] <baudrate>");
PrintAndLogEx(NORMAL, "Options:");
PrintAndLogEx(NORMAL, " h this help");
@ -41,8 +40,7 @@ int usage_flashmem_spibaud(void)
return 0;
}
int usage_flashmem_read(void)
{
int usage_flashmem_read(void) {
PrintAndLogEx(NORMAL, "Read flash memory on device");
PrintAndLogEx(NORMAL, "Usage: mem read o <offset> l <len>");
PrintAndLogEx(NORMAL, " o <offset> : offset in memory");
@ -53,8 +51,7 @@ int usage_flashmem_read(void)
PrintAndLogEx(NORMAL, " mem read o 1024 l 10"); // read 10 bytes starting at offset 1024
return 0;
}
int usage_flashmem_load(void)
{
int usage_flashmem_load(void) {
PrintAndLogEx(NORMAL, "Loads binary file into flash memory on device");
PrintAndLogEx(NORMAL, "Usage: mem load o <offset> f <file name> m t i");
PrintAndLogEx(NORMAL, " o <offset> : offset in memory");
@ -71,8 +68,7 @@ int usage_flashmem_load(void)
PrintAndLogEx(NORMAL, " mem load f default_iclass_keys i");
return 0;
}
int usage_flashmem_save(void)
{
int usage_flashmem_save(void) {
PrintAndLogEx(NORMAL, "Saves flash memory on device into the file");
PrintAndLogEx(NORMAL, " Usage: mem save o <offset> l <length> f <file name>");
PrintAndLogEx(NORMAL, " o <offset> : offset in memory");
@ -85,8 +81,7 @@ int usage_flashmem_save(void)
PrintAndLogEx(NORMAL, " mem save f myfile o 1024 l 4096"); // downlowd 4096 bytes from offset 1024 to file myfile
return 0;
}
int usage_flashmem_wipe(void)
{
int usage_flashmem_wipe(void) {
PrintAndLogEx(WARNING, "[OBS] use with caution.");
PrintAndLogEx(NORMAL, "Wipe flash memory on device, which fills memory with 0xFF\n");
@ -100,8 +95,7 @@ int usage_flashmem_wipe(void)
PrintAndLogEx(NORMAL, " mem wipe p 0"); // wipes first page.
return 0;
}
int usage_flashmem_info(void)
{
int usage_flashmem_info(void) {
PrintAndLogEx(NORMAL, "Collect signature and verify it from flash memory\n");
PrintAndLogEx(NORMAL, " Usage: mem info [h|s|w]");
PrintAndLogEx(NORMAL, " s : create a signature");
@ -113,8 +107,7 @@ int usage_flashmem_info(void)
return 0;
}
int CmdFlashMemRead(const char *Cmd)
{
int CmdFlashMemRead(const char *Cmd) {
uint8_t cmdp = 0;
bool errors = false;
@ -153,8 +146,7 @@ int CmdFlashMemRead(const char *Cmd)
return 0;
}
int CmdFlashmemSpiBaudrate(const char *Cmd)
{
int CmdFlashmemSpiBaudrate(const char *Cmd) {
char ctmp = tolower(param_getchar(Cmd, 0));
if (strlen(Cmd) < 1 || ctmp == 'h') return usage_flashmem_spibaud();
@ -166,8 +158,7 @@ int CmdFlashmemSpiBaudrate(const char *Cmd)
return 0;
}
int CmdFlashMemLoad(const char *Cmd)
{
int CmdFlashMemLoad(const char *Cmd) {
uint32_t start_index = 0;
char filename[FILE_PATH_SIZE] = {0};
@ -304,8 +295,7 @@ int CmdFlashMemLoad(const char *Cmd)
PrintAndLogEx(SUCCESS, "Wrote %u bytes to offset %u", datalen, start_index);
return 0;
}
int CmdFlashMemSave(const char *Cmd)
{
int CmdFlashMemSave(const char *Cmd) {
char filename[FILE_PATH_SIZE] = {0};
uint8_t cmdp = 0;
@ -361,8 +351,7 @@ int CmdFlashMemSave(const char *Cmd)
free(dump);
return 0;
}
int CmdFlashMemWipe(const char *Cmd)
{
int CmdFlashMemWipe(const char *Cmd) {
uint8_t cmdp = 0;
bool errors = false;
@ -411,8 +400,7 @@ int CmdFlashMemWipe(const char *Cmd)
return 0;
}
int CmdFlashMemInfo(const char *Cmd)
{
int CmdFlashMemInfo(const char *Cmd) {
uint8_t sha_hash[20] = {0};
mbedtls_rsa_context rsa;
@ -612,15 +600,13 @@ static command_t CommandTable[] = {
{NULL, NULL, 0, NULL}
};
int CmdFlashMem(const char *Cmd)
{
int CmdFlashMem(const char *Cmd) {
clearCommandBuffer();
CmdsParse(CommandTable, Cmd);
return 0;
}
int CmdHelp(const char *Cmd)
{
int CmdHelp(const char *Cmd) {
CmdsHelp(CommandTable);
return 0;
}

View file

@ -12,8 +12,7 @@
static int CmdHelp(const char *Cmd);
int usage_hf_search()
{
int usage_hf_search() {
PrintAndLogEx(NORMAL, "Usage: hf search");
PrintAndLogEx(NORMAL, "Will try to find a HF read out of the unknown tag. Stops when found.");
PrintAndLogEx(NORMAL, "Options:");
@ -21,8 +20,7 @@ int usage_hf_search()
PrintAndLogEx(NORMAL, "");
return 0;
}
int usage_hf_snoop()
{
int usage_hf_snoop() {
PrintAndLogEx(NORMAL, "Usage: hf snoop <skip pairs> <skip triggers>");
PrintAndLogEx(NORMAL, "The high frequence snoop will assign all available memory on device for snooped data");
PrintAndLogEx(NORMAL, "User the 'data samples' command to download from device, and 'data plot' to look at it");
@ -38,8 +36,7 @@ int usage_hf_snoop()
return 0;
}
int CmdHFSearch(const char *Cmd)
{
int CmdHFSearch(const char *Cmd) {
char cmdp = tolower(param_getchar(Cmd, 0));
if (cmdp == 'h') return usage_hf_search();
@ -88,8 +85,7 @@ int CmdHFSearch(const char *Cmd)
return 0;
}
int CmdHFTune(const char *Cmd)
{
int CmdHFTune(const char *Cmd) {
PrintAndLogEx(SUCCESS, "Measuring HF antenna, press button to exit");
UsbCommand c = {CMD_MEASURE_ANTENNA_TUNING_HF};
clearCommandBuffer();
@ -97,8 +93,7 @@ int CmdHFTune(const char *Cmd)
return 0;
}
int CmdHFSnoop(const char *Cmd)
{
int CmdHFSnoop(const char *Cmd) {
char cmdp = tolower(param_getchar(Cmd, 0));
if (cmdp == 'h') return usage_hf_snoop();
@ -133,15 +128,13 @@ static command_t CommandTable[] = {
{NULL, NULL, 0, NULL}
};
int CmdHF(const char *Cmd)
{
int CmdHF(const char *Cmd) {
clearCommandBuffer();
CmdsParse(CommandTable, Cmd);
return 0;
}
int CmdHelp(const char *Cmd)
{
int CmdHelp(const char *Cmd) {
CmdsHelp(CommandTable);
return 0;
}

View file

@ -136,8 +136,7 @@ static const manufactureName manufactureMapping[] = {
// get a product description based on the UID
// uid[8] tag uid
// returns description of the best match
char *getTagInfo(uint8_t uid)
{
char *getTagInfo(uint8_t uid) {
int i;
int len = sizeof(manufactureMapping) / sizeof(manufactureName);
@ -154,8 +153,7 @@ char *getTagInfo(uint8_t uid)
static uint16_t frameLength = 0;
uint16_t atsFSC[] = {16, 24, 32, 40, 48, 64, 96, 128, 256};
int usage_hf_14a_sim(void)
{
int usage_hf_14a_sim(void) {
// PrintAndLogEx(NORMAL, "\n Emulating ISO/IEC 14443 type A tag with 4,7 or 10 byte UID\n");
PrintAndLogEx(NORMAL, "\n Emulating ISO/IEC 14443 type A tag with 4,7 byte UID\n");
PrintAndLogEx(NORMAL, "Usage: hf 14a sim [h] t <type> u <uid> [x] [e] [v]");
@ -182,8 +180,7 @@ int usage_hf_14a_sim(void)
// PrintAndLogEx(NORMAL, " hf 14a sim t 1 u 11223445566778899AA\n");
return 0;
}
int usage_hf_14a_sniff(void)
{
int usage_hf_14a_sniff(void) {
PrintAndLogEx(NORMAL, "It get data from the field and saves it into command buffer.");
PrintAndLogEx(NORMAL, "Buffer accessible from command 'hf list 14a'");
PrintAndLogEx(NORMAL, "Usage: hf 14a sniff [c][r]");
@ -193,8 +190,7 @@ int usage_hf_14a_sniff(void)
PrintAndLogEx(NORMAL, " hf 14a sniff c r");
return 0;
}
int usage_hf_14a_raw(void)
{
int usage_hf_14a_raw(void) {
PrintAndLogEx(NORMAL, "Usage: hf 14a raw [-h] [-r] [-c] [-p] [-a] [-T] [-t] <milliseconds> [-b] <number of bits> <0A 0B 0C ... hex>");
PrintAndLogEx(NORMAL, " -h this help");
PrintAndLogEx(NORMAL, " -r do not read response");
@ -208,8 +204,7 @@ int usage_hf_14a_raw(void)
PrintAndLogEx(NORMAL, " -3 ISO14443-3 select only (skip RATS)");
return 0;
}
int usage_hf_14a_reader(void)
{
int usage_hf_14a_reader(void) {
PrintAndLogEx(NORMAL, "Usage: hf 14a reader [k|s|x] [3]");
PrintAndLogEx(NORMAL, " k keep the field active after command executed");
PrintAndLogEx(NORMAL, " s silent (no messages)");
@ -217,8 +212,7 @@ int usage_hf_14a_reader(void)
PrintAndLogEx(NORMAL, " 3 ISO14443-3 select only (skip RATS)");
return 0;
}
int usage_hf_14a_info(void)
{
int usage_hf_14a_info(void) {
PrintAndLogEx(NORMAL, "This command makes more extensive tests against a ISO14443a tag in order to collect information");
PrintAndLogEx(NORMAL, "Usage: hf 14a info [h|s]");
PrintAndLogEx(NORMAL, " s silent (no messages)");
@ -226,15 +220,13 @@ int usage_hf_14a_info(void)
return 0;
}
int CmdHF14AList(const char *Cmd)
{
int CmdHF14AList(const char *Cmd) {
//PrintAndLogEx(NORMAL, "Deprecated command, use 'hf list 14a' instead");
CmdTraceList("14a");
return 0;
}
int Hf14443_4aGetCardData(iso14a_card_select_t *card)
{
int Hf14443_4aGetCardData(iso14a_card_select_t *card) {
UsbCommand c = {CMD_READER_ISO_14443a, {ISO14A_CONNECT, 0, 0}};
SendCommand(&c);
@ -273,8 +265,7 @@ int Hf14443_4aGetCardData(iso14a_card_select_t *card)
return 0;
}
int CmdHF14AReader(const char *Cmd)
{
int CmdHF14AReader(const char *Cmd) {
uint32_t cm = ISO14A_CONNECT;
bool disconnectAfter = true, silent = false;
@ -362,8 +353,7 @@ int CmdHF14AReader(const char *Cmd)
return 0;
}
int CmdHF14AInfo(const char *Cmd)
{
int CmdHF14AInfo(const char *Cmd) {
if (Cmd[0] == 'h' || Cmd[0] == 'H') return usage_hf_14a_info();
@ -665,8 +655,7 @@ int CmdHF14AInfo(const char *Cmd)
}
// Collect ISO14443 Type A UIDs
int CmdHF14ACUIDs(const char *Cmd)
{
int CmdHF14ACUIDs(const char *Cmd) {
// requested number of UIDs
int n = atoi(Cmd);
// collect at least 1 (e.g. if no parameter was given)
@ -710,8 +699,7 @@ int CmdHF14ACUIDs(const char *Cmd)
}
// ## simulate iso14443a tag
int CmdHF14ASim(const char *Cmd)
{
int CmdHF14ASim(const char *Cmd) {
bool errors = false;
uint8_t flags = 0;
uint8_t tagtype = 1;
@ -806,8 +794,7 @@ int CmdHF14ASim(const char *Cmd)
return 0;
}
int CmdHF14ASniff(const char *Cmd)
{
int CmdHF14ASniff(const char *Cmd) {
int param = 0;
uint8_t ctmp;
for (int i = 0; i < 2; i++) {
@ -822,8 +809,7 @@ int CmdHF14ASniff(const char *Cmd)
return 0;
}
int ExchangeRAW14a(uint8_t *datain, int datainlen, bool activateField, bool leaveSignalON, uint8_t *dataout, int maxdataoutlen, int *dataoutlen)
{
int ExchangeRAW14a(uint8_t *datain, int datainlen, bool activateField, bool leaveSignalON, uint8_t *dataout, int maxdataoutlen, int *dataoutlen) {
static bool responseNum = false;
uint16_t cmdc = 0;
*dataoutlen = 0;
@ -922,8 +908,7 @@ int ExchangeRAW14a(uint8_t *datain, int datainlen, bool activateField, bool leav
return 0;
}
int SelectCard14443_4(bool disconnect, iso14a_card_select_t *card)
{
int SelectCard14443_4(bool disconnect, iso14a_card_select_t *card) {
UsbCommand resp;
frameLength = 0;
@ -993,8 +978,7 @@ int SelectCard14443_4(bool disconnect, iso14a_card_select_t *card)
return 0;
}
int CmdExchangeAPDU(bool chainingin, uint8_t *datain, int datainlen, bool activateField, uint8_t *dataout, int maxdataoutlen, int *dataoutlen, bool *chainingout)
{
int CmdExchangeAPDU(bool chainingin, uint8_t *datain, int datainlen, bool activateField, uint8_t *dataout, int maxdataoutlen, int *dataoutlen, bool *chainingout) {
*chainingout = false;
if (activateField) {
@ -1078,15 +1062,14 @@ int CmdExchangeAPDU(bool chainingin, uint8_t *datain, int datainlen, bool activa
return 0;
}
int ExchangeAPDU14a(uint8_t *datain, int datainlen, bool activateField, bool leaveSignalON, uint8_t *dataout, int maxdataoutlen, int *dataoutlen)
{
int ExchangeAPDU14a(uint8_t *datain, int datainlen, bool activateField, bool leaveSignalON, uint8_t *dataout, int maxdataoutlen, int *dataoutlen) {
*dataoutlen = 0;
bool chaining = false;
int res;
// 3 byte here - 1b framing header, 2b crc16
if (APDUInFramingEnable &&
((frameLength && (datainlen > frameLength - 3)) || (datainlen > USB_CMD_DATA_SIZE - 3))) {
((frameLength && (datainlen > frameLength - 3)) || (datainlen > USB_CMD_DATA_SIZE - 3))) {
int clen = 0;
bool vActivateField = activateField;
@ -1149,8 +1132,7 @@ int ExchangeAPDU14a(uint8_t *datain, int datainlen, bool activateField, bool lea
}
// ISO14443-4. 7. Half-duplex block transmission protocol
int CmdHF14AAPDU(const char *cmd)
{
int CmdHF14AAPDU(const char *cmd) {
uint8_t data[USB_CMD_DATA_SIZE];
int datalen = 0;
bool activateField = false;
@ -1197,8 +1179,7 @@ int CmdHF14AAPDU(const char *cmd)
return 0;
}
int CmdHF14ACmdRaw(const char *cmd)
{
int CmdHF14ACmdRaw(const char *cmd) {
UsbCommand c = {CMD_READER_ISO_14443a, {0, 0, 0}};
bool reply = 1;
bool crc = false;
@ -1271,8 +1252,8 @@ int CmdHF14ACmdRaw(const char *cmd)
continue;
}
if ((cmd[i] >= '0' && cmd[i] <= '9') ||
(cmd[i] >= 'a' && cmd[i] <= 'f') ||
(cmd[i] >= 'A' && cmd[i] <= 'F')) {
(cmd[i] >= 'a' && cmd[i] <= 'f') ||
(cmd[i] >= 'A' && cmd[i] <= 'F')) {
buf[strlen(buf) + 1] = 0;
buf[strlen(buf)] = cmd[i];
i++;
@ -1354,8 +1335,7 @@ int CmdHF14ACmdRaw(const char *cmd)
return 0;
}
static int waitCmd(uint8_t iSelect)
{
static int waitCmd(uint8_t iSelect) {
UsbCommand resp;
uint16_t len = 0;
@ -1383,8 +1363,7 @@ static int waitCmd(uint8_t iSelect)
return 0;
}
int CmdHF14AAntiFuzz(const char *cmd)
{
int CmdHF14AAntiFuzz(const char *cmd) {
CLIParserInit("hf 14a antifuzz",
"Tries to fuzz the ISO14443a anticollision phase",
@ -1413,8 +1392,7 @@ int CmdHF14AAntiFuzz(const char *cmd)
return 0;
}
int CmdHF14AChaining(const char *cmd)
{
int CmdHF14AChaining(const char *cmd) {
CLIParserInit("hf 14a chaining",
"Enable/Disable ISO14443a input chaining. Maximum input length goes from ATS.",
@ -1460,15 +1438,13 @@ static command_t CommandTable[] = {
{NULL, NULL, 0, NULL}
};
int CmdHF14A(const char *Cmd)
{
int CmdHF14A(const char *Cmd) {
clearCommandBuffer();
CmdsParse(CommandTable, Cmd);
return 0;
}
int CmdHelp(const char *Cmd)
{
int CmdHelp(const char *Cmd) {
CmdsHelp(CommandTable);
return 0;
}

View file

@ -14,8 +14,7 @@
#define TIMEOUT 2000
static int CmdHelp(const char *Cmd);
int usage_hf_14b_info(void)
{
int usage_hf_14b_info(void) {
PrintAndLogEx(NORMAL, "Usage: hf 14b info [h] [s]");
PrintAndLogEx(NORMAL, "Options:");
PrintAndLogEx(NORMAL, " h this help");
@ -24,8 +23,7 @@ int usage_hf_14b_info(void)
PrintAndLogEx(NORMAL, " hf 14b info");
return 0;
}
int usage_hf_14b_reader(void)
{
int usage_hf_14b_reader(void) {
PrintAndLogEx(NORMAL, "Usage: hf 14b reader [h] [s]");
PrintAndLogEx(NORMAL, "Options:");
PrintAndLogEx(NORMAL, " h this help");
@ -34,8 +32,7 @@ int usage_hf_14b_reader(void)
PrintAndLogEx(NORMAL, " hf 14b reader");
return 0;
}
int usage_hf_14b_raw(void)
{
int usage_hf_14b_raw(void) {
PrintAndLogEx(NORMAL, "Usage: hf 14b raw [-h] [-r] [-c] [-p] [-s || -ss] <0A 0B 0C ... hex>");
PrintAndLogEx(NORMAL, "Options:");
PrintAndLogEx(NORMAL, " -h this help");
@ -48,8 +45,7 @@ int usage_hf_14b_raw(void)
PrintAndLogEx(NORMAL, " hf 14b raw -s -c -p 0200a40400");
return 0;
}
int usage_hf_14b_sniff(void)
{
int usage_hf_14b_sniff(void) {
PrintAndLogEx(NORMAL, "It get data from the field and saves it into command buffer.");
PrintAndLogEx(NORMAL, "Buffer accessible from command 'hf list 14b'");
PrintAndLogEx(NORMAL, "Usage: hf 14b sniff [h]");
@ -59,8 +55,7 @@ int usage_hf_14b_sniff(void)
PrintAndLogEx(NORMAL, " hf 14b sniff");
return 0;
}
int usage_hf_14b_sim(void)
{
int usage_hf_14b_sim(void) {
PrintAndLogEx(NORMAL, "Emulating ISO/IEC 14443 type B tag with 4 UID / PUPI");
PrintAndLogEx(NORMAL, "Usage: hf 14b sim [h] u <uid>");
PrintAndLogEx(NORMAL, "Options:");
@ -71,8 +66,7 @@ int usage_hf_14b_sim(void)
PrintAndLogEx(NORMAL, " hf 14b sim u 11223344");
return 0;
}
int usage_hf_14b_read_srx(void)
{
int usage_hf_14b_read_srx(void) {
PrintAndLogEx(NORMAL, "Usage: hf 14b sriread [h] <1|2>");
PrintAndLogEx(NORMAL, "Options:");
PrintAndLogEx(NORMAL, " h this help");
@ -82,8 +76,7 @@ int usage_hf_14b_read_srx(void)
PrintAndLogEx(NORMAL, " hf 14b sriread 2");
return 0;
}
int usage_hf_14b_write_srx(void)
{
int usage_hf_14b_write_srx(void) {
PrintAndLogEx(NORMAL, "Usage: hf 14b [h] sriwrite <1|2> <BLOCK> <DATA>");
PrintAndLogEx(NORMAL, "Options:");
PrintAndLogEx(NORMAL, " h this help");
@ -97,8 +90,7 @@ int usage_hf_14b_write_srx(void)
PrintAndLogEx(NORMAL, " hf 14b sriwrite 2 FF 11223344");
return 0;
}
int usage_hf_14b_dump(void)
{
int usage_hf_14b_dump(void) {
PrintAndLogEx(NORMAL, "This command dumps the contents of a ISO-14443-B tag and save it to file\n"
"\n"
"Usage: hf 14b dump [h] [card memory] <f filname> \n"
@ -121,22 +113,19 @@ static void switch_on_field_14b(void) {
}
*/
static int switch_off_field_14b(void)
{
static int switch_off_field_14b(void) {
UsbCommand c = {CMD_ISO_14443B_COMMAND, {ISO14B_DISCONNECT, 0, 0}};
clearCommandBuffer();
SendCommand(&c);
return 0;
}
int CmdHF14BList(const char *Cmd)
{
int CmdHF14BList(const char *Cmd) {
CmdTraceList("14b");
return 0;
}
int CmdHF14BSim(const char *Cmd)
{
int CmdHF14BSim(const char *Cmd) {
char cmdp = tolower(param_getchar(Cmd, 0));
if (cmdp == 'h') return usage_hf_14b_sim();
@ -151,8 +140,7 @@ int CmdHF14BSim(const char *Cmd)
return 0;
}
int CmdHF14BSniff(const char *Cmd)
{
int CmdHF14BSniff(const char *Cmd) {
char cmdp = tolower(param_getchar(Cmd, 0));
if (cmdp == 'h') return usage_hf_14b_sniff();
@ -163,8 +151,7 @@ int CmdHF14BSniff(const char *Cmd)
return 0;
}
int CmdHF14BCmdRaw(const char *Cmd)
{
int CmdHF14BCmdRaw(const char *Cmd) {
bool reply = true, power = false, select = false;
char buf[5] = "";
int i = 0;
@ -209,8 +196,8 @@ int CmdHF14BCmdRaw(const char *Cmd)
continue;
}
if ((Cmd[i] >= '0' && Cmd[i] <= '9') ||
(Cmd[i] >= 'a' && Cmd[i] <= 'f') ||
(Cmd[i] >= 'A' && Cmd[i] <= 'F')) {
(Cmd[i] >= 'a' && Cmd[i] <= 'f') ||
(Cmd[i] >= 'A' && Cmd[i] <= 'F')) {
buf[strlen(buf) + 1] = 0;
buf[strlen(buf)] = Cmd[i];
i++;
@ -254,8 +241,7 @@ int CmdHF14BCmdRaw(const char *Cmd)
return 1;
}
static bool get_14b_UID(iso14b_card_select_t *card)
{
static bool get_14b_UID(iso14b_card_select_t *card) {
if (!card)
return false;
@ -309,8 +295,7 @@ static bool get_14b_UID(iso14b_card_select_t *card)
// 4 = bit rate capacity
// 5 = max frame size / -4 info
// 6 = FWI / Coding options
static void print_atqb_resp(uint8_t *data, uint8_t cid)
{
static void print_atqb_resp(uint8_t *data, uint8_t cid) {
//PrintAndLogEx(NORMAL, " UID: %s", sprint_hex(data+1,4));
PrintAndLogEx(NORMAL, " App Data: %s", sprint_hex(data, 4));
PrintAndLogEx(NORMAL, " Protocol: %s", sprint_hex(data + 4, 3));
@ -356,8 +341,7 @@ static void print_atqb_resp(uint8_t *data, uint8_t cid)
}
// get SRx chip model (from UID) // from ST Microelectronics
char *get_ST_Chip_Model(uint8_t data)
{
char *get_ST_Chip_Model(uint8_t data) {
static char model[20];
char *retStr = model;
memset(model, 0, sizeof(model));
@ -392,8 +376,7 @@ char *get_ST_Chip_Model(uint8_t data)
}
// REMAKE:
int print_ST_Lock_info(uint8_t model)
{
int print_ST_Lock_info(uint8_t model) {
// PrintAndLogEx(NORMAL, "Chip Write Protection Bits:");
// // now interpret the data
@ -439,8 +422,7 @@ int print_ST_Lock_info(uint8_t model)
}
// print UID info from SRx chips (ST Microelectronics)
static void print_st_general_info(uint8_t *data, uint8_t len)
{
static void print_st_general_info(uint8_t *data, uint8_t len) {
//uid = first 8 bytes in data
PrintAndLogEx(NORMAL, " UID: %s", sprint_hex(SwapEndian64(data, 8, 8), len));
PrintAndLogEx(NORMAL, " MFG: %02X, %s", data[6], getTagInfo(data[6]));
@ -467,8 +449,7 @@ static void print_st_general_info(uint8_t *data, uint8_t len)
//a2 = ? (resp 02 [6a d3])
// 14b get and print Full Info (as much as we know)
bool HF14B_Std_Info(bool verbose)
{
bool HF14B_Std_Info(bool verbose) {
bool isSuccess = false;
@ -512,8 +493,7 @@ bool HF14B_Std_Info(bool verbose)
}
// SRx get and print full info (needs more info...)
bool HF14B_ST_Info(bool verbose)
{
bool HF14B_ST_Info(bool verbose) {
UsbCommand c = {CMD_ISO_14443B_COMMAND, {ISO14B_CONNECT | ISO14B_SELECT_SR | ISO14B_DISCONNECT, 0, 0}};
clearCommandBuffer();
@ -559,8 +539,7 @@ bool HF14B_ST_Info(bool verbose)
}
// get and print all info known about any known 14b tag
bool HF14BInfo(bool verbose)
{
bool HF14BInfo(bool verbose) {
// try std 14b (atqb)
if (HF14B_Std_Info(verbose)) return true;
@ -575,8 +554,7 @@ bool HF14BInfo(bool verbose)
}
// menu command to get and print all info known about any known 14b tag
int CmdHF14Binfo(const char *Cmd)
{
int CmdHF14Binfo(const char *Cmd) {
char cmdp = tolower(param_getchar(Cmd, 0));
if (cmdp == 'h') return usage_hf_14b_info();
@ -584,8 +562,7 @@ int CmdHF14Binfo(const char *Cmd)
return HF14BInfo(verbose);
}
bool HF14B_ST_Reader(bool verbose)
{
bool HF14B_ST_Reader(bool verbose) {
bool isSuccess = false;
@ -625,8 +602,7 @@ bool HF14B_ST_Reader(bool verbose)
return isSuccess;
}
bool HF14B_Std_Reader(bool verbose)
{
bool HF14B_Std_Reader(bool verbose) {
bool isSuccess = false;
@ -668,8 +644,7 @@ bool HF14B_Std_Reader(bool verbose)
}
// test for other 14b type tags (mimic another reader - don't have tags to identify)
bool HF14B_Other_Reader()
{
bool HF14B_Other_Reader() {
// uint8_t data[] = {0x00, 0x0b, 0x3f, 0x80};
// uint8_t datalen = 4;
@ -728,8 +703,7 @@ bool HF14B_Other_Reader()
}
// get and print general info about all known 14b chips
bool HF14BReader(bool verbose)
{
bool HF14BReader(bool verbose) {
// try std 14b (atqb)
if (HF14B_Std_Reader(verbose)) return true;
@ -746,8 +720,7 @@ bool HF14BReader(bool verbose)
}
// menu command to get and print general info about all known 14b chips
int CmdHF14BReader(const char *Cmd)
{
int CmdHF14BReader(const char *Cmd) {
char cmdp = tolower(param_getchar(Cmd, 0));
if (cmdp == 'h') return usage_hf_14b_reader();
@ -759,8 +732,7 @@ int CmdHF14BReader(const char *Cmd)
* SRI* tags are ISO14443-B modulated memory tags,
* this command just dumps the contents of the memory/
*/
int CmdHF14BReadSri(const char *Cmd)
{
int CmdHF14BReadSri(const char *Cmd) {
char cmdp = tolower(param_getchar(Cmd, 0));
if (strlen(Cmd) < 1 || cmdp == 'h') return usage_hf_14b_read_srx();
@ -773,8 +745,7 @@ int CmdHF14BReadSri(const char *Cmd)
return 0;
}
// New command to write a SRI512/SRIX4K tag.
int CmdHF14BWriteSri(const char *Cmd)
{
int CmdHF14BWriteSri(const char *Cmd) {
/*
* For SRIX4K blocks 00 - 7F
* hf 14b raw -c -p 09 $srix4kwblock $srix4kwdata
@ -841,8 +812,7 @@ int CmdHF14BWriteSri(const char *Cmd)
}
// need to write to file
int CmdHF14BDump(const char *Cmd)
{
int CmdHF14BDump(const char *Cmd) {
uint8_t fileNameLen = 0;
char filename[FILE_PATH_SIZE] = {0};
@ -998,8 +968,7 @@ out:
return switch_off_field_14b();
}
uint32_t srix4kEncode(uint32_t value)
{
uint32_t srix4kEncode(uint32_t value) {
/*
// vv = value
// pp = position
@ -1055,8 +1024,7 @@ uint32_t srix4kEncode(uint32_t value)
PrintAndLogEx(NORMAL, "ICE encoded | %08X -> %08X", value, encvalue);
return encvalue;
}
uint32_t srix4kDecode(uint32_t value)
{
uint32_t srix4kDecode(uint32_t value) {
switch (value) {
case 0xC04F42C5:
return 0x003139;
@ -1067,15 +1035,13 @@ uint32_t srix4kDecode(uint32_t value)
}
return 0;
}
uint32_t srix4kDecodeCounter(uint32_t num)
{
uint32_t srix4kDecodeCounter(uint32_t num) {
uint32_t value = ~num;
++value;
return value;
}
uint32_t srix4kGetMagicbytes(uint64_t uid, uint32_t block6, uint32_t block18, uint32_t block19)
{
uint32_t srix4kGetMagicbytes(uint64_t uid, uint32_t block6, uint32_t block18, uint32_t block19) {
#define MASK 0xFFFFFFFF;
uint32_t uid32 = uid & MASK;
uint32_t counter = srix4kDecodeCounter(block6);
@ -1087,8 +1053,7 @@ uint32_t srix4kGetMagicbytes(uint64_t uid, uint32_t block6, uint32_t block18, ui
PrintAndLogEx(SUCCESS, "Magic bytes | %08X", result);
return result;
}
int srix4kValid(const char *Cmd)
{
int srix4kValid(const char *Cmd) {
uint64_t uid = 0xD00202501A4532F9;
uint32_t block6 = 0xFFFFFFFF;
@ -1106,8 +1071,7 @@ int srix4kValid(const char *Cmd)
return 0;
}
bool waitCmd14b(bool verbose)
{
bool waitCmd14b(bool verbose) {
bool crc = false;
uint8_t data[USB_CMD_DATA_SIZE] = {0x00};
@ -1161,15 +1125,13 @@ static command_t CommandTable[] = {
{NULL, NULL, 0, NULL}
};
int CmdHF14B(const char *Cmd)
{
int CmdHF14B(const char *Cmd) {
clearCommandBuffer();
CmdsParse(CommandTable, Cmd);
return 0;
}
int CmdHelp(const char *Cmd)
{
int CmdHelp(const char *Cmd) {
CmdsHelp(CommandTable);
return 0;
}

View file

@ -189,8 +189,7 @@ const productName uidmapping[] = {
// fast method to just read the UID of a tag (collission detection not supported)
// *buf should be large enough to fit the 64bit uid
// returns 1 if suceeded
int getUID(uint8_t *buf)
{
int getUID(uint8_t *buf) {
UsbCommand resp;
UsbCommand c = {CMD_ISO_15693_COMMAND, {0, 1, 1}}; // len,speed,recv?
@ -229,8 +228,7 @@ int getUID(uint8_t *buf)
// get a product description based on the UID
// uid[8] tag uid
// returns description of the best match
static char *getTagInfo_15(uint8_t *uid)
{
static char *getTagInfo_15(uint8_t *uid) {
uint64_t myuid, mask;
int i = 0, best = -1;
memcpy(&myuid, uid, sizeof(uint64_t));
@ -254,8 +252,7 @@ static char *getTagInfo_15(uint8_t *uid)
}
// return a clear-text message to an errorcode
static char *TagErrorStr(uint8_t error)
{
static char *TagErrorStr(uint8_t error) {
switch (error) {
case 0x01:
return "The command is not supported";
@ -280,20 +277,17 @@ static char *TagErrorStr(uint8_t error)
}
}
int usage_15_demod(void)
{
int usage_15_demod(void) {
PrintAndLogEx(NORMAL, "Tries to demodulate / decode ISO15693, from downloaded samples.\n"
"Gather samples with 'hf 15 read' / 'hf 15 record'");
return 0;
}
int usage_15_samples(void)
{
int usage_15_samples(void) {
PrintAndLogEx(NORMAL, "Acquire samples as Reader (enables carrier, send inquiry\n"
"and download it to graphbuffer. Try 'hf 15 demod' to try to demodulate/decode signal");
return 0;
}
int usage_15_info(void)
{
int usage_15_info(void) {
PrintAndLogEx(NORMAL, "Uses the optional command 'get_systeminfo' 0x2B to try and extract information\n"
"command may fail, depending on tag.\n"
"defaults to '1 out of 4' mode\n"
@ -309,13 +303,11 @@ int usage_15_info(void)
"\thf 15 info u");
return 0;
}
int usage_15_record(void)
{
int usage_15_record(void) {
PrintAndLogEx(NORMAL, "Record activity without enableing carrier");
return 0;
}
int usage_15_reader(void)
{
int usage_15_reader(void) {
PrintAndLogEx(NORMAL, "This command identifies a ISO 15693 tag\n"
"\n"
"Usage: hf 15 reader [h]\n"
@ -326,21 +318,18 @@ int usage_15_reader(void)
"\thf 15 reader");
return 0;
}
int usage_15_sim(void)
{
int usage_15_sim(void) {
PrintAndLogEx(NORMAL, "Usage: hf 15 sim <UID>\n"
"\n"
"Example:\n"
"\thf 15 sim E016240000000000");
return 0;
}
int usage_15_findafi(void)
{
int usage_15_findafi(void) {
PrintAndLogEx(NORMAL, "'hf 15 finafi' This command needs a helptext. Feel free to add one!");
return 0;
}
int usage_15_dump(void)
{
int usage_15_dump(void) {
PrintAndLogEx(NORMAL, "This command dumps the contents of a ISO-15693 tag and save it to file\n"
"\n"
"Usage: hf 15 dump [h] <f filname> \n"
@ -353,8 +342,7 @@ int usage_15_dump(void)
"\thf 15 dump f mydump");
return 0;
}
int usage_15_restore(void)
{
int usage_15_restore(void) {
char *options[][2] = {
{"h", "this help"},
{"-2", "use slower '1 out of 256' mode"},
@ -368,8 +356,7 @@ int usage_15_restore(void)
PrintAndLogOptions(options, 7, 3);
return 0;
}
int usage_15_raw(void)
{
int usage_15_raw(void) {
char *options[][2] = {
{"-r", "do not read response" },
{"-2", "use slower '1 out of 256' mode" },
@ -380,8 +367,7 @@ int usage_15_raw(void)
PrintAndLogOptions(options, 4, 3);
return 0;
}
int usage_15_read(void)
{
int usage_15_read(void) {
PrintAndLogEx(NORMAL, "Usage: hf 15 read [options] <uid|s|u|*> <page#>\n"
"Options:\n"
"\t-2 use slower '1 out of 256' mode\n"
@ -392,8 +378,7 @@ int usage_15_read(void)
"\tpage#: page number 0-255");
return 0;
}
int usage_15_write(void)
{
int usage_15_write(void) {
PrintAndLogEx(NORMAL, "Usage: hf 15 write [options] <uid|s|u|*> <page#> <hexdata>\n"
"Options:\n"
"\t-2 use slower '1 out of 256' mode\n"
@ -406,8 +391,7 @@ int usage_15_write(void)
"\thexdata: data to be written eg AA BB CC DD");
return 0;
}
int usage_15_readmulti(void)
{
int usage_15_readmulti(void) {
PrintAndLogEx(NORMAL, "Usage: hf 15 readmulti [options] <uid|s|u|*> <start#> <count#>\n"
"Options:\n"
"\t-2 use slower '1 out of 256' mode\n"
@ -421,8 +405,7 @@ int usage_15_readmulti(void)
}
// Mode 3
//helptext
int CmdHF15Demod(const char *Cmd)
{
int CmdHF15Demod(const char *Cmd) {
char cmdp = tolower(param_getchar(Cmd, 0));
if (cmdp == 'h') return usage_15_demod();
@ -502,8 +485,7 @@ int CmdHF15Demod(const char *Cmd)
// * Acquire Samples as Reader (enables carrier, sends inquiry)
//helptext
int CmdHF15Samples(const char *Cmd)
{
int CmdHF15Samples(const char *Cmd) {
char cmdp = tolower(param_getchar(Cmd, 0));
if (cmdp == 'h') return usage_15_samples();
@ -519,8 +501,7 @@ int CmdHF15Samples(const char *Cmd)
* Commandline handling: HF15 CMD SYSINFO
* get system information from tag/VICC
*/
int CmdHF15Info(const char *Cmd)
{
int CmdHF15Info(const char *Cmd) {
char cmdp = param_getchar(Cmd, 0);
if (strlen(Cmd) < 1 || cmdp == 'h' || cmdp == 'H') return usage_15_info();
@ -602,8 +583,7 @@ int CmdHF15Info(const char *Cmd)
// Record Activity without enabeling carrier
//helptext
int CmdHF15Record(const char *Cmd)
{
int CmdHF15Record(const char *Cmd) {
char cmdp = tolower(param_getchar(Cmd, 0));
if (cmdp == 'h') return usage_15_record();
@ -614,8 +594,7 @@ int CmdHF15Record(const char *Cmd)
}
// used with 'hf search'
int HF15Reader(const char *Cmd, bool verbose)
{
int HF15Reader(const char *Cmd, bool verbose) {
uint8_t uid[8] = {0, 0, 0, 0, 0, 0, 0, 0};
if (!getUID(uid)) {
if (verbose) PrintAndLogEx(WARNING, "No tag found.");
@ -627,8 +606,7 @@ int HF15Reader(const char *Cmd, bool verbose)
return 1;
}
int CmdHF15Reader(const char *Cmd)
{
int CmdHF15Reader(const char *Cmd) {
char cmdp = tolower(param_getchar(Cmd, 0));
if (cmdp == 'h') return usage_15_reader();
@ -638,8 +616,7 @@ int CmdHF15Reader(const char *Cmd)
// Simulation is still not working very good
// helptext
int CmdHF15Sim(const char *Cmd)
{
int CmdHF15Sim(const char *Cmd) {
char cmdp = tolower(param_getchar(Cmd, 0));
if (strlen(Cmd) < 1 || cmdp == 'h') return usage_15_sim();
@ -661,8 +638,7 @@ int CmdHF15Sim(const char *Cmd)
// finds the AFI (Application Family Idendifier) of a card, by trying all values
// (There is no standard way of reading the AFI, allthough some tags support this)
// helptext
int CmdHF15Afi(const char *Cmd)
{
int CmdHF15Afi(const char *Cmd) {
char cmdp = tolower(param_getchar(Cmd, 0));
if (cmdp == 'h') return usage_15_findafi();
@ -681,8 +657,7 @@ typedef struct {
// Reads all memory pages
// need to write to file
int CmdHF15Dump(const char *Cmd)
{
int CmdHF15Dump(const char *Cmd) {
uint8_t fileNameLen = 0;
char filename[FILE_PATH_SIZE] = {0};
@ -798,8 +773,7 @@ int CmdHF15Dump(const char *Cmd)
return 0;
}
int CmdHF15Restore(const char *Cmd)
{
int CmdHF15Restore(const char *Cmd) {
FILE *f;
uint8_t uid[8] = {0x00};
@ -911,15 +885,13 @@ int CmdHF15Restore(const char *Cmd)
fclose(f);
}
int CmdHF15List(const char *Cmd)
{
int CmdHF15List(const char *Cmd) {
//PrintAndLogEx(WARNING, "Deprecated command, use 'hf list 15' instead");
CmdTraceList("15");
return 0;
}
int CmdHF15Raw(const char *Cmd)
{
int CmdHF15Raw(const char *Cmd) {
char cmdp = param_getchar(Cmd, 0);
if (strlen(Cmd) < 3 || cmdp == 'h' || cmdp == 'H') return usage_15_raw();
@ -958,8 +930,8 @@ int CmdHF15Raw(const char *Cmd)
continue;
}
if ((Cmd[i] >= '0' && Cmd[i] <= '9') ||
(Cmd[i] >= 'a' && Cmd[i] <= 'f') ||
(Cmd[i] >= 'A' && Cmd[i] <= 'F')) {
(Cmd[i] >= 'a' && Cmd[i] <= 'f') ||
(Cmd[i] >= 'A' && Cmd[i] <= 'F')) {
buf[strlen(buf) + 1] = 0;
buf[strlen(buf)] = Cmd[i];
i++;
@ -1006,8 +978,7 @@ int CmdHF15Raw(const char *Cmd)
* Parameters:
* **cmd command line
*/
int prepareHF15Cmd(char **cmd, UsbCommand *c, uint8_t iso15cmd)
{
int prepareHF15Cmd(char **cmd, UsbCommand *c, uint8_t iso15cmd) {
int temp;
uint8_t *req = c->d.asBytes;
uint8_t uid[8] = {0x00};
@ -1084,8 +1055,7 @@ int prepareHF15Cmd(char **cmd, UsbCommand *c, uint8_t iso15cmd)
* Commandline handling: HF15 CMD READMULTI
* Read multiple blocks at once (not all tags support this)
*/
int CmdHF15Readmulti(const char *Cmd)
{
int CmdHF15Readmulti(const char *Cmd) {
char cmdp = param_getchar(Cmd, 0);
if (strlen(Cmd) < 3 || cmdp == 'h' || cmdp == 'H') return usage_15_readmulti();
@ -1168,8 +1138,7 @@ int CmdHF15Readmulti(const char *Cmd)
* Commandline handling: HF15 CMD READ
* Reads a single Block
*/
int CmdHF15Read(const char *Cmd)
{
int CmdHF15Read(const char *Cmd) {
char cmdp = param_getchar(Cmd, 0);
if (strlen(Cmd) < 3 || cmdp == 'h' || cmdp == 'H') return usage_15_read();
@ -1243,8 +1212,7 @@ int CmdHF15Read(const char *Cmd)
* Commandline handling: HF15 CMD WRITE
* Writes a single Block - might run into timeout, even when successful
*/
int CmdHF15Write(const char *Cmd)
{
int CmdHF15Write(const char *Cmd) {
char cmdp = param_getchar(Cmd, 0);
if (strlen(Cmd) < 3 || cmdp == 'h' || cmdp == 'H') return usage_15_write();
@ -1338,15 +1306,13 @@ static command_t CommandTable15[] = {
{NULL, NULL, 0, NULL}
};
int CmdHF15(const char *Cmd)
{
int CmdHF15(const char *Cmd) {
clearCommandBuffer();
CmdsParse(CommandTable15, Cmd);
return 0;
}
int CmdHF15Help(const char *Cmd)
{
int CmdHF15Help(const char *Cmd) {
CmdsHelp(CommandTable15);
return 0;
}

View file

@ -12,8 +12,7 @@
static int CmdHelp(const char *Cmd);
// Perform (part of) the PACE protocol
int CmdHFEPACollectPACENonces(const char *Cmd)
{
int CmdHFEPACollectPACENonces(const char *Cmd) {
// requested nonce size
uint32_t m = 0;
// requested number of Nonces
@ -60,8 +59,7 @@ int CmdHFEPACollectPACENonces(const char *Cmd)
}
// perform the PACE protocol by replaying APDUs
int CmdHFEPAPACEReplay(const char *Cmd)
{
int CmdHFEPAPACEReplay(const char *Cmd) {
// the 4 APDUs which are replayed + their lengths
uint8_t msesa_apdu[41], gn_apdu[8], map_apdu[75];
uint8_t pka_apdu[75], ma_apdu[18], apdu_lengths[5] = {0};
@ -169,14 +167,12 @@ static command_t CommandTable[] = {
{NULL, NULL, 0, NULL}
};
int CmdHelp(const char *Cmd)
{
int CmdHelp(const char *Cmd) {
CmdsHelp(CommandTable);
return 0;
}
int CmdHFEPA(const char *Cmd)
{
int CmdHFEPA(const char *Cmd) {
clearCommandBuffer();
CmdsParse(CommandTable, Cmd);
return 0;

View file

@ -11,8 +11,7 @@
static int CmdHelp(const char *Cmd);
int usage_hf_felica_sim(void)
{
int usage_hf_felica_sim(void) {
PrintAndLogEx(NORMAL, "\n Emulating ISO/18092 FeliCa tag \n");
PrintAndLogEx(NORMAL, "Usage: hf felica sim [h] t <type> [v]");
PrintAndLogEx(NORMAL, "Options:");
@ -24,8 +23,7 @@ int usage_hf_felica_sim(void)
PrintAndLogEx(NORMAL, " hf felica sim t 1 ");
return 0;
}
int usage_hf_felica_sniff(void)
{
int usage_hf_felica_sniff(void) {
PrintAndLogEx(NORMAL, "It get data from the field and saves it into command buffer.");
PrintAndLogEx(NORMAL, "Buffer accessible from command 'hf list felica'");
PrintAndLogEx(NORMAL, "Usage: hf felica sniff <s > <t>");
@ -35,8 +33,7 @@ int usage_hf_felica_sniff(void)
PrintAndLogEx(NORMAL, " hf felica sniff s 1000");
return 0;
}
int usage_hf_felica_simlite(void)
{
int usage_hf_felica_simlite(void) {
PrintAndLogEx(NORMAL, "\n Emulating ISO/18092 FeliCa Lite tag \n");
PrintAndLogEx(NORMAL, "Usage: hf felica litesim [h] u <uid>");
PrintAndLogEx(NORMAL, "Options:");
@ -46,8 +43,7 @@ int usage_hf_felica_simlite(void)
PrintAndLogEx(NORMAL, " hf felica litesim 11223344556677");
return 0;
}
int usage_hf_felica_dumplite(void)
{
int usage_hf_felica_dumplite(void) {
PrintAndLogEx(NORMAL, "\n Dump ISO/18092 FeliCa Lite tag \n");
PrintAndLogEx(NORMAL, "press button to abort run, otherwise it will loop for 200sec.");
PrintAndLogEx(NORMAL, "Usage: hf felica litedump [h]");
@ -57,8 +53,7 @@ int usage_hf_felica_dumplite(void)
PrintAndLogEx(NORMAL, " hf felica litedump");
return 0;
}
int usage_hf_felica_raw(void)
{
int usage_hf_felica_raw(void) {
PrintAndLogEx(NORMAL, "Usage: hf felica raw [-h] [-r] [-c] [-p] [-a] <0A 0B 0C ... hex>");
PrintAndLogEx(NORMAL, " -h this help");
PrintAndLogEx(NORMAL, " -r do not read response");
@ -69,15 +64,13 @@ int usage_hf_felica_raw(void)
return 0;
}
int CmdHFFelicaList(const char *Cmd)
{
int CmdHFFelicaList(const char *Cmd) {
//PrintAndLogEx(NORMAL, "Deprecated command, use 'hf list felica' instead");
CmdTraceList("felica");
return 0;
}
int CmdHFFelicaReader(const char *Cmd)
{
int CmdHFFelicaReader(const char *Cmd) {
bool silent = (Cmd[0] == 's' || Cmd[0] == 'S');
//UsbCommand cDisconnect = {CMD_FELICA_COMMAND, {0,0,0}};
UsbCommand c = {CMD_FELICA_COMMAND, {FELICA_CONNECT, 0, 0}};
@ -129,8 +122,7 @@ int CmdHFFelicaReader(const char *Cmd)
}
// simulate iso18092 / FeliCa tag
int CmdHFFelicaSim(const char *Cmd)
{
int CmdHFFelicaSim(const char *Cmd) {
bool errors = false;
uint8_t flags = 0;
uint8_t tagtype = 1;
@ -195,8 +187,7 @@ int CmdHFFelicaSim(const char *Cmd)
return 0;
}
int CmdHFFelicaSniff(const char *Cmd)
{
int CmdHFFelicaSniff(const char *Cmd) {
uint8_t cmdp = 0;
uint64_t samples2skip = 0;
@ -234,8 +225,7 @@ int CmdHFFelicaSniff(const char *Cmd)
}
// uid hex
int CmdHFFelicaSimLite(const char *Cmd)
{
int CmdHFFelicaSimLite(const char *Cmd) {
uint64_t uid = param_get64ex(Cmd, 0, 0, 16);
@ -248,13 +238,11 @@ int CmdHFFelicaSimLite(const char *Cmd)
return 0;
}
static void printSep()
{
static void printSep() {
PrintAndLogEx(NORMAL, "------------------------------------------------------------------------------------");
}
uint16_t PrintFliteBlock(uint16_t tracepos, uint8_t *trace, uint16_t tracelen)
{
uint16_t PrintFliteBlock(uint16_t tracepos, uint8_t *trace, uint16_t tracelen) {
if (tracepos + 19 >= tracelen)
return tracelen;
@ -401,8 +389,7 @@ uint16_t PrintFliteBlock(uint16_t tracepos, uint8_t *trace, uint16_t tracelen)
return tracepos + 19;
}
int CmdHFFelicaDumpLite(const char *Cmd)
{
int CmdHFFelicaDumpLite(const char *Cmd) {
char ctmp = tolower(param_getchar(Cmd, 0));
if (ctmp == 'h') return usage_hf_felica_dumplite();
@ -469,8 +456,7 @@ int CmdHFFelicaDumpLite(const char *Cmd)
return 0;
}
int CmdHFFelicaCmdRaw(const char *cmd)
{
int CmdHFFelicaCmdRaw(const char *cmd) {
UsbCommand c = {CMD_FELICA_COMMAND, {0, 0, 0}};
bool reply = 1;
bool crc = false;
@ -525,8 +511,8 @@ int CmdHFFelicaCmdRaw(const char *cmd)
continue;
}
if ((cmd[i] >= '0' && cmd[i] <= '9') ||
(cmd[i] >= 'a' && cmd[i] <= 'f') ||
(cmd[i] >= 'A' && cmd[i] <= 'F')) {
(cmd[i] >= 'a' && cmd[i] <= 'f') ||
(cmd[i] >= 'A' && cmd[i] <= 'F')) {
buf[strlen(buf) + 1] = 0;
buf[strlen(buf)] = cmd[i];
i++;
@ -586,8 +572,7 @@ int CmdHFFelicaCmdRaw(const char *cmd)
return 0;
}
void waitCmdFelica(uint8_t iSelect)
{
void waitCmdFelica(uint8_t iSelect) {
UsbCommand resp;
uint16_t len = 0;
@ -615,15 +600,13 @@ static command_t CommandTable[] = {
{NULL, NULL, 0, NULL}
};
int CmdHFFelica(const char *Cmd)
{
int CmdHFFelica(const char *Cmd) {
clearCommandBuffer();
CmdsParse(CommandTable, Cmd);
return 0;
}
int CmdHelp(const char *Cmd)
{
int CmdHelp(const char *Cmd) {
CmdsHelp(CommandTable);
return 0;
}

View file

@ -49,8 +49,7 @@
static int CmdHelp(const char *Cmd);
int CmdHFFidoInfo(const char *cmd)
{
int CmdHFFidoInfo(const char *cmd) {
if (cmd && strlen(cmd) > 0)
PrintAndLog("WARNING: command don't have any parameters.\n");
@ -125,8 +124,7 @@ int CmdHFFidoInfo(const char *cmd)
return 0;
}
json_t *OpenJson(int paramnum, char *fname, void *argtable[], bool *err)
{
json_t *OpenJson(int paramnum, char *fname, void *argtable[], bool *err) {
json_t *root = NULL;
json_error_t error;
*err = false;
@ -170,8 +168,7 @@ json_t *OpenJson(int paramnum, char *fname, void *argtable[], bool *err)
return root;
}
int CmdHFFidoRegister(const char *cmd)
{
int CmdHFFidoRegister(const char *cmd) {
uint8_t data[64] = {0};
int chlen = 0;
uint8_t cdata[250] = {0};
@ -400,8 +397,7 @@ int CmdHFFidoRegister(const char *cmd)
return 0;
};
int CmdHFFidoAuthenticate(const char *cmd)
{
int CmdHFFidoAuthenticate(const char *cmd) {
uint8_t data[512] = {0};
uint8_t hdata[250] = {0};
bool public_key_loaded = false;
@ -619,15 +615,13 @@ int CmdHFFidoAuthenticate(const char *cmd)
return 0;
};
void CheckSlash(char *fileName)
{
void CheckSlash(char *fileName) {
if ((fileName[strlen(fileName) - 1] != '/') &&
(fileName[strlen(fileName) - 1] != '\\'))
(fileName[strlen(fileName) - 1] != '\\'))
strcat(fileName, "/");
}
int GetExistsFileNameJson(char *prefixDir, char *reqestedFileName, char *fileName)
{
int GetExistsFileNameJson(char *prefixDir, char *reqestedFileName, char *fileName) {
fileName[0] = 0x00;
strcpy(fileName, get_my_executable_directory());
CheckSlash(fileName);
@ -654,8 +648,7 @@ int GetExistsFileNameJson(char *prefixDir, char *reqestedFileName, char *fileNam
return 0;
}
int CmdHFFido2MakeCredential(const char *cmd)
{
int CmdHFFido2MakeCredential(const char *cmd) {
json_error_t error;
json_t *root = NULL;
char fname[300] = {0};
@ -782,8 +775,7 @@ int CmdHFFido2MakeCredential(const char *cmd)
return 0;
};
int CmdHFFido2GetAssertion(const char *cmd)
{
int CmdHFFido2GetAssertion(const char *cmd) {
json_error_t error;
json_t *root = NULL;
char fname[300] = {0};
@ -920,15 +912,13 @@ static command_t CommandTable[] = {
{NULL, NULL, 0, NULL}
};
int CmdHFFido(const char *Cmd)
{
int CmdHFFido(const char *Cmd) {
(void)WaitForResponseTimeout(CMD_ACK, NULL, 100);
CmdsParse(CommandTable, Cmd);
return 0;
}
int CmdHelp(const char *Cmd)
{
int CmdHelp(const char *Cmd) {
CmdsHelp(CommandTable);
return 0;
}

View file

@ -29,8 +29,7 @@ static uint8_t iClass_Key_Table[ICLASS_KEYS_MAX][8] = {
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
};
int usage_hf_iclass_sim(void)
{
int usage_hf_iclass_sim(void) {
PrintAndLogEx(NORMAL, "Usage: hf iclass sim <option> [CSN]");
PrintAndLogEx(NORMAL, " options");
PrintAndLogEx(NORMAL, " 0 <CSN> simulate the given CSN");
@ -46,16 +45,14 @@ int usage_hf_iclass_sim(void)
PrintAndLogEx(NORMAL, " hf iclass sim 4");
return 0;
}
int usage_hf_iclass_eload(void)
{
int usage_hf_iclass_eload(void) {
PrintAndLogEx(NORMAL, "Loads iclass tag-dump into emulator memory on device");
PrintAndLogEx(NORMAL, "Usage: hf iclass eload f <filename>");
PrintAndLogEx(NORMAL, "Examples:");
PrintAndLogEx(NORMAL, " hf iclass eload f iclass_tagdump-aa162d30f8ff12f1.bin");
return 0;
}
int usage_hf_iclass_decrypt(void)
{
int usage_hf_iclass_decrypt(void) {
PrintAndLogEx(NORMAL, "This is simple implementation, it tries to decrypt every block after block 6.");
PrintAndLogEx(NORMAL, "Correct behaviour would be to decrypt only the application areas where the key is valid,");
PrintAndLogEx(NORMAL, "which is defined by the configuration block.");
@ -68,8 +65,7 @@ int usage_hf_iclass_decrypt(void)
PrintAndLogEx(NORMAL, "S hf iclass decrypt f tagdump_12312342343.bin");
return 0;
}
int usage_hf_iclass_encrypt(void)
{
int usage_hf_iclass_encrypt(void) {
PrintAndLogEx(NORMAL, "OBS! In order to use this function, the file 'iclass_decryptionkey.bin' must reside");
PrintAndLogEx(NORMAL, "in the working directory. The file should be 16 bytes binary data");
PrintAndLogEx(NORMAL, "");
@ -80,8 +76,7 @@ int usage_hf_iclass_encrypt(void)
PrintAndLogEx(NORMAL, "");
return 0;
}
int usage_hf_iclass_dump(void)
{
int usage_hf_iclass_dump(void) {
PrintAndLogEx(NORMAL, "Usage: hf iclass dump f <fileName> k <key> c <creditkey> [e|r|v]\n");
PrintAndLogEx(NORMAL, "Options:");
PrintAndLogEx(NORMAL, " f <filename> : specify a filename to save dump to");
@ -97,8 +92,7 @@ int usage_hf_iclass_dump(void)
PrintAndLogEx(NORMAL, " hf iclass dump k AAAAAAAAAAAAAAAA e");
return 0;
}
int usage_hf_iclass_clone(void)
{
int usage_hf_iclass_clone(void) {
PrintAndLogEx(NORMAL, "Usage: hf iclass clone f <tagfile.bin> b <first block> l <last block> k <KEY> c e|r");
PrintAndLogEx(NORMAL, "Options:");
PrintAndLogEx(NORMAL, " f <filename>: specify a filename to clone from");
@ -114,8 +108,7 @@ int usage_hf_iclass_clone(void)
PrintAndLogEx(NORMAL, " hf iclass clone f iclass_tagdump-121345.bin b 06 l 19 k 0 e");
return 0;
}
int usage_hf_iclass_writeblock(void)
{
int usage_hf_iclass_writeblock(void) {
PrintAndLogEx(NORMAL, "Usage: hf iclass writeblk b <block> d <data> k <key> [c|e|r|v]\n");
PrintAndLogEx(NORMAL, "Options:");
PrintAndLogEx(NORMAL, " b <Block> : The block number as 2 hex symbols");
@ -130,8 +123,7 @@ int usage_hf_iclass_writeblock(void)
PrintAndLogEx(NORMAL, " hf iclass writeblk b 1B d AAAAAAAAAAAAAAAA k 001122334455667B c");
return 0;
}
int usage_hf_iclass_readblock(void)
{
int usage_hf_iclass_readblock(void) {
PrintAndLogEx(NORMAL, "Usage: hf iclass readblk b <block> k <key> [c|e|r|v]\n");
PrintAndLogEx(NORMAL, "Options:");
PrintAndLogEx(NORMAL, " b <block> : The block number as 2 hex symbols");
@ -146,13 +138,11 @@ int usage_hf_iclass_readblock(void)
PrintAndLogEx(NORMAL, " hf iclass readblk b 0A k 0");
return 0;
}
int usage_hf_iclass_readtagfile()
{
int usage_hf_iclass_readtagfile() {
PrintAndLogEx(NORMAL, "Usage: hf iclass readtagfile <filename> [startblock] [endblock]");
return 0;
}
int usage_hf_iclass_calc_newkey(void)
{
int usage_hf_iclass_calc_newkey(void) {
PrintAndLogEx(NORMAL, "Calculate new key for updating\n");
PrintAndLogEx(NORMAL, "Usage: hf iclass calc_newkey o <Old key> n <New key> s [csn] e");
PrintAndLogEx(NORMAL, "Options:");
@ -168,8 +158,7 @@ int usage_hf_iclass_calc_newkey(void)
PrintAndLogEx(NORMAL, "\nNOTE: * = required\n");
return 0;
}
int usage_hf_iclass_managekeys(void)
{
int usage_hf_iclass_managekeys(void) {
PrintAndLogEx(NORMAL, "HELP : Manage iClass Keys in client memory:\n");
PrintAndLogEx(NORMAL, "Usage: hf iclass managekeys n [keynbr] k [key] f [filename] s l p\n");
PrintAndLogEx(NORMAL, "Options:");
@ -186,8 +175,7 @@ int usage_hf_iclass_managekeys(void)
PrintAndLogEx(NORMAL, " print keys : hf iclass managekeys p\n");
return 0;
}
int usage_hf_iclass_reader(void)
{
int usage_hf_iclass_reader(void) {
PrintAndLogEx(NORMAL, "Act as a Iclass reader. Look for iClass tags until a key or the pm3 button is pressed\n");
PrintAndLogEx(NORMAL, "Usage: hf iclass reader [h] [1]\n");
PrintAndLogEx(NORMAL, "Options:");
@ -197,8 +185,7 @@ int usage_hf_iclass_reader(void)
PrintAndLogEx(NORMAL, " hf iclass reader 1");
return 0;
}
int usage_hf_iclass_replay(void)
{
int usage_hf_iclass_replay(void) {
PrintAndLogEx(NORMAL, "Replay a collected mac message");
PrintAndLogEx(NORMAL, "Usage: hf iclass replay [h] <mac>");
PrintAndLogEx(NORMAL, "Options:");
@ -208,16 +195,14 @@ int usage_hf_iclass_replay(void)
PrintAndLogEx(NORMAL, " hf iclass replay 00112233");
return 0;
}
int usage_hf_iclass_sniff(void)
{
int usage_hf_iclass_sniff(void) {
PrintAndLogEx(NORMAL, "Sniff the communication between reader and tag");
PrintAndLogEx(NORMAL, "Usage: hf iclass sniff [h]");
PrintAndLogEx(NORMAL, "Examples:");
PrintAndLogEx(NORMAL, " hf iclass sniff");
return 0;
}
int usage_hf_iclass_loclass(void)
{
int usage_hf_iclass_loclass(void) {
PrintAndLogEx(NORMAL, "Usage: hf iclass loclass [options]");
PrintAndLogEx(NORMAL, "Options:");
PrintAndLogEx(NORMAL, "h Show this help");
@ -232,8 +217,7 @@ int usage_hf_iclass_loclass(void)
PrintAndLogEx(NORMAL, " ... totalling N*24 bytes");
return 0;
}
int usage_hf_iclass_chk(void)
{
int usage_hf_iclass_chk(void) {
PrintAndLogEx(NORMAL, "Checkkeys loads a dictionary text file with 8byte hex keys to test authenticating against a iClass tag");
PrintAndLogEx(NORMAL, "Usage: hf iclass chk [h|e|r] [f (*.dic)]");
PrintAndLogEx(NORMAL, "Options:");
@ -247,8 +231,7 @@ int usage_hf_iclass_chk(void)
PrintAndLogEx(NORMAL, " hf iclass chk f default_iclass_keys.dic e");
return 0;
}
int usage_hf_iclass_lookup(void)
{
int usage_hf_iclass_lookup(void) {
PrintAndLogEx(NORMAL, "Lookup keys takes some sniffed trace data and tries to verify what key was used against a dictionary file");
PrintAndLogEx(NORMAL, "Usage: hf iclass lookup [h|e|r] [f (*.dic)] [u <csn>] [p <epurse>] [m <macs>]");
PrintAndLogEx(NORMAL, "Options:");
@ -264,8 +247,7 @@ int usage_hf_iclass_lookup(void)
PrintAndLogEx(NORMAL, " hf iclass lookup u 9655a400f8ff12e0 p f0ffffffffffffff m 0000000089cb984b f default_iclass_keys.dic e");
return 0;
}
int usage_hf_iclass_permutekey(void)
{
int usage_hf_iclass_permutekey(void) {
PrintAndLogEx(NORMAL, "Permute function from 'heart of darkness' paper.");
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(NORMAL, "Usage: hf iclass permute [h] <r|f> <bytes>");
@ -280,8 +262,7 @@ int usage_hf_iclass_permutekey(void)
return 0;
}
int xorbits_8(uint8_t val)
{
int xorbits_8(uint8_t val) {
uint8_t res = val ^ (val >> 1); //1st pass
res = res ^ (res >> 1); // 2nd pass
res = res ^ (res >> 2); // 3rd pass
@ -289,15 +270,13 @@ int xorbits_8(uint8_t val)
return res & 1;
}
int CmdHFiClassList(const char *Cmd)
{
int CmdHFiClassList(const char *Cmd) {
//PrintAndLogEx(NORMAL, "Deprecated command, use 'hf list iclass' instead");
CmdTraceList("iclass");
return 0;
}
int CmdHFiClassSniff(const char *Cmd)
{
int CmdHFiClassSniff(const char *Cmd) {
char cmdp = tolower(param_getchar(Cmd, 0));
if (cmdp == 'h') return usage_hf_iclass_sniff();
UsbCommand c = {CMD_SNOOP_ICLASS};
@ -305,8 +284,7 @@ int CmdHFiClassSniff(const char *Cmd)
return 0;
}
int CmdHFiClassSim(const char *Cmd)
{
int CmdHFiClassSim(const char *Cmd) {
char cmdp = tolower(param_getchar(Cmd, 0));
if (strlen(Cmd) < 1 || cmdp == 'h') return usage_hf_iclass_sim();
@ -531,8 +509,7 @@ int CmdHFiClassSim(const char *Cmd)
return 0;
}
int HFiClassReader(const char *Cmd, bool loop, bool verbose)
{
int HFiClassReader(const char *Cmd, bool loop, bool verbose) {
bool tagFound = false;
uint32_t flags = FLAG_ICLASS_READER_CSN | FLAG_ICLASS_READER_CC | FLAG_ICLASS_READER_AIA |
@ -598,16 +575,14 @@ int HFiClassReader(const char *Cmd, bool loop, bool verbose)
return 0;
}
int CmdHFiClassReader(const char *Cmd)
{
int CmdHFiClassReader(const char *Cmd) {
char cmdp = tolower(param_getchar(Cmd, 0));
if (cmdp == 'h') return usage_hf_iclass_reader();
bool findone = (cmdp == '1') ? false : true;
return HFiClassReader(Cmd, findone, true);
}
int CmdHFiClassReader_Replay(const char *Cmd)
{
int CmdHFiClassReader_Replay(const char *Cmd) {
char cmdp = tolower(param_getchar(Cmd, 0));
if (strlen(Cmd) < 1 || cmdp == 'h') return usage_hf_iclass_replay();
@ -627,8 +602,7 @@ int CmdHFiClassReader_Replay(const char *Cmd)
return 0;
}
int iclassEmlSetMem(uint8_t *data, int blockNum, int blocksCount)
{
int iclassEmlSetMem(uint8_t *data, int blockNum, int blocksCount) {
UsbCommand c = {CMD_MIFARE_EML_MEMSET, {blockNum, blocksCount, 0}};
memcpy(c.d.asBytes, data, blocksCount * 16);
clearCommandBuffer();
@ -636,8 +610,7 @@ int iclassEmlSetMem(uint8_t *data, int blockNum, int blocksCount)
return 0;
}
int CmdHFiClassELoad(const char *Cmd)
{
int CmdHFiClassELoad(const char *Cmd) {
char ctmp = tolower(param_getchar(Cmd, 0));
if (strlen(Cmd) < 1 || ctmp == 'h') return usage_hf_iclass_eload();
@ -705,8 +678,7 @@ int CmdHFiClassELoad(const char *Cmd)
return 0;
}
static int readKeyfile(const char *filename, size_t len, uint8_t *buffer)
{
static int readKeyfile(const char *filename, size_t len, uint8_t *buffer) {
FILE *f = fopen(filename, "rb");
if (!f) {
PrintAndLogEx(WARNING, "Failed to read from file '%s'", filename);
@ -730,8 +702,7 @@ static int readKeyfile(const char *filename, size_t len, uint8_t *buffer)
return 0;
}
int CmdHFiClassDecrypt(const char *Cmd)
{
int CmdHFiClassDecrypt(const char *Cmd) {
char opt = tolower(param_getchar(Cmd, 0));
if (strlen(Cmd) < 1 || opt == 'h') return usage_hf_iclass_decrypt();
@ -818,8 +789,7 @@ int CmdHFiClassDecrypt(const char *Cmd)
return 0;
}
static int iClassEncryptBlkData(uint8_t *blkData)
{
static int iClassEncryptBlkData(uint8_t *blkData) {
uint8_t key[16] = { 0 };
if (readKeyfile("iclass_decryptionkey.bin", 16, key)) {
usage_hf_iclass_encrypt();
@ -836,8 +806,7 @@ static int iClassEncryptBlkData(uint8_t *blkData)
return 1;
}
int CmdHFiClassEncryptBlk(const char *Cmd)
{
int CmdHFiClassEncryptBlk(const char *Cmd) {
uint8_t blkData[8] = {0};
char opt = tolower(param_getchar(Cmd, 0));
if (strlen(Cmd) < 1 || opt == 'h') return usage_hf_iclass_encrypt();
@ -853,16 +822,14 @@ int CmdHFiClassEncryptBlk(const char *Cmd)
return 1;
}
void Calc_wb_mac(uint8_t blockno, uint8_t *data, uint8_t *div_key, uint8_t MAC[4])
{
void Calc_wb_mac(uint8_t blockno, uint8_t *data, uint8_t *div_key, uint8_t MAC[4]) {
uint8_t wb[9];
wb[0] = blockno;
memcpy(wb + 1, data, 8);
doMAC_N(wb, sizeof(wb), div_key, MAC);
}
static bool select_only(uint8_t *CSN, uint8_t *CCNR, bool use_credit_key, bool verbose)
{
static bool select_only(uint8_t *CSN, uint8_t *CCNR, bool use_credit_key, bool verbose) {
UsbCommand resp;
UsbCommand c = {CMD_READER_ICLASS, {0}};
c.arg[0] = FLAG_ICLASS_READER_ONLY_ONCE | FLAG_ICLASS_READER_CC | FLAG_ICLASS_READER_ONE_TRY;
@ -897,8 +864,7 @@ static bool select_only(uint8_t *CSN, uint8_t *CCNR, bool use_credit_key, bool v
return true;
}
static bool select_and_auth(uint8_t *KEY, uint8_t *MAC, uint8_t *div_key, bool use_credit_key, bool elite, bool rawkey, bool verbose)
{
static bool select_and_auth(uint8_t *KEY, uint8_t *MAC, uint8_t *div_key, bool use_credit_key, bool elite, bool rawkey, bool verbose) {
uint8_t CSN[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
uint8_t CCNR[12] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
@ -932,8 +898,7 @@ static bool select_and_auth(uint8_t *KEY, uint8_t *MAC, uint8_t *div_key, bool u
return true;
}
int CmdHFiClassReader_Dump(const char *Cmd)
{
int CmdHFiClassReader_Dump(const char *Cmd) {
uint8_t MAC[4] = {0x00, 0x00, 0x00, 0x00};
uint8_t div_key[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
@ -1189,8 +1154,7 @@ int CmdHFiClassReader_Dump(const char *Cmd)
return 1;
}
static int WriteBlock(uint8_t blockno, uint8_t *bldata, uint8_t *KEY, bool use_credit_key, bool elite, bool rawkey, bool verbose)
{
static int WriteBlock(uint8_t blockno, uint8_t *bldata, uint8_t *KEY, bool use_credit_key, bool elite, bool rawkey, bool verbose) {
uint8_t MAC[4] = {0x00, 0x00, 0x00, 0x00};
uint8_t div_key[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
if (!select_and_auth(KEY, MAC, div_key, use_credit_key, elite, rawkey, verbose))
@ -1217,8 +1181,7 @@ static int WriteBlock(uint8_t blockno, uint8_t *bldata, uint8_t *KEY, bool use_c
return isOK;
}
int CmdHFiClass_WriteBlock(const char *Cmd)
{
int CmdHFiClass_WriteBlock(const char *Cmd) {
uint8_t blockno = 0;
uint8_t bldata[8] = {0, 0, 0, 0, 0, 0, 0, 0};
uint8_t KEY[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
@ -1296,8 +1259,7 @@ int CmdHFiClass_WriteBlock(const char *Cmd)
return ans;
}
int CmdHFiClassCloneTag(const char *Cmd)
{
int CmdHFiClassCloneTag(const char *Cmd) {
char filename[FILE_PATH_SIZE] = { 0x00 };
char tempStr[50] = {0};
uint8_t KEY[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
@ -1449,8 +1411,7 @@ int CmdHFiClassCloneTag(const char *Cmd)
return 1;
}
static int ReadBlock(uint8_t *KEY, uint8_t blockno, uint8_t keyType, bool elite, bool rawkey, bool verbose, bool auth)
{
static int ReadBlock(uint8_t *KEY, uint8_t blockno, uint8_t keyType, bool elite, bool rawkey, bool verbose, bool auth) {
uint8_t MAC[4] = {0x00, 0x00, 0x00, 0x00};
uint8_t div_key[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
@ -1484,8 +1445,7 @@ static int ReadBlock(uint8_t *KEY, uint8_t blockno, uint8_t keyType, bool elite,
return 1;
}
int CmdHFiClass_ReadBlock(const char *Cmd)
{
int CmdHFiClass_ReadBlock(const char *Cmd) {
uint8_t blockno = 0;
uint8_t keyType = 0x88; //debit key
uint8_t KEY[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
@ -1557,8 +1517,7 @@ int CmdHFiClass_ReadBlock(const char *Cmd)
return ReadBlock(KEY, blockno, keyType, elite, rawkey, verbose, auth);
}
int CmdHFiClass_loclass(const char *Cmd)
{
int CmdHFiClass_loclass(const char *Cmd) {
char opt = tolower(param_getchar(Cmd, 0));
if (strlen(Cmd) < 1 || opt == 'h')
@ -1583,8 +1542,7 @@ int CmdHFiClass_loclass(const char *Cmd)
return 0;
}
void printIclassDumpContents(uint8_t *iclass_dump, uint8_t startblock, uint8_t endblock, size_t filesize)
{
void printIclassDumpContents(uint8_t *iclass_dump, uint8_t startblock, uint8_t endblock, size_t filesize) {
uint8_t mem_config;
memcpy(&mem_config, iclass_dump + 13, 1);
uint8_t maxmemcount;
@ -1618,8 +1576,7 @@ void printIclassDumpContents(uint8_t *iclass_dump, uint8_t startblock, uint8_t e
PrintAndLogEx(NORMAL, "------+--+-------------------------+\n");
}
int CmdHFiClassReadTagFile(const char *Cmd)
{
int CmdHFiClassReadTagFile(const char *Cmd) {
int startblock = 0;
int endblock = 0;
char tempnum[5];
@ -1671,8 +1628,7 @@ int CmdHFiClassReadTagFile(const char *Cmd)
return 0;
}
void HFiClassCalcDivKey(uint8_t *CSN, uint8_t *KEY, uint8_t *div_key, bool elite)
{
void HFiClassCalcDivKey(uint8_t *CSN, uint8_t *KEY, uint8_t *div_key, bool elite) {
uint8_t keytable[128] = {0};
uint8_t key_index[8] = {0};
if (elite) {
@ -1694,8 +1650,7 @@ void HFiClassCalcDivKey(uint8_t *CSN, uint8_t *KEY, uint8_t *div_key, bool elite
//when told CSN, oldkey, newkey, if new key is elite (elite), and if old key was elite (oldElite)
//calculate and return xor_div_key (ready for a key write command)
//print all div_keys if verbose
static void HFiClassCalcNewKey(uint8_t *CSN, uint8_t *OLDKEY, uint8_t *NEWKEY, uint8_t *xor_div_key, bool elite, bool oldElite, bool verbose)
{
static void HFiClassCalcNewKey(uint8_t *CSN, uint8_t *OLDKEY, uint8_t *NEWKEY, uint8_t *xor_div_key, bool elite, bool oldElite, bool verbose) {
uint8_t old_div_key[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
uint8_t new_div_key[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
//get old div key
@ -1713,8 +1668,7 @@ static void HFiClassCalcNewKey(uint8_t *CSN, uint8_t *OLDKEY, uint8_t *NEWKEY, u
}
}
int CmdHFiClassCalcNewKey(const char *Cmd)
{
int CmdHFiClassCalcNewKey(const char *Cmd) {
uint8_t OLDKEY[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
uint8_t NEWKEY[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
uint8_t xor_div_key[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
@ -1797,8 +1751,7 @@ int CmdHFiClassCalcNewKey(const char *Cmd)
return 0;
}
static int loadKeys(char *filename)
{
static int loadKeys(char *filename) {
FILE *f;
f = fopen(filename, "rb");
if (!f) {
@ -1837,8 +1790,7 @@ static int loadKeys(char *filename)
return 1;
}
static int saveKeys(char *filename)
{
static int saveKeys(char *filename) {
FILE *f;
f = fopen(filename, "wb");
if (!f) {
@ -1855,8 +1807,7 @@ static int saveKeys(char *filename)
return 0;
}
static int printKeys(void)
{
static int printKeys(void) {
PrintAndLogEx(NORMAL, "");
for (uint8_t i = 0; i < ICLASS_KEYS_MAX; i++)
PrintAndLogEx(NORMAL, "%u: %s", i, sprint_hex(iClass_Key_Table[i], 8));
@ -1864,8 +1815,7 @@ static int printKeys(void)
return 0;
}
int CmdHFiClassManageKeys(const char *Cmd)
{
int CmdHFiClassManageKeys(const char *Cmd) {
uint8_t keyNbr = 0;
uint8_t dataLen = 0;
uint8_t KEY[8] = {0};
@ -1955,8 +1905,7 @@ int CmdHFiClassManageKeys(const char *Cmd)
return 0;
}
int CmdHFiClassCheckKeys(const char *Cmd)
{
int CmdHFiClassCheckKeys(const char *Cmd) {
// empty string
if (strlen(Cmd) == 0) return usage_hf_iclass_chk();
@ -2161,8 +2110,7 @@ out:
return 0;
}
static int cmp_uint32(const void *a, const void *b)
{
static int cmp_uint32(const void *a, const void *b) {
const iclass_prekey_t *x = (const iclass_prekey_t *)a;
const iclass_prekey_t *y = (const iclass_prekey_t *)b;
@ -2178,8 +2126,7 @@ static int cmp_uint32(const void *a, const void *b)
// this method tries to identify in which configuration mode a iClass / iClass SE reader is in.
// Standard or Elite / HighSecurity mode. It uses a default key dictionary list in order to work.
int CmdHFiClassLookUp(const char *Cmd)
{
int CmdHFiClassLookUp(const char *Cmd) {
uint8_t CSN[8];
uint8_t EPURSE[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
@ -2316,8 +2263,7 @@ int CmdHFiClassLookUp(const char *Cmd)
return 0;
}
int LoadDictionaryKeyFile(char *filename, uint8_t **keys, int *keycnt)
{
int LoadDictionaryKeyFile(char *filename, uint8_t **keys, int *keycnt) {
char buf[17];
FILE *f;
@ -2368,8 +2314,7 @@ int LoadDictionaryKeyFile(char *filename, uint8_t **keys, int *keycnt)
}
// precalc diversified keys and their MAC
int GenerateMacFromKeyFile(uint8_t *CSN, uint8_t *CCNR, bool use_raw, bool use_elite, uint8_t *keys, int keycnt, iclass_premac_t *list)
{
int GenerateMacFromKeyFile(uint8_t *CSN, uint8_t *CCNR, bool use_raw, bool use_elite, uint8_t *keys, int keycnt, iclass_premac_t *list) {
uint8_t key[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
uint8_t div_key[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
@ -2387,8 +2332,7 @@ int GenerateMacFromKeyFile(uint8_t *CSN, uint8_t *CCNR, bool use_raw, bool use_e
return 0;
}
int GenerateFromKeyFile(uint8_t *CSN, uint8_t *CCNR, bool use_raw, bool use_elite, uint8_t *keys, int keycnt, iclass_prekey_t *list)
{
int GenerateFromKeyFile(uint8_t *CSN, uint8_t *CCNR, bool use_raw, bool use_elite, uint8_t *keys, int keycnt, iclass_prekey_t *list) {
uint8_t div_key[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
@ -2409,8 +2353,7 @@ int GenerateFromKeyFile(uint8_t *CSN, uint8_t *CCNR, bool use_raw, bool use_elit
}
// print diversified keys
void PrintPreCalcMac(uint8_t *keys, int keycnt, iclass_premac_t *pre_list)
{
void PrintPreCalcMac(uint8_t *keys, int keycnt, iclass_premac_t *pre_list) {
iclass_prekey_t *b = calloc(keycnt, sizeof(iclass_prekey_t));
if (!b)
@ -2424,8 +2367,7 @@ void PrintPreCalcMac(uint8_t *keys, int keycnt, iclass_premac_t *pre_list)
free(b);
}
void PrintPreCalc(iclass_prekey_t *list, int itemcnt)
{
void PrintPreCalc(iclass_prekey_t *list, int itemcnt) {
PrintAndLogEx(NORMAL, "-----+------------------+---------");
PrintAndLogEx(NORMAL, "#key | key | mac");
PrintAndLogEx(NORMAL, "-----+------------------+---------");
@ -2439,8 +2381,7 @@ void PrintPreCalc(iclass_prekey_t *list, int itemcnt)
}
}
static void permute(uint8_t *data, uint8_t len, uint8_t *output)
{
static void permute(uint8_t *data, uint8_t len, uint8_t *output) {
#define KEY_SIZE 8
if (len > KEY_SIZE) {
@ -2465,14 +2406,12 @@ static void permute(uint8_t *data, uint8_t len, uint8_t *output)
output[i] = p;
}
}
static void permute_rev(uint8_t *data, uint8_t len, uint8_t *output)
{
static void permute_rev(uint8_t *data, uint8_t len, uint8_t *output) {
permute(data, len, output);
permute(output, len, data);
permute(data, len, output);
}
static void simple_crc(uint8_t *data, uint8_t len, uint8_t *output)
{
static void simple_crc(uint8_t *data, uint8_t len, uint8_t *output) {
uint8_t crc = 0;
for (uint8_t i = 0; i < len; ++i) {
// seventh byte contains the crc.
@ -2486,13 +2425,11 @@ static void simple_crc(uint8_t *data, uint8_t len, uint8_t *output)
}
}
// DES doesn't use the MSB.
static void shave(uint8_t *data, uint8_t len)
{
static void shave(uint8_t *data, uint8_t len) {
for (uint8_t i = 0; i < len; ++i)
data[i] &= 0xFE;
}
static void generate_rev(uint8_t *data, uint8_t len)
{
static void generate_rev(uint8_t *data, uint8_t len) {
uint8_t *key = calloc(len, sizeof(uint8_t));
PrintAndLogEx(SUCCESS, "input permuted key | %s \n", sprint_hex(data, len));
permute_rev(data, len, key);
@ -2501,8 +2438,7 @@ static void generate_rev(uint8_t *data, uint8_t len)
PrintAndLogEx(SUCCESS, " key | %s \n", sprint_hex(key, len));
free(key);
}
static void generate(uint8_t *data, uint8_t len)
{
static void generate(uint8_t *data, uint8_t len) {
uint8_t *key = calloc(len, sizeof(uint8_t));
uint8_t *pkey = calloc(len, sizeof(uint8_t));
PrintAndLogEx(SUCCESS, " input key | %s \n", sprint_hex(data, len));
@ -2514,8 +2450,7 @@ static void generate(uint8_t *data, uint8_t len)
free(pkey);
}
int CmdHFiClassPermuteKey(const char *Cmd)
{
int CmdHFiClassPermuteKey(const char *Cmd) {
uint8_t key[8] = {0};
uint8_t key_std_format[8] = {0};
@ -2571,15 +2506,13 @@ static command_t CommandTable[] = {
{NULL, NULL, 0, NULL}
};
int CmdHFiClass(const char *Cmd)
{
int CmdHFiClass(const char *Cmd) {
clearCommandBuffer();
CmdsParse(CommandTable, Cmd);
return 0;
}
int CmdHelp(const char *Cmd)
{
int CmdHelp(const char *Cmd) {
CmdsHelp(CommandTable);
return 0;
}

View file

@ -13,8 +13,7 @@ static int CmdHelp(const char *Cmd);
#define MAX_LENGTH 1024
int usage_legic_calccrc(void)
{
int usage_legic_calccrc(void) {
PrintAndLogEx(NORMAL, "Calculates the legic crc8/crc16 on the given data.");
PrintAndLogEx(NORMAL, "There must be an even number of hexsymbols as input.");
PrintAndLogEx(NORMAL, "Usage: hf legic crc [h] d <data> u <uidcrc> c <8|16>");
@ -29,8 +28,7 @@ int usage_legic_calccrc(void)
PrintAndLogEx(NORMAL, " hf legic crc d deadbeef1122 u 9A c 16");
return 0;
}
int usage_legic_rdmem(void)
{
int usage_legic_rdmem(void) {
PrintAndLogEx(NORMAL, "Read data from a legic tag.");
PrintAndLogEx(NORMAL, "Usage: hf legic rdmem [h] <offset> <length> <IV>");
PrintAndLogEx(NORMAL, "Options:");
@ -45,8 +43,7 @@ int usage_legic_rdmem(void)
PrintAndLogEx(NORMAL, " hf legic rdmem 0 100 55 - reads 0x100 bytes with IV 0x55");
return 0;
}
int usage_legic_sim(void)
{
int usage_legic_sim(void) {
PrintAndLogEx(NORMAL, "Simulates a LEGIC Prime tag. MIM22, MIM256, MIM1024 types can be emulated");
PrintAndLogEx(NORMAL, "Use ELOAD/ESAVE to upload a dump into emulator memory");
PrintAndLogEx(NORMAL, "Usage: hf legic sim [h] <tagtype>");
@ -60,8 +57,7 @@ int usage_legic_sim(void)
PrintAndLogEx(NORMAL, " hf legic sim 2");
return 0;
}
int usage_legic_write(void)
{
int usage_legic_write(void) {
PrintAndLogEx(NORMAL, "Write data to a LEGIC Prime tag. It autodetects tagsize to make sure size");
PrintAndLogEx(NORMAL, "Usage: hf legic write [h] o <offset> d <data (hex symbols)>");
PrintAndLogEx(NORMAL, "Options:");
@ -74,8 +70,7 @@ int usage_legic_write(void)
PrintAndLogEx(NORMAL, " hf legic write o 10 d 11223344 - Write 0x11223344 starting from offset 0x10");
return 0;
}
int usage_legic_reader(void)
{
int usage_legic_reader(void) {
PrintAndLogEx(NORMAL, "Read UID and type information from a legic tag.");
PrintAndLogEx(NORMAL, "Usage: hf legic reader [h]");
PrintAndLogEx(NORMAL, "Options:");
@ -85,8 +80,7 @@ int usage_legic_reader(void)
PrintAndLogEx(NORMAL, " hf legic reader");
return 0;
}
int usage_legic_info(void)
{
int usage_legic_info(void) {
PrintAndLogEx(NORMAL, "Reads information from a legic prime tag.");
PrintAndLogEx(NORMAL, "Shows systemarea, user areas etc");
PrintAndLogEx(NORMAL, "Usage: hf legic info [h]");
@ -97,8 +91,7 @@ int usage_legic_info(void)
PrintAndLogEx(NORMAL, " hf legic info");
return 0;
}
int usage_legic_dump(void)
{
int usage_legic_dump(void) {
PrintAndLogEx(NORMAL, "Reads all pages from LEGIC Prime MIM22, MIM256, MIM1024");
PrintAndLogEx(NORMAL, "and saves binary dump into the file `filename.bin` or `cardUID.bin`");
PrintAndLogEx(NORMAL, "It autodetects card type.\n");
@ -112,8 +105,7 @@ int usage_legic_dump(void)
PrintAndLogEx(NORMAL, " hf legic dump o myfile");
return 0;
}
int usage_legic_restore(void)
{
int usage_legic_restore(void) {
PrintAndLogEx(NORMAL, "Reads binary file and it autodetects card type and verifies that the file has the same size");
PrintAndLogEx(NORMAL, "Then write the data back to card. All bytes except the first 7bytes [UID(4) MCC(1) DCF(2)]\n");
PrintAndLogEx(NORMAL, "Usage: hf legic restore [h] i <filename w/o .bin>");
@ -125,8 +117,7 @@ int usage_legic_restore(void)
PrintAndLogEx(NORMAL, " hf legic restore i myfile");
return 0;
}
int usage_legic_eload(void)
{
int usage_legic_eload(void) {
PrintAndLogEx(NORMAL, "It loads binary dump from the file `filename.bin`");
PrintAndLogEx(NORMAL, "Usage: hf legic eload [h] [card memory] <file name w/o `.bin`>");
PrintAndLogEx(NORMAL, "Options:");
@ -140,8 +131,7 @@ int usage_legic_eload(void)
PrintAndLogEx(NORMAL, " hf legic eload 2 myfile");
return 0;
}
int usage_legic_esave(void)
{
int usage_legic_esave(void) {
PrintAndLogEx(NORMAL, "It saves binary dump into the file `filename.bin` or `cardID.bin`");
PrintAndLogEx(NORMAL, " Usage: hf legic esave [h] [card memory] [file name w/o `.bin`]");
PrintAndLogEx(NORMAL, "Options:");
@ -155,8 +145,7 @@ int usage_legic_esave(void)
PrintAndLogEx(NORMAL, " hf legic esave 2 myfile");
return 0;
}
int usage_legic_wipe(void)
{
int usage_legic_wipe(void) {
PrintAndLogEx(NORMAL, "Fills a legic tag memory with zeros. From byte7 and to the end.");
PrintAndLogEx(NORMAL, " Usage: hf legic wipe [h]");
PrintAndLogEx(NORMAL, "Options:");
@ -171,8 +160,7 @@ int usage_legic_wipe(void)
* This is based on information given in the talk held
* by Henryk Ploetz and Karsten Nohl at 26c3
*/
int CmdLegicInfo(const char *Cmd)
{
int CmdLegicInfo(const char *Cmd) {
char cmdp = tolower(param_getchar(Cmd, 0));
if (cmdp == 'h') return usage_legic_info();
@ -481,8 +469,7 @@ out:
// params:
// offset in data memory
// number of bytes to read
int CmdLegicRdmem(const char *Cmd)
{
int CmdLegicRdmem(const char *Cmd) {
char cmdp = tolower(param_getchar(Cmd, 0));
if (cmdp == 'h') return usage_legic_rdmem();
@ -516,8 +503,7 @@ int CmdLegicRdmem(const char *Cmd)
return status;
}
int CmdLegicRfSim(const char *Cmd)
{
int CmdLegicRfSim(const char *Cmd) {
char cmdp = tolower(param_getchar(Cmd, 0));
if (strlen(Cmd) == 0 || cmdp == 'h') return usage_legic_sim();
@ -529,8 +515,7 @@ int CmdLegicRfSim(const char *Cmd)
return 0;
}
int CmdLegicRfWrite(const char *Cmd)
{
int CmdLegicRfWrite(const char *Cmd) {
uint8_t *data = NULL;
uint8_t cmdp = 0;
@ -670,8 +655,7 @@ int CmdLegicRfWrite(const char *Cmd)
return 0;
}
int CmdLegicCalcCrc(const char *Cmd)
{
int CmdLegicCalcCrc(const char *Cmd) {
uint8_t *data = NULL;
uint8_t cmdp = 0, uidcrc = 0, type = 0;
@ -753,8 +737,7 @@ int CmdLegicCalcCrc(const char *Cmd)
return 0;
}
int legic_read_mem(uint32_t offset, uint32_t len, uint32_t iv, uint8_t *out, uint16_t *outlen)
{
int legic_read_mem(uint32_t offset, uint32_t len, uint32_t iv, uint8_t *out, uint16_t *outlen) {
legic_chk_iv(&iv);
@ -793,8 +776,7 @@ int legic_read_mem(uint32_t offset, uint32_t len, uint32_t iv, uint8_t *out, uin
return 0;
}
int legic_print_type(uint32_t tagtype, uint8_t spaces)
{
int legic_print_type(uint32_t tagtype, uint8_t spaces) {
char spc[11] = " ";
spc[10] = 0x00;
char *spacer = spc + (10 - spaces);
@ -809,8 +791,7 @@ int legic_print_type(uint32_t tagtype, uint8_t spaces)
PrintAndLogEx(INFO, "%sTYPE : Unknown %06x", spacer, tagtype);
return 0;
}
int legic_get_type(legic_card_select_t *card)
{
int legic_get_type(legic_card_select_t *card) {
if (card == NULL) return 1;
@ -828,8 +809,7 @@ int legic_get_type(legic_card_select_t *card)
memcpy(card, (legic_card_select_t *)resp.d.asBytes, sizeof(legic_card_select_t));
return 0;
}
void legic_chk_iv(uint32_t *iv)
{
void legic_chk_iv(uint32_t *iv) {
if ((*iv & 0x7F) != *iv) {
*iv &= 0x7F;
PrintAndLogEx(INFO, "Truncating IV to 7bits, %u", *iv);
@ -840,8 +820,7 @@ void legic_chk_iv(uint32_t *iv)
PrintAndLogEx(INFO, "LSB of IV must be SET %u", *iv);
}
}
void legic_seteml(uint8_t *src, uint32_t offset, uint32_t numofbytes)
{
void legic_seteml(uint8_t *src, uint32_t offset, uint32_t numofbytes) {
size_t len = 0;
UsbCommand c = {CMD_LEGIC_ESET, {0, 0, 0}};
@ -856,8 +835,7 @@ void legic_seteml(uint8_t *src, uint32_t offset, uint32_t numofbytes)
}
}
int HFLegicReader(const char *Cmd, bool verbose)
{
int HFLegicReader(const char *Cmd, bool verbose) {
char cmdp = tolower(param_getchar(Cmd, 0));
if (cmdp == 'h') return usage_legic_reader();
@ -879,13 +857,11 @@ int HFLegicReader(const char *Cmd, bool verbose)
legic_print_type(card.cardsize, 0);
return 0;
}
int CmdLegicReader(const char *Cmd)
{
int CmdLegicReader(const char *Cmd) {
return HFLegicReader(Cmd, true);
}
int CmdLegicDump(const char *Cmd)
{
int CmdLegicDump(const char *Cmd) {
FILE *f;
char filename[FILE_PATH_SIZE] = {0x00};
@ -990,8 +966,7 @@ int CmdLegicDump(const char *Cmd)
return 0;
}
int CmdLegicRestore(const char *Cmd)
{
int CmdLegicRestore(const char *Cmd) {
FILE *f;
char filename[FILE_PATH_SIZE] = {0x00};
@ -1118,8 +1093,7 @@ int CmdLegicRestore(const char *Cmd)
return 0;
}
int CmdLegicELoad(const char *Cmd)
{
int CmdLegicELoad(const char *Cmd) {
FILE *f;
char filename[FILE_PATH_SIZE];
char *fnameptr = filename;
@ -1189,8 +1163,7 @@ int CmdLegicELoad(const char *Cmd)
return 0;
}
int CmdLegicESave(const char *Cmd)
{
int CmdLegicESave(const char *Cmd) {
char filename[FILE_PATH_SIZE];
char *fnameptr = filename;
@ -1250,8 +1223,7 @@ int CmdLegicESave(const char *Cmd)
return 0;
}
int CmdLegicWipe(const char *Cmd)
{
int CmdLegicWipe(const char *Cmd) {
char cmdp = tolower(param_getchar(Cmd, 0));
@ -1314,8 +1286,7 @@ int CmdLegicWipe(const char *Cmd)
return 0;
}
int CmdLegicList(const char *Cmd)
{
int CmdLegicList(const char *Cmd) {
CmdTraceList("legic");
return 0;
}
@ -1337,15 +1308,13 @@ static command_t CommandTable[] = {
{NULL, NULL, 0, NULL}
};
int CmdHFLegic(const char *Cmd)
{
int CmdHFLegic(const char *Cmd) {
clearCommandBuffer();
CmdsParse(CommandTable, Cmd);
return 0;
}
int CmdHelp(const char *Cmd)
{
int CmdHelp(const char *Cmd) {
CmdsHelp(CommandTable);
return 0;
}

View file

@ -24,8 +24,7 @@ enum MifareAuthSeq {
static enum MifareAuthSeq MifareAuthState;
static TAuthData AuthData;
void ClearAuthData()
{
void ClearAuthData() {
AuthData.uid = 0;
AuthData.nt = 0;
AuthData.first_auth = true;
@ -43,15 +42,13 @@ void ClearAuthData()
* 2 : Not crc-command
*/
uint8_t iso14443A_CRC_check(bool isResponse, uint8_t *d, uint8_t n)
{
uint8_t iso14443A_CRC_check(bool isResponse, uint8_t *d, uint8_t n) {
if (n < 3) return 2;
if (isResponse & (n < 6)) return 2;
return check_crc(CRC_14443_A, d, n);
}
uint8_t mifare_CRC_check(bool isResponse, uint8_t *data, uint8_t len)
{
uint8_t mifare_CRC_check(bool isResponse, uint8_t *data, uint8_t len) {
switch (MifareAuthState) {
case masNone:
case masError:
@ -69,13 +66,11 @@ uint8_t mifare_CRC_check(bool isResponse, uint8_t *data, uint8_t len)
* 1 : CRC-command, CRC ok
* 2 : Not crc-command
*/
uint8_t iso14443B_CRC_check(uint8_t *d, uint8_t n)
{
uint8_t iso14443B_CRC_check(uint8_t *d, uint8_t n) {
return check_crc(CRC_14443_B, d, n);
}
uint8_t iso15693_CRC_check(uint8_t *d, uint8_t n)
{
uint8_t iso15693_CRC_check(uint8_t *d, uint8_t n) {
return check_crc(CRC_15693, d, n);
}
@ -88,8 +83,7 @@ uint8_t iso15693_CRC_check(uint8_t *d, uint8_t n)
* 1 : CRC-command, CRC ok
* 2 : Not crc-command
*/
uint8_t iclass_CRC_check(bool isResponse, uint8_t *d, uint8_t n)
{
uint8_t iclass_CRC_check(bool isResponse, uint8_t *d, uint8_t n) {
//CRC commands (and responses) are all at least 4 bytes
if (n < 4) return 2;
@ -136,8 +130,7 @@ uint8_t iclass_CRC_check(bool isResponse, uint8_t *d, uint8_t n)
return check_crc(CRC_ICLASS, d, n);
}
int applyIso14443a(char *exp, size_t size, uint8_t *cmd, uint8_t cmdsize)
{
int applyIso14443a(char *exp, size_t size, uint8_t *cmd, uint8_t cmdsize) {
switch (cmd[0]) {
case ISO14443A_CMD_WUPA:
snprintf(exp, size, "WUPA");
@ -272,13 +265,11 @@ int applyIso14443a(char *exp, size_t size, uint8_t *cmd, uint8_t cmdsize)
return 1;
}
void annotateIso14443a(char *exp, size_t size, uint8_t *cmd, uint8_t cmdsize)
{
void annotateIso14443a(char *exp, size_t size, uint8_t *cmd, uint8_t cmdsize) {
applyIso14443a(exp, size, cmd, cmdsize);
}
void annotateIclass(char *exp, size_t size, uint8_t *cmd, uint8_t cmdsize)
{
void annotateIclass(char *exp, size_t size, uint8_t *cmd, uint8_t cmdsize) {
switch (cmd[0]) {
case ICLASS_CMD_ACTALL:
snprintf(exp, size, "ACTALL");
@ -328,8 +319,7 @@ void annotateIclass(char *exp, size_t size, uint8_t *cmd, uint8_t cmdsize)
return;
}
void annotateIso15693(char *exp, size_t size, uint8_t *cmd, uint8_t cmdsize)
{
void annotateIso15693(char *exp, size_t size, uint8_t *cmd, uint8_t cmdsize) {
switch (cmd[1]) {
case ISO15693_INVENTORY:
@ -385,8 +375,7 @@ void annotateIso15693(char *exp, size_t size, uint8_t *cmd, uint8_t cmdsize)
snprintf(exp, size, "?");
}
void annotateTopaz(char *exp, size_t size, uint8_t *cmd, uint8_t cmdsize)
{
void annotateTopaz(char *exp, size_t size, uint8_t *cmd, uint8_t cmdsize) {
switch (cmd[0]) {
case TOPAZ_REQA:
snprintf(exp, size, "REQA");
@ -428,8 +417,7 @@ void annotateTopaz(char *exp, size_t size, uint8_t *cmd, uint8_t cmdsize)
}
// iso 7816-3
void annotateIso7816(char *exp, size_t size, uint8_t *cmd, uint8_t cmdsize)
{
void annotateIso7816(char *exp, size_t size, uint8_t *cmd, uint8_t cmdsize) {
// S-block
if ((cmd[0] & 0xC0) && (cmdsize == 3)) {
switch ((cmd[0] & 0x3f)) {
@ -544,8 +532,7 @@ void annotateIso7816(char *exp, size_t size, uint8_t *cmd, uint8_t cmdsize)
}
// MIFARE DESFire
void annotateMfDesfire(char *exp, size_t size, uint8_t *cmd, uint8_t cmdsize)
{
void annotateMfDesfire(char *exp, size_t size, uint8_t *cmd, uint8_t cmdsize) {
// it's basically a ISO14443a tag, so try annotation from there
if (!applyIso14443a(exp, size, cmd, cmdsize)) {
@ -707,8 +694,7 @@ void annotateMfDesfire(char *exp, size_t size, uint8_t *cmd, uint8_t cmdsize)
0F = Completion
0A 11 22 33 44 55 66 = Authenticate (11 22 33 44 55 66 = data to authenticate)
**/
void annotateIso14443b(char *exp, size_t size, uint8_t *cmd, uint8_t cmdsize)
{
void annotateIso14443b(char *exp, size_t size, uint8_t *cmd, uint8_t cmdsize) {
switch (cmd[0]) {
case ISO14443B_REQB : {
@ -781,8 +767,7 @@ void annotateIso14443b(char *exp, size_t size, uint8_t *cmd, uint8_t cmdsize)
// 1 = read
// 0 = write
// Quite simpel tag
void annotateLegic(char *exp, size_t size, uint8_t *cmd, uint8_t cmdsize)
{
void annotateLegic(char *exp, size_t size, uint8_t *cmd, uint8_t cmdsize) {
uint8_t bitsend = cmd[0];
uint8_t cmdBit = (cmd[1] & 1);
switch (bitsend) {
@ -843,8 +828,7 @@ void annotateLegic(char *exp, size_t size, uint8_t *cmd, uint8_t cmdsize)
}
}
void annotateFelica(char *exp, size_t size, uint8_t *cmd, uint8_t cmdsize)
{
void annotateFelica(char *exp, size_t size, uint8_t *cmd, uint8_t cmdsize) {
switch (cmd[0]) {
case FELICA_POLL_REQ:
@ -973,8 +957,7 @@ void annotateFelica(char *exp, size_t size, uint8_t *cmd, uint8_t cmdsize)
}
}
void annotateMifare(char *exp, size_t size, uint8_t *cmd, uint8_t cmdsize, uint8_t *parity, uint8_t paritysize, bool isResponse)
{
void annotateMifare(char *exp, size_t size, uint8_t *cmd, uint8_t cmdsize, uint8_t *parity, uint8_t paritysize, bool isResponse) {
if (!isResponse && cmdsize == 1) {
switch (cmd[0]) {
case ISO14443A_CMD_WUPA:
@ -1050,8 +1033,7 @@ void annotateMifare(char *exp, size_t size, uint8_t *cmd, uint8_t cmdsize, uint8
}
bool DecodeMifareData(uint8_t *cmd, uint8_t cmdsize, uint8_t *parity, bool isResponse, uint8_t *mfData, size_t *mfDataLen)
{
bool DecodeMifareData(uint8_t *cmd, uint8_t cmdsize, uint8_t *parity, bool isResponse, uint8_t *mfData, size_t *mfDataLen) {
static struct Crypto1State *traceCrypto1;
static uint64_t mfLastKey;
@ -1183,8 +1165,7 @@ bool DecodeMifareData(uint8_t *cmd, uint8_t cmdsize, uint8_t *parity, bool isRes
return *mfDataLen > 0;
}
bool NTParityChk(TAuthData *ad, uint32_t ntx)
{
bool NTParityChk(TAuthData *ad, uint32_t ntx) {
if (
(oddparity8(ntx >> 8 & 0xff) ^ (ntx & 0x01) ^ ((ad->nt_enc_par >> 5) & 0x01) ^ (ad->nt_enc & 0x01)) ||
(oddparity8(ntx >> 16 & 0xff) ^ (ntx >> 8 & 0x01) ^ ((ad->nt_enc_par >> 6) & 0x01) ^ (ad->nt_enc >> 8 & 0x01)) ||
@ -1212,8 +1193,7 @@ bool NTParityChk(TAuthData *ad, uint32_t ntx)
return true;
}
bool NestedCheckKey(uint64_t key, TAuthData *ad, uint8_t *cmd, uint8_t cmdsize, uint8_t *parity)
{
bool NestedCheckKey(uint64_t key, TAuthData *ad, uint8_t *cmd, uint8_t cmdsize, uint8_t *parity) {
uint8_t buf[32] = {0};
struct Crypto1State *pcs;
@ -1251,8 +1231,7 @@ bool NestedCheckKey(uint64_t key, TAuthData *ad, uint8_t *cmd, uint8_t cmdsize,
return true;
}
bool CheckCrypto1Parity(uint8_t *cmd_enc, uint8_t cmdsize, uint8_t *cmd, uint8_t *parity_enc)
{
bool CheckCrypto1Parity(uint8_t *cmd_enc, uint8_t cmdsize, uint8_t *cmd, uint8_t *parity_enc) {
for (int i = 0; i < cmdsize - 1; i++) {
if (oddparity8(cmd[i]) ^ (cmd[i + 1] & 0x01) ^ ((parity_enc[i / 8] >> (7 - i % 8)) & 0x01) ^ (cmd_enc[i + 1] & 0x01))
return false;
@ -1262,8 +1241,7 @@ bool CheckCrypto1Parity(uint8_t *cmd_enc, uint8_t cmdsize, uint8_t *cmd, uint8_t
// Another implementation of mfkey64 attack, more "valid" than "probable"
//
uint64_t GetCrypto1ProbableKey(TAuthData *ad)
{
uint64_t GetCrypto1ProbableKey(TAuthData *ad) {
struct Crypto1State *revstate = lfsr_recovery64(ad->ks2, ad->ks3);
lfsr_rollback_word(revstate, 0, 0);
lfsr_rollback_word(revstate, 0, 0);

View file

@ -28,8 +28,7 @@
static int CmdHelp(const char *Cmd);
int usage_hf14_ice(void)
{
int usage_hf14_ice(void) {
PrintAndLogEx(NORMAL, "Usage: hf mf ice [l] <limit> [f] <name>");
PrintAndLogEx(NORMAL, " h this help");
PrintAndLogEx(NORMAL, " l <limit> nonces to be collected");
@ -41,8 +40,7 @@ int usage_hf14_ice(void)
return 0;
}
int usage_hf14_dump(void)
{
int usage_hf14_dump(void) {
PrintAndLogEx(NORMAL, "Usage: hf mf dump [card memory] k <name> f <name>");
PrintAndLogEx(NORMAL, " [card memory]: 0 = 320 bytes (Mifare Mini), 1 = 1K (default), 2 = 2K, 4 = 4K");
PrintAndLogEx(NORMAL, " k <name> : key filename, if no <name> given, UID will be used as filename");
@ -54,8 +52,7 @@ int usage_hf14_dump(void)
return 0;
}
int usage_hf14_mifare(void)
{
int usage_hf14_mifare(void) {
PrintAndLogEx(NORMAL, "Usage: hf mf darkside [h] <block number> <A|B>");
PrintAndLogEx(NORMAL, "Options:");
PrintAndLogEx(NORMAL, " h this help");
@ -67,8 +64,7 @@ int usage_hf14_mifare(void)
PrintAndLogEx(NORMAL, " hf mf darkside 16 B");
return 0;
}
int usage_hf14_mf1ksim(void)
{
int usage_hf14_mf1ksim(void) {
PrintAndLogEx(NORMAL, "Usage: hf mf sim [h] u <uid> n <numreads> [i] [x] [e] [v]");
PrintAndLogEx(NORMAL, "Options:");
PrintAndLogEx(NORMAL, " h this help");
@ -85,8 +81,7 @@ int usage_hf14_mf1ksim(void)
PrintAndLogEx(NORMAL, " hf mf sim u 11223344 i x");
return 0;
}
int usage_hf14_dbg(void)
{
int usage_hf14_dbg(void) {
PrintAndLogEx(NORMAL, "Usage: hf mf dbg [h] <debug level>");
PrintAndLogEx(NORMAL, "Options:");
PrintAndLogEx(NORMAL, " h this help");
@ -101,8 +96,7 @@ int usage_hf14_dbg(void)
PrintAndLogEx(NORMAL, " hf mf dbg 3");
return 0;
}
int usage_hf14_sniff(void)
{
int usage_hf14_sniff(void) {
PrintAndLogEx(NORMAL, "It continuously gets data from the field and saves it to: log, emulator, emulator file.");
PrintAndLogEx(NORMAL, "Usage: hf mf sniff [h] [l] [d] [f]");
PrintAndLogEx(NORMAL, "Options:");
@ -115,8 +109,7 @@ int usage_hf14_sniff(void)
PrintAndLogEx(NORMAL, " hf mf sniff l d f");
return 0;
}
int usage_hf14_nested(void)
{
int usage_hf14_nested(void) {
PrintAndLogEx(NORMAL, "Usage:");
PrintAndLogEx(NORMAL, " all sectors: hf mf nested <card memory> <block number> <key A/B> <key (12 hex symbols)> [t,d]");
PrintAndLogEx(NORMAL, " one sector: hf mf nested o <block number> <key A/B> <key (12 hex symbols)>");
@ -134,8 +127,7 @@ int usage_hf14_nested(void)
PrintAndLogEx(NORMAL, " hf mf nested o 0 A FFFFFFFFFFFF 4 A");
return 0;
}
int usage_hf14_hardnested(void)
{
int usage_hf14_hardnested(void) {
PrintAndLogEx(NORMAL, "Usage:");
PrintAndLogEx(NORMAL, " hf mf hardnested <block number> <key A|B> <key (12 hex symbols)>");
PrintAndLogEx(NORMAL, " <target block number> <target key A|B> [known target key (12 hex symbols)] [w] [s]");
@ -168,8 +160,7 @@ int usage_hf14_hardnested(void)
PrintAndLogEx(NORMAL, " hf mf hardnested 0 A A0A1A2A3A4A5 4 A FFFFFFFFFFFF");
return 0;
}
int usage_hf14_chk(void)
{
int usage_hf14_chk(void) {
PrintAndLogEx(NORMAL, "Usage: hf mf chk [h] <block number>|<*card memory> <key type (A/B/?)> [t|d] [<key (12 hex symbols)>] [<dic (*.dic)>]");
PrintAndLogEx(NORMAL, "Options:");
PrintAndLogEx(NORMAL, " h this help");
@ -187,8 +178,7 @@ int usage_hf14_chk(void)
PrintAndLogEx(NORMAL, " hf mf chk *1 ? d -- target all blocks, all keys, 1K, write to file");
return 0;
}
int usage_hf14_chk_fast(void)
{
int usage_hf14_chk_fast(void) {
PrintAndLogEx(NORMAL, "This is a improved checkkeys method speedwise. It checks Mifare Classic tags sector keys against a dictionary file with keys");
PrintAndLogEx(NORMAL, "Usage: hf mf fchk [h] <card memory> [t|d|f] [<key (12 hex symbols)>] [<dic (*.dic)>]");
PrintAndLogEx(NORMAL, "Options:");
@ -211,8 +201,7 @@ int usage_hf14_chk_fast(void)
#endif
return 0;
}
int usage_hf14_keybrute(void)
{
int usage_hf14_keybrute(void) {
PrintAndLogEx(NORMAL, "J_Run's 2nd phase of multiple sector nested authentication key recovery");
PrintAndLogEx(NORMAL, "You have a known 4 last bytes of a key recovered with mf_nonce_brute tool.");
PrintAndLogEx(NORMAL, "First 2 bytes of key will be bruteforced");
@ -229,8 +218,7 @@ int usage_hf14_keybrute(void)
PrintAndLogEx(NORMAL, " hf mf keybrute 1 A 000011223344");
return 0;
}
int usage_hf14_restore(void)
{
int usage_hf14_restore(void) {
PrintAndLogEx(NORMAL, "Usage: hf mf restore [card memory] u <UID> k <name> f <name>");
PrintAndLogEx(NORMAL, "Options:");
PrintAndLogEx(NORMAL, " [card memory]: 0 = 320 bytes (Mifare Mini), 1 = 1K (default), 2 = 2K, 4 = 4K");
@ -245,8 +233,7 @@ int usage_hf14_restore(void)
PrintAndLogEx(NORMAL, " hf mf restore 4 -- read the UID from tag with 4K memory first, then restore from hf-mf-<UID>-key.bin and and hf-mf-<UID>-data.bin");
return 0;
}
int usage_hf14_decryptbytes(void)
{
int usage_hf14_decryptbytes(void) {
PrintAndLogEx(NORMAL, "Decrypt Crypto-1 encrypted bytes given some known state of crypto. See tracelog to gather needed values\n");
PrintAndLogEx(NORMAL, "Usage: hf mf decrypt [h] <nt> <ar_enc> <at_enc> <data>");
PrintAndLogEx(NORMAL, "Options:");
@ -261,28 +248,24 @@ int usage_hf14_decryptbytes(void)
return 0;
}
int usage_hf14_eget(void)
{
int usage_hf14_eget(void) {
PrintAndLogEx(NORMAL, "Usage: hf mf eget <block number>");
PrintAndLogEx(NORMAL, "Examples:");
PrintAndLogEx(NORMAL, " hf mf eget 0 ");
return 0;
}
int usage_hf14_eclr(void)
{
int usage_hf14_eclr(void) {
PrintAndLogEx(NORMAL, "It set card emulator memory to empty data blocks and key A/B FFFFFFFFFFFF \n");
PrintAndLogEx(NORMAL, "Usage: hf mf eclr");
return 0;
}
int usage_hf14_eset(void)
{
int usage_hf14_eset(void) {
PrintAndLogEx(NORMAL, "Usage: hf mf eset <block number> <block data (32 hex symbols)>");
PrintAndLogEx(NORMAL, "Examples:");
PrintAndLogEx(NORMAL, " hf mf eset 1 000102030405060708090a0b0c0d0e0f ");
return 0;
}
int usage_hf14_eload(void)
{
int usage_hf14_eload(void) {
PrintAndLogEx(NORMAL, "It loads emul dump from the file `filename.eml`");
PrintAndLogEx(NORMAL, "Usage: hf mf eload [card memory] <file name w/o `.eml`> [numblocks]");
PrintAndLogEx(NORMAL, " [card memory]: 0 = 320 bytes (Mifare Mini), 1 = 1K (default), 2 = 2K, 4 = 4K, u = UL");
@ -292,8 +275,7 @@ int usage_hf14_eload(void)
PrintAndLogEx(NORMAL, " hf mf eload 4 filename");
return 0;
}
int usage_hf14_esave(void)
{
int usage_hf14_esave(void) {
PrintAndLogEx(NORMAL, "It saves emul dump into the file `filename.eml` or `cardID.eml`");
PrintAndLogEx(NORMAL, " Usage: hf mf esave [card memory] [file name w/o `.eml`]");
PrintAndLogEx(NORMAL, " [card memory]: 0 = 320 bytes (Mifare Mini), 1 = 1K (default), 2 = 2K, 4 = 4K");
@ -304,8 +286,7 @@ int usage_hf14_esave(void)
PrintAndLogEx(NORMAL, " hf mf esave 4 filename");
return 0;
}
int usage_hf14_ecfill(void)
{
int usage_hf14_ecfill(void) {
PrintAndLogEx(NORMAL, "Read card and transfer its data to emulator memory.");
PrintAndLogEx(NORMAL, "Keys must be laid in the emulator memory. \n");
PrintAndLogEx(NORMAL, "Usage: hf mf ecfill <key A/B> [card memory]");
@ -316,8 +297,7 @@ int usage_hf14_ecfill(void)
PrintAndLogEx(NORMAL, " hf mf ecfill A 4");
return 0;
}
int usage_hf14_ekeyprn(void)
{
int usage_hf14_ekeyprn(void) {
PrintAndLogEx(NORMAL, "It prints the keys loaded in the emulator memory");
PrintAndLogEx(NORMAL, "Usage: hf mf ekeyprn [card memory]");
PrintAndLogEx(NORMAL, " [card memory]: 0 = 320 bytes (Mifare Mini), 1 = 1K (default), 2 = 2K, 4 = 4K");
@ -327,8 +307,7 @@ int usage_hf14_ekeyprn(void)
return 0;
}
int usage_hf14_csetuid(void)
{
int usage_hf14_csetuid(void) {
PrintAndLogEx(NORMAL, "Set UID, ATQA, and SAK for magic Chinese card. Only works with magic cards");
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(NORMAL, "Usage: hf mf csetuid [h] <UID 8 hex symbols> [ATQA 4 hex symbols] [SAK 2 hex symbols] [w]");
@ -343,8 +322,7 @@ int usage_hf14_csetuid(void)
PrintAndLogEx(NORMAL, " hf mf csetuid 01020304 0004 08 w");
return 0;
}
int usage_hf14_csetblk(void)
{
int usage_hf14_csetblk(void) {
PrintAndLogEx(NORMAL, "Set block data for magic Chinese card. Only works with magic cards");
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(NORMAL, "Usage: hf mf csetblk [h] <block number> <block data (32 hex symbols)> [w]");
@ -358,8 +336,7 @@ int usage_hf14_csetblk(void)
PrintAndLogEx(NORMAL, " hf mf csetblk 1 01020304050607080910111213141516 w");
return 0;
}
int usage_hf14_cload(void)
{
int usage_hf14_cload(void) {
PrintAndLogEx(NORMAL, "It loads magic Chinese card from the file `filename.eml`");
PrintAndLogEx(NORMAL, "or from emulator memory");
PrintAndLogEx(NORMAL, "");
@ -375,8 +352,7 @@ int usage_hf14_cload(void)
PrintAndLogEx(NORMAL, " hf mf cload e");
return 0;
}
int usage_hf14_cgetblk(void)
{
int usage_hf14_cgetblk(void) {
PrintAndLogEx(NORMAL, "Get block data from magic Chinese card. Only works with magic cards\n");
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(NORMAL, "Usage: hf mf cgetblk [h] <block number>");
@ -387,8 +363,7 @@ int usage_hf14_cgetblk(void)
PrintAndLogEx(NORMAL, " hf mf cgetblk 1");
return 0;
}
int usage_hf14_cgetsc(void)
{
int usage_hf14_cgetsc(void) {
PrintAndLogEx(NORMAL, "Get sector data from magic Chinese card. Only works with magic cards\n");
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(NORMAL, "Usage: hf mf cgetsc [h] <sector number>");
@ -399,8 +374,7 @@ int usage_hf14_cgetsc(void)
PrintAndLogEx(NORMAL, " hf mf cgetsc 0");
return 0;
}
int usage_hf14_csave(void)
{
int usage_hf14_csave(void) {
PrintAndLogEx(NORMAL, "It saves `magic Chinese` card dump into the file `filename.eml` or `cardID.eml`");
PrintAndLogEx(NORMAL, "or into emulator memory");
PrintAndLogEx(NORMAL, "");
@ -418,8 +392,7 @@ int usage_hf14_csave(void)
PrintAndLogEx(NORMAL, " hf mf csave 4 o filename");
return 0;
}
int usage_hf14_nack(void)
{
int usage_hf14_nack(void) {
PrintAndLogEx(NORMAL, "Test a mifare classic based card for the NACK bug.");
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(NORMAL, "Usage: hf mf nack [h] [v]");
@ -431,8 +404,7 @@ int usage_hf14_nack(void)
return 0;
}
int GetHFMF14AUID(uint8_t *uid, int *uidlen)
{
int GetHFMF14AUID(uint8_t *uid, int *uidlen) {
UsbCommand c = {CMD_READER_ISO_14443a, {ISO14A_CONNECT, 0, 0}};
clearCommandBuffer();
SendCommand(&c);
@ -450,8 +422,7 @@ int GetHFMF14AUID(uint8_t *uid, int *uidlen)
return 1;
}
char *GenerateFilename(const char *prefix, const char *suffix)
{
char *GenerateFilename(const char *prefix, const char *suffix) {
uint8_t uid[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int uidlen = 0;
char *fptr = calloc(sizeof(char) * (strlen(prefix) + strlen(suffix)) + sizeof(uid) * 2 + 1, sizeof(uint8_t));
@ -468,8 +439,7 @@ char *GenerateFilename(const char *prefix, const char *suffix)
return fptr;
}
int CmdHF14AMfDarkside(const char *Cmd)
{
int CmdHF14AMfDarkside(const char *Cmd) {
uint8_t blockno = 0, key_type = MIFARE_AUTH_KEYA;
uint64_t key = 0;
@ -509,8 +479,7 @@ int CmdHF14AMfDarkside(const char *Cmd)
return 0;
}
int CmdHF14AMfWrBl(const char *Cmd)
{
int CmdHF14AMfWrBl(const char *Cmd) {
uint8_t blockNo = 0;
uint8_t keyType = 0;
uint8_t key[6] = {0, 0, 0, 0, 0, 0};
@ -564,8 +533,7 @@ int CmdHF14AMfWrBl(const char *Cmd)
return 0;
}
int CmdHF14AMfRdBl(const char *Cmd)
{
int CmdHF14AMfRdBl(const char *Cmd) {
uint8_t blockNo = 0;
uint8_t keyType = 0;
uint8_t key[6] = {0, 0, 0, 0, 0, 0};
@ -629,8 +597,7 @@ int CmdHF14AMfRdBl(const char *Cmd)
return 0;
}
int CmdHF14AMfRdSc(const char *Cmd)
{
int CmdHF14AMfRdSc(const char *Cmd) {
int i;
uint8_t sectorNo = 0;
uint8_t keyType = 0;
@ -701,8 +668,7 @@ int CmdHF14AMfRdSc(const char *Cmd)
return 0;
}
uint16_t NumOfBlocks(char card)
{
uint16_t NumOfBlocks(char card) {
switch (card) {
case '0' :
return MIFARE_MINI_MAXBLOCK;
@ -716,8 +682,7 @@ uint16_t NumOfBlocks(char card)
return MIFARE_1K_MAXBLOCK;
}
}
uint8_t NumOfSectors(char card)
{
uint8_t NumOfSectors(char card) {
switch (card) {
case '0' :
return MIFARE_MINI_MAXSECTOR;
@ -732,8 +697,7 @@ uint8_t NumOfSectors(char card)
}
}
uint8_t FirstBlockOfSector(uint8_t sectorNo)
{
uint8_t FirstBlockOfSector(uint8_t sectorNo) {
if (sectorNo < 32) {
return sectorNo * 4;
} else {
@ -741,8 +705,7 @@ uint8_t FirstBlockOfSector(uint8_t sectorNo)
}
}
uint8_t NumBlocksPerSector(uint8_t sectorNo)
{
uint8_t NumBlocksPerSector(uint8_t sectorNo) {
if (sectorNo < 32) {
return 4;
} else {
@ -750,8 +713,7 @@ uint8_t NumBlocksPerSector(uint8_t sectorNo)
}
}
int CmdHF14AMfDump(const char *Cmd)
{
int CmdHF14AMfDump(const char *Cmd) {
uint8_t sectorNo, blockNo;
uint8_t keyA[40][6];
@ -957,8 +919,7 @@ int CmdHF14AMfDump(const char *Cmd)
return 0;
}
int CmdHF14AMfRestore(const char *Cmd)
{
int CmdHF14AMfRestore(const char *Cmd) {
uint8_t sectorNo, blockNo;
uint8_t keyType = 0;
uint8_t key[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
@ -1099,8 +1060,7 @@ int CmdHF14AMfRestore(const char *Cmd)
return 0;
}
int CmdHF14AMfNested(const char *Cmd)
{
int CmdHF14AMfNested(const char *Cmd) {
int i, res, iterations;
sector_t *e_sector = NULL;
uint8_t blockNo = 0;
@ -1366,8 +1326,7 @@ int CmdHF14AMfNested(const char *Cmd)
return 0;
}
int CmdHF14AMfNestedHard(const char *Cmd)
{
int CmdHF14AMfNestedHard(const char *Cmd) {
uint8_t blockNo = 0;
uint8_t keyType = 0;
uint8_t trgBlockNo = 0;
@ -1549,14 +1508,12 @@ int CmdHF14AMfNestedHard(const char *Cmd)
return 0;
}
int randInRange(int min, int max)
{
int randInRange(int min, int max) {
return min + (int)(rand() / (double)(RAND_MAX) * (max - min + 1));
}
//FisherYates shuffle
void shuffle(uint8_t *array, uint16_t len)
{
void shuffle(uint8_t *array, uint16_t len) {
uint8_t tmp[6];
uint16_t x;
time_t t;
@ -1570,8 +1527,7 @@ void shuffle(uint8_t *array, uint16_t len)
}
}
int CmdHF14AMfChk_fast(const char *Cmd)
{
int CmdHF14AMfChk_fast(const char *Cmd) {
char ctmp = 0x00;
ctmp = tolower(param_getchar(Cmd, 0));
@ -1822,8 +1778,7 @@ out:
return 0;
}
int CmdHF14AMfChk(const char *Cmd)
{
int CmdHF14AMfChk(const char *Cmd) {
char ctmp = tolower(param_getchar(Cmd, 0));
if (strlen(Cmd) < 3 || ctmp == 'h') return usage_hf14_chk();
@ -2113,8 +2068,7 @@ out:
sector_t *k_sector = NULL;
uint8_t k_sectorsCount = 16;
static void emptySectorTable()
{
static void emptySectorTable() {
// initialize storage for found keys
if (k_sector == NULL)
@ -2131,8 +2085,7 @@ static void emptySectorTable()
}
}
void showSectorTable()
{
void showSectorTable() {
if (k_sector != NULL) {
printKeyTable(k_sectorsCount, k_sector);
free(k_sector);
@ -2140,8 +2093,7 @@ void showSectorTable()
}
}
void readerAttack(nonces_t data, bool setEmulatorMem, bool verbose)
{
void readerAttack(nonces_t data, bool setEmulatorMem, bool verbose) {
uint64_t key = 0;
bool success = false;
@ -2178,8 +2130,7 @@ void readerAttack(nonces_t data, bool setEmulatorMem, bool verbose)
}
}
int CmdHF14AMf1kSim(const char *Cmd)
{
int CmdHF14AMf1kSim(const char *Cmd) {
uint8_t uid[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
uint8_t exitAfterNReads = 0;
@ -2267,8 +2218,7 @@ int CmdHF14AMf1kSim(const char *Cmd)
return 0;
}
int CmdHF14AMfSniff(const char *Cmd)
{
int CmdHF14AMfSniff(const char *Cmd) {
bool wantLogToFile = false;
bool wantDecrypt = false;
//bool wantSaveToEml = false; TODO
@ -2429,8 +2379,7 @@ int CmdHF14AMfSniff(const char *Cmd)
return 0;
}
int CmdHF14AMfDbg(const char *Cmd)
{
int CmdHF14AMfDbg(const char *Cmd) {
char ctmp = tolower(param_getchar(Cmd, 0));
if (strlen(Cmd) < 1 || ctmp == 'h') return usage_hf14_dbg();
@ -2443,8 +2392,7 @@ int CmdHF14AMfDbg(const char *Cmd)
return 0;
}
int CmdHF14AMfKeyBrute(const char *Cmd)
{
int CmdHF14AMfKeyBrute(const char *Cmd) {
uint8_t blockNo = 0, keytype = 0;
uint8_t key[6] = {0, 0, 0, 0, 0, 0};
@ -2475,8 +2423,7 @@ int CmdHF14AMfKeyBrute(const char *Cmd)
return 0;
}
void printKeyTable(uint8_t sectorscnt, sector_t *e_sector)
{
void printKeyTable(uint8_t sectorscnt, sector_t *e_sector) {
char strA[12 + 1] = {0};
char strB[12 + 1] = {0};
PrintAndLogEx(NORMAL, "|---|----------------|---|----------------|---|");
@ -2504,8 +2451,7 @@ void printKeyTable(uint8_t sectorscnt, sector_t *e_sector)
}
// EMULATOR COMMANDS
int CmdHF14AMfEGet(const char *Cmd)
{
int CmdHF14AMfEGet(const char *Cmd) {
uint8_t blockNo = 0;
uint8_t data[16] = {0x00};
char c = tolower(param_getchar(Cmd, 0));
@ -2523,8 +2469,7 @@ int CmdHF14AMfEGet(const char *Cmd)
return 0;
}
int CmdHF14AMfEClear(const char *Cmd)
{
int CmdHF14AMfEClear(const char *Cmd) {
char c = tolower(param_getchar(Cmd, 0));
if (c == 'h') return usage_hf14_eclr();
@ -2534,8 +2479,7 @@ int CmdHF14AMfEClear(const char *Cmd)
return 0;
}
int CmdHF14AMfESet(const char *Cmd)
{
int CmdHF14AMfESet(const char *Cmd) {
char c = tolower(param_getchar(Cmd, 0));
uint8_t memBlock[16];
uint8_t blockNo = 0;
@ -2555,8 +2499,7 @@ int CmdHF14AMfESet(const char *Cmd)
return mfEmlSetMem(memBlock, blockNo, 1);
}
int CmdHF14AMfELoad(const char *Cmd)
{
int CmdHF14AMfELoad(const char *Cmd) {
size_t counter = 0;
char filename[FILE_PATH_SIZE];
@ -2650,8 +2593,7 @@ int CmdHF14AMfELoad(const char *Cmd)
return 0;
}
int CmdHF14AMfESave(const char *Cmd)
{
int CmdHF14AMfESave(const char *Cmd) {
char filename[FILE_PATH_SIZE];
char *fnameptr = filename;
@ -2697,8 +2639,7 @@ int CmdHF14AMfESave(const char *Cmd)
return 0;
}
int CmdHF14AMfECFill(const char *Cmd)
{
int CmdHF14AMfECFill(const char *Cmd) {
uint8_t keyType = 0;
uint8_t numSectors = 16;
char c = tolower(param_getchar(Cmd, 0));
@ -2723,8 +2664,7 @@ int CmdHF14AMfECFill(const char *Cmd)
return 0;
}
int CmdHF14AMfEKeyPrn(const char *Cmd)
{
int CmdHF14AMfEKeyPrn(const char *Cmd) {
int i;
uint8_t numSectors;
uint8_t data[16];
@ -2753,8 +2693,7 @@ int CmdHF14AMfEKeyPrn(const char *Cmd)
}
// CHINESE MAGIC COMMANDS
int CmdHF14AMfCSetUID(const char *Cmd)
{
int CmdHF14AMfCSetUID(const char *Cmd) {
uint8_t wipeCard = 0;
uint8_t uid[8] = {0x00};
uint8_t oldUid[8] = {0x00};
@ -2814,8 +2753,7 @@ int CmdHF14AMfCSetUID(const char *Cmd)
return 0;
}
int CmdHF14AMfCSetBlk(const char *Cmd)
{
int CmdHF14AMfCSetBlk(const char *Cmd) {
uint8_t block[16] = {0x00};
uint8_t blockNo = 0;
uint8_t params = MAGIC_SINGLE;
@ -2842,8 +2780,7 @@ int CmdHF14AMfCSetBlk(const char *Cmd)
return 0;
}
int CmdHF14AMfCLoad(const char *Cmd)
{
int CmdHF14AMfCLoad(const char *Cmd) {
uint8_t buf8[16] = {0x00};
uint8_t fillFromEmulator = 0;
@ -2958,8 +2895,7 @@ int CmdHF14AMfCLoad(const char *Cmd)
return 0;
}
int CmdHF14AMfCGetBlk(const char *Cmd)
{
int CmdHF14AMfCGetBlk(const char *Cmd) {
uint8_t data[16] = {0};
uint8_t blockNo = 0;
int res;
@ -2996,8 +2932,7 @@ int CmdHF14AMfCGetBlk(const char *Cmd)
return 0;
}
int CmdHF14AMfCGetSc(const char *Cmd)
{
int CmdHF14AMfCGetSc(const char *Cmd) {
uint8_t data[16] = {0};
uint8_t sector = 0;
int i, res, flags;
@ -3036,8 +2971,7 @@ int CmdHF14AMfCGetSc(const char *Cmd)
return 0;
}
int CmdHF14AMfCSave(const char *Cmd)
{
int CmdHF14AMfCSave(const char *Cmd) {
char filename[FILE_PATH_SIZE];
char *fnameptr = filename;
@ -3140,8 +3074,7 @@ int CmdHF14AMfCSave(const char *Cmd)
}
//needs nt, ar, at, Data to decrypt
int CmdHf14AMfDecryptBytes(const char *Cmd)
{
int CmdHf14AMfDecryptBytes(const char *Cmd) {
char ctmp = tolower(param_getchar(Cmd, 0));
if (strlen(Cmd) < 1 || ctmp == 'h') return usage_hf14_decryptbytes();
@ -3168,8 +3101,7 @@ int CmdHf14AMfDecryptBytes(const char *Cmd)
return 0;
}
int CmdHf14AMfSetMod(const char *Cmd)
{
int CmdHf14AMfSetMod(const char *Cmd) {
uint8_t key[6] = {0, 0, 0, 0, 0, 0};
uint8_t mod = 2;
@ -3206,8 +3138,7 @@ int CmdHf14AMfSetMod(const char *Cmd)
}
// Mifare NACK bug detection
int CmdHf14AMfNack(const char *Cmd)
{
int CmdHf14AMfNack(const char *Cmd) {
bool verbose = false;
char ctmp = tolower(param_getchar(Cmd, 0));
@ -3221,8 +3152,7 @@ int CmdHf14AMfNack(const char *Cmd)
return 0;
}
int CmdHF14AMfice(const char *Cmd)
{
int CmdHF14AMfice(const char *Cmd) {
uint8_t blockNo = 0;
uint8_t keyType = 0;
@ -3330,8 +3260,7 @@ out:
return 0;
}
int CmdHF14AMfAuth4(const char *Cmd)
{
int CmdHF14AMfAuth4(const char *Cmd) {
uint8_t keyn[20] = {0};
int keynlen = 0;
uint8_t key[16] = {0};
@ -3368,8 +3297,7 @@ int CmdHF14AMfAuth4(const char *Cmd)
}
// https://www.nxp.com/docs/en/application-note/AN10787.pdf
int CmdHF14AMfMAD(const char *cmd)
{
int CmdHF14AMfMAD(const char *cmd) {
CLIParserInit("hf mf mad",
"Checks and prints Mifare Application Directory (MAD)",
@ -3459,8 +3387,7 @@ int CmdHF14AMfMAD(const char *cmd)
return 0;
}
int CmdHFMFNDEF(const char *cmd)
{
int CmdHFMFNDEF(const char *cmd) {
CLIParserInit("hf mf ndef",
"Prints NFC Data Exchange Format (NDEF)",
@ -3564,8 +3491,7 @@ int CmdHFMFNDEF(const char *cmd)
return 0;
}
int CmdHF14AMfList(const char *Cmd)
{
int CmdHF14AMfList(const char *Cmd) {
CmdTraceList("mf");
return 0;
}
@ -3615,15 +3541,13 @@ static command_t CommandTable[] = {
{NULL, NULL, 0, NULL}
};
int CmdHFMF(const char *Cmd)
{
int CmdHFMF(const char *Cmd) {
clearCommandBuffer();
CmdsParse(CommandTable, Cmd);
return 0;
}
int CmdHelp(const char *Cmd)
{
int CmdHelp(const char *Cmd) {
CmdsHelp(CommandTable);
return 0;
}

View file

@ -35,8 +35,7 @@ uint8_t key_picc_data[16] = { 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x
static int CmdHelp(const char *Cmd);
int CmdHF14ADesWb(const char *Cmd)
{
int CmdHF14ADesWb(const char *Cmd) {
/* uint8_t blockNo = 0;
uint8_t keyType = 0;
uint8_t key[6] = {0, 0, 0, 0, 0, 0};
@ -84,8 +83,7 @@ int CmdHF14ADesWb(const char *Cmd)
return 0;
}
int CmdHF14ADesRb(const char *Cmd)
{
int CmdHF14ADesRb(const char *Cmd) {
// uint8_t blockNo = 0;
// uint8_t keyType = 0;
// uint8_t key[6] = {0, 0, 0, 0, 0, 0};
@ -132,8 +130,7 @@ int CmdHF14ADesRb(const char *Cmd)
return 0;
}
int CmdHF14ADesInfo(const char *Cmd)
{
int CmdHF14ADesInfo(const char *Cmd) {
UsbCommand c = {CMD_MIFARE_DESFIRE_INFO};
SendCommand(&c);
@ -225,8 +222,7 @@ int CmdHF14ADesInfo(const char *Cmd)
and set to '1' if the storage size is between 2^n and 2^(n+1).
For this version of DESFire the 7 MSBits are set to 0x0C (2^12 = 4096) and the LSBit is '0'.
*/
char *GetCardSizeStr(uint8_t fsize)
{
char *GetCardSizeStr(uint8_t fsize) {
static char buf[30] = {0x00};
char *retStr = buf;
@ -242,8 +238,7 @@ char *GetCardSizeStr(uint8_t fsize)
return buf;
}
char *GetProtocolStr(uint8_t id)
{
char *GetProtocolStr(uint8_t id) {
static char buf[30] = {0x00};
char *retStr = buf;
@ -255,8 +250,7 @@ char *GetProtocolStr(uint8_t id)
return buf;
}
char *GetVersionStr(uint8_t major, uint8_t minor)
{
char *GetVersionStr(uint8_t major, uint8_t minor) {
static char buf[30] = {0x00};
char *retStr = buf;
@ -272,8 +266,7 @@ char *GetVersionStr(uint8_t major, uint8_t minor)
return buf;
}
void GetKeySettings(uint8_t *aid)
{
void GetKeySettings(uint8_t *aid) {
char messStr[512] = {0x00};
char *str = messStr;
@ -442,8 +435,7 @@ void GetKeySettings(uint8_t *aid)
}
}
int CmdHF14ADesEnumApplications(const char *Cmd)
{
int CmdHF14ADesEnumApplications(const char *Cmd) {
uint8_t isOK = 0x00;
uint8_t aid[3];
@ -554,8 +546,7 @@ int CmdHF14ADesEnumApplications(const char *Cmd)
// MIAFRE DesFire Authentication
//
#define BUFSIZE 256
int CmdHF14ADesAuth(const char *Cmd)
{
int CmdHF14ADesAuth(const char *Cmd) {
// NR DESC KEYLENGHT
// ------------------------
@ -673,16 +664,14 @@ static command_t CommandTable[] = {
{NULL, NULL, 0, NULL}
};
int CmdHFMFDes(const char *Cmd)
{
int CmdHFMFDes(const char *Cmd) {
// flush
clearCommandBuffer();
CmdsParse(CommandTable, Cmd);
return 0;
}
int CmdHelp(const char *Cmd)
{
int CmdHelp(const char *Cmd) {
CmdsHelp(CommandTable);
return 0;
}

View file

@ -29,8 +29,7 @@ static int CmdHelp(const char *Cmd);
//n'r=rol(r5)
//verify n'r=nr
int CmdHF14AMfDESAuth(const char *Cmd)
{
int CmdHF14AMfDESAuth(const char *Cmd) {
uint8_t blockNo = 0;
//keyNo=0;
@ -123,8 +122,7 @@ int CmdHF14AMfDESAuth(const char *Cmd)
// Card 2 Reader : 02AF, 16 Bytes(b0), CRC1 CRC2
// Reader 2 Card : 03AF, 16 Bytes(b1),16Bytes(b2) CRC1 CRC2
// Card 2 Reader : 0300, 16 bytes(b3), CRC1 CRC2 ; success
int CmdHF14AMfAESAuth(const char *Cmd)
{
int CmdHF14AMfAESAuth(const char *Cmd) {
uint8_t blockNo = 0;
//keyNo=0;
@ -238,16 +236,14 @@ static command_t CommandTable[] = {
{NULL, NULL, 0, NULL}
};
int CmdHFMFDesfire(const char *Cmd)
{
int CmdHFMFDesfire(const char *Cmd) {
// flush
clearCommandBuffer();
CmdsParse(CommandTable, Cmd);
return 0;
}
int CmdHelp(const char *Cmd)
{
int CmdHelp(const char *Cmd) {
CmdsHelp(CommandTable);
return 0;
}

View file

@ -72,8 +72,7 @@ static uint32_t test_state[2] = {0, 0};
static float brute_force_per_second;
static void get_SIMD_instruction_set(char *instruction_set)
{
static void get_SIMD_instruction_set(char *instruction_set) {
switch (GetSIMDInstrAuto()) {
case SIMD_AVX512:
strcpy(instruction_set, "AVX512F");
@ -97,8 +96,7 @@ static void get_SIMD_instruction_set(char *instruction_set)
}
static void print_progress_header(void)
{
static void print_progress_header(void) {
char progress_text[80];
char instr_set[12] = "";
get_SIMD_instruction_set(instr_set);
@ -111,8 +109,7 @@ static void print_progress_header(void)
}
void hardnested_print_progress(uint32_t nonces, char *activity, float brute_force, uint64_t min_diff_print_time)
{
void hardnested_print_progress(uint32_t nonces, char *activity, float brute_force, uint64_t min_diff_print_time) {
static uint64_t last_print_time = 0;
if (msclock() - last_print_time > min_diff_print_time) {
last_print_time = msclock();
@ -136,31 +133,26 @@ void hardnested_print_progress(uint32_t nonces, char *activity, float brute_forc
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// bitarray functions
static inline void clear_bitarray24(uint32_t *bitarray)
{
static inline void clear_bitarray24(uint32_t *bitarray) {
memset(bitarray, 0x00, sizeof(uint32_t) * (1 << 19));
}
static inline void set_bitarray24(uint32_t *bitarray)
{
static inline void set_bitarray24(uint32_t *bitarray) {
memset(bitarray, 0xff, sizeof(uint32_t) * (1 << 19));
}
static inline void set_bit24(uint32_t *bitarray, uint32_t index)
{
static inline void set_bit24(uint32_t *bitarray, uint32_t index) {
bitarray[index >> 5] |= 0x80000000 >> (index & 0x0000001f);
}
static inline uint32_t test_bit24(uint32_t *bitarray, uint32_t index)
{
static inline uint32_t test_bit24(uint32_t *bitarray, uint32_t index) {
return bitarray[index >> 5] & (0x80000000 >> (index & 0x0000001f));
}
static inline uint32_t next_state(uint32_t *bitarray, uint32_t state)
{
static inline uint32_t next_state(uint32_t *bitarray, uint32_t state) {
if (++state == 1 << 24) return 1 << 24;
uint32_t index = state >> 5;
uint_fast8_t bit = state & 0x1f;
@ -202,22 +194,19 @@ static inline uint32_t next_state(uint32_t *bitarray, uint32_t state)
static uint32_t *bitflip_bitarrays[2][0x400];
static uint32_t count_bitflip_bitarrays[2][0x400];
static int compare_count_bitflip_bitarrays(const void *b1, const void *b2)
{
static int compare_count_bitflip_bitarrays(const void *b1, const void *b2) {
uint64_t count1 = (uint64_t)count_bitflip_bitarrays[ODD_STATE][*(uint16_t *)b1] * count_bitflip_bitarrays[EVEN_STATE][*(uint16_t *)b1];
uint64_t count2 = (uint64_t)count_bitflip_bitarrays[ODD_STATE][*(uint16_t *)b2] * count_bitflip_bitarrays[EVEN_STATE][*(uint16_t *)b2];
return (count1 > count2) - (count2 > count1);
}
static voidpf inflate_malloc(voidpf opaque, uInt items, uInt size)
{
static voidpf inflate_malloc(voidpf opaque, uInt items, uInt size) {
return calloc(items * size, sizeof(uint8_t));
}
static void inflate_free(voidpf opaque, voidpf address)
{
static void inflate_free(voidpf opaque, voidpf address) {
free(address);
}
@ -227,8 +216,7 @@ static void inflate_free(voidpf opaque, voidpf address)
//----------------------------------------------------------------------------
// Initialize decompression of the respective (HF or LF) FPGA stream
//----------------------------------------------------------------------------
static void init_inflate(z_streamp compressed_stream, uint8_t *input_buffer, uint32_t insize, uint8_t *output_buffer, uint32_t outsize)
{
static void init_inflate(z_streamp compressed_stream, uint8_t *input_buffer, uint32_t insize, uint8_t *output_buffer, uint32_t outsize) {
// initialize z_stream structure for inflate:
compressed_stream->next_in = input_buffer;
@ -243,8 +231,7 @@ static void init_inflate(z_streamp compressed_stream, uint8_t *input_buffer, uin
}
static void init_bitflip_bitarrays(void)
{
static void init_bitflip_bitarrays(void) {
#if defined (DEBUG_REDUCTION)
uint8_t line = 0;
#endif
@ -357,8 +344,7 @@ static void init_bitflip_bitarrays(void)
}
static void free_bitflip_bitarrays(void)
{
static void free_bitflip_bitarrays(void) {
for (int16_t bitflip = 0x3ff; bitflip > 0x000; bitflip--) {
free_bitarray(bitflip_bitarrays[ODD_STATE][bitflip]);
}
@ -375,8 +361,7 @@ static uint32_t *part_sum_a0_bitarrays[2][NUM_PART_SUMS];
static uint32_t *part_sum_a8_bitarrays[2][NUM_PART_SUMS];
static uint32_t *sum_a0_bitarrays[2][NUM_SUMS];
static uint16_t PartialSumProperty(uint32_t state, odd_even_t odd_even)
{
static uint16_t PartialSumProperty(uint32_t state, odd_even_t odd_even) {
uint16_t sum = 0;
for (uint16_t j = 0; j < 16; j++) {
uint32_t st = state;
@ -399,8 +384,7 @@ static uint16_t PartialSumProperty(uint32_t state, odd_even_t odd_even)
}
static void init_part_sum_bitarrays(void)
{
static void init_part_sum_bitarrays(void) {
for (odd_even_t odd_even = EVEN_STATE; odd_even <= ODD_STATE; odd_even++) {
for (uint16_t part_sum_a0 = 0; part_sum_a0 < NUM_PART_SUMS; part_sum_a0++) {
part_sum_a0_bitarrays[odd_even][part_sum_a0] = (uint32_t *)malloc_bitarray(sizeof(uint32_t) * (1 << 19));
@ -443,8 +427,7 @@ static void init_part_sum_bitarrays(void)
}
static void free_part_sum_bitarrays(void)
{
static void free_part_sum_bitarrays(void) {
for (int16_t part_sum_a8 = (NUM_PART_SUMS - 1); part_sum_a8 >= 0; part_sum_a8--) {
free_bitarray(part_sum_a8_bitarrays[ODD_STATE][part_sum_a8]);
}
@ -460,8 +443,7 @@ static void free_part_sum_bitarrays(void)
}
static void init_sum_bitarrays(void)
{
static void init_sum_bitarrays(void) {
for (uint16_t sum_a0 = 0; sum_a0 < NUM_SUMS; sum_a0++) {
for (odd_even_t odd_even = EVEN_STATE; odd_even <= ODD_STATE; odd_even++) {
sum_a0_bitarrays[odd_even][sum_a0] = (uint32_t *)malloc_bitarray(sizeof(uint32_t) * (1 << 19));
@ -485,8 +467,7 @@ static void init_sum_bitarrays(void)
}
static void free_sum_bitarrays(void)
{
static void free_sum_bitarrays(void) {
for (int8_t sum_a0 = NUM_SUMS - 1; sum_a0 >= 0; sum_a0--) {
free_bitarray(sum_a0_bitarrays[ODD_STATE][sum_a0]);
free_bitarray(sum_a0_bitarrays[EVEN_STATE][sum_a0]);
@ -524,8 +505,7 @@ static uint64_t num_keys_tested = 0;
static statelist_t *candidates = NULL;
static int add_nonce(uint32_t nonce_enc, uint8_t par_enc)
{
static int add_nonce(uint32_t nonce_enc, uint8_t par_enc) {
uint8_t first_byte = nonce_enc >> 24;
noncelistentry_t *p1 = nonces[first_byte].first;
noncelistentry_t *p2 = NULL;
@ -568,8 +548,7 @@ static int add_nonce(uint32_t nonce_enc, uint8_t par_enc)
}
static void init_nonce_memory(void)
{
static void init_nonce_memory(void) {
for (uint16_t i = 0; i < 256; i++) {
nonces[i].num = 0;
nonces[i].Sum = 0;
@ -604,8 +583,7 @@ static void init_nonce_memory(void)
}
static void free_nonce_list(noncelistentry_t *p)
{
static void free_nonce_list(noncelistentry_t *p) {
if (p == NULL) {
return;
} else {
@ -615,8 +593,7 @@ static void free_nonce_list(noncelistentry_t *p)
}
static void free_nonces_memory(void)
{
static void free_nonces_memory(void) {
for (uint16_t i = 0; i < 256; i++) {
free_nonce_list(nonces[i].first);
}
@ -630,8 +607,7 @@ static void free_nonces_memory(void)
static double p_hypergeometric(uint16_t i_K, uint16_t n, uint16_t k)
{
static double p_hypergeometric(uint16_t i_K, uint16_t n, uint16_t k) {
// for efficient computation we are using the recursive definition
// (K-k+1) * (n-k+1)
// P(X=k) = P(X=k-1) * --------------------
@ -675,8 +651,7 @@ static double p_hypergeometric(uint16_t i_K, uint16_t n, uint16_t k)
}
static float sum_probability(uint16_t i_K, uint16_t n, uint16_t k)
{
static float sum_probability(uint16_t i_K, uint16_t n, uint16_t k) {
if (k > sums[i_K]) return 0.0;
double p_T_is_k_when_S_is_K = p_hypergeometric(i_K, n, k);
@ -691,8 +666,7 @@ static float sum_probability(uint16_t i_K, uint16_t n, uint16_t k)
static uint32_t part_sum_count[2][NUM_PART_SUMS][NUM_PART_SUMS];
static void init_allbitflips_array(void)
{
static void init_allbitflips_array(void) {
for (odd_even_t odd_even = EVEN_STATE; odd_even <= ODD_STATE; odd_even++) {
uint32_t *bitset = all_bitflips_bitarray[odd_even] = (uint32_t *)malloc_bitarray(sizeof(uint32_t) * (1 << 19));
if (bitset == NULL) {
@ -706,8 +680,7 @@ static void init_allbitflips_array(void)
}
static void update_allbitflips_array(void)
{
static void update_allbitflips_array(void) {
if (hardnested_stage & CHECK_2ND_BYTES) {
for (uint16_t i = 0; i < 256; i++) {
for (odd_even_t odd_even = EVEN_STATE; odd_even <= ODD_STATE; odd_even++) {
@ -725,14 +698,12 @@ static void update_allbitflips_array(void)
}
static uint32_t estimated_num_states_part_sum_coarse(uint16_t part_sum_a0_idx, uint16_t part_sum_a8_idx, odd_even_t odd_even)
{
static uint32_t estimated_num_states_part_sum_coarse(uint16_t part_sum_a0_idx, uint16_t part_sum_a8_idx, odd_even_t odd_even) {
return part_sum_count[odd_even][part_sum_a0_idx][part_sum_a8_idx];
}
static uint32_t estimated_num_states_part_sum(uint8_t first_byte, uint16_t part_sum_a0_idx, uint16_t part_sum_a8_idx, odd_even_t odd_even)
{
static uint32_t estimated_num_states_part_sum(uint8_t first_byte, uint16_t part_sum_a0_idx, uint16_t part_sum_a8_idx, odd_even_t odd_even) {
if (odd_even == ODD_STATE) {
return count_bitarray_AND3(part_sum_a0_bitarrays[odd_even][part_sum_a0_idx],
part_sum_a8_bitarrays[odd_even][part_sum_a8_idx],
@ -754,8 +725,7 @@ static uint32_t estimated_num_states_part_sum(uint8_t first_byte, uint16_t part_
}
static uint64_t estimated_num_states(uint8_t first_byte, uint16_t sum_a0, uint16_t sum_a8)
{
static uint64_t estimated_num_states(uint8_t first_byte, uint16_t sum_a0, uint16_t sum_a8) {
uint64_t num_states = 0;
for (uint8_t p = 0; p < NUM_PART_SUMS; p++) {
for (uint8_t q = 0; q < NUM_PART_SUMS; q++) {
@ -775,8 +745,7 @@ static uint64_t estimated_num_states(uint8_t first_byte, uint16_t sum_a0, uint16
}
static uint64_t estimated_num_states_coarse(uint16_t sum_a0, uint16_t sum_a8)
{
static uint64_t estimated_num_states_coarse(uint16_t sum_a0, uint16_t sum_a8) {
uint64_t num_states = 0;
for (uint8_t p = 0; p < NUM_PART_SUMS; p++) {
for (uint8_t q = 0; q < NUM_PART_SUMS; q++) {
@ -796,8 +765,7 @@ static uint64_t estimated_num_states_coarse(uint16_t sum_a0, uint16_t sum_a8)
}
static void update_p_K(void)
{
static void update_p_K(void) {
if (hardnested_stage & CHECK_2ND_BYTES) {
uint64_t total_count = 0;
uint16_t sum_a0 = sums[first_byte_Sum];
@ -818,8 +786,7 @@ static void update_p_K(void)
}
static void update_sum_bitarrays(odd_even_t odd_even)
{
static void update_sum_bitarrays(odd_even_t odd_even) {
if (all_bitflips_bitarray_dirty[odd_even]) {
for (uint8_t part_sum = 0; part_sum < NUM_PART_SUMS; part_sum++) {
bitarray_AND(part_sum_a0_bitarrays[odd_even][part_sum], all_bitflips_bitarray[odd_even]);
@ -839,8 +806,7 @@ static void update_sum_bitarrays(odd_even_t odd_even)
}
static int compare_expected_num_brute_force(const void *b1, const void *b2)
{
static int compare_expected_num_brute_force(const void *b1, const void *b2) {
uint8_t index1 = *(uint8_t *)b1;
uint8_t index2 = *(uint8_t *)b2;
float score1 = nonces[index1].expected_num_brute_force;
@ -849,8 +815,7 @@ static int compare_expected_num_brute_force(const void *b1, const void *b2)
}
static int compare_sum_a8_guess(const void *b1, const void *b2)
{
static int compare_sum_a8_guess(const void *b1, const void *b2) {
float prob1 = ((guess_sum_a8_t *)b1)->prob;
float prob2 = ((guess_sum_a8_t *)b2)->prob;
return (prob1 < prob2) - (prob1 > prob2);
@ -858,8 +823,7 @@ static int compare_sum_a8_guess(const void *b1, const void *b2)
}
static float check_smallest_bitflip_bitarrays(void)
{
static float check_smallest_bitflip_bitarrays(void) {
uint32_t num_odd, num_even;
uint64_t smallest = 1LL << 48;
// initialize best_first_bytes, do a rough estimation on remaining states
@ -881,8 +845,7 @@ static float check_smallest_bitflip_bitarrays(void)
}
static void update_expected_brute_force(uint8_t best_byte)
{
static void update_expected_brute_force(uint8_t best_byte) {
float total_prob = 0.0;
for (uint8_t i = 0; i < NUM_SUMS; i++) {
@ -903,8 +866,7 @@ static void update_expected_brute_force(uint8_t best_byte)
}
static float sort_best_first_bytes(void)
{
static float sort_best_first_bytes(void) {
// initialize best_first_bytes, do a rough estimation on remaining states for each Sum_a8 property
// and the expected number of states to brute force
@ -993,8 +955,7 @@ static float sort_best_first_bytes(void)
}
static float update_reduction_rate(float last, bool init)
{
static float update_reduction_rate(float last, bool init) {
#define QUEUE_LEN 4
static float queue[QUEUE_LEN];
@ -1037,8 +998,7 @@ static float update_reduction_rate(float last, bool init)
}
static bool shrink_key_space(float *brute_forces)
{
static bool shrink_key_space(float *brute_forces) {
#if defined(DEBUG_REDUCTION)
PrintAndLogEx(NORMAL, "shrink_key_space() with stage = 0x%02x\n", hardnested_stage);
#endif
@ -1057,8 +1017,7 @@ static bool shrink_key_space(float *brute_forces)
}
static void estimate_sum_a8(void)
{
static void estimate_sum_a8(void) {
if (first_byte_num == 256) {
for (uint16_t i = 0; i < 256; i++) {
if (nonces[i].sum_a8_guess_dirty) {
@ -1074,8 +1033,7 @@ static void estimate_sum_a8(void)
}
static int read_nonce_file(char *filename)
{
static int read_nonce_file(char *filename) {
FILE *fnonces = NULL;
char progress_text[80] = "";
size_t bytes_read;
@ -1131,8 +1089,7 @@ static int read_nonce_file(char *filename)
}
noncelistentry_t *SearchFor2ndByte(uint8_t b1, uint8_t b2)
{
noncelistentry_t *SearchFor2ndByte(uint8_t b1, uint8_t b2) {
noncelistentry_t *p = nonces[b1].first;
while (p != NULL) {
if ((p->nonce_enc >> 16 & 0xff) == b2) {
@ -1144,8 +1101,7 @@ noncelistentry_t *SearchFor2ndByte(uint8_t b1, uint8_t b2)
}
static bool timeout(void)
{
static bool timeout(void) {
return (msclock() > last_sample_clock + sample_period);
}
@ -1156,8 +1112,7 @@ static void
__attribute__((force_align_arg_pointer))
#endif
#endif
*check_for_BitFlipProperties_thread(void *args)
{
*check_for_BitFlipProperties_thread(void *args) {
uint8_t first_byte = ((uint8_t *)args)[0];
uint8_t last_byte = ((uint8_t *)args)[1];
uint8_t time_budget = ((uint8_t *)args)[2];
@ -1174,11 +1129,11 @@ __attribute__((force_align_arg_pointer))
}
for (uint16_t i = first_byte; i <= last_byte; i++) {
if (nonces[i].BitFlips[bitflip] == 0 && nonces[i].BitFlips[bitflip ^ 0x100] == 0
&& nonces[i].first != NULL && nonces[i ^ (bitflip & 0xff)].first != NULL) {
&& nonces[i].first != NULL && nonces[i ^ (bitflip & 0xff)].first != NULL) {
uint8_t parity1 = (nonces[i].first->par_enc) >> 3; // parity of first byte
uint8_t parity2 = (nonces[i ^ (bitflip & 0xff)].first->par_enc) >> 3; // parity of nonce with bits flipped
if ((parity1 == parity2 && !(bitflip & 0x100)) // bitflip
|| (parity1 != parity2 && (bitflip & 0x100))) { // not bitflip
|| (parity1 != parity2 && (bitflip & 0x100))) { // not bitflip
nonces[i].BitFlips[bitflip] = 1;
for (odd_even_t odd_even = EVEN_STATE; odd_even <= ODD_STATE; odd_even++) {
if (bitflip_bitarrays[odd_even][bitflip] != NULL) {
@ -1218,7 +1173,7 @@ __attribute__((force_align_arg_pointer))
uint8_t parity1 = byte1->par_enc >> 2 & 0x01; // parity of 2nd byte
uint8_t parity2 = byte2->par_enc >> 2 & 0x01; // parity of 2nd byte with bits flipped
if ((parity1 == parity2 && !(bitflip & 0x100)) // bitflip
|| (parity1 != parity2 && (bitflip & 0x100))) { // not bitflip
|| (parity1 != parity2 && (bitflip & 0x100))) { // not bitflip
nonces[i].BitFlips[bitflip] = 1;
for (odd_even_t odd_even = EVEN_STATE; odd_even <= ODD_STATE; odd_even++) {
if (bitflip_bitarrays[odd_even][bitflip] != NULL) {
@ -1244,8 +1199,7 @@ __attribute__((force_align_arg_pointer))
}
static void check_for_BitFlipProperties(bool time_budget)
{
static void check_for_BitFlipProperties(bool time_budget) {
// create and run worker threads
pthread_t thread_id[NUM_CHECK_BITFLIPS_THREADS];
@ -1283,8 +1237,7 @@ static void check_for_BitFlipProperties(bool time_budget)
}
static void update_nonce_data(bool time_budget)
{
static void update_nonce_data(bool time_budget) {
check_for_BitFlipProperties(time_budget);
update_allbitflips_array();
update_sum_bitarrays(EVEN_STATE);
@ -1294,8 +1247,7 @@ static void update_nonce_data(bool time_budget)
}
static void apply_sum_a0(void)
{
static void apply_sum_a0(void) {
uint32_t old_count = num_all_bitflips_bitarray[EVEN_STATE];
num_all_bitflips_bitarray[EVEN_STATE] = count_bitarray_AND(all_bitflips_bitarray[EVEN_STATE], sum_a0_bitarrays[EVEN_STATE][first_byte_Sum]);
if (num_all_bitflips_bitarray[EVEN_STATE] != old_count) {
@ -1309,8 +1261,7 @@ static void apply_sum_a0(void)
}
static void simulate_MFplus_RNG(uint32_t test_cuid, uint64_t test_key, uint32_t *nt_enc, uint8_t *par_enc)
{
static void simulate_MFplus_RNG(uint32_t test_cuid, uint64_t test_key, uint32_t *nt_enc, uint8_t *par_enc) {
struct Crypto1State sim_cs = {0, 0};
// init cryptostate with key:
@ -1333,8 +1284,7 @@ static void simulate_MFplus_RNG(uint32_t test_cuid, uint64_t test_key, uint32_t
}
static void simulate_acquire_nonces()
{
static void simulate_acquire_nonces() {
time_t time1 = time(NULL);
last_sample_clock = 0;
sample_period = 1000; // for simulation
@ -1408,8 +1358,7 @@ static void simulate_acquire_nonces()
}
static int acquire_nonces(uint8_t blockNo, uint8_t keyType, uint8_t *key, uint8_t trgBlockNo, uint8_t trgKeyType, bool nonce_file_write, bool slow, char *filename)
{
static int acquire_nonces(uint8_t blockNo, uint8_t keyType, uint8_t *key, uint8_t trgBlockNo, uint8_t trgKeyType, bool nonce_file_write, bool slow, char *filename) {
last_sample_clock = msclock();
sample_period = 2000; // initial rough estimate. Will be refined.
bool initialize = true;
@ -1560,8 +1509,7 @@ static int acquire_nonces(uint8_t blockNo, uint8_t keyType, uint8_t *key, uint8_
}
static inline bool invariant_holds(uint_fast8_t byte_diff, uint_fast32_t state1, uint_fast32_t state2, uint_fast8_t bit, uint_fast8_t state_bit)
{
static inline bool invariant_holds(uint_fast8_t byte_diff, uint_fast32_t state1, uint_fast32_t state2, uint_fast8_t bit, uint_fast8_t state_bit) {
uint_fast8_t j_1_bit_mask = 0x01 << (bit - 1);
uint_fast8_t bit_diff = byte_diff & j_1_bit_mask; // difference of (j-1)th bit
uint_fast8_t filter_diff = filter(state1 >> (4 - state_bit)) ^ filter(state2 >> (4 - state_bit)); // difference in filter function
@ -1572,8 +1520,7 @@ static inline bool invariant_holds(uint_fast8_t byte_diff, uint_fast32_t state1,
}
static inline bool invalid_state(uint_fast8_t byte_diff, uint_fast32_t state1, uint_fast32_t state2, uint_fast8_t bit, uint_fast8_t state_bit)
{
static inline bool invalid_state(uint_fast8_t byte_diff, uint_fast32_t state1, uint_fast32_t state2, uint_fast8_t bit, uint_fast8_t state_bit) {
uint_fast8_t j_bit_mask = 0x01 << bit;
uint_fast8_t bit_diff = byte_diff & j_bit_mask; // difference of jth bit
uint_fast8_t mask_y13_y16 = 0x48 >> state_bit;
@ -1583,8 +1530,7 @@ static inline bool invalid_state(uint_fast8_t byte_diff, uint_fast32_t state1, u
}
static inline bool remaining_bits_match(uint_fast8_t num_common_bits, uint_fast8_t byte_diff, uint_fast32_t state1, uint_fast32_t state2, odd_even_t odd_even)
{
static inline bool remaining_bits_match(uint_fast8_t num_common_bits, uint_fast8_t byte_diff, uint_fast32_t state1, uint_fast32_t state2, odd_even_t odd_even) {
if (odd_even) {
// odd bits
switch (num_common_bits) {
@ -1646,8 +1592,7 @@ static struct sl_cache_entry {
} sl_cache[NUM_PART_SUMS][NUM_PART_SUMS][2];
static void init_statelist_cache(void)
{
static void init_statelist_cache(void) {
pthread_mutex_lock(&statelist_cache_mutex);
for (uint16_t i = 0; i < NUM_PART_SUMS; i++) {
for (uint16_t j = 0; j < NUM_PART_SUMS; j++) {
@ -1662,8 +1607,7 @@ static void init_statelist_cache(void)
}
static void free_statelist_cache(void)
{
static void free_statelist_cache(void) {
pthread_mutex_lock(&statelist_cache_mutex);
for (uint16_t i = 0; i < NUM_PART_SUMS; i++) {
for (uint16_t j = 0; j < NUM_PART_SUMS; j++) {
@ -1698,8 +1642,7 @@ static inline bool bitflips_match(uint8_t byte, uint32_t state, odd_even_t odd_e
}
static uint_fast8_t reverse(uint_fast8_t b)
{
static uint_fast8_t reverse(uint_fast8_t b) {
b = (b & 0xF0) >> 4 | (b & 0x0F) << 4;
b = (b & 0xCC) >> 2 | (b & 0x33) << 2;
b = (b & 0xAA) >> 1 | (b & 0x55) << 1;
@ -1707,8 +1650,7 @@ static uint_fast8_t reverse(uint_fast8_t b)
}
static bool all_bitflips_match(uint8_t byte, uint32_t state, odd_even_t odd_even)
{
static bool all_bitflips_match(uint8_t byte, uint32_t state, odd_even_t odd_even) {
uint32_t masks[2][8] = {{0x00fffff0, 0x00fffff8, 0x00fffff8, 0x00fffffc, 0x00fffffc, 0x00fffffe, 0x00fffffe, 0x00ffffff},
{0x00fffff0, 0x00fffff0, 0x00fffff8, 0x00fffff8, 0x00fffffc, 0x00fffffc, 0x00fffffe, 0x00fffffe}
};
@ -1752,8 +1694,7 @@ static bool all_bitflips_match(uint8_t byte, uint32_t state, odd_even_t odd_even
}
static void bitarray_to_list(uint8_t byte, uint32_t *bitarray, uint32_t *state_list, uint32_t *len, odd_even_t odd_even)
{
static void bitarray_to_list(uint8_t byte, uint32_t *bitarray, uint32_t *state_list, uint32_t *len, odd_even_t odd_even) {
uint32_t *p = state_list;
for (uint32_t state = next_state(bitarray, -1L); state < (1 << 24); state = next_state(bitarray, state)) {
if (all_bitflips_match(byte, state, odd_even)) {
@ -1766,16 +1707,14 @@ static void bitarray_to_list(uint8_t byte, uint32_t *bitarray, uint32_t *state_l
}
static void add_cached_states(statelist_t *candidates, uint16_t part_sum_a0, uint16_t part_sum_a8, odd_even_t odd_even)
{
static void add_cached_states(statelist_t *candidates, uint16_t part_sum_a0, uint16_t part_sum_a8, odd_even_t odd_even) {
candidates->states[odd_even] = sl_cache[part_sum_a0 / 2][part_sum_a8 / 2][odd_even].sl;
candidates->len[odd_even] = sl_cache[part_sum_a0 / 2][part_sum_a8 / 2][odd_even].len;
return;
}
static void add_matching_states(statelist_t *candidates, uint8_t part_sum_a0, uint8_t part_sum_a8, odd_even_t odd_even)
{
static void add_matching_states(statelist_t *candidates, uint8_t part_sum_a0, uint8_t part_sum_a8, odd_even_t odd_even) {
uint32_t worstcase_size = 1 << 20;
candidates->states[odd_even] = (uint32_t *)malloc(sizeof(uint32_t) * worstcase_size);
if (candidates->states[odd_even] == NULL) {
@ -1813,8 +1752,7 @@ static void add_matching_states(statelist_t *candidates, uint8_t part_sum_a0, ui
return;
}
static statelist_t *add_more_candidates(void)
{
static statelist_t *add_more_candidates(void) {
statelist_t *new_candidates = candidates;
if (candidates == NULL) {
candidates = (statelist_t *)malloc(sizeof(statelist_t));
@ -1835,8 +1773,7 @@ static statelist_t *add_more_candidates(void)
}
static void add_bitflip_candidates(uint8_t byte)
{
static void add_bitflip_candidates(uint8_t byte) {
statelist_t *candidates = add_more_candidates();
for (odd_even_t odd_even = EVEN_STATE; odd_even <= ODD_STATE; odd_even++) {
@ -1857,8 +1794,7 @@ static void add_bitflip_candidates(uint8_t byte)
}
static bool TestIfKeyExists(uint64_t key)
{
static bool TestIfKeyExists(uint64_t key) {
struct Crypto1State *pcs;
pcs = crypto1_create(key);
crypto1_byte(pcs, (cuid >> 24) ^ best_first_bytes[0], true);
@ -1906,8 +1842,7 @@ static bool TestIfKeyExists(uint64_t key)
static work_status_t book_of_work[NUM_PART_SUMS][NUM_PART_SUMS][NUM_PART_SUMS][NUM_PART_SUMS];
static void init_book_of_work(void)
{
static void init_book_of_work(void) {
for (uint8_t p = 0; p < NUM_PART_SUMS; p++) {
for (uint8_t q = 0; q < NUM_PART_SUMS; q++) {
for (uint8_t r = 0; r < NUM_PART_SUMS; r++) {
@ -1925,8 +1860,7 @@ static void
__attribute__((force_align_arg_pointer))
#endif
#endif
*generate_candidates_worker_thread(void *args)
{
*generate_candidates_worker_thread(void *args) {
uint16_t *sum_args = (uint16_t *)args;
uint16_t sum_a0 = sums[sum_args[0]];
uint16_t sum_a8 = sums[sum_args[1]];
@ -1951,7 +1885,7 @@ __attribute__((force_align_arg_pointer))
pthread_mutex_lock(&statelist_cache_mutex);
if (sl_cache[p][r][ODD_STATE].cache_status == WORK_IN_PROGRESS
|| sl_cache[q][s][EVEN_STATE].cache_status == WORK_IN_PROGRESS) { // defer until not blocked by another thread.
|| sl_cache[q][s][EVEN_STATE].cache_status == WORK_IN_PROGRESS) { // defer until not blocked by another thread.
pthread_mutex_unlock(&statelist_cache_mutex);
pthread_mutex_unlock(&book_of_work_mutex);
there_might_be_more_work = true;
@ -2067,8 +2001,7 @@ __attribute__((force_align_arg_pointer))
}
static void generate_candidates(uint8_t sum_a0_idx, uint8_t sum_a8_idx)
{
static void generate_candidates(uint8_t sum_a0_idx, uint8_t sum_a8_idx) {
init_statelist_cache();
init_book_of_work();
@ -2113,8 +2046,7 @@ static void generate_candidates(uint8_t sum_a0_idx, uint8_t sum_a8_idx)
}
static void free_candidates_memory(statelist_t *sl)
{
static void free_candidates_memory(statelist_t *sl) {
if (sl == NULL)
return;
@ -2123,8 +2055,7 @@ static void free_candidates_memory(statelist_t *sl)
}
static void pre_XOR_nonces(void)
{
static void pre_XOR_nonces(void) {
// prepare acquired nonces for faster brute forcing.
// XOR the cryptoUID and its parity
@ -2141,24 +2072,21 @@ static void pre_XOR_nonces(void)
}
}
static bool brute_force(uint64_t *found_key)
{
static bool brute_force(uint64_t *found_key) {
if (known_target_key != -1) {
TestIfKeyExists(known_target_key);
}
return brute_force_bs(NULL, candidates, cuid, num_acquired_nonces, maximum_states, nonces, best_first_bytes, found_key);
}
static uint16_t SumProperty(struct Crypto1State *s)
{
static uint16_t SumProperty(struct Crypto1State *s) {
uint16_t sum_odd = PartialSumProperty(s->odd, ODD_STATE);
uint16_t sum_even = PartialSumProperty(s->even, EVEN_STATE);
return (sum_odd * (16 - sum_even) + (16 - sum_odd) * sum_even);
}
static void Tests()
{
static void Tests() {
if (known_target_key != -1) {
for (odd_even_t odd_even = EVEN_STATE; odd_even <= ODD_STATE; odd_even++) {
uint32_t *bitset = nonces[best_first_bytes[0]].states_bitarray[odd_even];
@ -2182,8 +2110,7 @@ static void Tests()
}
static void Tests2(void)
{
static void Tests2(void) {
if (known_target_key != -1) {
for (odd_even_t odd_even = EVEN_STATE; odd_even <= ODD_STATE; odd_even++) {
uint32_t *bitset = nonces[best_first_byte_smallest_bitarray].states_bitarray[odd_even];
@ -2210,8 +2137,7 @@ static void Tests2(void)
static uint16_t real_sum_a8 = 0;
static void set_test_state(uint8_t byte)
{
static void set_test_state(uint8_t byte) {
struct Crypto1State *pcs;
pcs = crypto1_create(known_target_key);
crypto1_byte(pcs, (cuid >> 24) ^ byte, true);
@ -2222,8 +2148,7 @@ static void set_test_state(uint8_t byte)
}
int mfnestedhard(uint8_t blockNo, uint8_t keyType, uint8_t *key, uint8_t trgBlockNo, uint8_t trgKeyType, uint8_t *trgkey, bool nonce_file_read, bool nonce_file_write, bool slow, int tests, uint64_t *foundkey, char *filename)
{
int mfnestedhard(uint8_t blockNo, uint8_t keyType, uint8_t *key, uint8_t trgBlockNo, uint8_t trgKeyType, uint8_t *trgkey, bool nonce_file_read, bool nonce_file_write, bool slow, int tests, uint64_t *foundkey, char *filename) {
char progress_text[80];
char instr_set[12] = {0};

View file

@ -33,8 +33,7 @@ static const uint8_t DefaultKey[16] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
static int CmdHelp(const char *Cmd);
int CmdHFMFPInfo(const char *cmd)
{
int CmdHFMFPInfo(const char *cmd) {
if (cmd && strlen(cmd) > 0)
PrintAndLogEx(WARNING, "command don't have any parameters.\n");
@ -113,8 +112,7 @@ int CmdHFMFPInfo(const char *cmd)
return 0;
}
int CmdHFMFPWritePerso(const char *cmd)
{
int CmdHFMFPWritePerso(const char *cmd) {
uint8_t keyNum[64] = {0};
int keyNumLen = 0;
uint8_t key[64] = {0};
@ -180,8 +178,7 @@ int CmdHFMFPWritePerso(const char *cmd)
uint16_t CardAddresses[] = {0x9000, 0x9001, 0x9002, 0x9003, 0x9004, 0xA000, 0xA001, 0xA080, 0xA081, 0xC000, 0xC001};
int CmdHFMFPInitPerso(const char *cmd)
{
int CmdHFMFPInitPerso(const char *cmd) {
int res;
uint8_t key[256] = {0};
int keyLen = 0;
@ -255,8 +252,7 @@ int CmdHFMFPInitPerso(const char *cmd)
return 0;
}
int CmdHFMFPCommitPerso(const char *cmd)
{
int CmdHFMFPCommitPerso(const char *cmd) {
CLIParserInit("hf mfp commitp",
"Executes Commit Perso command. Can be used in SL0 mode only.",
"Usage:\n\thf mfp commitp -> \n");
@ -297,8 +293,7 @@ int CmdHFMFPCommitPerso(const char *cmd)
return 0;
}
int CmdHFMFPAuth(const char *cmd)
{
int CmdHFMFPAuth(const char *cmd) {
uint8_t keyn[250] = {0};
int keynlen = 0;
uint8_t key[250] = {0};
@ -336,8 +331,7 @@ int CmdHFMFPAuth(const char *cmd)
return MifareAuth4(NULL, keyn, key, true, false, verbose);
}
int CmdHFMFPRdbl(const char *cmd)
{
int CmdHFMFPRdbl(const char *cmd) {
uint8_t keyn[2] = {0};
uint8_t key[250] = {0};
int keylen = 0;
@ -449,8 +443,7 @@ int CmdHFMFPRdbl(const char *cmd)
return 0;
}
int CmdHFMFPRdsc(const char *cmd)
{
int CmdHFMFPRdsc(const char *cmd) {
uint8_t keyn[2] = {0};
uint8_t key[250] = {0};
int keylen = 0;
@ -546,8 +539,7 @@ int CmdHFMFPRdsc(const char *cmd)
return 0;
}
int CmdHFMFPWrbl(const char *cmd)
{
int CmdHFMFPWrbl(const char *cmd) {
uint8_t keyn[2] = {0};
uint8_t key[250] = {0};
int keylen = 0;
@ -649,8 +641,7 @@ int CmdHFMFPWrbl(const char *cmd)
return 0;
}
int CmdHFMFPMAD(const char *cmd)
{
int CmdHFMFPMAD(const char *cmd) {
CLIParserInit("hf mfp mad",
"Checks and prints Mifare Application Directory (MAD)",
@ -744,8 +735,7 @@ int CmdHFMFPMAD(const char *cmd)
return 0;
}
int CmdHFMFPNDEF(const char *cmd)
{
int CmdHFMFPNDEF(const char *cmd) {
CLIParserInit("hf mfp ndef",
"Prints NFC Data Exchange Format (NDEF)",
@ -864,15 +854,13 @@ static command_t CommandTable[] = {
{NULL, NULL, 0, NULL}
};
int CmdHFMFP(const char *Cmd)
{
int CmdHFMFP(const char *Cmd) {
(void)WaitForResponseTimeout(CMD_ACK, NULL, 100);
CmdsParse(CommandTable, Cmd);
return 0;
}
int CmdHelp(const char *Cmd)
{
int CmdHelp(const char *Cmd) {
CmdsHelp(CommandTable);
return 0;
}

View file

@ -77,8 +77,7 @@ const uint32_t c_D[] = {
0x5728B869, 0x30726D5A
};
void transform_D(uint8_t *ru)
{
void transform_D(uint8_t *ru) {
//Transform
uint8_t i;
uint8_t p = 0;
@ -103,8 +102,7 @@ void transform_D(uint8_t *ru)
}
// Certain pwd generation algo nickname A.
uint32_t ul_ev1_pwdgenA(uint8_t *uid)
{
uint32_t ul_ev1_pwdgenA(uint8_t *uid) {
uint8_t pos = (uid[3] ^ uid[4] ^ uid[5] ^ uid[6]) % 32;
@ -129,8 +127,7 @@ uint32_t ul_ev1_pwdgenA(uint8_t *uid)
}
// Certain pwd generation algo nickname B. (very simple)
uint32_t ul_ev1_pwdgenB(uint8_t *uid)
{
uint32_t ul_ev1_pwdgenB(uint8_t *uid) {
uint8_t pwd[] = {0x00, 0x00, 0x00, 0x00};
@ -142,8 +139,7 @@ uint32_t ul_ev1_pwdgenB(uint8_t *uid)
}
// Certain pwd generation algo nickname C.
uint32_t ul_ev1_pwdgenC(uint8_t *uid)
{
uint32_t ul_ev1_pwdgenC(uint8_t *uid) {
uint32_t pwd = 0;
uint8_t base[] = {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x28,
@ -162,8 +158,7 @@ uint32_t ul_ev1_pwdgenC(uint8_t *uid)
}
// Certain pwd generation algo nickname D.
// a.k.a xzy
uint32_t ul_ev1_pwdgenD(uint8_t *uid)
{
uint32_t ul_ev1_pwdgenD(uint8_t *uid) {
uint8_t i;
//Rotate
uint8_t r = (uid[1] + uid[3] + uid[5]) & 7; //Rotation offset
@ -182,21 +177,17 @@ uint32_t ul_ev1_pwdgenD(uint8_t *uid)
return BSWAP_32(pwd);
}
// pack generation for algo 1-3
uint16_t ul_ev1_packgenA(uint8_t *uid)
{
uint16_t ul_ev1_packgenA(uint8_t *uid) {
uint16_t pack = (uid[0] ^ uid[1] ^ uid[2]) << 8 | (uid[2] ^ 8);
return pack;
}
uint16_t ul_ev1_packgenB(uint8_t *uid)
{
uint16_t ul_ev1_packgenB(uint8_t *uid) {
return 0x8080;
}
uint16_t ul_ev1_packgenC(uint8_t *uid)
{
uint16_t ul_ev1_packgenC(uint8_t *uid) {
return 0xaa55;
}
uint16_t ul_ev1_packgenD(uint8_t *uid)
{
uint16_t ul_ev1_packgenD(uint8_t *uid) {
uint8_t i;
//Rotate
uint8_t r = (uid[2] + uid[5]) & 7; //Rotation offset
@ -215,8 +206,7 @@ uint16_t ul_ev1_packgenD(uint8_t *uid)
return BSWAP_16(p & 0xFFFF);
}
int ul_ev1_pwdgen_selftest()
{
int ul_ev1_pwdgen_selftest() {
uint8_t uid1[] = {0x04, 0x11, 0x12, 0x11, 0x12, 0x11, 0x10};
uint32_t pwd1 = ul_ev1_pwdgenA(uid1);
@ -238,8 +228,7 @@ int ul_ev1_pwdgen_selftest()
//------------------------------------
// get version nxp product type
char *getProductTypeStr(uint8_t id)
{
char *getProductTypeStr(uint8_t id) {
static char buf[20];
char *retStr = buf;
@ -263,8 +252,7 @@ char *getProductTypeStr(uint8_t id)
the LSBit is set to '0' if the size is exactly 2^n
and set to '1' if the storage size is between 2^n and 2^(n+1).
*/
char *getUlev1CardSizeStr(uint8_t fsize)
{
char *getUlev1CardSizeStr(uint8_t fsize) {
static char buf[40];
char *retStr = buf;
@ -281,15 +269,13 @@ char *getUlev1CardSizeStr(uint8_t fsize)
return buf;
}
static void ul_switch_on_field(void)
{
static void ul_switch_on_field(void) {
UsbCommand c = {CMD_READER_ISO_14443a, {ISO14A_CONNECT | ISO14A_NO_DISCONNECT | ISO14A_NO_RATS, 0, 0}};
clearCommandBuffer();
SendCommand(&c);
}
static int ul_send_cmd_raw(uint8_t *cmd, uint8_t cmdlen, uint8_t *response, uint16_t responseLength)
{
static int ul_send_cmd_raw(uint8_t *cmd, uint8_t cmdlen, uint8_t *response, uint16_t responseLength) {
UsbCommand c = {CMD_READER_ISO_14443a, {ISO14A_RAW | ISO14A_NO_DISCONNECT | ISO14A_APPEND_CRC | ISO14A_NO_RATS, cmdlen, 0}};
memcpy(c.d.asBytes, cmd, cmdlen);
clearCommandBuffer();
@ -303,8 +289,7 @@ static int ul_send_cmd_raw(uint8_t *cmd, uint8_t cmdlen, uint8_t *response, uint
return resplen;
}
static int ul_select(iso14a_card_select_t *card)
{
static int ul_select(iso14a_card_select_t *card) {
ul_switch_on_field();
@ -323,16 +308,14 @@ static int ul_select(iso14a_card_select_t *card)
}
// This read command will at least return 16bytes.
static int ul_read(uint8_t page, uint8_t *response, uint16_t responseLength)
{
static int ul_read(uint8_t page, uint8_t *response, uint16_t responseLength) {
uint8_t cmd[] = {ISO14443A_CMD_READBLOCK, page};
int len = ul_send_cmd_raw(cmd, sizeof(cmd), response, responseLength);
return len;
}
static int ul_comp_write(uint8_t page, uint8_t *data, uint8_t datalen)
{
static int ul_comp_write(uint8_t page, uint8_t *data, uint8_t datalen) {
uint8_t cmd[18];
memset(cmd, 0x00, sizeof(cmd));
@ -350,16 +333,14 @@ static int ul_comp_write(uint8_t page, uint8_t *data, uint8_t datalen)
return -1;
}
static int ulc_requestAuthentication(uint8_t *nonce, uint16_t nonceLength)
{
static int ulc_requestAuthentication(uint8_t *nonce, uint16_t nonceLength) {
uint8_t cmd[] = {MIFARE_ULC_AUTH_1, 0x00};
int len = ul_send_cmd_raw(cmd, sizeof(cmd), nonce, nonceLength);
return len;
}
static int ulc_authentication(uint8_t *key, bool switch_off_field)
{
static int ulc_authentication(uint8_t *key, bool switch_off_field) {
UsbCommand c = {CMD_MIFAREUC_AUTH, {switch_off_field}};
memcpy(c.d.asBytes, key, 16);
@ -372,8 +353,7 @@ static int ulc_authentication(uint8_t *key, bool switch_off_field)
return 0;
}
static int ulev1_requestAuthentication(uint8_t *pwd, uint8_t *pack, uint16_t packLength)
{
static int ulev1_requestAuthentication(uint8_t *pwd, uint8_t *pack, uint16_t packLength) {
uint8_t cmd[] = {MIFARE_ULEV1_AUTH, pwd[0], pwd[1], pwd[2], pwd[3]};
int len = ul_send_cmd_raw(cmd, sizeof(cmd), pack, packLength);
@ -384,8 +364,7 @@ static int ulev1_requestAuthentication(uint8_t *pwd, uint8_t *pack, uint16_t pac
return len;
}
static int ul_auth_select(iso14a_card_select_t *card, TagTypeUL_t tagtype, bool hasAuthKey, uint8_t *authkey, uint8_t *pack, uint8_t packSize)
{
static int ul_auth_select(iso14a_card_select_t *card, TagTypeUL_t tagtype, bool hasAuthKey, uint8_t *authkey, uint8_t *pack, uint8_t packSize) {
if (hasAuthKey && (tagtype & UL_C)) {
//will select card automatically and close connection on error
if (!ulc_authentication(authkey, false)) {
@ -406,31 +385,27 @@ static int ul_auth_select(iso14a_card_select_t *card, TagTypeUL_t tagtype, bool
return 1;
}
static int ulev1_getVersion(uint8_t *response, uint16_t responseLength)
{
static int ulev1_getVersion(uint8_t *response, uint16_t responseLength) {
uint8_t cmd[] = {MIFARE_ULEV1_VERSION};
int len = ul_send_cmd_raw(cmd, sizeof(cmd), response, responseLength);
return len;
}
static int ulev1_readCounter(uint8_t counter, uint8_t *response, uint16_t responseLength)
{
static int ulev1_readCounter(uint8_t counter, uint8_t *response, uint16_t responseLength) {
uint8_t cmd[] = {MIFARE_ULEV1_READ_CNT, counter};
int len = ul_send_cmd_raw(cmd, sizeof(cmd), response, responseLength);
return len;
}
static int ulev1_readTearing(uint8_t counter, uint8_t *response, uint16_t responseLength)
{
static int ulev1_readTearing(uint8_t counter, uint8_t *response, uint16_t responseLength) {
uint8_t cmd[] = {MIFARE_ULEV1_CHECKTEAR, counter};
int len = ul_send_cmd_raw(cmd, sizeof(cmd), response, responseLength);
return len;
}
static int ulev1_readSignature(uint8_t *response, uint16_t responseLength)
{
static int ulev1_readSignature(uint8_t *response, uint16_t responseLength) {
uint8_t cmd[] = {MIFARE_ULEV1_READSIG, 0x00};
int len = ul_send_cmd_raw(cmd, sizeof(cmd), response, responseLength);
@ -450,8 +425,7 @@ static int ulev1_readSignature(uint8_t *response, uint16_t responseLength)
// UL responds with read of page 0, fudan doesn't respond.
//
// make sure field is off before calling this function
static int ul_fudan_check(void)
{
static int ul_fudan_check(void) {
iso14a_card_select_t card;
if (!ul_select(&card))
return UL_ERROR;
@ -469,8 +443,7 @@ static int ul_fudan_check(void)
return (!resp.d.asBytes[0]) ? FUDAN_UL : UL; //if response == 0x00 then Fudan, else Genuine NXP
}
static int ul_print_default(uint8_t *data)
{
static int ul_print_default(uint8_t *data) {
uint8_t uid[7];
uid[0] = data[0];
@ -525,8 +498,7 @@ static int ul_print_default(uint8_t *data)
return 0;
}
static int ndef_print_CC(uint8_t *data)
{
static int ndef_print_CC(uint8_t *data) {
// no NDEF message
if (data[0] != 0xE1)
return -1;
@ -551,8 +523,7 @@ static int ndef_print_CC(uint8_t *data)
return 0;
}
int ul_print_type(uint32_t tagtype, uint8_t spaces)
{
int ul_print_type(uint32_t tagtype, uint8_t spaces) {
char spc[11] = " ";
spc[10] = 0x00;
char *spacer = spc + (10 - spaces);
@ -612,8 +583,7 @@ int ul_print_type(uint32_t tagtype, uint8_t spaces)
return 0;
}
static int ulc_print_3deskey(uint8_t *data)
{
static int ulc_print_3deskey(uint8_t *data) {
PrintAndLogEx(NORMAL, " deskey1 [44/0x2C] : %s [s]", sprint_hex(data, 4), sprint_ascii(data, 4));
PrintAndLogEx(NORMAL, " deskey1 [45/0x2D] : %s [s]", sprint_hex(data + 4, 4), sprint_ascii(data + 4, 4));
PrintAndLogEx(NORMAL, " deskey2 [46/0x2E] : %s [s]", sprint_hex(data + 8, 4), sprint_ascii(data + 8, 4));
@ -622,8 +592,7 @@ static int ulc_print_3deskey(uint8_t *data)
return 0;
}
static int ulc_print_configuration(uint8_t *data)
{
static int ulc_print_configuration(uint8_t *data) {
PrintAndLogEx(NORMAL, "--- UL-C Configuration");
PrintAndLogEx(NORMAL, " Higher Lockbits [40/0x28] : %s - %s", sprint_hex(data, 4), sprint_bin(data, 2));
@ -646,8 +615,7 @@ static int ulc_print_configuration(uint8_t *data)
return 0;
}
static int ulev1_print_configuration(uint32_t tagtype, uint8_t *data, uint8_t startPage)
{
static int ulev1_print_configuration(uint32_t tagtype, uint8_t *data, uint8_t startPage) {
PrintAndLogEx(NORMAL, "\n--- Tag Configuration");
@ -753,8 +721,7 @@ static int ulev1_print_configuration(uint32_t tagtype, uint8_t *data, uint8_t st
return 0;
}
static int ulev1_print_counters()
{
static int ulev1_print_counters() {
PrintAndLogEx(NORMAL, "--- Tag Counters");
uint8_t tear[1] = {0};
uint8_t counter[3] = {0, 0, 0};
@ -770,8 +737,7 @@ static int ulev1_print_counters()
return len;
}
static int ulev1_print_signature(uint8_t *data, uint8_t len)
{
static int ulev1_print_signature(uint8_t *data, uint8_t len) {
PrintAndLogEx(NORMAL, "\n--- Tag Signature");
PrintAndLogEx(NORMAL, "IC signature public key name : NXP NTAG21x (2013)");
PrintAndLogEx(NORMAL, "IC signature public key value : %s", sprint_hex(public_ecda_key, PUBLIC_ECDA_KEYLEN));
@ -783,8 +749,7 @@ static int ulev1_print_signature(uint8_t *data, uint8_t len)
return 0;
}
static int ulev1_print_version(uint8_t *data)
{
static int ulev1_print_version(uint8_t *data) {
PrintAndLogEx(NORMAL, "\n--- Tag Version");
PrintAndLogEx(NORMAL, " Raw bytes : %s", sprint_hex(data, 8));
PrintAndLogEx(NORMAL, " Vendor ID : %02X, %s", data[1], getTagInfo(data[1]));
@ -824,8 +789,7 @@ static int ulc_magic_test(){
return returnValue;
}
*/
static int ul_magic_test()
{
static int ul_magic_test() {
// Magic Ultralight tests
// 1) take present UID, and try to write it back. OBSOLETE
// 2) make a wrong length write to page0, and see if tag answers with ACK/NACK:
@ -840,8 +804,7 @@ static int ul_magic_test()
return 0;
}
uint32_t GetHF14AMfU_Type(void)
{
uint32_t GetHF14AMfU_Type(void) {
TagTypeUL_t tagtype = UNKNOWN;
iso14a_card_select_t card;
@ -963,8 +926,7 @@ uint32_t GetHF14AMfU_Type(void)
//
// extended tag information
//
int CmdHF14AMfUInfo(const char *Cmd)
{
int CmdHF14AMfUInfo(const char *Cmd) {
uint8_t authlim = 0xff;
uint8_t data[16] = {0x00};
@ -1229,8 +1191,7 @@ out:
//
// Write Single Block
//
int CmdHF14AMfUWrBl(const char *Cmd)
{
int CmdHF14AMfUWrBl(const char *Cmd) {
int blockNo = -1;
bool errors = false;
@ -1351,8 +1312,7 @@ int CmdHF14AMfUWrBl(const char *Cmd)
//
// Read Single Block
//
int CmdHF14AMfURdBl(const char *Cmd)
{
int CmdHF14AMfURdBl(const char *Cmd) {
int blockNo = -1;
bool errors = false;
@ -1460,8 +1420,7 @@ int CmdHF14AMfURdBl(const char *Cmd)
return 0;
}
int usage_hf_mfu_info(void)
{
int usage_hf_mfu_info(void) {
PrintAndLogEx(NORMAL, "It gathers information about the tag and tries to detect what kind it is.");
PrintAndLogEx(NORMAL, "Sometimes the tags are locked down, and you may need a key to be able to read the information");
PrintAndLogEx(NORMAL, "The following tags can be identified:\n");
@ -1480,8 +1439,7 @@ int usage_hf_mfu_info(void)
return 0;
}
int usage_hf_mfu_dump(void)
{
int usage_hf_mfu_dump(void) {
PrintAndLogEx(NORMAL, "Reads all pages from Ultralight, Ultralight-C, Ultralight EV1");
PrintAndLogEx(NORMAL, "NTAG 203, NTAG 210, NTAG 212, NTAG 213, NTAG 215, NTAG 216");
PrintAndLogEx(NORMAL, "and saves binary dump into the file `filename.bin` or `cardUID.bin`");
@ -1502,8 +1460,7 @@ int usage_hf_mfu_dump(void)
return 0;
}
int usage_hf_mfu_restore(void)
{
int usage_hf_mfu_restore(void) {
PrintAndLogEx(NORMAL, "Restore dumpfile onto card.");
PrintAndLogEx(NORMAL, "Usage: hf mfu restore [h] [l] [s] k <key> n <filename w/o .bin> ");
PrintAndLogEx(NORMAL, " Options :");
@ -1521,8 +1478,7 @@ int usage_hf_mfu_restore(void)
return 0;
}
int usage_hf_mfu_rdbl(void)
{
int usage_hf_mfu_rdbl(void) {
PrintAndLogEx(NORMAL, "Read a block and print. It autodetects card type.\n");
PrintAndLogEx(NORMAL, "Usage: hf mfu rdbl b <block number> k <key> l\n");
PrintAndLogEx(NORMAL, "Options:");
@ -1537,8 +1493,7 @@ int usage_hf_mfu_rdbl(void)
return 0;
}
int usage_hf_mfu_wrbl(void)
{
int usage_hf_mfu_wrbl(void) {
PrintAndLogEx(NORMAL, "Write a block. It autodetects card type.\n");
PrintAndLogEx(NORMAL, "Usage: hf mfu wrbl b <block number> d <data> k <key> l\n");
PrintAndLogEx(NORMAL, "Options:");
@ -1553,8 +1508,7 @@ int usage_hf_mfu_wrbl(void)
return 0;
}
int usage_hf_mfu_eload(void)
{
int usage_hf_mfu_eload(void) {
PrintAndLogEx(NORMAL, "It loads emul dump from the file `filename.eml`");
PrintAndLogEx(NORMAL, "Hint: See script dumptoemul-mfu.lua to convert the .bin to the eml");
PrintAndLogEx(NORMAL, "Usage: hf mfu eload u <file name w/o `.eml`> [numblocks]");
@ -1569,8 +1523,7 @@ int usage_hf_mfu_eload(void)
return 0;
}
int usage_hf_mfu_sim(void)
{
int usage_hf_mfu_sim(void) {
PrintAndLogEx(NORMAL, "\nEmulating Ultralight tag from emulator memory\n");
PrintAndLogEx(NORMAL, "\nBe sure to load the emulator memory first!\n");
PrintAndLogEx(NORMAL, "Usage: hf mfu sim t 7 u <uid>");
@ -1586,8 +1539,7 @@ int usage_hf_mfu_sim(void)
return 0;
}
int usage_hf_mfu_ucauth(void)
{
int usage_hf_mfu_ucauth(void) {
PrintAndLogEx(NORMAL, "Usage: hf mfu cauth k <key number>");
PrintAndLogEx(NORMAL, " 0 (default): 3DES standard key");
PrintAndLogEx(NORMAL, " 1 : all 0x00 key");
@ -1602,8 +1554,7 @@ int usage_hf_mfu_ucauth(void)
return 0;
}
int usage_hf_mfu_ucsetpwd(void)
{
int usage_hf_mfu_ucsetpwd(void) {
PrintAndLogEx(NORMAL, "Usage: hf mfu setpwd <password (32 hex symbols)>");
PrintAndLogEx(NORMAL, " [password] - (32 hex symbols)");
PrintAndLogEx(NORMAL, "");
@ -1613,8 +1564,7 @@ int usage_hf_mfu_ucsetpwd(void)
return 0;
}
int usage_hf_mfu_ucsetuid(void)
{
int usage_hf_mfu_ucsetuid(void) {
PrintAndLogEx(NORMAL, "Usage: hf mfu setuid <uid (14 hex symbols)>");
PrintAndLogEx(NORMAL, " [uid] - (14 hex symbols)");
PrintAndLogEx(NORMAL, "\nThis only works for Magic Ultralight tags.");
@ -1625,8 +1575,7 @@ int usage_hf_mfu_ucsetuid(void)
return 0;
}
int usage_hf_mfu_gendiverse(void)
{
int usage_hf_mfu_gendiverse(void) {
PrintAndLogEx(NORMAL, "Usage: hf mfu gen [h] [r] <uid (8 hex symbols)>");
PrintAndLogEx(NORMAL, "Options:");
PrintAndLogEx(NORMAL, " h : this help");
@ -1639,8 +1588,7 @@ int usage_hf_mfu_gendiverse(void)
return 0;
}
int usage_hf_mfu_pwdgen(void)
{
int usage_hf_mfu_pwdgen(void) {
PrintAndLogEx(NORMAL, "Usage: hf mfu pwdgen [h|t] [r] <uid (14 hex symbols)>");
PrintAndLogEx(NORMAL, "Options:");
PrintAndLogEx(NORMAL, " h : this help");
@ -1655,13 +1603,11 @@ int usage_hf_mfu_pwdgen(void)
return 0;
}
void printMFUdump(mfu_dump_t *card)
{
void printMFUdump(mfu_dump_t *card) {
printMFUdumpEx(card, 255, 0);
}
void printMFUdumpEx(mfu_dump_t *card, uint16_t pages, uint8_t startpage)
{
void printMFUdumpEx(mfu_dump_t *card, uint16_t pages, uint8_t startpage) {
PrintAndLogEx(NORMAL, "\n*special* data\n");
PrintAndLogEx(NORMAL, "\nDataType | Data | Ascii");
PrintAndLogEx(NORMAL, "----------+-------------------------+---------");
@ -1807,8 +1753,7 @@ void printMFUdumpEx(mfu_dump_t *card, uint16_t pages, uint8_t startpage)
//
// Mifare Ultralight / Ultralight-C / Ultralight-EV1
// Read and Dump Card Contents, using auto detection of tag size.
int CmdHF14AMfUDump(const char *Cmd)
{
int CmdHF14AMfUDump(const char *Cmd) {
uint8_t fileNameLen = 0;
char filename[FILE_PATH_SIZE] = {0x00};
@ -2030,8 +1975,7 @@ int CmdHF14AMfUDump(const char *Cmd)
return 0;
}
static void wait4response(uint8_t b)
{
static void wait4response(uint8_t b) {
UsbCommand resp;
if (WaitForResponseTimeout(CMD_ACK, &resp, 1500)) {
uint8_t isOK = resp.arg[0] & 0xff;
@ -2045,8 +1989,7 @@ static void wait4response(uint8_t b)
//
// Restore dump file onto tag
//
int CmdHF14AMfURestore(const char *Cmd)
{
int CmdHF14AMfURestore(const char *Cmd) {
char tempStr[50] = {0};
char filename[FILE_PATH_SIZE] = {0};
@ -2277,8 +2220,7 @@ int CmdHF14AMfURestore(const char *Cmd)
//
// Load emulator with dump file
//
int CmdHF14AMfUeLoad(const char *Cmd)
{
int CmdHF14AMfUeLoad(const char *Cmd) {
char c = tolower(param_getchar(Cmd, 0));
if (c == 'h' || c == 0x00) return usage_hf_mfu_eload();
return CmdHF14AMfELoad(Cmd);
@ -2286,8 +2228,7 @@ int CmdHF14AMfUeLoad(const char *Cmd)
//
// Simulate tag
//
int CmdHF14AMfUSim(const char *Cmd)
{
int CmdHF14AMfUSim(const char *Cmd) {
char c = tolower(param_getchar(Cmd, 0));
if (c == 'h' || c == 0x00) return usage_hf_mfu_sim();
return CmdHF14ASim(Cmd);
@ -2300,8 +2241,7 @@ int CmdHF14AMfUSim(const char *Cmd)
//
// Ultralight C Authentication Demo {currently uses hard-coded key}
//
int CmdHF14AMfucAuth(const char *Cmd)
{
int CmdHF14AMfucAuth(const char *Cmd) {
uint8_t keyNo = 3;
bool errors = false;
@ -2428,8 +2368,7 @@ int CmdTestDES(const char * cmd)
//
// Mifare Ultralight C - Set password
//
int CmdHF14AMfucSetPwd(const char *Cmd)
{
int CmdHF14AMfucSetPwd(const char *Cmd) {
uint8_t pwd[16] = {0x00};
char cmdp = tolower(param_getchar(Cmd, 0));
@ -2464,8 +2403,7 @@ int CmdHF14AMfucSetPwd(const char *Cmd)
//
// Magic UL / UL-C tags - Set UID
//
int CmdHF14AMfucSetUid(const char *Cmd)
{
int CmdHF14AMfucSetUid(const char *Cmd) {
UsbCommand c = {CMD_MIFAREU_READBL};
UsbCommand resp;
@ -2534,8 +2472,7 @@ int CmdHF14AMfucSetUid(const char *Cmd)
return 0;
}
int CmdHF14AMfuGenDiverseKeys(const char *Cmd)
{
int CmdHF14AMfuGenDiverseKeys(const char *Cmd) {
uint8_t uid[4];
char cmdp = tolower(param_getchar(Cmd, 0));
@ -2648,8 +2585,7 @@ int CmdHF14AMfuGenDiverseKeys(const char *Cmd)
return 0;
}
int CmdHF14AMfuPwdGen(const char *Cmd)
{
int CmdHF14AMfuPwdGen(const char *Cmd) {
uint8_t uid[7] = {0x00};
char cmdp = tolower(param_getchar(Cmd, 0));
@ -2720,15 +2656,13 @@ static command_t CommandTable[] = {
{NULL, NULL, 0, NULL}
};
int CmdHFMFUltra(const char *Cmd)
{
int CmdHFMFUltra(const char *Cmd) {
clearCommandBuffer();
CmdsParse(CommandTable, Cmd);
return 0;
}
int CmdHelp(const char *Cmd)
{
int CmdHelp(const char *Cmd) {
CmdsHelp(CommandTable);
return 0;
}

View file

@ -30,21 +30,18 @@ static struct {
dynamic_lock_area_t *dynamic_lock_areas; // lock area descriptors
} topaz_tag;
static void topaz_switch_on_field(void)
{
static void topaz_switch_on_field(void) {
UsbCommand c = {CMD_READER_ISO_14443a, {ISO14A_CONNECT | ISO14A_NO_SELECT | ISO14A_NO_DISCONNECT | ISO14A_TOPAZMODE | ISO14A_NO_RATS, 0, 0}};
SendCommand(&c);
}
static void topaz_switch_off_field(void)
{
static void topaz_switch_off_field(void) {
UsbCommand c = {CMD_READER_ISO_14443a, {0, 0, 0}};
SendCommand(&c);
}
// send a raw topaz command, returns the length of the response (0 in case of error)
static int topaz_send_cmd_raw(uint8_t *cmd, uint8_t len, uint8_t *response)
{
static int topaz_send_cmd_raw(uint8_t *cmd, uint8_t len, uint8_t *response) {
UsbCommand c = {CMD_READER_ISO_14443a, {ISO14A_RAW | ISO14A_NO_DISCONNECT | ISO14A_TOPAZMODE | ISO14A_NO_RATS, len, 0}};
memcpy(c.d.asBytes, cmd, len);
SendCommand(&c);
@ -61,8 +58,7 @@ static int topaz_send_cmd_raw(uint8_t *cmd, uint8_t len, uint8_t *response)
// calculate CRC bytes and send topaz command, returns the length of the response (0 in case of error)
static int topaz_send_cmd(uint8_t *cmd, uint8_t len, uint8_t *response)
{
static int topaz_send_cmd(uint8_t *cmd, uint8_t len, uint8_t *response) {
if (len > 1) {
uint8_t b1, b2;
compute_crc(CRC_14443_B, cmd, len - 2, &b1, &b2);
@ -75,8 +71,7 @@ static int topaz_send_cmd(uint8_t *cmd, uint8_t len, uint8_t *response)
// select a topaz tag. Send WUPA and RID.
static int topaz_select(uint8_t *atqa, uint8_t *rid_response)
{
static int topaz_select(uint8_t *atqa, uint8_t *rid_response) {
// ToDo: implement anticollision
uint8_t wupa_cmd[] = {TOPAZ_WUPA};
@ -99,8 +94,7 @@ static int topaz_select(uint8_t *atqa, uint8_t *rid_response)
// read all of the static memory of a selected Topaz tag.
static int topaz_rall(uint8_t *uid, uint8_t *response)
{
static int topaz_rall(uint8_t *uid, uint8_t *response) {
uint8_t rall_cmd[] = {TOPAZ_RALL, 0, 0, 0, 0, 0, 0, 0, 0};
memcpy(&rall_cmd[3], uid, 4);
@ -114,8 +108,7 @@ static int topaz_rall(uint8_t *uid, uint8_t *response)
// read a block (8 Bytes) of a selected Topaz tag.
static int topaz_read_block(uint8_t *uid, uint8_t blockno, uint8_t *block_data)
{
static int topaz_read_block(uint8_t *uid, uint8_t blockno, uint8_t *block_data) {
uint8_t read8_cmd[] = {TOPAZ_READ8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
uint8_t read8_response[11];
@ -130,8 +123,7 @@ static int topaz_read_block(uint8_t *uid, uint8_t blockno, uint8_t *block_data)
}
// read a segment (16 blocks = 128 Bytes) of a selected Topaz tag. Works only for tags with dynamic memory.
static int topaz_read_segment(uint8_t *uid, uint8_t segno, uint8_t *segment_data)
{
static int topaz_read_segment(uint8_t *uid, uint8_t segno, uint8_t *segment_data) {
uint8_t rseg_cmd[] = {TOPAZ_RSEG, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
uint8_t rseg_response[131];
@ -146,8 +138,7 @@ static int topaz_read_segment(uint8_t *uid, uint8_t segno, uint8_t *segment_data
}
// search for the lock area descriptor for the lockable area including byteno
static dynamic_lock_area_t *get_dynamic_lock_area(uint16_t byteno)
{
static dynamic_lock_area_t *get_dynamic_lock_area(uint16_t byteno) {
dynamic_lock_area_t *lock_area;
lock_area = topaz_tag.dynamic_lock_areas;
@ -162,8 +153,7 @@ static dynamic_lock_area_t *get_dynamic_lock_area(uint16_t byteno)
}
// check if a memory byte is locked.
static bool topaz_byte_is_locked(uint16_t byteno)
{
static bool topaz_byte_is_locked(uint16_t byteno) {
uint8_t *lockbits;
uint16_t locked_bytes_per_bit;
dynamic_lock_area_t *lock_area;
@ -192,8 +182,7 @@ static bool topaz_byte_is_locked(uint16_t byteno)
// read and print the Capability Container
static int topaz_print_CC(uint8_t *data)
{
static int topaz_print_CC(uint8_t *data) {
if (data[0] != 0xe1) {
topaz_tag.size = TOPAZ_STATIC_MEMORY;
return -1; // no NDEF message
@ -214,8 +203,7 @@ static int topaz_print_CC(uint8_t *data)
// return type, length and value of a TLV, starting at memory position *TLV_ptr
static void get_TLV(uint8_t **TLV_ptr, uint8_t *TLV_type, uint16_t *TLV_length, uint8_t **TLV_value)
{
static void get_TLV(uint8_t **TLV_ptr, uint8_t *TLV_type, uint16_t *TLV_length, uint8_t **TLV_value) {
*TLV_length = 0;
*TLV_value = NULL;
@ -249,8 +237,7 @@ static void get_TLV(uint8_t **TLV_ptr, uint8_t *TLV_type, uint16_t *TLV_length,
// lock area TLVs contain no information on the start of the respective lockable area. Lockable areas
// do not include the lock bits and reserved memory. We therefore need to adjust the start of the
// respective lockable areas accordingly
static void adjust_lock_areas(uint16_t block_start, uint16_t block_size)
{
static void adjust_lock_areas(uint16_t block_start, uint16_t block_size) {
dynamic_lock_area_t *lock_area = topaz_tag.dynamic_lock_areas;
while (lock_area != NULL) {
if (lock_area->first_locked_byte <= block_start) {
@ -262,8 +249,7 @@ static void adjust_lock_areas(uint16_t block_start, uint16_t block_size)
// read and print the lock area and reserved memory TLVs
static void topaz_print_control_TLVs(uint8_t *memory)
{
static void topaz_print_control_TLVs(uint8_t *memory) {
uint8_t *TLV_ptr = memory;
uint8_t TLV_type = 0;
uint16_t TLV_length;
@ -336,8 +322,7 @@ static void topaz_print_control_TLVs(uint8_t *memory)
}
// read all of the dynamic memory
static int topaz_read_dynamic_data(void)
{
static int topaz_read_dynamic_data(void) {
// first read the remaining block of segment 0
if (topaz_read_block(topaz_tag.uid, 0x0f, &topaz_tag.dynamic_memory[0]) == -1) {
PrintAndLogEx(WARNING, "Error while reading dynamic memory block %02x. Aborting...", 0x0f);
@ -357,8 +342,7 @@ static int topaz_read_dynamic_data(void)
// read and print the dynamic memory
static void topaz_print_dynamic_data(void)
{
static void topaz_print_dynamic_data(void) {
if (topaz_tag.size > TOPAZ_STATIC_MEMORY) {
PrintAndLogEx(NORMAL, "Dynamic Data blocks:");
if (topaz_read_dynamic_data() == 0) {
@ -378,19 +362,16 @@ static void topaz_print_dynamic_data(void)
}
}
static void topaz_print_lifecycle_state(uint8_t *data)
{
static void topaz_print_lifecycle_state(uint8_t *data) {
// to be done
}
static void topaz_print_NDEF(uint8_t *data)
{
static void topaz_print_NDEF(uint8_t *data) {
// to be done.
}
// read a Topaz tag and print some useful information
int CmdHFTopazReader(const char *Cmd)
{
int CmdHFTopazReader(const char *Cmd) {
int status;
uint8_t atqa[2];
uint8_t rid_response[8];
@ -506,20 +487,17 @@ int CmdHFTopazReader(const char *Cmd)
return 0;
}
int CmdHFTopazSim(const char *Cmd)
{
int CmdHFTopazSim(const char *Cmd) {
PrintAndLogEx(NORMAL, "not yet implemented");
return 0;
}
int CmdHFTopazCmdRaw(const char *Cmd)
{
int CmdHFTopazCmdRaw(const char *Cmd) {
PrintAndLogEx(NORMAL, "not yet implemented. Use hf 14 raw with option -T.");
return 0;
}
int CmdHFTopazList(const char *Cmd)
{
int CmdHFTopazList(const char *Cmd) {
CmdTraceList("topaz");
return 0;
}
@ -536,15 +514,13 @@ static command_t CommandTable[] = {
{NULL, NULL, 0, NULL}
};
int CmdHFTopaz(const char *Cmd)
{
int CmdHFTopaz(const char *Cmd) {
clearCommandBuffer();
CmdsParse(CommandTable, Cmd);
return 0;
}
static int CmdHelp(const char *Cmd)
{
static int CmdHelp(const char *Cmd) {
CmdsHelp(CommandTable);
return 0;
}

View file

@ -23,8 +23,7 @@
static int CmdHelp(const char *Cmd);
static void lookupChipID(uint32_t iChipID, uint32_t mem_used)
{
static void lookupChipID(uint32_t iChipID, uint32_t mem_used) {
char asBuff[120];
memset(asBuff, 0, sizeof(asBuff));
uint32_t mem_avail = 0;
@ -308,8 +307,7 @@ static void lookupChipID(uint32_t iChipID, uint32_t mem_used)
PrintAndLogEx(NORMAL, " --= Nonvolatile Program Memory Type: %s", asBuff);
}
int CmdDetectReader(const char *Cmd)
{
int CmdDetectReader(const char *Cmd) {
UsbCommand c = {CMD_LISTEN_READER_FIELD};
// 'l' means LF - 125/134 kHz
if (*Cmd == 'l') {
@ -326,8 +324,7 @@ int CmdDetectReader(const char *Cmd)
}
// ## FPGA Control
int CmdFPGAOff(const char *Cmd)
{
int CmdFPGAOff(const char *Cmd) {
UsbCommand c = {CMD_FPGA_MAJOR_MODE_OFF};
clearCommandBuffer();
SendCommand(&c);
@ -335,8 +332,7 @@ int CmdFPGAOff(const char *Cmd)
}
#ifdef WITH_LCD
int CmdLCD(const char *Cmd)
{
int CmdLCD(const char *Cmd) {
int i, j;
UsbCommand c = {CMD_LCD};
@ -349,8 +345,7 @@ int CmdLCD(const char *Cmd)
return 0;
}
int CmdLCDReset(const char *Cmd)
{
int CmdLCDReset(const char *Cmd) {
UsbCommand c = {CMD_LCD_RESET, {strtol(Cmd, NULL, 0), 0, 0}};
clearCommandBuffer();
SendCommand(&c);
@ -358,16 +353,14 @@ int CmdLCDReset(const char *Cmd)
}
#endif
int CmdReadmem(const char *Cmd)
{
int CmdReadmem(const char *Cmd) {
UsbCommand c = {CMD_READ_MEM, {strtol(Cmd, NULL, 0), 0, 0}};
clearCommandBuffer();
SendCommand(&c);
return 0;
}
int CmdReset(const char *Cmd)
{
int CmdReset(const char *Cmd) {
UsbCommand c = {CMD_HARDWARE_RESET};
clearCommandBuffer();
SendCommand(&c);
@ -378,8 +371,7 @@ int CmdReset(const char *Cmd)
* Sets the divisor for LF frequency clock: lets the user choose any LF frequency below
* 600kHz.
*/
int CmdSetDivisor(const char *Cmd)
{
int CmdSetDivisor(const char *Cmd) {
UsbCommand c = {CMD_SET_LF_DIVISOR, {strtol(Cmd, NULL, 0), 0, 0}};
if (c.arg[0] < 19 || c.arg[0] > 255) {
@ -393,8 +385,7 @@ int CmdSetDivisor(const char *Cmd)
return 0;
}
int CmdSetMux(const char *Cmd)
{
int CmdSetMux(const char *Cmd) {
if (strlen(Cmd) < 5) {
PrintAndLogEx(NORMAL, "expected: lopkd | loraw | hipkd | hiraw");
@ -412,13 +403,11 @@ int CmdSetMux(const char *Cmd)
return 0;
}
int CmdTune(const char *Cmd)
{
int CmdTune(const char *Cmd) {
return CmdTuneSamples(Cmd);
}
int CmdVersion(const char *Cmd)
{
int CmdVersion(const char *Cmd) {
bool silent = (Cmd[0] == 's' || Cmd[0] == 'S');
if (silent)
@ -457,8 +446,7 @@ int CmdVersion(const char *Cmd)
return 0;
}
int CmdStatus(const char *Cmd)
{
int CmdStatus(const char *Cmd) {
clearCommandBuffer();
UsbCommand c = {CMD_STATUS};
SendCommand(&c);
@ -467,8 +455,7 @@ int CmdStatus(const char *Cmd)
return 0;
}
int CmdPing(const char *Cmd)
{
int CmdPing(const char *Cmd) {
clearCommandBuffer();
UsbCommand resp;
UsbCommand c = {CMD_PING};
@ -499,15 +486,13 @@ static command_t CommandTable[] = {
{NULL, NULL, 0, NULL}
};
int CmdHW(const char *Cmd)
{
int CmdHW(const char *Cmd) {
clearCommandBuffer();
CmdsParse(CommandTable, Cmd);
return 0;
}
int CmdHelp(const char *Cmd)
{
int CmdHelp(const char *Cmd) {
CmdsHelp(CommandTable);
return 0;
}

View file

@ -13,8 +13,7 @@ bool g_lf_threshold_set = false;
static int CmdHelp(const char *Cmd);
int usage_lf_cmdread(void)
{
int usage_lf_cmdread(void) {
PrintAndLogEx(NORMAL, "Usage: lf cmdread d <delay period> z <zero period> o <one period> c <cmdbytes>");
PrintAndLogEx(NORMAL, "Options:");
PrintAndLogEx(NORMAL, " h This help");
@ -29,8 +28,7 @@ int usage_lf_cmdread(void)
PrintAndLogEx(NORMAL, " lf cmdread d 80 z 100 o 200 c 11000");
return 0;
}
int usage_lf_read(void)
{
int usage_lf_read(void) {
PrintAndLogEx(NORMAL, "Usage: lf read [h] [s] [d numofsamples]");
PrintAndLogEx(NORMAL, "Options:");
PrintAndLogEx(NORMAL, " h This help");
@ -43,8 +41,7 @@ int usage_lf_read(void)
PrintAndLogEx(NORMAL, " lf read s");
return 0;
}
int usage_lf_snoop(void)
{
int usage_lf_snoop(void) {
PrintAndLogEx(NORMAL, "Snoop low frequence signal. Use 'lf config' to set parameters.");
PrintAndLogEx(NORMAL, "Usage: lf snoop [h]");
PrintAndLogEx(NORMAL, "Options:");
@ -53,8 +50,7 @@ int usage_lf_snoop(void)
PrintAndLogEx(NORMAL, "Use 'lf config' to set parameters.");
return 0;
}
int usage_lf_config(void)
{
int usage_lf_config(void) {
PrintAndLogEx(NORMAL, "Usage: lf config [h] [H|<divisor>] [b <bps>] [d <decim>] [a 0|1]");
PrintAndLogEx(NORMAL, "Options:");
PrintAndLogEx(NORMAL, " h This help");
@ -77,8 +73,7 @@ int usage_lf_config(void)
PrintAndLogEx(NORMAL, " Performs a snoop (no active field)");
return 0;
}
int usage_lf_simfsk(void)
{
int usage_lf_simfsk(void) {
PrintAndLogEx(NORMAL, "Usage: lf simfsk [h] [c <clock>] [H <fcHigh>] [L <fcLow>] [d <hexdata>]");
PrintAndLogEx(NORMAL, "there are about four FSK modulations to know of.");
PrintAndLogEx(NORMAL, "FSK1 - where fc/8 = high and fc/5 = low");
@ -103,8 +98,7 @@ int usage_lf_simfsk(void)
PrintAndLogEx(NORMAL, "");
return 0;
}
int usage_lf_simask(void)
{
int usage_lf_simask(void) {
PrintAndLogEx(NORMAL, "Usage: lf simask [c <clock>] [i] [b|m|r] [s] [d <raw hex to sim>]");
PrintAndLogEx(NORMAL, "Options:");
PrintAndLogEx(NORMAL, " h This help");
@ -117,8 +111,7 @@ int usage_lf_simask(void)
PrintAndLogEx(NORMAL, " d <hexdata> Data to sim as hex - omit to sim from DemodBuffer");
return 0;
}
int usage_lf_simpsk(void)
{
int usage_lf_simpsk(void) {
PrintAndLogEx(NORMAL, "Usage: lf simpsk [1|2|3] [c <clock>] [i] [r <carrier>] [d <raw hex to sim>]");
PrintAndLogEx(NORMAL, "Options:");
PrintAndLogEx(NORMAL, " h This help");
@ -131,8 +124,7 @@ int usage_lf_simpsk(void)
PrintAndLogEx(NORMAL, " d <hexdata> Data to sim as hex - omit to sim from DemodBuffer");
return 0;
}
int usage_lf_find(void)
{
int usage_lf_find(void) {
PrintAndLogEx(NORMAL, "Usage: lf search [h] <0|1> [u]");
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(NORMAL, "Options:");
@ -149,8 +141,7 @@ int usage_lf_find(void)
/* send a LF command before reading */
int CmdLFCommandRead(const char *Cmd)
{
int CmdLFCommandRead(const char *Cmd) {
UsbCommand c = {CMD_MOD_THEN_ACQUIRE_RAW_ADC_SAMPLES_125K, {0, 0, 0}};
bool errors = false;
@ -194,8 +185,7 @@ int CmdLFCommandRead(const char *Cmd)
return 0;
}
int CmdFlexdemod(const char *Cmd)
{
int CmdFlexdemod(const char *Cmd) {
if (GraphTraceLen < 0)
return 0;
@ -272,8 +262,7 @@ int CmdFlexdemod(const char *Cmd)
return 0;
}
int CmdLFSetConfig(const char *Cmd)
{
int CmdLFSetConfig(const char *Cmd) {
uint8_t divisor = 0;//Frequency divisor
uint8_t bps = 0; // Bits per sample
uint8_t decimation = 0; //How many to keep
@ -341,8 +330,7 @@ int CmdLFSetConfig(const char *Cmd)
return 0;
}
bool lf_read(bool silent, uint32_t samples)
{
bool lf_read(bool silent, uint32_t samples) {
if (IsOffline()) return false;
UsbCommand c = {CMD_ACQUIRE_RAW_ADC_SAMPLES_125K, {silent, samples, 0}};
clearCommandBuffer();
@ -363,8 +351,7 @@ bool lf_read(bool silent, uint32_t samples)
return true;
}
int CmdLFRead(const char *Cmd)
{
int CmdLFRead(const char *Cmd) {
if (IsOffline()) return 0;
@ -397,8 +384,7 @@ int CmdLFRead(const char *Cmd)
return lf_read(silent, samples);
}
int CmdLFSnoop(const char *Cmd)
{
int CmdLFSnoop(const char *Cmd) {
uint8_t cmdp = tolower(param_getchar(Cmd, 0));
if (cmdp == 'h') return usage_lf_snoop();
@ -410,8 +396,7 @@ int CmdLFSnoop(const char *Cmd)
return 0;
}
static void ChkBitstream(const char *str)
{
static void ChkBitstream(const char *str) {
// convert to bitstream if necessary
for (int i = 0; i < (int)(GraphTraceLen / 2); i++) {
if (GraphBuffer[i] > 1 || GraphBuffer[i] < 0) {
@ -422,8 +407,7 @@ static void ChkBitstream(const char *str)
}
//Attempt to simulate any wave in buffer (one bit per output sample)
// converts GraphBuffer to bitstream (based on zero crossings) if needed.
int CmdLFSim(const char *Cmd)
{
int CmdLFSim(const char *Cmd) {
#define FPGA_LF 1
#define FPGA_HF 2
@ -459,8 +443,7 @@ int CmdLFSim(const char *Cmd)
// by marshmellow - sim fsk data given clock, fcHigh, fcLow, invert
// - allow pull data from DemodBuffer
int CmdLFfskSim(const char *Cmd)
{
int CmdLFfskSim(const char *Cmd) {
//might be able to autodetect FCs and clock from Graphbuffer if using demod buffer
// otherwise will need FChigh, FClow, Clock, and bitstream
uint8_t fcHigh = 0, fcLow = 0, clk = 0;
@ -553,8 +536,7 @@ int CmdLFfskSim(const char *Cmd)
// by marshmellow - sim ask data given clock, invert, manchester or raw, separator
// - allow pull data from DemodBuffer
int CmdLFaskSim(const char *Cmd)
{
int CmdLFaskSim(const char *Cmd) {
// autodetect clock from Graphbuffer if using demod buffer
// needs clock, invert, manchester/raw as m or r, separator as s, and bitstream
uint8_t encoding = 1, separator = 0, clk = 0, invert = 0;
@ -647,8 +629,7 @@ int CmdLFaskSim(const char *Cmd)
// by marshmellow - sim psk data given carrier, clock, invert
// - allow pull data from DemodBuffer or parameters
int CmdLFpskSim(const char *Cmd)
{
int CmdLFpskSim(const char *Cmd) {
//might be able to autodetect FC and clock from Graphbuffer if using demod buffer
//will need carrier, Clock, and bitstream
uint8_t carrier = 0, clk = 0;
@ -754,8 +735,7 @@ int CmdLFpskSim(const char *Cmd)
return 0;
}
int CmdLFSimBidir(const char *Cmd)
{
int CmdLFSimBidir(const char *Cmd) {
// Set ADC to twice the carrier for a slight supersampling
// HACK: not implemented in ARMSRC.
PrintAndLogEx(INFO, "Not implemented yet.");
@ -765,8 +745,7 @@ int CmdLFSimBidir(const char *Cmd)
}
// ICEMAN, todo, swap from Graphbuffer.
int CmdVchDemod(const char *Cmd)
{
int CmdVchDemod(const char *Cmd) {
// Is this the entire sync pattern, or does this also include some
// data bits that happen to be the same everywhere? That would be
// lovely to know.
@ -839,8 +818,7 @@ int CmdVchDemod(const char *Cmd)
}
//by marshmellow
bool CheckChipType(bool getDeviceData)
{
bool CheckChipType(bool getDeviceData) {
bool retval = false;
@ -873,8 +851,7 @@ out:
}
//by marshmellow
int CmdLFfind(const char *Cmd)
{
int CmdLFfind(const char *Cmd) {
int ans = 0;
size_t minLength = 2000;
char cmdp = tolower(param_getchar(Cmd, 0));
@ -1026,15 +1003,13 @@ static command_t CommandTable[] = {
{NULL, NULL, 0, NULL}
};
int CmdLF(const char *Cmd)
{
int CmdLF(const char *Cmd) {
clearCommandBuffer();
CmdsParse(CommandTable, Cmd);
return 0;
}
int CmdHelp(const char *Cmd)
{
int CmdHelp(const char *Cmd) {
CmdsHelp(CommandTable);
return 0;
}

View file

@ -14,8 +14,7 @@
static int CmdHelp(const char *Cmd);
int usage_lf_awid_read(void)
{
int usage_lf_awid_read(void) {
PrintAndLogEx(NORMAL, "Enables AWID compatible reader mode printing details of scanned AWID26 or AWID50 tags.");
PrintAndLogEx(NORMAL, "By default, values are printed and logged until the button is pressed or another USB command is issued.");
PrintAndLogEx(NORMAL, "If the [1] option is provided, reader mode is exited after reading a single AWID card.");
@ -31,8 +30,7 @@ int usage_lf_awid_read(void)
return 0;
}
int usage_lf_awid_sim(void)
{
int usage_lf_awid_sim(void) {
PrintAndLogEx(NORMAL, "Enables simulation of AWID card with specified facility-code and card number.");
PrintAndLogEx(NORMAL, "Simulation runs until the button is pressed or another USB command is issued.");
PrintAndLogEx(NORMAL, "");
@ -49,8 +47,7 @@ int usage_lf_awid_sim(void)
return 0;
}
int usage_lf_awid_clone(void)
{
int usage_lf_awid_clone(void) {
PrintAndLogEx(NORMAL, "Enables cloning of AWID card with specified facility-code and card number onto T55x7.");
PrintAndLogEx(NORMAL, "The T55x7 must be on the antenna when issuing this command. T55x7 blocks are calculated and printed in the process.");
PrintAndLogEx(NORMAL, "");
@ -68,8 +65,7 @@ int usage_lf_awid_clone(void)
return 0;
}
int usage_lf_awid_brute(void)
{
int usage_lf_awid_brute(void) {
PrintAndLogEx(NORMAL, "Enables bruteforce of AWID reader with specified facility-code.");
PrintAndLogEx(NORMAL, "This is a attack against reader. if cardnumber is given, it starts with it and goes up / down one step");
PrintAndLogEx(NORMAL, "if cardnumber is not given, it starts with 1 and goes up to 65535");
@ -90,8 +86,7 @@ int usage_lf_awid_brute(void)
return 0;
}
static bool sendPing(void)
{
static bool sendPing(void) {
UsbCommand ping = {CMD_PING, {1, 2, 3}};
SendCommand(&ping);
SendCommand(&ping);
@ -103,8 +98,7 @@ static bool sendPing(void)
return true;
}
static bool sendTry(uint8_t fmtlen, uint32_t fc, uint32_t cn, uint32_t delay, uint8_t *bits, size_t bs_len, bool verbose)
{
static bool sendTry(uint8_t fmtlen, uint32_t fc, uint32_t cn, uint32_t delay, uint8_t *bits, size_t bs_len, bool verbose) {
if (verbose)
PrintAndLogEx(INFO, "Trying FC: %u; CN: %u", fc, cn);
@ -129,8 +123,7 @@ static bool sendTry(uint8_t fmtlen, uint32_t fc, uint32_t cn, uint32_t delay, ui
}
//refactored by marshmellow
int getAWIDBits(uint8_t fmtlen, uint32_t fc, uint32_t cn, uint8_t *bits)
{
int getAWIDBits(uint8_t fmtlen, uint32_t fc, uint32_t cn, uint8_t *bits) {
// the return bits, preamble 0000 0001
bits[7] = 1;
@ -183,8 +176,7 @@ int getAWIDBits(uint8_t fmtlen, uint32_t fc, uint32_t cn, uint8_t *bits)
return 1;
}
static void verify_values(uint8_t *fmtlen, uint32_t *fc, uint32_t *cn)
{
static void verify_values(uint8_t *fmtlen, uint32_t *fc, uint32_t *cn) {
switch (*fmtlen) {
case 50:
if ((*fc & 0xFFFF) != *fc) {
@ -228,15 +220,13 @@ static void verify_values(uint8_t *fmtlen, uint32_t *fc, uint32_t *cn)
}
// this read is the "normal" read, which download lf signal and tries to demod here.
int CmdAWIDRead(const char *Cmd)
{
int CmdAWIDRead(const char *Cmd) {
lf_read(true, 12000);
return CmdAWIDDemod(Cmd);
}
// this read loops on device side.
// uses the demod in lfops.c
int CmdAWIDRead_device(const char *Cmd)
{
int CmdAWIDRead_device(const char *Cmd) {
if (Cmd[0] == 'h' || Cmd[0] == 'H') return usage_lf_awid_read();
uint8_t findone = (Cmd[0] == '1') ? 1 : 0;
@ -249,8 +239,7 @@ int CmdAWIDRead_device(const char *Cmd)
//by marshmellow
//AWID Prox demod - FSK2a RF/50 with preamble of 00000001 (always a 96 bit data stream)
//print full AWID Prox ID and some bit format details if found
int CmdAWIDDemod(const char *Cmd)
{
int CmdAWIDDemod(const char *Cmd) {
uint8_t bits[MAX_GRAPH_TRACE_LEN] = {0};
size_t size = getFromGraphBuf(bits);
if (size == 0) {
@ -380,8 +369,7 @@ int CmdAWIDDemod(const char *Cmd)
return 1;
}
int CmdAWIDSim(const char *Cmd)
{
int CmdAWIDSim(const char *Cmd) {
uint32_t fc = 0, cn = 0;
uint8_t fmtlen = 0;
uint8_t bits[96];
@ -421,8 +409,7 @@ int CmdAWIDSim(const char *Cmd)
return 0;
}
int CmdAWIDClone(const char *Cmd)
{
int CmdAWIDClone(const char *Cmd) {
uint32_t blocks[4] = {T55x7_MODULATION_FSK2a | T55x7_BITRATE_RF_50 | 3 << T55x7_MAXBLOCK_SHIFT, 0, 0, 0};
uint32_t fc = 0, cn = 0;
uint8_t fmtlen = 0;
@ -473,8 +460,7 @@ int CmdAWIDClone(const char *Cmd)
return 0;
}
int CmdAWIDBrute(const char *Cmd)
{
int CmdAWIDBrute(const char *Cmd) {
bool errors = false, verbose = false;
uint32_t fc = 0, cn = 0, delay = 1000;
@ -580,15 +566,13 @@ static command_t CommandTable[] = {
{NULL, NULL, 0, NULL}
};
int CmdLFAWID(const char *Cmd)
{
int CmdLFAWID(const char *Cmd) {
clearCommandBuffer();
CmdsParse(CommandTable, Cmd);
return 0;
}
int CmdHelp(const char *Cmd)
{
int CmdHelp(const char *Cmd) {
CmdsHelp(CommandTable);
return 0;
}

View file

@ -11,8 +11,7 @@
static int CmdHelp(const char *Cmd);
int usage_lf_cotag_read(void)
{
int usage_lf_cotag_read(void) {
PrintAndLogEx(NORMAL, "Usage: lf COTAG read [h] <signaldata>");
PrintAndLogEx(NORMAL, "Options:");
PrintAndLogEx(NORMAL, " h : This help");
@ -28,8 +27,7 @@ int usage_lf_cotag_read(void)
// COTAG demod should be able to use GraphBuffer,
// when data load samples
int CmdCOTAGDemod(const char *Cmd)
{
int CmdCOTAGDemod(const char *Cmd) {
uint8_t bits[COTAG_BITS] = {0};
size_t bitlen = COTAG_BITS;
@ -68,8 +66,7 @@ int CmdCOTAGDemod(const char *Cmd)
// 0 = HIGH/LOW signal - maxlength bigbuff
// 1 = translation for HI/LO into bytes with manchester 0,1 - length 300
// 2 = raw signal - maxlength bigbuff
int CmdCOTAGRead(const char *Cmd)
{
int CmdCOTAGRead(const char *Cmd) {
if (Cmd[0] == 'h' || Cmd[0] == 'H') return usage_lf_cotag_read();
@ -112,15 +109,13 @@ static command_t CommandTable[] = {
{NULL, NULL, 0, NULL}
};
int CmdLFCOTAG(const char *Cmd)
{
int CmdLFCOTAG(const char *Cmd) {
clearCommandBuffer();
CmdsParse(CommandTable, Cmd);
return 0;
}
int CmdHelp(const char *Cmd)
{
int CmdHelp(const char *Cmd) {
CmdsHelp(CommandTable);
return 0;
}

View file

@ -15,8 +15,7 @@ uint64_t g_em410xid = 0;
static int CmdHelp(const char *Cmd);
//////////////// 410x commands
int usage_lf_em410x_demod(void)
{
int usage_lf_em410x_demod(void) {
PrintAndLogEx(NORMAL, "Usage: lf em 410x_demod [h] [clock] <0|1> [maxError]");
PrintAndLogEx(NORMAL, "Options:");
PrintAndLogEx(NORMAL, " h - this help");
@ -32,8 +31,7 @@ int usage_lf_em410x_demod(void)
PrintAndLogEx(NORMAL, " lf em 410x_demod 64 1 0 = demod an EM410x Tag ID from GraphBuffer using a clock of RF/64 and inverting data and allowing 0 demod errors");
return 0;
}
int usage_lf_em410x_write(void)
{
int usage_lf_em410x_write(void) {
PrintAndLogEx(NORMAL, "Writes EM410x ID to a T55x7 / T5555 (Q5) tag");
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(NORMAL, "Usage: lf em 410x_write [h] <id> <card> [clock]");
@ -46,8 +44,7 @@ int usage_lf_em410x_write(void)
PrintAndLogEx(NORMAL, " lf em 410x_write 0F0368568B 1 = write ID to t55x7 card");
return 0;
}
int usage_lf_em410x_ws(void)
{
int usage_lf_em410x_ws(void) {
PrintAndLogEx(NORMAL, "Watch 'nd Spoof, activates reader, waits until a EM410x tag gets presented then it starts simulating the found UID");
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(NORMAL, "Usage: lf em 410x_spoof [h]");
@ -57,8 +54,7 @@ int usage_lf_em410x_ws(void)
PrintAndLogEx(NORMAL, " lf em 410x_spoof");
return 0;
}
int usage_lf_em410x_clone(void)
{
int usage_lf_em410x_clone(void) {
PrintAndLogEx(NORMAL, "Simulating EM410x tag");
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(NORMAL, "Usage: lf em 410x_clone [h] <uid> <clock>");
@ -71,8 +67,7 @@ int usage_lf_em410x_clone(void)
PrintAndLogEx(NORMAL, " lf em 410x_clone 0F0368568B 32");
return 0;
}
int usage_lf_em410x_sim(void)
{
int usage_lf_em410x_sim(void) {
PrintAndLogEx(NORMAL, "Simulating EM410x tag");
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(NORMAL, "Usage: lf em 410x_sim [h] <uid> <clock>");
@ -85,8 +80,7 @@ int usage_lf_em410x_sim(void)
PrintAndLogEx(NORMAL, " lf em 410x_sim 0F0368568B 32");
return 0;
}
int usage_lf_em410x_brute(void)
{
int usage_lf_em410x_brute(void) {
PrintAndLogEx(NORMAL, "Bruteforcing by emulating EM410x tag");
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(NORMAL, "Usage: lf em 410x_brute [h] ids.txt [d 2000] [c clock]");
@ -104,8 +98,7 @@ int usage_lf_em410x_brute(void)
}
//////////////// 4050 / 4450 commands
int usage_lf_em4x50_dump(void)
{
int usage_lf_em4x50_dump(void) {
PrintAndLogEx(NORMAL, "Dump EM4x50/EM4x69. Tag must be on antenna. ");
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(NORMAL, "Usage: lf em 4x50_dump [h] <pwd>");
@ -117,8 +110,7 @@ int usage_lf_em4x50_dump(void)
PrintAndLogEx(NORMAL, " lf em 4x50_dump 11223344");
return 0;
}
int usage_lf_em4x50_read(void)
{
int usage_lf_em4x50_read(void) {
PrintAndLogEx(NORMAL, "Read EM 4x50/EM4x69. Tag must be on antenna. ");
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(NORMAL, "Usage: lf em 4x50_read [h] <address> <pwd>");
@ -131,8 +123,7 @@ int usage_lf_em4x50_read(void)
PrintAndLogEx(NORMAL, " lf em 4x50_read 1 11223344");
return 0;
}
int usage_lf_em4x50_write(void)
{
int usage_lf_em4x50_write(void) {
PrintAndLogEx(NORMAL, "Write EM 4x50/4x69. Tag must be on antenna. ");
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(NORMAL, "Usage: lf em 4x50_write [h] <address> <data> <pwd>");
@ -148,8 +139,7 @@ int usage_lf_em4x50_write(void)
}
//////////////// 4205 / 4305 commands
int usage_lf_em4x05_dump(void)
{
int usage_lf_em4x05_dump(void) {
PrintAndLogEx(NORMAL, "Dump EM4x05/EM4x69. Tag must be on antenna. ");
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(NORMAL, "Usage: lf em 4x05_dump [h] <pwd>");
@ -161,8 +151,7 @@ int usage_lf_em4x05_dump(void)
PrintAndLogEx(NORMAL, " lf em 4x05_dump 11223344");
return 0;
}
int usage_lf_em4x05_read(void)
{
int usage_lf_em4x05_read(void) {
PrintAndLogEx(NORMAL, "Read EM4x05/EM4x69. Tag must be on antenna. ");
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(NORMAL, "Usage: lf em 4x05_read [h] <address> <pwd>");
@ -175,8 +164,7 @@ int usage_lf_em4x05_read(void)
PrintAndLogEx(NORMAL, " lf em 4x05_read 1 11223344");
return 0;
}
int usage_lf_em4x05_write(void)
{
int usage_lf_em4x05_write(void) {
PrintAndLogEx(NORMAL, "Write EM4x05/4x69. Tag must be on antenna. ");
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(NORMAL, "Usage: lf em 4x05_write [h] <address> <data> <pwd>");
@ -190,8 +178,7 @@ int usage_lf_em4x05_write(void)
PrintAndLogEx(NORMAL, " lf em 4x05_write 1 deadc0de 11223344");
return 0;
}
int usage_lf_em4x05_info(void)
{
int usage_lf_em4x05_info(void) {
PrintAndLogEx(NORMAL, "Tag information EM4205/4305/4469//4569 tags. Tag must be on antenna.");
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(NORMAL, "Usage: lf em 4x05_info [h] <pwd>");
@ -214,8 +201,7 @@ int usage_lf_em4x05_info(void)
*/
// Construct the graph for emulating an EM410X tag
void ConstructEM410xEmulGraph(const char *uid, const uint8_t clock)
{
void ConstructEM410xEmulGraph(const char *uid, const uint8_t clock) {
int i, j, binary[4], parity[4];
uint32_t n;
@ -262,8 +248,7 @@ void ConstructEM410xEmulGraph(const char *uid, const uint8_t clock)
//by marshmellow
//print 64 bit EM410x ID in multiple formats
void printEM410x(uint32_t hi, uint64_t id)
{
void printEM410x(uint32_t hi, uint64_t id) {
if (!id && !hi) return;
@ -367,8 +352,7 @@ void printEM410x(uint32_t hi, uint64_t id)
* CCCC <-- each bit here is parity for the 10 bits above in corresponding column
* 0 <-- stop bit, end of tag
*/
int AskEm410xDecode(bool verbose, uint32_t *hi, uint64_t *lo)
{
int AskEm410xDecode(bool verbose, uint32_t *hi, uint64_t *lo) {
size_t idx = 0;
uint8_t bits[512] = {0};
size_t size = sizeof(bits);
@ -409,24 +393,21 @@ int AskEm410xDecode(bool verbose, uint32_t *hi, uint64_t *lo)
return 1;
}
int AskEm410xDemod(const char *Cmd, uint32_t *hi, uint64_t *lo, bool verbose)
{
int AskEm410xDemod(const char *Cmd, uint32_t *hi, uint64_t *lo, bool verbose) {
bool st = true;
if (!ASKDemod_ext(Cmd, false, false, 1, &st)) return 0;
return AskEm410xDecode(verbose, hi, lo);
}
// this read is the "normal" read, which download lf signal and tries to demod here.
int CmdEM410xRead(const char *Cmd)
{
int CmdEM410xRead(const char *Cmd) {
lf_read(true, 8192);
return CmdEM410xDemod(Cmd);
}
// this read loops on device side.
// uses the demod in lfops.c
int CmdEM410xRead_device(const char *Cmd)
{
int CmdEM410xRead_device(const char *Cmd) {
char cmdp = tolower(param_getchar(Cmd, 0));
uint8_t findone = (cmdp == '1') ? 1 : 0;
UsbCommand c = {CMD_EM410X_DEMOD, {findone, 0, 0}};
@ -438,8 +419,7 @@ int CmdEM410xRead_device(const char *Cmd)
//takes 3 arguments - clock, invert and maxErr as integers
//attempts to demodulate ask while decoding manchester
//prints binary found and saves in graphbuffer for further commands
int CmdEM410xDemod(const char *Cmd)
{
int CmdEM410xDemod(const char *Cmd) {
char cmdp = tolower(param_getchar(Cmd, 0));
if (strlen(Cmd) > 10 || cmdp == 'h') return usage_lf_em410x_demod();
@ -453,8 +433,7 @@ int CmdEM410xDemod(const char *Cmd)
}
// emulate an EM410X tag
int CmdEM410xSim(const char *Cmd)
{
int CmdEM410xSim(const char *Cmd) {
char cmdp = tolower(param_getchar(Cmd, 0));
if (cmdp == 'h') return usage_lf_em410x_sim();
@ -479,8 +458,7 @@ int CmdEM410xSim(const char *Cmd)
return 0;
}
int CmdEM410xBrute(const char *Cmd)
{
int CmdEM410xBrute(const char *Cmd) {
char filename[FILE_PATH_SIZE] = {0};
FILE *f = NULL;
char buf[11];
@ -602,8 +580,7 @@ int CmdEM410xBrute(const char *Cmd)
*
* EDIT -- capture enough to get 2 complete preambles at the slowest data rate known to be used (rf/64) (64*64*2+9 = 8201) marshmellow
*/
int CmdEM410xWatch(const char *Cmd)
{
int CmdEM410xWatch(const char *Cmd) {
do {
if (ukbhit()) {
int gc = getchar();
@ -618,8 +595,7 @@ int CmdEM410xWatch(const char *Cmd)
}
//currently only supports manchester modulations
int CmdEM410xWatchnSpoof(const char *Cmd)
{
int CmdEM410xWatchnSpoof(const char *Cmd) {
char cmdp = tolower(param_getchar(Cmd, 0));
if (cmdp == 'h') return usage_lf_em410x_ws();
@ -631,8 +607,7 @@ int CmdEM410xWatchnSpoof(const char *Cmd)
return 0;
}
int CmdEM410xWrite(const char *Cmd)
{
int CmdEM410xWrite(const char *Cmd) {
char cmdp = tolower(param_getchar(Cmd, 0));
if (cmdp == 0x00 || cmdp == 'h') return usage_lf_em410x_write();
@ -693,8 +668,7 @@ int CmdEM410xWrite(const char *Cmd)
}
//**************** Start of EM4x50 Code ************************
bool EM_EndParityTest(uint8_t *bs, size_t size, uint8_t rows, uint8_t cols, uint8_t pType)
{
bool EM_EndParityTest(uint8_t *bs, size_t size, uint8_t rows, uint8_t cols, uint8_t pType) {
if (rows * cols > size) return false;
uint8_t colP = 0;
//assume last col is a parity and do not test
@ -707,8 +681,7 @@ bool EM_EndParityTest(uint8_t *bs, size_t size, uint8_t rows, uint8_t cols, uint
return true;
}
bool EM_ByteParityTest(uint8_t *bs, size_t size, uint8_t rows, uint8_t cols, uint8_t pType)
{
bool EM_ByteParityTest(uint8_t *bs, size_t size, uint8_t rows, uint8_t cols, uint8_t pType) {
if (rows * cols > size) return false;
uint8_t rowP = 0;
@ -732,8 +705,7 @@ bool EM_ByteParityTest(uint8_t *bs, size_t size, uint8_t rows, uint8_t cols, uin
//c012345678| 0
// |- must be zero
bool EMwordparitytest(uint8_t *bits)
{
bool EMwordparitytest(uint8_t *bits) {
// last row/col parity must be 0
if (bits[44] != 0) return false;
@ -762,8 +734,7 @@ bool EMwordparitytest(uint8_t *bits)
//////////////// 4050 / 4450 commands
uint32_t OutputEM4x50_Block(uint8_t *BitStream, size_t size, bool verbose, bool pTest)
{
uint32_t OutputEM4x50_Block(uint8_t *BitStream, size_t size, bool verbose, bool pTest) {
if (size < 45) return 0;
uint32_t code = bytebits_to_byte(BitStream, 8);
@ -813,8 +784,7 @@ uint32_t OutputEM4x50_Block(uint8_t *BitStream, size_t size, bool verbose, bool
* Word Read values. UID is stored in block 32.
*/
//completed by Marshmellow
int EM4x50Read(const char *Cmd, bool verbose)
{
int EM4x50Read(const char *Cmd, bool verbose) {
uint8_t fndClk[] = {8, 16, 32, 40, 50, 64, 128};
int clk = 0, invert = 0, tol = 0, phaseoff;
int i = 0, j = 0, startblock, skip, block, start, end, low = 0, high = 0, minClk = 255;
@ -1000,21 +970,18 @@ int EM4x50Read(const char *Cmd, bool verbose)
return (int)AllPTest;
}
int CmdEM4x50Read(const char *Cmd)
{
int CmdEM4x50Read(const char *Cmd) {
uint8_t ctmp = tolower(param_getchar(Cmd, 0));
if (ctmp == 'h') return usage_lf_em4x50_read();
return EM4x50Read(Cmd, true);
}
int CmdEM4x50Write(const char *Cmd)
{
int CmdEM4x50Write(const char *Cmd) {
uint8_t ctmp = tolower(param_getchar(Cmd, 0));
if (ctmp == 'h') return usage_lf_em4x50_write();
PrintAndLogEx(NORMAL, "no implemented yet");
return 0;
}
int CmdEM4x50Dump(const char *Cmd)
{
int CmdEM4x50Dump(const char *Cmd) {
uint8_t ctmp = tolower(param_getchar(Cmd, 0));
if (ctmp == 'h') return usage_lf_em4x50_dump();
PrintAndLogEx(NORMAL, "no implemented yet");
@ -1023,8 +990,7 @@ int CmdEM4x50Dump(const char *Cmd)
#define EM_PREAMBLE_LEN 6
// download samples from device and copy to Graphbuffer
bool downloadSamplesEM()
{
bool downloadSamplesEM() {
// 8 bit preamble + 32 bit word response (max clock (128) * 40bits = 5120 samples)
uint8_t got[6000];
@ -1045,8 +1011,7 @@ bool downloadSamplesEM()
}
// em_demod
bool doPreambleSearch(size_t *startIdx)
{
bool doPreambleSearch(size_t *startIdx) {
// sanity check
if (DemodBufferLen < EM_PREAMBLE_LEN) {
@ -1067,8 +1032,7 @@ bool doPreambleSearch(size_t *startIdx)
return true;
}
bool detectFSK()
{
bool detectFSK() {
// detect fsk clock
if (!GetFskClock("", false)) {
PrintAndLogEx(DEBUG, "DEBUG: Error - EM: FSK clock failed");
@ -1083,8 +1047,7 @@ bool detectFSK()
return true;
}
// PSK clocks should be easy to detect ( but difficult to demod a non-repeating pattern... )
bool detectPSK()
{
bool detectPSK() {
int ans = GetPskClock("", false);
if (ans <= 0) {
PrintAndLogEx(DEBUG, "DEBUG: Error - EM: PSK clock failed");
@ -1108,8 +1071,7 @@ bool detectPSK()
return true;
}
// try manchester - NOTE: ST only applies to T55x7 tags.
bool detectASK_MAN()
{
bool detectASK_MAN() {
bool stcheck = false;
if (!ASKDemod_ext("0 0 0", false, false, 1, &stcheck)) {
PrintAndLogEx(DEBUG, "DEBUG: Error - EM: ASK/Manchester Demod failed");
@ -1117,8 +1079,7 @@ bool detectASK_MAN()
}
return true;
}
bool detectASK_BI()
{
bool detectASK_BI() {
int ans = ASKbiphaseDemod("0 0 1", false);
if (!ans) {
PrintAndLogEx(DEBUG, "DEBUG: Error - EM: ASK/biphase normal demod failed");
@ -1133,8 +1094,7 @@ bool detectASK_BI()
}
// param: idx - start index in demoded data.
bool setDemodBufferEM(uint32_t *word, size_t idx)
{
bool setDemodBufferEM(uint32_t *word, size_t idx) {
//test for even parity bits.
uint8_t parity[45] = {0};
@ -1157,8 +1117,7 @@ bool setDemodBufferEM(uint32_t *word, size_t idx)
// FSK, PSK, ASK/MANCHESTER, ASK/BIPHASE, ASK/DIPHASE
// should cover 90% of known used configs
// the rest will need to be manually demoded for now...
bool demodEM4x05resp(uint32_t *word)
{
bool demodEM4x05resp(uint32_t *word) {
size_t idx = 0;
*word = 0;
if (detectASK_MAN() && doPreambleSearch(&idx))
@ -1182,8 +1141,7 @@ bool demodEM4x05resp(uint32_t *word)
}
//////////////// 4205 / 4305 commands
int EM4x05ReadWord_ext(uint8_t addr, uint32_t pwd, bool usePwd, uint32_t *word)
{
int EM4x05ReadWord_ext(uint8_t addr, uint32_t pwd, bool usePwd, uint32_t *word) {
UsbCommand c = {CMD_EM4X_READ_WORD, {addr, pwd, usePwd}};
clearCommandBuffer();
SendCommand(&c);
@ -1199,8 +1157,7 @@ int EM4x05ReadWord_ext(uint8_t addr, uint32_t pwd, bool usePwd, uint32_t *word)
return demodEM4x05resp(word);
}
int CmdEM4x05Dump(const char *Cmd)
{
int CmdEM4x05Dump(const char *Cmd) {
uint8_t addr = 0;
uint32_t pwd = 0;
bool usePwd = false;
@ -1233,8 +1190,7 @@ int CmdEM4x05Dump(const char *Cmd)
return success;
}
int CmdEM4x05Read(const char *Cmd)
{
int CmdEM4x05Read(const char *Cmd) {
uint8_t addr;
uint32_t pwd;
bool usePwd = false;
@ -1264,8 +1220,7 @@ int CmdEM4x05Read(const char *Cmd)
return isOk;
}
int CmdEM4x05Write(const char *Cmd)
{
int CmdEM4x05Write(const char *Cmd) {
uint8_t ctmp = tolower(param_getchar(Cmd, 0));
if (strlen(Cmd) == 0 || ctmp == 'h') return usage_lf_em4x05_write();
@ -1313,8 +1268,7 @@ int CmdEM4x05Write(const char *Cmd)
return isOk;
}
void printEM4x05config(uint32_t wordData)
{
void printEM4x05config(uint32_t wordData) {
uint16_t datarate = (((wordData & 0x3F) + 1) * 2);
uint8_t encoder = ((wordData >> 6) & 0xF);
char enc[14];
@ -1418,8 +1372,7 @@ void printEM4x05config(uint32_t wordData)
PrintAndLogEx(NORMAL, " Pigeon: %u | Pigeon Mode is %s\n", pigeon, pigeon ? "Enabled" : "Disabled");
}
void printEM4x05info(uint32_t block0, uint32_t serial)
{
void printEM4x05info(uint32_t block0, uint32_t serial) {
uint8_t chipType = (block0 >> 1) & 0xF;
uint8_t cap = (block0 >> 5) & 3;
@ -1467,8 +1420,7 @@ void printEM4x05info(uint32_t block0, uint32_t serial)
PrintAndLogEx(NORMAL, "\n Serial #: %08X\n", serial);
}
void printEM4x05ProtectionBits(uint32_t word)
{
void printEM4x05ProtectionBits(uint32_t word) {
for (uint8_t i = 0; i < 15; i++) {
PrintAndLogEx(NORMAL, " Word: %02u | %s", i, (((1 << i) & word) || i < 2) ? "Is Write Locked" : "Is Not Write Locked");
if (i == 14)
@ -1477,14 +1429,12 @@ void printEM4x05ProtectionBits(uint32_t word)
}
//quick test for EM4x05/EM4x69 tag
bool EM4x05IsBlock0(uint32_t *word)
{
bool EM4x05IsBlock0(uint32_t *word) {
int res = EM4x05ReadWord_ext(0, 0, false, word);
return (res > 0) ? true : false;
}
int CmdEM4x05Info(const char *Cmd)
{
int CmdEM4x05Info(const char *Cmd) {
#define EM_SERIAL_BLOCK 1
#define EM_CONFIG_BLOCK 4
#define EM_PROT1_BLOCK 14
@ -1553,15 +1503,13 @@ static command_t CommandTable[] = {
{NULL, NULL, 0, NULL}
};
int CmdLFEM4X(const char *Cmd)
{
int CmdLFEM4X(const char *Cmd) {
clearCommandBuffer();
CmdsParse(CommandTable, Cmd);
return 0;
}
int CmdHelp(const char *Cmd)
{
int CmdHelp(const char *Cmd) {
CmdsHelp(CommandTable);
return 0;
}

View file

@ -31,8 +31,7 @@
static int CmdHelp(const char *Cmd);
int usage_lf_fdx_clone(void)
{
int usage_lf_fdx_clone(void) {
PrintAndLogEx(NORMAL, "Clone a FDX-B animal tag to a T55x7 tag.");
PrintAndLogEx(NORMAL, "Usage: lf fdx clone [h] <country id> <animal id> <Q5>");
PrintAndLogEx(NORMAL, "Options:");
@ -50,8 +49,7 @@ int usage_lf_fdx_clone(void)
return 0;
}
int usage_lf_fdx_sim(void)
{
int usage_lf_fdx_sim(void) {
PrintAndLogEx(NORMAL, "Enables simulation of FDX-B animal tag");
PrintAndLogEx(NORMAL, "Simulation runs until the button is pressed or another USB command is issued.");
PrintAndLogEx(NORMAL, "");
@ -68,8 +66,7 @@ int usage_lf_fdx_sim(void)
// Ask/Biphase Demod then try to locate an ISO 11784/85 ID
// BitStream must contain previously askrawdemod and biphasedemoded data
int detectFDXB(uint8_t *dest, size_t *size)
{
int detectFDXB(uint8_t *dest, size_t *size) {
//make sure buffer has enough data
if (*size < 128 * 2) return -1;
size_t startIdx = 0;
@ -82,8 +79,7 @@ int detectFDXB(uint8_t *dest, size_t *size)
}
// clearing the topbit needed for the preambl detection.
static void verify_values(uint32_t countryid, uint64_t animalid)
{
static void verify_values(uint32_t countryid, uint64_t animalid) {
if ((animalid & 0x3FFFFFFFFF) != animalid) {
animalid &= 0x3FFFFFFFFF;
PrintAndLogEx(INFO, "Animal ID Truncated to 38bits: %"PRIx64, animalid);
@ -94,8 +90,7 @@ static void verify_values(uint32_t countryid, uint64_t animalid)
}
}
int getFDXBits(uint64_t national_id, uint16_t country, uint8_t isanimal, uint8_t isextended, uint32_t extended, uint8_t *bits)
{
int getFDXBits(uint64_t national_id, uint16_t country, uint8_t isanimal, uint8_t isextended, uint32_t extended, uint8_t *bits) {
// add preamble ten 0x00 and one 0x01
memset(bits, 0x00, 10);
@ -162,8 +157,7 @@ int getFDXBits(uint64_t national_id, uint16_t country, uint8_t isanimal, uint8_t
-- sample: 985121004515220 [ 37FF65B88EF94 ]
*/
int CmdFDXBdemodBI(const char *Cmd)
{
int CmdFDXBdemodBI(const char *Cmd) {
int clk = 32;
int invert = 1, errCnt = 0, offset = 0, maxErr = 0;
@ -238,8 +232,7 @@ int CmdFDXBdemodBI(const char *Cmd)
//see ASKDemod for what args are accepted
//almost the same demod as cmddata.c/CmdFDXBdemodBI
int CmdFdxDemod(const char *Cmd)
{
int CmdFdxDemod(const char *Cmd) {
//Differential Biphase / di-phase (inverted biphase)
//get binary from ask wave
@ -308,14 +301,12 @@ int CmdFdxDemod(const char *Cmd)
return 1;
}
int CmdFdxRead(const char *Cmd)
{
int CmdFdxRead(const char *Cmd) {
lf_read(true, 10000);
return CmdFdxDemod(Cmd);
}
int CmdFdxClone(const char *Cmd)
{
int CmdFdxClone(const char *Cmd) {
uint32_t countryid = 0;
uint64_t animalid = 0;
@ -367,8 +358,7 @@ int CmdFdxClone(const char *Cmd)
return 0;
}
int CmdFdxSim(const char *Cmd)
{
int CmdFdxSim(const char *Cmd) {
uint32_t countryid = 0;
uint64_t animalid = 0;
@ -407,15 +397,13 @@ static command_t CommandTable[] = {
{NULL, NULL, 0, NULL}
};
int CmdLFFdx(const char *Cmd)
{
int CmdLFFdx(const char *Cmd) {
clearCommandBuffer();
CmdsParse(CommandTable, Cmd);
return 0;
}
int CmdHelp(const char *Cmd)
{
int CmdHelp(const char *Cmd) {
CmdsHelp(CommandTable);
return 0;
}

View file

@ -11,8 +11,7 @@
static int CmdHelp(const char *Cmd);
int usage_lf_guard_clone(void)
{
int usage_lf_guard_clone(void) {
PrintAndLogEx(NORMAL, "clone a Guardall tag to a T55x7 tag.");
PrintAndLogEx(NORMAL, "The facility-code is 8-bit and the card number is 16-bit. Larger values are truncated. ");
PrintAndLogEx(NORMAL, "Currently work only on 26bit");
@ -28,8 +27,7 @@ int usage_lf_guard_clone(void)
return 0;
}
int usage_lf_guard_sim(void)
{
int usage_lf_guard_sim(void) {
PrintAndLogEx(NORMAL, "Enables simulation of Guardall card with specified card number.");
PrintAndLogEx(NORMAL, "Simulation runs until the button is pressed or another USB command is issued.");
PrintAndLogEx(NORMAL, "The facility-code is 8-bit and the card number is 16-bit. Larger values are truncated.");
@ -47,8 +45,7 @@ int usage_lf_guard_sim(void)
}
// Works for 26bits.
int GetGuardBits(uint8_t fmtlen, uint32_t fc, uint32_t cn, uint8_t *guardBits)
{
int GetGuardBits(uint8_t fmtlen, uint32_t fc, uint32_t cn, uint8_t *guardBits) {
uint8_t xorKey = 0x66;
uint8_t i;
@ -147,8 +144,7 @@ int GetGuardBits(uint8_t fmtlen, uint32_t fc, uint32_t cn, uint8_t *guardBits)
// error returns as -x
// success returns start position in bitstream
// Bitstream must contain previously askrawdemod and biphasedemoded data
int detectGProxII(uint8_t *bits, size_t *size)
{
int detectGProxII(uint8_t *bits, size_t *size) {
size_t startIdx = 0;
uint8_t preamble[] = {1, 1, 1, 1, 1, 0};
@ -176,8 +172,7 @@ int detectGProxII(uint8_t *bits, size_t *size)
//WARNING: if it fails during some points it will destroy the DemodBuffer data
// but will leave the GraphBuffer intact.
//if successful it will push askraw data back to demod buffer ready for emulation
int CmdGuardDemod(const char *Cmd)
{
int CmdGuardDemod(const char *Cmd) {
//Differential Biphase
//get binary from ask wave
@ -258,14 +253,12 @@ int CmdGuardDemod(const char *Cmd)
return 1;
}
int CmdGuardRead(const char *Cmd)
{
int CmdGuardRead(const char *Cmd) {
lf_read(true, 10000);
return CmdGuardDemod(Cmd);
}
int CmdGuardClone(const char *Cmd)
{
int CmdGuardClone(const char *Cmd) {
char cmdp = param_getchar(Cmd, 0);
if (strlen(Cmd) == 0 || cmdp == 'h' || cmdp == 'H') return usage_lf_guard_clone();
@ -316,8 +309,7 @@ int CmdGuardClone(const char *Cmd)
return 0;
}
int CmdGuardSim(const char *Cmd)
{
int CmdGuardSim(const char *Cmd) {
// Guard uses: clk: 64, invert: 0, encoding: 2 (ASK Biphase)
uint8_t clock = 64, encoding = 2, separator = 0, invert = 0;
@ -363,15 +355,13 @@ static command_t CommandTable[] = {
{NULL, NULL, 0, NULL}
};
int CmdLFGuard(const char *Cmd)
{
int CmdLFGuard(const char *Cmd) {
clearCommandBuffer();
CmdsParse(CommandTable, Cmd);
return 0;
}
int CmdHelp(const char *Cmd)
{
int CmdHelp(const char *Cmd) {
CmdsHelp(CommandTable);
return 0;
}

View file

@ -16,8 +16,7 @@
static int CmdHelp(const char *Cmd);
int usage_lf_hid_read(void)
{
int usage_lf_hid_read(void) {
PrintAndLogEx(NORMAL, "Enables HID compatible reader mode printing details.");
PrintAndLogEx(NORMAL, "By default, values are printed and logged until the button is pressed or another USB command is issued.");
PrintAndLogEx(NORMAL, "If the [1] option is provided, reader mode is exited after reading a single HID card.");
@ -32,8 +31,7 @@ int usage_lf_hid_read(void)
PrintAndLogEx(NORMAL, " lf hid read 1");
return 0;
}
int usage_lf_hid_wiegand(void)
{
int usage_lf_hid_wiegand(void) {
PrintAndLogEx(NORMAL, "This command converts facility code/card number to Wiegand code");
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(NORMAL, "Usage: lf hid wiegand [h] [OEM] [FC] [CN]");
@ -46,8 +44,7 @@ int usage_lf_hid_wiegand(void)
PrintAndLogEx(NORMAL, " lf hid wiegand 0 101 2001");
return 0;
}
int usage_lf_hid_sim(void)
{
int usage_lf_hid_sim(void) {
PrintAndLogEx(NORMAL, "Enables simulation of HID card with card number.");
PrintAndLogEx(NORMAL, "Simulation runs until the button is pressed or another USB command is issued.");
PrintAndLogEx(NORMAL, "");
@ -59,8 +56,7 @@ int usage_lf_hid_sim(void)
PrintAndLogEx(NORMAL, " lf hid sim 2006ec0c86");
return 0;
}
int usage_lf_hid_clone(void)
{
int usage_lf_hid_clone(void) {
PrintAndLogEx(NORMAL, "Clone HID to T55x7. Tag must be on antenna. ");
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(NORMAL, "Usage: lf hid clone [h] [ID] <L>");
@ -73,8 +69,7 @@ int usage_lf_hid_clone(void)
PrintAndLogEx(NORMAL, " lf hid clone 2006ec0c86 L");
return 0;
}
int usage_lf_hid_brute(void)
{
int usage_lf_hid_brute(void) {
PrintAndLogEx(NORMAL, "Enables bruteforce of HID readers with specified facility code.");
PrintAndLogEx(NORMAL, "This is a attack against reader. if cardnumber is given, it starts with it and goes up / down one step");
PrintAndLogEx(NORMAL, "if cardnumber is not given, it starts with 1 and goes up to 65535");
@ -96,8 +91,7 @@ int usage_lf_hid_brute(void)
}
// sending three times. Didn't seem to break the previous sim?
static bool sendPing(void)
{
static bool sendPing(void) {
UsbCommand ping = {CMD_PING, {1, 2, 3}};
SendCommand(&ping);
SendCommand(&ping);
@ -108,8 +102,7 @@ static bool sendPing(void)
return false;
return true;
}
static bool sendTry(uint8_t fmtlen, uint32_t fc, uint32_t cn, uint32_t delay, uint8_t *bits, bool verbose)
{
static bool sendTry(uint8_t fmtlen, uint32_t fc, uint32_t cn, uint32_t delay, uint8_t *bits, bool verbose) {
// this should be optional.
if (verbose)
@ -131,8 +124,7 @@ static bool sendTry(uint8_t fmtlen, uint32_t fc, uint32_t cn, uint32_t delay, ui
//by marshmellow (based on existing demod + holiman's refactor)
//HID Prox demod - FSK RF/50 with preamble of 00011101 (then manchester encoded)
//print full HID Prox ID and some bit format details if found
int CmdHIDDemod(const char *Cmd)
{
int CmdHIDDemod(const char *Cmd) {
//raw fsk demod no manchester decoding no start bit finding just get binary from wave
uint32_t hi2 = 0, hi = 0, lo = 0;
@ -230,16 +222,14 @@ int CmdHIDDemod(const char *Cmd)
}
// this read is the "normal" read, which download lf signal and tries to demod here.
int CmdHIDRead(const char *Cmd)
{
int CmdHIDRead(const char *Cmd) {
lf_read(true, 12000);
return CmdHIDDemod(Cmd);
}
// this read loops on device side.
// uses the demod in lfops.c
int CmdHIDRead_device(const char *Cmd)
{
int CmdHIDRead_device(const char *Cmd) {
if (Cmd[0] == 'h' || Cmd[0] == 'H') return usage_lf_hid_read();
uint8_t findone = (Cmd[0] == '1') ? 1 : 0;
@ -249,8 +239,7 @@ int CmdHIDRead_device(const char *Cmd)
return 0;
}
int CmdHIDSim(const char *Cmd)
{
int CmdHIDSim(const char *Cmd) {
uint32_t hi = 0, lo = 0;
uint32_t n = 0, i = 0;
@ -271,8 +260,7 @@ int CmdHIDSim(const char *Cmd)
return 0;
}
int CmdHIDClone(const char *Cmd)
{
int CmdHIDClone(const char *Cmd) {
uint32_t hi2 = 0, hi = 0, lo = 0;
uint32_t n = 0, i = 0;
@ -319,8 +307,7 @@ typedef struct {
size_t Wiegand_n;
} wiegand_t;
static void addHIDMarker(uint8_t fmtlen, uint8_t *out)
{
static void addHIDMarker(uint8_t fmtlen, uint8_t *out) {
// temp array
uint8_t arr[BITS];
memset(arr, 0, BITS);
@ -389,8 +376,7 @@ static void addHIDMarker(uint8_t fmtlen, uint8_t *out)
// }
//static void calc26(uint16_t fc, uint32_t cardno, uint8_t *out){
static void calc26(uint16_t fc, uint32_t cardno, uint8_t *out)
{
static void calc26(uint16_t fc, uint32_t cardno, uint8_t *out) {
uint8_t wiegand[24];
num_to_bytebits(fc, 8, wiegand);
num_to_bytebits(cardno, 16, wiegand + 8);
@ -398,8 +384,7 @@ static void calc26(uint16_t fc, uint32_t cardno, uint8_t *out)
}
// static void calc33(uint16_t fc, uint32_t cardno, uint8_t *out){
// }
static void calc34(uint16_t fc, uint32_t cardno, uint8_t *out)
{
static void calc34(uint16_t fc, uint32_t cardno, uint8_t *out) {
uint8_t wiegand[32];
num_to_bytebits(fc, 16, wiegand);
num_to_bytebits(cardno, 16, wiegand + 16);
@ -409,8 +394,7 @@ static void calc34(uint16_t fc, uint32_t cardno, uint8_t *out)
// *lo = ((cardno & 0xFFFFF) << 1) | fc << 21;
// *hi = (1 << 5) | ((fc >> 11) & 1);
// }
static void calc37S(uint16_t fc, uint32_t cardno, uint8_t *out)
{
static void calc37S(uint16_t fc, uint32_t cardno, uint8_t *out) {
// FC 2 - 17 - 16 bit
// cardno 18 - 36 - 19 bit
// Even P1 1 - 19
@ -420,8 +404,7 @@ static void calc37S(uint16_t fc, uint32_t cardno, uint8_t *out)
num_to_bytebits(cardno, 19, wiegand + 16);
wiegand_add_parity(out, wiegand, sizeof(wiegand));
}
static void calc37H(uint64_t cardno, uint8_t *out)
{
static void calc37H(uint64_t cardno, uint8_t *out) {
// SC NONE
// cardno 1-35 34 bits
// Even Parity 0th bit 1-18
@ -439,8 +422,7 @@ static void calc37H(uint64_t cardno, uint8_t *out)
// *hi = (cardno >> 31);
// }
void calcWiegand(uint8_t fmtlen, uint16_t fc, uint64_t cardno, uint8_t *bits)
{
void calcWiegand(uint8_t fmtlen, uint16_t fc, uint64_t cardno, uint8_t *bits) {
uint32_t cn32 = (cardno & 0xFFFFFFFF);
switch (fmtlen) {
case 26:
@ -465,8 +447,7 @@ void calcWiegand(uint8_t fmtlen, uint16_t fc, uint64_t cardno, uint8_t *bits)
}
}
int CmdHIDWiegand(const char *Cmd)
{
int CmdHIDWiegand(const char *Cmd) {
uint32_t oem = 0, fc = 0;
uint64_t cardnum = 0;
uint64_t blocks = 0, wiegand = 0;
@ -511,8 +492,7 @@ int CmdHIDWiegand(const char *Cmd)
return 0;
}
int CmdHIDBrute(const char *Cmd)
{
int CmdHIDBrute(const char *Cmd) {
bool errors = false, verbose = false;
uint32_t fc = 0, cn = 0, delay = 1000;
@ -612,15 +592,13 @@ static command_t CommandTable[] = {
{NULL, NULL, 0, NULL}
};
int CmdLFHID(const char *Cmd)
{
int CmdLFHID(const char *Cmd) {
clearCommandBuffer();
CmdsParse(CommandTable, Cmd);
return 0;
}
int CmdHelp(const char *Cmd)
{
int CmdHelp(const char *Cmd) {
CmdsHelp(CommandTable);
return 0;
}

View file

@ -25,13 +25,11 @@
static int CmdHelp(const char *Cmd);
size_t nbytes(size_t nbits)
{
size_t nbytes(size_t nbits) {
return (nbits / 8) + ((nbits % 8) > 0);
}
int CmdLFHitagList(const char *Cmd)
{
int CmdLFHitagList(const char *Cmd) {
uint8_t *got = calloc(USB_CMD_DATA_SIZE, sizeof(uint8_t));
if (!got) {
PrintAndLogEx(WARNING, "Cannot allocate memory for trace");
@ -158,16 +156,14 @@ int CmdLFHitagList(const char *Cmd)
return 0;
}
int CmdLFHitagSnoop(const char *Cmd)
{
int CmdLFHitagSnoop(const char *Cmd) {
UsbCommand c = {CMD_SNOOP_HITAG};
clearCommandBuffer();
SendCommand(&c);
return 0;
}
int CmdLFHitagSim(const char *Cmd)
{
int CmdLFHitagSim(const char *Cmd) {
UsbCommand c = {CMD_SIMULATE_HITAG};
char filename[FILE_PATH_SIZE] = { 0x00 };
@ -203,8 +199,7 @@ int CmdLFHitagSim(const char *Cmd)
return 0;
}
int CmdLFHitagReader(const char *Cmd)
{
int CmdLFHitagReader(const char *Cmd) {
UsbCommand c = {CMD_READER_HITAG, {0, 0, 0} }; //, {param_get32ex(Cmd,0,0,10),param_get32ex(Cmd,1,0,16),param_get32ex(Cmd,2,0,16),param_get32ex(Cmd,3,0,16)}};
hitag_data *htd = (hitag_data *)c.d.asBytes;
@ -299,8 +294,7 @@ int CmdLFHitagReader(const char *Cmd)
return 0;
}
int CmdLFHitagSimS(const char *Cmd)
{
int CmdLFHitagSimS(const char *Cmd) {
UsbCommand c = { CMD_SIMULATE_HITAG_S };
char filename[FILE_PATH_SIZE] = { 0x00 };
FILE *f;
@ -335,8 +329,7 @@ int CmdLFHitagSimS(const char *Cmd)
return 0;
}
int CmdLFHitagCheckChallenges(const char *Cmd)
{
int CmdLFHitagCheckChallenges(const char *Cmd) {
UsbCommand c = { CMD_TEST_HITAGS_TRACES };
char filename[FILE_PATH_SIZE] = { 0x00 };
FILE *f;
@ -371,8 +364,7 @@ int CmdLFHitagCheckChallenges(const char *Cmd)
return 0;
}
int CmdLFHitagWP(const char *Cmd)
{
int CmdLFHitagWP(const char *Cmd) {
UsbCommand c = { CMD_WR_HITAG_S };
hitag_data *htd = (hitag_data *)c.d.asBytes;
hitag_function htf = param_get32ex(Cmd, 0, 0, 10);
@ -429,15 +421,13 @@ static command_t CommandTable[] = {
{ NULL, NULL, 0, NULL }
};
int CmdLFHitag(const char *Cmd)
{
int CmdLFHitag(const char *Cmd) {
clearCommandBuffer();
CmdsParse(CommandTable, Cmd);
return 0;
}
int CmdHelp(const char *Cmd)
{
int CmdHelp(const char *Cmd) {
CmdsHelp(CommandTable);
return 0;
}

View file

@ -12,8 +12,7 @@
static int CmdHelp(const char *Cmd);
int usage_lf_indala_demod(void)
{
int usage_lf_indala_demod(void) {
PrintAndLogEx(NORMAL, "Enables Indala compatible reader mode printing details of scanned tags.");
PrintAndLogEx(NORMAL, "By default, values are printed and logged until the button is pressed or another USB command is issued.");
PrintAndLogEx(NORMAL, "");
@ -26,8 +25,7 @@ int usage_lf_indala_demod(void)
return 0;
}
int usage_lf_indala_sim(void)
{
int usage_lf_indala_sim(void) {
PrintAndLogEx(NORMAL, "Enables simulation of Indala card with specified uid.");
PrintAndLogEx(NORMAL, "Simulation runs until the button is pressed or another USB command is issued.");
PrintAndLogEx(NORMAL, "");
@ -41,8 +39,7 @@ int usage_lf_indala_sim(void)
return 0;
}
int usage_lf_indala_clone(void)
{
int usage_lf_indala_clone(void) {
PrintAndLogEx(NORMAL, "Enables cloning of Indala card with specified uid onto T55x7.");
PrintAndLogEx(NORMAL, "The T55x7 must be on the antenna when issuing this command. T55x7 blocks are calculated and printed in the process.");
PrintAndLogEx(NORMAL, "");
@ -59,8 +56,7 @@ int usage_lf_indala_clone(void)
// redesigned by marshmellow adjusted from existing decode functions
// indala id decoding
int indala64decode(uint8_t *dest, size_t *size, uint8_t *invert)
{
int indala64decode(uint8_t *dest, size_t *size, uint8_t *invert) {
//standard 64 bit indala formats including 26 bit 40134 format
uint8_t preamble64[] = {1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1};
uint8_t preamble64_i[] = {0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0};
@ -82,8 +78,7 @@ int indala64decode(uint8_t *dest, size_t *size, uint8_t *invert)
return (int) idx;
}
int indala224decode(uint8_t *dest, size_t *size, uint8_t *invert)
{
int indala224decode(uint8_t *dest, size_t *size, uint8_t *invert) {
//large 224 bit indala formats (different preamble too...)
uint8_t preamble224[] = {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1};
uint8_t preamble224_i[] = {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0};
@ -111,8 +106,7 @@ int indala224decode(uint8_t *dest, size_t *size, uint8_t *invert)
}
// this read is the "normal" read, which download lf signal and tries to demod here.
int CmdIndalaRead(const char *Cmd)
{
int CmdIndalaRead(const char *Cmd) {
lf_read(true, 30000);
return CmdIndalaDemod(Cmd);
}
@ -120,8 +114,7 @@ int CmdIndalaRead(const char *Cmd)
// Indala 26 bit decode
// by marshmellow
// optional arguments - same as PSKDemod (clock & invert & maxerr)
int CmdIndalaDemod(const char *Cmd)
{
int CmdIndalaDemod(const char *Cmd) {
int ans;
if (strlen(Cmd) > 0)
ans = PSKDemod(Cmd, 0);
@ -185,8 +178,7 @@ int CmdIndalaDemod(const char *Cmd)
// returns false positives more often - but runs against more sets of samples
// poor psk signal can be difficult to demod this approach might succeed when the other fails
// but the other appears to currently be more accurate than this approach most of the time.
int CmdIndalaDemodAlt(const char *Cmd)
{
int CmdIndalaDemodAlt(const char *Cmd) {
// Usage: recover 64bit UID by default, specify "224" as arg to recover a 224bit UID
int state = -1;
int count = 0;
@ -382,8 +374,7 @@ int CmdIndalaDemodAlt(const char *Cmd)
return 1;
}
int CmdIndalaSim(const char *Cmd)
{
int CmdIndalaSim(const char *Cmd) {
char cmdp = tolower(param_getchar(Cmd, 0));
if (strlen(Cmd) == 0 || cmdp == 'h') return usage_lf_indala_sim();
@ -428,8 +419,7 @@ int CmdIndalaSim(const char *Cmd)
}
// iceman - needs refactoring
int CmdIndalaClone(const char *Cmd)
{
int CmdIndalaClone(const char *Cmd) {
UsbCommand c = {0};
uint32_t uid1, uid2, uid3, uid4, uid5, uid6, uid7;
uid1 = uid2 = uid3 = uid4 = uid5 = uid6 = uid7 = 0;
@ -482,15 +472,13 @@ static command_t CommandTable[] = {
{NULL, NULL, 0, NULL}
};
int CmdLFINDALA(const char *Cmd)
{
int CmdLFINDALA(const char *Cmd) {
clearCommandBuffer();
CmdsParse(CommandTable, Cmd);
return 0;
}
int CmdHelp(const char *Cmd)
{
int CmdHelp(const char *Cmd) {
CmdsHelp(CommandTable);
return 0;
}

View file

@ -12,8 +12,7 @@
static int CmdHelp(const char *Cmd);
int usage_lf_io_read(void)
{
int usage_lf_io_read(void) {
PrintAndLogEx(NORMAL, "Enables IOProx compatible reader mode printing details of scanned tags.");
PrintAndLogEx(NORMAL, "By default, values are printed and logged until the button is pressed or another USB command is issued.");
PrintAndLogEx(NORMAL, "If the [1] option is provided, reader mode is exited after reading a single card.");
@ -29,8 +28,7 @@ int usage_lf_io_read(void)
return 0;
}
int usage_lf_io_sim(void)
{
int usage_lf_io_sim(void) {
PrintAndLogEx(NORMAL, "Enables simulation of IOProx card with specified facility-code and card number.");
PrintAndLogEx(NORMAL, "Simulation runs until the button is pressed or another USB command is issued.");
PrintAndLogEx(NORMAL, "");
@ -46,8 +44,7 @@ int usage_lf_io_sim(void)
return 0;
}
int usage_lf_io_clone(void)
{
int usage_lf_io_clone(void) {
PrintAndLogEx(NORMAL, "Enables cloning of IOProx card with specified facility-code and card number onto T55x7.");
PrintAndLogEx(NORMAL, "The T55x7 must be on the antenna when issuing this command. T55x7 blocks are calculated and printed in the process.");
PrintAndLogEx(NORMAL, "");
@ -65,15 +62,13 @@ int usage_lf_io_clone(void)
}
// this read is the "normal" read, which download lf signal and tries to demod here.
int CmdIOProxRead(const char *Cmd)
{
int CmdIOProxRead(const char *Cmd) {
lf_read(true, 12000);
return CmdIOProxDemod(Cmd);
}
// this read loops on device side.
// uses the demod in lfops.c
int CmdIOProxRead_device(const char *Cmd)
{
int CmdIOProxRead_device(const char *Cmd) {
if (Cmd[0] == 'h' || Cmd[0] == 'H') return usage_lf_io_read();
int findone = (Cmd[0] == '1') ? 1 : 0;
UsbCommand c = {CMD_IO_DEMOD_FSK, {findone, 0, 0}};
@ -85,8 +80,7 @@ int CmdIOProxRead_device(const char *Cmd)
//by marshmellow
//IO-Prox demod - FSK RF/64 with preamble of 000000001
//print ioprox ID and some format details
int CmdIOProxDemod(const char *Cmd)
{
int CmdIOProxDemod(const char *Cmd) {
int retval = 0;
int idx = 0;
uint8_t bits[MAX_GRAPH_TRACE_LEN] = {0};
@ -189,8 +183,7 @@ int CmdIOProxDemod(const char *Cmd)
//-----------------------------------------------------------------------------
//00000000 0 11110000 1 facility 1 version* 1 code*one 1 code*two 1 ???????? 11
//XSF(version)facility:codeone+codetwo (raw)
int getIOProxBits(uint8_t version, uint8_t fc, uint16_t cn, uint8_t *bits)
{
int getIOProxBits(uint8_t version, uint8_t fc, uint16_t cn, uint8_t *bits) {
#define SEPARATOR 1
uint8_t pos = 0;
// the return bits, preamble 0000 0000 0
@ -250,8 +243,7 @@ int getIOProxBits(uint8_t version, uint8_t fc, uint16_t cn, uint8_t *bits)
return 1;
}
int CmdIOProxSim(const char *Cmd)
{
int CmdIOProxSim(const char *Cmd) {
uint16_t cn = 0;
uint8_t version = 0, fc = 0;
uint8_t bits[64];
@ -296,8 +288,7 @@ int CmdIOProxSim(const char *Cmd)
return 0;
}
int CmdIOProxClone(const char *Cmd)
{
int CmdIOProxClone(const char *Cmd) {
uint32_t blocks[3] = {T55x7_MODULATION_FSK2a | T55x7_BITRATE_RF_64 | 2 << T55x7_MAXBLOCK_SHIFT, 0, 0};
uint16_t cn = 0;
@ -349,15 +340,13 @@ static command_t CommandTable[] = {
{NULL, NULL, 0, NULL}
};
int CmdLFIO(const char *Cmd)
{
int CmdLFIO(const char *Cmd) {
clearCommandBuffer();
CmdsParse(CommandTable, Cmd);
return 0;
}
int CmdHelp(const char *Cmd)
{
int CmdHelp(const char *Cmd) {
CmdsHelp(CommandTable);
return 0;
}

View file

@ -12,8 +12,7 @@
static int CmdHelp(const char *Cmd);
int usage_lf_jablotron_clone(void)
{
int usage_lf_jablotron_clone(void) {
PrintAndLogEx(NORMAL, "clone a Jablotron tag to a T55x7 tag.");
PrintAndLogEx(NORMAL, "Usage: lf jablotron clone [h] <card ID> <Q5>");
PrintAndLogEx(NORMAL, "Options:");
@ -26,8 +25,7 @@ int usage_lf_jablotron_clone(void)
return 0;
}
int usage_lf_jablotron_sim(void)
{
int usage_lf_jablotron_sim(void) {
PrintAndLogEx(NORMAL, "Enables simulation of jablotron card with specified card number.");
PrintAndLogEx(NORMAL, "Simulation runs until the button is pressed or another USB command is issued.");
PrintAndLogEx(NORMAL, "");
@ -41,8 +39,7 @@ int usage_lf_jablotron_sim(void)
return 0;
}
static uint8_t jablontron_chksum(uint8_t *bits)
{
static uint8_t jablontron_chksum(uint8_t *bits) {
uint8_t chksum = 0;
for (int i = 16; i < 56; i += 8) {
chksum += bytebits_to_byte(bits + i, 8);
@ -51,8 +48,7 @@ static uint8_t jablontron_chksum(uint8_t *bits)
return chksum;
}
int getJablotronBits(uint64_t fullcode, uint8_t *bits)
{
int getJablotronBits(uint64_t fullcode, uint8_t *bits) {
//preamp
num_to_bytebits(0xFFFF, 16, bits);
@ -69,8 +65,7 @@ int getJablotronBits(uint64_t fullcode, uint8_t *bits)
// Note: this is not a demod, this is only a detection
// the parameter *bits needs to be demoded before call
// 0xFFFF preamble, 64bits
int detectJablotron(uint8_t *bits, size_t *size)
{
int detectJablotron(uint8_t *bits, size_t *size) {
if (*size < 64 * 2) return -1; //make sure buffer has enough data
size_t startIdx = 0;
uint8_t preamble[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0};
@ -84,8 +79,7 @@ int detectJablotron(uint8_t *bits, size_t *size)
return (int)startIdx;
}
static uint64_t getJablontronCardId(uint64_t rawcode)
{
static uint64_t getJablontronCardId(uint64_t rawcode) {
uint64_t id = 0;
uint8_t bytes[] = {0, 0, 0, 0, 0};
num_to_bytes(rawcode, 5, bytes);
@ -97,8 +91,7 @@ static uint64_t getJablontronCardId(uint64_t rawcode)
}
//see ASKDemod for what args are accepted
int CmdJablotronDemod(const char *Cmd)
{
int CmdJablotronDemod(const char *Cmd) {
//Differential Biphase / di-phase (inverted biphase)
//get binary from ask wave
@ -152,14 +145,12 @@ int CmdJablotronDemod(const char *Cmd)
return 1;
}
int CmdJablotronRead(const char *Cmd)
{
int CmdJablotronRead(const char *Cmd) {
lf_read(true, 10000);
return CmdJablotronDemod(Cmd);
}
int CmdJablotronClone(const char *Cmd)
{
int CmdJablotronClone(const char *Cmd) {
uint64_t fullcode = 0;
uint32_t blocks[3] = {T55x7_MODULATION_DIPHASE | T55x7_BITRATE_RF_64 | 2 << T55x7_MAXBLOCK_SHIFT, 0, 0};
@ -209,8 +200,7 @@ int CmdJablotronClone(const char *Cmd)
return 0;
}
int CmdJablotronSim(const char *Cmd)
{
int CmdJablotronSim(const char *Cmd) {
uint64_t fullcode = 0;
char cmdp = tolower(param_getchar(Cmd, 0));
@ -248,15 +238,13 @@ static command_t CommandTable[] = {
{NULL, NULL, 0, NULL}
};
int CmdLFJablotron(const char *Cmd)
{
int CmdLFJablotron(const char *Cmd) {
clearCommandBuffer();
CmdsParse(CommandTable, Cmd);
return 0;
}
int CmdHelp(const char *Cmd)
{
int CmdHelp(const char *Cmd) {
CmdsHelp(CommandTable);
return 0;
}

View file

@ -11,8 +11,7 @@
static int CmdHelp(const char *Cmd);
int usage_lf_keri_clone(void)
{
int usage_lf_keri_clone(void) {
PrintAndLogEx(NORMAL, "clone a KERI tag to a T55x7 tag.");
PrintAndLogEx(NORMAL, "Usage: lf keri clone [h] <id> <Q5>");
PrintAndLogEx(NORMAL, "Options:");
@ -25,8 +24,7 @@ int usage_lf_keri_clone(void)
return 0;
}
int usage_lf_keri_sim(void)
{
int usage_lf_keri_sim(void) {
PrintAndLogEx(NORMAL, "Enables simulation of KERI card with specified card number.");
PrintAndLogEx(NORMAL, "Simulation runs until the button is pressed or another USB command is issued.");
PrintAndLogEx(NORMAL, "");
@ -41,8 +39,7 @@ int usage_lf_keri_sim(void)
}
// find KERI preamble in already demoded data
int detectKeri(uint8_t *dest, size_t *size, bool *invert)
{
int detectKeri(uint8_t *dest, size_t *size, bool *invert) {
uint8_t preamble[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1};
uint8_t preamble_i[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0};
@ -66,8 +63,7 @@ int detectKeri(uint8_t *dest, size_t *size, bool *invert)
return (int)startIdx;
}
int CmdKeriDemod(const char *Cmd)
{
int CmdKeriDemod(const char *Cmd) {
if (!PSKDemod("", false)) {
PrintAndLogEx(DEBUG, "DEBUG: Error - KERI: PSK1 Demod failed");
@ -126,14 +122,12 @@ int CmdKeriDemod(const char *Cmd)
return 1;
}
int CmdKeriRead(const char *Cmd)
{
int CmdKeriRead(const char *Cmd) {
lf_read(true, 10000);
return CmdKeriDemod(Cmd);
}
int CmdKeriClone(const char *Cmd)
{
int CmdKeriClone(const char *Cmd) {
uint32_t internalid = 0;
uint32_t blocks[3] = {
@ -196,8 +190,7 @@ int CmdKeriClone(const char *Cmd)
return 0;
}
int CmdKeriSim(const char *Cmd)
{
int CmdKeriSim(const char *Cmd) {
char cmdp = tolower(param_getchar(Cmd, 0));
if (strlen(Cmd) == 0 || cmdp == 'h') return usage_lf_keri_sim();
@ -239,15 +232,13 @@ static command_t CommandTable[] = {
{NULL, NULL, 0, NULL}
};
int CmdLFKeri(const char *Cmd)
{
int CmdLFKeri(const char *Cmd) {
clearCommandBuffer();
CmdsParse(CommandTable, Cmd);
return 0;
}
int CmdHelp(const char *Cmd)
{
int CmdHelp(const char *Cmd) {
CmdsHelp(CommandTable);
return 0;
}

View file

@ -10,8 +10,7 @@
#include "cmdlfnedap.h"
static int CmdHelp(const char *Cmd);
int usage_lf_nedap_clone(void)
{
int usage_lf_nedap_clone(void) {
PrintAndLogEx(NORMAL, "clone a NEDAP tag to a T55x7 tag.");
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(NORMAL, "Usage: lf nedap clone [h] <Card-Number>");
@ -25,8 +24,7 @@ int usage_lf_nedap_clone(void)
return 0;
}
int usage_lf_nedap_sim(void)
{
int usage_lf_nedap_sim(void) {
PrintAndLogEx(NORMAL, "Enables simulation of NEDAP card with specified card number.");
PrintAndLogEx(NORMAL, "Simulation runs until the button is pressed or another USB command is issued.");
PrintAndLogEx(NORMAL, "");
@ -41,8 +39,7 @@ int usage_lf_nedap_sim(void)
}
// find nedap preamble in already demoded data
int detectNedap(uint8_t *dest, size_t *size)
{
int detectNedap(uint8_t *dest, size_t *size) {
//make sure buffer has data
if (*size < 128) return -3;
@ -54,8 +51,7 @@ int detectNedap(uint8_t *dest, size_t *size)
return (int) startIdx;
}
int GetNedapBits(uint32_t cn, uint8_t *nedapBits)
{
int GetNedapBits(uint32_t cn, uint8_t *nedapBits) {
uint8_t pre[128];
memset(pre, 0x00, sizeof(pre));
@ -116,8 +112,7 @@ int GetNedapBits(uint32_t cn, uint8_t *nedapBits)
//NEDAP demod - ASK/Biphase (or Diphase), RF/64 with preamble of 1111111110 (always a 128 bit data stream)
//print NEDAP Prox ID, encoding, encrypted ID,
int CmdLFNedapDemod(const char *Cmd)
{
int CmdLFNedapDemod(const char *Cmd) {
//raw ask demod no start bit finding just get binary from wave
if (!ASKbiphaseDemod("0 64 1 0", false)) {
if (g_debugMode) PrintAndLogEx(DEBUG, "DEBUG: Error - Nedap ASKbiphaseDemod failed");
@ -236,8 +231,7 @@ lf t55xx wr b 4 d 4c0003ff
*/
int CmdLFNedapRead(const char *Cmd)
{
int CmdLFNedapRead(const char *Cmd) {
lf_read(true, 12000);
return CmdLFNedapDemod(Cmd);
}
@ -294,8 +288,7 @@ int CmdLFNedapClone(const char *Cmd) {
}
*/
int CmdLFNedapSim(const char *Cmd)
{
int CmdLFNedapSim(const char *Cmd) {
uint32_t cardnumber = 0, cn = 0;
@ -331,8 +324,7 @@ int CmdLFNedapSim(const char *Cmd)
return 0;
}
int CmdLFNedapChk(const char *Cmd)
{
int CmdLFNedapChk(const char *Cmd) {
//301600714021BE
uint8_t data[256] = { 0x30, 0x16, 0x00, 0x71, 0x40, 0x21, 0xBE};
int len = 0;
@ -389,15 +381,13 @@ static command_t CommandTable[] = {
{NULL, NULL, 0, NULL}
};
int CmdLFNedap(const char *Cmd)
{
int CmdLFNedap(const char *Cmd) {
clearCommandBuffer();
CmdsParse(CommandTable, Cmd);
return 0;
}
int CmdHelp(const char *Cmd)
{
int CmdHelp(const char *Cmd) {
CmdsHelp(CommandTable);
return 0;
}

View file

@ -12,8 +12,7 @@
static int CmdHelp(const char *Cmd);
int detectNexWatch(uint8_t *dest, size_t *size, bool *invert)
{
int detectNexWatch(uint8_t *dest, size_t *size, bool *invert) {
uint8_t preamble[28] = {0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
uint8_t preamble_i[28] = {1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
@ -32,8 +31,7 @@ int detectNexWatch(uint8_t *dest, size_t *size, bool *invert)
return (int) startIdx;
}
int CmdNexWatchDemod(const char *Cmd)
{
int CmdNexWatchDemod(const char *Cmd) {
if (!PSKDemod("", false)) {
PrintAndLogEx(DEBUG, "DEBUG: Error - NexWatch can't demod signal");
@ -89,8 +87,7 @@ int CmdNexWatchDemod(const char *Cmd)
//by marshmellow
//see ASKDemod for what args are accepted
int CmdNexWatchRead(const char *Cmd)
{
int CmdNexWatchRead(const char *Cmd) {
lf_read(true, 10000);
return CmdNexWatchDemod(Cmd);
}
@ -102,15 +99,13 @@ static command_t CommandTable[] = {
{NULL, NULL, 0, NULL}
};
int CmdLFNEXWATCH(const char *Cmd)
{
int CmdLFNEXWATCH(const char *Cmd) {
clearCommandBuffer();
CmdsParse(CommandTable, Cmd);
return 0;
}
int CmdHelp(const char *Cmd)
{
int CmdHelp(const char *Cmd) {
CmdsHelp(CommandTable);
return 0;
}

View file

@ -11,8 +11,7 @@
static int CmdHelp(const char *Cmd);
int usage_lf_noralsy_clone(void)
{
int usage_lf_noralsy_clone(void) {
PrintAndLogEx(NORMAL, "clone a Noralsy tag to a T55x7 tag.");
PrintAndLogEx(NORMAL, "Usage: lf noralsy clone [h] <card id> <year> <Q5>");
PrintAndLogEx(NORMAL, "Options:");
@ -26,8 +25,7 @@ int usage_lf_noralsy_clone(void)
return 0;
}
int usage_lf_noralsy_sim(void)
{
int usage_lf_noralsy_sim(void) {
PrintAndLogEx(NORMAL, "Enables simulation of Noralsy card with specified card number.");
PrintAndLogEx(NORMAL, "Simulation runs until the button is pressed or another USB command is issued.");
PrintAndLogEx(NORMAL, "");
@ -42,15 +40,13 @@ int usage_lf_noralsy_sim(void)
return 0;
}
static uint8_t noralsy_chksum(uint8_t *bits, uint8_t len)
{
static uint8_t noralsy_chksum(uint8_t *bits, uint8_t len) {
uint8_t sum = 0;
for (uint8_t i = 0; i < len; i += 4)
sum ^= bytebits_to_byte(bits + i, 4);
return sum & 0x0F ;
}
int getnoralsyBits(uint32_t id, uint16_t year, uint8_t *bits)
{
int getnoralsyBits(uint32_t id, uint16_t year, uint8_t *bits) {
//preamp
num_to_bytebits(0xBB0214FF, 32, bits); // --> Have seen 0xBB0214FF / 0xBB0314FF UNKNOWN
@ -80,8 +76,7 @@ int getnoralsyBits(uint32_t id, uint16_t year, uint8_t *bits)
// by iceman
// find Noralsy preamble in already demoded data
int detectNoralsy(uint8_t *dest, size_t *size)
{
int detectNoralsy(uint8_t *dest, size_t *size) {
if (*size < 96) return -1; //make sure buffer has data
size_t startIdx = 0;
uint8_t preamble[] = {1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 0};
@ -105,8 +100,7 @@ int detectNoralsy(uint8_t *dest, size_t *size)
**/
//see ASKDemod for what args are accepted
int CmdNoralsyDemod(const char *Cmd)
{
int CmdNoralsyDemod(const char *Cmd) {
//ASK / Manchester
bool st = true;
@ -175,14 +169,12 @@ int CmdNoralsyDemod(const char *Cmd)
return 1;
}
int CmdNoralsyRead(const char *Cmd)
{
int CmdNoralsyRead(const char *Cmd) {
lf_read(true, 8000);
return CmdNoralsyDemod(Cmd);
}
int CmdNoralsyClone(const char *Cmd)
{
int CmdNoralsyClone(const char *Cmd) {
uint16_t year = 0;
uint32_t id = 0;
@ -229,8 +221,7 @@ int CmdNoralsyClone(const char *Cmd)
return 0;
}
int CmdNoralsySim(const char *Cmd)
{
int CmdNoralsySim(const char *Cmd) {
uint8_t bits[96];
uint8_t *bs = bits;
@ -274,15 +265,13 @@ static command_t CommandTable[] = {
{NULL, NULL, 0, NULL}
};
int CmdLFNoralsy(const char *Cmd)
{
int CmdLFNoralsy(const char *Cmd) {
clearCommandBuffer();
CmdsParse(CommandTable, Cmd);
return 0;
}
int CmdHelp(const char *Cmd)
{
int CmdHelp(const char *Cmd) {
CmdsHelp(CommandTable);
return 0;
}

View file

@ -13,8 +13,7 @@ static int CmdHelp(const char *Cmd);
// by marshmellow
// find PAC preamble in already demoded data
int detectPac(uint8_t *dest, size_t *size)
{
int detectPac(uint8_t *dest, size_t *size) {
if (*size < 128) return -1; //make sure buffer has data
size_t startIdx = 0;
uint8_t preamble[] = {1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0};
@ -26,8 +25,7 @@ int detectPac(uint8_t *dest, size_t *size)
}
//see NRZDemod for what args are accepted
int CmdPacDemod(const char *Cmd)
{
int CmdPacDemod(const char *Cmd) {
//NRZ
if (!NRZrawDemod(Cmd, false)) {
@ -66,8 +64,7 @@ int CmdPacDemod(const char *Cmd)
return 1;
}
int CmdPacRead(const char *Cmd)
{
int CmdPacRead(const char *Cmd) {
lf_read(true, 4096 * 2 + 20);
return CmdPacDemod(Cmd);
}
@ -79,15 +76,13 @@ static command_t CommandTable[] = {
{NULL, NULL, 0, NULL}
};
int CmdLFPac(const char *Cmd)
{
int CmdLFPac(const char *Cmd) {
clearCommandBuffer();
CmdsParse(CommandTable, Cmd);
return 0;
}
int CmdHelp(const char *Cmd)
{
int CmdHelp(const char *Cmd) {
CmdsHelp(CommandTable);
return 0;
}

View file

@ -21,8 +21,7 @@
#include "lfdemod.h"
static int CmdHelp(const char *Cmd);
int usage_lf_paradox_sim(void)
{
int usage_lf_paradox_sim(void) {
PrintAndLogEx(NORMAL, "Enables simulation of Paradox card with specified card number.");
PrintAndLogEx(NORMAL, "Simulation runs until the button is pressed or another USB command is issued.");
PrintAndLogEx(NORMAL, "The facility-code is 8-bit and the card number is 16-bit. Larger values are truncated.");
@ -39,8 +38,7 @@ int usage_lf_paradox_sim(void)
}
// loop to get raw paradox waveform then FSK demodulate the TAG ID from it
int detectParadox(uint8_t *dest, size_t *size, uint32_t *hi2, uint32_t *hi, uint32_t *lo, int *waveStartIdx)
{
int detectParadox(uint8_t *dest, size_t *size, uint32_t *hi2, uint32_t *hi, uint32_t *lo, int *waveStartIdx) {
//make sure buffer has data
if (*size < 96 * 50) return -1;
@ -79,8 +77,7 @@ int detectParadox(uint8_t *dest, size_t *size, uint32_t *hi2, uint32_t *hi, uint
//by marshmellow
//Paradox Prox demod - FSK2a RF/50 with preamble of 00001111 (then manchester encoded)
//print full Paradox Prox ID and some bit format details if found
int CmdParadoxDemod(const char *Cmd)
{
int CmdParadoxDemod(const char *Cmd) {
//raw fsk demod no manchester decoding no start bit finding just get binary from wave
uint8_t bits[MAX_GRAPH_TRACE_LEN] = {0};
size_t size = getFromGraphBuf(bits);
@ -143,14 +140,12 @@ int CmdParadoxDemod(const char *Cmd)
}
//by marshmellow
//see ASKDemod for what args are accepted
int CmdParadoxRead(const char *Cmd)
{
int CmdParadoxRead(const char *Cmd) {
lf_read(true, 10000);
return CmdParadoxDemod(Cmd);
}
int CmdParadoxSim(const char *Cmd)
{
int CmdParadoxSim(const char *Cmd) {
char cmdp = param_getchar(Cmd, 0);
if (strlen(Cmd) == 0 || cmdp == 'h' || cmdp == 'H') return usage_lf_paradox_sim();
@ -197,15 +192,13 @@ static command_t CommandTable[] = {
{NULL, NULL, 0, NULL}
};
int CmdLFParadox(const char *Cmd)
{
int CmdLFParadox(const char *Cmd) {
clearCommandBuffer();
CmdsParse(CommandTable, Cmd);
return 0;
}
int CmdHelp(const char *Cmd)
{
int CmdHelp(const char *Cmd) {
CmdsHelp(CommandTable);
return 0;
}

View file

@ -35,8 +35,7 @@ struct pcf7931_config configPcf = {
};
// Resets the configuration settings to default values.
int pcf7931_resetConfig()
{
int pcf7931_resetConfig() {
memset(configPcf.Pwd, 0xFF, sizeof(configPcf.Pwd));
configPcf.InitDelay = PCF7931_DEFAULT_INITDELAY;
configPcf.OffsetWidth = PCF7931_DEFAULT_OFFSET_WIDTH;
@ -44,8 +43,7 @@ int pcf7931_resetConfig()
return 0;
}
int pcf7931_printConfig()
{
int pcf7931_printConfig() {
PrintAndLogEx(NORMAL, "Password (LSB first on bytes) : %s", sprint_hex(configPcf.Pwd, sizeof(configPcf.Pwd)));
PrintAndLogEx(NORMAL, "Tag initialization delay : %d us", configPcf.InitDelay);
PrintAndLogEx(NORMAL, "Offset low pulses width : %d us", configPcf.OffsetWidth);
@ -53,8 +51,7 @@ int pcf7931_printConfig()
return 0;
}
int usage_pcf7931_read()
{
int usage_pcf7931_read() {
PrintAndLogEx(NORMAL, "Usage: lf pcf7931 read [h] ");
PrintAndLogEx(NORMAL, "This command tries to read a PCF7931 tag.");
PrintAndLogEx(NORMAL, "Options:");
@ -64,8 +61,7 @@ int usage_pcf7931_read()
return 0;
}
int usage_pcf7931_write()
{
int usage_pcf7931_write() {
PrintAndLogEx(NORMAL, "Usage: lf pcf7931 write [h] <block address> <byte address> <data>");
PrintAndLogEx(NORMAL, "This command tries to write a PCF7931 tag.");
PrintAndLogEx(NORMAL, "Options:");
@ -78,8 +74,7 @@ int usage_pcf7931_write()
return 0;
}
int usage_pcf7931_config()
{
int usage_pcf7931_config() {
PrintAndLogEx(NORMAL, "Usage: lf pcf7931 config [h] [r] <pwd> <delay> <offset width> <offset position>");
PrintAndLogEx(NORMAL, "This command tries to set the configuration used with PCF7931 commands");
PrintAndLogEx(NORMAL, "The time offsets could be useful to correct slew rate generated by the antenna");
@ -99,8 +94,7 @@ int usage_pcf7931_config()
return 0;
}
int CmdLFPCF7931Read(const char *Cmd)
{
int CmdLFPCF7931Read(const char *Cmd) {
uint8_t ctmp = param_getchar(Cmd, 0);
if (ctmp == 'H' || ctmp == 'h') return usage_pcf7931_read();
@ -116,8 +110,7 @@ int CmdLFPCF7931Read(const char *Cmd)
return 0;
}
int CmdLFPCF7931Config(const char *Cmd)
{
int CmdLFPCF7931Config(const char *Cmd) {
uint8_t ctmp = param_getchar(Cmd, 0);
if (ctmp == 0) return pcf7931_printConfig();
@ -134,8 +127,7 @@ int CmdLFPCF7931Config(const char *Cmd)
return 0;
}
int CmdLFPCF7931Write(const char *Cmd)
{
int CmdLFPCF7931Write(const char *Cmd) {
uint8_t ctmp = param_getchar(Cmd, 0);
if (strlen(Cmd) < 1 || ctmp == 'h' || ctmp == 'H') return usage_pcf7931_write();
@ -173,15 +165,13 @@ static command_t CommandTable[] = {
{NULL, NULL, 0, NULL}
};
int CmdLFPCF7931(const char *Cmd)
{
int CmdLFPCF7931(const char *Cmd) {
clearCommandBuffer();
CmdsParse(CommandTable, Cmd);
return 0;
}
int CmdHelp(const char *Cmd)
{
int CmdHelp(const char *Cmd) {
CmdsHelp(CommandTable);
return 0;
}

View file

@ -10,8 +10,7 @@
#include "cmdlfpresco.h"
static int CmdHelp(const char *Cmd);
int usage_lf_presco_clone(void)
{
int usage_lf_presco_clone(void) {
PrintAndLogEx(NORMAL, "clone a Presco tag to a T55x7 tag.");
PrintAndLogEx(NORMAL, "Usage: lf presco clone [h] d <Card-ID> c <hex-ID> <Q5>");
PrintAndLogEx(NORMAL, "Options:");
@ -25,8 +24,7 @@ int usage_lf_presco_clone(void)
return 0;
}
int usage_lf_presco_sim(void)
{
int usage_lf_presco_sim(void) {
PrintAndLogEx(NORMAL, "Enables simulation of presco card with specified card number.");
PrintAndLogEx(NORMAL, "Simulation runs until the button is pressed or another USB command is issued.");
PrintAndLogEx(NORMAL, "Per presco format, the card number is 9 digit number and can contain *# chars. Larger values are truncated.");
@ -43,8 +41,7 @@ int usage_lf_presco_sim(void)
}
// find presco preamble 0x10D in already demoded data
int detectPresco(uint8_t *dest, size_t *size)
{
int detectPresco(uint8_t *dest, size_t *size) {
if (*size < 128 * 2) return -1; //make sure buffer has data
size_t startIdx = 0;
uint8_t preamble[] = {0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
@ -56,8 +53,7 @@ int detectPresco(uint8_t *dest, size_t *size)
}
// convert base 12 ID to sitecode & usercode & 8 bit other unknown code
int GetWiegandFromPresco(const char *Cmd, uint32_t *sitecode, uint32_t *usercode, uint32_t *fullcode, bool *Q5)
{
int GetWiegandFromPresco(const char *Cmd, uint32_t *sitecode, uint32_t *usercode, uint32_t *fullcode, bool *Q5) {
uint8_t val = 0;
bool hex = false, errors = false;
@ -120,8 +116,7 @@ int GetWiegandFromPresco(const char *Cmd, uint32_t *sitecode, uint32_t *usercode
}
// calc not certain - intended to get bitstream for programming / sim
int GetPrescoBits(uint32_t fullcode, uint8_t *prescoBits)
{
int GetPrescoBits(uint32_t fullcode, uint8_t *prescoBits) {
num_to_bytebits(0x10D00000, 32, prescoBits);
num_to_bytebits(0x00000000, 32, prescoBits + 32);
num_to_bytebits(0x00000000, 32, prescoBits + 64);
@ -130,8 +125,7 @@ int GetPrescoBits(uint32_t fullcode, uint8_t *prescoBits)
}
//see ASKDemod for what args are accepted
int CmdPrescoDemod(const char *Cmd)
{
int CmdPrescoDemod(const char *Cmd) {
bool st = true;
if (!ASKDemod_ext("32 0 0 0 0 a", false, false, 1, &st)) {
PrintAndLogEx(DEBUG, "DEBUG: Error Presco ASKDemod failed");
@ -171,8 +165,7 @@ int CmdPrescoDemod(const char *Cmd)
}
//see ASKDemod for what args are accepted
int CmdPrescoRead(const char *Cmd)
{
int CmdPrescoRead(const char *Cmd) {
// Presco Number: 123456789 --> Sitecode 30 | usercode 8665
lf_read(true, 12000);
return CmdPrescoDemod(Cmd);
@ -180,8 +173,7 @@ int CmdPrescoRead(const char *Cmd)
// takes base 12 ID converts to hex
// Or takes 8 digit hex ID
int CmdPrescoClone(const char *Cmd)
{
int CmdPrescoClone(const char *Cmd) {
bool Q5 = false;
uint32_t sitecode = 0, usercode = 0, fullcode = 0;
@ -229,8 +221,7 @@ int CmdPrescoClone(const char *Cmd)
// takes base 12 ID converts to hex
// Or takes 8 digit hex ID
int CmdPrescoSim(const char *Cmd)
{
int CmdPrescoSim(const char *Cmd) {
uint32_t sitecode = 0, usercode = 0, fullcode = 0;
bool Q5 = false;
// get wiegand from printed number.
@ -259,15 +250,13 @@ static command_t CommandTable[] = {
{NULL, NULL, 0, NULL}
};
int CmdLFPresco(const char *Cmd)
{
int CmdLFPresco(const char *Cmd) {
clearCommandBuffer();
CmdsParse(CommandTable, Cmd);
return 0;
}
int CmdHelp(const char *Cmd)
{
int CmdHelp(const char *Cmd) {
CmdsHelp(CommandTable);
return 0;
}

View file

@ -11,8 +11,7 @@
static int CmdHelp(const char *Cmd);
int usage_lf_pyramid_clone(void)
{
int usage_lf_pyramid_clone(void) {
PrintAndLogEx(NORMAL, "clone a Farpointe/Pyramid tag to a T55x7 tag.");
PrintAndLogEx(NORMAL, "The facility-code is 8-bit and the card number is 16-bit. Larger values are truncated. ");
PrintAndLogEx(NORMAL, "Currently only works on 26bit");
@ -29,8 +28,7 @@ int usage_lf_pyramid_clone(void)
return 0;
}
int usage_lf_pyramid_sim(void)
{
int usage_lf_pyramid_sim(void) {
PrintAndLogEx(NORMAL, "Enables simulation of Farpointe/Pyramid card with specified card number.");
PrintAndLogEx(NORMAL, "Simulation runs until the button is pressed or another USB command is issued.");
PrintAndLogEx(NORMAL, "The facility-code is 8-bit and the card number is 16-bit. Larger values are truncated.");
@ -49,8 +47,7 @@ int usage_lf_pyramid_sim(void)
// by marshmellow
// FSK Demod then try to locate a Farpointe Data (pyramid) ID
int detectPyramid(uint8_t *dest, size_t *size, int *waveStartIdx)
{
int detectPyramid(uint8_t *dest, size_t *size, int *waveStartIdx) {
//make sure buffer has data
if (*size < 128 * 50) return -1;
@ -75,8 +72,7 @@ int detectPyramid(uint8_t *dest, size_t *size, int *waveStartIdx)
}
// Works for 26bits.
int GetPyramidBits(uint32_t fc, uint32_t cn, uint8_t *pyramidBits)
{
int GetPyramidBits(uint32_t fc, uint32_t cn, uint8_t *pyramidBits) {
uint8_t pre[128];
memset(pre, 0x00, sizeof(pre));
@ -109,8 +105,7 @@ int GetPyramidBits(uint32_t fc, uint32_t cn, uint8_t *pyramidBits)
//by marshmellow
//Pyramid Prox demod - FSK RF/50 with preamble of 0000000000000001 (always a 128 bit data stream)
//print full Farpointe Data/Pyramid Prox ID and some bit format details if found
int CmdPyramidDemod(const char *Cmd)
{
int CmdPyramidDemod(const char *Cmd) {
//raw fsk demod no manchester decoding no start bit finding just get binary from wave
uint8_t bits[MAX_GRAPH_TRACE_LEN] = {0};
size_t size = getFromGraphBuf(bits);
@ -252,14 +247,12 @@ int CmdPyramidDemod(const char *Cmd)
return 1;
}
int CmdPyramidRead(const char *Cmd)
{
int CmdPyramidRead(const char *Cmd) {
lf_read(true, 15000);
return CmdPyramidDemod(Cmd);
}
int CmdPyramidClone(const char *Cmd)
{
int CmdPyramidClone(const char *Cmd) {
char cmdp = param_getchar(Cmd, 0);
if (strlen(Cmd) == 0 || cmdp == 'h' || cmdp == 'H') return usage_lf_pyramid_clone();
@ -310,8 +303,7 @@ int CmdPyramidClone(const char *Cmd)
return 0;
}
int CmdPyramidSim(const char *Cmd)
{
int CmdPyramidSim(const char *Cmd) {
char cmdp = param_getchar(Cmd, 0);
if (strlen(Cmd) == 0 || cmdp == 'h' || cmdp == 'H') return usage_lf_pyramid_sim();
@ -356,15 +348,13 @@ static command_t CommandTable[] = {
{NULL, NULL, 0, NULL}
};
int CmdLFPyramid(const char *Cmd)
{
int CmdLFPyramid(const char *Cmd) {
clearCommandBuffer();
CmdsParse(CommandTable, Cmd);
return 0;
}
int CmdHelp(const char *Cmd)
{
int CmdHelp(const char *Cmd) {
CmdsHelp(CommandTable);
return 0;
}

View file

@ -13,8 +13,7 @@ static int CmdHelp(const char *Cmd);
// by marshmellow
// find Securakey preamble in already demoded data
int detectSecurakey(uint8_t *dest, size_t *size)
{
int detectSecurakey(uint8_t *dest, size_t *size) {
if (*size < 96) return -1; //make sure buffer has data
size_t startIdx = 0;
uint8_t preamble[] = {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1};
@ -26,8 +25,7 @@ int detectSecurakey(uint8_t *dest, size_t *size)
}
//see ASKDemod for what args are accepted
int CmdSecurakeyDemod(const char *Cmd)
{
int CmdSecurakeyDemod(const char *Cmd) {
//ASK / Manchester
bool st = false;
@ -108,8 +106,7 @@ int CmdSecurakeyDemod(const char *Cmd)
return 1;
}
int CmdSecurakeyRead(const char *Cmd)
{
int CmdSecurakeyRead(const char *Cmd) {
lf_read(true, 8000);
return CmdSecurakeyDemod(Cmd);
}
@ -123,15 +120,13 @@ static command_t CommandTable[] = {
{NULL, NULL, 0, NULL}
};
int CmdLFSecurakey(const char *Cmd)
{
int CmdLFSecurakey(const char *Cmd) {
clearCommandBuffer();
CmdsParse(CommandTable, Cmd);
return 0;
}
int CmdHelp(const char *Cmd)
{
int CmdHelp(const char *Cmd) {
CmdsHelp(CommandTable);
return 0;
}

View file

@ -11,17 +11,14 @@
// Default configuration
t55xx_conf_block_t config = { .modulation = DEMOD_ASK, .inverted = false, .offset = 0x00, .block0 = 0x00, .Q5 = false };
t55xx_conf_block_t Get_t55xx_Config()
{
t55xx_conf_block_t Get_t55xx_Config() {
return config;
}
void Set_t55xx_Config(t55xx_conf_block_t conf)
{
void Set_t55xx_Config(t55xx_conf_block_t conf) {
config = conf;
}
int usage_t55xx_config()
{
int usage_t55xx_config() {
PrintAndLogEx(NORMAL, "Usage: lf t55xx config [d <demodulation>] [i 1] [o <offset>] [Q5]");
PrintAndLogEx(NORMAL, "Options:");
PrintAndLogEx(NORMAL, " h - This help");
@ -39,8 +36,7 @@ int usage_t55xx_config()
PrintAndLogEx(NORMAL, "");
return 0;
}
int usage_t55xx_read()
{
int usage_t55xx_read() {
PrintAndLogEx(NORMAL, "Usage: lf t55xx read [b <block>] [p <password>] <override_safety> <page1>");
PrintAndLogEx(NORMAL, "Options:");
PrintAndLogEx(NORMAL, " b <block> - block number to read. Between 0-7");
@ -58,8 +54,7 @@ int usage_t55xx_read()
PrintAndLogEx(NORMAL, "");
return 0;
}
int usage_t55xx_write()
{
int usage_t55xx_write() {
PrintAndLogEx(NORMAL, "Usage: lf t55xx write [b <block>] [d <data>] [p <password>] [1] [t]");
PrintAndLogEx(NORMAL, "Options:");
PrintAndLogEx(NORMAL, " b <block> - block number to write. Between 0-7");
@ -74,8 +69,7 @@ int usage_t55xx_write()
PrintAndLogEx(NORMAL, "");
return 0;
}
int usage_t55xx_trace()
{
int usage_t55xx_trace() {
PrintAndLogEx(NORMAL, "Usage: lf t55xx trace [1]");
PrintAndLogEx(NORMAL, "Options:");
PrintAndLogEx(NORMAL, " 1 - if set, use Graphbuffer otherwise read data from tag.");
@ -86,8 +80,7 @@ int usage_t55xx_trace()
PrintAndLogEx(NORMAL, "");
return 0;
}
int usage_t55xx_info()
{
int usage_t55xx_info() {
PrintAndLogEx(NORMAL, "Usage: lf t55xx info [1]");
PrintAndLogEx(NORMAL, "Options:");
PrintAndLogEx(NORMAL, " 1 - if set, use Graphbuffer otherwise read data from tag.");
@ -98,8 +91,7 @@ int usage_t55xx_info()
PrintAndLogEx(NORMAL, "");
return 0;
}
int usage_t55xx_dump()
{
int usage_t55xx_dump() {
PrintAndLogEx(NORMAL, "Usage: lf t55xx dump <password> [o]");
PrintAndLogEx(NORMAL, "Options:");
PrintAndLogEx(NORMAL, " <password> - OPTIONAL password 4bytes (8 hex symbols)");
@ -111,8 +103,7 @@ int usage_t55xx_dump()
PrintAndLogEx(NORMAL, "");
return 0;
}
int usage_t55xx_detect()
{
int usage_t55xx_detect() {
PrintAndLogEx(NORMAL, "Usage: lf t55xx detect [1] [p <password>]");
PrintAndLogEx(NORMAL, "Options:");
PrintAndLogEx(NORMAL, " 1 - if set, use Graphbuffer otherwise read data from tag.");
@ -125,8 +116,7 @@ int usage_t55xx_detect()
PrintAndLogEx(NORMAL, "");
return 0;
}
int usage_t55xx_detectP1()
{
int usage_t55xx_detectP1() {
PrintAndLogEx(NORMAL, "Command: Detect Page 1 of a t55xx chip");
PrintAndLogEx(NORMAL, "Usage: lf t55xx p1detect [1] [p <password>]");
PrintAndLogEx(NORMAL, "Options:");
@ -140,8 +130,7 @@ int usage_t55xx_detectP1()
PrintAndLogEx(NORMAL, "");
return 0;
}
int usage_t55xx_wakup()
{
int usage_t55xx_wakup() {
PrintAndLogEx(NORMAL, "Usage: lf t55xx wakeup [h] p <password>");
PrintAndLogEx(NORMAL, "This commands send the Answer-On-Request command and leaves the readerfield ON afterwards.");
PrintAndLogEx(NORMAL, "Options:");
@ -152,8 +141,7 @@ int usage_t55xx_wakup()
PrintAndLogEx(NORMAL, " lf t55xx wakeup p 11223344 - send wakeup password");
return 0;
}
int usage_t55xx_chk()
{
int usage_t55xx_chk() {
PrintAndLogEx(NORMAL, "This command uses a dictionary attack");
PrintAndLogEx(NORMAL, "press 'enter' to cancel the command");
PrintAndLogEx(NORMAL, "Usage: lf t55xx bruteforce [h] <m> [i <*.dic>]");
@ -168,8 +156,7 @@ int usage_t55xx_chk()
PrintAndLogEx(NORMAL, "");
return 0;
}
int usage_t55xx_bruteforce()
{
int usage_t55xx_bruteforce() {
PrintAndLogEx(NORMAL, "This command uses bruteforce to scan a number range");
PrintAndLogEx(NORMAL, "press 'enter' to cancel the command");
PrintAndLogEx(NORMAL, "Usage: lf t55xx bruteforce [h] <start password> <end password>");
@ -184,8 +171,7 @@ int usage_t55xx_bruteforce()
PrintAndLogEx(NORMAL, "");
return 0;
}
int usage_t55xx_recoverpw()
{
int usage_t55xx_recoverpw() {
PrintAndLogEx(NORMAL, "This command uses a few tricks to try to recover mangled password");
PrintAndLogEx(NORMAL, "press 'enter' to cancel the command");
PrintAndLogEx(NORMAL, "WARNING: this may brick non-password protected chips!");
@ -202,8 +188,7 @@ int usage_t55xx_recoverpw()
PrintAndLogEx(NORMAL, "");
return 0;
}
int usage_t55xx_wipe()
{
int usage_t55xx_wipe() {
PrintAndLogEx(NORMAL, "Usage: lf t55xx wipe [h] [Q5]");
PrintAndLogEx(NORMAL, "This commands wipes a tag, fills blocks 1-7 with zeros and a default configuration block");
PrintAndLogEx(NORMAL, "Options:");
@ -215,8 +200,7 @@ int usage_t55xx_wipe()
PrintAndLogEx(NORMAL, " lf t55xx wipe Q5 - wipes a t5555 Q5 tag, config block 0x6001F004");
return 0;
}
int usage_lf_deviceconfig()
{
int usage_lf_deviceconfig() {
PrintAndLogEx(NORMAL, "Sets t55x7 timings for direkt commands. The timings are set here in Field Clocks (FC), \nwhich is converted to (US) on device");
PrintAndLogEx(NORMAL, "Usage: lf t55xx deviceconfig a <gap> b <gap> c <gap> d <gap> e <gap> p");
PrintAndLogEx(NORMAL, "Options:");
@ -237,15 +221,13 @@ int usage_lf_deviceconfig()
int CmdHelp(const char *Cmd);
void printT5xxHeader(uint8_t page)
{
void printT5xxHeader(uint8_t page) {
PrintAndLogEx(NORMAL, "Reading Page %d:", page);
PrintAndLogEx(NORMAL, "blk | hex data | binary | ascii");
PrintAndLogEx(NORMAL, "----+----------+----------------------------------+-------");
}
int CmdT55xxSetConfig(const char *Cmd)
{
int CmdT55xxSetConfig(const char *Cmd) {
uint8_t offset = 0;
char modulation[6] = {0x00};
@ -347,8 +329,7 @@ int CmdT55xxSetConfig(const char *Cmd)
return printConfiguration(config);
}
int T55xxReadBlock(uint8_t block, bool page1, bool usepwd, bool override, uint32_t password)
{
int T55xxReadBlock(uint8_t block, bool page1, bool usepwd, bool override, uint32_t password) {
//Password mode
if (usepwd) {
// try reading the config block and verify that PWD bit is set before doing this!
@ -378,8 +359,7 @@ int T55xxReadBlock(uint8_t block, bool page1, bool usepwd, bool override, uint32
return 1;
}
int CmdT55xxReadBlock(const char *Cmd)
{
int CmdT55xxReadBlock(const char *Cmd) {
uint8_t block = REGULAR_READ_MODE_BLOCK;
uint32_t password = 0; //default to blank Block 7
bool usepwd = false;
@ -425,8 +405,7 @@ int CmdT55xxReadBlock(const char *Cmd)
return T55xxReadBlock(block, page1, usepwd, override, password);
}
bool DecodeT55xxBlock()
{
bool DecodeT55xxBlock() {
char buf[30] = {0x00};
char *cmdStr = buf;
@ -489,8 +468,7 @@ bool DecodeT55xxBlock()
return (bool) ans;
}
bool DecodeT5555TraceBlock()
{
bool DecodeT5555TraceBlock() {
DemodBufferLen = 0x00;
// According to datasheet. Always: RF/64, not inverted, Manchester
@ -498,8 +476,7 @@ bool DecodeT5555TraceBlock()
}
// sanity check. Don't use proxmark if it is offline and you didn't specify useGraphbuf
static int SanityOfflineCheck(bool useGraphBuffer)
{
static int SanityOfflineCheck(bool useGraphBuffer) {
if (!useGraphBuffer && IsOffline()) {
PrintAndLogEx(NORMAL, "Your proxmark3 device is offline. Specify [1] to use graphbuffer data instead");
return 0;
@ -507,8 +484,7 @@ static int SanityOfflineCheck(bool useGraphBuffer)
return 1;
}
int CmdT55xxDetect(const char *Cmd)
{
int CmdT55xxDetect(const char *Cmd) {
bool errors = false;
bool useGB = false, usepwd = false;
uint32_t password = 0;
@ -551,8 +527,7 @@ int CmdT55xxDetect(const char *Cmd)
}
// detect configuration?
bool tryDetectModulation()
{
bool tryDetectModulation() {
t55xx_conf_block_t tests[15];
int bitRate = 0, clk = 0, firstClockEdge = 0;
@ -738,8 +713,7 @@ bool tryDetectModulation()
return retval;
}
bool testKnownConfigBlock(uint32_t block0)
{
bool testKnownConfigBlock(uint32_t block0) {
switch (block0) {
case T55X7_DEFAULT_CONFIG_BLOCK:
case T55X7_RAW_CONFIG_BLOCK:
@ -759,8 +733,7 @@ bool testKnownConfigBlock(uint32_t block0)
return false;
}
bool testModulation(uint8_t mode, uint8_t modread)
{
bool testModulation(uint8_t mode, uint8_t modread) {
switch (mode) {
case DEMOD_FSK:
if (modread >= DEMOD_FSK1 && modread <= DEMOD_FSK2a) return true;
@ -792,8 +765,7 @@ bool testModulation(uint8_t mode, uint8_t modread)
return false;
}
bool testQ5Modulation(uint8_t mode, uint8_t modread)
{
bool testQ5Modulation(uint8_t mode, uint8_t modread) {
switch (mode) {
case DEMOD_FSK:
if (modread >= 4 && modread <= 5) return true;
@ -822,8 +794,7 @@ bool testQ5Modulation(uint8_t mode, uint8_t modread)
return false;
}
int convertQ5bitRate(uint8_t bitRateRead)
{
int convertQ5bitRate(uint8_t bitRateRead) {
uint8_t expected[] = {8, 16, 32, 40, 50, 64, 100, 128};
for (int i = 0; i < 8; i++)
if (expected[i] == bitRateRead)
@ -832,8 +803,7 @@ int convertQ5bitRate(uint8_t bitRateRead)
return -1;
}
bool testQ5(uint8_t mode, uint8_t *offset, int *fndBitRate, uint8_t clk)
{
bool testQ5(uint8_t mode, uint8_t *offset, int *fndBitRate, uint8_t clk) {
if (DemodBufferLen < 64) return false;
uint8_t si = 0;
@ -878,8 +848,7 @@ bool testQ5(uint8_t mode, uint8_t *offset, int *fndBitRate, uint8_t clk)
return false;
}
bool testBitRate(uint8_t readRate, uint8_t clk)
{
bool testBitRate(uint8_t readRate, uint8_t clk) {
uint8_t expected[] = {8, 16, 32, 40, 50, 64, 100, 128};
if (expected[readRate] == clk)
return true;
@ -887,8 +856,7 @@ bool testBitRate(uint8_t readRate, uint8_t clk)
return false;
}
bool test(uint8_t mode, uint8_t *offset, int *fndBitRate, uint8_t clk, bool *Q5)
{
bool test(uint8_t mode, uint8_t *offset, int *fndBitRate, uint8_t clk, bool *Q5) {
if (DemodBufferLen < 64) return false;
uint8_t si = 0;
@ -938,8 +906,7 @@ bool test(uint8_t mode, uint8_t *offset, int *fndBitRate, uint8_t clk, bool *Q5)
return false;
}
void printT55xxBlock(const char *blockNum)
{
void printT55xxBlock(const char *blockNum) {
uint8_t i = config.offset;
uint8_t endpos = 32 + i;
@ -963,8 +930,7 @@ void printT55xxBlock(const char *blockNum)
PrintAndLogEx(NORMAL, " %s | %08X | %s | %s", blockNum, blockData, sprint_bin(bits, 32), sprint_ascii(bytes, 4));
}
int special(const char *Cmd)
{
int special(const char *Cmd) {
uint32_t blockData = 0;
uint8_t bits[32] = {0x00};
@ -983,8 +949,7 @@ int special(const char *Cmd)
return 0;
}
int printConfiguration(t55xx_conf_block_t b)
{
int printConfiguration(t55xx_conf_block_t b) {
PrintAndLogEx(NORMAL, "Chip Type : %s", (b.Q5) ? "T5555(Q5)" : "T55x7");
PrintAndLogEx(NORMAL, "Modulation : %s", GetSelectedModulationStr(b.modulation));
PrintAndLogEx(NORMAL, "Bit Rate : %s", GetBitRateStr(b.bitrate, (b.block0 & T55x7_X_MODE && (b.block0 >> 28 == 6 || b.block0 >> 28 == 9))));
@ -996,8 +961,7 @@ int printConfiguration(t55xx_conf_block_t b)
return 0;
}
int CmdT55xxWakeUp(const char *Cmd)
{
int CmdT55xxWakeUp(const char *Cmd) {
uint32_t password = 0;
uint8_t cmdp = 0;
bool errors = false;
@ -1025,8 +989,7 @@ int CmdT55xxWakeUp(const char *Cmd)
return 0;
}
int CmdT55xxWriteBlock(const char *Cmd)
{
int CmdT55xxWriteBlock(const char *Cmd) {
uint8_t block = 0xFF; //default to invalid block
uint32_t data = 0; //default to blank Block
uint32_t password = 0; //default to blank Block 7
@ -1099,8 +1062,7 @@ int CmdT55xxWriteBlock(const char *Cmd)
return 1;
}
int CmdT55xxReadTrace(const char *Cmd)
{
int CmdT55xxReadTrace(const char *Cmd) {
char cmdp = tolower(param_getchar(Cmd, 0));
if (strlen(Cmd) > 1 || cmdp == 'h') return usage_t55xx_trace();
@ -1220,8 +1182,7 @@ int CmdT55xxReadTrace(const char *Cmd)
return 0;
}
void printT55x7Trace(t55x7_tracedata_t data, uint8_t repeat)
{
void printT55x7Trace(t55x7_tracedata_t data, uint8_t repeat) {
PrintAndLogEx(NORMAL, "-- T55x7 Trace Information ----------------------------------");
PrintAndLogEx(NORMAL, "-------------------------------------------------------------");
PrintAndLogEx(NORMAL, " ACL Allocation class (ISO/IEC 15963-1) : 0x%02X (%d)", data.acl, data.acl);
@ -1257,8 +1218,7 @@ void printT55x7Trace(t55x7_tracedata_t data, uint8_t repeat)
*/
}
void printT5555Trace(t5555_tracedata_t data, uint8_t repeat)
{
void printT5555Trace(t5555_tracedata_t data, uint8_t repeat) {
PrintAndLogEx(NORMAL, "-- T5555 (Q5) Trace Information -----------------------------");
PrintAndLogEx(NORMAL, "-------------------------------------------------------------");
PrintAndLogEx(NORMAL, " ICR IC Revision : %d", data.icr);
@ -1286,8 +1246,7 @@ void printT5555Trace(t5555_tracedata_t data, uint8_t repeat)
}
//need to add Q5 info...
int CmdT55xxInfo(const char *Cmd)
{
int CmdT55xxInfo(const char *Cmd) {
/*
Page 0 Block 0 Configuration data.
Normal mode
@ -1373,8 +1332,7 @@ int CmdT55xxInfo(const char *Cmd)
return 0;
}
int CmdT55xxDump(const char *Cmd)
{
int CmdT55xxDump(const char *Cmd) {
uint32_t password = 0;
bool override = false;
@ -1399,8 +1357,7 @@ int CmdT55xxDump(const char *Cmd)
return 1;
}
bool AquireData(uint8_t page, uint8_t block, bool pwdmode, uint32_t password)
{
bool AquireData(uint8_t page, uint8_t block, bool pwdmode, uint32_t password) {
// arg0 bitmodes:
// bit0 = pwdmode
// bit1 = page to read from
@ -1420,8 +1377,7 @@ bool AquireData(uint8_t page, uint8_t block, bool pwdmode, uint32_t password)
return !getSignalProperties()->isnoise;
}
char *GetBitRateStr(uint32_t id, bool xmode)
{
char *GetBitRateStr(uint32_t id, bool xmode) {
static char buf[25];
char *retStr = buf;
@ -1461,8 +1417,7 @@ char *GetBitRateStr(uint32_t id, bool xmode)
return buf;
}
char *GetSaferStr(uint32_t id)
{
char *GetSaferStr(uint32_t id) {
static char buf[40];
char *retStr = buf;
@ -1477,8 +1432,7 @@ char *GetSaferStr(uint32_t id)
return buf;
}
char *GetModulationStr(uint32_t id)
{
char *GetModulationStr(uint32_t id) {
static char buf[60];
char *retStr = buf;
@ -1526,8 +1480,7 @@ char *GetModulationStr(uint32_t id)
return buf;
}
char *GetModelStrFromCID(uint32_t cid)
{
char *GetModelStrFromCID(uint32_t cid) {
static char buf[10];
char *retStr = buf;
@ -1537,8 +1490,7 @@ char *GetModelStrFromCID(uint32_t cid)
return buf;
}
char *GetSelectedModulationStr(uint8_t id)
{
char *GetSelectedModulationStr(uint8_t id) {
static char buf[20];
char *retStr = buf;
@ -1587,8 +1539,7 @@ char *GetSelectedModulationStr(uint8_t id)
return buf;
}
void t55x7_create_config_block(int tagtype)
{
void t55x7_create_config_block(int tagtype) {
/*
T55X7_DEFAULT_CONFIG_BLOCK, T55X7_RAW_CONFIG_BLOCK
@ -1615,8 +1566,7 @@ void t55x7_create_config_block(int tagtype)
PrintAndLogEx(NORMAL, buf);
}
int CmdResetRead(const char *Cmd)
{
int CmdResetRead(const char *Cmd) {
UsbCommand c = {CMD_T55XX_RESET_READ, {0, 0, 0}};
clearCommandBuffer();
SendCommand(&c);
@ -1634,8 +1584,7 @@ int CmdResetRead(const char *Cmd)
return 1;
}
int CmdT55xxWipe(const char *Cmd)
{
int CmdT55xxWipe(const char *Cmd) {
char writeData[20] = {0};
char *ptrData = writeData;
char cmdp = tolower(param_getchar(Cmd, 0));
@ -1665,8 +1614,7 @@ int CmdT55xxWipe(const char *Cmd)
return 0;
}
bool IsCancelled(void)
{
bool IsCancelled(void) {
if (ukbhit()) {
int gc = getchar();
(void)gc;
@ -1676,8 +1624,7 @@ bool IsCancelled(void)
return false;
}
int CmdT55xxChkPwds(const char *Cmd)
{
int CmdT55xxChkPwds(const char *Cmd) {
// load a default pwd file.
char line[9];
char filename[FILE_PATH_SIZE] = {0};
@ -1848,8 +1795,7 @@ out:
return 0;
}
int CmdT55xxBruteForce(const char *Cmd)
{
int CmdT55xxBruteForce(const char *Cmd) {
uint32_t start_password = 0x00000000; //start password
uint32_t end_password = 0xFFFFFFFF; //end password
@ -1909,8 +1855,7 @@ int CmdT55xxBruteForce(const char *Cmd)
return 0;
}
int tryOnePassword(uint32_t password)
{
int tryOnePassword(uint32_t password) {
PrintAndLogEx(INFO, "Trying password %08x", password);
if (!AquireData(T55x7_PAGE0, T55x7_CONFIGURATION_BLOCK, true, password)) {
PrintAndLogEx(NORMAL, "Acquire data from device failed. Quitting");
@ -1923,8 +1868,7 @@ int tryOnePassword(uint32_t password)
return 0;
}
int CmdT55xxRecoverPW(const char *Cmd)
{
int CmdT55xxRecoverPW(const char *Cmd) {
int bit = 0;
uint32_t orig_password = 0x0;
uint32_t curr_password = 0x0;
@ -2001,8 +1945,7 @@ int CmdT55xxRecoverPW(const char *Cmd)
// note length of data returned is different for different chips.
// some return all page 1 (64 bits) and others return just that block (32 bits)
// unfortunately the 64 bits makes this more likely to get a false positive...
bool tryDetectP1(bool getData)
{
bool tryDetectP1(bool getData) {
uint8_t preamble[] = {1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1};
size_t startIdx = 0;
uint8_t fc1 = 0, fc2 = 0, ans = 0;
@ -2018,13 +1961,13 @@ bool tryDetectP1(bool getData)
ans = fskClocks(&fc1, &fc2, (uint8_t *)&clk, &firstClockEdge);
if (ans && ((fc1 == 10 && fc2 == 8) || (fc1 == 8 && fc2 == 5))) {
if (FSKrawDemod("0 0", false) &&
preambleSearchEx(DemodBuffer, preamble, sizeof(preamble), &DemodBufferLen, &startIdx, false) &&
(DemodBufferLen == 32 || DemodBufferLen == 64)) {
preambleSearchEx(DemodBuffer, preamble, sizeof(preamble), &DemodBufferLen, &startIdx, false) &&
(DemodBufferLen == 32 || DemodBufferLen == 64)) {
return true;
}
if (FSKrawDemod("0 1", false) &&
preambleSearchEx(DemodBuffer, preamble, sizeof(preamble), &DemodBufferLen, &startIdx, false) &&
(DemodBufferLen == 32 || DemodBufferLen == 64)) {
preambleSearchEx(DemodBuffer, preamble, sizeof(preamble), &DemodBufferLen, &startIdx, false) &&
(DemodBufferLen == 32 || DemodBufferLen == 64)) {
return true;
}
return false;
@ -2034,24 +1977,24 @@ bool tryDetectP1(bool getData)
clk = GetAskClock("", false);
if (clk > 0) {
if (ASKDemod_ext("0 0 1", false, false, 1, &st) &&
preambleSearchEx(DemodBuffer, preamble, sizeof(preamble), &DemodBufferLen, &startIdx, false) &&
(DemodBufferLen == 32 || DemodBufferLen == 64)) {
preambleSearchEx(DemodBuffer, preamble, sizeof(preamble), &DemodBufferLen, &startIdx, false) &&
(DemodBufferLen == 32 || DemodBufferLen == 64)) {
return true;
}
st = true;
if (ASKDemod_ext("0 1 1", false, false, 1, &st) &&
preambleSearchEx(DemodBuffer, preamble, sizeof(preamble), &DemodBufferLen, &startIdx, false) &&
(DemodBufferLen == 32 || DemodBufferLen == 64)) {
preambleSearchEx(DemodBuffer, preamble, sizeof(preamble), &DemodBufferLen, &startIdx, false) &&
(DemodBufferLen == 32 || DemodBufferLen == 64)) {
return true;
}
if (ASKbiphaseDemod("0 0 0 2", false) &&
preambleSearchEx(DemodBuffer, preamble, sizeof(preamble), &DemodBufferLen, &startIdx, false) &&
(DemodBufferLen == 32 || DemodBufferLen == 64)) {
preambleSearchEx(DemodBuffer, preamble, sizeof(preamble), &DemodBufferLen, &startIdx, false) &&
(DemodBufferLen == 32 || DemodBufferLen == 64)) {
return true;
}
if (ASKbiphaseDemod("0 0 1 2", false) &&
preambleSearchEx(DemodBuffer, preamble, sizeof(preamble), &DemodBufferLen, &startIdx, false) &&
(DemodBufferLen == 32 || DemodBufferLen == 64)) {
preambleSearchEx(DemodBuffer, preamble, sizeof(preamble), &DemodBufferLen, &startIdx, false) &&
(DemodBufferLen == 32 || DemodBufferLen == 64)) {
return true;
}
}
@ -2060,13 +2003,13 @@ bool tryDetectP1(bool getData)
clk = GetNrzClock("", false); //has the most false positives :(
if (clk > 0) {
if (NRZrawDemod("0 0 1", false) &&
preambleSearchEx(DemodBuffer, preamble, sizeof(preamble), &DemodBufferLen, &startIdx, false) &&
(DemodBufferLen == 32 || DemodBufferLen == 64)) {
preambleSearchEx(DemodBuffer, preamble, sizeof(preamble), &DemodBufferLen, &startIdx, false) &&
(DemodBufferLen == 32 || DemodBufferLen == 64)) {
return true;
}
if (NRZrawDemod("0 1 1", false) &&
preambleSearchEx(DemodBuffer, preamble, sizeof(preamble), &DemodBufferLen, &startIdx, false) &&
(DemodBufferLen == 32 || DemodBufferLen == 64)) {
preambleSearchEx(DemodBuffer, preamble, sizeof(preamble), &DemodBufferLen, &startIdx, false) &&
(DemodBufferLen == 32 || DemodBufferLen == 64)) {
return true;
}
}
@ -2080,14 +2023,14 @@ bool tryDetectP1(bool getData)
// skip first 160 samples to allow antenna to settle in (psk gets inverted occasionally otherwise)
//CmdLtrim("160");
if (PSKDemod("0 0 6", false) &&
preambleSearchEx(DemodBuffer, preamble, sizeof(preamble), &DemodBufferLen, &startIdx, false) &&
(DemodBufferLen == 32 || DemodBufferLen == 64)) {
preambleSearchEx(DemodBuffer, preamble, sizeof(preamble), &DemodBufferLen, &startIdx, false) &&
(DemodBufferLen == 32 || DemodBufferLen == 64)) {
//save_restoreGB(GRAPH_RESTORE);
return true;
}
if (PSKDemod("0 1 6", false) &&
preambleSearchEx(DemodBuffer, preamble, sizeof(preamble), &DemodBufferLen, &startIdx, false) &&
(DemodBufferLen == 32 || DemodBufferLen == 64)) {
preambleSearchEx(DemodBuffer, preamble, sizeof(preamble), &DemodBufferLen, &startIdx, false) &&
(DemodBufferLen == 32 || DemodBufferLen == 64)) {
//save_restoreGB(GRAPH_RESTORE);
return true;
}
@ -2095,7 +2038,7 @@ bool tryDetectP1(bool getData)
if (PSKDemod("0 0 6", false)) {
psk1TOpsk2(DemodBuffer, DemodBufferLen);
if (preambleSearchEx(DemodBuffer, preamble, sizeof(preamble), &DemodBufferLen, &startIdx, false) &&
(DemodBufferLen == 32 || DemodBufferLen == 64)) {
(DemodBufferLen == 32 || DemodBufferLen == 64)) {
//save_restoreGB(GRAPH_RESTORE);
return true;
}
@ -2109,8 +2052,7 @@ bool tryDetectP1(bool getData)
return false;
}
// does this need to be a callable command?
int CmdT55xxDetectPage1(const char *Cmd)
{
int CmdT55xxDetectPage1(const char *Cmd) {
bool errors = false;
bool useGB = false;
bool usepwd = false;
@ -2148,8 +2090,7 @@ int CmdT55xxDetectPage1(const char *Cmd)
return success;
}
int CmdT55xxSetDeviceConfig(const char *Cmd)
{
int CmdT55xxSetDeviceConfig(const char *Cmd) {
uint8_t startgap = 0, writegap = 0;
uint8_t write0 = 0, write1 = 0, readgap = 0;
bool errors = false, shall_persist = false;
@ -2222,15 +2163,13 @@ static command_t CommandTable[] = {
{NULL, NULL, 0, NULL}
};
int CmdLFT55XX(const char *Cmd)
{
int CmdLFT55XX(const char *Cmd) {
clearCommandBuffer();
CmdsParse(CommandTable, Cmd);
return 0;
}
int CmdHelp(const char *Cmd)
{
int CmdHelp(const char *Cmd) {
CmdsHelp(CommandTable);
return 0;
}

View file

@ -21,8 +21,7 @@
static int CmdHelp(const char *Cmd);
int CmdTIDemod(const char *Cmd)
{
int CmdTIDemod(const char *Cmd) {
/* MATLAB as follows:
f_s = 2000000; % sampling frequency
f_l = 123200; % low FSK tone
@ -276,8 +275,7 @@ out:
}
// read a TI tag and return its ID
int CmdTIRead(const char *Cmd)
{
int CmdTIRead(const char *Cmd) {
UsbCommand c = {CMD_READ_TI_TYPE};
clearCommandBuffer();
SendCommand(&c);
@ -285,8 +283,7 @@ int CmdTIRead(const char *Cmd)
}
// write new data to a r/w TI tag
int CmdTIWrite(const char *Cmd)
{
int CmdTIWrite(const char *Cmd) {
int res = 0;
UsbCommand c = {CMD_WRITE_TI_TYPE};
res = sscanf(Cmd, "%012" SCNx64 " %012" SCNx64 " %012" SCNx64 "", &c.arg[0], &c.arg[1], &c.arg[2]);
@ -311,15 +308,13 @@ static command_t CommandTable[] = {
{NULL, NULL, 0, NULL}
};
int CmdLFTI(const char *Cmd)
{
int CmdLFTI(const char *Cmd) {
clearCommandBuffer();
CmdsParse(CommandTable, Cmd);
return 0;
}
int CmdHelp(const char *Cmd)
{
int CmdHelp(const char *Cmd) {
CmdsHelp(CommandTable);
return 0;
}

View file

@ -11,8 +11,7 @@
static int CmdHelp(const char *Cmd);
int usage_lf_viking_clone(void)
{
int usage_lf_viking_clone(void) {
PrintAndLogEx(NORMAL, "clone a Viking AM tag to a T55x7 tag.");
PrintAndLogEx(NORMAL, "Usage: lf viking clone <Card ID - 8 hex digits> <Q5>");
PrintAndLogEx(NORMAL, "Options:");
@ -24,8 +23,7 @@ int usage_lf_viking_clone(void)
return 0;
}
int usage_lf_viking_sim(void)
{
int usage_lf_viking_sim(void) {
PrintAndLogEx(NORMAL, "Enables simulation of viking card with specified card number.");
PrintAndLogEx(NORMAL, "Simulation runs until the button is pressed or another USB command is issued.");
PrintAndLogEx(NORMAL, "Per viking format, the card number is 8 digit hex number. Larger values are truncated.");
@ -40,8 +38,7 @@ int usage_lf_viking_sim(void)
}
// calc checksum
uint64_t getVikingBits(uint32_t id)
{
uint64_t getVikingBits(uint32_t id) {
uint8_t checksum = ((id >> 24) & 0xFF) ^ ((id >> 16) & 0xFF) ^ ((id >> 8) & 0xFF) ^ (id & 0xFF) ^ 0xF2 ^ 0xA8;
uint64_t ret = (uint64_t)0xF2 << 56;
ret |= (uint64_t)id << 8;
@ -50,8 +47,7 @@ uint64_t getVikingBits(uint32_t id)
}
// by marshmellow
// find viking preamble 0xF200 in already demoded data
int detectViking(uint8_t *dest, size_t *size)
{
int detectViking(uint8_t *dest, size_t *size) {
//make sure buffer has data
if (*size < 64 * 2) return -2;
size_t startIdx = 0;
@ -75,8 +71,7 @@ int detectViking(uint8_t *dest, size_t *size)
//by marshmellow
//see ASKDemod for what args are accepted
int CmdVikingDemod(const char *Cmd)
{
int CmdVikingDemod(const char *Cmd) {
if (!ASKDemod(Cmd, false, false, 1)) {
PrintAndLogEx(DEBUG, "DEBUG: Error - Viking ASKDemod failed");
return 0;
@ -102,14 +97,12 @@ int CmdVikingDemod(const char *Cmd)
//by marshmellow
//see ASKDemod for what args are accepted
int CmdVikingRead(const char *Cmd)
{
int CmdVikingRead(const char *Cmd) {
lf_read(true, 10000);
return CmdVikingDemod(Cmd);
}
int CmdVikingClone(const char *Cmd)
{
int CmdVikingClone(const char *Cmd) {
uint32_t id = 0;
uint64_t rawID = 0;
bool Q5 = false;
@ -138,8 +131,7 @@ int CmdVikingClone(const char *Cmd)
return 0;
}
int CmdVikingSim(const char *Cmd)
{
int CmdVikingSim(const char *Cmd) {
uint32_t id = 0;
uint64_t rawID = 0;
uint8_t clk = 32, encoding = 1, separator = 0, invert = 0;
@ -175,15 +167,13 @@ static command_t CommandTable[] = {
{NULL, NULL, 0, NULL}
};
int CmdLFViking(const char *Cmd)
{
int CmdLFViking(const char *Cmd) {
clearCommandBuffer();
CmdsParse(CommandTable, Cmd);
return 0;
}
int CmdHelp(const char *Cmd)
{
int CmdHelp(const char *Cmd) {
CmdsHelp(CommandTable);
return 0;
}

View file

@ -15,8 +15,7 @@
static int CmdHelp(const char *Cmd);
int usage_lf_visa2k_clone(void)
{
int usage_lf_visa2k_clone(void) {
PrintAndLogEx(NORMAL, "clone a Visa2000 tag to a T55x7 tag.");
PrintAndLogEx(NORMAL, "Usage: lf visa2000 clone [h] <card ID> <Q5>");
PrintAndLogEx(NORMAL, "Options:");
@ -29,8 +28,7 @@ int usage_lf_visa2k_clone(void)
return 0;
}
int usage_lf_visa2k_sim(void)
{
int usage_lf_visa2k_sim(void) {
PrintAndLogEx(NORMAL, "Enables simulation of visa2k card with specified card number.");
PrintAndLogEx(NORMAL, "Simulation runs until the button is pressed or another USB command is issued.");
PrintAndLogEx(NORMAL, "");
@ -44,16 +42,14 @@ int usage_lf_visa2k_sim(void)
return 0;
}
static uint8_t visa_chksum(uint32_t id)
{
static uint8_t visa_chksum(uint32_t id) {
uint8_t sum = 0;
for (uint8_t i = 0; i < 32; i += 4)
sum ^= (id >> i) & 0xF;
return sum & 0xF;
}
static uint8_t visa_parity(uint32_t id)
{
static uint8_t visa_parity(uint32_t id) {
// 4bit parity LUT
uint8_t par_lut[] = {
0, 1, 1, 0
@ -75,8 +71,7 @@ static uint8_t visa_parity(uint32_t id)
// by iceman
// find Visa2000 preamble in already demoded data
int detectVisa2k(uint8_t *dest, size_t *size)
{
int detectVisa2k(uint8_t *dest, size_t *size) {
if (*size < 96) return -1; //make sure buffer has data
size_t startIdx = 0;
uint8_t preamble[] = {0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 0};
@ -99,8 +94,7 @@ int detectVisa2k(uint8_t *dest, size_t *size)
*
**/
//see ASKDemod for what args are accepted
int CmdVisa2kDemod(const char *Cmd)
{
int CmdVisa2kDemod(const char *Cmd) {
save_restoreGB(GRAPH_SAVE);
@ -159,14 +153,12 @@ int CmdVisa2kDemod(const char *Cmd)
}
// 64*96*2=12288 samples just in case we just missed the first preamble we can still catch 2 of them
int CmdVisa2kRead(const char *Cmd)
{
int CmdVisa2kRead(const char *Cmd) {
lf_read(true, 20000);
return CmdVisa2kDemod(Cmd);
}
int CmdVisa2kClone(const char *Cmd)
{
int CmdVisa2kClone(const char *Cmd) {
uint64_t id = 0;
uint32_t blocks[4] = {T55x7_MODULATION_MANCHESTER | T55x7_BITRATE_RF_64 | T55x7_ST_TERMINATOR | 3 << T55x7_MAXBLOCK_SHIFT, BL0CK1, 0};
@ -202,8 +194,7 @@ int CmdVisa2kClone(const char *Cmd)
return 0;
}
int CmdVisa2kSim(const char *Cmd)
{
int CmdVisa2kSim(const char *Cmd) {
uint32_t id = 0;
char cmdp = param_getchar(Cmd, 0);
@ -240,15 +231,13 @@ static command_t CommandTable[] = {
{NULL, NULL, 0, NULL}
};
int CmdLFVisa2k(const char *Cmd)
{
int CmdLFVisa2k(const char *Cmd) {
clearCommandBuffer();
CmdsParse(CommandTable, Cmd);
return 0;
}
int CmdHelp(const char *Cmd)
{
int CmdHelp(const char *Cmd) {
CmdsHelp(CommandTable);
return 0;
}

View file

@ -38,13 +38,11 @@ static command_t CommandTable[] = {
{NULL, NULL, 0, NULL}
};
command_t *getTopLevelCommandTable()
{
command_t *getTopLevelCommandTable() {
return CommandTable;
}
int CmdRem(const char *Cmd)
{
int CmdRem(const char *Cmd) {
char buf[22];
memset(buf, 0x00, sizeof(buf));
@ -56,19 +54,16 @@ int CmdRem(const char *Cmd)
return 0;
}
int CmdHelp(const char *Cmd)
{
int CmdHelp(const char *Cmd) {
CmdsHelp(CommandTable);
return 0;
}
int CmdQuit(const char *Cmd)
{
int CmdQuit(const char *Cmd) {
return 99;
}
int CmdRev(const char *Cmd)
{
int CmdRev(const char *Cmd) {
CmdCrc(Cmd);
return 0;
}
@ -77,7 +72,6 @@ int CmdRev(const char *Cmd)
// Entry point into our code: called whenever the user types a command and
// then presses Enter, which the full command line that they typed.
//-----------------------------------------------------------------------------
int CommandReceived(char *Cmd)
{
int CommandReceived(char *Cmd) {
return CmdsParse(CommandTable, Cmd);
}

View file

@ -17,8 +17,7 @@
#include "proxmark3.h"
#include "comms.h"
void CmdsHelp(const command_t Commands[])
{
void CmdsHelp(const command_t Commands[]) {
if (Commands[0].Name == NULL) return;
int i = 0;
while (Commands[i].Name) {
@ -28,8 +27,7 @@ void CmdsHelp(const command_t Commands[])
}
}
int CmdsParse(const command_t Commands[], const char *Cmd)
{
int CmdsParse(const command_t Commands[], const char *Cmd) {
// Help dump children
if (strcmp(Cmd, "XX_internal_command_dump_XX") == 0) {
dumpCommandsRecursive(Commands, 0);
@ -78,8 +76,7 @@ int CmdsParse(const command_t Commands[], const char *Cmd)
char pparent[512] = {0};
char *parent = pparent;
void dumpCommandsRecursive(const command_t cmds[], int markdown)
{
void dumpCommandsRecursive(const command_t cmds[], int markdown) {
if (cmds[0].Name == NULL) return;
int i = 0;

Some files were not shown because too many files have changed in this diff Show more