Example #1
0
        internal static InterfaceRadio GetInterfaceRadio(Base.WlanClient client, Guid interfaceId)
        {
            if (interfaceId == Guid.Empty)
            {
                throw new ArgumentException(nameof(interfaceId));
            }

            using (var container = new DisposableContainer <Base.WlanClient>(client))
            {
                var capability = Base.GetInterfaceCapability(container.Content.Handle, interfaceId);
                var states     = Base.GetPhyRadioStates(container.Content.Handle, interfaceId);             // The underlying collection is array.

                if ((capability.interfaceType == WLAN_INTERFACE_TYPE.wlan_interface_type_invalid) ||
                    (capability.dwNumberOfSupportedPhys != states.Count()))
                {
                    return(null);
                }

                var radioSets = Enumerable.Zip(
                    capability.dot11PhyTypes,
                    states.OrderBy(x => x.dwPhyIndex),
                    (x, y) => new RadioSet(
                        type: PhyTypeConverter.Convert(x),
                        softwareOn: ConvertToNullableBoolean(y.dot11SoftwareRadioState),
                        hardwareOn: ConvertToNullableBoolean(y.dot11HardwareRadioState)));

                return(new InterfaceRadio(
                           id: interfaceId,
                           radioSets: radioSets));
            }
        }
Example #2
0
 internal static IEnumerable <InterfaceInfo> EnumerateInterfaces(Base.WlanClient client)
 {
     using (var container = new DisposableContainer <Base.WlanClient>(client))
     {
         return(Base.GetInterfaceInfoList(container.Content.Handle)
                .Select(x => new InterfaceInfo(x)));
     }
 }
Example #3
0
        internal static IEnumerable <ProfilePack> EnumerateProfiles(Base.WlanClient client)
        {
            using (var container = new DisposableContainer <Base.WlanClient>(client))
            {
                var interfaceInfoList = Base.GetInterfaceInfoList(container.Content.Handle);

                foreach (var interfaceInfo in interfaceInfoList.Select(x => new InterfaceInfo(x)))
                {
                    var interfaceIsConnected = (interfaceInfo.State == InterfaceState.Connected);

                    var availableNetworkList = Base.GetAvailableNetworkList(container.Content.Handle, interfaceInfo.Id)
                                               .Where(x => !string.IsNullOrWhiteSpace(x.strProfileName))
                                               .ToArray();

                    var connection = Base.GetConnectionAttributes(container.Content.Handle, interfaceInfo.Id);

                    var profileInfoList = Base.GetProfileInfoList(container.Content.Handle, interfaceInfo.Id);

                    int position = 0;

                    foreach (var profileInfo in profileInfoList)
                    {
                        var availableNetwork   = availableNetworkList.FirstOrDefault(x => string.Equals(x.strProfileName, profileInfo.strProfileName, StringComparison.Ordinal));
                        var signalQuality      = (int)availableNetwork.wlanSignalQuality;
                        var profileIsConnected = interfaceIsConnected && string.Equals(connection.strProfileName, profileInfo.strProfileName, StringComparison.Ordinal);

                        var profileXml = Base.GetProfile(container.Content.Handle, interfaceInfo.Id, profileInfo.strProfileName, out uint profileTypeFlag);
                        if (string.IsNullOrWhiteSpace(profileXml))
                        {
                            continue;
                        }

                        if (!ProfileTypeConverter.TryConvert(profileTypeFlag, out ProfileType profileType))
                        {
                            continue;
                        }

                        //Debug.WriteLine("Interface: {0}, Profile: {1}, Position: {2}, Signal: {3}, Connected: {4}",
                        //	interfaceInfo.Description,
                        //	profileInfo.strProfileName,
                        //	position,
                        //	signalQuality,
                        //	profileIsConnected);

                        yield return(new ProfilePack(
                                         name: profileInfo.strProfileName,
                                         interfaceInfo: interfaceInfo,
                                         profileType: profileType,
                                         profileXml: profileXml,
                                         position: position++,
                                         signalQuality: signalQuality,
                                         isConnected: profileIsConnected));
                    }
                }
            }
        }
Example #4
0
        internal static bool DisconnectNetwork(Base.WlanClient client, Guid interfaceId)
        {
            if (interfaceId == Guid.Empty)
            {
                throw new ArgumentException(nameof(interfaceId));
            }

            using (var container = new DisposableContainer <Base.WlanClient>(client))
            {
                return(Base.Disconnect(container.Content.Handle, interfaceId));
            }
        }
Example #5
0
        internal static bool TurnInterfaceRadio(Base.WlanClient client, Guid interfaceId, DOT11_RADIO_STATE radioState)
        {
            if (interfaceId == Guid.Empty)
            {
                throw new ArgumentException(nameof(interfaceId));
            }

            using (var container = new DisposableContainer <Base.WlanClient>(client))
            {
                var phyRadioState = new WLAN_PHY_RADIO_STATE {
                    dot11SoftwareRadioState = radioState,
                };

                return(Base.SetPhyRadioState(container.Content.Handle, interfaceId, phyRadioState));
            }
        }
Example #6
0
        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)));
            }
        }
Example #7
0
        internal static bool DeleteProfile(Base.WlanClient client, Guid interfaceId, string profileName)
        {
            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.DeleteProfile(container.Content.Handle, interfaceId, profileName));
            }
        }
Example #8
0
        internal static bool SetProfile(Base.WlanClient client, Guid interfaceId, ProfileType profileType, string profileXml, string profileSecurity, bool overwrite)
        {
            if (interfaceId == Guid.Empty)
            {
                throw new ArgumentException(nameof(interfaceId));
            }

            if (string.IsNullOrWhiteSpace(profileXml))
            {
                throw new ArgumentNullException(nameof(profileXml));
            }

            using (var container = new DisposableContainer <Base.WlanClient>(client))
            {
                var profileTypeFlag = ProfileTypeConverter.ConvertBack(profileType);

                return(Base.SetProfile(container.Content.Handle, interfaceId, profileTypeFlag, profileXml, profileSecurity, overwrite));
            }
        }
Example #9
0
        internal static IEnumerable <string> EnumerateProfileNames(Base.WlanClient client)
        {
            using (var container = new DisposableContainer <Base.WlanClient>(client))
            {
                var interfaceInfoList = Base.GetInterfaceInfoList(container.Content.Handle);

                foreach (var interfaceInfo in interfaceInfoList)
                {
                    var profileInfoList = Base.GetProfileInfoList(container.Content.Handle, interfaceInfo.InterfaceGuid);

                    foreach (var profileInfo in profileInfoList)
                    {
                        //Debug.WriteLine("Interface: {0}, Profile: {1}",
                        //	interfaceInfo.strInterfaceDescription,
                        //	profileInfo.strProfileName);

                        yield return(profileInfo.strProfileName);
                    }
                }
            }
        }
Example #10
0
        internal static bool SetProfilePosition(Base.WlanClient client, Guid interfaceId, string profileName, int position)
        {
            if (interfaceId == Guid.Empty)
            {
                throw new ArgumentException(nameof(interfaceId));
            }

            if (string.IsNullOrWhiteSpace(profileName))
            {
                throw new ArgumentNullException(nameof(profileName));
            }

            if (position < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(position));
            }

            using (var container = new DisposableContainer <Base.WlanClient>(client))
            {
                return(Base.SetProfilePosition(container.Content.Handle, interfaceId, profileName, (uint)position));
            }
        }
Example #11
0
        internal static IEnumerable <BssNetworkPack> EnumerateBssNetworks(Base.WlanClient client)
        {
            using (var container = new DisposableContainer <Base.WlanClient>(client))
            {
                var interfaceInfoList = Base.GetInterfaceInfoList(container.Content.Handle);

                foreach (var interfaceInfo in interfaceInfoList.Select(x => new InterfaceInfo(x)))
                {
                    var networkBssEntryList = Base.GetNetworkBssEntryList(container.Content.Handle, interfaceInfo.Id);

                    foreach (var networkBssEntry in networkBssEntryList)
                    {
                        if (!BssTypeConverter.TryConvert(networkBssEntry.dot11BssType, out BssType bssType))
                        {
                            continue;
                        }

                        //Debug.WriteLine("Interface: {0}, SSID: {1}, BSSID: {2}, Signal: {3} Link: {4}, Frequency: {5}",
                        //	interfaceInfo.Description,
                        //	networkBssEntry.dot11Ssid,
                        //	networkBssEntry.dot11Bssid,
                        //	networkBssEntry.lRssi,
                        //	networkBssEntry.uLinkQuality,
                        //	networkBssEntry.ulChCenterFrequency);

                        yield return(new BssNetworkPack(
                                         interfaceInfo: interfaceInfo,
                                         ssid: new NetworkIdentifier(networkBssEntry.dot11Ssid.ToBytes(), networkBssEntry.dot11Ssid.ToString()),
                                         bssType: bssType,
                                         bssid: new NetworkIdentifier(networkBssEntry.dot11Bssid.ToBytes(), networkBssEntry.dot11Bssid.ToString()),
                                         signalStrength: networkBssEntry.lRssi,
                                         linkQuality: (int)networkBssEntry.uLinkQuality,
                                         frequency: (int)networkBssEntry.ulChCenterFrequency,
                                         channel: DetectChannel(networkBssEntry.ulChCenterFrequency)));
                    }
                }
            }
        }
Example #12
0
        internal static IEnumerable <AvailableNetworkPack> EnumerateAvailableNetworks(Base.WlanClient client)
        {
            using (var container = new DisposableContainer <Base.WlanClient>(client))
            {
                var interfaceInfoList = Base.GetInterfaceInfoList(container.Content.Handle);

                foreach (var interfaceInfo in interfaceInfoList.Select(x => new InterfaceInfo(x)))
                {
                    var availableNetworkList = Base.GetAvailableNetworkList(container.Content.Handle, interfaceInfo.Id);

                    foreach (var availableNetwork in availableNetworkList)
                    {
                        if (!BssTypeConverter.TryConvert(availableNetwork.dot11BssType, out BssType bssType))
                        {
                            continue;
                        }

                        //Debug.WriteLine("Interface: {0}, SSID: {1}, Signal: {2}, Security: {3}",
                        //	interfaceInfo.Description,
                        //	availableNetwork.dot11Ssid,
                        //	availableNetwork.wlanSignalQuality,
                        //	availableNetwork.bSecurityEnabled);

                        yield return(new AvailableNetworkPack(
                                         interfaceInfo: interfaceInfo,
                                         ssid: new NetworkIdentifier(availableNetwork.dot11Ssid.ToBytes(), availableNetwork.dot11Ssid.ToString()),
                                         bssType: bssType,
                                         signalQuality: (int)availableNetwork.wlanSignalQuality,
                                         isSecurityEnabled: availableNetwork.bSecurityEnabled,
                                         profileName: availableNetwork.strProfileName));
                    }
                }
            }
        }
Example #13
0
        internal static IEnumerable <NetworkIdentifier> EnumerateConnectedNetworkSsids(Base.WlanClient client)
        {
            using (var container = new DisposableContainer <Base.WlanClient>(client))
            {
                var interfaceInfoList = Base.GetInterfaceInfoList(container.Content.Handle);

                foreach (var interfaceInfo in interfaceInfoList)
                {
                    var connection = Base.GetConnectionAttributes(container.Content.Handle, interfaceInfo.InterfaceGuid);
                    if (connection.isState != WLAN_INTERFACE_STATE.wlan_interface_state_connected)
                    {
                        continue;
                    }

                    var association = connection.wlanAssociationAttributes;

                    //Debug.WriteLine("Interface: {0}, SSID: {1}, BSSID: {2}, Signal: {3}",
                    //	interfaceInfo.strInterfaceDescription,
                    //	association.dot11Ssid,
                    //	association.dot11Bssid,
                    //	association.wlanSignalQuality);

                    yield return(new NetworkIdentifier(association.dot11Ssid.ToBytes(), association.dot11Ssid.ToString()));
                }
            }
        }
Example #14
0
        internal static IEnumerable <NetworkIdentifier> EnumerateAvailableNetworkSsids(Base.WlanClient client)
        {
            using (var container = new DisposableContainer <Base.WlanClient>(client))
            {
                var interfaceInfoList = Base.GetInterfaceInfoList(container.Content.Handle);

                foreach (var interfaceInfo in interfaceInfoList)
                {
                    var availableNetworkList = Base.GetAvailableNetworkList(container.Content.Handle, interfaceInfo.InterfaceGuid);

                    foreach (var availableNetwork in availableNetworkList)
                    {
                        //Debug.WriteLine("Interface: {0}, SSID: {1}, Signal: {2}",
                        //	interfaceInfo.strInterfaceDescription,
                        //	availableNetwork.dot11Ssid,
                        //	availableNetwork.wlanSignalQuality);

                        yield return(new NetworkIdentifier(availableNetwork.dot11Ssid.ToBytes(), availableNetwork.dot11Ssid.ToString()));
                    }
                }
            }
        }