1017 lines
28 KiB
C++
Raw Blame History

//----------------------------------------------------------------------------
//
// Copyright (C) 2008 Intel Corporation
//
// File: RemoteAccessAdminFlow.cpp
//
// Contents: Api code for Intel(R) Active Management Technology
// (Intel<65> AMT) RemoteAccessAdmin Sample.
//
// Notes: This file contains the RemoteAccessAdminFlow methods implementation.
//
//----------------------------------------------------------------------------
#include "RemoteAccessAdminFlow.h"
#include "AMT_RemoteAccessCredentialContext.h"
#include "AMT_ManagementPresenceRemoteSAP.h"
#include "AMT_MPSUsernamePassword.h"
#include "AMT_RemoteAccessService.h"
#include "AMT_UserInitiatedConnectionService.h"
#include "AMT_RemoteAccessPolicyAppliesToMPS.h"
#include "LogicException.h"
#include "CommonDefinitions.h"
#include "CmdLineArguments.h"
#include "AssociationTraversalTypedUtils.h"
// Include from CIM Framework
#include "CimOpenWsmanClient.h"
#include "CommonDefinitions.h"
using namespace std;
using namespace ExceptionNamespace;
using namespace Intel::Manageability::Cim::Typed;
#pragma region CONSTANTS
const string DEFAULT_SERVER_USERNAME = "myUser";
const string UPDATED_SERVER_USERNAME = "updatedUser";
const string DEFAULT_SERVER_PASSWORD = "myPass!98";
const string UPDATED_SERVER_PASSWORD = "updatedPass!98";
const string DEFAULT_SERVER_ADDRESS = "10.0.0.12";
const char* DEFAULT_SERVER_CN = "SDKSampleMPS";
const unsigned short DEFAULT_SERVER_PORT = 16897;
const unsigned short UPDATED_SERVER_PORT = 16892;
const string DEFAULT_EXTENDED_DATA = "0";
const char* UPDATED_SERVER_CN = "UpdatedSDKSampleMPS";
const unsigned int DEFAULT_TUNNEL_LIFE_TIME = 0;
const unsigned int UPDATED_TUNNEL_LIFE_TIME = 1;
const unsigned int MAX_MPS_NUM = 4;
#pragma endregion
#pragma region ENUM
// Info Format
typedef enum {
IPv4 = 3,
IPv6 = 4,
FQDN = 201
}InfoFormat;
typedef enum {
MutualAuthentication = 1,
UsernamePasswordAuthentication = 2
}AuthMethod;
typedef enum {
USER_INITIATED = 0,
ALERT = 1,
PERIODIC = 2,
HOME_PROVISIONING
}Trigger;
typedef enum {
UNKNOWN = 0,
OTHER = 1,
ENABLED = 2,
DISABLED = 3,
SHUTTING_DOWN = 4,
NOT_APPLICABLE = 5,
ENABLED_BUT_OFFLINE = 6,
IN_TEST = 7,
DEFERRED = 8,
QUIESCE = 9,
STARTING = 10,
DMTF_RESERVED = 11,
ALL_INTERFACES_DISABLED = 32768,
BIOS_INTERFACE_ENABLED = 32769,
OS_INTERFACE_ENABLED = 32770,
BIOS_AND_OS_INTERFACES_ENABLED = 32771,
VENDOR_RESERVED = 32772
}EnabledState;
#pragma endregion
#pragma region MEMBERS
unsigned int returnValue;
CmdLineArguments::Format format;
#pragma endregion
#pragma region HELP_METHODS
#pragma region PRINT_MESSAGE
// Print headers
void PrintHeader(string header)
{
format.SetConsoleTextColor(HWHITE);
cout << header;
format.SetConsoleTextColor(LGRAY);
}
// Print success message
void DisplaySuccess()
{
format.SetConsoleTextColor(HGREEN);
cout << "Success" << endl;
format.SetConsoleTextColor(LGRAY);
}
// Print fail message
void DisplayFail()
{
format.SetConsoleTextColor(HRED);
cout << "Failed" << endl;
format.SetConsoleTextColor(LGRAY);
}
#pragma endregion
/*
* Get AMT_RemoteAccessService instance
* Arguments:
* wsmanClient - host uuid
*/
AMT_RemoteAccessService GetRemoteAccessService(ICimWsmanClient* wsmanClient)
{
AMT_RemoteAccessService service(wsmanClient);
service.Name("Intel(r) AMT Remote Access Service");
service.Get();
return service;
}
/*
* Get AMT_UserInitiatedConnectionService instance
* Arguments:
* wsmanClient - host uuid
*/
AMT_UserInitiatedConnectionService GetUserInitiatedConnectionService(ICimWsmanClient* wsmanClient)
{
AMT_UserInitiatedConnectionService service(wsmanClient);
service.Name("Intel(r) AMT User Initiated Connection Service");
service.Get();
return service;
}
/*
* Display ERP Selectors
* Arguments:
* ref - End Point Reference
*
*/
void DisplayEprSelectors(CimReference ref)
{
map<string, string> selectors = ref.Selectors();
map<string, string>::iterator itr;
cout << "Selectors: " << endl;
for(itr = selectors.begin() ;itr != selectors.end(); itr++)
{
string tabs = (itr->first.length()>8)?((itr->first.length()>16)?"\t":"\t\t"):"\t\t\t";
cout << "\t" << itr->first << tabs << "= " << itr->second << endl;
}
}
/*
* Find RemoteAccessCredentialContext From a Given MPServer EPR
* Arguments:
* ref - End Point Reference to AMT_ManagementPresenceRemoteSAP
* assos - Output RemoteAccessCredentialContext
*
* Return Value:
* PT_STATUS_SUCCESS - on success, PT_STATUS_INTERNAL_ERROR - on failure
*
*/
bool FindRemoteAccessCredentialContextFromMPServerEPR(ICimWsmanClient* wsmanClient, CimReference ref, AMT_RemoteAccessCredentialContext & assos)
{
bool res = false;
AMT_ManagementPresenceRemoteSAP managerPresenceRemoteSAP;
vector<tr1::shared_ptr<AMT_ManagementPresenceRemoteSAP> > servers = managerPresenceRemoteSAP.Enumerate(wsmanClient);
if(servers.size() > 0)
{
for(unsigned int i=0; i<servers.size() ; i++)
{
// Traverse AMT_RemoteAccessCredentialContext
AMT_ManagementPresenceRemoteSAP curObj = *(servers[i].get());
// Expecting 1 instance (1 for each instance of AMT_ManagementPresenceRemoteSAP)
tr1::shared_ptr<CimBase> credentialContext = AssociationTraversalTypedUtils::GetAssociation(wsmanClient, curObj.Reference(), "AMT_RemoteAccessCredentialContext");
AMT_RemoteAccessCredentialContext obj = *(static_cast<AMT_RemoteAccessCredentialContext*>(credentialContext.get()));
if (obj.ElementProvidingContext().Selectors() == ref.Selectors())
{
assos = obj;
res = true;
break;
}
}
}
return res;
}
/*
* Get the Associated MP Servers to the given Remote Access Policy
* Arguments:
* policy - The AMT_RemoteAccessPolicyRule policy
* server - The associated MP Servers
*
*/
vector<AMT_ManagementPresenceRemoteSAP> GetAssociatedMPServers(ICimWsmanClient* wsmanClient, AMT_RemoteAccessPolicyRule policy)
{
vector<AMT_ManagementPresenceRemoteSAP> servers;
servers.clear();
AMT_RemoteAccessPolicyRule remoteAccessPolicyRule;
vector<tr1::shared_ptr<AMT_RemoteAccessPolicyRule> > policies = remoteAccessPolicyRule.Enumerate(wsmanClient);
if(policies.size() > 0)
{
AMT_RemoteAccessPolicyRule tmpPolicy(wsmanClient);
AMT_ManagementPresenceRemoteSAP tmpMPServer(wsmanClient);
for(unsigned int i=0; i<policies.size() ; i++)
{
AMT_RemoteAccessPolicyRule curObj = *(policies[i].get());
// Traverse AMT_RemoteAccessPolicyAppliesToMPS
tr1::shared_ptr<CimBase> remoteAccessPoliciesAppliesToMPSPtr = AssociationTraversalTypedUtils::GetAssociation(wsmanClient,curObj.Reference() ,"AMT_RemoteAccessPolicyAppliesToMPS");
AMT_RemoteAccessPolicyAppliesToMPS remoteAccessPoliciesAppliesToMPS = *(static_cast<AMT_RemoteAccessPolicyAppliesToMPS*>(remoteAccessPoliciesAppliesToMPSPtr.get()));
tmpPolicy.Get(remoteAccessPoliciesAppliesToMPS.PolicySet());
if ((0 == tmpPolicy.SystemName().compare(policy.SystemName())) &&
(0 == tmpPolicy.PolicyRuleName().compare(policy.PolicyRuleName())) &&
(0 == tmpPolicy.CreationClassName().compare(policy.CreationClassName())) &&
(0 == tmpPolicy.SystemCreationClassName().compare(policy.SystemCreationClassName())))
{
tmpMPServer.Get(remoteAccessPoliciesAppliesToMPS.ManagedElement());
servers.push_back(tmpMPServer);
}
}
}
return servers;
}
/*
* Reverse memcpy - Copy Buffers in a reverse mode
* Arguments:
* dst - Pointer to the Destination Buffer
* src - Pointer to the Source Buffer
* n - Number of bytes to copy
*
*/
void ReverseMemCopy(void *dst, const void *src, size_t n)
{
char *d, *s;
size_t i;
d = (char *) dst;
s = (char *) src + n - 1;
for (i=0; i<n; i++)
*(d++) = *(s--);
}
/*
* Displays a MP Server Port, Address, UserName and Password of the Mp Server
* Arguments:
* wsmanClient - host uuid
* assos - the AMT_RemoteAccessCredentialContext association object
*
*/
void DisplayMpServer(ICimWsmanClient* wsmanClient, AMT_RemoteAccessCredentialContext assos)
{
AMT_ManagementPresenceRemoteSAP server(wsmanClient);
AMT_MPSUsernamePassword user(wsmanClient);
CimReference ref;
ref.Selectors(assos.ElementProvidingContext().Selectors());
server.Get(ref);
ref.Selectors(assos.ElementInContext().Selectors());
user.Get(ref);
if(server.PortExists())
cout << "MP Server Port: " << server.Port() << endl;
if(server.CNExists())
cout << "MP Server CN: " << server.CN() << endl;
if(server.AccessInfoExists())
cout << "MP Server Address: " << server.AccessInfo() << endl;
if(user.RemoteIDExists())
cout << "MP Server Username: " <<user.RemoteID() << endl;
cout << endl;
}
/*
* Enumerates all MP servers
* Arguments:
* wsmanClient - host uuid
* verbose - boolean value for API test
* size - boolean value for API test
*/
void EnumerateMpServers(ICimWsmanClient* wsmanClient, bool verbose, unsigned int & size)
{
// Enumerate AMT_ManagementPresenceRemoteSAP
AMT_ManagementPresenceRemoteSAP managerPresenceRemoteSAP;
vector<tr1::shared_ptr<AMT_ManagementPresenceRemoteSAP> > servers = managerPresenceRemoteSAP.Enumerate(wsmanClient);
size = servers.size();
if(size > 0)
{
if (verbose)
{
cout << endl << "MpServer Count = " << size <<endl;
cout << endl << "-------- MP Servers List ---------" << endl;
for(unsigned int i=0; i<servers.size() ; i++)
{
// Traverse AMT_RemoteAccessCredentialContext
AMT_ManagementPresenceRemoteSAP curObj = *(servers[i].get());
// Expecting 1 instance (1 for each instance of AMT_ManagementPresenceRemoteSAP)
tr1::shared_ptr<CimBase> assos = AssociationTraversalTypedUtils::GetAssociation(wsmanClient, curObj.Reference(), "AMT_RemoteAccessCredentialContext");
AMT_RemoteAccessCredentialContext obj = *(static_cast<AMT_RemoteAccessCredentialContext*>(assos.get()));
cout << endl << "MP Server #" << i+1 << ": " << endl << "-------------" << endl;
DisplayMpServer(wsmanClient, obj);
}
cout << "-----------------------------------" << endl;
}
else
{
DisplaySuccess();
}
}
}
/*
* Adds a MP Server to The Mp Servers List
* Arguments:
* wsmanClient - host uuid
* verbose - boolean value for API test
* server - End Point Reference to Server that was added
*
* Return Value:
* PT_STATUS_SUCCESS - on success, PT_STATUS_INTERNAL_ERROR - on failure
*
*/
void AddMpServer(ICimWsmanClient* wsmanClient, CimReference & server)
{
// Traverse AMT_RemoteAccessService
AMT_RemoteAccessService service = GetRemoteAccessService(wsmanClient);
AMT_RemoteAccessService::AddMpServer_INPUT input;
AMT_RemoteAccessService::AddMpServer_OUTPUT output;
input.AccessInfo(DEFAULT_SERVER_ADDRESS);
input.InfoFormat(IPv4);
input.Port(DEFAULT_SERVER_PORT);
input.AuthMethod(UsernamePasswordAuthentication);
input.Username(DEFAULT_SERVER_USERNAME);
input.Password(DEFAULT_SERVER_PASSWORD);
input.CN(DEFAULT_SERVER_CN);
returnValue = service.AddMpServer(input, output);
if (returnValue != PT_STATUS_SUCCESS)
{
throw LogicException("Failed to invoke AddMpServer", returnValue);
}
DisplaySuccess();
if (output.MpServerExists())
{
server = output.MpServer();
}
}
/*
* Get MP Server
* Arguments:
* wsmanClient - host uuid
* verbose - boolean value for API test
* ref - End Point Reference to AMT_ManagementPresenceRemoteSAP
* cn - MP Server CN
*/
void GetMpServer(ICimWsmanClient* wsmanClient, bool verbose, const CimReference ref, string & cn)
{
AMT_ManagementPresenceRemoteSAP mps(wsmanClient);
// Get Server and User
mps.Get(ref);
if (mps.CNExists())
{
cn = mps.CN();
}
if (verbose)
{
cout << endl << endl << "MP Server ";
DisplayEprSelectors(ref);
cout << endl;
AMT_RemoteAccessCredentialContext assos(wsmanClient);
FindRemoteAccessCredentialContextFromMPServerEPR(wsmanClient, ref, assos);
cout << "MP Server Data:" << endl << "---------------" << endl;
DisplayMpServer(wsmanClient, assos);
}
else
{
DisplaySuccess();
}
}
/*
* Update a MP Server
* Arguments:
* wsmanClient - host uuid
* ref - End Point Reference to Server to be updated (AMT_ManagementPresenceRemoteSAP)
*/
void UpdateMpServer(ICimWsmanClient* wsmanClient, CimReference ref)
{
AMT_RemoteAccessCredentialContext assos(wsmanClient);
AMT_ManagementPresenceRemoteSAP server(wsmanClient);
AMT_MPSUsernamePassword user(wsmanClient);
FindRemoteAccessCredentialContextFromMPServerEPR(wsmanClient, ref, assos);
// Get Server and User
CimReference reference;
reference.Selectors(assos.ElementProvidingContext().Selectors());
server.Get(reference);
reference.Selectors(assos.ElementInContext().Selectors());
user.Get(reference);
server.InfoFormat(IPv4);
server.AccessInfo(DEFAULT_SERVER_ADDRESS);
server.Port(UPDATED_SERVER_PORT);
server.CN(UPDATED_SERVER_CN);
user.RemoteID(UPDATED_SERVER_USERNAME);
user.Secret(UPDATED_SERVER_PASSWORD);
// Update Server and User
server.Put();
user.Put();
DisplaySuccess();
}
/*
* Remove a MP Server from the MP Servers List
* Arguments:
* wsmanClient - host uuid
* ref - End Point Reference to Server to be remove (AMT_ManagementPresenceRemoteSAP)
*/
void RemoveMpServer(ICimWsmanClient* wsmanClient, CimReference ref)
{
AMT_ManagementPresenceRemoteSAP mps(wsmanClient);
mps.Get(ref);
AMT_ManagementPresenceRemoteSAP::CimKeys keys;
keys.CreationClassName(mps.CreationClassName());
keys.Name(mps.Name());
keys.SystemCreationClassName(mps.SystemCreationClassName());
keys.SystemName(mps.SystemName());
mps.Delete(wsmanClient,keys);
DisplaySuccess();
}
/*
* Displays a Remote Access Policy TunnelLifeTime, Trigger, ExtendedData(if exist) and associated MP Servers
* Arguments:
* wsmanClient - host uuid
* policy - the AMT_RemoteAccessPolicyRule policy
*/
void DisplayRemoteAccessPolicy(ICimWsmanClient* wsmanClient, AMT_RemoteAccessPolicyRule policy)
{
cout << "Remote Access Policy TunnelLifeTime\t: " << policy.TunnelLifeTime() << endl
<< "Remote Access Policy Trigger\t\t: " << policy.Trigger() << " (" << triggerNames[policy.Trigger()] << ")" << endl;
if (policy.ExtendedDataExists() && (policy.ExtendedData().Length() > 0))
{
cout << "Remote Access Policy Extended Data\t: ";
if (policy.ExtendedData().Length() >= 4)
{
unsigned int periodicPolicyType;
ReverseMemCopy(&periodicPolicyType, policy.ExtendedData().Data(), 4);
if (RAS_POLICY_PERIODIC_INTERVAL == periodicPolicyType)
{
cout << "PeriodicPolicyType\t: " << periodicPolicyType << endl;
if (policy.ExtendedData().Length() >= 8)
{
unsigned int timeInterval;
ReverseMemCopy(&timeInterval, policy.ExtendedData().Data()+4, 4);
cout << " \t TimeInterval\t\t: " << timeInterval <<endl;
}
}
else if (RAS_POLICY_PERIODIC_DAILY == periodicPolicyType)
{
printf("PeriodicPolicyType: %d" , periodicPolicyType);
if (policy.ExtendedData().Length() >= 8)
{
unsigned int hourOfDay;
ReverseMemCopy(&hourOfDay, policy.ExtendedData().Data()+4, 4);
cout << " \t HourOfDay\t\t: " << hourOfDay <<endl;
}
if (policy.ExtendedData().Length()>= 12)
{
unsigned int minutesOfHour;
ReverseMemCopy(&minutesOfHour, policy.ExtendedData().Data()+8, 4);
cout << " \t MinutesOfHour\t\t: " << minutesOfHour << endl;
}
}
else
{
cout << "Unknown value was found for PeriodicPolicyType: " << periodicPolicyType << endl;
}
}
}
;
vector<AMT_ManagementPresenceRemoteSAP> servers = GetAssociatedMPServers(wsmanClient, policy);
cout << "Associated MP Servers Count\t\t: " << servers.size() << endl;
for (unsigned int i=0 ; i<servers.size() ; i++)
{
cout << "MP Server #" << i + 1 << ":" << endl << "--------------" << endl;
if(servers.at(i).PortExists())
cout << "\tMP Server Port\t\t: "<< servers.at(i).Port() << endl;
if(servers.at(i).CNExists())
cout << "\tMP Server CN\t\t: " << servers.at(i).CN() << endl;
if(servers.at(i).AccessInfoExists())
cout << "\tMP Server Address\t: " << servers.at(i).AccessInfo() << endl;
cout << endl;
}
}
/*
* Enumerates all Remote Access Policies
* Arguments:
* wsmanClient - host uuid
* verbose - boolean value for API test
* size - holds the size
*/
void EnumerateRemoteAccessPolicies(ICimWsmanClient* wsmanClient, bool verbose, unsigned int & size)
{
AMT_RemoteAccessPolicyRule remoteAccessPolicyRule;
vector<tr1::shared_ptr<AMT_RemoteAccessPolicyRule> > remoteAccessPolicies = remoteAccessPolicyRule.Enumerate(wsmanClient);
size = remoteAccessPolicies.size();
if (verbose)
{
cout << endl << "RemoteAccessPolicy Count = " << size << endl;
if (size > 0)
{
vector<tr1::shared_ptr<AMT_RemoteAccessPolicyRule> >::iterator itr;
cout << endl << "-------- Remote Access Policies List ---------"<<endl;
int count;
for(itr = remoteAccessPolicies.begin(), count = 1; itr != remoteAccessPolicies.end(); itr++, ++count)
{
AMT_RemoteAccessPolicyRule curObj = *((*itr).get());
cout << "Remote Access Policy #" << count << ": " << endl << "-----------------------" << endl;
DisplayRemoteAccessPolicy(wsmanClient, curObj);
}
cout << "-----------------------------------" << endl;
}
}
else
{
DisplaySuccess();
}
}
/*
* Get Remote Access Policy
* Arguments:
* policy - The AMT_RemoteAccessPolicyRule policy
* ref - End Point Reference to AMT_RemoteAccessPolicyRule
*/
void GetRemoteAccessPolicy(ICimWsmanClient* wsmanClient, bool verbose, CimReference ref)
{
AMT_RemoteAccessPolicyRule policy(wsmanClient);
// Get Server and User
policy.Get(ref);
if (verbose)
{
cout << endl << endl << "Remote Access Policy ";
DisplayEprSelectors(ref);
cout << endl;
cout << "Remote Access Policy Data:" << endl << "--------------------------" << endl;
DisplayRemoteAccessPolicy(wsmanClient, policy);
}
else
{
DisplaySuccess();
}
}
/*
* Update a Remote Access Policy
* Arguments:
* policy - The AMT_RemoteAccessPolicyRule policy
* ref - End Point Reference to AMT_RemoteAccessPolicyRule
*/
void UpdateRemoteAccessPolicy(ICimWsmanClient* wsmanClient, CimReference ref)
{
AMT_RemoteAccessPolicyRule policy(wsmanClient);
policy.Get(ref);
policy.TunnelLifeTime(UPDATED_TUNNEL_LIFE_TIME);
// Update policy
policy.Put();
DisplaySuccess();
}
/*
* Removes a Remote Access Policy
* Arguments:
* policy - The AMT_RemoteAccessPolicyRule policy
* ref - End Point Reference to AMT_RemoteAccessPolicyRule
*/
void RemoveRemoteAccessPolicy(ICimWsmanClient* wsmanClient, CimReference ref, bool verbose)
{
AMT_RemoteAccessPolicyRule policy(wsmanClient);
policy.Get(ref);
AMT_RemoteAccessPolicyRule::CimKeys keys;
// Add the policy keys for delete
keys.PolicyRuleName(policy.PolicyRuleName());
keys.SystemName(policy.SystemName());
keys.CreationClassName(policy.CreationClassName());
keys.SystemCreationClassName(policy.SystemCreationClassName());
policy.Delete(wsmanClient, keys);
if (verbose)
{
cout << endl << endl << "Deleted Remote Access Policy ";
DisplayEprSelectors(ref);
cout << endl;
}
else
{
DisplaySuccess();
}
}
/*
* Removes all Remote Access Policy
* Arguments:
* wsmanClient - host uuid
* verbose - boolean value for API test
*/
void RemoveCreatedRemoteAccessPolicies(ICimWsmanClient* wsmanClient, bool verbose)
{
AMT_RemoteAccessPolicyRule remoteAccessPolicyRule;
vector<tr1::shared_ptr<AMT_RemoteAccessPolicyRule> > policies = remoteAccessPolicyRule.Enumerate(wsmanClient);
vector<tr1::shared_ptr<AMT_RemoteAccessPolicyRule> >::iterator itr;
cout << endl << endl << "Remote Access Policies count : " << policies.size() << endl;
if(policies.size() > 0)
{
for(itr = policies.begin(); itr != policies.end() ; itr++)
{
AMT_RemoteAccessPolicyRule curObj = *((*itr).get());
// Deletes only policies that are connected to an MPS that the sample added
vector<AMT_ManagementPresenceRemoteSAP> mpServers =
GetAssociatedMPServers(wsmanClient, curObj);
for(unsigned int j=0 ; j < mpServers.size() ; j++)
{
string cn;
cout << endl << "Calling GetMpServer... ";
GetMpServer(wsmanClient, verbose, mpServers.at(j).Reference(), cn);
if((0 == strcmp(cn.c_str(),DEFAULT_SERVER_CN)) || (0 == strcmp(cn.c_str(),UPDATED_SERVER_CN)))
{
cout << endl << "Calling RemoveRemoteAccessPolicy... ";
RemoveRemoteAccessPolicy(wsmanClient, (*itr)->Reference(),verbose);
break;
}
}
}
}
}
/*
* Removes all MP servers
* Arguments:
* wsmanClient - host uuid
* verbose - boolean value for API test
*/
void RemoveCreatedMpServers(ICimWsmanClient* wsmanClient, bool verbose)
{
AMT_ManagementPresenceRemoteSAP managerPresenceRemoteSAP;
vector<tr1::shared_ptr<AMT_ManagementPresenceRemoteSAP> > servers = managerPresenceRemoteSAP.Enumerate(wsmanClient);
cout << "\nManagement Presence Servers count : " << servers.size() <<endl;
if(servers.size() > 0)
{
for(unsigned int i=0; i<servers.size() ; i++)
{
string cn = "";
AMT_ManagementPresenceRemoteSAP curObj = *((AMT_ManagementPresenceRemoteSAP*)servers[i].get());
cout << endl << "Calling GetMpServer... ";
GetMpServer(wsmanClient, verbose, curObj.Reference(), cn);
if((0 == strcmp(cn.c_str(),DEFAULT_SERVER_CN)) || (0 == strcmp(cn.c_str(),UPDATED_SERVER_CN)))
{
if(verbose)
{
cout << "Deleting MP Server: " << curObj.CN() << endl;
}
cout << endl << "Calling RemoveMpServer... ";
RemoveMpServer(wsmanClient, curObj.Reference());
}
}
}
}
/*
* Enable User Initiated Interface
* Arguments:
* wsmanClient - host uuid
* isEnabled - holds the User Initiated Interface status
*/
void EnableUserInitiatedInterface(ICimWsmanClient* wsmanClient, bool isEnabled)
{
AMT_UserInitiatedConnectionService service = GetUserInitiatedConnectionService(wsmanClient);
AMT_UserInitiatedConnectionService::RequestStateChange_INPUT input;
AMT_UserInitiatedConnectionService::RequestStateChange_OUTPUT output;
input.RequestedState((isEnabled)?BIOS_AND_OS_INTERFACES_ENABLED:OS_INTERFACE_ENABLED);
returnValue = service.RequestStateChange(input, output);
if (returnValue != PT_STATUS_SUCCESS)
{
throw LogicException("Failed to invoke InvokeRequestStateChange" , returnValue);
}
DisplaySuccess();
}
/*
* Get User Initiated Interface Configuration
* Arguments:
* wsmanClient - host uuid
* verbose - boolean value for API test
*/
void GetUserInitiatedInterfaceConfiguration(ICimWsmanClient* wsmanClient, bool verbose)
{
AMT_UserInitiatedConnectionService service(wsmanClient);
service.Name("Intel(r) AMT User Initiated Connection Service");
service.Get();
if (service.EnabledStateExists())
{
if (verbose)
{
cout << endl << endl << "Configuration status = " << service.EnabledState();
if (DMTF_RESERVED >= service.EnabledState())
{
cout << " (" << enabledStateNames[service.EnabledState()] << ")" << endl;
}
else if ((ALL_INTERFACES_DISABLED<=service.EnabledState()) && (VENDOR_RESERVED>=service.EnabledState()))
{
uint32_t ind = service.EnabledState() - ALL_INTERFACES_DISABLED + DMTF_RESERVED + 1;
if (ind < 17)
cout << " (" << enabledStateNames[ind] << ")" << endl;
else
cout << endl << "Error: Can't Display Enabled States" << endl;
}
}
else
{
DisplaySuccess();
}
}
}
/*
* Adds a Remote Access Policy to The Remote Access Policies List
* Arguments:
* wsmanClient - host uuid
* server - End Point Reference to MPS created by the sample
* policy - End Point Reference to Policy that was added
*/
void AddRemoteAccessPolicy(ICimWsmanClient* wsmanClient, CimReference & server, CimReference & policy)
{
// Traverse AMT_RemoteAccessService
AMT_RemoteAccessService service = GetRemoteAccessService(wsmanClient);
AMT_RemoteAccessService::AddRemoteAccessPolicyRule_INPUT input;
AMT_RemoteAccessService::AddRemoteAccessPolicyRule_OUTPUT output;
input.Trigger(USER_INITIATED);
input.TunnelLifeTime(DEFAULT_TUNNEL_LIFE_TIME);
std::vector<CimReference> g;
g.push_back(server);
input.MpServer(g);
returnValue = service.AddRemoteAccessPolicyRule(input, output);
if (returnValue != PT_STATUS_SUCCESS)
{
throw LogicException("Failed to invoke InvokeAddRemoteAccessPolicyRule", returnValue);
}
DisplaySuccess();
if (output.PolicyRuleExists())
{
policy = output.PolicyRule();
}
}
#pragma endregion
#pragma region MAIN_METHODS
/*
* Manipulate the MP Server Attribute
* Arguments:
* wsmanClient - host uuid
* verbose - boolean value for API test
*/
void ManipulateMpServers(ICimWsmanClient* wsmanClient, bool verbose)
{
CimReference server;
unsigned int size = 0;
cout << endl << "Calling EnumerateMpServers... " ;
EnumerateMpServers(wsmanClient, verbose, size);
cout << endl << "Calling AddMpServer... ";
AddMpServer(wsmanClient, server);
string cn;
cout << endl << "Calling GetMpServer... ";
GetMpServer(wsmanClient, verbose, server, cn);
cout << endl << "Calling UpdateMpServer... ";
UpdateMpServer(wsmanClient, server);
if(verbose)
{
cout << endl << "Verify updated MP Server attributes" << endl;
GetMpServer(wsmanClient, verbose, server, cn);
}
cout << endl << "Calling RemoveMpServer... ";
RemoveMpServer(wsmanClient, server);
}
/*
* Manipulate the Remote Access Policy
* Arguments:
* wsmanClient - host uuid
* verbose - boolean value for API test
*/
void ManipulatRemoteAccessPolicies(ICimWsmanClient* wsmanClient, bool verbose)
{
CimReference server;
CimReference policy;
unsigned int size = 0;
cout << endl << "Calling EnumerateRemoteAccessPolicies... ";
EnumerateRemoteAccessPolicies(wsmanClient, verbose, size);
// Add MpServer if max limit wasn't reached
cout << endl << "Calling EnumerateMpServers... ";
EnumerateMpServers(wsmanClient, verbose, size);
if(size >= MAX_MPS_NUM)
{
cout << endl << "ManipulatRemoteAccessPolicy function failed while trying to add MP Server, "
<< "because the MP Server's max limit reached. Aborting." << endl;
throw LogicException("ManipulatRemoteAccessPolicy function had failed.");
}
cout << endl << "Calling AddMpServer... ";
AddMpServer(wsmanClient, server);
cout << endl << "Calling AddRemoteAccessPolicy... " ;
AddRemoteAccessPolicy(wsmanClient, server, policy);
cout << endl << "Calling GetRemoteAccessPolicy... " ;
GetRemoteAccessPolicy(wsmanClient, verbose, policy);
cout << endl << "Calling UpdateRemoteAccessPolicy... ";
UpdateRemoteAccessPolicy(wsmanClient, policy);
if(verbose)
{
cout << endl << "Verify updated Remote Access Policy attributes";
GetRemoteAccessPolicy(wsmanClient, verbose, policy);
}
cout << endl << "Calling RemoveRemoteAccessPolicy... ";
RemoveRemoteAccessPolicy(wsmanClient, policy, verbose);
cout << endl << "Calling RemoveMpServer... ";
RemoveMpServer(wsmanClient, server) ;
}
/*
* Manipulate the User Interface attribute
* Arguments:
* wsmanClient - host uuid
* verbose - boolean value for API test
*
*/
void ManipulateUserInterface(ICimWsmanClient* wsmanClient, bool verbose)
{
cout << endl << "Calling EnableUserInitiatedInterface - Disable... ";
EnableUserInitiatedInterface(wsmanClient, false);
cout << endl << "Calling GetUserInitiatedInterfaceConfiguration... ";
GetUserInitiatedInterfaceConfiguration(wsmanClient, verbose);
cout << endl << "Calling EnableUserInitiatedInterface - Enable... ";
EnableUserInitiatedInterface(wsmanClient, true);
cout << endl << "Calling GetUserInitiatedInterfaceConfiguration... ";
GetUserInitiatedInterfaceConfiguration(wsmanClient, verbose);
}
/*
* API Test
* Arguments:
* wsmanClient - host uuid
* verbose - boolean value for API test
*/
void APITest(ICimWsmanClient* wsmanClient, bool verbose)
{
PrintHeader("Calling ManipulateMpServer\n--------------------------");
cout << endl;
ManipulateMpServers(wsmanClient, verbose);
cout << endl;
PrintHeader("Calling ManipulatRemoteAccessPolicy\n-----------------------------------");
cout << endl;
ManipulatRemoteAccessPolicies(wsmanClient, verbose);
cout << endl;
PrintHeader("Calling ManipulateUserInterface\n---------------------------------");
cout << endl;
ManipulateUserInterface(wsmanClient, verbose);
}
/*
* Cleanup Sample Stuff
* Arguments:
* wsmanClient - host uuid
* verbose - boolean value for API test
*
*/
void CleanupSample(ICimWsmanClient* wsmanClient, bool verbose)
{
cout << endl << "CleansRemoteAccessPolicies... ";
RemoveCreatedRemoteAccessPolicies(wsmanClient, verbose);
cout << endl << "CleansMpServers... " << endl;
RemoveCreatedMpServers(wsmanClient, verbose);
cout << endl;
}
#pragma endregion