ISO Session

exception icspacket.proto.iso_ses.session.SessionDataError[source]

Raised when session data exchange fails or unexpected SPDU content is received.

exception icspacket.proto.iso_ses.session.SessionRejectedError[source]

Raised when a session connection request is explicitly rejected by the peer.

class icspacket.proto.iso_ses.session.ISO_SessionSettings(calling_ses_sel: bytes = b'\x00\x01', called_ses_sel: bytes = b'\x00\x01', session_req: ~icspacket.proto.iso_ses.values.PV_SessionRequirements = <factory>, version: int = 2, extended: bool = False)[source]

Encapsulates (X.225 / ISO 8327-1) negotiation settings.

Parameters:
  • calling_ses_sel (bytes) – Calling session selector.

  • called_ses_sel (bytes) – Called session selector.

  • session_req (PV_SessionRequirements) – Session requirements parameter vector.

  • version (int) – Session protocol version (default 2).

  • extended (bool) – Whether extended SPDU formats are enabled.

class icspacket.proto.iso_ses.session.ISO_Session(transport: COTP_Connection, settings: ISO_SessionSettings | None = None)[source]

Implements the Connection-oriented Session Protocol (COSP) (ITU X.225 / ISO 8327-1) endpoint on top of COTP.

Provides session connection establishment, data transfer, and orderly release services using SPDUs (Session Protocol Data Units). This class ensures proper sequencing and validation of SPDUs as per ISO Session protocol semantics.

Parameters:
settings: ISO_SessionSettings

Currently applied session settings

property transport: COTP_Connection

Associated transport connection.

send_data(octets: bytes, /) None[source]

Send user data wrapped in a session TSDU.

Note

The session must already be initialized with an ACCEPT SPDU.

Parameters:

octets (bytes) – User data payload.

Raises:

ConnectionStateError – If the session is not initialized.

send_tsdu(tsdu: TSDU, /) None[source]

Send a fully constructed TSDU over the transport connection.

Parameters:

tsdu (TSDU) – Transport Service Data Unit.

recv_data() bytes[source]

Receive user data from the session.

Returns:

Extracted user data payload.

Return type:

bytes

Raises:

SessionDataError – If the expected SPDU sequence is not found.

recv_tsdu() TSDU[source]

Receive and parse a TSDU from the transport connection.

Returns:

Parsed TSDU object.

Return type:

TSDU

close() None[source]

Close the session and underlying transport connection immediately.

close_session(pres_octets: bytes, graceful: bool = False) bytes | None[source]

Attempt an orderly session release.

This method does not close the connection if graceful is set and user data is returned by the peer.

Parameters:
  • pres_octets (bytes) – User data to include in FINISH SPDU.

  • graceful (bool) – Whether to expect and validate a DISCONNECT_SPDU.

Returns:

Optional user data returned by peer during graceful release.

Return type:

bytes | None

Raises:

SessionDataError – If graceful close fails due to unexpected SPDU.

connect(address: tuple[str, int]) None[source]

Connect the underlying transport if not already connected.

Parameters:

address (tuple[str, int]) – Target address (host, port).

init_session(pres_octets: bytes, address: tuple[str, int] | None = None) bytes[source]

Initialize a session by sending CONNECT SPDU and awaiting ACCEPT SPDU.

Parameters:
  • pres_octets (bytes) – Presentation-layer user data to include.

  • address (tuple[str, int] | None) – Optional (host, port) if transport not yet connected.

Returns:

User data returned by peer in ACCEPT SPDU.

Return type:

bytes

Raises: