slcanpty: convert towards kernel coding style

pull/499/head
Marc Kleine-Budde 2024-02-19 08:45:55 +01:00
parent 4c2f81f790
commit 7683efab41
1 changed files with 31 additions and 48 deletions

View File

@ -50,8 +50,7 @@
#define DEVICE_NAME_PTMX "/dev/ptmx"
/* read data from pty, send CAN frames to CAN socket and answer commands */
int pty2can(int pty, int socket, struct can_filter *fi,
int *is_open, int *tstamp)
int pty2can(int pty, int socket, struct can_filter *fi, int *is_open, int *tstamp)
{
unsigned int nbytes;
char cmd;
@ -137,7 +136,6 @@ rx_restart:
goto rx_out_ack;
}
/* check for timestamp on/off command */
if (cmd == 'Z') {
*tstamp = buf[1] & 0x01;
@ -147,9 +145,7 @@ rx_restart:
/* check for 'O'pen command */
if (cmd == 'O') {
setsockopt(socket, SOL_CAN_RAW,
CAN_RAW_FILTER, fi,
sizeof(struct can_filter));
setsockopt(socket, SOL_CAN_RAW, CAN_RAW_FILTER, fi, sizeof(struct can_filter));
ptr = 1;
*is_open = 1;
goto rx_out_ack;
@ -157,8 +153,7 @@ rx_restart:
/* check for 'C'lose command */
if (cmd == 'C') {
setsockopt(socket, SOL_CAN_RAW, CAN_RAW_FILTER,
NULL, 0);
setsockopt(socket, SOL_CAN_RAW, CAN_RAW_FILTER, NULL, 0);
ptr = 1;
*is_open = 0;
goto rx_out_ack;
@ -221,8 +216,7 @@ rx_restart:
}
/* catch unknown commands */
if ((cmd != 't') && (cmd != 'T') &&
(cmd != 'r') && (cmd != 'R')) {
if ((cmd != 't') && (cmd != 'T') && (cmd != 'r') && (cmd != 'R')) {
ptr = nbytes - 1;
goto rx_out_nack;
}
@ -235,7 +229,6 @@ rx_restart:
memset(&frame.data, 0, 8); /* clear data[] */
if ((cmd | 0x20) == 'r' && buf[ptr] != '0') {
/*
* RTR frame without dlc information!
* This is against the SLCAN spec but sent
@ -258,7 +251,6 @@ rx_restart:
ptr--; /* we have no dlc component in the violation case */
} else {
if (!(buf[ptr] >= '0' && buf[ptr] < '9'))
goto rx_out_nack;
@ -275,7 +267,6 @@ rx_restart:
frame.can_id |= CAN_RTR_FLAG;
for (i = 0, ptr++; i < frame.can_dlc; i++) {
tmp = asc2nibble(buf[ptr++]);
if (tmp > 0x0F)
goto rx_out_nack;
@ -344,19 +335,14 @@ int can2pty(int pty, int socket, int *tstamp)
cmd = 'T'; /* becomes 't' in SFF format */
if (frame.can_id & CAN_EFF_FLAG)
sprintf(buf, "%c%08X%d", cmd,
frame.can_id & CAN_EFF_MASK,
frame.can_dlc);
sprintf(buf, "%c%08X%d", cmd, frame.can_id & CAN_EFF_MASK, frame.can_dlc);
else
sprintf(buf, "%c%03X%d", cmd | 0x20,
frame.can_id & CAN_SFF_MASK,
frame.can_dlc);
sprintf(buf, "%c%03X%d", cmd | 0x20, frame.can_id & CAN_SFF_MASK, frame.can_dlc);
ptr = strlen(buf);
for (i = 0; i < frame.can_dlc; i++)
sprintf(&buf[ptr + 2*i], "%02X",
frame.data[i]);
sprintf(&buf[ptr + 2 * i], "%02X", frame.data[i]);
if (*tstamp) {
struct timeval tv;
@ -447,15 +433,13 @@ int main(int argc, char **argv)
}
/* disable local echo which would cause double frames */
topts.c_lflag &= ~(ICANON | ECHO | ECHOE | ECHOK |
ECHONL | ECHOPRT | ECHOKE);
topts.c_lflag &= ~(ICANON | ECHO | ECHOE | ECHOK | ECHONL | ECHOPRT | ECHOKE);
topts.c_iflag &= ~(ICRNL);
topts.c_iflag |= INLCR;
tcsetattr(p, TCSANOW, &topts);
/* Support for the Unix 98 pseudo-terminal interface /dev/ptmx /dev/pts/N */
if (strcmp(argv[1], DEVICE_NAME_PTMX) == 0) {
char *name_pts = NULL; /* slave pseudo-terminal device name */
if (grantpt(p) < 0) {
@ -503,7 +487,6 @@ int main(int argc, char **argv)
fi.can_mask = 0;
while (running) {
FD_ZERO(&rdfs);
if (select_stdin)