public string GetProfileXml(string profileName)
            {
                IntPtr profileXml;

                Wlan.WlanProfileFlags flags;
                Wlan.WlanAccess       grantedAccess;
                Wlan.ThrowIfError(Wlan.WlanGetProfile(this.client.clientHandle, this.info.interfaceGuid, profileName, IntPtr.Zero, out profileXml, out flags, out grantedAccess));
                try
                {
                    return(Marshal.PtrToStringUni(profileXml));
                }
                finally
                {
                    Wlan.WlanFreeMemory(profileXml);
                }
            }
            private int GetInterfaceInt(Wlan.WlanIntfOpcode opCode)
            {
                int    dataSize;
                IntPtr ppData;

                Wlan.WlanOpcodeValueType wlanOpcodeValueType;
                Wlan.ThrowIfError(Wlan.WlanQueryInterface(this.client.clientHandle, this.info.interfaceGuid, opCode, IntPtr.Zero, out dataSize, out ppData, out wlanOpcodeValueType));
                try
                {
                    return(Marshal.ReadInt32(ppData));
                }
                finally
                {
                    Wlan.WlanFreeMemory(ppData);
                }
            }
Пример #3
0
 /// <summary>
 /// Creates a new instance of a Native Wifi service client.
 /// </summary>
 public WlanClient()
 {
     Wlan.ThrowIfError(
         Wlan.WlanOpenHandle(Wlan.WLAN_CLIENT_VERSION_XP_SP2, IntPtr.Zero, out negotiatedVersion, out clientHandle));
     try
     {
         Wlan.WlanNotificationSource prevSrc;
         wlanNotificationCallback = OnWlanNotification;
         Wlan.ThrowIfError(
             Wlan.WlanRegisterNotification(clientHandle, Wlan.WlanNotificationSource.All, false, wlanNotificationCallback, IntPtr.Zero, IntPtr.Zero, out prevSrc));
     }
     catch
     {
         Close();
         throw;
     }
 }
Пример #4
0
            /// <summary>
            /// Gets a parameter of the interface whose data type is <see cref="int"/>.
            /// </summary>
            /// <param name="opCode">The opcode of the parameter.</param>
            /// <returns>The integer value.</returns>
            private int GetInterfaceInt(Wlan.WlanIntfOpcode opCode)
            {
                IntPtr valuePtr;
                int    valueSize;

                Wlan.WlanOpcodeValueType opcodeValueType;
                Wlan.ThrowIfError(
                    Wlan.WlanQueryInterface(client.clientHandle, info.interfaceGuid, opCode, IntPtr.Zero, out valueSize, out valuePtr, out opcodeValueType));
                try
                {
                    return(Marshal.ReadInt32(valuePtr));
                }
                finally
                {
                    Wlan.WlanFreeMemory(valuePtr);
                }
            }
            public Wlan.WlanBssEntry[] GetNetworkBssList(Wlan.Dot11Ssid ssid, Wlan.Dot11BssType bssType, bool securityEnabled)
            {
                IntPtr num = Marshal.AllocHGlobal(Marshal.SizeOf((object)ssid));

                Marshal.StructureToPtr((object)ssid, num, false);
                try
                {
                    IntPtr wlanBssList;
                    Wlan.ThrowIfError(Wlan.WlanGetNetworkBssList(this.client.clientHandle, this.info.interfaceGuid, num, bssType, securityEnabled, IntPtr.Zero, out wlanBssList));
                    try
                    {
                        return(WlanClient.WlanInterface.ConvertBssListPtr(wlanBssList));
                    }
                    finally
                    {
                        Wlan.WlanFreeMemory(wlanBssList);
                    }
                }
                finally
                {
                    Marshal.FreeHGlobal(num);
                }
            }
            public Wlan.WlanProfileInfo[] GetProfiles()
            {
                IntPtr profileList;

                Wlan.ThrowIfError(Wlan.WlanGetProfileList(this.client.clientHandle, this.info.interfaceGuid, IntPtr.Zero, out profileList));
                try
                {
                    Wlan.WlanProfileInfoListHeader structure1           = (Wlan.WlanProfileInfoListHeader)Marshal.PtrToStructure(profileList, typeof(Wlan.WlanProfileInfoListHeader));
                    Wlan.WlanProfileInfo[]         wlanProfileInfoArray = new Wlan.WlanProfileInfo[(int)structure1.numberOfItems];
                    long num = profileList.ToInt64() + (long)Marshal.SizeOf((object)structure1);
                    for (int index = 0; (long)index < (long)structure1.numberOfItems; ++index)
                    {
                        Wlan.WlanProfileInfo structure2 = (Wlan.WlanProfileInfo)Marshal.PtrToStructure(new IntPtr(num), typeof(Wlan.WlanProfileInfo));
                        wlanProfileInfoArray[index] = structure2;
                        num += (long)Marshal.SizeOf((object)structure2);
                    }
                    return(wlanProfileInfoArray);
                }
                finally
                {
                    Wlan.WlanFreeMemory(profileList);
                }
            }
Пример #7
0
            /// <summary>
            /// Gets the information of all profiles on this interface.
            /// </summary>
            /// <returns>The profiles information.</returns>
            public Wlan.WlanProfileInfo[] GetProfiles()
            {
                IntPtr profileListPtr;

                Wlan.ThrowIfError(
                    Wlan.WlanGetProfileList(client.clientHandle, info.interfaceGuid, IntPtr.Zero, out profileListPtr));
                try
                {
                    Wlan.WlanProfileInfoListHeader header       = (Wlan.WlanProfileInfoListHeader)Marshal.PtrToStructure(profileListPtr, typeof(Wlan.WlanProfileInfoListHeader));
                    Wlan.WlanProfileInfo[]         profileInfos = new Wlan.WlanProfileInfo[header.numberOfItems];
                    long profileListIterator = profileListPtr.ToInt64() + Marshal.SizeOf(header);
                    for (int i = 0; i < header.numberOfItems; ++i)
                    {
                        Wlan.WlanProfileInfo profileInfo = (Wlan.WlanProfileInfo)Marshal.PtrToStructure(new IntPtr(profileListIterator), typeof(Wlan.WlanProfileInfo));
                        profileInfos[i]      = profileInfo;
                        profileListIterator += Marshal.SizeOf(profileInfo);
                    }
                    return(profileInfos);
                }
                finally
                {
                    Wlan.WlanFreeMemory(profileListPtr);
                }
            }
Пример #8
0
            /// <summary>
            /// Retrieves the basic service sets (BSS) list of the specified network.
            /// </summary>
            /// <param name="ssid">Specifies the SSID of the network from which the BSS list is requested.</param>
            /// <param name="bssType">Indicates the BSS type of the network.</param>
            /// <param name="securityEnabled">Indicates whether security is enabled on the network.</param>
            public Wlan.WlanBssEntry[] GetNetworkBssList(Wlan.Dot11Ssid ssid, Wlan.Dot11BssType bssType, bool securityEnabled)
            {
                IntPtr ssidPtr = Marshal.AllocHGlobal(Marshal.SizeOf(ssid));

                Marshal.StructureToPtr(ssid, ssidPtr, false);
                try
                {
                    IntPtr bssListPtr;
                    Wlan.ThrowIfError(
                        Wlan.WlanGetNetworkBssList(client.clientHandle, info.interfaceGuid, ssidPtr, bssType, securityEnabled, IntPtr.Zero, out bssListPtr));
                    try
                    {
                        return(ConvertBssListPtr(bssListPtr));
                    }
                    finally
                    {
                        Wlan.WlanFreeMemory(bssListPtr);
                    }
                }
                finally
                {
                    Marshal.FreeHGlobal(ssidPtr);
                }
            }
Пример #9
0
Файл: WlanApi.cs Проект: t00/seb
 /// <summary>
 /// Connects to the specified wireless network.
 /// </summary>
 /// <remarks>
 /// The method returns immediately. Progress is reported through the <see cref="WlanNotification"/> event.
 /// </remarks>
 public void Connect(Wlan.WlanConnectionMode connectionMode, Wlan.Dot11BssType bssType, Wlan.Dot11Ssid ssid, Wlan.WlanConnectionFlags flags)
 {
     Wlan.WlanConnectionParameters connectionParams = new Wlan.WlanConnectionParameters();
     connectionParams.wlanConnectionMode = connectionMode;
     connectionParams.dot11SsidPtr = Marshal.AllocHGlobal(Marshal.SizeOf(ssid));
     Marshal.StructureToPtr(ssid, connectionParams.dot11SsidPtr, false);
     connectionParams.dot11BssType = bssType;
     connectionParams.flags = flags;
     Connect(connectionParams);
     Marshal.DestroyStructure(connectionParams.dot11SsidPtr, ssid.GetType());
     Marshal.FreeHGlobal(connectionParams.dot11SsidPtr);
 }
Пример #10
0
Файл: WlanApi.cs Проект: t00/seb
 /// <summary>
 /// Requests a connection (association) to the specified wireless network.
 /// </summary>
 /// <remarks>
 /// The method returns immediately. Progress is reported through the <see cref="WlanNotification"/> event.
 /// </remarks>
 public void Connect(Wlan.WlanConnectionMode connectionMode, Wlan.Dot11BssType bssType, string profile)
 {
     Wlan.WlanConnectionParameters connectionParams = new Wlan.WlanConnectionParameters();
     connectionParams.wlanConnectionMode = connectionMode;
     connectionParams.profile = profile;
     connectionParams.dot11BssType = bssType;
     connectionParams.flags = 0;
     Connect(connectionParams);
 }
Пример #11
0
Файл: WlanApi.cs Проект: t00/seb
 internal WlanInterface(WlanClient client, Wlan.WlanInterfaceInfo info)
 {
     this.client = client;
     this.info = info;
 }
Пример #12
0
Файл: WlanApi.cs Проект: t00/seb
 /// <summary>
 /// Gets a parameter of the interface whose data type is <see cref="int"/>.
 /// </summary>
 /// <param name="opCode">The opcode of the parameter.</param>
 /// <returns>The integer value.</returns>
 private int GetInterfaceInt(Wlan.WlanIntfOpcode opCode)
 {
     IntPtr valuePtr;
     int valueSize;
     Wlan.WlanOpcodeValueType opcodeValueType;
     Wlan.ThrowIfError(
         Wlan.WlanQueryInterface(client.clientHandle, info.interfaceGuid, opCode, IntPtr.Zero, out valueSize, out valuePtr, out opcodeValueType));
     try
     {
         return Marshal.ReadInt32(valuePtr);
     }
     finally
     {
         Wlan.WlanFreeMemory(valuePtr);
     }
 }
Пример #13
0
Файл: WlanApi.cs Проект: t00/seb
 /// <summary>
 /// Retrieves the basic service sets (BSS) list of the specified network.
 /// </summary>
 /// <param name="ssid">Specifies the SSID of the network from which the BSS list is requested.</param>
 /// <param name="bssType">Indicates the BSS type of the network.</param>
 /// <param name="securityEnabled">Indicates whether security is enabled on the network.</param>
 public Wlan.WlanBssEntry[] GetNetworkBssList(Wlan.Dot11Ssid ssid, Wlan.Dot11BssType bssType, bool securityEnabled)
 {
     IntPtr ssidPtr = Marshal.AllocHGlobal(Marshal.SizeOf(ssid));
     Marshal.StructureToPtr(ssid, ssidPtr, false);
     try
     {
         IntPtr bssListPtr;
         Wlan.ThrowIfError(
             Wlan.WlanGetNetworkBssList(client.clientHandle, info.interfaceGuid, ssidPtr, bssType, securityEnabled, IntPtr.Zero, out bssListPtr));
         try
         {
             return ConvertBssListPtr(bssListPtr);
         }
         finally
         {
             Wlan.WlanFreeMemory(bssListPtr);
         }
     }
     finally
     {
         Marshal.FreeHGlobal(ssidPtr);
     }
 }
Пример #14
0
 /// <summary>
 /// Deletes a profile.
 /// </summary>
 /// <param name="profileName">
 /// The name of the profile to be deleted. Profile names are case-sensitive.
 /// On Windows XP SP2, the supplied name must match the profile name derived automatically from the SSID of the network. For an infrastructure network profile, the SSID must be supplied for the profile name. For an ad hoc network profile, the supplied name must be the SSID of the ad hoc network followed by <c>-adhoc</c>.
 /// </param>
 public void DeleteProfile(string profileName)
 {
     Wlan.ThrowIfError(
         Wlan.WlanDeleteProfile(client.clientHandle, info.interfaceGuid, profileName, IntPtr.Zero));
 }
Пример #15
0
 /// <summary>
 /// Connects to a network defined by a connection parameters structure.
 /// </summary>
 /// <param name="connectionParams">The connection paramters.</param>
 protected void Connect(Wlan.WlanConnectionParameters connectionParams)
 {
     Wlan.ThrowIfError(
         Wlan.WlanConnect(client.clientHandle, info.interfaceGuid, ref connectionParams, IntPtr.Zero));
 }
Пример #16
0
 /// <summary>
 /// Requests a scan for available networks.
 /// </summary>
 /// <remarks>
 /// The method returns immediately. Progress is reported through the <see cref="WlanNotification"/> event.
 /// </remarks>
 public void Scan()
 {
     Wlan.ThrowIfError(
         Wlan.WlanScan(client.clientHandle, info.interfaceGuid, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero));
 }
Пример #17
0
Файл: WlanApi.cs Проект: t00/seb
 /// <summary>
 /// Connects (associates) to the specified wireless network, returning either on a success to connect
 /// or a failure.
 /// </summary>
 /// <param name="connectionMode"></param>
 /// <param name="bssType"></param>
 /// <param name="profile"></param>
 /// <param name="connectTimeout"></param>
 /// <returns></returns>
 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 e = eventQueue.Dequeue();
                     if (e is WlanConnectionNotificationEventData)
                     {
                         WlanConnectionNotificationEventData wlanConnectionData = (WlanConnectionNotificationEventData)e;
                         // Check if the conditions are good to indicate either success or failure.
                         if (wlanConnectionData.notifyData.notificationSource == Wlan.WlanNotificationSource.ACM)
                         {
                             switch ((Wlan.WlanNotificationCodeAcm)wlanConnectionData.notifyData.notificationCode)
                             {
                                 case Wlan.WlanNotificationCodeAcm.ConnectionComplete:
                                     if (wlanConnectionData.connNotifyData.profileName == profile)
                                         return true;
                                     break;
                             }
                         }
                         break;
                     }
                 }
             }
         }
     }
     finally
     {
         queueEvents = false;
         eventQueue.Clear();
     }
     return false; // timeout expired and no "connection complete"
 }
Пример #18
0
Файл: WlanApi.cs Проект: t00/seb
            internal void OnWlanConnection(Wlan.WlanNotificationData notifyData, Wlan.WlanConnectionNotificationData connNotifyData)
            {
                if (WlanConnectionNotification != null)
                    WlanConnectionNotification(notifyData, connNotifyData);

                if (queueEvents)
                {
                    WlanConnectionNotificationEventData queuedEvent = new WlanConnectionNotificationEventData();
                    queuedEvent.notifyData = notifyData;
                    queuedEvent.connNotifyData = connNotifyData;
                    EnqueueEvent(queuedEvent);
                }
            }
Пример #19
0
Файл: WlanApi.cs Проект: t00/seb
 /// <summary>
 /// Retrieves the list of available networks.
 /// </summary>
 /// <param name="flags">Controls the type of networks returned.</param>
 /// <returns>A list of the available networks.</returns>
 public Wlan.WlanAvailableNetwork[] GetAvailableNetworkList(Wlan.WlanGetAvailableNetworkFlags flags = 0)
 {
     IntPtr availNetListPtr;
     Wlan.ThrowIfError(
         Wlan.WlanGetAvailableNetworkList(client.clientHandle, info.interfaceGuid, flags, IntPtr.Zero, out availNetListPtr));
     try
     {
         return ConvertAvailableNetworkListPtr(availNetListPtr);
     }
     finally
     {
         Wlan.WlanFreeMemory(availNetListPtr);
     }
 }
Пример #20
0
Файл: WlanApi.cs Проект: t00/seb
 internal void OnWlanReason(Wlan.WlanNotificationData notifyData, Wlan.WlanReasonCode reasonCode)
 {
     if (WlanReasonNotification != null)
         WlanReasonNotification(notifyData, reasonCode);
     if (queueEvents)
     {
         WlanReasonNotificationData queuedEvent = new WlanReasonNotificationData();
         queuedEvent.notifyData = notifyData;
         queuedEvent.reasonCode = reasonCode;
         EnqueueEvent(queuedEvent);
     }
 }
Пример #21
0
Файл: WlanApi.cs Проект: t00/seb
 /// <summary>
 /// Sets the profile.
 /// </summary>
 /// <param name="flags">The flags to set on the profile.</param>
 /// <param name="profileXml">The XML representation of the profile. On Windows XP SP 2, special care should be taken to adhere to its limitations.</param>
 /// <param name="overwrite">If a profile by the given name already exists, then specifies whether to overwrite it (if <c>true</c>) or return an error (if <c>false</c>).</param>
 /// <returns>The resulting code indicating a success or the reason why the profile wasn't valid.</returns>
 public Wlan.WlanReasonCode SetProfile(Wlan.WlanProfileFlags flags, string profileXml, bool overwrite)
 {
     Wlan.WlanReasonCode reasonCode;
     Wlan.ThrowIfError(
             Wlan.WlanSetProfile(client.clientHandle, info.interfaceGuid, flags, profileXml, null, overwrite, IntPtr.Zero, out reasonCode));
     return reasonCode;
 }
 public Wlan.WlanReasonCode SetProfile(Wlan.WlanProfileFlags flags, string profileXml, bool overwrite)
 {
     Wlan.WlanReasonCode reasonCode;
     Wlan.ThrowIfError(Wlan.WlanSetProfile(this.client.clientHandle, this.info.interfaceGuid, flags, profileXml, (string)null, overwrite, IntPtr.Zero, out reasonCode));
     return(reasonCode);
 }
Пример #23
0
Файл: WlanApi.cs Проект: t00/seb
 internal void OnWlanNotification(Wlan.WlanNotificationData notifyData)
 {
     if (WlanNotification != null)
         WlanNotification(notifyData);
 }
Пример #24
0
Файл: WlanApi.cs Проект: t00/seb
 /// <summary>
 /// Gets a string that describes a specified reason code.
 /// </summary>
 /// <param name="reasonCode">The reason code.</param>
 /// <returns>The string.</returns>
 public string GetStringForReasonCode(Wlan.WlanReasonCode reasonCode)
 {
     StringBuilder sb = new StringBuilder(1024); // the 1024 size here is arbitrary; the WlanReasonCodeToString docs fail to specify a recommended size
     Wlan.ThrowIfError(
         Wlan.WlanReasonCodeToString(reasonCode, sb.Capacity, sb, IntPtr.Zero));
     return sb.ToString();
 }
Пример #25
0
Файл: WlanApi.cs Проект: t00/seb
 /// <summary>
 /// Connects to a network defined by a connection parameters structure.
 /// </summary>
 /// <param name="connectionParams">The connection paramters.</param>
 protected void Connect(Wlan.WlanConnectionParameters connectionParams)
 {
     Wlan.ThrowIfError(
         Wlan.WlanConnect(client.clientHandle, info.interfaceGuid, ref connectionParams, IntPtr.Zero));
 }
Пример #26
0
Файл: WlanApi.cs Проект: t00/seb
        private static Wlan.WlanConnectionNotificationData? ParseWlanConnectionNotification(ref Wlan.WlanNotificationData notifyData)
        {
            int expectedSize = Marshal.SizeOf(typeof(Wlan.WlanConnectionNotificationData));
            if (notifyData.dataSize < expectedSize)
                return null;

            Wlan.WlanConnectionNotificationData connNotifyData =
                (Wlan.WlanConnectionNotificationData)
                Marshal.PtrToStructure(notifyData.dataPtr, typeof(Wlan.WlanConnectionNotificationData));
            if (connNotifyData.wlanReasonCode == Wlan.WlanReasonCode.Success)
            {
                IntPtr profileXmlPtr = new IntPtr(
                    notifyData.dataPtr.ToInt64() +
                    Marshal.OffsetOf(typeof(Wlan.WlanConnectionNotificationData), "profileXml").ToInt64());
                connNotifyData.profileXml = Marshal.PtrToStringUni(profileXmlPtr);
            }

            return connNotifyData;
        }
Пример #27
0
Файл: WlanApi.cs Проект: t00/seb
 /// <summary>
 /// Sets a parameter of the interface whose data type is <see cref="int"/>.
 /// </summary>
 /// <param name="opCode">The opcode of the parameter.</param>
 /// <param name="value">The value to set.</param>
 private void SetInterfaceInt(Wlan.WlanIntfOpcode opCode, int value)
 {
     IntPtr valuePtr = Marshal.AllocHGlobal(sizeof(int));
     Marshal.WriteInt32(valuePtr, value);
     try
     {
         Wlan.ThrowIfError(
             Wlan.WlanSetInterface(client.clientHandle, info.interfaceGuid, opCode, sizeof(int), valuePtr, IntPtr.Zero));
     }
     finally
     {
         Marshal.FreeHGlobal(valuePtr);
     }
 }
Пример #28
0
Файл: WlanApi.cs Проект: t00/seb
        private void OnWlanNotification(ref Wlan.WlanNotificationData notifyData, IntPtr context)
        {
            WlanInterface wlanIface;
            ifaces.TryGetValue(notifyData.interfaceGuid, out wlanIface);

            switch (notifyData.notificationSource)
            {
                case Wlan.WlanNotificationSource.ACM:
                    switch ((Wlan.WlanNotificationCodeAcm)notifyData.notificationCode)
                    {
                        case Wlan.WlanNotificationCodeAcm.ConnectionStart:
                        case Wlan.WlanNotificationCodeAcm.ConnectionComplete:
                        case Wlan.WlanNotificationCodeAcm.ConnectionAttemptFail:
                        case Wlan.WlanNotificationCodeAcm.Disconnecting:
                        case Wlan.WlanNotificationCodeAcm.Disconnected:
                            Wlan.WlanConnectionNotificationData? connNotifyData = ParseWlanConnectionNotification(ref notifyData);
                            if (connNotifyData.HasValue)
                                if (wlanIface != null)
                                    wlanIface.OnWlanConnection(notifyData, connNotifyData.Value);
                            break;
                        case Wlan.WlanNotificationCodeAcm.ScanFail:
                            {
                                int expectedSize = Marshal.SizeOf(typeof(int));
                                if (notifyData.dataSize >= expectedSize)
                                {
                                    Wlan.WlanReasonCode reasonCode = (Wlan.WlanReasonCode)Marshal.ReadInt32(notifyData.dataPtr);
                                    if (wlanIface != null)
                                        wlanIface.OnWlanReason(notifyData, reasonCode);
                                }
                            }
                            break;
                    }
                    break;
                case Wlan.WlanNotificationSource.MSM:
                    switch ((Wlan.WlanNotificationCodeMsm)notifyData.notificationCode)
                    {
                        case Wlan.WlanNotificationCodeMsm.Associating:
                        case Wlan.WlanNotificationCodeMsm.Associated:
                        case Wlan.WlanNotificationCodeMsm.Authenticating:
                        case Wlan.WlanNotificationCodeMsm.Connected:
                        case Wlan.WlanNotificationCodeMsm.RoamingStart:
                        case Wlan.WlanNotificationCodeMsm.RoamingEnd:
                        case Wlan.WlanNotificationCodeMsm.Disassociating:
                        case Wlan.WlanNotificationCodeMsm.Disconnected:
                        case Wlan.WlanNotificationCodeMsm.PeerJoin:
                        case Wlan.WlanNotificationCodeMsm.PeerLeave:
                        case Wlan.WlanNotificationCodeMsm.AdapterRemoval:
                            Wlan.WlanConnectionNotificationData? connNotifyData = ParseWlanConnectionNotification(ref notifyData);
                            if (connNotifyData.HasValue)
                                if (wlanIface != null)
                                    wlanIface.OnWlanConnection(notifyData, connNotifyData.Value);
                            break;
                    }
                    break;
            }

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