mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-20 05:13:46 -07:00
make style
This commit is contained in:
parent
0d9223a547
commit
0373696662
483 changed files with 56514 additions and 52451 deletions
|
@ -73,8 +73,9 @@ struct timeval timeout = {
|
|||
.tv_usec = 30000 // 30 000 micro seconds
|
||||
};
|
||||
|
||||
serial_port uart_open(const char* pcPortName) {
|
||||
serial_port_unix* sp = calloc(sizeof(serial_port_unix), sizeof(uint8_t));
|
||||
serial_port uart_open(const char *pcPortName)
|
||||
{
|
||||
serial_port_unix *sp = calloc(sizeof(serial_port_unix), sizeof(uint8_t));
|
||||
if (sp == 0) return INVALID_SERIAL_PORT;
|
||||
|
||||
if (memcmp(pcPortName, "tcp:", 4) == 0) {
|
||||
|
@ -135,7 +136,7 @@ serial_port uart_open(const char* pcPortName) {
|
|||
|
||||
int one = 1;
|
||||
int res = setsockopt(sp->fd, SOL_TCP, TCP_NODELAY, &one, sizeof(one));
|
||||
if ( res != 0) {
|
||||
if (res != 0) {
|
||||
free(sp);
|
||||
return INVALID_SERIAL_PORT;
|
||||
}
|
||||
|
@ -166,7 +167,7 @@ serial_port uart_open(const char* pcPortName) {
|
|||
}
|
||||
|
||||
// Try to retrieve the old (current) terminal info struct
|
||||
if (tcgetattr(sp->fd,&sp->tiOld) == -1) {
|
||||
if (tcgetattr(sp->fd, &sp->tiOld) == -1) {
|
||||
uart_close(sp);
|
||||
return INVALID_SERIAL_PORT;
|
||||
}
|
||||
|
@ -191,11 +192,11 @@ serial_port uart_open(const char* pcPortName) {
|
|||
return INVALID_SERIAL_PORT;
|
||||
}
|
||||
|
||||
// Flush all lingering data that may exist
|
||||
tcflush(sp->fd, TCIOFLUSH);
|
||||
// Flush all lingering data that may exist
|
||||
tcflush(sp->fd, TCIOFLUSH);
|
||||
|
||||
#ifdef WITH_FPC
|
||||
if ( uart_set_speed(sp, 115200) ) {
|
||||
if (uart_set_speed(sp, 115200)) {
|
||||
printf("[=] UART Setting serial baudrate 115200 [FPC enabled]\n");
|
||||
} else {
|
||||
uart_set_speed(sp, 9600);
|
||||
|
@ -214,8 +215,9 @@ serial_port uart_open(const char* pcPortName) {
|
|||
return sp;
|
||||
}
|
||||
|
||||
void uart_close(const serial_port sp) {
|
||||
serial_port_unix* spu = (serial_port_unix*)sp;
|
||||
void uart_close(const serial_port sp)
|
||||
{
|
||||
serial_port_unix *spu = (serial_port_unix *)sp;
|
||||
tcflush(spu->fd, TCIOFLUSH);
|
||||
tcsetattr(spu->fd, TCSANOW, &(spu->tiOld));
|
||||
struct flock fl;
|
||||
|
@ -227,14 +229,15 @@ void uart_close(const serial_port sp) {
|
|||
|
||||
// Does the system allows us to place a lock on this file descriptor
|
||||
int err = fcntl(spu->fd, F_SETLK, &fl);
|
||||
if ( err == -1) {
|
||||
if (err == -1) {
|
||||
//perror("fcntl");
|
||||
}
|
||||
close(spu->fd);
|
||||
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, size_t pszMaxRxLen, size_t *pszRxLen)
|
||||
{
|
||||
int res;
|
||||
int byteCount;
|
||||
fd_set rfds;
|
||||
|
@ -246,9 +249,9 @@ bool uart_receive(const serial_port sp, uint8_t* pbtRx, size_t pszMaxRxLen, size
|
|||
do {
|
||||
// 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, &rfds, NULL, NULL, &tv);
|
||||
res = select(((serial_port_unix *)sp)->fd + 1, &rfds, NULL, NULL, &tv);
|
||||
|
||||
// Read error
|
||||
if (res < 0) {
|
||||
|
@ -267,7 +270,7 @@ bool uart_receive(const serial_port sp, uint8_t* pbtRx, size_t pszMaxRxLen, size
|
|||
}
|
||||
|
||||
// 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);
|
||||
if (res < 0) return false;
|
||||
|
||||
// Cap the number of bytes, so we don't overrun the buffer
|
||||
|
@ -276,7 +279,7 @@ bool uart_receive(const serial_port sp, uint8_t* pbtRx, size_t pszMaxRxLen, size
|
|||
}
|
||||
|
||||
// There is something available, read the data
|
||||
res = read(((serial_port_unix*)sp)->fd, pbtRx + (*pszRxLen), byteCount);
|
||||
res = read(((serial_port_unix *)sp)->fd, pbtRx + (*pszRxLen), byteCount);
|
||||
|
||||
// Stop if the OS has some troubles reading the data
|
||||
if (res <= 0) return false;
|
||||
|
@ -293,7 +296,8 @@ bool uart_receive(const serial_port sp, uint8_t* pbtRx, size_t pszMaxRxLen, size
|
|||
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 size_t len)
|
||||
{
|
||||
int32_t res;
|
||||
size_t pos = 0;
|
||||
fd_set rfds;
|
||||
|
@ -302,9 +306,9 @@ bool uart_send(const serial_port sp, const uint8_t* pbtTx, const size_t len) {
|
|||
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);
|
||||
res = select(((serial_port_unix *)sp)->fd + 1, NULL, &rfds, NULL, &tv);
|
||||
|
||||
// Write error
|
||||
if (res < 0) {
|
||||
|
@ -319,7 +323,7 @@ bool uart_send(const serial_port sp, const uint8_t* pbtTx, const size_t len) {
|
|||
}
|
||||
|
||||
// Send away the bytes
|
||||
res = write(((serial_port_unix*)sp)->fd, pbtTx + pos, len - pos);
|
||||
res = write(((serial_port_unix *)sp)->fd, pbtTx + pos, len - pos);
|
||||
|
||||
// Stop if the OS has some troubles sending the data
|
||||
if (res <= 0) return false;
|
||||
|
@ -329,45 +333,87 @@ bool uart_send(const serial_port sp, const uint8_t* pbtTx, const size_t len) {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool uart_set_speed(serial_port sp, const uint32_t uiPortSpeed) {
|
||||
const serial_port_unix* spu = (serial_port_unix*)sp;
|
||||
bool uart_set_speed(serial_port sp, const uint32_t uiPortSpeed)
|
||||
{
|
||||
const serial_port_unix *spu = (serial_port_unix *)sp;
|
||||
speed_t stPortSpeed;
|
||||
switch (uiPortSpeed) {
|
||||
case 0: stPortSpeed = B0; break;
|
||||
case 50: stPortSpeed = B50; break;
|
||||
case 75: stPortSpeed = B75; break;
|
||||
case 110: stPortSpeed = B110; break;
|
||||
case 134: stPortSpeed = B134; break;
|
||||
case 150: stPortSpeed = B150; break;
|
||||
case 300: stPortSpeed = B300; break;
|
||||
case 600: stPortSpeed = B600; break;
|
||||
case 1200: stPortSpeed = B1200; break;
|
||||
case 1800: stPortSpeed = B1800; break;
|
||||
case 2400: stPortSpeed = B2400; break;
|
||||
case 4800: stPortSpeed = B4800; break;
|
||||
case 9600: stPortSpeed = B9600; break;
|
||||
case 19200: stPortSpeed = B19200; break;
|
||||
case 38400: stPortSpeed = B38400; break;
|
||||
case 0:
|
||||
stPortSpeed = B0;
|
||||
break;
|
||||
case 50:
|
||||
stPortSpeed = B50;
|
||||
break;
|
||||
case 75:
|
||||
stPortSpeed = B75;
|
||||
break;
|
||||
case 110:
|
||||
stPortSpeed = B110;
|
||||
break;
|
||||
case 134:
|
||||
stPortSpeed = B134;
|
||||
break;
|
||||
case 150:
|
||||
stPortSpeed = B150;
|
||||
break;
|
||||
case 300:
|
||||
stPortSpeed = B300;
|
||||
break;
|
||||
case 600:
|
||||
stPortSpeed = B600;
|
||||
break;
|
||||
case 1200:
|
||||
stPortSpeed = B1200;
|
||||
break;
|
||||
case 1800:
|
||||
stPortSpeed = B1800;
|
||||
break;
|
||||
case 2400:
|
||||
stPortSpeed = B2400;
|
||||
break;
|
||||
case 4800:
|
||||
stPortSpeed = B4800;
|
||||
break;
|
||||
case 9600:
|
||||
stPortSpeed = B9600;
|
||||
break;
|
||||
case 19200:
|
||||
stPortSpeed = B19200;
|
||||
break;
|
||||
case 38400:
|
||||
stPortSpeed = B38400;
|
||||
break;
|
||||
# ifdef B57600
|
||||
case 57600: stPortSpeed = B57600; break;
|
||||
case 57600:
|
||||
stPortSpeed = B57600;
|
||||
break;
|
||||
# endif
|
||||
# ifdef B115200
|
||||
case 115200: stPortSpeed = B115200; break;
|
||||
case 115200:
|
||||
stPortSpeed = B115200;
|
||||
break;
|
||||
# endif
|
||||
# ifdef B230400
|
||||
case 230400: stPortSpeed = B230400; break;
|
||||
case 230400:
|
||||
stPortSpeed = B230400;
|
||||
break;
|
||||
# endif
|
||||
# ifdef B460800
|
||||
case 460800: stPortSpeed = B460800; break;
|
||||
case 460800:
|
||||
stPortSpeed = B460800;
|
||||
break;
|
||||
# endif
|
||||
# ifdef B921600
|
||||
case 921600: stPortSpeed = B921600; break;
|
||||
case 921600:
|
||||
stPortSpeed = B921600;
|
||||
break;
|
||||
# endif
|
||||
default: return false;
|
||||
default:
|
||||
return false;
|
||||
};
|
||||
|
||||
struct termios ti;
|
||||
if (tcgetattr(spu->fd,&ti) == -1)
|
||||
if (tcgetattr(spu->fd, &ti) == -1)
|
||||
return false;
|
||||
|
||||
// Set port speed (Input and Output)
|
||||
|
@ -376,10 +422,11 @@ bool uart_set_speed(serial_port sp, const uint32_t uiPortSpeed) {
|
|||
return (tcsetattr(spu->fd, TCSANOW, &ti) != -1);
|
||||
}
|
||||
|
||||
uint32_t uart_get_speed(const serial_port sp) {
|
||||
uint32_t uart_get_speed(const serial_port sp)
|
||||
{
|
||||
struct termios ti;
|
||||
uint32_t uiPortSpeed;
|
||||
const serial_port_unix* spu = (serial_port_unix*)sp;
|
||||
const serial_port_unix *spu = (serial_port_unix *)sp;
|
||||
|
||||
if (tcgetattr(spu->fd, &ti) == -1)
|
||||
return 0;
|
||||
|
@ -387,37 +434,78 @@ uint32_t uart_get_speed(const serial_port sp) {
|
|||
// Set port speed (Input)
|
||||
speed_t stPortSpeed = cfgetispeed(&ti);
|
||||
switch (stPortSpeed) {
|
||||
case B0: uiPortSpeed = 0; break;
|
||||
case B50: uiPortSpeed = 50; break;
|
||||
case B75: uiPortSpeed = 75; break;
|
||||
case B110: uiPortSpeed = 110; break;
|
||||
case B134: uiPortSpeed = 134; break;
|
||||
case B150: uiPortSpeed = 150; break;
|
||||
case B300: uiPortSpeed = 300; break;
|
||||
case B600: uiPortSpeed = 600; break;
|
||||
case B1200: uiPortSpeed = 1200; break;
|
||||
case B1800: uiPortSpeed = 1800; break;
|
||||
case B2400: uiPortSpeed = 2400; break;
|
||||
case B4800: uiPortSpeed = 4800; break;
|
||||
case B9600: uiPortSpeed = 9600; break;
|
||||
case B19200: uiPortSpeed = 19200; break;
|
||||
case B38400: uiPortSpeed = 38400; break;
|
||||
case B0:
|
||||
uiPortSpeed = 0;
|
||||
break;
|
||||
case B50:
|
||||
uiPortSpeed = 50;
|
||||
break;
|
||||
case B75:
|
||||
uiPortSpeed = 75;
|
||||
break;
|
||||
case B110:
|
||||
uiPortSpeed = 110;
|
||||
break;
|
||||
case B134:
|
||||
uiPortSpeed = 134;
|
||||
break;
|
||||
case B150:
|
||||
uiPortSpeed = 150;
|
||||
break;
|
||||
case B300:
|
||||
uiPortSpeed = 300;
|
||||
break;
|
||||
case B600:
|
||||
uiPortSpeed = 600;
|
||||
break;
|
||||
case B1200:
|
||||
uiPortSpeed = 1200;
|
||||
break;
|
||||
case B1800:
|
||||
uiPortSpeed = 1800;
|
||||
break;
|
||||
case B2400:
|
||||
uiPortSpeed = 2400;
|
||||
break;
|
||||
case B4800:
|
||||
uiPortSpeed = 4800;
|
||||
break;
|
||||
case B9600:
|
||||
uiPortSpeed = 9600;
|
||||
break;
|
||||
case B19200:
|
||||
uiPortSpeed = 19200;
|
||||
break;
|
||||
case B38400:
|
||||
uiPortSpeed = 38400;
|
||||
break;
|
||||
# ifdef B57600
|
||||
case B57600: uiPortSpeed = 57600; break;
|
||||
case B57600:
|
||||
uiPortSpeed = 57600;
|
||||
break;
|
||||
# endif
|
||||
# ifdef B115200
|
||||
case B115200: uiPortSpeed = 115200; break;
|
||||
case B115200:
|
||||
uiPortSpeed = 115200;
|
||||
break;
|
||||
# endif
|
||||
# ifdef B230400
|
||||
case B230400: uiPortSpeed = 230400; break;
|
||||
case B230400:
|
||||
uiPortSpeed = 230400;
|
||||
break;
|
||||
# endif
|
||||
# ifdef B460800
|
||||
case B460800: uiPortSpeed = 460800; break;
|
||||
case B460800:
|
||||
uiPortSpeed = 460800;
|
||||
break;
|
||||
# endif
|
||||
# ifdef B921600
|
||||
case B921600: uiPortSpeed = 921600; break;
|
||||
case B921600:
|
||||
uiPortSpeed = 921600;
|
||||
break;
|
||||
# endif
|
||||
default: return 0;
|
||||
default:
|
||||
return 0;
|
||||
};
|
||||
return uiPortSpeed;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue