//---------------------------------------------------------------------------- // // Copyright (C) 2008 Intel Corporation // // File: WirelessConfigurationSample.cpp // // Contents: Sample code for an Intel� AMT Network client. // //---------------------------------------------------------------------------- #include "WirelessConfigurationSample.h" #include "WirelessConfigurationFlow.h" #include "CommonDefinitions.h" #include "CmdLineArguments.h" #include "LogicException.h" // Include from CIM Framework #include "CimOpenWsmanClient.h" #include using namespace ExceptionNamespace; using namespace Intel::Manageability::Cim::Utils; #pragma region CONSTANT static const char * CMD_TMP_SSID = "ssid"; static const char * WEP_KEY_1 = "123aa67890123aa67890111111"; static const char * WEP_KEY_2 = "1211111111123aa67890111111"; static const char * WEP_KEY_3 = "3456789312"; static const char * WEP_KEY_EMPTY = ""; //profiles names static const char * TKIPProfileName = "Wireless-Profile-TKIP"; static const char * ProfileName802_1x = "Wireless-Profile-802_1x"; static const char * WEPProfileName = "Wireless-Profile-WEP"; static const char * OpenProfileName = "Wireless-Profile-Open"; static const char * CCMPProfileName = "Wireless-Profile-CCMP"; static const unsigned int MAX_PROFILE = 16; #pragma endregion #pragma region MAIN int main(int argc, char* argv[]) { // set default dll lookup directory to system SetDefaultDllDirectories(LOAD_LIBRARY_SEARCH_SYSTEM32); PT_STATUS status = PT_STATUS_SUCCESS; CmdLineArguments::Format format; #pragma region COMMAND_LINE_ARGUMENTS // Add the general arguments format.AddArg(CMD_VERBOSE, false, false, false, ""); format.AddArg(CMD_USER, true, false, false, ""); format.AddArg(CMD_PASS, true, false, false, ""); format.AddArg(CMD_CERT_NAME, true, false, false, ""); format.AddArg(CMD_HOST, true, true, false, ""); format.AddArg(CMD_TLS, false, false, false, ""); format.AddArg(CMD_KRB, false, false, false, ""); format.AddArg(CMD_PROXY, true, false, false, ""); format.AddArg(CMD_PROXY_USERNAME, true, false, false, ""); format.AddArg(CMD_PROXY_PASS, true, false, false, ""); format.AddArg(CMD_ACCEPT_SELF_CIGNED_CERT, false, false, false, ""); // Add the sample-specific options arguments format.AddArg(CMD_API_TEST, false, false, true, CMD_API_TEST_DESCRIPTION); format.AddArg(CMD_DELETE_ALL_PROFILES, false, false, true, CMD_DELETE_ALL_PROFILES_DESCRIPTION); format.AddArg(CMD_ADD_PROFILE_802_1x, false, false, true, CMD_ADD_PROFILE_802_1x_DESCRIPTION); format.AddArg(CMD_ADD_PROFILE, false, false, true, CMD_ADD_PROFILE_DESCRIPTION); format.AddArg(CMD_UPDATE_PROFILE, false, false, true, CMD_UPDATE_PROFILE_DESCRIPTION); format.AddArg(CMD_DELETE_PROFILE, false, false, true, CMD_DELETE_PROFILE_DESCRIPTION); format.AddArg(CMD_ENUMERATE_PROFILES, false, false, true, CMD_ENUMERATE_PROFILES_DESCRIPTION); format.AddArg(CMD_WIFI_CAPABILITIES, false, false, true, CMD_WIFI_CAPABILITIES_DESCRIPTION); format.AddArg(CMD_GET_LOCAL_PROFILE_SYNCH, false, false, true, CMD_GET_LOCAL_PROFILE_SYNCH_DESCRIPTION); format.AddArg(CMD_SET_LOCAL_PROFILE_SYNCH, true, false, true, CMD_SET_LOCAL_PROFILE_SYNCH_DESCRIPTION); #pragma endregion #pragma endregion if (argc == 1) { cerr << format.CreateUsage(argv[0]); return status; } try { CmdLineArguments cmdLineArguments; cmdLineArguments.Parse(argc, argv, format); CimOpenWsmanClient wsmanClient( cmdLineArguments.GetArgValue(CMD_HOST), cmdLineArguments.ArgExists(CMD_TLS) ? AMT_SECURE_PORT : AMT_UNSECURE_PORT, cmdLineArguments.ArgExists(CMD_TLS), cmdLineArguments.ArgExists(CMD_KRB) ? KERBEROS : DIGEST, cmdLineArguments.GetArgValue(CMD_USER), cmdLineArguments.GetArgValue(CMD_PASS), cmdLineArguments.ArgExists(CMD_PROXY) ? cmdLineArguments.GetArgValue(CMD_PROXY): "", cmdLineArguments.ArgExists(CMD_PROXY_USERNAME) ? cmdLineArguments.GetArgValue(CMD_PROXY_USERNAME): "", cmdLineArguments.ArgExists(CMD_PROXY_PASS) ? cmdLineArguments.GetArgValue(CMD_PROXY_PASS): "", false, // Local certificate store cmdLineArguments.ArgExists(CMD_CERT_NAME) ? cmdLineArguments.GetArgValue(CMD_CERT_NAME): "", cmdLineArguments.ArgExists(CMD_LOCAL) ? OID_LOCAL : OID_REMOTE, cmdLineArguments.ArgExists(CMD_ACCEPT_SELF_CIGNED_CERT)); bool verbose = cmdLineArguments.ArgExists(CMD_VERBOSE); string userRequest = cmdLineArguments.GetSelectedOptionName(); int numOfProfiles = 0; if (format.CompareStringCaseSensitive(userRequest, CMD_API_TEST) == true) { WiFiCapabilities(&wsmanClient, verbose); EnumerateProfiles(&wsmanClient, numOfProfiles, verbose); if(numOfProfiles < MAX_PROFILE) { DeleteProfile(&wsmanClient, CCMPProfileName, verbose); AddProfile(&wsmanClient, CCMPProfileName, EncryptionMethodCCMP, CCMPPriority, verbose); UpdateProfile(&wsmanClient, CCMPProfileName, CCMPPriority, verbose); DeleteProfile(&wsmanClient, CCMPProfileName, verbose); } else { cout << "\nWarning: Skipping the creation, deletion and updating of a profile since there" << endl << "\t are already maximum profiles." << endl; } } else if (format.CompareStringCaseSensitive(userRequest, CMD_DELETE_ALL_PROFILES) == true) { DeleteAllProfiles(&wsmanClient, verbose); } else if (format.CompareStringCaseSensitive(userRequest, CMD_ADD_PROFILE_802_1x) == true) { AddProfile802_1x(&wsmanClient, ProfileName802_1x, EncryptionMethodCCMP, verbose); } else if (format.CompareStringCaseSensitive(userRequest, CMD_ADD_PROFILE) == true) { AddProfile(&wsmanClient, CCMPProfileName, EncryptionMethodCCMP, CCMPPriority, verbose); } else if (format.CompareStringCaseSensitive(userRequest, CMD_UPDATE_PROFILE) == true) { UpdateProfile(&wsmanClient, CCMPProfileName, CCMPPriority, verbose); } else if (format.CompareStringCaseSensitive(userRequest, CMD_DELETE_PROFILE) == true) { DeleteProfile(&wsmanClient, CCMPProfileName, verbose); } else if (format.CompareStringCaseSensitive(userRequest, CMD_ENUMERATE_PROFILES) == true) { EnumerateProfiles(&wsmanClient, numOfProfiles, verbose); } else if (format.CompareStringCaseSensitive(userRequest, CMD_WIFI_CAPABILITIES) == true) { WiFiCapabilities(&wsmanClient, verbose); } else if (format.CompareStringCaseSensitive(userRequest, CMD_GET_LOCAL_PROFILE_SYNCH) == true) { GetLocalProfileSynch(&wsmanClient, verbose); } else if (format.CompareStringCaseSensitive(userRequest, CMD_SET_LOCAL_PROFILE_SYNCH) == true) { string syncOption = cmdLineArguments.GetArgValue(CMD_SET_LOCAL_PROFILE_SYNCH); unsigned int val; if(syncOption.compare("0") == 0) { val = LocalSynchronizationDisabled; } else if(syncOption.compare("1") == 0) { val = LocalUserProfileSynchronization; } else if(syncOption.compare("2") == 0) { val = LocalAdminProfileSynchronization; } else if(syncOption.compare("3") == 0) { val = UnrestrictedSynchronization; } else if(syncOption.compare("4") == 0) { val = LocalSynchronizationReserved; } else { throw CmdLineException("Local Synchronization is not a valid value.\nPlease check the usage for valid options."); } SetLocalProfileSynch(&wsmanClient, val, verbose); } else { throw CmdLineException("Could not find a value for the option."); } } catch (CimException& exp) { cerr << endl << endl << "--------------------CimException--------------------" << endl; cerr << exp.what() << endl; status = PTSDK_STATUS_NETWORK_ERROR; } catch (ConversionException &exp) { cerr << endl << "--------------------ConversionException--------------------" << endl; cerr << exp.what() << endl; status = PTSDK_STATUS_NETWORK_ERROR; } catch (LogicException &exp) { cerr << endl << "--------------------LogicException--------------------" << endl; cerr << exp.getDetail(); if(exp.getErr() != 0) cerr << exp.getErr(); } catch (CmdLineException &exp) { cerr << endl << "--------------------CmdLineException--------------------" << endl; cerr << exp.what() << endl; status = PTSDK_STATUS_NETWORK_ERROR; cerr << endl << format.CreateUsage(argv[0]); } catch (WSManException &exp) { cerr << endl << "--------------------GeneralWsmanException--------------------" << endl; cerr << "Exception string error: " << exp.what() << endl; status = PTSDK_STATUS_NETWORK_ERROR; } catch (HTTPException &exp) { cerr << endl << "--------------------HTTPException--------------------" << endl; cerr << "Exception string error: " << exp.what() << endl; status = PTSDK_STATUS_NETWORK_ERROR; } catch (const exception &exp) { cerr << endl << "--------------------std::exception--------------------" << endl; cerr << exp.what() << endl;; status = PTSDK_STATUS_NETWORK_ERROR; } return status; } #pragma endregion