From e7a59a9ea4a848655d37930f7fa3cf1b8c86bf2e Mon Sep 17 00:00:00 2001 From: Urs Thuermann Date: Mon, 24 Apr 2006 14:14:09 +0000 Subject: [PATCH] Initial import of llcf-2.0-pre2 --- Makefile | 65 +++++ can-sniffer.c | 697 ++++++++++++++++++++++++++++++++++++++++++++++++++ candump.c | 509 ++++++++++++++++++++++++++++++++++++ terminal.h | 99 +++++++ 4 files changed, 1370 insertions(+) create mode 100644 Makefile create mode 100644 can-sniffer.c create mode 100644 candump.c create mode 100644 terminal.h diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..17d4e13 --- /dev/null +++ b/Makefile @@ -0,0 +1,65 @@ +# +# $Id: Makefile,v 2.0 2006/04/13 10:37:20 ethuerm Exp $ +# +# Copyright (c) 2002-2005 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 + +CFLAGS = -O2 -Wall -Wno-parentheses -I../kernel/2.4/can -fno-strict-aliasing + +PROGRAMS_GPL = candump \ + can-sniffer + +PROGRAMS_VW = tpdump \ + tp20-sniffer \ + mcnet-vit-emu \ + mcnet-sniffer \ + pq35speed + +default: all-gpl + +all: all-gpl all-vw + +all-gpl: $(PROGRAMS_GPL) +all-vw: $(PROGRAMS_VW) + +clean: + rm -f $(PROGRAMS_GPL) $(PROGRAMS_VW) + +distclean: + rm -f $(PROGRAMS_GPL) $(PROGRAMS_VW) *~ diff --git a/can-sniffer.c b/can-sniffer.c new file mode 100644 index 0000000..e4b4243 --- /dev/null +++ b/can-sniffer.c @@ -0,0 +1,697 @@ +/* + * $Id: can-sniffer.c,v 2.0 2006/04/13 10:37:20 ethuerm Exp $ + */ + +/* + * can-sniffer.c + * + * Copyright (c) 2002-2005 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 + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "af_can.h" +#include "bcm.h" +#include "terminal.h" + +#define U64_DATA(p) (*(unsigned long long*)(p)->data) + +#define SETFNAME "sniffset." + +/* flags */ + +#define ENABLE 1 /* by filter or user */ +#define DISPLAY 2 /* is on the screen */ +#define UPDATE 4 /* needs to be printed on the screen */ +#define CLRSCR 8 /* clear screen in next loop */ + +/* flags testing & setting */ + +#define is_set(id, flag) (sniftab[id].flags & flag) +#define is_clr(id, flag) (!(sniftab[id].flags & flag)) + +#define do_set(id, flag) (sniftab[id].flags |= flag) +#define do_clr(id, flag) (sniftab[id].flags &= ~flag) + +/* time defaults */ + +#define TIMEOUT 50 /* in 100ms */ +#define HOLD 10 /* in 100ms */ +#define LOOP 2 /* in 100ms */ + +#define MAXANI 8 +const char anichar[MAXANI] = {'|', '/', '-', '\\', '|', '/', '-', '\\'}; + +#define ATTCOLOR ATTBOLD FGRED + +#define STARTLINESTR "X time ID data ... " + +struct snif { + int flags; + long hold; + long timeout; + struct timeval laststamp; + struct timeval currstamp; + struct can_frame last; + struct can_frame current; + struct can_frame marker; + struct can_frame notch; +} sniftab[2048]; + + +extern int optind, opterr, optopt; + +static int running = 1; +static int clearscreen = 1; +static int notch = 0; +static long timeout = TIMEOUT; +static long hold = HOLD; +static long loop = LOOP; +static unsigned char binary = 0; +static unsigned char color = 0; + +void rx_setup (int fd, int id); +void rx_delete (int fd, int id); +void print_snifline(int id); +int handle_keyb(int fd); +int handle_bcm(int fd, long currcms); +int handle_timeo(int fd, long currcms); +void writesettings(char* name); +void readsettings(char* name, int sockfd); + +void print_usage(char *prg) +{ + const char manual [] = { + "commands that can be entered at runtime:\n" + "\n" + "q - quit\n" + "b - toggle binary / HEX-ASCII output\n" + "c - toggle color mode\n" + "# - notch currently marked/changed bits (can be used repeatedly)\n" + "* - clear notched marked\n" + "rMYNAME - read settings file (filter/notch)\n" + "wMYNAME - write settings file (filter/notch)\n" + "+FILTER - add CAN-IDs to sniff\n" + "-FILTER - remove CAN-IDs to sniff\n" + "\n" + "FILTER can be a single CAN-ID or a CAN-ID/Bitmask:\n" + "+1F5 - add CAN-ID 0x1F5\n" + "-42E - remove CAN-ID 0x42E\n" + "-42E7FF - remove CAN-ID 0x42E (using Bitmask)\n" + "-500700 - remove CAN-IDs 0x500 - 0x5FF\n" + "+400600 - add CAN-IDs 0x400 - 0x5FF\n" + "+000000 - add all CAN-IDs\n" + "-000000 - remove all CAN-IDs\n" + "\n" + "if (id & filter) == (sniff-id & filter) the action (+/-) is performed,\n" + "which is quite easy when the filter is 000\n" + "\n" + }; + + fprintf(stderr, "\nUsage: %s [can-interface]\n", prg); + fprintf(stderr, "Options: -m (initial FILTER default 0x00000000)\n"); + fprintf(stderr, " -v (initial FILTER default 0x00000000)\n"); + fprintf(stderr, " -q (quiet - all IDs deactivated)\n"); + fprintf(stderr, " -r (read %sname from file)\n", SETFNAME); + fprintf(stderr, " -b (start with binary mode)\n"); + fprintf(stderr, " -c (color changes)\n"); + fprintf(stderr, " -t