]> rtime.felk.cvut.cz Git - sojka/can-utils.git/commitdiff
Added new socketoptions to force the isotp protocol to intentionally
authorOliver Hartkopp <socketcan@hartkopp.net>
Sun, 14 Nov 2010 08:55:06 +0000 (08:55 +0000)
committerOliver Hartkopp <socketcan@hartkopp.net>
Sun, 14 Nov 2010 08:55:06 +0000 (08:55 +0000)
misbehave for regression tests.

CAN_ISOTP_TX_STMIN:
Set a value in nano secs that's used as minimum CF gap by the sender.
This value is used instead of the value provided by the receiver inside the FC.

CAN_ISOTP_RX_STMIN:
Ignores received CF frames which timestamps differ less than this value in nano
secs. This is used to test the receivers misbehaviour when the receiver
provides a lower stmin value that he's able to cope with. Received CF frames
are silently dropped when they come faster than specified by this value.

isotprecv.c
isotpsend.c

index 9e37c86829c726964df7fa3667a95fb4b2dd26e4..acd6de6acca52cf85213d6a167864fc672558bec 100644 (file)
@@ -71,6 +71,7 @@ void print_usage(char *prg)
        fprintf(stderr, "         -P <mode>    (check padding in SF/CF. (l)ength (c)ontent (a)ll)\n");
        fprintf(stderr, "         -b <bs>      (blocksize. 0 = off)\n");
        fprintf(stderr, "         -m <val>     (STmin in ms/ns. See spec.)\n");
+       fprintf(stderr, "         -f <time ns> (force rx stmin value in nanosecs)\n");
        fprintf(stderr, "         -w <num>     (max. wait frame transmissions.)\n");
        fprintf(stderr, "         -l           (loop: do not exit after pdu receiption.)\n");
        fprintf(stderr, "\nCAN IDs and addresses are given and expected in hexadecimal values.\n");
@@ -87,6 +88,7 @@ int main(int argc, char **argv)
     static struct can_isotp_fc_options fcopts;
     int opt, i;
     extern int optind, opterr, optopt;
+    __u32 force_rx_stmin = 0;
     int loop = 0;
 
     unsigned char msg[4096];
@@ -94,7 +96,7 @@ int main(int argc, char **argv)
 
     addr.can_addr.tp.tx_id = addr.can_addr.tp.rx_id = NO_CAN_ID;
 
-    while ((opt = getopt(argc, argv, "s:d:x:p:P:b:m:w:l?")) != -1) {
+    while ((opt = getopt(argc, argv, "s:d:x:p:P:b:m:w:f:l?")) != -1) {
            switch (opt) {
            case 's':
                    addr.can_addr.tp.tx_id = strtoul(optarg, (char **)NULL, 16);
@@ -144,6 +146,11 @@ int main(int argc, char **argv)
                    fcopts.wftmax = strtoul(optarg, (char **)NULL, 16) & 0xFF;
                    break;
 
+           case 'f':
+                   opts.flags |= CAN_ISOTP_FORCE_RXSTMIN;
+                   force_rx_stmin = strtoul(optarg, (char **)NULL, 10);
+                   break;
+
            case 'l':
                    loop = 1;
                    break;
@@ -176,6 +183,9 @@ int main(int argc, char **argv)
     setsockopt(s, SOL_CAN_ISOTP, CAN_ISOTP_OPTS, &opts, sizeof(opts));
     setsockopt(s, SOL_CAN_ISOTP, CAN_ISOTP_RECV_FC, &fcopts, sizeof(fcopts));
 
+    if (opts.flags & CAN_ISOTP_FORCE_RXSTMIN)
+           setsockopt(s, SOL_CAN_ISOTP, CAN_ISOTP_RX_STMIN, &force_rx_stmin, sizeof(force_rx_stmin));
+
     addr.can_family = AF_CAN;
     strcpy(ifr.ifr_name, argv[optind]);
     ioctl(s, SIOCGIFINDEX, &ifr);
index bcaa35ba7ff3e690853ee7b85e5fa0ea115a26b2..015dca6bab4d934ee3e87047324e748a1d5da94a 100644 (file)
@@ -69,7 +69,8 @@ void print_usage(char *prg)
        fprintf(stderr, "         -x <addr>    (extended addressing mode. Use 'any' for all addresses)\n");
        fprintf(stderr, "         -p <byte>    (set and enable padding byte)\n");
        fprintf(stderr, "         -P <mode>    (check padding in FC. (l)ength (c)ontent (a)ll)\n");
-       fprintf(stderr, "         -t <time ns> (transmit time in nanosecs)\n");
+       fprintf(stderr, "         -t <time ns> (frame transmit time (N_As) in nanosecs)\n");
+       fprintf(stderr, "         -f <time ns> (ignore FC and force local tx stmin value in nanosecs)\n");
        fprintf(stderr, "\nCAN IDs and addresses are given and expected in hexadecimal values.\n");
        fprintf(stderr, "The pdu data is expected on STDIN in space separated ASCII hex values.\n");
        fprintf(stderr, "\n");
@@ -83,12 +84,13 @@ int main(int argc, char **argv)
     static struct can_isotp_options opts;
     int opt;
     extern int optind, opterr, optopt;
+    __u32 force_tx_stmin = 0;
     unsigned char buf[4096];
     int buflen = 0;
 
     addr.can_addr.tp.tx_id = addr.can_addr.tp.rx_id = NO_CAN_ID;
 
-    while ((opt = getopt(argc, argv, "s:d:x:p:P:t:?")) != -1) {
+    while ((opt = getopt(argc, argv, "s:d:x:p:P:t:f:?")) != -1) {
            switch (opt) {
            case 's':
                    addr.can_addr.tp.tx_id = strtoul(optarg, (char **)NULL, 16);
@@ -130,6 +132,11 @@ int main(int argc, char **argv)
                    opts.frame_txtime = strtoul(optarg, (char **)NULL, 10);
                    break;
 
+           case 'f':
+                   opts.flags |= CAN_ISOTP_FORCE_TXSTMIN;
+                   force_tx_stmin = strtoul(optarg, (char **)NULL, 10);
+                   break;
+
            case '?':
                    print_usage(basename(argv[0]));
                    exit(0);
@@ -157,6 +164,9 @@ int main(int argc, char **argv)
 
     setsockopt(s, SOL_CAN_ISOTP, CAN_ISOTP_OPTS, &opts, sizeof(opts));
 
+    if (opts.flags & CAN_ISOTP_FORCE_TXSTMIN)
+           setsockopt(s, SOL_CAN_ISOTP, CAN_ISOTP_TX_STMIN, &force_tx_stmin, sizeof(force_tx_stmin));
+
     addr.can_family = AF_CAN;
     strcpy(ifr.ifr_name, argv[optind]);
     ioctl(s, SIOCGIFINDEX, &ifr);