cipso: unsigned buf_len cannot be negative
[linux-2.6/next.git] / net / can / bcm.c
blobd0dd382001e210c052e2fcb1ca6ae304d72b46a1
1 /*
2 * bcm.c - Broadcast Manager to filter/send (cyclic) CAN content
4 * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
5 * All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of Volkswagen nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * Alternatively, provided that this notice is retained in full, this
20 * software may be distributed under the terms of the GNU General
21 * Public License ("GPL") version 2, in which case the provisions of the
22 * GPL apply INSTEAD OF those given above.
24 * The provided data structures and external interfaces from this code
25 * are not restricted to be used by modules with a GPL compatible license.
27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
32 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
34 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
35 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
38 * DAMAGE.
40 * Send feedback to <socketcan-users@lists.berlios.de>
44 #include <linux/module.h>
45 #include <linux/init.h>
46 #include <linux/hrtimer.h>
47 #include <linux/list.h>
48 #include <linux/proc_fs.h>
49 #include <linux/uio.h>
50 #include <linux/net.h>
51 #include <linux/netdevice.h>
52 #include <linux/socket.h>
53 #include <linux/if_arp.h>
54 #include <linux/skbuff.h>
55 #include <linux/can.h>
56 #include <linux/can/core.h>
57 #include <linux/can/bcm.h>
58 #include <net/sock.h>
59 #include <net/net_namespace.h>
61 /* use of last_frames[index].can_dlc */
62 #define RX_RECV 0x40 /* received data for this element */
63 #define RX_THR 0x80 /* element not been sent due to throttle feature */
64 #define BCM_CAN_DLC_MASK 0x0F /* clean private flags in can_dlc by masking */
66 /* get best masking value for can_rx_register() for a given single can_id */
67 #define REGMASK(id) ((id & CAN_RTR_FLAG) | ((id & CAN_EFF_FLAG) ? \
68 (CAN_EFF_MASK | CAN_EFF_FLAG) : CAN_SFF_MASK))
70 #define CAN_BCM_VERSION "20080415"
71 static __initdata const char banner[] = KERN_INFO
72 "can: broadcast manager protocol (rev " CAN_BCM_VERSION ")\n";
74 MODULE_DESCRIPTION("PF_CAN broadcast manager protocol");
75 MODULE_LICENSE("Dual BSD/GPL");
76 MODULE_AUTHOR("Oliver Hartkopp <oliver.hartkopp@volkswagen.de>");
78 /* easy access to can_frame payload */
79 static inline u64 GET_U64(const struct can_frame *cp)
81 return *(u64 *)cp->data;
84 struct bcm_op {
85 struct list_head list;
86 int ifindex;
87 canid_t can_id;
88 int flags;
89 unsigned long frames_abs, frames_filtered;
90 struct timeval ival1, ival2;
91 struct hrtimer timer, thrtimer;
92 ktime_t rx_stamp, kt_ival1, kt_ival2, kt_lastmsg;
93 int rx_ifindex;
94 int count;
95 int nframes;
96 int currframe;
97 struct can_frame *frames;
98 struct can_frame *last_frames;
99 struct can_frame sframe;
100 struct can_frame last_sframe;
101 struct sock *sk;
102 struct net_device *rx_reg_dev;
105 static struct proc_dir_entry *proc_dir;
107 struct bcm_sock {
108 struct sock sk;
109 int bound;
110 int ifindex;
111 struct notifier_block notifier;
112 struct list_head rx_ops;
113 struct list_head tx_ops;
114 unsigned long dropped_usr_msgs;
115 struct proc_dir_entry *bcm_proc_read;
116 char procname [9]; /* pointer printed in ASCII with \0 */
119 static inline struct bcm_sock *bcm_sk(const struct sock *sk)
121 return (struct bcm_sock *)sk;
124 #define CFSIZ sizeof(struct can_frame)
125 #define OPSIZ sizeof(struct bcm_op)
126 #define MHSIZ sizeof(struct bcm_msg_head)
129 * procfs functions
131 static char *bcm_proc_getifname(int ifindex)
133 struct net_device *dev;
135 if (!ifindex)
136 return "any";
138 /* no usage counting */
139 dev = __dev_get_by_index(&init_net, ifindex);
140 if (dev)
141 return dev->name;
143 return "???";
146 static int bcm_read_proc(char *page, char **start, off_t off,
147 int count, int *eof, void *data)
149 int len = 0;
150 struct sock *sk = (struct sock *)data;
151 struct bcm_sock *bo = bcm_sk(sk);
152 struct bcm_op *op;
154 len += snprintf(page + len, PAGE_SIZE - len, ">>> socket %p",
155 sk->sk_socket);
156 len += snprintf(page + len, PAGE_SIZE - len, " / sk %p", sk);
157 len += snprintf(page + len, PAGE_SIZE - len, " / bo %p", bo);
158 len += snprintf(page + len, PAGE_SIZE - len, " / dropped %lu",
159 bo->dropped_usr_msgs);
160 len += snprintf(page + len, PAGE_SIZE - len, " / bound %s",
161 bcm_proc_getifname(bo->ifindex));
162 len += snprintf(page + len, PAGE_SIZE - len, " <<<\n");
164 list_for_each_entry(op, &bo->rx_ops, list) {
166 unsigned long reduction;
168 /* print only active entries & prevent division by zero */
169 if (!op->frames_abs)
170 continue;
172 len += snprintf(page + len, PAGE_SIZE - len,
173 "rx_op: %03X %-5s ",
174 op->can_id, bcm_proc_getifname(op->ifindex));
175 len += snprintf(page + len, PAGE_SIZE - len, "[%d]%c ",
176 op->nframes,
177 (op->flags & RX_CHECK_DLC)?'d':' ');
178 if (op->kt_ival1.tv64)
179 len += snprintf(page + len, PAGE_SIZE - len,
180 "timeo=%lld ",
181 (long long)
182 ktime_to_us(op->kt_ival1));
184 if (op->kt_ival2.tv64)
185 len += snprintf(page + len, PAGE_SIZE - len,
186 "thr=%lld ",
187 (long long)
188 ktime_to_us(op->kt_ival2));
190 len += snprintf(page + len, PAGE_SIZE - len,
191 "# recv %ld (%ld) => reduction: ",
192 op->frames_filtered, op->frames_abs);
194 reduction = 100 - (op->frames_filtered * 100) / op->frames_abs;
196 len += snprintf(page + len, PAGE_SIZE - len, "%s%ld%%\n",
197 (reduction == 100)?"near ":"", reduction);
199 if (len > PAGE_SIZE - 200) {
200 /* mark output cut off */
201 len += snprintf(page + len, PAGE_SIZE - len, "(..)\n");
202 break;
206 list_for_each_entry(op, &bo->tx_ops, list) {
208 len += snprintf(page + len, PAGE_SIZE - len,
209 "tx_op: %03X %s [%d] ",
210 op->can_id, bcm_proc_getifname(op->ifindex),
211 op->nframes);
213 if (op->kt_ival1.tv64)
214 len += snprintf(page + len, PAGE_SIZE - len, "t1=%lld ",
215 (long long) ktime_to_us(op->kt_ival1));
217 if (op->kt_ival2.tv64)
218 len += snprintf(page + len, PAGE_SIZE - len, "t2=%lld ",
219 (long long) ktime_to_us(op->kt_ival2));
221 len += snprintf(page + len, PAGE_SIZE - len, "# sent %ld\n",
222 op->frames_abs);
224 if (len > PAGE_SIZE - 100) {
225 /* mark output cut off */
226 len += snprintf(page + len, PAGE_SIZE - len, "(..)\n");
227 break;
231 len += snprintf(page + len, PAGE_SIZE - len, "\n");
233 *eof = 1;
234 return len;
238 * bcm_can_tx - send the (next) CAN frame to the appropriate CAN interface
239 * of the given bcm tx op
241 static void bcm_can_tx(struct bcm_op *op)
243 struct sk_buff *skb;
244 struct net_device *dev;
245 struct can_frame *cf = &op->frames[op->currframe];
247 /* no target device? => exit */
248 if (!op->ifindex)
249 return;
251 dev = dev_get_by_index(&init_net, op->ifindex);
252 if (!dev) {
253 /* RFC: should this bcm_op remove itself here? */
254 return;
257 skb = alloc_skb(CFSIZ, gfp_any());
258 if (!skb)
259 goto out;
261 memcpy(skb_put(skb, CFSIZ), cf, CFSIZ);
263 /* send with loopback */
264 skb->dev = dev;
265 skb->sk = op->sk;
266 can_send(skb, 1);
268 /* update statistics */
269 op->currframe++;
270 op->frames_abs++;
272 /* reached last frame? */
273 if (op->currframe >= op->nframes)
274 op->currframe = 0;
275 out:
276 dev_put(dev);
280 * bcm_send_to_user - send a BCM message to the userspace
281 * (consisting of bcm_msg_head + x CAN frames)
283 static void bcm_send_to_user(struct bcm_op *op, struct bcm_msg_head *head,
284 struct can_frame *frames, int has_timestamp)
286 struct sk_buff *skb;
287 struct can_frame *firstframe;
288 struct sockaddr_can *addr;
289 struct sock *sk = op->sk;
290 int datalen = head->nframes * CFSIZ;
291 int err;
293 skb = alloc_skb(sizeof(*head) + datalen, gfp_any());
294 if (!skb)
295 return;
297 memcpy(skb_put(skb, sizeof(*head)), head, sizeof(*head));
299 if (head->nframes) {
300 /* can_frames starting here */
301 firstframe = (struct can_frame *)skb_tail_pointer(skb);
303 memcpy(skb_put(skb, datalen), frames, datalen);
306 * the BCM uses the can_dlc-element of the can_frame
307 * structure for internal purposes. This is only
308 * relevant for updates that are generated by the
309 * BCM, where nframes is 1
311 if (head->nframes == 1)
312 firstframe->can_dlc &= BCM_CAN_DLC_MASK;
315 if (has_timestamp) {
316 /* restore rx timestamp */
317 skb->tstamp = op->rx_stamp;
321 * Put the datagram to the queue so that bcm_recvmsg() can
322 * get it from there. We need to pass the interface index to
323 * bcm_recvmsg(). We pass a whole struct sockaddr_can in skb->cb
324 * containing the interface index.
327 BUILD_BUG_ON(sizeof(skb->cb) < sizeof(struct sockaddr_can));
328 addr = (struct sockaddr_can *)skb->cb;
329 memset(addr, 0, sizeof(*addr));
330 addr->can_family = AF_CAN;
331 addr->can_ifindex = op->rx_ifindex;
333 err = sock_queue_rcv_skb(sk, skb);
334 if (err < 0) {
335 struct bcm_sock *bo = bcm_sk(sk);
337 kfree_skb(skb);
338 /* don't care about overflows in this statistic */
339 bo->dropped_usr_msgs++;
344 * bcm_tx_timeout_handler - performes cyclic CAN frame transmissions
346 static enum hrtimer_restart bcm_tx_timeout_handler(struct hrtimer *hrtimer)
348 struct bcm_op *op = container_of(hrtimer, struct bcm_op, timer);
349 enum hrtimer_restart ret = HRTIMER_NORESTART;
351 if (op->kt_ival1.tv64 && (op->count > 0)) {
353 op->count--;
354 if (!op->count && (op->flags & TX_COUNTEVT)) {
355 struct bcm_msg_head msg_head;
357 /* create notification to user */
358 msg_head.opcode = TX_EXPIRED;
359 msg_head.flags = op->flags;
360 msg_head.count = op->count;
361 msg_head.ival1 = op->ival1;
362 msg_head.ival2 = op->ival2;
363 msg_head.can_id = op->can_id;
364 msg_head.nframes = 0;
366 bcm_send_to_user(op, &msg_head, NULL, 0);
370 if (op->kt_ival1.tv64 && (op->count > 0)) {
372 /* send (next) frame */
373 bcm_can_tx(op);
374 hrtimer_forward(hrtimer, ktime_get(), op->kt_ival1);
375 ret = HRTIMER_RESTART;
377 } else {
378 if (op->kt_ival2.tv64) {
380 /* send (next) frame */
381 bcm_can_tx(op);
382 hrtimer_forward(hrtimer, ktime_get(), op->kt_ival2);
383 ret = HRTIMER_RESTART;
387 return ret;
391 * bcm_rx_changed - create a RX_CHANGED notification due to changed content
393 static void bcm_rx_changed(struct bcm_op *op, struct can_frame *data)
395 struct bcm_msg_head head;
397 /* update statistics */
398 op->frames_filtered++;
400 /* prevent statistics overflow */
401 if (op->frames_filtered > ULONG_MAX/100)
402 op->frames_filtered = op->frames_abs = 0;
404 head.opcode = RX_CHANGED;
405 head.flags = op->flags;
406 head.count = op->count;
407 head.ival1 = op->ival1;
408 head.ival2 = op->ival2;
409 head.can_id = op->can_id;
410 head.nframes = 1;
412 bcm_send_to_user(op, &head, data, 1);
416 * bcm_rx_update_and_send - process a detected relevant receive content change
417 * 1. update the last received data
418 * 2. send a notification to the user (if possible)
420 static void bcm_rx_update_and_send(struct bcm_op *op,
421 struct can_frame *lastdata,
422 struct can_frame *rxdata)
424 memcpy(lastdata, rxdata, CFSIZ);
426 /* mark as used */
427 lastdata->can_dlc |= RX_RECV;
429 /* throtteling mode inactive OR data update already on the run ? */
430 if (!op->kt_ival2.tv64 || hrtimer_callback_running(&op->thrtimer)) {
431 /* send RX_CHANGED to the user immediately */
432 bcm_rx_changed(op, rxdata);
433 return;
436 if (hrtimer_active(&op->thrtimer)) {
437 /* mark as 'throttled' */
438 lastdata->can_dlc |= RX_THR;
439 return;
442 if (!op->kt_lastmsg.tv64) {
443 /* send first RX_CHANGED to the user immediately */
444 bcm_rx_changed(op, rxdata);
445 op->kt_lastmsg = ktime_get();
446 return;
449 if (ktime_us_delta(ktime_get(), op->kt_lastmsg) <
450 ktime_to_us(op->kt_ival2)) {
451 /* mark as 'throttled' and start timer */
452 lastdata->can_dlc |= RX_THR;
453 hrtimer_start(&op->thrtimer,
454 ktime_add(op->kt_lastmsg, op->kt_ival2),
455 HRTIMER_MODE_ABS);
456 return;
459 /* the gap was that big, that throttling was not needed here */
460 bcm_rx_changed(op, rxdata);
461 op->kt_lastmsg = ktime_get();
465 * bcm_rx_cmp_to_index - (bit)compares the currently received data to formerly
466 * received data stored in op->last_frames[]
468 static void bcm_rx_cmp_to_index(struct bcm_op *op, int index,
469 struct can_frame *rxdata)
472 * no one uses the MSBs of can_dlc for comparation,
473 * so we use it here to detect the first time of reception
476 if (!(op->last_frames[index].can_dlc & RX_RECV)) {
477 /* received data for the first time => send update to user */
478 bcm_rx_update_and_send(op, &op->last_frames[index], rxdata);
479 return;
482 /* do a real check in can_frame data section */
484 if ((GET_U64(&op->frames[index]) & GET_U64(rxdata)) !=
485 (GET_U64(&op->frames[index]) & GET_U64(&op->last_frames[index]))) {
486 bcm_rx_update_and_send(op, &op->last_frames[index], rxdata);
487 return;
490 if (op->flags & RX_CHECK_DLC) {
491 /* do a real check in can_frame dlc */
492 if (rxdata->can_dlc != (op->last_frames[index].can_dlc &
493 BCM_CAN_DLC_MASK)) {
494 bcm_rx_update_and_send(op, &op->last_frames[index],
495 rxdata);
496 return;
502 * bcm_rx_starttimer - enable timeout monitoring for CAN frame receiption
504 static void bcm_rx_starttimer(struct bcm_op *op)
506 if (op->flags & RX_NO_AUTOTIMER)
507 return;
509 if (op->kt_ival1.tv64)
510 hrtimer_start(&op->timer, op->kt_ival1, HRTIMER_MODE_REL);
514 * bcm_rx_timeout_handler - when the (cyclic) CAN frame receiption timed out
516 static enum hrtimer_restart bcm_rx_timeout_handler(struct hrtimer *hrtimer)
518 struct bcm_op *op = container_of(hrtimer, struct bcm_op, timer);
519 struct bcm_msg_head msg_head;
521 msg_head.opcode = RX_TIMEOUT;
522 msg_head.flags = op->flags;
523 msg_head.count = op->count;
524 msg_head.ival1 = op->ival1;
525 msg_head.ival2 = op->ival2;
526 msg_head.can_id = op->can_id;
527 msg_head.nframes = 0;
529 bcm_send_to_user(op, &msg_head, NULL, 0);
531 /* no restart of the timer is done here! */
533 /* if user wants to be informed, when cyclic CAN-Messages come back */
534 if ((op->flags & RX_ANNOUNCE_RESUME) && op->last_frames) {
535 /* clear received can_frames to indicate 'nothing received' */
536 memset(op->last_frames, 0, op->nframes * CFSIZ);
539 return HRTIMER_NORESTART;
543 * bcm_rx_thr_flush - Check for throttled data and send it to the userspace
545 static int bcm_rx_thr_flush(struct bcm_op *op)
547 int updated = 0;
549 if (op->nframes > 1) {
550 int i;
552 /* for MUX filter we start at index 1 */
553 for (i = 1; i < op->nframes; i++) {
554 if ((op->last_frames) &&
555 (op->last_frames[i].can_dlc & RX_THR)) {
556 op->last_frames[i].can_dlc &= ~RX_THR;
557 bcm_rx_changed(op, &op->last_frames[i]);
558 updated++;
562 } else {
563 /* for RX_FILTER_ID and simple filter */
564 if (op->last_frames && (op->last_frames[0].can_dlc & RX_THR)) {
565 op->last_frames[0].can_dlc &= ~RX_THR;
566 bcm_rx_changed(op, &op->last_frames[0]);
567 updated++;
571 return updated;
575 * bcm_rx_thr_handler - the time for blocked content updates is over now:
576 * Check for throttled data and send it to the userspace
578 static enum hrtimer_restart bcm_rx_thr_handler(struct hrtimer *hrtimer)
580 struct bcm_op *op = container_of(hrtimer, struct bcm_op, thrtimer);
582 if (bcm_rx_thr_flush(op)) {
583 hrtimer_forward(hrtimer, ktime_get(), op->kt_ival2);
584 return HRTIMER_RESTART;
585 } else {
586 /* rearm throttle handling */
587 op->kt_lastmsg = ktime_set(0, 0);
588 return HRTIMER_NORESTART;
593 * bcm_rx_handler - handle a CAN frame receiption
595 static void bcm_rx_handler(struct sk_buff *skb, void *data)
597 struct bcm_op *op = (struct bcm_op *)data;
598 struct can_frame rxframe;
599 int i;
601 /* disable timeout */
602 hrtimer_cancel(&op->timer);
604 if (skb->len == sizeof(rxframe)) {
605 memcpy(&rxframe, skb->data, sizeof(rxframe));
606 /* save rx timestamp */
607 op->rx_stamp = skb->tstamp;
608 /* save originator for recvfrom() */
609 op->rx_ifindex = skb->dev->ifindex;
610 /* update statistics */
611 op->frames_abs++;
612 kfree_skb(skb);
614 } else {
615 kfree_skb(skb);
616 return;
619 if (op->can_id != rxframe.can_id)
620 return;
622 if (op->flags & RX_RTR_FRAME) {
623 /* send reply for RTR-request (placed in op->frames[0]) */
624 bcm_can_tx(op);
625 return;
628 if (op->flags & RX_FILTER_ID) {
629 /* the easiest case */
630 bcm_rx_update_and_send(op, &op->last_frames[0], &rxframe);
631 bcm_rx_starttimer(op);
632 return;
635 if (op->nframes == 1) {
636 /* simple compare with index 0 */
637 bcm_rx_cmp_to_index(op, 0, &rxframe);
638 bcm_rx_starttimer(op);
639 return;
642 if (op->nframes > 1) {
644 * multiplex compare
646 * find the first multiplex mask that fits.
647 * Remark: The MUX-mask is stored in index 0
650 for (i = 1; i < op->nframes; i++) {
651 if ((GET_U64(&op->frames[0]) & GET_U64(&rxframe)) ==
652 (GET_U64(&op->frames[0]) &
653 GET_U64(&op->frames[i]))) {
654 bcm_rx_cmp_to_index(op, i, &rxframe);
655 break;
658 bcm_rx_starttimer(op);
663 * helpers for bcm_op handling: find & delete bcm [rx|tx] op elements
665 static struct bcm_op *bcm_find_op(struct list_head *ops, canid_t can_id,
666 int ifindex)
668 struct bcm_op *op;
670 list_for_each_entry(op, ops, list) {
671 if ((op->can_id == can_id) && (op->ifindex == ifindex))
672 return op;
675 return NULL;
678 static void bcm_remove_op(struct bcm_op *op)
680 hrtimer_cancel(&op->timer);
681 hrtimer_cancel(&op->thrtimer);
683 if ((op->frames) && (op->frames != &op->sframe))
684 kfree(op->frames);
686 if ((op->last_frames) && (op->last_frames != &op->last_sframe))
687 kfree(op->last_frames);
689 kfree(op);
691 return;
694 static void bcm_rx_unreg(struct net_device *dev, struct bcm_op *op)
696 if (op->rx_reg_dev == dev) {
697 can_rx_unregister(dev, op->can_id, REGMASK(op->can_id),
698 bcm_rx_handler, op);
700 /* mark as removed subscription */
701 op->rx_reg_dev = NULL;
702 } else
703 printk(KERN_ERR "can-bcm: bcm_rx_unreg: registered device "
704 "mismatch %p %p\n", op->rx_reg_dev, dev);
708 * bcm_delete_rx_op - find and remove a rx op (returns number of removed ops)
710 static int bcm_delete_rx_op(struct list_head *ops, canid_t can_id, int ifindex)
712 struct bcm_op *op, *n;
714 list_for_each_entry_safe(op, n, ops, list) {
715 if ((op->can_id == can_id) && (op->ifindex == ifindex)) {
718 * Don't care if we're bound or not (due to netdev
719 * problems) can_rx_unregister() is always a save
720 * thing to do here.
722 if (op->ifindex) {
724 * Only remove subscriptions that had not
725 * been removed due to NETDEV_UNREGISTER
726 * in bcm_notifier()
728 if (op->rx_reg_dev) {
729 struct net_device *dev;
731 dev = dev_get_by_index(&init_net,
732 op->ifindex);
733 if (dev) {
734 bcm_rx_unreg(dev, op);
735 dev_put(dev);
738 } else
739 can_rx_unregister(NULL, op->can_id,
740 REGMASK(op->can_id),
741 bcm_rx_handler, op);
743 list_del(&op->list);
744 bcm_remove_op(op);
745 return 1; /* done */
749 return 0; /* not found */
753 * bcm_delete_tx_op - find and remove a tx op (returns number of removed ops)
755 static int bcm_delete_tx_op(struct list_head *ops, canid_t can_id, int ifindex)
757 struct bcm_op *op, *n;
759 list_for_each_entry_safe(op, n, ops, list) {
760 if ((op->can_id == can_id) && (op->ifindex == ifindex)) {
761 list_del(&op->list);
762 bcm_remove_op(op);
763 return 1; /* done */
767 return 0; /* not found */
771 * bcm_read_op - read out a bcm_op and send it to the user (for bcm_sendmsg)
773 static int bcm_read_op(struct list_head *ops, struct bcm_msg_head *msg_head,
774 int ifindex)
776 struct bcm_op *op = bcm_find_op(ops, msg_head->can_id, ifindex);
778 if (!op)
779 return -EINVAL;
781 /* put current values into msg_head */
782 msg_head->flags = op->flags;
783 msg_head->count = op->count;
784 msg_head->ival1 = op->ival1;
785 msg_head->ival2 = op->ival2;
786 msg_head->nframes = op->nframes;
788 bcm_send_to_user(op, msg_head, op->frames, 0);
790 return MHSIZ;
794 * bcm_tx_setup - create or update a bcm tx op (for bcm_sendmsg)
796 static int bcm_tx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg,
797 int ifindex, struct sock *sk)
799 struct bcm_sock *bo = bcm_sk(sk);
800 struct bcm_op *op;
801 int i, err;
803 /* we need a real device to send frames */
804 if (!ifindex)
805 return -ENODEV;
807 /* we need at least one can_frame */
808 if (msg_head->nframes < 1)
809 return -EINVAL;
811 /* check the given can_id */
812 op = bcm_find_op(&bo->tx_ops, msg_head->can_id, ifindex);
814 if (op) {
815 /* update existing BCM operation */
818 * Do we need more space for the can_frames than currently
819 * allocated? -> This is a _really_ unusual use-case and
820 * therefore (complexity / locking) it is not supported.
822 if (msg_head->nframes > op->nframes)
823 return -E2BIG;
825 /* update can_frames content */
826 for (i = 0; i < msg_head->nframes; i++) {
827 err = memcpy_fromiovec((u8 *)&op->frames[i],
828 msg->msg_iov, CFSIZ);
830 if (op->frames[i].can_dlc > 8)
831 err = -EINVAL;
833 if (err < 0)
834 return err;
836 if (msg_head->flags & TX_CP_CAN_ID) {
837 /* copy can_id into frame */
838 op->frames[i].can_id = msg_head->can_id;
842 } else {
843 /* insert new BCM operation for the given can_id */
845 op = kzalloc(OPSIZ, GFP_KERNEL);
846 if (!op)
847 return -ENOMEM;
849 op->can_id = msg_head->can_id;
851 /* create array for can_frames and copy the data */
852 if (msg_head->nframes > 1) {
853 op->frames = kmalloc(msg_head->nframes * CFSIZ,
854 GFP_KERNEL);
855 if (!op->frames) {
856 kfree(op);
857 return -ENOMEM;
859 } else
860 op->frames = &op->sframe;
862 for (i = 0; i < msg_head->nframes; i++) {
863 err = memcpy_fromiovec((u8 *)&op->frames[i],
864 msg->msg_iov, CFSIZ);
866 if (op->frames[i].can_dlc > 8)
867 err = -EINVAL;
869 if (err < 0) {
870 if (op->frames != &op->sframe)
871 kfree(op->frames);
872 kfree(op);
873 return err;
876 if (msg_head->flags & TX_CP_CAN_ID) {
877 /* copy can_id into frame */
878 op->frames[i].can_id = msg_head->can_id;
882 /* tx_ops never compare with previous received messages */
883 op->last_frames = NULL;
885 /* bcm_can_tx / bcm_tx_timeout_handler needs this */
886 op->sk = sk;
887 op->ifindex = ifindex;
889 /* initialize uninitialized (kzalloc) structure */
890 hrtimer_init(&op->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
891 op->timer.function = bcm_tx_timeout_handler;
893 /* currently unused in tx_ops */
894 hrtimer_init(&op->thrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
896 /* add this bcm_op to the list of the tx_ops */
897 list_add(&op->list, &bo->tx_ops);
899 } /* if ((op = bcm_find_op(&bo->tx_ops, msg_head->can_id, ifindex))) */
901 if (op->nframes != msg_head->nframes) {
902 op->nframes = msg_head->nframes;
903 /* start multiple frame transmission with index 0 */
904 op->currframe = 0;
907 /* check flags */
909 op->flags = msg_head->flags;
911 if (op->flags & TX_RESET_MULTI_IDX) {
912 /* start multiple frame transmission with index 0 */
913 op->currframe = 0;
916 if (op->flags & SETTIMER) {
917 /* set timer values */
918 op->count = msg_head->count;
919 op->ival1 = msg_head->ival1;
920 op->ival2 = msg_head->ival2;
921 op->kt_ival1 = timeval_to_ktime(msg_head->ival1);
922 op->kt_ival2 = timeval_to_ktime(msg_head->ival2);
924 /* disable an active timer due to zero values? */
925 if (!op->kt_ival1.tv64 && !op->kt_ival2.tv64)
926 hrtimer_cancel(&op->timer);
929 if ((op->flags & STARTTIMER) &&
930 ((op->kt_ival1.tv64 && op->count) || op->kt_ival2.tv64)) {
932 /* spec: send can_frame when starting timer */
933 op->flags |= TX_ANNOUNCE;
935 if (op->kt_ival1.tv64 && (op->count > 0)) {
936 /* op->count-- is done in bcm_tx_timeout_handler */
937 hrtimer_start(&op->timer, op->kt_ival1,
938 HRTIMER_MODE_REL);
939 } else
940 hrtimer_start(&op->timer, op->kt_ival2,
941 HRTIMER_MODE_REL);
944 if (op->flags & TX_ANNOUNCE)
945 bcm_can_tx(op);
947 return msg_head->nframes * CFSIZ + MHSIZ;
951 * bcm_rx_setup - create or update a bcm rx op (for bcm_sendmsg)
953 static int bcm_rx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg,
954 int ifindex, struct sock *sk)
956 struct bcm_sock *bo = bcm_sk(sk);
957 struct bcm_op *op;
958 int do_rx_register;
959 int err = 0;
961 if ((msg_head->flags & RX_FILTER_ID) || (!(msg_head->nframes))) {
962 /* be robust against wrong usage ... */
963 msg_head->flags |= RX_FILTER_ID;
964 /* ignore trailing garbage */
965 msg_head->nframes = 0;
968 if ((msg_head->flags & RX_RTR_FRAME) &&
969 ((msg_head->nframes != 1) ||
970 (!(msg_head->can_id & CAN_RTR_FLAG))))
971 return -EINVAL;
973 /* check the given can_id */
974 op = bcm_find_op(&bo->rx_ops, msg_head->can_id, ifindex);
975 if (op) {
976 /* update existing BCM operation */
979 * Do we need more space for the can_frames than currently
980 * allocated? -> This is a _really_ unusual use-case and
981 * therefore (complexity / locking) it is not supported.
983 if (msg_head->nframes > op->nframes)
984 return -E2BIG;
986 if (msg_head->nframes) {
987 /* update can_frames content */
988 err = memcpy_fromiovec((u8 *)op->frames,
989 msg->msg_iov,
990 msg_head->nframes * CFSIZ);
991 if (err < 0)
992 return err;
994 /* clear last_frames to indicate 'nothing received' */
995 memset(op->last_frames, 0, msg_head->nframes * CFSIZ);
998 op->nframes = msg_head->nframes;
1000 /* Only an update -> do not call can_rx_register() */
1001 do_rx_register = 0;
1003 } else {
1004 /* insert new BCM operation for the given can_id */
1005 op = kzalloc(OPSIZ, GFP_KERNEL);
1006 if (!op)
1007 return -ENOMEM;
1009 op->can_id = msg_head->can_id;
1010 op->nframes = msg_head->nframes;
1012 if (msg_head->nframes > 1) {
1013 /* create array for can_frames and copy the data */
1014 op->frames = kmalloc(msg_head->nframes * CFSIZ,
1015 GFP_KERNEL);
1016 if (!op->frames) {
1017 kfree(op);
1018 return -ENOMEM;
1021 /* create and init array for received can_frames */
1022 op->last_frames = kzalloc(msg_head->nframes * CFSIZ,
1023 GFP_KERNEL);
1024 if (!op->last_frames) {
1025 kfree(op->frames);
1026 kfree(op);
1027 return -ENOMEM;
1030 } else {
1031 op->frames = &op->sframe;
1032 op->last_frames = &op->last_sframe;
1035 if (msg_head->nframes) {
1036 err = memcpy_fromiovec((u8 *)op->frames, msg->msg_iov,
1037 msg_head->nframes * CFSIZ);
1038 if (err < 0) {
1039 if (op->frames != &op->sframe)
1040 kfree(op->frames);
1041 if (op->last_frames != &op->last_sframe)
1042 kfree(op->last_frames);
1043 kfree(op);
1044 return err;
1048 /* bcm_can_tx / bcm_tx_timeout_handler needs this */
1049 op->sk = sk;
1050 op->ifindex = ifindex;
1052 /* initialize uninitialized (kzalloc) structure */
1053 hrtimer_init(&op->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
1054 op->timer.function = bcm_rx_timeout_handler;
1056 hrtimer_init(&op->thrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
1057 op->thrtimer.function = bcm_rx_thr_handler;
1059 /* add this bcm_op to the list of the rx_ops */
1060 list_add(&op->list, &bo->rx_ops);
1062 /* call can_rx_register() */
1063 do_rx_register = 1;
1065 } /* if ((op = bcm_find_op(&bo->rx_ops, msg_head->can_id, ifindex))) */
1067 /* check flags */
1068 op->flags = msg_head->flags;
1070 if (op->flags & RX_RTR_FRAME) {
1072 /* no timers in RTR-mode */
1073 hrtimer_cancel(&op->thrtimer);
1074 hrtimer_cancel(&op->timer);
1077 * funny feature in RX(!)_SETUP only for RTR-mode:
1078 * copy can_id into frame BUT without RTR-flag to
1079 * prevent a full-load-loopback-test ... ;-]
1081 if ((op->flags & TX_CP_CAN_ID) ||
1082 (op->frames[0].can_id == op->can_id))
1083 op->frames[0].can_id = op->can_id & ~CAN_RTR_FLAG;
1085 } else {
1086 if (op->flags & SETTIMER) {
1088 /* set timer value */
1089 op->ival1 = msg_head->ival1;
1090 op->ival2 = msg_head->ival2;
1091 op->kt_ival1 = timeval_to_ktime(msg_head->ival1);
1092 op->kt_ival2 = timeval_to_ktime(msg_head->ival2);
1094 /* disable an active timer due to zero value? */
1095 if (!op->kt_ival1.tv64)
1096 hrtimer_cancel(&op->timer);
1099 * In any case cancel the throttle timer, flush
1100 * potentially blocked msgs and reset throttle handling
1102 op->kt_lastmsg = ktime_set(0, 0);
1103 hrtimer_cancel(&op->thrtimer);
1104 bcm_rx_thr_flush(op);
1107 if ((op->flags & STARTTIMER) && op->kt_ival1.tv64)
1108 hrtimer_start(&op->timer, op->kt_ival1,
1109 HRTIMER_MODE_REL);
1112 /* now we can register for can_ids, if we added a new bcm_op */
1113 if (do_rx_register) {
1114 if (ifindex) {
1115 struct net_device *dev;
1117 dev = dev_get_by_index(&init_net, ifindex);
1118 if (dev) {
1119 err = can_rx_register(dev, op->can_id,
1120 REGMASK(op->can_id),
1121 bcm_rx_handler, op,
1122 "bcm");
1124 op->rx_reg_dev = dev;
1125 dev_put(dev);
1128 } else
1129 err = can_rx_register(NULL, op->can_id,
1130 REGMASK(op->can_id),
1131 bcm_rx_handler, op, "bcm");
1132 if (err) {
1133 /* this bcm rx op is broken -> remove it */
1134 list_del(&op->list);
1135 bcm_remove_op(op);
1136 return err;
1140 return msg_head->nframes * CFSIZ + MHSIZ;
1144 * bcm_tx_send - send a single CAN frame to the CAN interface (for bcm_sendmsg)
1146 static int bcm_tx_send(struct msghdr *msg, int ifindex, struct sock *sk)
1148 struct sk_buff *skb;
1149 struct net_device *dev;
1150 int err;
1152 /* we need a real device to send frames */
1153 if (!ifindex)
1154 return -ENODEV;
1156 skb = alloc_skb(CFSIZ, GFP_KERNEL);
1158 if (!skb)
1159 return -ENOMEM;
1161 err = memcpy_fromiovec(skb_put(skb, CFSIZ), msg->msg_iov, CFSIZ);
1162 if (err < 0) {
1163 kfree_skb(skb);
1164 return err;
1167 dev = dev_get_by_index(&init_net, ifindex);
1168 if (!dev) {
1169 kfree_skb(skb);
1170 return -ENODEV;
1173 skb->dev = dev;
1174 skb->sk = sk;
1175 err = can_send(skb, 1); /* send with loopback */
1176 dev_put(dev);
1178 if (err)
1179 return err;
1181 return CFSIZ + MHSIZ;
1185 * bcm_sendmsg - process BCM commands (opcodes) from the userspace
1187 static int bcm_sendmsg(struct kiocb *iocb, struct socket *sock,
1188 struct msghdr *msg, size_t size)
1190 struct sock *sk = sock->sk;
1191 struct bcm_sock *bo = bcm_sk(sk);
1192 int ifindex = bo->ifindex; /* default ifindex for this bcm_op */
1193 struct bcm_msg_head msg_head;
1194 int ret; /* read bytes or error codes as return value */
1196 if (!bo->bound)
1197 return -ENOTCONN;
1199 /* check for valid message length from userspace */
1200 if (size < MHSIZ || (size - MHSIZ) % CFSIZ)
1201 return -EINVAL;
1203 /* check for alternative ifindex for this bcm_op */
1205 if (!ifindex && msg->msg_name) {
1206 /* no bound device as default => check msg_name */
1207 struct sockaddr_can *addr =
1208 (struct sockaddr_can *)msg->msg_name;
1210 if (addr->can_family != AF_CAN)
1211 return -EINVAL;
1213 /* ifindex from sendto() */
1214 ifindex = addr->can_ifindex;
1216 if (ifindex) {
1217 struct net_device *dev;
1219 dev = dev_get_by_index(&init_net, ifindex);
1220 if (!dev)
1221 return -ENODEV;
1223 if (dev->type != ARPHRD_CAN) {
1224 dev_put(dev);
1225 return -ENODEV;
1228 dev_put(dev);
1232 /* read message head information */
1234 ret = memcpy_fromiovec((u8 *)&msg_head, msg->msg_iov, MHSIZ);
1235 if (ret < 0)
1236 return ret;
1238 lock_sock(sk);
1240 switch (msg_head.opcode) {
1242 case TX_SETUP:
1243 ret = bcm_tx_setup(&msg_head, msg, ifindex, sk);
1244 break;
1246 case RX_SETUP:
1247 ret = bcm_rx_setup(&msg_head, msg, ifindex, sk);
1248 break;
1250 case TX_DELETE:
1251 if (bcm_delete_tx_op(&bo->tx_ops, msg_head.can_id, ifindex))
1252 ret = MHSIZ;
1253 else
1254 ret = -EINVAL;
1255 break;
1257 case RX_DELETE:
1258 if (bcm_delete_rx_op(&bo->rx_ops, msg_head.can_id, ifindex))
1259 ret = MHSIZ;
1260 else
1261 ret = -EINVAL;
1262 break;
1264 case TX_READ:
1265 /* reuse msg_head for the reply to TX_READ */
1266 msg_head.opcode = TX_STATUS;
1267 ret = bcm_read_op(&bo->tx_ops, &msg_head, ifindex);
1268 break;
1270 case RX_READ:
1271 /* reuse msg_head for the reply to RX_READ */
1272 msg_head.opcode = RX_STATUS;
1273 ret = bcm_read_op(&bo->rx_ops, &msg_head, ifindex);
1274 break;
1276 case TX_SEND:
1277 /* we need exactly one can_frame behind the msg head */
1278 if ((msg_head.nframes != 1) || (size != CFSIZ + MHSIZ))
1279 ret = -EINVAL;
1280 else
1281 ret = bcm_tx_send(msg, ifindex, sk);
1282 break;
1284 default:
1285 ret = -EINVAL;
1286 break;
1289 release_sock(sk);
1291 return ret;
1295 * notification handler for netdevice status changes
1297 static int bcm_notifier(struct notifier_block *nb, unsigned long msg,
1298 void *data)
1300 struct net_device *dev = (struct net_device *)data;
1301 struct bcm_sock *bo = container_of(nb, struct bcm_sock, notifier);
1302 struct sock *sk = &bo->sk;
1303 struct bcm_op *op;
1304 int notify_enodev = 0;
1306 if (!net_eq(dev_net(dev), &init_net))
1307 return NOTIFY_DONE;
1309 if (dev->type != ARPHRD_CAN)
1310 return NOTIFY_DONE;
1312 switch (msg) {
1314 case NETDEV_UNREGISTER:
1315 lock_sock(sk);
1317 /* remove device specific receive entries */
1318 list_for_each_entry(op, &bo->rx_ops, list)
1319 if (op->rx_reg_dev == dev)
1320 bcm_rx_unreg(dev, op);
1322 /* remove device reference, if this is our bound device */
1323 if (bo->bound && bo->ifindex == dev->ifindex) {
1324 bo->bound = 0;
1325 bo->ifindex = 0;
1326 notify_enodev = 1;
1329 release_sock(sk);
1331 if (notify_enodev) {
1332 sk->sk_err = ENODEV;
1333 if (!sock_flag(sk, SOCK_DEAD))
1334 sk->sk_error_report(sk);
1336 break;
1338 case NETDEV_DOWN:
1339 if (bo->bound && bo->ifindex == dev->ifindex) {
1340 sk->sk_err = ENETDOWN;
1341 if (!sock_flag(sk, SOCK_DEAD))
1342 sk->sk_error_report(sk);
1346 return NOTIFY_DONE;
1350 * initial settings for all BCM sockets to be set at socket creation time
1352 static int bcm_init(struct sock *sk)
1354 struct bcm_sock *bo = bcm_sk(sk);
1356 bo->bound = 0;
1357 bo->ifindex = 0;
1358 bo->dropped_usr_msgs = 0;
1359 bo->bcm_proc_read = NULL;
1361 INIT_LIST_HEAD(&bo->tx_ops);
1362 INIT_LIST_HEAD(&bo->rx_ops);
1364 /* set notifier */
1365 bo->notifier.notifier_call = bcm_notifier;
1367 register_netdevice_notifier(&bo->notifier);
1369 return 0;
1373 * standard socket functions
1375 static int bcm_release(struct socket *sock)
1377 struct sock *sk = sock->sk;
1378 struct bcm_sock *bo = bcm_sk(sk);
1379 struct bcm_op *op, *next;
1381 /* remove bcm_ops, timer, rx_unregister(), etc. */
1383 unregister_netdevice_notifier(&bo->notifier);
1385 lock_sock(sk);
1387 list_for_each_entry_safe(op, next, &bo->tx_ops, list)
1388 bcm_remove_op(op);
1390 list_for_each_entry_safe(op, next, &bo->rx_ops, list) {
1392 * Don't care if we're bound or not (due to netdev problems)
1393 * can_rx_unregister() is always a save thing to do here.
1395 if (op->ifindex) {
1397 * Only remove subscriptions that had not
1398 * been removed due to NETDEV_UNREGISTER
1399 * in bcm_notifier()
1401 if (op->rx_reg_dev) {
1402 struct net_device *dev;
1404 dev = dev_get_by_index(&init_net, op->ifindex);
1405 if (dev) {
1406 bcm_rx_unreg(dev, op);
1407 dev_put(dev);
1410 } else
1411 can_rx_unregister(NULL, op->can_id,
1412 REGMASK(op->can_id),
1413 bcm_rx_handler, op);
1415 bcm_remove_op(op);
1418 /* remove procfs entry */
1419 if (proc_dir && bo->bcm_proc_read)
1420 remove_proc_entry(bo->procname, proc_dir);
1422 /* remove device reference */
1423 if (bo->bound) {
1424 bo->bound = 0;
1425 bo->ifindex = 0;
1428 release_sock(sk);
1429 sock_put(sk);
1431 return 0;
1434 static int bcm_connect(struct socket *sock, struct sockaddr *uaddr, int len,
1435 int flags)
1437 struct sockaddr_can *addr = (struct sockaddr_can *)uaddr;
1438 struct sock *sk = sock->sk;
1439 struct bcm_sock *bo = bcm_sk(sk);
1441 if (bo->bound)
1442 return -EISCONN;
1444 /* bind a device to this socket */
1445 if (addr->can_ifindex) {
1446 struct net_device *dev;
1448 dev = dev_get_by_index(&init_net, addr->can_ifindex);
1449 if (!dev)
1450 return -ENODEV;
1452 if (dev->type != ARPHRD_CAN) {
1453 dev_put(dev);
1454 return -ENODEV;
1457 bo->ifindex = dev->ifindex;
1458 dev_put(dev);
1460 } else {
1461 /* no interface reference for ifindex = 0 ('any' CAN device) */
1462 bo->ifindex = 0;
1465 bo->bound = 1;
1467 if (proc_dir) {
1468 /* unique socket address as filename */
1469 sprintf(bo->procname, "%p", sock);
1470 bo->bcm_proc_read = create_proc_read_entry(bo->procname, 0644,
1471 proc_dir,
1472 bcm_read_proc, sk);
1475 return 0;
1478 static int bcm_recvmsg(struct kiocb *iocb, struct socket *sock,
1479 struct msghdr *msg, size_t size, int flags)
1481 struct sock *sk = sock->sk;
1482 struct sk_buff *skb;
1483 int error = 0;
1484 int noblock;
1485 int err;
1487 noblock = flags & MSG_DONTWAIT;
1488 flags &= ~MSG_DONTWAIT;
1489 skb = skb_recv_datagram(sk, flags, noblock, &error);
1490 if (!skb)
1491 return error;
1493 if (skb->len < size)
1494 size = skb->len;
1496 err = memcpy_toiovec(msg->msg_iov, skb->data, size);
1497 if (err < 0) {
1498 skb_free_datagram(sk, skb);
1499 return err;
1502 sock_recv_timestamp(msg, sk, skb);
1504 if (msg->msg_name) {
1505 msg->msg_namelen = sizeof(struct sockaddr_can);
1506 memcpy(msg->msg_name, skb->cb, msg->msg_namelen);
1509 skb_free_datagram(sk, skb);
1511 return size;
1514 static struct proto_ops bcm_ops __read_mostly = {
1515 .family = PF_CAN,
1516 .release = bcm_release,
1517 .bind = sock_no_bind,
1518 .connect = bcm_connect,
1519 .socketpair = sock_no_socketpair,
1520 .accept = sock_no_accept,
1521 .getname = sock_no_getname,
1522 .poll = datagram_poll,
1523 .ioctl = NULL, /* use can_ioctl() from af_can.c */
1524 .listen = sock_no_listen,
1525 .shutdown = sock_no_shutdown,
1526 .setsockopt = sock_no_setsockopt,
1527 .getsockopt = sock_no_getsockopt,
1528 .sendmsg = bcm_sendmsg,
1529 .recvmsg = bcm_recvmsg,
1530 .mmap = sock_no_mmap,
1531 .sendpage = sock_no_sendpage,
1534 static struct proto bcm_proto __read_mostly = {
1535 .name = "CAN_BCM",
1536 .owner = THIS_MODULE,
1537 .obj_size = sizeof(struct bcm_sock),
1538 .init = bcm_init,
1541 static struct can_proto bcm_can_proto __read_mostly = {
1542 .type = SOCK_DGRAM,
1543 .protocol = CAN_BCM,
1544 .capability = -1,
1545 .ops = &bcm_ops,
1546 .prot = &bcm_proto,
1549 static int __init bcm_module_init(void)
1551 int err;
1553 printk(banner);
1555 err = can_proto_register(&bcm_can_proto);
1556 if (err < 0) {
1557 printk(KERN_ERR "can: registration of bcm protocol failed\n");
1558 return err;
1561 /* create /proc/net/can-bcm directory */
1562 proc_dir = proc_mkdir("can-bcm", init_net.proc_net);
1564 if (proc_dir)
1565 proc_dir->owner = THIS_MODULE;
1567 return 0;
1570 static void __exit bcm_module_exit(void)
1572 can_proto_unregister(&bcm_can_proto);
1574 if (proc_dir)
1575 proc_net_remove(&init_net, "can-bcm");
1578 module_init(bcm_module_init);
1579 module_exit(bcm_module_exit);