/// <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( InterfaceConnectionInfo interfaceInfo, NetworkIdentifier ssid, BssType bssType, int signalQuality, bool isSecurityEnabled, string profileName, bool isNetworkConnectable, string wlanNotConnectableReason, AuthenticationMethod authenticationMethod, EncryptionType encryptionType, IEnumerable <BssNetworkPack> bssNetworks) : base( interfaceInfo: interfaceInfo, ssid: ssid, bssType: bssType, signalQuality: signalQuality, isSecurityEnabled: isSecurityEnabled, profileName: profileName, isNetworkConnectable: isNetworkConnectable, wlanNotConnectableReason: wlanNotConnectableReason, authenticationMethod: authenticationMethod, encryptionType: encryptionType) { 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> /// 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> /// 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; }
NetworkType ConvertBssType(BssType type) { return(type switch { BssType.Infrastructure => NetworkType.Infrastructure, BssType.Independent => NetworkType.Adhoc, _ => NetworkType.Undefined });
public static DOT11_BSS_TYPE ConvertBack(BssType source) { switch (source) { case BssType.Infrastructure: return(DOT11_BSS_TYPE.dot11_BSS_type_infrastructure); case BssType.Independent: return(DOT11_BSS_TYPE.dot11_BSS_type_independent); } throw new ArgumentException(nameof(source)); }
internal WlanConnectionNotificationEventArgs(WlanInternNotificationData data, WlanInternNotificationConnectionData c) { Source = data.notificationSource; Code = data.NotificationCode; BssType = c.dot11BssType; ProfileName = c.profileName; ProfileXml = c.profileXml; SecurityEnabled = c.securityEnabled; ConnectionMode = c.ConnectionMode; ReasonCode = c.wlanReasonCode; Ssid = c.Dot11Ssid.GetSsid(); }
private static DOT11_BSS_TYPE ConvertFromBssType(BssType source) { switch (source) { case BssType.Infrastructure: return(DOT11_BSS_TYPE.dot11_BSS_type_infrastructure); case BssType.Independent: return(DOT11_BSS_TYPE.dot11_BSS_type_independent); default: return(DOT11_BSS_TYPE.dot11_BSS_type_any); } }
/// <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; }
public static bool TryConvert(DOT11_BSS_TYPE source, out BssType bssType) { switch (source) { case DOT11_BSS_TYPE.dot11_BSS_type_infrastructure: bssType = BssType.Infrastructure; return(true); case DOT11_BSS_TYPE.dot11_BSS_type_independent: bssType = BssType.Independent; return(true); } bssType = default(BssType); return(false); }
public static bool TryParse(string source, out BssType bssType) { if (string.Equals("ESS", source, StringComparison.OrdinalIgnoreCase)) { bssType = BssType.Infrastructure; return(true); } if (string.Equals("IBSS", source, StringComparison.OrdinalIgnoreCase)) { bssType = BssType.Independent; return(true); } bssType = default(BssType); return(false); }
/// <summary> /// Attempts to connect to the wireless LAN associated to a specified wireless profile. /// </summary> /// <param name="interfaceId">Interface ID</param> /// <param name="profileName">Profile name</param> /// <param name="bssType">BSS network type</param> /// <returns>True if successfully requested the connection. False if failed.</returns> public static bool ConnectNetwork(Guid interfaceId, string profileName, BssType bssType = BssType.Any) { if (interfaceId == Guid.Empty) { throw new ArgumentException(nameof(interfaceId)); } if (string.IsNullOrWhiteSpace(profileName)) { throw new ArgumentNullException(nameof(profileName)); } using (var client = new Base.WlanClient()) { return(Base.Connect(client.Handle, interfaceId, profileName, ConvertFromBssType(bssType))); } }
/// <summary> /// Converts enum BssType (ManagedNativeWifi) to internal type WiFiBssType. /// </summary> private WiFiBssType BssTypeConverter(BssType bssType) { WiFiBssType wiFiBssType = default(WiFiBssType);; switch (bssType) { case BssType.Infrastructure: wiFiBssType = WiFiBssType.Infrastructure; break; case BssType.Independent: wiFiBssType = WiFiBssType.Independent; break; } return(wiFiBssType); }
/// <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 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 AvailableNetworkPack( InterfaceConnectionInfo interfaceInfo, NetworkIdentifier ssid, BssType bssType, int signalQuality, bool isSecurityEnabled, string profileName, bool isNetworkConnectable, string wlanNotConnectableReason, AuthenticationMethod authenticationMethod, EncryptionType encryptionType) { this.Interface = interfaceInfo; this.Ssid = ssid; this.BssType = bssType; this.SignalQuality = signalQuality; this.IsSecurityEnabled = isSecurityEnabled; this.ProfileName = profileName; this.NetworkConnectable = isNetworkConnectable; this.WlanNotConnectableReason = wlanNotConnectableReason; this.Authentication = authenticationMethod; this.Encryption = encryptionType; }
internal static async Task <bool> ConnectNetworkAsync(Base.WlanNotificationClient client, Guid interfaceId, string profileName, BssType bssType, PhysicalAddress bssid, TimeSpan timeout, CancellationToken cancellationToken) { if (interfaceId == Guid.Empty) { throw new ArgumentException("The specified interface ID is invalid.", nameof(interfaceId)); } if (string.IsNullOrWhiteSpace(profileName)) { throw new ArgumentNullException(nameof(profileName)); } if (timeout <= TimeSpan.Zero) { throw new ArgumentOutOfRangeException(nameof(timeout), "The timeout duration must be positive."); } using var container = new DisposableContainer <Base.WlanNotificationClient>(client); var tcs = new TaskCompletionSource <bool>(); container.Content.NotificationReceived += (sender, data) => { if (data.InterfaceGuid != interfaceId) { return; } switch ((WLAN_NOTIFICATION_ACM)data.NotificationCode) { case WLAN_NOTIFICATION_ACM.wlan_notification_acm_connection_complete: case WLAN_NOTIFICATION_ACM.wlan_notification_acm_connection_attempt_fail: break; default: return; } var connectionNotificationData = Marshal.PtrToStructure <WLAN_CONNECTION_NOTIFICATION_DATA>(data.pData); if (connectionNotificationData.strProfileName != profileName) { return; } switch ((WLAN_NOTIFICATION_ACM)data.NotificationCode) { case WLAN_NOTIFICATION_ACM.wlan_notification_acm_connection_complete: Task.Run(() => tcs.TrySetResult(true)); break; case WLAN_NOTIFICATION_ACM.wlan_notification_acm_connection_attempt_fail: // This notification will not always mean that a connection has failed. // A connection consists of one or more connection attempts and this notification // may be received zero or more times before the connection completes. Task.Run(() => tcs.TrySetResult(false)); break; } }; bool result; if (bssid is not null) { var dot11MacAddress = new DOT11_MAC_ADDRESS { ucDot11MacAddress = bssid.GetAddressBytes() }; result = Base.Connect(container.Content.Handle, interfaceId, profileName, BssTypeConverter.ConvertBack(bssType), dot11MacAddress); } else { result = Base.Connect(container.Content.Handle, interfaceId, profileName, BssTypeConverter.ConvertBack(bssType)); } if (!result) { tcs.SetResult(false); } using (cancellationToken.Register(() => tcs.TrySetCanceled())) { var connectTask = tcs.Task; var completedTask = await Task.WhenAny(connectTask, Task.Delay(timeout, cancellationToken)); return((completedTask == connectTask) && connectTask.IsCompleted && connectTask.Result); } }
/// <summary> /// Asynchronously attempts to connect to the wireless LAN associated to a specified wireless profile. /// </summary> /// <param name="interfaceId">Interface ID</param> /// <param name="profileName">Profile name</param> /// <param name="bssType">BSS network type</param> /// <param name="bssid">BSSID of the network</param> /// <param name="timeout">Timeout duration</param> /// <param name="cancellationToken">Cancellation token</param> /// <returns>True if successfully connected. False if failed or timed out.</returns> public static Task <bool> ConnectNetworkAsync(Guid interfaceId, string profileName, BssType bssType, PhysicalAddress bssid, TimeSpan timeout, CancellationToken cancellationToken) { return(ConnectNetworkAsync(null, interfaceId, profileName, bssType, bssid, timeout, cancellationToken)); }
/// <summary> /// Asynchronously attempts to connect to the wireless LAN associated to a specified wireless profile. /// </summary> /// <param name="interfaceId">Interface ID</param> /// <param name="profileName">Profile name</param> /// <param name="bssType">BSS network type</param> /// <param name="timeout">Timeout duration</param> /// <returns>True if successfully connected. False if failed or timed out.</returns> public static Task <bool> ConnectNetworkAsync(Guid interfaceId, string profileName, BssType bssType, TimeSpan timeout) { return(ConnectNetworkAsync(null, interfaceId, profileName, bssType, null, timeout, CancellationToken.None)); }
internal static bool ConnectNetwork(Base.WlanClient client, Guid interfaceId, string profileName, BssType bssType, PhysicalAddress bssid = null) { if (interfaceId == Guid.Empty) { throw new ArgumentException("The specified interface ID is invalid.", nameof(interfaceId)); } if (string.IsNullOrWhiteSpace(profileName)) { throw new ArgumentNullException(nameof(profileName)); } using var container = new DisposableContainer <Base.WlanClient>(client); if (bssid is not null) { var dot11MacAddress = new DOT11_MAC_ADDRESS { ucDot11MacAddress = bssid.GetAddressBytes() }; return(Base.Connect(container.Content.Handle, interfaceId, profileName, BssTypeConverter.ConvertBack(bssType), dot11MacAddress)); } else { return(Base.Connect(container.Content.Handle, interfaceId, profileName, BssTypeConverter.ConvertBack(bssType))); } }
/// <summary> /// Attempts to connect to the wireless LAN associated to a specified wireless profile. /// </summary> /// <param name="interfaceId">Interface ID</param> /// <param name="profileName">Profile name</param> /// <param name="bssType">BSS network type</param> /// <param name="bssid">BSSID of the network</param> /// <returns>True if successfully requested the connection. False if failed.</returns> public static bool ConnectNetwork(Guid interfaceId, string profileName, BssType bssType, PhysicalAddress bssid = null) { return(ConnectNetwork(null, interfaceId, profileName, bssType, bssid)); }
/// <summary> /// Attempt to connect to a wireless LAN. /// </summary> /// <param name="profileName">Profile name</param> /// <param name="interfaceGuid">Interface GUID</param> /// <param name="bssType">BSS type</param> /// <param name="timeoutDuration">Timeout duration</param> /// <returns>True if succeeded. False if failed or timed out.</returns> public static async Task<bool> ConnectAsync(string profileName, Guid interfaceGuid, BssType bssType, TimeSpan timeoutDuration) { if (string.IsNullOrWhiteSpace(profileName)) return false; if (interfaceGuid == default(Guid)) return false; using (var client = new WlanClient()) { var tcs = new TaskCompletionSource<bool>(); Action<IntPtr, IntPtr> callback = (data, context) => { var notificationData = Marshal.PtrToStructure<WLAN_NOTIFICATION_DATA>(data); if (notificationData.NotificationSource != WLAN_NOTIFICATION_SOURCE_ACM) return; //Debug.WriteLine("Callback: {0}", (WLAN_NOTIFICATION_ACM)notificationData.NotificationCode); switch (notificationData.NotificationCode) { case (uint)WLAN_NOTIFICATION_ACM.wlan_notification_acm_connection_complete: Task.Run(() => tcs.SetResult(true)); break; case (uint)WLAN_NOTIFICATION_ACM.wlan_notification_acm_connection_attempt_fail: Task.Run(() => tcs.SetResult(false)); break; } }; RegisterNotification(client.Handle, WLAN_NOTIFICATION_SOURCE_ACM, callback); var result = Connect(client.Handle, interfaceGuid, profileName, ConvertFromBssType(bssType)); if (!result) tcs.SetResult(false); var connectTask = tcs.Task; var completedTask = await Task.WhenAny(connectTask, Task.Delay(timeoutDuration)); return (completedTask == connectTask) ? connectTask.Result : false; } }
/// <summary> /// Attempts to connect to the wireless LAN associated to a specified wireless profile. /// </summary> public bool ConnectNetwork(Guid interfaceId, string profileName, BssType bssType) => NativeWifi.ConnectNetwork(_client, interfaceId, profileName, bssType);
internal static bool ConnectNetwork(Base.WlanClient client, Guid interfaceId, string profileName, BssType bssType) { if (interfaceId == Guid.Empty) { throw new ArgumentException(nameof(interfaceId)); } if (string.IsNullOrWhiteSpace(profileName)) { throw new ArgumentNullException(nameof(profileName)); } using (var container = new DisposableContainer <Base.WlanClient>(client)) { return(Base.Connect(container.Content.Handle, interfaceId, profileName, BssTypeConverter.ConvertBack(bssType))); } }
/// <summary> /// Attempts to connect to the wireless LAN associated to a specified wireless profile. /// </summary> /// <param name="interfaceId">Interface ID</param> /// <param name="profileName">Profile name</param> /// <param name="bssType">BSS network type</param> /// <returns>True if successfully requested the connection. False if failed.</returns> public static bool ConnectNetwork(Guid interfaceId, string profileName, BssType bssType) { return(ConnectNetwork(null, interfaceId, profileName, bssType)); }
public ProfilePack( string name, Guid interfaceGuid, string interfaceDescription, string ssid, BssType bssType, string authentication, string encryption, int position, bool isAutomatic, int signal, bool isConnected) { this.Name = name; this.InterfaceGuid = interfaceGuid; this.InterfaceDescription = interfaceDescription; this.Ssid = ssid; this.BssType = bssType; this.Authentication = authentication; this.Encryption = encryption; this.Position = position; this.IsAutomatic = isAutomatic; this.Signal = signal; this.IsConnected = isConnected; }
public NetworkPack(Guid interfaceGuid, string ssid, BssType bssType, int signal, string profileName) { this.InterfaceGuid = interfaceGuid; this.Ssid = ssid; this.BssType = bssType; this.Signal = signal; this.ProfileName = profileName; }
/// <summary> /// Asynchronously attempts to connect to the wireless LAN associated to a specified wireless profile. /// </summary> /// <param name="interfaceId">Interface ID</param> /// <param name="profileName">Profile name</param> /// <param name="bssType">BSS network type</param> /// <param name="timeout">Timeout duration</param> /// <param name="cancellationToken">Cancellation token</param> /// <returns>True if successfully connected. False if failed or timed out.</returns> public static async Task <bool> ConnectNetworkAsync(Guid interfaceId, string profileName, BssType bssType, TimeSpan timeout, CancellationToken cancellationToken) { if (interfaceId == Guid.Empty) { throw new ArgumentException(nameof(interfaceId)); } if (string.IsNullOrWhiteSpace(profileName)) { throw new ArgumentNullException(nameof(profileName)); } if (timeout < TimeSpan.Zero) { throw new ArgumentException(nameof(timeout)); } using (var client = new Base.WlanClient()) { var tcs = new TaskCompletionSource <bool>(); Action <IntPtr, IntPtr> callback = (data, context) => { var notificationData = Marshal.PtrToStructure <WLAN_NOTIFICATION_DATA>(data); if (notificationData.NotificationSource != WLAN_NOTIFICATION_SOURCE_ACM) { return; } Debug.WriteLine("Callback: {0}", (WLAN_NOTIFICATION_ACM)notificationData.NotificationCode); switch (notificationData.NotificationCode) { case (uint)WLAN_NOTIFICATION_ACM.wlan_notification_acm_connection_complete: Task.Run(() => tcs.SetResult(true)); break; case (uint)WLAN_NOTIFICATION_ACM.wlan_notification_acm_connection_attempt_fail: Task.Run(() => tcs.SetResult(false)); break; } }; Base.RegisterNotification(client.Handle, WLAN_NOTIFICATION_SOURCE_ACM, callback); var result = Base.Connect(client.Handle, interfaceId, profileName, ConvertFromBssType(bssType)); if (!result) { tcs.SetResult(false); } var connectTask = tcs.Task; var completedTask = await Task.WhenAny(connectTask, Task.Delay(timeout, cancellationToken)); return((completedTask == connectTask) && connectTask.Result); } }
public BytecodeBssSymbol(string?name, BssType type, ushort length) { this.name = name; this.type = type; this.length = length; }
/// <summary> /// Asynchronously attempts to connect to the wireless LAN associated to a specified wireless profile. /// </summary> public Task <bool> ConnectNetworkAsync(Guid interfaceId, string profileName, BssType bssType, TimeSpan timeout, CancellationToken cancellationToken) => NativeWifi.ConnectNetworkAsync(_client, interfaceId, profileName, bssType, timeout, cancellationToken);
private static DOT11_BSS_TYPE ConvertFromBssType(BssType source) { switch (source) { case BssType.Infrastructure: return DOT11_BSS_TYPE.dot11_BSS_type_infrastructure; case BssType.Independent: return DOT11_BSS_TYPE.dot11_BSS_type_independent; default: return DOT11_BSS_TYPE.dot11_BSS_type_any; } }