Exemple #1
0
        public void UpdateSettings(string ssid, string secondaryKey, bool isSecondaryKeyPersistent)
        {
            CheckElevationRequired();

            WlanHostedNetworkConnectionSettings settings = new WlanHostedNetworkConnectionSettings();

            settings.SSID             = ssid.ToDot11SSID();
            settings.MaxNumberOfPeers = _maxNumberOfPeers;

            IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(settings));

            Marshal.StructureToPtr(settings, ptr, false);
            NativeMethods.WlanHostedNetworkSetProperty(_clientHandle, WlanHostedNetworkOpCode.ConnectionSettings, (uint)Marshal.SizeOf(settings), ptr, out _reason, IntPtr.Zero);
            NativeMethods.WlanFreeMemory(ptr);

            NativeMethods.WlanHostedNetworkSetSecondaryKey(_clientHandle, (uint)(secondaryKey.Length + 1), secondaryKey, true, isSecondaryKeyPersistent, out _reason, IntPtr.Zero);
        }
        public void UpdateSettings(string ssid, string secondaryKey, bool isSecondaryKeyPersistent)
        {
            CheckElevationRequired();

            WlanHostedNetworkConnectionSettings settings = new WlanHostedNetworkConnectionSettings();
            settings.SSID = ssid.ToDot11SSID();
            settings.MaxNumberOfPeers = _maxNumberOfPeers;

            IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(settings));
            Marshal.StructureToPtr(settings, ptr, false);
            NativeMethods.WlanHostedNetworkSetProperty(_clientHandle, WlanHostedNetworkOpCode.ConnectionSettings, (uint)Marshal.SizeOf(settings), ptr, out _reason, IntPtr.Zero);
            NativeMethods.WlanFreeMemory(ptr);

            NativeMethods.WlanHostedNetworkSetSecondaryKey(_clientHandle, (uint)(secondaryKey.Length + 1), secondaryKey, true, isSecondaryKeyPersistent, out _reason, IntPtr.Zero);
        }
Exemple #3
0
        public void SetWlanHostedNetworkInfo()
        {
            try
            {
                IntPtr ptr = IntPtr.Zero;

                uint size;
                WlanOpCodeValueType opcode;

                ptr = IntPtr.Zero;
                NativeMethods.WlanHostedNetworkQueryProperty(_clientHandle, WlanHostedNetworkOpCode.Enable, out size, out ptr, out opcode, IntPtr.Zero);
                bool isEnabled = (bool)Marshal.PtrToStructure(ptr, typeof(bool));
                NativeMethods.WlanFreeMemory(ptr);

                ptr = IntPtr.Zero;
                NativeMethods.WlanHostedNetworkQueryProperty(_clientHandle, WlanHostedNetworkOpCode.ConnectionSettings, out size, out ptr, out opcode, IntPtr.Zero);
                WlanHostedNetworkConnectionSettings settings = (WlanHostedNetworkConnectionSettings)Marshal.PtrToStructure(ptr, typeof(WlanHostedNetworkConnectionSettings));
                NativeMethods.WlanFreeMemory(ptr);
                this.SSID         = settings.SSID.Value;
                _maxNumberOfPeers = settings.MaxNumberOfPeers;

                uint   length;
                string key;
                bool   isPassPhrase;
                bool   isPersistent;
                NativeMethods.WlanHostedNetworkQuerySecondaryKey(_clientHandle, out length, out key, out isPassPhrase, out isPersistent, out _reason, IntPtr.Zero);
                this.SecondaryKey             = key;
                this.IsSecondaryKeyPersistent = isPersistent;

                IntPtr pPtr = IntPtr.Zero;
                NativeMethods.WlanHostedNetworkQueryStatus(_clientHandle, out pPtr, IntPtr.Zero);
                ptr = new IntPtr(pPtr.ToInt32());
                WlanHostedNetworkStatus status = (WlanHostedNetworkStatus)Marshal.PtrToStructure(ptr, typeof(WlanHostedNetworkStatus));
                NativeMethods.WlanFreeMemory(ptr);
                this.IsStarted = (status.State == WlanHostedNetworkState.Active);
                string radioType = string.Empty;
                switch (status.PhyType)
                {
                case Dot11PhyType.ERP:
                case Dot11PhyType.HRDSSS:
                    radioType = "802.11g";
                    break;

                case Dot11PhyType.OFDM:
                case Dot11PhyType.IRBaseband:
                    radioType = "802.11a";
                    break;

                case Dot11PhyType.HT:
                    radioType = "802.11n";
                    break;

                default:
                    radioType = "Unknown";
                    break;
                }

                StringBuilder sb = new StringBuilder();
                sb.AppendFormat("Hosted network settings\r\n");
                sb.AppendFormat("----------------------------\r\n");
                sb.AppendFormat("Mode\t\t\t: {0}\r\n", (isEnabled ? "Allowed" : "Disallowed"));
                sb.AppendFormat("SSID\t\t\t: {0}\r\n", this.SSID);
                sb.AppendFormat("Key\t\t\t: {0}\r\n", this.SecondaryKey);
                sb.AppendFormat("Authentication\t: WPA2-Personal\r\n");
                sb.AppendFormat("\r\n");
                sb.AppendFormat("Hosted network status\r\n");
                sb.AppendFormat("----------------------------\r\n");
                sb.AppendFormat("Status\t\t\t: {0}\r\n", (this.IsStarted ? "Started" : "Not started"));
                if (this.IsStarted)
                {
                    sb.AppendFormat("Radio type\t\t: {0}\r\n", radioType);
                    sb.AppendFormat("Channel\t\t: {0}\r\n", status.Channel);
                    sb.AppendFormat("BSSID\t\t\t: {0}\r\n", status.BSSID.ToMacAddressString());
                    sb.AppendFormat("Connected clients\t: {0}\r\n", status.NumberOfPeers);
                }
                this.StatusInfo = sb.ToString();
            }
            catch (NullReferenceException) {}
        }