return PM3_SUCCESS on usart_writebuffer_sync, usb_write

This commit is contained in:
Philippe Teuwen 2019-04-22 22:58:45 +02:00
commit b0eef756c1
8 changed files with 33 additions and 33 deletions

View file

@ -1201,8 +1201,8 @@ static void PacketReceived(PacketCommandNG *packet) {
for (size_t i = 0; i < numofbytes; i += USB_CMD_DATA_SIZE) { for (size_t i = 0; i < numofbytes; i += USB_CMD_DATA_SIZE) {
size_t len = MIN((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); int result = reply_old(CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K, i, len, BigBuf_get_traceLen(), mem + startidx + i, len);
if (result <= 0) if (result != PM3_SUCCESS)
Dbprintf("transfer to client failed :: | bytes between %d - %d (%d) | result: %d", i, i + len, len, result); 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 // 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) { for (size_t i = 0; i < numofbytes; i += USB_CMD_DATA_SIZE) {
len = MIN((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); int result = reply_old(CMD_DOWNLOADED_EML_BIGBUF, i, len, 0, mem + startidx + i, len);
if (result <= 0) if (result != PM3_SUCCESS)
Dbprintf("transfer to client failed :: | bytes between %d - %d (%d) | result: %d", i, i + len, len, result); 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 // 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 // Check if there is a packet available
PacketCommandNG rx; PacketCommandNG rx;
int16_t ret = receive_ng(&rx); int ret = receive_ng(&rx);
if (ret == PM3_SUCCESS) { if (ret == PM3_SUCCESS) {
PacketReceived(&rx); PacketReceived(&rx);
} else if (ret != PM3_ENODATA) { } else if (ret != PM3_ENODATA) {

View file

@ -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); void iClass_ReadCheck(uint8_t blockno, uint8_t keytype);
// cmd.h // cmd.h
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);
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);
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);
int16_t receive_ng(PacketCommandNG *rx); int receive_ng(PacketCommandNG *rx);
// util.h // util.h
void HfSniff(int, int); void HfSniff(int, int);

View file

@ -47,7 +47,7 @@ extern void Dbprintf(const char *fmt, ...);
reply_via_fpc = tmp;} reply_via_fpc = tmp;}
#endif #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; PacketResponseOLD txcmd;
for (size_t i = 0; i < sizeof(PacketResponseOLD); i++) 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 // Send frame and make sure all bytes are transmitted
if (reply_via_fpc) { if (reply_via_fpc) {
#ifdef WITH_FPC_HOST #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); // Dbprintf_usb("Sent %i bytes over usart", len);
#else #else
return PM3_EDEVNOTSUPP; return PM3_EDEVNOTSUPP;
#endif #endif
} else { } 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; PacketResponseNGRaw txBufferNG;
size_t txBufferNGLen; size_t txBufferNGLen;
// for (size_t i = 0; i < sizeof(txBufferNG); i++) // 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); txBufferNGLen = sizeof(PacketResponseNGPreamble) + len + sizeof(PacketResponseNGPostamble);
int32_t sendlen = 0; int result = PM3_EUNDEF;
// Send frame and make sure all bytes are transmitted // Send frame and make sure all bytes are transmitted
if (reply_via_fpc) { if (reply_via_fpc) {
#ifdef WITH_FPC_HOST #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); // Dbprintf_usb("Sent %i bytes over usart", len);
#else #else
return PM3_EDEVNOTSUPP; return PM3_EDEVNOTSUPP;
#endif #endif
} else { } 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); 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; uint16_t status = PM3_SUCCESS;
uint64_t arg[3] = {arg0, arg1, arg2}; uint64_t arg[3] = {arg0, arg1, arg2};
if (len > USB_CMD_DATA_SIZE - sizeof(arg)) { 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); 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; PacketCommandNGRaw rx_raw;
size_t bytes = read_ng((uint8_t *)&rx_raw.pre, sizeof(PacketCommandNGPreamble)); size_t bytes = read_ng((uint8_t *)&rx_raw.pre, sizeof(PacketCommandNGPreamble));
if (bytes == 0) if (bytes == 0)
@ -219,7 +219,7 @@ static int16_t receive_ng_internal(PacketCommandNG *rx, uint32_t read_ng(uint8_t
return PM3_SUCCESS; return PM3_SUCCESS;
} }
int16_t receive_ng(PacketCommandNG *rx) { int receive_ng(PacketCommandNG *rx) {
// Check if there is a packet available // Check if there is a packet available
if (usb_poll_validate_length()) if (usb_poll_validate_length())

View file

@ -39,10 +39,10 @@
#include "usart.h" #include "usart.h"
#include "proxmark3.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); int 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); int 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); int 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 receive_ng(PacketCommandNG *rx);
// Flags to tell where to add CRC on sent replies // Flags to tell where to add CRC on sent replies
extern bool reply_with_crc_on_usb; extern bool reply_with_crc_on_usb;

View file

@ -129,7 +129,7 @@ uint32_t usart_read_ng(uint8_t *data, size_t len) {
} }
// transfer from device to client // 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 // Wait for current PDC bank to be free
// (and check next bank too, in case there will be a usart_writebuffer_async) // (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 // 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) // (if we don't wait here, bulk send as e.g. "hw status" will fail)
while (pUS1->US_TNCR || pUS1->US_TCR) {}; while (pUS1->US_TNCR || pUS1->US_TCR) {};
return len; return PM3_SUCCESS;
} }
void usart_init(void) { void usart_init(void) {

View file

@ -12,7 +12,7 @@
void usart_init(void); void usart_init(void);
void usart_close(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); uint32_t usart_read_ng(uint8_t *data, size_t len);
uint16_t usart_rxdata_available(void); uint16_t usart_rxdata_available(void);
#define USART_BUFFLEN 512 #define USART_BUFFLEN 512

View file

@ -709,7 +709,7 @@ uint32_t usb_read_ng(uint8_t *data, size_t len) {
//* \fn usb_write //* \fn usb_write
//* \brief Send through endpoint 2 (device to host) //* \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 (!len) return PM3_EINVARG;
if (!usb_check()) return PM3_EIO; 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); UDP_CLEAR_EP_FLAGS(AT91C_EP_IN, AT91C_UDP_TXCOMP);
while (pUdp->UDP_CSR[AT91C_EP_IN] & AT91C_UDP_TXCOMP) {}; while (pUdp->UDP_CSR[AT91C_EP_IN] & AT91C_UDP_TXCOMP) {};
return len; return PM3_SUCCESS;
} }
//*---------------------------------------------------------------------------- //*----------------------------------------------------------------------------

View file

@ -47,7 +47,7 @@ bool usb_check(void);
bool usb_poll(void); bool usb_poll(void);
bool usb_poll_validate_length(void); bool usb_poll_validate_length(void);
uint32_t usb_read(uint8_t *data, size_t len); 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); uint32_t usb_read_ng(uint8_t *data, size_t len);
void SetUSBreconnect(int value); void SetUSBreconnect(int value);