///<summary> ///Parse AARQ request that client send and returns AARE request. /// </summary> ///<returns> ///Reply to the client. ///</returns> private void HandleAarqRequest(GXByteBuffer data, GXDLMSConnectionEventArgs connectionInfo) { AssociationResult result = AssociationResult.Accepted; Settings.CtoSChallenge = null; if (!Settings.UseCustomChallenge) { Settings.StoCChallenge = null; } // Reset settings for wrapper. if (Settings.InterfaceType == InterfaceType.WRAPPER) { Reset(true); } SourceDiagnostic diagnostic = GXAPDU.ParsePDU(Settings, Settings.Cipher, data, null); if (diagnostic != SourceDiagnostic.None) { result = AssociationResult.PermanentRejected; diagnostic = SourceDiagnostic.ApplicationContextNameNotSupported; InvalidConnection(connectionInfo); } else { diagnostic = ValidateAuthentication(Settings.Authentication, Settings.Password); if (diagnostic != SourceDiagnostic.None) { result = AssociationResult.PermanentRejected; InvalidConnection(connectionInfo); } else if (Settings.Authentication > Authentication.Low) { // If High authentication is used. if (!Settings.UseCustomChallenge) { Settings.StoCChallenge = GXSecure.GenerateChallenge(Settings.Authentication); } result = AssociationResult.Accepted; diagnostic = SourceDiagnostic.AuthenticationRequired; } else { Connected(connectionInfo); Settings.Connected = true; } } Settings.IsAuthenticationRequired = diagnostic == SourceDiagnostic.AuthenticationRequired; if (Settings.InterfaceType == Enums.InterfaceType.HDLC) { replyData.Set(GXCommon.LLCReplyBytes); } // Generate AARE packet. GXAPDU.GenerateAARE(Settings, replyData, result, diagnostic, Settings.Cipher, null); }
///<summary> ///Parse AARQ request that client send and returns AARE request. /// </summary> ///<returns> ///Reply to the client. ///</returns> private byte[][] HandleAarqRequest() { AssociationResult result = AssociationResult.Accepted; Settings.CtoSChallenge = null; if (!Settings.UseCustomChallenge) { Settings.StoCChallenge = null; } SourceDiagnostic diagnostic = GXAPDU.ParsePDU(Settings, Settings.Cipher, Reply.Data); if (diagnostic != SourceDiagnostic.None) { result = AssociationResult.PermanentRejected; diagnostic = SourceDiagnostic.ApplicationContextNameNotSupported; } else { // Check that user can access server. diagnostic = ValidateAuthentication(Settings.Authentication, Settings.Password); if (diagnostic != SourceDiagnostic.None) { result = AssociationResult.PermanentRejected; } else if (Settings.Authentication > Authentication.Low) { // If High authentication is used. Settings.StoCChallenge = GXSecure.GenerateChallenge(Settings.Authentication); result = AssociationResult.Accepted; diagnostic = SourceDiagnostic.AuthenticationRequired; } } // Generate AARE packet. GXByteBuffer buff = new GXByteBuffer(150); GXAPDU.GenerateAARE(Settings, buff, result, diagnostic, Settings.Cipher); return(GXDLMS.SplitPdu(Settings, Command.Aare, 0, buff, ErrorCode.Ok, DateTime.MinValue)[0]); }