Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions scapy/contrib/isotp/isotp_soft_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ def __init__(self,

self.rx_queue = ObjectPipe[Tuple[bytes, Union[float, EDecimal]]]()
self.rx_len = -1
self.rx_buf = None # type: Optional[bytes]
self.rx_buf = None # type: Optional[bytearray]
self.rx_sn = 0
self.rx_bs = 0
self.rx_idx = 0
Expand Down Expand Up @@ -1001,7 +1001,7 @@ def _recv_ff(self, data, ts):
# copy the first received data bytes
data_bytes = data[ff_pci_sz:]
self.rx_idx = len(data_bytes)
self.rx_buf = data_bytes
self.rx_buf = bytearray(data_bytes)
self.rx_ts = ts

# initial setup for this pdu reception
Expand Down Expand Up @@ -1060,14 +1060,13 @@ def _recv_cf(self, data):
return

self.rx_sn = (self.rx_sn + 1) % 16
self.rx_buf += data[1:]
self.rx_buf.extend(data[1:])
self.rx_idx = len(self.rx_buf)

if self.rx_idx >= self.rx_len:
# we are done
self.rx_buf = self.rx_buf[0:self.rx_len]
self.rx_state = ISOTP_IDLE
self.rx_queue.send((self.rx_buf, self.rx_ts))
self.rx_queue.send((bytes(self.rx_buf[0:self.rx_len]), self.rx_ts))
self.rx_buf = None
return

Expand Down
11 changes: 11 additions & 0 deletions test/contrib/isotp_soft_socket.uts
Original file line number Diff line number Diff line change
Expand Up @@ -2913,6 +2913,17 @@ with ISOTPSoftSocket(TestSocket(CAN), rx_id=0x123) as s:
s.impl._recv_cf(b"\x21\xAA") # Wrong SN
assert s.impl.rx_state == 0

= Long receive extends the existing reassembly buffer
from scapy.contrib.isotp import ISOTPSoftSocket
from scapy.layers.can import CAN
from test.testsocket import TestSocket

with ISOTPSoftSocket(TestSocket(CAN), rx_id=0x123, listen_only=True) as s:
s.impl._recv_ff(bytes.fromhex("10 00 00 00 13 88 41 41"), 1.23)
reassembly_buffer = s.impl.rx_buf
s.impl._recv_cf(bytes.fromhex("21 41 41 41 41 41 41 41"))
assert s.impl.rx_buf is reassembly_buffer

= begin_send busy / too much data
with ISOTPSoftSocket(TestSocket(CAN), tx_id=0x123) as s:
s.impl.tx_state = 1
Expand Down
Loading