using System.Collections.Generic;
using System.Linq;
using QCRPG.TSL.BT.Packets;

namespace QCRPG.TSL.BT;

public class BTLERemoteDeviceInfo
{
	public struct BTRemoteDeviceInfo
	{
		public string bdAddress;

		public PageScanRepetitionModeEnum pageScanRepMode;

		public uint classOfDevice;

		public uint clockOffset;

		public bool dm1enable;

		public bool dm3enable;

		public bool dm5enable;

		public bool dh1enable;

		public bool dh3enable;

		public bool dh5enable;

		public bool twoDH1enable;

		public bool twoDH3enable;

		public bool twoDH5enable;

		public bool threeDH1enable;

		public bool threeDH3enable;

		public bool threeDH5enable;

		public bool allowRoleSwitch;

		public bool lmPerformMSswitch;

		public bool hv1enable;

		public bool hv2enable;

		public bool hv3enable;

		public bool clockOffsetValid;

		public bool levelDefaultEnable;

		public bool levelAuthenticationEnable;

		public bool levelPairingEnable;

		public bool linkKeyASCIIEnable;

		public bool linkKeyHexEnable;

		public string linkKey;

		public bool pinCodeASCIIEnable;

		public bool pinCodeHexEnable;

		public string pinCode;

		public IoCapabilityEnum ioCapability;

		public bool outOfBandDataPresent;

		public bool confirmationRequestReply;

		public bool passkeyRequestReply;

		public bool authenticationRequirements;

		public string oobc;

		public string oobr;

		public string RSSI;

		public int connectionHandler;

		public string MasterSlave;

		public bool askForConnectionRequest;

		public Dictionary<int, object> scoConnections;

		public HciModeChange.UserFieldsWrapper.CurrentModeEnum currentMode;
	}

	public struct LERemoteDeviceInfo
	{
		public uint eventType;

		public uint addressType;

		public string bdAddress;

		public uint dataLength;

		public string data;

		public string RSSI;

		public int connectionHandler;

		public string MasterSlave;

		public string longTermKey;

		public string randomNumber;

		public string encryptedDiversifier;

		public bool keyReply;

		public uint connUpdateIntervalMin;

		public uint connUpdateIntervalMax;

		public uint connUpdateTimeoutMs;

		public uint connUpdateLatency;

		public uint connUpdateCELengthMin;

		public uint connUpdateCELengthMax;

		public bool connUpdateParamRequestAutoReply;

		public uint connUpdateParamReqRejectReason;

		public int cisHandle;
	}

	public List<BTRemoteDeviceInfo> btRemoteDeviceInfo = new List<BTRemoteDeviceInfo>();

	public List<LERemoteDeviceInfo> leRemoteDeviceInfo = new List<LERemoteDeviceInfo>();

	public int defaultConnectionHandle = -99999;

	public BTLERemoteDeviceInfo()
	{
		btRemoteDeviceInfo.Clear();
		leRemoteDeviceInfo.Clear();
	}

	public void UpdateBTRemoteDeviceList(BTRemoteDeviceInfo btRemoteDevice)
	{
		int num = -1;
		foreach (BTRemoteDeviceInfo item in btRemoteDeviceInfo)
		{
			if (item.bdAddress == btRemoteDevice.bdAddress)
			{
				num = btRemoteDeviceInfo.IndexOf(item);
				break;
			}
		}
		if (num != -1)
		{
			btRemoteDeviceInfo.RemoveAt(num);
			btRemoteDeviceInfo.Insert(num, btRemoteDevice);
		}
		else
		{
			btRemoteDeviceInfo.Add(btRemoteDevice);
		}
	}

	public void UpdateBTRemoteDeviceList(string bdAddress, uint pageScanRepMode, uint classOfDevice, uint clockOffset, string RSSI)
	{
		BTRemoteDeviceInfo item = default(BTRemoteDeviceInfo);
		int num = -1;
		foreach (BTRemoteDeviceInfo item2 in btRemoteDeviceInfo)
		{
			if (item2.bdAddress == bdAddress)
			{
				num = btRemoteDeviceInfo.IndexOf(item2);
				break;
			}
		}
		if (num != -1)
		{
			item = btRemoteDeviceInfo.ElementAt(num);
			item.bdAddress = bdAddress;
			item.pageScanRepMode = PageScanRepetitionModeInfo.ValueToPageScanRepetitionMode(pageScanRepMode);
			item.classOfDevice = classOfDevice;
			item.clockOffset = clockOffset;
			if (RSSI != null)
			{
				item.RSSI = RSSI;
			}
			else
			{
				item.RSSI = "Invalid";
			}
			btRemoteDeviceInfo.RemoveAt(num);
			btRemoteDeviceInfo.Insert(num, item);
		}
		else
		{
			item.bdAddress = bdAddress;
			item.pageScanRepMode = PageScanRepetitionModeInfo.ValueToPageScanRepetitionMode(pageScanRepMode);
			item.classOfDevice = classOfDevice;
			item.clockOffset = clockOffset;
			if (RSSI != null)
			{
				item.RSSI = RSSI;
			}
			else
			{
				item.RSSI = "Invalid";
			}
			item.connectionHandler = defaultConnectionHandle;
			btRemoteDeviceInfo.Add(item);
		}
	}

	public bool CheckBTRemoteDeviceInListByBDAddress(string bdAddress)
	{
		foreach (BTRemoteDeviceInfo item in btRemoteDeviceInfo)
		{
			if (item.bdAddress == bdAddress)
			{
				return true;
			}
		}
		return false;
	}

	public bool CheckAndGetBTRemoteDeviceInfoByBDAddress(string bdAddress, out uint packetType, out uint pageScanRepMode, out uint clockOffSet, out bool allowRoleSwitch)
	{
		packetType = 0u;
		pageScanRepMode = 0u;
		clockOffSet = 0u;
		allowRoleSwitch = false;
		foreach (BTRemoteDeviceInfo item in btRemoteDeviceInfo)
		{
			if (item.bdAddress == bdAddress)
			{
				AclPacketTypeEnumCollection aclPacketTypeEnumCollection = new AclPacketTypeEnumCollection();
				aclPacketTypeEnumCollection.Dm1MayBeUsed = (item.dm1enable ? AssertBitEnum.Set : AssertBitEnum.Not_Set);
				aclPacketTypeEnumCollection.Dm3MayBeUsed = (item.dm3enable ? AssertBitEnum.Set : AssertBitEnum.Not_Set);
				aclPacketTypeEnumCollection.Dm5MayBeUsed = (item.dm5enable ? AssertBitEnum.Set : AssertBitEnum.Not_Set);
				aclPacketTypeEnumCollection.Dh1MayBeUsed = (item.dh1enable ? AssertBitEnum.Set : AssertBitEnum.Not_Set);
				aclPacketTypeEnumCollection.Dh3MayBeUsed = (item.dh3enable ? AssertBitEnum.Set : AssertBitEnum.Not_Set);
				aclPacketTypeEnumCollection.Dh5MayBeUsed = (item.dh5enable ? AssertBitEnum.Set : AssertBitEnum.Not_Set);
				aclPacketTypeEnumCollection.TwoDh1MayNotBeUsed = ((!item.twoDH1enable) ? AssertBitEnum.Set : AssertBitEnum.Not_Set);
				aclPacketTypeEnumCollection.TwoDh3MayNotBeUsed = ((!item.twoDH3enable) ? AssertBitEnum.Set : AssertBitEnum.Not_Set);
				aclPacketTypeEnumCollection.TwoDh5MayNotBeUsed = ((!item.twoDH5enable) ? AssertBitEnum.Set : AssertBitEnum.Not_Set);
				aclPacketTypeEnumCollection.ThreeDh1MayNotBeUsed = ((!item.threeDH1enable) ? AssertBitEnum.Set : AssertBitEnum.Not_Set);
				aclPacketTypeEnumCollection.ThreeDh3MayNotBeUsed = ((!item.threeDH3enable) ? AssertBitEnum.Set : AssertBitEnum.Not_Set);
				aclPacketTypeEnumCollection.ThreeDh5MayNotBeUsed = ((!item.threeDH5enable) ? AssertBitEnum.Set : AssertBitEnum.Not_Set);
				packetType = AclPacketTypeInfo.AclPacketTypeToValue(aclPacketTypeEnumCollection);
				pageScanRepMode = PageScanRepetitionModeInfo.PageScanRepetitionModeToValue(item.pageScanRepMode);
				ClockOffsetEnumCollection clockOffsetEnumCollection = new ClockOffsetEnumCollection();
				clockOffsetEnumCollection.Bits162OfClknslaveClk = item.clockOffset;
				clockOffsetEnumCollection.ClockOffsetValidFlag = (item.clockOffsetValid ? ClockOffsetEnumCollection.ClockOffsetValidFlagEnum.Valid_Clock_Offset : ClockOffsetEnumCollection.ClockOffsetValidFlagEnum.Invalid_Clock_Offset);
				clockOffSet = ClockOffsetInfo.ClockOffsetToValue(clockOffsetEnumCollection);
				allowRoleSwitch = item.allowRoleSwitch;
				return true;
			}
		}
		return false;
	}

	public void CheckAndGetBTRemoteDeviceRSSIByBDAddress(string bdAddress, out string RSSI)
	{
		RSSI = "Invalid Rssi Value";
		foreach (BTRemoteDeviceInfo item in btRemoteDeviceInfo)
		{
			if (item.bdAddress == bdAddress)
			{
				RSSI = item.RSSI;
			}
		}
	}

	public bool CheckAndGetBTRemoteDeviceInfoByBDAddress(string bdAddress, out BTRemoteDeviceInfo btRemoteDevice)
	{
		foreach (BTRemoteDeviceInfo item in btRemoteDeviceInfo)
		{
			if (item.bdAddress == bdAddress)
			{
				btRemoteDevice = item;
				return true;
			}
		}
		btRemoteDevice = default(BTRemoteDeviceInfo);
		return false;
	}

	public bool CheckAndGetBTRemoteDeviceLMPerformMSSwitchByBDAddress(string bdAddress, out bool lmPerformMSswitch)
	{
		lmPerformMSswitch = false;
		foreach (BTRemoteDeviceInfo item in btRemoteDeviceInfo)
		{
			if (item.bdAddress == bdAddress)
			{
				lmPerformMSswitch = item.lmPerformMSswitch;
				return true;
			}
		}
		return false;
	}

	public void UpdateBTRemoteDeviceConnectionHandler(string bdAddress, int connectionHandler)
	{
		BTRemoteDeviceInfo item = default(BTRemoteDeviceInfo);
		int num = -1;
		foreach (BTRemoteDeviceInfo item2 in btRemoteDeviceInfo)
		{
			if (item2.bdAddress == bdAddress)
			{
				num = btRemoteDeviceInfo.IndexOf(item2);
				break;
			}
		}
		if (num != -1)
		{
			item = btRemoteDeviceInfo.ElementAt(num);
			item.connectionHandler = connectionHandler;
			btRemoteDeviceInfo.RemoveAt(num);
			btRemoteDeviceInfo.Insert(num, item);
		}
		else
		{
			item.bdAddress = bdAddress;
			item.connectionHandler = connectionHandler;
			item.RSSI = "Invalid Rssi Value";
			btRemoteDeviceInfo.Add(item);
		}
	}

	public int GetBTRemoteDeviceConnectionHandlerByBDAddress(string bdAddress)
	{
		foreach (BTRemoteDeviceInfo item in btRemoteDeviceInfo)
		{
			if (item.bdAddress == bdAddress)
			{
				return item.connectionHandler;
			}
		}
		return defaultConnectionHandle;
	}

	public void RemoveBTRemoteDeviceConnectionHandler(int connectionHandler)
	{
		BTRemoteDeviceInfo bTRemoteDeviceInfo = default(BTRemoteDeviceInfo);
		int num = -1;
		foreach (BTRemoteDeviceInfo item in btRemoteDeviceInfo)
		{
			if (item.connectionHandler == connectionHandler)
			{
				num = btRemoteDeviceInfo.IndexOf(item);
				break;
			}
		}
		if (num != -1)
		{
			bTRemoteDeviceInfo = btRemoteDeviceInfo.ElementAt(num);
			bTRemoteDeviceInfo.connectionHandler = defaultConnectionHandle;
			btRemoteDeviceInfo.RemoveAt(num);
			btRemoteDeviceInfo.Insert(num, bTRemoteDeviceInfo);
		}
	}

	public void RemoveBTRemoteDeviceSCOConnectionHandler(int scoConnectionHandler)
	{
		BTRemoteDeviceInfo bTRemoteDeviceInfo = default(BTRemoteDeviceInfo);
		int num = -1;
		foreach (BTRemoteDeviceInfo item in btRemoteDeviceInfo)
		{
			if (item.scoConnections != null && item.scoConnections.ContainsKey(scoConnectionHandler))
			{
				num = btRemoteDeviceInfo.IndexOf(item);
				break;
			}
		}
		if (num != -1)
		{
			bTRemoteDeviceInfo = btRemoteDeviceInfo.ElementAt(num);
			bTRemoteDeviceInfo.scoConnections.Remove(scoConnectionHandler);
			btRemoteDeviceInfo.RemoveAt(num);
			btRemoteDeviceInfo.Insert(num, bTRemoteDeviceInfo);
		}
	}

	public string GetBTRemoteDeviceBDAddressByConnectionHandler(int connectionHandler)
	{
		foreach (BTRemoteDeviceInfo item in btRemoteDeviceInfo)
		{
			if (item.connectionHandler == connectionHandler)
			{
				return item.bdAddress;
			}
		}
		return null;
	}

	public string GetBTRemoteDeviceBDAddressByScoConnectionHandler(int scoConnectionHandler)
	{
		foreach (BTRemoteDeviceInfo item in btRemoteDeviceInfo)
		{
			if (item.scoConnections != null && item.scoConnections.ContainsKey(scoConnectionHandler))
			{
				return item.bdAddress;
			}
		}
		return null;
	}

	public bool CheckAndGetBTRemoteDeviceScoPacketTypeByBDAddress(string bdAddress, out uint packetType, out int connectionHandle)
	{
		packetType = 0u;
		connectionHandle = 0;
		foreach (BTRemoteDeviceInfo item in btRemoteDeviceInfo)
		{
			if (item.bdAddress == bdAddress)
			{
				SynchronousPacketTypeEnumCollection synchronousPacketTypeEnumCollection = new SynchronousPacketTypeEnumCollection();
				synchronousPacketTypeEnumCollection.Hv1 = (item.hv1enable ? AssertBitEnum.Set : AssertBitEnum.Not_Set);
				synchronousPacketTypeEnumCollection.Hv2 = (item.hv2enable ? AssertBitEnum.Set : AssertBitEnum.Not_Set);
				synchronousPacketTypeEnumCollection.Hv3 = (item.hv3enable ? AssertBitEnum.Set : AssertBitEnum.Not_Set);
				packetType = SynchronousPacketTypeInfo.SynchronousPacketTypeToValue(synchronousPacketTypeEnumCollection);
				connectionHandle = item.connectionHandler;
				return true;
			}
		}
		return false;
	}

	public void UpdateBTRemoteDeviceRoleByBDAddress(string bdAddress, string masterSlave)
	{
		BTRemoteDeviceInfo item = default(BTRemoteDeviceInfo);
		int num = -1;
		foreach (BTRemoteDeviceInfo item2 in btRemoteDeviceInfo)
		{
			if (item2.bdAddress == bdAddress)
			{
				num = btRemoteDeviceInfo.IndexOf(item2);
				break;
			}
		}
		if (num != -1)
		{
			item = btRemoteDeviceInfo.ElementAt(num);
			item.MasterSlave = masterSlave;
			btRemoteDeviceInfo.RemoveAt(num);
			btRemoteDeviceInfo.Insert(num, item);
		}
		else
		{
			item.bdAddress = bdAddress;
			item.MasterSlave = masterSlave;
			item.RSSI = "Invalid Rssi Value";
			btRemoteDeviceInfo.Add(item);
		}
	}

	public void UpdateBTRemoteDeviceHCIModeByBDAddress(string bdAddress, HciModeChange.UserFieldsWrapper.CurrentModeEnum hciMode)
	{
		BTRemoteDeviceInfo bTRemoteDeviceInfo = default(BTRemoteDeviceInfo);
		int num = -1;
		foreach (BTRemoteDeviceInfo item in btRemoteDeviceInfo)
		{
			if (item.bdAddress == bdAddress)
			{
				num = btRemoteDeviceInfo.IndexOf(item);
				break;
			}
		}
		if (num != -1)
		{
			bTRemoteDeviceInfo = btRemoteDeviceInfo.ElementAt(num);
			bTRemoteDeviceInfo.currentMode = hciMode;
			btRemoteDeviceInfo.RemoveAt(num);
			btRemoteDeviceInfo.Insert(num, bTRemoteDeviceInfo);
		}
	}

	public void CheckAndGetBTRemoteDeviceRoleByBDAddress(string bdAddress, out string masterSlave)
	{
		masterSlave = "S";
		foreach (BTRemoteDeviceInfo item in btRemoteDeviceInfo)
		{
			if (item.bdAddress == bdAddress)
			{
				masterSlave = item.MasterSlave;
			}
		}
		if (masterSlave == null || masterSlave == "")
		{
			masterSlave = "S";
		}
	}

	public void UpdateBTRemoteDeviceConnectionRequestByBDAddress(string bdAddress, bool askForConnectionRequest)
	{
		BTRemoteDeviceInfo item = default(BTRemoteDeviceInfo);
		int num = -1;
		foreach (BTRemoteDeviceInfo item2 in btRemoteDeviceInfo)
		{
			if (item2.bdAddress == bdAddress)
			{
				num = btRemoteDeviceInfo.IndexOf(item2);
				break;
			}
		}
		if (num != -1)
		{
			item = btRemoteDeviceInfo.ElementAt(num);
			item.askForConnectionRequest = askForConnectionRequest;
			btRemoteDeviceInfo.RemoveAt(num);
			btRemoteDeviceInfo.Insert(num, item);
		}
		else
		{
			item.bdAddress = bdAddress;
			item.askForConnectionRequest = askForConnectionRequest;
			item.RSSI = "Invalid Rssi Value";
			btRemoteDeviceInfo.Add(item);
		}
	}

	public void CheckAndGetBTRemoteDeviceConnectionRequestByBDAddress(string bdAddress, out bool askForConnectionRequest, out uint packetType)
	{
		askForConnectionRequest = false;
		packetType = 0u;
		foreach (BTRemoteDeviceInfo item in btRemoteDeviceInfo)
		{
			if (item.bdAddress == bdAddress)
			{
				askForConnectionRequest = item.askForConnectionRequest;
				AclPacketTypeEnumCollection aclPacketTypeEnumCollection = new AclPacketTypeEnumCollection();
				aclPacketTypeEnumCollection.Dm1MayBeUsed = (item.dm1enable ? AssertBitEnum.Set : AssertBitEnum.Not_Set);
				aclPacketTypeEnumCollection.Dm3MayBeUsed = (item.dm3enable ? AssertBitEnum.Set : AssertBitEnum.Not_Set);
				aclPacketTypeEnumCollection.Dm5MayBeUsed = (item.dm5enable ? AssertBitEnum.Set : AssertBitEnum.Not_Set);
				aclPacketTypeEnumCollection.Dh1MayBeUsed = (item.dh1enable ? AssertBitEnum.Set : AssertBitEnum.Not_Set);
				aclPacketTypeEnumCollection.Dh3MayBeUsed = (item.dh3enable ? AssertBitEnum.Set : AssertBitEnum.Not_Set);
				aclPacketTypeEnumCollection.Dh5MayBeUsed = (item.dh5enable ? AssertBitEnum.Set : AssertBitEnum.Not_Set);
				aclPacketTypeEnumCollection.TwoDh1MayNotBeUsed = ((!item.twoDH1enable) ? AssertBitEnum.Set : AssertBitEnum.Not_Set);
				aclPacketTypeEnumCollection.TwoDh3MayNotBeUsed = ((!item.twoDH3enable) ? AssertBitEnum.Set : AssertBitEnum.Not_Set);
				aclPacketTypeEnumCollection.TwoDh5MayNotBeUsed = ((!item.twoDH5enable) ? AssertBitEnum.Set : AssertBitEnum.Not_Set);
				aclPacketTypeEnumCollection.ThreeDh1MayNotBeUsed = ((!item.threeDH1enable) ? AssertBitEnum.Set : AssertBitEnum.Not_Set);
				aclPacketTypeEnumCollection.ThreeDh3MayNotBeUsed = ((!item.threeDH3enable) ? AssertBitEnum.Set : AssertBitEnum.Not_Set);
				aclPacketTypeEnumCollection.ThreeDh5MayNotBeUsed = ((!item.threeDH5enable) ? AssertBitEnum.Set : AssertBitEnum.Not_Set);
				packetType = AclPacketTypeInfo.AclPacketTypeToValue(aclPacketTypeEnumCollection);
			}
		}
	}

	public void RemoveBTRemoteDeviceByBDAddress(string bdAddress)
	{
		foreach (BTRemoteDeviceInfo item in btRemoteDeviceInfo)
		{
			if (item.bdAddress == bdAddress)
			{
				btRemoteDeviceInfo.Remove(item);
				break;
			}
		}
	}

	public void UpdateBTRemoteDeviceSCOConnectionHandler(string bdAddress, int scoConnectionHandler, object packetType)
	{
		BTRemoteDeviceInfo bTRemoteDeviceInfo = default(BTRemoteDeviceInfo);
		int num = -1;
		foreach (BTRemoteDeviceInfo item in btRemoteDeviceInfo)
		{
			if (item.bdAddress == bdAddress)
			{
				num = btRemoteDeviceInfo.IndexOf(item);
				break;
			}
		}
		if (num != -1)
		{
			bTRemoteDeviceInfo = btRemoteDeviceInfo.ElementAt(num);
			if (bTRemoteDeviceInfo.scoConnections == null)
			{
				bTRemoteDeviceInfo.scoConnections = new Dictionary<int, object>();
				bTRemoteDeviceInfo.scoConnections.Add(scoConnectionHandler, packetType);
			}
			else if (bTRemoteDeviceInfo.scoConnections.ContainsKey(scoConnectionHandler))
			{
				bTRemoteDeviceInfo.scoConnections[scoConnectionHandler] = packetType;
			}
			else
			{
				bTRemoteDeviceInfo.scoConnections.Add(scoConnectionHandler, packetType);
			}
			btRemoteDeviceInfo.RemoveAt(num);
			btRemoteDeviceInfo.Insert(num, bTRemoteDeviceInfo);
		}
	}

	public object CheckAndGetBTRemoteDeviceScoPacketTypeByConnectionHandle(int scoConnectionHandle)
	{
		foreach (BTRemoteDeviceInfo item in btRemoteDeviceInfo)
		{
			if (item.scoConnections != null && item.scoConnections.ContainsKey(scoConnectionHandle))
			{
				return item.scoConnections[scoConnectionHandle];
			}
		}
		return null;
	}

	public void UpdateBTRemoteDeviceIOCapability(string bdAddress, IoCapabilityEnum ioCapability)
	{
		int num = -1;
		foreach (BTRemoteDeviceInfo item2 in btRemoteDeviceInfo)
		{
			if (item2.bdAddress == bdAddress)
			{
				num = btRemoteDeviceInfo.IndexOf(item2);
				break;
			}
		}
		if (num != -1)
		{
			BTRemoteDeviceInfo item = btRemoteDeviceInfo.ElementAt(num);
			item.ioCapability = ioCapability;
			btRemoteDeviceInfo.RemoveAt(num);
			btRemoteDeviceInfo.Insert(num, item);
		}
	}

	public bool CheckAndGetBTRemoteDeviceIOCapabilityByBDAddress(string bdAddress, out IoCapabilityEnum ioCapability, out bool outOfBandDataPresent, out bool authenticationRequirements)
	{
		ioCapability = IoCapabilityEnum.DisplayOnly;
		outOfBandDataPresent = false;
		authenticationRequirements = false;
		foreach (BTRemoteDeviceInfo item in btRemoteDeviceInfo)
		{
			if (item.bdAddress == bdAddress)
			{
				ioCapability = item.ioCapability;
				outOfBandDataPresent = item.outOfBandDataPresent;
				authenticationRequirements = item.authenticationRequirements;
				return true;
			}
		}
		return false;
	}

	public void UpdateBTRemoteDeviceLinkKey(string bdAddress, string linkKey)
	{
		int num = -1;
		foreach (BTRemoteDeviceInfo item2 in btRemoteDeviceInfo)
		{
			if (item2.bdAddress == bdAddress)
			{
				num = btRemoteDeviceInfo.IndexOf(item2);
				break;
			}
		}
		if (num != -1)
		{
			BTRemoteDeviceInfo item = btRemoteDeviceInfo.ElementAt(num);
			item.linkKey = linkKey;
			btRemoteDeviceInfo.RemoveAt(num);
			btRemoteDeviceInfo.Insert(num, item);
		}
	}

	public bool CheckAndGetBTRemoteDeviceLinkKeyByBDAddress(string bdAddress, out bool levelAuthenticationEnable, out string linkKey)
	{
		levelAuthenticationEnable = false;
		linkKey = "";
		foreach (BTRemoteDeviceInfo item in btRemoteDeviceInfo)
		{
			if (item.bdAddress == bdAddress)
			{
				levelAuthenticationEnable = item.levelAuthenticationEnable;
				linkKey = item.linkKey;
				return true;
			}
		}
		return false;
	}

	public bool CheckAndGetBTRemoteDevicePinCodeByBDAddress(string bdAddress, out bool levelPairingEnable, out string pinCode)
	{
		levelPairingEnable = false;
		pinCode = "";
		foreach (BTRemoteDeviceInfo item in btRemoteDeviceInfo)
		{
			if (item.bdAddress == bdAddress)
			{
				levelPairingEnable = item.levelPairingEnable;
				pinCode = item.pinCode;
				return true;
			}
		}
		return false;
	}

	public bool CheckAndGetBTRemoteDeviceConfirmationRequestReplyByBDAddress(string bdAddress, out bool confirmationRequestReply)
	{
		confirmationRequestReply = false;
		foreach (BTRemoteDeviceInfo item in btRemoteDeviceInfo)
		{
			if (item.bdAddress == bdAddress)
			{
				confirmationRequestReply = item.confirmationRequestReply;
				return true;
			}
		}
		return false;
	}

	public bool CheckAndGetBTRemoteDevicePasskeyRequestReplyByBDAddress(string bdAddress, out bool passkeyRequestReply)
	{
		passkeyRequestReply = false;
		foreach (BTRemoteDeviceInfo item in btRemoteDeviceInfo)
		{
			if (item.bdAddress == bdAddress)
			{
				passkeyRequestReply = item.passkeyRequestReply;
				return true;
			}
		}
		return false;
	}

	public bool CheckAndGetBTRemoteDeviceOOBDataByBDAddress(string bdAddress, out string oobc, out string oobr)
	{
		oobc = "";
		oobr = "";
		foreach (BTRemoteDeviceInfo item in btRemoteDeviceInfo)
		{
			if (item.bdAddress == bdAddress)
			{
				oobc = item.oobc;
				oobr = item.oobr;
				return true;
			}
		}
		return false;
	}

	public void UpdateLERemoteDeviceList(LERemoteDeviceInfo leRemoteDevice)
	{
		int num = -1;
		lock (leRemoteDeviceInfo)
		{
			foreach (LERemoteDeviceInfo item in leRemoteDeviceInfo)
			{
				if (item.bdAddress == leRemoteDevice.bdAddress)
				{
					num = leRemoteDeviceInfo.IndexOf(item);
					break;
				}
			}
			if (num != -1)
			{
				leRemoteDeviceInfo.RemoveAt(num);
				leRemoteDeviceInfo.Insert(num, leRemoteDevice);
			}
			else
			{
				leRemoteDeviceInfo.Add(leRemoteDevice);
			}
		}
	}

	public bool CheckAndGetLERemoteDeviceInfoByBDAddress(string bdAddress, out LERemoteDeviceInfo leRemoteDevice)
	{
		lock (leRemoteDeviceInfo)
		{
			foreach (LERemoteDeviceInfo item in leRemoteDeviceInfo)
			{
				if (item.bdAddress == bdAddress)
				{
					leRemoteDevice = item;
					return true;
				}
			}
		}
		leRemoteDevice = default(LERemoteDeviceInfo);
		return false;
	}

	public void UpdateLERemoteDeviceList(string bdAddress, uint addressType, string RSSI)
	{
		LERemoteDeviceInfo item = default(LERemoteDeviceInfo);
		item.connectionHandler = defaultConnectionHandle;
		int num = -1;
		lock (leRemoteDeviceInfo)
		{
			foreach (LERemoteDeviceInfo item2 in leRemoteDeviceInfo)
			{
				if (item2.bdAddress == bdAddress)
				{
					num = leRemoteDeviceInfo.IndexOf(item2);
					break;
				}
			}
			if (num != -1)
			{
				item = leRemoteDeviceInfo.ElementAt(num);
				item.bdAddress = bdAddress;
				item.addressType = addressType;
				item.RSSI = RSSI;
				leRemoteDeviceInfo.RemoveAt(num);
				leRemoteDeviceInfo.Insert(num, item);
			}
			else
			{
				item.bdAddress = bdAddress;
				item.addressType = addressType;
				item.RSSI = RSSI;
				leRemoteDeviceInfo.Add(item);
			}
		}
	}

	public uint GetLERemoteDeviceAddressTypeByBDAddress(string bdAddress)
	{
		lock (leRemoteDeviceInfo)
		{
			foreach (LERemoteDeviceInfo item in leRemoteDeviceInfo)
			{
				if (item.bdAddress == bdAddress)
				{
					return item.addressType;
				}
			}
		}
		return 2u;
	}

	public void UpdateLERemoteDeviceConnectionHandler(string bdAddress, int connectionHandler)
	{
		LERemoteDeviceInfo item = default(LERemoteDeviceInfo);
		int num = -1;
		lock (leRemoteDeviceInfo)
		{
			foreach (LERemoteDeviceInfo item2 in leRemoteDeviceInfo)
			{
				if (item2.bdAddress == bdAddress)
				{
					num = leRemoteDeviceInfo.IndexOf(item2);
					break;
				}
			}
			if (num != -1)
			{
				item = leRemoteDeviceInfo.ElementAt(num);
				item.connectionHandler = connectionHandler;
				leRemoteDeviceInfo.RemoveAt(num);
				leRemoteDeviceInfo.Insert(num, item);
			}
			else
			{
				item.bdAddress = bdAddress;
				item.connectionHandler = connectionHandler;
				item.RSSI = "Invalid Rssi Value";
				leRemoteDeviceInfo.Add(item);
			}
		}
	}

	public void UpdateLERemoteDeviceListRSSI(int connectionHandler, string RSSI, out string bdAddress)
	{
		bdAddress = "";
		LERemoteDeviceInfo item = default(LERemoteDeviceInfo);
		int num = -1;
		lock (leRemoteDeviceInfo)
		{
			foreach (LERemoteDeviceInfo item2 in leRemoteDeviceInfo)
			{
				if (item2.connectionHandler == connectionHandler)
				{
					num = leRemoteDeviceInfo.IndexOf(item2);
					break;
				}
			}
			if (num != -1)
			{
				item = leRemoteDeviceInfo.ElementAt(num);
				item.RSSI = RSSI;
				leRemoteDeviceInfo.RemoveAt(num);
				leRemoteDeviceInfo.Insert(num, item);
				bdAddress = item.bdAddress;
			}
			else
			{
				item.connectionHandler = connectionHandler;
				item.RSSI = "Invalid Rssi Value";
				leRemoteDeviceInfo.Add(item);
			}
		}
	}

	public void RemoveLERemoteDeviceCisHandle(int cisHandle)
	{
		LERemoteDeviceInfo lERemoteDeviceInfo = default(LERemoteDeviceInfo);
		int num = -1;
		lock (leRemoteDeviceInfo)
		{
			foreach (LERemoteDeviceInfo item in leRemoteDeviceInfo)
			{
				if (item.cisHandle == cisHandle)
				{
					num = leRemoteDeviceInfo.IndexOf(item);
					break;
				}
			}
			if (num != -1)
			{
				lERemoteDeviceInfo = leRemoteDeviceInfo.ElementAt(num);
				lERemoteDeviceInfo.cisHandle = 0;
				leRemoteDeviceInfo.RemoveAt(num);
				leRemoteDeviceInfo.Insert(num, lERemoteDeviceInfo);
			}
		}
	}

	public void UpdateLERemoteDeviceCisHandleByBTConnectionHandler(int connectionHandler, int cisHandle)
	{
		LERemoteDeviceInfo lERemoteDeviceInfo = default(LERemoteDeviceInfo);
		int num = -1;
		lock (leRemoteDeviceInfo)
		{
			foreach (LERemoteDeviceInfo item in leRemoteDeviceInfo)
			{
				if (item.connectionHandler == connectionHandler)
				{
					num = leRemoteDeviceInfo.IndexOf(item);
					break;
				}
			}
			if (num != -1)
			{
				lERemoteDeviceInfo = leRemoteDeviceInfo.ElementAt(num);
				lERemoteDeviceInfo.cisHandle = cisHandle;
				leRemoteDeviceInfo.RemoveAt(num);
				leRemoteDeviceInfo.Insert(num, lERemoteDeviceInfo);
			}
		}
	}

	public void CheckAndGetLERemoteDeviceRSSIByBDAddress(string bdAddress, out string RSSI)
	{
		RSSI = "Invalid Rssi Value";
		lock (leRemoteDeviceInfo)
		{
			foreach (LERemoteDeviceInfo item in leRemoteDeviceInfo)
			{
				if (item.bdAddress == bdAddress)
				{
					RSSI = item.RSSI;
				}
			}
		}
	}

	public void CheckAndGetLERemoteDeviceRoleByBDAddress(string bdAddress, out string masterSlave)
	{
		masterSlave = "S";
		lock (leRemoteDeviceInfo)
		{
			foreach (LERemoteDeviceInfo item in leRemoteDeviceInfo)
			{
				if (item.bdAddress == bdAddress)
				{
					masterSlave = item.MasterSlave;
				}
			}
			if (masterSlave == null)
			{
				masterSlave = "S";
			}
		}
	}

	public string GetLERemoteDeviceBDAddressByConnectionHandler(int connectionHandler)
	{
		lock (leRemoteDeviceInfo)
		{
			foreach (LERemoteDeviceInfo item in leRemoteDeviceInfo)
			{
				if (item.connectionHandler == connectionHandler)
				{
					return item.bdAddress;
				}
			}
		}
		return null;
	}

	public void RemoveLERemoteDeviceConnectionHandler(int connectionHandler)
	{
		LERemoteDeviceInfo lERemoteDeviceInfo = default(LERemoteDeviceInfo);
		int num = -1;
		lock (leRemoteDeviceInfo)
		{
			foreach (LERemoteDeviceInfo item in leRemoteDeviceInfo)
			{
				if (item.connectionHandler == connectionHandler)
				{
					num = leRemoteDeviceInfo.IndexOf(item);
					break;
				}
			}
			if (num != -1)
			{
				lERemoteDeviceInfo = leRemoteDeviceInfo.ElementAt(num);
				lERemoteDeviceInfo.connectionHandler = defaultConnectionHandle;
				leRemoteDeviceInfo.RemoveAt(num);
				leRemoteDeviceInfo.Insert(num, lERemoteDeviceInfo);
			}
		}
	}

	public void UpdateLERemoteDeviceRoleByBDAddress(string bdAddress, string masterSlave)
	{
		LERemoteDeviceInfo item = default(LERemoteDeviceInfo);
		int num = -1;
		lock (leRemoteDeviceInfo)
		{
			foreach (LERemoteDeviceInfo item2 in leRemoteDeviceInfo)
			{
				if (item2.bdAddress == bdAddress)
				{
					num = leRemoteDeviceInfo.IndexOf(item2);
					break;
				}
			}
			if (num != -1)
			{
				item = leRemoteDeviceInfo.ElementAt(num);
				item.MasterSlave = masterSlave;
				leRemoteDeviceInfo.RemoveAt(num);
				leRemoteDeviceInfo.Insert(num, item);
			}
			else
			{
				item.bdAddress = bdAddress;
				item.MasterSlave = masterSlave;
				item.RSSI = "Invalid Rssi Value";
				leRemoteDeviceInfo.Add(item);
			}
		}
	}

	public int GetLERemoteDeviceConnectionHandlerByBDAddress(string bdAddress)
	{
		lock (leRemoteDeviceInfo)
		{
			foreach (LERemoteDeviceInfo item in leRemoteDeviceInfo)
			{
				if (item.bdAddress == bdAddress)
				{
					return item.connectionHandler;
				}
			}
		}
		return 0;
	}

	public int GetLERemoteDeviceCisHandleByBDAddress(string bdAddress)
	{
		lock (leRemoteDeviceInfo)
		{
			foreach (LERemoteDeviceInfo item in leRemoteDeviceInfo)
			{
				if (item.bdAddress == bdAddress)
				{
					return item.cisHandle;
				}
			}
		}
		return 0;
	}

	public bool CheckAndGetLERemoteDeviceLinkKeyByConnectionHandle(int connectionHandle, out string longTermKey, out string randomNumber, out string encryptedDiversifier, out bool keyReply)
	{
		longTermKey = "";
		randomNumber = "";
		encryptedDiversifier = "";
		keyReply = false;
		lock (leRemoteDeviceInfo)
		{
			foreach (LERemoteDeviceInfo item in leRemoteDeviceInfo)
			{
				if (item.connectionHandler == connectionHandle)
				{
					longTermKey = item.longTermKey;
					randomNumber = item.randomNumber;
					encryptedDiversifier = item.encryptedDiversifier;
					keyReply = item.keyReply;
					return true;
				}
			}
		}
		return false;
	}

	public bool CheckAndGetLERemoteDeviceConnectionUpdateByConnectionHandle(int connectionHandle, out uint intervalMin, out uint intervalMax, out uint timeoutMs, out uint latency, out uint ceLengthMin, out uint ceLengthMax, out bool keyReply, out uint paramRejectReason)
	{
		intervalMin = 0u;
		intervalMax = 0u;
		timeoutMs = 0u;
		latency = 0u;
		ceLengthMin = 0u;
		ceLengthMax = 0u;
		keyReply = true;
		paramRejectReason = 0u;
		lock (leRemoteDeviceInfo)
		{
			foreach (LERemoteDeviceInfo item in leRemoteDeviceInfo)
			{
				if (item.connectionHandler == connectionHandle)
				{
					intervalMin = item.connUpdateIntervalMin;
					intervalMax = item.connUpdateIntervalMax;
					timeoutMs = item.connUpdateTimeoutMs;
					latency = item.connUpdateLatency;
					ceLengthMin = item.connUpdateCELengthMin;
					ceLengthMax = item.connUpdateCELengthMax;
					keyReply = item.connUpdateParamRequestAutoReply;
					paramRejectReason = item.connUpdateParamReqRejectReason;
					return true;
				}
			}
		}
		return false;
	}

	public void RemoveLERemoteDeviceByBDAddress(string bdAddress)
	{
		lock (leRemoteDeviceInfo)
		{
			foreach (LERemoteDeviceInfo item in leRemoteDeviceInfo)
			{
				if (item.bdAddress == bdAddress)
				{
					leRemoteDeviceInfo.Remove(item);
					break;
				}
			}
		}
	}
}
