Example #1
0
        private static bool SetRadioState(Guid interfaceGuid, Wlan.Dot11RadioState radioState)
        {
            //set Wlan.WlanPhyRadioState struct state's value.
            var state = new Wlan.WlanPhyRadioState
            {
                dwPhyIndex = (int)Wlan.Dot11PhyType.Any,
                dot11SoftwareRadioState = radioState,
            };
            var size = Marshal.SizeOf(state);

            var pointer = IntPtr.Zero;

            try
            {
                pointer = Marshal.AllocHGlobal(size);
                Marshal.StructureToPtr(state, pointer, false);

                var clientHandle = IntPtr.Zero;
                try
                {
                    uint negotiatedVersion;
                    var  result = Wlan.WlanOpenHandle(
                        Wlan.WLAN_CLIENT_VERSION_LONGHORN,
                        IntPtr.Zero,
                        out negotiatedVersion,
                        out clientHandle);
                    if (result != 0)
                    {
                        return(false);
                    }

                    result = Wlan.WlanSetInterface(
                        clientHandle,
                        interfaceGuid,
                        Wlan.WlanIntfOpcode.RadioState,
                        (uint)size,
                        pointer,
                        IntPtr.Zero);

                    return(result == 0);
                }
                finally
                {
                    Wlan.WlanCloseHandle(
                        clientHandle,
                        IntPtr.Zero);
                }
            }
            finally
            {
                Marshal.FreeHGlobal(pointer);
            }
        }
Example #2
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;
     }
 }
Example #3
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;
     }
 }