2 * af_can.c - Protocol family CAN core module
3 * (used by different CAN protocol modules)
5 * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions, the following disclaimer and
13 * the referenced file 'COPYING'.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of Volkswagen nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * Alternatively, provided that this notice is retained in full, this
22 * software may be distributed under the terms of the GNU General
23 * Public License ("GPL") version 2 as distributed in the 'COPYING'
24 * file from the main directory of the linux kernel source.
26 * The provided data structures and external interfaces from this code
27 * are not restricted to be used by modules with a GPL compatible license.
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
42 * Send feedback to <socketcan-users@lists.berlios.de>
46 #include <linux/autoconf.h>
47 #include <linux/module.h>
48 #include <linux/version.h>
49 #include <linux/slab.h>
50 #include <linux/kmod.h>
51 #include <linux/init.h>
52 #include <linux/list.h>
53 #include <linux/spinlock.h>
54 #include <linux/rcupdate.h>
55 #include <linux/socket.h>
56 #include <linux/if_ether.h>
57 #include <linux/if_arp.h>
58 #include <linux/skbuff.h>
59 #include <linux/net.h>
60 #include <linux/netdevice.h>
62 #include <asm/uaccess.h>
64 #include <linux/can.h>
65 #include <linux/can/version.h>
72 #define IDENT "af_can"
73 static __initdata const char banner[] = KERN_INFO "CAN: Controller Area "
74 "Network PF_CAN core " VERSION "\n";
76 MODULE_DESCRIPTION("Controller Area Network PF_CAN core");
77 MODULE_LICENSE("Dual BSD/GPL");
78 MODULE_AUTHOR("Urs Thuermann <urs.thuermann@volkswagen.de>, "
79 "Oliver Hartkopp <oliver.hartkopp@volkswagen.de>");
81 int stats_timer = 1; /* default: on */
82 module_param(stats_timer, int, S_IRUGO);
84 #ifdef CONFIG_CAN_DEBUG_CORE
86 module_param(debug, int, S_IRUGO);
87 #define DBG(args...) (debug & 1 ? \
88 (printk(KERN_DEBUG "CAN %s: ", __func__), \
90 #define DBG_FRAME(args...) (debug & 2 ? can_debug_cframe(args) : 0)
91 #define DBG_SKB(skb) (debug & 4 ? can_debug_skb(skb) : 0)
94 #define DBG_FRAME(args...)
98 static __init int can_init(void);
99 static __exit void can_exit(void);
101 static int can_create(struct socket *sock, int protocol);
102 static int can_notifier(struct notifier_block *nb,
103 unsigned long msg, void *data);
104 static int can_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg);
105 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,14)
106 static int can_rcv(struct sk_buff *skb, struct net_device *dev,
107 struct packet_type *pt, struct net_device *orig_dev);
109 static int can_rcv(struct sk_buff *skb, struct net_device *dev,
110 struct packet_type *pt);
112 static int can_rcv_filter(struct dev_rcv_lists *d, struct sk_buff *skb);
113 static struct dev_rcv_lists *find_dev_rcv_lists(struct net_device *dev);
114 static struct hlist_head *find_rcv_list(canid_t *can_id, canid_t *mask,
115 struct dev_rcv_lists *d);
116 static void can_rcv_lists_delete(struct rcu_head *rp);
117 static void can_rx_delete(struct rcu_head *rp);
118 static void can_rx_delete_all(struct hlist_head *rl);
122 struct list_head list;
123 struct net_device *dev;
124 void (*func)(unsigned long msg, void *data);
128 static LIST_HEAD(notifier_list);
129 static rwlock_t notifier_lock = RW_LOCK_UNLOCKED;
131 HLIST_HEAD(rx_dev_list);
132 static struct dev_rcv_lists rx_alldev_list;
133 static spinlock_t rcv_lists_lock = SPIN_LOCK_UNLOCKED;
135 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
136 static struct kmem_cache *rcv_cache __read_mostly;
138 static kmem_cache_t *rcv_cache;
141 static struct packet_type can_packet = {
142 .type = __constant_htons(ETH_P_CAN),
147 static struct net_proto_family can_family_ops = {
149 .create = can_create,
150 .owner = THIS_MODULE,
153 /* notifier block for netdevice event */
154 static struct notifier_block can_netdev_notifier = {
155 .notifier_call = can_notifier,
158 /* table of registered CAN protocols */
159 static struct can_proto *proto_tab[CAN_NPROTO];
161 extern struct timer_list stattimer; /* timer for statistics update */
162 extern struct s_stats stats; /* packet statistics */
163 extern struct s_pstats pstats; /* receive list statistics */
165 module_init(can_init);
166 module_exit(can_exit);
168 /**************************************************/
169 /* af_can module init/exit functions */
170 /**************************************************/
172 static __init int can_init(void)
176 rcv_cache = kmem_cache_create("can_receiver", sizeof(struct receiver),
181 /* Insert struct dev_rcv_lists for reception on all devices.
182 This struct is zero initialized which is correct for the
183 embedded hlist heads, the dev pointer, and the entries counter.
186 spin_lock_bh(&rcv_lists_lock);
187 hlist_add_head_rcu(&rx_alldev_list.list, &rx_dev_list);
188 spin_unlock_bh(&rcv_lists_lock);
191 /* statistics init */
192 init_timer(&stattimer);
198 /* protocol register */
199 sock_register(&can_family_ops);
200 register_netdevice_notifier(&can_netdev_notifier);
201 dev_add_pack(&can_packet);
206 static __exit void can_exit(void)
208 struct dev_rcv_lists *d;
209 struct hlist_node *n, *next;
212 /* stop statistics timer */
213 del_timer(&stattimer);
219 /* protocol unregister */
220 dev_remove_pack(&can_packet);
221 unregister_netdevice_notifier(&can_netdev_notifier);
222 sock_unregister(PF_CAN);
224 /* remove rx_dev_list */
225 spin_lock_bh(&rcv_lists_lock);
226 hlist_del(&rx_alldev_list.list);
227 hlist_for_each_entry_safe(d, n, next, &rx_dev_list, list) {
231 spin_unlock_bh(&rcv_lists_lock);
233 kmem_cache_destroy(rcv_cache);
236 /**************************************************/
237 /* af_can protocol functions */
238 /**************************************************/
240 void can_proto_register(struct can_proto *cp)
242 int proto = cp->protocol;
243 if (proto < 0 || proto >= CAN_NPROTO) {
244 printk(KERN_ERR "CAN: protocol number %d out "
245 "of range\n", proto);
248 if (proto_tab[proto]) {
249 printk(KERN_ERR "CAN: protocol %d already "
250 "registered\n", proto);
254 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,13)
255 if (proto_register(cp->prot, 0) != 0) {
259 proto_tab[proto] = cp;
261 /* use generic ioctl function if the module doesn't bring its own */
263 cp->ops->ioctl = can_ioctl;
266 void can_proto_unregister(struct can_proto *cp)
268 int proto = cp->protocol;
269 if (!proto_tab[proto]) {
270 printk(KERN_ERR "CAN: protocol %d is not registered\n", proto);
273 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,13)
274 proto_unregister(cp->prot);
276 proto_tab[proto] = NULL;
279 void can_dev_register(struct net_device *dev,
280 void (*func)(unsigned long msg, void *), void *data)
284 DBG("called for %s\n", dev->name);
286 if (!(n = kmalloc(sizeof(*n), GFP_KERNEL)))
293 write_lock(¬ifier_lock);
294 list_add(&n->list, ¬ifier_list);
295 write_unlock(¬ifier_lock);
298 void can_dev_unregister(struct net_device *dev,
299 void (*func)(unsigned long msg, void *), void *data)
301 struct notifier *n, *next;
303 DBG("called for %s\n", dev->name);
305 write_lock(¬ifier_lock);
306 list_for_each_entry_safe(n, next, ¬ifier_list, list) {
307 if (n->dev == dev && n->func == func && n->data == data) {
313 write_unlock(¬ifier_lock);
316 /**************************************************/
317 /* af_can socket functions */
318 /**************************************************/
320 static void can_sock_destruct(struct sock *sk)
322 DBG("called for sock %p\n", sk);
324 skb_queue_purge(&sk->sk_receive_queue);
326 kfree(sk->sk_protinfo);
329 static int can_create(struct socket *sock, int protocol)
332 struct can_proto *cp;
335 DBG("socket %p, type %d, proto %d\n", sock, sock->type, protocol);
337 sock->state = SS_UNCONNECTED;
339 if (protocol < 0 || protocol >= CAN_NPROTO)
342 DBG("looking up proto %d in proto_tab[]\n", protocol);
344 /* try to load protocol module, when CONFIG_KMOD is defined */
345 if (!proto_tab[protocol]) {
346 char module_name[30];
347 sprintf(module_name, "can-proto-%d", protocol);
348 if (request_module(module_name) == -ENOSYS)
349 printk(KERN_INFO "CAN: request_module(%s) not"
350 " implemented.\n", module_name);
353 /* check for success and correct type */
354 if (!(cp = proto_tab[protocol]) || cp->type != sock->type)
355 return -EPROTONOSUPPORT;
357 if (cp->capability >= 0 && !capable(cp->capability))
362 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,13)
363 sk = sk_alloc(PF_CAN, GFP_KERNEL, cp->prot, 1);
367 sk = sk_alloc(PF_CAN, GFP_KERNEL, 1, 0);
371 !(sk->sk_protinfo = kmalloc(cp->obj_size, GFP_KERNEL))) {
375 sk_set_owner(sk, proto_tab[protocol]->owner);
377 sock_init_data(sock, sk);
378 sk->sk_destruct = can_sock_destruct;
380 DBG("created sock: %p\n", sk);
383 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,13)
384 if (sk->sk_prot->init)
385 ret = sk->sk_prot->init(sk);
391 /* we must release sk */
403 static int can_notifier(struct notifier_block *nb,
404 unsigned long msg, void *data)
406 struct net_device *dev = (struct net_device *)data;
409 DBG("called for %s, msg = %lu\n", dev->name, msg);
411 if (dev->type != ARPHRD_CAN)
415 struct dev_rcv_lists *d;
418 case NETDEV_REGISTER:
420 /* create new dev_rcv_lists for this device */
422 DBG("creating new dev_rcv_lists for %s\n", dev->name);
423 if (!(d = kmalloc(sizeof(*d),
424 in_interrupt() ? GFP_ATOMIC : GFP_KERNEL))) {
425 printk(KERN_ERR "CAN: allocation of receive "
429 /* N.B. zeroing the struct is the correct initialization
430 for the embedded hlist_head structs.
431 Another list type, e.g. list_head, would require
432 explicit initialization. */
433 memset(d, 0, sizeof(*d));
436 spin_lock_bh(&rcv_lists_lock);
437 hlist_add_head_rcu(&d->list, &rx_dev_list);
438 spin_unlock_bh(&rcv_lists_lock);
442 case NETDEV_UNREGISTER:
443 spin_lock_bh(&rcv_lists_lock);
445 if (!(d = find_dev_rcv_lists(dev))) {
446 printk(KERN_ERR "CAN: notifier: receive list not "
447 "found for dev %s\n", dev->name);
451 hlist_del_rcu(&d->list);
453 /* remove all receivers hooked at this netdevice */
454 can_rx_delete_all(&d->rx_err);
455 can_rx_delete_all(&d->rx_all);
456 can_rx_delete_all(&d->rx_fil);
457 can_rx_delete_all(&d->rx_inv);
458 can_rx_delete_all(&d->rx_eff);
459 for (i = 0; i < 2048; i++)
460 can_rx_delete_all(&d->rx_sff[i]);
463 spin_unlock_bh(&rcv_lists_lock);
466 call_rcu(&d->rcu, can_rcv_lists_delete);
471 read_lock(¬ifier_lock);
472 list_for_each_entry(n, ¬ifier_list, list) {
474 n->func(msg, n->data);
476 read_unlock(¬ifier_lock);
481 static int can_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
483 struct sock *sk = sock->sk;
487 return sock_get_timestamp(sk, (struct timeval __user *)arg);
489 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
492 return dev_ioctl(cmd, (void __user *)arg);
498 /**************************************************/
500 /**************************************************/
502 int can_send(struct sk_buff *skb, int loop)
506 if (loop) { /* local loopback (default) */
507 *(struct sock **)skb->cb = skb->sk; /* tx sock reference */
509 /* interface not capabable to do the loopback itself? */
510 if (!(skb->dev->flags & IFF_LOOPBACK)) {
511 struct sk_buff *newskb = skb_clone(skb, GFP_ATOMIC);
512 newskb->protocol = htons(ETH_P_CAN);
513 newskb->ip_summed = CHECKSUM_UNNECESSARY;
514 netif_rx(newskb); /* perform local loopback here */
517 *(struct sock **)skb->cb = NULL; /* no loopback required */
519 if (!(skb->dev->flags & IFF_UP))
521 else if ((err = dev_queue_xmit(skb)) > 0) /* send to netdevice */
522 err = net_xmit_errno(err);
524 /* update statistics */
526 stats.tx_frames_delta++;
531 /**************************************************/
533 /**************************************************/
535 int can_rx_register(struct net_device *dev, canid_t can_id, canid_t mask,
536 void (*func)(struct sk_buff *, void *), void *data,
540 struct hlist_head *rl;
541 struct dev_rcv_lists *d;
544 /* insert new receiver (dev,canid,mask) -> (func,data) */
546 DBG("dev %p, id %03X, mask %03X, callback %p, data %p, ident %s\n",
547 dev, can_id, mask, func, data, ident);
549 if (!(r = kmem_cache_alloc(rcv_cache, GFP_KERNEL))) {
554 spin_lock_bh(&rcv_lists_lock);
556 if (!(d = find_dev_rcv_lists(dev))) {
557 DBG("receive list not found for dev %s, id %03X, mask %03X\n",
558 DNAME(dev), can_id, mask);
559 kmem_cache_free(rcv_cache, r);
564 rl = find_rcv_list(&can_id, &mask, d);
573 hlist_add_head_rcu(&r->list, rl);
576 pstats.rcv_entries++;
577 if (pstats.rcv_entries_max < pstats.rcv_entries)
578 pstats.rcv_entries_max = pstats.rcv_entries;
581 spin_unlock_bh(&rcv_lists_lock);
586 static void can_rcv_lists_delete(struct rcu_head *rp)
588 struct dev_rcv_lists *d = container_of(rp, struct dev_rcv_lists, rcu);
592 static void can_rx_delete(struct rcu_head *rp)
594 struct receiver *r = container_of(rp, struct receiver, rcu);
595 kmem_cache_free(rcv_cache, r);
598 static void can_rx_delete_all(struct hlist_head *rl)
601 struct hlist_node *n;
603 hlist_for_each_entry_rcu(r, n, rl, list) {
604 hlist_del_rcu(&r->list);
605 call_rcu(&r->rcu, can_rx_delete);
609 int can_rx_unregister(struct net_device *dev, canid_t can_id, canid_t mask,
610 void (*func)(struct sk_buff *, void *), void *data)
613 struct hlist_head *rl;
614 struct hlist_node *next;
615 struct dev_rcv_lists *d;
618 DBG("dev %p, id %03X, mask %03X, callback %p, data %p\n",
619 dev, can_id, mask, func, data);
623 spin_lock_bh(&rcv_lists_lock);
625 if (!(d = find_dev_rcv_lists(dev))) {
626 DBG("receive list not found for dev %s, id %03X, mask %03X\n",
627 DNAME(dev), can_id, mask);
632 rl = find_rcv_list(&can_id, &mask, d);
634 /* Search the receiver list for the item to delete. This should
635 * exist, since no receiver may be unregistered that hasn't
636 * been registered before.
639 hlist_for_each_entry(r, next, rl, list) {
640 if (r->can_id == can_id && r->mask == mask
641 && r->func == func && r->data == data)
645 /* Check for bug in CAN protocol implementations:
646 * If no matching list item was found, the list cursor variable next
647 * will be NULL, while r will point to the last item of the list.
651 DBG("receive list entry not found for "
652 "dev %s, id %03X, mask %03X\n", DNAME(dev), can_id, mask);
658 hlist_del_rcu(&r->list);
661 if (pstats.rcv_entries > 0)
662 pstats.rcv_entries--;
665 spin_unlock_bh(&rcv_lists_lock);
667 /* schedule the receiver item for deletion */
669 call_rcu(&r->rcu, can_rx_delete);
674 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,14)
675 static int can_rcv(struct sk_buff *skb, struct net_device *dev,
676 struct packet_type *pt, struct net_device *orig_dev)
678 static int can_rcv(struct sk_buff *skb, struct net_device *dev,
679 struct packet_type *pt)
682 struct dev_rcv_lists *d;
685 DBG("received skbuff on device %s, ptype %04x\n",
686 dev->name, ntohs(pt->type));
688 DBG_FRAME("af_can: can_rcv: received CAN frame",
689 (struct can_frame *)skb->data);
691 /* update statistics */
693 stats.rx_frames_delta++;
697 /* deliver the packet to sockets listening on all devices */
698 matches = can_rcv_filter(&rx_alldev_list, skb);
700 /* find receive list for this device */
701 if ((d = find_dev_rcv_lists(dev)))
702 matches += can_rcv_filter(d, skb);
706 /* free the skbuff allocated by the netdevice driver */
707 DBG("freeing skbuff %p\n", skb);
712 stats.matches_delta++;
719 static inline void deliver(struct sk_buff *skb, struct receiver *r)
721 struct sk_buff *clone = skb_clone(skb, GFP_ATOMIC);
722 DBG("skbuff %p cloned to %p\n", skb, clone);
724 r->func(clone, r->data);
725 r->matches++; /* update specific statistics */
729 static int can_rcv_filter(struct dev_rcv_lists *d, struct sk_buff *skb)
732 struct hlist_node *n;
734 struct can_frame *cf = (struct can_frame*)skb->data;
735 canid_t can_id = cf->can_id;
740 if (can_id & CAN_ERR_FLAG) {
741 /* check for error frame entries only */
742 hlist_for_each_entry_rcu(r, n, &d->rx_err, list) {
743 if (can_id & r->mask) {
744 DBG("match on rx_err skbuff %p\n", skb);
752 /* check for unfiltered entries */
753 hlist_for_each_entry_rcu(r, n, &d->rx_all, list) {
754 DBG("match on rx_all skbuff %p\n", skb);
759 /* check for can_id/mask entries */
760 hlist_for_each_entry_rcu(r, n, &d->rx_fil, list) {
761 if ((can_id & r->mask) == r->can_id) {
762 DBG("match on rx_fil skbuff %p\n", skb);
768 /* check for inverted can_id/mask entries */
769 hlist_for_each_entry_rcu(r, n, &d->rx_inv, list) {
770 if ((can_id & r->mask) != r->can_id) {
771 DBG("match on rx_inv skbuff %p\n", skb);
777 /* check CAN_ID specific entries */
778 if (can_id & CAN_EFF_FLAG) {
779 hlist_for_each_entry_rcu(r, n, &d->rx_eff, list) {
780 if (r->can_id == can_id) {
781 DBG("match on rx_eff skbuff %p\n", skb);
787 can_id &= CAN_SFF_MASK;
788 hlist_for_each_entry_rcu(r, n, &d->rx_sff[can_id], list) {
789 DBG("match on rx_sff skbuff %p\n", skb);
799 static struct dev_rcv_lists *find_dev_rcv_lists(struct net_device *dev)
801 struct dev_rcv_lists *d;
802 struct hlist_node *n;
804 /* find receive list for this device */
806 /* The hlist_for_each_entry*() macros curse through the list
807 * using the pointer variable n and set d to the containing
808 * struct in each list iteration. Therefore, after list
809 * iteration, d is unmodified when the list is empty, and it
810 * points to last list element, when the list is non-empty
811 * but no match in the loop body is found. I.e. d is *not*
812 * NULL when no match is found. We can, however, use the
813 * cursor variable n to decide if a match was found.
816 hlist_for_each_entry(d, n, &rx_dev_list, list)
823 static struct hlist_head *find_rcv_list(canid_t *can_id, canid_t *mask,
824 struct dev_rcv_lists *d)
826 canid_t inv = *can_id & CAN_INV_FILTER; /* save flag before masking */
828 if (*mask & CAN_ERR_FLAG) { /* filter error frames */
829 *mask &= CAN_ERR_MASK; /* clear CAN_ERR_FLAG in list entry */
833 /* ensure valid values in can_mask */
834 if (*mask & CAN_EFF_FLAG)
835 *mask &= (CAN_EFF_MASK | CAN_EFF_FLAG | CAN_RTR_FLAG);
837 *mask &= (CAN_SFF_MASK | CAN_RTR_FLAG);
839 *can_id &= *mask; /* reduce condition testing at receive time */
841 if (inv) /* inverse can_id/can_mask filter */
844 if (!(*mask)) /* mask == 0 => no condition testing at receive time */
847 /* use extra filterset for the subscription of exactly *one* can_id */
848 if (*can_id & CAN_EFF_FLAG) {
849 if (*mask == (CAN_EFF_MASK | CAN_EFF_FLAG))
850 return &d->rx_eff; /* use-case for hash-table here? */
852 if (*mask == CAN_SFF_MASK)
853 return &d->rx_sff[*can_id];
856 return &d->rx_fil; /* default: filter via can_id/can_mask */
859 /**************************************************/
860 /* af_can utility stuff */
861 /**************************************************/
863 unsigned long timeval2jiffies(struct timeval *tv, int round_up)
866 unsigned long sec = tv->tv_sec;
867 unsigned long usec = tv->tv_usec;
869 if (sec > ULONG_MAX / HZ) /* check for overflow */
872 if (round_up) /* any usec below one HZ? */
873 usec += 1000000 / HZ - 1; /* pump it up */
875 jif = usec / (1000000 / HZ);
877 if (sec * HZ > ULONG_MAX - jif) /* check for overflow */
880 return jif + sec * HZ;
884 /**************************************************/
885 /* af_can debugging stuff */
886 /**************************************************/
888 #ifdef CONFIG_CAN_DEBUG_CORE
890 void can_debug_cframe(const char *msg, struct can_frame *cf, ...)
897 len = sprintf(buf, KERN_DEBUG);
899 len += snprintf(buf + len, sizeof(buf) - 64, msg, ap);
904 if ((dlc = cf->can_dlc) > 8)
907 if (cf->can_id & CAN_EFF_FLAG)
908 len += sprintf(buf + len, "<%08X> [%X] ",
909 cf->can_id & CAN_EFF_MASK, dlc);
911 len += sprintf(buf + len, "<%03X> [%X] ",
912 cf->can_id & CAN_SFF_MASK, dlc);
914 for (i = 0; i < dlc; i++)
915 len += sprintf(buf + len, "%02X ", cf->data[i]);
917 if (cf->can_id & CAN_RTR_FLAG)
918 len += sprintf(buf + len, "(RTR)");
925 void can_debug_skb(struct sk_buff *skb)
931 KERN_DEBUG " skbuff at %p, dev: %d, proto: %04x\n"
932 KERN_DEBUG " users: %d, dataref: %d, nr_frags: %d, "
933 "h,d,t,e,l: %p %+d %+d %+d, %d",
934 skb, skb->dev ? skb->dev->ifindex : -1,
935 ntohs(skb->protocol),
936 atomic_read(&skb->users),
937 atomic_read(&(skb_shinfo(skb)->dataref)),
938 skb_shinfo(skb)->nr_frags,
939 skb->head, skb->data - skb->head,
940 skb->tail - skb->head, skb->end - skb->head, skb->len);
941 nbytes = skb->end - skb->head;
942 for (i = 0; i < nbytes; i++) {
944 len += sprintf(buf + len, "\n" KERN_DEBUG " ");
945 if (len < sizeof(buf) - 16) {
946 len += sprintf(buf + len, " %02x", skb->head[i]);
948 len += sprintf(buf + len, "...");
957 EXPORT_SYMBOL(can_debug_cframe);
958 EXPORT_SYMBOL(can_debug_skb);
962 /**************************************************/
963 /* Exported symbols */
964 /**************************************************/
965 EXPORT_SYMBOL(can_proto_register);
966 EXPORT_SYMBOL(can_proto_unregister);
967 EXPORT_SYMBOL(can_rx_register);
968 EXPORT_SYMBOL(can_rx_unregister);
969 EXPORT_SYMBOL(can_dev_register);
970 EXPORT_SYMBOL(can_dev_unregister);
971 EXPORT_SYMBOL(can_send);
972 EXPORT_SYMBOL(timeval2jiffies);