blob: fcc38e0617f4efa02c53a7f5a496db5ced011809 [file] [log] [blame]
Patrick Williamsb48b7b42016-08-17 15:04:38 -05001From bab595e38295dcafcfc17a011d3d51f2df1618e6 Mon Sep 17 00:00:00 2001
2From: AnilKumar Ch <anilkumar@ti.com>
3Date: Tue, 10 Jan 2012 18:55:11 +0530
4Subject: [PATCH] canutils: candump: Add error frame's handling
5
6This patch adds the error handling capability to candump utility
7by adding error flags for displaying all kind of error frames
8like tx_timeout, lost arbitration, controller problems, buserrors,
9bus warnings etc.
10
11Usage of candump for error frame display on console:
12candump [<can-interface>] [Options]
13Ex: candump can0 --error
14
15This patch is created on top of canutils-4.0.6 tag from
16http://git.pengutronix.de/?p=tools/canutils.git
17
18Signed-off-by: AnilKumar Ch <anilkumar@ti.com>
19Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
20---
21Upstream-Status: Backport
22
23 src/candump.c | 20 ++++++++++++++++++++
24 1 file changed, 20 insertions(+)
25
26diff --git a/src/candump.c b/src/candump.c
27index 259d442..c16425b 100644
28--- a/src/candump.c
29+++ b/src/candump.c
30@@ -20,6 +20,7 @@
31
32 #include <linux/can.h>
33 #include <linux/can/raw.h>
34+#include <linux/can/error.h>
35
36 extern int optind, opterr, optopt;
37
38@@ -40,6 +41,7 @@ static void print_usage(char *prg)
39 " -p, --protocol=PROTO\t" "CAN protocol (default CAN_RAW = %d)\n"
40 " --filter=id:mask[:id:mask]...\n"
41 "\t\t\t" "apply filter\n"
42+ " -e, --error\t\t" "dump error frames along with data frames\n"
43 " -h, --help\t\t" "this help\n"
44 " -o <filename>\t\t" "output into filename\n"
45 " -d\t\t\t" "daemonize\n"
46@@ -86,6 +88,11 @@ int main(int argc, char **argv)
47 int nbytes, i;
48 int opt, optdaemon = 0;
49 uint32_t id, mask;
50+ int error = 0;
51+ can_err_mask_t err_mask = (CAN_ERR_TX_TIMEOUT | CAN_ERR_LOSTARB |
52+ CAN_ERR_CRTL | CAN_ERR_PROT |
53+ CAN_ERR_TRX | CAN_ERR_ACK | CAN_ERR_BUSOFF |
54+ CAN_ERR_BUSERROR);
55
56 signal(SIGPIPE, SIG_IGN);
57
58@@ -95,6 +102,7 @@ int main(int argc, char **argv)
59 { "protocol", required_argument, 0, 'p' },
60 { "type", required_argument, 0, 't' },
61 { "filter", required_argument, 0, FILTER_OPTION },
62+ { "error", no_argument, 0, 'e' },
63 { "version", no_argument, 0, VERSION_OPTION},
64 { 0, 0, 0, 0},
65 };
66@@ -121,6 +129,10 @@ int main(int argc, char **argv)
67 proto = strtoul(optarg, NULL, 0);
68 break;
69
70+ case 'e':
71+ error = 1;
72+ break;
73+
74 case 'o':
75 optout = optarg;
76 break;
77@@ -186,6 +198,14 @@ int main(int argc, char **argv)
78 }
79 }
80
81+ if (error) {
82+ if (setsockopt(s, SOL_CAN_RAW, CAN_RAW_ERR_FILTER, &err_mask,
83+ sizeof(err_mask)) != 0) {
84+ perror("setsockopt");
85+ exit(1);
86+ }
87+ }
88+
89 if (optdaemon)
90 daemon(1, 0);
91 else {
92--
931.8.3.1
94