KFDtool/sw/control/KFDtool.P25/ManualRekey/ManualRekeyApplication.cs

844 lines
32 KiB
C#
Raw Permalink Normal View History

2019-07-29 15:24:10 -06:00
using KFDtool.Adapter.Protocol.Adapter;
using KFDtool.P25.DataLinkIndependent;
using KFDtool.P25.DeviceProtocol;
2019-07-29 15:24:10 -06:00
using KFDtool.P25.Kmm;
using KFDtool.P25.NetworkProtocol;
using KFDtool.P25.Partition;
2019-07-29 15:24:10 -06:00
using KFDtool.P25.ThreeWire;
using KFDtool.P25.TransferConstructs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace KFDtool.P25.ManualRekey
{
public class ManualRekeyApplication
{
private static NLog.Logger Logger = NLog.LogManager.GetCurrentClassLogger();
private bool WithPreamble { get; set; }
private byte Mfid { get; set; }
private IDeviceProtocol DeviceProtocol;
2019-07-29 15:24:10 -06:00
public ManualRekeyApplication(AdapterProtocol adapterProtocol)
{
DeviceProtocol = new ThreeWireProtocol(adapterProtocol);
WithPreamble = false;
Mfid = 0x00;
}
public ManualRekeyApplication(UdpProtocol udpProtocol, bool motVariant)
{
DeviceProtocol = new DataLinkIndependentProtocol(udpProtocol, motVariant);
WithPreamble = true;
Mfid = motVariant ? (byte)0x90 : (byte)0x00;
2019-07-29 15:24:10 -06:00
}
private void Begin()
{
DeviceProtocol.SendKeySignature();
2019-07-29 15:24:10 -06:00
DeviceProtocol.InitSession();
2019-07-29 15:24:10 -06:00
}
private KmmBody TxRxKmm(KmmBody commandKmmBody)
{
KmmFrame commandKmmFrame = new KmmFrame(commandKmmBody);
byte[] toRadio = WithPreamble ? commandKmmFrame.ToBytesWithPreamble(Mfid) : commandKmmFrame.ToBytes();
2019-07-29 15:24:10 -06:00
byte[] fromRadio = DeviceProtocol.PerformKmmTransfer(toRadio);
2019-07-29 15:24:10 -06:00
KmmFrame responseKmmFrame = new KmmFrame(WithPreamble, fromRadio);
2019-07-29 15:24:10 -06:00
return responseKmmFrame.KmmBody;
}
private void End()
{
DeviceProtocol.EndSession();
2019-07-29 15:24:10 -06:00
}
public void Keyload(List<CmdKeyItem> keyItems)
2019-07-29 15:24:10 -06:00
{
List<List<CmdKeyItem>> keyGroups = KeyPartitioner.PartitionKeys(keyItems);
2019-07-29 15:24:10 -06:00
Begin();
try
{
InventoryCommandListActiveKsetIds cmdKmmBody1 = new InventoryCommandListActiveKsetIds();
2019-07-29 15:24:10 -06:00
KmmBody rspKmmBody1 = TxRxKmm(cmdKmmBody1);
2019-07-29 15:24:10 -06:00
int activeKeysetId = 0;
2019-07-29 15:24:10 -06:00
if (rspKmmBody1 is InventoryResponseListActiveKsetIds)
{
InventoryResponseListActiveKsetIds kmm = rspKmmBody1 as InventoryResponseListActiveKsetIds;
2019-07-29 15:24:10 -06:00
Logger.Debug("number of active keyset ids: {0}", kmm.KsetIds.Count);
2019-07-29 15:24:10 -06:00
for (int i = 0; i < kmm.KsetIds.Count; i++)
{
Logger.Debug("* keyset id index {0} *", i);
Logger.Debug("keyset id: {0} (dec), {0:X} (hex)", kmm.KsetIds[i]);
}
2019-07-29 15:24:10 -06:00
// TODO support more than one crypto group
if (kmm.KsetIds.Count > 0)
{
activeKeysetId = kmm.KsetIds[0];
}
else
{
activeKeysetId = 1; // to match KVL3000+ R3.53.03 behavior
}
2019-07-29 15:24:10 -06:00
}
else if (rspKmmBody1 is NegativeAcknowledgment)
2019-07-29 15:24:10 -06:00
{
NegativeAcknowledgment kmm = rspKmmBody1 as NegativeAcknowledgment;
2020-03-15 16:53:24 -06:00
string statusDescr = OperationStatusExtensions.ToStatusString(kmm.Status);
string statusReason = OperationStatusExtensions.ToReasonString(kmm.Status);
throw new Exception(string.Format("received negative acknowledgment{0}status: {1} (0x{2:X2}){0}{3}", Environment.NewLine, statusDescr, kmm.Status, statusReason));
2019-07-29 15:24:10 -06:00
}
else
{
throw new Exception("unexpected kmm");
2019-07-29 15:24:10 -06:00
}
foreach (List<CmdKeyItem> keyGroup in keyGroups)
{
ModifyKeyCommand modifyKeyCommand = new ModifyKeyCommand();
2019-07-29 15:24:10 -06:00
// TODO support more than one crypto group
if (keyGroup[0].UseActiveKeyset && !keyGroup[0].IsKek)
{
modifyKeyCommand.KeysetId = activeKeysetId;
}
else if (keyGroup[0].UseActiveKeyset && keyGroup[0].IsKek)
{
modifyKeyCommand.KeysetId = 0xFF; // to match KVL3000+ R3.53.03 behavior
}
else
{
modifyKeyCommand.KeysetId = keyGroup[0].KeysetId;
}
2019-07-29 15:24:10 -06:00
modifyKeyCommand.AlgorithmId = keyGroup[0].AlgorithmId;
2019-07-29 15:24:10 -06:00
foreach (CmdKeyItem key in keyGroup)
{
Logger.Debug(key.ToString());
2019-07-29 15:24:10 -06:00
KeyItem keyItem = new KeyItem();
keyItem.SLN = key.Sln;
keyItem.KeyId = key.KeyId;
keyItem.Key = key.Key.ToArray();
keyItem.KEK = key.IsKek;
keyItem.Erase = false;
2019-07-29 15:24:10 -06:00
modifyKeyCommand.KeyItems.Add(keyItem);
}
2019-07-29 15:24:10 -06:00
KmmBody rspKmmBody2 = TxRxKmm(modifyKeyCommand);
2019-07-29 15:24:10 -06:00
if (rspKmmBody2 is RekeyAcknowledgment)
2019-07-29 15:24:10 -06:00
{
RekeyAcknowledgment kmm = rspKmmBody2 as RekeyAcknowledgment;
Logger.Debug("number of key status: {0}", kmm.Keys.Count);
for (int i = 0; i < kmm.Keys.Count; i++)
{
KeyStatus status = kmm.Keys[i];
Logger.Debug("* key status index {0} *", i);
Logger.Debug("algorithm id: {0} (dec), {0:X} (hex)", status.AlgorithmId);
Logger.Debug("key id: {0} (dec), {0:X} (hex)", status.KeyId);
Logger.Debug("status: {0} (dec), {0:X} (hex)", status.Status);
if (status.Status != 0)
{
string statusDescr = OperationStatusExtensions.ToStatusString((OperationStatus)status.Status);
string statusReason = OperationStatusExtensions.ToReasonString((OperationStatus)status.Status);
2020-08-01 08:12:20 -06:00
throw new Exception(
string.Format(
"received unexpected key status{0}" +
"algorithm id: {1} (0x{1:X}){0}" +
"key id: {2} (0x{2:X}){0}" +
"status: {3} (0x{3:X}){0}" +
"status description: {4}{0}" +
"status reason: {5}",
Environment.NewLine, status.AlgorithmId, status.KeyId, status.Status, statusDescr, statusReason
)
);
}
}
2019-07-29 15:24:10 -06:00
}
else if (rspKmmBody2 is NegativeAcknowledgment)
{
NegativeAcknowledgment kmm = rspKmmBody2 as NegativeAcknowledgment;
2019-12-28 11:28:57 -07:00
string statusDescr = OperationStatusExtensions.ToStatusString(kmm.Status);
string statusReason = OperationStatusExtensions.ToReasonString(kmm.Status);
throw new Exception(string.Format("received negative acknowledgment{0}status: {1} (0x{2:X2}){0}{3}", Environment.NewLine, statusDescr, kmm.Status, statusReason));
}
else
{
throw new Exception("received unexpected kmm");
}
}
2019-12-28 11:28:57 -07:00
}
catch
2019-07-29 15:24:10 -06:00
{
End();
throw;
2019-07-29 15:24:10 -06:00
}
End();
}
public void EraseKeys(List<CmdKeyItem> keyItems)
2019-07-29 15:24:10 -06:00
{
List<List<CmdKeyItem>> keyGroups = KeyPartitioner.PartitionKeys(keyItems);
2019-07-29 15:24:10 -06:00
Begin();
try
{
InventoryCommandListActiveKsetIds cmdKmmBody1 = new InventoryCommandListActiveKsetIds();
2019-07-29 15:24:10 -06:00
KmmBody rspKmmBody1 = TxRxKmm(cmdKmmBody1);
2019-07-29 15:24:10 -06:00
int activeKeysetId = 0;
2019-07-29 15:24:10 -06:00
if (rspKmmBody1 is InventoryResponseListActiveKsetIds)
{
InventoryResponseListActiveKsetIds kmm = rspKmmBody1 as InventoryResponseListActiveKsetIds;
2019-07-29 15:24:10 -06:00
Logger.Debug("number of active keyset ids: {0}", kmm.KsetIds.Count);
2019-07-29 15:24:10 -06:00
for (int i = 0; i < kmm.KsetIds.Count; i++)
{
Logger.Debug("* keyset id index {0} *", i);
Logger.Debug("keyset id: {0} (dec), {0:X} (hex)", kmm.KsetIds[i]);
}
2019-07-29 15:24:10 -06:00
// TODO support more than one crypto group
if (kmm.KsetIds.Count > 0)
{
activeKeysetId = kmm.KsetIds[0];
}
else
{
activeKeysetId = 1; // to match KVL3000+ R3.53.03 behavior
}
2019-07-29 15:24:10 -06:00
}
else if (rspKmmBody1 is NegativeAcknowledgment)
2019-07-29 15:24:10 -06:00
{
NegativeAcknowledgment kmm = rspKmmBody1 as NegativeAcknowledgment;
2020-03-15 16:53:24 -06:00
string statusDescr = OperationStatusExtensions.ToStatusString(kmm.Status);
string statusReason = OperationStatusExtensions.ToReasonString(kmm.Status);
throw new Exception(string.Format("received negative acknowledgment{0}status: {1} (0x{2:X2}){0}{3}", Environment.NewLine, statusDescr, kmm.Status, statusReason));
2019-07-29 15:24:10 -06:00
}
else
{
throw new Exception("unexpected kmm");
2019-07-29 15:24:10 -06:00
}
2019-12-28 11:28:57 -07:00
foreach (List<CmdKeyItem> keyGroup in keyGroups)
{
ModifyKeyCommand modifyKeyCommand = new ModifyKeyCommand();
2019-07-29 15:24:10 -06:00
// TODO support more than one crypto group
if (keyGroup[0].UseActiveKeyset && !keyGroup[0].IsKek)
{
modifyKeyCommand.KeysetId = activeKeysetId;
}
else if (keyGroup[0].UseActiveKeyset && keyGroup[0].IsKek)
{
modifyKeyCommand.KeysetId = 0xFF; // to match KVL3000+ R3.53.03 behavior
}
else
{
modifyKeyCommand.KeysetId = keyGroup[0].KeysetId;
}
2019-07-29 15:24:10 -06:00
modifyKeyCommand.AlgorithmId = 0x81; // to match KVL3000+ R3.53.03 behavior
2019-07-29 15:24:10 -06:00
foreach (CmdKeyItem key in keyGroup)
{
Logger.Debug(key.ToString());
2019-07-29 15:24:10 -06:00
KeyItem keyItem = new KeyItem();
keyItem.SLN = key.Sln;
keyItem.KeyId = 65535; // to match KVL3000+ R3.53.03 behavior
keyItem.Key = new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; // to match KVL3000+ R3.53.03 behavior
keyItem.KEK = key.IsKek;
keyItem.Erase = true;
2019-07-29 15:24:10 -06:00
modifyKeyCommand.KeyItems.Add(keyItem);
}
2019-07-29 15:24:10 -06:00
KmmBody rspKmmBody2 = TxRxKmm(modifyKeyCommand);
2019-07-29 15:24:10 -06:00
if (rspKmmBody2 is RekeyAcknowledgment)
2019-07-29 15:24:10 -06:00
{
RekeyAcknowledgment kmm = rspKmmBody2 as RekeyAcknowledgment;
Logger.Debug("number of key status: {0}", kmm.Keys.Count);
for (int i = 0; i < kmm.Keys.Count; i++)
{
KeyStatus status = kmm.Keys[i];
Logger.Debug("* key status index {0} *", i);
Logger.Debug("algorithm id: {0} (dec), {0:X} (hex)", status.AlgorithmId);
Logger.Debug("key id: {0} (dec), {0:X} (hex)", status.KeyId);
Logger.Debug("status: {0} (dec), {0:X} (hex)", status.Status);
if (status.Status != 0)
{
string statusDescr = OperationStatusExtensions.ToStatusString((OperationStatus)status.Status);
string statusReason = OperationStatusExtensions.ToReasonString((OperationStatus)status.Status);
2020-08-01 08:12:20 -06:00
throw new Exception(
string.Format(
"received unexpected key status{0}" +
"algorithm id: {1} (0x{1:X}){0}" +
"key id: {2} (0x{2:X}){0}" +
"status: {3} (0x{3:X}){0}" +
"status description: {4}{0}" +
"status reason: {5}",
Environment.NewLine, status.AlgorithmId, status.KeyId, status.Status, statusDescr, statusReason
)
);
}
}
2019-07-29 15:24:10 -06:00
}
else if (rspKmmBody2 is NegativeAcknowledgment)
{
NegativeAcknowledgment kmm = rspKmmBody2 as NegativeAcknowledgment;
2019-12-28 11:28:57 -07:00
string statusDescr = OperationStatusExtensions.ToStatusString(kmm.Status);
string statusReason = OperationStatusExtensions.ToReasonString(kmm.Status);
throw new Exception(string.Format("received negative acknowledgment{0}status: {1} (0x{2:X2}){0}{3}", Environment.NewLine, statusDescr, kmm.Status, statusReason));
}
else
{
throw new Exception("received unexpected kmm");
}
}
2019-12-28 11:28:57 -07:00
}
catch
2019-07-29 15:24:10 -06:00
{
End();
throw;
2019-07-29 15:24:10 -06:00
}
End();
}
public void EraseAllKeys()
{
Begin();
try
{
ZeroizeCommand commandKmmBody = new ZeroizeCommand();
2019-07-29 15:24:10 -06:00
KmmBody responseKmmBody = TxRxKmm(commandKmmBody);
2019-07-29 15:24:10 -06:00
if (responseKmmBody is ZeroizeResponse)
{
Logger.Debug("zerozied");
}
else if (responseKmmBody is NegativeAcknowledgment)
{
NegativeAcknowledgment kmm = responseKmmBody as NegativeAcknowledgment;
2019-12-28 11:28:57 -07:00
2020-03-15 16:53:24 -06:00
string statusDescr = OperationStatusExtensions.ToStatusString(kmm.Status);
string statusReason = OperationStatusExtensions.ToReasonString(kmm.Status);
throw new Exception(string.Format("received negative acknowledgment{0}status: {1} (0x{2:X2}){0}{3}", Environment.NewLine, statusDescr, kmm.Status, statusReason));
}
else
{
throw new Exception("unexpected kmm");
}
2019-12-28 11:28:57 -07:00
}
catch
2019-07-29 15:24:10 -06:00
{
End();
throw;
2019-07-29 15:24:10 -06:00
}
End();
}
public List<RspKeyInfo> ViewKeyInfo()
{
List<RspKeyInfo> result = new List<RspKeyInfo>();
Begin();
try
2019-07-29 15:24:10 -06:00
{
bool more = true;
int marker = 0;
2019-07-29 15:24:10 -06:00
while (more)
2019-07-29 15:24:10 -06:00
{
InventoryCommandListActiveKeys commandKmmBody = new InventoryCommandListActiveKeys();
commandKmmBody.InventoryMarker = marker;
commandKmmBody.MaxKeysRequested = 78;
KmmBody responseKmmBody = TxRxKmm(commandKmmBody);
2019-07-29 15:24:10 -06:00
if (responseKmmBody is InventoryResponseListActiveKeys)
{
InventoryResponseListActiveKeys kmm = responseKmmBody as InventoryResponseListActiveKeys;
marker = kmm.InventoryMarker;
Logger.Debug("inventory marker: {0}", marker);
if (marker == 0)
{
more = false;
}
2019-07-29 15:24:10 -06:00
Logger.Debug("number of keys returned: {0}", kmm.Keys.Count);
2019-07-29 15:24:10 -06:00
for (int i = 0; i < kmm.Keys.Count; i++)
{
KeyInfo info = kmm.Keys[i];
2019-07-29 15:24:10 -06:00
Logger.Debug("* key index {0} *", i);
Logger.Debug("keyset id: {0} (dec), {0:X} (hex)", info.KeySetId);
Logger.Debug("sln: {0} (dec), {0:X} (hex)", info.SLN);
Logger.Debug("algorithm id: {0} (dec), {0:X} (hex)", info.AlgorithmId);
Logger.Debug("key id: {0} (dec), {0:X} (hex)", info.KeyId);
RspKeyInfo res = new RspKeyInfo();
res.KeysetId = info.KeySetId;
res.Sln = info.SLN;
res.AlgorithmId = info.AlgorithmId;
res.KeyId = info.KeyId;
result.Add(res);
}
}
else if (responseKmmBody is NegativeAcknowledgment)
{
NegativeAcknowledgment kmm = responseKmmBody as NegativeAcknowledgment;
2019-12-28 11:28:57 -07:00
2020-03-15 16:53:24 -06:00
string statusDescr = OperationStatusExtensions.ToStatusString(kmm.Status);
string statusReason = OperationStatusExtensions.ToReasonString(kmm.Status);
throw new Exception(string.Format("received negative acknowledgment{0}status: {1} (0x{2:X2}){0}{3}", Environment.NewLine, statusDescr, kmm.Status, statusReason));
}
else
{
throw new Exception("unexpected kmm");
}
2019-07-29 15:24:10 -06:00
}
}
catch
{
End();
throw;
}
2019-07-29 15:24:10 -06:00
End();
return result;
}
public int ViewKmfRsi()
2019-07-29 15:24:10 -06:00
{
int result = new int();
Begin();
try
{
InventoryCommandListKmfRsi commandKmmBody = new InventoryCommandListKmfRsi();
KmmBody responseKmmBody = TxRxKmm(commandKmmBody);
if (responseKmmBody is InventoryResponseListKmfRsi)
{
Logger.Debug("MNP response");
InventoryResponseListKmfRsi kmm = responseKmmBody as InventoryResponseListKmfRsi;
result = kmm.KmfRsi;
}
else if (responseKmmBody is NegativeAcknowledgment)
{
NegativeAcknowledgment kmm = responseKmmBody as NegativeAcknowledgment;
string statusDescr = OperationStatusExtensions.ToStatusString(kmm.Status);
string statusReason = OperationStatusExtensions.ToReasonString(kmm.Status);
throw new Exception(string.Format("received negative acknowledgment{0}status: {1} (0x{2:X2}){0}{3}", Environment.NewLine, statusDescr, kmm.Status, statusReason));
}
else
{
throw new Exception("unexpected kmm");
}
}
catch
{
End();
throw;
}
End();
return result;
2019-07-29 15:24:10 -06:00
}
public int ViewMnp()
2019-07-29 15:24:10 -06:00
{
int result = new int();
Begin();
try
{
InventoryCommandListMnp commandKmmBody = new InventoryCommandListMnp();
KmmBody responseKmmBody = TxRxKmm(commandKmmBody);
if (responseKmmBody is InventoryResponseListMnp)
{
Logger.Debug("MNP response");
InventoryResponseListMnp kmm = responseKmmBody as InventoryResponseListMnp;
result = kmm.MessageNumberPeriod;
}
else if (responseKmmBody is NegativeAcknowledgment)
{
NegativeAcknowledgment kmm = responseKmmBody as NegativeAcknowledgment;
string statusDescr = OperationStatusExtensions.ToStatusString(kmm.Status);
string statusReason = OperationStatusExtensions.ToReasonString(kmm.Status);
throw new Exception(string.Format("received negative acknowledgment{0}status: {1} (0x{2:X2}){0}{3}", Environment.NewLine, statusDescr, kmm.Status, statusReason));
}
else
{
throw new Exception("unexpected kmm");
}
}
catch
{
End();
throw;
}
End();
return result;
2019-07-29 15:24:10 -06:00
}
public RspRsiInfo LoadConfig(int kmfRsi, int mnp)
{
RspRsiInfo result = new RspRsiInfo();
Begin();
try
{
LoadConfigCommand cmdKmmBody = new LoadConfigCommand();
cmdKmmBody.KmfRsi = kmfRsi;
cmdKmmBody.MessageNumberPeriod = mnp;
KmmBody rspKmmBody = TxRxKmm(cmdKmmBody);
if (rspKmmBody is LoadConfigResponse)
{
LoadConfigResponse kmm = rspKmmBody as LoadConfigResponse;
result.RSI = kmm.RSI;
result.MN = kmm.MN;
result.Status = kmm.Status;
}
else if (rspKmmBody is NegativeAcknowledgment)
{
NegativeAcknowledgment kmm = rspKmmBody as NegativeAcknowledgment;
string statusDescr = OperationStatusExtensions.ToStatusString(kmm.Status);
string statusReason = OperationStatusExtensions.ToReasonString(kmm.Status);
throw new Exception(string.Format("received negative acknowledgment{0}status: {1} (0x{2:X2}){0}{3}", Environment.NewLine, statusDescr, kmm.Status, statusReason));
}
else
{
throw new Exception("unexpected kmm");
}
}
catch
{
End();
throw;
}
End();
return result;
}
public RspRsiInfo ChangeRsi(int rsiOld, int rsiNew, int mnp)
{
RspRsiInfo result = new RspRsiInfo();
Begin();
try
{
ChangeRsiCommand cmdKmmBody = new ChangeRsiCommand();
cmdKmmBody.RsiOld = rsiOld;
cmdKmmBody.RsiNew = rsiNew;
cmdKmmBody.MessageNumber = mnp;
2020-05-17 18:57:10 -06:00
KmmBody rspKmmBody = TxRxKmm(cmdKmmBody);
2020-05-17 18:57:10 -06:00
if (rspKmmBody is ChangeRsiResponse)
{
ChangeRsiResponse kmm = rspKmmBody as ChangeRsiResponse;
result.RSI = rsiNew;
result.MN = mnp;
result.Status = kmm.Status;
}
else if (rspKmmBody is NegativeAcknowledgment)
{
NegativeAcknowledgment kmm = rspKmmBody as NegativeAcknowledgment;
string statusDescr = OperationStatusExtensions.ToStatusString(kmm.Status);
string statusReason = OperationStatusExtensions.ToReasonString(kmm.Status);
throw new Exception(string.Format("received negative acknowledgment{0}status: {1} (0x{2:X2}){0}{3}", Environment.NewLine, statusDescr, kmm.Status, statusReason));
}
else
{
throw new Exception("unexpected kmm");
}
}
catch
{
End();
throw;
}
End();
return result;
}
public List<RspRsiInfo> ViewRsiItems()
{
List<RspRsiInfo> result = new List<RspRsiInfo>();
Begin();
try
{
bool more = true;
int marker = 0;
while (more)
{
InventoryCommandListRsiItems commandKmmBody = new InventoryCommandListRsiItems();
KmmBody responseKmmBody = TxRxKmm(commandKmmBody);
if (responseKmmBody is InventoryResponseListRsiItems)
{
InventoryResponseListRsiItems kmm = responseKmmBody as InventoryResponseListRsiItems;
Logger.Debug("inventory marker: {0}", marker);
if (marker == 0)
{
more = false;
}
Logger.Debug("number of RSIs returned: {0}", kmm.RsiItems.Count);
for (int i = 0; i < kmm.RsiItems.Count; i++)
{
RsiItem item = kmm.RsiItems[i];
Logger.Debug("* rsi index {0} *", i);
Logger.Debug("rsi id: {0} (dec), {0:X} (hex)", item.RSI);
Logger.Debug("mn: {0} (dec), {0:X} (hex)", item.MessageNumber);
RspRsiInfo res = new RspRsiInfo();
res.RSI = (int)item.RSI;
res.MN = item.MessageNumber;
result.Add(res);
}
}
else if (responseKmmBody is NegativeAcknowledgment)
{
NegativeAcknowledgment kmm = responseKmmBody as NegativeAcknowledgment;
string statusDescr = OperationStatusExtensions.ToStatusString(kmm.Status);
string statusReason = OperationStatusExtensions.ToReasonString(kmm.Status);
throw new Exception(string.Format("received negative acknowledgment{0}status: {1} (0x{2:X2}){0}{3}", Environment.NewLine, statusDescr, kmm.Status, statusReason));
}
else
{
throw new Exception("unexpected kmm");
}
}
}
catch
{
End();
throw;
}
End();
return result;
}
public List<RspKeysetInfo> ViewKeysetTaggingInfo()
{
List<RspKeysetInfo> result = new List<RspKeysetInfo>();
Begin();
try
{
InventoryCommandListKeysetTaggingInfo commandKmmBody = new InventoryCommandListKeysetTaggingInfo();
KmmBody responseKmmBody = TxRxKmm(commandKmmBody);
if (responseKmmBody is InventoryResponseListKeysetTaggingInfo)
{
Logger.Debug("KeysetTaggingInfo response");
InventoryResponseListKeysetTaggingInfo kmm = responseKmmBody as InventoryResponseListKeysetTaggingInfo;
for (int i = 0; i < kmm.KeysetItems.Count; i++)
{
KeysetItem item = kmm.KeysetItems[i];
RspKeysetInfo res = new RspKeysetInfo();
res.KeysetId = item.KeysetId;
res.KeysetName = item.KeysetName;
res.KeysetType = item.KeysetType;
res.ActivationDateTime = item.ActivationDateTime;
res.ReservedField = item.ReservedField;
result.Add(res);
}
}
else if (responseKmmBody is NegativeAcknowledgment)
{
NegativeAcknowledgment kmm = responseKmmBody as NegativeAcknowledgment;
string statusDescr = OperationStatusExtensions.ToStatusString(kmm.Status);
string statusReason = OperationStatusExtensions.ToReasonString(kmm.Status);
throw new Exception(string.Format("received negative acknowledgment{0}status: {1} (0x{2:X2}){0}{3}", Environment.NewLine, statusDescr, kmm.Status, statusReason));
}
else
{
throw new Exception("unexpected kmm");
}
}
catch
{
End();
throw;
}
End();
return result;
}
public RspChangeoverInfo ActivateKeyset(int keysetSuperseded, int keysetActivated)
{
RspChangeoverInfo result = new RspChangeoverInfo();
Begin();
try
{
ChangeoverCommand cmdKmmBody = new ChangeoverCommand();
cmdKmmBody.KeysetIdSuperseded = keysetSuperseded;
cmdKmmBody.KeysetIdActivated = keysetActivated;
KmmBody rspKmmBody = TxRxKmm(cmdKmmBody);
2020-05-17 18:57:10 -06:00
if (rspKmmBody is ChangeoverResponse)
{
ChangeoverResponse kmm = rspKmmBody as ChangeoverResponse;
result.KeysetIdSuperseded = kmm.KeysetIdSuperseded;
result.KeysetIdActivated = kmm.KeysetIdActivated;
}
else if (rspKmmBody is NegativeAcknowledgment)
{
NegativeAcknowledgment kmm = rspKmmBody as NegativeAcknowledgment;
string statusDescr = OperationStatusExtensions.ToStatusString(kmm.Status);
string statusReason = OperationStatusExtensions.ToReasonString(kmm.Status);
throw new Exception(string.Format("received negative acknowledgment{0}status: {1} (0x{2:X2}){0}{3}", Environment.NewLine, statusDescr, kmm.Status, statusReason));
}
else
{
throw new Exception("unexpected kmm");
}
}
catch
{
End();
throw;
}
End();
return result;
}
2020-05-17 18:57:10 -06:00
public void LoadAuthenticationKey()
{
throw new NotImplementedException();
}
2020-05-17 18:57:10 -06:00
public void DeleteAuthenticationKey()
{
throw new NotImplementedException();
}
2020-05-17 18:57:10 -06:00
public void ViewSuidInfo()
{
throw new NotImplementedException();
}
public void ViewActiveSuidInfo()
{
throw new NotImplementedException();
}
2019-07-29 15:24:10 -06:00
}
}