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.
TrueFrame initiates a transaction.FalseFrame 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:
Trueif buffer space is insufficient,Falseotherwise.- 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:
- property sec2pri_code: LinkSecondaryFunctionCode¶
Interpret the function code for Secondary-to-Primary frames.
- Returns:
Link layer function code for PRM = 0.
- Return type:
- 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