192 lines
7.0 KiB
C#
192 lines
7.0 KiB
C#
//----------------------------------------------------------------------------
|
|
//
|
|
// Copyright (c) Intel Corporation, 2009-2014 All Rights Reserved.
|
|
//
|
|
// File: KVMFunctionality.cs
|
|
//
|
|
// Contents: Demonstrate the IKVM interface.
|
|
//
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using Intel.Manageability;
|
|
using Intel.Manageability.KVM;
|
|
using Intel.Manageability.Exceptions;
|
|
using System.Security;
|
|
|
|
namespace KVMSample
|
|
{
|
|
public class KVMFunctionality
|
|
{
|
|
/// <summary>
|
|
/// Get KVM capabilities
|
|
/// </summary>
|
|
/// <param name="amt">The Intel AMT instance</param>
|
|
public static void DisplayCapabilities(IAMTInstance amt)
|
|
{
|
|
try
|
|
{
|
|
KVMCapabilities capabilities = amt.KVMSetup.GetCapabilities();
|
|
Console.WriteLine("KVM Capabilities:\n=================\n");
|
|
Console.WriteLine("Default port (5900): {0}", (capabilities.IsDefaultPortEnable) ? "enable" : "disable");
|
|
Console.WriteLine("Redirection port: {0}", (capabilities.IsRedirectionPortEnable) ? "enable" : "disable");
|
|
Console.WriteLine("Opt-In policy: {0}", (capabilities.OptInPolicyEnable) ? "enable" : "disable");
|
|
Console.WriteLine("Opt-In policy timeout: {0}", capabilities.OptInPolicyTimeout);
|
|
Console.WriteLine("TCP Session timeout: {0}", capabilities.TcpSessionTimeout);
|
|
Console.WriteLine("Default visible screen: {0}", capabilities.VisibleScreen);
|
|
}
|
|
catch (KVMManageabilityException ex)
|
|
{
|
|
Console.WriteLine("Failed to get KVM Capabilities with status: " + ex.Message);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Set the state of the KVM ports
|
|
/// </summary>
|
|
/// <param name="amt">The Intel AMT instance</param>
|
|
/// <param name="ports">The ports to set. Default port is no longer supported. See remarks.</param>
|
|
/// <remarks>
|
|
/// NOTE:KVM Default port (5900) is no longer supported, starting from the following releases.
|
|
/// KabyLake: 11.8.94
|
|
/// CannonLake: 12.0.93
|
|
/// CometLake: 14.1.70
|
|
/// TigerLake: 15.0.45
|
|
/// AlderLake, RaptorLake: 16.1.25
|
|
/// Attempting to configure a RFB password or enabling the port via IPS_KVMRedirectionSettingData.PUT
|
|
/// will return unsupported message.
|
|
/// </remarks>
|
|
public static void SetPortsState(IAMTInstance amt, KVMPortsState ports)
|
|
{
|
|
try
|
|
{
|
|
Console.Write("Setting port state...\t");
|
|
amt.KVMSetup.SetPortsState(ports);
|
|
Console.WriteLine("Success");
|
|
}
|
|
catch (KVMManageabilityException ex)
|
|
{
|
|
Console.WriteLine("Failed with status: " + ex.Message);
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Set the default monitor
|
|
/// </summary>
|
|
/// <param name="amt">The Intel AMT instance</param>
|
|
public static void SetDefaultMonitor(IAMTInstance amt)
|
|
{
|
|
try
|
|
{
|
|
Console.Write("Setting default monitor...\t");
|
|
List<VisibleScreen> screens = amt.KVMSetup.GetAvailableMonitors();
|
|
if (screens.Contains(VisibleScreen.Monitor0))
|
|
amt.KVMSetup.SetDefaultMonitor(VisibleScreen.Monitor0);
|
|
Console.WriteLine("Success");
|
|
}
|
|
catch (KVMManageabilityException ex)
|
|
{
|
|
Console.WriteLine("Failed with status: " + ex.Message);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// Set the RFB password
|
|
/// </summary>
|
|
/// <param name="amt">The Intel AMT instance</param>
|
|
/// <param name="password">The new RFB password</param>
|
|
/// <remarks>
|
|
/// NOTE: KVM Default port (5900) and configuring an RFB password are no longer supported, starting from the following releases.
|
|
/// KabyLake: 11.8.94
|
|
/// CannonLake: 12.0.93
|
|
/// CometLake: 14.1.70
|
|
/// TigerLake: 15.0.45
|
|
/// AlderLake, RaptorLake: 16.1.25
|
|
/// Attempting to configure a RFB password or enabling the port via IPS_KVMRedirectionSettingData.PUT
|
|
/// will return unsupported message.
|
|
/// </remarks>
|
|
public static void SetNewRFBPass(IAMTInstance amt, SecureString password)
|
|
{
|
|
try
|
|
{
|
|
Console.Write("Setting RFB Password...\t");
|
|
amt.KVMSetup.SetRFBPassword(password);
|
|
Console.WriteLine("Success");
|
|
}
|
|
catch (KVMManageabilityException ex)
|
|
{
|
|
Console.WriteLine("Failed with status: " + ex.Message);
|
|
}
|
|
catch (ManageabilityException ex)
|
|
{
|
|
Console.WriteLine("Failed with status: " + ex.Message);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Set the opt-in timeout
|
|
/// </summary>
|
|
/// <param name="amt">The Intel AMT instance</param>
|
|
/// <param name="timeout">The timeout to set</param>
|
|
public static void SetOptInTimeout(IAMTInstance amt, ushort timeout)
|
|
{
|
|
try
|
|
{
|
|
Console.Write("Setting Opt-In timeout...\t");
|
|
amt.KVMSetup.SetOptInTimeout(timeout);
|
|
Console.WriteLine("Success");
|
|
}
|
|
catch (KVMManageabilityException ex)
|
|
{
|
|
Console.WriteLine("Failed with status: " + ex.Message);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Set the TCP session timeout
|
|
/// </summary>
|
|
/// <param name="amt">The Intel AMT instance</param>
|
|
/// <param name="timeout">The timeout to set</param>
|
|
public static void SetTCPSessionTimeout(IAMTInstance amt, ushort timeout)
|
|
{
|
|
try
|
|
{
|
|
Console.Write("Setting TCP session timeout...\t");
|
|
amt.KVMSetup.SetSessionTimeout(timeout);
|
|
Console.WriteLine("Success");
|
|
}
|
|
catch (KVMManageabilityException ex)
|
|
{
|
|
Console.WriteLine("Failed with status: " + ex.Message);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Enable the KVM interface
|
|
/// </summary>
|
|
/// <param name="amt">The Intel AMT instance</param>
|
|
public static void EnableKVMInterface(IAMTInstance amt)
|
|
{
|
|
try
|
|
{
|
|
Console.Write("Enable KVM interface...\t");
|
|
if (amt.KVMSetup.GetInterfaceState())
|
|
Console.WriteLine("\nKVM Interface is already enable.");
|
|
else
|
|
{
|
|
amt.KVMSetup.SetInterfaceState(true);
|
|
Console.WriteLine("Success");
|
|
}
|
|
}
|
|
catch (KVMManageabilityException ex)
|
|
{
|
|
Console.WriteLine("Failed with status: " + ex.Message);
|
|
}
|
|
}
|
|
}
|
|
} |