Example #1
0
        private void Init()
        {
            try {
                WlanUtils.Throw_On_Win32_Error(wlanapi.WlanOpenHandle(wlanapi.WLAN_CLIENT_VERSION_VISTA, IntPtr.Zero, out this._ServerVersion, ref this._WlanHandle));


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


                WLAN_HOSTED_NETWORK_REASON failReason = this.InitSettings();
                if (failReason != WLAN_HOSTED_NETWORK_REASON.wlan_hosted_network_reason_success)
                {
                    throw new Exception("Init Error WlanHostedNetworkInitSettings: " + failReason.ToString());
                }

                //我加的
                var netStat = QueryStatus();
                _HostedNetworkState = netStat.HostedNetworkState;
                foreach (var i in netStat.PeerList)
                {
                    WlanStation station = new WlanStation(i);
                    _Stations[station.MacAddress] = station;
                }
            } catch {
                wlanapi.WlanCloseHandle(this._WlanHandle, IntPtr.Zero);
                throw;
            }
        }
Example #2
0
        public WLAN_HOSTED_NETWORK_STATUS QueryStatus()
        {
            WLAN_HOSTED_NETWORK_STATUS status;

            WlanUtils.Throw_On_Win32_Error(wlanapi.WlanHostedNetworkQueryStatus(this._WlanHandle, out status, IntPtr.Zero));
            return(status);
        }
Example #3
0
        public WLAN_HOSTED_NETWORK_REASON InitSettings()
        {
            WLAN_HOSTED_NETWORK_REASON failReason;

            WlanUtils.Throw_On_Win32_Error(wlanapi.WlanHostedNetworkInitSettings(this._WlanHandle, out failReason, IntPtr.Zero));
            return(failReason);
        }
Example #4
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));

            try {
                Marshal.StructureToPtr(settings, settingsPtr, false);

                WlanUtils.Throw_On_Win32_Error(
                    wlanapi.WlanHostedNetworkSetProperty(
                        this._WlanHandle,
                        WLAN_HOSTED_NETWORK_OPCODE.wlan_hosted_network_opcode_connection_settings,
                        (uint)Marshal.SizeOf(settings), settingsPtr, out failReason, IntPtr.Zero
                        )
                    );
            } finally {
                Marshal.FreeHGlobal(settingsPtr);
            }


            return(failReason);
        }
Example #5
0
        public WLAN_HOSTED_NETWORK_REASON SetSecondaryKey(string passKey)
        {
            WLAN_HOSTED_NETWORK_REASON failReason;

            WlanUtils.Throw_On_Win32_Error(wlanapi.WlanHostedNetworkSetSecondaryKey(this._WlanHandle, (uint)(passKey.Length + 1), passKey, true, true, out failReason, IntPtr.Zero));
            return(failReason);
        }
Example #6
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(this._WlanHandle, out keyLen, out passKey, out isPassPhrase, out isPersistent, out failReason, IntPtr.Zero));
            return(failReason);
        }
Example #7
0
        public WLAN_HOSTED_NETWORK_REASON StopUsing()
        {
            WLAN_HOSTED_NETWORK_REASON failReason;

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

            this._HostedNetworkState = WLAN_HOSTED_NETWORK_STATE.wlan_hosted_network_idle;

            return(failReason);
        }
Example #8
0
        public WLAN_HOSTED_NETWORK_STATUS QueryStatus()
        {
            WLAN_HOSTED_NETWORK_STATUS status;
            IntPtr ptr   = new IntPtr();
            var    error = wlanapi.WlanHostedNetworkQueryStatus(this._WlanHandle, out ptr, IntPtr.Zero);

            status = ptr.Dereference <WLAN_HOSTED_NETWORK_STATUS>();
            WlanUtils.Throw_On_Win32_Error(error);
            status.FixPeerListAddr(ptr);
            return(status);
        }
Example #9
0
        public WLAN_HOSTED_NETWORK_STATUS_Wrapper QueryStatus()
        {
            WLAN_HOSTED_NETWORK_STATUS status;
            IntPtr ptr   = new IntPtr();
            var    error = wlanapi.WlanHostedNetworkQueryStatus(this._WlanHandle, out ptr, IntPtr.Zero);

            status = ptr.Dereference <WLAN_HOSTED_NETWORK_STATUS>();
            WlanUtils.Throw_On_Win32_Error(error);
            var wrapper    = new WLAN_HOSTED_NETWORK_STATUS_Wrapper(status);
            int structSize = Marshal.SizeOf(typeof(WLAN_HOSTED_NETWORK_PEER_STATE));
            //将指向WLAN_HOSTED_NETWORK_STATUS的指针偏移到PeerList成员的地方
            IntPtr offset = Marshal.OffsetOf(typeof(WLAN_HOSTED_NETWORK_STATUS), "PeerList");

            IntPtr peerListPtr = ptr + offset.ToInt32();

            wrapper.PeerList.AddRange(peerListPtr.ToEnumerable <WLAN_HOSTED_NETWORK_PEER_STATE>((int)status.dwNumberOfPeers));
            return(wrapper);
        }
Example #10
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(
                    this._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);
        }