Merge patch series "can-utils-dev: a set of update and cleanup patches"
Vincent Mailhol <mailhol.vincent@wanadoo.fr> says:
This series contain cleanup patches and update of header files. There
is no real relation between each patch (aside of 2/6 and 3/6 which
form a pair) so I will end the cover letter here and let you refer to
the short description.
* Changelog *
v2 -> v3:
* reorder the patches so that related changes are next to each
other (especially patch 2/6 and 3/6).
* patch 2/6: new patch to update include/linux/can/error.h with the
latest hearder from Linux 6.0.0.
* patch 3/6: do not use an #ifdef anymore and make sure that the
code still work if run on old kernel version lower than 6.0.0.
* patch 6/6: rewrite commit description to point out that there is a
local copy of the linux headers under include/linux/.
v1 -> v2:
* patch 2/5: add a note in commit message to explain that slcanpty.c
debug is deactivated by default.
* patch 2/5: make the compiler check the pr_debug() syntax even if
debug is off.
* reorder the patches so that the lib.c and the candump.c patches
are next to each other in the series.
Link: https://lore.kernel.org/all/20221114163848.3398-1-mailhol.vincent@wanadoo.fr
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
pull/387/head
commit
9177294093
|
|
@ -33,6 +33,7 @@ set(PROGRAMS_CANLIB
|
|||
cansequence
|
||||
log2asc
|
||||
log2long
|
||||
slcanpty
|
||||
)
|
||||
|
||||
set(PROGRAMS_J1939
|
||||
|
|
@ -58,7 +59,6 @@ set(PROGRAMS
|
|||
isotptun
|
||||
slcan_attach
|
||||
slcand
|
||||
slcanpty
|
||||
)
|
||||
|
||||
add_executable(can-calc-bit-timing
|
||||
|
|
|
|||
3
Makefile
3
Makefile
|
|
@ -46,6 +46,7 @@ MAKEFLAGS := -k
|
|||
CFLAGS := -O2 -Wall -Wno-parentheses
|
||||
|
||||
CPPFLAGS += \
|
||||
-I. \
|
||||
-Iinclude \
|
||||
-DAF_CAN=PF_CAN \
|
||||
-DPF_CAN=29 \
|
||||
|
|
@ -119,6 +120,7 @@ canplayer.o: lib.h
|
|||
cansend.o: lib.h
|
||||
log2asc.o: lib.h
|
||||
log2long.o: lib.h
|
||||
slcanpty.o: lib.h
|
||||
j1939acd.o: libj1939.h
|
||||
j1939cat.o: libj1939.h
|
||||
j1939spy.o: libj1939.h
|
||||
|
|
@ -135,6 +137,7 @@ cansend: cansend.o lib.o
|
|||
cansequence: cansequence.o lib.o
|
||||
log2asc: log2asc.o lib.o
|
||||
log2long: log2long.o lib.o
|
||||
slcanpty: slcanpty.o lib.o
|
||||
j1939acd: j1939acd.o libj1939.o
|
||||
j1939cat: j1939cat.o libj1939.o
|
||||
j1939spy: j1939spy.o libj1939.o
|
||||
|
|
|
|||
|
|
@ -61,6 +61,7 @@
|
|||
#include <linux/can.h>
|
||||
#include <linux/can/raw.h>
|
||||
|
||||
#include "lib.h"
|
||||
#include "terminal.h"
|
||||
#include "canframelen.h"
|
||||
|
||||
|
|
@ -310,9 +311,7 @@ int main(int argc, char **argv)
|
|||
return 1;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("open %d '%s'.\n", i, ptr);
|
||||
#endif
|
||||
pr_debug("open %d '%s'.\n", i, ptr);
|
||||
|
||||
s[i] = socket(PF_CAN, SOCK_RAW, CAN_RAW);
|
||||
if (s[i] < 0) {
|
||||
|
|
@ -358,10 +357,8 @@ int main(int argc, char **argv)
|
|||
if (nbytes > max_bitrate_len)
|
||||
max_bitrate_len = nbytes; /* for nice printing */
|
||||
|
||||
pr_debug("using interface name '%s'.\n", ifr.ifr_name);
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("using interface name '%s'.\n", ifr.ifr_name);
|
||||
#endif
|
||||
/* try to switch the socket into CAN FD mode */
|
||||
const int canfd_on = 1;
|
||||
setsockopt(s[i], SOL_CAN_RAW, CAN_RAW_FD_FRAMES, &canfd_on, sizeof(canfd_on));
|
||||
|
|
|
|||
58
candump.c
58
candump.c
|
|
@ -63,6 +63,7 @@
|
|||
|
||||
#include <linux/can.h>
|
||||
#include <linux/can/raw.h>
|
||||
#include <linux/net_tstamp.h>
|
||||
|
||||
#include "terminal.h"
|
||||
#include "lib.h"
|
||||
|
|
@ -72,10 +73,6 @@
|
|||
#define SO_TIMESTAMPING 37
|
||||
#endif
|
||||
|
||||
/* from #include <linux/net_tstamp.h> - since Linux 2.6.30 */
|
||||
#define SOF_TIMESTAMPING_SOFTWARE (1 << 4)
|
||||
#define SOF_TIMESTAMPING_RX_SOFTWARE (1 << 3)
|
||||
#define SOF_TIMESTAMPING_RAW_HARDWARE (1 << 6)
|
||||
#define TIMESTAMPSZ 50 /* string 'absolute with date' requires max 49 bytes */
|
||||
|
||||
#define MAXSOCK 16 /* max. number of CAN interfaces given on the cmdline */
|
||||
|
|
@ -108,6 +105,7 @@ struct if_info { /* bundled information per open socket */
|
|||
};
|
||||
static struct if_info sock_info[MAXSOCK];
|
||||
|
||||
static char *progname;
|
||||
static char devname[MAXIFNAMES][IFNAMSIZ+1];
|
||||
static int dindex[MAXIFNAMES];
|
||||
static int max_devname_len; /* to prevent frazzled device name output */
|
||||
|
|
@ -121,11 +119,11 @@ extern int optind, opterr, optopt;
|
|||
|
||||
static volatile int running = 1;
|
||||
|
||||
static void print_usage(char *prg)
|
||||
static void print_usage(void)
|
||||
{
|
||||
fprintf(stderr, "%s - dump CAN bus traffic.\n", prg);
|
||||
fprintf(stderr, "\nUsage: %s [options] <CAN interface>+\n", prg);
|
||||
fprintf(stderr, " (use CTRL-C to terminate %s)\n\n", prg);
|
||||
fprintf(stderr, "%s - dump CAN bus traffic.\n", progname);
|
||||
fprintf(stderr, "\nUsage: %s [options] <CAN interface>+\n", progname);
|
||||
fprintf(stderr, " (use CTRL-C to terminate %s)\n\n", progname);
|
||||
fprintf(stderr, "Options:\n");
|
||||
fprintf(stderr, " -t <type> (timestamp: (a)bsolute/(d)elta/(z)ero/(A)bsolute w date)\n");
|
||||
fprintf(stderr, " -H (read hardware timestamps instead of system timestamps)\n");
|
||||
|
|
@ -159,12 +157,12 @@ static void print_usage(char *prg)
|
|||
fprintf(stderr, "Without any given filter all data frames are received ('0:0' default filter).\n");
|
||||
fprintf(stderr, "\nUse interface name '%s' to receive from all CAN interfaces.\n", ANYDEV);
|
||||
fprintf(stderr, "\nExamples:\n");
|
||||
fprintf(stderr, "%s -c -c -ta can0,123:7FF,400:700,#000000FF can2,400~7F0 can3 can8\n\n", prg);
|
||||
fprintf(stderr, "%s -l any,0~0,#FFFFFFFF\n (log only error frames but no(!) data frames)\n", prg);
|
||||
fprintf(stderr, "%s -l any,0:0,#FFFFFFFF\n (log error frames and also all data frames)\n", prg);
|
||||
fprintf(stderr, "%s vcan2,12345678:DFFFFFFF\n (match only for extended CAN ID 12345678)\n", prg);
|
||||
fprintf(stderr, "%s vcan2,123:7FF\n (matches CAN ID 123 - including EFF and RTR frames)\n", prg);
|
||||
fprintf(stderr, "%s vcan2,123:C00007FF\n (matches CAN ID 123 - only SFF and non-RTR frames)\n", prg);
|
||||
fprintf(stderr, "%s -c -c -ta can0,123:7FF,400:700,#000000FF can2,400~7F0 can3 can8\n\n", progname);
|
||||
fprintf(stderr, "%s -l any,0~0,#FFFFFFFF\n (log only error frames but no(!) data frames)\n", progname);
|
||||
fprintf(stderr, "%s -l any,0:0,#FFFFFFFF\n (log error frames and also all data frames)\n", progname);
|
||||
fprintf(stderr, "%s vcan2,12345678:DFFFFFFF\n (match only for extended CAN ID 12345678)\n", progname);
|
||||
fprintf(stderr, "%s vcan2,123:7FF\n (matches CAN ID 123 - including EFF and RTR frames)\n", progname);
|
||||
fprintf(stderr, "%s vcan2,123:C00007FF\n (matches CAN ID 123 - only SFF and non-RTR frames)\n", progname);
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
|
||||
|
|
@ -216,9 +214,7 @@ static int idx2dindex(int ifidx, int socket)
|
|||
|
||||
strcpy(devname[i], ifr.ifr_name);
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("new index %d (%s)\n", i, devname[i]);
|
||||
#endif
|
||||
pr_debug("new index %d (%s)\n", i, devname[i]);
|
||||
|
||||
return i;
|
||||
}
|
||||
|
|
@ -327,6 +323,8 @@ int main(int argc, char **argv)
|
|||
last_tv.tv_sec = 0;
|
||||
last_tv.tv_usec = 0;
|
||||
|
||||
progname = basename(argv[0]);
|
||||
|
||||
while ((opt = getopt(argc, argv, "t:HciaSs:lDdxLf:n:r:he8T:?")) != -1) {
|
||||
switch (opt) {
|
||||
case 't':
|
||||
|
|
@ -335,7 +333,7 @@ int main(int argc, char **argv)
|
|||
if ((timestamp != 'a') && (timestamp != 'A') &&
|
||||
(timestamp != 'd') && (timestamp != 'z')) {
|
||||
fprintf(stderr, "%s: unknown timestamp mode '%c' - ignored\n",
|
||||
basename(argv[0]), optarg[0]);
|
||||
progname, optarg[0]);
|
||||
timestamp = 0;
|
||||
}
|
||||
if ((logtimestamp != 'a') && (logtimestamp != 'z')) {
|
||||
|
|
@ -374,7 +372,7 @@ int main(int argc, char **argv)
|
|||
case 's':
|
||||
silent = atoi(optarg);
|
||||
if (silent > SILENT_ON) {
|
||||
print_usage(basename(argv[0]));
|
||||
print_usage();
|
||||
exit(1);
|
||||
}
|
||||
break;
|
||||
|
|
@ -407,7 +405,7 @@ int main(int argc, char **argv)
|
|||
case 'n':
|
||||
count = atoi(optarg);
|
||||
if (count < 1) {
|
||||
print_usage(basename(argv[0]));
|
||||
print_usage();
|
||||
exit(1);
|
||||
}
|
||||
break;
|
||||
|
|
@ -415,7 +413,7 @@ int main(int argc, char **argv)
|
|||
case 'r':
|
||||
rcvbuf_size = atoi(optarg);
|
||||
if (rcvbuf_size < 1) {
|
||||
print_usage(basename(argv[0]));
|
||||
print_usage();
|
||||
exit(1);
|
||||
}
|
||||
break;
|
||||
|
|
@ -424,19 +422,19 @@ int main(int argc, char **argv)
|
|||
errno = 0;
|
||||
timeout_ms = strtol(optarg, NULL, 0);
|
||||
if (errno != 0) {
|
||||
print_usage(basename(argv[0]));
|
||||
print_usage();
|
||||
exit(1);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
print_usage(basename(argv[0]));
|
||||
print_usage();
|
||||
exit(1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (optind == argc) {
|
||||
print_usage(basename(argv[0]));
|
||||
print_usage();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
|
@ -477,9 +475,7 @@ int main(int argc, char **argv)
|
|||
ptr = argv[optind+i];
|
||||
nptr = strchr(ptr, ',');
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("open %d '%s'.\n", i, ptr);
|
||||
#endif
|
||||
pr_debug("open %d '%s'.\n", i, ptr);
|
||||
|
||||
obj->s = socket(PF_CAN, SOCK_RAW, CAN_RAW);
|
||||
if (obj->s < 0) {
|
||||
|
|
@ -513,9 +509,7 @@ int main(int argc, char **argv)
|
|||
memset(&ifr.ifr_name, 0, sizeof(ifr.ifr_name));
|
||||
strncpy(ifr.ifr_name, ptr, nbytes);
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("using interface name '%s'.\n", ifr.ifr_name);
|
||||
#endif
|
||||
pr_debug("using interface name '%s'.\n", ifr.ifr_name);
|
||||
|
||||
if (strcmp(ANYDEV, ifr.ifr_name) != 0) {
|
||||
if (ioctl(obj->s, SIOCGIFINDEX, &ifr) < 0) {
|
||||
|
|
@ -605,9 +599,7 @@ int main(int argc, char **argv)
|
|||
/* try SO_RCVBUFFORCE first, if we run with CAP_NET_ADMIN */
|
||||
if (setsockopt(obj->s, SOL_SOCKET, SO_RCVBUFFORCE,
|
||||
&rcvbuf_size, sizeof(rcvbuf_size)) < 0) {
|
||||
#ifdef DEBUG
|
||||
printf("SO_RCVBUFFORCE failed so try SO_RCVBUF ...\n");
|
||||
#endif
|
||||
pr_debug("SO_RCVBUFFORCE failed so try SO_RCVBUF ...\n");
|
||||
if (setsockopt(obj->s, SOL_SOCKET, SO_RCVBUF,
|
||||
&rcvbuf_size, sizeof(rcvbuf_size)) < 0) {
|
||||
perror("setsockopt SO_RCVBUF");
|
||||
|
|
|
|||
|
|
@ -145,9 +145,7 @@ int idx2dindex(int ifidx, int socket)
|
|||
|
||||
strcpy(devname[i], ifr.ifr_name);
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("new index %d (%s)\n", i, devname[i]);
|
||||
#endif
|
||||
pr_debug("new index %d (%s)\n", i, devname[i]);
|
||||
|
||||
return i;
|
||||
}
|
||||
|
|
@ -310,11 +308,9 @@ int main(int argc, char **argv)
|
|||
|
||||
for (i=0; i<currmax; i++) {
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("open %d '%s' m%08X v%08X i%d e%d.\n",
|
||||
i, argv[optind+i], mask[i], value[i],
|
||||
inv_filter[i], err_mask[i]);
|
||||
#endif
|
||||
pr_debug("open %d '%s' m%08X v%08X i%d e%d.\n",
|
||||
i, argv[optind+i], mask[i], value[i],
|
||||
inv_filter[i], err_mask[i]);
|
||||
|
||||
if ((s[i] = socket(PF_CAN, SOCK_RAW, CAN_RAW)) < 0) {
|
||||
perror("socket");
|
||||
|
|
|
|||
|
|
@ -57,6 +57,8 @@
|
|||
#define CAN_ERR_BUSOFF 0x00000040U /* bus off */
|
||||
#define CAN_ERR_BUSERROR 0x00000080U /* bus error (may flood!) */
|
||||
#define CAN_ERR_RESTARTED 0x00000100U /* controller restarted */
|
||||
#define CAN_ERR_CNT 0x00000200U /* TX error counter / data[6] */
|
||||
/* RX error counter / data[7] */
|
||||
|
||||
/* arbitration lost in bit ... / data[0] */
|
||||
#define CAN_ERR_LOSTARB_UNSPEC 0x00 /* unspecified */
|
||||
|
|
@ -120,6 +122,22 @@
|
|||
#define CAN_ERR_TRX_CANL_SHORT_TO_GND 0x70 /* 0111 0000 */
|
||||
#define CAN_ERR_TRX_CANL_SHORT_TO_CANH 0x80 /* 1000 0000 */
|
||||
|
||||
/* controller specific additional information / data[5..7] */
|
||||
/* data[5] is reserved (do not use) */
|
||||
|
||||
/* TX error counter / data[6] */
|
||||
/* RX error counter / data[7] */
|
||||
|
||||
/* CAN state thresholds
|
||||
*
|
||||
* Error counter Error state
|
||||
* -----------------------------------
|
||||
* 0 - 95 Error-active
|
||||
* 96 - 127 Error-warning
|
||||
* 128 - 255 Error-passive
|
||||
* 256 and greater Bus-off
|
||||
*/
|
||||
#define CAN_ERROR_WARNING_THRESHOLD 96
|
||||
#define CAN_ERROR_PASSIVE_THRESHOLD 128
|
||||
#define CAN_BUS_OFF_THRESHOLD 256
|
||||
|
||||
#endif /* _UAPI_CAN_ERROR_H */
|
||||
|
|
|
|||
2
lib.c
2
lib.c
|
|
@ -680,7 +680,7 @@ void snprintf_can_error_frame(char *buf, size_t len, const struct canfd_frame *c
|
|||
}
|
||||
}
|
||||
|
||||
if (cf->data[6] || cf->data[7]) {
|
||||
if (cf->can_id & CAN_ERR_CNT || cf->data[6] || cf->data[7]) {
|
||||
n += snprintf(buf + n, len - n, "%s", sep);
|
||||
n += snprintf(buf + n, len - n, "error-counter-tx-rx{{%d}{%d}}",
|
||||
cf->data[6], cf->data[7]);
|
||||
|
|
|
|||
7
lib.h
7
lib.h
|
|
@ -47,6 +47,13 @@
|
|||
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef DEBUG
|
||||
#define pr_debug(fmt, args...) printf(fmt, ##args)
|
||||
#else
|
||||
__attribute__((format (printf, 1, 2)))
|
||||
static inline int pr_debug(const char* fmt, ...) {return 0;}
|
||||
#endif
|
||||
|
||||
/* buffer sizes for CAN frame string representations */
|
||||
|
||||
#define CL_ID (sizeof("12345678##1"))
|
||||
|
|
|
|||
|
|
@ -17,18 +17,10 @@
|
|||
|
||||
#include <linux/kernel.h>
|
||||
|
||||
#include "lib.h"
|
||||
#include "mcp251xfd.h"
|
||||
#include "mcp251xfd-dump-userspace.h"
|
||||
|
||||
#define pr_err(fmt, args...) fprintf(stderr, fmt, ##args)
|
||||
#define pr_no(fmt, args...) while (0) { fprintf(stdout, fmt, ##args); }
|
||||
|
||||
#ifdef DEBUG
|
||||
#define pr_debug(fmt, args...) pr_err(fmt, ##args)
|
||||
#else
|
||||
#define pr_debug(fmt, args...) pr_no(fmt, ##args)
|
||||
#endif
|
||||
|
||||
|
||||
struct mcp251xfd_dump_iter {
|
||||
const void *start;
|
||||
|
|
|
|||
27
slcanpty.c
27
slcanpty.c
|
|
@ -43,27 +43,12 @@
|
|||
#include <linux/can/raw.h>
|
||||
#include <linux/sockios.h>
|
||||
|
||||
#include "lib.h"
|
||||
|
||||
/* maximum rx buffer len: extended CAN frame with timestamp */
|
||||
#define SLC_MTU (sizeof("T1111222281122334455667788EA5F\r")+1)
|
||||
#define DEVICE_NAME_PTMX "/dev/ptmx"
|
||||
|
||||
#define DEBUG
|
||||
|
||||
static int asc2nibble(char c)
|
||||
{
|
||||
|
||||
if ((c >= '0') && (c <= '9'))
|
||||
return c - '0';
|
||||
|
||||
if ((c >= 'A') && (c <= 'F'))
|
||||
return c - 'A' + 10;
|
||||
|
||||
if ((c >= 'a') && (c <= 'f'))
|
||||
return c - 'a' + 10;
|
||||
|
||||
return 16; /* error */
|
||||
}
|
||||
|
||||
/* 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)
|
||||
|
|
@ -119,14 +104,12 @@ rx_restart:
|
|||
cmd = buf[0];
|
||||
buf[nbytes] = 0;
|
||||
|
||||
#ifdef DEBUG
|
||||
for (tmp = 0; tmp < nbytes; tmp++)
|
||||
if (buf[tmp] == '\r')
|
||||
putchar('@');
|
||||
pr_debug("@");
|
||||
else
|
||||
putchar(buf[tmp]);
|
||||
printf("\n");
|
||||
#endif
|
||||
pr_debug("%c", buf[tmp]);
|
||||
pr_debug("\n");
|
||||
|
||||
/* check for filter configuration commands */
|
||||
if (cmd == 'm' || cmd == 'M') {
|
||||
|
|
|
|||
Loading…
Reference in New Issue