libiec61850  1.2.0
iec61850_server.h
Go to the documentation of this file.
1 /*
2  * iec61850_server.h
3  *
4  * IEC 61850 server API for libiec61850.
5  *
6  * Copyright 2013, 2014 Michael Zillgith
7  *
8  * This file is part of libIEC61850.
9  *
10  * libIEC61850 is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * libIEC61850 is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with libIEC61850. If not, see <http://www.gnu.org/licenses/>.
22  *
23  * See COPYING file for the complete license text.
24  *
25  */
26 
27 #ifndef IED_SERVER_API_H_
28 #define IED_SERVER_API_H_
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
38 #include "mms_server.h"
39 #include "iec61850_dynamic_model.h"
40 #include "iec61850_model.h"
41 #include "hal_filesystem.h"
43 
47 typedef struct sIedServer* IedServer;
48 
52 typedef struct sClientConnection* ClientConnection;
53 
68 IedServer
69 IedServer_create(IedModel* dataModel);
70 
79 IedServer
80 IedServer_createWithTlsSupport(IedModel* dataModel, TLSConfiguration tlsConfiguration);
81 
87 void
88 IedServer_destroy(IedServer self);
89 
96 void
97 IedServer_setLocalIpAddress(IedServer self, const char* localIpAddress);
98 
109 void
110 IedServer_setFilestoreBasepath(IedServer self, const char* basepath);
111 
118 void
119 IedServer_start(IedServer self, int tcpPort);
120 
126 void
127 IedServer_stop(IedServer self);
128 
139 void
140 IedServer_startThreadless(IedServer self, int tcpPort);
141 
155 int
156 IedServer_waitReady(IedServer self, unsigned int timeoutMs);
157 
167 void
168 IedServer_processIncomingData(IedServer self);
169 
178 void
179 IedServer_performPeriodicTasks(IedServer self);
180 
186 void
187 IedServer_stopThreadless(IedServer self);
188 
196 IedModel*
197 IedServer_getDataModel(IedServer self);
198 
206 bool
207 IedServer_isRunning(IedServer self);
208 
219 MmsServer
220 IedServer_getMmsServer(IedServer self);
221 
232 void
233 IedServer_enableGoosePublishing(IedServer self);
234 
243 void
244 IedServer_disableGoosePublishing(IedServer self);
245 
256 void
257 IedServer_setGooseInterfaceId(IedServer self, const char* interfaceId);
258 
279 void
280 IedServer_setAuthenticator(IedServer self, AcseAuthenticator authenticator, void* authenticatorParameter);
281 
282 
283 
293 const char*
294 ClientConnection_getPeerAddress(ClientConnection self);
295 
306 void*
307 ClientConnection_getSecurityToken(ClientConnection self);
308 
318 typedef void (*IedConnectionIndicationHandler) (IedServer self, ClientConnection connection, bool connected, void* parameter);
319 
327 void
328 IedServer_setConnectionIndicationHandler(IedServer self, IedConnectionIndicationHandler handler, void* parameter);
329 
330 
351 void
352 IedServer_lockDataModel(IedServer self);
353 
362 void
363 IedServer_unlockDataModel(IedServer self);
364 
377 MmsValue*
378 IedServer_getAttributeValue(IedServer self, DataAttribute* dataAttribute);
379 
391 bool
392 IedServer_getBooleanAttributeValue(IedServer self, const DataAttribute* dataAttribute);
393 
405 int32_t
406 IedServer_getInt32AttributeValue(IedServer self, const DataAttribute* dataAttribute);
407 
419 int64_t
420 IedServer_getInt64AttributeValue(IedServer self, const DataAttribute* dataAttribute);
421 
433 uint32_t
434 IedServer_getUInt32AttributeValue(IedServer self, const DataAttribute* dataAttribute);
435 
447 float
448 IedServer_getFloatAttributeValue(IedServer self, const DataAttribute* dataAttribute);
449 
461 uint64_t
462 IedServer_getUTCTimeAttributeValue(IedServer self, const DataAttribute* dataAttribute);
463 
479 uint32_t
480 IedServer_getBitStringAttributeValue(IedServer self, const DataAttribute* dataAttribute);
481 
493 const char*
494 IedServer_getStringAttributeValue(IedServer self, const DataAttribute* dataAttribute);
495 
496 
512 MmsValue*
513 IedServer_getFunctionalConstrainedData(IedServer self, DataObject* dataObject, FunctionalConstraint fc);
514 
531 void
532 IedServer_updateAttributeValue(IedServer self, DataAttribute* dataAttribute, MmsValue* value);
533 
546 void
547 IedServer_updateFloatAttributeValue(IedServer self, DataAttribute* dataAttribute, float value);
548 
561 void
562 IedServer_updateInt32AttributeValue(IedServer self, DataAttribute* dataAttribute, int32_t value);
563 
576 void
577 IedServer_udpateDbposValue(IedServer self, DataAttribute* dataAttribute, Dbpos value);
578 
591 void
592 IedServer_updateInt64AttributeValue(IedServer self, DataAttribute* dataAttribute, int64_t value);
593 
606 void
607 IedServer_updateUnsignedAttributeValue(IedServer self, DataAttribute* dataAttribute, uint32_t value);
608 
621 void
622 IedServer_updateBitStringAttributeValue(IedServer self, DataAttribute* dataAttribute, uint32_t value);
623 
636 void
637 IedServer_updateBooleanAttributeValue(IedServer self, DataAttribute* dataAttribute, bool value);
638 
651 void
652 IedServer_updateVisibleStringAttributeValue(IedServer self, DataAttribute* dataAttribute, char *value);
653 
666 void
667 IedServer_updateUTCTimeAttributeValue(IedServer self, DataAttribute* dataAttribute, uint64_t value);
668 
681 void
682 IedServer_updateTimestampAttributeValue(IedServer self, DataAttribute* dataAttribute, Timestamp* timestamp);
683 
698 void
699 IedServer_updateQuality(IedServer self, DataAttribute* dataAttribute, Quality quality);
700 
704 void
705 IedServer_setLogStorage(IedServer self, const char* logRef, LogStorage logStorage);
706 
723 void
724 IedServer_changeActiveSettingGroup(IedServer self, SettingGroupControlBlock* sgcb, uint8_t newActiveSg);
725 
734 uint8_t
735 IedServer_getActiveSettingGroup(IedServer self, SettingGroupControlBlock* sgcb);
736 
752 typedef bool (*ActiveSettingGroupChangedHandler) (void* parameter, SettingGroupControlBlock* sgcb,
753  uint8_t newActSg, ClientConnection connection);
754 
763 void
764 IedServer_setActiveSettingGroupChangedHandler(IedServer self, SettingGroupControlBlock* sgcb,
765  ActiveSettingGroupChangedHandler handler, void* parameter);
766 
784 typedef bool (*EditSettingGroupChangedHandler) (void* parameter, SettingGroupControlBlock* sgcb,
785  uint8_t newEditSg, ClientConnection connection);
786 
795 void
796 IedServer_setEditSettingGroupChangedHandler(IedServer self, SettingGroupControlBlock* sgcb,
797  EditSettingGroupChangedHandler handler, void* parameter);
798 
808 typedef void (*EditSettingGroupConfirmationHandler) (void* parameter, SettingGroupControlBlock* sgcb,
809  uint8_t editSg);
810 
819 void
820 IedServer_setEditSettingGroupConfirmationHandler(IedServer self, SettingGroupControlBlock* sgcb,
821  EditSettingGroupConfirmationHandler handler, void* parameter);
822 
834 typedef enum {
842 
846 typedef enum {
851 
870 typedef CheckHandlerResult (*ControlPerformCheckHandler) (void* parameter, MmsValue* ctlVal, bool test, bool interlockCheck,
871  ClientConnection connection);
872 
892 typedef ControlHandlerResult (*ControlWaitForExecutionHandler) (void* parameter, MmsValue* ctlVal, bool test, bool synchroCheck);
893 
911 typedef ControlHandlerResult (*ControlHandler) (void* parameter, MmsValue* ctlVal, bool test);
912 
926 void
927 IedServer_setControlHandler(IedServer self, DataObject* node, ControlHandler handler, void* parameter);
928 
943 void
944 IedServer_setPerformCheckHandler(IedServer self, DataObject* node, ControlPerformCheckHandler handler, void* parameter);
945 
961 void
962 IedServer_setWaitForExecutionHandler(IedServer self, DataObject* node, ControlWaitForExecutionHandler handler, void* parameter);
963 
973 #define IEC61850_SVCB_EVENT_ENABLE 1
974 
976 #define IEC61850_SVCB_EVENT_DISABLE 0
977 
985 typedef void (*SVCBEventHandler) (SVControlBlock* svcb, int event, void* parameter);
986 
995 void
996 IedServer_setSVCBHandler(IedServer self, SVControlBlock* svcb, SVCBEventHandler handler, void* parameter);
997 
1006 /***************************************************************************
1007  * Access control
1008  **************************************************************************/
1009 
1028 typedef MmsDataAccessError
1029 (*WriteAccessHandler) (DataAttribute* dataAttribute, MmsValue* value, ClientConnection connection, void* parameter);
1030 
1046 void
1047 IedServer_handleWriteAccess(IedServer self, DataAttribute* dataAttribute,
1048  WriteAccessHandler handler, void* parameter);
1049 
1050 typedef enum {
1053 } AccessPolicy;
1054 
1063 void
1064 IedServer_setWriteAccessPolicy(IedServer self, FunctionalConstraint fc, AccessPolicy policy);
1065 
1070 #ifdef __cplusplus
1071 }
1072 #endif
1073 
1074 #endif /* IED_SERVER_API_H_ */
void IedServer_destroy(IedServer self)
Destroy an IedServer instance and release all resources (memory, TCP sockets)
Definition: iec61850_server.h:849
Definition: iec61850_server.h:838
void IedServer_setGooseInterfaceId(IedServer self, const char *interfaceId)
Set the Ethernet interface to be used by GOOSE publishing.
void IedServer_start(IedServer self, int tcpPort)
Start handling client connections.
void IedServer_updateVisibleStringAttributeValue(IedServer self, DataAttribute *dataAttribute, char *value)
Update the value of an IEC 61850 visible string data attribute.
uint16_t Quality
Definition: iec61850_common.h:266
Definition: iec61850_server.h:835
void IedServer_updateBitStringAttributeValue(IedServer self, DataAttribute *dataAttribute, uint32_t value)
Update the value of an IEC 61850 bit string data attribute.
IedModel * IedServer_getDataModel(IedServer self)
Return the data model of the server.
void IedServer_unlockDataModel(IedServer self)
Unlock the MMS server data model and process pending client requests.
bool(* EditSettingGroupChangedHandler)(void *parameter, SettingGroupControlBlock *sgcb, uint8_t newEditSg, ClientConnection connection)
Callback handler that is invoked when the edit setting group is about to be changed by an external cl...
Definition: iec61850_server.h:784
CheckHandlerResult
result code for ControlPerformCheckHandler
Definition: iec61850_server.h:834
void IedServer_setConnectionIndicationHandler(IedServer self, IedConnectionIndicationHandler handler, void *parameter)
set a callback function that will be called on connection events (open or close). ...
void IedServer_updateQuality(IedServer self, DataAttribute *dataAttribute, Quality quality)
Update a quality ("q") IEC 61850 data attribute.
bool(* ActiveSettingGroupChangedHandler)(void *parameter, SettingGroupControlBlock *sgcb, uint8_t newActSg, ClientConnection connection)
Callback handler that is invoked when the active setting group is about to be changed by an external ...
Definition: iec61850_server.h:752
Definition: iec61850_server.h:847
void IedServer_updateUTCTimeAttributeValue(IedServer self, DataAttribute *dataAttribute, uint64_t value)
Update the value of an IEC 61850 UTC time (timestamp) data attribute.
void IedServer_updateInt32AttributeValue(IedServer self, DataAttribute *dataAttribute, int32_t value)
Update the value of an IEC 61850 integer32 data attribute.
Definition: iec61850_server.h:848
void(* IedConnectionIndicationHandler)(IedServer self, ClientConnection connection, bool connected, void *parameter)
User provided callback function that is invoked whenever a new client connects or an existing connect...
Definition: iec61850_server.h:318
bool(* AcseAuthenticator)(void *parameter, AcseAuthenticationParameter authParameter, void **securityToken, IsoApplicationReference *appReference)
Callback function to authenticate a client.
Definition: iso_connection_parameters.h:105
void IedServer_stopThreadless(IedServer self)
Stop handling client connections for non-threaded mode.
struct sMmsServer * MmsServer
Definition: mms_server.h:43
MmsValue * IedServer_getAttributeValue(IedServer self, DataAttribute *dataAttribute)
Get data attribute value.
void IedServer_lockDataModel(IedServer self)
Lock the MMS server data model.
uint8_t IedServer_getActiveSettingGroup(IedServer self, SettingGroupControlBlock *sgcb)
Get the active setting group number.
void IedServer_setActiveSettingGroupChangedHandler(IedServer self, SettingGroupControlBlock *sgcb, ActiveSettingGroupChangedHandler handler, void *parameter)
Set the callback handler for the SetActSG event.
void IedServer_processIncomingData(IedServer self)
handle incoming TCP data in non-threaded mode
MmsDataAccessError(* WriteAccessHandler)(DataAttribute *dataAttribute, MmsValue *value, ClientConnection connection, void *parameter)
callback handler to intercept/control client access to data attributes
Definition: iec61850_server.h:1029
const char * ClientConnection_getPeerAddress(ClientConnection self)
get the peer address of this connection as string
int32_t IedServer_getInt32AttributeValue(IedServer self, const DataAttribute *dataAttribute)
Get data attribute value of an integer data attribute.
Definition: iec61850_common.h:352
float IedServer_getFloatAttributeValue(IedServer self, const DataAttribute *dataAttribute)
Get data attribute value of a floating point data attribute.
void IedServer_setWriteAccessPolicy(IedServer self, FunctionalConstraint fc, AccessPolicy policy)
Change the default write access policy for functional constraint data with a specific FC...
struct sIedServer * IedServer
Definition: iec61850_server.h:47
Definition: iec61850_server.h:837
MmsValue * IedServer_getFunctionalConstrainedData(IedServer self, DataObject *dataObject, FunctionalConstraint fc)
Get the MmsValue object related to a FunctionalConstrainedData object.
void IedServer_updateInt64AttributeValue(IedServer self, DataAttribute *dataAttribute, int64_t value)
Update the value of an IEC 61850 integer64 data attribute (like BCR actVal)
Definition: iec61850_server.h:836
void IedServer_stop(IedServer self)
Stop handling client connections.
void IedServer_setLocalIpAddress(IedServer self, const char *localIpAddress)
Set the local IP address to listen on.
ControlHandlerResult(* ControlWaitForExecutionHandler)(void *parameter, MmsValue *ctlVal, bool test, bool synchroCheck)
Control model callback to perform the dynamic tests (optional).
Definition: iec61850_server.h:892
uint32_t IedServer_getBitStringAttributeValue(IedServer self, const DataAttribute *dataAttribute)
Get data attribute value of a bit string data attribute as integer value.
Definition: iec61850_server.h:839
int IedServer_waitReady(IedServer self, unsigned int timeoutMs)
Wait until a server connection is ready (with timeout)
ControlHandlerResult
result codes for control handler (ControlWaitForExecutionHandler and ControlHandler) ...
Definition: iec61850_server.h:846
MmsServer IedServer_getMmsServer(IedServer self)
Get access to the underlying MmsServer instance.
void IedServer_disableGoosePublishing(IedServer self)
Disable all GOOSE control blocks.
void IedServer_updateUnsignedAttributeValue(IedServer self, DataAttribute *dataAttribute, uint32_t value)
Update the value of an IEC 61850 unsigned integer data attribute.
void IedServer_updateAttributeValue(IedServer self, DataAttribute *dataAttribute, MmsValue *value)
Update the MmsValue object of an IEC 61850 data attribute.
MmsDataAccessError
Definition: mms_value.h:47
void IedServer_setFilestoreBasepath(IedServer self, const char *basepath)
Set the virtual filestore basepath for the MMS file services.
void(* EditSettingGroupConfirmationHandler)(void *parameter, SettingGroupControlBlock *sgcb, uint8_t editSg)
Callback handler that is invoked when the edit setting group has been confirmed by an external client...
Definition: iec61850_server.h:808
void * ClientConnection_getSecurityToken(ClientConnection self)
Get the security token associated with this connection.
struct sClientConnection * ClientConnection
Definition: iec61850_server.h:52
CheckHandlerResult(* ControlPerformCheckHandler)(void *parameter, MmsValue *ctlVal, bool test, bool interlockCheck, ClientConnection connection)
Control model callback to perform the static tests (optional).
Definition: iec61850_server.h:870
AccessPolicy
Definition: iec61850_server.h:1050
Definition: iec61850_server.h:1051
void IedServer_changeActiveSettingGroup(IedServer self, SettingGroupControlBlock *sgcb, uint8_t newActiveSg)
Change active setting group.
uint32_t IedServer_getUInt32AttributeValue(IedServer self, const DataAttribute *dataAttribute)
Get data attribute value of an unsigned integer data attribute.
void IedServer_handleWriteAccess(IedServer self, DataAttribute *dataAttribute, WriteAccessHandler handler, void *parameter)
Install a WriteAccessHandler for a data attribute.
void IedServer_setLogStorage(IedServer self, const char *logRef, LogStorage logStorage)
void IedServer_updateTimestampAttributeValue(IedServer self, DataAttribute *dataAttribute, Timestamp *timestamp)
Update the value of an IEC 61850 UTC time (timestamp) data attribute.
void(* SVCBEventHandler)(SVControlBlock *svcb, int event, void *parameter)
callback handler for SVCB events.
Definition: iec61850_server.h:985
Dbpos
Definition: iec61850_common.h:315
void IedServer_setEditSettingGroupConfirmationHandler(IedServer self, SettingGroupControlBlock *sgcb, EditSettingGroupConfirmationHandler handler, void *parameter)
Set the callback handler for the COnfEditSG event.
void IedServer_setControlHandler(IedServer self, DataObject *node, ControlHandler handler, void *parameter)
Set control handler for controllable data object.
void IedServer_updateBooleanAttributeValue(IedServer self, DataAttribute *dataAttribute, bool value)
Update the value of an IEC 61850 boolean data attribute.
void IedServer_enableGoosePublishing(IedServer self)
Enable all GOOSE control blocks.
Definition: iec61850_server.h:1052
void IedServer_setWaitForExecutionHandler(IedServer self, DataObject *node, ControlWaitForExecutionHandler handler, void *parameter)
Set a handler for a controllable data object to perform dynamic tests.
void IedServer_setAuthenticator(IedServer self, AcseAuthenticator authenticator, void *authenticatorParameter)
set the authenticator for this server
IedServer IedServer_create(IedModel *dataModel)
Create a new IedServer instance.
FunctionalConstraint
Definition: iec61850_common.h:202
void IedServer_udpateDbposValue(IedServer self, DataAttribute *dataAttribute, Dbpos value)
Update the value of an IEC 61850 Dbpos (double point/position) data attribute.
void IedServer_updateFloatAttributeValue(IedServer self, DataAttribute *dataAttribute, float value)
Update the value of an IEC 61850 float data attribute.
void IedServer_startThreadless(IedServer self, int tcpPort)
Start handling client connection for non-threaded mode.
void IedServer_setEditSettingGroupChangedHandler(IedServer self, SettingGroupControlBlock *sgcb, EditSettingGroupChangedHandler handler, void *parameter)
Set the callback handler for the SetEditSG event.
uint64_t IedServer_getUTCTimeAttributeValue(IedServer self, const DataAttribute *dataAttribute)
Get data attribute value of a UTC time data attribute.
bool IedServer_getBooleanAttributeValue(IedServer self, const DataAttribute *dataAttribute)
Get data attribute value of a boolean data attribute.
void IedServer_setPerformCheckHandler(IedServer self, DataObject *node, ControlPerformCheckHandler handler, void *parameter)
Set a handler for a controllable data object to perform operative tests.
void IedServer_setSVCBHandler(IedServer self, SVControlBlock *svcb, SVCBEventHandler handler, void *parameter)
Set a handler for SVCB control block events (enable/disable)
ControlHandlerResult(* ControlHandler)(void *parameter, MmsValue *ctlVal, bool test)
Control model callback to actually perform the control operation.
Definition: iec61850_server.h:911
const char * IedServer_getStringAttributeValue(IedServer self, const DataAttribute *dataAttribute)
Get data attribute value of a string type data attribute.
IedServer IedServer_createWithTlsSupport(IedModel *dataModel, TLSConfiguration tlsConfiguration)
Create a new IedServer with TLS support.
bool IedServer_isRunning(IedServer self)
Check if IedServer instance is listening for client connections.
void IedServer_performPeriodicTasks(IedServer self)
perform periodic background tasks in non-threaded mode
Definition: iec61850_server.h:840
struct sMmsValue MmsValue
Definition: mms_value.h:68
int64_t IedServer_getInt64AttributeValue(IedServer self, const DataAttribute *dataAttribute)
Get data attribute value of an integer data attribute.