using System;
using QCRPG.Framework;

namespace QCRPG.TSL.ZigBee.Packets;

public class McpsDataRequestInfo : PacketInfoBase
{
	public override string Name => "Mcps Data Request";

	public override string DisplayGroup => "MCPS Data Packets";

	public McpsDataRequestInfo(McpsDataRequest packet)
		: base(packet)
	{
		UpdateFieldInfoFromPacket();
	}

	public override void UpdateFieldInfoFromPacket()
	{
		McpsDataRequest mcpsDataRequest = (McpsDataRequest)packet;
		fieldInfoList.Clear();
		fieldInfoList.Add(new PacketFieldInfo("SrcAddrMode", "The source addressing mode for this primitive and subsequent MPDU\r\n\r\n" + DutaddressmodeInfo.DutaddressmodeToDescription(), 8, FormatValue(mcpsDataRequest.UserFields.Srcaddrmode, 8), DutaddressmodeInfo.DutaddressmodeToString(DutaddressmodeInfo.ValueToDutaddressmode(mcpsDataRequest.UserFields.Srcaddrmode)), "00", "03", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("DstAddrMode", "The destination addressing mode for this primitive and subsequent MPDU\r\n\r\n" + DutaddressmodeInfo.DutaddressmodeToDescription(), 8, FormatValue(mcpsDataRequest.UserFields.Dstaddrmode, 8), DutaddressmodeInfo.DutaddressmodeToString(DutaddressmodeInfo.ValueToDutaddressmode(mcpsDataRequest.UserFields.Dstaddrmode)), "", "03", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("DstPANId", "The 16-bit PAN identifier of the entity to which the MSDU is being transferred.", 16, FormatValue(mcpsDataRequest.UserFields.Dstpanid, 16), "", "0000", "0xFFFF", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("DstAddr", "The individual device address of the entity to which the MSDU is being transferred", 64, FormatValue(mcpsDataRequest.UserFields.Dstaddr, 64), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("msduLength", "The number of octets contained in the MSDU to be transmitted by the MAC sublayer entity.", 8, FormatValue(mcpsDataRequest.UserFields.Msdulength, 8), "", "", "FF", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("msduHandle", "The handle associated with the MSDU to be transmitted by the MAC sublayer entity", 8, FormatValue(mcpsDataRequest.UserFields.Msduhandle, 8), "", "00", "FF", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("TxOptions", "The 3 bits (b0, b1, b2) indicate the transmission options for this MSDU", 8, FormatValue(mcpsDataRequest.UserFields.Txoptions, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("SecurityLevel", "The security level to be used\r\n\r\n" + SecurityLevelOptionsInfo.SecurityLevelOptionsToDescription(), 8, FormatValue(mcpsDataRequest.UserFields.Securitylevel, 8), SecurityLevelOptionsInfo.SecurityLevelOptionsToString(SecurityLevelOptionsInfo.ValueToSecurityLevelOptions(mcpsDataRequest.UserFields.Securitylevel)), "0", "7", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("KeyIdMode", "The mode used to identify the key to be used. This parameter is ignored if the SecurityLevel parameter is set to 0x00", 8, FormatValue(mcpsDataRequest.UserFields.Keyidmode, 8), "", "0", "3", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("KeySource", "The originator of the key to be used. This parameter is ignored if the KeyIdMode parameter is ignored or set to 0x00", 64, FormatValue(mcpsDataRequest.UserFields.Keysource, 64), "", "", "", settable: true, littleEndianTransport: true, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("KeyIndex", "The index of the key to be used. This parameter is ignored if the KeyIdMode parameter is ignored or set to 0x00", 8, FormatValue(mcpsDataRequest.UserFields.Keyindex, 8), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
		fieldInfoList.Add(new PacketFieldInfo("MSDUData", "MSDU data based on msduLength", mcpsDataRequest.UserFields.MsdudataList.Count * 8, FormatValue(mcpsDataRequest.UserFields.MsdudataList, mcpsDataRequest.UserFields.MsdudataList.Count * 8, includeSpaces: false), "", "", "", settable: true, littleEndianTransport: false, omitFromTransport: false, DataEntryMode.RightAlignedHex));
	}

	public override void UpdatePacketFromFieldInfo(int index, string value)
	{
		McpsDataRequest mcpsDataRequest = (McpsDataRequest)packet;
		int num = -1;
		if (index == ++num)
		{
			mcpsDataRequest.UserFields.Srcaddrmode = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			mcpsDataRequest.UserFields.Dstaddrmode = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			mcpsDataRequest.UserFields.Dstpanid = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			mcpsDataRequest.UserFields.Dstaddr = Convert.ToUInt64(value, 16);
		}
		else if (index == ++num)
		{
			mcpsDataRequest.UserFields.Msdulength = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			mcpsDataRequest.UserFields.Msduhandle = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			mcpsDataRequest.UserFields.Txoptions = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			mcpsDataRequest.UserFields.Securitylevel = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			mcpsDataRequest.UserFields.Keyidmode = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			mcpsDataRequest.UserFields.Keysource = Convert.ToUInt64(value, 16);
		}
		else if (index == ++num)
		{
			mcpsDataRequest.UserFields.Keyindex = Convert.ToUInt32(value, 16);
		}
		else if (index == ++num)
		{
			value = AddLeadingZerosAndCheckValueStringLength(value, mcpsDataRequest.UserFields.MsdudataList.Count);
			int num2 = 0;
			while (value.Length > 0)
			{
				string value2 = value.Substring(0, 2);
				value = value.Remove(0, 2);
				mcpsDataRequest.UserFields.MsdudataList[num2] = Convert.ToUInt32(value2, 16);
				num2++;
			}
		}
	}
}
