mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-02-15 03:34:22 +08:00
Harmonize usb_write & usart_writebuffer_sync return values
This commit is contained in:
parent
3e402797c1
commit
f29facd15a
8 changed files with 24 additions and 24 deletions
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
12
common/cmd.c
12
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)) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
//*----------------------------------------------------------------------------
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue