Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/bouyer-socketcan]: src Add canconfig(8), an utility to configure CAN int...



details:   https://anonhg.NetBSD.org/src/rev/e099295aaae0
branches:  bouyer-socketcan
changeset: 820877:e099295aaae0
user:      bouyer <bouyer%NetBSD.org@localhost>
date:      Mon Apr 17 20:48:35 2017 +0000

description:
Add canconfig(8), an utility to configure CAN interfaces.
Compile-tested only.

diffstat:

 distrib/sets/lists/base/mi  |    3 +-
 distrib/sets/lists/debug/mi |    3 +-
 distrib/sets/lists/man/mi   |    5 +-
 sbin/Makefile               |    7 +-
 sbin/canconfig/Makefile     |    6 +
 sbin/canconfig/canconfig.8  |  118 ++++++++++
 sbin/canconfig/canconfig.c  |  517 ++++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 653 insertions(+), 6 deletions(-)

diffs (truncated from 741 to 300 lines):

diff -r 73d154199696 -r e099295aaae0 distrib/sets/lists/base/mi
--- a/distrib/sets/lists/base/mi        Mon Apr 17 20:41:55 2017 +0000
+++ b/distrib/sets/lists/base/mi        Mon Apr 17 20:48:35 2017 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1150.2.1 2017/04/17 20:35:00 bouyer Exp $
+# $NetBSD: mi,v 1.1150.2.2 2017/04/17 20:48:36 bouyer Exp $
 #
 # Note:        Don't delete entries from here - mark them as "obsolete" instead,
 #      unless otherwise stated below.
@@ -445,6 +445,7 @@
 ./sbin/blacklistctl                            base-sysutil-root
 ./sbin/blacklistd                              base-sysutil-root
 ./sbin/brconfig                                        base-netutil-root
+./sbin/canconfig                               base-netutil-root
 ./sbin/ccdconfig                               base-sysutil-root
 ./sbin/cgdconfig                               base-sysutil-root
 ./sbin/chown                                   base-sysutil-root
diff -r 73d154199696 -r e099295aaae0 distrib/sets/lists/debug/mi
--- a/distrib/sets/lists/debug/mi       Mon Apr 17 20:41:55 2017 +0000
+++ b/distrib/sets/lists/debug/mi       Mon Apr 17 20:48:35 2017 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.191.2.1 2017/04/17 20:35:00 bouyer Exp $
+# $NetBSD: mi,v 1.191.2.2 2017/04/17 20:48:36 bouyer Exp $
 ./etc/mtree/set.debug                           comp-sys-root
 ./usr/lib                                      comp-sys-usr            compatdir
 ./usr/lib/i18n/libBIG5_g.a                     comp-c-debuglib         debuglib,compatfile
@@ -307,6 +307,7 @@
 ./usr/libdata/debug/sbin/blacklistctl.debug    comp-sysutil-debug      debug
 ./usr/libdata/debug/sbin/blacklistd.debug      comp-sysutil-debug      debug
 ./usr/libdata/debug/sbin/brconfig.debug                comp-netutil-debug      debug
+./usr/libdata/debug/sbin/canconfig.debug       comp-netutil-debug      debug
 ./usr/libdata/debug/sbin/ccdconfig.debug       comp-sysutil-debug      debug
 ./usr/libdata/debug/sbin/cgdconfig.debug       comp-sysutil-debug      debug
 ./usr/libdata/debug/sbin/chown.debug           comp-sysutil-debug      debug
diff -r 73d154199696 -r e099295aaae0 distrib/sets/lists/man/mi
--- a/distrib/sets/lists/man/mi Mon Apr 17 20:41:55 2017 +0000
+++ b/distrib/sets/lists/man/mi Mon Apr 17 20:48:35 2017 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1545 2017/01/07 20:49:23 christos Exp $
+# $NetBSD: mi,v 1.1545.2.1 2017/04/17 20:48:36 bouyer Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -2365,6 +2365,7 @@
 ./usr/share/man/cat8/bounce.0                  man-postfix-catman      postfix,.cat
 ./usr/share/man/cat8/bozohttpd.0               man-netutil-catman      .cat
 ./usr/share/man/cat8/brconfig.0                        man-netutil-catman      .cat
+./usr/share/man/cat8/canconfig.0               man-netutil-catman      .cat
 ./usr/share/man/cat8/btattach.0                        man-sysutil-catman      .cat
 ./usr/share/man/cat8/btconfig.0                        man-sysutil-catman      .cat
 ./usr/share/man/cat8/btcontrol.0               man-obsolete            obsolete
@@ -5337,6 +5338,7 @@
 ./usr/share/man/html8/bounce.html              man-postfix-htmlman     postfix,html
 ./usr/share/man/html8/bozohttpd.html           man-netutil-htmlman     html
 ./usr/share/man/html8/brconfig.html            man-netutil-htmlman     html
+./usr/share/man/html8/canconfig.html           man-netutil-htmlman     html
 ./usr/share/man/html8/btattach.html            man-sysutil-htmlman     html
 ./usr/share/man/html8/btconfig.html            man-sysutil-htmlman     html
 ./usr/share/man/html8/btdevctl.html            man-sysutil-htmlman     html
@@ -8344,6 +8346,7 @@
 ./usr/share/man/man8/bounce.8                  man-postfix-man         postfix,.man
 ./usr/share/man/man8/bozohttpd.8               man-netutil-man         .man
 ./usr/share/man/man8/brconfig.8                        man-netutil-man         .man
+./usr/share/man/man8/canconfig.8               man-netutil-man         .man
 ./usr/share/man/man8/btattach.8                        man-sysutil-man         .man
 ./usr/share/man/man8/btconfig.8                        man-sysutil-man         .man
 ./usr/share/man/man8/btcontrol.8               man-obsolete            obsolete
diff -r 73d154199696 -r e099295aaae0 sbin/Makefile
--- a/sbin/Makefile     Mon Apr 17 20:41:55 2017 +0000
+++ b/sbin/Makefile     Mon Apr 17 20:48:35 2017 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.129 2016/07/01 22:50:50 christos Exp $
+#      $NetBSD: Makefile,v 1.129.4.1 2017/04/17 20:48:35 bouyer Exp $
 #      @(#)Makefile    8.5 (Berkeley) 3/31/94
 
 # Not ported: XNSrouted enpload scsiformat startslip
@@ -6,8 +6,9 @@
 
 .include <bsd.own.mk>
 
-SUBDIR=        amrctl apmlabel atactl badsect bioctl brconfig ccdconfig cgdconfig \
-       chown devpubd disklabel dkctl dkscan_bsdlabel dmesg dmctl \
+SUBDIR=        amrctl apmlabel atactl badsect bioctl brconfig \
+       canconfig ccdconfig cgdconfig chown \
+       devpubd disklabel dkctl dkscan_bsdlabel dmesg dmctl \
        drvctl fastboot fdisk fsck fsirand gpt ifconfig init ldconfig luactl \
        mbrlabel mknod modload modstat modunload mount \
        newbtconf nologin nvmectl \
diff -r 73d154199696 -r e099295aaae0 sbin/canconfig/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sbin/canconfig/Makefile   Mon Apr 17 20:48:35 2017 +0000
@@ -0,0 +1,6 @@
+#      $NetBSD: Makefile,v 1.1.2.1 2017/04/17 20:48:36 bouyer Exp $
+
+PROG=  canconfig
+MAN=   canconfig.8
+
+.include <bsd.prog.mk>
diff -r 73d154199696 -r e099295aaae0 sbin/canconfig/canconfig.8
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sbin/canconfig/canconfig.8        Mon Apr 17 20:48:35 2017 +0000
@@ -0,0 +1,118 @@
+.\"    $NetBSD: canconfig.8,v 1.1.2.1 2017/04/17 20:48:36 bouyer Exp $
+.\"
+.\" Copyright (c) 2017 Manuel Bouyer.
+ *
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+ *
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.    
+.\"
+.Dd Apris 15, 2017
+.Dt CANCONFIG 8
+.Os
+.Sh NAME
+.Nm canconfig
+.Nd configure CAN network interface parameters
+.Sh SYNOPSIS
+.Nm
+.Fl a
+.Nm
+.Ar canif
+.Nm
+.Ar can
+.Ar command
+.Op Ar args ...
+.Sh DESCRIPTION
+The
+.Nm
+utility is used to configure CAN network interface parameters and retrieve
+CAN network interface parameters and status from the kernel.
+.Ss Timing
+.Pp
+The base time unit used to define the network bit rate is the time quanta (tq),
+its value is defined by the input clock freqency and the prescaler value
+as (1/ freq * prescaler).
+.Pp
+The network bit time is split in 4 segments:
+.Bl -tag -width "phase_seg1" -offset indent -compact
+.It sync_seg
+fixed to 1 tq
+.It prop_seg
+.It phase_seg1
+.It phase_seg2
+.El
+The network bit time is (1 + prop_seg + phase_seg1 + phase_seg2), in tq.
+The sample point is between phase_seg1 and phase_seg2.
+.Pp
+The receiver hardware is allowed to shorten prop_seg or phase_seg2 to
+resynchronise with the sender. The swj (Synchronisation Jump Width) parameter
+defines by how much the hardware can shorten these segments.
+.Pp
+Some hardware can use 3 sample points instead of one, and keep the majority as
+the final value.
+.Ss Options
+.Pp
+The options are as follows:
+.Bl -tag -width indent
+.It Fl a
+Display the status of all CAN devices present on the system.
+This flag is mutually exclusive with all other sub-commands.
+.El
+.Pp
+All other operations require that a CAN interface be specified.
+If a CAN interface is specified with no sub-commands,
+the status of that interface is displayed.
+.Pp
+The following sub-commands are available:
+.Pp
+.Bl -tag -width indent
+.It Cm up
+Start network operations on the interface. Requires that all timing parameters
+have been set.
+.It Cm down
+Stop network operations on the interface.
+.It Cm brp Ar value
+Set the value of the baud rate prescaler.
+.It Cm prop_seg Ar value
+set the number of tq for the propagation segment.
+.It Cm phase_seg1 Ar value
+set the number of tq for the phase segment 1.
+.It Cm phase_seg2 Ar value
+set the number of tq for the phase segment 2.
+.It Cm sjw Ar value
+set the number of tq for the Synchronisation Jump Width.
+.It Cm 3samples
+enables triple-sampling.
+.It Cm -3samples
+disables triple-sampling.
+.El
+.Sh EXAMPLES
+TODO
+.Sh SEE ALSO
+.Xr ifconfig.if 5 ,
+.Xr ifconfig 8 ,
+.Sh HISTORY
+The
+.Nm
+utility first appeared in
+.Nx 8.0 .
+.Sh AUTHORS
+This version of the
+.Nm
+utility was written by
+.An Manuel Bouyer .
diff -r 73d154199696 -r e099295aaae0 sbin/canconfig/canconfig.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sbin/canconfig/canconfig.c        Mon Apr 17 20:48:35 2017 +0000
@@ -0,0 +1,517 @@
+/*     $NetBSD: canconfig.c,v 1.1.2.1 2017/04/17 20:48:36 bouyer Exp $ */
+
+/*
+ * Copyright 2001 Wasabi Systems, Inc.
+ * All rights reserved.
+ *
+ * Written by Jason R. Thorpe for Wasabi Systems, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed for the NetBSD Project by
+ *     Wasabi Systems, Inc.
+ * 4. The name of Wasabi Systems, Inc. may not be used to endorse
+ *    or promote products derived from this software without specific prior
+ *    written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+
+#ifndef lint
+__RCSID("$NetBSD: canconfig.c,v 1.1.2.1 2017/04/17 20:48:36 bouyer Exp $");
+#endif
+
+
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <sys/ioctl.h>
+
+#include <net/if.h>
+#include <netcan/can.h>
+#include <netcan/can_link.h>
+#include <ifaddrs.h>
+
+#include <ctype.h>
+#include <err.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+struct command {
+       const char *cmd_keyword;
+       int     cmd_argcnt;
+       int     cmd_flags;
+       void    (*cmd_func)(const struct command *, int, const char *,
+                   char **);
+};
+
+#define        CMD_INVERT      0x01    /* "invert" the sense of the command */
+
+static void    cmd_up(const struct command *, int, const char *, char **);
+static void    cmd_down(const struct command *, int, const char *, char **);
+static void    cmd_brp(const struct command *, int, const char *, char **);
+static void    cmd_prop_seg(const struct command *, int, const char *, char **);
+static void    cmd_phase_seg1(const struct command *, int, const char *, char **);



Home | Main Index | Thread Index | Old Index