SPDU Types#
- class icspacket.proto.iso_ses.spdu.LI(extended: bool = True)[source]#
Implements the Length Indicator (clause 8.2.5) that reports, in octets, how large the parameter field attached to it is.
That count only covers the parameter bytes themselves - it never includes the LI’s own octets, nor any user-information octets that might follow.
This class switches between two on-the-wire shapes depending on how big the value being described is:
sizes from 0 to 254 fit in a single octet, and a value of 0 means there is no parameter field at all;
anything from 255 up to 65535 instead uses three octets: a marker octet of
0xFF(255), followed by the size as a big-endian 16-bit integer.
- EXTENDED_INDICATOR: bytes = b'\xff'#
Indicates an extended length indicator.
- icspacket.proto.iso_ses.spdu.LI_Extended: Final[LI] = <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.
According to 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). (See 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). (See X.225, §8.2.2)
Wire format#+--------+--------+-----------------... | PGI | LI | parameter field +--------+--------+-----------------...
The parameter field of a PGI holds either a single parameter value on its own, or a run of one or more PI units stacked back to back (each still carrying its own LI prefix).
This raw representation keeps the inner sequence as a list of PI_Unit_Raw.
- 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.
- 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). (See 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.
- class icspacket.proto.iso_ses.spdu.SPDU_Category(*values)[source]#
Groups SPDU types by how they may be packed into a TSDU. (See 6.3.7)
- CATEGORY_0 = 0#
SPDUs that can either stand alone as a whole TSDU or ride along with one or more Category 2 SPDUs bundled into the same TSDU.
- CATEGORY_1 = 1#
SPDUs that always fill an entire TSDU by themselves and are never combined with other SPDUs.
- CATEGORY_2 = 2#
SPDUs that can never appear alone in a TSDU and must always be bundled together with another SPDU.
- class icspacket.proto.iso_ses.spdu.SPDU(code: int = 0, category: SPDU_Category | None = None)[source]#
Convenience wrapper over
SPDU_Rawwith user-info detection.Structure (logical). (See X.225, 8.2)
On the wire, an SPDU is built from up to four consecutive parts: a one-octet SI that identifies the SPDU type, an LI (one or three octets) giving the size of what follows, a parameter field holding zero or more PGI/PI units sized by that LI, and - only for some SPDU types - a trailing User Information Field.
SPDU_Rawonly models the SI, the LI and the parameter field. Whether a User Information Field follows can’t be told from the LI alone: for some SPDU types (e.g., DT) that depends on control items such as the Enclosure Item, plus sequencing rules (See §7.11.2 and §8.3.*.4). This wrapper inspects the decoded parameters to work out whether any trailing octets should be treated as that User Information Field.- code: int#
The SI code (a.k.a. SPDU type).
- category: SPDU_Category#
Concatenation category (See 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.
- 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
Only certain SI codes define user information (DT/EX/TD). See SPDU_Codes.has_user_info(). If not defined, return False.
Category 0 SPDUs are excluded here (mapping rules may reserve bytes).
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 (See §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: