예제 #1
0
        public IEnumerable <Wlan.WlanAvailableNetwork> GetAvailableNetworkList(Wlan.WlanGetAvailableNetworkFlags flags)
        {
            IntPtr ptr;

            Wlan.WlanAvailableNetwork[] networkArray;
            Wlan.ThrowIfError(Wlan.WlanGetAvailableNetworkList(_client.ItsClientHandle, _info.interfaceGuid, flags, IntPtr.Zero, out ptr));
            try
            {
                networkArray = ConvertAvailableNetworkListPtr(ptr);
            }
            finally
            {
                Wlan.WlanFreeMemory(ptr);
            }
            return(networkArray);
        }
예제 #2
0
        public IEnumerable <Wlan.WlanBssEntryN> GetNetworkBssList()
        {
            IntPtr ptr;

            Wlan.WlanBssEntryN[] entryArray;
            Wlan.ThrowIfError(Wlan.WlanGetNetworkBssList(_client.ItsClientHandle, _info.interfaceGuid, IntPtr.Zero, Wlan.Dot11BssType.Any, false, IntPtr.Zero, out ptr));
            try
            {
                entryArray = ConvertBssListPtr(ptr);
            }
            finally
            {
                Wlan.WlanFreeMemory(ptr);
            }
            return(entryArray);
        }
예제 #3
0
        private int GetInterfaceInt(Wlan.WlanIntfOpcode opCode)
        {
            IntPtr ptr;
            int    num;

            Wlan.WlanOpcodeValueType type;
            int num2;

            Wlan.ThrowIfError(Wlan.WlanQueryInterface(_client.ItsClientHandle, _info.interfaceGuid, opCode, IntPtr.Zero, out num, out ptr, out type));
            try
            {
                num2 = Marshal.ReadInt32(ptr);
            }
            finally
            {
                Wlan.WlanFreeMemory(ptr);
            }
            return(num2);
        }
예제 #4
0
        public string GetProfileXml(string profileName)
        {
            IntPtr ptr;

            Wlan.WlanProfileFlags flags;
            Wlan.WlanAccess       access;
            string str;

            Wlan.ThrowIfError(Wlan.WlanGetProfile(_client.ItsClientHandle, _info.interfaceGuid, profileName, IntPtr.Zero, out ptr, out flags, out access));
            try
            {
                str = Marshal.PtrToStringUni(ptr);
            }
            finally
            {
                Wlan.WlanFreeMemory(ptr);
            }
            return(str);
        }
예제 #5
0
        public WlanClient()
        {
            ItsLogger = new Logger(this);

            try
            {
                Wlan.ThrowIfError(Wlan.WlanOpenHandle(1, IntPtr.Zero, out _negotiatedVersion, out _clientHandle));
                WlanNotificationCallback = new Wlan.WlanNotificationCallbackDelegate(OnWlanNotification);

                Wlan.WlanNotificationSource source;
                Wlan.ThrowIfError(Wlan.WlanRegisterNotification(_clientHandle, Wlan.WlanNotificationSource.All, false, WlanNotificationCallback, IntPtr.Zero, IntPtr.Zero, out source));
            }
            catch (Win32Exception ex)
            {
                Wlan.WlanCloseHandle(_clientHandle, IntPtr.Zero);
                ItsLogger.Warn(ex.Message);
                throw;
            }
        }
예제 #6
0
        /// <summary>
        /// Converts the bssType to a readable string
        /// </summary>
        /// <param name="bssType">type to convert to a string</param>
        /// <returns>string representing the bss type</returns>
        public static string ConvertToString(Wlan.Dot11BssType bssType)
        {
            string bssText;
            switch (bssType)
            {
                case Wlan.Dot11BssType.Infrastructure:
                    bssText = "Infrastructure";
                    break;
                case Wlan.Dot11BssType.Independent:
                    bssText = "Adhoc";
                    break;
                case Wlan.Dot11BssType.Any:
                    bssText = "AutoUnknown";
                    break;
                default:
                    bssText = "Unknown";
                    break;
            }

            return (bssText);
        }
예제 #7
0
 private int GetInterfaceInt(Wlan.WlanIntfOpcode opCode)
 {
     IntPtr ptr;
     int num;
     Wlan.WlanOpcodeValueType type;
     int num2;
     Wlan.ThrowIfError(Wlan.WlanQueryInterface(_client._clientHandle, _info.interfaceGuid, opCode, IntPtr.Zero, out num, out ptr, out type));
     try
     {
         num2 = Marshal.ReadInt32(ptr);
     }
     finally
     {
         Wlan.WlanFreeMemory(ptr);
     }
     return num2;
 }
예제 #8
0
 private void Connect(Wlan.WlanConnectionParameters connectionParams)
 {
     Wlan.ThrowIfError(Wlan.WlanConnect(_client._clientHandle, _info.interfaceGuid, ref connectionParams, IntPtr.Zero));
 }
예제 #9
0
 internal void OnWlanNotification(Wlan.WlanNotificationData notifyData)
 {
     if (WlanNotification != null)
     {
         WlanNotification(notifyData);
     }
 }
예제 #10
0
 public Wlan.WlanReasonCode SetProfile(Wlan.WlanProfileFlags flags, string profileXml, bool overwrite)
 {
     Wlan.WlanReasonCode code;
     Wlan.ThrowIfError(Wlan.WlanSetProfile(_client._clientHandle, _info.interfaceGuid, flags, profileXml, null, overwrite, IntPtr.Zero, out code));
     return code;
 }
예제 #11
0
 public IEnumerable<Wlan.WlanAvailableNetwork> GetAvailableNetworkList(Wlan.WlanGetAvailableNetworkFlags flags)
 {
     IntPtr ptr;
     Wlan.WlanAvailableNetwork[] networkArray;
     Wlan.ThrowIfError(Wlan.WlanGetAvailableNetworkList(_client._clientHandle, _info.interfaceGuid, flags, IntPtr.Zero, out ptr));
     try
     {
         networkArray = ConvertAvailableNetworkListPtr(ptr);
     }
     finally
     {
         Wlan.WlanFreeMemory(ptr);
     }
     return networkArray;
 }
예제 #12
0
 /// <summary>
 /// Creates a readable string based on the encryption algorithm and
 /// the authentication method
 /// </summary>
 /// <param name="authentication">authentication used</param>
 /// <param name="encryption">encryption used</param>
 /// <returns>a string representing the privacy mode</returns>
 public static string CreatePrivacyString(Wlan.Dot11AuthAlgorithm authentication,
     Wlan.Dot11CipherAlgorithm encryption)
 {
     String text = authentication + "-" + encryption;
     text = text.Replace("_PSK", "");
     text = text.Replace("IEEE80211_", "");
     text = text.Replace("Open", "");
     text = text.Trim(new[] { '-' });
     if (null == text || text.Equals(String.Empty))
     {
         text = "None";
     }
     return text;
 }
예제 #13
0
 private void Connect(Wlan.WlanConnectionParameters connectionParams)
 {
     Wlan.ThrowIfError(Wlan.WlanConnect(_client.ItsClientHandle, _info.interfaceGuid, ref connectionParams, IntPtr.Zero));
 }
예제 #14
0
 public Wlan.WlanReasonCode SetProfile(Wlan.WlanProfileFlags flags, string profileXml, bool overwrite)
 {
     Wlan.WlanReasonCode code;
     Wlan.ThrowIfError(Wlan.WlanSetProfile(_client.ItsClientHandle, _info.interfaceGuid, flags, profileXml, null, overwrite, IntPtr.Zero, out code));
     return(code);
 }
예제 #15
0
 public void Scan()
 {
     Wlan.ThrowIfError(Wlan.WlanScan(_client.ItsClientHandle, _info.interfaceGuid, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero));
 }
예제 #16
0
 public void Connect(Wlan.WlanConnectionMode connectionMode, Wlan.Dot11BssType bssType, Wlan.Dot11Ssid ssid, Wlan.WlanConnectionFlags flags)
 {
     Wlan.WlanConnectionParameters parameters2 = new Wlan.WlanConnectionParameters {
         wlanConnectionMode = connectionMode,
         dot11SsidPtr = Marshal.AllocHGlobal(Marshal.SizeOf(ssid)),
         dot11BssType = bssType,
         flags = flags
     };
     Wlan.WlanConnectionParameters connectionParams = parameters2;
     this.Connect(connectionParams);
     Marshal.StructureToPtr(ssid, connectionParams.dot11SsidPtr, false);
     Marshal.DestroyStructure(connectionParams.dot11SsidPtr, ssid.GetType());
     Marshal.FreeHGlobal(connectionParams.dot11SsidPtr);
 }
예제 #17
0
 public bool ConnectSynchronously(Wlan.WlanConnectionMode connectionMode, Wlan.Dot11BssType bssType, string profile, int connectTimeout)
 {
     _queueEvents = true;
     try
     {
         Connect(connectionMode, bssType, profile);
         while (_queueEvents && _eventQueueFilled.WaitOne(connectTimeout, true))
         {
             lock (_eventQueue)
             {
                 while (_eventQueue.Count != 0)
                 {
                     object obj2 = _eventQueue.Dequeue();
                     if (obj2 is WlanConnectionNotificationEventData)
                     {
                         WlanConnectionNotificationEventData data = (WlanConnectionNotificationEventData) obj2;
                         if (((data.NotifyData.notificationSource != Wlan.WlanNotificationSource.Acm) || (data.NotifyData.notificationCode != 10)) || data.ConnNotifyData.profileName != profile)
                         {
                             break;
                         }
                         return true;
                     }
                 }
                 continue;
             }
         }
     }
     finally
     {
         _queueEvents = false;
         _eventQueue.Clear();
     }
     return false;
 }
 private static bool FindNetwork(string ssid, IEnumerable<Wlan.WlanAvailableNetwork> networks, ref Wlan.WlanAvailableNetwork foundNetwork)
 {
     if (networks != null)
     {
         foreach (Wlan.WlanAvailableNetwork network in networks)
         {
             string str = Encoding.ASCII.GetString(network.dot11Ssid.SSID, 0, (int)network.dot11Ssid.SSIDLength);
             if (!string.IsNullOrEmpty(str) && str.Equals(ssid))
             {
                 foundNetwork = network;
                 return true;
             }
         }
     }
     return false;
 }
예제 #19
0
 public Wlan.WlanBssEntryN[] GetNetworkBssList(Wlan.Dot11Ssid ssid, Wlan.Dot11BssType bssType, bool securityEnabled)
 {
     Wlan.WlanBssEntryN[] entryArray;
     IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(ssid));
     Marshal.StructureToPtr(ssid, ptr, false);
     try
     {
         IntPtr ptr2;
         Wlan.ThrowIfError(Wlan.WlanGetNetworkBssList(_client._clientHandle, _info.interfaceGuid, ptr, bssType, securityEnabled, IntPtr.Zero, out ptr2));
         try
         {
             entryArray = ConvertBssListPtr(ptr2);
         }
         finally
         {
             Wlan.WlanFreeMemory(ptr2);
         }
     }
     finally
     {
         Marshal.FreeHGlobal(ptr);
     }
     return entryArray;
 }
 private void WlanApi_WlanNotification(Wlan.WlanNotificationData notifyData)
 {
     lock (this)
     {
         if (notifyData.notificationSource == Wlan.WlanNotificationSource.Acm)
         {
             switch (((Wlan.WlanNotificationCodeAcm)notifyData.NotificationCode))
             {
                 case Wlan.WlanNotificationCodeAcm.ScanComplete:
                 case Wlan.WlanNotificationCodeAcm.ScanFail:
                     OnScanComplete();
                     break;
             }
         }
     }
 }
예제 #21
0
 internal void OnWlanConnection(Wlan.WlanNotificationData notifyData, Wlan.WlanConnectionNotificationData connNotifyData)
 {
     if (WlanConnectionNotification != null)
     {
         WlanConnectionNotification(notifyData, connNotifyData);
     }
     if (_queueEvents)
     {
         WlanConnectionNotificationEventData data2 = new WlanConnectionNotificationEventData {
             NotifyData = notifyData,
             ConnNotifyData = connNotifyData
         };
         WlanConnectionNotificationEventData queuedEvent = data2;
         EnqueueEvent(queuedEvent);
     }
 }
예제 #22
0
 public string GetStringForReasonCode(Wlan.WlanReasonCode reasonCode)
 {
     StringBuilder stringBuffer = new StringBuilder(0x400);
     Wlan.ThrowIfError(Wlan.WlanReasonCodeToString(reasonCode, stringBuffer.Capacity, stringBuffer, IntPtr.Zero));
     return stringBuffer.ToString();
 }
예제 #23
0
 internal void OnWlanReason(Wlan.WlanNotificationData notifyData, Wlan.WlanReasonCode reasonCode)
 {
     if (WlanReasonNotification != null)
     {
         WlanReasonNotification(notifyData, reasonCode);
     }
     if (_queueEvents)
     {
         WlanReasonNotificationData data2 = new WlanReasonNotificationData {
             NotifyData = notifyData,
             ReasonCode = reasonCode
         };
         WlanReasonNotificationData queuedEvent = data2;
         EnqueueEvent(queuedEvent);
     }
 }
예제 #24
0
        private void OnWlanNotification(ref Wlan.WlanNotificationData notifyData, IntPtr context)
        {
            WlanInterface interface2 = _ifaces.ContainsKey(notifyData.interfaceGuid) ? _ifaces[notifyData.interfaceGuid] : null;
            switch (notifyData.notificationSource)
            {
                case Wlan.WlanNotificationSource.Acm:
                    switch (notifyData.notificationCode)
                    {
                        case 8:
                            if (notifyData.dataSize >= Marshal.SizeOf(0))
                            {
                                Wlan.WlanReasonCode reasonCode = (Wlan.WlanReasonCode) Marshal.ReadInt32(notifyData.dataPtr);
                                if (interface2 != null)
                                {
                                    interface2.OnWlanReason(notifyData, reasonCode);
                                }
                            }
                            goto Label_0194;

                        case 9:
                        case 10:
                        case 11:
                        case 20:
                        case 0x15:
                        {
                            Wlan.WlanConnectionNotificationData? nullable = ParseWlanConnectionNotification(ref notifyData);
                            if (nullable.HasValue && (interface2 != null))
                            {
                                interface2.OnWlanConnection(notifyData, nullable.Value);
                            }
                            goto Label_0194;
                        }
                        case 12:
                        case 15:
                        case 0x10:
                        case 0x11:
                        case 0x12:
                        case 0x13:
                            goto Label_0194;

                        case 13:
                            InvokeInterfaceArrivedEvent(new InterfaceNotificationEventsArgs(notifyData.interfaceGuid));
                            goto Label_0194;

                        case 14:
                            InvokeInterfaceRemovedEvent(new InterfaceNotificationEventsArgs(notifyData.interfaceGuid));
                            goto Label_0194;
                    }
                    break;

                case Wlan.WlanNotificationSource.Msm:
                    switch (notifyData.notificationCode)
                    {
                        case 1:
                        case 2:
                        case 3:
                        case 4:
                        case 5:
                        case 6:
                        case 9:
                        case 10:
                        case 11:
                        case 12:
                        case 13:
                        {
                            Wlan.WlanConnectionNotificationData? nullable2 = ParseWlanConnectionNotification(ref notifyData);
                            if (nullable2.HasValue && (interface2 != null))
                            {
                                interface2.OnWlanConnection(notifyData, nullable2.Value);
                            }
                            goto Label_0194;
                        }
                        case 7:
                        case 8:
                            goto Label_0194;
                    }
                    goto Label_0194;
            }
            Label_0194:
            if (interface2 != null)
            {
                interface2.OnWlanNotification(notifyData);
            }
        }
예제 #25
0
 private void Connect(Wlan.WlanConnectionMode connectionMode, Wlan.Dot11BssType bssType, string profile)
 {
     Wlan.WlanConnectionParameters parameters2 = new Wlan.WlanConnectionParameters {
         wlanConnectionMode = connectionMode,
         profile = profile,
         dot11BssType = bssType,
         flags = 0
     };
     Wlan.WlanConnectionParameters connectionParams = parameters2;
     Connect(connectionParams);
 }
예제 #26
0
 private Wlan.WlanConnectionNotificationData? ParseWlanConnectionNotification(ref Wlan.WlanNotificationData notifyData)
 {
     int num = Marshal.SizeOf(typeof(Wlan.WlanConnectionNotificationData));
     if (notifyData.dataSize < num)
     {
         return null;
     }
     Wlan.WlanConnectionNotificationData data = (Wlan.WlanConnectionNotificationData) Marshal.PtrToStructure(notifyData.dataPtr, typeof(Wlan.WlanConnectionNotificationData));
     if (data.wlanReasonCode == Wlan.WlanReasonCode.Success)
     {
         IntPtr ptr = new IntPtr(notifyData.dataPtr.ToInt64() + Marshal.OffsetOf(typeof(Wlan.WlanConnectionNotificationData), "profileXml").ToInt64());
         data.profileXml = Marshal.PtrToStringUni(ptr);
     }
     return data;
 }
예제 #27
0
 private void SetInterfaceInt(Wlan.WlanIntfOpcode opCode, int value)
 {
     IntPtr ptr = Marshal.AllocHGlobal(4);
     Marshal.WriteInt32(ptr, value);
     try
     {
         Wlan.ThrowIfError(Wlan.WlanSetInterface(_client._clientHandle, _info.interfaceGuid, opCode, 4, ptr, IntPtr.Zero));
     }
     finally
     {
         Marshal.FreeHGlobal(ptr);
     }
 }
예제 #28
0
 internal WlanInterface(WlanClient client, Wlan.WlanInterfaceInfo info)
 {
     _client = client;
     _info = info;
 }
예제 #29
0
 /// <summary>
 /// Creates a readable string based on the encryption algorithm and
 /// the authentication method
 /// </summary>
 /// <param name="authentication">authentication used</param>
 /// <param name="encryption">encryption used</param>
 /// <returns>a string representing the security mode</returns>
 public static string CreateSecurityString(Wlan.Dot11AuthAlgorithm authentication,
     Wlan.Dot11CipherAlgorithm encryption)
 {
     String text = authentication + "-" + encryption;
     text = text.Replace("RSNA", "WPA2");
     text = text.Replace("_PSK-CCMP", "-Personal");
     text = text.Replace("_PSK-TKIP", "-Personal");
     text = text.Replace("CCMP", "Enterprise");
     text = text.Replace("IEEE80211_", "");
     text = text.Replace("None", "");
     text = text.Replace("Open", "");
     text = text.Replace("WEP40", "WEP");
     text = text.Replace("WEP104", "WEP");
     text = text.Trim(new[] { '-' });
     if (null == text || text.Equals(String.Empty))
     {
         text = "Open";
     }
     return text;
 }
예제 #30
0
 public void DeleteProfile(string profileName)
 {
     Wlan.ThrowIfError(Wlan.WlanDeleteProfile(_client.ItsClientHandle, _info.interfaceGuid, profileName, IntPtr.Zero));
 }