]> rtime.felk.cvut.cz Git - socketcan-devel.git/blob - patches/linux-2.6.21-rc3/can-networking-R180-2.6.21-rc3_X_Complete.diff
Added patches for socketcan Revision 180 for the current Kernel 2.6.21-rc3 .
[socketcan-devel.git] / patches / linux-2.6.21-rc3 / can-networking-R180-2.6.21-rc3_X_Complete.diff
1 diff -N -u -r a/CREDITS c/CREDITS
2 --- a/CREDITS   2007-03-09 09:51:49.000000000 +0100
3 +++ c/CREDITS   2007-03-09 13:39:10.000000000 +0100
4 @@ -1324,6 +1324,14 @@
5  S: 5623 HZ Eindhoven
6  S: The Netherlands
7  
8 +N: Oliver Hartkopp
9 +E: oliver.hartkopp@volkswagen.de
10 +W: http://www.volkswagen.de
11 +D: Controller Area Network (network layer core)
12 +S: Brieffach 1776
13 +S: 38436 Wolfsburg
14 +S: Germany 
15 +
16  N: Andrew Haylett
17  E: ajh@primag.co.uk
18  D: Selection mechanism
19 @@ -3277,6 +3285,14 @@
20  S: F-35042 Rennes Cedex
21  S: France
22  
23 +N: Urs Thuermann
24 +E: urs.thuermann@volkswagen.de
25 +W: http://www.volkswagen.de
26 +D: Controller Area Network (network layer core)
27 +S: Brieffach 1776
28 +S: 38436 Wolfsburg
29 +S: Germany 
30 +
31  N: Jon Tombs
32  E: jon@gte.esi.us.es
33  W: http://www.esi.us.es/~jon
34 diff -N -u -r a/drivers/net/can/Kconfig c/drivers/net/can/Kconfig
35 --- a/drivers/net/can/Kconfig   1970-01-01 01:00:00.000000000 +0100
36 +++ c/drivers/net/can/Kconfig   2007-03-09 13:45:53.000000000 +0100
37 @@ -0,0 +1,26 @@
38 +menu "CAN Device Drivers"
39 +       depends on CAN
40 +
41 +config CAN_VCAN
42 +       tristate "Virtual Local CAN Interface (vcan)"
43 +       depends on CAN
44 +       default N
45 +       ---help---
46 +         Similar to the network loopback devices, vcan offers a
47 +         virtual local CAN interface.
48 +
49 +         This driver can also be built as a module.  If so, the module
50 +         will be called vcan.
51 +
52 +config CAN_DEBUG_DEVICES
53 +       bool "CAN devices debugging messages"
54 +       depends on CAN
55 +       default N
56 +       ---help---
57 +         Say Y here if you want the CAN device drivers to produce a bunch of
58 +         debug messages to the system log.  Select this if you are having
59 +         a problem with CAN support and want to see more of what is going
60 +         on.
61 +
62 +endmenu
63 +
64 diff -N -u -r a/drivers/net/can/Makefile c/drivers/net/can/Makefile
65 --- a/drivers/net/can/Makefile  1970-01-01 01:00:00.000000000 +0100
66 +++ c/drivers/net/can/Makefile  2007-03-09 13:45:53.000000000 +0100
67 @@ -0,0 +1,5 @@
68 +#
69 +#  Makefile for the Linux Controller Area Network drivers.
70 +#
71 +
72 +obj-$(CONFIG_CAN_VCAN)         += vcan.o
73 diff -N -u -r a/drivers/net/can/vcan.c c/drivers/net/can/vcan.c
74 --- a/drivers/net/can/vcan.c    1970-01-01 01:00:00.000000000 +0100
75 +++ c/drivers/net/can/vcan.c    2007-03-09 13:45:53.000000000 +0100
76 @@ -0,0 +1,301 @@
77 +/*
78 + * vcan.c - Virtual CAN interface
79 + *
80 + * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
81 + * All rights reserved.
82 + *
83 + * Redistribution and use in source and binary forms, with or without
84 + * modification, are permitted provided that the following conditions
85 + * are met:
86 + * 1. Redistributions of source code must retain the above copyright
87 + *    notice, this list of conditions, the following disclaimer and
88 + *    the referenced file 'COPYING'.
89 + * 2. Redistributions in binary form must reproduce the above copyright
90 + *    notice, this list of conditions and the following disclaimer in the
91 + *    documentation and/or other materials provided with the distribution.
92 + * 3. Neither the name of Volkswagen nor the names of its contributors
93 + *    may be used to endorse or promote products derived from this software
94 + *    without specific prior written permission.
95 + *
96 + * Alternatively, provided that this notice is retained in full, this
97 + * software may be distributed under the terms of the GNU General
98 + * Public License ("GPL") version 2 as distributed in the 'COPYING'
99 + * file from the main directory of the linux kernel source.
100 + *
101 + * The provided data structures and external interfaces from this code
102 + * are not restricted to be used by modules with a GPL compatible license.
103 + *
104 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
105 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
106 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
107 + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
108 + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
109 + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
110 + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
111 + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
112 + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
113 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
114 + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
115 + * DAMAGE.
116 + *
117 + * Send feedback to <socketcan-users@lists.berlios.de>
118 + *
119 + */
120 +
121 +#include <linux/autoconf.h>
122 +#include <linux/module.h>
123 +#include <linux/init.h>
124 +#include <linux/netdevice.h>
125 +#include <linux/if_arp.h>
126 +#include <linux/if_ether.h>
127 +
128 +#include <linux/can.h>
129 +#include <linux/can/version.h>
130 +
131 +RCSID("$Id: vcan.c 168 2007-03-05 13:33:59Z hartkopp $");
132 +
133 +static __initdata const char banner[] = KERN_INFO "CAN: virtual CAN "
134 +                                       "interface " VERSION "\n"; 
135 +
136 +MODULE_DESCRIPTION("virtual CAN interface");
137 +MODULE_LICENSE("Dual BSD/GPL");
138 +MODULE_AUTHOR("Urs Thuermann <urs.thuermann@volkswagen.de>");
139 +
140 +#ifdef CONFIG_CAN_DEBUG_DEVICES
141 +static int debug = 0;
142 +module_param(debug, int, S_IRUGO);
143 +#define DBG(args...)       (debug & 1 ? \
144 +                              (printk(KERN_DEBUG "VCAN %s: ", __func__), \
145 +                               printk(args)) : 0)
146 +#define DBG_FRAME(args...) (debug & 2 ? can_debug_cframe(args) : 0)
147 +#define DBG_SKB(skb)       (debug & 4 ? can_debug_skb(skb) : 0)
148 +#else
149 +#define DBG(args...)
150 +#define DBG_FRAME(args...)
151 +#define DBG_SKB(skb)
152 +#endif
153 +
154 +/* Indicate if this VCAN driver should do a real loopback, or if this */
155 +/* should be done in af_can.c */
156 +#undef  DO_LOOPBACK
157 +
158 +#define STATSIZE sizeof(struct net_device_stats)
159 +
160 +static int numdev = 4; /* default number of virtual CAN interfaces */
161 +module_param(numdev, int, S_IRUGO);
162 +MODULE_PARM_DESC(numdev, "Number of virtual CAN devices");
163 +
164 +static struct net_device **vcan_devs; /* root pointer to netdevice structs */
165 +
166 +static int vcan_open(struct net_device *dev)
167 +{
168 +       DBG("%s: interface up\n", dev->name);
169 +
170 +       netif_start_queue(dev);
171 +       return 0;
172 +}
173 +
174 +static int vcan_stop(struct net_device *dev)
175 +{
176 +       DBG("%s: interface down\n", dev->name);
177 +
178 +       netif_stop_queue(dev);
179 +       return 0;
180 +}
181 +
182 +#ifdef DO_LOOPBACK
183 +
184 +static void vcan_rx(struct sk_buff *skb, struct net_device *dev)
185 +{
186 +       struct net_device_stats *stats = netdev_priv(dev);
187 +       stats->rx_packets++;
188 +       stats->rx_bytes += skb->len;
189 +
190 +       skb->protocol  = htons(ETH_P_CAN);
191 +       skb->dev       = dev;
192 +       skb->ip_summed = CHECKSUM_UNNECESSARY;
193 +
194 +       DBG("received skbuff on interface %d\n", dev->ifindex);
195 +       DBG_SKB(skb);
196 +
197 +       netif_rx(skb);
198 +}
199 +
200 +#endif
201 +
202 +static int vcan_tx(struct sk_buff *skb, struct net_device *dev)
203 +{
204 +       struct net_device_stats *stats = netdev_priv(dev);
205 +       int loop;
206 +
207 +       DBG("sending skbuff on interface %s\n", dev->name);
208 +       DBG_SKB(skb);
209 +       DBG_FRAME("VCAN: transmit CAN frame", (struct can_frame *)skb->data);
210 +
211 +       stats->tx_packets++;
212 +       stats->tx_bytes += skb->len;
213 +
214 +       loop = *(struct sock **)skb->cb != NULL;   /* loopback required */
215 +
216 +#ifdef DO_LOOPBACK
217 +       if (loop) {
218 +               if (atomic_read(&skb->users) != 1) {
219 +                       struct sk_buff *old_skb = skb;
220 +                       skb = skb_clone(old_skb, GFP_ATOMIC);
221 +                       DBG("  freeing old skbuff %p, using new skbuff %p\n",
222 +                           old_skb, skb);
223 +                       kfree_skb(old_skb);
224 +                       if (!skb) {
225 +                               return 0;
226 +                       }
227 +               } else
228 +                       skb_orphan(skb);
229 +
230 +               vcan_rx(skb, dev); /* with packet counting */
231 +       } else {
232 +               /* no looped packets => no counting */
233 +               kfree_skb(skb);
234 +       }
235 +#else
236 +       /* only count, when the CAN core did a loopback */
237 +       if (loop) {
238 +               stats->rx_packets++;
239 +               stats->rx_bytes += skb->len;
240 +       }
241 +       kfree_skb(skb);
242 +#endif
243 +       return 0;
244 +}
245 +
246 +static int vcan_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
247 +{
248 +       return -EOPNOTSUPP;
249 +}
250 +
251 +static int vcan_rebuild_header(struct sk_buff *skb)
252 +{
253 +       DBG("skbuff %p\n", skb);
254 +       DBG_SKB(skb);
255 +       return 0;
256 +}
257 +
258 +static int vcan_header(struct sk_buff *skb, struct net_device *dev,
259 +                      unsigned short type, void *daddr, void *saddr,
260 +                      unsigned int len)
261 +{
262 +       DBG("skbuff %p, device %p\n", skb, dev);
263 +       DBG_SKB(skb);
264 +       return 0;
265 +}
266 +
267 +
268 +static struct net_device_stats *vcan_get_stats(struct net_device *dev)
269 +{
270 +       struct net_device_stats *stats = netdev_priv(dev);
271 +       return stats;
272 +}
273 +
274 +static void vcan_init(struct net_device *dev)
275 +{
276 +       DBG("dev %s\n", dev->name);
277 +
278 +       ether_setup(dev);
279 +
280 +       memset(dev->priv, 0, STATSIZE);
281 +
282 +       dev->type              = ARPHRD_CAN;
283 +       dev->mtu               = sizeof(struct can_frame);
284 +       dev->flags             = IFF_NOARP;
285 +#ifdef DO_LOOPBACK
286 +       dev->flags            |= IFF_LOOPBACK;
287 +#endif
288 +
289 +       dev->open              = vcan_open;
290 +       dev->stop              = vcan_stop;
291 +       dev->set_config        = NULL;
292 +       dev->hard_start_xmit   = vcan_tx;
293 +       dev->do_ioctl          = vcan_ioctl;
294 +       dev->get_stats         = vcan_get_stats;
295 +       dev->hard_header       = vcan_header;
296 +       dev->rebuild_header    = vcan_rebuild_header;
297 +       dev->hard_header_cache = NULL;
298 +
299 +       SET_MODULE_OWNER(dev);
300 +}
301 +
302 +static __init int vcan_init_module(void)
303 +{
304 +       int i, ndev = 0, result = 0;
305 +
306 +       printk(banner);
307 +
308 +       if (numdev < 1)
309 +               numdev = 1; /* register at least one interface */
310 +
311 +       printk(KERN_INFO "vcan: registering %d virtual CAN interfaces.\n",
312 +              numdev );
313 +
314 +       vcan_devs = kmalloc(numdev * sizeof(struct net_device *), GFP_KERNEL);
315 +       if (!vcan_devs) {
316 +               printk(KERN_ERR "vcan: Can't allocate vcan devices array!\n");
317 +               return -ENOMEM;
318 +       }
319 +
320 +       /* Clear the pointer array */
321 +       memset(vcan_devs, 0, numdev * sizeof(struct net_device *));
322 +
323 +       for (i = 0; i < numdev; i++) {
324 +               if (!(vcan_devs[i] = alloc_netdev(STATSIZE, "vcan%d",
325 +                                                 vcan_init))) {
326 +                       printk(KERN_ERR "vcan: error allocating net_device\n");
327 +                       result = -ENOMEM;
328 +                       goto out;
329 +               } else if ((result = register_netdev(vcan_devs[i])) < 0) {
330 +                       printk(KERN_ERR "vcan: error %d registering "
331 +                              "interface %s\n",
332 +                              result, vcan_devs[i]->name);
333 +                       free_netdev(vcan_devs[i]);
334 +                       vcan_devs[i] = NULL;
335 +                       goto out;
336 +               } else {
337 +                       DBG("successfully registered interface %s\n",
338 +                           vcan_devs[i]->name);
339 +                       ndev++;
340 +               }
341 +       }
342 +
343 +       if (ndev)
344 +               return 0;
345 +
346 + out:
347 +       for (i = 0; i < numdev; i++) {
348 +               if (vcan_devs[i]) {
349 +                       unregister_netdev(vcan_devs[i]);
350 +                       free_netdev(vcan_devs[i]);
351 +               }
352 +       }
353 +
354 +       kfree(vcan_devs);
355 +
356 +       return result;
357 +}
358 +
359 +static __exit void vcan_cleanup_module(void)
360 +{
361 +       int i;
362 +
363 +       if (!vcan_devs)
364 +               return;
365 +
366 +       for (i = 0; i < numdev; i++) {
367 +               if (vcan_devs[i]) {
368 +                       unregister_netdev(vcan_devs[i]);
369 +                       free_netdev(vcan_devs[i]);
370 +               }
371 +       }
372 +
373 +       kfree(vcan_devs);
374 +}
375 +
376 +module_init(vcan_init_module);
377 +module_exit(vcan_cleanup_module);
378 diff -N -u -r a/drivers/net/Makefile c/drivers/net/Makefile
379 --- a/drivers/net/Makefile      2007-03-09 09:52:04.000000000 +0100
380 +++ c/drivers/net/Makefile      2007-03-09 13:39:10.000000000 +0100
381 @@ -8,6 +8,7 @@
382  obj-$(CONFIG_CHELSIO_T1) += chelsio/
383  obj-$(CONFIG_CHELSIO_T3) += cxgb3/
384  obj-$(CONFIG_EHEA) += ehea/
385 +obj-$(CONFIG_CAN) += can/
386  obj-$(CONFIG_BONDING) += bonding/
387  obj-$(CONFIG_ATL1) += atl1/
388  obj-$(CONFIG_GIANFAR) += gianfar_driver.o
389 diff -N -u -r a/include/linux/can/bcm.h c/include/linux/can/bcm.h
390 --- a/include/linux/can/bcm.h   1970-01-01 01:00:00.000000000 +0100
391 +++ c/include/linux/can/bcm.h   2007-03-07 17:13:13.000000000 +0100
392 @@ -0,0 +1,56 @@
393 +/*
394 + * linux/can/bcm.h
395 + *
396 + * Definitions for CAN Broadcast Manager (BCM)
397 + *
398 + * $Id: bcm.h 176 2007-03-07 16:12:46Z hartkopp $
399 + *
400 + * Author: Oliver Hartkopp <oliver.hartkopp@volkswagen.de>
401 + * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
402 + * All rights reserved.
403 + *
404 + * Send feedback to <socketcan-users@lists.berlios.de>
405 + *
406 + */
407 +
408 +#ifndef CAN_BCM_H
409 +#define CAN_BCM_H
410 +
411 +struct bcm_msg_head {
412 +       int opcode;                   /* command */
413 +       int flags;                    /* special flags */
414 +       int count;                    /* run 'count' times ival1 then ival2 */
415 +       struct timeval ival1, ival2;  /* intervals */
416 +       canid_t can_id;               /* 32 Bit SFF/EFF. MSB set at EFF */
417 +       int nframes;                  /* number of following can_frame's */
418 +       struct can_frame frames[0];
419 +};
420 +
421 +enum {
422 +       TX_SETUP = 1,   /* create (cyclic) transmission task */
423 +       TX_DELETE,      /* remove (cyclic) transmission task */
424 +       TX_READ,        /* read properties of (cyclic) transmission task */
425 +       TX_SEND,        /* send one CAN frame */
426 +       RX_SETUP,       /* create RX content filter subscription */
427 +       RX_DELETE,      /* remove RX content filter subscription */
428 +       RX_READ,        /* read properties of RX content filter subscription */
429 +       TX_STATUS,      /* reply to TX_READ request */
430 +       TX_EXPIRED,     /* notification on performed transmissions (count=0) */
431 +       RX_STATUS,      /* reply to RX_READ request */
432 +       RX_TIMEOUT,     /* cyclic message is absent */
433 +       RX_CHANGED      /* updated CAN frame (detected content change) */
434 +};
435 +
436 +#define SETTIMER            0x0001
437 +#define STARTTIMER          0x0002
438 +#define TX_COUNTEVT         0x0004
439 +#define TX_ANNOUNCE         0x0008
440 +#define TX_CP_CAN_ID        0x0010
441 +#define RX_FILTER_ID        0x0020
442 +#define RX_CHECK_DLC        0x0040
443 +#define RX_NO_AUTOTIMER     0x0080
444 +#define RX_ANNOUNCE_RESUME  0x0100
445 +#define TX_RESET_MULTI_IDX  0x0200
446 +#define RX_RTR_FRAME        0x0400
447 +
448 +#endif /* CAN_BCM_H */
449 diff -N -u -r a/include/linux/can/core.h c/include/linux/can/core.h
450 --- a/include/linux/can/core.h  1970-01-01 01:00:00.000000000 +0100
451 +++ c/include/linux/can/core.h  2007-03-08 12:03:06.000000000 +0100
452 @@ -0,0 +1,62 @@
453 +/*
454 + * linux/can/core.h
455 + *
456 + * Protoypes and definitions for CAN protocol modules using the PF_CAN core
457 + *
458 + * $Id: core.h 177 2007-03-08 11:02:43Z hartkopp $
459 + *
460 + * Authors: Oliver Hartkopp <oliver.hartkopp@volkswagen.de>
461 + *          Urs Thuermann   <urs.thuermann@volkswagen.de>
462 + * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
463 + * All rights reserved.
464 + *
465 + * Send feedback to <socketcan-users@lists.berlios.de>
466 + *
467 + */
468 +
469 +#ifndef CAN_CORE_H
470 +#define CAN_CORE_H
471 +
472 +#include <linux/can.h>
473 +#include <linux/skbuff.h>
474 +#include <linux/netdevice.h>
475 +
476 +#define DNAME(dev) ((dev) ? (dev)->name : "any")
477 +
478 +#define CAN_PROC_DIR "net/can" /* /proc/... */
479 +
480 +struct can_proto {
481 +       int              type;
482 +       int              protocol;
483 +       int              capability;
484 +       struct proto_ops *ops;
485 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,13)
486 +       struct proto     *prot;
487 +#else
488 +       struct module    *owner;
489 +       int              (*init)(struct sock *sk);
490 +       size_t           obj_size;
491 +#endif
492 +};
493 +
494 +/* function prototypes for the CAN networklayer core (af_can.c) */
495 +
496 +void can_debug_skb(struct sk_buff *skb);
497 +void can_debug_cframe(const char *msg, struct can_frame *cframe, ...);
498 +
499 +void can_proto_register(struct can_proto *cp);
500 +void can_proto_unregister(struct can_proto *cp);
501 +int  can_rx_register(struct net_device *dev, canid_t can_id, canid_t mask,
502 +                    void (*func)(struct sk_buff *, void *), void *data,
503 +                    char *ident);
504 +int  can_rx_unregister(struct net_device *dev, canid_t can_id, canid_t mask,
505 +                      void (*func)(struct sk_buff *, void *), void *data);
506 +void can_dev_register(struct net_device *dev,
507 +                     void (*func)(unsigned long msg, void *), void *data);
508 +void can_dev_unregister(struct net_device *dev,
509 +                       void (*func)(unsigned long msg, void *), void *data);
510 +int  can_send(struct sk_buff *skb, int loop);
511 +
512 +unsigned long timeval2jiffies(struct timeval *tv, int round_up);
513 +
514 +#endif /* CAN_CORE_H */
515 diff -N -u -r a/include/linux/can/error.h c/include/linux/can/error.h
516 --- a/include/linux/can/error.h 1970-01-01 01:00:00.000000000 +0100
517 +++ c/include/linux/can/error.h 2007-03-05 09:25:43.000000000 +0100
518 @@ -0,0 +1,95 @@
519 +/*
520 + * linux/can/error.h
521 + *
522 + * Definitions of the CAN error frame to be filtered and passed to the user.
523 + *
524 + * $Id: error.h 162 2007-03-05 08:25:02Z hartkopp $
525 + *
526 + * Author: Oliver Hartkopp <oliver.hartkopp@volkswagen.de>
527 + * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
528 + * All rights reserved.
529 + *
530 + * Send feedback to <socketcan-users@lists.berlios.de>
531 + *
532 + */
533 +
534 +#ifndef CAN_ERROR_H
535 +#define CAN_ERROR_H
536 +
537 +#define CAN_ERR_DLC 8 /* dlc for error frames */
538 +
539 +/* error class (mask) in can_id */
540 +#define CAN_ERR_TX_TIMEOUT   0x00000001U /* TX timeout (by netdevice driver) */
541 +#define CAN_ERR_LOSTARB      0x00000002U /* lost arbitration    / data[0]    */
542 +#define CAN_ERR_CRTL         0x00000004U /* controller problems / data[1]    */
543 +#define CAN_ERR_PROT         0x00000008U /* protocol violations / data[2..3] */
544 +#define CAN_ERR_TRX          0x00000010U /* transceiver status  / data[4]    */
545 +#define CAN_ERR_ACK          0x00000020U /* received no ACK on transmission */
546 +#define CAN_ERR_BUSOFF       0x00000040U /* bus off */
547 +#define CAN_ERR_BUSERROR     0x00000080U /* bus error (may flood!) */
548 +#define CAN_ERR_RESTARTED    0x00000100U /* controller restarted */
549 +
550 +/* arbitration lost in bit ... / data[0] */
551 +#define CAN_ERR_LOSTARB_UNSPEC   0x00 /* unspecified */
552 +                                     /* else bit number in bitstream */
553 +
554 +/* error status of CAN-controller / data[1] */
555 +#define CAN_ERR_CRTL_UNSPEC      0x00 /* unspecified */
556 +#define CAN_ERR_CRTL_RX_OVERFLOW 0x01 /* RX buffer overflow */
557 +#define CAN_ERR_CRTL_TX_OVERFLOW 0x02 /* TX buffer overflow */
558 +#define CAN_ERR_CRTL_RX_WARNING  0x04 /* reached warning level for RX errors */
559 +#define CAN_ERR_CRTL_TX_WARNING  0x08 /* reached warning level for TX errors */
560 +#define CAN_ERR_CRTL_RX_PASSIVE  0x10 /* reached error passive status RX */
561 +#define CAN_ERR_CRTL_TX_PASSIVE  0x20 /* reached error passive status TX */
562 +                                     /* (at least one error counter exceeds */
563 +                                     /* the protocol-defined level of 127)  */
564 +
565 +/* error in CAN protocol (type) / data[2] */
566 +#define CAN_ERR_PROT_UNSPEC      0x00 /* unspecified */
567 +#define CAN_ERR_PROT_BIT         0x01 /* single bit error */
568 +#define CAN_ERR_PROT_FORM        0x02 /* frame format error */
569 +#define CAN_ERR_PROT_STUFF       0x04 /* bit stuffing error */
570 +#define CAN_ERR_PROT_BIT0        0x08 /* unable to send dominant bit */
571 +#define CAN_ERR_PROT_BIT1        0x10 /* unable to send recessive bit */
572 +#define CAN_ERR_PROT_OVERLOAD    0x20 /* bus overload */
573 +#define CAN_ERR_PROT_ACTIVE      0x40 /* active error announcement */
574 +#define CAN_ERR_PROT_TX          0x80 /* error occured on transmission */
575 +
576 +/* error in CAN protocol (location) / data[3] */
577 +#define CAN_ERR_PROT_LOC_UNSPEC  0x00 /* unspecified */
578 +#define CAN_ERR_PROT_LOC_SOF     0x03 /* start of frame */
579 +#define CAN_ERR_PROT_LOC_ID28_21 0x02 /* ID bits 28 - 21 (SFF: 10 - 3) */
580 +#define CAN_ERR_PROT_LOC_ID20_18 0x06 /* ID bits 20 - 18 (SFF: 2 - 0 )*/
581 +#define CAN_ERR_PROT_LOC_SRTR    0x04 /* substitute RTR (SFF: RTR) */
582 +#define CAN_ERR_PROT_LOC_IDE     0x05 /* identifier extension */
583 +#define CAN_ERR_PROT_LOC_ID17_13 0x07 /* ID bits 17-13 */
584 +#define CAN_ERR_PROT_LOC_ID12_05 0x0F /* ID bits 12-5 */
585 +#define CAN_ERR_PROT_LOC_ID04_00 0x0E /* ID bits 4-0 */
586 +#define CAN_ERR_PROT_LOC_RTR     0x0C /* RTR */
587 +#define CAN_ERR_PROT_LOC_RES1    0x0D /* reserved bit 1 */
588 +#define CAN_ERR_PROT_LOC_RES0    0x09 /* reserved bit 0 */
589 +#define CAN_ERR_PROT_LOC_DLC     0x0B /* data length code */
590 +#define CAN_ERR_PROT_LOC_DATA    0x0A /* data section */
591 +#define CAN_ERR_PROT_LOC_CRC_SEQ 0x08 /* CRC sequence */
592 +#define CAN_ERR_PROT_LOC_CRC_DEL 0x18 /* CRC delimiter */
593 +#define CAN_ERR_PROT_LOC_ACK     0x19 /* ACK slot */
594 +#define CAN_ERR_PROT_LOC_ACK_DEL 0x1B /* ACK delimiter */
595 +#define CAN_ERR_PROT_LOC_EOF     0x1A /* end of frame */
596 +#define CAN_ERR_PROT_LOC_INTERM  0x12 /* intermission */
597 +
598 +/* error status of CAN-transceiver / data[4] */
599 +/*                                             CANH CANL */
600 +#define CAN_ERR_TRX_UNSPEC             0x00 /* 0000 0000 */
601 +#define CAN_ERR_TRX_CANH_NO_WIRE       0x04 /* 0000 0100 */
602 +#define CAN_ERR_TRX_CANH_SHORT_TO_BAT  0x05 /* 0000 0101 */
603 +#define CAN_ERR_TRX_CANH_SHORT_TO_VCC  0x06 /* 0000 0110 */
604 +#define CAN_ERR_TRX_CANH_SHORT_TO_GND  0x07 /* 0000 0111 */
605 +#define CAN_ERR_TRX_CANL_NO_WIRE       0x40 /* 0100 0000 */
606 +#define CAN_ERR_TRX_CANL_SHORT_TO_BAT  0x50 /* 0101 0000 */
607 +#define CAN_ERR_TRX_CANL_SHORT_TO_VCC  0x60 /* 0110 0000 */
608 +#define CAN_ERR_TRX_CANL_SHORT_TO_GND  0x70 /* 0111 0000 */
609 +#define CAN_ERR_TRX_CANL_SHORT_TO_CANH 0x80 /* 1000 0000 */
610 +
611 +/* controller specific additional information / data[5..7] */
612 +
613 +#endif /* CAN_ERROR_H */
614 diff -N -u -r a/include/linux/can/raw.h c/include/linux/can/raw.h
615 --- a/include/linux/can/raw.h   1970-01-01 01:00:00.000000000 +0100
616 +++ c/include/linux/can/raw.h   2007-03-07 17:13:13.000000000 +0100
617 @@ -0,0 +1,31 @@
618 +/*
619 + * linux/can/raw.h
620 + *
621 + * Definitions for raw CAN sockets
622 + *
623 + * $Id: raw.h 176 2007-03-07 16:12:46Z hartkopp $
624 + *
625 + * Authors: Oliver Hartkopp <oliver.hartkopp@volkswagen.de>
626 + *          Urs Thuermann   <urs.thuermann@volkswagen.de>
627 + * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
628 + * All rights reserved.
629 + *
630 + * Send feedback to <socketcan-users@lists.berlios.de>
631 + *
632 + */
633 +
634 +#ifndef CAN_RAW_H
635 +#define CAN_RAW_H
636 +
637 +#include <linux/can.h>
638 +
639 +#define SOL_CAN_RAW (SOL_CAN_BASE + CAN_RAW)
640 +
641 +/* for socket options affecting the socket (not the global system) */
642 +
643 +#define CAN_RAW_FILTER         1       /* set 0 .. n can_filter(s)          */
644 +#define CAN_RAW_ERR_FILTER     2       /* set filter for error frames       */
645 +#define CAN_RAW_LOOPBACK       3       /* local loopback (default:on)       */
646 +#define CAN_RAW_RECV_OWN_MSGS  4       /* receive my own msgs (default:off) */
647 +
648 +#endif
649 diff -N -u -r a/include/linux/can/version.h c/include/linux/can/version.h
650 --- a/include/linux/can/version.h       1970-01-01 01:00:00.000000000 +0100
651 +++ c/include/linux/can/version.h       2007-03-05 14:59:06.000000000 +0100
652 @@ -0,0 +1,40 @@
653 +/*
654 + * linux/can/version.h
655 + *
656 + * Version information for the CAN network layer implementation
657 +
658 + * Author: Urs Thuermann   <urs.thuermann@volkswagen.de>
659 + * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
660 + * All rights reserved.
661 + *
662 + * Send feedback to <socketcan-users@lists.berlios.de>
663 + *
664 + */
665 +
666 +#ifndef CAN_VERSION_H
667 +#define CAN_VERSION_H
668 +
669 +#define RCSID(s) asm(".section .rodata.str1.1,\"aMS\",@progbits,1\n\t" \
670 +                    ".string \"" s "\"\n\t.previous\n")
671 +
672 +RCSID("$Id: version.h 170 2007-03-05 13:58:26Z hartkopp $");
673 +
674 +#define MAJORVERSION 2
675 +#define MINORVERSION 0
676 +#define PATCHLEVEL   0
677 +#define EXTRAVERSION "-pre6"
678 +
679 +#define LLCF_VERSION_CODE (((MAJORVERSION) << 16) + ((MINORVERSION) << 8) \
680 +                               + (PATCHLEVEL))
681 +
682 +/* stringification:  these are the usual macros to stringify with macro
683 +   expansion.   The str() macro does the expansion, the xstr() macro is
684 +   for the actual stringification.
685 +*/
686 +#define str(arg) xstr(arg)
687 +#define xstr(arg) #arg
688 +
689 +#define VERSION str(MAJORVERSION) "." str(MINORVERSION) "." str(PATCHLEVEL) \
690 +       EXTRAVERSION
691 +
692 +#endif /* CAN_VERSION_H */
693 diff -N -u -r a/include/linux/can.h c/include/linux/can.h
694 --- a/include/linux/can.h       1970-01-01 01:00:00.000000000 +0100
695 +++ c/include/linux/can.h       2007-03-05 11:14:57.000000000 +0100
696 @@ -0,0 +1,77 @@
697 +/*
698 + * linux/can.h
699 + *
700 + * Definitions for CAN networklayer (socket addr / CAN frame / CAN filter)
701 + *
702 + * $Id: can.h 165 2007-03-05 10:14:18Z hartkopp $
703 + *
704 + * Authors: Oliver Hartkopp <oliver.hartkopp@volkswagen.de>
705 + *          Urs Thuermann   <urs.thuermann@volkswagen.de>
706 + * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
707 + * All rights reserved.
708 + *
709 + * Send feedback to <socketcan-users@lists.berlios.de>
710 + *
711 + */
712 +
713 +#ifndef CAN_H
714 +#define CAN_H
715 +
716 +#include <linux/version.h>
717 +#include <linux/types.h>
718 +#include <linux/socket.h>
719 +
720 +/* controller area network (CAN) kernel definitions */
721 +
722 +/* special address description flags for the CAN_ID */
723 +#define CAN_EFF_FLAG 0x80000000U /* EFF/SFF is set in the MSB */
724 +#define CAN_RTR_FLAG 0x40000000U /* remote transmission request */
725 +#define CAN_ERR_FLAG 0x20000000U /* error frame */
726 +
727 +/* valid bits in CAN ID for frame formats */
728 +#define CAN_SFF_MASK 0x000007FFU /* standard frame format (SFF) */
729 +#define CAN_EFF_MASK 0x1FFFFFFFU /* extended frame format (EFF) */
730 +#define CAN_ERR_MASK 0x1FFFFFFFU /* omit EFF, RTR, ERR flags */
731 +
732 +typedef __u32 canid_t;
733 +
734 +struct can_frame {
735 +       canid_t can_id;  /* 32 bit CAN_ID + EFF/RTR/ERR flags */
736 +       __u8    can_dlc; /* data length code: 0 .. 8 */
737 +       __u8    data[8] __attribute__ ((aligned(8)));
738 +};
739 +
740 +/* particular protocols of the protocol family PF_CAN */
741 +#define CAN_RAW                1 /* RAW sockets */
742 +#define CAN_BCM                2 /* Broadcast Manager */
743 +#define CAN_TP16       3 /* VAG Transport Protocol v1.6 */
744 +#define CAN_TP20       4 /* VAG Transport Protocol v2.0 */
745 +#define CAN_MCNET      5 /* Bosch MCNet */
746 +#define CAN_ISOTP      6 /* ISO 15765-2 Transport Protocol */
747 +#define CAN_BAP                7 /* VAG Bedien- und Anzeigeprotokoll */
748 +#define CAN_NPROTO     8
749 +
750 +#define SOL_CAN_BASE 100
751 +
752 +struct sockaddr_can {
753 +       sa_family_t   can_family;
754 +       int           can_ifindex;
755 +       union {
756 +               struct { canid_t rx_id, tx_id;   } tp16;
757 +               struct { canid_t rx_id, tx_id;   } tp20;
758 +               struct { canid_t rx_id, tx_id;   } mcnet;
759 +               struct { canid_t rx_id, tx_id;   } isotp;
760 +               struct { int     sg_id, sg_type; } bap;
761 +       } can_addr;
762 +};
763 +
764 +typedef canid_t can_err_mask_t;
765 +
766 +struct can_filter {
767 +       canid_t can_id;
768 +       canid_t can_mask;
769 +};
770 +
771 +#define CAN_INV_FILTER 0x20000000U /* to be set in can_filter.can_id */
772 +
773 +#endif /* CAN_H */
774 diff -N -u -r a/include/linux/if_arp.h c/include/linux/if_arp.h
775 --- a/include/linux/if_arp.h    2007-02-04 19:44:54.000000000 +0100
776 +++ c/include/linux/if_arp.h    2007-03-09 13:39:10.000000000 +0100
777 @@ -52,6 +52,7 @@
778  #define ARPHRD_ROSE    270
779  #define ARPHRD_X25     271             /* CCITT X.25                   */
780  #define ARPHRD_HWX25   272             /* Boards with X.25 in firmware */
781 +#define ARPHRD_CAN     280             /* Controller Area Network      */
782  #define ARPHRD_PPP     512
783  #define ARPHRD_CISCO   513             /* Cisco HDLC                   */
784  #define ARPHRD_HDLC    ARPHRD_CISCO
785 diff -N -u -r a/include/linux/if_ether.h c/include/linux/if_ether.h
786 --- a/include/linux/if_ether.h  2007-02-04 19:44:54.000000000 +0100
787 +++ c/include/linux/if_ether.h  2007-03-09 13:39:10.000000000 +0100
788 @@ -88,6 +88,7 @@
789  #define ETH_P_WAN_PPP   0x0007          /* Dummy type for WAN PPP frames*/
790  #define ETH_P_PPP_MP    0x0008          /* Dummy type for PPP MP frames */
791  #define ETH_P_LOCALTALK 0x0009         /* Localtalk pseudo type        */
792 +#define ETH_P_CAN      0x000C          /* Controller Area Network      */
793  #define ETH_P_PPPTALK  0x0010          /* Dummy type for Atalk over PPP*/
794  #define ETH_P_TR_802_2 0x0011          /* 802.2 frames                 */
795  #define ETH_P_MOBITEX  0x0015          /* Mobitex (kaz@cafe.net)       */
796 diff -N -u -r a/include/linux/socket.h c/include/linux/socket.h
797 --- a/include/linux/socket.h    2007-03-09 09:52:17.000000000 +0100
798 +++ c/include/linux/socket.h    2007-03-09 13:39:10.000000000 +0100
799 @@ -185,6 +185,7 @@
800  #define AF_PPPOX       24      /* PPPoX sockets                */
801  #define AF_WANPIPE     25      /* Wanpipe API Sockets */
802  #define AF_LLC         26      /* Linux LLC                    */
803 +#define AF_CAN         29      /* Controller Area Network      */
804  #define AF_TIPC                30      /* TIPC sockets                 */
805  #define AF_BLUETOOTH   31      /* Bluetooth sockets            */
806  #define AF_IUCV                32      /* IUCV sockets                 */
807 @@ -219,6 +220,7 @@
808  #define PF_PPPOX       AF_PPPOX
809  #define PF_WANPIPE     AF_WANPIPE
810  #define PF_LLC         AF_LLC
811 +#define PF_CAN         AF_CAN
812  #define PF_TIPC                AF_TIPC
813  #define PF_BLUETOOTH   AF_BLUETOOTH
814  #define PF_IUCV                AF_IUCV
815 diff -N -u -r a/include/linux/tty.h c/include/linux/tty.h
816 --- a/include/linux/tty.h       2007-03-09 09:52:17.000000000 +0100
817 +++ c/include/linux/tty.h       2007-03-09 13:39:10.000000000 +0100
818 @@ -24,7 +24,7 @@
819  #define NR_PTYS        CONFIG_LEGACY_PTY_COUNT   /* Number of legacy ptys */
820  #define NR_UNIX98_PTY_DEFAULT  4096      /* Default maximum for Unix98 ptys */
821  #define NR_UNIX98_PTY_MAX      (1 << MINORBITS) /* Absolute limit */
822 -#define NR_LDISCS              17
823 +#define NR_LDISCS              18
824  
825  /* line disciplines */
826  #define N_TTY          0
827 @@ -45,6 +45,7 @@
828  #define N_SYNC_PPP     14      /* synchronous PPP */
829  #define N_HCI          15      /* Bluetooth HCI UART */
830  #define N_GIGASET_M101 16      /* Siemens Gigaset M101 serial DECT adapter */
831 +#define N_SLCAN                17      /* Serial / USB serial CAN Adaptors */
832  
833  /*
834   * This character is the same as _POSIX_VDISABLE: it cannot be used as
835 diff -N -u -r a/MAINTAINERS c/MAINTAINERS
836 --- a/MAINTAINERS       2007-03-09 09:51:50.000000000 +0100
837 +++ c/MAINTAINERS       2007-03-09 13:39:10.000000000 +0100
838 @@ -856,6 +856,15 @@
839  T:     git kernel.org:/pub/scm/linux/kernel/git/mchehab/v4l-dvb.git
840  S:     Maintained
841  
842 +CAN NETWORK LAYER
843 +P:     Urs Thuermann
844 +M:     urs.thuermann@volkswagen.de
845 +P:     Oliver Hartkopp
846 +M:     oliver.hartkopp@volkswagen.de
847 +L:     socketcan-core@lists.berlios.de
848 +W:     http://developer.berlios.de/projects/socketcan/
849 +S:     Maintained
850 +
851  CALGARY x86-64 IOMMU
852  P:     Muli Ben-Yehuda
853  M:     muli@il.ibm.com
854 diff -N -u -r a/net/can/af_can.c c/net/can/af_can.c
855 --- a/net/can/af_can.c  1970-01-01 01:00:00.000000000 +0100
856 +++ c/net/can/af_can.c  2007-03-09 13:47:12.000000000 +0100
857 @@ -0,0 +1,973 @@
858 +/*
859 + * af_can.c - Protocol family CAN core module
860 + *            (used by different CAN protocol modules)
861 + *
862 + * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
863 + * All rights reserved.
864 + *
865 + * Redistribution and use in source and binary forms, with or without
866 + * modification, are permitted provided that the following conditions
867 + * are met:
868 + * 1. Redistributions of source code must retain the above copyright
869 + *    notice, this list of conditions, the following disclaimer and
870 + *    the referenced file 'COPYING'.
871 + * 2. Redistributions in binary form must reproduce the above copyright
872 + *    notice, this list of conditions and the following disclaimer in the
873 + *    documentation and/or other materials provided with the distribution.
874 + * 3. Neither the name of Volkswagen nor the names of its contributors
875 + *    may be used to endorse or promote products derived from this software
876 + *    without specific prior written permission.
877 + *
878 + * Alternatively, provided that this notice is retained in full, this
879 + * software may be distributed under the terms of the GNU General
880 + * Public License ("GPL") version 2 as distributed in the 'COPYING'
881 + * file from the main directory of the linux kernel source.
882 + *
883 + * The provided data structures and external interfaces from this code
884 + * are not restricted to be used by modules with a GPL compatible license.
885 + *
886 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
887 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
888 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
889 + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
890 + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
891 + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
892 + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
893 + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
894 + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
895 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
896 + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
897 + * DAMAGE.
898 + *
899 + * Send feedback to <socketcan-users@lists.berlios.de>
900 + *
901 + */
902 +
903 +#include <linux/autoconf.h>
904 +#include <linux/module.h>
905 +#include <linux/version.h>
906 +#include <linux/slab.h>
907 +#include <linux/kmod.h>
908 +#include <linux/init.h>
909 +#include <linux/list.h>
910 +#include <linux/spinlock.h>
911 +#include <linux/rcupdate.h>
912 +#include <linux/socket.h>
913 +#include <linux/if_ether.h>
914 +#include <linux/if_arp.h>
915 +#include <linux/skbuff.h>
916 +#include <linux/net.h>
917 +#include <linux/netdevice.h>
918 +#include <net/sock.h>
919 +#include <asm/uaccess.h>
920 +
921 +#include <linux/can.h>
922 +#include <linux/can/core.h>
923 +#include <linux/can/version.h>
924 +
925 +#include "af_can.h"
926 +
927 +
928 +RCSID("$Id: af_can.c 177 2007-03-08 11:02:43Z hartkopp $");
929 +
930 +#define IDENT "af_can"
931 +static __initdata const char banner[] = KERN_INFO "CAN: Controller Area "
932 +                                       "Network PF_CAN core " VERSION "\n"; 
933 +
934 +MODULE_DESCRIPTION("Controller Area Network PF_CAN core");
935 +MODULE_LICENSE("Dual BSD/GPL");
936 +MODULE_AUTHOR("Urs Thuermann <urs.thuermann@volkswagen.de>, "
937 +             "Oliver Hartkopp <oliver.hartkopp@volkswagen.de>");
938 +
939 +int stats_timer = 1; /* default: on */
940 +module_param(stats_timer, int, S_IRUGO);
941 +
942 +#ifdef CONFIG_CAN_DEBUG_CORE
943 +static int debug = 0;
944 +module_param(debug, int, S_IRUGO);
945 +#define DBG(args...)       (debug & 1 ? \
946 +                              (printk(KERN_DEBUG "CAN %s: ", __func__), \
947 +                               printk(args)) : 0)
948 +#define DBG_FRAME(args...) (debug & 2 ? can_debug_cframe(args) : 0)
949 +#define DBG_SKB(skb)       (debug & 4 ? can_debug_skb(skb) : 0)
950 +#else
951 +#define DBG(args...)
952 +#define DBG_FRAME(args...)
953 +#define DBG_SKB(skb)
954 +#endif
955 +
956 +static __init int  can_init(void);
957 +static __exit void can_exit(void);
958 +
959 +static int can_create(struct socket *sock, int protocol);
960 +static int can_notifier(struct notifier_block *nb,
961 +                       unsigned long msg, void *data);
962 +static int can_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg);
963 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,14)
964 +static int can_rcv(struct sk_buff *skb, struct net_device *dev,
965 +                  struct packet_type *pt, struct net_device *orig_dev);
966 +#else
967 +static int can_rcv(struct sk_buff *skb, struct net_device *dev,
968 +                  struct packet_type *pt);
969 +#endif
970 +static int can_rcv_filter(struct dev_rcv_lists *d, struct sk_buff *skb);
971 +static struct dev_rcv_lists *find_dev_rcv_lists(struct net_device *dev);
972 +static struct hlist_head *find_rcv_list(canid_t *can_id, canid_t *mask,
973 +                                       struct dev_rcv_lists *d);
974 +static void can_rcv_lists_delete(struct rcu_head *rp);
975 +static void can_rx_delete(struct rcu_head *rp);
976 +static void can_rx_delete_all(struct hlist_head *rl);
977 +
978 +
979 +struct notifier {
980 +       struct list_head list;
981 +       struct net_device *dev;
982 +       void (*func)(unsigned long msg, void *data);
983 +       void *data;
984 +};
985 +
986 +static LIST_HEAD(notifier_list);
987 +static rwlock_t notifier_lock = RW_LOCK_UNLOCKED;
988 +
989 +HLIST_HEAD(rx_dev_list);
990 +static struct dev_rcv_lists rx_alldev_list;
991 +static spinlock_t rcv_lists_lock = SPIN_LOCK_UNLOCKED;
992 +
993 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
994 +static struct kmem_cache *rcv_cache __read_mostly;
995 +#else
996 +static kmem_cache_t *rcv_cache;
997 +#endif
998 +
999 +static struct packet_type can_packet = {
1000 +       .type = __constant_htons(ETH_P_CAN),
1001 +       .dev  = NULL,
1002 +       .func = can_rcv,
1003 +};
1004 +
1005 +static struct net_proto_family can_family_ops = {
1006 +       .family = PF_CAN,
1007 +       .create = can_create,
1008 +       .owner  = THIS_MODULE,
1009 +};
1010 +
1011 +/* notifier block for netdevice event */
1012 +static struct notifier_block can_netdev_notifier = {
1013 +       .notifier_call = can_notifier,
1014 +};
1015 +
1016 +/* table of registered CAN protocols */
1017 +static struct can_proto *proto_tab[CAN_NPROTO];
1018 +
1019 +extern struct timer_list stattimer; /* timer for statistics update */
1020 +extern struct s_stats  stats;       /* packet statistics */
1021 +extern struct s_pstats pstats;      /* receive list statistics */
1022 +
1023 +module_init(can_init);
1024 +module_exit(can_exit);
1025 +
1026 +/**************************************************/
1027 +/* af_can module init/exit functions              */
1028 +/**************************************************/
1029 +
1030 +static __init int can_init(void)
1031 +{
1032 +       printk(banner);
1033 +
1034 +       rcv_cache = kmem_cache_create("can_receiver", sizeof(struct receiver),
1035 +                                     0, 0, NULL, NULL);
1036 +       if (!rcv_cache)
1037 +               return -ENOMEM;
1038 +
1039 +       /* Insert struct dev_rcv_lists for reception on all devices.
1040 +          This struct is zero initialized which is correct for the 
1041 +          embedded hlist heads, the dev pointer, and the entries counter.
1042 +       */
1043 +
1044 +       spin_lock_bh(&rcv_lists_lock);
1045 +       hlist_add_head_rcu(&rx_alldev_list.list, &rx_dev_list);
1046 +       spin_unlock_bh(&rcv_lists_lock);
1047 +
1048 +       if (stats_timer) {
1049 +               /* statistics init */
1050 +               init_timer(&stattimer);
1051 +       }
1052 +
1053 +       /* procfs init */
1054 +       can_init_proc();
1055 +
1056 +       /* protocol register */
1057 +       sock_register(&can_family_ops);
1058 +       register_netdevice_notifier(&can_netdev_notifier);
1059 +       dev_add_pack(&can_packet);
1060 +
1061 +       return 0;
1062 +}
1063 +
1064 +static __exit void can_exit(void)
1065 +{
1066 +       struct dev_rcv_lists *d;
1067 +       struct hlist_node *n, *next;
1068 +
1069 +       if (stats_timer) {
1070 +               /* stop statistics timer */
1071 +               del_timer(&stattimer);
1072 +       }
1073 +
1074 +       /* procfs remove */
1075 +       can_remove_proc();
1076 +
1077 +       /* protocol unregister */
1078 +       dev_remove_pack(&can_packet);
1079 +       unregister_netdevice_notifier(&can_netdev_notifier);
1080 +       sock_unregister(PF_CAN);
1081 +
1082 +       /* remove rx_dev_list */
1083 +       spin_lock_bh(&rcv_lists_lock);
1084 +       hlist_del(&rx_alldev_list.list);
1085 +       hlist_for_each_entry_safe(d, n, next, &rx_dev_list, list) {
1086 +               hlist_del(&d->list);
1087 +               kfree(d);
1088 +       }
1089 +       spin_unlock_bh(&rcv_lists_lock);
1090 +
1091 +       kmem_cache_destroy(rcv_cache);
1092 +}
1093 +
1094 +/**************************************************/
1095 +/* af_can protocol functions                      */
1096 +/**************************************************/
1097 +
1098 +void can_proto_register(struct can_proto *cp)
1099 +{
1100 +       int proto = cp->protocol;
1101 +       if (proto < 0 || proto >= CAN_NPROTO) {
1102 +               printk(KERN_ERR "CAN: protocol number %d out "
1103 +                      "of range\n", proto);
1104 +               return;
1105 +       }
1106 +       if (proto_tab[proto]) {
1107 +               printk(KERN_ERR "CAN: protocol %d already "
1108 +                      "registered\n", proto);
1109 +               return;
1110 +       }
1111 +
1112 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,13)
1113 +       if (proto_register(cp->prot, 0) != 0) {
1114 +               return;
1115 +       }
1116 +#endif
1117 +       proto_tab[proto] = cp;
1118 +
1119 +       /* use generic ioctl function if the module doesn't bring its own */
1120 +       if (!cp->ops->ioctl)
1121 +               cp->ops->ioctl = can_ioctl;
1122 +}
1123 +
1124 +void can_proto_unregister(struct can_proto *cp)
1125 +{
1126 +       int proto = cp->protocol;
1127 +       if (!proto_tab[proto]) {
1128 +               printk(KERN_ERR "CAN: protocol %d is not registered\n", proto);
1129 +               return;
1130 +       }
1131 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,13)
1132 +       proto_unregister(cp->prot);
1133 +#endif
1134 +       proto_tab[proto] = NULL;
1135 +}
1136 +
1137 +void can_dev_register(struct net_device *dev,
1138 +                     void (*func)(unsigned long msg, void *), void *data)
1139 +{
1140 +       struct notifier *n;
1141 +
1142 +       DBG("called for %s\n", dev->name);
1143 +
1144 +       if (!(n = kmalloc(sizeof(*n), GFP_KERNEL)))
1145 +               return;
1146 +
1147 +       n->dev  = dev;
1148 +       n->func = func;
1149 +       n->data = data;
1150 +
1151 +       write_lock(&notifier_lock);
1152 +       list_add(&n->list, &notifier_list);
1153 +       write_unlock(&notifier_lock);
1154 +}
1155 +
1156 +void can_dev_unregister(struct net_device *dev,
1157 +                       void (*func)(unsigned long msg, void *), void *data)
1158 +{
1159 +       struct notifier *n, *next;
1160 +
1161 +       DBG("called for %s\n", dev->name);
1162 +
1163 +       write_lock(&notifier_lock);
1164 +       list_for_each_entry_safe(n, next, &notifier_list, list) {
1165 +               if (n->dev == dev && n->func == func && n->data == data) {
1166 +                       list_del(&n->list);
1167 +                       kfree(n);
1168 +                       break;
1169 +               }
1170 +       }
1171 +       write_unlock(&notifier_lock);
1172 +}
1173 +
1174 +/**************************************************/
1175 +/* af_can socket functions                        */
1176 +/**************************************************/
1177 +
1178 +static void can_sock_destruct(struct sock *sk)
1179 +{
1180 +       DBG("called for sock %p\n", sk);
1181 +
1182 +       skb_queue_purge(&sk->sk_receive_queue);
1183 +       if (sk->sk_protinfo)
1184 +               kfree(sk->sk_protinfo);
1185 +}
1186 +
1187 +static int can_create(struct socket *sock, int protocol)
1188 +{
1189 +       struct sock *sk;
1190 +       struct can_proto *cp;
1191 +       int ret;
1192 +
1193 +       DBG("socket %p, type %d, proto %d\n", sock, sock->type, protocol);
1194 +
1195 +       sock->state = SS_UNCONNECTED;
1196 +
1197 +       if (protocol < 0 || protocol >= CAN_NPROTO)
1198 +               return -EINVAL;
1199 +
1200 +       DBG("looking up proto %d in proto_tab[]\n", protocol);
1201 +
1202 +       /* try to load protocol module, when CONFIG_KMOD is defined */
1203 +       if (!proto_tab[protocol]) {
1204 +               char module_name[30];
1205 +               sprintf(module_name, "can-proto-%d", protocol);
1206 +               if (request_module(module_name) == -ENOSYS)
1207 +                       printk(KERN_INFO "CAN: request_module(%s) not"
1208 +                              " implemented.\n", module_name);
1209 +       }
1210 +
1211 +       /* check for success and correct type */
1212 +       if (!(cp = proto_tab[protocol]) || cp->type != sock->type)
1213 +               return -EPROTONOSUPPORT;
1214 +
1215 +       if (cp->capability >= 0 && !capable(cp->capability))
1216 +               return -EPERM;
1217 +
1218 +       sock->ops = cp->ops;
1219 +
1220 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,13)
1221 +       sk = sk_alloc(PF_CAN, GFP_KERNEL, cp->prot, 1);
1222 +       if (!sk)
1223 +               goto oom;
1224 +#else
1225 +       sk = sk_alloc(PF_CAN, GFP_KERNEL, 1, 0);
1226 +       if (!sk)
1227 +               goto oom;
1228 +       if (cp->obj_size &&
1229 +           !(sk->sk_protinfo = kmalloc(cp->obj_size, GFP_KERNEL))) {
1230 +               sk_free(sk);
1231 +               goto oom;
1232 +       }
1233 +       sk_set_owner(sk, proto_tab[protocol]->owner);
1234 +#endif
1235 +       sock_init_data(sock, sk);
1236 +       sk->sk_destruct = can_sock_destruct;
1237 +
1238 +       DBG("created sock: %p\n", sk);
1239 +
1240 +       ret = 0;
1241 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,13)
1242 +       if (sk->sk_prot->init)
1243 +               ret = sk->sk_prot->init(sk);
1244 +#else
1245 +       if (cp->init)
1246 +               ret = cp->init(sk);
1247 +#endif
1248 +       if (ret) {
1249 +               /* we must release sk */
1250 +               sock_orphan(sk);
1251 +               sock_put(sk);
1252 +               return ret;
1253 +       }
1254 +
1255 +       return 0;
1256 +
1257 + oom:
1258 +       return -ENOMEM;
1259 +}
1260 +
1261 +static int can_notifier(struct notifier_block *nb,
1262 +                       unsigned long msg, void *data)
1263 +{
1264 +       struct net_device *dev = (struct net_device *)data;
1265 +       struct notifier *n;
1266 +
1267 +       DBG("called for %s, msg = %lu\n", dev->name, msg);
1268 +
1269 +       if (dev->type != ARPHRD_CAN)
1270 +               return NOTIFY_DONE;
1271 +
1272 +       switch (msg) {
1273 +               struct dev_rcv_lists *d;
1274 +               int i;
1275 +
1276 +       case NETDEV_REGISTER:
1277 +
1278 +               /* create new dev_rcv_lists for this device */
1279 +
1280 +               DBG("creating new dev_rcv_lists for %s\n", dev->name);
1281 +               if (!(d = kmalloc(sizeof(*d),
1282 +                                 in_interrupt() ? GFP_ATOMIC : GFP_KERNEL))) {
1283 +                       printk(KERN_ERR "CAN: allocation of receive "
1284 +                              "list failed\n");
1285 +                       return NOTIFY_DONE;
1286 +               }
1287 +               /* N.B. zeroing the struct is the correct initialization
1288 +                       for the embedded hlist_head structs.
1289 +                       Another list type, e.g. list_head, would require
1290 +                       explicit initialization. */
1291 +               memset(d, 0, sizeof(*d));
1292 +               d->dev = dev;
1293 +
1294 +               spin_lock_bh(&rcv_lists_lock);
1295 +               hlist_add_head_rcu(&d->list, &rx_dev_list);
1296 +               spin_unlock_bh(&rcv_lists_lock);
1297 +
1298 +               break;
1299 +
1300 +       case NETDEV_UNREGISTER:
1301 +               spin_lock_bh(&rcv_lists_lock);
1302 +
1303 +               if (!(d = find_dev_rcv_lists(dev))) {
1304 +                       printk(KERN_ERR "CAN: notifier: receive list not "
1305 +                              "found for dev %s\n", dev->name);
1306 +                       goto unreg_out;
1307 +               }
1308 +
1309 +               hlist_del_rcu(&d->list);
1310 +
1311 +               /* remove all receivers hooked at this netdevice */
1312 +               can_rx_delete_all(&d->rx_err);
1313 +               can_rx_delete_all(&d->rx_all);
1314 +               can_rx_delete_all(&d->rx_fil);
1315 +               can_rx_delete_all(&d->rx_inv);
1316 +               can_rx_delete_all(&d->rx_eff);
1317 +               for (i = 0; i < 2048; i++)
1318 +                       can_rx_delete_all(&d->rx_sff[i]);
1319 +
1320 +       unreg_out:
1321 +               spin_unlock_bh(&rcv_lists_lock);
1322 +
1323 +               if (d)
1324 +                       call_rcu(&d->rcu, can_rcv_lists_delete);
1325 +
1326 +               break;
1327 +       }
1328 +
1329 +       read_lock(&notifier_lock);
1330 +       list_for_each_entry(n, &notifier_list, list) {
1331 +               if (n->dev == dev)
1332 +                       n->func(msg, n->data);
1333 +       }
1334 +       read_unlock(&notifier_lock);
1335 +
1336 +       return NOTIFY_DONE;
1337 +}
1338 +
1339 +static int can_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1340 +{
1341 +       struct sock *sk = sock->sk;
1342 +
1343 +       switch (cmd) {
1344 +       case SIOCGSTAMP:
1345 +               return sock_get_timestamp(sk, (struct timeval __user *)arg);
1346 +       default:
1347 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
1348 +               return -ENOIOCTLCMD;
1349 +#else
1350 +               return dev_ioctl(cmd, (void __user *)arg);
1351 +#endif
1352 +       }
1353 +       return 0;
1354 +}
1355 +
1356 +/**************************************************/
1357 +/* af_can tx path                                 */
1358 +/**************************************************/
1359 +
1360 +int can_send(struct sk_buff *skb, int loop)
1361 +{
1362 +       int err;
1363 +
1364 +       if (loop) { /* local loopback (default) */
1365 +               *(struct sock **)skb->cb = skb->sk; /* tx sock reference */
1366 +
1367 +               /* interface not capabable to do the loopback itself? */
1368 +               if (!(skb->dev->flags & IFF_LOOPBACK)) {
1369 +                       struct sk_buff *newskb = skb_clone(skb, GFP_ATOMIC);
1370 +                       newskb->protocol  = htons(ETH_P_CAN);
1371 +                       newskb->ip_summed = CHECKSUM_UNNECESSARY;
1372 +                       netif_rx(newskb); /* perform local loopback here */
1373 +               }
1374 +       } else
1375 +               *(struct sock **)skb->cb = NULL; /* no loopback required */
1376 +
1377 +       if (!(skb->dev->flags & IFF_UP))
1378 +               err = -ENETDOWN;
1379 +       else if ((err = dev_queue_xmit(skb)) > 0)  /* send to netdevice */
1380 +               err = net_xmit_errno(err);
1381 +
1382 +       /* update statistics */
1383 +       stats.tx_frames++;
1384 +       stats.tx_frames_delta++;
1385 +
1386 +       return err;
1387 +}
1388 +
1389 +/**************************************************/
1390 +/* af_can rx path                                 */
1391 +/**************************************************/
1392 +
1393 +int can_rx_register(struct net_device *dev, canid_t can_id, canid_t mask,
1394 +                   void (*func)(struct sk_buff *, void *), void *data,
1395 +                   char *ident)
1396 +{
1397 +       struct receiver *r;
1398 +       struct hlist_head *rl;
1399 +       struct dev_rcv_lists *d;
1400 +       int ret = 0;
1401 +
1402 +       /* insert new receiver  (dev,canid,mask) -> (func,data) */
1403 +
1404 +       DBG("dev %p, id %03X, mask %03X, callback %p, data %p, ident %s\n",
1405 +           dev, can_id, mask, func, data, ident);
1406 +
1407 +       if (!(r = kmem_cache_alloc(rcv_cache, GFP_KERNEL))) {
1408 +               ret = -ENOMEM;
1409 +               goto out;
1410 +       }
1411 +
1412 +       spin_lock_bh(&rcv_lists_lock);
1413 +
1414 +       if (!(d = find_dev_rcv_lists(dev))) {
1415 +               DBG("receive list not found for dev %s, id %03X, mask %03X\n",
1416 +                   DNAME(dev), can_id, mask);
1417 +               kmem_cache_free(rcv_cache, r);
1418 +               ret = -ENODEV;
1419 +               goto out_unlock;
1420 +       }
1421 +
1422 +       rl = find_rcv_list(&can_id, &mask, d);
1423 +
1424 +       r->can_id  = can_id;
1425 +       r->mask    = mask;
1426 +       r->matches = 0;
1427 +       r->func    = func;
1428 +       r->data    = data;
1429 +       r->ident   = ident;
1430 +
1431 +       hlist_add_head_rcu(&r->list, rl);
1432 +       d->entries++;
1433 +
1434 +       pstats.rcv_entries++;
1435 +       if (pstats.rcv_entries_max < pstats.rcv_entries)
1436 +               pstats.rcv_entries_max = pstats.rcv_entries;
1437 +
1438 + out_unlock:
1439 +       spin_unlock_bh(&rcv_lists_lock);
1440 + out:
1441 +       return ret;
1442 +}
1443 +
1444 +static void can_rcv_lists_delete(struct rcu_head *rp)
1445 +{
1446 +       struct dev_rcv_lists *d = container_of(rp, struct dev_rcv_lists, rcu);
1447 +       kfree(d);
1448 +}
1449 +
1450 +static void can_rx_delete(struct rcu_head *rp)
1451 +{
1452 +       struct receiver *r = container_of(rp, struct receiver, rcu);
1453 +       kmem_cache_free(rcv_cache, r);
1454 +}
1455 +
1456 +static void can_rx_delete_all(struct hlist_head *rl)
1457 +{
1458 +       struct receiver *r;
1459 +       struct hlist_node *n;
1460 +
1461 +       hlist_for_each_entry_rcu(r, n, rl, list) {
1462 +               hlist_del_rcu(&r->list);
1463 +               call_rcu(&r->rcu, can_rx_delete);
1464 +       }
1465 +}
1466 +
1467 +int can_rx_unregister(struct net_device *dev, canid_t can_id, canid_t mask,
1468 +                     void (*func)(struct sk_buff *, void *), void *data)
1469 +{
1470 +       struct receiver *r;
1471 +       struct hlist_head *rl;
1472 +       struct hlist_node *next;
1473 +       struct dev_rcv_lists *d;
1474 +       int ret = 0;
1475 +
1476 +       DBG("dev %p, id %03X, mask %03X, callback %p, data %p\n",
1477 +           dev, can_id, mask, func, data);
1478 +
1479 +       r = NULL;
1480 +
1481 +       spin_lock_bh(&rcv_lists_lock);
1482 +
1483 +       if (!(d = find_dev_rcv_lists(dev))) {
1484 +               DBG("receive list not found for dev %s, id %03X, mask %03X\n",
1485 +                   DNAME(dev), can_id, mask);
1486 +               ret = -ENODEV;
1487 +               goto out;
1488 +       }
1489 +
1490 +       rl = find_rcv_list(&can_id, &mask, d);
1491 +
1492 +       /*  Search the receiver list for the item to delete.  This should
1493 +        *  exist, since no receiver may be unregistered that hasn't
1494 +        *  been registered before.
1495 +        */
1496 +
1497 +       hlist_for_each_entry(r, next, rl, list) {
1498 +               if (r->can_id == can_id && r->mask == mask
1499 +                   && r->func == func && r->data == data)
1500 +                       break;
1501 +       }
1502 +
1503 +       /*  Check for bug in CAN protocol implementations:
1504 +        *  If no matching list item was found, the list cursor variable next
1505 +        *  will be NULL, while r will point to the last item of the list.
1506 +        */
1507 +
1508 +       if (!next) {
1509 +               DBG("receive list entry not found for "
1510 +                   "dev %s, id %03X, mask %03X\n", DNAME(dev), can_id, mask);
1511 +               ret = -EINVAL;
1512 +               r = NULL;
1513 +               goto out;
1514 +       }
1515 +
1516 +       hlist_del_rcu(&r->list);
1517 +       d->entries--;
1518 +
1519 +       if (pstats.rcv_entries > 0)
1520 +               pstats.rcv_entries--;
1521 +
1522 + out:
1523 +       spin_unlock_bh(&rcv_lists_lock);
1524 +
1525 +       /* schedule the receiver item for deletion */
1526 +       if (r)
1527 +               call_rcu(&r->rcu, can_rx_delete);
1528 +
1529 +       return ret;
1530 +}
1531 +
1532 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,14)
1533 +static int can_rcv(struct sk_buff *skb, struct net_device *dev,
1534 +                  struct packet_type *pt, struct net_device *orig_dev)
1535 +#else
1536 +static int can_rcv(struct sk_buff *skb, struct net_device *dev,
1537 +                  struct packet_type *pt)
1538 +#endif
1539 +{
1540 +       struct dev_rcv_lists *d;
1541 +       int matches;
1542 +
1543 +       DBG("received skbuff on device %s, ptype %04x\n",
1544 +           dev->name, ntohs(pt->type));
1545 +       DBG_SKB(skb);
1546 +       DBG_FRAME("af_can: can_rcv: received CAN frame",
1547 +                 (struct can_frame *)skb->data);
1548 +
1549 +       /* update statistics */
1550 +       stats.rx_frames++;
1551 +       stats.rx_frames_delta++;
1552 +
1553 +       rcu_read_lock();
1554 +
1555 +       /* deliver the packet to sockets listening on all devices */
1556 +       matches = can_rcv_filter(&rx_alldev_list, skb);
1557 +
1558 +       /* find receive list for this device */
1559 +       if ((d = find_dev_rcv_lists(dev)))
1560 +               matches += can_rcv_filter(d, skb);
1561 +
1562 +       rcu_read_unlock();
1563 +
1564 +       /* free the skbuff allocated by the netdevice driver */
1565 +       DBG("freeing skbuff %p\n", skb);
1566 +       kfree_skb(skb);
1567 +
1568 +       if (matches > 0) {
1569 +               stats.matches++;
1570 +               stats.matches_delta++;
1571 +       }
1572 +
1573 +       return 0;
1574 +}
1575 +
1576 +
1577 +static inline void deliver(struct sk_buff *skb, struct receiver *r)
1578 +{
1579 +       struct sk_buff *clone = skb_clone(skb, GFP_ATOMIC);
1580 +       DBG("skbuff %p cloned to %p\n", skb, clone);
1581 +       if (clone) {
1582 +               r->func(clone, r->data);
1583 +               r->matches++;    /* update specific statistics */
1584 +       }
1585 +}
1586 +
1587 +static int can_rcv_filter(struct dev_rcv_lists *d, struct sk_buff *skb)
1588 +{
1589 +       struct receiver *r;
1590 +       struct hlist_node *n;
1591 +       int matches = 0;
1592 +       struct can_frame *cf = (struct can_frame*)skb->data;
1593 +       canid_t can_id = cf->can_id;
1594 +
1595 +       if (d->entries == 0)
1596 +               return 0;
1597 +
1598 +       if (can_id & CAN_ERR_FLAG) {
1599 +               /* check for error frame entries only */
1600 +               hlist_for_each_entry_rcu(r, n, &d->rx_err, list) {
1601 +                       if (can_id & r->mask) {
1602 +                               DBG("match on rx_err skbuff %p\n", skb);
1603 +                               deliver(skb, r);
1604 +                               matches++;
1605 +                       }
1606 +               }
1607 +               goto out;
1608 +       }
1609 +
1610 +       /* check for unfiltered entries */
1611 +       hlist_for_each_entry_rcu(r, n, &d->rx_all, list) {
1612 +               DBG("match on rx_all skbuff %p\n", skb);
1613 +               deliver(skb, r);
1614 +               matches++;
1615 +       }
1616 +
1617 +       /* check for can_id/mask entries */
1618 +       hlist_for_each_entry_rcu(r, n, &d->rx_fil, list) {
1619 +               if ((can_id & r->mask) == r->can_id) {
1620 +                       DBG("match on rx_fil skbuff %p\n", skb);
1621 +                       deliver(skb, r);
1622 +                       matches++;
1623 +               }
1624 +       }
1625 +
1626 +       /* check for inverted can_id/mask entries */
1627 +       hlist_for_each_entry_rcu(r, n, &d->rx_inv, list) {
1628 +               if ((can_id & r->mask) != r->can_id) {
1629 +                       DBG("match on rx_inv skbuff %p\n", skb);
1630 +                       deliver(skb, r);
1631 +                       matches++;
1632 +               }
1633 +       }
1634 +
1635 +       /* check CAN_ID specific entries */
1636 +       if (can_id & CAN_EFF_FLAG) {
1637 +               hlist_for_each_entry_rcu(r, n, &d->rx_eff, list) {
1638 +                       if (r->can_id == can_id) {
1639 +                               DBG("match on rx_eff skbuff %p\n", skb);
1640 +                               deliver(skb, r);
1641 +                               matches++;
1642 +                       }
1643 +               }
1644 +       } else {
1645 +               can_id &= CAN_SFF_MASK;
1646 +               hlist_for_each_entry_rcu(r, n, &d->rx_sff[can_id], list) {
1647 +                       DBG("match on rx_sff skbuff %p\n", skb);
1648 +                       deliver(skb, r);
1649 +                       matches++;
1650 +               }
1651 +       }
1652 +
1653 + out:
1654 +       return matches;
1655 +}
1656 +
1657 +static struct dev_rcv_lists *find_dev_rcv_lists(struct net_device *dev)
1658 +{
1659 +       struct dev_rcv_lists *d;
1660 +       struct hlist_node *n;
1661 +
1662 +       /* find receive list for this device */
1663 +
1664 +       /*  The hlist_for_each_entry*() macros curse through the list
1665 +        *  using the pointer variable n and set d to the containing
1666 +        *  struct in each list iteration.  Therefore, after list
1667 +        *  iteration, d is unmodified when the list is empty, and it
1668 +        *  points to last list element, when the list is non-empty
1669 +        *  but no match in the loop body is found.  I.e. d is *not*
1670 +        *  NULL when no match is found.  We can, however, use the
1671 +        *  cursor variable n to decide if a match was found.
1672 +        */
1673 +
1674 +       hlist_for_each_entry(d, n, &rx_dev_list, list)
1675 +               if (d->dev == dev)
1676 +                       break;
1677 +
1678 +       return n ? d : NULL;
1679 +}
1680 +
1681 +static struct hlist_head *find_rcv_list(canid_t *can_id, canid_t *mask,
1682 +                                       struct dev_rcv_lists *d)
1683 +{
1684 +       canid_t inv = *can_id & CAN_INV_FILTER; /* save flag before masking */
1685 +
1686 +       if (*mask & CAN_ERR_FLAG) { /* filter error frames */
1687 +               *mask &= CAN_ERR_MASK; /* clear CAN_ERR_FLAG in list entry */
1688 +               return &d->rx_err;
1689 +       }
1690 +
1691 +       /* ensure valid values in can_mask */
1692 +       if (*mask & CAN_EFF_FLAG)
1693 +               *mask &= (CAN_EFF_MASK | CAN_EFF_FLAG | CAN_RTR_FLAG);
1694 +       else
1695 +               *mask &= (CAN_SFF_MASK | CAN_RTR_FLAG);
1696 +
1697 +       *can_id &= *mask; /* reduce condition testing at receive time */
1698 +
1699 +       if (inv) /* inverse can_id/can_mask filter */
1700 +               return &d->rx_inv;
1701 +
1702 +       if (!(*mask)) /* mask == 0 => no condition testing at receive time */
1703 +               return &d->rx_all;
1704 +
1705 +       /* use extra filterset for the subscription of exactly *one* can_id */
1706 +       if (*can_id & CAN_EFF_FLAG) {
1707 +               if (*mask == (CAN_EFF_MASK | CAN_EFF_FLAG))
1708 +                       return &d->rx_eff; /* use-case for hash-table here? */
1709 +       } else {
1710 +               if (*mask == CAN_SFF_MASK)
1711 +                       return &d->rx_sff[*can_id];
1712 +       }
1713 +
1714 +       return &d->rx_fil;  /* default: filter via can_id/can_mask */
1715 +}
1716 +
1717 +/**************************************************/
1718 +/* af_can utility stuff                           */
1719 +/**************************************************/
1720 +
1721 +unsigned long timeval2jiffies(struct timeval *tv, int round_up)
1722 +{
1723 +       unsigned long jif;
1724 +       unsigned long sec  = tv->tv_sec;
1725 +       unsigned long usec = tv->tv_usec;
1726 +
1727 +       if (sec > ULONG_MAX / HZ)          /* check for overflow */
1728 +               return ULONG_MAX;
1729 +
1730 +       if (round_up)                      /* any usec below one HZ? */
1731 +               usec += 1000000 / HZ - 1;  /* pump it up */
1732 +
1733 +       jif = usec / (1000000 / HZ);
1734 +
1735 +       if (sec * HZ > ULONG_MAX - jif)    /* check for overflow */
1736 +               return ULONG_MAX;
1737 +       else
1738 +               return jif + sec * HZ;
1739 +}
1740 +
1741 +
1742 +/**************************************************/
1743 +/* af_can debugging stuff                         */
1744 +/**************************************************/
1745 +
1746 +#ifdef CONFIG_CAN_DEBUG_CORE
1747 +
1748 +void can_debug_cframe(const char *msg, struct can_frame *cf, ...)
1749 +{
1750 +       va_list ap;
1751 +       int len;
1752 +       int dlc, i;
1753 +       char buf[1024];
1754 +
1755 +       len = sprintf(buf, KERN_DEBUG);
1756 +       va_start(ap, cf);
1757 +       len += snprintf(buf + len, sizeof(buf) - 64, msg, ap);
1758 +       buf[len++] = ':';
1759 +       buf[len++] = ' ';
1760 +       va_end(ap);
1761 +
1762 +       if ((dlc = cf->can_dlc) > 8)
1763 +               dlc = 8;
1764 +
1765 +       if (cf->can_id & CAN_EFF_FLAG)
1766 +               len += sprintf(buf + len, "<%08X> [%X] ",
1767 +                              cf->can_id & CAN_EFF_MASK, dlc);
1768 +       else
1769 +               len += sprintf(buf + len, "<%03X> [%X] ",
1770 +                              cf->can_id & CAN_SFF_MASK, dlc);
1771 +
1772 +       for (i = 0; i < dlc; i++)
1773 +               len += sprintf(buf + len, "%02X ", cf->data[i]);
1774 +
1775 +       if (cf->can_id & CAN_RTR_FLAG)
1776 +               len += sprintf(buf + len, "(RTR)");
1777 +
1778 +       buf[len++] = '\n';
1779 +       buf[len]   = '\0';
1780 +       printk(buf);
1781 +}
1782 +
1783 +void can_debug_skb(struct sk_buff *skb)
1784 +{
1785 +       int len, nbytes, i;
1786 +       char buf[1024];
1787 +
1788 +       len = sprintf(buf,
1789 +                     KERN_DEBUG "  skbuff at %p, dev: %d, proto: %04x\n"
1790 +                     KERN_DEBUG "  users: %d, dataref: %d, nr_frags: %d, "
1791 +                     "h,d,t,e,l: %p %+d %+d %+d, %d",
1792 +                     skb, skb->dev ? skb->dev->ifindex : -1,
1793 +                     ntohs(skb->protocol),
1794 +                     atomic_read(&skb->users),
1795 +                     atomic_read(&(skb_shinfo(skb)->dataref)),
1796 +                     skb_shinfo(skb)->nr_frags,
1797 +                     skb->head, skb->data - skb->head,
1798 +                     skb->tail - skb->head, skb->end - skb->head, skb->len);
1799 +       nbytes = skb->end - skb->head;
1800 +       for (i = 0; i < nbytes; i++) {
1801 +               if (i % 16 == 0)
1802 +                       len += sprintf(buf + len, "\n" KERN_DEBUG "  ");
1803 +               if (len < sizeof(buf) - 16) {
1804 +                       len += sprintf(buf + len, " %02x", skb->head[i]);
1805 +               } else {
1806 +                       len += sprintf(buf + len, "...");
1807 +                       break;
1808 +               }
1809 +       }
1810 +       buf[len++] = '\n';
1811 +       buf[len]   = '\0';
1812 +       printk(buf);
1813 +}
1814 +
1815 +EXPORT_SYMBOL(can_debug_cframe);
1816 +EXPORT_SYMBOL(can_debug_skb);
1817 +
1818 +#endif
1819 +
1820 +/**************************************************/
1821 +/* Exported symbols                               */
1822 +/**************************************************/
1823 +EXPORT_SYMBOL(can_proto_register);
1824 +EXPORT_SYMBOL(can_proto_unregister);
1825 +EXPORT_SYMBOL(can_rx_register);
1826 +EXPORT_SYMBOL(can_rx_unregister);
1827 +EXPORT_SYMBOL(can_dev_register);
1828 +EXPORT_SYMBOL(can_dev_unregister);
1829 +EXPORT_SYMBOL(can_send);
1830 +EXPORT_SYMBOL(timeval2jiffies);
1831 diff -N -u -r a/net/can/af_can.h c/net/can/af_can.h
1832 --- a/net/can/af_can.h  1970-01-01 01:00:00.000000000 +0100
1833 +++ c/net/can/af_can.h  2007-03-09 13:47:12.000000000 +0100
1834 @@ -0,0 +1,119 @@
1835 +/*
1836 + * $Id: af_can.h 177 2007-03-08 11:02:43Z hartkopp $
1837 + *
1838 + * Copyright (c) 2002-2005 Volkswagen Group Electronic Research
1839 + * All rights reserved.
1840 + *
1841 + * Redistribution and use in source and binary forms, with or without
1842 + * modification, are permitted provided that the following conditions
1843 + * are met:
1844 + * 1. Redistributions of source code must retain the above copyright
1845 + *    notice, this list of conditions, the following disclaimer and
1846 + *    the referenced file 'COPYING'.
1847 + * 2. Redistributions in binary form must reproduce the above copyright
1848 + *    notice, this list of conditions and the following disclaimer in the
1849 + *    documentation and/or other materials provided with the distribution.
1850 + * 3. Neither the name of Volkswagen nor the names of its contributors
1851 + *    may be used to endorse or promote products derived from this software
1852 + *    without specific prior written permission.
1853 + *
1854 + * Alternatively, provided that this notice is retained in full, this
1855 + * software may be distributed under the terms of the GNU General
1856 + * Public License ("GPL") version 2 as distributed in the 'COPYING'
1857 + * file from the main directory of the linux kernel source.
1858 + *
1859 + * The provided data structures and external interfaces from this code
1860 + * are not restricted to be used by modules with a GPL compatible license.
1861 + *
1862 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1863 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1864 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1865 + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
1866 + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
1867 + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
1868 + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
1869 + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
1870 + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1871 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
1872 + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
1873 + * DAMAGE.
1874 + *
1875 + * Send feedback to <socketcan-users@lists.berlios.de>
1876 + *
1877 + */
1878 +
1879 +#ifndef AF_CAN_H
1880 +#define AF_CAN_H
1881 +
1882 +#include <linux/skbuff.h>
1883 +#include <linux/netdevice.h>
1884 +#include <linux/list.h>
1885 +#include <linux/rcupdate.h>
1886 +
1887 +#include <linux/can.h>
1888 +
1889 +/* af_can rx dispatcher structures */
1890 +
1891 +struct receiver {
1892 +       struct hlist_node list;
1893 +       struct rcu_head rcu;
1894 +       canid_t can_id;
1895 +       canid_t mask;
1896 +       unsigned long matches;
1897 +       void (*func)(struct sk_buff *, void *);
1898 +       void *data;
1899 +       char *ident;
1900 +};
1901 +
1902 +struct dev_rcv_lists {
1903 +       struct hlist_node list;
1904 +       struct rcu_head rcu;
1905 +       struct net_device *dev;
1906 +       struct hlist_head rx_err;
1907 +       struct hlist_head rx_all;
1908 +       struct hlist_head rx_fil;
1909 +       struct hlist_head rx_inv;
1910 +       struct hlist_head rx_sff[0x800];
1911 +       struct hlist_head rx_eff;
1912 +       int entries;
1913 +};
1914 +
1915 +/* statistic structures */
1916 +
1917 +struct s_stats {
1918 +       unsigned long jiffies_init;
1919 +
1920 +       unsigned long rx_frames;
1921 +       unsigned long tx_frames;
1922 +       unsigned long matches;
1923 +
1924 +       unsigned long total_rx_rate;
1925 +       unsigned long total_tx_rate;
1926 +       unsigned long total_rx_match_ratio;
1927 +
1928 +       unsigned long current_rx_rate;
1929 +       unsigned long current_tx_rate;
1930 +       unsigned long current_rx_match_ratio;
1931 +
1932 +       unsigned long max_rx_rate;
1933 +       unsigned long max_tx_rate;
1934 +       unsigned long max_rx_match_ratio;
1935 +
1936 +       unsigned long rx_frames_delta;
1937 +       unsigned long tx_frames_delta;
1938 +       unsigned long matches_delta;
1939 +}; /* can be reset e.g. by can_init_stats() */
1940 +
1941 +struct s_pstats {
1942 +       unsigned long stats_reset;
1943 +       unsigned long rcv_entries;
1944 +       unsigned long rcv_entries_max;
1945 +}; /* persistent statistics */
1946 +
1947 +
1948 +/* function prototypes for the CAN networklayer procfs (proc.c) */
1949 +
1950 +void can_init_proc(void);
1951 +void can_remove_proc(void);
1952 +
1953 +#endif /* AF_CAN_H */
1954 diff -N -u -r a/net/can/bcm.c c/net/can/bcm.c
1955 --- a/net/can/bcm.c     1970-01-01 01:00:00.000000000 +0100
1956 +++ c/net/can/bcm.c     2007-03-09 13:47:12.000000000 +0100
1957 @@ -0,0 +1,1614 @@
1958 +/*
1959 + * bcm.c - Broadcast Manager to filter/send (cyclic) CAN content
1960 + *
1961 + * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
1962 + * All rights reserved.
1963 + *
1964 + * Redistribution and use in source and binary forms, with or without
1965 + * modification, are permitted provided that the following conditions
1966 + * are met:
1967 + * 1. Redistributions of source code must retain the above copyright
1968 + *    notice, this list of conditions, the following disclaimer and
1969 + *    the referenced file 'COPYING'.
1970 + * 2. Redistributions in binary form must reproduce the above copyright
1971 + *    notice, this list of conditions and the following disclaimer in the
1972 + *    documentation and/or other materials provided with the distribution.
1973 + * 3. Neither the name of Volkswagen nor the names of its contributors
1974 + *    may be used to endorse or promote products derived from this software
1975 + *    without specific prior written permission.
1976 + *
1977 + * Alternatively, provided that this notice is retained in full, this
1978 + * software may be distributed under the terms of the GNU General
1979 + * Public License ("GPL") version 2 as distributed in the 'COPYING'
1980 + * file from the main directory of the linux kernel source.
1981 + *
1982 + * The provided data structures and external interfaces from this code
1983 + * are not restricted to be used by modules with a GPL compatible license.
1984 + *
1985 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1986 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1987 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1988 + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
1989 + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
1990 + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
1991 + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
1992 + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
1993 + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1994 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
1995 + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
1996 + * DAMAGE.
1997 + *
1998 + * Send feedback to <socketcan-users@lists.berlios.de>
1999 + *
2000 + */
2001 +
2002 +#include <linux/autoconf.h>
2003 +#include <linux/module.h>
2004 +#include <linux/init.h>
2005 +#include <linux/net.h>
2006 +#include <linux/netdevice.h>
2007 +#include <linux/proc_fs.h>
2008 +#include <linux/poll.h>
2009 +#include <net/sock.h>
2010 +
2011 +#include <linux/can.h>
2012 +#include <linux/can/core.h>
2013 +#include <linux/can/bcm.h>
2014 +#include <linux/can/version.h>
2015 +
2016 +RCSID("$Id: bcm.c 179 2007-03-09 07:36:49Z hartkopp $");
2017 +
2018 +#ifdef CONFIG_CAN_DEBUG_CORE
2019 +static int debug = 0;
2020 +module_param(debug, int, S_IRUGO);
2021 +#define DBG(args...)       (debug & 1 ? \
2022 +                              (printk(KERN_DEBUG "BCM %s: ", __func__), \
2023 +                               printk(args)) : 0)
2024 +#define DBG_FRAME(args...) (debug & 2 ? can_debug_cframe(args) : 0)
2025 +#define DBG_SKB(skb)       (debug & 4 ? can_debug_skb(skb) : 0)
2026 +#else
2027 +#define DBG(args...)
2028 +#define DBG_FRAME(args...)
2029 +#define DBG_SKB(skb)
2030 +#endif
2031 +
2032 +/* use of last_frames[index].can_dlc */
2033 +#define RX_RECV    0x40 /* received data for this element */
2034 +#define RX_THR     0x80 /* element not been sent due to throttle feature */
2035 +#define BCM_CAN_DLC_MASK 0x0F /* clean private flags in can_dlc by masking */
2036 +
2037 +/* get best masking value for can_rx_register() for a given single can_id */
2038 +#define REGMASK(id) ((id & CAN_RTR_FLAG) | ((id & CAN_EFF_FLAG) ? \
2039 +                       (CAN_EFF_MASK | CAN_EFF_FLAG) : CAN_SFF_MASK))
2040 +
2041 +#define IDENT "bcm"
2042 +static __initdata const char banner[] = KERN_INFO
2043 +       "CAN: broadcast manager (bcm) socket protocol " VERSION "\n"; 
2044 +
2045 +MODULE_DESCRIPTION("PF_CAN bcm sockets");
2046 +MODULE_LICENSE("Dual BSD/GPL");
2047 +MODULE_AUTHOR("Oliver Hartkopp <oliver.hartkopp@volkswagen.de>");
2048 +
2049 +#define GET_U64(p) (*(u64*)(p)->data) /* easy access */
2050 +
2051 +struct bcm_op {
2052 +       struct list_head list;
2053 +       int ifindex;
2054 +       canid_t can_id;
2055 +       int flags;
2056 +       unsigned long j_ival1, j_ival2, j_lastmsg;
2057 +       unsigned long frames_abs, frames_filtered;
2058 +       struct timer_list timer, thrtimer;
2059 +       struct timeval ival1, ival2;
2060 +       struct timeval rx_stamp;
2061 +       int rx_ifindex;
2062 +       int count;
2063 +       int nframes;
2064 +       int currframe;
2065 +       struct can_frame *frames;
2066 +       struct can_frame *last_frames;
2067 +       struct sock *sk;
2068 +};
2069 +
2070 +struct bcm_opt {
2071 +       int bound;
2072 +       int ifindex;
2073 +       struct list_head rx_ops;
2074 +       struct list_head tx_ops;
2075 +       unsigned long dropped_usr_msgs;
2076 +       struct proc_dir_entry *bcm_proc_read;
2077 +       char procname [9]; /* pointer printed in ASCII with \0 */
2078 +};
2079 +
2080 +static struct proc_dir_entry *proc_dir = NULL;
2081 +
2082 +static int  bcm_init(struct sock *sk);
2083 +static void bcm_notifier(unsigned long msg, void *data);
2084 +static int  bcm_release(struct socket *sock);
2085 +static int  bcm_connect(struct socket *sock, struct sockaddr *uaddr, int len,
2086 +                       int flags);
2087 +static int  bcm_sendmsg(struct kiocb *iocb, struct socket *sock,
2088 +                       struct msghdr *msg, size_t size);
2089 +static int  bcm_recvmsg(struct kiocb *iocb, struct socket *sock,
2090 +                       struct msghdr *msg, size_t size, int flags);
2091 +static unsigned int bcm_poll(struct file *file, struct socket *sock,
2092 +                            poll_table *wait);
2093 +
2094 +static int  bcm_read_proc(char *page, char **start, off_t off,
2095 +                         int count, int *eof, void *data);
2096 +
2097 +static void bcm_tx_timeout_handler(unsigned long data);
2098 +static int  bcm_tx_send(struct msghdr *msg, int ifindex, struct sock *sk);
2099 +static int  bcm_tx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg,
2100 +                        int ifindex, struct sock *sk);
2101 +static void bcm_can_tx(struct bcm_op *op);
2102 +
2103 +static int  bcm_rx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg,
2104 +                        int ifindex, struct sock *sk);
2105 +static void bcm_rx_handler(struct sk_buff *skb, void *op);
2106 +static void bcm_rx_timeout_handler(unsigned long data);
2107 +static void bcm_rx_thr_handler(unsigned long data);
2108 +static void bcm_rx_cmp_to_index(struct bcm_op *op, int index,
2109 +                               struct can_frame *rxdata);
2110 +static void bcm_rx_changed(struct bcm_op *op, struct can_frame *data);
2111 +static void bcm_rx_starttimer(struct bcm_op *op);
2112 +static void bcm_rx_update_and_send(struct bcm_op *op,
2113 +                                  struct can_frame *lastdata,
2114 +                                  struct can_frame *rxdata);
2115 +static void bcm_send_to_user(struct bcm_op *op, struct bcm_msg_head *head,
2116 +                            struct can_frame *frames, struct timeval *tv);
2117 +
2118 +static int  bcm_delete_tx_op(struct list_head *ops, canid_t can_id,
2119 +                            int ifindex);
2120 +static int  bcm_delete_rx_op(struct list_head *ops, canid_t can_id,
2121 +                            int ifindex);
2122 +static void bcm_remove_op(struct bcm_op *op);
2123 +static int  bcm_read_op(struct list_head *ops, struct bcm_msg_head *msg_head,
2124 +                       int ifindex);
2125 +static struct bcm_op *bcm_find_op(struct list_head *ops, canid_t can_id,
2126 +                                 int ifindex);
2127 +
2128 +static struct proto_ops bcm_ops = {
2129 +       .family        = PF_CAN,
2130 +       .release       = bcm_release,
2131 +       .bind          = sock_no_bind,
2132 +       .connect       = bcm_connect,
2133 +       .socketpair    = sock_no_socketpair,
2134 +       .accept        = sock_no_accept,
2135 +       .getname       = sock_no_getname,
2136 +       .poll          = bcm_poll,
2137 +       .ioctl         = NULL,          /* use can_ioctl() from af_can.c */
2138 +       .listen        = sock_no_listen,
2139 +       .shutdown      = sock_no_shutdown,
2140 +       .setsockopt    = sock_no_setsockopt,
2141 +       .getsockopt    = sock_no_getsockopt,
2142 +       .sendmsg       = bcm_sendmsg,
2143 +       .recvmsg       = bcm_recvmsg,
2144 +       .mmap          = sock_no_mmap,
2145 +       .sendpage      = sock_no_sendpage,
2146 +};
2147 +
2148 +#ifdef CONFIG_CAN_BCM_USER
2149 +#define BCM_CAP (-1)
2150 +#else
2151 +#define BCM_CAP CAP_NET_RAW
2152 +#endif
2153 +
2154 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,13)
2155 +struct bcm_sock {
2156 +       struct sock    sk;
2157 +       struct bcm_opt opt;
2158 +};
2159 +
2160 +#define bcm_sk(sk) (&((struct bcm_sock *)(sk))->opt)
2161 +
2162 +static struct proto bcm_proto = {
2163 +       .name       = "CAN_BCM",
2164 +       .owner      = THIS_MODULE,
2165 +       .obj_size   = sizeof(struct bcm_sock),
2166 +       .init       = bcm_init,
2167 +};
2168 +
2169 +static struct can_proto bcm_can_proto = {
2170 +       .type       = SOCK_DGRAM,
2171 +       .protocol   = CAN_BCM,
2172 +       .capability = BCM_CAP,
2173 +       .ops        = &bcm_ops,
2174 +       .prot       = &bcm_proto,
2175 +};
2176 +#else
2177 +#define bcm_sk(sk) ((struct bcm_opt *)(sk)->sk_protinfo)
2178 +
2179 +static struct can_proto bcm_can_proto = {
2180 +       .type       = SOCK_DGRAM,
2181 +       .protocol   = CAN_BCM,
2182 +       .capability = BCM_CAP,
2183 +       .ops        = &bcm_ops,
2184 +       .owner      = THIS_MODULE,
2185 +       .obj_size   = sizeof(struct bcm_opt),
2186 +       .init       = bcm_init,
2187 +};
2188 +#endif
2189 +
2190 +#define CFSIZ sizeof(struct can_frame)
2191 +#define OPSIZ sizeof(struct bcm_op)
2192 +#define MHSIZ sizeof(struct bcm_msg_head)
2193 +
2194 +static int __init bcm_module_init(void)
2195 +{
2196 +       printk(banner);
2197 +
2198 +       can_proto_register(&bcm_can_proto);
2199 +
2200 +       /* create /proc/net/can/bcm directory */
2201 +       proc_dir = proc_mkdir(CAN_PROC_DIR"/"IDENT, NULL);
2202 +
2203 +       if (proc_dir)
2204 +               proc_dir->owner = THIS_MODULE;
2205 +
2206 +       return 0;
2207 +}
2208 +
2209 +static void __exit bcm_module_exit(void)
2210 +{
2211 +       can_proto_unregister(&bcm_can_proto);
2212 +
2213 +       if (proc_dir)
2214 +               remove_proc_entry(CAN_PROC_DIR"/"IDENT, NULL);
2215 +
2216 +}
2217 +
2218 +/**************************************************/
2219 +/* initial settings at socket creation time       */
2220 +/**************************************************/
2221 +
2222 +static int bcm_init(struct sock *sk)
2223 +{
2224 +       struct bcm_opt *bo = bcm_sk(sk);
2225 +
2226 +       bo->bound            = 0;
2227 +       bo->ifindex          = 0;
2228 +       bo->dropped_usr_msgs = 0;
2229 +       bo->bcm_proc_read    = NULL;
2230 +
2231 +       INIT_LIST_HEAD(&bo->tx_ops);
2232 +       INIT_LIST_HEAD(&bo->rx_ops);
2233 +
2234 +       return 0;
2235 +}
2236 +
2237 +/**************************************************/
2238 +/* handling of netdevice problems                 */
2239 +/**************************************************/
2240 +
2241 +static void bcm_notifier(unsigned long msg, void *data)
2242 +{
2243 +       struct sock *sk = (struct sock *)data;
2244 +       struct bcm_opt *bo = bcm_sk(sk);
2245 +
2246 +       DBG("called for sock %p\n", sk);
2247 +
2248 +       switch (msg) {
2249 +       case NETDEV_UNREGISTER:
2250 +               bo->bound   = 0;
2251 +               bo->ifindex = 0;
2252 +               /* fallthrough */
2253 +       case NETDEV_DOWN:
2254 +               sk->sk_err = ENETDOWN;
2255 +               if (!sock_flag(sk, SOCK_DEAD))
2256 +                       sk->sk_error_report(sk);
2257 +       }
2258 +}
2259 +
2260 +/**************************************************/
2261 +/* standard socket functions                      */
2262 +/**************************************************/
2263 +
2264 +static int bcm_release(struct socket *sock)
2265 +{
2266 +       struct sock *sk = sock->sk;
2267 +       struct bcm_opt *bo = bcm_sk(sk);
2268 +       struct bcm_op *op, *next;
2269 +
2270 +       DBG("socket %p, sk %p\n", sock, sk);
2271 +
2272 +       /* remove bcm_ops, timer, rx_unregister(), etc. */
2273 +
2274 +       list_for_each_entry_safe(op, next, &bo->tx_ops, list) {
2275 +               DBG("removing tx_op %p for can_id %03X\n", op, op->can_id);
2276 +               bcm_remove_op(op);
2277 +       }
2278 +
2279 +       list_for_each_entry_safe(op, next, &bo->rx_ops, list) {
2280 +               DBG("removing rx_op %p for can_id %03X\n", op, op->can_id);
2281 +
2282 +               /* Don't care if we're bound or not (due to netdev problems) */
2283 +               /* can_rx_unregister() is always a save thing to do here     */
2284 +               if (op->ifindex) {
2285 +                       struct net_device *dev = dev_get_by_index(op->ifindex);
2286 +                       if (dev) {
2287 +                               can_rx_unregister(dev, op->can_id,
2288 +                                                 REGMASK(op->can_id),
2289 +                                                 bcm_rx_handler, op);
2290 +                               dev_put(dev);
2291 +                       }
2292 +               } else
2293 +                       can_rx_unregister(NULL, op->can_id,
2294 +                                         REGMASK(op->can_id),
2295 +                                         bcm_rx_handler, op);
2296 +
2297 +               bcm_remove_op(op);
2298 +       }
2299 +
2300 +       /* remove procfs entry */
2301 +       if ((proc_dir) && (bo->bcm_proc_read)) {
2302 +               remove_proc_entry(bo->procname, proc_dir);
2303 +       }
2304 +
2305 +       /* remove device notifier */
2306 +       if (bo->ifindex) {
2307 +               struct net_device *dev = dev_get_by_index(bo->ifindex);
2308 +               if (dev) {
2309 +                       can_dev_unregister(dev, bcm_notifier, sk);
2310 +                       dev_put(dev);
2311 +               }
2312 +       }
2313 +
2314 +       sock_put(sk);
2315 +
2316 +       return 0;
2317 +}
2318 +
2319 +static int bcm_connect(struct socket *sock, struct sockaddr *uaddr, int len,
2320 +                      int flags)
2321 +{
2322 +       struct sockaddr_can *addr = (struct sockaddr_can *)uaddr;
2323 +       struct sock *sk = sock->sk;
2324 +       struct bcm_opt *bo = bcm_sk(sk);
2325 +
2326 +       if (bo->bound)
2327 +               return -EISCONN;
2328 +
2329 +       /* bind a device to this socket */
2330 +       if (addr->can_ifindex) {
2331 +               struct net_device *dev = dev_get_by_index(addr->can_ifindex);
2332 +               if (!dev) {
2333 +                       DBG("could not find device index %d\n",
2334 +                           addr->can_ifindex);
2335 +                       return -ENODEV;
2336 +               }
2337 +               bo->ifindex = dev->ifindex;
2338 +               can_dev_register(dev, bcm_notifier, sk); /* register notif. */
2339 +               dev_put(dev);
2340 +
2341 +               DBG("socket %p bound to device %s (idx %d)\n",
2342 +                   sock, dev->name, dev->ifindex);
2343 +       } else {
2344 +               /* no notifier for ifindex = 0 ('any' CAN device) */
2345 +               bo->ifindex = 0;
2346 +       }
2347 +
2348 +       bo->bound = 1;
2349 +
2350 +       if (proc_dir) {
2351 +               /* unique socket address as filename */
2352 +               sprintf(bo->procname, "%p", sock);
2353 +               bo->bcm_proc_read = create_proc_read_entry(bo->procname, 0644,
2354 +                                                          proc_dir,
2355 +                                                          bcm_read_proc, sk);
2356 +       }
2357 +
2358 +       return 0;
2359 +}
2360 +
2361 +static int bcm_sendmsg(struct kiocb *iocb, struct socket *sock,
2362 +                      struct msghdr *msg, size_t size)
2363 +{
2364 +       struct sock *sk = sock->sk;
2365 +       struct bcm_opt *bo = bcm_sk(sk);
2366 +       int ifindex = bo->ifindex; /* default ifindex for this bcm_op */
2367 +       struct bcm_msg_head msg_head;
2368 +       int ret; /* read bytes or error codes as return value */
2369 +
2370 +       if (!bo->bound) {
2371 +               DBG("sock %p not bound\n", sk);
2372 +               return -ENOTCONN;
2373 +       }
2374 +
2375 +       /* check for alternative ifindex for this bcm_op */
2376 +
2377 +       if (!ifindex && msg->msg_name) { /* no bound device as default */
2378 +               struct sockaddr_can *addr = 
2379 +                       (struct sockaddr_can *)msg->msg_name;
2380 +               if (addr->can_family != AF_CAN)
2381 +                       return -EINVAL;
2382 +               ifindex = addr->can_ifindex; /* ifindex from sendto() */
2383 +
2384 +               if (ifindex && !dev_get_by_index(ifindex)) {
2385 +                       DBG("device %d not found\n", ifindex);
2386 +                       return -ENODEV;
2387 +               }
2388 +       }
2389 +
2390 +       /* read message head information */
2391 +
2392 +       if ((ret = memcpy_fromiovec((u8*)&msg_head, msg->msg_iov,
2393 +                                   MHSIZ)) < 0)
2394 +               return ret;
2395 +
2396 +       DBG("opcode %d for can_id %03X\n", msg_head.opcode, msg_head.can_id);
2397 +
2398 +       switch (msg_head.opcode) {
2399 +
2400 +       case TX_SETUP:
2401 +
2402 +               ret = bcm_tx_setup(&msg_head, msg, ifindex, sk);
2403 +               break;
2404 +
2405 +       case RX_SETUP:
2406 +
2407 +               ret = bcm_rx_setup(&msg_head, msg, ifindex, sk);
2408 +               break;
2409 +
2410 +       case TX_DELETE:
2411 +
2412 +               if (bcm_delete_tx_op(&bo->tx_ops, msg_head.can_id, ifindex))
2413 +                       ret = MHSIZ;
2414 +               else
2415 +                       ret = -EINVAL;
2416 +               break;
2417 +                   
2418 +       case RX_DELETE:
2419 +
2420 +               if (bcm_delete_rx_op(&bo->rx_ops, msg_head.can_id, ifindex))
2421 +                       ret = MHSIZ;
2422 +               else
2423 +                       ret = -EINVAL;
2424 +               break;
2425 +
2426 +       case TX_READ:
2427 +
2428 +               /* reuse msg_head for the reply */
2429 +               msg_head.opcode  = TX_STATUS; /* reply to TX_READ */
2430 +               ret = bcm_read_op(&bo->tx_ops, &msg_head, ifindex);
2431 +               break;
2432 +
2433 +       case RX_READ:
2434 +
2435 +               /* reuse msg_head for the reply */
2436 +               msg_head.opcode  = RX_STATUS; /* reply to RX_READ */
2437 +               ret = bcm_read_op(&bo->rx_ops, &msg_head, ifindex);
2438 +               break;
2439 +
2440 +       case TX_SEND:
2441 +
2442 +               if (msg_head.nframes < 1) /* we need at least one can_frame */
2443 +                       return -EINVAL;
2444 +
2445 +               ret = bcm_tx_send(msg, ifindex, sk);
2446 +               break;
2447 +
2448 +       default:
2449 +
2450 +               DBG("Unknown opcode %d\n", msg_head.opcode);
2451 +               ret = -EINVAL;
2452 +               break;
2453 +       }
2454 +
2455 +       return ret;
2456 +}
2457 +
2458 +static int bcm_recvmsg(struct kiocb *iocb, struct socket *sock,
2459 +                      struct msghdr *msg, size_t size, int flags)
2460 +{
2461 +       struct sock *sk = sock->sk;
2462 +       struct sk_buff *skb;
2463 +       int error = 0;
2464 +       int noblock;
2465 +       int err;
2466 +
2467 +       DBG("socket %p, sk %p\n", sock, sk);
2468 +
2469 +       noblock =  flags & MSG_DONTWAIT;
2470 +       flags   &= ~MSG_DONTWAIT;
2471 +       if (!(skb = skb_recv_datagram(sk, flags, noblock, &error))) {
2472 +               return error;
2473 +       }
2474 +
2475 +       DBG("delivering skbuff %p\n", skb);
2476 +       DBG_SKB(skb);
2477 +
2478 +       if (skb->len < size)
2479 +               size = skb->len;
2480 +       if ((err = memcpy_toiovec(msg->msg_iov, skb->data, size)) < 0) {
2481 +               skb_free_datagram(sk, skb);
2482 +               return err;
2483 +       }
2484 +
2485 +       sock_recv_timestamp(msg, sk, skb);
2486 +
2487 +       if (msg->msg_name) {
2488 +               msg->msg_namelen = sizeof(struct sockaddr_can);
2489 +               memcpy(msg->msg_name, skb->cb, msg->msg_namelen);
2490 +       }
2491 +
2492 +       DBG("freeing sock %p, skbuff %p\n", sk, skb);
2493 +       skb_free_datagram(sk, skb);
2494 +
2495 +       return size;
2496 +}
2497 +
2498 +static unsigned int bcm_poll(struct file *file, struct socket *sock,
2499 +                            poll_table *wait)
2500 +{
2501 +       unsigned int mask = 0;
2502 +
2503 +       DBG("socket %p\n", sock);
2504 +
2505 +       mask = datagram_poll(file, sock, wait);
2506 +       return mask;
2507 +}
2508 +
2509 +/**************************************************/
2510 +/* helper functions for bcm_sendmsg()             */
2511 +/**************************************************/
2512 +
2513 +static int bcm_tx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg,
2514 +                       int ifindex, struct sock *sk)
2515 +{
2516 +       struct bcm_opt *bo = bcm_sk(sk);
2517 +       struct bcm_op *op;
2518 +       int i, err;
2519 +
2520 +       if (!ifindex) /* we need a real device to send frames */
2521 +               return -ENODEV;
2522 +
2523 +       if (msg_head->nframes < 1) /* we need at least one can_frame */
2524 +               return -EINVAL;
2525 +
2526 +       /* check the given can_id */
2527 +
2528 +       if ((op = bcm_find_op(&bo->tx_ops, msg_head->can_id, ifindex))) {
2529 +
2530 +               /* update existing BCM operation */
2531 +
2532 +               DBG("TX_SETUP: modifying existing tx_op %p for can_id %03X\n",
2533 +                   op, msg_head->can_id);
2534 +
2535 +               /* Do we need more space for the can_frames than currently */
2536 +               /* allocated? -> This is a _really_ unusual use-case and   */
2537 +               /* therefore (complexity / locking) it is not supported.   */
2538 +               if (msg_head->nframes > op->nframes)
2539 +                       return -E2BIG;
2540 +
2541 +               /* update can_frames content */
2542 +               for (i = 0; i < msg_head->nframes; i++) {
2543 +                       if ((err = memcpy_fromiovec((u8*)&op->frames[i],
2544 +                                                   msg->msg_iov, CFSIZ)) < 0)
2545 +                               return err;
2546 +
2547 +                       if (msg_head->flags & TX_CP_CAN_ID) {
2548 +                               /* copy can_id into frame */
2549 +                               op->frames[i].can_id = msg_head->can_id;
2550 +                       }
2551 +               }
2552 +
2553 +       } else {
2554 +               /* insert new BCM operation for the given can_id */
2555 +
2556 +               if (!(op = kmalloc(OPSIZ, GFP_KERNEL)))
2557 +                       return -ENOMEM;
2558 +
2559 +               memset(op, 0, OPSIZ); /* init to zero, e.g. for timers */
2560 +
2561 +               DBG("TX_SETUP: creating new tx_op %p for can_id %03X\n",
2562 +                   op, msg_head->can_id);
2563 +
2564 +               op->can_id    = msg_head->can_id;
2565 +
2566 +               /* create array for can_frames and copy the data */
2567 +               if (!(op->frames = kmalloc(msg_head->nframes * CFSIZ,
2568 +                                          GFP_KERNEL))) {
2569 +                       kfree(op);
2570 +                       return -ENOMEM;
2571 +               }
2572 +
2573 +               for (i = 0; i < msg_head->nframes; i++) {
2574 +                       if ((err = memcpy_fromiovec((u8*)&op->frames[i],
2575 +                                                   msg->msg_iov,
2576 +                                                   CFSIZ)) < 0) {
2577 +                               kfree(op->frames);
2578 +                               kfree(op);
2579 +                               return err;
2580 +                       }
2581 +
2582 +                       if (msg_head->flags & TX_CP_CAN_ID) {
2583 +                               /* copy can_id into frame */
2584 +                               op->frames[i].can_id = msg_head->can_id;
2585 +                       }
2586 +               }
2587 +
2588 +               /* tx_ops never compare with previous received messages */
2589 +               op->last_frames = NULL;
2590 +
2591 +               /* bcm_can_tx / bcm_tx_timeout_handler needs this */
2592 +               op->sk = sk;
2593 +
2594 +               op->ifindex = ifindex;
2595 +
2596 +               /* initialize uninitialized (kmalloc) structure */
2597 +               init_timer(&op->timer);
2598 +
2599 +               /* currently unused in tx_ops */
2600 +               init_timer(&op->thrtimer);
2601 +
2602 +               /* handler for tx_ops */
2603 +               op->timer.function = bcm_tx_timeout_handler;
2604 +
2605 +               /* timer.data points to this op-structure */
2606 +               op->timer.data = (unsigned long)op;
2607 +
2608 +               /* add this bcm_op to the list of the tx_ops */
2609 +               list_add(&op->list, &bo->tx_ops);
2610 +
2611 +       } /* if ((op = bcm_find_op(&bo->tx_ops, msg_head->can_id, ifindex))) */
2612 +
2613 +       if (op->nframes != msg_head->nframes) {
2614 +               op->nframes   = msg_head->nframes;
2615 +               /* start multiple frame transmission with index 0 */
2616 +               op->currframe = 0;
2617 +       }
2618 +
2619 +       /* check flags */
2620 +
2621 +       op->flags = msg_head->flags;
2622 +
2623 +       if (op->flags & TX_RESET_MULTI_IDX) {
2624 +               /* start multiple frame transmission with index 0 */
2625 +               op->currframe = 0; 
2626 +       }
2627 +
2628 +       if (op->flags & SETTIMER) {
2629 +
2630 +               /* set timer values */
2631 +
2632 +               op->count   = msg_head->count;
2633 +               op->ival1   = msg_head->ival1;
2634 +               op->ival2   = msg_head->ival2;
2635 +               op->j_ival1 = timeval2jiffies(&msg_head->ival1, 1);
2636 +               op->j_ival2 = timeval2jiffies(&msg_head->ival2, 1);
2637 +
2638 +               DBG("TX_SETUP: SETTIMER count=%d j_ival1=%ld j_ival2=%ld\n",
2639 +                   op->count, op->j_ival1, op->j_ival2);
2640 +
2641 +               /* disable an active timer due to zero values? */
2642 +               if (!op->j_ival1 && !op->j_ival2) {
2643 +                       del_timer(&op->timer);
2644 +                       DBG("TX_SETUP: SETTIMER disabled timer.\n");
2645 +               }
2646 +       }
2647 +
2648 +       if ((op->flags & STARTTIMER) &&
2649 +           ((op->j_ival1 && op->count) || op->j_ival2)) {
2650 +
2651 +               del_timer(&op->timer);
2652 +
2653 +               /* spec: send can_frame when starting timer */
2654 +               op->flags |= TX_ANNOUNCE;
2655 +
2656 +               if (op->j_ival1 && (op->count > 0)){
2657 +                       op->timer.expires = jiffies + op->j_ival1;
2658 +                       /* op->count-- is done in bcm_tx_timeout_handler */
2659 +                       DBG("TX_SETUP: adding timer ival1. func=%p data=%p "
2660 +                           "exp=0x%08X\n",
2661 +                           op->timer.function,
2662 +                           (char*) op->timer.data,
2663 +                           (unsigned int) op->timer.expires);
2664 +               } else{
2665 +                       op->timer.expires = jiffies + op->j_ival2;
2666 +                       DBG("TX_SETUP: adding timer ival2. func=%p data=%p "
2667 +                           "exp=0x%08X\n",
2668 +                           op->timer.function,
2669 +                           (char*) op->timer.data,
2670 +                           (unsigned int) op->timer.expires);
2671 +               }
2672 +
2673 +               add_timer(&op->timer);
2674 +       }
2675 +
2676 +       if (op->flags & TX_ANNOUNCE)
2677 +               bcm_can_tx(op);
2678 +
2679 +       return msg_head->nframes * CFSIZ + MHSIZ;
2680 +}
2681 +
2682 +static int bcm_rx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg,
2683 +                       int ifindex, struct sock *sk)
2684 +{
2685 +       struct bcm_opt *bo = bcm_sk(sk);
2686 +       struct bcm_op *op;
2687 +       int do_rx_register;
2688 +       int err;
2689 +
2690 +       if ((msg_head->flags & RX_FILTER_ID) || (!(msg_head->nframes))) {
2691 +               /* be robust against wrong usage ... */
2692 +               msg_head->flags |= RX_FILTER_ID;
2693 +               msg_head->nframes = 0; /* ignore trailing garbage */
2694 +       }
2695 +
2696 +       if ((msg_head->flags & RX_RTR_FRAME) &&
2697 +           ((msg_head->nframes != 1) ||
2698 +            (!(msg_head->can_id & CAN_RTR_FLAG)))) {
2699 +
2700 +               DBG("RX_SETUP: bad RX_RTR_FRAME setup!\n");
2701 +               return -EINVAL;
2702 +       }
2703 +
2704 +       /* check the given can_id */
2705 +
2706 +       if ((op = bcm_find_op(&bo->rx_ops, msg_head->can_id, ifindex))) {
2707 +
2708 +               /* update existing BCM operation */
2709 +
2710 +               DBG("RX_SETUP: modifying existing rx_op %p for can_id %03X\n",
2711 +                   op, msg_head->can_id);
2712 +
2713 +               /* Do we need more space for the can_frames than currently */
2714 +               /* allocated? -> This is a _really_ unusual use-case and   */
2715 +               /* therefore (complexity / locking) it is not supported.   */
2716 +               if (msg_head->nframes > op->nframes)
2717 +                       return -E2BIG;
2718 +
2719 +               if (msg_head->nframes) {
2720 +                       /* update can_frames content */
2721 +                       if ((err = memcpy_fromiovec((u8*)op->frames,
2722 +                                                   msg->msg_iov,
2723 +                                                   msg_head->nframes
2724 +                                                   * CFSIZ) < 0))
2725 +                               return err;
2726 +
2727 +                       /* clear last_frames to indicate 'nothing received' */
2728 +                       memset(op->last_frames, 0, msg_head->nframes * CFSIZ);
2729 +               }
2730 +
2731 +               op->nframes = msg_head->nframes;
2732 +               /* Only an update -> do not call can_rx_register() */
2733 +               do_rx_register = 0;
2734 +
2735 +       } else {
2736 +               /* insert new BCM operation for the given can_id */
2737 +
2738 +               if (!(op = kmalloc(OPSIZ, GFP_KERNEL)))
2739 +                       return -ENOMEM;
2740 +
2741 +               memset(op, 0, OPSIZ); /* init to zero, e.g. for timers */
2742 +
2743 +               DBG("RX_SETUP: creating new rx_op %p for can_id %03X\n",
2744 +                   op, msg_head->can_id);
2745 +
2746 +               op->can_id    = msg_head->can_id;
2747 +               op->nframes   = msg_head->nframes;
2748 +
2749 +               if (msg_head->nframes) {
2750 +
2751 +                       /* create array for can_frames and copy the data */
2752 +                       if (!(op->frames = kmalloc(msg_head->nframes * CFSIZ,
2753 +                                                  GFP_KERNEL))) {
2754 +                               kfree(op);
2755 +                               return -ENOMEM;
2756 +                       }
2757 +
2758 +                       if ((err = memcpy_fromiovec((u8*)op->frames,
2759 +                                                   msg->msg_iov,
2760 +                                                   msg_head->nframes
2761 +                                                   * CFSIZ)) < 0) {
2762 +                               kfree(op->frames);
2763 +                               kfree(op);
2764 +                               return err;
2765 +                       }
2766 +
2767 +                       /* create array for received can_frames */
2768 +                       if (!(op->last_frames = kmalloc(msg_head->nframes
2769 +                                                       * CFSIZ,
2770 +                                                       GFP_KERNEL))) {
2771 +                               kfree(op->frames);
2772 +                               kfree(op);
2773 +                               return -ENOMEM;
2774 +                       }
2775 +
2776 +                       /* clear last_frames to indicate 'nothing received' */
2777 +                       memset(op->last_frames, 0, msg_head->nframes * CFSIZ);
2778 +               } else {
2779 +                       /* op->frames = NULL due to memset */
2780 +
2781 +                       /* even when we have the RX_FILTER_ID case, we need */
2782 +                       /* to store the last frame for the throttle feature */
2783 +
2784 +                       /* create array for received can_frames */
2785 +                       if (!(op->last_frames = kmalloc(CFSIZ, GFP_KERNEL))) {
2786 +                               kfree(op);
2787 +                               return -ENOMEM;
2788 +                       }
2789 +
2790 +                       /* clear last_frames to indicate 'nothing received' */
2791 +                       memset(op->last_frames, 0, CFSIZ);
2792 +               }
2793 +
2794 +               op->sk = sk; /* bcm_delete_rx_op() needs this */
2795 +               op->ifindex = ifindex;
2796 +
2797 +               /* initialize uninitialized (kmalloc) structure */
2798 +               init_timer(&op->timer);
2799 +
2800 +               /* init throttle timer for RX_CHANGED */
2801 +               init_timer(&op->thrtimer);
2802 +
2803 +               /* handler for rx timeouts */
2804 +               op->timer.function = bcm_rx_timeout_handler;
2805 +
2806 +               /* timer.data points to this op-structure */
2807 +               op->timer.data = (unsigned long)op;
2808 +
2809 +               /* handler for RX_CHANGED throttle timeouts */
2810 +               op->thrtimer.function = bcm_rx_thr_handler;
2811 +
2812 +               /* timer.data points to this op-structure */
2813 +               op->thrtimer.data = (unsigned long)op;
2814 +
2815 +               op->thrtimer.expires = 0; /* mark disabled timer */
2816 +
2817 +               /* add this bcm_op to the list of the tx_ops */
2818 +               list_add(&op->list, &bo->rx_ops);
2819 +
2820 +               do_rx_register = 1; /* call can_rx_register() */
2821 +
2822 +       } /* if ((op = bcm_find_op(&bo->rx_ops, msg_head->can_id, ifindex))) */
2823 +
2824 +
2825 +       /* check flags */
2826 +
2827 +       op->flags = msg_head->flags;
2828 +
2829 +       if (op->flags & RX_RTR_FRAME) {
2830 +
2831 +               /* no timers in RTR-mode */
2832 +               del_timer(&op->thrtimer);
2833 +               del_timer(&op->timer);
2834 +
2835 +               /* funny feature in RX(!)_SETUP only for RTR-mode: */
2836 +               /* copy can_id into frame BUT without RTR-flag to  */
2837 +               /* prevent a full-load-loopback-test ... ;-]       */
2838 +               if ((op->flags & TX_CP_CAN_ID) ||
2839 +                   (op->frames[0].can_id == op->can_id))
2840 +                       op->frames[0].can_id = op->can_id & ~CAN_RTR_FLAG;
2841 +
2842 +       } else {
2843 +               if (op->flags & SETTIMER) {
2844 +
2845 +                       /* set timer value */
2846 +
2847 +                       op->ival1   = msg_head->ival1;
2848 +                       op->j_ival1 = timeval2jiffies(&msg_head->ival1, 1);
2849 +                       op->ival2   = msg_head->ival2;
2850 +                       op->j_ival2 = timeval2jiffies(&msg_head->ival2, 1);
2851 +
2852 +                       DBG("RX_SETUP: SETTIMER j_ival1=%ld j_ival2=%ld\n",
2853 +                           op->j_ival1, op->j_ival2);
2854 +
2855 +                       /* disable an active timer due to zero value? */
2856 +                       if (!op->j_ival1) {
2857 +                               del_timer(&op->timer);
2858 +                               DBG("RX_SETUP: disabled timer rx timeouts.\n");
2859 +                       }
2860 +
2861 +                       /* free currently blocked msgs ? */
2862 +                       if (op->thrtimer.expires) { /* blocked by timer? */
2863 +                               DBG("RX_SETUP: unblocking throttled msgs.\n");
2864 +                               del_timer(&op->thrtimer);
2865 +                               /* send blocked msgs hereafter */
2866 +                               op->thrtimer.expires = jiffies + 2;
2867 +                               add_timer(&op->thrtimer);
2868 +                       }
2869 +                       /* if (op->j_ival2) is zero, no (new) throttling     */
2870 +                       /* will happen. For details see functions            */
2871 +                       /* bcm_rx_update_and_send() and bcm_rx_thr_handler() */
2872 +               }
2873 +
2874 +               if ((op->flags & STARTTIMER) && op->j_ival1) {
2875 +
2876 +                       del_timer(&op->timer);
2877 +
2878 +                       op->timer.expires = jiffies + op->j_ival1;
2879 +
2880 +                       DBG("RX_SETUP: adding timer ival1. func=%p data=%p"
2881 +                           " exp=0x%08X\n",
2882 +                           (char *) op->timer.function,
2883 +                           (char *) op->timer.data,
2884 +                           (unsigned int) op->timer.expires);
2885 +
2886 +                       add_timer(&op->timer);
2887 +               }
2888 +       }
2889 +
2890 +       /* now we can register for can_ids, if we added a new bcm_op */
2891 +       if (do_rx_register) {
2892 +               DBG("RX_SETUP: can_rx_register() for can_id %03X. "
2893 +                   "rx_op is %p\n", op->can_id, op);
2894 +
2895 +               if (ifindex) {
2896 +                       struct net_device *dev = dev_get_by_index(ifindex);
2897 +
2898 +                       if (dev) {
2899 +                               can_rx_register(dev, op->can_id,
2900 +                                               REGMASK(op->can_id),
2901 +                                               bcm_rx_handler, op, IDENT);
2902 +                               dev_put(dev);
2903 +                       }
2904 +               } else 
2905 +                       can_rx_register(NULL, op->can_id, REGMASK(op->can_id),
2906 +                                       bcm_rx_handler, op, IDENT);
2907 +       }
2908 +
2909 +       return msg_head->nframes * CFSIZ + MHSIZ;
2910 +}
2911 +
2912 +static int bcm_tx_send(struct msghdr *msg, int ifindex, struct sock *sk)
2913 +{
2914 +       struct sk_buff *skb;
2915 +       struct net_device *dev;
2916 +       int err;
2917 +
2918 +       /* just copy and send one can_frame */
2919 +
2920 +       if (!ifindex) /* we need a real device to send frames */
2921 +               return -ENODEV;
2922 +
2923 +       skb = alloc_skb(CFSIZ, GFP_KERNEL);
2924 +
2925 +       if (!skb)
2926 +               return -ENOMEM;
2927 +
2928 +       if ((err = memcpy_fromiovec(skb_put(skb, CFSIZ), msg->msg_iov,
2929 +                                   CFSIZ)) < 0) {
2930 +               kfree_skb(skb);
2931 +               return err;
2932 +       }
2933 +
2934 +       DBG_FRAME("BCM: TX_SEND: sending frame",
2935 +                 (struct can_frame *)skb->data);
2936 +       dev = dev_get_by_index(ifindex);
2937 +
2938 +       if (!dev) {
2939 +               kfree_skb(skb);
2940 +               return -ENODEV;
2941 +       }
2942 +
2943 +       skb->dev = dev;
2944 +       skb->sk  = sk;
2945 +       can_send(skb, 1); /* send with loopback */
2946 +       dev_put(dev);
2947 +
2948 +       return CFSIZ + MHSIZ;
2949 +}
2950 +
2951 +static int bcm_read_op(struct list_head *ops, struct bcm_msg_head *msg_head,
2952 +                      int ifindex)
2953 +{
2954 +       struct bcm_op *op;
2955 +       int ret;
2956 +
2957 +       if ((op = bcm_find_op(ops, msg_head->can_id, ifindex))) {
2958 +
2959 +               DBG("TRX_READ: sending status for can_id %03X\n",
2960 +                   msg_head->can_id);
2961 +               /* put current values into msg_head */
2962 +               msg_head->flags   = op->flags;
2963 +               msg_head->count   = op->count;
2964 +               msg_head->ival1   = op->ival1;
2965 +               msg_head->ival2   = op->ival2;
2966 +               msg_head->nframes = op->nframes;
2967 +
2968 +               bcm_send_to_user(op, msg_head, op->frames, NULL);
2969 +
2970 +               ret = MHSIZ;
2971 +
2972 +       } else {
2973 +
2974 +               DBG("TRX_READ: did not find op for can_id %03X\n",
2975 +                   msg_head->can_id);
2976 +               ret = -EINVAL;
2977 +       }
2978 +
2979 +       return ret;
2980 +}
2981 +
2982 +/**************************************************/
2983 +/* procfs functions                               */
2984 +/**************************************************/
2985 +
2986 +static char *bcm_proc_getifname(int ifindex)
2987 +{
2988 +       struct net_device *dev;
2989 +
2990 +       if (!ifindex)
2991 +               return "any";
2992 +
2993 +       dev = __dev_get_by_index(ifindex); /* no usage counting */
2994 +       if (dev)
2995 +               return dev->name;
2996 +
2997 +       return "???";
2998 +}
2999 +
3000 +static int bcm_read_proc(char *page, char **start, off_t off,
3001 +                        int count, int *eof, void *data)
3002 +{
3003 +       int len = 0;
3004 +       struct sock *sk = (struct sock *)data;
3005 +       struct bcm_opt *bo = bcm_sk(sk);
3006 +       struct bcm_op *op;
3007 +
3008 +       len += snprintf(page + len, PAGE_SIZE - len, ">>> socket %p",
3009 +                       sk->sk_socket);
3010 +       len += snprintf(page + len, PAGE_SIZE - len, " / sk %p", sk);
3011 +       len += snprintf(page + len, PAGE_SIZE - len, " / bo %p", bo);
3012 +       len += snprintf(page + len, PAGE_SIZE - len, " / dropped %lu",
3013 +                       bo->dropped_usr_msgs);
3014 +       len += snprintf(page + len, PAGE_SIZE - len, " / bound %s",
3015 +                       bcm_proc_getifname(bo->ifindex));
3016 +       len += snprintf(page + len, PAGE_SIZE - len, " <<<\n");
3017 +
3018 +       list_for_each_entry(op, &bo->rx_ops, list) {
3019 +
3020 +               unsigned long reduction;
3021 +
3022 +               /* print only active entries & prevent division by zero */
3023 +               if (!op->frames_abs)
3024 +                       continue;
3025 +
3026 +               len += snprintf(page + len, PAGE_SIZE - len,
3027 +                               "rx_op: %03X %-5s ",
3028 +                               op->can_id, bcm_proc_getifname(op->ifindex));
3029 +               len += snprintf(page + len, PAGE_SIZE - len, "[%d]%c ",
3030 +                               op->nframes,
3031 +                               (op->flags & RX_CHECK_DLC)?'d':' ');
3032 +               if (op->j_ival1)
3033 +                       len += snprintf(page + len, PAGE_SIZE - len,
3034 +                                       "timeo=%ld ", op->j_ival1);
3035 +
3036 +               if (op->j_ival2)
3037 +                       len += snprintf(page + len, PAGE_SIZE - len,
3038 +                                       "thr=%ld ", op->j_ival2);
3039 +
3040 +               len += snprintf(page + len, PAGE_SIZE - len,
3041 +                               "# recv %ld (%ld) => reduction: ",
3042 +                               op->frames_filtered, op->frames_abs);
3043 +
3044 +               reduction = 100 - (op->frames_filtered * 100) / op->frames_abs;
3045 +
3046 +               len += snprintf(page + len, PAGE_SIZE - len, "%s%ld%%\n",
3047 +                               (reduction == 100)?"near ":"", reduction);
3048 +
3049 +               if (len > PAGE_SIZE - 200) {
3050 +                       /* mark output cut off */
3051 +                       len += snprintf(page + len, PAGE_SIZE - len, "(..)\n");
3052 +                       break;
3053 +               }
3054 +       }
3055 +
3056 +       list_for_each_entry(op, &bo->tx_ops, list) {
3057 +
3058 +               len += snprintf(page + len, PAGE_SIZE - len,
3059 +                               "tx_op: %03X %s [%d] ",
3060 +                               op->can_id, bcm_proc_getifname(op->ifindex),
3061 +                               op->nframes);
3062 +               if (op->j_ival1)
3063 +                       len += snprintf(page + len, PAGE_SIZE - len, "t1=%ld ",
3064 +                                       op->j_ival1);
3065 +
3066 +               if (op->j_ival2)
3067 +                       len += snprintf(page + len, PAGE_SIZE - len, "t2=%ld ",
3068 +                                       op->j_ival2);
3069 +
3070 +               len += snprintf(page + len, PAGE_SIZE - len, "# sent %ld\n",
3071 +                               op->frames_abs);
3072 +
3073 +               if (len > PAGE_SIZE - 100) {
3074 +                       /* mark output cut off */
3075 +                       len += snprintf(page + len, PAGE_SIZE - len, "(..)\n");
3076 +                       break;
3077 +               }
3078 +       }
3079 +
3080 +       len += snprintf(page + len, PAGE_SIZE - len, "\n");
3081 +
3082 +       *eof = 1;
3083 +       return len;
3084 +}
3085 +
3086 +/**************************************************/
3087 +/* bcm_op handling tx path                        */
3088 +/**************************************************/
3089 +
3090 +static void bcm_can_tx(struct bcm_op *op)
3091 +{
3092 +       struct sk_buff *skb;
3093 +       struct net_device *dev;
3094 +       struct can_frame *cf = &op->frames[op->currframe];
3095 +
3096 +       DBG_FRAME("BCM: bcm_can_tx: sending frame", cf);
3097 +
3098 +       if (!op->ifindex)
3099 +               return; /* no target device -> exit */
3100 +
3101 +       dev = dev_get_by_index(op->ifindex);
3102 +
3103 +       if (!dev)
3104 +               return; /* should this bcm_op remove itself here? */
3105 +
3106 +       skb = alloc_skb(CFSIZ,
3107 +                       in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
3108 +
3109 +       if (!skb)
3110 +               goto out; /* no memory */
3111 +
3112 +       memcpy(skb_put(skb, CFSIZ), cf, CFSIZ);
3113 +
3114 +       skb->dev = dev;
3115 +       skb->sk = op->sk;
3116 +       can_send(skb, 1); /* send with loopback */
3117 +
3118 +       op->currframe++;
3119 +       op->frames_abs++; /* statistics */
3120 +
3121 +       /* reached last frame? */
3122 +       if (op->currframe >= op->nframes)
3123 +               op->currframe = 0;
3124 + out:
3125 +       dev_put(dev);
3126 +}
3127 +
3128 +static void bcm_tx_timeout_handler(unsigned long data)
3129 +{
3130 +       struct bcm_op *op = (struct bcm_op*)data;
3131 +
3132 +       DBG("Called with bcm_op %p\n", op);
3133 +
3134 +       if (op->j_ival1 && (op->count > 0)) {
3135 +
3136 +               op->count--;
3137 +
3138 +               if (!op->count && (op->flags & TX_COUNTEVT)) {
3139 +                       /* create notification to user */
3140 +
3141 +                       struct bcm_msg_head msg_head;
3142 +
3143 +                       DBG("sending TX_EXPIRED for can_id %03X\n",
3144 +                           op->can_id);
3145 +
3146 +                       msg_head.opcode  = TX_EXPIRED;
3147 +                       msg_head.flags   = op->flags;
3148 +                       msg_head.count   = op->count;
3149 +                       msg_head.ival1   = op->ival1;
3150 +                       msg_head.ival2   = op->ival2;
3151 +                       msg_head.can_id  = op->can_id;
3152 +                       msg_head.nframes = 0;
3153 +
3154 +                       bcm_send_to_user(op, &msg_head, NULL, NULL);
3155 +               }
3156 +       }
3157 +
3158 +       DBG("count=%d j_ival1=%ld j_ival2=%ld\n",
3159 +           op->count, op->j_ival1, op->j_ival2);
3160 +
3161 +       if (op->j_ival1 && (op->count > 0)) {
3162 +
3163 +               op->timer.expires = jiffies + op->j_ival1;
3164 +               add_timer(&op->timer);
3165 +
3166 +               DBG("adding timer ival1. func=%p data=%p exp=0x%08X\n",
3167 +                   op->timer.function,
3168 +                   (char*) op->timer.data,
3169 +                   (unsigned int) op->timer.expires);
3170 +
3171 +               bcm_can_tx(op); /* send (next) frame */
3172 +       } else {
3173 +               if (op->j_ival2) {
3174 +                       op->timer.expires = jiffies + op->j_ival2;
3175 +                       add_timer(&op->timer);
3176 +
3177 +                       DBG("adding timer ival2. func=%p data=%p exp=0x%08X\n",
3178 +                           op->timer.function,
3179 +                           (char*) op->timer.data,
3180 +                           (unsigned int) op->timer.expires);
3181 +
3182 +                       bcm_can_tx(op); /* send (next) frame */
3183 +               } else
3184 +                       DBG("no timer restart\n");
3185 +       }
3186 +
3187 +       return;
3188 +
3189 +}
3190 +
3191 +/**************************************************/
3192 +/* bcm_op handling rx path                        */
3193 +/**************************************************/
3194 +
3195 +static void bcm_rx_handler(struct sk_buff *skb, void *data)
3196 +{
3197 +       struct bcm_op *op = (struct bcm_op*)data;
3198 +       struct can_frame rxframe;
3199 +       int i;
3200 +
3201 +       del_timer(&op->timer); /* disable timeout */
3202 +
3203 +       DBG("Called with bcm_op %p\n", op);
3204 +
3205 +       if (skb->len == sizeof(rxframe)) {
3206 +               memcpy(&rxframe, skb->data, sizeof(rxframe));
3207 +               skb_get_timestamp(skb, &op->rx_stamp); /* save rx timestamp */
3208 +               /* save originator for recvfrom() */
3209 +               op->rx_ifindex = skb->dev->ifindex;
3210 +               op->frames_abs++; /* statistics */
3211 +               kfree_skb(skb);
3212 +               DBG("got can_frame with can_id %03X\n", rxframe.can_id);
3213 +       } else {
3214 +               DBG("Wrong skb->len = %d\n", skb->len);
3215 +               kfree_skb(skb);
3216 +               return;
3217 +       }
3218 +
3219 +       DBG_FRAME("BCM: bcm_rx_handler: CAN frame", &rxframe);
3220 +
3221 +       if (op->can_id != rxframe.can_id) {
3222 +               DBG("ERROR! Got wrong can_id %03X! Expected %03X.\n",
3223 +                   rxframe.can_id, op->can_id);
3224 +               return;
3225 +       }
3226 +
3227 +       if (op->flags & RX_RTR_FRAME) { /* send reply for RTR-request */
3228 +               DBG("RTR-request\n");
3229 +               bcm_can_tx(op); /* send op->frames[0] to CAN device */
3230 +               return;
3231 +       }
3232 +
3233 +       if (op->flags & RX_FILTER_ID) { /* the easiest case */
3234 +               DBG("Easy does it with RX_FILTER_ID\n");
3235 +               bcm_rx_update_and_send(op, &op->last_frames[0], &rxframe);
3236 +               bcm_rx_starttimer(op);
3237 +               return;
3238 +       }
3239 +
3240 +       if (op->nframes == 1) { /* simple compare with index 0 */
3241 +               DBG("Simple compare\n");
3242 +               bcm_rx_cmp_to_index(op, 0, &rxframe);
3243 +               bcm_rx_starttimer(op);
3244 +               return;
3245 +       }
3246 +
3247 +       if (op->nframes > 1) { /* multiplex compare */
3248 +
3249 +               DBG("Multiplex compare\n");
3250 +               /* find the first multiplex mask that fits */
3251 +               /* MUX-mask is in index 0 */
3252 +
3253 +               for (i=1; i < op->nframes; i++) {
3254 +
3255 +                       if ((GET_U64(&op->frames[0]) & GET_U64(&rxframe)) ==
3256 +                           (GET_U64(&op->frames[0]) &
3257 +                            GET_U64(&op->frames[i]))) {
3258 +                               DBG("found MUX index %d\n", i);
3259 +                               bcm_rx_cmp_to_index(op, i, &rxframe);
3260 +                               break;
3261 +                       }
3262 +               }
3263 +               bcm_rx_starttimer(op);
3264 +       }
3265 +}
3266 +
3267 +static void bcm_rx_cmp_to_index(struct bcm_op *op, int index,
3268 +                               struct can_frame *rxdata)
3269 +{
3270 +       /* no one uses the MSBs of can_dlc for comparation, */
3271 +       /* so we use it here to detect the first time of reception */
3272 +
3273 +       if (!(op->last_frames[index].can_dlc & RX_RECV)) { /* first time? */
3274 +               DBG("first time :)\n");
3275 +               bcm_rx_update_and_send(op, &op->last_frames[index], rxdata);
3276 +               return;
3277 +       }
3278 +
3279 +       /* do a real check in can_data */
3280 +
3281 +       DBG("op->frames[index].data = 0x%016llx\n",
3282 +           GET_U64(&op->frames[index]));
3283 +       DBG("op->last_frames[index].data = 0x%016llx\n",
3284 +           GET_U64(&op->last_frames[index]));
3285 +       DBG("rxdata->data = 0x%016llx\n", GET_U64(rxdata));
3286 +
3287 +       if ((GET_U64(&op->frames[index]) & GET_U64(rxdata)) !=
3288 +           (GET_U64(&op->frames[index]) & GET_U64(&op->last_frames[index]))) {
3289 +               DBG("relevant data change :)\n");
3290 +               bcm_rx_update_and_send(op, &op->last_frames[index], rxdata);
3291 +               return;
3292 +       }
3293 +
3294 +
3295 +       if (op->flags & RX_CHECK_DLC) {
3296 +
3297 +               /* do a real check in dlc */
3298 +
3299 +               if (rxdata->can_dlc != (op->last_frames[index].can_dlc &
3300 +                                       BCM_CAN_DLC_MASK)) {
3301 +                       DBG("dlc change :)\n");
3302 +                       bcm_rx_update_and_send(op, &op->last_frames[index],
3303 +                                              rxdata);
3304 +                       return;
3305 +               }
3306 +       }
3307 +       DBG("no relevant change :(\n");
3308 +}
3309 +
3310 +static void bcm_rx_update_and_send(struct bcm_op *op,
3311 +                                  struct can_frame *lastdata,
3312 +                                  struct can_frame *rxdata)
3313 +{
3314 +       unsigned long nexttx = op->j_lastmsg + op->j_ival2;
3315 +
3316 +       memcpy(lastdata, rxdata, CFSIZ);
3317 +       lastdata->can_dlc |= RX_RECV; /* mark as used */
3318 +
3319 +       /* throttle bcm_rx_changed ? */
3320 +       if ((op->thrtimer.expires) || /* somebody else is already waiting OR */
3321 +           ((op->j_ival2) && (nexttx > jiffies))) {      /* we have to wait */
3322 +
3323 +               lastdata->can_dlc |= RX_THR; /* mark as 'throttled' */
3324 +
3325 +               if (!(op->thrtimer.expires)) { /* start only the first time */
3326 +                       op->thrtimer.expires = nexttx;
3327 +                       add_timer(&op->thrtimer);
3328 +
3329 +                       DBG("adding thrtimer. func=%p data=%p exp=0x%08X\n",
3330 +                           op->thrtimer.function,
3331 +                           (char*) op->thrtimer.data,
3332 +                           (unsigned int) op->thrtimer.expires);
3333 +               }
3334 +       } else
3335 +               bcm_rx_changed(op, rxdata); /* send RX_CHANGED to the user */
3336 +}
3337 +
3338 +static void bcm_rx_starttimer(struct bcm_op *op)
3339 +{
3340 +       if (op->flags & RX_NO_AUTOTIMER)
3341 +               return;
3342 +
3343 +       if (op->j_ival1) {
3344 +
3345 +               op->timer.expires = jiffies + op->j_ival1;
3346 +
3347 +               DBG("adding rx timeout timer ival1. func=%p data=%p "
3348 +                   "exp=0x%08X\n",
3349 +                   op->timer.function,
3350 +                   (char*) op->timer.data,
3351 +                   (unsigned int) op->timer.expires);
3352 +
3353 +               add_timer(&op->timer);
3354 +       }
3355 +}
3356 +
3357 +
3358 +static void bcm_rx_changed(struct bcm_op *op, struct can_frame *data)
3359 +{
3360 +       struct bcm_msg_head head;
3361 +
3362 +       op->j_lastmsg = jiffies;
3363 +       op->frames_filtered++; /* statistics */
3364 +
3365 +       if (op->frames_filtered > ULONG_MAX/100)
3366 +               op->frames_filtered = op->frames_abs = 0; /* restart */
3367 +
3368 +       DBG("setting j_lastmsg to 0x%08X for rx_op %p\n",
3369 +           (unsigned int) op->j_lastmsg, op);
3370 +       DBG("sending notification\n");
3371 +
3372 +       head.opcode  = RX_CHANGED;
3373 +       head.flags   = op->flags;
3374 +       head.count   = op->count;
3375 +       head.ival1   = op->ival1;
3376 +       head.ival2   = op->ival2;
3377 +       head.can_id  = op->can_id;
3378 +       head.nframes = 1;
3379 +
3380 +       bcm_send_to_user(op, &head, data, &op->rx_stamp);
3381 +}
3382 +
3383 +
3384 +static void bcm_rx_timeout_handler(unsigned long data)
3385 +{
3386 +       struct bcm_op *op = (struct bcm_op*)data;
3387 +       struct bcm_msg_head msg_head;
3388 +
3389 +       DBG("sending RX_TIMEOUT for can_id %03X. op is %p\n", op->can_id, op);
3390 +
3391 +       msg_head.opcode  = RX_TIMEOUT;
3392 +       msg_head.flags   = op->flags;
3393 +       msg_head.count   = op->count;
3394 +       msg_head.ival1   = op->ival1;
3395 +       msg_head.ival2   = op->ival2;
3396 +       msg_head.can_id  = op->can_id;
3397 +       msg_head.nframes = 0;
3398 +
3399 +       bcm_send_to_user(op, &msg_head, NULL, NULL);
3400 +
3401 +       /* no restart of the timer is done here! */
3402 +
3403 +       /* if user wants to be informed, when cyclic CAN-Messages come back */
3404 +       if ((op->flags & RX_ANNOUNCE_RESUME) && op->last_frames) {
3405 +               /* clear received can_frames to indicate 'nothing received' */
3406 +               memset(op->last_frames, 0, op->nframes * CFSIZ);
3407 +               DBG("RX_ANNOUNCE_RESTART\n");
3408 +       }
3409 +
3410 +}
3411 +
3412 +static void bcm_rx_thr_handler(unsigned long data)
3413 +{
3414 +       struct bcm_op *op = (struct bcm_op*)data;
3415 +       int i = 0;
3416 +
3417 +       op->thrtimer.expires = 0; /* mark disabled / consumed timer */
3418 +
3419 +       if (op->nframes > 1){
3420 +
3421 +               DBG("sending MUX RX_CHANGED for can_id %03X. op is %p\n",
3422 +                   op->can_id, op);
3423 +               /* for MUX filter we start at index 1 */
3424 +               for (i=1; i<op->nframes; i++){
3425 +                       if ((op->last_frames) &&
3426 +                           (op->last_frames[i].can_dlc & RX_THR)){
3427 +                               op->last_frames[i].can_dlc &= ~RX_THR;
3428 +                               bcm_rx_changed(op, &op->last_frames[i]);
3429 +                       }
3430 +               }
3431 +       } else {
3432 +
3433 +               DBG("sending simple RX_CHANGED for can_id %03X. op is %p\n",
3434 +                   op->can_id, op);
3435 +               /* for RX_FILTER_ID and simple filter */
3436 +               if (op->last_frames && (op->last_frames[0].can_dlc & RX_THR)){
3437 +                       op->last_frames[0].can_dlc &= ~RX_THR;
3438 +                       bcm_rx_changed(op, &op->last_frames[0]);
3439 +               }
3440 +       }
3441 +}
3442 +
3443 +static void bcm_send_to_user(struct bcm_op *op, struct bcm_msg_head *head,
3444 +                            struct can_frame *frames, struct timeval *tv)
3445 +{
3446 +       struct sk_buff *skb;
3447 +       struct can_frame *firstframe;
3448 +       struct sock *sk = op->sk;
3449 +       int datalen = head->nframes * CFSIZ;
3450 +       struct sockaddr_can *addr;
3451 +       int err;
3452 +
3453 +       skb = alloc_skb(sizeof(*head) + datalen,
3454 +                       in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
3455 +       if (!skb)
3456 +               return;
3457 +
3458 +       memcpy(skb_put(skb, sizeof(*head)), head, sizeof(*head));
3459 +       /* can_frames starting here */
3460 +       firstframe = (struct can_frame *) skb->tail;
3461 +
3462 +       if (tv)
3463 +               skb_set_timestamp(skb, tv); /* restore timestamp */
3464 +
3465 +       addr = (struct sockaddr_can *)skb->cb;
3466 +       memset(addr, 0, sizeof(*addr));
3467 +       addr->can_family  = AF_CAN;
3468 +       /* restore originator for recvfrom() */
3469 +       addr->can_ifindex = op->rx_ifindex;
3470 +
3471 +       if (head->nframes){
3472 +               memcpy(skb_put(skb, datalen), frames, datalen);
3473 +
3474 +               /* the BCM uses the can_dlc-element of the can_frame */
3475 +               /* structure for internal purposes. This is only     */
3476 +               /* relevant for updates that are generated by the    */
3477 +               /* BCM, where nframes is 1                           */
3478 +               if (head->nframes == 1)
3479 +                       firstframe->can_dlc &= BCM_CAN_DLC_MASK;
3480 +       }
3481 +       if ((err = sock_queue_rcv_skb(sk, skb)) < 0) {
3482 +               struct bcm_opt *bo = bcm_sk(sk);
3483 +               DBG("sock_queue_rcv_skb failed: %d\n", err);
3484 +               kfree_skb(skb);
3485 +               bo->dropped_usr_msgs++; /* don't care about overflows */
3486 +       }
3487 +}
3488 +
3489 +/**************************************************/
3490 +/* bcm_op handling: find & delete bcm_op elements */
3491 +/**************************************************/
3492 +
3493 +static struct bcm_op *bcm_find_op(struct list_head *ops, canid_t can_id,
3494 +                                 int ifindex)
3495 +{
3496 +       struct bcm_op *op;
3497 +
3498 +       list_for_each_entry(op, ops, list)
3499 +               if ((op->can_id == can_id) && (op->ifindex == ifindex))
3500 +                       return op;
3501 +
3502 +       return NULL;
3503 +}
3504 +
3505 +static int bcm_delete_rx_op(struct list_head *ops, canid_t can_id, int ifindex)
3506 +{
3507 +       struct bcm_op *op, *n;
3508 +
3509 +       list_for_each_entry_safe(op, n, ops, list) {
3510 +               if ((op->can_id == can_id) && (op->ifindex == ifindex)) {
3511 +                       DBG("removing rx_op %p for can_id %03X\n",
3512 +                           op, op->can_id);
3513 +
3514 +                       /* Don't care if we're bound or not (due to netdev */
3515 +                       /* problems) can_rx_unregister() is always a save  */
3516 +                       /* thing to do here.                               */
3517 +                       if (op->ifindex) {
3518 +                               struct net_device *dev =
3519 +                                       dev_get_by_index(op->ifindex);
3520 +                               if (dev) {
3521 +                                       can_rx_unregister(dev, op->can_id,
3522 +                                                         REGMASK(op->can_id),
3523 +                                                         bcm_rx_handler, op);
3524 +                                       dev_put(dev);
3525 +                               }
3526 +                       } else
3527 +                               can_rx_unregister(NULL, op->can_id,
3528 +                                                 REGMASK(op->can_id),
3529 +                                                 bcm_rx_handler, op);
3530 +
3531 +                       list_del(&op->list);
3532 +                       bcm_remove_op(op);
3533 +                       return 1; /* done */
3534 +               }
3535 +       }
3536 +
3537 +       return 0; /* not found */
3538 +}
3539 +
3540 +static int bcm_delete_tx_op(struct list_head *ops, canid_t can_id, int ifindex)
3541 +{
3542 +       struct bcm_op *op, *n;
3543 +
3544 +       list_for_each_entry_safe(op, n, ops, list) {
3545 +               if ((op->can_id == can_id) && (op->ifindex == ifindex)) {
3546 +                       DBG("removing rx_op %p for can_id %03X\n",
3547 +                           op, op->can_id);
3548 +                       list_del(&op->list);
3549 +                       bcm_remove_op(op);
3550 +                       return 1; /* done */
3551 +               }
3552 +       }
3553 +
3554 +       return 0; /* not found */
3555 +}
3556 +
3557 +static void bcm_remove_op(struct bcm_op *op)
3558 +{
3559 +       del_timer(&op->timer);
3560 +       del_timer(&op->thrtimer);
3561 +       if (op->frames)
3562 +               kfree(op->frames);
3563 +       if (op->last_frames)
3564 +               kfree(op->last_frames);
3565 +       kfree(op);
3566 +
3567 +       return;
3568 +}
3569 +
3570 +module_init(bcm_module_init);
3571 +module_exit(bcm_module_exit);
3572 diff -N -u -r a/net/can/Kconfig c/net/can/Kconfig
3573 --- a/net/can/Kconfig   1970-01-01 01:00:00.000000000 +0100
3574 +++ c/net/can/Kconfig   2007-03-09 13:47:12.000000000 +0100
3575 @@ -0,0 +1,71 @@
3576 +#
3577 +# Controller Area Network (CAN) network layer core configuration
3578 +#
3579 +
3580 +menuconfig CAN
3581 +       depends on NET
3582 +       tristate "CAN bus subsystem support"
3583 +       ---help---
3584 +         Controller Area Network (CAN) is a slow (up to 1Mbit/s) serial
3585 +         communications protocol was developed by Bosch at 1991 mainly for
3586 +         automotive, but now widely used in marine (NMEA2000), industrial and
3587 +         medical applications.
3588 +         More information is contained in the directory <Documentation/can/>.
3589 +
3590 +         If you want CAN support, you should say Y here and also to the
3591 +         specific driver for your controller(s) below.
3592 +
3593 +         This CAN support can also be built as a module.  If so, the module
3594 +         will be called can.ko.
3595 +
3596 +config CAN_RAW
3597 +       tristate "Raw CAN Protocol (raw access with CAN-ID filtering)"
3598 +       depends on CAN
3599 +       default N
3600 +       ---help---
3601 +         The Raw CAN protocol option offers access to the CAN bus via
3602 +         the BSD socket API. You probably want to use the raw socket in
3603 +         most cases where no higher level protocol is being used. The raw 
3604 +         socket has several filter options e.g. ID-Masking / Errorframes.
3605 +         To receive/send raw CAN messages, use AF_CAN with protocol CAN_RAW.
3606 +
3607 +config CAN_RAW_USER
3608 +       bool "Allow non-root users to access Raw CAN Protocol sockets"
3609 +       depends on CAN_RAW
3610 +       default N
3611 +       ---help---
3612 +         Say Y here if you want non-root users to be able to access CAN_RAW-
3613 +         sockets. This may lead to a security hole.
3614 +
3615 +config CAN_BCM
3616 +       tristate "Broadcast Manager CAN Protocol (with content filtering)"
3617 +       depends on CAN
3618 +       default N
3619 +       ---help---
3620 +         The Broadcast Manager offers content filtering, timeout monitoring,
3621 +         sending of RTR-frames and cyclic CAN messages without permanent user
3622 +         interaction. The BCM can be 'programmed' via the BSD socket API and
3623 +         informs you on demand e.g. only on content updates / timeouts.
3624 +         You probably want to use the bcm socket in most cases where cyclic
3625 +         CAN messages are used on the bus (e.g. in automotive environments).
3626 +         To use the Broadcast Manager, use AF_CAN with protocol CAN_BCM.
3627 +
3628 +config CAN_BCM_USER
3629 +       bool "Allow non-root users to access CAN broadcast manager sockets"
3630 +       depends on CAN_BCM
3631 +       default N
3632 +       ---help---
3633 +         Say Y here if you want non-root users to be able to access CAN_BCM-
3634 +         sockets. This may lead to a security hole.
3635 +
3636 +config CAN_DEBUG_CORE
3637 +       bool "CAN Core debugging messages"
3638 +       depends on CAN
3639 +       ---help---
3640 +         Say Y here if you want the CAN core to produce a bunch of debug
3641 +         messages to the system log.  Select this if you are having a
3642 +         problem with CAN support and want to see more of what is going on.
3643 +
3644 +
3645 +source "drivers/net/can/Kconfig"
3646 +
3647 diff -N -u -r a/net/can/Makefile c/net/can/Makefile
3648 --- a/net/can/Makefile  1970-01-01 01:00:00.000000000 +0100
3649 +++ c/net/can/Makefile  2007-03-09 13:47:12.000000000 +0100
3650 @@ -0,0 +1,12 @@
3651 +#
3652 +#  Makefile for the Linux Controller Area Network core.
3653 +#
3654 +
3655 +obj-$(CONFIG_CAN)      += can.o
3656 +can-objs               := af_can.o proc.o
3657 +
3658 +obj-$(CONFIG_CAN_RAW)  += can-raw.o
3659 +can-raw-objs           := raw.o
3660 +
3661 +obj-$(CONFIG_CAN_BCM)  += can-bcm.o
3662 +can-bcm-objs           := bcm.o
3663 diff -N -u -r a/net/can/proc.c c/net/can/proc.c
3664 --- a/net/can/proc.c    1970-01-01 01:00:00.000000000 +0100
3665 +++ c/net/can/proc.c    2007-03-09 13:47:12.000000000 +0100
3666 @@ -0,0 +1,663 @@
3667 +/*
3668 + * proc.c - procfs support for Protocol family CAN core module
3669 + *
3670 + * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
3671 + * All rights reserved.
3672 + *
3673 + * Redistribution and use in source and binary forms, with or without
3674 + * modification, are permitted provided that the following conditions
3675 + * are met:
3676 + * 1. Redistributions of source code must retain the above copyright
3677 + *    notice, this list of conditions, the following disclaimer and
3678 + *    the referenced file 'COPYING'.
3679 + * 2. Redistributions in binary form must reproduce the above copyright
3680 + *    notice, this list of conditions and the following disclaimer in the
3681 + *    documentation and/or other materials provided with the distribution.
3682 + * 3. Neither the name of Volkswagen nor the names of its contributors
3683 + *    may be used to endorse or promote products derived from this software
3684 + *    without specific prior written permission.
3685 + *
3686 + * Alternatively, provided that this notice is retained in full, this
3687 + * software may be distributed under the terms of the GNU General
3688 + * Public License ("GPL") version 2 as distributed in the 'COPYING'
3689 + * file from the main directory of the linux kernel source.
3690 + *
3691 + * The provided data structures and external interfaces from this code
3692 + * are not restricted to be used by modules with a GPL compatible license.
3693 + *
3694 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
3695 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
3696 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
3697 + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
3698 + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
3699 + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
3700 + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
3701 + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
3702 + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3703 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3704 + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
3705 + * DAMAGE.
3706 + *
3707 + * Send feedback to <socketcan-users@lists.berlios.de>
3708 + *
3709 + */
3710 +
3711 +#include <linux/module.h>
3712 +#include <linux/proc_fs.h>
3713 +#include <linux/list.h>
3714 +#include <linux/rcupdate.h>
3715 +
3716 +#include <linux/can/core.h>
3717 +#include <linux/can/version.h>
3718 +
3719 +#include "af_can.h"
3720 +
3721 +RCSID("$Id: proc.c 177 2007-03-08 11:02:43Z hartkopp $");
3722 +
3723 +/* proc filenames */
3724 +
3725 +#define CAN_PROC_VERSION     "version"
3726 +#define CAN_PROC_STATS       "stats"
3727 +#define CAN_PROC_RESET_STATS "reset_stats"
3728 +#define CAN_PROC_RCVLIST_ALL "rcvlist_all"
3729 +#define CAN_PROC_RCVLIST_FIL "rcvlist_fil"
3730 +#define CAN_PROC_RCVLIST_INV "rcvlist_inv"
3731 +#define CAN_PROC_RCVLIST_SFF "rcvlist_sff"
3732 +#define CAN_PROC_RCVLIST_EFF "rcvlist_eff"
3733 +#define CAN_PROC_RCVLIST_ERR "rcvlist_err"
3734 +
3735 +static void can_init_stats(int caller);
3736 +static void can_stat_update(unsigned long data);
3737 +
3738 +static struct proc_dir_entry *can_create_proc_readentry(const char *name,
3739 +       mode_t mode, read_proc_t* read_proc, void *data);
3740 +static void can_remove_proc_readentry(const char *name);
3741 +static unsigned long calc_rate(unsigned long oldjif, unsigned long newjif,
3742 +                              unsigned long count);
3743 +
3744 +static int can_proc_read_version(char *page, char **start, off_t off,
3745 +                                    int count, int *eof, void *data);
3746 +static int can_proc_read_stats(char *page, char **start, off_t off,
3747 +                                    int count, int *eof, void *data);
3748 +static int can_proc_read_reset_stats(char *page, char **start, off_t off,
3749 +                                    int count, int *eof, void *data);
3750 +static int can_proc_read_rcvlist_all(char *page, char **start, off_t off,
3751 +                                    int count, int *eof, void *data);
3752 +static int can_proc_read_rcvlist_fil(char *page, char **start, off_t off,
3753 +                                    int count, int *eof, void *data);
3754 +static int can_proc_read_rcvlist_inv(char *page, char **start, off_t off,
3755 +                                    int count, int *eof, void *data);
3756 +static int can_proc_read_rcvlist_sff(char *page, char **start, off_t off,
3757 +                                    int count, int *eof, void *data);
3758 +static int can_proc_read_rcvlist_eff(char *page, char **start, off_t off,
3759 +                                    int count, int *eof, void *data);
3760 +static int can_proc_read_rcvlist_err(char *page, char **start, off_t off,
3761 +                                    int count, int *eof, void *data);
3762 +
3763 +static struct proc_dir_entry *can_dir         = NULL;
3764 +static struct proc_dir_entry *pde_version     = NULL;
3765 +static struct proc_dir_entry *pde_stats       = NULL;
3766 +static struct proc_dir_entry *pde_reset_stats = NULL;
3767 +static struct proc_dir_entry *pde_rcvlist_all = NULL;
3768 +static struct proc_dir_entry *pde_rcvlist_fil = NULL;
3769 +static struct proc_dir_entry *pde_rcvlist_inv = NULL;
3770 +static struct proc_dir_entry *pde_rcvlist_sff = NULL;
3771 +static struct proc_dir_entry *pde_rcvlist_eff = NULL;
3772 +static struct proc_dir_entry *pde_rcvlist_err = NULL;
3773 +
3774 +struct timer_list stattimer; /* timer for statistics update */
3775 +
3776 +struct s_stats  stats; /* statistics */
3777 +struct s_pstats pstats;
3778 +
3779 +extern struct hlist_head rx_dev_list;    /* rx dispatcher structures */
3780 +extern int stats_timer;                  /* module parameter. default: on */
3781 +
3782 +/**************************************************/
3783 +/* procfs init / remove                           */
3784 +/**************************************************/
3785 +
3786 +void can_init_proc(void)
3787 +{
3788 +
3789 +       /* procfs init */
3790 +
3791 +       /* create /proc/can directory */
3792 +       can_dir = proc_mkdir(CAN_PROC_DIR, NULL);
3793 +
3794 +       if (!can_dir) {
3795 +               printk(KERN_INFO "CAN: failed to create CAN_PROC_DIR. "
3796 +                      "CONFIG_PROC_FS missing?\n");
3797 +               return;
3798 +       }
3799 +
3800 +       can_dir->owner = THIS_MODULE;
3801 +
3802 +       /* own procfs entries from the AF_CAN core */
3803 +       pde_version     = can_create_proc_readentry(
3804 +               CAN_PROC_VERSION, 0644, can_proc_read_version, NULL);
3805 +       pde_stats       = can_create_proc_readentry(
3806 +               CAN_PROC_STATS, 0644, can_proc_read_stats, NULL);
3807 +       pde_reset_stats = can_create_proc_readentry(
3808 +               CAN_PROC_RESET_STATS, 0644, can_proc_read_reset_stats, NULL);
3809 +       pde_rcvlist_all = can_create_proc_readentry(
3810 +               CAN_PROC_RCVLIST_ALL, 0644, can_proc_read_rcvlist_all, NULL);
3811 +       pde_rcvlist_fil = can_create_proc_readentry(
3812 +               CAN_PROC_RCVLIST_FIL, 0644, can_proc_read_rcvlist_fil, NULL);
3813 +       pde_rcvlist_inv = can_create_proc_readentry(
3814 +               CAN_PROC_RCVLIST_INV, 0644, can_proc_read_rcvlist_inv, NULL);
3815 +       pde_rcvlist_sff = can_create_proc_readentry(
3816 +               CAN_PROC_RCVLIST_SFF, 0644, can_proc_read_rcvlist_sff, NULL);
3817 +       pde_rcvlist_eff = can_create_proc_readentry(
3818 +               CAN_PROC_RCVLIST_EFF, 0644, can_proc_read_rcvlist_eff, NULL);
3819 +       pde_rcvlist_err = can_create_proc_readentry(
3820 +               CAN_PROC_RCVLIST_ERR, 0644, can_proc_read_rcvlist_err, NULL);
3821 +
3822 +       if (stats_timer) {
3823 +               /* the statistics are updated every second (timer triggered) */
3824 +               stattimer.function = can_stat_update;
3825 +               stattimer.data = 0;
3826 +               stattimer.expires = jiffies + HZ; /* every second */
3827 +               add_timer(&stattimer); /* start statistics timer */
3828 +       }
3829 +}
3830 +
3831 +void can_remove_proc(void)
3832 +{
3833 +       /* procfs remove */
3834 +       if (pde_version)
3835 +               can_remove_proc_readentry(CAN_PROC_VERSION);
3836 +
3837 +       if (pde_stats)
3838 +               can_remove_proc_readentry(CAN_PROC_STATS);
3839 +
3840 +       if (pde_reset_stats)
3841 +               can_remove_proc_readentry(CAN_PROC_RESET_STATS);
3842 +
3843 +       if (pde_rcvlist_all)
3844 +               can_remove_proc_readentry(CAN_PROC_RCVLIST_ALL);
3845 +
3846 +       if (pde_rcvlist_fil)
3847 +               can_remove_proc_readentry(CAN_PROC_RCVLIST_FIL);
3848 +
3849 +       if (pde_rcvlist_inv)
3850 +               can_remove_proc_readentry(CAN_PROC_RCVLIST_INV);
3851 +
3852 +       if (pde_rcvlist_sff)
3853 +               can_remove_proc_readentry(CAN_PROC_RCVLIST_SFF);
3854 +
3855 +       if (pde_rcvlist_eff)
3856 +               can_remove_proc_readentry(CAN_PROC_RCVLIST_EFF);
3857 +
3858 +       if (pde_rcvlist_err)
3859 +               can_remove_proc_readentry(CAN_PROC_RCVLIST_ERR);
3860 +
3861 +       if (can_dir)
3862 +               remove_proc_entry(CAN_PROC_DIR, NULL);
3863 +}
3864 +
3865 +/**************************************************/
3866 +/* proc read functions                            */
3867 +/**************************************************/
3868 +
3869 +static int can_print_rcvlist(char *page, int len, struct hlist_head *rx_list,
3870 +                            struct net_device *dev)
3871 +{
3872 +       struct receiver *r;
3873 +       struct hlist_node *n;
3874 +
3875 +       rcu_read_lock();
3876 +       hlist_for_each_entry_rcu(r, n, rx_list, list) {
3877 +               char *fmt = r->can_id & CAN_EFF_FLAG ? /* EFF & CAN_ID_ALL */
3878 +                       "   %-5s  %08X  %08x  %08x  %08x  %8ld  %s\n" :
3879 +                       "   %-5s     %03X    %08x  %08x  %08x  %8ld  %s\n";
3880 +
3881 +               len += snprintf(page + len, PAGE_SIZE - len, fmt,
3882 +                               DNAME(dev), r->can_id, r->mask,
3883 +                               (unsigned int)r->func, (unsigned int)r->data,
3884 +                               r->matches, r->ident);
3885 +
3886 +               /* does a typical line fit into the current buffer? */
3887 +               /* 100 Bytes before end of buffer */
3888 +               if (len > PAGE_SIZE - 100) {
3889 +                       /* mark output cut off */
3890 +                       len += snprintf(page + len, PAGE_SIZE - len,
3891 +                                       "   (..)\n");
3892 +                       break;
3893 +               }
3894 +       }
3895 +       rcu_read_unlock();
3896 +
3897 +       return len;
3898 +}
3899 +
3900 +static int can_print_recv_banner(char *page, int len)
3901 +{
3902 +       /*                  can1.  00000000  00000000  00000000
3903 +                          .......          0  tp20 */
3904 +       len += snprintf(page + len, PAGE_SIZE - len,
3905 +                       "  device   can_id   can_mask  function"
3906 +                       "  userdata   matches  ident\n");
3907 +
3908 +       return len;
3909 +}
3910 +
3911 +static int can_proc_read_stats(char *page, char **start, off_t off,
3912 +                              int count, int *eof, void *data)
3913 +{
3914 +       int len = 0;
3915 +
3916 +       len += snprintf(page + len, PAGE_SIZE - len, "\n");
3917 +       len += snprintf(page + len, PAGE_SIZE - len,
3918 +                       " %8ld transmitted frames (TXF)\n", stats.tx_frames);
3919 +       len += snprintf(page + len, PAGE_SIZE - len,
3920 +                       " %8ld received frames (RXF)\n", stats.rx_frames);
3921 +       len += snprintf(page + len, PAGE_SIZE - len,
3922 +                       " %8ld matched frames (RXMF)\n", stats.matches);
3923 +
3924 +       len += snprintf(page + len, PAGE_SIZE - len, "\n");
3925 +
3926 +       len += snprintf(page + len, PAGE_SIZE - len,
3927 +                       " %8ld %% total match ratio (RXMR)\n",
3928 +                       stats.total_rx_match_ratio);
3929 +
3930 +       len += snprintf(page + len, PAGE_SIZE - len,
3931 +                       " %8ld frames/s total tx rate (TXR)\n",
3932 +                       stats.total_tx_rate);
3933 +       len += snprintf(page + len, PAGE_SIZE - len,
3934 +                       " %8ld frames/s total rx rate (RXR)\n",
3935 +                       stats.total_rx_rate);
3936 +
3937 +       len += snprintf(page + len, PAGE_SIZE - len, "\n");
3938 +
3939 +       len += snprintf(page + len, PAGE_SIZE - len,
3940 +                       " %8ld %% current match ratio (CRXMR)\n",
3941 +                       stats.current_rx_match_ratio);
3942 +
3943 +       len += snprintf(page + len, PAGE_SIZE - len,
3944 +                       " %8ld frames/s current tx rate (CTXR)\n",
3945 +                       stats.current_tx_rate);
3946 +       len += snprintf(page + len, PAGE_SIZE - len,
3947 +                       " %8ld frames/s current rx rate (CRXR)\n",
3948 +                       stats.current_rx_rate);
3949 +
3950 +       len += snprintf(page + len, PAGE_SIZE - len, "\n");
3951 +
3952 +       len += snprintf(page + len, PAGE_SIZE - len,
3953 +                       " %8ld %% max match ratio (MRXMR)\n",
3954 +                       stats.max_rx_match_ratio);
3955 +
3956 +       len += snprintf(page + len, PAGE_SIZE - len,
3957 +                       " %8ld frames/s max tx rate (MTXR)\n",
3958 +                       stats.max_tx_rate);
3959 +       len += snprintf(page + len, PAGE_SIZE - len,
3960 +                       " %8ld frames/s max rx rate (MRXR)\n",
3961 +                       stats.max_rx_rate);
3962 +
3963 +       len += snprintf(page + len, PAGE_SIZE - len, "\n");
3964 +
3965 +       len += snprintf(page + len, PAGE_SIZE - len,
3966 +                       " %8ld current receive list entries (CRCV)\n",
3967 +                       pstats.rcv_entries);
3968 +       len += snprintf(page + len, PAGE_SIZE - len,
3969 +                       " %8ld maximum receive list entries (MRCV)\n",
3970 +                       pstats.rcv_entries_max);
3971 +
3972 +       if (pstats.stats_reset)
3973 +               len += snprintf(page + len, PAGE_SIZE - len,
3974 +                               "\n %8ld statistic resets (STR)\n",
3975 +                               pstats.stats_reset);
3976 +
3977 +       len += snprintf(page + len, PAGE_SIZE - len, "\n");
3978 +
3979 +       *eof = 1;
3980 +       return len;
3981 +}
3982 +
3983 +static int can_proc_read_reset_stats(char *page, char **start, off_t off,
3984 +                                    int count, int *eof, void *data)
3985 +{
3986 +       int len = 0;
3987 +
3988 +       can_init_stats(1);
3989 +
3990 +       len += snprintf(page + len, PAGE_SIZE - len,
3991 +                       "CAN statistic reset #%ld done.\n",
3992 +                       pstats.stats_reset);
3993 +
3994 +       *eof = 1;
3995 +       return len;
3996 +}
3997 +
3998 +static int can_proc_read_version(char *page, char **start, off_t off,
3999 +                                int count, int *eof, void *data)
4000 +{
4001 +       int len = 0;
4002 +
4003 +       len += snprintf(page + len, PAGE_SIZE - len,
4004 +                       "%06X [ Volkswagen Group - Low Level CAN Framework"
4005 +                       " (LLCF) v%s ]\n", LLCF_VERSION_CODE, VERSION);
4006 +       *eof = 1;
4007 +       return len;
4008 +}
4009 +
4010 +static int can_proc_read_rcvlist_all(char *page, char **start, off_t off,
4011 +                                    int count, int *eof, void *data)
4012 +{
4013 +       int len = 0;
4014 +       struct dev_rcv_lists *d;
4015 +       struct hlist_node *n;
4016 +
4017 +       /* RX_ALL */
4018 +       len += snprintf(page + len, PAGE_SIZE - len,
4019 +                       "\nreceive list 'rx_all':\n");
4020 +
4021 +       /* find receive list for this device */
4022 +       rcu_read_lock();
4023 +       hlist_for_each_entry_rcu(d, n, &rx_dev_list, list) {
4024 +
4025 +               if (!hlist_empty(&d->rx_all)) {
4026 +                       len = can_print_recv_banner(page, len);
4027 +                       len = can_print_rcvlist(page, len, &d->rx_all, d->dev);
4028 +               } else
4029 +                       len += snprintf(page + len, PAGE_SIZE - len,
4030 +                                       "  (%s: no entry)\n", DNAME(d->dev));
4031 +
4032 +               if (len > PAGE_SIZE - 100)
4033 +                       break; /* exit on end of buffer */
4034 +       }
4035 +       rcu_read_unlock();
4036 +
4037 +       len += snprintf(page + len, PAGE_SIZE - len, "\n");
4038 +
4039 +       *eof = 1;
4040 +       return len;
4041 +}
4042 +
4043 +static int can_proc_read_rcvlist_fil(char *page, char **start, off_t off,
4044 +                                    int count, int *eof, void *data)
4045 +{
4046 +       int len = 0;
4047 +       struct dev_rcv_lists *d;
4048 +       struct hlist_node *n;
4049 +
4050 +       /* RX_FIL */
4051 +       len += snprintf(page + len, PAGE_SIZE - len,
4052 +                       "\nreceive list 'rx_fil':\n");
4053 +
4054 +       /* find receive list for this device */
4055 +       rcu_read_lock();
4056 +       hlist_for_each_entry_rcu(d, n, &rx_dev_list, list) {
4057 +
4058 +               if (!hlist_empty(&d->rx_fil)) {
4059 +                       len = can_print_recv_banner(page, len);
4060 +                       len = can_print_rcvlist(page, len, &d->rx_fil, d->dev);
4061 +               } else
4062 +                       len += snprintf(page + len, PAGE_SIZE - len,
4063 +                                       "  (%s: no entry)\n", DNAME(d->dev));
4064 +
4065 +               if (len > PAGE_SIZE - 100)
4066 +                       break; /* exit on end of buffer */
4067 +       }
4068 +       rcu_read_unlock();
4069 +
4070 +       len += snprintf(page + len, PAGE_SIZE - len, "\n");
4071 +
4072 +       *eof = 1;
4073 +       return len;
4074 +}
4075 +
4076 +static int can_proc_read_rcvlist_inv(char *page, char **start, off_t off,
4077 +                                    int count, int *eof, void *data)
4078 +{
4079 +       int len = 0;
4080 +       struct dev_rcv_lists *d;
4081 +       struct hlist_node *n;
4082 +
4083 +       /* RX_INV */
4084 +       len += snprintf(page + len, PAGE_SIZE - len,
4085 +                       "\nreceive list 'rx_inv':\n");
4086 +
4087 +       /* find receive list for this device */
4088 +       rcu_read_lock();
4089 +       hlist_for_each_entry_rcu(d, n, &rx_dev_list, list) {
4090 +
4091 +               if (!hlist_empty(&d->rx_inv)) {
4092 +                       len = can_print_recv_banner(page, len);
4093 +                       len = can_print_rcvlist(page, len, &d->rx_inv, d->dev);
4094 +               } else
4095 +                       len += snprintf(page + len, PAGE_SIZE - len,
4096 +                                       "  (%s: no entry)\n", DNAME(d->dev));
4097 +
4098 +               if (len > PAGE_SIZE - 100)
4099 +                       break; /* exit on end of buffer */
4100 +       }
4101 +       rcu_read_unlock();
4102 +
4103 +       len += snprintf(page + len, PAGE_SIZE - len, "\n");
4104 +
4105 +       *eof = 1;
4106 +       return len;
4107 +}
4108 +
4109 +static int can_proc_read_rcvlist_sff(char *page, char **start, off_t off,
4110 +                                    int count, int *eof, void *data)
4111 +{
4112 +       int len = 0;
4113 +       struct dev_rcv_lists *d;
4114 +       struct hlist_node *n;
4115 +
4116 +       /* RX_SFF */
4117 +       len += snprintf(page + len, PAGE_SIZE - len,
4118 +                       "\nreceive list 'rx_sff':\n");
4119 +
4120 +       /* find receive list for this device */
4121 +       rcu_read_lock();
4122 +       hlist_for_each_entry_rcu(d, n, &rx_dev_list, list) {
4123 +               int i, all_empty = 1;
4124 +               /* check wether at least one list is non-empty */
4125 +               for (i = 0; i < 0x800; i++)
4126 +                       if (!hlist_empty(&d->rx_sff[i])) {
4127 +                               all_empty = 0;
4128 +                               break;
4129 +                       }
4130 +
4131 +               if (!all_empty) {
4132 +                       len = can_print_recv_banner(page, len);
4133 +                       for (i = 0; i < 0x800; i++) {
4134 +                               if (!hlist_empty(&d->rx_sff[i]) &&
4135 +                                   len < PAGE_SIZE - 100)
4136 +                                       len = can_print_rcvlist(page, len,
4137 +                                                               &d->rx_sff[i],
4138 +                                                               d->dev);
4139 +                       }
4140 +               } else
4141 +                       len += snprintf(page + len, PAGE_SIZE - len,
4142 +                                       "  (%s: no entry)\n", DNAME(d->dev));
4143 +
4144 +               if (len > PAGE_SIZE - 100)
4145 +                       break; /* exit on end of buffer */
4146 +       }
4147 +       rcu_read_unlock();
4148 +
4149 +       len += snprintf(page + len, PAGE_SIZE - len, "\n");
4150 +
4151 +       *eof = 1;
4152 +       return len;
4153 +}
4154 +
4155 +static int can_proc_read_rcvlist_eff(char *page, char **start, off_t off,
4156 +                                    int count, int *eof, void *data)
4157 +{
4158 +       int len = 0;
4159 +       struct dev_rcv_lists *d;
4160 +       struct hlist_node *n;
4161 +
4162 +       /* RX_EFF */
4163 +       len += snprintf(page + len, PAGE_SIZE - len,
4164 +                       "\nreceive list 'rx_eff':\n");
4165 +
4166 +       /* find receive list for this device */
4167 +       rcu_read_lock();
4168 +       hlist_for_each_entry_rcu(d, n, &rx_dev_list, list) {
4169 +
4170 +               if (!hlist_empty(&d->rx_eff)) {
4171 +                       len = can_print_recv_banner(page, len);
4172 +                       len = can_print_rcvlist(page, len, &d->rx_eff, d->dev);
4173 +               } else
4174 +                       len += snprintf(page + len, PAGE_SIZE - len,
4175 +                                       "  (%s: no entry)\n", DNAME(d->dev));
4176 +
4177 +               if (len > PAGE_SIZE - 100)
4178 +                       break; /* exit on end of buffer */
4179 +       }
4180 +       rcu_read_unlock();
4181 +
4182 +       len += snprintf(page + len, PAGE_SIZE - len, "\n");
4183 +
4184 +       *eof = 1;
4185 +       return len;
4186 +}
4187 +
4188 +static int can_proc_read_rcvlist_err(char *page, char **start, off_t off,
4189 +                                    int count, int *eof, void *data)
4190 +{
4191 +       int len = 0;
4192 +       struct dev_rcv_lists *d;
4193 +       struct hlist_node *n;
4194 +
4195 +       /* RX_ERR */
4196 +       len += snprintf(page + len, PAGE_SIZE - len,
4197 +                       "\nreceive list 'rx_err':\n");
4198 +
4199 +       /* find receive list for this device */
4200 +       rcu_read_lock();
4201 +       hlist_for_each_entry_rcu(d, n, &rx_dev_list, list) {
4202 +
4203 +               if (!hlist_empty(&d->rx_err)) {
4204 +                       len = can_print_recv_banner(page, len);
4205 +                       len = can_print_rcvlist(page, len, &d->rx_err, d->dev);
4206 +               } else
4207 +                       len += snprintf(page + len, PAGE_SIZE - len,
4208 +                                       "  (%s: no entry)\n", DNAME(d->dev));
4209 +
4210 +               if (len > PAGE_SIZE - 100)
4211 +                       break; /* exit on end of buffer */
4212 +       }
4213 +       rcu_read_unlock();
4214 +
4215 +       len += snprintf(page + len, PAGE_SIZE - len, "\n");
4216 +
4217 +       *eof = 1;
4218 +       return len;
4219 +}
4220 +
4221 +/**************************************************/
4222 +/* proc utility functions                         */
4223 +/**************************************************/
4224 +
4225 +static struct proc_dir_entry *can_create_proc_readentry(const char *name,
4226 +                                                       mode_t mode,
4227 +                                                       read_proc_t* read_proc,
4228 +                                                       void *data)
4229 +{
4230 +       if (can_dir)
4231 +               return create_proc_read_entry(name, mode, can_dir, read_proc,
4232 +                                             data);
4233 +       else
4234 +               return NULL;
4235 +}
4236 +
4237 +static void can_remove_proc_readentry(const char *name)
4238 +{
4239 +       if (can_dir)
4240 +               remove_proc_entry(name, can_dir);
4241 +}
4242 +
4243 +static unsigned long calc_rate(unsigned long oldjif, unsigned long newjif,
4244 +                              unsigned long count)
4245 +{
4246 +       unsigned long ret = 0;
4247 +
4248 +       if (oldjif == newjif)
4249 +               return 0;
4250 +
4251 +       /* see can_rcv() - this should NEVER happen! */
4252 +       if (count > (ULONG_MAX / HZ)) {
4253 +               printk(KERN_ERR "CAN: calc_rate: count exceeded! %ld\n",
4254 +                      count);
4255 +               return 99999999;
4256 +       }
4257 +
4258 +       ret = (count * HZ) / (newjif - oldjif);
4259 +
4260 +       return ret;
4261 +}
4262 +
4263 +/**************************************************/
4264 +/* af_can statistics stuff                        */
4265 +/**************************************************/
4266 +
4267 +static void can_init_stats(int caller)
4268 +{
4269 +       memset(&stats, 0, sizeof(stats));
4270 +       stats.jiffies_init  = jiffies;
4271 +       pstats.stats_reset++;
4272 +}
4273 +
4274 +static void can_stat_update(unsigned long data)
4275 +{
4276 +       unsigned long j = jiffies; /* snapshot */
4277 +
4278 +       //DBG("CAN: can_stat_update() jiffies = %ld\n", j);
4279 +
4280 +       if (j < stats.jiffies_init) /* jiffies overflow */
4281 +               can_init_stats(2);
4282 +
4283 +       /* stats.rx_frames is the definitively max. statistic value */
4284 +
4285 +       /* prevent overflow in calc_rate() */
4286 +       if (stats.rx_frames > (ULONG_MAX / HZ))
4287 +               can_init_stats(3); /* restart */
4288 +
4289 +       /* matches overflow - very improbable */
4290 +       if (stats.matches > (ULONG_MAX / 100))
4291 +               can_init_stats(4);
4292 +
4293 +       /* calc total values */
4294 +       if (stats.rx_frames)
4295 +               stats.total_rx_match_ratio = (stats.matches * 100) / 
4296 +                                               stats.rx_frames;
4297 +
4298 +       stats.total_tx_rate = calc_rate(stats.jiffies_init, j,
4299 +                                       stats.tx_frames);
4300 +       stats.total_rx_rate = calc_rate(stats.jiffies_init, j,
4301 +                                       stats.rx_frames);
4302 +
4303 +       /* calc current values */
4304 +       if (stats.rx_frames_delta)
4305 +               stats.current_rx_match_ratio =
4306 +                       (stats.matches_delta * 100) / stats.rx_frames_delta;
4307 +
4308 +       stats.current_tx_rate = calc_rate(0, HZ, stats.tx_frames_delta);
4309 +       stats.current_rx_rate = calc_rate(0, HZ, stats.rx_frames_delta);
4310 +
4311 +       /* check / update maximum values */
4312 +       if (stats.max_tx_rate < stats.current_tx_rate)
4313 +               stats.max_tx_rate = stats.current_tx_rate;
4314 +
4315 +       if (stats.max_rx_rate < stats.current_rx_rate)
4316 +               stats.max_rx_rate = stats.current_rx_rate;
4317 +
4318 +       if (stats.max_rx_match_ratio < stats.current_rx_match_ratio)
4319 +               stats.max_rx_match_ratio = stats.current_rx_match_ratio;
4320 +
4321 +       /* clear values for 'current rate' calculation */
4322 +       stats.tx_frames_delta = 0;
4323 +       stats.rx_frames_delta = 0;
4324 +       stats.matches_delta   = 0;
4325 +
4326 +       /* restart timer */
4327 +       stattimer.expires = jiffies + HZ; /* every second */
4328 +       add_timer(&stattimer);
4329 +}
4330 diff -N -u -r a/net/can/raw.c c/net/can/raw.c
4331 --- a/net/can/raw.c     1970-01-01 01:00:00.000000000 +0100
4332 +++ c/net/can/raw.c     2007-03-09 13:47:12.000000000 +0100
4333 @@ -0,0 +1,738 @@
4334 +/*
4335 + * raw.c - Raw sockets for protocol family CAN
4336 + *
4337 + * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
4338 + * All rights reserved.
4339 + *
4340 + * Redistribution and use in source and binary forms, with or without
4341 + * modification, are permitted provided that the following conditions
4342 + * are met:
4343 + * 1. Redistributions of source code must retain the above copyright
4344 + *    notice, this list of conditions, the following disclaimer and
4345 + *    the referenced file 'COPYING'.
4346 + * 2. Redistributions in binary form must reproduce the above copyright
4347 + *    notice, this list of conditions and the following disclaimer in the
4348 + *    documentation and/or other materials provided with the distribution.
4349 + * 3. Neither the name of Volkswagen nor the names of its contributors
4350 + *    may be used to endorse or promote products derived from this software
4351 + *    without specific prior written permission.
4352 + *
4353 + * Alternatively, provided that this notice is retained in full, this
4354 + * software may be distributed under the terms of the GNU General
4355 + * Public License ("GPL") version 2 as distributed in the 'COPYING'
4356 + * file from the main directory of the linux kernel source.
4357 + *
4358 + * The provided data structures and external interfaces from this code
4359 + * are not restricted to be used by modules with a GPL compatible license.
4360 + *
4361 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4362 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
4363 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
4364 + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
4365 + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
4366 + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
4367 + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
4368 + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
4369 + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
4370 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
4371 + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
4372 + * DAMAGE.
4373 + *
4374 + * Send feedback to <socketcan-users@lists.berlios.de>
4375 + *
4376 + */
4377 +
4378 +#include <linux/autoconf.h>
4379 +#include <linux/module.h>
4380 +#include <linux/version.h>
4381 +#include <linux/init.h>
4382 +#include <linux/net.h>
4383 +#include <linux/netdevice.h>
4384 +#include <linux/uio.h>
4385 +#include <linux/poll.h>
4386 +#include <net/sock.h>
4387 +
4388 +#include <linux/can.h>
4389 +#include <linux/can/error.h>
4390 +#include <linux/can/core.h>
4391 +#include <linux/can/raw.h>
4392 +#include <linux/can/version.h>
4393 +
4394 +RCSID("$Id: raw.c 177 2007-03-08 11:02:43Z hartkopp $");
4395 +
4396 +#define IDENT "raw"
4397 +static __initdata const char banner[] = KERN_INFO "CAN: raw socket protocol"
4398 +                                       " " VERSION "\n"; 
4399 +
4400 +MODULE_DESCRIPTION("PF_CAN raw sockets");
4401 +MODULE_LICENSE("Dual BSD/GPL");
4402 +MODULE_AUTHOR("Urs Thuermann <urs.thuermann@volkswagen.de>");
4403 +
4404 +#ifdef CONFIG_CAN_DEBUG_CORE
4405 +static int debug = 0;
4406 +module_param(debug, int, S_IRUGO);
4407 +#define DBG(args...)       (debug & 1 ? \
4408 +                              (printk(KERN_DEBUG "RAW %s: ", __func__), \
4409 +                               printk(args)) : 0)
4410 +#define DBG_SKB(skb)       (debug & 4 ? can_debug_skb(skb) : 0)
4411 +#else
4412 +#define DBG(args...)
4413 +#define DBG_SKB(skb)
4414 +#endif
4415 +
4416 +static int raw_init(struct sock *sk);
4417 +static int raw_release(struct socket *sock);
4418 +static int raw_bind   (struct socket *sock, struct sockaddr *uaddr, int len);
4419 +static int raw_getname(struct socket *sock, struct sockaddr *uaddr,
4420 +                      int *len, int peer);
4421 +static unsigned int raw_poll(struct file *file, struct socket *sock,
4422 +                            poll_table *wait);
4423 +static int raw_setsockopt(struct socket *sock, int level, int optname,
4424 +                         char __user *optval, int optlen);
4425 +static int raw_getsockopt(struct socket *sock, int level, int optname,
4426 +                         char __user *optval, int __user *optlen);
4427 +static int raw_sendmsg(struct kiocb *iocb, struct socket *sock,
4428 +                      struct msghdr *msg, size_t size);
4429 +static int raw_recvmsg(struct kiocb *iocb, struct socket *sock,
4430 +                      struct msghdr *msg, size_t size, int flags);
4431 +static void raw_rcv(struct sk_buff *skb, void *data);
4432 +static void raw_notifier(unsigned long msg, void *data);
4433 +
4434 +static void raw_add_filters(struct net_device *dev, struct sock *sk);
4435 +static void raw_remove_filters(struct net_device *dev, struct sock *sk);
4436 +
4437 +
4438 +static struct proto_ops raw_ops = {
4439 +       .family        = PF_CAN,
4440 +       .release       = raw_release,
4441 +       .bind          = raw_bind,
4442 +       .connect       = sock_no_connect,
4443 +       .socketpair    = sock_no_socketpair,
4444 +       .accept        = sock_no_accept,
4445 +       .getname       = raw_getname,
4446 +       .poll          = raw_poll,
4447 +       .ioctl         = NULL,          /* use can_ioctl() from af_can.c */
4448 +       .listen        = sock_no_listen,
4449 +       .shutdown      = sock_no_shutdown,
4450 +       .setsockopt    = raw_setsockopt,
4451 +       .getsockopt    = raw_getsockopt,
4452 +       .sendmsg       = raw_sendmsg,
4453 +       .recvmsg       = raw_recvmsg,
4454 +       .mmap          = sock_no_mmap,
4455 +       .sendpage      = sock_no_sendpage,
4456 +};
4457 +
4458 +
4459 +/* A raw socket has a list of can_filters attached to it, each receiving
4460 +   the CAN frames matching that filter.  If the filter list is empty,
4461 +   no CAN frames will be received by the socket.  The default after
4462 +   opening the socket, is to have one filter which receives all frames.
4463 +   The filter list is allocated dynamically with the exception of the
4464 +   list containing only one item.  This common case is optimized by
4465 +   storing the single filter in dfilter, to avoid using dynamic memory.
4466 +*/
4467 +
4468 +struct raw_opt {
4469 +       int bound;
4470 +       int ifindex;
4471 +       int loopback;
4472 +       int recv_own_msgs;
4473 +       int count;                 /* number of active filters */
4474 +       struct can_filter dfilter; /* default/single filter */
4475 +       struct can_filter *filter; /* pointer to filter(s) */
4476 +       can_err_mask_t err_mask;
4477 +};
4478 +
4479 +#ifdef CONFIG_CAN_RAW_USER
4480 +#define RAW_CAP (-1)
4481 +#else
4482 +#define RAW_CAP CAP_NET_RAW
4483 +#endif
4484 +
4485 +#undef CAN_RAW_SUPPORT_REBIND /* use bind on already bound socket */
4486 +
4487 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,13)
4488 +struct raw_sock {
4489 +       struct sock    sk;
4490 +       struct raw_opt opt;
4491 +};
4492 +
4493 +#define raw_sk(sk) (&((struct raw_sock *)(sk))->opt)
4494 +
4495 +static struct proto raw_proto = {
4496 +       .name       = "CAN_RAW",
4497 +       .owner      = THIS_MODULE,
4498 +       .obj_size   = sizeof(struct raw_sock),
4499 +       .init       = raw_init,
4500 +};
4501 +
4502 +static struct can_proto raw_can_proto = {
4503 +       .type       = SOCK_RAW,
4504 +       .protocol   = CAN_RAW,
4505 +       .capability = RAW_CAP,
4506 +       .ops        = &raw_ops,
4507 +       .prot       = &raw_proto,
4508 +};
4509 +#else
4510 +#define raw_sk(sk) ((struct raw_opt *)(sk)->sk_protinfo)
4511 +
4512 +static struct can_proto raw_can_proto = {
4513 +       .type       = SOCK_RAW,
4514 +       .protocol   = CAN_RAW,
4515 +       .capability = RAW_CAP,
4516 +       .ops        = &raw_ops,
4517 +       .owner      = THIS_MODULE,
4518 +       .obj_size   = sizeof(struct raw_opt),
4519 +       .init       = raw_init,
4520 +};
4521 +#endif
4522 +
4523 +#define MASK_ALL 0
4524 +
4525 +static __init int raw_module_init(void)
4526 +{
4527 +       printk(banner);
4528 +
4529 +       can_proto_register(&raw_can_proto);
4530 +       return 0;
4531 +}
4532 +
4533 +static __exit void raw_module_exit(void)
4534 +{
4535 +       can_proto_unregister(&raw_can_proto);
4536 +}
4537 +
4538 +static int raw_init(struct sock *sk)
4539 +{
4540 +       struct raw_opt *ro = raw_sk(sk);
4541 +
4542 +       ro->bound            = 0;
4543 +
4544 +       /* set default filter to single entry dfilter */
4545 +       ro->dfilter.can_id   = 0;
4546 +       ro->dfilter.can_mask = MASK_ALL;
4547 +       ro->filter           = &ro->dfilter;
4548 +       ro->count            = 1;
4549 +
4550 +       /* set default loopback behaviour */
4551 +       ro->loopback         = 1;
4552 +       ro->recv_own_msgs    = 0;
4553 +
4554 +       return 0;
4555 +}
4556 +
4557 +static int raw_release(struct socket *sock)
4558 +{
4559 +       struct sock *sk = sock->sk;
4560 +       struct raw_opt *ro = raw_sk(sk);
4561 +       struct net_device *dev = NULL;
4562 +
4563 +       DBG("socket %p, sk %p, refcnt %d\n", sock, sk,
4564 +           atomic_read(&sk->sk_refcnt));
4565 +
4566 +       if (ro->bound && ro->ifindex)
4567 +               dev = dev_get_by_index(ro->ifindex);
4568 +
4569 +       /* remove current filters & unregister */
4570 +       if (ro->bound)
4571 +               raw_remove_filters(dev, sk);
4572 +       if (ro->count > 1)
4573 +               kfree(ro->filter);
4574 +
4575 +       /* remove current error mask */
4576 +       if (ro->err_mask && ro->bound)
4577 +               can_rx_unregister(dev, 0, ro->err_mask | CAN_ERR_FLAG,
4578 +                                 raw_rcv, sk);
4579 +
4580 +       if (dev) {
4581 +               can_dev_unregister(dev, raw_notifier, sk);
4582 +               dev_put(dev);
4583 +       }
4584 +
4585 +       sock_put(sk);
4586 +
4587 +       return 0;
4588 +}
4589 +
4590 +static int raw_bind(struct socket *sock, struct sockaddr *uaddr, int len)
4591 +{
4592 +       struct sockaddr_can *addr = (struct sockaddr_can *)uaddr;
4593 +       struct sock *sk = sock->sk;
4594 +       struct raw_opt *ro = raw_sk(sk);
4595 +       struct net_device *dev;
4596 +
4597 +       DBG("socket %p to device %d\n", sock, addr->can_ifindex);
4598 +
4599 +       if (len < sizeof(*addr))
4600 +               return -EINVAL;
4601 +
4602 +       if (ro->bound) {
4603 +#ifdef CAN_RAW_SUPPORT_REBIND
4604 +               /* remove current bindings / notifier */
4605 +               if (ro->ifindex) {
4606 +                       dev = dev_get_by_index(ro->ifindex);
4607 +                       if (!dev) {
4608 +                               DBG("could not find device %d\n",
4609 +                                   addr->can_ifindex);
4610 +                               return -ENODEV;
4611 +                       }
4612 +                       if (!(dev->flags & IFF_UP)) {
4613 +                               sk->sk_err = ENETDOWN;
4614 +                               if (!sock_flag(sk, SOCK_DEAD))
4615 +                                       sk->sk_error_report(sk);
4616 +                               goto out;
4617 +                       }
4618 +                       can_dev_unregister(dev, raw_notifier, sk);
4619 +               } else
4620 +                       dev = NULL;
4621 +
4622 +               /* unregister current filters for this device */
4623 +               raw_remove_filters(dev, sk);
4624 +
4625 +               if (dev)
4626 +                       dev_put(dev);
4627 +
4628 +               ro->bound = 0;
4629 +#else
4630 +               return -EINVAL;
4631 +#endif
4632 +       }
4633 +
4634 +       if (addr->can_ifindex) {
4635 +               dev = dev_get_by_index(addr->can_ifindex);
4636 +               if (!dev) {
4637 +                       DBG("could not find device %d\n", addr->can_ifindex);
4638 +                       return -ENODEV;
4639 +               }
4640 +               if (!(dev->flags & IFF_UP)) {
4641 +                       sk->sk_err = ENETDOWN;
4642 +                       if (!sock_flag(sk, SOCK_DEAD))
4643 +                               sk->sk_error_report(sk);
4644 +                       goto out;
4645 +               }
4646 +               can_dev_register(dev, raw_notifier, sk);
4647 +       } else
4648 +               dev = NULL;
4649 +
4650 +       ro->ifindex = addr->can_ifindex;
4651 +
4652 +       raw_add_filters(dev, sk); /* filters set by default/setsockopt */
4653 +
4654 +       if (ro->err_mask) /* error frame filter set by setsockopt */
4655 +               can_rx_register(dev, 0, ro->err_mask | CAN_ERR_FLAG,
4656 +                               raw_rcv, sk, IDENT);
4657 +
4658 +       ro->bound = 1;
4659 +
4660 + out:
4661 +       if (dev)
4662 +               dev_put(dev);
4663 +
4664 +       return 0;
4665 +}
4666 +
4667 +static int raw_getname(struct socket *sock, struct sockaddr *uaddr,
4668 +                      int *len, int peer)
4669 +{
4670 +       struct sockaddr_can *addr = (struct sockaddr_can *)uaddr;
4671 +       struct sock *sk = sock->sk;
4672 +       struct raw_opt *ro = raw_sk(sk);
4673 +
4674 +       if (peer)
4675 +               return -EOPNOTSUPP;
4676 +
4677 +       addr->can_family  = AF_CAN;
4678 +       addr->can_ifindex = ro->ifindex;
4679 +       *len = sizeof(*addr);
4680 +
4681 +       return 0;
4682 +}
4683 +
4684 +static unsigned int raw_poll(struct file *file, struct socket *sock,
4685 +                            poll_table *wait)
4686 +{
4687 +       unsigned int mask = 0;
4688 +
4689 +       DBG("socket %p\n", sock);
4690 +
4691 +       mask = datagram_poll(file, sock, wait);
4692 +       return mask;
4693 +}
4694 +
4695 +static int raw_setsockopt(struct socket *sock, int level, int optname,
4696 +                         char __user *optval, int optlen)
4697 +{
4698 +       struct sock *sk = sock->sk;
4699 +       struct raw_opt *ro = raw_sk(sk);
4700 +       struct can_filter *filter = NULL;  /* dyn. alloc'ed filters */
4701 +       struct can_filter sfilter;         /* single filter */
4702 +       struct net_device *dev = NULL;
4703 +       can_err_mask_t err_mask = 0;
4704 +       int count = 0;
4705 +       int err;
4706 +
4707 +       if (level != SOL_CAN_RAW)
4708 +               return -EINVAL;
4709 +
4710 +       switch (optname) {
4711 +       case CAN_RAW_FILTER:
4712 +               if (optlen % sizeof(struct can_filter) != 0)
4713 +                       return -EINVAL;
4714 +
4715 +               count = optlen / sizeof(struct can_filter);
4716 +
4717 +               if (count > 1) { /* does not fit into dfilter */
4718 +                       if (!(filter = kmalloc(optlen, GFP_KERNEL)))
4719 +                               return -ENOMEM;
4720 +                       if ((err = copy_from_user(filter, optval, optlen))) {
4721 +                               kfree(filter);
4722 +                               return err;
4723 +                       }
4724 +               } else if (count == 1) {
4725 +                       if ((err = copy_from_user(&sfilter, optval, optlen)))
4726 +                               return err;
4727 +               }
4728 +
4729 +               if (ro->bound && ro->ifindex)
4730 +                       dev = dev_get_by_index(ro->ifindex);
4731 +
4732 +               /* remove current filters & unregister */
4733 +               if (ro->bound)
4734 +                       raw_remove_filters(dev, sk);
4735 +               if (ro->count > 1)
4736 +                       kfree(ro->filter);
4737 +
4738 +               if (count == 1) { /* copy data for single filter */
4739 +                       ro->dfilter = sfilter;
4740 +                       filter = &ro->dfilter;
4741 +               }
4742 +
4743 +               /* add new filters & register */
4744 +               ro->filter = filter;
4745 +               ro->count  = count;
4746 +               if (ro->bound)
4747 +                       raw_add_filters(dev, sk);
4748 +
4749 +               if (dev)
4750 +                       dev_put(dev);
4751 +
4752 +               break;
4753 +
4754 +       case CAN_RAW_ERR_FILTER:
4755 +               if (optlen != sizeof(err_mask))
4756 +                       return -EINVAL;
4757 +               if ((err = copy_from_user(&err_mask, optval, optlen)))
4758 +                       return err;
4759 +
4760 +               err_mask &= CAN_ERR_MASK;
4761 +
4762 +               if (ro->bound && ro->ifindex)
4763 +                       dev = dev_get_by_index(ro->ifindex);
4764 +
4765 +               /* remove current error mask */
4766 +               if (ro->err_mask && ro->bound)
4767 +                       can_rx_unregister(dev, 0, ro->err_mask | CAN_ERR_FLAG,
4768 +                                         raw_rcv, sk);
4769 +
4770 +               /* add new error mask */
4771 +               ro->err_mask = err_mask;
4772 +               if (ro->err_mask && ro->bound)
4773 +                       can_rx_register(dev, 0, ro->err_mask | CAN_ERR_FLAG,
4774 +                                       raw_rcv, sk, IDENT);
4775 +
4776 +               if (dev)
4777 +                       dev_put(dev);
4778 +
4779 +               break;
4780 +
4781 +       case CAN_RAW_LOOPBACK:
4782 +               if (optlen != sizeof(ro->loopback))
4783 +                       return -EINVAL;
4784 +               if ((err = copy_from_user(&ro->loopback, optval, optlen)))
4785 +                       return err;
4786 +               break;
4787 +
4788 +       case CAN_RAW_RECV_OWN_MSGS:
4789 +               if (optlen != sizeof(ro->recv_own_msgs))
4790 +                       return -EINVAL;
4791 +               if ((err = copy_from_user(&ro->recv_own_msgs, optval, optlen)))
4792 +                       return err;
4793 +               break;
4794 +
4795 +       default:
4796 +               return -ENOPROTOOPT;
4797 +       }
4798 +       return 0;
4799 +}
4800 +
4801 +static int raw_getsockopt(struct socket *sock, int level, int optname,
4802 +                         char __user *optval, int __user *optlen)
4803 +{
4804 +       struct sock *sk = sock->sk;
4805 +       struct raw_opt *ro = raw_sk(sk);
4806 +       struct can_filter *filter = ro->filter;
4807 +       int count = ro->count;
4808 +       int len;
4809 +
4810 +       if (level != SOL_CAN_RAW)
4811 +               return -EINVAL;
4812 +
4813 +       switch (optname) {
4814 +       case CAN_RAW_FILTER:
4815 +               if (get_user(len, optlen))
4816 +                       return -EFAULT;
4817 +
4818 +               if (count && filter) {
4819 +                       int filter_size = count * sizeof(struct can_filter);
4820 +                       if (len < filter_size)
4821 +                               return -EINVAL;
4822 +                       if (len > filter_size)
4823 +                               len = filter_size;
4824 +                       if (copy_to_user(optval, filter, len))
4825 +                               return -EFAULT;
4826 +               } else
4827 +                       len = 0;
4828 +
4829 +               if (put_user(len, optlen))
4830 +                       return -EFAULT;
4831 +
4832 +               break;
4833 +
4834 +       case CAN_RAW_ERR_FILTER:
4835 +               if (get_user(len, optlen))
4836 +                       return -EFAULT;
4837 +
4838 +               if (len < sizeof(can_err_mask_t))
4839 +                       return -EINVAL;
4840 +
4841 +               if (len > sizeof(can_err_mask_t))
4842 +                       len = sizeof(can_err_mask_t);
4843 +
4844 +               if (copy_to_user(optval, &ro->err_mask, len))
4845 +                       return -EFAULT;
4846 +
4847 +               if (put_user(len, optlen))
4848 +                       return -EFAULT;
4849 +
4850 +               break;
4851 +
4852 +       case CAN_RAW_LOOPBACK:
4853 +               if (get_user(len, optlen))
4854 +                       return -EFAULT;
4855 +
4856 +               if (len < sizeof(int))
4857 +                       return -EINVAL;
4858 +
4859 +               if (len > sizeof(int))
4860 +                       len = sizeof(int);
4861 +
4862 +               if (copy_to_user(optval, &ro->loopback, len))
4863 +                       return -EFAULT;
4864 +
4865 +               if (put_user(len, optlen))
4866 +                       return -EFAULT;
4867 +
4868 +               break;
4869 +
4870 +       case CAN_RAW_RECV_OWN_MSGS:
4871 +               if (get_user(len, optlen))
4872 +                       return -EFAULT;
4873 +
4874 +               if (len < sizeof(int))
4875 +                       return -EINVAL;
4876 +
4877 +               if (len > sizeof(int))
4878 +                       len = sizeof(int);
4879 +
4880 +               if (copy_to_user(optval, &ro->recv_own_msgs, len))
4881 +                       return -EFAULT;
4882 +
4883 +               if (put_user(len, optlen))
4884 +                       return -EFAULT;
4885 +
4886 +               break;
4887 +
4888 +       default:
4889 +               return -ENOPROTOOPT;
4890 +       }
4891 +       return 0;
4892 +}
4893 +
4894 +static void raw_add_filters(struct net_device *dev, struct sock *sk)
4895 +{
4896 +       struct raw_opt *ro = raw_sk(sk);
4897 +       struct can_filter *filter = ro->filter;
4898 +       int i;
4899 +
4900 +       for (i = 0; i < ro->count; i++) {
4901 +               can_rx_register(dev, filter[i].can_id, filter[i].can_mask,
4902 +                               raw_rcv, sk, IDENT);
4903 +               DBG("filter can_id %08X, can_mask %08X%s, sk %p\n",
4904 +                   filter[i].can_id, filter[i].can_mask,
4905 +                   filter[i].can_id & CAN_INV_FILTER ? " (inv)" : "", sk);
4906 +       }
4907 +}
4908 +
4909 +static void raw_remove_filters(struct net_device *dev, struct sock *sk)
4910 +{
4911 +       struct raw_opt *ro = raw_sk(sk);
4912 +       struct can_filter *filter = ro->filter;
4913 +       int i;
4914 +
4915 +       for (i = 0; i < ro->count; i++) {
4916 +               can_rx_unregister(dev, filter[i].can_id, filter[i].can_mask,
4917 +                                 raw_rcv, sk);
4918 +               DBG("filter can_id %08X, can_mask %08X%s, sk %p\n",
4919 +                   filter[i].can_id, filter[i].can_mask,
4920 +                   filter[i].can_id & CAN_INV_FILTER ? " (inv)" : "", sk);
4921 +       }
4922 +}
4923 +
4924 +static int raw_sendmsg(struct kiocb *iocb, struct socket *sock,
4925 +                      struct msghdr *msg, size_t size)
4926 +{
4927 +       struct sock *sk = sock->sk;
4928 +       struct raw_opt *ro = raw_sk(sk);
4929 +       struct sk_buff *skb;
4930 +       struct net_device *dev;
4931 +       int ifindex;
4932 +       int err;
4933 +
4934 +       DBG("socket %p, sk %p\n", sock, sk);
4935 +
4936 +       if (msg->msg_name) {
4937 +               struct sockaddr_can *addr =
4938 +                       (struct sockaddr_can *)msg->msg_name;
4939 +               if (addr->can_family != AF_CAN)
4940 +                       return -EINVAL;
4941 +               ifindex = addr->can_ifindex;
4942 +       } else
4943 +               ifindex = ro->ifindex;
4944 +
4945 +       if (!(dev = dev_get_by_index(ifindex))) {
4946 +               DBG("device %d not found\n", ifindex);
4947 +               return -ENXIO;
4948 +       }
4949 +
4950 +       if (!(skb = alloc_skb(size, GFP_KERNEL))) {
4951 +               dev_put(dev);
4952 +               return -ENOMEM;
4953 +       }
4954 +
4955 +       if ((err = memcpy_fromiovec(skb_put(skb, size),
4956 +                                   msg->msg_iov, size)) < 0) {
4957 +               kfree_skb(skb);
4958 +               dev_put(dev);
4959 +               return err;
4960 +       }
4961 +       skb->dev = dev;
4962 +       skb->sk  = sk;
4963 +
4964 +       DBG("sending skbuff to interface %d\n", ifindex);
4965 +       DBG_SKB(skb);
4966 +
4967 +       err = can_send(skb, ro->loopback);
4968 +
4969 +       dev_put(dev);
4970 +
4971 +       if (err)
4972 +               return err;
4973 +
4974 +       return size;
4975 +}
4976 +
4977 +static int raw_recvmsg(struct kiocb *iocb, struct socket *sock,
4978 +                      struct msghdr *msg, size_t size, int flags)
4979 +{
4980 +       struct sock *sk = sock->sk;
4981 +       struct sk_buff *skb;
4982 +       int error = 0;
4983 +       int noblock;
4984 +
4985 +       DBG("socket %p, sk %p\n", sock, sk);
4986 +
4987 +       noblock =  flags & MSG_DONTWAIT;
4988 +       flags   &= ~MSG_DONTWAIT;
4989 +
4990 +       if (!(skb = skb_recv_datagram(sk, flags, noblock, &error)))
4991 +               return error;
4992 +
4993 +       DBG("delivering skbuff %p\n", skb);
4994 +       DBG_SKB(skb);
4995 +
4996 +       if (size < skb->len)
4997 +               msg->msg_flags |= MSG_TRUNC;
4998 +       else
4999 +               size = skb->len;
5000 +
5001 +       if ((error = memcpy_toiovec(msg->msg_iov, skb->data, size)) < 0) {
5002 +               skb_free_datagram(sk, skb);
5003 +               return error;
5004 +       }
5005 +
5006 +       sock_recv_timestamp(msg, sk, skb);
5007 +
5008 +       if (msg->msg_name) {
5009 +               msg->msg_namelen = sizeof(struct sockaddr_can);
5010 +               memcpy(msg->msg_name, skb->cb, msg->msg_namelen);
5011 +       }
5012 +
5013 +       DBG("freeing sock %p, skbuff %p\n", sk, skb);
5014 +       skb_free_datagram(sk, skb);
5015 +
5016 +       return size;
5017 +}
5018 +
5019 +static void raw_rcv(struct sk_buff *skb, void *data)
5020 +{
5021 +       struct sock *sk = (struct sock*)data;
5022 +       struct raw_opt *ro = raw_sk(sk);
5023 +       struct sockaddr_can *addr;
5024 +       int error;
5025 +
5026 +       DBG("received skbuff %p, sk %p\n", skb, sk);
5027 +       DBG_SKB(skb);
5028 +
5029 +       if (!ro->recv_own_msgs) {
5030 +               if (*(struct sock **)skb->cb == sk) { /* tx sock reference */
5031 +                       DBG("trashed own tx msg\n");
5032 +                       kfree_skb(skb);
5033 +                       return;
5034 +               }
5035 +       }
5036 +
5037 +       addr = (struct sockaddr_can *)skb->cb;
5038 +       memset(addr, 0, sizeof(*addr));
5039 +       addr->can_family  = AF_CAN;
5040 +       addr->can_ifindex = skb->dev->ifindex;
5041 +
5042 +       if ((error = sock_queue_rcv_skb(sk, skb)) < 0) {
5043 +               DBG("sock_queue_rcv_skb failed: %d\n", error);
5044 +               DBG("freeing skbuff %p\n", skb);
5045 +               kfree_skb(skb);
5046 +       }
5047 +}
5048 +
5049 +static void raw_notifier(unsigned long msg, void *data)
5050 +{
5051 +       struct sock *sk = (struct sock *)data;
5052 +       struct raw_opt *ro = raw_sk(sk);
5053 +
5054 +       DBG("called for sock %p\n", sk);
5055 +
5056 +       switch (msg) {
5057 +       case NETDEV_UNREGISTER:
5058 +               ro->ifindex = 0;
5059 +               ro->bound   = 0;
5060 +               /* fallthrough */
5061 +       case NETDEV_DOWN:
5062 +               sk->sk_err = ENETDOWN;
5063 +               if (!sock_flag(sk, SOCK_DEAD))
5064 +                       sk->sk_error_report(sk);
5065 +               break;
5066 +       }
5067 +}
5068 +
5069 +
5070 +module_init(raw_module_init);
5071 +module_exit(raw_module_exit);
5072 diff -N -u -r a/net/ipv6/addrconf.c c/net/ipv6/addrconf.c
5073 --- a/net/ipv6/addrconf.c       2007-03-09 09:52:20.000000000 +0100
5074 +++ c/net/ipv6/addrconf.c       2007-03-09 13:39:10.000000000 +0100
5075 @@ -2178,6 +2178,10 @@
5076         struct inet6_dev *idev = __in6_dev_get(dev);
5077         int run_pending = 0;
5078  
5079 +       /* more non ipv6 compatible dev types to skip here? */
5080 +       if (dev->type == ARPHRD_CAN)
5081 +               return NOTIFY_OK;
5082 +
5083         switch(event) {
5084         case NETDEV_REGISTER:
5085                 if (!idev) {
5086 diff -N -u -r a/net/Kconfig c/net/Kconfig
5087 --- a/net/Kconfig       2007-03-09 09:52:18.000000000 +0100
5088 +++ c/net/Kconfig       2007-03-09 13:39:10.000000000 +0100
5089 @@ -217,6 +217,7 @@
5090  endmenu
5091  
5092  source "net/ax25/Kconfig"
5093 +source "net/can/Kconfig"
5094  source "net/irda/Kconfig"
5095  source "net/bluetooth/Kconfig"
5096  source "net/ieee80211/Kconfig"
5097 diff -N -u -r a/net/Makefile c/net/Makefile
5098 --- a/net/Makefile      2007-03-09 09:52:18.000000000 +0100
5099 +++ c/net/Makefile      2007-03-09 13:39:10.000000000 +0100
5100 @@ -34,6 +34,7 @@
5101  obj-$(CONFIG_NETROM)           += netrom/
5102  obj-$(CONFIG_ROSE)             += rose/
5103  obj-$(CONFIG_AX25)             += ax25/
5104 +obj-$(CONFIG_CAN)              += can/
5105  obj-$(CONFIG_IRDA)             += irda/
5106  obj-$(CONFIG_BT)               += bluetooth/
5107  obj-$(CONFIG_SUNRPC)           += sunrpc/