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