From: Cyril H. <su...@li...> - 2011-07-13 08:07:27
|
The branch, master, has been updated via 0d624959bf77e013afd8d7534578af88de587db9 (commit) from 058daa414ddb7a980eca0e73ff8df6e9c53541eb (commit) - Log ----------------------------------------------------------------- commit 0d624959bf77e013afd8d7534578af88de587db9 Author: Oliver Hartkopp <soc...@ha...> Date: Mon Jul 11 19:32:27 2011 +0200 CAN: major update for the Controller Area Network LTP tests CAN: major update for the Controller Area Network LTP tests This update for the LTP tests are dealing with CAN filters and the CAN frame flow down to the CAN netdevice and vice versa. The patch removes all the obsolete stuff from the source code directory that has been originally used to pick the tests from. The two new tools also reside in the SocketCAN SVN svn://svn.berlios.de/socketcan/trunk/test tst-filter: New filter test tool in *one* programm (easy to use & handle) tst-rcv-own-msgs: Checks the CAN frame flow inside the networking stack Additionally the virtual CAN driver needs to be loaded with a special commandline option to perform the CAN frame flow test correctly. Signed-off-by: Oliver Hartkopp <soc...@ha...> ----------------------------------------------------------------------- Summary of changes: testcases/network/can/filter-tests/Makefile | 61 +--- testcases/network/can/filter-tests/canecho.c | 163 ------ .../network/can/filter-tests/run_ltp-can_tests.sh | 45 +- testcases/network/can/filter-tests/tst-bcm-cycle.c | 137 ------ testcases/network/can/filter-tests/tst-bcm-dump.c | 200 -------- .../network/can/filter-tests/tst-bcm-filter.c | 515 -------------------- testcases/network/can/filter-tests/tst-bcm-rtr.c | 145 ------ .../network/can/filter-tests/tst-bcm-rx-sendto.c | 162 ------ .../network/can/filter-tests/tst-bcm-server.c | 263 ---------- .../network/can/filter-tests/tst-bcm-single.c | 110 ----- .../network/can/filter-tests/tst-bcm-throttle.c | 464 ------------------ .../network/can/filter-tests/tst-bcm-tx-sendto.c | 122 ----- .../network/can/filter-tests/tst-bcm-tx_read.c | 158 ------ testcases/network/can/filter-tests/tst-err.c | 166 ------- .../network/can/filter-tests/tst-filter-master.c | 165 ------- .../network/can/filter-tests/tst-filter-server.c | 210 -------- testcases/network/can/filter-tests/tst-filter.c | 244 +++++++++ testcases/network/can/filter-tests/tst-packet.c | 167 ------- testcases/network/can/filter-tests/tst-proc.c | 120 ----- .../network/can/filter-tests/tst-raw-filter.c | 177 ------- .../network/can/filter-tests/tst-raw-sendto.c | 115 ----- testcases/network/can/filter-tests/tst-raw.c | 186 ------- .../network/can/filter-tests/tst-rcv-own-msgs.c | 247 ++++++++++ 23 files changed, 521 insertions(+), 3821 deletions(-) delete mode 100644 testcases/network/can/filter-tests/canecho.c delete mode 100644 testcases/network/can/filter-tests/tst-bcm-cycle.c delete mode 100644 testcases/network/can/filter-tests/tst-bcm-dump.c delete mode 100644 testcases/network/can/filter-tests/tst-bcm-filter.c delete mode 100644 testcases/network/can/filter-tests/tst-bcm-rtr.c delete mode 100644 testcases/network/can/filter-tests/tst-bcm-rx-sendto.c delete mode 100644 testcases/network/can/filter-tests/tst-bcm-server.c delete mode 100644 testcases/network/can/filter-tests/tst-bcm-single.c delete mode 100644 testcases/network/can/filter-tests/tst-bcm-throttle.c delete mode 100644 testcases/network/can/filter-tests/tst-bcm-tx-sendto.c delete mode 100644 testcases/network/can/filter-tests/tst-bcm-tx_read.c delete mode 100644 testcases/network/can/filter-tests/tst-err.c delete mode 100644 testcases/network/can/filter-tests/tst-filter-master.c delete mode 100644 testcases/network/can/filter-tests/tst-filter-server.c create mode 100644 testcases/network/can/filter-tests/tst-filter.c delete mode 100644 testcases/network/can/filter-tests/tst-packet.c delete mode 100644 testcases/network/can/filter-tests/tst-proc.c delete mode 100644 testcases/network/can/filter-tests/tst-raw-filter.c delete mode 100644 testcases/network/can/filter-tests/tst-raw-sendto.c delete mode 100644 testcases/network/can/filter-tests/tst-raw.c create mode 100644 testcases/network/can/filter-tests/tst-rcv-own-msgs.c diff --git a/testcases/network/can/filter-tests/Makefile b/testcases/network/can/filter-tests/Makefile index 192c3b0..c88f704 100644 --- a/testcases/network/can/filter-tests/Makefile +++ b/testcases/network/can/filter-tests/Makefile @@ -1,43 +1,6 @@ # # $Id: Makefile,v 1.1 2009/03/02 15:33:55 subrata_modak Exp $ # -# Copyright (c) 2002-2007 Volkswagen Group Electronic Research -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions, the following disclaimer and -# the referenced file 'COPYING'. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# 3. Neither the name of Volkswagen nor the names of its contributors -# may be used to endorse or promote products derived from this software -# without specific prior written permission. -# -# Alternatively, provided that this notice is retained in full, this -# software may be distributed under the terms of the GNU General -# Public License ("GPL") version 2 as distributed in the 'COPYING' -# file from the main directory of the linux kernel source. -# -# The provided data structures and external interfaces from this code -# are not restricted to be used by modules with a GPL compatible license. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH -# DAMAGE. -# # Send feedback to <soc...@li...> CFLAGS = -O2 -Wall -Wno-parentheses \ @@ -46,25 +9,7 @@ CFLAGS = -O2 -Wall -Wno-parentheses \ -DPF_CAN=29 \ -DAF_CAN=PF_CAN -PROGRAMS = tst-raw \ - tst-raw-filter \ - tst-err \ - tst-raw-sendto \ - tst-packet \ - tst-filter-master \ - tst-filter-server \ - tst-bcm-cycle \ - tst-bcm-server \ - tst-bcm-tx_read \ - tst-bcm-rtr \ - tst-bcm-single \ - tst-bcm-filter \ - tst-bcm-throttle \ - tst-bcm-rx-sendto \ - tst-bcm-tx-sendto \ - tst-bcm-dump \ - tst-proc \ - canecho +PROGRAMS = tst-filter tst-rcv-own-msgs all: $(PROGRAMS) @@ -72,8 +17,8 @@ install: cp -f $(PROGRAMS) /usr/local/bin clean: - rm -f $(PROGRAMS) output_ltp-can.txt output_ltp-can-verify.txt /etc/modprobe.d/vcan + rm -f $(PROGRAMS) distclean: - rm -f $(PROGRAMS) *~ output_ltp-can.txt output_ltp-can-verify.txt /etc/modprobe.d/vcan + rm -f $(PROGRAMS) *~ diff --git a/testcases/network/can/filter-tests/canecho.c b/testcases/network/can/filter-tests/canecho.c deleted file mode 100644 index e87f063..0000000 --- a/testcases/network/can/filter-tests/canecho.c +++ /dev/null @@ -1,163 +0,0 @@ -/* - * $Id: canecho.c,v 1.1 2009/03/02 15:33:55 subrata_modak Exp $ - */ - -/* - * canecho.c - * - * Copyright (c) 2002-2007 Volkswagen Group Electronic Research - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of Volkswagen nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * Alternatively, provided that this notice is retained in full, this - * software may be distributed under the terms of the GNU General - * Public License ("GPL") version 2, in which case the provisions of the - * GPL apply INSTEAD OF those given above. - * - * The provided data structures and external interfaces from this code - * are not restricted to be used by modules with a GPL compatible license. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH - * DAMAGE. - * - * Send feedback to <soc...@li...> - * - */ - -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <string.h> -#include <signal.h> -#include <libgen.h> - -#include <sys/types.h> -#include <sys/socket.h> -#include <sys/ioctl.h> -#include <sys/uio.h> -#include <net/if.h> - -#include <linux/can.h> - -extern int optind, opterr, optopt; - -static int s = -1; -static int running = 1; - -void print_usage(char *prg) -{ - fprintf(stderr, "Usage: %s [can-interface]\n", prg); -} - -void sigterm(int signo) -{ - printf("got signal %d\n", signo); - running = 0; -} - -int main(int argc, char **argv) -{ - int family = PF_CAN, type = SOCK_RAW, proto = CAN_RAW; - int opt; - struct sockaddr_can addr; - struct ifreq ifr; - struct can_frame frame; - int nbytes, i; - int verbose = 0; - - signal(SIGTERM, sigterm); - signal(SIGHUP, sigterm); - - while ((opt = getopt(argc, argv, "f:t:p:v")) != -1) { - switch (opt) { - case 'f': - family = atoi(optarg); - break; - - case 't': - type = atoi(optarg); - break; - - case 'p': - proto = atoi(optarg); - break; - - case 'v': - verbose = 1; - break; - - case '?': - break; - - default: - fprintf(stderr, "Unknown option %c\n", opt); - break; - } - } - - if (optind == argc) { - print_usage(basename(argv[0])); - exit(0); - } - - printf("interface = %s, family = %d, type = %d, proto = %d\n", - argv[optind], family, type, proto); - if ((s = socket(family, type, proto)) < 0) { - perror("socket"); - return 1; - } - - addr.can_family = family; - strcpy(ifr.ifr_name, argv[optind]); - ioctl(s, SIOCGIFINDEX, &ifr); - addr.can_ifindex = ifr.ifr_ifindex; - - if (bind(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) { - perror("bind"); - return 1; - } - - while (running) { - if ((nbytes = read(s, &frame, sizeof(frame))) < 0) { - perror("read"); - return 1; - } - if (verbose) { - printf("%03X: ", frame.can_id & CAN_EFF_MASK); - if (frame.can_id & CAN_RTR_FLAG) { - printf("remote request"); - } else { - printf("[%d]", frame.can_dlc); - for (i = 0; i < frame.can_dlc; i++) { - printf(" %02X", frame.data[i]); - } - } - printf("\n"); - } - frame.can_id++; - write(s, &frame, sizeof(frame)); - } - - return 0; -} \ No newline at end of file diff --git a/testcases/network/can/filter-tests/run_ltp-can_tests.sh b/testcases/network/can/filter-tests/run_ltp-can_tests.sh index 6d7aafc..8070c9a 100644 --- a/testcases/network/can/filter-tests/run_ltp-can_tests.sh +++ b/testcases/network/can/filter-tests/run_ltp-can_tests.sh @@ -1,6 +1,6 @@ #!/bin/sh ################################################################################ -## Copyright (c) Oliver Hartkopp <oli...@vo...>, 2009 ## +## Copyright (c) Oliver Hartkopp <oli...@vo...>, 2011 ## ## Copyright (c) International Business Machines Corp., 2009 ## ## ## ## This program is free software; you can redistribute it and#or modify ## @@ -24,25 +24,34 @@ if [ $(id -ru) -ne 0 ]; then exit 1 fi -cat <<-EOF > /etc/modprobe.d/vcan -# protocol family PF_CAN -alias net-pf-29 can -# protocols in PF_CAN -alias can-proto-1 can-raw -alias can-proto-2 can-bcm -alias can-proto-3 can-tp16 -alias can-proto-4 can-tp20 -alias can-proto-5 can-mcnet -alias can-proto-6 can-isotp -EOF - +# load needed CAN networklayer modules modprobe -f can modprobe -f can_raw -modprobe -f vcan -ip link add dev vcan0 type vcan -ifconfig vcan0 up -./tst-filter-server > output_ltp-can.txt & -./tst-filter-master | tee output_ltp-can-verify.txt +# ensure the vcan driver to perform the ECHO on driver level +modprobe -r vcan +modprobe -f vcan echo=1 + +VCAN=vcan0 + +# create virtual CAN device +ip link add dev $VCAN type vcan || exit 1 +ifconfig $VCAN up + +# check precondition for CAN frame flow test +HAS_ECHO=`ip link show $VCAN | grep -c ECHO` + +if [ $HAS_ECHO -ne 1 ] +then + exit 1 +fi + +# test of CAN filters on af_can.c +./tst-filter $VCAN || exit 1 + +# test of CAN frame flow down to the netdevice and up again +./tst-rcv-own-msgs $VCAN || exit 1 + +exit 0 diff --git a/testcases/network/can/filter-tests/tst-bcm-cycle.c b/testcases/network/can/filter-tests/tst-bcm-cycle.c deleted file mode 100644 index 7f4c8ac..0000000 --- a/testcases/network/can/filter-tests/tst-bcm-cycle.c +++ /dev/null @@ -1,137 +0,0 @@ -/* - * $Id: tst-bcm-cycle.c,v 1.1 2009/03/02 15:33:55 subrata_modak Exp $ - */ - -/* - * tst-bcm-cycle.c - * - * Copyright (c) 2002-2007 Volkswagen Group Electronic Research - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of Volkswagen nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * Alternatively, provided that this notice is retained in full, this - * software may be distributed under the terms of the GNU General - * Public License ("GPL") version 2, in which case the provisions of the - * GPL apply INSTEAD OF those given above. - * - * The provided data structures and external interfaces from this code - * are not restricted to be used by modules with a GPL compatible license. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH - * DAMAGE. - * - * Send feedback to <soc...@li...> - * - */ - -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <string.h> - -#include <sys/types.h> -#include <sys/socket.h> -#include <sys/ioctl.h> -#include <sys/uio.h> -#include <net/if.h> - -#include <linux/can.h> -#include <linux/can/bcm.h> - -#define U64_DATA(p) (*(unsigned long long*)(p)->data) - -int main(int argc, char **argv) -{ - int s; - struct sockaddr_can addr; - struct ifreq ifr; - - struct { - struct bcm_msg_head msg_head; - struct can_frame frame[4]; - } msg; - - if ((s = socket(PF_CAN, SOCK_DGRAM, CAN_BCM)) < 0) { - perror("socket"); - return 1; - } - - addr.can_family = PF_CAN; - strcpy(ifr.ifr_name, "vcan2"); - ioctl(s, SIOCGIFINDEX, &ifr); - addr.can_ifindex = ifr.ifr_ifindex; - - if (connect(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) { - perror("connect"); - return 1; - } - - msg.msg_head.opcode = TX_SETUP; - msg.msg_head.can_id = 0x42; - msg.msg_head.flags = SETTIMER|STARTTIMER; - msg.msg_head.nframes = 1; - msg.msg_head.count = 10; - msg.msg_head.ival1.tv_sec = 1; - msg.msg_head.ival1.tv_usec = 0; - msg.msg_head.ival2.tv_sec = 0; - msg.msg_head.ival2.tv_usec = 0; - msg.frame[0].can_id = 0x42; - msg.frame[0].can_dlc = 8; - U64_DATA(&msg.frame[0]) = (__u64) 0xdeadbeefdeadbeefULL; - - if (write(s, &msg, sizeof(msg)) < 0) - perror("write"); - - printf("Press any key to stop the cycle ...\n"); - - getchar(); - - msg.msg_head.opcode = TX_SETUP; - msg.msg_head.can_id = 0x42; - msg.msg_head.flags = SETTIMER|STARTTIMER; - msg.msg_head.nframes = 1; - msg.msg_head.count = 0; - msg.msg_head.ival1.tv_sec = 0; - msg.msg_head.ival1.tv_usec = 0; - msg.msg_head.ival2.tv_sec = 0; - msg.msg_head.ival2.tv_usec = 0; - msg.frame[0].can_id = 0x42; - msg.frame[0].can_dlc = 8; - U64_DATA(&msg.frame[0]) = (__u64) 0xdeadbeefdeadbeefULL; - - if (write(s, &msg, sizeof(msg)) < 0) - perror("write"); - - printf("Press any key to close the socket ...\n"); - - getchar(); - - close(s); - - printf("Press any key to end the program ...\n"); - - getchar(); - - return 0; -} \ No newline at end of file diff --git a/testcases/network/can/filter-tests/tst-bcm-dump.c b/testcases/network/can/filter-tests/tst-bcm-dump.c deleted file mode 100644 index 5004d3a..0000000 --- a/testcases/network/can/filter-tests/tst-bcm-dump.c +++ /dev/null @@ -1,200 +0,0 @@ -/* - * $Id: tst-bcm-dump.c,v 1.1 2009/03/02 15:33:55 subrata_modak Exp $ - */ - -/* - * tst-bcm-dump.c - * - * Copyright (c) 2008 Oliver Hartkopp - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the version 2 of the GNU General Public License - * as published by the Free Software Foundation - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * Send feedback to <soc...@li...> - * - */ - -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <string.h> -#include <time.h> -#include <libgen.h> - -#include <sys/types.h> -#include <sys/socket.h> -#include <sys/ioctl.h> -#include <sys/time.h> -#include <net/if.h> - -#include <linux/can.h> -#include <linux/can/bcm.h> - -#define DEFAULT_IFACE "vcan0" -#define DEFAULT_CANID 0x42 - -void print_usage(char *prg) -{ - fprintf(stderr, "\nUsage: %s [options]\n", prg); - fprintf(stderr, "Options: -i <interface> (CAN interface. Default: '%s')\n", DEFAULT_IFACE); - fprintf(stderr, " -c <can_id> (used CAN ID. Default: 0x%03X)\n", DEFAULT_CANID); - fprintf(stderr, " -o <timeout> (Timeout value in nsecs. Default: 0)\n"); - fprintf(stderr, " -t <throttle> (Throttle value in nsecs. Default: 0)\n"); - fprintf(stderr, " -q <msgs> (Quit after receiption of #msgs)\n"); - fprintf(stderr, " -s (set STARTTIMER flag. Default: off)\n"); - fprintf(stderr, "\n"); -} - -int main(int argc, char **argv) -{ - int s; - struct sockaddr_can addr; - int nbytes; - int i; - struct ifreq ifr; - char *ifname = DEFAULT_IFACE; - canid_t canid = DEFAULT_CANID; - int opt; - struct timeval tv; - unsigned long starttimer = 0; - unsigned long long timeout = 0; - unsigned long long throttle = 0; - unsigned long msgs = 0; - struct { - struct bcm_msg_head msg_head; - struct can_frame frame; - } msg; - - while ((opt = getopt(argc, argv, "i:c:o:t:q:s")) != -1) { - switch (opt) { - - case 'i': - ifname = optarg; - break; - - case 'c': - canid = strtoul(optarg, (char **)NULL, 16); - break; - - case 'o': - timeout = strtoull(optarg, (char **)NULL, 10); - break; - - case 't': - throttle = strtoull(optarg, (char **)NULL, 10); - break; - - case 'q': - msgs = strtoul(optarg, (char **)NULL, 10); - break; - - case 's': - starttimer = STARTTIMER; - break; - - case '?': - default: - print_usage(basename(argv[0])); - exit(1); - break; - } - } - - if ((s = socket(PF_CAN, SOCK_DGRAM, CAN_BCM)) < 0) { - perror("socket"); - return 1; - } - - if (strcmp(ifname, "any") == 0) - addr.can_ifindex = 0; - else { - strcpy(ifr.ifr_name, ifname); - if (ioctl(s, SIOCGIFINDEX, &ifr) < 0) { - perror("SIOCGIFINDEX"); - return 1; - } - addr.can_ifindex = ifr.ifr_ifindex; - } - - addr.can_family = PF_CAN; - - if (connect(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) { - perror("connect"); - return 1; - } - - msg.msg_head.opcode = RX_SETUP; - msg.msg_head.can_id = canid; - msg.msg_head.flags = SETTIMER|RX_FILTER_ID|starttimer; - msg.msg_head.ival1.tv_sec = timeout / 1000000; - msg.msg_head.ival1.tv_usec = timeout % 1000000; - msg.msg_head.ival2.tv_sec = throttle / 1000000; - msg.msg_head.ival2.tv_usec = throttle % 1000000; - msg.msg_head.nframes = 0; - - gettimeofday(&tv, NULL); - printf("[%ld.%06ld] ", tv.tv_sec, tv.tv_usec); - printf("Writing RX_SETUP with RX_FILTER_ID for can_id <%03X>\n", - msg.msg_head.can_id); - - if (write(s, &msg, sizeof(msg)) < 0) - perror("write"); - - while (1) { - - nbytes = read(s, &msg, sizeof(msg)); - if (nbytes < 0) { - perror("read"); - return 1; - } - gettimeofday(&tv, NULL); - printf("[%ld.%06ld] ", tv.tv_sec, tv.tv_usec); - - if (nbytes == sizeof(msg)) { - - if (ioctl(s, SIOCGSTAMP, &tv) < 0) - perror("SIOCGSTAMP"); - else - printf("(%ld.%06ld) ", tv.tv_sec, tv.tv_usec); - - if (msg.msg_head.opcode != RX_CHANGED) { - printf("missing RX_CHANGED.\n"); - return 1; - } - - printf("RX_CHANGED "); - - for (i=0; i < msg.frame.can_dlc; i++) - printf("%02X ", msg.frame.data[i]); - - } else { - - if (msg.msg_head.opcode != RX_TIMEOUT) { - printf("missing RX_TIMEOUT.\n"); - return 1; - } - - printf("RX_TIMEOUT"); - } - - printf("\n"); - fflush(stdout); - - if (msgs && !(--msgs)) - break; - } - - close(s); - - return 0; -} \ No newline at end of file diff --git a/testcases/network/can/filter-tests/tst-bcm-filter.c b/testcases/network/can/filter-tests/tst-bcm-filter.c deleted file mode 100644 index 873e871..0000000 --- a/testcases/network/can/filter-tests/tst-bcm-filter.c +++ /dev/null @@ -1,515 +0,0 @@ -/* - * $Id: tst-bcm-filter.c,v 1.1 2009/03/02 15:33:55 subrata_modak Exp $ - */ - -/* - * tst-bcm-filter.c - * - * Copyright (c) 2002-2007 Volkswagen Group Electronic Research - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of Volkswagen nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * Alternatively, provided that this notice is retained in full, this - * software may be distributed under the terms of the GNU General - * Public License ("GPL") version 2, in which case the provisions of the - * GPL apply INSTEAD OF those given above. - * - * The provided data structures and external interfaces from this code - * are not restricted to be used by modules with a GPL compatible license. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH - * DAMAGE. - * - * Send feedback to <soc...@li...> - * - */ - -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <string.h> - -#include <sys/types.h> -#include <sys/socket.h> -#include <sys/ioctl.h> -#include <sys/uio.h> -#include <net/if.h> - -#include <linux/can.h> -#include <linux/can/bcm.h> - -#define U64_DATA(p) (*(unsigned long long*)(p)->data) - -int main(int argc, char **argv) -{ - int s,nbytes; - struct sockaddr_can addr; - struct ifreq ifr; - - struct timeval tv; - - struct { - struct bcm_msg_head msg_head; - struct can_frame frame[4]; - } txmsg, rxmsg; - - if ((s = socket(PF_CAN, SOCK_DGRAM, CAN_BCM)) < 0) { - perror("socket"); - return 1; - } - - addr.can_family = PF_CAN; - strcpy(ifr.ifr_name, "vcan2"); - ioctl(s, SIOCGIFINDEX, &ifr); - addr.can_ifindex = ifr.ifr_ifindex; - - if (connect(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) { - perror("connect"); - return 1; - } - - txmsg.msg_head.opcode = RX_SETUP; - txmsg.msg_head.can_id = 0x042; - txmsg.msg_head.flags = SETTIMER|RX_FILTER_ID; - txmsg.msg_head.ival1.tv_sec = 1; - txmsg.msg_head.ival1.tv_usec = 0; - txmsg.msg_head.ival2.tv_sec = 0; - txmsg.msg_head.ival2.tv_usec = 0; - txmsg.msg_head.nframes = 0; - - printf("<*>Writing RX_SETUP with RX_FILTER_ID for can_id <%03X>\n", - txmsg.msg_head.can_id); - - if (write(s, &txmsg, sizeof(txmsg)) < 0) - perror("write"); - - /* test for RX_DELETE */ - txmsg.msg_head.opcode = RX_DELETE; - txmsg.msg_head.can_id = 0x042; /* everything we need for RX_DELETE */ - - printf("<*>Writing RX_DELETE for can_id <%03X>\n", - txmsg.msg_head.can_id); - - if (write(s, &txmsg, sizeof(txmsg)) < 0) - perror("write"); - - txmsg.msg_head.opcode = RX_SETUP; - txmsg.msg_head.can_id = 0x042; - txmsg.msg_head.flags = SETTIMER|RX_FILTER_ID; - txmsg.msg_head.ival1.tv_sec = 1; - txmsg.msg_head.ival1.tv_usec = 0; - txmsg.msg_head.ival2.tv_sec = 0; - txmsg.msg_head.ival2.tv_usec = 0; - txmsg.msg_head.nframes = 0; - - printf("<*>Writing RX_SETUP with RX_FILTER_ID for can_id <%03X>\n", - txmsg.msg_head.can_id); - - if (write(s, &txmsg, sizeof(txmsg)) < 0) - perror("write"); - - txmsg.msg_head.opcode = TX_SEND; - txmsg.msg_head.nframes = 1; - /* obsolete for TX_SEND ... */ -#if 0 - txmsg.msg_head.can_id = 0x43; - txmsg.msg_head.flags = SETTIMER|STARTTIMER|TX_CP_CAN_ID; - txmsg.msg_head.count = 0; - txmsg.msg_head.ival1.tv_sec = 0; - txmsg.msg_head.ival1.tv_usec = 0; - txmsg.msg_head.ival2.tv_sec = 0; - txmsg.msg_head.ival2.tv_usec = 0; -#endif - txmsg.frame[0].can_id = 0x43; - txmsg.frame[0].can_dlc = 8; - U64_DATA(&txmsg.frame[0]) = (__u64) 0xdeadbeefdeadbeefULL; - - printf("<2>Writing TX_SEND with wrong can_id <%03X>\n", - txmsg.frame[0].can_id); - - if (write(s, &txmsg, sizeof(txmsg)) < 0) - perror("write"); - - txmsg.msg_head.opcode = TX_SEND; - txmsg.msg_head.nframes = 1; - txmsg.frame[0].can_id = 0x42; - txmsg.frame[0].can_dlc = 8; - U64_DATA(&txmsg.frame[0]) = (__u64) 0xdeadbeefdeadbeefULL; - - printf("<3>Writing TX_SEND with correct can_id <%03X>\n", - txmsg.frame[0].can_id); - - if (write(s, &txmsg, sizeof(txmsg)) < 0) - perror("write"); - - if ((nbytes = read(s, &rxmsg, sizeof(rxmsg))) < 0) - perror("read"); - - ioctl(s, SIOCGSTAMP, &tv); - printf("(%ld.%06ld) ", tv.tv_sec, tv.tv_usec); - - if (rxmsg.msg_head.opcode == RX_CHANGED && - nbytes == sizeof(struct bcm_msg_head) + sizeof(struct can_frame) && - rxmsg.msg_head.can_id == 0x42 && rxmsg.frame[0].can_id == 0x42) { - printf("<3>Received correct RX_CHANGED message for can_id <%03X> >> OK!\n", - rxmsg.frame[0].can_id); - } - - /* growing number of nframes => RX_DELETE instead of simple update */ - txmsg.msg_head.opcode = RX_DELETE; - txmsg.msg_head.can_id = 0x042; /* everything we need for RX_DELETE */ - - printf("<*>Writing RX_DELETE for can_id <%03X>\n", - txmsg.msg_head.can_id); - - if (write(s, &txmsg, sizeof(txmsg)) < 0) - perror("write"); - - txmsg.msg_head.opcode = RX_SETUP; - txmsg.msg_head.can_id = 0x042; - txmsg.msg_head.flags = SETTIMER|RX_CHECK_DLC; - txmsg.msg_head.ival1.tv_sec = 1; - txmsg.msg_head.ival1.tv_usec = 0; - txmsg.msg_head.ival2.tv_sec = 0; - txmsg.msg_head.ival2.tv_usec = 0; - txmsg.msg_head.nframes = 1; - /* txmsg.frame[0].can_dlc = 8; obsolete for RX_SETUP */ - U64_DATA(&txmsg.frame[0]) = (__u64) 0xFF00000000000000ULL; - - printf("<*>Writing simple RX_SETUP for can_id <%03X> with msgbits 0x%016llX\n", - txmsg.msg_head.can_id, U64_DATA(&txmsg.frame[0])); - - if (write(s, &txmsg, sizeof(txmsg)) < 0) - perror("write"); - - txmsg.msg_head.opcode = TX_SEND; - txmsg.msg_head.nframes = 1; - txmsg.frame[0].can_id = 0x42; - txmsg.frame[0].can_dlc = 8; - U64_DATA(&txmsg.frame[0]) = (__u64) 0xdeadbeefdeadbeefULL; - - printf("<5>Writing TX_SEND with correct can_id <%03X>\n", - txmsg.frame[0].can_id); - - if (write(s, &txmsg, sizeof(txmsg)) < 0) - perror("write"); - - if ((nbytes = read(s, &rxmsg, sizeof(rxmsg))) < 0) - perror("read"); - - ioctl(s, SIOCGSTAMP, &tv); - printf("(%ld.%06ld) ", tv.tv_sec, tv.tv_usec); - - if (rxmsg.msg_head.opcode == RX_CHANGED && - nbytes == sizeof(struct bcm_msg_head) + sizeof(struct can_frame) && - rxmsg.msg_head.can_id == 0x42 && rxmsg.frame[0].can_id == 0x42) { - printf("<5>Received correct RX_CHANGED message for can_id <%03X> >> OK!\n", - rxmsg.frame[0].can_id); - } - - txmsg.msg_head.opcode = TX_SEND; - txmsg.msg_head.nframes = 1; - txmsg.frame[0].can_id = 0x42; - txmsg.frame[0].can_dlc = 8; - U64_DATA(&txmsg.frame[0]) = (__u64) 0xdeadbeefdeadbeefULL; - - printf("<6>Writing TX_SEND with correct can_id <%03X> ", - txmsg.frame[0].can_id); - printf("no changed data\n"); - - if (write(s, &txmsg, sizeof(txmsg)) < 0) - perror("write"); - - /* no change here */ - - txmsg.msg_head.opcode = TX_SEND; - txmsg.msg_head.nframes = 1; - txmsg.frame[0].can_id = 0x42; - txmsg.frame[0].can_dlc = 8; - U64_DATA(&txmsg.frame[0]) = (__u64) 0xdeadbeefdeadbeefULL; - - printf("<7>Writing TX_SEND with correct can_id <%03X> ", - txmsg.frame[0].can_id); - printf("changed relevant msgbits\n"); - - if (write(s, &txmsg, sizeof(txmsg)) < 0) - perror("write"); - - if ((nbytes = read(s, &rxmsg, sizeof(rxmsg))) < 0) - perror("read"); - - ioctl(s, SIOCGSTAMP, &tv); - printf("(%ld.%06ld) ", tv.tv_sec, tv.tv_usec); - - if (rxmsg.msg_head.opcode == RX_CHANGED && - nbytes == sizeof(struct bcm_msg_head) + sizeof(struct can_frame) && - rxmsg.msg_head.can_id == 0x42 && rxmsg.frame[0].can_id == 0x42) { - printf("<7>Received correct RX_CHANGED message for can_id <%03X> >> OK!\n", - rxmsg.frame[0].can_id); - } - - txmsg.msg_head.opcode = TX_SEND; - txmsg.msg_head.nframes = 1; - txmsg.frame[0].can_id = 0x42; - txmsg.frame[0].can_dlc = 8; - U64_DATA(&txmsg.frame[0]) = (__u64) 0xdeadbeefdeadbeefULL; - - printf("<8>Writing TX_SEND with correct can_id <%03X> ", - txmsg.frame[0].can_id); - printf("changed irrelevant msgbits\n"); - - if (write(s, &txmsg, sizeof(txmsg)) < 0) - perror("write"); - - txmsg.msg_head.opcode = TX_SEND; - txmsg.msg_head.nframes = 1; - txmsg.frame[0].can_id = 0x42; - txmsg.frame[0].can_dlc = 7; - U64_DATA(&txmsg.frame[0]) = (__u64) 0xdeadbeefdeadbeefULL; - - printf("<9>Writing TX_SEND with correct can_id <%03X> ", - txmsg.frame[0].can_id); - printf("changed Data Length Code DLC\n"); - - if (write(s, &txmsg, sizeof(txmsg)) < 0) - perror("write"); - - if ((nbytes = read(s, &rxmsg, sizeof(rxmsg))) < 0) - perror("read"); - - ioctl(s, SIOCGSTAMP, &tv); - printf("(%ld.%06ld) ", tv.tv_sec, tv.tv_usec); - - if (rxmsg.msg_head.opcode == RX_CHANGED && - nbytes == sizeof(struct bcm_msg_head) + sizeof(struct can_frame) && - rxmsg.msg_head.can_id == 0x42 && rxmsg.frame[0].can_id == 0x42) { - printf("<9>Received correct RX_CHANGED message for can_id <%03X> >> OK!\n", - rxmsg.frame[0].can_id); - } - - txmsg.msg_head.opcode = RX_DELETE; - txmsg.msg_head.can_id = 0x042; /* everything we need for RX_DELETE */ - - printf("<*>Writing RX_DELETE for can_id <%03X> for RX_SETUP with growing nframes\n", - txmsg.msg_head.can_id); - - if (write(s, &txmsg, sizeof(txmsg)) < 0) - perror("write"); - - /* no problems ;-) but NOW we try MUX messages ... and timeouts */ - - txmsg.msg_head.opcode = RX_SETUP; - txmsg.msg_head.can_id = 0x042; - txmsg.msg_head.flags = SETTIMER|RX_CHECK_DLC; - txmsg.msg_head.ival1.tv_sec = 1; - txmsg.msg_head.ival1.tv_usec = 0; - txmsg.msg_head.nframes = 3; - U64_DATA(&txmsg.frame[0]) = (__u64) 0xFF00000000000000ULL; - U64_DATA(&txmsg.frame[1]) = (__u64) 0x01000000000000FFULL; - U64_DATA(&txmsg.frame[2]) = (__u64) 0x02000000000000FFULL; - - printf("<*>Writing multiplex RX_SETUP for can_id <%03X>\n", - txmsg.msg_head.can_id); - - if (write(s, &txmsg, sizeof(txmsg)) < 0) - perror("write"); - - txmsg.msg_head.opcode = TX_SEND; - txmsg.msg_head.nframes = 1; - txmsg.frame[0].can_id = 0x42; - txmsg.frame[0].can_dlc = 8; - U64_DATA(&txmsg.frame[0]) = (__u64) 0x4200000000000000ULL; - - printf("<A>Writing TX_SEND with wrong MUX ID 42\n"); - - if (write(s, &txmsg, sizeof(txmsg)) < 0) - perror("write"); - - txmsg.msg_head.opcode = TX_SEND; - txmsg.msg_head.nframes = 1; - txmsg.frame[0].can_id = 0x42; - txmsg.frame[0].can_dlc = 8; - U64_DATA(&txmsg.frame[0]) = (__u64) 0x0100000000000000ULL; - - printf("<B>Writing TX_SEND with correct MUX ID 01\n"); - - if (write(s, &txmsg, sizeof(txmsg)) < 0) - perror("write"); - - if ((nbytes = read(s, &rxmsg, sizeof(rxmsg))) < 0) - perror("read"); - - ioctl(s, SIOCGSTAMP, &tv); - printf("(%ld.%06ld) ", tv.tv_sec, tv.tv_usec); - - if (rxmsg.msg_head.opcode == RX_CHANGED && - nbytes == sizeof(struct bcm_msg_head) + sizeof(struct can_frame) && - rxmsg.msg_head.can_id == 0x42 && rxmsg.frame[0].can_id == 0x42) { - printf("<B>Received correct RX_CHANGED message for can_id <%03X> >> OK!\n", - rxmsg.frame[0].can_id); - } - - txmsg.msg_head.opcode = TX_SEND; - txmsg.msg_head.nframes = 1; - txmsg.frame[0].can_id = 0x42; - txmsg.frame[0].can_dlc = 8; - U64_DATA(&txmsg.frame[0]) = (__u64) 0x0100000000000000ULL; - - printf("<C>Writing TX_SEND with correct MUX ID 01 but no data change\n"); - - if (write(s, &txmsg, sizeof(txmsg)) < 0) - perror("write"); - - txmsg.msg_head.opcode = TX_SEND; - txmsg.msg_head.nframes = 1; - txmsg.frame[0].can_id = 0x42; - txmsg.frame[0].can_dlc = 8; - U64_DATA(&txmsg.frame[0]) = (__u64) 0x0100001234567800ULL; - - printf("<D>Writing TX_SEND with correct MUX ID 01 but no relevant data change\n"); - - if (write(s, &txmsg, sizeof(txmsg)) < 0) - perror("write"); - - txmsg.msg_head.opcode = TX_SEND; - txmsg.msg_head.nframes = 1; - txmsg.frame[0].can_id = 0x42; - txmsg.frame[0].can_dlc = 8; - U64_DATA(&txmsg.frame[0]) = (__u64) 0x0100001234567801ULL; - - printf("<E>Writing TX_SEND with correct MUX ID 01 with relevant data change\n"); - - if (write(s, &txmsg, sizeof(txmsg)) < 0) - perror("write"); - - if ((nbytes = read(s, &rxmsg, sizeof(rxmsg))) < 0) - perror("read"); - - ioctl(s, SIOCGSTAMP, &tv); - printf("(%ld.%06ld) ", tv.tv_sec, tv.tv_usec); - - if (rxmsg.msg_head.opcode == RX_CHANGED && - nbytes == sizeof(struct bcm_msg_head) + sizeof(struct can_frame) && - rxmsg.msg_head.can_id == 0x42 && rxmsg.frame[0].can_id == 0x42) { - printf("<E>Received correct RX_CHANGED message for can_id <%03X> >> OK!\n", - rxmsg.frame[0].can_id); - } - - txmsg.msg_head.opcode = TX_SEND; - txmsg.msg_head.nframes = 1; - txmsg.frame[0].can_id = 0x42; - txmsg.frame[0].can_dlc = 8; - U64_DATA(&txmsg.frame[0]) = (__u64) 0x0200000000000000ULL; - - printf("<F>Writing TX_SEND with correct MUX ID 02\n"); - - if (write(s, &txmsg, sizeof(txmsg)) < 0) - perror("write"); - - if ((nbytes = read(s, &rxmsg, sizeof(rxmsg))) < 0) - perror("read"); - - ioctl(s, SIOCGSTAMP, &tv); - printf("(%ld.%06ld) ", tv.tv_sec, tv.tv_usec); - - if (rxmsg.msg_head.opcode == RX_CHANGED && - nbytes == sizeof(struct bcm_msg_head) + sizeof(struct can_frame) && - rxmsg.msg_head.can_id == 0x42 && rxmsg.frame[0].can_id == 0x42) { - printf("<F>Received correct RX_CHANGED message for can_id <%03X> >> OK!\n", - rxmsg.frame[0].can_id); - } - - txmsg.msg_head.opcode = TX_SEND; - txmsg.msg_head.nframes = 1; - txmsg.frame[0].can_id = 0x42; - txmsg.frame[0].can_dlc = 8; - U64_DATA(&txmsg.frame[0]) = (__u64) 0x0200000000000001ULL; - - printf("<10>Writing TX_SEND with correct MUX ID 02 with relevant data change\n"); - - if (write(s, &txmsg, sizeof(txmsg)) < 0) - perror("write"); - - if ((nbytes = read(s, &rxmsg, sizeof(rxmsg))) < 0) - perror("read"); - - ioctl(s, SIOCGSTAMP, &tv); - printf("(%ld.%06ld) ", tv.tv_sec, tv.tv_usec); - - if (rxmsg.msg_head.opcode == RX_CHANGED && - nbytes == sizeof(struct bcm_msg_head) + sizeof(struct can_frame) && - rxmsg.msg_head.can_id == 0x42 && rxmsg.frame[0].can_id == 0x42) { - printf("<10>Received correct RX_CHANGED message for can_id <%03X> >> OK!\n", - rxmsg.frame[0].can_id); - } - - txmsg.msg_head.opcode = TX_SEND; - txmsg.msg_head.nframes = 1; - txmsg.frame[0].can_id = 0x42; - txmsg.frame[0].can_dlc = 7; - U64_DATA(&txmsg.frame[0]) = (__u64) 0x0200000000000001ULL; - - printf("<11>Writing TX_SEND with correct MUX ID 02 no data change but DLC\n"); - - if (write(s, &txmsg, sizeof(txmsg)) < 0) - perror("write"); - - if ((nbytes = read(s, &rxmsg, sizeof(rxmsg))) < 0) - perror("read"); - - if (rxmsg.msg_head.opcode == RX_CHANGED && - nbytes == sizeof(struct bcm_msg_head) + sizeof(struct can_frame) && - rxmsg.msg_head.can_id == 0x42 && rxmsg.frame[0].can_id == 0x42) { - printf("<11>Received correct RX_CHANGED message for can_id <%03X> >> OK!\n", - rxmsg.frame[0].can_id); - } - - txmsg.msg_head.opcode = TX_SEND; - txmsg.msg_head.nframes = 1; - txmsg.frame[0].can_id = 0x42; - txmsg.frame[0].can_dlc = 7; - U64_DATA(&txmsg.frame[0]) = (__u64) 0x0300000000000001ULL; - - printf("<12>Writing TX_SEND with wrong MUX ID 03\n"); - - if (write(s, &txmsg, sizeof(txmsg)) < 0) - perror("write"); - - if ((nbytes = read(s, &rxmsg, sizeof(rxmsg))) < 0) - perror("read"); - - ioctl(s, SIOCGSTAMP, &tv); - printf("(%ld.%06ld) ", tv.tv_sec, tv.tv_usec); - - if (rxmsg.msg_head.opcode == RX_TIMEOUT && - nbytes == sizeof(struct bcm_msg_head) && - rxmsg.msg_head.can_id == 0x42) { - printf("<-->Received correct RX_TIMEOUT message for can_id <%03X> >> OK!\n", - rxmsg.msg_head.can_id); - } - - close(s); - - return 0; -} \ No newline at end of file diff --git a/testcases/network/can/filter-tests/tst-bcm-rtr.c b/testcases/network/can/filter-tests/tst-bcm-rtr.c deleted file mode 100644 index 955864d..0000000 --- a/testcases/network/can/filter-tests/tst-bcm-rtr.c +++ /dev/null @@ -1,145 +0,0 @@ -/* - * $Id: tst-bcm-rtr.c,v 1.1 2009/03/02 15:33:55 subrata_modak Exp $ - */ - -/* - * tst-bcm-rtr.c - * - * Copyright (c) 2002-2007 Volkswagen Group Electronic Research - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of Volkswagen nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * Alternatively, provided that this notice is retained in full, this - * software may be distributed under the terms of the GNU General - * Public License ("GPL") version 2, in which case the provisions of the - * GPL apply INSTEAD OF those given above. - * - * The provided data structures and external interfaces from this code - * are not restricted to be used by modules with a GPL compatible license. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH - * DAMAGE. - * - * Send feedback to <soc...@li...> - * - */ - -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <string.h> - -#include <sys/types.h> -#include <sys/socket.h> -#include <sys/ioctl.h> -#include <sys/uio.h> -#include <net/if.h> - -#include <linux/can.h> -#include <linux/can/bcm.h> - -#define RTR_SETUP - -int main(int argc, char **argv) -{ - int s,nbytes; - struct sockaddr_can addr; - struct ifreq ifr; - - struct timeval tv; - - struct { - struct bcm_msg_head msg_head; - struct can_frame frame; - } txmsg, rxmsg; - - if ((s = socket(PF_CAN, SOCK_DGRAM, CAN_BCM)) < 0) { - perror("socket"); - return 1; - } - - addr.can_family = PF_CAN; - strcpy(ifr.ifr_name, "vcan2"); - ioctl(s, SIOCGIFINDEX, &ifr); - addr.can_ifindex = ifr.ifr_ifindex; - - if (connect(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) { - perror("connect"); - return 1; - } - -#ifdef RTR_SETUP - /* specify CAN-Frame to send as reply to a RTR-request */ - txmsg.msg_head.opcode = RX_SETUP; - txmsg.msg_head.can_id = 0x359 | CAN_RTR_FLAG; - txmsg.msg_head.flags = RX_RTR_FRAME; /* | TX_CP_CAN_ID */; - txmsg.msg_head.ival1.tv_sec = 0; /* no timers in RTR-mode */ - txmsg.msg_head.ival1.tv_usec = 0; - txmsg.msg_head.ival2.tv_sec = 0; - txmsg.msg_head.ival2.tv_usec = 0; - txmsg.msg_head.nframes = 1; /* exact 1 */ - - /* the frame to send as reply ... */ - txmsg.frame.can_id = 0x359; /* 'should' be the same */ - txmsg.frame.can_dlc = 3; - txmsg.frame.data[0] = 0x12; - txmsg.frame.data[1] = 0x34; - txmsg.frame.data[2] = 0x56; - -#else - /* normal receiption of RTR-frames in Userspace */ - txmsg.msg_head.opcode = RX_SETUP; - txmsg.msg_head.can_id = 0x359 | CAN_RTR_FLAG; - txmsg.msg_head.flags = RX_FILTER_ID; - txmsg.msg_head.ival1.tv_sec = 0; - txmsg.msg_head.ival1.tv_usec = 0; - txmsg.msg_head.ival2.tv_sec = 0; - txmsg.msg_head.ival2.tv_usec = 0; - txmsg.msg_head.nframes = 0; -#endif - - if (write(s, &txmsg, sizeof(txmsg)) < 0) - perror("write"); - - while (1) { - - if ((nbytes = read(s, &rxmsg, sizeof(rxmsg))) < 0) - perror("read"); - - ioctl(s, SIOCGSTAMP, &tv); - printf("(%ld.%06ld) ", tv.tv_sec, tv.tv_usec); - - if (rxmsg.msg_head.opcode == RX_CHANGED && - nbytes == sizeof(struct bcm_msg_head) + sizeof(struct can_frame) && - (rxmsg.msg_head.can_id & CAN_SFF_MASK) == 0x359 && - (rxmsg.frame.can_id & CAN_SFF_MASK) == 0x359) { - printf("RX_CHANGED message for can_id <%03X> RTR = %d\n", - rxmsg.frame.can_id, (rxmsg.frame.can_id & CAN_RTR_FLAG)?1:0); - } - } - - close(s); - - return 0; -} \ No newline at end of file diff --git a/testcases/network/can/filter-tests/tst-bcm-rx-sendto.c b/testcases/network/can/filter-tests/tst-bcm-rx-sendto.c deleted file mode 100644 index 7d3dcaf..0000000 --- a/testcases/network/can/filter-tests/tst-bcm-rx-sendto.c +++ /dev/null @@ -1,162 +0,0 @@ -/* - * $Id: tst-bcm-rx-sendto.c,v 1.1 2009/03/02 15:33:55 subrata_modak Exp $ - */ - -/* - * tst-bcm-rx-sendto.c - * - * Copyright (c) 2002-2007 Volkswagen Group Electronic Research - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of Volkswagen nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * Alternatively, provided that this notice is retained in full, this - * software may be distributed under the terms of the GNU General - * Public License ("GPL") version 2, in which case the provisions of the - * GPL apply INSTEAD OF those given above. - * - * The provided data structures and external interfaces from this code - * are not restricted to be used by modules with a GPL compatible license. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH - * DAMAGE. - * - * Send feedback to <soc...@li...> - * - */ - -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <string.h> - -#include <sys/types.h> -#include <sys/socket.h> -#include <sys/ioctl.h> -#include <sys/uio.h> -#include <net/if.h> - -#include <linux/can.h> -#include <linux/can/bcm.h> - -int main(int argc, char **argv) -{ - int s,nbytes; - struct sockaddr_can addr; - struct ifreq ifr; - - struct timeval tv; - - struct { - struct bcm_msg_head msg_head; - struct can_frame frame; - } txmsg, rxmsg; - - if ((s = socket(PF_CAN, SOCK_DGRAM, CAN_BCM)) < 0) { - perror("socket"); - return 1; - } - - addr.can_family = PF_CAN; - addr.can_ifindex = 0; /* bind to 'any' device */ - - if (connect(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) { - perror("connect"); - return 1; - } - - memset(&txmsg, 0, sizeof(txmsg)); /* clear timers, nframes, etc. */ - - txmsg.msg_head.opcode = RX_SETUP; - txmsg.msg_head.can_id = 0x123; - txmsg.msg_head.flags = RX_FILTER_ID; - - if (write(s, &txmsg, sizeof(txmsg)) < 0) - perror("write"); - - addr.can_family = PF_CAN; - strcpy(ifr.ifr_name, "vcan2"); - ioctl(s, SIOCGIFINDEX, &ifr); - addr.can_ifindex = ifr.ifr_ifindex; - - txmsg.msg_head.opcode = RX_SETUP; - txmsg.msg_head.can_id = 0x321; - txmsg.msg_head.flags = RX_FILTER_ID; - - if (sendto(s, &txmsg, sizeof(txmsg), 0, (struct sockaddr*)&addr, sizeof(addr)) < 0) - perror("sendto"); - - addr.can_family = PF_CAN; - strcpy(ifr.ifr_name, "vcan1"); - ioctl(s, SIOCGIFINDEX, &ifr); - addr.can_ifindex = ifr.ifr_ifindex; - - txmsg.msg_head.opcode = RX_SETUP; - txmsg.msg_head.can_id = 0x424; - txmsg.msg_head.flags = RX_FILTER_ID; - - if (sendto(s, &txmsg, sizeof(txmsg), 0, (struct sockaddr*)&addr, sizeof(addr)) < 0) - perror("sendto"); - - while (1) { - socklen_t len = sizeof(addr); - nbytes = recvfrom(s, &rxmsg, sizeof(rxmsg), - 0, (struct sockaddr*)&addr, &len); - if (nbytes < 0) { - perror("recvfrom"); - return 1; - } else if (nbytes < sizeof(rxmsg)) { - fprintf(stderr, "recvfrom: incomplete BCM message from iface %d\n", - addr.can_ifindex); - return 1; - } else { - int i; - - ioctl(s, SIOCGSTAMP, &tv); - printf("(%ld.%06ld) ", tv.tv_sec, tv.tv_usec); - - ifr.ifr_ifindex = addr.can_ifindex; - ioctl(s, SIOCGIFNAME, &ifr); - - printf(" %-5s ", ifr.ifr_name); - if (rxmsg.frame.can_id & CAN_EFF_FLAG) - printf("%8X ", rxmsg.frame.can_id & CAN_EFF_MASK); - else - printf("%3X ", rxmsg.frame.can_id & CAN_SFF_MASK); - - printf("[%d] ", rxmsg.frame.can_dlc); - - for (i = 0; i < rxmsg.frame.can_dlc; i++) { - printf("%02X ", rxmsg.frame.data[i]); - } - if (rxmsg.frame.can_id & CAN_RTR_FLAG) - printf("remote request"); - printf("\n"); - fflush(stdout); - } - } - - close(s); - - return 0; -} \ No newline at end of file diff --git a/testcases/network/can/filter-tests/tst-bcm-server.c b/testcases/network/can/filter-tests/tst-bcm-server.c deleted file mode 100644 index c057780..0000000 --- a/testcases/network/can/filter-tests/tst-bcm-server.c +++ /dev/null @@ -1,263 +0,0 @@ -/* - * $Id: tst-bcm-server.c,v 1.1 2009/03/02 15:33:55 subrata_modak Exp $ - */ - -/* - * tst-bcm-server.c - * - * Test programm that implements a socket server which understands ASCII - * messages for simple broadcast manager frame send commands. - * - * < interface command ival_s ival_us can_id can_dlc [data]* > - * - * The commands are 'A'dd, 'U'pdate, 'D'elete and 'S'end. - * e.g. - * - * Send the CAN frame 123#1122334455667788 every second on vcan1 - * < vcan1 A 1 0 123 8 11 22 33 44 55 66 77 88 > - * - * Send the CAN frame 123#1122334455667788 every 10 usecs on vcan1 - * < vcan1 A 0 10 123 8 11 22 33 44 55 66 77 88 > - * - * Send the CAN frame 123#42424242 every 20 msecs on vcan1 - * < vcan1 A 0 20000 123 4 42 42 42 42 > - * - * Update the CAN frame 123#42424242 with 123#112233 - no change of timers - * < vcan1 U 0 0 123 3 11 22 33 > - * - * Delete the cyclic send job from above - * < vcan1 D 0 0 123 0 > - * - * Send a single CAN frame without cyclic transmission - * < can0 S 0 0 123 0 > - * - * When the socket is closed the cyclic transmissions are terminated. - * - * Authors: - * Andre Naujoks (the socket server stuff) - * Oliver Hartkopp (the rest) - * - * Copyright (c) 2002-2007 Volkswagen Group Electronic Research - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - ... [truncated message content] |