/// <summary> /// Constructor /// </summary> public AvailableNetworkGroupPack( InterfaceInfo interfaceInfo, NetworkIdentifier ssid, BssType bssType, int signalQuality, bool isSecurityEnabled, string profileName, AuthenticationAlgorithm authenticationAlgorithm, CipherAlgorithm cipherAlgorithm, IEnumerable <BssNetworkPack> bssNetworks) : base( interfaceInfo: interfaceInfo, ssid: ssid, bssType: bssType, signalQuality: signalQuality, isSecurityEnabled: isSecurityEnabled, profileName: profileName, authenticationAlgorithm: authenticationAlgorithm, cipherAlgorithm: cipherAlgorithm) { this.BssNetworks = Array.AsReadOnly(bssNetworks?.OrderByDescending(x => x.LinkQuality).ToArray() ?? new BssNetworkPack[0]); if (!this.BssNetworks.Any()) { return; } var highestLinkQualityNetwork = this.BssNetworks.First(); LinkQuality = highestLinkQualityNetwork.LinkQuality; Frequency = highestLinkQualityNetwork.Frequency; Band = highestLinkQualityNetwork.Band; Channel = highestLinkQualityNetwork.Channel; }
private static bool TryConvertBssNetwork(InterfaceInfo interfaceInfo, WLAN_BSS_ENTRY bssEntry, out BssNetworkPack bssNetwork) { bssNetwork = null; if (!BssTypeConverter.TryConvert(bssEntry.dot11BssType, out BssType bssType)) { return(false); } if (!TryDetectBandChannel(bssEntry.ulChCenterFrequency, out float band, out int channel)) { return(false); } bssNetwork = new BssNetworkPack( interfaceInfo: interfaceInfo, ssid: new NetworkIdentifier(bssEntry.dot11Ssid), bssType: bssType, bssid: new NetworkIdentifier(bssEntry.dot11Bssid), signalStrength: bssEntry.lRssi, linkQuality: (int)bssEntry.uLinkQuality, frequency: (int)bssEntry.ulChCenterFrequency, band: band, channel: channel); return(true); }
/// <summary> /// Constructor /// </summary> public ProfilePack( string name, InterfaceInfo interfaceInfo, ProfileType profileType, string profileXml, NetworkIdentifier ssid, BssType bssType, string authentication, string encryption, int signalQuality, int position, bool isAutomatic, bool isConnected) { this.Name = name; this.Interface = interfaceInfo; this.ProfileType = profileType; this.ProfileXml = profileXml; this.Ssid = ssid; this.BssType = bssType; this.Authentication = authentication; this.Encryption = encryption; this.SignalQuality = signalQuality; this.Position = position; this.IsAutomatic = isAutomatic; this.IsConnected = isConnected; }
/// <summary> /// Constructor /// </summary> public AvailableNetworkGroupPack( InterfaceInfo interfaceInfo, NetworkIdentifier ssid, BssType bssType, int signalQuality, bool isSecurityEnabled, string profileName, IEnumerable <BssNetworkPack> bssNetworks) : base( interfaceInfo: interfaceInfo, ssid: ssid, bssType: bssType, signalQuality: signalQuality, isSecurityEnabled: isSecurityEnabled, profileName: profileName) { this._bssNetworks = bssNetworks.OrderByDescending(x => x.LinkQuality).ToArray(); var highestLinkQualityNetwork = _bssNetworks.FirstOrDefault(); if (highestLinkQualityNetwork != null) { LinkQuality = highestLinkQualityNetwork.LinkQuality; Frequency = highestLinkQualityNetwork.Frequency; Band = highestLinkQualityNetwork.Band; Channel = highestLinkQualityNetwork.Channel; } }
/// <summary> /// Gets a specified wireless profile information. /// </summary> /// <param name="clientHandle">Client handle</param> /// <param name="interfaceInfo">Interface information</param> /// <param name="profileName">Profile name</param> /// <param name="signalQuality">Signal quality</param> /// <param name="position">Position in preference order</param> /// <param name="isConnected">Whether this profile is connected to a wireless LAN</param> /// <returns>Wireless profile information</returns> /// <remarks> /// For profile elements, see /// https://msdn.microsoft.com/en-us/library/windows/desktop/ms707381.aspx /// </remarks> private static ProfilePack GetProfile(SafeClientHandle clientHandle, InterfaceInfo interfaceInfo, string profileName, int signalQuality, int position, bool isConnected) { ProfileType profileType; var source = Base.GetProfile(clientHandle, interfaceInfo.Id, profileName, out profileType); if (string.IsNullOrWhiteSpace(source)) { return(null); } XElement rootXml; using (var sr = new StringReader(source)) rootXml = XElement.Load(sr); var ns = rootXml.Name.Namespace; var ssidXml = rootXml.Descendants(ns + "SSID").FirstOrDefault(); var ssidHexadecimalString = ssidXml?.Descendants(ns + "hex").FirstOrDefault()?.Value; var ssidBytes = ConvertFromHexadecimalStringToBytes(ssidHexadecimalString); var ssidString = ssidXml?.Descendants(ns + "name").FirstOrDefault()?.Value; var connectionTypeXml = rootXml.Descendants(ns + "connectionType").FirstOrDefault(); var bssType = ConvertToBssType(connectionTypeXml?.Value); var connectionModeXml = rootXml.Descendants(ns + "connectionMode").FirstOrDefault(); var isAutomatic = (connectionModeXml?.Value.Equals("auto", StringComparison.OrdinalIgnoreCase)).GetValueOrDefault(); var authenticationXml = rootXml.Descendants(ns + "authentication").FirstOrDefault(); var authentication = authenticationXml?.Value; var encryptionXml = rootXml.Descendants(ns + "encryption").FirstOrDefault(); var encryption = encryptionXml?.Value; //Debug.WriteLine("SSID: {0}, BssType: {1}, Authentication: {2}, Encryption: {3}, Automatic: {4}", // ssidString, // bssType, // authentication, // encryption, // isAutomatic); return(new ProfilePack( name: profileName, interfaceInfo: interfaceInfo, profileType: profileType, profileXml: source, ssid: new NetworkIdentifier(ssidBytes, ssidString), bssType: bssType, authentication: authentication, encryption: encryption, signalQuality: signalQuality, position: position, isAutomatic: isAutomatic, isConnected: isConnected)); }
/// <summary> /// Constructor /// </summary> public ProfilePack( string name, InterfaceInfo interfaceInfo, ProfileType profileType, string profileXml, int position) { this.Name = name; this.Interface = interfaceInfo; this.ProfileType = profileType; Document = new ProfileDocument(profileXml); this.Position = position; }
/// <summary> /// Constructor /// </summary> public AvailableNetworkPack( InterfaceInfo interfaceInfo, NetworkIdentifier ssid, BssType bssType, int signalQuality, bool isSecurityEnabled, string profileName) { this.Interface = interfaceInfo; this.Ssid = ssid; this.BssType = bssType; this.SignalQuality = signalQuality; this.IsSecurityEnabled = isSecurityEnabled; this.ProfileName = profileName; }
/// <summary> /// Constructor /// </summary> public AvailableNetworkPack( InterfaceInfo interfaceInfo, NetworkIdentifier ssid, BssType bssType, int signalQuality, bool isSecurityEnabled, string profileName, AuthenticationAlgorithm authenticationAlgorithm, CipherAlgorithm cipherAlgorithm) { this.Interface = interfaceInfo; this.Ssid = ssid; this.BssType = bssType; this.SignalQuality = signalQuality; this.IsSecurityEnabled = isSecurityEnabled; this.ProfileName = profileName; this.AuthenticationAlgorithm = authenticationAlgorithm; this.CipherAlgorithm = cipherAlgorithm; }
/// <summary> /// Constructor /// </summary> public BssNetworkPack( InterfaceInfo interfaceInfo, NetworkIdentifier ssid, BssType bssType, NetworkIdentifier bssid, int signalStrength, int linkQuality, int frequency, int channel) { this.Interface = interfaceInfo; this.Ssid = ssid; this.BssType = bssType; this.Bssid = bssid; this.SignalStrength = signalStrength; this.LinkQuality = linkQuality; this.Frequency = frequency; this.Channel = channel; }
/// <summary> /// Constructor /// </summary> public ProfilePack( string name, InterfaceInfo interfaceInfo, ProfileType profileType, string profileXml, int position, bool isRadioOn, int signalQuality, bool isConnected) { this.Name = name; this.Interface = interfaceInfo; this.ProfileType = profileType; Document = new ProfileDocument(profileXml); this.Position = position; this.IsRadioOn = isRadioOn; this.SignalQuality = signalQuality; this.IsConnected = isConnected; }
private static IEnumerable <AvailableNetworkGroupPack> EnumerateAvailableNetworkGroups(Base.WlanClient client, InterfaceInfo interfaceInfo) { foreach (var availableNetwork in Base.GetAvailableNetworkList(client.Handle, interfaceInfo.Id)) { if (!BssTypeConverter.TryConvert(availableNetwork.dot11BssType, out BssType bssType)) { continue; } if (!AuthenticationAlgorithmConverter.TryConvert(availableNetwork.dot11DefaultAuthAlgorithm, out AuthenticationAlgorithm authenticationAlgorithm)) { continue; } if (!CipherAlgorithmConverter.TryConvert(availableNetwork.dot11DefaultCipherAlgorithm, out CipherAlgorithm cipherAlgorithm)) { continue; } var bssNetworks = Base.GetNetworkBssEntryList(client.Handle, interfaceInfo.Id, availableNetwork.dot11Ssid, availableNetwork.dot11BssType, availableNetwork.bSecurityEnabled) .Select(x => TryConvertBssNetwork(interfaceInfo, x, out BssNetworkPack bssNetwork) ? bssNetwork : null) .Where(x => x is not null); yield return(new AvailableNetworkGroupPack( interfaceInfo: interfaceInfo, ssid: new NetworkIdentifier(availableNetwork.dot11Ssid), bssType: bssType, signalQuality: (int)availableNetwork.wlanSignalQuality, isSecurityEnabled: availableNetwork.bSecurityEnabled, profileName: availableNetwork.strProfileName, authenticationAlgorithm: authenticationAlgorithm, cipherAlgorithm: cipherAlgorithm, bssNetworks: bssNetworks)); } }