mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-14 18:48:13 -07:00
Better Reply structs
This commit is contained in:
parent
64eb93c9c4
commit
533667ea6d
57 changed files with 725 additions and 718 deletions
37
common/cmd.c
37
common/cmd.c
|
@ -44,9 +44,9 @@ extern void Dbprintf(const char *fmt, ...);
|
|||
#endif
|
||||
|
||||
uint8_t cmd_send(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void *data, size_t len) {
|
||||
UsbCommand txcmd;
|
||||
UsbCommandOLD txcmd;
|
||||
|
||||
for (size_t i = 0; i < sizeof(UsbCommand); i++)
|
||||
for (size_t i = 0; i < sizeof(UsbCommandOLD); i++)
|
||||
((uint8_t *)&txcmd)[i] = 0x00;
|
||||
|
||||
// Compose the outgoing command frame
|
||||
|
@ -68,47 +68,48 @@ 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(UsbCommand));
|
||||
sendlen = usart_writebuffer((uint8_t *)&txcmd, sizeof(UsbCommandOLD));
|
||||
// Dbprintf_usb("Sent %i bytes over usart", len);
|
||||
} else {
|
||||
sendlen = usb_write((uint8_t *)&txcmd, sizeof(UsbCommand));
|
||||
sendlen = usb_write((uint8_t *)&txcmd, sizeof(UsbCommandOLD));
|
||||
}
|
||||
#else
|
||||
sendlen = usb_write((uint8_t *)&txcmd, sizeof(UsbCommand));
|
||||
sendlen = usb_write((uint8_t *)&txcmd, sizeof(UsbCommandOLD));
|
||||
#endif
|
||||
|
||||
return sendlen;
|
||||
}
|
||||
|
||||
uint8_t reply_ng(uint16_t cmd, int16_t status, uint8_t *data, size_t len) {
|
||||
UsbReplyNG txBufferNG;
|
||||
UsbReplyNGRaw txBufferNG;
|
||||
size_t txBufferNGLen;
|
||||
// for (size_t i = 0; i < sizeof(txBufferNG); i++)
|
||||
// ((uint8_t *)&txBufferNG)[i] = 0x00;
|
||||
|
||||
// Compose the outgoing command frame
|
||||
txBufferNG.magic = USB_REPLYNG_PREAMBLE_MAGIC;
|
||||
txBufferNG.core.ng.cmd = cmd;
|
||||
txBufferNG.status = status;
|
||||
if (len > USB_DATANG_SIZE) {
|
||||
len = USB_DATANG_SIZE;
|
||||
txBufferNG.pre.magic = USB_REPLYNG_PREAMBLE_MAGIC;
|
||||
txBufferNG.pre.cmd = cmd;
|
||||
txBufferNG.pre.status = status;
|
||||
if (len > USB_CMD_DATA_SIZE) {
|
||||
len = USB_CMD_DATA_SIZE;
|
||||
// overwrite status
|
||||
txBufferNG.status = PM3_EOVFLOW;
|
||||
txBufferNG.pre.status = PM3_EOVFLOW;
|
||||
}
|
||||
txBufferNG.length = len;
|
||||
UsbReplyNGPostamble *tx_post = (UsbReplyNGPostamble *)((uint8_t *)&txBufferNG + sizeof(UsbReplyNGPreamble) + sizeof(UsbPacketNGCore) - USB_DATANG_SIZE + len);
|
||||
txBufferNG.pre.length = len;
|
||||
|
||||
// Add the (optional) content to the frame, with a maximum size of USB_DATANG_SIZE
|
||||
// Add the (optional) content to the frame, with a maximum size of USB_CMD_DATA_SIZE
|
||||
if (data && len) {
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
txBufferNG.core.ng.data[i] = data[i];
|
||||
txBufferNG.data[i] = data[i];
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t first, second;
|
||||
compute_crc(CRC_14443_A, (uint8_t *)&txBufferNG, sizeof(UsbReplyNGPreamble) + sizeof(UsbPacketNGCore) - USB_DATANG_SIZE + len, &first, &second);
|
||||
compute_crc(CRC_14443_A, (uint8_t *)&txBufferNG, sizeof(UsbReplyNGPreamble) + len, &first, &second);
|
||||
|
||||
UsbReplyNGPostamble *tx_post = (UsbReplyNGPostamble *)((uint8_t *)&txBufferNG + sizeof(UsbReplyNGPreamble) + len);
|
||||
tx_post->crc = (first << 8) + second;
|
||||
txBufferNGLen = sizeof(UsbReplyNGPreamble) + sizeof(UsbPacketNGCore) - USB_DATANG_SIZE + len + sizeof(UsbReplyNGPostamble);
|
||||
txBufferNGLen = sizeof(UsbReplyNGPreamble) + len + sizeof(UsbReplyNGPostamble);
|
||||
|
||||
uint32_t sendlen = 0;
|
||||
// Send frame and make sure all bytes are transmitted
|
||||
|
|
|
@ -38,8 +38,8 @@ void usart_close(void) {
|
|||
}
|
||||
*/
|
||||
|
||||
static uint8_t us_inbuf[sizeof(UsbCommand)];
|
||||
static uint8_t us_outbuf[sizeof(UsbCommand)];
|
||||
static uint8_t us_inbuf[sizeof(UsbCommandOLD)];
|
||||
static uint8_t us_outbuf[sizeof(UsbCommandOLD)];
|
||||
/*
|
||||
// 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(UsbCommand);
|
||||
pUS1->US_RCR = sizeof(UsbCommandOLD);
|
||||
pUS1->US_PTCR = AT91C_PDC_RXTEN | AT91C_PDC_TXTEN;
|
||||
check = 0;
|
||||
return 2;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue