vv104

package module
v0.0.0-...-005cf32 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2024 License: MIT Imports: 19 Imported by: 1

README

vv104

IEC 60870-5-104 (IEC 104) server and client implementation with test features.

Work in progress.

  • Run as client with go run cmd/main.go
  • Use -s to run as server.
  • Use -h 192.168.0.1 to connect to or listen on specific hostname or IP address. Default is localhost.
  • Use -p 2405 to connect or listen on specific port. Default is 2404.
  • For more cli flags use --help

This repository is mainly used in my other repository https://github.com/viduq/brez104 which is a GUI program for IEC 104.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	TypeIDs []string = []string{
		M_SP_NA_1.String(),
		M_DP_NA_1.String(),
		M_ST_NA_1.String(),
		M_BO_NA_1.String(),
		M_ME_NA_1.String(),
		M_ME_NB_1.String(),
		M_ME_NC_1.String(),
		M_IT_NA_1.String(),
		M_SP_TB_1.String(),
		M_DP_TB_1.String(),
		M_ST_TB_1.String(),
		M_BO_TB_1.String(),
		M_ME_TD_1.String(),
		M_ME_TE_1.String(),
		M_ME_TF_1.String(),
		M_IT_TB_1.String(),
		C_SC_NA_1.String(),
		C_DC_NA_1.String(),
		C_RC_NA_1.String(),
		C_SE_NA_1.String(),
		C_SE_NB_1.String(),
		C_SE_NC_1.String(),
		C_BO_NA_1.String(),
		C_SC_TA_1.String(),
		C_DC_TA_1.String(),
		C_RC_TA_1.String(),
		C_SE_TA_1.String(),
		C_SE_TB_1.String(),
		C_SE_TC_1.String(),
		C_BO_TA_1.String(),
		M_EI_NA_1.String(),
	}

	CauseTxs []string = []string{
		Per_Cyc.String(),
		Back.String(),
		Spont.String(),
		Init.String(),
		Req.String(),
		Act.String(),
		ActCon.String(),
		Deact.String(),
		DeactCon.String(),
		ActTerm.String(),
		Retrem.String(),
		Retloc.String(),

		Inrogen.String(),
		Inro1.String(),

		Reqcogen.String(),
		Reqco1.String(),

		UkTypeId.String(),
		UkCauseTx.String(),
		UkComAdrASDU.String(),
		UkIOA.String(),
	}
)

for GUI

View Source
var (
	LogChan chan string
)

Functions

func LoadConfigAndObjectsFromFile

func LoadConfigAndObjectsFromFile(filePathAndName string) (*Config, *Objects, error)

func NewLogChan

func NewLogChan() chan string

func TypeIsTimeTagged

func TypeIsTimeTagged(typeId TypeId) bool

func WriteConfigAndObjectsToFile

func WriteConfigAndObjectsToFile(state *State, filePathAndName string) error

Types

type AllChans

type AllChans struct {
	CommandsFromStdin chan string
	Received          chan Apdu
	ToSend            chan Apdu
}

type Apci

type Apci struct {
	FrameFormat FrameFormat
	Rsn         SeqNumber
	Ssn         SeqNumber
	UFormat     UFormat
	// contains filtered or unexported fields
}

type Apdu

type Apdu struct {
	Apci Apci
	Asdu Asdu
}

func NewApdu

func NewApdu() Apdu

func ParseApdu

func ParseApdu(buf *bytes.Buffer) ([]Apdu, error)

func (Apdu) CheckApdu

func (apdu Apdu) CheckApdu() (bool, error)

CheckApdu checks all Apdu Fields if they comply to IEC 104 standard todo: extend

func (*Apdu) Serialize

func (apdu *Apdu) Serialize(state State) ([]byte, error)

func (Apdu) String

func (apdu Apdu) String() string

type Asdu

type Asdu struct {
	TypeId   TypeId // Type Identification
	Num      Num
	Sequence bool
	CauseTx  CauseTx // Cause of Transmission
	Negative bool
	Test     bool
	OrigAddr OrigAddr // Originator Address
	Casdu    Casdu    // Common ASDU
	InfoObj  []InfoObj
}

func NewAsdu

func NewAsdu() *Asdu

func (*Asdu) AddInfoObject

func (asdu *Asdu) AddInfoObject(infoObj InfoObj) error

an ASDU can contain multiple InfoObjects, append them using this function

func (Asdu) String

func (asdu Asdu) String() string

type Casdu

type Casdu uint16

func (Casdu) String

func (casdu Casdu) String() string

type CauseTx

type CauseTx uint8
const (
	Per_Cyc      CauseTx = 1
	Back         CauseTx = 2
	Spont        CauseTx = 3
	Init         CauseTx = 4
	Req          CauseTx = 5
	Act          CauseTx = 6
	ActCon       CauseTx = 7
	Deact        CauseTx = 8
	DeactCon     CauseTx = 9
	ActTerm      CauseTx = 10
	Retrem       CauseTx = 11
	Retloc       CauseTx = 12
	File         CauseTx = 13
	Inrogen      CauseTx = 20
	Inro1        CauseTx = 21
	Inro2        CauseTx = 22
	Inro3        CauseTx = 23
	Inro4        CauseTx = 24
	Inro5        CauseTx = 25
	Inro6        CauseTx = 26
	Inro7        CauseTx = 27
	Inro8        CauseTx = 28
	Inro9        CauseTx = 29
	Inro10       CauseTx = 30
	Inro11       CauseTx = 31
	Inro12       CauseTx = 32
	Inro13       CauseTx = 33
	Inro14       CauseTx = 34
	Inro15       CauseTx = 35
	Inro16       CauseTx = 36
	Reqcogen     CauseTx = 37
	Reqco1       CauseTx = 38
	Reqco2       CauseTx = 39
	Reqco3       CauseTx = 40
	Reqco4       CauseTx = 41
	UkTypeId     CauseTx = 44
	UkCauseTx    CauseTx = 45
	UkComAdrASDU CauseTx = 46
	UkIOA        CauseTx = 47
)

Cause of Transmission

func CauseTxFromName

func CauseTxFromName(cot string) CauseTx

func (CauseTx) String

func (i CauseTx) String() string

type CommandInfo

type CommandInfo struct {
	Quoc Quoc
	Qoi  Qoi
}

type Config

type Config struct {
	Mode            string `toml:"mode"`
	Ipv4Addr        string `toml:"ipv4Addr"`
	Port            int    `toml:"port"`
	Casdu           int    `toml:"casdu"`
	AutoAck         bool   `toml:"autoAck"`
	K               int    `toml:"k"`
	W               int    `toml:"w"`
	T1              int    `toml:"t1"`
	T2              int    `toml:"t2"`
	T3              int    `toml:"t3"`
	IoaStructured   bool   `toml:"ioaStructured"`
	InteractiveMode bool   `toml:"interactiveMode"`
	UseLocalTime    bool   `toml:"useLocalTime"`
	LogToBuffer     bool   `toml:"logToBuffer"`
	LogToStdOut     bool   `toml:"logToStdOut"`
}

func NewConfig

func NewConfig() *Config

type ConfiguredObjects

type ConfiguredObjects struct {
	MonitoringList []NameTypeIdIoa `toml:"monitoringList,multiline,omitempty"`
	ControlList    []NameTypeIdIoa `toml:"controlList,multiline,omitempty"`
}

for toml conf file

func NewConfiguredObjects

func NewConfiguredObjects() *ConfiguredObjects

type ConnState

type ConnState int
const (
	STOPPED ConnState = iota
	STARTED
	PENDING_UNCONFIRMED_STOPPED
	PENDING_STARTED
	PENDING_STOPPED
	STOP_CONN
	START_CONN
)

type FloatVal

type FloatVal float32

func (FloatVal) String

func (f FloatVal) String() string

func (FloatVal) Value

func (f FloatVal) Value() float32

type FrameFormat

type FrameFormat byte
const (
	IFormatFrame FrameFormat = 0
	SFormatFrame FrameFormat = 1
	UFormatFrame FrameFormat = 3
)

type InfoObj

type InfoObj struct {
	Ioa         Ioa // Info Object Address
	Value       InfoValue
	Quality     Quality
	CommandInfo CommandInfo
	TimeTag     time.Time // todo: add su, iv bits
}

func NewInfoObj

func NewInfoObj() InfoObj

type InfoValue

type InfoValue interface {
	Value() float32
	String() string
}

type IntVal

type IntVal int32

func (IntVal) String

func (i IntVal) String() string

func (IntVal) Value

func (i IntVal) Value() float32

type Ioa

type Ioa uint32

func (Ioa) String

func (ioa Ioa) String() string

type NameTypeIdIoa

type NameTypeIdIoa [3]string

holds three strings: obj name, typeId, IOA all are strings, so the toml marshaller will produce toml arrays (otherwise tables)

type Num

type Num uint8

type ObjectList

type ObjectList []string

func (ObjectList) FindObjectInList

func (objectList ObjectList) FindObjectInList(objName string) (int, error)

type Objects

type Objects struct {
	sync.RWMutex
	// maps keep obj Names and refer to Asdu objects
	MoniObjects ObjectsMap
	CtrlObjects ObjectsMap

	// lists are mainly for GUI use (could be merged with configuredObjects?)
	MoniList ObjectList
	CtrlList ObjectList
	// contains filtered or unexported fields
}

func NewObjects

func NewObjects() *Objects

func (*Objects) AddObjectByName

func (objects *Objects) AddObjectByName(objectName string, asdu Asdu) error

func (Objects) PrintObjects

func (objects Objects) PrintObjects()

func (*Objects) RemoveObject

func (objects *Objects) RemoveObject(objectName string) error

type ObjectsMap

type ObjectsMap map[string]Asdu

func (ObjectsMap) ObjectExists

func (objectsMap ObjectsMap) ObjectExists(objName string, ioa int, typeId int) bool

search for object by providing name, or ioa and typeid

type OrigAddr

type OrigAddr uint8

type Qoi

type Qoi uint8

func (Qoi) String

func (i Qoi) String() string

type Qu

type Qu uint8

func (Qu) String

func (i Qu) String() string

type Quality

type Quality struct {
	Bl bool
	Sb bool
	Nt bool
	Iv bool
	Ov bool
}

Quality flags

func (Quality) String

func (q Quality) String() string

type Quoc

type Quoc struct {
	Select bool
	Qu     Qu
}

type SeqNumber

type SeqNumber int

type State

type State struct {
	Config       Config
	ConnState    ConnState
	Chans        AllChans
	Objects      *Objects
	Running      bool // true when trying to connect/waiting for connection
	TcpConnected bool
	Ctx          context.Context
	Wg           sync.WaitGroup
	Cancel       context.CancelFunc
	// contains filtered or unexported fields
}

func NewState

func NewState() State

func (*State) ParseFlags

func (state *State) ParseFlags()

func (*State) Start

func (state *State) Start()

type TypeId

type TypeId uint8
const (
	M_SP_NA_1 TypeId = 1   // single-point information
	M_DP_NA_1 TypeId = 3   // double-point information
	M_ST_NA_1 TypeId = 5   // step position information
	M_BO_NA_1 TypeId = 7   // bitstring of 32 bits
	M_ME_NA_1 TypeId = 9   // measured value, normalized value
	M_ME_NB_1 TypeId = 11  // measured value, scaled value
	M_ME_NC_1 TypeId = 13  // measured value, short floating point number
	M_IT_NA_1 TypeId = 15  // integrated totals
	M_SP_TB_1 TypeId = 30  // single-point information with time tag CP56Time2a
	M_DP_TB_1 TypeId = 31  // double-point information with time tag CP56Time2a
	M_ST_TB_1 TypeId = 32  // step position information with time tag CP56Time2a
	M_BO_TB_1 TypeId = 33  // bitstring of 32 bit with time tag CP56Time2a
	M_ME_TD_1 TypeId = 34  // measured value, normalized value with time tag CP56Time2a
	M_ME_TE_1 TypeId = 35  // measured value, scaled value with time tag CP56Time2a
	M_ME_TF_1 TypeId = 36  // measured value, short floating point number with time tag CP56Time2a
	M_IT_TB_1 TypeId = 37  // integrated totals with time tag CP56Time2a
	C_SC_NA_1 TypeId = 45  // single command
	C_DC_NA_1 TypeId = 46  // double command
	C_RC_NA_1 TypeId = 47  // regulating step command
	C_SE_NA_1 TypeId = 48  // set point command, normalized value
	C_SE_NB_1 TypeId = 49  // set point command, scaled value
	C_SE_NC_1 TypeId = 50  // set point command, short floating point number
	C_BO_NA_1 TypeId = 51  // bitstring of 32 bits
	C_SC_TA_1 TypeId = 58  // single command with time tag CP56Time2a
	C_DC_TA_1 TypeId = 59  // double command with time tag CP56Time2a
	C_RC_TA_1 TypeId = 60  // regulating step command with time tag CP56Time2a
	C_SE_TA_1 TypeId = 61  // set point command, normalized value with time tag CP56Time2a
	C_SE_TB_1 TypeId = 62  // set point command, scaled value with time tag CP56Time2a
	C_SE_TC_1 TypeId = 63  // set point command, short floating-point number with time tag CP56Time2a
	C_BO_TA_1 TypeId = 64  // bitstring of 32 bits with time tag CP56Time2a
	M_EI_NA_1 TypeId = 70  // end of initialization
	C_IC_NA_1 TypeId = 100 // interrogation command
	C_CI_NA_1 TypeId = 101 // counter interrogation command
	C_RD_NA_1 TypeId = 102 // read command
	C_CS_NA_1 TypeId = 103 // clock synchronization command
	C_RP_NA_1 TypeId = 105 // reset process command
	C_TS_TA_1 TypeId = 107 // test command with time tag CP56Time2a

	// "private" range for internal purposes, will not be sent
	INTERNAL_STATE_MACHINE_NOTIFIER TypeId = 200
)

Type IDs

func TypeIdFromName

func TypeIdFromName(id string) TypeId

func (TypeId) String

func (i TypeId) String() string

type UFormat

type UFormat byte
const (
	StartDTAct UFormat = 0x07
	StartDTCon UFormat = 0x0b
	StopDTAct  UFormat = 0x13
	StopDTCon  UFormat = 0x23
	TestFRAct  UFormat = 0x43
	TestFRCon  UFormat = 0x83
)

U-Format types

func (UFormat) String

func (i UFormat) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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