scapy icon indicating copy to clipboard operation
scapy copied to clipboard

ISO-TP doesn't support CAN-FD

Open ghost opened this issue 1 year ago • 3 comments

Brief description

Hi guys, We are currently trying to implement a pair of ISO-TP sender/receiver over a CAN-FD connection. As it seems there is no way to configure the ISOTPSoftSocket in such a way that it supports CAN-FD interfaces using a data length of 64 bytes.

We tried the following things to work around this:

  • Enabled the 'fd=True' flag on the FD socket. We can send FD frames in general, but the ISO-TP splits into CAN frames with 8 bytes in size (classic CAN instead of FD)
  • Manually increased the fragmentation size inside the ISO-TP component/package, but without success

Has anyone an idea of how to get to CAN-TP support for the ISO-TP package?

Thanks a lot!

Scapy version

2.5.0

Python version

3.11

Operating system

Fedora 37

Additional environment information

No response

How to reproduce

  • Create virtual CAN interface, set MTU to 72 for fake FD support
  • Implement ISO-TP receiver:
#!/usr/bin/python3

from scapy.all import *
import scapy

conf.contribs['ISOTP'] = {
    'use-can-isotp-kernel-module': False
}

load_contrib("cansocket")
load_contrib("isotp")

cansock = CANSocket("vcan0", bustype="socketcan", fd=True)

if scapy.VERSION == "2.4.5.rc1.dev32":
    kwargs = {'sid': 0x123, 'did': 0x321}
else:
    kwargs = {'rx_id': 0x123, 'tx_id': 0x321}

with ISOTPSocket(cansock, **kwargs) as isotpsock:
    data = isotpsock.recv()
    print(data)
  • Implement sender:
#!/usr/bin/python3

from scapy.all import *

conf.contribs['ISOTP'] = {
    'use-can-isotp-kernel-module': False
}

load_contrib("cansocket")
load_contrib("isotp")

if scapy.VERSION == "2.4.5.rc1.dev32":
    kwargs = {'sid': 0x321, 'did': 0x123}
else:
    kwargs = {'rx_id': 0x321, 'tx_id': 0x123}

cansock = CANSocket("vcan0", bustype="socketcan", fd=True)
with ISOTPSocket(cansock, **kwargs) as isotpsock:
    isotpsock.send(ISOTP(data=b"Hello World, this is a very long message which should be very much longer than 64 bytes."))
  • We can see via candump vcan0 that the frames are still 8 bytes in size

Actual result

No response

Expected result

No response

Related resources

No response

ghost avatar Mar 10 '23 17:03 ghost

Hi, thanks for your request.

CANFD is currently not supported by ISOTPSoftSockets. Only ISOTPNativeSockets support CANFD at the moment.

polybassa avatar Mar 10 '23 21:03 polybassa

Hi polybassa,

thanks for your quick reply. I did some research and found another python package (can-isotp) which seemingly serves our purpose.

I am curious: has adding CAN-FD support to scapy/isotp ever been considered?

ghost avatar Mar 13 '23 09:03 ghost

Well, CANFD is already added to most parts. Just the ISOTPSoftSocket doesn’t support FD yet. Feel free to submit a PR.

polydroi avatar Mar 14 '23 08:03 polydroi

This issue got fixed

polybassa avatar Apr 10 '24 09:04 polybassa