SPDU Types

class icspacket.proto.iso_ses.spdu.LI(extended: bool = True)[source]

8.2.5 Length indicator field

Encodes/decodes the length, in octets, of the associated parameter field. The LI value does not include the LI octets themselves nor any subsequent user information octets.

Encoding forms:

  • Short form (1 octet): values in range 0..254 are encoded in one octet. A value of 0 indicates that the associated parameter field is absent.

  • Extended form (3 octets): values in range 255..65535 are encoded as: 0xFF | <length: uint16 big-endian> i.e., first octet 1111 1111 (255), followed by two octets carrying the length.

EXTENDED_INDICATOR = b'\xff'

Indicates an extended length indicator.

static octet_size(value: int) int[source]

Return the number of octets required to encode value as an LI.

icspacket.proto.iso_ses.spdu.LI_Extended = <icspacket.proto.iso_ses.spdu.LI object>

Convenience alias for LI that allows extended form

class icspacket.proto.iso_ses.spdu.SPDU_Codes[source]

Mapping of SPDU SI codes to mnemonic names.

Note

Some codes in X.225 are contextual aliases (e.g., code 1 is used for both DT and GT) depending on category/semantics. This class preserves the code values.

static has_user_info(code: int) bool[source]

Return True if User Information Field is defined for this SI code.

Per X.225, only a subset of SPDUs carry user data directly. In the connection-oriented subset, these are primarily:

  • DATA TRANSFER (DT)

  • EXPEDITED (EX)

  • TYPED DATA (TD)

Final presence is further constrained by Enclosure Item semantics for DT.

class icspacket.proto.iso_ses.spdu.PGI_Code(*values)[source]

Parameter Group Identifier (PGI) codes

class icspacket.proto.iso_ses.spdu.PI_Unit_Raw(pi: int, value: Any)[source]

PI Unit (Parameter) — X.225 §8.2.3

Wire format
+--------+--------+-----------------...
|  PI    |   LI   | parameter value (LI octets)
+--------+--------+-----------------...
  • PI: 1 octet identifier for the parameter.

  • LI: Length Indicator (1 or 3 octets) for the parameter value.

  • value_raw: Bytes of the parameter value (no nested parsing here).

pi: int

PI field that identifies the parameter.

value: Any

Parameter value as raw bytes, length-prefixed by an LI, if not implemented in icspacket.iso_cosp.values.

icspacket.proto.iso_ses.spdu.PI_Units_Raw = <Prefixed>

Defines a list of PI Units (length-prefixed aggregate).

class icspacket.proto.iso_ses.spdu.PGI_Unit_Raw(pgi: PGI_Code | int, value: list[PI_Unit_Raw])[source]

PGI Unit (Parameter Group) — X.225 §8.2.2

Wire format
+--------+--------+-----------------...
|  PGI   |   LI   |   parameter field
+--------+--------+-----------------...

The parameter field of a PGI may be:

    1. a single parameter value, or

    1. one or more PI units (each PI is again LI-prefixed).

This raw representation keeps the inner sequence as a list of PI_Unit_Raw.

pgi: PGI_Code | int

PGI field identifying the parameter group.

value: list[PI_Unit_Raw]

Parameter field for the group: either a single value or multiple PI units.

class icspacket.proto.iso_ses.spdu.Px_Unit(pi: int, value: Any)[source]

Unified view over either a PI or a PGI.

pi: int

The 1-octet identifier. For PGIs this holds the PGI code; for PIs it is the PI.

value: Any
  • PGI: list of PI_Unit_Raw (unless USER_DATA/EXTENDED_USER_DATA)

  • PI: raw value bytes (LI-prefixed)

property is_group: bool

True if pi is a known PGI code.

property is_user_data: bool

True if pi is USER_DATA or EXTENDED_USER_DATA.

add_parameter(pi: int, value: list[Px_Unit] | bytes | Any) Px_Unit[source]

Add a parameter (PGI or PI) to the SPDU.

icspacket.proto.iso_ses.spdu.Px_Units = <Prefixed>

Defines a prefixed list of PGI or PI units (mixed).

class icspacket.proto.iso_ses.spdu.SPDU_Raw(si: int, parameters_raw: list[Px_Unit])[source]

SPDU (raw representation) — X.225 §8.2

Wire format
+--------+--------+-----------------...
|  SI    |   LI   | parameter field (LI octets)
+--------+--------+-----------------...
  • si (1 octet): SPDU Identifier (SI) — code that identifies the SPDU type (e.g., CN/AC/DT/etc.).

  • parameters_raw (LI-prefixed): a mixed sequence of PGI units and/or PI units as defined for that SPDU type.

Important

The User Information Field (if any) is not part of this raw struct. It is handled by the higher-level SPDU wrapper because the presence rules depend on the SI code and items like the Enclosure Item.

si: int

The SI field that identifies the type of SPDU.

parameters_raw: list[Px_Unit]

The parameter field: a prefixed block of PGI units and/or PI units.

static from_octets(octets: bytes)[source]

Deserialize a raw SPDU from octets (SI + LI + parameter field).

class icspacket.proto.iso_ses.spdu.SPDU_Category(*values)[source]

SPDU categories for transport concatenation behavior — 6.3.7.

CATEGORY_0 = 0
  1. Category 0 SPDUs which may be mapped one-to-one onto a TSDU or may be concatenated with one or more category 2 SPDUs;

CATEGORY_1 = 1
  1. Category 1 SPDUs which are always mapped one-to-one onto a TSDU;

CATEGORY_2 = 2
  1. Category 2 SPDUs which are never mapped one-to-one onto a TSDU.

class icspacket.proto.iso_ses.spdu.SPDU(code: int = 0, category: SPDU_Category | None = None)[source]

Convenience wrapper over SPDU_Raw with user-info detection.

Structure (logical) — X.225 8.2

SPDUs shall contain, in order:

    1. SI — identifies the SPDU type (1 octet).

    1. LI — length (in octets) of the parameter field (1 or 3 octets).

    1. Parameter field — zero or more PGI/PI units (the block whose

  • length is provided by the LI).

    1. User Information Field — if defined for the SPDU type and present.

SPDU_Raw models (a)-(c). Whether (d) exists cannot be decided by just looking at the LI, because for some SPDU types (e.g., DT) the presence of user information depends on control items like the Enclosure Item and sequence rules (§7.11.2 and §8.3.*.4). This wrapper inspects parameters to decide if trailing octets belong to the User Information Field.

code: int

The SI code (a.k.a. SPDU type).

category: SPDU_Category

Concatenation category (6.3.7).

add_parameter(pi: int, value: list[Px_Unit] | bytes | Any) Px_Unit[source]

Add a parameter (PGI or PI) to the SPDU.

property parameters: list[Px_Unit]

The top-level mixed list of PGI/PI units for this SPDU.

iter_parameters() Generator[Px_Unit, None, None][source]

Yield parameters flattened: for PGIs, yield their inner PIs.

property name: str

A human-readable name for this SPDU type.

parameter_by_id(pi: int) Px_Unit | None[source]

Get a parameter by its PI code.

Parameters:

pi (int) – The PI code

Returns:

The parameter, or None if not found

Return type:

Px_Unit | None

property has_user_information: bool

Infer whether a User Information Field is expected/present.

Rules applied

  1. Only certain SI codes define user information (DT/EX/TD). See SPDU_Codes.has_user_info(). If not defined, return False.

  2. Category 0 SPDUs are excluded here (mapping rules may reserve bytes).

  3. For DATA TRANSFER (DT) in particular:

    • If the Enclosure Item is present, its bit 2 semantics affect whether user information should appear in a multi-SPDU sequence (§8.3.11/13.4, §7.11.2). If Enclosure indicates “more follows” (bit 1 == 0), user information must be present on all but the last.

Returns:

True if we should treat remaining octets as the User Information Field; False otherwise.

Return type:

bool

property user_information: bytes

Raw bytes of the User Information Field (may be empty).

static from_octets(octets: bytes, category: SPDU_Category | None = None)[source]

Deserialize an SPDU from octets and extract user-info if applicable.

Parameters:
  • octets (bytes) – The full SPDU octet string (SI + LI + parameters [+ user info?]).

  • category (SPDU_Category, optional) – The concatenation category to associate with this SPDU., defaults to SPDU_Category.CATEGORY_2

Returns:

A high-level SPDU with parameters and (if detected) user info.

Return type:

SPDU

build() bytes[source]

Serialize the SPDU to octets.