Source-Changes-HG archive

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

[src/bouyer-socketcan]: src/sys Initial commit of a CAN socket layer, compati...



details:   https://anonhg.NetBSD.org/src/rev/73862f0fb509
branches:  bouyer-socketcan
changeset: 820804:73862f0fb509
user:      bouyer <bouyer%NetBSD.org@localhost>
date:      Sun Jan 15 20:27:33 2017 +0000

description:
Initial commit of a CAN socket layer, compatible with linux SoccketCAN
(but incomplete). Based on work from Robert Swindells.

diffstat:

 sys/Makefile                                  |    4 +-
 sys/arch/emips/include/disklabel.h            |    2 +-
 sys/arch/x68k/include/cdefs.h                 |    2 +-
 sys/arch/x68k/include/cpufunc.h               |    2 +-
 sys/arch/x68k/include/ieeefp.h                |    2 +-
 sys/arch/x68k/include/profile.h               |    2 +-
 sys/arch/x68k/include/setjmp.h                |    2 +-
 sys/conf/files                                |    4 +-
 sys/net/netisr.h                              |    8 +-
 sys/net/netisr_dispatch.h                     |    5 +-
 sys/netcan/Makefile                           |    8 +
 sys/netcan/can.c                              |  697 ++++++++++++++++++++++++++
 sys/netcan/can.h                              |  133 ++++
 sys/netcan/can_pcb.c                          |  283 ++++++++++
 sys/netcan/can_pcb.h                          |   98 +++
 sys/netcan/can_proto.c                        |   75 ++
 sys/netcan/can_var.h                          |   56 ++
 sys/netcan/files.netcan                       |    8 +
 sys/netcan/if_canloop.c                       |  232 ++++++++
 sys/rump/include/opt/opt_rumpkernel.h         |    4 +-
 sys/rump/include/rump/rumpdefs.h              |    6 +-
 sys/rump/net/Makefile.rumpnetcomp             |    4 +-
 sys/rump/net/lib/libnetcan/Makefile           |   20 +
 sys/rump/net/lib/libnetcan/NETCAN.ioconf      |    7 +
 sys/rump/net/lib/libnetcan/netcan_component.c |   52 +
 sys/sys/socket.h                              |    6 +-
 26 files changed, 1704 insertions(+), 18 deletions(-)

diffs (truncated from 1950 to 300 lines):

diff -r 983357977eb1 -r 73862f0fb509 sys/Makefile
--- a/sys/Makefile      Sun Jan 15 18:15:45 2017 +0000
+++ b/sys/Makefile      Sun Jan 15 20:27:33 2017 +0000
@@ -1,9 +1,9 @@
-#      $NetBSD: Makefile,v 1.79 2013/03/01 18:25:27 joerg Exp $
+#      $NetBSD: Makefile,v 1.79.22.1 2017/01/15 20:27:33 bouyer Exp $
 
 .include <bsd.own.mk>
 
 SUBDIR=        altq arch compat dev fs miscfs \
-       net net80211 netatalk netbt netipsec netinet netinet6 \
+       net net80211 netatalk netbt netcan netipsec netinet netinet6 \
         netisdn netkey netmpls netnatm netsmb \
        nfs opencrypto sys ufs uvm
 
diff -r 983357977eb1 -r 73862f0fb509 sys/arch/emips/include/disklabel.h
--- a/sys/arch/emips/include/disklabel.h        Sun Jan 15 18:15:45 2017 +0000
+++ b/sys/arch/emips/include/disklabel.h        Sun Jan 15 20:27:33 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: disklabel.h,v 1.3 2013/05/16 19:06:44 christos Exp $   */
+/*     $NetBSD: disklabel.h,v 1.5 2013/05/16 19:06:44 christos Exp $   */
 
 /*
  * Copyright (c) 1994 Christopher G. Demetriou
diff -r 983357977eb1 -r 73862f0fb509 sys/arch/x68k/include/cdefs.h
--- a/sys/arch/x68k/include/cdefs.h     Sun Jan 15 18:15:45 2017 +0000
+++ b/sys/arch/x68k/include/cdefs.h     Sun Jan 15 20:27:33 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cdefs.h,v 1.1 1996/05/05 12:17:15 oki Exp $    */
+/*     $NetBSD: cdefs.h,v 1.1.1.1 1996/05/05 12:17:03 oki Exp $        */
 
 #ifndef _MACHINE_CDEFS_H_
 #define _MACHINE_CDEFS_H_
diff -r 983357977eb1 -r 73862f0fb509 sys/arch/x68k/include/cpufunc.h
--- a/sys/arch/x68k/include/cpufunc.h   Sun Jan 15 18:15:45 2017 +0000
+++ b/sys/arch/x68k/include/cpufunc.h   Sun Jan 15 20:27:33 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cpufunc.h,v 1.1 1996/05/05 12:17:15 oki Exp $  */
+/*     $NetBSD: cpufunc.h,v 1.1.1.1 1996/05/05 12:17:03 oki Exp $      */
 
 /*
  * Functions to provide access to special cpu instructions.
diff -r 983357977eb1 -r 73862f0fb509 sys/arch/x68k/include/ieeefp.h
--- a/sys/arch/x68k/include/ieeefp.h    Sun Jan 15 18:15:45 2017 +0000
+++ b/sys/arch/x68k/include/ieeefp.h    Sun Jan 15 20:27:33 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ieeefp.h,v 1.1 1996/05/05 12:17:14 oki Exp $   */
+/*     $NetBSD: ieeefp.h,v 1.1.1.1 1996/05/05 12:17:03 oki Exp $       */
 
 /* Just use the common m68k definition */
 #include <m68k/ieeefp.h>
diff -r 983357977eb1 -r 73862f0fb509 sys/arch/x68k/include/profile.h
--- a/sys/arch/x68k/include/profile.h   Sun Jan 15 18:15:45 2017 +0000
+++ b/sys/arch/x68k/include/profile.h   Sun Jan 15 20:27:33 2017 +0000
@@ -1,3 +1,3 @@
-/*     $NetBSD: profile.h,v 1.1 1996/05/05 12:17:14 oki Exp $  */
+/*     $NetBSD: profile.h,v 1.1.1.1 1996/05/05 12:17:03 oki Exp $      */
 
 #include <m68k/profile.h>
diff -r 983357977eb1 -r 73862f0fb509 sys/arch/x68k/include/setjmp.h
--- a/sys/arch/x68k/include/setjmp.h    Sun Jan 15 18:15:45 2017 +0000
+++ b/sys/arch/x68k/include/setjmp.h    Sun Jan 15 20:27:33 2017 +0000
@@ -1,3 +1,3 @@
-/*     $NetBSD: setjmp.h,v 1.1 1996/05/05 12:17:15 oki Exp $   */
+/*     $NetBSD: setjmp.h,v 1.1.1.1 1996/05/05 12:17:03 oki Exp $       */
 
 #include <m68k/setjmp.h>
diff -r 983357977eb1 -r 73862f0fb509 sys/conf/files
--- a/sys/conf/files    Sun Jan 15 18:15:45 2017 +0000
+++ b/sys/conf/files    Sun Jan 15 20:27:33 2017 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files,v 1.1168 2016/12/26 23:12:33 pgoyette Exp $
+#      $NetBSD: files,v 1.1168.2.1 2017/01/15 20:27:33 bouyer Exp $
 #      @(#)files.newconf       7.5 (Berkeley) 5/10/93
 
 version        20150846
@@ -229,6 +229,7 @@
 include "net80211/files.net80211"
 include "netatalk/files.netatalk"
 include "netbt/files.netbt"
+include "netcan/files.netcan"
 include "netinet/files.netinet"
 include "netinet6/files.netinet6"
 include "netipsec/files.netipsec"
@@ -1435,6 +1436,7 @@
 defpseudodev tap:      ifnet, ether, arp
 defpseudo carp:                ifnet, ether, arp
 defpseudodev etherip:  ifnet, ether, arp
+defpseudo canloop:     ifnet
 
 defpseudo sequencer
 defpseudo clockctl
diff -r 983357977eb1 -r 73862f0fb509 sys/net/netisr.h
--- a/sys/net/netisr.h  Sun Jan 15 18:15:45 2017 +0000
+++ b/sys/net/netisr.h  Sun Jan 15 20:27:33 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: netisr.h,v 1.44 2015/05/25 08:29:01 ozaki-r Exp $ */
+/* $NetBSD: netisr.h,v 1.44.4.1 2017/01/15 20:27:33 bouyer Exp $ */
 
 /*
  * Copyright (c) 1980, 1986, 1989, 1993
@@ -53,6 +53,7 @@
 #include "opt_atalk.h"
 #include "opt_mpls.h"
 #include "opt_natm.h"
+#include "opt_can.h"
 #include "arp.h"
 #endif /* defined(_KERNEL_OPT) */
 
@@ -90,6 +91,10 @@
 #ifdef NETATALK
 #include <netatalk/at_extern.h>
 #endif
+#ifdef CAN
+#include <netcan/can.h>
+#include <netcan/can_var.h>
+#endif
 
 #endif /* !defined(_LOCORE) */
 #endif /* defined(_KERNEL) */
@@ -109,6 +114,7 @@
 #define        NETISR_NATM     27              /* same as AF_NATM */
 #define        NETISR_ARP      28              /* same as AF_ARP */
 #define        NETISR_MPLS     33              /* same as AF_MPLS */
+#define        NETISR_CAN      35              /* same as AF_CAN */
 #define        NETISR_MAX      AF_MAX
 
 #if !defined(_LOCORE) && defined(_KERNEL)
diff -r 983357977eb1 -r 73862f0fb509 sys/net/netisr_dispatch.h
--- a/sys/net/netisr_dispatch.h Sun Jan 15 18:15:45 2017 +0000
+++ b/sys/net/netisr_dispatch.h Sun Jan 15 20:27:33 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: netisr_dispatch.h,v 1.18 2014/06/05 23:48:16 rmind Exp $ */
+/* $NetBSD: netisr_dispatch.h,v 1.18.12.1 2017/01/15 20:27:33 bouyer Exp $ */
 
 #ifndef _NET_NETISR_DISPATCH_H_
 #define _NET_NETISR_DISPATCH_H_
@@ -41,5 +41,8 @@
 #ifdef NATM
        DONETISR(NETISR_NATM,natmintr);
 #endif
+#ifdef CAN
+       DONETISR(NETISR_CAN,canintr);
+#endif
 
 #endif /* !_NET_NETISR_DISPATCH_H_ */
diff -r 983357977eb1 -r 73862f0fb509 sys/netcan/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/netcan/Makefile       Sun Jan 15 20:27:33 2017 +0000
@@ -0,0 +1,8 @@
+#      $NetBSD: Makefile,v 1.1.2.1 2017/01/15 20:27:33 bouyer Exp $
+
+KDIR=  /sys/netcan
+INCSDIR= /usr/include/netcan
+
+INCS=  can.h
+
+.include <bsd.kinc.mk>
diff -r 983357977eb1 -r 73862f0fb509 sys/netcan/can.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/netcan/can.c  Sun Jan 15 20:27:33 2017 +0000
@@ -0,0 +1,697 @@
+/*     $NetBSD: can.c,v 1.1.2.1 2017/01/15 20:27:33 bouyer Exp $       */
+
+/*-
+ * Copyright (c) 2003, 2017 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Robert Swindells and 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 NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: can.c,v 1.1.2.1 2017/01/15 20:27:33 bouyer Exp $");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/mbuf.h>
+#include <sys/ioctl.h>
+#include <sys/protosw.h>
+#include <sys/errno.h>
+#include <sys/socket.h>
+#include <sys/socketvar.h>
+#include <sys/proc.h>
+#include <sys/kauth.h>
+
+#include <net/if.h>
+#include <net/netisr.h>
+#include <net/route.h>
+
+#include <netcan/can.h>
+#include <netcan/can_pcb.h>
+#include <netcan/can_var.h>
+
+struct canpcb canpcb;
+#if 0
+struct canpcb canrawpcb;
+#endif
+
+struct canpcbtable cbtable;
+
+struct ifqueue canintrq;
+int    canqmaxlen = IFQ_MAXLEN;
+
+int can_copy_output = 0;
+int can_output_cnt = 0;
+struct mbuf *can_lastout;
+
+int    can_sendspace = 4096;           /* really max datagram size */
+int    can_recvspace = 40 * (1024 + sizeof(struct sockaddr_can));
+                                       /* 40 1K datagrams */
+#ifndef CANHASHSIZE
+#define        CANHASHSIZE     128
+#endif
+int    canhashsize = CANHASHSIZE;
+
+static int can_output(struct mbuf *, struct canpcb *);
+
+static int can_control(struct socket *, u_long, void *, struct ifnet *);
+
+void
+can_init(void)
+{
+       canintrq.ifq_maxlen = canqmaxlen;
+       IFQ_LOCK_INIT(&canintrq);
+       can_pcbinit(&cbtable, canhashsize, canhashsize);
+}
+
+/*
+ * Generic control operations (ioctl's).
+ */
+/* ARGSUSED */
+static int
+can_control(struct socket *so, u_long cmd, void *data, struct ifnet *ifp)
+{
+#if 0
+       struct can_ifreq *cfr = (struct can_ifreq *)data;
+       int error = 0;
+#endif
+
+
+       switch (cmd) {
+
+       default:
+               if (ifp == 0 || ifp->if_ioctl == 0)
+                       return (EOPNOTSUPP);
+               return ((*ifp->if_ioctl)(ifp, cmd, data));
+       }
+       return (0);
+}
+
+static int
+can_purgeif(struct socket *so, struct ifnet *ifp)
+{
+       return 0;
+}
+
+static int
+can_output(struct mbuf *m, struct canpcb *canp)
+{
+       struct ifnet *ifp;
+       int error = 0;
+
+       if (canp == 0) {
+               printf("can_output: no pcb\n");
+               error = EINVAL;
+               goto done;
+       }
+       ifp = canp->canp_ifp;
+       if (ifp == 0) {
+               error = EDESTADDRREQ;
+               goto done;
+       }
+       if (m->m_len <= ifp->if_mtu) {
+               can_output_cnt++;
+               error = (*ifp->if_output)(ifp, m, NULL, 0);
+               goto done;
+       } else error = EMSGSIZE;
+



Home | Main Index | Thread Index | Old Index