lib60870-C  2.3.2
C source code library for the IEC 60870-5-101/104 protocols
Typedefs | Enumerations | Functions
CS 104 slave (TCP/IP server) related functions
Collaboration diagram for CS 104 slave (TCP/IP server) related functions:

Typedefs

typedef struct sCS104_Slave * CS104_Slave
 
typedef struct sCS104_RedundancyGroup * CS104_RedundancyGroup
 
typedef bool(* CS104_ConnectionRequestHandler) (void *parameter, const char *ipAddress)
 Connection request handler is called when a client tries to connect to the server. More...
 
typedef void(* CS104_ConnectionEventHandler) (void *parameter, IMasterConnection connection, CS104_PeerConnectionEvent event)
 Handler that is called when a peer connection is established or closed, or START_DT/STOP_DT is issued. More...
 
typedef void(* CS104_SlaveRawMessageHandler) (void *parameter, IMasterConnection connection, uint8_t *msg, int msgSize, bool send)
 Callback handler for sent and received messages. More...
 

Enumerations

enum  CS104_ServerMode { CS104_MODE_SINGLE_REDUNDANCY_GROUP , CS104_MODE_CONNECTION_IS_REDUNDANCY_GROUP , CS104_MODE_MULTIPLE_REDUNDANCY_GROUPS }
 
enum  eCS104_IPAddressType { IP_ADDRESS_TYPE_IPV4 , IP_ADDRESS_TYPE_IPV6 }
 
enum  CS104_PeerConnectionEvent { CS104_CON_EVENT_CONNECTION_OPENED = 0 , CS104_CON_EVENT_CONNECTION_CLOSED = 1 , CS104_CON_EVENT_ACTIVATED = 2 , CS104_CON_EVENT_DEACTIVATED = 3 }
 

Functions

CS104_Slave CS104_Slave_create (int maxLowPrioQueueSize, int maxHighPrioQueueSize)
 Create a new instance of a CS104 slave (server) More...
 
CS104_Slave CS104_Slave_createSecure (int maxLowPrioQueueSize, int maxHighPrioQueueSize, TLSConfiguration tlsConfig)
 Create a new instance of a CS104 slave (server) with TLS enabled. More...
 
void CS104_Slave_addPlugin (CS104_Slave self, CS101_SlavePlugin plugin)
 
void CS104_Slave_setLocalAddress (CS104_Slave self, const char *ipAddress)
 Set the local IP address to bind the server use "0.0.0.0" to bind to all interfaces. More...
 
void CS104_Slave_setLocalPort (CS104_Slave self, int tcpPort)
 Set the local TCP port to bind the server. More...
 
int CS104_Slave_getOpenConnections (CS104_Slave self)
 Get the number of connected clients. More...
 
void CS104_Slave_setMaxOpenConnections (CS104_Slave self, int maxOpenConnections)
 set the maximum number of open client connections allowed More...
 
void CS104_Slave_setServerMode (CS104_Slave self, CS104_ServerMode serverMode)
 Set one of the server modes. More...
 
void CS104_Slave_setConnectionRequestHandler (CS104_Slave self, CS104_ConnectionRequestHandler handler, void *parameter)
 Set the connection request handler. More...
 
void CS104_Slave_setConnectionEventHandler (CS104_Slave self, CS104_ConnectionEventHandler handler, void *parameter)
 Set the connection event handler. More...
 
void CS104_Slave_setInterrogationHandler (CS104_Slave self, CS101_InterrogationHandler handler, void *parameter)
 
void CS104_Slave_setCounterInterrogationHandler (CS104_Slave self, CS101_CounterInterrogationHandler handler, void *parameter)
 
void CS104_Slave_setReadHandler (CS104_Slave self, CS101_ReadHandler handler, void *parameter)
 set handler for read request (C_RD_NA_1 - 102)
 
void CS104_Slave_setASDUHandler (CS104_Slave self, CS101_ASDUHandler handler, void *parameter)
 
void CS104_Slave_setClockSyncHandler (CS104_Slave self, CS101_ClockSynchronizationHandler handler, void *parameter)
 
void CS104_Slave_setRawMessageHandler (CS104_Slave self, CS104_SlaveRawMessageHandler handler, void *parameter)
 Set the raw message callback (called when a message is sent or received) More...
 
CS104_APCIParameters CS104_Slave_getConnectionParameters (CS104_Slave self)
 Get the APCI parameters instance. APCI parameters are CS 104 specific parameters.
 
CS101_AppLayerParameters CS104_Slave_getAppLayerParameters (CS104_Slave self)
 Get the application layer parameters instance..
 
void CS104_Slave_start (CS104_Slave self)
 Start the CS 104 slave. The slave (server) will listen on the configured TCP/IP port. More...
 
bool CS104_Slave_isRunning (CS104_Slave self)
 Check if slave is running. More...
 
void CS104_Slave_stop (CS104_Slave self)
 Stop the server. More...
 
void CS104_Slave_startThreadless (CS104_Slave self)
 Start the slave (server) in non-threaded mode. More...
 
void CS104_Slave_stopThreadless (CS104_Slave self)
 Stop the server in non-threaded mode. More...
 
void CS104_Slave_tick (CS104_Slave self)
 Protocol stack tick function for non-threaded mode. More...
 
int CS104_Slave_getNumberOfQueueEntries (CS104_Slave self, CS104_RedundancyGroup redGroup)
 
void CS104_Slave_enqueueASDU (CS104_Slave self, CS101_ASDU asdu)
 Add an ASDU to the low-priority queue of the slave (use for periodic and spontaneous messages) More...
 
void CS104_Slave_addRedundancyGroup (CS104_Slave self, CS104_RedundancyGroup redundancyGroup)
 Add a new redundancy group to the server. More...
 
void CS104_Slave_destroy (CS104_Slave self)
 Delete the slave instance. Release all resources.
 
CS104_RedundancyGroup CS104_RedundancyGroup_create (const char *name)
 Create a new redundancy group. More...
 
void CS104_RedundancyGroup_addAllowedClient (CS104_RedundancyGroup self, const char *ipAddress)
 Add an allowed client to the redundancy group. More...
 
void CS104_RedundancyGroup_addAllowedClientEx (CS104_RedundancyGroup self, const uint8_t *ipAddress, eCS104_IPAddressType addressType)
 Add an allowed client to the redundancy group. More...
 
void CS104_RedundancyGroup_destroy (CS104_RedundancyGroup self)
 Destroy the instance and release all resources. More...
 

Detailed Description

Typedef Documentation

◆ CS104_ConnectionEventHandler

typedef void(* CS104_ConnectionEventHandler) (void *parameter, IMasterConnection connection, CS104_PeerConnectionEvent event)

Handler that is called when a peer connection is established or closed, or START_DT/STOP_DT is issued.

Parameters
parameteruser provided parameter
connectionthe connection object
eventevent type

◆ CS104_ConnectionRequestHandler

typedef bool(* CS104_ConnectionRequestHandler) (void *parameter, const char *ipAddress)

Connection request handler is called when a client tries to connect to the server.

Parameters
parameteruser provided parameter
ipAddressstring containing IP address and TCP port number (e.g. "192.168.1.1:34521")
Returns
true to accept the connection request, false to deny

◆ CS104_SlaveRawMessageHandler

typedef void(* CS104_SlaveRawMessageHandler) (void *parameter, IMasterConnection connection, uint8_t *msg, int msgSize, bool send)

Callback handler for sent and received messages.

This callback handler provides access to the raw message buffer of received or sent messages. It can be used for debugging purposes. Usually it is not used nor required for applications.

Parameters
parameteruser provided parameter
connectionthe connection that sent or received the message
msgthe message buffer
msgSizesize of the message
sentindicates if the message was sent or received

Function Documentation

◆ CS104_RedundancyGroup_addAllowedClient()

void CS104_RedundancyGroup_addAllowedClient ( CS104_RedundancyGroup  self,
const char *  ipAddress 
)

Add an allowed client to the redundancy group.

Parameters
ipAddressthe IP address of the client as C string (can be IPv4 or IPv6 address).

◆ CS104_RedundancyGroup_addAllowedClientEx()

void CS104_RedundancyGroup_addAllowedClientEx ( CS104_RedundancyGroup  self,
const uint8_t *  ipAddress,
eCS104_IPAddressType  addressType 
)

Add an allowed client to the redundancy group.

Parameters
ipAddressthe IP address as byte buffer (4 byte for IPv4, 16 byte for IPv6)
addressTypetype of the IP address (either IP_ADDRESS_TYPE_IPV4 or IP_ADDRESS_TYPE_IPV6)

◆ CS104_RedundancyGroup_create()

CS104_RedundancyGroup CS104_RedundancyGroup_create ( const char *  name)

Create a new redundancy group.

A redundancy group is a group of clients that share the same event queue. Redundancy groups can only be used with server mode CS104_MODE_MULTIPLE_REDUNDANCY_GROUPS.

◆ CS104_RedundancyGroup_destroy()

void CS104_RedundancyGroup_destroy ( CS104_RedundancyGroup  self)

Destroy the instance and release all resources.

NOTE: This function will be called by CS104_Slave_destroy. After using the CS104_Slave_addRedundancyGroup function the redundancy group object must not be destroyed manually.

◆ CS104_Slave_addRedundancyGroup()

void CS104_Slave_addRedundancyGroup ( CS104_Slave  self,
CS104_RedundancyGroup  redundancyGroup 
)

Add a new redundancy group to the server.

A redundancy group is a group of clients that share the same event queue. This function can only be used with server mode CS104_MODE_MULTIPLE_REDUNDANCY_GROUPS.

NOTE: Has to be called before the server is started!

Parameters
redundancyGroupthe new redundancy group

◆ CS104_Slave_create()

CS104_Slave CS104_Slave_create ( int  maxLowPrioQueueSize,
int  maxHighPrioQueueSize 
)

Create a new instance of a CS104 slave (server)

Parameters
maxLowPrioQueueSizethe maximum size of the event queue
maxHighPrioQueueSizethe maximum size of the high-priority queue
Returns
the new slave instance

◆ CS104_Slave_createSecure()

CS104_Slave CS104_Slave_createSecure ( int  maxLowPrioQueueSize,
int  maxHighPrioQueueSize,
TLSConfiguration  tlsConfig 
)

Create a new instance of a CS104 slave (server) with TLS enabled.

Parameters
maxLowPrioQueueSizethe maximum size of the event queue
maxHighPrioQueueSizethe maximum size of the high-priority queue
tlsConfigthe TLS configuration object (containing configuration parameters, keys, and certificates)
Returns
the new slave instance

◆ CS104_Slave_enqueueASDU()

void CS104_Slave_enqueueASDU ( CS104_Slave  self,
CS101_ASDU  asdu 
)

Add an ASDU to the low-priority queue of the slave (use for periodic and spontaneous messages)

Parameters
asduthe ASDU to add

◆ CS104_Slave_getOpenConnections()

int CS104_Slave_getOpenConnections ( CS104_Slave  self)

Get the number of connected clients.

Parameters
selfthe slave instance

◆ CS104_Slave_isRunning()

bool CS104_Slave_isRunning ( CS104_Slave  self)

Check if slave is running.

Parameters
selfCS104_Slave instance
Returns
true when slave is running, false otherwise

◆ CS104_Slave_setConnectionEventHandler()

void CS104_Slave_setConnectionEventHandler ( CS104_Slave  self,
CS104_ConnectionEventHandler  handler,
void *  parameter 
)

Set the connection event handler.

The connection request handler is called whenever a connection event happens. A connection event can be when a client connects or disconnects, or when a START_DT or STOP_DT message is received.

Parameters
selfthe slave instance
handlerthe callback function to be used
parameteruser provided context parameter that will be passed to the callback function (or NULL if not required).

◆ CS104_Slave_setConnectionRequestHandler()

void CS104_Slave_setConnectionRequestHandler ( CS104_Slave  self,
CS104_ConnectionRequestHandler  handler,
void *  parameter 
)

Set the connection request handler.

The connection request handler is called whenever a client/master is trying to connect. This handler can be used to implement access control mechanisms as it allows the user to decide if the new connection is accepted or not.

Parameters
selfthe slave instance
handlerthe callback function to be used
parameteruser provided context parameter that will be passed to the callback function (or NULL if not required).

◆ CS104_Slave_setLocalAddress()

void CS104_Slave_setLocalAddress ( CS104_Slave  self,
const char *  ipAddress 
)

Set the local IP address to bind the server use "0.0.0.0" to bind to all interfaces.

Parameters
selfthe slave instance
ipAddressthe IP address string or hostname

◆ CS104_Slave_setLocalPort()

void CS104_Slave_setLocalPort ( CS104_Slave  self,
int  tcpPort 
)

Set the local TCP port to bind the server.

Parameters
selfthe slave instance
tcpPortthe TCP port to use (default is 2404)

◆ CS104_Slave_setMaxOpenConnections()

void CS104_Slave_setMaxOpenConnections ( CS104_Slave  self,
int  maxOpenConnections 
)

set the maximum number of open client connections allowed

NOTE: the number cannot be larger than the static maximum defined in

Parameters
selfthe slave instance
maxOpenConnectionsthe maximum number of open client connections allowed

◆ CS104_Slave_setRawMessageHandler()

void CS104_Slave_setRawMessageHandler ( CS104_Slave  self,
CS104_SlaveRawMessageHandler  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

◆ CS104_Slave_setServerMode()

void CS104_Slave_setServerMode ( CS104_Slave  self,
CS104_ServerMode  serverMode 
)

Set one of the server modes.

Parameters
selfthe slave instance
serverModethe server mode (see CS104_ServerMode) to use

◆ CS104_Slave_start()

void CS104_Slave_start ( CS104_Slave  self)

Start the CS 104 slave. The slave (server) will listen on the configured TCP/IP port.

NOTE: This function will start a thread that handles the incoming client connections. This function requires CONFIG_USE_THREADS = 1 and CONFIG_USE_SEMAPHORES == 1 in lib60870_config.h

Parameters
selfCS104_Slave instance

◆ CS104_Slave_startThreadless()

void CS104_Slave_startThreadless ( CS104_Slave  self)

Start the slave (server) in non-threaded mode.

Start listening to incoming TCP/IP connections.

NOTE: Server should only be started after all configuration is done.

◆ CS104_Slave_stop()

void CS104_Slave_stop ( CS104_Slave  self)

Stop the server.

Stop listening to incoming TCP/IP connections and close all open connections. Event buffers will be deactivated.

◆ CS104_Slave_stopThreadless()

void CS104_Slave_stopThreadless ( CS104_Slave  self)

Stop the server in non-threaded mode.

Stop listening to incoming TCP/IP connections and close all open connections. Event buffers will be deactivated.

◆ CS104_Slave_tick()

void CS104_Slave_tick ( CS104_Slave  self)

Protocol stack tick function for non-threaded mode.

Handle incoming connection requests and messages, send buffered events, and handle periodic tasks.

NOTE: This function has to be called periodically by the application.