Rename few stuff for consistency

This commit is contained in:
Philippe Teuwen 2019-04-18 12:43:35 +02:00
commit 482db05741
83 changed files with 691 additions and 675 deletions

View file

@ -43,10 +43,10 @@ extern void Dbprintf(const char *fmt, ...);
reply_via_fpc = true;}
#endif
uint8_t cmd_send(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void *data, size_t len) {
UsbCommandOLD txcmd;
uint8_t reply_old(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void *data, size_t len) {
PacketResponseOLD txcmd;
for (size_t i = 0; i < sizeof(UsbCommandOLD); i++)
for (size_t i = 0; i < sizeof(PacketResponseOLD); i++)
((uint8_t *)&txcmd)[i] = 0x00;
// Compose the outgoing command frame
@ -68,20 +68,20 @@ uint8_t cmd_send(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void
#ifdef WITH_FPC_HOST
if (reply_via_fpc) {
sendlen = usart_writebuffer((uint8_t *)&txcmd, sizeof(UsbCommandOLD));
sendlen = usart_writebuffer((uint8_t *)&txcmd, sizeof(PacketResponseOLD));
// Dbprintf_usb("Sent %i bytes over usart", len);
} else {
sendlen = usb_write((uint8_t *)&txcmd, sizeof(UsbCommandOLD));
sendlen = usb_write((uint8_t *)&txcmd, sizeof(PacketResponseOLD));
}
#else
sendlen = usb_write((uint8_t *)&txcmd, sizeof(UsbCommandOLD));
sendlen = usb_write((uint8_t *)&txcmd, sizeof(PacketResponseOLD));
#endif
return sendlen;
}
uint8_t reply_ng(uint16_t cmd, int16_t status, uint8_t *data, size_t len) {
UsbReplyNGRaw txBufferNG;
PacketResponseNGRaw txBufferNG;
size_t txBufferNGLen;
// for (size_t i = 0; i < sizeof(txBufferNG); i++)
// ((uint8_t *)&txBufferNG)[i] = 0x00;
@ -105,11 +105,11 @@ uint8_t reply_ng(uint16_t cmd, int16_t status, uint8_t *data, size_t len) {
}
uint8_t first, second;
compute_crc(CRC_14443_A, (uint8_t *)&txBufferNG, sizeof(UsbReplyNGPreamble) + len, &first, &second);
compute_crc(CRC_14443_A, (uint8_t *)&txBufferNG, sizeof(PacketResponseNGPreamble) + len, &first, &second);
UsbReplyNGPostamble *tx_post = (UsbReplyNGPostamble *)((uint8_t *)&txBufferNG + sizeof(UsbReplyNGPreamble) + len);
PacketResponseNGPostamble *tx_post = (PacketResponseNGPostamble *)((uint8_t *)&txBufferNG + sizeof(PacketResponseNGPreamble) + len);
tx_post->crc = (first << 8) + second;
txBufferNGLen = sizeof(UsbReplyNGPreamble) + len + sizeof(UsbReplyNGPostamble);
txBufferNGLen = sizeof(PacketResponseNGPreamble) + len + sizeof(PacketResponseNGPostamble);
uint32_t sendlen = 0;
// Send frame and make sure all bytes are transmitted
@ -128,10 +128,10 @@ uint8_t reply_ng(uint16_t cmd, int16_t status, uint8_t *data, size_t len) {
return sendlen;
}
int16_t receive_ng(UsbCommandNG *rx) {
UsbCommandNGRaw rx_raw;
size_t bytes = usb_read_ng((uint8_t *)&rx_raw.pre, sizeof(UsbCommandNGPreamble));
if (bytes != sizeof(UsbCommandNGPreamble))
int16_t receive_ng(PacketCommandNG *rx) {
PacketCommandNGRaw rx_raw;
size_t bytes = usb_read_ng((uint8_t *)&rx_raw.pre, sizeof(PacketCommandNGPreamble));
if (bytes != sizeof(PacketCommandNGPreamble))
return PM3_EIO;
rx->magic = rx_raw.pre.magic;
rx->length = rx_raw.pre.length;
@ -145,13 +145,13 @@ int16_t receive_ng(UsbCommandNG *rx) {
return PM3_EIO;
memcpy(rx->data.asBytes, rx_raw.data, rx->length);
// Get the postamble
bytes = usb_read_ng((uint8_t *)&rx_raw.foopost, sizeof(UsbCommandNGPostamble));
if (bytes != sizeof(UsbCommandNGPostamble))
bytes = usb_read_ng((uint8_t *)&rx_raw.foopost, sizeof(PacketCommandNGPostamble));
if (bytes != sizeof(PacketCommandNGPostamble))
return PM3_EIO;
// Check CRC
rx->crc = rx_raw.foopost.crc;
uint8_t first, second;
compute_crc(CRC_14443_A, (uint8_t *)&rx_raw, sizeof(UsbCommandNGPreamble) + rx->length, &first, &second);
compute_crc(CRC_14443_A, (uint8_t *)&rx_raw, sizeof(PacketCommandNGPreamble) + rx->length, &first, &second);
if ((first << 8) + second != rx->crc)
return PM3_EIO;
#ifdef WITH_FPC_HOST
@ -159,10 +159,10 @@ int16_t receive_ng(UsbCommandNG *rx) {
#endif
rx->ng = true;
} else { // Old style command
UsbCommandOLD rx_old;
memcpy(&rx_old, &rx_raw.pre, sizeof(UsbCommandNGPreamble));
bytes = usb_read_ng(((uint8_t *)&rx_old) + sizeof(UsbCommandNGPreamble), sizeof(UsbCommandOLD) - sizeof(UsbCommandNGPreamble));
if (bytes != sizeof(UsbCommandOLD) - sizeof(UsbCommandNGPreamble))
PacketCommandOLD rx_old;
memcpy(&rx_old, &rx_raw.pre, sizeof(PacketCommandNGPreamble));
bytes = usb_read_ng(((uint8_t *)&rx_old) + sizeof(PacketCommandNGPreamble), sizeof(PacketCommandOLD) - sizeof(PacketCommandNGPreamble));
if (bytes != sizeof(PacketCommandOLD) - sizeof(PacketCommandNGPreamble))
return PM3_EIO;
#ifdef WITH_FPC_HOST
reply_via_fpc = false;

View file

@ -39,9 +39,9 @@
#include "usart.h"
#include "proxmark3.h"
uint8_t cmd_send(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void *data, size_t len);
uint8_t reply_old(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void *data, size_t len);
uint8_t reply_ng(uint16_t cmd, int16_t status, uint8_t *data, size_t len);
int16_t receive_ng(UsbCommandNG *rx);
int16_t receive_ng(PacketCommandNG *rx);
#endif // _PROXMARK_CMD_H_

View file

@ -691,7 +691,7 @@ void SmartCardAtr(void) {
set_tracing(true);
I2C_Reset_EnterMainProgram();
bool isOK = GetATR(&card);
cmd_send(CMD_ACK, isOK, sizeof(smart_card_atr_t), 0, &card, sizeof(smart_card_atr_t));
reply_old(CMD_ACK, isOK, sizeof(smart_card_atr_t), 0, &card, sizeof(smart_card_atr_t));
set_tracing(false);
LEDsoff();
}
@ -716,7 +716,7 @@ void SmartCardRaw(uint64_t arg0, uint64_t arg1, uint8_t *data) {
if ((flags & SC_SELECT)) {
smart_card_atr_t card;
bool gotATR = GetATR(&card);
//cmd_send(CMD_ACK, gotATR, sizeof(smart_card_atr_t), 0, &card, sizeof(smart_card_atr_t));
//reply_old(CMD_ACK, gotATR, sizeof(smart_card_atr_t), 0, &card, sizeof(smart_card_atr_t));
if (!gotATR)
goto OUT;
}
@ -742,7 +742,7 @@ void SmartCardRaw(uint64_t arg0, uint64_t arg1, uint8_t *data) {
}
}
OUT:
cmd_send(CMD_ACK, len, 0, 0, resp, len);
reply_old(CMD_ACK, len, 0, 0, resp, len);
BigBuf_free();
set_tracing(false);
LEDsoff();
@ -801,7 +801,7 @@ void SmartCardUpgrade(uint64_t arg0) {
length -= size;
pos += size;
}
cmd_send(CMD_ACK, isOK, pos, 0, 0, 0);
reply_old(CMD_ACK, isOK, pos, 0, 0, 0);
LED_C_OFF();
BigBuf_free();
}
@ -818,7 +818,7 @@ void SmartCardSetClock(uint64_t arg0) {
// start [C0 05 xx] stop
I2C_WriteByte(arg0, I2C_DEVICE_CMD_SIM_CLC, I2C_DEVICE_ADDRESS_MAIN);
cmd_send(CMD_ACK, 1, 0, 0, 0, 0);
reply_old(CMD_ACK, 1, 0, 0, 0, 0);
set_tracing(false);
LEDsoff();
}

View file

@ -38,8 +38,8 @@ void usart_close(void) {
}
*/
static uint8_t us_inbuf[sizeof(UsbCommandOLD)];
static uint8_t us_outbuf[sizeof(UsbCommandOLD)];
static uint8_t us_inbuf[sizeof(PacketCommandOLD)];
static uint8_t us_outbuf[sizeof(PacketResponseOLD)];
/*
// transfer from client to device
inline int16_t usart_readbuffer(uint8_t *data) {
@ -63,7 +63,7 @@ inline int16_t usart_readbuffer(uint8_t *data) {
// Check if the first PDC bank is free
if (pUS1->US_RCR == 0) {
pUS1->US_RPR = (uint32_t)data;
pUS1->US_RCR = sizeof(UsbCommandOLD);
pUS1->US_RCR = sizeof(PacketCommandOLD);
pUS1->US_PTCR = AT91C_PDC_RXTEN | AT91C_PDC_TXTEN;
check = 0;
return 2;