part5

package module
v0.0.0-...-26ed527 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 18, 2022 License: CC0-1.0 Imports: 10 Imported by: 0

README

Go Reference Build Status

Part5 With The Go Programming Language

The International Electrotechnical Commission standard 870 part 5 (IEC 870-5) is a set of transmission procedures intended for SCADA systems. Prefix 60 was added later as in IEC 60870. For serial communication please refer to 60870-5-101 and 60870-5-104 is the TCP-based evolution.

The project consists of a high-level framework, including a low-level library, and tooling for network exploration and automated testing. Incomplete! About 95% of the work has been published; see issue #1.

This is free and unencumbered software released into the public domain.

Definitions

At its essence, part 5 formalizes reliable means to exchange data and commands.

The initiating stations are called primary and the responding stations are secondary. With unbalanced transmission stations are either primary or secodary [master/slave] and with balanced transmission stations can act both as primary and as secondory [peer-to-peer].

Addressing follows this initiate–respond context; an origin address remains that of the primary and a destination address points to (something on) the secondary, regardless of the message direction.

A common address can be seen as a data set wherein each data element has its own predefined information object address. The set may be downloaded with an interrogation command.

The standard provides commands that operate on data and they may trigger remote procceses by agreement. Again, each command is applied to a single information object address. Secondaries either confirm or reject execution. Optionaly the command may indicate completion with a terminate message. Some commands can be preceded with a select directive which locks down processing to one at a time.

To get started please see the API documentation of Dial [serial], DialTCP or ListenTCP.

TODO

  • file transfer
  • parameters
  • complete ASDU encoding types

iechbin

The project comes with a test tool. Download a prebuilt binary or run go get -u github.com/pascaldekloe/part5/cmd/iechbin to make one yourself. Without arguments the command opens a browser UI.

Documentation

Overview

Package part5 provides the OSI application layer with asynchronous I/O.

Index

Constants

This section is empty.

Variables

View Source
var ErrCmdDeny = errors.New("part5: command execution denied")

ErrCmdDeny signals a remote acceptance rejection.

View Source
var ErrCmdRace = errors.New("part5: pending command execution on same address")

ErrCmdRace signals a concurrent command execution.

Functions

This section is empty.

Types

type Bits

type Bits func(info.ID, uint32, MeasureAttrs)

Bits gets called for type M_BO_NA_1, M_BO_TA_1 and M_BO_TB_1.

type BitsCmd

type BitsCmd func(info.ID, uint32, info.ObjAddr, time.Time, ExecTerm) (ok bool)

BitsCmd gets called for type C_BO_NA_1 and C_BO_TA_1. The timestamp is zero when the data is invalid or when the type does not include timing at all. Return ok causes a positive info.Actcon or negative info.NegFlag confirmation message to be send about whether the specified control action is about to commence—hence the actual execution should proceed in a separate routine and ExecTerm may be called once on completion.

type Caller

type Caller struct {
	// contains filtered or unexported fields
}

Caller submits messages. All of its methods are thread-safe.

func MustLaunch

func MustLaunch(t *session.Transport, p *info.Params, delegates map[info.CommonAddr]*Delegate) (*Caller, <-chan error)

MustLaunch starts a setup which runs until session.Exit. If the configuration is invalid, MustLaunch will panic.

func (*Caller) Bits

func (c *Caller) Bits(id info.ID, v uint32, attrs MeasureAttrs)

Bits sends a type M_BO_NA_1, M_BO_TA_1 or M_BO_TB_1.

func (*Caller) BitsCmd

func (c *Caller) BitsCmd(id info.ID, bits uint32, addr info.ObjAddr, tag time.Time, term CmdTerm) error

BitsCmd sends a type C_BO_NA_1 or C_BO_TA_1.

func (*Caller) Double

func (c *Caller) Double(id info.ID, v info.DoublePoint, attrs MeasureAttrs) error

Double sends a type M_DP_NA_1, M_DP_TA_1 or M_DP_TB_1.

func (*Caller) DoubleCmd

func (c *Caller) DoubleCmd(id info.ID, p info.DoublePoint, attrs ExecAttrs, term CmdTerm) error

DoubleCmd sends a type C_DC_NA_1 or C_DC_TA_1.

func (*Caller) Float

func (c *Caller) Float(id info.ID, v float32, attrs MeasureAttrs) error

Float sends a type M_ME_NC_1, M_ME_TC_1 or M_ME_TF_1.

func (*Caller) FloatSetpoint

func (c *Caller) FloatSetpoint(id info.ID, p float32, attrs ExecAttrs, term CmdTerm) error

FloatSetpoint sends a type C_SE_NC_1 or C_SE_TC_1.

func (*Caller) Normal

func (c *Caller) Normal(id info.ID, v info.Normal, attrs MeasureAttrs)

Normal sends a type M_ME_NA_1, M_ME_TA_1, M_ME_TD_1 or M_ME_ND_1. The quality descriptor must default to info.OK for type M_ME_ND_1.

func (*Caller) NormalSetpoint

func (c *Caller) NormalSetpoint(id info.ID, p info.Normal, attrs ExecAttrs, term CmdTerm) error

NormalSetpoint sends a type C_SE_NA_1 or C_SE_TA_1.

func (*Caller) RegulCmd

func (c *Caller) RegulCmd(id info.ID, up info.DoublePoint, attrs ExecAttrs, term CmdTerm) error

RegulCmd sends a type C_RC_NA_1 or C_RC_TA_1.

func (*Caller) Scaled

func (c *Caller) Scaled(id info.ID, v int16, attrs MeasureAttrs)

Scaled sends a type M_ME_NB_1, M_ME_TB_1 or M_ME_TE_1.

func (*Caller) ScaledSetpoint

func (c *Caller) ScaledSetpoint(id info.ID, p int16, attrs ExecAttrs, term CmdTerm) error

ScaledSetpoint sends a type C_SE_NB_1 or C_SE_TB_1.

func (*Caller) Send

func (c *Caller) Send(u *info.ASDU) error

Send submits a message and awaits receival confirmation.

func (*Caller) Single

func (c *Caller) Single(id info.ID, v info.SinglePoint, attrs MeasureAttrs) error

Single sends a type M_SP_NA_1, M_SP_TA_1 or M_SP_TB_1.

func (*Caller) SingleCmd

func (c *Caller) SingleCmd(id info.ID, p info.SinglePoint, attrs ExecAttrs, term CmdTerm) error

SingleCmd sends a type C_SC_NA_1 or C_SC_TA_1.

func (*Caller) Step

func (c *Caller) Step(id info.ID, v info.StepPos, attrs MeasureAttrs)

Step sends a type M_ST_NA_1, M_ST_TA_1 or M_ST_TB_1.

type CmdTerm

type CmdTerm func(error)

CmdTerm gets called for notification messages about the termination of a command execution. Note that the outcome, whether success or failure, is out of scope and error handling is unspecified.

This notification step is optional depending on the vendor. When ignored (with a nil CmdTerm) then it must be done consistently so per address or risk false hits.

Go routines may safely wait for a call thanks to timeout protection(s).

type Delegate

type Delegate struct {
	sync.WaitGroup

	// All inbound messages are reported to these entries first. The
	// functions are called in order of appearance. An ASDU is dropped
	// immediately when the return is false. Thus All can be used as a
	// filter, a preprocessor or as an extension point.
	All []func(*info.ASDU) (pass bool)

	// Tests are called in order of appearance for type C_TS_NA_1.
	// See section 5, subclause 6.11.
	Tests []func() (ok bool)

	// Listeners For Measured Values [primary]
	// Use info.IrrelevantAddr to catch'm all.
	Singles map[info.ObjAddr]Single
	Doubles map[info.ObjAddr]Double
	Steps   map[info.ObjAddr]Step
	Bits    map[info.ObjAddr]Bits
	Normals map[info.ObjAddr]Normal
	Scaleds map[info.ObjAddr]Scaled
	Floats  map[info.ObjAddr]Float

	// Listeners For Commands [secondary]
	// Use info.IrrelevantAddr to catch'm all.
	SingleCmds      map[info.ObjAddr]SingleCmd
	DoubleCmds      map[info.ObjAddr]DoubleCmd
	RegulCmds       map[info.ObjAddr]RegulCmd
	NormalSetpoints map[info.ObjAddr]NormalSetpoint
	ScaledSetpoints map[info.ObjAddr]ScaledSetpoint
	FloatSetpoints  map[info.ObjAddr]FloatSetpoint
	BitsCmds        map[info.ObjAddr]BitsCmd
}

Delegate is a listener configuration for one common address.

func (*Delegate) String

func (d *Delegate) String() string

String returns a compact description of the setup.

func (*Delegate) Valid

func (d *Delegate) Valid() error

Valid returns the validation result.

type Double

type Double func(info.ID, info.DoublePoint, MeasureAttrs)

Double gets called for type M_DP_NA_1, M_DP_TA_1 and M_DP_TB_1.

type DoubleCmd

type DoubleCmd func(info.ID, info.DoublePoint, ExecAttrs, ExecTerm) (ok bool)

DoubleCmd gets called for type C_DC_NA_1 and C_DC_TA_1. Return ok causes a positive info.Actcon or negative info.NegFlag confirmation message to be send about whether the specified control action is about to commence—hence the actual execution should proceed in a separate routine and ExecTerm may be called once on completion.

type ExecAttrs

type ExecAttrs struct {
	Addr info.ObjAddr

	// Use constants for the qualifier of command.
	// See info.Cmd.Qual and info.SetpointCmd.Qual.
	Qual uint

	// The timestamp is zero when the data is invalid
	// or when the type does not include timing at all.
	Time time.Time

	// Flags whether to execute with "select" protection.
	// See README.md and section 5, subclause 6.8.
	InSelect bool
}

ExecAttrs are the command execution attributes.

type ExecTerm

type ExecTerm func()

ExecTerm causes a notification message to be send about the termination of a command execution. Note that the outcome, whether success or failure, is out of scope and error handling is unspecified.

This notification step is optional depending on the vendor.

type Float

type Float func(info.ID, float32, MeasureAttrs)

Float gets called for type M_ME_NC_1, M_ME_TC_1 and M_ME_TF_1.

type FloatSetpoint

type FloatSetpoint func(info.ID, float32, ExecAttrs, ExecTerm) (ok bool)

FloatSetpoint gets called for type C_SE_NC_1 and C_SE_TC_1. Return ok causes a positive info.Actcon or negative info.NegFlag confirmation message to be send about whether the specified control action is about to commence—hence the actual execution should proceed in a separate routine and ExecTerm may be called once on completion.

type MeasureAttrs

type MeasureAttrs struct {
	Addr info.ObjAddr

	// Quality descriptor info.OK means no remarks.
	QualDesc uint

	// The timestamp is zero when the data is invalid
	// or when the type does not include timing at all.
	Time time.Time
}

MeasureAttrs are the measured value attributes.

type Normal

type Normal func(info.ID, info.Normal, MeasureAttrs)

Normal gets called for type M_ME_NA_1, M_ME_TA_1, M_ME_TD_1 and M_ME_ND_1. The quality descriptor defaults to info.OK for type M_ME_ND_1.

type NormalSetpoint

type NormalSetpoint func(info.ID, info.Normal, ExecAttrs, ExecTerm) (ok bool)

NormalSetpoint gets called for type C_SE_NA_1 and C_SE_TA_1. Return ok causes a positive info.Actcon or negative info.NegFlag confirmation message to be send about whether the specified control action is about to commence—hence the actual execution should proceed in a separate routine and ExecTerm may be called once on completion.

type RegulCmd

type RegulCmd func(info.ID, info.DoublePoint, ExecAttrs, ExecTerm) (ok bool)

RegulCmd gets called for type C_RC_NA_1 and C_RC_TA_1. Return ok causes a positive info.Actcon or negative info.NegFlag confirmation message to be send about whether the specified control action is about to commence—hence the actual execution should proceed in a separate routine and ExecTerm may be called once on completion.

type Scaled

type Scaled func(info.ID, int16, MeasureAttrs)

Scaled gets called for type M_ME_NB_1, M_ME_TB_1 and M_ME_TE_1.

type ScaledSetpoint

type ScaledSetpoint func(info.ID, int16, ExecAttrs, ExecTerm) (ok bool)

ScaledSetpoint gets called for type C_SE_NB_1 and C_SE_TB_1. Return ok causes a positive info.Actcon or negative info.NegFlag confirmation message to be send about whether the specified control action is about to commence—hence the actual execution should proceed in a separate routine and ExecTerm may be called once on completion.

type Single

type Single func(info.ID, info.SinglePoint, MeasureAttrs)

Single gets called for type M_SP_NA_1, M_SP_TA_1 and M_SP_TB_1.

type SingleCmd

type SingleCmd func(info.ID, info.SinglePoint, ExecAttrs, ExecTerm) (ok bool)

SingleCmd gets called for type C_SC_NA_1 and C_SC_TA_1. Return ok causes a positive info.Actcon or negative info.NegFlag confirmation message to be send about whether the specified control action is about to commence—hence the actual execution should proceed in a separate routine and ExecTerm may be called once on completion.

type Step

type Step func(info.ID, info.StepPos, MeasureAttrs)

Step gets called for type M_ST_NA_1, M_ST_TA_1 and M_ST_TB_1.

Notes

Bugs

  • Hardcoded command termination timeout of 60s.

  • Hardcoded command activation timeout of 10s.

  • Hardcoded select timeout of 10s.

Directories

Path Synopsis
Package info provides the OSI presentation layer.
Package info provides the OSI presentation layer.
Package media provides the OSI media layers from section 1 & 2.
Package media provides the OSI media layers from section 1 & 2.
Package session provides the OSI transport and session layers.
Package session provides the OSI transport and session layers.
Package track follows address states.
Package track follows address states.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL