Added Intel AMT WIFI auto enabling/disabling.

Ylian Saint-Hilaire committed Oct 22, 2020 at 19:11 UTC f9e64aeb3f7ddfbfa4023cdd6158bec06fb6a77a
1 file changed +27 -10
amtmanager.js
+27 -10
@@ -954,19 +954,20 @@ module.exports.CreateAmtManager = function (parent) {
954 if (isAmtDeviceValid(dev) == false) return; // Device no longer exists, ignore this request.
955 if (dev.connType != 2) { func(dev); return; } // Only configure wireless over a CIRA-LMS link
956 if (parent.config.domains[dev.domainid].amtmanager.wifiprofiles == null) { func(dev); return; } // No server WIFI profiles set, skip this.
957 + if ((dev.mpsConnection.tag.meiState == null) || (dev.mpsConnection.tag.meiState.net1 == null)) { func(dev); return; } // No WIFI on this device, skip this.
958
959 // Get the current list of WIFI profiles
960 dev.taskCount = 1;
961 dev.taskCompleted = func;
961 - dev.amtstack.BatchEnum(null, ['CIM_WiFiEndpointSettings'], function (stack, name, responses, status) {
962 + dev.amtstack.BatchEnum(null, ['CIM_WiFiEndpointSettings', '*CIM_WiFiPort'], function (stack, name, responses, status) {
963 const dev = stack.dev;
964 if (isAmtDeviceValid(dev) == false) return; // Device no longer exists, ignore this request.
965 if (status != 200) { devTaskCompleted(dev); return; } // We can't get wireless settings, ignore and carry on.
966
967 // The server and device WIFI profiles, find profiles to add and remove
968 const sevProfiles = parent.config.domains[dev.domainid].amtmanager.wifiprofiles;
968 - const devProfiles = responses['CIM_WiFiEndpointSettings'].responses
969 - var profilesToAdd = [], profilesToRemove = [];
969 + const devProfiles = responses['CIM_WiFiEndpointSettings'].responses;
970 + var profilesToAdd = [], profilesToRemove = [];
971
972 // Look at the WIFI profiles in the device
973 for (var i in sevProfiles) {
@@ -988,16 +989,12 @@ module.exports.CreateAmtManager = function (parent) {
989 if (devProfile.match !== true) { profilesToRemove.push(devProfile); }
990 }
991
991 - // If both lists are empty, we have nothing to do.
992 - if ((profilesToAdd.length == 0) && (profilesToRemove.length == 0)) { devTaskCompleted(dev); return; }
993 -
992 // Compute what priorities are allowed
993 var prioritiesInUse = [];
996 - for (var j in devProfiles) { if (devProfiles[j].match == true) { prioritiesInUse.push(devProfiles[j].Priority); }}
994 + for (var j in devProfiles) { if (devProfiles[j].match == true) { prioritiesInUse.push(devProfiles[j].Priority); } }
995
996 // Notify of WIFI profile changes
999 - console.log(dev.name, "Changing WIFI profiles, adding " + profilesToAdd.length + ", removing " + profilesToRemove.length + ".");
1000 - dev.consoleMsg("Changing WIFI profiles, adding " + profilesToAdd.length + ", removing " + profilesToRemove.length + ".");
997 + if ((profilesToAdd.length > 0) && (profilesToRemove.length > 0)) { dev.consoleMsg("Changing WIFI profiles, adding " + profilesToAdd.length + ", removing " + profilesToRemove.length + "."); }
998
999 // Remove any extra WIFI profiles
1000 for (var i in profilesToRemove) {
@@ -1026,7 +1023,27 @@ module.exports.CreateAmtManager = function (parent) {
1023 PSKPassPhrase: profileToAdd.password
1024 }
1025 prioritiesInUse.push(nextPriority); // Occupy the priority slot and add the WIFI profile.
1029 - dev.amtstack.AMT_WiFiPortConfigurationService_AddWiFiSettings(wifiep, wifiepsettinginput, null, null, null, function (stack, name, responses, status) { console.log('added', status); });
1026 + dev.amtstack.AMT_WiFiPortConfigurationService_AddWiFiSettings(wifiep, wifiepsettinginput, null, null, null, function (stack, name, responses, status) { console.log('added', status); });
1027 + }
1028 +
1029 + // Compute how many WIFI profiles will be in the device and change the state if needed
1030 + // WifiState = { 3: "Disabled", 32768: "Enabled in S0", 32769: "Enabled in S0, Sx/AC" };
1031 + var resultingProfileCount = (devProfiles.length + profilesToAdd.length - profilesToRemove.length);
1032 + var wifiState = (resultingProfileCount == 0) ? 3 : 32769;
1033 + if (responses['CIM_WiFiPort'].responses.Body.EnabledState != wifiState) {
1034 + if (wifiState == 3) {
1035 + dev.amtstack.CIM_WiFiPort_RequestStateChange(wifiState, null, function (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) { dev.consoleMsg("Disabled WIFI."); }
1039 + });
1040 + } else {
1041 + dev.amtstack.CIM_WiFiPort_RequestStateChange(wifiState, null, function (stack, name, responses, status) {
1042 + const dev = stack.dev;
1043 + if (isAmtDeviceValid(dev) == false) return; // Device no longer exists, ignore this request.
1044 + if (status == 200) { dev.consoleMsg("Enabled WIFI."); }
1045 + });
1046 + }
1047 }
1048
1049 // Done