From afe82ef4762f51b670b2fc7bd4c7a9cc886e04cd Mon Sep 17 00:00:00 2001 From: devrim-ayyildiz Date: Tue, 24 Oct 2023 16:38:22 +0200 Subject: [PATCH] Pass the fd to underlying NativeCANSocket ISOTPSoftSocket should pass the fd (CanFD support) to the NativeCANSocket instance it creates. Otherwise it will always be created as non CanFD. --- scapy/contrib/isotp/isotp_soft_socket.py | 2 +- test/contrib/isotp_soft_socket.uts | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/scapy/contrib/isotp/isotp_soft_socket.py b/scapy/contrib/isotp/isotp_soft_socket.py index 3b8dc7f80ce..119917e5f44 100644 --- a/scapy/contrib/isotp/isotp_soft_socket.py +++ b/scapy/contrib/isotp/isotp_soft_socket.py @@ -133,7 +133,7 @@ def __init__(self, if LINUX and isinstance(can_socket, str): from scapy.contrib.cansocket_native import NativeCANSocket - can_socket = NativeCANSocket(can_socket) + can_socket = NativeCANSocket(can_socket, fd=fd) elif isinstance(can_socket, str): raise Scapy_Exception("Provide a CANSocket object instead") diff --git a/test/contrib/isotp_soft_socket.uts b/test/contrib/isotp_soft_socket.uts index b2b7295805d..ece7ef5f621 100644 --- a/test/contrib/isotp_soft_socket.uts +++ b/test/contrib/isotp_soft_socket.uts @@ -11,6 +11,8 @@ from scapy.layers.can import * from scapy.contrib.isotp import * from scapy.contrib.isotp.isotp_soft_socket import TimeoutScheduler from test.testsocket import TestSocket, cleanup_testsockets +with open(scapy_path("test/contrib/automotive/interface_mockup.py")) as f: + exec(f.read()) = Redirect logging import logging @@ -58,6 +60,18 @@ assert sniffed[0]['ISOTP'].rx_ext_address == 0xEA + ISOTPSoftSocket tests += CAN socket FD +~ not_pypy needs_root linux vcan_socket + +with ISOTPSoftSocket(iface0, tx_id=0x641, rx_id=0x241, fd=True) as s: + assert s.impl.can_socket.fd == True + += CAN socket non-FD +~ not_pypy needs_root linux vcan_socket + +with ISOTPSoftSocket(iface0, tx_id=0x641, rx_id=0x241) as s: + assert s.impl.can_socket.fd == False + = Single-frame receive with TestSocket(CAN) as cans, TestSocket(CAN) as stim, ISOTPSoftSocket(cans, tx_id=0x641, rx_id=0x241) as s: