Esempio n. 1
0
        public WLAN_HOSTED_NETWORK_REASON InitSettings()
        {
            WLAN_HOSTED_NETWORK_REASON failReason;

            WlanUtils.Throw_On_Win32_Error(wlanapi.WlanHostedNetworkInitSettings(_wlanHandle, out failReason, IntPtr.Zero));
            return(failReason);
        }
Esempio n. 2
0
        public WLAN_HOSTED_NETWORK_REASON SetSecondaryKey(string passKey)
        {
            WLAN_HOSTED_NETWORK_REASON failReason;

            WlanUtils.Throw_On_Win32_Error(wlanapi.WlanHostedNetworkSetSecondaryKey(_wlanHandle, (uint)(passKey.Length + 1), passKey, true, true, out failReason, IntPtr.Zero));

            return(failReason);
        }
Esempio n. 3
0
        public WLAN_HOSTED_NETWORK_REASON QuerySecondaryKey(out string passKey, out bool isPassPhrase, out bool isPersistent)
        {
            WLAN_HOSTED_NETWORK_REASON failReason;
            uint keyLen;

            WlanUtils.Throw_On_Win32_Error(wlanapi.WlanHostedNetworkQuerySecondaryKey(_wlanHandle, out keyLen, out passKey, out isPassPhrase, out isPersistent, out failReason, IntPtr.Zero));
            return(failReason);
        }
Esempio n. 4
0
        public WLAN_HOSTED_NETWORK_STATUS QueryStatus()
        {
            IntPtr pStatus;

            WlanUtils.Throw_On_Win32_Error(wlanapi.WlanHostedNetworkQueryStatus(_wlanHandle, out pStatus, IntPtr.Zero));
            WLAN_HOSTED_NETWORK_STATUS status = (WLAN_HOSTED_NETWORK_STATUS)Marshal.PtrToStructure(pStatus, typeof(WLAN_HOSTED_NETWORK_STATUS));

            return(status);
        }
Esempio n. 5
0
        public WLAN_HOSTED_NETWORK_REASON StartUsing()
        {
            WLAN_HOSTED_NETWORK_REASON failReason;

            WlanUtils.Throw_On_Win32_Error(wlanapi.WlanHostedNetworkStartUsing(_wlanHandle, out failReason, IntPtr.Zero));

            _hostedNetworkState = WLAN_HOSTED_NETWORK_STATE.wlan_hosted_network_active;

            return(failReason);
        }
Esempio n. 6
0
        public WLAN_HOSTED_NETWORK_REASON StopUsing()
        {
            WLAN_HOSTED_NETWORK_REASON failReason;

            WlanUtils.Throw_On_Win32_Error(wlanapi.WlanHostedNetworkStopUsing(_wlanHandle, out failReason, IntPtr.Zero));

            _hostedNetworkState = WLAN_HOSTED_NETWORK_STATE.wlan_hosted_network_idle;

            _stations.Clear();
            RaiseStationLeave();

            return(failReason);
        }
Esempio n. 7
0
        public WLAN_OPCODE_VALUE_TYPE QueryConnectionSettings(out string hostedNetworkSSID, out int maxNumberOfPeers)
        {
            uint   dataSize;
            IntPtr dataPtr;
            WLAN_OPCODE_VALUE_TYPE opcode;

            WlanUtils.Throw_On_Win32_Error(
                wlanapi.WlanHostedNetworkQueryProperty(
                    _wlanHandle,
                    WLAN_HOSTED_NETWORK_OPCODE.wlan_hosted_network_opcode_connection_settings,
                    out dataSize, out dataPtr, out opcode, IntPtr.Zero
                    )
                );

            var settings = (WLAN_HOSTED_NETWORK_CONNECTION_SETTINGS)Marshal.PtrToStructure(dataPtr, typeof(WLAN_HOSTED_NETWORK_CONNECTION_SETTINGS));

            hostedNetworkSSID = settings.hostedNetworkSSID.ConvertToString();

            maxNumberOfPeers = (int)settings.dwMaxNumberOfPeers;

            return(opcode);
        }
Esempio n. 8
0
        public WLAN_HOSTED_NETWORK_REASON SetConnectionSettings(string hostedNetworkSSID, int maxNumberOfPeers)
        {
            WLAN_HOSTED_NETWORK_REASON failReason;

            WLAN_HOSTED_NETWORK_CONNECTION_SETTINGS settings = new WLAN_HOSTED_NETWORK_CONNECTION_SETTINGS();

            settings.hostedNetworkSSID  = WlanUtils.ConvertStringToDOT11_SSID(hostedNetworkSSID);
            settings.dwMaxNumberOfPeers = (uint)maxNumberOfPeers;

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

            Marshal.StructureToPtr(settings, settingsPtr, false);

            WlanUtils.Throw_On_Win32_Error(
                wlanapi.WlanHostedNetworkSetProperty(
                    _wlanHandle,
                    WLAN_HOSTED_NETWORK_OPCODE.wlan_hosted_network_opcode_connection_settings,
                    (uint)Marshal.SizeOf(settings), settingsPtr, out failReason, IntPtr.Zero
                    )
                );

            return(failReason);
        }
Esempio n. 9
0
        private void Init()
        {
            try
            {
                WlanUtils.Throw_On_Win32_Error(wlanapi.WlanOpenHandle(wlanapi.WLAN_CLIENT_VERSION_VISTA, IntPtr.Zero, out _serverVersion, ref _wlanHandle));


                WLAN_NOTIFICATION_SOURCE notifSource;
                WlanUtils.Throw_On_Win32_Error(wlanapi.WlanRegisterNotification(_wlanHandle, WLAN_NOTIFICATION_SOURCE.All, true, _notificationCallback, IntPtr.Zero, IntPtr.Zero, out notifSource));


                WLAN_HOSTED_NETWORK_REASON failReason = InitSettings();
                if (failReason != WLAN_HOSTED_NETWORK_REASON.wlan_hosted_network_reason_success)
                {
                    throw new Exception("Init Error WlanHostedNetworkInitSettings: " + failReason.ToString());
                }
            }
            catch
            {
                wlanapi.WlanCloseHandle(_wlanHandle, IntPtr.Zero);
                throw;
            }
        }