New reply frames transmission (reception still to be done)

This commit is contained in:
Philippe Teuwen 2019-04-16 23:15:23 +02:00
commit 96843c3f47
6 changed files with 112 additions and 23 deletions

View file

@ -30,6 +30,7 @@
* @brief
*/
#include "cmd.h"
#include "crc16.h"
#ifdef WITH_FPC_HOST
// "Session" flag, to tell via which interface next msgs should be sent: USB or FPC USART
@ -78,3 +79,53 @@ uint8_t cmd_send(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void
return sendlen;
}
uint8_t reply_ng(uint16_t cmd, int16_t status, uint8_t *data, size_t len) {
uint8_t txBufferNG[USB_REPLYNG_MAXLEN];
size_t txBufferNGLen;
// for (size_t i = 0; i < sizeof(txBufferNG); i++)
// ((uint8_t *)&txBufferNG)[i] = 0x00;
// Compose the outgoing command frame
UsbReplyNGPreamble *tx_pre = (UsbReplyNGPreamble *)txBufferNG;
tx_pre->magic = USB_REPLYNG_PREAMBLE_MAGIC;
tx_pre->cmd = cmd;
tx_pre->status = status;
if (len > USB_DATANG_SIZE) {
len = USB_DATANG_SIZE;
// overwrite status
tx_pre->status = PM3_EOVFLOW;
}
tx_pre->length = len;
uint8_t *tx_data = txBufferNG + sizeof(UsbReplyNGPreamble);
UsbReplyNGPostamble *tx_post = (UsbReplyNGPostamble *)(txBufferNG + sizeof(UsbReplyNGPreamble) + len);
// Add the (optional) content to the frame, with a maximum size of USB_DATANG_SIZE
if (data && len) {
for (size_t i = 0; i < len; i++) {
tx_data[i] = data[i];
}
}
uint8_t first, second;
compute_crc(CRC_14443_A, txBufferNG, sizeof(UsbReplyNGPreamble) + len, &first, &second);
tx_post->crc = (first << 8) + second;
txBufferNGLen = sizeof(UsbReplyNGPreamble) + len + sizeof(UsbReplyNGPostamble);
uint32_t sendlen = 0;
// Send frame and make sure all bytes are transmitted
#ifdef WITH_FPC_HOST
if (reply_via_fpc) {
sendlen = usart_writebuffer(txBufferNG, txBufferNGLen);
// Dbprintf_usb("Sent %i bytes over usart", len);
} else {
sendlen = usb_write(txBufferNG, txBufferNGLen);
}
#else
sendlen = usb_write(txBufferNG, txBufferNGLen);
#endif
return sendlen;
}

View file

@ -40,6 +40,7 @@
#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_ng(uint16_t cmd, int16_t status, uint8_t *data, size_t len);
#endif // _PROXMARK_CMD_H_