1 // SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
2 /* isotp.c - ISO 15765-2 CAN transport protocol for protocol family CAN
4 * This implementation does not provide ISO-TP specific return values to the
7 * - RX path timeout of data reception leads to -ETIMEDOUT
8 * - RX path SN mismatch leads to -EILSEQ
9 * - RX path data reception with wrong padding leads to -EBADMSG
10 * - TX path flowcontrol reception timeout leads to -ECOMM
11 * - TX path flowcontrol reception overflow leads to -EMSGSIZE
12 * - TX path flowcontrol reception with wrong layout/padding leads to -EBADMSG
13 * - when a transfer (tx) is on the run the next write() blocks until it's done
14 * - use CAN_ISOTP_WAIT_TX_DONE flag to block the caller until the PDU is sent
15 * - as we have static buffers the check whether the PDU fits into the buffer
16 * is done at FF reception time (no support for sending 'wait frames')
18 * Copyright (c) 2020 Volkswagen Group Electronic Research
19 * All rights reserved.
21 * Redistribution and use in source and binary forms, with or without
22 * modification, are permitted provided that the following conditions
24 * 1. Redistributions of source code must retain the above copyright
25 * notice, this list of conditions and the following disclaimer.
26 * 2. Redistributions in binary form must reproduce the above copyright
27 * notice, this list of conditions and the following disclaimer in the
28 * documentation and/or other materials provided with the distribution.
29 * 3. Neither the name of Volkswagen nor the names of its contributors
30 * may be used to endorse or promote products derived from this software
31 * without specific prior written permission.
33 * Alternatively, provided that this notice is retained in full, this
34 * software may be distributed under the terms of the GNU General
35 * Public License ("GPL") version 2, in which case the provisions of the
36 * GPL apply INSTEAD OF those given above.
38 * The provided data structures and external interfaces from this code
39 * are not restricted to be used by modules with a GPL compatible license.
41 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
42 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
43 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
44 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
45 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
46 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
47 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
48 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
49 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
50 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
51 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
55 #include <linux/module.h>
56 #include <linux/init.h>
57 #include <linux/interrupt.h>
58 #include <linux/spinlock.h>
59 #include <linux/hrtimer.h>
60 #include <linux/wait.h>
61 #include <linux/uio.h>
62 #include <linux/net.h>
63 #include <linux/netdevice.h>
64 #include <linux/socket.h>
65 #include <linux/if_arp.h>
66 #include <linux/skbuff.h>
67 #include <linux/can.h>
68 #include <linux/can/core.h>
69 #include <linux/can/skb.h>
70 #include <linux/can/isotp.h>
71 #include <linux/slab.h>
73 #include <net/net_namespace.h>
75 MODULE_DESCRIPTION("PF_CAN isotp 15765-2:2016 protocol");
76 MODULE_LICENSE("Dual BSD/GPL");
77 MODULE_AUTHOR("Oliver Hartkopp <socketcan@hartkopp.net>");
78 MODULE_ALIAS("can-proto-6");
80 #define ISOTP_MIN_NAMELEN CAN_REQUIRED_SIZE(struct sockaddr_can, can_addr.tp)
82 #define SINGLE_MASK(id) (((id) & CAN_EFF_FLAG) ? \
83 (CAN_EFF_MASK | CAN_EFF_FLAG | CAN_RTR_FLAG) : \
84 (CAN_SFF_MASK | CAN_EFF_FLAG | CAN_RTR_FLAG))
86 /* ISO 15765-2:2016 supports more than 4095 byte per ISO PDU as the FF_DL can
87 * take full 32 bit values (4 Gbyte). We would need some good concept to handle
88 * this between user space and kernel space. For now increase the static buffer
89 * to something about 64 kbyte to be able to test this new functionality.
91 #define MAX_MSG_LENGTH 66000
93 /* N_PCI type values in bits 7-4 of N_PCI bytes */
94 #define N_PCI_SF 0x00 /* single frame */
95 #define N_PCI_FF 0x10 /* first frame */
96 #define N_PCI_CF 0x20 /* consecutive frame */
97 #define N_PCI_FC 0x30 /* flow control */
99 #define N_PCI_SZ 1 /* size of the PCI byte #1 */
100 #define SF_PCI_SZ4 1 /* size of SingleFrame PCI including 4 bit SF_DL */
101 #define SF_PCI_SZ8 2 /* size of SingleFrame PCI including 8 bit SF_DL */
102 #define FF_PCI_SZ12 2 /* size of FirstFrame PCI including 12 bit FF_DL */
103 #define FF_PCI_SZ32 6 /* size of FirstFrame PCI including 32 bit FF_DL */
104 #define FC_CONTENT_SZ 3 /* flow control content size in byte (FS/BS/STmin) */
106 #define ISOTP_CHECK_PADDING (CAN_ISOTP_CHK_PAD_LEN | CAN_ISOTP_CHK_PAD_DATA)
108 /* Flow Status given in FC frame */
109 #define ISOTP_FC_CTS 0 /* clear to send */
110 #define ISOTP_FC_WT 1 /* wait */
111 #define ISOTP_FC_OVFLW 2 /* overflow */
128 u8 buf[MAX_MSG_LENGTH + 1];
138 ktime_t lastrxcf_tstamp;
139 struct hrtimer rxtimer, txtimer;
140 struct can_isotp_options opt;
141 struct can_isotp_fc_options rxfc, txfc;
142 struct can_isotp_ll_options ll;
146 u32 cfecho; /* consecutive frame echo tag */
148 struct list_head notifier;
149 wait_queue_head_t wait;
150 spinlock_t rx_lock; /* protect single thread state machine */
153 static LIST_HEAD(isotp_notifier_list);
154 static DEFINE_SPINLOCK(isotp_notifier_lock);
155 static struct isotp_sock *isotp_busy_notifier;
157 static inline struct isotp_sock *isotp_sk(const struct sock *sk)
159 return (struct isotp_sock *)sk;
162 static enum hrtimer_restart isotp_rx_timer_handler(struct hrtimer *hrtimer)
164 struct isotp_sock *so = container_of(hrtimer, struct isotp_sock,
166 struct sock *sk = &so->sk;
168 if (so->rx.state == ISOTP_WAIT_DATA) {
169 /* we did not get new data frames in time */
171 /* report 'connection timed out' */
172 sk->sk_err = ETIMEDOUT;
173 if (!sock_flag(sk, SOCK_DEAD))
177 so->rx.state = ISOTP_IDLE;
180 return HRTIMER_NORESTART;
183 static int isotp_send_fc(struct sock *sk, int ae, u8 flowstatus)
185 struct net_device *dev;
186 struct sk_buff *nskb;
187 struct canfd_frame *ncf;
188 struct isotp_sock *so = isotp_sk(sk);
191 nskb = alloc_skb(so->ll.mtu + sizeof(struct can_skb_priv), gfp_any());
195 dev = dev_get_by_index(sock_net(sk), so->ifindex);
201 can_skb_reserve(nskb);
202 can_skb_prv(nskb)->ifindex = dev->ifindex;
203 can_skb_prv(nskb)->skbcnt = 0;
206 can_skb_set_owner(nskb, sk);
207 ncf = (struct canfd_frame *)nskb->data;
208 skb_put_zero(nskb, so->ll.mtu);
210 /* create & send flow control reply */
211 ncf->can_id = so->txid;
213 if (so->opt.flags & CAN_ISOTP_TX_PADDING) {
214 memset(ncf->data, so->opt.txpad_content, CAN_MAX_DLEN);
215 ncf->len = CAN_MAX_DLEN;
217 ncf->len = ae + FC_CONTENT_SZ;
220 ncf->data[ae] = N_PCI_FC | flowstatus;
221 ncf->data[ae + 1] = so->rxfc.bs;
222 ncf->data[ae + 2] = so->rxfc.stmin;
225 ncf->data[0] = so->opt.ext_address;
227 ncf->flags = so->ll.tx_flags;
229 can_send_ret = can_send(nskb, 1);
231 pr_notice_once("can-isotp: %s: can_send_ret %pe\n",
232 __func__, ERR_PTR(can_send_ret));
236 /* reset blocksize counter */
239 /* reset last CF frame rx timestamp for rx stmin enforcement */
240 so->lastrxcf_tstamp = ktime_set(0, 0);
242 /* start rx timeout watchdog */
243 hrtimer_start(&so->rxtimer, ktime_set(1, 0), HRTIMER_MODE_REL_SOFT);
247 static void isotp_rcv_skb(struct sk_buff *skb, struct sock *sk)
249 struct sockaddr_can *addr = (struct sockaddr_can *)skb->cb;
251 BUILD_BUG_ON(sizeof(skb->cb) < sizeof(struct sockaddr_can));
253 memset(addr, 0, sizeof(*addr));
254 addr->can_family = AF_CAN;
255 addr->can_ifindex = skb->dev->ifindex;
257 if (sock_queue_rcv_skb(sk, skb) < 0)
261 static u8 padlen(u8 datalen)
263 static const u8 plen[] = {
264 8, 8, 8, 8, 8, 8, 8, 8, 8, /* 0 - 8 */
265 12, 12, 12, 12, /* 9 - 12 */
266 16, 16, 16, 16, /* 13 - 16 */
267 20, 20, 20, 20, /* 17 - 20 */
268 24, 24, 24, 24, /* 21 - 24 */
269 32, 32, 32, 32, 32, 32, 32, 32, /* 25 - 32 */
270 48, 48, 48, 48, 48, 48, 48, 48, /* 33 - 40 */
271 48, 48, 48, 48, 48, 48, 48, 48 /* 41 - 48 */
277 return plen[datalen];
280 /* check for length optimization and return 1/true when the check fails */
281 static int check_optimized(struct canfd_frame *cf, int start_index)
283 /* for CAN_DL <= 8 the start_index is equal to the CAN_DL as the
284 * padding would start at this point. E.g. if the padding would
285 * start at cf.data[7] cf->len has to be 7 to be optimal.
286 * Note: The data[] index starts with zero.
288 if (cf->len <= CAN_MAX_DLEN)
289 return (cf->len != start_index);
291 /* This relation is also valid in the non-linear DLC range, where
292 * we need to take care of the minimal next possible CAN_DL.
293 * The correct check would be (padlen(cf->len) != padlen(start_index)).
294 * But as cf->len can only take discrete values from 12, .., 64 at this
295 * point the padlen(cf->len) is always equal to cf->len.
297 return (cf->len != padlen(start_index));
300 /* check padding and return 1/true when the check fails */
301 static int check_pad(struct isotp_sock *so, struct canfd_frame *cf,
302 int start_index, u8 content)
306 /* no RX_PADDING value => check length of optimized frame length */
307 if (!(so->opt.flags & CAN_ISOTP_RX_PADDING)) {
308 if (so->opt.flags & CAN_ISOTP_CHK_PAD_LEN)
309 return check_optimized(cf, start_index);
311 /* no valid test against empty value => ignore frame */
315 /* check datalength of correctly padded CAN frame */
316 if ((so->opt.flags & CAN_ISOTP_CHK_PAD_LEN) &&
317 cf->len != padlen(cf->len))
320 /* check padding content */
321 if (so->opt.flags & CAN_ISOTP_CHK_PAD_DATA) {
322 for (i = start_index; i < cf->len; i++)
323 if (cf->data[i] != content)
329 static int isotp_rcv_fc(struct isotp_sock *so, struct canfd_frame *cf, int ae)
331 struct sock *sk = &so->sk;
333 if (so->tx.state != ISOTP_WAIT_FC &&
334 so->tx.state != ISOTP_WAIT_FIRST_FC)
337 hrtimer_cancel(&so->txtimer);
339 if ((cf->len < ae + FC_CONTENT_SZ) ||
340 ((so->opt.flags & ISOTP_CHECK_PADDING) &&
341 check_pad(so, cf, ae + FC_CONTENT_SZ, so->opt.rxpad_content))) {
342 /* malformed PDU - report 'not a data message' */
343 sk->sk_err = EBADMSG;
344 if (!sock_flag(sk, SOCK_DEAD))
347 so->tx.state = ISOTP_IDLE;
348 wake_up_interruptible(&so->wait);
352 /* get communication parameters only from the first FC frame */
353 if (so->tx.state == ISOTP_WAIT_FIRST_FC) {
354 so->txfc.bs = cf->data[ae + 1];
355 so->txfc.stmin = cf->data[ae + 2];
357 /* fix wrong STmin values according spec */
358 if (so->txfc.stmin > 0x7F &&
359 (so->txfc.stmin < 0xF1 || so->txfc.stmin > 0xF9))
360 so->txfc.stmin = 0x7F;
362 so->tx_gap = ktime_set(0, 0);
363 /* add transmission time for CAN frame N_As */
364 so->tx_gap = ktime_add_ns(so->tx_gap, so->frame_txtime);
365 /* add waiting time for consecutive frames N_Cs */
366 if (so->opt.flags & CAN_ISOTP_FORCE_TXSTMIN)
367 so->tx_gap = ktime_add_ns(so->tx_gap,
369 else if (so->txfc.stmin < 0x80)
370 so->tx_gap = ktime_add_ns(so->tx_gap,
371 so->txfc.stmin * 1000000);
373 so->tx_gap = ktime_add_ns(so->tx_gap,
374 (so->txfc.stmin - 0xF0)
376 so->tx.state = ISOTP_WAIT_FC;
379 switch (cf->data[ae] & 0x0F) {
382 so->tx.state = ISOTP_SENDING;
383 /* start cyclic timer for sending CF frame */
384 hrtimer_start(&so->txtimer, so->tx_gap,
385 HRTIMER_MODE_REL_SOFT);
389 /* start timer to wait for next FC frame */
390 hrtimer_start(&so->txtimer, ktime_set(1, 0),
391 HRTIMER_MODE_REL_SOFT);
395 /* overflow on receiver side - report 'message too long' */
396 sk->sk_err = EMSGSIZE;
397 if (!sock_flag(sk, SOCK_DEAD))
402 /* stop this tx job */
403 so->tx.state = ISOTP_IDLE;
404 wake_up_interruptible(&so->wait);
409 static int isotp_rcv_sf(struct sock *sk, struct canfd_frame *cf, int pcilen,
410 struct sk_buff *skb, int len)
412 struct isotp_sock *so = isotp_sk(sk);
413 struct sk_buff *nskb;
415 hrtimer_cancel(&so->rxtimer);
416 so->rx.state = ISOTP_IDLE;
418 if (!len || len > cf->len - pcilen)
421 if ((so->opt.flags & ISOTP_CHECK_PADDING) &&
422 check_pad(so, cf, pcilen + len, so->opt.rxpad_content)) {
423 /* malformed PDU - report 'not a data message' */
424 sk->sk_err = EBADMSG;
425 if (!sock_flag(sk, SOCK_DEAD))
430 nskb = alloc_skb(len, gfp_any());
434 memcpy(skb_put(nskb, len), &cf->data[pcilen], len);
436 nskb->tstamp = skb->tstamp;
437 nskb->dev = skb->dev;
438 isotp_rcv_skb(nskb, sk);
442 static int isotp_rcv_ff(struct sock *sk, struct canfd_frame *cf, int ae)
444 struct isotp_sock *so = isotp_sk(sk);
449 hrtimer_cancel(&so->rxtimer);
450 so->rx.state = ISOTP_IDLE;
452 /* get the used sender LL_DL from the (first) CAN frame data length */
453 so->rx.ll_dl = padlen(cf->len);
455 /* the first frame has to use the entire frame up to LL_DL length */
456 if (cf->len != so->rx.ll_dl)
460 so->rx.len = (cf->data[ae] & 0x0F) << 8;
461 so->rx.len += cf->data[ae + 1];
463 /* Check for FF_DL escape sequence supporting 32 bit PDU length */
465 ff_pci_sz = FF_PCI_SZ12;
467 /* FF_DL = 0 => get real length from next 4 bytes */
468 so->rx.len = cf->data[ae + 2] << 24;
469 so->rx.len += cf->data[ae + 3] << 16;
470 so->rx.len += cf->data[ae + 4] << 8;
471 so->rx.len += cf->data[ae + 5];
472 ff_pci_sz = FF_PCI_SZ32;
475 /* take care of a potential SF_DL ESC offset for TX_DL > 8 */
476 off = (so->rx.ll_dl > CAN_MAX_DLEN) ? 1 : 0;
478 if (so->rx.len + ae + off + ff_pci_sz < so->rx.ll_dl)
481 if (so->rx.len > MAX_MSG_LENGTH) {
482 /* send FC frame with overflow status */
483 isotp_send_fc(sk, ae, ISOTP_FC_OVFLW);
487 /* copy the first received data bytes */
489 for (i = ae + ff_pci_sz; i < so->rx.ll_dl; i++)
490 so->rx.buf[so->rx.idx++] = cf->data[i];
492 /* initial setup for this pdu reception */
494 so->rx.state = ISOTP_WAIT_DATA;
496 /* no creation of flow control frames */
497 if (so->opt.flags & CAN_ISOTP_LISTEN_MODE)
500 /* send our first FC frame */
501 isotp_send_fc(sk, ae, ISOTP_FC_CTS);
505 static int isotp_rcv_cf(struct sock *sk, struct canfd_frame *cf, int ae,
508 struct isotp_sock *so = isotp_sk(sk);
509 struct sk_buff *nskb;
512 if (so->rx.state != ISOTP_WAIT_DATA)
515 /* drop if timestamp gap is less than force_rx_stmin nano secs */
516 if (so->opt.flags & CAN_ISOTP_FORCE_RXSTMIN) {
517 if (ktime_to_ns(ktime_sub(skb->tstamp, so->lastrxcf_tstamp)) <
521 so->lastrxcf_tstamp = skb->tstamp;
524 hrtimer_cancel(&so->rxtimer);
526 /* CFs are never longer than the FF */
527 if (cf->len > so->rx.ll_dl)
530 /* CFs have usually the LL_DL length */
531 if (cf->len < so->rx.ll_dl) {
532 /* this is only allowed for the last CF */
533 if (so->rx.len - so->rx.idx > so->rx.ll_dl - ae - N_PCI_SZ)
537 if ((cf->data[ae] & 0x0F) != so->rx.sn) {
538 /* wrong sn detected - report 'illegal byte sequence' */
540 if (!sock_flag(sk, SOCK_DEAD))
544 so->rx.state = ISOTP_IDLE;
550 for (i = ae + N_PCI_SZ; i < cf->len; i++) {
551 so->rx.buf[so->rx.idx++] = cf->data[i];
552 if (so->rx.idx >= so->rx.len)
556 if (so->rx.idx >= so->rx.len) {
558 so->rx.state = ISOTP_IDLE;
560 if ((so->opt.flags & ISOTP_CHECK_PADDING) &&
561 check_pad(so, cf, i + 1, so->opt.rxpad_content)) {
562 /* malformed PDU - report 'not a data message' */
563 sk->sk_err = EBADMSG;
564 if (!sock_flag(sk, SOCK_DEAD))
569 nskb = alloc_skb(so->rx.len, gfp_any());
573 memcpy(skb_put(nskb, so->rx.len), so->rx.buf,
576 nskb->tstamp = skb->tstamp;
577 nskb->dev = skb->dev;
578 isotp_rcv_skb(nskb, sk);
582 /* perform blocksize handling, if enabled */
583 if (!so->rxfc.bs || ++so->rx.bs < so->rxfc.bs) {
584 /* start rx timeout watchdog */
585 hrtimer_start(&so->rxtimer, ktime_set(1, 0),
586 HRTIMER_MODE_REL_SOFT);
590 /* no creation of flow control frames */
591 if (so->opt.flags & CAN_ISOTP_LISTEN_MODE)
594 /* we reached the specified blocksize so->rxfc.bs */
595 isotp_send_fc(sk, ae, ISOTP_FC_CTS);
599 static void isotp_rcv(struct sk_buff *skb, void *data)
601 struct sock *sk = (struct sock *)data;
602 struct isotp_sock *so = isotp_sk(sk);
603 struct canfd_frame *cf;
604 int ae = (so->opt.flags & CAN_ISOTP_EXTEND_ADDR) ? 1 : 0;
605 u8 n_pci_type, sf_dl;
607 /* Strictly receive only frames with the configured MTU size
608 * => clear separation of CAN2.0 / CAN FD transport channels
610 if (skb->len != so->ll.mtu)
613 cf = (struct canfd_frame *)skb->data;
615 /* if enabled: check reception of my configured extended address */
616 if (ae && cf->data[0] != so->opt.rx_ext_address)
619 n_pci_type = cf->data[ae] & 0xF0;
621 /* Make sure the state changes and data structures stay consistent at
622 * CAN frame reception time. This locking is not needed in real world
623 * use cases but the inconsistency can be triggered with syzkaller.
625 spin_lock(&so->rx_lock);
627 if (so->opt.flags & CAN_ISOTP_HALF_DUPLEX) {
628 /* check rx/tx path half duplex expectations */
629 if ((so->tx.state != ISOTP_IDLE && n_pci_type != N_PCI_FC) ||
630 (so->rx.state != ISOTP_IDLE && n_pci_type == N_PCI_FC))
634 switch (n_pci_type) {
636 /* tx path: flow control frame containing the FC parameters */
637 isotp_rcv_fc(so, cf, ae);
641 /* rx path: single frame
643 * As we do not have a rx.ll_dl configuration, we can only test
644 * if the CAN frames payload length matches the LL_DL == 8
645 * requirements - no matter if it's CAN 2.0 or CAN FD
648 /* get the SF_DL from the N_PCI byte */
649 sf_dl = cf->data[ae] & 0x0F;
651 if (cf->len <= CAN_MAX_DLEN) {
652 isotp_rcv_sf(sk, cf, SF_PCI_SZ4 + ae, skb, sf_dl);
654 if (skb->len == CANFD_MTU) {
655 /* We have a CAN FD frame and CAN_DL is greater than 8:
656 * Only frames with the SF_DL == 0 ESC value are valid.
658 * If so take care of the increased SF PCI size
659 * (SF_PCI_SZ8) to point to the message content behind
660 * the extended SF PCI info and get the real SF_DL
661 * length value from the formerly first data byte.
664 isotp_rcv_sf(sk, cf, SF_PCI_SZ8 + ae, skb,
665 cf->data[SF_PCI_SZ4 + ae]);
671 /* rx path: first frame */
672 isotp_rcv_ff(sk, cf, ae);
676 /* rx path: consecutive frame */
677 isotp_rcv_cf(sk, cf, ae, skb);
682 spin_unlock(&so->rx_lock);
685 static void isotp_fill_dataframe(struct canfd_frame *cf, struct isotp_sock *so,
688 int pcilen = N_PCI_SZ + ae + off;
689 int space = so->tx.ll_dl - pcilen;
690 int num = min_t(int, so->tx.len - so->tx.idx, space);
693 cf->can_id = so->txid;
694 cf->len = num + pcilen;
697 if (so->opt.flags & CAN_ISOTP_TX_PADDING) {
698 /* user requested padding */
699 cf->len = padlen(cf->len);
700 memset(cf->data, so->opt.txpad_content, cf->len);
701 } else if (cf->len > CAN_MAX_DLEN) {
702 /* mandatory padding for CAN FD frames */
703 cf->len = padlen(cf->len);
704 memset(cf->data, CAN_ISOTP_DEFAULT_PAD_CONTENT,
709 for (i = 0; i < num; i++)
710 cf->data[pcilen + i] = so->tx.buf[so->tx.idx++];
713 cf->data[0] = so->opt.ext_address;
716 static void isotp_send_cframe(struct isotp_sock *so)
718 struct sock *sk = &so->sk;
720 struct net_device *dev;
721 struct canfd_frame *cf;
723 int ae = (so->opt.flags & CAN_ISOTP_EXTEND_ADDR) ? 1 : 0;
725 dev = dev_get_by_index(sock_net(sk), so->ifindex);
729 skb = alloc_skb(so->ll.mtu + sizeof(struct can_skb_priv), GFP_ATOMIC);
735 can_skb_reserve(skb);
736 can_skb_prv(skb)->ifindex = dev->ifindex;
737 can_skb_prv(skb)->skbcnt = 0;
739 cf = (struct canfd_frame *)skb->data;
740 skb_put_zero(skb, so->ll.mtu);
742 /* create consecutive frame */
743 isotp_fill_dataframe(cf, so, ae, 0);
745 /* place consecutive frame N_PCI in appropriate index */
746 cf->data[ae] = N_PCI_CF | so->tx.sn++;
750 cf->flags = so->ll.tx_flags;
753 can_skb_set_owner(skb, sk);
755 /* cfecho should have been zero'ed by init/isotp_rcv_echo() */
757 pr_notice_once("can-isotp: cfecho is %08X != 0\n", so->cfecho);
759 /* set consecutive frame echo tag */
760 so->cfecho = *(u32 *)cf->data;
762 /* send frame with local echo enabled */
763 can_send_ret = can_send(skb, 1);
765 pr_notice_once("can-isotp: %s: can_send_ret %pe\n",
766 __func__, ERR_PTR(can_send_ret));
767 if (can_send_ret == -ENOBUFS)
768 pr_notice_once("can-isotp: tx queue is full\n");
773 static void isotp_create_fframe(struct canfd_frame *cf, struct isotp_sock *so,
779 cf->can_id = so->txid;
780 cf->len = so->tx.ll_dl;
782 cf->data[0] = so->opt.ext_address;
784 /* create N_PCI bytes with 12/32 bit FF_DL data length */
785 if (so->tx.len > 4095) {
786 /* use 32 bit FF_DL notation */
787 cf->data[ae] = N_PCI_FF;
788 cf->data[ae + 1] = 0;
789 cf->data[ae + 2] = (u8)(so->tx.len >> 24) & 0xFFU;
790 cf->data[ae + 3] = (u8)(so->tx.len >> 16) & 0xFFU;
791 cf->data[ae + 4] = (u8)(so->tx.len >> 8) & 0xFFU;
792 cf->data[ae + 5] = (u8)so->tx.len & 0xFFU;
793 ff_pci_sz = FF_PCI_SZ32;
795 /* use 12 bit FF_DL notation */
796 cf->data[ae] = (u8)(so->tx.len >> 8) | N_PCI_FF;
797 cf->data[ae + 1] = (u8)so->tx.len & 0xFFU;
798 ff_pci_sz = FF_PCI_SZ12;
801 /* add first data bytes depending on ae */
802 for (i = ae + ff_pci_sz; i < so->tx.ll_dl; i++)
803 cf->data[i] = so->tx.buf[so->tx.idx++];
806 so->tx.state = ISOTP_WAIT_FIRST_FC;
809 static void isotp_rcv_echo(struct sk_buff *skb, void *data)
811 struct sock *sk = (struct sock *)data;
812 struct isotp_sock *so = isotp_sk(sk);
813 struct canfd_frame *cf = (struct canfd_frame *)skb->data;
815 /* only handle my own local echo skb's */
816 if (skb->sk != sk || so->cfecho != *(u32 *)cf->data)
819 /* cancel local echo timeout */
820 hrtimer_cancel(&so->txtimer);
822 /* local echo skb with consecutive frame has been consumed */
825 if (so->tx.idx >= so->tx.len) {
827 so->tx.state = ISOTP_IDLE;
828 wake_up_interruptible(&so->wait);
832 if (so->txfc.bs && so->tx.bs >= so->txfc.bs) {
833 /* stop and wait for FC with timeout */
834 so->tx.state = ISOTP_WAIT_FC;
835 hrtimer_start(&so->txtimer, ktime_set(1, 0),
836 HRTIMER_MODE_REL_SOFT);
840 /* no gap between data frames needed => use burst mode */
842 isotp_send_cframe(so);
846 /* start timer to send next consecutive frame with correct delay */
847 hrtimer_start(&so->txtimer, so->tx_gap, HRTIMER_MODE_REL_SOFT);
850 static enum hrtimer_restart isotp_tx_timer_handler(struct hrtimer *hrtimer)
852 struct isotp_sock *so = container_of(hrtimer, struct isotp_sock,
854 struct sock *sk = &so->sk;
855 enum hrtimer_restart restart = HRTIMER_NORESTART;
857 switch (so->tx.state) {
860 /* cfecho should be consumed by isotp_rcv_echo() here */
862 /* start timeout for unlikely lost echo skb */
863 hrtimer_set_expires(&so->txtimer,
864 ktime_add(ktime_get(),
866 restart = HRTIMER_RESTART;
868 /* push out the next consecutive frame */
869 isotp_send_cframe(so);
873 /* cfecho has not been cleared in isotp_rcv_echo() */
874 pr_notice_once("can-isotp: cfecho %08X timeout\n", so->cfecho);
878 case ISOTP_WAIT_FIRST_FC:
880 /* we did not get any flow control frame in time */
882 /* report 'communication error on send' */
884 if (!sock_flag(sk, SOCK_DEAD))
888 so->tx.state = ISOTP_IDLE;
889 wake_up_interruptible(&so->wait);
899 static int isotp_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
901 struct sock *sk = sock->sk;
902 struct isotp_sock *so = isotp_sk(sk);
903 u32 old_state = so->tx.state;
905 struct net_device *dev;
906 struct canfd_frame *cf;
907 int ae = (so->opt.flags & CAN_ISOTP_EXTEND_ADDR) ? 1 : 0;
908 int wait_tx_done = (so->opt.flags & CAN_ISOTP_WAIT_TX_DONE) ? 1 : 0;
913 return -EADDRNOTAVAIL;
915 /* we do not support multiple buffers - for now */
916 if (cmpxchg(&so->tx.state, ISOTP_IDLE, ISOTP_SENDING) != ISOTP_IDLE ||
917 wq_has_sleeper(&so->wait)) {
918 if (msg->msg_flags & MSG_DONTWAIT) {
923 /* wait for complete transmission of current pdu */
924 err = wait_event_interruptible(so->wait, so->tx.state == ISOTP_IDLE);
929 if (!size || size > MAX_MSG_LENGTH) {
934 /* take care of a potential SF_DL ESC offset for TX_DL > 8 */
935 off = (so->tx.ll_dl > CAN_MAX_DLEN) ? 1 : 0;
937 /* does the given data fit into a single frame for SF_BROADCAST? */
938 if ((so->opt.flags & CAN_ISOTP_SF_BROADCAST) &&
939 (size > so->tx.ll_dl - SF_PCI_SZ4 - ae - off)) {
944 err = memcpy_from_msg(so->tx.buf, msg, size);
948 dev = dev_get_by_index(sock_net(sk), so->ifindex);
954 skb = sock_alloc_send_skb(sk, so->ll.mtu + sizeof(struct can_skb_priv),
955 msg->msg_flags & MSG_DONTWAIT, &err);
961 can_skb_reserve(skb);
962 can_skb_prv(skb)->ifindex = dev->ifindex;
963 can_skb_prv(skb)->skbcnt = 0;
968 cf = (struct canfd_frame *)skb->data;
969 skb_put_zero(skb, so->ll.mtu);
971 /* check for single frame transmission depending on TX_DL */
972 if (size <= so->tx.ll_dl - SF_PCI_SZ4 - ae - off) {
973 /* The message size generally fits into a SingleFrame - good.
975 * SF_DL ESC offset optimization:
977 * When TX_DL is greater 8 but the message would still fit
978 * into a 8 byte CAN frame, we can omit the offset.
979 * This prevents a protocol caused length extension from
980 * CAN_DL = 8 to CAN_DL = 12 due to the SF_SL ESC handling.
982 if (size <= CAN_MAX_DLEN - SF_PCI_SZ4 - ae)
985 isotp_fill_dataframe(cf, so, ae, off);
987 /* place single frame N_PCI w/o length in appropriate index */
988 cf->data[ae] = N_PCI_SF;
990 /* place SF_DL size value depending on the SF_DL ESC offset */
992 cf->data[SF_PCI_SZ4 + ae] = size;
994 cf->data[ae] |= size;
996 so->tx.state = ISOTP_IDLE;
997 wake_up_interruptible(&so->wait);
999 /* don't enable wait queue for a single frame transmission */
1002 /* send first frame and wait for FC */
1004 isotp_create_fframe(cf, so, ae);
1006 /* start timeout for FC */
1007 hrtimer_start(&so->txtimer, ktime_set(1, 0), HRTIMER_MODE_REL_SOFT);
1010 /* send the first or only CAN frame */
1011 cf->flags = so->ll.tx_flags;
1015 err = can_send(skb, 1);
1018 pr_notice_once("can-isotp: %s: can_send_ret %pe\n",
1019 __func__, ERR_PTR(err));
1024 /* wait for complete transmission of current pdu */
1025 wait_event_interruptible(so->wait, so->tx.state == ISOTP_IDLE);
1034 /* drop this PDU and unlock a potential wait queue */
1035 old_state = ISOTP_IDLE;
1037 so->tx.state = old_state;
1038 if (so->tx.state == ISOTP_IDLE)
1039 wake_up_interruptible(&so->wait);
1044 static int isotp_recvmsg(struct socket *sock, struct msghdr *msg, size_t size,
1047 struct sock *sk = sock->sk;
1048 struct sk_buff *skb;
1049 struct isotp_sock *so = isotp_sk(sk);
1050 int noblock = flags & MSG_DONTWAIT;
1053 if (flags & ~(MSG_DONTWAIT | MSG_TRUNC | MSG_PEEK))
1057 return -EADDRNOTAVAIL;
1059 flags &= ~MSG_DONTWAIT;
1060 skb = skb_recv_datagram(sk, flags, noblock, &ret);
1064 if (size < skb->len)
1065 msg->msg_flags |= MSG_TRUNC;
1069 ret = memcpy_to_msg(msg, skb->data, size);
1073 sock_recv_timestamp(msg, sk, skb);
1075 if (msg->msg_name) {
1076 __sockaddr_check_size(ISOTP_MIN_NAMELEN);
1077 msg->msg_namelen = ISOTP_MIN_NAMELEN;
1078 memcpy(msg->msg_name, skb->cb, msg->msg_namelen);
1081 /* set length of return value */
1082 ret = (flags & MSG_TRUNC) ? skb->len : size;
1085 skb_free_datagram(sk, skb);
1090 static int isotp_release(struct socket *sock)
1092 struct sock *sk = sock->sk;
1093 struct isotp_sock *so;
1102 /* wait for complete transmission of current pdu */
1103 wait_event_interruptible(so->wait, so->tx.state == ISOTP_IDLE);
1105 spin_lock(&isotp_notifier_lock);
1106 while (isotp_busy_notifier == so) {
1107 spin_unlock(&isotp_notifier_lock);
1108 schedule_timeout_uninterruptible(1);
1109 spin_lock(&isotp_notifier_lock);
1111 list_del(&so->notifier);
1112 spin_unlock(&isotp_notifier_lock);
1116 /* remove current filters & unregister */
1117 if (so->bound && (!(so->opt.flags & CAN_ISOTP_SF_BROADCAST))) {
1119 struct net_device *dev;
1121 dev = dev_get_by_index(net, so->ifindex);
1123 can_rx_unregister(net, dev, so->rxid,
1124 SINGLE_MASK(so->rxid),
1126 can_rx_unregister(net, dev, so->txid,
1127 SINGLE_MASK(so->txid),
1128 isotp_rcv_echo, sk);
1135 hrtimer_cancel(&so->txtimer);
1136 hrtimer_cancel(&so->rxtimer);
1150 static int isotp_bind(struct socket *sock, struct sockaddr *uaddr, int len)
1152 struct sockaddr_can *addr = (struct sockaddr_can *)uaddr;
1153 struct sock *sk = sock->sk;
1154 struct isotp_sock *so = isotp_sk(sk);
1155 struct net *net = sock_net(sk);
1157 struct net_device *dev;
1158 canid_t tx_id, rx_id;
1160 int notify_enetdown = 0;
1163 if (len < ISOTP_MIN_NAMELEN)
1166 /* sanitize tx/rx CAN identifiers */
1167 tx_id = addr->can_addr.tp.tx_id;
1168 if (tx_id & CAN_EFF_FLAG)
1169 tx_id &= (CAN_EFF_FLAG | CAN_EFF_MASK);
1171 tx_id &= CAN_SFF_MASK;
1173 rx_id = addr->can_addr.tp.rx_id;
1174 if (rx_id & CAN_EFF_FLAG)
1175 rx_id &= (CAN_EFF_FLAG | CAN_EFF_MASK);
1177 rx_id &= CAN_SFF_MASK;
1179 if (!addr->can_ifindex)
1184 /* do not register frame reception for functional addressing */
1185 if (so->opt.flags & CAN_ISOTP_SF_BROADCAST)
1188 /* do not validate rx address for functional addressing */
1189 if (do_rx_reg && rx_id == tx_id) {
1190 err = -EADDRNOTAVAIL;
1194 if (so->bound && addr->can_ifindex == so->ifindex &&
1195 rx_id == so->rxid && tx_id == so->txid)
1198 dev = dev_get_by_index(net, addr->can_ifindex);
1203 if (dev->type != ARPHRD_CAN) {
1208 if (dev->mtu < so->ll.mtu) {
1213 if (!(dev->flags & IFF_UP))
1214 notify_enetdown = 1;
1216 ifindex = dev->ifindex;
1219 can_rx_register(net, dev, rx_id, SINGLE_MASK(rx_id),
1220 isotp_rcv, sk, "isotp", sk);
1222 /* no consecutive frame echo skb in flight */
1225 /* register for echo skb's */
1226 can_rx_register(net, dev, tx_id, SINGLE_MASK(tx_id),
1227 isotp_rcv_echo, sk, "isotpe", sk);
1232 if (so->bound && do_rx_reg) {
1233 /* unregister old filter */
1235 dev = dev_get_by_index(net, so->ifindex);
1237 can_rx_unregister(net, dev, so->rxid,
1238 SINGLE_MASK(so->rxid),
1240 can_rx_unregister(net, dev, so->txid,
1241 SINGLE_MASK(so->txid),
1242 isotp_rcv_echo, sk);
1248 /* switch to new settings */
1249 so->ifindex = ifindex;
1257 if (notify_enetdown) {
1258 sk->sk_err = ENETDOWN;
1259 if (!sock_flag(sk, SOCK_DEAD))
1260 sk_error_report(sk);
1266 static int isotp_getname(struct socket *sock, struct sockaddr *uaddr, int peer)
1268 struct sockaddr_can *addr = (struct sockaddr_can *)uaddr;
1269 struct sock *sk = sock->sk;
1270 struct isotp_sock *so = isotp_sk(sk);
1275 memset(addr, 0, ISOTP_MIN_NAMELEN);
1276 addr->can_family = AF_CAN;
1277 addr->can_ifindex = so->ifindex;
1278 addr->can_addr.tp.rx_id = so->rxid;
1279 addr->can_addr.tp.tx_id = so->txid;
1281 return ISOTP_MIN_NAMELEN;
1284 static int isotp_setsockopt_locked(struct socket *sock, int level, int optname,
1285 sockptr_t optval, unsigned int optlen)
1287 struct sock *sk = sock->sk;
1288 struct isotp_sock *so = isotp_sk(sk);
1295 case CAN_ISOTP_OPTS:
1296 if (optlen != sizeof(struct can_isotp_options))
1299 if (copy_from_sockptr(&so->opt, optval, optlen))
1302 /* no separate rx_ext_address is given => use ext_address */
1303 if (!(so->opt.flags & CAN_ISOTP_RX_EXT_ADDR))
1304 so->opt.rx_ext_address = so->opt.ext_address;
1306 /* check for frame_txtime changes (0 => no changes) */
1307 if (so->opt.frame_txtime) {
1308 if (so->opt.frame_txtime == CAN_ISOTP_FRAME_TXTIME_ZERO)
1309 so->frame_txtime = 0;
1311 so->frame_txtime = so->opt.frame_txtime;
1315 case CAN_ISOTP_RECV_FC:
1316 if (optlen != sizeof(struct can_isotp_fc_options))
1319 if (copy_from_sockptr(&so->rxfc, optval, optlen))
1323 case CAN_ISOTP_TX_STMIN:
1324 if (optlen != sizeof(u32))
1327 if (copy_from_sockptr(&so->force_tx_stmin, optval, optlen))
1331 case CAN_ISOTP_RX_STMIN:
1332 if (optlen != sizeof(u32))
1335 if (copy_from_sockptr(&so->force_rx_stmin, optval, optlen))
1339 case CAN_ISOTP_LL_OPTS:
1340 if (optlen == sizeof(struct can_isotp_ll_options)) {
1341 struct can_isotp_ll_options ll;
1343 if (copy_from_sockptr(&ll, optval, optlen))
1346 /* check for correct ISO 11898-1 DLC data length */
1347 if (ll.tx_dl != padlen(ll.tx_dl))
1350 if (ll.mtu != CAN_MTU && ll.mtu != CANFD_MTU)
1353 if (ll.mtu == CAN_MTU &&
1354 (ll.tx_dl > CAN_MAX_DLEN || ll.tx_flags != 0))
1357 memcpy(&so->ll, &ll, sizeof(ll));
1359 /* set ll_dl for tx path to similar place as for rx */
1360 so->tx.ll_dl = ll.tx_dl;
1373 static int isotp_setsockopt(struct socket *sock, int level, int optname,
1374 sockptr_t optval, unsigned int optlen)
1377 struct sock *sk = sock->sk;
1380 if (level != SOL_CAN_ISOTP)
1384 ret = isotp_setsockopt_locked(sock, level, optname, optval, optlen);
1389 static int isotp_getsockopt(struct socket *sock, int level, int optname,
1390 char __user *optval, int __user *optlen)
1392 struct sock *sk = sock->sk;
1393 struct isotp_sock *so = isotp_sk(sk);
1397 if (level != SOL_CAN_ISOTP)
1399 if (get_user(len, optlen))
1405 case CAN_ISOTP_OPTS:
1406 len = min_t(int, len, sizeof(struct can_isotp_options));
1410 case CAN_ISOTP_RECV_FC:
1411 len = min_t(int, len, sizeof(struct can_isotp_fc_options));
1415 case CAN_ISOTP_TX_STMIN:
1416 len = min_t(int, len, sizeof(u32));
1417 val = &so->force_tx_stmin;
1420 case CAN_ISOTP_RX_STMIN:
1421 len = min_t(int, len, sizeof(u32));
1422 val = &so->force_rx_stmin;
1425 case CAN_ISOTP_LL_OPTS:
1426 len = min_t(int, len, sizeof(struct can_isotp_ll_options));
1431 return -ENOPROTOOPT;
1434 if (put_user(len, optlen))
1436 if (copy_to_user(optval, val, len))
1441 static void isotp_notify(struct isotp_sock *so, unsigned long msg,
1442 struct net_device *dev)
1444 struct sock *sk = &so->sk;
1446 if (!net_eq(dev_net(dev), sock_net(sk)))
1449 if (so->ifindex != dev->ifindex)
1453 case NETDEV_UNREGISTER:
1455 /* remove current filters & unregister */
1456 if (so->bound && (!(so->opt.flags & CAN_ISOTP_SF_BROADCAST))) {
1457 can_rx_unregister(dev_net(dev), dev, so->rxid,
1458 SINGLE_MASK(so->rxid),
1460 can_rx_unregister(dev_net(dev), dev, so->txid,
1461 SINGLE_MASK(so->txid),
1462 isotp_rcv_echo, sk);
1469 sk->sk_err = ENODEV;
1470 if (!sock_flag(sk, SOCK_DEAD))
1471 sk_error_report(sk);
1475 sk->sk_err = ENETDOWN;
1476 if (!sock_flag(sk, SOCK_DEAD))
1477 sk_error_report(sk);
1482 static int isotp_notifier(struct notifier_block *nb, unsigned long msg,
1485 struct net_device *dev = netdev_notifier_info_to_dev(ptr);
1487 if (dev->type != ARPHRD_CAN)
1489 if (msg != NETDEV_UNREGISTER && msg != NETDEV_DOWN)
1491 if (unlikely(isotp_busy_notifier)) /* Check for reentrant bug. */
1494 spin_lock(&isotp_notifier_lock);
1495 list_for_each_entry(isotp_busy_notifier, &isotp_notifier_list, notifier) {
1496 spin_unlock(&isotp_notifier_lock);
1497 isotp_notify(isotp_busy_notifier, msg, dev);
1498 spin_lock(&isotp_notifier_lock);
1500 isotp_busy_notifier = NULL;
1501 spin_unlock(&isotp_notifier_lock);
1505 static int isotp_init(struct sock *sk)
1507 struct isotp_sock *so = isotp_sk(sk);
1512 so->opt.flags = CAN_ISOTP_DEFAULT_FLAGS;
1513 so->opt.ext_address = CAN_ISOTP_DEFAULT_EXT_ADDRESS;
1514 so->opt.rx_ext_address = CAN_ISOTP_DEFAULT_EXT_ADDRESS;
1515 so->opt.rxpad_content = CAN_ISOTP_DEFAULT_PAD_CONTENT;
1516 so->opt.txpad_content = CAN_ISOTP_DEFAULT_PAD_CONTENT;
1517 so->opt.frame_txtime = CAN_ISOTP_DEFAULT_FRAME_TXTIME;
1518 so->frame_txtime = CAN_ISOTP_DEFAULT_FRAME_TXTIME;
1519 so->rxfc.bs = CAN_ISOTP_DEFAULT_RECV_BS;
1520 so->rxfc.stmin = CAN_ISOTP_DEFAULT_RECV_STMIN;
1521 so->rxfc.wftmax = CAN_ISOTP_DEFAULT_RECV_WFTMAX;
1522 so->ll.mtu = CAN_ISOTP_DEFAULT_LL_MTU;
1523 so->ll.tx_dl = CAN_ISOTP_DEFAULT_LL_TX_DL;
1524 so->ll.tx_flags = CAN_ISOTP_DEFAULT_LL_TX_FLAGS;
1526 /* set ll_dl for tx path to similar place as for rx */
1527 so->tx.ll_dl = so->ll.tx_dl;
1529 so->rx.state = ISOTP_IDLE;
1530 so->tx.state = ISOTP_IDLE;
1532 hrtimer_init(&so->rxtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL_SOFT);
1533 so->rxtimer.function = isotp_rx_timer_handler;
1534 hrtimer_init(&so->txtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL_SOFT);
1535 so->txtimer.function = isotp_tx_timer_handler;
1537 init_waitqueue_head(&so->wait);
1538 spin_lock_init(&so->rx_lock);
1540 spin_lock(&isotp_notifier_lock);
1541 list_add_tail(&so->notifier, &isotp_notifier_list);
1542 spin_unlock(&isotp_notifier_lock);
1547 static int isotp_sock_no_ioctlcmd(struct socket *sock, unsigned int cmd,
1550 /* no ioctls for socket layer -> hand it down to NIC layer */
1551 return -ENOIOCTLCMD;
1554 static const struct proto_ops isotp_ops = {
1556 .release = isotp_release,
1558 .connect = sock_no_connect,
1559 .socketpair = sock_no_socketpair,
1560 .accept = sock_no_accept,
1561 .getname = isotp_getname,
1562 .poll = datagram_poll,
1563 .ioctl = isotp_sock_no_ioctlcmd,
1564 .gettstamp = sock_gettstamp,
1565 .listen = sock_no_listen,
1566 .shutdown = sock_no_shutdown,
1567 .setsockopt = isotp_setsockopt,
1568 .getsockopt = isotp_getsockopt,
1569 .sendmsg = isotp_sendmsg,
1570 .recvmsg = isotp_recvmsg,
1571 .mmap = sock_no_mmap,
1572 .sendpage = sock_no_sendpage,
1575 static struct proto isotp_proto __read_mostly = {
1576 .name = "CAN_ISOTP",
1577 .owner = THIS_MODULE,
1578 .obj_size = sizeof(struct isotp_sock),
1582 static const struct can_proto isotp_can_proto = {
1584 .protocol = CAN_ISOTP,
1586 .prot = &isotp_proto,
1589 static struct notifier_block canisotp_notifier = {
1590 .notifier_call = isotp_notifier
1593 static __init int isotp_module_init(void)
1597 pr_info("can: isotp protocol\n");
1599 err = can_proto_register(&isotp_can_proto);
1601 pr_err("can: registration of isotp protocol failed %pe\n", ERR_PTR(err));
1603 register_netdevice_notifier(&canisotp_notifier);
1608 static __exit void isotp_module_exit(void)
1610 can_proto_unregister(&isotp_can_proto);
1611 unregister_netdevice_notifier(&canisotp_notifier);
1614 module_init(isotp_module_init);
1615 module_exit(isotp_module_exit);