From edbf23870a6d5f591f093e3b8e2f11825d6b9c2f Mon Sep 17 00:00:00 2001 From: Maxson Ramon dos Anjos Medeiros Date: Tue, 29 Jul 2025 18:34:07 +0200 Subject: [PATCH] (LIB61850-513) ->API IsoApplicationReference_getAeQualifier, IsoApplicationReference_getApTitle, ItuObjectIdentifier_getArcCount, ItuObjectIdentifier_getArc added --- .../AcseAuthenticationParameter.cs | 61 +++++++++++++++++++ .../server_example_access_control/Program.cs | 22 ++++++- src/mms/inc/iso_connection_parameters.h | 13 +++- .../iso_common/iso_connection_parameters.c | 32 ++++++++++ 4 files changed, 126 insertions(+), 2 deletions(-) diff --git a/dotnet/IEC61850forCSharp/AcseAuthenticationParameter.cs b/dotnet/IEC61850forCSharp/AcseAuthenticationParameter.cs index a0502fbe..ef10b8ee 100644 --- a/dotnet/IEC61850forCSharp/AcseAuthenticationParameter.cs +++ b/dotnet/IEC61850forCSharp/AcseAuthenticationParameter.cs @@ -114,9 +114,70 @@ namespace IEC61850 { private IntPtr self = IntPtr.Zero; + [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] + static extern int IsoApplicationReference_getAeQualifier(IntPtr self); + + [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] + static extern IntPtr IsoApplicationReference_getApTitle(IntPtr self); + public IsoApplicationReference(IntPtr self) { this.self= self; } + + public int GetAeQualifier() + { + return IsoApplicationReference_getAeQualifier(self); + } + + public ItuObjectIdentifier GetApTitle() + { + IntPtr identfier = IsoApplicationReference_getApTitle(self); + + if (identfier == IntPtr.Zero) + return null; + + return new ItuObjectIdentifier(identfier); + } + + } + + public class ItuObjectIdentifier + { + private IntPtr self = IntPtr.Zero; + + [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] + static extern int ItuObjectIdentifier_getArcCount(IntPtr self); + + [DllImport("iec61850", CallingConvention = CallingConvention.Cdecl)] + static extern IntPtr ItuObjectIdentifier_getArc(IntPtr self); + + public ItuObjectIdentifier(IntPtr self) + { + this.self = self; + } + + public int GetArcCount() + { + return ItuObjectIdentifier_getArcCount(self); + } + + public ushort[] GetArcs() + { + int count = ItuObjectIdentifier_getArcCount(self); + if (count <= 0 || count > 10) return Array.Empty(); + + IntPtr arcPtr = ItuObjectIdentifier_getArc(self); + + ushort[] arcs = new ushort[count]; + + short[] temp = new short[count]; + Marshal.Copy(arcPtr, temp, 0, count); + + for (int i = 0; i < count; i++) + arcs[i] = (ushort)temp[i]; + + return arcs; + } } } diff --git a/dotnet/server_example_access_control/Program.cs b/dotnet/server_example_access_control/Program.cs index fd4919fc..9dc01f28 100644 --- a/dotnet/server_example_access_control/Program.cs +++ b/dotnet/server_example_access_control/Program.cs @@ -8,6 +8,7 @@ using System; using IEC61850.Server; using IEC61850.Common; +using IEC61850; using System.Threading; using System.Net; using static IEC61850.Server.IedServer; @@ -17,7 +18,7 @@ using IEC61850.Client; using ReportControlBlock = IEC61850.Server.ReportControlBlock; using IEC61850.Model; using System.Data.Common; -using IEC61850; +using System.Security.Cryptography; namespace server_access_control { @@ -348,8 +349,27 @@ namespace server_access_control bool clientAuthenticator (object parameter, AcseAuthenticationParameter authParameter, object securityToken, IsoApplicationReference isoApplicationReference) { List passwords = parameter as List; + + int aeQualifier = isoApplicationReference.GetAeQualifier(); + ItuObjectIdentifier ituObjectIdentifier = isoApplicationReference.GetApTitle(); + int arcCount = ituObjectIdentifier.GetArcCount(); + ushort[] arc = ituObjectIdentifier.GetArcs(); + Console.WriteLine("ACSE Authenticator:\n"); + string appTitle = ""; + for (int i = 0; i < arcCount; i++) + { + appTitle += arc[i]; + + if (i != (arcCount - 1)) + appTitle += "."; + } + + Console.WriteLine(" client ap-title: " + appTitle); + + Console.WriteLine("\n client ae-qualifier: "+ aeQualifier + " \n"); + IEC61850.AcseAuthenticationMechanism acseAuthenticationMechanism = authParameter.GetAuthMechanism(); if (acseAuthenticationMechanism == IEC61850.AcseAuthenticationMechanism.ACSE_AUTH_PASSWORD) diff --git a/src/mms/inc/iso_connection_parameters.h b/src/mms/inc/iso_connection_parameters.h index 32f5b854..e2953c47 100644 --- a/src/mms/inc/iso_connection_parameters.h +++ b/src/mms/inc/iso_connection_parameters.h @@ -103,8 +103,19 @@ AcseAuthenticationParameter_getPassword(AcseAuthenticationParameter self); LIB61850_API int AcseAuthenticationParameter_getPasswordLength(AcseAuthenticationParameter self); +LIB61850_API int +IsoApplicationReference_getAeQualifier(IsoApplicationReference self); -/** +LIB61850_API const ItuObjectIdentifier* +IsoApplicationReference_getApTitle(const IsoApplicationReference* self); + +LIB61850_API int +ItuObjectIdentifier_getArcCount(ItuObjectIdentifier* self); + +LIB61850_API const uint16_t* +ItuObjectIdentifier_getArc(ItuObjectIdentifier* self); + + /** * \brief Callback function to authenticate a client * * \param parameter user provided parameter - set when user registers the authenticator diff --git a/src/mms/iso_common/iso_connection_parameters.c b/src/mms/iso_common/iso_connection_parameters.c index 04c8997d..ddab8f47 100644 --- a/src/mms/iso_common/iso_connection_parameters.c +++ b/src/mms/iso_common/iso_connection_parameters.c @@ -93,6 +93,38 @@ AcseAuthenticationParameter_getAuthMechanism(AcseAuthenticationParameter self) return self->mechanism; } +LIB61850_API int +IsoApplicationReference_getAeQualifier(IsoApplicationReference self) +{ + return self.aeQualifier; +} + +LIB61850_API const ItuObjectIdentifier* +IsoApplicationReference_getApTitle(const IsoApplicationReference* self) +{ + if (self == NULL) + return NULL; + return &(self->apTitle); +} + +LIB61850_API int +ItuObjectIdentifier_getArcCount(ItuObjectIdentifier* self) +{ + if (self == NULL) + return NULL; + + return self->arcCount; +} + +LIB61850_API const uint16_t* +ItuObjectIdentifier_getArc(ItuObjectIdentifier* self) +{ + if (self == NULL) + return NULL; + + return self->arc; +} + IsoConnectionParameters IsoConnectionParameters_create() {