Example #1
0
        private void SetInterface(WlanIntfOpcode opCode, Object value)
        {
            IntPtr data;
            int    dataSize = Marshal.SizeOf(value);

            data = Marshal.AllocHGlobal(dataSize);
            switch (opCode)
            {
            case WlanIntfOpcode.AutoconfEnabled:
            case WlanIntfOpcode.BackgroundScanEnabled:
            case WlanIntfOpcode.MediaStreamingMode:
            case WlanIntfOpcode.CurrentOperationMode:
            //Marshal.WriteInt32(data, Convert.ToInt32((uint)value));
            //break;
            case WlanIntfOpcode.BssType:
                Marshal.WriteInt32(data, (int)value);
                break;

            case WlanIntfOpcode.RadioState:
                Marshal.StructureToPtr(value, data, false);
                break;

            default:
                throw new NotSupportedException();
            }
            try {
                Util.ThrowIfError(NativeMethods.WlanSetInterface(client.clientHandle, Guid, opCode, (uint)dataSize, data, IntPtr.Zero));
            } finally {
                Marshal.FreeHGlobal(data);
            }
        }
Example #2
0
 public static extern int WlanSetInterface(
     [In] IntPtr clientHandle,
     [In, MarshalAs(UnmanagedType.LPStruct)] Guid interfaceGuid,
     [In] WlanIntfOpcode opCode,
     [In] uint dataSize,
     [In] IntPtr pData,
     [In, Out] IntPtr pReserved);
Example #3
0
 internal static extern uint WlanQueryInterface([In] IntPtr hClientHandle,
                                                [In] ref Guid pInterfaceGuid,
                                                WlanIntfOpcode OpCode,
                                                IntPtr pReserved,
                                                [Out] out uint pdwDataSize,
                                                ref IntPtr ppData,
                                                IntPtr pWlanOpcodeValueType);
Example #4
0
 public static extern int WlanQueryInterface(
     [In] IntPtr clientHandle,
     [In, MarshalAs(UnmanagedType.LPStruct)] Guid interfaceGuid,
     [In] WlanIntfOpcode opCode,
     [In, Out] IntPtr pReserved,
     [Out] out int dataSize,
     [Out] out IntPtr ppData,
     [Out] out WlanOpcodeValueType wlanOpcodeValueType);
Example #5
0
 internal static extern int WlanQueryInterface(
     [In] IntPtr hClientHandle,
     [In, MarshalAs(UnmanagedType.LPStruct)] Guid interfaceGuid,
     [In] WlanIntfOpcode OpCode,
     [In, Out] IntPtr pReserved,
     [Out] out uint pdwDataSize,
     [Out] out IntPtr ppData,
     [Out, Optional] out WlanOpcodeValueType pWlanOpcodeValueType
     );
Example #6
0
        /// <summary>
        /// Sets a parameter of the interface whose data type is <see cref="int"/>.
        ///
        /// Possible Win32 errors:
        /// ERROR_ACCESS_DENIED: The caller does not have sufficient permissions to perform the requested operation.
        /// ERROR_GEN_FAILURE: The parameter specified by OpCode is not supported by the driver or NIC.
        /// ERROR_INVALID_HANDLE: The handle hClientHandle was not found in the handle table.
        /// ERROR_INVALID_PARAMETER: One parameter is likely NULL
        /// RPC_STATUS: Various return codes to indicate errors occurred when connecting.
        /// </summary>
        /// <param name="opCode">The opcode of the parameter.</param>
        /// <param name="value">The value to set.</param>
        private void SetInterfaceInt(WlanIntfOpcode opCode, int value)
        {
            IntPtr valuePtr = Marshal.AllocHGlobal(sizeof(int));

            Marshal.WriteInt32(valuePtr, value);

            try
            {
                WlanInterop.ThrowIfError(WlanInterop.WlanSetInterface(client.clientHandle, info.interfaceGuid, opCode, sizeof(int), valuePtr, IntPtr.Zero));
            }
            finally
            {
                Marshal.FreeHGlobal(valuePtr);
            }
        }
Example #7
0
        /// <summary>
        /// Gets a parameter of the interface whose data type is <see cref="int"/>.
        ///
        /// Possible Win32 errors:
        /// ERROR_ACCESS_DENIED: The caller does not have sufficient permissions to perform the requested operation.
        /// ERROR_INVALID PARAMETER: hClientHandle is NULL or invalid, pInterfaceGuid is NULL, pReserved is not NULL, ppData is NULL, or pdwDataSize is NULL.
        /// ERROR_INVALID_HANDLE: The handle hClientHandle was not found in the handle table.
        /// ERROR_INVALID_STATE: OpCode is set to wlan_intf_opcode_current_connection and the client is not currently connected to a network.
        /// ERROR_NOT_ENOUGH_MEMORY: Failed to allocate memory for the query results.
        /// RPC_STATUS: Various error codes.
        /// </summary>
        /// <param name="opCode">The opcode of the parameter.</param>
        /// <returns>The integer value.</returns>
        private int GetInterfaceInt(WlanIntfOpcode opCode)
        {
            IntPtr valuePtr;
            int    valueSize;
            WlanOpcodeValueType opcodeValueType;

            WlanInterop.ThrowIfError(WlanInterop.WlanQueryInterface(client.clientHandle, info.interfaceGuid, opCode, IntPtr.Zero, out valueSize, out valuePtr, out opcodeValueType));

            try
            {
                return(Marshal.ReadInt32(valuePtr));
            }
            finally
            {
                WlanInterop.WlanFreeMemory(valuePtr);
            }
        }
Example #8
0
        private Object QueryInterface(WlanIntfOpcode opCode)
        {
            IntPtr data;
            uint   dataSize;
            WlanOpcodeValueType opcodeValueType;

            Util.ThrowIfError(NativeMethods.WlanQueryInterface(client.clientHandle, Guid, opCode, IntPtr.Zero, out dataSize, out data, out opcodeValueType));
            try {
                switch (opCode)
                {
                case WlanIntfOpcode.AutoconfEnabled:
                case WlanIntfOpcode.BackgroundScanEnabled:
                case WlanIntfOpcode.MediaStreamingMode:
                case WlanIntfOpcode.SupportedSafeMode:
                case WlanIntfOpcode.CertifiedSafeMode:
                    return(Convert.ToBoolean(Marshal.ReadByte(data)));

                case WlanIntfOpcode.ChannelNumber:
                case WlanIntfOpcode.CurrentOperationMode:
                // type to uint
                case WlanIntfOpcode.Rssi:
                case WlanIntfOpcode.BssType:
                case WlanIntfOpcode.InterfaceState:
                    return(Marshal.ReadInt32(data));

                case WlanIntfOpcode.RadioState:
                    return(Marshal.PtrToStructure(data, typeof(WlanRadioState)));

                case WlanIntfOpcode.CurrentConnection:
                    return(Marshal.PtrToStructure(data, typeof(WlanConnectionAttributes)));

                case WlanIntfOpcode.SupportedInfrastructureAuthCipherPairs:
                case WlanIntfOpcode.SupportedAdhocAuthCipherPairs:
                case WlanIntfOpcode.SupportedCountryOrRegionStringList:
                case WlanIntfOpcode.Statistics:
                default:
                    throw new NotSupportedException();
                }
            } finally {
                NativeMethods.WlanFreeMemory(data);
            }
        }
Example #9
0
 public static extern uint WlanQueryInterface(IntPtr hClientHandle, [MarshalAs(UnmanagedType.LPStruct)] Guid pInterfaceGuid, WlanIntfOpcode opCode, IntPtr pReserved, out uint pdwDataSize, ref IntPtr ppData, IntPtr pWlanOpcodeValueType);
Example #10
0
		/// <summary>
		/// Gets a parameter of the interface whose data type is <see cref="int"/>.
		/// 
		/// Possible Win32 errors:
		/// ERROR_ACCESS_DENIED: The caller does not have sufficient permissions to perform the requested operation.
		/// ERROR_INVALID PARAMETER: hClientHandle is NULL or invalid, pInterfaceGuid is NULL, pReserved is not NULL, ppData is NULL, or pdwDataSize is NULL.
		/// ERROR_INVALID_HANDLE: The handle hClientHandle was not found in the handle table.
		/// ERROR_INVALID_STATE: OpCode is set to wlan_intf_opcode_current_connection and the client is not currently connected to a network.
		/// ERROR_NOT_ENOUGH_MEMORY: Failed to allocate memory for the query results.
		/// RPC_STATUS: Various error codes.
		/// </summary>
		/// <param name="opCode">The opcode of the parameter.</param>
		/// <returns>The integer value.</returns>
		private int GetInterfaceInt(WlanIntfOpcode opCode)
		{
			IntPtr valuePtr;
			int valueSize;
			WlanOpcodeValueType opcodeValueType;

			WlanInterop.ThrowIfError(WlanInterop.WlanQueryInterface(client.clientHandle, info.interfaceGuid, opCode, IntPtr.Zero, out valueSize, out valuePtr, out opcodeValueType));

			try
			{
				return Marshal.ReadInt32(valuePtr);
			}
			finally
			{
				WlanInterop.WlanFreeMemory(valuePtr);
			}
		}
Example #11
0
		/// <summary>
		/// Sets a parameter of the interface whose data type is <see cref="int"/>.
		/// 
		/// Possible Win32 errors:
		/// ERROR_ACCESS_DENIED: The caller does not have sufficient permissions to perform the requested operation.
		/// ERROR_GEN_FAILURE: The parameter specified by OpCode is not supported by the driver or NIC.
		/// ERROR_INVALID_HANDLE: The handle hClientHandle was not found in the handle table.
		/// ERROR_INVALID_PARAMETER: One parameter is likely NULL
		/// RPC_STATUS: Various return codes to indicate errors occurred when connecting.
		/// </summary>
		/// <param name="opCode">The opcode of the parameter.</param>
		/// <param name="value">The value to set.</param>
		private void SetInterfaceInt(WlanIntfOpcode opCode, int value)
		{
			IntPtr valuePtr = Marshal.AllocHGlobal(sizeof(int));
			Marshal.WriteInt32(valuePtr, value);

			try
			{
				WlanInterop.ThrowIfError(WlanInterop.WlanSetInterface(client.clientHandle, info.interfaceGuid, opCode, sizeof(int), valuePtr, IntPtr.Zero));
			}
			finally
			{
				Marshal.FreeHGlobal(valuePtr);
			}
		}