Skip to content
Open
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
3 changes: 1 addition & 2 deletions snap7/server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2705,10 +2705,9 @@ def _build_cotp_cc(self) -> bytes:
pdu_size_param = struct.pack(">BBB", self.COTP_PARAM_PDU_SIZE, 1, self.tpdu_size)
pdu_length = 6 + len(pdu_size_param)
base_pdu = struct.pack(
">BBBHHB",
">BBHHB",
pdu_length, # PDU length
self.COTP_CC, # PDU type
0x00, # Reserved / CDT
self.dst_ref, # Destination reference (client's source ref)
self.src_ref, # Source reference (our ref)
0x00, # Class/option
Expand Down
11 changes: 11 additions & 0 deletions tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,17 @@ def test_server_area_management(self) -> None:

@pytest.mark.server
class TestServerISOConnectionLimits:
def test_connection_confirm_has_valid_length_and_tpdu_size(self) -> None:
client_socket = MagicMock()
connection = ServerISOConnection(client_socket)
connection.dst_ref = 0x000F
connection.tpdu_size = 0x09

connection_confirm = connection._build_cotp_cc()

assert connection_confirm == bytes.fromhex("09d0000f000100c00109")
assert connection_confirm[0] == len(connection_confirm) - 1

def test_partial_frame_timeout_closes_connection(self) -> None:
client_socket = MagicMock()
client_socket.recv.side_effect = [b"\x03", TimeoutError()]
Expand Down
Loading