Esempio n. 1
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 WlanBssEntry[] GetNetworkBssList(Dot11Ssid ssid, Dot11BssType bssType, bool securityEnabled)
        {
            IntPtr ssidPtr = Marshal.AllocHGlobal(Marshal.SizeOf(ssid));

            Marshal.StructureToPtr(ssid, ssidPtr, false);

            try
            {
                IntPtr bssListPtr;
                WlanInterop.ThrowIfError(WlanInterop.WlanGetNetworkBssList(client.clientHandle, info.interfaceGuid, ssidPtr, bssType, securityEnabled, IntPtr.Zero, out bssListPtr));

                try
                {
                    return(ConvertBssListPtr(bssListPtr));
                }
                finally
                {
                    WlanInterop.WlanFreeMemory(bssListPtr);
                }
            }
            finally
            {
                Marshal.FreeHGlobal(ssidPtr);
            }
        }
Esempio n. 2
0
        /// <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(WlanConnectionMode connectionMode, Dot11BssType bssType, Dot11Ssid ssid, WlanConnectionFlags flags)
        {
            WlanConnectionParameters connectionParams = new 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);
        }