mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-20 21:33:47 -07:00
return PM3_SUCCESS on usart_writebuffer_sync, usb_write
This commit is contained in:
parent
9602e641e2
commit
b0eef756c1
8 changed files with 33 additions and 33 deletions
|
@ -1201,8 +1201,8 @@ static void PacketReceived(PacketCommandNG *packet) {
|
|||
|
||||
for (size_t i = 0; i < numofbytes; i += USB_CMD_DATA_SIZE) {
|
||||
size_t len = MIN((numofbytes - i), USB_CMD_DATA_SIZE);
|
||||
int16_t result = reply_old(CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K, i, len, BigBuf_get_traceLen(), mem + startidx + i, len);
|
||||
if (result <= 0)
|
||||
int result = reply_old(CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K, i, len, BigBuf_get_traceLen(), mem + startidx + i, len);
|
||||
if (result != PM3_SUCCESS)
|
||||
Dbprintf("transfer to client failed :: | bytes between %d - %d (%d) | result: %d", i, i + len, len, result);
|
||||
}
|
||||
// Trigger a finish downloading signal with an ACK frame
|
||||
|
@ -1245,8 +1245,8 @@ static void PacketReceived(PacketCommandNG *packet) {
|
|||
|
||||
for (size_t i = 0; i < numofbytes; i += USB_CMD_DATA_SIZE) {
|
||||
len = MIN((numofbytes - i), USB_CMD_DATA_SIZE);
|
||||
int16_t result = reply_old(CMD_DOWNLOADED_EML_BIGBUF, i, len, 0, mem + startidx + i, len);
|
||||
if (result <= 0)
|
||||
int result = reply_old(CMD_DOWNLOADED_EML_BIGBUF, i, len, 0, mem + startidx + i, len);
|
||||
if (result != PM3_SUCCESS)
|
||||
Dbprintf("transfer to client failed :: | bytes between %d - %d (%d) | result: %d", i, i + len, len, result);
|
||||
}
|
||||
// Trigger a finish downloading signal with an ACK frame
|
||||
|
@ -1570,7 +1570,7 @@ void __attribute__((noreturn)) AppMain(void) {
|
|||
|
||||
// Check if there is a packet available
|
||||
PacketCommandNG rx;
|
||||
int16_t ret = receive_ng(&rx);
|
||||
int ret = receive_ng(&rx);
|
||||
if (ret == PM3_SUCCESS) {
|
||||
PacketReceived(&rx);
|
||||
} else if (ret != PM3_ENODATA) {
|
||||
|
|
|
@ -222,10 +222,10 @@ void iClass_Clone(uint8_t startblock, uint8_t endblock, uint8_t *data);
|
|||
void iClass_ReadCheck(uint8_t blockno, uint8_t keytype);
|
||||
|
||||
// cmd.h
|
||||
int32_t reply_old(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void *data, size_t len);
|
||||
int32_t reply_mix(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void *data, size_t len);
|
||||
int32_t reply_ng(uint16_t cmd, int16_t status, uint8_t *data, size_t len);
|
||||
int16_t receive_ng(PacketCommandNG *rx);
|
||||
int reply_old(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void *data, size_t len);
|
||||
int reply_mix(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void *data, size_t len);
|
||||
int reply_ng(uint16_t cmd, int16_t status, uint8_t *data, size_t len);
|
||||
int receive_ng(PacketCommandNG *rx);
|
||||
|
||||
// util.h
|
||||
void HfSniff(int, int);
|
||||
|
|
28
common/cmd.c
28
common/cmd.c
|
@ -47,7 +47,7 @@ extern void Dbprintf(const char *fmt, ...);
|
|||
reply_via_fpc = tmp;}
|
||||
#endif
|
||||
|
||||
int32_t reply_old(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void *data, size_t len) {
|
||||
int 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(PacketResponseOLD); i++)
|
||||
|
@ -67,24 +67,24 @@ int32_t reply_old(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, voi
|
|||
}
|
||||
}
|
||||
|
||||
int32_t sendlen = 0;
|
||||
int result = PM3_EUNDEF;
|
||||
// Send frame and make sure all bytes are transmitted
|
||||
|
||||
if (reply_via_fpc) {
|
||||
#ifdef WITH_FPC_HOST
|
||||
sendlen = usart_writebuffer_sync((uint8_t *)&txcmd, sizeof(PacketResponseOLD));
|
||||
result = usart_writebuffer_sync((uint8_t *)&txcmd, sizeof(PacketResponseOLD));
|
||||
// Dbprintf_usb("Sent %i bytes over usart", len);
|
||||
#else
|
||||
return PM3_EDEVNOTSUPP;
|
||||
#endif
|
||||
} else {
|
||||
sendlen = usb_write((uint8_t *)&txcmd, sizeof(PacketResponseOLD));
|
||||
result = usb_write((uint8_t *)&txcmd, sizeof(PacketResponseOLD));
|
||||
}
|
||||
|
||||
return sendlen;
|
||||
return result;
|
||||
}
|
||||
|
||||
static int32_t reply_ng_internal(uint16_t cmd, int16_t status, uint8_t *data, size_t len, bool ng) {
|
||||
static int reply_ng_internal(uint16_t cmd, int16_t status, uint8_t *data, size_t len, bool ng) {
|
||||
PacketResponseNGRaw txBufferNG;
|
||||
size_t txBufferNGLen;
|
||||
// for (size_t i = 0; i < sizeof(txBufferNG); i++)
|
||||
|
@ -119,28 +119,28 @@ static int32_t reply_ng_internal(uint16_t cmd, int16_t status, uint8_t *data, si
|
|||
}
|
||||
txBufferNGLen = sizeof(PacketResponseNGPreamble) + len + sizeof(PacketResponseNGPostamble);
|
||||
|
||||
int32_t sendlen = 0;
|
||||
int result = PM3_EUNDEF;
|
||||
// Send frame and make sure all bytes are transmitted
|
||||
|
||||
if (reply_via_fpc) {
|
||||
#ifdef WITH_FPC_HOST
|
||||
sendlen = usart_writebuffer_sync((uint8_t *)&txBufferNG, txBufferNGLen);
|
||||
result = usart_writebuffer_sync((uint8_t *)&txBufferNG, txBufferNGLen);
|
||||
// Dbprintf_usb("Sent %i bytes over usart", len);
|
||||
#else
|
||||
return PM3_EDEVNOTSUPP;
|
||||
#endif
|
||||
} else {
|
||||
sendlen = usb_write((uint8_t *)&txBufferNG, txBufferNGLen);
|
||||
result = usb_write((uint8_t *)&txBufferNG, txBufferNGLen);
|
||||
}
|
||||
|
||||
return sendlen;
|
||||
return result;
|
||||
}
|
||||
|
||||
int32_t reply_ng(uint16_t cmd, int16_t status, uint8_t *data, size_t len) {
|
||||
int reply_ng(uint16_t cmd, int16_t status, uint8_t *data, size_t len) {
|
||||
return reply_ng_internal(cmd, status, data, len, true);
|
||||
}
|
||||
|
||||
int32_t reply_mix(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void *data, size_t len) {
|
||||
int reply_mix(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void *data, size_t len) {
|
||||
uint16_t status = PM3_SUCCESS;
|
||||
uint64_t arg[3] = {arg0, arg1, arg2};
|
||||
if (len > USB_CMD_DATA_SIZE - sizeof(arg)) {
|
||||
|
@ -154,7 +154,7 @@ int32_t reply_mix(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, voi
|
|||
return reply_ng_internal(cmd, status, cmddata, len + sizeof(arg), false);
|
||||
}
|
||||
|
||||
static int16_t receive_ng_internal(PacketCommandNG *rx, uint32_t read_ng(uint8_t *data, size_t len), bool fpc) {
|
||||
static int receive_ng_internal(PacketCommandNG *rx, uint32_t read_ng(uint8_t *data, size_t len), bool fpc) {
|
||||
PacketCommandNGRaw rx_raw;
|
||||
size_t bytes = read_ng((uint8_t *)&rx_raw.pre, sizeof(PacketCommandNGPreamble));
|
||||
if (bytes == 0)
|
||||
|
@ -219,7 +219,7 @@ static int16_t receive_ng_internal(PacketCommandNG *rx, uint32_t read_ng(uint8_t
|
|||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
int16_t receive_ng(PacketCommandNG *rx) {
|
||||
int receive_ng(PacketCommandNG *rx) {
|
||||
|
||||
// Check if there is a packet available
|
||||
if (usb_poll_validate_length())
|
||||
|
|
|
@ -39,10 +39,10 @@
|
|||
#include "usart.h"
|
||||
#include "proxmark3.h"
|
||||
|
||||
int32_t reply_old(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void *data, size_t len);
|
||||
int32_t reply_ng(uint16_t cmd, int16_t status, uint8_t *data, size_t len);
|
||||
int32_t reply_mix(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void *data, size_t len);
|
||||
int16_t receive_ng(PacketCommandNG *rx);
|
||||
int reply_old(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void *data, size_t len);
|
||||
int reply_ng(uint16_t cmd, int16_t status, uint8_t *data, size_t len);
|
||||
int reply_mix(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void *data, size_t len);
|
||||
int receive_ng(PacketCommandNG *rx);
|
||||
|
||||
// Flags to tell where to add CRC on sent replies
|
||||
extern bool reply_with_crc_on_usb;
|
||||
|
|
|
@ -129,7 +129,7 @@ uint32_t usart_read_ng(uint8_t *data, size_t len) {
|
|||
}
|
||||
|
||||
// transfer from device to client
|
||||
inline int32_t usart_writebuffer_sync(uint8_t *data, size_t len) {
|
||||
inline int usart_writebuffer_sync(uint8_t *data, size_t len) {
|
||||
|
||||
// Wait for current PDC bank to be free
|
||||
// (and check next bank too, in case there will be a usart_writebuffer_async)
|
||||
|
@ -139,7 +139,7 @@ inline int32_t usart_writebuffer_sync(uint8_t *data, size_t len) {
|
|||
// Wait until finishing all transfers to make sure "data" buffer can be discarded
|
||||
// (if we don't wait here, bulk send as e.g. "hw status" will fail)
|
||||
while (pUS1->US_TNCR || pUS1->US_TCR) {};
|
||||
return len;
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
void usart_init(void) {
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
void usart_init(void);
|
||||
void usart_close(void);
|
||||
|
||||
int32_t usart_writebuffer_sync(uint8_t *data, size_t len);
|
||||
int usart_writebuffer_sync(uint8_t *data, size_t len);
|
||||
uint32_t usart_read_ng(uint8_t *data, size_t len);
|
||||
uint16_t usart_rxdata_available(void);
|
||||
#define USART_BUFFLEN 512
|
||||
|
|
|
@ -709,7 +709,7 @@ uint32_t usb_read_ng(uint8_t *data, size_t len) {
|
|||
//* \fn usb_write
|
||||
//* \brief Send through endpoint 2 (device to host)
|
||||
//*----------------------------------------------------------------------------
|
||||
int32_t usb_write(const uint8_t *data, const size_t len) {
|
||||
int usb_write(const uint8_t *data, const size_t len) {
|
||||
|
||||
if (!len) return PM3_EINVARG;
|
||||
if (!usb_check()) return PM3_EIO;
|
||||
|
@ -758,7 +758,7 @@ int32_t usb_write(const uint8_t *data, const size_t len) {
|
|||
UDP_CLEAR_EP_FLAGS(AT91C_EP_IN, AT91C_UDP_TXCOMP);
|
||||
while (pUdp->UDP_CSR[AT91C_EP_IN] & AT91C_UDP_TXCOMP) {};
|
||||
|
||||
return len;
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
//*----------------------------------------------------------------------------
|
||||
|
|
|
@ -47,7 +47,7 @@ bool usb_check(void);
|
|||
bool usb_poll(void);
|
||||
bool usb_poll_validate_length(void);
|
||||
uint32_t usb_read(uint8_t *data, size_t len);
|
||||
int32_t usb_write(const uint8_t *data, const size_t len);
|
||||
int usb_write(const uint8_t *data, const size_t len);
|
||||
uint32_t usb_read_ng(uint8_t *data, size_t len);
|
||||
|
||||
void SetUSBreconnect(int value);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue