Wolfgang Grandegger | 5a20447 | 2009-05-12 11:42:50 +0200 | [diff] [blame] | 1 | /* |
| 2 | * iplink_can.c CAN device support |
| 3 | * |
Oliver Hartkopp | 3bbff7d | 2014-04-23 19:27:26 +0200 | [diff] [blame] | 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; either version |
| 7 | * 2 of the License, or (at your option) any later version. |
Wolfgang Grandegger | 5a20447 | 2009-05-12 11:42:50 +0200 | [diff] [blame] | 8 | * |
Oliver Hartkopp | 3bbff7d | 2014-04-23 19:27:26 +0200 | [diff] [blame] | 9 | * Authors: Wolfgang Grandegger <wg@grandegger.com> |
Wolfgang Grandegger | 5a20447 | 2009-05-12 11:42:50 +0200 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | #include <stdio.h> |
| 13 | #include <stdlib.h> |
| 14 | #include <string.h> |
| 15 | |
| 16 | #include <linux/can/netlink.h> |
| 17 | |
| 18 | #include "rt_names.h" |
| 19 | #include "utils.h" |
| 20 | #include "ip_common.h" |
| 21 | |
vadimk | 561e650 | 2014-09-30 08:17:31 +0300 | [diff] [blame] | 22 | static void print_usage(FILE *f) |
Wolfgang Grandegger | 5a20447 | 2009-05-12 11:42:50 +0200 | [diff] [blame] | 23 | { |
vadimk | 561e650 | 2014-09-30 08:17:31 +0300 | [diff] [blame] | 24 | fprintf(f, |
Wolfgang Grandegger | 5a20447 | 2009-05-12 11:42:50 +0200 | [diff] [blame] | 25 | "Usage: ip link set DEVICE type can\n" |
Oliver Hartkopp | 3bbff7d | 2014-04-23 19:27:26 +0200 | [diff] [blame] | 26 | "\t[ bitrate BITRATE [ sample-point SAMPLE-POINT] ] | \n" |
| 27 | "\t[ tq TQ prop-seg PROP_SEG phase-seg1 PHASE-SEG1\n " |
Wolfgang Grandegger | 5a20447 | 2009-05-12 11:42:50 +0200 | [diff] [blame] | 28 | "\t phase-seg2 PHASE-SEG2 [ sjw SJW ] ]\n" |
| 29 | "\n" |
Oliver Hartkopp | 2bfe047 | 2014-04-23 19:27:27 +0200 | [diff] [blame] | 30 | "\t[ dbitrate BITRATE [ dsample-point SAMPLE-POINT] ] | \n" |
| 31 | "\t[ dtq TQ dprop-seg PROP_SEG dphase-seg1 PHASE-SEG1\n " |
| 32 | "\t dphase-seg2 PHASE-SEG2 [ dsjw SJW ] ]\n" |
| 33 | "\n" |
Oliver Hartkopp | 3bbff7d | 2014-04-23 19:27:26 +0200 | [diff] [blame] | 34 | "\t[ loopback { on | off } ]\n" |
| 35 | "\t[ listen-only { on | off } ]\n" |
| 36 | "\t[ triple-sampling { on | off } ]\n" |
| 37 | "\t[ one-shot { on | off } ]\n" |
| 38 | "\t[ berr-reporting { on | off } ]\n" |
Oliver Hartkopp | 2bfe047 | 2014-04-23 19:27:27 +0200 | [diff] [blame] | 39 | "\t[ fd { on | off } ]\n" |
Nikita Edward Baruzdin | d26caee | 2014-12-05 11:41:42 +0300 | [diff] [blame^] | 40 | "\t[ presume-ack { on | off } ]\n" |
Wolfgang Grandegger | 5a20447 | 2009-05-12 11:42:50 +0200 | [diff] [blame] | 41 | "\n" |
Oliver Hartkopp | 3bbff7d | 2014-04-23 19:27:26 +0200 | [diff] [blame] | 42 | "\t[ restart-ms TIME-MS ]\n" |
| 43 | "\t[ restart ]\n" |
Wolfgang Grandegger | 5a20447 | 2009-05-12 11:42:50 +0200 | [diff] [blame] | 44 | "\n" |
Oliver Hartkopp | 3bbff7d | 2014-04-23 19:27:26 +0200 | [diff] [blame] | 45 | "\tWhere: BITRATE := { 1..1000000 }\n" |
| 46 | "\t SAMPLE-POINT := { 0.000..0.999 }\n" |
| 47 | "\t TQ := { NUMBER }\n" |
| 48 | "\t PROP-SEG := { 1..8 }\n" |
| 49 | "\t PHASE-SEG1 := { 1..8 }\n" |
| 50 | "\t PHASE-SEG2 := { 1..8 }\n" |
| 51 | "\t SJW := { 1..4 }\n" |
| 52 | "\t RESTART-MS := { 0 | NUMBER }\n" |
Wolfgang Grandegger | 5a20447 | 2009-05-12 11:42:50 +0200 | [diff] [blame] | 53 | ); |
| 54 | } |
| 55 | |
vadimk | 561e650 | 2014-09-30 08:17:31 +0300 | [diff] [blame] | 56 | static void usage(void) |
| 57 | { |
| 58 | print_usage(stderr); |
| 59 | } |
| 60 | |
Wolfgang Grandegger | 5a20447 | 2009-05-12 11:42:50 +0200 | [diff] [blame] | 61 | static int get_float(float *val, const char *arg) |
| 62 | { |
| 63 | float res; |
| 64 | char *ptr; |
| 65 | |
| 66 | if (!arg || !*arg) |
| 67 | return -1; |
| 68 | res = strtof(arg, &ptr); |
| 69 | if (!ptr || ptr == arg || *ptr) |
| 70 | return -1; |
| 71 | *val = res; |
| 72 | return 0; |
| 73 | } |
| 74 | |
| 75 | static void set_ctrlmode(char* name, char *arg, |
| 76 | struct can_ctrlmode *cm, __u32 flags) |
| 77 | { |
| 78 | if (strcmp(arg, "on") == 0) { |
| 79 | cm->flags |= flags; |
| 80 | } else if (strcmp(arg, "off") != 0) { |
| 81 | fprintf(stderr, |
Kees van Reeuwijk | 14645ec | 2013-02-08 03:32:36 +0000 | [diff] [blame] | 82 | "Error: argument of \"%s\" must be \"on\" or \"off\", not \"%s\"\n", |
| 83 | name, arg); |
Wolfgang Grandegger | 5a20447 | 2009-05-12 11:42:50 +0200 | [diff] [blame] | 84 | exit(-1); |
| 85 | } |
| 86 | cm->mask |= flags; |
| 87 | } |
| 88 | |
| 89 | static void print_ctrlmode(FILE *f, __u32 cm) |
| 90 | { |
| 91 | fprintf(f, "<"); |
| 92 | #define _PF(cmflag, cmname) \ |
| 93 | if (cm & cmflag) { \ |
| 94 | cm &= ~cmflag; \ |
| 95 | fprintf(f, "%s%s", cmname, cm ? "," : ""); \ |
| 96 | } |
| 97 | _PF(CAN_CTRLMODE_LOOPBACK, "LOOPBACK"); |
| 98 | _PF(CAN_CTRLMODE_LISTENONLY, "LISTEN-ONLY"); |
| 99 | _PF(CAN_CTRLMODE_3_SAMPLES, "TRIPLE-SAMPLING"); |
Wolfgang Grandegger | 8a51794 | 2010-02-22 22:24:55 +0000 | [diff] [blame] | 100 | _PF(CAN_CTRLMODE_ONE_SHOT, "ONE-SHOT"); |
| 101 | _PF(CAN_CTRLMODE_BERR_REPORTING, "BERR-REPORTING"); |
Oliver Hartkopp | 2bfe047 | 2014-04-23 19:27:27 +0200 | [diff] [blame] | 102 | _PF(CAN_CTRLMODE_FD, "FD"); |
Nikita Edward Baruzdin | d26caee | 2014-12-05 11:41:42 +0300 | [diff] [blame^] | 103 | _PF(CAN_CTRLMODE_PRESUME_ACK, "PRESUME-ACK"); |
Wolfgang Grandegger | 5a20447 | 2009-05-12 11:42:50 +0200 | [diff] [blame] | 104 | #undef _PF |
| 105 | if (cm) |
| 106 | fprintf(f, "%x", cm); |
| 107 | fprintf(f, "> "); |
| 108 | } |
| 109 | |
| 110 | static int can_parse_opt(struct link_util *lu, int argc, char **argv, |
| 111 | struct nlmsghdr *n) |
| 112 | { |
Oliver Hartkopp | 2bfe047 | 2014-04-23 19:27:27 +0200 | [diff] [blame] | 113 | struct can_bittiming bt, dbt; |
Wolfgang Grandegger | 5a20447 | 2009-05-12 11:42:50 +0200 | [diff] [blame] | 114 | struct can_ctrlmode cm = {0, 0}; |
| 115 | |
| 116 | memset(&bt, 0, sizeof(bt)); |
Oliver Hartkopp | 2bfe047 | 2014-04-23 19:27:27 +0200 | [diff] [blame] | 117 | memset(&dbt, 0, sizeof(dbt)); |
Wolfgang Grandegger | 5a20447 | 2009-05-12 11:42:50 +0200 | [diff] [blame] | 118 | while (argc > 0) { |
| 119 | if (matches(*argv, "bitrate") == 0) { |
| 120 | NEXT_ARG(); |
| 121 | if (get_u32(&bt.bitrate, *argv, 0)) |
| 122 | invarg("invalid \"bitrate\" value\n", *argv); |
| 123 | } else if (matches(*argv, "sample-point") == 0) { |
| 124 | float sp; |
| 125 | |
| 126 | NEXT_ARG(); |
| 127 | if (get_float(&sp, *argv)) |
| 128 | invarg("invalid \"sample-point\" value\n", |
| 129 | *argv); |
| 130 | bt.sample_point = (__u32)(sp * 1000); |
| 131 | } else if (matches(*argv, "tq") == 0) { |
| 132 | NEXT_ARG(); |
| 133 | if (get_u32(&bt.tq, *argv, 0)) |
| 134 | invarg("invalid \"tq\" value\n", *argv); |
| 135 | } else if (matches(*argv, "prop-seg") == 0) { |
| 136 | NEXT_ARG(); |
| 137 | if (get_u32(&bt.prop_seg, *argv, 0)) |
| 138 | invarg("invalid \"prop-seg\" value\n", *argv); |
| 139 | } else if (matches(*argv, "phase-seg1") == 0) { |
| 140 | NEXT_ARG(); |
| 141 | if (get_u32(&bt.phase_seg1, *argv, 0)) |
| 142 | invarg("invalid \"phase-seg1\" value\n", *argv); |
| 143 | } else if (matches(*argv, "phase-seg2") == 0) { |
| 144 | NEXT_ARG(); |
| 145 | if (get_u32(&bt.phase_seg2, *argv, 0)) |
| 146 | invarg("invalid \"phase-seg2\" value\n", *argv); |
| 147 | } else if (matches(*argv, "sjw") == 0) { |
| 148 | NEXT_ARG(); |
| 149 | if (get_u32(&bt.sjw, *argv, 0)) |
| 150 | invarg("invalid \"sjw\" value\n", *argv); |
Oliver Hartkopp | 2bfe047 | 2014-04-23 19:27:27 +0200 | [diff] [blame] | 151 | } else if (matches(*argv, "dbitrate") == 0) { |
| 152 | NEXT_ARG(); |
| 153 | if (get_u32(&dbt.bitrate, *argv, 0)) |
| 154 | invarg("invalid \"dbitrate\" value\n", *argv); |
| 155 | } else if (matches(*argv, "dsample-point") == 0) { |
| 156 | float sp; |
| 157 | |
| 158 | NEXT_ARG(); |
| 159 | if (get_float(&sp, *argv)) |
| 160 | invarg("invalid \"dsample-point\" value\n", *argv); |
| 161 | dbt.sample_point = (__u32)(sp * 1000); |
| 162 | } else if (matches(*argv, "dtq") == 0) { |
| 163 | NEXT_ARG(); |
| 164 | if (get_u32(&dbt.tq, *argv, 0)) |
| 165 | invarg("invalid \"dtq\" value\n", *argv); |
| 166 | } else if (matches(*argv, "dprop-seg") == 0) { |
| 167 | NEXT_ARG(); |
| 168 | if (get_u32(&dbt.prop_seg, *argv, 0)) |
| 169 | invarg("invalid \"dprop-seg\" value\n", *argv); |
| 170 | } else if (matches(*argv, "dphase-seg1") == 0) { |
| 171 | NEXT_ARG(); |
| 172 | if (get_u32(&dbt.phase_seg1, *argv, 0)) |
| 173 | invarg("invalid \"dphase-seg1\" value\n", *argv); |
| 174 | } else if (matches(*argv, "dphase-seg2") == 0) { |
| 175 | NEXT_ARG(); |
| 176 | if (get_u32(&dbt.phase_seg2, *argv, 0)) |
| 177 | invarg("invalid \"dphase-seg2\" value\n", *argv); |
| 178 | } else if (matches(*argv, "dsjw") == 0) { |
| 179 | NEXT_ARG(); |
| 180 | if (get_u32(&dbt.sjw, *argv, 0)) |
| 181 | invarg("invalid \"dsjw\" value\n", *argv); |
Wolfgang Grandegger | 5a20447 | 2009-05-12 11:42:50 +0200 | [diff] [blame] | 182 | } else if (matches(*argv, "loopback") == 0) { |
| 183 | NEXT_ARG(); |
| 184 | set_ctrlmode("loopback", *argv, &cm, |
| 185 | CAN_CTRLMODE_LOOPBACK); |
| 186 | } else if (matches(*argv, "listen-only") == 0) { |
| 187 | NEXT_ARG(); |
| 188 | set_ctrlmode("listen-only", *argv, &cm, |
| 189 | CAN_CTRLMODE_LISTENONLY); |
| 190 | } else if (matches(*argv, "triple-sampling") == 0) { |
| 191 | NEXT_ARG(); |
| 192 | set_ctrlmode("triple-sampling", *argv, &cm, |
| 193 | CAN_CTRLMODE_3_SAMPLES); |
Wolfgang Grandegger | 8a51794 | 2010-02-22 22:24:55 +0000 | [diff] [blame] | 194 | } else if (matches(*argv, "one-shot") == 0) { |
| 195 | NEXT_ARG(); |
| 196 | set_ctrlmode("one-shot", *argv, &cm, |
| 197 | CAN_CTRLMODE_ONE_SHOT); |
| 198 | } else if (matches(*argv, "berr-reporting") == 0) { |
| 199 | NEXT_ARG(); |
| 200 | set_ctrlmode("berr-reporting", *argv, &cm, |
| 201 | CAN_CTRLMODE_BERR_REPORTING); |
Oliver Hartkopp | 2bfe047 | 2014-04-23 19:27:27 +0200 | [diff] [blame] | 202 | } else if (matches(*argv, "fd") == 0) { |
| 203 | NEXT_ARG(); |
| 204 | set_ctrlmode("fd", *argv, &cm, |
| 205 | CAN_CTRLMODE_FD); |
Nikita Edward Baruzdin | d26caee | 2014-12-05 11:41:42 +0300 | [diff] [blame^] | 206 | } else if (matches(*argv, "presume-ack") == 0) { |
| 207 | NEXT_ARG(); |
| 208 | set_ctrlmode("presume-ack", *argv, &cm, |
| 209 | CAN_CTRLMODE_PRESUME_ACK); |
Wolfgang Grandegger | 5a20447 | 2009-05-12 11:42:50 +0200 | [diff] [blame] | 210 | } else if (matches(*argv, "restart") == 0) { |
| 211 | __u32 val = 1; |
| 212 | |
| 213 | addattr32(n, 1024, IFLA_CAN_RESTART, val); |
| 214 | } else if (matches(*argv, "restart-ms") == 0) { |
| 215 | __u32 val; |
| 216 | |
| 217 | NEXT_ARG(); |
| 218 | if (get_u32(&val, *argv, 0)) |
| 219 | invarg("invalid \"restart-ms\" value\n", *argv); |
| 220 | addattr32(n, 1024, IFLA_CAN_RESTART_MS, val); |
| 221 | } else if (matches(*argv, "help") == 0) { |
| 222 | usage(); |
| 223 | return -1; |
| 224 | } else { |
Kees van Reeuwijk | 14645ec | 2013-02-08 03:32:36 +0000 | [diff] [blame] | 225 | fprintf(stderr, "can: unknown option \"%s\"\n", *argv); |
Wolfgang Grandegger | 5a20447 | 2009-05-12 11:42:50 +0200 | [diff] [blame] | 226 | usage(); |
| 227 | return -1; |
| 228 | } |
| 229 | argc--, argv++; |
| 230 | } |
| 231 | |
| 232 | if (bt.bitrate || bt.tq) |
| 233 | addattr_l(n, 1024, IFLA_CAN_BITTIMING, &bt, sizeof(bt)); |
Oliver Hartkopp | 2bfe047 | 2014-04-23 19:27:27 +0200 | [diff] [blame] | 234 | if (dbt.bitrate || dbt.tq) |
| 235 | addattr_l(n, 1024, IFLA_CAN_DATA_BITTIMING, &dbt, sizeof(dbt)); |
Wolfgang Grandegger | 5a20447 | 2009-05-12 11:42:50 +0200 | [diff] [blame] | 236 | if (cm.mask) |
| 237 | addattr_l(n, 1024, IFLA_CAN_CTRLMODE, &cm, sizeof(cm)); |
| 238 | |
| 239 | return 0; |
| 240 | } |
| 241 | |
| 242 | static const char *can_state_names[] = { |
Oliver Hartkopp | 3bbff7d | 2014-04-23 19:27:26 +0200 | [diff] [blame] | 243 | [CAN_STATE_ERROR_ACTIVE] = "ERROR-ACTIVE", |
| 244 | [CAN_STATE_ERROR_WARNING] = "ERROR-WARNING", |
| 245 | [CAN_STATE_ERROR_PASSIVE] = "ERROR-PASSIVE", |
| 246 | [CAN_STATE_BUS_OFF] = "BUS-OFF", |
| 247 | [CAN_STATE_STOPPED] = "STOPPED", |
| 248 | [CAN_STATE_SLEEPING] = "SLEEPING" |
Wolfgang Grandegger | 5a20447 | 2009-05-12 11:42:50 +0200 | [diff] [blame] | 249 | }; |
| 250 | |
| 251 | static void can_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) |
| 252 | { |
| 253 | if (!tb) |
| 254 | return; |
| 255 | |
| 256 | if (tb[IFLA_CAN_CTRLMODE]) { |
| 257 | struct can_ctrlmode *cm = RTA_DATA(tb[IFLA_CAN_CTRLMODE]); |
| 258 | |
| 259 | if (cm->flags) |
| 260 | print_ctrlmode(f, cm->flags); |
| 261 | } |
| 262 | |
| 263 | if (tb[IFLA_CAN_STATE]) { |
| 264 | int *state = RTA_DATA(tb[IFLA_CAN_STATE]); |
| 265 | |
| 266 | fprintf(f, "state %s ", *state <= CAN_STATE_MAX ? |
| 267 | can_state_names[*state] : "UNKNOWN"); |
| 268 | } |
| 269 | |
Wolfgang Grandegger | 8a51794 | 2010-02-22 22:24:55 +0000 | [diff] [blame] | 270 | if (tb[IFLA_CAN_BERR_COUNTER]) { |
| 271 | struct can_berr_counter *bc = |
| 272 | RTA_DATA(tb[IFLA_CAN_BERR_COUNTER]); |
| 273 | |
| 274 | fprintf(f, "(berr-counter tx %d rx %d) ", bc->txerr, bc->rxerr); |
| 275 | } |
| 276 | |
Wolfgang Grandegger | 5a20447 | 2009-05-12 11:42:50 +0200 | [diff] [blame] | 277 | if (tb[IFLA_CAN_RESTART_MS]) { |
| 278 | __u32 *restart_ms = RTA_DATA(tb[IFLA_CAN_RESTART_MS]); |
| 279 | |
| 280 | fprintf(f, "restart-ms %d ", *restart_ms); |
| 281 | } |
| 282 | |
| 283 | if (tb[IFLA_CAN_BITTIMING]) { |
| 284 | struct can_bittiming *bt = RTA_DATA(tb[IFLA_CAN_BITTIMING]); |
| 285 | |
Oliver Hartkopp | 3bbff7d | 2014-04-23 19:27:26 +0200 | [diff] [blame] | 286 | fprintf(f, "\n " |
Wolfgang Grandegger | 5a20447 | 2009-05-12 11:42:50 +0200 | [diff] [blame] | 287 | "bitrate %d sample-point %.3f ", |
Oliver Hartkopp | 3bbff7d | 2014-04-23 19:27:26 +0200 | [diff] [blame] | 288 | bt->bitrate, (float)bt->sample_point / 1000.); |
| 289 | fprintf(f, "\n " |
Wolfgang Grandegger | 5a20447 | 2009-05-12 11:42:50 +0200 | [diff] [blame] | 290 | "tq %d prop-seg %d phase-seg1 %d phase-seg2 %d sjw %d", |
| 291 | bt->tq, bt->prop_seg, bt->phase_seg1, bt->phase_seg2, |
| 292 | bt->sjw); |
| 293 | } |
| 294 | |
| 295 | if (tb[IFLA_CAN_BITTIMING_CONST]) { |
| 296 | struct can_bittiming_const *btc = |
| 297 | RTA_DATA(tb[IFLA_CAN_BITTIMING_CONST]); |
| 298 | |
Oliver Hartkopp | 3bbff7d | 2014-04-23 19:27:26 +0200 | [diff] [blame] | 299 | fprintf(f, "\n " |
Wolfgang Grandegger | 5a20447 | 2009-05-12 11:42:50 +0200 | [diff] [blame] | 300 | "%s: tseg1 %d..%d tseg2 %d..%d " |
| 301 | "sjw 1..%d brp %d..%d brp-inc %d", |
Oliver Hartkopp | 3bbff7d | 2014-04-23 19:27:26 +0200 | [diff] [blame] | 302 | btc->name, btc->tseg1_min, btc->tseg1_max, |
Wolfgang Grandegger | 5a20447 | 2009-05-12 11:42:50 +0200 | [diff] [blame] | 303 | btc->tseg2_min, btc->tseg2_max, btc->sjw_max, |
| 304 | btc->brp_min, btc->brp_max, btc->brp_inc); |
| 305 | } |
| 306 | |
Oliver Hartkopp | 2bfe047 | 2014-04-23 19:27:27 +0200 | [diff] [blame] | 307 | if (tb[IFLA_CAN_DATA_BITTIMING]) { |
| 308 | struct can_bittiming *dbt = |
| 309 | RTA_DATA(tb[IFLA_CAN_DATA_BITTIMING]); |
| 310 | |
| 311 | fprintf(f, "\n " |
| 312 | "dbitrate %d dsample-point %.3f ", |
| 313 | dbt->bitrate, (float)dbt->sample_point / 1000.); |
| 314 | fprintf(f, "\n " |
| 315 | "dtq %d dprop-seg %d dphase-seg1 %d " |
| 316 | "dphase-seg2 %d dsjw %d", |
| 317 | dbt->tq, dbt->prop_seg, dbt->phase_seg1, |
| 318 | dbt->phase_seg2, dbt->sjw); |
| 319 | } |
| 320 | |
| 321 | if (tb[IFLA_CAN_DATA_BITTIMING_CONST]) { |
| 322 | struct can_bittiming_const *dbtc = |
| 323 | RTA_DATA(tb[IFLA_CAN_DATA_BITTIMING_CONST]); |
| 324 | |
| 325 | fprintf(f, "\n " |
| 326 | "%s: dtseg1 %d..%d dtseg2 %d..%d " |
| 327 | "dsjw 1..%d dbrp %d..%d dbrp-inc %d", |
| 328 | dbtc->name, dbtc->tseg1_min, dbtc->tseg1_max, |
| 329 | dbtc->tseg2_min, dbtc->tseg2_max, dbtc->sjw_max, |
| 330 | dbtc->brp_min, dbtc->brp_max, dbtc->brp_inc); |
| 331 | } |
| 332 | |
Wolfgang Grandegger | 5a20447 | 2009-05-12 11:42:50 +0200 | [diff] [blame] | 333 | if (tb[IFLA_CAN_CLOCK]) { |
| 334 | struct can_clock *clock = RTA_DATA(tb[IFLA_CAN_CLOCK]); |
| 335 | |
Oliver Hartkopp | 3bbff7d | 2014-04-23 19:27:26 +0200 | [diff] [blame] | 336 | fprintf(f, "\n clock %d", clock->freq); |
Wolfgang Grandegger | 5a20447 | 2009-05-12 11:42:50 +0200 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | } |
| 340 | |
| 341 | static void can_print_xstats(struct link_util *lu, |
| 342 | FILE *f, struct rtattr *xstats) |
| 343 | { |
| 344 | struct can_device_stats *stats; |
| 345 | |
| 346 | if (xstats && RTA_PAYLOAD(xstats) == sizeof(*stats)) { |
| 347 | stats = RTA_DATA(xstats); |
Oliver Hartkopp | 3bbff7d | 2014-04-23 19:27:26 +0200 | [diff] [blame] | 348 | fprintf(f, "\n " |
Wolfgang Grandegger | 5a20447 | 2009-05-12 11:42:50 +0200 | [diff] [blame] | 349 | "re-started bus-errors arbit-lost " |
| 350 | "error-warn error-pass bus-off"); |
Oliver Hartkopp | 3bbff7d | 2014-04-23 19:27:26 +0200 | [diff] [blame] | 351 | fprintf(f, "\n %-10d %-10d %-10d %-10d %-10d %-10d", |
Wolfgang Grandegger | 5a20447 | 2009-05-12 11:42:50 +0200 | [diff] [blame] | 352 | stats->restarts, stats->bus_error, |
| 353 | stats->arbitration_lost, stats->error_warning, |
| 354 | stats->error_passive, stats->bus_off); |
| 355 | } |
| 356 | } |
| 357 | |
vadimk | 561e650 | 2014-09-30 08:17:31 +0300 | [diff] [blame] | 358 | static void can_print_help(struct link_util *lu, int argc, char **argv, |
| 359 | FILE *f) |
| 360 | { |
| 361 | print_usage(f); |
| 362 | } |
| 363 | |
Wolfgang Grandegger | 5a20447 | 2009-05-12 11:42:50 +0200 | [diff] [blame] | 364 | struct link_util can_link_util = { |
| 365 | .id = "can", |
| 366 | .maxattr = IFLA_CAN_MAX, |
| 367 | .parse_opt = can_parse_opt, |
| 368 | .print_opt = can_print_opt, |
Stephen Hemminger | 4806867 | 2014-02-17 10:56:31 -0800 | [diff] [blame] | 369 | .print_xstats = can_print_xstats, |
vadimk | 561e650 | 2014-09-30 08:17:31 +0300 | [diff] [blame] | 370 | .print_help = can_print_help, |
Wolfgang Grandegger | 5a20447 | 2009-05-12 11:42:50 +0200 | [diff] [blame] | 371 | }; |