mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-20 05:13:46 -07:00
fix uart_posix: bytecound must be 32b
This commit is contained in:
parent
6e744043f5
commit
4aa1b49493
4 changed files with 12 additions and 10 deletions
|
@ -319,7 +319,7 @@ __attribute__((force_align_arg_pointer))
|
||||||
#endif
|
#endif
|
||||||
*uart_communication(void *targ) {
|
*uart_communication(void *targ) {
|
||||||
communication_arg_t *connection = (communication_arg_t *)targ;
|
communication_arg_t *connection = (communication_arg_t *)targ;
|
||||||
size_t rxlen;
|
uint32_t rxlen;
|
||||||
|
|
||||||
PacketResponseNG rx;
|
PacketResponseNG rx;
|
||||||
PacketResponseNGRaw rx_raw;
|
PacketResponseNGRaw rx_raw;
|
||||||
|
|
|
@ -88,13 +88,13 @@ void uart_close(const serial_port sp);
|
||||||
* partial read may have completed into the buffer by the corresponding
|
* partial read may have completed into the buffer by the corresponding
|
||||||
* implementation, so pszRxLen should be checked to see if any data was written.
|
* implementation, so pszRxLen should be checked to see if any data was written.
|
||||||
*/
|
*/
|
||||||
bool uart_receive(const serial_port sp, uint8_t *pbtRx, size_t pszMaxRxLen, size_t *pszRxLen);
|
bool uart_receive(const serial_port sp, uint8_t *pbtRx, uint32_t pszMaxRxLen, uint32_t *pszRxLen);
|
||||||
|
|
||||||
/* Sends a buffer to a given serial port.
|
/* Sends a buffer to a given serial port.
|
||||||
* pbtTx: A pointer to a buffer containing the data to send.
|
* pbtTx: A pointer to a buffer containing the data to send.
|
||||||
* len: The amount of data to be sent.
|
* len: The amount of data to be sent.
|
||||||
*/
|
*/
|
||||||
bool uart_send(const serial_port sp, const uint8_t *pbtTx, const size_t len);
|
bool uart_send(const serial_port sp, const uint8_t *pbtTx, const uint32_t len);
|
||||||
|
|
||||||
/* Sets the current speed of the serial port, in baud.
|
/* Sets the current speed of the serial port, in baud.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -234,8 +234,8 @@ void uart_close(const serial_port sp) {
|
||||||
free(sp);
|
free(sp);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool uart_receive(const serial_port sp, uint8_t *pbtRx, size_t pszMaxRxLen, size_t *pszRxLen) {
|
bool uart_receive(const serial_port sp, uint8_t *pbtRx, uint32_t pszMaxRxLen, uint32_t *pszRxLen) {
|
||||||
size_t byteCount;
|
uint32_t byteCount; // FIONREAD returns size on 32b
|
||||||
fd_set rfds;
|
fd_set rfds;
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
|
|
||||||
|
@ -267,10 +267,12 @@ bool uart_receive(const serial_port sp, uint8_t *pbtRx, size_t pszMaxRxLen, size
|
||||||
|
|
||||||
// Retrieve the count of the incoming bytes
|
// Retrieve the count of the incoming bytes
|
||||||
res = ioctl(((serial_port_unix *)sp)->fd, FIONREAD, &byteCount);
|
res = ioctl(((serial_port_unix *)sp)->fd, FIONREAD, &byteCount);
|
||||||
|
printf("UART:: RX ioctl res %d byteCount %u\n", res, byteCount);
|
||||||
if (res < 0) return false;
|
if (res < 0) return false;
|
||||||
|
|
||||||
// Cap the number of bytes, so we don't overrun the buffer
|
// Cap the number of bytes, so we don't overrun the buffer
|
||||||
if (pszMaxRxLen - (*pszRxLen) < byteCount) {
|
if (pszMaxRxLen - (*pszRxLen) < byteCount) {
|
||||||
|
printf("UART:: RX buffer overrun (have %u, need %u)\n", pszMaxRxLen - (*pszRxLen), byteCount);
|
||||||
byteCount = pszMaxRxLen - (*pszRxLen);
|
byteCount = pszMaxRxLen - (*pszRxLen);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -292,8 +294,8 @@ bool uart_receive(const serial_port sp, uint8_t *pbtRx, size_t pszMaxRxLen, size
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool uart_send(const serial_port sp, const uint8_t *pbtTx, const size_t len) {
|
bool uart_send(const serial_port sp, const uint8_t *pbtTx, const uint32_t len) {
|
||||||
size_t pos = 0;
|
uint32_t pos = 0;
|
||||||
fd_set rfds;
|
fd_set rfds;
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
|
|
||||||
|
|
|
@ -169,11 +169,11 @@ uint32_t uart_get_speed(const serial_port sp) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool uart_receive(const serial_port sp, uint8_t *p_rx, size_t pszMaxRxLen, size_t *len) {
|
bool uart_receive(const serial_port sp, uint8_t *pbtRx, uint32_t pszMaxRxLen, uint32_t *pszRxLen) {
|
||||||
return ReadFile(((serial_port_windows *)sp)->hPort, p_rx, pszMaxRxLen, (LPDWORD)len, NULL);
|
return ReadFile(((serial_port_windows *)sp)->hPort, pbtRx, pszMaxRxLen, (LPDWORD)pszRxLen, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool uart_send(const serial_port sp, const uint8_t *p_tx, const size_t len) {
|
bool uart_send(const serial_port sp, const uint8_t *p_tx, const uint32_t len) {
|
||||||
DWORD txlen = 0;
|
DWORD txlen = 0;
|
||||||
return WriteFile(((serial_port_windows *)sp)->hPort, p_tx, len, &txlen, NULL);
|
return WriteFile(((serial_port_windows *)sp)->hPort, p_tx, len, &txlen, NULL);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue