lib60870-C  2.3.2
C source code library for the IEC 60870-5-101/104 protocols
iec60870_slave.h
Go to the documentation of this file.
1 /*
2  * Copyright 2016-2018 MZ Automation GmbH
3  *
4  * This file is part of lib60870-C
5  *
6  * lib60870-C is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * lib60870-C is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with lib60870-C. If not, see <http://www.gnu.org/licenses/>.
18  *
19  * See COPYING file for the complete license text.
20  */
21 
22 #ifndef SRC_IEC60750_SLAVE_H_
23 #define SRC_IEC60750_SLAVE_H_
24 
25 #include <stdint.h>
26 #include <stdbool.h>
27 #include "iec60870_common.h"
28 #include "tls_config.h"
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
64 
66  bool (*isReady) (IMasterConnection self);
67  bool (*sendASDU) (IMasterConnection self, CS101_ASDU asdu);
68  bool (*sendACT_CON) (IMasterConnection self, CS101_ASDU asdu, bool negative);
69  bool (*sendACT_TERM) (IMasterConnection self, CS101_ASDU asdu);
70  void (*close) (IMasterConnection self);
71  int (*getPeerAddress) (IMasterConnection self, char* addrBuf, int addrBufSize);
72  CS101_AppLayerParameters (*getApplicationLayerParameters) (IMasterConnection self);
73  void* object;
74 };
75 
76 /*
77  * \brief Check if the connection is ready to send an ASDU.
78  *
79  * \deprecated Use one of the send functions (e.g. \ref IMasterConnection_sendASDU) and evaluate
80  * the return value.
81  *
82  * NOTE: The functions returns true when the connection is activated, the ASDU can be immediately sent,
83  * or the queue has enough space to store another ASDU.
84  *
85  * \param self the connection object (this is usually received as a parameter of a callback function)
86  *
87  * \returns true if the connection is ready to send an ASDU, false otherwise
88  */
89 bool
90 IMasterConnection_isReady(IMasterConnection self);
91 
102 bool
104 
115 bool
117 
127 bool
129 
138 int
139 IMasterConnection_getPeerAddress(IMasterConnection self, char* addrBuf, int addrBufSize);
140 
146 void
148 
154 
166 typedef enum
167 {
168  CS101_PLUGIN_RESULT_NOT_HANDLED = 0,
169  CS101_PLUGIN_RESULT_HANDLED = 1,
170  CS101_PLUGIN_RESULT_INVALID_ASDU = 2
171 } CS101_SlavePlugin_Result;
172 
177 
179 {
180  CS101_SlavePlugin_Result (*handleAsdu) (void* parameter, IMasterConnection connection, CS101_ASDU asdu);
181  void (*runTask) (void* parameter, IMasterConnection connection);
182 
183  void* parameter;
184 };
185 
203 typedef void (*CS101_ResetCUHandler) (void* parameter);
204 
208 typedef bool (*CS101_InterrogationHandler) (void* parameter, IMasterConnection connection, CS101_ASDU asdu, uint8_t qoi);
209 
213 typedef bool (*CS101_CounterInterrogationHandler) (void* parameter, IMasterConnection connection, CS101_ASDU asdu, QualifierOfCIC qcc);
214 
218 typedef bool (*CS101_ReadHandler) (void* parameter, IMasterConnection connection, CS101_ASDU asdu, int ioa);
219 
233 typedef bool (*CS101_ClockSynchronizationHandler) (void* parameter, IMasterConnection connection, CS101_ASDU asdu, CP56Time2a newTime);
234 
238 typedef bool (*CS101_ResetProcessHandler ) (void* parameter, IMasterConnection connection, CS101_ASDU asdu, uint8_t qrp);
239 
243 typedef bool (*CS101_DelayAcquisitionHandler) (void* parameter, IMasterConnection connection, CS101_ASDU asdu, CP16Time2a delayTime);
244 
248 typedef bool (*CS101_ASDUHandler) (void* parameter, IMasterConnection connection, CS101_ASDU asdu);
249 
263 #ifdef __cplusplus
264 }
265 #endif
266 
267 
268 #endif /* SRC_IEC60750_SLAVE_H_ */
struct sCS101_SlavePlugin * CS101_SlavePlugin
Plugin interface for CS101 or CS104 slaves.
Definition: iec60870_slave.h:176
uint8_t QualifierOfCIC
QCC (Qualifier of counter interrogation command) according to IEC 60870-5-101:2003 7....
Definition: cs101_information_objects.h:185
struct sCS101_ASDU * CS101_ASDU
Application Service Data Unit (ASDU) for the CS101/CS104 application layer.
Definition: iec60870_common.h:216
struct sCS101_AppLayerParameters * CS101_AppLayerParameters
Parameters for the CS101/CS104 application layer.
Definition: iec60870_common.h:110
struct sIMasterConnection * IMasterConnection
Interface to send messages to the master (used by slave)
Definition: iec60870_slave.h:63
bool IMasterConnection_sendACT_TERM(IMasterConnection self, CS101_ASDU asdu)
Send an ACT_TERM ASDU to the client/master.
int IMasterConnection_getPeerAddress(IMasterConnection self, char *addrBuf, int addrBufSize)
Get the peer address of the master (only for CS 104)
bool IMasterConnection_sendACT_CON(IMasterConnection self, CS101_ASDU asdu, bool negative)
Send an ACT_CON ASDU to the client/master.
bool IMasterConnection_sendASDU(IMasterConnection self, CS101_ASDU asdu)
Send an ASDU to the client/master.
CS101_AppLayerParameters IMasterConnection_getApplicationLayerParameters(IMasterConnection self)
Get the application layer parameters used by this connection.
void IMasterConnection_close(IMasterConnection self)
Close the master connection (only for CS 104)
bool(* CS101_ResetProcessHandler)(void *parameter, IMasterConnection connection, CS101_ASDU asdu, uint8_t qrp)
Handler for reset process command (C_RP_NA_1 - 105)
Definition: iec60870_slave.h:238
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_DelayAcquisitionHandler)(void *parameter, IMasterConnection connection, CS101_ASDU asdu, CP16Time2a delayTime)
Handler for delay acquisition command (C_CD_NA:1 - 106)
Definition: iec60870_slave.h:243
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
void(* CS101_ResetCUHandler)(void *parameter)
Handler will be called when a link layer reset CU (communication unit) message is received.
Definition: iec60870_slave.h:203
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 definitions for IEC 60870-5-101/104 These types are used by CS101/CS104 master and slaves.
Definition: iec60870_common.h:231
Definition: iec60870_common.h:255
Definition: iec60870_common.h:112
Definition: iec60870_slave.h:179
Definition: iec60870_slave.h:65