public Wlan.WlanAvailableNetwork[] GetAvailableNetworkList(Wlan.WlanGetAvailableNetworkFlags flags = (Wlan.WlanGetAvailableNetworkFlags) 0)
            {
                IntPtr availableNetworkListPtr;

                Wlan.ThrowIfError(Wlan.WlanGetAvailableNetworkList(this.client.clientHandle, this.info.interfaceGuid, flags, IntPtr.Zero, out availableNetworkListPtr));
                try
                {
                    return(WlanClient.WlanInterface.ConvertAvailableNetworkListPtr(availableNetworkListPtr));
                }
                finally
                {
                    Wlan.WlanFreeMemory(availableNetworkListPtr);
                }
            }
            public Wlan.WlanBssEntry[] GetNetworkBssList()
            {
                IntPtr wlanBssList;

                Wlan.ThrowIfError(Wlan.WlanGetNetworkBssList(this.client.clientHandle, this.info.interfaceGuid, IntPtr.Zero, Wlan.Dot11BssType.Any, false, IntPtr.Zero, out wlanBssList));
                try
                {
                    return(WlanClient.WlanInterface.ConvertBssListPtr(wlanBssList));
                }
                finally
                {
                    Wlan.WlanFreeMemory(wlanBssList);
                }
            }
            private void SetInterfaceInt(Wlan.WlanIntfOpcode opCode, int value)
            {
                IntPtr num = Marshal.AllocHGlobal(4);

                Marshal.WriteInt32(num, value);
                try
                {
                    Wlan.ThrowIfError(Wlan.WlanSetInterface(this.client.clientHandle, this.info.interfaceGuid, opCode, 4U, num, IntPtr.Zero));
                }
                finally
                {
                    Marshal.FreeHGlobal(num);
                }
            }
Exemplo n.º 4
0
            /// <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);
                }
            }
 public WlanClient()
 {
     Wlan.ThrowIfError(Wlan.WlanOpenHandle(1U, IntPtr.Zero, out this.negotiatedVersion, out this.clientHandle));
     try
     {
         this.wlanNotificationCallback = new Wlan.WlanNotificationCallbackDelegate(this.OnWlanNotification);
         Wlan.WlanNotificationSource prevNotifSource;
         Wlan.ThrowIfError(Wlan.WlanRegisterNotification(this.clientHandle, Wlan.WlanNotificationSource.All, false, this.wlanNotificationCallback, IntPtr.Zero, IntPtr.Zero, out prevNotifSource));
     }
     catch
     {
         this.Close();
         throw;
     }
 }
Exemplo n.º 6
0
            /// <summary>
            /// Retrieves the basic service sets (BSS) list of all available networks.
            /// </summary>
            public Wlan.WlanBssEntry[] GetNetworkBssList()
            {
                IntPtr bssListPtr;

                Wlan.ThrowIfError(
                    Wlan.WlanGetNetworkBssList(client.clientHandle, info.interfaceGuid, IntPtr.Zero, Wlan.Dot11BssType.Any, false, IntPtr.Zero, out bssListPtr));
                try
                {
                    return(ConvertBssListPtr(bssListPtr));
                }
                finally
                {
                    Wlan.WlanFreeMemory(bssListPtr);
                }
            }
            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);
                }
            }
            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);
                }
            }
Exemplo n.º 9
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);
                }
            }
Exemplo n.º 10
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;
     }
 }
            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);
                }
            }
            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);
                }
            }
Exemplo n.º 13
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);
                }
            }
Exemplo n.º 14
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);
                }
            }
Exemplo n.º 15
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));
 }
Exemplo n.º 16
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));
 }
Exemplo n.º 17
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));
 }
 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);
 }