Module Name:    src
Committed By:   bouyer
Date:           Thu Apr 20 12:59:54 UTC 2017

Modified Files:
        src/sbin/canconfig [bouyer-socketcan]: canconfig.8 canconfig.c

Log Message:
Implement listenonly and loopback flags.
Fix do_canflag()


To generate a diff of this commit:
cvs rdiff -u -r1.1.2.1 -r1.1.2.2 src/sbin/canconfig/canconfig.8
cvs rdiff -u -r1.1.2.2 -r1.1.2.3 src/sbin/canconfig/canconfig.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/canconfig/canconfig.8
diff -u src/sbin/canconfig/canconfig.8:1.1.2.1 src/sbin/canconfig/canconfig.8:1.1.2.2
--- src/sbin/canconfig/canconfig.8:1.1.2.1	Mon Apr 17 20:48:36 2017
+++ src/sbin/canconfig/canconfig.8	Thu Apr 20 12:59:54 2017
@@ -1,4 +1,4 @@
-.\"	$NetBSD: canconfig.8,v 1.1.2.1 2017/04/17 20:48:36 bouyer Exp $
+.\"	$NetBSD: canconfig.8,v 1.1.2.2 2017/04/20 12:59:54 bouyer Exp $
 .\"
 .\" Copyright (c) 2017 Manuel Bouyer.
  *
@@ -100,6 +100,16 @@ set the number of tq for the Synchronisa
 enables triple-sampling.
 .It Cm -3samples
 disables triple-sampling.
+.It Cm listenonly
+enables listenonly mode. In this mode the controller is passive, and
+doesn't send ACKs on the bus.
+.It Cm -listenonly
+disables listenonly mode.
+.It Cm loopback
+enables loopback mode. In this mode, the controller doens't expect ACK from
+the bus.
+.It Cm -loopback
+disables loopback mode.
 .El
 .Sh EXAMPLES
 TODO

Index: src/sbin/canconfig/canconfig.c
diff -u src/sbin/canconfig/canconfig.c:1.1.2.2 src/sbin/canconfig/canconfig.c:1.1.2.3
--- src/sbin/canconfig/canconfig.c:1.1.2.2	Wed Apr 19 17:51:16 2017
+++ src/sbin/canconfig/canconfig.c	Thu Apr 20 12:59:54 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: canconfig.c,v 1.1.2.2 2017/04/19 17:51:16 bouyer Exp $	*/
+/*	$NetBSD: canconfig.c,v 1.1.2.3 2017/04/20 12:59:54 bouyer Exp $	*/
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -38,7 +38,7 @@
 #include <sys/cdefs.h>
 
 #ifndef lint
-__RCSID("$NetBSD: canconfig.c,v 1.1.2.2 2017/04/19 17:51:16 bouyer Exp $");
+__RCSID("$NetBSD: canconfig.c,v 1.1.2.3 2017/04/20 12:59:54 bouyer Exp $");
 #endif
 
 
@@ -77,6 +77,8 @@ static void	cmd_phase_seg1(const struct 
 static void	cmd_phase_seg2(const struct command *, int, const char *, char **);
 static void	cmd_sjw(const struct command *, int, const char *, char **);
 static void	cmd_3samples(const struct command *, int, const char *, char **);
+static void	cmd_listenonly(const struct command *, int, const char *, char **);
+static void	cmd_loopback(const struct command *, int, const char *, char **);
 
 static const struct command command_table[] = {
 	{ "up",			0,	0,		cmd_up },
@@ -91,6 +93,12 @@ static const struct command command_tabl
 	{ "3samples",		0,	0,		cmd_3samples },
 	{ "-3samples",		0,	CMD_INVERT,	cmd_3samples },
 
+	{ "listenonly",		0,	0,		cmd_listenonly },
+	{ "-listenonly",	0,	CMD_INVERT,	cmd_listenonly },
+
+	{ "loopback",		0,	0,		cmd_loopback },
+	{ "-loopback",		0,	CMD_INVERT,	cmd_loopback },
+
 	{ NULL,			0,	0,		NULL },
 };
 
@@ -225,6 +233,8 @@ usage(void)
 		"<canif> phase_seg2 <value>",
 		"<canif> sjw <value>",
 		"<canif> 3samples | -3samples",
+		"<canif> listenonly | -listenonly",
+		"<canif> loopback | -loopback",
 		NULL,
 	};
 	extern const char *__progname;
@@ -353,7 +363,7 @@ show_timings(int sock, const char *canif
 	printb("capabilities", cltc.cltc_linkmode_caps, CAN_IFFBITS);
 	printf("\n");
 	printf("%soperational timings:\n", prefix);
-	printf("%s  brp %d prop_seg %d, phase_seg1 %d, phase_seg2 %d, sjw %d\n",
+	printf("%s  brp %d, prop_seg %d, phase_seg1 %d, phase_seg2 %d, sjw %d\n",
 	    prefix,
 	    clt.clt_brp, clt.clt_prop, clt.clt_ps1, clt.clt_ps2, clt.clt_sjw);
 	printf("%s  ", prefix);
@@ -418,7 +428,7 @@ do_canflag(int sock, const char *canifna
 		cmd = CANSLINKMODE;
 	else
 		cmd = CANCLINKMODE;
-	return do_cmd(sock, canifname, cmd, &flag, sizeof(flag), set);
+	return do_cmd(sock, canifname, cmd, &flag, sizeof(flag), 1);
 }
 
 static void
@@ -506,7 +516,6 @@ cmd_sjw(const struct command *cmd, int s
 	g_clt.clt_sjw = val;
 	g_clt_updated=1;
 }
-
 static void
 cmd_3samples(const struct command *cmd, int sock, const char *canifname,
     char **argv)
@@ -516,3 +525,23 @@ cmd_3samples(const struct command *cmd, 
 		err(1, "%s", cmd->cmd_keyword);
 
 }
+
+static void
+cmd_listenonly(const struct command *cmd, int sock, const char *canifname,
+    char **argv)
+{
+        if (do_canflag(sock, canifname, CAN_LINKMODE_LISTENONLY,
+	    (cmd->cmd_flags & CMD_INVERT) ? 0 : 1) < 0)
+		err(1, "%s", cmd->cmd_keyword);
+
+}
+
+static void
+cmd_loopback(const struct command *cmd, int sock, const char *canifname,
+    char **argv)
+{
+        if (do_canflag(sock, canifname, CAN_LINKMODE_LOOPBACK,
+	    (cmd->cmd_flags & CMD_INVERT) ? 0 : 1) < 0)
+		err(1, "%s", cmd->cmd_keyword);
+
+}

Reply via email to