using System; using System.Collections.Generic; using System.Linq; using System.Text; using Intel.Management.Wsman; namespace Intel.Management.PSModule.Amt { public enum PasswordModel { Coupled=0, Separate=1, HashedSeparate=2 } public class AmtSetupParameters { IManagedInstance _serviceObj; public AmtSetupParameters(IManagedInstance serviceObj) { _serviceObj = serviceObj; } public string ProvisioningServerOTP { get { return _serviceObj.GetProperty("ProvisioningServerOTP").ToString(); } } public PasswordModel PasswordModel { get { return (PasswordModel)int.Parse(_serviceObj.GetProperty("PasswordModel").ToString()); } } public bool ZeroTouchConfigurationEnabled { get { return bool.Parse(_serviceObj.GetProperty("ZeroTouchConfigurationEnabled").ToString()); } } public string ConfigurationServerFQDN { get { return _serviceObj.GetProperty("ConfigurationServerFQDN").ToString(); } } public void PartialUnprovision() { IWsmanConnection conn = _serviceObj.Connection; IManagedReference refToService = conn.NewReference("AMT_SetupAndConfigurationService"); IManagedInstance inputObj = refToService.CreateMethodInput("PartialUnprovision"); IManagedInstance outObj = refToService.InvokeMethod(inputObj); switch (outObj.GetProperty("ReturnValue").ToString()) { case "0": break; case "1": AmtException.ThrowInvokeError(outObj, "Internal Error"); break; case "16": AmtException.ThrowInvokeError(outObj, "Not Permitted"); break; case "2076": AmtException.ThrowInvokeError(outObj, "Bocking Component"); break; default: AmtException.ThrowInvokeError(outObj); break; } } } class SetupService : DriveContainer { enum ProvisioningMode { Admin =1, Client=4, } enum ProvisioningState { Pre=0, In=1, Post=2, } class SetupMode : DriveItem { public SetupMode(ProvisioningState value,DriveItem parent) :base("SetupMode",value,parent) { } public override void SetItem(object values, DriveProvider provider) { IWsmanConnection conn = ((AmtRootService)GetRoot()).Connection; IManagedReference refToService = conn.NewReference("AMT_SetupAndConfigurationService"); if (string.Compare(values.ToString(), "Pre", true) == 0) { IManagedInstance inputObj = refToService.CreateMethodInput("Unprovision"); inputObj.SetProperty("ProvisioningMode", "1"); IManagedInstance outObj = refToService.InvokeMethod(inputObj); switch (outObj.GetProperty("ReturnValue").ToString()) { case "0": break; case "1": AmtException.ThrowInvokeError(outObj, "Internal Error"); break; case "16": AmtException.ThrowInvokeError(outObj, "Not Permitted"); break; case "36": AmtException.ThrowInvokeError(outObj, "Invalid Parameter"); break; case "2076": AmtException.ThrowInvokeError(outObj, "Bocking Component"); break; default: AmtException.ThrowInvokeError(outObj); break; } } else if (string.Compare(values.ToString(), "Post", true) == 0) { IManagedInstance inputObj = refToService.CreateMethodInput("CommitChanges"); IManagedInstance outObj = refToService.InvokeMethod(inputObj); switch (outObj.GetProperty("ReturnValue").ToString()) { case "0": break; case "1": AmtException.ThrowInvokeError(outObj, "Internal Error"); break; case "38": AmtException.ThrowInvokeError(outObj, "Flash write limit exceeded"); break; case "2057": AmtException.ThrowInvokeError(outObj, "Data missing"); break; default: AmtException.ThrowInvokeError(outObj); break; } } } } public SetupService(DriveItem parent) : base("Setup",parent) { } public override void GetChildItems(ChildWriter writer) { IWsmanConnection conn = ((AmtRootService)GetRoot()).Connection; IManagedInstance serviceObj= conn.NewReference("AMT_SetupAndConfigurationService").Get(); writer.Add(new DriveItem("Parameters", new AmtSetupParameters(serviceObj), this)); ProvisioningMode mode = (ProvisioningMode)int.Parse(serviceObj.GetProperty("ProvisioningMode").ToString()); writer.Add(new DriveItem("ProvisioningMode", mode, this)); ProvisioningState state = (ProvisioningState)int.Parse(serviceObj.GetProperty("ProvisioningState").ToString()); writer.Add(new SetupMode(state, this)); } } }