162 lines
7.0 KiB
C#
162 lines
7.0 KiB
C#
//----------------------------------------------------------------------------
|
|
//
|
|
// Copyright (c) Intel Corporation, 2012-2014 All Rights Reserved.
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
|
|
using System;
|
|
using System.Threading;
|
|
using Intel.Manageability;
|
|
using Intel.Manageability.Exceptions;
|
|
using Common.Utils;
|
|
using System.IO;
|
|
using System.Runtime.InteropServices;
|
|
|
|
namespace RemotePlatformEraseSample
|
|
{
|
|
class Program
|
|
{
|
|
[DllImport("kernel32.dll", CallingConvention = CallingConvention.StdCall)]
|
|
[return: MarshalAs(UnmanagedType.Bool)]
|
|
public static extern bool SetDefaultDllDirectories(int directoryFlags);
|
|
|
|
static void Main(string[] args)
|
|
{
|
|
// set default dll lookup directory to system
|
|
SetDefaultDllDirectories(0x00000800); //LOAD_LIBRARY_SEARCH_SYSTEM32
|
|
|
|
IAMTInstance amt = null;
|
|
ConnectionInfoEX ci = null;
|
|
bool PerformMeUnconfigure = false;
|
|
|
|
try
|
|
{
|
|
// Check if JSON path was provided as an argument. If not, default path would be used.
|
|
try
|
|
{
|
|
ci = ProgramInput.DeserializeJsonToStruct(args.Length > 0 ? args[0] : null);
|
|
}
|
|
catch (IOException e)
|
|
{
|
|
Console.WriteLine($"Could not read argument file: {e.Message}");
|
|
return;
|
|
}
|
|
|
|
amt = AMTInstanceFactory.CreateEX(ci);
|
|
}
|
|
catch (ManageabilityException e)
|
|
{
|
|
ci?.Dispose();
|
|
Console.WriteLine(e.Message);
|
|
return;
|
|
}
|
|
|
|
try
|
|
{
|
|
//RPE 3.0 step
|
|
//Relevant when VerifyStorageErase is set and GenerateSanitizationReport is supported
|
|
//Subscribe to iAMT0071 WS-Event for report generation
|
|
//Update the subscriber IP and port in this method: SubscribeToWsEvenStorageEraseReport, before invoking this method
|
|
RemotePlatformEraseFunctionality.SubscribeToWsEvenStorageEraseReport(amt);
|
|
|
|
//RPE 3.0 step
|
|
//Relevant when VerifyStorageErase is set and GenerateSanitizationReport is supported
|
|
//Relevant if the previous step is called (SubscribeToWsEvenStorageEraseReport)
|
|
//Start WS Eventing Listener to get the Erase Report event, when sent from AMT
|
|
//Note: The listener is stopped in 2 cases: either when the event arrives or if timeout is over and the event is not sent yet
|
|
RemotePlatformEraseFunctionality.StartWsEventingListener(amt);
|
|
|
|
//Check if RPE is supported in BIOS
|
|
if (!RemotePlatformEraseFunctionality.IsRPESupported(amt))
|
|
return;
|
|
|
|
//Check if RPE is enabled in BIOS
|
|
if (!RemotePlatformEraseFunctionality.IsRPEEnabledInBIOS(amt))
|
|
return;
|
|
|
|
//Check if RPE is enabled in AMT
|
|
if (!RemotePlatformEraseFunctionality.IsRPEEnabledInAMT(amt))
|
|
{
|
|
//Enable RPE in AMT
|
|
RemotePlatformEraseFunctionality.EnableRPEInAMT(amt);
|
|
}
|
|
|
|
//Display the RPE Erase options
|
|
RemotePlatformEraseFunctionality.DisplayRPEEraseOptions(amt);
|
|
|
|
//Set RPE boot parameters
|
|
//User must update the desired RPE options in this method: SetNextBootToRPE() before triggering this step.
|
|
//By default, all options are set to false.
|
|
RemotePlatformEraseFunctionality.SetNextBootToRPE(amt);
|
|
|
|
//Subscribe to Remote Platform Erase events in event log and get current number of events in the event log.
|
|
/* This method returns the current number of events in the event log,
|
|
* in order to display in this sample only the RPE events from the current flow.
|
|
*/
|
|
uint numOfRecordsBeforeRPE;
|
|
RemotePlatformEraseFunctionality.SubscribeToRPEEvents(amt, out numOfRecordsBeforeRPE);
|
|
|
|
//Perform reboot
|
|
RemotePlatformEraseFunctionality.PerformReboot(amt);
|
|
|
|
//Retrieve BIOS Last status
|
|
/* BIOS last status return value depends on the current RPE flow state.
|
|
* You might want to add here a retry loop to get the updated status
|
|
*/
|
|
RemotePlatformEraseFunctionality.GetBIOSLastStatus(amt);
|
|
|
|
//RPE 3.0 step
|
|
//Relevant when SecureEraseAllSSDs and VerifyStorageErase are set and GenerateSanitizationReport is supported
|
|
//Get erase report from AMT's Web-Storage
|
|
//Add delay until WS Event for Erase Report is sent. Delay time might vary.
|
|
Thread.Sleep(90000);
|
|
if (RemotePlatformEraseFunctionality.IsWsEventSent)
|
|
{
|
|
RemotePlatformEraseFunctionality.GetStorageEraseReportFromWebStorage(amt);
|
|
}
|
|
// stop listener if timeout has passed and event was not sent
|
|
//In case BIOS failed to send report to AMT, a PET event will be sent for this failure in DisplayRPEEventsFromLog() step
|
|
else
|
|
{
|
|
Console.WriteLine("WS-Event for Erase report was not sent, stopping WS-Eventing listener");
|
|
RemotePlatformEraseFunctionality.Listener.StopListening();
|
|
}
|
|
|
|
//Display RPE events from event log
|
|
//In case RPE3.0 is supported, options are set, and BIOS failed to send report to AMT, a specific PET event will be sent for this failure
|
|
/* In order to get all RPE events from log,
|
|
* a delay may be added here until the erase operation is complete.
|
|
* Delay time may vary.
|
|
*/
|
|
Thread.Sleep(60000);
|
|
RemotePlatformEraseFunctionality.DisplayRPEEventsFromLog(amt, numOfRecordsBeforeRPE);
|
|
|
|
//Disable RPE on AMT
|
|
RemotePlatformEraseFunctionality.DisableRPEInAMT(amt);
|
|
|
|
/* Me UnConfigure Option */
|
|
//Set PerformMeUnconfigure parameter to true in order to perform ME unconfigure.
|
|
|
|
if (PerformMeUnconfigure)
|
|
{
|
|
//Check if configuration data reset is supported
|
|
RemotePlatformEraseFunctionality.SetNextBootToMEUnconfigure(amt);
|
|
|
|
//Get log from audit log to show that configurationDataReset was set
|
|
RemotePlatformEraseFunctionality.GetMEUnconfigureRecordFromAuditLog(amt);
|
|
|
|
//Perform Reboot
|
|
RemotePlatformEraseFunctionality.PerformReboot(amt);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine(ex.Message);
|
|
}
|
|
finally
|
|
{
|
|
amt?.Dispose();
|
|
}
|
|
}
|
|
}
|
|
} |