$(SRC_CRAPTO1) \
$(SRC_CRC) \
legic_prng.c \
- iclass.c
+ iclass.c \
+ BigBuf.c \
+
# stdint.h provided locally until GCC 4.5 becomes C99 compliant
APP_CFLAGS += -I.
MifareUC_Auth2(c->arg[0],c->d.asBytes);
break;
case CMD_MIFAREU_READCARD:
- MifareUReadCard(c->arg[0],c->arg[1],c->d.asBytes);
+ MifareUReadCard(c->arg[0], c->arg[1], c->d.asBytes);
- break;
+ break;
case CMD_MIFAREUC_READCARD:
- MifareUReadCard(c->arg[0],c->arg[1],c->d.asBytes);
- break;
+ MifareUReadCard(c->arg[0], c->arg[1], c->d.asBytes);
+ break;
case CMD_MIFARE_READSC:
MifareReadSector(c->arg[0], c->arg[1], c->arg[2], c->d.asBytes);
break;
#include <stdint.h>
#include <stddef.h>
-#include "common.h"
-#include "hitag2.h"
-#include "mifare.h"
+#include <stdlib.h>
+#include <sys/types.h>
+#include <string.h>
+#include <strings.h>
-
- #include "../include/common.h"
- #include "../include/hitag2.h"
- #include "../include/mifare.h"
-
- //#include <openssl/des.h>
- //#include <openssl/aes.h>
- //#include "des.h"
- //#include "aes.h"
- #include "../common/desfire.h"
#include "../common/crc32.h"
-
- // The large multi-purpose buffer, typically used to hold A/D samples,
- // maybe processed in some way.
- #define BIGBUF_SIZE 40000
- uint32_t BigBuf[BIGBUF_SIZE / sizeof(uint32_t)];
- #define TRACE_OFFSET 0
- #define TRACE_SIZE 3000
- #define RECV_CMD_OFFSET (TRACE_OFFSET + TRACE_SIZE)
- #define MAX_FRAME_SIZE 256
- #define MAX_PARITY_SIZE ((MAX_FRAME_SIZE + 1)/ 8)
- #define RECV_CMD_PAR_OFFSET (RECV_CMD_OFFSET + MAX_FRAME_SIZE)
- #define RECV_RESP_OFFSET (RECV_CMD_PAR_OFFSET + MAX_PARITY_SIZE)
- #define RECV_RESP_PAR_OFFSET (RECV_RESP_OFFSET + MAX_FRAME_SIZE)
- #define CARD_MEMORY_OFFSET (RECV_RESP_PAR_OFFSET + MAX_PARITY_SIZE)
- #define CARD_MEMORY_SIZE 4096
- #define DMA_BUFFER_OFFSET CARD_MEMORY_OFFSET
- #define DMA_BUFFER_SIZE CARD_MEMORY_SIZE
- #define FREE_BUFFER_OFFSET (CARD_MEMORY_OFFSET + CARD_MEMORY_SIZE)
- #define FREE_BUFFER_SIZE (BIGBUF_SIZE - FREE_BUFFER_OFFSET - 1)
+ #include "BigBuf.h"
extern const uint8_t OddByteParity[256];
- extern uint8_t *trace; // = (uint8_t *) BigBuf;
- extern int traceLen; // = 0;
extern int rsamples; // = 0;
extern int tracing; // = TRUE;
extern uint8_t trigger;
void ListenReaderField(int limit);
void AcquireRawAdcSamples125k(int at134khz);
void SnoopLFRawAdcSamples(int divisor, int trigger_threshold);
-void DoAcquisition125k(int trigger_threshold);
+void DoAcquisition125k_internal(int trigger_threshold, bool silent);
+void DoAcquisition125k_threshold(int trigger_threshold);
+void DoAcquisition125k();
+
extern int ToSendMax;
extern uint8_t ToSend[];
- extern uint32_t BigBuf[];
/// fpga.h
void FpgaSendCommand(uint16_t cmd, uint16_t v);
// power up the field
iso14443a_setup(FPGA_HF_ISO14443A_READER_MOD);
-
+
+ iso14a_set_timeout(10500);
+
+ iso14a_set_timeout(10500);
+
// select the card
return_code = iso14443a_select_card(uid, &card_select_info, NULL);
if (return_code != 1) {
// The command (reader -> tag) that we're receiving.
// The length of a received command will in most cases be no more than 18 bytes.
// So 32 should be enough!
- uint8_t *readerToTagCmd = (((uint8_t *)BigBuf) + RECV_CMD_OFFSET);
+ #define ICLASS_BUFFER_SIZE 32
+ uint8_t readerToTagCmd[ICLASS_BUFFER_SIZE];
// The response (tag -> reader) that we're receiving.
- uint8_t *tagToReaderResponse = (((uint8_t *)BigBuf) + RECV_RESP_OFFSET);
-
+ uint8_t tagToReaderResponse[ICLASS_BUFFER_SIZE];
+
FpgaDownloadAndGo(FPGA_BITSTREAM_HF);
- // reset traceLen to 0
+ // free all BigBuf memory
+ BigBuf_free();
+ // The DMA buffer, used to stream samples from the FPGA
+ uint8_t *dmaBuf = BigBuf_malloc(DMA_BUFFER_SIZE);
+
+ // reset traceLen to 0
iso14a_set_tracing(TRUE);
iso14a_clear_trace();
iso14a_set_trigger(FALSE);
- // The DMA buffer, used to stream samples from the FPGA
- int8_t *dmaBuf = ((int8_t *)BigBuf) + DMA_BUFFER_OFFSET;
- int lastRxCounter;
+ int lastRxCounter;
- int8_t *upTo;
+ uint8_t *upTo;
int smpl;
int maxBehindBy = 0;
if(div > 3) {
smpl = decbyte;
if(ManchesterDecoding(smpl & 0x0F)) {
- rsamples = samples - Demod.samples;
+ time_stop = (GetCountSspClk()-time_0) << 4;
+
+ rsamples = samples - Demod.samples;
LED_B_ON();
- if(tracing) {
+ if(tracing) {
uint8_t parity[MAX_PARITY_SIZE];
GetParity(Demod.output, Demod.len, parity);
- LogTrace(Demod.output, Demod.len, (GetCountSspClk()-time_0) << 4, (GetCountSspClk()-time_0) << 4, parity, FALSE);
+ LogTrace(Demod.output, Demod.len, time_start, time_stop, parity, FALSE);
}
-
// And ready to receive another response.
memset(&Demod, 0, sizeof(Demod));
Demod.output = tagToReaderResponse;
ToSendReset();
// Send SOF
- ToSend[++ToSendMax] = 0x00;
- ToSend[++ToSendMax] = 0x00;
- ToSend[++ToSendMax] = 0x00;
- ToSend[++ToSendMax] = 0xff;//Proxtoair duration starts here
- ToSend[++ToSendMax] = 0xff;
- ToSend[++ToSendMax] = 0xff;
- ToSend[++ToSendMax] = 0x00;
- ToSend[++ToSendMax] = 0xff;
+ ToSend[++ToSendMax] = 0x1D;
for(i = 0; i < len; i++) {
- int j;
uint8_t b = cmd[i];
-
- // Data bits
- for(j = 0; j < 8; j++) {
- if(b & 1) {
- ToSend[++ToSendMax] = 0x00;
- ToSend[++ToSendMax] = 0xff;
- } else {
- ToSend[++ToSendMax] = 0xff;
- ToSend[++ToSendMax] = 0x00;
+ ToSend[++ToSendMax] = encode4Bits(b & 0xF); //Least significant half
+ ToSend[++ToSendMax] = encode4Bits((b >>4) & 0xF);//Most significant half
- }
+ }
- b >>= 1;
- }
- }
// Send EOF
- ToSend[++ToSendMax] = 0xff;
- ToSend[++ToSendMax] = 0x00;
- ToSend[++ToSendMax] = 0xff;
- ToSend[++ToSendMax] = 0xff;
- ToSend[++ToSendMax] = 0xff;
- ToSend[++ToSendMax] = 0x00;
- ToSend[++ToSendMax] = 0x00;
- ToSend[++ToSendMax] = 0x00;
-
+ ToSend[++ToSendMax] = 0xB8;
//lastProxToAirDuration = 8*ToSendMax - 3*8 - 3*8;//Not counting zeroes in the beginning or end
-
// Convert from last byte pos to length
ToSendMax++;
}
if (wait)
{
if(*wait < 10) *wait = 10;
-
+
- for(c = 0; c < *wait;) {
- if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY)) {
- AT91C_BASE_SSC->SSC_THR = 0x00; // For exact timing!
- c++;
- }
- if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
- volatile uint32_t r = AT91C_BASE_SSC->SSC_RHR;
- (void)r;
- }
- WDT_HIT();
- }
+ for(c = 0; c < *wait;) {
+ if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_TXRDY)) {
+ AT91C_BASE_SSC->SSC_THR = 0x00; // For exact timing!
+ c++;
+ }
+ if(AT91C_BASE_SSC->SSC_SR & (AT91C_SSC_RXRDY)) {
+ volatile uint32_t r = AT91C_BASE_SSC->SSC_RHR;
+ (void)r;
+ }
+ WDT_HIT();
+ }
}
void ReaderTransmitIClass(uint8_t* frame, int len)
{
- int wait = 0;
- int samples = 0;
+ int wait = 0;
+ int samples = 0;
- // This is tied to other size changes
- CodeIClassCommand(frame,len);
+ // This is tied to other size changes
+ CodeIClassCommand(frame,len);
- // Select the card
- TransmitIClassCommand(ToSend, ToSendMax, &samples, &wait);
- if(trigger)
- LED_A_ON();
+ // Select the card
+ TransmitIClassCommand(ToSend, ToSendMax, &samples, &wait);
+ if(trigger)
+ LED_A_ON();
- // Store reader command in buffer
+ // Store reader command in buffer
- if (tracing) {
+ if (tracing) {
uint8_t par[MAX_PARITY_SIZE];
GetParity(frame, len, par);
LogTrace(frame, len, rsamples, rsamples, par, TRUE);
cmd_send(CMD_ACK, isOK, 0, 0, dataout, sizeof(dataout));\r
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);\r
LEDsoff();\r
--}
++}\r
}\r
\r
// send commands\r
- 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)\r
+ 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)\r
{\r
-- return mifare_sendcmd_shortex(pcs, crypted, cmd, data, answer, answer_parity, timing);
--}
--
--int mifare_sendcmd_short_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[8];
- dcmd[0] = cmd;\r
- dcmd[0] = cmd;
- dcmd[1] = data[0];
- dcmd[2] = data[1];
- dcmd[3] = data[2];
- dcmd[4] = data[3];
- dcmd[5] = data[4];
- AppendCrc14443a(dcmd, 6);
- ReaderTransmit(dcmd, sizeof(dcmd), NULL);
- int len = ReaderReceive(answer, answer_parity);
- if(!len) {
- if (MF_DBGLEVEL >= 1) Dbprintf("Authentication failed. Card timeout.");
- return 2;
++ return mifare_sendcmd_shortex(pcs, crypted, cmd, data, answer, answer_parity, timing);\r
++}\r
++\r
++int mifare_sendcmd_short_special(struct Crypto1State *pcs, uint8_t crypted, uint8_t cmd, uint8_t* data, uint8_t* answer, uint8_t *answer_parity, uint32_t *timing)\r
++{\r
++ uint8_t dcmd[8];\r
++ dcmd[0] = cmd;\r
+ dcmd[1] = data[0];\r
- dcmd[2] = data[1];
++ dcmd[2] = data[1];\r
+ dcmd[3] = data[2];\r
+ dcmd[4] = data[3];\r
+ dcmd[5] = data[4];\r
- AppendCrc14443a(dcmd, 6);
- ReaderTransmit(dcmd, sizeof(dcmd), NULL);
- int len = ReaderReceive(answer, answer_parity);
- if(!len) {
- if (MF_DBGLEVEL >= 1) Dbprintf("Authentication failed. Card timeout.");
- return 2;
++ AppendCrc14443a(dcmd, 6);\r
++ ReaderTransmit(dcmd, sizeof(dcmd), NULL);\r
++ int len = ReaderReceive(answer, answer_parity);\r
++ if(!len) {\r
++ if (MF_DBGLEVEL >= 1) Dbprintf("Authentication failed. Card timeout.");\r
++ return 2;\r
}\r
return len;\r
}\r
if(len==1) {\r
if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("NAK - Authentication failed.");\r
return 1;\r
-- }
-- return len;
--}
--
--int mifare_sendcmd_shortex(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[4], ecmd[4];
++ }\r
++ return len;\r
++}\r
++\r
++int mifare_sendcmd_shortex(struct Crypto1State *pcs, uint8_t crypted, uint8_t cmd, uint8_t data, uint8_t *answer, uint8_t *answer_parity, uint32_t *timing)\r
++{\r
++ uint8_t dcmd[4], ecmd[4];\r
uint16_t pos, res;\r
uint8_t par[1]; // 1 Byte parity is enough here\r
dcmd[0] = cmd;\r
}\r
\r
memcpy(blockData, receivedAnswer, 16);\r
-- return 0;
-}
-
++ return 0;\r
+}\r
+\r
// mifare ultralight commands\r
int mifare_ultra_auth1(uint32_t uid, uint8_t *blockData){\r
\r
}\r
memcpy(blockData, receivedAnswer, 11);\r
return 0;\r
- }
-
- int mifare_ultra_readblock(uint32_t uid, uint8_t blockNo, uint8_t *blockData)
- {
- uint16_t len;
- uint8_t bt[2];
- uint8_t *receivedAnswer = get_bigbufptr_recvrespbuf();
- uint8_t *receivedAnswerPar = receivedAnswer + MAX_FRAME_SIZE;\r
- \r
-
- // command MIFARE_CLASSIC_READBLOCK
- len = mifare_sendcmd_short(NULL, 1, 0x30, blockNo, receivedAnswer, receivedAnswerPar, NULL);
- if (len == 1) {
+ }\r
+ \r
-int mifare_ultra_readblock(uint32_t uid, uint8_t blockNo, uint8_t *blockData)
-{
- uint16_t len;
- uint8_t bt[2];
++int mifare_ultra_readblock(uint32_t uid, uint8_t blockNo, uint8_t *blockData)\r
++{\r
++ uint16_t len;\r
++ uint8_t bt[2];\r
+ uint8_t receivedAnswer[MAX_MIFARE_FRAME_SIZE];\r
+ uint8_t receivedAnswerPar[MAX_MIFARE_PARITY_SIZE];\r
-
+ \r
- // command MIFARE_CLASSIC_READBLOCK
- len = mifare_sendcmd_short(NULL, 1, 0x30, blockNo, receivedAnswer, receivedAnswerPar, NULL);
- if (len == 1) {
++ \r
++ // command MIFARE_CLASSIC_READBLOCK\r
++ len = mifare_sendcmd_short(NULL, 1, 0x30, blockNo, receivedAnswer, receivedAnswerPar, NULL);\r
++ if (len == 1) {\r
if (MF_DBGLEVEL >= MF_DBG_ERROR)\r
-- Dbprintf("Cmd Error: %02x", receivedAnswer[0]);
-- return 1;
-- }
-- if (len != 18) {
++ Dbprintf("Cmd Error: %02x", receivedAnswer[0]);\r
++ return 1;\r
++ }\r
++ if (len != 18) {\r
if (MF_DBGLEVEL >= MF_DBG_ERROR)\r
-- Dbprintf("Cmd Error: card timeout. len: %x", len);
-- return 2;
-- }
--
-- memcpy(bt, receivedAnswer + 16, 2);
-- AppendCrc14443a(receivedAnswer, 16);
-- if (bt[0] != receivedAnswer[16] || bt[1] != receivedAnswer[17]) {
++ Dbprintf("Cmd Error: card timeout. len: %x", len);\r
++ return 2;\r
++ }\r
++ \r
++ memcpy(bt, receivedAnswer + 16, 2);\r
++ AppendCrc14443a(receivedAnswer, 16);\r
++ if (bt[0] != receivedAnswer[16] || bt[1] != receivedAnswer[17]) {\r
if (MF_DBGLEVEL >= MF_DBG_ERROR)\r
-- Dbprintf("Cmd CRC response error.");
-- return 3;
-- }
--
-- memcpy(blockData, receivedAnswer, 14);
-- return 0;
--}
--
--
--int mifare_classic_writeblock(struct Crypto1State *pcs, uint32_t uid, uint8_t blockNo, uint8_t *blockData)
--{
-- // variables
++ Dbprintf("Cmd CRC response error.");\r
++ return 3;\r
++ }\r
++ \r
++ memcpy(blockData, receivedAnswer, 14);\r
++ return 0;\r
++}\r
++\r
++\r
++int mifare_classic_writeblock(struct Crypto1State *pcs, uint32_t uid, uint8_t blockNo, uint8_t *blockData) \r
++{\r
++ // variables\r
uint16_t len, i; \r
uint32_t pos;\r
uint8_t par[3] = {0}; // enough for 18 Bytes to send\r
return 2;\r
}\r
\r
-- return 0;
--}
--
--int mifare_ultra_writeblock(uint32_t uid, uint8_t blockNo, uint8_t *blockData)
--{
- uint16_t len;
- uint8_t par[3] = {0}; // enough for 18 parity bits
- uint16_t len;
- uint8_t par[3] = {0}; // enough for 18 parity bits
-- uint8_t d_block[18] = {0x00};
- uint8_t *receivedAnswer = get_bigbufptr_recvrespbuf();\r
- uint8_t *receivedAnswerPar = receivedAnswer + MAX_FRAME_SIZE;
-
- // command MIFARE_CLASSIC_WRITEBLOCK
- len = mifare_sendcmd_short(NULL, true, 0xA0, blockNo, receivedAnswer, receivedAnswerPar, NULL);
-
- if ((len != 1) || (receivedAnswer[0] != 0x0A)) { // 0x0a - ACK
++ return 0;\r
++}\r
++\r
++int mifare_ultra_writeblock(uint32_t uid, uint8_t blockNo, uint8_t *blockData) \r
++{\r
++ uint16_t len; \r
++ uint8_t par[3] = {0}; // enough for 18 parity bits\r
++ uint8_t d_block[18] = {0x00};\r
+ uint8_t receivedAnswer[MAX_MIFARE_FRAME_SIZE];\r
+ uint8_t receivedAnswerPar[MAX_MIFARE_PARITY_SIZE];\r
-
- // command MIFARE_CLASSIC_WRITEBLOCK
- len = mifare_sendcmd_short(NULL, true, 0xA0, blockNo, receivedAnswer, receivedAnswerPar, NULL);
-
- if ((len != 1) || (receivedAnswer[0] != 0x0A)) { // 0x0a - ACK
++ \r
++ // command MIFARE_CLASSIC_WRITEBLOCK\r
++ len = mifare_sendcmd_short(NULL, true, 0xA0, blockNo, receivedAnswer, receivedAnswerPar, NULL);\r
++\r
++ if ((len != 1) || (receivedAnswer[0] != 0x0A)) { // 0x0a - ACK\r
if (MF_DBGLEVEL >= MF_DBG_ERROR)\r
-- Dbprintf("Cmd Addr Error: %02x", receivedAnswer[0]);
- return 1;
- }
- return 1;
- }
--
-- memcpy(d_block, blockData, 16);
-- AppendCrc14443a(d_block, 16);
--
-- ReaderTransmitPar(d_block, sizeof(d_block), par, NULL);
- \r
-
-- len = ReaderReceive(receivedAnswer, receivedAnswerPar);
--
-- if ((len != 1) || (receivedAnswer[0] != 0x0A)) { // 0x0a - ACK
++ Dbprintf("Cmd Addr Error: %02x", receivedAnswer[0]); \r
++ return 1;\r
++ }\r
++\r
++ memcpy(d_block, blockData, 16);\r
++ AppendCrc14443a(d_block, 16);\r
++\r
++ ReaderTransmitPar(d_block, sizeof(d_block), par, NULL);\r
++\r
++ len = ReaderReceive(receivedAnswer, receivedAnswerPar); \r
++\r
++ if ((len != 1) || (receivedAnswer[0] != 0x0A)) { // 0x0a - ACK\r
if (MF_DBGLEVEL >= MF_DBG_ERROR)\r
-- Dbprintf("Cmd Data Error: %02x %d", receivedAnswer[0],len);
- return 2;
- }
- return 2;
- }
-- return 0;
--}
--
--int mifare_ultra_special_writeblock(uint32_t uid, uint8_t blockNo, uint8_t *blockData)
--{
-- uint16_t len;
-- uint8_t d_block[8] = {0x00};
- uint8_t *receivedAnswer = get_bigbufptr_recvrespbuf();\r
- uint8_t *receivedAnswerPar = receivedAnswer + MAX_FRAME_SIZE;
-
- // command MIFARE_CLASSIC_WRITEBLOCK
- d_block[0]= blockNo;
- memcpy(d_block+1,blockData,4);
- AppendCrc14443a(d_block, 6);
-
- len = mifare_sendcmd_short_special(NULL, 1, 0xA2, d_block, receivedAnswer, receivedAnswerPar, NULL);
-
- if (receivedAnswer[0] != 0x0A) { // 0x0a - ACK
++ Dbprintf("Cmd Data Error: %02x %d", receivedAnswer[0],len);\r
++ return 2;\r
++ } \r
++ return 0;\r
++} \r
++\r
++int mifare_ultra_special_writeblock(uint32_t uid, uint8_t blockNo, uint8_t *blockData)\r
++{\r
++ uint16_t len;\r
++ uint8_t d_block[8] = {0x00};\r
+ uint8_t receivedAnswer[MAX_MIFARE_FRAME_SIZE];\r
+ uint8_t receivedAnswerPar[MAX_MIFARE_PARITY_SIZE];\r
-
- // command MIFARE_CLASSIC_WRITEBLOCK
- d_block[0]= blockNo;
- memcpy(d_block+1,blockData,4);
- AppendCrc14443a(d_block, 6);
-
- len = mifare_sendcmd_short_special(NULL, 1, 0xA2, d_block, receivedAnswer, receivedAnswerPar, NULL);
-
- if (receivedAnswer[0] != 0x0A) { // 0x0a - ACK
++\r
++ // command MIFARE_CLASSIC_WRITEBLOCK\r
++ d_block[0]= blockNo;\r
++ memcpy(d_block+1,blockData,4);\r
++ AppendCrc14443a(d_block, 6);\r
++\r
++ len = mifare_sendcmd_short_special(NULL, 1, 0xA2, d_block, receivedAnswer, receivedAnswerPar, NULL);\r
++\r
++ if (receivedAnswer[0] != 0x0A) { // 0x0a - ACK\r
if (MF_DBGLEVEL >= MF_DBG_ERROR)\r
-- Dbprintf("Cmd Send Error: %02x %d", receivedAnswer[0],len);
- return 1;
- }
- return 0;
- return 1;
- }
-\r return 0;
--}
--
--int mifare_classic_halt(struct Crypto1State *pcs, uint32_t uid)
--{
++ Dbprintf("Cmd Send Error: %02x %d", receivedAnswer[0],len);\r
++ return 1;\r
++ }\r
++ return 0;\r
++}\r
++\r
++int mifare_classic_halt(struct Crypto1State *pcs, uint32_t uid) \r
++{\r
uint16_t len; \r
- uint8_t* receivedAnswer = get_bigbufptr_recvrespbuf();\r
- uint8_t *receivedAnswerPar = receivedAnswer + MAX_FRAME_SIZE;\r
+ uint8_t receivedAnswer[MAX_MIFARE_FRAME_SIZE];\r
+ uint8_t receivedAnswerPar[MAX_MIFARE_PARITY_SIZE];\r
\r
len = mifare_sendcmd_short(pcs, pcs == NULL ? false:true, 0x50, 0x00, receivedAnswer, receivedAnswerPar, NULL);\r
if (len != 0) {\r
return 1;\r
}\r
\r
-- return 0;
--}
--
--int mifare_ultra_halt(uint32_t uid)
--{
- uint16_t len; \r
- uint8_t *receivedAnswer = get_bigbufptr_recvrespbuf();\r
- uint8_t *receivedAnswerPar = receivedAnswer + MAX_FRAME_SIZE;\r
-
- len = mifare_sendcmd_short(NULL, true, 0x50, 0x00, receivedAnswer, receivedAnswerPar, NULL);
- if (len != 0) {
- uint16_t len;
++ return 0;\r
++}\r
++\r
++int mifare_ultra_halt(uint32_t uid)\r
++{\r
++ uint16_t len;\r
+ uint8_t receivedAnswer[MAX_MIFARE_FRAME_SIZE];\r
+ uint8_t receivedAnswerPar[MAX_MIFARE_PARITY_SIZE];\r
-
- len = mifare_sendcmd_short(NULL, true, 0x50, 0x00, receivedAnswer, receivedAnswerPar, NULL);
- if (len != 0) {
++ \r
++ len = mifare_sendcmd_short(NULL, true, 0x50, 0x00, receivedAnswer, receivedAnswerPar, NULL);\r
++ if (len != 0) {\r
if (MF_DBGLEVEL >= MF_DBG_ERROR)\r
-- Dbprintf("halt error. response len: %x", len);
-- return 1;
- }
- return 0;
-}
-
++ Dbprintf("halt error. response len: %x", len);\r
++ return 1;\r
+ }\r
- return 0;
- }
-
++ return 0;\r
++}\r
++\r
\r
// Mifare Memory Structure: up to 32 Sectors with 4 blocks each (1k and 2k cards),\r
// plus evtl. 8 sectors with 16 blocks each (4k cards)\r
}\r
\r
\r
--// work with emulator memory
--void emlSetMem(uint8_t *data, int blockNum, int blocksCount) {
- uint8_t* emCARD = get_bigbufptr_emlcardmem();\r
- uint8_t* emCARD = BigBuf_get_EM_addr();
++// work with emulator memory\r
++void emlSetMem(uint8_t *data, int blockNum, int blocksCount) {\r
++ uint8_t* emCARD = BigBuf_get_EM_addr();\r
memcpy(emCARD + blockNum * 16, data, blocksCount * 16);\r
}\r
\r
return 0;\r
}\r
return 1;\r
--}
++}\r
local data = self.data
local cmd = self.cmd
local arg1, arg2, arg3 = self.arg1, self.arg2, self.arg3
-
-
return bin.pack("LLLLH",cmd, arg1, arg2, arg3,data);
end
return _commands
return {
convert_bin_to_html = convert_bin_to_html,
convert_eml_to_html = convert_eml_to_html,
- convert_eml_to_bin = convert_eml_to_bin,
+ convert_eml_to_bin = convert_eml_to_bin,
+ SaveAsBinary = save_BIN,
+ SaveAsText = save_TEXT,
+ SaveAsBinary = save_BIN,
+ SaveAsText = save_TEXT,
}
'eff603e1efe9',
'644672bd4afe',
+ 'b5ff67cba951',
+ }
+
++ --[[
++ Kiev metro cards
++ --]]
++ '8fe644038790',
++ 'f14ee7cae863',
++ '632193be1c3c',
++ '569369c5a0e5',
++ '9de89e070277',
++ 'eff603e1efe9',
++ '644672bd4afe',
++
+ 'b5ff67cba951',
+}
+
---
-- The keys above have just been pasted in, for completeness sake. They contain duplicates.
-- We need to weed the duplicates out before we expose the list to someone who actually wants to use them
uint16_t i, len;\r
uint32_t uid;\r
UsbCommand resp;\r
- \r
-\r
StateList_t statelists[2];\r
struct Crypto1State *p1, *p2, *p3, *p4;\r
\r
memcpy(c.d.asBytes, data, 16); \r
SendCommand(&c);\r
\r
- UsbCommand resp;\r
+ UsbCommand resp;\r
if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) {\r
isOK = resp.arg[0] & 0xff;\r
- if (uid != NULL) memcpy(uid, resp.d.asBytes, 4);\r
- if (!isOK) return 2;\r
+ if (uid != NULL) \r
+ memcpy(uid, resp.d.asBytes, 4);\r
+ if (!isOK) \r
+ return 2;\r
} else {\r
PrintAndLog("Command execute timeout");\r
return 1;\r
FillFileNameByUID(traceFileName, tuid, ".eml", 7);\r
\r
f = fopen(traceFileName, "r");\r
- if (!f) return 1;\r
+ if (!f) {\r
+ fclose(f);\r
+ return 1;\r
+ }\r
\r
blockNum = 0;\r
+ \r
while(!feof(f)){\r
+ \r
memset(buf, 0, sizeof(buf));\r
if (fgets(buf, sizeof(buf), f) == NULL) {\r
- PrintAndLog("File reading error.");\r
+ PrintAndLog("File reading error.");\r
fclose(f);\r
return 2;\r
- }\r
+ }\r
\r
if (strlen(buf) < 32){\r
if (feof(f)) break;\r
statelist = malloc((sizeof *statelist) << 21); //how large should be? \r
if(!statelist || !odd || !even)\r
{\r
- free(statelist);\r
- free(odd);\r
- free(even);\r
+ free(statelist);\r
+ free(odd);\r
+ free(even);\r
- return 0;\r
+ return 0;\r
}\r
\r
s = statelist;\r
volatile static bool txcmd_pending = false;
void SendCommand(UsbCommand *c) {
- #if 0
+ #if 0
- printf("Sending %d bytes\n", sizeof(UsbCommand));
+ printf("Sending %d bytes\n", sizeof(UsbCommand));
- #endif
+ #endif
if (offline) {
PrintAndLog("Sending bytes to proxmark failed - offline");
byte_t* prx = rx;
static void *uart_receiver(void *targ) {
- struct receiver_arg *arg = (struct receiver_arg*)targ;
- size_t rxlen;
- size_t cmd_count;
+ struct receiver_arg *arg = (struct receiver_arg*)targ;
+ size_t rxlen;
+ size_t cmd_count;
-
+
- while (arg->run) {
- rxlen = sizeof(UsbCommand);
+ while (arg->run) {
+ rxlen = sizeof(UsbCommand);
- if (uart_receive(sp,prx,&rxlen)) {
+ if (uart_receive(sp, prx, &rxlen)) {
- prx += rxlen;
- if (((prx-rx) % sizeof(UsbCommand)) != 0) {
- continue;
- }
- cmd_count = (prx-rx) / sizeof(UsbCommand);
+ prx += rxlen;
+ if (((prx-rx) % sizeof(UsbCommand)) != 0) {
+ continue;
+ }
+ cmd_count = (prx-rx) / sizeof(UsbCommand);
- for (size_t i=0; i<cmd_count; i++) {
+ for (size_t i = 0; i < cmd_count; i++) {
- UsbCommandReceived((UsbCommand*)(rx+(i*sizeof(UsbCommand))));
- }
- }
- prx = rx;
+ UsbCommandReceived((UsbCommand*)(rx+(i*sizeof(UsbCommand))));
+ }
+ }
+ prx = rx;
-
+
- if(txcmd_pending) {
+ if(txcmd_pending) {
- if (!uart_send(sp,(byte_t*)&txcmd,sizeof(UsbCommand))) {
+ if (!uart_send(sp, (byte_t*) &txcmd, sizeof(UsbCommand))) {
- PrintAndLog("Sending bytes to proxmark failed");
- }
- txcmd_pending = false;
- }
- }
+ PrintAndLog("Sending bytes to proxmark failed");
+ }
+ txcmd_pending = false;
+ }
+ }
-
+
- pthread_exit(NULL);
- return NULL;
+ pthread_exit(NULL);
+ return NULL;
}
static void *main_loop(void *targ) {
- struct main_loop_arg *arg = (struct main_loop_arg*)targ;
- struct receiver_arg rarg;
- char *cmd = NULL;
- pthread_t reader_thread;
+ struct main_loop_arg *arg = (struct main_loop_arg*)targ;
+ struct receiver_arg rarg;
+ char *cmd = NULL;
+ pthread_t reader_thread;
- if (arg->usb_present == 1) {
+ if (arg->usb_present == 1) {
- rarg.run=1;
+ rarg.run = 1;
- pthread_create(&reader_thread, NULL, &uart_receiver, &rarg);
- }
+ pthread_create(&reader_thread, NULL, &uart_receiver, &rarg);
+ }
-
+
- FILE *script_file = NULL;
+ FILE *script_file = NULL;
- char script_cmd_buf[256]; // iceman, needs lua script the same file_path_buffer as the rest
-
+ char script_cmd_buf[256]; // iceman, needs lua script the same file_path_buffer as the rest
+
if (arg->script_cmds_file) {
- script_file = fopen(arg->script_cmds_file, "r");
+ script_file = fopen(arg->script_cmds_file, "r");
if (script_file) {
- printf("using 'scripting' commands file %s\n", arg->script_cmds_file);
- }
- }
+ printf("using 'scripting' commands file %s\n", arg->script_cmds_file);
+ }
+ }
read_history(".history");
while(1) {
- // If there is a script file
- if (script_file)
- {
+ // If there is a script file
+ if (script_file)
+ {
if (!fgets(script_cmd_buf, sizeof(script_cmd_buf), script_file)) {
- fclose(script_file);
- script_file = NULL;
+ fclose(script_file);
+ script_file = NULL;
} else {
- char *nl;
- nl = strrchr(script_cmd_buf, '\r');
- if (nl) *nl = '\0';
+ char *nl;
+ nl = strrchr(script_cmd_buf, '\r');
+ if (nl) *nl = '\0';
- nl = strrchr(script_cmd_buf, '\n');
- if (nl) *nl = '\0';
+ nl = strrchr(script_cmd_buf, '\n');
+ if (nl) *nl = '\0';
-
+
if ((cmd = (char*) malloc(strlen(script_cmd_buf) + 1)) != NULL) {
- memset(cmd, 0, strlen(script_cmd_buf));
- strcpy(cmd, script_cmd_buf);
- printf("%s\n", cmd);
- }
- }
- }
+ memset(cmd, 0, strlen(script_cmd_buf));
+ strcpy(cmd, script_cmd_buf);
+ printf("%s\n", cmd);
+ }
+ }
+ }
if (!script_file) {
- cmd = readline(PROXPROMPT);
+ cmd = readline(PROXPROMPT);
}
if (cmd) {
write_history(".history");
- if (arg->usb_present == 1) {
- rarg.run = 0;
- pthread_join(reader_thread, NULL);
- }
+ if (arg->usb_present == 1) {
+ rarg.run = 0;
+ pthread_join(reader_thread, NULL);
+ }
-
+
if (script_file) {
- fclose(script_file);
- script_file = NULL;
- }
+ fclose(script_file);
+ script_file = NULL;
+ }
-
+
- ExitGraphics();
- pthread_exit(NULL);
- return NULL;
+ ExitGraphics();
+ pthread_exit(NULL);
+ return NULL;
}
static void dumpAllHelp(int markdown)
CFLAGS = -c $(INCLUDE) -Wall -Werror -pedantic -std=c99 $(APP_CFLAGS) -Os
LDFLAGS = -nostartfiles -nodefaultlibs -Wl,-gc-sections -n
+ LIBS = -lgcc
+
+LIBS = -lgcc
+
THUMBOBJ = $(patsubst %.c,$(OBJDIR)/%.o,$(THUMBSRC))
ARMOBJ = $(ARMSRC:%.c=$(OBJDIR)/%.o)
ASMOBJ = $(patsubst %.s,$(OBJDIR)/%.o,$(ASMSRC))