private static void HandleAarqAare(XmlNode node, GXDLMSXmlSettings s, int tag)
{
byte[] tmp;
byte[] conformanceBlock;
int value;
switch (tag)
{
case (int)TranslatorGeneralTags.ApplicationContextName:
if (s.OutputType == TranslatorOutputType.StandardXml)
{
value = int.Parse(node.InnerText);
switch (value)
{
case 1:
s.settings.UseLogicalNameReferencing = true;
break;
case 2:
s.settings.UseLogicalNameReferencing = false;
break;
case 3:
s.settings.UseLogicalNameReferencing = true;
break;
case 4:
s.settings.UseLogicalNameReferencing = false;
break;
default:
throw new ArgumentException("Invalid dedicated key.");
}
}
else
{
string str = node.Attributes[0].InnerText;
if (string.Compare(str, "SN") == 0 ||
string.Compare(str, "SN_WITH_CIPHERING") == 0)
{
s.settings.UseLogicalNameReferencing = false;
}
else if (string.Compare(str, "LN") == 0 ||
string.Compare(str, "LN_WITH_CIPHERING") == 0)
{
s.settings.UseLogicalNameReferencing = true;
}
else
{
throw new ArgumentException("Invalid Reference type name.");
}
}
break;
case (byte)Command.GloInitiateRequest:
case (byte)Command.GloGetRequest:
case (byte)Command.GloSetRequest:
case (byte)Command.GloMethodRequest:
case (byte)Command.GloReadRequest:
case (byte)Command.GloWriteRequest:
s.settings.IsServer = false;
tmp = GXCommon.HexToBytes(GetValue(node, s));
s.settings.Cipher.Security = (Security)tmp[0];
s.data.Set(tmp);
break;
case (byte)Command.GloInitiateResponse:
case (byte)Command.GloGetResponse:
case (byte)Command.GloSetResponse:
case (byte)Command.GloMethodResponse:
case (byte)Command.GloReadResponse:
case (byte)Command.GloWriteResponse:
tmp = GXCommon.HexToBytes(GetValue(node, s));
s.settings.Cipher.Security = (Security)tmp[0];
s.data.Set(tmp);
break;
case (byte)Command.InitiateRequest:
case (byte)Command.InitiateResponse:
if (s.OutputType == TranslatorOutputType.StandardXml)
{
GXByteBuffer bb = new GXByteBuffer();
tmp = GXCommon.HexToBytes(GetValue(node, s));
GXCommon.SetObjectCount(tmp.Length, bb);
bb.Set(tmp);
GXAPDU.ParseUserInformation(s.settings,
s.settings.Cipher, bb, null);
if (s.command == Command.Aarq)
{
if (s.settings.UseLogicalNameReferencing)
{
s.settings.LnSettings.ConformanceBlock =
s.settings.ConformanceBlock;
}
else
{
s.settings.SnSettings.ConformanceBlock =
s.settings.ConformanceBlock;
}
}
}
break;
case 0xBE00:
//NegotiatedQualityOfService
break;
case 0xBE06:
case 0xBE01:
//NegotiatedDlmsVersionNumber or ProposedDlmsVersionNumber is skipped.
break;
case 0xBE04:
//VaaName is not needed.
break;
case 0x8A:
//SenderACSERequirements is not needed.
break;
case 0x8B:
case 0x89:
//MechanismName.
s.settings.Authentication = (Authentication)Enum.Parse(typeof(Authentication), GetValue(node, s));
if (s.OutputType == TranslatorOutputType.SimpleXml)
{
s.settings.Authentication = (Authentication)Enum.Parse(typeof(Authentication), GetValue(node, s));
}
else
{
s.settings.Authentication = (Authentication)int.Parse(GetValue(node, s));
}
break;
case 0xAC:
//CallingAuthentication.
if (s.settings.Authentication == Authentication.Low)
{
s.settings.Password = GXCommon.HexToBytes(GetValue(node, s));
}
else
{
s.settings.CtoSChallenge = GXCommon.HexToBytes(GetValue(node, s));
}
break;
case (int)TranslatorGeneralTags.DedicatedKey:
tmp = GXCommon.HexToBytes(GetValue(node, s));
s.settings.DedicatedKey = tmp;
break;
case (int)TranslatorGeneralTags.CallingAPTitle:
s.settings
.CtoSChallenge = GXCommon.HexToBytes(GetValue(node, s));
break;
case 0xA4:
//RespondingAPTitle.
s.settings.StoCChallenge = GXCommon.HexToBytes(GetValue(node, s));
break;
case 0xBE03:
case 0xBE05:
//ProposedConformance or NegotiatedConformance
if (s.settings.UseLogicalNameReferencing)
{
s.settings.LnSettings.Clear();
}
else
{
s.settings.SnSettings.Clear();
}
if (s.OutputType == TranslatorOutputType.StandardXml)
{
String nodes = node.InnerText;
if (s.settings.UseLogicalNameReferencing)
{
conformanceBlock = s.settings.LnSettings.ConformanceBlock;
}
else
{
conformanceBlock = s.settings.SnSettings.ConformanceBlock;
}
foreach (String it in nodes.Split(' '))
{
if (it.Trim() != string.Empty)
{
value = (int)ValueOfConformance(it.Trim());
if (value < 0x100)
{
conformanceBlock[2] |= (byte)value;
}
else if (value < 0x10000)
{
conformanceBlock[1] |= (byte)(value >> 8);
}
else
{
conformanceBlock[0] |= (byte)(value >> 16);
}
}
}
}
break;
case 0xBE08:
//ConformanceBit.
value = (int)Enum.Parse(typeof(Conformance), node.Attributes["Name"].InnerText);
if (s.settings.UseLogicalNameReferencing)
{
conformanceBlock = s.settings.LnSettings.ConformanceBlock;
}
else
{
conformanceBlock = s.settings.SnSettings.ConformanceBlock;
}
if (value < 0x100)
{
conformanceBlock[2] |= (byte)value;
}
else if (value < 0x10000)
{
conformanceBlock[1] |= (byte)(value >> 8);
}
else
{
conformanceBlock[0] |= (byte)(value >> 16);
}
break;
case 0xA2:
//AssociationResult
s.result = (AssociationResult)Enum.Parse(typeof(AssociationResult), GetValue(node, s));
break;
case 0xBE02:
case 0xBE07:
//NegotiatedMaxPduSize or ProposedMaxPduSize.
s.settings.MaxPduSize = (UInt16)s.ParseInt(GetValue(node, s));
break;
case 0xA3:
//ResultSourceDiagnostic
s.diagnostic = SourceDiagnostic.None;
break;
case 0xA301:
//ACSEServiceUser
s.diagnostic = (SourceDiagnostic)s.ParseInt(GetValue(node, s));
break;
case 0xBE09:
// ProposedQualityOfService
break;
case (int)TranslatorGeneralTags.CharString:
// Get PW
if (s.settings.Authentication == Authentication.Low)
{
s.settings
.Password = GXCommon.HexToBytes(GetValue(node, s));
}
else
{
if (s.command == Command.Aarq)
{
s.settings.CtoSChallenge =
GXCommon.HexToBytes(GetValue(node, s));
}
else
{
s.settings.StoCChallenge =
GXCommon.HexToBytes(GetValue(node, s));
}
}
break;
case (int)TranslatorGeneralTags.ResponderACSERequirement:
break;
case (int)TranslatorGeneralTags.RespondingAuthentication:
s.settings
.StoCChallenge = GXCommon.HexToBytes(GetValue(node, s));
break;
case (int)TranslatorTags.Result:
s.result = (AssociationResult)
int.Parse(GetValue(node, s));
break;
default:
throw new ArgumentException("Invalid AARQ node: " + node.Name);
}
}