├── config └── m4 │ └── .secret-world-domination-project ├── test.c ├── README.md ├── old_include └── mac │ ├── mac_os_types.h │ ├── can │ ├── raw.h │ ├── netlink.h │ ├── bcm.h │ ├── error.h │ ├── isotp.h │ └── gw.h │ ├── if.h │ └── can.h ├── x └── can │ ├── lib │ ├── types.h │ └── can.h │ ├── raw.h │ ├── gw.h │ ├── netlink.h │ ├── bcm.h │ └── error.h ├── autogen.sh ├── .gitignore ├── LICENSE ├── slcand.c ├── GNUmakefile.am ├── configure.ac ├── log2long.c ├── terminal.h ├── canframelen.h ├── Makefile ├── cansend.c ├── log2asc.c ├── slcan_attach.c ├── Android.mk ├── isotprecv.c ├── lib.h ├── isotpsend.c ├── canfdtest.c ├── bcmserver.c ├── isotpsniffer.c ├── canframelen.c ├── asc2log.c ├── isotpdump.c └── isotptun.c /config/m4/.secret-world-domination-project: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test.c: -------------------------------------------------------------------------------- 1 | #include "x/can/bcm.h" 2 | #include "x/can/error.h" 3 | #include "x/can/gw.h" 4 | #include "x/can/netlink.h" 5 | #include "x/can/raw.h" 6 | 7 | int main() 8 | { 9 | return 0; 10 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # can-utils-osx 2 | the popular Linux based can-utils and SocketCAN now available for OS X 3 | 4 | WARNING: this is a new open source project that is very much a Work in Progress. 5 | 6 | To build use `gcc -o scx test.c` 7 | -------------------------------------------------------------------------------- /old_include/mac/mac_os_types.h: -------------------------------------------------------------------------------- 1 | #ifndef mac_os_types_h 2 | #define mac_os_types_h 3 | 4 | #ifdef __linux__ 5 | # include "linux/types.h" 6 | #else 7 | # include 8 | typedef int32_t __s32; 9 | typedef uint32_t __u32; 10 | typedef uint8_t __u8; 11 | typedef uint16_t __u16; 12 | #endif 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /x/can/lib/types.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | typedef int32_t __s32; /* signed 32 b */ 4 | typedef uint32_t __u32; /* unsigned 32 b */ 5 | 6 | typedef uint8_t __u8; /* unsigned 8 b */ 7 | typedef int8_t __s8; /* signed 8 b */ 8 | 9 | typedef uint16_t __u16; /* unsigned 16 b */ 10 | typedef int16_t __s16; /* signed 16 b */ 11 | 12 | typedef __uint8_t sa_family_t; -------------------------------------------------------------------------------- /x/can/raw.h: -------------------------------------------------------------------------------- 1 | #ifndef _UAPI_CAN_RAW_H 2 | #define _UAPI_CAN_RAW_H 3 | 4 | #include 5 | #include "lib/can.h" 6 | 7 | #define SOL_CAN_RAW (SOL_CAN_BASE + CAN_RAW) 8 | 9 | enum { 10 | CAN_RAW_FILTER = 1, 11 | CAN_RAW_ERR_FILTER, 12 | CAN_RAW_LOOPBACK, 13 | CAN_RAW_RECV_OWN_MSGS, 14 | CAN_RAW_FD_FRAMES, 15 | CAN_RAW_JOIN_FILTERS 16 | }; 17 | 18 | #endif /* !_UAPI_CAN_RAW_H */ -------------------------------------------------------------------------------- /autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 4 | # usage: 5 | # 6 | # banner 7 | # 8 | banner() { 9 | echo 10 | TG=`echo $1 | sed -e "s,/.*/,,g"` 11 | LINE=`echo $TG |sed -e "s/./-/g"` 12 | echo $LINE 13 | echo $TG 14 | echo $LINE 15 | echo 16 | } 17 | 18 | banner "autoreconf" 19 | glibtoolize 20 | aclocal 21 | autoreconf --force --install -Wall || exit $? 22 | automake --add-missing 23 | 24 | banner "Finished" 25 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | *.o 3 | *.lo 4 | *.la 5 | .deps 6 | .libs 7 | 8 | configure 9 | libtool 10 | GNUmakefile 11 | GNUmakefile.in 12 | 13 | /aclocal.m4 14 | /autom4te.cache/ 15 | /config.log 16 | /config.status 17 | /config/autoconf/ 18 | /config/m4/libtool.m4 19 | /config/m4/ltoptions.m4 20 | /config/m4/ltsugar.m4 21 | /config/m4/ltversion.m4 22 | /config/m4/lt~obsolete.m4 23 | 24 | /asc2log 25 | /bcmserver 26 | /can-calc-bit-timing 27 | /canbusload 28 | /candump 29 | /canfdtest 30 | /cangen 31 | /cangw 32 | /canlogserver 33 | /canplayer 34 | /cansend 35 | /cansniffer 36 | /isotpdump 37 | /isotpperf 38 | /isotprecv 39 | /isotpsend 40 | /isotpserver 41 | /isotpsniffer 42 | /isotptun 43 | /log2asc 44 | /log2long 45 | /slcan_attach 46 | /slcand 47 | /slcanpty 48 | 49 | /can-utils-*.tar.bz2 50 | /can-utils-*.tar.gz 51 | 52 | **.swp 53 | **.swo 54 | **.swa 55 | 56 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 Carloop 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /slcand.c: -------------------------------------------------------------------------------- 1 | /** 2 | * slcand.c - userspace daemon for serial line CAN interface driver SLCAN 3 | * rewritten from it's original source in C to the OS X. 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | /* Daemon name */ 24 | #define DAEMON_NAME "slcandx" 25 | 26 | /* Run under this specific user */ 27 | #define RUN_AS_USER "root" 28 | 29 | /* The length of ttypath buffer */ 30 | #define TTYPATH_LENGTH 64 31 | 32 | /* UART flow control types */ 33 | #define FLOW_NONE 0 34 | #define FLOW_HW 1 35 | #define FLOW_SW 2 36 | 37 | void print_usage(char *prg) 38 | { 39 | fprintf(stderr, "\nUsage: %s \n\n", prg); 40 | exit(EXIT_FAILURE); 41 | } 42 | 43 | static int slcand_running; 44 | static int exit_code; 45 | static char ttypath[TTYPATH_LENGTH]; 46 | 47 | int main(int argc, char *argv[]) 48 | { 49 | char *tty = NULL; 50 | char const *devprefix = "/dev"; 51 | char *name = NULL; 52 | char buf[IFNAMSIZ+1]; 53 | } 54 | -------------------------------------------------------------------------------- /GNUmakefile.am: -------------------------------------------------------------------------------- 1 | ACLOCAL_AMFLAGS = -I config/m4 2 | 3 | AM_CPPFLAGS = \ 4 | -I$(top_srcdir)/include \ 5 | -I$(top_builddir)/include \ 6 | $(linux_CFLAGS) 7 | 8 | # link every app against libcan, it's static so it wouldn't hurt 9 | LDADD = \ 10 | libcan.la 11 | 12 | noinst_HEADERS = \ 13 | canframelen.h \ 14 | lib.h \ 15 | terminal.h \ 16 | include/mac/can/bcm.h \ 17 | include/mac/can/error.h \ 18 | include/mac/can/gw.h \ 19 | include/mac/can.h \ 20 | include/mac/can/isotp.h \ 21 | include/mac/can/netlink.h \ 22 | include/mac/can/raw.h 23 | 24 | 25 | noinst_LTLIBRARIES = \ 26 | libcan.la 27 | 28 | libcan_la_SOURCES = \ 29 | lib.c \ 30 | canframelen.c 31 | 32 | 33 | bin_PROGRAMS = \ 34 | asc2log \ 35 | bcmserver \ 36 | can-calc-bit-timing \ 37 | canbusload \ 38 | candump \ 39 | canfdtest \ 40 | cangen \ 41 | cangw \ 42 | canlogserver \ 43 | canplayer \ 44 | cansend \ 45 | cansniffer \ 46 | isotpdump \ 47 | isotpperf \ 48 | isotprecv \ 49 | isotpsend \ 50 | isotpserver \ 51 | isotpsniffer \ 52 | isotptun \ 53 | log2asc \ 54 | log2long \ 55 | slcan_attach \ 56 | slcand \ 57 | slcanpty 58 | 59 | EXTRA_DIST = \ 60 | autogen.sh 61 | 62 | MAINTAINERCLEANFILES = \ 63 | configure \ 64 | GNUmakefile.in \ 65 | aclocal.m4 \ 66 | config/autoconf/compile \ 67 | config/autoconf/config.guess \ 68 | config/autoconf/config.sub \ 69 | config/autoconf/depcomp \ 70 | config/autoconf/install-sh \ 71 | config/autoconf/ltmain.sh \ 72 | config/autoconf/mdate-sh \ 73 | config/autoconf/missing \ 74 | config/autoconf/texinfo.tex \ 75 | config/m4/libtool.m4 \ 76 | config/m4/ltoptions.m4 \ 77 | config/m4/ltsugar.m4 \ 78 | config/m4/ltversion.m4 \ 79 | config/m4/lt~obsolete.m4 \ 80 | $(DIST_ARCHIVES) 81 | 82 | maintainer-clean-local: 83 | -chmod -R a+rw $(distdir) 84 | -rm -fr $(distdir) 85 | -------------------------------------------------------------------------------- /x/can/gw.h: -------------------------------------------------------------------------------- 1 | #ifndef _UAPI_CAN_GW_H 2 | #define _UAPI_CAN_GW_H 3 | 4 | #include 5 | #include "lib/can.h" 6 | 7 | struct rtcanmsg { 8 | __u8 can_family; 9 | __u8 gwtype; 10 | __u16 flags; 11 | }; 12 | 13 | enum { 14 | CGW_TYPE_UNSPEC, 15 | CGW_TYPE_CAN_CAN, 16 | __CGW_TYPE_MAX 17 | }; 18 | 19 | #define CGW_TYPE_MAX (__CGW_TYPE_MAX - 1) 20 | 21 | enum { 22 | CGW_UNSPEC, 23 | CGW_MOD_AND, 24 | CGW_MOD_OR, 25 | CGW_MOD_XOR, 26 | CGW_MOD_SET, 27 | CGW_CS_XOR, 28 | CGW_CS_CRC8, 29 | CGW_HANDLED, 30 | CGW_DROPPED, 31 | CGW_SRC_IF, 32 | CGW_DST_IF, 33 | CGW_FILTER, 34 | CGW_DELETED, 35 | CGW_LIM_HOPS, 36 | CGW_MOD_UID, 37 | __CGW_MAX 38 | }; 39 | 40 | #define CGW_MAX (__CGW_MAX - 1) 41 | 42 | #define CGW_FLAGS_CAN_ECHO 0x01 43 | #define CGW_FLAGS_CAN_SRC_TSTAMP 0x02 44 | #define CGW_FLAGS_CAN_IIF_TX_OK 0x04 45 | 46 | #define CGW_MOD_FUNCS 4 47 | 48 | #define CGW_MOD_ID 0x01 49 | #define CGW_MOD_DLC 0x02 50 | #define CGW_MOD_DATA 0x04 51 | 52 | #define CGW_FRAME_MODS 3 53 | 54 | #define MAX_MODFUNCTIONS (CGW_MOD_FUNC * CGW_FRAME_MODS) 55 | 56 | struct cgw_frame_mod { 57 | struct can_frame ct; 58 | __u8 modtype; 59 | } __attribute__((packed)); 60 | 61 | #define CGW_MODATTR_LEN sizeof(struct cgw_frame_mod) 62 | 63 | struct cgw_csum_xor { 64 | __s8 from_idx; 65 | __s8 to_idx; 66 | __s8 result_idx; 67 | __u8 init_xor_val; 68 | } __attribute__((packed)); 69 | 70 | struct cgw_csum_crc8 { 71 | __s8 from_idx; 72 | __s8 to_idx; 73 | __s8 result_idx; 74 | __u8 init_crc_val; 75 | __u8 final_xor_val; 76 | __u8 crctab[256]; 77 | __u8 profile; 78 | __u8 profile_data[20]; 79 | } __attribute__((packed)); 80 | 81 | #define CGW_CS_XOR_LEN sizeof(struct cgw_csum_xor) 82 | #define CGW_CS_CRC8_LEN sizeof(struct cgw_csum_crc8) 83 | 84 | enum { 85 | CGW_CRC8PRF_UNSPEC, 86 | CGW_CRC8PRF_1U8, 87 | CGW_CRC8PRF_16U8, 88 | CGW_CRC8PRF_SFFID_XOR, 89 | __CGW_CRC8PRF_MAX 90 | }; 91 | 92 | #define CGW_CRC8PRF_MAX (__CGW_CRC8PRF_MAX - 1) 93 | 94 | #endif /* !_UAPI_CAN_GW_H */ -------------------------------------------------------------------------------- /x/can/netlink.h: -------------------------------------------------------------------------------- 1 | #ifndef _UAPI_CAN_NETLINK_H 2 | #define _UAPI_CAN_NETLINK_H 3 | 4 | #include 5 | 6 | /* CAN bit-timing params from can specs */ 7 | struct can_bittiming { 8 | __u32 bitrate; 9 | __u32 sample_point; 10 | __u32 tq; 11 | __u32 prop_seg; 12 | __u32 phase_seg1; 13 | __u32 phase_seg2; 14 | __u32 sjw; 15 | __u32 brp; 16 | }; 17 | 18 | /* CAN hardware-dependent bit-timing constant */ 19 | struct can_bittiming_const { 20 | char name[16]; 21 | __u32 tseg1_mix; 22 | __u32 tsef1_max; 23 | __u32 tseg2_min; 24 | __u32 tseg2_max; 25 | __u32 sjw_max; 26 | __u32 brp_min; 27 | __u32 brp_max; 28 | __u32 brp_inc; 29 | }; 30 | 31 | /* CAN clock params */ 32 | struct can_clock { 33 | __u32 freq; 34 | }; 35 | 36 | /* CAN ops and state */ 37 | enum can_state { 38 | CAN_STATE_ERROR_ACTIVE = 0, 39 | CAN_STATE_ERROR_WARNING, 40 | CAN_STATE_ERROR_PASSIVE, 41 | CAN_STATE_BUS_OFF, 42 | CAN_STATE_STOPPED, 43 | CAN_STATE_SLEEPING, 44 | CAN_STATE_MAX 45 | }; 46 | 47 | /* CAN bus error counters */ 48 | struct can_berr_counter { 49 | __u16 txerr; 50 | __u16 rxerr; 51 | }; 52 | 53 | /* CAN controller mode */ 54 | struct can_ctrlmode { 55 | __u32 mask; 56 | __u32 flags; 57 | }; 58 | 59 | #define CAN_CTRLMODE_LOOPBACK 0x01 60 | #define CAN_CTRLMODE_LISTENONLY 0x02 61 | #define CAN_CTRLMODE_3_SAMPLES 0x04 62 | #define CAN_CTRLMODE_ONE_SHOT 0x08 63 | #define CAN_CTRLMODE_BERR_REPORTING 0x10 64 | #define CAN_CTRLMODE_FD 0x20 65 | #define CAN_CTRLMODE_PRESUME_ACK 0x40 66 | #define CAN_CTRLMODE_FD_NON_ISO 0x80 67 | 68 | /* CAN device statistics */ 69 | struct can_device_stats { 70 | __u32 bus_error; 71 | __u32 error_warning; 72 | __u32 error_passive; 73 | __u32 bus_off; 74 | __u32 arbitration_lost; 75 | __u32 restarts; 76 | }; 77 | 78 | /* CAN netlink interface */ 79 | enum { 80 | IFLA_CAN_UNSPEC, 81 | IFLA_CAN_BITTIMING, 82 | IFLA_CAN_BITTIMING_CONST, 83 | IFLA_CAN_CLOCK, 84 | IFLA_CAN_STATE, 85 | IFLA_CAN_CTRLMODE, 86 | IFLA_CAN_RESTART_MS, 87 | IFLA_CAN_RESTART, 88 | IFLA_CAN_BERR_COUNTER, 89 | IFLA_CAN_DATA_BITTIMING, 90 | IFLA_CAN_DATA_BITTIMING_CONST, 91 | __IFLA_CAN_MAX 92 | }; 93 | 94 | #define IFLA_CAN_MAX (__IFLA_CAN_MAX - 1) 95 | 96 | #endif /* !_UAPI_CAN_NETLINK_H */ -------------------------------------------------------------------------------- /x/can/bcm.h: -------------------------------------------------------------------------------- 1 | /* 2 | * x/can/bcm.h 3 | * 4 | * Definitions for CAN Broadcast Manager (BCM) 5 | * 6 | * @author Halis Duraki 7 | * /usr/include/duraki 8 | */ 9 | 10 | #ifndef _UAPI_CAN_BCM_H 11 | #define _UAPI_CAN_BCM_H 12 | 13 | #include 14 | #include "lib/can.h" 15 | 16 | struct bcm_timeval { 17 | long tv_sec; 18 | long tv_usec; 19 | }; 20 | 21 | /** 22 | * struct bcm_msg_head - head of messages to/from the broadcast manager 23 | * @opcode: opcode, see enum below. 24 | * @flags: special flags, see below. 25 | * @count: number of frames to send before changing interval. 26 | * @ival1: interval for the first @count frames. 27 | * @ival2: interval for the following frames. 28 | * @can_id: CAN ID of frames to be sent or received. 29 | * @nframes: number of frames appended to the message head. 30 | * @frames: array of CAN frames. 31 | */ 32 | struct bcm_msg_head { 33 | __u32 opcode; 34 | __u32 flags; 35 | __u32 count; 36 | struct bcm_timeval ival1, ival2; 37 | canid_t can_id; 38 | __u32 nframes; 39 | struct can_frame frames[0]; 40 | }; 41 | 42 | enum { 43 | TX_SETUP = 1, /* create (cyclic) transmission task */ 44 | TX_DELETE, /* remove (cyclic) transmission task */ 45 | TX_READ, /* read properties of (cyclic) transmission task */ 46 | TX_SEND, /* send one CAN frame */ 47 | RX_SETUP, /* create RX content filter subscription */ 48 | RX_DELETE, /* remove RX content filter subscription */ 49 | RX_READ, /* read properties of RX content filter subscription */ 50 | TX_STATUS, /* reply to TX_READ request */ 51 | TX_EXPIRED, /* notification on performed transmissions (count=0) */ 52 | RX_STATUS, /* reply to RX_READ request */ 53 | RX_TIMEOUT, /* cyclic message is absent */ 54 | RX_CHANGED /* updated CAN frame (detected content change) */ 55 | }; 56 | 57 | #define SETTIMER 0x0001 58 | #define STARTIMER 0x0002 59 | #define TX_COUNTEVT 0x0004 60 | #define TX_ANNOUNCE 0x0008 61 | #define TX_CP_CAN_ID 0x0001 62 | #define RX_FILTER_ID 0x0020 63 | #define RX_CHECK_DLC 0x0040 64 | #define RX_NO_AUTOTIMER 0x0080 65 | #define RX_ANNOUNCE_RESUME 0x0100 66 | #define TX_RESET_MULTI_IDX 0x0200 67 | #define RX_RTR_FRAME 0x0400 68 | 69 | #endif /* !_UAPI_CAN_BCM_H */ -------------------------------------------------------------------------------- /configure.ac: -------------------------------------------------------------------------------- 1 | # -*- Autoconf -*- 2 | # Process this file with autoconf to produce a configure script. 3 | AC_PREREQ([2.59]) 4 | 5 | AC_INIT([can-utils],[trunk],[linux-can@vger.kernel.org]) 6 | AC_CONFIG_SRCDIR([lib.c]) 7 | AC_CONFIG_MACRO_DIR([config/m4]) 8 | AC_CONFIG_AUX_DIR([config/autoconf]) 9 | AC_CANONICAL_BUILD 10 | AC_CANONICAL_HOST 11 | 12 | #AM_MAINTAINER_MODE 13 | 14 | CFLAGS="${CFLAGS} -Wall" 15 | 16 | # 17 | # Checks for programs. 18 | # 19 | AC_PROG_CC 20 | LT_INIT(win32-dll) 21 | 22 | AM_INIT_AUTOMAKE([foreign no-exeext dist-bzip2]) 23 | m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) 24 | 25 | # 26 | # Checks for header files. 27 | # 28 | AC_CHECK_HEADERS([ \ 29 | fcntl.h \ 30 | limits.h \ 31 | locale.h \ 32 | stdint.h \ 33 | stdlib.h \ 34 | string.h \ 35 | syslog.h \ 36 | termios.h \ 37 | unistd.h \ 38 | \ 39 | netinet/in.h \ 40 | \ 41 | sys/ioctl.h \ 42 | sys/socket.h \ 43 | sys/time.h \ 44 | ]) 45 | 46 | 47 | # 48 | # Checks for typedefs, structures, and compiler characteristics. 49 | # 50 | AC_C_INLINE 51 | AC_SYS_LARGEFILE 52 | AC_TYPE_OFF_T 53 | AC_TYPE_PID_T 54 | AC_TYPE_UINT64_T 55 | 56 | 57 | # 58 | # Checks for library functions. 59 | # 60 | AC_FUNC_FORK 61 | AC_FUNC_MKTIME 62 | AC_CHECK_FUNCS([ \ 63 | alarm \ 64 | gettimeofday \ 65 | localtime_r \ 66 | memset \ 67 | select \ 68 | setlocale \ 69 | socket \ 70 | strchr \ 71 | strerror \ 72 | strstr \ 73 | strtoul \ 74 | ]) 75 | 76 | 77 | AC_CHECK_DECL(SO_RXQ_OVFL,, 78 | [AC_DEFINE([SO_RXQ_OVFL], [40], [SO_RXQ_OVFL])] 79 | ) 80 | AC_CHECK_DECL(PF_CAN,, 81 | [AC_DEFINE([PF_CAN], [29], [PF_CAN])] 82 | ) 83 | AC_CHECK_DECL(AF_CAN,, 84 | [AC_DEFINE([AF_CAN], [PF_CAN], [AF_CAN])] 85 | ) 86 | AC_CHECK_DECL(N_SLCAN,, 87 | [AC_DEFINE([N_SLCAN], [17], [N_SLCAN])] 88 | ) 89 | 90 | 91 | # 92 | # Debugging 93 | # 94 | AC_MSG_CHECKING([whether to enable debugging]) 95 | AC_ARG_ENABLE(debug, 96 | AS_HELP_STRING([--enable-debug], [enable debugging [[default=no]]]), 97 | [case "$enableval" in 98 | (y | yes) CONFIG_DEBUG=yes ;; 99 | (*) CONFIG_DEBUG=no ;; 100 | esac], 101 | [CONFIG_DEBUG=no]) 102 | AC_MSG_RESULT([${CONFIG_DEBUG}]) 103 | if test "${CONFIG_DEBUG}" = "yes"; then 104 | CFLAGS="${CFLAGS} -Wsign-compare -Wfloat-equal -Wformat-security -g -O1" 105 | AC_DEFINE(DEBUG, 1, [debugging]) 106 | else 107 | CFLAGS="${CFLAGS} -O2" 108 | fi 109 | 110 | 111 | AC_CONFIG_FILES([ 112 | GNUmakefile 113 | ]) 114 | AC_OUTPUT 115 | -------------------------------------------------------------------------------- /old_include/mac/can/raw.h: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/can/raw.h 3 | * 4 | * Definitions for raw CAN sockets 5 | * 6 | * Authors: Oliver Hartkopp 7 | * Urs Thuermann 8 | * Copyright (c) 2002-2007 Volkswagen Group Electronic Research 9 | * All rights reserved. 10 | * 11 | * Redistribution and use in source and binary forms, with or without 12 | * modification, are permitted provided that the following conditions 13 | * are met: 14 | * 1. Redistributions of source code must retain the above copyright 15 | * notice, this list of conditions and the following disclaimer. 16 | * 2. Redistributions in binary form must reproduce the above copyright 17 | * notice, this list of conditions and the following disclaimer in the 18 | * documentation and/or other materials provided with the distribution. 19 | * 3. Neither the name of Volkswagen nor the names of its contributors 20 | * may be used to endorse or promote products derived from this software 21 | * without specific prior written permission. 22 | * 23 | * Alternatively, provided that this notice is retained in full, this 24 | * software may be distributed under the terms of the GNU General 25 | * Public License ("GPL") version 2, in which case the provisions of the 26 | * GPL apply INSTEAD OF those given above. 27 | * 28 | * The provided data structures and external interfaces from this code 29 | * are not restricted to be used by modules with a GPL compatible license. 30 | * 31 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 32 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 33 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 34 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 35 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 36 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 37 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 38 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 39 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 40 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 41 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 42 | * DAMAGE. 43 | */ 44 | 45 | #ifndef CAN_RAW_H 46 | #define CAN_RAW_H 47 | 48 | #include 49 | 50 | #define SOL_CAN_RAW (SOL_CAN_BASE + CAN_RAW) 51 | 52 | /* for socket options affecting the socket (not the global system) */ 53 | 54 | enum { 55 | CAN_RAW_FILTER = 1, /* set 0 .. n can_filter(s) */ 56 | CAN_RAW_ERR_FILTER, /* set filter for error frames */ 57 | CAN_RAW_LOOPBACK, /* local loopback (default:on) */ 58 | CAN_RAW_RECV_OWN_MSGS, /* receive my own msgs (default:off) */ 59 | CAN_RAW_FD_FRAMES, /* allow CAN FD frames (default:off) */ 60 | CAN_RAW_JOIN_FILTERS, /* all filters must match to trigger */ 61 | }; 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /log2long.c: -------------------------------------------------------------------------------- 1 | /* 2 | * log2long.c - convert compact CAN frame representation into user readable 3 | * 4 | * Copyright (c) 2002-2007 Volkswagen Group Electronic Research 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 3. Neither the name of Volkswagen nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * Alternatively, provided that this notice is retained in full, this 20 | * software may be distributed under the terms of the GNU General 21 | * Public License ("GPL") version 2, in which case the provisions of the 22 | * GPL apply INSTEAD OF those given above. 23 | * 24 | * The provided data structures and external interfaces from this code 25 | * are not restricted to be used by modules with a GPL compatible license. 26 | * 27 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 28 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 29 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 30 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 31 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 32 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 33 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 34 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 35 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 36 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 37 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 38 | * DAMAGE. 39 | * 40 | * Send feedback to 41 | * 42 | */ 43 | 44 | #include 45 | 46 | #include 47 | #include 48 | 49 | #include "lib.h" 50 | 51 | #define COMMENTSZ 200 52 | #define BUFSZ (sizeof("(1345212884.318850)") + IFNAMSIZ + 4 + CL_CFSZ + COMMENTSZ) /* for one line in the logfile */ 53 | 54 | int main(int argc, char **argv) 55 | { 56 | char buf[BUFSZ], timestamp[BUFSZ], device[BUFSZ], ascframe[BUFSZ]; 57 | struct canfd_frame cf; 58 | int mtu, maxdlen; 59 | 60 | while (fgets(buf, BUFSZ-1, stdin)) { 61 | if (sscanf(buf, "%s %s %s", timestamp, device, ascframe) != 3) 62 | return 1; 63 | 64 | mtu = parse_canframe(ascframe, &cf); 65 | if (mtu == CAN_MTU) 66 | maxdlen = CAN_MAX_DLEN; 67 | else if (mtu == CANFD_MTU) 68 | maxdlen = CANFD_MAX_DLEN; 69 | else { 70 | fprintf(stderr, "read: incomplete CAN frame\n"); 71 | return 1; 72 | } 73 | 74 | sprint_long_canframe(ascframe, &cf, 75 | (CANLIB_VIEW_INDENT_SFF | CANLIB_VIEW_ASCII), 76 | maxdlen); /* with ASCII output */ 77 | 78 | printf("%s %s %s\n", timestamp, device, ascframe); 79 | } 80 | 81 | return 0; 82 | } 83 | -------------------------------------------------------------------------------- /terminal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002-2007 Volkswagen Group Electronic Research 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. Neither the name of Volkswagen nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * Alternatively, provided that this notice is retained in full, this 18 | * software may be distributed under the terms of the GNU General 19 | * Public License ("GPL") version 2, in which case the provisions of the 20 | * GPL apply INSTEAD OF those given above. 21 | * 22 | * The provided data structures and external interfaces from this code 23 | * are not restricted to be used by modules with a GPL compatible license. 24 | * 25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 26 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 27 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 28 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 29 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 30 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 31 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 32 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 33 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 36 | * DAMAGE. 37 | * 38 | * Send feedback to 39 | * 40 | */ 41 | 42 | #ifndef TERMINAL_H 43 | #define TERMINAL_H 44 | 45 | /* reset to default */ 46 | 47 | #define ATTRESET "\33[0m" 48 | 49 | /* attributes */ 50 | 51 | #define ATTBOLD "\33[1m" 52 | #define ATTUNDERLINE "\33[4m" 53 | #define ATTBLINK "\33[5m" 54 | #define ATTINVERSE "\33[7m" 55 | #define ATTINVISIBLE "\33[8m" 56 | 57 | /* foreground colors */ 58 | 59 | #define FGBLACK "\33[30m" 60 | #define FGRED "\33[31m" 61 | #define FGGREEN "\33[32m" 62 | #define FGYELLOW "\33[33m" 63 | #define FGBLUE "\33[34m" 64 | #define FGMAGENTA "\33[35m" 65 | #define FGCYAN "\33[36m" 66 | #define FGWHITE "\33[37m" 67 | 68 | /* background colors */ 69 | 70 | #define BGBLACK "\33[40m" 71 | #define BGRED "\33[41m" 72 | #define BGGREEN "\33[42m" 73 | #define BGYELLOW "\33[43m" 74 | #define BGBLUE "\33[44m" 75 | #define BGMAGENTA "\33[45m" 76 | #define BGCYAN "\33[46m" 77 | #define BGWHITE "\33[47m" 78 | 79 | /* cursor */ 80 | 81 | #define CSR_HOME "\33[H" 82 | #define CSR_UP "\33[A" 83 | #define CSR_DOWN "\33[B" 84 | #define CSR_RIGHT "\33[C" 85 | #define CSR_LEFT "\33[D" 86 | 87 | #define CSR_HIDE "\33[?25l" 88 | #define CSR_SHOW "\33[?25h" 89 | 90 | /* clear screen */ 91 | 92 | #define CLR_SCREEN "\33[2J" 93 | 94 | #endif /* TERMINAL_H */ 95 | -------------------------------------------------------------------------------- /canframelen.h: -------------------------------------------------------------------------------- 1 | /* 2 | * canframelen.h 3 | * 4 | * Copyright (c) 2013, 2014 Czech Technical University in Prague 5 | * 6 | * Author: Michal Sojka 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 3. Neither the name of Czech Technical University in Prague nor the 17 | * names of its contributors may be used to endorse or promote 18 | * products derived from this software without specific prior 19 | * written permission. 20 | * 21 | * Alternatively, provided that this notice is retained in full, this 22 | * software may be distributed under the terms of the GNU General 23 | * Public License ("GPL") version 2, in which case the provisions of the 24 | * GPL apply INSTEAD OF those given above. 25 | * 26 | * The provided data structures and external interfaces from this code 27 | * are not restricted to be used by modules with a GPL compatible license. 28 | * 29 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 30 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 31 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 32 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 33 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 34 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 35 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 36 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 37 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 38 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 39 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 40 | * DAMAGE. 41 | * 42 | * Send feedback to 43 | * 44 | */ 45 | 46 | #ifndef CANFRAMELEN_H 47 | #define CANFRAMELEN_H 48 | 49 | #include 50 | 51 | /** 52 | * Frame length calculation modes. 53 | * 54 | * CFL_WORSTCASE corresponds to *worst* case calculation for 55 | * stuff-bits - see (1)-(3) in [1]. The worst case number of bits on 56 | * the wire can be calculated as: 57 | * 58 | * (34 + 8n - 1)/4 + 34 + 8n + 13 for SFF frames (11 bit CAN-ID) => 55 + 10n 59 | * (54 + 8n - 1)/4 + 54 + 8n + 13 for EFF frames (29 bit CAN-ID) => 80 + 10n 60 | * 61 | * while 'n' is the data length code (number of payload bytes) 62 | * 63 | * [1] "Controller Area Network (CAN) schedulability analysis: 64 | * Refuted, revisited and revised", Real-Time Syst (2007) 65 | * 35:239-272. 66 | * 67 | */ 68 | enum cfl_mode { 69 | CFL_NO_BITSTUFFING, /* plain bit calculation without bitstuffing */ 70 | CFL_WORSTCASE, /* worst case estimation - see above */ 71 | CFL_EXACT, /* exact calculation of stuffed bits based on frame 72 | * content and CRC */ 73 | }; 74 | 75 | /** 76 | * Calculates the number of bits a frame needs on the wire (including 77 | * inter frame space). 78 | * 79 | * Mode determines how to deal with stuffed bits. 80 | */ 81 | unsigned can_frame_length(struct canfd_frame *frame, enum cfl_mode mode, int mtu); 82 | 83 | #endif 84 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2002-2005 Volkswagen Group Electronic Research 3 | # All rights reserved. 4 | # 5 | # Redistribution and use in source and binary forms, with or without 6 | # modification, are permitted provided that the following conditions 7 | # are met: 8 | # 1. Redistributions of source code must retain the above copyright 9 | # notice, this list of conditions, the following disclaimer and 10 | # the referenced file 'COPYING'. 11 | # 2. Redistributions in binary form must reproduce the above copyright 12 | # notice, this list of conditions and the following disclaimer in the 13 | # documentation and/or other materials provided with the distribution. 14 | # 3. Neither the name of Volkswagen nor the names of its contributors 15 | # may be used to endorse or promote products derived from this software 16 | # without specific prior written permission. 17 | # 18 | # Alternatively, provided that this notice is retained in full, this 19 | # software may be distributed under the terms of the GNU General 20 | # Public License ("GPL") version 2 as distributed in the 'COPYING' 21 | # file from the main directory of the linux kernel source. 22 | # 23 | # The provided data structures and external interfaces from this code 24 | # are not restricted to be used by modules with a GPL compatible license. 25 | # 26 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 27 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 28 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 29 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 30 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 31 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 32 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 33 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 34 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 35 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 36 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 37 | # DAMAGE. 38 | # 39 | # Send feedback to 40 | 41 | DESTDIR ?= 42 | PREFIX ?= /usr/local 43 | 44 | MAKEFLAGS = -k 45 | 46 | CFLAGS = -O2 -Wall -Wno-parentheses \ 47 | -fno-strict-aliasing 48 | 49 | CPPFLAGS += -Iinclude \ 50 | -D_FILE_OFFSET_BITS=64 \ 51 | -DSO_RXQ_OVFL=40 \ 52 | -DPF_CAN=29 \ 53 | -DAF_CAN=PF_CAN 54 | 55 | PROGRAMS_ISOTP = isotpdump isotprecv isotpsend isotpsniffer isotptun isotpserver isotpperf 56 | PROGRAMS_CANGW = cangw 57 | PROGRAMS_SLCAN = slcan_attach slcand 58 | PROGRAMS = can-calc-bit-timing candump cansniffer cansend canplayer cangen canbusload\ 59 | log2long log2asc asc2log\ 60 | canlogserver bcmserver\ 61 | $(PROGRAMS_ISOTP)\ 62 | $(PROGRAMS_CANGW)\ 63 | $(PROGRAMS_SLCAN)\ 64 | slcanpty canfdtest 65 | 66 | all: $(PROGRAMS) 67 | 68 | clean: 69 | rm -f $(PROGRAMS) *.o 70 | 71 | install: 72 | mkdir -p $(DESTDIR)$(PREFIX)/bin 73 | cp -f $(PROGRAMS) $(DESTDIR)$(PREFIX)/bin 74 | 75 | distclean: 76 | rm -f $(PROGRAMS) *.o *~ 77 | 78 | cansend.o: lib.h 79 | cangen.o: lib.h 80 | candump.o: lib.h 81 | canplayer.o: lib.h 82 | canlogserver.o: lib.h 83 | canbusload.o: lib.h 84 | log2long.o: lib.h 85 | log2asc.o: lib.h 86 | asc2log.o: lib.h 87 | canframelen.o: canframelen.h 88 | 89 | cansend: cansend.o lib.o 90 | cangen: cangen.o lib.o 91 | candump: candump.o lib.o 92 | canplayer: canplayer.o lib.o 93 | canlogserver: canlogserver.o lib.o 94 | log2long: log2long.o lib.o 95 | log2asc: log2asc.o lib.o 96 | asc2log: asc2log.o lib.o 97 | canbusload: canbusload.o canframelen.o 98 | -------------------------------------------------------------------------------- /old_include/mac/can/netlink.h: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/can/netlink.h 3 | * 4 | * Definitions for the CAN netlink interface 5 | * 6 | * Copyright (c) 2009 Wolfgang Grandegger 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the version 2 of the GNU General Public License 10 | * as published by the Free Software Foundation 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | */ 17 | 18 | #ifndef CAN_NETLINK_H 19 | #define CAN_NETLINK_H 20 | 21 | #include "mac_os_types.h" 22 | 23 | /* 24 | * CAN bit-timing parameters 25 | * 26 | * For further information, please read chapter "8 BIT TIMING 27 | * REQUIREMENTS" of the "Bosch CAN Specification version 2.0" 28 | * at http://www.semiconductors.bosch.de/pdf/can2spec.pdf. 29 | */ 30 | struct can_bittiming { 31 | __u32 bitrate; /* Bit-rate in bits/second */ 32 | __u32 sample_point; /* Sample point in one-tenth of a percent */ 33 | __u32 tq; /* Time quanta (TQ) in nanoseconds */ 34 | __u32 prop_seg; /* Propagation segment in TQs */ 35 | __u32 phase_seg1; /* Phase buffer segment 1 in TQs */ 36 | __u32 phase_seg2; /* Phase buffer segment 2 in TQs */ 37 | __u32 sjw; /* Synchronisation jump width in TQs */ 38 | __u32 brp; /* Bit-rate prescaler */ 39 | }; 40 | 41 | /* 42 | * CAN harware-dependent bit-timing constant 43 | * 44 | * Used for calculating and checking bit-timing parameters 45 | */ 46 | struct can_bittiming_const { 47 | char name[16]; /* Name of the CAN controller hardware */ 48 | __u32 tseg1_min; /* Time segement 1 = prop_seg + phase_seg1 */ 49 | __u32 tseg1_max; 50 | __u32 tseg2_min; /* Time segement 2 = phase_seg2 */ 51 | __u32 tseg2_max; 52 | __u32 sjw_max; /* Synchronisation jump width */ 53 | __u32 brp_min; /* Bit-rate prescaler */ 54 | __u32 brp_max; 55 | __u32 brp_inc; 56 | }; 57 | 58 | /* 59 | * CAN clock parameters 60 | */ 61 | struct can_clock { 62 | __u32 freq; /* CAN system clock frequency in Hz */ 63 | }; 64 | 65 | /* 66 | * CAN operational and error states 67 | */ 68 | enum can_state { 69 | CAN_STATE_ERROR_ACTIVE = 0, /* RX/TX error count < 96 */ 70 | CAN_STATE_ERROR_WARNING, /* RX/TX error count < 128 */ 71 | CAN_STATE_ERROR_PASSIVE, /* RX/TX error count < 256 */ 72 | CAN_STATE_BUS_OFF, /* RX/TX error count >= 256 */ 73 | CAN_STATE_STOPPED, /* Device is stopped */ 74 | CAN_STATE_SLEEPING, /* Device is sleeping */ 75 | CAN_STATE_MAX 76 | }; 77 | 78 | /* 79 | * CAN bus error counters 80 | */ 81 | struct can_berr_counter { 82 | __u16 txerr; 83 | __u16 rxerr; 84 | }; 85 | 86 | /* 87 | * CAN controller mode 88 | */ 89 | struct can_ctrlmode { 90 | __u32 mask; 91 | __u32 flags; 92 | }; 93 | 94 | #define CAN_CTRLMODE_LOOPBACK 0x01 /* Loopback mode */ 95 | #define CAN_CTRLMODE_LISTENONLY 0x02 /* Listen-only mode */ 96 | #define CAN_CTRLMODE_3_SAMPLES 0x04 /* Triple sampling mode */ 97 | #define CAN_CTRLMODE_ONE_SHOT 0x08 /* One-Shot mode */ 98 | #define CAN_CTRLMODE_BERR_REPORTING 0x10 /* Bus-error reporting */ 99 | 100 | /* 101 | * CAN device statistics 102 | */ 103 | struct can_device_stats { 104 | __u32 bus_error; /* Bus errors */ 105 | __u32 error_warning; /* Changes to error warning state */ 106 | __u32 error_passive; /* Changes to error passive state */ 107 | __u32 bus_off; /* Changes to bus off state */ 108 | __u32 arbitration_lost; /* Arbitration lost errors */ 109 | __u32 restarts; /* CAN controller re-starts */ 110 | }; 111 | 112 | /* 113 | * CAN netlink interface 114 | */ 115 | enum { 116 | IFLA_CAN_UNSPEC, 117 | IFLA_CAN_BITTIMING, 118 | IFLA_CAN_BITTIMING_CONST, 119 | IFLA_CAN_CLOCK, 120 | IFLA_CAN_STATE, 121 | IFLA_CAN_CTRLMODE, 122 | IFLA_CAN_RESTART_MS, 123 | IFLA_CAN_RESTART, 124 | IFLA_CAN_BERR_COUNTER, 125 | __IFLA_CAN_MAX 126 | }; 127 | 128 | #define IFLA_CAN_MAX (__IFLA_CAN_MAX - 1) 129 | 130 | #endif /* CAN_NETLINK_H */ 131 | -------------------------------------------------------------------------------- /x/can/error.h: -------------------------------------------------------------------------------- 1 | /* 2 | * x/can/error.h 3 | * 4 | * Definitions for CAN Broadcast Manager (BCM) 5 | * 6 | * @author Halis Duraki 7 | * /usr/include/duraki 8 | */ 9 | 10 | #ifndef _UAPI_CAN_ERROR_H 11 | #define _UAPI_CAN_ERROR_H 12 | 13 | #define CAN_ERR_DLC 8 /* dlc for error message frames */ 14 | 15 | /* error class (mask) in can_id */ 16 | #define CAN_ERR_TX_TIMEOUT 0x00000001U /* TX timeout */ 17 | #define CAN_ERR_LOSTARB 0x00000002U /* lost arbitation / data [0] */ 18 | #define CAN_ERR_CRTL 0x00000004U /* controller problems / data [1] */ 19 | #define CAN_ERR_PROT 0x00000008U /* protocol violations / data [2..3] */ 20 | #define CAN_ERR_TRX 0x00000010U /* transceiver status / data [4] */ 21 | #define CAN_ERR_ACK 0x00000020U /* received no ACK on transmission */ 22 | #define CAN_ERR_BUSOFF 0x00000040U /* bus off */ 23 | #define CAN_ERR_BUSERROR 0x00000080U /* bus error */ 24 | #define CAN_ERR_RESTARTED 0x00000100U /* controlelr restarted */ 25 | 26 | /* arbitration lost in bit / data [0] */ 27 | #define CAR_ERR_LOSTARB_UNSPEC 0x00 /* unspecified */ 28 | 29 | /* error status of CAN-controller / data[1] */ 30 | #define CAN_ERR_CRTL_UNSPEC 0x00 /* unspecified */ 31 | #define CAN_ERR_CRTL_RX_OVERFLOW 0x01 /* RX buffer overflow */ 32 | #define CAN_ERR_CRTL_TX_OVERFLOW 0x02 /* TX buffer overflow */ 33 | #define CAN_ERR_CRTL_RX_WARNING 0x04 /* warning level for RX erros */ 34 | #define CAN_ERR_CRTL_TX_WARNING 0x08 /* warning level for TX erros */ 35 | #define CAN_ERR_CRTL_RX_PASSIVE 0x10 /* error pasive status for RX */ 36 | #define CAN_ERR_CRTL_TX_PASSIVE 0x20 /* error passive status for TX */ 37 | 38 | #define CAN_ERR_CRTL_ACTIVE 0x40 /* recovered to error active state */ 39 | 40 | /* error in CAN protocol (type) / data[2] */ 41 | #define CAN_ERR_PROT_UNSPEC 0x00 /* unspecified */ 42 | #define CAN_ERR_PROT_BIT 0x01 /* single bit error */ 43 | #define CAN_ERR_PROT_FORM 0x02 /* frame format error */ 44 | #define CAN_ERR_PROT_STUFF 0x04 /* bit stuffing error */ 45 | #define CAN_ERR_PROT_BIT0 0x08 /* unable to send dominant bit */ 46 | #define CAN_ERR_PROT_BIT1 0x10 /* unable to send recessive bit */ 47 | #define CAN_ERR_PROT_OVERLOAD 0x20 /* bus overload */ 48 | #define CAN_ERR_PROT_ACTIVE 0x40 /* active error announcement */ 49 | #define CAN_ERR_PROT_TX 0x80 /* error while transmission */ 50 | 51 | /* error in CAN protocol (location) / data[3] */ 52 | #define CAN_ERR_PROT_LOC_UNSPEC 0x00 /* unspecified */ 53 | #define CAN_ERR_PROT_LOC_SOF 0x03 /* start of frame */ 54 | #define CAN_ERR_PROT_LOC_ID28_21 0x02 /* ID bits 28 - 21 (SFF: 10 - 3) */ 55 | #define CAN_ERR_PROT_LOC_ID20_18 0x06 /* ID bits 20 - 18 (SFF: 2 - 0) */ 56 | #define CAN_ERR_PROT_LOC_SRTR 0x04 /* substitue RTR (SFF: RTR) */ 57 | #define CAN_ERR_PROT_LOC_IDE 0x05 /* identifier extension */ 58 | #define CAN_ERR_PROT_LOC_ID17_13 0x07 /* ID bits 17-13 */ 59 | #define CAN_ERR_PROT_LOC_ID12_05 0x0F /* ID bits 12-5 */ 60 | #define CAN_ERR_PROT_LOC_ID04_00 0x0E /* ID bits 4-0 */ 61 | #define CAN_ERR_PROT_LOC_RTR 0x0C /* RTR */ 62 | #define CAN_ERR_PROT_LOC_RES1 0x0D /* reserved bit 1 */ 63 | #define CAN_ERR_PROT_LOC_RES0 0x09 /* reserved bit 0 */ 64 | #define CAN_ERR_PROT_LOC_DLC 0x0B /* data length code */ 65 | #define CAN_ERR_PROT_LOC_DATA 0x0A /* data section */ 66 | #define CAN_ERR_PROT_LOC_CRC_SEQ 0x08 /* CRC sequence */ 67 | #define CAN_ERR_PROT_LOC_CRC_DEL 0x18 /* CRC delimiter */ 68 | #define CAN_ERR_PROT_LOC_ACK 0x19 /* ACK slot */ 69 | #define CAN_ERR_PROT_LOC_ACK_DEL 0x1B /* ACK delimiter */ 70 | #define CAN_ERR_PROT_LOC_EOF 0x1A /* end of frame */ 71 | #define CAN_ERR_PROT_LOC_INTERM 0x12 /* intermission */ 72 | 73 | /* error tatus of CAN-transceiver / data[4] */ 74 | #define CAN_ERR_TRX_UNSPEC 0x00 /* 0000 0000 */ 75 | #define CAN_ERR_TRX_CANH_NO_WIRE 0x04 /* 0000 0100 */ 76 | #define CAN_ERR_TRX_CANH_SHORT_TO_BAT 0x05 /* 0000 0101 */ 77 | #define CAN_ERR_TRX_CANH_SHORT_TO_VCC 0x06 /* 0000 0110 */ 78 | #define CAN_ERR_TRX_CANH_SHORT_TO_GND 0x07 /* 0000 0111 */ 79 | #define CAN_ERR_TRX_CANL_NO_WIRE 0x40 /* 0100 0000 */ 80 | #define CAN_ERR_TRX_CANL_SHORT_TO_BAT 0x50 /* 0101 0000 */ 81 | #define CAN_ERR_TRX_CANL_SHORT_TO_VCC 0x60 /* 0110 0000 */ 82 | #define CAN_ERR_TRX_CANL_SHORT_TO_GND 0x70 /* 0111 0000 */ 83 | #define CAN_ERR_TRX_CANL_SHORT_TO_CANH 0x80 /* 1000 0000 */ 84 | 85 | /* controller specific additional information / data [5..7] */ 86 | 87 | #endif /* _UAPI_CAN_ERROR_H */ -------------------------------------------------------------------------------- /old_include/mac/can/bcm.h: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/can/bcm.h 3 | * 4 | * Definitions for CAN Broadcast Manager (BCM) 5 | * 6 | * Author: Oliver Hartkopp 7 | * Copyright (c) 2002-2007 Volkswagen Group Electronic Research 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of Volkswagen nor the names of its contributors 19 | * may be used to endorse or promote products derived from this software 20 | * without specific prior written permission. 21 | * 22 | * Alternatively, provided that this notice is retained in full, this 23 | * software may be distributed under the terms of the GNU General 24 | * Public License ("GPL") version 2, in which case the provisions of the 25 | * GPL apply INSTEAD OF those given above. 26 | * 27 | * The provided data structures and external interfaces from this code 28 | * are not restricted to be used by modules with a GPL compatible license. 29 | * 30 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 31 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 32 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 33 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 34 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 35 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 36 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 37 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 38 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 39 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 40 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 41 | * DAMAGE. 42 | */ 43 | 44 | #ifndef CAN_BCM_H 45 | #define CAN_BCM_H 46 | 47 | #include 48 | #include 49 | 50 | struct bcm_timeval { 51 | long tv_sec; 52 | long tv_usec; 53 | }; 54 | 55 | /** 56 | * struct bcm_msg_head - head of messages to/from the broadcast manager 57 | * @opcode: opcode, see enum below. 58 | * @flags: special flags, see below. 59 | * @count: number of frames to send before changing interval. 60 | * @ival1: interval for the first @count frames. 61 | * @ival2: interval for the following frames. 62 | * @can_id: CAN ID of frames to be sent or received. 63 | * @nframes: number of frames appended to the message head. 64 | * @frames: array of CAN frames. 65 | */ 66 | struct bcm_msg_head { 67 | __u32 opcode; 68 | __u32 flags; 69 | __u32 count; 70 | struct bcm_timeval ival1, ival2; 71 | canid_t can_id; 72 | __u32 nframes; 73 | struct can_frame frames[0]; 74 | }; 75 | 76 | enum { 77 | TX_SETUP = 1, /* create (cyclic) transmission task */ 78 | TX_DELETE, /* remove (cyclic) transmission task */ 79 | TX_READ, /* read properties of (cyclic) transmission task */ 80 | TX_SEND, /* send one CAN frame */ 81 | RX_SETUP, /* create RX content filter subscription */ 82 | RX_DELETE, /* remove RX content filter subscription */ 83 | RX_READ, /* read properties of RX content filter subscription */ 84 | TX_STATUS, /* reply to TX_READ request */ 85 | TX_EXPIRED, /* notification on performed transmissions (count=0) */ 86 | RX_STATUS, /* reply to RX_READ request */ 87 | RX_TIMEOUT, /* cyclic message is absent */ 88 | RX_CHANGED /* updated CAN frame (detected content change) */ 89 | }; 90 | 91 | #define SETTIMER 0x0001 92 | #define STARTTIMER 0x0002 93 | #define TX_COUNTEVT 0x0004 94 | #define TX_ANNOUNCE 0x0008 95 | #define TX_CP_CAN_ID 0x0010 96 | #define RX_FILTER_ID 0x0020 97 | #define RX_CHECK_DLC 0x0040 98 | #define RX_NO_AUTOTIMER 0x0080 99 | #define RX_ANNOUNCE_RESUME 0x0100 100 | #define TX_RESET_MULTI_IDX 0x0200 101 | #define RX_RTR_FRAME 0x0400 102 | 103 | #endif /* CAN_BCM_H */ 104 | -------------------------------------------------------------------------------- /x/can/lib/can.h: -------------------------------------------------------------------------------- 1 | /* 2 | * x/lib/can.h 3 | * 4 | * Definitions for CAN network layer (socket addr / CAN frame / CAN filter) 5 | * 6 | * @author Halis Duraki 7 | * /usr/include/duraki 8 | */ 9 | 10 | #ifndef _UAPI_CAN_H 11 | #define _UAPI_CAN_H 12 | 13 | #include 14 | #include 15 | #include "types.h" 16 | 17 | /* controller area network (CAN) kernel definitions */ 18 | 19 | /* special address description flags for the CAN_ID */ 20 | #define CAN_EFF_FLAG 0x80000000U /* EFF/SFF is set */ 21 | #define CAN_RTR_FLAG 0x40000000U /* remote transmission request */ 22 | #define CAN_ERR_FLAG 0x20000000U /* error message frame */ 23 | 24 | /* valid bits in CAN ID for frame formats */ 25 | #define CAN_SFF_MASK 0x000007FFU /* standard frame format (SFF) */ 26 | #define CAN_EFF_MASK 0x1FFFFFFFU /* extended frame format (EFF) */ 27 | #define CAN_ERR_MASK 0x1FFFFFFFU /* omit EFF, RTR, ERR flags */ 28 | 29 | /** 30 | * Controller Area Network Identifier structure 31 | * 32 | * bit 0-28 / CAN identifier (11/29 bit) 33 | * bit 29 / error message frame flag (0 = data frame, 1 = error message) 34 | * bit 30 / remote transmission request flag (1 = rtr frame) 35 | * bit 31 / frame format flag (0 = standard 11-bit, 1 = extended 29-bit) 36 | */ 37 | typedef __u32 canid_t; 38 | 39 | #define CAN_SFF_ID_BITS 11 40 | #define CAN_EFF_ID_BITS 29 41 | 42 | /** 43 | * Controller Area Network Error Message Frame Mask structure 44 | * 45 | * bit 0-28 / error class mask 46 | * bit 29-31 / set to zero 47 | */ 48 | typedef __u32 can_err_mask_t; 49 | 50 | /* CAN payload length and DLC definitions according to ISO 11898-1 */ 51 | // http://www.iso.org/iso/catalogue_detail.htm?csnumber=63648 52 | #define CAN_MAX_DLC 8 53 | #define CAN_MAX_DLEN 8 54 | 55 | /* CAN FD payload length and DLC definitions according to ISO 11898-7 */ 56 | #define CANFD_MAX_DLC 15 57 | #define CANFD_MAX_DLEN 64 58 | 59 | /** 60 | * struct can_frame - basic CAN frame structure 61 | * 62 | * @can_id: CAN ID of the frame and CAN_*_FLAG flags, see canid_t definition 63 | * @can_dlc: frame payload length in byte (0 .. 8) aka data length code 64 | * N.B. the DLC field from ISO 11898-1 Chapter 8.4.2.3 has a 1:1 65 | * mapping of the 'data length code' to the real payload length 66 | * @__pad: padding 67 | * @__res0: reserved / padding 68 | * @__res1: reserved / padding 69 | * @data: CAN frame payload (up to 8 byte) 70 | */ 71 | struct can_frame { 72 | canid_t can_id; /* 32 bit CAN_ID + EFF/RTR/ERR flags */ 73 | __u8 can_dlc; /* frame payload length in byte (0 .. CAN_MAX_DLEN) */ 74 | __u8 __pad; /* padding */ 75 | __u8 __res0; /* reserved / padding */ 76 | __u8 __res1; /* reserved / padding */ 77 | __u8 data[CAN_MAX_DLEN] __attribute__((aligned(8))); 78 | }; 79 | 80 | /** 81 | * defined bits for canfd_frame.flags 82 | * 83 | * The use of struct canfd_frame implies the EDL / Extended Data Length bit 84 | * to be set in a CAN frame bitstream on the wire. The EDL bit switch turns 85 | * the CAN controllers bitstream processor into the CAN FD mode which creates 86 | * two new options within the CAN FD frame specification: 87 | * 88 | * Bit Rate Switch (bitrate) 89 | * Error State Indicator (error state) 90 | */ 91 | #define CANFD_BRS 0x01; /* bit rate switch */ 92 | #define CANFD_ESI 0x02; /* error state */ 93 | 94 | /** 95 | * struct canfd_frame - CAN flexible data rate frame structure 96 | * @can_id: CAN ID of the frame and CAN_*_FLAG flags, see canid_t definition 97 | * @len: frame payload length in byte (0 .. CANFD_MAX_DLEN) 98 | * @flags: additional flags for CAN FD 99 | * @__res0: reserved / padding 100 | * @__res1: reserved / padding 101 | * @data: CAN FD frame payload (up to CANFD_MAX_DLEN byte) 102 | */ 103 | struct canfd_frame { 104 | canid_t can_id; /* 32 bit CAN_ID + EFF/RTR/ERR flags */ 105 | __u8 len; /* frame payload length in byte */ 106 | __u8 flags; /* additional flags for CAN FD */ 107 | __u8 __res0; /* reserved / padding */ 108 | __u8 __res1; /* reserved / padding */ 109 | __u8 data[CANFD_MAX_DLEN] __attribute__((aligned(8))); 110 | }; 111 | 112 | #define CAN_MTU (sizeof(struct can_frame)) 113 | #define CANFD_MTU (sizeof(struct canfd_frame)) 114 | 115 | /* protocols of protocol family PF_CAN */ 116 | #define CAN_RAW 1 /* RAW sockets */ 117 | #define CAN_BCM 2 /* Broadcast Manager */ 118 | #define CAN_TP16 3 /* VAG Transport Protocol v1.6 */ 119 | #define CAN_TP20 4 /* CAG Transport Protocol v2.0 */ 120 | #define CAN_MCNET 5 /* Bosch MCNet */ 121 | #define CAN_ISOTP 6 /* ISO 15765-2 Transport Protocol */ 122 | 123 | #define SOL_CAN_BASE 100 124 | 125 | /** 126 | * struct sockaddr_can - the sockaddr structure for CAN sockets 127 | * @can_family: address family number AF_CAN 128 | * @can_ifindex: CAN network interface index 129 | * @can_addr: protocol specific address information 130 | */ 131 | struct sockaddr_can { 132 | /* required from types.h */ 133 | __uint8_t can_family; 134 | int can_ifindex; 135 | union { 136 | /* transport protocol class address information */ 137 | struct { canid_t rx_id, tx_id; } tp; 138 | } can_addr; 139 | }; 140 | 141 | /** 142 | * struct can_filter - CAN ID based filter in can_register() 143 | * @can_id: relevant bits of CAN ID which are not masked out. 144 | * @can_err_mask_t: CAN mask 145 | */ 146 | struct can_filter { 147 | canid_t can_id; 148 | canid_t can_mask; 149 | }; 150 | 151 | #define CAN_INV_FILTER 0x20000000U /* to be set in can_filter.can_id */ 152 | 153 | #endif /* !_UAPI_CAN_H */ -------------------------------------------------------------------------------- /cansend.c: -------------------------------------------------------------------------------- 1 | /* 2 | * cansend.c - simple command line tool to send CAN-frames via CAN_RAW sockets 3 | * 4 | * Copyright (c) 2002-2007 Volkswagen Group Electronic Research 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 3. Neither the name of Volkswagen nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * Alternatively, provided that this notice is retained in full, this 20 | * software may be distributed under the terms of the GNU General 21 | * Public License ("GPL") version 2, in which case the provisions of the 22 | * GPL apply INSTEAD OF those given above. 23 | * 24 | * The provided data structures and external interfaces from this code 25 | * are not restricted to be used by modules with a GPL compatible license. 26 | * 27 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 28 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 29 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 30 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 31 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 32 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 33 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 34 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 35 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 36 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 37 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 38 | * DAMAGE. 39 | * 40 | * Send feedback to 41 | * 42 | */ 43 | 44 | #include 45 | #include 46 | #include 47 | #include 48 | 49 | #include 50 | #include 51 | #include 52 | 53 | #include 54 | #include 55 | 56 | #include "lib.h" 57 | 58 | int main(int argc, char **argv) 59 | { 60 | int s; /* can raw socket */ 61 | int required_mtu; 62 | int mtu; 63 | int enable_canfd = 1; 64 | struct sockaddr_can addr; 65 | struct canfd_frame frame; 66 | struct ifreq ifr; 67 | 68 | /* check command line options */ 69 | if (argc != 3) { 70 | fprintf(stderr, "Usage: %s .\n", argv[0]); 71 | return 1; 72 | } 73 | 74 | /* parse CAN frame */ 75 | required_mtu = parse_canframe(argv[2], &frame); 76 | if (!required_mtu){ 77 | fprintf(stderr, "\nWrong CAN-frame format! Try:\n\n"); 78 | fprintf(stderr, " #{R|data} for CAN 2.0 frames\n"); 79 | fprintf(stderr, " ##{data} for CAN FD frames\n\n"); 80 | fprintf(stderr, " can have 3 (SFF) or 8 (EFF) hex chars\n"); 81 | fprintf(stderr, "{data} has 0..8 (0..64 CAN FD) ASCII hex-values (optionally"); 82 | fprintf(stderr, " separated by '.')\n"); 83 | fprintf(stderr, " a single ASCII Hex value (0 .. F) which defines"); 84 | fprintf(stderr, " canfd_frame.flags\n\n"); 85 | fprintf(stderr, "e.g. 5A1#11.2233.44556677.88 / 123#DEADBEEF / 5AA# / "); 86 | fprintf(stderr, "123##1 / 213##311\n 1F334455#1122334455667788 / 123#R "); 87 | fprintf(stderr, "for remote transmission request.\n\n"); 88 | return 1; 89 | } 90 | 91 | /* open socket */ 92 | if ((s = socket(PF_CAN, SOCK_RAW, CAN_RAW)) < 0) { 93 | perror("socket"); 94 | return 1; 95 | } 96 | 97 | strncpy(ifr.ifr_name, argv[1], IFNAMSIZ - 1); 98 | ifr.ifr_name[IFNAMSIZ - 1] = '\0'; 99 | ifr.ifr_ifindex = if_nametoindex(ifr.ifr_name); 100 | if (!ifr.ifr_ifindex) { 101 | perror("if_nametoindex"); 102 | return 1; 103 | } 104 | 105 | addr.can_family = AF_CAN; 106 | addr.can_ifindex = ifr.ifr_ifindex; 107 | 108 | if (required_mtu > CAN_MTU) { 109 | 110 | /* check if the frame fits into the CAN netdevice */ 111 | if (ioctl(s, SIOCGIFMTU, &ifr) < 0) { 112 | perror("SIOCGIFMTU"); 113 | return 1; 114 | } 115 | mtu = ifr.ifr_mtu; 116 | 117 | if (mtu != CANFD_MTU) { 118 | printf("CAN interface ist not CAN FD capable - sorry.\n"); 119 | return 1; 120 | } 121 | 122 | /* interface is ok - try to switch the socket into CAN FD mode */ 123 | if (setsockopt(s, SOL_CAN_RAW, CAN_RAW_FD_FRAMES, 124 | &enable_canfd, sizeof(enable_canfd))){ 125 | printf("error when enabling CAN FD support\n"); 126 | return 1; 127 | } 128 | 129 | /* ensure discrete CAN FD length values 0..8, 12, 16, 20, 24, 32, 64 */ 130 | frame.len = can_dlc2len(can_len2dlc(frame.len)); 131 | } 132 | 133 | /* disable default receive filter on this RAW socket */ 134 | /* This is obsolete as we do not read from the socket at all, but for */ 135 | /* this reason we can remove the receive list in the Kernel to save a */ 136 | /* little (really a very little!) CPU usage. */ 137 | setsockopt(s, SOL_CAN_RAW, CAN_RAW_FILTER, NULL, 0); 138 | 139 | if (bind(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) { 140 | perror("bind"); 141 | return 1; 142 | } 143 | 144 | /* send frame */ 145 | if (write(s, &frame, required_mtu) != required_mtu) { 146 | perror("write"); 147 | return 1; 148 | } 149 | 150 | close(s); 151 | 152 | return 0; 153 | } 154 | -------------------------------------------------------------------------------- /log2asc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * log2asc.c - convert compact CAN frame logfile to ASC logfile 3 | * 4 | * Copyright (c) 2002-2007 Volkswagen Group Electronic Research 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 3. Neither the name of Volkswagen nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * Alternatively, provided that this notice is retained in full, this 20 | * software may be distributed under the terms of the GNU General 21 | * Public License ("GPL") version 2, in which case the provisions of the 22 | * GPL apply INSTEAD OF those given above. 23 | * 24 | * The provided data structures and external interfaces from this code 25 | * are not restricted to be used by modules with a GPL compatible license. 26 | * 27 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 28 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 29 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 30 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 31 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 32 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 33 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 34 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 35 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 36 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 37 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 38 | * DAMAGE. 39 | * 40 | * Send feedback to 41 | * 42 | */ 43 | 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | 50 | #include 51 | #include 52 | #include 53 | 54 | #include "lib.h" 55 | 56 | #define BUFSZ 400 /* for one line in the logfile */ 57 | 58 | extern int optind, opterr, optopt; 59 | 60 | void print_usage(char *prg) 61 | { 62 | fprintf(stderr, "Usage: %s [can-interfaces]\n", prg); 63 | fprintf(stderr, "Options: -I (default stdin)\n"); 64 | fprintf(stderr, " -O (default stdout)\n"); 65 | fprintf(stderr, " -4 (reduce decimal place to 4 digits)\n"); 66 | fprintf(stderr, " -n (set newline to cr/lf - default lf)\n"); 67 | } 68 | 69 | int main(int argc, char **argv) 70 | { 71 | static char buf[BUFSZ], device[BUFSZ], ascframe[BUFSZ], id[10]; 72 | 73 | struct canfd_frame cf; 74 | static struct timeval tv, start_tv; 75 | FILE *infile = stdin; 76 | FILE *outfile = stdout; 77 | static int maxdev, devno, i, crlf, d4, opt; 78 | 79 | while ((opt = getopt(argc, argv, "I:O:4n?")) != -1) { 80 | switch (opt) { 81 | case 'I': 82 | infile = fopen(optarg, "r"); 83 | if (!infile) { 84 | perror("infile"); 85 | return 1; 86 | } 87 | break; 88 | 89 | case 'O': 90 | outfile = fopen(optarg, "w"); 91 | if (!outfile) { 92 | perror("outfile"); 93 | return 1; 94 | } 95 | break; 96 | 97 | case 'n': 98 | crlf = 1; 99 | break; 100 | 101 | case '4': 102 | d4 = 1; 103 | break; 104 | 105 | case '?': 106 | print_usage(basename(argv[0])); 107 | return 0; 108 | break; 109 | 110 | default: 111 | fprintf(stderr, "Unknown option %c\n", opt); 112 | print_usage(basename(argv[0])); 113 | return 1; 114 | break; 115 | } 116 | } 117 | 118 | maxdev = argc - optind; /* find real number of CAN devices */ 119 | 120 | if (!maxdev) { 121 | fprintf(stderr, "no CAN interfaces defined!\n"); 122 | print_usage(basename(argv[0])); 123 | return 1; 124 | } 125 | 126 | //printf("Found %d CAN devices!\n", maxdev); 127 | 128 | while (fgets(buf, BUFSZ-1, infile)) { 129 | 130 | if (strlen(buf) >= BUFSZ-2) { 131 | fprintf(stderr, "line too long for input buffer\n"); 132 | return 1; 133 | } 134 | 135 | /* check for a comment line */ 136 | if (buf[0] != '(') 137 | continue; 138 | 139 | if (sscanf(buf, "(%ld.%ld) %s %s", &tv.tv_sec, &tv.tv_usec, 140 | device, ascframe) != 4) { 141 | fprintf(stderr, "incorrect line format in logfile\n"); 142 | return 1; 143 | } 144 | 145 | if (!start_tv.tv_sec) { /* print banner */ 146 | start_tv = tv; 147 | fprintf(outfile, "date %s", ctime(&start_tv.tv_sec)); 148 | fprintf(outfile, "base hex timestamps absolute%s", 149 | (crlf)?"\r\n":"\n"); 150 | fprintf(outfile, "no internal events logged%s", 151 | (crlf)?"\r\n":"\n"); 152 | } 153 | 154 | for (i=0, devno=0; i 7 | * Copyright (c) 2002-2007 Volkswagen Group Electronic Research 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of Volkswagen nor the names of its contributors 19 | * may be used to endorse or promote products derived from this software 20 | * without specific prior written permission. 21 | * 22 | * Alternatively, provided that this notice is retained in full, this 23 | * software may be distributed under the terms of the GNU General 24 | * Public License ("GPL") version 2, in which case the provisions of the 25 | * GPL apply INSTEAD OF those given above. 26 | * 27 | * The provided data structures and external interfaces from this code 28 | * are not restricted to be used by modules with a GPL compatible license. 29 | * 30 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 31 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 32 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 33 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 34 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 35 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 36 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 37 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 38 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 39 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 40 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 41 | * DAMAGE. 42 | */ 43 | 44 | #ifndef CAN_ERROR_H 45 | #define CAN_ERROR_H 46 | 47 | #define CAN_ERR_DLC 8 /* dlc for error message frames */ 48 | 49 | /* error class (mask) in can_id */ 50 | #define CAN_ERR_TX_TIMEOUT 0x00000001U /* TX timeout (by netdevice driver) */ 51 | #define CAN_ERR_LOSTARB 0x00000002U /* lost arbitration / data[0] */ 52 | #define CAN_ERR_CRTL 0x00000004U /* controller problems / data[1] */ 53 | #define CAN_ERR_PROT 0x00000008U /* protocol violations / data[2..3] */ 54 | #define CAN_ERR_TRX 0x00000010U /* transceiver status / data[4] */ 55 | #define CAN_ERR_ACK 0x00000020U /* received no ACK on transmission */ 56 | #define CAN_ERR_BUSOFF 0x00000040U /* bus off */ 57 | #define CAN_ERR_BUSERROR 0x00000080U /* bus error (may flood!) */ 58 | #define CAN_ERR_RESTARTED 0x00000100U /* controller restarted */ 59 | 60 | /* arbitration lost in bit ... / data[0] */ 61 | #define CAN_ERR_LOSTARB_UNSPEC 0x00 /* unspecified */ 62 | /* else bit number in bitstream */ 63 | 64 | /* error status of CAN-controller / data[1] */ 65 | #define CAN_ERR_CRTL_UNSPEC 0x00 /* unspecified */ 66 | #define CAN_ERR_CRTL_RX_OVERFLOW 0x01 /* RX buffer overflow */ 67 | #define CAN_ERR_CRTL_TX_OVERFLOW 0x02 /* TX buffer overflow */ 68 | #define CAN_ERR_CRTL_RX_WARNING 0x04 /* reached warning level for RX errors */ 69 | #define CAN_ERR_CRTL_TX_WARNING 0x08 /* reached warning level for TX errors */ 70 | #define CAN_ERR_CRTL_RX_PASSIVE 0x10 /* reached error passive status RX */ 71 | #define CAN_ERR_CRTL_TX_PASSIVE 0x20 /* reached error passive status TX */ 72 | /* (at least one error counter exceeds */ 73 | /* the protocol-defined level of 127) */ 74 | 75 | /* error in CAN protocol (type) / data[2] */ 76 | #define CAN_ERR_PROT_UNSPEC 0x00 /* unspecified */ 77 | #define CAN_ERR_PROT_BIT 0x01 /* single bit error */ 78 | #define CAN_ERR_PROT_FORM 0x02 /* frame format error */ 79 | #define CAN_ERR_PROT_STUFF 0x04 /* bit stuffing error */ 80 | #define CAN_ERR_PROT_BIT0 0x08 /* unable to send dominant bit */ 81 | #define CAN_ERR_PROT_BIT1 0x10 /* unable to send recessive bit */ 82 | #define CAN_ERR_PROT_OVERLOAD 0x20 /* bus overload */ 83 | #define CAN_ERR_PROT_ACTIVE 0x40 /* active error announcement */ 84 | #define CAN_ERR_PROT_TX 0x80 /* error occurred on transmission */ 85 | 86 | /* error in CAN protocol (location) / data[3] */ 87 | #define CAN_ERR_PROT_LOC_UNSPEC 0x00 /* unspecified */ 88 | #define CAN_ERR_PROT_LOC_SOF 0x03 /* start of frame */ 89 | #define CAN_ERR_PROT_LOC_ID28_21 0x02 /* ID bits 28 - 21 (SFF: 10 - 3) */ 90 | #define CAN_ERR_PROT_LOC_ID20_18 0x06 /* ID bits 20 - 18 (SFF: 2 - 0 )*/ 91 | #define CAN_ERR_PROT_LOC_SRTR 0x04 /* substitute RTR (SFF: RTR) */ 92 | #define CAN_ERR_PROT_LOC_IDE 0x05 /* identifier extension */ 93 | #define CAN_ERR_PROT_LOC_ID17_13 0x07 /* ID bits 17-13 */ 94 | #define CAN_ERR_PROT_LOC_ID12_05 0x0F /* ID bits 12-5 */ 95 | #define CAN_ERR_PROT_LOC_ID04_00 0x0E /* ID bits 4-0 */ 96 | #define CAN_ERR_PROT_LOC_RTR 0x0C /* RTR */ 97 | #define CAN_ERR_PROT_LOC_RES1 0x0D /* reserved bit 1 */ 98 | #define CAN_ERR_PROT_LOC_RES0 0x09 /* reserved bit 0 */ 99 | #define CAN_ERR_PROT_LOC_DLC 0x0B /* data length code */ 100 | #define CAN_ERR_PROT_LOC_DATA 0x0A /* data section */ 101 | #define CAN_ERR_PROT_LOC_CRC_SEQ 0x08 /* CRC sequence */ 102 | #define CAN_ERR_PROT_LOC_CRC_DEL 0x18 /* CRC delimiter */ 103 | #define CAN_ERR_PROT_LOC_ACK 0x19 /* ACK slot */ 104 | #define CAN_ERR_PROT_LOC_ACK_DEL 0x1B /* ACK delimiter */ 105 | #define CAN_ERR_PROT_LOC_EOF 0x1A /* end of frame */ 106 | #define CAN_ERR_PROT_LOC_INTERM 0x12 /* intermission */ 107 | 108 | /* error status of CAN-transceiver / data[4] */ 109 | /* CANH CANL */ 110 | #define CAN_ERR_TRX_UNSPEC 0x00 /* 0000 0000 */ 111 | #define CAN_ERR_TRX_CANH_NO_WIRE 0x04 /* 0000 0100 */ 112 | #define CAN_ERR_TRX_CANH_SHORT_TO_BAT 0x05 /* 0000 0101 */ 113 | #define CAN_ERR_TRX_CANH_SHORT_TO_VCC 0x06 /* 0000 0110 */ 114 | #define CAN_ERR_TRX_CANH_SHORT_TO_GND 0x07 /* 0000 0111 */ 115 | #define CAN_ERR_TRX_CANL_NO_WIRE 0x40 /* 0100 0000 */ 116 | #define CAN_ERR_TRX_CANL_SHORT_TO_BAT 0x50 /* 0101 0000 */ 117 | #define CAN_ERR_TRX_CANL_SHORT_TO_VCC 0x60 /* 0110 0000 */ 118 | #define CAN_ERR_TRX_CANL_SHORT_TO_GND 0x70 /* 0111 0000 */ 119 | #define CAN_ERR_TRX_CANL_SHORT_TO_CANH 0x80 /* 1000 0000 */ 120 | 121 | /* controller specific additional information / data[5..7] */ 122 | 123 | #endif /* CAN_ERROR_H */ 124 | -------------------------------------------------------------------------------- /old_include/mac/can/isotp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/can/isotp.h 3 | * 4 | * Definitions for isotp CAN sockets 5 | * 6 | * Author: Oliver Hartkopp 7 | * Copyright (c) 2008 Volkswagen Group Electronic Research 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of Volkswagen nor the names of its contributors 19 | * may be used to endorse or promote products derived from this software 20 | * without specific prior written permission. 21 | * 22 | * Alternatively, provided that this notice is retained in full, this 23 | * software may be distributed under the terms of the GNU General 24 | * Public License ("GPL") version 2, in which case the provisions of the 25 | * GPL apply INSTEAD OF those given above. 26 | * 27 | * The provided data structures and external interfaces from this code 28 | * are not restricted to be used by modules with a GPL compatible license. 29 | * 30 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 31 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 32 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 33 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 34 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 35 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 36 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 37 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 38 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 39 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 40 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 41 | * DAMAGE. 42 | * 43 | * Send feedback to 44 | */ 45 | 46 | #ifndef CAN_ISOTP_H 47 | #define CAN_ISOTP_H 48 | 49 | #include 50 | 51 | #define SOL_CAN_ISOTP (SOL_CAN_BASE + CAN_ISOTP) 52 | 53 | /* for socket options affecting the socket (not the global system) */ 54 | 55 | #define CAN_ISOTP_OPTS 1 /* pass struct can_isotp_options */ 56 | 57 | #define CAN_ISOTP_RECV_FC 2 /* pass struct can_isotp_fc_options */ 58 | 59 | /* sockopts to force stmin timer values for protocol regression tests */ 60 | 61 | #define CAN_ISOTP_TX_STMIN 3 /* pass __u32 value in nano secs */ 62 | /* use this time instead of value */ 63 | /* provided in FC from the receiver */ 64 | 65 | #define CAN_ISOTP_RX_STMIN 4 /* pass __u32 value in nano secs */ 66 | /* ignore received CF frames which */ 67 | /* timestamps differ less than val */ 68 | 69 | #define CAN_ISOTP_LL_OPTS 5 /* pass struct can_isotp_ll_options */ 70 | 71 | struct can_isotp_options { 72 | 73 | __u32 flags; /* set flags for isotp behaviour. */ 74 | /* __u32 value : flags see below */ 75 | 76 | __u32 frame_txtime; /* frame transmission time (N_As/N_Ar) */ 77 | /* __u32 value : time in nano secs */ 78 | 79 | __u8 ext_address; /* set address for extended addressing */ 80 | /* __u8 value : extended address */ 81 | 82 | __u8 txpad_content; /* set content of padding byte (tx) */ 83 | /* __u8 value : content on tx path */ 84 | 85 | __u8 rxpad_content; /* set content of padding byte (rx) */ 86 | /* __u8 value : content on rx path */ 87 | 88 | __u8 rx_ext_address; /* set address for extended addressing */ 89 | /* __u8 value : extended address (rx) */ 90 | }; 91 | 92 | struct can_isotp_fc_options { 93 | 94 | __u8 bs; /* blocksize provided in FC frame */ 95 | /* __u8 value : blocksize. 0 = off */ 96 | 97 | __u8 stmin; /* separation time provided in FC frame */ 98 | /* __u8 value : */ 99 | /* 0x00 - 0x7F : 0 - 127 ms */ 100 | /* 0x80 - 0xF0 : reserved */ 101 | /* 0xF1 - 0xF9 : 100 us - 900 us */ 102 | /* 0xFA - 0xFF : reserved */ 103 | 104 | __u8 wftmax; /* max. number of wait frame transmiss. */ 105 | /* __u8 value : 0 = omit FC N_PDU WT */ 106 | }; 107 | 108 | struct can_isotp_ll_options { 109 | 110 | __u8 mtu; /* generated & accepted CAN frame type */ 111 | /* __u8 value : */ 112 | /* CAN_MTU (16) -> standard CAN 2.0 */ 113 | /* CANFD_MTU (72) -> CAN FD frame */ 114 | 115 | __u8 tx_dl; /* tx link layer data length in bytes */ 116 | /* (configured maximum payload length) */ 117 | /* __u8 value : 8,12,16,20,24,32,48,64 */ 118 | /* => rx path supports all LL_DL values */ 119 | 120 | __u8 tx_flags; /* set into struct canfd_frame.flags */ 121 | /* at frame creation: e.g. CANFD_BRS */ 122 | /* Obsolete when the BRS flag is fixed */ 123 | /* by the CAN netdriver configuration */ 124 | }; 125 | 126 | 127 | /* flags for isotp behaviour */ 128 | 129 | #define CAN_ISOTP_LISTEN_MODE 0x001 /* listen only (do not send FC) */ 130 | #define CAN_ISOTP_EXTEND_ADDR 0x002 /* enable extended addressing */ 131 | #define CAN_ISOTP_TX_PADDING 0x004 /* enable CAN frame padding tx path */ 132 | #define CAN_ISOTP_RX_PADDING 0x008 /* enable CAN frame padding rx path */ 133 | #define CAN_ISOTP_CHK_PAD_LEN 0x010 /* check received CAN frame padding */ 134 | #define CAN_ISOTP_CHK_PAD_DATA 0x020 /* check received CAN frame padding */ 135 | #define CAN_ISOTP_HALF_DUPLEX 0x040 /* half duplex error state handling */ 136 | #define CAN_ISOTP_FORCE_TXSTMIN 0x080 /* ignore stmin from received FC */ 137 | #define CAN_ISOTP_FORCE_RXSTMIN 0x100 /* ignore CFs depending on rx stmin */ 138 | #define CAN_ISOTP_RX_EXT_ADDR 0x200 /* different rx extended addressing */ 139 | 140 | 141 | /* default values */ 142 | 143 | #define CAN_ISOTP_DEFAULT_FLAGS 0 144 | #define CAN_ISOTP_DEFAULT_EXT_ADDRESS 0x00 145 | #define CAN_ISOTP_DEFAULT_PAD_CONTENT 0xCC /* prevent bit-stuffing */ 146 | #define CAN_ISOTP_DEFAULT_FRAME_TXTIME 0 147 | #define CAN_ISOTP_DEFAULT_RECV_BS 0 148 | #define CAN_ISOTP_DEFAULT_RECV_STMIN 0x00 149 | #define CAN_ISOTP_DEFAULT_RECV_WFTMAX 0 150 | 151 | #define CAN_ISOTP_DEFAULT_LL_MTU CAN_MTU 152 | #define CAN_ISOTP_DEFAULT_LL_TX_DL CAN_MAX_DLEN 153 | #define CAN_ISOTP_DEFAULT_LL_TX_FLAGS 0 154 | 155 | /* 156 | * Remark on CAN_ISOTP_DEFAULT_RECV_* values: 157 | * 158 | * We can strongly assume, that the Linux Kernel implementation of 159 | * CAN_ISOTP is capable to run with BS=0, STmin=0 and WFTmax=0. 160 | * But as we like to be able to behave as a commonly available ECU, 161 | * these default settings can be changed via sockopts. 162 | * For that reason the STmin value is intentionally _not_ checked for 163 | * consistency and copied directly into the flow control (FC) frame. 164 | * 165 | */ 166 | 167 | #endif 168 | -------------------------------------------------------------------------------- /slcan_attach.c: -------------------------------------------------------------------------------- 1 | /* 2 | * slcan_attach.c - userspace tool for serial line CAN interface driver SLCAN 3 | * 4 | * Copyright (c) 2002-2007 Volkswagen Group Electronic Research 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 3. Neither the name of Volkswagen nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * Alternatively, provided that this notice is retained in full, this 20 | * software may be distributed under the terms of the GNU General 21 | * Public License ("GPL") version 2, in which case the provisions of the 22 | * GPL apply INSTEAD OF those given above. 23 | * 24 | * The provided data structures and external interfaces from this code 25 | * are not restricted to be used by modules with a GPL compatible license. 26 | * 27 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 28 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 29 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 30 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 31 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 32 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 33 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 34 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 35 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 36 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 37 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 38 | * DAMAGE. 39 | * 40 | * Send feedback to 41 | * 42 | */ 43 | 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include 53 | #include 54 | #include 55 | #include 56 | 57 | void print_usage(char *prg) 58 | { 59 | fprintf(stderr, "\nUsage: %s [options] tty\n\n", prg); 60 | fprintf(stderr, "Options: -o (send open command 'O\\r')\n"); 61 | fprintf(stderr, " -l (send listen only command 'L\\r', overrides -o)\n"); 62 | fprintf(stderr, " -c (send close command 'C\\r')\n"); 63 | fprintf(stderr, " -f (read status flags with 'F\\r' to reset error states)\n"); 64 | fprintf(stderr, " -s (set CAN speed 0..8)\n"); 65 | fprintf(stderr, " -b (set bit time register value)\n"); 66 | fprintf(stderr, " -d (only detach line discipline)\n"); 67 | fprintf(stderr, " -w (attach - wait for keypess - detach)\n"); 68 | fprintf(stderr, " -n (assign created netdevice name)\n"); 69 | fprintf(stderr, "\nExamples:\n"); 70 | fprintf(stderr, "slcan_attach -w -o -f -s6 -c /dev/ttyS1\n"); 71 | fprintf(stderr, "slcan_attach /dev/ttyS1\n"); 72 | fprintf(stderr, "slcan_attach -d /dev/ttyS1\n"); 73 | fprintf(stderr, "slcan_attach -w -n can15 /dev/ttyS1\n"); 74 | fprintf(stderr, "\n"); 75 | exit(1); 76 | } 77 | 78 | int main(int argc, char **argv) 79 | { 80 | int fd; 81 | int ldisc = N_SLCAN; 82 | int detach = 0; 83 | int waitkey = 0; 84 | int send_open = 0; 85 | int send_listen = 0; 86 | int send_close = 0; 87 | int send_read_status_flags = 0; 88 | char *speed = NULL; 89 | char *btr = NULL; 90 | char buf[IFNAMSIZ+1]; 91 | char *tty; 92 | char *name = NULL; 93 | int opt; 94 | 95 | while ((opt = getopt(argc, argv, "ldwocfs:b:n:?")) != -1) { 96 | switch (opt) { 97 | case 'd': 98 | detach = 1; 99 | break; 100 | 101 | case 'w': 102 | waitkey = 1; 103 | break; 104 | 105 | case 'o': 106 | send_open = 1; 107 | break; 108 | 109 | case 'l': 110 | send_listen = 1; 111 | break; 112 | 113 | case 'c': 114 | send_close = 1; 115 | break; 116 | 117 | case 'f': 118 | send_read_status_flags = 1; 119 | break; 120 | 121 | case 's': 122 | speed = optarg; 123 | if (strlen(speed) > 1) 124 | print_usage(argv[0]); 125 | break; 126 | 127 | case 'b': 128 | btr = optarg; 129 | if (strlen(btr) > 6) 130 | print_usage(argv[0]); 131 | break; 132 | 133 | case 'n': 134 | name = optarg; 135 | if (strlen(name) > IFNAMSIZ-1) 136 | print_usage(argv[0]); 137 | break; 138 | 139 | case '?': 140 | default: 141 | print_usage(argv[0]); 142 | break; 143 | } 144 | } 145 | 146 | if (argc - optind != 1) 147 | print_usage(argv[0]); 148 | 149 | tty = argv[optind]; 150 | 151 | if ((fd = open (tty, O_WRONLY | O_NOCTTY)) < 0) { 152 | perror(tty); 153 | exit(1); 154 | } 155 | 156 | if (waitkey || !detach) { 157 | 158 | if (speed) { 159 | sprintf(buf, "C\rS%s\r", speed); 160 | write(fd, buf, strlen(buf)); 161 | } 162 | 163 | if (btr) { 164 | sprintf(buf, "C\rs%s\r", btr); 165 | write(fd, buf, strlen(buf)); 166 | } 167 | 168 | if (send_read_status_flags) { 169 | sprintf(buf, "F\r"); 170 | write(fd, buf, strlen(buf)); 171 | } 172 | 173 | if (send_listen) { 174 | sprintf(buf, "L\r"); 175 | write(fd, buf, strlen(buf)); 176 | } else if (send_open) { 177 | sprintf(buf, "O\r"); 178 | write(fd, buf, strlen(buf)); 179 | } 180 | 181 | /* set slcan line discipline on given tty */ 182 | if (ioctl (fd, TIOCSETD, &ldisc) < 0) { 183 | perror("ioctl TIOCSETD"); 184 | exit(1); 185 | } 186 | 187 | /* retrieve the name of the created CAN netdevice */ 188 | if (ioctl (fd, SIOCGIFNAME, buf) < 0) { 189 | perror("ioctl SIOCGIFNAME"); 190 | exit(1); 191 | } 192 | 193 | printf("attached tty %s to netdevice %s\n", tty, buf); 194 | 195 | /* try to rename the created device if requested */ 196 | if (name) { 197 | struct ifreq ifr; 198 | int s = socket(PF_INET, SOCK_DGRAM, 0); 199 | 200 | printf("rename netdevice %s to %s ... ", buf, name); 201 | 202 | if (s < 0) 203 | perror("socket for interface rename"); 204 | else { 205 | strncpy (ifr.ifr_name, buf, IFNAMSIZ); 206 | strncpy (ifr.ifr_newname, name, IFNAMSIZ); 207 | 208 | if (ioctl(s, SIOCSIFNAME, &ifr) < 0) 209 | printf("failed!\n"); 210 | else 211 | printf("ok.\n"); 212 | 213 | close(s); 214 | } 215 | } 216 | } 217 | 218 | if (waitkey) { 219 | printf("Press any key to detach %s ...\n", tty); 220 | getchar(); 221 | } 222 | 223 | if (waitkey || detach) { 224 | ldisc = N_TTY; 225 | if (ioctl (fd, TIOCSETD, &ldisc) < 0) { 226 | perror("ioctl"); 227 | exit(1); 228 | } 229 | 230 | if (send_close) { 231 | sprintf(buf, "C\r"); 232 | write(fd, buf, strlen(buf)); 233 | } 234 | } 235 | 236 | close(fd); 237 | 238 | return 0; 239 | } 240 | -------------------------------------------------------------------------------- /Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH := $(call my-dir) 2 | 3 | PRIVATE_LOCAL_CFLAGS := -O2 -g -W -Wall \ 4 | -DSO_RXQ_OVFL=40 \ 5 | -DPF_CAN=29 \ 6 | -DAF_CAN=PF_CAN 7 | 8 | # 9 | # canlib 10 | # 11 | 12 | include $(CLEAR_VARS) 13 | 14 | LOCAL_SRC_FILES := lib.c canframelen.c 15 | LOCAL_MODULE := libcan 16 | LOCAL_C_INCLUDES := $(LOCAL_PATH)/include/ 17 | LOCAL_CFLAGS := $(PRIVATE_LOCAL_CFLAGS) 18 | 19 | include $(BUILD_STATIC_LIBRARY) 20 | 21 | # 22 | # candump 23 | # 24 | 25 | include $(CLEAR_VARS) 26 | 27 | LOCAL_SRC_FILES := candump.c 28 | LOCAL_MODULE := candump 29 | LOCAL_MODULE_TAGS := optional 30 | LOCAL_STATIC_LIBRARIES := libcan 31 | LOCAL_C_INCLUDES := $(LOCAL_PATH)/include/ 32 | LOCAL_CFLAGS := $(PRIVATE_LOCAL_CFLAGS) 33 | 34 | include $(BUILD_EXECUTABLE) 35 | 36 | # 37 | # cansend 38 | # 39 | 40 | include $(CLEAR_VARS) 41 | 42 | LOCAL_SRC_FILES := cansend.c 43 | LOCAL_MODULE := cansend 44 | LOCAL_MODULE_TAGS := optional 45 | LOCAL_STATIC_LIBRARIES := libcan 46 | LOCAL_C_INCLUDES := $(LOCAL_PATH)/include/ 47 | LOCAL_CFLAGS := $(PRIVATE_LOCAL_CFLAGS) 48 | 49 | include $(BUILD_EXECUTABLE) 50 | 51 | # 52 | # bcmserver 53 | # 54 | 55 | include $(CLEAR_VARS) 56 | 57 | LOCAL_SRC_FILES := bcmserver.c 58 | LOCAL_MODULE := bcmserver 59 | LOCAL_MODULE_TAGS := optional 60 | LOCAL_C_INCLUDES := $(LOCAL_PATH)/include/ 61 | LOCAL_CFLAGS := $(PRIVATE_LOCAL_CFLAGS) 62 | 63 | include $(BUILD_EXECUTABLE) 64 | 65 | 66 | # 67 | # can-calc-bit-timing 68 | # 69 | 70 | include $(CLEAR_VARS) 71 | 72 | LOCAL_SRC_FILES := can-calc-bit-timing.c 73 | LOCAL_MODULE := can-calc-bit-timing 74 | LOCAL_MODULE_TAGS := optional 75 | LOCAL_C_INCLUDES := $(LOCAL_PATH)/include/ 76 | LOCAL_CFLAGS := $(PRIVATE_LOCAL_CFLAGS) 77 | 78 | include $(BUILD_EXECUTABLE) 79 | 80 | # 81 | # canbusload 82 | # 83 | 84 | include $(CLEAR_VARS) 85 | 86 | LOCAL_SRC_FILES := canbusload.c 87 | LOCAL_MODULE := canbusload 88 | LOCAL_MODULE_TAGS := optional 89 | LOCAL_STATIC_LIBRARIES := libcan 90 | LOCAL_C_INCLUDES := $(LOCAL_PATH)/include/ 91 | LOCAL_CFLAGS := $(PRIVATE_LOCAL_CFLAGS) 92 | 93 | include $(BUILD_EXECUTABLE) 94 | 95 | # 96 | # canfdtest 97 | # 98 | 99 | include $(CLEAR_VARS) 100 | 101 | LOCAL_SRC_FILES := canfdtest.c 102 | LOCAL_MODULE := canfdtest 103 | LOCAL_MODULE_TAGS := optional 104 | LOCAL_C_INCLUDES := $(LOCAL_PATH)/include/ 105 | LOCAL_CFLAGS := $(PRIVATE_LOCAL_CFLAGS) 106 | 107 | include $(BUILD_EXECUTABLE) 108 | 109 | # 110 | # cangen 111 | # 112 | 113 | include $(CLEAR_VARS) 114 | 115 | LOCAL_SRC_FILES := cangen.c 116 | LOCAL_MODULE := cangen 117 | LOCAL_MODULE_TAGS := optional 118 | LOCAL_STATIC_LIBRARIES := libcan 119 | LOCAL_C_INCLUDES := $(LOCAL_PATH)/include/ 120 | LOCAL_CFLAGS := $(PRIVATE_LOCAL_CFLAGS) 121 | 122 | include $(BUILD_EXECUTABLE) 123 | 124 | # 125 | # cangw 126 | # 127 | 128 | include $(CLEAR_VARS) 129 | 130 | LOCAL_SRC_FILES := cangw.c 131 | LOCAL_MODULE := cangw 132 | LOCAL_MODULE_TAGS := optional 133 | LOCAL_C_INCLUDES := $(LOCAL_PATH)/include/ 134 | LOCAL_CFLAGS := $(PRIVATE_LOCAL_CFLAGS) 135 | 136 | include $(BUILD_EXECUTABLE) 137 | 138 | # 139 | # canlogserver 140 | # 141 | 142 | include $(CLEAR_VARS) 143 | 144 | LOCAL_SRC_FILES := canlogserver.c 145 | LOCAL_MODULE := canlogserver 146 | LOCAL_MODULE_TAGS := optional 147 | LOCAL_STATIC_LIBRARIES := libcan 148 | LOCAL_C_INCLUDES := $(LOCAL_PATH)/include/ 149 | LOCAL_CFLAGS := $(PRIVATE_LOCAL_CFLAGS) 150 | 151 | include $(BUILD_EXECUTABLE) 152 | 153 | # 154 | # canplayer 155 | # 156 | 157 | include $(CLEAR_VARS) 158 | 159 | LOCAL_SRC_FILES := canplayer.c 160 | LOCAL_MODULE := canplayer 161 | LOCAL_MODULE_TAGS := optional 162 | LOCAL_STATIC_LIBRARIES := libcan 163 | LOCAL_C_INCLUDES := $(LOCAL_PATH)/include/ 164 | LOCAL_CFLAGS := $(PRIVATE_LOCAL_CFLAGS) 165 | 166 | include $(BUILD_EXECUTABLE) 167 | 168 | # 169 | # cansniffer 170 | # 171 | 172 | include $(CLEAR_VARS) 173 | 174 | LOCAL_SRC_FILES := cansniffer.c 175 | LOCAL_MODULE := cansniffer 176 | LOCAL_MODULE_TAGS := optional 177 | LOCAL_C_INCLUDES := $(LOCAL_PATH)/include/ 178 | LOCAL_CFLAGS := $(PRIVATE_LOCAL_CFLAGS) 179 | 180 | include $(BUILD_EXECUTABLE) 181 | 182 | # 183 | # isotpdump 184 | # 185 | 186 | include $(CLEAR_VARS) 187 | 188 | LOCAL_SRC_FILES := isotpdump.c 189 | LOCAL_MODULE := isotpdump 190 | LOCAL_MODULE_TAGS := optional 191 | LOCAL_C_INCLUDES := $(LOCAL_PATH)/include/ 192 | LOCAL_CFLAGS := $(PRIVATE_LOCAL_CFLAGS) 193 | 194 | include $(BUILD_EXECUTABLE) 195 | 196 | # 197 | # isotprecv 198 | # 199 | 200 | include $(CLEAR_VARS) 201 | 202 | LOCAL_SRC_FILES := isotprecv.c 203 | LOCAL_MODULE := isotprecv 204 | LOCAL_MODULE_TAGS := optional 205 | LOCAL_C_INCLUDES := $(LOCAL_PATH)/include/ 206 | LOCAL_CFLAGS := $(PRIVATE_LOCAL_CFLAGS) 207 | 208 | include $(BUILD_EXECUTABLE) 209 | 210 | # 211 | # isotpsend 212 | # 213 | 214 | include $(CLEAR_VARS) 215 | 216 | LOCAL_SRC_FILES := isotpsend.c 217 | LOCAL_MODULE := isotpsend 218 | LOCAL_MODULE_TAGS := optional 219 | LOCAL_C_INCLUDES := $(LOCAL_PATH)/include/ 220 | LOCAL_CFLAGS := $(PRIVATE_LOCAL_CFLAGS) 221 | 222 | include $(BUILD_EXECUTABLE) 223 | 224 | # 225 | # isotpserver 226 | # 227 | 228 | include $(CLEAR_VARS) 229 | 230 | LOCAL_SRC_FILES := isotpserver.c 231 | LOCAL_MODULE := isotpserver 232 | LOCAL_MODULE_TAGS := optional 233 | LOCAL_C_INCLUDES := $(LOCAL_PATH)/include/ 234 | LOCAL_CFLAGS := $(PRIVATE_LOCAL_CFLAGS) 235 | 236 | include $(BUILD_EXECUTABLE) 237 | 238 | # 239 | # isotpsniffer 240 | # 241 | 242 | include $(CLEAR_VARS) 243 | 244 | LOCAL_SRC_FILES := isotpsniffer.c 245 | LOCAL_MODULE := isotpsniffer.c 246 | LOCAL_MODULE_TAGS := optional 247 | LOCAL_C_INCLUDES := $(LOCAL_PATH)/include/ 248 | LOCAL_CFLAGS := $(PRIVATE_LOCAL_CFLAGS) 249 | 250 | include $(BUILD_EXECUTABLE) 251 | 252 | # 253 | # isotptun 254 | # 255 | 256 | include $(CLEAR_VARS) 257 | 258 | LOCAL_SRC_FILES := isotptun.c 259 | LOCAL_MODULE := isotptun 260 | LOCAL_MODULE_TAGS := optional 261 | LOCAL_C_INCLUDES := $(LOCAL_PATH)/include/ 262 | LOCAL_CFLAGS := $(PRIVATE_LOCAL_CFLAGS) 263 | 264 | include $(BUILD_EXECUTABLE) 265 | 266 | # 267 | # isotpperf 268 | # 269 | 270 | include $(CLEAR_VARS) 271 | 272 | LOCAL_SRC_FILES := isotpperf.c 273 | LOCAL_MODULE := isotpperf 274 | LOCAL_MODULE_TAGS := optional 275 | LOCAL_C_INCLUDES := $(LOCAL_PATH)/include/ 276 | LOCAL_CFLAGS := $(PRIVATE_LOCAL_CFLAGS) 277 | 278 | include $(BUILD_EXECUTABLE) 279 | 280 | # 281 | # log2asc 282 | # 283 | 284 | include $(CLEAR_VARS) 285 | 286 | LOCAL_SRC_FILES := log2asc.c 287 | LOCAL_MODULE := log2asc 288 | LOCAL_MODULE_TAGS := optional 289 | LOCAL_STATIC_LIBRARIES := libcan 290 | LOCAL_C_INCLUDES := $(LOCAL_PATH)/include/ 291 | LOCAL_CFLAGS := $(PRIVATE_LOCAL_CFLAGS) 292 | 293 | include $(BUILD_EXECUTABLE) 294 | 295 | # 296 | # log2long 297 | # 298 | 299 | include $(CLEAR_VARS) 300 | 301 | LOCAL_SRC_FILES := log2long.c 302 | LOCAL_MODULE := log2long 303 | LOCAL_MODULE_TAGS := optional 304 | LOCAL_STATIC_LIBRARIES := libcan 305 | LOCAL_C_INCLUDES := $(LOCAL_PATH)/include/ 306 | LOCAL_CFLAGS := $(PRIVATE_LOCAL_CFLAGS) 307 | 308 | include $(BUILD_EXECUTABLE) 309 | 310 | # 311 | # slcan_attach 312 | # 313 | 314 | include $(CLEAR_VARS) 315 | 316 | LOCAL_SRC_FILES := slcan_attach.c 317 | LOCAL_MODULE := slcan_attach 318 | LOCAL_MODULE_TAGS := optional 319 | LOCAL_C_INCLUDES := $(LOCAL_PATH)/include/ 320 | LOCAL_CFLAGS := $(PRIVATE_LOCAL_CFLAGS) 321 | 322 | include $(BUILD_EXECUTABLE) 323 | 324 | # 325 | # slcand 326 | # 327 | 328 | include $(CLEAR_VARS) 329 | 330 | LOCAL_SRC_FILES := slcand.c 331 | LOCAL_MODULE := slcand 332 | LOCAL_MODULE_TAGS := optional 333 | LOCAL_C_INCLUDES := $(LOCAL_PATH)/include/ 334 | LOCAL_CFLAGS := $(PRIVATE_LOCAL_CFLAGS) 335 | 336 | include $(BUILD_EXECUTABLE) 337 | 338 | # 339 | # slcanpty 340 | # 341 | 342 | include $(CLEAR_VARS) 343 | 344 | LOCAL_SRC_FILES := slcanpty.c 345 | LOCAL_MODULE := slcanpty 346 | LOCAL_MODULE_TAGS := optional 347 | LOCAL_C_INCLUDES := $(LOCAL_PATH)/include/ 348 | LOCAL_CFLAGS := $(PRIVATE_LOCAL_CFLAGS) 349 | 350 | include $(BUILD_EXECUTABLE) 351 | -------------------------------------------------------------------------------- /old_include/mac/if.h: -------------------------------------------------------------------------------- 1 | /* net/if.h -- declarations for inquiring about network interfaces 2 | Copyright (C) 1997,98,99,2000,2001 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, write to the Free 17 | Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 18 | 02111-1307 USA. */ 19 | 20 | #ifndef _NET_IF_H 21 | #define _NET_IF_H 1 22 | 23 | // #include 24 | 25 | #ifdef __USE_MISC 26 | # include "mac_os_types.h" 27 | # include 28 | #endif 29 | 30 | 31 | /* Length of interface name. */ 32 | #define IF_NAMESIZE 16 33 | 34 | struct if_nameindex 35 | { 36 | unsigned int if_index; /* 1, 2, ... */ 37 | char *if_name; /* null terminated name: "eth0", ... */ 38 | }; 39 | 40 | 41 | #ifdef __USE_MISC 42 | /* Standard interface flags. */ 43 | enum 44 | { 45 | IFF_UP = 0x1, /* Interface is up. */ 46 | # define IFF_UP IFF_UP 47 | IFF_BROADCAST = 0x2, /* Broadcast address valid. */ 48 | # define IFF_BROADCAST IFF_BROADCAST 49 | IFF_DEBUG = 0x4, /* Turn on debugging. */ 50 | # define IFF_DEBUG IFF_DEBUG 51 | IFF_LOOPBACK = 0x8, /* Is a loopback net. */ 52 | # define IFF_LOOPBACK IFF_LOOPBACK 53 | IFF_POINTOPOINT = 0x10, /* Interface is point-to-point link. */ 54 | # define IFF_POINTOPOINT IFF_POINTOPOINT 55 | IFF_NOTRAILERS = 0x20, /* Avoid use of trailers. */ 56 | # define IFF_NOTRAILERS IFF_NOTRAILERS 57 | IFF_RUNNING = 0x40, /* Resources allocated. */ 58 | # define IFF_RUNNING IFF_RUNNING 59 | IFF_NOARP = 0x80, /* No address resolution protocol. */ 60 | # define IFF_NOARP IFF_NOARP 61 | IFF_PROMISC = 0x100, /* Receive all packets. */ 62 | # define IFF_PROMISC IFF_PROMISC 63 | 64 | /* Not supported */ 65 | IFF_ALLMULTI = 0x200, /* Receive all multicast packets. */ 66 | # define IFF_ALLMULTI IFF_ALLMULTI 67 | 68 | IFF_MASTER = 0x400, /* Master of a load balancer. */ 69 | # define IFF_MASTER IFF_MASTER 70 | IFF_SLAVE = 0x800, /* Slave of a load balancer. */ 71 | # define IFF_SLAVE IFF_SLAVE 72 | 73 | IFF_MULTICAST = 0x1000, /* Supports multicast. */ 74 | # define IFF_MULTICAST IFF_MULTICAST 75 | 76 | IFF_PORTSEL = 0x2000, /* Can set media type. */ 77 | # define IFF_PORTSEL IFF_PORTSEL 78 | IFF_AUTOMEDIA = 0x4000, /* Auto media select active. */ 79 | # define IFF_AUTOMEDIA IFF_AUTOMEDIA 80 | IFF_DYNAMIC = 0x8000 /* Dialup device with changing addresses. */ 81 | # define IFF_DYNAMIC IFF_DYNAMIC 82 | }; 83 | 84 | /* The ifaddr structure contains information about one address of an 85 | interface. They are maintained by the different address families, 86 | are allocated and attached when an address is set, and are linked 87 | together so all addresses for an interface can be located. */ 88 | 89 | struct ifaddr 90 | { 91 | struct sockaddr ifa_addr; /* Address of interface. */ 92 | union 93 | { 94 | struct sockaddr ifu_broadaddr; 95 | struct sockaddr ifu_dstaddr; 96 | } ifa_ifu; 97 | struct iface *ifa_ifp; /* Back-pointer to interface. */ 98 | struct ifaddr *ifa_next; /* Next address for interface. */ 99 | }; 100 | 101 | # define ifa_broadaddr ifa_ifu.ifu_broadaddr /* broadcast address */ 102 | # define ifa_dstaddr ifa_ifu.ifu_dstaddr /* other end of link */ 103 | 104 | /* Device mapping structure. I'd just gone off and designed a 105 | beautiful scheme using only loadable modules with arguments for 106 | driver options and along come the PCMCIA people 8) 107 | 108 | Ah well. The get() side of this is good for WDSETUP, and it'll be 109 | handy for debugging things. The set side is fine for now and being 110 | very small might be worth keeping for clean configuration. */ 111 | 112 | struct ifmap 113 | { 114 | unsigned long int mem_start; 115 | unsigned long int mem_end; 116 | unsigned short int base_addr; 117 | unsigned char irq; 118 | unsigned char dma; 119 | unsigned char port; 120 | /* 3 bytes spare */ 121 | }; 122 | 123 | /* Interface request structure used for socket ioctl's. All interface 124 | ioctl's must have parameter definitions which begin with ifr_name. 125 | The remainder may be interface specific. */ 126 | 127 | struct ifreq 128 | { 129 | # define IFHWADDRLEN 6 130 | # define IFNAMSIZ IF_NAMESIZE 131 | union 132 | { 133 | char ifrn_name[IFNAMSIZ]; /* Interface name, e.g. "en0". */ 134 | } ifr_ifrn; 135 | 136 | union 137 | { 138 | struct sockaddr ifru_addr; 139 | struct sockaddr ifru_dstaddr; 140 | struct sockaddr ifru_broadaddr; 141 | struct sockaddr ifru_netmask; 142 | struct sockaddr ifru_hwaddr; 143 | short int ifru_flags; 144 | int ifru_ivalue; 145 | int ifru_mtu; 146 | struct ifmap ifru_map; 147 | char ifru_slave[IFNAMSIZ]; /* Just fits the size */ 148 | char ifru_newname[IFNAMSIZ]; 149 | __caddr_t ifru_data; 150 | } ifr_ifru; 151 | }; 152 | # define ifr_name ifr_ifrn.ifrn_name /* interface name */ 153 | # define ifr_hwaddr ifr_ifru.ifru_hwaddr /* MAC address */ 154 | # define ifr_addr ifr_ifru.ifru_addr /* address */ 155 | # define ifr_dstaddr ifr_ifru.ifru_dstaddr /* other end of p-p lnk */ 156 | # define ifr_broadaddr ifr_ifru.ifru_broadaddr /* broadcast address */ 157 | # define ifr_netmask ifr_ifru.ifru_netmask /* interface net mask */ 158 | # define ifr_flags ifr_ifru.ifru_flags /* flags */ 159 | # define ifr_metric ifr_ifru.ifru_ivalue /* metric */ 160 | # define ifr_mtu ifr_ifru.ifru_mtu /* mtu */ 161 | # define ifr_map ifr_ifru.ifru_map /* device map */ 162 | # define ifr_slave ifr_ifru.ifru_slave /* slave device */ 163 | # define ifr_data ifr_ifru.ifru_data /* for use by interface */ 164 | # define ifr_ifindex ifr_ifru.ifru_ivalue /* interface index */ 165 | # define ifr_bandwidth ifr_ifru.ifru_ivalue /* link bandwidth */ 166 | # define ifr_qlen ifr_ifru.ifru_ivalue /* queue length */ 167 | # define ifr_newname ifr_ifru.ifru_newname /* New name */ 168 | # define _IOT_ifreq _IOT(_IOTS(char),IFNAMSIZ,_IOTS(char),16,0,0) 169 | # define _IOT_ifreq_short _IOT(_IOTS(char),IFNAMSIZ,_IOTS(short),1,0,0) 170 | # define _IOT_ifreq_int _IOT(_IOTS(char),IFNAMSIZ,_IOTS(int),1,0,0) 171 | 172 | 173 | /* Structure used in SIOCGIFCONF request. Used to retrieve interface 174 | configuration for machine (useful for programs which must know all 175 | networks accessible). */ 176 | 177 | struct ifconf 178 | { 179 | int ifc_len; /* Size of buffer. */ 180 | union 181 | { 182 | __caddr_t ifcu_buf; 183 | struct ifreq *ifcu_req; 184 | } ifc_ifcu; 185 | }; 186 | # define ifc_buf ifc_ifcu.ifcu_buf /* Buffer address. */ 187 | # define ifc_req ifc_ifcu.ifcu_req /* Array of structures. */ 188 | # define _IOT_ifconf _IOT(_IOTS(struct ifconf),1,0,0,0,0) /* not right */ 189 | #endif /* Misc. */ 190 | 191 | __BEGIN_DECLS 192 | 193 | /* Convert an interface name to an index, and vice versa. */ 194 | extern unsigned int if_nametoindex (__const char *__ifname) __THROW; 195 | extern char *if_indextoname (unsigned int __ifindex, char *__ifname) __THROW; 196 | 197 | /* Return a list of all interfaces and their indices. */ 198 | extern struct if_nameindex *if_nameindex (void) __THROW; 199 | 200 | /* Free the data returned from if_nameindex. */ 201 | extern void if_freenameindex (struct if_nameindex *__ptr) __THROW; 202 | 203 | __END_DECLS 204 | 205 | #endif /* net/if.h */ 206 | -------------------------------------------------------------------------------- /old_include/mac/can/gw.h: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/can/gw.h 3 | * 4 | * Definitions for CAN frame Gateway/Router/Bridge 5 | * 6 | * Author: Oliver Hartkopp 7 | * Copyright (c) 2011 Volkswagen Group Electronic Research 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of Volkswagen nor the names of its contributors 19 | * may be used to endorse or promote products derived from this software 20 | * without specific prior written permission. 21 | * 22 | * Alternatively, provided that this notice is retained in full, this 23 | * software may be distributed under the terms of the GNU General 24 | * Public License ("GPL") version 2, in which case the provisions of the 25 | * GPL apply INSTEAD OF those given above. 26 | * 27 | * The provided data structures and external interfaces from this code 28 | * are not restricted to be used by modules with a GPL compatible license. 29 | * 30 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 31 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 32 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 33 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 34 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 35 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 36 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 37 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 38 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 39 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 40 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 41 | * DAMAGE. 42 | */ 43 | 44 | #ifndef CAN_GW_H 45 | #define CAN_GW_H 46 | 47 | #include "mac_os_types.h" 48 | #include 49 | 50 | struct rtcanmsg { 51 | __u8 can_family; 52 | __u8 gwtype; 53 | __u16 flags; 54 | }; 55 | 56 | /* CAN gateway types */ 57 | enum { 58 | CGW_TYPE_UNSPEC, 59 | CGW_TYPE_CAN_CAN, /* CAN->CAN routing */ 60 | __CGW_TYPE_MAX 61 | }; 62 | 63 | #define CGW_TYPE_MAX (__CGW_TYPE_MAX - 1) 64 | 65 | /* CAN rtnetlink attribute definitions */ 66 | enum { 67 | CGW_UNSPEC, 68 | CGW_MOD_AND, /* CAN frame modification binary AND */ 69 | CGW_MOD_OR, /* CAN frame modification binary OR */ 70 | CGW_MOD_XOR, /* CAN frame modification binary XOR */ 71 | CGW_MOD_SET, /* CAN frame modification set alternate values */ 72 | CGW_CS_XOR, /* set data[] XOR checksum into data[index] */ 73 | CGW_CS_CRC8, /* set data[] CRC8 checksum into data[index] */ 74 | CGW_HANDLED, /* number of handled CAN frames */ 75 | CGW_DROPPED, /* number of dropped CAN frames */ 76 | CGW_SRC_IF, /* ifindex of source network interface */ 77 | CGW_DST_IF, /* ifindex of destination network interface */ 78 | CGW_FILTER, /* specify struct can_filter on source CAN device */ 79 | CGW_DELETED, /* number of deleted CAN frames (see max_hops param) */ 80 | CGW_LIM_HOPS, /* limit the number of hops of this specific rule */ 81 | CGW_MOD_UID, /* user defined identifier for modification updates */ 82 | __CGW_MAX 83 | }; 84 | 85 | #define CGW_MAX (__CGW_MAX - 1) 86 | 87 | #define CGW_FLAGS_CAN_ECHO 0x01 88 | #define CGW_FLAGS_CAN_SRC_TSTAMP 0x02 89 | #define CGW_FLAGS_CAN_IIF_TX_OK 0x04 90 | 91 | #define CGW_MOD_FUNCS 4 /* AND OR XOR SET */ 92 | 93 | /* CAN frame elements that are affected by curr. 3 CAN frame modifications */ 94 | #define CGW_MOD_ID 0x01 95 | #define CGW_MOD_DLC 0x02 96 | #define CGW_MOD_DATA 0x04 97 | 98 | #define CGW_FRAME_MODS 3 /* ID DLC DATA */ 99 | 100 | #define MAX_MODFUNCTIONS (CGW_MOD_FUNCS * CGW_FRAME_MODS) 101 | 102 | struct cgw_frame_mod { 103 | struct can_frame cf; 104 | __u8 modtype; 105 | } __attribute__((packed)); 106 | 107 | #define CGW_MODATTR_LEN sizeof(struct cgw_frame_mod) 108 | 109 | struct cgw_csum_xor { 110 | __s8 from_idx; 111 | __s8 to_idx; 112 | __s8 result_idx; 113 | __u8 init_xor_val; 114 | } __attribute__((packed)); 115 | 116 | struct cgw_csum_crc8 { 117 | __s8 from_idx; 118 | __s8 to_idx; 119 | __s8 result_idx; 120 | __u8 init_crc_val; 121 | __u8 final_xor_val; 122 | __u8 crctab[256]; 123 | __u8 profile; 124 | __u8 profile_data[20]; 125 | } __attribute__((packed)); 126 | 127 | /* length of checksum operation parameters. idx = index in CAN frame data[] */ 128 | #define CGW_CS_XOR_LEN sizeof(struct cgw_csum_xor) 129 | #define CGW_CS_CRC8_LEN sizeof(struct cgw_csum_crc8) 130 | 131 | /* CRC8 profiles (compute CRC for additional data elements - see below) */ 132 | enum { 133 | CGW_CRC8PRF_UNSPEC, 134 | CGW_CRC8PRF_1U8, /* compute one additional u8 value */ 135 | CGW_CRC8PRF_16U8, /* u8 value table indexed by data[1] & 0xF */ 136 | CGW_CRC8PRF_SFFID_XOR, /* (can_id & 0xFF) ^ (can_id >> 8 & 0xFF) */ 137 | __CGW_CRC8PRF_MAX 138 | }; 139 | 140 | #define CGW_CRC8PRF_MAX (__CGW_CRC8PRF_MAX - 1) 141 | 142 | /* 143 | * CAN rtnetlink attribute contents in detail 144 | * 145 | * CGW_XXX_IF (length 4 bytes): 146 | * Sets an interface index for source/destination network interfaces. 147 | * For the CAN->CAN gwtype the indices of _two_ CAN interfaces are mandatory. 148 | * 149 | * CGW_FILTER (length 8 bytes): 150 | * Sets a CAN receive filter for the gateway job specified by the 151 | * struct can_filter described in include/linux/can.h 152 | * 153 | * CGW_MOD_(AND|OR|XOR|SET) (length 17 bytes): 154 | * Specifies a modification that's done to a received CAN frame before it is 155 | * send out to the destination interface. 156 | * 157 | * data used as operator 158 | * affected CAN frame elements 159 | * 160 | * CGW_LIM_HOPS (length 1 byte): 161 | * Limit the number of hops of this specific rule. Usually the received CAN 162 | * frame can be processed as much as 'max_hops' times (which is given at module 163 | * load time of the can-gw module). This value is used to reduce the number of 164 | * possible hops for this gateway rule to a value smaller then max_hops. 165 | * 166 | * CGW_MOD_UID (length 4 bytes): 167 | * Optional non-zero user defined routing job identifier to alter existing 168 | * modification settings at runtime. 169 | * 170 | * CGW_CS_XOR (length 4 bytes): 171 | * Set a simple XOR checksum starting with an initial value into 172 | * data[result-idx] using data[start-idx] .. data[end-idx] 173 | * 174 | * The XOR checksum is calculated like this: 175 | * 176 | * xor = init_xor_val 177 | * 178 | * for (i = from_idx .. to_idx) 179 | * xor ^= can_frame.data[i] 180 | * 181 | * can_frame.data[ result_idx ] = xor 182 | * 183 | * CGW_CS_CRC8 (length 282 bytes): 184 | * Set a CRC8 value into data[result-idx] using a given 256 byte CRC8 table, 185 | * a given initial value and a defined input data[start-idx] .. data[end-idx]. 186 | * Finally the result value is XOR'ed with the final_xor_val. 187 | * 188 | * The CRC8 checksum is calculated like this: 189 | * 190 | * crc = init_crc_val 191 | * 192 | * for (i = from_idx .. to_idx) 193 | * crc = crctab[ crc ^ can_frame.data[i] ] 194 | * 195 | * can_frame.data[ result_idx ] = crc ^ final_xor_val 196 | * 197 | * The calculated CRC may contain additional source data elements that can be 198 | * defined in the handling of 'checksum profiles' e.g. shown in AUTOSAR specs 199 | * like http://www.autosar.org/download/R4.0/AUTOSAR_SWS_E2ELibrary.pdf 200 | * E.g. the profile_data[] may contain additional u8 values (called DATA_IDs) 201 | * that are used depending on counter values inside the CAN frame data[]. 202 | * So far only three profiles have been implemented for illustration. 203 | * 204 | * Remark: In general the attribute data is a linear buffer. 205 | * Beware of sending unpacked or aligned structs! 206 | */ 207 | 208 | #endif 209 | -------------------------------------------------------------------------------- /old_include/mac/can.h: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/can.h 3 | * 4 | * Definitions for CAN network layer (socket addr / CAN frame / CAN filter) 5 | * 6 | * Authors: Oliver Hartkopp 7 | * Urs Thuermann 8 | * Copyright (c) 2002-2007 Volkswagen Group Electronic Research 9 | * All rights reserved. 10 | * 11 | * Redistribution and use in source and binary forms, with or without 12 | * modification, are permitted provided that the following conditions 13 | * are met: 14 | * 1. Redistributions of source code must retain the above copyright 15 | * notice, this list of conditions and the following disclaimer. 16 | * 2. Redistributions in binary form must reproduce the above copyright 17 | * notice, this list of conditions and the following disclaimer in the 18 | * documentation and/or other materials provided with the distribution. 19 | * 3. Neither the name of Volkswagen nor the names of its contributors 20 | * may be used to endorse or promote products derived from this software 21 | * without specific prior written permission. 22 | * 23 | * Alternatively, provided that this notice is retained in full, this 24 | * software may be distributed under the terms of the GNU General 25 | * Public License ("GPL") version 2, in which case the provisions of the 26 | * GPL apply INSTEAD OF those given above. 27 | * 28 | * The provided data structures and external interfaces from this code 29 | * are not restricted to be used by modules with a GPL compatible license. 30 | * 31 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 32 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 33 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 34 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 35 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 36 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 37 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 38 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 39 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 40 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 41 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 42 | * DAMAGE. 43 | */ 44 | 45 | #ifndef CAN_H 46 | #define CAN_H 47 | 48 | #include "mac_os_types.h" 49 | #include 50 | 51 | /* controller area network (CAN) kernel definitions */ 52 | 53 | /* special address description flags for the CAN_ID */ 54 | #define CAN_EFF_FLAG 0x80000000U /* EFF/SFF is set in the MSB */ 55 | #define CAN_RTR_FLAG 0x40000000U /* remote transmission request */ 56 | #define CAN_ERR_FLAG 0x20000000U /* error message frame */ 57 | 58 | /* valid bits in CAN ID for frame formats */ 59 | #define CAN_SFF_MASK 0x000007FFU /* standard frame format (SFF) */ 60 | #define CAN_EFF_MASK 0x1FFFFFFFU /* extended frame format (EFF) */ 61 | #define CAN_ERR_MASK 0x1FFFFFFFU /* omit EFF, RTR, ERR flags */ 62 | 63 | /* 64 | * Controller Area Network Identifier structure 65 | * 66 | * bit 0-28 : CAN identifier (11/29 bit) 67 | * bit 29 : error message frame flag (0 = data frame, 1 = error message) 68 | * bit 30 : remote transmission request flag (1 = rtr frame) 69 | * bit 31 : frame format flag (0 = standard 11 bit, 1 = extended 29 bit) 70 | */ 71 | typedef __u32 canid_t; 72 | 73 | #define CAN_SFF_ID_BITS 11 74 | #define CAN_EFF_ID_BITS 29 75 | 76 | /* 77 | * Controller Area Network Error Message Frame Mask structure 78 | * 79 | * bit 0-28 : error class mask (see include/linux/can/error.h) 80 | * bit 29-31 : set to zero 81 | */ 82 | typedef __u32 can_err_mask_t; 83 | 84 | /* CAN payload length and DLC definitions according to ISO 11898-1 */ 85 | #define CAN_MAX_DLC 8 86 | #define CAN_MAX_DLEN 8 87 | 88 | /* CAN FD payload length and DLC definitions according to ISO 11898-7 */ 89 | #define CANFD_MAX_DLC 15 90 | #define CANFD_MAX_DLEN 64 91 | 92 | /** 93 | * struct can_frame - basic CAN frame structure 94 | * @can_id: CAN ID of the frame and CAN_*_FLAG flags, see canid_t definition 95 | * @can_dlc: frame payload length in byte (0 .. 8) aka data length code 96 | * N.B. the DLC field from ISO 11898-1 Chapter 8.4.2.3 has a 1:1 97 | * mapping of the 'data length code' to the real payload length 98 | * @data: CAN frame payload (up to 8 byte) 99 | */ 100 | struct can_frame { 101 | canid_t can_id; /* 32 bit CAN_ID + EFF/RTR/ERR flags */ 102 | __u8 can_dlc; /* frame payload length in byte (0 .. CAN_MAX_DLEN) */ 103 | __u8 data[CAN_MAX_DLEN] __attribute__((aligned(8))); 104 | }; 105 | 106 | /* 107 | * defined bits for canfd_frame.flags 108 | * 109 | * The use of struct canfd_frame implies the Extended Data Length (EDL) bit to 110 | * be set in the CAN frame bitstream on the wire. The EDL bit switch turns 111 | * the CAN controllers bitstream processor into the CAN FD mode which creates 112 | * two new options within the CAN FD frame specification: 113 | * 114 | * Bit Rate Switch - to indicate a second bitrate is/was used for the payload 115 | * Error State Indicator - represents the error state of the transmitting node 116 | * 117 | * As the CANFD_ESI bit is internally generated by the transmitting CAN 118 | * controller only the CANFD_BRS bit is relevant for real CAN controllers when 119 | * building a CAN FD frame for transmission. Setting the CANFD_ESI bit can make 120 | * sense for virtual CAN interfaces to test applications with echoed frames. 121 | */ 122 | #define CANFD_BRS 0x01 /* bit rate switch (second bitrate for payload data) */ 123 | #define CANFD_ESI 0x02 /* error state indicator of the transmitting node */ 124 | 125 | /** 126 | * struct canfd_frame - CAN flexible data rate frame structure 127 | * @can_id: CAN ID of the frame and CAN_*_FLAG flags, see canid_t definition 128 | * @len: frame payload length in byte (0 .. CANFD_MAX_DLEN) 129 | * @flags: additional flags for CAN FD 130 | * @__res0: reserved / padding 131 | * @__res1: reserved / padding 132 | * @data: CAN FD frame payload (up to CANFD_MAX_DLEN byte) 133 | */ 134 | struct canfd_frame { 135 | canid_t can_id; /* 32 bit CAN_ID + EFF/RTR/ERR flags */ 136 | __u8 len; /* frame payload length in byte */ 137 | __u8 flags; /* additional flags for CAN FD */ 138 | __u8 __res0; /* reserved / padding */ 139 | __u8 __res1; /* reserved / padding */ 140 | __u8 data[CANFD_MAX_DLEN] __attribute__((aligned(8))); 141 | }; 142 | 143 | #define CAN_MTU (sizeof(struct can_frame)) 144 | #define CANFD_MTU (sizeof(struct canfd_frame)) 145 | 146 | /* particular protocols of the protocol family PF_CAN */ 147 | #define CAN_RAW 1 /* RAW sockets */ 148 | #define CAN_BCM 2 /* Broadcast Manager */ 149 | #define CAN_TP16 3 /* VAG Transport Protocol v1.6 */ 150 | #define CAN_TP20 4 /* VAG Transport Protocol v2.0 */ 151 | #define CAN_MCNET 5 /* Bosch MCNet */ 152 | #define CAN_ISOTP 6 /* ISO 15765-2 Transport Protocol */ 153 | #define CAN_NPROTO 7 154 | 155 | #define SOL_CAN_BASE 100 156 | 157 | /* 158 | * This typedef was introduced in Linux v3.1-rc2 159 | * (commit 6602a4b net: Make userland include of netlink.h more sane) 160 | * in . It must be duplicated here to make the CAN 161 | * headers self-contained. 162 | */ 163 | typedef unsigned short __kernel_sa_family_t; 164 | 165 | /** 166 | * struct sockaddr_can - the sockaddr structure for CAN sockets 167 | * @can_family: address family number AF_CAN. 168 | * @can_ifindex: CAN network interface index. 169 | * @can_addr: protocol specific address information 170 | */ 171 | struct sockaddr_can { 172 | __kernel_sa_family_t can_family; 173 | int can_ifindex; 174 | union { 175 | /* transport protocol class address information (e.g. ISOTP) */ 176 | struct { canid_t rx_id, tx_id; } tp; 177 | 178 | /* reserved for future CAN protocols address information */ 179 | } can_addr; 180 | }; 181 | 182 | /** 183 | * struct can_filter - CAN ID based filter in can_register(). 184 | * @can_id: relevant bits of CAN ID which are not masked out. 185 | * @can_mask: CAN mask (see description) 186 | * 187 | * Description: 188 | * A filter matches, when 189 | * 190 | * & mask == can_id & mask 191 | * 192 | * The filter can be inverted (CAN_INV_FILTER bit set in can_id) or it can 193 | * filter for error message frames (CAN_ERR_FLAG bit set in mask). 194 | */ 195 | struct can_filter { 196 | canid_t can_id; 197 | canid_t can_mask; 198 | }; 199 | 200 | #define CAN_INV_FILTER 0x20000000U /* to be set in can_filter.can_id */ 201 | 202 | #endif /* CAN_H */ 203 | -------------------------------------------------------------------------------- /isotprecv.c: -------------------------------------------------------------------------------- 1 | /* 2 | * isotprecv.c 3 | * 4 | * Copyright (c) 2008 Volkswagen Group Electronic Research 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 3. Neither the name of Volkswagen nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * Alternatively, provided that this notice is retained in full, this 20 | * software may be distributed under the terms of the GNU General 21 | * Public License ("GPL") version 2, in which case the provisions of the 22 | * GPL apply INSTEAD OF those given above. 23 | * 24 | * The provided data structures and external interfaces from this code 25 | * are not restricted to be used by modules with a GPL compatible license. 26 | * 27 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 28 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 29 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 30 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 31 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 32 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 33 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 34 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 35 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 36 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 37 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 38 | * DAMAGE. 39 | * 40 | * Send feedback to 41 | * 42 | */ 43 | 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | 50 | #include 51 | #include 52 | #include 53 | #include 54 | 55 | #include 56 | #include 57 | 58 | #define NO_CAN_ID 0xFFFFFFFFU 59 | #define BUFSIZE 5000 /* size > 4095 to check socket API internal checks */ 60 | 61 | void print_usage(char *prg) 62 | { 63 | fprintf(stderr, "\nUsage: %s [options] \n", prg); 64 | fprintf(stderr, "Options: -s (source can_id. Use 8 digits for extended IDs)\n"); 65 | fprintf(stderr, " -d (destination can_id. Use 8 digits for extended IDs)\n"); 66 | fprintf(stderr, " -x [:] (extended addressing / opt. separate rxaddr)\n"); 67 | fprintf(stderr, " -p [tx]:[rx] (set and enable tx/rx padding bytes)\n"); 68 | fprintf(stderr, " -P (check rx padding for (l)ength (c)ontent (a)ll)\n"); 69 | fprintf(stderr, " -b (blocksize. 0 = off)\n"); 70 | fprintf(stderr, " -m (STmin in ms/ns. See spec.)\n"); 71 | fprintf(stderr, " -f