lib60870-C  2.3.2
C source code library for the IEC 60870-5-101/104 protocols
cs104_connection.h
Go to the documentation of this file.
1 /*
2  * Copyright 2016-2022 Michael Zillgith
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_INC_CS104_CONNECTION_H_
23 #define SRC_INC_CS104_CONNECTION_H_
24 
25 #include <stdbool.h>
26 #include <stdint.h>
27 
28 #include "tls_config.h"
29 #include "iec60870_master.h"
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
52 typedef struct sCS104_Connection* CS104_Connection;
53 
62 CS104_Connection
63 CS104_Connection_create(const char* hostname, int tcpPort);
64 
74 CS104_Connection
75 CS104_Connection_createSecure(const char* hostname, int tcpPort, TLSConfiguration tlsConfig);
76 
77 
87 void
88 CS104_Connection_setLocalAddress(CS104_Connection self, const char* localIpAddress, int localPort);
89 
100 void
101 CS104_Connection_setAPCIParameters(CS104_Connection self, const CS104_APCIParameters parameters);
102 
107 CS104_Connection_getAPCIParameters(CS104_Connection self);
108 
119 void
120 CS104_Connection_setAppLayerParameters(CS104_Connection self, const CS101_AppLayerParameters parameters);
121 
133 
142 void
143 CS104_Connection_setConnectTimeout(CS104_Connection self, int millies);
144 
152 void
153 CS104_Connection_connectAsync(CS104_Connection self);
154 
164 bool
165 CS104_Connection_connect(CS104_Connection self);
166 
173 void
174 CS104_Connection_sendStartDT(CS104_Connection self);
175 
179 void
180 CS104_Connection_sendStopDT(CS104_Connection self);
181 
189 bool
191 
201 bool
202 CS104_Connection_sendInterrogationCommand(CS104_Connection self, CS101_CauseOfTransmission cot, int ca, QualifierOfInterrogation qoi);
203 
213 bool
214 CS104_Connection_sendCounterInterrogationCommand(CS104_Connection self, CS101_CauseOfTransmission cot, int ca, uint8_t qcc);
215 
227 bool
228 CS104_Connection_sendReadCommand(CS104_Connection self, int ca, int ioa);
229 
238 bool
239 CS104_Connection_sendClockSyncCommand(CS104_Connection self, int ca, CP56Time2a newTime);
240 
250 bool
251 CS104_Connection_sendTestCommand(CS104_Connection self, int ca);
252 
262 bool
263 CS104_Connection_sendTestCommandWithTimestamp(CS104_Connection self, int ca, uint16_t tsc, CP56Time2a timestamp);
264 
277 bool
278 CS104_Connection_sendProcessCommand(CS104_Connection self, TypeID typeId, CS101_CauseOfTransmission cot,
279  int ca, InformationObject command);
280 
290 bool
291 CS104_Connection_sendProcessCommandEx(CS104_Connection self, CS101_CauseOfTransmission cot, int ca, InformationObject sc);
292 
293 
301 bool
302 CS104_Connection_sendASDU(CS104_Connection self, CS101_ASDU asdu);
303 
310 void
311 CS104_Connection_setASDUReceivedHandler(CS104_Connection self, CS101_ASDUReceivedHandler handler, void* parameter);
312 
313 typedef enum {
314  CS104_CONNECTION_OPENED = 0,
315  CS104_CONNECTION_CLOSED = 1,
316  CS104_CONNECTION_STARTDT_CON_RECEIVED = 2,
317  CS104_CONNECTION_STOPDT_CON_RECEIVED = 3,
318  CS104_CONNECTION_FAILED = 4
319 } CS104_ConnectionEvent;
320 
331 typedef void (*CS104_ConnectionHandler) (void* parameter, CS104_Connection connection, CS104_ConnectionEvent event);
332 
339 void
340 CS104_Connection_setConnectionHandler(CS104_Connection self, CS104_ConnectionHandler handler, void* parameter);
341 
342 
349 void
350 CS104_Connection_setRawMessageHandler(CS104_Connection self, IEC60870_RawMessageHandler handler, void* parameter);
351 
355 void
356 CS104_Connection_close(CS104_Connection self);
357 
361 void
362 CS104_Connection_destroy(CS104_Connection self);
363 
368 #ifdef __cplusplus
369 }
370 #endif
371 
372 #endif /* SRC_INC_CS104_CONNECTION_H_ */
struct sCS101_ASDU * CS101_ASDU
Application Service Data Unit (ASDU) for the CS101/CS104 application layer.
Definition: iec60870_common.h:216
IEC60870_5_TypeID
Message type IDs.
Definition: iec60870_common.h:125
void(* IEC60870_RawMessageHandler)(void *parameter, uint8_t *msg, int msgSize, bool sent)
Callback handler for sent and received messages.
Definition: iec60870_common.h:105
uint8_t QualifierOfInterrogation
Qualifier of interrogation (QUI) according to IEC 60870-5-101:2003 7.2.6.22.
Definition: cs101_information_objects.h:146
CS101_AppLayerParameters CS104_Connection_getAppLayerParameters(CS104_Connection self)
Return the currently used application layer parameter.
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)
void CS104_Connection_setConnectionHandler(CS104_Connection self, CS104_ConnectionHandler handler, void *parameter)
Set the connection event handler.
bool CS104_Connection_sendASDU(CS104_Connection self, CS101_ASDU asdu)
Send a user specified ASDU.
void CS104_Connection_setConnectTimeout(CS104_Connection self, int millies)
Sets the timeout for connecting to the server (in ms)
void CS104_Connection_sendStartDT(CS104_Connection self)
start data transmission on this connection
bool CS104_Connection_sendInterrogationCommand(CS104_Connection self, CS101_CauseOfTransmission cot, int ca, QualifierOfInterrogation qoi)
send an interrogation command
bool CS104_Connection_sendCounterInterrogationCommand(CS104_Connection self, CS101_CauseOfTransmission cot, int ca, uint8_t qcc)
send a counter interrogation command
bool CS104_Connection_sendTestCommand(CS104_Connection self, int ca)
Send a test command (C_TS_NA_1 typeID: 104)
void CS104_Connection_close(CS104_Connection self)
Close the connection.
bool CS104_Connection_sendProcessCommandEx(CS104_Connection self, CS101_CauseOfTransmission cot, int ca, InformationObject sc)
Send a process command to the controlled (or other) station.
bool CS104_Connection_isTransmitBufferFull(CS104_Connection self)
Check if the transmit (send) buffer is full. If true the next send command will fail.
void CS104_Connection_setASDUReceivedHandler(CS104_Connection self, CS101_ASDUReceivedHandler handler, void *parameter)
Register a callback handler for received ASDUs.
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.
CS104_APCIParameters CS104_Connection_getAPCIParameters(CS104_Connection self)
Get the currently used CS104 specific APCI parameters.
CS104_Connection CS104_Connection_create(const char *hostname, int tcpPort)
Create a new connection object.
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.
bool CS104_Connection_sendClockSyncCommand(CS104_Connection self, int ca, CP56Time2a newTime)
Sends a clock synchronization command (C_CS_NA_1 typeID: 103)
bool CS104_Connection_sendReadCommand(CS104_Connection self, int ca, int ioa)
Sends a read command (C_RD_NA_1 typeID: 102)
CS104_Connection CS104_Connection_createSecure(const char *hostname, int tcpPort, TLSConfiguration tlsConfig)
Create a new secure connection object (uses TLS)
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)
void(* CS104_ConnectionHandler)(void *parameter, CS104_Connection connection, CS104_ConnectionEvent event)
Handler that is called when the connection is established or closed.
Definition: cs104_connection.h:331
void CS104_Connection_setAPCIParameters(CS104_Connection self, const CS104_APCIParameters parameters)
Set the CS104 specific APCI parameters.
void CS104_Connection_setAppLayerParameters(CS104_Connection self, const CS101_AppLayerParameters parameters)
Set the CS101 application layer parameters.
void CS104_Connection_destroy(CS104_Connection self)
Close the connection and free all related resources.
void CS104_Connection_connectAsync(CS104_Connection self)
non-blocking connect.
void CS104_Connection_sendStopDT(CS104_Connection self)
stop data transmission on this connection
bool CS104_Connection_connect(CS104_Connection self)
blocking connect
Common master side definitions for IEC 60870-5-101/104 These types are used by CS101/CS104 master.
bool(* CS101_ASDUReceivedHandler)(void *parameter, int address, CS101_ASDU asdu)
Callback handler for received ASDUs.
Definition: iec60870_master.h:53
Definition: iec60870_common.h:255
Definition: iec60870_common.h:112
Definition: iec60870_common.h:273