mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-14 10:37:23 -07:00
ADD: increased debug messages in order to see when commnunications break down between device and client.
Before it silently just broke and you just didn't know what happend..
This commit is contained in:
parent
70542749bf
commit
c9f7ba2ab0
3 changed files with 27 additions and 14 deletions
|
@ -82,9 +82,9 @@ bool uart_receive(const serial_port sp, byte_t* pbtRx, size_t pszMaxRxLen, size_
|
|||
|
||||
/* Sends a buffer to a given serial port.
|
||||
* pbtTx: A pointer to a buffer containing the data to send.
|
||||
* szTxLen: The amount of data to be sent.
|
||||
* len: The amount of data to be sent.
|
||||
*/
|
||||
bool uart_send(const serial_port sp, const byte_t* pbtTx, const size_t szTxLen);
|
||||
bool uart_send(const serial_port sp, const byte_t* pbtTx, const size_t len);
|
||||
|
||||
/* Sets the current speed of the serial port, in baud.
|
||||
*/
|
||||
|
|
|
@ -203,16 +203,16 @@ bool uart_receive(const serial_port sp, byte_t* pbtRx, size_t pszMaxRxLen, size_
|
|||
return true;
|
||||
}
|
||||
|
||||
bool uart_send(const serial_port sp, const byte_t* pbtTx, const size_t szTxLen) {
|
||||
bool uart_send(const serial_port sp, const byte_t* pbtTx, const size_t len) {
|
||||
int32_t res;
|
||||
size_t szPos = 0;
|
||||
size_t pos = 0;
|
||||
fd_set rfds;
|
||||
struct timeval tv;
|
||||
|
||||
while (szPos < szTxLen) {
|
||||
while (pos < len) {
|
||||
// Reset file descriptor
|
||||
FD_ZERO(&rfds);
|
||||
FD_SET(((serial_port_unix*)sp)->fd,&rfds);
|
||||
FD_SET(((serial_port_unix*)sp)->fd, &rfds);
|
||||
tv = timeout;
|
||||
res = select(((serial_port_unix*)sp)->fd+1, NULL, &rfds, NULL, &tv);
|
||||
|
||||
|
@ -229,7 +229,7 @@ bool uart_send(const serial_port sp, const byte_t* pbtTx, const size_t szTxLen)
|
|||
}
|
||||
|
||||
// Send away the bytes
|
||||
res = write(((serial_port_unix*)sp)->fd,pbtTx+szPos,szTxLen-szPos);
|
||||
res = write(((serial_port_unix*)sp)->fd, pbtTx+pos, len-pos);
|
||||
|
||||
// Stop if the OS has some troubles sending the data
|
||||
if (res <= 0) {
|
||||
|
@ -237,7 +237,7 @@ bool uart_send(const serial_port sp, const byte_t* pbtTx, const size_t szTxLen)
|
|||
return false;
|
||||
}
|
||||
|
||||
szPos += res;
|
||||
pos += res;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -69,6 +69,7 @@ serial_port uart_open(const char* pcPortName) {
|
|||
upcase(acPortName);
|
||||
|
||||
// Try to open the serial port
|
||||
// r/w, none-share comport, no security, existing, no overlapping, no templates
|
||||
sp->hPort = CreateFileA(acPortName, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
|
||||
if (sp->hPort == INVALID_HANDLE_VALUE) {
|
||||
uart_close(sp);
|
||||
|
@ -79,7 +80,7 @@ serial_port uart_open(const char* pcPortName) {
|
|||
// doesn't matter since PM3 device ignors this CDC command: set_line_coding in usb_cdc.c
|
||||
memset(&sp->dcb, 0, sizeof(DCB));
|
||||
sp->dcb.DCBlength = sizeof(DCB);
|
||||
if (!BuildCommDCBA("baud=115200 parity=N data=8 stop=1",&sp->dcb)) {
|
||||
if (!BuildCommDCBA("baud=115200 parity=N data=8 stop=1", &sp->dcb)) {
|
||||
uart_close(sp);
|
||||
return INVALID_SERIAL_PORT;
|
||||
}
|
||||
|
@ -119,18 +120,30 @@ void uart_close(const serial_port sp) {
|
|||
|
||||
bool uart_receive(const serial_port sp, byte_t* p_rx, size_t pszMaxRxLen, size_t* p_rxlen) {
|
||||
int res = ReadFile(((serial_port_windows*)sp)->hPort, p_rx, pszMaxRxLen, (LPDWORD)p_rxlen, NULL);
|
||||
if ( res == 0 )
|
||||
if ( res == 0 ) {
|
||||
printf("UART:: reading from port error\n");
|
||||
return false;
|
||||
return ( pszMaxRxLen == *p_rxlen );
|
||||
}
|
||||
|
||||
bool read_test = ( pszMaxRxLen == *p_rxlen );
|
||||
if ( !read_test && *p_rxlen > 0 ) {
|
||||
printf("UART:: not all data read from port len %u | read %u\n", pszMaxRxLen, *p_rxlen);
|
||||
}
|
||||
return read_test;
|
||||
}
|
||||
|
||||
bool uart_send(const serial_port sp, const byte_t* p_tx, const size_t len) {
|
||||
DWORD txlen = 0;
|
||||
DWORD txlen = 0;
|
||||
int res = WriteFile(((serial_port_windows*)sp)->hPort, p_tx, len, &txlen, NULL);
|
||||
if ( res == 0)
|
||||
if ( res == 0) {
|
||||
printf("UART:: writing to port error\n");
|
||||
return false;
|
||||
return ( len == txlen );
|
||||
}
|
||||
bool write_test = ( len == txlen );
|
||||
if ( !write_test ) {
|
||||
printf("UART:: not all data written to port len %u | sent %lu\n", len, txlen);
|
||||
}
|
||||
return write_test;
|
||||
}
|
||||
|
||||
bool uart_set_speed(serial_port sp, const uint32_t uiPortSpeed) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue