From d9b6577d1a6d8629313e8c6b4bf9dee6ef6b1fbf Mon Sep 17 00:00:00 2001 From: Luotao Fu Date: Fri, 20 Nov 2009 15:29:42 +0100 Subject: [PATCH 01/88] initial create libsocketcan-nl project Signed-off-by: Luotao Fu --- GNUmakefile.am | 34 ++ autogen-oldtools.sh | 45 ++ autogen.sh | 22 + config/GNUmakefile.am | 8 + config/libsocketcan-nl.pc.in | 12 + config/m4/.secret-world-domination-project | 0 config/m4/acx_pthread.m4 | 238 +++++++++ configure.ac | 122 +++++ include/GNUmakefile.am | 9 + include/can/netlink.h | 113 +++++ include/libsocketcan-nl.h | 5 + include/libsocketcan-nlstuff.h | 5 + include/socketcan_netlink.h | 49 ++ src/GNUmakefile.am | 17 + src/socketcan_netlink.c | 554 +++++++++++++++++++++ tests/GNUmakefile.am | 17 + tests/test.c | 7 + 17 files changed, 1257 insertions(+) create mode 100644 GNUmakefile.am create mode 100755 autogen-oldtools.sh create mode 100755 autogen.sh create mode 100644 config/GNUmakefile.am create mode 100644 config/libsocketcan-nl.pc.in create mode 100644 config/m4/.secret-world-domination-project create mode 100644 config/m4/acx_pthread.m4 create mode 100644 configure.ac create mode 100644 include/GNUmakefile.am create mode 100644 include/can/netlink.h create mode 100644 include/libsocketcan-nl.h create mode 100644 include/libsocketcan-nlstuff.h create mode 100644 include/socketcan_netlink.h create mode 100644 src/GNUmakefile.am create mode 100644 src/socketcan_netlink.c create mode 100644 tests/GNUmakefile.am create mode 100644 tests/test.c diff --git a/GNUmakefile.am b/GNUmakefile.am new file mode 100644 index 00000000..7f8d6f82 --- /dev/null +++ b/GNUmakefile.am @@ -0,0 +1,34 @@ +SUBDIRS = \ + include \ + config \ + src \ + tests + +EXTRA_DIST = \ + autogen.sh \ + config/m4/.secret-world-domination-project + +MAINTAINERCLEANFILES = \ + configure \ + GNUmakefile.in \ + aclocal.m4 \ + config/autoconf/compile \ + config/autoconf/config.guess \ + config/autoconf/config.sub \ + config/autoconf/depcomp \ + config/autoconf/install-sh \ + config/autoconf/ltmain.sh \ + config/autoconf/mdate-sh \ + config/autoconf/missing \ + config/autoconf/texinfo.tex \ + config/m4/libtool.m4 \ + config/m4/ltoptions.m4 \ + config/m4/ltsugar.m4 \ + config/m4/ltversion.m4 \ + config/m4/lt~obsolete.m4 \ + $(DIST_ARCHIVES) + +maintainer-clean-local: + -chmod -R a+rw $(distdir) + -rm -fr $(distdir) + diff --git a/autogen-oldtools.sh b/autogen-oldtools.sh new file mode 100755 index 00000000..cbb9522a --- /dev/null +++ b/autogen-oldtools.sh @@ -0,0 +1,45 @@ +#!/bin/bash + +# +# usage: +# +# banner +# +banner() { + + echo + TG=`echo $1 | sed -e "s,/.*/,,g"` + LINE=`echo $TG |sed -e "s/./-/g"` + echo $LINE + echo $TG + echo $LINE + echo +} + + +ACLOCAL=${ACLOCAL:=aclocal} +AUTOHEADER=${AUTOHEADER:=autoheader} +AUTOMAKE=${AUTOMAKE:=automake} +AUTOCONF=${AUTOCONF:=autoconf} + +banner "running libtoolize" +libtoolize --force +[ $? != 0 ] && exit + +banner "running aclocal" +$ACLOCAL -I config/m4 +[ $? != 0 ] && exit + +banner "running autoheader" +$AUTOHEADER +[ $? != 0 ] && exit + +banner "running automake" +$AUTOMAKE --gnu --add-missing -Wall +[ $? != 0 ] && exit + +banner "running autoconf" +$AUTOCONF -Wall +[ $? != 0 ] && exit + +banner "Finished" diff --git a/autogen.sh b/autogen.sh new file mode 100755 index 00000000..29db9c98 --- /dev/null +++ b/autogen.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +# +# usage: +# +# banner +# +banner() { + echo + TG=`echo $1 | sed -e "s,/.*/,,g"` + LINE=`echo $TG |sed -e "s/./-/g"` + echo $LINE + echo $TG + echo $LINE + echo +} + +banner "autoreconf" + +autoreconf --force --install --symlink -Wall || exit $? + +banner "Finished" diff --git a/config/GNUmakefile.am b/config/GNUmakefile.am new file mode 100644 index 00000000..998e3934 --- /dev/null +++ b/config/GNUmakefile.am @@ -0,0 +1,8 @@ +EXTRA_DIST = \ + libsocketcan-nl.pc.in + +pkgconfigdir = $(libdir)/pkgconfig +pkgconfig_DATA = libsocketcan-nl.pc + +MAINTAINERCLEANFILES = \ + GNUmakefile.in diff --git a/config/libsocketcan-nl.pc.in b/config/libsocketcan-nl.pc.in new file mode 100644 index 00000000..a29224aa --- /dev/null +++ b/config/libsocketcan-nl.pc.in @@ -0,0 +1,12 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: libsocketcan-nl +Description: provides access to socketcan netlink interface +Requires: @REQUIRES_LIBRN@ +Version: @VERSION@ +Libs: -L${libdir} -llibsocketcan-nl +#Libs.private: -lm -lpthread ...etc... +Cflags: -I${includedir} diff --git a/config/m4/.secret-world-domination-project b/config/m4/.secret-world-domination-project new file mode 100644 index 00000000..e69de29b diff --git a/config/m4/acx_pthread.m4 b/config/m4/acx_pthread.m4 new file mode 100644 index 00000000..06af8427 --- /dev/null +++ b/config/m4/acx_pthread.m4 @@ -0,0 +1,238 @@ +dnl @synopsis ACX_PTHREAD([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) +dnl +dnl @summary figure out how to build C programs using POSIX threads +dnl +dnl This macro figures out how to build C programs using POSIX threads. +dnl It sets the PTHREAD_LIBS output variable to the threads library and +dnl linker flags, and the PTHREAD_CFLAGS output variable to any special +dnl C compiler flags that are needed. (The user can also force certain +dnl compiler flags/libs to be tested by setting these environment +dnl variables.) +dnl +dnl Also sets PTHREAD_CC to any special C compiler that is needed for +dnl multi-threaded programs (defaults to the value of CC otherwise). +dnl (This is necessary on AIX to use the special cc_r compiler alias.) +dnl +dnl NOTE: You are assumed to not only compile your program with these +dnl flags, but also link it with them as well. e.g. you should link +dnl with $PTHREAD_CC $CFLAGS $PTHREAD_CFLAGS $LDFLAGS ... $PTHREAD_LIBS +dnl $LIBS +dnl +dnl If you are only building threads programs, you may wish to use +dnl these variables in your default LIBS, CFLAGS, and CC: +dnl +dnl LIBS="$PTHREAD_LIBS $LIBS" +dnl CFLAGS="$CFLAGS $PTHREAD_CFLAGS" +dnl CC="$PTHREAD_CC" +dnl +dnl In addition, if the PTHREAD_CREATE_JOINABLE thread-attribute +dnl constant has a nonstandard name, defines PTHREAD_CREATE_JOINABLE to +dnl that name (e.g. PTHREAD_CREATE_UNDETACHED on AIX). +dnl +dnl ACTION-IF-FOUND is a list of shell commands to run if a threads +dnl library is found, and ACTION-IF-NOT-FOUND is a list of commands to +dnl run it if it is not found. If ACTION-IF-FOUND is not specified, the +dnl default action will define HAVE_PTHREAD. +dnl +dnl Please let the authors know if this macro fails on any platform, or +dnl if you have any other suggestions or comments. This macro was based +dnl on work by SGJ on autoconf scripts for FFTW (www.fftw.org) (with +dnl help from M. Frigo), as well as ac_pthread and hb_pthread macros +dnl posted by Alejandro Forero Cuervo to the autoconf macro repository. +dnl We are also grateful for the helpful feedback of numerous users. +dnl +dnl @category InstalledPackages +dnl @author Steven G. Johnson +dnl @version 2005-06-15 +dnl @license GPLWithACException + +AC_DEFUN([ACX_PTHREAD], [ +AC_REQUIRE([AC_CANONICAL_HOST]) +AC_LANG_SAVE +AC_LANG_C +acx_pthread_ok=no + +# We used to check for pthread.h first, but this fails if pthread.h +# requires special compiler flags (e.g. on True64 or Sequent). +# It gets checked for in the link test anyway. + +# First of all, check if the user has set any of the PTHREAD_LIBS, +# etcetera environment variables, and if threads linking works using +# them: +if test x"$PTHREAD_LIBS$PTHREAD_CFLAGS" != x; then + save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS $PTHREAD_CFLAGS" + save_LIBS="$LIBS" + LIBS="$PTHREAD_LIBS $LIBS" + AC_MSG_CHECKING([for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS=$PTHREAD_CFLAGS]) + AC_TRY_LINK_FUNC(pthread_join, acx_pthread_ok=yes) + AC_MSG_RESULT($acx_pthread_ok) + if test x"$acx_pthread_ok" = xno; then + PTHREAD_LIBS="" + PTHREAD_CFLAGS="" + fi + LIBS="$save_LIBS" + CFLAGS="$save_CFLAGS" +fi + +# We must check for the threads library under a number of different +# names; the ordering is very important because some systems +# (e.g. DEC) have both -lpthread and -lpthreads, where one of the +# libraries is broken (non-POSIX). + +# Create a list of thread flags to try. Items starting with a "-" are +# C compiler flags, and other items are library names, except for "none" +# which indicates that we try without any flags at all, and "pthread-config" +# which is a program returning the flags for the Pth emulation library. + +acx_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config" + +# The ordering *is* (sometimes) important. Some notes on the +# individual items follow: + +# pthreads: AIX (must check this before -lpthread) +# none: in case threads are in libc; should be tried before -Kthread and +# other compiler flags to prevent continual compiler warnings +# -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h) +# -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able) +# lthread: LinuxThreads port on FreeBSD (also preferred to -pthread) +# -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads) +# -pthreads: Solaris/gcc +# -mthreads: Mingw32/gcc, Lynx/gcc +# -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it +# doesn't hurt to check since this sometimes defines pthreads too; +# also defines -D_REENTRANT) +# ... -mt is also the pthreads flag for HP/aCC +# pthread: Linux, etcetera +# --thread-safe: KAI C++ +# pthread-config: use pthread-config program (for GNU Pth library) + +case "${host_cpu}-${host_os}" in + *solaris*) + + # On Solaris (at least, for some versions), libc contains stubbed + # (non-functional) versions of the pthreads routines, so link-based + # tests will erroneously succeed. (We need to link with -pthreads/-mt/ + # -lpthread.) (The stubs are missing pthread_cleanup_push, or rather + # a function called by this macro, so we could check for that, but + # who knows whether they'll stub that too in a future libc.) So, + # we'll just look for -pthreads and -lpthread first: + + acx_pthread_flags="-pthreads pthread -mt -pthread $acx_pthread_flags" + ;; +esac + +if test x"$acx_pthread_ok" = xno; then +for flag in $acx_pthread_flags; do + + case $flag in + none) + AC_MSG_CHECKING([whether pthreads work without any flags]) + ;; + + -*) + AC_MSG_CHECKING([whether pthreads work with $flag]) + PTHREAD_CFLAGS="$flag" + ;; + + pthread-config) + AC_CHECK_PROG(acx_pthread_config, pthread-config, yes, no) + if test x"$acx_pthread_config" = xno; then continue; fi + PTHREAD_CFLAGS="`pthread-config --cflags`" + PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`" + ;; + + *) + AC_MSG_CHECKING([for the pthreads library -l$flag]) + PTHREAD_LIBS="-l$flag" + ;; + esac + + save_LIBS="$LIBS" + save_CFLAGS="$CFLAGS" + LIBS="$PTHREAD_LIBS $LIBS" + CFLAGS="$CFLAGS $PTHREAD_CFLAGS" + + # Check for various functions. We must include pthread.h, + # since some functions may be macros. (On the Sequent, we + # need a special flag -Kthread to make this header compile.) + # We check for pthread_join because it is in -lpthread on IRIX + # while pthread_create is in libc. We check for pthread_attr_init + # due to DEC craziness with -lpthreads. We check for + # pthread_cleanup_push because it is one of the few pthread + # functions on Solaris that doesn't have a non-functional libc stub. + # We try pthread_create on general principles. + AC_TRY_LINK([#include ], + [pthread_t th; pthread_join(th, 0); + pthread_attr_init(0); pthread_cleanup_push(0, 0); + pthread_create(0,0,0,0); pthread_cleanup_pop(0); ], + [acx_pthread_ok=yes]) + + LIBS="$save_LIBS" + CFLAGS="$save_CFLAGS" + + AC_MSG_RESULT($acx_pthread_ok) + if test "x$acx_pthread_ok" = xyes; then + break; + fi + + PTHREAD_LIBS="" + PTHREAD_CFLAGS="" +done +fi + +# Various other checks: +if test "x$acx_pthread_ok" = xyes; then + save_LIBS="$LIBS" + LIBS="$PTHREAD_LIBS $LIBS" + save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS $PTHREAD_CFLAGS" + + # Detect AIX lossage: JOINABLE attribute is called UNDETACHED. + AC_MSG_CHECKING([for joinable pthread attribute]) + attr_name=unknown + for attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do + AC_TRY_LINK([#include ], [int attr=$attr; return attr;], + [attr_name=$attr; break]) + done + AC_MSG_RESULT($attr_name) + if test "$attr_name" != PTHREAD_CREATE_JOINABLE; then + AC_DEFINE_UNQUOTED(PTHREAD_CREATE_JOINABLE, $attr_name, + [Define to necessary symbol if this constant + uses a non-standard name on your system.]) + fi + + AC_MSG_CHECKING([if more special flags are required for pthreads]) + flag=no + case "${host_cpu}-${host_os}" in + *-aix* | *-freebsd* | *-darwin*) flag="-D_THREAD_SAFE";; + *solaris* | *-osf* | *-hpux*) flag="-D_REENTRANT";; + esac + AC_MSG_RESULT(${flag}) + if test "x$flag" != xno; then + PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS" + fi + + LIBS="$save_LIBS" + CFLAGS="$save_CFLAGS" + + # More AIX lossage: must compile with cc_r + AC_CHECK_PROG(PTHREAD_CC, cc_r, cc_r, ${CC}) +else + PTHREAD_CC="$CC" +fi + +AC_SUBST(PTHREAD_LIBS) +AC_SUBST(PTHREAD_CFLAGS) +AC_SUBST(PTHREAD_CC) + +# Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND: +if test x"$acx_pthread_ok" = xyes; then + ifelse([$1],,AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.]),[$1]) + : +else + acx_pthread_ok=no + $2 +fi +AC_LANG_RESTORE +])dnl ACX_PTHREAD diff --git a/configure.ac b/configure.ac new file mode 100644 index 00000000..00b290f6 --- /dev/null +++ b/configure.ac @@ -0,0 +1,122 @@ +# -*- Autoconf -*- +# Process this file with autoconf to produce a configure script. +AC_PREREQ(2.59) + +AC_INIT([libsocketcan-nl], [0.0.1], [bugs@pengutronix.de]) +AC_CONFIG_HEADERS([include/libsocketcan-nl_config.h]) +AC_CONFIG_SRCDIR([src/socketcan_netlink.c]) +AC_CONFIG_MACRO_DIR([config/m4]) +AC_CONFIG_AUX_DIR([config/autoconf]) +AC_CANONICAL_BUILD +AC_CANONICAL_HOST + +AM_MAINTAINER_MODE + +CFLAGS="${CFLAGS} -Wall" + +# +# libtool library versioning stuff +# +# Library code modified: REVISION++ +# Interfaces changed/added/removed: CURRENT++ REVISION=0 +# Interfaces added: AGE++ +# Interfaces removed: AGE=0 +LT_CURRENT=0 +LT_REVISION=0 +LT_AGE=0 +AC_SUBST(LT_CURRENT) +AC_SUBST(LT_REVISION) +AC_SUBST(LT_AGE) + + +# +# Checks for programs. +# +AC_PROG_CC +#AM_MISSING_PROG(PERL, perl, $missing_dir) +# libtool, old: +AC_LIBTOOL_WIN32_DLL +#AC_LIBTOOL_TAGS([]) +AC_PROG_LIBTOOL +# libtool, new: +# LT_INIT(win32-dll) + +AM_INIT_AUTOMAKE([foreign no-exeext dist-bzip2]) + + +# +# Checks for libraries. +# + +AC_HEADER_DIRENT +AC_HEADER_STDC +AC_HEADER_SYS_WAIT +AC_CHECK_HEADERS([ \ + arpa/inet.h \ + limits.h \ + netdb.h \ + netinet/in.h \ + stddef.h \ + stdlib.h \ + string.h \ + sys/param.h \ + sys/socket.h \ + sys/time.h \ + sys/un.h \ + unistd.h \ + utime.h \ + net/if.h \ + linux/netlink.h \ + linux/rtnetlink.h \ + ]) + + +# +# Checks for typedefs, structures, and compiler characteristics. +# +AC_C_CONST +AC_C_INLINE +AC_TYPE_SIZE_T +AC_HEADER_TIME + + +# +# Checks for library functions. +# +AC_FUNC_MEMCMP +AC_TYPE_SIGNAL +AC_FUNC_STAT +AC_FUNC_UTIME_NULL +AC_CHECK_FUNCS([gethostbyaddr gethostbyname gethostname gettimeofday memset mkdir socket utime]) + + +# +# Debugging +# +AC_MSG_CHECKING([whether to enable debugging]) +AC_ARG_ENABLE(debug, + AS_HELP_STRING([--enable-debug], [enable debugging @<:@default=yes@:>@]), + [case "$enableval" in + y | yes) CONFIG_DEBUG=yes ;; + *) CONFIG_DEBUG=no ;; + esac], + [CONFIG_DEBUG=yes]) +AC_MSG_RESULT([${CONFIG_DEBUG}]) +if test "${CONFIG_DEBUG}" = "yes"; then + CFLAGS="${CFLAGS} -Werror -Wsign-compare -Wfloat-equal -Wformat-security -g -O1" + AC_DEFINE(DEBUG, 1, [debugging]) +else + CFLAGS="${CFLAGS} -O2" +fi + + +AC_CONFIG_FILES([ + GNUmakefile + config/libsocketcan-nl.pc + config/GNUmakefile + include/GNUmakefile + src/GNUmakefile + tests/GNUmakefile + ]) +AC_OUTPUT + diff --git a/include/GNUmakefile.am b/include/GNUmakefile.am new file mode 100644 index 00000000..c9abcb91 --- /dev/null +++ b/include/GNUmakefile.am @@ -0,0 +1,9 @@ +noinst_HEADERS = \ + libsocketcan-nlstuff.h + +nobase_include_HEADERS = \ + socketcan_netlink.h + +MAINTAINERCLEANFILES = \ + libsocketcan-nl_config.h.in \ + GNUmakefile.in diff --git a/include/can/netlink.h b/include/can/netlink.h new file mode 100644 index 00000000..9ecbb787 --- /dev/null +++ b/include/can/netlink.h @@ -0,0 +1,113 @@ +/* + * linux/can/netlink.h + * + * Definitions for the CAN netlink interface + * + * Copyright (c) 2009 Wolfgang Grandegger + * + * Send feedback to + * + */ + +#ifndef CAN_NETLINK_H +#define CAN_NETLINK_H + +#include + +/* + * CAN bit-timing parameters + * + * For futher information, please read chapter "8 BIT TIMING + * REQUIREMENTS" of the "Bosch CAN Specification version 2.0" + * at http://www.semiconductors.bosch.de/pdf/can2spec.pdf. + */ +struct can_bittiming { + __u32 bitrate; /* Bit-rate in bits/second */ + __u32 sample_point; /* Sample point in one-tenth of a percent */ + __u32 tq; /* Time quanta (TQ) in nanoseconds */ + __u32 prop_seg; /* Propagation segment in TQs */ + __u32 phase_seg1; /* Phase buffer segment 1 in TQs */ + __u32 phase_seg2; /* Phase buffer segment 2 in TQs */ + __u32 sjw; /* Synchronisation jump width in TQs */ + __u32 brp; /* Bit-rate prescaler */ +}; + +/* + * CAN harware-dependent bit-timing constant + * + * Used for calculating and checking bit-timing parameters + */ +struct can_bittiming_const { + char name[16]; /* Name of the CAN controller hardware */ + __u32 tseg1_min; /* Time segement 1 = prop_seg + phase_seg1 */ + __u32 tseg1_max; + __u32 tseg2_min; /* Time segement 2 = phase_seg2 */ + __u32 tseg2_max; + __u32 sjw_max; /* Synchronisation jump width */ + __u32 brp_min; /* Bit-rate prescaler */ + __u32 brp_max; + __u32 brp_inc; +}; + +/* + * CAN clock parameters + */ +struct can_clock { + __u32 freq; /* CAN system clock frequency in Hz */ +}; + +/* + * CAN operational and error states + */ +enum can_state { + CAN_STATE_ERROR_ACTIVE = 0, /* RX/TX error count < 96 */ + CAN_STATE_ERROR_WARNING, /* RX/TX error count < 128 */ + CAN_STATE_ERROR_PASSIVE, /* RX/TX error count < 256 */ + CAN_STATE_BUS_OFF, /* RX/TX error count >= 256 */ + CAN_STATE_STOPPED, /* Device is stopped */ + CAN_STATE_SLEEPING, /* Device is sleeping */ + CAN_STATE_MAX +}; + +/* + * CAN controller mode + */ +struct can_ctrlmode { + __u32 mask; + __u32 flags; +}; + +#define CAN_CTRLMODE_LOOPBACK 0x1 /* Loopback mode */ +#define CAN_CTRLMODE_LISTENONLY 0x2 /* Listen-only mode */ +#define CAN_CTRLMODE_3_SAMPLES 0x4 /* Triple sampling mode */ + +/* + * CAN device statistics + */ +struct can_device_stats { + __u32 bus_error; /* Bus errors */ + __u32 error_warning; /* Changes to error warning state */ + __u32 error_passive; /* Changes to error passive state */ + __u32 bus_off; /* Changes to bus off state */ + __u32 arbitration_lost; /* Arbitration lost errors */ + __u32 restarts; /* CAN controller re-starts */ +}; + +/* + * CAN netlink interface + */ +enum { + IFLA_CAN_UNSPEC, + IFLA_CAN_BITTIMING, + IFLA_CAN_BITTIMING_CONST, + IFLA_CAN_CLOCK, + IFLA_CAN_STATE, + IFLA_CAN_CTRLMODE, + IFLA_CAN_RESTART_MS, + IFLA_CAN_RESTART, + __IFLA_CAN_MAX +}; + +#define IFLA_CAN_MAX (__IFLA_CAN_MAX - 1) + +#endif /* CAN_NETLINK_H */ diff --git a/include/libsocketcan-nl.h b/include/libsocketcan-nl.h new file mode 100644 index 00000000..26ad1e43 --- /dev/null +++ b/include/libsocketcan-nl.h @@ -0,0 +1,5 @@ +#ifndef LIBSOCKETCAN-NL_H +#define LIBSOCKETCAN-NL_H + + +#endif diff --git a/include/libsocketcan-nlstuff.h b/include/libsocketcan-nlstuff.h new file mode 100644 index 00000000..26ad1e43 --- /dev/null +++ b/include/libsocketcan-nlstuff.h @@ -0,0 +1,5 @@ +#ifndef LIBSOCKETCAN-NL_H +#define LIBSOCKETCAN-NL_H + + +#endif diff --git a/include/socketcan_netlink.h b/include/socketcan_netlink.h new file mode 100644 index 00000000..a2bfe5dd --- /dev/null +++ b/include/socketcan_netlink.h @@ -0,0 +1,49 @@ +/* + * Header file for CAN netlink support + * (C) 2009 Luotao Fu + */ + +#ifndef _NMS_H +#define _NMS_H + +#define IFLA_CAN_MAX (__IFLA_CAN_MAX - 1) +#define IF_UP 1 +#define IF_DOWN 2 + +#define GET_STATE 1 +#define GET_RESTART_MS 2 +#define GET_BITTIMING 3 + +struct get_req { + struct nlmsghdr n; + struct rtgenmsg g; +}; + +struct set_req { + struct nlmsghdr n; + struct ifinfomsg i; + char buf[1024]; +}; + +struct req_info { + __u8 restart; + __u8 disable_autorestart; + __u32 restart_ms; + __u32 bitrate; + __u32 ctrlmode; + __u32 flags; +}; + +int if_down(int fd, const char *name); +int if_up(int fd, const char *name); + +int set_link_can(const char *name, struct req_info *req_info); +int set_restart(const char *name); +int set_bitrate(const char *name, __u32 bitrate); +int set_restart_ms(const char *name, __u32 restart_ms); + +int get_state(const char *name); +__u32 get_restart_ms(const char *name); +int get_bittiming(const char *name, struct can_bittiming *bt); + +#endif diff --git a/src/GNUmakefile.am b/src/GNUmakefile.am new file mode 100644 index 00000000..3e0fe38f --- /dev/null +++ b/src/GNUmakefile.am @@ -0,0 +1,17 @@ +lib_LTLIBRARIES = libsocketcan-nl.la + +AM_CPPFLAGS = \ + -I$(top_srcdir)/include \ + -I$(top_builddir)/include + +libsocketcan_nl_la_SOURCES = socketcan_netlink.c + +libsocketcan_nl_la_LDFLAGS = \ + -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) +# -no-undefined # win32_dll stuff only + +#libsocketcan-nl_LDADD = \ +# $(librn_LIBS) +# +MAINTAINERCLEANFILES = \ + GNUmakefile.in diff --git a/src/socketcan_netlink.c b/src/socketcan_netlink.c new file mode 100644 index 00000000..087a604a --- /dev/null +++ b/src/socketcan_netlink.c @@ -0,0 +1,554 @@ +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include + +#define parse_rtattr_nested(tb, max, rta) \ + (parse_rtattr((tb), (max), RTA_DATA(rta), RTA_PAYLOAD(rta))) + +#define NLMSG_TAIL(nmsg) \ + ((struct rtattr *) (((void *) (nmsg)) + NLMSG_ALIGN((nmsg)->nlmsg_len))) + + +static void +parse_rtattr(struct rtattr **tb, int max, struct rtattr *rta, int len) +{ + memset(tb, 0, sizeof(*tb) * max); + while (RTA_OK(rta, len)) { + if (rta->rta_type <= max) { + tb[rta->rta_type] = rta; + } + + rta = RTA_NEXT(rta, len); + } +} + +static int addattr32(struct nlmsghdr *n, size_t maxlen, int type, __u32 data) +{ + int len = RTA_LENGTH(4); + struct rtattr *rta; + + if (NLMSG_ALIGN(n->nlmsg_len) + len > maxlen) { + fprintf(stderr, + "addattr32: Error! max allowed bound %lu exceeded\n", + maxlen); + return -1; + } + + rta = NLMSG_TAIL(n); + rta->rta_type = type; + rta->rta_len = len; + memcpy(RTA_DATA(rta), &data, 4); + n->nlmsg_len = NLMSG_ALIGN(n->nlmsg_len) + len; + + return 0; +} + +static int addattr_l(struct nlmsghdr *n, size_t maxlen, int type, const void *data, + int alen) +{ + int len = RTA_LENGTH(alen); + struct rtattr *rta; + + if (NLMSG_ALIGN(n->nlmsg_len) + RTA_ALIGN(len) > maxlen) { + fprintf(stderr, + "addattr_l ERROR: message exceeded bound of %lu\n", + maxlen); + return -1; + } + + rta = NLMSG_TAIL(n); + rta->rta_type = type; + rta->rta_len = len; + memcpy(RTA_DATA(rta), data, alen); + n->nlmsg_len = NLMSG_ALIGN(n->nlmsg_len) + RTA_ALIGN(len); + + return 0; +} + +static int send_mod_request(int fd, struct nlmsghdr *n) +{ + int status; + struct sockaddr_nl nladdr; + struct nlmsghdr *h; + + struct iovec iov = { + .iov_base = (void *)n, + .iov_len = n->nlmsg_len + }; + struct msghdr msg = { + .msg_name = &nladdr, + .msg_namelen = sizeof(nladdr), + .msg_iov = &iov, + .msg_iovlen = 1, + }; + char buf[16384]; + + memset(&nladdr, 0, sizeof(nladdr)); + + nladdr.nl_family = AF_NETLINK; + nladdr.nl_pid = 0; + nladdr.nl_groups = 0; + + n->nlmsg_seq = 0; + n->nlmsg_flags |= NLM_F_ACK; + + status = sendmsg(fd, &msg, 0); + + if (status < 0) { + perror("Cannot talk to rtnetlink"); + return -1; + } + //printf("stat sent: %d\n", status); + + iov.iov_base = buf; + while (1) { + iov.iov_len = sizeof(buf); + status = recvmsg(fd, &msg, 0); + //printf("stat rcv: %d\n", status); + for (h = (struct nlmsghdr *)buf; + (size_t)status >= sizeof(*h);) { + int len = h->nlmsg_len; + int l = len - sizeof(*h); + //printf("msgtype: %d, len %d, l %d\n", h->nlmsg_type, len, l); + if (l < 0 || len > status) { + if (msg.msg_flags & MSG_TRUNC) { + fprintf(stderr, "Truncated message\n"); + return -1; + } + fprintf(stderr, + "!!!malformed message: len=%d\n", len); + return -1; + } + + if (h->nlmsg_type == NLMSG_ERROR) { + struct nlmsgerr *err = + (struct nlmsgerr *)NLMSG_DATA(h); + if ((size_t)l < sizeof(struct nlmsgerr)) { + fprintf(stderr, "ERROR truncated\n"); + } else { + errno = -err->error; + if (errno == 0) + return 0; + + perror("RTNETLINK answers"); + } + return -1; + } + status -= NLMSG_ALIGN(len); + h = (struct nlmsghdr *)((char *)h + NLMSG_ALIGN(len)); + } + } + + return 0; +} + +static int send_dump_request(int fd, int family, int type) +{ + struct get_req req; + + memset(&req, 0, sizeof(req)); + + req.n.nlmsg_len = sizeof(req); + req.n.nlmsg_type = type; + req.n.nlmsg_flags = NLM_F_REQUEST | NLM_F_ROOT | NLM_F_MATCH; + req.n.nlmsg_pid = 0; + req.n.nlmsg_seq = 0; + + req.g.rtgen_family = family; + + return send(fd, (void *)&req, sizeof(req), 0); +} + +static int open_nl_sock() +{ + int fd; + int sndbuf = 32768; + int rcvbuf = 32768; + unsigned int addr_len; + struct sockaddr_nl local; + + fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE); + if (fd < 0) { + perror("Cannot open netlink socket"); + return -1; + } + + setsockopt(fd, SOL_SOCKET, SO_SNDBUF, (void *)&sndbuf, sizeof(sndbuf)); + + setsockopt(fd, SOL_SOCKET, SO_RCVBUF, (void *)&rcvbuf, sizeof(rcvbuf)); + + memset(&local, 0, sizeof(local)); + local.nl_family = AF_NETLINK; + local.nl_groups = 0; + + if (bind(fd, (struct sockaddr *)&local, sizeof(local)) < 0) { + perror("Cannot bind netlink socket"); + return -1; + } + + addr_len = sizeof(local); + if (getsockname(fd, (struct sockaddr *)&local, &addr_len) < 0) { + perror("Cannot getsockname"); + return -1; + } + if (addr_len != sizeof(local)) { + fprintf(stderr, "Wrong address length %d\n", addr_len); + return -1; + } + if (local.nl_family != AF_NETLINK) { + fprintf(stderr, "Wrong address family %d\n", local.nl_family); + return -1; + } + return fd; +} + +static int do_get_nl_link(int fd, __u8 acquire, const char *name, void *res) +{ + struct sockaddr_nl peer; + + char cbuf[64]; + char nlbuf[1024 * 8]; + + int ret = -1; + + struct iovec iov = { + .iov_base = (void *)nlbuf, + .iov_len = sizeof(nlbuf), + }; + + struct msghdr msg = { + .msg_name = (void *)&peer, + .msg_namelen = sizeof(peer), + .msg_iov = &iov, + .msg_iovlen = 1, + .msg_control = &cbuf, + .msg_controllen = sizeof(cbuf), + .msg_flags = 0, + }; + struct nlmsghdr *nl_msg; + ssize_t msglen; + + struct rtattr *linkinfo[IFLA_INFO_MAX + 1]; + struct rtattr *can_attr[IFLA_CAN_MAX + 1]; + + if (send_dump_request(fd, AF_PACKET, RTM_GETLINK) < 0) { + perror("Cannot send dump request"); + return ret; + } + + if ((msglen = recvmsg(fd, &msg, 0)) <= 0) { + perror("Receive error"); + return ret; + } + size_t u_msglen = (size_t)msglen; + /* Check to see if the buffers in msg get truncated */ + if (msg.msg_namelen != sizeof(peer) || + (msg.msg_flags & (MSG_TRUNC | MSG_CTRUNC))) { + fprintf(stderr, "Uhoh... truncated message.\n"); + return ret; + } + + for (nl_msg = (struct nlmsghdr *)nlbuf; + NLMSG_OK(nl_msg, u_msglen); nl_msg = NLMSG_NEXT(nl_msg, u_msglen)) { + int type = nl_msg->nlmsg_type; + int len; + if (type != RTM_NEWLINK) + continue; + + struct ifinfomsg *ifi = NLMSG_DATA(nl_msg); + struct rtattr *tb[IFLA_MAX + 1]; + + len = + nl_msg->nlmsg_len - NLMSG_LENGTH(sizeof(struct ifaddrmsg)); + parse_rtattr(tb, IFLA_MAX, IFLA_RTA(ifi), len); + + if (strncmp((char *)RTA_DATA(tb[IFLA_IFNAME]), name, 4) != 0) + continue; + + if (tb[IFLA_LINKINFO]) + parse_rtattr_nested(linkinfo, + IFLA_INFO_MAX, tb[IFLA_LINKINFO]); + else + continue; + + if (!linkinfo[IFLA_INFO_DATA]) { + fprintf(stderr, "no link data found\n"); + return ret; + } + + parse_rtattr_nested(can_attr, IFLA_CAN_MAX, + linkinfo[IFLA_INFO_DATA]); + + switch (acquire) { + case GET_STATE: + if (can_attr[IFLA_CAN_STATE]) { + *((int *)res) = + *((__u32 *) + RTA_DATA(can_attr[IFLA_CAN_STATE])); + ret = 0; + } else { + fprintf(stderr, "no state data found\n"); + } + + break; + case GET_RESTART_MS: + if (can_attr[IFLA_CAN_RESTART_MS]) { + *((__u32 *) res) = + *((__u32 *) + RTA_DATA(can_attr[IFLA_CAN_RESTART_MS])); + ret = 0; + } else + fprintf(stderr, "no restart_ms data found\n"); + + break; + case GET_BITTIMING: + if (can_attr[IFLA_CAN_BITTIMING]) { + memcpy(res, RTA_DATA(can_attr[IFLA_CAN_BITTIMING]), + sizeof(struct can_bittiming)); + ret = 0; + } else + fprintf(stderr, "no bittiming data found\n"); + + break; + default: + fprintf(stderr, "unknown acquire mode\n"); + } + } + return ret; +} + +static int do_set_nl_link(int fd, __u8 if_state, const char* name, struct req_info *req_info) +{ + struct set_req req; + + struct can_bittiming bt; + struct can_ctrlmode cm; + + const char* type="can"; + + memset(&req, 0, sizeof(req)); + + req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg)); + req.n.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK; + req.n.nlmsg_type = RTM_NEWLINK; + req.i.ifi_family = 0; + + req.i.ifi_index = if_nametoindex(name); + if (req.i.ifi_index == 0) { + fprintf(stderr, "Cannot find device \"%s\"\n", name); + return -1; + } + + if (if_state) { + switch (if_state) { + case IF_DOWN: + req.i.ifi_change |= IFF_UP; + req.i.ifi_flags &= ~IFF_UP; + break; + case IF_UP: + req.i.ifi_change |= IFF_UP; + req.i.ifi_flags |= IFF_UP; + break; + default: + fprintf(stderr, "unknown state\n"); + return -1; + } + } + + if (req_info != NULL) { + /* setup linkinfo section */ + struct rtattr *linkinfo = NLMSG_TAIL(&req.n); + addattr_l(&req.n, sizeof(req), IFLA_LINKINFO, NULL, 0); + addattr_l(&req.n, sizeof(req), IFLA_INFO_KIND, type, + strlen(type)); + /* setup data section */ + struct rtattr *data = NLMSG_TAIL(&req.n); + addattr_l(&req.n, sizeof(req), IFLA_INFO_DATA, NULL, 0); + + if (req_info->restart_ms > 0 || req_info->disable_autorestart) + addattr32(&req.n, 1024, IFLA_CAN_RESTART_MS, + req_info->restart_ms); + + if (req_info->bitrate > 0) { + memset(&bt, 0, sizeof(bt)); + bt.bitrate = req_info->bitrate; + addattr_l(&req.n, 1024, IFLA_CAN_BITTIMING, + &bt, sizeof(bt)); + } + + if (req_info->restart) + addattr32(&req.n, 1024, IFLA_CAN_RESTART, 1); + + if (req_info->ctrlmode) { + memset(&cm, 0, sizeof(cm)); + cm.mask = req_info->ctrlmode; + cm.flags = req_info->flags; + addattr_l(&req.n, 1024, IFLA_CAN_CTRLMODE, &cm, sizeof(cm)); + } + + /* mark end of data section */ + data->rta_len = (void *)NLMSG_TAIL(&req.n) - (void *)data; + + /* mark end of link info section */ + linkinfo->rta_len = + (void *)NLMSG_TAIL(&req.n) - (void *)linkinfo; + } + + return send_mod_request(fd, &req.n); +} + +static int set_link(const char *name, struct req_info *req_info) +{ + int fd; + int err = 0; + + fd = open_nl_sock(); + if (fd < 0) + goto err_out; + + err = if_down(fd, name); + if (err < 0) + goto close_out; + + err = do_set_nl_link(fd, 0, name, req_info); + if (err < 0) + goto close_out; + + err = if_up(fd, name); + if (err < 0) + goto close_out; + +close_out: + close(fd); +err_out: + return err; +} + +int if_up(int fd, const char *name) +{ + return do_set_nl_link(fd, IF_UP, name, NULL); +} + +int if_down(int fd, const char *name) +{ + return do_set_nl_link(fd, IF_DOWN, name, NULL); +} + +int set_bitrate(const char *name, __u32 bitrate) +{ + struct req_info req_info = { + .bitrate = bitrate, + }; + + return set_link(name, &req_info); +} + +int set_restart(const char *name) +{ + int fd; + int err = -1; + int state; + + state = get_state(name); + + if (state != CAN_STATE_BUS_OFF) { + fprintf(stderr, + "Device %s is not in BUS_OFF," + " no use to restart it\n", + name); + err = 0; + goto err_out; + } + + struct req_info req_info = { + .restart = 1, + }; + + fd = open_nl_sock(); + if (fd < 0) + goto err_out; + + err = do_set_nl_link(fd, 0, name, &req_info); + if (err < 0) + goto close_out; + +close_out: + close(fd); +err_out: + return err; +} + +int set_restart_ms(const char *name, __u32 restart_ms) +{ + struct req_info req_info = { + .restart_ms = restart_ms, + }; + + if (restart_ms == 0) + req_info.disable_autorestart = 1; + + return set_link(name, &req_info); +} + +int get_state(const char *name) +{ + int fd; + int state; + int err; + + fd = open_nl_sock(); + if (fd < 0) + return -1; + + err = do_get_nl_link(fd, GET_STATE, name, &state); + if (err < 0) + return -1; + + return state; +} + +__u32 get_restart_ms(const char *name) +{ + int fd; + int err; + __u32 restart_ms; + + fd = open_nl_sock(); + if (fd < 0) + return -1; + + err = do_get_nl_link(fd, GET_RESTART_MS, name, &restart_ms); + if (err < 0) + return -1; + + close(fd); + return restart_ms; + +} + +int get_bittiming(const char *name, struct can_bittiming *bt) +{ + int fd; + int err; + + fd = open_nl_sock(); + if (fd < 0) + return -1; + + err = do_get_nl_link(fd, GET_BITTIMING, name, bt); + if (err < 0) + return -1; + + close(fd); + return 0; +} diff --git a/tests/GNUmakefile.am b/tests/GNUmakefile.am new file mode 100644 index 00000000..6e52c67d --- /dev/null +++ b/tests/GNUmakefile.am @@ -0,0 +1,17 @@ +TESTS = \ + test + +noinst_PROGRAMS = \ + test + +test_SOURCES = \ + test.c +test_LDADD = \ + $(top_builddir)/src/libsocketcan-nl.la + +AM_CPPFLAGS = \ + -I$(top_srcdir)/include \ + -I$(top_builddir)/include + +MAINTAINERCLEANFILES = \ + GNUmakefile.in diff --git a/tests/test.c b/tests/test.c new file mode 100644 index 00000000..ad562a28 --- /dev/null +++ b/tests/test.c @@ -0,0 +1,7 @@ +#include + +int main(void) +{ + printf("hallo\n"); + return 0; +} From 529838a56d790002d9720c7bc45e355f763f9d59 Mon Sep 17 00:00:00 2001 From: Luotao Fu Date: Fri, 20 Nov 2009 16:31:11 +0100 Subject: [PATCH 02/88] fix header checking, add dist header Signed-off-by: Luotao Fu --- configure.ac | 4 ++-- include/GNUmakefile.am | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index 00b290f6..7e7c2a5c 100644 --- a/configure.ac +++ b/configure.ac @@ -66,8 +66,8 @@ AC_CHECK_HEADERS([ \ unistd.h \ utime.h \ net/if.h \ - linux/netlink.h \ - linux/rtnetlink.h \ + linux/netlink.h,,,[linux/socket.h] \ + linux/rtnetlink.h,,,[linux/socket.h] \ ]) diff --git a/include/GNUmakefile.am b/include/GNUmakefile.am index c9abcb91..d977b8d5 100644 --- a/include/GNUmakefile.am +++ b/include/GNUmakefile.am @@ -2,7 +2,8 @@ noinst_HEADERS = \ libsocketcan-nlstuff.h nobase_include_HEADERS = \ - socketcan_netlink.h + socketcan_netlink.h \ + can/netlink.h MAINTAINERCLEANFILES = \ libsocketcan-nl_config.h.in \ From 64c23c603cbbdc3d1e63d030cdd4bb1bf639bd57 Mon Sep 17 00:00:00 2001 From: Luotao Fu Date: Fri, 20 Nov 2009 16:59:04 +0100 Subject: [PATCH 03/88] rename set_link and switch to static. remove internally used structs from header Signed-off-by: Luotao Fu --- include/socketcan_netlink.h | 21 --------------------- src/socketcan_netlink.c | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/include/socketcan_netlink.h b/include/socketcan_netlink.h index a2bfe5dd..e324bbb6 100644 --- a/include/socketcan_netlink.h +++ b/include/socketcan_netlink.h @@ -14,30 +14,9 @@ #define GET_RESTART_MS 2 #define GET_BITTIMING 3 -struct get_req { - struct nlmsghdr n; - struct rtgenmsg g; -}; - -struct set_req { - struct nlmsghdr n; - struct ifinfomsg i; - char buf[1024]; -}; - -struct req_info { - __u8 restart; - __u8 disable_autorestart; - __u32 restart_ms; - __u32 bitrate; - __u32 ctrlmode; - __u32 flags; -}; - int if_down(int fd, const char *name); int if_up(int fd, const char *name); -int set_link_can(const char *name, struct req_info *req_info); int set_restart(const char *name); int set_bitrate(const char *name, __u32 bitrate); int set_restart_ms(const char *name, __u32 restart_ms); diff --git a/src/socketcan_netlink.c b/src/socketcan_netlink.c index 087a604a..404e10e0 100644 --- a/src/socketcan_netlink.c +++ b/src/socketcan_netlink.c @@ -18,6 +18,25 @@ #define NLMSG_TAIL(nmsg) \ ((struct rtattr *) (((void *) (nmsg)) + NLMSG_ALIGN((nmsg)->nlmsg_len))) +struct get_req { + struct nlmsghdr n; + struct rtgenmsg g; +}; + +struct set_req { + struct nlmsghdr n; + struct ifinfomsg i; + char buf[1024]; +}; + +struct req_info { + __u8 restart; + __u8 disable_autorestart; + __u32 restart_ms; + __u32 bitrate; + __u32 ctrlmode; + __u32 flags; +}; static void parse_rtattr(struct rtattr **tb, int max, struct rtattr *rta, int len) From 0e3319df9827ee05cec747d19138aa7c862fddc2 Mon Sep 17 00:00:00 2001 From: Luotao Fu Date: Mon, 23 Nov 2009 09:05:40 +0100 Subject: [PATCH 04/88] update copyright, remove obsolete prints Signed-off-by: Luotao Fu --- include/socketcan_netlink.h | 23 +++++++++++++++++++---- src/socketcan_netlink.c | 22 +++++++++++++++++++--- 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/include/socketcan_netlink.h b/include/socketcan_netlink.h index e324bbb6..fe6256b9 100644 --- a/include/socketcan_netlink.h +++ b/include/socketcan_netlink.h @@ -1,10 +1,25 @@ -/* - * Header file for CAN netlink support +/* + * socketcan_netlink.h + * * (C) 2009 Luotao Fu + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the version 2 of the GNU General Public License + * as published by the Free Software Foundation + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef _NMS_H -#define _NMS_H + +#ifndef _SOCKETCAN_NETLINK_H +#define _SOCKETCAN_NETLINK_H #define IFLA_CAN_MAX (__IFLA_CAN_MAX - 1) #define IF_UP 1 diff --git a/src/socketcan_netlink.c b/src/socketcan_netlink.c index 404e10e0..078afc3c 100644 --- a/src/socketcan_netlink.c +++ b/src/socketcan_netlink.c @@ -1,3 +1,22 @@ +/* + * socketcan_netlink.c + * + * (C) 2009 Luotao Fu + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the version 2 of the GNU General Public License + * as published by the Free Software Foundation + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + #include #include #include @@ -127,18 +146,15 @@ static int send_mod_request(int fd, struct nlmsghdr *n) perror("Cannot talk to rtnetlink"); return -1; } - //printf("stat sent: %d\n", status); iov.iov_base = buf; while (1) { iov.iov_len = sizeof(buf); status = recvmsg(fd, &msg, 0); - //printf("stat rcv: %d\n", status); for (h = (struct nlmsghdr *)buf; (size_t)status >= sizeof(*h);) { int len = h->nlmsg_len; int l = len - sizeof(*h); - //printf("msgtype: %d, len %d, l %d\n", h->nlmsg_type, len, l); if (l < 0 || len > status) { if (msg.msg_flags & MSG_TRUNC) { fprintf(stderr, "Truncated message\n"); From 8c25d8d4b08374cddd137f6c89821a6238b8f671 Mon Sep 17 00:00:00 2001 From: Luotao Fu Date: Mon, 23 Nov 2009 09:06:52 +0100 Subject: [PATCH 05/88] Lindent Signed-off-by: Luotao Fu --- src/socketcan_netlink.c | 46 +++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/src/socketcan_netlink.c b/src/socketcan_netlink.c index 078afc3c..ff889811 100644 --- a/src/socketcan_netlink.c +++ b/src/socketcan_netlink.c @@ -91,8 +91,8 @@ static int addattr32(struct nlmsghdr *n, size_t maxlen, int type, __u32 data) return 0; } -static int addattr_l(struct nlmsghdr *n, size_t maxlen, int type, const void *data, - int alen) +static int addattr_l(struct nlmsghdr *n, size_t maxlen, int type, + const void *data, int alen) { int len = RTA_LENGTH(alen); struct rtattr *rta; @@ -151,8 +151,7 @@ static int send_mod_request(int fd, struct nlmsghdr *n) while (1) { iov.iov_len = sizeof(buf); status = recvmsg(fd, &msg, 0); - for (h = (struct nlmsghdr *)buf; - (size_t)status >= sizeof(*h);) { + for (h = (struct nlmsghdr *)buf; (size_t) status >= sizeof(*h);) { int len = h->nlmsg_len; int l = len - sizeof(*h); if (l < 0 || len > status) { @@ -168,7 +167,7 @@ static int send_mod_request(int fd, struct nlmsghdr *n) if (h->nlmsg_type == NLMSG_ERROR) { struct nlmsgerr *err = (struct nlmsgerr *)NLMSG_DATA(h); - if ((size_t)l < sizeof(struct nlmsgerr)) { + if ((size_t) l < sizeof(struct nlmsgerr)) { fprintf(stderr, "ERROR truncated\n"); } else { errno = -err->error; @@ -285,7 +284,7 @@ static int do_get_nl_link(int fd, __u8 acquire, const char *name, void *res) perror("Receive error"); return ret; } - size_t u_msglen = (size_t)msglen; + size_t u_msglen = (size_t) msglen; /* Check to see if the buffers in msg get truncated */ if (msg.msg_namelen != sizeof(peer) || (msg.msg_flags & (MSG_TRUNC | MSG_CTRUNC))) { @@ -294,7 +293,8 @@ static int do_get_nl_link(int fd, __u8 acquire, const char *name, void *res) } for (nl_msg = (struct nlmsghdr *)nlbuf; - NLMSG_OK(nl_msg, u_msglen); nl_msg = NLMSG_NEXT(nl_msg, u_msglen)) { + NLMSG_OK(nl_msg, u_msglen); + nl_msg = NLMSG_NEXT(nl_msg, u_msglen)) { int type = nl_msg->nlmsg_type; int len; if (type != RTM_NEWLINK) @@ -327,9 +327,9 @@ static int do_get_nl_link(int fd, __u8 acquire, const char *name, void *res) switch (acquire) { case GET_STATE: if (can_attr[IFLA_CAN_STATE]) { - *((int *)res) = - *((__u32 *) - RTA_DATA(can_attr[IFLA_CAN_STATE])); + *((int *)res) = *((__u32 *) + RTA_DATA(can_attr + [IFLA_CAN_STATE])); ret = 0; } else { fprintf(stderr, "no state data found\n"); @@ -338,9 +338,9 @@ static int do_get_nl_link(int fd, __u8 acquire, const char *name, void *res) break; case GET_RESTART_MS: if (can_attr[IFLA_CAN_RESTART_MS]) { - *((__u32 *) res) = - *((__u32 *) - RTA_DATA(can_attr[IFLA_CAN_RESTART_MS])); + *((__u32 *) res) = *((__u32 *) + RTA_DATA(can_attr + [IFLA_CAN_RESTART_MS])); ret = 0; } else fprintf(stderr, "no restart_ms data found\n"); @@ -348,7 +348,8 @@ static int do_get_nl_link(int fd, __u8 acquire, const char *name, void *res) break; case GET_BITTIMING: if (can_attr[IFLA_CAN_BITTIMING]) { - memcpy(res, RTA_DATA(can_attr[IFLA_CAN_BITTIMING]), + memcpy(res, + RTA_DATA(can_attr[IFLA_CAN_BITTIMING]), sizeof(struct can_bittiming)); ret = 0; } else @@ -362,14 +363,15 @@ static int do_get_nl_link(int fd, __u8 acquire, const char *name, void *res) return ret; } -static int do_set_nl_link(int fd, __u8 if_state, const char* name, struct req_info *req_info) +static int do_set_nl_link(int fd, __u8 if_state, const char *name, + struct req_info *req_info) { struct set_req req; struct can_bittiming bt; - struct can_ctrlmode cm; + struct can_ctrlmode cm; - const char* type="can"; + const char *type = "can"; memset(&req, 0, sizeof(req)); @@ -428,7 +430,8 @@ static int do_set_nl_link(int fd, __u8 if_state, const char* name, struct req_in memset(&cm, 0, sizeof(cm)); cm.mask = req_info->ctrlmode; cm.flags = req_info->flags; - addattr_l(&req.n, 1024, IFLA_CAN_CTRLMODE, &cm, sizeof(cm)); + addattr_l(&req.n, 1024, IFLA_CAN_CTRLMODE, &cm, + sizeof(cm)); } /* mark end of data section */ @@ -447,7 +450,7 @@ static int set_link(const char *name, struct req_info *req_info) int fd; int err = 0; - fd = open_nl_sock(); + fd = open_nl_sock(); if (fd < 0) goto err_out; @@ -499,8 +502,7 @@ int set_restart(const char *name) if (state != CAN_STATE_BUS_OFF) { fprintf(stderr, "Device %s is not in BUS_OFF," - " no use to restart it\n", - name); + " no use to restart it\n", name); err = 0; goto err_out; } @@ -509,7 +511,7 @@ int set_restart(const char *name) .restart = 1, }; - fd = open_nl_sock(); + fd = open_nl_sock(); if (fd < 0) goto err_out; From 9b332909b360a1f1fd1d45292d5c7d7b4ff91cdc Mon Sep 17 00:00:00 2001 From: Luotao Fu Date: Mon, 23 Nov 2009 10:56:54 +0100 Subject: [PATCH 06/88] add get/set raw ctrlmode callbacks Signed-off-by: Luotao Fu --- include/socketcan_netlink.h | 3 +++ src/socketcan_netlink.c | 50 +++++++++++++++++++++++++++++-------- 2 files changed, 42 insertions(+), 11 deletions(-) diff --git a/include/socketcan_netlink.h b/include/socketcan_netlink.h index fe6256b9..6b3b2ccd 100644 --- a/include/socketcan_netlink.h +++ b/include/socketcan_netlink.h @@ -28,6 +28,7 @@ #define GET_STATE 1 #define GET_RESTART_MS 2 #define GET_BITTIMING 3 +#define GET_CTRLMODE 4 int if_down(int fd, const char *name); int if_up(int fd, const char *name); @@ -35,9 +36,11 @@ int if_up(int fd, const char *name); int set_restart(const char *name); int set_bitrate(const char *name, __u32 bitrate); int set_restart_ms(const char *name, __u32 restart_ms); +int set_ctrlmode(const char *name, __u32 mode, __u32 flags); int get_state(const char *name); __u32 get_restart_ms(const char *name); int get_bittiming(const char *name, struct can_bittiming *bt); +int get_ctrlmode(const char *name, struct can_ctrlmode *cm); #endif diff --git a/src/socketcan_netlink.c b/src/socketcan_netlink.c index ff889811..d9760dd3 100644 --- a/src/socketcan_netlink.c +++ b/src/socketcan_netlink.c @@ -54,7 +54,7 @@ struct req_info { __u32 restart_ms; __u32 bitrate; __u32 ctrlmode; - __u32 flags; + __u32 ctrlflags; }; static void @@ -355,6 +355,16 @@ static int do_get_nl_link(int fd, __u8 acquire, const char *name, void *res) } else fprintf(stderr, "no bittiming data found\n"); + break; + case GET_CTRLMODE: + if (can_attr[IFLA_CAN_CTRLMODE]) { + memcpy(res, + RTA_DATA(can_attr[IFLA_CAN_CTRLMODE]), + sizeof(struct can_ctrlmode)); + ret = 0; + } else + fprintf(stderr, "no ctrlmode data found\n"); + break; default: fprintf(stderr, "unknown acquire mode\n"); @@ -429,7 +439,7 @@ static int do_set_nl_link(int fd, __u8 if_state, const char *name, if (req_info->ctrlmode) { memset(&cm, 0, sizeof(cm)); cm.mask = req_info->ctrlmode; - cm.flags = req_info->flags; + cm.flags = req_info->ctrlflags; addattr_l(&req.n, 1024, IFLA_CAN_CTRLMODE, &cm, sizeof(cm)); } @@ -482,15 +492,6 @@ int if_down(int fd, const char *name) return do_set_nl_link(fd, IF_DOWN, name, NULL); } -int set_bitrate(const char *name, __u32 bitrate) -{ - struct req_info req_info = { - .bitrate = bitrate, - }; - - return set_link(name, &req_info); -} - int set_restart(const char *name) { int fd; @@ -537,6 +538,16 @@ int set_restart_ms(const char *name, __u32 restart_ms) return set_link(name, &req_info); } +int set_ctrlmode(const char *name, __u32 mode, __u32 flags) +{ + struct req_info req_info = { + .ctrlmode = mode, + .ctrlflags = flags, + }; + + return set_link(name, &req_info); +} + int get_state(const char *name) { int fd; @@ -589,3 +600,20 @@ int get_bittiming(const char *name, struct can_bittiming *bt) close(fd); return 0; } + +int get_ctrlmode(const char *name, struct can_ctrlmode *cm) +{ + int fd; + int err; + + fd = open_nl_sock(); + if (fd < 0) + return -1; + + err = do_get_nl_link(fd, GET_CTRLMODE, name, cm); + if (err < 0) + return -1; + + close(fd); + return 0; +} From 12a155aa20d91e2dc8aa7aff04e6fec593b3b1b9 Mon Sep 17 00:00:00 2001 From: Luotao Fu Date: Mon, 23 Nov 2009 11:03:09 +0100 Subject: [PATCH 07/88] rename API functions Signed-off-by: Luotao Fu --- include/socketcan_netlink.h | 24 ++++++++++++------------ src/socketcan_netlink.c | 24 ++++++++++++------------ 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/include/socketcan_netlink.h b/include/socketcan_netlink.h index 6b3b2ccd..19fd4df4 100644 --- a/include/socketcan_netlink.h +++ b/include/socketcan_netlink.h @@ -30,17 +30,17 @@ #define GET_BITTIMING 3 #define GET_CTRLMODE 4 -int if_down(int fd, const char *name); -int if_up(int fd, const char *name); - -int set_restart(const char *name); -int set_bitrate(const char *name, __u32 bitrate); -int set_restart_ms(const char *name, __u32 restart_ms); -int set_ctrlmode(const char *name, __u32 mode, __u32 flags); - -int get_state(const char *name); -__u32 get_restart_ms(const char *name); -int get_bittiming(const char *name, struct can_bittiming *bt); -int get_ctrlmode(const char *name, struct can_ctrlmode *cm); +int netif_down(int fd, const char *name); +int netif_up(int fd, const char *name); + +int scan_set_restart(const char *name); +int scan_set_bitrate(const char *name, __u32 bitrate); +int scan_set_restart_ms(const char *name, __u32 restart_ms); +int scan_set_ctrlmode(const char *name, __u32 mode, __u32 flags); + +int scan_get_state(const char *name); +__u32 scan_get_restart_ms(const char *name); +int scan_get_bittiming(const char *name, struct can_bittiming *bt); +int scan_get_ctrlmode(const char *name, struct can_ctrlmode *cm); #endif diff --git a/src/socketcan_netlink.c b/src/socketcan_netlink.c index d9760dd3..b491a918 100644 --- a/src/socketcan_netlink.c +++ b/src/socketcan_netlink.c @@ -464,7 +464,7 @@ static int set_link(const char *name, struct req_info *req_info) if (fd < 0) goto err_out; - err = if_down(fd, name); + err = netif_down(fd, name); if (err < 0) goto close_out; @@ -472,7 +472,7 @@ static int set_link(const char *name, struct req_info *req_info) if (err < 0) goto close_out; - err = if_up(fd, name); + err = netif_up(fd, name); if (err < 0) goto close_out; @@ -482,23 +482,23 @@ static int set_link(const char *name, struct req_info *req_info) return err; } -int if_up(int fd, const char *name) +int netif_up(int fd, const char *name) { return do_set_nl_link(fd, IF_UP, name, NULL); } -int if_down(int fd, const char *name) +int netif_down(int fd, const char *name) { return do_set_nl_link(fd, IF_DOWN, name, NULL); } -int set_restart(const char *name) +int scan_set_restart(const char *name) { int fd; int err = -1; int state; - state = get_state(name); + state = scan_get_state(name); if (state != CAN_STATE_BUS_OFF) { fprintf(stderr, @@ -526,7 +526,7 @@ int set_restart(const char *name) return err; } -int set_restart_ms(const char *name, __u32 restart_ms) +int scan_set_restart_ms(const char *name, __u32 restart_ms) { struct req_info req_info = { .restart_ms = restart_ms, @@ -538,7 +538,7 @@ int set_restart_ms(const char *name, __u32 restart_ms) return set_link(name, &req_info); } -int set_ctrlmode(const char *name, __u32 mode, __u32 flags) +int scan_set_ctrlmode(const char *name, __u32 mode, __u32 flags) { struct req_info req_info = { .ctrlmode = mode, @@ -548,7 +548,7 @@ int set_ctrlmode(const char *name, __u32 mode, __u32 flags) return set_link(name, &req_info); } -int get_state(const char *name) +int scan_get_state(const char *name) { int fd; int state; @@ -565,7 +565,7 @@ int get_state(const char *name) return state; } -__u32 get_restart_ms(const char *name) +__u32 scan_get_restart_ms(const char *name) { int fd; int err; @@ -584,7 +584,7 @@ __u32 get_restart_ms(const char *name) } -int get_bittiming(const char *name, struct can_bittiming *bt) +int scan_get_bittiming(const char *name, struct can_bittiming *bt) { int fd; int err; @@ -601,7 +601,7 @@ int get_bittiming(const char *name, struct can_bittiming *bt) return 0; } -int get_ctrlmode(const char *name, struct can_ctrlmode *cm) +int scan_get_ctrlmode(const char *name, struct can_ctrlmode *cm) { int fd; int err; From 9c5c1090d1c79e8c1717c976020a9c2717632661 Mon Sep 17 00:00:00 2001 From: Luotao Fu Date: Mon, 23 Nov 2009 11:11:37 +0100 Subject: [PATCH 08/88] change fixed char size in strncmp Signed-off-by: Luotao Fu --- src/socketcan_netlink.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/socketcan_netlink.c b/src/socketcan_netlink.c index b491a918..2ff5fd01 100644 --- a/src/socketcan_netlink.c +++ b/src/socketcan_netlink.c @@ -307,7 +307,7 @@ static int do_get_nl_link(int fd, __u8 acquire, const char *name, void *res) nl_msg->nlmsg_len - NLMSG_LENGTH(sizeof(struct ifaddrmsg)); parse_rtattr(tb, IFLA_MAX, IFLA_RTA(ifi), len); - if (strncmp((char *)RTA_DATA(tb[IFLA_IFNAME]), name, 4) != 0) + if (strncmp((char *)RTA_DATA(tb[IFLA_IFNAME]), name, sizeof(name)) != 0) continue; if (tb[IFLA_LINKINFO]) From 0c3e5a710b1e07caa79916117262ed7d83f96387 Mon Sep 17 00:00:00 2001 From: Luotao Fu Date: Mon, 23 Nov 2009 12:35:08 +0100 Subject: [PATCH 09/88] fix printf format Signed-off-by: Luotao Fu --- src/socketcan_netlink.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/socketcan_netlink.c b/src/socketcan_netlink.c index 2ff5fd01..693d3239 100644 --- a/src/socketcan_netlink.c +++ b/src/socketcan_netlink.c @@ -77,7 +77,7 @@ static int addattr32(struct nlmsghdr *n, size_t maxlen, int type, __u32 data) if (NLMSG_ALIGN(n->nlmsg_len) + len > maxlen) { fprintf(stderr, - "addattr32: Error! max allowed bound %lu exceeded\n", + "addattr32: Error! max allowed bound %zu exceeded\n", maxlen); return -1; } @@ -99,7 +99,7 @@ static int addattr_l(struct nlmsghdr *n, size_t maxlen, int type, if (NLMSG_ALIGN(n->nlmsg_len) + RTA_ALIGN(len) > maxlen) { fprintf(stderr, - "addattr_l ERROR: message exceeded bound of %lu\n", + "addattr_l ERROR: message exceeded bound of %zu\n", maxlen); return -1; } From dc908807df4ace3a3b3e7b7be2ab854cafdd2fa3 Mon Sep 17 00:00:00 2001 From: Luotao Fu Date: Mon, 23 Nov 2009 12:35:31 +0100 Subject: [PATCH 10/88] fix noinst header Signed-off-by: Luotao Fu --- include/GNUmakefile.am | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/GNUmakefile.am b/include/GNUmakefile.am index d977b8d5..daae417a 100644 --- a/include/GNUmakefile.am +++ b/include/GNUmakefile.am @@ -1,9 +1,9 @@ noinst_HEADERS = \ - libsocketcan-nlstuff.h + libsocketcan-nlstuff.h \ + can/netlink.h nobase_include_HEADERS = \ - socketcan_netlink.h \ - can/netlink.h + socketcan_netlink.h MAINTAINERCLEANFILES = \ libsocketcan-nl_config.h.in \ From 7e041b9af75d91cd79b4bda1b584ff0645c60baf Mon Sep 17 00:00:00 2001 From: Luotao Fu Date: Mon, 23 Nov 2009 12:59:02 +0100 Subject: [PATCH 11/88] remove own copy of can/netlink.h file include this from the header file now to make sure that application using this library will include this properly Signed-off-by: Luotao Fu --- include/GNUmakefile.am | 3 +- include/can/netlink.h | 113 ------------------------------------ include/socketcan_netlink.h | 2 + src/socketcan_netlink.c | 1 - 4 files changed, 3 insertions(+), 116 deletions(-) delete mode 100644 include/can/netlink.h diff --git a/include/GNUmakefile.am b/include/GNUmakefile.am index daae417a..c9abcb91 100644 --- a/include/GNUmakefile.am +++ b/include/GNUmakefile.am @@ -1,6 +1,5 @@ noinst_HEADERS = \ - libsocketcan-nlstuff.h \ - can/netlink.h + libsocketcan-nlstuff.h nobase_include_HEADERS = \ socketcan_netlink.h diff --git a/include/can/netlink.h b/include/can/netlink.h deleted file mode 100644 index 9ecbb787..00000000 --- a/include/can/netlink.h +++ /dev/null @@ -1,113 +0,0 @@ -/* - * linux/can/netlink.h - * - * Definitions for the CAN netlink interface - * - * Copyright (c) 2009 Wolfgang Grandegger - * - * Send feedback to - * - */ - -#ifndef CAN_NETLINK_H -#define CAN_NETLINK_H - -#include - -/* - * CAN bit-timing parameters - * - * For futher information, please read chapter "8 BIT TIMING - * REQUIREMENTS" of the "Bosch CAN Specification version 2.0" - * at http://www.semiconductors.bosch.de/pdf/can2spec.pdf. - */ -struct can_bittiming { - __u32 bitrate; /* Bit-rate in bits/second */ - __u32 sample_point; /* Sample point in one-tenth of a percent */ - __u32 tq; /* Time quanta (TQ) in nanoseconds */ - __u32 prop_seg; /* Propagation segment in TQs */ - __u32 phase_seg1; /* Phase buffer segment 1 in TQs */ - __u32 phase_seg2; /* Phase buffer segment 2 in TQs */ - __u32 sjw; /* Synchronisation jump width in TQs */ - __u32 brp; /* Bit-rate prescaler */ -}; - -/* - * CAN harware-dependent bit-timing constant - * - * Used for calculating and checking bit-timing parameters - */ -struct can_bittiming_const { - char name[16]; /* Name of the CAN controller hardware */ - __u32 tseg1_min; /* Time segement 1 = prop_seg + phase_seg1 */ - __u32 tseg1_max; - __u32 tseg2_min; /* Time segement 2 = phase_seg2 */ - __u32 tseg2_max; - __u32 sjw_max; /* Synchronisation jump width */ - __u32 brp_min; /* Bit-rate prescaler */ - __u32 brp_max; - __u32 brp_inc; -}; - -/* - * CAN clock parameters - */ -struct can_clock { - __u32 freq; /* CAN system clock frequency in Hz */ -}; - -/* - * CAN operational and error states - */ -enum can_state { - CAN_STATE_ERROR_ACTIVE = 0, /* RX/TX error count < 96 */ - CAN_STATE_ERROR_WARNING, /* RX/TX error count < 128 */ - CAN_STATE_ERROR_PASSIVE, /* RX/TX error count < 256 */ - CAN_STATE_BUS_OFF, /* RX/TX error count >= 256 */ - CAN_STATE_STOPPED, /* Device is stopped */ - CAN_STATE_SLEEPING, /* Device is sleeping */ - CAN_STATE_MAX -}; - -/* - * CAN controller mode - */ -struct can_ctrlmode { - __u32 mask; - __u32 flags; -}; - -#define CAN_CTRLMODE_LOOPBACK 0x1 /* Loopback mode */ -#define CAN_CTRLMODE_LISTENONLY 0x2 /* Listen-only mode */ -#define CAN_CTRLMODE_3_SAMPLES 0x4 /* Triple sampling mode */ - -/* - * CAN device statistics - */ -struct can_device_stats { - __u32 bus_error; /* Bus errors */ - __u32 error_warning; /* Changes to error warning state */ - __u32 error_passive; /* Changes to error passive state */ - __u32 bus_off; /* Changes to bus off state */ - __u32 arbitration_lost; /* Arbitration lost errors */ - __u32 restarts; /* CAN controller re-starts */ -}; - -/* - * CAN netlink interface - */ -enum { - IFLA_CAN_UNSPEC, - IFLA_CAN_BITTIMING, - IFLA_CAN_BITTIMING_CONST, - IFLA_CAN_CLOCK, - IFLA_CAN_STATE, - IFLA_CAN_CTRLMODE, - IFLA_CAN_RESTART_MS, - IFLA_CAN_RESTART, - __IFLA_CAN_MAX -}; - -#define IFLA_CAN_MAX (__IFLA_CAN_MAX - 1) - -#endif /* CAN_NETLINK_H */ diff --git a/include/socketcan_netlink.h b/include/socketcan_netlink.h index 19fd4df4..0ab4729a 100644 --- a/include/socketcan_netlink.h +++ b/include/socketcan_netlink.h @@ -21,6 +21,8 @@ #ifndef _SOCKETCAN_NETLINK_H #define _SOCKETCAN_NETLINK_H +#include + #define IFLA_CAN_MAX (__IFLA_CAN_MAX - 1) #define IF_UP 1 #define IF_DOWN 2 diff --git a/src/socketcan_netlink.c b/src/socketcan_netlink.c index 693d3239..b571e0dd 100644 --- a/src/socketcan_netlink.c +++ b/src/socketcan_netlink.c @@ -28,7 +28,6 @@ #include #include -#include #include #define parse_rtattr_nested(tb, max, rta) \ From bae25c143803f1099427f122b159c096270530c8 Mon Sep 17 00:00:00 2001 From: Luotao Fu Date: Mon, 23 Nov 2009 12:59:31 +0100 Subject: [PATCH 12/88] fixed dependency in .pc file Signed-off-by: Luotao Fu --- config/libsocketcan-nl.pc.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/libsocketcan-nl.pc.in b/config/libsocketcan-nl.pc.in index a29224aa..3b40509d 100644 --- a/config/libsocketcan-nl.pc.in +++ b/config/libsocketcan-nl.pc.in @@ -5,7 +5,7 @@ includedir=@includedir@ Name: libsocketcan-nl Description: provides access to socketcan netlink interface -Requires: @REQUIRES_LIBRN@ +Requires: Version: @VERSION@ Libs: -L${libdir} -llibsocketcan-nl #Libs.private: -lm -lpthread ...etc... From bbac00bbc7a427fd259eb0202e6a159b2eed4806 Mon Sep 17 00:00:00 2001 From: Luotao Fu Date: Mon, 23 Nov 2009 13:05:42 +0100 Subject: [PATCH 13/88] move internally used defines away from header Signed-off-by: Luotao Fu --- include/socketcan_netlink.h | 5 ----- src/socketcan_netlink.c | 5 +++++ 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/socketcan_netlink.h b/include/socketcan_netlink.h index 0ab4729a..5af0e98a 100644 --- a/include/socketcan_netlink.h +++ b/include/socketcan_netlink.h @@ -17,16 +17,11 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - #ifndef _SOCKETCAN_NETLINK_H #define _SOCKETCAN_NETLINK_H #include -#define IFLA_CAN_MAX (__IFLA_CAN_MAX - 1) -#define IF_UP 1 -#define IF_DOWN 2 - #define GET_STATE 1 #define GET_RESTART_MS 2 #define GET_BITTIMING 3 diff --git a/src/socketcan_netlink.c b/src/socketcan_netlink.c index b571e0dd..3f0862b9 100644 --- a/src/socketcan_netlink.c +++ b/src/socketcan_netlink.c @@ -36,6 +36,11 @@ #define NLMSG_TAIL(nmsg) \ ((struct rtattr *) (((void *) (nmsg)) + NLMSG_ALIGN((nmsg)->nlmsg_len))) +#define IFLA_CAN_MAX (__IFLA_CAN_MAX - 1) + +#define IF_UP 1 +#define IF_DOWN 2 + struct get_req { struct nlmsghdr n; struct rtgenmsg g; From 022be45eb1250c88222a92ab1d8f707fffcd34aa Mon Sep 17 00:00:00 2001 From: Luotao Fu Date: Mon, 23 Nov 2009 14:52:48 +0100 Subject: [PATCH 14/88] fix set_restart callback Signed-off-by: Luotao Fu --- src/socketcan_netlink.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/socketcan_netlink.c b/src/socketcan_netlink.c index 3f0862b9..0d11e7ae 100644 --- a/src/socketcan_netlink.c +++ b/src/socketcan_netlink.c @@ -501,14 +501,22 @@ int scan_set_restart(const char *name) int fd; int err = -1; int state; + __u32 restart_ms; + /* first we check if we can restart the device at all */ state = scan_get_state(name); - if (state != CAN_STATE_BUS_OFF) { fprintf(stderr, - "Device %s is not in BUS_OFF," - " no use to restart it\n", name); - err = 0; + "Device is not in BUS_OFF," + " no use to restart\n"); + goto err_out; + } + + restart_ms = scan_get_restart_ms(name); + if (restart_ms > 0) { + fprintf(stderr, + "auto restart with %ums interval is turned on," + " no use to restart\n", restart_ms); goto err_out; } From ba5cc5b4c84912bb6ea731ddb6ba983b2cc8c010 Mon Sep 17 00:00:00 2001 From: Luotao Fu Date: Mon, 23 Nov 2009 14:53:05 +0100 Subject: [PATCH 15/88] add set_bitrate callback Signed-off-by: Luotao Fu --- src/socketcan_netlink.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/socketcan_netlink.c b/src/socketcan_netlink.c index 0d11e7ae..e1c0a77f 100644 --- a/src/socketcan_netlink.c +++ b/src/socketcan_netlink.c @@ -560,6 +560,15 @@ int scan_set_ctrlmode(const char *name, __u32 mode, __u32 flags) return set_link(name, &req_info); } +int scan_set_bitrate(const char *name, __u32 bitrate) +{ + struct req_info req_info = { + .bitrate = bitrate, + }; + + return set_link(name, &req_info); +} + int scan_get_state(const char *name) { int fd; From fb19f0edcb7c7dfcf65fecbb87261fc500e8cb39 Mon Sep 17 00:00:00 2001 From: Luotao Fu Date: Mon, 23 Nov 2009 15:32:27 +0100 Subject: [PATCH 16/88] change get_state/restart_ms function prototype This way we can verify the return value correctly Signed-off-by: Luotao Fu --- include/socketcan_netlink.h | 4 ++-- src/socketcan_netlink.c | 34 ++++++++++++++++++---------------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/include/socketcan_netlink.h b/include/socketcan_netlink.h index 5af0e98a..330d6da5 100644 --- a/include/socketcan_netlink.h +++ b/include/socketcan_netlink.h @@ -35,8 +35,8 @@ int scan_set_bitrate(const char *name, __u32 bitrate); int scan_set_restart_ms(const char *name, __u32 restart_ms); int scan_set_ctrlmode(const char *name, __u32 mode, __u32 flags); -int scan_get_state(const char *name); -__u32 scan_get_restart_ms(const char *name); +int scan_get_state(const char *name, int *state); +int scan_get_restart_ms(const char *name, __u32 *restart_ms); int scan_get_bittiming(const char *name, struct can_bittiming *bt); int scan_get_ctrlmode(const char *name, struct can_ctrlmode *cm); diff --git a/src/socketcan_netlink.c b/src/socketcan_netlink.c index e1c0a77f..405e234c 100644 --- a/src/socketcan_netlink.c +++ b/src/socketcan_netlink.c @@ -504,16 +504,22 @@ int scan_set_restart(const char *name) __u32 restart_ms; /* first we check if we can restart the device at all */ - state = scan_get_state(name); - if (state != CAN_STATE_BUS_OFF) { + if ((scan_get_state(name, &state)) < 0) { + fprintf(stderr, "cannot get bustate, " + "something is seriously wrong\n"); + goto err_out; + } else if (state != CAN_STATE_BUS_OFF) { fprintf(stderr, "Device is not in BUS_OFF," " no use to restart\n"); goto err_out; } - restart_ms = scan_get_restart_ms(name); - if (restart_ms > 0) { + if ((scan_get_restart_ms(name, &restart_ms)) < 0) { + fprintf(stderr, "cannot get restart_ms, " + "something is seriously wrong\n"); + goto err_out; + } else if (restart_ms > 0) { fprintf(stderr, "auto restart with %ums interval is turned on," " no use to restart\n", restart_ms); @@ -569,39 +575,35 @@ int scan_set_bitrate(const char *name, __u32 bitrate) return set_link(name, &req_info); } -int scan_get_state(const char *name) +int scan_get_state(const char *name, int *state) { int fd; - int state; int err; fd = open_nl_sock(); if (fd < 0) return -1; - err = do_get_nl_link(fd, GET_STATE, name, &state); - if (err < 0) - return -1; + err = do_get_nl_link(fd, GET_STATE, name, state); + + close(fd); - return state; + return err; } -__u32 scan_get_restart_ms(const char *name) +int scan_get_restart_ms(const char *name, __u32 *restart_ms) { int fd; int err; - __u32 restart_ms; fd = open_nl_sock(); if (fd < 0) return -1; - err = do_get_nl_link(fd, GET_RESTART_MS, name, &restart_ms); - if (err < 0) - return -1; + err = do_get_nl_link(fd, GET_RESTART_MS, name, restart_ms); close(fd); - return restart_ms; + return err; } From dc8f25b61aebdc94ef51de56f74da481e571a8da Mon Sep 17 00:00:00 2001 From: Luotao Fu Date: Mon, 23 Nov 2009 15:36:38 +0100 Subject: [PATCH 17/88] switch netif_up/down to internal static function Signed-off-by: Luotao Fu --- include/socketcan_netlink.h | 3 --- src/socketcan_netlink.c | 20 ++++++++++---------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/include/socketcan_netlink.h b/include/socketcan_netlink.h index 330d6da5..9f8a3a95 100644 --- a/include/socketcan_netlink.h +++ b/include/socketcan_netlink.h @@ -27,9 +27,6 @@ #define GET_BITTIMING 3 #define GET_CTRLMODE 4 -int netif_down(int fd, const char *name); -int netif_up(int fd, const char *name); - int scan_set_restart(const char *name); int scan_set_bitrate(const char *name, __u32 bitrate); int scan_set_restart_ms(const char *name, __u32 restart_ms); diff --git a/src/socketcan_netlink.c b/src/socketcan_netlink.c index 405e234c..d13c8df6 100644 --- a/src/socketcan_netlink.c +++ b/src/socketcan_netlink.c @@ -459,6 +459,16 @@ static int do_set_nl_link(int fd, __u8 if_state, const char *name, return send_mod_request(fd, &req.n); } +static int netif_up(int fd, const char *name) +{ + return do_set_nl_link(fd, IF_UP, name, NULL); +} + +static int netif_down(int fd, const char *name) +{ + return do_set_nl_link(fd, IF_DOWN, name, NULL); +} + static int set_link(const char *name, struct req_info *req_info) { int fd; @@ -486,16 +496,6 @@ static int set_link(const char *name, struct req_info *req_info) return err; } -int netif_up(int fd, const char *name) -{ - return do_set_nl_link(fd, IF_UP, name, NULL); -} - -int netif_down(int fd, const char *name) -{ - return do_set_nl_link(fd, IF_DOWN, name, NULL); -} - int scan_set_restart(const char *name) { int fd; From c73035239f842523568338e1c618f7a18ab27105 Mon Sep 17 00:00:00 2001 From: Luotao Fu Date: Mon, 23 Nov 2009 15:38:07 +0100 Subject: [PATCH 18/88] move internally used defines away from header Signed-off-by: Luotao Fu --- include/socketcan_netlink.h | 5 ----- src/socketcan_netlink.c | 5 +++++ 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/socketcan_netlink.h b/include/socketcan_netlink.h index 9f8a3a95..a1d1e697 100644 --- a/include/socketcan_netlink.h +++ b/include/socketcan_netlink.h @@ -22,11 +22,6 @@ #include -#define GET_STATE 1 -#define GET_RESTART_MS 2 -#define GET_BITTIMING 3 -#define GET_CTRLMODE 4 - int scan_set_restart(const char *name); int scan_set_bitrate(const char *name, __u32 bitrate); int scan_set_restart_ms(const char *name, __u32 restart_ms); diff --git a/src/socketcan_netlink.c b/src/socketcan_netlink.c index d13c8df6..d5f39d60 100644 --- a/src/socketcan_netlink.c +++ b/src/socketcan_netlink.c @@ -41,6 +41,11 @@ #define IF_UP 1 #define IF_DOWN 2 +#define GET_STATE 1 +#define GET_RESTART_MS 2 +#define GET_BITTIMING 3 +#define GET_CTRLMODE 4 + struct get_req { struct nlmsghdr n; struct rtgenmsg g; From 4a8daa7258610b2607caa331c13ff83d4e3445d6 Mon Sep 17 00:00:00 2001 From: Luotao Fu Date: Mon, 23 Nov 2009 16:22:37 +0100 Subject: [PATCH 19/88] changed licence to LGPL Signed-off-by: Luotao Fu --- include/socketcan_netlink.h | 25 +++++++++++++------------ src/socketcan_netlink.c | 23 ++++++++++++----------- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/include/socketcan_netlink.h b/include/socketcan_netlink.h index a1d1e697..d5dcad11 100644 --- a/include/socketcan_netlink.h +++ b/include/socketcan_netlink.h @@ -1,20 +1,21 @@ /* * socketcan_netlink.h * - * (C) 2009 Luotao Fu - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the version 2 of the GNU General Public License - * as published by the Free Software Foundation + * (C) 2009 Luotao Fu * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef _SOCKETCAN_NETLINK_H diff --git a/src/socketcan_netlink.c b/src/socketcan_netlink.c index d5f39d60..af8060eb 100644 --- a/src/socketcan_netlink.c +++ b/src/socketcan_netlink.c @@ -2,19 +2,20 @@ * socketcan_netlink.c * * (C) 2009 Luotao Fu - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the version 2 of the GNU General Public License - * as published by the Free Software Foundation * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include From d8940fa45f801c7b6baf3b7f577de8db3b719205 Mon Sep 17 00:00:00 2001 From: Luotao Fu Date: Tue, 24 Nov 2009 14:56:48 +0100 Subject: [PATCH 20/88] switch back to trunk Signed-off-by: Luotao Fu --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 7e7c2a5c..3d018ed5 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ(2.59) -AC_INIT([libsocketcan-nl], [0.0.1], [bugs@pengutronix.de]) +AC_INIT([libsocketcan-nl], [trunk], [bugs@pengutronix.de]) AC_CONFIG_HEADERS([include/libsocketcan-nl_config.h]) AC_CONFIG_SRCDIR([src/socketcan_netlink.c]) AC_CONFIG_MACRO_DIR([config/m4]) From 0e6e5faad5f6dd8ecbd512bdf1270261bd822edd Mon Sep 17 00:00:00 2001 From: Luotao Fu Date: Tue, 24 Nov 2009 14:53:32 +0100 Subject: [PATCH 21/88] fix header check in configure.ac checking linux/[rt]netlink.h somehow doesn't work, remove them for now. Checking for linux/can/netlink.h is more important any way, add quit-if-not-found for this file Signed-off-by: Luotao Fu --- configure.ac | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index 3d018ed5..f0fcf6ea 100644 --- a/configure.ac +++ b/configure.ac @@ -66,11 +66,9 @@ AC_CHECK_HEADERS([ \ unistd.h \ utime.h \ net/if.h \ - linux/netlink.h,,,[linux/socket.h] \ - linux/rtnetlink.h,,,[linux/socket.h] \ ]) - +AC_CHECK_HEADER(linux/can/netlink.h,[],[AC_MSG_ERROR([cannot findcan/netlink.h])],[]) # # Checks for typedefs, structures, and compiler characteristics. # From 6cfd09ac25a6a8baa7206ad3263651303c12aac9 Mon Sep 17 00:00:00 2001 From: Luotao Fu Date: Tue, 24 Nov 2009 14:58:47 +0100 Subject: [PATCH 22/88] v0.0.2 Signed-off-by: Luotao Fu --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index f0fcf6ea..7aff817c 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ(2.59) -AC_INIT([libsocketcan-nl], [trunk], [bugs@pengutronix.de]) +AC_INIT([libsocketcan-nl], [0.0.2], [bugs@pengutronix.de]) AC_CONFIG_HEADERS([include/libsocketcan-nl_config.h]) AC_CONFIG_SRCDIR([src/socketcan_netlink.c]) AC_CONFIG_MACRO_DIR([config/m4]) From c3fa1d8c205d3dc2ab9b3b287d278244f0e997a7 Mon Sep 17 00:00:00 2001 From: Luotao Fu Date: Tue, 24 Nov 2009 15:00:10 +0100 Subject: [PATCH 23/88] switch version back to trunk Signed-off-by: Luotao Fu --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 7aff817c..f0fcf6ea 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ(2.59) -AC_INIT([libsocketcan-nl], [0.0.2], [bugs@pengutronix.de]) +AC_INIT([libsocketcan-nl], [trunk], [bugs@pengutronix.de]) AC_CONFIG_HEADERS([include/libsocketcan-nl_config.h]) AC_CONFIG_SRCDIR([src/socketcan_netlink.c]) AC_CONFIG_MACRO_DIR([config/m4]) From 6809185bf8549502c0370191749d6a5d5b77e0eb Mon Sep 17 00:00:00 2001 From: Luotao Fu Date: Wed, 25 Nov 2009 11:02:56 +0100 Subject: [PATCH 24/88] add .gitignore file Signed-off-by: Luotao Fu --- .gitignore | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..f95fbc42 --- /dev/null +++ b/.gitignore @@ -0,0 +1,29 @@ +libtool +configure +GNUmakefile +GNUmakefile.in + +aclocal.m4 +config/libsocketcan-nl.pc +config/m4/libtool.m4 +config/m4/ltoptions.m4 +config/m4/ltsugar.m4 +config/m4/ltversion.m4 +config/m4/lt~obsolete.m4 +include/libsocketcan-nl_config.h +include/libsocketcan-nl_config.h.in +include/stamp-h1 + +config.log +config.status +config/autoconf/ +autom4te.cache/ + +src/.libs/ +src/*.l* +tests/.libs/ +tests/test + +*~ +*.o +.deps/ From 14bb1061bc97a62ae5c74a900bc052d313c9f331 Mon Sep 17 00:00:00 2001 From: Luotao Fu Date: Wed, 25 Nov 2009 11:04:52 +0100 Subject: [PATCH 25/88] API change * parse struct can_ctrlmode directly to set_ctrl_mode * add set_bittiming, change set_bitrate internally * rename set_restart to do_restart * rerangement Signed-off-by: Luotao Fu --- include/socketcan_netlink.h | 10 ++++--- src/socketcan_netlink.c | 52 +++++++++++++++++++------------------ 2 files changed, 33 insertions(+), 29 deletions(-) diff --git a/include/socketcan_netlink.h b/include/socketcan_netlink.h index d5dcad11..79d27af8 100644 --- a/include/socketcan_netlink.h +++ b/include/socketcan_netlink.h @@ -23,14 +23,16 @@ #include -int scan_set_restart(const char *name); -int scan_set_bitrate(const char *name, __u32 bitrate); +int scan_do_restart(const char *name); + int scan_set_restart_ms(const char *name, __u32 restart_ms); -int scan_set_ctrlmode(const char *name, __u32 mode, __u32 flags); +int scan_set_bittiming(const char *name, struct can_bittiming *bt); +int scan_set_ctrlmode(const char *name, struct can_ctrlmode *cm); +int scan_set_bitrate(const char *name, __u32 bitrate); -int scan_get_state(const char *name, int *state); int scan_get_restart_ms(const char *name, __u32 *restart_ms); int scan_get_bittiming(const char *name, struct can_bittiming *bt); int scan_get_ctrlmode(const char *name, struct can_ctrlmode *cm); +int scan_get_state(const char *name, int *state); #endif diff --git a/src/socketcan_netlink.c b/src/socketcan_netlink.c index af8060eb..e54370b7 100644 --- a/src/socketcan_netlink.c +++ b/src/socketcan_netlink.c @@ -62,9 +62,8 @@ struct req_info { __u8 restart; __u8 disable_autorestart; __u32 restart_ms; - __u32 bitrate; - __u32 ctrlmode; - __u32 ctrlflags; + struct can_ctrlmode *ctrlmode; + struct can_bittiming *bittiming; }; static void @@ -388,9 +387,6 @@ static int do_set_nl_link(int fd, __u8 if_state, const char *name, { struct set_req req; - struct can_bittiming bt; - struct can_ctrlmode cm; - const char *type = "can"; memset(&req, 0, sizeof(req)); @@ -436,22 +432,19 @@ static int do_set_nl_link(int fd, __u8 if_state, const char *name, addattr32(&req.n, 1024, IFLA_CAN_RESTART_MS, req_info->restart_ms); - if (req_info->bitrate > 0) { - memset(&bt, 0, sizeof(bt)); - bt.bitrate = req_info->bitrate; - addattr_l(&req.n, 1024, IFLA_CAN_BITTIMING, - &bt, sizeof(bt)); - } - if (req_info->restart) addattr32(&req.n, 1024, IFLA_CAN_RESTART, 1); - if (req_info->ctrlmode) { - memset(&cm, 0, sizeof(cm)); - cm.mask = req_info->ctrlmode; - cm.flags = req_info->ctrlflags; - addattr_l(&req.n, 1024, IFLA_CAN_CTRLMODE, &cm, - sizeof(cm)); + if (req_info->bittiming != NULL) { + addattr_l(&req.n, 1024, IFLA_CAN_BITTIMING, + req_info->bittiming, + sizeof(struct can_bittiming)); + } + + if (req_info->ctrlmode != NULL) { + addattr_l(&req.n, 1024, IFLA_CAN_CTRLMODE, + req_info->ctrlmode, + sizeof(struct can_ctrlmode)); } /* mark end of data section */ @@ -502,7 +495,7 @@ static int set_link(const char *name, struct req_info *req_info) return err; } -int scan_set_restart(const char *name) +int scan_do_restart(const char *name) { int fd; int err = -1; @@ -562,25 +555,34 @@ int scan_set_restart_ms(const char *name, __u32 restart_ms) return set_link(name, &req_info); } -int scan_set_ctrlmode(const char *name, __u32 mode, __u32 flags) +int scan_set_ctrlmode(const char *name, struct can_ctrlmode *cm) { struct req_info req_info = { - .ctrlmode = mode, - .ctrlflags = flags, + .ctrlmode = cm, }; return set_link(name, &req_info); } -int scan_set_bitrate(const char *name, __u32 bitrate) +int scan_set_bittiming(const char *name, struct can_bittiming *bt) { struct req_info req_info = { - .bitrate = bitrate, + .bittiming = bt, }; return set_link(name, &req_info); } +int scan_set_bitrate(const char *name, __u32 bitrate) +{ + struct can_bittiming bt; + + memset(&bt, 0, sizeof(bt)); + bt.bitrate = bitrate; + + return scan_set_bittiming(name, &bt); +} + int scan_get_state(const char *name, int *state) { int fd; From cfcc9044d2a5e8591d68df563bdd116fb72dc00f Mon Sep 17 00:00:00 2001 From: Luotao Fu Date: Wed, 25 Nov 2009 11:20:35 +0100 Subject: [PATCH 26/88] update libtool version due to API change Signed-off-by: Luotao Fu --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index f0fcf6ea..cbffab37 100644 --- a/configure.ac +++ b/configure.ac @@ -21,7 +21,7 @@ CFLAGS="${CFLAGS} -Wall" # Interfaces changed/added/removed: CURRENT++ REVISION=0 # Interfaces added: AGE++ # Interfaces removed: AGE=0 -LT_CURRENT=0 +LT_CURRENT=1 LT_REVISION=0 LT_AGE=0 AC_SUBST(LT_CURRENT) From 5acb73848a6a2593ccf178897a7cbcda9090e765 Mon Sep 17 00:00:00 2001 From: Luotao Fu Date: Wed, 25 Nov 2009 14:59:49 +0100 Subject: [PATCH 27/88] fix linkerflag in .pc file Signed-off-by: Luotao Fu --- config/libsocketcan-nl.pc.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/libsocketcan-nl.pc.in b/config/libsocketcan-nl.pc.in index 3b40509d..f1beee10 100644 --- a/config/libsocketcan-nl.pc.in +++ b/config/libsocketcan-nl.pc.in @@ -7,6 +7,6 @@ Name: libsocketcan-nl Description: provides access to socketcan netlink interface Requires: Version: @VERSION@ -Libs: -L${libdir} -llibsocketcan-nl +Libs: -L${libdir} -lsocketcan-nl #Libs.private: -lm -lpthread ...etc... Cflags: -I${includedir} From 6f73bd10bcd4e3e8b5c5a0212f248356742b05f9 Mon Sep 17 00:00:00 2001 From: Luotao Fu Date: Wed, 25 Nov 2009 15:20:36 +0100 Subject: [PATCH 28/88] add set samplepoint value to set_bitrate Signed-off-by: Luotao Fu --- include/socketcan_netlink.h | 2 +- src/socketcan_netlink.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/include/socketcan_netlink.h b/include/socketcan_netlink.h index 79d27af8..5d6d3f79 100644 --- a/include/socketcan_netlink.h +++ b/include/socketcan_netlink.h @@ -28,7 +28,7 @@ int scan_do_restart(const char *name); int scan_set_restart_ms(const char *name, __u32 restart_ms); int scan_set_bittiming(const char *name, struct can_bittiming *bt); int scan_set_ctrlmode(const char *name, struct can_ctrlmode *cm); -int scan_set_bitrate(const char *name, __u32 bitrate); +int scan_set_bitrate(const char *name, __u32 bitrate, __u32 sample_point); int scan_get_restart_ms(const char *name, __u32 *restart_ms); int scan_get_bittiming(const char *name, struct can_bittiming *bt); diff --git a/src/socketcan_netlink.c b/src/socketcan_netlink.c index e54370b7..786969eb 100644 --- a/src/socketcan_netlink.c +++ b/src/socketcan_netlink.c @@ -573,12 +573,13 @@ int scan_set_bittiming(const char *name, struct can_bittiming *bt) return set_link(name, &req_info); } -int scan_set_bitrate(const char *name, __u32 bitrate) +int scan_set_bitrate(const char *name, __u32 bitrate, __u32 sample_point) { struct can_bittiming bt; memset(&bt, 0, sizeof(bt)); bt.bitrate = bitrate; + bt.sample_point = sample_point; return scan_set_bittiming(name, &bt); } From 5b2ef2f2d31e72c0fd9e22726acdef0be06f72a5 Mon Sep 17 00:00:00 2001 From: Luotao Fu Date: Wed, 25 Nov 2009 15:21:05 +0100 Subject: [PATCH 29/88] add get clock callbacks Signed-off-by: Luotao Fu --- include/socketcan_netlink.h | 1 + src/socketcan_netlink.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/include/socketcan_netlink.h b/include/socketcan_netlink.h index 5d6d3f79..b0ab757d 100644 --- a/include/socketcan_netlink.h +++ b/include/socketcan_netlink.h @@ -34,5 +34,6 @@ int scan_get_restart_ms(const char *name, __u32 *restart_ms); int scan_get_bittiming(const char *name, struct can_bittiming *bt); int scan_get_ctrlmode(const char *name, struct can_ctrlmode *cm); int scan_get_state(const char *name, int *state); +int scan_get_clock(const char *name, struct can_clock *clock); #endif diff --git a/src/socketcan_netlink.c b/src/socketcan_netlink.c index 786969eb..b2a7a330 100644 --- a/src/socketcan_netlink.c +++ b/src/socketcan_netlink.c @@ -46,6 +46,7 @@ #define GET_RESTART_MS 2 #define GET_BITTIMING 3 #define GET_CTRLMODE 4 +#define GET_CLOCK 5 struct get_req { struct nlmsghdr n; @@ -374,6 +375,16 @@ static int do_get_nl_link(int fd, __u8 acquire, const char *name, void *res) } else fprintf(stderr, "no ctrlmode data found\n"); + break; + case GET_CLOCK: + if (can_attr[IFLA_CAN_CLOCK]) { + memcpy(res, + RTA_DATA(can_attr[IFLA_CAN_CLOCK]), + sizeof(struct can_clock)); + ret = 0; + } else + fprintf(stderr, "no clock parameter data found\n"); + break; default: fprintf(stderr, "unknown acquire mode\n"); @@ -649,3 +660,20 @@ int scan_get_ctrlmode(const char *name, struct can_ctrlmode *cm) close(fd); return 0; } + +int scan_get_clock(const char *name, struct can_clock *clock) +{ + int fd; + int err; + + fd = open_nl_sock(); + if (fd < 0) + return -1; + + err = do_get_nl_link(fd, GET_CLOCK, name, clock); + if (err < 0) + return -1; + + close(fd); + return 0; +} From d480c2c8d0fd36a7a745664cdc059d792b975489 Mon Sep 17 00:00:00 2001 From: Luotao Fu Date: Wed, 25 Nov 2009 16:32:44 +0100 Subject: [PATCH 30/88] v0.0.3 --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index cbffab37..37eca014 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ(2.59) -AC_INIT([libsocketcan-nl], [trunk], [bugs@pengutronix.de]) +AC_INIT([libsocketcan-nl], [0.0.3], [bugs@pengutronix.de]) AC_CONFIG_HEADERS([include/libsocketcan-nl_config.h]) AC_CONFIG_SRCDIR([src/socketcan_netlink.c]) AC_CONFIG_MACRO_DIR([config/m4]) From 338a640d6f392d88a91fad6cc83c0b831914105c Mon Sep 17 00:00:00 2001 From: Luotao Fu Date: Wed, 25 Nov 2009 16:45:03 +0100 Subject: [PATCH 31/88] switch version back to trunk Signed-off-by: Luotao Fu --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 37eca014..cbffab37 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ(2.59) -AC_INIT([libsocketcan-nl], [0.0.3], [bugs@pengutronix.de]) +AC_INIT([libsocketcan-nl], [trunk], [bugs@pengutronix.de]) AC_CONFIG_HEADERS([include/libsocketcan-nl_config.h]) AC_CONFIG_SRCDIR([src/socketcan_netlink.c]) AC_CONFIG_MACRO_DIR([config/m4]) From 32c72a4868ab77d6e33359eee221ac9b502b25e1 Mon Sep 17 00:00:00 2001 From: Luotao Fu Date: Thu, 26 Nov 2009 16:09:54 +0100 Subject: [PATCH 32/88] removed duplicated code in get_ callbacks added a get_link internal callback to eliminate the duplicated code in _get functions. Signed-off-by: Luotao Fu --- src/socketcan_netlink.c | 88 ++++++++++++----------------------------- 1 file changed, 25 insertions(+), 63 deletions(-) diff --git a/src/socketcan_netlink.c b/src/socketcan_netlink.c index b2a7a330..f784fce9 100644 --- a/src/socketcan_netlink.c +++ b/src/socketcan_netlink.c @@ -393,6 +393,26 @@ static int do_get_nl_link(int fd, __u8 acquire, const char *name, void *res) return ret; } +static int get_link(const char *name, __u8 acquire, void *res) +{ + int fd; + int err = -1; + + fd = open_nl_sock(); + if (fd < 0) + goto err_out; + + err = do_get_nl_link(fd, acquire, name, res); + if (err < 0) + goto close_out; + +close_out: + close(fd); +err_out: + return err; + +} + static int do_set_nl_link(int fd, __u8 if_state, const char *name, struct req_info *req_info) { @@ -597,83 +617,25 @@ int scan_set_bitrate(const char *name, __u32 bitrate, __u32 sample_point) int scan_get_state(const char *name, int *state) { - int fd; - int err; - - fd = open_nl_sock(); - if (fd < 0) - return -1; - - err = do_get_nl_link(fd, GET_STATE, name, state); - - close(fd); - - return err; + return get_link(name, GET_STATE, state); } int scan_get_restart_ms(const char *name, __u32 *restart_ms) { - int fd; - int err; - - fd = open_nl_sock(); - if (fd < 0) - return -1; - - err = do_get_nl_link(fd, GET_RESTART_MS, name, restart_ms); - - close(fd); - return err; - + return get_link(name, GET_RESTART_MS, restart_ms); } int scan_get_bittiming(const char *name, struct can_bittiming *bt) { - int fd; - int err; - - fd = open_nl_sock(); - if (fd < 0) - return -1; - - err = do_get_nl_link(fd, GET_BITTIMING, name, bt); - if (err < 0) - return -1; - - close(fd); - return 0; + return get_link(name, GET_BITTIMING, bt); } int scan_get_ctrlmode(const char *name, struct can_ctrlmode *cm) { - int fd; - int err; - - fd = open_nl_sock(); - if (fd < 0) - return -1; - - err = do_get_nl_link(fd, GET_CTRLMODE, name, cm); - if (err < 0) - return -1; - - close(fd); - return 0; + return get_link(name, GET_CTRLMODE, cm); } int scan_get_clock(const char *name, struct can_clock *clock) { - int fd; - int err; - - fd = open_nl_sock(); - if (fd < 0) - return -1; - - err = do_get_nl_link(fd, GET_CLOCK, name, clock); - if (err < 0) - return -1; - - close(fd); - return 0; + return get_link(name, GET_CLOCK, clock); } From 1751269c33346c825df9183cf26c4ff1d3a4b8be Mon Sep 17 00:00:00 2001 From: Luotao Fu Date: Thu, 26 Nov 2009 16:16:02 +0100 Subject: [PATCH 33/88] remove internal netif_up/down callbacks and export them We don't do if_up/down internally any longer, since it is depreacated. Instead we add now can_start/stop callbacks and let the user do the job themselves in threir applications. Signed-off-by: Luotao Fu --- include/socketcan_netlink.h | 2 ++ src/socketcan_netlink.c | 39 +++++++++++++++---------------------- 2 files changed, 18 insertions(+), 23 deletions(-) diff --git a/include/socketcan_netlink.h b/include/socketcan_netlink.h index b0ab757d..c5712184 100644 --- a/include/socketcan_netlink.h +++ b/include/socketcan_netlink.h @@ -24,6 +24,8 @@ #include int scan_do_restart(const char *name); +int scan_do_stop(const char *name); +int scan_do_start(const char *name); int scan_set_restart_ms(const char *name, __u32 restart_ms); int scan_set_bittiming(const char *name, struct can_bittiming *bt); diff --git a/src/socketcan_netlink.c b/src/socketcan_netlink.c index f784fce9..250e56b4 100644 --- a/src/socketcan_netlink.c +++ b/src/socketcan_netlink.c @@ -489,17 +489,7 @@ static int do_set_nl_link(int fd, __u8 if_state, const char *name, return send_mod_request(fd, &req.n); } -static int netif_up(int fd, const char *name) -{ - return do_set_nl_link(fd, IF_UP, name, NULL); -} - -static int netif_down(int fd, const char *name) -{ - return do_set_nl_link(fd, IF_DOWN, name, NULL); -} - -static int set_link(const char *name, struct req_info *req_info) +static int set_link(const char *name, __u8 if_state, struct req_info *req_info) { int fd; int err = 0; @@ -508,15 +498,7 @@ static int set_link(const char *name, struct req_info *req_info) if (fd < 0) goto err_out; - err = netif_down(fd, name); - if (err < 0) - goto close_out; - - err = do_set_nl_link(fd, 0, name, req_info); - if (err < 0) - goto close_out; - - err = netif_up(fd, name); + err = do_set_nl_link(fd, if_state, name, req_info); if (err < 0) goto close_out; @@ -526,6 +508,17 @@ static int set_link(const char *name, struct req_info *req_info) return err; } +int scan_do_start(const char *name) +{ + return set_link(name, IF_UP, NULL); +} + +int scan_do_stop(const char *name) +{ + + return set_link(name, IF_DOWN, NULL); +} + int scan_do_restart(const char *name) { int fd; @@ -583,7 +576,7 @@ int scan_set_restart_ms(const char *name, __u32 restart_ms) if (restart_ms == 0) req_info.disable_autorestart = 1; - return set_link(name, &req_info); + return set_link(name, 0, &req_info); } int scan_set_ctrlmode(const char *name, struct can_ctrlmode *cm) @@ -592,7 +585,7 @@ int scan_set_ctrlmode(const char *name, struct can_ctrlmode *cm) .ctrlmode = cm, }; - return set_link(name, &req_info); + return set_link(name, 0, &req_info); } int scan_set_bittiming(const char *name, struct can_bittiming *bt) @@ -601,7 +594,7 @@ int scan_set_bittiming(const char *name, struct can_bittiming *bt) .bittiming = bt, }; - return set_link(name, &req_info); + return set_link(name, 0, &req_info); } int scan_set_bitrate(const char *name, __u32 bitrate, __u32 sample_point) From 257877f31506a5440ba8ae78ab35b177df792397 Mon Sep 17 00:00:00 2001 From: Luotao Fu Date: Fri, 27 Nov 2009 11:53:41 +0100 Subject: [PATCH 34/88] rename library and API prefix library is now called libsocketcan, API carry the prefix can_ Signed-off-by: Luotao Fu --- .gitignore | 6 ++-- config/GNUmakefile.am | 4 +-- ...bsocketcan-nl.pc.in => libsocketcan.pc.in} | 6 ++-- configure.ac | 8 ++--- include/GNUmakefile.am | 8 ++--- include/libsocketcan-nl.h | 5 --- include/libsocketcan-nlstuff.h | 5 --- .../{socketcan_netlink.h => libsocketcan.h} | 26 +++++++------- src/GNUmakefile.am | 8 ++--- src/{socketcan_netlink.c => libsocketcan.c} | 34 +++++++++---------- tests/GNUmakefile.am | 2 +- 11 files changed, 51 insertions(+), 61 deletions(-) rename config/{libsocketcan-nl.pc.in => libsocketcan.pc.in} (60%) delete mode 100644 include/libsocketcan-nl.h delete mode 100644 include/libsocketcan-nlstuff.h rename include/{socketcan_netlink.h => libsocketcan.h} (55%) rename src/{socketcan_netlink.c => libsocketcan.c} (93%) diff --git a/.gitignore b/.gitignore index f95fbc42..f5cc7783 100644 --- a/.gitignore +++ b/.gitignore @@ -4,14 +4,14 @@ GNUmakefile GNUmakefile.in aclocal.m4 -config/libsocketcan-nl.pc +config/libsocketcan.pc config/m4/libtool.m4 config/m4/ltoptions.m4 config/m4/ltsugar.m4 config/m4/ltversion.m4 config/m4/lt~obsolete.m4 -include/libsocketcan-nl_config.h -include/libsocketcan-nl_config.h.in +include/libsocketcan_config.h +include/libsocketcan_config.h.in include/stamp-h1 config.log diff --git a/config/GNUmakefile.am b/config/GNUmakefile.am index 998e3934..5b690b43 100644 --- a/config/GNUmakefile.am +++ b/config/GNUmakefile.am @@ -1,8 +1,8 @@ EXTRA_DIST = \ - libsocketcan-nl.pc.in + libsocketcan.pc.in pkgconfigdir = $(libdir)/pkgconfig -pkgconfig_DATA = libsocketcan-nl.pc +pkgconfig_DATA = libsocketcan.pc MAINTAINERCLEANFILES = \ GNUmakefile.in diff --git a/config/libsocketcan-nl.pc.in b/config/libsocketcan.pc.in similarity index 60% rename from config/libsocketcan-nl.pc.in rename to config/libsocketcan.pc.in index f1beee10..5cb6ebeb 100644 --- a/config/libsocketcan-nl.pc.in +++ b/config/libsocketcan.pc.in @@ -3,10 +3,10 @@ exec_prefix=@exec_prefix@ libdir=@libdir@ includedir=@includedir@ -Name: libsocketcan-nl -Description: provides access to socketcan netlink interface +Name: libsocketcan +Description: provides access to socketcan configuration interface Requires: Version: @VERSION@ -Libs: -L${libdir} -lsocketcan-nl +Libs: -L${libdir} -lsocketcan #Libs.private: -lm -lpthread ...etc... Cflags: -I${includedir} diff --git a/configure.ac b/configure.ac index cbffab37..c205dd4c 100644 --- a/configure.ac +++ b/configure.ac @@ -2,9 +2,9 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ(2.59) -AC_INIT([libsocketcan-nl], [trunk], [bugs@pengutronix.de]) -AC_CONFIG_HEADERS([include/libsocketcan-nl_config.h]) -AC_CONFIG_SRCDIR([src/socketcan_netlink.c]) +AC_INIT([libsocketcan], [trunk], [bugs@pengutronix.de]) +AC_CONFIG_HEADERS([include/libsocketcan_config.h]) +AC_CONFIG_SRCDIR([src/libsocketcan.c]) AC_CONFIG_MACRO_DIR([config/m4]) AC_CONFIG_AUX_DIR([config/autoconf]) AC_CANONICAL_BUILD @@ -110,7 +110,7 @@ fi AC_CONFIG_FILES([ GNUmakefile - config/libsocketcan-nl.pc + config/libsocketcan.pc config/GNUmakefile include/GNUmakefile src/GNUmakefile diff --git a/include/GNUmakefile.am b/include/GNUmakefile.am index c9abcb91..00bf0ec8 100644 --- a/include/GNUmakefile.am +++ b/include/GNUmakefile.am @@ -1,9 +1,9 @@ -noinst_HEADERS = \ - libsocketcan-nlstuff.h +# noinst_HEADERS = \ +# libsocketcan-stuff.h nobase_include_HEADERS = \ - socketcan_netlink.h + libsocketcan.h MAINTAINERCLEANFILES = \ - libsocketcan-nl_config.h.in \ + libsocketcan_config.h.in \ GNUmakefile.in diff --git a/include/libsocketcan-nl.h b/include/libsocketcan-nl.h deleted file mode 100644 index 26ad1e43..00000000 --- a/include/libsocketcan-nl.h +++ /dev/null @@ -1,5 +0,0 @@ -#ifndef LIBSOCKETCAN-NL_H -#define LIBSOCKETCAN-NL_H - - -#endif diff --git a/include/libsocketcan-nlstuff.h b/include/libsocketcan-nlstuff.h deleted file mode 100644 index 26ad1e43..00000000 --- a/include/libsocketcan-nlstuff.h +++ /dev/null @@ -1,5 +0,0 @@ -#ifndef LIBSOCKETCAN-NL_H -#define LIBSOCKETCAN-NL_H - - -#endif diff --git a/include/socketcan_netlink.h b/include/libsocketcan.h similarity index 55% rename from include/socketcan_netlink.h rename to include/libsocketcan.h index c5712184..5ee8ab75 100644 --- a/include/socketcan_netlink.h +++ b/include/libsocketcan.h @@ -1,5 +1,5 @@ /* - * socketcan_netlink.h + * libsocketcan.h * * (C) 2009 Luotao Fu * @@ -23,19 +23,19 @@ #include -int scan_do_restart(const char *name); -int scan_do_stop(const char *name); -int scan_do_start(const char *name); +int can_do_restart(const char *name); +int can_do_stop(const char *name); +int can_do_start(const char *name); -int scan_set_restart_ms(const char *name, __u32 restart_ms); -int scan_set_bittiming(const char *name, struct can_bittiming *bt); -int scan_set_ctrlmode(const char *name, struct can_ctrlmode *cm); -int scan_set_bitrate(const char *name, __u32 bitrate, __u32 sample_point); +int can_set_restart_ms(const char *name, __u32 restart_ms); +int can_set_bittiming(const char *name, struct can_bittiming *bt); +int can_set_ctrlmode(const char *name, struct can_ctrlmode *cm); +int can_set_bitrate(const char *name, __u32 bitrate, __u32 sample_point); -int scan_get_restart_ms(const char *name, __u32 *restart_ms); -int scan_get_bittiming(const char *name, struct can_bittiming *bt); -int scan_get_ctrlmode(const char *name, struct can_ctrlmode *cm); -int scan_get_state(const char *name, int *state); -int scan_get_clock(const char *name, struct can_clock *clock); +int can_get_restart_ms(const char *name, __u32 *restart_ms); +int can_get_bittiming(const char *name, struct can_bittiming *bt); +int can_get_ctrlmode(const char *name, struct can_ctrlmode *cm); +int can_get_state(const char *name, int *state); +int can_get_clock(const char *name, struct can_clock *clock); #endif diff --git a/src/GNUmakefile.am b/src/GNUmakefile.am index 3e0fe38f..1709bbe6 100644 --- a/src/GNUmakefile.am +++ b/src/GNUmakefile.am @@ -1,16 +1,16 @@ -lib_LTLIBRARIES = libsocketcan-nl.la +lib_LTLIBRARIES = libsocketcan.la AM_CPPFLAGS = \ -I$(top_srcdir)/include \ -I$(top_builddir)/include -libsocketcan_nl_la_SOURCES = socketcan_netlink.c +libsocketcan_la_SOURCES = libsocketcan.c -libsocketcan_nl_la_LDFLAGS = \ +libsocketcan_la_LDFLAGS = \ -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) # -no-undefined # win32_dll stuff only -#libsocketcan-nl_LDADD = \ +#libsocketcan_LDADD = \ # $(librn_LIBS) # MAINTAINERCLEANFILES = \ diff --git a/src/socketcan_netlink.c b/src/libsocketcan.c similarity index 93% rename from src/socketcan_netlink.c rename to src/libsocketcan.c index 250e56b4..94d66315 100644 --- a/src/socketcan_netlink.c +++ b/src/libsocketcan.c @@ -1,5 +1,5 @@ /* - * socketcan_netlink.c + * libsocketcan.c * * (C) 2009 Luotao Fu * @@ -29,7 +29,7 @@ #include #include -#include +#include #define parse_rtattr_nested(tb, max, rta) \ (parse_rtattr((tb), (max), RTA_DATA(rta), RTA_PAYLOAD(rta))) @@ -508,18 +508,18 @@ static int set_link(const char *name, __u8 if_state, struct req_info *req_info) return err; } -int scan_do_start(const char *name) +int can_do_start(const char *name) { return set_link(name, IF_UP, NULL); } -int scan_do_stop(const char *name) +int can_do_stop(const char *name) { return set_link(name, IF_DOWN, NULL); } -int scan_do_restart(const char *name) +int can_do_restart(const char *name) { int fd; int err = -1; @@ -527,7 +527,7 @@ int scan_do_restart(const char *name) __u32 restart_ms; /* first we check if we can restart the device at all */ - if ((scan_get_state(name, &state)) < 0) { + if ((can_get_state(name, &state)) < 0) { fprintf(stderr, "cannot get bustate, " "something is seriously wrong\n"); goto err_out; @@ -538,7 +538,7 @@ int scan_do_restart(const char *name) goto err_out; } - if ((scan_get_restart_ms(name, &restart_ms)) < 0) { + if ((can_get_restart_ms(name, &restart_ms)) < 0) { fprintf(stderr, "cannot get restart_ms, " "something is seriously wrong\n"); goto err_out; @@ -567,7 +567,7 @@ int scan_do_restart(const char *name) return err; } -int scan_set_restart_ms(const char *name, __u32 restart_ms) +int can_set_restart_ms(const char *name, __u32 restart_ms) { struct req_info req_info = { .restart_ms = restart_ms, @@ -579,7 +579,7 @@ int scan_set_restart_ms(const char *name, __u32 restart_ms) return set_link(name, 0, &req_info); } -int scan_set_ctrlmode(const char *name, struct can_ctrlmode *cm) +int can_set_ctrlmode(const char *name, struct can_ctrlmode *cm) { struct req_info req_info = { .ctrlmode = cm, @@ -588,7 +588,7 @@ int scan_set_ctrlmode(const char *name, struct can_ctrlmode *cm) return set_link(name, 0, &req_info); } -int scan_set_bittiming(const char *name, struct can_bittiming *bt) +int can_set_bittiming(const char *name, struct can_bittiming *bt) { struct req_info req_info = { .bittiming = bt, @@ -597,7 +597,7 @@ int scan_set_bittiming(const char *name, struct can_bittiming *bt) return set_link(name, 0, &req_info); } -int scan_set_bitrate(const char *name, __u32 bitrate, __u32 sample_point) +int can_set_bitrate(const char *name, __u32 bitrate, __u32 sample_point) { struct can_bittiming bt; @@ -605,30 +605,30 @@ int scan_set_bitrate(const char *name, __u32 bitrate, __u32 sample_point) bt.bitrate = bitrate; bt.sample_point = sample_point; - return scan_set_bittiming(name, &bt); + return can_set_bittiming(name, &bt); } -int scan_get_state(const char *name, int *state) +int can_get_state(const char *name, int *state) { return get_link(name, GET_STATE, state); } -int scan_get_restart_ms(const char *name, __u32 *restart_ms) +int can_get_restart_ms(const char *name, __u32 *restart_ms) { return get_link(name, GET_RESTART_MS, restart_ms); } -int scan_get_bittiming(const char *name, struct can_bittiming *bt) +int can_get_bittiming(const char *name, struct can_bittiming *bt) { return get_link(name, GET_BITTIMING, bt); } -int scan_get_ctrlmode(const char *name, struct can_ctrlmode *cm) +int can_get_ctrlmode(const char *name, struct can_ctrlmode *cm) { return get_link(name, GET_CTRLMODE, cm); } -int scan_get_clock(const char *name, struct can_clock *clock) +int can_get_clock(const char *name, struct can_clock *clock) { return get_link(name, GET_CLOCK, clock); } diff --git a/tests/GNUmakefile.am b/tests/GNUmakefile.am index 6e52c67d..0744dc65 100644 --- a/tests/GNUmakefile.am +++ b/tests/GNUmakefile.am @@ -7,7 +7,7 @@ noinst_PROGRAMS = \ test_SOURCES = \ test.c test_LDADD = \ - $(top_builddir)/src/libsocketcan-nl.la + $(top_builddir)/src/libsocketcan.la AM_CPPFLAGS = \ -I$(top_srcdir)/include \ From b2306d4979363616c26fc8a8a9c2b9e44d3ad7eb Mon Sep 17 00:00:00 2001 From: Luotao Fu Date: Fri, 27 Nov 2009 13:27:07 +0100 Subject: [PATCH 35/88] splitted up set_bitrate we now have can_set_bitrate and can_set_bitrate_samplepoint. The second is for convenience for the developer. We tend to let the kernel use CIA recommnended sample point value, which can_set_bitrate simply does Signed-off-by: Luotao Fu --- include/libsocketcan.h | 3 ++- src/libsocketcan.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/include/libsocketcan.h b/include/libsocketcan.h index 5ee8ab75..a92d33b3 100644 --- a/include/libsocketcan.h +++ b/include/libsocketcan.h @@ -30,7 +30,8 @@ int can_do_start(const char *name); int can_set_restart_ms(const char *name, __u32 restart_ms); int can_set_bittiming(const char *name, struct can_bittiming *bt); int can_set_ctrlmode(const char *name, struct can_ctrlmode *cm); -int can_set_bitrate(const char *name, __u32 bitrate, __u32 sample_point); +int can_set_bitrate(const char *name, __u32 bitrate); +int can_set_bitrate_samplepoint(const char *name, __u32 bitrate, __u32 sample_point); int can_get_restart_ms(const char *name, __u32 *restart_ms); int can_get_bittiming(const char *name, struct can_bittiming *bt); diff --git a/src/libsocketcan.c b/src/libsocketcan.c index 94d66315..c3922f21 100644 --- a/src/libsocketcan.c +++ b/src/libsocketcan.c @@ -597,17 +597,27 @@ int can_set_bittiming(const char *name, struct can_bittiming *bt) return set_link(name, 0, &req_info); } -int can_set_bitrate(const char *name, __u32 bitrate, __u32 sample_point) +int can_set_bitrate(const char *name, __u32 bitrate) { struct can_bittiming bt; memset(&bt, 0, sizeof(bt)); bt.bitrate = bitrate; - bt.sample_point = sample_point; return can_set_bittiming(name, &bt); } +int can_set_bitrate_samplepoint(const char *name, __u32 bitrate, __u32 sample_point) +{ + struct can_bittiming bt; + + memset(&bt, 0, sizeof(bt)); + bt.bitrate = bitrate; + bt.sample_point = sample_point; + printf("%s: sample_point %u\n", __func__,bt.sample_point); + return can_set_bittiming(name, &bt); +} + int can_get_state(const char *name, int *state) { return get_link(name, GET_STATE, state); From bedbd3788fb41e958d041c8b72812fff828af53d Mon Sep 17 00:00:00 2001 From: Luotao Fu Date: Fri, 27 Nov 2009 14:35:05 +0100 Subject: [PATCH 36/88] update libtool version Signed-off-by: Luotao Fu --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index c205dd4c..e4e64449 100644 --- a/configure.ac +++ b/configure.ac @@ -21,7 +21,7 @@ CFLAGS="${CFLAGS} -Wall" # Interfaces changed/added/removed: CURRENT++ REVISION=0 # Interfaces added: AGE++ # Interfaces removed: AGE=0 -LT_CURRENT=1 +LT_CURRENT=2 LT_REVISION=0 LT_AGE=0 AC_SUBST(LT_CURRENT) From 96b6e7594758d392e5f61d43f43700c093fa59a5 Mon Sep 17 00:00:00 2001 From: Luotao Fu Date: Fri, 27 Nov 2009 16:28:36 +0100 Subject: [PATCH 37/88] lindent, remove debug print Signed-off-by: Luotao Fu --- src/libsocketcan.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/libsocketcan.c b/src/libsocketcan.c index c3922f21..3c02d3db 100644 --- a/src/libsocketcan.c +++ b/src/libsocketcan.c @@ -317,7 +317,9 @@ static int do_get_nl_link(int fd, __u8 acquire, const char *name, void *res) nl_msg->nlmsg_len - NLMSG_LENGTH(sizeof(struct ifaddrmsg)); parse_rtattr(tb, IFLA_MAX, IFLA_RTA(ifi), len); - if (strncmp((char *)RTA_DATA(tb[IFLA_IFNAME]), name, sizeof(name)) != 0) + if (strncmp + ((char *)RTA_DATA(tb[IFLA_IFNAME]), name, + sizeof(name)) != 0) continue; if (tb[IFLA_LINKINFO]) @@ -383,7 +385,8 @@ static int do_get_nl_link(int fd, __u8 acquire, const char *name, void *res) sizeof(struct can_clock)); ret = 0; } else - fprintf(stderr, "no clock parameter data found\n"); + fprintf(stderr, + "no clock parameter data found\n"); break; default: @@ -468,14 +471,14 @@ static int do_set_nl_link(int fd, __u8 if_state, const char *name, if (req_info->bittiming != NULL) { addattr_l(&req.n, 1024, IFLA_CAN_BITTIMING, - req_info->bittiming, - sizeof(struct can_bittiming)); + req_info->bittiming, + sizeof(struct can_bittiming)); } if (req_info->ctrlmode != NULL) { addattr_l(&req.n, 1024, IFLA_CAN_CTRLMODE, - req_info->ctrlmode, - sizeof(struct can_ctrlmode)); + req_info->ctrlmode, + sizeof(struct can_ctrlmode)); } /* mark end of data section */ @@ -515,7 +518,6 @@ int can_do_start(const char *name) int can_do_stop(const char *name) { - return set_link(name, IF_DOWN, NULL); } @@ -529,18 +531,17 @@ int can_do_restart(const char *name) /* first we check if we can restart the device at all */ if ((can_get_state(name, &state)) < 0) { fprintf(stderr, "cannot get bustate, " - "something is seriously wrong\n"); + "something is seriously wrong\n"); goto err_out; } else if (state != CAN_STATE_BUS_OFF) { fprintf(stderr, - "Device is not in BUS_OFF," - " no use to restart\n"); + "Device is not in BUS_OFF," " no use to restart\n"); goto err_out; } if ((can_get_restart_ms(name, &restart_ms)) < 0) { fprintf(stderr, "cannot get restart_ms, " - "something is seriously wrong\n"); + "something is seriously wrong\n"); goto err_out; } else if (restart_ms > 0) { fprintf(stderr, @@ -579,7 +580,7 @@ int can_set_restart_ms(const char *name, __u32 restart_ms) return set_link(name, 0, &req_info); } -int can_set_ctrlmode(const char *name, struct can_ctrlmode *cm) +int can_set_ctrlmode(const char *name, struct can_ctrlmode *cm) { struct req_info req_info = { .ctrlmode = cm, @@ -607,14 +608,15 @@ int can_set_bitrate(const char *name, __u32 bitrate) return can_set_bittiming(name, &bt); } -int can_set_bitrate_samplepoint(const char *name, __u32 bitrate, __u32 sample_point) +int can_set_bitrate_samplepoint(const char *name, __u32 bitrate, + __u32 sample_point) { struct can_bittiming bt; memset(&bt, 0, sizeof(bt)); bt.bitrate = bitrate; bt.sample_point = sample_point; - printf("%s: sample_point %u\n", __func__,bt.sample_point); + return can_set_bittiming(name, &bt); } From 73a4999c24e7c3d1c26a1f705f72d42d16efb906 Mon Sep 17 00:00:00 2001 From: Luotao Fu Date: Fri, 27 Nov 2009 16:45:05 +0100 Subject: [PATCH 38/88] v0.0.4 Signed-off-by: Luotao Fu --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index e4e64449..51bfb872 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ(2.59) -AC_INIT([libsocketcan], [trunk], [bugs@pengutronix.de]) +AC_INIT([libsocketcan], [0.0.4], [bugs@pengutronix.de]) AC_CONFIG_HEADERS([include/libsocketcan_config.h]) AC_CONFIG_SRCDIR([src/libsocketcan.c]) AC_CONFIG_MACRO_DIR([config/m4]) From 463ac873c75e88d92d3e4bdd3584a5ec520d8d66 Mon Sep 17 00:00:00 2001 From: Wolfgang Grandegger Date: Tue, 1 Dec 2009 09:59:19 +0100 Subject: [PATCH 39/88] Add can_get_bittiming_const() Signed-off-by: Wolfgang Grandegger Acked-by: Luotao Fu --- include/libsocketcan.h | 1 + src/libsocketcan.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/include/libsocketcan.h b/include/libsocketcan.h index a92d33b3..afe15f61 100644 --- a/include/libsocketcan.h +++ b/include/libsocketcan.h @@ -38,5 +38,6 @@ int can_get_bittiming(const char *name, struct can_bittiming *bt); int can_get_ctrlmode(const char *name, struct can_ctrlmode *cm); int can_get_state(const char *name, int *state); int can_get_clock(const char *name, struct can_clock *clock); +int can_get_bittiming_const(const char *name, struct can_bittiming_const *btc); #endif diff --git a/src/libsocketcan.c b/src/libsocketcan.c index 3c02d3db..07cc10f0 100644 --- a/src/libsocketcan.c +++ b/src/libsocketcan.c @@ -47,6 +47,7 @@ #define GET_BITTIMING 3 #define GET_CTRLMODE 4 #define GET_CLOCK 5 +#define GET_BITTIMING_CONST 6 struct get_req { struct nlmsghdr n; @@ -388,6 +389,16 @@ static int do_get_nl_link(int fd, __u8 acquire, const char *name, void *res) fprintf(stderr, "no clock parameter data found\n"); + break; + case GET_BITTIMING_CONST: + if (can_attr[IFLA_CAN_BITTIMING_CONST]) { + memcpy(res, + RTA_DATA(can_attr[IFLA_CAN_BITTIMING_CONST]), + sizeof(struct can_bittiming_const)); + ret = 0; + } else + fprintf(stderr, "no bittiming_const data found\n"); + break; default: fprintf(stderr, "unknown acquire mode\n"); @@ -644,3 +655,9 @@ int can_get_clock(const char *name, struct can_clock *clock) { return get_link(name, GET_CLOCK, clock); } + +int can_get_bittiming_const(const char *name, struct can_bittiming_const *btc) +{ + return get_link(name, GET_BITTIMING_CONST, btc); +} + From 8373c1f17bff1e3898bf69afbc4c46beb9eeb977 Mon Sep 17 00:00:00 2001 From: Luotao Fu Date: Tue, 1 Dec 2009 10:42:23 +0100 Subject: [PATCH 40/88] switch version back to trunk Signed-off-by: Luotao Fu --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 51bfb872..e4e64449 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ(2.59) -AC_INIT([libsocketcan], [0.0.4], [bugs@pengutronix.de]) +AC_INIT([libsocketcan], [trunk], [bugs@pengutronix.de]) AC_CONFIG_HEADERS([include/libsocketcan_config.h]) AC_CONFIG_SRCDIR([src/libsocketcan.c]) AC_CONFIG_MACRO_DIR([config/m4]) From d6747aad3ce1de632c831cd2199d2ec3e5882752 Mon Sep 17 00:00:00 2001 From: Luotao Fu Date: Fri, 4 Dec 2009 15:03:53 +0100 Subject: [PATCH 41/88] update libtool revision Signed-off-by: Luotao Fu --- configure.ac | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index e4e64449..b8ef8252 100644 --- a/configure.ac +++ b/configure.ac @@ -21,9 +21,9 @@ CFLAGS="${CFLAGS} -Wall" # Interfaces changed/added/removed: CURRENT++ REVISION=0 # Interfaces added: AGE++ # Interfaces removed: AGE=0 -LT_CURRENT=2 +LT_CURRENT=3 LT_REVISION=0 -LT_AGE=0 +LT_AGE=1 AC_SUBST(LT_CURRENT) AC_SUBST(LT_REVISION) AC_SUBST(LT_AGE) From f38c3b6d92ddb223b62212bbe0a2e80b5b50731e Mon Sep 17 00:00:00 2001 From: Luotao Fu Date: Fri, 4 Dec 2009 15:05:37 +0100 Subject: [PATCH 42/88] v0.0.5 Signed-off-by: Luotao Fu --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index b8ef8252..38440c61 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ(2.59) -AC_INIT([libsocketcan], [trunk], [bugs@pengutronix.de]) +AC_INIT([libsocketcan], [0.0.5], [bugs@pengutronix.de]) AC_CONFIG_HEADERS([include/libsocketcan_config.h]) AC_CONFIG_SRCDIR([src/libsocketcan.c]) AC_CONFIG_MACRO_DIR([config/m4]) From 7ee625b6f349a1401a2ed87eabe6fcc5e6e4bee1 Mon Sep 17 00:00:00 2001 From: Luotao Fu Date: Fri, 4 Dec 2009 15:07:30 +0100 Subject: [PATCH 43/88] switch version back to trunk Signed-off-by: Luotao Fu --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 38440c61..b8ef8252 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ(2.59) -AC_INIT([libsocketcan], [0.0.5], [bugs@pengutronix.de]) +AC_INIT([libsocketcan], [trunk], [bugs@pengutronix.de]) AC_CONFIG_HEADERS([include/libsocketcan_config.h]) AC_CONFIG_SRCDIR([src/libsocketcan.c]) AC_CONFIG_MACRO_DIR([config/m4]) From 6f0eac7ab9484b4da8ab33e1c01ce0001a0446d3 Mon Sep 17 00:00:00 2001 From: Luotao Fu Date: Mon, 7 Dec 2009 16:31:26 +0100 Subject: [PATCH 44/88] add doxygen documentation Signed-off-by: Luotao Fu --- Documentation/main.dox | 11 + Doxyfile | 1298 ++++++++++++++++++++++++++++++++++++++++ GNUmakefile.am | 7 + include/libsocketcan.h | 21 +- src/libsocketcan.c | 426 ++++++++++++- 5 files changed, 1753 insertions(+), 10 deletions(-) create mode 100644 Documentation/main.dox create mode 100644 Doxyfile diff --git a/Documentation/main.dox b/Documentation/main.dox new file mode 100644 index 00000000..72495d46 --- /dev/null +++ b/Documentation/main.dox @@ -0,0 +1,11 @@ +/** @mainpage libsocketcan + +This is libsocketcan, a userspace library to do some common tasks while dealing +with the socketcan Framework. + +@defgroup extern External API +@defgroup intern Interally used callbacks and structures + +*/ + + diff --git a/Doxyfile b/Doxyfile new file mode 100644 index 00000000..14323be7 --- /dev/null +++ b/Doxyfile @@ -0,0 +1,1298 @@ +# Doxyfile 1.5.3 + +# This file describes the settings to be used by the documentation system +# doxygen (www.doxygen.org) for a project +# +# All text after a hash (#) is considered a comment and will be ignored +# The format is: +# TAG = value [value, ...] +# For lists items can also be appended using: +# TAG += value [value, ...] +# Values that contain spaces should be placed between quotes (" ") + +#--------------------------------------------------------------------------- +# Project related configuration options +#--------------------------------------------------------------------------- + +# This tag specifies the encoding used for all characters in the config file that +# follow. The default is UTF-8 which is also the encoding used for all text before +# the first occurrence of this tag. Doxygen uses libiconv (or the iconv built into +# libc) for the transcoding. See http://www.gnu.org/software/libiconv for the list of +# possible encodings. + +DOXYFILE_ENCODING = UTF-8 + +# The PROJECT_NAME tag is a single word (or a sequence of words surrounded +# by quotes) that should identify the project. + +PROJECT_NAME = libsocketcan + +# The PROJECT_NUMBER tag can be used to enter a project or revision number. +# This could be handy for archiving the generated documentation or +# if some version control system is used. + +PROJECT_NUMBER = v0.0.5 + +# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) +# base path where the generated documentation will be put. +# If a relative path is entered, it will be relative to the location +# where doxygen was started. If left blank the current directory will be used. + +OUTPUT_DIRECTORY = Documentation + +# If the CREATE_SUBDIRS tag is set to YES, then doxygen will create +# 4096 sub-directories (in 2 levels) under the output directory of each output +# format and will distribute the generated files over these directories. +# Enabling this option can be useful when feeding doxygen a huge amount of +# source files, where putting all generated files in the same directory would +# otherwise cause performance problems for the file system. + +CREATE_SUBDIRS = NO + +# The OUTPUT_LANGUAGE tag is used to specify the language in which all +# documentation generated by doxygen is written. Doxygen will use this +# information to generate all constant output in the proper language. +# The default language is English, other supported languages are: +# Afrikaans, Arabic, Brazilian, Catalan, Chinese, Chinese-Traditional, +# Croatian, Czech, Danish, Dutch, Finnish, French, German, Greek, Hungarian, +# Italian, Japanese, Japanese-en (Japanese with English messages), Korean, +# Korean-en, Lithuanian, Norwegian, Polish, Portuguese, Romanian, Russian, +# Serbian, Slovak, Slovene, Spanish, Swedish, and Ukrainian. + +OUTPUT_LANGUAGE = English + +# If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will +# include brief member descriptions after the members that are listed in +# the file and class documentation (similar to JavaDoc). +# Set to NO to disable this. + +BRIEF_MEMBER_DESC = YES + +# If the REPEAT_BRIEF tag is set to YES (the default) Doxygen will prepend +# the brief description of a member or function before the detailed description. +# Note: if both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the +# brief descriptions will be completely suppressed. + +REPEAT_BRIEF = YES + +# This tag implements a quasi-intelligent brief description abbreviator +# that is used to form the text in various listings. Each string +# in this list, if found as the leading text of the brief description, will be +# stripped from the text and the result after processing the whole list, is +# used as the annotated text. Otherwise, the brief description is used as-is. +# If left blank, the following values are used ("$name" is automatically +# replaced with the name of the entity): "The $name class" "The $name widget" +# "The $name file" "is" "provides" "specifies" "contains" +# "represents" "a" "an" "the" + +ABBREVIATE_BRIEF = + +# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then +# Doxygen will generate a detailed section even if there is only a brief +# description. + +ALWAYS_DETAILED_SEC = NO + +# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all +# inherited members of a class in the documentation of that class as if those +# members were ordinary class members. Constructors, destructors and assignment +# operators of the base classes will not be shown. + +INLINE_INHERITED_MEMB = NO + +# If the FULL_PATH_NAMES tag is set to YES then Doxygen will prepend the full +# path before files name in the file list and in the header files. If set +# to NO the shortest path that makes the file name unique will be used. + +FULL_PATH_NAMES = YES + +# If the FULL_PATH_NAMES tag is set to YES then the STRIP_FROM_PATH tag +# can be used to strip a user-defined part of the path. Stripping is +# only done if one of the specified strings matches the left-hand part of +# the path. The tag can be used to show relative paths in the file list. +# If left blank the directory from which doxygen is run is used as the +# path to strip. + +STRIP_FROM_PATH = + +# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of +# the path mentioned in the documentation of a class, which tells +# the reader which header file to include in order to use a class. +# If left blank only the name of the header file containing the class +# definition is used. Otherwise one should specify the include paths that +# are normally passed to the compiler using the -I flag. + +STRIP_FROM_INC_PATH = + +# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter +# (but less readable) file names. This can be useful is your file systems +# doesn't support long names like on DOS, Mac, or CD-ROM. + +SHORT_NAMES = NO + +# If the JAVADOC_AUTOBRIEF tag is set to YES then Doxygen +# will interpret the first line (until the first dot) of a JavaDoc-style +# comment as the brief description. If set to NO, the JavaDoc +# comments will behave just like regular Qt-style comments +# (thus requiring an explicit @brief command for a brief description.) + +JAVADOC_AUTOBRIEF = YES + +# If the QT_AUTOBRIEF tag is set to YES then Doxygen will +# interpret the first line (until the first dot) of a Qt-style +# comment as the brief description. If set to NO, the comments +# will behave just like regular Qt-style comments (thus requiring +# an explicit \brief command for a brief description.) + +QT_AUTOBRIEF = YES + +# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make Doxygen +# treat a multi-line C++ special comment block (i.e. a block of //! or /// +# comments) as a brief description. This used to be the default behaviour. +# The new default is to treat a multi-line C++ comment block as a detailed +# description. Set this tag to YES if you prefer the old behaviour instead. + +MULTILINE_CPP_IS_BRIEF = NO + +# If the DETAILS_AT_TOP tag is set to YES then Doxygen +# will output the detailed description near the top, like JavaDoc. +# If set to NO, the detailed description appears after the member +# documentation. + +DETAILS_AT_TOP = YES + +# If the INHERIT_DOCS tag is set to YES (the default) then an undocumented +# member inherits the documentation from any documented member that it +# re-implements. + +INHERIT_DOCS = NO + +# If the SEPARATE_MEMBER_PAGES tag is set to YES, then doxygen will produce +# a new page for each member. If set to NO, the documentation of a member will +# be part of the file/class/namespace that contains it. + +SEPARATE_MEMBER_PAGES = NO + +# The TAB_SIZE tag can be used to set the number of spaces in a tab. +# Doxygen uses this value to replace tabs by spaces in code fragments. + +TAB_SIZE = 8 + +# This tag can be used to specify a number of aliases that acts +# as commands in the documentation. An alias has the form "name=value". +# For example adding "sideeffect=\par Side Effects:\n" will allow you to +# put the command \sideeffect (or @sideeffect) in the documentation, which +# will result in a user-defined paragraph with heading "Side Effects:". +# You can put \n's in the value part of an alias to insert newlines. + +ALIASES = + +# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C +# sources only. Doxygen will then generate output that is more tailored for C. +# For instance, some of the names that are used will be different. The list +# of all members will be omitted, etc. + +OPTIMIZE_OUTPUT_FOR_C = YES + +# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java +# sources only. Doxygen will then generate output that is more tailored for Java. +# For instance, namespaces will be presented as packages, qualified scopes +# will look different, etc. + +OPTIMIZE_OUTPUT_JAVA = NO + +# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want to +# include (a tag file for) the STL sources as input, then you should +# set this tag to YES in order to let doxygen match functions declarations and +# definitions whose arguments contain STL classes (e.g. func(std::string); v.s. +# func(std::string) {}). This also make the inheritance and collaboration +# diagrams that involve STL classes more complete and accurate. + +BUILTIN_STL_SUPPORT = NO + +# If you use Microsoft's C++/CLI language, you should set this option to YES to +# enable parsing support. + +CPP_CLI_SUPPORT = NO + +# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC +# tag is set to YES, then doxygen will reuse the documentation of the first +# member in the group (if any) for the other members of the group. By default +# all members of a group must be documented explicitly. + +DISTRIBUTE_GROUP_DOC = NO + +# Set the SUBGROUPING tag to YES (the default) to allow class member groups of +# the same type (for instance a group of public functions) to be put as a +# subgroup of that type (e.g. under the Public Functions section). Set it to +# NO to prevent subgrouping. Alternatively, this can be done per class using +# the \nosubgrouping command. + +SUBGROUPING = YES + +#--------------------------------------------------------------------------- +# Build related configuration options +#--------------------------------------------------------------------------- + +# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in +# documentation are documented, even if no documentation was available. +# Private class members and static file members will be hidden unless +# the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES + +EXTRACT_ALL = NO + +# If the EXTRACT_PRIVATE tag is set to YES all private members of a class +# will be included in the documentation. + +EXTRACT_PRIVATE = NO + +# If the EXTRACT_STATIC tag is set to YES all static members of a file +# will be included in the documentation. + +EXTRACT_STATIC = YES + +# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs) +# defined locally in source files will be included in the documentation. +# If set to NO only classes defined in header files are included. + +EXTRACT_LOCAL_CLASSES = NO + +# This flag is only useful for Objective-C code. When set to YES local +# methods, which are defined in the implementation section but not in +# the interface are included in the documentation. +# If set to NO (the default) only methods in the interface are included. + +EXTRACT_LOCAL_METHODS = NO + +# If this flag is set to YES, the members of anonymous namespaces will be extracted +# and appear in the documentation as a namespace called 'anonymous_namespace{file}', +# where file will be replaced with the base name of the file that contains the anonymous +# namespace. By default anonymous namespace are hidden. + +EXTRACT_ANON_NSPACES = NO + +# If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all +# undocumented members of documented classes, files or namespaces. +# If set to NO (the default) these members will be included in the +# various overviews, but no documentation section is generated. +# This option has no effect if EXTRACT_ALL is enabled. + +HIDE_UNDOC_MEMBERS = NO + +# If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all +# undocumented classes that are normally visible in the class hierarchy. +# If set to NO (the default) these classes will be included in the various +# overviews. This option has no effect if EXTRACT_ALL is enabled. + +HIDE_UNDOC_CLASSES = NO + +# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, Doxygen will hide all +# friend (class|struct|union) declarations. +# If set to NO (the default) these declarations will be included in the +# documentation. + +HIDE_FRIEND_COMPOUNDS = NO + +# If the HIDE_IN_BODY_DOCS tag is set to YES, Doxygen will hide any +# documentation blocks found inside the body of a function. +# If set to NO (the default) these blocks will be appended to the +# function's detailed documentation block. + +HIDE_IN_BODY_DOCS = NO + +# The INTERNAL_DOCS tag determines if documentation +# that is typed after a \internal command is included. If the tag is set +# to NO (the default) then the documentation will be excluded. +# Set it to YES to include the internal documentation. + +INTERNAL_DOCS = NO + +# If the CASE_SENSE_NAMES tag is set to NO then Doxygen will only generate +# file names in lower-case letters. If set to YES upper-case letters are also +# allowed. This is useful if you have classes or files whose names only differ +# in case and if your file system supports case sensitive file names. Windows +# and Mac users are advised to set this option to NO. + +CASE_SENSE_NAMES = YES + +# If the HIDE_SCOPE_NAMES tag is set to NO (the default) then Doxygen +# will show members with their full class and namespace scopes in the +# documentation. If set to YES the scope will be hidden. + +HIDE_SCOPE_NAMES = NO + +# If the SHOW_INCLUDE_FILES tag is set to YES (the default) then Doxygen +# will put a list of the files that are included by a file in the documentation +# of that file. + +SHOW_INCLUDE_FILES = YES + +# If the INLINE_INFO tag is set to YES (the default) then a tag [inline] +# is inserted in the documentation for inline members. + +INLINE_INFO = YES + +# If the SORT_MEMBER_DOCS tag is set to YES (the default) then doxygen +# will sort the (detailed) documentation of file and class members +# alphabetically by member name. If set to NO the members will appear in +# declaration order. + +SORT_MEMBER_DOCS = YES + +# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the +# brief documentation of file, namespace and class members alphabetically +# by member name. If set to NO (the default) the members will appear in +# declaration order. + +SORT_BRIEF_DOCS = NO + +# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be +# sorted by fully-qualified names, including namespaces. If set to +# NO (the default), the class list will be sorted only by class name, +# not including the namespace part. +# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES. +# Note: This option applies only to the class list, not to the +# alphabetical list. + +SORT_BY_SCOPE_NAME = NO + +# The GENERATE_TODOLIST tag can be used to enable (YES) or +# disable (NO) the todo list. This list is created by putting \todo +# commands in the documentation. + +GENERATE_TODOLIST = YES + +# The GENERATE_TESTLIST tag can be used to enable (YES) or +# disable (NO) the test list. This list is created by putting \test +# commands in the documentation. + +GENERATE_TESTLIST = YES + +# The GENERATE_BUGLIST tag can be used to enable (YES) or +# disable (NO) the bug list. This list is created by putting \bug +# commands in the documentation. + +GENERATE_BUGLIST = YES + +# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or +# disable (NO) the deprecated list. This list is created by putting +# \deprecated commands in the documentation. + +GENERATE_DEPRECATEDLIST= YES + +# The ENABLED_SECTIONS tag can be used to enable conditional +# documentation sections, marked by \if sectionname ... \endif. + +ENABLED_SECTIONS = + +# The MAX_INITIALIZER_LINES tag determines the maximum number of lines +# the initial value of a variable or define consists of for it to appear in +# the documentation. If the initializer consists of more lines than specified +# here it will be hidden. Use a value of 0 to hide initializers completely. +# The appearance of the initializer of individual variables and defines in the +# documentation can be controlled using \showinitializer or \hideinitializer +# command in the documentation regardless of this setting. + +MAX_INITIALIZER_LINES = 30 + +# Set the SHOW_USED_FILES tag to NO to disable the list of files generated +# at the bottom of the documentation of classes and structs. If set to YES the +# list will mention the files that were used to generate the documentation. + +SHOW_USED_FILES = YES + +# If the sources in your project are distributed over multiple directories +# then setting the SHOW_DIRECTORIES tag to YES will show the directory hierarchy +# in the documentation. The default is NO. + +SHOW_DIRECTORIES = NO + +# The FILE_VERSION_FILTER tag can be used to specify a program or script that +# doxygen should invoke to get the current version for each file (typically from the +# version control system). Doxygen will invoke the program by executing (via +# popen()) the command , where is the value of +# the FILE_VERSION_FILTER tag, and is the name of an input file +# provided by doxygen. Whatever the program writes to standard output +# is used as the file version. See the manual for examples. + +FILE_VERSION_FILTER = + +#--------------------------------------------------------------------------- +# configuration options related to warning and progress messages +#--------------------------------------------------------------------------- + +# The QUIET tag can be used to turn on/off the messages that are generated +# by doxygen. Possible values are YES and NO. If left blank NO is used. + +QUIET = YES + +# The WARNINGS tag can be used to turn on/off the warning messages that are +# generated by doxygen. Possible values are YES and NO. If left blank +# NO is used. + +WARNINGS = YES + +# If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate warnings +# for undocumented members. If EXTRACT_ALL is set to YES then this flag will +# automatically be disabled. + +WARN_IF_UNDOCUMENTED = NO + +# If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings for +# potential errors in the documentation, such as not documenting some +# parameters in a documented function, or documenting parameters that +# don't exist or using markup commands wrongly. + +WARN_IF_DOC_ERROR = YES + +# This WARN_NO_PARAMDOC option can be abled to get warnings for +# functions that are documented, but have no documentation for their parameters +# or return value. If set to NO (the default) doxygen will only warn about +# wrong or incomplete parameter documentation, but not about the absence of +# documentation. + +WARN_NO_PARAMDOC = NO + +# The WARN_FORMAT tag determines the format of the warning messages that +# doxygen can produce. The string should contain the $file, $line, and $text +# tags, which will be replaced by the file and line number from which the +# warning originated and the warning text. Optionally the format may contain +# $version, which will be replaced by the version of the file (if it could +# be obtained via FILE_VERSION_FILTER) + +WARN_FORMAT = "$file:$line: $text " + +# The WARN_LOGFILE tag can be used to specify a file to which warning +# and error messages should be written. If left blank the output is written +# to stderr. + +WARN_LOGFILE = + +#--------------------------------------------------------------------------- +# configuration options related to the input files +#--------------------------------------------------------------------------- + +# The INPUT tag can be used to specify the files and/or directories that contain +# documented source files. You may enter file names like "myfile.cpp" or +# directories like "/usr/src/myproject". Separate the files or directories +# with spaces. + +INPUT = include \ + src \ + Documentation + +# This tag can be used to specify the character encoding of the source files that +# doxygen parses. Internally doxygen uses the UTF-8 encoding, which is also the default +# input encoding. Doxygen uses libiconv (or the iconv built into libc) for the transcoding. +# See http://www.gnu.org/software/libiconv for the list of possible encodings. + +INPUT_ENCODING = UTF-8 + +# If the value of the INPUT tag contains directories, you can use the +# FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp +# and *.h) to filter out the source-files in the directories. If left +# blank the following patterns are tested: +# *.c *.cc *.cxx *.cpp *.c++ *.java *.ii *.ixx *.ipp *.i++ *.inl *.h *.hh *.hxx +# *.hpp *.h++ *.idl *.odl *.cs *.php *.php3 *.inc *.m *.mm *.py + +FILE_PATTERNS = *.c \ + *.h \ + *.dox + +# The RECURSIVE tag can be used to turn specify whether or not subdirectories +# should be searched for input files as well. Possible values are YES and NO. +# If left blank NO is used. + +RECURSIVE = YES + +# The EXCLUDE tag can be used to specify files and/or directories that should +# excluded from the INPUT source files. This way you can easily exclude a +# subdirectory from a directory tree whose root is specified with the INPUT tag. + +EXCLUDE = + +# The EXCLUDE_SYMLINKS tag can be used select whether or not files or +# directories that are symbolic links (a Unix filesystem feature) are excluded +# from the input. + +EXCLUDE_SYMLINKS = YES + +# If the value of the INPUT tag contains directories, you can use the +# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude +# certain files from those directories. Note that the wildcards are matched +# against the file with absolute path, so to exclude all test directories +# for example use the pattern */test/* + +EXCLUDE_PATTERNS = + +# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names +# (namespaces, classes, functions, etc.) that should be excluded from the output. +# The symbol name can be a fully qualified name, a word, or if the wildcard * is used, +# a substring. Examples: ANamespace, AClass, AClass::ANamespace, ANamespace::*Test + +EXCLUDE_SYMBOLS = + +# The EXAMPLE_PATH tag can be used to specify one or more files or +# directories that contain example code fragments that are included (see +# the \include command). + +# EXAMPLE_PATH = Documentation/examples/ + +# If the value of the EXAMPLE_PATH tag contains directories, you can use the +# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp +# and *.h) to filter out the source-files in the directories. If left +# blank all files are included. + +EXAMPLE_PATTERNS = + +# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be +# searched for input files to be used with the \include or \dontinclude +# commands irrespective of the value of the RECURSIVE tag. +# Possible values are YES and NO. If left blank NO is used. + +EXAMPLE_RECURSIVE = NO + +# The IMAGE_PATH tag can be used to specify one or more files or +# directories that contain image that are included in the documentation (see +# the \image command). + +# IMAGE_PATH = Documentation/images/ + +# The INPUT_FILTER tag can be used to specify a program that doxygen should +# invoke to filter for each input file. Doxygen will invoke the filter program +# by executing (via popen()) the command , where +# is the value of the INPUT_FILTER tag, and is the name of an +# input file. Doxygen will then use the output that the filter program writes +# to standard output. If FILTER_PATTERNS is specified, this tag will be +# ignored. + +INPUT_FILTER = + +# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern +# basis. Doxygen will compare the file name with each pattern and apply the +# filter if there is a match. The filters are a list of the form: +# pattern=filter (like *.cpp=my_cpp_filter). See INPUT_FILTER for further +# info on how filters are used. If FILTER_PATTERNS is empty, INPUT_FILTER +# is applied to all files. + +FILTER_PATTERNS = + +# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using +# INPUT_FILTER) will be used to filter the input files when producing source +# files to browse (i.e. when SOURCE_BROWSER is set to YES). + +FILTER_SOURCE_FILES = NO + +#--------------------------------------------------------------------------- +# configuration options related to source browsing +#--------------------------------------------------------------------------- + +# If the SOURCE_BROWSER tag is set to YES then a list of source files will +# be generated. Documented entities will be cross-referenced with these sources. +# Note: To get rid of all source code in the generated output, make sure also +# VERBATIM_HEADERS is set to NO. If you have enabled CALL_GRAPH or CALLER_GRAPH +# then you must also enable this option. If you don't then doxygen will produce +# a warning and turn it on anyway + +SOURCE_BROWSER = NO + +# Setting the INLINE_SOURCES tag to YES will include the body +# of functions and classes directly in the documentation. + +INLINE_SOURCES = NO + +# Setting the STRIP_CODE_COMMENTS tag to YES (the default) will instruct +# doxygen to hide any special comment blocks from generated source code +# fragments. Normal C and C++ comments will always remain visible. + +STRIP_CODE_COMMENTS = YES + +# If the REFERENCED_BY_RELATION tag is set to YES (the default) +# then for each documented function all documented +# functions referencing it will be listed. + +REFERENCED_BY_RELATION = YES + +# If the REFERENCES_RELATION tag is set to YES (the default) +# then for each documented function all documented entities +# called/used by that function will be listed. + +REFERENCES_RELATION = YES + +# If the REFERENCES_LINK_SOURCE tag is set to YES (the default) +# and SOURCE_BROWSER tag is set to YES, then the hyperlinks from +# functions in REFERENCES_RELATION and REFERENCED_BY_RELATION lists will +# link to the source code. Otherwise they will link to the documentstion. + +REFERENCES_LINK_SOURCE = YES + +# If the USE_HTAGS tag is set to YES then the references to source code +# will point to the HTML generated by the htags(1) tool instead of doxygen +# built-in source browser. The htags tool is part of GNU's global source +# tagging system (see http://www.gnu.org/software/global/global.html). You +# will need version 4.8.6 or higher. + +USE_HTAGS = NO + +# If the VERBATIM_HEADERS tag is set to YES (the default) then Doxygen +# will generate a verbatim copy of the header file for each class for +# which an include is specified. Set to NO to disable this. + +VERBATIM_HEADERS = NO + +#--------------------------------------------------------------------------- +# configuration options related to the alphabetical class index +#--------------------------------------------------------------------------- + +# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index +# of all compounds will be generated. Enable this if the project +# contains a lot of classes, structs, unions or interfaces. + +ALPHABETICAL_INDEX = YES + +# If the alphabetical index is enabled (see ALPHABETICAL_INDEX) then +# the COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns +# in which this list will be split (can be a number in the range [1..20]) + +COLS_IN_ALPHA_INDEX = 5 + +# In case all classes in a project start with a common prefix, all +# classes will be put under the same header in the alphabetical index. +# The IGNORE_PREFIX tag can be used to specify one or more prefixes that +# should be ignored while generating the index headers. + +IGNORE_PREFIX = + +#--------------------------------------------------------------------------- +# configuration options related to the HTML output +#--------------------------------------------------------------------------- + +# If the GENERATE_HTML tag is set to YES (the default) Doxygen will +# generate HTML output. + +GENERATE_HTML = YES + +# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `html' will be used as the default path. + +HTML_OUTPUT = html + +# The HTML_FILE_EXTENSION tag can be used to specify the file extension for +# each generated HTML page (for example: .htm,.php,.asp). If it is left blank +# doxygen will generate files with .html extension. + +HTML_FILE_EXTENSION = .html + +# The HTML_HEADER tag can be used to specify a personal HTML header for +# each generated HTML page. If it is left blank doxygen will generate a +# standard header. + +HTML_HEADER = + +# The HTML_FOOTER tag can be used to specify a personal HTML footer for +# each generated HTML page. If it is left blank doxygen will generate a +# standard footer. + +HTML_FOOTER = + +# The HTML_STYLESHEET tag can be used to specify a user-defined cascading +# style sheet that is used by each HTML page. It can be used to +# fine-tune the look of the HTML output. If the tag is left blank doxygen +# will generate a default style sheet. Note that doxygen will try to copy +# the style sheet file to the HTML output directory, so don't put your own +# stylesheet in the HTML output directory as well, or it will be erased! + +HTML_STYLESHEET = + +# If the HTML_ALIGN_MEMBERS tag is set to YES, the members of classes, +# files or namespaces will be aligned in HTML using tables. If set to +# NO a bullet list will be used. + +HTML_ALIGN_MEMBERS = YES + +# If the GENERATE_HTMLHELP tag is set to YES, additional index files +# will be generated that can be used as input for tools like the +# Microsoft HTML help workshop to generate a compressed HTML help file (.chm) +# of the generated HTML documentation. + +GENERATE_HTMLHELP = NO + +# If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML +# documentation will contain sections that can be hidden and shown after the +# page has loaded. For this to work a browser that supports +# JavaScript and DHTML is required (for instance Mozilla 1.0+, Firefox +# Netscape 6.0+, Internet explorer 5.0+, Konqueror, or Safari). + +HTML_DYNAMIC_SECTIONS = NO + +# If the GENERATE_HTMLHELP tag is set to YES, the CHM_FILE tag can +# be used to specify the file name of the resulting .chm file. You +# can add a path in front of the file if the result should not be +# written to the html output directory. + +CHM_FILE = + +# If the GENERATE_HTMLHELP tag is set to YES, the HHC_LOCATION tag can +# be used to specify the location (absolute path including file name) of +# the HTML help compiler (hhc.exe). If non-empty doxygen will try to run +# the HTML help compiler on the generated index.hhp. + +HHC_LOCATION = + +# If the GENERATE_HTMLHELP tag is set to YES, the GENERATE_CHI flag +# controls if a separate .chi index file is generated (YES) or that +# it should be included in the master .chm file (NO). + +GENERATE_CHI = NO + +# If the GENERATE_HTMLHELP tag is set to YES, the BINARY_TOC flag +# controls whether a binary table of contents is generated (YES) or a +# normal table of contents (NO) in the .chm file. + +BINARY_TOC = NO + +# The TOC_EXPAND flag can be set to YES to add extra items for group members +# to the contents of the HTML help documentation and to the tree view. + +TOC_EXPAND = NO + +# The DISABLE_INDEX tag can be used to turn on/off the condensed index at +# top of each HTML page. The value NO (the default) enables the index and +# the value YES disables it. + +DISABLE_INDEX = YES + +# This tag can be used to set the number of enum values (range [1..20]) +# that doxygen will group on one line in the generated HTML documentation. + +ENUM_VALUES_PER_LINE = 4 + +# If the GENERATE_TREEVIEW tag is set to YES, a side panel will be +# generated containing a tree-like index structure (just like the one that +# is generated for HTML Help). For this to work a browser that supports +# JavaScript, DHTML, CSS and frames is required (for instance Mozilla 1.0+, +# Netscape 6.0+, Internet explorer 5.0+, or Konqueror). Windows users are +# probably better off using the HTML help feature. + +GENERATE_TREEVIEW = YES + +# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be +# used to set the initial width (in pixels) of the frame in which the tree +# is shown. + +TREEVIEW_WIDTH = 250 + +#--------------------------------------------------------------------------- +# configuration options related to the LaTeX output +#--------------------------------------------------------------------------- + +# If the GENERATE_LATEX tag is set to YES (the default) Doxygen will +# generate Latex output. + +GENERATE_LATEX = NO + +# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `latex' will be used as the default path. + +LATEX_OUTPUT = latex + +# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be +# invoked. If left blank `latex' will be used as the default command name. + +LATEX_CMD_NAME = latex + +# The MAKEINDEX_CMD_NAME tag can be used to specify the command name to +# generate index for LaTeX. If left blank `makeindex' will be used as the +# default command name. + +MAKEINDEX_CMD_NAME = makeindex + +# If the COMPACT_LATEX tag is set to YES Doxygen generates more compact +# LaTeX documents. This may be useful for small projects and may help to +# save some trees in general. + +COMPACT_LATEX = NO + +# The PAPER_TYPE tag can be used to set the paper type that is used +# by the printer. Possible values are: a4, a4wide, letter, legal and +# executive. If left blank a4wide will be used. + +PAPER_TYPE = a4wide + +# The EXTRA_PACKAGES tag can be to specify one or more names of LaTeX +# packages that should be included in the LaTeX output. + +EXTRA_PACKAGES = + +# The LATEX_HEADER tag can be used to specify a personal LaTeX header for +# the generated latex document. The header should contain everything until +# the first chapter. If it is left blank doxygen will generate a +# standard header. Notice: only use this tag if you know what you are doing! + +LATEX_HEADER = + +# If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated +# is prepared for conversion to pdf (using ps2pdf). The pdf file will +# contain links (just like the HTML output) instead of page references +# This makes the output suitable for online browsing using a pdf viewer. + +PDF_HYPERLINKS = NO + +# If the USE_PDFLATEX tag is set to YES, pdflatex will be used instead of +# plain latex in the generated Makefile. Set this option to YES to get a +# higher quality PDF documentation. + +USE_PDFLATEX = NO + +# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \\batchmode. +# command to the generated LaTeX files. This will instruct LaTeX to keep +# running if errors occur, instead of asking the user for help. +# This option is also used when generating formulas in HTML. + +LATEX_BATCHMODE = NO + +# If LATEX_HIDE_INDICES is set to YES then doxygen will not +# include the index chapters (such as File Index, Compound Index, etc.) +# in the output. + +LATEX_HIDE_INDICES = NO + +#--------------------------------------------------------------------------- +# configuration options related to the RTF output +#--------------------------------------------------------------------------- + +# If the GENERATE_RTF tag is set to YES Doxygen will generate RTF output +# The RTF output is optimized for Word 97 and may not look very pretty with +# other RTF readers or editors. + +GENERATE_RTF = NO + +# The RTF_OUTPUT tag is used to specify where the RTF docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `rtf' will be used as the default path. + +RTF_OUTPUT = rtf + +# If the COMPACT_RTF tag is set to YES Doxygen generates more compact +# RTF documents. This may be useful for small projects and may help to +# save some trees in general. + +COMPACT_RTF = NO + +# If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated +# will contain hyperlink fields. The RTF file will +# contain links (just like the HTML output) instead of page references. +# This makes the output suitable for online browsing using WORD or other +# programs which support those fields. +# Note: wordpad (write) and others do not support links. + +RTF_HYPERLINKS = NO + +# Load stylesheet definitions from file. Syntax is similar to doxygen's +# config file, i.e. a series of assignments. You only have to provide +# replacements, missing definitions are set to their default value. + +RTF_STYLESHEET_FILE = + +# Set optional variables used in the generation of an rtf document. +# Syntax is similar to doxygen's config file. + +RTF_EXTENSIONS_FILE = + +#--------------------------------------------------------------------------- +# configuration options related to the man page output +#--------------------------------------------------------------------------- + +# If the GENERATE_MAN tag is set to YES (the default) Doxygen will +# generate man pages + +GENERATE_MAN = NO + +# The MAN_OUTPUT tag is used to specify where the man pages will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `man' will be used as the default path. + +MAN_OUTPUT = man + +# The MAN_EXTENSION tag determines the extension that is added to +# the generated man pages (default is the subroutine's section .3) + +MAN_EXTENSION = .3 + +# If the MAN_LINKS tag is set to YES and Doxygen generates man output, +# then it will generate one additional man file for each entity +# documented in the real man page(s). These additional files +# only source the real man page, but without them the man command +# would be unable to find the correct page. The default is NO. + +MAN_LINKS = NO + +#--------------------------------------------------------------------------- +# configuration options related to the XML output +#--------------------------------------------------------------------------- + +# If the GENERATE_XML tag is set to YES Doxygen will +# generate an XML file that captures the structure of +# the code including all documentation. + +GENERATE_XML = NO + +# The XML_OUTPUT tag is used to specify where the XML pages will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `xml' will be used as the default path. + +XML_OUTPUT = xml + +# The XML_SCHEMA tag can be used to specify an XML schema, +# which can be used by a validating XML parser to check the +# syntax of the XML files. + +XML_SCHEMA = + +# The XML_DTD tag can be used to specify an XML DTD, +# which can be used by a validating XML parser to check the +# syntax of the XML files. + +XML_DTD = + +# If the XML_PROGRAMLISTING tag is set to YES Doxygen will +# dump the program listings (including syntax highlighting +# and cross-referencing information) to the XML output. Note that +# enabling this will significantly increase the size of the XML output. + +XML_PROGRAMLISTING = YES + +#--------------------------------------------------------------------------- +# configuration options for the AutoGen Definitions output +#--------------------------------------------------------------------------- + +# If the GENERATE_AUTOGEN_DEF tag is set to YES Doxygen will +# generate an AutoGen Definitions (see autogen.sf.net) file +# that captures the structure of the code including all +# documentation. Note that this feature is still experimental +# and incomplete at the moment. + +GENERATE_AUTOGEN_DEF = NO + +#--------------------------------------------------------------------------- +# configuration options related to the Perl module output +#--------------------------------------------------------------------------- + +# If the GENERATE_PERLMOD tag is set to YES Doxygen will +# generate a Perl module file that captures the structure of +# the code including all documentation. Note that this +# feature is still experimental and incomplete at the +# moment. + +GENERATE_PERLMOD = NO + +# If the PERLMOD_LATEX tag is set to YES Doxygen will generate +# the necessary Makefile rules, Perl scripts and LaTeX code to be able +# to generate PDF and DVI output from the Perl module output. + +PERLMOD_LATEX = NO + +# If the PERLMOD_PRETTY tag is set to YES the Perl module output will be +# nicely formatted so it can be parsed by a human reader. This is useful +# if you want to understand what is going on. On the other hand, if this +# tag is set to NO the size of the Perl module output will be much smaller +# and Perl will parse it just the same. + +PERLMOD_PRETTY = YES + +# The names of the make variables in the generated doxyrules.make file +# are prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX. +# This is useful so different doxyrules.make files included by the same +# Makefile don't overwrite each other's variables. + +PERLMOD_MAKEVAR_PREFIX = + +#--------------------------------------------------------------------------- +# Configuration options related to the preprocessor +#--------------------------------------------------------------------------- + +# If the ENABLE_PREPROCESSING tag is set to YES (the default) Doxygen will +# evaluate all C-preprocessor directives found in the sources and include +# files. + +ENABLE_PREPROCESSING = YES + +# If the MACRO_EXPANSION tag is set to YES Doxygen will expand all macro +# names in the source code. If set to NO (the default) only conditional +# compilation will be performed. Macro expansion can be done in a controlled +# way by setting EXPAND_ONLY_PREDEF to YES. + +MACRO_EXPANSION = NO + +# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES +# then the macro expansion is limited to the macros specified with the +# PREDEFINED and EXPAND_AS_DEFINED tags. + +EXPAND_ONLY_PREDEF = NO + +# If the SEARCH_INCLUDES tag is set to YES (the default) the includes files +# in the INCLUDE_PATH (see below) will be search if a #include is found. + +SEARCH_INCLUDES = YES + +# The INCLUDE_PATH tag can be used to specify one or more directories that +# contain include files that are not input files but should be processed by +# the preprocessor. + +INCLUDE_PATH = + +# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard +# patterns (like *.h and *.hpp) to filter out the header-files in the +# directories. If left blank, the patterns specified with FILE_PATTERNS will +# be used. + +INCLUDE_FILE_PATTERNS = + +# The PREDEFINED tag can be used to specify one or more macro names that +# are defined before the preprocessor is started (similar to the -D option of +# gcc). The argument of the tag is a list of macros of the form: name +# or name=definition (no spaces). If the definition and the = are +# omitted =1 is assumed. To prevent a macro definition from being +# undefined via #undef or recursively expanded use the := operator +# instead of the = operator. + +PREDEFINED = + +# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then +# this tag can be used to specify a list of macro names that should be expanded. +# The macro definition that is found in the sources will be used. +# Use the PREDEFINED tag if you want to use a different macro definition. + +EXPAND_AS_DEFINED = + +# If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then +# doxygen's preprocessor will remove all function-like macros that are alone +# on a line, have an all uppercase name, and do not end with a semicolon. Such +# function macros are typically used for boiler-plate code, and will confuse +# the parser if not removed. + +SKIP_FUNCTION_MACROS = YES + +#--------------------------------------------------------------------------- +# Configuration::additions related to external references +#--------------------------------------------------------------------------- + +# The TAGFILES option can be used to specify one or more tagfiles. +# Optionally an initial location of the external documentation +# can be added for each tagfile. The format of a tag file without +# this location is as follows: +# TAGFILES = file1 file2 ... +# Adding location for the tag files is done as follows: +# TAGFILES = file1=loc1 "file2 = loc2" ... +# where "loc1" and "loc2" can be relative or absolute paths or +# URLs. If a location is present for each tag, the installdox tool +# does not have to be run to correct the links. +# Note that each tag file must have a unique name +# (where the name does NOT include the path) +# If a tag file is not located in the directory in which doxygen +# is run, you must also specify the path to the tagfile here. + +TAGFILES = + +# When a file name is specified after GENERATE_TAGFILE, doxygen will create +# a tag file that is based on the input files it reads. + +GENERATE_TAGFILE = + +# If the ALLEXTERNALS tag is set to YES all external classes will be listed +# in the class index. If set to NO only the inherited external classes +# will be listed. + +ALLEXTERNALS = NO + +# If the EXTERNAL_GROUPS tag is set to YES all external groups will be listed +# in the modules index. If set to NO, only the current project's groups will +# be listed. + +EXTERNAL_GROUPS = YES + +# The PERL_PATH should be the absolute path and name of the perl script +# interpreter (i.e. the result of `which perl'). + +PERL_PATH = /usr/bin/perl + +#--------------------------------------------------------------------------- +# Configuration options related to the dot tool +#--------------------------------------------------------------------------- + +# If the CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will +# generate a inheritance diagram (in HTML, RTF and LaTeX) for classes with base +# or super classes. Setting the tag to NO turns the diagrams off. Note that +# this option is superseded by the HAVE_DOT option below. This is only a +# fallback. It is recommended to install and use dot, since it yields more +# powerful graphs. + +CLASS_DIAGRAMS = YES + +# You can define message sequence charts within doxygen comments using the \msc +# command. Doxygen will then run the mscgen tool (see http://www.mcternan.me.uk/mscgen/) to +# produce the chart and insert it in the documentation. The MSCGEN_PATH tag allows you to +# specify the directory where the mscgen tool resides. If left empty the tool is assumed to +# be found in the default search path. + +MSCGEN_PATH = + +# If set to YES, the inheritance and collaboration graphs will hide +# inheritance and usage relations if the target is undocumented +# or is not a class. + +HIDE_UNDOC_RELATIONS = YES + +# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is +# available from the path. This tool is part of Graphviz, a graph visualization +# toolkit from AT&T and Lucent Bell Labs. The other options in this section +# have no effect if this option is set to NO (the default) + +HAVE_DOT = YES + +# If the CLASS_GRAPH and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for each documented class showing the direct and +# indirect inheritance relations. Setting this tag to YES will force the +# the CLASS_DIAGRAMS tag to NO. + +CLASS_GRAPH = YES + +# If the COLLABORATION_GRAPH and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for each documented class showing the direct and +# indirect implementation dependencies (inheritance, containment, and +# class references variables) of the class with other documented classes. + +COLLABORATION_GRAPH = YES + +# If the GROUP_GRAPHS and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for groups, showing the direct groups dependencies + +GROUP_GRAPHS = YES + +# If the UML_LOOK tag is set to YES doxygen will generate inheritance and +# collaboration diagrams in a style similar to the OMG's Unified Modeling +# Language. + +UML_LOOK = NO + +# If set to YES, the inheritance and collaboration graphs will show the +# relations between templates and their instances. + +TEMPLATE_RELATIONS = NO + +# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDE_GRAPH, and HAVE_DOT +# tags are set to YES then doxygen will generate a graph for each documented +# file showing the direct and indirect include dependencies of the file with +# other documented files. + +INCLUDE_GRAPH = YES + +# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDED_BY_GRAPH, and +# HAVE_DOT tags are set to YES then doxygen will generate a graph for each +# documented header file showing the documented files that directly or +# indirectly include this file. + +INCLUDED_BY_GRAPH = YES + +# If the CALL_GRAPH, SOURCE_BROWSER and HAVE_DOT tags are set to YES then doxygen will +# generate a call dependency graph for every global function or class method. +# Note that enabling this option will significantly increase the time of a run. +# So in most cases it will be better to enable call graphs for selected +# functions only using the \callgraph command. + +CALL_GRAPH = YES + +# If the CALLER_GRAPH, SOURCE_BROWSER and HAVE_DOT tags are set to YES then doxygen will +# generate a caller dependency graph for every global function or class method. +# Note that enabling this option will significantly increase the time of a run. +# So in most cases it will be better to enable caller graphs for selected +# functions only using the \callergraph command. + +CALLER_GRAPH = YES + +# If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen +# will graphical hierarchy of all classes instead of a textual one. + +GRAPHICAL_HIERARCHY = YES + +# If the DIRECTORY_GRAPH, SHOW_DIRECTORIES and HAVE_DOT tags are set to YES +# then doxygen will show the dependencies a directory has on other directories +# in a graphical way. The dependency relations are determined by the #include +# relations between the files in the directories. + +DIRECTORY_GRAPH = YES + +# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images +# generated by dot. Possible values are png, jpg, or gif +# If left blank png will be used. + +DOT_IMAGE_FORMAT = png + +# The tag DOT_PATH can be used to specify the path where the dot tool can be +# found. If left blank, it is assumed the dot tool can be found in the path. + +DOT_PATH = + +# The DOTFILE_DIRS tag can be used to specify one or more directories that +# contain dot files that are included in the documentation (see the +# \dotfile command). + +DOTFILE_DIRS = + +# The MAX_DOT_GRAPH_MAX_NODES tag can be used to set the maximum number of +# nodes that will be shown in the graph. If the number of nodes in a graph +# becomes larger than this value, doxygen will truncate the graph, which is +# visualized by representing a node as a red box. Note that doxygen if the number +# of direct children of the root node in a graph is already larger than +# MAX_DOT_GRAPH_NOTES then the graph will not be shown at all. Also note +# that the size of a graph can be further restricted by MAX_DOT_GRAPH_DEPTH. + +DOT_GRAPH_MAX_NODES = 50 + +# The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the +# graphs generated by dot. A depth value of 3 means that only nodes reachable +# from the root by following a path via at most 3 edges will be shown. Nodes +# that lay further from the root node will be omitted. Note that setting this +# option to 1 or 2 may greatly reduce the computation time needed for large +# code bases. Also note that the size of a graph can be further restricted by +# DOT_GRAPH_MAX_NODES. Using a depth of 0 means no depth restriction. + +MAX_DOT_GRAPH_DEPTH = 0 + +# Set the DOT_TRANSPARENT tag to YES to generate images with a transparent +# background. This is disabled by default, which results in a white background. +# Warning: Depending on the platform used, enabling this option may lead to +# badly anti-aliased labels on the edges of a graph (i.e. they become hard to +# read). + +DOT_TRANSPARENT = NO + +# Set the DOT_MULTI_TARGETS tag to YES allow dot to generate multiple output +# files in one run (i.e. multiple -o and -T options on the command line). This +# makes dot run faster, but since only newer versions of dot (>1.8.10) +# support this, this feature is disabled by default. + +DOT_MULTI_TARGETS = YES + +# If the GENERATE_LEGEND tag is set to YES (the default) Doxygen will +# generate a legend page explaining the meaning of the various boxes and +# arrows in the dot generated graphs. + +GENERATE_LEGEND = NO + +# If the DOT_CLEANUP tag is set to YES (the default) Doxygen will +# remove the intermediate dot files that are used to generate +# the various graphs. + +DOT_CLEANUP = YES + +#--------------------------------------------------------------------------- +# Configuration::additions related to the search engine +#--------------------------------------------------------------------------- + +# The SEARCHENGINE tag specifies whether or not a search engine should be +# used. If set to NO the values of all tags below this one will be ignored. + +SEARCHENGINE = NO diff --git a/GNUmakefile.am b/GNUmakefile.am index 7f8d6f82..694d59b5 100644 --- a/GNUmakefile.am +++ b/GNUmakefile.am @@ -32,3 +32,10 @@ maintainer-clean-local: -chmod -R a+rw $(distdir) -rm -fr $(distdir) +docs : htmldocs + +htmldocs: + @echo 'Running doxygen with local Doxyfile' + -doxygen Doxyfile + + diff --git a/include/libsocketcan.h b/include/libsocketcan.h index afe15f61..8a92eee2 100644 --- a/include/libsocketcan.h +++ b/include/libsocketcan.h @@ -8,18 +8,23 @@ * Software Foundation; either version 2.1 of the License, or (at your option) * any later version. * - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * This library is distributed in the hope that it will be useful, but without + * any warranty; without even the implied warranty of merchantability or fitness + * for a particular purpose. see the gnu lesser general public license for more * details. * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * you should have received a copy of the gnu lesser general public license + * along with this library; if not, write to the free software foundation, inc., + * 59 temple place, suite 330, boston, ma 02111-1307 usa */ -#ifndef _SOCKETCAN_NETLINK_H -#define _SOCKETCAN_NETLINK_H +#ifndef _socketcan_netlink_h +#define _socketcan_netlink_h + +/** + * @file + * @brief API overview + */ #include diff --git a/src/libsocketcan.c b/src/libsocketcan.c index 07cc10f0..417abcc6 100644 --- a/src/libsocketcan.c +++ b/src/libsocketcan.c @@ -1,5 +1,4 @@ -/* - * libsocketcan.c +/* libsocketcan.c * * (C) 2009 Luotao Fu * @@ -18,6 +17,11 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +/** + * @file + * @brief library code + */ + #include #include #include @@ -124,6 +128,19 @@ static int addattr_l(struct nlmsghdr *n, size_t maxlen, int type, return 0; } +/** + * @ingroup intern + * @brief send_mod_request - send a linkinfo modification request + * + * @param fd decriptor to a priorly opened netlink socket + * @param n netlink message containing the request + * + * sends a request to setup the the linkinfo to netlink layer and awaits the + * status. + * + * @return 0 if success + * @return negativ if failed + */ static int send_mod_request(int fd, struct nlmsghdr *n) { int status; @@ -197,6 +214,17 @@ static int send_mod_request(int fd, struct nlmsghdr *n) return 0; } +/** + * @ingroup intern + * @brief send_dump_request - send a dump linkinfo request + * + * @param fd decriptor to a priorly opened netlink socket + * @param family rt_gen message family + * @param type netlink message header type + * + * @return 0 if success + * @return negativ if failed + */ static int send_dump_request(int fd, int family, int type) { struct get_req req; @@ -214,6 +242,15 @@ static int send_dump_request(int fd, int family, int type) return send(fd, (void *)&req, sizeof(req), 0); } +/** + * @ingroup intern + * @brief open_nl_sock - open a netlink socket + * + * opens a netlink socket and returns the socket descriptor + * + * @return 0 if success + * @return negativ if failed + */ static int open_nl_sock() { int fd; @@ -257,6 +294,25 @@ static int open_nl_sock() return fd; } +/** + * @ingroup intern + * @brief do_get_nl_link - get linkinfo + * + * @param fd socket file descriptor to a priorly opened netlink socket + * @param acquire which parameter we want to get + * @param name name of the can device. This is the netdev name, as ifconfig -a + * shows in your system. usually it contains prefix "can" and the numer of the + * can line. e.g. "can0" + * @param res pointer to store the result + * + * This callback send a dump request into the netlink layer, collect the packet + * containing the linkinfo and fill the pointer res points to depending on the + * acquire mode set in param acquire. + * + * @return 0 if success + * @return -1 if failed + */ + static int do_get_nl_link(int fd, __u8 acquire, const char *name, void *res) { struct sockaddr_nl peer; @@ -407,6 +463,21 @@ static int do_get_nl_link(int fd, __u8 acquire, const char *name, void *res) return ret; } +/** + * @ingroup intern + * @brief get_link - get linkinfo + * + * @param name name of the can device. This is the netdev name, as ifconfig -a shows + * in your system. usually it contains prefix "can" and the numer of the can + * line. e.g. "can0" + * @param acquire which parameter we want to get + * @param res pointer to store the result + * + * This is a wrapper for do_get_nl_link + * + * @return 0 if success + * @return -1 if failed + */ static int get_link(const char *name, __u8 acquire, void *res) { int fd; @@ -427,6 +498,27 @@ static int get_link(const char *name, __u8 acquire, void *res) } +/** + * @ingroup intern + * @brief do_set_nl_link - setup linkinfo + * + * @param fd socket file descriptor to a priorly opened netlink socket + * @param if_state state of the interface we want to put the device into. this + * parameter is only set if you want to use the callback to driver up/down the + * device + * @param name name of the can device. This is the netdev name, as ifconfig -a shows + * in your system. usually it contains prefix "can" and the numer of the can + * line. e.g. "can0" + * @param req_info request parameters + * + * This callback can do two different tasks: + * - bring up/down the interface + * - set up a netlink packet with request, as set up in req_info + * Which task this callback will do depends on which parameters are set. + * + * @return 0 if success + * @return -1 if failed + */ static int do_set_nl_link(int fd, __u8 if_state, const char *name, struct req_info *req_info) { @@ -503,6 +595,24 @@ static int do_set_nl_link(int fd, __u8 if_state, const char *name, return send_mod_request(fd, &req.n); } +/** + * @ingroup intern + * @brief set_link - open a netlink socket and setup linkinfo + * + * @param name name of the can device. This is the netdev name, as ifconfig -a + * shows in your system. usually it contains prefix "can" and the numer of the + * can line. e.g. "can0" + * @param if_state state of the interface we want to put the device into. this + * parameter is only set if you want to use the callback to driver up/down the + * device + * @param req_info request parameters + * + * This is a wrapper for do_set_nl_link. It opens a netlink socket and sends + * down the requests. + * + * @return 0 if success + * @return -1 if failed + */ static int set_link(const char *name, __u8 if_state, struct req_info *req_info) { int fd; @@ -522,16 +632,59 @@ static int set_link(const char *name, __u8 if_state, struct req_info *req_info) return err; } +/** + * @ingroup extern + * can_do_start - start the can interface + * @param name name of the can device. This is the netdev name, as ifconfig -a shows + * in your system. usually it contains prefix "can" and the numer of the can + * line. e.g. "can0" + * + * This starts the can interface with the given name. It simply changes the if + * state of the interface to up. All initialisation works will be done in + * kernel. The if state can also be queried by a simple ifconfig. + * + * @return 0 if success + * @return -1 if failed + */ int can_do_start(const char *name) { return set_link(name, IF_UP, NULL); } +/** + * @ingroup extern + * can_do_stop - stop the can interface + * @param name name of the can device. This is the netdev name, as ifconfig -a shows + * in your system. usually it contains prefix "can" and the numer of the can + * line. e.g. "can0" + * + * This stops the can interface with the given name. It simply changes the if + * state of the interface to down. Any running communication would be stopped. + * + * @return 0 if success + * @return -1 if failed + */ int can_do_stop(const char *name) { return set_link(name, IF_DOWN, NULL); } +/** + * @ingroup extern + * can_do_restart - restart the can interface + * @param name name of the can device. This is the netdev name, as ifconfig -a shows + * in your system. usually it contains prefix "can" and the numer of the can + * line. e.g. "can0" + * + * This triggers the start mode of the can device. + * + * NOTE: + * - restart mode can only be triggerd if the device is in BUS_OFF and the auto + * restart not turned on (restart_ms == 0) + * + * @return 0 if success + * @return -1 if failed + */ int can_do_restart(const char *name) { int fd; @@ -579,6 +732,21 @@ int can_do_restart(const char *name) return err; } +/** + * @ingroup extern + * can_set_restart_ms - set interval of auto restart. + * + * @param name name of the can device. This is the netdev name, as ifconfig -a shows + * in your system. usually it contains prefix "can" and the numer of the can + * line. e.g. "can0" + * @param restart_ms interval of auto restart in milliseconds + * + * This sets how often the device shall automatically restart the interface in + * case that a bus_off is detected. + * + * @return 0 if success + * @return -1 if failed + */ int can_set_restart_ms(const char *name, __u32 restart_ms) { struct req_info req_info = { @@ -591,6 +759,58 @@ int can_set_restart_ms(const char *name, __u32 restart_ms) return set_link(name, 0, &req_info); } +/** + * @ingroup extern + * can_set_ctrlmode - setup the control mode. + * + * @param name name of the can device. This is the netdev name, as ifconfig -a shows + * in your system. usually it contains prefix "can" and the numer of the can + * line. e.g. "can0" + * + * @param cm pointer of a can_ctrlmode struct + * + * This sets the control mode of the can device. There're currently three + * different control modes: + * - LOOPBACK + * - LISTEN_ONLY + * - TRIPPLE_SAMPLING + * + * You have to define the control mode struct yourself. a can_ctrlmode struct + * is declared as: + * + * @code + * struct can_ctrlmode { + * __u32 mask; + * __u32 flags; + * } + * @endcode + * + * You can use mask to select modes you want to control and flags to determine + * if you want to turn the selected mode(s) on or off. Every control mode is + * mapped to an own macro + * + * @code + * #define CAN_CTRLMODE_LOOPBACK 0x1 + * #define CAN_CTRLMODE_LISTENONLY 0x2 + * #define CAN_CTRLMODE_3_SAMPLES 0x4 + * @endcode + * + * e.g. the following pseudocode + * + * @code + * struct can_ctrlmode cm; + * memset(&cm, 0, sizeof(cm)); + * cm.mask = CAN_CTRLMODE_LOOPBACK | CAN_CTRLMODE_LISTENONLY; + * cm.flags = CAN_CTRLMODE_LOOPBACK; + * can_set_ctrlmode(candev, &cm); + * @endcode + * + * will turn the loopback mode on and listenonly mode off. + * + * @return 0 if success + * @return -1 if failed + */ + int can_set_ctrlmode(const char *name, struct can_ctrlmode *cm) { struct req_info req_info = { @@ -600,6 +820,44 @@ int can_set_ctrlmode(const char *name, struct can_ctrlmode *cm) return set_link(name, 0, &req_info); } +/** + * @ingroup extern + * can_set_bittiming - setup the bittiming. + * + * @param name name of the can device. This is the netdev name, as ifconfig -a shows + * in your system. usually it contains prefix "can" and the numer of the can + * line. e.g. "can0" + * @param bt pointer to a can_bittiming struct + * + * This sets the bittiming of the can device. This is for advantage usage. In + * normal cases you should use can_set_bitrate to simply define the bitrate and + * let the driver automatically calculate the bittiming. You will only need this + * function if you wish to define the bittiming in expert mode with fully + * manually defined timing values. + * You have to define the bittiming struct yourself. a can_bittiming struct + * consists of: + * + * @code + * struct can_bittiming { + * __u32 bitrate; + * __u32 sample_point; + * __u32 tq; + * __u32 prop_seg; + * __u32 phase_seg1; + * __u32 phase_seg2; + * __u32 sjw; + * __u32 brp; + * } + * @endcode + * + * to define a customized bittiming, you have to define tq, prop_seq, + * phase_seg1, phase_seg2 and sjw. See http://www.can-cia.org/index.php?id=88 + * for more information about bittiming and synchronizations on can bus. + * + * @return 0 if success + * @return -1 if failed + */ + int can_set_bittiming(const char *name, struct can_bittiming *bt) { struct req_info req_info = { @@ -609,6 +867,25 @@ int can_set_bittiming(const char *name, struct can_bittiming *bt) return set_link(name, 0, &req_info); } +/** + * @ingroup extern + * can_set_bitrate - setup the bitrate. + * + * @param name name of the can device. This is the netdev name, as ifconfig -a shows + * in your system. usually it contains prefix "can" and the numer of the can + * line. e.g. "can0" + * @param bitrate bitrate of the can bus + * + * This is the recommended way to setup the bus bit timing. You only have to + * give a bitrate value here. The exact bit timing will be calculated + * automatically. To use this function, make sure that CONFIG_CAN_CALC_BITTIMING + * is set to y in your kernel configuration. bitrate can be a value between + * 1000(1kbit/s) and 1000000(1000kbit/s). + * + * @return 0 if success + * @return -1 if failed + */ + int can_set_bitrate(const char *name, __u32 bitrate) { struct can_bittiming bt; @@ -619,6 +896,23 @@ int can_set_bitrate(const char *name, __u32 bitrate) return can_set_bittiming(name, &bt); } +/** + * @ingroup extern + * can_set_bitrate_samplepoint - setup the bitrate. + * + * @param name name of the can device. This is the netdev name, as ifconfig -a shows + * in your system. usually it contains prefix "can" and the numer of the can + * line. e.g. "can0" + * @param bitrate bitrate of the can bus + * @param sample_point sample point value + * + * This one is similar to can_set_bitrate, only you can additionally set up the + * time point for sampling (sample point) customly instead of using the + * CIA recommended value. sample_point can be a value between 0 and 999. + * + * @return 0 if success + * @return -1 if failed + */ int can_set_bitrate_samplepoint(const char *name, __u32 bitrate, __u32 sample_point) { @@ -631,31 +925,159 @@ int can_set_bitrate_samplepoint(const char *name, __u32 bitrate, return can_set_bittiming(name, &bt); } +/** + * @ingroup extern + * can_get_state - get the current state of the device + * + * @param name name of the can device. This is the netdev name, as ifconfig -a shows + * in your system. usually it contains prefix "can" and the numer of the can + * line. e.g. "can0" + * @param state pointer to store the state + * + * This one stores the current state of the can interface into the given + * pointer. Valid states are: + * - CAN_STATE_ERROR_ACTIVE + * - CAN_STATE_ERROR_WARNING + * - CAN_STATE_ERROR_PASSIVE + * - CAN_STATE_BUS_OFF + * - CAN_STATE_STOPPED + * - CAN_STATE_SLEEPING + * + * The first four states is determined by the value of RX/TX error counter. + * Please see relevant can specification for more information about this. A + * device in STATE_STOPPED is an inactive device. STATE_SLEEPING is not + * implemented on all devices. + * + * @return 0 if success + * @return -1 if failed + */ + int can_get_state(const char *name, int *state) { return get_link(name, GET_STATE, state); } +/** + * @ingroup extern + * can_get_restart_ms - get the current interval of auto restarting. + * + * @param name name of the can device. This is the netdev name, as ifconfig -a shows + * in your system. usually it contains prefix "can" and the numer of the can + * line. e.g. "can0" + * @param restart_ms pointer to store the value. + * + * This one stores the current interval of auto restarting into the given + * pointer. + * + * The socketcan framework can automatically restart a device if it is in + * bus_off in a given interval. This function gets this value in milliseconds. + * restart_ms == 0 means that autorestarting is turned off. + * + * @return 0 if success + * @return -1 if failed + */ + int can_get_restart_ms(const char *name, __u32 *restart_ms) { return get_link(name, GET_RESTART_MS, restart_ms); } +/** + * @ingroup extern + * can_get_bittiming - get the current bittimnig configuration. + * + * @param name name of the can device. This is the netdev name, as ifconfig -a shows + * in your system. usually it contains prefix "can" and the numer of the can + * line. e.g. "can0" + * @param bt pointer to the bittiming struct. + * + * This one stores the current bittiming configuration. + * + * Please see can_set_bittiming for more information about bit timing. + * + * @return 0 if success + * @return -1 if failed + */ int can_get_bittiming(const char *name, struct can_bittiming *bt) { return get_link(name, GET_BITTIMING, bt); } +/** + * @ingroup extern + * can_get_ctrlmode - get the current control mode. + * + * @param name name of the can device. This is the netdev name, as ifconfig -a shows + * in your system. usually it contains prefix "can" and the numer of the can + * line. e.g. "can0" + * @param cm pointer to the ctrlmode struct. + * + * This one stores the current control mode configuration. + * + * Please see can_set_ctrlmode for more information about control modes. + * + * @return 0 if success + * @return -1 if failed + */ + int can_get_ctrlmode(const char *name, struct can_ctrlmode *cm) { return get_link(name, GET_CTRLMODE, cm); } +/** + * @ingroup extern + * can_get_clock - get the current clock struct. + * + * @param name: name of the can device. This is the netdev name, as ifconfig -a shows + * in your system. usually it contains prefix "can" and the numer of the can + * line. e.g. "can0" + * @param clock pointer to the clock struct. + * + * This one stores the current clock configuration. At the time of writing the + * can_clock struct only contains information about the clock frequecy. This + * information is e.g. essential while setting up the bit timing. + * + * @return 0 if success + * @return -1 if failed + */ int can_get_clock(const char *name, struct can_clock *clock) { return get_link(name, GET_CLOCK, clock); } +/** + * @ingroup extern + * can_get_bittiming_const - get the current bittimnig constant. + * + * @param name name of the can device. This is the netdev name, as ifconfig -a shows + * in your system. usually it contains prefix "can" and the numer of the can + * line. e.g. "can0" + * @param btc pointer to the bittiming constant struct. + * + * This one stores the hardware dependent bittiming constant. The + * can_bittiming_const struct consists: + * + * @code + * struct can_bittiming_const { + * char name[16]; + * __u32 tseg1_min; + * __u32 tseg1_max; + * __u32 tseg2_min; + * __u32 tseg2_max; + * __u32 sjw_max; + * __u32 brp_min; + * __u32 brp_max; + * __u32 brp_inc; + * }; + * @endcode + * + * The information in this struct is used to calculate the bus bit timing + * automatically. + * + * @return 0 if success + * @return -1 if failed + */ int can_get_bittiming_const(const char *name, struct can_bittiming_const *btc) { return get_link(name, GET_BITTIMING_CONST, btc); From 917c6fb06993f77a4e05187c9b62a6514e5c35ed Mon Sep 17 00:00:00 2001 From: Luotao Fu Date: Fri, 11 Dec 2009 14:30:12 +0100 Subject: [PATCH 45/88] fix typo Signed-off-by: Luotao Fu --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index b8ef8252..a4df1d94 100644 --- a/configure.ac +++ b/configure.ac @@ -68,7 +68,7 @@ AC_CHECK_HEADERS([ \ net/if.h \ ]) -AC_CHECK_HEADER(linux/can/netlink.h,[],[AC_MSG_ERROR([cannot findcan/netlink.h])],[]) +AC_CHECK_HEADER(linux/can/netlink.h,[],[AC_MSG_ERROR([cannot find can/netlink.h])],[]) # # Checks for typedefs, structures, and compiler characteristics. # From d75a02c13d11c166a171e4e08a42da94506cf53c Mon Sep 17 00:00:00 2001 From: Luotao Fu Date: Fri, 11 Dec 2009 16:07:08 +0100 Subject: [PATCH 46/88] remove dependency on kernel header include make a local copy of the can/netlink.h. This way we don't have to include a kernel include directory to build any more. Signed-off-by: Luotao Fu --- configure.ac | 1 - include/can_netlink.h | 113 +++++++++++++++++++++++++++++++++++++++++ include/libsocketcan.h | 2 +- 3 files changed, 114 insertions(+), 2 deletions(-) create mode 100644 include/can_netlink.h diff --git a/configure.ac b/configure.ac index a4df1d94..6198df57 100644 --- a/configure.ac +++ b/configure.ac @@ -68,7 +68,6 @@ AC_CHECK_HEADERS([ \ net/if.h \ ]) -AC_CHECK_HEADER(linux/can/netlink.h,[],[AC_MSG_ERROR([cannot find can/netlink.h])],[]) # # Checks for typedefs, structures, and compiler characteristics. # diff --git a/include/can_netlink.h b/include/can_netlink.h new file mode 100644 index 00000000..9ecbb787 --- /dev/null +++ b/include/can_netlink.h @@ -0,0 +1,113 @@ +/* + * linux/can/netlink.h + * + * Definitions for the CAN netlink interface + * + * Copyright (c) 2009 Wolfgang Grandegger + * + * Send feedback to + * + */ + +#ifndef CAN_NETLINK_H +#define CAN_NETLINK_H + +#include + +/* + * CAN bit-timing parameters + * + * For futher information, please read chapter "8 BIT TIMING + * REQUIREMENTS" of the "Bosch CAN Specification version 2.0" + * at http://www.semiconductors.bosch.de/pdf/can2spec.pdf. + */ +struct can_bittiming { + __u32 bitrate; /* Bit-rate in bits/second */ + __u32 sample_point; /* Sample point in one-tenth of a percent */ + __u32 tq; /* Time quanta (TQ) in nanoseconds */ + __u32 prop_seg; /* Propagation segment in TQs */ + __u32 phase_seg1; /* Phase buffer segment 1 in TQs */ + __u32 phase_seg2; /* Phase buffer segment 2 in TQs */ + __u32 sjw; /* Synchronisation jump width in TQs */ + __u32 brp; /* Bit-rate prescaler */ +}; + +/* + * CAN harware-dependent bit-timing constant + * + * Used for calculating and checking bit-timing parameters + */ +struct can_bittiming_const { + char name[16]; /* Name of the CAN controller hardware */ + __u32 tseg1_min; /* Time segement 1 = prop_seg + phase_seg1 */ + __u32 tseg1_max; + __u32 tseg2_min; /* Time segement 2 = phase_seg2 */ + __u32 tseg2_max; + __u32 sjw_max; /* Synchronisation jump width */ + __u32 brp_min; /* Bit-rate prescaler */ + __u32 brp_max; + __u32 brp_inc; +}; + +/* + * CAN clock parameters + */ +struct can_clock { + __u32 freq; /* CAN system clock frequency in Hz */ +}; + +/* + * CAN operational and error states + */ +enum can_state { + CAN_STATE_ERROR_ACTIVE = 0, /* RX/TX error count < 96 */ + CAN_STATE_ERROR_WARNING, /* RX/TX error count < 128 */ + CAN_STATE_ERROR_PASSIVE, /* RX/TX error count < 256 */ + CAN_STATE_BUS_OFF, /* RX/TX error count >= 256 */ + CAN_STATE_STOPPED, /* Device is stopped */ + CAN_STATE_SLEEPING, /* Device is sleeping */ + CAN_STATE_MAX +}; + +/* + * CAN controller mode + */ +struct can_ctrlmode { + __u32 mask; + __u32 flags; +}; + +#define CAN_CTRLMODE_LOOPBACK 0x1 /* Loopback mode */ +#define CAN_CTRLMODE_LISTENONLY 0x2 /* Listen-only mode */ +#define CAN_CTRLMODE_3_SAMPLES 0x4 /* Triple sampling mode */ + +/* + * CAN device statistics + */ +struct can_device_stats { + __u32 bus_error; /* Bus errors */ + __u32 error_warning; /* Changes to error warning state */ + __u32 error_passive; /* Changes to error passive state */ + __u32 bus_off; /* Changes to bus off state */ + __u32 arbitration_lost; /* Arbitration lost errors */ + __u32 restarts; /* CAN controller re-starts */ +}; + +/* + * CAN netlink interface + */ +enum { + IFLA_CAN_UNSPEC, + IFLA_CAN_BITTIMING, + IFLA_CAN_BITTIMING_CONST, + IFLA_CAN_CLOCK, + IFLA_CAN_STATE, + IFLA_CAN_CTRLMODE, + IFLA_CAN_RESTART_MS, + IFLA_CAN_RESTART, + __IFLA_CAN_MAX +}; + +#define IFLA_CAN_MAX (__IFLA_CAN_MAX - 1) + +#endif /* CAN_NETLINK_H */ diff --git a/include/libsocketcan.h b/include/libsocketcan.h index 8a92eee2..bd2b0406 100644 --- a/include/libsocketcan.h +++ b/include/libsocketcan.h @@ -26,7 +26,7 @@ * @brief API overview */ -#include +#include int can_do_restart(const char *name); int can_do_stop(const char *name); From 3f2a397589dec6f34eaf3ad8946f174b766e5ea6 Mon Sep 17 00:00:00 2001 From: Luotao Fu Date: Tue, 15 Dec 2009 10:16:01 +0100 Subject: [PATCH 47/88] add dist doc files Signed-off-by: Luotao Fu --- GNUmakefile.am | 3 + INSTALL | 229 +++++++++++++++++++++++++++++++++++++++++++++++++ README | 18 ++++ 3 files changed, 250 insertions(+) create mode 100644 INSTALL create mode 100644 README diff --git a/GNUmakefile.am b/GNUmakefile.am index 694d59b5..d89ac474 100644 --- a/GNUmakefile.am +++ b/GNUmakefile.am @@ -28,6 +28,9 @@ MAINTAINERCLEANFILES = \ config/m4/lt~obsolete.m4 \ $(DIST_ARCHIVES) +dist_doc_DATA = INSTALL \ + README + maintainer-clean-local: -chmod -R a+rw $(distdir) -rm -fr $(distdir) diff --git a/INSTALL b/INSTALL new file mode 100644 index 00000000..54caf7c1 --- /dev/null +++ b/INSTALL @@ -0,0 +1,229 @@ +Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002 Free Software +Foundation, Inc. + + This file is free documentation; the Free Software Foundation gives +unlimited permission to copy, distribute and modify it. + +Basic Installation +================== + + These are generic installation instructions. + + The `configure' shell script attempts to guess correct values for +various system-dependent variables used during compilation. It uses +those values to create a `Makefile' in each directory of the package. +It may also create one or more `.h' files containing system-dependent +definitions. Finally, it creates a shell script `config.status' that +you can run in the future to recreate the current configuration, and a +file `config.log' containing compiler output (useful mainly for +debugging `configure'). + + It can also use an optional file (typically called `config.cache' +and enabled with `--cache-file=config.cache' or simply `-C') that saves +the results of its tests to speed up reconfiguring. (Caching is +disabled by default to prevent problems with accidental use of stale +cache files.) + + If you need to do unusual things to compile the package, please try +to figure out how `configure' could check whether to do them, and mail +diffs or instructions to the address given in the `README' so they can +be considered for the next release. If you are using the cache, and at +some point `config.cache' contains results you don't want to keep, you +may remove or edit it. + + The file `configure.ac' (or `configure.in') is used to create +`configure' by a program called `autoconf'. You only need +`configure.ac' if you want to change it or regenerate `configure' using +a newer version of `autoconf'. + +The simplest way to compile this package is: + + 1. `cd' to the directory containing the package's source code and type + `./configure' to configure the package for your system. If you're + using `csh' on an old version of System V, you might need to type + `sh ./configure' instead to prevent `csh' from trying to execute + `configure' itself. + + Running `configure' takes awhile. While running, it prints some + messages telling which features it is checking for. + + 2. Type `make' to compile the package. + + 3. Optionally, type `make check' to run any self-tests that come with + the package. + + 4. Type `make install' to install the programs and any data files and + documentation. + + 5. You can remove the program binaries and object files from the + source code directory by typing `make clean'. To also remove the + files that `configure' created (so you can compile the package for + a different kind of computer), type `make distclean'. There is + also a `make maintainer-clean' target, but that is intended mainly + for the package's developers. If you use it, you may have to get + all sorts of other programs in order to regenerate files that came + with the distribution. + +Compilers and Options +===================== + + Some systems require unusual options for compilation or linking that +the `configure' script does not know about. Run `./configure --help' +for details on some of the pertinent environment variables. + + You can give `configure' initial values for configuration parameters +by setting variables in the command line or in the environment. Here +is an example: + + ./configure CC=c89 CFLAGS=-O2 LIBS=-lposix + + *Note Defining Variables::, for more details. + +Compiling For Multiple Architectures +==================================== + + You can compile the package for more than one kind of computer at the +same time, by placing the object files for each architecture in their +own directory. To do this, you must use a version of `make' that +supports the `VPATH' variable, such as GNU `make'. `cd' to the +directory where you want the object files and executables to go and run +the `configure' script. `configure' automatically checks for the +source code in the directory that `configure' is in and in `..'. + + If you have to use a `make' that does not support the `VPATH' +variable, you have to compile the package for one architecture at a +time in the source code directory. After you have installed the +package for one architecture, use `make distclean' before reconfiguring +for another architecture. + +Installation Names +================== + + By default, `make install' will install the package's files in +`/usr/local/bin', `/usr/local/man', etc. You can specify an +installation prefix other than `/usr/local' by giving `configure' the +option `--prefix=PATH'. + + You can specify separate installation prefixes for +architecture-specific files and architecture-independent files. If you +give `configure' the option `--exec-prefix=PATH', the package will use +PATH as the prefix for installing programs and libraries. +Documentation and other data files will still use the regular prefix. + + In addition, if you use an unusual directory layout you can give +options like `--bindir=PATH' to specify different values for particular +kinds of files. Run `configure --help' for a list of the directories +you can set and what kinds of files go in them. + + If the package supports it, you can cause programs to be installed +with an extra prefix or suffix on their names by giving `configure' the +option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'. + +Optional Features +================= + + Some packages pay attention to `--enable-FEATURE' options to +`configure', where FEATURE indicates an optional part of the package. +They may also pay attention to `--with-PACKAGE' options, where PACKAGE +is something like `gnu-as' or `x' (for the X Window System). The +`README' should mention any `--enable-' and `--with-' options that the +package recognizes. + + For packages that use the X Window System, `configure' can usually +find the X include and library files automatically, but if it doesn't, +you can use the `configure' options `--x-includes=DIR' and +`--x-libraries=DIR' to specify their locations. + +Specifying the System Type +========================== + + There may be some features `configure' cannot figure out +automatically, but needs to determine by the type of machine the package +will run on. Usually, assuming the package is built to be run on the +_same_ architectures, `configure' can figure that out, but if it prints +a message saying it cannot guess the machine type, give it the +`--build=TYPE' option. TYPE can either be a short name for the system +type, such as `sun4', or a canonical name which has the form: + + CPU-COMPANY-SYSTEM + +where SYSTEM can have one of these forms: + + OS KERNEL-OS + + See the file `config.sub' for the possible values of each field. If +`config.sub' isn't included in this package, then this package doesn't +need to know the machine type. + + If you are _building_ compiler tools for cross-compiling, you should +use the `--target=TYPE' option to select the type of system they will +produce code for. + + If you want to _use_ a cross compiler, that generates code for a +platform different from the build platform, you should specify the +"host" platform (i.e., that on which the generated programs will +eventually be run) with `--host=TYPE'. + +Sharing Defaults +================ + + If you want to set default values for `configure' scripts to share, +you can create a site shell script called `config.site' that gives +default values for variables like `CC', `cache_file', and `prefix'. +`configure' looks for `PREFIX/share/config.site' if it exists, then +`PREFIX/etc/config.site' if it exists. Or, you can set the +`CONFIG_SITE' environment variable to the location of the site script. +A warning: not all `configure' scripts look for a site script. + +Defining Variables +================== + + Variables not defined in a site shell script can be set in the +environment passed to `configure'. However, some packages may run +configure again during the build, and the customized values of these +variables may be lost. In order to avoid this problem, you should set +them in the `configure' command line, using `VAR=value'. For example: + + ./configure CC=/usr/local2/bin/gcc + +will cause the specified gcc to be used as the C compiler (unless it is +overridden in the site shell script). + +`configure' Invocation +====================== + + `configure' recognizes the following options to control how it +operates. + +`--help' +`-h' + Print a summary of the options to `configure', and exit. + +`--version' +`-V' + Print the version of Autoconf used to generate the `configure' + script, and exit. + +`--cache-file=FILE' + Enable the cache: use and save the results of the tests in FILE, + traditionally `config.cache'. FILE defaults to `/dev/null' to + disable caching. + +`--config-cache' +`-C' + Alias for `--cache-file=config.cache'. + +`--quiet' +`--silent' +`-q' + Do not print messages saying which checks are being made. To + suppress all normal output, redirect it to `/dev/null' (any error + messages will still be shown). + +`--srcdir=DIR' + Look for the package's source code in directory DIR. Usually + `configure' can determine that directory automatically. + +`configure' also accepts some other, not widely useful, options. Run +`configure --help' for more details. + diff --git a/README b/README new file mode 100644 index 00000000..6293959f --- /dev/null +++ b/README @@ -0,0 +1,18 @@ +libsocketcan +---------------------------------------------------- +This library allows you to control some basic functions in socketcan from +userspace. + +Dependencies: +---------------------------------------------------- +A recent kernel with integrated SocketCAN (at least 2.6.30) + +Building: +---------------------------------------------------- +Please refert to the INSTALL file + +Documentation: +---------------------------------------------------- +Make sure you have oxygen installed on your host. If yes simply Run +make docs +and look for the API doc in Documentation/html. From 94e93700222f2a307e34a9b01ae79744248fee5e Mon Sep 17 00:00:00 2001 From: Luotao Fu Date: Tue, 15 Dec 2009 10:25:57 +0100 Subject: [PATCH 48/88] v0.0.6 Signed-off-by: Luotao Fu --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 6198df57..1ecf583f 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ(2.59) -AC_INIT([libsocketcan], [trunk], [bugs@pengutronix.de]) +AC_INIT([libsocketcan], [0.0.6], [bugs@pengutronix.de]) AC_CONFIG_HEADERS([include/libsocketcan_config.h]) AC_CONFIG_SRCDIR([src/libsocketcan.c]) AC_CONFIG_MACRO_DIR([config/m4]) From c9f7a3d715a06c3c91f47ac2810e48b570811dac Mon Sep 17 00:00:00 2001 From: Luotao Fu Date: Tue, 15 Dec 2009 10:31:39 +0100 Subject: [PATCH 49/88] switch back to trunk Signed-off-by: Luotao Fu --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 1ecf583f..6198df57 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ(2.59) -AC_INIT([libsocketcan], [0.0.6], [bugs@pengutronix.de]) +AC_INIT([libsocketcan], [trunk], [bugs@pengutronix.de]) AC_CONFIG_HEADERS([include/libsocketcan_config.h]) AC_CONFIG_SRCDIR([src/libsocketcan.c]) AC_CONFIG_MACRO_DIR([config/m4]) From 7422435b03b6ec48d3aeb4160372b3dc6ba60a84 Mon Sep 17 00:00:00 2001 From: Luotao Fu Date: Tue, 15 Dec 2009 12:30:09 +0100 Subject: [PATCH 50/88] fix distinstall of can_netlink.h Signed-off-by: Luotao Fu --- include/GNUmakefile.am | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/GNUmakefile.am b/include/GNUmakefile.am index 00bf0ec8..4ba27980 100644 --- a/include/GNUmakefile.am +++ b/include/GNUmakefile.am @@ -1,8 +1,8 @@ -# noinst_HEADERS = \ -# libsocketcan-stuff.h +noinst_HEADERS = \ + can_netlink.h nobase_include_HEADERS = \ - libsocketcan.h + libsocketcan.h MAINTAINERCLEANFILES = \ libsocketcan_config.h.in \ From fbb55a487fa450a3b05fe5cb4c6257d50338f876 Mon Sep 17 00:00:00 2001 From: Luotao Fu Date: Tue, 15 Dec 2009 12:46:42 +0100 Subject: [PATCH 51/88] v0.0.7 Signed-off-by: Luotao Fu --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 6198df57..37cbcfd9 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ(2.59) -AC_INIT([libsocketcan], [trunk], [bugs@pengutronix.de]) +AC_INIT([libsocketcan], [0.0.7], [bugs@pengutronix.de]) AC_CONFIG_HEADERS([include/libsocketcan_config.h]) AC_CONFIG_SRCDIR([src/libsocketcan.c]) AC_CONFIG_MACRO_DIR([config/m4]) From 118358336eceb0ad4ab4e72751af09964eb0a6ef Mon Sep 17 00:00:00 2001 From: Luotao Fu Date: Sun, 14 Feb 2010 17:25:33 +0100 Subject: [PATCH 52/88] fix header install Signed-off-by: Luotao Fu --- include/GNUmakefile.am | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/include/GNUmakefile.am b/include/GNUmakefile.am index 4ba27980..12d9b049 100644 --- a/include/GNUmakefile.am +++ b/include/GNUmakefile.am @@ -1,8 +1,6 @@ -noinst_HEADERS = \ - can_netlink.h - nobase_include_HEADERS = \ - libsocketcan.h + libsocketcan.h \ + can_netlink.h MAINTAINERCLEANFILES = \ libsocketcan_config.h.in \ From 298e6efc3e06251bd39f8a2afb7eb272c0fd9772 Mon Sep 17 00:00:00 2001 From: Luotao Fu Date: Sun, 14 Feb 2010 18:12:01 +0100 Subject: [PATCH 53/88] add get error counter call Signed-off-by: Luotao Fu --- include/can_netlink.h | 17 ++++++++++++++--- src/libsocketcan.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 3 deletions(-) diff --git a/include/can_netlink.h b/include/can_netlink.h index 9ecbb787..31cfa6ae 100644 --- a/include/can_netlink.h +++ b/include/can_netlink.h @@ -69,6 +69,14 @@ enum can_state { CAN_STATE_MAX }; +/* + * CAN bus error counters + */ +struct can_berr_counter { + __u16 txerr; + __u16 rxerr; +}; + /* * CAN controller mode */ @@ -77,9 +85,11 @@ struct can_ctrlmode { __u32 flags; }; -#define CAN_CTRLMODE_LOOPBACK 0x1 /* Loopback mode */ -#define CAN_CTRLMODE_LISTENONLY 0x2 /* Listen-only mode */ -#define CAN_CTRLMODE_3_SAMPLES 0x4 /* Triple sampling mode */ +#define CAN_CTRLMODE_LOOPBACK 0x01 /* Loopback mode */ +#define CAN_CTRLMODE_LISTENONLY 0x02 /* Listen-only mode */ +#define CAN_CTRLMODE_3_SAMPLES 0x04 /* Triple sampling mode */ +#define CAN_CTRLMODE_ONE_SHOT 0x08 /* One-Shot mode */ +#define CAN_CTRLMODE_BERR_REPORTING 0x10 /* Bus-error reporting */ /* * CAN device statistics @@ -105,6 +115,7 @@ enum { IFLA_CAN_CTRLMODE, IFLA_CAN_RESTART_MS, IFLA_CAN_RESTART, + IFLA_CAN_BERR_COUNTER, __IFLA_CAN_MAX }; diff --git a/src/libsocketcan.c b/src/libsocketcan.c index 417abcc6..2ac3f2a6 100644 --- a/src/libsocketcan.c +++ b/src/libsocketcan.c @@ -52,6 +52,7 @@ #define GET_CTRLMODE 4 #define GET_CLOCK 5 #define GET_BITTIMING_CONST 6 +#define GET_BERR_COUNTER 7 struct get_req { struct nlmsghdr n; @@ -456,6 +457,17 @@ static int do_get_nl_link(int fd, __u8 acquire, const char *name, void *res) fprintf(stderr, "no bittiming_const data found\n"); break; + case GET_BERR_COUNTER: + if (can_attr[IFLA_CAN_BERR_COUNTER]) { + memcpy(res, + RTA_DATA(can_attr[IFLA_CAN_BERR_COUNTER]), + sizeof(struct can_berr_counter)); + ret = 0; + } else + fprintf(stderr, "no berr_counter data found\n"); + + break; + default: fprintf(stderr, "unknown acquire mode\n"); } @@ -1083,3 +1095,29 @@ int can_get_bittiming_const(const char *name, struct can_bittiming_const *btc) return get_link(name, GET_BITTIMING_CONST, btc); } + +/** + * @ingroup extern + * can_get_berr_counter - get the tx/rx error counter. + * + * @param name name of the can device. This is the netdev name, as ifconfig -a shows + * in your system. usually it contains prefix "can" and the numer of the can + * line. e.g. "can0" + * @param bc pointer to the error counter struct.. + * + * This one gets the current rx/tx error counter from the hardware. + * + * @code + * struct can_berr_counter { + * __u16 txerr; + * __u16 rxerr; + * }; + * @endcode + * + * @return 0 if success + * @return -1 if failed + */ +int can_get_berr_counter(const char *name, struct can_berr_counter *bc) +{ + return get_link(name, GET_BERR_COUNTER, bc); +} From 1b50d5545dc12ea22e162d9f9f259148f160e06c Mon Sep 17 00:00:00 2001 From: Luotao Fu Date: Sun, 14 Feb 2010 18:18:09 +0100 Subject: [PATCH 54/88] change libtool library versioning Signed-off-by: Luotao Fu --- configure.ac | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 37cbcfd9..f67a0ce4 100644 --- a/configure.ac +++ b/configure.ac @@ -21,9 +21,9 @@ CFLAGS="${CFLAGS} -Wall" # Interfaces changed/added/removed: CURRENT++ REVISION=0 # Interfaces added: AGE++ # Interfaces removed: AGE=0 -LT_CURRENT=3 +LT_CURRENT=4 LT_REVISION=0 -LT_AGE=1 +LT_AGE=2 AC_SUBST(LT_CURRENT) AC_SUBST(LT_REVISION) AC_SUBST(LT_AGE) From cbe29b66de0eac77d710cbba6533147a2aea7e05 Mon Sep 17 00:00:00 2001 From: Luotao Fu Date: Sun, 14 Feb 2010 18:57:03 +0100 Subject: [PATCH 55/88] add berr counter call prototype to library header Signed-off-by: Luotao Fu --- include/libsocketcan.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/libsocketcan.h b/include/libsocketcan.h index bd2b0406..10c012c1 100644 --- a/include/libsocketcan.h +++ b/include/libsocketcan.h @@ -44,5 +44,6 @@ int can_get_ctrlmode(const char *name, struct can_ctrlmode *cm); int can_get_state(const char *name, int *state); int can_get_clock(const char *name, struct can_clock *clock); int can_get_bittiming_const(const char *name, struct can_bittiming_const *btc); +int can_get_berr_counter(const char *name, struct can_berr_counter *bc); #endif From 33f96f936c9e8fcf9092e77ba9582f65f5daa288 Mon Sep 17 00:00:00 2001 From: Luotao Fu Date: Sun, 14 Feb 2010 20:11:33 +0100 Subject: [PATCH 56/88] v0.0.8 Signed-off-by: Luotao Fu --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index f67a0ce4..1abed24e 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ(2.59) -AC_INIT([libsocketcan], [0.0.7], [bugs@pengutronix.de]) +AC_INIT([libsocketcan], [0.0.8], [bugs@pengutronix.de]) AC_CONFIG_HEADERS([include/libsocketcan_config.h]) AC_CONFIG_SRCDIR([src/libsocketcan.c]) AC_CONFIG_MACRO_DIR([config/m4]) From 36328666b6dcbb70c064c46264c46e253ab4e355 Mon Sep 17 00:00:00 2001 From: Luotao Fu Date: Sun, 14 Feb 2010 20:17:57 +0100 Subject: [PATCH 57/88] switch back to trunk --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 1abed24e..6b63992d 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ(2.59) -AC_INIT([libsocketcan], [0.0.8], [bugs@pengutronix.de]) +AC_INIT([libsocketcan], [trunk], [bugs@pengutronix.de]) AC_CONFIG_HEADERS([include/libsocketcan_config.h]) AC_CONFIG_SRCDIR([src/libsocketcan.c]) AC_CONFIG_MACRO_DIR([config/m4]) From 9f1be156e4cc31c3d70a6bb4953490e931161a60 Mon Sep 17 00:00:00 2001 From: Marc Kleine-Budde Date: Mon, 25 Oct 2010 13:28:31 +0200 Subject: [PATCH 58/88] configure: disable debug by default, turn off maintainer mode Signed-off-by: Marc Kleine-Budde --- configure.ac | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index 6b63992d..76b23049 100644 --- a/configure.ac +++ b/configure.ac @@ -10,8 +10,6 @@ AC_CONFIG_AUX_DIR([config/autoconf]) AC_CANONICAL_BUILD AC_CANONICAL_HOST -AM_MAINTAINER_MODE - CFLAGS="${CFLAGS} -Wall" # @@ -92,12 +90,12 @@ AC_CHECK_FUNCS([gethostbyaddr gethostbyname gethostname gettimeofday memset mkdi # AC_MSG_CHECKING([whether to enable debugging]) AC_ARG_ENABLE(debug, - AS_HELP_STRING([--enable-debug], [enable debugging @<:@default=yes@:>@]), + AS_HELP_STRING([--enable-debug], [enable debugging @<:@default=no@:>@]), [case "$enableval" in y | yes) CONFIG_DEBUG=yes ;; *) CONFIG_DEBUG=no ;; esac], - [CONFIG_DEBUG=yes]) + [CONFIG_DEBUG=no]) AC_MSG_RESULT([${CONFIG_DEBUG}]) if test "${CONFIG_DEBUG}" = "yes"; then CFLAGS="${CFLAGS} -Werror -Wsign-compare -Wfloat-equal -Wformat-security -g -O1" From d99010f50bb7fb80340d92b8a69ec8ef249d39d3 Mon Sep 17 00:00:00 2001 From: Marc Kleine-Budde Date: Mon, 25 Oct 2010 11:46:40 +0200 Subject: [PATCH 59/88] libsocketcan: remove trailing whitespace Signed-off-by: Marc Kleine-Budde --- src/libsocketcan.c | 48 +++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/src/libsocketcan.c b/src/libsocketcan.c index 2ac3f2a6..6c0b1841 100644 --- a/src/libsocketcan.c +++ b/src/libsocketcan.c @@ -1,6 +1,6 @@ /* libsocketcan.c * - * (C) 2009 Luotao Fu + * (C) 2009 Luotao Fu * * This library is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free @@ -248,7 +248,7 @@ static int send_dump_request(int fd, int family, int type) * @brief open_nl_sock - open a netlink socket * * opens a netlink socket and returns the socket descriptor - * + * * @return 0 if success * @return negativ if failed */ @@ -484,7 +484,7 @@ static int do_get_nl_link(int fd, __u8 acquire, const char *name, void *res) * line. e.g. "can0" * @param acquire which parameter we want to get * @param res pointer to store the result - * + * * This is a wrapper for do_get_nl_link * * @return 0 if success @@ -522,7 +522,7 @@ static int get_link(const char *name, __u8 acquire, void *res) * in your system. usually it contains prefix "can" and the numer of the can * line. e.g. "can0" * @param req_info request parameters - * + * * This callback can do two different tasks: * - bring up/down the interface * - set up a netlink packet with request, as set up in req_info @@ -672,7 +672,7 @@ int can_do_start(const char *name) * * This stops the can interface with the given name. It simply changes the if * state of the interface to down. Any running communication would be stopped. - * + * * @return 0 if success * @return -1 if failed */ @@ -689,11 +689,11 @@ int can_do_stop(const char *name) * line. e.g. "can0" * * This triggers the start mode of the can device. - * - * NOTE: + * + * NOTE: * - restart mode can only be triggerd if the device is in BUS_OFF and the auto * restart not turned on (restart_ms == 0) - * + * * @return 0 if success * @return -1 if failed */ @@ -755,7 +755,7 @@ int can_do_restart(const char *name) * * This sets how often the device shall automatically restart the interface in * case that a bus_off is detected. - * + * * @return 0 if success * @return -1 if failed */ @@ -796,7 +796,7 @@ int can_set_restart_ms(const char *name, __u32 restart_ms) * __u32 flags; * } * @endcode - * + * * You can use mask to select modes you want to control and flags to determine * if you want to turn the selected mode(s) on or off. Every control mode is * mapped to an own macro @@ -808,7 +808,7 @@ int can_set_restart_ms(const char *name, __u32 restart_ms) * @endcode * * e.g. the following pseudocode - * + * * @code * struct can_ctrlmode cm; * memset(&cm, 0, sizeof(cm)); @@ -816,7 +816,7 @@ int can_set_restart_ms(const char *name, __u32 restart_ms) * cm.flags = CAN_CTRLMODE_LOOPBACK; * can_set_ctrlmode(candev, &cm); * @endcode - * + * * will turn the loopback mode on and listenonly mode off. * * @return 0 if success @@ -959,7 +959,7 @@ int can_set_bitrate_samplepoint(const char *name, __u32 bitrate, * Please see relevant can specification for more information about this. A * device in STATE_STOPPED is an inactive device. STATE_SLEEPING is not * implemented on all devices. - * + * * @return 0 if success * @return -1 if failed */ @@ -971,7 +971,7 @@ int can_get_state(const char *name, int *state) /** * @ingroup extern - * can_get_restart_ms - get the current interval of auto restarting. + * can_get_restart_ms - get the current interval of auto restarting. * * @param name name of the can device. This is the netdev name, as ifconfig -a shows * in your system. usually it contains prefix "can" and the numer of the can @@ -980,7 +980,7 @@ int can_get_state(const char *name, int *state) * * This one stores the current interval of auto restarting into the given * pointer. - * + * * The socketcan framework can automatically restart a device if it is in * bus_off in a given interval. This function gets this value in milliseconds. * restart_ms == 0 means that autorestarting is turned off. @@ -1006,7 +1006,7 @@ int can_get_restart_ms(const char *name, __u32 *restart_ms) * This one stores the current bittiming configuration. * * Please see can_set_bittiming for more information about bit timing. - * + * * @return 0 if success * @return -1 if failed */ @@ -1027,7 +1027,7 @@ int can_get_bittiming(const char *name, struct can_bittiming *bt) * This one stores the current control mode configuration. * * Please see can_set_ctrlmode for more information about control modes. - * + * * @return 0 if success * @return -1 if failed */ @@ -1049,7 +1049,7 @@ int can_get_ctrlmode(const char *name, struct can_ctrlmode *cm) * This one stores the current clock configuration. At the time of writing the * can_clock struct only contains information about the clock frequecy. This * information is e.g. essential while setting up the bit timing. - * + * * @return 0 if success * @return -1 if failed */ @@ -1069,7 +1069,7 @@ int can_get_clock(const char *name, struct can_clock *clock) * * This one stores the hardware dependent bittiming constant. The * can_bittiming_const struct consists: - * + * * @code * struct can_bittiming_const { * char name[16]; @@ -1083,10 +1083,10 @@ int can_get_clock(const char *name, struct can_clock *clock) * __u32 brp_inc; * }; * @endcode - * + * * The information in this struct is used to calculate the bus bit timing * automatically. - * + * * @return 0 if success * @return -1 if failed */ @@ -1106,14 +1106,14 @@ int can_get_bittiming_const(const char *name, struct can_bittiming_const *btc) * @param bc pointer to the error counter struct.. * * This one gets the current rx/tx error counter from the hardware. - * + * * @code * struct can_berr_counter { * __u16 txerr; - * __u16 rxerr; + * __u16 rxerr; * }; * @endcode - * + * * @return 0 if success * @return -1 if failed */ From 42a3b65198f65134ac049172d5c9b998ae6220de Mon Sep 17 00:00:00 2001 From: Marc Kleine-Budde Date: Tue, 18 Oct 2011 13:25:50 +0200 Subject: [PATCH 60/88] tests: remove test example Signed-off-by: Marc Kleine-Budde --- GNUmakefile.am | 3 +-- tests/GNUmakefile.am | 17 ----------------- tests/test.c | 7 ------- 3 files changed, 1 insertion(+), 26 deletions(-) delete mode 100644 tests/GNUmakefile.am delete mode 100644 tests/test.c diff --git a/GNUmakefile.am b/GNUmakefile.am index d89ac474..687ff44f 100644 --- a/GNUmakefile.am +++ b/GNUmakefile.am @@ -1,8 +1,7 @@ SUBDIRS = \ include \ config \ - src \ - tests + src EXTRA_DIST = \ autogen.sh \ diff --git a/tests/GNUmakefile.am b/tests/GNUmakefile.am deleted file mode 100644 index 0744dc65..00000000 --- a/tests/GNUmakefile.am +++ /dev/null @@ -1,17 +0,0 @@ -TESTS = \ - test - -noinst_PROGRAMS = \ - test - -test_SOURCES = \ - test.c -test_LDADD = \ - $(top_builddir)/src/libsocketcan.la - -AM_CPPFLAGS = \ - -I$(top_srcdir)/include \ - -I$(top_builddir)/include - -MAINTAINERCLEANFILES = \ - GNUmakefile.in diff --git a/tests/test.c b/tests/test.c deleted file mode 100644 index ad562a28..00000000 --- a/tests/test.c +++ /dev/null @@ -1,7 +0,0 @@ -#include - -int main(void) -{ - printf("hallo\n"); - return 0; -} From 6db5d772b4b03bf76a72ba95ff5dda2bf94466db Mon Sep 17 00:00:00 2001 From: Kurt Van Dijck Date: Wed, 12 Oct 2011 14:55:13 +0200 Subject: [PATCH 61/88] add can_get_device_stats() When using libsocketcan on git://git.pengutronix.de/git/tools/libsocketcan.git, I kind of missed a method to fetch the can device statistics. This patch adds that functionality. I think this is the proper library to put such function. Signed-off-by: Kurt Van Dijck Signed-off-by: Marc Kleine-Budde --- include/libsocketcan.h | 1 + src/libsocketcan.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/include/libsocketcan.h b/include/libsocketcan.h index 10c012c1..6098d6a9 100644 --- a/include/libsocketcan.h +++ b/include/libsocketcan.h @@ -45,5 +45,6 @@ int can_get_state(const char *name, int *state); int can_get_clock(const char *name, struct can_clock *clock); int can_get_bittiming_const(const char *name, struct can_bittiming_const *btc); int can_get_berr_counter(const char *name, struct can_berr_counter *bc); +int can_get_device_stats(const char *name, struct can_device_stats *cds); #endif diff --git a/src/libsocketcan.c b/src/libsocketcan.c index 6c0b1841..26da338e 100644 --- a/src/libsocketcan.c +++ b/src/libsocketcan.c @@ -53,6 +53,7 @@ #define GET_CLOCK 5 #define GET_BITTIMING_CONST 6 #define GET_BERR_COUNTER 7 +#define GET_XSTATS 8 struct get_req { struct nlmsghdr n; @@ -386,6 +387,17 @@ static int do_get_nl_link(int fd, __u8 acquire, const char *name, void *res) else continue; + if (acquire == GET_XSTATS) { + if (!linkinfo[IFLA_INFO_XSTATS]) + fprintf(stderr, "no can statistics found\n"); + else { + memcpy(res, RTA_DATA(linkinfo[IFLA_INFO_XSTATS]), + sizeof(struct can_device_stats)); + ret = 0; + } + continue; + } + if (!linkinfo[IFLA_INFO_DATA]) { fprintf(stderr, "no link data found\n"); return ret; @@ -1121,3 +1133,24 @@ int can_get_berr_counter(const char *name, struct can_berr_counter *bc) { return get_link(name, GET_BERR_COUNTER, bc); } + +/** + * @ingroup extern + * can_get_device_stats - get the can_device_stats. + * + * @param name name of the can device. This is the netdev name, as ifconfig -a shows + * in your system. usually it contains prefix "can" and the numer of the can + * line. e.g. "can0" + * @param bc pointer to the error counter struct.. + * + * This one gets the current can_device_stats. + * + * Please see struct can_device_stats for more information. + * + * @return 0 if success + * @return -1 if failed + */ +int can_get_device_stats(const char *name, struct can_device_stats *cds) +{ + return get_link(name, GET_XSTATS, cds); +} From 3a2cec63a4e6212cc63d21008453bd799cfe8774 Mon Sep 17 00:00:00 2001 From: Kurt Van Dijck Date: Wed, 12 Oct 2011 14:57:17 +0200 Subject: [PATCH 62/88] allow linking from c++ libsocketcan with c++ fails linking. Signed-off-by: Kurt Van Dijck Signed-off-by: Marc Kleine-Budde --- include/libsocketcan.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/libsocketcan.h b/include/libsocketcan.h index 6098d6a9..dc52053b 100644 --- a/include/libsocketcan.h +++ b/include/libsocketcan.h @@ -28,6 +28,10 @@ #include +#ifdef __cplusplus +extern "C" { +#endif + int can_do_restart(const char *name); int can_do_stop(const char *name); int can_do_start(const char *name); @@ -47,4 +51,8 @@ int can_get_bittiming_const(const char *name, struct can_bittiming_const *btc); int can_get_berr_counter(const char *name, struct can_berr_counter *bc); int can_get_device_stats(const char *name, struct can_device_stats *cds); +#ifdef __cplusplus +} +#endif + #endif From 5b990a47714ea21911538304f9350edefe349299 Mon Sep 17 00:00:00 2001 From: Marc Kleine-Budde Date: Fri, 16 Dec 2011 14:06:08 +0100 Subject: [PATCH 63/88] configure: fix tests/GNUmakefile.in not found regression This patch fixes the following problem: configure.ac:108: required file `tests/GNUmakefile.in' not found which has been introduced in commit: 42a3b65198f65134ac049172d5c9b998ae6220de tests: remove test example Signed-off-by: Marc Kleine-Budde --- configure.ac | 1 - 1 file changed, 1 deletion(-) diff --git a/configure.ac b/configure.ac index 76b23049..fef29049 100644 --- a/configure.ac +++ b/configure.ac @@ -111,7 +111,6 @@ AC_CONFIG_FILES([ config/GNUmakefile include/GNUmakefile src/GNUmakefile - tests/GNUmakefile ]) AC_OUTPUT From 5ba2310d85da1309f770cc4abeb372d45dcb44b8 Mon Sep 17 00:00:00 2001 From: Andrew Beard Date: Fri, 3 Aug 2012 11:10:27 -0700 Subject: [PATCH 64/88] Modified do_get_nl_link to potentially process multiple netlink dump replies. Prior to this commit, do_get_nl_link assumed there would only be a single reply for a dump request. On my system with multiple can interfaces, this would cause only half of them to be listed in the dump reply. This change checks for NLMSG_DONE dump terminator and stops receiving messages once received. Signed-off-by: Andrew Beard [mkl: fix indention, move variable init out of loop] Signed-off-by: Marc Kleine-Budde --- src/libsocketcan.c | 255 +++++++++++++++++++++++---------------------- 1 file changed, 130 insertions(+), 125 deletions(-) diff --git a/src/libsocketcan.c b/src/libsocketcan.c index 26da338e..fedcbdc0 100644 --- a/src/libsocketcan.c +++ b/src/libsocketcan.c @@ -323,6 +323,7 @@ static int do_get_nl_link(int fd, __u8 acquire, const char *name, void *res) char nlbuf[1024 * 8]; int ret = -1; + int done = 0; struct iovec iov = { .iov_base = (void *)nlbuf, @@ -349,141 +350,145 @@ static int do_get_nl_link(int fd, __u8 acquire, const char *name, void *res) return ret; } - if ((msglen = recvmsg(fd, &msg, 0)) <= 0) { - perror("Receive error"); - return ret; - } - size_t u_msglen = (size_t) msglen; - /* Check to see if the buffers in msg get truncated */ - if (msg.msg_namelen != sizeof(peer) || - (msg.msg_flags & (MSG_TRUNC | MSG_CTRUNC))) { - fprintf(stderr, "Uhoh... truncated message.\n"); - return ret; - } - - for (nl_msg = (struct nlmsghdr *)nlbuf; - NLMSG_OK(nl_msg, u_msglen); - nl_msg = NLMSG_NEXT(nl_msg, u_msglen)) { - int type = nl_msg->nlmsg_type; - int len; - if (type != RTM_NEWLINK) - continue; - - struct ifinfomsg *ifi = NLMSG_DATA(nl_msg); - struct rtattr *tb[IFLA_MAX + 1]; - - len = - nl_msg->nlmsg_len - NLMSG_LENGTH(sizeof(struct ifaddrmsg)); - parse_rtattr(tb, IFLA_MAX, IFLA_RTA(ifi), len); - - if (strncmp - ((char *)RTA_DATA(tb[IFLA_IFNAME]), name, - sizeof(name)) != 0) - continue; - - if (tb[IFLA_LINKINFO]) - parse_rtattr_nested(linkinfo, - IFLA_INFO_MAX, tb[IFLA_LINKINFO]); - else - continue; - - if (acquire == GET_XSTATS) { - if (!linkinfo[IFLA_INFO_XSTATS]) - fprintf(stderr, "no can statistics found\n"); - else { - memcpy(res, RTA_DATA(linkinfo[IFLA_INFO_XSTATS]), - sizeof(struct can_device_stats)); - ret = 0; - } - continue; + while (!done && (msglen = recvmsg(fd, &msg, 0)) > 0) { + size_t u_msglen = (size_t) msglen; + /* Check to see if the buffers in msg get truncated */ + if (msg.msg_namelen != sizeof(peer) || + (msg.msg_flags & (MSG_TRUNC | MSG_CTRUNC))) { + fprintf(stderr, "Uhoh... truncated message.\n"); + return -1; } - if (!linkinfo[IFLA_INFO_DATA]) { - fprintf(stderr, "no link data found\n"); - return ret; - } + for (nl_msg = (struct nlmsghdr *)nlbuf; + NLMSG_OK(nl_msg, u_msglen); + nl_msg = NLMSG_NEXT(nl_msg, u_msglen)) { + int type = nl_msg->nlmsg_type; + int len; - parse_rtattr_nested(can_attr, IFLA_CAN_MAX, - linkinfo[IFLA_INFO_DATA]); - - switch (acquire) { - case GET_STATE: - if (can_attr[IFLA_CAN_STATE]) { - *((int *)res) = *((__u32 *) - RTA_DATA(can_attr - [IFLA_CAN_STATE])); - ret = 0; - } else { - fprintf(stderr, "no state data found\n"); + if (type == NLMSG_DONE) { + done++; + continue; + } + if (type != RTM_NEWLINK) + continue; + + struct ifinfomsg *ifi = NLMSG_DATA(nl_msg); + struct rtattr *tb[IFLA_MAX + 1]; + + len = + nl_msg->nlmsg_len - NLMSG_LENGTH(sizeof(struct ifaddrmsg)); + parse_rtattr(tb, IFLA_MAX, IFLA_RTA(ifi), len); + + if (strncmp + ((char *)RTA_DATA(tb[IFLA_IFNAME]), name, + sizeof(name)) != 0) + continue; + + if (tb[IFLA_LINKINFO]) + parse_rtattr_nested(linkinfo, + IFLA_INFO_MAX, tb[IFLA_LINKINFO]); + else + continue; + + if (acquire == GET_XSTATS) { + if (!linkinfo[IFLA_INFO_XSTATS]) + fprintf(stderr, "no can statistics found\n"); + else { + memcpy(res, RTA_DATA(linkinfo[IFLA_INFO_XSTATS]), + sizeof(struct can_device_stats)); + ret = 0; + } + continue; } - break; - case GET_RESTART_MS: - if (can_attr[IFLA_CAN_RESTART_MS]) { - *((__u32 *) res) = *((__u32 *) - RTA_DATA(can_attr - [IFLA_CAN_RESTART_MS])); - ret = 0; - } else - fprintf(stderr, "no restart_ms data found\n"); - - break; - case GET_BITTIMING: - if (can_attr[IFLA_CAN_BITTIMING]) { - memcpy(res, - RTA_DATA(can_attr[IFLA_CAN_BITTIMING]), - sizeof(struct can_bittiming)); - ret = 0; - } else - fprintf(stderr, "no bittiming data found\n"); - - break; - case GET_CTRLMODE: - if (can_attr[IFLA_CAN_CTRLMODE]) { - memcpy(res, - RTA_DATA(can_attr[IFLA_CAN_CTRLMODE]), - sizeof(struct can_ctrlmode)); - ret = 0; - } else - fprintf(stderr, "no ctrlmode data found\n"); - - break; - case GET_CLOCK: - if (can_attr[IFLA_CAN_CLOCK]) { - memcpy(res, - RTA_DATA(can_attr[IFLA_CAN_CLOCK]), - sizeof(struct can_clock)); - ret = 0; - } else - fprintf(stderr, - "no clock parameter data found\n"); - - break; - case GET_BITTIMING_CONST: - if (can_attr[IFLA_CAN_BITTIMING_CONST]) { - memcpy(res, - RTA_DATA(can_attr[IFLA_CAN_BITTIMING_CONST]), - sizeof(struct can_bittiming_const)); - ret = 0; - } else - fprintf(stderr, "no bittiming_const data found\n"); + if (!linkinfo[IFLA_INFO_DATA]) { + fprintf(stderr, "no link data found\n"); + return ret; + } - break; - case GET_BERR_COUNTER: - if (can_attr[IFLA_CAN_BERR_COUNTER]) { - memcpy(res, - RTA_DATA(can_attr[IFLA_CAN_BERR_COUNTER]), - sizeof(struct can_berr_counter)); - ret = 0; - } else - fprintf(stderr, "no berr_counter data found\n"); + parse_rtattr_nested(can_attr, IFLA_CAN_MAX, + linkinfo[IFLA_INFO_DATA]); - break; + switch (acquire) { + case GET_STATE: + if (can_attr[IFLA_CAN_STATE]) { + *((int *)res) = *((__u32 *) + RTA_DATA(can_attr + [IFLA_CAN_STATE])); + ret = 0; + } else { + fprintf(stderr, "no state data found\n"); + } - default: - fprintf(stderr, "unknown acquire mode\n"); + break; + case GET_RESTART_MS: + if (can_attr[IFLA_CAN_RESTART_MS]) { + *((__u32 *) res) = *((__u32 *) + RTA_DATA(can_attr + [IFLA_CAN_RESTART_MS])); + ret = 0; + } else + fprintf(stderr, "no restart_ms data found\n"); + + break; + case GET_BITTIMING: + if (can_attr[IFLA_CAN_BITTIMING]) { + memcpy(res, + RTA_DATA(can_attr[IFLA_CAN_BITTIMING]), + sizeof(struct can_bittiming)); + ret = 0; + } else + fprintf(stderr, "no bittiming data found\n"); + + break; + case GET_CTRLMODE: + if (can_attr[IFLA_CAN_CTRLMODE]) { + memcpy(res, + RTA_DATA(can_attr[IFLA_CAN_CTRLMODE]), + sizeof(struct can_ctrlmode)); + ret = 0; + } else + fprintf(stderr, "no ctrlmode data found\n"); + + break; + case GET_CLOCK: + if (can_attr[IFLA_CAN_CLOCK]) { + memcpy(res, + RTA_DATA(can_attr[IFLA_CAN_CLOCK]), + sizeof(struct can_clock)); + ret = 0; + } else + fprintf(stderr, + "no clock parameter data found\n"); + + break; + case GET_BITTIMING_CONST: + if (can_attr[IFLA_CAN_BITTIMING_CONST]) { + memcpy(res, + RTA_DATA(can_attr[IFLA_CAN_BITTIMING_CONST]), + sizeof(struct can_bittiming_const)); + ret = 0; + } else + fprintf(stderr, "no bittiming_const data found\n"); + + break; + case GET_BERR_COUNTER: + if (can_attr[IFLA_CAN_BERR_COUNTER]) { + memcpy(res, + RTA_DATA(can_attr[IFLA_CAN_BERR_COUNTER]), + sizeof(struct can_berr_counter)); + ret = 0; + } else + fprintf(stderr, "no berr_counter data found\n"); + + break; + + default: + fprintf(stderr, "unknown acquire mode\n"); + } } } + return ret; } From 10a2051adb3d4add43452813dc8620ccbb2138c2 Mon Sep 17 00:00:00 2001 From: Marc Kleine-Budde Date: Tue, 6 Nov 2012 21:58:25 +0100 Subject: [PATCH 65/88] configure.ac: enable AM_SILENT_RULES Signed-off-by: Marc Kleine-Budde --- configure.ac | 1 + 1 file changed, 1 insertion(+) diff --git a/configure.ac b/configure.ac index fef29049..3e4e0485 100644 --- a/configure.ac +++ b/configure.ac @@ -40,6 +40,7 @@ AC_PROG_LIBTOOL # LT_INIT(win32-dll) AM_INIT_AUTOMAKE([foreign no-exeext dist-bzip2]) +m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes]])) # From e1a224bf1c409adf0c02b07a90deada634e54b88 Mon Sep 17 00:00:00 2001 From: Marc Kleine-Budde Date: Tue, 6 Nov 2012 21:58:57 +0100 Subject: [PATCH 66/88] v0.0.9 Signed-off-by: Marc Kleine-Budde --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 3e4e0485..6120b8c1 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ(2.59) -AC_INIT([libsocketcan], [trunk], [bugs@pengutronix.de]) +AC_INIT([libsocketcan], [0.0.9], [bugs@pengutronix.de]) AC_CONFIG_HEADERS([include/libsocketcan_config.h]) AC_CONFIG_SRCDIR([src/libsocketcan.c]) AC_CONFIG_MACRO_DIR([config/m4]) From 58f117aa512e96cd4f75c73bc1e3624fb78d69d9 Mon Sep 17 00:00:00 2001 From: Marc Kleine-Budde Date: Tue, 6 Nov 2012 22:04:43 +0100 Subject: [PATCH 67/88] configure.ac: back to trunk Signed-off-by: Marc Kleine-Budde --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 6120b8c1..3e4e0485 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ(2.59) -AC_INIT([libsocketcan], [0.0.9], [bugs@pengutronix.de]) +AC_INIT([libsocketcan], [trunk], [bugs@pengutronix.de]) AC_CONFIG_HEADERS([include/libsocketcan_config.h]) AC_CONFIG_SRCDIR([src/libsocketcan.c]) AC_CONFIG_MACRO_DIR([config/m4]) From 94094cc4ee7ae585da3e5e7e83e7d82b5d6de656 Mon Sep 17 00:00:00 2001 From: Alexander Stein Date: Wed, 14 Nov 2012 12:13:06 +0100 Subject: [PATCH 68/88] Use strcmp instead of sizeof on char* string This bug was detected by the clang warning: libsocketcan.c:384:16: warning: argument to 'sizeof' in 'strncmp' call is the same expression as the source; did you mean to provide an explicit length? [-Wsizeof-pointer-memaccess] sizeof(name)) != 0) ~~~~~~~^~~~~~ Signed-off-by: Alexander Stein Signed-off-by: Marc Kleine-Budde --- src/libsocketcan.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/libsocketcan.c b/src/libsocketcan.c index fedcbdc0..841c2ed9 100644 --- a/src/libsocketcan.c +++ b/src/libsocketcan.c @@ -379,9 +379,8 @@ static int do_get_nl_link(int fd, __u8 acquire, const char *name, void *res) nl_msg->nlmsg_len - NLMSG_LENGTH(sizeof(struct ifaddrmsg)); parse_rtattr(tb, IFLA_MAX, IFLA_RTA(ifi), len); - if (strncmp - ((char *)RTA_DATA(tb[IFLA_IFNAME]), name, - sizeof(name)) != 0) + if (strcmp + ((char *)RTA_DATA(tb[IFLA_IFNAME]), name) != 0) continue; if (tb[IFLA_LINKINFO]) From d5deaf6296b915c5860fbd2e93821ef9cbb7c7f0 Mon Sep 17 00:00:00 2001 From: Wolfram Sang Date: Wed, 28 Nov 2012 13:05:47 +0100 Subject: [PATCH 69/88] libsocketcan: add LICENSE file Took LGPL v2.1+ from the FSF website which is stated in libsocketcan.c. Signed-off-by: Wolfram Sang Signed-off-by: Marc Kleine-Budde --- LICENSE | 502 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 502 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 00000000..4362b491 --- /dev/null +++ b/LICENSE @@ -0,0 +1,502 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! From 9a889d52d078587fd4ebc571ccdda25d876eb1c5 Mon Sep 17 00:00:00 2001 From: Jan Engelhardt Date: Sun, 30 Dec 2012 08:12:59 +0100 Subject: [PATCH 70/88] build: avoid expansion of commented macros '#' does not ignore the line at the m4 level, "dnl" does. Signed-off-by: Jan Engelhardt Signed-off-by: Marc Kleine-Budde --- configure.ac | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index 3e4e0485..1f17ce25 100644 --- a/configure.ac +++ b/configure.ac @@ -31,13 +31,13 @@ AC_SUBST(LT_AGE) # Checks for programs. # AC_PROG_CC -#AM_MISSING_PROG(PERL, perl, $missing_dir) +dnl AM_MISSING_PROG(PERL, perl, $missing_dir) # libtool, old: AC_LIBTOOL_WIN32_DLL -#AC_LIBTOOL_TAGS([]) +dnl AC_LIBTOOL_TAGS([]) AC_PROG_LIBTOOL # libtool, new: -# LT_INIT(win32-dll) +dnl LT_INIT(win32-dll) AM_INIT_AUTOMAKE([foreign no-exeext dist-bzip2]) m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes]])) From 8ec77c4e7efeda92c57b163c1410eba08834d78f Mon Sep 17 00:00:00 2001 From: Jan Engelhardt Date: Sun, 30 Dec 2012 08:13:42 +0100 Subject: [PATCH 71/88] build: fix bracket imbalance Signed-off-by: Jan Engelhardt Signed-off-by: Marc Kleine-Budde --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 1f17ce25..fb9253b6 100644 --- a/configure.ac +++ b/configure.ac @@ -40,7 +40,7 @@ AC_PROG_LIBTOOL dnl LT_INIT(win32-dll) AM_INIT_AUTOMAKE([foreign no-exeext dist-bzip2]) -m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes]])) +m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) # From 9db8e13d5ebcb5ba83182198e87c10cdfa15b822 Mon Sep 17 00:00:00 2001 From: Yegor Yefremov Date: Thu, 16 Jan 2014 09:45:00 +0100 Subject: [PATCH 72/88] README: typos and beautification Signed-off-by: Yegor Yefremov Signed-off-by: Marc Kleine-Budde --- README | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README b/README index 6293959f..02b24536 100644 --- a/README +++ b/README @@ -1,18 +1,18 @@ libsocketcan ----------------------------------------------------- -This library allows you to control some basic functions in socketcan from +------------------------------------------------------------------------------- +This library allows you to control some basic functions in SocketCAN from userspace. Dependencies: ----------------------------------------------------- +------------------------------------------------------------------------------- A recent kernel with integrated SocketCAN (at least 2.6.30) Building: ----------------------------------------------------- -Please refert to the INSTALL file +------------------------------------------------------------------------------- +Please refer to the INSTALL file Documentation: ----------------------------------------------------- -Make sure you have oxygen installed on your host. If yes simply Run +------------------------------------------------------------------------------- +Make sure you have Doxygen installed on your host. If yes simply run: make docs and look for the API doc in Documentation/html. From d9469850ac39792abbd167c061b16e57d8f22182 Mon Sep 17 00:00:00 2001 From: Alexander Shiyan Date: Fri, 31 Jan 2014 14:02:49 +0400 Subject: [PATCH 73/88] Use "%u" printf-format specifier for unsigned variable Signed-off-by: Alexander Shiyan Signed-off-by: Marc Kleine-Budde --- src/libsocketcan.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libsocketcan.c b/src/libsocketcan.c index 841c2ed9..a39c74be 100644 --- a/src/libsocketcan.c +++ b/src/libsocketcan.c @@ -286,7 +286,7 @@ static int open_nl_sock() return -1; } if (addr_len != sizeof(local)) { - fprintf(stderr, "Wrong address length %d\n", addr_len); + fprintf(stderr, "Wrong address length %u\n", addr_len); return -1; } if (local.nl_family != AF_NETLINK) { From 9a28d6918380e5dc5ba4e81cb5a4f4b0622f59b3 Mon Sep 17 00:00:00 2001 From: Alexander Shiyan Date: Fri, 31 Jan 2014 14:02:50 +0400 Subject: [PATCH 74/88] Optimize can_do_restart() function This patch optimizes can_do_restart() function by reusing some part of code from existing set_link() function. Signed-off-by: Alexander Shiyan Signed-off-by: Marc Kleine-Budde --- src/libsocketcan.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/libsocketcan.c b/src/libsocketcan.c index a39c74be..7a523d2b 100644 --- a/src/libsocketcan.c +++ b/src/libsocketcan.c @@ -715,7 +715,6 @@ int can_do_stop(const char *name) */ int can_do_restart(const char *name) { - int fd; int err = -1; int state; __u32 restart_ms; @@ -746,16 +745,8 @@ int can_do_restart(const char *name) .restart = 1, }; - fd = open_nl_sock(); - if (fd < 0) - goto err_out; + err = set_link(name, 0, &req_info); - err = do_set_nl_link(fd, 0, name, &req_info); - if (err < 0) - goto close_out; - -close_out: - close(fd); err_out: return err; } From 24500fcaca7e7791187154bf03fbde5e7ecbe350 Mon Sep 17 00:00:00 2001 From: Alexander Shiyan Date: Mon, 3 Feb 2014 13:40:21 +0400 Subject: [PATCH 75/88] libsocketcan: Fix return value for get{set}_link() function This patch makes return value negative when open_nl_sock() function fail and removes excess labels. Signed-off-by: Alexander Shiyan Signed-off-by: Marc Kleine-Budde --- src/libsocketcan.c | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/src/libsocketcan.c b/src/libsocketcan.c index 7a523d2b..02714aef 100644 --- a/src/libsocketcan.c +++ b/src/libsocketcan.c @@ -508,20 +508,15 @@ static int do_get_nl_link(int fd, __u8 acquire, const char *name, void *res) */ static int get_link(const char *name, __u8 acquire, void *res) { - int fd; - int err = -1; + int err, fd; fd = open_nl_sock(); if (fd < 0) - goto err_out; + return -1; err = do_get_nl_link(fd, acquire, name, res); - if (err < 0) - goto close_out; - -close_out: close(fd); -err_out: + return err; } @@ -643,20 +638,15 @@ static int do_set_nl_link(int fd, __u8 if_state, const char *name, */ static int set_link(const char *name, __u8 if_state, struct req_info *req_info) { - int fd; - int err = 0; + int err, fd; fd = open_nl_sock(); if (fd < 0) - goto err_out; + return -1; err = do_set_nl_link(fd, if_state, name, req_info); - if (err < 0) - goto close_out; - -close_out: close(fd); -err_out: + return err; } From 0c4609f54f44653176ce54ce0ea7c04f2cad5b42 Mon Sep 17 00:00:00 2001 From: Alexander Shiyan Date: Fri, 7 Feb 2014 13:21:27 +0400 Subject: [PATCH 76/88] libsocketcan: Remove excess gotos. Signed-off-by: Alexander Shiyan Signed-off-by: Marc Kleine-Budde --- src/libsocketcan.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/libsocketcan.c b/src/libsocketcan.c index 02714aef..fe3a0b37 100644 --- a/src/libsocketcan.c +++ b/src/libsocketcan.c @@ -705,7 +705,6 @@ int can_do_stop(const char *name) */ int can_do_restart(const char *name) { - int err = -1; int state; __u32 restart_ms; @@ -713,32 +712,29 @@ int can_do_restart(const char *name) if ((can_get_state(name, &state)) < 0) { fprintf(stderr, "cannot get bustate, " "something is seriously wrong\n"); - goto err_out; + return -1; } else if (state != CAN_STATE_BUS_OFF) { fprintf(stderr, "Device is not in BUS_OFF," " no use to restart\n"); - goto err_out; + return -1; } if ((can_get_restart_ms(name, &restart_ms)) < 0) { fprintf(stderr, "cannot get restart_ms, " "something is seriously wrong\n"); - goto err_out; + return -1; } else if (restart_ms > 0) { fprintf(stderr, "auto restart with %ums interval is turned on," " no use to restart\n", restart_ms); - goto err_out; + return -1; } struct req_info req_info = { .restart = 1, }; - err = set_link(name, 0, &req_info); - -err_out: - return err; + return set_link(name, 0, &req_info); } /** From c503a5bc6058acc7f342e2a0acfb90f1c18b8df9 Mon Sep 17 00:00:00 2001 From: Robert Schwebel Date: Wed, 19 Mar 2014 09:43:43 +0100 Subject: [PATCH 77/88] configure.ac: add hints from autoupdate Signed-off-by: Robert Schwebel Signed-off-by: Marc Kleine-Budde --- configure.ac | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/configure.ac b/configure.ac index fb9253b6..ec838334 100644 --- a/configure.ac +++ b/configure.ac @@ -1,6 +1,6 @@ # -*- Autoconf -*- # Process this file with autoconf to produce a configure script. -AC_PREREQ(2.59) +AC_PREREQ([2.69]) AC_INIT([libsocketcan], [trunk], [bugs@pengutronix.de]) AC_CONFIG_HEADERS([include/libsocketcan_config.h]) @@ -31,13 +31,7 @@ AC_SUBST(LT_AGE) # Checks for programs. # AC_PROG_CC -dnl AM_MISSING_PROG(PERL, perl, $missing_dir) -# libtool, old: -AC_LIBTOOL_WIN32_DLL -dnl AC_LIBTOOL_TAGS([]) -AC_PROG_LIBTOOL -# libtool, new: -dnl LT_INIT(win32-dll) +LT_INIT(win32-dll) AM_INIT_AUTOMAKE([foreign no-exeext dist-bzip2]) m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) @@ -80,7 +74,6 @@ AC_HEADER_TIME # Checks for library functions. # AC_FUNC_MEMCMP -AC_TYPE_SIGNAL AC_FUNC_STAT AC_FUNC_UTIME_NULL AC_CHECK_FUNCS([gethostbyaddr gethostbyname gethostname gettimeofday memset mkdir socket utime]) From c2f7f8e9b2f15431fb801eab479bd0196031c524 Mon Sep 17 00:00:00 2001 From: Marc Kleine-Budde Date: Wed, 19 Mar 2014 09:44:25 +0100 Subject: [PATCH 78/88] autogen-oldtools.sh: remove Signed-off-by: Marc Kleine-Budde --- autogen-oldtools.sh | 45 --------------------------------------------- 1 file changed, 45 deletions(-) delete mode 100755 autogen-oldtools.sh diff --git a/autogen-oldtools.sh b/autogen-oldtools.sh deleted file mode 100755 index cbb9522a..00000000 --- a/autogen-oldtools.sh +++ /dev/null @@ -1,45 +0,0 @@ -#!/bin/bash - -# -# usage: -# -# banner -# -banner() { - - echo - TG=`echo $1 | sed -e "s,/.*/,,g"` - LINE=`echo $TG |sed -e "s/./-/g"` - echo $LINE - echo $TG - echo $LINE - echo -} - - -ACLOCAL=${ACLOCAL:=aclocal} -AUTOHEADER=${AUTOHEADER:=autoheader} -AUTOMAKE=${AUTOMAKE:=automake} -AUTOCONF=${AUTOCONF:=autoconf} - -banner "running libtoolize" -libtoolize --force -[ $? != 0 ] && exit - -banner "running aclocal" -$ACLOCAL -I config/m4 -[ $? != 0 ] && exit - -banner "running autoheader" -$AUTOHEADER -[ $? != 0 ] && exit - -banner "running automake" -$AUTOMAKE --gnu --add-missing -Wall -[ $? != 0 ] && exit - -banner "running autoconf" -$AUTOCONF -Wall -[ $? != 0 ] && exit - -banner "Finished" From 51f1610160a1707f026f8c2d714a6f7aa3ca232b Mon Sep 17 00:00:00 2001 From: Marc Kleine-Budde Date: Wed, 19 Mar 2014 10:12:35 +0100 Subject: [PATCH 79/88] v0.0.10 Signed-off-by: Marc Kleine-Budde --- configure.ac | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index ec838334..0160d37e 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ([2.69]) -AC_INIT([libsocketcan], [trunk], [bugs@pengutronix.de]) +AC_INIT([libsocketcan], [0.0.10], [bugs@pengutronix.de]) AC_CONFIG_HEADERS([include/libsocketcan_config.h]) AC_CONFIG_SRCDIR([src/libsocketcan.c]) AC_CONFIG_MACRO_DIR([config/m4]) @@ -20,7 +20,7 @@ CFLAGS="${CFLAGS} -Wall" # Interfaces added: AGE++ # Interfaces removed: AGE=0 LT_CURRENT=4 -LT_REVISION=0 +LT_REVISION=1 LT_AGE=2 AC_SUBST(LT_CURRENT) AC_SUBST(LT_REVISION) From 4608afb987149a131f4508184e53a4554616a8a8 Mon Sep 17 00:00:00 2001 From: Marc Kleine-Budde Date: Mon, 24 Mar 2014 10:33:24 +0100 Subject: [PATCH 80/88] configure: back to trunk Signed-off-by: Marc Kleine-Budde --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 0160d37e..492da2cc 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ([2.69]) -AC_INIT([libsocketcan], [0.0.10], [bugs@pengutronix.de]) +AC_INIT([libsocketcan], [trunk], [bugs@pengutronix.de]) AC_CONFIG_HEADERS([include/libsocketcan_config.h]) AC_CONFIG_SRCDIR([src/libsocketcan.c]) AC_CONFIG_MACRO_DIR([config/m4]) From 0c91940da1c16e01e8220e9fa18c703852ba6d1b Mon Sep 17 00:00:00 2001 From: Marc Kleine-Budde Date: Mon, 24 Mar 2014 10:07:52 +0100 Subject: [PATCH 81/88] GNUmakefile: include LICENSE file in tarball Reported-by: Yegor Yefremov Signed-off-by: Marc Kleine-Budde --- GNUmakefile.am | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/GNUmakefile.am b/GNUmakefile.am index 687ff44f..ca4fbda9 100644 --- a/GNUmakefile.am +++ b/GNUmakefile.am @@ -27,8 +27,10 @@ MAINTAINERCLEANFILES = \ config/m4/lt~obsolete.m4 \ $(DIST_ARCHIVES) -dist_doc_DATA = INSTALL \ - README +dist_doc_DATA = \ + INSTALL \ + LICENSE \ + README maintainer-clean-local: -chmod -R a+rw $(distdir) From 5938ac70cb46673fd8ca47d217db3e4b1ddea31a Mon Sep 17 00:00:00 2001 From: Nikita Edward Baruzdin Date: Mon, 21 Jul 2014 13:43:19 +0400 Subject: [PATCH 82/88] Update CAN netlink header Signed-off-by: Nikita Edward Baruzdin Signed-off-by: Marc Kleine-Budde --- include/can_netlink.h | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/include/can_netlink.h b/include/can_netlink.h index 31cfa6ae..3e4323a3 100644 --- a/include/can_netlink.h +++ b/include/can_netlink.h @@ -5,19 +5,25 @@ * * Copyright (c) 2009 Wolfgang Grandegger * - * Send feedback to + * This program is free software; you can redistribute it and/or modify + * it under the terms of the version 2 of the GNU General Public License + * as published by the Free Software Foundation * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. */ -#ifndef CAN_NETLINK_H -#define CAN_NETLINK_H +#ifndef _UAPI_CAN_NETLINK_H +#define _UAPI_CAN_NETLINK_H #include /* * CAN bit-timing parameters * - * For futher information, please read chapter "8 BIT TIMING + * For further information, please read chapter "8 BIT TIMING * REQUIREMENTS" of the "Bosch CAN Specification version 2.0" * at http://www.semiconductors.bosch.de/pdf/can2spec.pdf. */ @@ -85,11 +91,13 @@ struct can_ctrlmode { __u32 flags; }; -#define CAN_CTRLMODE_LOOPBACK 0x01 /* Loopback mode */ -#define CAN_CTRLMODE_LISTENONLY 0x02 /* Listen-only mode */ -#define CAN_CTRLMODE_3_SAMPLES 0x04 /* Triple sampling mode */ -#define CAN_CTRLMODE_ONE_SHOT 0x08 /* One-Shot mode */ -#define CAN_CTRLMODE_BERR_REPORTING 0x10 /* Bus-error reporting */ +#define CAN_CTRLMODE_LOOPBACK 0x01 /* Loopback mode */ +#define CAN_CTRLMODE_LISTENONLY 0x02 /* Listen-only mode */ +#define CAN_CTRLMODE_3_SAMPLES 0x04 /* Triple sampling mode */ +#define CAN_CTRLMODE_ONE_SHOT 0x08 /* One-Shot mode */ +#define CAN_CTRLMODE_BERR_REPORTING 0x10 /* Bus-error reporting */ +#define CAN_CTRLMODE_FD 0x20 /* CAN FD mode */ +#define CAN_CTRLMODE_PRESUME_ACK 0x40 /* Ignore missing CAN ACKs */ /* * CAN device statistics @@ -116,9 +124,11 @@ enum { IFLA_CAN_RESTART_MS, IFLA_CAN_RESTART, IFLA_CAN_BERR_COUNTER, + IFLA_CAN_DATA_BITTIMING, + IFLA_CAN_DATA_BITTIMING_CONST, __IFLA_CAN_MAX }; #define IFLA_CAN_MAX (__IFLA_CAN_MAX - 1) -#endif /* CAN_NETLINK_H */ +#endif /* !_UAPI_CAN_NETLINK_H */ From 4ea9ec7cf37a0c52f2c39a13887aaad11042ef5c Mon Sep 17 00:00:00 2001 From: Nikita Edward Baruzdin Date: Mon, 21 Jul 2014 13:43:20 +0400 Subject: [PATCH 83/88] Update can_set_ctrlmode() documentation Signed-off-by: Nikita Edward Baruzdin Signed-off-by: Marc Kleine-Budde --- src/libsocketcan.c | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/src/libsocketcan.c b/src/libsocketcan.c index fe3a0b37..c97a28cc 100644 --- a/src/libsocketcan.c +++ b/src/libsocketcan.c @@ -774,13 +774,20 @@ int can_set_restart_ms(const char *name, __u32 restart_ms) * * @param cm pointer of a can_ctrlmode struct * - * This sets the control mode of the can device. There're currently three - * different control modes: - * - LOOPBACK - * - LISTEN_ONLY - * - TRIPPLE_SAMPLING + * This sets the control mode of the can device. There are currently the + * following modes available (each mapped to its own macro): * - * You have to define the control mode struct yourself. a can_ctrlmode struct + * @code + * #define CAN_CTRLMODE_LOOPBACK 0x01 // Loopback mode + * #define CAN_CTRLMODE_LISTENONLY 0x02 // Listen-only mode + * #define CAN_CTRLMODE_3_SAMPLES 0x04 // Triple sampling mode + * #define CAN_CTRLMODE_ONE_SHOT 0x08 // One-Shot mode + * #define CAN_CTRLMODE_BERR_REPORTING 0x10 // Bus-error reporting + * #define CAN_CTRLMODE_FD 0x20 // CAN FD mode + * #define CAN_CTRLMODE_PRESUME_ACK 0x40 // Ignore missing CAN ACKs + * @endcode + * + * You have to define the control mode struct yourself. A can_ctrlmode struct * is declared as: * * @code @@ -791,16 +798,8 @@ int can_set_restart_ms(const char *name, __u32 restart_ms) * @endcode * * You can use mask to select modes you want to control and flags to determine - * if you want to turn the selected mode(s) on or off. Every control mode is - * mapped to an own macro - * - * @code - * #define CAN_CTRLMODE_LOOPBACK 0x1 - * #define CAN_CTRLMODE_LISTENONLY 0x2 - * #define CAN_CTRLMODE_3_SAMPLES 0x4 - * @endcode - * - * e.g. the following pseudocode + * if you want to turn the selected mode(s) on or off. E. g. the following + * pseudocode will turn the loopback mode on and listenonly mode off: * * @code * struct can_ctrlmode cm; @@ -810,8 +809,6 @@ int can_set_restart_ms(const char *name, __u32 restart_ms) * can_set_ctrlmode(candev, &cm); * @endcode * - * will turn the loopback mode on and listenonly mode off. - * * @return 0 if success * @return -1 if failed */ From f5392c365447706f772559942ddd6dc9e1d21a07 Mon Sep 17 00:00:00 2001 From: Leo Ruan Date: Sat, 4 Aug 2018 20:07:40 +0200 Subject: [PATCH 84/88] Fix parse_rtattr() does not completely initialize Because max is the index of the last element in array tb, max+1 elements need to be initialized. Signed-off-by: Leo Ruan Signed-off-by: Mark Jonas Signed-off-by: Marc Kleine-Budde --- src/libsocketcan.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/libsocketcan.c b/src/libsocketcan.c index c97a28cc..093b64a1 100644 --- a/src/libsocketcan.c +++ b/src/libsocketcan.c @@ -74,10 +74,18 @@ struct req_info { struct can_bittiming *bittiming; }; +/** + * @brief this method parse attributions of link info + * + * @param tb: point array of struct rtattr point + * @param max: index of the last element in array tb + * @param rtattr: point of link info data + * @param len: length of link info data + */ static void parse_rtattr(struct rtattr **tb, int max, struct rtattr *rta, int len) { - memset(tb, 0, sizeof(*tb) * max); + memset(tb, 0, sizeof(*tb) * (max + 1)); while (RTA_OK(rta, len)) { if (rta->rta_type <= max) { tb[rta->rta_type] = rta; From 6f13cefafe48f5d7a33ccbb45ce15b1417e1f4d6 Mon Sep 17 00:00:00 2001 From: Leo Ruan Date: Sat, 4 Aug 2018 20:07:41 +0200 Subject: [PATCH 85/88] Get link information only from specified interface libsocketcan always retrieves link information from all interfaces instead of only specified one. This commit fixes the issue by appending an interface information to dump request netlink message. See man 7 rtnetlink for detail description in section 'RTM_GETLINK'. Signed-off-by: Leo Ruan Signed-off-by: Mark Jonas Signed-off-by: Marc Kleine-Budde --- src/libsocketcan.c | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/src/libsocketcan.c b/src/libsocketcan.c index 093b64a1..a44728da 100644 --- a/src/libsocketcan.c +++ b/src/libsocketcan.c @@ -57,7 +57,7 @@ struct get_req { struct nlmsghdr n; - struct rtgenmsg g; + struct ifinfomsg i; }; struct set_req { @@ -229,13 +229,14 @@ static int send_mod_request(int fd, struct nlmsghdr *n) * @brief send_dump_request - send a dump linkinfo request * * @param fd decriptor to a priorly opened netlink socket + * @param name network interface name, null means all interfaces * @param family rt_gen message family * @param type netlink message header type * * @return 0 if success * @return negativ if failed */ -static int send_dump_request(int fd, int family, int type) +static int send_dump_request(int fd, const char *name, int family, int type) { struct get_req req; @@ -243,11 +244,25 @@ static int send_dump_request(int fd, int family, int type) req.n.nlmsg_len = sizeof(req); req.n.nlmsg_type = type; - req.n.nlmsg_flags = NLM_F_REQUEST | NLM_F_ROOT | NLM_F_MATCH; + req.n.nlmsg_flags = NLM_F_REQUEST; req.n.nlmsg_pid = 0; req.n.nlmsg_seq = 0; - req.g.rtgen_family = family; + req.i.ifi_family = family; + /* + * If name is null, set flag to dump link information from all + * interfaces otherwise, just dump specified interface's link + * information. + */ + if (name == NULL) { + req.n.nlmsg_flags |= NLM_F_DUMP; + } else { + req.i.ifi_index = if_nametoindex(name); + if (req.i.ifi_index == 0) { + fprintf(stderr, "Cannot find device \"%s\"\n", name); + return -1; + } + } return send(fd, (void *)&req, sizeof(req), 0); } @@ -353,7 +368,7 @@ static int do_get_nl_link(int fd, __u8 acquire, const char *name, void *res) struct rtattr *linkinfo[IFLA_INFO_MAX + 1]; struct rtattr *can_attr[IFLA_CAN_MAX + 1]; - if (send_dump_request(fd, AF_PACKET, RTM_GETLINK) < 0) { + if (send_dump_request(fd, name, AF_PACKET, RTM_GETLINK) < 0) { perror("Cannot send dump request"); return ret; } @@ -387,8 +402,10 @@ static int do_get_nl_link(int fd, __u8 acquire, const char *name, void *res) nl_msg->nlmsg_len - NLMSG_LENGTH(sizeof(struct ifaddrmsg)); parse_rtattr(tb, IFLA_MAX, IFLA_RTA(ifi), len); - if (strcmp - ((char *)RTA_DATA(tb[IFLA_IFNAME]), name) != 0) + /* Finish process if the reply message is matched */ + if (strcmp((char *)RTA_DATA(tb[IFLA_IFNAME]), name) == 0) + done++; + else continue; if (tb[IFLA_LINKINFO]) From 9679a3f50a14b2c864889c6da56a7cdbaa7b1f9b Mon Sep 17 00:00:00 2001 From: Leo Ruan Date: Sat, 4 Aug 2018 20:07:42 +0200 Subject: [PATCH 86/88] Add interface to retrieve link statistics This commit adds an interface to get the statistics (64-bits) from CAN interface. See more information from /usr/include/linux/if_link.h where defines the struct rtnl_link_stats64. Compare to the rtnl_link_stats, rtnl_link_stats64 was introduced since linux kernel 2.6. After that the rtnl_link_stats is synchronous with struct rtnl_link_stats64 by truncating each member from 64 bits to 32 bits. Actually, the struct rtnl_link_stats is kept for compatibility. Signed-off-by: Leo Ruan Signed-off-by: Mark Jonas Signed-off-by: Marc Kleine-Budde --- include/libsocketcan.h | 3 +++ src/libsocketcan.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/include/libsocketcan.h b/include/libsocketcan.h index dc52053b..1603a7b7 100644 --- a/include/libsocketcan.h +++ b/include/libsocketcan.h @@ -28,6 +28,8 @@ #include +struct rtnl_link_stats64; /* from */ + #ifdef __cplusplus extern "C" { #endif @@ -50,6 +52,7 @@ int can_get_clock(const char *name, struct can_clock *clock); int can_get_bittiming_const(const char *name, struct can_bittiming_const *btc); int can_get_berr_counter(const char *name, struct can_berr_counter *bc); int can_get_device_stats(const char *name, struct can_device_stats *cds); +int can_get_link_stats(const char *name, struct rtnl_link_stats64 *rls); #ifdef __cplusplus } diff --git a/src/libsocketcan.c b/src/libsocketcan.c index a44728da..a1a47179 100644 --- a/src/libsocketcan.c +++ b/src/libsocketcan.c @@ -30,6 +30,7 @@ #include #include +#include #include #include @@ -54,6 +55,7 @@ #define GET_BITTIMING_CONST 6 #define GET_BERR_COUNTER 7 #define GET_XSTATS 8 +#define GET_LINK_STATS 9 struct get_req { struct nlmsghdr n; @@ -408,6 +410,16 @@ static int do_get_nl_link(int fd, __u8 acquire, const char *name, void *res) else continue; + if (acquire == GET_LINK_STATS) { + if (!tb[IFLA_STATS64]) { + fprintf(stderr, "no link statistics (64-bit) found\n"); + } else { + memcpy(res, RTA_DATA(tb[IFLA_STATS64]), sizeof(struct rtnl_link_stats64)); + ret = 0; + } + continue; + } + if (tb[IFLA_LINKINFO]) parse_rtattr_nested(linkinfo, IFLA_INFO_MAX, tb[IFLA_LINKINFO]); @@ -1157,3 +1169,29 @@ int can_get_device_stats(const char *name, struct can_device_stats *cds) { return get_link(name, GET_XSTATS, cds); } + +/** + * @ingroup extern + * can_get_link_statistics - get RX/TX statistics (64 bits version) + * + * @param name name of the can device. This is the netdev name, as ip link shows + * in your system. usually it contains prefix "can" and the number of the can + * line. e.g. "can0" + * @param rls pointer to the rtnl_link_stats64 struct which is from if_link.h. + * + * This one gets the current rtnl_link_stats64. Compares to the rtnl_link_stats, + * The rtnl_link_stats64 is introduced since linux kernel 2.6. After that the + * rtnl_link_stats is synchronous with struct rtnl_link_stats64 by truncating + * each member from 64 bits to 32 bits. actually, the struct rtnl_link_stats + * is kept for compatibility. + * + * Please see struct rtnl_link_stats64 (/usr/include/linux/if_link.h) for more + * information. + * + * @return 0 if success + * @return -1 if failed + */ +int can_get_link_stats(const char *name, struct rtnl_link_stats64 *rls) +{ + return get_link(name, GET_LINK_STATS, rls); +} From 15af38a25c679d3ed0f72bbc1109c6b34a959c39 Mon Sep 17 00:00:00 2001 From: Leo Ruan Date: Sat, 4 Aug 2018 20:07:43 +0200 Subject: [PATCH 87/88] Add compile option to disable error logging If you have an application stderr shall not be used by libsocketcan you can disable all error logging by defining DISABLE_ERROR_LOG. Signed-off-by: Leo Ruan Signed-off-by: Mark Jonas Signed-off-by: Marc Kleine-Budde --- src/libsocketcan.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/libsocketcan.c b/src/libsocketcan.c index a1a47179..5c7665ce 100644 --- a/src/libsocketcan.c +++ b/src/libsocketcan.c @@ -36,6 +36,12 @@ #include +/* Define DISABLE_ERROR_LOG to disable printing of error messages to stderr. */ +#ifdef DISABLE_ERROR_LOG +#define perror(x) +#define fprintf(...) +#endif + #define parse_rtattr_nested(tb, max, rta) \ (parse_rtattr((tb), (max), RTA_DATA(rta), RTA_PAYLOAD(rta))) From b217774ca825ba449ddb27e2bc9be6f3b8cad9b1 Mon Sep 17 00:00:00 2001 From: Mark Jonas Date: Thu, 9 Aug 2018 10:59:05 +0200 Subject: [PATCH 88/88] Add configure switch for error logging For keeping backwards compatibility the configure switch --enable-error-log is enabled by default. To disable error logging use --enable-error-log=no. Signed-off-by: Mark Jonas Signed-off-by: Marc Kleine-Budde --- configure.ac | 17 +++++++++++++++++ src/libsocketcan.c | 4 ++++ 2 files changed, 21 insertions(+) diff --git a/configure.ac b/configure.ac index 492da2cc..9a807ec8 100644 --- a/configure.ac +++ b/configure.ac @@ -99,6 +99,23 @@ else fi +# +# Error logging +# +AC_MSG_CHECKING([whether to enable error logging]) +AC_ARG_ENABLE(error-log, + AS_HELP_STRING([--enable-error-log], [enable error log @<:@default=yes@:>@]), + [case "$enableval" in + y | yes) CONFIG_ERROR_LOG=yes ;; + *) CONFIG_ERROR_LOG=no ;; + esac], + [CONFIG_ERROR_LOG=yes]) +AC_MSG_RESULT([${CONFIG_ERROR_LOG}]) +if test "${CONFIG_ERROR_LOG}" = "no"; then + AC_DEFINE(DISABLE_ERROR_LOG, 1, [disable error logging]) +fi + + AC_CONFIG_FILES([ GNUmakefile config/libsocketcan.pc diff --git a/src/libsocketcan.c b/src/libsocketcan.c index 5c7665ce..c802849f 100644 --- a/src/libsocketcan.c +++ b/src/libsocketcan.c @@ -22,6 +22,10 @@ * @brief library code */ +#ifdef HAVE_CONFIG_H +#include "libsocketcan_config.h" +#endif + #include #include #include