diff --git a/armsrc/appmain.c b/armsrc/appmain.c index 89d462003..553f66414 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -1203,7 +1203,7 @@ static void PacketReceived(PacketCommandNG *packet) { 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) - Dbprintf("transfer to client failed :: | bytes between %d - %d (%d)", i, i + len, len); + 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 // iceman, when did sending samplingconfig array got attached here?!? @@ -1247,7 +1247,7 @@ static void PacketReceived(PacketCommandNG *packet) { 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) - Dbprintf("transfer to client failed :: | bytes between %d - %d (%d)", i, i + len, len); + 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 reply_old(CMD_ACK, 1, 0, 0, 0, 0); diff --git a/armsrc/apps.h b/armsrc/apps.h index 507c04782..723e55fa5 100644 --- a/armsrc/apps.h +++ b/armsrc/apps.h @@ -222,8 +222,9 @@ void iClass_Clone(uint8_t startblock, uint8_t endblock, uint8_t *data); void iClass_ReadCheck(uint8_t blockno, uint8_t keytype); // cmd.h -int16_t reply_old(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void *data, size_t len); -int16_t reply_ng(uint16_t cmd, int16_t status, uint8_t *data, size_t len); +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); // util.h diff --git a/common/cmd.c b/common/cmd.c index 13ca856d8..dfde60848 100644 --- a/common/cmd.c +++ b/common/cmd.c @@ -47,7 +47,7 @@ extern void Dbprintf(const char *fmt, ...); reply_via_fpc = tmp;} #endif -int16_t reply_old(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void *data, size_t len) { +int32_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(PacketResponseOLD); i++) @@ -67,7 +67,7 @@ int16_t reply_old(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, voi } } - uint32_t sendlen = 0; + int32_t sendlen = 0; // Send frame and make sure all bytes are transmitted if (reply_via_fpc) { @@ -84,7 +84,7 @@ int16_t reply_old(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, voi return sendlen; } -static int16_t reply_ng_internal(uint16_t cmd, int16_t status, uint8_t *data, size_t len, bool ng) { +static int32_t 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,7 +119,7 @@ static int16_t reply_ng_internal(uint16_t cmd, int16_t status, uint8_t *data, si } txBufferNGLen = sizeof(PacketResponseNGPreamble) + len + sizeof(PacketResponseNGPostamble); - uint32_t sendlen = 0; + int32_t sendlen = 0; // Send frame and make sure all bytes are transmitted if (reply_via_fpc) { @@ -136,11 +136,11 @@ static int16_t reply_ng_internal(uint16_t cmd, int16_t status, uint8_t *data, si return sendlen; } -int16_t reply_ng(uint16_t cmd, int16_t status, uint8_t *data, size_t len) { +int32_t reply_ng(uint16_t cmd, int16_t status, uint8_t *data, size_t len) { return reply_ng_internal(cmd, status, data, len, true); } -int16_t reply_mix(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) { uint16_t status = PM3_SUCCESS; uint64_t arg[3] = {arg0, arg1, arg2}; if (len > USB_CMD_DATA_SIZE - sizeof(arg)) { diff --git a/common/cmd.h b/common/cmd.h index 4c9d6b1d1..e6e30aadc 100644 --- a/common/cmd.h +++ b/common/cmd.h @@ -39,9 +39,9 @@ #include "usart.h" #include "proxmark3.h" -int16_t reply_old(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void *data, size_t len); -int16_t reply_ng(uint16_t cmd, int16_t status, uint8_t *data, size_t len); -int16_t reply_mix(uint64_t cmd, uint64_t arg0, uint64_t arg1, uint64_t arg2, void *data, size_t len); +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); // Flags to tell where to add CRC on sent replies diff --git a/common/usart.c b/common/usart.c index cb4153062..8294844a2 100644 --- a/common/usart.c +++ b/common/usart.c @@ -129,7 +129,7 @@ uint32_t usart_read_ng(uint8_t *data, size_t len) { } // transfer from device to client -inline int16_t usart_writebuffer_sync(uint8_t *data, size_t len) { +inline int32_t 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) diff --git a/common/usart.h b/common/usart.h index 1b3c6ded7..ff65049fa 100644 --- a/common/usart.h +++ b/common/usart.h @@ -12,7 +12,7 @@ void usart_init(void); void usart_close(void); -int16_t usart_writebuffer_sync(uint8_t *data, size_t len); +int32_t 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 diff --git a/common/usb_cdc.c b/common/usb_cdc.c index 9090d8dc2..b464beffc 100644 --- a/common/usb_cdc.c +++ b/common/usb_cdc.c @@ -709,13 +709,13 @@ uint32_t usb_read_ng(uint8_t *data, size_t len) { //* \fn usb_write //* \brief Send through endpoint 2 (device to host) //*---------------------------------------------------------------------------- -uint32_t usb_write(const uint8_t *data, const size_t len) { +int32_t usb_write(const uint8_t *data, const size_t len) { - if (!len) return 0; - if (!usb_check()) return 0; + if (!len) return PM3_EINVARG; + if (!usb_check()) return PM3_EIO; // can we write? - if ((pUdp->UDP_CSR[AT91C_EP_IN] & AT91C_UDP_TXPKTRDY) != 0) return 0; + if ((pUdp->UDP_CSR[AT91C_EP_IN] & AT91C_UDP_TXPKTRDY) != 0) return PM3_EIO; size_t length = len; uint32_t cpt = 0; @@ -741,7 +741,7 @@ uint32_t usb_write(const uint8_t *data, const size_t len) { // Wait for previous chunk to be sent // (iceman) when is the bankswapping done? while (!(pUdp->UDP_CSR[AT91C_EP_IN] & AT91C_UDP_TXCOMP)) { - if (!usb_check()) return length; + if (!usb_check()) return PM3_EIO; } UDP_CLEAR_EP_FLAGS(AT91C_EP_IN, AT91C_UDP_TXCOMP); @@ -752,13 +752,13 @@ uint32_t usb_write(const uint8_t *data, const size_t len) { // Wait for the end of transfer while (!(pUdp->UDP_CSR[AT91C_EP_IN] & AT91C_UDP_TXCOMP)) { - if (!usb_check()) return length; + if (!usb_check()) return PM3_EIO; } UDP_CLEAR_EP_FLAGS(AT91C_EP_IN, AT91C_UDP_TXCOMP); while (pUdp->UDP_CSR[AT91C_EP_IN] & AT91C_UDP_TXCOMP) {}; - return length; + return len; } //*---------------------------------------------------------------------------- diff --git a/common/usb_cdc.h b/common/usb_cdc.h index d5a4451ea..3079f93e3 100644 --- a/common/usb_cdc.h +++ b/common/usb_cdc.h @@ -47,9 +47,8 @@ bool usb_check(void); bool usb_poll(void); bool usb_poll_validate_length(void); uint32_t usb_read(uint8_t *data, size_t len); -uint32_t usb_write(const uint8_t *data, const size_t len); +int32_t usb_write(const uint8_t *data, const size_t len); uint32_t usb_read_ng(uint8_t *data, size_t len); -uint32_t usb_write_ng(const uint8_t *data, const size_t len); void SetUSBreconnect(int value); int GetUSBreconnect(void);