using System;
using System.Collections.Generic;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.IO.Ports;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading;
using System.Timers;
using System.Windows.Forms;
using QC.QMSLPhone;
using QCRPG.Framework;
using QCRPG.TSL.BT.Packets;
using QCRPG.TSL.BT.Properties;

namespace QCRPG.TSL.BT;

public class BTGooier : GooierBase, QCRPG.Framework.IObserver<ConnectionStateChangeInfo>, IConfigurable
{
	private struct LV_ITEM
	{
		public uint uiMask;

		public int iItem;

		public int iSubItem;

		public uint uiState;

		public uint uiStateMask;

		public string pszText;

		public int cchTextMax;

		public int iImage;

		public IntPtr lParam;

		public int iIndent;
	}

	protected enum ControlEnableMode
	{
		DEFAULT,
		CONNECTION_OPENED,
		CONNECTION_CLOSED
	}

	public struct leRemoteInfo
	{
		public ListViewItem remoteDeviceItem;

		public uint addrType;

		public string rssi;
	}

	public const int LVM_FIRST = 4096;

	public const int LVM_SETITEM = 4102;

	public const int LVIF_IMAGE = 2;

	public const int LVIF_INDENT = 16;

	public const int LVW_FIRST = 4096;

	public const int LVM_SETEXTENDEDLISTVIEWSTYLE = 4150;

	public const int LVM_GETEXTENDEDLISTVIEWSTYLE = 4151;

	public const int LVS_EX_SUBITEMIMAGES = 2;

	protected const string menuTextOpenConnection = "Open Connection";

	protected const string menuTextCloseConnection = "Close Connection";

	protected const string menuTextLoadDefaultNVMFile = "Load NVM File";

	protected const string menuTextLoadDefaultPatchFile = "Load Patch File";

	protected const string menuTextLoadDefaultScriptFile = "Load Script File";

	protected const string menuTextEnableBTSnoopLogs = "Enable BT Snoop Logs";

	protected const string menuTextSaveBTSnoopLogs = "Save BT Snoop Logs";

	protected const string menuTextClearBTSnoopLogs = "Reset/Clear BT Snoop Logs";

	protected const string menuTextBTSnoopLiveLoggingConfig = "BT Snoop Live Import Config...";

	protected const string menuTextEnableBTSnoopLiveLogging = "Enable BT Snoop Live Logs";

	protected const string menuTextEnhancedLog = "Enhanced Logging";

	protected const string menuTextDisplayEnhLog = "Enable display";

	protected const string menuTextLiveImport = "Live Import";

	protected const string menuTextBTSnoopLogs = "BT Snoop Logs";

	protected const string menuTextStaticSnoopLogs = "Log to file";

	protected const string menuTextAclDataView = "ACL Data View";

	protected const string menuTextDisplayFullAclData = "Display ACL Data";

	protected const string menuTextDisplaySummaryAclData = "Display Summary ACL Data";

	protected const string menuTextHideAclData = "Hide ACL Data";

	protected const string menuTextFullAclDataLogToFile = "Full ACL Data to Log";

	protected const string menuTextSetDecodePacket = "Decode Packet";

	protected const string menuTextStartupCommand = "Run Init Commands at Startup";

	protected const string menuTextStartupCommandLEOnly = "(BLE only target) Run Init Commands at Startup";

	protected const string menuTextResetPacketCounter = "Reset Packet Counter";

	protected const string menuTextScanEnable = "Scan Enable...";

	protected const string menuTextDutMode = "Enable DUT Mode";

	protected const string menuTextOptions = "Options";

	protected const string menuTextBTOptions = "Bluetooth Options...";

	protected const string menuTextLEOptions = "LE Options...";

	private const string FilterWildcard = "FF";

	private const string cisIDString = "CIS ID ";

	private const string cigIDString = "CIG ID ";

	protected Configurer configurer;

	protected BTAPI btAPI;

	protected PacketListBase packetList;

	protected PacketUserControl packetUserControl;

	protected DeviceListViewUserControl btListViewUserControl;

	protected BTMainWorkerThread btMainWorkerThread;

	protected readonly ToolStripMenuItem enhancedLogMenu = new ToolStripMenuItem("Enhanced Logging");

	protected readonly ToolStripMenuItem snoopLiveImportMenu = new ToolStripMenuItem("Live Import");

	protected readonly ToolStripMenuItem snoopLogsMenu = new ToolStripMenuItem("BT Snoop Logs");

	protected readonly ToolStripMenuItem snoopStaticLogsMenu = new ToolStripMenuItem("Log to file");

	protected readonly ToolStripMenuItem aclLogMenu = new ToolStripMenuItem("ACL Data View");

	protected ToolStripButton toolStripButtonOpenConnection;

	protected ToolStripButton toolStripButtonCloseConnection;

	protected ToolStripButton toolStripButtonLoadDefaultNvm;

	protected ToolStripButton toolStripButtonLoadNvm;

	protected ToolStripButton toolStripButtonLoadDefaultPatch;

	protected ToolStripButton toolStripButtonLoadPatch;

	protected ToolStripButton toolStripButtonPageScan;

	protected ToolStripButton toolStripButtonInquiryScan;

	protected ToolStripButton toolStripButtonInquiry;

	protected ToolStripButton toolStripButtonFileTransfer;

	protected ToolStripButton toolStripButtonDataTransfer;

	protected ToolStripButton ToolStripButtonHCIReset;

	protected ToolStripButton ToolStripButtonBringUp;

	protected ToolStripButton toolStripButtonLEAdvertising;

	protected ToolStripButton toolStripButtonLEScan;

	protected OpenConnectionMultipleTypesForm openConnectionMultipleTypesForm = new OpenConnectionMultipleTypesForm();

	protected BTConfigUserControl btConfigUserControl;

	protected BTSendRawBytesUserControl btSendRawBytesUserControl;

	protected BTConfigSettings btConfigSettings;

	protected BTScriptUserControl btScriptUserControl;

	protected DataTransferUserControlSelector btDataTransferUserControl;

	protected SCOoverHCIUserControl scoOverHciUserControl;

	protected bool deviceEmulationMode;

	protected DeviceEmulationModeUserControl deviceEmulationModeUserControl;

	protected DeviceEmulationModeConfigSettings deviceEmulationModeConfigSettings;

	protected PacketAutoResponder packetAutoResponder;

	protected ToolStripStatusLabel toolStripStatusLabelCisHandle;

	protected ToolStripStatusLabel toolStripStatusLabelEmpty;

	protected ToolStripStatusLabel toolStripStatusLabelPacketInfo;

	protected ToolStripStatusLabel toolStripStatusLabelConnectionPacketInfo;

	protected ToolStripStatusLabel toolStripStatusLabelConnectionInfo;

	protected ToolStripStatusLabel toolStripStatusLabelFilterInfo;

	protected int command;

	protected int notification;

	protected int TxAcl;

	protected int TxSco;

	protected int RxAcl;

	protected int RxSco;

	protected ToolStripItem setDefaultNVM;

	protected ToolStripItem setDefaultPatch;

	protected ToolStripItem setDefaultScript;

	protected ToolStripItem setStartupCommand;

	protected ToolStripItem setStartupCommandLEOnly;

	protected ToolStripItem resetPacketCounter;

	protected ToolStripItem setDecodePacket;

	protected ToolStripItem setBTSnoopEnable;

	protected ToolStripItem setBTSnoopLiveEnable;

	protected ToolStripItem displayEnhLog;

	protected ToolStripItem displayFullAclData;

	protected ToolStripItem displaySummaryAclData;

	protected ToolStripItem hideAclData;

	protected ToolStripItem fullAclDataToLog;

	protected WriteScanEnable.UserFieldsWrapper.ScanEnableEnum scanEnable = WriteScanEnable.UserFieldsWrapper.ScanEnableEnum.BOTH_SCANS_ENABLED;

	protected bool enableInterlacedPageScan;

	protected bool enableInterlacedInquiryScan;

	protected readonly ToolStripMenuItem optionDownMenu = new ToolStripMenuItem("Options");

	protected LocalHostDefaultOption localHostDefaultOption;

	protected LocalHostULPOption localHostULPOption;

	protected System.Timers.Timer updateConnectionPacketInfoTimer = new System.Timers.Timer(1000.0);

	protected BTLERemoteDeviceInfo BTLERemoteDeviceInfoList;

	protected SpecificPacketNotifier specificPacketNotifier;

	protected ProdTestUserControl prodTestUserControl;

	protected LEProdTestUserControl leProdTestuserControl;

	protected ListView btDeviceListView;

	protected int LocalBTDeviceIndex;

	protected int LocalLEDeviceIndex = 1;

	protected int currentBTConnectionHandler;

	protected uint currentBTPacketType;

	protected ConnectionPacketType connectionPacketType;

	protected SniffParameters sniffParameters;

	protected HoldParameters holdParameters;

	protected ESCOParameters escoParameters;

	protected RemoteDeviceOptions remoteDeviceOptions;

	protected string localBDAddress;

	protected string localApplicationInfo;

	protected CombinedScripter combinedScripter;

	protected ContextMenuStrip localBTDeviceContextMenuStrip = new ContextMenuStrip();

	protected ToolStripMenuItem InquiryToolStripMenuItem = new ToolStripMenuItem();

	protected ToolStripMenuItem resetToolStripMenuItem = new ToolStripMenuItem();

	protected ToolStripMenuItem scanEnableToolStripMenuItem = new ToolStripMenuItem();

	protected ToolStripMenuItem enableDUTModeToolStripMenuItem = new ToolStripMenuItem();

	protected ToolStripMenuItem readLocalInformationToolStripMenuItem = new ToolStripMenuItem();

	protected ToolStripMenuItem nameToolStripMenuItem = new ToolStripMenuItem();

	protected ToolStripMenuItem bdAddressToolStripMenuItem = new ToolStripMenuItem();

	protected ToolStripMenuItem versionToolStripMenuItem = new ToolStripMenuItem();

	protected ToolStripMenuItem supportedFeaturesToolStripMenuItem = new ToolStripMenuItem();

	protected ToolStripMenuItem extendedFeaturesToolStripMenuItem = new ToolStripMenuItem();

	protected ToolStripMenuItem page1ToolStripMenuItem = new ToolStripMenuItem();

	protected ToolStripMenuItem page2ToolStripMenuItem = new ToolStripMenuItem();

	protected ToolStripSeparator toolStripSeparator1 = new ToolStripSeparator();

	protected ToolStripMenuItem addNewDeviceToolStripMenuItem = new ToolStripMenuItem();

	protected ToolStripSeparator toolStripSeparator2 = new ToolStripSeparator();

	protected ToolStripMenuItem bluetoothOptionsToolStripMenuItem = new ToolStripMenuItem();

	protected ContextMenuStrip btDeviceConnectionContextMenuStrip = new ContextMenuStrip();

	protected ToolStripMenuItem connectToolStripMenuItem = new ToolStripMenuItem();

	protected ToolStripMenuItem disconnectToolStripMenuItem = new ToolStripMenuItem();

	protected ToolStripMenuItem addSCOConnectionToolStripMenuItem = new ToolStripMenuItem();

	protected ToolStripMenuItem setupModifyESCOConnectionToolStripMenuItem = new ToolStripMenuItem();

	protected ToolStripMenuItem setupModifyEnhancedConnectionToolStripMenuItem = new ToolStripMenuItem();

	protected ToolStripSeparator toolStripSeparator3 = new ToolStripSeparator();

	protected ToolStripMenuItem changeConnectionPacketTypeToolStripMenuItem = new ToolStripMenuItem();

	protected ToolStripMenuItem changeLinkSupervisionTimeoutToolStripMenuItem = new ToolStripMenuItem();

	protected ToolStripSeparator toolStripSeparator4 = new ToolStripSeparator();

	protected ToolStripMenuItem requestAuthenticationToolStripMenuItem = new ToolStripMenuItem();

	protected ToolStripMenuItem connectionEncryptionToolStripMenuItem = new ToolStripMenuItem();

	protected ToolStripMenuItem enableToolStripMenuItem = new ToolStripMenuItem();

	protected ToolStripMenuItem disableToolStripMenuItem = new ToolStripMenuItem();

	protected ToolStripMenuItem switchRoleToolStripMenuItem = new ToolStripMenuItem();

	protected ToolStripSeparator toolStripSeparator5 = new ToolStripSeparator();

	protected ToolStripMenuItem changeConnectionLinkKeyToolStripMenuItem = new ToolStripMenuItem();

	protected ToolStripMenuItem masterLinkKeyToolStripMenuItem = new ToolStripMenuItem();

	protected ToolStripMenuItem semiPermanentToolStripMenuItem = new ToolStripMenuItem();

	protected ToolStripMenuItem temporaryToolStripMenuItem = new ToolStripMenuItem();

	protected ToolStripMenuItem readRemoteInformationToolStripMenuItem = new ToolStripMenuItem();

	protected ToolStripMenuItem remoteNameToolStripMenuItem = new ToolStripMenuItem();

	protected ToolStripMenuItem remoteVersionToolStripMenuItem = new ToolStripMenuItem();

	protected ToolStripMenuItem remoteSupportedFeaturesToolStripMenuItem = new ToolStripMenuItem();

	protected ToolStripMenuItem remoteExtendedFeaturesToolStripMenuItem = new ToolStripMenuItem();

	protected ToolStripMenuItem remotePage1ToolStripMenuItem = new ToolStripMenuItem();

	protected ToolStripMenuItem remotePage2ToolStripMenuItem = new ToolStripMenuItem();

	protected ToolStripMenuItem afhChannelMapToolStripMenuItem = new ToolStripMenuItem();

	protected ToolStripSeparator toolStripSeparator6 = new ToolStripSeparator();

	protected ToolStripMenuItem lowPowerModeToolStripMenuItem = new ToolStripMenuItem();

	protected ToolStripMenuItem parkModeToolStripMenuItem = new ToolStripMenuItem();

	protected ToolStripMenuItem exitParkModeToolStripMenuItem = new ToolStripMenuItem();

	protected ToolStripSeparator toolStripSeparator7 = new ToolStripSeparator();

	protected ToolStripMenuItem sniffModeToolStripMenuItem = new ToolStripMenuItem();

	protected ToolStripMenuItem exitSniffModeToolStripMenuItem = new ToolStripMenuItem();

	protected ToolStripSeparator toolStripSeparator8 = new ToolStripSeparator();

	protected ToolStripMenuItem holdModeToolStripMenuItem = new ToolStripMenuItem();

	protected ToolStripSeparator toolStripSeparator9 = new ToolStripSeparator();

	protected ToolStripMenuItem deviceSettingsToolStripMenuItem = new ToolStripMenuItem();

	protected ToolStripMenuItem editSelectedDeviceToolStripMenuItem = new ToolStripMenuItem();

	protected ToolStripMenuItem removeSelectedDeviceToolStripMenuItem = new ToolStripMenuItem();

	protected ToolStripSeparator toolStripSeparator10 = new ToolStripSeparator();

	protected ToolStripMenuItem extendedInquiryResponseDataToolStripMenuItem = new ToolStripMenuItem();

	protected ContextMenuStrip localLEDeviceContextMenuStrip = new ContextMenuStrip();

	protected ToolStripMenuItem advertiseToolStripMenuItem = new ToolStripMenuItem();

	protected ToolStripMenuItem scanToolStripMenuItem = new ToolStripMenuItem();

	protected ToolStripSeparator toolStripSeparator11 = new ToolStripSeparator();

	protected ToolStripMenuItem addNewLEDeviceToolStripMenuItem = new ToolStripMenuItem();

	protected ToolStripSeparator toolStripSeparator12 = new ToolStripSeparator();

	protected ToolStripMenuItem cancelConnectionToolStripMenuItem = new ToolStripMenuItem();

	protected ToolStripMenuItem lEOptionsToolStripMenuItem = new ToolStripMenuItem();

	protected ContextMenuStrip leDeviceConnectionContextMenuStrip = new ContextMenuStrip();

	protected ToolStripMenuItem leConnectToolStripMenuItem = new ToolStripMenuItem();

	protected ToolStripMenuItem leDisconnectToolStripMenuItem = new ToolStripMenuItem();

	protected ToolStripSeparator toolStripSeparator13 = new ToolStripSeparator();

	protected ToolStripMenuItem readRemoteVersionInfoToolStripMenuItem = new ToolStripMenuItem();

	protected ToolStripMenuItem readChannelMapToolStripMenuItem = new ToolStripMenuItem();

	protected ToolStripMenuItem readRemoteFeaturesToolStripMenuItem = new ToolStripMenuItem();

	protected ToolStripMenuItem updateConnectionToolStripMenuItem = new ToolStripMenuItem();

	protected ToolStripSeparator toolStripSeparator14 = new ToolStripSeparator();

	protected ToolStripMenuItem startEncryptionToolStripMenuItem = new ToolStripMenuItem();

	protected ToolStripSeparator toolStripSeparator15 = new ToolStripSeparator();

	protected ToolStripMenuItem deviceLESettingsToolStripMenuItem = new ToolStripMenuItem();

	protected ToolStripMenuItem editSelectedLEDeviceToolStripMenuItem = new ToolStripMenuItem();

	protected ToolStripMenuItem removeSelectedLEDeviceToolStripMenuItem = new ToolStripMenuItem();

	protected ToolStripSeparator toolStripSeparator16 = new ToolStripSeparator();

	protected ToolStripSeparator toolStripSeparator17 = new ToolStripSeparator();

	protected ToolStripMenuItem leSetCigMenuItem = new ToolStripMenuItem();

	protected ToolStripMenuItem leRemoveCigMenuItem = new ToolStripMenuItem();

	protected ToolStripMenuItem leCreateCisMenuItem = new ToolStripMenuItem();

	protected ToolStripMenuItem leDisconnectCisMenuItem = new ToolStripMenuItem();

	protected bool DM1enable = true;

	protected bool DM3enable = true;

	protected bool DM5enable = true;

	protected bool DH1enable = true;

	protected bool DH3enable = true;

	protected bool DH5enable = true;

	protected bool twoDH1enable = true;

	protected bool twoDH3enable = true;

	protected bool twoDH5enable = true;

	protected bool threeDH1enable = true;

	protected bool threeDH3enable = true;

	protected bool threeDH5enable = true;

	protected bool allowRoleswitch;

	protected bool lmPerformMSswitch;

	protected WriteScanEnable.UserFieldsWrapper.ScanEnableEnum scanEnableLocalHost = WriteScanEnable.UserFieldsWrapper.ScanEnableEnum.BOTH_SCANS_ENABLED;

	protected bool HV1enable = true;

	protected bool HV2enable = true;

	protected bool HV3enable = true;

	protected bool autoAcceptConnectionRequest = true;

	protected bool MasterSlaveSwitchEnable = true;

	protected bool HoldModeEnable = true;

	protected bool SniffModeEnable = true;

	protected bool ParkModeEnable = true;

	protected bool MaintainCurrentPower;

	protected bool SuspendPageScanEnable = true;

	protected bool SuspendInquiryScanEnable = true;

	protected bool SuspendPeriodicInquiriesEnable = true;

	private bool useEnhancedParameters;

	protected int TransmitBandwidth = 8000;

	protected int ReceiveBandwidth = 8000;

	protected int MaxLatency = 10;

	protected bool MsMaxLatency = true;

	protected bool SlotMaxLatency;

	protected bool NoRestrans;

	protected bool OptimizePower = true;

	protected bool OptimizeQuality;

	protected bool DontCare;

	protected bool ESCOHV1enable = true;

	protected bool ESCOHV2enable = true;

	protected bool ESCOHV3enable = true;

	protected bool ESCOEV3enable = true;

	protected bool ESCOEV4enable = true;

	protected bool ESCOEV5enable = true;

	protected bool ESCO2EV3enable = true;

	protected bool ESCO3EV3enable = true;

	protected bool ESCO2EV5enable = true;

	protected bool ESCO3EV5enable = true;

	protected string VoiceSetting = "0060";

	protected bool AirCodingCVSDEnable = true;

	protected bool AirCodingULawEnable;

	protected bool AirCodingALawEnable;

	protected bool AirCodingTransparentDataEnable;

	protected int LinearPCMBitPosition = 3;

	protected bool SampleSize8BitEnable = true;

	protected bool SampleSize16BitEnable;

	protected bool InputData1ComplEnable;

	protected bool InputData2ComplEnable = true;

	protected bool InputDataSignMagnitudeEnable;

	protected bool InputDataUnsignedEnable;

	protected bool InputCodingLinearEnable;

	protected bool InputCodingALawEnable = true;

	protected bool InputCodingULawEnable;

	protected bool InputCodingCVSDEnable;

	protected bool AudioSourceCodecEnable = true;

	protected bool AudioSourceHCIEnable;

	protected int TransmitBandwidth_enhSync = 8000;

	protected int ReceiveBandwidth_enhSync = 8000;

	protected int MaxLatency_enhSync = 10;

	protected bool MsMaxLatency_enhSync = true;

	protected bool SlotMaxLatency_enhSync;

	protected bool NoRestrans_enhSync;

	protected bool OptimizePower_enhSync = true;

	protected bool OptimizeQuality_enhSync;

	protected bool DontCare_enhSync;

	protected bool ESCOHV1enable_enhSync = true;

	protected bool ESCOHV2enable_enhSync = true;

	protected bool ESCOHV3enable_enhSync = true;

	protected bool ESCOEV3enable_enhSync = true;

	protected bool ESCOEV4enable_enhSync = true;

	protected bool ESCOEV5enable_enhSync = true;

	protected bool ESCO2EV3enable_enhSync = true;

	protected bool ESCO3EV3enable_enhSync = true;

	protected bool ESCO2EV5enable_enhSync = true;

	protected bool ESCO3EV5enable_enhSync = true;

	private int inputDataPath;

	private int outputDataPath;

	private long txRxCodingFormat;

	private int pcmSamplePayload = 3;

	private int ioCodedDataSize;

	private int ioPcmDataFormat = 3;

	private long ioCodingFormat;

	protected string Lap = "9E8B33";

	protected int Length = 5;

	protected int Responses = 64;

	protected string[] AddressFilter = Enumerable.Repeat("FF", 6).ToArray();

	protected bool FECRequired;

	protected string ExtendedInquiryResponse = "0109";

	protected bool AuthenticationEnable;

	protected bool EncryptionEnable;

	protected bool SimplePairingEnable;

	protected bool DebugModeEnable;

	protected bool SecureConnectionsHostSupportEnable;

	protected bool LevelDefaultEnable = true;

	protected bool LevelAuthenticationEnable;

	protected bool LevelPairingEnable;

	protected bool LinkKeyASCIIEnable;

	protected bool LinkKeyHexEnable = true;

	protected string LinkKey = "0102030405060708090A0B0C0D0E0F10";

	protected bool PinCodeASCIIEnable;

	protected bool PinCodeHexEnable = true;

	protected string PinCode = "0102030405060708090A0B0C0D0E0F10";

	protected IoCapabilityEnum IOCapability;

	protected bool OutOfBandDataPresent;

	protected bool ConfirmationRequestReply = true;

	protected bool PasskeyRequestReply = true;

	protected bool AuthenticationRequirements = true;

	protected string OOBC = "00000000000000000000000000000000";

	protected string OOBR = "00000000000000000000000000000000";

	protected int SniffMaxInterval = 2048;

	protected int SniffMinInterval = 2048;

	protected int SniffAttempt = 8;

	protected int SniffTimeout = 1;

	protected int HoldMaxInterval = 10;

	protected int HoldMinInterval = 10;

	protected int Advertising_Interval_Min = 32;

	protected int Advertising_Interval_Max = 32;

	protected AdvertisingTypeEnum AdvertisingType;

	protected OwnAddressTypeEnum AdvertisingOwnAddressType;

	protected PeerAddressTypeEnum PeerAddressType;

	protected string PeerAddress = "000000000000";

	protected bool Index37Enable = true;

	protected bool Index38Enable = true;

	protected bool Index39Enable = true;

	protected AdvertisingFilterPolicyEnum AdvertisingFilterPolicy;

	protected int AdvertisingDataLength;

	protected string AdvertisingData = "";

	protected int ScanResponseDataLength;

	protected string ScanResponseData = "";

	protected LeSetScanParameters.UserFieldsWrapper.LeScanTypeEnum LeScanType;

	protected OwnAddressTypeEnum ScanOwnAddressType;

	protected int ScanInterval = 16;

	protected int ScanWindow = 16;

	protected bool ScanFilterPolicyEnable;

	protected bool ScanFilterDuplicatesEnable;

	protected string[] LEFilterAddress = Enumerable.Repeat("FF", 6).ToArray();

	protected OwnAddressTypeEnum CreateConnectionOwnAddressType;

	protected int ConnectionTimingMinInterval = 40;

	protected int ConnectionTimingMaxInterval = 40;

	protected int ConnectionTimingTimeout = 10000;

	protected int ConnectionTimingLatency;

	protected int ConnectionEventTimingMinLength;

	protected int ConnectionEventTimingMaxLength;

	protected int ConnectionScanTimingScanInterval = 20;

	protected int ConnectionScanTimingScanWindow = 20;

	protected bool InitiatorWhiteListEnabe;

	protected string LELinkKey = "0102030405060708090A0B0C0D0E0F10";

	protected string RandomNumber = "0102030405060708";

	protected string EncryptedDiversifier = "0000";

	protected bool PositiveAutoReply = true;

	protected bool NegativeAutoReply;

	protected bool UserPromptedAutoReply;

	protected int currentCisHandle;

	protected LECisInfo leCisInfo;

	protected uint cigId;

	protected uint numCis = 1u;

	protected uint isoIntervalMsec = 10u;

	protected uint packing;

	protected uint numCisSubEvents = 2u;

	protected uint sca;

	protected uint cisFlushTimeoutMS = 1u;

	protected uint cisFlushTimeoutSM = 1u;

	protected uint cisMaxPayloadSizeMS = 30u;

	protected uint cisMaxPayloadSizeSM = 30u;

	protected bool cisPhyType1MMSEnable = true;

	protected bool cisPhyType2MMSEnable;

	protected bool cisPhyTypeCodedMSEnable;

	protected bool cisPhyType1MSMEnable = true;

	protected bool cisPhyType2MSMEnable;

	protected bool cisPhyTypeCodedSMEnable;

	protected uint cisBurstNumMS = 1u;

	protected uint cisBurstNumSM = 1u;

	protected bool cisAutoAccept = true;

	protected bool cisFraming;

	protected uint cisSDUIntervalMS = 10000u;

	protected uint cisSDUIntervalSM = 10000u;

	protected uint cisMaxSDUSizeMS = 30u;

	protected uint cisMaxSDUSizeSM = 30u;

	protected uint connUpdateIntervalMin = 40u;

	protected uint connUpdateIntervalMax = 40u;

	protected uint connUpdateTimeoutMs = 1000u;

	protected uint connUpdateLatency;

	protected uint connUpdateCeLengthMin;

	protected uint connUpdateCeLengthMax;

	protected bool connUpdateParamRequestPositiveReply = true;

	protected bool connUpdateParamRequestNegativeReply;

	protected uint connUpdateParamRejectReason;

	protected string BTSnoopLiveImportDllFileName = "";

	protected string BTSnoopLiveImportIniFileName = "";

	private RecentParameterSettings recentParameterSettings = new RecentParameterSettings();

	private Queue<leRemoteInfo> leRemoteDeviceQueue;

	private Thread UpdateRemoteDeviceListThread;

	private ManualResetEvent updateDeviceListEvent = new ManualResetEvent(initialState: false);

	private Queue<PacketBase> txPacketQueue;

	private Thread SendPacketsThread;

	private ManualResetEvent sendPacketEvent = new ManualResetEvent(initialState: false);

	private BTScripter btScripter;

	private bool dutSetCig;

	private bool sortAscendingOrder = true;

	public ToolStripMenuItem OptionDownMenu => optionDownMenu;

	public uint CurrentBTPacketType
	{
		set
		{
			currentBTPacketType = value;
		}
	}

	public string voiceSetting => VoiceSetting;

	public int InputDataPath
	{
		get
		{
			return inputDataPath;
		}
		set
		{
			inputDataPath = value;
		}
	}

	public int OutputDataPath
	{
		get
		{
			return outputDataPath;
		}
		set
		{
			outputDataPath = value;
		}
	}

	public long TxRxCodingFormat
	{
		get
		{
			return txRxCodingFormat;
		}
		set
		{
			txRxCodingFormat = value;
		}
	}

	public int PcmSamplePayload
	{
		get
		{
			return pcmSamplePayload;
		}
		set
		{
			pcmSamplePayload = value;
		}
	}

	public int IOCodedDataSize
	{
		get
		{
			return ioCodedDataSize;
		}
		set
		{
			ioCodedDataSize = value;
		}
	}

	public int IOPcmDataFormat
	{
		get
		{
			return ioPcmDataFormat;
		}
		set
		{
			ioPcmDataFormat = value;
		}
	}

	public long IOCodingFormat
	{
		get
		{
			return ioCodingFormat;
		}
		set
		{
			ioCodingFormat = value;
		}
	}

	[DllImport("user32.dll")]
	private static extern int SendMessage(IntPtr hWnd, uint Msg, int wParam, int lParam);

	[DllImport("user32.dll")]
	private static extern int SendMessage(IntPtr hWnd, uint Msg, int wParam, ref LV_ITEM item_info);

	public BTGooier(string technologyName, QCRPG.Framework.Logger logger, Configurer configurer, BTAPI btAPI, PacketListBase packetList, BTConfigSettings btConfigSettings, BTMainWorkerThread btMainWorkerThread, bool deviceEmulationMode, DeviceEmulationModeConfigSettings deviceEmulationModeConfigSettings, PacketAutoResponder packetAutoResponder, SpecificPacketNotifier SpecificPacketHandler, BTScripter btScripter)
		: base(technologyName, logger)
	{
		this.configurer = configurer;
		this.btAPI = btAPI;
		this.packetList = packetList;
		this.btConfigSettings = btConfigSettings;
		this.btMainWorkerThread = btMainWorkerThread;
		this.deviceEmulationMode = deviceEmulationMode;
		this.packetAutoResponder = packetAutoResponder;
		specificPacketNotifier = SpecificPacketHandler;
		specificPacketNotifier.AddPacketNotification(typeof(ConnectionRequest), generalPacketParserForUIUpdates);
		specificPacketNotifier.AddPacketNotification(typeof(ConnectionComplete), generalPacketParserForUIUpdates);
		specificPacketNotifier.AddPacketNotification(typeof(DisconnectionComplete), generalPacketParserForUIUpdates);
		specificPacketNotifier.AddPacketNotification(typeof(HciModeChange), generalPacketParserForUIUpdates);
		specificPacketNotifier.AddPacketNotification(typeof(RoleChange), generalPacketParserForUIUpdates);
		specificPacketNotifier.AddPacketNotification(typeof(LeConnectionComplete), generalPacketParserForUIUpdates);
		specificPacketNotifier.AddPacketNotification(typeof(LeEnhancedConnectionComplete), generalPacketParserForUIUpdates);
		specificPacketNotifier.AddPacketNotification(typeof(SynchronousConnectionCompleteEvent), generalPacketParserForUIUpdates);
		specificPacketNotifier.AddPacketNotification(typeof(LeLongTermKeyRequestEvent), generalPacketParserForUIUpdates);
		specificPacketNotifier.AddPacketNotification(typeof(InquiryResultWithRssi), generalPacketParserForUIUpdates);
		specificPacketNotifier.AddPacketNotification(typeof(InquiryResult), generalPacketParserForUIUpdates);
		specificPacketNotifier.AddPacketNotification(typeof(InquiryComplete), generalPacketParserForUIUpdates);
		specificPacketNotifier.AddPacketNotification(typeof(LeSetScanEnabled), generalPacketParserForUIUpdates);
		specificPacketNotifier.AddPacketNotification(typeof(CommandCompleteForLeSetScanEnabled), generalPacketParserForUIUpdates);
		specificPacketNotifier.AddPacketNotification(typeof(LeSetAdvertiseEnabled), generalPacketParserForUIUpdates);
		specificPacketNotifier.AddPacketNotification(typeof(CommandCompleteForLeSetAdvertiseEnabled), generalPacketParserForUIUpdates);
		specificPacketNotifier.AddPacketNotification(typeof(LeAdvertisingReport), generalPacketParserForUIUpdates);
		specificPacketNotifier.AddPacketNotification(typeof(LeExtendedAdvertisingReport), generalPacketParserForUIUpdates);
		specificPacketNotifier.AddPacketNotification(typeof(CommandCompleteForReadRssi), generalPacketParserForUIUpdates);
		specificPacketNotifier.AddPacketNotification(typeof(LinkKeyRequest), generalPacketParserForUIUpdates);
		specificPacketNotifier.AddPacketNotification(typeof(PinCodeRequest), generalPacketParserForUIUpdates);
		specificPacketNotifier.AddPacketNotification(typeof(IoCapabilityRequest), generalPacketParserForUIUpdates);
		specificPacketNotifier.AddPacketNotification(typeof(IoCapabilityResponse), generalPacketParserForUIUpdates);
		specificPacketNotifier.AddPacketNotification(typeof(UserConfirmationRequest), generalPacketParserForUIUpdates);
		specificPacketNotifier.AddPacketNotification(typeof(UserPasskeyRequest), generalPacketParserForUIUpdates);
		specificPacketNotifier.AddPacketNotification(typeof(UserPasskeyNotification), generalPacketParserForUIUpdates);
		specificPacketNotifier.AddPacketNotification(typeof(RemoteOobDataRequest), generalPacketParserForUIUpdates);
		specificPacketNotifier.AddPacketNotification(typeof(LinkKeyNotification), generalPacketParserForUIUpdates);
		specificPacketNotifier.AddPacketNotification(typeof(RamDumpFragment), generalPacketParserForUIUpdates);
		specificPacketNotifier.AddPacketNotification(typeof(DumpInformationVse), generalPacketParserForUIUpdates);
		specificPacketNotifier.AddPacketNotification(typeof(CsrRxBerErr1StatsEvent), generalPacketParserForUIUpdates);
		specificPacketNotifier.AddPacketNotification(typeof(LeRemoteConnectionParameterRequest), generalPacketParserForUIUpdates);
		specificPacketNotifier.AddPacketNotification(typeof(CommandCompleteForReadBdAddr), generalPacketParserForUIUpdates);
		specificPacketNotifier.AddPacketNotification(typeof(CommandCompleteForReset), generalPacketParserForUIUpdates);
		specificPacketNotifier.AddPacketNotification(typeof(CommandCompleteForWriteScanEnable), generalPacketParserForUIUpdates);
		specificPacketNotifier.AddPacketNotification(typeof(CommandCompleteForLeSetCigParametersTest), generalPacketParserForUIUpdates);
		specificPacketNotifier.AddPacketNotification(typeof(LeCisEstablished), generalPacketParserForUIUpdates);
		specificPacketNotifier.AddPacketNotification(typeof(LeCisRequest), generalPacketParserForUIUpdates);
		specificPacketNotifier.AddPacketNotification(typeof(CommandCompleteForLeRemoveCig), generalPacketParserForUIUpdates);
		specificPacketNotifier.AddPacketNotification(typeof(CommandCompleteForLeTestEnd), generalPacketParserForUIUpdates);
		specificPacketNotifier.AddPacketNotification(typeof(ConnectionComplete), UpdateStatusBarInfo);
		if (!deviceEmulationMode)
		{
			packetUserControl = new PacketUserControl(packetList.CommandPackets);
		}
		else
		{
			List<PacketBase> list = new List<PacketBase>();
			list.AddRange(packetList.NotificationPackets);
			list.AddRange(packetList.ResponsePackets);
			packetUserControl = new PacketUserControl(list);
			this.deviceEmulationModeConfigSettings = deviceEmulationModeConfigSettings;
			deviceEmulationModeUserControl = new DeviceEmulationModeUserControl(deviceEmulationModeConfigSettings, packetAutoResponder);
		}
		updateConnectionPacketInfoTimer.Enabled = false;
		updateConnectionPacketInfoTimer.Elapsed += updateConnectionPacketInfoTimer_Elapsed;
		packetUserControl.RegisterLogMessageObserver(logger);
		packetUserControl.RegisterSendPacketClickedObserver(specificPacketNotifier);
		configurer.RegisterConfigurableObject(openConnectionMultipleTypesForm, "OpenConnectionMultipleTypesFormSettings");
		configurer.RegisterConfigurableObject(this, "BTGooierMultipleSettings");
		btSendRawBytesUserControl = new BTSendRawBytesUserControl(btMainWorkerThread);
		btConfigUserControl = new BTConfigUserControl(btConfigSettings);
		BTLERemoteDeviceInfoList = new BTLERemoteDeviceInfo();
		prodTestUserControl = new ProdTestUserControl(btMainWorkerThread, specificPacketNotifier, BTLERemoteDeviceInfoList, this);
		leProdTestuserControl = new LEProdTestUserControl(btMainWorkerThread);
		LocalBTDeviceContextMenuStrip();
		LocalLEDeviceContextMenuStrip();
		BTDeviceConnectionContextMenuStrip();
		LEDeviceConnectionContextMenuStrip();
		btScriptUserControl = new BTScriptUserControl();
		btDataTransferUserControl = new DataTransferUserControlSelector(btMainWorkerThread, logger);
		btDataTransferUserControl.ClearGui();
		btAPI.RegisterReceiveACLDataPacketObserver(btDataTransferUserControl);
		scoOverHciUserControl = new SCOoverHCIUserControl(btMainWorkerThread, specificPacketNotifier, logger, btAPI, this);
		scoOverHciUserControl.Enabled = false;
		configurer.RegisterConfigurableObject(recentParameterSettings, "RecentParameterSettings");
		btMainWorkerThread.StartupEventHandler += btMainWorkerThread_StartupEventHandler;
		btListViewUserControl = new DeviceListViewUserControl();
		leRemoteDeviceQueue = new Queue<leRemoteInfo>();
		UpdateRemoteDeviceListThread = new Thread(updateRemoteDeviceList);
		UpdateRemoteDeviceListThread.Name = "BtGooier-UpdateRemoteDeviceList";
		UpdateRemoteDeviceListThread.IsBackground = true;
		UpdateRemoteDeviceListThread.Start();
		txPacketQueue = new Queue<PacketBase>();
		SendPacketsThread = new Thread(SendPackets);
		SendPacketsThread.Name = "BtGooier-SendPackets";
		SendPacketsThread.IsBackground = true;
		SendPacketsThread.Start();
		this.btScripter = btScripter;
		btAPI.SetAclDataDisplay();
	}

	private void updateRemoteDeviceList()
	{
		ManualResetEvent[] array = new ManualResetEvent[1] { updateDeviceListEvent };
		while (true)
		{
			int num = WaitHandle.WaitAny(array);
			if (array[num] != updateDeviceListEvent)
			{
				continue;
			}
			if (leRemoteDeviceQueue.Count == 0)
			{
				updateDeviceListEvent.Reset();
				continue;
			}
			leRemoteInfo leRemoteInfo = default(leRemoteInfo);
			lock (leRemoteDeviceQueue)
			{
				leRemoteInfo = leRemoteDeviceQueue.Dequeue();
			}
			try
			{
				BTLERemoteDeviceInfoList.UpdateLERemoteDeviceList(leRemoteInfo.remoteDeviceItem.Text, leRemoteInfo.addrType, leRemoteInfo.rssi);
				UpdateLERemoteDeviceInfoWithLocalHostULPOptions(leRemoteInfo.remoteDeviceItem.Text);
				UpdateLEDeviceListView(leRemoteInfo.remoteDeviceItem);
			}
			catch (NullReferenceException ex)
			{
				logger.Enqueue(new QCRPG.Framework.LogMessage(LogMessageType.Error, "Failed to update queue. " + ex));
			}
		}
	}

	private void SendPackets()
	{
		ManualResetEvent[] array = new ManualResetEvent[1] { sendPacketEvent };
		while (true)
		{
			int num = WaitHandle.WaitAny(array);
			if (array[num] == sendPacketEvent)
			{
				if (txPacketQueue.Count == 0)
				{
					sendPacketEvent.Reset();
					continue;
				}
				PacketBase packet = txPacketQueue.Dequeue();
				btAPI.Send(packet);
			}
		}
	}

	private void btMainWorkerThread_StartupEventHandler(object sender, int ACLPacketLength, int SCOPacketLength, int ACLBufferSize, int SCOBufferSize, string BDAddress, string ApplicationInfo, int LeACLBufferSize)
	{
		localBDAddress = BDAddress;
		localApplicationInfo = ApplicationInfo;
		if (localBDAddress != null && localApplicationInfo != null)
		{
			base.TitleBarMessage = "QCRPG-BT   Address: " + localBDAddress + localApplicationInfo;
			GooierBase.SetWindowText((IntPtr)mainWindowHandle, base.TitleBarMessage);
		}
	}

	protected override void StartupComplete()
	{
		SetControlEnables(ControlEnableMode.DEFAULT);
		btAPI.RegisterConnectionStateChangeInfoObserver(this);
	}

	public void ApplicationReady()
	{
	}

	protected override void AddUserControls()
	{
		userControls.Add(packetUserControl);
		userControls.Add(btConfigUserControl);
		userControls.Add(prodTestUserControl);
		userControls.Add(leProdTestuserControl);
		userControls.Add(btScriptUserControl);
		userControls.Add(btDataTransferUserControl);
		userControls.Add(btSendRawBytesUserControl);
		userControls.Add(btListViewUserControl);
		userControls.Add(scoOverHciUserControl);
		configurer.RegisterConfigurableObject(packetUserControl, "PacketUserControlSettings");
		configurer.RegisterConfigurableObject(btConfigUserControl, "BTConfigUserControlSettings");
		configurer.RegisterConfigurableObject(btScriptUserControl, "BTScriptUserControlSettings");
		configurer.RegisterConfigurableObject(btSendRawBytesUserControl, "BTSendRawBytesUserControlSettings");
		if (deviceEmulationMode)
		{
			userControls.Add(deviceEmulationModeUserControl);
			configurer.RegisterConfigurableObject(deviceEmulationModeUserControl, "DeviceEmulationModeUserControlSettings");
		}
	}

	protected override void BuildDropDownMenu()
	{
		dropDownMenu.Text = technologyName;
		AddDropDownMenuItems();
		SetDropDownMenuItemNames();
	}

	protected void AddDropDownMenuItems()
	{
		dropDownMenu.DropDownItems.Add("Open Connection", null, OpenConnectionHandler);
		dropDownMenu.DropDownItems.Add("Close Connection", null, CloseConnectionHandler);
		setDefaultNVM = dropDownMenu.DropDownItems.Add("Load NVM File", null, EnableDefaultNvmHandler);
		((ToolStripMenuItem)setDefaultNVM).Checked = true;
		setDefaultPatch = dropDownMenu.DropDownItems.Add("Load Patch File", null, EnableDefaultPatchHandler);
		((ToolStripMenuItem)setDefaultPatch).Checked = true;
		setStartupCommand = dropDownMenu.DropDownItems.Add("Run Init Commands at Startup", null, EnableStartupCommandHandler);
		setStartupCommand.ToolTipText = "Following commands are send at startup - \nReadLocalVersionInformation\nReadLocalSupportedFeatures\nSetEventMask\nWriteExtendedInquiryResponse\nWriteScanEnable\nWriteHoldModeActivity\nWriteAuthenticationEnable\nWriteSimplePairingMode\nWriteInquiryMode\nWriteInquiryScanType\nWritePageScanType\nReadBufferSize\nLeReadBufferSize\nWriteSecureConnectionsHostSupport";
		((ToolStripMenuItem)setStartupCommand).Checked = true;
		setStartupCommandLEOnly = dropDownMenu.DropDownItems.Add("(BLE only target) Run Init Commands at Startup", null, EnableStartupCommandLEOnlyHandler);
		setStartupCommandLEOnly.ToolTipText = "Following commands are send at startup - \nReadLocalVersionInformation\nReadLocalSupportedFeatures\nSetEventMask\nLeSetEventMask\nLeReadBufferSize";
		((ToolStripMenuItem)setStartupCommandLEOnly).Checked = true;
		setDefaultScript = dropDownMenu.DropDownItems.Add("Load Script File", null, EnableDefaultScriptHandler);
		((ToolStripMenuItem)setDefaultScript).Checked = false;
		resetPacketCounter = dropDownMenu.DropDownItems.Add("Reset Packet Counter", null, ResetPacketCounterHandler);
		setDecodePacket = dropDownMenu.DropDownItems.Add("Decode Packet", null, EnablePacketDecodeHandler);
		((ToolStripMenuItem)setDecodePacket).Checked = true;
		((ToolStripMenuItem)setDecodePacket).CheckStateChanged += CheckStateChanged;
		dropDownMenu.DropDownItems.Add(new ToolStripSeparator());
		dropDownMenu.DropDownItems.Add("<Sleep config is moved to Config menu>", null);
		dropDownMenu.DropDownItems.Add(new ToolStripSeparator());
		dropDownMenu.DropDownItems.Add("Scan Enable...", null, ScanModeHandler);
		dropDownMenu.DropDownItems.Add(new ToolStripSeparator());
		dropDownMenu.DropDownItems.Add("Enable DUT Mode", null, DUTModeHandler);
		dropDownMenu.DropDownItems.Add(new ToolStripSeparator());
		optionDownMenu.DropDownItems.Add("Bluetooth Options...", null, BTOptionsHandler);
		optionDownMenu.DropDownItems.Add("LE Options...", null, LEOptionsHandler);
		dropDownMenu.DropDownItems.Add(optionDownMenu);
		dropDownMenu.DropDownItems.Add(new ToolStripSeparator());
		displayEnhLog = enhancedLogMenu.DropDownItems.Add("Enable display", null, DisplayEnhLog);
		((ToolStripMenuItem)displayEnhLog).Checked = true;
		btAPI.EnableDisplayEnhancedLog(enable: true);
		dropDownMenu.DropDownItems.Add(enhancedLogMenu);
		dropDownMenu.DropDownItems.Add(new ToolStripSeparator());
		dropDownMenu.DropDownItems.Add("<Snoop Log config is moved to Config menu>", null);
		dropDownMenu.DropDownItems.Add(new ToolStripSeparator());
		displayFullAclData = aclLogMenu.DropDownItems.Add("Display ACL Data", null, DisplayFullAclData);
		displaySummaryAclData = aclLogMenu.DropDownItems.Add("Display Summary ACL Data", null, DisplaySummaryAclData);
		((ToolStripMenuItem)displaySummaryAclData).Checked = true;
		hideAclData = aclLogMenu.DropDownItems.Add("Hide ACL Data", null, HideAclData);
		aclLogMenu.DropDownItems.Add(new ToolStripSeparator());
		fullAclDataToLog = aclLogMenu.DropDownItems.Add("Full ACL Data to Log", null, FullAclDataToLogFile);
		dropDownMenu.DropDownItems.Add(aclLogMenu);
	}

	protected void SetDropDownMenuItemNames()
	{
		for (int i = 0; i < dropDownMenu.DropDownItems.Count; i++)
		{
			dropDownMenu.DropDownItems[i].Name = dropDownMenu.DropDownItems[i].Text;
		}
	}

	protected override void BuildCustomStatusStrip()
	{
		toolStripStatusLabelCisHandle = new ToolStripStatusLabel("CIS Handle");
		toolStripStatusLabelCisHandle.Spring = true;
		customToolStripStatusLabels.Add(toolStripStatusLabelCisHandle);
		toolStripStatusLabelEmpty = new ToolStripStatusLabel("Connection Handle");
		toolStripStatusLabelEmpty.Spring = true;
		customToolStripStatusLabels.Add(toolStripStatusLabelEmpty);
		toolStripStatusLabelPacketInfo = new ToolStripStatusLabel("Command:    0   Event:  0   ");
		customToolStripStatusLabels.Add(toolStripStatusLabelPacketInfo);
		toolStripStatusLabelConnectionPacketInfo = new ToolStripStatusLabel("TxACL:    0   RxACL:    0   TxSCO:    0   RxSCO:    0   ");
		customToolStripStatusLabels.Add(toolStripStatusLabelConnectionPacketInfo);
		toolStripStatusLabelConnectionInfo = new ToolStripStatusLabel("Not Connected");
		toolStripStatusLabelConnectionInfo.BorderStyle = Border3DStyle.Etched;
		toolStripStatusLabelConnectionInfo.BorderSides = ToolStripStatusLabelBorderSides.Left;
		customToolStripStatusLabels.Add(toolStripStatusLabelConnectionInfo);
		toolStripStatusLabelFilterInfo = new ToolStripStatusLabel("Device Filter Off");
		toolStripStatusLabelFilterInfo.BorderStyle = Border3DStyle.Etched;
		toolStripStatusLabelFilterInfo.BorderSides = ToolStripStatusLabelBorderSides.Left;
		customToolStripStatusLabels.Add(toolStripStatusLabelFilterInfo);
	}

	protected override void BuildCustomToolStrip()
	{
		toolStripButtonOpenConnection = new ToolStripButton(QCRPG.Framework.Resources.GetImage("OpenConnection.png"));
		toolStripButtonOpenConnection.DisplayStyle = ToolStripItemDisplayStyle.Image;
		toolStripButtonOpenConnection.AutoToolTip = true;
		toolStripButtonOpenConnection.ToolTipText = "Open a BT connection";
		toolStripButtonOpenConnection.Click += OpenConnectionHandler;
		customToolStripItems.Add(toolStripButtonOpenConnection);
		toolStripButtonCloseConnection = new ToolStripButton(QCRPG.Framework.Resources.GetImage("CloseConnection.png"));
		toolStripButtonCloseConnection.DisplayStyle = ToolStripItemDisplayStyle.Image;
		toolStripButtonCloseConnection.AutoToolTip = true;
		toolStripButtonCloseConnection.ToolTipText = "Close a BT connection";
		toolStripButtonCloseConnection.Click += CloseConnectionHandler;
		customToolStripItems.Add(toolStripButtonCloseConnection);
		toolStripButtonLoadDefaultNvm = new ToolStripButton(QCRPG.Framework.Resources.GetImage("LoadDefaultNvm.png"));
		toolStripButtonLoadDefaultNvm.DisplayStyle = ToolStripItemDisplayStyle.Image;
		toolStripButtonLoadDefaultNvm.AutoToolTip = true;
		toolStripButtonLoadDefaultNvm.ToolTipText = "Load the default BT NVM file specified in the config";
		toolStripButtonLoadDefaultNvm.Click += LoadDefaultNvmHandler;
		customToolStripItems.Add(toolStripButtonLoadDefaultNvm);
		toolStripButtonLoadNvm = new ToolStripButton(QCRPG.Framework.Resources.GetImage("LoadNvm.png"));
		toolStripButtonLoadNvm.DisplayStyle = ToolStripItemDisplayStyle.Image;
		toolStripButtonLoadNvm.AutoToolTip = true;
		toolStripButtonLoadNvm.ToolTipText = "Choose and load an BT NVM file";
		toolStripButtonLoadNvm.Click += LoadNvmHandler;
		customToolStripItems.Add(toolStripButtonLoadNvm);
		toolStripButtonLoadDefaultPatch = new ToolStripButton(QCRPG.Framework.Resources.GetImage("LoadDefaultPatch.png"));
		toolStripButtonLoadDefaultPatch.DisplayStyle = ToolStripItemDisplayStyle.Image;
		toolStripButtonLoadDefaultPatch.AutoToolTip = true;
		toolStripButtonLoadDefaultPatch.ToolTipText = "Load the default BT firmware patch file specified in the config";
		toolStripButtonLoadDefaultPatch.Click += LoadDefaultPatchHandler;
		customToolStripItems.Add(toolStripButtonLoadDefaultPatch);
		toolStripButtonLoadPatch = new ToolStripButton(QCRPG.Framework.Resources.GetImage("LoadPatch.png"));
		toolStripButtonLoadPatch.DisplayStyle = ToolStripItemDisplayStyle.Image;
		toolStripButtonLoadPatch.AutoToolTip = true;
		toolStripButtonLoadPatch.ToolTipText = "Choose and load an BT firmware patch file";
		toolStripButtonLoadPatch.Click += LoadPatchHandler;
		customToolStripItems.Add(toolStripButtonLoadPatch);
		customToolStripItems.Add(new ToolStripSeparator());
		toolStripButtonInquiry = new ToolStripButton(QCRPG.Framework.Resources.GetImage("Inquiry.png"));
		toolStripButtonInquiry.DisplayStyle = ToolStripItemDisplayStyle.Image;
		toolStripButtonInquiry.AutoToolTip = true;
		toolStripButtonInquiry.ToolTipText = "Inquiry";
		toolStripButtonInquiry.Click += InquiryToolStripMenuItem_Click;
		customToolStripItems.Add(toolStripButtonInquiry);
		toolStripButtonPageScan = new ToolStripButton(QCRPG.Framework.Resources.GetImage("PageScan.png"));
		toolStripButtonPageScan.DisplayStyle = ToolStripItemDisplayStyle.Image;
		toolStripButtonPageScan.AutoToolTip = true;
		toolStripButtonPageScan.ToolTipText = "Page Scan Control";
		toolStripButtonPageScan.Click += PageScanHandler;
		toolStripButtonPageScan.Checked = false;
		customToolStripItems.Add(toolStripButtonPageScan);
		toolStripButtonInquiryScan = new ToolStripButton(QCRPG.Framework.Resources.GetImage("InquiryScan.png"));
		toolStripButtonInquiryScan.DisplayStyle = ToolStripItemDisplayStyle.Image;
		toolStripButtonInquiryScan.AutoToolTip = true;
		toolStripButtonInquiryScan.ToolTipText = "Inquiry Scan Control";
		toolStripButtonInquiryScan.Click += InquiryScanHandler;
		toolStripButtonInquiryScan.Checked = false;
		customToolStripItems.Add(toolStripButtonInquiryScan);
		toolStripButtonFileTransfer = new ToolStripButton(QCRPG.Framework.Resources.GetImage("FileTransfer.png"));
		toolStripButtonFileTransfer.DisplayStyle = ToolStripItemDisplayStyle.Image;
		toolStripButtonFileTransfer.AutoToolTip = true;
		toolStripButtonFileTransfer.ToolTipText = "File Transfer";
		toolStripButtonFileTransfer.Click += FileTransferHandler;
		toolStripButtonFileTransfer.Enabled = false;
		customToolStripItems.Add(toolStripButtonFileTransfer);
		toolStripButtonDataTransfer = new ToolStripButton(QCRPG.Framework.Resources.GetImage("DataTransfer.png"));
		toolStripButtonDataTransfer.DisplayStyle = ToolStripItemDisplayStyle.Image;
		toolStripButtonDataTransfer.AutoToolTip = true;
		toolStripButtonDataTransfer.ToolTipText = "Data Transfer";
		toolStripButtonDataTransfer.Click += FileTransferHandler;
		toolStripButtonDataTransfer.Enabled = false;
		customToolStripItems.Add(toolStripButtonDataTransfer);
		customToolStripItems.Add(new ToolStripSeparator());
		toolStripButtonLEAdvertising = new ToolStripButton(QCRPG.Framework.Resources.GetImage("LEAdvertising.png"));
		toolStripButtonLEAdvertising.DisplayStyle = ToolStripItemDisplayStyle.Image;
		toolStripButtonLEAdvertising.AutoToolTip = true;
		toolStripButtonLEAdvertising.ToolTipText = "LE Advertising";
		toolStripButtonLEAdvertising.Click += LEAdvertisingHandler;
		customToolStripItems.Add(toolStripButtonLEAdvertising);
		toolStripButtonLEScan = new ToolStripButton(QCRPG.Framework.Resources.GetImage("LEScan.png"));
		toolStripButtonLEScan.DisplayStyle = ToolStripItemDisplayStyle.Image;
		toolStripButtonLEScan.AutoToolTip = true;
		toolStripButtonLEScan.ToolTipText = "LE Scan";
		toolStripButtonLEScan.Click += LEScanHandler;
		customToolStripItems.Add(toolStripButtonLEScan);
		customToolStripItems.Add(new ToolStripSeparator());
		customToolStripItems.Add(new ToolStripSeparator());
		ToolStripButtonBringUp = new ToolStripButton(QCRPG.Framework.Resources.GetImage("apply_2a2b2c.png"));
		ToolStripButtonBringUp.DisplayStyle = ToolStripItemDisplayStyle.Image;
		ToolStripButtonBringUp.AutoToolTip = true;
		ToolStripButtonBringUp.ToolTipText = "MTP emulation platform bringup.\n- Switch baudrate to Config using HCI VS Set Baudrate command \n- Load patch \n- Load NVM";
		ToolStripButtonBringUp.Click += bringupToolsStripMenuItem_Click;
		customToolStripItems.Add(ToolStripButtonBringUp);
		ToolStripButtonHCIReset = new ToolStripButton(QCRPG.Framework.Resources.GetImage("Reset.png"));
		ToolStripButtonHCIReset.DisplayStyle = ToolStripItemDisplayStyle.Image;
		ToolStripButtonHCIReset.AutoToolTip = true;
		ToolStripButtonHCIReset.ToolTipText = "RESET";
		ToolStripButtonHCIReset.Click += resetToolStripMenuItem_Click;
		customToolStripItems.Add(ToolStripButtonHCIReset);
		customToolStripItems.Add(new ToolStripSeparator());
		customToolStripItems.Add(new ToolStripSeparator());
	}

	private void OpenConnectionHandler(object sender, EventArgs e)
	{
		openConnectionMultipleTypesForm.Title = "Open BT Connection";
		List<OpenConnectionMultipleTypesForm.ConnectionType> list = new List<OpenConnectionMultipleTypesForm.ConnectionType>();
		list.Add(OpenConnectionMultipleTypesForm.ConnectionType.SERIAL);
		list.Add(OpenConnectionMultipleTypesForm.ConnectionType.USB);
		list.Add(OpenConnectionMultipleTypesForm.ConnectionType.DIAG);
		list.Add(OpenConnectionMultipleTypesForm.ConnectionType.TCP);
		openConnectionMultipleTypesForm.SupportedConnectionTypes = list;
		openConnectionMultipleTypesForm.SerialShowSlaveAddress = false;
		openConnectionMultipleTypesForm.SerialDisplayedDataRateList = new List<int>
		{
			300, 1200, 2400, 4800, 9600, 19200, 34800, 57600, 115200, 3000000,
			3200000, 4000000
		};
		openConnectionMultipleTypesForm.UIEnableInitAt115k = true;
		List<UsbDeviceInfo> list2 = new List<UsbDeviceInfo>();
		list2.AddRange(new ConnectionUsbAtheros().FindDevices());
		openConnectionMultipleTypesForm.UsbDisplayedDeviceList = list2;
		btAPI.UpdateEventTimeout(btConfigSettings.EventTimeout);
		btMainWorkerThread.EventTimeout = btConfigSettings.EventTimeout;
		if (openConnectionMultipleTypesForm.ShowDialog() != DialogResult.OK)
		{
			return;
		}
		if (openConnectionMultipleTypesForm.SelectedConnectionType == OpenConnectionMultipleTypesForm.ConnectionType.SERIAL)
		{
			string serialSelectedPortName = openConnectionMultipleTypesForm.SerialSelectedPortName;
			int serialSelectedDataRate = openConnectionMultipleTypesForm.SerialSelectedDataRate;
			Handshake serialSelectedHandShake = openConnectionMultipleTypesForm.SerialSelectedHandShake;
			bool enableInitAt115k = openConnectionMultipleTypesForm.EnableInitAt115k;
			bool enableHciInit = openConnectionMultipleTypesForm.EnableHciInit;
			int serialSelectedInitialDataRate = openConnectionMultipleTypesForm.SerialSelectedInitialDataRate;
			bool sharedConnectionEnabled = openConnectionMultipleTypesForm.SharedConnectionEnabled;
			try
			{
				if (sharedConnectionEnabled)
				{
					if (!APIBase.IsSharedConnectionActiveAndOpen(serialSelectedPortName))
					{
						APIBase.OpenNewSharedSerialConnection(serialSelectedPortName, serialSelectedDataRate, serialSelectedHandShake);
					}
					btAPI.AddToSharedSerialConnection(serialSelectedPortName);
				}
				else if (enableHciInit && serialSelectedDataRate != serialSelectedInitialDataRate)
				{
					btAPI.OpenSerialConnection(serialSelectedPortName, serialSelectedInitialDataRate, serialSelectedDataRate, serialSelectedHandShake, enableHciInit);
					btMainWorkerThread.ReadBDAddressAndVersion();
				}
				else
				{
					btAPI.OpenSerialConnection(serialSelectedPortName, serialSelectedDataRate, serialSelectedHandShake, enableInitAt115k);
				}
				toolStripStatusLabelConnectionInfo.Text = serialSelectedPortName.ToString() + " Baud Rate:" + serialSelectedDataRate + " | " + serialSelectedHandShake;
			}
			catch (Exception ex)
			{
				logger.Enqueue(new QCRPG.Framework.LogMessage(LogMessageType.Error, ex));
				MessageBoxes.ShowErrorBox("Error opening BT serial connection");
				return;
			}
		}
		else if (openConnectionMultipleTypesForm.SelectedConnectionType == OpenConnectionMultipleTypesForm.ConnectionType.USB)
		{
			UsbDeviceInfo usbSelectedDeviceInfo = openConnectionMultipleTypesForm.UsbSelectedDeviceInfo;
			try
			{
				btAPI.OpenUsbConnection(usbSelectedDeviceInfo);
				toolStripStatusLabelConnectionInfo.Text = usbSelectedDeviceInfo.ToString();
			}
			catch (Exception ex2)
			{
				logger.Enqueue(new QCRPG.Framework.LogMessage(LogMessageType.Error, ex2));
				MessageBoxes.ShowErrorBox("Error opening BT USB connection");
				return;
			}
		}
		else if (openConnectionMultipleTypesForm.SelectedConnectionType == OpenConnectionMultipleTypesForm.ConnectionType.DIAG)
		{
			string diagSelectedPortName = openConnectionMultipleTypesForm.DiagSelectedPortName;
			LibraryModeEnum diagSelectedLibraryMode = openConnectionMultipleTypesForm.DiagSelectedLibraryMode;
			Phone.TargetType diagSelectedTargetType = openConnectionMultipleTypesForm.DiagSelectedTargetType;
			Phone.DiagType diagSelectedDiagType = openConnectionMultipleTypesForm.DiagSelectedDiagType;
			try
			{
				if (!APIBase.IsSharedConnectionActiveAndOpen(diagSelectedPortName))
				{
					APIBase.OpenNewSharedDiagConnection(diagSelectedPortName, diagSelectedLibraryMode, diagSelectedTargetType, diagSelectedDiagType);
				}
				btAPI.AddToSharedDiagConnection(diagSelectedPortName, openConnectionMultipleTypesForm.DiagTypeList[(int)diagSelectedDiagType]);
				btAPI.SetDiagLibraryMode(openConnectionMultipleTypesForm.DiagTypeList[(int)diagSelectedDiagType], openConnectionMultipleTypesForm.DiagLibraryModeList[(int)diagSelectedLibraryMode]);
				toolStripStatusLabelConnectionInfo.Text = diagSelectedPortName.ToString() + "   Mode: " + openConnectionMultipleTypesForm.DiagLibraryModeList[(int)diagSelectedLibraryMode] + "   Target: " + openConnectionMultipleTypesForm.DiagTargetTypeList[(int)diagSelectedTargetType] + "   Type: " + openConnectionMultipleTypesForm.DiagTypeList[(int)diagSelectedDiagType];
			}
			catch (Exception ex3)
			{
				logger.Enqueue(new QCRPG.Framework.LogMessage(LogMessageType.Error, ex3));
				MessageBoxes.ShowErrorBox("Error opening BT diag connection");
				return;
			}
		}
		else
		{
			if (openConnectionMultipleTypesForm.SelectedConnectionType != OpenConnectionMultipleTypesForm.ConnectionType.TCP)
			{
				string text = "Unsupported connection type: " + openConnectionMultipleTypesForm.SelectedConnectionType;
				logger.Enqueue(new QCRPG.Framework.LogMessage(LogMessageType.Error, text));
				MessageBoxes.ShowErrorBox(text);
				return;
			}
			string tCPSelectedIPAddress = openConnectionMultipleTypesForm.TCPSelectedIPAddress;
			int portNumber = int.Parse(openConnectionMultipleTypesForm.TCPSelectedPortNumber);
			string text2 = tCPSelectedIPAddress + ":" + portNumber;
			try
			{
				btAPI.OpenTCPConnection(tCPSelectedIPAddress, portNumber, openConnectionMultipleTypesForm.TCPSelectedWillsAndDos, openConnectionMultipleTypesForm.TCPSelectedAddProtocolByte);
				toolStripStatusLabelConnectionInfo.Text = text2.ToString();
			}
			catch (Exception ex4)
			{
				logger.Enqueue(new QCRPG.Framework.LogMessage(LogMessageType.Error, ex4));
				MessageBoxes.ShowErrorBox("Error opening BT TCP connection");
				return;
			}
		}
		SetControlEnables(ControlEnableMode.CONNECTION_OPENED);
		if (((ToolStripMenuItem)setDefaultPatch).Checked)
		{
			btMainWorkerThread.PatchFirmware(btConfigSettings.DefaultBTPatchFile, btConfigSettings.SkipPatchResponseChecks);
		}
		if (((ToolStripMenuItem)setDefaultNVM).Checked)
		{
			btMainWorkerThread.WriteNvm(btConfigSettings.DefaultBTNVMFile, btConfigSettings.SkipNVMResponseChecks, ProtocolHCI.SleepModeState.NONE, btConfigSettings.ConvertNVMToBin);
		}
		if (((ToolStripMenuItem)setStartupCommand).Checked)
		{
			btMainWorkerThread.StartupCommands(localHostDefaultOption, scanEnable);
		}
		if (((ToolStripMenuItem)setStartupCommandLEOnly).Checked)
		{
			btMainWorkerThread.StartupCommandsLEOnly();
		}
		if (((ToolStripMenuItem)setDefaultScript).Checked)
		{
			try
			{
				string scriptFileLocation = Path.GetDirectoryName(btConfigSettings.DefaultBTScriptFile) + "\\";
				btMainWorkerThread.StartDefaultScript(btConfigSettings.DefaultBTScriptFile, scriptFileLocation);
			}
			catch (ArgumentException ex5)
			{
				logger.Enqueue(new QCRPG.Framework.LogMessage(LogMessageType.Error, "Unable to load default patch, path is not valid. " + ex5));
			}
			catch (Exception ex6)
			{
				logger.Enqueue(new QCRPG.Framework.LogMessage(LogMessageType.Error, "failed to load default patch. " + ex6));
			}
		}
		if (((ToolStripMenuItem)setStartupCommand).Checked)
		{
			btMainWorkerThread.ReadBDAddressAndVersion();
		}
		if (((ToolStripMenuItem)setStartupCommandLEOnly).Checked)
		{
			btMainWorkerThread.ReadBDAddress();
		}
		UpdateBTDeviceListView(null);
		UpdateLEDeviceListView(null);
		BTLERemoteDeviceInfoList.btRemoteDeviceInfo.Clear();
		BTLERemoteDeviceInfoList.leRemoteDeviceInfo.Clear();
	}

	private void CloseConnectionHandler(object sender, EventArgs e)
	{
		try
		{
			bool flag = openConnectionMultipleTypesForm.SelectedConnectionType == OpenConnectionMultipleTypesForm.ConnectionType.DIAG;
			string portName = (flag ? openConnectionMultipleTypesForm.DiagSelectedPortName : openConnectionMultipleTypesForm.SerialSelectedPortName);
			if (openConnectionMultipleTypesForm.SharedConnectionEnabled)
			{
				APIBase.CloseSharedSerialConnection(portName);
			}
			else if (flag)
			{
				APIBase.CloseSharedDiagConnection(portName);
			}
			else
			{
				btAPI.CloseConnection();
			}
			toolStripStatusLabelConnectionInfo.Text = "Not Connected";
		}
		catch (Exception ex)
		{
			logger.Enqueue(new QCRPG.Framework.LogMessage(LogMessageType.Error, ex));
			MessageBoxes.ShowErrorBox("Error closing BT connection");
			SetControlEnables(ControlEnableMode.CONNECTION_CLOSED);
			return;
		}
		SetControlEnables(ControlEnableMode.CONNECTION_CLOSED);
	}

	private void LoadDefaultNvmHandler(object sender, EventArgs e)
	{
		base.TitleBarMessage = string.Empty;
		UpdateTitleBar();
		btMainWorkerThread.WriteNvm(btConfigSettings.DefaultBTNVMFile, btConfigSettings.SkipNVMResponseChecks, ProtocolHCI.SleepModeState.NONE, btConfigSettings.ConvertNVMToBin);
	}

	private void LoadNvmHandler(object sender, EventArgs e)
	{
		OpenFileDialog openFileDialog = new OpenFileDialog();
		openFileDialog.Filter = "NVM Files (*.nvm)|*.nvm| BIN/TLV Files (*.BIN)|*.BIN|All Files (*.*)|*.*";
		if (openFileDialog.ShowDialog() == DialogResult.OK)
		{
			base.TitleBarMessage = string.Empty;
			UpdateTitleBar();
			btMainWorkerThread.WriteNvm(openFileDialog.FileName, btConfigSettings.SkipNVMResponseChecks, ProtocolHCI.SleepModeState.NONE, btConfigSettings.ConvertNVMToBin);
		}
	}

	private void LoadDefaultPatchHandler(object sender, EventArgs e)
	{
		btMainWorkerThread.PatchFirmware(btConfigSettings.DefaultBTPatchFile, btConfigSettings.SkipPatchResponseChecks);
	}

	private void LoadPatchHandler(object sender, EventArgs e)
	{
		OpenFileDialog openFileDialog = new OpenFileDialog();
		openFileDialog.Filter = "Patch Image Files  (*.tlv)|*.tlv|(*.img)|*.img|All Files (*.*)|*.*";
		if (openFileDialog.ShowDialog() == DialogResult.OK)
		{
			btMainWorkerThread.PatchFirmware(openFileDialog.FileName, btConfigSettings.SkipPatchResponseChecks);
		}
	}

	public void NotifyObserver(ConnectionStateChangeInfo connectionStateChangeInfo)
	{
		if (invokeControl == null)
		{
			UpdateControlEnablesFromConnectionStateChangeInfo(connectionStateChangeInfo);
			return;
		}
		invokeControl.BeginInvoke((MethodInvoker)delegate
		{
			UpdateControlEnablesFromConnectionStateChangeInfo(connectionStateChangeInfo);
		});
	}

	private void UpdateControlEnablesFromConnectionStateChangeInfo(ConnectionStateChangeInfo connectionStateChangeInfo)
	{
		if (!connectionStateChangeInfo.openStateChanged)
		{
			return;
		}
		if (connectionStateChangeInfo.openState)
		{
			SetControlEnables(ControlEnableMode.CONNECTION_OPENED);
			if (Monitor.TryEnter(btAPI))
			{
				try
				{
					SetSleepModeAtStartup();
				}
				finally
				{
					Monitor.Exit(btAPI);
				}
			}
		}
		else
		{
			SetControlEnables(ControlEnableMode.CONNECTION_CLOSED);
		}
	}

	private void SetSleepModeAtStartup()
	{
	}

	protected virtual void SetControlEnables(ControlEnableMode controlEnableMode)
	{
		switch (controlEnableMode)
		{
		case ControlEnableMode.DEFAULT:
			SetControlEnables(ControlEnableMode.CONNECTION_CLOSED);
			break;
		case ControlEnableMode.CONNECTION_OPENED:
			dropDownMenu.DropDownItems["Open Connection"].Enabled = false;
			toolStripButtonOpenConnection.Enabled = false;
			dropDownMenu.DropDownItems["Close Connection"].Enabled = true;
			toolStripButtonCloseConnection.Enabled = true;
			dropDownMenu.DropDownItems["Load NVM File"].Enabled = true;
			toolStripButtonLoadDefaultNvm.Enabled = true;
			toolStripButtonLoadNvm.Enabled = true;
			dropDownMenu.DropDownItems["Load Patch File"].Enabled = true;
			toolStripButtonLoadDefaultPatch.Enabled = true;
			toolStripButtonLoadPatch.Enabled = true;
			dropDownMenu.DropDownItems["Load Script File"].Enabled = true;
			updateConnectionPacketInfoTimer.Enabled = true;
			break;
		case ControlEnableMode.CONNECTION_CLOSED:
			dropDownMenu.DropDownItems["Close Connection"].Enabled = false;
			toolStripButtonCloseConnection.Enabled = false;
			dropDownMenu.DropDownItems["Open Connection"].Enabled = true;
			toolStripButtonOpenConnection.Enabled = true;
			dropDownMenu.DropDownItems["Load NVM File"].Enabled = true;
			toolStripButtonLoadDefaultNvm.Enabled = false;
			toolStripButtonLoadNvm.Enabled = false;
			dropDownMenu.DropDownItems["Load Patch File"].Enabled = true;
			toolStripButtonLoadDefaultPatch.Enabled = false;
			toolStripButtonLoadPatch.Enabled = false;
			dropDownMenu.DropDownItems["Load Script File"].Enabled = true;
			updateConnectionPacketInfoTimer.Enabled = false;
			break;
		default:
			throw new Exception("Unhandled control enable mode: " + controlEnableMode);
		}
	}

	private void listView_MouseUp(object sender, MouseEventArgs e)
	{
		ListView listView = sender as ListView;
		if (e.Button == MouseButtons.Right)
		{
			ListViewItem itemAt = listView.GetItemAt(e.X, e.Y);
			if (itemAt == null)
			{
				return;
			}
			itemAt.Selected = true;
			if (itemAt.Text == "Local Bluetooth Devices")
			{
				localBTDeviceContextMenuStrip.Show(Cursor.Position);
			}
			else if (itemAt.Text == "Local LE Devices")
			{
				localLEDeviceContextMenuStrip.Show(Cursor.Position);
			}
			else if (itemAt.Index > LocalBTDeviceIndex && itemAt.Index < LocalLEDeviceIndex)
			{
				if (!itemAt.Checked)
				{
					if ((string)itemAt.Tag == "SCO")
					{
						connectToolStripMenuItem.Enabled = false;
						disconnectToolStripMenuItem.Enabled = true;
						addSCOConnectionToolStripMenuItem.Enabled = false;
						setupModifyESCOConnectionToolStripMenuItem.Enabled = false;
						setupModifyEnhancedConnectionToolStripMenuItem.Enabled = false;
						changeConnectionPacketTypeToolStripMenuItem.Enabled = true;
						changeLinkSupervisionTimeoutToolStripMenuItem.Enabled = false;
						requestAuthenticationToolStripMenuItem.Enabled = false;
						enableToolStripMenuItem.Enabled = false;
						disableToolStripMenuItem.Enabled = false;
						switchRoleToolStripMenuItem.Enabled = false;
						changeConnectionLinkKeyToolStripMenuItem.Enabled = false;
						semiPermanentToolStripMenuItem.Enabled = false;
						temporaryToolStripMenuItem.Enabled = false;
						readRemoteInformationToolStripMenuItem.Enabled = false;
						parkModeToolStripMenuItem.Enabled = false;
						exitParkModeToolStripMenuItem.Enabled = false;
						sniffModeToolStripMenuItem.Enabled = false;
						exitSniffModeToolStripMenuItem.Enabled = false;
						holdModeToolStripMenuItem.Enabled = false;
						editSelectedDeviceToolStripMenuItem.Enabled = false;
						removeSelectedDeviceToolStripMenuItem.Enabled = false;
					}
					else if ((string)itemAt.Tag == "ESCO")
					{
						connectToolStripMenuItem.Enabled = false;
						disconnectToolStripMenuItem.Enabled = true;
						addSCOConnectionToolStripMenuItem.Enabled = false;
						setupModifyESCOConnectionToolStripMenuItem.Enabled = true;
						setupModifyEnhancedConnectionToolStripMenuItem.Enabled = true;
						changeConnectionPacketTypeToolStripMenuItem.Enabled = false;
						changeLinkSupervisionTimeoutToolStripMenuItem.Enabled = false;
						requestAuthenticationToolStripMenuItem.Enabled = false;
						enableToolStripMenuItem.Enabled = false;
						disableToolStripMenuItem.Enabled = false;
						switchRoleToolStripMenuItem.Enabled = false;
						changeConnectionLinkKeyToolStripMenuItem.Enabled = false;
						semiPermanentToolStripMenuItem.Enabled = false;
						temporaryToolStripMenuItem.Enabled = false;
						readRemoteInformationToolStripMenuItem.Enabled = false;
						parkModeToolStripMenuItem.Enabled = false;
						exitParkModeToolStripMenuItem.Enabled = false;
						sniffModeToolStripMenuItem.Enabled = false;
						exitSniffModeToolStripMenuItem.Enabled = false;
						holdModeToolStripMenuItem.Enabled = false;
						editSelectedDeviceToolStripMenuItem.Enabled = false;
						removeSelectedDeviceToolStripMenuItem.Enabled = false;
					}
					else
					{
						connectToolStripMenuItem.Enabled = true;
						disconnectToolStripMenuItem.Enabled = false;
						addSCOConnectionToolStripMenuItem.Enabled = false;
						setupModifyESCOConnectionToolStripMenuItem.Enabled = false;
						setupModifyEnhancedConnectionToolStripMenuItem.Enabled = false;
						changeConnectionPacketTypeToolStripMenuItem.Enabled = false;
						changeLinkSupervisionTimeoutToolStripMenuItem.Enabled = false;
						requestAuthenticationToolStripMenuItem.Enabled = false;
						enableToolStripMenuItem.Enabled = false;
						disableToolStripMenuItem.Enabled = false;
						switchRoleToolStripMenuItem.Enabled = false;
						changeConnectionLinkKeyToolStripMenuItem.Enabled = false;
						semiPermanentToolStripMenuItem.Enabled = false;
						temporaryToolStripMenuItem.Enabled = false;
						readRemoteInformationToolStripMenuItem.Enabled = true;
						remoteVersionToolStripMenuItem.Enabled = false;
						remoteSupportedFeaturesToolStripMenuItem.Enabled = false;
						remoteExtendedFeaturesToolStripMenuItem.Enabled = false;
						afhChannelMapToolStripMenuItem.Enabled = false;
						parkModeToolStripMenuItem.Enabled = false;
						exitParkModeToolStripMenuItem.Enabled = false;
						sniffModeToolStripMenuItem.Enabled = false;
						exitSniffModeToolStripMenuItem.Enabled = false;
						holdModeToolStripMenuItem.Enabled = false;
						editSelectedDeviceToolStripMenuItem.Enabled = false;
						removeSelectedDeviceToolStripMenuItem.Enabled = true;
					}
					btDeviceConnectionContextMenuStrip.Show(Cursor.Position);
					return;
				}
				if ((string)itemAt.Tag == "Sniff")
				{
					connectToolStripMenuItem.Enabled = false;
					disconnectToolStripMenuItem.Enabled = true;
					addSCOConnectionToolStripMenuItem.Enabled = true;
					setupModifyESCOConnectionToolStripMenuItem.Enabled = true;
					setupModifyEnhancedConnectionToolStripMenuItem.Enabled = true;
					changeConnectionPacketTypeToolStripMenuItem.Enabled = true;
					changeLinkSupervisionTimeoutToolStripMenuItem.Enabled = true;
					requestAuthenticationToolStripMenuItem.Enabled = true;
					enableToolStripMenuItem.Enabled = true;
					disableToolStripMenuItem.Enabled = true;
					switchRoleToolStripMenuItem.Enabled = true;
					changeConnectionLinkKeyToolStripMenuItem.Enabled = true;
					semiPermanentToolStripMenuItem.Enabled = true;
					temporaryToolStripMenuItem.Enabled = true;
					readRemoteInformationToolStripMenuItem.Enabled = true;
					remoteVersionToolStripMenuItem.Enabled = true;
					remoteSupportedFeaturesToolStripMenuItem.Enabled = true;
					remoteExtendedFeaturesToolStripMenuItem.Enabled = true;
					afhChannelMapToolStripMenuItem.Enabled = true;
					parkModeToolStripMenuItem.Enabled = false;
					exitParkModeToolStripMenuItem.Enabled = false;
					sniffModeToolStripMenuItem.Enabled = false;
					exitSniffModeToolStripMenuItem.Enabled = true;
					holdModeToolStripMenuItem.Enabled = false;
					editSelectedDeviceToolStripMenuItem.Enabled = true;
					removeSelectedDeviceToolStripMenuItem.Enabled = false;
				}
				else if ((string)itemAt.Tag == "Hold")
				{
					connectToolStripMenuItem.Enabled = false;
					disconnectToolStripMenuItem.Enabled = true;
					addSCOConnectionToolStripMenuItem.Enabled = true;
					setupModifyESCOConnectionToolStripMenuItem.Enabled = true;
					setupModifyEnhancedConnectionToolStripMenuItem.Enabled = true;
					changeConnectionPacketTypeToolStripMenuItem.Enabled = true;
					changeLinkSupervisionTimeoutToolStripMenuItem.Enabled = true;
					requestAuthenticationToolStripMenuItem.Enabled = true;
					enableToolStripMenuItem.Enabled = true;
					disableToolStripMenuItem.Enabled = true;
					switchRoleToolStripMenuItem.Enabled = true;
					changeConnectionLinkKeyToolStripMenuItem.Enabled = true;
					semiPermanentToolStripMenuItem.Enabled = true;
					temporaryToolStripMenuItem.Enabled = true;
					readRemoteInformationToolStripMenuItem.Enabled = true;
					remoteVersionToolStripMenuItem.Enabled = true;
					remoteSupportedFeaturesToolStripMenuItem.Enabled = true;
					remoteExtendedFeaturesToolStripMenuItem.Enabled = true;
					afhChannelMapToolStripMenuItem.Enabled = true;
					parkModeToolStripMenuItem.Enabled = false;
					exitParkModeToolStripMenuItem.Enabled = false;
					sniffModeToolStripMenuItem.Enabled = false;
					exitSniffModeToolStripMenuItem.Enabled = false;
					holdModeToolStripMenuItem.Enabled = false;
					editSelectedDeviceToolStripMenuItem.Enabled = true;
					removeSelectedDeviceToolStripMenuItem.Enabled = false;
				}
				else if ((string)itemAt.Tag == "Park")
				{
					connectToolStripMenuItem.Enabled = false;
					disconnectToolStripMenuItem.Enabled = true;
					addSCOConnectionToolStripMenuItem.Enabled = true;
					setupModifyESCOConnectionToolStripMenuItem.Enabled = true;
					setupModifyEnhancedConnectionToolStripMenuItem.Enabled = true;
					changeConnectionPacketTypeToolStripMenuItem.Enabled = true;
					changeLinkSupervisionTimeoutToolStripMenuItem.Enabled = true;
					requestAuthenticationToolStripMenuItem.Enabled = true;
					enableToolStripMenuItem.Enabled = true;
					disableToolStripMenuItem.Enabled = true;
					switchRoleToolStripMenuItem.Enabled = true;
					changeConnectionLinkKeyToolStripMenuItem.Enabled = true;
					semiPermanentToolStripMenuItem.Enabled = true;
					temporaryToolStripMenuItem.Enabled = true;
					readRemoteInformationToolStripMenuItem.Enabled = true;
					remoteVersionToolStripMenuItem.Enabled = true;
					remoteSupportedFeaturesToolStripMenuItem.Enabled = true;
					remoteExtendedFeaturesToolStripMenuItem.Enabled = true;
					afhChannelMapToolStripMenuItem.Enabled = true;
					parkModeToolStripMenuItem.Enabled = false;
					exitParkModeToolStripMenuItem.Enabled = true;
					sniffModeToolStripMenuItem.Enabled = false;
					exitSniffModeToolStripMenuItem.Enabled = false;
					holdModeToolStripMenuItem.Enabled = false;
					editSelectedDeviceToolStripMenuItem.Enabled = true;
					removeSelectedDeviceToolStripMenuItem.Enabled = false;
				}
				else if (itemAt.Tag == null)
				{
					connectToolStripMenuItem.Enabled = false;
					disconnectToolStripMenuItem.Enabled = true;
					addSCOConnectionToolStripMenuItem.Enabled = true;
					setupModifyESCOConnectionToolStripMenuItem.Enabled = true;
					setupModifyEnhancedConnectionToolStripMenuItem.Enabled = true;
					changeConnectionPacketTypeToolStripMenuItem.Enabled = true;
					changeLinkSupervisionTimeoutToolStripMenuItem.Enabled = true;
					requestAuthenticationToolStripMenuItem.Enabled = true;
					enableToolStripMenuItem.Enabled = true;
					disableToolStripMenuItem.Enabled = true;
					switchRoleToolStripMenuItem.Enabled = true;
					changeConnectionLinkKeyToolStripMenuItem.Enabled = true;
					semiPermanentToolStripMenuItem.Enabled = true;
					temporaryToolStripMenuItem.Enabled = true;
					readRemoteInformationToolStripMenuItem.Enabled = true;
					remoteVersionToolStripMenuItem.Enabled = true;
					remoteSupportedFeaturesToolStripMenuItem.Enabled = true;
					remoteExtendedFeaturesToolStripMenuItem.Enabled = true;
					afhChannelMapToolStripMenuItem.Enabled = true;
					parkModeToolStripMenuItem.Enabled = true;
					exitParkModeToolStripMenuItem.Enabled = false;
					sniffModeToolStripMenuItem.Enabled = true;
					exitSniffModeToolStripMenuItem.Enabled = false;
					holdModeToolStripMenuItem.Enabled = true;
					editSelectedDeviceToolStripMenuItem.Enabled = true;
					removeSelectedDeviceToolStripMenuItem.Enabled = false;
				}
				btDeviceConnectionContextMenuStrip.Show(Cursor.Position);
			}
			else
			{
				if (itemAt.Index <= LocalLEDeviceIndex)
				{
					return;
				}
				if (!itemAt.Checked)
				{
					leConnectToolStripMenuItem.Enabled = true;
					leDisconnectToolStripMenuItem.Enabled = false;
					readRemoteVersionInfoToolStripMenuItem.Enabled = false;
					readChannelMapToolStripMenuItem.Enabled = false;
					readRemoteFeaturesToolStripMenuItem.Enabled = false;
					updateConnectionToolStripMenuItem.Enabled = false;
					startEncryptionToolStripMenuItem.Enabled = false;
					editSelectedLEDeviceToolStripMenuItem.Enabled = true;
					removeSelectedLEDeviceToolStripMenuItem.Enabled = true;
					leDeviceConnectionContextMenuStrip.Show(Cursor.Position);
					leDisconnectCisMenuItem.Enabled = false;
					leCreateCisMenuItem.Enabled = false;
					return;
				}
				leConnectToolStripMenuItem.Enabled = false;
				leDisconnectToolStripMenuItem.Enabled = true;
				readRemoteVersionInfoToolStripMenuItem.Enabled = true;
				readChannelMapToolStripMenuItem.Enabled = true;
				readRemoteFeaturesToolStripMenuItem.Enabled = true;
				updateConnectionToolStripMenuItem.Enabled = true;
				startEncryptionToolStripMenuItem.Enabled = true;
				editSelectedLEDeviceToolStripMenuItem.Enabled = true;
				removeSelectedLEDeviceToolStripMenuItem.Enabled = false;
				leDeviceConnectionContextMenuStrip.Show(Cursor.Position);
				if (leCreateCisMenuItem.DropDownItems.Count > 0)
				{
					leCreateCisMenuItem.Enabled = true;
				}
				if (leDisconnectCisMenuItem.DropDownItems.Count > 0)
				{
					leDisconnectCisMenuItem.Enabled = true;
				}
			}
		}
		else
		{
			if (e.Button != MouseButtons.Left)
			{
				return;
			}
			ListViewItem itemAt2 = listView.GetItemAt(e.X, e.Y);
			if (itemAt2 == null)
			{
				return;
			}
			itemAt2.Selected = true;
			if (itemAt2.Index > LocalBTDeviceIndex && itemAt2.Index < LocalLEDeviceIndex)
			{
				if (itemAt2.Checked)
				{
					UpdateBTConnectionHandler(itemAt2.Text);
					btDataTransferUserControl.SelectDataTransferControl(currentBTConnectionHandler, isBtConnection: true);
					scoOverHciUserControl.Enabled = true;
					FileDataTranfer(enable: true);
					return;
				}
				if ((string)itemAt2.Tag == "SCO" || (string)itemAt2.Tag == "ESCO")
				{
					UpdateBTSCOConnectionHandler(itemAt2.SubItems[1].Text);
					btDataTransferUserControl.ClearGui();
					scoOverHciUserControl.Enabled = false;
					FileDataTranfer(enable: false);
					return;
				}
				btDataTransferUserControl.ClearGui();
				scoOverHciUserControl.Enabled = false;
				FileDataTranfer(enable: false);
				if (toolStripStatusLabelEmpty != null)
				{
					toolStripStatusLabelEmpty.Text = "Connection Handle: NA";
				}
			}
			else if (itemAt2.Index > LocalLEDeviceIndex)
			{
				scoOverHciUserControl.Enabled = false;
				if (itemAt2.Checked)
				{
					UpdateLEConnectionHandler(itemAt2.Text);
					btDataTransferUserControl.SelectDataTransferControl(currentBTConnectionHandler, isBtConnection: false);
					FileDataTranfer(enable: false);
					return;
				}
				if (toolStripStatusLabelEmpty != null)
				{
					toolStripStatusLabelEmpty.Text = "Connection Handle: NA";
				}
				if (toolStripStatusLabelCisHandle != null)
				{
					toolStripStatusLabelCisHandle.Text = "CIS Handle: NA";
				}
				btDataTransferUserControl.ClearGui();
				FileDataTranfer(enable: false);
			}
			else if (itemAt2.Index == LocalBTDeviceIndex || itemAt2.Index == LocalLEDeviceIndex)
			{
				btDataTransferUserControl.ClearGui();
				FileDataTranfer(enable: false);
			}
		}
	}

	private void LocalBTDeviceContextMenuStrip()
	{
		localBTDeviceContextMenuStrip.Items.AddRange(new ToolStripItem[9] { InquiryToolStripMenuItem, resetToolStripMenuItem, scanEnableToolStripMenuItem, enableDUTModeToolStripMenuItem, readLocalInformationToolStripMenuItem, toolStripSeparator1, addNewDeviceToolStripMenuItem, toolStripSeparator2, bluetoothOptionsToolStripMenuItem });
		localBTDeviceContextMenuStrip.Name = "localDeviceContextMenuStrip";
		localBTDeviceContextMenuStrip.Size = new Size(181, 148);
		InquiryToolStripMenuItem.Name = "InquiryToolStripMenuItem";
		InquiryToolStripMenuItem.Size = new Size(180, 22);
		InquiryToolStripMenuItem.Text = "Inquiry";
		InquiryToolStripMenuItem.Click += InquiryToolStripMenuItem_Click;
		resetToolStripMenuItem.Name = "resetToolStripMenuItem";
		resetToolStripMenuItem.Size = new Size(180, 22);
		resetToolStripMenuItem.Text = "Reset";
		resetToolStripMenuItem.Click += resetToolStripMenuItem_Click;
		scanEnableToolStripMenuItem.Name = "scanEnableToolStripMenuItem";
		scanEnableToolStripMenuItem.Size = new Size(180, 22);
		scanEnableToolStripMenuItem.Text = "Scan Enable...";
		scanEnableToolStripMenuItem.Click += scanEnableToolStripMenuItem_Click;
		enableDUTModeToolStripMenuItem.Name = "enableDUTModeToolStripMenuItem";
		enableDUTModeToolStripMenuItem.Size = new Size(180, 22);
		enableDUTModeToolStripMenuItem.Text = "Enable DUT Mode";
		enableDUTModeToolStripMenuItem.Click += enableDUTModeToolStripMenuItem_Click;
		readLocalInformationToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[5] { nameToolStripMenuItem, bdAddressToolStripMenuItem, versionToolStripMenuItem, supportedFeaturesToolStripMenuItem, extendedFeaturesToolStripMenuItem });
		readLocalInformationToolStripMenuItem.Name = "readLocalInformationToolStripMenuItem";
		readLocalInformationToolStripMenuItem.Size = new Size(180, 22);
		readLocalInformationToolStripMenuItem.Text = "Read Local Information";
		nameToolStripMenuItem.Name = "nameToolStripMenuItem";
		nameToolStripMenuItem.Size = new Size(112, 22);
		nameToolStripMenuItem.Text = "Name";
		nameToolStripMenuItem.Click += nameToolStripMenuItem_Click;
		bdAddressToolStripMenuItem.Name = "bdAddressToolStripMenuItem";
		bdAddressToolStripMenuItem.Size = new Size(112, 22);
		bdAddressToolStripMenuItem.Text = "BD Address";
		bdAddressToolStripMenuItem.Click += bdAddressToolStripMenuItem_Click;
		versionToolStripMenuItem.Name = "versionToolStripMenuItem";
		versionToolStripMenuItem.Size = new Size(112, 22);
		versionToolStripMenuItem.Text = "Version";
		versionToolStripMenuItem.Click += versionToolStripMenuItem_Click;
		supportedFeaturesToolStripMenuItem.Name = "supportedFeaturesToolStripMenuItem";
		supportedFeaturesToolStripMenuItem.Size = new Size(112, 22);
		supportedFeaturesToolStripMenuItem.Text = "Supported Features";
		supportedFeaturesToolStripMenuItem.Click += supportedFeaturesToolStripMenuItem_Click;
		extendedFeaturesToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[2] { page1ToolStripMenuItem, page2ToolStripMenuItem });
		extendedFeaturesToolStripMenuItem.Name = "extendedFeaturesToolStripMenuItem";
		extendedFeaturesToolStripMenuItem.Size = new Size(112, 22);
		extendedFeaturesToolStripMenuItem.Text = "Extended Features";
		page1ToolStripMenuItem.Name = "page1ToolStripMenuItem";
		page1ToolStripMenuItem.Size = new Size(112, 22);
		page1ToolStripMenuItem.Text = "Page 1";
		page1ToolStripMenuItem.Click += page1ToolStripMenuItem_Click;
		page2ToolStripMenuItem.Name = "page2ToolStripMenuItem";
		page2ToolStripMenuItem.Size = new Size(112, 22);
		page2ToolStripMenuItem.Text = "Page 2";
		page2ToolStripMenuItem.Click += page2ToolStripMenuItem_Click;
		toolStripSeparator1.Name = "toolStripSeparator1";
		toolStripSeparator1.Size = new Size(177, 6);
		addNewDeviceToolStripMenuItem.Name = "addNewDeviceToolStripMenuItem";
		addNewDeviceToolStripMenuItem.Size = new Size(180, 22);
		addNewDeviceToolStripMenuItem.Text = "Add New Device...";
		addNewDeviceToolStripMenuItem.Click += addNewDeviceToolStripMenuItem_Click;
		toolStripSeparator2.Name = "toolStripSeparator2";
		toolStripSeparator2.Size = new Size(177, 6);
		bluetoothOptionsToolStripMenuItem.Name = "bluetoothOptionsToolStripMenuItem";
		bluetoothOptionsToolStripMenuItem.Size = new Size(180, 22);
		bluetoothOptionsToolStripMenuItem.Text = "Bluetooth Options...";
		bluetoothOptionsToolStripMenuItem.Click += bluetoothOptionsToolStripMenuItem_Click;
	}

	private void LocalLEDeviceContextMenuStrip()
	{
		localLEDeviceContextMenuStrip.Items.AddRange(new ToolStripItem[10] { advertiseToolStripMenuItem, scanToolStripMenuItem, toolStripSeparator11, addNewLEDeviceToolStripMenuItem, toolStripSeparator12, leSetCigMenuItem, leRemoveCigMenuItem, toolStripSeparator16, cancelConnectionToolStripMenuItem, lEOptionsToolStripMenuItem });
		localLEDeviceContextMenuStrip.Name = "localLEDeviceContextMenuStrip";
		localLEDeviceContextMenuStrip.Size = new Size(177, 126);
		advertiseToolStripMenuItem.Name = "advertiseToolStripMenuItem";
		advertiseToolStripMenuItem.Size = new Size(176, 22);
		advertiseToolStripMenuItem.Text = "Advertise";
		advertiseToolStripMenuItem.Click += advertiseToolStripMenuItem_Click;
		scanToolStripMenuItem.Name = "scanToolStripMenuItem";
		scanToolStripMenuItem.Size = new Size(176, 22);
		scanToolStripMenuItem.Text = "Scan";
		scanToolStripMenuItem.Click += scanToolStripMenuItem_Click;
		toolStripSeparator11.Name = "toolStripSeparator11";
		toolStripSeparator11.Size = new Size(173, 6);
		addNewLEDeviceToolStripMenuItem.Name = "addNewLEDeviceToolStripMenuItem";
		addNewLEDeviceToolStripMenuItem.Size = new Size(176, 22);
		addNewLEDeviceToolStripMenuItem.Text = "Add New LE Device";
		addNewLEDeviceToolStripMenuItem.Click += addNewLEDeviceToolStripMenuItem_Click;
		toolStripSeparator12.Name = "toolStripSeparator12";
		toolStripSeparator12.Size = new Size(173, 6);
		leSetCigMenuItem.Name = "leSetCigMenuItem";
		leSetCigMenuItem.Size = new Size(176, 22);
		leSetCigMenuItem.Text = "Set CIG";
		PopulateSetCigMenuDefault(numCis);
		leRemoveCigMenuItem.Name = "leRemoveCigMenuItem";
		leRemoveCigMenuItem.Size = new Size(176, 22);
		leRemoveCigMenuItem.Text = "Remove CIG";
		leRemoveCigMenuItem.Enabled = false;
		leRemoveCigMenuItem.Click += leRemoveCig_Click;
		toolStripSeparator16.Name = "toolStripSeparator16";
		toolStripSeparator16.Size = new Size(173, 6);
		cancelConnectionToolStripMenuItem.Name = "cancelConnectionToolStripMenuItem";
		cancelConnectionToolStripMenuItem.Size = new Size(176, 22);
		cancelConnectionToolStripMenuItem.Text = "Cancel Connection";
		cancelConnectionToolStripMenuItem.Click += cancelConnectionToolStripMenuItem_Click;
		lEOptionsToolStripMenuItem.Name = "lEOptionsToolStripMenuItem";
		lEOptionsToolStripMenuItem.Size = new Size(176, 22);
		lEOptionsToolStripMenuItem.Text = "LE Options...";
		lEOptionsToolStripMenuItem.Click += LEOptionsHandler;
	}

	private void PopulateSetCigMenuDefault(uint numCis)
	{
		leSetCigMenuItem.DropDownItems.Clear();
		for (int i = 0; i < numCis; i++)
		{
			leSetCigMenuItem.DropDownItems.Add(new ToolStripMenuItem("CIS ID " + i)
			{
				Name = "CIS ID " + i
			});
			leSetCigMenuItem.DropDownItems[leSetCigMenuItem.DropDownItems.Count - 1].Click += leSetCig_Click;
		}
		if (leSetCigMenuItem.DropDownItems.Count == 0)
		{
			leSetCigMenuItem.Enabled = false;
		}
		else
		{
			leSetCigMenuItem.Enabled = true;
		}
	}

	private void BTDeviceConnectionContextMenuStrip()
	{
		btDeviceConnectionContextMenuStrip.Items.AddRange(new ToolStripItem[19]
		{
			connectToolStripMenuItem, disconnectToolStripMenuItem, setupModifyEnhancedConnectionToolStripMenuItem, setupModifyESCOConnectionToolStripMenuItem, addSCOConnectionToolStripMenuItem, toolStripSeparator3, changeConnectionPacketTypeToolStripMenuItem, toolStripSeparator4, requestAuthenticationToolStripMenuItem, connectionEncryptionToolStripMenuItem,
			switchRoleToolStripMenuItem, toolStripSeparator5, changeConnectionLinkKeyToolStripMenuItem, masterLinkKeyToolStripMenuItem, readRemoteInformationToolStripMenuItem, toolStripSeparator6, lowPowerModeToolStripMenuItem, toolStripSeparator9, deviceSettingsToolStripMenuItem
		});
		btDeviceConnectionContextMenuStrip.Name = "deviceConnectionContextMenuStrip";
		btDeviceConnectionContextMenuStrip.Size = new Size(258, 370);
		connectToolStripMenuItem.Name = "connectToolStripMenuItem";
		connectToolStripMenuItem.Size = new Size(257, 22);
		connectToolStripMenuItem.Text = "Connect";
		connectToolStripMenuItem.Click += btConnectToolStripMenuItem_Click;
		disconnectToolStripMenuItem.Enabled = false;
		disconnectToolStripMenuItem.Name = "disconnectToolStripMenuItem";
		disconnectToolStripMenuItem.Size = new Size(257, 22);
		disconnectToolStripMenuItem.Text = "Disconnect";
		disconnectToolStripMenuItem.Click += disconnectToolStripMenuItem_Click;
		setupModifyEnhancedConnectionToolStripMenuItem.Enabled = false;
		setupModifyEnhancedConnectionToolStripMenuItem.Name = "setupModifyEnhancedConnectionToolStripMenuItem";
		setupModifyEnhancedConnectionToolStripMenuItem.Size = new Size(257, 22);
		setupModifyEnhancedConnectionToolStripMenuItem.Text = "Enhanced Setup/Modify eSCO Connection";
		setupModifyEnhancedConnectionToolStripMenuItem.Click += setupModifyEnhancedConnectionToolStripMenuItem_Click;
		setupModifyESCOConnectionToolStripMenuItem.Enabled = false;
		setupModifyESCOConnectionToolStripMenuItem.Name = "setupModifyESCOConnectionToolStripMenuItem";
		setupModifyESCOConnectionToolStripMenuItem.Size = new Size(257, 22);
		setupModifyESCOConnectionToolStripMenuItem.Text = "Setup/Modify eSCO Connection";
		setupModifyESCOConnectionToolStripMenuItem.Click += setupModifyESCOConnectionToolStripMenuItem_Click;
		addSCOConnectionToolStripMenuItem.Enabled = false;
		addSCOConnectionToolStripMenuItem.Name = "addSCOConnectionToolStripMenuItem";
		addSCOConnectionToolStripMenuItem.Size = new Size(257, 22);
		addSCOConnectionToolStripMenuItem.Text = "Add SCO Connection";
		addSCOConnectionToolStripMenuItem.Click += addSCOConnectionToolStripMenuItem_Click;
		toolStripSeparator3.Name = "toolStripSeparator3";
		toolStripSeparator3.Size = new Size(254, 6);
		changeConnectionPacketTypeToolStripMenuItem.Enabled = false;
		changeConnectionPacketTypeToolStripMenuItem.Name = "changeConnectionPacketTypeToolStripMenuItem";
		changeConnectionPacketTypeToolStripMenuItem.Size = new Size(257, 22);
		changeConnectionPacketTypeToolStripMenuItem.Text = "Change Connection Packet Type";
		changeConnectionPacketTypeToolStripMenuItem.Click += changeConnectionPacketTypeToolStripMenuItem_Click;
		changeLinkSupervisionTimeoutToolStripMenuItem.Enabled = false;
		changeLinkSupervisionTimeoutToolStripMenuItem.Name = "changeLinkSupervisionTimeoutToolStripMenuItem";
		changeLinkSupervisionTimeoutToolStripMenuItem.Size = new Size(257, 22);
		changeLinkSupervisionTimeoutToolStripMenuItem.Text = "Change Time Supervision Timeout";
		toolStripSeparator4.Name = "toolStripSeparator4";
		toolStripSeparator4.Size = new Size(254, 6);
		requestAuthenticationToolStripMenuItem.Enabled = false;
		requestAuthenticationToolStripMenuItem.Name = "requestAuthenticationToolStripMenuItem";
		requestAuthenticationToolStripMenuItem.Size = new Size(257, 22);
		requestAuthenticationToolStripMenuItem.Text = "Request Authentication";
		requestAuthenticationToolStripMenuItem.Click += requestAuthenticationToolStripMenuItem_Click;
		connectionEncryptionToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[2] { enableToolStripMenuItem, disableToolStripMenuItem });
		connectionEncryptionToolStripMenuItem.Name = "connectionEncryptionToolStripMenuItem";
		connectionEncryptionToolStripMenuItem.Size = new Size(257, 22);
		connectionEncryptionToolStripMenuItem.Text = "Connection Encryption";
		enableToolStripMenuItem.Enabled = false;
		enableToolStripMenuItem.Name = "enableToolStripMenuItem";
		enableToolStripMenuItem.Size = new Size(112, 22);
		enableToolStripMenuItem.Text = "Enable";
		enableToolStripMenuItem.Click += enableToolStripMenuItem_Click;
		disableToolStripMenuItem.Enabled = false;
		disableToolStripMenuItem.Name = "disableToolStripMenuItem";
		disableToolStripMenuItem.Size = new Size(112, 22);
		disableToolStripMenuItem.Text = "Disable";
		disableToolStripMenuItem.Click += disableToolStripMenuItem_Click;
		switchRoleToolStripMenuItem.Enabled = false;
		switchRoleToolStripMenuItem.Name = "switchRoleToolStripMenuItem";
		switchRoleToolStripMenuItem.Size = new Size(257, 22);
		switchRoleToolStripMenuItem.Text = "Switch Role";
		switchRoleToolStripMenuItem.Click += switchRoleToolStripMenuItem_Click;
		toolStripSeparator5.Name = "toolStripSeparator5";
		toolStripSeparator5.Size = new Size(254, 6);
		changeConnectionLinkKeyToolStripMenuItem.Enabled = false;
		changeConnectionLinkKeyToolStripMenuItem.Name = "changeConnectionLinkKeyToolStripMenuItem";
		changeConnectionLinkKeyToolStripMenuItem.Size = new Size(257, 22);
		changeConnectionLinkKeyToolStripMenuItem.Text = "Change Connection Link Key";
		masterLinkKeyToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[2] { semiPermanentToolStripMenuItem, temporaryToolStripMenuItem });
		masterLinkKeyToolStripMenuItem.Name = "masterLinkKeyToolStripMenuItem";
		masterLinkKeyToolStripMenuItem.Size = new Size(257, 22);
		masterLinkKeyToolStripMenuItem.Text = "Master Link Key";
		semiPermanentToolStripMenuItem.Enabled = false;
		semiPermanentToolStripMenuItem.Name = "semiPermanentToolStripMenuItem";
		semiPermanentToolStripMenuItem.Size = new Size(161, 22);
		semiPermanentToolStripMenuItem.Text = "Semi Permanent";
		semiPermanentToolStripMenuItem.Click += semiPermanentToolStripMenuItem_Click;
		temporaryToolStripMenuItem.Enabled = false;
		temporaryToolStripMenuItem.Name = "temporaryToolStripMenuItem";
		temporaryToolStripMenuItem.Size = new Size(161, 22);
		temporaryToolStripMenuItem.Text = "Temporary";
		temporaryToolStripMenuItem.Click += temporaryToolStripMenuItem_Click;
		readRemoteInformationToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[5] { remoteNameToolStripMenuItem, remoteVersionToolStripMenuItem, remoteSupportedFeaturesToolStripMenuItem, remoteExtendedFeaturesToolStripMenuItem, afhChannelMapToolStripMenuItem });
		readRemoteInformationToolStripMenuItem.Name = "readRemoteInformationToolStripMenuItem";
		readRemoteInformationToolStripMenuItem.Size = new Size(257, 22);
		readRemoteInformationToolStripMenuItem.Text = "Read Remote Information";
		remoteNameToolStripMenuItem.Name = "remoteNameToolStripMenuItem";
		remoteNameToolStripMenuItem.Size = new Size(112, 22);
		remoteNameToolStripMenuItem.Text = "Name";
		remoteNameToolStripMenuItem.Click += remoteNameToolStripMenuItem_Click;
		remoteVersionToolStripMenuItem.Name = "remoteVersionToolStripMenuItem";
		remoteVersionToolStripMenuItem.Size = new Size(112, 22);
		remoteVersionToolStripMenuItem.Text = "Version";
		remoteVersionToolStripMenuItem.Click += remoteVersionToolStripMenuItem_Click;
		remoteSupportedFeaturesToolStripMenuItem.Name = "remoteSupportedFeaturesToolStripMenuItem";
		remoteSupportedFeaturesToolStripMenuItem.Size = new Size(112, 22);
		remoteSupportedFeaturesToolStripMenuItem.Text = "Supported Features";
		remoteSupportedFeaturesToolStripMenuItem.Click += remoteSupportedFeaturesToolStripMenuItem_Click;
		remoteExtendedFeaturesToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[2] { remotePage1ToolStripMenuItem, remotePage2ToolStripMenuItem });
		remoteExtendedFeaturesToolStripMenuItem.Name = "remoteExtendedFeaturesToolStripMenuItem";
		remoteExtendedFeaturesToolStripMenuItem.Size = new Size(112, 22);
		remoteExtendedFeaturesToolStripMenuItem.Text = "Extended Features";
		remotePage1ToolStripMenuItem.Name = "remotePage1ToolStripMenuItem";
		remotePage1ToolStripMenuItem.Size = new Size(112, 22);
		remotePage1ToolStripMenuItem.Text = "Page 1";
		remotePage1ToolStripMenuItem.Click += remotePage1ToolStripMenuItem_Click;
		remotePage2ToolStripMenuItem.Name = "remotePage2ToolStripMenuItem";
		remotePage2ToolStripMenuItem.Size = new Size(112, 22);
		remotePage2ToolStripMenuItem.Text = "Page 2";
		remotePage2ToolStripMenuItem.Click += remotePage2ToolStripMenuItem_Click;
		afhChannelMapToolStripMenuItem.Name = "afhChannelMapToolStripMenuItem";
		afhChannelMapToolStripMenuItem.Size = new Size(112, 22);
		afhChannelMapToolStripMenuItem.Text = "AFH Channel Map";
		afhChannelMapToolStripMenuItem.Click += afhChannelMapToolStripMenuItem_Click;
		toolStripSeparator6.Name = "toolStripSeparator6";
		toolStripSeparator6.Size = new Size(254, 6);
		lowPowerModeToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[7] { parkModeToolStripMenuItem, exitParkModeToolStripMenuItem, toolStripSeparator7, sniffModeToolStripMenuItem, exitSniffModeToolStripMenuItem, toolStripSeparator8, holdModeToolStripMenuItem });
		lowPowerModeToolStripMenuItem.Name = "lowPowerModeToolStripMenuItem";
		lowPowerModeToolStripMenuItem.Size = new Size(257, 22);
		lowPowerModeToolStripMenuItem.Text = "Low Power Modes";
		parkModeToolStripMenuItem.Enabled = false;
		parkModeToolStripMenuItem.Name = "parkModeToolStripMenuItem";
		parkModeToolStripMenuItem.Size = new Size(153, 22);
		parkModeToolStripMenuItem.Text = "Park Mode";
		parkModeToolStripMenuItem.Click += parkModeToolStripMenuItem_Click;
		exitParkModeToolStripMenuItem.Enabled = false;
		exitParkModeToolStripMenuItem.Name = "exitParkModeToolStripMenuItem";
		exitParkModeToolStripMenuItem.Size = new Size(153, 22);
		exitParkModeToolStripMenuItem.Text = "Exit Park Mode";
		toolStripSeparator7.Name = "toolStripSeparator7";
		toolStripSeparator7.Size = new Size(150, 6);
		sniffModeToolStripMenuItem.Enabled = false;
		sniffModeToolStripMenuItem.Name = "sniffModeToolStripMenuItem";
		sniffModeToolStripMenuItem.Size = new Size(153, 22);
		sniffModeToolStripMenuItem.Text = "Sniff Mode";
		sniffModeToolStripMenuItem.Click += sniffModeToolStripMenuItem_Click;
		exitSniffModeToolStripMenuItem.Enabled = false;
		exitSniffModeToolStripMenuItem.Name = "exitSniffModeToolStripMenuItem";
		exitSniffModeToolStripMenuItem.Size = new Size(153, 22);
		exitSniffModeToolStripMenuItem.Text = "Exit Sniff Mode";
		exitSniffModeToolStripMenuItem.Click += exitSniffModeToolStripMenuItem_Click;
		toolStripSeparator8.Name = "toolStripSeparator8";
		toolStripSeparator8.Size = new Size(150, 6);
		holdModeToolStripMenuItem.Enabled = false;
		holdModeToolStripMenuItem.Name = "holdModeToolStripMenuItem";
		holdModeToolStripMenuItem.Size = new Size(153, 22);
		holdModeToolStripMenuItem.Text = "Hold Mode";
		holdModeToolStripMenuItem.Click += holdModeToolStripMenuItem_Click;
		toolStripSeparator9.Name = "toolStripSeparator9";
		toolStripSeparator9.Size = new Size(254, 6);
		deviceSettingsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[2] { editSelectedDeviceToolStripMenuItem, removeSelectedDeviceToolStripMenuItem });
		deviceSettingsToolStripMenuItem.Name = "deviceSettingsToolStripMenuItem";
		deviceSettingsToolStripMenuItem.Size = new Size(257, 22);
		deviceSettingsToolStripMenuItem.Text = "Device Settings";
		editSelectedDeviceToolStripMenuItem.Enabled = false;
		editSelectedDeviceToolStripMenuItem.Name = "editSelectedDeviceToolStripMenuItem";
		editSelectedDeviceToolStripMenuItem.Size = new Size(202, 22);
		editSelectedDeviceToolStripMenuItem.Text = "Edit Selected Device";
		editSelectedDeviceToolStripMenuItem.Click += editSelectedDeviceToolStripMenuItem_Click;
		removeSelectedDeviceToolStripMenuItem.Name = "removeSelectedDeviceToolStripMenuItem";
		removeSelectedDeviceToolStripMenuItem.Size = new Size(202, 22);
		removeSelectedDeviceToolStripMenuItem.Text = "Remove Selected Device";
		removeSelectedDeviceToolStripMenuItem.Click += removeSelectedDeviceToolStripMenuItem_Click;
		toolStripSeparator10.Name = "toolStripSeparator10";
		toolStripSeparator10.Size = new Size(254, 6);
		extendedInquiryResponseDataToolStripMenuItem.Enabled = false;
		extendedInquiryResponseDataToolStripMenuItem.Name = "extendedInquiryResponseDataToolStripMenuItem";
		extendedInquiryResponseDataToolStripMenuItem.Size = new Size(257, 22);
		extendedInquiryResponseDataToolStripMenuItem.Text = "Extended Inquiry Response Data";
	}

	private void LEDeviceConnectionContextMenuStrip()
	{
		leDeviceConnectionContextMenuStrip.Items.AddRange(new ToolStripItem[14]
		{
			leConnectToolStripMenuItem, leDisconnectToolStripMenuItem, toolStripSeparator13, readRemoteVersionInfoToolStripMenuItem, readChannelMapToolStripMenuItem, readRemoteFeaturesToolStripMenuItem, updateConnectionToolStripMenuItem, toolStripSeparator14, startEncryptionToolStripMenuItem, toolStripSeparator17,
			leCreateCisMenuItem, leDisconnectCisMenuItem, toolStripSeparator15, deviceLESettingsToolStripMenuItem
		});
		leDeviceConnectionContextMenuStrip.Name = "contextMenuStrip1";
		leDeviceConnectionContextMenuStrip.Size = new Size(211, 198);
		leConnectToolStripMenuItem.Name = "leConnectToolStripMenuItem";
		leConnectToolStripMenuItem.Size = new Size(210, 22);
		leConnectToolStripMenuItem.Text = "Connect";
		leConnectToolStripMenuItem.Click += leConnectToolStripMenuItem_Click;
		leDisconnectToolStripMenuItem.Enabled = false;
		leDisconnectToolStripMenuItem.Name = "leDisconnectToolStripMenuItem";
		leDisconnectToolStripMenuItem.Size = new Size(210, 22);
		leDisconnectToolStripMenuItem.Text = "Disconnect";
		leDisconnectToolStripMenuItem.Click += leDisconnectToolStripMenuItem_Click;
		toolStripSeparator13.Name = "toolStripSeparator13";
		toolStripSeparator13.Size = new Size(207, 6);
		readRemoteVersionInfoToolStripMenuItem.Enabled = false;
		readRemoteVersionInfoToolStripMenuItem.Name = "readRemoteVersionInfoToolStripMenuItem";
		readRemoteVersionInfoToolStripMenuItem.Size = new Size(210, 22);
		readRemoteVersionInfoToolStripMenuItem.Text = "Read Remote Version Info";
		readRemoteVersionInfoToolStripMenuItem.Click += readRemoteVersionInfoToolStripMenuItem_Click;
		readChannelMapToolStripMenuItem.Enabled = false;
		readChannelMapToolStripMenuItem.Name = "readChannelMapToolStripMenuItem";
		readChannelMapToolStripMenuItem.Size = new Size(210, 22);
		readChannelMapToolStripMenuItem.Text = "Read Channel Map";
		readChannelMapToolStripMenuItem.Click += readChannelMapToolStripMenuItem_Click;
		readRemoteFeaturesToolStripMenuItem.Enabled = false;
		readRemoteFeaturesToolStripMenuItem.Name = "readRemoteFeaturesToolStripMenuItem";
		readRemoteFeaturesToolStripMenuItem.Size = new Size(210, 22);
		readRemoteFeaturesToolStripMenuItem.Text = "Read Remote Features";
		readRemoteFeaturesToolStripMenuItem.Click += readRemoteFeatureToolStripMenuItem_Click;
		updateConnectionToolStripMenuItem.Enabled = false;
		updateConnectionToolStripMenuItem.Name = "updateConnectionToolStripMenuItem";
		updateConnectionToolStripMenuItem.Size = new Size(210, 22);
		updateConnectionToolStripMenuItem.Text = "Update Connection";
		updateConnectionToolStripMenuItem.Click += updateConnectionToolStripMenuItem_Click;
		toolStripSeparator14.Name = "toolStripSeparator14";
		toolStripSeparator14.Size = new Size(207, 6);
		startEncryptionToolStripMenuItem.Enabled = false;
		startEncryptionToolStripMenuItem.Name = "startEncryptionToolStripMenuItem";
		startEncryptionToolStripMenuItem.Size = new Size(210, 22);
		startEncryptionToolStripMenuItem.Text = "Start Encryption";
		startEncryptionToolStripMenuItem.Click += startEncryptionToolStripMenuItem_Click;
		toolStripSeparator17.Name = "toolStripSeparator17";
		toolStripSeparator17.Size = new Size(207, 6);
		leCreateCisMenuItem.Name = "leCreateCisMenuItem";
		leCreateCisMenuItem.Size = new Size(210, 22);
		leCreateCisMenuItem.Text = "Create CIS";
		leCreateCisMenuItem.Enabled = false;
		leDisconnectCisMenuItem.Name = "leDisconnectCisMenuItem";
		leDisconnectCisMenuItem.Size = new Size(210, 22);
		leDisconnectCisMenuItem.Text = "Disconnect CIS";
		leDisconnectCisMenuItem.Enabled = false;
		toolStripSeparator15.Name = "toolStripSeparator15";
		toolStripSeparator15.Size = new Size(207, 6);
		deviceLESettingsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[2] { editSelectedLEDeviceToolStripMenuItem, removeSelectedLEDeviceToolStripMenuItem });
		deviceLESettingsToolStripMenuItem.Name = "deviceSettingsToolStripMenuItem1";
		deviceLESettingsToolStripMenuItem.Size = new Size(210, 22);
		deviceLESettingsToolStripMenuItem.Text = "Device Settings";
		editSelectedLEDeviceToolStripMenuItem.Name = "editSelectedLEDeviceToolStripMenuItem";
		editSelectedLEDeviceToolStripMenuItem.Size = new Size(217, 22);
		editSelectedLEDeviceToolStripMenuItem.Text = "Edit Selected LE Device";
		editSelectedLEDeviceToolStripMenuItem.Click += editSelectedLEDeviceToolStripMenuItem_Click;
		removeSelectedLEDeviceToolStripMenuItem.Name = "removeSelectedLEDeviceToolStripMenuItem";
		removeSelectedLEDeviceToolStripMenuItem.Size = new Size(217, 22);
		removeSelectedLEDeviceToolStripMenuItem.Text = "Remove Selected LE Device";
		removeSelectedLEDeviceToolStripMenuItem.Click += removeSelectedLEDeviceToolStripMenuItem_Click;
	}

	private void InquiryToolStripMenuItem_Click(object sender, EventArgs e)
	{
		InquiryHandler();
	}

	private void bringupToolsStripMenuItem_Click(object sender, EventArgs e)
	{
		int serialSelectedDataRate = openConnectionMultipleTypesForm.SerialSelectedDataRate;
		Handshake serialSelectedHandShake = openConnectionMultipleTypesForm.SerialSelectedHandShake;
		ConnectionSpecificProtocolInfo.SleepModeState sleepMode = btAPI.GetSleepMode();
		try
		{
			string serialSelectedPortName = openConnectionMultipleTypesForm.SerialSelectedPortName;
			Handshake handShakeFromString = openConnectionMultipleTypesForm.GetHandShakeFromString(btConfigSettings.BringUpInitialFlowControl);
			btMainWorkerThread.HostBringup(serialSelectedPortName, btConfigSettings.BringUpInitialRate, serialSelectedDataRate, handShakeFromString, serialSelectedHandShake, btConfigSettings.BringupSendWakeByte, btConfigSettings.DefaultBTPatchFile, btConfigSettings.DefaultBTNVMFile, sleepMode, btConfigSettings.ConvertNVMToBin);
			toolStripStatusLabelConnectionInfo.Text = serialSelectedPortName.ToString() + " Baud Rate:" + serialSelectedDataRate + " | " + serialSelectedHandShake;
		}
		catch (Exception ex)
		{
			logger.Enqueue(new QCRPG.Framework.LogMessage(LogMessageType.Error, "Failed to Bringup Platform. " + ex));
		}
	}

	private void resetToolStripMenuItem_Click(object sender, EventArgs e)
	{
		if (((ToolStripMenuItem)setStartupCommand).Checked)
		{
			btMainWorkerThread.StartupCommands(localHostDefaultOption, scanEnable);
			btMainWorkerThread.ReadBDAddressAndVersion();
			return;
		}
		if (((ToolStripMenuItem)setStartupCommandLEOnly).Checked)
		{
			btMainWorkerThread.StartupCommandsLEOnly();
			btMainWorkerThread.ReadBDAddress();
			return;
		}
		Reset packet = new Reset();
		try
		{
			btAPI.Send(packet);
		}
		catch (Exception ex)
		{
			logger.Enqueue(new QCRPG.Framework.LogMessage(LogMessageType.Error, ex));
		}
	}

	private void scanEnableToolStripMenuItem_Click(object sender, EventArgs e)
	{
		ScanMode scanMode = new ScanMode();
		scanMode.scanEnable = scanEnable;
		scanMode.interlacedInquiryScan = enableInterlacedInquiryScan;
		scanMode.interlacedPageScan = enableInterlacedPageScan;
		scanMode.ShowDialog();
		if (scanMode.DialogResult != DialogResult.OK)
		{
			return;
		}
		WriteScanEnable writeScanEnable = new WriteScanEnable();
		writeScanEnable.UserFields.ScanEnable = (uint)scanMode.scanEnable;
		try
		{
			btAPI.Send(writeScanEnable);
			scanEnable = scanMode.scanEnable;
			if (scanMode.scanEnable == WriteScanEnable.UserFieldsWrapper.ScanEnableEnum.BOTH_SCANS_ENABLED)
			{
				toolStripButtonPageScan.Checked = true;
				toolStripButtonInquiryScan.Checked = true;
			}
			else if (scanMode.scanEnable == WriteScanEnable.UserFieldsWrapper.ScanEnableEnum.INQUIRY_SCAN_ENABLED)
			{
				toolStripButtonPageScan.Checked = false;
				toolStripButtonInquiryScan.Checked = true;
			}
			else if (scanMode.scanEnable == WriteScanEnable.UserFieldsWrapper.ScanEnableEnum.PAGE_SCAN_ENABLED)
			{
				toolStripButtonPageScan.Checked = true;
				toolStripButtonInquiryScan.Checked = false;
			}
			else if (scanMode.scanEnable == WriteScanEnable.UserFieldsWrapper.ScanEnableEnum.NO_SCANS_ENABLED)
			{
				toolStripButtonPageScan.Checked = false;
				toolStripButtonInquiryScan.Checked = false;
			}
			else
			{
				logger.Enqueue(new QCRPG.Framework.LogMessage(LogMessageType.Error, "Invalid scan mode"));
			}
		}
		catch (Exception ex)
		{
			logger.Enqueue(new QCRPG.Framework.LogMessage(LogMessageType.Error, "Fail to write scan enable. " + ex));
		}
	}

	private void enableDUTModeToolStripMenuItem_Click(object sender, EventArgs e)
	{
		EnableDeviceUnderTestMode packet = new EnableDeviceUnderTestMode();
		try
		{
			btAPI.Send(packet);
		}
		catch (Exception ex)
		{
			logger.Enqueue(new QCRPG.Framework.LogMessage(LogMessageType.Error, "Fail to enable DUT Mode. " + ex));
		}
	}

	private void nameToolStripMenuItem_Click(object sender, EventArgs e)
	{
		ReadLocalName packet = new ReadLocalName();
		try
		{
			btAPI.Send(packet);
		}
		catch (Exception ex)
		{
			logger.Enqueue(new QCRPG.Framework.LogMessage(LogMessageType.Error, "Fail to read Local Name. " + ex));
		}
	}

	private void bdAddressToolStripMenuItem_Click(object sender, EventArgs e)
	{
		btMainWorkerThread.ReadBDAddress();
	}

	private void versionToolStripMenuItem_Click(object sender, EventArgs e)
	{
		ReadLocalVersionInformation packet = new ReadLocalVersionInformation();
		try
		{
			btAPI.Send(packet);
		}
		catch (Exception ex)
		{
			logger.Enqueue(new QCRPG.Framework.LogMessage(LogMessageType.Error, "Fail to read Local Version Information. " + ex));
		}
	}

	private void supportedFeaturesToolStripMenuItem_Click(object sender, EventArgs e)
	{
		btMainWorkerThread.ReadLocalSupportedFeatures();
	}

	private void page1ToolStripMenuItem_Click(object sender, EventArgs e)
	{
		ReadLocalExtendedFeaturesHandler(1u);
	}

	private void page2ToolStripMenuItem_Click(object sender, EventArgs e)
	{
		ReadLocalExtendedFeaturesHandler(2u);
	}

	private void initBTOptions()
	{
		localHostDefaultOption = new LocalHostDefaultOption();
		localHostDefaultOption.dM1enable = DM1enable;
		localHostDefaultOption.dM3enable = DM3enable;
		localHostDefaultOption.dM5enable = DM5enable;
		localHostDefaultOption.dH1enable = DH1enable;
		localHostDefaultOption.dH3enable = DH3enable;
		localHostDefaultOption.dH5enable = DH5enable;
		localHostDefaultOption.twodH1enable = twoDH1enable;
		localHostDefaultOption.twodH3enable = twoDH3enable;
		localHostDefaultOption.twodH5enable = twoDH5enable;
		localHostDefaultOption.threedH1enable = threeDH1enable;
		localHostDefaultOption.threedH3enable = threeDH3enable;
		localHostDefaultOption.threedH5enable = threeDH5enable;
		localHostDefaultOption.scanEnableLocalHost = scanEnableLocalHost;
		localHostDefaultOption.hV1enable = HV1enable;
		localHostDefaultOption.hV2enable = HV2enable;
		localHostDefaultOption.hV3enable = HV3enable;
		localHostDefaultOption.allowRoleSwitch = allowRoleswitch;
		localHostDefaultOption.lmPerformMSswitch = lmPerformMSswitch;
		localHostDefaultOption.AutoAcceptConnectionReq = autoAcceptConnectionRequest;
		localHostDefaultOption.masterSlaveSwitch = MasterSlaveSwitchEnable;
		localHostDefaultOption.holdMode = HoldModeEnable;
		localHostDefaultOption.sniffMode = SniffModeEnable;
		localHostDefaultOption.parkMode = ParkModeEnable;
		localHostDefaultOption.maintainCurrentPower = MaintainCurrentPower;
		localHostDefaultOption.suspendPageScan = SuspendPageScanEnable;
		localHostDefaultOption.suspendInquiryScan = SuspendInquiryScanEnable;
		localHostDefaultOption.suspendPeriodicInquiries = SuspendPeriodicInquiriesEnable;
		localHostDefaultOption.transmitBandwidth = TransmitBandwidth;
		localHostDefaultOption.receiveBandwidth = ReceiveBandwidth;
		localHostDefaultOption.maxLatency = MaxLatency;
		localHostDefaultOption.msMaxLatency = MsMaxLatency;
		localHostDefaultOption.slotMaxLatency = SlotMaxLatency;
		localHostDefaultOption.voiceSetting = VoiceSetting;
		localHostDefaultOption.noRestrans = NoRestrans;
		localHostDefaultOption.optimizePower = OptimizePower;
		localHostDefaultOption.optimizeQuality = OptimizeQuality;
		localHostDefaultOption.dontCare = DontCare;
		localHostDefaultOption.escoHV1enable = ESCOHV1enable;
		localHostDefaultOption.escoHV2enable = ESCOHV2enable;
		localHostDefaultOption.escoHV3enable = ESCOHV3enable;
		localHostDefaultOption.escoEV3enable = ESCOEV3enable;
		localHostDefaultOption.escoEV4enable = ESCOEV4enable;
		localHostDefaultOption.escoEV5enable = ESCOEV5enable;
		localHostDefaultOption.esco2EV3enable = ESCO2EV3enable;
		localHostDefaultOption.esco3EV3enable = ESCO3EV3enable;
		localHostDefaultOption.esco2EV5enable = ESCO2EV5enable;
		localHostDefaultOption.esco3EV5enable = ESCO3EV5enable;
		localHostDefaultOption.airCodingCVSDEnable = AirCodingCVSDEnable;
		localHostDefaultOption.airCodingULawEnable = AirCodingULawEnable;
		localHostDefaultOption.airCodingALawEnable = AirCodingALawEnable;
		localHostDefaultOption.airCodingTransparentDataEnable = AirCodingTransparentDataEnable;
		localHostDefaultOption.linearPCMBitPosition = LinearPCMBitPosition;
		localHostDefaultOption.sampleSize8BitEnable = SampleSize8BitEnable;
		localHostDefaultOption.sampleSize16BitEnable = SampleSize16BitEnable;
		localHostDefaultOption.inputData1ComplEnable = InputData1ComplEnable;
		localHostDefaultOption.inputData2ComplEnable = InputData2ComplEnable;
		localHostDefaultOption.inputDataSignMagnitudeEnable = InputDataSignMagnitudeEnable;
		localHostDefaultOption.inputDataUnsignedEnable = InputDataUnsignedEnable;
		localHostDefaultOption.inputCodingLinearEnable = InputCodingLinearEnable;
		localHostDefaultOption.inputCodingALawEnable = InputCodingALawEnable;
		localHostDefaultOption.inputCodingULawEnable = InputCodingULawEnable;
		localHostDefaultOption.inputCodingCVSDEnable = InputCodingCVSDEnable;
		localHostDefaultOption.audioSourceCodecEnable = AudioSourceCodecEnable;
		localHostDefaultOption.audioSourceHCIEnable = AudioSourceHCIEnable;
		localHostDefaultOption.transmitBandwidth_enhSync = TransmitBandwidth_enhSync;
		localHostDefaultOption.receiveBandwidth_enhSync = ReceiveBandwidth_enhSync;
		localHostDefaultOption.maxLatency_enhSync = MaxLatency_enhSync;
		localHostDefaultOption.msMaxLatency_enhSync = MsMaxLatency_enhSync;
		localHostDefaultOption.slotMaxLatency_enhSync = SlotMaxLatency_enhSync;
		localHostDefaultOption.noRestrans_enhSync = NoRestrans_enhSync;
		localHostDefaultOption.optimizePower_enhSync = OptimizePower_enhSync;
		localHostDefaultOption.optimizeQuality_enhSync = OptimizeQuality_enhSync;
		localHostDefaultOption.dontCare_enhSync = DontCare_enhSync;
		localHostDefaultOption.escoHV1enable_enhSync = ESCOHV1enable_enhSync;
		localHostDefaultOption.escoHV2enable_enhSync = ESCOHV2enable_enhSync;
		localHostDefaultOption.escoHV3enable_enhSync = ESCOHV3enable_enhSync;
		localHostDefaultOption.escoEV3enable_enhSync = ESCOEV3enable_enhSync;
		localHostDefaultOption.escoEV4enable_enhSync = ESCOEV4enable_enhSync;
		localHostDefaultOption.escoEV5enable_enhSync = ESCOEV5enable_enhSync;
		localHostDefaultOption.esco2EV3enable_enhSync = ESCO2EV3enable_enhSync;
		localHostDefaultOption.esco3EV3enable_enhSync = ESCO3EV3enable_enhSync;
		localHostDefaultOption.esco2EV5enable_enhSync = ESCO2EV5enable_enhSync;
		localHostDefaultOption.esco3EV5enable_enhSync = ESCO3EV5enable_enhSync;
		localHostDefaultOption.InputDataPath = InputDataPath;
		localHostDefaultOption.OutputDataPath = OutputDataPath;
		localHostDefaultOption.TxRxCodingFormat = TxRxCodingFormat;
		localHostDefaultOption.PcmSamplePayload = PcmSamplePayload;
		localHostDefaultOption.IOCodedDataSize = IOCodedDataSize;
		localHostDefaultOption.IOPcmDataFormat = IOPcmDataFormat;
		localHostDefaultOption.IOCodingFormat = IOCodingFormat;
		localHostDefaultOption.EnhancedSync = useEnhancedParameters;
		localHostDefaultOption.lap = Lap;
		localHostDefaultOption.length = Length;
		localHostDefaultOption.responses = Responses;
		localHostDefaultOption.bluetoothAddress1 = AddressFilter[0];
		localHostDefaultOption.bluetoothAddress2 = AddressFilter[1];
		localHostDefaultOption.bluetoothAddress3 = AddressFilter[2];
		localHostDefaultOption.bluetoothAddress4 = AddressFilter[3];
		localHostDefaultOption.bluetoothAddress5 = AddressFilter[4];
		localHostDefaultOption.bluetoothAddress6 = AddressFilter[5];
		localHostDefaultOption.fecRequired = FECRequired;
		localHostDefaultOption.extendedInquiryResponse = ExtendedInquiryResponse;
		localHostDefaultOption.authenticationEnable = AuthenticationEnable;
		localHostDefaultOption.encryptionEnable = EncryptionEnable;
		localHostDefaultOption.simplePairingEnable = SimplePairingEnable;
		localHostDefaultOption.debugModeEnable = DebugModeEnable;
		localHostDefaultOption.secureConnectionsHostSupportEnable = SecureConnectionsHostSupportEnable;
		localHostDefaultOption.levelChoice = ((!LevelDefaultEnable) ? (LevelAuthenticationEnable ? 1 : (LevelPairingEnable ? 2 : 0)) : 0);
		localHostDefaultOption.linkKeyChoice = ((!LinkKeyASCIIEnable) ? (LinkKeyHexEnable ? 1 : 1) : 0);
		localHostDefaultOption.linkKey = LinkKey;
		localHostDefaultOption.pinCodeChoice = ((!PinCodeASCIIEnable) ? (PinCodeHexEnable ? 1 : 1) : 0);
		localHostDefaultOption.pinCode = PinCode;
		localHostDefaultOption.ioCapability = IOCapability;
		localHostDefaultOption.outOfBandDataPresent = OutOfBandDataPresent;
		localHostDefaultOption.confirmationRequestReply = ConfirmationRequestReply;
		localHostDefaultOption.passkeyRequestReply = PasskeyRequestReply;
		localHostDefaultOption.authenticationRequirements = AuthenticationRequirements;
		localHostDefaultOption.oobc = OOBC;
		localHostDefaultOption.oobr = OOBR;
	}

	private void bluetoothOptionsToolStripMenuItem_Click(object sender, EventArgs e)
	{
		localHostDefaultOption.ShowDialog();
		if (localHostDefaultOption.DialogResult != DialogResult.OK)
		{
			return;
		}
		DM1enable = localHostDefaultOption.dM1enable;
		DM3enable = localHostDefaultOption.dM3enable;
		DM5enable = localHostDefaultOption.dM5enable;
		DH1enable = localHostDefaultOption.dH1enable;
		DH3enable = localHostDefaultOption.dH3enable;
		DH5enable = localHostDefaultOption.dH5enable;
		twoDH1enable = localHostDefaultOption.twodH1enable;
		twoDH3enable = localHostDefaultOption.twodH3enable;
		twoDH5enable = localHostDefaultOption.twodH5enable;
		threeDH1enable = localHostDefaultOption.threedH1enable;
		threeDH3enable = localHostDefaultOption.threedH3enable;
		threeDH5enable = localHostDefaultOption.threedH5enable;
		scanEnableLocalHost = localHostDefaultOption.scanEnableLocalHost;
		HV1enable = localHostDefaultOption.hV1enable;
		HV2enable = localHostDefaultOption.hV2enable;
		HV3enable = localHostDefaultOption.hV3enable;
		allowRoleswitch = localHostDefaultOption.allowRoleSwitch;
		lmPerformMSswitch = localHostDefaultOption.lmPerformMSswitch;
		autoAcceptConnectionRequest = localHostDefaultOption.AutoAcceptConnectionReq;
		MasterSlaveSwitchEnable = localHostDefaultOption.masterSlaveSwitch;
		HoldModeEnable = localHostDefaultOption.holdMode;
		SniffModeEnable = localHostDefaultOption.sniffMode;
		ParkModeEnable = localHostDefaultOption.parkMode;
		MaintainCurrentPower = localHostDefaultOption.maintainCurrentPower;
		SuspendPageScanEnable = localHostDefaultOption.suspendPageScan;
		SuspendInquiryScanEnable = localHostDefaultOption.suspendInquiryScan;
		SuspendPeriodicInquiriesEnable = localHostDefaultOption.suspendPeriodicInquiries;
		if (localHostDefaultOption.writeHoldModeActivity)
		{
			if (MaintainCurrentPower)
			{
				btMainWorkerThread.WriteHoldModeActivity(DefaultHoldModeActivityInfo.DefaultHoldModeActivityToValue(DefaultHoldModeActivityEnum.Maintain_current_Power_State));
			}
			else
			{
				SuspendHoldModeActivityEnumCollection suspendHoldModeActivityEnumCollection = new SuspendHoldModeActivityEnumCollection();
				suspendHoldModeActivityEnumCollection.SuspendPageScan = (SuspendPageScanEnable ? EnableBitEnum.Enabled : EnableBitEnum.Disabled);
				suspendHoldModeActivityEnumCollection.SuspendInquiryScan = (SuspendInquiryScanEnable ? EnableBitEnum.Enabled : EnableBitEnum.Disabled);
				suspendHoldModeActivityEnumCollection.SuspendPeriodicInquiries = (SuspendPeriodicInquiriesEnable ? EnableBitEnum.Enabled : EnableBitEnum.Disabled);
				btMainWorkerThread.WriteHoldModeActivity(SuspendHoldModeActivityInfo.SuspendHoldModeActivityToValue(suspendHoldModeActivityEnumCollection));
			}
		}
		TransmitBandwidth = localHostDefaultOption.transmitBandwidth;
		ReceiveBandwidth = localHostDefaultOption.receiveBandwidth;
		MaxLatency = localHostDefaultOption.maxLatency;
		MsMaxLatency = localHostDefaultOption.msMaxLatency;
		SlotMaxLatency = localHostDefaultOption.slotMaxLatency;
		VoiceSetting = localHostDefaultOption.voiceSetting;
		NoRestrans = localHostDefaultOption.noRestrans;
		OptimizePower = localHostDefaultOption.optimizePower;
		OptimizeQuality = localHostDefaultOption.optimizeQuality;
		DontCare = localHostDefaultOption.dontCare;
		ESCOHV1enable = localHostDefaultOption.escoHV1enable;
		ESCOHV2enable = localHostDefaultOption.escoHV2enable;
		ESCOHV3enable = localHostDefaultOption.escoHV3enable;
		ESCOEV3enable = localHostDefaultOption.escoEV3enable;
		ESCOEV4enable = localHostDefaultOption.escoEV4enable;
		ESCOEV5enable = localHostDefaultOption.escoEV5enable;
		ESCO2EV3enable = localHostDefaultOption.esco2EV3enable;
		ESCO3EV3enable = localHostDefaultOption.esco3EV3enable;
		ESCO2EV5enable = localHostDefaultOption.esco2EV5enable;
		ESCO3EV5enable = localHostDefaultOption.esco3EV5enable;
		AirCodingCVSDEnable = localHostDefaultOption.airCodingCVSDEnable;
		AirCodingULawEnable = localHostDefaultOption.airCodingULawEnable;
		AirCodingALawEnable = localHostDefaultOption.airCodingALawEnable;
		AirCodingTransparentDataEnable = localHostDefaultOption.airCodingTransparentDataEnable;
		LinearPCMBitPosition = localHostDefaultOption.linearPCMBitPosition;
		SampleSize8BitEnable = localHostDefaultOption.sampleSize8BitEnable;
		SampleSize16BitEnable = localHostDefaultOption.sampleSize16BitEnable;
		InputData1ComplEnable = localHostDefaultOption.inputData1ComplEnable;
		InputData2ComplEnable = localHostDefaultOption.inputData2ComplEnable;
		InputDataSignMagnitudeEnable = localHostDefaultOption.inputDataSignMagnitudeEnable;
		InputDataUnsignedEnable = localHostDefaultOption.inputDataUnsignedEnable;
		InputCodingLinearEnable = localHostDefaultOption.inputCodingLinearEnable;
		InputCodingALawEnable = localHostDefaultOption.inputCodingALawEnable;
		InputCodingULawEnable = localHostDefaultOption.inputCodingULawEnable;
		InputCodingCVSDEnable = localHostDefaultOption.inputCodingCVSDEnable;
		AudioSourceCodecEnable = localHostDefaultOption.audioSourceCodecEnable;
		AudioSourceHCIEnable = localHostDefaultOption.audioSourceHCIEnable;
		TransmitBandwidth_enhSync = localHostDefaultOption.transmitBandwidth_enhSync;
		ReceiveBandwidth_enhSync = localHostDefaultOption.receiveBandwidth_enhSync;
		MaxLatency_enhSync = localHostDefaultOption.maxLatency_enhSync;
		MsMaxLatency_enhSync = localHostDefaultOption.msMaxLatency_enhSync;
		SlotMaxLatency_enhSync = localHostDefaultOption.slotMaxLatency_enhSync;
		NoRestrans_enhSync = localHostDefaultOption.noRestrans_enhSync;
		OptimizePower_enhSync = localHostDefaultOption.optimizePower_enhSync;
		OptimizeQuality_enhSync = localHostDefaultOption.optimizeQuality_enhSync;
		DontCare_enhSync = localHostDefaultOption.dontCare_enhSync;
		ESCOHV1enable_enhSync = localHostDefaultOption.escoHV1enable_enhSync;
		ESCOHV2enable_enhSync = localHostDefaultOption.escoHV2enable_enhSync;
		ESCOHV3enable_enhSync = localHostDefaultOption.escoHV3enable_enhSync;
		ESCOEV3enable_enhSync = localHostDefaultOption.escoEV3enable_enhSync;
		ESCOEV4enable_enhSync = localHostDefaultOption.escoEV4enable_enhSync;
		ESCOEV5enable_enhSync = localHostDefaultOption.escoEV5enable_enhSync;
		ESCO2EV3enable_enhSync = localHostDefaultOption.esco2EV3enable_enhSync;
		ESCO3EV3enable_enhSync = localHostDefaultOption.esco3EV3enable_enhSync;
		ESCO2EV5enable_enhSync = localHostDefaultOption.esco2EV5enable_enhSync;
		ESCO3EV5enable_enhSync = localHostDefaultOption.esco3EV5enable_enhSync;
		InputDataPath = localHostDefaultOption.InputDataPath;
		OutputDataPath = localHostDefaultOption.OutputDataPath;
		TxRxCodingFormat = localHostDefaultOption.TxRxCodingFormat;
		PcmSamplePayload = localHostDefaultOption.PcmSamplePayload;
		IOCodedDataSize = localHostDefaultOption.IOCodedDataSize;
		IOPcmDataFormat = localHostDefaultOption.IOPcmDataFormat;
		IOCodingFormat = localHostDefaultOption.IOCodingFormat;
		Lap = localHostDefaultOption.lap;
		Length = localHostDefaultOption.length;
		Responses = localHostDefaultOption.responses;
		AddressFilter[0] = localHostDefaultOption.bluetoothAddress1.ToUpper();
		AddressFilter[1] = localHostDefaultOption.bluetoothAddress2.ToUpper();
		AddressFilter[2] = localHostDefaultOption.bluetoothAddress3.ToUpper();
		AddressFilter[3] = localHostDefaultOption.bluetoothAddress4.ToUpper();
		AddressFilter[4] = localHostDefaultOption.bluetoothAddress5.ToUpper();
		AddressFilter[5] = localHostDefaultOption.bluetoothAddress6.ToUpper();
		FECRequired = localHostDefaultOption.fecRequired;
		ExtendedInquiryResponse = localHostDefaultOption.extendedInquiryResponse;
		if (localHostDefaultOption.writeExtendedInquiryResponse)
		{
			btMainWorkerThread.WriteExtendedInquiryResponse(FECRequired ? 1u : 0u, Conversions.HexStringToByteArray(ExtendedInquiryResponse));
		}
		AuthenticationEnable = localHostDefaultOption.authenticationEnable;
		EncryptionEnable = localHostDefaultOption.encryptionEnable;
		SimplePairingEnable = localHostDefaultOption.simplePairingEnable;
		DebugModeEnable = localHostDefaultOption.debugModeEnable;
		SecureConnectionsHostSupportEnable = localHostDefaultOption.secureConnectionsHostSupportEnable;
		if (localHostDefaultOption.writeAuthenticationAndEncryptionParameters)
		{
			btMainWorkerThread.WriteAuthenticationAndEncryptionParameters(AuthenticationEnable ? 1u : 0u, EncryptionEnable ? 1u : 0u, SimplePairingEnable ? 1u : 0u, DebugModeEnable ? 1u : 0u, SecureConnectionsHostSupportEnable ? 1u : 0u);
		}
		LevelDefaultEnable = localHostDefaultOption.levelChoice == 0;
		LevelAuthenticationEnable = localHostDefaultOption.levelChoice == 1;
		LevelPairingEnable = localHostDefaultOption.levelChoice == 2;
		LinkKeyASCIIEnable = localHostDefaultOption.linkKeyChoice == 0;
		LinkKeyHexEnable = localHostDefaultOption.linkKeyChoice == 1;
		LinkKey = localHostDefaultOption.linkKey;
		PinCodeASCIIEnable = localHostDefaultOption.pinCodeChoice == 0;
		PinCodeHexEnable = localHostDefaultOption.pinCodeChoice == 1;
		PinCode = localHostDefaultOption.pinCode;
		IOCapability = localHostDefaultOption.ioCapability;
		OutOfBandDataPresent = localHostDefaultOption.outOfBandDataPresent;
		ConfirmationRequestReply = localHostDefaultOption.confirmationRequestReply;
		PasskeyRequestReply = localHostDefaultOption.passkeyRequestReply;
		AuthenticationRequirements = localHostDefaultOption.authenticationRequirements;
		OOBC = localHostDefaultOption.oobc;
		OOBR = localHostDefaultOption.oobr;
		UpdateAllBTRemoteDeviceInfoWithLocalHostDefaultOptions();
	}

	private void addNewDeviceToolStripMenuItem_Click(object sender, EventArgs e)
	{
		remoteDeviceOptions = new RemoteDeviceOptions();
		remoteDeviceOptions.dm1enable = DM1enable;
		remoteDeviceOptions.dm3enable = DM3enable;
		remoteDeviceOptions.dm5enable = DM5enable;
		remoteDeviceOptions.dh1enable = DH1enable;
		remoteDeviceOptions.dh3enable = DH3enable;
		remoteDeviceOptions.dh5enable = DH5enable;
		remoteDeviceOptions.allowRoleSwitch = allowRoleswitch;
		remoteDeviceOptions.lmPerformMSswitch = lmPerformMSswitch;
		remoteDeviceOptions.hv1enable = HV1enable;
		remoteDeviceOptions.hv2enable = HV2enable;
		remoteDeviceOptions.hv3enable = HV3enable;
		remoteDeviceOptions.levelChoice = ((!LevelDefaultEnable) ? (LevelAuthenticationEnable ? 1 : (LevelPairingEnable ? 2 : 0)) : 0);
		remoteDeviceOptions.linkKeyChoice = ((!LinkKeyASCIIEnable) ? (LinkKeyHexEnable ? 1 : 1) : 0);
		remoteDeviceOptions.linkKey = LinkKey;
		remoteDeviceOptions.pinCodeChoice = ((!PinCodeASCIIEnable) ? (PinCodeHexEnable ? 1 : 1) : 0);
		remoteDeviceOptions.pinCode = PinCode;
		remoteDeviceOptions.ioCapability = IOCapability;
		remoteDeviceOptions.outOfBandDataPresent = OutOfBandDataPresent;
		remoteDeviceOptions.confirmationRequestReply = ConfirmationRequestReply;
		remoteDeviceOptions.passkeyRequestReply = PasskeyRequestReply;
		remoteDeviceOptions.authenticationRequirements = AuthenticationRequirements;
		remoteDeviceOptions.oobc = OOBC;
		remoteDeviceOptions.oobr = OOBR;
		remoteDeviceOptions.ShowDialog();
		if (remoteDeviceOptions.DialogResult == DialogResult.OK)
		{
			BTLERemoteDeviceInfo.BTRemoteDeviceInfo btRemoteDevice = default(BTLERemoteDeviceInfo.BTRemoteDeviceInfo);
			btRemoteDevice.bdAddress = remoteDeviceOptions.deviceAddress;
			btRemoteDevice.pageScanRepMode = remoteDeviceOptions.pageScanRepetitionMode;
			btRemoteDevice.dm1enable = remoteDeviceOptions.dm1enable;
			btRemoteDevice.dm3enable = remoteDeviceOptions.dm3enable;
			btRemoteDevice.dm5enable = remoteDeviceOptions.dm5enable;
			btRemoteDevice.dh1enable = remoteDeviceOptions.dh1enable;
			btRemoteDevice.dh3enable = remoteDeviceOptions.dh3enable;
			btRemoteDevice.dh5enable = remoteDeviceOptions.dh5enable;
			btRemoteDevice.allowRoleSwitch = remoteDeviceOptions.allowRoleSwitch;
			btRemoteDevice.lmPerformMSswitch = remoteDeviceOptions.lmPerformMSswitch;
			btRemoteDevice.hv1enable = remoteDeviceOptions.hv1enable;
			btRemoteDevice.hv2enable = remoteDeviceOptions.hv2enable;
			btRemoteDevice.hv3enable = remoteDeviceOptions.hv3enable;
			btRemoteDevice.clockOffsetValid = remoteDeviceOptions.clockOffsetValid;
			btRemoteDevice.levelDefaultEnable = remoteDeviceOptions.levelChoice == 0;
			btRemoteDevice.levelAuthenticationEnable = remoteDeviceOptions.levelChoice == 1;
			btRemoteDevice.levelPairingEnable = remoteDeviceOptions.levelChoice == 2;
			btRemoteDevice.linkKeyASCIIEnable = remoteDeviceOptions.linkKeyChoice == 0;
			btRemoteDevice.linkKeyHexEnable = remoteDeviceOptions.linkKeyChoice == 1;
			btRemoteDevice.linkKey = remoteDeviceOptions.linkKey;
			btRemoteDevice.pinCodeASCIIEnable = remoteDeviceOptions.pinCodeChoice == 0;
			btRemoteDevice.pinCodeHexEnable = remoteDeviceOptions.pinCodeChoice == 1;
			btRemoteDevice.pinCode = remoteDeviceOptions.pinCode;
			btRemoteDevice.ioCapability = remoteDeviceOptions.ioCapability;
			btRemoteDevice.outOfBandDataPresent = remoteDeviceOptions.outOfBandDataPresent;
			btRemoteDevice.confirmationRequestReply = remoteDeviceOptions.confirmationRequestReply;
			btRemoteDevice.passkeyRequestReply = remoteDeviceOptions.passkeyRequestReply;
			btRemoteDevice.authenticationRequirements = remoteDeviceOptions.authenticationRequirements;
			btRemoteDevice.oobc = remoteDeviceOptions.oobc;
			btRemoteDevice.oobr = remoteDeviceOptions.oobr;
			BTLERemoteDeviceInfoList.UpdateBTRemoteDeviceList(btRemoteDevice);
			ListViewItem listViewItem = new ListViewItem();
			listViewItem.ImageIndex = 0;
			listViewItem.Text = btRemoteDevice.bdAddress;
			listViewItem.SubItems.Add("Invalid");
			UpdateBTDeviceListView(listViewItem);
		}
	}

	private void advertiseToolStripMenuItem_Click(object sender, EventArgs e)
	{
		if (!advertiseToolStripMenuItem.Checked)
		{
			advertiseToolStripMenuItem.Tag = true;
			toolStripButtonLEAdvertising.Checked = true;
			LEAdvertiseHandler(enable: true);
		}
		else
		{
			advertiseToolStripMenuItem.Tag = false;
			toolStripButtonLEAdvertising.Checked = false;
			LEAdvertiseHandler(enable: false);
		}
	}

	private void scanToolStripMenuItem_Click(object sender, EventArgs e)
	{
		if (!scanToolStripMenuItem.Checked)
		{
			scanToolStripMenuItem.Tag = true;
			toolStripButtonLEScan.Checked = true;
			LEScanHandler(enable: true);
		}
		else
		{
			scanToolStripMenuItem.Tag = false;
			toolStripButtonLEScan.Checked = false;
			LEScanHandler(enable: false);
		}
	}

	private void addNewLEDeviceToolStripMenuItem_Click(object sender, EventArgs e)
	{
		LERemoteDeviceOptions lERemoteDeviceOptions = new LERemoteDeviceOptions();
		lERemoteDeviceOptions.PositiveReply = PositiveAutoReply;
		lERemoteDeviceOptions.NegativeReply = NegativeAutoReply;
		lERemoteDeviceOptions.LeLongTermKey = LELinkKey;
		lERemoteDeviceOptions.LeRandomNumber = RandomNumber;
		lERemoteDeviceOptions.LeEncryptedDiversifier = EncryptedDiversifier;
		lERemoteDeviceOptions.LeLongTermKeys = recentParameterSettings.leLongTermKeys;
		lERemoteDeviceOptions.LeRandomNumbers = recentParameterSettings.leRandomNumbers;
		lERemoteDeviceOptions.LEConnUpdateIntervalMin = (uint)ConnectionTimingMinInterval;
		lERemoteDeviceOptions.LEConnUpdateIntervalMax = (uint)ConnectionTimingMaxInterval;
		lERemoteDeviceOptions.LEConnUpdateTimeoutmsec = (uint)ConnectionTimingTimeout;
		lERemoteDeviceOptions.LEConnUpdateLatency = (uint)ConnectionTimingLatency;
		lERemoteDeviceOptions.LEConnUpdateCELengthMin = (uint)ConnectionEventTimingMinLength;
		lERemoteDeviceOptions.LEConnUpdateCELengthMax = (uint)ConnectionEventTimingMaxLength;
		lERemoteDeviceOptions.LEConnRequestPositiveAutoReply = connUpdateParamRequestPositiveReply;
		lERemoteDeviceOptions.LEConnRequestNegativeAutoReply = connUpdateParamRequestNegativeReply;
		DialogResult dialogResult = lERemoteDeviceOptions.ShowDialog();
		if (dialogResult == DialogResult.OK)
		{
			BTLERemoteDeviceInfo.LERemoteDeviceInfo leRemoteDevice = default(BTLERemoteDeviceInfo.LERemoteDeviceInfo);
			leRemoteDevice.bdAddress = lERemoteDeviceOptions.BDAddress;
			leRemoteDevice.keyReply = lERemoteDeviceOptions.PositiveReply;
			leRemoteDevice.longTermKey = lERemoteDeviceOptions.LeLongTermKey;
			leRemoteDevice.randomNumber = lERemoteDeviceOptions.LeRandomNumber;
			leRemoteDevice.encryptedDiversifier = lERemoteDeviceOptions.LeEncryptedDiversifier;
			leRemoteDevice.connUpdateIntervalMin = lERemoteDeviceOptions.LEConnUpdateIntervalMin;
			leRemoteDevice.connUpdateIntervalMax = lERemoteDeviceOptions.LEConnUpdateIntervalMax;
			leRemoteDevice.connUpdateTimeoutMs = lERemoteDeviceOptions.LEConnUpdateTimeoutmsec;
			leRemoteDevice.connUpdateLatency = lERemoteDeviceOptions.LEConnUpdateLatency;
			leRemoteDevice.connUpdateCELengthMin = lERemoteDeviceOptions.LEConnUpdateCELengthMin;
			leRemoteDevice.connUpdateCELengthMax = lERemoteDeviceOptions.LEConnUpdateCELengthMax;
			leRemoteDevice.connUpdateParamRequestAutoReply = lERemoteDeviceOptions.LEConnRequestPositiveAutoReply;
			leRemoteDevice.connUpdateParamReqRejectReason = lERemoteDeviceOptions.LEConnRequestRejectReason;
			BTLERemoteDeviceInfoList.UpdateLERemoteDeviceList(leRemoteDevice);
			ListViewItem listViewItem = new ListViewItem();
			listViewItem.ImageIndex = 0;
			listViewItem.Text = leRemoteDevice.bdAddress;
			listViewItem.SubItems.Add("Invalid");
			listViewItem.SubItems.Add("");
			UpdateLEDeviceListView(listViewItem);
		}
	}

	private void cancelConnectionToolStripMenuItem_Click(object sender, EventArgs e)
	{
		LeCreateConnectionCancel packet = new LeCreateConnectionCancel();
		try
		{
			btAPI.Send(packet);
		}
		catch (Exception ex)
		{
			logger.Enqueue(new QCRPG.Framework.LogMessage(LogMessageType.Error, ex));
		}
	}

	private void LEOptionsHandler(object sender, EventArgs e)
	{
		localHostULPOption = new LocalHostULPOption();
		localHostULPOption.maxInterval = (int)((double)Advertising_Interval_Max * 0.625);
		localHostULPOption.minInterval = (int)((double)Advertising_Interval_Min * 0.625);
		localHostULPOption.advertisingType = AdvertisingType;
		localHostULPOption.advertisingOwnAddressType = AdvertisingOwnAddressType;
		localHostULPOption.peerAddressType = PeerAddressType;
		localHostULPOption.peerAddress = PeerAddress;
		localHostULPOption.index37Enable = Index37Enable;
		localHostULPOption.index38Enable = Index38Enable;
		localHostULPOption.index39Enable = Index39Enable;
		localHostULPOption.advertisingFilterPolicy = AdvertisingFilterPolicy;
		localHostULPOption.advertisingData = AdvertisingData;
		localHostULPOption.scanResponseData = ScanResponseData;
		localHostULPOption.leScanType = LeScanType;
		localHostULPOption.scanOwnAddressType = ScanOwnAddressType;
		localHostULPOption.scanInterval = (int)((double)ScanInterval * 0.625);
		localHostULPOption.scanWindow = (int)((double)ScanWindow * 0.625);
		localHostULPOption.scanFilterPolicyEnable = ScanFilterPolicyEnable;
		localHostULPOption.scanFilterDuplicatesEnable = ScanFilterDuplicatesEnable;
		localHostULPOption.leFilterAddress = string.Join("", LEFilterAddress);
		localHostULPOption.creatConnectionOwnAddressType = CreateConnectionOwnAddressType;
		localHostULPOption.connectionTimingMinInterval = ConnectionTimingMinInterval;
		localHostULPOption.connectionTimingMaxInterval = ConnectionTimingMaxInterval;
		localHostULPOption.connectionTimingTimeout = ConnectionTimingTimeout;
		localHostULPOption.connectionTimingLatency = ConnectionTimingLatency;
		localHostULPOption.connectionEventTimingMinLength = ConnectionEventTimingMinLength;
		localHostULPOption.connectionEventTimingMaxLength = ConnectionEventTimingMaxLength;
		localHostULPOption.connectionScanTimingScanInterval = ConnectionScanTimingScanInterval;
		localHostULPOption.connectionScanTimingScanWindow = ConnectionScanTimingScanWindow;
		localHostULPOption.initiatorWhiteListEnabe = InitiatorWhiteListEnabe;
		localHostULPOption.currentLinkKey = LELinkKey;
		localHostULPOption.randomNumber = RandomNumber;
		localHostULPOption.encryptedDiversifier = EncryptedDiversifier;
		localHostULPOption.positiveAutoReply = PositiveAutoReply;
		localHostULPOption.negativeAutoReply = NegativeAutoReply;
		localHostULPOption.userPromptedAutoReply = UserPromptedAutoReply;
		localHostULPOption.leLongTermKeys = recentParameterSettings.leLongTermKeys;
		localHostULPOption.leRandomNumbers = recentParameterSettings.leRandomNumbers;
		localHostULPOption.NumCis = numCis;
		localHostULPOption.IsoInterval = isoIntervalMsec;
		localHostULPOption.Packing = packing;
		localHostULPOption.NumSubEvents = numCisSubEvents;
		localHostULPOption.Sca = sca;
		localHostULPOption.FlushTimeoutMS = cisFlushTimeoutMS;
		localHostULPOption.FlushTimeoutSM = cisFlushTimeoutSM;
		localHostULPOption.MaxPayloadSizeMS = cisMaxPayloadSizeMS;
		localHostULPOption.MaxPayloadSizeSM = cisMaxPayloadSizeSM;
		localHostULPOption.PhyType1MMSEnable = cisPhyType1MMSEnable;
		localHostULPOption.PhyType2MMSEnable = cisPhyType2MMSEnable;
		localHostULPOption.PhyTypeCodedMSEnable = cisPhyTypeCodedMSEnable;
		localHostULPOption.PhyType1MSMEnable = cisPhyType1MSMEnable;
		localHostULPOption.PhyType2MSMEnable = cisPhyType2MSMEnable;
		localHostULPOption.PhyTypeCodedMSEnable = cisPhyTypeCodedSMEnable;
		localHostULPOption.BurstNumMS = cisBurstNumMS;
		localHostULPOption.BurstNumSM = cisBurstNumSM;
		localHostULPOption.IcoAutoAccept = cisAutoAccept;
		localHostULPOption.CisFraming = cisFraming;
		localHostULPOption.CisMaxSDUSizeMS = cisMaxSDUSizeMS;
		localHostULPOption.CisSDUIntervalMS = cisSDUIntervalMS;
		localHostULPOption.CisMaxSDUSizeSM = cisMaxSDUSizeSM;
		localHostULPOption.CisSDUIntervalSM = cisSDUIntervalSM;
		localHostULPOption.ShowDialog();
		if (localHostULPOption.DialogResult != DialogResult.OK)
		{
			return;
		}
		Advertising_Interval_Max = (int)((double)localHostULPOption.maxInterval / 0.625);
		Advertising_Interval_Min = (int)((double)localHostULPOption.minInterval / 0.625);
		AdvertisingType = localHostULPOption.advertisingType;
		AdvertisingOwnAddressType = localHostULPOption.advertisingOwnAddressType;
		PeerAddressType = localHostULPOption.peerAddressType;
		PeerAddress = localHostULPOption.peerAddress;
		Index37Enable = localHostULPOption.index37Enable;
		Index38Enable = localHostULPOption.index38Enable;
		Index39Enable = localHostULPOption.index39Enable;
		AdvertisingFilterPolicy = localHostULPOption.advertisingFilterPolicy;
		AdvertisingData = localHostULPOption.advertisingData;
		AdvertisingDataLength = localHostULPOption.advertisingDataLength;
		ScanResponseData = localHostULPOption.scanResponseData;
		ScanResponseDataLength = localHostULPOption.scanResponseDataLength;
		LeScanType = localHostULPOption.leScanType;
		ScanOwnAddressType = localHostULPOption.scanOwnAddressType;
		ScanInterval = (int)((double)localHostULPOption.scanInterval / 0.625);
		ScanWindow = (int)((double)localHostULPOption.scanWindow / 0.625);
		ScanFilterPolicyEnable = localHostULPOption.scanFilterPolicyEnable;
		ScanFilterDuplicatesEnable = localHostULPOption.scanFilterDuplicatesEnable;
		LEFilterAddress = (from i in Enumerable.Range(0, localHostULPOption.leFilterAddress.Length / 2)
			select localHostULPOption.leFilterAddress.Substring(i * 2, 2)).ToArray();
		CreateConnectionOwnAddressType = localHostULPOption.creatConnectionOwnAddressType;
		ConnectionTimingMinInterval = localHostULPOption.connectionTimingMinInterval;
		ConnectionTimingMaxInterval = localHostULPOption.connectionTimingMaxInterval;
		ConnectionTimingTimeout = localHostULPOption.connectionTimingTimeout;
		ConnectionTimingLatency = localHostULPOption.connectionTimingLatency;
		ConnectionEventTimingMinLength = localHostULPOption.connectionEventTimingMinLength;
		ConnectionEventTimingMaxLength = localHostULPOption.connectionEventTimingMaxLength;
		ConnectionScanTimingScanInterval = localHostULPOption.connectionScanTimingScanInterval;
		ConnectionScanTimingScanWindow = localHostULPOption.connectionScanTimingScanWindow;
		InitiatorWhiteListEnabe = localHostULPOption.initiatorWhiteListEnabe;
		LELinkKey = localHostULPOption.currentLinkKey;
		RandomNumber = localHostULPOption.randomNumber;
		EncryptedDiversifier = localHostULPOption.encryptedDiversifier;
		PositiveAutoReply = localHostULPOption.positiveAutoReply;
		NegativeAutoReply = localHostULPOption.negativeAutoReply;
		UserPromptedAutoReply = localHostULPOption.userPromptedAutoReply;
		numCis = localHostULPOption.NumCis;
		isoIntervalMsec = localHostULPOption.IsoInterval;
		packing = localHostULPOption.Packing;
		numCisSubEvents = localHostULPOption.NumSubEvents;
		sca = localHostULPOption.Sca;
		cisFlushTimeoutMS = localHostULPOption.FlushTimeoutMS;
		cisFlushTimeoutSM = localHostULPOption.FlushTimeoutSM;
		cisMaxPayloadSizeMS = localHostULPOption.MaxPayloadSizeMS;
		cisMaxPayloadSizeSM = localHostULPOption.MaxPayloadSizeSM;
		cisPhyType1MMSEnable = localHostULPOption.PhyType1MMSEnable;
		cisPhyType2MMSEnable = localHostULPOption.PhyType2MMSEnable;
		cisPhyTypeCodedMSEnable = localHostULPOption.PhyTypeCodedMSEnable;
		cisPhyType1MSMEnable = localHostULPOption.PhyType1MSMEnable;
		cisPhyType2MSMEnable = localHostULPOption.PhyType2MSMEnable;
		cisPhyTypeCodedSMEnable = localHostULPOption.PhyTypeCodedMSEnable;
		cisBurstNumMS = localHostULPOption.BurstNumMS;
		cisBurstNumSM = localHostULPOption.BurstNumSM;
		cisAutoAccept = localHostULPOption.IcoAutoAccept;
		cisFraming = localHostULPOption.CisFraming;
		cisMaxSDUSizeMS = localHostULPOption.CisMaxSDUSizeMS;
		cisSDUIntervalMS = localHostULPOption.CisSDUIntervalMS;
		cisMaxSDUSizeSM = localHostULPOption.CisMaxSDUSizeSM;
		cisSDUIntervalSM = localHostULPOption.CisSDUIntervalSM;
		leSetCigMenuItem.DropDownItems.Clear();
		PopulateSetCigMenuDefault(numCis);
		ModeAgnosticDataReceiver modeAgnosticDataReceiver = new ModeAgnosticDataReceiver(btAPI);
		modeAgnosticDataReceiver.Startup();
		List<PacketBase> list = null;
		try
		{
			LeSetAdvertisingParameters leSetAdvertisingParameters = new LeSetAdvertisingParameters();
			leSetAdvertisingParameters.UserFields.AdvertisingIntervalMin = (uint)Advertising_Interval_Min;
			leSetAdvertisingParameters.UserFields.AdvertisingIntervalMax = (uint)Advertising_Interval_Max;
			leSetAdvertisingParameters.UserFields.AdvertisingType = (uint)AdvertisingType;
			leSetAdvertisingParameters.UserFields.OwnAddressType = (uint)AdvertisingOwnAddressType;
			leSetAdvertisingParameters.UserFields.PeerAddressType = (uint)PeerAddressType;
			leSetAdvertisingParameters.UserFields.PeerAddress = Convert.ToUInt64(PeerAddress, 16);
			AdvertisingChannelMapEnumCollection advertisingChannelMapEnumCollection = new AdvertisingChannelMapEnumCollection();
			advertisingChannelMapEnumCollection.Channel37ShallBeUsed = (Index37Enable ? EnableBitEnum.Enabled : EnableBitEnum.Disabled);
			advertisingChannelMapEnumCollection.Channel38ShallBeUsed = (Index38Enable ? EnableBitEnum.Enabled : EnableBitEnum.Disabled);
			advertisingChannelMapEnumCollection.Channel39ShallBeUsed = (Index39Enable ? EnableBitEnum.Enabled : EnableBitEnum.Disabled);
			leSetAdvertisingParameters.UserFields.SetAdvertisingChannelMapAsAdvertisingChannelMapEnumCollection(advertisingChannelMapEnumCollection);
			leSetAdvertisingParameters.UserFields.AdvertisingFilterPolicy = (uint)AdvertisingFilterPolicy;
			btAPI.Send(leSetAdvertisingParameters);
			list = modeAgnosticDataReceiver.ReceiveAll(leSetAdvertisingParameters.ExpectedResponseTypes, 2000);
			CommandCompleteForLeSetAdvertisingParameters packet = (CommandCompleteForLeSetAdvertisingParameters)PacketHelper.GetPacketTypeFromList(typeof(CommandCompleteForLeSetAdvertisingParameters), list);
			CheckStatusForPacket(packet, leSetAdvertisingParameters.GetType().ToString());
			LeSetScanResponseData leSetScanResponseData = new LeSetScanResponseData();
			leSetScanResponseData.UserFields.ScanResponseDataLength = (uint)ScanResponseDataLength;
			int[] array = new int[ScanResponseDataLength];
			for (int j = 0; j < ScanResponseDataLength; j++)
			{
				string s = ScanResponseData.Substring(j * 2, 2);
				if (!int.TryParse(s, NumberStyles.HexNumber, null, out array[j]))
				{
					array[j] = 0;
				}
				leSetScanResponseData.UserFields.ScanResponseDataList[j] = (uint)array[j];
			}
			btAPI.Send(leSetScanResponseData);
			list = modeAgnosticDataReceiver.ReceiveAll(leSetScanResponseData.ExpectedResponseTypes, 2000);
			CommandCompleteForLeSetScanResponseData packet2 = (CommandCompleteForLeSetScanResponseData)PacketHelper.GetPacketTypeFromList(typeof(CommandCompleteForLeSetScanResponseData), list);
			CheckStatusForPacket(packet2, leSetScanResponseData.GetType().ToString());
			LeSetAdvertisingData leSetAdvertisingData = new LeSetAdvertisingData();
			leSetAdvertisingData.UserFields.AdvertisingDataLength = (uint)AdvertisingDataLength;
			int[] array2 = new int[AdvertisingDataLength];
			for (int k = 0; k < AdvertisingDataLength; k++)
			{
				string s2 = AdvertisingData.Substring(k * 2, 2);
				if (!int.TryParse(s2, NumberStyles.HexNumber, null, out array2[k]))
				{
					array2[k] = 0;
				}
				leSetAdvertisingData.UserFields.AdvertisingDataList[k] = (uint)array2[k];
			}
			btAPI.Send(leSetAdvertisingData);
			list = modeAgnosticDataReceiver.ReceiveAll(leSetAdvertisingData.ExpectedResponseTypes, 2000);
			CommandCompleteForLeSetAdvertisingData packet3 = (CommandCompleteForLeSetAdvertisingData)PacketHelper.GetPacketTypeFromList(typeof(CommandCompleteForLeSetAdvertisingData), list);
			CheckStatusForPacket(packet3, leSetAdvertisingData.GetType().ToString());
			LeSetScanParameters leSetScanParameters = new LeSetScanParameters();
			leSetScanParameters.UserFields.LeScanType = (uint)LeScanType;
			leSetScanParameters.UserFields.LeScanInterval = (uint)ScanInterval;
			leSetScanParameters.UserFields.LeScanWindow = (uint)ScanWindow;
			leSetScanParameters.UserFields.OwnAddressType = (uint)ScanOwnAddressType;
			leSetScanParameters.UserFields.ScanningFilterPolicy = (ScanFilterPolicyEnable ? 1u : 0u);
			btAPI.Send(leSetScanParameters);
			list = modeAgnosticDataReceiver.ReceiveAll(leSetScanParameters.ExpectedResponseTypes, 2000);
			CommandCompleteForLeSetScanParameters packet4 = (CommandCompleteForLeSetScanParameters)PacketHelper.GetPacketTypeFromList(typeof(CommandCompleteForLeSetScanParameters), list);
			CheckStatusForPacket(packet4, leSetScanParameters.GetType().ToString());
		}
		catch (Exception ex)
		{
			logger.Enqueue(new QCRPG.Framework.LogMessage(LogMessageType.Error, "Fail to execute LE parameters settings. " + ex));
		}
		finally
		{
			modeAgnosticDataReceiver.Shutdown();
		}
		UpdateAllLERemoteDeviceInfoWithLocalHostULPOptions();
	}

	private void leRemoveCig_Click(object sender, EventArgs e)
	{
		LeRemoveCig leRemoveCig = new LeRemoveCig();
		leRemoveCig._UserFields.CigId = 0u;
		try
		{
			btAPI.Send(leRemoveCig);
			dutSetCig = false;
		}
		catch (Exception ex)
		{
			logger.Enqueue(new QCRPG.Framework.LogMessage(LogMessageType.Error, ex));
		}
	}

	private void leCreateAllCis_Click(object sender, EventArgs e)
	{
		if (currentBTConnectionHandler > 0)
		{
			LeCreateCis leCreateCis = new LeCreateCis();
			leCreateCis._UserFields.CisCount = numCis;
			for (int i = 0; i < numCis; i++)
			{
				leCreateCis._UserFields.ConnectionHandlesList[i].AclConnectionHandle = (uint)currentBTConnectionHandler;
				leCreateCis._UserFields.ConnectionHandlesList[i].CisConnectionHandle = leCisInfo.LeGetIcoHandlePerIcoChannelId(getIcoChannelIdFromChannelString("CIS ID " + i));
			}
			try
			{
				btAPI.Send(leCreateCis);
			}
			catch (Exception ex)
			{
				logger.Enqueue(new QCRPG.Framework.LogMessage(LogMessageType.Error, ex));
			}
		}
	}

	private void leCreateCis_Click(object sender, EventArgs e)
	{
		if (currentBTConnectionHandler > 0)
		{
			LeCreateCis leCreateCis = new LeCreateCis();
			leCreateCis._UserFields.CisCount = 1u;
			leCreateCis._UserFields.ConnectionHandlesList[0].AclConnectionHandle = (uint)currentBTConnectionHandler;
			leCreateCis._UserFields.ConnectionHandlesList[0].CisConnectionHandle = leCisInfo.LeGetIcoHandlePerIcoChannelId(getIcoChannelIdFromChannelString(sender.ToString()));
			try
			{
				btAPI.Send(leCreateCis);
			}
			catch (Exception ex)
			{
				logger.Enqueue(new QCRPG.Framework.LogMessage(LogMessageType.Error, ex));
			}
		}
	}

	private void leDisconnectCis_Click(object sender, EventArgs e)
	{
		Disconnect disconnect = new Disconnect();
		disconnect._UserFields.ConnectionHandle = leCisInfo.LeGetIcoHandlePerIcoChannelId(getIcoChannelIdFromChannelString(sender.ToString()));
		disconnect._UserFields.SetReasonAsReasonEnum(Disconnect.UserFieldsWrapper.ReasonEnum.REMOTE_USER_TERMINATED_CONNECTION);
		try
		{
			btAPI.Send(disconnect);
		}
		catch (Exception ex)
		{
			logger.Enqueue(new QCRPG.Framework.LogMessage(LogMessageType.Error, ex));
		}
	}

	private uint getIcoChannelIdFromChannelString(string chStr)
	{
		int startIndex = chStr.IndexOf("CIS ID ");
		string s = chStr.Remove(startIndex, "CIS ID ".Length - 1);
		uint.TryParse(s, out var result);
		return result;
	}

	private void leSetCig_Click(object sender, EventArgs e)
	{
		if (leCisInfo == null)
		{
			leCisInfo = new LECisInfo();
		}
		leCisInfo.pendingCisId = (int)getIcoChannelIdFromChannelString(sender.ToString());
		LeSetCigParametersTest leSetCigParametersTest = new LeSetCigParametersTest();
		leSetCigParametersTest._UserFields.CigId = cigId;
		leSetCigParametersTest._UserFields.CisParametersList[0].CisId = (uint)leCisInfo.pendingCisId;
		leSetCigParametersTest._UserFields.IsoInterval = (uint)((double)isoIntervalMsec / 1.25);
		leSetCigParametersTest._UserFields.Sca = sca;
		leSetCigParametersTest._UserFields.Packing = packing;
		leSetCigParametersTest._UserFields.Framing = (cisFraming ? 1u : 0u);
		leSetCigParametersTest._UserFields.SduIntervalMToS = cisSDUIntervalMS;
		leSetCigParametersTest._UserFields.SduIntervalSToM = cisSDUIntervalSM;
		leSetCigParametersTest._UserFields.FtMToS = cisFlushTimeoutMS;
		leSetCigParametersTest._UserFields.FtSToM = cisFlushTimeoutSM;
		leSetCigParametersTest._UserFields.CisParametersList[0].Nse = numCisSubEvents;
		leSetCigParametersTest._UserFields.CisParametersList[0].MaxPduMToS = cisMaxPayloadSizeMS;
		leSetCigParametersTest._UserFields.CisParametersList[0].MaxPduSToM = cisMaxPayloadSizeSM;
		int num = (cisPhyType1MMSEnable ? 1 : 0);
		num += (cisPhyType2MMSEnable ? 1 : 0) << 1;
		num += (cisPhyTypeCodedMSEnable ? 1 : 0) << 2;
		leSetCigParametersTest._UserFields.CisParametersList[0].PhyMToS = (uint)num;
		int num2 = (cisPhyType1MSMEnable ? 1 : 0);
		num2 += (cisPhyType2MSMEnable ? 1 : 0) << 1;
		num2 += (cisPhyTypeCodedSMEnable ? 1 : 0) << 2;
		leSetCigParametersTest._UserFields.CisParametersList[0].PhySToM = (uint)num2;
		leSetCigParametersTest._UserFields.CisParametersList[0].BnMToS = cisBurstNumMS;
		leSetCigParametersTest._UserFields.CisParametersList[0].BnSToM = cisBurstNumSM;
		leSetCigParametersTest._UserFields.CisParametersList[0].MaxSduMToS = cisMaxSDUSizeMS;
		leSetCigParametersTest._UserFields.CisParametersList[0].MaxSduSToM = cisMaxSDUSizeSM;
		try
		{
			btAPI.Send(leSetCigParametersTest);
			dutSetCig = true;
		}
		catch (Exception ex)
		{
			logger.Enqueue(new QCRPG.Framework.LogMessage(LogMessageType.Error, ex));
		}
	}

	private void btConnectToolStripMenuItem_Click(object sender, EventArgs e)
	{
		ListViewItem listViewItem = btDeviceListView.SelectedItems[0];
		string text = listViewItem.Text;
		uint packetType = 0u;
		uint pageScanRepMode = 0u;
		uint clockOffSet = 0u;
		bool allowRoleSwitch = false;
		if (BTLERemoteDeviceInfoList.CheckAndGetBTRemoteDeviceInfoByBDAddress(text, out packetType, out pageScanRepMode, out clockOffSet, out allowRoleSwitch))
		{
			BTConnectionHandler(text, packetType, pageScanRepMode, clockOffSet, allowRoleSwitch);
			currentBTPacketType = packetType;
		}
	}

	private void disconnectToolStripMenuItem_Click(object sender, EventArgs e)
	{
		ListViewItem listViewItem = btDeviceListView.SelectedItems[0];
		string text = listViewItem.Text;
		if (!text.Equals("SCO") && !text.Equals("ESCO"))
		{
			int bTRemoteDeviceConnectionHandlerByBDAddress = BTLERemoteDeviceInfoList.GetBTRemoteDeviceConnectionHandlerByBDAddress(text);
			if (bTRemoteDeviceConnectionHandlerByBDAddress != 0)
			{
				BTDisconnectionHandler(bTRemoteDeviceConnectionHandlerByBDAddress);
			}
			return;
		}
		object tag = listViewItem.Tag;
		string text2 = listViewItem.SubItems[1].Text;
		if ((string)tag == "SCO")
		{
			SCODisconnectionHandler(text2);
		}
		else if ((string)tag == "ESCO")
		{
			SCODisconnectionHandler(text2);
		}
	}

	private void addSCOConnectionToolStripMenuItem_Click(object sender, EventArgs e)
	{
		ListViewItem listViewItem = btDeviceListView.SelectedItems[0];
		string text = listViewItem.Text;
		uint packetType = 0u;
		int connectionHandle = 0;
		if (BTLERemoteDeviceInfoList.CheckAndGetBTRemoteDeviceScoPacketTypeByBDAddress(text, out packetType, out connectionHandle))
		{
			AddSCOConnectionHandler(connectionHandle, packetType);
			currentBTPacketType = packetType;
		}
	}

	private void setupModifyESCOConnectionToolStripMenuItem_Click(object sender, EventArgs e)
	{
		ListViewItem listViewItem = btDeviceListView.SelectedItems[0];
		string text = listViewItem.Text;
		if (text != "ESCO")
		{
			int bTRemoteDeviceConnectionHandlerByBDAddress = BTLERemoteDeviceInfoList.GetBTRemoteDeviceConnectionHandlerByBDAddress(text);
			int result = 0;
			int.TryParse(VoiceSetting, NumberStyles.HexNumber, null, out result);
			int packetType = CalculatePacketTypeForESCOConnection();
			int retransmissionEffort = CalculateRetransmissionEffortForESCOConnection();
			AddESCOConnectionHandler(bTRemoteDeviceConnectionHandlerByBDAddress, result, retransmissionEffort, packetType);
			currentBTPacketType = (uint)packetType;
		}
		else
		{
			string text2 = listViewItem.SubItems[1].Text;
			ModifyESCOConnectionHandler(text2);
		}
	}

	private void setupModifyEnhancedConnectionToolStripMenuItem_Click(object sender, EventArgs e)
	{
		ListViewItem listViewItem = btDeviceListView.SelectedItems[0];
		string text = listViewItem.Text;
		if (text != "ESCO")
		{
			int bTRemoteDeviceConnectionHandlerByBDAddress = BTLERemoteDeviceInfoList.GetBTRemoteDeviceConnectionHandlerByBDAddress(text);
			int packetType = CalculatePacketTypeForESCOConnection();
			int retransmissionEffort = CalculateRetransmissionEffortForESCOConnection();
			AddEnhancedSynchronousConnectionHandler(bTRemoteDeviceConnectionHandlerByBDAddress, retransmissionEffort, packetType);
			currentBTPacketType = (uint)packetType;
		}
		else
		{
			string text2 = listViewItem.SubItems[1].Text;
			ModifyESCOConnectionHandler(text2, enhancedParameters: true);
		}
	}

	private void changeConnectionPacketTypeToolStripMenuItem_Click(object sender, EventArgs e)
	{
		ListViewItem listViewItem = btDeviceListView.SelectedItems[0];
		string text = listViewItem.Text;
		if (text != "SCO")
		{
			int bTRemoteDeviceConnectionHandlerByBDAddress = BTLERemoteDeviceInfoList.GetBTRemoteDeviceConnectionHandlerByBDAddress(text);
			ChangeConnectionPacketTypeHandler(bTRemoteDeviceConnectionHandlerByBDAddress, isSCO: false, text);
		}
		else
		{
			int connectionHandle = int.Parse(listViewItem.SubItems[1].Text);
			ChangeConnectionPacketTypeHandler(connectionHandle, isSCO: true);
		}
	}

	private void requestAuthenticationToolStripMenuItem_Click(object sender, EventArgs e)
	{
		ListViewItem listViewItem = btDeviceListView.SelectedItems[0];
		string text = listViewItem.Text;
		int bTRemoteDeviceConnectionHandlerByBDAddress = BTLERemoteDeviceInfoList.GetBTRemoteDeviceConnectionHandlerByBDAddress(text);
		if (bTRemoteDeviceConnectionHandlerByBDAddress != 0)
		{
			RequestAuthenticationHandler(bTRemoteDeviceConnectionHandlerByBDAddress);
		}
	}

	private void enableToolStripMenuItem_Click(object sender, EventArgs e)
	{
		ListViewItem listViewItem = btDeviceListView.SelectedItems[0];
		string text = listViewItem.Text;
		int bTRemoteDeviceConnectionHandlerByBDAddress = BTLERemoteDeviceInfoList.GetBTRemoteDeviceConnectionHandlerByBDAddress(text);
		if (bTRemoteDeviceConnectionHandlerByBDAddress != 0)
		{
			EncryptionHandler(bTRemoteDeviceConnectionHandlerByBDAddress, enable: true);
		}
	}

	private void disableToolStripMenuItem_Click(object sender, EventArgs e)
	{
		ListViewItem listViewItem = btDeviceListView.SelectedItems[0];
		string text = listViewItem.Text;
		int bTRemoteDeviceConnectionHandlerByBDAddress = BTLERemoteDeviceInfoList.GetBTRemoteDeviceConnectionHandlerByBDAddress(text);
		if (bTRemoteDeviceConnectionHandlerByBDAddress != 0)
		{
			EncryptionHandler(bTRemoteDeviceConnectionHandlerByBDAddress, enable: false);
		}
	}

	private void sniffModeToolStripMenuItem_Click(object sender, EventArgs e)
	{
		ListViewItem listViewItem = btDeviceListView.SelectedItems[0];
		string text = listViewItem.Text;
		int bTRemoteDeviceConnectionHandlerByBDAddress = BTLERemoteDeviceInfoList.GetBTRemoteDeviceConnectionHandlerByBDAddress(text);
		sniffParameters = new SniffParameters();
		sniffParameters.MaxInterval = SniffMaxInterval;
		sniffParameters.MinInterval = SniffMinInterval;
		sniffParameters.SniffAttempt = SniffAttempt;
		sniffParameters.SniffTimeout = SniffTimeout;
		sniffParameters.ShowDialog();
		if (sniffParameters.DialogResult == DialogResult.OK)
		{
			SniffMaxInterval = sniffParameters.MaxInterval;
			SniffMinInterval = sniffParameters.MinInterval;
			SniffAttempt = sniffParameters.SniffAttempt;
			SniffTimeout = sniffParameters.SniffTimeout;
			if (bTRemoteDeviceConnectionHandlerByBDAddress != 0)
			{
				SniffModeHandler(bTRemoteDeviceConnectionHandlerByBDAddress);
			}
		}
	}

	private void switchRoleToolStripMenuItem_Click(object sender, EventArgs e)
	{
		ListViewItem listViewItem = btDeviceListView.SelectedItems[0];
		string text = listViewItem.Text;
		string masterSlave = "S";
		BTLERemoteDeviceInfoList.CheckAndGetBTRemoteDeviceRoleByBDAddress(text, out masterSlave);
		int role = ((!(masterSlave == "M")) ? 1 : 0);
		SwitchRoleHandler(text, role);
	}

	private void semiPermanentToolStripMenuItem_Click(object sender, EventArgs e)
	{
		MasterLinKKeyHandler(semi: true);
	}

	private void temporaryToolStripMenuItem_Click(object sender, EventArgs e)
	{
		MasterLinKKeyHandler(semi: false);
	}

	private void remoteNameToolStripMenuItem_Click(object sender, EventArgs e)
	{
		ListViewItem listViewItem = btDeviceListView.SelectedItems[0];
		string text = listViewItem.Text;
		uint packetType = 0u;
		uint pageScanRepMode = 0u;
		uint clockOffSet = 0u;
		bool allowRoleSwitch = false;
		if (BTLERemoteDeviceInfoList.CheckAndGetBTRemoteDeviceInfoByBDAddress(text, out packetType, out pageScanRepMode, out clockOffSet, out allowRoleSwitch))
		{
			BTReadRemoteNameHandler(text, pageScanRepMode, clockOffSet);
		}
	}

	private void remoteVersionToolStripMenuItem_Click(object sender, EventArgs e)
	{
		ListViewItem listViewItem = btDeviceListView.SelectedItems[0];
		string text = listViewItem.Text;
		int bTRemoteDeviceConnectionHandlerByBDAddress = BTLERemoteDeviceInfoList.GetBTRemoteDeviceConnectionHandlerByBDAddress(text);
		ReadRemoteVersionHandler(bTRemoteDeviceConnectionHandlerByBDAddress);
	}

	private void remoteSupportedFeaturesToolStripMenuItem_Click(object sender, EventArgs e)
	{
		ListViewItem listViewItem = btDeviceListView.SelectedItems[0];
		string text = listViewItem.Text;
		int bTRemoteDeviceConnectionHandlerByBDAddress = BTLERemoteDeviceInfoList.GetBTRemoteDeviceConnectionHandlerByBDAddress(text);
		ReadRemoteSupportedFeaturesHandler(bTRemoteDeviceConnectionHandlerByBDAddress);
	}

	private void remotePage1ToolStripMenuItem_Click(object sender, EventArgs e)
	{
		ListViewItem listViewItem = btDeviceListView.SelectedItems[0];
		string text = listViewItem.Text;
		int bTRemoteDeviceConnectionHandlerByBDAddress = BTLERemoteDeviceInfoList.GetBTRemoteDeviceConnectionHandlerByBDAddress(text);
		ReadRemoteExtendedFeaturesHandler(bTRemoteDeviceConnectionHandlerByBDAddress, 1u);
	}

	private void remotePage2ToolStripMenuItem_Click(object sender, EventArgs e)
	{
		ListViewItem listViewItem = btDeviceListView.SelectedItems[0];
		string text = listViewItem.Text;
		int bTRemoteDeviceConnectionHandlerByBDAddress = BTLERemoteDeviceInfoList.GetBTRemoteDeviceConnectionHandlerByBDAddress(text);
		ReadRemoteExtendedFeaturesHandler(bTRemoteDeviceConnectionHandlerByBDAddress, 2u);
	}

	private void afhChannelMapToolStripMenuItem_Click(object sender, EventArgs e)
	{
		ListViewItem listViewItem = btDeviceListView.SelectedItems[0];
		string text = listViewItem.Text;
		int bTRemoteDeviceConnectionHandlerByBDAddress = BTLERemoteDeviceInfoList.GetBTRemoteDeviceConnectionHandlerByBDAddress(text);
		ReadAFHChannelMapHandler(bTRemoteDeviceConnectionHandlerByBDAddress);
	}

	private void parkModeToolStripMenuItem_Click(object sender, EventArgs e)
	{
	}

	private void exitSniffModeToolStripMenuItem_Click(object sender, EventArgs e)
	{
		ListViewItem listViewItem = btDeviceListView.SelectedItems[0];
		string text = listViewItem.Text;
		int bTRemoteDeviceConnectionHandlerByBDAddress = BTLERemoteDeviceInfoList.GetBTRemoteDeviceConnectionHandlerByBDAddress(text);
		if (bTRemoteDeviceConnectionHandlerByBDAddress != 0)
		{
			ExitSniffModeHandler(bTRemoteDeviceConnectionHandlerByBDAddress);
		}
	}

	private void holdModeToolStripMenuItem_Click(object sender, EventArgs e)
	{
		ListViewItem listViewItem = btDeviceListView.SelectedItems[0];
		string text = listViewItem.Text;
		int bTRemoteDeviceConnectionHandlerByBDAddress = BTLERemoteDeviceInfoList.GetBTRemoteDeviceConnectionHandlerByBDAddress(text);
		holdParameters = new HoldParameters();
		holdParameters.MaxInterval = HoldMaxInterval;
		holdParameters.MinInterval = HoldMinInterval;
		holdParameters.ShowDialog();
		if (holdParameters.DialogResult == DialogResult.OK)
		{
			HoldMaxInterval = holdParameters.MaxInterval;
			HoldMinInterval = holdParameters.MinInterval;
			if (bTRemoteDeviceConnectionHandlerByBDAddress != 0)
			{
				HoldModeHandler(bTRemoteDeviceConnectionHandlerByBDAddress);
			}
		}
	}

	private void editSelectedDeviceToolStripMenuItem_Click(object sender, EventArgs e)
	{
		ListViewItem listViewItem = btDeviceListView.SelectedItems[0];
		string text = listViewItem.Text;
		if (BTLERemoteDeviceInfoList.CheckAndGetBTRemoteDeviceInfoByBDAddress(text, out var btRemoteDevice))
		{
			EditSelectedDeviceHandler(btRemoteDevice);
		}
	}

	private void removeSelectedDeviceToolStripMenuItem_Click(object sender, EventArgs e)
	{
		ListViewItem listViewItem = btDeviceListView.SelectedItems[0];
		string text = listViewItem.Text;
		BTLERemoteDeviceInfoList.RemoveBTRemoteDeviceByBDAddress(text);
		RemoveItemFromListView(listViewItem);
		LocalLEDeviceIndex--;
	}

	private void leConnectToolStripMenuItem_Click(object sender, EventArgs e)
	{
		ListViewItem listViewItem = btDeviceListView.SelectedItems[0];
		string text = listViewItem.Text;
		uint num = 0u;
		num = BTLERemoteDeviceInfoList.GetLERemoteDeviceAddressTypeByBDAddress(text);
		LEConnectionHandler(text, num);
	}

	private void leDisconnectToolStripMenuItem_Click(object sender, EventArgs e)
	{
		ListViewItem listViewItem = btDeviceListView.SelectedItems[0];
		string text = listViewItem.Text;
		int lERemoteDeviceConnectionHandlerByBDAddress = BTLERemoteDeviceInfoList.GetLERemoteDeviceConnectionHandlerByBDAddress(text);
		if (lERemoteDeviceConnectionHandlerByBDAddress != BTLERemoteDeviceInfoList.defaultConnectionHandle)
		{
			BTDisconnectionHandler(lERemoteDeviceConnectionHandlerByBDAddress);
		}
	}

	private void readRemoteVersionInfoToolStripMenuItem_Click(object sender, EventArgs e)
	{
		ListViewItem listViewItem = btDeviceListView.SelectedItems[0];
		string text = listViewItem.Text;
		int lERemoteDeviceConnectionHandlerByBDAddress = BTLERemoteDeviceInfoList.GetLERemoteDeviceConnectionHandlerByBDAddress(text);
		if (lERemoteDeviceConnectionHandlerByBDAddress != BTLERemoteDeviceInfoList.defaultConnectionHandle)
		{
			LEReadRemoteVersionHandler(lERemoteDeviceConnectionHandlerByBDAddress);
		}
	}

	private void readChannelMapToolStripMenuItem_Click(object sender, EventArgs e)
	{
		ListViewItem listViewItem = btDeviceListView.SelectedItems[0];
		string text = listViewItem.Text;
		int lERemoteDeviceConnectionHandlerByBDAddress = BTLERemoteDeviceInfoList.GetLERemoteDeviceConnectionHandlerByBDAddress(text);
		if (lERemoteDeviceConnectionHandlerByBDAddress != BTLERemoteDeviceInfoList.defaultConnectionHandle)
		{
			LEReadChannelMapHandler(lERemoteDeviceConnectionHandlerByBDAddress);
		}
	}

	private void readRemoteFeatureToolStripMenuItem_Click(object sender, EventArgs e)
	{
		ListViewItem listViewItem = btDeviceListView.SelectedItems[0];
		string text = listViewItem.Text;
		int lERemoteDeviceConnectionHandlerByBDAddress = BTLERemoteDeviceInfoList.GetLERemoteDeviceConnectionHandlerByBDAddress(text);
		if (lERemoteDeviceConnectionHandlerByBDAddress != BTLERemoteDeviceInfoList.defaultConnectionHandle)
		{
			LEReadRemoteFeatureHandler(lERemoteDeviceConnectionHandlerByBDAddress);
		}
	}

	private void editSelectedLEDeviceToolStripMenuItem_Click(object sender, EventArgs e)
	{
		ListViewItem listViewItem = btDeviceListView.SelectedItems[0];
		string text = listViewItem.Text;
		if (BTLERemoteDeviceInfoList.CheckAndGetLERemoteDeviceInfoByBDAddress(text, out var leRemoteDevice))
		{
			LEEditSelectedDeviceHandler(leRemoteDevice);
		}
	}

	private void startEncryptionToolStripMenuItem_Click(object sender, EventArgs e)
	{
		ListViewItem listViewItem = btDeviceListView.SelectedItems[0];
		string text = listViewItem.Text;
		int lERemoteDeviceConnectionHandlerByBDAddress = BTLERemoteDeviceInfoList.GetLERemoteDeviceConnectionHandlerByBDAddress(text);
		if (lERemoteDeviceConnectionHandlerByBDAddress != BTLERemoteDeviceInfoList.defaultConnectionHandle)
		{
			LEStartEncryptionHandler(lERemoteDeviceConnectionHandlerByBDAddress);
		}
	}

	private void updateConnectionToolStripMenuItem_Click(object sender, EventArgs e)
	{
		ListViewItem listViewItem = btDeviceListView.SelectedItems[0];
		string text = listViewItem.Text;
		int lERemoteDeviceConnectionHandlerByBDAddress = BTLERemoteDeviceInfoList.GetLERemoteDeviceConnectionHandlerByBDAddress(text);
		if (lERemoteDeviceConnectionHandlerByBDAddress != BTLERemoteDeviceInfoList.defaultConnectionHandle)
		{
			LEUpdateConnectionHandler(lERemoteDeviceConnectionHandlerByBDAddress);
		}
	}

	private void removeSelectedLEDeviceToolStripMenuItem_Click(object sender, EventArgs e)
	{
		ListViewItem listViewItem = btDeviceListView.SelectedItems[0];
		string text = listViewItem.Text;
		BTLERemoteDeviceInfoList.RemoveLERemoteDeviceByBDAddress(text);
		RemoveItemFromListView(listViewItem);
	}

	public override void SetDeviceListView(ListView listView)
	{
		btDeviceListView = listView;
		btDeviceListView.Columns.Add("BD Address", 130);
		btDeviceListView.Columns.Add("RSSI", 40);
		btDeviceListView.Columns.Add("M/S");
		btDeviceListView.Columns.Add("EIR");
		ListViewItem listViewItem = new ListViewItem("Local Bluetooth Devices", 2);
		listViewItem.ForeColor = Color.Blue;
		listViewItem.Font = new Font(listView.Font, FontStyle.Bold);
		btDeviceListView.Items.Add(listViewItem);
		listViewItem = new ListViewItem("Local LE Devices", 3);
		listViewItem.ForeColor = Color.Blue;
		listViewItem.Font = new Font(listView.Font, FontStyle.Bold);
		btDeviceListView.Items.Add(listViewItem);
		btDeviceListView.FullRowSelect = true;
		btDeviceListView.HideSelection = true;
		btDeviceListView.MultiSelect = false;
		btDeviceListView.ColumnClick += btDeviceListView_ColumnClick;
		ImageList imageList = new ImageList();
		imageList.Images.Add(QCRPG.TSL.BT.Properties.Resources.Remote);
		imageList.Images.Add(QCRPG.TSL.BT.Properties.Resources.Connect);
		imageList.Images.Add(QCRPG.TSL.BT.Properties.Resources.BTLocal);
		imageList.Images.Add(QCRPG.TSL.BT.Properties.Resources.LELocal);
		imageList.Images.Add(QCRPG.TSL.BT.Properties.Resources.Sniff);
		imageList.Images.Add(QCRPG.TSL.BT.Properties.Resources.Hold);
		imageList.Images.Add(QCRPG.TSL.BT.Properties.Resources.Park);
		imageList.Images.Add(QCRPG.TSL.BT.Properties.Resources.SCO);
		imageList.Images.Add(QCRPG.TSL.BT.Properties.Resources.ESCO);
		btDeviceListView.SmallImageList = imageList;
		listView.MouseUp += listView_MouseUp;
	}

	public void UpdateBTDeviceListView(ListViewItem listViewItem)
	{
		if (btDeviceListView == null)
		{
			return;
		}
		if (listViewItem != null)
		{
			for (int i = LocalBTDeviceIndex + 1; i < LocalLEDeviceIndex; i++)
			{
				ListViewItem listViewItem2 = btDeviceListView.Items[i];
				if (listViewItem2.Text == listViewItem.Text)
				{
					listViewItem2.SubItems.Clear();
					listViewItem2.ImageIndex = listViewItem.ImageIndex;
					listViewItem2.Text = listViewItem.Text;
					listViewItem2.SubItems.Add(listViewItem.SubItems[1]);
					if (listViewItem.SubItems.Count > 2)
					{
						listViewItem2.SubItems.Add(listViewItem.SubItems[2]);
					}
					return;
				}
			}
			InsertItemToListView(listViewItem);
			return;
		}
		if (LocalLEDeviceIndex >= 2)
		{
			for (int j = 1; j < LocalLEDeviceIndex; j++)
			{
				RemoveItemAtIndexFromListView(1);
			}
			LocalLEDeviceIndex = 1;
			int count = btDeviceListView.Items.Count;
			for (int k = LocalLEDeviceIndex + 1; k < count; k++)
			{
				RemoveItemAtIndexFromListView(2);
			}
		}
		else if (LocalLEDeviceIndex == 1)
		{
			int count2 = btDeviceListView.Items.Count;
			for (int l = LocalLEDeviceIndex + 1; l < count2; l++)
			{
				RemoveItemAtIndexFromListView(2);
			}
		}
		LocalLEDeviceIndex = 1;
	}

	public bool CheckBTConnectionStatusByBDAddress(string bdAddress)
	{
		for (int i = LocalBTDeviceIndex + 1; i < LocalLEDeviceIndex; i++)
		{
			ListViewItem listViewItem = btDeviceListView.Items[i];
			if (listViewItem.Text == bdAddress && listViewItem.Checked)
			{
				return true;
			}
		}
		return false;
	}

	public bool CheckLEConnectionStatusByBDAddress(string bdAddress)
	{
		int count = btDeviceListView.Items.Count;
		for (int i = LocalLEDeviceIndex + 1; i < count; i++)
		{
			ListViewItem listViewItem = btDeviceListView.Items[i];
			if (listViewItem.Text == bdAddress && listViewItem.Checked)
			{
				return true;
			}
		}
		return false;
	}

	public void UpdateLEDeviceListView(ListViewItem listViewItem)
	{
		if (btDeviceListView == null)
		{
			return;
		}
		if (listViewItem != null)
		{
			for (int i = LocalLEDeviceIndex + 1; i < btDeviceListView.Items.Count; i++)
			{
				if (btDeviceListView.Items[i].Text == listViewItem.Text)
				{
					return;
				}
			}
			AddItemToListView(listViewItem);
		}
		else if (btDeviceListView.Items.Count > LocalLEDeviceIndex + 1)
		{
			for (int j = LocalLEDeviceIndex + 1; j < btDeviceListView.Items.Count; j++)
			{
				RemoveItemAtIndexFromListView(LocalLEDeviceIndex + 1);
			}
		}
	}

	public void UpdateLEDeviceConnectionStatus(string bdAddress, bool connected)
	{
		int count = btDeviceListView.Items.Count;
		for (int i = LocalLEDeviceIndex + 1; i < count; i++)
		{
			ListViewItem listViewItem = btDeviceListView.Items[i];
			if (listViewItem.Text == bdAddress)
			{
				if (connected)
				{
					listViewItem.ImageIndex = 1;
					listViewItem.Checked = true;
				}
				else
				{
					listViewItem.ImageIndex = 0;
					listViewItem.Checked = false;
				}
				break;
			}
		}
	}

	public void UpdateLEDeviceConnectionRSSI(string bdAddress, bool connected, string rssi)
	{
		int count = btDeviceListView.Items.Count;
		for (int i = LocalLEDeviceIndex + 1; i < count; i++)
		{
			ListViewItem listViewItem = btDeviceListView.Items[i];
			if (listViewItem.Text == bdAddress)
			{
				if (connected)
				{
					listViewItem.SubItems[1].Text = rssi;
				}
				break;
			}
		}
	}

	public void SetAdvertiseToolStripMenuItemCheck(bool itemCheck)
	{
		if (itemCheck)
		{
			if (advertiseToolStripMenuItem.Tag == null)
			{
				return;
			}
			if ((bool)advertiseToolStripMenuItem.Tag)
			{
				advertiseToolStripMenuItem.Checked = true;
				toolStripButtonLEAdvertising.Checked = true;
			}
			else
			{
				advertiseToolStripMenuItem.Checked = false;
				toolStripButtonLEAdvertising.Checked = false;
			}
		}
		else
		{
			advertiseToolStripMenuItem.Checked = false;
			toolStripButtonLEAdvertising.Checked = false;
		}
		advertiseToolStripMenuItem.Tag = null;
	}

	public void SetScanToolStripMenuItemCheck()
	{
		if (scanToolStripMenuItem.Tag != null)
		{
			if ((bool)scanToolStripMenuItem.Tag)
			{
				scanToolStripMenuItem.Checked = true;
				toolStripButtonLEScan.Checked = true;
			}
			else
			{
				scanToolStripMenuItem.Checked = false;
				toolStripButtonLEScan.Checked = false;
			}
			scanToolStripMenuItem.Tag = null;
		}
	}

	public void UpdateBTDeviceConnectionModeListView(string bdAddress, HciModeChange.UserFieldsWrapper.CurrentModeEnum currentMode)
	{
		for (int i = LocalBTDeviceIndex + 1; i < LocalLEDeviceIndex; i++)
		{
			ListViewItem listViewItem = btDeviceListView.Items[i];
			if (listViewItem.Text == bdAddress)
			{
				switch (currentMode)
				{
				case HciModeChange.UserFieldsWrapper.CurrentModeEnum.Active_Mode:
					listViewItem.ImageIndex = 1;
					listViewItem.Tag = null;
					break;
				case HciModeChange.UserFieldsWrapper.CurrentModeEnum.Hold_Mode:
					listViewItem.ImageIndex = 5;
					listViewItem.Tag = "Hold";
					break;
				case HciModeChange.UserFieldsWrapper.CurrentModeEnum.Sniff_Mode:
					listViewItem.ImageIndex = 4;
					listViewItem.Tag = "Sniff";
					break;
				case HciModeChange.UserFieldsWrapper.CurrentModeEnum.Park_State:
					listViewItem.ImageIndex = 6;
					listViewItem.Tag = "Park";
					break;
				}
				break;
			}
		}
	}

	public void UpdateBTDeviceConnectionRole(string bdAddress, string role)
	{
		for (int i = LocalBTDeviceIndex + 1; i < LocalLEDeviceIndex; i++)
		{
			ListViewItem listViewItem = btDeviceListView.Items[i];
			if (listViewItem.Text == bdAddress)
			{
				ListViewItem listViewItem2 = new ListViewItem();
				listViewItem2.ImageIndex = listViewItem.ImageIndex;
				listViewItem2.Text = listViewItem.Text;
				listViewItem2.Tag = listViewItem.Tag;
				listViewItem2.SubItems.Add(listViewItem.SubItems[1]);
				listViewItem2.SubItems.Add(role);
				UpdateBTDeviceListView(listViewItem2);
				break;
			}
		}
	}

	public void UpdateBTDeviceConnectionStatus(string bdAddress, bool connected)
	{
		for (int i = LocalBTDeviceIndex + 1; i < LocalLEDeviceIndex; i++)
		{
			ListViewItem listViewItem = btDeviceListView.Items[i];
			if (listViewItem.Text == bdAddress)
			{
				if (connected)
				{
					listViewItem.ImageIndex = 1;
					listViewItem.Checked = true;
					FileDataTranfer(enable: true);
					UpdateBTConnectionHandler(listViewItem.Text);
				}
				else
				{
					listViewItem.ImageIndex = 0;
					listViewItem.Checked = false;
					listViewItem.Tag = null;
					FileDataTranfer(enable: false);
				}
				break;
			}
		}
	}

	public void UpdateBLEDeviceConnectionStatus(string bdAddress, bool connected)
	{
		UpdateLEConnectionHandler(bdAddress);
	}

	public void UpdateBTSCODeviceListView(string bdAddress, ListViewItem listViewItem)
	{
		if (btDeviceListView == null)
		{
			return;
		}
		int num = -1;
		if (listViewItem == null)
		{
			return;
		}
		ListViewItem listViewItem2;
		for (int i = LocalBTDeviceIndex + 1; i < LocalLEDeviceIndex; i++)
		{
			listViewItem2 = btDeviceListView.Items[i];
			num = listViewItem2.Index;
			if (listViewItem2.Text == bdAddress)
			{
				break;
			}
		}
		listViewItem2 = btDeviceListView.Items[num + 1];
		if ((string)listViewItem2.Tag != "SCO" || (string)listViewItem2.Tag != "ESCO")
		{
			InsertItemToListView(num + 1, listViewItem);
			if ((string)listViewItem.Tag == "SCO")
			{
				AddIconToSubitem(btDeviceListView, num + 1, 0, 7);
			}
			else if ((string)listViewItem.Tag == "ESCO")
			{
				AddIconToSubitem(btDeviceListView, num + 1, 0, 8);
			}
			LocalLEDeviceIndex++;
		}
	}

	public void RemoveBTDevice(string bdAddress)
	{
		for (int i = LocalBTDeviceIndex + 1; i < LocalLEDeviceIndex; i++)
		{
			ListViewItem listViewItem = btDeviceListView.Items[i];
			if (listViewItem.Text == bdAddress)
			{
				RemoveItemFromListView(listViewItem);
				LocalLEDeviceIndex--;
				break;
			}
		}
	}

	private void generalPacketParserForUIUpdates(PacketBase packet)
	{
		string text = packet.ToString();
		if (text.Contains("DisconnectionComplete"))
		{
			int result = -1;
			int.TryParse(packet.Info.FieldInfoList[0].Value, NumberStyles.HexNumber, null, out result);
			if (result != 0)
			{
				return;
			}
			int result2 = 0;
			int.TryParse(packet.Info.FieldInfoList[1].Value, NumberStyles.HexNumber, null, out result2);
			string bTRemoteDeviceBDAddressByConnectionHandler = BTLERemoteDeviceInfoList.GetBTRemoteDeviceBDAddressByConnectionHandler(result2);
			if (bTRemoteDeviceBDAddressByConnectionHandler != null)
			{
				if (CheckBTConnectionStatusByBDAddress(bTRemoteDeviceBDAddressByConnectionHandler))
				{
					BTLERemoteDeviceInfoList.RemoveBTRemoteDeviceConnectionHandler(result2);
					string RSSI = "Invalid Rssi Value";
					BTLERemoteDeviceInfoList.CheckAndGetBTRemoteDeviceRSSIByBDAddress(bTRemoteDeviceBDAddressByConnectionHandler, out RSSI);
					BTLERemoteDeviceInfoList.UpdateBTRemoteDeviceRoleByBDAddress(bTRemoteDeviceBDAddressByConnectionHandler, "");
					ListViewItem listViewItem = new ListViewItem();
					listViewItem.ImageIndex = 0;
					listViewItem.Text = bTRemoteDeviceBDAddressByConnectionHandler;
					listViewItem.SubItems.Add(RSSI);
					listViewItem.SubItems.Add("");
					UpdateBTDeviceListView(listViewItem);
					UpdateBTDeviceConnectionStatus(bTRemoteDeviceBDAddressByConnectionHandler, connected: false);
					if (btDataTransferUserControl.IsConnectionAvailable(result2))
					{
						scoOverHciUserControl.Enabled = false;
						btMainWorkerThread.CancelTxDataTransfer(yesNo: true, result2);
						btMainWorkerThread.StopDataTransfer(result2);
						btDataTransferUserControl.RemoveDataTransferControl(result2);
						btMainWorkerThread.CancelTxDataTransfer(yesNo: false, result2);
					}
				}
				return;
			}
			bTRemoteDeviceBDAddressByConnectionHandler = BTLERemoteDeviceInfoList.GetLERemoteDeviceBDAddressByConnectionHandler(result2);
			if (bTRemoteDeviceBDAddressByConnectionHandler != null)
			{
				if (CheckLEConnectionStatusByBDAddress(bTRemoteDeviceBDAddressByConnectionHandler))
				{
					BTLERemoteDeviceInfoList.RemoveLERemoteDeviceConnectionHandler(result2);
					string RSSI2 = "Invalid Rssi Value";
					BTLERemoteDeviceInfoList.CheckAndGetLERemoteDeviceRSSIByBDAddress(bTRemoteDeviceBDAddressByConnectionHandler, out RSSI2);
					BTLERemoteDeviceInfoList.UpdateLERemoteDeviceRoleByBDAddress(bTRemoteDeviceBDAddressByConnectionHandler, "");
					ListViewItem listViewItem2 = new ListViewItem();
					listViewItem2.ImageIndex = 0;
					listViewItem2.Text = bTRemoteDeviceBDAddressByConnectionHandler;
					listViewItem2.SubItems.Add(RSSI2);
					listViewItem2.SubItems.Add("");
					UpdateLEDeviceListView(listViewItem2);
					UpdateLEDeviceConnectionStatus(bTRemoteDeviceBDAddressByConnectionHandler, connected: false);
					if (btDataTransferUserControl.IsConnectionAvailable(result2))
					{
						scoOverHciUserControl.Enabled = false;
						btMainWorkerThread.CancelTxDataTransfer(yesNo: true, result2);
						btMainWorkerThread.StopDataTransfer(result2);
						btDataTransferUserControl.RemoveDataTransferControl(result2);
						btMainWorkerThread.CancelTxDataTransfer(yesNo: false, result2);
					}
				}
				return;
			}
			bTRemoteDeviceBDAddressByConnectionHandler = BTLERemoteDeviceInfoList.GetBTRemoteDeviceBDAddressByScoConnectionHandler(result2);
			if (bTRemoteDeviceBDAddressByConnectionHandler != null)
			{
				if (!CheckBTConnectionStatusByBDAddress(bTRemoteDeviceBDAddressByConnectionHandler))
				{
					return;
				}
				BTLERemoteDeviceInfoList.RemoveBTRemoteDeviceSCOConnectionHandler(result2);
				for (int j = LocalBTDeviceIndex + 1; j < LocalLEDeviceIndex; j++)
				{
					ListViewItem listViewItem3 = btDeviceListView.Items[j];
					if ((listViewItem3.Text == "SCO" || listViewItem3.Text == "ESCO") && listViewItem3.SubItems[1].Text == result2.ToString("X4"))
					{
						RemoveItemFromListView(listViewItem3);
						LocalLEDeviceIndex--;
						break;
					}
				}
			}
			else
			{
				if (leCisInfo == null)
				{
					return;
				}
				DisconnectionComplete disconnectionComplete = (DisconnectionComplete)packet;
				int num = leCisInfo.LeGetCisChannelIdPerCisHandle(disconnectionComplete.UserFields.ConnectionHandle);
				if (num != -1)
				{
					BTLERemoteDeviceInfoList.RemoveLERemoteDeviceCisHandle((int)disconnectionComplete.UserFields.ConnectionHandle);
					leDisconnectCisMenuItem.DropDownItems.RemoveByKey("CIS ID " + num);
					if (leDisconnectCisMenuItem.DropDownItems.Count == 0)
					{
						leDisconnectCisMenuItem.Enabled = false;
					}
					if (dutSetCig)
					{
						leCreateCisMenuItem.DropDownItems.Add(new ToolStripMenuItem("CIS ID " + num)
						{
							Name = "CIS ID " + num
						});
						leCreateCisMenuItem.DropDownItems[leCreateCisMenuItem.DropDownItems.Count - 1].Click += leCreateCis_Click;
					}
					if (toolStripStatusLabelCisHandle != null)
					{
						toolStripStatusLabelCisHandle.Text = "CIS Handle: NA";
					}
				}
			}
		}
		else if (text.Contains("ConnectionComplete") && !text.Contains("LeConnectionComplete") && !text.Contains("LeEnhancedConnectionComplete") && !text.Contains("SynchronousConnectionCompleteEvent"))
		{
			int result3 = -1;
			int.TryParse(packet.Info.FieldInfoList[0].Value, NumberStyles.HexNumber, null, out result3);
			if (result3 != 0)
			{
				return;
			}
			int result4 = 0;
			int.TryParse(packet.Info.FieldInfoList[1].Value, NumberStyles.HexNumber, null, out result4);
			int result5 = 1;
			int.TryParse(packet.Info.FieldInfoList[3].Value, NumberStyles.HexNumber, null, out result5);
			switch (result5)
			{
			case 1:
			{
				string value2 = packet.Info.FieldInfoList[2].Value;
				BTLERemoteDeviceInfoList.UpdateBTRemoteDeviceConnectionHandler(value2, result4);
				string RSSI3 = "Invalid Rssi Value";
				BTLERemoteDeviceInfoList.CheckAndGetBTRemoteDeviceRSSIByBDAddress(value2, out RSSI3);
				string masterSlave = "S";
				BTLERemoteDeviceInfoList.CheckAndGetBTRemoteDeviceRoleByBDAddress(value2, out masterSlave);
				BTLERemoteDeviceInfoList.UpdateBTRemoteDeviceRoleByBDAddress(value2, masterSlave);
				ListViewItem listViewItem5 = new ListViewItem();
				listViewItem5.ImageIndex = 1;
				listViewItem5.Text = value2;
				listViewItem5.SubItems.Add(RSSI3);
				listViewItem5.SubItems.Add(masterSlave);
				UpdateBTDeviceListView(listViewItem5);
				btDataTransferUserControl.CreateDataTransferControl(result4, isBtConnection: true, value2);
				UpdateBTDeviceConnectionStatus(value2, connected: true);
				scoOverHciUserControl.Enabled = true;
				bool askForConnectionRequest = false;
				uint packetType2 = 0u;
				BTLERemoteDeviceInfoList.CheckAndGetBTRemoteDeviceConnectionRequestByBDAddress(value2, out askForConnectionRequest, out packetType2);
				if (askForConnectionRequest)
				{
					BTLERemoteDeviceInfoList.UpdateBTRemoteDeviceConnectionRequestByBDAddress(value2, askForConnectionRequest: false);
					try
					{
						WriteLinkPolicySettings writeLinkPolicySettings = new WriteLinkPolicySettings();
						writeLinkPolicySettings.UserFields.ConnectionHandle = (uint)result4;
						LinkPolicySettingsEnumCollection linkPolicySettingsEnumCollection = new LinkPolicySettingsEnumCollection();
						linkPolicySettingsEnumCollection.EnableRoleSwitch = (MasterSlaveSwitchEnable ? EnableBitEnum.Enabled : EnableBitEnum.Disabled);
						linkPolicySettingsEnumCollection.EnableHoldMode = (HoldModeEnable ? EnableBitEnum.Enabled : EnableBitEnum.Disabled);
						linkPolicySettingsEnumCollection.EnableSniffMode = (SniffModeEnable ? EnableBitEnum.Enabled : EnableBitEnum.Disabled);
						linkPolicySettingsEnumCollection.EnableParkState = (ParkModeEnable ? EnableBitEnum.Enabled : EnableBitEnum.Disabled);
						writeLinkPolicySettings.UserFields.SetLinkPolicySettingsAsLinkPolicySettingsEnumCollection(linkPolicySettingsEnumCollection);
						txPacketQueue.Enqueue(writeLinkPolicySettings);
						sendPacketEvent.Set();
						WriteScanEnable writeScanEnable = new WriteScanEnable();
						writeScanEnable.UserFields.ScanEnable = (uint)scanEnableLocalHost;
						txPacketQueue.Enqueue(writeScanEnable);
						sendPacketEvent.Set();
						ChangeConnectionPacketType changeConnectionPacketType = new ChangeConnectionPacketType();
						changeConnectionPacketType.UserFields.ConnectionHandle = (uint)result4;
						changeConnectionPacketType.UserFields.PacketType = packetType2;
						txPacketQueue.Enqueue(changeConnectionPacketType);
						sendPacketEvent.Set();
					}
					catch (Exception ex)
					{
						logger.Enqueue(new QCRPG.Framework.LogMessage(LogMessageType.Error, "Fail to execute commands after connection. " + ex));
					}
					currentBTPacketType = packetType2;
				}
				break;
			}
			case 0:
			{
				string value = packet.Info.FieldInfoList[2].Value;
				SynchronousPacketTypeEnumCollection packetType = SynchronousPacketTypeInfo.ValueToSynchronousPacketType(currentBTPacketType);
				BTLERemoteDeviceInfoList.UpdateBTRemoteDeviceSCOConnectionHandler(value, result4, packetType);
				ListViewItem listViewItem4 = new ListViewItem();
				listViewItem4.Text = "SCO";
				listViewItem4.Tag = "SCO";
				listViewItem4.SubItems.Add(result4.ToString("X4"));
				UpdateBTSCODeviceListView(value, listViewItem4);
				break;
			}
			}
		}
		else if (text.Contains("LeConnectionComplete") || text.Contains("LeEnhancedConnectionComplete"))
		{
			int result6 = -1;
			int.TryParse(packet.Info.FieldInfoList[1].Value, NumberStyles.HexNumber, null, out result6);
			if (result6 == 0)
			{
				int result7 = 0;
				int.TryParse(packet.Info.FieldInfoList[2].Value, NumberStyles.HexNumber, null, out result7);
				string value3 = packet.Info.FieldInfoList[5].Value;
				BTLERemoteDeviceInfoList.UpdateLERemoteDeviceConnectionHandler(value3, result7);
				UpdateLERemoteDeviceInfoWithLocalHostULPOptions(value3);
				string RSSI4 = "Invalid Rssi Value";
				BTLERemoteDeviceInfoList.CheckAndGetLERemoteDeviceRSSIByBDAddress(value3, out RSSI4);
				int result8 = 1;
				string text2 = "S";
				int.TryParse(packet.Info.FieldInfoList[3].Value, NumberStyles.HexNumber, null, out result8);
				switch (result8)
				{
				case 0:
					text2 = "S";
					break;
				case 1:
				{
					text2 = "M";
					SetAdvertiseToolStripMenuItemCheck(itemCheck: false);
					ReadRssi readRssi = new ReadRssi();
					readRssi.UserFields.Handle = (uint)result7;
					btAPI.SendAsync(readRssi);
					break;
				}
				}
				BTLERemoteDeviceInfoList.UpdateLERemoteDeviceRoleByBDAddress(value3, text2);
				ListViewItem listViewItem6 = new ListViewItem();
				listViewItem6.ImageIndex = 1;
				listViewItem6.Text = value3;
				listViewItem6.SubItems.Add(RSSI4);
				listViewItem6.SubItems.Add(text2);
				UpdateLEDeviceListView(listViewItem6);
				UpdateLEDeviceConnectionStatus(value3, connected: true);
				btDataTransferUserControl.CreateDataTransferControl(result7, isBtConnection: false, value3);
				scoOverHciUserControl.Enabled = false;
				UpdateBLEDeviceConnectionStatus(value3, connected: true);
				ReadRemoteVersionInformation readRemoteVersionInformation = new ReadRemoteVersionInformation();
				readRemoteVersionInformation.UserFields.ConnectionHandle = (uint)result7;
				txPacketQueue.Enqueue(readRemoteVersionInformation);
				sendPacketEvent.Set();
			}
		}
		else
		{
			if (btScriptUserControl.ScriptRunning)
			{
				return;
			}
			Queue<leRemoteInfo> obj = default(Queue<leRemoteInfo>);
			if (text.Contains("LeExtendedAdvertisingReport"))
			{
				string text3 = packet.Info.FieldInfoList[4].Value.ToString();
				string text4 = packet.Info.FieldInfoList[9].ValueNote.ToString();
				ListViewItem listViewItem7 = new ListViewItem();
				listViewItem7.ImageIndex = 0;
				listViewItem7.Text = text3;
				listViewItem7.SubItems.Add(text4);
				listViewItem7.SubItems.Add("");
				uint result9 = 0u;
				uint.TryParse(packet.Info.FieldInfoList[3].Value.ToString(), NumberStyles.HexNumber, null, out result9);
				leRemoteInfo item = default(leRemoteInfo);
				item.addrType = result9;
				item.remoteDeviceItem = listViewItem7;
				item.rssi = text4;
				bool lockTaken = false;
				try
				{
					Monitor.Enter(obj = leRemoteDeviceQueue, ref lockTaken);
					leRemoteDeviceQueue.Enqueue(item);
				}
				finally
				{
					if (lockTaken)
					{
						Monitor.Exit(obj);
					}
				}
				updateDeviceListEvent.Set();
			}
			else if (text.Contains("CsrRxBerErr1StatsEvent"))
			{
				CSRRxBerErr1Response cSRRxBerErr1Response = new CSRRxBerErr1Response();
				uint result10 = 0u;
				uint.TryParse(packet.Info.FieldInfoList[3].Value, NumberStyles.HexNumber, null, out result10);
				cSRRxBerErr1Response.UserFields.Seqno = result10;
				uint result11 = 0u;
				uint.TryParse(packet.Info.FieldInfoList[6].Value, NumberStyles.HexNumber, null, out result11);
				cSRRxBerErr1Response.UserFields.Index = result11;
				uint result12 = 0u;
				uint.TryParse(packet.Info.FieldInfoList[7].Value, NumberStyles.HexNumber, null, out result12);
				cSRRxBerErr1Response.UserFields.LastValue = result12;
				uint result13 = 0u;
				uint.TryParse(packet.Info.FieldInfoList[8].Value, NumberStyles.HexNumber, null, out result13);
				cSRRxBerErr1Response.UserFields.TotalValue = result13;
				btAPI.Send(cSRRxBerErr1Response);
			}
			else if (text.Contains("InquiryResultWithRssi"))
			{
				string bdaddress = packet.Info.FieldInfoList[1].Value.ToString();
				if (AddressFilter.Select((string octet, int i) => octet == "FF" || octet == bdaddress.Substring(2 * i, 2)).All((bool eq) => eq))
				{
					uint result14 = 0u;
					uint.TryParse(packet.Info.FieldInfoList[2].Value, NumberStyles.HexNumber, null, out result14);
					uint result15 = 0u;
					uint.TryParse(packet.Info.FieldInfoList[4].Value, NumberStyles.HexNumber, null, out result15);
					uint result16 = 0u;
					uint.TryParse(packet.Info.FieldInfoList[5].Value, NumberStyles.HexNumber, null, out result16);
					string valueNote = packet.Info.FieldInfoList[6].ValueNote;
					BTLERemoteDeviceInfoList.UpdateBTRemoteDeviceList(bdaddress, result14, result15, result16, valueNote);
					UpdateBTRemoteDeviceInfoWithLocalHostDefaultOptions(bdaddress);
					ListViewItem listViewItem8 = new ListViewItem();
					listViewItem8.ImageIndex = 0;
					listViewItem8.Text = bdaddress;
					listViewItem8.SubItems.Add(valueNote);
					int bTRemoteDeviceConnectionHandlerByBDAddress = BTLERemoteDeviceInfoList.GetBTRemoteDeviceConnectionHandlerByBDAddress(bdaddress);
					if (bTRemoteDeviceConnectionHandlerByBDAddress != BTLERemoteDeviceInfoList.defaultConnectionHandle)
					{
						string masterSlave2 = "";
						BTLERemoteDeviceInfoList.CheckAndGetBTRemoteDeviceRoleByBDAddress(bdaddress, out masterSlave2);
						listViewItem8.ImageIndex = 1;
						listViewItem8.SubItems.Add(masterSlave2);
					}
					UpdateBTDeviceListView(listViewItem8);
				}
			}
			else if (text.Contains("InquiryResult"))
			{
				string bdaddress = packet.Info.FieldInfoList[1].Value.ToString();
				if (AddressFilter.Select((string octet, int i) => octet == "FF" || octet == bdaddress.Substring(2 * i, 2)).All((bool eq) => eq))
				{
					uint result17 = 0u;
					uint.TryParse(packet.Info.FieldInfoList[2].Value, NumberStyles.HexNumber, null, out result17);
					uint result18 = 0u;
					uint.TryParse(packet.Info.FieldInfoList[5].Value, NumberStyles.HexNumber, null, out result18);
					uint result19 = 0u;
					uint.TryParse(packet.Info.FieldInfoList[6].Value, NumberStyles.HexNumber, null, out result19);
					BTLERemoteDeviceInfoList.UpdateBTRemoteDeviceList(bdaddress, result17, result18, result19, null);
					UpdateBTRemoteDeviceInfoWithLocalHostDefaultOptions(bdaddress);
					ListViewItem listViewItem9 = new ListViewItem();
					listViewItem9.ImageIndex = 0;
					listViewItem9.Text = bdaddress;
					listViewItem9.SubItems.Add("Invalid");
					int bTRemoteDeviceConnectionHandlerByBDAddress2 = BTLERemoteDeviceInfoList.GetBTRemoteDeviceConnectionHandlerByBDAddress(bdaddress);
					if (bTRemoteDeviceConnectionHandlerByBDAddress2 != BTLERemoteDeviceInfoList.defaultConnectionHandle)
					{
						string masterSlave3 = "";
						BTLERemoteDeviceInfoList.CheckAndGetBTRemoteDeviceRoleByBDAddress(bdaddress, out masterSlave3);
						listViewItem9.ImageIndex = 1;
						listViewItem9.SubItems.Add(masterSlave3);
					}
					UpdateBTDeviceListView(listViewItem9);
				}
			}
			else
			{
				if (text.Contains("InquiryComplete"))
				{
					return;
				}
				if (text.Contains("LeAdvertisingReport"))
				{
					string bdaddress = packet.Info.FieldInfoList[4].Value.ToString();
					if (!LEFilterAddress.Select((string octet, int i) => octet == "FF" || octet == bdaddress.Substring(2 * i, 2)).All((bool eq) => eq))
					{
						return;
					}
					string text5 = packet.Info.FieldInfoList[7].ValueNote.ToString();
					ListViewItem listViewItem10 = new ListViewItem();
					listViewItem10.ImageIndex = 0;
					listViewItem10.Text = bdaddress;
					listViewItem10.SubItems.Add(text5);
					listViewItem10.SubItems.Add("");
					uint result20 = 0u;
					uint.TryParse(packet.Info.FieldInfoList[3].Value.ToString(), NumberStyles.HexNumber, null, out result20);
					leRemoteInfo item2 = default(leRemoteInfo);
					item2.addrType = result20;
					item2.remoteDeviceItem = listViewItem10;
					item2.rssi = text5;
					bool lockTaken2 = false;
					try
					{
						Monitor.Enter(obj = leRemoteDeviceQueue, ref lockTaken2);
						leRemoteDeviceQueue.Enqueue(item2);
					}
					finally
					{
						if (lockTaken2)
						{
							Monitor.Exit(obj);
						}
					}
					updateDeviceListEvent.Set();
				}
				else if (text.Contains("SynchronousConnectionCompleteEvent"))
				{
					int result21 = -1;
					int.TryParse(packet.Info.FieldInfoList[0].Value, NumberStyles.HexNumber, null, out result21);
					if (result21 == 0)
					{
						SynchronousConnectionCompleteEvent.UserFieldsWrapper.LinkTypeEnum linkTypeAsLinkTypeEnum = ((SynchronousConnectionCompleteEvent)packet).UserFields.GetLinkTypeAsLinkTypeEnum();
						int result22 = 0;
						int.TryParse(packet.Info.FieldInfoList[1].Value, NumberStyles.HexNumber, null, out result22);
						scoOverHciUserControl.CurrentSCOConnectionHandler = result22;
						string value4 = packet.Info.FieldInfoList[2].Value;
						scoOverHciUserControl.RemoteBDAddress = value4;
						EnhancedSynchronousPacketTypeEnumCollection packetType3 = EnhancedSynchronousPacketTypeInfo.ValueToEnhancedSynchronousPacketType(currentBTPacketType);
						BTLERemoteDeviceInfoList.UpdateBTRemoteDeviceSCOConnectionHandler(value4, result22, packetType3);
						ListViewItem listViewItem11 = new ListViewItem();
						if (linkTypeAsLinkTypeEnum == SynchronousConnectionCompleteEvent.UserFieldsWrapper.LinkTypeEnum.SCO_Connection)
						{
							listViewItem11.Text = "SCO";
							listViewItem11.Tag = "SCO";
						}
						else
						{
							listViewItem11.Text = "ESCO";
							listViewItem11.Tag = "ESCO";
						}
						listViewItem11.SubItems.Add(result22.ToString("X4"));
						UpdateBTSCODeviceListView(value4, listViewItem11);
					}
				}
				else if (text.Contains("ConnectionPacketTypeChange"))
				{
					int result23 = -1;
					int.TryParse(packet.Info.FieldInfoList[0].Value, NumberStyles.HexNumber, null, out result23);
					if (result23 != 0)
					{
						return;
					}
					int result24 = 0;
					int result25 = 0;
					int.TryParse(packet.Info.FieldInfoList[1].Value, NumberStyles.HexNumber, null, out result24);
					int.TryParse(packet.Info.FieldInfoList[2].Value, NumberStyles.HexNumber, null, out result25);
					string bTRemoteDeviceBDAddressByConnectionHandler2 = BTLERemoteDeviceInfoList.GetBTRemoteDeviceBDAddressByConnectionHandler(result24);
					if (bTRemoteDeviceBDAddressByConnectionHandler2 != null)
					{
						if (BTLERemoteDeviceInfoList.CheckAndGetBTRemoteDeviceInfoByBDAddress(bTRemoteDeviceBDAddressByConnectionHandler2, out var btRemoteDevice))
						{
							AclPacketTypeEnumCollection aclPacketTypeEnumCollection = AclPacketTypeInfo.ValueToAclPacketType((uint)result25);
							btRemoteDevice.dm1enable = aclPacketTypeEnumCollection.Dm1MayBeUsed == AssertBitEnum.Set;
							btRemoteDevice.dh1enable = aclPacketTypeEnumCollection.Dh1MayBeUsed == AssertBitEnum.Set;
							btRemoteDevice.dm3enable = aclPacketTypeEnumCollection.Dm3MayBeUsed == AssertBitEnum.Set;
							btRemoteDevice.dh3enable = aclPacketTypeEnumCollection.Dh3MayBeUsed == AssertBitEnum.Set;
							btRemoteDevice.dm5enable = aclPacketTypeEnumCollection.Dm5MayBeUsed == AssertBitEnum.Set;
							btRemoteDevice.dh5enable = aclPacketTypeEnumCollection.Dh5MayBeUsed == AssertBitEnum.Set;
							btRemoteDevice.twoDH1enable = aclPacketTypeEnumCollection.TwoDh1MayNotBeUsed == AssertBitEnum.Not_Set;
							btRemoteDevice.threeDH1enable = aclPacketTypeEnumCollection.ThreeDh1MayNotBeUsed == AssertBitEnum.Not_Set;
							btRemoteDevice.twoDH3enable = aclPacketTypeEnumCollection.TwoDh3MayNotBeUsed == AssertBitEnum.Not_Set;
							btRemoteDevice.threeDH3enable = aclPacketTypeEnumCollection.ThreeDh3MayNotBeUsed == AssertBitEnum.Not_Set;
							btRemoteDevice.twoDH5enable = aclPacketTypeEnumCollection.TwoDh5MayNotBeUsed == AssertBitEnum.Not_Set;
							btRemoteDevice.threeDH5enable = aclPacketTypeEnumCollection.ThreeDh5MayNotBeUsed == AssertBitEnum.Not_Set;
							BTLERemoteDeviceInfoList.UpdateBTRemoteDeviceList(btRemoteDevice);
						}
					}
					else
					{
						bTRemoteDeviceBDAddressByConnectionHandler2 = BTLERemoteDeviceInfoList.GetBTRemoteDeviceBDAddressByScoConnectionHandler(result24);
						if (bTRemoteDeviceBDAddressByConnectionHandler2 != null)
						{
							SynchronousPacketTypeEnumCollection packetType4 = SynchronousPacketTypeInfo.ValueToSynchronousPacketType((uint)result25);
							BTLERemoteDeviceInfoList.UpdateBTRemoteDeviceSCOConnectionHandler(bTRemoteDeviceBDAddressByConnectionHandler2, result24, packetType4);
						}
					}
				}
				else if (text.Contains("ConnectionRequest"))
				{
					int result26 = 1;
					int.TryParse(packet.Info.FieldInfoList[2].Value, NumberStyles.HexNumber, null, out result26);
					if (!autoAcceptConnectionRequest)
					{
						return;
					}
					switch (result26)
					{
					case 1:
					{
						string bdAddress3 = packet.Info.FieldInfoList[0].Value.ToString();
						bool flag = false;
						if (!BTLERemoteDeviceInfoList.CheckAndGetBTRemoteDeviceLMPerformMSSwitchByBDAddress(bdAddress3, out flag))
						{
							UpdateBTRemoteDeviceInfoWithLocalHostDefaultOptions(bdAddress3);
							flag = lmPerformMSswitch;
						}
						AcceptConnectRequestHandler(bdAddress3, flag);
						BTLERemoteDeviceInfoList.UpdateBTRemoteDeviceRoleByBDAddress(bdAddress3, flag ? "S" : "M");
						BTLERemoteDeviceInfoList.UpdateBTRemoteDeviceConnectionRequestByBDAddress(bdAddress3, askForConnectionRequest: true);
						break;
					}
					case 0:
					{
						string bdAddress2 = packet.Info.FieldInfoList[0].Value.ToString();
						AcceptConnectRequestHandler(bdAddress2);
						break;
					}
					case 2:
					{
						string bdAddress = packet.Info.FieldInfoList[0].Value.ToString();
						if (useEnhancedParameters)
						{
							AcceptEnhancedSynchronousRequestHandler(bdAddress);
						}
						else
						{
							AcceptESCOConnectRequestHandler(bdAddress);
						}
						break;
					}
					}
				}
				else if (text.Contains("HciModeChange"))
				{
					int result27 = -1;
					int.TryParse(packet.Info.FieldInfoList[0].Value, out result27);
					if (result27 != 0)
					{
						return;
					}
					int result28 = 0;
					int.TryParse(packet.Info.FieldInfoList[1].Value, NumberStyles.HexNumber, null, out result28);
					string bTRemoteDeviceBDAddressByConnectionHandler3 = BTLERemoteDeviceInfoList.GetBTRemoteDeviceBDAddressByConnectionHandler(result28);
					if (bTRemoteDeviceBDAddressByConnectionHandler3 != null)
					{
						int result29 = -1;
						int.TryParse(packet.Info.FieldInfoList[2].Value, NumberStyles.HexNumber, null, out result29);
						BTLERemoteDeviceInfoList.UpdateBTRemoteDeviceHCIModeByBDAddress(bTRemoteDeviceBDAddressByConnectionHandler3, (HciModeChange.UserFieldsWrapper.CurrentModeEnum)result29);
						switch ((HciModeChange.UserFieldsWrapper.CurrentModeEnum)result29)
						{
						case HciModeChange.UserFieldsWrapper.CurrentModeEnum.Active_Mode:
							UpdateBTDeviceConnectionModeListView(bTRemoteDeviceBDAddressByConnectionHandler3, HciModeChange.UserFieldsWrapper.CurrentModeEnum.Active_Mode);
							break;
						case HciModeChange.UserFieldsWrapper.CurrentModeEnum.Hold_Mode:
							UpdateBTDeviceConnectionModeListView(bTRemoteDeviceBDAddressByConnectionHandler3, HciModeChange.UserFieldsWrapper.CurrentModeEnum.Hold_Mode);
							break;
						case HciModeChange.UserFieldsWrapper.CurrentModeEnum.Sniff_Mode:
							UpdateBTDeviceConnectionModeListView(bTRemoteDeviceBDAddressByConnectionHandler3, HciModeChange.UserFieldsWrapper.CurrentModeEnum.Sniff_Mode);
							break;
						case HciModeChange.UserFieldsWrapper.CurrentModeEnum.Park_State:
							UpdateBTDeviceConnectionModeListView(bTRemoteDeviceBDAddressByConnectionHandler3, HciModeChange.UserFieldsWrapper.CurrentModeEnum.Park_State);
							break;
						}
					}
				}
				else if (text.Contains("RoleChange"))
				{
					int result30 = -1;
					int.TryParse(packet.Info.FieldInfoList[0].Value, NumberStyles.HexNumber, null, out result30);
					if (result30 == 0)
					{
						string value5 = packet.Info.FieldInfoList[1].Value;
						int result31 = -1;
						int.TryParse(packet.Info.FieldInfoList[2].Value, NumberStyles.HexNumber, null, out result31);
						switch ((RoleChange.UserFieldsWrapper.NewRoleEnum)result31)
						{
						case RoleChange.UserFieldsWrapper.NewRoleEnum.Currently_the_Master_for_specified_BD_ADDR:
							BTLERemoteDeviceInfoList.UpdateBTRemoteDeviceRoleByBDAddress(value5, "S");
							UpdateBTDeviceConnectionRole(value5, "S");
							break;
						case RoleChange.UserFieldsWrapper.NewRoleEnum.Currently_the_Slave_for_specified_BD_ADDR:
							BTLERemoteDeviceInfoList.UpdateBTRemoteDeviceRoleByBDAddress(value5, "M");
							UpdateBTDeviceConnectionRole(value5, "M");
							break;
						}
					}
				}
				else if (text.Contains("CommandCompleteForLeSetAdvertiseEnabled"))
				{
					specificPacketNotifier.SetPacketNotification(typeof(CommandCompleteForLeSetAdvertiseEnabled), generalPacketParserForUIUpdates, enabled: false);
					if (CheckStatusForPacket(packet, text.ToString()))
					{
						SetAdvertiseToolStripMenuItemCheck(itemCheck: true);
					}
				}
				else if (text.Contains("LeSetAdvertiseEnabled"))
				{
					specificPacketNotifier.SetPacketNotification(typeof(CommandCompleteForLeSetAdvertiseEnabled), generalPacketParserForUIUpdates, enabled: true);
					int result32 = -1;
					int.TryParse(packet.Info.FieldInfoList[0].Value, NumberStyles.HexNumber, null, out result32);
					advertiseToolStripMenuItem.Tag = result32 == 1;
				}
				else if (text.Contains("CommandCompleteForLeSetScanEnabled"))
				{
					specificPacketNotifier.SetPacketNotification(typeof(CommandCompleteForLeSetScanEnabled), generalPacketParserForUIUpdates, enabled: false);
					if (CheckStatusForPacket(packet, text.ToString()))
					{
						SetScanToolStripMenuItemCheck();
					}
				}
				else if (text.Contains("LeSetScanEnabled"))
				{
					specificPacketNotifier.SetPacketNotification(typeof(CommandCompleteForLeSetScanEnabled), generalPacketParserForUIUpdates, enabled: true);
					int result33 = -1;
					int.TryParse(packet.Info.FieldInfoList[0].Value, NumberStyles.HexNumber, null, out result33);
					scanToolStripMenuItem.Tag = result33 == 1;
				}
				else if (text.Contains("LeLongTermKeyRequestEvent"))
				{
					int result34 = 0;
					if (!int.TryParse(packet.Info.FieldInfoList[1].Value, NumberStyles.HexNumber, null, out result34))
					{
						return;
					}
					if (BTLERemoteDeviceInfoList.CheckAndGetLERemoteDeviceLinkKeyByConnectionHandle(result34, out var longTermKey, out var _, out var _, out var keyReply))
					{
						if (keyReply)
						{
							LeLongTermKeyRequestReply leLongTermReply = new LeLongTermKeyRequestReply();
							leLongTermReply.UserFields.ConnectionHandle = (uint)result34;
							Conversions.HexStringToByteArray(longTermKey).Select((byte b, int i) => leLongTermReply.UserFields.LongTermKeyList[i] = b).Count();
							txPacketQueue.Enqueue(leLongTermReply);
							sendPacketEvent.Set();
						}
						else
						{
							LeLongTermKeyRequestNegativeReply leLongTermKeyRequestNegativeReply = new LeLongTermKeyRequestNegativeReply();
							leLongTermKeyRequestNegativeReply.UserFields.ConnectionHandle = (uint)result34;
							txPacketQueue.Enqueue(leLongTermKeyRequestNegativeReply);
							sendPacketEvent.Set();
						}
					}
					else if (PositiveAutoReply)
					{
						LeLongTermKeyRequestReply leLongTermReply = new LeLongTermKeyRequestReply();
						leLongTermReply.UserFields.ConnectionHandle = (uint)result34;
						Conversions.HexStringToByteArray(LELinkKey).Select((byte b, int i) => leLongTermReply.UserFields.LongTermKeyList[i] = b).Count();
						txPacketQueue.Enqueue(leLongTermReply);
						sendPacketEvent.Set();
					}
					else
					{
						LeLongTermKeyRequestNegativeReply leLongTermKeyRequestNegativeReply2 = new LeLongTermKeyRequestNegativeReply();
						leLongTermKeyRequestNegativeReply2.UserFields.ConnectionHandle = (uint)result34;
						txPacketQueue.Enqueue(leLongTermKeyRequestNegativeReply2);
						sendPacketEvent.Set();
					}
				}
				else
				{
					if (text.Contains("CommandCompleteForReadRssi"))
					{
						int result35 = -1;
						if (packet.Info.FieldInfoList.Count < 1)
						{
							return;
						}
						{
							foreach (PacketFieldInfo fieldInfo in packet.Info.FieldInfoList)
							{
								if (!(fieldInfo.ParameterName == "Status"))
								{
									continue;
								}
								if (!int.TryParse(fieldInfo.Value, NumberStyles.HexNumber, null, out result35))
								{
									break;
								}
								int result36 = 0;
								string text6 = "";
								if (result35 != 0)
								{
									break;
								}
								foreach (PacketFieldInfo fieldInfo2 in packet.Info.FieldInfoList)
								{
									if (fieldInfo2.ParameterName == "RSSI")
									{
										text6 = fieldInfo2.ValueNote;
										break;
									}
								}
								foreach (PacketFieldInfo fieldInfo3 in packet.Info.FieldInfoList)
								{
									if (fieldInfo3.ParameterName == "Handle")
									{
										if (!int.TryParse(fieldInfo3.Value.ToString(), NumberStyles.HexNumber, null, out result36))
										{
											result36 = -999;
										}
										break;
									}
								}
								string bdAddress4 = "";
								BTLERemoteDeviceInfoList.UpdateLERemoteDeviceListRSSI(result36, text6, out bdAddress4);
								if (bdAddress4 != "")
								{
									UpdateLEDeviceConnectionRSSI(bdAddress4, connected: true, text6);
								}
								break;
							}
							return;
						}
					}
					if (text.Contains("LinkKeyRequest"))
					{
						if (BTLERemoteDeviceInfoList.CheckAndGetBTRemoteDeviceLinkKeyByBDAddress(packet.Info.FieldInfoList[0].Value, out var levelAuthenticationEnable, out var linkKey))
						{
							if (levelAuthenticationEnable)
							{
								LinkKeyRequestReply linkKeyRequestReply = new LinkKeyRequestReply();
								linkKeyRequestReply.UserFields.BdAddress = Convert.ToUInt64(packet.Info.FieldInfoList[0].Value, 16);
								for (int k = 0; k < linkKeyRequestReply.UserFields.LinkKeyList.Count; k++)
								{
									linkKeyRequestReply.UserFields.LinkKeyList[k] = Convert.ToUInt32(linkKey.Substring(2 * k, 2), 16);
								}
								txPacketQueue.Enqueue(linkKeyRequestReply);
								sendPacketEvent.Set();
								return;
							}
						}
						else if (LevelAuthenticationEnable)
						{
							LinkKeyRequestReply linkKeyRequestReply2 = new LinkKeyRequestReply();
							linkKeyRequestReply2.UserFields.BdAddress = Convert.ToUInt64(packet.Info.FieldInfoList[0].Value, 16);
							for (int l = 0; l < linkKeyRequestReply2.UserFields.LinkKeyList.Count; l++)
							{
								linkKeyRequestReply2.UserFields.LinkKeyList[l] = Convert.ToUInt32(LinkKey.Substring(2 * l, 2), 16);
							}
							txPacketQueue.Enqueue(linkKeyRequestReply2);
							sendPacketEvent.Set();
							return;
						}
						LinkKeyRequestNegativeReply linkKeyRequestNegativeReply = new LinkKeyRequestNegativeReply();
						linkKeyRequestNegativeReply.UserFields.BdAddress = Convert.ToUInt64(packet.Info.FieldInfoList[0].Value, 16);
						txPacketQueue.Enqueue(linkKeyRequestNegativeReply);
						sendPacketEvent.Set();
					}
					else if (text.Contains("PinCodeRequest"))
					{
						if (BTLERemoteDeviceInfoList.CheckAndGetBTRemoteDevicePinCodeByBDAddress(packet.Info.FieldInfoList[0].Value, out var levelPairingEnable, out var pinCode))
						{
							if (levelPairingEnable)
							{
								PinCodeRequestReply pinCodeRequestReply = new PinCodeRequestReply();
								pinCodeRequestReply.UserFields.BdAddress = Convert.ToUInt64(packet.Info.FieldInfoList[0].Value, 16);
								pinCodeRequestReply.UserFields.PinCodeLength = (uint)pinCode.Length / 2u;
								for (int m = 0; m < pinCodeRequestReply.UserFields.PinCodeLength; m++)
								{
									pinCodeRequestReply.UserFields.PinCodeList[m] = Convert.ToUInt32(pinCode.Substring(2 * m, 2), 16);
								}
								txPacketQueue.Enqueue(pinCodeRequestReply);
								sendPacketEvent.Set();
								return;
							}
						}
						else if (LevelPairingEnable)
						{
							PinCodeRequestReply pinCodeRequestReply2 = new PinCodeRequestReply();
							pinCodeRequestReply2.UserFields.BdAddress = Convert.ToUInt64(packet.Info.FieldInfoList[0].Value, 16);
							pinCodeRequestReply2.UserFields.PinCodeLength = (uint)PinCode.Length / 2u;
							for (int n = 0; n < pinCodeRequestReply2.UserFields.PinCodeLength; n++)
							{
								pinCodeRequestReply2.UserFields.PinCodeList[n] = Convert.ToUInt32(PinCode.Substring(2 * n, 2), 16);
							}
							txPacketQueue.Enqueue(pinCodeRequestReply2);
							sendPacketEvent.Set();
							return;
						}
						PinCodeRequestNegativeReply pinCodeRequestNegativeReply = new PinCodeRequestNegativeReply();
						pinCodeRequestNegativeReply.UserFields.BdAddress = Convert.ToUInt64(packet.Info.FieldInfoList[0].Value, 16);
						txPacketQueue.Enqueue(pinCodeRequestNegativeReply);
						sendPacketEvent.Set();
					}
					else if (text.Contains("IoCapabilityRequest"))
					{
						IoCapabilityRequestReply ioCapabilityRequestReply = new IoCapabilityRequestReply();
						ioCapabilityRequestReply.UserFields.BdAddr = Convert.ToUInt64(packet.Info.FieldInfoList[0].Value, 16);
						if (BTLERemoteDeviceInfoList.CheckAndGetBTRemoteDeviceIOCapabilityByBDAddress(packet.Info.FieldInfoList[0].Value, out var ioCapability, out var outOfBandDataPresent, out var authenticationRequirements))
						{
							ioCapabilityRequestReply.UserFields.SetIoCapabilityAsIoCapabilityEnum(ioCapability);
							ioCapabilityRequestReply.UserFields.OobDataPresent = (outOfBandDataPresent ? 1u : 0u);
							ioCapabilityRequestReply.UserFields.AuthenticationRequirements = (authenticationRequirements ? 1u : 0u);
						}
						else
						{
							ioCapabilityRequestReply.UserFields.SetIoCapabilityAsIoCapabilityEnum(IOCapability);
							ioCapabilityRequestReply.UserFields.OobDataPresent = (OutOfBandDataPresent ? 1u : 0u);
							ioCapabilityRequestReply.UserFields.AuthenticationRequirements = (AuthenticationRequirements ? 1u : 0u);
						}
						txPacketQueue.Enqueue(ioCapabilityRequestReply);
						sendPacketEvent.Set();
					}
					else if (text.Contains("IoCapabilityResponse"))
					{
						IoCapabilityEnum ioCapability2 = IoCapabilityInfo.ValueToIoCapability(Convert.ToUInt32(packet.Info.FieldInfoList[1].Value));
						BTLERemoteDeviceInfoList.UpdateBTRemoteDeviceIOCapability(packet.Info.FieldInfoList[0].Value, ioCapability2);
					}
					else if (text.Contains("UserConfirmationRequest"))
					{
						if (BTLERemoteDeviceInfoList.CheckAndGetBTRemoteDeviceConfirmationRequestReplyByBDAddress(packet.Info.FieldInfoList[0].Value, out var confirmationRequestReply))
						{
							if (confirmationRequestReply)
							{
								UserConfirmationRequestReply userConfirmationRequestReply = new UserConfirmationRequestReply();
								userConfirmationRequestReply.UserFields.BdAddr = Convert.ToUInt64(packet.Info.FieldInfoList[0].Value, 16);
								txPacketQueue.Enqueue(userConfirmationRequestReply);
								sendPacketEvent.Set();
								return;
							}
						}
						else if (ConfirmationRequestReply)
						{
							UserConfirmationRequestReply userConfirmationRequestReply2 = new UserConfirmationRequestReply();
							userConfirmationRequestReply2.UserFields.BdAddr = Convert.ToUInt64(packet.Info.FieldInfoList[0].Value, 16);
							txPacketQueue.Enqueue(userConfirmationRequestReply2);
							sendPacketEvent.Set();
							return;
						}
						UserConfirmationRequestNegativeReply userConfirmationRequestNegativeReply = new UserConfirmationRequestNegativeReply();
						userConfirmationRequestNegativeReply.UserFields.BdAddr = Convert.ToUInt64(packet.Info.FieldInfoList[0].Value, 16);
						txPacketQueue.Enqueue(userConfirmationRequestNegativeReply);
						sendPacketEvent.Set();
					}
					else if (text.Contains("UserPasskeyRequest"))
					{
						if (BTLERemoteDeviceInfoList.CheckAndGetBTRemoteDevicePasskeyRequestReplyByBDAddress(packet.Info.FieldInfoList[0].Value, out var passkeyRequestReply))
						{
							if (passkeyRequestReply)
							{
								btMainWorkerThread.SendPasskey(Convert.ToUInt64(packet.Info.FieldInfoList[0].Value, 16));
								return;
							}
						}
						else if (PasskeyRequestReply)
						{
							btMainWorkerThread.SendPasskey(Convert.ToUInt64(packet.Info.FieldInfoList[0].Value, 16));
							return;
						}
						UserPasskeyRequestNegativeReply userPasskeyRequestNegativeReply = new UserPasskeyRequestNegativeReply();
						userPasskeyRequestNegativeReply.UserFields.BdAddr = Convert.ToUInt64(packet.Info.FieldInfoList[0].Value, 16);
						txPacketQueue.Enqueue(userPasskeyRequestNegativeReply);
						sendPacketEvent.Set();
					}
					else if (text.Contains("UserPasskeyNotification"))
					{
						BTMainWorkerThread.Passkey = Convert.ToUInt32(packet.Info.FieldInfoList[1].Value, 16);
					}
					else if (text.Contains("RemoteOobDataRequest"))
					{
						RemoteOobDataRequestReply remoteOobDataRequestReply = new RemoteOobDataRequestReply();
						remoteOobDataRequestReply.UserFields.BdAddr = Convert.ToUInt64(packet.Info.FieldInfoList[0].Value, 16);
						if (BTLERemoteDeviceInfoList.CheckAndGetBTRemoteDeviceOOBDataByBDAddress(packet.Info.FieldInfoList[0].Value, out var oobc, out var oobr))
						{
							for (int num2 = 0; num2 < 16; num2++)
							{
								remoteOobDataRequestReply.UserFields.CList[num2] = Convert.ToUInt32(oobc.Substring(2 * num2, 2), 16);
								remoteOobDataRequestReply.UserFields.RList[num2] = Convert.ToUInt32(oobr.Substring(2 * num2, 2), 16);
							}
						}
						else
						{
							for (int num3 = 0; num3 < 16; num3++)
							{
								remoteOobDataRequestReply.UserFields.CList[num3] = Convert.ToUInt32(OOBC.Substring(2 * num3, 2), 16);
								remoteOobDataRequestReply.UserFields.RList[num3] = Convert.ToUInt32(OOBR.Substring(2 * num3, 2), 16);
							}
						}
						txPacketQueue.Enqueue(remoteOobDataRequestReply);
						sendPacketEvent.Set();
					}
					else if (text.Contains("LinkKeyNotification"))
					{
						BTLERemoteDeviceInfoList.UpdateBTRemoteDeviceLinkKey(packet.Info.FieldInfoList[0].Value, packet.Info.FieldInfoList[1].Value);
					}
					else if (text.Contains("RamDumpFragment"))
					{
						btAPI.BufferRAMDumpFragment(packet);
					}
					else if (text.Contains("DumpInformationVse"))
					{
						btAPI.WriteMiniDump((DumpInformationVse)packet);
					}
					else if (text.Contains("CommandCompleteForReset"))
					{
						toolStripButtonInquiryScan.Checked = false;
						toolStripButtonPageScan.Checked = false;
						toolStripButtonLEAdvertising.Checked = false;
						toolStripButtonLEScan.Checked = false;
						leSetCigMenuItem.DropDownItems.Clear();
						leRemoveCigMenuItem.DropDownItems.Clear();
						leRemoveCigMenuItem.Enabled = false;
						leCreateCisMenuItem.DropDownItems.Clear();
						leCreateCisMenuItem.Enabled = false;
						leDisconnectCisMenuItem.DropDownItems.Clear();
						PopulateSetCigMenuDefault(numCis);
						if (leCisInfo != null)
						{
							leCisInfo.leCisInfoList.Clear();
							leCisInfo.pendingCisId = -1;
						}
						prodTestUserControl.Stop();
						leRemoteDeviceQueue.Clear();
						UpdateBTDeviceListView(null);
						BTLERemoteDeviceInfoList.btRemoteDeviceInfo.Clear();
						BTLERemoteDeviceInfoList.leRemoteDeviceInfo.Clear();
						FileDataTranfer(enable: false);
					}
					else if (text.Contains("LeRemoteConnectionParameterRequest"))
					{
						int result37 = 0;
						if (!int.TryParse(packet.Info.FieldInfoList[1].Value, NumberStyles.HexNumber, null, out result37))
						{
							return;
						}
						if (BTLERemoteDeviceInfoList.CheckAndGetLERemoteDeviceConnectionUpdateByConnectionHandle(result37, out var intervalMin, out var intervalMax, out var timeoutMs, out var latency, out var ceLengthMin, out var ceLengthMax, out var keyReply2, out var paramRejectReason))
						{
							if (keyReply2)
							{
								LeRemoteConnectionParameterRequestReply leRemoteConnectionParameterRequestReply = new LeRemoteConnectionParameterRequestReply();
								leRemoteConnectionParameterRequestReply.UserFields.ConnectionHandle = (uint)result37;
								leRemoteConnectionParameterRequestReply.UserFields.IntervalMax = intervalMax;
								leRemoteConnectionParameterRequestReply.UserFields.IntervalMin = intervalMin;
								leRemoteConnectionParameterRequestReply.UserFields.Latency = latency;
								leRemoteConnectionParameterRequestReply.UserFields.MaximumCeLength = ceLengthMax;
								leRemoteConnectionParameterRequestReply.UserFields.MinimumCeLength = ceLengthMin;
								leRemoteConnectionParameterRequestReply.UserFields.Timeout = timeoutMs;
								txPacketQueue.Enqueue(leRemoteConnectionParameterRequestReply);
								sendPacketEvent.Set();
							}
							else
							{
								LeRemoteConnectionParameterRequestNegativeReply leRemoteConnectionParameterRequestNegativeReply = new LeRemoteConnectionParameterRequestNegativeReply();
								leRemoteConnectionParameterRequestNegativeReply.UserFields.ConnectionHandle = (uint)result37;
								leRemoteConnectionParameterRequestNegativeReply.UserFields.Reason = paramRejectReason;
								txPacketQueue.Enqueue(leRemoteConnectionParameterRequestNegativeReply);
								sendPacketEvent.Set();
							}
						}
						else if (connUpdateParamRequestPositiveReply)
						{
							LeRemoteConnectionParameterRequestReply leRemoteConnectionParameterRequestReply2 = new LeRemoteConnectionParameterRequestReply();
							leRemoteConnectionParameterRequestReply2.UserFields.ConnectionHandle = (uint)result37;
							leRemoteConnectionParameterRequestReply2.UserFields.IntervalMax = connUpdateIntervalMax;
							leRemoteConnectionParameterRequestReply2.UserFields.IntervalMin = connUpdateIntervalMin;
							leRemoteConnectionParameterRequestReply2.UserFields.Latency = connUpdateLatency;
							leRemoteConnectionParameterRequestReply2.UserFields.MaximumCeLength = connUpdateCeLengthMax;
							leRemoteConnectionParameterRequestReply2.UserFields.MinimumCeLength = connUpdateCeLengthMin;
							leRemoteConnectionParameterRequestReply2.UserFields.Timeout = connUpdateTimeoutMs;
							txPacketQueue.Enqueue(leRemoteConnectionParameterRequestReply2);
							sendPacketEvent.Set();
						}
						else
						{
							LeRemoteConnectionParameterRequestNegativeReply leRemoteConnectionParameterRequestNegativeReply2 = new LeRemoteConnectionParameterRequestNegativeReply();
							leRemoteConnectionParameterRequestNegativeReply2.UserFields.ConnectionHandle = (uint)result37;
							leRemoteConnectionParameterRequestNegativeReply2.UserFields.Reason = connUpdateParamRejectReason;
							txPacketQueue.Enqueue(leRemoteConnectionParameterRequestNegativeReply2);
							sendPacketEvent.Set();
						}
					}
					else if (text.Contains("CommandCompleteForReadBdAddr"))
					{
						CommandCompleteForReadBdAddr commandCompleteForReadBdAddr = (CommandCompleteForReadBdAddr)packet;
						localBDAddress = $"{commandCompleteForReadBdAddr.UserFields.BdAddr:X12}";
						base.TitleBarMessage = "QCRPG-BT   Address: " + localBDAddress + localApplicationInfo;
						UpdateTitleBar();
					}
					else if (text.Contains("CommandCompleteForWriteScanEnable"))
					{
						if (scanEnable == WriteScanEnable.UserFieldsWrapper.ScanEnableEnum.BOTH_SCANS_ENABLED)
						{
							toolStripButtonPageScan.Checked = true;
							toolStripButtonInquiryScan.Checked = true;
						}
						else if (scanEnable == WriteScanEnable.UserFieldsWrapper.ScanEnableEnum.INQUIRY_SCAN_ENABLED)
						{
							toolStripButtonPageScan.Checked = false;
							toolStripButtonInquiryScan.Checked = true;
						}
						else if (scanEnable == WriteScanEnable.UserFieldsWrapper.ScanEnableEnum.PAGE_SCAN_ENABLED)
						{
							toolStripButtonPageScan.Checked = true;
							toolStripButtonInquiryScan.Checked = false;
						}
						else
						{
							toolStripButtonPageScan.Checked = false;
							toolStripButtonInquiryScan.Checked = false;
						}
					}
					else if (text.Contains("CommandCompleteForLeSetCigParametersTest") && leCisInfo != null)
					{
						CommandCompleteForLeSetCigParametersTest commandCompleteForLeSetCigParametersTest = (CommandCompleteForLeSetCigParametersTest)packet;
						if (commandCompleteForLeSetCigParametersTest.UserFields.Status == 0)
						{
							leSetCigMenuItem.DropDownItems.RemoveByKey("CIS ID " + leCisInfo.pendingCisId);
							if (leSetCigMenuItem.DropDownItems.Count == 0)
							{
								leSetCigMenuItem.Enabled = false;
							}
							else
							{
								leSetCigMenuItem.Enabled = true;
							}
							leRemoveCigMenuItem.Enabled = true;
							if (leCreateCisMenuItem.DropDownItems.Count == 0)
							{
								leCreateCisMenuItem.DropDownItems.Add(new ToolStripMenuItem("All CIS")
								{
									Name = "All CIS"
								});
								leCreateCisMenuItem.DropDownItems[leCreateCisMenuItem.DropDownItems.Count - 1].Click += leCreateAllCis_Click;
							}
							if (!leCreateCisMenuItem.DropDownItems.ContainsKey("CIS ID " + leCisInfo.pendingCisId))
							{
								leCreateCisMenuItem.DropDownItems.Add(new ToolStripMenuItem("CIS ID " + leCisInfo.pendingCisId)
								{
									Name = "CIS ID " + leCisInfo.pendingCisId
								});
								leCreateCisMenuItem.DropDownItems[leCreateCisMenuItem.DropDownItems.Count - 1].Click += leCreateCis_Click;
								leCreateCisMenuItem.Enabled = true;
							}
							LECisInfo.LECisData item3 = default(LECisInfo.LECisData);
							item3.icoChannelID = (uint)leCisInfo.pendingCisId;
							item3.cisHandle = commandCompleteForLeSetCigParametersTest.UserFields.ConnectionHandlesList[0].ConnectionHandle;
							leCisInfo.leCisInfoList.Add(item3);
						}
						leCisInfo.pendingCisId = -1;
					}
					else if (text.Contains("LeCisEstablished") && leCisInfo != null)
					{
						LeCisEstablished leCisEstablished = (LeCisEstablished)packet;
						if (leCisEstablished.UserFields.Status == 0)
						{
							BTLERemoteDeviceInfoList.UpdateLERemoteDeviceCisHandleByBTConnectionHandler(currentBTConnectionHandler, (int)leCisEstablished.UserFields.ConnectionHandle);
							string text7 = "CIS ID " + leCisInfo.LeGetCisChannelIdPerCisHandle(leCisEstablished.UserFields.ConnectionHandle);
							if (!leDisconnectCisMenuItem.DropDownItems.ContainsKey(text7))
							{
								leDisconnectCisMenuItem.DropDownItems.Add(new ToolStripMenuItem(text7)
								{
									Name = text7
								});
								leDisconnectCisMenuItem.DropDownItems[leDisconnectCisMenuItem.DropDownItems.Count - 1].Click += leDisconnectCis_Click;
								leDisconnectCisMenuItem.Enabled = true;
							}
							leCreateCisMenuItem.DropDownItems.RemoveByKey(text7);
							if (leCreateCisMenuItem.DropDownItems.Count < 2)
							{
								leCreateCisMenuItem.DropDownItems.Clear();
								leCreateCisMenuItem.Enabled = false;
							}
							string lERemoteDeviceBDAddressByConnectionHandler = BTLERemoteDeviceInfoList.GetLERemoteDeviceBDAddressByConnectionHandler(currentBTConnectionHandler);
							UpdateBLEDeviceConnectionStatus(lERemoteDeviceBDAddressByConnectionHandler, connected: true);
						}
					}
					else if (text.Contains("LeCisRequest"))
					{
						if (cisAutoAccept)
						{
							LeCisRequest leCisRequest = (LeCisRequest)packet;
							LeAcceptCisRequest leAcceptCisRequest = new LeAcceptCisRequest();
							leAcceptCisRequest._UserFields.ConnectionHandle = leCisRequest.UserFields.CisConnectionHandle;
							txPacketQueue.Enqueue(leAcceptCisRequest);
							sendPacketEvent.Set();
							BTLERemoteDeviceInfoList.UpdateLERemoteDeviceCisHandleByBTConnectionHandler((int)leCisRequest.UserFields.AclConnectionHandle, (int)leCisRequest.UserFields.CisConnectionHandle);
							string text8 = "CIS ID " + leCisRequest.UserFields.CisId;
							leCreateCisMenuItem.DropDownItems.RemoveByKey(text8);
							if (!leDisconnectCisMenuItem.DropDownItems.ContainsKey(text8))
							{
								leDisconnectCisMenuItem.DropDownItems.Add(new ToolStripMenuItem(text8)
								{
									Name = text8
								});
								leDisconnectCisMenuItem.DropDownItems[leDisconnectCisMenuItem.DropDownItems.Count - 1].Click += leDisconnectCis_Click;
								leDisconnectCisMenuItem.Enabled = true;
							}
							if (leCisInfo == null)
							{
								leCisInfo = new LECisInfo();
							}
							LECisInfo.LECisData item4 = default(LECisInfo.LECisData);
							item4.cisHandle = leCisRequest.UserFields.CisConnectionHandle;
							item4.icoChannelID = leCisRequest.UserFields.CisId;
							leCisInfo.leCisInfoList.Add(item4);
						}
					}
					else if (text.Contains("CommandCompleteForLeRemoveCig"))
					{
						PopulateSetCigMenuDefault(numCis);
						leRemoveCigMenuItem.Enabled = false;
						leCreateCisMenuItem.DropDownItems.Clear();
						leCreateCisMenuItem.Enabled = false;
					}
					else if (text.Contains("CommandCompleteForLeTestEnd"))
					{
						CommandCompleteForLeTestEnd commandComplete = (CommandCompleteForLeTestEnd)packet;
						Action action = delegate
						{
							leProdTestuserControl.UpdateNoOfReceivedPackets(commandComplete.UserFields.NumberOfPackets);
						};
						if (leProdTestuserControl.InvokeRequired)
						{
							leProdTestuserControl.Invoke(action);
						}
						else
						{
							action();
						}
					}
				}
			}
		}
	}

	private void UpdateStatusBarInfo(PacketBase packet)
	{
		if (packet.GetType() == typeof(ConnectionComplete) && toolStripStatusLabelEmpty != null)
		{
			toolStripStatusLabelEmpty.Text = "Connection Handle: " + packet.Info.FieldInfoList[1].Value.ToString();
		}
	}

	private void FileDataTranfer(bool enable)
	{
		if (enable)
		{
			toolStripButtonFileTransfer.Enabled = true;
			toolStripButtonDataTransfer.Enabled = true;
		}
		else
		{
			toolStripButtonFileTransfer.Enabled = false;
			toolStripButtonDataTransfer.Enabled = false;
		}
	}

	private void updateConnectionPacketInfoTimer_Elapsed(object sender, EventArgs e)
	{
		if (toolStripStatusLabelConnectionPacketInfo != null && toolStripStatusLabelPacketInfo != null)
		{
			string text = $"Command:   {command}   Event:   {notification}   ";
			toolStripStatusLabelPacketInfo.Text = text.ToString();
			text = $"TxACL:    {TxAcl}   RxACL:    {RxAcl}   TxSCO:    {TxSco}   RxSCO:    {RxSco}   ";
			toolStripStatusLabelConnectionPacketInfo.Text = text.ToString();
		}
	}

	private void InquiryHandler()
	{
		Inquiry inquiry = new Inquiry();
		inquiry.UserFields.InquiryLength = (uint)Length;
		inquiry.UserFields.Lap = Convert.ToUInt32(Lap, 16);
		inquiry.UserFields.NumResponses = (uint)Responses;
		try
		{
			btAPI.Send(inquiry);
		}
		catch (Exception ex)
		{
			logger.Enqueue(new QCRPG.Framework.LogMessage(LogMessageType.Error, ex));
		}
	}

	private void ReadLocalExtendedFeaturesHandler(uint pageNumber)
	{
		ReadLocalExtendedFeatures readLocalExtendedFeatures = new ReadLocalExtendedFeatures();
		readLocalExtendedFeatures.UserFields.PageNumber = pageNumber;
		try
		{
			btAPI.Send(readLocalExtendedFeatures);
		}
		catch (Exception ex)
		{
			logger.Enqueue(new QCRPG.Framework.LogMessage(LogMessageType.Error, ex));
		}
	}

	private void AcceptConnectRequestHandler(string bdAddress, bool lmPerformMSSwitch = false)
	{
		HciAcceptConnectionRequest hciAcceptConnectionRequest = new HciAcceptConnectionRequest();
		hciAcceptConnectionRequest.UserFields.BdAddr = Convert.ToUInt64(bdAddress, 16);
		hciAcceptConnectionRequest.UserFields.Role = ((!lmPerformMSSwitch) ? 1u : 0u);
		try
		{
			txPacketQueue.Enqueue(hciAcceptConnectionRequest);
			sendPacketEvent.Set();
		}
		catch (Exception ex)
		{
			logger.Enqueue(new QCRPG.Framework.LogMessage(LogMessageType.Error, ex));
		}
	}

	private void AcceptESCOConnectRequestHandler(string bdAddress)
	{
		int result = 0;
		int.TryParse(VoiceSetting, NumberStyles.HexNumber, null, out result);
		int packetType = CalculatePacketTypeForESCOConnection();
		int retransmissionEffort = CalculateRetransmissionEffortForESCOConnection();
		AcceptSynchronousConnectionRequest acceptSynchronousConnectionRequest = new AcceptSynchronousConnectionRequest();
		acceptSynchronousConnectionRequest.UserFields.BdAddr = Convert.ToUInt64(bdAddress, 16);
		acceptSynchronousConnectionRequest.UserFields.TransmitBandwidth = (uint)TransmitBandwidth;
		acceptSynchronousConnectionRequest.UserFields.ReceiveBandwidth = (uint)ReceiveBandwidth;
		acceptSynchronousConnectionRequest.UserFields.MaxLatency = (uint)MaxLatency;
		acceptSynchronousConnectionRequest.UserFields.VoiceSetting = (uint)result;
		acceptSynchronousConnectionRequest.UserFields.RetransmissionEffort = (uint)retransmissionEffort;
		acceptSynchronousConnectionRequest.UserFields.PacketType = (uint)packetType;
		try
		{
			txPacketQueue.Enqueue(acceptSynchronousConnectionRequest);
			sendPacketEvent.Set();
		}
		catch (Exception ex)
		{
			logger.Enqueue(new QCRPG.Framework.LogMessage(LogMessageType.Error, ex));
		}
	}

	private void AcceptEnhancedSynchronousRequestHandler(string bdAddress)
	{
		int packetType = CalculatePacketTypeForESCOConnection();
		int retransmissionEffort = CalculateRetransmissionEffortForESCOConnection();
		EnhancedAcceptSynchronousConnectionRequest enhancedAcceptSynchronousConnectionRequest = new EnhancedAcceptSynchronousConnectionRequest();
		enhancedAcceptSynchronousConnectionRequest.UserFields.BdAddr = Convert.ToUInt64(bdAddress, 16);
		enhancedAcceptSynchronousConnectionRequest.UserFields.TransmitBandwidth = (uint)TransmitBandwidth_enhSync;
		enhancedAcceptSynchronousConnectionRequest.UserFields.ReceiveBandwidth = (uint)ReceiveBandwidth_enhSync;
		enhancedAcceptSynchronousConnectionRequest.UserFields.MaxLatency = (uint)MaxLatency_enhSync;
		enhancedAcceptSynchronousConnectionRequest.UserFields.RetransmissionEffort = (uint)retransmissionEffort;
		enhancedAcceptSynchronousConnectionRequest.UserFields.PacketType = (uint)packetType;
		enhancedAcceptSynchronousConnectionRequest.UserFields.InputDataPath = (uint)inputDataPath;
		enhancedAcceptSynchronousConnectionRequest.UserFields.OutputDataPath = (uint)outputDataPath;
		enhancedAcceptSynchronousConnectionRequest.UserFields.TransmitCodingFormat = (ulong)TxRxCodingFormat;
		enhancedAcceptSynchronousConnectionRequest.UserFields.ReceiveCodingFormat = (ulong)TxRxCodingFormat;
		enhancedAcceptSynchronousConnectionRequest.UserFields.InputPcmSamplePayloadMsbPosition = (uint)PcmSamplePayload;
		enhancedAcceptSynchronousConnectionRequest.UserFields.OutputPcmSamplePayloadMsbPosition = (uint)PcmSamplePayload;
		enhancedAcceptSynchronousConnectionRequest.UserFields.InputCodeDataSize = (uint)IOCodedDataSize;
		enhancedAcceptSynchronousConnectionRequest.UserFields.OutputCodeDataSize = (uint)IOCodedDataSize;
		enhancedAcceptSynchronousConnectionRequest.UserFields.InputPcmDataFormat = (uint)IOPcmDataFormat;
		enhancedAcceptSynchronousConnectionRequest.UserFields.OutputPcmDataFormat = (uint)IOPcmDataFormat;
		enhancedAcceptSynchronousConnectionRequest.UserFields.InputCodingFormat = (ulong)IOCodingFormat;
		enhancedAcceptSynchronousConnectionRequest.UserFields.OutputCodingFormat = (ulong)IOCodingFormat;
		try
		{
			txPacketQueue.Enqueue(enhancedAcceptSynchronousConnectionRequest);
			sendPacketEvent.Set();
		}
		catch (Exception ex)
		{
			logger.Enqueue(new QCRPG.Framework.LogMessage(LogMessageType.Error, ex));
		}
	}

	private void LEAdvertiseHandler(bool enable)
	{
		LeSetAdvertiseEnabled leSetAdvertiseEnabled = new LeSetAdvertiseEnabled();
		leSetAdvertiseEnabled.UserFields.AdvertisingEnable = (enable ? 1u : 0u);
		try
		{
			specificPacketNotifier.SetPacketNotification(typeof(CommandCompleteForLeSetAdvertiseEnabled), generalPacketParserForUIUpdates, enabled: true);
			btAPI.Send(leSetAdvertiseEnabled);
		}
		catch (Exception ex)
		{
			logger.Enqueue(new QCRPG.Framework.LogMessage(LogMessageType.Error, ex));
		}
	}

	private void LEScanHandler(bool enable)
	{
		LeSetScanEnabled leSetScanEnabled = new LeSetScanEnabled();
		leSetScanEnabled.UserFields.FilterDuplicates = 0u;
		leSetScanEnabled.UserFields.LeScanEnable = (enable ? 1u : 0u);
		try
		{
			specificPacketNotifier.SetPacketNotification(typeof(CommandCompleteForLeSetScanEnabled), generalPacketParserForUIUpdates, enabled: true);
			if (enable)
			{
				specificPacketNotifier.SetPacketNotification(typeof(LeAdvertisingReport), generalPacketParserForUIUpdates, enabled: true);
			}
			else
			{
				specificPacketNotifier.SetPacketNotification(typeof(LeAdvertisingReport), generalPacketParserForUIUpdates, enabled: false);
			}
			btAPI.Send(leSetScanEnabled);
		}
		catch (Exception ex)
		{
			logger.Enqueue(new QCRPG.Framework.LogMessage(LogMessageType.Error, ex));
		}
	}

	private void BTConnectionHandler(string bdAddress, uint packetType, uint pageScanRepMode, uint clockOffSet, bool allowRoleSwitch)
	{
		CreateConnection createConnection = new CreateConnection();
		createConnection.UserFields.BdAddress = Convert.ToUInt64(bdAddress, 16);
		createConnection.UserFields.PacketTypeMask = packetType;
		createConnection.UserFields.PageScanRepetitionMode = pageScanRepMode;
		createConnection.UserFields.ClockOffset = clockOffSet;
		createConnection.UserFields.AllowRoleSwitch = (allowRoleSwitch ? 1u : 0u);
		try
		{
			BTLERemoteDeviceInfoList.UpdateBTRemoteDeviceConnectionRequestByBDAddress(bdAddress, askForConnectionRequest: true);
			btAPI.Send(createConnection);
		}
		catch (Exception ex)
		{
			logger.Enqueue(new QCRPG.Framework.LogMessage(LogMessageType.Error, ex));
		}
	}

	private void BTDisconnectionHandler(int connectionHandler)
	{
		Disconnect disconnect = new Disconnect();
		disconnect.UserFields.ConnectionHandle = (uint)connectionHandler;
		disconnect.UserFields.SetReasonAsReasonEnum(Disconnect.UserFieldsWrapper.ReasonEnum.REMOTE_USER_TERMINATED_CONNECTION);
		try
		{
			btAPI.Send(disconnect);
		}
		catch (Exception ex)
		{
			logger.Enqueue(new QCRPG.Framework.LogMessage(LogMessageType.Error, ex));
		}
	}

	private void LEReadRemoteVersionHandler(int connectionHandler)
	{
		ReadRemoteVersionInformation readRemoteVersionInformation = new ReadRemoteVersionInformation();
		readRemoteVersionInformation.UserFields.ConnectionHandle = (uint)connectionHandler;
		try
		{
			btAPI.Send(readRemoteVersionInformation);
		}
		catch (Exception ex)
		{
			logger.Enqueue(new QCRPG.Framework.LogMessage(LogMessageType.Error, ex));
		}
	}

	private void LEReadChannelMapHandler(int connectionHandler)
	{
		LeReadChannelMap leReadChannelMap = new LeReadChannelMap();
		leReadChannelMap.UserFields.ConnectionHandle = (uint)connectionHandler;
		try
		{
			btAPI.Send(leReadChannelMap);
		}
		catch (Exception ex)
		{
			logger.Enqueue(new QCRPG.Framework.LogMessage(LogMessageType.Error, ex));
		}
	}

	private void LEReadRemoteFeatureHandler(int connectionHandler)
	{
		LeReadRemoteFeatures leReadRemoteFeatures = new LeReadRemoteFeatures();
		leReadRemoteFeatures.UserFields.ConnectionHandle = (uint)connectionHandler;
		try
		{
			btAPI.Send(leReadRemoteFeatures);
		}
		catch (Exception ex)
		{
			logger.Enqueue(new QCRPG.Framework.LogMessage(LogMessageType.Error, ex));
		}
	}

	private void LEStartEncryptionHandler(int connectionHandle)
	{
		LeStartEncryption startEncryption = new LeStartEncryption();
		startEncryption.UserFields.ConnectionHandle = (uint)connectionHandle;
		if (BTLERemoteDeviceInfoList.CheckAndGetLERemoteDeviceLinkKeyByConnectionHandle(connectionHandle, out var longTermKey, out var randomNumber, out var encryptedDiversifier, out var _))
		{
			Conversions.HexStringToByteArray(longTermKey).Select((byte b, int i) => startEncryption._UserFields.LongTermKeyList[i] = b).Count();
			startEncryption._UserFields.RandomNumber = ulong.Parse(randomNumber, NumberStyles.HexNumber);
			startEncryption._UserFields.EncryptedDiversifier = uint.Parse(encryptedDiversifier, NumberStyles.HexNumber);
		}
		else
		{
			Conversions.HexStringToByteArray(LELinkKey).Select((byte b, int i) => startEncryption._UserFields.LongTermKeyList[i] = b).Count();
			startEncryption._UserFields.RandomNumber = ulong.Parse(RandomNumber, NumberStyles.HexNumber);
			startEncryption._UserFields.EncryptedDiversifier = uint.Parse(EncryptedDiversifier, NumberStyles.HexNumber);
		}
		try
		{
			btAPI.Send(startEncryption);
		}
		catch (Exception ex)
		{
			logger.Enqueue(new QCRPG.Framework.LogMessage(LogMessageType.Error, ex));
		}
	}

	private void LEUpdateConnectionHandler(int connectionHandle)
	{
		LeConnectionUpdate leConnectionUpdate = new LeConnectionUpdate();
		leConnectionUpdate.UserFields.ConnectionHandle = (uint)connectionHandle;
		if (BTLERemoteDeviceInfoList.CheckAndGetLERemoteDeviceConnectionUpdateByConnectionHandle(connectionHandle, out var intervalMin, out var intervalMax, out var timeoutMs, out var latency, out var ceLengthMin, out var ceLengthMax, out var _, out var _))
		{
			leConnectionUpdate.UserFields.ConnIntervalMin = (uint)((double)intervalMin / 1.25);
			leConnectionUpdate.UserFields.ConnIntervalMax = (uint)((double)intervalMax / 1.25);
			leConnectionUpdate.UserFields.ConnLatency = latency;
			leConnectionUpdate.UserFields.SupervisionTimeout = timeoutMs / 10;
			leConnectionUpdate.UserFields.MinimumCeLength = (uint)((double)ceLengthMin / 0.625);
			leConnectionUpdate.UserFields.MaximumCeLength = (uint)((double)ceLengthMax / 0.625);
		}
		else
		{
			leConnectionUpdate.UserFields.ConnIntervalMin = (uint)((double)ConnectionTimingMinInterval / 1.25);
			leConnectionUpdate.UserFields.ConnIntervalMax = (uint)((double)ConnectionTimingMaxInterval / 1.25);
			leConnectionUpdate.UserFields.ConnLatency = (uint)ConnectionTimingLatency;
			leConnectionUpdate.UserFields.SupervisionTimeout = (uint)ConnectionTimingTimeout / 10u;
			leConnectionUpdate.UserFields.MinimumCeLength = (uint)((double)ConnectionEventTimingMinLength / 0.625);
			leConnectionUpdate.UserFields.MaximumCeLength = (uint)((double)ConnectionEventTimingMaxLength / 0.625);
		}
		try
		{
			btAPI.Send(leConnectionUpdate);
		}
		catch (Exception ex)
		{
			logger.Enqueue(new QCRPG.Framework.LogMessage(LogMessageType.Error, ex));
		}
	}

	private void LEEditSelectedDeviceHandler(BTLERemoteDeviceInfo.LERemoteDeviceInfo leRemoteDeviceInfo)
	{
		LERemoteDeviceOptions lERemoteDeviceOptions = new LERemoteDeviceOptions();
		lERemoteDeviceOptions.BDAddress = leRemoteDeviceInfo.bdAddress;
		lERemoteDeviceOptions.PositiveReply = leRemoteDeviceInfo.keyReply;
		lERemoteDeviceOptions.NegativeReply = !leRemoteDeviceInfo.keyReply;
		lERemoteDeviceOptions.LeLongTermKey = leRemoteDeviceInfo.longTermKey;
		lERemoteDeviceOptions.LeRandomNumber = leRemoteDeviceInfo.randomNumber;
		lERemoteDeviceOptions.LeEncryptedDiversifier = leRemoteDeviceInfo.encryptedDiversifier;
		lERemoteDeviceOptions.LeLongTermKeys = recentParameterSettings.leLongTermKeys;
		lERemoteDeviceOptions.LeRandomNumbers = recentParameterSettings.leRandomNumbers;
		lERemoteDeviceOptions.LEConnUpdateIntervalMin = leRemoteDeviceInfo.connUpdateIntervalMin;
		lERemoteDeviceOptions.LEConnUpdateIntervalMax = leRemoteDeviceInfo.connUpdateIntervalMax;
		lERemoteDeviceOptions.LEConnUpdateTimeoutmsec = leRemoteDeviceInfo.connUpdateTimeoutMs;
		lERemoteDeviceOptions.LEConnUpdateLatency = leRemoteDeviceInfo.connUpdateLatency;
		lERemoteDeviceOptions.LEConnUpdateCELengthMin = leRemoteDeviceInfo.connUpdateCELengthMin;
		lERemoteDeviceOptions.LEConnUpdateCELengthMax = leRemoteDeviceInfo.connUpdateCELengthMax;
		lERemoteDeviceOptions.LEConnRequestPositiveAutoReply = leRemoteDeviceInfo.connUpdateParamRequestAutoReply;
		lERemoteDeviceOptions.LEConnRequestNegativeAutoReply = !leRemoteDeviceInfo.connUpdateParamRequestAutoReply;
		lERemoteDeviceOptions.LEConnRequestRejectReason = leRemoteDeviceInfo.connUpdateParamReqRejectReason;
		DialogResult dialogResult = lERemoteDeviceOptions.ShowDialog();
		if (dialogResult == DialogResult.OK)
		{
			leRemoteDeviceInfo.keyReply = lERemoteDeviceOptions.PositiveReply;
			leRemoteDeviceInfo.longTermKey = lERemoteDeviceOptions.LeLongTermKey;
			leRemoteDeviceInfo.randomNumber = lERemoteDeviceOptions.LeRandomNumber;
			leRemoteDeviceInfo.encryptedDiversifier = lERemoteDeviceOptions.LeEncryptedDiversifier;
			leRemoteDeviceInfo.connUpdateIntervalMin = lERemoteDeviceOptions.LEConnUpdateIntervalMin;
			leRemoteDeviceInfo.connUpdateIntervalMax = lERemoteDeviceOptions.LEConnUpdateIntervalMax;
			leRemoteDeviceInfo.connUpdateTimeoutMs = lERemoteDeviceOptions.LEConnUpdateTimeoutmsec;
			leRemoteDeviceInfo.connUpdateLatency = lERemoteDeviceOptions.LEConnUpdateLatency;
			leRemoteDeviceInfo.connUpdateCELengthMin = lERemoteDeviceOptions.LEConnUpdateCELengthMin;
			leRemoteDeviceInfo.connUpdateCELengthMax = lERemoteDeviceOptions.LEConnUpdateCELengthMax;
			leRemoteDeviceInfo.connUpdateParamRequestAutoReply = lERemoteDeviceOptions.LEConnRequestPositiveAutoReply;
			leRemoteDeviceInfo.connUpdateParamReqRejectReason = lERemoteDeviceOptions.LEConnRequestRejectReason;
			BTLERemoteDeviceInfoList.UpdateLERemoteDeviceList(leRemoteDeviceInfo);
		}
	}

	private void SCODisconnectionHandler(string connectionHandler)
	{
		int result = 0;
		int.TryParse(connectionHandler, NumberStyles.HexNumber, null, out result);
		if (result != 0)
		{
			BTDisconnectionHandler(result);
		}
	}

	private void AddSCOConnectionHandler(int connectionHandler, uint packetType)
	{
		AddScoConnection addScoConnection = new AddScoConnection();
		addScoConnection.UserFields.ConnectionHandle = (uint)connectionHandler;
		addScoConnection.UserFields.PacketType = packetType;
		try
		{
			btAPI.Send(addScoConnection);
		}
		catch (Exception ex)
		{
			logger.Enqueue(new QCRPG.Framework.LogMessage(LogMessageType.Error, ex));
		}
	}

	public void AddESCOConnectionHandler(int connectionHandler, int voiceSettings, int retransmissionEffort, int packetType)
	{
		HciSetupSynchronousConnection hciSetupSynchronousConnection = new HciSetupSynchronousConnection();
		hciSetupSynchronousConnection.UserFields.ConnectionHandle = (uint)connectionHandler;
		hciSetupSynchronousConnection.UserFields.TransmitBandwidth = (uint)TransmitBandwidth;
		hciSetupSynchronousConnection.UserFields.ReceiveBandwidth = (uint)ReceiveBandwidth;
		hciSetupSynchronousConnection.UserFields.MaxLatency = (uint)MaxLatency;
		hciSetupSynchronousConnection.UserFields.VoiceSetting = (uint)voiceSettings;
		hciSetupSynchronousConnection.UserFields.RetransmissionEffort = (uint)retransmissionEffort;
		hciSetupSynchronousConnection.UserFields.PacketType = (uint)packetType;
		try
		{
			btAPI.Send(hciSetupSynchronousConnection);
		}
		catch (Exception ex)
		{
			logger.Enqueue(new QCRPG.Framework.LogMessage(LogMessageType.Error, ex));
		}
	}

	public void AddEnhancedSynchronousConnectionHandler(int connectionHandler, int retransmissionEffort, int packetType)
	{
		EnhancedSetupSynchronousConnection enhancedSetupSynchronousConnection = new EnhancedSetupSynchronousConnection();
		enhancedSetupSynchronousConnection.UserFields.ConnectionHandle = (uint)connectionHandler;
		enhancedSetupSynchronousConnection.UserFields.TransmitBandwidth = (uint)TransmitBandwidth_enhSync;
		enhancedSetupSynchronousConnection.UserFields.ReceiveBandwidth = (uint)ReceiveBandwidth_enhSync;
		enhancedSetupSynchronousConnection.UserFields.MaxLatency = (uint)MaxLatency_enhSync;
		enhancedSetupSynchronousConnection.UserFields.RetransmissionEffort = (uint)retransmissionEffort;
		enhancedSetupSynchronousConnection.UserFields.PacketType = (uint)packetType;
		enhancedSetupSynchronousConnection.UserFields.InputDataPath = (uint)inputDataPath;
		enhancedSetupSynchronousConnection.UserFields.OutputDataPath = (uint)outputDataPath;
		enhancedSetupSynchronousConnection.UserFields.TransmitCodingFormat = (ulong)TxRxCodingFormat;
		enhancedSetupSynchronousConnection.UserFields.ReceiveCodingFormat = (ulong)TxRxCodingFormat;
		enhancedSetupSynchronousConnection.UserFields.InputPcmSamplePayloadMsbPosition = (uint)PcmSamplePayload;
		enhancedSetupSynchronousConnection.UserFields.OutputPcmSamplePayloadMsbPosition = (uint)PcmSamplePayload;
		enhancedSetupSynchronousConnection.UserFields.InputCodeDataSize = (uint)IOCodedDataSize;
		enhancedSetupSynchronousConnection.UserFields.OutputCodeDataSize = (uint)IOCodedDataSize;
		enhancedSetupSynchronousConnection.UserFields.InputPcmDataFormat = (uint)IOPcmDataFormat;
		enhancedSetupSynchronousConnection.UserFields.OutputPcmDataFormat = (uint)IOPcmDataFormat;
		enhancedSetupSynchronousConnection.UserFields.InputCodingFormat = (ulong)IOCodingFormat;
		enhancedSetupSynchronousConnection.UserFields.OutputCodingFormat = (ulong)IOCodingFormat;
		try
		{
			btAPI.Send(enhancedSetupSynchronousConnection);
		}
		catch (Exception ex)
		{
			logger.Enqueue(new QCRPG.Framework.LogMessage(LogMessageType.Error, ex));
		}
	}

	private void ModifyESCOConnectionHandler(string connectionHandlerString, bool enhancedParameters = false)
	{
		useEnhancedParameters = enhancedParameters;
		escoParameters = new ESCOParameters();
		escoParameters.transmitBandwidth = TransmitBandwidth;
		escoParameters.receiveBandwidth = ReceiveBandwidth;
		escoParameters.maxLatency = MaxLatency;
		escoParameters.msMaxLatency = MsMaxLatency;
		escoParameters.slotMaxLatency = SlotMaxLatency;
		escoParameters.voiceSetting = VoiceSetting;
		escoParameters.noRestrans = NoRestrans;
		escoParameters.optimizePower = OptimizePower;
		escoParameters.optimizeQuality = OptimizeQuality;
		escoParameters.dontCare = DontCare;
		escoParameters.escoHV1enable = ESCOHV1enable;
		escoParameters.escoHV2enable = ESCOHV2enable;
		escoParameters.escoHV3enable = ESCOHV3enable;
		escoParameters.escoEV3enable = ESCOEV3enable;
		escoParameters.escoEV4enable = ESCOEV4enable;
		escoParameters.escoEV5enable = ESCOEV5enable;
		escoParameters.esco2EV3enable = ESCO2EV3enable;
		escoParameters.esco3EV3enable = ESCO3EV3enable;
		escoParameters.esco2EV5enable = ESCO2EV5enable;
		escoParameters.esco3EV5enable = ESCO3EV5enable;
		escoParameters.airCodingCVSDEnable = AirCodingCVSDEnable;
		escoParameters.airCodingULawEnable = AirCodingULawEnable;
		escoParameters.airCodingALawEnable = AirCodingALawEnable;
		escoParameters.airCodingTransparentDataEnable = AirCodingTransparentDataEnable;
		escoParameters.linearPCMBitPosition = LinearPCMBitPosition;
		escoParameters.sampleSize8BitEnable = SampleSize8BitEnable;
		escoParameters.sampleSize16BitEnable = SampleSize16BitEnable;
		escoParameters.inputData1ComplEnable = InputData1ComplEnable;
		escoParameters.inputData2ComplEnable = InputData2ComplEnable;
		escoParameters.inputDataSignMagnitudeEnable = InputDataSignMagnitudeEnable;
		escoParameters.inputDataUnsignedEnable = InputDataUnsignedEnable;
		escoParameters.inputCodingLinearEnable = InputCodingLinearEnable;
		escoParameters.inputCodingALawEnable = InputCodingALawEnable;
		escoParameters.inputCodingULawEnable = InputCodingULawEnable;
		escoParameters.inputCodingCVSDEnable = InputCodingCVSDEnable;
		escoParameters.audioSourceCodecEnable = AudioSourceCodecEnable;
		escoParameters.audioSourceHCIEnable = AudioSourceHCIEnable;
		escoParameters.transmitBandwidth_enhSync = TransmitBandwidth_enhSync;
		escoParameters.receiveBandwidth_enhSync = ReceiveBandwidth_enhSync;
		escoParameters.maxLatency_enhSync = MaxLatency_enhSync;
		escoParameters.msMaxLatency_enhSync = MsMaxLatency_enhSync;
		escoParameters.slotMaxLatency_enhSync = SlotMaxLatency_enhSync;
		escoParameters.noRestrans_enhSync = NoRestrans_enhSync;
		escoParameters.optimizePower_enhSync = OptimizePower_enhSync;
		escoParameters.optimizeQuality_enhSync = OptimizeQuality_enhSync;
		escoParameters.dontCare_enhSync = DontCare_enhSync;
		escoParameters.escoHV1enable_enhSync = ESCOHV1enable_enhSync;
		escoParameters.escoHV2enable_enhSync = ESCOHV2enable_enhSync;
		escoParameters.escoHV3enable_enhSync = ESCOHV3enable_enhSync;
		escoParameters.escoEV3enable_enhSync = ESCOEV3enable_enhSync;
		escoParameters.escoEV4enable_enhSync = ESCOEV4enable_enhSync;
		escoParameters.escoEV5enable_enhSync = ESCOEV5enable_enhSync;
		escoParameters.esco2EV3enable_enhSync = ESCO2EV3enable_enhSync;
		escoParameters.esco3EV3enable_enhSync = ESCO3EV3enable_enhSync;
		escoParameters.esco2EV5enable_enhSync = ESCO2EV5enable_enhSync;
		escoParameters.esco3EV5enable_enhSync = ESCO3EV5enable_enhSync;
		escoParameters.InputDataPath = InputDataPath;
		escoParameters.OutputDataPath = OutputDataPath;
		escoParameters.TxRxCodingFormat = TxRxCodingFormat;
		escoParameters.PcmSamplePayload = PcmSamplePayload;
		escoParameters.IOCodedDataSize = IOCodedDataSize;
		escoParameters.IOPcmDataFormat = IOPcmDataFormat;
		escoParameters.IOCodingFormat = IOCodingFormat;
		escoParameters.EnhancedSync = useEnhancedParameters;
		escoParameters.ShowDialog();
		if (escoParameters.DialogResult == DialogResult.OK)
		{
			TransmitBandwidth = escoParameters.transmitBandwidth;
			ReceiveBandwidth = escoParameters.receiveBandwidth;
			MaxLatency = escoParameters.maxLatency;
			MsMaxLatency = escoParameters.msMaxLatency;
			SlotMaxLatency = escoParameters.slotMaxLatency;
			VoiceSetting = escoParameters.voiceSetting;
			NoRestrans = escoParameters.noRestrans;
			OptimizePower = escoParameters.optimizePower;
			OptimizeQuality = escoParameters.optimizeQuality;
			DontCare = escoParameters.dontCare;
			ESCOHV1enable = escoParameters.escoHV1enable;
			ESCOHV2enable = escoParameters.escoHV2enable;
			ESCOHV3enable = escoParameters.escoHV3enable;
			ESCOEV3enable = escoParameters.escoEV3enable;
			ESCOEV4enable = escoParameters.escoEV4enable;
			ESCOEV5enable = escoParameters.escoEV5enable;
			ESCO2EV3enable = escoParameters.esco2EV3enable;
			ESCO3EV3enable = escoParameters.esco3EV3enable;
			ESCO2EV5enable = escoParameters.esco2EV5enable;
			ESCO3EV5enable = escoParameters.esco3EV5enable;
			AirCodingCVSDEnable = escoParameters.airCodingCVSDEnable;
			AirCodingULawEnable = escoParameters.airCodingULawEnable;
			AirCodingALawEnable = escoParameters.airCodingALawEnable;
			AirCodingTransparentDataEnable = escoParameters.airCodingTransparentDataEnable;
			LinearPCMBitPosition = escoParameters.linearPCMBitPosition;
			SampleSize8BitEnable = escoParameters.sampleSize8BitEnable;
			SampleSize16BitEnable = escoParameters.sampleSize16BitEnable;
			InputData1ComplEnable = escoParameters.inputData1ComplEnable;
			InputData2ComplEnable = escoParameters.inputData2ComplEnable;
			InputDataSignMagnitudeEnable = escoParameters.inputDataSignMagnitudeEnable;
			InputDataUnsignedEnable = escoParameters.inputDataUnsignedEnable;
			InputCodingLinearEnable = escoParameters.inputCodingLinearEnable;
			InputCodingALawEnable = escoParameters.inputCodingALawEnable;
			InputCodingULawEnable = escoParameters.inputCodingULawEnable;
			InputCodingCVSDEnable = escoParameters.inputCodingCVSDEnable;
			AudioSourceCodecEnable = escoParameters.audioSourceCodecEnable;
			AudioSourceHCIEnable = escoParameters.audioSourceHCIEnable;
			TransmitBandwidth_enhSync = escoParameters.transmitBandwidth_enhSync;
			ReceiveBandwidth_enhSync = escoParameters.receiveBandwidth_enhSync;
			MaxLatency_enhSync = escoParameters.maxLatency_enhSync;
			MsMaxLatency_enhSync = escoParameters.msMaxLatency_enhSync;
			SlotMaxLatency_enhSync = escoParameters.slotMaxLatency_enhSync;
			NoRestrans_enhSync = escoParameters.noRestrans_enhSync;
			OptimizePower_enhSync = escoParameters.optimizePower_enhSync;
			OptimizeQuality_enhSync = escoParameters.optimizeQuality_enhSync;
			DontCare_enhSync = escoParameters.dontCare_enhSync;
			ESCOHV1enable_enhSync = escoParameters.escoHV1enable_enhSync;
			ESCOHV2enable_enhSync = escoParameters.escoHV2enable_enhSync;
			ESCOHV3enable_enhSync = escoParameters.escoHV3enable_enhSync;
			ESCOEV3enable_enhSync = escoParameters.escoEV3enable_enhSync;
			ESCOEV4enable_enhSync = escoParameters.escoEV4enable_enhSync;
			ESCOEV5enable_enhSync = escoParameters.escoEV5enable_enhSync;
			ESCO2EV3enable_enhSync = escoParameters.esco2EV3enable_enhSync;
			ESCO3EV3enable_enhSync = escoParameters.esco3EV3enable_enhSync;
			ESCO2EV5enable_enhSync = escoParameters.esco2EV5enable_enhSync;
			ESCO3EV5enable_enhSync = escoParameters.esco3EV5enable_enhSync;
			InputDataPath = escoParameters.InputDataPath;
			OutputDataPath = escoParameters.OutputDataPath;
			TxRxCodingFormat = escoParameters.TxRxCodingFormat;
			PcmSamplePayload = escoParameters.PcmSamplePayload;
			IOCodedDataSize = escoParameters.IOCodedDataSize;
			IOPcmDataFormat = escoParameters.IOPcmDataFormat;
			IOCodingFormat = escoParameters.IOCodingFormat;
			useEnhancedParameters = escoParameters.EnhancedSync;
			int result = 0;
			int.TryParse(connectionHandlerString, NumberStyles.HexNumber, null, out result);
			int result2 = 0;
			int.TryParse(VoiceSetting, NumberStyles.HexNumber, null, out result2);
			int packetType = CalculatePacketTypeForESCOConnection();
			int retransmissionEffort = CalculateRetransmissionEffortForESCOConnection();
			if (useEnhancedParameters)
			{
				AddEnhancedSynchronousConnectionHandler(result, retransmissionEffort, packetType);
			}
			else
			{
				AddESCOConnectionHandler(result, result2, retransmissionEffort, packetType);
			}
			currentBTPacketType = (uint)packetType;
		}
	}

	private void ChangeConnectionPacketTypeHandler(int connectionHandle, bool isSCO, string address = null)
	{
		ChangeConnectionPacketType changeConnectionPacketType = new ChangeConnectionPacketType();
		changeConnectionPacketType.UserFields.ConnectionHandle = (uint)connectionHandle;
		connectionPacketType = new ConnectionPacketType();
		if (isSCO)
		{
			object obj = BTLERemoteDeviceInfoList.CheckAndGetBTRemoteDeviceScoPacketTypeByConnectionHandle(connectionHandle);
			SynchronousPacketTypeEnumCollection synchronousPacketTypeEnumCollection;
			if (obj != null && obj is SynchronousPacketTypeEnumCollection)
			{
				synchronousPacketTypeEnumCollection = (SynchronousPacketTypeEnumCollection)obj;
				connectionPacketType.isSCO = true;
				connectionPacketType.hv1enable = synchronousPacketTypeEnumCollection.Hv1 == AssertBitEnum.Set;
				connectionPacketType.hv2enable = synchronousPacketTypeEnumCollection.Hv2 == AssertBitEnum.Set;
				connectionPacketType.hv3enable = synchronousPacketTypeEnumCollection.Hv3 == AssertBitEnum.Set;
			}
			else if (obj != null && obj is EnhancedSynchronousPacketTypeEnumCollection)
			{
				EnhancedSynchronousPacketTypeEnumCollection enhancedSynchronousPacketTypeEnumCollection = (EnhancedSynchronousPacketTypeEnumCollection)obj;
				connectionPacketType.isSCO = true;
				connectionPacketType.hv1enable = enhancedSynchronousPacketTypeEnumCollection.Hv1MayBeUsed == AssertBitEnum.Set;
				connectionPacketType.hv2enable = enhancedSynchronousPacketTypeEnumCollection.Hv2MayBeUsed == AssertBitEnum.Set;
				connectionPacketType.hv3enable = enhancedSynchronousPacketTypeEnumCollection.Hv3MayBeUsed == AssertBitEnum.Set;
			}
			else
			{
				connectionPacketType.isSCO = true;
				connectionPacketType.hv1enable = true;
				connectionPacketType.hv2enable = true;
				connectionPacketType.hv3enable = true;
			}
			connectionPacketType.ShowDialog();
			if (connectionPacketType.DialogResult != DialogResult.OK)
			{
				return;
			}
			synchronousPacketTypeEnumCollection = new SynchronousPacketTypeEnumCollection();
			synchronousPacketTypeEnumCollection.Hv1 = (connectionPacketType.hv1enable ? AssertBitEnum.Set : AssertBitEnum.Not_Set);
			synchronousPacketTypeEnumCollection.Hv2 = (connectionPacketType.hv2enable ? AssertBitEnum.Set : AssertBitEnum.Not_Set);
			synchronousPacketTypeEnumCollection.Hv3 = (connectionPacketType.hv3enable ? AssertBitEnum.Set : AssertBitEnum.Not_Set);
			changeConnectionPacketType.UserFields.SetPacketTypeAsSynchronousPacketTypeEnumCollection(synchronousPacketTypeEnumCollection);
		}
		else
		{
			uint packetType = 0u;
			uint pageScanRepMode = 0u;
			uint clockOffSet = 0u;
			bool allowRoleSwitch = false;
			if (BTLERemoteDeviceInfoList.CheckAndGetBTRemoteDeviceInfoByBDAddress(address, out var btRemoteDevice))
			{
				connectionPacketType.dm1enable = btRemoteDevice.dm1enable;
				connectionPacketType.dh1enable = btRemoteDevice.dh1enable;
				connectionPacketType.dm3enable = btRemoteDevice.dm3enable;
				connectionPacketType.dh3enable = btRemoteDevice.dh3enable;
				connectionPacketType.dm5enable = btRemoteDevice.dm5enable;
				connectionPacketType.dh5enable = btRemoteDevice.dh5enable;
				connectionPacketType.twoDH1enable = btRemoteDevice.twoDH1enable;
				connectionPacketType.threeDH1enable = btRemoteDevice.threeDH1enable;
				connectionPacketType.twoDH3enable = btRemoteDevice.twoDH3enable;
				connectionPacketType.threeDH3enable = btRemoteDevice.threeDH3enable;
				connectionPacketType.twoDH5enable = btRemoteDevice.twoDH5enable;
				connectionPacketType.threeDH5enable = btRemoteDevice.threeDH5enable;
				connectionPacketType.ShowDialog();
				if (connectionPacketType.DialogResult != DialogResult.OK)
				{
					return;
				}
				btRemoteDevice.dm1enable = connectionPacketType.dm1enable;
				btRemoteDevice.dh1enable = connectionPacketType.dh1enable;
				btRemoteDevice.dm3enable = connectionPacketType.dm3enable;
				btRemoteDevice.dh3enable = connectionPacketType.dh3enable;
				btRemoteDevice.dm5enable = connectionPacketType.dm5enable;
				btRemoteDevice.dh5enable = connectionPacketType.dh5enable;
				btRemoteDevice.twoDH1enable = connectionPacketType.twoDH1enable;
				btRemoteDevice.threeDH1enable = connectionPacketType.threeDH1enable;
				btRemoteDevice.twoDH3enable = connectionPacketType.twoDH3enable;
				btRemoteDevice.threeDH3enable = connectionPacketType.threeDH3enable;
				btRemoteDevice.twoDH5enable = connectionPacketType.twoDH5enable;
				btRemoteDevice.threeDH5enable = connectionPacketType.threeDH5enable;
				BTLERemoteDeviceInfoList.UpdateBTRemoteDeviceList(btRemoteDevice);
				if (BTLERemoteDeviceInfoList.CheckAndGetBTRemoteDeviceInfoByBDAddress(address, out packetType, out pageScanRepMode, out clockOffSet, out allowRoleSwitch))
				{
					changeConnectionPacketType.UserFields.PacketType = packetType;
				}
			}
		}
		currentBTPacketType = changeConnectionPacketType.UserFields.PacketType;
		try
		{
			btAPI.Send(changeConnectionPacketType);
		}
		catch (Exception ex)
		{
			logger.Enqueue(new QCRPG.Framework.LogMessage(LogMessageType.Error, ex));
		}
	}

	private void RequestAuthenticationHandler(int connectionHandle)
	{
		AuthenticationRequested authenticationRequested = new AuthenticationRequested();
		authenticationRequested.UserFields.ConnectionHandle = (uint)connectionHandle;
		try
		{
			btAPI.Send(authenticationRequested);
		}
		catch (Exception ex)
		{
			logger.Enqueue(new QCRPG.Framework.LogMessage(LogMessageType.Error, ex));
		}
	}

	private void EncryptionHandler(int connectionHandle, bool enable)
	{
		SetConnectionEncryption.UserFieldsWrapper.EncryptionEnableEnum encryptionEnableAsEncryptionEnableEnum = (enable ? SetConnectionEncryption.UserFieldsWrapper.EncryptionEnableEnum.TURN_LINK_LEVEL_ENCRYPTION_ON : SetConnectionEncryption.UserFieldsWrapper.EncryptionEnableEnum.TURN_LINK_LEVEL_ENCRYPTION_OFF);
		SetConnectionEncryption setConnectionEncryption = new SetConnectionEncryption();
		setConnectionEncryption.UserFields.ConnectionHandle = (uint)connectionHandle;
		setConnectionEncryption.UserFields.SetEncryptionEnableAsEncryptionEnableEnum(encryptionEnableAsEncryptionEnableEnum);
		try
		{
			btAPI.Send(setConnectionEncryption);
		}
		catch (Exception ex)
		{
			logger.Enqueue(new QCRPG.Framework.LogMessage(LogMessageType.Error, ex));
		}
	}

	private void SniffModeHandler(int connectionHandler)
	{
		HciSniffMode hciSniffMode = new HciSniffMode();
		hciSniffMode.UserFields.ConnectionHandle = (uint)connectionHandler;
		hciSniffMode.UserFields.SniffMaxInterval = (uint)SniffMaxInterval;
		hciSniffMode.UserFields.SniffMinInterval = (uint)SniffMinInterval;
		hciSniffMode.UserFields.SniffAttempt = (uint)SniffAttempt;
		hciSniffMode.UserFields.SniffTimeout = (uint)SniffTimeout;
		try
		{
			btAPI.Send(hciSniffMode);
		}
		catch (Exception ex)
		{
			logger.Enqueue(new QCRPG.Framework.LogMessage(LogMessageType.Error, ex));
		}
	}

	private void SwitchRoleHandler(string bdAddress, int role)
	{
		SwitchRole switchRole = new SwitchRole();
		switchRole.UserFields.BdAddr = Convert.ToUInt64(bdAddress, 16);
		switchRole.UserFields.Role = (uint)role;
		try
		{
			btAPI.Send(switchRole);
		}
		catch (Exception ex)
		{
			logger.Enqueue(new QCRPG.Framework.LogMessage(LogMessageType.Error, ex));
		}
	}

	private void MasterLinKKeyHandler(bool semi)
	{
		MasterLinkKey masterLinkKey = new MasterLinkKey();
		masterLinkKey.UserFields.KeyFlag = ((!semi) ? 1u : 0u);
		try
		{
			btAPI.Send(masterLinkKey);
		}
		catch (Exception ex)
		{
			logger.Enqueue(new QCRPG.Framework.LogMessage(LogMessageType.Error, ex));
		}
	}

	private void BTReadRemoteNameHandler(string bdAddress, uint pageScanRepMode, uint clockOffSet)
	{
		RemoteNameRequest remoteNameRequest = new RemoteNameRequest();
		remoteNameRequest.UserFields.BdAddress = Convert.ToUInt64(bdAddress, 16);
		remoteNameRequest.UserFields.PageScanRepetitionMode = pageScanRepMode;
		remoteNameRequest.UserFields.ClockOffset = clockOffSet;
		try
		{
			btAPI.Send(remoteNameRequest);
		}
		catch (Exception ex)
		{
			logger.Enqueue(new QCRPG.Framework.LogMessage(LogMessageType.Error, ex));
		}
	}

	private void ReadRemoteVersionHandler(int connectionHandle)
	{
		ReadRemoteVersionInformation readRemoteVersionInformation = new ReadRemoteVersionInformation();
		readRemoteVersionInformation.UserFields.ConnectionHandle = (uint)connectionHandle;
		try
		{
			btAPI.Send(readRemoteVersionInformation);
		}
		catch (Exception ex)
		{
			logger.Enqueue(new QCRPG.Framework.LogMessage(LogMessageType.Error, "Fail to read Remote Version Information. " + ex));
		}
	}

	private void ReadRemoteSupportedFeaturesHandler(int connectionHandle)
	{
		ReadRemoteSupportedFeatures readRemoteSupportedFeatures = new ReadRemoteSupportedFeatures();
		readRemoteSupportedFeatures.UserFields.ConnectionHandle = (uint)connectionHandle;
		try
		{
			btAPI.Send(readRemoteSupportedFeatures);
		}
		catch (Exception ex)
		{
			logger.Enqueue(new QCRPG.Framework.LogMessage(LogMessageType.Error, "Fail to read Remote Supported Features. " + ex));
		}
	}

	private void ReadRemoteExtendedFeaturesHandler(int connectionHandle, uint pageNumber)
	{
		ReadRemoteExtendedFeatures readRemoteExtendedFeatures = new ReadRemoteExtendedFeatures();
		readRemoteExtendedFeatures.UserFields.ConnectionHandle = (uint)connectionHandle;
		readRemoteExtendedFeatures.UserFields.PageNumber = pageNumber;
		try
		{
			btAPI.Send(readRemoteExtendedFeatures);
		}
		catch (Exception ex)
		{
			logger.Enqueue(new QCRPG.Framework.LogMessage(LogMessageType.Error, "Fail to read Remote Supported Features. " + ex));
		}
	}

	private void ReadAFHChannelMapHandler(int connectionHandle)
	{
		ReadAfhChannelMap readAfhChannelMap = new ReadAfhChannelMap();
		readAfhChannelMap.UserFields.ConnectionHandle = (uint)connectionHandle;
		try
		{
			btAPI.Send(readAfhChannelMap);
		}
		catch (Exception ex)
		{
			logger.Enqueue(new QCRPG.Framework.LogMessage(LogMessageType.Error, "Fail to read AFH Channel Map. " + ex));
		}
	}

	private void ExitSniffModeHandler(int connectionHandler)
	{
		HciExitSniffMode hciExitSniffMode = new HciExitSniffMode();
		hciExitSniffMode.UserFields.ConnectionHandle = (uint)connectionHandler;
		try
		{
			btAPI.Send(hciExitSniffMode);
		}
		catch (Exception ex)
		{
			logger.Enqueue(new QCRPG.Framework.LogMessage(LogMessageType.Error, ex));
		}
	}

	private void HoldModeHandler(int connectionHandler)
	{
		HoldMode holdMode = new HoldMode();
		holdMode.UserFields.ConnectionHandle = (uint)connectionHandler;
		holdMode.UserFields.HoldModeMaxInterval = (uint)HoldMaxInterval;
		holdMode.UserFields.HoldModeMinInterval = (uint)HoldMinInterval;
		try
		{
			btAPI.Send(holdMode);
		}
		catch (Exception ex)
		{
			logger.Enqueue(new QCRPG.Framework.LogMessage(LogMessageType.Error, ex));
		}
	}

	private void EditSelectedDeviceHandler(BTLERemoteDeviceInfo.BTRemoteDeviceInfo btRemoteDeviceInfo)
	{
		remoteDeviceOptions = new RemoteDeviceOptions();
		remoteDeviceOptions.deviceAddress = btRemoteDeviceInfo.bdAddress;
		remoteDeviceOptions.pageScanRepetitionMode = btRemoteDeviceInfo.pageScanRepMode;
		remoteDeviceOptions.classOfDevice = btRemoteDeviceInfo.classOfDevice;
		remoteDeviceOptions.clockOffset = (ushort)btRemoteDeviceInfo.clockOffset;
		remoteDeviceOptions.dm1enable = btRemoteDeviceInfo.dm1enable;
		remoteDeviceOptions.dm3enable = btRemoteDeviceInfo.dm3enable;
		remoteDeviceOptions.dm5enable = btRemoteDeviceInfo.dm5enable;
		remoteDeviceOptions.dh1enable = btRemoteDeviceInfo.dh1enable;
		remoteDeviceOptions.dh3enable = btRemoteDeviceInfo.dh3enable;
		remoteDeviceOptions.dh5enable = btRemoteDeviceInfo.dh5enable;
		remoteDeviceOptions.allowRoleSwitch = btRemoteDeviceInfo.allowRoleSwitch;
		remoteDeviceOptions.lmPerformMSswitch = btRemoteDeviceInfo.lmPerformMSswitch;
		remoteDeviceOptions.hv1enable = btRemoteDeviceInfo.hv1enable;
		remoteDeviceOptions.hv2enable = btRemoteDeviceInfo.hv2enable;
		remoteDeviceOptions.hv3enable = btRemoteDeviceInfo.hv3enable;
		remoteDeviceOptions.clockOffsetValid = btRemoteDeviceInfo.clockOffsetValid;
		remoteDeviceOptions.levelChoice = ((!btRemoteDeviceInfo.levelDefaultEnable) ? (btRemoteDeviceInfo.levelAuthenticationEnable ? 1 : (btRemoteDeviceInfo.levelPairingEnable ? 2 : 0)) : 0);
		remoteDeviceOptions.linkKeyChoice = ((!btRemoteDeviceInfo.linkKeyASCIIEnable) ? (btRemoteDeviceInfo.linkKeyHexEnable ? 1 : 1) : 0);
		remoteDeviceOptions.linkKey = btRemoteDeviceInfo.linkKey;
		remoteDeviceOptions.pinCodeChoice = ((!btRemoteDeviceInfo.pinCodeASCIIEnable) ? (btRemoteDeviceInfo.pinCodeHexEnable ? 1 : 1) : 0);
		remoteDeviceOptions.pinCode = btRemoteDeviceInfo.pinCode;
		remoteDeviceOptions.ioCapability = btRemoteDeviceInfo.ioCapability;
		remoteDeviceOptions.outOfBandDataPresent = btRemoteDeviceInfo.outOfBandDataPresent;
		remoteDeviceOptions.confirmationRequestReply = btRemoteDeviceInfo.confirmationRequestReply;
		remoteDeviceOptions.passkeyRequestReply = btRemoteDeviceInfo.passkeyRequestReply;
		remoteDeviceOptions.authenticationRequirements = btRemoteDeviceInfo.authenticationRequirements;
		remoteDeviceOptions.oobc = btRemoteDeviceInfo.oobc;
		remoteDeviceOptions.oobr = btRemoteDeviceInfo.oobr;
		remoteDeviceOptions.ShowDialog();
		if (remoteDeviceOptions.DialogResult == DialogResult.OK)
		{
			btRemoteDeviceInfo.bdAddress = remoteDeviceOptions.deviceAddress;
			btRemoteDeviceInfo.pageScanRepMode = remoteDeviceOptions.pageScanRepetitionMode;
			btRemoteDeviceInfo.dm1enable = remoteDeviceOptions.dm1enable;
			btRemoteDeviceInfo.dm3enable = remoteDeviceOptions.dm3enable;
			btRemoteDeviceInfo.dm5enable = remoteDeviceOptions.dm5enable;
			btRemoteDeviceInfo.dh1enable = remoteDeviceOptions.dh1enable;
			btRemoteDeviceInfo.dh3enable = remoteDeviceOptions.dh3enable;
			btRemoteDeviceInfo.dh5enable = remoteDeviceOptions.dh5enable;
			btRemoteDeviceInfo.allowRoleSwitch = remoteDeviceOptions.allowRoleSwitch;
			btRemoteDeviceInfo.lmPerformMSswitch = remoteDeviceOptions.lmPerformMSswitch;
			btRemoteDeviceInfo.hv1enable = remoteDeviceOptions.hv1enable;
			btRemoteDeviceInfo.hv2enable = remoteDeviceOptions.hv2enable;
			btRemoteDeviceInfo.hv3enable = remoteDeviceOptions.hv3enable;
			btRemoteDeviceInfo.clockOffsetValid = remoteDeviceOptions.clockOffsetValid;
			btRemoteDeviceInfo.levelDefaultEnable = remoteDeviceOptions.levelChoice == 0;
			btRemoteDeviceInfo.levelAuthenticationEnable = remoteDeviceOptions.levelChoice == 1;
			btRemoteDeviceInfo.levelPairingEnable = remoteDeviceOptions.levelChoice == 2;
			btRemoteDeviceInfo.linkKeyASCIIEnable = remoteDeviceOptions.linkKeyChoice == 0;
			btRemoteDeviceInfo.linkKeyHexEnable = remoteDeviceOptions.linkKeyChoice == 1;
			btRemoteDeviceInfo.linkKey = remoteDeviceOptions.linkKey;
			btRemoteDeviceInfo.pinCodeASCIIEnable = remoteDeviceOptions.pinCodeChoice == 0;
			btRemoteDeviceInfo.pinCodeHexEnable = remoteDeviceOptions.pinCodeChoice == 1;
			btRemoteDeviceInfo.pinCode = remoteDeviceOptions.pinCode;
			btRemoteDeviceInfo.ioCapability = remoteDeviceOptions.ioCapability;
			btRemoteDeviceInfo.outOfBandDataPresent = remoteDeviceOptions.outOfBandDataPresent;
			btRemoteDeviceInfo.confirmationRequestReply = remoteDeviceOptions.confirmationRequestReply;
			btRemoteDeviceInfo.passkeyRequestReply = remoteDeviceOptions.passkeyRequestReply;
			btRemoteDeviceInfo.authenticationRequirements = remoteDeviceOptions.authenticationRequirements;
			btRemoteDeviceInfo.oobc = remoteDeviceOptions.oobc;
			btRemoteDeviceInfo.oobr = remoteDeviceOptions.oobr;
			BTLERemoteDeviceInfoList.UpdateBTRemoteDeviceList(btRemoteDeviceInfo);
		}
	}

	private void LEConnectionHandler(string bdAddress, uint addressType)
	{
		if (addressType == 2)
		{
			string text = $"Address Type {addressType} is not supported";
			logger.Enqueue(new QCRPG.Framework.LogMessage(LogMessageType.Error, text));
			return;
		}
		LeCreateConnection leCreateConnection = new LeCreateConnection();
		leCreateConnection.UserFields.LeScanInterval = (uint)((double)ConnectionScanTimingScanInterval / 0.625);
		leCreateConnection.UserFields.LeScanWindow = (uint)((double)ConnectionScanTimingScanWindow / 0.625);
		leCreateConnection.UserFields.InitiatorFilterPolicy = (InitiatorWhiteListEnabe ? 1u : 0u);
		leCreateConnection.UserFields.PeerAddressType = addressType;
		leCreateConnection.UserFields.PeerAddress = Convert.ToUInt64(bdAddress, 16);
		leCreateConnection.UserFields.OwnAddressType = (uint)CreateConnectionOwnAddressType;
		leCreateConnection.UserFields.ConnIntervalMin = (uint)((double)ConnectionTimingMinInterval / 1.25);
		leCreateConnection.UserFields.ConnIntervalMax = (uint)((double)ConnectionTimingMaxInterval / 1.25);
		leCreateConnection.UserFields.ConnLatency = (uint)ConnectionTimingLatency;
		leCreateConnection.UserFields.SupervisionTimeout = (uint)ConnectionTimingTimeout / 10u;
		leCreateConnection.UserFields.MinimumCeLength = (uint)((double)ConnectionEventTimingMinLength / 0.625);
		leCreateConnection.UserFields.MaximumCeLength = (uint)((double)ConnectionEventTimingMaxLength / 0.625);
		try
		{
			btAPI.Send(leCreateConnection);
		}
		catch (Exception ex)
		{
			logger.Enqueue(new QCRPG.Framework.LogMessage(LogMessageType.Error, ex));
		}
	}

	private void UpdateBTConnectionHandler(string bdaddress)
	{
		int bTRemoteDeviceConnectionHandlerByBDAddress = BTLERemoteDeviceInfoList.GetBTRemoteDeviceConnectionHandlerByBDAddress(bdaddress);
		if (toolStripStatusLabelEmpty != null)
		{
			toolStripStatusLabelEmpty.Text = "Connection Handle: " + bTRemoteDeviceConnectionHandlerByBDAddress.ToString("X4");
		}
		currentBTConnectionHandler = bTRemoteDeviceConnectionHandlerByBDAddress;
		toolStripButtonFileTransfer.Enabled = true;
		toolStripButtonDataTransfer.Enabled = true;
		btDataTransferUserControl.SelectDataTransferControl(currentBTConnectionHandler, isBtConnection: true);
		scoOverHciUserControl.AclConnectionHandle = currentBTConnectionHandler;
		btScripter.SetOverrideParamVariable("connectionHandle", "0x" + currentBTConnectionHandler.ToString("X4"));
	}

	private void UpdateBTSCOConnectionHandler(string connectionHandlerString)
	{
		if (toolStripStatusLabelEmpty != null)
		{
			toolStripStatusLabelEmpty.Text = "Connection Handle: " + connectionHandlerString;
			int.TryParse(connectionHandlerString, out currentBTConnectionHandler);
			scoOverHciUserControl.AclConnectionHandle = currentBTConnectionHandler;
		}
	}

	private void UpdateLEConnectionHandler(string bdaddress)
	{
		int lERemoteDeviceConnectionHandlerByBDAddress = BTLERemoteDeviceInfoList.GetLERemoteDeviceConnectionHandlerByBDAddress(bdaddress);
		if (toolStripStatusLabelEmpty != null)
		{
			toolStripStatusLabelEmpty.Text = "Connection Handle: " + lERemoteDeviceConnectionHandlerByBDAddress.ToString("X4");
		}
		int lERemoteDeviceCisHandleByBDAddress = BTLERemoteDeviceInfoList.GetLERemoteDeviceCisHandleByBDAddress(bdaddress);
		if (toolStripStatusLabelCisHandle != null && lERemoteDeviceCisHandleByBDAddress != 0)
		{
			toolStripStatusLabelCisHandle.Text = "CIS Handle: " + lERemoteDeviceCisHandleByBDAddress.ToString("X4");
			if (dutSetCig)
			{
				leRemoveCigMenuItem.Enabled = true;
			}
		}
		currentBTConnectionHandler = lERemoteDeviceConnectionHandlerByBDAddress;
		currentCisHandle = lERemoteDeviceCisHandleByBDAddress;
		toolStripButtonFileTransfer.Enabled = false;
		toolStripButtonDataTransfer.Enabled = true;
		btDataTransferUserControl.SelectDataTransferControl(currentBTConnectionHandler, isBtConnection: false);
		btScripter.SetOverrideParamVariable("connectionHandle", "0x" + currentBTConnectionHandler.ToString("X4"));
	}

	private void EnableDefaultNvmHandler(object sender, EventArgs e)
	{
		if (((ToolStripMenuItem)setDefaultNVM).Checked)
		{
			((ToolStripMenuItem)setDefaultNVM).Checked = false;
		}
		else
		{
			((ToolStripMenuItem)setDefaultNVM).Checked = true;
		}
		btConfigSettings.EnableDefaultBTNVM = ((ToolStripMenuItem)setDefaultNVM).Checked;
	}

	private void DisplayEnhLog(object sender, EventArgs e)
	{
		if (((ToolStripMenuItem)displayEnhLog).Checked)
		{
			((ToolStripMenuItem)displayEnhLog).Checked = false;
			btAPI.EnableDisplayEnhancedLog(enable: false);
		}
		else
		{
			((ToolStripMenuItem)displayEnhLog).Checked = true;
			btAPI.EnableDisplayEnhancedLog(enable: true);
		}
	}

	private void DisplayFullAclData(object sender, EventArgs e)
	{
		if (!((ToolStripMenuItem)displayFullAclData).Checked)
		{
			((ToolStripMenuItem)displayFullAclData).Checked = true;
			((ToolStripMenuItem)displaySummaryAclData).Checked = false;
			((ToolStripMenuItem)hideAclData).Checked = false;
			btAPI.SetAclDataDisplay(ProtocolHCI.AclLogMode.FULL);
		}
	}

	private void DisplaySummaryAclData(object sender, EventArgs e)
	{
		if (!((ToolStripMenuItem)displaySummaryAclData).Checked)
		{
			((ToolStripMenuItem)displayFullAclData).Checked = false;
			((ToolStripMenuItem)displaySummaryAclData).Checked = true;
			((ToolStripMenuItem)hideAclData).Checked = false;
			btAPI.SetAclDataDisplay(ProtocolHCI.AclLogMode.SUMMARY);
		}
	}

	private void HideAclData(object sender, EventArgs e)
	{
		if (!((ToolStripMenuItem)hideAclData).Checked)
		{
			((ToolStripMenuItem)displayFullAclData).Checked = false;
			((ToolStripMenuItem)displaySummaryAclData).Checked = false;
			((ToolStripMenuItem)hideAclData).Checked = true;
			btAPI.SetAclDataDisplay(ProtocolHCI.AclLogMode.NONE);
		}
	}

	private void FullAclDataToLogFile(object sender, EventArgs e)
	{
		if (!((ToolStripMenuItem)fullAclDataToLog).Checked)
		{
			((ToolStripMenuItem)fullAclDataToLog).Checked = true;
			btAPI.SetFullAclDataToLogFile(fullAclLogging: true);
		}
		else
		{
			((ToolStripMenuItem)fullAclDataToLog).Checked = false;
			btAPI.SetFullAclDataToLogFile(fullAclLogging: false);
		}
	}

	private void EnableDefaultPatchHandler(object sender, EventArgs e)
	{
		if (((ToolStripMenuItem)setDefaultPatch).Checked)
		{
			((ToolStripMenuItem)setDefaultPatch).Checked = false;
		}
		else
		{
			((ToolStripMenuItem)setDefaultPatch).Checked = true;
		}
		btConfigSettings.EnableDefaultBTPatch = ((ToolStripMenuItem)setDefaultPatch).Checked;
	}

	private void EnableStartupCommandHandler(object sender, EventArgs e)
	{
		if (((ToolStripMenuItem)setStartupCommand).Checked)
		{
			((ToolStripMenuItem)setStartupCommand).Checked = false;
		}
		else
		{
			((ToolStripMenuItem)setStartupCommand).Checked = true;
			((ToolStripMenuItem)setDefaultScript).Checked = false;
		}
		btConfigSettings.EnableStartupCommand = ((ToolStripMenuItem)setStartupCommand).Checked;
		btConfigSettings.EnableDefaultBTScript = ((ToolStripMenuItem)setDefaultScript).Checked;
	}

	private void EnableStartupCommandLEOnlyHandler(object sender, EventArgs e)
	{
		if (((ToolStripMenuItem)setStartupCommandLEOnly).Checked)
		{
			((ToolStripMenuItem)setStartupCommandLEOnly).Checked = false;
		}
		else
		{
			((ToolStripMenuItem)setStartupCommandLEOnly).Checked = true;
			((ToolStripMenuItem)setStartupCommand).Checked = false;
		}
		btConfigSettings.EnableStartupCommandLEOnly = ((ToolStripMenuItem)setStartupCommandLEOnly).Checked;
	}

	private void EnableDefaultScriptHandler(object sender, EventArgs e)
	{
		if (((ToolStripMenuItem)setDefaultScript).Checked)
		{
			((ToolStripMenuItem)setDefaultScript).Checked = false;
		}
		else
		{
			((ToolStripMenuItem)setDefaultScript).Checked = true;
			((ToolStripMenuItem)setStartupCommand).Checked = false;
		}
		btConfigSettings.EnableStartupCommand = ((ToolStripMenuItem)setStartupCommand).Checked;
		btConfigSettings.EnableDefaultBTScript = ((ToolStripMenuItem)setDefaultScript).Checked;
	}

	private void CheckStateChanged(object sender, EventArgs e)
	{
		btAPI.SetDecodePacket(((ToolStripMenuItem)setDecodePacket).Checked, packetResponse: false);
	}

	private void EnablePacketDecodeHandler(object sender, EventArgs e)
	{
		if (((ToolStripMenuItem)setDecodePacket).Checked)
		{
			((ToolStripMenuItem)setDecodePacket).Checked = false;
		}
		else
		{
			((ToolStripMenuItem)setDecodePacket).Checked = true;
		}
		btConfigSettings.EnablePacketDecode = ((ToolStripMenuItem)setDecodePacket).Checked;
	}

	private void ResetPacketCounterHandler(object sender, EventArgs e)
	{
		command = 0;
		notification = 0;
		TxAcl = 0;
		TxSco = 0;
		RxAcl = 0;
		RxSco = 0;
	}

	private void ScanModeHandler(object sender, EventArgs e)
	{
		ScanMode scanMode = new ScanMode();
		scanMode.scanEnable = scanEnable;
		scanMode.interlacedInquiryScan = enableInterlacedInquiryScan;
		scanMode.interlacedPageScan = enableInterlacedPageScan;
		scanMode.ShowDialog();
		if (scanMode.DialogResult != DialogResult.OK)
		{
			return;
		}
		WriteScanEnable writeScanEnable = new WriteScanEnable();
		writeScanEnable.UserFields.ScanEnable = (uint)scanMode.scanEnable;
		try
		{
			btAPI.Send(writeScanEnable);
			scanEnable = scanMode.scanEnable;
			if (scanMode.scanEnable == WriteScanEnable.UserFieldsWrapper.ScanEnableEnum.BOTH_SCANS_ENABLED)
			{
				toolStripButtonPageScan.Checked = true;
				toolStripButtonInquiryScan.Checked = true;
			}
			else if (scanMode.scanEnable == WriteScanEnable.UserFieldsWrapper.ScanEnableEnum.INQUIRY_SCAN_ENABLED)
			{
				toolStripButtonPageScan.Checked = false;
				toolStripButtonInquiryScan.Checked = true;
			}
			else if (scanMode.scanEnable == WriteScanEnable.UserFieldsWrapper.ScanEnableEnum.PAGE_SCAN_ENABLED)
			{
				toolStripButtonPageScan.Checked = true;
				toolStripButtonInquiryScan.Checked = false;
			}
			else if (scanMode.scanEnable == WriteScanEnable.UserFieldsWrapper.ScanEnableEnum.NO_SCANS_ENABLED)
			{
				toolStripButtonPageScan.Checked = false;
				toolStripButtonInquiryScan.Checked = false;
			}
			else
			{
				logger.Enqueue(new QCRPG.Framework.LogMessage(LogMessageType.Error, "Invalid scan mode"));
			}
		}
		catch (Exception ex)
		{
			logger.Enqueue(new QCRPG.Framework.LogMessage(LogMessageType.Error, "Fail to write scan enable. " + ex));
		}
	}

	private void DUTModeHandler(object sender, EventArgs e)
	{
		EnableDeviceUnderTestMode packet = new EnableDeviceUnderTestMode();
		try
		{
			btAPI.Send(packet);
		}
		catch (Exception ex)
		{
			logger.Enqueue(new QCRPG.Framework.LogMessage(LogMessageType.Error, "Fail to enable DUT Mode. " + ex));
		}
	}

	private void BTOptionsHandler(object sender, EventArgs e)
	{
		localHostDefaultOption = new LocalHostDefaultOption();
		localHostDefaultOption.dM1enable = DM1enable;
		localHostDefaultOption.dM3enable = DM3enable;
		localHostDefaultOption.dM5enable = DM5enable;
		localHostDefaultOption.dH1enable = DH1enable;
		localHostDefaultOption.dH3enable = DH3enable;
		localHostDefaultOption.dH5enable = DH5enable;
		localHostDefaultOption.twodH1enable = twoDH1enable;
		localHostDefaultOption.twodH3enable = twoDH3enable;
		localHostDefaultOption.twodH5enable = twoDH5enable;
		localHostDefaultOption.threedH1enable = threeDH1enable;
		localHostDefaultOption.threedH3enable = threeDH3enable;
		localHostDefaultOption.threedH5enable = threeDH5enable;
		localHostDefaultOption.scanEnableLocalHost = scanEnableLocalHost;
		localHostDefaultOption.hV1enable = HV1enable;
		localHostDefaultOption.hV2enable = HV2enable;
		localHostDefaultOption.hV3enable = HV3enable;
		localHostDefaultOption.allowRoleSwitch = allowRoleswitch;
		localHostDefaultOption.lmPerformMSswitch = lmPerformMSswitch;
		localHostDefaultOption.AutoAcceptConnectionReq = autoAcceptConnectionRequest;
		localHostDefaultOption.masterSlaveSwitch = MasterSlaveSwitchEnable;
		localHostDefaultOption.holdMode = HoldModeEnable;
		localHostDefaultOption.sniffMode = SniffModeEnable;
		localHostDefaultOption.parkMode = ParkModeEnable;
		localHostDefaultOption.maintainCurrentPower = MaintainCurrentPower;
		localHostDefaultOption.suspendPageScan = SuspendPageScanEnable;
		localHostDefaultOption.suspendInquiryScan = SuspendInquiryScanEnable;
		localHostDefaultOption.suspendPeriodicInquiries = SuspendPeriodicInquiriesEnable;
		localHostDefaultOption.transmitBandwidth = TransmitBandwidth;
		localHostDefaultOption.receiveBandwidth = ReceiveBandwidth;
		localHostDefaultOption.maxLatency = MaxLatency;
		localHostDefaultOption.msMaxLatency = MsMaxLatency;
		localHostDefaultOption.slotMaxLatency = SlotMaxLatency;
		localHostDefaultOption.voiceSetting = VoiceSetting;
		localHostDefaultOption.noRestrans = NoRestrans;
		localHostDefaultOption.optimizePower = OptimizePower;
		localHostDefaultOption.optimizeQuality = OptimizeQuality;
		localHostDefaultOption.dontCare = DontCare;
		localHostDefaultOption.escoHV1enable = ESCOHV1enable;
		localHostDefaultOption.escoHV2enable = ESCOHV2enable;
		localHostDefaultOption.escoHV3enable = ESCOHV3enable;
		localHostDefaultOption.escoEV3enable = ESCOEV3enable;
		localHostDefaultOption.escoEV4enable = ESCOEV4enable;
		localHostDefaultOption.escoEV5enable = ESCOEV5enable;
		localHostDefaultOption.esco2EV3enable = ESCO2EV3enable;
		localHostDefaultOption.esco3EV3enable = ESCO3EV3enable;
		localHostDefaultOption.esco2EV5enable = ESCO2EV5enable;
		localHostDefaultOption.esco3EV5enable = ESCO3EV5enable;
		localHostDefaultOption.airCodingCVSDEnable = AirCodingCVSDEnable;
		localHostDefaultOption.airCodingULawEnable = AirCodingULawEnable;
		localHostDefaultOption.airCodingALawEnable = AirCodingALawEnable;
		localHostDefaultOption.airCodingTransparentDataEnable = AirCodingTransparentDataEnable;
		localHostDefaultOption.linearPCMBitPosition = LinearPCMBitPosition;
		localHostDefaultOption.sampleSize8BitEnable = SampleSize8BitEnable;
		localHostDefaultOption.sampleSize16BitEnable = SampleSize16BitEnable;
		localHostDefaultOption.inputData1ComplEnable = InputData1ComplEnable;
		localHostDefaultOption.inputData2ComplEnable = InputData2ComplEnable;
		localHostDefaultOption.inputDataSignMagnitudeEnable = InputDataSignMagnitudeEnable;
		localHostDefaultOption.inputDataUnsignedEnable = InputDataUnsignedEnable;
		localHostDefaultOption.inputCodingLinearEnable = InputCodingLinearEnable;
		localHostDefaultOption.inputCodingALawEnable = InputCodingALawEnable;
		localHostDefaultOption.inputCodingULawEnable = InputCodingULawEnable;
		localHostDefaultOption.inputCodingCVSDEnable = InputCodingCVSDEnable;
		localHostDefaultOption.audioSourceCodecEnable = AudioSourceCodecEnable;
		localHostDefaultOption.audioSourceHCIEnable = AudioSourceHCIEnable;
		localHostDefaultOption.transmitBandwidth_enhSync = TransmitBandwidth_enhSync;
		localHostDefaultOption.receiveBandwidth_enhSync = ReceiveBandwidth_enhSync;
		localHostDefaultOption.maxLatency_enhSync = MaxLatency_enhSync;
		localHostDefaultOption.msMaxLatency_enhSync = MsMaxLatency_enhSync;
		localHostDefaultOption.slotMaxLatency_enhSync = SlotMaxLatency_enhSync;
		localHostDefaultOption.noRestrans_enhSync = NoRestrans_enhSync;
		localHostDefaultOption.optimizePower_enhSync = OptimizePower_enhSync;
		localHostDefaultOption.optimizeQuality_enhSync = OptimizeQuality_enhSync;
		localHostDefaultOption.dontCare_enhSync = DontCare_enhSync;
		localHostDefaultOption.escoHV1enable_enhSync = ESCOHV1enable_enhSync;
		localHostDefaultOption.escoHV2enable_enhSync = ESCOHV2enable_enhSync;
		localHostDefaultOption.escoHV3enable_enhSync = ESCOHV3enable_enhSync;
		localHostDefaultOption.escoEV3enable_enhSync = ESCOEV3enable_enhSync;
		localHostDefaultOption.escoEV4enable_enhSync = ESCOEV4enable_enhSync;
		localHostDefaultOption.escoEV5enable_enhSync = ESCOEV5enable_enhSync;
		localHostDefaultOption.esco2EV3enable_enhSync = ESCO2EV3enable_enhSync;
		localHostDefaultOption.esco3EV3enable_enhSync = ESCO3EV3enable_enhSync;
		localHostDefaultOption.esco2EV5enable_enhSync = ESCO2EV5enable_enhSync;
		localHostDefaultOption.esco3EV5enable_enhSync = ESCO3EV5enable_enhSync;
		localHostDefaultOption.InputDataPath = InputDataPath;
		localHostDefaultOption.OutputDataPath = OutputDataPath;
		localHostDefaultOption.TxRxCodingFormat = TxRxCodingFormat;
		localHostDefaultOption.PcmSamplePayload = PcmSamplePayload;
		localHostDefaultOption.IOCodedDataSize = IOCodedDataSize;
		localHostDefaultOption.IOPcmDataFormat = IOPcmDataFormat;
		localHostDefaultOption.IOCodingFormat = IOCodingFormat;
		localHostDefaultOption.EnhancedSync = useEnhancedParameters;
		localHostDefaultOption.lap = Lap;
		localHostDefaultOption.length = Length;
		localHostDefaultOption.responses = Responses;
		localHostDefaultOption.bluetoothAddress1 = AddressFilter[0];
		localHostDefaultOption.bluetoothAddress2 = AddressFilter[1];
		localHostDefaultOption.bluetoothAddress3 = AddressFilter[2];
		localHostDefaultOption.bluetoothAddress4 = AddressFilter[3];
		localHostDefaultOption.bluetoothAddress5 = AddressFilter[4];
		localHostDefaultOption.bluetoothAddress6 = AddressFilter[5];
		localHostDefaultOption.fecRequired = FECRequired;
		localHostDefaultOption.extendedInquiryResponse = ExtendedInquiryResponse;
		localHostDefaultOption.authenticationEnable = AuthenticationEnable;
		localHostDefaultOption.encryptionEnable = EncryptionEnable;
		localHostDefaultOption.simplePairingEnable = SimplePairingEnable;
		localHostDefaultOption.debugModeEnable = DebugModeEnable;
		localHostDefaultOption.secureConnectionsHostSupportEnable = SecureConnectionsHostSupportEnable;
		localHostDefaultOption.levelChoice = ((!LevelDefaultEnable) ? (LevelAuthenticationEnable ? 1 : (LevelPairingEnable ? 2 : 0)) : 0);
		localHostDefaultOption.linkKeyChoice = ((!LinkKeyASCIIEnable) ? (LinkKeyHexEnable ? 1 : 1) : 0);
		localHostDefaultOption.linkKey = LinkKey;
		localHostDefaultOption.pinCodeChoice = ((!PinCodeASCIIEnable) ? (PinCodeHexEnable ? 1 : 1) : 0);
		localHostDefaultOption.pinCode = PinCode;
		localHostDefaultOption.ioCapability = IOCapability;
		localHostDefaultOption.outOfBandDataPresent = OutOfBandDataPresent;
		localHostDefaultOption.confirmationRequestReply = ConfirmationRequestReply;
		localHostDefaultOption.passkeyRequestReply = PasskeyRequestReply;
		localHostDefaultOption.authenticationRequirements = AuthenticationRequirements;
		localHostDefaultOption.oobc = OOBC;
		localHostDefaultOption.oobr = OOBR;
		localHostDefaultOption.ShowDialog();
		if (localHostDefaultOption.DialogResult != DialogResult.OK)
		{
			return;
		}
		DM1enable = localHostDefaultOption.dM1enable;
		DM3enable = localHostDefaultOption.dM3enable;
		DM5enable = localHostDefaultOption.dM5enable;
		DH1enable = localHostDefaultOption.dH1enable;
		DH3enable = localHostDefaultOption.dH3enable;
		DH5enable = localHostDefaultOption.dH5enable;
		twoDH1enable = localHostDefaultOption.twodH1enable;
		twoDH3enable = localHostDefaultOption.twodH3enable;
		twoDH5enable = localHostDefaultOption.twodH5enable;
		threeDH1enable = localHostDefaultOption.threedH1enable;
		threeDH3enable = localHostDefaultOption.threedH3enable;
		threeDH5enable = localHostDefaultOption.threedH5enable;
		scanEnableLocalHost = localHostDefaultOption.scanEnableLocalHost;
		HV1enable = localHostDefaultOption.hV1enable;
		HV2enable = localHostDefaultOption.hV2enable;
		HV3enable = localHostDefaultOption.hV3enable;
		allowRoleswitch = localHostDefaultOption.allowRoleSwitch;
		lmPerformMSswitch = localHostDefaultOption.lmPerformMSswitch;
		autoAcceptConnectionRequest = localHostDefaultOption.AutoAcceptConnectionReq;
		MasterSlaveSwitchEnable = localHostDefaultOption.masterSlaveSwitch;
		HoldModeEnable = localHostDefaultOption.holdMode;
		SniffModeEnable = localHostDefaultOption.sniffMode;
		ParkModeEnable = localHostDefaultOption.parkMode;
		MaintainCurrentPower = localHostDefaultOption.maintainCurrentPower;
		SuspendPageScanEnable = localHostDefaultOption.suspendPageScan;
		SuspendInquiryScanEnable = localHostDefaultOption.suspendInquiryScan;
		SuspendPeriodicInquiriesEnable = localHostDefaultOption.suspendPeriodicInquiries;
		if (localHostDefaultOption.writeHoldModeActivity)
		{
			if (MaintainCurrentPower)
			{
				btMainWorkerThread.WriteHoldModeActivity(DefaultHoldModeActivityInfo.DefaultHoldModeActivityToValue(DefaultHoldModeActivityEnum.Maintain_current_Power_State));
			}
			else
			{
				SuspendHoldModeActivityEnumCollection suspendHoldModeActivityEnumCollection = new SuspendHoldModeActivityEnumCollection();
				suspendHoldModeActivityEnumCollection.SuspendPageScan = (SuspendPageScanEnable ? EnableBitEnum.Enabled : EnableBitEnum.Disabled);
				suspendHoldModeActivityEnumCollection.SuspendInquiryScan = (SuspendInquiryScanEnable ? EnableBitEnum.Enabled : EnableBitEnum.Disabled);
				suspendHoldModeActivityEnumCollection.SuspendPeriodicInquiries = (SuspendPeriodicInquiriesEnable ? EnableBitEnum.Enabled : EnableBitEnum.Disabled);
				btMainWorkerThread.WriteHoldModeActivity(SuspendHoldModeActivityInfo.SuspendHoldModeActivityToValue(suspendHoldModeActivityEnumCollection));
			}
		}
		TransmitBandwidth = localHostDefaultOption.transmitBandwidth;
		ReceiveBandwidth = localHostDefaultOption.receiveBandwidth;
		MaxLatency = localHostDefaultOption.maxLatency;
		MsMaxLatency = localHostDefaultOption.msMaxLatency;
		SlotMaxLatency = localHostDefaultOption.slotMaxLatency;
		VoiceSetting = localHostDefaultOption.voiceSetting;
		NoRestrans = localHostDefaultOption.noRestrans;
		OptimizePower = localHostDefaultOption.optimizePower;
		OptimizeQuality = localHostDefaultOption.optimizeQuality;
		DontCare = localHostDefaultOption.dontCare;
		ESCOHV1enable = localHostDefaultOption.escoHV1enable;
		ESCOHV2enable = localHostDefaultOption.escoHV2enable;
		ESCOHV3enable = localHostDefaultOption.escoHV3enable;
		ESCOEV3enable = localHostDefaultOption.escoEV3enable;
		ESCOEV4enable = localHostDefaultOption.escoEV4enable;
		ESCOEV5enable = localHostDefaultOption.escoEV5enable;
		ESCO2EV3enable = localHostDefaultOption.esco2EV3enable;
		ESCO3EV3enable = localHostDefaultOption.esco3EV3enable;
		ESCO2EV5enable = localHostDefaultOption.esco2EV5enable;
		ESCO3EV5enable = localHostDefaultOption.esco3EV5enable;
		AirCodingCVSDEnable = localHostDefaultOption.airCodingCVSDEnable;
		AirCodingULawEnable = localHostDefaultOption.airCodingULawEnable;
		AirCodingALawEnable = localHostDefaultOption.airCodingALawEnable;
		AirCodingTransparentDataEnable = localHostDefaultOption.airCodingTransparentDataEnable;
		LinearPCMBitPosition = localHostDefaultOption.linearPCMBitPosition;
		SampleSize8BitEnable = localHostDefaultOption.sampleSize8BitEnable;
		SampleSize16BitEnable = localHostDefaultOption.sampleSize16BitEnable;
		InputData1ComplEnable = localHostDefaultOption.inputData1ComplEnable;
		InputData2ComplEnable = localHostDefaultOption.inputData2ComplEnable;
		InputDataSignMagnitudeEnable = localHostDefaultOption.inputDataSignMagnitudeEnable;
		InputDataUnsignedEnable = localHostDefaultOption.inputDataUnsignedEnable;
		InputCodingLinearEnable = localHostDefaultOption.inputCodingLinearEnable;
		InputCodingALawEnable = localHostDefaultOption.inputCodingALawEnable;
		InputCodingULawEnable = localHostDefaultOption.inputCodingULawEnable;
		InputCodingCVSDEnable = localHostDefaultOption.inputCodingCVSDEnable;
		AudioSourceCodecEnable = localHostDefaultOption.audioSourceCodecEnable;
		AudioSourceHCIEnable = localHostDefaultOption.audioSourceHCIEnable;
		TransmitBandwidth_enhSync = localHostDefaultOption.transmitBandwidth_enhSync;
		ReceiveBandwidth_enhSync = localHostDefaultOption.receiveBandwidth_enhSync;
		MaxLatency_enhSync = localHostDefaultOption.maxLatency_enhSync;
		MsMaxLatency_enhSync = localHostDefaultOption.msMaxLatency_enhSync;
		SlotMaxLatency_enhSync = localHostDefaultOption.slotMaxLatency_enhSync;
		NoRestrans_enhSync = localHostDefaultOption.noRestrans_enhSync;
		OptimizePower_enhSync = localHostDefaultOption.optimizePower_enhSync;
		OptimizeQuality_enhSync = localHostDefaultOption.optimizeQuality_enhSync;
		DontCare_enhSync = localHostDefaultOption.dontCare_enhSync;
		ESCOHV1enable_enhSync = localHostDefaultOption.escoHV1enable_enhSync;
		ESCOHV2enable_enhSync = localHostDefaultOption.escoHV2enable_enhSync;
		ESCOHV3enable_enhSync = localHostDefaultOption.escoHV3enable_enhSync;
		ESCOEV3enable_enhSync = localHostDefaultOption.escoEV3enable_enhSync;
		ESCOEV4enable_enhSync = localHostDefaultOption.escoEV4enable_enhSync;
		ESCOEV5enable_enhSync = localHostDefaultOption.escoEV5enable_enhSync;
		ESCO2EV3enable_enhSync = localHostDefaultOption.esco2EV3enable_enhSync;
		ESCO3EV3enable_enhSync = localHostDefaultOption.esco3EV3enable_enhSync;
		ESCO2EV5enable_enhSync = localHostDefaultOption.esco2EV5enable_enhSync;
		ESCO3EV5enable_enhSync = localHostDefaultOption.esco3EV5enable_enhSync;
		InputDataPath = localHostDefaultOption.InputDataPath;
		OutputDataPath = localHostDefaultOption.OutputDataPath;
		TxRxCodingFormat = localHostDefaultOption.TxRxCodingFormat;
		PcmSamplePayload = localHostDefaultOption.PcmSamplePayload;
		IOCodedDataSize = localHostDefaultOption.IOCodedDataSize;
		IOPcmDataFormat = localHostDefaultOption.IOPcmDataFormat;
		IOCodingFormat = localHostDefaultOption.IOCodingFormat;
		useEnhancedParameters = localHostDefaultOption.EnhancedSync;
		Lap = localHostDefaultOption.lap;
		Length = localHostDefaultOption.length;
		Responses = localHostDefaultOption.responses;
		AddressFilter[0] = localHostDefaultOption.bluetoothAddress1.ToUpper();
		AddressFilter[1] = localHostDefaultOption.bluetoothAddress2.ToUpper();
		AddressFilter[2] = localHostDefaultOption.bluetoothAddress3.ToUpper();
		AddressFilter[3] = localHostDefaultOption.bluetoothAddress4.ToUpper();
		AddressFilter[4] = localHostDefaultOption.bluetoothAddress5.ToUpper();
		AddressFilter[5] = localHostDefaultOption.bluetoothAddress6.ToUpper();
		FECRequired = localHostDefaultOption.fecRequired;
		ExtendedInquiryResponse = localHostDefaultOption.extendedInquiryResponse;
		if (localHostDefaultOption.writeExtendedInquiryResponse)
		{
			btMainWorkerThread.WriteExtendedInquiryResponse(FECRequired ? 1u : 0u, Conversions.HexStringToByteArray(ExtendedInquiryResponse));
		}
		AuthenticationEnable = localHostDefaultOption.authenticationEnable;
		EncryptionEnable = localHostDefaultOption.encryptionEnable;
		SimplePairingEnable = localHostDefaultOption.simplePairingEnable;
		DebugModeEnable = localHostDefaultOption.debugModeEnable;
		SecureConnectionsHostSupportEnable = localHostDefaultOption.secureConnectionsHostSupportEnable;
		if (localHostDefaultOption.writeAuthenticationAndEncryptionParameters)
		{
			btMainWorkerThread.WriteAuthenticationAndEncryptionParameters(AuthenticationEnable ? 1u : 0u, EncryptionEnable ? 1u : 0u, SimplePairingEnable ? 1u : 0u, DebugModeEnable ? 1u : 0u, SecureConnectionsHostSupportEnable ? 1u : 0u);
		}
		LevelDefaultEnable = localHostDefaultOption.levelChoice == 0;
		LevelAuthenticationEnable = localHostDefaultOption.levelChoice == 1;
		LevelPairingEnable = localHostDefaultOption.levelChoice == 2;
		LinkKeyASCIIEnable = localHostDefaultOption.linkKeyChoice == 0;
		LinkKeyHexEnable = localHostDefaultOption.linkKeyChoice == 1;
		LinkKey = localHostDefaultOption.linkKey;
		PinCodeASCIIEnable = localHostDefaultOption.pinCodeChoice == 0;
		PinCodeHexEnable = localHostDefaultOption.pinCodeChoice == 1;
		PinCode = localHostDefaultOption.pinCode;
		IOCapability = localHostDefaultOption.ioCapability;
		OutOfBandDataPresent = localHostDefaultOption.outOfBandDataPresent;
		ConfirmationRequestReply = localHostDefaultOption.confirmationRequestReply;
		PasskeyRequestReply = localHostDefaultOption.passkeyRequestReply;
		AuthenticationRequirements = localHostDefaultOption.authenticationRequirements;
		OOBC = localHostDefaultOption.oobc;
		OOBR = localHostDefaultOption.oobr;
		UpdateAllBTRemoteDeviceInfoWithLocalHostDefaultOptions();
	}

	private void PageScanHandler(object sender, EventArgs e)
	{
		WriteScanEnable writeScanEnable = new WriteScanEnable();
		if (toolStripButtonPageScan.Checked)
		{
			if (toolStripButtonInquiryScan.Checked)
			{
				writeScanEnable.UserFields.ScanEnable = 1u;
				try
				{
					btAPI.Send(writeScanEnable);
					toolStripButtonPageScan.Checked = false;
					scanEnable = WriteScanEnable.UserFieldsWrapper.ScanEnableEnum.INQUIRY_SCAN_ENABLED;
					return;
				}
				catch (Exception ex)
				{
					logger.Enqueue(new QCRPG.Framework.LogMessage(LogMessageType.Error, ex));
					return;
				}
			}
			writeScanEnable.UserFields.ScanEnable = 0u;
			try
			{
				btAPI.Send(writeScanEnable);
				toolStripButtonPageScan.Checked = false;
				scanEnable = WriteScanEnable.UserFieldsWrapper.ScanEnableEnum.NO_SCANS_ENABLED;
				return;
			}
			catch (Exception ex2)
			{
				logger.Enqueue(new QCRPG.Framework.LogMessage(LogMessageType.Error, ex2));
				return;
			}
		}
		if (toolStripButtonInquiryScan.Checked)
		{
			writeScanEnable.UserFields.ScanEnable = 3u;
			try
			{
				btAPI.Send(writeScanEnable);
				toolStripButtonPageScan.Checked = true;
				scanEnable = WriteScanEnable.UserFieldsWrapper.ScanEnableEnum.BOTH_SCANS_ENABLED;
				return;
			}
			catch (Exception ex3)
			{
				logger.Enqueue(new QCRPG.Framework.LogMessage(LogMessageType.Error, ex3));
				return;
			}
		}
		writeScanEnable.UserFields.ScanEnable = 2u;
		try
		{
			btAPI.Send(writeScanEnable);
			toolStripButtonPageScan.Checked = true;
			scanEnable = WriteScanEnable.UserFieldsWrapper.ScanEnableEnum.PAGE_SCAN_ENABLED;
		}
		catch (Exception ex4)
		{
			logger.Enqueue(new QCRPG.Framework.LogMessage(LogMessageType.Error, ex4));
		}
	}

	private void InquiryScanHandler(object sender, EventArgs e)
	{
		WriteScanEnable writeScanEnable = new WriteScanEnable();
		if (toolStripButtonInquiryScan.Checked)
		{
			if (toolStripButtonPageScan.Checked)
			{
				writeScanEnable.UserFields.ScanEnable = 2u;
				try
				{
					btAPI.Send(writeScanEnable);
					toolStripButtonInquiryScan.Checked = false;
					scanEnable = WriteScanEnable.UserFieldsWrapper.ScanEnableEnum.PAGE_SCAN_ENABLED;
					return;
				}
				catch (Exception ex)
				{
					logger.Enqueue(new QCRPG.Framework.LogMessage(LogMessageType.Error, ex));
					return;
				}
			}
			writeScanEnable.UserFields.ScanEnable = 0u;
			try
			{
				btAPI.Send(writeScanEnable);
				toolStripButtonInquiryScan.Checked = false;
				scanEnable = WriteScanEnable.UserFieldsWrapper.ScanEnableEnum.NO_SCANS_ENABLED;
				return;
			}
			catch (Exception ex2)
			{
				logger.Enqueue(new QCRPG.Framework.LogMessage(LogMessageType.Error, ex2));
				return;
			}
		}
		if (toolStripButtonPageScan.Checked)
		{
			writeScanEnable.UserFields.ScanEnable = 3u;
			try
			{
				btAPI.Send(writeScanEnable);
				toolStripButtonInquiryScan.Checked = true;
				scanEnable = WriteScanEnable.UserFieldsWrapper.ScanEnableEnum.BOTH_SCANS_ENABLED;
				return;
			}
			catch (Exception ex3)
			{
				logger.Enqueue(new QCRPG.Framework.LogMessage(LogMessageType.Error, ex3));
				return;
			}
		}
		writeScanEnable.UserFields.ScanEnable = 1u;
		try
		{
			btAPI.Send(writeScanEnable);
			toolStripButtonInquiryScan.Checked = true;
			scanEnable = WriteScanEnable.UserFieldsWrapper.ScanEnableEnum.INQUIRY_SCAN_ENABLED;
		}
		catch (Exception ex4)
		{
			logger.Enqueue(new QCRPG.Framework.LogMessage(LogMessageType.Error, ex4));
		}
	}

	private void FileTransferHandler(object sender, EventArgs e)
	{
		OpenFileDialog openFileDialog = new OpenFileDialog();
		openFileDialog.Filter = "All Files (*.*)|*.*";
		if (openFileDialog.ShowDialog() == DialogResult.OK)
		{
			btMainWorkerThread.ACLDataPacketTransferViaFile(currentBTConnectionHandler, openFileDialog.FileName);
		}
	}

	private void LEAdvertisingHandler(object sender, EventArgs e)
	{
		LeSetAdvertiseEnabled leSetAdvertiseEnabled = new LeSetAdvertiseEnabled();
		if (toolStripButtonLEAdvertising.Checked)
		{
			leSetAdvertiseEnabled.UserFields.AdvertisingEnable = 0u;
			try
			{
				specificPacketNotifier.SetPacketNotification(typeof(CommandCompleteForLeSetAdvertiseEnabled), generalPacketParserForUIUpdates, enabled: true);
				advertiseToolStripMenuItem.Tag = false;
				btAPI.Send(leSetAdvertiseEnabled);
				toolStripButtonLEAdvertising.Checked = false;
				return;
			}
			catch (Exception ex)
			{
				logger.Enqueue(new QCRPG.Framework.LogMessage(LogMessageType.Error, ex));
				return;
			}
		}
		leSetAdvertiseEnabled.UserFields.AdvertisingEnable = 1u;
		try
		{
			specificPacketNotifier.SetPacketNotification(typeof(CommandCompleteForLeSetAdvertiseEnabled), generalPacketParserForUIUpdates, enabled: true);
			advertiseToolStripMenuItem.Tag = true;
			btAPI.Send(leSetAdvertiseEnabled);
			toolStripButtonLEAdvertising.Checked = true;
		}
		catch (Exception ex2)
		{
			logger.Enqueue(new QCRPG.Framework.LogMessage(LogMessageType.Error, ex2));
		}
	}

	private void LEScanHandler(object sender, EventArgs e)
	{
		LeSetScanEnabled leSetScanEnabled = new LeSetScanEnabled();
		leSetScanEnabled.UserFields.FilterDuplicates = 0u;
		if (toolStripButtonLEScan.Checked)
		{
			leSetScanEnabled.UserFields.LeScanEnable = 0u;
			try
			{
				specificPacketNotifier.SetPacketNotification(typeof(CommandCompleteForLeSetScanEnabled), generalPacketParserForUIUpdates, enabled: true);
				specificPacketNotifier.SetPacketNotification(typeof(LeAdvertisingReport), generalPacketParserForUIUpdates, enabled: false);
				scanToolStripMenuItem.Tag = false;
				btAPI.Send(leSetScanEnabled);
				toolStripButtonLEScan.Checked = false;
				return;
			}
			catch (Exception ex)
			{
				logger.Enqueue(new QCRPG.Framework.LogMessage(LogMessageType.Error, ex));
				return;
			}
		}
		leSetScanEnabled.UserFields.LeScanEnable = 1u;
		try
		{
			specificPacketNotifier.SetPacketNotification(typeof(CommandCompleteForLeSetScanEnabled), generalPacketParserForUIUpdates, enabled: true);
			specificPacketNotifier.SetPacketNotification(typeof(LeAdvertisingReport), generalPacketParserForUIUpdates, enabled: true);
			scanToolStripMenuItem.Tag = true;
			btAPI.Send(leSetScanEnabled);
			toolStripButtonLEScan.Checked = true;
		}
		catch (Exception ex2)
		{
			logger.Enqueue(new QCRPG.Framework.LogMessage(LogMessageType.Error, ex2));
		}
	}

	private void btDeviceListView_ColumnClick(object sender, ColumnClickEventArgs e)
	{
		sortAscendingOrder = !sortAscendingOrder;
		SortListView(e.Column, sortAscendingOrder);
	}

	private bool CheckStatusForPacket(PacketBase packet, string packetName)
	{
		foreach (PacketFieldInfo fieldInfo in packet.Info.FieldInfoList)
		{
			if (fieldInfo.ParameterName == "Status")
			{
				ErrorCodeEnum errorCodeEnum = ErrorCodeInfo.ValueToErrorCode(Convert.ToUInt32(fieldInfo.Value, 16));
				if (errorCodeEnum != 0)
				{
					logger.Enqueue(new QCRPG.Framework.LogMessage(LogMessageType.Error, packetName + " status field indicates error: " + errorCodeEnum));
				}
				return true;
			}
		}
		logger.Enqueue(new QCRPG.Framework.LogMessage(LogMessageType.Error, "Packet type doesn't have a status field: " + packetName));
		return false;
	}

	public int CalculatePacketTypeForESCOConnection()
	{
		EnhancedSynchronousPacketTypeEnumCollection enhancedSynchronousPacketTypeEnumCollection = new EnhancedSynchronousPacketTypeEnumCollection();
		enhancedSynchronousPacketTypeEnumCollection.Hv1MayBeUsed = (ESCOHV1enable ? AssertBitEnum.Set : AssertBitEnum.Not_Set);
		enhancedSynchronousPacketTypeEnumCollection.Hv2MayBeUsed = (ESCOHV2enable ? AssertBitEnum.Set : AssertBitEnum.Not_Set);
		enhancedSynchronousPacketTypeEnumCollection.Hv3MayBeUsed = (ESCOHV3enable ? AssertBitEnum.Set : AssertBitEnum.Not_Set);
		enhancedSynchronousPacketTypeEnumCollection.Ev3MayBeUsed = (ESCOEV3enable ? AssertBitEnum.Set : AssertBitEnum.Not_Set);
		enhancedSynchronousPacketTypeEnumCollection.Ev4MayBeUsed = (ESCOEV4enable ? AssertBitEnum.Set : AssertBitEnum.Not_Set);
		enhancedSynchronousPacketTypeEnumCollection.Ev5MayBeUsed = (ESCOEV5enable ? AssertBitEnum.Set : AssertBitEnum.Not_Set);
		enhancedSynchronousPacketTypeEnumCollection.TwoEv3ShallNotBeUsed = ((!ESCO2EV3enable) ? AssertBitEnum.Set : AssertBitEnum.Not_Set);
		enhancedSynchronousPacketTypeEnumCollection.ThreeEv3ShallNotBeUsed = ((!ESCO3EV3enable) ? AssertBitEnum.Set : AssertBitEnum.Not_Set);
		enhancedSynchronousPacketTypeEnumCollection.TwoEv5ShallNotBeUsed = ((!ESCO2EV5enable) ? AssertBitEnum.Set : AssertBitEnum.Not_Set);
		enhancedSynchronousPacketTypeEnumCollection.ThreeEv5ShallNotBeUsed = ((!ESCO3EV5enable) ? AssertBitEnum.Set : AssertBitEnum.Not_Set);
		return (int)EnhancedSynchronousPacketTypeInfo.EnhancedSynchronousPacketTypeToValue(enhancedSynchronousPacketTypeEnumCollection);
	}

	public int CalculateRetransmissionEffortForESCOConnection()
	{
		int result = 0;
		if (NoRestrans)
		{
			result = 0;
		}
		if (OptimizePower)
		{
			result = 1;
		}
		if (OptimizeQuality)
		{
			result = 2;
		}
		if (DontCare)
		{
			result = 255;
		}
		return result;
	}

	private void UpdateBTRemoteDeviceInfoWithLocalHostDefaultOptions(string bdAddress)
	{
		BTLERemoteDeviceInfo.BTRemoteDeviceInfo btRemoteDevice = default(BTLERemoteDeviceInfo.BTRemoteDeviceInfo);
		btRemoteDevice.dm1enable = DM1enable;
		btRemoteDevice.dm3enable = DM3enable;
		btRemoteDevice.dm5enable = DM5enable;
		btRemoteDevice.dh1enable = DH1enable;
		btRemoteDevice.dh3enable = DH3enable;
		btRemoteDevice.dh5enable = DH5enable;
		btRemoteDevice.twoDH1enable = twoDH1enable;
		btRemoteDevice.twoDH3enable = twoDH3enable;
		btRemoteDevice.twoDH5enable = twoDH5enable;
		btRemoteDevice.threeDH1enable = threeDH1enable;
		btRemoteDevice.threeDH3enable = threeDH3enable;
		btRemoteDevice.threeDH5enable = threeDH5enable;
		btRemoteDevice.allowRoleSwitch = allowRoleswitch;
		btRemoteDevice.lmPerformMSswitch = lmPerformMSswitch;
		btRemoteDevice.hv1enable = HV1enable;
		btRemoteDevice.hv2enable = HV2enable;
		btRemoteDevice.hv3enable = HV3enable;
		btRemoteDevice.levelDefaultEnable = LevelDefaultEnable;
		btRemoteDevice.levelAuthenticationEnable = LevelAuthenticationEnable;
		btRemoteDevice.levelPairingEnable = LevelPairingEnable;
		btRemoteDevice.linkKeyASCIIEnable = LinkKeyASCIIEnable;
		btRemoteDevice.linkKeyHexEnable = LinkKeyHexEnable;
		btRemoteDevice.linkKey = LinkKey;
		btRemoteDevice.pinCodeASCIIEnable = PinCodeASCIIEnable;
		btRemoteDevice.pinCodeHexEnable = PinCodeHexEnable;
		btRemoteDevice.pinCode = PinCode;
		btRemoteDevice.ioCapability = IOCapability;
		btRemoteDevice.outOfBandDataPresent = OutOfBandDataPresent;
		btRemoteDevice.confirmationRequestReply = ConfirmationRequestReply;
		btRemoteDevice.passkeyRequestReply = PasskeyRequestReply;
		btRemoteDevice.authenticationRequirements = AuthenticationRequirements;
		btRemoteDevice.oobc = OOBC;
		btRemoteDevice.oobr = OOBR;
		if (BTLERemoteDeviceInfoList.CheckAndGetBTRemoteDeviceInfoByBDAddress(bdAddress, out var btRemoteDevice2))
		{
			btRemoteDevice.bdAddress = btRemoteDevice2.bdAddress;
			btRemoteDevice.pageScanRepMode = btRemoteDevice2.pageScanRepMode;
			btRemoteDevice.classOfDevice = btRemoteDevice2.classOfDevice;
			btRemoteDevice.clockOffset = btRemoteDevice2.clockOffset;
			btRemoteDevice.clockOffsetValid = btRemoteDevice2.clockOffsetValid;
			btRemoteDevice.RSSI = btRemoteDevice2.RSSI;
			btRemoteDevice.connectionHandler = btRemoteDevice2.connectionHandler;
			btRemoteDevice.MasterSlave = btRemoteDevice2.MasterSlave;
			btRemoteDevice.askForConnectionRequest = btRemoteDevice2.askForConnectionRequest;
			btRemoteDevice.scoConnections = btRemoteDevice2.scoConnections;
			btRemoteDevice.currentMode = btRemoteDevice2.currentMode;
		}
		else
		{
			btRemoteDevice.bdAddress = bdAddress;
			btRemoteDevice.pageScanRepMode = PageScanRepetitionModeEnum.R1;
			btRemoteDevice.RSSI = "Invalid";
		}
		BTLERemoteDeviceInfoList.UpdateBTRemoteDeviceList(btRemoteDevice);
	}

	private void UpdateAllBTRemoteDeviceInfoWithLocalHostDefaultOptions()
	{
		BTLERemoteDeviceInfo.BTRemoteDeviceInfo btRemoteDevice = default(BTLERemoteDeviceInfo.BTRemoteDeviceInfo);
		btRemoteDevice.dm1enable = DM1enable;
		btRemoteDevice.dm3enable = DM3enable;
		btRemoteDevice.dm5enable = DM5enable;
		btRemoteDevice.dh1enable = DH1enable;
		btRemoteDevice.dh3enable = DH3enable;
		btRemoteDevice.dh5enable = DH5enable;
		btRemoteDevice.twoDH1enable = twoDH1enable;
		btRemoteDevice.twoDH3enable = twoDH3enable;
		btRemoteDevice.twoDH5enable = twoDH5enable;
		btRemoteDevice.threeDH1enable = threeDH1enable;
		btRemoteDevice.threeDH3enable = threeDH3enable;
		btRemoteDevice.threeDH5enable = threeDH5enable;
		btRemoteDevice.allowRoleSwitch = allowRoleswitch;
		btRemoteDevice.lmPerformMSswitch = lmPerformMSswitch;
		btRemoteDevice.hv1enable = HV1enable;
		btRemoteDevice.hv2enable = HV2enable;
		btRemoteDevice.hv3enable = HV3enable;
		btRemoteDevice.levelDefaultEnable = LevelDefaultEnable;
		btRemoteDevice.levelAuthenticationEnable = LevelAuthenticationEnable;
		btRemoteDevice.levelPairingEnable = LevelPairingEnable;
		btRemoteDevice.linkKeyASCIIEnable = LinkKeyASCIIEnable;
		btRemoteDevice.linkKeyHexEnable = LinkKeyHexEnable;
		btRemoteDevice.linkKey = LinkKey;
		btRemoteDevice.pinCodeASCIIEnable = PinCodeASCIIEnable;
		btRemoteDevice.pinCodeHexEnable = PinCodeHexEnable;
		btRemoteDevice.pinCode = PinCode;
		btRemoteDevice.ioCapability = IOCapability;
		btRemoteDevice.outOfBandDataPresent = OutOfBandDataPresent;
		btRemoteDevice.confirmationRequestReply = ConfirmationRequestReply;
		btRemoteDevice.passkeyRequestReply = PasskeyRequestReply;
		btRemoteDevice.authenticationRequirements = AuthenticationRequirements;
		btRemoteDevice.oobc = OOBC;
		btRemoteDevice.oobr = OOBR;
		for (int i = LocalBTDeviceIndex + 1; i < LocalLEDeviceIndex; i++)
		{
			if (BTLERemoteDeviceInfoList.CheckAndGetBTRemoteDeviceInfoByBDAddress(btDeviceListView.Items[i].Text, out var btRemoteDevice2))
			{
				btRemoteDevice.bdAddress = btRemoteDevice2.bdAddress;
				btRemoteDevice.pageScanRepMode = btRemoteDevice2.pageScanRepMode;
				btRemoteDevice.classOfDevice = btRemoteDevice2.classOfDevice;
				btRemoteDevice.clockOffset = btRemoteDevice2.clockOffset;
				btRemoteDevice.clockOffsetValid = btRemoteDevice2.clockOffsetValid;
				btRemoteDevice.RSSI = btRemoteDevice2.RSSI;
				btRemoteDevice.connectionHandler = btRemoteDevice2.connectionHandler;
				btRemoteDevice.MasterSlave = btRemoteDevice2.MasterSlave;
				btRemoteDevice.askForConnectionRequest = btRemoteDevice2.askForConnectionRequest;
				btRemoteDevice.scoConnections = btRemoteDevice2.scoConnections;
				btRemoteDevice.currentMode = btRemoteDevice2.currentMode;
			}
			BTLERemoteDeviceInfoList.UpdateBTRemoteDeviceList(btRemoteDevice);
		}
	}

	private void UpdateLERemoteDeviceInfoWithLocalHostULPOptions(string bdAddress)
	{
		BTLERemoteDeviceInfo.LERemoteDeviceInfo leRemoteDevice = default(BTLERemoteDeviceInfo.LERemoteDeviceInfo);
		leRemoteDevice.longTermKey = LELinkKey;
		leRemoteDevice.randomNumber = RandomNumber;
		leRemoteDevice.encryptedDiversifier = EncryptedDiversifier;
		leRemoteDevice.keyReply = PositiveAutoReply;
		leRemoteDevice.connUpdateIntervalMin = (uint)ConnectionTimingMinInterval;
		leRemoteDevice.connUpdateIntervalMax = (uint)ConnectionTimingMaxInterval;
		leRemoteDevice.connUpdateTimeoutMs = (uint)ConnectionTimingTimeout;
		leRemoteDevice.connUpdateLatency = (uint)ConnectionTimingLatency;
		leRemoteDevice.connUpdateCELengthMin = (uint)ConnectionEventTimingMinLength;
		leRemoteDevice.connUpdateCELengthMax = (uint)ConnectionEventTimingMaxLength;
		leRemoteDevice.connUpdateParamRequestAutoReply = connUpdateParamRequestPositiveReply;
		if (BTLERemoteDeviceInfoList.CheckAndGetLERemoteDeviceInfoByBDAddress(bdAddress, out var leRemoteDevice2))
		{
			leRemoteDevice.eventType = leRemoteDevice2.eventType;
			leRemoteDevice.addressType = leRemoteDevice2.addressType;
			leRemoteDevice.bdAddress = leRemoteDevice2.bdAddress;
			leRemoteDevice.dataLength = leRemoteDevice2.dataLength;
			leRemoteDevice.data = leRemoteDevice2.data;
			leRemoteDevice.RSSI = leRemoteDevice2.RSSI;
			leRemoteDevice.connectionHandler = leRemoteDevice2.connectionHandler;
			leRemoteDevice.MasterSlave = leRemoteDevice2.MasterSlave;
		}
		BTLERemoteDeviceInfoList.UpdateLERemoteDeviceList(leRemoteDevice);
	}

	private void UpdateAllLERemoteDeviceInfoWithLocalHostULPOptions()
	{
		BTLERemoteDeviceInfo.LERemoteDeviceInfo leRemoteDevice = default(BTLERemoteDeviceInfo.LERemoteDeviceInfo);
		leRemoteDevice.longTermKey = LELinkKey;
		leRemoteDevice.randomNumber = RandomNumber;
		leRemoteDevice.encryptedDiversifier = EncryptedDiversifier;
		leRemoteDevice.keyReply = PositiveAutoReply;
		leRemoteDevice.connUpdateIntervalMin = (uint)ConnectionTimingMinInterval;
		leRemoteDevice.connUpdateIntervalMax = (uint)ConnectionTimingMaxInterval;
		leRemoteDevice.connUpdateTimeoutMs = (uint)ConnectionTimingTimeout;
		leRemoteDevice.connUpdateLatency = (uint)ConnectionTimingLatency;
		leRemoteDevice.connUpdateCELengthMin = (uint)ConnectionEventTimingMinLength;
		leRemoteDevice.connUpdateCELengthMax = (uint)ConnectionEventTimingMaxLength;
		leRemoteDevice.connUpdateParamRequestAutoReply = connUpdateParamRequestPositiveReply;
		int count = btDeviceListView.Items.Count;
		for (int i = LocalLEDeviceIndex + 1; i < count; i++)
		{
			if (BTLERemoteDeviceInfoList.CheckAndGetLERemoteDeviceInfoByBDAddress(btDeviceListView.Items[i].Text, out var leRemoteDevice2))
			{
				leRemoteDevice.eventType = leRemoteDevice2.eventType;
				leRemoteDevice.addressType = leRemoteDevice2.addressType;
				leRemoteDevice.bdAddress = leRemoteDevice2.bdAddress;
				leRemoteDevice.dataLength = leRemoteDevice2.dataLength;
				leRemoteDevice.data = leRemoteDevice2.data;
				leRemoteDevice.RSSI = leRemoteDevice2.RSSI;
				leRemoteDevice.connectionHandler = leRemoteDevice2.connectionHandler;
				leRemoteDevice.MasterSlave = leRemoteDevice2.MasterSlave;
			}
			BTLERemoteDeviceInfoList.UpdateLERemoteDeviceList(leRemoteDevice);
		}
	}

	public static void AddIconToSubitem(ListView DeviceListView, int row, int col, int icon_num)
	{
		LV_ITEM item_info = default(LV_ITEM);
		item_info.iItem = row;
		item_info.iSubItem = col;
		item_info.uiMask = 18u;
		item_info.iImage = icon_num;
		item_info.iIndent = 1;
		SendMessage(DeviceListView.Handle, 4102u, 0, ref item_info);
		ShowSubItemIcons(DeviceListView);
	}

	public static void ShowSubItemIcons(ListView DeviceListView)
	{
		int num = SendMessage(DeviceListView.Handle, 4151u, 0, 0);
		num |= 2;
		SendMessage(DeviceListView.Handle, 4150u, 0, num);
	}

	public void SetCombinedScripter(CombinedScripter combinedScripter)
	{
		this.combinedScripter = combinedScripter;
		btMainWorkerThread.SetCombinedScripter(combinedScripter);
		btScriptUserControl.SetCombinedScripter(combinedScripter);
	}

	public override void UpdateStatusBar(PacketBase packet)
	{
		if (packet.Type == PacketType.Data)
		{
			uint num = 2u;
			uint num2 = 4u;
			bool flag = (packet.Flags & num) == num;
			bool flag2 = (packet.Flags & num2) == num2;
			if (packet is AclData)
			{
				if (flag)
				{
					TxAcl++;
				}
				if (flag2)
				{
					RxAcl++;
				}
			}
			else if (packet is SynchronousData)
			{
				if (flag)
				{
					TxSco++;
				}
				if (flag2)
				{
					RxSco++;
				}
			}
		}
		else if (packet.Type == PacketType.Command)
		{
			command++;
		}
		else if (packet.Type == PacketType.Notification)
		{
			notification++;
		}
		else if (packet.Type == PacketType.Response)
		{
			notification++;
		}
	}

	public override void UpdateTitleBar()
	{
		if (string.IsNullOrEmpty(base.TitleBarMessage))
		{
			base.TitleBarMessage = "QCRPG-BT";
		}
		GooierBase.SetWindowText((IntPtr)mainWindowHandle, base.TitleBarMessage);
	}

	private void InsertItemToListView(ListViewItem deviceItem)
	{
		IAsyncResult asyncResult = btDeviceListView.BeginInvoke((MethodInvoker)delegate
		{
			bool flag = false;
			for (int i = LocalBTDeviceIndex + 1; i < LocalLEDeviceIndex; i++)
			{
				int result = -999;
				if (int.TryParse(btDeviceListView.Items[i].SubItems[1].Text.ToString().Substring(0, btDeviceListView.Items[i].SubItems[1].Text.ToString().Length - 3), out var _) && int.TryParse(deviceItem.SubItems[1].Text.Substring(0, deviceItem.SubItems[1].Text.Length - 3), out result) && int.Parse(btDeviceListView.Items[i].SubItems[1].Text.ToString().Substring(0, btDeviceListView.Items[i].SubItems[1].Text.ToString().Length - 3)) < int.Parse(deviceItem.SubItems[1].Text.Substring(0, deviceItem.SubItems[1].Text.Length - 3)))
				{
					btDeviceListView.Items.Insert(i, deviceItem);
					LocalLEDeviceIndex++;
					flag = true;
					break;
				}
			}
			if (!flag)
			{
				btDeviceListView.Items.Insert(LocalLEDeviceIndex++, deviceItem);
			}
		});
		btDeviceListView.EndInvoke(asyncResult);
	}

	private void SortListView(int columnIndex, bool order)
	{
		IAsyncResult asyncResult = btDeviceListView.BeginInvoke((MethodInvoker)delegate
		{
			if (columnIndex > 1)
			{
				return;
			}
			UpdateBTDeviceListView(null);
			UpdateLEDeviceListView(null);
			if (columnIndex == 1)
			{
				foreach (BTLERemoteDeviceInfo.BTRemoteDeviceInfo item in BTLERemoteDeviceInfoList.btRemoteDeviceInfo)
				{
					ListViewItem listViewItem = new ListViewItem
					{
						Text = item.bdAddress
					};
					int connectionHandler = item.connectionHandler;
					if (connectionHandler != BTLERemoteDeviceInfoList.defaultConnectionHandle)
					{
						int imageIndex = 1;
						switch (item.currentMode)
						{
						case HciModeChange.UserFieldsWrapper.CurrentModeEnum.Active_Mode:
							imageIndex = 1;
							listViewItem.Tag = null;
							break;
						case HciModeChange.UserFieldsWrapper.CurrentModeEnum.Hold_Mode:
							imageIndex = 5;
							listViewItem.Tag = "Hold";
							break;
						case HciModeChange.UserFieldsWrapper.CurrentModeEnum.Sniff_Mode:
							imageIndex = 4;
							listViewItem.Tag = "Sniff";
							break;
						case HciModeChange.UserFieldsWrapper.CurrentModeEnum.Park_State:
							imageIndex = 6;
							listViewItem.Tag = "Park";
							break;
						case HciModeChange.UserFieldsWrapper.CurrentModeEnum.Reserved:
							imageIndex = 1;
							break;
						case HciModeChange.UserFieldsWrapper.CurrentModeEnum.InvalidCurrentModeValue:
							imageIndex = 1;
							break;
						}
						listViewItem.ImageIndex = imageIndex;
						listViewItem.Checked = true;
						listViewItem.SubItems.Add(item.RSSI);
						listViewItem.SubItems.Add(item.MasterSlave);
					}
					else
					{
						listViewItem.ImageIndex = 0;
						listViewItem.Checked = false;
						listViewItem.SubItems.Add(item.RSSI);
					}
					bool flag = false;
					for (int i = LocalBTDeviceIndex + 1; i < LocalLEDeviceIndex; i++)
					{
						int result = -999;
						if (int.TryParse(btDeviceListView.Items[i].SubItems[1].Text.ToString().Substring(0, btDeviceListView.Items[i].SubItems[1].Text.ToString().Length - 3), out var _) && int.TryParse(item.RSSI.Substring(0, item.RSSI.Length - 3), out result))
						{
							if (order)
							{
								if (int.Parse(btDeviceListView.Items[i].SubItems[1].Text.ToString().Substring(0, btDeviceListView.Items[i].SubItems[1].Text.ToString().Length - 3)) < int.Parse(item.RSSI.Substring(0, item.RSSI.Length - 3)))
								{
									btDeviceListView.Items.Insert(i, listViewItem);
									flag = true;
									LocalLEDeviceIndex++;
									break;
								}
							}
							else if (int.Parse(btDeviceListView.Items[i].SubItems[1].Text.ToString().Substring(0, btDeviceListView.Items[i].SubItems[1].Text.ToString().Length - 3)) > int.Parse(item.RSSI.Substring(0, item.RSSI.Length - 3)))
							{
								btDeviceListView.Items.Insert(i, listViewItem);
								flag = true;
								LocalLEDeviceIndex++;
								break;
							}
						}
					}
					if (!flag)
					{
						btDeviceListView.Items.Insert(LocalLEDeviceIndex, listViewItem);
						LocalLEDeviceIndex++;
					}
				}
				int num = LocalLEDeviceIndex + 1;
				lock (BTLERemoteDeviceInfoList.leRemoteDeviceInfo)
				{
					foreach (BTLERemoteDeviceInfo.LERemoteDeviceInfo item2 in BTLERemoteDeviceInfoList.leRemoteDeviceInfo)
					{
						ListViewItem listViewItem2 = new ListViewItem
						{
							Text = item2.bdAddress
						};
						int connectionHandler2 = item2.connectionHandler;
						if (connectionHandler2 != BTLERemoteDeviceInfoList.defaultConnectionHandle)
						{
							listViewItem2.ImageIndex = 1;
							listViewItem2.Checked = true;
							listViewItem2.SubItems.Add(item2.RSSI);
							listViewItem2.SubItems.Add(item2.MasterSlave);
						}
						else
						{
							listViewItem2.ImageIndex = 0;
							listViewItem2.Checked = false;
							listViewItem2.SubItems.Add(item2.RSSI);
						}
						bool flag2 = false;
						for (int j = LocalLEDeviceIndex + 1; j < btDeviceListView.Items.Count; j++)
						{
							if (order)
							{
								if (int.Parse(btDeviceListView.Items[j].SubItems[1].Text.ToString().Substring(0, btDeviceListView.Items[j].SubItems[1].Text.ToString().Length - 3)) < int.Parse(item2.RSSI.Substring(0, item2.RSSI.Length - 3)))
								{
									btDeviceListView.Items.Insert(j, listViewItem2);
									flag2 = true;
									num++;
									break;
								}
							}
							else if (int.Parse(btDeviceListView.Items[j].SubItems[1].Text.ToString().Substring(0, btDeviceListView.Items[j].SubItems[1].Text.ToString().Length - 3)) > int.Parse(item2.RSSI.Substring(0, item2.RSSI.Length - 3)))
							{
								btDeviceListView.Items.Insert(j, listViewItem2);
								flag2 = true;
								num++;
								break;
							}
						}
						if (!flag2)
						{
							btDeviceListView.Items.Insert(num, listViewItem2);
							num++;
						}
					}
				}
			}
			else if (columnIndex == 0)
			{
				foreach (BTLERemoteDeviceInfo.BTRemoteDeviceInfo item3 in BTLERemoteDeviceInfoList.btRemoteDeviceInfo)
				{
					ListViewItem listViewItem3 = new ListViewItem
					{
						Text = item3.bdAddress
					};
					int connectionHandler3 = item3.connectionHandler;
					if (connectionHandler3 != 0 && connectionHandler3 != BTLERemoteDeviceInfoList.defaultConnectionHandle)
					{
						int imageIndex2 = 1;
						switch (item3.currentMode)
						{
						case HciModeChange.UserFieldsWrapper.CurrentModeEnum.Active_Mode:
							imageIndex2 = 1;
							listViewItem3.Tag = null;
							break;
						case HciModeChange.UserFieldsWrapper.CurrentModeEnum.Hold_Mode:
							imageIndex2 = 5;
							listViewItem3.Tag = "Hold";
							break;
						case HciModeChange.UserFieldsWrapper.CurrentModeEnum.Sniff_Mode:
							imageIndex2 = 4;
							listViewItem3.Tag = "Sniff";
							break;
						case HciModeChange.UserFieldsWrapper.CurrentModeEnum.Park_State:
							imageIndex2 = 6;
							listViewItem3.Tag = "Park";
							break;
						case HciModeChange.UserFieldsWrapper.CurrentModeEnum.Reserved:
							imageIndex2 = 1;
							break;
						case HciModeChange.UserFieldsWrapper.CurrentModeEnum.InvalidCurrentModeValue:
							imageIndex2 = 1;
							break;
						}
						listViewItem3.ImageIndex = imageIndex2;
						listViewItem3.Checked = true;
						listViewItem3.SubItems.Add(item3.RSSI);
						listViewItem3.SubItems.Add(item3.MasterSlave);
					}
					else
					{
						listViewItem3.ImageIndex = 0;
						listViewItem3.Checked = false;
						listViewItem3.SubItems.Add(item3.RSSI);
					}
					bool flag3 = false;
					for (int k = LocalBTDeviceIndex + 1; k < LocalLEDeviceIndex; k++)
					{
						if (order)
						{
							if (string.Compare(btDeviceListView.Items[k].Text, item3.bdAddress) > 0)
							{
								btDeviceListView.Items.Insert(k, listViewItem3);
								flag3 = true;
								LocalLEDeviceIndex++;
								break;
							}
						}
						else if (string.Compare(btDeviceListView.Items[k].Text, item3.bdAddress) < 0)
						{
							btDeviceListView.Items.Insert(k, listViewItem3);
							flag3 = true;
							LocalLEDeviceIndex++;
							break;
						}
					}
					if (!flag3)
					{
						btDeviceListView.Items.Insert(LocalLEDeviceIndex, listViewItem3);
						LocalLEDeviceIndex++;
					}
				}
				int num2 = LocalLEDeviceIndex + 1;
				lock (BTLERemoteDeviceInfoList.leRemoteDeviceInfo)
				{
					foreach (BTLERemoteDeviceInfo.LERemoteDeviceInfo item4 in BTLERemoteDeviceInfoList.leRemoteDeviceInfo)
					{
						ListViewItem listViewItem4 = new ListViewItem
						{
							Text = item4.bdAddress
						};
						int connectionHandler4 = item4.connectionHandler;
						if (connectionHandler4 != 0 && connectionHandler4 != BTLERemoteDeviceInfoList.defaultConnectionHandle)
						{
							listViewItem4.ImageIndex = 1;
							listViewItem4.Checked = true;
							listViewItem4.SubItems.Add(item4.RSSI);
							listViewItem4.SubItems.Add(item4.MasterSlave);
						}
						else
						{
							listViewItem4.ImageIndex = 0;
							listViewItem4.Checked = false;
							listViewItem4.SubItems.Add(item4.RSSI);
						}
						bool flag4 = false;
						for (int l = LocalLEDeviceIndex + 1; l < btDeviceListView.Items.Count; l++)
						{
							if (order)
							{
								if (string.Compare(btDeviceListView.Items[l].Text, item4.bdAddress) > 0)
								{
									btDeviceListView.Items.Insert(l, listViewItem4);
									flag4 = true;
									num2++;
									break;
								}
							}
							else if (string.Compare(btDeviceListView.Items[l].Text, item4.bdAddress) < 0)
							{
								btDeviceListView.Items.Insert(l, listViewItem4);
								flag4 = true;
								num2++;
								break;
							}
						}
						if (!flag4)
						{
							btDeviceListView.Items.Insert(num2, listViewItem4);
							num2++;
						}
					}
				}
			}
			foreach (BTLERemoteDeviceInfo.BTRemoteDeviceInfo item5 in BTLERemoteDeviceInfoList.btRemoteDeviceInfo)
			{
				if (item5.scoConnections != null)
				{
					foreach (KeyValuePair<int, object> scoConnection in item5.scoConnections)
					{
						ListViewItem listViewItem5 = new ListViewItem();
						if (scoConnection.Value is SynchronousPacketTypeEnumCollection)
						{
							listViewItem5.Text = "SCO";
							listViewItem5.Tag = "SCO";
						}
						else
						{
							listViewItem5.Text = "ESCO";
							listViewItem5.Tag = "ESCO";
						}
						listViewItem5.SubItems.Add(scoConnection.Key.ToString("X4"));
						UpdateBTSCODeviceListView(item5.bdAddress, listViewItem5);
					}
				}
			}
		});
		btDeviceListView.EndInvoke(asyncResult);
	}

	private void InsertItemToListView(int itemIndex, ListViewItem deviceItem)
	{
		IAsyncResult asyncResult = btDeviceListView.BeginInvoke((MethodInvoker)delegate
		{
			btDeviceListView.Items.Insert(itemIndex, deviceItem);
		});
		btDeviceListView.EndInvoke(asyncResult);
	}

	private void RemoveItemAtIndexFromListView(int itemIndex)
	{
		IAsyncResult asyncResult = btDeviceListView.BeginInvoke((MethodInvoker)delegate
		{
			lock (btDeviceListView)
			{
				if (btDeviceListView.Items != null && itemIndex >= 0 && itemIndex < btDeviceListView.Items.Count)
				{
					btDeviceListView.Items.RemoveAt(itemIndex);
				}
			}
		});
		btDeviceListView.EndInvoke(asyncResult);
	}

	private void AddItemToListView(ListViewItem deviceItem)
	{
		IAsyncResult asyncResult = btDeviceListView.BeginInvoke((MethodInvoker)delegate
		{
			lock (btDeviceListView)
			{
				btDeviceListView.Items.Add(deviceItem);
			}
		});
		btDeviceListView.EndInvoke(asyncResult);
	}

	private void RemoveItemFromListView(ListViewItem deviceItem)
	{
		IAsyncResult asyncResult = btDeviceListView.BeginInvoke((MethodInvoker)delegate
		{
			lock (btDeviceListView)
			{
				btDeviceListView.Items.Remove(deviceItem);
			}
		});
		btDeviceListView.EndInvoke(asyncResult);
	}

	public Configuration GetConfiguration()
	{
		Configuration configuration = new Configuration();
		configuration.SetBool("EnableStartupCommand", btConfigSettings.EnableStartupCommand);
		configuration.SetBool("EnableStartupCommandLEOnly", btConfigSettings.EnableStartupCommandLEOnly);
		configuration.SetBool("EnableDefaultBTNVM", btConfigSettings.EnableDefaultBTNVM);
		configuration.SetBool("EnableDefaultBTPatch", btConfigSettings.EnableDefaultBTPatch);
		configuration.SetBool("EnablePacketDecode", btConfigSettings.EnablePacketDecode);
		configuration.SetBool("EnableDefaultBTScript", btConfigSettings.EnableDefaultBTScript);
		configuration.SetInt("ESCO_TransmitBandwidth", TransmitBandwidth);
		configuration.SetInt("ESCO_ReceiveBandwidth", ReceiveBandwidth);
		configuration.SetBool("ESCO_SlotMaxLatency", SlotMaxLatency);
		configuration.SetBool("ESCO_MsMaxLatency", MsMaxLatency);
		configuration.SetInt("ESCO_MaxLatency", MaxLatency);
		configuration.SetString("ESCO_VoiceSetting", VoiceSetting);
		configuration.SetBool("ESCO_NoRetrans", NoRestrans);
		configuration.SetBool("ESCO_OptimizePower", OptimizePower);
		configuration.SetBool("ESCO_OptimizeQuality", OptimizeQuality);
		configuration.SetBool("ESCO_DontCare", DontCare);
		configuration.SetBool("ESCO_HV1Enable", ESCOHV1enable);
		configuration.SetBool("ESCO_HV2Enable", ESCOHV2enable);
		configuration.SetBool("ESCO_HV3Enable", ESCOHV3enable);
		configuration.SetBool("ESCO_EV3Enable", ESCOEV3enable);
		configuration.SetBool("ESCO_EV4Enable", ESCOEV4enable);
		configuration.SetBool("ESCO_EV5Enable", ESCOEV5enable);
		configuration.SetBool("ESCO_2EV3Enable", ESCO2EV3enable);
		configuration.SetBool("ESCO_2EV5Enable", ESCO2EV5enable);
		configuration.SetBool("ESCO_3EV3Enable", ESCO3EV3enable);
		configuration.SetBool("ESCO_3EV5Enable", ESCO3EV5enable);
		configuration.SetInt("ESCO_TransmitBandwidth_enhSync", TransmitBandwidth_enhSync);
		configuration.SetInt("ESCO_ReceiveBandwidth_enhSync", ReceiveBandwidth_enhSync);
		configuration.SetBool("ESCO_SlotMaxLatency_enhSync", SlotMaxLatency_enhSync);
		configuration.SetBool("ESCO_MsMaxLatency_enhSync", MsMaxLatency_enhSync);
		configuration.SetInt("ESCO_MaxLatency_enhSync", MaxLatency_enhSync);
		configuration.SetBool("ESCO_NoRetrans_enhSync", NoRestrans_enhSync);
		configuration.SetBool("ESCO_OptimizePower_enhSync", OptimizePower_enhSync);
		configuration.SetBool("ESCO_OptimizeQuality_enhSync", OptimizeQuality_enhSync);
		configuration.SetBool("ESCO_DontCare_enhSync", DontCare_enhSync);
		configuration.SetBool("ESCO_HV1Enable_enhSync", ESCOHV1enable_enhSync);
		configuration.SetBool("ESCO_HV2Enable_enhSync", ESCOHV2enable_enhSync);
		configuration.SetBool("ESCO_HV3Enable_enhSync", ESCOHV3enable_enhSync);
		configuration.SetBool("ESCO_EV3Enable_enhSync", ESCOEV3enable_enhSync);
		configuration.SetBool("ESCO_EV4Enable_enhSync", ESCOEV4enable_enhSync);
		configuration.SetBool("ESCO_EV5Enable_enhSync", ESCOEV5enable_enhSync);
		configuration.SetBool("ESCO_2EV3Enable_enhSync", ESCO2EV3enable_enhSync);
		configuration.SetBool("ESCO_2EV5Enable_enhSync", ESCO2EV5enable_enhSync);
		configuration.SetBool("ESCO_3EV3Enable_enhSync", ESCO3EV3enable_enhSync);
		configuration.SetBool("ESCO_3EV5Enable_enhSync", ESCO3EV5enable_enhSync);
		configuration.SetInt("ESCO_InputDataPath", InputDataPath);
		configuration.SetInt("ESCO_OutputDataPath", OutputDataPath);
		configuration.SetLong("ESCO_TxRxCodingFormat", TxRxCodingFormat);
		configuration.SetInt("ESCO_PcmSamplePayload", PcmSamplePayload);
		configuration.SetInt("ESCO_IOCodedDataSize", IOCodedDataSize);
		configuration.SetInt("ESCO_IOPcmDataFormat", IOPcmDataFormat);
		configuration.SetLong("ESCO_IOCodingFormat", IOCodingFormat);
		configuration.SetBool("ESCO_UseEnhancedParameters", useEnhancedParameters);
		configuration.SetBool("DisplayEnhancedLog", ((ToolStripMenuItem)displayEnhLog).Checked);
		configuration.SetString("BTSnoop_LiveImportDLL", BTSnoopLiveImportDllFileName);
		configuration.SetString("BTSnoop_LiveImportIni", BTSnoopLiveImportIniFileName);
		configuration.SetInt("SimplePairing_IOCapability", (int)IOCapability);
		configuration.SetBool("SimplePairing_OOBPresent", OutOfBandDataPresent);
		configuration.SetBool("SimplePairing_ConfirmationReqReply", ConfirmationRequestReply);
		configuration.SetBool("SimplePairing_PassKeyReqReply", PasskeyRequestReply);
		configuration.SetBool("SimplePairing_AuthenticationRequirements", AuthenticationRequirements);
		configuration.SetString("OOB_C", OOBC);
		configuration.SetString("OOB_R", OOBR);
		configuration.SetBool("Connection_DM1Enable", DM1enable);
		configuration.SetBool("Connection_DM3Enable", DM3enable);
		configuration.SetBool("Connection_DM5Enable", DM5enable);
		configuration.SetBool("Connection_DH1Enable", DH1enable);
		configuration.SetBool("Connection_DH3Enable", DH3enable);
		configuration.SetBool("Connection_DH5Enable", DH5enable);
		configuration.SetBool("Connection_2DH1Enable", twoDH1enable);
		configuration.SetBool("Connection_2DH3Enable", twoDH3enable);
		configuration.SetBool("Connection_2DH5Enable", twoDH5enable);
		configuration.SetBool("Connection_3DH1Enable", threeDH1enable);
		configuration.SetBool("Connection_3DH3Enable", threeDH3enable);
		configuration.SetBool("Connection_3DH5Enable", threeDH5enable);
		configuration.SetBool("Connection_AllowRoleSwitch", allowRoleswitch);
		configuration.SetBool("Connection_LMPerformMSSwitch", lmPerformMSswitch);
		configuration.SetInt("Connection_ScanAfterConnection", (int)scanEnableLocalHost);
		configuration.SetBool("Connection_HV1", HV1enable);
		configuration.SetBool("Connection_HV2", HV2enable);
		configuration.SetBool("Connection_HV3", HV3enable);
		configuration.SetBool("Connection_AutoAcceptConnRequest", autoAcceptConnectionRequest);
		configuration.SetBool("Security_LevelDefaultEnable", LevelDefaultEnable);
		configuration.SetBool("Security_LevelAuthenticationEnable", LevelAuthenticationEnable);
		configuration.SetBool("Security_LevelPairingEnable", LevelPairingEnable);
		configuration.SetBool("Security_LinkKeyASCIIEnable", LinkKeyASCIIEnable);
		configuration.SetBool("Security_LinkKeyHexEnable", LinkKeyHexEnable);
		configuration.SetString("Security_LinkKey", LinkKey);
		configuration.SetBool("Security_PinCodeASCIIEnable", PinCodeASCIIEnable);
		configuration.SetBool("Security_PinCodeHexEnable", PinCodeHexEnable);
		configuration.SetString("Security_PinCode", PinCode);
		configuration.SetBool("LinkPolicy_MasterSlaveSwitchEnable", MasterSlaveSwitchEnable);
		configuration.SetBool("LinkPolicy_HoldModeEnable", HoldModeEnable);
		configuration.SetBool("LinkPolicy_SniffModeEnable", SniffModeEnable);
		configuration.SetBool("LinkPolicy_ParkModeEnable", ParkModeEnable);
		configuration.SetBool("LinkPolicy_MaintainCurrentPower", MaintainCurrentPower);
		configuration.SetBool("LinkPolicy_SuspendPageScanEnable", SuspendPageScanEnable);
		configuration.SetBool("LinkPolicy_SuspendInquiryScanEnable", SuspendInquiryScanEnable);
		configuration.SetBool("LinkPolicy_SuspendPeriodicInquiriesEnable", SuspendPeriodicInquiriesEnable);
		configuration.SetString("Inquiry_LAP", Lap);
		configuration.SetInt("Inquiry_Length", Length);
		configuration.SetInt("Inquiry_Responses", Responses);
		configuration.SetString("Inquiry_FilterBDA", AddressFilter[0] + AddressFilter[1] + AddressFilter[2] + AddressFilter[3] + AddressFilter[4] + AddressFilter[5]);
		configuration.SetBool("Inquiry_FECRequired", FECRequired);
		configuration.SetString("Inquiry_ExtendedInquiryResponse", ExtendedInquiryResponse);
		configuration.SetBool("Authentication_AuthenticationEnable", AuthenticationEnable);
		configuration.SetBool("Authentication_EncryptionEnable", EncryptionEnable);
		configuration.SetBool("Authentication_SimplePairingEnable", SimplePairingEnable);
		configuration.SetBool("Authentication_DebugModeEnable", DebugModeEnable);
		configuration.SetBool("Authentication_SecureConnectionsHostSupportEnable", SecureConnectionsHostSupportEnable);
		configuration.SetInt("ScanEnabled", (int)scanEnable);
		return configuration;
	}

	public void SetConfiguration(Configuration configuration)
	{
		btConfigSettings.EnableStartupCommand = configuration.GetBool("EnableStartupCommand", defaultValue: true);
		((ToolStripMenuItem)setStartupCommand).Checked = btConfigSettings.EnableStartupCommand;
		btConfigSettings.EnableStartupCommandLEOnly = configuration.GetBool("EnableStartupCommandLEOnly", defaultValue: false);
		((ToolStripMenuItem)setStartupCommandLEOnly).Checked = btConfigSettings.EnableStartupCommandLEOnly;
		btConfigSettings.EnableDefaultBTNVM = configuration.GetBool("EnableDefaultBTNVM", defaultValue: false);
		((ToolStripMenuItem)setDefaultNVM).Checked = btConfigSettings.EnableDefaultBTNVM;
		btConfigSettings.EnableDefaultBTPatch = configuration.GetBool("EnableDefaultBTPatch", defaultValue: false);
		((ToolStripMenuItem)setDefaultPatch).Checked = btConfigSettings.EnableDefaultBTPatch;
		btConfigSettings.EnablePacketDecode = configuration.GetBool("EnablePacketDecode", defaultValue: true);
		((ToolStripMenuItem)setDecodePacket).Checked = btConfigSettings.EnablePacketDecode;
		btConfigSettings.EnableDefaultBTScript = configuration.GetBool("EnableDefaultBTScript", defaultValue: false);
		((ToolStripMenuItem)setDefaultScript).Checked = btConfigSettings.EnableDefaultBTScript;
		TransmitBandwidth = configuration.GetInt("ESCO_TransmitBandwidth", 8000);
		ReceiveBandwidth = configuration.GetInt("ESCO_ReceiveBandwidth", 8000);
		SlotMaxLatency = configuration.GetBool("ESCO_SlotMaxLatency", defaultValue: false);
		MsMaxLatency = configuration.GetBool("ESCO_MsMaxLatency", defaultValue: true);
		MaxLatency = configuration.GetInt("ESCO_MaxLatency", 10);
		VoiceSetting = configuration.GetString("ESCO_VoiceSetting", "0060");
		NoRestrans = configuration.GetBool("ESCO_NoRetrans", defaultValue: false);
		OptimizePower = configuration.GetBool("ESCO_OptimizePower", defaultValue: true);
		OptimizeQuality = configuration.GetBool("ESCO_OptimizeQuality", defaultValue: false);
		DontCare = configuration.GetBool("ESCO_DontCare", defaultValue: false);
		ESCOHV1enable = configuration.GetBool("ESCO_HV1Enable", defaultValue: true);
		ESCOHV2enable = configuration.GetBool("ESCO_HV2Enable", defaultValue: true);
		ESCOHV3enable = configuration.GetBool("ESCO_HV3Enable", defaultValue: true);
		ESCOEV3enable = configuration.GetBool("ESCO_EV3Enable", defaultValue: true);
		ESCOEV4enable = configuration.GetBool("ESCO_EV4Enable", defaultValue: true);
		ESCOEV5enable = configuration.GetBool("ESCO_EV5Enable", defaultValue: true);
		ESCO2EV3enable = configuration.GetBool("ESCO_2EV3Enable", defaultValue: true);
		ESCO2EV5enable = configuration.GetBool("ESCO_2EV5Enable", defaultValue: true);
		ESCO3EV3enable = configuration.GetBool("ESCO_3EV3Enable", defaultValue: true);
		ESCO3EV5enable = configuration.GetBool("ESCO_3EV5Enable", defaultValue: true);
		TransmitBandwidth_enhSync = configuration.GetInt("ESCO_TransmitBandwidth_enhSync", 8000);
		ReceiveBandwidth_enhSync = configuration.GetInt("ESCO_ReceiveBandwidth_enhSync", 8000);
		SlotMaxLatency_enhSync = configuration.GetBool("ESCO_SlotMaxLatency_enhSync", defaultValue: false);
		MsMaxLatency_enhSync = configuration.GetBool("ESCO_MsMaxLatency_enhSync", defaultValue: true);
		MaxLatency_enhSync = configuration.GetInt("ESCO_MaxLatency_enhSync", 10);
		NoRestrans_enhSync = configuration.GetBool("ESCO_NoRetrans_enhSync", defaultValue: false);
		OptimizePower_enhSync = configuration.GetBool("ESCO_OptimizePower_enhSync", defaultValue: true);
		OptimizeQuality_enhSync = configuration.GetBool("ESCO_OptimizeQuality_enhSync", defaultValue: false);
		DontCare_enhSync = configuration.GetBool("ESCO_DontCare_enhSync", defaultValue: false);
		ESCOHV1enable_enhSync = configuration.GetBool("ESCO_HV1Enable_enhSync", defaultValue: true);
		ESCOHV2enable_enhSync = configuration.GetBool("ESCO_HV2Enable_enhSync", defaultValue: true);
		ESCOHV3enable_enhSync = configuration.GetBool("ESCO_HV3Enable_enhSync", defaultValue: true);
		ESCOEV3enable_enhSync = configuration.GetBool("ESCO_EV3Enable_enhSync", defaultValue: true);
		ESCOEV4enable_enhSync = configuration.GetBool("ESCO_EV4Enable_enhSync", defaultValue: true);
		ESCOEV5enable_enhSync = configuration.GetBool("ESCO_EV5Enable_enhSync", defaultValue: true);
		ESCO2EV3enable_enhSync = configuration.GetBool("ESCO_2EV3Enable_enhSync", defaultValue: true);
		ESCO2EV5enable_enhSync = configuration.GetBool("ESCO_2EV5Enable_enhSync", defaultValue: true);
		ESCO3EV3enable_enhSync = configuration.GetBool("ESCO_3EV3Enable_enhSync", defaultValue: true);
		ESCO3EV5enable_enhSync = configuration.GetBool("ESCO_3EV5Enable_enhSync", defaultValue: true);
		InputDataPath = configuration.GetInt("ESCO_InputDataPath", 0);
		OutputDataPath = configuration.GetInt("ESCO_OutputDataPath", 0);
		TxRxCodingFormat = configuration.GetLong("ESCO_TxRxCodingFormat", 0L);
		PcmSamplePayload = configuration.GetInt("ESCO_PcmSamplePayload", 3);
		IOCodedDataSize = configuration.GetInt("ESCO_IOCodedDataSize", 0);
		IOPcmDataFormat = configuration.GetInt("ESCO_IOPcmDataFormat", 0);
		IOCodingFormat = configuration.GetLong("ESCO_IOCodingFormat", 0L);
		useEnhancedParameters = configuration.GetBool("ESCO_UseEnhancedParameters", defaultValue: true);
		((ToolStripMenuItem)displayEnhLog).Checked = configuration.GetBool("DisplayEnhancedLog", defaultValue: true);
		btAPI.EnableDisplayEnhancedLog(((ToolStripMenuItem)displayEnhLog).Checked);
		BTSnoopLiveImportDllFileName = configuration.GetString("BTSnoop_LiveImportDLL", "");
		BTSnoopLiveImportIniFileName = configuration.GetString("BTSnoop_LiveImportIni", "");
		IOCapability = (IoCapabilityEnum)configuration.GetInt("SimplePairing_IOCapability", 0);
		OutOfBandDataPresent = configuration.GetBool("SimplePairing_OOBPresent", defaultValue: false);
		ConfirmationRequestReply = configuration.GetBool("SimplePairing_ConfirmationReqReply", defaultValue: true);
		PasskeyRequestReply = configuration.GetBool("SimplePairing_PassKeyReqReply", defaultValue: true);
		AuthenticationRequirements = configuration.GetBool("SimplePairing_AuthenticationRequirements", defaultValue: true);
		OOBC = configuration.GetString("OOB_C", "00000000000000000000000000000000");
		OOBR = configuration.GetString("OOB_R", "00000000000000000000000000000000");
		DM1enable = configuration.GetBool("Connection_DM1Enable", defaultValue: true);
		DM5enable = configuration.GetBool("Connection_DM3Enable", defaultValue: true);
		DM5enable = configuration.GetBool("Connection_DM5Enable", defaultValue: true);
		DH1enable = configuration.GetBool("Connection_DH1Enable", defaultValue: true);
		DH3enable = configuration.GetBool("Connection_DH3Enable", defaultValue: true);
		DH5enable = configuration.GetBool("Connection_DH5Enable", defaultValue: true);
		twoDH1enable = configuration.GetBool("Connection_2DH1Enable", defaultValue: true);
		twoDH3enable = configuration.GetBool("Connection_2DH3Enable", defaultValue: true);
		twoDH5enable = configuration.GetBool("Connection_2DH5Enable", defaultValue: true);
		threeDH1enable = configuration.GetBool("Connection_3DH1Enable", defaultValue: true);
		threeDH3enable = configuration.GetBool("Connection_3DH3Enable", defaultValue: true);
		threeDH5enable = configuration.GetBool("Connection_3DH5Enable", defaultValue: true);
		allowRoleswitch = configuration.GetBool("Connection_AllowRoleSwitch", defaultValue: true);
		lmPerformMSswitch = configuration.GetBool("Connection_LMPerformMSSwitch", defaultValue: false);
		scanEnableLocalHost = (WriteScanEnable.UserFieldsWrapper.ScanEnableEnum)configuration.GetInt("Connection_ScanAfterConnection", 3);
		HV1enable = configuration.GetBool("Connection_HV1", defaultValue: true);
		HV2enable = configuration.GetBool("Connection_HV2", defaultValue: true);
		HV3enable = configuration.GetBool("Connection_HV3", defaultValue: true);
		autoAcceptConnectionRequest = configuration.GetBool("Connection_AutoAcceptConnRequest", defaultValue: true);
		LevelDefaultEnable = configuration.GetBool("Security_LevelDefaultEnable", defaultValue: true);
		LevelAuthenticationEnable = configuration.GetBool("Security_LevelAuthenticationEnable", defaultValue: false);
		LevelPairingEnable = configuration.GetBool("Security_LevelPairingEnable", defaultValue: false);
		LinkKeyASCIIEnable = configuration.GetBool("Security_LinkKeyASCIIEnable", defaultValue: false);
		LinkKeyHexEnable = configuration.GetBool("Security_LinkKeyHexEnable", defaultValue: true);
		LinkKey = configuration.GetString("Security_LinkKey", "0102030405060708090A0B0C0D0E0F10");
		PinCodeASCIIEnable = configuration.GetBool("Security_PinCodeASCIIEnable", defaultValue: false);
		PinCodeHexEnable = configuration.GetBool("Security_PinCodeHexEnable", defaultValue: true);
		PinCode = configuration.GetString("Security_PinCode", "0102030405060708090A0B0C0D0E0F10");
		MasterSlaveSwitchEnable = configuration.GetBool("LinkPolicy_MasterSlaveSwitchEnable", defaultValue: true);
		HoldModeEnable = configuration.GetBool("LinkPolicy_HoldModeEnable", defaultValue: true);
		SniffModeEnable = configuration.GetBool("LinkPolicy_SniffModeEnable", defaultValue: true);
		ParkModeEnable = configuration.GetBool("LinkPolicy_ParkModeEnable", defaultValue: true);
		MaintainCurrentPower = configuration.GetBool("LinkPolicy_MaintainCurrentPower", defaultValue: false);
		SuspendPageScanEnable = configuration.GetBool("LinkPolicy_SuspendPageScanEnable", defaultValue: true);
		SuspendInquiryScanEnable = configuration.GetBool("LinkPolicy_SuspendInquiryScanEnable", defaultValue: true);
		SuspendPeriodicInquiriesEnable = configuration.GetBool("LinkPolicy_SuspendPeriodicInquiriesEnable", defaultValue: true);
		Lap = configuration.GetString("Inquiry_LAP", "9E8B33");
		Length = configuration.GetInt("Inquiry_Length", 5);
		Responses = configuration.GetInt("Inquiry_Responses", 40);
		string @string = configuration.GetString("Inquiry_FilterBDA", "FFFFFFFFFFFF");
		for (int i = 0; i < 6; i++)
		{
			AddressFilter[i] = @string.Substring(i * 2, 2);
		}
		FECRequired = configuration.GetBool("Inquiry_FECRequired", defaultValue: false);
		ExtendedInquiryResponse = configuration.GetString("Inquiry_ExtendedInquiryResponse", "0109");
		AuthenticationEnable = configuration.GetBool("Authentication_AuthenticationEnable", defaultValue: false);
		EncryptionEnable = configuration.GetBool("Authentication_EncryptionEnable", defaultValue: false);
		SimplePairingEnable = configuration.GetBool("Authentication_SimplePairingEnable", defaultValue: false);
		DebugModeEnable = configuration.GetBool("Authentication_DebugModeEnable", defaultValue: false);
		SecureConnectionsHostSupportEnable = configuration.GetBool("Authentication_SecureConnectionsHostSupportEnable", defaultValue: false);
		scanEnable = (WriteScanEnable.UserFieldsWrapper.ScanEnableEnum)configuration.GetInt("ScanEnabled", 3);
		initBTOptions();
	}
}
