763 lines
24 KiB
C++
763 lines
24 KiB
C++
//-------------------------------------------------------------------------------------
|
||
//
|
||
// Copyright (C) 2008 Intel Corporation
|
||
//
|
||
// File: WirelessConfigurationFlow.cpp
|
||
//
|
||
// Contents: Api code for Intel(R) Active Management Technology
|
||
// (Intel<65> AMT) WirelessConfiguration Sample.
|
||
//
|
||
// Notes: This file contains the WirelessConfigurationFlow methods implementation.
|
||
//
|
||
//---------------------------------------------------------------------------------------
|
||
|
||
#include "WirelessConfigurationFlow.h"
|
||
#include "WirelessConfigurationSample.h"
|
||
#include "AMT_WiFiPortConfigurationService.h"
|
||
#include "CIM_WiFiPort.h"
|
||
#include "CIM_WiFiPortCapabilities.h"
|
||
#include "CIM_WiFiEndpointSettings.h"
|
||
#include "CIM_HostedAccessPoint.h"
|
||
#include "CIM_ComputerSystem.h"
|
||
#include "CIM_WiFiEndpoint.h"
|
||
#include "AMT_PublicKeyCertificate.h"
|
||
#include "CIM_IEEE8021xSettings.h"
|
||
#include "CIM_ConcreteComponent.h"
|
||
#include "CIM_CredentialContext.h"
|
||
#include "CmdLineArguments.h"
|
||
#include "LogicException.h"
|
||
#include "AssociationTraversalTypedUtils.h"
|
||
#include "AMT_PublicKeyManagementService.h"
|
||
#include "CIM_SoftwareIdentity.h"
|
||
#include <iomanip>
|
||
|
||
// Include from CIM Framework
|
||
#include "CimOpenWsmanClient.h"
|
||
#include "CommonDefinitions.h"
|
||
|
||
using namespace std;
|
||
using namespace Intel::WSManagement;
|
||
using namespace Intel::Manageability::Cim::Typed;
|
||
using namespace Intel::Manageability::Exceptions;
|
||
using namespace ExceptionNamespace;
|
||
|
||
#pragma region CONSTANT
|
||
|
||
const string DELETE_ALL_PROFILES_SUPPORTED_VERSION = "6.0";
|
||
string SSID = "Wireless-API";
|
||
|
||
#pragma endregion
|
||
|
||
#pragma region MEMBERS
|
||
|
||
unsigned int returnValue;
|
||
CmdLineArguments::Format format;
|
||
AMT_WiFiPortConfigurationService service;
|
||
bool isServiceInitialize = false;
|
||
string coreVersion; // The target machine's FW Core Version
|
||
|
||
#pragma endregion
|
||
|
||
#pragma region METHODS
|
||
|
||
#pragma region PRIVATE_METHODS
|
||
|
||
#pragma region PRINT_MESSAGE
|
||
|
||
// Print success message
|
||
void DisplaySuccess()
|
||
{
|
||
format.SetConsoleTextColor(HGREEN);
|
||
cout << "Success" << endl;
|
||
format.SetConsoleTextColor(LGRAY);
|
||
}
|
||
|
||
// Print fail message
|
||
void DisplayFailure()
|
||
{
|
||
format.SetConsoleTextColor(HRED);
|
||
cout << "Failed" << endl;
|
||
format.SetConsoleTextColor(LGRAY);
|
||
}
|
||
|
||
#pragma endregion
|
||
|
||
// Get AMT_WiFiPortConfigurationService
|
||
AMT_WiFiPortConfigurationService GetServiceInstance(ICimWsmanClient* wsmanClient)
|
||
{
|
||
if(!isServiceInitialize)
|
||
{
|
||
service = AMT_WiFiPortConfigurationService(wsmanClient);
|
||
service.Name("Intel(r) AMT WiFi Port Configuration Service");
|
||
service.Get();
|
||
|
||
isServiceInitialize = true;
|
||
}
|
||
return service;
|
||
}
|
||
// Get CIM_WiFiPort instance
|
||
CIM_WiFiPort GetWiFiPortInstance(ICimWsmanClient* wsmanClient)
|
||
{
|
||
CIM_WiFiPort wpPtr(wsmanClient);
|
||
wpPtr.DeviceID("WiFi Port 0");
|
||
wpPtr.Get();
|
||
|
||
return wpPtr;
|
||
}
|
||
|
||
// Get CIM_WiFiEndpoint instance
|
||
CIM_WiFiEndpoint GetWiFiEndpointInstance(ICimWsmanClient* wsmanClient)
|
||
{
|
||
CIM_WiFiEndpoint wePtr(wsmanClient);
|
||
wePtr.Name("WiFi Endpoint 0");
|
||
wePtr.Get();
|
||
|
||
return wePtr;
|
||
}
|
||
|
||
// Traversing the CIM_WiFiEndpointSettings instances
|
||
std::vector<shared_ptr<CIM_WiFiEndpointSettings>> EnumerateWiFiEndpointSettings(ICimWsmanClient* wsmanClient)
|
||
{
|
||
CIM_WiFiEndpointSettings wifiEndpointSettings;
|
||
std::vector<shared_ptr<CIM_WiFiEndpointSettings>> vecProfiles = wifiEndpointSettings.Enumerate(wsmanClient);
|
||
|
||
return vecProfiles;
|
||
}
|
||
|
||
// Print the Encryption method type
|
||
void PrintEncryptionMethod(int enc)
|
||
{
|
||
cout << "\tEncryption Method: " << enc << " (";
|
||
switch(enc)
|
||
{
|
||
case EncryptionMethodOther:
|
||
cout << "Other";
|
||
break;
|
||
case EncryptionMethodWEP:
|
||
cout << "WEP";
|
||
break;
|
||
case EncryptionMethodTKIP:
|
||
cout << "TKIP";
|
||
break;
|
||
case EncryptionMethodCCMP:
|
||
cout << "CCMP";
|
||
break;
|
||
case EncryptionMethodReserved:
|
||
cout << "Reserved";
|
||
break;
|
||
}
|
||
cout << ")" << endl;
|
||
}
|
||
|
||
// Print the Authentication method type
|
||
void PrintAuthMethod(int auth)
|
||
{
|
||
cout << "\tAuthentication Method: " << auth << " (";
|
||
switch(auth)
|
||
{
|
||
case AuthenticationMethodOther:
|
||
cout <<"Other";
|
||
break;
|
||
case AuthenticationMethodOpenSystem:
|
||
cout <<"OpenSystem";
|
||
break;
|
||
case AuthenticationMethodSharedKey:
|
||
cout <<"SharedKey";
|
||
break;
|
||
case AuthenticationMethodWPAPSK:
|
||
cout <<"WPAPSK";
|
||
break;
|
||
case AuthenticationMethodWPAIEEE802_1x:
|
||
cout <<"WPAIEEE802_1x";
|
||
break;
|
||
case AuthenticationMethodWPA2PSK:
|
||
cout <<"WPA2PSK";
|
||
break;
|
||
case AuthenticationMethodWPA2IEEE802_1x:
|
||
cout <<"WPA2IEEE802_1x";
|
||
break;
|
||
case AuthenticationMethodDMTFReserved:
|
||
cout <<"DMTFReserved";
|
||
break;
|
||
}
|
||
cout << ")" << endl;
|
||
}
|
||
|
||
// Print the Encryption method type
|
||
void PrintAuthProtocol802_1x(int auth)
|
||
{
|
||
cout << "\tAuthentication Protocol: " << auth << " (";
|
||
switch(auth)
|
||
{
|
||
case AuthenticationMethods802_1xEAP_TLS:
|
||
cout <<"802.1x EAP TLS";
|
||
break;
|
||
case AuthenticationMethods802_1xEAP_TTLS:
|
||
cout <<"802.1x EAP TTLS";
|
||
break;
|
||
case AuthenticationMethods802_1xPEAPv0:
|
||
cout <<"802.1x PEAPv0";
|
||
break;
|
||
case AuthenticationMethods802_1xPEAPv1:
|
||
cout <<"802.1x PEAPv1";
|
||
break;
|
||
case AuthenticationMethods802_1xEAP_FAST_MSCHAPv2:
|
||
cout <<"802.1x EAP FAST MSCHAPv2";
|
||
break;
|
||
case AuthenticationMethods802_1xEAP_FAST_GTC:
|
||
cout <<"802.1x EAP FAST GTC";
|
||
break;
|
||
case AuthenticationMethods802_1xEAP_MD5:
|
||
cout <<"802.1x EAP MD5";
|
||
break;
|
||
case AuthenticationMethods802_1xEAP_PSK:
|
||
cout <<"802.1x EAP PSK";
|
||
break;
|
||
case AuthenticationMethods802_1xEAP_SIM:
|
||
cout <<"802.1x EAP SIM";
|
||
break;
|
||
case AuthenticationMethods802_1xEAP_AKA:
|
||
cout <<"802.1x EAP AKA";
|
||
break;
|
||
case AuthenticationMethods802_1xEAP_FAST_TLS:
|
||
cout <<"802.1x EAP FAST TLS";
|
||
break;
|
||
case AuthenticationMethods802_1xDMTF_Reserved:
|
||
cout <<"802.1x DMTF Reserved ";
|
||
break;
|
||
}
|
||
cout << ")" << endl;
|
||
}
|
||
|
||
#pragma endregion
|
||
|
||
#pragma region MAIN_METHODS
|
||
|
||
// Update profile
|
||
void UpdateProfile(ICimWsmanClient* wsmanClient, string profileName, unsigned short profilePriority, bool verbose)
|
||
{
|
||
cout << "Updating Wireless Profile... ";
|
||
|
||
CIM_WiFiEndpointSettings wesObj;
|
||
|
||
std::vector<shared_ptr<CIM_WiFiEndpointSettings>> vecProfiles;
|
||
|
||
// Retrieve the CIM_WiFiEndpointSettings instances
|
||
vecProfiles = EnumerateWiFiEndpointSettings(wsmanClient);
|
||
|
||
std::vector<shared_ptr<CIM_WiFiEndpointSettings>> ::iterator itr;
|
||
|
||
for(itr = vecProfiles.begin() ;itr != vecProfiles.end(); itr++)
|
||
{
|
||
wesObj = *((CIM_WiFiEndpointSettings*)(*itr).get());
|
||
|
||
if(wesObj.ElementName().compare(profileName) == 0)
|
||
break;
|
||
}
|
||
if(itr == vecProfiles.end())
|
||
{
|
||
DisplayFailure();
|
||
cout << "Error: Can't update profile " << profileName << " since it does not exist." << endl;
|
||
return;
|
||
}
|
||
CIM_WiFiEndpointSettings wifiSettings(wsmanClient);
|
||
wifiSettings.AuthenticationMethod(wesObj.AuthenticationMethod());
|
||
wifiSettings.BSSType(wesObj.BSSType());
|
||
wifiSettings.ElementName(wesObj.ElementName());
|
||
wifiSettings.EncryptionMethod(wesObj.EncryptionMethod());
|
||
wifiSettings.InstanceID(wesObj.InstanceID());
|
||
wifiSettings.PSKPassPhrase(PskPassPhrase);
|
||
|
||
string content = "1";
|
||
Base64 base(content);
|
||
wifiSettings.PSKValue(base);
|
||
wifiSettings.Priority(profilePriority);
|
||
wifiSettings.SSID(SSID);
|
||
|
||
AMT_WiFiPortConfigurationService service;
|
||
|
||
// Retrieve the AMT_WiFiPortConfigurationService instance
|
||
service = GetServiceInstance(wsmanClient);
|
||
|
||
AMT_WiFiPortConfigurationService::UpdateWiFiSettings_INPUT input;
|
||
AMT_WiFiPortConfigurationService::UpdateWiFiSettings_OUTPUT output;
|
||
input.WiFiEndpointSettings(wesObj.Reference());
|
||
input.WiFiEndpointSettingsInput(wifiSettings);
|
||
|
||
returnValue = service.UpdateWiFiSettings(input, output);
|
||
if(returnValue != PT_STATUS_SUCCESS)
|
||
{
|
||
throw LogicException("Failed to invoke UpdateWiFiSettings, returnValue = ", returnValue);
|
||
}
|
||
DisplaySuccess();
|
||
|
||
if(verbose)
|
||
{
|
||
cout << endl << "Update Wireless Profile with the following parameters:" << endl;
|
||
if(wifiSettings.ElementNameExists())
|
||
cout << "\tElement Name: " << wifiSettings.ElementName() << endl;
|
||
if(wifiSettings.SSIDExists())
|
||
cout << "\tSSID: " << wifiSettings.SSID() << endl;
|
||
if(wifiSettings.PriorityExists())
|
||
cout << "\tPriority: " << (int)wifiSettings.Priority() << endl;
|
||
if(wifiSettings.AuthenticationMethodExists())
|
||
PrintAuthMethod(wifiSettings.AuthenticationMethod());
|
||
if(wifiSettings.EncryptionMethodExists())
|
||
PrintEncryptionMethod(wifiSettings.EncryptionMethod());
|
||
}
|
||
}
|
||
|
||
// Function delete all profiles.
|
||
// This function will use delete all User Profiles & delete all IT profiles.
|
||
void DeleteAllProfiles(ICimWsmanClient* wsmanClient, bool verbose)
|
||
{
|
||
GetCoreVersion(wsmanClient);
|
||
if(Version(coreVersion) > Version(DELETE_ALL_PROFILES_SUPPORTED_VERSION) || Version(coreVersion) == Version(DELETE_ALL_PROFILES_SUPPORTED_VERSION))
|
||
{
|
||
cout << endl << "Delete All Profiles... ";
|
||
|
||
AMT_WiFiPortConfigurationService service;
|
||
|
||
// Retrieve the WiFiPortConfigurationService
|
||
service = GetServiceInstance(wsmanClient);
|
||
|
||
// try deleting all User Profiles
|
||
returnValue = service.DeleteAllUserProfiles();
|
||
if(returnValue != PT_STATUS_SUCCESS)
|
||
{
|
||
throw LogicException("Failed to invoke DeleteAllUserProfiles, returnValue = ", returnValue);
|
||
}
|
||
|
||
// try deleting all IT Profiles
|
||
returnValue = service.DeleteAllITProfiles();
|
||
if(returnValue != PT_STATUS_SUCCESS)
|
||
{
|
||
throw LogicException("Failed to invoke DeleteAllITProfiles, returnValue = ", returnValue);
|
||
}
|
||
DisplaySuccess();
|
||
}
|
||
else
|
||
{
|
||
cout << endl << "Delete All Profiles is not supported in FW versions lower than 6.0";
|
||
DisplayFailure();
|
||
}
|
||
}
|
||
|
||
// add a specific profile based on the parameters
|
||
// mentioned in the h file
|
||
// Authentication Method WPAPSK
|
||
void AddProfile(ICimWsmanClient* wsmanClient, string profileName, EncryptionMethods encryptionMethod, unsigned short profilePriority, bool verbose)
|
||
{
|
||
cout << endl << "Adding Wireless Profile... ";
|
||
|
||
CIM_WiFiEndpoint wifiEndpoint;
|
||
|
||
// Retrieve the CIM_WiFiEndpoint instance
|
||
wifiEndpoint = GetWiFiEndpointInstance(wsmanClient);
|
||
|
||
CIM_WiFiEndpointSettings wifiSettings(wsmanClient);
|
||
wifiSettings.AuthenticationMethod(AuthenticationMethodWPA2PSK);
|
||
wifiSettings.ElementName(profileName);
|
||
wifiSettings.EncryptionMethod(encryptionMethod);
|
||
wifiSettings.InstanceID(InstanceIDIT + profileName);
|
||
wifiSettings.PSKPassPhrase(PskPassPhrase);
|
||
|
||
string content = "1";
|
||
Base64 base(content);
|
||
wifiSettings.PSKValue(base);
|
||
wifiSettings.Priority(profilePriority);
|
||
wifiSettings.SSID(SSID);
|
||
|
||
AMT_WiFiPortConfigurationService service;
|
||
|
||
// Retrieve the AMT_WiFiPortConfigurationService instance
|
||
service = GetServiceInstance(wsmanClient);
|
||
|
||
AMT_WiFiPortConfigurationService::AddWiFiSettings_INPUT input;
|
||
AMT_WiFiPortConfigurationService::AddWiFiSettings_OUTPUT output;
|
||
|
||
input.WiFiEndpoint(wifiEndpoint.Reference());
|
||
input.WiFiEndpointSettingsInput(wifiSettings);
|
||
|
||
returnValue = service.AddWiFiSettings(input, output);
|
||
if(returnValue != PT_STATUS_SUCCESS)
|
||
{
|
||
throw LogicException("Failed to invoke AddWiFiSettings, returnValue = ", returnValue);
|
||
}
|
||
DisplaySuccess();
|
||
|
||
if(verbose)
|
||
{
|
||
cout << endl << "Adding a Wireless Profile with the following parameters:" << endl;
|
||
if(wifiSettings.ElementNameExists())
|
||
cout << "\tElement Name: " << wifiSettings.ElementName() << endl;
|
||
if(wifiSettings.SSIDExists())
|
||
cout << "\tSSID: " << wifiSettings.SSID() << endl;
|
||
if (wifiSettings.PriorityExists())
|
||
cout << "\tPriority: " << (int)wifiSettings.Priority() << endl;
|
||
if(wifiSettings.AuthenticationMethodExists())
|
||
PrintAuthMethod(wifiSettings.AuthenticationMethod());
|
||
if(wifiSettings.EncryptionMethodExists())
|
||
PrintEncryptionMethod(wifiSettings.EncryptionMethod());
|
||
}
|
||
cout << endl;
|
||
}
|
||
|
||
// Print the WIFI capabilities that this machine supports
|
||
void WiFiCapabilities(ICimWsmanClient* wsmanClient, bool verbose)
|
||
{
|
||
cout << "Wireless Capabilities... ";
|
||
|
||
CIM_WiFiPortCapabilities WiFiPortCapabilities(wsmanClient);
|
||
WiFiPortCapabilities.InstanceID("Intel(r) AMT:WiFi Port 0 Capabilities");
|
||
WiFiPortCapabilities.Get();
|
||
|
||
DisplaySuccess();
|
||
|
||
if(verbose)
|
||
{
|
||
cout << endl << "Supported Features:" << endl;
|
||
for(unsigned int i = 0; i < WiFiPortCapabilities.SupportedPortTypes().size(); i++)
|
||
{
|
||
switch(WiFiPortCapabilities.SupportedPortTypes()[i])
|
||
{
|
||
case SupportedCapabilitiesP802_11a:
|
||
cout <<"\t802.11a" << endl;
|
||
break;
|
||
case SupportedCapabilitiesP802_11b:
|
||
cout <<"\t802.11b" << endl;
|
||
break;
|
||
case SupportedCapabilitiesP802_11g:
|
||
cout <<"\t802.11g" << endl;
|
||
break;
|
||
case SupportedCapabilitiesP802_11n:
|
||
cout <<"\t802.11n" << endl;
|
||
break;
|
||
default:
|
||
printf("\tUnknown\n");
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
cout << endl;
|
||
}
|
||
|
||
// Authentication mode WPA IEEE802.1x
|
||
// 802.1x settings - EAP TLS
|
||
// Authentication Method EAP TLS
|
||
void AddProfile802_1x(ICimWsmanClient* wsmanClient, string profileName, EncryptionMethods encryptionMethod, bool verbose)
|
||
{
|
||
cout << "Adding Wireless Profile... ";
|
||
|
||
CIM_WiFiEndpoint wifiEndpoint = GetWiFiEndpointInstance(wsmanClient);
|
||
|
||
// WifiEndPoint settings
|
||
CIM_WiFiEndpointSettings wifiSettings(wsmanClient);
|
||
wifiSettings.AuthenticationMethod(AuthenticationMethodWPAIEEE802_1x);
|
||
wifiSettings.ElementName(profileName);
|
||
wifiSettings.EncryptionMethod(encryptionMethod);
|
||
wifiSettings.InstanceID(InstanceIDIT + profileName);
|
||
wifiSettings.Priority(Priority802_11x);
|
||
wifiSettings.SSID(SSID);
|
||
|
||
// 802.1x settings
|
||
CIM_IEEE8021xSettings settings802_1x(wsmanClient);
|
||
settings802_1x.AuthenticationProtocol(AuthenticationMethods802_1xEAP_TLS);
|
||
settings802_1x.ElementName(profileName);
|
||
settings802_1x.InstanceID(profileName);
|
||
settings802_1x.Username(UserWireless);
|
||
|
||
|
||
// Managed certificate object.
|
||
AMT_PublicKeyManagementService publicKeyManagementService(wsmanClient);
|
||
|
||
// Add public key.
|
||
AMT_PublicKeyManagementService::AddCertificate_INPUT addCertificate_INPUT;
|
||
AMT_PublicKeyManagementService::AddCertificate_OUTPUT addCertificate_OUTPUT;
|
||
addCertificate_INPUT.CertificateBlob(Base64("MIICdDCCAd2gAwIBAgIBATANBgkqhkiG9w0BAQsFADAZMRcwFQYDVQQDFA5EZW1vIFN1YiBDQSAjMTAeFw0xMTExMjgwNzI2MDhaFw0xMjExMjcwNzI2MDhaMBgxFjAUBgNVBAMTDWR1dC5pbnRlbC5jb20wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAOqGOUQJZhvo57WSyg6tu4SdakCo7k4tXcVyWxOte6hS7CHHmQCrmcOBtJLeG6ALOG0PeypYNT8iQVIYkNGGJQdwSNaAKmK/b8BWrXnqmJkb7EQaHL3HoHPV0K0Hi4zibqhaxdZ4NyK45GKU6G+I/u90Pi0O3ef3yqwbfeCAGXS5AgMBAAGjgcwwgckwCQYDVR0TBAIwADALBgNVHQ8EBAMCB4AwEgYDVR0lAQH/BAgwBgYEWhUOCDAdBgNVHQ4EFgQU9rDsvUcGs/235QA660xH3kjptNMwWgYDVR0jBFMwUYAUd3fG6KXZZ5TrPh4g5li5enIxdUOhNqQ0MDIxFTATBgNVBAMTDERlbW8gUm9vdCBDQTELMAkGA1UEBhMCSUwxDDAKBgNVBAsTA0ZUTIIBATAgBgNVHR8EGTAXMBWgE6ARhg9odHRwOi8vc29tZS51cmwwDQYJKoZIhvcNAQELBQADgYEAl2r/DMnx5mi1DiiWHIc6iDC843k8el7gLDTS3zl+JH+nbTNSeAOY352vT2aY/pVLKA6+DykxFbyG/bYdHmRCr/F7OkXMOwX8Ik0bT5/SPKPzSFoGEubyau2uRURT5pUUws97Bkj5fXMakolqauRReHMG9bNvI4FswrIaqZCo1eg="));
|
||
publicKeyManagementService.AddCertificate(addCertificate_INPUT, addCertificate_OUTPUT);
|
||
|
||
// Add private key.
|
||
AMT_PublicKeyManagementService::AddKey_INPUT addKey_INPUT;
|
||
AMT_PublicKeyManagementService::AddKey_OUTPUT addKey_OUTPUT;
|
||
addKey_INPUT.KeyBlob(Base64("MIICWwIBAAKBgQDqhjlECWYb6Oe1ksoOrbuEnWpAqO5OLV3FclsTrXuoUuwhx5kAq5nDgbSS3hugCzhtD3sqWDU/IkFSGJDRhiUHcEjWgCpiv2/AVq156piZG+xEGhy9x6Bz1dCtB4uM4m6oWsXWeDciuORilOhviP7vdD4tDt3n98qsG33ggBl0uQIDAQABAoGAbcKD6qO7djR6vTAGAPiuWlKR99EYNt5klJQArCT1SsIEYYrYwMePH0EFEfeBVlXqAqDMM/U0dmfBynpUzLrLeNo49TGKuTIgADpykXT3IXU90Z3HAoA/XSr3ozdjP2+/d8UEYgMW2tnttu/aIJJ7ZIgQhXf6LeIWKP6YcZjo2AECQQD/NfOrueTInpPe9RGtFSJrC+g62+jeVXP0+sHR9fHsvCM3kNn6wEeOR23s8Qr3FEehJ8RA1PrPA7M3uLJINmvxAkEA6z/lAy4INNZcuP/AtztuTtzUXRyBhUEjlM9j8H0+Y+DuEGjgHehiTe4kWdXeygm2Wg5q3t01kfl9/cyGE+B9SQJARkUXs9f6e5bWRlSaKlsgX/MmXVaBtv42cGS/C0258CIZXEphCp741N8sEEqKZ1/JHUFy0xsReACfzx7mz+VUMQJAeLpcrAoWmg8cnLBb1W0BiiVYMsSrT5iDSx43mrabqyRG6FL6GT8mG/pH23aflC3x0Duv6tm5YUWZvAMXF+JQSQJAD02ZRno3bkmRmpZgq4bWJgKd9ko8iL+425xwwH++eBAKdvrbnvEE3FVNkR4Z/t1OnrR0NjUWrPk42Ln4kHDPQg=="));
|
||
publicKeyManagementService.AddKey(addKey_INPUT, addKey_OUTPUT);
|
||
|
||
AMT_WiFiPortConfigurationService service;
|
||
|
||
// Retrieve the AMT_WiFiPortConfigurationService instance
|
||
service = GetServiceInstance(wsmanClient);
|
||
|
||
AMT_WiFiPortConfigurationService::AddWiFiSettings_INPUT input;
|
||
AMT_WiFiPortConfigurationService::AddWiFiSettings_OUTPUT output;
|
||
|
||
// Fill the input structure with the Wifi settings, 802.1x settings and
|
||
// client certificate settings
|
||
input.WiFiEndpoint(wifiEndpoint.Reference());
|
||
input.WiFiEndpointSettingsInput(wifiSettings);
|
||
input.IEEE8021xSettingsInput(settings802_1x);
|
||
input.ClientCredential(addCertificate_OUTPUT.CreatedCertificate());
|
||
|
||
// invoke the actual add profile function
|
||
returnValue = service.AddWiFiSettings(input, output);
|
||
if(returnValue != PT_STATUS_SUCCESS)
|
||
{
|
||
throw LogicException("Failed to invoke AddWiFiSettings, returnValue = ", returnValue);
|
||
}
|
||
DisplaySuccess();
|
||
|
||
// print the profile that was added in case verbose mode specified
|
||
if(verbose)
|
||
{
|
||
cout << "Adding a Wireless Profile with the following parameters:" << endl;
|
||
if(wifiSettings.ElementNameExists())
|
||
cout << "\tElement Name: " << wifiSettings.ElementName() << endl;
|
||
if(wifiSettings.SSIDExists())
|
||
cout << "\tSSID: " << wifiSettings.SSID() << endl;
|
||
if(wifiSettings.PriorityExists())
|
||
cout << "\tPriority: " << (int)wifiSettings.Priority() << endl;
|
||
PrintAuthMethod(AuthenticationMethodWPAIEEE802_1x);
|
||
PrintEncryptionMethod(encryptionMethod);
|
||
|
||
cout << "\t802.1x Settings:" << endl;
|
||
cout << "\t";
|
||
PrintAuthProtocol802_1x(settings802_1x.AuthenticationProtocol());
|
||
cout << "\t\tUsername: " << settings802_1x.Username() << endl;
|
||
CimReference r;
|
||
|
||
AMT_PublicKeyCertificate createdCertificate(wsmanClient);
|
||
createdCertificate.Get(addCertificate_OUTPUT.CreatedCertificate());
|
||
|
||
cout << "\tCertificate Settings:" << endl;
|
||
cout << "\t\tInstanceID:" << createdCertificate.InstanceID() << endl;
|
||
if(createdCertificate.ElementNameExists())
|
||
cout << "\t\tElement Name:" << createdCertificate.ElementName() << endl;
|
||
if(createdCertificate.SubjectExists())
|
||
cout << "\t\tSubject:" << createdCertificate.Subject() << endl;
|
||
}
|
||
cout << endl;
|
||
}
|
||
|
||
// Enumerate all profiles and print each of them
|
||
void EnumerateProfiles(ICimWsmanClient* wsmanClient, int &numOfProfiles, bool verbose)
|
||
{
|
||
cout << "Enumerate Profiles... ";
|
||
|
||
std::vector<shared_ptr<CIM_WiFiEndpointSettings>> vecProfiles;
|
||
|
||
// Retrieve the CIM_WiFiEndpointSettings instances
|
||
vecProfiles = EnumerateWiFiEndpointSettings(wsmanClient);
|
||
|
||
DisplaySuccess();
|
||
|
||
if(vecProfiles.size() > 0)
|
||
{
|
||
for(unsigned int i=0; i<vecProfiles.size(); i++)
|
||
{
|
||
CIM_WiFiEndpointSettings wesObj = *((CIM_WiFiEndpointSettings*)vecProfiles.at(i).get());
|
||
|
||
if(verbose)
|
||
{
|
||
cout << endl;
|
||
if(wesObj.ElementNameExists())
|
||
cout << " " << i+1 << ") Element Name " << wesObj.ElementName() << endl;
|
||
if(wesObj.SSIDExists())
|
||
cout << "\tSSID: " << wesObj.SSID() << endl;
|
||
if(wesObj.PriorityExists())
|
||
cout << "\tPriority: " << (int)wesObj.Priority() << endl;
|
||
if(wesObj.AuthenticationMethodExists())
|
||
PrintAuthMethod(wesObj.AuthenticationMethod());
|
||
if(wesObj.EncryptionMethodExists())
|
||
PrintEncryptionMethod(wesObj.EncryptionMethod());
|
||
}
|
||
|
||
// Find the association between a profile and 802.1x
|
||
// Traverse to the CIM_IEEE8021xSettings
|
||
vector<tr1::shared_ptr <CimBase> > vecConcreteComp = AssociationTraversalTypedUtils::EnumerateAssociated(wsmanClient, wesObj.Reference(), "CIM_IEEE8021xSettings" ,"CIM_ConcreteComponent");
|
||
|
||
// Expecting 1 instance
|
||
if(vecConcreteComp.size() > 0)
|
||
{
|
||
CIM_IEEE8021xSettings set802_1x = *(static_cast<CIM_IEEE8021xSettings*>(vecConcreteComp[0].get()));
|
||
|
||
if(verbose)
|
||
{
|
||
cout << "\t802.1x Settings:" << endl;
|
||
if(set802_1x.ElementNameExists())
|
||
cout << "\t\tElement Name: " << set802_1x.ElementName() << endl;
|
||
if(set802_1x.AuthenticationProtocolExists())
|
||
{
|
||
cout << "\t";
|
||
PrintAuthProtocol802_1x(set802_1x.AuthenticationProtocol());
|
||
}
|
||
if(set802_1x.UsernameExists())
|
||
cout << "\t\tUsername: " << set802_1x.Username() << endl;
|
||
}
|
||
|
||
// Find the association between 802.1x to public key certificate
|
||
// Traverse the AMT_PublicKeyCertificate
|
||
vector<tr1::shared_ptr <CimBase> > vecCredentialCont = AssociationTraversalTypedUtils::EnumerateAssociated(wsmanClient, set802_1x.Reference(), "AMT_PublicKeyCertificate", "CIM_CredentialContext");
|
||
|
||
// Expecting 1 instance
|
||
if(vecCredentialCont.size() > 0)
|
||
{
|
||
AMT_PublicKeyCertificate cert = *(static_cast<AMT_PublicKeyCertificate*>(vecCredentialCont[0].get()));
|
||
|
||
if(verbose)
|
||
{
|
||
cout << "\tCertificate Settings:" << endl;
|
||
cout << "\t\tInstanceID:" << cert.InstanceID() << endl;
|
||
if(cert.ElementNameExists())
|
||
cout << "\t\tElement Name:" << cert.ElementName() << endl;
|
||
if(cert.SubjectExists())
|
||
cout << "\t\tSubject:" << cert.Subject() << endl;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if(verbose)
|
||
{
|
||
cout << endl << "No Profiles Available" << endl;
|
||
}
|
||
}
|
||
numOfProfiles = vecProfiles.size();
|
||
}
|
||
|
||
// delete a profile corresponding to the given profileName
|
||
void DeleteProfile(ICimWsmanClient* wsmanClient, string profileName, bool verbose)
|
||
{
|
||
// Determine whether to delete all profiles or delete a specific profile
|
||
bool deleteAll = (profileName.compare("") == 0);
|
||
if(deleteAll)
|
||
cout << "Delete All Profiles... ";
|
||
else
|
||
cout << endl << "Delete Profile "<< profileName << "... ";
|
||
|
||
std::vector<shared_ptr <CIM_WiFiEndpointSettings> > vecProfiles;
|
||
|
||
// Retrieve the CIM_WiFiEndpointSettings instances
|
||
vecProfiles = EnumerateWiFiEndpointSettings(wsmanClient);
|
||
|
||
if(vecProfiles.size() == 0)
|
||
{
|
||
cout << "No profiles exist." << endl << endl;
|
||
return;
|
||
}
|
||
int profilesDeleted = 0;
|
||
|
||
std::vector<shared_ptr <CIM_WiFiEndpointSettings> > ::iterator itr;
|
||
|
||
for(itr = vecProfiles.begin() ; itr!=vecProfiles.end() ; itr++)
|
||
{
|
||
CIM_WiFiEndpointSettings wesObj = *((CIM_WiFiEndpointSettings*)(*itr).get());
|
||
|
||
// if delete all instances is specified it will always enter this loop
|
||
if(deleteAll || (wesObj.InstanceID().compare(InstanceIDIT + profileName) == 0))
|
||
{
|
||
wesObj.Delete();
|
||
profilesDeleted++;
|
||
}
|
||
}
|
||
if (profilesDeleted > 0)
|
||
{
|
||
DisplaySuccess();
|
||
}
|
||
else if (!deleteAll)
|
||
{
|
||
cout << endl << "No profiles exist corresponding with ElementName " << profileName << endl;
|
||
}
|
||
cout << endl;
|
||
}
|
||
|
||
// Get the local profile synchronization
|
||
void GetLocalProfileSynch(ICimWsmanClient* wsmanClient, bool verbose)
|
||
{
|
||
cout << "Get Local Profile Synchronization... ";
|
||
|
||
AMT_WiFiPortConfigurationService service;
|
||
|
||
// Retrieve the AMT_WiFiPortConfigurationService instance
|
||
service = GetServiceInstance(wsmanClient);
|
||
|
||
DisplaySuccess();
|
||
string s = "";
|
||
if(service.localProfileSynchronizationEnabledExists())
|
||
{
|
||
switch(service.localProfileSynchronizationEnabled())
|
||
{
|
||
case LocalSynchronizationDisabled:
|
||
s = "Local Synchronization Disabled";
|
||
break;
|
||
case LocalUserProfileSynchronization:
|
||
s = "Local User Profile Synchronization";
|
||
break;
|
||
case LocalAdminProfileSynchronization:
|
||
s = "Local Admin Profile Synchronization";
|
||
break;
|
||
case UnrestrictedSynchronization:
|
||
s = "Unrestricted Synchronization";
|
||
break;
|
||
default:
|
||
s = "Local Synchronization Reserved";
|
||
break;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
s = "Local Profile Synchronization Unspecified";
|
||
}
|
||
if(verbose)
|
||
{
|
||
cout << s << endl;
|
||
}
|
||
}
|
||
|
||
// Set the local profile synchronization
|
||
void SetLocalProfileSynch(ICimWsmanClient* wsmanClient, unsigned int syncType, bool verbose)
|
||
{
|
||
cout << "Set Local Profile Synchronization... ";
|
||
|
||
AMT_WiFiPortConfigurationService service;
|
||
|
||
// Retrieve the AMT_WiFiPortConfigurationService instance
|
||
service = GetServiceInstance(wsmanClient);
|
||
|
||
// Set the value we want to update
|
||
service.localProfileSynchronizationEnabled(syncType);
|
||
|
||
// Update the data
|
||
service.Put();
|
||
|
||
DisplaySuccess();
|
||
}
|
||
/*****************************************************************************
|
||
* Function that returns the AMT's core version.
|
||
* Arguments:
|
||
* fwCoreVersion - [out] core version.
|
||
****************************************************************************/
|
||
void GetCoreVersion(ICimWsmanClient* wsmanClient)
|
||
{
|
||
if (coreVersion.empty())
|
||
{
|
||
try
|
||
{
|
||
CIM_SoftwareIdentity softwareIdentity(wsmanClient);
|
||
CIM_SoftwareIdentity::CimKeys keys;
|
||
keys.InstanceID("AMT FW Core Version");
|
||
softwareIdentity.Get(keys);
|
||
|
||
coreVersion = softwareIdentity.VersionString().c_str();
|
||
}
|
||
catch (...)
|
||
{
|
||
cout << "\nError: Get Core Version Failed." << endl;
|
||
throw;
|
||
}
|
||
}
|
||
}
|
||
#pragma endregion
|
||
|
||
#pragma endregion |