lib60870-C
2.3.2
C source code library for the IEC 60870-5-101/104 protocols
|
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... | |
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... | |
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.
parameter | user provided parameter |
connection | the connection object |
event | event type |
typedef bool(* CS104_ConnectionRequestHandler) (void *parameter, const char *ipAddress) |
Connection request handler is called when a client tries to connect to the server.
parameter | user provided parameter |
ipAddress | string containing IP address and TCP port number (e.g. "192.168.1.1:34521") |
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.
parameter | user provided parameter |
connection | the connection that sent or received the message |
msg | the message buffer |
msgSize | size of the message |
sent | indicates if the message was sent or received |
void CS104_RedundancyGroup_addAllowedClient | ( | CS104_RedundancyGroup | self, |
const char * | ipAddress | ||
) |
Add an allowed client to the redundancy group.
ipAddress | the IP address of the client as C string (can be IPv4 or IPv6 address). |
void CS104_RedundancyGroup_addAllowedClientEx | ( | CS104_RedundancyGroup | self, |
const uint8_t * | ipAddress, | ||
eCS104_IPAddressType | addressType | ||
) |
Add an allowed client to the redundancy group.
ipAddress | the IP address as byte buffer (4 byte for IPv4, 16 byte for IPv6) |
addressType | type of the IP address (either IP_ADDRESS_TYPE_IPV4 or IP_ADDRESS_TYPE_IPV6) |
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.
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.
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!
redundancyGroup | the new redundancy group |
CS104_Slave CS104_Slave_create | ( | int | maxLowPrioQueueSize, |
int | maxHighPrioQueueSize | ||
) |
Create a new instance of a CS104 slave (server)
maxLowPrioQueueSize | the maximum size of the event queue |
maxHighPrioQueueSize | the maximum size of the high-priority queue |
CS104_Slave CS104_Slave_createSecure | ( | int | maxLowPrioQueueSize, |
int | maxHighPrioQueueSize, | ||
TLSConfiguration | tlsConfig | ||
) |
Create a new instance of a CS104 slave (server) with TLS enabled.
maxLowPrioQueueSize | the maximum size of the event queue |
maxHighPrioQueueSize | the maximum size of the high-priority queue |
tlsConfig | the TLS configuration object (containing configuration parameters, keys, and certificates) |
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)
asdu | the ASDU to add |
int CS104_Slave_getOpenConnections | ( | CS104_Slave | self | ) |
Get the number of connected clients.
self | the slave instance |
bool CS104_Slave_isRunning | ( | CS104_Slave | self | ) |
Check if slave is running.
self | CS104_Slave instance |
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.
self | the slave instance |
handler | the callback function to be used |
parameter | user provided context parameter that will be passed to the callback function (or NULL if not required). |
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.
self | the slave instance |
handler | the callback function to be used |
parameter | user provided context parameter that will be passed to the callback function (or NULL if not required). |
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.
self | the slave instance |
ipAddress | the IP address string or hostname |
void CS104_Slave_setLocalPort | ( | CS104_Slave | self, |
int | tcpPort | ||
) |
Set the local TCP port to bind the server.
self | the slave instance |
tcpPort | the TCP port to use (default is 2404) |
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
self | the slave instance |
maxOpenConnections | the maximum number of open client connections allowed |
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)
handler | user provided callback handler function |
parameter | user provided parameter that is passed to the callback handler |
void CS104_Slave_setServerMode | ( | CS104_Slave | self, |
CS104_ServerMode | serverMode | ||
) |
Set one of the server modes.
self | the slave instance |
serverMode | the server mode (see CS104_ServerMode) to use |
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
self | CS104_Slave instance |
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.
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.
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.
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.