diff --git a/config/stack_config.h b/config/stack_config.h index 54907198..1ecd9da9 100644 --- a/config/stack_config.h +++ b/config/stack_config.h @@ -164,6 +164,9 @@ /* allow user to control read access by callback */ #define CONFIG_IEC61850_SUPPORT_USER_READ_ACCESS_CONTROL 1 +/* allow application to set server identity (for MMS identity service) at runtime */ +#define CONFIG_IEC61850_SUPPORT_SERVER_IDENTITY 1 + /* Force memory alignment - required for some platforms (required more memory for buffered reporting) */ #define CONFIG_IEC61850_FORCE_MEMORY_ALIGNMENT 1 diff --git a/config/stack_config.h.cmake b/config/stack_config.h.cmake index 45963309..164e2602 100644 --- a/config/stack_config.h.cmake +++ b/config/stack_config.h.cmake @@ -154,6 +154,9 @@ /* allow user to control read access by callback */ #cmakedefine01 CONFIG_IEC61850_SUPPORT_USER_READ_ACCESS_CONTROL +/* allow application to set server identity (for MMS identity service) at runtime */ +#define CONFIG_IEC61850_SUPPORT_SERVER_IDENTITY 1 + /* Force memory alignment - required for some platforms (required more memory for buffered reporting) */ #define CONFIG_IEC61850_FORCE_MEMORY_ALIGNMENT 1 diff --git a/examples/server_example_basic_io/server_example_basic_io.c b/examples/server_example_basic_io/server_example_basic_io.c index 98bcf49a..3bd87ee2 100644 --- a/examples/server_example_basic_io/server_example_basic_io.c +++ b/examples/server_example_basic_io/server_example_basic_io.c @@ -114,6 +114,9 @@ main(int argc, char** argv) /* configuration object is no longer required */ IedServerConfig_destroy(config); + /* set the identity values for MMS identify service */ + IedServer_setServerIdentity(iedServer, "MZ", "basic io", "1.4.2"); + /* Install handler for operate command */ IedServer_setControlHandler(iedServer, IEDMODEL_GenericIO_GGIO1_SPCSO1, (ControlHandler) controlHandlerForBinaryOutput, diff --git a/src/iec61850/inc/iec61850_server.h b/src/iec61850/inc/iec61850_server.h index f34e67ea..1e067ecb 100644 --- a/src/iec61850/inc/iec61850_server.h +++ b/src/iec61850/inc/iec61850_server.h @@ -347,6 +347,19 @@ IedServer_destroy(IedServer self); LIB61850_API void IedServer_setLocalIpAddress(IedServer self, const char* localIpAddress); +/** + * \brief Set the identify for the MMS identify service + * + * CONFIG_IEC61850_SUPPORT_SERVER_IDENTITY required + * + * \param self the IedServer instance + * \param vendor the IED vendor name + * \param model the IED model name + * \param revision the IED revision/version number + */ +LIB61850_API void +IedServer_setServerIdentity(IedServer self, const char* vendor, const char* model, const char* revision); + /** * \brief Set the virtual filestore basepath for the MMS file services * diff --git a/src/iec61850/inc_private/ied_server_private.h b/src/iec61850/inc_private/ied_server_private.h index 55271c85..e866a503 100644 --- a/src/iec61850/inc_private/ied_server_private.h +++ b/src/iec61850/inc_private/ied_server_private.h @@ -61,6 +61,12 @@ struct sIedServer Thread serverThread; #endif +#if (CONFIG_IEC61850_SUPPORT_SERVER_IDENTITY == 1) + char* vendorName; + char* modelName; + char* revision; +#endif + uint8_t edition; bool running; diff --git a/src/iec61850/server/impl/ied_server.c b/src/iec61850/server/impl/ied_server.c index 2f950ac9..d7f622db 100644 --- a/src/iec61850/server/impl/ied_server.c +++ b/src/iec61850/server/impl/ied_server.c @@ -548,6 +548,18 @@ IedServer_destroy(IedServer self) Semaphore_destroy(self->clientConnectionsLock); #endif +#if (CONFIG_IEC61850_SUPPORT_SERVER_IDENTITY == 1) + + if (self->vendorName) + GLOBAL_FREEMEM(self->vendorName); + + if (self->modelName) + GLOBAL_FREEMEM(self->modelName); + + if (self->revision) + GLOBAL_FREEMEM(self->revision); +#endif /* (CONFIG_IEC61850_SUPPORT_SERVER_IDENTITY == 1) */ + GLOBAL_FREEMEM(self); } @@ -1530,6 +1542,28 @@ IedServer_setLogStorage(IedServer self, const char* logRef, LogStorage logStorag #endif } +void +IedServer_setServerIdentity(IedServer self, const char* vendor, const char* model, const char* revision) +{ +#if (CONFIG_IEC61850_SUPPORT_SERVER_IDENTITY == 1) + + if (self->vendorName) + GLOBAL_FREEMEM(self->vendorName); + + if (self->modelName) + GLOBAL_FREEMEM(self->modelName); + + if (self->revision) + GLOBAL_FREEMEM(self->revision); + + self->vendorName = StringUtils_copyString(vendor); + self->modelName = StringUtils_copyString(model); + self->revision = StringUtils_copyString(revision); + + MmsServer_setServerIdentity(self->mmsServer, self->vendorName, self->modelName, self->revision); +#endif +} + ClientConnection private_IedServer_getClientConnectionByHandle(IedServer self, void* serverConnectionHandle) {