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
9 +E: oliver.hartkopp@volkswagen.de
10 +W: http://www.volkswagen.de
11 +D: Controller Area Network (network layer core)
18 D: Selection mechanism
19 @@ -3277,6 +3285,14 @@
20 S: F-35042 Rennes Cedex
24 +E: urs.thuermann@volkswagen.de
25 +W: http://www.volkswagen.de
26 +D: Controller Area Network (network layer core)
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
38 +menu "CAN Device Drivers"
42 + tristate "Virtual Local CAN Interface (vcan)"
46 + Similar to the network loopback devices, vcan offers a
47 + virtual local CAN interface.
49 + This driver can also be built as a module. If so, the module
50 + will be called vcan.
52 +config CAN_DEBUG_DEVICES
53 + bool "CAN devices debugging messages"
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
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
69 +# Makefile for the Linux Controller Area Network drivers.
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
78 + * vcan.c - Virtual CAN interface
80 + * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
81 + * All rights reserved.
83 + * Redistribution and use in source and binary forms, with or without
84 + * modification, are permitted provided that the following conditions
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.
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.
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.
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
117 + * Send feedback to <socketcan-users@lists.berlios.de>
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>
128 +#include <linux/can.h>
129 +#include <linux/can/version.h>
131 +RCSID("$Id: vcan.c 168 2007-03-05 13:33:59Z hartkopp $");
133 +static __initdata const char banner[] = KERN_INFO "CAN: virtual CAN "
134 + "interface " VERSION "\n";
136 +MODULE_DESCRIPTION("virtual CAN interface");
137 +MODULE_LICENSE("Dual BSD/GPL");
138 +MODULE_AUTHOR("Urs Thuermann <urs.thuermann@volkswagen.de>");
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__), \
146 +#define DBG_FRAME(args...) (debug & 2 ? can_debug_cframe(args) : 0)
147 +#define DBG_SKB(skb) (debug & 4 ? can_debug_skb(skb) : 0)
149 +#define DBG(args...)
150 +#define DBG_FRAME(args...)
151 +#define DBG_SKB(skb)
154 +/* Indicate if this VCAN driver should do a real loopback, or if this */
155 +/* should be done in af_can.c */
158 +#define STATSIZE sizeof(struct net_device_stats)
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");
164 +static struct net_device **vcan_devs; /* root pointer to netdevice structs */
166 +static int vcan_open(struct net_device *dev)
168 + DBG("%s: interface up\n", dev->name);
170 + netif_start_queue(dev);
174 +static int vcan_stop(struct net_device *dev)
176 + DBG("%s: interface down\n", dev->name);
178 + netif_stop_queue(dev);
184 +static void vcan_rx(struct sk_buff *skb, struct net_device *dev)
186 + struct net_device_stats *stats = netdev_priv(dev);
187 + stats->rx_packets++;
188 + stats->rx_bytes += skb->len;
190 + skb->protocol = htons(ETH_P_CAN);
192 + skb->ip_summed = CHECKSUM_UNNECESSARY;
194 + DBG("received skbuff on interface %d\n", dev->ifindex);
202 +static int vcan_tx(struct sk_buff *skb, struct net_device *dev)
204 + struct net_device_stats *stats = netdev_priv(dev);
207 + DBG("sending skbuff on interface %s\n", dev->name);
209 + DBG_FRAME("VCAN: transmit CAN frame", (struct can_frame *)skb->data);
211 + stats->tx_packets++;
212 + stats->tx_bytes += skb->len;
214 + loop = *(struct sock **)skb->cb != NULL; /* loopback required */
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",
223 + kfree_skb(old_skb);
230 + vcan_rx(skb, dev); /* with packet counting */
232 + /* no looped packets => no counting */
236 + /* only count, when the CAN core did a loopback */
238 + stats->rx_packets++;
239 + stats->rx_bytes += skb->len;
246 +static int vcan_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
248 + return -EOPNOTSUPP;
251 +static int vcan_rebuild_header(struct sk_buff *skb)
253 + DBG("skbuff %p\n", skb);
258 +static int vcan_header(struct sk_buff *skb, struct net_device *dev,
259 + unsigned short type, void *daddr, void *saddr,
262 + DBG("skbuff %p, device %p\n", skb, dev);
268 +static struct net_device_stats *vcan_get_stats(struct net_device *dev)
270 + struct net_device_stats *stats = netdev_priv(dev);
274 +static void vcan_init(struct net_device *dev)
276 + DBG("dev %s\n", dev->name);
280 + memset(dev->priv, 0, STATSIZE);
282 + dev->type = ARPHRD_CAN;
283 + dev->mtu = sizeof(struct can_frame);
284 + dev->flags = IFF_NOARP;
286 + dev->flags |= IFF_LOOPBACK;
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;
299 + SET_MODULE_OWNER(dev);
302 +static __init int vcan_init_module(void)
304 + int i, ndev = 0, result = 0;
309 + numdev = 1; /* register at least one interface */
311 + printk(KERN_INFO "vcan: registering %d virtual CAN interfaces.\n",
314 + vcan_devs = kmalloc(numdev * sizeof(struct net_device *), GFP_KERNEL);
316 + printk(KERN_ERR "vcan: Can't allocate vcan devices array!\n");
320 + /* Clear the pointer array */
321 + memset(vcan_devs, 0, numdev * sizeof(struct net_device *));
323 + for (i = 0; i < numdev; i++) {
324 + if (!(vcan_devs[i] = alloc_netdev(STATSIZE, "vcan%d",
326 + printk(KERN_ERR "vcan: error allocating net_device\n");
329 + } else if ((result = register_netdev(vcan_devs[i])) < 0) {
330 + printk(KERN_ERR "vcan: error %d registering "
332 + result, vcan_devs[i]->name);
333 + free_netdev(vcan_devs[i]);
334 + vcan_devs[i] = NULL;
337 + DBG("successfully registered interface %s\n",
338 + vcan_devs[i]->name);
347 + for (i = 0; i < numdev; i++) {
348 + if (vcan_devs[i]) {
349 + unregister_netdev(vcan_devs[i]);
350 + free_netdev(vcan_devs[i]);
359 +static __exit void vcan_cleanup_module(void)
366 + for (i = 0; i < numdev; i++) {
367 + if (vcan_devs[i]) {
368 + unregister_netdev(vcan_devs[i]);
369 + free_netdev(vcan_devs[i]);
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
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
396 + * Definitions for CAN Broadcast Manager (BCM)
398 + * $Id: bcm.h 176 2007-03-07 16:12:46Z hartkopp $
400 + * Author: Oliver Hartkopp <oliver.hartkopp@volkswagen.de>
401 + * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
402 + * All rights reserved.
404 + * Send feedback to <socketcan-users@lists.berlios.de>
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];
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) */
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
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
456 + * Protoypes and definitions for CAN protocol modules using the PF_CAN core
458 + * $Id: core.h 177 2007-03-08 11:02:43Z hartkopp $
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.
465 + * Send feedback to <socketcan-users@lists.berlios.de>
472 +#include <linux/can.h>
473 +#include <linux/skbuff.h>
474 +#include <linux/netdevice.h>
476 +#define DNAME(dev) ((dev) ? (dev)->name : "any")
478 +#define CAN_PROC_DIR "net/can" /* /proc/... */
484 + struct proto_ops *ops;
485 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,13)
486 + struct proto *prot;
488 + struct module *owner;
489 + int (*init)(struct sock *sk);
494 +/* function prototypes for the CAN networklayer core (af_can.c) */
496 +void can_debug_skb(struct sk_buff *skb);
497 +void can_debug_cframe(const char *msg, struct can_frame *cframe, ...);
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,
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);
512 +unsigned long timeval2jiffies(struct timeval *tv, int round_up);
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
520 + * linux/can/error.h
522 + * Definitions of the CAN error frame to be filtered and passed to the user.
524 + * $Id: error.h 162 2007-03-05 08:25:02Z hartkopp $
526 + * Author: Oliver Hartkopp <oliver.hartkopp@volkswagen.de>
527 + * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
528 + * All rights reserved.
530 + * Send feedback to <socketcan-users@lists.berlios.de>
537 +#define CAN_ERR_DLC 8 /* dlc for error frames */
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 */
550 +/* arbitration lost in bit ... / data[0] */
551 +#define CAN_ERR_LOSTARB_UNSPEC 0x00 /* unspecified */
552 + /* else bit number in bitstream */
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) */
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 */
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 */
598 +/* error status of CAN-transceiver / data[4] */
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 */
611 +/* controller specific additional information / data[5..7] */
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
621 + * Definitions for raw CAN sockets
623 + * $Id: raw.h 176 2007-03-07 16:12:46Z hartkopp $
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.
630 + * Send feedback to <socketcan-users@lists.berlios.de>
637 +#include <linux/can.h>
639 +#define SOL_CAN_RAW (SOL_CAN_BASE + CAN_RAW)
641 +/* for socket options affecting the socket (not the global system) */
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) */
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
654 + * linux/can/version.h
656 + * Version information for the CAN network layer implementation
658 + * Author: Urs Thuermann <urs.thuermann@volkswagen.de>
659 + * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
660 + * All rights reserved.
662 + * Send feedback to <socketcan-users@lists.berlios.de>
666 +#ifndef CAN_VERSION_H
667 +#define CAN_VERSION_H
669 +#define RCSID(s) asm(".section .rodata.str1.1,\"aMS\",@progbits,1\n\t" \
670 + ".string \"" s "\"\n\t.previous\n")
672 +RCSID("$Id: version.h 170 2007-03-05 13:58:26Z hartkopp $");
674 +#define MAJORVERSION 2
675 +#define MINORVERSION 0
676 +#define PATCHLEVEL 0
677 +#define EXTRAVERSION "-pre6"
679 +#define LLCF_VERSION_CODE (((MAJORVERSION) << 16) + ((MINORVERSION) << 8) \
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.
686 +#define str(arg) xstr(arg)
687 +#define xstr(arg) #arg
689 +#define VERSION str(MAJORVERSION) "." str(MINORVERSION) "." str(PATCHLEVEL) \
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
700 + * Definitions for CAN networklayer (socket addr / CAN frame / CAN filter)
702 + * $Id: can.h 165 2007-03-05 10:14:18Z hartkopp $
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.
709 + * Send feedback to <socketcan-users@lists.berlios.de>
716 +#include <linux/version.h>
717 +#include <linux/types.h>
718 +#include <linux/socket.h>
720 +/* controller area network (CAN) kernel definitions */
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 */
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 */
732 +typedef __u32 canid_t;
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)));
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
750 +#define SOL_CAN_BASE 100
752 +struct sockaddr_can {
753 + sa_family_t can_family;
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;
764 +typedef canid_t can_err_mask_t;
771 +#define CAN_INV_FILTER 0x20000000U /* to be set in can_filter.can_id */
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
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
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
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 */
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
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
825 /* line disciplines */
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 */
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
839 T: git kernel.org:/pub/scm/linux/kernel/git/mchehab/v4l-dvb.git
844 +M: urs.thuermann@volkswagen.de
846 +M: oliver.hartkopp@volkswagen.de
847 +L: socketcan-core@lists.berlios.de
848 +W: http://developer.berlios.de/projects/socketcan/
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
859 + * af_can.c - Protocol family CAN core module
860 + * (used by different CAN protocol modules)
862 + * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
863 + * All rights reserved.
865 + * Redistribution and use in source and binary forms, with or without
866 + * modification, are permitted provided that the following conditions
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.
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.
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.
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
899 + * Send feedback to <socketcan-users@lists.berlios.de>
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>
921 +#include <linux/can.h>
922 +#include <linux/can/core.h>
923 +#include <linux/can/version.h>
928 +RCSID("$Id: af_can.c 177 2007-03-08 11:02:43Z hartkopp $");
930 +#define IDENT "af_can"
931 +static __initdata const char banner[] = KERN_INFO "CAN: Controller Area "
932 + "Network PF_CAN core " VERSION "\n";
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>");
939 +int stats_timer = 1; /* default: on */
940 +module_param(stats_timer, int, S_IRUGO);
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__), \
948 +#define DBG_FRAME(args...) (debug & 2 ? can_debug_cframe(args) : 0)
949 +#define DBG_SKB(skb) (debug & 4 ? can_debug_skb(skb) : 0)
951 +#define DBG(args...)
952 +#define DBG_FRAME(args...)
953 +#define DBG_SKB(skb)
956 +static __init int can_init(void);
957 +static __exit void can_exit(void);
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);
967 +static int can_rcv(struct sk_buff *skb, struct net_device *dev,
968 + struct packet_type *pt);
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);
980 + struct list_head list;
981 + struct net_device *dev;
982 + void (*func)(unsigned long msg, void *data);
986 +static LIST_HEAD(notifier_list);
987 +static rwlock_t notifier_lock = RW_LOCK_UNLOCKED;
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;
993 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
994 +static struct kmem_cache *rcv_cache __read_mostly;
996 +static kmem_cache_t *rcv_cache;
999 +static struct packet_type can_packet = {
1000 + .type = __constant_htons(ETH_P_CAN),
1005 +static struct net_proto_family can_family_ops = {
1007 + .create = can_create,
1008 + .owner = THIS_MODULE,
1011 +/* notifier block for netdevice event */
1012 +static struct notifier_block can_netdev_notifier = {
1013 + .notifier_call = can_notifier,
1016 +/* table of registered CAN protocols */
1017 +static struct can_proto *proto_tab[CAN_NPROTO];
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 */
1023 +module_init(can_init);
1024 +module_exit(can_exit);
1026 +/**************************************************/
1027 +/* af_can module init/exit functions */
1028 +/**************************************************/
1030 +static __init int can_init(void)
1034 + rcv_cache = kmem_cache_create("can_receiver", sizeof(struct receiver),
1035 + 0, 0, NULL, NULL);
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.
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);
1048 + if (stats_timer) {
1049 + /* statistics init */
1050 + init_timer(&stattimer);
1056 + /* protocol register */
1057 + sock_register(&can_family_ops);
1058 + register_netdevice_notifier(&can_netdev_notifier);
1059 + dev_add_pack(&can_packet);
1064 +static __exit void can_exit(void)
1066 + struct dev_rcv_lists *d;
1067 + struct hlist_node *n, *next;
1069 + if (stats_timer) {
1070 + /* stop statistics timer */
1071 + del_timer(&stattimer);
1074 + /* procfs remove */
1075 + can_remove_proc();
1077 + /* protocol unregister */
1078 + dev_remove_pack(&can_packet);
1079 + unregister_netdevice_notifier(&can_netdev_notifier);
1080 + sock_unregister(PF_CAN);
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);
1089 + spin_unlock_bh(&rcv_lists_lock);
1091 + kmem_cache_destroy(rcv_cache);
1094 +/**************************************************/
1095 +/* af_can protocol functions */
1096 +/**************************************************/
1098 +void can_proto_register(struct can_proto *cp)
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);
1106 + if (proto_tab[proto]) {
1107 + printk(KERN_ERR "CAN: protocol %d already "
1108 + "registered\n", proto);
1112 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,13)
1113 + if (proto_register(cp->prot, 0) != 0) {
1117 + proto_tab[proto] = cp;
1119 + /* use generic ioctl function if the module doesn't bring its own */
1120 + if (!cp->ops->ioctl)
1121 + cp->ops->ioctl = can_ioctl;
1124 +void can_proto_unregister(struct can_proto *cp)
1126 + int proto = cp->protocol;
1127 + if (!proto_tab[proto]) {
1128 + printk(KERN_ERR "CAN: protocol %d is not registered\n", proto);
1131 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,13)
1132 + proto_unregister(cp->prot);
1134 + proto_tab[proto] = NULL;
1137 +void can_dev_register(struct net_device *dev,
1138 + void (*func)(unsigned long msg, void *), void *data)
1140 + struct notifier *n;
1142 + DBG("called for %s\n", dev->name);
1144 + if (!(n = kmalloc(sizeof(*n), GFP_KERNEL)))
1151 + write_lock(¬ifier_lock);
1152 + list_add(&n->list, ¬ifier_list);
1153 + write_unlock(¬ifier_lock);
1156 +void can_dev_unregister(struct net_device *dev,
1157 + void (*func)(unsigned long msg, void *), void *data)
1159 + struct notifier *n, *next;
1161 + DBG("called for %s\n", dev->name);
1163 + write_lock(¬ifier_lock);
1164 + list_for_each_entry_safe(n, next, ¬ifier_list, list) {
1165 + if (n->dev == dev && n->func == func && n->data == data) {
1166 + list_del(&n->list);
1171 + write_unlock(¬ifier_lock);
1174 +/**************************************************/
1175 +/* af_can socket functions */
1176 +/**************************************************/
1178 +static void can_sock_destruct(struct sock *sk)
1180 + DBG("called for sock %p\n", sk);
1182 + skb_queue_purge(&sk->sk_receive_queue);
1183 + if (sk->sk_protinfo)
1184 + kfree(sk->sk_protinfo);
1187 +static int can_create(struct socket *sock, int protocol)
1190 + struct can_proto *cp;
1193 + DBG("socket %p, type %d, proto %d\n", sock, sock->type, protocol);
1195 + sock->state = SS_UNCONNECTED;
1197 + if (protocol < 0 || protocol >= CAN_NPROTO)
1200 + DBG("looking up proto %d in proto_tab[]\n", protocol);
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);
1211 + /* check for success and correct type */
1212 + if (!(cp = proto_tab[protocol]) || cp->type != sock->type)
1213 + return -EPROTONOSUPPORT;
1215 + if (cp->capability >= 0 && !capable(cp->capability))
1218 + sock->ops = cp->ops;
1220 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,13)
1221 + sk = sk_alloc(PF_CAN, GFP_KERNEL, cp->prot, 1);
1225 + sk = sk_alloc(PF_CAN, GFP_KERNEL, 1, 0);
1228 + if (cp->obj_size &&
1229 + !(sk->sk_protinfo = kmalloc(cp->obj_size, GFP_KERNEL))) {
1233 + sk_set_owner(sk, proto_tab[protocol]->owner);
1235 + sock_init_data(sock, sk);
1236 + sk->sk_destruct = can_sock_destruct;
1238 + DBG("created sock: %p\n", sk);
1241 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,13)
1242 + if (sk->sk_prot->init)
1243 + ret = sk->sk_prot->init(sk);
1246 + ret = cp->init(sk);
1249 + /* we must release sk */
1261 +static int can_notifier(struct notifier_block *nb,
1262 + unsigned long msg, void *data)
1264 + struct net_device *dev = (struct net_device *)data;
1265 + struct notifier *n;
1267 + DBG("called for %s, msg = %lu\n", dev->name, msg);
1269 + if (dev->type != ARPHRD_CAN)
1270 + return NOTIFY_DONE;
1273 + struct dev_rcv_lists *d;
1276 + case NETDEV_REGISTER:
1278 + /* create new dev_rcv_lists for this device */
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 "
1285 + return NOTIFY_DONE;
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));
1294 + spin_lock_bh(&rcv_lists_lock);
1295 + hlist_add_head_rcu(&d->list, &rx_dev_list);
1296 + spin_unlock_bh(&rcv_lists_lock);
1300 + case NETDEV_UNREGISTER:
1301 + spin_lock_bh(&rcv_lists_lock);
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);
1309 + hlist_del_rcu(&d->list);
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]);
1321 + spin_unlock_bh(&rcv_lists_lock);
1324 + call_rcu(&d->rcu, can_rcv_lists_delete);
1329 + read_lock(¬ifier_lock);
1330 + list_for_each_entry(n, ¬ifier_list, list) {
1331 + if (n->dev == dev)
1332 + n->func(msg, n->data);
1334 + read_unlock(¬ifier_lock);
1336 + return NOTIFY_DONE;
1339 +static int can_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1341 + struct sock *sk = sock->sk;
1345 + return sock_get_timestamp(sk, (struct timeval __user *)arg);
1347 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
1348 + return -ENOIOCTLCMD;
1350 + return dev_ioctl(cmd, (void __user *)arg);
1356 +/**************************************************/
1357 +/* af_can tx path */
1358 +/**************************************************/
1360 +int can_send(struct sk_buff *skb, int loop)
1364 + if (loop) { /* local loopback (default) */
1365 + *(struct sock **)skb->cb = skb->sk; /* tx sock reference */
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 */
1375 + *(struct sock **)skb->cb = NULL; /* no loopback required */
1377 + if (!(skb->dev->flags & IFF_UP))
1379 + else if ((err = dev_queue_xmit(skb)) > 0) /* send to netdevice */
1380 + err = net_xmit_errno(err);
1382 + /* update statistics */
1383 + stats.tx_frames++;
1384 + stats.tx_frames_delta++;
1389 +/**************************************************/
1390 +/* af_can rx path */
1391 +/**************************************************/
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,
1397 + struct receiver *r;
1398 + struct hlist_head *rl;
1399 + struct dev_rcv_lists *d;
1402 + /* insert new receiver (dev,canid,mask) -> (func,data) */
1404 + DBG("dev %p, id %03X, mask %03X, callback %p, data %p, ident %s\n",
1405 + dev, can_id, mask, func, data, ident);
1407 + if (!(r = kmem_cache_alloc(rcv_cache, GFP_KERNEL))) {
1412 + spin_lock_bh(&rcv_lists_lock);
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);
1422 + rl = find_rcv_list(&can_id, &mask, d);
1424 + r->can_id = can_id;
1431 + hlist_add_head_rcu(&r->list, rl);
1434 + pstats.rcv_entries++;
1435 + if (pstats.rcv_entries_max < pstats.rcv_entries)
1436 + pstats.rcv_entries_max = pstats.rcv_entries;
1439 + spin_unlock_bh(&rcv_lists_lock);
1444 +static void can_rcv_lists_delete(struct rcu_head *rp)
1446 + struct dev_rcv_lists *d = container_of(rp, struct dev_rcv_lists, rcu);
1450 +static void can_rx_delete(struct rcu_head *rp)
1452 + struct receiver *r = container_of(rp, struct receiver, rcu);
1453 + kmem_cache_free(rcv_cache, r);
1456 +static void can_rx_delete_all(struct hlist_head *rl)
1458 + struct receiver *r;
1459 + struct hlist_node *n;
1461 + hlist_for_each_entry_rcu(r, n, rl, list) {
1462 + hlist_del_rcu(&r->list);
1463 + call_rcu(&r->rcu, can_rx_delete);
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)
1470 + struct receiver *r;
1471 + struct hlist_head *rl;
1472 + struct hlist_node *next;
1473 + struct dev_rcv_lists *d;
1476 + DBG("dev %p, id %03X, mask %03X, callback %p, data %p\n",
1477 + dev, can_id, mask, func, data);
1481 + spin_lock_bh(&rcv_lists_lock);
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);
1490 + rl = find_rcv_list(&can_id, &mask, d);
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.
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)
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.
1509 + DBG("receive list entry not found for "
1510 + "dev %s, id %03X, mask %03X\n", DNAME(dev), can_id, mask);
1516 + hlist_del_rcu(&r->list);
1519 + if (pstats.rcv_entries > 0)
1520 + pstats.rcv_entries--;
1523 + spin_unlock_bh(&rcv_lists_lock);
1525 + /* schedule the receiver item for deletion */
1527 + call_rcu(&r->rcu, can_rx_delete);
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)
1536 +static int can_rcv(struct sk_buff *skb, struct net_device *dev,
1537 + struct packet_type *pt)
1540 + struct dev_rcv_lists *d;
1543 + DBG("received skbuff on device %s, ptype %04x\n",
1544 + dev->name, ntohs(pt->type));
1546 + DBG_FRAME("af_can: can_rcv: received CAN frame",
1547 + (struct can_frame *)skb->data);
1549 + /* update statistics */
1550 + stats.rx_frames++;
1551 + stats.rx_frames_delta++;
1555 + /* deliver the packet to sockets listening on all devices */
1556 + matches = can_rcv_filter(&rx_alldev_list, skb);
1558 + /* find receive list for this device */
1559 + if ((d = find_dev_rcv_lists(dev)))
1560 + matches += can_rcv_filter(d, skb);
1562 + rcu_read_unlock();
1564 + /* free the skbuff allocated by the netdevice driver */
1565 + DBG("freeing skbuff %p\n", skb);
1568 + if (matches > 0) {
1570 + stats.matches_delta++;
1577 +static inline void deliver(struct sk_buff *skb, struct receiver *r)
1579 + struct sk_buff *clone = skb_clone(skb, GFP_ATOMIC);
1580 + DBG("skbuff %p cloned to %p\n", skb, clone);
1582 + r->func(clone, r->data);
1583 + r->matches++; /* update specific statistics */
1587 +static int can_rcv_filter(struct dev_rcv_lists *d, struct sk_buff *skb)
1589 + struct receiver *r;
1590 + struct hlist_node *n;
1592 + struct can_frame *cf = (struct can_frame*)skb->data;
1593 + canid_t can_id = cf->can_id;
1595 + if (d->entries == 0)
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);
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);
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);
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);
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);
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);
1657 +static struct dev_rcv_lists *find_dev_rcv_lists(struct net_device *dev)
1659 + struct dev_rcv_lists *d;
1660 + struct hlist_node *n;
1662 + /* find receive list for this device */
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.
1674 + hlist_for_each_entry(d, n, &rx_dev_list, list)
1675 + if (d->dev == dev)
1678 + return n ? d : NULL;
1681 +static struct hlist_head *find_rcv_list(canid_t *can_id, canid_t *mask,
1682 + struct dev_rcv_lists *d)
1684 + canid_t inv = *can_id & CAN_INV_FILTER; /* save flag before masking */
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;
1691 + /* ensure valid values in can_mask */
1692 + if (*mask & CAN_EFF_FLAG)
1693 + *mask &= (CAN_EFF_MASK | CAN_EFF_FLAG | CAN_RTR_FLAG);
1695 + *mask &= (CAN_SFF_MASK | CAN_RTR_FLAG);
1697 + *can_id &= *mask; /* reduce condition testing at receive time */
1699 + if (inv) /* inverse can_id/can_mask filter */
1700 + return &d->rx_inv;
1702 + if (!(*mask)) /* mask == 0 => no condition testing at receive time */
1703 + return &d->rx_all;
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? */
1710 + if (*mask == CAN_SFF_MASK)
1711 + return &d->rx_sff[*can_id];
1714 + return &d->rx_fil; /* default: filter via can_id/can_mask */
1717 +/**************************************************/
1718 +/* af_can utility stuff */
1719 +/**************************************************/
1721 +unsigned long timeval2jiffies(struct timeval *tv, int round_up)
1723 + unsigned long jif;
1724 + unsigned long sec = tv->tv_sec;
1725 + unsigned long usec = tv->tv_usec;
1727 + if (sec > ULONG_MAX / HZ) /* check for overflow */
1730 + if (round_up) /* any usec below one HZ? */
1731 + usec += 1000000 / HZ - 1; /* pump it up */
1733 + jif = usec / (1000000 / HZ);
1735 + if (sec * HZ > ULONG_MAX - jif) /* check for overflow */
1738 + return jif + sec * HZ;
1742 +/**************************************************/
1743 +/* af_can debugging stuff */
1744 +/**************************************************/
1746 +#ifdef CONFIG_CAN_DEBUG_CORE
1748 +void can_debug_cframe(const char *msg, struct can_frame *cf, ...)
1755 + len = sprintf(buf, KERN_DEBUG);
1757 + len += snprintf(buf + len, sizeof(buf) - 64, msg, ap);
1762 + if ((dlc = cf->can_dlc) > 8)
1765 + if (cf->can_id & CAN_EFF_FLAG)
1766 + len += sprintf(buf + len, "<%08X> [%X] ",
1767 + cf->can_id & CAN_EFF_MASK, dlc);
1769 + len += sprintf(buf + len, "<%03X> [%X] ",
1770 + cf->can_id & CAN_SFF_MASK, dlc);
1772 + for (i = 0; i < dlc; i++)
1773 + len += sprintf(buf + len, "%02X ", cf->data[i]);
1775 + if (cf->can_id & CAN_RTR_FLAG)
1776 + len += sprintf(buf + len, "(RTR)");
1778 + buf[len++] = '\n';
1783 +void can_debug_skb(struct sk_buff *skb)
1785 + int len, nbytes, i;
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++) {
1802 + len += sprintf(buf + len, "\n" KERN_DEBUG " ");
1803 + if (len < sizeof(buf) - 16) {
1804 + len += sprintf(buf + len, " %02x", skb->head[i]);
1806 + len += sprintf(buf + len, "...");
1810 + buf[len++] = '\n';
1815 +EXPORT_SYMBOL(can_debug_cframe);
1816 +EXPORT_SYMBOL(can_debug_skb);
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
1836 + * $Id: af_can.h 177 2007-03-08 11:02:43Z hartkopp $
1838 + * Copyright (c) 2002-2005 Volkswagen Group Electronic Research
1839 + * All rights reserved.
1841 + * Redistribution and use in source and binary forms, with or without
1842 + * modification, are permitted provided that the following conditions
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.
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.
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.
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
1875 + * Send feedback to <socketcan-users@lists.berlios.de>
1882 +#include <linux/skbuff.h>
1883 +#include <linux/netdevice.h>
1884 +#include <linux/list.h>
1885 +#include <linux/rcupdate.h>
1887 +#include <linux/can.h>
1889 +/* af_can rx dispatcher structures */
1892 + struct hlist_node list;
1893 + struct rcu_head rcu;
1896 + unsigned long matches;
1897 + void (*func)(struct sk_buff *, void *);
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;
1915 +/* statistic structures */
1918 + unsigned long jiffies_init;
1920 + unsigned long rx_frames;
1921 + unsigned long tx_frames;
1922 + unsigned long matches;
1924 + unsigned long total_rx_rate;
1925 + unsigned long total_tx_rate;
1926 + unsigned long total_rx_match_ratio;
1928 + unsigned long current_rx_rate;
1929 + unsigned long current_tx_rate;
1930 + unsigned long current_rx_match_ratio;
1932 + unsigned long max_rx_rate;
1933 + unsigned long max_tx_rate;
1934 + unsigned long max_rx_match_ratio;
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() */
1942 + unsigned long stats_reset;
1943 + unsigned long rcv_entries;
1944 + unsigned long rcv_entries_max;
1945 +}; /* persistent statistics */
1948 +/* function prototypes for the CAN networklayer procfs (proc.c) */
1950 +void can_init_proc(void);
1951 +void can_remove_proc(void);
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
1959 + * bcm.c - Broadcast Manager to filter/send (cyclic) CAN content
1961 + * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
1962 + * All rights reserved.
1964 + * Redistribution and use in source and binary forms, with or without
1965 + * modification, are permitted provided that the following conditions
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.
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.
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.
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
1998 + * Send feedback to <socketcan-users@lists.berlios.de>
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>
2011 +#include <linux/can.h>
2012 +#include <linux/can/core.h>
2013 +#include <linux/can/bcm.h>
2014 +#include <linux/can/version.h>
2016 +RCSID("$Id: bcm.c 179 2007-03-09 07:36:49Z hartkopp $");
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)
2027 +#define DBG(args...)
2028 +#define DBG_FRAME(args...)
2029 +#define DBG_SKB(skb)
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 */
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))
2041 +#define IDENT "bcm"
2042 +static __initdata const char banner[] = KERN_INFO
2043 + "CAN: broadcast manager (bcm) socket protocol " VERSION "\n";
2045 +MODULE_DESCRIPTION("PF_CAN bcm sockets");
2046 +MODULE_LICENSE("Dual BSD/GPL");
2047 +MODULE_AUTHOR("Oliver Hartkopp <oliver.hartkopp@volkswagen.de>");
2049 +#define GET_U64(p) (*(u64*)(p)->data) /* easy access */
2052 + struct list_head list;
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;
2065 + struct can_frame *frames;
2066 + struct can_frame *last_frames;
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 */
2080 +static struct proc_dir_entry *proc_dir = NULL;
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,
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);
2094 +static int bcm_read_proc(char *page, char **start, off_t off,
2095 + int count, int *eof, void *data);
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);
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);
2118 +static int bcm_delete_tx_op(struct list_head *ops, canid_t can_id,
2120 +static int bcm_delete_rx_op(struct list_head *ops, canid_t can_id,
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,
2125 +static struct bcm_op *bcm_find_op(struct list_head *ops, canid_t can_id,
2128 +static struct proto_ops bcm_ops = {
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,
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,
2148 +#ifdef CONFIG_CAN_BCM_USER
2149 +#define BCM_CAP (-1)
2151 +#define BCM_CAP CAP_NET_RAW
2154 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,13)
2157 + struct bcm_opt opt;
2160 +#define bcm_sk(sk) (&((struct bcm_sock *)(sk))->opt)
2162 +static struct proto bcm_proto = {
2163 + .name = "CAN_BCM",
2164 + .owner = THIS_MODULE,
2165 + .obj_size = sizeof(struct bcm_sock),
2169 +static struct can_proto bcm_can_proto = {
2170 + .type = SOCK_DGRAM,
2171 + .protocol = CAN_BCM,
2172 + .capability = BCM_CAP,
2174 + .prot = &bcm_proto,
2177 +#define bcm_sk(sk) ((struct bcm_opt *)(sk)->sk_protinfo)
2179 +static struct can_proto bcm_can_proto = {
2180 + .type = SOCK_DGRAM,
2181 + .protocol = CAN_BCM,
2182 + .capability = BCM_CAP,
2184 + .owner = THIS_MODULE,
2185 + .obj_size = sizeof(struct bcm_opt),
2190 +#define CFSIZ sizeof(struct can_frame)
2191 +#define OPSIZ sizeof(struct bcm_op)
2192 +#define MHSIZ sizeof(struct bcm_msg_head)
2194 +static int __init bcm_module_init(void)
2198 + can_proto_register(&bcm_can_proto);
2200 + /* create /proc/net/can/bcm directory */
2201 + proc_dir = proc_mkdir(CAN_PROC_DIR"/"IDENT, NULL);
2204 + proc_dir->owner = THIS_MODULE;
2209 +static void __exit bcm_module_exit(void)
2211 + can_proto_unregister(&bcm_can_proto);
2214 + remove_proc_entry(CAN_PROC_DIR"/"IDENT, NULL);
2218 +/**************************************************/
2219 +/* initial settings at socket creation time */
2220 +/**************************************************/
2222 +static int bcm_init(struct sock *sk)
2224 + struct bcm_opt *bo = bcm_sk(sk);
2228 + bo->dropped_usr_msgs = 0;
2229 + bo->bcm_proc_read = NULL;
2231 + INIT_LIST_HEAD(&bo->tx_ops);
2232 + INIT_LIST_HEAD(&bo->rx_ops);
2237 +/**************************************************/
2238 +/* handling of netdevice problems */
2239 +/**************************************************/
2241 +static void bcm_notifier(unsigned long msg, void *data)
2243 + struct sock *sk = (struct sock *)data;
2244 + struct bcm_opt *bo = bcm_sk(sk);
2246 + DBG("called for sock %p\n", sk);
2249 + case NETDEV_UNREGISTER:
2254 + sk->sk_err = ENETDOWN;
2255 + if (!sock_flag(sk, SOCK_DEAD))
2256 + sk->sk_error_report(sk);
2260 +/**************************************************/
2261 +/* standard socket functions */
2262 +/**************************************************/
2264 +static int bcm_release(struct socket *sock)
2266 + struct sock *sk = sock->sk;
2267 + struct bcm_opt *bo = bcm_sk(sk);
2268 + struct bcm_op *op, *next;
2270 + DBG("socket %p, sk %p\n", sock, sk);
2272 + /* remove bcm_ops, timer, rx_unregister(), etc. */
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);
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);
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);
2287 + can_rx_unregister(dev, op->can_id,
2288 + REGMASK(op->can_id),
2289 + bcm_rx_handler, op);
2293 + can_rx_unregister(NULL, op->can_id,
2294 + REGMASK(op->can_id),
2295 + bcm_rx_handler, op);
2297 + bcm_remove_op(op);
2300 + /* remove procfs entry */
2301 + if ((proc_dir) && (bo->bcm_proc_read)) {
2302 + remove_proc_entry(bo->procname, proc_dir);
2305 + /* remove device notifier */
2306 + if (bo->ifindex) {
2307 + struct net_device *dev = dev_get_by_index(bo->ifindex);
2309 + can_dev_unregister(dev, bcm_notifier, sk);
2319 +static int bcm_connect(struct socket *sock, struct sockaddr *uaddr, int len,
2322 + struct sockaddr_can *addr = (struct sockaddr_can *)uaddr;
2323 + struct sock *sk = sock->sk;
2324 + struct bcm_opt *bo = bcm_sk(sk);
2329 + /* bind a device to this socket */
2330 + if (addr->can_ifindex) {
2331 + struct net_device *dev = dev_get_by_index(addr->can_ifindex);
2333 + DBG("could not find device index %d\n",
2334 + addr->can_ifindex);
2337 + bo->ifindex = dev->ifindex;
2338 + can_dev_register(dev, bcm_notifier, sk); /* register notif. */
2341 + DBG("socket %p bound to device %s (idx %d)\n",
2342 + sock, dev->name, dev->ifindex);
2344 + /* no notifier for ifindex = 0 ('any' CAN device) */
2351 + /* unique socket address as filename */
2352 + sprintf(bo->procname, "%p", sock);
2353 + bo->bcm_proc_read = create_proc_read_entry(bo->procname, 0644,
2355 + bcm_read_proc, sk);
2361 +static int bcm_sendmsg(struct kiocb *iocb, struct socket *sock,
2362 + struct msghdr *msg, size_t size)
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 */
2371 + DBG("sock %p not bound\n", sk);
2375 + /* check for alternative ifindex for this bcm_op */
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)
2382 + ifindex = addr->can_ifindex; /* ifindex from sendto() */
2384 + if (ifindex && !dev_get_by_index(ifindex)) {
2385 + DBG("device %d not found\n", ifindex);
2390 + /* read message head information */
2392 + if ((ret = memcpy_fromiovec((u8*)&msg_head, msg->msg_iov,
2396 + DBG("opcode %d for can_id %03X\n", msg_head.opcode, msg_head.can_id);
2398 + switch (msg_head.opcode) {
2402 + ret = bcm_tx_setup(&msg_head, msg, ifindex, sk);
2407 + ret = bcm_rx_setup(&msg_head, msg, ifindex, sk);
2412 + if (bcm_delete_tx_op(&bo->tx_ops, msg_head.can_id, ifindex))
2420 + if (bcm_delete_rx_op(&bo->rx_ops, msg_head.can_id, ifindex))
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);
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);
2442 + if (msg_head.nframes < 1) /* we need at least one can_frame */
2445 + ret = bcm_tx_send(msg, ifindex, sk);
2450 + DBG("Unknown opcode %d\n", msg_head.opcode);
2458 +static int bcm_recvmsg(struct kiocb *iocb, struct socket *sock,
2459 + struct msghdr *msg, size_t size, int flags)
2461 + struct sock *sk = sock->sk;
2462 + struct sk_buff *skb;
2467 + DBG("socket %p, sk %p\n", sock, sk);
2469 + noblock = flags & MSG_DONTWAIT;
2470 + flags &= ~MSG_DONTWAIT;
2471 + if (!(skb = skb_recv_datagram(sk, flags, noblock, &error))) {
2475 + DBG("delivering skbuff %p\n", skb);
2478 + if (skb->len < size)
2480 + if ((err = memcpy_toiovec(msg->msg_iov, skb->data, size)) < 0) {
2481 + skb_free_datagram(sk, skb);
2485 + sock_recv_timestamp(msg, sk, skb);
2487 + if (msg->msg_name) {
2488 + msg->msg_namelen = sizeof(struct sockaddr_can);
2489 + memcpy(msg->msg_name, skb->cb, msg->msg_namelen);
2492 + DBG("freeing sock %p, skbuff %p\n", sk, skb);
2493 + skb_free_datagram(sk, skb);
2498 +static unsigned int bcm_poll(struct file *file, struct socket *sock,
2501 + unsigned int mask = 0;
2503 + DBG("socket %p\n", sock);
2505 + mask = datagram_poll(file, sock, wait);
2509 +/**************************************************/
2510 +/* helper functions for bcm_sendmsg() */
2511 +/**************************************************/
2513 +static int bcm_tx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg,
2514 + int ifindex, struct sock *sk)
2516 + struct bcm_opt *bo = bcm_sk(sk);
2517 + struct bcm_op *op;
2520 + if (!ifindex) /* we need a real device to send frames */
2523 + if (msg_head->nframes < 1) /* we need at least one can_frame */
2526 + /* check the given can_id */
2528 + if ((op = bcm_find_op(&bo->tx_ops, msg_head->can_id, ifindex))) {
2530 + /* update existing BCM operation */
2532 + DBG("TX_SETUP: modifying existing tx_op %p for can_id %03X\n",
2533 + op, msg_head->can_id);
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)
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)
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;
2554 + /* insert new BCM operation for the given can_id */
2556 + if (!(op = kmalloc(OPSIZ, GFP_KERNEL)))
2559 + memset(op, 0, OPSIZ); /* init to zero, e.g. for timers */
2561 + DBG("TX_SETUP: creating new tx_op %p for can_id %03X\n",
2562 + op, msg_head->can_id);
2564 + op->can_id = msg_head->can_id;
2566 + /* create array for can_frames and copy the data */
2567 + if (!(op->frames = kmalloc(msg_head->nframes * CFSIZ,
2573 + for (i = 0; i < msg_head->nframes; i++) {
2574 + if ((err = memcpy_fromiovec((u8*)&op->frames[i],
2577 + kfree(op->frames);
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;
2588 + /* tx_ops never compare with previous received messages */
2589 + op->last_frames = NULL;
2591 + /* bcm_can_tx / bcm_tx_timeout_handler needs this */
2594 + op->ifindex = ifindex;
2596 + /* initialize uninitialized (kmalloc) structure */
2597 + init_timer(&op->timer);
2599 + /* currently unused in tx_ops */
2600 + init_timer(&op->thrtimer);
2602 + /* handler for tx_ops */
2603 + op->timer.function = bcm_tx_timeout_handler;
2605 + /* timer.data points to this op-structure */
2606 + op->timer.data = (unsigned long)op;
2608 + /* add this bcm_op to the list of the tx_ops */
2609 + list_add(&op->list, &bo->tx_ops);
2611 + } /* if ((op = bcm_find_op(&bo->tx_ops, msg_head->can_id, ifindex))) */
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;
2621 + op->flags = msg_head->flags;
2623 + if (op->flags & TX_RESET_MULTI_IDX) {
2624 + /* start multiple frame transmission with index 0 */
2625 + op->currframe = 0;
2628 + if (op->flags & SETTIMER) {
2630 + /* set timer values */
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);
2638 + DBG("TX_SETUP: SETTIMER count=%d j_ival1=%ld j_ival2=%ld\n",
2639 + op->count, op->j_ival1, op->j_ival2);
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");
2648 + if ((op->flags & STARTTIMER) &&
2649 + ((op->j_ival1 && op->count) || op->j_ival2)) {
2651 + del_timer(&op->timer);
2653 + /* spec: send can_frame when starting timer */
2654 + op->flags |= TX_ANNOUNCE;
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 "
2661 + op->timer.function,
2662 + (char*) op->timer.data,
2663 + (unsigned int) op->timer.expires);
2665 + op->timer.expires = jiffies + op->j_ival2;
2666 + DBG("TX_SETUP: adding timer ival2. func=%p data=%p "
2668 + op->timer.function,
2669 + (char*) op->timer.data,
2670 + (unsigned int) op->timer.expires);
2673 + add_timer(&op->timer);
2676 + if (op->flags & TX_ANNOUNCE)
2679 + return msg_head->nframes * CFSIZ + MHSIZ;
2682 +static int bcm_rx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg,
2683 + int ifindex, struct sock *sk)
2685 + struct bcm_opt *bo = bcm_sk(sk);
2686 + struct bcm_op *op;
2687 + int do_rx_register;
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 */
2696 + if ((msg_head->flags & RX_RTR_FRAME) &&
2697 + ((msg_head->nframes != 1) ||
2698 + (!(msg_head->can_id & CAN_RTR_FLAG)))) {
2700 + DBG("RX_SETUP: bad RX_RTR_FRAME setup!\n");
2704 + /* check the given can_id */
2706 + if ((op = bcm_find_op(&bo->rx_ops, msg_head->can_id, ifindex))) {
2708 + /* update existing BCM operation */
2710 + DBG("RX_SETUP: modifying existing rx_op %p for can_id %03X\n",
2711 + op, msg_head->can_id);
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)
2719 + if (msg_head->nframes) {
2720 + /* update can_frames content */
2721 + if ((err = memcpy_fromiovec((u8*)op->frames,
2727 + /* clear last_frames to indicate 'nothing received' */
2728 + memset(op->last_frames, 0, msg_head->nframes * CFSIZ);
2731 + op->nframes = msg_head->nframes;
2732 + /* Only an update -> do not call can_rx_register() */
2733 + do_rx_register = 0;
2736 + /* insert new BCM operation for the given can_id */
2738 + if (!(op = kmalloc(OPSIZ, GFP_KERNEL)))
2741 + memset(op, 0, OPSIZ); /* init to zero, e.g. for timers */
2743 + DBG("RX_SETUP: creating new rx_op %p for can_id %03X\n",
2744 + op, msg_head->can_id);
2746 + op->can_id = msg_head->can_id;
2747 + op->nframes = msg_head->nframes;
2749 + if (msg_head->nframes) {
2751 + /* create array for can_frames and copy the data */
2752 + if (!(op->frames = kmalloc(msg_head->nframes * CFSIZ,
2758 + if ((err = memcpy_fromiovec((u8*)op->frames,
2762 + kfree(op->frames);
2767 + /* create array for received can_frames */
2768 + if (!(op->last_frames = kmalloc(msg_head->nframes
2771 + kfree(op->frames);
2776 + /* clear last_frames to indicate 'nothing received' */
2777 + memset(op->last_frames, 0, msg_head->nframes * CFSIZ);
2779 + /* op->frames = NULL due to memset */
2781 + /* even when we have the RX_FILTER_ID case, we need */
2782 + /* to store the last frame for the throttle feature */
2784 + /* create array for received can_frames */
2785 + if (!(op->last_frames = kmalloc(CFSIZ, GFP_KERNEL))) {
2790 + /* clear last_frames to indicate 'nothing received' */
2791 + memset(op->last_frames, 0, CFSIZ);
2794 + op->sk = sk; /* bcm_delete_rx_op() needs this */
2795 + op->ifindex = ifindex;
2797 + /* initialize uninitialized (kmalloc) structure */
2798 + init_timer(&op->timer);
2800 + /* init throttle timer for RX_CHANGED */
2801 + init_timer(&op->thrtimer);
2803 + /* handler for rx timeouts */
2804 + op->timer.function = bcm_rx_timeout_handler;
2806 + /* timer.data points to this op-structure */
2807 + op->timer.data = (unsigned long)op;
2809 + /* handler for RX_CHANGED throttle timeouts */
2810 + op->thrtimer.function = bcm_rx_thr_handler;
2812 + /* timer.data points to this op-structure */
2813 + op->thrtimer.data = (unsigned long)op;
2815 + op->thrtimer.expires = 0; /* mark disabled timer */
2817 + /* add this bcm_op to the list of the tx_ops */
2818 + list_add(&op->list, &bo->rx_ops);
2820 + do_rx_register = 1; /* call can_rx_register() */
2822 + } /* if ((op = bcm_find_op(&bo->rx_ops, msg_head->can_id, ifindex))) */
2827 + op->flags = msg_head->flags;
2829 + if (op->flags & RX_RTR_FRAME) {
2831 + /* no timers in RTR-mode */
2832 + del_timer(&op->thrtimer);
2833 + del_timer(&op->timer);
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;
2843 + if (op->flags & SETTIMER) {
2845 + /* set timer value */
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);
2852 + DBG("RX_SETUP: SETTIMER j_ival1=%ld j_ival2=%ld\n",
2853 + op->j_ival1, op->j_ival2);
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");
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);
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() */
2874 + if ((op->flags & STARTTIMER) && op->j_ival1) {
2876 + del_timer(&op->timer);
2878 + op->timer.expires = jiffies + op->j_ival1;
2880 + DBG("RX_SETUP: adding timer ival1. func=%p data=%p"
2882 + (char *) op->timer.function,
2883 + (char *) op->timer.data,
2884 + (unsigned int) op->timer.expires);
2886 + add_timer(&op->timer);
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);
2896 + struct net_device *dev = dev_get_by_index(ifindex);
2899 + can_rx_register(dev, op->can_id,
2900 + REGMASK(op->can_id),
2901 + bcm_rx_handler, op, IDENT);
2905 + can_rx_register(NULL, op->can_id, REGMASK(op->can_id),
2906 + bcm_rx_handler, op, IDENT);
2909 + return msg_head->nframes * CFSIZ + MHSIZ;
2912 +static int bcm_tx_send(struct msghdr *msg, int ifindex, struct sock *sk)
2914 + struct sk_buff *skb;
2915 + struct net_device *dev;
2918 + /* just copy and send one can_frame */
2920 + if (!ifindex) /* we need a real device to send frames */
2923 + skb = alloc_skb(CFSIZ, GFP_KERNEL);
2928 + if ((err = memcpy_fromiovec(skb_put(skb, CFSIZ), msg->msg_iov,
2934 + DBG_FRAME("BCM: TX_SEND: sending frame",
2935 + (struct can_frame *)skb->data);
2936 + dev = dev_get_by_index(ifindex);
2945 + can_send(skb, 1); /* send with loopback */
2948 + return CFSIZ + MHSIZ;
2951 +static int bcm_read_op(struct list_head *ops, struct bcm_msg_head *msg_head,
2954 + struct bcm_op *op;
2957 + if ((op = bcm_find_op(ops, msg_head->can_id, ifindex))) {
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;
2968 + bcm_send_to_user(op, msg_head, op->frames, NULL);
2974 + DBG("TRX_READ: did not find op for can_id %03X\n",
2975 + msg_head->can_id);
2982 +/**************************************************/
2983 +/* procfs functions */
2984 +/**************************************************/
2986 +static char *bcm_proc_getifname(int ifindex)
2988 + struct net_device *dev;
2993 + dev = __dev_get_by_index(ifindex); /* no usage counting */
3000 +static int bcm_read_proc(char *page, char **start, off_t off,
3001 + int count, int *eof, void *data)
3004 + struct sock *sk = (struct sock *)data;
3005 + struct bcm_opt *bo = bcm_sk(sk);
3006 + struct bcm_op *op;
3008 + len += snprintf(page + len, PAGE_SIZE - len, ">>> socket %p",
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");
3018 + list_for_each_entry(op, &bo->rx_ops, list) {
3020 + unsigned long reduction;
3022 + /* print only active entries & prevent division by zero */
3023 + if (!op->frames_abs)
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 ",
3031 + (op->flags & RX_CHECK_DLC)?'d':' ');
3033 + len += snprintf(page + len, PAGE_SIZE - len,
3034 + "timeo=%ld ", op->j_ival1);
3037 + len += snprintf(page + len, PAGE_SIZE - len,
3038 + "thr=%ld ", op->j_ival2);
3040 + len += snprintf(page + len, PAGE_SIZE - len,
3041 + "# recv %ld (%ld) => reduction: ",
3042 + op->frames_filtered, op->frames_abs);
3044 + reduction = 100 - (op->frames_filtered * 100) / op->frames_abs;
3046 + len += snprintf(page + len, PAGE_SIZE - len, "%s%ld%%\n",
3047 + (reduction == 100)?"near ":"", reduction);
3049 + if (len > PAGE_SIZE - 200) {
3050 + /* mark output cut off */
3051 + len += snprintf(page + len, PAGE_SIZE - len, "(..)\n");
3056 + list_for_each_entry(op, &bo->tx_ops, list) {
3058 + len += snprintf(page + len, PAGE_SIZE - len,
3059 + "tx_op: %03X %s [%d] ",
3060 + op->can_id, bcm_proc_getifname(op->ifindex),
3063 + len += snprintf(page + len, PAGE_SIZE - len, "t1=%ld ",
3067 + len += snprintf(page + len, PAGE_SIZE - len, "t2=%ld ",
3070 + len += snprintf(page + len, PAGE_SIZE - len, "# sent %ld\n",
3073 + if (len > PAGE_SIZE - 100) {
3074 + /* mark output cut off */
3075 + len += snprintf(page + len, PAGE_SIZE - len, "(..)\n");
3080 + len += snprintf(page + len, PAGE_SIZE - len, "\n");
3086 +/**************************************************/
3087 +/* bcm_op handling tx path */
3088 +/**************************************************/
3090 +static void bcm_can_tx(struct bcm_op *op)
3092 + struct sk_buff *skb;
3093 + struct net_device *dev;
3094 + struct can_frame *cf = &op->frames[op->currframe];
3096 + DBG_FRAME("BCM: bcm_can_tx: sending frame", cf);
3099 + return; /* no target device -> exit */
3101 + dev = dev_get_by_index(op->ifindex);
3104 + return; /* should this bcm_op remove itself here? */
3106 + skb = alloc_skb(CFSIZ,
3107 + in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
3110 + goto out; /* no memory */
3112 + memcpy(skb_put(skb, CFSIZ), cf, CFSIZ);
3116 + can_send(skb, 1); /* send with loopback */
3119 + op->frames_abs++; /* statistics */
3121 + /* reached last frame? */
3122 + if (op->currframe >= op->nframes)
3123 + op->currframe = 0;
3128 +static void bcm_tx_timeout_handler(unsigned long data)
3130 + struct bcm_op *op = (struct bcm_op*)data;
3132 + DBG("Called with bcm_op %p\n", op);
3134 + if (op->j_ival1 && (op->count > 0)) {
3138 + if (!op->count && (op->flags & TX_COUNTEVT)) {
3139 + /* create notification to user */
3141 + struct bcm_msg_head msg_head;
3143 + DBG("sending TX_EXPIRED for can_id %03X\n",
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;
3154 + bcm_send_to_user(op, &msg_head, NULL, NULL);
3158 + DBG("count=%d j_ival1=%ld j_ival2=%ld\n",
3159 + op->count, op->j_ival1, op->j_ival2);
3161 + if (op->j_ival1 && (op->count > 0)) {
3163 + op->timer.expires = jiffies + op->j_ival1;
3164 + add_timer(&op->timer);
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);
3171 + bcm_can_tx(op); /* send (next) frame */
3173 + if (op->j_ival2) {
3174 + op->timer.expires = jiffies + op->j_ival2;
3175 + add_timer(&op->timer);
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);
3182 + bcm_can_tx(op); /* send (next) frame */
3184 + DBG("no timer restart\n");
3191 +/**************************************************/
3192 +/* bcm_op handling rx path */
3193 +/**************************************************/
3195 +static void bcm_rx_handler(struct sk_buff *skb, void *data)
3197 + struct bcm_op *op = (struct bcm_op*)data;
3198 + struct can_frame rxframe;
3201 + del_timer(&op->timer); /* disable timeout */
3203 + DBG("Called with bcm_op %p\n", op);
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 */
3212 + DBG("got can_frame with can_id %03X\n", rxframe.can_id);
3214 + DBG("Wrong skb->len = %d\n", skb->len);
3219 + DBG_FRAME("BCM: bcm_rx_handler: CAN frame", &rxframe);
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);
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 */
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);
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);
3247 + if (op->nframes > 1) { /* multiplex compare */
3249 + DBG("Multiplex compare\n");
3250 + /* find the first multiplex mask that fits */
3251 + /* MUX-mask is in index 0 */
3253 + for (i=1; i < op->nframes; i++) {
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);
3263 + bcm_rx_starttimer(op);
3267 +static void bcm_rx_cmp_to_index(struct bcm_op *op, int index,
3268 + struct can_frame *rxdata)
3270 + /* no one uses the MSBs of can_dlc for comparation, */
3271 + /* so we use it here to detect the first time of reception */
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);
3279 + /* do a real check in can_data */
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));
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);
3295 + if (op->flags & RX_CHECK_DLC) {
3297 + /* do a real check in dlc */
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],
3307 + DBG("no relevant change :(\n");
3310 +static void bcm_rx_update_and_send(struct bcm_op *op,
3311 + struct can_frame *lastdata,
3312 + struct can_frame *rxdata)
3314 + unsigned long nexttx = op->j_lastmsg + op->j_ival2;
3316 + memcpy(lastdata, rxdata, CFSIZ);
3317 + lastdata->can_dlc |= RX_RECV; /* mark as used */
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 */
3323 + lastdata->can_dlc |= RX_THR; /* mark as 'throttled' */
3325 + if (!(op->thrtimer.expires)) { /* start only the first time */
3326 + op->thrtimer.expires = nexttx;
3327 + add_timer(&op->thrtimer);
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);
3335 + bcm_rx_changed(op, rxdata); /* send RX_CHANGED to the user */
3338 +static void bcm_rx_starttimer(struct bcm_op *op)
3340 + if (op->flags & RX_NO_AUTOTIMER)
3343 + if (op->j_ival1) {
3345 + op->timer.expires = jiffies + op->j_ival1;
3347 + DBG("adding rx timeout timer ival1. func=%p data=%p "
3349 + op->timer.function,
3350 + (char*) op->timer.data,
3351 + (unsigned int) op->timer.expires);
3353 + add_timer(&op->timer);
3358 +static void bcm_rx_changed(struct bcm_op *op, struct can_frame *data)
3360 + struct bcm_msg_head head;
3362 + op->j_lastmsg = jiffies;
3363 + op->frames_filtered++; /* statistics */
3365 + if (op->frames_filtered > ULONG_MAX/100)
3366 + op->frames_filtered = op->frames_abs = 0; /* restart */
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");
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;
3380 + bcm_send_to_user(op, &head, data, &op->rx_stamp);
3384 +static void bcm_rx_timeout_handler(unsigned long data)
3386 + struct bcm_op *op = (struct bcm_op*)data;
3387 + struct bcm_msg_head msg_head;
3389 + DBG("sending RX_TIMEOUT for can_id %03X. op is %p\n", op->can_id, op);
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;
3399 + bcm_send_to_user(op, &msg_head, NULL, NULL);
3401 + /* no restart of the timer is done here! */
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");
3412 +static void bcm_rx_thr_handler(unsigned long data)
3414 + struct bcm_op *op = (struct bcm_op*)data;
3417 + op->thrtimer.expires = 0; /* mark disabled / consumed timer */
3419 + if (op->nframes > 1){
3421 + DBG("sending MUX RX_CHANGED for can_id %03X. op is %p\n",
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]);
3433 + DBG("sending simple RX_CHANGED for can_id %03X. op is %p\n",
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]);
3443 +static void bcm_send_to_user(struct bcm_op *op, struct bcm_msg_head *head,
3444 + struct can_frame *frames, struct timeval *tv)
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;
3453 + skb = alloc_skb(sizeof(*head) + datalen,
3454 + in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
3458 + memcpy(skb_put(skb, sizeof(*head)), head, sizeof(*head));
3459 + /* can_frames starting here */
3460 + firstframe = (struct can_frame *) skb->tail;
3463 + skb_set_timestamp(skb, tv); /* restore timestamp */
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;
3471 + if (head->nframes){
3472 + memcpy(skb_put(skb, datalen), frames, datalen);
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;
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);
3485 + bo->dropped_usr_msgs++; /* don't care about overflows */
3489 +/**************************************************/
3490 +/* bcm_op handling: find & delete bcm_op elements */
3491 +/**************************************************/
3493 +static struct bcm_op *bcm_find_op(struct list_head *ops, canid_t can_id,
3496 + struct bcm_op *op;
3498 + list_for_each_entry(op, ops, list)
3499 + if ((op->can_id == can_id) && (op->ifindex == ifindex))
3505 +static int bcm_delete_rx_op(struct list_head *ops, canid_t can_id, int ifindex)
3507 + struct bcm_op *op, *n;
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",
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);
3521 + can_rx_unregister(dev, op->can_id,
3522 + REGMASK(op->can_id),
3523 + bcm_rx_handler, op);
3527 + can_rx_unregister(NULL, op->can_id,
3528 + REGMASK(op->can_id),
3529 + bcm_rx_handler, op);
3531 + list_del(&op->list);
3532 + bcm_remove_op(op);
3533 + return 1; /* done */
3537 + return 0; /* not found */
3540 +static int bcm_delete_tx_op(struct list_head *ops, canid_t can_id, int ifindex)
3542 + struct bcm_op *op, *n;
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",
3548 + list_del(&op->list);
3549 + bcm_remove_op(op);
3550 + return 1; /* done */
3554 + return 0; /* not found */
3557 +static void bcm_remove_op(struct bcm_op *op)
3559 + del_timer(&op->timer);
3560 + del_timer(&op->thrtimer);
3562 + kfree(op->frames);
3563 + if (op->last_frames)
3564 + kfree(op->last_frames);
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
3577 +# Controller Area Network (CAN) network layer core configuration
3582 + tristate "CAN bus subsystem support"
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/>.
3590 + If you want CAN support, you should say Y here and also to the
3591 + specific driver for your controller(s) below.
3593 + This CAN support can also be built as a module. If so, the module
3594 + will be called can.ko.
3597 + tristate "Raw CAN Protocol (raw access with CAN-ID filtering)"
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.
3607 +config CAN_RAW_USER
3608 + bool "Allow non-root users to access Raw CAN Protocol sockets"
3609 + depends on CAN_RAW
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.
3616 + tristate "Broadcast Manager CAN Protocol (with content filtering)"
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.
3628 +config CAN_BCM_USER
3629 + bool "Allow non-root users to access CAN broadcast manager sockets"
3630 + depends on CAN_BCM
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.
3636 +config CAN_DEBUG_CORE
3637 + bool "CAN Core debugging messages"
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.
3645 +source "drivers/net/can/Kconfig"
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
3652 +# Makefile for the Linux Controller Area Network core.
3655 +obj-$(CONFIG_CAN) += can.o
3656 +can-objs := af_can.o proc.o
3658 +obj-$(CONFIG_CAN_RAW) += can-raw.o
3659 +can-raw-objs := raw.o
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
3668 + * proc.c - procfs support for Protocol family CAN core module
3670 + * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
3671 + * All rights reserved.
3673 + * Redistribution and use in source and binary forms, with or without
3674 + * modification, are permitted provided that the following conditions
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.
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.
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.
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
3707 + * Send feedback to <socketcan-users@lists.berlios.de>
3711 +#include <linux/module.h>
3712 +#include <linux/proc_fs.h>
3713 +#include <linux/list.h>
3714 +#include <linux/rcupdate.h>
3716 +#include <linux/can/core.h>
3717 +#include <linux/can/version.h>
3719 +#include "af_can.h"
3721 +RCSID("$Id: proc.c 177 2007-03-08 11:02:43Z hartkopp $");
3723 +/* proc filenames */
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"
3735 +static void can_init_stats(int caller);
3736 +static void can_stat_update(unsigned long data);
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);
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);
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;
3774 +struct timer_list stattimer; /* timer for statistics update */
3776 +struct s_stats stats; /* statistics */
3777 +struct s_pstats pstats;
3779 +extern struct hlist_head rx_dev_list; /* rx dispatcher structures */
3780 +extern int stats_timer; /* module parameter. default: on */
3782 +/**************************************************/
3783 +/* procfs init / remove */
3784 +/**************************************************/
3786 +void can_init_proc(void)
3791 + /* create /proc/can directory */
3792 + can_dir = proc_mkdir(CAN_PROC_DIR, NULL);
3795 + printk(KERN_INFO "CAN: failed to create CAN_PROC_DIR. "
3796 + "CONFIG_PROC_FS missing?\n");
3800 + can_dir->owner = THIS_MODULE;
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);
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 */
3831 +void can_remove_proc(void)
3833 + /* procfs remove */
3835 + can_remove_proc_readentry(CAN_PROC_VERSION);
3838 + can_remove_proc_readentry(CAN_PROC_STATS);
3840 + if (pde_reset_stats)
3841 + can_remove_proc_readentry(CAN_PROC_RESET_STATS);
3843 + if (pde_rcvlist_all)
3844 + can_remove_proc_readentry(CAN_PROC_RCVLIST_ALL);
3846 + if (pde_rcvlist_fil)
3847 + can_remove_proc_readentry(CAN_PROC_RCVLIST_FIL);
3849 + if (pde_rcvlist_inv)
3850 + can_remove_proc_readentry(CAN_PROC_RCVLIST_INV);
3852 + if (pde_rcvlist_sff)
3853 + can_remove_proc_readentry(CAN_PROC_RCVLIST_SFF);
3855 + if (pde_rcvlist_eff)
3856 + can_remove_proc_readentry(CAN_PROC_RCVLIST_EFF);
3858 + if (pde_rcvlist_err)
3859 + can_remove_proc_readentry(CAN_PROC_RCVLIST_ERR);
3862 + remove_proc_entry(CAN_PROC_DIR, NULL);
3865 +/**************************************************/
3866 +/* proc read functions */
3867 +/**************************************************/
3869 +static int can_print_rcvlist(char *page, int len, struct hlist_head *rx_list,
3870 + struct net_device *dev)
3872 + struct receiver *r;
3873 + struct hlist_node *n;
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";
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);
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,
3895 + rcu_read_unlock();
3900 +static int can_print_recv_banner(char *page, int len)
3902 + /* can1. 00000000 00000000 00000000
3904 + len += snprintf(page + len, PAGE_SIZE - len,
3905 + " device can_id can_mask function"
3906 + " userdata matches ident\n");
3911 +static int can_proc_read_stats(char *page, char **start, off_t off,
3912 + int count, int *eof, void *data)
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);
3924 + len += snprintf(page + len, PAGE_SIZE - len, "\n");
3926 + len += snprintf(page + len, PAGE_SIZE - len,
3927 + " %8ld %% total match ratio (RXMR)\n",
3928 + stats.total_rx_match_ratio);
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);
3937 + len += snprintf(page + len, PAGE_SIZE - len, "\n");
3939 + len += snprintf(page + len, PAGE_SIZE - len,
3940 + " %8ld %% current match ratio (CRXMR)\n",
3941 + stats.current_rx_match_ratio);
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);
3950 + len += snprintf(page + len, PAGE_SIZE - len, "\n");
3952 + len += snprintf(page + len, PAGE_SIZE - len,
3953 + " %8ld %% max match ratio (MRXMR)\n",
3954 + stats.max_rx_match_ratio);
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);
3963 + len += snprintf(page + len, PAGE_SIZE - len, "\n");
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);
3972 + if (pstats.stats_reset)
3973 + len += snprintf(page + len, PAGE_SIZE - len,
3974 + "\n %8ld statistic resets (STR)\n",
3975 + pstats.stats_reset);
3977 + len += snprintf(page + len, PAGE_SIZE - len, "\n");
3983 +static int can_proc_read_reset_stats(char *page, char **start, off_t off,
3984 + int count, int *eof, void *data)
3988 + can_init_stats(1);
3990 + len += snprintf(page + len, PAGE_SIZE - len,
3991 + "CAN statistic reset #%ld done.\n",
3992 + pstats.stats_reset);
3998 +static int can_proc_read_version(char *page, char **start, off_t off,
3999 + int count, int *eof, void *data)
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);
4010 +static int can_proc_read_rcvlist_all(char *page, char **start, off_t off,
4011 + int count, int *eof, void *data)
4014 + struct dev_rcv_lists *d;
4015 + struct hlist_node *n;
4018 + len += snprintf(page + len, PAGE_SIZE - len,
4019 + "\nreceive list 'rx_all':\n");
4021 + /* find receive list for this device */
4023 + hlist_for_each_entry_rcu(d, n, &rx_dev_list, list) {
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);
4029 + len += snprintf(page + len, PAGE_SIZE - len,
4030 + " (%s: no entry)\n", DNAME(d->dev));
4032 + if (len > PAGE_SIZE - 100)
4033 + break; /* exit on end of buffer */
4035 + rcu_read_unlock();
4037 + len += snprintf(page + len, PAGE_SIZE - len, "\n");
4043 +static int can_proc_read_rcvlist_fil(char *page, char **start, off_t off,
4044 + int count, int *eof, void *data)
4047 + struct dev_rcv_lists *d;
4048 + struct hlist_node *n;
4051 + len += snprintf(page + len, PAGE_SIZE - len,
4052 + "\nreceive list 'rx_fil':\n");
4054 + /* find receive list for this device */
4056 + hlist_for_each_entry_rcu(d, n, &rx_dev_list, list) {
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);
4062 + len += snprintf(page + len, PAGE_SIZE - len,
4063 + " (%s: no entry)\n", DNAME(d->dev));
4065 + if (len > PAGE_SIZE - 100)
4066 + break; /* exit on end of buffer */
4068 + rcu_read_unlock();
4070 + len += snprintf(page + len, PAGE_SIZE - len, "\n");
4076 +static int can_proc_read_rcvlist_inv(char *page, char **start, off_t off,
4077 + int count, int *eof, void *data)
4080 + struct dev_rcv_lists *d;
4081 + struct hlist_node *n;
4084 + len += snprintf(page + len, PAGE_SIZE - len,
4085 + "\nreceive list 'rx_inv':\n");
4087 + /* find receive list for this device */
4089 + hlist_for_each_entry_rcu(d, n, &rx_dev_list, list) {
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);
4095 + len += snprintf(page + len, PAGE_SIZE - len,
4096 + " (%s: no entry)\n", DNAME(d->dev));
4098 + if (len > PAGE_SIZE - 100)
4099 + break; /* exit on end of buffer */
4101 + rcu_read_unlock();
4103 + len += snprintf(page + len, PAGE_SIZE - len, "\n");
4109 +static int can_proc_read_rcvlist_sff(char *page, char **start, off_t off,
4110 + int count, int *eof, void *data)
4113 + struct dev_rcv_lists *d;
4114 + struct hlist_node *n;
4117 + len += snprintf(page + len, PAGE_SIZE - len,
4118 + "\nreceive list 'rx_sff':\n");
4120 + /* find receive list for this device */
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])) {
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,
4141 + len += snprintf(page + len, PAGE_SIZE - len,
4142 + " (%s: no entry)\n", DNAME(d->dev));
4144 + if (len > PAGE_SIZE - 100)
4145 + break; /* exit on end of buffer */
4147 + rcu_read_unlock();
4149 + len += snprintf(page + len, PAGE_SIZE - len, "\n");
4155 +static int can_proc_read_rcvlist_eff(char *page, char **start, off_t off,
4156 + int count, int *eof, void *data)
4159 + struct dev_rcv_lists *d;
4160 + struct hlist_node *n;
4163 + len += snprintf(page + len, PAGE_SIZE - len,
4164 + "\nreceive list 'rx_eff':\n");
4166 + /* find receive list for this device */
4168 + hlist_for_each_entry_rcu(d, n, &rx_dev_list, list) {
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);
4174 + len += snprintf(page + len, PAGE_SIZE - len,
4175 + " (%s: no entry)\n", DNAME(d->dev));
4177 + if (len > PAGE_SIZE - 100)
4178 + break; /* exit on end of buffer */
4180 + rcu_read_unlock();
4182 + len += snprintf(page + len, PAGE_SIZE - len, "\n");
4188 +static int can_proc_read_rcvlist_err(char *page, char **start, off_t off,
4189 + int count, int *eof, void *data)
4192 + struct dev_rcv_lists *d;
4193 + struct hlist_node *n;
4196 + len += snprintf(page + len, PAGE_SIZE - len,
4197 + "\nreceive list 'rx_err':\n");
4199 + /* find receive list for this device */
4201 + hlist_for_each_entry_rcu(d, n, &rx_dev_list, list) {
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);
4207 + len += snprintf(page + len, PAGE_SIZE - len,
4208 + " (%s: no entry)\n", DNAME(d->dev));
4210 + if (len > PAGE_SIZE - 100)
4211 + break; /* exit on end of buffer */
4213 + rcu_read_unlock();
4215 + len += snprintf(page + len, PAGE_SIZE - len, "\n");
4221 +/**************************************************/
4222 +/* proc utility functions */
4223 +/**************************************************/
4225 +static struct proc_dir_entry *can_create_proc_readentry(const char *name,
4227 + read_proc_t* read_proc,
4231 + return create_proc_read_entry(name, mode, can_dir, read_proc,
4237 +static void can_remove_proc_readentry(const char *name)
4240 + remove_proc_entry(name, can_dir);
4243 +static unsigned long calc_rate(unsigned long oldjif, unsigned long newjif,
4244 + unsigned long count)
4246 + unsigned long ret = 0;
4248 + if (oldjif == newjif)
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",
4258 + ret = (count * HZ) / (newjif - oldjif);
4263 +/**************************************************/
4264 +/* af_can statistics stuff */
4265 +/**************************************************/
4267 +static void can_init_stats(int caller)
4269 + memset(&stats, 0, sizeof(stats));
4270 + stats.jiffies_init = jiffies;
4271 + pstats.stats_reset++;
4274 +static void can_stat_update(unsigned long data)
4276 + unsigned long j = jiffies; /* snapshot */
4278 + //DBG("CAN: can_stat_update() jiffies = %ld\n", j);
4280 + if (j < stats.jiffies_init) /* jiffies overflow */
4281 + can_init_stats(2);
4283 + /* stats.rx_frames is the definitively max. statistic value */
4285 + /* prevent overflow in calc_rate() */
4286 + if (stats.rx_frames > (ULONG_MAX / HZ))
4287 + can_init_stats(3); /* restart */
4289 + /* matches overflow - very improbable */
4290 + if (stats.matches > (ULONG_MAX / 100))
4291 + can_init_stats(4);
4293 + /* calc total values */
4294 + if (stats.rx_frames)
4295 + stats.total_rx_match_ratio = (stats.matches * 100) /
4298 + stats.total_tx_rate = calc_rate(stats.jiffies_init, j,
4300 + stats.total_rx_rate = calc_rate(stats.jiffies_init, j,
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;
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);
4311 + /* check / update maximum values */
4312 + if (stats.max_tx_rate < stats.current_tx_rate)
4313 + stats.max_tx_rate = stats.current_tx_rate;
4315 + if (stats.max_rx_rate < stats.current_rx_rate)
4316 + stats.max_rx_rate = stats.current_rx_rate;
4318 + if (stats.max_rx_match_ratio < stats.current_rx_match_ratio)
4319 + stats.max_rx_match_ratio = stats.current_rx_match_ratio;
4321 + /* clear values for 'current rate' calculation */
4322 + stats.tx_frames_delta = 0;
4323 + stats.rx_frames_delta = 0;
4324 + stats.matches_delta = 0;
4326 + /* restart timer */
4327 + stattimer.expires = jiffies + HZ; /* every second */
4328 + add_timer(&stattimer);
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
4335 + * raw.c - Raw sockets for protocol family CAN
4337 + * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
4338 + * All rights reserved.
4340 + * Redistribution and use in source and binary forms, with or without
4341 + * modification, are permitted provided that the following conditions
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.
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.
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.
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
4374 + * Send feedback to <socketcan-users@lists.berlios.de>
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>
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>
4394 +RCSID("$Id: raw.c 177 2007-03-08 11:02:43Z hartkopp $");
4396 +#define IDENT "raw"
4397 +static __initdata const char banner[] = KERN_INFO "CAN: raw socket protocol"
4400 +MODULE_DESCRIPTION("PF_CAN raw sockets");
4401 +MODULE_LICENSE("Dual BSD/GPL");
4402 +MODULE_AUTHOR("Urs Thuermann <urs.thuermann@volkswagen.de>");
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)
4412 +#define DBG(args...)
4413 +#define DBG_SKB(skb)
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);
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);
4438 +static struct proto_ops raw_ops = {
4440 + .release = raw_release,
4442 + .connect = sock_no_connect,
4443 + .socketpair = sock_no_socketpair,
4444 + .accept = sock_no_accept,
4445 + .getname = raw_getname,
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,
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.
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;
4479 +#ifdef CONFIG_CAN_RAW_USER
4480 +#define RAW_CAP (-1)
4482 +#define RAW_CAP CAP_NET_RAW
4485 +#undef CAN_RAW_SUPPORT_REBIND /* use bind on already bound socket */
4487 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,13)
4490 + struct raw_opt opt;
4493 +#define raw_sk(sk) (&((struct raw_sock *)(sk))->opt)
4495 +static struct proto raw_proto = {
4496 + .name = "CAN_RAW",
4497 + .owner = THIS_MODULE,
4498 + .obj_size = sizeof(struct raw_sock),
4502 +static struct can_proto raw_can_proto = {
4504 + .protocol = CAN_RAW,
4505 + .capability = RAW_CAP,
4507 + .prot = &raw_proto,
4510 +#define raw_sk(sk) ((struct raw_opt *)(sk)->sk_protinfo)
4512 +static struct can_proto raw_can_proto = {
4514 + .protocol = CAN_RAW,
4515 + .capability = RAW_CAP,
4517 + .owner = THIS_MODULE,
4518 + .obj_size = sizeof(struct raw_opt),
4525 +static __init int raw_module_init(void)
4529 + can_proto_register(&raw_can_proto);
4533 +static __exit void raw_module_exit(void)
4535 + can_proto_unregister(&raw_can_proto);
4538 +static int raw_init(struct sock *sk)
4540 + struct raw_opt *ro = raw_sk(sk);
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;
4550 + /* set default loopback behaviour */
4552 + ro->recv_own_msgs = 0;
4557 +static int raw_release(struct socket *sock)
4559 + struct sock *sk = sock->sk;
4560 + struct raw_opt *ro = raw_sk(sk);
4561 + struct net_device *dev = NULL;
4563 + DBG("socket %p, sk %p, refcnt %d\n", sock, sk,
4564 + atomic_read(&sk->sk_refcnt));
4566 + if (ro->bound && ro->ifindex)
4567 + dev = dev_get_by_index(ro->ifindex);
4569 + /* remove current filters & unregister */
4571 + raw_remove_filters(dev, sk);
4572 + if (ro->count > 1)
4573 + kfree(ro->filter);
4575 + /* remove current error mask */
4576 + if (ro->err_mask && ro->bound)
4577 + can_rx_unregister(dev, 0, ro->err_mask | CAN_ERR_FLAG,
4581 + can_dev_unregister(dev, raw_notifier, sk);
4590 +static int raw_bind(struct socket *sock, struct sockaddr *uaddr, int len)
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;
4597 + DBG("socket %p to device %d\n", sock, addr->can_ifindex);
4599 + if (len < sizeof(*addr))
4603 +#ifdef CAN_RAW_SUPPORT_REBIND
4604 + /* remove current bindings / notifier */
4605 + if (ro->ifindex) {
4606 + dev = dev_get_by_index(ro->ifindex);
4608 + DBG("could not find device %d\n",
4609 + addr->can_ifindex);
4612 + if (!(dev->flags & IFF_UP)) {
4613 + sk->sk_err = ENETDOWN;
4614 + if (!sock_flag(sk, SOCK_DEAD))
4615 + sk->sk_error_report(sk);
4618 + can_dev_unregister(dev, raw_notifier, sk);
4622 + /* unregister current filters for this device */
4623 + raw_remove_filters(dev, sk);
4634 + if (addr->can_ifindex) {
4635 + dev = dev_get_by_index(addr->can_ifindex);
4637 + DBG("could not find device %d\n", addr->can_ifindex);
4640 + if (!(dev->flags & IFF_UP)) {
4641 + sk->sk_err = ENETDOWN;
4642 + if (!sock_flag(sk, SOCK_DEAD))
4643 + sk->sk_error_report(sk);
4646 + can_dev_register(dev, raw_notifier, sk);
4650 + ro->ifindex = addr->can_ifindex;
4652 + raw_add_filters(dev, sk); /* filters set by default/setsockopt */
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);
4667 +static int raw_getname(struct socket *sock, struct sockaddr *uaddr,
4668 + int *len, int peer)
4670 + struct sockaddr_can *addr = (struct sockaddr_can *)uaddr;
4671 + struct sock *sk = sock->sk;
4672 + struct raw_opt *ro = raw_sk(sk);
4675 + return -EOPNOTSUPP;
4677 + addr->can_family = AF_CAN;
4678 + addr->can_ifindex = ro->ifindex;
4679 + *len = sizeof(*addr);
4684 +static unsigned int raw_poll(struct file *file, struct socket *sock,
4687 + unsigned int mask = 0;
4689 + DBG("socket %p\n", sock);
4691 + mask = datagram_poll(file, sock, wait);
4695 +static int raw_setsockopt(struct socket *sock, int level, int optname,
4696 + char __user *optval, int optlen)
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;
4707 + if (level != SOL_CAN_RAW)
4710 + switch (optname) {
4711 + case CAN_RAW_FILTER:
4712 + if (optlen % sizeof(struct can_filter) != 0)
4715 + count = optlen / sizeof(struct can_filter);
4717 + if (count > 1) { /* does not fit into dfilter */
4718 + if (!(filter = kmalloc(optlen, GFP_KERNEL)))
4720 + if ((err = copy_from_user(filter, optval, optlen))) {
4724 + } else if (count == 1) {
4725 + if ((err = copy_from_user(&sfilter, optval, optlen)))
4729 + if (ro->bound && ro->ifindex)
4730 + dev = dev_get_by_index(ro->ifindex);
4732 + /* remove current filters & unregister */
4734 + raw_remove_filters(dev, sk);
4735 + if (ro->count > 1)
4736 + kfree(ro->filter);
4738 + if (count == 1) { /* copy data for single filter */
4739 + ro->dfilter = sfilter;
4740 + filter = &ro->dfilter;
4743 + /* add new filters & register */
4744 + ro->filter = filter;
4745 + ro->count = count;
4747 + raw_add_filters(dev, sk);
4754 + case CAN_RAW_ERR_FILTER:
4755 + if (optlen != sizeof(err_mask))
4757 + if ((err = copy_from_user(&err_mask, optval, optlen)))
4760 + err_mask &= CAN_ERR_MASK;
4762 + if (ro->bound && ro->ifindex)
4763 + dev = dev_get_by_index(ro->ifindex);
4765 + /* remove current error mask */
4766 + if (ro->err_mask && ro->bound)
4767 + can_rx_unregister(dev, 0, ro->err_mask | CAN_ERR_FLAG,
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);
4781 + case CAN_RAW_LOOPBACK:
4782 + if (optlen != sizeof(ro->loopback))
4784 + if ((err = copy_from_user(&ro->loopback, optval, optlen)))
4788 + case CAN_RAW_RECV_OWN_MSGS:
4789 + if (optlen != sizeof(ro->recv_own_msgs))
4791 + if ((err = copy_from_user(&ro->recv_own_msgs, optval, optlen)))
4796 + return -ENOPROTOOPT;
4801 +static int raw_getsockopt(struct socket *sock, int level, int optname,
4802 + char __user *optval, int __user *optlen)
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;
4810 + if (level != SOL_CAN_RAW)
4813 + switch (optname) {
4814 + case CAN_RAW_FILTER:
4815 + if (get_user(len, optlen))
4818 + if (count && filter) {
4819 + int filter_size = count * sizeof(struct can_filter);
4820 + if (len < filter_size)
4822 + if (len > filter_size)
4823 + len = filter_size;
4824 + if (copy_to_user(optval, filter, len))
4829 + if (put_user(len, optlen))
4834 + case CAN_RAW_ERR_FILTER:
4835 + if (get_user(len, optlen))
4838 + if (len < sizeof(can_err_mask_t))
4841 + if (len > sizeof(can_err_mask_t))
4842 + len = sizeof(can_err_mask_t);
4844 + if (copy_to_user(optval, &ro->err_mask, len))
4847 + if (put_user(len, optlen))
4852 + case CAN_RAW_LOOPBACK:
4853 + if (get_user(len, optlen))
4856 + if (len < sizeof(int))
4859 + if (len > sizeof(int))
4860 + len = sizeof(int);
4862 + if (copy_to_user(optval, &ro->loopback, len))
4865 + if (put_user(len, optlen))
4870 + case CAN_RAW_RECV_OWN_MSGS:
4871 + if (get_user(len, optlen))
4874 + if (len < sizeof(int))
4877 + if (len > sizeof(int))
4878 + len = sizeof(int);
4880 + if (copy_to_user(optval, &ro->recv_own_msgs, len))
4883 + if (put_user(len, optlen))
4889 + return -ENOPROTOOPT;
4894 +static void raw_add_filters(struct net_device *dev, struct sock *sk)
4896 + struct raw_opt *ro = raw_sk(sk);
4897 + struct can_filter *filter = ro->filter;
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);
4909 +static void raw_remove_filters(struct net_device *dev, struct sock *sk)
4911 + struct raw_opt *ro = raw_sk(sk);
4912 + struct can_filter *filter = ro->filter;
4915 + for (i = 0; i < ro->count; i++) {
4916 + can_rx_unregister(dev, filter[i].can_id, filter[i].can_mask,
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);
4924 +static int raw_sendmsg(struct kiocb *iocb, struct socket *sock,
4925 + struct msghdr *msg, size_t size)
4927 + struct sock *sk = sock->sk;
4928 + struct raw_opt *ro = raw_sk(sk);
4929 + struct sk_buff *skb;
4930 + struct net_device *dev;
4934 + DBG("socket %p, sk %p\n", sock, sk);
4936 + if (msg->msg_name) {
4937 + struct sockaddr_can *addr =
4938 + (struct sockaddr_can *)msg->msg_name;
4939 + if (addr->can_family != AF_CAN)
4941 + ifindex = addr->can_ifindex;
4943 + ifindex = ro->ifindex;
4945 + if (!(dev = dev_get_by_index(ifindex))) {
4946 + DBG("device %d not found\n", ifindex);
4950 + if (!(skb = alloc_skb(size, GFP_KERNEL))) {
4955 + if ((err = memcpy_fromiovec(skb_put(skb, size),
4956 + msg->msg_iov, size)) < 0) {
4964 + DBG("sending skbuff to interface %d\n", ifindex);
4967 + err = can_send(skb, ro->loopback);
4977 +static int raw_recvmsg(struct kiocb *iocb, struct socket *sock,
4978 + struct msghdr *msg, size_t size, int flags)
4980 + struct sock *sk = sock->sk;
4981 + struct sk_buff *skb;
4985 + DBG("socket %p, sk %p\n", sock, sk);
4987 + noblock = flags & MSG_DONTWAIT;
4988 + flags &= ~MSG_DONTWAIT;
4990 + if (!(skb = skb_recv_datagram(sk, flags, noblock, &error)))
4993 + DBG("delivering skbuff %p\n", skb);
4996 + if (size < skb->len)
4997 + msg->msg_flags |= MSG_TRUNC;
5001 + if ((error = memcpy_toiovec(msg->msg_iov, skb->data, size)) < 0) {
5002 + skb_free_datagram(sk, skb);
5006 + sock_recv_timestamp(msg, sk, skb);
5008 + if (msg->msg_name) {
5009 + msg->msg_namelen = sizeof(struct sockaddr_can);
5010 + memcpy(msg->msg_name, skb->cb, msg->msg_namelen);
5013 + DBG("freeing sock %p, skbuff %p\n", sk, skb);
5014 + skb_free_datagram(sk, skb);
5019 +static void raw_rcv(struct sk_buff *skb, void *data)
5021 + struct sock *sk = (struct sock*)data;
5022 + struct raw_opt *ro = raw_sk(sk);
5023 + struct sockaddr_can *addr;
5026 + DBG("received skbuff %p, sk %p\n", skb, sk);
5029 + if (!ro->recv_own_msgs) {
5030 + if (*(struct sock **)skb->cb == sk) { /* tx sock reference */
5031 + DBG("trashed own tx msg\n");
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;
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);
5049 +static void raw_notifier(unsigned long msg, void *data)
5051 + struct sock *sk = (struct sock *)data;
5052 + struct raw_opt *ro = raw_sk(sk);
5054 + DBG("called for sock %p\n", sk);
5057 + case NETDEV_UNREGISTER:
5062 + sk->sk_err = ENETDOWN;
5063 + if (!sock_flag(sk, SOCK_DEAD))
5064 + sk->sk_error_report(sk);
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;
5079 + /* more non ipv6 compatible dev types to skip here? */
5080 + if (dev->type == ARPHRD_CAN)
5084 case NETDEV_REGISTER:
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
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
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/