Пример #1
0
 /// <summary>
 /// Internal constructor to create wireless network
 /// </summary>
 /// <param name="wlanInterfac">Wifi network interface</param>
 /// <param name="network">Win32 structure for wireless network</param>
 internal WirelessNetwork(WlanInterface wlanInterfac, WlanAvailableNetwork network)
 {
     _wlanInterface = wlanInterfac;
     _network       = network;
 }
Пример #2
0
        // Called from interop
        private void OnWlanNotification(ref WlanNotificationData notifyData, IntPtr context)
        {
            if (NoWifiAvailable)
            {
                return;
            }

            WlanInterface wlanIface = ifaces.ContainsKey(notifyData.interfaceGuid) ? ifaces[notifyData.interfaceGuid] : null;

            switch (notifyData.notificationSource)
            {
            case WlanNotificationSource.ACM:
                switch ((WlanNotificationCodeAcm)notifyData.notificationCode)
                {
                case WlanNotificationCodeAcm.ConnectionStart:
                case WlanNotificationCodeAcm.ConnectionComplete:
                case WlanNotificationCodeAcm.ConnectionAttemptFail:
                case WlanNotificationCodeAcm.Disconnecting:
                case WlanNotificationCodeAcm.Disconnected:
                    WlanConnectionNotificationData?connNotifyData = WlanHelpers.ParseWlanConnectionNotification(ref notifyData);

                    if (connNotifyData.HasValue && wlanIface != null)
                    {
                        wlanIface.OnWlanConnection(notifyData, connNotifyData.Value);
                    }

                    break;

                case WlanNotificationCodeAcm.ScanFail:
                    int expectedSize = Marshal.SizeOf(typeof(int));

                    if (notifyData.dataSize >= expectedSize)
                    {
                        int reasonInt = Marshal.ReadInt32(notifyData.dataPtr);

                        // Want to make sure this doesn't crash if windows sends a reasoncode not defined in the enum.
                        if (Enum.IsDefined(typeof(WlanReasonCode), reasonInt))
                        {
                            WlanReasonCode reasonCode = (WlanReasonCode)reasonInt;

                            if (wlanIface != null)
                            {
                                wlanIface.OnWlanReason(notifyData, reasonCode);
                            }
                        }
                    }
                    break;
                }
                break;

            case WlanNotificationSource.MSM:
                switch ((WlanNotificationCodeMsm)notifyData.notificationCode)
                {
                case WlanNotificationCodeMsm.Associating:
                case WlanNotificationCodeMsm.Associated:
                case WlanNotificationCodeMsm.Authenticating:
                case WlanNotificationCodeMsm.Connected:
                case WlanNotificationCodeMsm.RoamingStart:
                case WlanNotificationCodeMsm.RoamingEnd:
                case WlanNotificationCodeMsm.Disassociating:
                case WlanNotificationCodeMsm.Disconnected:
                case WlanNotificationCodeMsm.PeerJoin:
                case WlanNotificationCodeMsm.PeerLeave:
                case WlanNotificationCodeMsm.AdapterRemoval:
                    WlanConnectionNotificationData?connNotifyData = WlanHelpers.ParseWlanConnectionNotification(ref notifyData);

                    if (connNotifyData.HasValue && wlanIface != null)
                    {
                        wlanIface.OnWlanConnection(notifyData, connNotifyData.Value);
                    }

                    break;
                }
                break;
            }

            if (wlanIface != null)
            {
                wlanIface.OnWlanNotification(notifyData);
            }
        }