lib60870-C  2.3.2
C source code library for the IEC 60870-5-101/104 protocols
Typedefs | Enumerations | Functions
CS 104 master related functions
Collaboration diagram for CS 104 master related functions:

Typedefs

typedef struct sCS104_Connection * CS104_Connection
 
typedef void(* CS104_ConnectionHandler) (void *parameter, CS104_Connection connection, CS104_ConnectionEvent event)
 Handler that is called when the connection is established or closed. More...
 

Enumerations

enum  CS104_ConnectionEvent {
  CS104_CONNECTION_OPENED = 0 , CS104_CONNECTION_CLOSED = 1 , CS104_CONNECTION_STARTDT_CON_RECEIVED = 2 , CS104_CONNECTION_STOPDT_CON_RECEIVED = 3 ,
  CS104_CONNECTION_FAILED = 4
}
 

Functions

CS104_Connection CS104_Connection_create (const char *hostname, int tcpPort)
 Create a new connection object. More...
 
CS104_Connection CS104_Connection_createSecure (const char *hostname, int tcpPort, TLSConfiguration tlsConfig)
 Create a new secure connection object (uses TLS) More...
 
void CS104_Connection_setLocalAddress (CS104_Connection self, const char *localIpAddress, int localPort)
 Set the local IP address and port to be used by the client. More...
 
void CS104_Connection_setAPCIParameters (CS104_Connection self, const CS104_APCIParameters parameters)
 Set the CS104 specific APCI parameters. More...
 
CS104_APCIParameters CS104_Connection_getAPCIParameters (CS104_Connection self)
 Get the currently used CS104 specific APCI parameters.
 
void CS104_Connection_setAppLayerParameters (CS104_Connection self, const CS101_AppLayerParameters parameters)
 Set the CS101 application layer parameters. More...
 
CS101_AppLayerParameters CS104_Connection_getAppLayerParameters (CS104_Connection self)
 Return the currently used application layer parameter. More...
 
void CS104_Connection_setConnectTimeout (CS104_Connection self, int millies)
 Sets the timeout for connecting to the server (in ms) More...
 
void CS104_Connection_connectAsync (CS104_Connection self)
 non-blocking connect. More...
 
bool CS104_Connection_connect (CS104_Connection self)
 blocking connect More...
 
void CS104_Connection_sendStartDT (CS104_Connection self)
 start data transmission on this connection More...
 
void CS104_Connection_sendStopDT (CS104_Connection self)
 stop data transmission on this connection
 
bool CS104_Connection_isTransmitBufferFull (CS104_Connection self)
 Check if the transmit (send) buffer is full. If true the next send command will fail. More...
 
bool CS104_Connection_sendInterrogationCommand (CS104_Connection self, CS101_CauseOfTransmission cot, int ca, QualifierOfInterrogation qoi)
 send an interrogation command More...
 
bool CS104_Connection_sendCounterInterrogationCommand (CS104_Connection self, CS101_CauseOfTransmission cot, int ca, uint8_t qcc)
 send a counter interrogation command More...
 
bool CS104_Connection_sendReadCommand (CS104_Connection self, int ca, int ioa)
 Sends a read command (C_RD_NA_1 typeID: 102) More...
 
bool CS104_Connection_sendClockSyncCommand (CS104_Connection self, int ca, CP56Time2a newTime)
 Sends a clock synchronization command (C_CS_NA_1 typeID: 103) More...
 
bool CS104_Connection_sendTestCommand (CS104_Connection self, int ca)
 Send a test command (C_TS_NA_1 typeID: 104) More...
 
bool CS104_Connection_sendTestCommandWithTimestamp (CS104_Connection self, int ca, uint16_t tsc, CP56Time2a timestamp)
 Send a test command with timestamp (C_TS_TA_1 typeID: 107) More...
 
bool CS104_Connection_sendProcessCommand (CS104_Connection self, TypeID typeId, CS101_CauseOfTransmission cot, int ca, InformationObject command)
 Send a process command to the controlled (or other) station. More...
 
bool CS104_Connection_sendProcessCommandEx (CS104_Connection self, CS101_CauseOfTransmission cot, int ca, InformationObject sc)
 Send a process command to the controlled (or other) station. More...
 
bool CS104_Connection_sendASDU (CS104_Connection self, CS101_ASDU asdu)
 Send a user specified ASDU. More...
 
void CS104_Connection_setASDUReceivedHandler (CS104_Connection self, CS101_ASDUReceivedHandler handler, void *parameter)
 Register a callback handler for received ASDUs. More...
 
void CS104_Connection_setConnectionHandler (CS104_Connection self, CS104_ConnectionHandler handler, void *parameter)
 Set the connection event handler. More...
 
void CS104_Connection_setRawMessageHandler (CS104_Connection self, IEC60870_RawMessageHandler handler, void *parameter)
 Set the raw message callback (called when a message is sent or received) More...
 
void CS104_Connection_close (CS104_Connection self)
 Close the connection.
 
void CS104_Connection_destroy (CS104_Connection self)
 Close the connection and free all related resources.
 

Detailed Description

Typedef Documentation

◆ CS104_ConnectionHandler

typedef void(* CS104_ConnectionHandler) (void *parameter, CS104_Connection connection, CS104_ConnectionEvent event)

Handler that is called when the connection is established or closed.

Note
Calling CS104_Connection_destroy or CS104_Connection_close inside of the callback causes a memory leak!
Parameters
parameteruser provided parameter
connectionthe connection object
eventevent type

Function Documentation

◆ CS104_Connection_connect()

bool CS104_Connection_connect ( CS104_Connection  self)

blocking connect

Establishes a connection to a server. This function is blocking and will return after the connection is established or the connect timeout elapsed.

Parameters
selfCS104_Connection instance
Returns
true when connected, false otherwise

◆ CS104_Connection_connectAsync()

void CS104_Connection_connectAsync ( CS104_Connection  self)

non-blocking connect.

Invokes a connection establishment to the server and returns immediately.

Parameters
selfCS104_Connection instance

◆ CS104_Connection_create()

CS104_Connection CS104_Connection_create ( const char *  hostname,
int  tcpPort 
)

Create a new connection object.

Parameters
hostnamehost name of IP address of the server to connect
tcpPorttcp port of the server to connect. If set to -1 use default port (2404)
Returns
the new connection object

◆ CS104_Connection_createSecure()

CS104_Connection CS104_Connection_createSecure ( const char *  hostname,
int  tcpPort,
TLSConfiguration  tlsConfig 
)

Create a new secure connection object (uses TLS)

Parameters
hostnamehost name of IP address of the server to connect
tcpPorttcp port of the server to connect. If set to -1 use default port (19998)
tlcConfigthe TLS configuration (certificates, keys, and parameters)
Returns
the new connection object

◆ CS104_Connection_getAppLayerParameters()

CS101_AppLayerParameters CS104_Connection_getAppLayerParameters ( CS104_Connection  self)

Return the currently used application layer parameter.

NOTE: The application layer parameters are required to create CS101_ASDU objects.

Parameters
selfCS104_Connection instance
Returns
the currently used CS101_AppLayerParameters object

◆ CS104_Connection_isTransmitBufferFull()

bool CS104_Connection_isTransmitBufferFull ( CS104_Connection  self)

Check if the transmit (send) buffer is full. If true the next send command will fail.

The transmit buffer is full when the slave/server didn't confirm the last k sent messages. In this case the next message can only be sent after the next confirmation (by I or S messages) that frees part of the sent messages buffer.

◆ CS104_Connection_sendASDU()

bool CS104_Connection_sendASDU ( CS104_Connection  self,
CS101_ASDU  asdu 
)

Send a user specified ASDU.

Parameters
asduthe ASDU to send
Returns
true if message was sent, false otherwise

◆ CS104_Connection_sendClockSyncCommand()

bool CS104_Connection_sendClockSyncCommand ( CS104_Connection  self,
int  ca,
CP56Time2a  newTime 
)

Sends a clock synchronization command (C_CS_NA_1 typeID: 103)

Parameters
caCommon address of the slave/server
newTimenew system time for the slave/server
Returns
true if message was sent, false otherwise

◆ CS104_Connection_sendCounterInterrogationCommand()

bool CS104_Connection_sendCounterInterrogationCommand ( CS104_Connection  self,
CS101_CauseOfTransmission  cot,
int  ca,
uint8_t  qcc 
)

send a counter interrogation command

Parameters
cotcause of transmission
caCommon address of the slave/server
qcc
Returns
true if message was sent, false otherwise

◆ CS104_Connection_sendInterrogationCommand()

bool CS104_Connection_sendInterrogationCommand ( CS104_Connection  self,
CS101_CauseOfTransmission  cot,
int  ca,
QualifierOfInterrogation  qoi 
)

send an interrogation command

Parameters
cotcause of transmission
caCommon address of the slave/server
qoiqualifier of interrogation (20 for station interrogation)
Returns
true if message was sent, false otherwise

◆ CS104_Connection_sendProcessCommand()

bool CS104_Connection_sendProcessCommand ( CS104_Connection  self,
TypeID  typeId,
CS101_CauseOfTransmission  cot,
int  ca,
InformationObject  command 
)

Send a process command to the controlled (or other) station.

Deprecated:
Use CS104_Connection_sendProcessCommandEx instead
Parameters
typeIdthe type ID of the command message to send or 0 to use the type ID of the information object
cotthe cause of transmission (should be ACTIVATION to select/execute or ACT_TERM to cancel the command)
cathe common address of the information object
commandthe command information object (e.g. SingleCommand or DoubleCommand)
Returns
true if message was sent, false otherwise

◆ CS104_Connection_sendProcessCommandEx()

bool CS104_Connection_sendProcessCommandEx ( CS104_Connection  self,
CS101_CauseOfTransmission  cot,
int  ca,
InformationObject  sc 
)

Send a process command to the controlled (or other) station.

Parameters
cotthe cause of transmission (should be ACTIVATION to select/execute or ACT_TERM to cancel the command)
cathe common address of the information object
commandthe command information object (e.g. SingleCommand or DoubleCommand)
Returns
true if message was sent, false otherwise

◆ CS104_Connection_sendReadCommand()

bool CS104_Connection_sendReadCommand ( CS104_Connection  self,
int  ca,
int  ioa 
)

Sends a read command (C_RD_NA_1 typeID: 102)

This will send a read command C_RC_NA_1 (102) to the slave/outstation. The COT is always REQUEST (5). It is used to implement the cyclical polling of data application function.

Parameters
caCommon address of the slave/server
ioaInformation object address of the data point to read
Returns
true if message was sent, false otherwise

◆ CS104_Connection_sendStartDT()

void CS104_Connection_sendStartDT ( CS104_Connection  self)

start data transmission on this connection

After issuing this command the client (master) will receive spontaneous (unsolicited) messages from the server (slave).

◆ CS104_Connection_sendTestCommand()

bool CS104_Connection_sendTestCommand ( CS104_Connection  self,
int  ca 
)

Send a test command (C_TS_NA_1 typeID: 104)

Note: This command is not supported by IEC 60870-5-104

Parameters
caCommon address of the slave/server
Returns
true if message was sent, false otherwise

◆ CS104_Connection_sendTestCommandWithTimestamp()

bool CS104_Connection_sendTestCommandWithTimestamp ( CS104_Connection  self,
int  ca,
uint16_t  tsc,
CP56Time2a  timestamp 
)

Send a test command with timestamp (C_TS_TA_1 typeID: 107)

Parameters
caCommon address of the slave/server
tsctest sequence counter
timestampCP56Time2a timestamp
Returns
true if message was sent, false otherwise

◆ CS104_Connection_setAPCIParameters()

void CS104_Connection_setAPCIParameters ( CS104_Connection  self,
const CS104_APCIParameters  parameters 
)

Set the CS104 specific APCI parameters.

If not set the default parameters are used. This function must be called before the CS104_Connection_connect function is called! If the function is called after the connect the behavior is undefined.

Parameters
selfCS104_Connection instance
parametersthe APCI layer parameters

◆ CS104_Connection_setAppLayerParameters()

void CS104_Connection_setAppLayerParameters ( CS104_Connection  self,
const CS101_AppLayerParameters  parameters 
)

Set the CS101 application layer parameters.

If not set the default parameters are used. This function must be called before the CS104_Connection_connect function is called! If the function is called after the connect the behavior is undefined.

Parameters
selfCS104_Connection instance
parametersthe application layer parameters

◆ CS104_Connection_setASDUReceivedHandler()

void CS104_Connection_setASDUReceivedHandler ( CS104_Connection  self,
CS101_ASDUReceivedHandler  handler,
void *  parameter 
)

Register a callback handler for received ASDUs.

Parameters
handleruser provided callback handler function
parameteruser provided parameter that is passed to the callback handler

◆ CS104_Connection_setConnectionHandler()

void CS104_Connection_setConnectionHandler ( CS104_Connection  self,
CS104_ConnectionHandler  handler,
void *  parameter 
)

Set the connection event handler.

Parameters
handleruser provided callback handler function
parameteruser provided parameter that is passed to the callback handler

◆ CS104_Connection_setConnectTimeout()

void CS104_Connection_setConnectTimeout ( CS104_Connection  self,
int  millies 
)

Sets the timeout for connecting to the server (in ms)

Deprecated:
Function has no effect! Set T0 parameter instead.
Parameters
self
milliestimeout value in ms

◆ CS104_Connection_setLocalAddress()

void CS104_Connection_setLocalAddress ( CS104_Connection  self,
const char *  localIpAddress,
int  localPort 
)

Set the local IP address and port to be used by the client.

NOTE: This function is optional. When not used the OS decides what IP address and TCP port to use.

Parameters
selfCS104_Connection instance
localIpAddressthe local IP address or hostname as C string
localPortthe local TCP port to use. When < 1 the OS will chose the TCP port to use.

◆ CS104_Connection_setRawMessageHandler()

void CS104_Connection_setRawMessageHandler ( CS104_Connection  self,
IEC60870_RawMessageHandler  handler,
void *  parameter 
)

Set the raw message callback (called when a message is sent or received)

Parameters
handleruser provided callback handler function
parameteruser provided parameter that is passed to the callback handler