icspacket
  • Examples
    • MMS Utilities Manufacturing Message Specification tools
    • DNP3 Tools DNP3 utilities and tools
    • IED Enumeration Tool Logical Device enumeration and more
  • Changelog
/
  • Discussion

Getting Started

  • Installation
  • Protocols Overview
  • Core API Reference

DNP3 / IEEE 1815

  • Reading Objects
  • Dumping Objects
  • Resolve Link Addresses
  • API Reference
    • Link Layer
    • Transport Layer
    • Application Layer
    • Master
    • Object Library
      • Primitive Types
      • Encoding / Decoding
      • Variations
      • Object Utilities

IEC 61850

  • Enumerating IEDs
  • Operating on IEDs
  • API Reference
    • Data Classes
    • Object / Data References
    • Control / Operation
    • IED Client
    • GOOSE Client
    • SampledValues Client

MMS / ISO 9506

  • Variable Target Format
  • VariableAccess Service (rwq)
  • FileManagement Service
  • API Reference
    • MMS Connection
    • Data Conversion
    • Protocol Utilities

ACSE / X.227

  • API Reference

COPP / X.226 / ISO 8823

  • API Reference
    • ISO Presentation
    • Protocol Utilities

COSP / X.225 / ISO 8237-1

  • API Reference
    • TSDU
    • SPDU Types
    • Parameter Values (PV)
    • ISO Session
    • Protocol Utilities

COTP / X.224

  • API Reference
    • TPDU Types
    • Connection

TPKT Protocol (RFC1006)

  • Using a TPKT Wrapper
  • API Reference

Development

  • Changelog

On this page

  • LPDU_HEADER_MIN_LENGTH
  • LPDU_HEADER_MAX_LENGTH
  • LPDU_USER_DATA_MAX_LENGTH
  • LinkDirection
    • MASTER
    • OUTSTATION
  • LinkPrimaryFunctionCode
    • RESET_LINK_STATES
    • TEST_LINK_STATES
    • CONFIRMED_USER_DATA
    • UNCONFIRMED_USER_DATA
    • REQUEST_LINK_STATUS
  • LinkSecondaryFunctionCode
    • ACK
    • NACK
    • LINK_STATUS
    • NOT_SUPPORTED
  • LinkControl
    • direction
    • primary_message
    • frame_count_bit
    • frame_count_valid
    • function_code
    • data_flow_control
    • pri2sec_code
    • sec2pri_code
  • LPDU
    • start
    • length
    • control
    • destination
    • source
    • crc16
    • user_data
    • build()
    • from_octets()
    • apdu
    • tpdu
MatrixEditor/icspacket 0 0
Edit this page
  1. icspacket /
  2. API Reference /
  3. Link Layer

Link Layer¶

icspacket.proto.dnp3.link.LPDU_HEADER_MIN_LENGTH = 5¶

Minimum number of bytes required to represent an LPDU header.

icspacket.proto.dnp3.link.LPDU_HEADER_MAX_LENGTH = 255¶

Maximum possible size of an LPDU header in bytes.

icspacket.proto.dnp3.link.LPDU_USER_DATA_MAX_LENGTH = 250¶

Maximum user data size (250 bytes) that a single LPDU can contain.

class icspacket.proto.dnp3.link.LinkDirection(*values)[source]¶

Direction indicator bit for the DNP3 link layer (DIR field).

(See DNP3 Specification, Section 9.2.4.1.3.1)

MASTER = 1¶

Indicates a frame sent from a Master device.

OUTSTATION = 0¶

Indicates a frame sent from an Outstation device.

class icspacket.proto.dnp3.link.LinkPrimaryFunctionCode(*values)[source]¶

Primary-to-Secondary function codes for the Link Layer.

These codes are valid when the PRM bit is set (PRM = 1). (See DNP3 Specification, Table 9-1)

RESET_LINK_STATES = 0¶

Reset link states.

TEST_LINK_STATES = 2¶

Test link states.

CONFIRMED_USER_DATA = 3¶

Confirmed user data transfer.

UNCONFIRMED_USER_DATA = 4¶

Unconfirmed user data transfer.

REQUEST_LINK_STATUS = 9¶

Request link status.

class icspacket.proto.dnp3.link.LinkSecondaryFunctionCode(*values)[source]¶

Secondary-to-Primary function codes for the Link Layer.

These codes are valid when the PRM bit is clear (PRM = 0). (See DNP3 Specification, Table 9-2)

ACK = 0¶

Acknowledgement.

NACK = 1¶

Negative acknowledgement.

LINK_STATUS = 11¶

Report link status.

NOT_SUPPORTED = 15¶

Function code not supported.

class icspacket.proto.dnp3.link.LinkControl(direction: LinkDirection = LinkDirection.MASTER, primary_message: bool = False, frame_count_bit: bool = False, frame_count_valid: bool = False, function_code: int = 0)[source]¶

Control field of the Link Layer Protocol Data Unit (LPDU).

Stores metadata about the frame direction, initiator, error handling, and function code. (See DNP3 Specification, Section 9.2.4.1.3)

direction: LinkDirection = 1¶

DIR bit. Indicates the physical origin of the frame (Master/Outstation).

primary_message: bool = False¶

PRM bit.

  • True Frame initiates a transaction.

  • False Frame completes a transaction.

frame_count_bit: bool = False¶

FCB bit. Used in primary-to-secondary frames to detect loss or duplication.

frame_count_valid: bool = False¶

FCV bit. Specifies whether the secondary station must examine the FCB.

function_code: int = 0¶

Function code field identifying the service or command type.

property data_flow_control: bool¶

Report data flow availability (DFC bit).

Indicates insufficient Data Link Layer buffer capacity.

Returns:

True if buffer space is insufficient, False otherwise.

Return type:

bool

property pri2sec_code: LinkPrimaryFunctionCode¶

Interpret the function code for Primary-to-Secondary frames.

Returns:

Link layer function code for PRM = 1.

Return type:

LinkPrimaryFunctionCode

property sec2pri_code: LinkSecondaryFunctionCode¶

Interpret the function code for Secondary-to-Primary frames.

Returns:

Link layer function code for PRM = 0.

Return type:

LinkSecondaryFunctionCode

class icspacket.proto.dnp3.link.LPDU(start: bytes = b'\x05d', length: int = 0, control: LinkControl = None, destination: int = 0, source: int = 0, crc16: int = 0, user_data: bytes = b'')[source]¶

Link-layer Protocol Data Unit (LPDU).

Each LPDU consists of a fixed header block and a variable-length sequence of data blocks, each terminated by a 16-bit CRC. (See DNP3 Specification, Section 9.2.4)

start: bytes = b'\x05d'¶

Sync bytes marking the start of every LPDU (0x05, 0x64).

length: int = 0¶

Length field. Number of non-CRC bytes following the header. Includes CONTROL, DESTINATION, SOURCE, and USER DATA fields.

control: LinkControl = None¶

Control field containing direction, function, and status flags.

destination: int = 0¶

Destination address of the data link frame.

source: int = 0¶

Source address of the data link frame.

crc16: int = 0¶

CRC checksum for the LPDU header block.

user_data: bytes = b''¶

Payload data field containing one or more user data chunks.

build() → bytes[source]¶

Construct a serialized LPDU with correct length.

Returns:

Encoded LPDU bytes.

Return type:

bytes

static from_octets(data: bytes) → LPDU[source]¶

Parse an LPDU from a raw byte sequence.

Changed in version 0.2.0: Renamed from from_bytes to from_octets

Parameters:

data (bytes) – Encoded LPDU bytes.

Returns:

Decoded LPDU instance.

Return type:

LPDU

property apdu: APDU¶

Parse the APDU contained in the TPDU.

property tpdu: TPDU¶

The TPDU contained in the LPDU.

Previous
API Reference
Next
Transport Layer

2025, MatrixEditor

Made with Sphinx and Shibuya theme.