Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions Source/NETworkManager.Converters/LvlChartsHeaderConverter.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
<ProjectReference Include="..\NETworkManager.Utilities\NETworkManager.Utilities.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="LiveCharts.Wpf" Version="0.9.7" />
<PackageReference Include="MahApps.Metro" Version="2.4.11" />

</ItemGroup>
</Project>
18 changes: 0 additions & 18 deletions Source/NETworkManager.Converters/WiFiDBMReverseConverter.cs

This file was deleted.

11 changes: 10 additions & 1 deletion Source/NETworkManager.Localization/Resources/Strings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Source/NETworkManager.Localization/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2274,6 +2274,9 @@ $$hostname$$ --&gt; Hostname</value>
<data name="Channel" xml:space="preserve">
<value>Channel</value>
</data>
<data name="ChannelWidth" xml:space="preserve">
<value>Channel width</value>
</data>
<data name="GHz2dot4" xml:space="preserve">
<value>2.4 GHz</value>
</data>
Expand Down
53 changes: 48 additions & 5 deletions Source/NETworkManager.Models/Network/WiFi.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using log4net;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Windows.Devices.WiFi;
using Windows.Networking.Connectivity;
using Windows.Security.Credentials;
using Microsoft.CodeAnalysis.Emit;
using NETworkManager.Models.Lookup;
Comment thread
BornToBeRoot marked this conversation as resolved.

namespace NETworkManager.Models.Network;
Expand Down Expand Up @@ -68,18 +70,25 @@ public static async Task<WiFiNetworkScanInfo> GetNetworksAsync(WiFiAdapter adapt
// Try to get the current connected Wi-Fi network of this network adapter
var (_, bssid) = TryGetConnectedNetworkFromWiFiAdapter(adapter.NetworkAdapter.NetworkAdapterId.ToString());

// The WinRT API does not expose the channel bandwidth, so it is read from the native
// BSS list (wlanapi.dll) and matched by BSSID below. Failures yield an empty map and we
// fall back to a heuristic per network.
var channelWidths = WlanApi.GetBssChannelWidths(adapter.NetworkAdapter.NetworkAdapterId);

var wifiNetworkInfos = new List<WiFiNetworkInfo>();

foreach (var availableNetwork in adapter.NetworkReport.AvailableNetworks)
{
var channelFrequencyInGigahertz = ConvertChannelFrequencyToGigahertz(availableNetwork.ChannelCenterFrequencyInKilohertz);
var radio = GetWiFiRadioFromChannelFrequency(channelFrequencyInGigahertz);

var wifiNetworkInfo = new WiFiNetworkInfo
{
AvailableNetwork = availableNetwork,
Radio = GetWiFiRadioFromChannelFrequency(channelFrequencyInGigahertz),
Radio = radio,
ChannelCenterFrequencyInGigahertz = channelFrequencyInGigahertz,
Channel = GetChannelFromChannelFrequency(channelFrequencyInGigahertz),
ChannelBandwidth = GetChannelBandwidth(channelWidths, availableNetwork.Bssid, radio, availableNetwork.PhyKind),
IsHidden = string.IsNullOrEmpty(availableNetwork.Ssid),
IsConnected = availableNetwork.Bssid.Equals(bssid, StringComparison.OrdinalIgnoreCase),
NetworkAuthenticationType = GetHumanReadableNetworkAuthenticationType(availableNetwork.SecuritySettings.NetworkAuthenticationType),
Expand Down Expand Up @@ -258,8 +267,8 @@ public static async Task<bool> IsWpsAvailable(WiFiAdapter adapter, WiFiAvailable
/// Get the Wi-Fi channel from channel frequency.
/// </summary>
/// <param name="gigahertz">Input like 2.422 or 5.240.</param>
/// <returns>WiFi channel like 3 or 48.</returns>
public static int GetChannelFromChannelFrequency(double gigahertz)
/// <returns>Wi-Fi channel like 3 or 48.</returns>
private static int GetChannelFromChannelFrequency(double gigahertz)
{
return gigahertz switch
{
Expand Down Expand Up @@ -313,7 +322,7 @@ public static int GetChannelFromChannelFrequency(double gigahertz)
/// </summary>
/// <param name="kilohertz">Frequency in kilohertz like 2422000 or 5240000.</param>
/// <returns>Frequency in gigahertz like 2.422 or 5.240.</returns>
public static double ConvertChannelFrequencyToGigahertz(int kilohertz)
private static double ConvertChannelFrequencyToGigahertz(int kilohertz)
{
return Convert.ToDouble(kilohertz) / 1000 / 1000;
}
Expand All @@ -323,7 +332,7 @@ public static double ConvertChannelFrequencyToGigahertz(int kilohertz)
/// </summary>
/// <param name="gigahertz">Frequency in gigahertz like 2.412 or 5.180.</param>
/// <returns>Radio like 2.4 GHz, 5 GHz, etc. as <see cref="WiFiRadio" />.</returns>
public static WiFiRadio GetWiFiRadioFromChannelFrequency(double gigahertz)
private static WiFiRadio GetWiFiRadioFromChannelFrequency(double gigahertz)
{
return gigahertz switch
{
Expand All @@ -334,6 +343,40 @@ public static WiFiRadio GetWiFiRadioFromChannelFrequency(double gigahertz)
};
}

/// <summary>
/// Determines the channel bandwidth (MHz) for a network. Prefers the value parsed from the
/// native BSS list (<see cref="WlanApi" />); if unavailable, falls back to a heuristic based
/// on the radio band and PHY kind, and finally to 20 MHz.
/// </summary>
private static int GetChannelBandwidth(IReadOnlyDictionary<string, int> channelWidths, string networkBssid,
WiFiRadio radio, WiFiPhyKind phyKind)
{
if (!string.IsNullOrEmpty(networkBssid) && channelWidths.TryGetValue(networkBssid, out var width) && width > 0)
return width;

return GetHeuristicChannelBandwidth(radio, phyKind);
}

/// <summary>
/// Estimates the channel bandwidth (MHz) from the radio band and PHY kind when the exact
/// value could not be read from the BSS list.
/// </summary>
private static int GetHeuristicChannelBandwidth(WiFiRadio radio, WiFiPhyKind phyKind)
{
return radio switch
{
WiFiRadio.GHz2dot4 => phyKind == WiFiPhyKind.HT ? 40 : 20,
WiFiRadio.GHz5 => phyKind switch
{
WiFiPhyKind.Vht or WiFiPhyKind.HE or WiFiPhyKind.Eht => 80,
WiFiPhyKind.HT => 40,
_ => 20
},
WiFiRadio.GHz6 => phyKind is WiFiPhyKind.HE or WiFiPhyKind.Eht ? 160 : 20,
_ => 20
};
}

/// <summary>
/// Get the human-readable network authentication type.
/// </summary>
Expand Down
5 changes: 5 additions & 0 deletions Source/NETworkManager.Models/Network/WiFiNetworkInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ public WiFiNetworkInfo()
/// </summary>
public int Channel { get; set; }

/// <summary>
/// The channel bandwidth in MHz (e.g. 20, 40, 80, 160). A value of 0 means unknown.
/// </summary>
public int ChannelBandwidth { get; set; }
Comment on lines +40 to +44

/// <summary>
/// Indicates if the Wi-Fi network Ssid is hidden.
/// </summary>
Expand Down
Loading
Loading