예제 #1
0
        /// <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());
        }
            /// <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;
                int ret = Wlan.WlanSetProfile(client.clientHandle, info.interfaceGuid, flags, profileXml, null, overwrite, IntPtr.Zero, out reasonCode);

                Wlan.ThrowIfError(ret);
                return(reasonCode);
            }
예제 #3
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);
                }
            }
예제 #4
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);
                }
            }
예제 #5
0
            /// <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)
            {
                IntPtr availNetListPtr;

                Wlan.ThrowIfError(
                    Wlan.WlanGetAvailableNetworkList(client.clientHandle, info.interfaceGuid, flags, IntPtr.Zero, out availNetListPtr));
                try {
                    return(ConvertAvailableNetworkListPtr(availNetListPtr));
                } finally {
                    Wlan.WlanFreeMemory(availNetListPtr);
                }
            }
예제 #6
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);
                }
            }
예제 #7
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 = new Wlan.WlanNotificationCallbackDelegate(OnWlanNotification);
         Wlan.ThrowIfError(Wlan.WlanRegisterVirtualStationNotification(clientHandle, true, IntPtr.Zero));
         Wlan.ThrowIfError(
             Wlan.WlanRegisterNotification(clientHandle, Wlan.WlanNotificationSource.All, false, wlanNotificationCallback, IntPtr.Zero, IntPtr.Zero, out prevSrc));
     } catch {
         Wlan.WlanCloseHandle(clientHandle, IntPtr.Zero);
         throw;
     }
 }
예제 #8
0
            /// <summary>
            /// Gets the profile's XML specification.
            /// </summary>
            /// <param name="profileName">The name of the profile.</param>
            /// <returns>The XML document.</returns>
            public string GetProfileXml(string profileName)
            {
                IntPtr profileXmlPtr;

                Wlan.WlanProfileFlags flags;
                Wlan.WlanAccess       access;
                Wlan.ThrowIfError(
                    Wlan.WlanGetProfile(client.clientHandle, info.interfaceGuid, profileName, IntPtr.Zero, out profileXmlPtr, out flags,
                                        out access));
                try {
                    return(Marshal.PtrToStringUni(profileXmlPtr));
                } finally {
                    Wlan.WlanFreeMemory(profileXmlPtr);
                }
            }
예제 #9
0
 /// <summary>
 /// Creates a new instance of a Native Wifi service client.
 /// </summary>
 protected 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;
     }
 }
예제 #10
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);
                }
            }
예제 #11
0
            public Wlan.WlanInterfaceCapability GetInterfaceCapability()
            {
                IntPtr capabilityPtr;

                Wlan.ThrowIfError(
                    Wlan.WlanGetInterfaceCapability(client.clientHandle, info.interfaceGuid, IntPtr.Zero, out capabilityPtr));
                try
                {
                    //Wlan.WlanInterfaceCapability capability = new Wlan.WlanInterfaceCapability();

                    Wlan.WlanInterfaceCapability capability = (Wlan.WlanInterfaceCapability)Marshal.PtrToStructure(capabilityPtr, typeof(Wlan.WlanInterfaceCapability));

                    return(capability);
                }
                finally
                {
                    Wlan.WlanFreeMemory(capabilityPtr);
                }
            }
예제 #12
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);
                }
            }
예제 #13
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));
 }
예제 #14
0
 /// <summary>
 /// Disconnects to a network
 /// </summary>
 public void Disconnect()
 {
     Wlan.ThrowIfError(
         Wlan.WlanDisconnect(client.clientHandle, info.interfaceGuid, 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));
 }