Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions armsrc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ THUMBSRC = start.c \
printf.c \
util.c \
string.c \
usb_cdc.c \
cmd.c
usb_cdc.c

# Compile these in thumb mode optimized for speed (still smaller than ARM mode)
THUMBOPTSRC = $(SRC_ISO15693)
Expand Down
30 changes: 15 additions & 15 deletions armsrc/appmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include <stdarg.h>

#include "usb_cdc.h"
#include "cmd.h"
#include "proxmark3.h"
#include "apps.h"
#include "fpga.h"
Expand Down Expand Up @@ -312,6 +311,7 @@ void set_hw_capabilities(void) {


void SendVersion(void) {
LED_A_ON();
set_hw_capabilities();

char temp[USB_CMD_DATA_SIZE]; /* Limited data payload in USB packets */
Expand Down Expand Up @@ -347,7 +347,8 @@ void SendVersion(void) {
// Send Chip ID and used flash memory
uint32_t text_and_rodata_section_size = (uint32_t)&__data_src_start__ - (uint32_t)&_flash_start;
uint32_t compressed_data_section_size = common_area.arg1;
cmd_send(CMD_ACK, *(AT91C_DBGU_CIDR), text_and_rodata_section_size + compressed_data_section_size, hw_capabilities, VersionString, strlen(VersionString));
cmd_send(CMD_ACK, *(AT91C_DBGU_CIDR), text_and_rodata_section_size + compressed_data_section_size, hw_capabilities, VersionString, strlen(VersionString) + 1);
LED_A_OFF();
}

// measure the USB Speed by sending SpeedTestBufferSize bytes to client and measuring the elapsed time.
Expand All @@ -363,13 +364,11 @@ void printUSBSpeed(void) {
uint32_t start_time = end_time = GetTickCount();
uint32_t bytes_transferred = 0;

LED_B_ON();
while(end_time < start_time + USB_SPEED_TEST_MIN_TIME) {
while (end_time < start_time + USB_SPEED_TEST_MIN_TIME) {
cmd_send(CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K, 0, USB_CMD_DATA_SIZE, 0, test_data, USB_CMD_DATA_SIZE);
end_time = GetTickCount();
bytes_transferred += USB_CMD_DATA_SIZE;
}
LED_B_OFF();

Dbprintf(" Time elapsed: %dms", end_time - start_time);
Dbprintf(" Bytes transferred: %d", bytes_transferred);
Expand All @@ -382,6 +381,7 @@ void printUSBSpeed(void) {
* Prints runtime information about the PM3.
**/
void SendStatus(void) {
LED_A_ON();
BigBuf_print_status();
Fpga_print_status();
#ifdef WITH_SMARTCARD
Expand All @@ -394,7 +394,8 @@ void SendStatus(void) {
Dbprintf(" ToSendMax..........%d", ToSendMax);
Dbprintf(" ToSendBit..........%d", ToSendBit);

cmd_send(CMD_ACK,1,0,0,0,0);
cmd_send(CMD_ACK, 1, 0, 0, 0, 0);
LED_A_OFF();
}

#if defined(WITH_ISO14443a_StandAlone) || defined(WITH_LF_StandAlone)
Expand Down Expand Up @@ -936,9 +937,7 @@ void ListenReaderField(int limit) {
}


void UsbPacketReceived(uint8_t *packet, int len) {

UsbCommand *c = (UsbCommand *)packet;
void UsbPacketReceived(UsbCommand *c) {

// 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]);

Expand Down Expand Up @@ -1337,9 +1336,11 @@ void UsbPacketReceived(uint8_t *packet, int len) {
break;

case CMD_FPGA_MAJOR_MODE_OFF: // ## FPGA Control
LED_A_ON();
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
SpinDelay(200);
LED_D_OFF(); // LED D indicates field ON or OFF
LED_A_OFF();
break;

case CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K:
Expand Down Expand Up @@ -1428,7 +1429,7 @@ void UsbPacketReceived(uint8_t *packet, int len) {
case CMD_DEVICE_INFO: {
uint32_t dev_info = DEVICE_INFO_FLAG_OSIMAGE_PRESENT | DEVICE_INFO_FLAG_CURRENT_MODE_OS;
if(common_area.flags.bootrom_present) dev_info |= DEVICE_INFO_FLAG_BOOTROM_PRESENT;
cmd_send(CMD_DEVICE_INFO,dev_info,0,0,0,0);
cmd_send_old(CMD_DEVICE_INFO,dev_info,0,0,0,0);
break;
}
default:
Expand Down Expand Up @@ -1479,13 +1480,12 @@ void __attribute__((noreturn)) AppMain(void) {
LCDInit();
#endif

uint8_t rx[sizeof(UsbCommand)];
size_t rx_len;

UsbCommand rx;

for(;;) {
WDT_HIT();
if (usb_poll() && (rx_len = usb_read(rx, sizeof(rx)))) {
UsbPacketReceived(rx, rx_len);
if (cmd_receive(&rx)) {
UsbPacketReceived(&rx);
} else {
#if defined(WITH_LF_StandAlone) && !defined(WITH_ISO14443a_StandAlone)
if (BUTTON_HELD(1000) > 0)
Expand Down
4 changes: 0 additions & 4 deletions armsrc/apps.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,4 @@ void ReaderMifareDES(uint32_t param, uint32_t param2, uint8_t * datain);
int DesfireAPDU(uint8_t *cmd, size_t cmd_len, uint8_t *dataout);
size_t CreateAPDU( uint8_t *datain, size_t len, uint8_t *dataout);

// cmd.h
bool cmd_receive(UsbCommand* cmd);
bool cmd_send(uint32_t cmd, uint32_t arg0, uint32_t arg1, uint32_t arg2, void* data, size_t len);

#endif
15 changes: 6 additions & 9 deletions armsrc/epa.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "iso14443a.h"
#include "iso14443b.h"
#include "epa.h"
#include "cmd.h"
#include "usb_cdc.h"
#include "fpgaloader.h"
#include "string.h"
#include "util.h"
Expand Down Expand Up @@ -453,20 +453,17 @@ 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
// if an APDU has been passed, just save it
if (c->arg[0] != 0) {
// make sure it's not too big
if(c->arg[2] > apdus_replay[c->arg[0] - 1].len)
{
if(c->arg[2] > apdus_replay[c->arg[0] - 1].len) {
cmd_send(CMD_ACK, 1, 0, 0, NULL, 0);
return;
}
memcpy(apdus_replay[c->arg[0] - 1].data + c->arg[1],
c->d.asBytes,
c->arg[2]);
memcpy(apdus_replay[c->arg[0] - 1].data + c->arg[1], c->d.asBytes, c->arg[2]);
// save/update APDU length
if (c->arg[1] == 0) {
apdu_lengths_replay[c->arg[0] - 1] = c->arg[2];
Expand Down
2 changes: 1 addition & 1 deletion armsrc/hfsnoop.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include "BigBuf.h"
#include "util.h"
#include "apps.h"
#include "usb_cdc.h" // for usb_poll_validate_length
#include "usb_cdc.h"
#include "fpga.h"
#include "fpgaloader.h"

Expand Down
2 changes: 1 addition & 1 deletion armsrc/hitag2.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "hitag2.h"

#include "proxmark3.h"
#include "cmd.h"
#include "usb_cdc.h"
#include "apps.h"
#include "util.h"
#include "hitag.h"
Expand Down
1 change: 1 addition & 0 deletions armsrc/hitagS.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <stdlib.h>
#include "proxmark3.h"
#include "apps.h"
#include "usb_cdc.h"
#include "util.h"
#include "hitag.h"
#include "string.h"
Expand Down
1 change: 1 addition & 0 deletions armsrc/i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "mifareutil.h" // for MF_DBGLEVEL
#include "BigBuf.h"
#include "apps.h"
#include "usb_cdc.h"

#ifdef WITH_SMARTCARD
#include "smartcard.h"
Expand Down
71 changes: 34 additions & 37 deletions armsrc/iclass.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include "string.h"
#include "printf.h"
#include "common.h"
#include "cmd.h"
#include "usb_cdc.h"
#include "iso14443a.h"
#include "iso15693.h"
// Needed for CRC in emulation mode;
Expand All @@ -34,7 +34,6 @@
#include "iso15693tools.h"
#include "protocols.h"
#include "optimized_cipher.h"
#include "usb_cdc.h" // for usb_poll_validate_length
#include "fpgaloader.h"

// iCLASS has a slightly different timing compared to ISO15693. According to the picopass data sheet the tag response is expected 330us after
Expand Down Expand Up @@ -675,14 +674,14 @@ static bool selectIclassTag(uint8_t *card_data, uint32_t *eof_time) {
// Send act_all
ReaderTransmitIClass(act_all, 1, &start_time);
// Card present?
if (GetIso15693AnswerFromTag(resp, sizeof(resp), ICLASS_READER_TIMEOUT_ACTALL, eof_time) < 0) return false;//Fail
if (GetIso15693AnswerFromTag(resp, sizeof(resp), ICLASS_READER_TIMEOUT_ACTALL, eof_time) < 0) return false; //Fail

//Send Identify
start_time = *eof_time + DELAY_ICLASS_VICC_TO_VCD_READER;
ReaderTransmitIClass(identify, 1, &start_time);
//We expect a 10-byte response here, 8 byte anticollision-CSN and 2 byte CRC
uint8_t len = GetIso15693AnswerFromTag(resp, sizeof(resp), ICLASS_READER_TIMEOUT_OTHERS, eof_time);
if (len != 10) return false;//Fail
if (len != 10) return false; //Fail

//Copy the Anti-collision CSN to our select-packet
memcpy(&select[1], resp, 8);
Expand All @@ -691,7 +690,7 @@ static bool selectIclassTag(uint8_t *card_data, uint32_t *eof_time) {
ReaderTransmitIClass(select, sizeof(select), &start_time);
//We expect a 10-byte response here, 8 byte CSN and 2 byte CRC
len = GetIso15693AnswerFromTag(resp, sizeof(resp), ICLASS_READER_TIMEOUT_OTHERS, eof_time);
if (len != 10) return false;//Fail
if (len != 10) return false; //Fail

//Success - we got CSN
//Save CSN in response data
Expand Down Expand Up @@ -734,42 +733,42 @@ void ReaderIClass(uint8_t flags) {
if (selectIclassTag(resp, &eof_time)) {
result_status = FLAG_ICLASS_READER_CSN;
memcpy(card_data, resp, 8);
}

start_time = eof_time + DELAY_ICLASS_VICC_TO_VCD_READER;
start_time = eof_time + DELAY_ICLASS_VICC_TO_VCD_READER;

//Read block 1, config
if (flags & FLAG_ICLASS_READER_CONF) {
if (sendCmdGetResponseWithRetries(readConf, sizeof(readConf), resp, sizeof(resp), 10, 10, start_time, ICLASS_READER_TIMEOUT_OTHERS, &eof_time)) {
result_status |= FLAG_ICLASS_READER_CONF;
memcpy(card_data+8, resp, 8);
} else {
Dbprintf("Failed to read config block");
//Read block 1, config
if (flags & FLAG_ICLASS_READER_CONF) {
if (sendCmdGetResponseWithRetries(readConf, sizeof(readConf), resp, sizeof(resp), 10, 10, start_time, ICLASS_READER_TIMEOUT_OTHERS, &eof_time)) {
result_status |= FLAG_ICLASS_READER_CONF;
memcpy(card_data+8, resp, 8);
} else {
Dbprintf("Failed to read config block");
}
start_time = eof_time + DELAY_ICLASS_VICC_TO_VCD_READER;
}
start_time = eof_time + DELAY_ICLASS_VICC_TO_VCD_READER;
}

//Read block 2, e-purse
if (flags & FLAG_ICLASS_READER_CC) {
if (sendCmdGetResponseWithRetries(readEpurse, sizeof(readEpurse), resp, sizeof(resp), 10, 10, start_time, ICLASS_READER_TIMEOUT_OTHERS, &eof_time)) {
result_status |= FLAG_ICLASS_READER_CC;
memcpy(card_data + (8*2), resp, 8);
} else {
Dbprintf("Failed to read e-purse");
//Read block 2, e-purse
if (flags & FLAG_ICLASS_READER_CC) {
if (sendCmdGetResponseWithRetries(readEpurse, sizeof(readEpurse), resp, sizeof(resp), 10, 10, start_time, ICLASS_READER_TIMEOUT_OTHERS, &eof_time)) {
result_status |= FLAG_ICLASS_READER_CC;
memcpy(card_data + (8*2), resp, 8);
} else {
Dbprintf("Failed to read e-purse");
}
start_time = eof_time + DELAY_ICLASS_VICC_TO_VCD_READER;
}
start_time = eof_time + DELAY_ICLASS_VICC_TO_VCD_READER;
}

//Read block 5, AA
if (flags & FLAG_ICLASS_READER_AA) {
if (sendCmdGetResponseWithRetries(readAA, sizeof(readAA), resp, sizeof(resp), 10, 10, start_time, ICLASS_READER_TIMEOUT_OTHERS, &eof_time)) {
result_status |= FLAG_ICLASS_READER_AA;
memcpy(card_data + (8*5), resp, 8);
} else {
Dbprintf("Failed to read AA block");
//Read block 5, AA
if (flags & FLAG_ICLASS_READER_AA) {
if (sendCmdGetResponseWithRetries(readAA, sizeof(readAA), resp, sizeof(resp), 10, 10, start_time, ICLASS_READER_TIMEOUT_OTHERS, &eof_time)) {
result_status |= FLAG_ICLASS_READER_AA;
memcpy(card_data + (8*5), resp, 8);
} else {
Dbprintf("Failed to read AA block");
}
}
}

cmd_send(CMD_ACK, result_status, 0, 0, card_data, sizeof(card_data));

LED_A_OFF();
Expand Down Expand Up @@ -820,9 +819,9 @@ void iClass_ReadBlk(uint8_t blockno) {

uint8_t readblockdata[10];
bool isOK = iClass_ReadBlock(blockno, readblockdata);
cmd_send(CMD_ACK, isOK, 0, 0, readblockdata, 8);
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
LED_D_OFF();
cmd_send(CMD_ACK, isOK, 0, 0, readblockdata, 8);

LED_A_OFF();
}
Expand Down Expand Up @@ -900,11 +899,10 @@ void iClass_WriteBlock(uint8_t blockNo, uint8_t *data) {
} else {
Dbprintf("Write block [%02x] failed", blockNo);
}
cmd_send(CMD_ACK, isOK, 0, 0, 0, 0);

FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
LED_D_OFF();

cmd_send(CMD_ACK, isOK, 0, 0, 0, 0);
LED_A_OFF();
}

Expand Down Expand Up @@ -935,6 +933,5 @@ void iClass_Clone(uint8_t startblock, uint8_t endblock, uint8_t *data) {
LED_D_OFF();

cmd_send(CMD_ACK, 1, 0, 0, 0, 0);

LED_A_OFF();
}
Loading