22 #ifndef SRC_INC_IEC60870_COMMON_H_
23 #define SRC_INC_IEC60870_COMMON_H_
45 #define IEC_60870_5_104_DEFAULT_PORT 2404
46 #define IEC_60870_5_104_DEFAULT_TLS_PORT 19998
48 #define LIB60870_VERSION_MAJOR 2
49 #define LIB60870_VERSION_MINOR 3
50 #define LIB60870_VERSION_PATCH 1
65 IEC60870_LINK_LAYER_BALANCED = 0,
66 IEC60870_LINK_LAYER_UNBALANCED = 1
116 int originatorAddress;
211 typedef struct sInformationObject* InformationObject;
221 int asduHeaderLength;
224 uint8_t encodedData[256];
232 uint8_t encodedValue[2];
238 uint8_t encodedValue[3];
247 uint8_t encodedValue[4];
256 uint8_t encodedValue[7];
265 uint8_t encodedValue[5];
285 CS101_COT_PERIODIC = 1,
286 CS101_COT_BACKGROUND_SCAN = 2,
287 CS101_COT_SPONTANEOUS = 3,
288 CS101_COT_INITIALIZED = 4,
289 CS101_COT_REQUEST = 5,
290 CS101_COT_ACTIVATION = 6,
291 CS101_COT_ACTIVATION_CON = 7,
292 CS101_COT_DEACTIVATION = 8,
293 CS101_COT_DEACTIVATION_CON = 9,
294 CS101_COT_ACTIVATION_TERMINATION = 10,
295 CS101_COT_RETURN_INFO_REMOTE = 11,
296 CS101_COT_RETURN_INFO_LOCAL = 12,
297 CS101_COT_FILE_TRANSFER = 13,
298 CS101_COT_AUTHENTICATION = 14,
299 CS101_COT_MAINTENANCE_OF_AUTH_SESSION_KEY = 15,
300 CS101_COT_MAINTENANCE_OF_USER_ROLE_AND_UPDATE_KEY = 16,
301 CS101_COT_INTERROGATED_BY_STATION = 20,
302 CS101_COT_INTERROGATED_BY_GROUP_1 = 21,
303 CS101_COT_INTERROGATED_BY_GROUP_2 = 22,
304 CS101_COT_INTERROGATED_BY_GROUP_3 = 23,
305 CS101_COT_INTERROGATED_BY_GROUP_4 = 24,
306 CS101_COT_INTERROGATED_BY_GROUP_5 = 25,
307 CS101_COT_INTERROGATED_BY_GROUP_6 = 26,
308 CS101_COT_INTERROGATED_BY_GROUP_7 = 27,
309 CS101_COT_INTERROGATED_BY_GROUP_8 = 28,
310 CS101_COT_INTERROGATED_BY_GROUP_9 = 29,
311 CS101_COT_INTERROGATED_BY_GROUP_10 = 30,
312 CS101_COT_INTERROGATED_BY_GROUP_11 = 31,
313 CS101_COT_INTERROGATED_BY_GROUP_12 = 32,
314 CS101_COT_INTERROGATED_BY_GROUP_13 = 33,
315 CS101_COT_INTERROGATED_BY_GROUP_14 = 34,
316 CS101_COT_INTERROGATED_BY_GROUP_15 = 35,
317 CS101_COT_INTERROGATED_BY_GROUP_16 = 36,
318 CS101_COT_REQUESTED_BY_GENERAL_COUNTER = 37,
319 CS101_COT_REQUESTED_BY_GROUP_1_COUNTER = 38,
320 CS101_COT_REQUESTED_BY_GROUP_2_COUNTER = 39,
321 CS101_COT_REQUESTED_BY_GROUP_3_COUNTER = 40,
322 CS101_COT_REQUESTED_BY_GROUP_4_COUNTER = 41,
323 CS101_COT_UNKNOWN_TYPE_ID = 44,
324 CS101_COT_UNKNOWN_COT = 45,
325 CS101_COT_UNKNOWN_CA = 46,
326 CS101_COT_UNKNOWN_IOA = 47
327 } CS101_CauseOfTransmission;
330 CS101_CauseOfTransmission_toString(CS101_CauseOfTransmission
self);
333 Lib60870_enableDebugOutput(
bool value);
336 Lib60870_getLibraryVersionInfo(
void);
371 CS101_CauseOfTransmission
493 bool isTest,
bool isNegative);
513 bool isTest,
bool isNegative);
671 CP32Time2a_setFromMsTimestamp(
CP32Time2a self, uint64_t timestamp);
674 CP32Time2a_getMillisecond(
const CP32Time2a self);
677 CP32Time2a_setMillisecond(
CP32Time2a self,
int value);
683 CP32Time2a_setSecond(
CP32Time2a self,
int value);
690 CP32Time2a_setMinute(
CP32Time2a self,
int value);
696 CP32Time2a_setInvalid(
CP32Time2a self,
bool value);
699 CP32Time2a_isSubstituted(
const CP32Time2a self);
702 CP32Time2a_setSubstituted(
CP32Time2a self,
bool value);
708 CP32Time2a_setHour(
CP32Time2a self,
int value);
711 CP32Time2a_isSummerTime(
const CP32Time2a self);
714 CP32Time2a_setSummerTime(
CP32Time2a self,
bool value);
744 CP56Time2a_setSecond(
CP56Time2a self,
int value);
750 CP56Time2a_setMinute(
CP56Time2a self,
int value);
756 CP56Time2a_setHour(
CP56Time2a self,
int value);
759 CP56Time2a_getDayOfWeek(
const CP56Time2a self);
762 CP56Time2a_setDayOfWeek(
CP56Time2a self,
int value);
765 CP56Time2a_getDayOfMonth(
const CP56Time2a self);
768 CP56Time2a_setDayOfMonth(
CP56Time2a self,
int value);
803 CP56Time2a_isSummerTime(
const CP56Time2a self);
806 CP56Time2a_setSummerTime(
CP56Time2a self,
bool value);
812 CP56Time2a_setInvalid(
CP56Time2a self,
bool value);
815 CP56Time2a_isSubstituted(
const CP56Time2a self);
818 CP56Time2a_setSubstituted(
CP56Time2a self,
bool value);
822 bool hasCarry,
bool isAdjusted,
bool isInvalid);
861 typedef struct sFrame* Frame;
864 Frame_destroy(Frame
self);
867 Frame_resetFrame(Frame
self);
870 Frame_setNextByte(Frame
self, uint8_t
byte);
873 Frame_appendBytes(Frame
self, uint8_t* bytes,
int numberOfBytes);
876 Frame_getMsgSize(Frame
self);
879 Frame_getBuffer(Frame
self);
882 Frame_getSpaceLeft(Frame
self);
bool CS101_ASDU_isSequence(CS101_ASDU self)
Check if the ASDU contains a sequence of consecutive information objects.
void CP56Time2a_setFromMsTimestamp(CP56Time2a self, uint64_t timestamp)
Set the time value of a 7 byte time from a UTC ms timestamp.
CS101_ASDU CS101_ASDU_create(CS101_AppLayerParameters parameters, bool isSequence, CS101_CauseOfTransmission cot, int oa, int ca, bool isTest, bool isNegative)
Create a new ASDU. The type ID will be derived from the first InformationObject that will be added.
bool CS101_ASDU_addPayload(CS101_ASDU self, uint8_t *buffer, int size)
Append the provided data to the ASDU payload.
void CP56Time2a_setMonth(CP56Time2a self, int value)
Set the month field of the time.
void CP24Time2a_setSubstituted(CP24Time2a self, bool value)
Set the substituted flag of the time value.
void CS101_ASDU_removeAllElements(CS101_ASDU self)
remove all information elements from the ASDU object
int CP56Time2a_getMillisecond(const CP56Time2a self)
Get the ms part of a time value.
void CP56Time2a_setYear(CP56Time2a self, int value)
Set the year.
void CP24Time2a_setMinute(CP24Time2a self, int value)
Set the minute part of the time value.
void CP24Time2a_setMillisecond(CP24Time2a self, int value)
Set the millisecond part of the time value.
int CP56Time2a_getMonth(const CP56Time2a self)
Get the month field of the time.
void CS101_ASDU_setTest(CS101_ASDU self, bool value)
Set the test flag of the ASDU.
IEC60870_5_TypeID CS101_ASDU_getTypeID(CS101_ASDU self)
Get the type ID of the ASDU.
void CS101_ASDU_setTypeID(CS101_ASDU self, IEC60870_5_TypeID typeId)
Set the type ID of the ASDU.
bool CS101_ASDU_isNegative(CS101_ASDU self)
Check if the negative flag of the ASDU is set.
struct sCS101_ASDU * CS101_ASDU
Application Service Data Unit (ASDU) for the CS101/CS104 application layer.
Definition: iec60870_common.h:216
int CP24Time2a_getSecond(const CP24Time2a self)
Get the second part of the time value.
LinkLayerState
State of the link layer.
Definition: iec60870_common.h:70
InformationObject CS101_ASDU_getElement(CS101_ASDU self, int index)
Get the information object with the given index.
void CS101_ASDU_setSequence(CS101_ASDU self, bool isSequence)
Set the ASDU to represent a sequence of consecutive information objects.
void CP56Time2a_setMillisecond(CP56Time2a self, int value)
Set the ms part of a time value.
void CS101_ASDU_destroy(CS101_ASDU self)
Destroy the ASDU object (release all resources)
CS101_ASDU CS101_ASDU_initializeStatic(CS101_StaticASDU self, CS101_AppLayerParameters parameters, bool isSequence, CS101_CauseOfTransmission cot, int oa, int ca, bool isTest, bool isNegative)
Create a new ASDU and store it in the provided static ASDU structure.
IEC60870_5_TypeID
Message type IDs.
Definition: iec60870_common.h:125
InformationObject CS101_ASDU_getElementEx(CS101_ASDU self, InformationObject io, int index)
Get the information object with the given index and store it in the provided information object insta...
void(* IEC60870_RawMessageHandler)(void *parameter, uint8_t *msg, int msgSize, bool sent)
Callback handler for sent and received messages.
Definition: iec60870_common.h:105
int CS101_ASDU_getNumberOfElements(CS101_ASDU self)
Get the number of information objects (elements) in the ASDU.
void CP24Time2a_setInvalid(CP24Time2a self, bool value)
Set the invalid flag of the time value.
uint64_t CP56Time2a_toMsTimestamp(const CP56Time2a self)
Convert a 7 byte time to a ms timestamp.
CP56Time2a CP56Time2a_createFromMsTimestamp(CP56Time2a self, uint64_t timestamp)
Create a 7 byte time from a UTC ms timestamp.
void(* IEC60870_LinkLayerStateChangedHandler)(void *parameter, int address, LinkLayerState newState)
Callback handler for link layer state changes.
Definition: iec60870_common.h:91
struct sCS101_AppLayerParameters * CS101_AppLayerParameters
Parameters for the CS101/CS104 application layer.
Definition: iec60870_common.h:110
void CS101_ASDU_setNumberOfElements(CS101_ASDU self, int numberOfElements)
Set the number of information objects (elements) in the ASDU.
int CS101_ASDU_getCA(CS101_ASDU self)
Get the common address (CA) of the ASDU.
bool CS101_ASDU_isTest(CS101_ASDU self)
Check if the test flag of the ASDU is set.
void CS101_ASDU_setNegative(CS101_ASDU self, bool value)
Set the negative flag of the ASDU.
uint8_t * CS101_ASDU_getPayload(CS101_ASDU self)
void CP16Time2a_setEplapsedTimeInMs(CP16Time2a self, int value)
set the elapsed time in ms
struct sCP56Time2a * CP56Time2a
7 byte binary time
Definition: iec60870_common.h:253
void CP24Time2a_setSecond(CP24Time2a self, int value)
Set the second part of the time value.
CS101_ASDU CS101_ASDU_clone(CS101_ASDU self, CS101_StaticASDU clone)
Create a new ASDU that is an exact copy of the ASDU.
void CS101_ASDU_setCOT(CS101_ASDU self, CS101_CauseOfTransmission value)
Set the cause of transmission (COT) of the ASDU.
IEC60870_LinkLayerMode
link layer mode for serial link layers
Definition: iec60870_common.h:64
struct sCS104_APCIParameters * CS104_APCIParameters
Parameters for CS104 connections - APCI (application protocol control information)
Definition: iec60870_common.h:271
int CS101_ASDU_getPayloadSize(CS101_ASDU self)
bool CP24Time2a_isInvalid(const CP24Time2a self)
Check if the invalid flag of the time value is set.
int CP24Time2a_getMinute(const CP24Time2a self)
Get the minute part of the time value.
int CP24Time2a_getMillisecond(const CP24Time2a self)
Get the millisecond part of the time value.
bool CS101_ASDU_addInformationObject(CS101_ASDU self, InformationObject io)
add an information object to the ASDU
struct sBinaryCounterReading * BinaryCounterReading
Base type for counter readings.
Definition: iec60870_common.h:262
bool CP24Time2a_isSubstituted(const CP24Time2a self)
Check if the substituted flag of the time value is set.
int CP56Time2a_getYear(const CP56Time2a self)
Get the year (range 0..99)
int CS101_ASDU_getOA(CS101_ASDU self)
get the OA (originator address) of the ASDU.
CS101_CauseOfTransmission CS101_ASDU_getCOT(CS101_ASDU self)
Get the cause of transmission (COT) of the ASDU.
void CS101_ASDU_setCA(CS101_ASDU self, int ca)
Set the common address (CA) of the ASDU.
int CP16Time2a_getEplapsedTimeInMs(const CP16Time2a self)
Get the elapsed time in ms.
@ LL_STATE_BUSY
Definition: iec60870_common.h:78
@ LL_STATE_AVAILABLE
Definition: iec60870_common.h:81
@ LL_STATE_IDLE
Definition: iec60870_common.h:72
@ LL_STATE_ERROR
Definition: iec60870_common.h:75
lib60870 version information
Definition: iec60870_common.h:55
Definition: iec60870_common.h:264
Definition: iec60870_common.h:231
Definition: iec60870_common.h:237
4 byte binary time
Definition: iec60870_common.h:246
Definition: iec60870_common.h:255
Definition: iec60870_common.h:112
Definition: iec60870_common.h:218
Definition: iec60870_common.h:273