Application Layer

icspacket.proto.dnp3.application.APDU_SEQ_MAX = 16

Maximum border number of a sequence number within an APDU.

Added in version 0.2.0.

class icspacket.proto.dnp3.application.ApplicationControl(first_fragment: bool = False, final_fragment: bool = False, need_confirmation: bool = False, unsolicited_response: bool = False, sequence: int = 0)[source]

Represents the DNP3 Application Control octet (see DNP3 standard §4.2.2.4).

This octet carries control information required for managing multi-fragment Application Layer messages, including message boundaries, sequencing, and whether acknowledgments are required.

first_fragment: bool = False

Indicates whether this is the first fragment of a multi-fragment message.

final_fragment: bool = False

Indicates whether this is the final fragment of a multi-fragment message.

need_confirmation: bool = False

Specifies whether the receiver’s Application Layer shall return an Application Layer confirmation message.

unsolicited_response: bool = False

Marks the fragment as containing an unsolicited response or a confirmation of an unsolicited response.

sequence: int = 0

Message sequence number used to verify fragment ordering and detect duplicate fragments. Values increment modulo 16.

class icspacket.proto.dnp3.application.IIN(device_restart: bool = False, device_trouble: bool = False, local_control: bool = False, need_time: bool = False, class_3_events: bool = False, class_2_events: bool = False, class_1_events: bool = False, broadcast: bool = 0, reserved: int = 0, config_corrupt: bool = False, already_executing: bool = False, event_buffer_overflow: bool = False, parameter_error: bool = False, object_unknown: bool = False, no_func_code_support: bool = False)[source]

Represents the DNP3 Internal Indications (IIN) bitfield (§4.2.2.6).

This 2-byte structure communicates the outstation’s internal states and error conditions, such as pending events, device restarts, or unsupported function codes.

device_restart: bool = False

Indicates that the outstation has restarted.

device_trouble: bool = False

An abnormal, device-specific condition exists in the outstation.

local_control: bool = False

Indicates one or more of the outstation’s points are in local control mode.

need_time: bool = False

Indicates that the outstation requires time synchronization.

class_3_events: bool = False

Indicates unreported Class 3 events are pending at the outstation.

class_2_events: bool = False

Indicates unreported Class 2 events are pending at the outstation.

class_1_events: bool = False

Indicates unreported Class 1 events are pending at the outstation.

broadcast: bool = 0

A broadcast message was received.

config_corrupt: bool = False

The outstation detected corrupt configuration data. Support is optional.

already_executing: bool = False

The requested operation is already executing. Support for this field is optional.

event_buffer_overflow: bool = False

An event buffer overflow occurred, and at least one unconfirmed event was lost.

parameter_error: bool = False

A parameter error was detected in the request.

object_unknown: bool = False

The outstation does not support the requested object(s) in the request.

no_func_code_support: bool = False

The outstation does not support the requested function code.

class icspacket.proto.dnp3.application.APDU(control: ApplicationControl = None, function: FunctionCode | int = FunctionCode.CONFIRM, iin: IIN = None, objects: bytes = b'')[source]

Represents the Application Protocol Data Unit (APDU) in DNP3 (§4.2.2).

APDUs encapsulate Application Layer fragments exchanged between masters and outstations. Both request and response fragments share the same structural format, consisting of an application control octet, a function code, internal indications, and object headers.

Changed in version 0.2.0: Added support for building an APDU using bytes(obj).

control: ApplicationControl = None

Application control octet providing fragment sequencing and acknowledgment control.

function: FunctionCode | int = 0

Function code octet indicating the operation requested or responded to. Values range from 0-128 for requests and 129-255 for responses.

iin: IIN = None

Internal indications (IIN) structure, included only in response APDUs. Encodes device states and error conditions.

Parsing is conditional on the APDU being a response (function code ≥ 129).

objects: bytes = b''

Application objects included in the fragment. These represent the payload of the APDU and are parsed separately according to object headers.

static from_octets(octets: bytes)[source]

Parse an APDU from a raw byte sequence.

icspacket.proto.dnp3.const.APDU_REQ_FUNC_MIN = 0

Minimum function code value for Application Layer requests.

icspacket.proto.dnp3.const.APDU_REQ_FUNC_MAX = 128

Maximum function code value for Application Layer requests.

icspacket.proto.dnp3.const.APDU_RESP_FUNC_MIN = 129

Minimum function code value for Application Layer responses.

icspacket.proto.dnp3.const.APDU_RESP_FUNC_MAX = 255

Maximum function code value for Application Layer responses.

class icspacket.proto.dnp3.const.FunctionCode(*values)[source]

Application Layer Function Codes.

Function codes define the type of operation performed by the Application Layer. They are carried in the first octet of an Application Protocol Data Unit (APDU).

(See DNP3 Specification, Section 4.2.2.5)

CONFIRM = 0

Master confirms receipt of an Application Layer fragment.

READ = 1

Outstation shall return the data specified in the request.

WRITE = 2

Outstation shall store the data specified in the request.

SELECT = 3

Outstation selects output points in preparation for an OPERATE command.

OPERATE = 4

Outstation activates output points selected by a prior SELECT.

DIRECT_OPERATE = 5

Outstation immediately actuates output points without requiring SELECT.

DIRECT_OPERATE_NR = 6

Same as DIRECT_OPERATE but without sending a response.

IMMED_FREEZE = 7

Outstation copies data values into a freeze buffer.

IMMED_FREEZE_NR = 8

Same as IMMED_FREEZE but without sending a response.

FREEZE_CLEAR = 9

Outstation copies data values into a freeze buffer and clears originals.

FREEZE_CLEAR_NR = 10

Same as FREEZE_CLEAR but without sending a response.

FREEZE_AT_TIME = 11

Outstation freezes data values at a specified time/interval.

FREEZE_AT_TIME_NR = 12

Same as FREEZE_AT_TIME but without sending a response.

COLD_RESTART = 13

Outstation performs a full reset of hardware and software.

WARM_RESTART = 14

Outstation performs a partial reset of the device.

INITIALIZE_DATA = 15

Obsolete — not to be used in new designs.

INITIALIZE_APPL = 16

Outstation places applications into ready-to-run state.

START_APPL = 17

Outstation starts the specified applications.

STOP_APPL = 18

Outstation stops the specified applications.

SAVE_CONFIG = 19

Deprecated — saving of configuration (do not use in new designs).

ENABLE_UNSOLICITED = 20

Outstation enables unsolicited responses for specified points.

DISABLE_UNSOLICITED = 21

Outstation disables unsolicited responses for specified points.

ASSIGN_CLASS = 22

Outstation assigns points/events to one of the defined classes.

DELAY_MESSAGE = 23

Outstation reports processing/transmission delay time.

RECORD_CURRENT_TIME = 24

Outstation records the current time when the last octet is received.

OPEN_FILE = 25

Outstation opens a file.

CLOSE_FILE = 26

Outstation closes a file.

DELETE_FILE = 27

Outstation deletes a file.

GET_FILE_INFO = 28

Outstation retrieves information about a file.

AUTHENTICATE_FILE = 29

Outstation returns a file authentication key.

ABORT_FILE = 30

Outstation aborts an ongoing file transfer.

ACTIVATE_CONFIG = 31

Outstation activates a configuration.

AUTHENTICATE_REQ = 32

Master sends an authentication request requiring acknowledgement.

AUTH_REQ_NO_ACK = 33

Master sends an authentication request not requiring acknowledgement.

RESPONSE = 129

Application Layer response to a master request.

UNSOLICITED_RESPONSE = 130

Unsolicited Application Layer response from the outstation.

AUTHENTICATE_RESP = 131

Outstation issues an authentication response to the master.

class icspacket.proto.dnp3.const.ObjectPrefixCode(*values)[source]

Object Prefix Codes.

Define how objects are prefixed when encoded in an Application Layer message. (See DNP3 Specification, Section 4.2.2.7.3.2)

NONE = 0

Objects are encoded without any index prefix.

INDEX_8 = 1

Objects are prefixed with an 8-bit index.

INDEX_16 = 2

Objects are prefixed with a 16-bit index.

INDEX_32 = 3

Objects are prefixed with a 32-bit index.

OBJECT_SIZE_8 = 4

Objects are prefixed with an 8-bit object size.

OBJECT_SIZE_16 = 5

Objects are prefixed with a 16-bit object size.

OBJECT_SIZE_32 = 6

Objects are prefixed with a 32-bit object size.

RESERVED = 7

Reserved for future use.

class icspacket.proto.dnp3.const.RangeSpecifierCode(*values)[source]

Range Specifier Codes.

Indicate how ranges of objects are expressed in a qualifier field, including start/stop indexes, virtual addresses, or counts. (See DNP3 Specification, Section 4.2.2.7.3.3)

RANGE_8 = 0

Range field contains 1-octet start and stop indexes.

RANGE_16 = 1

Range field contains 2-octet start and stop indexes.

RANGE_32 = 2

Range field contains 4-octet start and stop indexes.

RANGE_8_VIRTUAL = 3

Range field contains 1-octet start and stop virtual addresses.

RANGE_16_VIRTUAL = 4

Range field contains 2-octet start and stop virtual addresses.

RANGE_32_VIRTUAL = 5

Range field contains 4-octet start and stop virtual addresses.

NONE = 6

No range field is used (implies all values).

COUNT_8 = 7

Range field contains a 1-octet count of objects.

COUNT_16 = 8

Range field contains a 2-octet count of objects.

COUNT_32 = 9

Range field contains a 4-octet count of objects.

VARIABLE = 11

Variable format qualifier with a 1-octet object count.