4 * Copyright (c) 2002-2005 Volkswagen Group Electronic Research
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions, the following disclaimer and
12 * the referenced file 'COPYING'.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of Volkswagen nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * Alternatively, provided that this notice is retained in full, this
21 * software may be distributed under the terms of the GNU General
22 * Public License ("GPL") version 2 as distributed in the 'COPYING'
23 * file from the main directory of the linux kernel source.
25 * The provided data structures and external interfaces from this code
26 * are not restricted to be used by modules with a GPL compatible license.
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
41 * Send feedback to <socketcan-users@lists.berlios.de>
45 #include <linux/autoconf.h>
46 #include <linux/module.h>
47 #include <linux/version.h>
48 #include <linux/slab.h>
49 #include <linux/kmod.h>
50 #include <linux/init.h>
51 #include <linux/list.h>
52 #include <linux/spinlock.h>
53 #include <linux/rcupdate.h>
54 #include <linux/socket.h>
55 #include <linux/skbuff.h>
56 #include <linux/net.h>
57 #include <linux/netdevice.h>
59 #include <asm/uaccess.h>
61 #include <linux/can.h>
62 #include <linux/can/version.h>
69 #define NAME "Volkswagen AG - Low Level CAN Framework (LLCF)"
70 #define IDENT "af_can"
71 static __initdata const char banner[] = BANNER(NAME);
73 MODULE_DESCRIPTION(NAME);
74 MODULE_LICENSE("Dual BSD/GPL");
75 MODULE_AUTHOR("Urs Thuermann <urs.thuermann@volkswagen.de>, "
76 "Oliver Hartkopp <oliver.hartkopp@volkswagen.de>");
78 int stats_timer = 1; /* default: on */
79 module_param(stats_timer, int, S_IRUGO);
81 #ifdef CONFIG_CAN_DEBUG_CORE
83 module_param(debug, int, S_IRUGO);
84 #define DBG(args...) (debug & 1 ? \
85 (printk(KERN_DEBUG "CAN %s: ", __func__), \
87 #define DBG_FRAME(args...) (debug & 2 ? can_debug_cframe(args) : 0)
88 #define DBG_SKB(skb) (debug & 4 ? can_debug_skb(skb) : 0)
91 #define DBG_FRAME(args...)
95 static __init int can_init(void);
96 static __exit void can_exit(void);
98 static int can_create(struct socket *sock, int protocol);
99 static int can_notifier(struct notifier_block *nb,
100 unsigned long msg, void *data);
101 static int can_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg);
102 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,14)
103 static int can_rcv(struct sk_buff *skb, struct net_device *dev,
104 struct packet_type *pt, struct net_device *orig_dev);
106 static int can_rcv(struct sk_buff *skb, struct net_device *dev,
107 struct packet_type *pt);
109 static int can_rcv_filter(struct dev_rcv_lists *d, struct sk_buff *skb);
110 static struct dev_rcv_lists *find_dev_rcv_lists(struct net_device *dev);
111 static struct hlist_head *find_rcv_list(canid_t *can_id, canid_t *mask,
112 struct dev_rcv_lists *d);
113 static void can_rcv_lists_delete(struct rcu_head *rp);
114 static void can_rx_delete(struct rcu_head *rp);
115 static void can_rx_delete_all(struct hlist_head *rl);
119 struct list_head list;
120 struct net_device *dev;
121 void (*func)(unsigned long msg, void *data);
125 static LIST_HEAD(notifier_list);
126 static rwlock_t notifier_lock = RW_LOCK_UNLOCKED;
128 HLIST_HEAD(rx_dev_list);
129 static struct dev_rcv_lists rx_alldev_list;
130 static spinlock_t rcv_lists_lock = SPIN_LOCK_UNLOCKED;
132 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
133 static struct kmem_cache *rcv_cache __read_mostly;
135 static kmem_cache_t *rcv_cache;
138 static struct packet_type can_packet = {
139 .type = __constant_htons(ETH_P_CAN),
144 static struct net_proto_family can_family_ops = {
146 .create = can_create,
147 .owner = THIS_MODULE,
150 /* notifier block for netdevice event */
151 static struct notifier_block can_netdev_notifier = {
152 .notifier_call = can_notifier,
155 /* table of registered CAN protocols */
156 static struct can_proto *proto_tab[CAN_NPROTO];
158 extern struct timer_list stattimer; /* timer for statistics update */
159 extern struct s_stats stats; /* packet statistics */
160 extern struct s_pstats pstats; /* receive list statistics */
162 module_init(can_init);
163 module_exit(can_exit);
165 /**************************************************/
166 /* af_can module init/exit functions */
167 /**************************************************/
169 static __init int can_init(void)
173 rcv_cache = kmem_cache_create("can_receiver", sizeof(struct receiver),
178 /* Insert struct dev_rcv_lists for reception on all devices.
179 This struct is zero initialized which is correct for the
180 embedded hlist heads, the dev pointer, and the entries counter.
183 spin_lock(&rcv_lists_lock);
184 hlist_add_head_rcu(&rx_alldev_list.list, &rx_dev_list);
185 spin_unlock(&rcv_lists_lock);
188 /* statistics init */
189 init_timer(&stattimer);
195 /* protocol register */
196 sock_register(&can_family_ops);
197 register_netdevice_notifier(&can_netdev_notifier);
198 dev_add_pack(&can_packet);
203 static __exit void can_exit(void)
205 struct dev_rcv_lists *d;
206 struct hlist_node *n, *next;
209 /* stop statistics timer */
210 del_timer(&stattimer);
216 /* protocol unregister */
217 dev_remove_pack(&can_packet);
218 unregister_netdevice_notifier(&can_netdev_notifier);
219 sock_unregister(PF_CAN);
221 /* remove rx_dev_list */
222 /* XXX: should we lock the receive list here? */
223 hlist_del(&rx_alldev_list.list);
224 hlist_for_each_entry_safe(d, n, next, &rx_dev_list, list)
227 kmem_cache_destroy(rcv_cache);
230 /**************************************************/
231 /* af_can protocol functions */
232 /**************************************************/
234 void can_proto_register(struct can_proto *cp)
236 int proto = cp->protocol;
237 if (proto < 0 || proto >= CAN_NPROTO) {
238 printk(KERN_ERR "CAN: protocol number %d out of range\n", proto);
241 if (proto_tab[proto]) {
242 printk(KERN_ERR "CAN: protocol %d already registered\n", proto);
246 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,13)
247 if (proto_register(cp->prot, 0) != 0) {
251 proto_tab[proto] = cp;
253 /* use our generic ioctl function if the module doesn't bring its own */
255 cp->ops->ioctl = can_ioctl;
258 void can_proto_unregister(struct can_proto *cp)
260 int proto = cp->protocol;
261 if (!proto_tab[proto]) {
262 printk(KERN_ERR "CAN: protocol %d is not registered\n", proto);
265 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,13)
266 proto_unregister(cp->prot);
268 proto_tab[proto] = NULL;
271 void can_dev_register(struct net_device *dev,
272 void (*func)(unsigned long msg, void *), void *data)
276 DBG("called for %s\n", dev->name);
278 if (!(n = kmalloc(sizeof(*n), GFP_KERNEL)))
285 write_lock(¬ifier_lock);
286 list_add(&n->list, ¬ifier_list);
287 write_unlock(¬ifier_lock);
290 void can_dev_unregister(struct net_device *dev,
291 void (*func)(unsigned long msg, void *), void *data)
293 struct notifier *n, *next;
295 DBG("called for %s\n", dev->name);
297 write_lock(¬ifier_lock);
298 list_for_each_entry_safe(n, next, ¬ifier_list, list) {
299 if (n->dev == dev && n->func == func && n->data == data) {
305 write_unlock(¬ifier_lock);
308 /**************************************************/
309 /* af_can socket functions */
310 /**************************************************/
312 static void can_sock_destruct(struct sock *sk)
314 DBG("called for sock %p\n", sk);
316 skb_queue_purge(&sk->sk_receive_queue);
318 kfree(sk->sk_protinfo);
321 static int can_create(struct socket *sock, int protocol)
324 struct can_proto *cp;
327 DBG("socket %p, type %d, proto %d\n", sock, sock->type, protocol);
329 sock->state = SS_UNCONNECTED;
331 if (protocol < 0 || protocol >= CAN_NPROTO)
334 DBG("looking up proto %d in proto_tab[]\n", protocol);
336 /* try to load protocol module, when CONFIG_KMOD is defined */
337 if (!proto_tab[protocol]) {
338 char module_name[30];
339 sprintf(module_name, "can-proto-%d", protocol);
340 if (request_module(module_name) == -ENOSYS)
341 printk(KERN_INFO "CAN: request_module(%s) not implemented.\n",
345 /* check for success and correct type */
346 if (!(cp = proto_tab[protocol]) || cp->type != sock->type)
347 return -EPROTONOSUPPORT;
349 if (cp->capability >= 0 && !capable(cp->capability))
354 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,13)
355 sk = sk_alloc(PF_CAN, GFP_KERNEL, cp->prot, 1);
359 sk = sk_alloc(PF_CAN, GFP_KERNEL, 1, 0);
363 !(sk->sk_protinfo = kmalloc(cp->obj_size, GFP_KERNEL))) {
367 sk_set_owner(sk, proto_tab[protocol]->owner);
369 sock_init_data(sock, sk);
370 sk->sk_destruct = can_sock_destruct;
372 DBG("created sock: %p\n", sk);
375 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,13)
376 if (sk->sk_prot->init)
377 ret = sk->sk_prot->init(sk);
383 /* we must release sk */
395 static int can_notifier(struct notifier_block *nb,
396 unsigned long msg, void *data)
398 struct net_device *dev = (struct net_device *)data;
401 DBG("called for %s, msg = %lu\n", dev->name, msg);
404 if (dev->type != ARPHRD_CAN)
409 struct dev_rcv_lists *d;
412 case NETDEV_REGISTER:
414 /* create new dev_rcv_lists for this device */
416 DBG("creating new dev_rcv_lists for %s\n", dev->name);
417 if (!(d = kmalloc(sizeof(*d), GFP_KERNEL))) {
418 printk(KERN_ERR "CAN: allocation of receive list failed\n");
421 /* N.B. zeroing the struct is the correct initialization
422 for the embedded hlist_head structs.
423 Another list type, e.g. list_head, would require
424 explicit initialization. */
425 memset(d, 0, sizeof(*d));
428 spin_lock(&rcv_lists_lock);
429 hlist_add_head_rcu(&d->list, &rx_dev_list);
430 spin_unlock(&rcv_lists_lock);
434 case NETDEV_UNREGISTER:
435 spin_lock(&rcv_lists_lock);
437 if (!(d = find_dev_rcv_lists(dev))) {
438 printk(KERN_ERR "CAN: notifier: receive list not "
439 "found for dev %s\n", dev->name);
443 hlist_del_rcu(&d->list);
445 /* remove all receivers hooked at this netdevice */
446 can_rx_delete_all(&d->rx_err);
447 can_rx_delete_all(&d->rx_all);
448 can_rx_delete_all(&d->rx_fil);
449 can_rx_delete_all(&d->rx_inv);
450 can_rx_delete_all(&d->rx_eff);
451 for (i = 0; i < 2048; i++)
452 can_rx_delete_all(&d->rx_sff[i]);
455 spin_unlock(&rcv_lists_lock);
458 call_rcu(&d->rcu, can_rcv_lists_delete);
463 read_lock(¬ifier_lock);
464 list_for_each_entry(n, ¬ifier_list, list) {
466 n->func(msg, n->data);
468 read_unlock(¬ifier_lock);
473 static int can_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
475 struct sock *sk = sock->sk;
479 return sock_get_timestamp(sk, (struct timeval __user *)arg);
481 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
484 return dev_ioctl(cmd, (void __user *)arg);
490 /**************************************************/
492 /**************************************************/
494 int can_send(struct sk_buff *skb, int loop)
498 if (loop) { /* local loopback (default) */
499 *(struct sock **)skb->cb = skb->sk; /* tx sock reference */
501 /* interface not capabable to do the loopback itself? */
502 if (!(skb->dev->flags & IFF_LOOPBACK)) {
503 struct sk_buff *newskb = skb_clone(skb, GFP_ATOMIC);
504 newskb->protocol = htons(ETH_P_CAN);
505 newskb->ip_summed = CHECKSUM_UNNECESSARY;
506 netif_rx(newskb); /* perform local loopback here */
509 *(struct sock **)skb->cb = NULL; /* no loopback required */
511 if (!(skb->dev->flags & IFF_UP))
513 else if ((err = dev_queue_xmit(skb)) > 0) /* send to netdevice */
514 err = net_xmit_errno(err);
516 /* update statistics */
518 stats.tx_frames_delta++;
523 /**************************************************/
525 /**************************************************/
527 int can_rx_register(struct net_device *dev, canid_t can_id, canid_t mask,
528 void (*func)(struct sk_buff *, void *), void *data,
532 struct hlist_head *rl;
533 struct dev_rcv_lists *d;
536 /* insert new receiver (dev,canid,mask) -> (func,data) */
538 DBG("dev %p, id %03X, mask %03X, callback %p, data %p, ident %s\n",
539 dev, can_id, mask, func, data, ident);
541 if (!(r = kmem_cache_alloc(rcv_cache, GFP_KERNEL))) {
546 spin_lock(&rcv_lists_lock);
548 if (!(d = find_dev_rcv_lists(dev))) {
549 DBG("receive list not found for dev %s, id %03X, mask %03X\n",
550 DNAME(dev), can_id, mask);
551 kmem_cache_free(rcv_cache, r);
556 rl = find_rcv_list(&can_id, &mask, d);
565 hlist_add_head_rcu(&r->list, rl);
568 pstats.rcv_entries++;
569 if (pstats.rcv_entries_max < pstats.rcv_entries)
570 pstats.rcv_entries_max = pstats.rcv_entries;
573 spin_unlock(&rcv_lists_lock);
578 static void can_rcv_lists_delete(struct rcu_head *rp)
580 struct dev_rcv_lists *d = container_of(rp, struct dev_rcv_lists, rcu);
584 static void can_rx_delete(struct rcu_head *rp)
586 struct receiver *r = container_of(rp, struct receiver, rcu);
587 kmem_cache_free(rcv_cache, r);
590 static void can_rx_delete_all(struct hlist_head *rl)
593 struct hlist_node *n;
595 hlist_for_each_entry_rcu(r, n, rl, list) {
596 hlist_del_rcu(&r->list);
597 call_rcu(&r->rcu, can_rx_delete);
601 int can_rx_unregister(struct net_device *dev, canid_t can_id, canid_t mask,
602 void (*func)(struct sk_buff *, void *), void *data)
605 struct hlist_head *rl;
606 struct hlist_node *next;
607 struct dev_rcv_lists *d;
610 DBG("dev %p, id %03X, mask %03X, callback %p, data %p\n",
611 dev, can_id, mask, func, data);
615 spin_lock(&rcv_lists_lock);
617 if (!(d = find_dev_rcv_lists(dev))) {
618 DBG("receive list not found for dev %s, id %03X, mask %03X\n",
619 DNAME(dev), can_id, mask);
624 rl = find_rcv_list(&can_id, &mask, d);
626 /* Search the receiver list for the item to delete. This should
627 * exist, since no receiver may be unregistered that hasn't
628 * been registered before.
631 hlist_for_each_entry(r, next, rl, list) {
632 if (r->can_id == can_id && r->mask == mask
633 && r->func == func && r->data == data)
637 /* Check for bug in CAN protocol implementations:
638 * If no matching list item was found, the list cursor variable next
639 * will be NULL, while r will point to the last item of the list.
643 DBG("receive list entry not found for "
644 "dev %s, id %03X, mask %03X\n", DNAME(dev), can_id, mask);
650 hlist_del_rcu(&r->list);
653 if (pstats.rcv_entries > 0)
654 pstats.rcv_entries--;
657 spin_unlock(&rcv_lists_lock);
659 /* schedule the receiver item for deletion */
661 call_rcu(&r->rcu, can_rx_delete);
666 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,14)
667 static int can_rcv(struct sk_buff *skb, struct net_device *dev,
668 struct packet_type *pt, struct net_device *orig_dev)
670 static int can_rcv(struct sk_buff *skb, struct net_device *dev,
671 struct packet_type *pt)
674 struct dev_rcv_lists *d;
677 DBG("received skbuff on device %s, ptype %04x\n",
678 dev->name, ntohs(pt->type));
680 DBG_FRAME("af_can: can_rcv: received CAN frame",
681 (struct can_frame *)skb->data);
683 /* update statistics */
685 stats.rx_frames_delta++;
689 /* deliver the packet to sockets listening on all devices */
690 matches = can_rcv_filter(&rx_alldev_list, skb);
692 /* find receive list for this device */
693 if ((d = find_dev_rcv_lists(dev)))
694 matches += can_rcv_filter(d, skb);
698 /* free the skbuff allocated by the netdevice driver */
699 DBG("freeing skbuff %p\n", skb);
704 stats.matches_delta++;
711 static inline void deliver(struct sk_buff *skb, struct receiver *r)
713 struct sk_buff *clone = skb_clone(skb, GFP_ATOMIC);
714 DBG("skbuff %p cloned to %p\n", skb, clone);
716 r->func(clone, r->data);
717 r->matches++; /* update specific statistics */
721 static int can_rcv_filter(struct dev_rcv_lists *d, struct sk_buff *skb)
724 struct hlist_node *n;
726 struct can_frame *cf = (struct can_frame*)skb->data;
727 canid_t can_id = cf->can_id;
732 if (can_id & CAN_ERR_FLAG) {
733 /* check for error frame entries only */
734 hlist_for_each_entry_rcu(r, n, &d->rx_err, list) {
735 if (can_id & r->mask) {
736 DBG("match on rx_err skbuff %p\n", skb);
744 /* check for unfiltered entries */
745 hlist_for_each_entry_rcu(r, n, &d->rx_all, list) {
746 DBG("match on rx_all skbuff %p\n", skb);
751 /* check for can_id/mask entries */
752 hlist_for_each_entry_rcu(r, n, &d->rx_fil, list) {
753 if ((can_id & r->mask) == r->can_id) {
754 DBG("match on rx_fil skbuff %p\n", skb);
760 /* check for inverted can_id/mask entries */
761 hlist_for_each_entry_rcu(r, n, &d->rx_inv, list) {
762 if ((can_id & r->mask) != r->can_id) {
763 DBG("match on rx_inv skbuff %p\n", skb);
769 /* check CAN_ID specific entries */
770 if (can_id & CAN_EFF_FLAG) {
771 hlist_for_each_entry_rcu(r, n, &d->rx_eff, list) {
772 if (r->can_id == can_id) {
773 DBG("match on rx_eff skbuff %p\n", skb);
779 can_id &= CAN_SFF_MASK;
780 hlist_for_each_entry_rcu(r, n, &d->rx_sff[can_id], list) {
781 DBG("match on rx_sff skbuff %p\n", skb);
791 static struct dev_rcv_lists *find_dev_rcv_lists(struct net_device *dev)
793 struct dev_rcv_lists *d;
794 struct hlist_node *n;
796 /* find receive list for this device */
798 /* The hlist_for_each_entry*() macros curse through the list
799 * using the pointer variable n and set d to the containing
800 * struct in each list iteration. Therefore, after list
801 * iteration, d is unmodified when the list is empty, and it
802 * points to last list element, when the list is non-empty
803 * but no match in the loop body is found. I.e. d is *not*
804 * NULL when no match is found. We can, however, use the
805 * cursor variable n to decide if a match was found.
808 hlist_for_each_entry(d, n, &rx_dev_list, list)
815 static struct hlist_head *find_rcv_list(canid_t *can_id, canid_t *mask,
816 struct dev_rcv_lists *d)
818 canid_t inv = *can_id & CAN_INV_FILTER; /* save flag before masking values */
819 canid_t eff = *can_id & *mask & CAN_EFF_FLAG; /* correct EFF check? */
820 canid_t rtr = *can_id & *mask & CAN_RTR_FLAG; /* correct RTR check? */
822 /* do not modify the error mask due to the can_id which is 0 */
823 if (*mask & CAN_ERR_FLAG) { /* filter error frames */
824 *mask &= CAN_ERR_MASK; /* clear CAN_ERR_FLAG in list entry */
828 /* make some paranoic operations */
829 if (*can_id & CAN_EFF_FLAG)
830 *mask &= (CAN_EFF_MASK | eff | rtr);
832 *mask &= (CAN_SFF_MASK | rtr);
836 if (inv) /* inverse can_id/can_mask filter and RTR */
839 if (*can_id & CAN_RTR_FLAG) /* positive filter RTR */
842 if (!(*mask)) /* mask == 0 => no filter */
845 if (*can_id & CAN_EFF_FLAG) {
846 if (*mask == CAN_EFF_MASK) /* filter exact EFF can_id */
849 if (*mask == CAN_SFF_MASK) /* filter exact SFF can_id */
850 return &d->rx_sff[*can_id];
853 return &d->rx_fil; /* filter via can_id/can_mask */
856 /**************************************************/
857 /* af_can utility stuff */
858 /**************************************************/
860 unsigned long timeval2jiffies(struct timeval *tv, int round_up)
863 unsigned long sec = tv->tv_sec;
864 unsigned long usec = tv->tv_usec;
866 if (sec > ULONG_MAX / HZ) /* check for overflow */
869 if (round_up) /* any usec below one HZ? */
870 usec += 1000000 / HZ - 1; /* pump it up */
872 jif = usec / (1000000 / HZ);
874 if (sec * HZ > ULONG_MAX - jif) /* check for overflow */
877 return jif + sec * HZ;
881 /**************************************************/
882 /* af_can debugging stuff */
883 /**************************************************/
885 #ifdef CONFIG_CAN_DEBUG_CORE
887 void can_debug_cframe(const char *msg, struct can_frame *cf, ...)
894 len = sprintf(buf, KERN_DEBUG);
896 len += snprintf(buf + len, sizeof(buf) - 64, msg, ap);
901 if ((dlc = cf->can_dlc) > 8)
904 if (cf->can_id & CAN_EFF_FLAG)
905 len += sprintf(buf + len, "<%08X> [%X] ",
906 cf->can_id & CAN_EFF_MASK, dlc);
908 len += sprintf(buf + len, "<%03X> [%X] ",
909 cf->can_id & CAN_SFF_MASK, dlc);
911 for (i = 0; i < dlc; i++)
912 len += sprintf(buf + len, "%02X ", cf->data[i]);
914 if (cf->can_id & CAN_RTR_FLAG)
915 len += sprintf(buf + len, "(RTR)");
922 void can_debug_skb(struct sk_buff *skb)
928 KERN_DEBUG " skbuff at %p, dev: %d, proto: %04x\n"
929 KERN_DEBUG " users: %d, dataref: %d, nr_frags: %d, "
930 "h,d,t,e,l: %p %+d %+d %+d, %d",
931 skb, skb->dev ? skb->dev->ifindex : -1,
932 ntohs(skb->protocol),
933 atomic_read(&skb->users),
934 atomic_read(&(skb_shinfo(skb)->dataref)),
935 skb_shinfo(skb)->nr_frags,
936 skb->head, skb->data - skb->head,
937 skb->tail - skb->head, skb->end - skb->head, skb->len);
938 nbytes = skb->end - skb->head;
939 for (i = 0; i < nbytes; i++) {
941 len += sprintf(buf + len, "\n" KERN_DEBUG " ");
942 if (len < sizeof(buf) - 16) {
943 len += sprintf(buf + len, " %02x", skb->head[i]);
945 len += sprintf(buf + len, "...");
954 EXPORT_SYMBOL(can_debug_cframe);
955 EXPORT_SYMBOL(can_debug_skb);
959 /**************************************************/
960 /* Exported symbols */
961 /**************************************************/
962 EXPORT_SYMBOL(can_proto_register);
963 EXPORT_SYMBOL(can_proto_unregister);
964 EXPORT_SYMBOL(can_rx_register);
965 EXPORT_SYMBOL(can_rx_unregister);
966 EXPORT_SYMBOL(can_dev_register);
967 EXPORT_SYMBOL(can_dev_unregister);
968 EXPORT_SYMBOL(can_send);
969 EXPORT_SYMBOL(timeval2jiffies);