From 32aa6ab84b79a58e9dd0b08e25fc849b902f259f Mon Sep 17 00:00:00 2001 From: Igor Stadnyk Date: Sun, 16 Aug 2026 09:14:37 +0100 Subject: [PATCH] Handle reserved STmin values per ISO-15765-2 --- isotp/protocol.py | 7 ++++--- test/test_helper_classes.py | 19 ++++++++++--------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/isotp/protocol.py b/isotp/protocol.py index a248936..bcbcd54 100755 --- a/isotp/protocol.py +++ b/isotp/protocol.py @@ -161,9 +161,10 @@ def __init__(self, msg: CanMessage, start_of_data: int = 0) -> None: self.stmin_sec = (stmin_temp - 0xF0) / 10000 if self.stmin_sec is None: - raise ValueError('Invalid StMin received in Flow Control') - else: - self.stmin = stmin_temp + # ISO-15765-2 requires reserved values to be treated as 0x7F. + stmin_temp = 0x7F + self.stmin_sec = stmin_temp / 1000 + self.stmin = stmin_temp else: raise ValueError("Unsupported PDU type: %s" % self.type) diff --git a/test/test_helper_classes.py b/test/test_helper_classes.py index 7ec268a..1b5486b 100755 --- a/test/test_helper_classes.py +++ b/test/test_helper_classes.py @@ -419,7 +419,7 @@ def test_decode_flow_control(self): self.assertEqual(pdu.stmin, 0) self.assertEqual(pdu.stmin_sec, 0) - for i in range(0, 0x7F): # Millisecs + for i in range(0, 0x80): # Millisecs pdu = self.make_pdu([0x30, 0x00, i]) self.assertEqual(pdu.type, isotp.protocol.PDU.Type.FLOW_CONTROL) self.assertEqual(pdu.flow_status, isotp.protocol.PDU.FlowStatus.ContinueToSend) @@ -427,7 +427,7 @@ def test_decode_flow_control(self): self.assertEqual(pdu.stmin, i) self.assertEqual(pdu.stmin_sec, i / 1000) - for i in range(0xF1, 0xF9): # Microsecs + for i in range(0xF1, 0xFA): # Microsecs pdu = self.make_pdu([0x30, 0x00, i]) self.assertEqual(pdu.type, isotp.protocol.PDU.Type.FLOW_CONTROL) self.assertEqual(pdu.flow_status, isotp.protocol.PDU.FlowStatus.ContinueToSend) @@ -435,13 +435,14 @@ def test_decode_flow_control(self): self.assertEqual(pdu.stmin, i) self.assertEqual(pdu.stmin_sec, (i - 0xF0) / 10000) - for i in range(0x80, 0xF1): # Reserved StMin - with self.assertRaises(ValueError): - pdu = self.make_pdu([0x30, 0x00, i]) - - for i in range(0xFA, 0x100): # Reserved StMin - with self.assertRaises(ValueError): - pdu = self.make_pdu([0x30, 0x00, i]) + for lower, upper in ((0x80, 0xF1), (0xFA, 0x100)): # Reserved StMin + for i in range(lower, upper): + pdu = self.make_pdu([0x30, 0xA5, i]) + self.assertEqual(pdu.type, isotp.protocol.PDU.Type.FLOW_CONTROL) + self.assertEqual(pdu.flow_status, isotp.protocol.PDU.FlowStatus.ContinueToSend) + self.assertEqual(pdu.blocksize, 0xA5) + self.assertEqual(pdu.stmin, 0x7F) + self.assertEqual(pdu.stmin_sec, 0x7F / 1000) class TestRateLimiter(unittest.TestCase):