Example #1
0
        private void ReloadInterfaces()
        {
            IntPtr listPtr;

            Util.ThrowIfError(
                NativeMethods.WlanEnumInterfaces(clientHandle, IntPtr.Zero, out listPtr));
            try {
                WlanInterfaceInfoList list        = (WlanInterfaceInfoList)Marshal.PtrToStructure(listPtr, typeof(WlanInterfaceInfoList));
                uint            numberOfItems     = list.NumberOfItems;
                Int64           listIterator      = listPtr.ToInt64() + Marshal.OffsetOf(typeof(WlanInterfaceInfoList), "InterfaceInfo").ToInt64();
                WlanInterface[] interfaces        = new WlanInterface[numberOfItems];
                List <Guid>     currentIfaceGuids = new List <Guid>();
                for (int i = 0; i < numberOfItems; i++)
                {
                    WlanInterfaceInfo info =
                        (WlanInterfaceInfo)Marshal.PtrToStructure(new IntPtr(listIterator), typeof(WlanInterfaceInfo));
                    listIterator += Marshal.SizeOf(info);
                    WlanInterface wlanInterface;
                    currentIfaceGuids.Add(info.Guid);
                    if (interfaceMap.ContainsKey(info.Guid))
                    {
                        wlanInterface = interfaceMap[info.Guid];
                        //wlanInterface.UpdateInfo(info);
                    }
                    else
                    {
                        wlanInterface = WlanInterface.CreateInterface(this, info);
                    }
                    interfaces[i]           = wlanInterface;
                    interfaceMap[info.Guid] = wlanInterface;
                }
                // Remove stale interfaceList
                Queue <Guid> deadIfacesGuids = new Queue <Guid>();
                foreach (Guid ifaceGuid in interfaceMap.Keys)
                {
                    if (!currentIfaceGuids.Contains(ifaceGuid))
                    {
                        deadIfacesGuids.Enqueue(ifaceGuid);
                    }
                }
                while (deadIfacesGuids.Count != 0)
                {
                    Guid deadIfaceGuid = deadIfacesGuids.Dequeue();
                    interfaceMap.Remove(deadIfaceGuid);
                }
                interfaceList = interfaces;
            } finally {
                NativeMethods.WlanFreeMemory(listPtr);
            }
        }
Example #2
0
        internal void OnWlanNotification(ref WlanNotificationData data, IntPtr context)
        {
            WlanInterface wlanIface = null;
            WlanEventArgs wlanEvent = WlanEventArgs.Empty;

            if (interfaceMap.ContainsKey(data.InterfaceGuid))
            {
                wlanIface = interfaceMap[data.InterfaceGuid];
                wlanEvent.InterfaceGuid = wlanIface.Guid;
            }
            wlanEvent.NotificationSource = data.NotificationSource;
            wlanEvent.NotificationCode   = data.NotificationCode;

            switch (data.NotificationSource)
            {
            case WlanNotificationSource.Acm:
                switch ((WlanAcmNotificationCode)data.NotificationCode)
                {
                case WlanAcmNotificationCode.ConnectionStart:
                case WlanAcmNotificationCode.ConnectionAttemptFail:
                case WlanAcmNotificationCode.Disconnecting:
                case WlanAcmNotificationCode.Disconnected:
                    break;

                case WlanAcmNotificationCode.ConnectionComplete:
                    WlanConnectionNotificationData?conNotif = ParseWlanConnectionNotificationData(ref data);
                    if (conNotif.HasValue && wlanIface != null)
                    {
                        AcmConnectionEventArgs conArgs = new AcmConnectionEventArgs();
                        conArgs.ConnectionData   = conNotif.Value;
                        conArgs.NotificationCode = WlanAcmNotificationCode.ConnectionComplete;
                        wlanIface.OnAcmConnectionCompleted(conArgs);
                    }
                    break;

                case WlanAcmNotificationCode.ScanFail:
                    //TODO parse WLAN_REASON_CODE in field Data
                    break;

                case WlanAcmNotificationCode.BssTypeChange:
                    //TODO parse DOT11_BSS_TYPE in field Data
                    break;

                case WlanAcmNotificationCode.PowerSettingChange:
                    //TODO parse WLAN_POWER_SETTING in field Data
                    break;

                case WlanAcmNotificationCode.ProfileNameChange:
                    //TODO parse two null-terminated WCHAR strings in field Data
                    break;

                case WlanAcmNotificationCode.AdhocNetworkStateChange:
                    //TODO parse WLAN_ADHOC_NETWORK_STATE in field Data
                    break;

                case WlanAcmNotificationCode.ScreenPowerChange:
                    //TODO parse BOOL in field Data
                    break;
                }
                OnAcmNotification(new AcmEventArgs());
                break;

            case WlanNotificationSource.Msm:
                switch ((WlanMsmNotificationCode)data.NotificationCode)
                {
                case WlanMsmNotificationCode.Associating:
                case WlanMsmNotificationCode.Associated:
                case WlanMsmNotificationCode.Authenticating:
                case WlanMsmNotificationCode.Connected:
                case WlanMsmNotificationCode.RoamingStart:
                case WlanMsmNotificationCode.RoamingEnd:
                case WlanMsmNotificationCode.Disassociating:
                case WlanMsmNotificationCode.Disconnected:
                case WlanMsmNotificationCode.PeerJoin:
                case WlanMsmNotificationCode.PeerLeave:
                case WlanMsmNotificationCode.AdapterRemoval:
                    //TODO parse WLAN_MSM_NOTIFICATION_DATA in field Data
                    break;

                case WlanMsmNotificationCode.AdapterOperationModeChange:
                    //TODO parse ULONG in field Data
                    break;

                case WlanMsmNotificationCode.SignalQualityChange:
                    //TODO parse ULONG for WLAN_SIGNAL_QUALITY in field Data
                    break;

                case WlanMsmNotificationCode.RadioStateChange: {
                    WlanPhyRadioState            radioState = Util.ParseStruct <WlanPhyRadioState>(data.Data, data.DataSize);
                    MsmRadioStateChangeEventArgs eventArgs  = new MsmRadioStateChangeEventArgs();
                    eventArgs.RadioState = radioState;
                    wlanIface.OnMsmRadioStateChange(eventArgs);
                }
                break;
                }
                OnMsmNotification(new MsmEventArgs());
                break;

            case WlanNotificationSource.OneX:
                OnOneXNotification(new OneXEventArgs());
                break;     //TODO

            case WlanNotificationSource.Security:
                OnSecurityNotification(new SecurityEventArgs());
                break;     //TODO

            case WlanNotificationSource.Ihv: {
                IhvEventArgs eventArgs = new IhvEventArgs();
                eventArgs.Data     = data.Data;
                eventArgs.DataSize = data.DataSize;
                OnIhvNotification(eventArgs);
            }
            break;         //TODO

            case WlanNotificationSource.HostedNetwork:
                if (HostedNetwork != null)
                {
                    switch ((WlanHostedNetworkNotificationCode)data.NotificationCode)
                    {
                    case WlanHostedNetworkNotificationCode.PeerStateChange: {
                        WlanHostedNetworkDataPeerStateChange peerStateChange = Util.ParseStruct <WlanHostedNetworkDataPeerStateChange>(data.Data, data.DataSize);
                        HnwkPeerStateChangeEventArgs         eventArgs       = new HnwkPeerStateChangeEventArgs();
                        eventArgs.PeerState = peerStateChange;
                        HostedNetwork.OnHnwkPeerStateChange(eventArgs);
                    }
                    break;

                    case WlanHostedNetworkNotificationCode.RadioStateChange: {
                        WlanHostedNetworkRadioState   radioState = Util.ParseStruct <WlanHostedNetworkRadioState>(data.Data, data.DataSize);
                        HnwkRadioStateChangeEventArgs eventArgs  = new HnwkRadioStateChangeEventArgs();
                        eventArgs.RadioState = radioState;
                        HostedNetwork.OnHnwkRadioStateChange(eventArgs);
                    }
                    break;

                    case WlanHostedNetworkNotificationCode.StateChange: {
                        WlanHostedNetworkStateChange stateChange = Util.ParseStruct <WlanHostedNetworkStateChange>(data.Data, data.DataSize);
                        HnwkStateChangeEventArgs     eventArgs   = new HnwkStateChangeEventArgs();
                        eventArgs.State = stateChange;
                        HostedNetwork.OnHnwkStateChange(eventArgs);
                    }
                    break;
                    }
                    wlanEvent.InterfaceGuid = HostedNetwork.Guid;
                    OnHwnkNotification(new HnwkEventArgs());
                }
                break;
            }
            OnWlanNotification(wlanEvent);
        }
Example #3
0
        /// <summary>
        /// Creates an instance of an interface control class.
        /// </summary>
        /// <param name="client">Native Wi-Fi client control class.</param>
        /// <param name="info">Interface information provided by client control class.</param>
        /// <returns>Instance of an interface control class.</returns>
        public static WlanInterface CreateInterface(WlanClient client, WlanInterfaceInfo info)
        {
            WlanInterface intf = new WlanInterface(client, info);

            return(intf);
        }