lib60870-C  2.3.2
C source code library for the IEC 60870-5-101/104 protocols
cs104_slave.h
Go to the documentation of this file.
1 /*
2  * cs104_slave.h
3  *
4  * Copyright 2017-2022 Michael Zillgith
5  *
6  * This file is part of lib60870-C
7  *
8  * lib60870-C is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * lib60870-C is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with lib60870-C. If not, see <http://www.gnu.org/licenses/>.
20  *
21  * See COPYING file for the complete license text.
22  */
23 
24 #ifndef SRC_INC_API_CS104_SLAVE_H_
25 #define SRC_INC_API_CS104_SLAVE_H_
26 
27 #include "iec60870_slave.h"
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
50 typedef struct sCS104_Slave* CS104_Slave;
51 
52 typedef enum {
53  CS104_MODE_SINGLE_REDUNDANCY_GROUP,
54  CS104_MODE_CONNECTION_IS_REDUNDANCY_GROUP,
55  CS104_MODE_MULTIPLE_REDUNDANCY_GROUPS
56 } CS104_ServerMode;
57 
58 typedef enum
59 {
60  IP_ADDRESS_TYPE_IPV4,
61  IP_ADDRESS_TYPE_IPV6
62 } eCS104_IPAddressType;
63 
64 typedef struct sCS104_RedundancyGroup* CS104_RedundancyGroup;
65 
74 typedef bool (*CS104_ConnectionRequestHandler) (void* parameter, const char* ipAddress);
75 
76 typedef enum {
77  CS104_CON_EVENT_CONNECTION_OPENED = 0,
78  CS104_CON_EVENT_CONNECTION_CLOSED = 1,
79  CS104_CON_EVENT_ACTIVATED = 2,
80  CS104_CON_EVENT_DEACTIVATED = 3
81 } CS104_PeerConnectionEvent;
82 
83 
91 typedef void (*CS104_ConnectionEventHandler) (void* parameter, IMasterConnection connection, CS104_PeerConnectionEvent event);
92 
106 typedef void (*CS104_SlaveRawMessageHandler) (void* parameter, IMasterConnection connection, uint8_t* msg, int msgSize, bool send);
107 
108 
117 CS104_Slave
118 CS104_Slave_create(int maxLowPrioQueueSize, int maxHighPrioQueueSize);
119 
129 CS104_Slave
130 CS104_Slave_createSecure(int maxLowPrioQueueSize, int maxHighPrioQueueSize, TLSConfiguration tlsConfig);
131 
132 void
133 CS104_Slave_addPlugin(CS104_Slave self, CS101_SlavePlugin plugin);
134 
142 void
143 CS104_Slave_setLocalAddress(CS104_Slave self, const char* ipAddress);
144 
151 void
152 CS104_Slave_setLocalPort(CS104_Slave self, int tcpPort);
153 
159 int
161 
170 void
171 CS104_Slave_setMaxOpenConnections(CS104_Slave self, int maxOpenConnections);
172 
179 void
180 CS104_Slave_setServerMode(CS104_Slave self, CS104_ServerMode serverMode);
181 
193 void
195 
206 void
207 CS104_Slave_setConnectionEventHandler(CS104_Slave self, CS104_ConnectionEventHandler handler, void* parameter);
208 
209 void
210 CS104_Slave_setInterrogationHandler(CS104_Slave self, CS101_InterrogationHandler handler, void* parameter);
211 
212 void
213 CS104_Slave_setCounterInterrogationHandler(CS104_Slave self, CS101_CounterInterrogationHandler handler, void* parameter);
214 
218 void
219 CS104_Slave_setReadHandler(CS104_Slave self, CS101_ReadHandler handler, void* parameter);
220 
221 void
222 CS104_Slave_setASDUHandler(CS104_Slave self, CS101_ASDUHandler handler, void* parameter);
223 
224 void
225 CS104_Slave_setClockSyncHandler(CS104_Slave self, CS101_ClockSynchronizationHandler handler, void* parameter);
226 
233 void
234 CS104_Slave_setRawMessageHandler(CS104_Slave self, CS104_SlaveRawMessageHandler handler, void* parameter);
235 
241 
247 
256 void
257 CS104_Slave_start(CS104_Slave self);
258 
266 bool
267 CS104_Slave_isRunning(CS104_Slave self);
268 
275 void
276 CS104_Slave_stop(CS104_Slave self);
277 
285 void
286 CS104_Slave_startThreadless(CS104_Slave self);
287 
294 void
295 CS104_Slave_stopThreadless(CS104_Slave self);
296 
305 void
306 CS104_Slave_tick(CS104_Slave self);
307 
308 /*
309  * \brief Gets the number of ASDU in the low-priority queue
310  *
311  * NOTE: Mode CS104_MODE_CONNECTION_IS_REDUNDANCY_GROUP is not supported by this function.
312  *
313  * \param redGroup the redundancy group to use or NULL for single redundancy mode
314  *
315  * \return the number of ASDU in the low-priority queue
316  */
317 int
318 CS104_Slave_getNumberOfQueueEntries(CS104_Slave self, CS104_RedundancyGroup redGroup);
319 
325 void
326 CS104_Slave_enqueueASDU(CS104_Slave self, CS101_ASDU asdu);
327 
338 void
339 CS104_Slave_addRedundancyGroup(CS104_Slave self, CS104_RedundancyGroup redundancyGroup);
340 
344 void
345 CS104_Slave_destroy(CS104_Slave self);
346 
353 CS104_RedundancyGroup
355 
361 void
362 CS104_RedundancyGroup_addAllowedClient(CS104_RedundancyGroup self, const char* ipAddress);
363 
370 void
371 CS104_RedundancyGroup_addAllowedClientEx(CS104_RedundancyGroup self, const uint8_t* ipAddress, eCS104_IPAddressType addressType);
372 
380 void
381 CS104_RedundancyGroup_destroy(CS104_RedundancyGroup self);
382 
391 #ifdef __cplusplus
392 }
393 #endif
394 
395 #endif /* SRC_INC_API_CS104_SLAVE_H_ */
struct sCS101_ASDU * CS101_ASDU
Application Service Data Unit (ASDU) for the CS101/CS104 application layer.
Definition: iec60870_common.h:216
void CS104_Slave_start(CS104_Slave self)
Start the CS 104 slave. The slave (server) will listen on the configured TCP/IP port.
void CS104_RedundancyGroup_destroy(CS104_RedundancyGroup self)
Destroy the instance and release all resources.
void(* CS104_SlaveRawMessageHandler)(void *parameter, IMasterConnection connection, uint8_t *msg, int msgSize, bool send)
Callback handler for sent and received messages.
Definition: cs104_slave.h:106
void CS104_Slave_setLocalPort(CS104_Slave self, int tcpPort)
Set the local TCP port to bind the server.
CS104_APCIParameters CS104_Slave_getConnectionParameters(CS104_Slave self)
Get the APCI parameters instance. APCI parameters are CS 104 specific parameters.
CS104_Slave CS104_Slave_create(int maxLowPrioQueueSize, int maxHighPrioQueueSize)
Create a new instance of a CS104 slave (server)
void CS104_Slave_destroy(CS104_Slave self)
Delete the slave instance. Release all resources.
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.
void CS104_Slave_setServerMode(CS104_Slave self, CS104_ServerMode serverMode)
Set one of the server modes.
void CS104_RedundancyGroup_addAllowedClient(CS104_RedundancyGroup self, const char *ipAddress)
Add an allowed client to the redundancy group.
void CS104_Slave_startThreadless(CS104_Slave self)
Start the slave (server) in non-threaded mode.
int CS104_Slave_getOpenConnections(CS104_Slave self)
Get the number of connected clients.
void CS104_Slave_setConnectionRequestHandler(CS104_Slave self, CS104_ConnectionRequestHandler handler, void *parameter)
Set the connection request handler.
void CS104_Slave_tick(CS104_Slave self)
Protocol stack tick function for non-threaded mode.
void CS104_Slave_stop(CS104_Slave self)
Stop the server.
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...
Definition: cs104_slave.h:91
CS104_Slave CS104_Slave_createSecure(int maxLowPrioQueueSize, int maxHighPrioQueueSize, TLSConfiguration tlsConfig)
Create a new instance of a CS104 slave (server) with TLS enabled.
void CS104_Slave_stopThreadless(CS104_Slave self)
Stop the server in non-threaded mode.
void CS104_Slave_setConnectionEventHandler(CS104_Slave self, CS104_ConnectionEventHandler handler, void *parameter)
Set the connection event handler.
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)
bool(* CS104_ConnectionRequestHandler)(void *parameter, const char *ipAddress)
Connection request handler is called when a client tries to connect to the server.
Definition: cs104_slave.h:74
void CS104_Slave_addRedundancyGroup(CS104_Slave self, CS104_RedundancyGroup redundancyGroup)
Add a new redundancy group to the server.
CS101_AppLayerParameters CS104_Slave_getAppLayerParameters(CS104_Slave self)
Get the application layer parameters instance..
bool CS104_Slave_isRunning(CS104_Slave self)
Check if slave is running.
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)
void CS104_Slave_setReadHandler(CS104_Slave self, CS101_ReadHandler handler, void *parameter)
set handler for read request (C_RD_NA_1 - 102)
void CS104_RedundancyGroup_addAllowedClientEx(CS104_RedundancyGroup self, const uint8_t *ipAddress, eCS104_IPAddressType addressType)
Add an allowed client to the redundancy group.
CS104_RedundancyGroup CS104_RedundancyGroup_create(const char *name)
Create a new redundancy group.
void CS104_Slave_setMaxOpenConnections(CS104_Slave self, int maxOpenConnections)
set the maximum number of open client connections allowed
bool(* CS101_ReadHandler)(void *parameter, IMasterConnection connection, CS101_ASDU asdu, int ioa)
Handler for read command (C_RD_NA_1 - 102)
Definition: iec60870_slave.h:218
bool(* CS101_InterrogationHandler)(void *parameter, IMasterConnection connection, CS101_ASDU asdu, uint8_t qoi)
Handler for interrogation command (C_IC_NA_1 - 100).
Definition: iec60870_slave.h:208
bool(* CS101_CounterInterrogationHandler)(void *parameter, IMasterConnection connection, CS101_ASDU asdu, QualifierOfCIC qcc)
Handler for counter interrogation command (C_CI_NA_1 - 101).
Definition: iec60870_slave.h:213
bool(* CS101_ASDUHandler)(void *parameter, IMasterConnection connection, CS101_ASDU asdu)
Handler for ASDUs that are not handled by other handlers (default handler)
Definition: iec60870_slave.h:248
bool(* CS101_ClockSynchronizationHandler)(void *parameter, IMasterConnection connection, CS101_ASDU asdu, CP56Time2a newTime)
Handler for clock synchronization command (C_CS_NA_1 - 103)
Definition: iec60870_slave.h:233
Common slave side definitions for IEC 60870-5-101/104 These types are used by CS101/CS104 slaves.
Definition: iec60870_common.h:112
Definition: iec60870_slave.h:179
Definition: iec60870_common.h:273
Definition: iec60870_slave.h:65