Added Intel AMT Redirection/KVM settings.

Ylian Saint-Hilaire committed Oct 21, 2020 at 10:28 UTC 08c46be4a2b4fd50d2d88cf382512a402a6788bd
1 file changed +116 -17
amtmanager.js
+116 -17
@@ -368,6 +368,8 @@ module.exports.CreateAmtManager = function(parent) {
368 if (stack.wsman.comm.xtls == 1) { dev.aquired.hash = stack.wsman.comm.xtlsCertificate.fingerprint.split(':').join('').toLowerCase(); } else { delete dev.aquired.hash; }
369 UpdateDevice(dev);
370
371 + // TODO: Enable redirection port and KVM
372 +
373 // Perform Intel AMT clock sync
374 attemptSyncClock(dev, function () {
375 // Check Intel AMT TLS state
@@ -376,23 +378,26 @@ module.exports.CreateAmtManager = function(parent) {
378 attemptRootCertSync(dev, function () {
379 // Check Intel AMT CIRA settings
380 attemptCiraSync(dev, function () {
379 - // See if we need to get hardware inventory
380 - attemptFetchHardwareInventory(dev, function () {
381 - dev.consoleMsg('Done.');
382 -
383 - // Remove from task limiter if needed
384 - if (dev.taskid != null) { obj.parent.taskLimiter.completed(dev.taskid); delete dev.taskLimiter; }
385 -
386 - if (dev.connType != 2) {
387 - // Start power polling if not connected to LMS
388 - var ppfunc = function powerPoleFunction() { fetchPowerState(powerPoleFunction.dev); }
389 - ppfunc.dev = dev;
390 - dev.polltimer = new setTimeout(ppfunc, 290000); // Poll for power state every 4 minutes 50 seconds.
391 - fetchPowerState(dev);
392 - } else {
393 - // For LMS connections, close now.
394 - dev.controlMsg({ action: 'close' });
395 - }
381 + // Check Intel AMT settings
382 + attemptSettingsSync(dev, function() {
383 + // See if we need to get hardware inventory
384 + attemptFetchHardwareInventory(dev, function () {
385 + dev.consoleMsg('Done.');
386 +
387 + // Remove from task limiter if needed
388 + if (dev.taskid != null) { obj.parent.taskLimiter.completed(dev.taskid); delete dev.taskLimiter; }
389 +
390 + if (dev.connType != 2) {
391 + // Start power polling if not connected to LMS
392 + var ppfunc = function powerPoleFunction() { fetchPowerState(powerPoleFunction.dev); }
393 + ppfunc.dev = dev;
394 + dev.polltimer = new setTimeout(ppfunc, 290000); // Poll for power state every 4 minutes 50 seconds.
395 + fetchPowerState(dev);
396 + } else {
397 + // For LMS connections, close now.
398 + dev.controlMsg({ action: 'close' });
399 + }
400 + });
401 });
402 });
403 });
@@ -1008,6 +1013,100 @@ module.exports.CreateAmtManager = function(parent) {
1013 }
1014 }
1015
1016 +
1017 + //
1018 + // Intel AMT Settings
1019 + //
1020 +
1021 + function attemptSettingsSync(dev, func) {
1022 + if (isAmtDeviceValid(dev) == false) return; // Device no longer exists, ignore this request.
1023 + dev.taskCount = 1;
1024 + dev.taskCompleted = func;
1025 +
1026 + dev.consoleMsg("Checking settings...");
1027 +
1028 + // Query the things we are going to be checking
1029 + var query = ['*AMT_GeneralSettings', '*AMT_RedirectionService'];
1030 + if (dev.aquired.majorver > 5) query.push('*CIM_KVMRedirectionSAP');
1031 + dev.amtstack.BatchEnum('', query, attemptSettingsSyncResponse);
1032 + }
1033 +
1034 +
1035 + function attemptSettingsSyncResponse(stack, name, responses, status) {
1036 + const dev = stack.dev;
1037 + if (isAmtDeviceValid(dev) == false) return; // Device no longer exists, ignore this request.
1038 + if (status != 200) { devTaskCompleted(dev); return; }
1039 +
1040 + // If this device does not have KVM, ignore the response. This can happen for Intel Standard Manageability (Intel(R) SM).
1041 + if ((responses['CIM_KVMRedirectionSAP'] == null) || (responses['CIM_KVMRedirectionSAP'].status == 400)) { responses['CIM_KVMRedirectionSAP'] = null; }
1042 +
1043 + // Check redirection services
1044 + var redir = (responses['AMT_RedirectionService'].response['ListenerEnabled'] == true);
1045 + var sol = ((responses['AMT_RedirectionService'].response['EnabledState'] & 2) != 0);
1046 + var ider = ((responses['AMT_RedirectionService'].response['EnabledState'] & 1) != 0);
1047 +
1048 + // Enable SOL & IDER
1049 + if (responses['AMT_RedirectionService'].response['EnabledState'] != 32771) {
1050 + dev.redirObj = responses['AMT_RedirectionService'].response;
1051 + dev.redirObj['ListenerEnabled'] = true;
1052 + dev.redirObj['EnabledState'] = 32771;
1053 + dev.taskCount++;
1054 + dev.amtstack.AMT_RedirectionService_RequestStateChange(32771,
1055 + function (stack, name, response, status) {
1056 + const dev = stack.dev;
1057 + if (isAmtDeviceValid(dev) == false) return; // Device no longer exists, ignore this request.
1058 + dev.amtstack.Put('AMT_RedirectionService', dev.redirObj, function (stack, name, response, status) {
1059 + const dev = stack.dev;
1060 + delete dev.redirObj;
1061 + if (isAmtDeviceValid(dev) == false) return; // Device no longer exists, ignore this request.
1062 + if (status == 200) { dev.consoleMsg("Enabled redirection features."); }
1063 + devTaskCompleted(dev);
1064 + }, 0, 1);
1065 + }
1066 + );
1067 + }
1068 +
1069 + // Check KVM state
1070 + if ((dev.aquired.majorver > 5) && (responses['CIM_KVMRedirectionSAP'] != null)) {
1071 + var kvm = (((responses['CIM_KVMRedirectionSAP'].response['EnabledState'] == 6) && (responses['CIM_KVMRedirectionSAP'].response['RequestedState'] == 2)) || (responses['CIM_KVMRedirectionSAP'].response['EnabledState'] == 2) || (responses['CIM_KVMRedirectionSAP'].response['EnabledState'] == 6));
1072 + if (kvm == false) {
1073 + // Enable KVM
1074 + dev.taskCount++;
1075 + dev.amtstack.CIM_KVMRedirectionSAP_RequestStateChange(2, 0,
1076 + function (stack, name, response, status) {
1077 + const dev = stack.dev;
1078 + if (isAmtDeviceValid(dev) == false) return; // Device no longer exists, ignore this request.
1079 + if (status == 200) { dev.consoleMsg("Enabled KVM"); }
1080 + devTaskCompleted(dev);
1081 + }
1082 + );
1083 + }
1084 + }
1085 +
1086 + // Check device name and domain name
1087 + if ((dev.connType == 2) && (dev.mpsConnection != null) && (dev.mpsConnection.tag != null) && (dev.mpsConnection.tag.meiState != null) && (typeof dev.mpsConnection.tag.meiState.OsHostname == 'string') && (typeof dev.mpsConnection.tag.meiState.OsDnsSuffix == 'string')) {
1088 + const generalSettings = responses['AMT_GeneralSettings'].response;
1089 + if ((generalSettings['HostName'] != dev.mpsConnection.tag.meiState.OsHostname) || (generalSettings['DomainName'] != dev.mpsConnection.tag.meiState.OsDnsSuffix)) {
1090 + // Change the computer and domain name
1091 + generalSettings['HostName'] = dev.mpsConnection.tag.meiState.OsHostname;
1092 + generalSettings['DomainName'] = dev.mpsConnection.tag.meiState.OsDnsSuffix;
1093 + dev.taskCount++;
1094 + dev.xname = dev.mpsConnection.tag.meiState.OsHostname + '.' + dev.mpsConnection.tag.meiState.OsDnsSuffix;
1095 + dev.amtstack.Put('AMT_GeneralSettings', generalSettings, function () {
1096 + const dev = stack.dev;
1097 + if (isAmtDeviceValid(dev) == false) return; // Device no longer exists, ignore this request.
1098 + if (status == 200) { dev.consoleMsg("Changed device name: " + dev.xname); }
1099 + delete dev.xname;
1100 + devTaskCompleted(dev);
1101 + }, 0, 1);
1102 + }
1103 + }
1104 +
1105 + // Done
1106 + devTaskCompleted(dev);
1107 + }
1108 +
1109 +
1110 //
1111 // Intel AMT Hardware Inventory and Networking
1112 //