Re: [RFC, PATCH]: Pass link level header from/to PPP interface

2008-02-14 Thread Urs Thuermann
David Miller [EMAIL PROTECTED] writes:

 Can tcpdump and libpcap already handle PPP properly?

Yes, with the (admittedly non-serious) limitation, that both, tcpdump
and tcpdump -e don't show the PPP header.  I don't remember how
tcpdump behaved on BSD in this respect (so many years ago), but I
think libpcap will use the DLT_PPP link type on BSD, which has the PPP
header.

urs
--
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFC, PATCH]: Pass link level header from/to PPP interface

2008-02-13 Thread Urs Thuermann
Hello Dave,

 But if libpcap and tcpdump can already identify PPP packets
 then, besides consistency, what does this buy us other
 than potential breakage?

My reason for the patch is mostly cleanliness and to make the kernel
match what is described in packet(7).

If you open a PF_PACKET/SOCK_RAW socket and bind it to an interface
you get a fixed type of frame/packet depending on the type of
interface, including the LL header.  Also if you bind to all
interfaces you can look at the interface type to know what type of
packet you get.  But not for PPP interfaces.

I've written a small packet dump util with a packet parser (somewhat
comparable to tcpdump but much smaller), which looks like this

struct sockaddr_ll addr;
...
s = open(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
...
recvfrom(s, buffer, sizeof(buffer), 0, addr, size);
switch (addr.sll_hatype) {
case ARPHRD_ETHER:
case ARPHRD_IEEE80211:
case ARPHRD_LOOPBACK:
parse_ether(buffer);
break;
case ARPHRD_TUNNEL:
parse_ip(buffer);
break;
case ARPHRD_SIT:
parse_ipv6(buffer);
break;

and so on.  Only for PPP I need to switch on the addr.sll_protocol
since with PPP I don't get the PPP header:

case ARPHRD_PPP:
switch (ntohs(addr.sll_protocol))
case ETH_P_IP:
parse_ip(buffer);
break;
case ETH_P_IPV6:
parse_ipv6(buffer);
break;
...
}
break;

With my patch you would write

case ARPHRD_PPP:
parse_ppp(buffer);
break;

and the parse function can show the complete PPP frame with protocol
field.  Without the patch there is no way to see the 2-byte PPP header
and, in contrast to packet(7), SOCK_DGRAM and SOCK_RAW are the same.

Do you consider this strong enough to justify this change?

urs
--
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] Fix comment for skb_pull_rcsum

2008-02-10 Thread Urs Thuermann
Fix comment for skb_pull_rcsum

Signed-off-by: Urs Thuermann [EMAIL PROTECTED]

---

Index: net-2.6/net/core/skbuff.c
===
--- net-2.6.orig/net/core/skbuff.c  2008-02-06 22:17:58.0 +0100
+++ net-2.6/net/core/skbuff.c   2008-02-08 11:05:00.0 +0100
@@ -2106,11 +2106,10 @@
 /**
  * skb_pull_rcsum - pull skb and update receive checksum
  * @skb: buffer to update
- * @start: start of data before pull
  * @len: length of data pulled
  *
  * This function performs an skb_pull on the packet and updates
- * update the CHECKSUM_COMPLETE checksum.  It should be used on
+ * the CHECKSUM_COMPLETE checksum.  It should be used on
  * receive path processing instead of skb_pull unless you know
  * that the checksum difference is zero (e.g., a valid IP header)
  * or you are setting ip_summed to CHECKSUM_NONE.
--
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RFC, PATCH]: Pass link level header from/to PPP interface

2008-02-10 Thread Urs Thuermann
The PPP interface strips off the PPP header from the packet before
passing it up with netif_rx().  On the xmit path, it has to add the
PPP header itself because dev-header_ops is NULL.

This means that a PF_PACKET, SOCK_RAW socket can't get the link level
header and has to use the sll_protocol field of the sockaddr_ll to
know what type of packet is received with recvfrom(2).  I consider
this a design flaw since with most (all?) other interfaces you only
need to know the sll_hatype to know what type of packet you get.

I have patched the PPP code to include the PPP header.  I tried with
IP and IPv6 over PPP and it works as expected.  This patch, however,
changes the interface to the user space in an incompatible way.  But
IMHO we could include it, since

* PF_PACKET is Linux specific and not portable anyway.  Most apps use
  libpcap instead of opening PF_PACKET sockets themselves.

* Using strace on tcpdump, it seems that libpcap on Linux uses
  PF_PACKET/SOCK_DGRAM for PPP interfaces and thus is not affected by
  my patch.

* Other apps using PF_PACKET/SOCK_RAW can easily be changed to
  PF_PACKET/SOCK_DGRAM if they don't want to see the link level
  header.  After all, this is what SOCK_DGRAM is for.

Currently SOCK_RAW and SOCK_DGRAM are the same although the packet(7)
man page states that with SOCK_RAW packets are passed without any
changes.  This makes having SOCK_RAW besides SOCK_DGRAM useless for
PPP.

So what is your opinion about this change?


Signed-off-by: Urs Thuermann [EMAIL PROTECTED]

---
 drivers/net/ppp_generic.c |   41 -
 1 file changed, 28 insertions(+), 13 deletions(-)

Index: net-2.6/drivers/net/ppp_generic.c
===
--- net-2.6.orig/drivers/net/ppp_generic.c  2008-02-08 11:09:03.0 
+0100
+++ net-2.6/drivers/net/ppp_generic.c   2008-02-08 13:27:29.0 +0100
@@ -873,12 +873,32 @@
 /*
  * Network interface unit routines.
  */
+
+/* Put the 2-byte PPP protocol number on the front of skb */
+static int ppp_header(struct sk_buff *skb, struct net_device *dev,
+ unsigned short type,
+ const void *daddr, const void *saddr, unsigned len)
+{
+   unsigned char *pp;
+   int npi, proto;
+
+   npi = ethertype_to_npindex(ntohs(skb-protocol));
+   if (npi  0)
+   return -dev-hard_header_len;
+
+   pp = skb_push(skb, 2);
+   proto = npindex_to_proto[npi];
+   pp[0] = proto  8;
+   pp[1] = proto;
+
+   return dev-hard_header_len;
+}
+
 static int
 ppp_start_xmit(struct sk_buff *skb, struct net_device *dev)
 {
struct ppp *ppp = (struct ppp *) dev-priv;
-   int npi, proto;
-   unsigned char *pp;
+   int npi;
 
npi = ethertype_to_npindex(ntohs(skb-protocol));
if (npi  0)
@@ -897,16 +917,6 @@
goto outf;
}
 
-   /* Put the 2-byte PPP protocol number on the front,
-  making sure there is room for the address and control fields. */
-   if (skb_cow_head(skb, PPP_HDRLEN))
-   goto outf;
-
-   pp = skb_push(skb, 2);
-   proto = npindex_to_proto[npi];
-   pp[0] = proto  8;
-   pp[1] = proto;
-
netif_stop_queue(dev);
skb_queue_tail(ppp-file.xq, skb);
ppp_xmit_process(ppp);
@@ -969,9 +979,14 @@
return err;
 }
 
+static const struct header_ops ppp_header_ops cacheline_aligned = {
+   .create = ppp_header,
+};
+
 static void ppp_setup(struct net_device *dev)
 {
dev-hard_header_len = PPP_HDRLEN;
+   dev-header_ops = ppp_header_ops;
dev-mtu = PPP_MTU;
dev-addr_len = 0;
dev-tx_queue_len = 3;
@@ -1677,10 +1692,10 @@
kfree_skb(skb);
} else {
/* chop off protocol */
+   skb_reset_mac_header(skb);
skb_pull_rcsum(skb, 2);
skb-dev = ppp-dev;
skb-protocol = htons(npindex_to_ethertype[npi]);
-   skb_reset_mac_header(skb);
netif_rx(skb);
ppp-dev-last_rx = jiffies;
}
--
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[patch 0/3] CAN: Some updates for 2.6.25

2008-02-06 Thread urs . thuermann
The following patches are intended for 2.6.25.

--
--
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[patch 1/3] CAN: Clean up module auto loading

2008-02-06 Thread urs . thuermann
Remove local char array to construct module name.
Don't call request_module() when CONFIG_KMOD is not set.

Signed-off-by: Urs Thuermann [EMAIL PROTECTED]
Signed-off-by: Oliver Hartkopp [EMAIL PROTECTED]

---
 net/can/af_can.c |   18 ++
 1 file changed, 6 insertions(+), 12 deletions(-)

Index: net-2.6/net/can/af_can.c
===
--- net-2.6.orig/net/can/af_can.c   2008-02-06 22:17:58.0 +0100
+++ net-2.6/net/can/af_can.c2008-02-06 22:20:46.0 +0100
@@ -118,7 +118,6 @@
 {
struct sock *sk;
struct can_proto *cp;
-   char module_name[sizeof(can-proto-000)];
int err = 0;
 
sock-state = SS_UNCONNECTED;
@@ -129,26 +128,21 @@
if (net != init_net)
return -EAFNOSUPPORT;
 
+#ifdef CONFIG_KMOD
/* try to load protocol module, when CONFIG_KMOD is defined */
if (!proto_tab[protocol]) {
-   sprintf(module_name, can-proto-%d, protocol);
-   err = request_module(module_name);
+   err = request_module(can-proto-%d, protocol);
 
/*
 * In case of error we only print a message but don't
 * return the error code immediately.  Below we will
 * return -EPROTONOSUPPORT
 */
-   if (err == -ENOSYS) {
-   if (printk_ratelimit())
-   printk(KERN_INFO can: request_module(%s)
-   not implemented.\n, module_name);
-   } else if (err) {
-   if (printk_ratelimit())
-   printk(KERN_ERR can: request_module(%s)
-   failed.\n, module_name);
-   }
+   if (err  printk_ratelimit())
+   printk(KERN_ERR can: request_module 
+  (can-proto-%d) failed.\n, protocol);
}
+#endif
 
spin_lock(proto_tab_lock);
cp = proto_tab[protocol];

--
--
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[patch 2/3] CAN: Move proto_{,un}register() out of spin-locked region

2008-02-06 Thread urs . thuermann
The implementation of proto_register() has changed so that it can now
sleep.  The call to proto_register() must be moved out of the
spin-locked region.

Signed-off-by: Urs Thuermann [EMAIL PROTECTED]
Signed-off-by: Oliver Hartkopp [EMAIL PROTECTED]

---
 net/can/af_can.c |   27 ++-
 1 file changed, 14 insertions(+), 13 deletions(-)

Index: net-2.6/net/can/af_can.c
===
--- net-2.6.orig/net/can/af_can.c   2008-02-06 22:20:46.0 +0100
+++ net-2.6/net/can/af_can.c2008-02-06 22:22:51.0 +0100
@@ -656,26 +656,26 @@
return -EINVAL;
}
 
+   err = proto_register(cp-prot, 0);
+   if (err  0)
+   return err;
+
spin_lock(proto_tab_lock);
if (proto_tab[proto]) {
printk(KERN_ERR can: protocol %d already registered\n,
   proto);
err = -EBUSY;
-   goto errout;
+   } else {
+   proto_tab[proto] = cp;
+
+   /* use generic ioctl function if not defined by module */
+   if (!cp-ops-ioctl)
+   cp-ops-ioctl = can_ioctl;
}
+   spin_unlock(proto_tab_lock);
 
-   err = proto_register(cp-prot, 0);
if (err  0)
-   goto errout;
-
-   proto_tab[proto] = cp;
-
-   /* use generic ioctl function if the module doesn't bring its own */
-   if (!cp-ops-ioctl)
-   cp-ops-ioctl = can_ioctl;
-
- errout:
-   spin_unlock(proto_tab_lock);
+   proto_unregister(cp-prot);
 
return err;
 }
@@ -694,9 +694,10 @@
printk(KERN_ERR BUG: can: protocol %d is not registered\n,
   proto);
}
-   proto_unregister(cp-prot);
proto_tab[proto] = NULL;
spin_unlock(proto_tab_lock);
+
+   proto_unregister(cp-prot);
 }
 EXPORT_SYMBOL(can_proto_unregister);
 

--
--
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[patch 3/3] CAN: Minor clean-ups

2008-02-06 Thread urs . thuermann
Remove unneeded variable.
Rename local variable error to err like in all other places.
Some white-space changes.

Signed-off-by: Urs Thuermann [EMAIL PROTECTED]
Signed-off-by: Oliver Hartkopp [EMAIL PROTECTED]

---
 net/can/raw.c |   24 +---
 1 file changed, 9 insertions(+), 15 deletions(-)

Index: net-2.6/net/can/raw.c
===
--- net-2.6.orig/net/can/raw.c  2008-02-06 22:17:58.0 +0100
+++ net-2.6/net/can/raw.c   2008-02-06 22:30:55.0 +0100
@@ -98,7 +98,6 @@
struct sock *sk = (struct sock *)data;
struct raw_sock *ro = raw_sk(sk);
struct sockaddr_can *addr;
-   int error;
 
if (!ro-recv_own_msgs) {
/* check the received tx sock reference */
@@ -121,14 +120,12 @@
addr-can_family  = AF_CAN;
addr-can_ifindex = skb-dev-ifindex;
 
-   error = sock_queue_rcv_skb(sk, skb);
-   if (error  0)
+   if (sock_queue_rcv_skb(sk, skb)  0)
kfree_skb(skb);
 }
 
 static int raw_enable_filters(struct net_device *dev, struct sock *sk,
- struct can_filter *filter,
- int count)
+ struct can_filter *filter, int count)
 {
int err = 0;
int i;
@@ -163,8 +160,7 @@
 }
 
 static void raw_disable_filters(struct net_device *dev, struct sock *sk,
- struct can_filter *filter,
- int count)
+ struct can_filter *filter, int count)
 {
int i;
 
@@ -353,7 +349,6 @@
/* filters set by default/setsockopt */
err = raw_enable_allfilters(dev, sk);
dev_put(dev);
-
} else {
ifindex = 0;
 
@@ -466,7 +461,6 @@
if (err) {
if (count  1)
kfree(filter);
-
goto out_fil;
}
 
@@ -673,25 +667,25 @@
 {
struct sock *sk = sock-sk;
struct sk_buff *skb;
-   int error = 0;
+   int err = 0;
int noblock;
 
noblock =  flags  MSG_DONTWAIT;
flags   = ~MSG_DONTWAIT;
 
-   skb = skb_recv_datagram(sk, flags, noblock, error);
+   skb = skb_recv_datagram(sk, flags, noblock, err);
if (!skb)
-   return error;
+   return err;
 
if (size  skb-len)
msg-msg_flags |= MSG_TRUNC;
else
size = skb-len;
 
-   error = memcpy_toiovec(msg-msg_iov, skb-data, size);
-   if (error  0) {
+   err = memcpy_toiovec(msg-msg_iov, skb-data, size);
+   if (err  0) {
skb_free_datagram(sk, skb);
-   return error;
+   return err;
}
 
sock_recv_timestamp(msg, sk, skb);

--
--
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 5/7] CAN: Add virtual CAN netdevice driver

2007-11-16 Thread Urs Thuermann
This patch adds the virtual CAN bus (vcan) network driver.
The vcan device is just a loopback device for CAN frames, no
real CAN hardware is involved.

Signed-off-by: Oliver Hartkopp [EMAIL PROTECTED]
Signed-off-by: Urs Thuermann [EMAIL PROTECTED]

---
 drivers/net/Makefile |1 
 drivers/net/can/Kconfig  |   25 ++
 drivers/net/can/Makefile |5 +
 drivers/net/can/vcan.c   |  169 +++
 net/can/Kconfig  |3 
 5 files changed, 203 insertions(+)

Index: net-2.6.25/drivers/net/Makefile
===
--- net-2.6.25.orig/drivers/net/Makefile2007-11-16 14:50:12.0 
+0100
+++ net-2.6.25/drivers/net/Makefile 2007-11-16 14:50:18.0 +0100
@@ -12,6 +12,7 @@
 obj-$(CONFIG_CHELSIO_T1) += chelsio/
 obj-$(CONFIG_CHELSIO_T3) += cxgb3/
 obj-$(CONFIG_EHEA) += ehea/
+obj-$(CONFIG_CAN) += can/
 obj-$(CONFIG_BONDING) += bonding/
 obj-$(CONFIG_ATL1) += atl1/
 obj-$(CONFIG_GIANFAR) += gianfar_driver.o
Index: net-2.6.25/drivers/net/can/Kconfig
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ net-2.6.25/drivers/net/can/Kconfig  2007-11-16 14:50:18.0 +0100
@@ -0,0 +1,25 @@
+menu CAN Device Drivers
+   depends on CAN
+
+config CAN_VCAN
+   tristate Virtual Local CAN Interface (vcan)
+   depends on CAN
+   default N
+   ---help---
+ Similar to the network loopback devices, vcan offers a
+ virtual local CAN interface.
+
+ This driver can also be built as a module.  If so, the module
+ will be called vcan.
+
+config CAN_DEBUG_DEVICES
+   bool CAN devices debugging messages
+   depends on CAN
+   default N
+   ---help---
+ Say Y here if you want the CAN device drivers to produce a bunch of
+ debug messages to the system log.  Select this if you are having
+ a problem with CAN support and want to see more of what is going
+ on.
+
+endmenu
Index: net-2.6.25/drivers/net/can/Makefile
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ net-2.6.25/drivers/net/can/Makefile 2007-11-16 14:50:18.0 +0100
@@ -0,0 +1,5 @@
+#
+#  Makefile for the Linux Controller Area Network drivers.
+#
+
+obj-$(CONFIG_CAN_VCAN) += vcan.o
Index: net-2.6.25/drivers/net/can/vcan.c
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ net-2.6.25/drivers/net/can/vcan.c   2007-11-16 14:51:53.0 +0100
@@ -0,0 +1,169 @@
+/*
+ * vcan.c - Virtual CAN interface
+ *
+ * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
+ * All rights reserved.
+ *
+ * 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. Neither the name of Volkswagen nor the names of its contributors
+ *may be used to endorse or promote products derived from this software
+ *without specific prior written permission.
+ *
+ * Alternatively, provided that this notice is retained in full, this
+ * software may be distributed under the terms of the GNU General
+ * Public License (GPL) version 2, in which case the provisions of the
+ * GPL apply INSTEAD OF those given above.
+ *
+ * The provided data structures and external interfaces from this code
+ * are not restricted to be used by modules with a GPL compatible license.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT
+ * OWNER 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.
+ *
+ * Send feedback to [EMAIL PROTECTED]
+ *
+ */
+
+#include linux/module.h
+#include linux/init.h
+#include linux/netdevice.h
+#include linux/if_arp.h
+#include linux/if_ether.h
+#include linux/can.h
+#include net/rtnetlink.h
+
+static

[PATCH 0/7] CAN: New PF_CAN protocol family for 2.6.25, update

2007-11-16 Thread Urs Thuermann
Hello Dave, hello Patrick,

this patch series adds the PF_CAN protocol family for the
Controller Area Network.  Since our last post we have changed:

* Remove vcan_open() and vcan_stop().
* return NETDEV_TX_OK instead of 0.
* Add can_ prefix to some global vars.
* Remove all debug code completely.
* Cleanup of timer code.

This patch series applies against net-2.6.25 and is derived from Subversion
revision r560 of http://svn.berlios.de/svnroot/repos/socketcan.
It can be found in the directory
http://svn.berlios.de/svnroot/repos/socketcan/trunk/patch-series/version.

Urs Thuermann
Oliver Hartkopp


The changes in try #11 were:

* Fix a bug causing NULL pointer dereference when module autoloading fails.
* Initialize skb using skb_reset_{transport,network}_header().
* Use sock_alloc_send_skb() instead of alloc_skb().
* Adapt to changes in sk_alloc() parameter list.
* Rename some local variables for readability.

The changes in try #10 were:

* Rename our static debug variables to {can,raw,bcm,vcan}_debug.
* Use module_param_named() so that the module option names remain.
* Remove raw_poll() and bcm_poll() functions and use datagram_poll instead.
* Cleanup of can_addr union in sockaddr_can.
* Change type of echo module parameter to boolean.

The changes in try #9 were:

* Changes suggested by Arnaldo Carvalho de Melo:
  - Use gfp_any() instead of checking in_interrupt().
  - Don't kfree() the sk_protinfo field.
* Fixed licence text as pointed out by Yoshifuji Hideaki and Patrick McHardy.
* Added IFF_ECHO to include/linux/if.h and use that instead of IFF_LOOPBACK,
  as suggested by Eric W. Biederman.  IFF_LOOPBACK is only for the normal
  loopback interface.

The changes in try #8 were:

* Some changes in debug code, following suggestions from Joe Perches:
  - Remove dynamically allocated buffer for debug output.
  - Use kernel functions for hexdumps.
  - Don't interpret printf-style %-sequences in can_debug_cframe().
  - Specify the fixed argument fmt to DBG() macro and use
GCC ## mechanism to remove , when args is empty.
* Removed CAN_RAW_USER and CAN_BCM_USER Kconfig options following a
  suggestion from Patrick.
* Prevent overflow in statistics calculation.
* Minor optimization.

The changes in try #7 were:

* Changes suggested by Patrick:
  - protect proto_tab[] by a lock.
  - add _rcu to some hlist traversals.
  - use printk_ratelimit() for module autoload failures.
  - make can_proto_unregister() and can_rx_unregister() return void.
  - use return value of can_proto_register() and can_rx_register()
(this also removed a flaw in behavior of raw_bind() and raw_setsockopt()
 in case of failure to can_rx_register() their filters).
  - call kzalloc() with GFP_KERNEL in case NETDEV_REGISTER.
  - use round_jiffies() to calculate expiration times.
  - make some variables static and/or __read_mostly.
  - in can_create() check for net namespace before auto loading modules.
  - add build time check for struct sizes.
  - use skb_share_chack() in vcan.
  - fixed some comments.
* Typos in documentation as pointed out by Randy Dunlap and Bill Fink.

The changes in try #6 were:

* Update code to work with namespaces in net-2.6.24.
* Remove SET_MODULE_OWNER() from vcan.

The changes in try #5 were:

* Remove slab destructor from calls to kmem_cache_alloc().
* Add comments about types defined in can.h.
* Update comment on vcan loopback module parameter.
* Fix typo in documentation.

The changes in try #4 were:

* Change vcan network driver to use the new RTNL API, as suggested by
  Patrick.
* Revert our change to use skb-iif instead of skb-cb.  After
  discussion with Patrick and Jamal it turned out, our first
  implementation was correct.
* Use skb_tail_pointer() instead of skb-tail directly.
* Coding style changes to satisfy linux/scripts/checkpatch.pl.
* Minor changes for 64-bit-cleanliness.
* Minor cleanup of #include's

The changes in try #3 were:

* Use sbk-sk and skb-pkt_type instead of skb-cb to pass loopback
  flags and originating socket down to the driver and back to the
  receiving socket.  Thanks to Patrick McHardy for pointing out our
  wrong use of sbk-cb.
* Use skb-iif instead of skb-cb to pass receiving interface from
  raw_rcv() and bcm_rcv() up to raw_recvmsg() and bcm_recvmsg().
* Set skb-protocol when sending CAN frames to netdevices.
* Removed struct raw_opt and struct bcm_opt and integrated these
  directly into struct raw_sock and bcm_sock resp., like most other
  proto implementations do.
* We have found and fixed race conditions between raw_bind(),
  raw_{set,get}sockopt() and raw_notifier().  This resulted in
  - complete removal of our own notifier list infrastructure in
af_can.c.  raw.c and bcm.c now use normal netdevice notifiers.
  - removal of ro-lock spinlock.  We use lock_sock(sk) now.
  - changed deletion of dev_rcv_lists, which are now marked for
deletion in the netdevice notifier in af_can.c and are actually
deleted when all entries have been deleted using

[PATCH 7/7] CAN: Add documentation

2007-11-16 Thread Urs Thuermann
This patch adds documentation for the PF_CAN protocol family.

Signed-off-by: Oliver Hartkopp [EMAIL PROTECTED]
Signed-off-by: Urs Thuermann [EMAIL PROTECTED]

---
 Documentation/networking/00-INDEX |2 
 Documentation/networking/can.txt  |  629 ++
 2 files changed, 631 insertions(+)

Index: net-2.6.25/Documentation/networking/can.txt
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ net-2.6.25/Documentation/networking/can.txt 2007-11-16 14:56:31.0 
+0100
@@ -0,0 +1,629 @@
+
+
+can.txt
+
+Readme file for the Controller Area Network Protocol Family (aka Socket CAN)
+
+This file contains
+
+  1 Overview / What is Socket CAN
+
+  2 Motivation / Why using the socket API
+
+  3 Socket CAN concept
+3.1 receive lists
+3.2 local loopback of sent frames
+3.3 network security issues (capabilities)
+3.4 network problem notifications
+
+  4 How to use Socket CAN
+4.1 RAW protocol sockets with can_filters (SOCK_RAW)
+  4.1.1 RAW socket option CAN_RAW_FILTER
+  4.1.2 RAW socket option CAN_RAW_ERR_FILTER
+  4.1.3 RAW socket option CAN_RAW_LOOPBACK
+  4.1.4 RAW socket option CAN_RAW_RECV_OWN_MSGS
+4.2 Broadcast Manager protocol sockets (SOCK_DGRAM)
+4.3 connected transport protocols (SOCK_SEQPACKET)
+4.4 unconnected transport protocols (SOCK_DGRAM)
+
+  5 Socket CAN core module
+5.1 can.ko module params
+5.2 procfs content
+5.3 writing own CAN protocol modules
+
+  6 CAN network drivers
+6.1 general settings
+6.2 local loopback of sent frames
+6.3 CAN controller hardware filters
+6.4 currently supported CAN hardware
+6.5 todo
+
+  7 Credits
+
+
+
+1. Overview / What is Socket CAN
+
+
+The socketcan package is an implementation of CAN protocols
+(Controller Area Network) for Linux.  CAN is a networking technology
+which has widespread use in automation, embedded devices, and
+automotive fields.  While there have been other CAN implementations
+for Linux based on character devices, Socket CAN uses the Berkeley
+socket API, the Linux network stack and implements the CAN device
+drivers as network interfaces.  The CAN socket API has been designed
+as similar as possible to the TCP/IP protocols to allow programmers,
+familiar with network programming, to easily learn how to use CAN
+sockets.
+
+2. Motivation / Why using the socket API
+
+
+There have been CAN implementations for Linux before Socket CAN so the
+question arises, why we have started another project.  Most existing
+implementations come as a device driver for some CAN hardware, they
+are based on character devices and provide comparatively little
+functionality.  Usually, there is only a hardware-specific device
+driver which provides a character device interface to send and
+receive raw CAN frames, directly to/from the controller hardware.
+Queueing of frames and higher-level transport protocols like ISO-TP
+have to be implemented in user space applications.  Also, most
+character-device implementations support only one single process to
+open the device at a time, similar to a serial interface.  Exchanging
+the CAN controller requires employment of another device driver and
+often the need for adaption of large parts of the application to the
+new driver's API.
+
+Socket CAN was designed to overcome all of these limitations.  A new
+protocol family has been implemented which provides a socket interface
+to user space applications and which builds upon the Linux network
+layer, so to use all of the provided queueing functionality.  A device
+driver for CAN controller hardware registers itself with the Linux
+network layer as a network device, so that CAN frames from the
+controller can be passed up to the network layer and on to the CAN
+protocol family module and also vice-versa.  Also, the protocol family
+module provides an API for transport protocol modules to register, so
+that any number of transport protocols can be loaded or unloaded
+dynamically.  In fact, the can core module alone does not provide any
+protocol and cannot be used without loading at least one additional
+protocol module.  Multiple sockets can be opened at the same time,
+on different or the same protocol module and they can listen/send
+frames on different or the same CAN IDs.  Several sockets listening on
+the same interface for frames with the same CAN ID are all passed the
+same received matching CAN frames.  An application wishing to
+communicate using a specific transport protocol, e.g. ISO-TP, just
+selects that protocol when opening the socket, and then can read and
+write application data byte streams, without having to deal with
+CAN-IDs, frames, etc

[PATCH 4/7] CAN: Add broadcast manager (bcm) protocol

2007-11-16 Thread Urs Thuermann
This patch adds the CAN broadcast manager (bcm) protocol.

Signed-off-by: Oliver Hartkopp [EMAIL PROTECTED]
Signed-off-by: Urs Thuermann [EMAIL PROTECTED]

---
 include/linux/can/bcm.h |   65 +
 net/can/Kconfig |   13 
 net/can/Makefile|3 
 net/can/bcm.c   | 1561 
 4 files changed, 1642 insertions(+)

Index: net-2.6.25/include/linux/can/bcm.h
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ net-2.6.25/include/linux/can/bcm.h  2007-11-16 14:44:48.0 +0100
@@ -0,0 +1,65 @@
+/*
+ * linux/can/bcm.h
+ *
+ * Definitions for CAN Broadcast Manager (BCM)
+ *
+ * Author: Oliver Hartkopp [EMAIL PROTECTED]
+ * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
+ * All rights reserved.
+ *
+ * Send feedback to [EMAIL PROTECTED]
+ *
+ */
+
+#ifndef CAN_BCM_H
+#define CAN_BCM_H
+
+/**
+ * struct bcm_msg_head - head of messages to/from the broadcast manager
+ * @opcode:opcode, see enum below.
+ * @flags: special flags, see below.
+ * @count: number of frames to send before changing interval.
+ * @ival1: interval for the first @count frames.
+ * @ival2: interval for the following frames.
+ * @can_id:CAN ID of frames to be sent or received.
+ * @nframes:   number of frames appended to the message head.
+ * @frames:array of CAN frames.
+ */
+struct bcm_msg_head {
+   int opcode;
+   int flags;
+   int count;
+   struct timeval ival1, ival2;
+   canid_t can_id;
+   int nframes;
+   struct can_frame frames[0];
+};
+
+enum {
+   TX_SETUP = 1,   /* create (cyclic) transmission task */
+   TX_DELETE,  /* remove (cyclic) transmission task */
+   TX_READ,/* read properties of (cyclic) transmission task */
+   TX_SEND,/* send one CAN frame */
+   RX_SETUP,   /* create RX content filter subscription */
+   RX_DELETE,  /* remove RX content filter subscription */
+   RX_READ,/* read properties of RX content filter subscription */
+   TX_STATUS,  /* reply to TX_READ request */
+   TX_EXPIRED, /* notification on performed transmissions (count=0) */
+   RX_STATUS,  /* reply to RX_READ request */
+   RX_TIMEOUT, /* cyclic message is absent */
+   RX_CHANGED  /* updated CAN frame (detected content change) */
+};
+
+#define SETTIMER0x0001
+#define STARTTIMER  0x0002
+#define TX_COUNTEVT 0x0004
+#define TX_ANNOUNCE 0x0008
+#define TX_CP_CAN_ID0x0010
+#define RX_FILTER_ID0x0020
+#define RX_CHECK_DLC0x0040
+#define RX_NO_AUTOTIMER 0x0080
+#define RX_ANNOUNCE_RESUME  0x0100
+#define TX_RESET_MULTI_IDX  0x0200
+#define RX_RTR_FRAME0x0400
+
+#endif /* CAN_BCM_H */
Index: net-2.6.25/net/can/Kconfig
===
--- net-2.6.25.orig/net/can/Kconfig 2007-11-16 14:42:30.0 +0100
+++ net-2.6.25/net/can/Kconfig  2007-11-16 14:46:32.0 +0100
@@ -26,3 +26,16 @@
  most cases where no higher level protocol is being used. The raw
  socket has several filter options e.g. ID masking / error frames.
  To receive/send raw CAN messages, use AF_CAN with protocol CAN_RAW.
+
+config CAN_BCM
+   tristate Broadcast Manager CAN Protocol (with content filtering)
+   depends on CAN
+   default N
+   ---help---
+ The Broadcast Manager offers content filtering, timeout monitoring,
+ sending of RTR frames, and cyclic CAN messages without permanent user
+ interaction. The BCM can be 'programmed' via the BSD socket API and
+ informs you on demand e.g. only on content updates / timeouts.
+ You probably want to use the bcm socket in most cases where cyclic
+ CAN messages are used on the bus (e.g. in automotive environments).
+ To use the Broadcast Manager, use AF_CAN with protocol CAN_BCM.
Index: net-2.6.25/net/can/Makefile
===
--- net-2.6.25.orig/net/can/Makefile2007-11-16 14:40:14.0 +0100
+++ net-2.6.25/net/can/Makefile 2007-11-16 14:44:48.0 +0100
@@ -7,3 +7,6 @@
 
 obj-$(CONFIG_CAN_RAW)  += can-raw.o
 can-raw-objs   := raw.o
+
+obj-$(CONFIG_CAN_BCM)  += can-bcm.o
+can-bcm-objs   := bcm.o
Index: net-2.6.25/net/can/bcm.c
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ net-2.6.25/net/can/bcm.c2007-11-16 14:47:57.0 +0100
@@ -0,0 +1,1561 @@
+/*
+ * bcm.c - Broadcast Manager to filter/send (cyclic) CAN content
+ *
+ * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following

[PATCH 2/7] CAN: Add PF_CAN core module

2007-11-16 Thread Urs Thuermann
This patch adds the CAN core functionality but no protocols or drivers.
No protocol implementations are included here.  They come as separate
patches.  Protocol numbers are already in include/linux/can.h.

Signed-off-by: Oliver Hartkopp [EMAIL PROTECTED]
Signed-off-by: Urs Thuermann [EMAIL PROTECTED]

---
 include/linux/can.h   |  111 +
 include/linux/can/core.h  |   64 +++
 include/linux/can/error.h |   93 
 net/Kconfig   |1 
 net/Makefile  |1 
 net/can/Kconfig   |   17 
 net/can/Makefile  |6 
 net/can/af_can.c  |  861 ++
 net/can/af_can.h  |  122 ++
 net/can/proc.c|  533 
 10 files changed, 1809 insertions(+)

Index: net-2.6.25/include/linux/can.h
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ net-2.6.25/include/linux/can.h  2007-11-16 11:11:50.0 +0100
@@ -0,0 +1,111 @@
+/*
+ * linux/can.h
+ *
+ * Definitions for CAN network layer (socket addr / CAN frame / CAN filter)
+ *
+ * Authors: Oliver Hartkopp [EMAIL PROTECTED]
+ *  Urs Thuermann   [EMAIL PROTECTED]
+ * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
+ * All rights reserved.
+ *
+ * Send feedback to [EMAIL PROTECTED]
+ *
+ */
+
+#ifndef CAN_H
+#define CAN_H
+
+#include linux/types.h
+#include linux/socket.h
+
+/* controller area network (CAN) kernel definitions */
+
+/* special address description flags for the CAN_ID */
+#define CAN_EFF_FLAG 0x8000U /* EFF/SFF is set in the MSB */
+#define CAN_RTR_FLAG 0x4000U /* remote transmission request */
+#define CAN_ERR_FLAG 0x2000U /* error frame */
+
+/* valid bits in CAN ID for frame formats */
+#define CAN_SFF_MASK 0x07FFU /* standard frame format (SFF) */
+#define CAN_EFF_MASK 0x1FFFU /* extended frame format (EFF) */
+#define CAN_ERR_MASK 0x1FFFU /* omit EFF, RTR, ERR flags */
+
+/*
+ * Controller Area Network Identifier structure
+ *
+ * bit 0-28: CAN identifier (11/29 bit)
+ * bit 29  : error frame flag (0 = data frame, 1 = error frame)
+ * bit 30  : remote transmission request flag (1 = rtr frame)
+ * bit 31  : frame format flag (0 = standard 11 bit, 1 = extended 29 bit)
+ */
+typedef __u32 canid_t;
+
+/*
+ * Controller Area Network Error Frame Mask structure
+ *
+ * bit 0-28: error class mask (see include/linux/can/error.h)
+ * bit 29-31   : set to zero
+ */
+typedef __u32 can_err_mask_t;
+
+/**
+ * struct can_frame - basic CAN frame structure
+ * @can_id:  the CAN ID of the frame and CAN_*_FLAG flags, see above.
+ * @can_dlc: the data length field of the CAN frame
+ * @data:the CAN frame payload.
+ */
+struct can_frame {
+   canid_t can_id;  /* 32 bit CAN_ID + EFF/RTR/ERR flags */
+   __u8can_dlc; /* data length code: 0 .. 8 */
+   __u8data[8] __attribute__((aligned(8)));
+};
+
+/* particular protocols of the protocol family PF_CAN */
+#define CAN_RAW1 /* RAW sockets */
+#define CAN_BCM2 /* Broadcast Manager */
+#define CAN_TP16   3 /* VAG Transport Protocol v1.6 */
+#define CAN_TP20   4 /* VAG Transport Protocol v2.0 */
+#define CAN_MCNET  5 /* Bosch MCNet */
+#define CAN_ISOTP  6 /* ISO 15765-2 Transport Protocol */
+#define CAN_NPROTO 7
+
+#define SOL_CAN_BASE 100
+
+/**
+ * struct sockaddr_can - the sockaddr structure for CAN sockets
+ * @can_family:  address family number AF_CAN.
+ * @can_ifindex: CAN network interface index.
+ * @can_addr:protocol specific address information
+ */
+struct sockaddr_can {
+   sa_family_t can_family;
+   int can_ifindex;
+   union {
+   /* transport protocol class address information (e.g. ISOTP) */
+   struct { canid_t rx_id, tx_id; } tp;
+
+   /* reserved for future CAN protocols address information */
+   } can_addr;
+};
+
+/**
+ * struct can_filter - CAN ID based filter in can_register().
+ * @can_id:   relevant bits of CAN ID which are not masked out.
+ * @can_mask: CAN mask (see description)
+ *
+ * Description:
+ * A filter matches, when
+ *
+ *  received_can_id  mask == can_id  mask
+ *
+ * The filter can be inverted (CAN_INV_FILTER bit set in can_id) or it can
+ * filter for error frames (CAN_ERR_FLAG bit set in mask).
+ */
+struct can_filter {
+   canid_t can_id;
+   canid_t can_mask;
+};
+
+#define CAN_INV_FILTER 0x2000U /* to be set in can_filter.can_id */
+
+#endif /* CAN_H */
Index: net-2.6.25/include/linux/can/core.h
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ net-2.6.25/include/linux/can/core.h 2007-11-16 14:38:25.0 +0100
@@ -0,0 +1,64 @@
+/*
+ * linux/can/core.h
+ *
+ * Protoypes and definitions for CAN protocol modules using the PF_CAN core
+ *
+ * Authors: Oliver Hartkopp [EMAIL

[PATCH 6/7] CAN: Add maintainer entries

2007-11-16 Thread Urs Thuermann
This patch adds entries in the CREDITS and MAINTAINERS file for CAN.

Signed-off-by: Oliver Hartkopp [EMAIL PROTECTED]
Signed-off-by: Urs Thuermann [EMAIL PROTECTED]

---
 CREDITS |   16 
 MAINTAINERS |9 +
 2 files changed, 25 insertions(+)

Index: net-2.6.25/CREDITS
===
--- net-2.6.25.orig/CREDITS 2007-11-14 13:04:23.0 +0100
+++ net-2.6.25/CREDITS  2007-11-14 13:04:55.0 +0100
@@ -1353,6 +1353,14 @@
 S: 5623 HZ Eindhoven
 S: The Netherlands
 
+N: Oliver Hartkopp
+E: [EMAIL PROTECTED]
+W: http://www.volkswagen.de
+D: Controller Area Network (network layer core)
+S: Brieffach 1776
+S: 38436 Wolfsburg
+S: Germany
+
 N: Andrew Haylett
 E: [EMAIL PROTECTED]
 D: Selection mechanism
@@ -3306,6 +3314,14 @@
 S: F-35042 Rennes Cedex
 S: France
 
+N: Urs Thuermann
+E: [EMAIL PROTECTED]
+W: http://www.volkswagen.de
+D: Controller Area Network (network layer core)
+S: Brieffach 1776
+S: 38436 Wolfsburg
+S: Germany
+
 N: Jon Tombs
 E: [EMAIL PROTECTED]
 W: http://www.esi.us.es/~jon
Index: net-2.6.25/MAINTAINERS
===
--- net-2.6.25.orig/MAINTAINERS 2007-11-14 13:04:23.0 +0100
+++ net-2.6.25/MAINTAINERS  2007-11-14 13:04:56.0 +0100
@@ -981,6 +981,15 @@
 L: [EMAIL PROTECTED]
 S: Maintained
 
+CAN NETWORK LAYER
+P: Urs Thuermann
+M: [EMAIL PROTECTED]
+P: Oliver Hartkopp
+M: [EMAIL PROTECTED]
+L: [EMAIL PROTECTED]
+W: http://developer.berlios.de/projects/socketcan/
+S: Maintained
+
 CALGARY x86-64 IOMMU
 P: Muli Ben-Yehuda
 M: [EMAIL PROTECTED]

--
-
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 1/7] CAN: Allocate protocol numbers for PF_CAN

2007-11-16 Thread Urs Thuermann
This patch adds a protocol/address family number, ARP hardware type,
ethernet packet type, and a line discipline number for the SocketCAN
implementation.

Signed-off-by: Oliver Hartkopp [EMAIL PROTECTED]
Signed-off-by: Urs Thuermann [EMAIL PROTECTED]

---
 include/linux/if.h   |4 +++-
 include/linux/if_arp.h   |1 +
 include/linux/if_ether.h |1 +
 include/linux/socket.h   |2 ++
 include/linux/tty.h  |3 ++-
 net/core/sock.c  |4 ++--
 6 files changed, 11 insertions(+), 4 deletions(-)

Index: net-2.6.25/include/linux/if_arp.h
===
--- net-2.6.25.orig/include/linux/if_arp.h  2007-11-14 13:04:26.0 
+0100
+++ net-2.6.25/include/linux/if_arp.h   2007-11-14 13:04:46.0 +0100
@@ -52,6 +52,7 @@
 #define ARPHRD_ROSE270
 #define ARPHRD_X25 271 /* CCITT X.25   */
 #define ARPHRD_HWX25   272 /* Boards with X.25 in firmware */
+#define ARPHRD_CAN 280 /* Controller Area Network  */
 #define ARPHRD_PPP 512
 #define ARPHRD_CISCO   513 /* Cisco HDLC   */
 #define ARPHRD_HDLCARPHRD_CISCO
Index: net-2.6.25/include/linux/if_ether.h
===
--- net-2.6.25.orig/include/linux/if_ether.h2007-11-14 13:04:26.0 
+0100
+++ net-2.6.25/include/linux/if_ether.h 2007-11-14 13:04:46.0 +0100
@@ -90,6 +90,7 @@
 #define ETH_P_WAN_PPP   0x0007  /* Dummy type for WAN PPP frames*/
 #define ETH_P_PPP_MP0x0008  /* Dummy type for PPP MP frames */
 #define ETH_P_LOCALTALK 0x0009 /* Localtalk pseudo type*/
+#define ETH_P_CAN  0x000C  /* Controller Area Network  */
 #define ETH_P_PPPTALK  0x0010  /* Dummy type for Atalk over PPP*/
 #define ETH_P_TR_802_2 0x0011  /* 802.2 frames */
 #define ETH_P_MOBITEX  0x0015  /* Mobitex ([EMAIL PROTECTED])  */
Index: net-2.6.25/include/linux/socket.h
===
--- net-2.6.25.orig/include/linux/socket.h  2007-11-14 13:04:26.0 
+0100
+++ net-2.6.25/include/linux/socket.h   2007-11-14 13:04:46.0 +0100
@@ -185,6 +185,7 @@
 #define AF_PPPOX   24  /* PPPoX sockets*/
 #define AF_WANPIPE 25  /* Wanpipe API Sockets */
 #define AF_LLC 26  /* Linux LLC*/
+#define AF_CAN 29  /* Controller Area Network  */
 #define AF_TIPC30  /* TIPC sockets */
 #define AF_BLUETOOTH   31  /* Bluetooth sockets*/
 #define AF_IUCV32  /* IUCV sockets */
@@ -220,6 +221,7 @@
 #define PF_PPPOX   AF_PPPOX
 #define PF_WANPIPE AF_WANPIPE
 #define PF_LLC AF_LLC
+#define PF_CAN AF_CAN
 #define PF_TIPCAF_TIPC
 #define PF_BLUETOOTH   AF_BLUETOOTH
 #define PF_IUCVAF_IUCV
Index: net-2.6.25/include/linux/tty.h
===
--- net-2.6.25.orig/include/linux/tty.h 2007-11-14 13:04:26.0 +0100
+++ net-2.6.25/include/linux/tty.h  2007-11-14 13:04:46.0 +0100
@@ -23,7 +23,7 @@
  */
 #define NR_UNIX98_PTY_DEFAULT  4096  /* Default maximum for Unix98 ptys */
 #define NR_UNIX98_PTY_MAX  (1  MINORBITS) /* Absolute limit */
-#define NR_LDISCS  17
+#define NR_LDISCS  18
 
 /* line disciplines */
 #define N_TTY  0
@@ -44,6 +44,7 @@
 #define N_SYNC_PPP 14  /* synchronous PPP */
 #define N_HCI  15  /* Bluetooth HCI UART */
 #define N_GIGASET_M101 16  /* Siemens Gigaset M101 serial DECT adapter */
+#define N_SLCAN17  /* Serial / USB serial CAN Adaptors */
 
 /*
  * This character is the same as _POSIX_VDISABLE: it cannot be used as
Index: net-2.6.25/net/core/sock.c
===
--- net-2.6.25.orig/net/core/sock.c 2007-11-14 13:04:26.0 +0100
+++ net-2.6.25/net/core/sock.c  2007-11-14 13:04:47.0 +0100
@@ -154,7 +154,7 @@
   sk_lock-AF_ASH   , sk_lock-AF_ECONET   , sk_lock-AF_ATMSVC   ,
   sk_lock-21   , sk_lock-AF_SNA  , sk_lock-AF_IRDA ,
   sk_lock-AF_PPPOX , sk_lock-AF_WANPIPE  , sk_lock-AF_LLC  ,
-  sk_lock-27   , sk_lock-28  , sk_lock-29  ,
+  sk_lock-27   , sk_lock-28  , sk_lock-AF_CAN  ,
   sk_lock-AF_TIPC  , sk_lock-AF_BLUETOOTH, sk_lock-IUCV,
   sk_lock-AF_RXRPC , sk_lock-AF_MAX
 };
@@ -168,7 +168,7 @@
   slock-AF_ASH   , slock-AF_ECONET   , slock-AF_ATMSVC   ,
   slock-21   , slock-AF_SNA  , slock-AF_IRDA ,
   slock-AF_PPPOX , slock-AF_WANPIPE  , slock-AF_LLC  ,
-  slock-27   , slock-28  , slock-29  ,
+  slock-27   , slock-28  , slock-AF_CAN

Re: [PATCH 2/7] CAN: Add PF_CAN core module

2007-11-16 Thread Urs Thuermann
David Miller [EMAIL PROTECTED] writes:

 I really frown upon these local debugging macros people tend to want
 to submit with their changes.
 
 It really craps up the tree, even though it might be useful to you.

We have now removed the debug code completely.  The code is quite
stable and we won't need these remnants from early days anymore.

 So please remove this stuff or replace the debugging statements
 with some generic kernel debugging facility, there are several.

I am not aware of any useful kernel facilities to replace our debug
macros, i.e. printing of debug messages, controlled by a bit mask
passed in as a module parameter, hexdumping of fames, etc.  Of course,
there are other things like kprobes but sometimes printk(KERN_DEBUG...)
is more convenient and that's why people write their own DBG() macros.

urs
-
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 3/7] CAN: Add raw protocol

2007-11-16 Thread Urs Thuermann
This patch adds the CAN raw protocol.

Signed-off-by: Oliver Hartkopp [EMAIL PROTECTED]
Signed-off-by: Urs Thuermann [EMAIL PROTECTED]

---
 include/linux/can/raw.h |   31 +
 net/can/Kconfig |   11 
 net/can/Makefile|3 
 net/can/raw.c   |  763 
 4 files changed, 808 insertions(+)

Index: net-2.6.25/include/linux/can/raw.h
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ net-2.6.25/include/linux/can/raw.h  2007-11-16 14:40:14.0 +0100
@@ -0,0 +1,31 @@
+/*
+ * linux/can/raw.h
+ *
+ * Definitions for raw CAN sockets
+ *
+ * Authors: Oliver Hartkopp [EMAIL PROTECTED]
+ *  Urs Thuermann   [EMAIL PROTECTED]
+ * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
+ * All rights reserved.
+ *
+ * Send feedback to [EMAIL PROTECTED]
+ *
+ */
+
+#ifndef CAN_RAW_H
+#define CAN_RAW_H
+
+#include linux/can.h
+
+#define SOL_CAN_RAW (SOL_CAN_BASE + CAN_RAW)
+
+/* for socket options affecting the socket (not the global system) */
+
+enum {
+   CAN_RAW_FILTER = 1, /* set 0 .. n can_filter(s)  */
+   CAN_RAW_ERR_FILTER, /* set filter for error frames   */
+   CAN_RAW_LOOPBACK,   /* local loopback (default:on)   */
+   CAN_RAW_RECV_OWN_MSGS   /* receive my own msgs (default:off) */
+};
+
+#endif
Index: net-2.6.25/net/can/Kconfig
===
--- net-2.6.25.orig/net/can/Kconfig 2007-11-16 14:34:20.0 +0100
+++ net-2.6.25/net/can/Kconfig  2007-11-16 14:42:30.0 +0100
@@ -15,3 +15,14 @@
 
  If you want CAN support you should say Y here and also to the
  specific driver for your controller(s) below.
+
+config CAN_RAW
+   tristate Raw CAN Protocol (raw access with CAN-ID filtering)
+   depends on CAN
+   default N
+   ---help---
+ The raw CAN protocol option offers access to the CAN bus via
+ the BSD socket API. You probably want to use the raw socket in
+ most cases where no higher level protocol is being used. The raw
+ socket has several filter options e.g. ID masking / error frames.
+ To receive/send raw CAN messages, use AF_CAN with protocol CAN_RAW.
Index: net-2.6.25/net/can/Makefile
===
--- net-2.6.25.orig/net/can/Makefile2007-11-16 14:25:56.0 +0100
+++ net-2.6.25/net/can/Makefile 2007-11-16 14:40:14.0 +0100
@@ -4,3 +4,6 @@
 
 obj-$(CONFIG_CAN)  += can.o
 can-objs   := af_can.o proc.o
+
+obj-$(CONFIG_CAN_RAW)  += can-raw.o
+can-raw-objs   := raw.o
Index: net-2.6.25/net/can/raw.c
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ net-2.6.25/net/can/raw.c2007-11-16 14:43:29.0 +0100
@@ -0,0 +1,763 @@
+/*
+ * raw.c - Raw sockets for protocol family CAN
+ *
+ * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
+ * All rights reserved.
+ *
+ * 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. Neither the name of Volkswagen nor the names of its contributors
+ *may be used to endorse or promote products derived from this software
+ *without specific prior written permission.
+ *
+ * Alternatively, provided that this notice is retained in full, this
+ * software may be distributed under the terms of the GNU General
+ * Public License (GPL) version 2, in which case the provisions of the
+ * GPL apply INSTEAD OF those given above.
+ *
+ * The provided data structures and external interfaces from this code
+ * are not restricted to be used by modules with a GPL compatible license.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT
+ * OWNER 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

Re: [PATCH 2/7] CAN: Add PF_CAN core module

2007-11-15 Thread Urs Thuermann
Stephen Hemminger [EMAIL PROTECTED] writes:

  +#ifdef CONFIG_CAN_DEBUG_CORE
  +extern void can_debug_skb(struct sk_buff *skb);
  +extern void can_debug_cframe(const char *msg, struct can_frame *cframe);
  +#define DBG(fmt, args...)  (DBG_VAR  1 ? printk( \
  +   KERN_DEBUG DBG_PREFIX : %s:  fmt, \
  +   __func__, ##args) : 0)
  +#define DBG_FRAME(fmt, cf) (DBG_VAR  2 ? can_debug_cframe(fmt, cf) : 0)
  +#define DBG_SKB(skb)   (DBG_VAR  4 ? can_debug_skb(skb) : 0)
  +#else
  +#define DBG(fmt, args...)
  +#define DBG_FRAME(fmt, cf)
  +#define DBG_SKB(skb)
  +#endif
 
 
 This non-standard debugging seems like it needs a better interface.
 Also, need paren's around (DBG_VAR  1) and don't use UPPERCASE for
 variable names.

No additional parenthesis is needed here.  ?: is the lowest precedence
operator above assignment and ,.  Also, DBG_VAR is no variable name.
It's a macro that expands to a variable name like can_debug, raw_debug
or bcm_debug.

  +HLIST_HEAD(rx_dev_list);
 
 Please either make rx_dev_list static or call it can_rx_dev_list
 to avoid name conflices.
 
 
  +static struct dev_rcv_lists rx_alldev_list;
  +static DEFINE_SPINLOCK(rcv_lists_lock);
  +
  +static struct kmem_cache *rcv_cache __read_mostly;
  +
  +/* table of registered CAN protocols */
  +static struct can_proto *proto_tab[CAN_NPROTO] __read_mostly;
  +static DEFINE_SPINLOCK(proto_tab_lock);
  +
  +struct timer_list stattimer; /* timer for statistics update */
  +struct s_stats  stats;   /* packet statistics */
  +struct s_pstats pstats;  /* receive list statistics */
 
 More global variables without prefix.

These variables are not exported with EXPORT_SYMBOL, so there should
be no name conflict.  They cannot be made static because they are used
in af_can.c and proc.c.  Nevertheless we can prefix them with can_ if
you still think it's necessary.

  +static int can_proc_read_stats(char *page, char **start, off_t off,
  +  int count, int *eof, void *data)
  +{

  +}
 
 The read interface should use seq_file interface rather than
 formatting into page buffer.

Why?  For this simple function a page buffer is enough space and the
seq_file API would require more effort.  IMHO, seq_files offer
advantages if the proc file shows some sequence of data generated in
an iteration through some loop (see below).

  +static int can_proc_read_reset_stats(char *page, char **start, off_t off,
  +int count, int *eof, void *data)
  +{

  +}
 
 Why not have a write interface to do the reset?

I haven't looked into writable proc files yet.  Will do so.

  +static int can_proc_read_rcvlist(char *page, char **start, off_t off,
  +int count, int *eof, void *data)
  +{
  +   /* double cast to prevent GCC warning */
  +   int idx = (int)(long)data;

  +}

This is were I would prefer sequence files.  However, the seq file
interface doesn't allow me to pass additional info like the `data'
argument.  This means I would have to write separate functions
instead.

 Output from checkpatch:
 
 WARNING: do not add new typedefs
 #116: FILE: include/linux/can.h:41:
 +typedef __u32 canid_t;
 
 WARNING: do not add new typedefs
 #124: FILE: include/linux/can.h:49:
 +typedef __u32 can_err_mask_t;

These typedef were considered OK in previous discussions on the list.

 ERROR: use tabs not spaces
 #498: FILE: net/can/af_can.c:159:
 +^I^I^I^I not implemented.\n, module_name);$

Fixed.

 WARNING: braces {} are not necessary for single statement blocks
 #1080: FILE: net/can/af_can.c:741:
 + if (!proto_tab[proto]) {
 + printk(KERN_ERR BUG: can: protocol %d is not registered\n,
 +proto);
 + }

Hm, isn't it common to use braces for single statements if they span
more than one line?

Thanks for your review.

urs
-
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/7] CAN: Add PF_CAN core module

2007-11-15 Thread Urs Thuermann
Joe Perches [EMAIL PROTECTED] writes:

 On Thu, 2007-11-15 at 08:40 +0100, Oliver Hartkopp wrote:
  Stephen Hemminger wrote:
   +#ifdef CONFIG_CAN_DEBUG_CORE
   +extern void can_debug_skb(struct sk_buff *skb);
   +extern void can_debug_cframe(const char *msg, struct can_frame *cframe);
   +#define DBG(fmt, args...)  (DBG_VAR  1 ? printk( \
   +KERN_DEBUG DBG_PREFIX : %s:  
   fmt, \
   +__func__, ##args) : 0)
   +#define DBG_FRAME(fmt, cf) (DBG_VAR  2 ? can_debug_cframe(fmt, cf) : 0)
   +#define DBG_SKB(skb)   (DBG_VAR  4 ? can_debug_skb(skb) : 0)
   +#else
   +#define DBG(fmt, args...)
   +#define DBG_FRAME(fmt, cf)
   +#define DBG_SKB(skb)
   +#endif
 
 I would prefer the more frequently used macro style:
 
 #define DBG(fmt, args...) \
   do { if (DBG_VAR  1) printk(KERN_DEBUG DBG_PREFIX : %s:  fmt, \
__func__, ##args); } while (0)
 
 #define DBG_FRAME(fmt, cf) \
   do { if (DBG_VAR  2) can_debug_cframe(fmt, cf); } while (0)
 
 #define DBG_SKB(skb) \
   do { if (DBG_VAR  4) can_debug_skb(skb); } while (0)

I prefer our code because it is shorter (fits into one line) and can
be used anywhere where an expression is allowed compared to only where
a statement is allowed.  Actually, I first had

#define DBG( ... )   ((debug  1)  printk( ... ))

and so on, but that didn't work with can_debug_{cframe,sbk} since they
return void.

Admitted, the benefit of expr vs. statement is really negligible and
since this issue has come up several times I will change these macros
using do-while.

urs
-
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 6/7] CAN: Add maintainer entries

2007-11-14 Thread Urs Thuermann
This patch adds entries in the CREDITS and MAINTAINERS file for CAN.

Signed-off-by: Oliver Hartkopp [EMAIL PROTECTED]
Signed-off-by: Urs Thuermann [EMAIL PROTECTED]

---
 CREDITS |   16 
 MAINTAINERS |9 +
 2 files changed, 25 insertions(+)

Index: net-2.6.25/CREDITS
===
--- net-2.6.25.orig/CREDITS 2007-11-14 13:04:23.0 +0100
+++ net-2.6.25/CREDITS  2007-11-14 13:04:55.0 +0100
@@ -1353,6 +1353,14 @@
 S: 5623 HZ Eindhoven
 S: The Netherlands
 
+N: Oliver Hartkopp
+E: [EMAIL PROTECTED]
+W: http://www.volkswagen.de
+D: Controller Area Network (network layer core)
+S: Brieffach 1776
+S: 38436 Wolfsburg
+S: Germany
+
 N: Andrew Haylett
 E: [EMAIL PROTECTED]
 D: Selection mechanism
@@ -3306,6 +3314,14 @@
 S: F-35042 Rennes Cedex
 S: France
 
+N: Urs Thuermann
+E: [EMAIL PROTECTED]
+W: http://www.volkswagen.de
+D: Controller Area Network (network layer core)
+S: Brieffach 1776
+S: 38436 Wolfsburg
+S: Germany
+
 N: Jon Tombs
 E: [EMAIL PROTECTED]
 W: http://www.esi.us.es/~jon
Index: net-2.6.25/MAINTAINERS
===
--- net-2.6.25.orig/MAINTAINERS 2007-11-14 13:04:23.0 +0100
+++ net-2.6.25/MAINTAINERS  2007-11-14 13:04:56.0 +0100
@@ -981,6 +981,15 @@
 L: [EMAIL PROTECTED]
 S: Maintained
 
+CAN NETWORK LAYER
+P: Urs Thuermann
+M: [EMAIL PROTECTED]
+P: Oliver Hartkopp
+M: [EMAIL PROTECTED]
+L: [EMAIL PROTECTED]
+W: http://developer.berlios.de/projects/socketcan/
+S: Maintained
+
 CALGARY x86-64 IOMMU
 P: Muli Ben-Yehuda
 M: [EMAIL PROTECTED]

--
-
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 7/7] CAN: Add documentation

2007-11-14 Thread Urs Thuermann
This patch adds documentation for the PF_CAN protocol family.

Signed-off-by: Oliver Hartkopp [EMAIL PROTECTED]
Signed-off-by: Urs Thuermann [EMAIL PROTECTED]

---
 Documentation/networking/00-INDEX |2 
 Documentation/networking/can.txt  |  637 ++
 2 files changed, 639 insertions(+)

Index: net-2.6.25/Documentation/networking/can.txt
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ net-2.6.25/Documentation/networking/can.txt 2007-11-14 13:04:57.0 
+0100
@@ -0,0 +1,637 @@
+
+
+can.txt
+
+Readme file for the Controller Area Network Protocol Family (aka Socket CAN)
+
+This file contains
+
+  1 Overview / What is Socket CAN
+
+  2 Motivation / Why using the socket API
+
+  3 Socket CAN concept
+3.1 receive lists
+3.2 local loopback of sent frames
+3.3 network security issues (capabilities)
+3.4 network problem notifications
+
+  4 How to use Socket CAN
+4.1 RAW protocol sockets with can_filters (SOCK_RAW)
+  4.1.1 RAW socket option CAN_RAW_FILTER
+  4.1.2 RAW socket option CAN_RAW_ERR_FILTER
+  4.1.3 RAW socket option CAN_RAW_LOOPBACK
+  4.1.4 RAW socket option CAN_RAW_RECV_OWN_MSGS
+4.2 Broadcast Manager protocol sockets (SOCK_DGRAM)
+4.3 connected transport protocols (SOCK_SEQPACKET)
+4.4 unconnected transport protocols (SOCK_DGRAM)
+
+  5 Socket CAN core module
+5.1 can.ko module params
+5.2 procfs content
+5.3 writing own CAN protocol modules
+
+  6 CAN network drivers
+6.1 general settings
+6.2 local loopback of sent frames
+6.3 CAN controller hardware filters
+6.4 currently supported CAN hardware
+6.5 todo
+
+  7 Credits
+
+
+
+1. Overview / What is Socket CAN
+
+
+The socketcan package is an implementation of CAN protocols
+(Controller Area Network) for Linux.  CAN is a networking technology
+which has widespread use in automation, embedded devices, and
+automotive fields.  While there have been other CAN implementations
+for Linux based on character devices, Socket CAN uses the Berkeley
+socket API, the Linux network stack and implements the CAN device
+drivers as network interfaces.  The CAN socket API has been designed
+as similar as possible to the TCP/IP protocols to allow programmers,
+familiar with network programming, to easily learn how to use CAN
+sockets.
+
+2. Motivation / Why using the socket API
+
+
+There have been CAN implementations for Linux before Socket CAN so the
+question arises, why we have started another project.  Most existing
+implementations come as a device driver for some CAN hardware, they
+are based on character devices and provide comparatively little
+functionality.  Usually, there is only a hardware-specific device
+driver which provides a character device interface to send and
+receive raw CAN frames, directly to/from the controller hardware.
+Queueing of frames and higher-level transport protocols like ISO-TP
+have to be implemented in user space applications.  Also, most
+character-device implementations support only one single process to
+open the device at a time, similar to a serial interface.  Exchanging
+the CAN controller requires employment of another device driver and
+often the need for adaption of large parts of the application to the
+new driver's API.
+
+Socket CAN was designed to overcome all of these limitations.  A new
+protocol family has been implemented which provides a socket interface
+to user space applications and which builds upon the Linux network
+layer, so to use all of the provided queueing functionality.  A device
+driver for CAN controller hardware registers itself with the Linux
+network layer as a network device, so that CAN frames from the
+controller can be passed up to the network layer and on to the CAN
+protocol family module and also vice-versa.  Also, the protocol family
+module provides an API for transport protocol modules to register, so
+that any number of transport protocols can be loaded or unloaded
+dynamically.  In fact, the can core module alone does not provide any
+protocol and cannot be used without loading at least one additional
+protocol module.  Multiple sockets can be opened at the same time,
+on different or the same protocol module and they can listen/send
+frames on different or the same CAN IDs.  Several sockets listening on
+the same interface for frames with the same CAN ID are all passed the
+same received matching CAN frames.  An application wishing to
+communicate using a specific transport protocol, e.g. ISO-TP, just
+selects that protocol when opening the socket, and then can read and
+write application data byte streams, without having to deal with
+CAN-IDs, frames, etc

[PATCH 4/7] CAN: Add broadcast manager (bcm) protocol

2007-11-14 Thread Urs Thuermann
This patch adds the CAN broadcast manager (bcm) protocol.

Signed-off-by: Oliver Hartkopp [EMAIL PROTECTED]
Signed-off-by: Urs Thuermann [EMAIL PROTECTED]

---
 include/linux/can/bcm.h |   65 +
 net/can/Kconfig |   13 
 net/can/Makefile|3 
 net/can/bcm.c   | 1763 
 4 files changed, 1844 insertions(+)

Index: net-2.6.25/include/linux/can/bcm.h
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ net-2.6.25/include/linux/can/bcm.h  2007-11-14 13:04:52.0 +0100
@@ -0,0 +1,65 @@
+/*
+ * linux/can/bcm.h
+ *
+ * Definitions for CAN Broadcast Manager (BCM)
+ *
+ * Author: Oliver Hartkopp [EMAIL PROTECTED]
+ * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
+ * All rights reserved.
+ *
+ * Send feedback to [EMAIL PROTECTED]
+ *
+ */
+
+#ifndef CAN_BCM_H
+#define CAN_BCM_H
+
+/**
+ * struct bcm_msg_head - head of messages to/from the broadcast manager
+ * @opcode:opcode, see enum below.
+ * @flags: special flags, see below.
+ * @count: number of frames to send before changing interval.
+ * @ival1: interval for the first @count frames.
+ * @ival2: interval for the following frames.
+ * @can_id:CAN ID of frames to be sent or received.
+ * @nframes:   number of frames appended to the message head.
+ * @frames:array of CAN frames.
+ */
+struct bcm_msg_head {
+   int opcode;
+   int flags;
+   int count;
+   struct timeval ival1, ival2;
+   canid_t can_id;
+   int nframes;
+   struct can_frame frames[0];
+};
+
+enum {
+   TX_SETUP = 1,   /* create (cyclic) transmission task */
+   TX_DELETE,  /* remove (cyclic) transmission task */
+   TX_READ,/* read properties of (cyclic) transmission task */
+   TX_SEND,/* send one CAN frame */
+   RX_SETUP,   /* create RX content filter subscription */
+   RX_DELETE,  /* remove RX content filter subscription */
+   RX_READ,/* read properties of RX content filter subscription */
+   TX_STATUS,  /* reply to TX_READ request */
+   TX_EXPIRED, /* notification on performed transmissions (count=0) */
+   RX_STATUS,  /* reply to RX_READ request */
+   RX_TIMEOUT, /* cyclic message is absent */
+   RX_CHANGED  /* updated CAN frame (detected content change) */
+};
+
+#define SETTIMER0x0001
+#define STARTTIMER  0x0002
+#define TX_COUNTEVT 0x0004
+#define TX_ANNOUNCE 0x0008
+#define TX_CP_CAN_ID0x0010
+#define RX_FILTER_ID0x0020
+#define RX_CHECK_DLC0x0040
+#define RX_NO_AUTOTIMER 0x0080
+#define RX_ANNOUNCE_RESUME  0x0100
+#define TX_RESET_MULTI_IDX  0x0200
+#define RX_RTR_FRAME0x0400
+
+#endif /* CAN_BCM_H */
Index: net-2.6.25/net/can/Kconfig
===
--- net-2.6.25.orig/net/can/Kconfig 2007-11-14 13:04:51.0 +0100
+++ net-2.6.25/net/can/Kconfig  2007-11-14 13:04:52.0 +0100
@@ -27,6 +27,19 @@
  socket has several filter options e.g. ID masking / error frames.
  To receive/send raw CAN messages, use AF_CAN with protocol CAN_RAW.
 
+config CAN_BCM
+   tristate Broadcast Manager CAN Protocol (with content filtering)
+   depends on CAN
+   default N
+   ---help---
+ The Broadcast Manager offers content filtering, timeout monitoring,
+ sending of RTR frames, and cyclic CAN messages without permanent user
+ interaction. The BCM can be 'programmed' via the BSD socket API and
+ informs you on demand e.g. only on content updates / timeouts.
+ You probably want to use the bcm socket in most cases where cyclic
+ CAN messages are used on the bus (e.g. in automotive environments).
+ To use the Broadcast Manager, use AF_CAN with protocol CAN_BCM.
+
 config CAN_DEBUG_CORE
bool CAN Core debugging messages
depends on CAN
Index: net-2.6.25/net/can/Makefile
===
--- net-2.6.25.orig/net/can/Makefile2007-11-14 13:04:51.0 +0100
+++ net-2.6.25/net/can/Makefile 2007-11-14 13:04:52.0 +0100
@@ -7,3 +7,6 @@
 
 obj-$(CONFIG_CAN_RAW)  += can-raw.o
 can-raw-objs   := raw.o
+
+obj-$(CONFIG_CAN_BCM)  += can-bcm.o
+can-bcm-objs   := bcm.o
Index: net-2.6.25/net/can/bcm.c
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ net-2.6.25/net/can/bcm.c2007-11-14 13:04:52.0 +0100
@@ -0,0 +1,1763 @@
+/*
+ * bcm.c - Broadcast Manager to filter/send (cyclic) CAN content
+ *
+ * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided

[PATCH 5/7] CAN: Add virtual CAN netdevice driver

2007-11-14 Thread Urs Thuermann
This patch adds the virtual CAN bus (vcan) network driver.
The vcan device is just a loopback device for CAN frames, no
real CAN hardware is involved.

Signed-off-by: Oliver Hartkopp [EMAIL PROTECTED]
Signed-off-by: Urs Thuermann [EMAIL PROTECTED]

---
 drivers/net/Makefile |1 
 drivers/net/can/Kconfig  |   25 +
 drivers/net/can/Makefile |5 +
 drivers/net/can/vcan.c   |  207 +++
 net/can/Kconfig  |3 
 5 files changed, 241 insertions(+)

Index: net-2.6.25/drivers/net/Makefile
===
--- net-2.6.25.orig/drivers/net/Makefile2007-11-14 13:04:24.0 
+0100
+++ net-2.6.25/drivers/net/Makefile 2007-11-14 13:04:54.0 +0100
@@ -12,6 +12,7 @@
 obj-$(CONFIG_CHELSIO_T1) += chelsio/
 obj-$(CONFIG_CHELSIO_T3) += cxgb3/
 obj-$(CONFIG_EHEA) += ehea/
+obj-$(CONFIG_CAN) += can/
 obj-$(CONFIG_BONDING) += bonding/
 obj-$(CONFIG_ATL1) += atl1/
 obj-$(CONFIG_GIANFAR) += gianfar_driver.o
Index: net-2.6.25/drivers/net/can/Kconfig
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ net-2.6.25/drivers/net/can/Kconfig  2007-11-14 13:04:54.0 +0100
@@ -0,0 +1,25 @@
+menu CAN Device Drivers
+   depends on CAN
+
+config CAN_VCAN
+   tristate Virtual Local CAN Interface (vcan)
+   depends on CAN
+   default N
+   ---help---
+ Similar to the network loopback devices, vcan offers a
+ virtual local CAN interface.
+
+ This driver can also be built as a module.  If so, the module
+ will be called vcan.
+
+config CAN_DEBUG_DEVICES
+   bool CAN devices debugging messages
+   depends on CAN
+   default N
+   ---help---
+ Say Y here if you want the CAN device drivers to produce a bunch of
+ debug messages to the system log.  Select this if you are having
+ a problem with CAN support and want to see more of what is going
+ on.
+
+endmenu
Index: net-2.6.25/drivers/net/can/Makefile
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ net-2.6.25/drivers/net/can/Makefile 2007-11-14 13:04:54.0 +0100
@@ -0,0 +1,5 @@
+#
+#  Makefile for the Linux Controller Area Network drivers.
+#
+
+obj-$(CONFIG_CAN_VCAN) += vcan.o
Index: net-2.6.25/drivers/net/can/vcan.c
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ net-2.6.25/drivers/net/can/vcan.c   2007-11-14 13:04:54.0 +0100
@@ -0,0 +1,207 @@
+/*
+ * vcan.c - Virtual CAN interface
+ *
+ * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
+ * All rights reserved.
+ *
+ * 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. Neither the name of Volkswagen nor the names of its contributors
+ *may be used to endorse or promote products derived from this software
+ *without specific prior written permission.
+ *
+ * Alternatively, provided that this notice is retained in full, this
+ * software may be distributed under the terms of the GNU General
+ * Public License (GPL) version 2, in which case the provisions of the
+ * GPL apply INSTEAD OF those given above.
+ *
+ * The provided data structures and external interfaces from this code
+ * are not restricted to be used by modules with a GPL compatible license.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT
+ * OWNER 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.
+ *
+ * Send feedback to [EMAIL PROTECTED]
+ *
+ */
+
+#include linux/module.h
+#include linux/init.h
+#include linux/netdevice.h
+#include linux/if_arp.h
+#include linux/if_ether.h
+#include linux/can.h
+#include net/rtnetlink.h
+
+static

[PATCH 3/7] CAN: Add raw protocol

2007-11-14 Thread Urs Thuermann
This patch adds the CAN raw protocol.

Signed-off-by: Oliver Hartkopp [EMAIL PROTECTED]
Signed-off-by: Urs Thuermann [EMAIL PROTECTED]

---
 include/linux/can/raw.h |   31 +
 net/can/Kconfig |   11 
 net/can/Makefile|3 
 net/can/raw.c   |  811 
 4 files changed, 856 insertions(+)

Index: net-2.6.25/include/linux/can/raw.h
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ net-2.6.25/include/linux/can/raw.h  2007-11-14 13:04:51.0 +0100
@@ -0,0 +1,31 @@
+/*
+ * linux/can/raw.h
+ *
+ * Definitions for raw CAN sockets
+ *
+ * Authors: Oliver Hartkopp [EMAIL PROTECTED]
+ *  Urs Thuermann   [EMAIL PROTECTED]
+ * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
+ * All rights reserved.
+ *
+ * Send feedback to [EMAIL PROTECTED]
+ *
+ */
+
+#ifndef CAN_RAW_H
+#define CAN_RAW_H
+
+#include linux/can.h
+
+#define SOL_CAN_RAW (SOL_CAN_BASE + CAN_RAW)
+
+/* for socket options affecting the socket (not the global system) */
+
+enum {
+   CAN_RAW_FILTER = 1, /* set 0 .. n can_filter(s)  */
+   CAN_RAW_ERR_FILTER, /* set filter for error frames   */
+   CAN_RAW_LOOPBACK,   /* local loopback (default:on)   */
+   CAN_RAW_RECV_OWN_MSGS   /* receive my own msgs (default:off) */
+};
+
+#endif
Index: net-2.6.25/net/can/Kconfig
===
--- net-2.6.25.orig/net/can/Kconfig 2007-11-14 13:04:49.0 +0100
+++ net-2.6.25/net/can/Kconfig  2007-11-14 13:04:51.0 +0100
@@ -16,6 +16,17 @@
  If you want CAN support you should say Y here and also to the
  specific driver for your controller(s) below.
 
+config CAN_RAW
+   tristate Raw CAN Protocol (raw access with CAN-ID filtering)
+   depends on CAN
+   default N
+   ---help---
+ The raw CAN protocol option offers access to the CAN bus via
+ the BSD socket API. You probably want to use the raw socket in
+ most cases where no higher level protocol is being used. The raw
+ socket has several filter options e.g. ID masking / error frames.
+ To receive/send raw CAN messages, use AF_CAN with protocol CAN_RAW.
+
 config CAN_DEBUG_CORE
bool CAN Core debugging messages
depends on CAN
Index: net-2.6.25/net/can/Makefile
===
--- net-2.6.25.orig/net/can/Makefile2007-11-14 13:04:49.0 +0100
+++ net-2.6.25/net/can/Makefile 2007-11-14 13:04:51.0 +0100
@@ -4,3 +4,6 @@
 
 obj-$(CONFIG_CAN)  += can.o
 can-objs   := af_can.o proc.o
+
+obj-$(CONFIG_CAN_RAW)  += can-raw.o
+can-raw-objs   := raw.o
Index: net-2.6.25/net/can/raw.c
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ net-2.6.25/net/can/raw.c2007-11-14 13:04:51.0 +0100
@@ -0,0 +1,811 @@
+/*
+ * raw.c - Raw sockets for protocol family CAN
+ *
+ * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
+ * All rights reserved.
+ *
+ * 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. Neither the name of Volkswagen nor the names of its contributors
+ *may be used to endorse or promote products derived from this software
+ *without specific prior written permission.
+ *
+ * Alternatively, provided that this notice is retained in full, this
+ * software may be distributed under the terms of the GNU General
+ * Public License (GPL) version 2, in which case the provisions of the
+ * GPL apply INSTEAD OF those given above.
+ *
+ * The provided data structures and external interfaces from this code
+ * are not restricted to be used by modules with a GPL compatible license.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT
+ * OWNER 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

[PATCH 0/7] CAN: New PF_CAN protocol family for 2.6.25

2007-11-14 Thread Urs Thuermann
Hello Dave, hello Patrick,

this patch series that adds the PF_CAN protocol family for the
Controller Area Network.  Since our last post we have changed:

* Fix a bug causing NULL pointer dereference when module autoloading fails.
* Initialize skb using skb_reset_{transport,network}_header().
* Use sock_alloc_send_skb() instead of alloc_skb().
* Adapt to changes in sk_alloc() parameter list.
* Rename some local variables for readability.

This patch series applies against net-2.6.25 and is derived from Subversion
revision r542 of http://svn.berlios.de/svnroot/repos/socketcan.
It can be found in the directory
http://svn.berlios.de/svnroot/repos/socketcan/trunk/patch-series/version.

Thanks very much for your work!

Best regards,

Urs Thuermann
Oliver Hartkopp



The changes in try #10 were:

* Rename our static debug variables to {can,raw,bcm,vcan}_debug.
* Use module_param_named() so that the module option names remain.
* Remove raw_poll() and bcm_poll() functions and use datagram_poll instead.
* Cleanup of can_addr union in sockaddr_can.
* Change type of echo module parameter to boolean.

The changes in try #9 were:

* Changes suggested by Arnaldo Carvalho de Melo:
  - Use gfp_any() instead of checking in_interrupt().
  - Don't kfree() the sk_protinfo field.
* Fixed licence text as pointed out by Yoshifuji Hideaki and Patrick McHardy.
* Added IFF_ECHO to include/linux/if.h and use that instead of IFF_LOOPBACK,
  as suggested by Eric W. Biederman.  IFF_LOOPBACK is only for the normal
  loopback interface.

The changes in try #8 were:

* Some changes in debug code, following suggestions from Joe Perches:
  - Remove dynamically allocated buffer for debug output.
  - Use kernel functions for hexdumps.
  - Don't interpret printf-style %-sequences in can_debug_cframe().
  - Specify the fixed argument fmt to DBG() macro and use
GCC ## mechanism to remove , when args is empty.
* Removed CAN_RAW_USER and CAN_BCM_USER Kconfig options following a
  suggestion from Patrick.
* Prevent overflow in statistics calculation.
* Minor optimization.

The changes in try #7 were:

* Changes suggested by Patrick:
  - protect proto_tab[] by a lock.
  - add _rcu to some hlist traversals.
  - use printk_ratelimit() for module autoload failures.
  - make can_proto_unregister() and can_rx_unregister() return void.
  - use return value of can_proto_register() and can_rx_register()
(this also removed a flaw in behavior of raw_bind() and raw_setsockopt()
 in case of failure to can_rx_register() their filters).
  - call kzalloc() with GFP_KERNEL in case NETDEV_REGISTER.
  - use round_jiffies() to calculate expiration times.
  - make some variables static and/or __read_mostly.
  - in can_create() check for net namespace before auto loading modules.
  - add build time check for struct sizes.
  - use skb_share_chack() in vcan.
  - fixed some comments.
* Typos in documentation as pointed out by Randy Dunlap and Bill Fink.

The changes in try #6 were:

* Update code to work with namespaces in net-2.6.24.
* Remove SET_MODULE_OWNER() from vcan.

The changes in try #5 were:

* Remove slab destructor from calls to kmem_cache_alloc().
* Add comments about types defined in can.h.
* Update comment on vcan loopback module parameter.
* Fix typo in documentation.

The changes in try #4 were:

* Change vcan network driver to use the new RTNL API, as suggested by
  Patrick.
* Revert our change to use skb-iif instead of skb-cb.  After
  discussion with Patrick and Jamal it turned out, our first
  implementation was correct.
* Use skb_tail_pointer() instead of skb-tail directly.
* Coding style changes to satisfy linux/scripts/checkpatch.pl.
* Minor changes for 64-bit-cleanliness.
* Minor cleanup of #include's

The changes in try #3 were:

* Use sbk-sk and skb-pkt_type instead of skb-cb to pass loopback
  flags and originating socket down to the driver and back to the
  receiving socket.  Thanks to Patrick McHardy for pointing out our
  wrong use of sbk-cb.
* Use skb-iif instead of skb-cb to pass receiving interface from
  raw_rcv() and bcm_rcv() up to raw_recvmsg() and bcm_recvmsg().
* Set skb-protocol when sending CAN frames to netdevices.
* Removed struct raw_opt and struct bcm_opt and integrated these
  directly into struct raw_sock and bcm_sock resp., like most other
  proto implementations do.
* We have found and fixed race conditions between raw_bind(),
  raw_{set,get}sockopt() and raw_notifier().  This resulted in
  - complete removal of our own notifier list infrastructure in
af_can.c.  raw.c and bcm.c now use normal netdevice notifiers.
  - removal of ro-lock spinlock.  We use lock_sock(sk) now.
  - changed deletion of dev_rcv_lists, which are now marked for
deletion in the netdevice notifier in af_can.c and are actually
deleted when all entries have been deleted using can_rx_unregister().
* Follow changes in 2.6.22 (e.g. ktime_t timestamps in skb).
* Removed obsolete code from vcan.c, as pointed out by Stephen Hemminger

[PATCH 1/7] CAN: Allocate protocol numbers for PF_CAN

2007-11-14 Thread Urs Thuermann
This patch adds a protocol/address family number, ARP hardware type,
ethernet packet type, and a line discipline number for the SocketCAN
implementation.

Signed-off-by: Oliver Hartkopp [EMAIL PROTECTED]
Signed-off-by: Urs Thuermann [EMAIL PROTECTED]

---
 include/linux/if.h   |4 +++-
 include/linux/if_arp.h   |1 +
 include/linux/if_ether.h |1 +
 include/linux/socket.h   |2 ++
 include/linux/tty.h  |3 ++-
 net/core/sock.c  |4 ++--
 6 files changed, 11 insertions(+), 4 deletions(-)

Index: net-2.6.25/include/linux/if_arp.h
===
--- net-2.6.25.orig/include/linux/if_arp.h  2007-11-14 13:04:26.0 
+0100
+++ net-2.6.25/include/linux/if_arp.h   2007-11-14 13:04:46.0 +0100
@@ -52,6 +52,7 @@
 #define ARPHRD_ROSE270
 #define ARPHRD_X25 271 /* CCITT X.25   */
 #define ARPHRD_HWX25   272 /* Boards with X.25 in firmware */
+#define ARPHRD_CAN 280 /* Controller Area Network  */
 #define ARPHRD_PPP 512
 #define ARPHRD_CISCO   513 /* Cisco HDLC   */
 #define ARPHRD_HDLCARPHRD_CISCO
Index: net-2.6.25/include/linux/if_ether.h
===
--- net-2.6.25.orig/include/linux/if_ether.h2007-11-14 13:04:26.0 
+0100
+++ net-2.6.25/include/linux/if_ether.h 2007-11-14 13:04:46.0 +0100
@@ -90,6 +90,7 @@
 #define ETH_P_WAN_PPP   0x0007  /* Dummy type for WAN PPP frames*/
 #define ETH_P_PPP_MP0x0008  /* Dummy type for PPP MP frames */
 #define ETH_P_LOCALTALK 0x0009 /* Localtalk pseudo type*/
+#define ETH_P_CAN  0x000C  /* Controller Area Network  */
 #define ETH_P_PPPTALK  0x0010  /* Dummy type for Atalk over PPP*/
 #define ETH_P_TR_802_2 0x0011  /* 802.2 frames */
 #define ETH_P_MOBITEX  0x0015  /* Mobitex ([EMAIL PROTECTED])  */
Index: net-2.6.25/include/linux/socket.h
===
--- net-2.6.25.orig/include/linux/socket.h  2007-11-14 13:04:26.0 
+0100
+++ net-2.6.25/include/linux/socket.h   2007-11-14 13:04:46.0 +0100
@@ -185,6 +185,7 @@
 #define AF_PPPOX   24  /* PPPoX sockets*/
 #define AF_WANPIPE 25  /* Wanpipe API Sockets */
 #define AF_LLC 26  /* Linux LLC*/
+#define AF_CAN 29  /* Controller Area Network  */
 #define AF_TIPC30  /* TIPC sockets */
 #define AF_BLUETOOTH   31  /* Bluetooth sockets*/
 #define AF_IUCV32  /* IUCV sockets */
@@ -220,6 +221,7 @@
 #define PF_PPPOX   AF_PPPOX
 #define PF_WANPIPE AF_WANPIPE
 #define PF_LLC AF_LLC
+#define PF_CAN AF_CAN
 #define PF_TIPCAF_TIPC
 #define PF_BLUETOOTH   AF_BLUETOOTH
 #define PF_IUCVAF_IUCV
Index: net-2.6.25/include/linux/tty.h
===
--- net-2.6.25.orig/include/linux/tty.h 2007-11-14 13:04:26.0 +0100
+++ net-2.6.25/include/linux/tty.h  2007-11-14 13:04:46.0 +0100
@@ -23,7 +23,7 @@
  */
 #define NR_UNIX98_PTY_DEFAULT  4096  /* Default maximum for Unix98 ptys */
 #define NR_UNIX98_PTY_MAX  (1  MINORBITS) /* Absolute limit */
-#define NR_LDISCS  17
+#define NR_LDISCS  18
 
 /* line disciplines */
 #define N_TTY  0
@@ -44,6 +44,7 @@
 #define N_SYNC_PPP 14  /* synchronous PPP */
 #define N_HCI  15  /* Bluetooth HCI UART */
 #define N_GIGASET_M101 16  /* Siemens Gigaset M101 serial DECT adapter */
+#define N_SLCAN17  /* Serial / USB serial CAN Adaptors */
 
 /*
  * This character is the same as _POSIX_VDISABLE: it cannot be used as
Index: net-2.6.25/net/core/sock.c
===
--- net-2.6.25.orig/net/core/sock.c 2007-11-14 13:04:26.0 +0100
+++ net-2.6.25/net/core/sock.c  2007-11-14 13:04:47.0 +0100
@@ -154,7 +154,7 @@
   sk_lock-AF_ASH   , sk_lock-AF_ECONET   , sk_lock-AF_ATMSVC   ,
   sk_lock-21   , sk_lock-AF_SNA  , sk_lock-AF_IRDA ,
   sk_lock-AF_PPPOX , sk_lock-AF_WANPIPE  , sk_lock-AF_LLC  ,
-  sk_lock-27   , sk_lock-28  , sk_lock-29  ,
+  sk_lock-27   , sk_lock-28  , sk_lock-AF_CAN  ,
   sk_lock-AF_TIPC  , sk_lock-AF_BLUETOOTH, sk_lock-IUCV,
   sk_lock-AF_RXRPC , sk_lock-AF_MAX
 };
@@ -168,7 +168,7 @@
   slock-AF_ASH   , slock-AF_ECONET   , slock-AF_ATMSVC   ,
   slock-21   , slock-AF_SNA  , slock-AF_IRDA ,
   slock-AF_PPPOX , slock-AF_WANPIPE  , slock-AF_LLC  ,
-  slock-27   , slock-28  , slock-29  ,
+  slock-27   , slock-28  , slock-AF_CAN

Re: [PATCH 5/7] CAN: Add virtual CAN netdevice driver

2007-11-14 Thread Urs Thuermann
Patrick McHardy [EMAIL PROTECTED] writes:

  +static int vcan_open(struct net_device *dev)

  +static int vcan_stop(struct net_device *dev)

 These two functions look unnecessary, there's no need to manage
 the queue for pure software devices.

OK, removed.

 Please use the NETDEV_TX codes.

OK, replaced return 0 by NETDEV_TX_OK.

The new patch is below.

urs



This patch adds the virtual CAN bus (vcan) network driver.
The vcan device is just a loopback device for CAN frames, no
real CAN hardware is involved.

Signed-off-by: Oliver Hartkopp [EMAIL PROTECTED]
Signed-off-by: Urs Thuermann [EMAIL PROTECTED]

---
 drivers/net/Makefile |1 
 drivers/net/can/Kconfig  |   25 ++
 drivers/net/can/Makefile |5 +
 drivers/net/can/vcan.c   |  189 +++
 net/can/Kconfig  |3 
 5 files changed, 223 insertions(+)

Index: net-2.6.25/drivers/net/Makefile
===
--- net-2.6.25.orig/drivers/net/Makefile2007-11-14 13:04:24.0 
+0100
+++ net-2.6.25/drivers/net/Makefile 2007-11-14 13:04:54.0 +0100
@@ -12,6 +12,7 @@
 obj-$(CONFIG_CHELSIO_T1) += chelsio/
 obj-$(CONFIG_CHELSIO_T3) += cxgb3/
 obj-$(CONFIG_EHEA) += ehea/
+obj-$(CONFIG_CAN) += can/
 obj-$(CONFIG_BONDING) += bonding/
 obj-$(CONFIG_ATL1) += atl1/
 obj-$(CONFIG_GIANFAR) += gianfar_driver.o
Index: net-2.6.25/drivers/net/can/Kconfig
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ net-2.6.25/drivers/net/can/Kconfig  2007-11-14 13:04:54.0 +0100
@@ -0,0 +1,25 @@
+menu CAN Device Drivers
+   depends on CAN
+
+config CAN_VCAN
+   tristate Virtual Local CAN Interface (vcan)
+   depends on CAN
+   default N
+   ---help---
+ Similar to the network loopback devices, vcan offers a
+ virtual local CAN interface.
+
+ This driver can also be built as a module.  If so, the module
+ will be called vcan.
+
+config CAN_DEBUG_DEVICES
+   bool CAN devices debugging messages
+   depends on CAN
+   default N
+   ---help---
+ Say Y here if you want the CAN device drivers to produce a bunch of
+ debug messages to the system log.  Select this if you are having
+ a problem with CAN support and want to see more of what is going
+ on.
+
+endmenu
Index: net-2.6.25/drivers/net/can/Makefile
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ net-2.6.25/drivers/net/can/Makefile 2007-11-14 13:04:54.0 +0100
@@ -0,0 +1,5 @@
+#
+#  Makefile for the Linux Controller Area Network drivers.
+#
+
+obj-$(CONFIG_CAN_VCAN) += vcan.o
Index: net-2.6.25/drivers/net/can/vcan.c
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ net-2.6.25/drivers/net/can/vcan.c   2007-11-14 14:17:43.0 +0100
@@ -0,0 +1,189 @@
+/*
+ * vcan.c - Virtual CAN interface
+ *
+ * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
+ * All rights reserved.
+ *
+ * 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. Neither the name of Volkswagen nor the names of its contributors
+ *may be used to endorse or promote products derived from this software
+ *without specific prior written permission.
+ *
+ * Alternatively, provided that this notice is retained in full, this
+ * software may be distributed under the terms of the GNU General
+ * Public License (GPL) version 2, in which case the provisions of the
+ * GPL apply INSTEAD OF those given above.
+ *
+ * The provided data structures and external interfaces from this code
+ * are not restricted to be used by modules with a GPL compatible license.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT
+ * OWNER 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

[PATCH] [AF_PACKET] Fix minor code duplication

2007-11-08 Thread Urs Thuermann
Simplify some code by eliminating duplicate if-else clauses in
packet_do_bind().


Signed-off-by: Urs Thuermann [EMAIL PROTECTED]


--- net-2.6/net/packet/af_packet.c.orig 2007-11-05 13:07:28.0 +0100
+++ net-2.6/net/packet/af_packet.c  2007-11-08 12:14:25.0 +0100
@@ -886,20 +886,14 @@ static int packet_do_bind(struct sock *s
if (protocol == 0)
goto out_unlock;
 
-   if (dev) {
-   if (dev-flagsIFF_UP) {
-   dev_add_pack(po-prot_hook);
-   sock_hold(sk);
-   po-running = 1;
-   } else {
-   sk-sk_err = ENETDOWN;
-   if (!sock_flag(sk, SOCK_DEAD))
-   sk-sk_error_report(sk);
-   }
-   } else {
+   if (!dev || (dev-flags  IFF_UP)) {
dev_add_pack(po-prot_hook);
sock_hold(sk);
po-running = 1;
+   } else {
+   sk-sk_err = ENETDOWN;
+   if (!sock_flag(sk, SOCK_DEAD))
+   sk-sk_error_report(sk);
}
 
 out_unlock:
-
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] - trivial - Improve appletalk checksum calculation

2007-10-28 Thread Urs Thuermann
Herbert Xu [EMAIL PROTECTED] writes:

 But your code differs significantly from Stephen's version.
 However, if it is correct it does look like a good improvement.
 
 So please write a simple test program.  It can't that bad since
 there are only 65536 values to test :)

I think the code is simple enough to see immediately that it should
calculate the same checksum.  But I have written a short test program
to show this and tested it on i686 (gcc-4.2.2) and powerpc (gcc-3.4.5)
without optimization and with -O6.

BTW, shouldn't unsigned long be replaced by unsigned int to avoid
64-bit operations one some platforms?

urs


#include stdio.h

unsigned long f1(unsigned long sum)
{
sum = 1;
if (sum  0x1) {
sum++;
sum = 0x;
}
return sum;
}

unsigned long f2(unsigned long sum)
{
sum = ((sum  0x8000)15) | ((sum  0x7fff)1);
return sum;
}

int main()
{
unsigned long s;

for (s = 0; s  65536; s++) {
if (f1(s) != f2(s) || f1(s)  65535)
printf(%ld\n, s);
}
return 0;
}
-
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: net-2.6.24 rebased...

2007-10-09 Thread Urs Thuermann
Hallo Dave,

 9.1MB, 739 changesets, keep those patches flowing!

Last week I have sent another version of our patch series for PF_CAN.
The changes after the last review feedback were only cosmetics.

Do you have any plans with that code for this or the next release?

Regards,
urs
-
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 4/7] CAN: Add broadcast manager (bcm) protocol

2007-10-05 Thread Urs Thuermann
This patch adds the CAN broadcast manager (bcm) protocol.

Signed-off-by: Oliver Hartkopp [EMAIL PROTECTED]
Signed-off-by: Urs Thuermann [EMAIL PROTECTED]

---
 include/linux/can/bcm.h |   65 +
 net/can/Kconfig |   13 
 net/can/Makefile|3 
 net/can/bcm.c   | 1763 
 4 files changed, 1844 insertions(+)

Index: net-2.6.24/include/linux/can/bcm.h
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ net-2.6.24/include/linux/can/bcm.h  2007-10-05 11:13:17.0 +0200
@@ -0,0 +1,65 @@
+/*
+ * linux/can/bcm.h
+ *
+ * Definitions for CAN Broadcast Manager (BCM)
+ *
+ * Author: Oliver Hartkopp [EMAIL PROTECTED]
+ * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
+ * All rights reserved.
+ *
+ * Send feedback to [EMAIL PROTECTED]
+ *
+ */
+
+#ifndef CAN_BCM_H
+#define CAN_BCM_H
+
+/**
+ * struct bcm_msg_head - head of messages to/from the broadcast manager
+ * @opcode:opcode, see enum below.
+ * @flags: special flags, see below.
+ * @count: number of frames to send before changing interval.
+ * @ival1: interval for the first @count frames.
+ * @ival2: interval for the following frames.
+ * @can_id:CAN ID of frames to be sent or received.
+ * @nframes:   number of frames appended to the message head.
+ * @frames:array of CAN frames.
+ */
+struct bcm_msg_head {
+   int opcode;
+   int flags;
+   int count;
+   struct timeval ival1, ival2;
+   canid_t can_id;
+   int nframes;
+   struct can_frame frames[0];
+};
+
+enum {
+   TX_SETUP = 1,   /* create (cyclic) transmission task */
+   TX_DELETE,  /* remove (cyclic) transmission task */
+   TX_READ,/* read properties of (cyclic) transmission task */
+   TX_SEND,/* send one CAN frame */
+   RX_SETUP,   /* create RX content filter subscription */
+   RX_DELETE,  /* remove RX content filter subscription */
+   RX_READ,/* read properties of RX content filter subscription */
+   TX_STATUS,  /* reply to TX_READ request */
+   TX_EXPIRED, /* notification on performed transmissions (count=0) */
+   RX_STATUS,  /* reply to RX_READ request */
+   RX_TIMEOUT, /* cyclic message is absent */
+   RX_CHANGED  /* updated CAN frame (detected content change) */
+};
+
+#define SETTIMER0x0001
+#define STARTTIMER  0x0002
+#define TX_COUNTEVT 0x0004
+#define TX_ANNOUNCE 0x0008
+#define TX_CP_CAN_ID0x0010
+#define RX_FILTER_ID0x0020
+#define RX_CHECK_DLC0x0040
+#define RX_NO_AUTOTIMER 0x0080
+#define RX_ANNOUNCE_RESUME  0x0100
+#define TX_RESET_MULTI_IDX  0x0200
+#define RX_RTR_FRAME0x0400
+
+#endif /* CAN_BCM_H */
Index: net-2.6.24/net/can/Kconfig
===
--- net-2.6.24.orig/net/can/Kconfig 2007-10-05 11:12:35.0 +0200
+++ net-2.6.24/net/can/Kconfig  2007-10-05 11:13:49.0 +0200
@@ -27,6 +27,19 @@
  socket has several filter options e.g. ID masking / error frames.
  To receive/send raw CAN messages, use AF_CAN with protocol CAN_RAW.
 
+config CAN_BCM
+   tristate Broadcast Manager CAN Protocol (with content filtering)
+   depends on CAN
+   default N
+   ---help---
+ The Broadcast Manager offers content filtering, timeout monitoring,
+ sending of RTR frames, and cyclic CAN messages without permanent user
+ interaction. The BCM can be 'programmed' via the BSD socket API and
+ informs you on demand e.g. only on content updates / timeouts.
+ You probably want to use the bcm socket in most cases where cyclic
+ CAN messages are used on the bus (e.g. in automotive environments).
+ To use the Broadcast Manager, use AF_CAN with protocol CAN_BCM.
+
 config CAN_DEBUG_CORE
bool CAN Core debugging messages
depends on CAN
Index: net-2.6.24/net/can/Makefile
===
--- net-2.6.24.orig/net/can/Makefile2007-10-05 11:11:41.0 +0200
+++ net-2.6.24/net/can/Makefile 2007-10-05 11:13:17.0 +0200
@@ -7,3 +7,6 @@
 
 obj-$(CONFIG_CAN_RAW)  += can-raw.o
 can-raw-objs   := raw.o
+
+obj-$(CONFIG_CAN_BCM)  += can-bcm.o
+can-bcm-objs   := bcm.o
Index: net-2.6.24/net/can/bcm.c
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ net-2.6.24/net/can/bcm.c2007-10-05 11:13:17.0 +0200
@@ -0,0 +1,1763 @@
+/*
+ * bcm.c - Broadcast Manager to filter/send (cyclic) CAN content
+ *
+ * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided

[PATCH 5/7] CAN: Add virtual CAN netdevice driver

2007-10-05 Thread Urs Thuermann
This patch adds the virtual CAN bus (vcan) network driver.
The vcan device is just a loopback device for CAN frames, no
real CAN hardware is involved.

Signed-off-by: Oliver Hartkopp [EMAIL PROTECTED]
Signed-off-by: Urs Thuermann [EMAIL PROTECTED]

---
 drivers/net/Makefile |1 
 drivers/net/can/Kconfig  |   25 +
 drivers/net/can/Makefile |5 +
 drivers/net/can/vcan.c   |  207 +++
 net/can/Kconfig  |3 
 5 files changed, 241 insertions(+)

Index: net-2.6.24/drivers/net/Makefile
===
--- net-2.6.24.orig/drivers/net/Makefile2007-10-05 11:08:03.0 
+0200
+++ net-2.6.24/drivers/net/Makefile 2007-10-05 11:17:41.0 +0200
@@ -12,6 +12,7 @@
 obj-$(CONFIG_CHELSIO_T1) += chelsio/
 obj-$(CONFIG_CHELSIO_T3) += cxgb3/
 obj-$(CONFIG_EHEA) += ehea/
+obj-$(CONFIG_CAN) += can/
 obj-$(CONFIG_BONDING) += bonding/
 obj-$(CONFIG_ATL1) += atl1/
 obj-$(CONFIG_GIANFAR) += gianfar_driver.o
Index: net-2.6.24/drivers/net/can/Kconfig
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ net-2.6.24/drivers/net/can/Kconfig  2007-10-05 11:17:41.0 +0200
@@ -0,0 +1,25 @@
+menu CAN Device Drivers
+   depends on CAN
+
+config CAN_VCAN
+   tristate Virtual Local CAN Interface (vcan)
+   depends on CAN
+   default N
+   ---help---
+ Similar to the network loopback devices, vcan offers a
+ virtual local CAN interface.
+
+ This driver can also be built as a module.  If so, the module
+ will be called vcan.
+
+config CAN_DEBUG_DEVICES
+   bool CAN devices debugging messages
+   depends on CAN
+   default N
+   ---help---
+ Say Y here if you want the CAN device drivers to produce a bunch of
+ debug messages to the system log.  Select this if you are having
+ a problem with CAN support and want to see more of what is going
+ on.
+
+endmenu
Index: net-2.6.24/drivers/net/can/Makefile
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ net-2.6.24/drivers/net/can/Makefile 2007-10-05 11:17:41.0 +0200
@@ -0,0 +1,5 @@
+#
+#  Makefile for the Linux Controller Area Network drivers.
+#
+
+obj-$(CONFIG_CAN_VCAN) += vcan.o
Index: net-2.6.24/drivers/net/can/vcan.c
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ net-2.6.24/drivers/net/can/vcan.c   2007-10-05 11:17:41.0 +0200
@@ -0,0 +1,207 @@
+/*
+ * vcan.c - Virtual CAN interface
+ *
+ * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
+ * All rights reserved.
+ *
+ * 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. Neither the name of Volkswagen nor the names of its contributors
+ *may be used to endorse or promote products derived from this software
+ *without specific prior written permission.
+ *
+ * Alternatively, provided that this notice is retained in full, this
+ * software may be distributed under the terms of the GNU General
+ * Public License (GPL) version 2, in which case the provisions of the
+ * GPL apply INSTEAD OF those given above.
+ *
+ * The provided data structures and external interfaces from this code
+ * are not restricted to be used by modules with a GPL compatible license.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT
+ * OWNER 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.
+ *
+ * Send feedback to [EMAIL PROTECTED]
+ *
+ */
+
+#include linux/module.h
+#include linux/init.h
+#include linux/netdevice.h
+#include linux/if_arp.h
+#include linux/if_ether.h
+#include linux/can.h
+#include net/rtnetlink.h
+
+static

[PATCH 0/7] CAN: Add new PF_CAN protocol family, try #10

2007-10-05 Thread Urs Thuermann
revision r522 of http://svn.berlios.de/svnroot/repos/socketcan.
It can be found in the directory
http://svn.berlios.de/svnroot/repos/socketcan/trunk/patch-series/version.

Thanks very much for your work!

Best regards,

Urs Thuermann
Oliver Hartkopp
--
-
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 6/7] CAN: Add maintainer entries

2007-10-05 Thread Urs Thuermann
This patch adds entries in the CREDITS and MAINTAINERS file for CAN.

Signed-off-by: Oliver Hartkopp [EMAIL PROTECTED]
Signed-off-by: Urs Thuermann [EMAIL PROTECTED]

---
 CREDITS |   16 
 MAINTAINERS |9 +
 2 files changed, 25 insertions(+)

Index: net-2.6.24/CREDITS
===
--- net-2.6.24.orig/CREDITS 2007-09-20 06:37:28.0 +0200
+++ net-2.6.24/CREDITS  2007-10-02 12:03:43.0 +0200
@@ -1347,6 +1347,14 @@
 S: 5623 HZ Eindhoven
 S: The Netherlands
 
+N: Oliver Hartkopp
+E: [EMAIL PROTECTED]
+W: http://www.volkswagen.de
+D: Controller Area Network (network layer core)
+S: Brieffach 1776
+S: 38436 Wolfsburg
+S: Germany
+
 N: Andrew Haylett
 E: [EMAIL PROTECTED]
 D: Selection mechanism
@@ -3300,6 +3308,14 @@
 S: F-35042 Rennes Cedex
 S: France
 
+N: Urs Thuermann
+E: [EMAIL PROTECTED]
+W: http://www.volkswagen.de
+D: Controller Area Network (network layer core)
+S: Brieffach 1776
+S: 38436 Wolfsburg
+S: Germany
+
 N: Jon Tombs
 E: [EMAIL PROTECTED]
 W: http://www.esi.us.es/~jon
Index: net-2.6.24/MAINTAINERS
===
--- net-2.6.24.orig/MAINTAINERS 2007-09-28 18:01:52.0 +0200
+++ net-2.6.24/MAINTAINERS  2007-10-02 12:03:43.0 +0200
@@ -991,6 +991,15 @@
 L: [EMAIL PROTECTED]
 S: Maintained
 
+CAN NETWORK LAYER
+P: Urs Thuermann
+M: [EMAIL PROTECTED]
+P: Oliver Hartkopp
+M: [EMAIL PROTECTED]
+L: [EMAIL PROTECTED]
+W: http://developer.berlios.de/projects/socketcan/
+S: Maintained
+
 CALGARY x86-64 IOMMU
 P: Muli Ben-Yehuda
 M: [EMAIL PROTECTED]

--
-
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 3/7] CAN: Add raw protocol

2007-10-05 Thread Urs Thuermann
This patch adds the CAN raw protocol.

Signed-off-by: Oliver Hartkopp [EMAIL PROTECTED]
Signed-off-by: Urs Thuermann [EMAIL PROTECTED]

---
 include/linux/can/raw.h |   31 +
 net/can/Kconfig |   11 
 net/can/Makefile|3 
 net/can/raw.c   |  810 
 4 files changed, 855 insertions(+)

Index: net-2.6.24/include/linux/can/raw.h
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ net-2.6.24/include/linux/can/raw.h  2007-10-05 11:11:41.0 +0200
@@ -0,0 +1,31 @@
+/*
+ * linux/can/raw.h
+ *
+ * Definitions for raw CAN sockets
+ *
+ * Authors: Oliver Hartkopp [EMAIL PROTECTED]
+ *  Urs Thuermann   [EMAIL PROTECTED]
+ * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
+ * All rights reserved.
+ *
+ * Send feedback to [EMAIL PROTECTED]
+ *
+ */
+
+#ifndef CAN_RAW_H
+#define CAN_RAW_H
+
+#include linux/can.h
+
+#define SOL_CAN_RAW (SOL_CAN_BASE + CAN_RAW)
+
+/* for socket options affecting the socket (not the global system) */
+
+enum {
+   CAN_RAW_FILTER = 1, /* set 0 .. n can_filter(s)  */
+   CAN_RAW_ERR_FILTER, /* set filter for error frames   */
+   CAN_RAW_LOOPBACK,   /* local loopback (default:on)   */
+   CAN_RAW_RECV_OWN_MSGS   /* receive my own msgs (default:off) */
+};
+
+#endif
Index: net-2.6.24/net/can/Kconfig
===
--- net-2.6.24.orig/net/can/Kconfig 2007-10-05 11:11:04.0 +0200
+++ net-2.6.24/net/can/Kconfig  2007-10-05 11:12:35.0 +0200
@@ -16,6 +16,17 @@
  If you want CAN support you should say Y here and also to the
  specific driver for your controller(s) below.
 
+config CAN_RAW
+   tristate Raw CAN Protocol (raw access with CAN-ID filtering)
+   depends on CAN
+   default N
+   ---help---
+ The raw CAN protocol option offers access to the CAN bus via
+ the BSD socket API. You probably want to use the raw socket in
+ most cases where no higher level protocol is being used. The raw
+ socket has several filter options e.g. ID masking / error frames.
+ To receive/send raw CAN messages, use AF_CAN with protocol CAN_RAW.
+
 config CAN_DEBUG_CORE
bool CAN Core debugging messages
depends on CAN
Index: net-2.6.24/net/can/Makefile
===
--- net-2.6.24.orig/net/can/Makefile2007-10-05 11:08:05.0 +0200
+++ net-2.6.24/net/can/Makefile 2007-10-05 11:11:41.0 +0200
@@ -4,3 +4,6 @@
 
 obj-$(CONFIG_CAN)  += can.o
 can-objs   := af_can.o proc.o
+
+obj-$(CONFIG_CAN_RAW)  += can-raw.o
+can-raw-objs   := raw.o
Index: net-2.6.24/net/can/raw.c
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ net-2.6.24/net/can/raw.c2007-10-05 11:11:41.0 +0200
@@ -0,0 +1,810 @@
+/*
+ * raw.c - Raw sockets for protocol family CAN
+ *
+ * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
+ * All rights reserved.
+ *
+ * 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. Neither the name of Volkswagen nor the names of its contributors
+ *may be used to endorse or promote products derived from this software
+ *without specific prior written permission.
+ *
+ * Alternatively, provided that this notice is retained in full, this
+ * software may be distributed under the terms of the GNU General
+ * Public License (GPL) version 2, in which case the provisions of the
+ * GPL apply INSTEAD OF those given above.
+ *
+ * The provided data structures and external interfaces from this code
+ * are not restricted to be used by modules with a GPL compatible license.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT
+ * OWNER 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

[PATCH 1/7] CAN: Allocate protocol numbers for PF_CAN

2007-10-05 Thread Urs Thuermann
This patch adds a protocol/address family number, ARP hardware type,
ethernet packet type, and a line discipline number for the SocketCAN
implementation.

Signed-off-by: Oliver Hartkopp [EMAIL PROTECTED]
Signed-off-by: Urs Thuermann [EMAIL PROTECTED]

---
 include/linux/if.h   |4 +++-
 include/linux/if_arp.h   |1 +
 include/linux/if_ether.h |1 +
 include/linux/socket.h   |2 ++
 include/linux/tty.h  |3 ++-
 net/core/sock.c  |4 ++--
 6 files changed, 11 insertions(+), 4 deletions(-)

Index: net-2.6.24/include/linux/if_arp.h
===
--- net-2.6.24.orig/include/linux/if_arp.h  2007-10-02 12:10:51.0 
+0200
+++ net-2.6.24/include/linux/if_arp.h   2007-10-02 12:11:01.0 +0200
@@ -52,6 +52,7 @@
 #define ARPHRD_ROSE270
 #define ARPHRD_X25 271 /* CCITT X.25   */
 #define ARPHRD_HWX25   272 /* Boards with X.25 in firmware */
+#define ARPHRD_CAN 280 /* Controller Area Network  */
 #define ARPHRD_PPP 512
 #define ARPHRD_CISCO   513 /* Cisco HDLC   */
 #define ARPHRD_HDLCARPHRD_CISCO
Index: net-2.6.24/include/linux/if_ether.h
===
--- net-2.6.24.orig/include/linux/if_ether.h2007-10-02 12:10:51.0 
+0200
+++ net-2.6.24/include/linux/if_ether.h 2007-10-02 12:11:01.0 +0200
@@ -90,6 +90,7 @@
 #define ETH_P_WAN_PPP   0x0007  /* Dummy type for WAN PPP frames*/
 #define ETH_P_PPP_MP0x0008  /* Dummy type for PPP MP frames */
 #define ETH_P_LOCALTALK 0x0009 /* Localtalk pseudo type*/
+#define ETH_P_CAN  0x000C  /* Controller Area Network  */
 #define ETH_P_PPPTALK  0x0010  /* Dummy type for Atalk over PPP*/
 #define ETH_P_TR_802_2 0x0011  /* 802.2 frames */
 #define ETH_P_MOBITEX  0x0015  /* Mobitex ([EMAIL PROTECTED])  */
Index: net-2.6.24/include/linux/socket.h
===
--- net-2.6.24.orig/include/linux/socket.h  2007-10-02 12:10:51.0 
+0200
+++ net-2.6.24/include/linux/socket.h   2007-10-02 12:11:01.0 +0200
@@ -185,6 +185,7 @@
 #define AF_PPPOX   24  /* PPPoX sockets*/
 #define AF_WANPIPE 25  /* Wanpipe API Sockets */
 #define AF_LLC 26  /* Linux LLC*/
+#define AF_CAN 29  /* Controller Area Network  */
 #define AF_TIPC30  /* TIPC sockets */
 #define AF_BLUETOOTH   31  /* Bluetooth sockets*/
 #define AF_IUCV32  /* IUCV sockets */
@@ -220,6 +221,7 @@
 #define PF_PPPOX   AF_PPPOX
 #define PF_WANPIPE AF_WANPIPE
 #define PF_LLC AF_LLC
+#define PF_CAN AF_CAN
 #define PF_TIPCAF_TIPC
 #define PF_BLUETOOTH   AF_BLUETOOTH
 #define PF_IUCVAF_IUCV
Index: net-2.6.24/include/linux/tty.h
===
--- net-2.6.24.orig/include/linux/tty.h 2007-10-02 12:10:51.0 +0200
+++ net-2.6.24/include/linux/tty.h  2007-10-02 12:11:02.0 +0200
@@ -24,7 +24,7 @@
 #define NR_PTYSCONFIG_LEGACY_PTY_COUNT   /* Number of legacy ptys */
 #define NR_UNIX98_PTY_DEFAULT  4096  /* Default maximum for Unix98 ptys */
 #define NR_UNIX98_PTY_MAX  (1  MINORBITS) /* Absolute limit */
-#define NR_LDISCS  17
+#define NR_LDISCS  18
 
 /* line disciplines */
 #define N_TTY  0
@@ -45,6 +45,7 @@
 #define N_SYNC_PPP 14  /* synchronous PPP */
 #define N_HCI  15  /* Bluetooth HCI UART */
 #define N_GIGASET_M101 16  /* Siemens Gigaset M101 serial DECT adapter */
+#define N_SLCAN17  /* Serial / USB serial CAN Adaptors */
 
 /*
  * This character is the same as _POSIX_VDISABLE: it cannot be used as
Index: net-2.6.24/net/core/sock.c
===
--- net-2.6.24.orig/net/core/sock.c 2007-10-02 12:10:51.0 +0200
+++ net-2.6.24/net/core/sock.c  2007-10-02 12:11:02.0 +0200
@@ -154,7 +154,7 @@
   sk_lock-AF_ASH   , sk_lock-AF_ECONET   , sk_lock-AF_ATMSVC   ,
   sk_lock-21   , sk_lock-AF_SNA  , sk_lock-AF_IRDA ,
   sk_lock-AF_PPPOX , sk_lock-AF_WANPIPE  , sk_lock-AF_LLC  ,
-  sk_lock-27   , sk_lock-28  , sk_lock-29  ,
+  sk_lock-27   , sk_lock-28  , sk_lock-AF_CAN  ,
   sk_lock-AF_TIPC  , sk_lock-AF_BLUETOOTH, sk_lock-IUCV,
   sk_lock-AF_RXRPC , sk_lock-AF_MAX
 };
@@ -168,7 +168,7 @@
   slock-AF_ASH   , slock-AF_ECONET   , slock-AF_ATMSVC   ,
   slock-21   , slock-AF_SNA  , slock-AF_IRDA ,
   slock-AF_PPPOX , slock-AF_WANPIPE  , slock-AF_LLC  ,
-  slock-27   , slock-28  , slock-29

[PATCH 7/7] CAN: Add documentation

2007-10-05 Thread Urs Thuermann
This patch adds documentation for the PF_CAN protocol family.

Signed-off-by: Oliver Hartkopp [EMAIL PROTECTED]
Signed-off-by: Urs Thuermann [EMAIL PROTECTED]

---
 Documentation/networking/00-INDEX |2 
 Documentation/networking/can.txt  |  637 ++
 2 files changed, 639 insertions(+)

Index: net-2.6.24/Documentation/networking/can.txt
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ net-2.6.24/Documentation/networking/can.txt 2007-10-02 08:43:50.0 
+0200
@@ -0,0 +1,637 @@
+
+
+can.txt
+
+Readme file for the Controller Area Network Protocol Family (aka Socket CAN)
+
+This file contains
+
+  1 Overview / What is Socket CAN
+
+  2 Motivation / Why using the socket API
+
+  3 Socket CAN concept
+3.1 receive lists
+3.2 local loopback of sent frames
+3.3 network security issues (capabilities)
+3.4 network problem notifications
+
+  4 How to use Socket CAN
+4.1 RAW protocol sockets with can_filters (SOCK_RAW)
+  4.1.1 RAW socket option CAN_RAW_FILTER
+  4.1.2 RAW socket option CAN_RAW_ERR_FILTER
+  4.1.3 RAW socket option CAN_RAW_LOOPBACK
+  4.1.4 RAW socket option CAN_RAW_RECV_OWN_MSGS
+4.2 Broadcast Manager protocol sockets (SOCK_DGRAM)
+4.3 connected transport protocols (SOCK_SEQPACKET)
+4.4 unconnected transport protocols (SOCK_DGRAM)
+
+  5 Socket CAN core module
+5.1 can.ko module params
+5.2 procfs content
+5.3 writing own CAN protocol modules
+
+  6 CAN network drivers
+6.1 general settings
+6.2 local loopback of sent frames
+6.3 CAN controller hardware filters
+6.4 currently supported CAN hardware
+6.5 todo
+
+  7 Credits
+
+
+
+1. Overview / What is Socket CAN
+
+
+The socketcan package is an implementation of CAN protocols
+(Controller Area Network) for Linux.  CAN is a networking technology
+which has widespread use in automation, embedded devices, and
+automotive fields.  While there have been other CAN implementations
+for Linux based on character devices, Socket CAN uses the Berkeley
+socket API, the Linux network stack and implements the CAN device
+drivers as network interfaces.  The CAN socket API has been designed
+as similar as possible to the TCP/IP protocols to allow programmers,
+familiar with network programming, to easily learn how to use CAN
+sockets.
+
+2. Motivation / Why using the socket API
+
+
+There have been CAN implementations for Linux before Socket CAN so the
+question arises, why we have started another project.  Most existing
+implementations come as a device driver for some CAN hardware, they
+are based on character devices and provide comparatively little
+functionality.  Usually, there is only a hardware-specific device
+driver which provides a character device interface to send and
+receive raw CAN frames, directly to/from the controller hardware.
+Queueing of frames and higher-level transport protocols like ISO-TP
+have to be implemented in user space applications.  Also, most
+character-device implementations support only one single process to
+open the device at a time, similar to a serial interface.  Exchanging
+the CAN controller requires employment of another device driver and
+often the need for adaption of large parts of the application to the
+new driver's API.
+
+Socket CAN was designed to overcome all of these limitations.  A new
+protocol family has been implemented which provides a socket interface
+to user space applications and which builds upon the Linux network
+layer, so to use all of the provided queueing functionality.  A device
+driver for CAN controller hardware registers itself with the Linux
+network layer as a network device, so that CAN frames from the
+controller can be passed up to the network layer and on to the CAN
+protocol family module and also vice-versa.  Also, the protocol family
+module provides an API for transport protocol modules to register, so
+that any number of transport protocols can be loaded or unloaded
+dynamically.  In fact, the can core module alone does not provide any
+protocol and cannot be used without loading at least one additional
+protocol module.  Multiple sockets can be opened at the same time,
+on different or the same protocol module and they can listen/send
+frames on different or the same CAN IDs.  Several sockets listening on
+the same interface for frames with the same CAN ID are all passed the
+same received matching CAN frames.  An application wishing to
+communicate using a specific transport protocol, e.g. ISO-TP, just
+selects that protocol when opening the socket, and then can read and
+write application data byte streams, without having to deal with
+CAN-IDs, frames, etc

Re: [PATCH 2/7] CAN: Add PF_CAN core module

2007-10-04 Thread Urs Thuermann
Arnaldo Carvalho de Melo [EMAIL PROTECTED] writes:

  +struct sockaddr_can {
  +   sa_family_t can_family;
  +   int can_ifindex;
  +   union {
  +   struct { canid_t rx_id, tx_id; } tp16;
  +   struct { canid_t rx_id, tx_id; } tp20;
  +   struct { canid_t rx_id, tx_id; } mcnet;
  +   struct { canid_t rx_id, tx_id; } isotp;
  +   } can_addr;
 
 Again being curious, what is the value of this union of all its members
 have the same definition? Backward source code compatibility?

As Oliver already wrote, different CAN transport protocols may use
different sockaddr structures.  Therefore, we have made can_addr a
union.  The four we have defined already, all look the same, but
other, future protocols may define a different structure.

  +struct can_proto {
  +   int  type;
  +   int  protocol;
  +   int  capability;
  +   struct proto_ops *ops;
  +   struct proto *prot;
  +};
  +
  +/* function prototypes for the CAN networklayer core (af_can.c) */
  +
  +extern int  can_proto_register(struct can_proto *cp);
  +extern void can_proto_unregister(struct can_proto *cp);
 
 We have proto registering infrastructure for bluetooth, inet and now
 CAN, have you looked at:
 
 struct inet_protosw;
 proto_{register,unregister}, etc?

Yes, I know inet_protosw and inet_{,un}register_protosw().  But we
can't use inet_register_protosw().

And can_proto_register() does use proto_register().  What exactly do
you want to suggest?

urs
-
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 3/7] CAN: Add raw protocol

2007-10-04 Thread Urs Thuermann
Arnaldo Carvalho de Melo [EMAIL PROTECTED] writes:

  +static inline struct raw_sock *raw_sk(const struct sock *sk)
  +{
  +   return (struct raw_sock *)sk;
  +}
 
 
 What if I want to do some kernel module that uses INET raw sockets
 (include/net/icmp.h) and CAN raw sockets? Namespace collision, could you
 please use can_raw_ for this namespace?

raw_sk is static so you can't use in another file where you include
include/net/icmp.h.  There is no collision.  Also, since it's inline
you won't even see it in a symbol table.

Hm, it's more than 10 years that I've tested ctags(1) and etags(1)
with several identical static names in different files and I don't
remember my results.  Do these tools have a problem with multiple
defs?  I think they shouldn't since C is explicitly designed for that.

  +static unsigned int raw_poll(struct file *file, struct socket *sock,
  +poll_table *wait)
  +{
  +   unsigned int mask = 0;
  +
  +   DBG(socket %p\n, sock);
  +
  +   mask = datagram_poll(file, sock, wait);
  +   return mask;
 
 What is the value of 'mask' here? Leftover from debugging?

Ah, yes.  We should remove it.

  +static int raw_setsockopt(struct socket *sock, int level, int optname,
  + char __user *optval, int optlen)
  +{

  +   lock_sock(sk);
  +
  +   if (ro-bound  ro-ifindex)
  +   dev = dev_get_by_index(init_net, ro-ifindex);
 
 dev_get_by_index can fail, are you sure that raw_enable_filters can cope
 with this possibility?

When ro-ifindex != 0, the call to dev_get_by_index() shouldn't fail.
We also use lock_sock() here and in NETDEV_UNREGISTER, so there should
be no problem.


urs
-
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 5/7] CAN: Add virtual CAN netdevice driver

2007-10-04 Thread Urs Thuermann
Arnaldo Carvalho de Melo [EMAIL PROTECTED] writes:

  +#ifdef CONFIG_CAN_DEBUG_DEVICES
  +static int debug;
  +module_param(debug, int, S_IRUGO);
  +#endif
 
 Can debug be a boolean? Like its counterpart on DCCP:

debug used to a bit mask, like it still is in core.h.  You can see
this in the test

debug  1 ? ... : ...

below.  Only the test for bit 0 is left, so we could change it to bool.

 net/dccp/proto.c:
 
 module_param(dccp_debug, bool, 0444);
 
 Where we also use a namespace prefix, for those of us who use ctags or
 cscope.

I think ctags should be able to handle multiple identical static
symbols.  Isn't it?  I find it somewhat clumsy to write

modprobe vcan vcan_debug=1

I think it would be nice to change the module_param() macro so that
you can name the module argument and the corresponding variable
independently, like

module_param(can_debug, debug, bool, 0444);

OK, forget that last paragraph.  I've looked at the definition of
module_param() and have seen that we have module_param_named().  I
think we should use that.

  +
  +/* To be moved to linux/can/dev.h */
 
 Is this comment still valid? If so can this move happen now? If not I
 think it would be better to stick a FIXME:  just before it, no?

OK.

  +static int echo; /* echo testing. Default: 0 (Off) */
  +module_param(echo, int, S_IRUGO);
  +MODULE_PARM_DESC(echo, Echo sent frames (for testing). Default: 0 (Off));
 
 echo also seems to be a boolean

ACK.

  +static int vcan_open(struct net_device *dev)
  +{
  +   DBG(%s: interface up\n, dev-name);
  +
  +   netif_start_queue(dev);
  +   return 0;
  +}
  +
  +static int vcan_stop(struct net_device *dev)
  +{
  +   DBG(%s: interface down\n, dev-name);
  +
  +   netif_stop_queue(dev);
  +   return 0;
  +}
 
 Thinking out loud: I guess these days we can try to reduce the clutter
 on the source code for things like hey, I entered function foo using
 simple systemtap scripts, that could even be shipped with the kernel
 sources. Not something pressing right now, just a suggestion.

I've never heard of systemtap before.  I've ust looked at its overview
web page which sounds promising.  I think I'll check it out when time
permits...


urs
-
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 1/7] CAN: Allocate protocol numbers for PF_CAN

2007-10-02 Thread Urs Thuermann
This patch adds a protocol/address family number, ARP hardware type,
ethernet packet type, and a line discipline number for the SocketCAN
implementation.

Signed-off-by: Oliver Hartkopp [EMAIL PROTECTED]
Signed-off-by: Urs Thuermann [EMAIL PROTECTED]

---
 include/linux/if.h   |4 +++-
 include/linux/if_arp.h   |1 +
 include/linux/if_ether.h |1 +
 include/linux/socket.h   |2 ++
 include/linux/tty.h  |3 ++-
 net/core/sock.c  |4 ++--
 6 files changed, 11 insertions(+), 4 deletions(-)

Index: net-2.6.24/include/linux/if_arp.h
===
--- net-2.6.24.orig/include/linux/if_arp.h  2007-10-02 12:10:51.0 
+0200
+++ net-2.6.24/include/linux/if_arp.h   2007-10-02 12:11:01.0 +0200
@@ -52,6 +52,7 @@
 #define ARPHRD_ROSE270
 #define ARPHRD_X25 271 /* CCITT X.25   */
 #define ARPHRD_HWX25   272 /* Boards with X.25 in firmware */
+#define ARPHRD_CAN 280 /* Controller Area Network  */
 #define ARPHRD_PPP 512
 #define ARPHRD_CISCO   513 /* Cisco HDLC   */
 #define ARPHRD_HDLCARPHRD_CISCO
Index: net-2.6.24/include/linux/if_ether.h
===
--- net-2.6.24.orig/include/linux/if_ether.h2007-10-02 12:10:51.0 
+0200
+++ net-2.6.24/include/linux/if_ether.h 2007-10-02 12:11:01.0 +0200
@@ -90,6 +90,7 @@
 #define ETH_P_WAN_PPP   0x0007  /* Dummy type for WAN PPP frames*/
 #define ETH_P_PPP_MP0x0008  /* Dummy type for PPP MP frames */
 #define ETH_P_LOCALTALK 0x0009 /* Localtalk pseudo type*/
+#define ETH_P_CAN  0x000C  /* Controller Area Network  */
 #define ETH_P_PPPTALK  0x0010  /* Dummy type for Atalk over PPP*/
 #define ETH_P_TR_802_2 0x0011  /* 802.2 frames */
 #define ETH_P_MOBITEX  0x0015  /* Mobitex ([EMAIL PROTECTED])  */
Index: net-2.6.24/include/linux/socket.h
===
--- net-2.6.24.orig/include/linux/socket.h  2007-10-02 12:10:51.0 
+0200
+++ net-2.6.24/include/linux/socket.h   2007-10-02 12:11:01.0 +0200
@@ -185,6 +185,7 @@
 #define AF_PPPOX   24  /* PPPoX sockets*/
 #define AF_WANPIPE 25  /* Wanpipe API Sockets */
 #define AF_LLC 26  /* Linux LLC*/
+#define AF_CAN 29  /* Controller Area Network  */
 #define AF_TIPC30  /* TIPC sockets */
 #define AF_BLUETOOTH   31  /* Bluetooth sockets*/
 #define AF_IUCV32  /* IUCV sockets */
@@ -220,6 +221,7 @@
 #define PF_PPPOX   AF_PPPOX
 #define PF_WANPIPE AF_WANPIPE
 #define PF_LLC AF_LLC
+#define PF_CAN AF_CAN
 #define PF_TIPCAF_TIPC
 #define PF_BLUETOOTH   AF_BLUETOOTH
 #define PF_IUCVAF_IUCV
Index: net-2.6.24/include/linux/tty.h
===
--- net-2.6.24.orig/include/linux/tty.h 2007-10-02 12:10:51.0 +0200
+++ net-2.6.24/include/linux/tty.h  2007-10-02 12:11:02.0 +0200
@@ -24,7 +24,7 @@
 #define NR_PTYSCONFIG_LEGACY_PTY_COUNT   /* Number of legacy ptys */
 #define NR_UNIX98_PTY_DEFAULT  4096  /* Default maximum for Unix98 ptys */
 #define NR_UNIX98_PTY_MAX  (1  MINORBITS) /* Absolute limit */
-#define NR_LDISCS  17
+#define NR_LDISCS  18
 
 /* line disciplines */
 #define N_TTY  0
@@ -45,6 +45,7 @@
 #define N_SYNC_PPP 14  /* synchronous PPP */
 #define N_HCI  15  /* Bluetooth HCI UART */
 #define N_GIGASET_M101 16  /* Siemens Gigaset M101 serial DECT adapter */
+#define N_SLCAN17  /* Serial / USB serial CAN Adaptors */
 
 /*
  * This character is the same as _POSIX_VDISABLE: it cannot be used as
Index: net-2.6.24/net/core/sock.c
===
--- net-2.6.24.orig/net/core/sock.c 2007-10-02 12:10:51.0 +0200
+++ net-2.6.24/net/core/sock.c  2007-10-02 12:11:02.0 +0200
@@ -154,7 +154,7 @@
   sk_lock-AF_ASH   , sk_lock-AF_ECONET   , sk_lock-AF_ATMSVC   ,
   sk_lock-21   , sk_lock-AF_SNA  , sk_lock-AF_IRDA ,
   sk_lock-AF_PPPOX , sk_lock-AF_WANPIPE  , sk_lock-AF_LLC  ,
-  sk_lock-27   , sk_lock-28  , sk_lock-29  ,
+  sk_lock-27   , sk_lock-28  , sk_lock-AF_CAN  ,
   sk_lock-AF_TIPC  , sk_lock-AF_BLUETOOTH, sk_lock-IUCV,
   sk_lock-AF_RXRPC , sk_lock-AF_MAX
 };
@@ -168,7 +168,7 @@
   slock-AF_ASH   , slock-AF_ECONET   , slock-AF_ATMSVC   ,
   slock-21   , slock-AF_SNA  , slock-AF_IRDA ,
   slock-AF_PPPOX , slock-AF_WANPIPE  , slock-AF_LLC  ,
-  slock-27   , slock-28  , slock-29

[PATCH 3/7] CAN: Add raw protocol

2007-10-02 Thread Urs Thuermann
This patch adds the CAN raw protocol.

Signed-off-by: Oliver Hartkopp [EMAIL PROTECTED]
Signed-off-by: Urs Thuermann [EMAIL PROTECTED]

---
 include/linux/can/raw.h |   31 +
 net/can/Kconfig |   11 
 net/can/Makefile|3 
 net/can/raw.c   |  821 
 4 files changed, 866 insertions(+)

Index: net-2.6.24/include/linux/can/raw.h
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ net-2.6.24/include/linux/can/raw.h  2007-10-02 08:33:39.0 +0200
@@ -0,0 +1,31 @@
+/*
+ * linux/can/raw.h
+ *
+ * Definitions for raw CAN sockets
+ *
+ * Authors: Oliver Hartkopp [EMAIL PROTECTED]
+ *  Urs Thuermann   [EMAIL PROTECTED]
+ * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
+ * All rights reserved.
+ *
+ * Send feedback to [EMAIL PROTECTED]
+ *
+ */
+
+#ifndef CAN_RAW_H
+#define CAN_RAW_H
+
+#include linux/can.h
+
+#define SOL_CAN_RAW (SOL_CAN_BASE + CAN_RAW)
+
+/* for socket options affecting the socket (not the global system) */
+
+enum {
+   CAN_RAW_FILTER = 1, /* set 0 .. n can_filter(s)  */
+   CAN_RAW_ERR_FILTER, /* set filter for error frames   */
+   CAN_RAW_LOOPBACK,   /* local loopback (default:on)   */
+   CAN_RAW_RECV_OWN_MSGS   /* receive my own msgs (default:off) */
+};
+
+#endif
Index: net-2.6.24/net/can/Kconfig
===
--- net-2.6.24.orig/net/can/Kconfig 2007-10-02 06:18:29.0 +0200
+++ net-2.6.24/net/can/Kconfig  2007-10-02 08:35:31.0 +0200
@@ -16,6 +16,17 @@
  If you want CAN support, you should say Y here and also to the
  specific driver for your controller(s) below.
 
+config CAN_RAW
+   tristate Raw CAN Protocol (raw access with CAN-ID filtering)
+   depends on CAN
+   default N
+   ---help---
+ The Raw CAN protocol option offers access to the CAN bus via
+ the BSD socket API. You probably want to use the raw socket in
+ most cases where no higher level protocol is being used. The raw
+ socket has several filter options e.g. ID-Masking / Errorframes.
+ To receive/send raw CAN messages, use AF_CAN with protocol CAN_RAW.
+
 config CAN_DEBUG_CORE
bool CAN Core debugging messages
depends on CAN
Index: net-2.6.24/net/can/Makefile
===
--- net-2.6.24.orig/net/can/Makefile2007-10-02 06:18:29.0 +0200
+++ net-2.6.24/net/can/Makefile 2007-10-02 08:35:31.0 +0200
@@ -4,3 +4,6 @@
 
 obj-$(CONFIG_CAN)  += can.o
 can-objs   := af_can.o proc.o
+
+obj-$(CONFIG_CAN_RAW)  += can-raw.o
+can-raw-objs   := raw.o
Index: net-2.6.24/net/can/raw.c
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ net-2.6.24/net/can/raw.c2007-10-02 08:35:48.0 +0200
@@ -0,0 +1,821 @@
+/*
+ * raw.c - Raw sockets for protocol family CAN
+ *
+ * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
+ * All rights reserved.
+ *
+ * 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. Neither the name of Volkswagen nor the names of its contributors
+ *may be used to endorse or promote products derived from this software
+ *without specific prior written permission.
+ *
+ * Alternatively, provided that this notice is retained in full, this
+ * software may be distributed under the terms of the GNU General
+ * Public License (GPL) version 2, in which case the provisions of the
+ * GPL apply INSTEAD OF those given above.
+ *
+ * The provided data structures and external interfaces from this code
+ * are not restricted to be used by modules with a GPL compatible license.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT
+ * OWNER 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

[PATCH 0/7] CAN: Add new PF_CAN protocol family, try #9

2007-10-02 Thread Urs Thuermann
Hello Dave, hello Patrick,

this is the nineth post of the patch series that adds the PF_CAN
protocol family for the Controller Area Network.

Since our last post we have changed the following:

* Changes suggested by Arnaldo Carvalho de Melo:
  - Use gfp_any() instead of checking in_interrupt().
  - Don't kfree() the sk_protinfo field.
* Fixed licence text as pointed out by Yoshifuji Hideaki and Patrick McHardy.
* Added IFF_ECHO to include/linux/if.h and use that instead of IFF_LOOPBACK,
  as suggested by Eric W. Biederman.  IFF_LOOPBACK is only for the normal
  loopback interface.

The changes in try #8 were:

* Some changes in debug code, following suggestions from Joe Perches:
  - Remove dynamically allocated buffer for debug output.
  - Use kernel functions for hexdumps.
  - Don't interpret printf-style %-sequences in can_debug_cframe().
  - Specify the fixed argument fmt to DBG() macro and use
GCC ## mechanism to remove , when args is empty.
* Removed CAN_RAW_USER and CAN_BCM_USER Kconfig options following a
  suggestion from Patrick.
* Prevent overflow in statistics calculation.
* Minor optimization.

The changes in try #7 were:

* Changes suggested by Patrick:
  - protect proto_tab[] by a lock.
  - add _rcu to some hlist traversals.
  - use printk_ratelimit() for module autoload failures.
  - make can_proto_unregister() and can_rx_unregister() return void.
  - use return value of can_proto_register() and can_rx_register()
(this also removed a flaw in behavior of raw_bind() and raw_setsockopt()
 in case of failure to can_rx_register() their filters).
  - call kzalloc() with GFP_KERNEL in case NETDEV_REGISTER.
  - use round_jiffies() to calculate expiration times.
  - make some variables static and/or __read_mostly.
  - in can_create() check for net namespace before auto loading modules.
  - add build time check for struct sizes.
  - use skb_share_chack() in vcan.
  - fixed some comments.
* Typos in documentation as pointed out by Randy Dunlap and Bill Fink.

The changes in try #6 were:

* Update code to work with namespaces in net-2.6.24.
* Remove SET_MODULE_OWNER() from vcan.

The changes in try #5 were:

* Remove slab destructor from calls to kmem_cache_alloc().
* Add comments about types defined in can.h.
* Update comment on vcan loopback module parameter.
* Fix typo in documentation.

The changes in try #4 were:

* Change vcan network driver to use the new RTNL API, as suggested by
  Patrick.
* Revert our change to use skb-iif instead of skb-cb.  After
  discussion with Patrick and Jamal it turned out, our first
  implementation was correct.
* Use skb_tail_pointer() instead of skb-tail directly.
* Coding style changes to satisfy linux/scripts/checkpatch.pl.
* Minor changes for 64-bit-cleanliness.
* Minor cleanup of #include's

The changes in try #3 were:

* Use sbk-sk and skb-pkt_type instead of skb-cb to pass loopback
  flags and originating socket down to the driver and back to the
  receiving socket.  Thanks to Patrick McHardy for pointing out our
  wrong use of sbk-cb.
* Use skb-iif instead of skb-cb to pass receiving interface from
  raw_rcv() and bcm_rcv() up to raw_recvmsg() and bcm_recvmsg().
* Set skb-protocol when sending CAN frames to netdevices.
* Removed struct raw_opt and struct bcm_opt and integrated these
  directly into struct raw_sock and bcm_sock resp., like most other
  proto implementations do.
* We have found and fixed race conditions between raw_bind(),
  raw_{set,get}sockopt() and raw_notifier().  This resulted in
  - complete removal of our own notifier list infrastructure in
af_can.c.  raw.c and bcm.c now use normal netdevice notifiers.
  - removal of ro-lock spinlock.  We use lock_sock(sk) now.
  - changed deletion of dev_rcv_lists, which are now marked for
deletion in the netdevice notifier in af_can.c and are actually
deleted when all entries have been deleted using can_rx_unregister().
* Follow changes in 2.6.22 (e.g. ktime_t timestamps in skb).
* Removed obsolete code from vcan.c, as pointed out by Stephen Hemminger.

The changes in try #2 were:

* reduced RCU callback overhead when deleting receiver lists (thx to
  feedback from Paul E. McKenney).
* eliminated some code duplication in net/can/proc.c.
* renamed slock-29 and sk_lock-29 to slock-AF_CAN and sk_lock-AF_CAN in
  net/core/sock.c
* added entry for can.txt in Documentation/networking/00-INDEX
* added error frame definitions in include/linux/can/error.h, which are to
  be used by CAN network drivers.


This patch series applies against net-2.6.24 and is derived from Subversion
revision r511 of http://svn.berlios.de/svnroot/repos/socketcan.
It can be found in the directory
http://svn.berlios.de/svnroot/repos/socketcan/trunk/patch-series/version.

Thanks very much for your work!

Best regards,

Urs Thuermann
Oliver Hartkopp
--
-
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org

[PATCH 7/7] CAN: Add documentation

2007-10-02 Thread Urs Thuermann
This patch adds documentation for the PF_CAN protocol family.

Signed-off-by: Oliver Hartkopp [EMAIL PROTECTED]
Signed-off-by: Urs Thuermann [EMAIL PROTECTED]

---
 Documentation/networking/00-INDEX |2 
 Documentation/networking/can.txt  |  637 ++
 2 files changed, 639 insertions(+)

Index: net-2.6.24/Documentation/networking/can.txt
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ net-2.6.24/Documentation/networking/can.txt 2007-10-02 08:43:50.0 
+0200
@@ -0,0 +1,637 @@
+
+
+can.txt
+
+Readme file for the Controller Area Network Protocol Family (aka Socket CAN)
+
+This file contains
+
+  1 Overview / What is Socket CAN
+
+  2 Motivation / Why using the socket API
+
+  3 Socket CAN concept
+3.1 receive lists
+3.2 local loopback of sent frames
+3.3 network security issues (capabilities)
+3.4 network problem notifications
+
+  4 How to use Socket CAN
+4.1 RAW protocol sockets with can_filters (SOCK_RAW)
+  4.1.1 RAW socket option CAN_RAW_FILTER
+  4.1.2 RAW socket option CAN_RAW_ERR_FILTER
+  4.1.3 RAW socket option CAN_RAW_LOOPBACK
+  4.1.4 RAW socket option CAN_RAW_RECV_OWN_MSGS
+4.2 Broadcast Manager protocol sockets (SOCK_DGRAM)
+4.3 connected transport protocols (SOCK_SEQPACKET)
+4.4 unconnected transport protocols (SOCK_DGRAM)
+
+  5 Socket CAN core module
+5.1 can.ko module params
+5.2 procfs content
+5.3 writing own CAN protocol modules
+
+  6 CAN network drivers
+6.1 general settings
+6.2 local loopback of sent frames
+6.3 CAN controller hardware filters
+6.4 currently supported CAN hardware
+6.5 todo
+
+  7 Credits
+
+
+
+1. Overview / What is Socket CAN
+
+
+The socketcan package is an implementation of CAN protocols
+(Controller Area Network) for Linux.  CAN is a networking technology
+which has widespread use in automation, embedded devices, and
+automotive fields.  While there have been other CAN implementations
+for Linux based on character devices, Socket CAN uses the Berkeley
+socket API, the Linux network stack and implements the CAN device
+drivers as network interfaces.  The CAN socket API has been designed
+as similar as possible to the TCP/IP protocols to allow programmers,
+familiar with network programming, to easily learn how to use CAN
+sockets.
+
+2. Motivation / Why using the socket API
+
+
+There have been CAN implementations for Linux before Socket CAN so the
+question arises, why we have started another project.  Most existing
+implementations come as a device driver for some CAN hardware, they
+are based on character devices and provide comparatively little
+functionality.  Usually, there is only a hardware-specific device
+driver which provides a character device interface to send and
+receive raw CAN frames, directly to/from the controller hardware.
+Queueing of frames and higher-level transport protocols like ISO-TP
+have to be implemented in user space applications.  Also, most
+character-device implementations support only one single process to
+open the device at a time, similar to a serial interface.  Exchanging
+the CAN controller requires employment of another device driver and
+often the need for adaption of large parts of the application to the
+new driver's API.
+
+Socket CAN was designed to overcome all of these limitations.  A new
+protocol family has been implemented which provides a socket interface
+to user space applications and which builds upon the Linux network
+layer, so to use all of the provided queueing functionality.  A device
+driver for CAN controller hardware registers itself with the Linux
+network layer as a network device, so that CAN frames from the
+controller can be passed up to the network layer and on to the CAN
+protocol family module and also vice-versa.  Also, the protocol family
+module provides an API for transport protocol modules to register, so
+that any number of transport protocols can be loaded or unloaded
+dynamically.  In fact, the can core module alone does not provide any
+protocol and cannot be used without loading at least one additional
+protocol module.  Multiple sockets can be opened at the same time,
+on different or the same protocol module and they can listen/send
+frames on different or the same CAN IDs.  Several sockets listening on
+the same interface for frames with the same CAN ID are all passed the
+same received matching CAN frames.  An application wishing to
+communicate using a specific transport protocol, e.g. ISO-TP, just
+selects that protocol when opening the socket, and then can read and
+write application data byte streams, without having to deal with
+CAN-IDs, frames, etc

[PATCH 6/7] CAN: Add maintainer entries

2007-10-02 Thread Urs Thuermann
This patch adds entries in the CREDITS and MAINTAINERS file for CAN.

Signed-off-by: Oliver Hartkopp [EMAIL PROTECTED]
Signed-off-by: Urs Thuermann [EMAIL PROTECTED]

---
 CREDITS |   16 
 MAINTAINERS |9 +
 2 files changed, 25 insertions(+)

Index: net-2.6.24/CREDITS
===
--- net-2.6.24.orig/CREDITS 2007-09-20 06:37:28.0 +0200
+++ net-2.6.24/CREDITS  2007-10-02 12:03:43.0 +0200
@@ -1347,6 +1347,14 @@
 S: 5623 HZ Eindhoven
 S: The Netherlands
 
+N: Oliver Hartkopp
+E: [EMAIL PROTECTED]
+W: http://www.volkswagen.de
+D: Controller Area Network (network layer core)
+S: Brieffach 1776
+S: 38436 Wolfsburg
+S: Germany
+
 N: Andrew Haylett
 E: [EMAIL PROTECTED]
 D: Selection mechanism
@@ -3300,6 +3308,14 @@
 S: F-35042 Rennes Cedex
 S: France
 
+N: Urs Thuermann
+E: [EMAIL PROTECTED]
+W: http://www.volkswagen.de
+D: Controller Area Network (network layer core)
+S: Brieffach 1776
+S: 38436 Wolfsburg
+S: Germany
+
 N: Jon Tombs
 E: [EMAIL PROTECTED]
 W: http://www.esi.us.es/~jon
Index: net-2.6.24/MAINTAINERS
===
--- net-2.6.24.orig/MAINTAINERS 2007-09-28 18:01:52.0 +0200
+++ net-2.6.24/MAINTAINERS  2007-10-02 12:03:43.0 +0200
@@ -991,6 +991,15 @@
 L: [EMAIL PROTECTED]
 S: Maintained
 
+CAN NETWORK LAYER
+P: Urs Thuermann
+M: [EMAIL PROTECTED]
+P: Oliver Hartkopp
+M: [EMAIL PROTECTED]
+L: [EMAIL PROTECTED]
+W: http://developer.berlios.de/projects/socketcan/
+S: Maintained
+
 CALGARY x86-64 IOMMU
 P: Muli Ben-Yehuda
 M: [EMAIL PROTECTED]

--
-
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 5/7] CAN: Add virtual CAN netdevice driver

2007-10-02 Thread Urs Thuermann
This patch adds the virtual CAN bus (vcan) network driver.
The vcan device is just a loopback device for CAN frames, no
real CAN hardware is involved.

Signed-off-by: Oliver Hartkopp [EMAIL PROTECTED]
Signed-off-by: Urs Thuermann [EMAIL PROTECTED]

---
 drivers/net/Makefile |1 
 drivers/net/can/Kconfig  |   25 +
 drivers/net/can/Makefile |5 +
 drivers/net/can/vcan.c   |  207 +++
 net/can/Kconfig  |3 
 5 files changed, 241 insertions(+)

Index: net-2.6.24/drivers/net/Makefile
===
--- net-2.6.24.orig/drivers/net/Makefile2007-09-20 23:46:01.0 
+0200
+++ net-2.6.24/drivers/net/Makefile 2007-10-02 12:03:30.0 +0200
@@ -12,6 +12,7 @@
 obj-$(CONFIG_CHELSIO_T1) += chelsio/
 obj-$(CONFIG_CHELSIO_T3) += cxgb3/
 obj-$(CONFIG_EHEA) += ehea/
+obj-$(CONFIG_CAN) += can/
 obj-$(CONFIG_BONDING) += bonding/
 obj-$(CONFIG_ATL1) += atl1/
 obj-$(CONFIG_GIANFAR) += gianfar_driver.o
Index: net-2.6.24/drivers/net/can/Kconfig
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ net-2.6.24/drivers/net/can/Kconfig  2007-10-02 12:03:30.0 +0200
@@ -0,0 +1,25 @@
+menu CAN Device Drivers
+   depends on CAN
+
+config CAN_VCAN
+   tristate Virtual Local CAN Interface (vcan)
+   depends on CAN
+   default N
+   ---help---
+ Similar to the network loopback devices, vcan offers a
+ virtual local CAN interface.
+
+ This driver can also be built as a module.  If so, the module
+ will be called vcan.
+
+config CAN_DEBUG_DEVICES
+   bool CAN devices debugging messages
+   depends on CAN
+   default N
+   ---help---
+ Say Y here if you want the CAN device drivers to produce a bunch of
+ debug messages to the system log.  Select this if you are having
+ a problem with CAN support and want to see more of what is going
+ on.
+
+endmenu
Index: net-2.6.24/drivers/net/can/Makefile
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ net-2.6.24/drivers/net/can/Makefile 2007-10-02 12:03:30.0 +0200
@@ -0,0 +1,5 @@
+#
+#  Makefile for the Linux Controller Area Network drivers.
+#
+
+obj-$(CONFIG_CAN_VCAN) += vcan.o
Index: net-2.6.24/drivers/net/can/vcan.c
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ net-2.6.24/drivers/net/can/vcan.c   2007-10-02 12:03:30.0 +0200
@@ -0,0 +1,207 @@
+/*
+ * vcan.c - Virtual CAN interface
+ *
+ * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
+ * All rights reserved.
+ *
+ * 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. Neither the name of Volkswagen nor the names of its contributors
+ *may be used to endorse or promote products derived from this software
+ *without specific prior written permission.
+ *
+ * Alternatively, provided that this notice is retained in full, this
+ * software may be distributed under the terms of the GNU General
+ * Public License (GPL) version 2, in which case the provisions of the
+ * GPL apply INSTEAD OF those given above.
+ *
+ * The provided data structures and external interfaces from this code
+ * are not restricted to be used by modules with a GPL compatible license.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT
+ * OWNER 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.
+ *
+ * Send feedback to [EMAIL PROTECTED]
+ *
+ */
+
+#include linux/module.h
+#include linux/init.h
+#include linux/netdevice.h
+#include linux/if_arp.h
+#include linux/if_ether.h
+#include linux/can.h
+#include net/rtnetlink.h
+
+static

[PATCH 4/7] CAN: Add broadcast manager (bcm) protocol

2007-10-02 Thread Urs Thuermann
This patch adds the CAN broadcast manager (bcm) protocol.

Signed-off-by: Oliver Hartkopp [EMAIL PROTECTED]
Signed-off-by: Urs Thuermann [EMAIL PROTECTED]

---
 include/linux/can/bcm.h |   65 +
 net/can/Kconfig |   13 
 net/can/Makefile|3 
 net/can/bcm.c   | 1774 
 4 files changed, 1855 insertions(+)

Index: net-2.6.24/include/linux/can/bcm.h
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ net-2.6.24/include/linux/can/bcm.h  2007-10-02 08:33:40.0 +0200
@@ -0,0 +1,65 @@
+/*
+ * linux/can/bcm.h
+ *
+ * Definitions for CAN Broadcast Manager (BCM)
+ *
+ * Author: Oliver Hartkopp [EMAIL PROTECTED]
+ * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
+ * All rights reserved.
+ *
+ * Send feedback to [EMAIL PROTECTED]
+ *
+ */
+
+#ifndef CAN_BCM_H
+#define CAN_BCM_H
+
+/**
+ * struct bcm_msg_head - head of messages to/from the broadcast manager
+ * @opcode:opcode, see enum below.
+ * @flags: special flags, see below.
+ * @count: number of frames to send before changing interval.
+ * @ival1: interval for the first @count frames.
+ * @ival2: interval for the following frames.
+ * @can_id:CAN ID of frames to be sent or received.
+ * @nframes:   number of frames appended to the message head.
+ * @frames:array of CAN frames.
+ */
+struct bcm_msg_head {
+   int opcode;
+   int flags;
+   int count;
+   struct timeval ival1, ival2;
+   canid_t can_id;
+   int nframes;
+   struct can_frame frames[0];
+};
+
+enum {
+   TX_SETUP = 1,   /* create (cyclic) transmission task */
+   TX_DELETE,  /* remove (cyclic) transmission task */
+   TX_READ,/* read properties of (cyclic) transmission task */
+   TX_SEND,/* send one CAN frame */
+   RX_SETUP,   /* create RX content filter subscription */
+   RX_DELETE,  /* remove RX content filter subscription */
+   RX_READ,/* read properties of RX content filter subscription */
+   TX_STATUS,  /* reply to TX_READ request */
+   TX_EXPIRED, /* notification on performed transmissions (count=0) */
+   RX_STATUS,  /* reply to RX_READ request */
+   RX_TIMEOUT, /* cyclic message is absent */
+   RX_CHANGED  /* updated CAN frame (detected content change) */
+};
+
+#define SETTIMER0x0001
+#define STARTTIMER  0x0002
+#define TX_COUNTEVT 0x0004
+#define TX_ANNOUNCE 0x0008
+#define TX_CP_CAN_ID0x0010
+#define RX_FILTER_ID0x0020
+#define RX_CHECK_DLC0x0040
+#define RX_NO_AUTOTIMER 0x0080
+#define RX_ANNOUNCE_RESUME  0x0100
+#define TX_RESET_MULTI_IDX  0x0200
+#define RX_RTR_FRAME0x0400
+
+#endif /* CAN_BCM_H */
Index: net-2.6.24/net/can/Kconfig
===
--- net-2.6.24.orig/net/can/Kconfig 2007-10-02 08:33:39.0 +0200
+++ net-2.6.24/net/can/Kconfig  2007-10-02 08:33:40.0 +0200
@@ -27,6 +27,19 @@
  socket has several filter options e.g. ID-Masking / Errorframes.
  To receive/send raw CAN messages, use AF_CAN with protocol CAN_RAW.
 
+config CAN_BCM
+   tristate Broadcast Manager CAN Protocol (with content filtering)
+   depends on CAN
+   default N
+   ---help---
+ The Broadcast Manager offers content filtering, timeout monitoring,
+ sending of RTR-frames and cyclic CAN messages without permanent user
+ interaction. The BCM can be 'programmed' via the BSD socket API and
+ informs you on demand e.g. only on content updates / timeouts.
+ You probably want to use the bcm socket in most cases where cyclic
+ CAN messages are used on the bus (e.g. in automotive environments).
+ To use the Broadcast Manager, use AF_CAN with protocol CAN_BCM.
+
 config CAN_DEBUG_CORE
bool CAN Core debugging messages
depends on CAN
Index: net-2.6.24/net/can/Makefile
===
--- net-2.6.24.orig/net/can/Makefile2007-10-02 08:33:39.0 +0200
+++ net-2.6.24/net/can/Makefile 2007-10-02 08:33:40.0 +0200
@@ -7,3 +7,6 @@
 
 obj-$(CONFIG_CAN_RAW)  += can-raw.o
 can-raw-objs   := raw.o
+
+obj-$(CONFIG_CAN_BCM)  += can-bcm.o
+can-bcm-objs   := bcm.o
Index: net-2.6.24/net/can/bcm.c
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ net-2.6.24/net/can/bcm.c2007-10-02 08:35:04.0 +0200
@@ -0,0 +1,1774 @@
+/*
+ * bcm.c - Broadcast Manager to filter/send (cyclic) CAN content
+ *
+ * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided

Re: [PATCH 1/7] CAN: Allocate protocol numbers for PF_CAN

2007-10-02 Thread Urs Thuermann
Arnaldo Carvalho de Melo [EMAIL PROTECTED] writes:

  --- net-2.6.24.orig/include/linux/if_arp.h  2007-10-02 12:10:51.0 
  +0200
  +++ net-2.6.24/include/linux/if_arp.h   2007-10-02 12:11:01.0 
  +0200
  @@ -52,6 +52,7 @@
   #define ARPHRD_ROSE270
   #define ARPHRD_X25 271 /* CCITT X.25   */
   #define ARPHRD_HWX25   272 /* Boards with X.25 in firmware 
  */
  +#define ARPHRD_CAN 280 /* Controller Area Network  */
 
 Is 280 used in other OS? Just curious as why not using 273

When we first implemented PF_CAN a couple of years ago, we wanted to
avoid a clash with other ARPHRD_* defines which might be added, so we
skipped some numbers after the last used one.  I don't care what
number ARPHRD_CAN is, we can use 273.

  --- net-2.6.24.orig/include/linux/socket.h  2007-10-02 12:10:51.0 
  +0200
  +++ net-2.6.24/include/linux/socket.h   2007-10-02 12:11:01.0 
  +0200
  @@ -185,6 +185,7 @@
   #define AF_PPPOX   24  /* PPPoX sockets*/
   #define AF_WANPIPE 25  /* Wanpipe API Sockets */
   #define AF_LLC 26  /* Linux LLC*/
  +#define AF_CAN 29  /* Controller Area Network  */
 
 Ditto
 
   #define AF_TIPC30  /* TIPC sockets */
   #define AF_BLUETOOTH   31  /* Bluetooth sockets*/
   #define AF_IUCV32  /* IUCV sockets */

For the same reason as above, we didn't use 27, but the last unused
without modifying AF_MAX.  First, we had AF_CAN == 30, then TIPC used
that number and we changed AF_CAN to 29.  Changing again would mean an
ABI change and would break user apps.  If there is a pressing reason I
wouldn't mind personally, but it would probably upset quite a number
of users of our code.  It seems common now to allocate these numbers
from the top in decreasing order.

urs
-
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 6/7] CAN: Add maintainer entries

2007-09-25 Thread Urs Thuermann
This patch adds entries in the CREDITS and MAINTAINERS file for CAN.

Signed-off-by: Oliver Hartkopp [EMAIL PROTECTED]
Signed-off-by: Urs Thuermann [EMAIL PROTECTED]

---
 CREDITS |   16 
 MAINTAINERS |9 +
 2 files changed, 25 insertions(+)

Index: net-2.6.24/CREDITS
===
--- net-2.6.24.orig/CREDITS 2007-09-20 18:48:21.0 +0200
+++ net-2.6.24/CREDITS  2007-09-20 18:49:00.0 +0200
@@ -1331,6 +1331,14 @@
 S: 5623 HZ Eindhoven
 S: The Netherlands
 
+N: Oliver Hartkopp
+E: [EMAIL PROTECTED]
+W: http://www.volkswagen.de
+D: Controller Area Network (network layer core)
+S: Brieffach 1776
+S: 38436 Wolfsburg
+S: Germany
+
 N: Andrew Haylett
 E: [EMAIL PROTECTED]
 D: Selection mechanism
@@ -3284,6 +3292,14 @@
 S: F-35042 Rennes Cedex
 S: France
 
+N: Urs Thuermann
+E: [EMAIL PROTECTED]
+W: http://www.volkswagen.de
+D: Controller Area Network (network layer core)
+S: Brieffach 1776
+S: 38436 Wolfsburg
+S: Germany
+
 N: Jon Tombs
 E: [EMAIL PROTECTED]
 W: http://www.esi.us.es/~jon
Index: net-2.6.24/MAINTAINERS
===
--- net-2.6.24.orig/MAINTAINERS 2007-09-20 18:48:21.0 +0200
+++ net-2.6.24/MAINTAINERS  2007-09-20 18:49:00.0 +0200
@@ -975,6 +975,15 @@
 L: [EMAIL PROTECTED]
 S: Maintained
 
+CAN NETWORK LAYER
+P: Urs Thuermann
+M: [EMAIL PROTECTED]
+P: Oliver Hartkopp
+M: [EMAIL PROTECTED]
+L: [EMAIL PROTECTED]
+W: http://developer.berlios.de/projects/socketcan/
+S: Maintained
+
 CALGARY x86-64 IOMMU
 P: Muli Ben-Yehuda
 M: [EMAIL PROTECTED]

--
-
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 0/7] CAN: Add new PF_CAN protocol family, try #8

2007-09-25 Thread Urs Thuermann
Hello Dave, hello Patrick,

this is the eigth post of the patch series that adds the PF_CAN
protocol family for the Controller Area Network.

Since our last post we have changed the following:

* Some changes in debug code, following suggestions from Joe Perches:
  - Remove dynamically allocated buffer for debug output.
  - Use kernel functions for hexdumps.
  - Don't interpret printf-style %-sequences in can_debug_cframe().
  - Specify the fixed argument fmt to DBG() macro and use
GCC ## mechanism to remove , when args is empty.
* Removed CAN_RAW_USER and CAN_BCM_USER Kconfig options following a
  suggestion from Patrick.
* Prevent overflow in statistics calculation.
* Minor optimization.

The changes in try #7 were:

* Changes suggested by Patrick:
  - protect proto_tab[] by a lock.
  - add _rcu to some hlist traversals.
  - use printk_ratelimit() for module autoload failures.
  - make can_proto_unregister() and can_rx_unregister() return void.
  - use return value of can_proto_register() and can_rx_register()
(this also removed a flaw in behavior of raw_bind() and raw_setsockopt()
 in case of failure to can_rx_register() their filters).
  - call kzalloc() with GFP_KERNEL in case NETDEV_REGISTER.
  - use round_jiffies() to calculate expiration times.
  - make some variables static and/or __read_mostly.
  - in can_create() check for net namespace before auto loading modules.
  - add build time check for struct sizes.
  - use skb_share_chack() in vcan.
  - fixed some comments.
* Typos in documentation as pointed out by Randy Dunlap and Bill Fink.

The changes in try #6 were:

* Update code to work with namespaces in net-2.6.24.
* Remove SET_MODULE_OWNER() from vcan.

The changes in try #5 were:

* Remove slab destructor from calls to kmem_cache_alloc().
* Add comments about types defined in can.h.
* Update comment on vcan loopback module parameter.
* Fix typo in documentation.

The changes in try #4 were:

* Change vcan network driver to use the new RTNL API, as suggested by
  Patrick.
* Revert our change to use skb-iif instead of skb-cb.  After
  discussion with Patrick and Jamal it turned out, our first
  implementation was correct.
* Use skb_tail_pointer() instead of skb-tail directly.
* Coding style changes to satisfy linux/scripts/checkpatch.pl.
* Minor changes for 64-bit-cleanliness.
* Minor cleanup of #include's

The changes in try #3 were:

* Use sbk-sk and skb-pkt_type instead of skb-cb to pass loopback
  flags and originating socket down to the driver and back to the
  receiving socket.  Thanks to Patrick McHardy for pointing out our
  wrong use of sbk-cb.
* Use skb-iif instead of skb-cb to pass receiving interface from
  raw_rcv() and bcm_rcv() up to raw_recvmsg() and bcm_recvmsg().
* Set skb-protocol when sending CAN frames to netdevices.
* Removed struct raw_opt and struct bcm_opt and integrated these
  directly into struct raw_sock and bcm_sock resp., like most other
  proto implementations do.
* We have found and fixed race conditions between raw_bind(),
  raw_{set,get}sockopt() and raw_notifier().  This resulted in
  - complete removal of our own notifier list infrastructure in
af_can.c.  raw.c and bcm.c now use normal netdevice notifiers.
  - removal of ro-lock spinlock.  We use lock_sock(sk) now.
  - changed deletion of dev_rcv_lists, which are now marked for
deletion in the netdevice notifier in af_can.c and are actually
deleted when all entries have been deleted using can_rx_unregister().
* Follow changes in 2.6.22 (e.g. ktime_t timestamps in skb).
* Removed obsolete code from vcan.c, as pointed out by Stephen Hemminger.

The changes in try #2 were:

* reduced RCU callback overhead when deleting receiver lists (thx to
  feedback from Paul E. McKenney).
* eliminated some code duplication in net/can/proc.c.
* renamed slock-29 and sk_lock-29 to slock-AF_CAN and sk_lock-AF_CAN in
  net/core/sock.c
* added entry for can.txt in Documentation/networking/00-INDEX
* added error frame definitions in include/linux/can/error.h, which are to
  be used by CAN network drivers.


This patch series applies against net-2.6.24 and is derived from Subversion
revision r493 of http://svn.berlios.de/svnroot/repos/socketcan.
It can be found in the directory
http://svn.berlios.de/svnroot/repos/socketcan/trunk/patch-series/version.

Thanks very much for your work!

Best regards,

Urs Thuermann
Oliver Hartkopp
--
-
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 5/7] CAN: Add virtual CAN netdevice driver

2007-09-25 Thread Urs Thuermann
This patch adds the virtual CAN bus (vcan) network driver.
The vcan device is just a loopback device for CAN frames, no
real CAN hardware is involved.

Signed-off-by: Oliver Hartkopp [EMAIL PROTECTED]
Signed-off-by: Urs Thuermann [EMAIL PROTECTED]

---
 drivers/net/Makefile |1 
 drivers/net/can/Kconfig  |   25 +
 drivers/net/can/Makefile |5 +
 drivers/net/can/vcan.c   |  208 +++
 net/can/Kconfig  |3 
 5 files changed, 242 insertions(+)

Index: net-2.6.24/drivers/net/Makefile
===
--- net-2.6.24.orig/drivers/net/Makefile2007-09-25 13:28:42.0 
+0200
+++ net-2.6.24/drivers/net/Makefile 2007-09-25 13:32:23.0 +0200
@@ -10,6 +10,7 @@
 obj-$(CONFIG_CHELSIO_T1) += chelsio/
 obj-$(CONFIG_CHELSIO_T3) += cxgb3/
 obj-$(CONFIG_EHEA) += ehea/
+obj-$(CONFIG_CAN) += can/
 obj-$(CONFIG_BONDING) += bonding/
 obj-$(CONFIG_ATL1) += atl1/
 obj-$(CONFIG_GIANFAR) += gianfar_driver.o
Index: net-2.6.24/drivers/net/can/Kconfig
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ net-2.6.24/drivers/net/can/Kconfig  2007-09-25 13:32:23.0 +0200
@@ -0,0 +1,25 @@
+menu CAN Device Drivers
+   depends on CAN
+
+config CAN_VCAN
+   tristate Virtual Local CAN Interface (vcan)
+   depends on CAN
+   default N
+   ---help---
+ Similar to the network loopback devices, vcan offers a
+ virtual local CAN interface.
+
+ This driver can also be built as a module.  If so, the module
+ will be called vcan.
+
+config CAN_DEBUG_DEVICES
+   bool CAN devices debugging messages
+   depends on CAN
+   default N
+   ---help---
+ Say Y here if you want the CAN device drivers to produce a bunch of
+ debug messages to the system log.  Select this if you are having
+ a problem with CAN support and want to see more of what is going
+ on.
+
+endmenu
Index: net-2.6.24/drivers/net/can/Makefile
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ net-2.6.24/drivers/net/can/Makefile 2007-09-25 13:32:23.0 +0200
@@ -0,0 +1,5 @@
+#
+#  Makefile for the Linux Controller Area Network drivers.
+#
+
+obj-$(CONFIG_CAN_VCAN) += vcan.o
Index: net-2.6.24/drivers/net/can/vcan.c
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ net-2.6.24/drivers/net/can/vcan.c   2007-09-25 13:32:23.0 +0200
@@ -0,0 +1,208 @@
+/*
+ * vcan.c - Virtual CAN interface
+ *
+ * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
+ * All rights reserved.
+ *
+ * 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, the following disclaimer and
+ *the referenced file 'COPYING'.
+ * 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. Neither the name of Volkswagen nor the names of its contributors
+ *may be used to endorse or promote products derived from this software
+ *without specific prior written permission.
+ *
+ * Alternatively, provided that this notice is retained in full, this
+ * software may be distributed under the terms of the GNU General
+ * Public License (GPL) version 2 as distributed in the 'COPYING'
+ * file from the main directory of the linux kernel source.
+ *
+ * The provided data structures and external interfaces from this code
+ * are not restricted to be used by modules with a GPL compatible license.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT
+ * OWNER 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.
+ *
+ * Send feedback to [EMAIL PROTECTED]
+ *
+ */
+
+#include linux/module.h
+#include linux/init.h
+#include linux/netdevice.h
+#include linux/if_arp.h
+#include linux/if_ether.h
+#include

[PATCH 3/7] CAN: Add raw protocol

2007-09-25 Thread Urs Thuermann
This patch adds the CAN raw protocol.

Signed-off-by: Oliver Hartkopp [EMAIL PROTECTED]
Signed-off-by: Urs Thuermann [EMAIL PROTECTED]

---
 include/linux/can/raw.h |   31 +
 net/can/Kconfig |   11 
 net/can/Makefile|3 
 net/can/raw.c   |  822 
 4 files changed, 867 insertions(+)

Index: net-2.6.24/include/linux/can/raw.h
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ net-2.6.24/include/linux/can/raw.h  2007-09-25 13:23:05.0 +0200
@@ -0,0 +1,31 @@
+/*
+ * linux/can/raw.h
+ *
+ * Definitions for raw CAN sockets
+ *
+ * Authors: Oliver Hartkopp [EMAIL PROTECTED]
+ *  Urs Thuermann   [EMAIL PROTECTED]
+ * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
+ * All rights reserved.
+ *
+ * Send feedback to [EMAIL PROTECTED]
+ *
+ */
+
+#ifndef CAN_RAW_H
+#define CAN_RAW_H
+
+#include linux/can.h
+
+#define SOL_CAN_RAW (SOL_CAN_BASE + CAN_RAW)
+
+/* for socket options affecting the socket (not the global system) */
+
+enum {
+   CAN_RAW_FILTER = 1, /* set 0 .. n can_filter(s)  */
+   CAN_RAW_ERR_FILTER, /* set filter for error frames   */
+   CAN_RAW_LOOPBACK,   /* local loopback (default:on)   */
+   CAN_RAW_RECV_OWN_MSGS   /* receive my own msgs (default:off) */
+};
+
+#endif
Index: net-2.6.24/net/can/Kconfig
===
--- net-2.6.24.orig/net/can/Kconfig 2007-09-25 13:14:46.0 +0200
+++ net-2.6.24/net/can/Kconfig  2007-09-25 13:31:06.0 +0200
@@ -16,6 +16,17 @@
  If you want CAN support, you should say Y here and also to the
  specific driver for your controller(s) below.
 
+config CAN_RAW
+   tristate Raw CAN Protocol (raw access with CAN-ID filtering)
+   depends on CAN
+   default N
+   ---help---
+ The Raw CAN protocol option offers access to the CAN bus via
+ the BSD socket API. You probably want to use the raw socket in
+ most cases where no higher level protocol is being used. The raw
+ socket has several filter options e.g. ID-Masking / Errorframes.
+ To receive/send raw CAN messages, use AF_CAN with protocol CAN_RAW.
+
 config CAN_DEBUG_CORE
bool CAN Core debugging messages
depends on CAN
Index: net-2.6.24/net/can/Makefile
===
--- net-2.6.24.orig/net/can/Makefile2007-09-25 13:14:46.0 +0200
+++ net-2.6.24/net/can/Makefile 2007-09-25 13:29:23.0 +0200
@@ -4,3 +4,6 @@
 
 obj-$(CONFIG_CAN)  += can.o
 can-objs   := af_can.o proc.o
+
+obj-$(CONFIG_CAN_RAW)  += can-raw.o
+can-raw-objs   := raw.o
Index: net-2.6.24/net/can/raw.c
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ net-2.6.24/net/can/raw.c2007-09-25 13:25:24.0 +0200
@@ -0,0 +1,822 @@
+/*
+ * raw.c - Raw sockets for protocol family CAN
+ *
+ * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
+ * All rights reserved.
+ *
+ * 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, the following disclaimer and
+ *the referenced file 'COPYING'.
+ * 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. Neither the name of Volkswagen nor the names of its contributors
+ *may be used to endorse or promote products derived from this software
+ *without specific prior written permission.
+ *
+ * Alternatively, provided that this notice is retained in full, this
+ * software may be distributed under the terms of the GNU General
+ * Public License (GPL) version 2 as distributed in the 'COPYING'
+ * file from the main directory of the linux kernel source.
+ *
+ * The provided data structures and external interfaces from this code
+ * are not restricted to be used by modules with a GPL compatible license.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT
+ * OWNER 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

[PATCH 1/7] CAN: Allocate protocol numbers for PF_CAN

2007-09-25 Thread Urs Thuermann
This patch adds a protocol/address family number, ARP hardware type,
ethernet packet type, and a line discipline number for the SocketCAN
implementation.

Signed-off-by: Oliver Hartkopp [EMAIL PROTECTED]
Signed-off-by: Urs Thuermann [EMAIL PROTECTED]

---
 include/linux/if_arp.h   |1 +
 include/linux/if_ether.h |1 +
 include/linux/socket.h   |2 ++
 include/linux/tty.h  |3 ++-
 net/core/sock.c  |4 ++--
 5 files changed, 8 insertions(+), 3 deletions(-)

Index: net-2.6.24/include/linux/if_arp.h
===
--- net-2.6.24.orig/include/linux/if_arp.h  2007-09-20 18:48:21.0 
+0200
+++ net-2.6.24/include/linux/if_arp.h   2007-09-20 18:48:57.0 +0200
@@ -52,6 +52,7 @@
 #define ARPHRD_ROSE270
 #define ARPHRD_X25 271 /* CCITT X.25   */
 #define ARPHRD_HWX25   272 /* Boards with X.25 in firmware */
+#define ARPHRD_CAN 280 /* Controller Area Network  */
 #define ARPHRD_PPP 512
 #define ARPHRD_CISCO   513 /* Cisco HDLC   */
 #define ARPHRD_HDLCARPHRD_CISCO
Index: net-2.6.24/include/linux/if_ether.h
===
--- net-2.6.24.orig/include/linux/if_ether.h2007-09-20 18:48:21.0 
+0200
+++ net-2.6.24/include/linux/if_ether.h 2007-09-20 18:48:57.0 +0200
@@ -90,6 +90,7 @@
 #define ETH_P_WAN_PPP   0x0007  /* Dummy type for WAN PPP frames*/
 #define ETH_P_PPP_MP0x0008  /* Dummy type for PPP MP frames */
 #define ETH_P_LOCALTALK 0x0009 /* Localtalk pseudo type*/
+#define ETH_P_CAN  0x000C  /* Controller Area Network  */
 #define ETH_P_PPPTALK  0x0010  /* Dummy type for Atalk over PPP*/
 #define ETH_P_TR_802_2 0x0011  /* 802.2 frames */
 #define ETH_P_MOBITEX  0x0015  /* Mobitex ([EMAIL PROTECTED])  */
Index: net-2.6.24/include/linux/socket.h
===
--- net-2.6.24.orig/include/linux/socket.h  2007-09-20 18:48:21.0 
+0200
+++ net-2.6.24/include/linux/socket.h   2007-09-20 18:48:57.0 +0200
@@ -185,6 +185,7 @@
 #define AF_PPPOX   24  /* PPPoX sockets*/
 #define AF_WANPIPE 25  /* Wanpipe API Sockets */
 #define AF_LLC 26  /* Linux LLC*/
+#define AF_CAN 29  /* Controller Area Network  */
 #define AF_TIPC30  /* TIPC sockets */
 #define AF_BLUETOOTH   31  /* Bluetooth sockets*/
 #define AF_IUCV32  /* IUCV sockets */
@@ -220,6 +221,7 @@
 #define PF_PPPOX   AF_PPPOX
 #define PF_WANPIPE AF_WANPIPE
 #define PF_LLC AF_LLC
+#define PF_CAN AF_CAN
 #define PF_TIPCAF_TIPC
 #define PF_BLUETOOTH   AF_BLUETOOTH
 #define PF_IUCVAF_IUCV
Index: net-2.6.24/include/linux/tty.h
===
--- net-2.6.24.orig/include/linux/tty.h 2007-09-20 18:48:21.0 +0200
+++ net-2.6.24/include/linux/tty.h  2007-09-20 18:48:57.0 +0200
@@ -24,7 +24,7 @@
 #define NR_PTYSCONFIG_LEGACY_PTY_COUNT   /* Number of legacy ptys */
 #define NR_UNIX98_PTY_DEFAULT  4096  /* Default maximum for Unix98 ptys */
 #define NR_UNIX98_PTY_MAX  (1  MINORBITS) /* Absolute limit */
-#define NR_LDISCS  17
+#define NR_LDISCS  18
 
 /* line disciplines */
 #define N_TTY  0
@@ -45,6 +45,7 @@
 #define N_SYNC_PPP 14  /* synchronous PPP */
 #define N_HCI  15  /* Bluetooth HCI UART */
 #define N_GIGASET_M101 16  /* Siemens Gigaset M101 serial DECT adapter */
+#define N_SLCAN17  /* Serial / USB serial CAN Adaptors */
 
 /*
  * This character is the same as _POSIX_VDISABLE: it cannot be used as
Index: net-2.6.24/net/core/sock.c
===
--- net-2.6.24.orig/net/core/sock.c 2007-09-20 18:48:21.0 +0200
+++ net-2.6.24/net/core/sock.c  2007-09-20 18:48:57.0 +0200
@@ -154,7 +154,7 @@
   sk_lock-AF_ASH   , sk_lock-AF_ECONET   , sk_lock-AF_ATMSVC   ,
   sk_lock-21   , sk_lock-AF_SNA  , sk_lock-AF_IRDA ,
   sk_lock-AF_PPPOX , sk_lock-AF_WANPIPE  , sk_lock-AF_LLC  ,
-  sk_lock-27   , sk_lock-28  , sk_lock-29  ,
+  sk_lock-27   , sk_lock-28  , sk_lock-AF_CAN  ,
   sk_lock-AF_TIPC  , sk_lock-AF_BLUETOOTH, sk_lock-IUCV,
   sk_lock-AF_RXRPC , sk_lock-AF_MAX
 };
@@ -168,7 +168,7 @@
   slock-AF_ASH   , slock-AF_ECONET   , slock-AF_ATMSVC   ,
   slock-21   , slock-AF_SNA  , slock-AF_IRDA ,
   slock-AF_PPPOX , slock-AF_WANPIPE  , slock-AF_LLC  ,
-  slock-27   , slock-28  , slock-29  ,
+  slock-27   , slock

[PATCH 7/7] CAN: Add documentation

2007-09-25 Thread Urs Thuermann
This patch adds documentation for the PF_CAN protocol family.

Signed-off-by: Oliver Hartkopp [EMAIL PROTECTED]
Signed-off-by: Urs Thuermann [EMAIL PROTECTED]

---
 Documentation/networking/00-INDEX |2 
 Documentation/networking/can.txt  |  634 ++
 2 files changed, 636 insertions(+)

Index: net-2.6.24/Documentation/networking/can.txt
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ net-2.6.24/Documentation/networking/can.txt 2007-09-25 13:28:26.0 
+0200
@@ -0,0 +1,634 @@
+
+
+can.txt
+
+Readme file for the Controller Area Network Protocol Family (aka Socket CAN)
+
+This file contains
+
+  1 Overview / What is Socket CAN
+
+  2 Motivation / Why using the socket API
+
+  3 Socket CAN concept
+3.1 receive lists
+3.2 loopback
+3.3 network security issues (capabilities)
+3.4 network problem notifications
+
+  4 How to use Socket CAN
+4.1 RAW protocol sockets with can_filters (SOCK_RAW)
+  4.1.1 RAW socket option CAN_RAW_FILTER
+  4.1.2 RAW socket option CAN_RAW_ERR_FILTER
+  4.1.3 RAW socket option CAN_RAW_LOOPBACK
+  4.1.4 RAW socket option CAN_RAW_RECV_OWN_MSGS
+4.2 Broadcast Manager protocol sockets (SOCK_DGRAM)
+4.3 connected transport protocols (SOCK_SEQPACKET)
+4.4 unconnected transport protocols (SOCK_DGRAM)
+
+  5 Socket CAN core module
+5.1 can.ko module params
+5.2 procfs content
+5.3 writing own CAN protocol modules
+
+  6 CAN network drivers
+6.1 general settings
+6.2 loopback
+6.3 CAN controller hardware filters
+6.4 currently supported CAN hardware
+6.5 todo
+
+  7 Credits
+
+
+
+1. Overview / What is Socket CAN
+
+
+The socketcan package is an implementation of CAN protocols
+(Controller Area Network) for Linux.  CAN is a networking technology
+which has widespread use in automation, embedded devices, and
+automotive fields.  While there have been other CAN implementations
+for Linux based on character devices, Socket CAN uses the Berkeley
+socket API, the Linux network stack and implements the CAN device
+drivers as network interfaces.  The CAN socket API has been designed
+as similar as possible to the TCP/IP protocols to allow programmers,
+familiar with network programming, to easily learn how to use CAN
+sockets.
+
+2. Motivation / Why using the socket API
+
+
+There have been CAN implementations for Linux before Socket CAN so the
+question arises, why we have started another project.  Most existing
+implementations come as a device driver for some CAN hardware, they
+are based on character devices and provide comparatively little
+functionality.  Usually, there is only a hardware-specific device
+driver which provides a character device interface to send and
+receive raw CAN frames, directly to/from the controller hardware.
+Queueing of frames and higher-level transport protocols like ISO-TP
+have to be implemented in user space applications.  Also, most
+character-device implementations support only one single process to
+open the device at a time, similar to a serial interface.  Exchanging
+the CAN controller requires employment of another device driver and
+often the need for adaption of large parts of the application to the
+new driver's API.
+
+Socket CAN was designed to overcome all of these limitations.  A new
+protocol family has been implemented which provides a socket interface
+to user space applications and which builds upon the Linux network
+layer, so to use all of the provided queueing functionality.  A device
+driver for CAN controller hardware registers itself with the Linux
+network layer as a network device, so that CAN frames from the
+controller can be passed up to the network layer and on to the CAN
+protocol family module and also vice-versa.  Also, the protocol family
+module provides an API for transport protocol modules to register, so
+that any number of transport protocols can be loaded or unloaded
+dynamically.  In fact, the can core module alone does not provide any
+protocol and cannot be used without loading at least one additional
+protocol module.  Multiple sockets can be opened at the same time,
+on different or the same protocol module and they can listen/send
+frames on different or the same CAN IDs.  Several sockets listening on
+the same interface for frames with the same CAN ID are all passed the
+same received matching CAN frames.  An application wishing to
+communicate using a specific transport protocol, e.g. ISO-TP, just
+selects that protocol when opening the socket, and then can read and
+write application data byte streams, without having to deal with
+CAN-IDs, frames, etc.
+
+Similar functionality visible from user-space

Re: [PATCH 2/7] CAN: Add PF_CAN core module

2007-09-25 Thread Urs Thuermann
Arnaldo Carvalho de Melo [EMAIL PROTECTED] writes:

  +   skb_queue_purge(sk-sk_receive_queue);
  +   if (sk-sk_protinfo)
  +   kfree(sk-sk_protinfo);
  +}
 
 Is it really needed to do this sk_protinfo check?

Thanks for finding this.  This is from 2.6.12 times or so.  We have
other CAN protocol (which we are not allowed to put under GPL)
implemenatations which still use the protinfo field.  But we should
change those and I will delete this check.

urs
-
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 4/7] CAN: Add broadcast manager (bcm) protocol

2007-09-25 Thread Urs Thuermann
Arnaldo Carvalho de Melo [EMAIL PROTECTED] writes:

  +   skb = alloc_skb(CFSIZ,
  +   in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
 
 We have gfp_any() for this:

Ah, ok.  That looks better.  Applied.

urs
-
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 5/7] CAN: Add virtual CAN netdevice driver

2007-09-25 Thread Urs Thuermann
YOSHIFUJI Hideaki / È£ÑÀ  [EMAIL PROTECTED] writes:

 I'm not a lawyer, but the following lines:
 
 | + * Alternatively, provided that this notice is retained in full, this
  ~~
 | + * software may be distributed under the terms of the GNU General
 | + * Public License (GPL) version 2 as distributed in the 'COPYING'
 | + * file from the main directory of the linux kernel source.
 
 make this whole licence imcompatible with GPL.

I'm no lawyer at all, either.  And also Oliver is not, but he has
carried out the fights with our company lawyers.  Maybe he can say
something about whether we can change this.

 I do think you need to allow people to select GPLv2 only.

The sentence you cite *does* allow distribution under GPLv2 only.  And
I think I have often read the restriction to retain such licences in
full in GPLv2 code.  Is that really incompatible?

urs
-
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/7] CAN: Add PF_CAN core module

2007-09-25 Thread Urs Thuermann
Stephen Hemminger [EMAIL PROTECTED] writes:

 Then please make all exported symbols marked EXPORT_SYMBOL_GPL to make
 sure that the other CAN protocol can not reuse your infrastructure.

We don't want to force other CAN protocol implementations to be GPL
also.  AFAIR from discussions on LKML, it was mostly agreed upon that
this decision is up to the authors of code.

urs
-
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/7] CAN: Add PF_CAN core module

2007-09-24 Thread Urs Thuermann
Joe Perches [EMAIL PROTECTED] writes:

 I'd prefer something like this, which removes the unnecessary
 kmalloc/kfree pairs or the equivalent conversions to functions.

I have changed this to a static buffer.  Since this is only in
#ifdef CONFIG_CAN_DEBUG_CORE, it shouldn't hurt.

 #define can_debug_cframe(cf, fmt, arg...) \
 do { \
   char buf[20]; \
   int dlc = cf-can_dlc; \
   if (dlc  8) \
   dlc = 8; \
   if (cf-can_id  CAN_EFF_FLAG) \
   sprintf(buf, %08X [%X] , cf-can_id  CAN_EFF_MASK, dlc); \
   else \
   sprintf(buf, %03X [%X] , cf-can_id  CAN_SFF_MASK, dlc); \
   printk(KERN_DEBUG fmt, ##arg); \
   print_hex_dump(buf, DUMP_PREFIX_NONE, cf-data, dlc); \
 } while (0)

The line isn't printed atomically, i.e. it could happen that something
is printed between the fmt+args and the hexdump, i.e inbetween the
line.

 and
 
 #define can_debug_skb(skb) \
 do { \
   pr_debug(skbuff at %p, dev: %d, proto: %04x\n, \
skb, skb-dev ? skb-dev-ifindex : -1, \
ntohs(skb-protocol)); \
   pr_debug(users: %d, dataref: %d, nr_frags: %d,  \
h,d,t,e,l: %p %+d %+d %+d, %d\n, \
atomic_read(skb-users), \
atomic_read((skb_shinfo(skb)-dataref)), \
skb_shinfo(skb)-nr_frags, \
skb-head, skb-data - skb-head, \
skb-tail - skb-head, skb-end - skb-head, skb-len); \
   print_hex_dump(KERN_DEBUG, skb_head: , DUMP_PREFIX_NONE, \
  16, 1, skb-head, skb-end - skb-head); \ 
 } while (0)

Here, the consecutive lines aren't printed atomically.

I think sprintf() to a buffer first and the do one printk() is
better.  But I will use hex_dump_to_buffer().


urs
-
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/7] CAN: Add PF_CAN core module

2007-09-21 Thread Urs Thuermann
Joe Perches [EMAIL PROTECTED] writes:

 On Thu, 2007-09-20 at 20:43 +0200, Urs Thuermann wrote:
  +#define DBG(...)   (debug  1 ? \
  +  (printk(KERN_DEBUG can-%s %s: , \
  +   IDENT, __func__), printk(args)) : 0)
  +#define DBG_FRAME(args...) (debug  2 ? can_debug_cframe(args) : 0)
  +#define DBG_SKB(skb)   (debug  4 ? can_debug_skb(skb) : 0)
  +#else
  +#define DBG(args...)
  +#define DBG_FRAME(args...)
  +#define DBG_SKB(skb)
  +#endif
 
 Shouldn't these be like the more common
 
 #define DBG(fmt, args...) \

When I wrote these macros we had one platform where we still used
linux-2.4 and gcc-2.95.3 and with that old gcc your macro def would
mean you can't use DBG with only one argument, like DBG(some string\n);
since gcc-2.95 would leave the , after __func__ followed by the
closing ).  I didn't find a way with gcc-2.95 to make the format
string a separate macro argument (which I also wanted).  OK, that's
history now and linux-2.6 needs gcc-3/4 anyway, so I will change this.

 do { \
   if (debug  1) \
   printk(KERN_DEBUG can-%s %s:  fmt, IDENT, __func__, ##args); \
 } while (0)

I use do { ... } while(0) only for statements, not for expressions.
But I could have used the  instead of ?: operator.  I don't think
the do { ... } while(0) looks nicer or has any other advantage.

  void can_debug_cframe(const char *msg, struct can_frame *cf, ...)
 
 This prototype looks backwards to me.

You mean the order or `msg' and `cf'?  You want to switch them so that
the variable args follow immediately the format string?  Might make
sense, OTOH we wanted to have the message as the first argument.

 I'd prefer something like this, which removes the unnecessary
 kmalloc/kfree pairs or the equivalent conversions to functions.
 
 #define can_debug_cframe(cf, fmt, arg...) \
 do { \
   char buf[20]; \
   int dlc = cf-can_dlc; \
   if (dlc  8) \
   dlc = 8; \
   if (cf-can_id  CAN_EFF_FLAG) \
   sprintf(buf, %08X [%X] , cf-can_id  CAN_EFF_MASK, dlc); \
   else \
   sprintf(buf, %03X [%X] , cf-can_id  CAN_SFF_MASK, dlc); \
   printk(KERN_DEBUG fmt, ##arg); \
   print_hex_dump(buf, DUMP_PREFIX_NONE, cf-data, dlc); \
 } while (0)

Ah, I didn't know print_hex_dump().  That looks nicer.  But as Thomas
mentioned, we shouldn't convert these functions into macros.

urs
-
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/7] CAN: Add PF_CAN core module

2007-09-21 Thread Urs Thuermann
Patrick McHardy [EMAIL PROTECTED] writes:

 You drop the module reference again when leaving this function.
 So sock-ops might contain a stale pointer if the module is
 unloaded after this. You need to either keep the module reference
 while the socket is alive or remove stale references when
 unregistering the protocol.

I don't think that can happen.  Before we drop the module reference we
call sk_alloc() which gets another module reference via its cp-prot
argument.  If sk_alloc() fails we return with error from can_create()
I assume sock-ops won't be used after that.

urs
-
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 3/7] CAN: Add raw protocol

2007-09-21 Thread Urs Thuermann
Patrick McHardy [EMAIL PROTECTED] writes:

 Urs Thuermann wrote:
  +config CAN_RAW_USER
  +   bool Allow non-root users to access Raw CAN Protocol sockets
 
 
 If you plan to remove this option, it should happen before merging
 since it affects userspace visible behaviour.

We have discussed this and have come to the conclusion that we should
remove permission checks completely, i.e. any user can open any CAN
socket (raw, bcm, or whatever will be implemented in the future).
This is because CAN is a pure broadcast network with no addresses.
CAN frames can't be directed to only one machine or a group or to only
one process (say one port).  There is no communication between only
two (or some number) of stations which must be protected from other
stations.

On the other hand, requiring a process to have CAP_NET_RAW to open a
CAN socket would mean that such process would also be able to sniff on
your ethernet or WLAN interfaces, which one probably wouldn't want.

We have added that check when we still allowed the CAN raw socket to
bind to any interface and we didn't want an unprivileged process to be
able to read all e.g. TCP/IP traffic.  Now binding is restricted to
ARPHRD_CAN interfaces.  But even without this restriction the check is
not necessary, since all CAN sockets can only receive and send
ETH_P_CAN packets.  So even if there would be an encapsulation of CAN
frames over ethernet or some other type of network, a normal user
process opening a CAN socket would only be able to read/write CAN
traffic, which should be OK without any special capability.

So what do you think about this?

urs
-
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/7] CAN: Add PF_CAN core module

2007-09-20 Thread Urs Thuermann
Hi Patrick,

I have done allmost all changes to the code as you suggested.  The
changes to use the return value of can_rx_register() also fixed a
minor flax with failing bind() and setsockopt() on raw sockets.

But there are two things left I would like to ask/understand:

Patrick McHardy [EMAIL PROTECTED] writes:

  When the module is unloaded it calls can_proto_unregister() which
  clears the pointer.  Do you see a race condition here?
 
 Yes, you do request_module, load the module, get the cp pointer
 from proto_tab, the module is unloaded again. cp points to
 stable memory. Using module references would fix this.

How would I use the module reference counter?  Somehow with
try_module_get()?  I have thought something like

cp = proto_tab[protocol];
if (!cp ...)
return ...;

if (!try_module_get(cp-prot-owner))
return ...;

sk = sk_alloc(...)

module_put(...);
return ret;

But here I see two problems:

1. Between the check !cp...  and referencing cp-prot-owner the
   module could get unloaded and the reference be invalid.  Is there
   some lock I can hold that prevents module unloading?  I haven't
   found something like this in include/linux/module.h

2. If the module gets unloaded after the first check and
   request_module() but before the call to try_module_get() the
   socket() syscall will return with error, although module auto
   loading would normally be successful.  How can I prevent that?

  find_dev_rcv_lists() is called in one place from can_rcv() with RCU
  lock held, as you write.  The other two calls to find_dev_rcv_lists()
  are from can_rx_register/unregister() functions which change the
  receive lists.  Therefore, we can't only use RCU but need protection
  against simultanous writes.  We do this with the spin_lock_bh().  The
  _bh variant, because can_rcv() runs in interrupt and we need to block
  that.  I thought this is pretty standard.
  
  I'll check this again tomorrow, but I have put much time in these
  locking issues already, changed it quite a few times and hoped to have
  got it right finally.
 
 
 I'm not saying you should use *only* RCU, you need the lock
 for additions/removal of course, but since the receive path
 doesn't take that lock and relies on RCU, you need to use
 the _rcu list walking variant to avoid races with concurrent
 list changes.

I have no objections to add the _rcu suffix for the code changing the
receive lists, but I don't see why it's necessary.  When I do a
spin_lock_bh() before writing, can't I be sure that there is no
interrupt routine running in parallel while I hold this spinlock?  If
so, there is no reader in parallel because the can_rcv() function runs
in a softirq.  I'd really like to understand why you think the writers
should also use the _rcu variant.  I'm sorry if I miss something
obvious here, but could you try to explain it to me?

urs
-
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/7] CAN: Add PF_CAN core module

2007-09-20 Thread Urs Thuermann
Patrick McHardy [EMAIL PROTECTED] writes:

 No, you need to add your own locking to prevent this, something
 list this:
 
 registration/unregistration:
 
 take lock
 change proto_tab[]
 release lock
 
 lookup:
 
 take lock
 cp = proto_tab[]
 if (cp  !try_module_get(cp-owner))
   cp = NULL
 release lock

Ah, ok.  Thanks for that hint.  I will add it that way.

  2. If the module gets unloaded after the first check and
 request_module() but before the call to try_module_get() the
 socket() syscall will return with error, although module auto
 loading would normally be successful.  How can I prevent that?
 
 
 Why do you want to prevent it? The admin unloaded the module,
 so he apparently doesn't want the operation to succeed.

Well, unloading a module doesn't usually cause to operation to fail
when auto loading is enabled.  It only wouldn't succeed when the
unload happens in the small window between test/request-module and
call to try_module_get().  This looks ugly to me.  But the lock you
described above would also solve this.

 I'm saying you need _rcu for the *read side*. All operations changing
 the list already use the _rcu variants.
 
  I'm sorry if I miss something
  obvious here, but could you try to explain it to me?
 
 
 spin_lock_bh only disables BHs locally, other CPUs can still process
 softirqs. And since rcv_lists_lock is only used in process context,
 the BH disabling is actually not even necessary.

Well, I finally (hopefully) got it and I have changed the code
accordingly.  Thanks for your explanation.

I will post our updated code again, probably today.  The issues still
left are

* module parameter for loopback, but we want to keep that.
* configure option for allowing normal users access to raw and bcm CAN
  sockets.  I'll check how easily an (embedded) system can be set up
  to run relevant/all processes with the CAP_NEW_RAW capability.  I
  would like to kill that configure option.
* seq_files for proc fs.  On my TODO list.

urs
-
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 3/7] CAN: Add raw protocol

2007-09-20 Thread Urs Thuermann
This patch adds the CAN raw protocol.

Signed-off-by: Oliver Hartkopp [EMAIL PROTECTED]
Signed-off-by: Urs Thuermann [EMAIL PROTECTED]

---
 include/linux/can/raw.h |   31 +
 net/can/Kconfig |   26 +
 net/can/Makefile|3 
 net/can/raw.c   |  828 
 4 files changed, 888 insertions(+)

Index: net-2.6.24/include/linux/can/raw.h
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ net-2.6.24/include/linux/can/raw.h  2007-09-20 18:48:59.0 +0200
@@ -0,0 +1,31 @@
+/*
+ * linux/can/raw.h
+ *
+ * Definitions for raw CAN sockets
+ *
+ * Authors: Oliver Hartkopp [EMAIL PROTECTED]
+ *  Urs Thuermann   [EMAIL PROTECTED]
+ * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
+ * All rights reserved.
+ *
+ * Send feedback to [EMAIL PROTECTED]
+ *
+ */
+
+#ifndef CAN_RAW_H
+#define CAN_RAW_H
+
+#include linux/can.h
+
+#define SOL_CAN_RAW (SOL_CAN_BASE + CAN_RAW)
+
+/* for socket options affecting the socket (not the global system) */
+
+enum {
+   CAN_RAW_FILTER = 1, /* set 0 .. n can_filter(s)  */
+   CAN_RAW_ERR_FILTER, /* set filter for error frames   */
+   CAN_RAW_LOOPBACK,   /* local loopback (default:on)   */
+   CAN_RAW_RECV_OWN_MSGS   /* receive my own msgs (default:off) */
+};
+
+#endif
Index: net-2.6.24/net/can/Kconfig
===
--- net-2.6.24.orig/net/can/Kconfig 2007-09-20 18:48:58.0 +0200
+++ net-2.6.24/net/can/Kconfig  2007-09-20 18:48:59.0 +0200
@@ -16,6 +16,32 @@
  If you want CAN support, you should say Y here and also to the
  specific driver for your controller(s) below.
 
+config CAN_RAW
+   tristate Raw CAN Protocol (raw access with CAN-ID filtering)
+   depends on CAN
+   default N
+   ---help---
+ The Raw CAN protocol option offers access to the CAN bus via
+ the BSD socket API. You probably want to use the raw socket in
+ most cases where no higher level protocol is being used. The raw
+ socket has several filter options e.g. ID-Masking / Errorframes.
+ To receive/send raw CAN messages, use AF_CAN with protocol CAN_RAW.
+
+config CAN_RAW_USER
+   bool Allow non-root users to access Raw CAN Protocol sockets
+   depends on CAN_RAW
+   default N
+   ---help---
+ The Controller Area Network is a local field bus transmitting only
+ broadcast messages without any routing and security concepts.
+ In the majority of cases the user application has to deal with
+ raw CAN frames. Therefore it might be reasonable NOT to restrict
+ the CAN access only to the user root, as known from other networks.
+ Since CAN_RAW sockets can only send and receive frames to/from CAN
+ interfaces this does not affect security of others networks.
+ Say Y here if you want non-root users to be able to access CAN_RAW
+ sockets.
+
 config CAN_DEBUG_CORE
bool CAN Core debugging messages
depends on CAN
Index: net-2.6.24/net/can/Makefile
===
--- net-2.6.24.orig/net/can/Makefile2007-09-20 18:48:58.0 +0200
+++ net-2.6.24/net/can/Makefile 2007-09-20 18:48:59.0 +0200
@@ -4,3 +4,6 @@
 
 obj-$(CONFIG_CAN)  += can.o
 can-objs   := af_can.o proc.o
+
+obj-$(CONFIG_CAN_RAW)  += can-raw.o
+can-raw-objs   := raw.o
Index: net-2.6.24/net/can/raw.c
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ net-2.6.24/net/can/raw.c2007-09-20 18:48:59.0 +0200
@@ -0,0 +1,828 @@
+/*
+ * raw.c - Raw sockets for protocol family CAN
+ *
+ * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
+ * All rights reserved.
+ *
+ * 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, the following disclaimer and
+ *the referenced file 'COPYING'.
+ * 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. Neither the name of Volkswagen nor the names of its contributors
+ *may be used to endorse or promote products derived from this software
+ *without specific prior written permission.
+ *
+ * Alternatively, provided that this notice is retained in full, this
+ * software may be distributed under the terms of the GNU General
+ * Public License (GPL) version 2 as distributed in the 'COPYING'
+ * file from the main directory

[PATCH 1/7] CAN: Allocate protocol numbers for PF_CAN

2007-09-20 Thread Urs Thuermann
This patch adds a protocol/address family number, ARP hardware type,
ethernet packet type, and a line discipline number for the SocketCAN
implementation.

Signed-off-by: Oliver Hartkopp [EMAIL PROTECTED]
Signed-off-by: Urs Thuermann [EMAIL PROTECTED]

---
 include/linux/if_arp.h   |1 +
 include/linux/if_ether.h |1 +
 include/linux/socket.h   |2 ++
 include/linux/tty.h  |3 ++-
 net/core/sock.c  |4 ++--
 5 files changed, 8 insertions(+), 3 deletions(-)

Index: net-2.6.24/include/linux/if_arp.h
===
--- net-2.6.24.orig/include/linux/if_arp.h  2007-09-20 18:48:21.0 
+0200
+++ net-2.6.24/include/linux/if_arp.h   2007-09-20 18:48:57.0 +0200
@@ -52,6 +52,7 @@
 #define ARPHRD_ROSE270
 #define ARPHRD_X25 271 /* CCITT X.25   */
 #define ARPHRD_HWX25   272 /* Boards with X.25 in firmware */
+#define ARPHRD_CAN 280 /* Controller Area Network  */
 #define ARPHRD_PPP 512
 #define ARPHRD_CISCO   513 /* Cisco HDLC   */
 #define ARPHRD_HDLCARPHRD_CISCO
Index: net-2.6.24/include/linux/if_ether.h
===
--- net-2.6.24.orig/include/linux/if_ether.h2007-09-20 18:48:21.0 
+0200
+++ net-2.6.24/include/linux/if_ether.h 2007-09-20 18:48:57.0 +0200
@@ -90,6 +90,7 @@
 #define ETH_P_WAN_PPP   0x0007  /* Dummy type for WAN PPP frames*/
 #define ETH_P_PPP_MP0x0008  /* Dummy type for PPP MP frames */
 #define ETH_P_LOCALTALK 0x0009 /* Localtalk pseudo type*/
+#define ETH_P_CAN  0x000C  /* Controller Area Network  */
 #define ETH_P_PPPTALK  0x0010  /* Dummy type for Atalk over PPP*/
 #define ETH_P_TR_802_2 0x0011  /* 802.2 frames */
 #define ETH_P_MOBITEX  0x0015  /* Mobitex ([EMAIL PROTECTED])  */
Index: net-2.6.24/include/linux/socket.h
===
--- net-2.6.24.orig/include/linux/socket.h  2007-09-20 18:48:21.0 
+0200
+++ net-2.6.24/include/linux/socket.h   2007-09-20 18:48:57.0 +0200
@@ -185,6 +185,7 @@
 #define AF_PPPOX   24  /* PPPoX sockets*/
 #define AF_WANPIPE 25  /* Wanpipe API Sockets */
 #define AF_LLC 26  /* Linux LLC*/
+#define AF_CAN 29  /* Controller Area Network  */
 #define AF_TIPC30  /* TIPC sockets */
 #define AF_BLUETOOTH   31  /* Bluetooth sockets*/
 #define AF_IUCV32  /* IUCV sockets */
@@ -220,6 +221,7 @@
 #define PF_PPPOX   AF_PPPOX
 #define PF_WANPIPE AF_WANPIPE
 #define PF_LLC AF_LLC
+#define PF_CAN AF_CAN
 #define PF_TIPCAF_TIPC
 #define PF_BLUETOOTH   AF_BLUETOOTH
 #define PF_IUCVAF_IUCV
Index: net-2.6.24/include/linux/tty.h
===
--- net-2.6.24.orig/include/linux/tty.h 2007-09-20 18:48:21.0 +0200
+++ net-2.6.24/include/linux/tty.h  2007-09-20 18:48:57.0 +0200
@@ -24,7 +24,7 @@
 #define NR_PTYSCONFIG_LEGACY_PTY_COUNT   /* Number of legacy ptys */
 #define NR_UNIX98_PTY_DEFAULT  4096  /* Default maximum for Unix98 ptys */
 #define NR_UNIX98_PTY_MAX  (1  MINORBITS) /* Absolute limit */
-#define NR_LDISCS  17
+#define NR_LDISCS  18
 
 /* line disciplines */
 #define N_TTY  0
@@ -45,6 +45,7 @@
 #define N_SYNC_PPP 14  /* synchronous PPP */
 #define N_HCI  15  /* Bluetooth HCI UART */
 #define N_GIGASET_M101 16  /* Siemens Gigaset M101 serial DECT adapter */
+#define N_SLCAN17  /* Serial / USB serial CAN Adaptors */
 
 /*
  * This character is the same as _POSIX_VDISABLE: it cannot be used as
Index: net-2.6.24/net/core/sock.c
===
--- net-2.6.24.orig/net/core/sock.c 2007-09-20 18:48:21.0 +0200
+++ net-2.6.24/net/core/sock.c  2007-09-20 18:48:57.0 +0200
@@ -154,7 +154,7 @@
   sk_lock-AF_ASH   , sk_lock-AF_ECONET   , sk_lock-AF_ATMSVC   ,
   sk_lock-21   , sk_lock-AF_SNA  , sk_lock-AF_IRDA ,
   sk_lock-AF_PPPOX , sk_lock-AF_WANPIPE  , sk_lock-AF_LLC  ,
-  sk_lock-27   , sk_lock-28  , sk_lock-29  ,
+  sk_lock-27   , sk_lock-28  , sk_lock-AF_CAN  ,
   sk_lock-AF_TIPC  , sk_lock-AF_BLUETOOTH, sk_lock-IUCV,
   sk_lock-AF_RXRPC , sk_lock-AF_MAX
 };
@@ -168,7 +168,7 @@
   slock-AF_ASH   , slock-AF_ECONET   , slock-AF_ATMSVC   ,
   slock-21   , slock-AF_SNA  , slock-AF_IRDA ,
   slock-AF_PPPOX , slock-AF_WANPIPE  , slock-AF_LLC  ,
-  slock-27   , slock-28  , slock-29  ,
+  slock-27   , slock

[PATCH 7/7] CAN: Add documentation

2007-09-20 Thread Urs Thuermann
This patch adds documentation for the PF_CAN protocol family.

Signed-off-by: Oliver Hartkopp [EMAIL PROTECTED]
Signed-off-by: Urs Thuermann [EMAIL PROTECTED]

---
 Documentation/networking/00-INDEX |2 
 Documentation/networking/can.txt  |  635 ++
 2 files changed, 637 insertions(+)

Index: net-2.6.24/Documentation/networking/can.txt
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ net-2.6.24/Documentation/networking/can.txt 2007-09-20 18:49:01.0 
+0200
@@ -0,0 +1,635 @@
+
+
+can.txt
+
+Readme file for the Controller Area Network Protocol Family (aka Socket CAN)
+
+This file contains
+
+  1 Overview / What is Socket CAN
+
+  2 Motivation / Why using the socket API
+
+  3 Socket CAN concept
+3.1 receive lists
+3.2 loopback
+3.3 network security issues (capabilities)
+3.4 network problem notifications
+
+  4 How to use Socket CAN
+4.1 RAW protocol sockets with can_filters (SOCK_RAW)
+  4.1.1 RAW socket option CAN_RAW_FILTER
+  4.1.2 RAW socket option CAN_RAW_ERR_FILTER
+  4.1.3 RAW socket option CAN_RAW_LOOPBACK
+  4.1.4 RAW socket option CAN_RAW_RECV_OWN_MSGS
+4.2 Broadcast Manager protocol sockets (SOCK_DGRAM)
+4.3 connected transport protocols (SOCK_SEQPACKET)
+4.4 unconnected transport protocols (SOCK_DGRAM)
+
+  5 Socket CAN core module
+5.1 can.ko module params
+5.2 procfs content
+5.3 writing own CAN protocol modules
+
+  6 CAN network drivers
+6.1 general settings
+6.2 loopback
+6.3 CAN controller hardware filters
+6.4 currently supported CAN hardware
+6.5 todo
+
+  7 Credits
+
+
+
+1. Overview / What is Socket CAN
+
+
+The socketcan package is an implementation of CAN protocols
+(Controller Area Network) for Linux.  CAN is a networking technology
+which has widespread use in automation, embedded devices, and
+automotive fields.  While there have been other CAN implementations
+for Linux based on character devices, Socket CAN uses the Berkeley
+socket API, the Linux network stack and implements the CAN device
+drivers as network interfaces.  The CAN socket API has been designed
+as similar as possible to the TCP/IP protocols to allow programmers,
+familiar with network programming, to easily learn how to use CAN
+sockets.
+
+2. Motivation / Why using the socket API
+
+
+There have been CAN implementations for Linux before Socket CAN so the
+question arises, why we have started another project.  Most existing
+implementations come as a device driver for some CAN hardware, they
+are based on character devices and provide comparatively little
+functionality.  Usually, there is only a hardware-specific device
+driver which provides a character device interface to send and
+receive raw CAN frames, directly to/from the controller hardware.
+Queueing of frames and higher-level transport protocols like ISO-TP
+have to be implemented in user space applications.  Also, most
+character-device implementations support only one single process to
+open the device at a time, similar to a serial interface.  Exchanging
+the CAN controller requires employment of another device driver and
+often the need for adaption of large parts of the application to the
+new driver's API.
+
+Socket CAN was designed to overcome all of these limitations.  A new
+protocol family has been implemented which provides a socket interface
+to user space applications and which builds upon the Linux network
+layer, so to use all of the provided queueing functionality.  A device
+driver for CAN controller hardware registers itself with the Linux
+network layer as a network device, so that CAN frames from the
+controller can be passed up to the network layer and on to the CAN
+protocol family module and also vice-versa.  Also, the protocol family
+module provides an API for transport protocol modules to register, so
+that any number of transport protocols can be loaded or unloaded
+dynamically.  In fact, the can core module alone does not provide any
+protocol and cannot be used without loading at least one additional
+protocol module.  Multiple sockets can be opened at the same time,
+on different or the same protocol module and they can listen/send
+frames on different or the same CAN IDs.  Several sockets listening on
+the same interface for frames with the same CAN ID are all passed the
+same received matching CAN frames.  An application wishing to
+communicate using a specific transport protocol, e.g. ISO-TP, just
+selects that protocol when opening the socket, and then can read and
+write application data byte streams, without having to deal with
+CAN-IDs, frames, etc.
+
+Similar functionality visible from user-space

[PATCH 0/7] CAN: Add new PF_CAN protocol family, try #7

2007-09-20 Thread Urs Thuermann
Hello Dave, hello Patrick,

this is the seventh post of the patch series that adds the PF_CAN
protocol family for the Controller Area Network.

Since our last post we have changed the following:

* Changes suggested by Patrick:
  - protect proto_tab[] by a lock.
  - add _rcu to some hlist traversals.
  - use printk_ratelimit() for module autoload failures.
  - make can_proto_unregister() and can_rx_unregister() return void.
  - use return value of can_proto_register() and can_rx_register()
(this also removed a flaw in behavior of raw_bind() and raw_setsockopt()
 in case of failure to can_rx_register() their filters).
  - call kzalloc() with GFP_KERNEL in case NETDEV_REGISTER.
  - use round_jiffies() to calculate expiration times.
  - make some variables static and/or __read_mostly.
  - in can_create() check for net namespace before auto loading modules.
  - add build time check for struct sizes.
  - use skb_share_chack() in vcan.
  - fixed some comments.
* Typos in documentation as pointed out by Randy Dunlap and Bill Fink.

The changes in try #6 were:

* Update code to work with namespaces in net-2.6.24.
* Remove SET_MODULE_OWNER() from vcan.

The changes in try #5 were:

* Remove slab destructor from calls to kmem_cache_alloc().
* Add comments about types defined in can.h.
* Update comment on vcan loopback module parameter.
* Fix typo in documentation.

The changes in try #4 were:

* Change vcan network driver to use the new RTNL API, as suggested by
  Patrick.
* Revert our change to use skb-iif instead of skb-cb.  After
  discussion with Patrick and Jamal it turned out, our first
  implementation was correct.
* Use skb_tail_pointer() instead of skb-tail directly.
* Coding style changes to satisfy linux/scripts/checkpatch.pl.
* Minor changes for 64-bit-cleanliness.
* Minor cleanup of #include's

The changes in try #3 were:

* Use sbk-sk and skb-pkt_type instead of skb-cb to pass loopback
  flags and originating socket down to the driver and back to the
  receiving socket.  Thanks to Patrick McHardy for pointing out our
  wrong use of sbk-cb.
* Use skb-iif instead of skb-cb to pass receiving interface from
  raw_rcv() and bcm_rcv() up to raw_recvmsg() and bcm_recvmsg().
* Set skb-protocol when sending CAN frames to netdevices.
* Removed struct raw_opt and struct bcm_opt and integrated these
  directly into struct raw_sock and bcm_sock resp., like most other
  proto implementations do.
* We have found and fixed race conditions between raw_bind(),
  raw_{set,get}sockopt() and raw_notifier().  This resulted in
  - complete removal of our own notifier list infrastructure in
af_can.c.  raw.c and bcm.c now use normal netdevice notifiers.
  - removal of ro-lock spinlock.  We use lock_sock(sk) now.
  - changed deletion of dev_rcv_lists, which are now marked for
deletion in the netdevice notifier in af_can.c and are actually
deleted when all entries have been deleted using can_rx_unregister().
* Follow changes in 2.6.22 (e.g. ktime_t timestamps in skb).
* Removed obsolete code from vcan.c, as pointed out by Stephen Hemminger.

The changes in try #2 were:

* reduced RCU callback overhead when deleting receiver lists (thx to
  feedback from Paul E. McKenney).
* eliminated some code duplication in net/can/proc.c.
* renamed slock-29 and sk_lock-29 to slock-AF_CAN and sk_lock-AF_CAN in
  net/core/sock.c
* added entry for can.txt in Documentation/networking/00-INDEX
* added error frame definitions in include/linux/can/error.h, which are to
  be used by CAN network drivers.


This patch series applies against net-2.6.24 and is derived from Subversion
revision r484 of http://svn.berlios.de/svnroot/repos/socketcan.
It can be found in the directory
http://svn.berlios.de/svnroot/repos/socketcan/trunk/patch-series/version.

Thanks very much for your work!

Best regards,

Urs Thuermann
Oliver Hartkopp


P.S. Greetings from some BSD and Linux users here at the LUG meeting in
 Braunschweig :-)
--
-
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 5/7] CAN: Add virtual CAN netdevice driver

2007-09-20 Thread Urs Thuermann
This patch adds the virtual CAN bus (vcan) network driver.
The vcan device is just a loopback device for CAN frames, no
real CAN hardware is involved.

Signed-off-by: Oliver Hartkopp [EMAIL PROTECTED]
Signed-off-by: Urs Thuermann [EMAIL PROTECTED]

---
 drivers/net/Makefile |1 
 drivers/net/can/Kconfig  |   25 +
 drivers/net/can/Makefile |5 +
 drivers/net/can/vcan.c   |  208 +++
 net/can/Kconfig  |3 
 5 files changed, 242 insertions(+)

Index: net-2.6.24/drivers/net/Makefile
===
--- net-2.6.24.orig/drivers/net/Makefile2007-09-20 18:48:21.0 
+0200
+++ net-2.6.24/drivers/net/Makefile 2007-09-20 18:49:00.0 +0200
@@ -10,6 +10,7 @@
 obj-$(CONFIG_CHELSIO_T1) += chelsio/
 obj-$(CONFIG_CHELSIO_T3) += cxgb3/
 obj-$(CONFIG_EHEA) += ehea/
+obj-$(CONFIG_CAN) += can/
 obj-$(CONFIG_BONDING) += bonding/
 obj-$(CONFIG_ATL1) += atl1/
 obj-$(CONFIG_GIANFAR) += gianfar_driver.o
Index: net-2.6.24/drivers/net/can/Kconfig
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ net-2.6.24/drivers/net/can/Kconfig  2007-09-20 18:49:00.0 +0200
@@ -0,0 +1,25 @@
+menu CAN Device Drivers
+   depends on CAN
+
+config CAN_VCAN
+   tristate Virtual Local CAN Interface (vcan)
+   depends on CAN
+   default N
+   ---help---
+ Similar to the network loopback devices, vcan offers a
+ virtual local CAN interface.
+
+ This driver can also be built as a module.  If so, the module
+ will be called vcan.
+
+config CAN_DEBUG_DEVICES
+   bool CAN devices debugging messages
+   depends on CAN
+   default N
+   ---help---
+ Say Y here if you want the CAN device drivers to produce a bunch of
+ debug messages to the system log.  Select this if you are having
+ a problem with CAN support and want to see more of what is going
+ on.
+
+endmenu
Index: net-2.6.24/drivers/net/can/Makefile
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ net-2.6.24/drivers/net/can/Makefile 2007-09-20 18:49:00.0 +0200
@@ -0,0 +1,5 @@
+#
+#  Makefile for the Linux Controller Area Network drivers.
+#
+
+obj-$(CONFIG_CAN_VCAN) += vcan.o
Index: net-2.6.24/drivers/net/can/vcan.c
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ net-2.6.24/drivers/net/can/vcan.c   2007-09-20 18:49:00.0 +0200
@@ -0,0 +1,208 @@
+/*
+ * vcan.c - Virtual CAN interface
+ *
+ * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
+ * All rights reserved.
+ *
+ * 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, the following disclaimer and
+ *the referenced file 'COPYING'.
+ * 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. Neither the name of Volkswagen nor the names of its contributors
+ *may be used to endorse or promote products derived from this software
+ *without specific prior written permission.
+ *
+ * Alternatively, provided that this notice is retained in full, this
+ * software may be distributed under the terms of the GNU General
+ * Public License (GPL) version 2 as distributed in the 'COPYING'
+ * file from the main directory of the linux kernel source.
+ *
+ * The provided data structures and external interfaces from this code
+ * are not restricted to be used by modules with a GPL compatible license.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT
+ * OWNER 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.
+ *
+ * Send feedback to [EMAIL PROTECTED]
+ *
+ */
+
+#include linux/module.h
+#include linux/init.h
+#include linux/netdevice.h
+#include linux/if_arp.h
+#include linux/if_ether.h
+#include

[PATCH 4/7] CAN: Add broadcast manager (bcm) protocol

2007-09-20 Thread Urs Thuermann
This patch adds the CAN broadcast manager (bcm) protocol.

Signed-off-by: Oliver Hartkopp [EMAIL PROTECTED]
Signed-off-by: Urs Thuermann [EMAIL PROTECTED]

---
 include/linux/can/bcm.h |   65 +
 net/can/Kconfig |   28 
 net/can/Makefile|3 
 net/can/bcm.c   | 1784 
 4 files changed, 1880 insertions(+)

Index: net-2.6.24/include/linux/can/bcm.h
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ net-2.6.24/include/linux/can/bcm.h  2007-09-20 18:48:59.0 +0200
@@ -0,0 +1,65 @@
+/*
+ * linux/can/bcm.h
+ *
+ * Definitions for CAN Broadcast Manager (BCM)
+ *
+ * Author: Oliver Hartkopp [EMAIL PROTECTED]
+ * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
+ * All rights reserved.
+ *
+ * Send feedback to [EMAIL PROTECTED]
+ *
+ */
+
+#ifndef CAN_BCM_H
+#define CAN_BCM_H
+
+/**
+ * struct bcm_msg_head - head of messages to/from the broadcast manager
+ * @opcode:opcode, see enum below.
+ * @flags: special flags, see below.
+ * @count: number of frames to send before changing interval.
+ * @ival1: interval for the first @count frames.
+ * @ival2: interval for the following frames.
+ * @can_id:CAN ID of frames to be sent or received.
+ * @nframes:   number of frames appended to the message head.
+ * @frames:array of CAN frames.
+ */
+struct bcm_msg_head {
+   int opcode;
+   int flags;
+   int count;
+   struct timeval ival1, ival2;
+   canid_t can_id;
+   int nframes;
+   struct can_frame frames[0];
+};
+
+enum {
+   TX_SETUP = 1,   /* create (cyclic) transmission task */
+   TX_DELETE,  /* remove (cyclic) transmission task */
+   TX_READ,/* read properties of (cyclic) transmission task */
+   TX_SEND,/* send one CAN frame */
+   RX_SETUP,   /* create RX content filter subscription */
+   RX_DELETE,  /* remove RX content filter subscription */
+   RX_READ,/* read properties of RX content filter subscription */
+   TX_STATUS,  /* reply to TX_READ request */
+   TX_EXPIRED, /* notification on performed transmissions (count=0) */
+   RX_STATUS,  /* reply to RX_READ request */
+   RX_TIMEOUT, /* cyclic message is absent */
+   RX_CHANGED  /* updated CAN frame (detected content change) */
+};
+
+#define SETTIMER0x0001
+#define STARTTIMER  0x0002
+#define TX_COUNTEVT 0x0004
+#define TX_ANNOUNCE 0x0008
+#define TX_CP_CAN_ID0x0010
+#define RX_FILTER_ID0x0020
+#define RX_CHECK_DLC0x0040
+#define RX_NO_AUTOTIMER 0x0080
+#define RX_ANNOUNCE_RESUME  0x0100
+#define TX_RESET_MULTI_IDX  0x0200
+#define RX_RTR_FRAME0x0400
+
+#endif /* CAN_BCM_H */
Index: net-2.6.24/net/can/Kconfig
===
--- net-2.6.24.orig/net/can/Kconfig 2007-09-20 18:48:59.0 +0200
+++ net-2.6.24/net/can/Kconfig  2007-09-20 18:48:59.0 +0200
@@ -42,6 +42,34 @@
  Say Y here if you want non-root users to be able to access CAN_RAW
  sockets.
 
+config CAN_BCM
+   tristate Broadcast Manager CAN Protocol (with content filtering)
+   depends on CAN
+   default N
+   ---help---
+ The Broadcast Manager offers content filtering, timeout monitoring,
+ sending of RTR-frames and cyclic CAN messages without permanent user
+ interaction. The BCM can be 'programmed' via the BSD socket API and
+ informs you on demand e.g. only on content updates / timeouts.
+ You probably want to use the bcm socket in most cases where cyclic
+ CAN messages are used on the bus (e.g. in automotive environments).
+ To use the Broadcast Manager, use AF_CAN with protocol CAN_BCM.
+
+config CAN_BCM_USER
+   bool Allow non-root users to access CAN broadcast manager sockets
+   depends on CAN_BCM
+   default N
+   ---help---
+ The Controller Area Network is a local field bus transmitting only
+ broadcast messages without any routing and security concepts.
+ In the majority of cases the user application has to deal with
+ raw CAN frames. Therefore it might be reasonable NOT to restrict
+ the CAN access only to the user root, as known from other networks.
+ Since CAN_BCM sockets can only send and receive frames to/from CAN
+ interfaces this does not affect security of others networks.
+ Say Y here if you want non-root users to be able to access CAN_BCM
+ sockets.
+
 config CAN_DEBUG_CORE
bool CAN Core debugging messages
depends on CAN
Index: net-2.6.24/net/can/Makefile
===
--- net-2.6.24.orig/net/can/Makefile2007-09-20 18:48:59.0 +0200
+++ net-2.6.24/net/can/Makefile

[PATCH 6/7] CAN: Add maintainer entries

2007-09-20 Thread Urs Thuermann
This patch adds entries in the CREDITS and MAINTAINERS file for CAN.

Signed-off-by: Oliver Hartkopp [EMAIL PROTECTED]
Signed-off-by: Urs Thuermann [EMAIL PROTECTED]

---
 CREDITS |   16 
 MAINTAINERS |9 +
 2 files changed, 25 insertions(+)

Index: net-2.6.24/CREDITS
===
--- net-2.6.24.orig/CREDITS 2007-09-20 18:48:21.0 +0200
+++ net-2.6.24/CREDITS  2007-09-20 18:49:00.0 +0200
@@ -1331,6 +1331,14 @@
 S: 5623 HZ Eindhoven
 S: The Netherlands
 
+N: Oliver Hartkopp
+E: [EMAIL PROTECTED]
+W: http://www.volkswagen.de
+D: Controller Area Network (network layer core)
+S: Brieffach 1776
+S: 38436 Wolfsburg
+S: Germany
+
 N: Andrew Haylett
 E: [EMAIL PROTECTED]
 D: Selection mechanism
@@ -3284,6 +3292,14 @@
 S: F-35042 Rennes Cedex
 S: France
 
+N: Urs Thuermann
+E: [EMAIL PROTECTED]
+W: http://www.volkswagen.de
+D: Controller Area Network (network layer core)
+S: Brieffach 1776
+S: 38436 Wolfsburg
+S: Germany
+
 N: Jon Tombs
 E: [EMAIL PROTECTED]
 W: http://www.esi.us.es/~jon
Index: net-2.6.24/MAINTAINERS
===
--- net-2.6.24.orig/MAINTAINERS 2007-09-20 18:48:21.0 +0200
+++ net-2.6.24/MAINTAINERS  2007-09-20 18:49:00.0 +0200
@@ -975,6 +975,15 @@
 L: [EMAIL PROTECTED]
 S: Maintained
 
+CAN NETWORK LAYER
+P: Urs Thuermann
+M: [EMAIL PROTECTED]
+P: Oliver Hartkopp
+M: [EMAIL PROTECTED]
+L: [EMAIL PROTECTED]
+W: http://developer.berlios.de/projects/socketcan/
+S: Maintained
+
 CALGARY x86-64 IOMMU
 P: Muli Ben-Yehuda
 M: [EMAIL PROTECTED]

--
-
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 7/7] CAN: Add documentation

2007-09-18 Thread Urs Thuermann
Bill Fink [EMAIL PROTECTED] writes:

 One more typo.

 decive - device above.

Thank you.  It's fixed now.

urs
-
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: e1000 driver and samba

2007-09-18 Thread Urs Thuermann
Bill Fink [EMAIL PROTECTED] writes:

 It may also be a useful test to disable hardware TSO support
 via ethtool -K ethX tso off.

All suggestions here on the list, i.e. checking for flow control,
duplex, cable problems, etc. don't explain (at least to me) why LF
sees file corruption.  How can a corrupted frame pass the TCP checksum
check?  Does TCP use the hardware checksum of the NIC if available?
AFAICS, this would be the only way for a corrupt frame to make it into
the file.  But Bill already suggested this and LF reported that it
didn't make a difference.

A few months ago I had hadware problems with an embedded device, where
transmission from the NIC via the PCI bus to the CPU had some bits
flipped.  But tcpdump clearly showed the TCP checksum errors and also
TCP recognized the errors and the connection was stalled.  And, BTW,
we also observed an increasing percentage of corrupted frames with
increasing traffic on that interface, i.e. increasing load on the PCI
bus.

So I would run tcpdump -s0 and watch for incorrect checksum messages.


urs
-
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/7] CAN: Add PF_CAN core module

2007-09-18 Thread Urs Thuermann
Patrick McHardy [EMAIL PROTECTED] writes:

 Looks pretty good, please see below for a few comments (mostly minor
 nitpicking, a few things that look like real bugs). Nothing that
 couldn't be fixed after merging though.

Thank you for your review.  I'll go through it and your other mail
this evening/tonight.  From a fast overview it looks like most issues
can be fixed/changed quite easily.

urs
-
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/7] CAN: Add PF_CAN core module

2007-09-18 Thread Urs Thuermann
Patrick McHardy [EMAIL PROTECTED] writes:

  +++ net-2.6.24/include/linux/can.h  2007-09-17 10:27:09.0 +0200

 Is this file used only from within the kernel? If so you could use
 the nicer-to-look-at u8/u16/u32 types instead of the double underscored
 ones.

No, this file contains the interface to user space.

  +++ net-2.6.24/include/linux/can/core.h 2007-09-17 11:08:39.0 
  +0200
  @@ -0,0 +1,78 @@
  +
  +extern int can_proto_register(struct can_proto *cp);
  +extern int can_proto_unregister(struct can_proto *cp);
 
 
 The callers of the unregister function don't check the return code,
 and they can't handle errors anyways since they use it in the
 module unload path, so making it void seems more appropriate
 (and maybe a WARN_ON for the not-found case).

These functions have been declared returning void originally, but in
the review process with Thomas we changed them since they can fail.
Even if the current users, i.e. raw.c and bcm.c don't use the return
value, others might do.  I therefore prefer to keep the int return
value.  Rather we should check whether we can do something useful with
the return value in raw.c and bcm.c.  At least we can put a WARN_ON
there.

 Same here, none of the callers check the return value and since
 they're all declared as void they can't propagate any errors back.

Same as above.

  +#include af_can.h
 
 
 It seems most of the things declared in that file are only used within
 af_can.c. Might be easier to read the code if you'd just move it over.

af_can.h declares the interface between af_can.c and proc.c.  There
should be nothing in af_can.h which is only used in af_can.c

  +int stats_timer = 1; /* default: on */
 
 
 This seems to be only used in af_can.c, so it could be static.
 __read_mostly also seems to be approriate.

Right.  Will be changed.

 There are a few more that look like they could be __read_mostly
 below, but I'll skip these since you probably know better than me.

Yes, I will check these also.

  +HLIST_HEAD(rx_dev_list);
 
 
 Same here (static).

Can't be static since it's used in proc.c.  But __read_mostly might
make sense.

What exactly is the effect of __read_mostly?  Is that in a separate
ELF section?  Where is that finally located?

  +   if (ret == -ENOSYS)
  +   printk(KERN_INFO can: request_module(%s) not
  +   implemented.\n, module_name);
  +   else if (ret)
  +   printk(KERN_ERR can: request_module(%s) failed\n,
  +  module_name);
 
 
 Both of these printks seem to be user-triggerable, so they should
 be rate-limited (or maybe get removed completely/changed to DBG).

Hm, I don't think DBG() would be right here, since the messages show
problems in the installation to the admin.  OTOH, I see that a user
can flood the log by opening sockets with invalid proto numbers.  Rate
limiting might solve this, or we should print the message only once
per proto number.  I will think about this.


  +   /* check for success and correct type */
  +   cp = proto_tab[protocol];
 
 
 What prevents the module from getting unloaded again (and using
 a stale pointer)?

When the module is unloaded it calls can_proto_unregister() which
clears the pointer.  Do you see a race condition here?

  +   if (!cp || cp-type != sock-type)
  +   return -EPROTONOSUPPORT;
  +
  +   if (net != init_net)
  +   return -EAFNOSUPPORT;
 
 
 Shouldn't this be done before attempting the module load?

Yes, you're right.

  +int can_send(struct sk_buff *skb, int loop)
  +{
  +   int err;
  +
  +   if (skb-dev-type != ARPHRD_CAN) {
  +   kfree_skb(skb);
  +   return -EPERM;
 
 
 EPERM doesn't seem like the best fit, but I don't have a better
 suggestion myself at the moment.

We have chosen EPERM because a user shouldn't be allowed to open a raw
CAN socket and then send arbitrary frames to other non-CAN interfaces.
This is also because the raw and bcm protocols can be configured to
grant access to non-root users.

  +   if (!(skb-dev-flags  IFF_LOOPBACK)) {
  +   /*
  +* If the interface is not capable to do loopback
  +* itself, we do it here.
  +*/
  +   struct sk_buff *newskb = skb_clone(skb, GFP_ATOMIC);
  +
  +   if (!newskb) {
  +   kfree_skb(skb);
  +   return -ENOMEM;
  +   }
  +
  +   newskb-sk = skb-sk;
  +   newskb-ip_summed = CHECKSUM_UNNECESSARY;
  +   newskb-pkt_type = PACKET_BROADCAST;
  +   netif_rx(newskb);
 
 
 So the intention here is to send the packet to the non-loopback device
 and manually loop it, which means sending it twice?

CAN is a broadcast message network, so every frame should be (usually)
sent to all receivers, on remote hosts and to all local sockets.  If
the driver 

Re: [PATCH 3/7] CAN: Add raw protocol

2007-09-18 Thread Urs Thuermann
Patrick McHardy [EMAIL PROTECTED] writes:

  +config CAN_RAW_USER
  +   bool Allow non-root users to access Raw CAN Protocol sockets
  +   depends on CAN_RAW
  +   default N
  +   ---help---
  + The Controller Area Network is a local field bus transmitting only
  + broadcast messages without any routing and security concepts.
  + In the majority of cases the user application has to deal with
  + raw CAN frames. Therefore it might be reasonable NOT to restrict
  + the CAN access only to the user root
 
 
 Would it be much more trouble for userspace to use capabilities for
 this? This would allow userspace to always know what to expect, I
 don't think distributions will enable this option (which might again
 not matter since they're probably rarely used in cars :)).

First, it's not only used in cars but also in other embedded and
automation contexts :-)

In fact, we already check capabilities in af_can.c:can_create() like
this

if (cp-capability = 0  !capable(cp-capability))
return -EPERM;

Each protocol implementation can set cp-capability to -1 so that all
users can open sockets without any restriction or to some capability,
typically CAP_NET_RAW.  In raw.c it is done so

#ifdef CONFIG_CAN_RAW_USER
#define RAW_CAP (-1)
#else
#define RAW_CAP CAP_NET_RAW
#endif

I also didn't love this configure option very much when we added it.
But in embedded systems it is often not much of a problem to let
anybody access raw sockets, since there are no normal users.  This
is the reason for the configure option.  I haven't yet looked into
capabilities and their inheritance between process in detail.   Would
it be easy to let all user space run with CAP_NET_RAW?  What if some
process calls setuid() or execve()s a set-uid program?  Will
capabilities be retained?

  +   addr = (struct sockaddr_can *)skb-cb;
  +   memset(addr, 0, sizeof(*addr));
  +   addr-can_family  = AF_CAN;
  +   addr-can_ifindex = skb-dev-ifindex;
 
 
 From a quick look it looks like there's more than enough space, but
 I guess a BUILD_BUG_ON(sizeof(skb-cb)  sizeof(struct sockaddr_can))
 in the module init path wouldn't hurt.

OK.  I didn't know about BUILD_BUG_ON.

  +   can_rx_register(dev, filter[i].can_id, filter[i].can_mask,
  +   raw_rcv, sk, IDENT);
 
 
 Shouldn't this check for errors?

Yes...

  +   can_rx_register(dev, 0, ro-err_mask | CAN_ERR_FLAG,
  +   raw_rcv, sk, IDENT);
 
 
 Same question here ..

and yes...

I talk(1)ed to Oliver an hour ago.  He will look at this.

  +static int raw_notifier(struct notifier_block *nb,
  +   unsigned long msg, void *data)
  +{
  +   struct net_device *dev = (struct net_device *)data;
  +   struct raw_sock *ro = container_of(nb, struct raw_sock, notifier);
  +   struct sock *sk = ro-sk;
  +
  +   DBG(msg %ld for dev %p (%s idx %d) sk %p ro-ifindex %d\n,
  +   msg, dev, dev-name, dev-ifindex, sk, ro-ifindex);
  +
  +   if (dev-nd_net != init_net)
  +   return NOTIFY_DONE;
  +
  +   if (dev-type != ARPHRD_CAN)
  +   return NOTIFY_DONE;
  +
  +   if (ro-ifindex != dev-ifindex)
  +   return NOTIFY_DONE;
 
 
 Wouldn't that be a BUG()?

Would it?  I think there is only one netdev_chain, not one per
device.  I.e. our raw_notifier() gets all events on any netdevice, not
only the ones we're interested in, for example also eth0.  And I think
we should silently ignore these events by returning NOTIFY_DONE.  Am I
missing something here?

urs
-
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 5/7] CAN: Add virtual CAN netdevice driver

2007-09-18 Thread Urs Thuermann
Patrick McHardy [EMAIL PROTECTED] writes:

  +static int loopback; /* loopback testing. Default: 0 (Off) */
  +module_param(loopback, int, S_IRUGO);
  +MODULE_PARM_DESC(loopback, Loop back frames (for testing). Default: 0 
  (Off));
 
 
 I would still prefer to have this on a per-device level configured
 through netlink, but since we currently don't support specifying
 flags for new devices anyways, I won't argue about it anymore
 (OTOH, if you'd agree I could send a patch to add this feature
 to the rtnl_link API).

Hm, somehow this topic comes up again and again.  I think there is
some misunderstanding about loopback in general and vcan, but I must
admit that our documentation until recently didn't describe this good
enough.  In fact, I think we also got better understanding from this
discussion and trying to explain this.

vcan is *not* a special loopback device like lo and it is not needed
to use PF_CAN.  Every CAN device driver should preferably loop back
frames sent by dev-hard_start_xmit() to netif_rx().  Since this is
unusual for netdevice drivers, the CAN core can do this itself as a
fallback for drivers that don't loopback.

For vcan it makes no difference whether loopback is done in the vcan
driver or in the CAN core.  No user will ever have to use this module
parameter.  Having a driver which can show both driver behaviors is
however useful for debugging our own code, to check whether the CAN
core does the right thing in both cases.

vcan is not a loopback device but a null device which simply discards
all sent frames since there is no hardware to send the frame to.  Like
other CAN drivers it can loop back the frame to the CAN core, but this
is not different from other CAN drivers.

It can be useful to have several vcan null devices so that different
apps can talk to each other through different interfaces.



Now I think we should consider removing the loopback code from
can_send() and demand from each CAN driver that it *has to* implement
this itself.

  +
  +struct vcan_priv {
  +   struct net_device *dev;
  +   struct list_head list;
  +};
 
 
 This is not needed anymore. The rtnl_link_unregister function calls
 the -dellink function for each device of this type. Check out the
 current dummy.c driver.

OK.

  +   if (atomic_read(skb-users) != 1) {
  +   struct sk_buff *old_skb = skb;
  +
  +   skb = skb_clone(old_skb, GFP_ATOMIC);
  +   DBG(KERN_INFO %s: %s: freeing old skbuff %p, 
  +   using new skbuff %p\n,
  +   dev-name, __FUNCTION__, old_skb, skb);
  +   kfree_skb(old_skb);
 
 skb_share_check()?

New to me.  I read that skb_share_check() decrements the refcount so I
am not sure it is we want.  Will take a look tomorrow.

  +   /* receive with packet counting */
  +   skb-sk = srcsk;
 
 
 Where is the socket used and what makes sure it still exists?

This socket pointer is used when the loopback frame is processed in
raw_rcv, only to compare it to the receiving socket to determine if
this frame was sent by the receiving socket itself.  The srcsk is only
compared, not dereferenced.

  +static void vcan_dellink(struct net_device *dev)
  +{
  +   struct vcan_priv *priv = netdev_priv(dev);
  +
  +   list_del(priv-list);
  +   unregister_netdevice(dev);
  +}
 
 
 Both the addlink and dellink function can be removed, the default
 for addlink is register_netdevice, the default for unregister
 is unregister_netdevice (and the list is not needed anymore as
 mentioned above).

OK, we'll remove them.

  +   rtnl_lock();
  +   err = __rtnl_link_register(vcan_link_ops);
  +   rtnl_unlock();
 
 
 Just using rtnl_link_register here is fine.

OK, we'll change that.

 and rtnl_link_unregister (without manual cleanup) here.

OK.

urs
-
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 6/7] CAN: Add maintainer entries

2007-09-17 Thread Urs Thuermann
This patch adds entries in the CREDITS and MAINTAINERS file for CAN.

Signed-off-by: Oliver Hartkopp [EMAIL PROTECTED]
Signed-off-by: Urs Thuermann [EMAIL PROTECTED]

---
 CREDITS |   16 
 MAINTAINERS |9 +
 2 files changed, 25 insertions(+)

Index: net-2.6.24/CREDITS
===
--- net-2.6.24.orig/CREDITS 2007-09-17 10:26:57.0 +0200
+++ net-2.6.24/CREDITS  2007-09-17 10:27:21.0 +0200
@@ -1331,6 +1331,14 @@
 S: 5623 HZ Eindhoven
 S: The Netherlands
 
+N: Oliver Hartkopp
+E: [EMAIL PROTECTED]
+W: http://www.volkswagen.de
+D: Controller Area Network (network layer core)
+S: Brieffach 1776
+S: 38436 Wolfsburg
+S: Germany
+
 N: Andrew Haylett
 E: [EMAIL PROTECTED]
 D: Selection mechanism
@@ -3284,6 +3292,14 @@
 S: F-35042 Rennes Cedex
 S: France
 
+N: Urs Thuermann
+E: [EMAIL PROTECTED]
+W: http://www.volkswagen.de
+D: Controller Area Network (network layer core)
+S: Brieffach 1776
+S: 38436 Wolfsburg
+S: Germany
+
 N: Jon Tombs
 E: [EMAIL PROTECTED]
 W: http://www.esi.us.es/~jon
Index: net-2.6.24/MAINTAINERS
===
--- net-2.6.24.orig/MAINTAINERS 2007-09-17 10:26:57.0 +0200
+++ net-2.6.24/MAINTAINERS  2007-09-17 10:27:21.0 +0200
@@ -975,6 +975,15 @@
 L: [EMAIL PROTECTED]
 S: Maintained
 
+CAN NETWORK LAYER
+P: Urs Thuermann
+M: [EMAIL PROTECTED]
+P: Oliver Hartkopp
+M: [EMAIL PROTECTED]
+L: [EMAIL PROTECTED]
+W: http://developer.berlios.de/projects/socketcan/
+S: Maintained
+
 CALGARY x86-64 IOMMU
 P: Muli Ben-Yehuda
 M: [EMAIL PROTECTED]

--
-
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 0/7] CAN: Add new PF_CAN protocol family, try #6

2007-09-17 Thread Urs Thuermann
Hello Dave,

this is the sixth post of the patch series that adds the PF_CAN
protocol family for the Controller Area Network.

Since our last post we have changed the following:

* Update code to work with namespaces in net-2.6.24.
* Remove SET_MODULE_OWNER() from vcan.

The changes in try #5 were:

* Remove slab destructor from calls to kmem_cache_alloc().
* Add comments about types defined in can.h.
* Update comment on vcan loopback module parameter.
* Fix typo in documentation.

The changes in try #4 were:

* Change vcan network driver to use the new RTNL API, as suggested by
  Patrick.
* Revert our change to use skb-iif instead of skb-cb.  After
  discussion with Patrick and Jamal it turned out, our first
  implementation was correct.
* Use skb_tail_pointer() instead of skb-tail directly.
* Coding style changes to satisfy linux/scripts/checkpatch.pl.
* Minor changes for 64-bit-cleanliness.
* Minor cleanup of #include's

The changes in try #3 were:

* Use sbk-sk and skb-pkt_type instead of skb-cb to pass loopback
  flags and originating socket down to the driver and back to the
  receiving socket.  Thanks to Patrick McHardy for pointing out our
  wrong use of sbk-cb.
* Use skb-iif instead of skb-cb to pass receiving interface from
  raw_rcv() and bcm_rcv() up to raw_recvmsg() and bcm_recvmsg().
* Set skb-protocol when sending CAN frames to netdevices.
* Removed struct raw_opt and struct bcm_opt and integrated these
  directly into struct raw_sock and bcm_sock resp., like most other
  proto implementations do.
* We have found and fixed race conditions between raw_bind(),
  raw_{set,get}sockopt() and raw_notifier().  This resulted in
  - complete removal of our own notifier list infrastructure in
af_can.c.  raw.c and bcm.c now use normal netdevice notifiers.
  - removal of ro-lock spinlock.  We use lock_sock(sk) now.
  - changed deletion of dev_rcv_lists, which are now marked for
deletion in the netdevice notifier in af_can.c and are actually
deleted when all entries have been deleted using can_rx_unregister().
* Follow changes in 2.6.22 (e.g. ktime_t timestamps in skb).
* Removed obsolete code from vcan.c, as pointed out by Stephen Hemminger.

The changes in try #2 were:

* reduced RCU callback overhead when deleting receiver lists (thx to
  feedback from Paul E. McKenney).
* eliminated some code duplication in net/can/proc.c.
* renamed slock-29 and sk_lock-29 to slock-AF_CAN and sk_lock-AF_CAN in
  net/core/sock.c
* added entry for can.txt in Documentation/networking/00-INDEX
* added error frame definitions in include/linux/can/error.h, which are to
  be used by CAN network drivers.


This patch series applies against net-2.6.24 and is derived from Subversion
revision r466 of http://svn.berlios.de/svnroot/repos/socketcan.
It can be found in the directory
http://svn.berlios.de/svnroot/repos/socketcan/trunk/patch-series/version.

This patch doesn't touch anything in the kernel except for the allocation
of a couple of numbers for protocol, arp hw type, and a line discipline.

Please review this patch series for integration into your tree.

Thanks very much for your work!

Best regards,

Urs Thuermann
Oliver Hartkopp
--
-
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 1/7] CAN: Allocate protocol numbers for PF_CAN

2007-09-17 Thread Urs Thuermann
This patch adds a protocol/address family number, ARP hardware type,
ethernet packet type, and a line discipline number for the SocketCAN
implementation.

Signed-off-by: Oliver Hartkopp [EMAIL PROTECTED]
Signed-off-by: Urs Thuermann [EMAIL PROTECTED]

---
 include/linux/if_arp.h   |1 +
 include/linux/if_ether.h |1 +
 include/linux/socket.h   |2 ++
 include/linux/tty.h  |3 ++-
 net/core/sock.c  |4 ++--
 5 files changed, 8 insertions(+), 3 deletions(-)

Index: net-2.6.24/include/linux/if_arp.h
===
--- net-2.6.24.orig/include/linux/if_arp.h  2007-09-17 10:26:58.0 
+0200
+++ net-2.6.24/include/linux/if_arp.h   2007-09-17 10:27:06.0 +0200
@@ -52,6 +52,7 @@
 #define ARPHRD_ROSE270
 #define ARPHRD_X25 271 /* CCITT X.25   */
 #define ARPHRD_HWX25   272 /* Boards with X.25 in firmware */
+#define ARPHRD_CAN 280 /* Controller Area Network  */
 #define ARPHRD_PPP 512
 #define ARPHRD_CISCO   513 /* Cisco HDLC   */
 #define ARPHRD_HDLCARPHRD_CISCO
Index: net-2.6.24/include/linux/if_ether.h
===
--- net-2.6.24.orig/include/linux/if_ether.h2007-09-17 10:26:58.0 
+0200
+++ net-2.6.24/include/linux/if_ether.h 2007-09-17 10:27:06.0 +0200
@@ -90,6 +90,7 @@
 #define ETH_P_WAN_PPP   0x0007  /* Dummy type for WAN PPP frames*/
 #define ETH_P_PPP_MP0x0008  /* Dummy type for PPP MP frames */
 #define ETH_P_LOCALTALK 0x0009 /* Localtalk pseudo type*/
+#define ETH_P_CAN  0x000C  /* Controller Area Network  */
 #define ETH_P_PPPTALK  0x0010  /* Dummy type for Atalk over PPP*/
 #define ETH_P_TR_802_2 0x0011  /* 802.2 frames */
 #define ETH_P_MOBITEX  0x0015  /* Mobitex ([EMAIL PROTECTED])  */
Index: net-2.6.24/include/linux/socket.h
===
--- net-2.6.24.orig/include/linux/socket.h  2007-09-17 10:26:58.0 
+0200
+++ net-2.6.24/include/linux/socket.h   2007-09-17 10:27:06.0 +0200
@@ -185,6 +185,7 @@
 #define AF_PPPOX   24  /* PPPoX sockets*/
 #define AF_WANPIPE 25  /* Wanpipe API Sockets */
 #define AF_LLC 26  /* Linux LLC*/
+#define AF_CAN 29  /* Controller Area Network  */
 #define AF_TIPC30  /* TIPC sockets */
 #define AF_BLUETOOTH   31  /* Bluetooth sockets*/
 #define AF_IUCV32  /* IUCV sockets */
@@ -220,6 +221,7 @@
 #define PF_PPPOX   AF_PPPOX
 #define PF_WANPIPE AF_WANPIPE
 #define PF_LLC AF_LLC
+#define PF_CAN AF_CAN
 #define PF_TIPCAF_TIPC
 #define PF_BLUETOOTH   AF_BLUETOOTH
 #define PF_IUCVAF_IUCV
Index: net-2.6.24/include/linux/tty.h
===
--- net-2.6.24.orig/include/linux/tty.h 2007-09-17 10:26:58.0 +0200
+++ net-2.6.24/include/linux/tty.h  2007-09-17 10:27:06.0 +0200
@@ -24,7 +24,7 @@
 #define NR_PTYSCONFIG_LEGACY_PTY_COUNT   /* Number of legacy ptys */
 #define NR_UNIX98_PTY_DEFAULT  4096  /* Default maximum for Unix98 ptys */
 #define NR_UNIX98_PTY_MAX  (1  MINORBITS) /* Absolute limit */
-#define NR_LDISCS  17
+#define NR_LDISCS  18
 
 /* line disciplines */
 #define N_TTY  0
@@ -45,6 +45,7 @@
 #define N_SYNC_PPP 14  /* synchronous PPP */
 #define N_HCI  15  /* Bluetooth HCI UART */
 #define N_GIGASET_M101 16  /* Siemens Gigaset M101 serial DECT adapter */
+#define N_SLCAN17  /* Serial / USB serial CAN Adaptors */
 
 /*
  * This character is the same as _POSIX_VDISABLE: it cannot be used as
Index: net-2.6.24/net/core/sock.c
===
--- net-2.6.24.orig/net/core/sock.c 2007-09-17 10:26:58.0 +0200
+++ net-2.6.24/net/core/sock.c  2007-09-17 10:27:06.0 +0200
@@ -154,7 +154,7 @@
   sk_lock-AF_ASH   , sk_lock-AF_ECONET   , sk_lock-AF_ATMSVC   ,
   sk_lock-21   , sk_lock-AF_SNA  , sk_lock-AF_IRDA ,
   sk_lock-AF_PPPOX , sk_lock-AF_WANPIPE  , sk_lock-AF_LLC  ,
-  sk_lock-27   , sk_lock-28  , sk_lock-29  ,
+  sk_lock-27   , sk_lock-28  , sk_lock-AF_CAN  ,
   sk_lock-AF_TIPC  , sk_lock-AF_BLUETOOTH, sk_lock-IUCV,
   sk_lock-AF_RXRPC , sk_lock-AF_MAX
 };
@@ -168,7 +168,7 @@
   slock-AF_ASH   , slock-AF_ECONET   , slock-AF_ATMSVC   ,
   slock-21   , slock-AF_SNA  , slock-AF_IRDA ,
   slock-AF_PPPOX , slock-AF_WANPIPE  , slock-AF_LLC  ,
-  slock-27   , slock-28  , slock-29  ,
+  slock-27   , slock

[PATCH 5/7] CAN: Add virtual CAN netdevice driver

2007-09-17 Thread Urs Thuermann
This patch adds the virtual CAN bus (vcan) network driver.
The vcan device is just a loopback device for CAN frames, no
real CAN hardware is involved.

Signed-off-by: Oliver Hartkopp [EMAIL PROTECTED]
Signed-off-by: Urs Thuermann [EMAIL PROTECTED]

---
 drivers/net/Makefile |1 
 drivers/net/can/Kconfig  |   25 
 drivers/net/can/Makefile |5 
 drivers/net/can/vcan.c   |  260 +++
 net/can/Kconfig  |3 
 5 files changed, 294 insertions(+)

Index: net-2.6.24/drivers/net/Makefile
===
--- net-2.6.24.orig/drivers/net/Makefile2007-09-17 10:30:35.0 
+0200
+++ net-2.6.24/drivers/net/Makefile 2007-09-17 11:13:45.0 +0200
@@ -10,6 +10,7 @@
 obj-$(CONFIG_CHELSIO_T1) += chelsio/
 obj-$(CONFIG_CHELSIO_T3) += cxgb3/
 obj-$(CONFIG_EHEA) += ehea/
+obj-$(CONFIG_CAN) += can/
 obj-$(CONFIG_BONDING) += bonding/
 obj-$(CONFIG_ATL1) += atl1/
 obj-$(CONFIG_GIANFAR) += gianfar_driver.o
Index: net-2.6.24/drivers/net/can/Kconfig
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ net-2.6.24/drivers/net/can/Kconfig  2007-09-17 11:13:45.0 +0200
@@ -0,0 +1,25 @@
+menu CAN Device Drivers
+   depends on CAN
+
+config CAN_VCAN
+   tristate Virtual Local CAN Interface (vcan)
+   depends on CAN
+   default N
+   ---help---
+ Similar to the network loopback devices, vcan offers a
+ virtual local CAN interface.
+
+ This driver can also be built as a module.  If so, the module
+ will be called vcan.
+
+config CAN_DEBUG_DEVICES
+   bool CAN devices debugging messages
+   depends on CAN
+   default N
+   ---help---
+ Say Y here if you want the CAN device drivers to produce a bunch of
+ debug messages to the system log.  Select this if you are having
+ a problem with CAN support and want to see more of what is going
+ on.
+
+endmenu
Index: net-2.6.24/drivers/net/can/Makefile
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ net-2.6.24/drivers/net/can/Makefile 2007-09-17 11:13:45.0 +0200
@@ -0,0 +1,5 @@
+#
+#  Makefile for the Linux Controller Area Network drivers.
+#
+
+obj-$(CONFIG_CAN_VCAN) += vcan.o
Index: net-2.6.24/drivers/net/can/vcan.c
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ net-2.6.24/drivers/net/can/vcan.c   2007-09-17 11:17:45.0 +0200
@@ -0,0 +1,260 @@
+/*
+ * vcan.c - Virtual CAN interface
+ *
+ * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
+ * All rights reserved.
+ *
+ * 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, the following disclaimer and
+ *the referenced file 'COPYING'.
+ * 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. Neither the name of Volkswagen nor the names of its contributors
+ *may be used to endorse or promote products derived from this software
+ *without specific prior written permission.
+ *
+ * Alternatively, provided that this notice is retained in full, this
+ * software may be distributed under the terms of the GNU General
+ * Public License (GPL) version 2 as distributed in the 'COPYING'
+ * file from the main directory of the linux kernel source.
+ *
+ * The provided data structures and external interfaces from this code
+ * are not restricted to be used by modules with a GPL compatible license.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT
+ * OWNER 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.
+ *
+ * Send feedback to [EMAIL PROTECTED]
+ *
+ */
+
+#include linux/module.h
+#include linux/init.h
+#include linux/netdevice.h
+#include linux/if_arp.h
+#include linux/if_ether.h
+#include linux

[PATCH 3/7] CAN: Add raw protocol

2007-09-17 Thread Urs Thuermann
This patch adds the CAN raw protocol.

Signed-off-by: Oliver Hartkopp [EMAIL PROTECTED]
Signed-off-by: Urs Thuermann [EMAIL PROTECTED]

---
 include/linux/can/raw.h |   31 +
 net/can/Kconfig |   26 +
 net/can/Makefile|3 
 net/can/raw.c   |  767 
 4 files changed, 827 insertions(+)

Index: net-2.6.24/include/linux/can/raw.h
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ net-2.6.24/include/linux/can/raw.h  2007-09-17 11:10:10.0 +0200
@@ -0,0 +1,31 @@
+/*
+ * linux/can/raw.h
+ *
+ * Definitions for raw CAN sockets
+ *
+ * Authors: Oliver Hartkopp [EMAIL PROTECTED]
+ *  Urs Thuermann   [EMAIL PROTECTED]
+ * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
+ * All rights reserved.
+ *
+ * Send feedback to [EMAIL PROTECTED]
+ *
+ */
+
+#ifndef CAN_RAW_H
+#define CAN_RAW_H
+
+#include linux/can.h
+
+#define SOL_CAN_RAW (SOL_CAN_BASE + CAN_RAW)
+
+/* for socket options affecting the socket (not the global system) */
+
+enum {
+   CAN_RAW_FILTER = 1, /* set 0 .. n can_filter(s)  */
+   CAN_RAW_ERR_FILTER, /* set filter for error frames   */
+   CAN_RAW_LOOPBACK,   /* local loopback (default:on)   */
+   CAN_RAW_RECV_OWN_MSGS   /* receive my own msgs (default:off) */
+};
+
+#endif
Index: net-2.6.24/net/can/Kconfig
===
--- net-2.6.24.orig/net/can/Kconfig 2007-09-17 10:30:35.0 +0200
+++ net-2.6.24/net/can/Kconfig  2007-09-17 11:10:10.0 +0200
@@ -16,6 +16,32 @@
  If you want CAN support, you should say Y here and also to the
  specific driver for your controller(s) below.
 
+config CAN_RAW
+   tristate Raw CAN Protocol (raw access with CAN-ID filtering)
+   depends on CAN
+   default N
+   ---help---
+ The Raw CAN protocol option offers access to the CAN bus via
+ the BSD socket API. You probably want to use the raw socket in
+ most cases where no higher level protocol is being used. The raw
+ socket has several filter options e.g. ID-Masking / Errorframes.
+ To receive/send raw CAN messages, use AF_CAN with protocol CAN_RAW.
+
+config CAN_RAW_USER
+   bool Allow non-root users to access Raw CAN Protocol sockets
+   depends on CAN_RAW
+   default N
+   ---help---
+ The Controller Area Network is a local field bus transmitting only
+ broadcast messages without any routing and security concepts.
+ In the majority of cases the user application has to deal with
+ raw CAN frames. Therefore it might be reasonable NOT to restrict
+ the CAN access only to the user root, as known from other networks.
+ Since CAN_RAW sockets can only send and receive frames to/from CAN
+ interfaces this does not affect security of others networks.
+ Say Y here if you want non-root users to be able to access CAN_RAW
+ sockets.
+
 config CAN_DEBUG_CORE
bool CAN Core debugging messages
depends on CAN
Index: net-2.6.24/net/can/Makefile
===
--- net-2.6.24.orig/net/can/Makefile2007-09-17 10:30:35.0 +0200
+++ net-2.6.24/net/can/Makefile 2007-09-17 11:10:10.0 +0200
@@ -4,3 +4,6 @@
 
 obj-$(CONFIG_CAN)  += can.o
 can-objs   := af_can.o proc.o
+
+obj-$(CONFIG_CAN_RAW)  += can-raw.o
+can-raw-objs   := raw.o
Index: net-2.6.24/net/can/raw.c
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ net-2.6.24/net/can/raw.c2007-09-17 11:11:10.0 +0200
@@ -0,0 +1,767 @@
+/*
+ * raw.c - Raw sockets for protocol family CAN
+ *
+ * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
+ * All rights reserved.
+ *
+ * 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, the following disclaimer and
+ *the referenced file 'COPYING'.
+ * 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. Neither the name of Volkswagen nor the names of its contributors
+ *may be used to endorse or promote products derived from this software
+ *without specific prior written permission.
+ *
+ * Alternatively, provided that this notice is retained in full, this
+ * software may be distributed under the terms of the GNU General
+ * Public License (GPL) version 2 as distributed in the 'COPYING'
+ * file from the main directory

[PATCH 7/7] CAN: Add documentation

2007-09-17 Thread Urs Thuermann
This patch adds documentation for the PF_CAN protocol family.

Signed-off-by: Oliver Hartkopp [EMAIL PROTECTED]
Signed-off-by: Urs Thuermann [EMAIL PROTECTED]

---
 Documentation/networking/00-INDEX |2 
 Documentation/networking/can.txt  |  635 ++
 2 files changed, 637 insertions(+)

Index: net-2.6.24/Documentation/networking/can.txt
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ net-2.6.24/Documentation/networking/can.txt 2007-09-17 10:27:25.0 
+0200
@@ -0,0 +1,635 @@
+
+
+can.txt
+
+Readme file for the Controller Area Network Protocol Family (aka Socket CAN)
+
+This file contains
+
+  1 Overview / What is Socket CAN
+
+  2 Motivation / Why using the socket API
+
+  3 Socket CAN concept
+3.1 receive lists
+3.2 loopback
+3.3 network security issues (capabilities)
+3.4 network problem notifications
+
+  4 How to use Socket CAN
+4.1 RAW protocol sockets with can_filters (SOCK_RAW)
+  4.1.1 RAW socket option CAN_RAW_FILTER
+  4.1.2 RAW socket option CAN_RAW_ERR_FILTER
+  4.1.3 RAW socket option CAN_RAW_LOOPBACK
+  4.1.4 RAW socket option CAN_RAW_RECV_OWN_MSGS
+4.2 Broadcast Manager protocol sockets (SOCK_DGRAM)
+4.3 connected transport protocols (SOCK_SEQPACKET)
+4.4 unconnected transport protocols (SOCK_DGRAM)
+
+  5 Socket CAN core module
+5.1 can.ko module params
+5.2 procfs content
+5.3 writing own CAN protocol modules
+
+  6 CAN network drivers
+6.1 general settings
+6.2 loopback
+6.3 CAN controller hardware filters
+6.4 currently supported CAN hardware
+6.5 todo
+
+  7 Credits
+
+
+
+1. Overview / What is Socket CAN
+
+
+The socketcan package is an implementation of CAN protocols
+(Controller Area Network) for Linux.  CAN is a networking technology
+which has wide-spread use in automation, embedded devices, and
+automotive fields.  While there have been other CAN implementations
+for Linux based on character devices, Socket CAN uses the Berkeley
+socket API, the Linux network stack and implements the CAN device
+drivers as network interfaces.  The CAN socket API has been designed
+as similar as possible to the TCP/IP protocols to allow programmers,
+familiar with network programming, to easily learn how to use CAN
+sockets.
+
+2. Motivation / Why using the socket API
+
+
+There have been CAN implementations for Linux before Socket CAN so the
+question arises, why we have started another project.  Most existing
+implementations come as a device driver for some CAN hardware, they
+are based on character devices and provide comparatively little
+functionality.  Usually, there is only a hardware-specific device
+driver which provides a character device interface to send and
+receive raw CAN frames, directly to/from the controller hardware.
+Queueing of frames and higher-level transport protocols like ISO-TP
+have to be implemented in user space applications.  Also, most
+character-device implementations support only one single process to
+open the device at a time, similar to a serial interface.  Exchanging
+the CAN controller requires employment of another device driver and
+often the need for adaption of large parts of the application to the
+new driver's API.
+
+Socket CAN was designed to overcome all of these limitations.  A new
+protocol family has been implemented which provides a socket interface
+to user space applications and which builds upon the Linux network
+layer, so to use all of the provided queueing functionality.  Device
+drivers for CAN controller hardware register itself with the Linux
+network layer as a network device, so that CAN frames from the
+controller can be passed up to the network layer and on to the CAN
+protocol family module and also vice-versa.  Also, the protocol family
+module provides an API for transport protocol modules to register, so
+that any number of transport protocols can be loaded or unloaded
+dynamically.  In fact, the can core module alone does not provide any
+protocol and can not be used without loading at least one additional
+protocol module.  Multiple sockets can be opened at the same time,
+on different or the same protocol module and they can listen/send
+frames on different or the same CAN IDs.  Several sockets listening on
+the same interface for frames with the same CAN ID are all passed the
+same received matching CAN frames.  An application wishing to
+communicate using a specific transport protocol, e.g. ISO-TP, just
+selects that protocol when opening the socket, and then can read and
+write application data byte streams, without having to deal with
+CAN-IDs, frames, etc.
+
+Similar functionality visible from user-space

[PATCH 4/7] CAN: Add broadcast manager (bcm) protocol

2007-09-17 Thread Urs Thuermann
This patch adds the CAN broadcast manager (bcm) protocol.

Signed-off-by: Oliver Hartkopp [EMAIL PROTECTED]
Signed-off-by: Urs Thuermann [EMAIL PROTECTED]

---
 include/linux/can/bcm.h |   65 +
 net/can/Kconfig |   28 
 net/can/Makefile|3 
 net/can/bcm.c   | 1762 
 4 files changed, 1858 insertions(+)

Index: net-2.6.24/include/linux/can/bcm.h
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ net-2.6.24/include/linux/can/bcm.h  2007-09-17 11:12:30.0 +0200
@@ -0,0 +1,65 @@
+/*
+ * linux/can/bcm.h
+ *
+ * Definitions for CAN Broadcast Manager (BCM)
+ *
+ * Author: Oliver Hartkopp [EMAIL PROTECTED]
+ * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
+ * All rights reserved.
+ *
+ * Send feedback to [EMAIL PROTECTED]
+ *
+ */
+
+#ifndef CAN_BCM_H
+#define CAN_BCM_H
+
+/**
+ * struct bcm_msg_head - head of messages to/from the broadcast manager
+ * @opcode:opcode, see enum below.
+ * @flags: special flags, see below.
+ * @count: number of frames to send before changing interval.
+ * @ival1: interval for the first @count frames.
+ * @ival2: interval for the following frames.
+ * @can_id:CAN ID of frames to be sent or received.
+ * @nframes:   number of frames appended to the message head.
+ * @frames:array of CAN frames.
+ */
+struct bcm_msg_head {
+   int opcode;
+   int flags;
+   int count;
+   struct timeval ival1, ival2;
+   canid_t can_id;
+   int nframes;
+   struct can_frame frames[0];
+};
+
+enum {
+   TX_SETUP = 1,   /* create (cyclic) transmission task */
+   TX_DELETE,  /* remove (cyclic) transmission task */
+   TX_READ,/* read properties of (cyclic) transmission task */
+   TX_SEND,/* send one CAN frame */
+   RX_SETUP,   /* create RX content filter subscription */
+   RX_DELETE,  /* remove RX content filter subscription */
+   RX_READ,/* read properties of RX content filter subscription */
+   TX_STATUS,  /* reply to TX_READ request */
+   TX_EXPIRED, /* notification on performed transmissions (count=0) */
+   RX_STATUS,  /* reply to RX_READ request */
+   RX_TIMEOUT, /* cyclic message is absent */
+   RX_CHANGED  /* updated CAN frame (detected content change) */
+};
+
+#define SETTIMER0x0001
+#define STARTTIMER  0x0002
+#define TX_COUNTEVT 0x0004
+#define TX_ANNOUNCE 0x0008
+#define TX_CP_CAN_ID0x0010
+#define RX_FILTER_ID0x0020
+#define RX_CHECK_DLC0x0040
+#define RX_NO_AUTOTIMER 0x0080
+#define RX_ANNOUNCE_RESUME  0x0100
+#define TX_RESET_MULTI_IDX  0x0200
+#define RX_RTR_FRAME0x0400
+
+#endif /* CAN_BCM_H */
Index: net-2.6.24/net/can/Kconfig
===
--- net-2.6.24.orig/net/can/Kconfig 2007-09-17 11:10:10.0 +0200
+++ net-2.6.24/net/can/Kconfig  2007-09-17 11:12:30.0 +0200
@@ -42,6 +42,34 @@
  Say Y here if you want non-root users to be able to access CAN_RAW
  sockets.
 
+config CAN_BCM
+   tristate Broadcast Manager CAN Protocol (with content filtering)
+   depends on CAN
+   default N
+   ---help---
+ The Broadcast Manager offers content filtering, timeout monitoring,
+ sending of RTR-frames and cyclic CAN messages without permanent user
+ interaction. The BCM can be 'programmed' via the BSD socket API and
+ informs you on demand e.g. only on content updates / timeouts.
+ You probably want to use the bcm socket in most cases where cyclic
+ CAN messages are used on the bus (e.g. in automotive environments).
+ To use the Broadcast Manager, use AF_CAN with protocol CAN_BCM.
+
+config CAN_BCM_USER
+   bool Allow non-root users to access CAN broadcast manager sockets
+   depends on CAN_BCM
+   default N
+   ---help---
+ The Controller Area Network is a local field bus transmitting only
+ broadcast messages without any routing and security concepts.
+ In the majority of cases the user application has to deal with
+ raw CAN frames. Therefore it might be reasonable NOT to restrict
+ the CAN access only to the user root, as known from other networks.
+ Since CAN_BCM sockets can only send and receive frames to/from CAN
+ interfaces this does not affect security of others networks.
+ Say Y here if you want non-root users to be able to access CAN_BCM
+ sockets.
+
 config CAN_DEBUG_CORE
bool CAN Core debugging messages
depends on CAN
Index: net-2.6.24/net/can/Makefile
===
--- net-2.6.24.orig/net/can/Makefile2007-09-17 11:10:10.0 +0200
+++ net-2.6.24/net/can/Makefile

Re: [PATCH 7/7] CAN: Add documentation

2007-09-17 Thread Urs Thuermann
Hi Randy,

 Thanks for all of this informative documentation.
 
 I have some typo/spello corrections below.

Thank you very much.  I have applied all your suggestions to our SVN
repository.  To reduce traffic on the list, I only repeat the pointer
to the repository:

http://svn.berlios.de/svnroot/repos/socketcan/trunk/patch-series/net-2.6.24

If you request, I could send PATCH 7/7 on the list again.

urs
-
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 7/7] CAN: Add documentation

2007-09-17 Thread Urs Thuermann
Thomas Gleixner [EMAIL PROTECTED] writes:

 Please do, having the patch in mail makes it easier to review and to
 comment.

OK, here it is:



This patch adds documentation for the PF_CAN protocol family.

Signed-off-by: Oliver Hartkopp [EMAIL PROTECTED]
Signed-off-by: Urs Thuermann [EMAIL PROTECTED]

---
 Documentation/networking/00-INDEX |2 
 Documentation/networking/can.txt  |  635 ++
 2 files changed, 637 insertions(+)

Index: net-2.6.24/Documentation/networking/can.txt
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ net-2.6.24/Documentation/networking/can.txt 2007-09-17 21:57:29.0 
+0200
@@ -0,0 +1,635 @@
+
+
+can.txt
+
+Readme file for the Controller Area Network Protocol Family (aka Socket CAN)
+
+This file contains
+
+  1 Overview / What is Socket CAN
+
+  2 Motivation / Why using the socket API
+
+  3 Socket CAN concept
+3.1 receive lists
+3.2 loopback
+3.3 network security issues (capabilities)
+3.4 network problem notifications
+
+  4 How to use Socket CAN
+4.1 RAW protocol sockets with can_filters (SOCK_RAW)
+  4.1.1 RAW socket option CAN_RAW_FILTER
+  4.1.2 RAW socket option CAN_RAW_ERR_FILTER
+  4.1.3 RAW socket option CAN_RAW_LOOPBACK
+  4.1.4 RAW socket option CAN_RAW_RECV_OWN_MSGS
+4.2 Broadcast Manager protocol sockets (SOCK_DGRAM)
+4.3 connected transport protocols (SOCK_SEQPACKET)
+4.4 unconnected transport protocols (SOCK_DGRAM)
+
+  5 Socket CAN core module
+5.1 can.ko module params
+5.2 procfs content
+5.3 writing own CAN protocol modules
+
+  6 CAN network drivers
+6.1 general settings
+6.2 loopback
+6.3 CAN controller hardware filters
+6.4 currently supported CAN hardware
+6.5 todo
+
+  7 Credits
+
+
+
+1. Overview / What is Socket CAN
+
+
+The socketcan package is an implementation of CAN protocols
+(Controller Area Network) for Linux.  CAN is a networking technology
+which has widespread use in automation, embedded devices, and
+automotive fields.  While there have been other CAN implementations
+for Linux based on character devices, Socket CAN uses the Berkeley
+socket API, the Linux network stack and implements the CAN device
+drivers as network interfaces.  The CAN socket API has been designed
+as similar as possible to the TCP/IP protocols to allow programmers,
+familiar with network programming, to easily learn how to use CAN
+sockets.
+
+2. Motivation / Why using the socket API
+
+
+There have been CAN implementations for Linux before Socket CAN so the
+question arises, why we have started another project.  Most existing
+implementations come as a device driver for some CAN hardware, they
+are based on character devices and provide comparatively little
+functionality.  Usually, there is only a hardware-specific device
+driver which provides a character device interface to send and
+receive raw CAN frames, directly to/from the controller hardware.
+Queueing of frames and higher-level transport protocols like ISO-TP
+have to be implemented in user space applications.  Also, most
+character-device implementations support only one single process to
+open the device at a time, similar to a serial interface.  Exchanging
+the CAN controller requires employment of another device driver and
+often the need for adaption of large parts of the application to the
+new driver's API.
+
+Socket CAN was designed to overcome all of these limitations.  A new
+protocol family has been implemented which provides a socket interface
+to user space applications and which builds upon the Linux network
+layer, so to use all of the provided queueing functionality.  A device
+driver for CAN controller hardware registers itself with the Linux
+network layer as a network device, so that CAN frames from the
+controller can be passed up to the network layer and on to the CAN
+protocol family module and also vice-versa.  Also, the protocol family
+module provides an API for transport protocol modules to register, so
+that any number of transport protocols can be loaded or unloaded
+dynamically.  In fact, the can core module alone does not provide any
+protocol and cannot be used without loading at least one additional
+protocol module.  Multiple sockets can be opened at the same time,
+on different or the same protocol module and they can listen/send
+frames on different or the same CAN IDs.  Several sockets listening on
+the same interface for frames with the same CAN ID are all passed the
+same received matching CAN frames.  An application wishing to
+communicate using a specific transport protocol, e.g. ISO-TP, just
+selects that protocol when opening the socket, and then can read

Re: [PATCH 7/7] CAN: Add documentation

2007-09-17 Thread Urs Thuermann
Hi Randy,

 Just a few more minor changes...  Thanks again.

Again, thank you.  I have applied these two typo fixes, too.


urs
-
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[patch 0/7] CAN: Add new PF_CAN protocol family, try #5

2007-08-03 Thread Urs Thuermann
Hello Dave,

this is the fifth post of the patch series that adds the PF_CAN
protocol family for the Controller Area Network.

Since our last post we have changed the following:

* Remove slab destructor from calls to kmem_cache_alloc().
* Add comments about types defined in can.h.
* Update comment on vcan loopback module parameter.
* Fix typo in documentation.

The changes in try #4 were:

* Change vcan network driver to use the new RTNL API, as suggested by
  Patrick.
* Revert our change to use skb-iif instead of skb-cb.  After
  discussion with Patrick and Jamal it turned out, our first
  implementation was correct.
* Use skb_tail_pointer() instead of skb-tail directly.
* Coding style changes to satisfy linux/scripts/checkpatch.pl.
* Minor changes for 64-bit-cleanliness.
* Minor cleanup of #include's

The changes in try #3 were:

* Use sbk-sk and skb-pkt_type instead of skb-cb to pass loopback
  flags and originating socket down to the driver and back to the
  receiving socket.  Thanks to Patrick McHardy for pointing out our
  wrong use of sbk-cb.
* Use skb-iif instead of skb-cb to pass receiving interface from
  raw_rcv() and bcm_rcv() up to raw_recvmsg() and bcm_recvmsg().
* Set skb-protocol when sending CAN frames to netdevices.
* Removed struct raw_opt and struct bcm_opt and integrated these
  directly into struct raw_sock and bcm_sock resp., like most other
  proto implementations do.
* We have found and fixed race conditions between raw_bind(),
  raw_{set,get}sockopt() and raw_notifier().  This resulted in
  - complete removal of our own notifier list infrastructure in
af_can.c.  raw.c and bcm.c now use normal netdevice notifiers.
  - removal of ro-lock spinlock.  We use lock_sock(sk) now.
  - changed deletion of dev_rcv_lists, which are now marked for
deletion in the netdevice notifier in af_can.c and are actually
deleted when all entries have been deleted using can_rx_unregister().
* Follow changes in 2.6.22 (e.g. ktime_t timestamps in skb).
* Removed obsolete code from vcan.c, as pointed out by Stephen Hemminger.

The changes in try #2 were:

* reduced RCU callback overhead when deleting receiver lists (thx to
  feedback from Paul E. McKenney).
* eliminated some code duplication in net/can/proc.c.
* renamed slock-29 and sk_lock-29 to slock-AF_CAN and sk_lock-AF_CAN in
  net/core/sock.c
* added entry for can.txt in Documentation/networking/00-INDEX
* added error frame definitions in include/linux/can/error.h, which are to
  be used by CAN network drivers.


This patch series applies against net-2.6 and is derived from Subversion
revision r455 of http://svn.berlios.de/svnroot/repos/socketcan.
It can be found in the directory
http://svn.berlios.de/svnroot/repos/socketcan/trunk/patch-series/version.

This patch doesn't touch anything in the kernel except for the allocation
of a couple of numbers for protocol, arp hw type, and a line discipline.

Please review this patch series for integration into your tree.

Thanks very much for your work!

Best regards,

Urs Thuermann
Oliver Hartkopp

--
-
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[patch 6/7] CAN: Add maintainer entries

2007-08-03 Thread Urs Thuermann
This patch adds entries in the CREDITS and MAINTAINERS file for CAN.

Signed-off-by: Oliver Hartkopp [EMAIL PROTECTED]
Signed-off-by: Urs Thuermann [EMAIL PROTECTED]

---
 CREDITS |   16 
 MAINTAINERS |9 +
 2 files changed, 25 insertions(+)

Index: net-2.6/CREDITS
===
--- net-2.6.orig/CREDITS2007-08-03 11:21:31.0 +0200
+++ net-2.6/CREDITS 2007-08-03 11:21:56.0 +0200
@@ -1331,6 +1331,14 @@
 S: 5623 HZ Eindhoven
 S: The Netherlands
 
+N: Oliver Hartkopp
+E: [EMAIL PROTECTED]
+W: http://www.volkswagen.de
+D: Controller Area Network (network layer core)
+S: Brieffach 1776
+S: 38436 Wolfsburg
+S: Germany
+
 N: Andrew Haylett
 E: [EMAIL PROTECTED]
 D: Selection mechanism
@@ -3284,6 +3292,14 @@
 S: F-35042 Rennes Cedex
 S: France
 
+N: Urs Thuermann
+E: [EMAIL PROTECTED]
+W: http://www.volkswagen.de
+D: Controller Area Network (network layer core)
+S: Brieffach 1776
+S: 38436 Wolfsburg
+S: Germany
+
 N: Jon Tombs
 E: [EMAIL PROTECTED]
 W: http://www.esi.us.es/~jon
Index: net-2.6/MAINTAINERS
===
--- net-2.6.orig/MAINTAINERS2007-08-03 11:21:31.0 +0200
+++ net-2.6/MAINTAINERS 2007-08-03 11:21:56.0 +0200
@@ -951,6 +951,15 @@
 L: [EMAIL PROTECTED]
 S: Maintained
 
+CAN NETWORK LAYER
+P: Urs Thuermann
+M: [EMAIL PROTECTED]
+P: Oliver Hartkopp
+M: [EMAIL PROTECTED]
+L: [EMAIL PROTECTED]
+W: http://developer.berlios.de/projects/socketcan/
+S: Maintained
+
 CALGARY x86-64 IOMMU
 P: Muli Ben-Yehuda
 M: [EMAIL PROTECTED]

--
-
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[patch 5/7] CAN: Add virtual CAN netdevice driver

2007-08-03 Thread Urs Thuermann
This patch adds the virtual CAN bus (vcan) network driver.
The vcan device is just a loopback device for CAN frames, no
real CAN hardware is involved.

Signed-off-by: Oliver Hartkopp [EMAIL PROTECTED]
Signed-off-by: Urs Thuermann [EMAIL PROTECTED]

---
 drivers/net/Makefile |1 
 drivers/net/can/Kconfig  |   25 
 drivers/net/can/Makefile |5 
 drivers/net/can/vcan.c   |  261 +++
 net/can/Kconfig  |3 
 5 files changed, 295 insertions(+)

Index: net-2.6/drivers/net/Makefile
===
--- net-2.6.orig/drivers/net/Makefile   2007-08-03 11:21:31.0 +0200
+++ net-2.6/drivers/net/Makefile2007-08-03 11:21:54.0 +0200
@@ -8,6 +8,7 @@
 obj-$(CONFIG_CHELSIO_T1) += chelsio/
 obj-$(CONFIG_CHELSIO_T3) += cxgb3/
 obj-$(CONFIG_EHEA) += ehea/
+obj-$(CONFIG_CAN) += can/
 obj-$(CONFIG_BONDING) += bonding/
 obj-$(CONFIG_ATL1) += atl1/
 obj-$(CONFIG_GIANFAR) += gianfar_driver.o
Index: net-2.6/drivers/net/can/Kconfig
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ net-2.6/drivers/net/can/Kconfig 2007-08-03 11:21:54.0 +0200
@@ -0,0 +1,25 @@
+menu CAN Device Drivers
+   depends on CAN
+
+config CAN_VCAN
+   tristate Virtual Local CAN Interface (vcan)
+   depends on CAN
+   default N
+   ---help---
+ Similar to the network loopback devices, vcan offers a
+ virtual local CAN interface.
+
+ This driver can also be built as a module.  If so, the module
+ will be called vcan.
+
+config CAN_DEBUG_DEVICES
+   bool CAN devices debugging messages
+   depends on CAN
+   default N
+   ---help---
+ Say Y here if you want the CAN device drivers to produce a bunch of
+ debug messages to the system log.  Select this if you are having
+ a problem with CAN support and want to see more of what is going
+ on.
+
+endmenu
Index: net-2.6/drivers/net/can/Makefile
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ net-2.6/drivers/net/can/Makefile2007-08-03 11:21:54.0 +0200
@@ -0,0 +1,5 @@
+#
+#  Makefile for the Linux Controller Area Network drivers.
+#
+
+obj-$(CONFIG_CAN_VCAN) += vcan.o
Index: net-2.6/drivers/net/can/vcan.c
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ net-2.6/drivers/net/can/vcan.c  2007-08-03 11:21:54.0 +0200
@@ -0,0 +1,261 @@
+/*
+ * vcan.c - Virtual CAN interface
+ *
+ * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
+ * All rights reserved.
+ *
+ * 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, the following disclaimer and
+ *the referenced file 'COPYING'.
+ * 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. Neither the name of Volkswagen nor the names of its contributors
+ *may be used to endorse or promote products derived from this software
+ *without specific prior written permission.
+ *
+ * Alternatively, provided that this notice is retained in full, this
+ * software may be distributed under the terms of the GNU General
+ * Public License (GPL) version 2 as distributed in the 'COPYING'
+ * file from the main directory of the linux kernel source.
+ *
+ * The provided data structures and external interfaces from this code
+ * are not restricted to be used by modules with a GPL compatible license.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT
+ * OWNER 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.
+ *
+ * Send feedback to [EMAIL PROTECTED]
+ *
+ */
+
+#include linux/module.h
+#include linux/init.h
+#include linux/netdevice.h
+#include linux/if_arp.h
+#include linux/if_ether.h
+#include linux/can.h
+#include net

[patch 3/7] CAN: Add raw protocol

2007-08-03 Thread Urs Thuermann
This patch adds the CAN raw protocol.

Signed-off-by: Oliver Hartkopp [EMAIL PROTECTED]
Signed-off-by: Urs Thuermann [EMAIL PROTECTED]

---
 include/linux/can/raw.h |   31 +
 net/can/Kconfig |   26 +
 net/can/Makefile|3 
 net/can/raw.c   |  757 
 4 files changed, 817 insertions(+)

Index: net-2.6/include/linux/can/raw.h
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ net-2.6/include/linux/can/raw.h 2007-08-03 11:21:48.0 +0200
@@ -0,0 +1,31 @@
+/*
+ * linux/can/raw.h
+ *
+ * Definitions for raw CAN sockets
+ *
+ * Authors: Oliver Hartkopp [EMAIL PROTECTED]
+ *  Urs Thuermann   [EMAIL PROTECTED]
+ * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
+ * All rights reserved.
+ *
+ * Send feedback to [EMAIL PROTECTED]
+ *
+ */
+
+#ifndef CAN_RAW_H
+#define CAN_RAW_H
+
+#include linux/can.h
+
+#define SOL_CAN_RAW (SOL_CAN_BASE + CAN_RAW)
+
+/* for socket options affecting the socket (not the global system) */
+
+enum {
+   CAN_RAW_FILTER = 1, /* set 0 .. n can_filter(s)  */
+   CAN_RAW_ERR_FILTER, /* set filter for error frames   */
+   CAN_RAW_LOOPBACK,   /* local loopback (default:on)   */
+   CAN_RAW_RECV_OWN_MSGS   /* receive my own msgs (default:off) */
+};
+
+#endif
Index: net-2.6/net/can/Kconfig
===
--- net-2.6.orig/net/can/Kconfig2007-08-03 11:21:46.0 +0200
+++ net-2.6/net/can/Kconfig 2007-08-03 11:21:48.0 +0200
@@ -16,6 +16,32 @@
  If you want CAN support, you should say Y here and also to the
  specific driver for your controller(s) below.
 
+config CAN_RAW
+   tristate Raw CAN Protocol (raw access with CAN-ID filtering)
+   depends on CAN
+   default N
+   ---help---
+ The Raw CAN protocol option offers access to the CAN bus via
+ the BSD socket API. You probably want to use the raw socket in
+ most cases where no higher level protocol is being used. The raw
+ socket has several filter options e.g. ID-Masking / Errorframes.
+ To receive/send raw CAN messages, use AF_CAN with protocol CAN_RAW.
+
+config CAN_RAW_USER
+   bool Allow non-root users to access Raw CAN Protocol sockets
+   depends on CAN_RAW
+   default N
+   ---help---
+ The Controller Area Network is a local field bus transmitting only
+ broadcast messages without any routing and security concepts.
+ In the majority of cases the user application has to deal with
+ raw CAN frames. Therefore it might be reasonable NOT to restrict
+ the CAN access only to the user root, as known from other networks.
+ Since CAN_RAW sockets can only send and receive frames to/from CAN
+ interfaces this does not affect security of others networks.
+ Say Y here if you want non-root users to be able to access CAN_RAW
+ sockets.
+
 config CAN_DEBUG_CORE
bool CAN Core debugging messages
depends on CAN
Index: net-2.6/net/can/Makefile
===
--- net-2.6.orig/net/can/Makefile   2007-08-03 11:21:46.0 +0200
+++ net-2.6/net/can/Makefile2007-08-03 11:21:48.0 +0200
@@ -4,3 +4,6 @@
 
 obj-$(CONFIG_CAN)  += can.o
 can-objs   := af_can.o proc.o
+
+obj-$(CONFIG_CAN_RAW)  += can-raw.o
+can-raw-objs   := raw.o
Index: net-2.6/net/can/raw.c
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ net-2.6/net/can/raw.c   2007-08-03 11:21:48.0 +0200
@@ -0,0 +1,757 @@
+/*
+ * raw.c - Raw sockets for protocol family CAN
+ *
+ * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
+ * All rights reserved.
+ *
+ * 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, the following disclaimer and
+ *the referenced file 'COPYING'.
+ * 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. Neither the name of Volkswagen nor the names of its contributors
+ *may be used to endorse or promote products derived from this software
+ *without specific prior written permission.
+ *
+ * Alternatively, provided that this notice is retained in full, this
+ * software may be distributed under the terms of the GNU General
+ * Public License (GPL) version 2 as distributed in the 'COPYING'
+ * file from the main directory of the linux kernel

[patch 1/7] CAN: Allocate protocol numbers for PF_CAN

2007-08-03 Thread Urs Thuermann
This patch adds a protocol/address family number, ARP hardware type,
ethernet packet type, and a line discipline number for the SocketCAN
implementation.

Signed-off-by: Oliver Hartkopp [EMAIL PROTECTED]
Signed-off-by: Urs Thuermann [EMAIL PROTECTED]

---
 include/linux/if_arp.h   |1 +
 include/linux/if_ether.h |1 +
 include/linux/socket.h   |2 ++
 include/linux/tty.h  |3 ++-
 net/core/sock.c  |4 ++--
 5 files changed, 8 insertions(+), 3 deletions(-)

Index: net-2.6/include/linux/if_arp.h
===
--- net-2.6.orig/include/linux/if_arp.h 2007-08-03 11:21:32.0 +0200
+++ net-2.6/include/linux/if_arp.h  2007-08-03 11:21:42.0 +0200
@@ -52,6 +52,7 @@
 #define ARPHRD_ROSE270
 #define ARPHRD_X25 271 /* CCITT X.25   */
 #define ARPHRD_HWX25   272 /* Boards with X.25 in firmware */
+#define ARPHRD_CAN 280 /* Controller Area Network  */
 #define ARPHRD_PPP 512
 #define ARPHRD_CISCO   513 /* Cisco HDLC   */
 #define ARPHRD_HDLCARPHRD_CISCO
Index: net-2.6/include/linux/if_ether.h
===
--- net-2.6.orig/include/linux/if_ether.h   2007-08-03 11:21:32.0 
+0200
+++ net-2.6/include/linux/if_ether.h2007-08-03 11:21:42.0 +0200
@@ -90,6 +90,7 @@
 #define ETH_P_WAN_PPP   0x0007  /* Dummy type for WAN PPP frames*/
 #define ETH_P_PPP_MP0x0008  /* Dummy type for PPP MP frames */
 #define ETH_P_LOCALTALK 0x0009 /* Localtalk pseudo type*/
+#define ETH_P_CAN  0x000C  /* Controller Area Network  */
 #define ETH_P_PPPTALK  0x0010  /* Dummy type for Atalk over PPP*/
 #define ETH_P_TR_802_2 0x0011  /* 802.2 frames */
 #define ETH_P_MOBITEX  0x0015  /* Mobitex ([EMAIL PROTECTED])  */
Index: net-2.6/include/linux/socket.h
===
--- net-2.6.orig/include/linux/socket.h 2007-08-03 11:21:32.0 +0200
+++ net-2.6/include/linux/socket.h  2007-08-03 11:21:42.0 +0200
@@ -185,6 +185,7 @@
 #define AF_PPPOX   24  /* PPPoX sockets*/
 #define AF_WANPIPE 25  /* Wanpipe API Sockets */
 #define AF_LLC 26  /* Linux LLC*/
+#define AF_CAN 29  /* Controller Area Network  */
 #define AF_TIPC30  /* TIPC sockets */
 #define AF_BLUETOOTH   31  /* Bluetooth sockets*/
 #define AF_IUCV32  /* IUCV sockets */
@@ -220,6 +221,7 @@
 #define PF_PPPOX   AF_PPPOX
 #define PF_WANPIPE AF_WANPIPE
 #define PF_LLC AF_LLC
+#define PF_CAN AF_CAN
 #define PF_TIPCAF_TIPC
 #define PF_BLUETOOTH   AF_BLUETOOTH
 #define PF_IUCVAF_IUCV
Index: net-2.6/include/linux/tty.h
===
--- net-2.6.orig/include/linux/tty.h2007-08-03 11:21:32.0 +0200
+++ net-2.6/include/linux/tty.h 2007-08-03 11:21:42.0 +0200
@@ -24,7 +24,7 @@
 #define NR_PTYSCONFIG_LEGACY_PTY_COUNT   /* Number of legacy ptys */
 #define NR_UNIX98_PTY_DEFAULT  4096  /* Default maximum for Unix98 ptys */
 #define NR_UNIX98_PTY_MAX  (1  MINORBITS) /* Absolute limit */
-#define NR_LDISCS  17
+#define NR_LDISCS  18
 
 /* line disciplines */
 #define N_TTY  0
@@ -45,6 +45,7 @@
 #define N_SYNC_PPP 14  /* synchronous PPP */
 #define N_HCI  15  /* Bluetooth HCI UART */
 #define N_GIGASET_M101 16  /* Siemens Gigaset M101 serial DECT adapter */
+#define N_SLCAN17  /* Serial / USB serial CAN Adaptors */
 
 /*
  * This character is the same as _POSIX_VDISABLE: it cannot be used as
Index: net-2.6/net/core/sock.c
===
--- net-2.6.orig/net/core/sock.c2007-08-03 11:21:32.0 +0200
+++ net-2.6/net/core/sock.c 2007-08-03 11:21:42.0 +0200
@@ -153,7 +153,7 @@
   sk_lock-AF_ASH   , sk_lock-AF_ECONET   , sk_lock-AF_ATMSVC   ,
   sk_lock-21   , sk_lock-AF_SNA  , sk_lock-AF_IRDA ,
   sk_lock-AF_PPPOX , sk_lock-AF_WANPIPE  , sk_lock-AF_LLC  ,
-  sk_lock-27   , sk_lock-28  , sk_lock-29  ,
+  sk_lock-27   , sk_lock-28  , sk_lock-AF_CAN  ,
   sk_lock-AF_TIPC  , sk_lock-AF_BLUETOOTH, sk_lock-IUCV,
   sk_lock-AF_RXRPC , sk_lock-AF_MAX
 };
@@ -167,7 +167,7 @@
   slock-AF_ASH   , slock-AF_ECONET   , slock-AF_ATMSVC   ,
   slock-21   , slock-AF_SNA  , slock-AF_IRDA ,
   slock-AF_PPPOX , slock-AF_WANPIPE  , slock-AF_LLC  ,
-  slock-27   , slock-28  , slock-29  ,
+  slock-27   , slock-28  , slock-AF_CAN  ,
   slock

[patch 7/7] CAN: Add documentation

2007-08-03 Thread Urs Thuermann
This patch adds documentation for the PF_CAN protocol family.

Signed-off-by: Oliver Hartkopp [EMAIL PROTECTED]
Signed-off-by: Urs Thuermann [EMAIL PROTECTED]

---
 Documentation/networking/00-INDEX |2 
 Documentation/networking/can.txt  |  635 ++
 2 files changed, 637 insertions(+)

Index: net-2.6/Documentation/networking/can.txt
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ net-2.6/Documentation/networking/can.txt2007-08-03 11:21:58.0 
+0200
@@ -0,0 +1,635 @@
+
+
+can.txt
+
+Readme file for the Controller Area Network Protocol Family (aka Socket CAN)
+
+This file contains
+
+  1 Overview / What is Socket CAN
+
+  2 Motivation / Why using the socket API
+
+  3 Socket CAN concept
+3.1 receive lists
+3.2 loopback
+3.3 network security issues (capabilities)
+3.4 network problem notifications
+
+  4 How to use Socket CAN
+4.1 RAW protocol sockets with can_filters (SOCK_RAW)
+  4.1.1 RAW socket option CAN_RAW_FILTER
+  4.1.2 RAW socket option CAN_RAW_ERR_FILTER
+  4.1.3 RAW socket option CAN_RAW_LOOPBACK
+  4.1.4 RAW socket option CAN_RAW_RECV_OWN_MSGS
+4.2 Broadcast Manager protocol sockets (SOCK_DGRAM)
+4.3 connected transport protocols (SOCK_SEQPACKET)
+4.4 unconnected transport protocols (SOCK_DGRAM)
+
+  5 Socket CAN core module
+5.1 can.ko module params
+5.2 procfs content
+5.3 writing own CAN protocol modules
+
+  6 CAN network drivers
+6.1 general settings
+6.2 loopback
+6.3 CAN controller hardware filters
+6.4 currently supported CAN hardware
+6.5 todo
+
+  7 Credits
+
+
+
+1. Overview / What is Socket CAN
+
+
+The socketcan package is an implementation of CAN protocols
+(Controller Area Network) for Linux.  CAN is a networking technology
+which has wide-spread use in automation, embedded devices, and
+automotive fields.  While there have been other CAN implementations
+for Linux based on character devices, Socket CAN uses the Berkeley
+socket API, the Linux network stack and implements the CAN device
+drivers as network interfaces.  The CAN socket API has been designed
+as similar as possible to the TCP/IP protocols to allow programmers,
+familiar with network programming, to easily learn how to use CAN
+sockets.
+
+2. Motivation / Why using the socket API
+
+
+There have been CAN implementations for Linux before Socket CAN so the
+question arises, why we have started another project.  Most existing
+implementations come as a device driver for some CAN hardware, they
+are based on character devices and provide comparatively little
+functionality.  Usually, there is only a hardware-specific device
+driver which provides a character device interface to send and
+receive raw CAN frames, directly to/from the controller hardware.
+Queueing of frames and higher-level transport protocols like ISO-TP
+have to be implemented in user space applications.  Also, most
+character-device implementations support only one single process to
+open the device at a time, similar to a serial interface.  Exchanging
+the CAN controller requires employment of another device driver and
+often the need for adaption of large parts of the application to the
+new driver's API.
+
+Socket CAN was designed to overcome all of these limitations.  A new
+protocol family has been implemented which provides a socket interface
+to user space applications and which builds upon the Linux network
+layer, so to use all of the provided queueing functionality.  Device
+drivers for CAN controller hardware register itself with the Linux
+network layer as a network device, so that CAN frames from the
+controller can be passed up to the network layer and on to the CAN
+protocol family module and also vice-versa.  Also, the protocol family
+module provides an API for transport protocol modules to register, so
+that any number of transport protocols can be loaded or unloaded
+dynamically.  In fact, the can core module alone does not provide any
+protocol and can not be used without loading at least one additional
+protocol module.  Multiple sockets can be opened at the same time,
+on different or the same protocol module and they can listen/send
+frames on different or the same CAN IDs.  Several sockets listening on
+the same interface for frames with the same CAN ID are all passed the
+same received matching CAN frames.  An application wishing to
+communicate using a specific transport protocol, e.g. ISO-TP, just
+selects that protocol when opening the socket, and then can read and
+write application data byte streams, without having to deal with
+CAN-IDs, frames, etc.
+
+Similar functionality visible from user-space could

[patch 4/7] CAN: Add broadcast manager (bcm) protocol

2007-08-03 Thread Urs Thuermann
This patch adds the CAN broadcast manager (bcm) protocol.

Signed-off-by: Oliver Hartkopp [EMAIL PROTECTED]
Signed-off-by: Urs Thuermann [EMAIL PROTECTED]

---
 include/linux/can/bcm.h |   65 +
 net/can/Kconfig |   28 
 net/can/Makefile|3 
 net/can/bcm.c   | 1755 
 4 files changed, 1851 insertions(+)

Index: net-2.6/include/linux/can/bcm.h
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ net-2.6/include/linux/can/bcm.h 2007-08-03 11:21:51.0 +0200
@@ -0,0 +1,65 @@
+/*
+ * linux/can/bcm.h
+ *
+ * Definitions for CAN Broadcast Manager (BCM)
+ *
+ * Author: Oliver Hartkopp [EMAIL PROTECTED]
+ * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
+ * All rights reserved.
+ *
+ * Send feedback to [EMAIL PROTECTED]
+ *
+ */
+
+#ifndef CAN_BCM_H
+#define CAN_BCM_H
+
+/**
+ * struct bcm_msg_head - head of messages to/from the broadcast manager
+ * @opcode:opcode, see enum below.
+ * @flags: special flags, see below.
+ * @count: number of frames to send before changing interval.
+ * @ival1: interval for the first @count frames.
+ * @ival2: interval for the following frames.
+ * @can_id:CAN ID of frames to be sent or received.
+ * @nframes:   number of frames appended to the message head.
+ * @frames:array of CAN frames.
+ */
+struct bcm_msg_head {
+   int opcode;
+   int flags;
+   int count;
+   struct timeval ival1, ival2;
+   canid_t can_id;
+   int nframes;
+   struct can_frame frames[0];
+};
+
+enum {
+   TX_SETUP = 1,   /* create (cyclic) transmission task */
+   TX_DELETE,  /* remove (cyclic) transmission task */
+   TX_READ,/* read properties of (cyclic) transmission task */
+   TX_SEND,/* send one CAN frame */
+   RX_SETUP,   /* create RX content filter subscription */
+   RX_DELETE,  /* remove RX content filter subscription */
+   RX_READ,/* read properties of RX content filter subscription */
+   TX_STATUS,  /* reply to TX_READ request */
+   TX_EXPIRED, /* notification on performed transmissions (count=0) */
+   RX_STATUS,  /* reply to RX_READ request */
+   RX_TIMEOUT, /* cyclic message is absent */
+   RX_CHANGED  /* updated CAN frame (detected content change) */
+};
+
+#define SETTIMER0x0001
+#define STARTTIMER  0x0002
+#define TX_COUNTEVT 0x0004
+#define TX_ANNOUNCE 0x0008
+#define TX_CP_CAN_ID0x0010
+#define RX_FILTER_ID0x0020
+#define RX_CHECK_DLC0x0040
+#define RX_NO_AUTOTIMER 0x0080
+#define RX_ANNOUNCE_RESUME  0x0100
+#define TX_RESET_MULTI_IDX  0x0200
+#define RX_RTR_FRAME0x0400
+
+#endif /* CAN_BCM_H */
Index: net-2.6/net/can/Kconfig
===
--- net-2.6.orig/net/can/Kconfig2007-08-03 11:21:48.0 +0200
+++ net-2.6/net/can/Kconfig 2007-08-03 11:21:51.0 +0200
@@ -42,6 +42,34 @@
  Say Y here if you want non-root users to be able to access CAN_RAW
  sockets.
 
+config CAN_BCM
+   tristate Broadcast Manager CAN Protocol (with content filtering)
+   depends on CAN
+   default N
+   ---help---
+ The Broadcast Manager offers content filtering, timeout monitoring,
+ sending of RTR-frames and cyclic CAN messages without permanent user
+ interaction. The BCM can be 'programmed' via the BSD socket API and
+ informs you on demand e.g. only on content updates / timeouts.
+ You probably want to use the bcm socket in most cases where cyclic
+ CAN messages are used on the bus (e.g. in automotive environments).
+ To use the Broadcast Manager, use AF_CAN with protocol CAN_BCM.
+
+config CAN_BCM_USER
+   bool Allow non-root users to access CAN broadcast manager sockets
+   depends on CAN_BCM
+   default N
+   ---help---
+ The Controller Area Network is a local field bus transmitting only
+ broadcast messages without any routing and security concepts.
+ In the majority of cases the user application has to deal with
+ raw CAN frames. Therefore it might be reasonable NOT to restrict
+ the CAN access only to the user root, as known from other networks.
+ Since CAN_BCM sockets can only send and receive frames to/from CAN
+ interfaces this does not affect security of others networks.
+ Say Y here if you want non-root users to be able to access CAN_BCM
+ sockets.
+
 config CAN_DEBUG_CORE
bool CAN Core debugging messages
depends on CAN
Index: net-2.6/net/can/Makefile
===
--- net-2.6.orig/net/can/Makefile   2007-08-03 11:21:48.0 +0200
+++ net-2.6/net/can/Makefile2007-08-03

Re: [patch 5/7] CAN: Add virtual CAN netdevice driver

2007-07-09 Thread Urs Thuermann
Patrick McHardy [EMAIL PROTECTED] writes:

  I currently still prefer no default interfaces, since we would get rid
  of some code.
 
 
 Me too, and you don't need to worry about compatibility.

Here is a new version of the vcan driver for you to review.  We now
use the netlink link creation API and no interfaces will be created at
module load time.  The module parameter for the number of interfaces
to be created has been removed.

I have appended the patch at the end of this mail.

We have also made some changes to the rest of the PF_CAN code, here is
the complete list of changes:

* Change vcan network driver to use the new RTNL API.

* Revert our change to use skb-iif instead of skb-cb.  After
  discussion with Patrick and Jamal it turned out, our first
  implementation was correct.
 
* Use skb_tail_pointer() instead of skb-tail directly.

* Minor changes for 64-bit-cleanliness.

* Minor cleanup of #include's

The current patch series can be found at
http://svn.berlios.de/svnroot/repos/socketcan/trunk/patch-series/net-2.6.23

Could you please review this again?  Should we post the whole patch
series to netdev ML again?

Regards,
urs



This patch adds the virtual CAN bus (vcan) network driver.
The vcan device is just a loopback device for CAN frames, no
real CAN hardware is involved.

Signed-Off-By: Oliver Hartkopp [EMAIL PROTECTED]
Signed-Off-By: Urs Thuermann [EMAIL PROTECTED]

---
 drivers/net/Makefile |1 
 drivers/net/can/Kconfig  |   25 
 drivers/net/can/Makefile |5 
 drivers/net/can/vcan.c   |  264 +++
 net/can/Kconfig  |3 
 5 files changed, 298 insertions(+)

Index: net-2.6.23/drivers/net/Makefile
===
--- net-2.6.23.orig/drivers/net/Makefile2007-07-09 10:41:38.0 
+0200
+++ net-2.6.23/drivers/net/Makefile 2007-07-09 10:42:01.0 +0200
@@ -8,6 +8,7 @@
 obj-$(CONFIG_CHELSIO_T1) += chelsio/
 obj-$(CONFIG_CHELSIO_T3) += cxgb3/
 obj-$(CONFIG_EHEA) += ehea/
+obj-$(CONFIG_CAN) += can/
 obj-$(CONFIG_BONDING) += bonding/
 obj-$(CONFIG_ATL1) += atl1/
 obj-$(CONFIG_GIANFAR) += gianfar_driver.o
Index: net-2.6.23/drivers/net/can/Kconfig
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ net-2.6.23/drivers/net/can/Kconfig  2007-07-09 10:42:01.0 +0200
@@ -0,0 +1,25 @@
+menu CAN Device Drivers
+   depends on CAN
+
+config CAN_VCAN
+   tristate Virtual Local CAN Interface (vcan)
+   depends on CAN
+   default N
+   ---help---
+ Similar to the network loopback devices, vcan offers a
+ virtual local CAN interface.
+
+ This driver can also be built as a module.  If so, the module
+ will be called vcan.
+
+config CAN_DEBUG_DEVICES
+   bool CAN devices debugging messages
+   depends on CAN
+   default N
+   ---help---
+ Say Y here if you want the CAN device drivers to produce a bunch of
+ debug messages to the system log.  Select this if you are having
+ a problem with CAN support and want to see more of what is going
+ on.
+
+endmenu
Index: net-2.6.23/drivers/net/can/Makefile
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ net-2.6.23/drivers/net/can/Makefile 2007-07-09 10:42:01.0 +0200
@@ -0,0 +1,5 @@
+#
+#  Makefile for the Linux Controller Area Network drivers.
+#
+
+obj-$(CONFIG_CAN_VCAN) += vcan.o
Index: net-2.6.23/drivers/net/can/vcan.c
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ net-2.6.23/drivers/net/can/vcan.c   2007-07-09 13:22:44.0 +0200
@@ -0,0 +1,264 @@
+/*
+ * vcan.c - Virtual CAN interface
+ *
+ * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
+ * All rights reserved.
+ *
+ * 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, the following disclaimer and
+ *the referenced file 'COPYING'.
+ * 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. Neither the name of Volkswagen nor the names of its contributors
+ *may be used to endorse or promote products derived from this software
+ *without specific prior written permission.
+ *
+ * Alternatively, provided that this notice is retained in full, this
+ * software may be distributed under the terms of the GNU General
+ * Public License (GPL) version 2 as distributed in the 'COPYING'
+ * file from the main directory of the linux kernel source

Re: [patch 5/7] CAN: Add virtual CAN netdevice driver

2007-07-04 Thread Urs Thuermann
Patrick McHardy [EMAIL PROTECTED] writes:

 It should create as many devices as necessary to operate (similar
 to the loopback device) by default. Optional interfaces that are
 used for addressing reasons should be manually added by the user
 as needed. And it should not use module parameters for that please.

I have now changed vcan to use the netlink interface.  I am now
thinking about how many interfaces should be created at module load
time.

The PF_CAN doesn't need vcan to operate, like lo for IP.  vcan is
mostly for doing tests when you don't have real CAN interfaces
available, and you would normally want to have as many vcan devices as
you would have real CAN interface on your target hardware.

This is why I also wanted to have a default of 0 vcan interfaces and
an ioctl do add interfaces as needed.  Then we decided however to have
a module parameter with a typical default and no ioctl().

Now, I would again think that 0 vcan interfaces should be created
automatically and the user must create the devices he needs.  Wouldn't
that also be a better default for dummy interfaces?  It would simplify
dummy.c quite a bit, since dummy_init_one() could be removed
completely and dummy_init_module() would only register the
dummy_link_ops, right?

However, this could surprise a user loading the module and not seeing
any new interface.  Is it because of backward compatibility that you
create one dummy interface by default?

For this reason I also consider a default of one vcan interface to be
created automatically.  But then 1 seems almost as arbitrarily as 4,
since also 1 is not needed for PF_CAN to work.

I currently still prefer no default interfaces, since we would get rid
of some code.

What is the reason you don't like a module parameter to control the
number of default interfaces?  We still have that in our code
currently (but I'm about to remove it).

urs
-
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [patch 5/7] CAN: Add virtual CAN netdevice driver

2007-06-22 Thread Urs Thuermann
Patrick McHardy [EMAIL PROTECTED] writes:

 Is there a reason why you're still doing the allocate n devices
 on init thing instead of using the rtnl_link API?

Sorry, it's simply a matter of time.  We have been extremely busy with
other projects and two presentations (mgmt, customers, and press) the
last two weeks and have worked on the other changes this week.  I'm
sorry I haven't yet been able to look at your rtnl_link code close
enough, but it's definitely on my todo list.  Starting on Sunday I'll
be on a business trip to .jp for a week, and I hope I get to it in
that week, otherwise on return.

urs
-
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[patch 1/7] CAN: Allocate protocol numbers for PF_CAN

2007-06-21 Thread Urs Thuermann
This patch adds a protocol/address family number, ARP hardware type,
ethernet packet type, and a line discipline number for the SocketCAN
implementation.

Signed-Off-By: Oliver Hartkopp [EMAIL PROTECTED]
Signed-Off-By: Urs Thuermann [EMAIL PROTECTED]

---
 include/linux/if_arp.h   |1 +
 include/linux/if_ether.h |1 +
 include/linux/socket.h   |2 ++
 include/linux/tty.h  |3 ++-
 net/core/sock.c  |4 ++--
 5 files changed, 8 insertions(+), 3 deletions(-)

Index: linux-2.6.22-rc5/include/linux/if_arp.h
===
--- linux-2.6.22-rc5.orig/include/linux/if_arp.h2007-06-20 
14:10:41.0 +0200
+++ linux-2.6.22-rc5/include/linux/if_arp.h 2007-06-20 14:11:00.0 
+0200
@@ -52,6 +52,7 @@
 #define ARPHRD_ROSE270
 #define ARPHRD_X25 271 /* CCITT X.25   */
 #define ARPHRD_HWX25   272 /* Boards with X.25 in firmware */
+#define ARPHRD_CAN 280 /* Controller Area Network  */
 #define ARPHRD_PPP 512
 #define ARPHRD_CISCO   513 /* Cisco HDLC   */
 #define ARPHRD_HDLCARPHRD_CISCO
Index: linux-2.6.22-rc5/include/linux/if_ether.h
===
--- linux-2.6.22-rc5.orig/include/linux/if_ether.h  2007-06-20 
14:10:41.0 +0200
+++ linux-2.6.22-rc5/include/linux/if_ether.h   2007-06-20 14:11:00.0 
+0200
@@ -90,6 +90,7 @@
 #define ETH_P_WAN_PPP   0x0007  /* Dummy type for WAN PPP frames*/
 #define ETH_P_PPP_MP0x0008  /* Dummy type for PPP MP frames */
 #define ETH_P_LOCALTALK 0x0009 /* Localtalk pseudo type*/
+#define ETH_P_CAN  0x000C  /* Controller Area Network  */
 #define ETH_P_PPPTALK  0x0010  /* Dummy type for Atalk over PPP*/
 #define ETH_P_TR_802_2 0x0011  /* 802.2 frames */
 #define ETH_P_MOBITEX  0x0015  /* Mobitex ([EMAIL PROTECTED])  */
Index: linux-2.6.22-rc5/include/linux/socket.h
===
--- linux-2.6.22-rc5.orig/include/linux/socket.h2007-06-20 
14:10:41.0 +0200
+++ linux-2.6.22-rc5/include/linux/socket.h 2007-06-20 14:11:00.0 
+0200
@@ -185,6 +185,7 @@
 #define AF_PPPOX   24  /* PPPoX sockets*/
 #define AF_WANPIPE 25  /* Wanpipe API Sockets */
 #define AF_LLC 26  /* Linux LLC*/
+#define AF_CAN 29  /* Controller Area Network  */
 #define AF_TIPC30  /* TIPC sockets */
 #define AF_BLUETOOTH   31  /* Bluetooth sockets*/
 #define AF_IUCV32  /* IUCV sockets */
@@ -220,6 +221,7 @@
 #define PF_PPPOX   AF_PPPOX
 #define PF_WANPIPE AF_WANPIPE
 #define PF_LLC AF_LLC
+#define PF_CAN AF_CAN
 #define PF_TIPCAF_TIPC
 #define PF_BLUETOOTH   AF_BLUETOOTH
 #define PF_IUCVAF_IUCV
Index: linux-2.6.22-rc5/include/linux/tty.h
===
--- linux-2.6.22-rc5.orig/include/linux/tty.h   2007-06-20 14:10:41.0 
+0200
+++ linux-2.6.22-rc5/include/linux/tty.h2007-06-20 14:11:00.0 
+0200
@@ -24,7 +24,7 @@
 #define NR_PTYSCONFIG_LEGACY_PTY_COUNT   /* Number of legacy ptys */
 #define NR_UNIX98_PTY_DEFAULT  4096  /* Default maximum for Unix98 ptys */
 #define NR_UNIX98_PTY_MAX  (1  MINORBITS) /* Absolute limit */
-#define NR_LDISCS  17
+#define NR_LDISCS  18
 
 /* line disciplines */
 #define N_TTY  0
@@ -45,6 +45,7 @@
 #define N_SYNC_PPP 14  /* synchronous PPP */
 #define N_HCI  15  /* Bluetooth HCI UART */
 #define N_GIGASET_M101 16  /* Siemens Gigaset M101 serial DECT adapter */
+#define N_SLCAN17  /* Serial / USB serial CAN Adaptors */
 
 /*
  * This character is the same as _POSIX_VDISABLE: it cannot be used as
Index: linux-2.6.22-rc5/net/core/sock.c
===
--- linux-2.6.22-rc5.orig/net/core/sock.c   2007-06-20 14:10:41.0 
+0200
+++ linux-2.6.22-rc5/net/core/sock.c2007-06-20 14:11:00.0 +0200
@@ -153,7 +153,7 @@
   sk_lock-AF_ASH   , sk_lock-AF_ECONET   , sk_lock-AF_ATMSVC   ,
   sk_lock-21   , sk_lock-AF_SNA  , sk_lock-AF_IRDA ,
   sk_lock-AF_PPPOX , sk_lock-AF_WANPIPE  , sk_lock-AF_LLC  ,
-  sk_lock-27   , sk_lock-28  , sk_lock-29  ,
+  sk_lock-27   , sk_lock-28  , sk_lock-AF_CAN  ,
   sk_lock-AF_TIPC  , sk_lock-AF_BLUETOOTH, sk_lock-IUCV,
   sk_lock-AF_RXRPC , sk_lock-AF_MAX
 };
@@ -167,7 +167,7 @@
   slock-AF_ASH   , slock-AF_ECONET   , slock-AF_ATMSVC   ,
   slock-21   , slock-AF_SNA  , slock-AF_IRDA ,
   slock-AF_PPPOX , slock

[patch 5/7] CAN: Add virtual CAN netdevice driver

2007-06-21 Thread Urs Thuermann
This patch adds the virtual CAN bus (vcan) network driver.
The vcan device is just a loopback device for CAN frames, no
real CAN hardware is involved.

Signed-Off-By: Oliver Hartkopp [EMAIL PROTECTED]
Signed-Off-By: Urs Thuermann [EMAIL PROTECTED]

---
 drivers/net/Makefile |1 
 drivers/net/can/Kconfig  |   25 
 drivers/net/can/Makefile |5 
 drivers/net/can/vcan.c   |  287 +++
 net/can/Kconfig  |3 
 5 files changed, 321 insertions(+)

Index: linux-2.6.22-rc5/drivers/net/Makefile
===
--- linux-2.6.22-rc5.orig/drivers/net/Makefile  2007-06-20 14:10:41.0 
+0200
+++ linux-2.6.22-rc5/drivers/net/Makefile   2007-06-20 14:11:19.0 
+0200
@@ -8,6 +8,7 @@
 obj-$(CONFIG_CHELSIO_T1) += chelsio/
 obj-$(CONFIG_CHELSIO_T3) += cxgb3/
 obj-$(CONFIG_EHEA) += ehea/
+obj-$(CONFIG_CAN) += can/
 obj-$(CONFIG_BONDING) += bonding/
 obj-$(CONFIG_ATL1) += atl1/
 obj-$(CONFIG_GIANFAR) += gianfar_driver.o
Index: linux-2.6.22-rc5/drivers/net/can/Kconfig
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ linux-2.6.22-rc5/drivers/net/can/Kconfig2007-06-20 14:11:19.0 
+0200
@@ -0,0 +1,25 @@
+menu CAN Device Drivers
+   depends on CAN
+
+config CAN_VCAN
+   tristate Virtual Local CAN Interface (vcan)
+   depends on CAN
+   default N
+   ---help---
+ Similar to the network loopback devices, vcan offers a
+ virtual local CAN interface.
+
+ This driver can also be built as a module.  If so, the module
+ will be called vcan.
+
+config CAN_DEBUG_DEVICES
+   bool CAN devices debugging messages
+   depends on CAN
+   default N
+   ---help---
+ Say Y here if you want the CAN device drivers to produce a bunch of
+ debug messages to the system log.  Select this if you are having
+ a problem with CAN support and want to see more of what is going
+ on.
+
+endmenu
Index: linux-2.6.22-rc5/drivers/net/can/Makefile
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ linux-2.6.22-rc5/drivers/net/can/Makefile   2007-06-20 14:11:19.0 
+0200
@@ -0,0 +1,5 @@
+#
+#  Makefile for the Linux Controller Area Network drivers.
+#
+
+obj-$(CONFIG_CAN_VCAN) += vcan.o
Index: linux-2.6.22-rc5/drivers/net/can/vcan.c
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ linux-2.6.22-rc5/drivers/net/can/vcan.c 2007-06-20 14:11:19.0 
+0200
@@ -0,0 +1,287 @@
+/*
+ * vcan.c - Virtual CAN interface
+ *
+ * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
+ * All rights reserved.
+ *
+ * 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, the following disclaimer and
+ *the referenced file 'COPYING'.
+ * 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. Neither the name of Volkswagen nor the names of its contributors
+ *may be used to endorse or promote products derived from this software
+ *without specific prior written permission.
+ *
+ * Alternatively, provided that this notice is retained in full, this
+ * software may be distributed under the terms of the GNU General
+ * Public License (GPL) version 2 as distributed in the 'COPYING'
+ * file from the main directory of the linux kernel source.
+ *
+ * The provided data structures and external interfaces from this code
+ * are not restricted to be used by modules with a GPL compatible license.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT
+ * OWNER 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.
+ *
+ * Send feedback to [EMAIL PROTECTED]
+ *
+ */
+
+#include linux/module.h
+#include linux/init.h
+#include linux/netdevice.h
+#include

[patch 3/7] CAN: Add raw protocol

2007-06-21 Thread Urs Thuermann
This patch adds the CAN raw protocol.

Signed-Off-By: Oliver Hartkopp [EMAIL PROTECTED]
Signed-Off-By: Urs Thuermann [EMAIL PROTECTED]

---
 include/linux/can/raw.h |   31 +
 net/can/Kconfig |   26 +
 net/can/Makefile|3 
 net/can/raw.c   |  751 
 4 files changed, 811 insertions(+)

Index: linux-2.6.22-rc5-git5/include/linux/can/raw.h
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ linux-2.6.22-rc5-git5/include/linux/can/raw.h   2007-06-21 
14:05:26.0 +0200
@@ -0,0 +1,31 @@
+/*
+ * linux/can/raw.h
+ *
+ * Definitions for raw CAN sockets
+ *
+ * Authors: Oliver Hartkopp [EMAIL PROTECTED]
+ *  Urs Thuermann   [EMAIL PROTECTED]
+ * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
+ * All rights reserved.
+ *
+ * Send feedback to [EMAIL PROTECTED]
+ *
+ */
+
+#ifndef CAN_RAW_H
+#define CAN_RAW_H
+
+#include linux/can.h
+
+#define SOL_CAN_RAW (SOL_CAN_BASE + CAN_RAW)
+
+/* for socket options affecting the socket (not the global system) */
+
+enum {
+   CAN_RAW_FILTER = 1, /* set 0 .. n can_filter(s)  */
+   CAN_RAW_ERR_FILTER, /* set filter for error frames   */
+   CAN_RAW_LOOPBACK,   /* local loopback (default:on)   */
+   CAN_RAW_RECV_OWN_MSGS   /* receive my own msgs (default:off) */
+};
+
+#endif
Index: linux-2.6.22-rc5-git5/net/can/Kconfig
===
--- linux-2.6.22-rc5-git5.orig/net/can/Kconfig  2007-06-21 14:03:50.0 
+0200
+++ linux-2.6.22-rc5-git5/net/can/Kconfig   2007-06-21 14:05:26.0 
+0200
@@ -16,6 +16,32 @@
  If you want CAN support, you should say Y here and also to the
  specific driver for your controller(s) below.
 
+config CAN_RAW
+   tristate Raw CAN Protocol (raw access with CAN-ID filtering)
+   depends on CAN
+   default N
+   ---help---
+ The Raw CAN protocol option offers access to the CAN bus via
+ the BSD socket API. You probably want to use the raw socket in
+ most cases where no higher level protocol is being used. The raw
+ socket has several filter options e.g. ID-Masking / Errorframes.
+ To receive/send raw CAN messages, use AF_CAN with protocol CAN_RAW.
+
+config CAN_RAW_USER
+   bool Allow non-root users to access Raw CAN Protocol sockets
+   depends on CAN_RAW
+   default N
+   ---help---
+ The Controller Area Network is a local field bus transmitting only
+ broadcast messages without any routing and security concepts.
+ In the majority of cases the user application has to deal with
+ raw CAN frames. Therefore it might be reasonable NOT to restrict
+ the CAN access only to the user root, as known from other networks.
+ Since CAN_RAW sockets can only send and receive frames to/from CAN
+ interfaces this does not affect security of others networks.
+ Say Y here if you want non-root users to be able to access CAN_RAW
+ sockets.
+
 config CAN_DEBUG_CORE
bool CAN Core debugging messages
depends on CAN
Index: linux-2.6.22-rc5-git5/net/can/Makefile
===
--- linux-2.6.22-rc5-git5.orig/net/can/Makefile 2007-06-21 14:03:50.0 
+0200
+++ linux-2.6.22-rc5-git5/net/can/Makefile  2007-06-21 14:05:26.0 
+0200
@@ -4,3 +4,6 @@
 
 obj-$(CONFIG_CAN)  += can.o
 can-objs   := af_can.o proc.o
+
+obj-$(CONFIG_CAN_RAW)  += can-raw.o
+can-raw-objs   := raw.o
Index: linux-2.6.22-rc5-git5/net/can/raw.c
===
--- /dev/null   1970-01-01 00:00:00.0 +
+++ linux-2.6.22-rc5-git5/net/can/raw.c 2007-06-21 14:05:42.0 +0200
@@ -0,0 +1,751 @@
+/*
+ * raw.c - Raw sockets for protocol family CAN
+ *
+ * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
+ * All rights reserved.
+ *
+ * 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, the following disclaimer and
+ *the referenced file 'COPYING'.
+ * 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. Neither the name of Volkswagen nor the names of its contributors
+ *may be used to endorse or promote products derived from this software
+ *without specific prior written permission.
+ *
+ * Alternatively, provided that this notice is retained in full, this
+ * software may be distributed under the terms

  1   2   >