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_bh(&rcv_lists_lock);
184 hlist_add_head_rcu(&rx_alldev_list.list, &rx_dev_list);
185 spin_unlock_bh(&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 spin_lock_bh(&rcv_lists_lock);
223 hlist_del(&rx_alldev_list.list);
224 hlist_for_each_entry_safe(d, n, next, &rx_dev_list, list) {
228 spin_unlock_bh(&rcv_lists_lock);
230 kmem_cache_destroy(rcv_cache);
233 /**************************************************/
234 /* af_can protocol functions */
235 /**************************************************/
237 void can_proto_register(struct can_proto *cp)
239 int proto = cp->protocol;
240 if (proto < 0 || proto >= CAN_NPROTO) {
241 printk(KERN_ERR "CAN: protocol number %d out of range\n", proto);
244 if (proto_tab[proto]) {
245 printk(KERN_ERR "CAN: protocol %d already registered\n", proto);
249 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,13)
250 if (proto_register(cp->prot, 0) != 0) {
254 proto_tab[proto] = cp;
256 /* use our generic ioctl function if the module doesn't bring its own */
258 cp->ops->ioctl = can_ioctl;
261 void can_proto_unregister(struct can_proto *cp)
263 int proto = cp->protocol;
264 if (!proto_tab[proto]) {
265 printk(KERN_ERR "CAN: protocol %d is not registered\n", proto);
268 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,13)
269 proto_unregister(cp->prot);
271 proto_tab[proto] = NULL;
274 void can_dev_register(struct net_device *dev,
275 void (*func)(unsigned long msg, void *), void *data)
279 DBG("called for %s\n", dev->name);
281 if (!(n = kmalloc(sizeof(*n), GFP_KERNEL)))
288 write_lock(¬ifier_lock);
289 list_add(&n->list, ¬ifier_list);
290 write_unlock(¬ifier_lock);
293 void can_dev_unregister(struct net_device *dev,
294 void (*func)(unsigned long msg, void *), void *data)
296 struct notifier *n, *next;
298 DBG("called for %s\n", dev->name);
300 write_lock(¬ifier_lock);
301 list_for_each_entry_safe(n, next, ¬ifier_list, list) {
302 if (n->dev == dev && n->func == func && n->data == data) {
308 write_unlock(¬ifier_lock);
311 /**************************************************/
312 /* af_can socket functions */
313 /**************************************************/
315 static void can_sock_destruct(struct sock *sk)
317 DBG("called for sock %p\n", sk);
319 skb_queue_purge(&sk->sk_receive_queue);
321 kfree(sk->sk_protinfo);
324 static int can_create(struct socket *sock, int protocol)
327 struct can_proto *cp;
330 DBG("socket %p, type %d, proto %d\n", sock, sock->type, protocol);
332 sock->state = SS_UNCONNECTED;
334 if (protocol < 0 || protocol >= CAN_NPROTO)
337 DBG("looking up proto %d in proto_tab[]\n", protocol);
339 /* try to load protocol module, when CONFIG_KMOD is defined */
340 if (!proto_tab[protocol]) {
341 char module_name[30];
342 sprintf(module_name, "can-proto-%d", protocol);
343 if (request_module(module_name) == -ENOSYS)
344 printk(KERN_INFO "CAN: request_module(%s) not implemented.\n",
348 /* check for success and correct type */
349 if (!(cp = proto_tab[protocol]) || cp->type != sock->type)
350 return -EPROTONOSUPPORT;
352 if (cp->capability >= 0 && !capable(cp->capability))
357 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,13)
358 sk = sk_alloc(PF_CAN, GFP_KERNEL, cp->prot, 1);
362 sk = sk_alloc(PF_CAN, GFP_KERNEL, 1, 0);
366 !(sk->sk_protinfo = kmalloc(cp->obj_size, GFP_KERNEL))) {
370 sk_set_owner(sk, proto_tab[protocol]->owner);
372 sock_init_data(sock, sk);
373 sk->sk_destruct = can_sock_destruct;
375 DBG("created sock: %p\n", sk);
378 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,13)
379 if (sk->sk_prot->init)
380 ret = sk->sk_prot->init(sk);
386 /* we must release sk */
398 static int can_notifier(struct notifier_block *nb,
399 unsigned long msg, void *data)
401 struct net_device *dev = (struct net_device *)data;
404 DBG("called for %s, msg = %lu\n", dev->name, msg);
406 if (dev->type != ARPHRD_CAN)
410 struct dev_rcv_lists *d;
413 case NETDEV_REGISTER:
415 /* create new dev_rcv_lists for this device */
417 DBG("creating new dev_rcv_lists for %s\n", dev->name);
418 if (!(d = kmalloc(sizeof(*d),
419 in_interrupt() ? GFP_ATOMIC : GFP_KERNEL))) {
420 printk(KERN_ERR "CAN: allocation of receive list failed\n");
423 /* N.B. zeroing the struct is the correct initialization
424 for the embedded hlist_head structs.
425 Another list type, e.g. list_head, would require
426 explicit initialization. */
427 memset(d, 0, sizeof(*d));
430 spin_lock_bh(&rcv_lists_lock);
431 hlist_add_head_rcu(&d->list, &rx_dev_list);
432 spin_unlock_bh(&rcv_lists_lock);
436 case NETDEV_UNREGISTER:
437 spin_lock_bh(&rcv_lists_lock);
439 if (!(d = find_dev_rcv_lists(dev))) {
440 printk(KERN_ERR "CAN: notifier: receive list not "
441 "found for dev %s\n", dev->name);
445 hlist_del_rcu(&d->list);
447 /* remove all receivers hooked at this netdevice */
448 can_rx_delete_all(&d->rx_err);
449 can_rx_delete_all(&d->rx_all);
450 can_rx_delete_all(&d->rx_fil);
451 can_rx_delete_all(&d->rx_inv);
452 can_rx_delete_all(&d->rx_eff);
453 for (i = 0; i < 2048; i++)
454 can_rx_delete_all(&d->rx_sff[i]);
457 spin_unlock_bh(&rcv_lists_lock);
460 call_rcu(&d->rcu, can_rcv_lists_delete);
465 read_lock(¬ifier_lock);
466 list_for_each_entry(n, ¬ifier_list, list) {
468 n->func(msg, n->data);
470 read_unlock(¬ifier_lock);
475 static int can_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
477 struct sock *sk = sock->sk;
481 return sock_get_timestamp(sk, (struct timeval __user *)arg);
483 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
486 return dev_ioctl(cmd, (void __user *)arg);
492 /**************************************************/
494 /**************************************************/
496 int can_send(struct sk_buff *skb, int loop)
500 if (loop) { /* local loopback (default) */
501 *(struct sock **)skb->cb = skb->sk; /* tx sock reference */
503 /* interface not capabable to do the loopback itself? */
504 if (!(skb->dev->flags & IFF_LOOPBACK)) {
505 struct sk_buff *newskb = skb_clone(skb, GFP_ATOMIC);
506 newskb->protocol = htons(ETH_P_CAN);
507 newskb->ip_summed = CHECKSUM_UNNECESSARY;
508 netif_rx(newskb); /* perform local loopback here */
511 *(struct sock **)skb->cb = NULL; /* no loopback required */
513 if (!(skb->dev->flags & IFF_UP))
515 else if ((err = dev_queue_xmit(skb)) > 0) /* send to netdevice */
516 err = net_xmit_errno(err);
518 /* update statistics */
520 stats.tx_frames_delta++;
525 /**************************************************/
527 /**************************************************/
529 int can_rx_register(struct net_device *dev, canid_t can_id, canid_t mask,
530 void (*func)(struct sk_buff *, void *), void *data,
534 struct hlist_head *rl;
535 struct dev_rcv_lists *d;
538 /* insert new receiver (dev,canid,mask) -> (func,data) */
540 DBG("dev %p, id %03X, mask %03X, callback %p, data %p, ident %s\n",
541 dev, can_id, mask, func, data, ident);
543 if (!(r = kmem_cache_alloc(rcv_cache, GFP_KERNEL))) {
548 spin_lock_bh(&rcv_lists_lock);
550 if (!(d = find_dev_rcv_lists(dev))) {
551 DBG("receive list not found for dev %s, id %03X, mask %03X\n",
552 DNAME(dev), can_id, mask);
553 kmem_cache_free(rcv_cache, r);
558 rl = find_rcv_list(&can_id, &mask, d);
567 hlist_add_head_rcu(&r->list, rl);
570 pstats.rcv_entries++;
571 if (pstats.rcv_entries_max < pstats.rcv_entries)
572 pstats.rcv_entries_max = pstats.rcv_entries;
575 spin_unlock_bh(&rcv_lists_lock);
580 static void can_rcv_lists_delete(struct rcu_head *rp)
582 struct dev_rcv_lists *d = container_of(rp, struct dev_rcv_lists, rcu);
586 static void can_rx_delete(struct rcu_head *rp)
588 struct receiver *r = container_of(rp, struct receiver, rcu);
589 kmem_cache_free(rcv_cache, r);
592 static void can_rx_delete_all(struct hlist_head *rl)
595 struct hlist_node *n;
597 hlist_for_each_entry_rcu(r, n, rl, list) {
598 hlist_del_rcu(&r->list);
599 call_rcu(&r->rcu, can_rx_delete);
603 int can_rx_unregister(struct net_device *dev, canid_t can_id, canid_t mask,
604 void (*func)(struct sk_buff *, void *), void *data)
607 struct hlist_head *rl;
608 struct hlist_node *next;
609 struct dev_rcv_lists *d;
612 DBG("dev %p, id %03X, mask %03X, callback %p, data %p\n",
613 dev, can_id, mask, func, data);
617 spin_lock_bh(&rcv_lists_lock);
619 if (!(d = find_dev_rcv_lists(dev))) {
620 DBG("receive list not found for dev %s, id %03X, mask %03X\n",
621 DNAME(dev), can_id, mask);
626 rl = find_rcv_list(&can_id, &mask, d);
628 /* Search the receiver list for the item to delete. This should
629 * exist, since no receiver may be unregistered that hasn't
630 * been registered before.
633 hlist_for_each_entry(r, next, rl, list) {
634 if (r->can_id == can_id && r->mask == mask
635 && r->func == func && r->data == data)
639 /* Check for bug in CAN protocol implementations:
640 * If no matching list item was found, the list cursor variable next
641 * will be NULL, while r will point to the last item of the list.
645 DBG("receive list entry not found for "
646 "dev %s, id %03X, mask %03X\n", DNAME(dev), can_id, mask);
652 hlist_del_rcu(&r->list);
655 if (pstats.rcv_entries > 0)
656 pstats.rcv_entries--;
659 spin_unlock_bh(&rcv_lists_lock);
661 /* schedule the receiver item for deletion */
663 call_rcu(&r->rcu, can_rx_delete);
668 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,14)
669 static int can_rcv(struct sk_buff *skb, struct net_device *dev,
670 struct packet_type *pt, struct net_device *orig_dev)
672 static int can_rcv(struct sk_buff *skb, struct net_device *dev,
673 struct packet_type *pt)
676 struct dev_rcv_lists *d;
679 DBG("received skbuff on device %s, ptype %04x\n",
680 dev->name, ntohs(pt->type));
682 DBG_FRAME("af_can: can_rcv: received CAN frame",
683 (struct can_frame *)skb->data);
685 /* update statistics */
687 stats.rx_frames_delta++;
691 /* deliver the packet to sockets listening on all devices */
692 matches = can_rcv_filter(&rx_alldev_list, skb);
694 /* find receive list for this device */
695 if ((d = find_dev_rcv_lists(dev)))
696 matches += can_rcv_filter(d, skb);
700 /* free the skbuff allocated by the netdevice driver */
701 DBG("freeing skbuff %p\n", skb);
706 stats.matches_delta++;
713 static inline void deliver(struct sk_buff *skb, struct receiver *r)
715 struct sk_buff *clone = skb_clone(skb, GFP_ATOMIC);
716 DBG("skbuff %p cloned to %p\n", skb, clone);
718 r->func(clone, r->data);
719 r->matches++; /* update specific statistics */
723 static int can_rcv_filter(struct dev_rcv_lists *d, struct sk_buff *skb)
726 struct hlist_node *n;
728 struct can_frame *cf = (struct can_frame*)skb->data;
729 canid_t can_id = cf->can_id;
734 if (can_id & CAN_ERR_FLAG) {
735 /* check for error frame entries only */
736 hlist_for_each_entry_rcu(r, n, &d->rx_err, list) {
737 if (can_id & r->mask) {
738 DBG("match on rx_err skbuff %p\n", skb);
746 /* check for unfiltered entries */
747 hlist_for_each_entry_rcu(r, n, &d->rx_all, list) {
748 DBG("match on rx_all skbuff %p\n", skb);
753 /* check for can_id/mask entries */
754 hlist_for_each_entry_rcu(r, n, &d->rx_fil, list) {
755 if ((can_id & r->mask) == r->can_id) {
756 DBG("match on rx_fil skbuff %p\n", skb);
762 /* check for inverted can_id/mask entries */
763 hlist_for_each_entry_rcu(r, n, &d->rx_inv, list) {
764 if ((can_id & r->mask) != r->can_id) {
765 DBG("match on rx_inv skbuff %p\n", skb);
771 /* check CAN_ID specific entries */
772 if (can_id & CAN_EFF_FLAG) {
773 hlist_for_each_entry_rcu(r, n, &d->rx_eff, list) {
774 if (r->can_id == can_id) {
775 DBG("match on rx_eff skbuff %p\n", skb);
781 can_id &= CAN_SFF_MASK;
782 hlist_for_each_entry_rcu(r, n, &d->rx_sff[can_id], list) {
783 DBG("match on rx_sff skbuff %p\n", skb);
793 static struct dev_rcv_lists *find_dev_rcv_lists(struct net_device *dev)
795 struct dev_rcv_lists *d;
796 struct hlist_node *n;
798 /* find receive list for this device */
800 /* The hlist_for_each_entry*() macros curse through the list
801 * using the pointer variable n and set d to the containing
802 * struct in each list iteration. Therefore, after list
803 * iteration, d is unmodified when the list is empty, and it
804 * points to last list element, when the list is non-empty
805 * but no match in the loop body is found. I.e. d is *not*
806 * NULL when no match is found. We can, however, use the
807 * cursor variable n to decide if a match was found.
810 hlist_for_each_entry(d, n, &rx_dev_list, list)
817 static struct hlist_head *find_rcv_list(canid_t *can_id, canid_t *mask,
818 struct dev_rcv_lists *d)
820 canid_t inv = *can_id & CAN_INV_FILTER; /* save flag before masking */
822 if (*mask & CAN_ERR_FLAG) { /* filter error frames */
823 *mask &= CAN_ERR_MASK; /* clear CAN_ERR_FLAG in list entry */
827 /* ensure valid values in can_mask */
828 if (*mask & CAN_EFF_FLAG)
829 *mask &= (CAN_EFF_MASK | CAN_EFF_FLAG | CAN_RTR_FLAG);
831 *mask &= (CAN_SFF_MASK | CAN_RTR_FLAG);
833 *can_id &= *mask; /* reduce condition testing at receive time */
835 if (inv) /* inverse can_id/can_mask filter */
838 if (!(*mask)) /* mask == 0 => no condition testing at receive time */
841 /* use extra filterset for the subscription of exactly *one* can_id */
842 if (*can_id & CAN_EFF_FLAG) {
843 if (*mask == (CAN_EFF_MASK | CAN_EFF_FLAG))
844 return &d->rx_eff; /* use-case for hash-table here? */
846 if (*mask == CAN_SFF_MASK)
847 return &d->rx_sff[*can_id];
850 return &d->rx_fil; /* default: filter via can_id/can_mask */
853 /**************************************************/
854 /* af_can utility stuff */
855 /**************************************************/
857 unsigned long timeval2jiffies(struct timeval *tv, int round_up)
860 unsigned long sec = tv->tv_sec;
861 unsigned long usec = tv->tv_usec;
863 if (sec > ULONG_MAX / HZ) /* check for overflow */
866 if (round_up) /* any usec below one HZ? */
867 usec += 1000000 / HZ - 1; /* pump it up */
869 jif = usec / (1000000 / HZ);
871 if (sec * HZ > ULONG_MAX - jif) /* check for overflow */
874 return jif + sec * HZ;
878 /**************************************************/
879 /* af_can debugging stuff */
880 /**************************************************/
882 #ifdef CONFIG_CAN_DEBUG_CORE
884 void can_debug_cframe(const char *msg, struct can_frame *cf, ...)
891 len = sprintf(buf, KERN_DEBUG);
893 len += snprintf(buf + len, sizeof(buf) - 64, msg, ap);
898 if ((dlc = cf->can_dlc) > 8)
901 if (cf->can_id & CAN_EFF_FLAG)
902 len += sprintf(buf + len, "<%08X> [%X] ",
903 cf->can_id & CAN_EFF_MASK, dlc);
905 len += sprintf(buf + len, "<%03X> [%X] ",
906 cf->can_id & CAN_SFF_MASK, dlc);
908 for (i = 0; i < dlc; i++)
909 len += sprintf(buf + len, "%02X ", cf->data[i]);
911 if (cf->can_id & CAN_RTR_FLAG)
912 len += sprintf(buf + len, "(RTR)");
919 void can_debug_skb(struct sk_buff *skb)
925 KERN_DEBUG " skbuff at %p, dev: %d, proto: %04x\n"
926 KERN_DEBUG " users: %d, dataref: %d, nr_frags: %d, "
927 "h,d,t,e,l: %p %+d %+d %+d, %d",
928 skb, skb->dev ? skb->dev->ifindex : -1,
929 ntohs(skb->protocol),
930 atomic_read(&skb->users),
931 atomic_read(&(skb_shinfo(skb)->dataref)),
932 skb_shinfo(skb)->nr_frags,
933 skb->head, skb->data - skb->head,
934 skb->tail - skb->head, skb->end - skb->head, skb->len);
935 nbytes = skb->end - skb->head;
936 for (i = 0; i < nbytes; i++) {
938 len += sprintf(buf + len, "\n" KERN_DEBUG " ");
939 if (len < sizeof(buf) - 16) {
940 len += sprintf(buf + len, " %02x", skb->head[i]);
942 len += sprintf(buf + len, "...");
951 EXPORT_SYMBOL(can_debug_cframe);
952 EXPORT_SYMBOL(can_debug_skb);
956 /**************************************************/
957 /* Exported symbols */
958 /**************************************************/
959 EXPORT_SYMBOL(can_proto_register);
960 EXPORT_SYMBOL(can_proto_unregister);
961 EXPORT_SYMBOL(can_rx_register);
962 EXPORT_SYMBOL(can_rx_unregister);
963 EXPORT_SYMBOL(can_dev_register);
964 EXPORT_SYMBOL(can_dev_unregister);
965 EXPORT_SYMBOL(can_send);
966 EXPORT_SYMBOL(timeval2jiffies);