Added Intel AMT WIFI profile sync.
Ylian Saint-Hilaire committed
Oct 22, 2020 at 18:39 UTC
898dbc4e24e632f51a00fcae3cdd05382e4b0b27
1 file changed
+154
-23
amtmanager.js
+154
-23
@@ -46,6 +46,8 @@ module.exports.CreateAmtManager = function (parent) {
46
obj.amtAdminAccounts[domainid].push(c2);
47
}
48
}
49
+ } else {
50
+ delete domain.amtmanager.adminaccounts;
51
}
52
53
// Check environment detection
@@ -57,6 +59,41 @@ module.exports.CreateAmtManager = function (parent) {
59
if (envDetect.length >= 4) break; // Maximum of 4 DNS suffix
60
}
61
if (envDetect.length > 0) { domain.amtmanager.environmentdetection = envDetect; } else { delete domain.amtmanager.environmentdetection; }
62
+ } else {
63
+ delete domain.amtmanager.environmentdetection;
64
+ }
65
+
66
+ // Check WIFI profiles
67
+ //var wifiAuthMethod = { 1: "Other", 2: "Open", 3: "Shared Key", 4: "WPA PSK", 5: "WPA 802.1x", 6: "WPA2 PSK", 7: "WPA2 802.1x", 32768: "WPA3 802.1x" };
68
+ //var wifiEncMethod = { 1: "Other", 2: "WEP", 3: "TKIP", 4: "CCMP", 5: "None" }
69
+ if (Array.isArray(domain.amtmanager.wifiprofiles) == true) {
70
+ var goodWifiProfiles = [];
71
+ for (var i = 0; i < domain.amtmanager.wifiprofiles.length; i++) {
72
+ var wifiProfile = domain.amtmanager.wifiprofiles[i];
73
+ if ((typeof wifiProfile.ssid == 'string') && (wifiProfile.ssid != '') && (typeof wifiProfile.password == 'string') && (wifiProfile.password != '')) {
74
+ if ((wifiProfile.name == null) || (wifiProfile.name == '')) { wifiProfile.name = wifiProfile.ssid; }
75
+ if (typeof wifiProfile.authentication == 'string') {
76
+ // Authentication
77
+ if (typeof wifiProfile.authentication == 'string') { wifiProfile.authentication = wifiProfile.authentication.toLowerCase(); }
78
+ if (wifiProfile.authentication == 'wpa-psk') { wifiProfile.authentication = 4; }
79
+ if (wifiProfile.authentication == 'wpa2-psk') { wifiProfile.authentication = 6; }
80
+ if (typeof wifiProfile.authentication != 'number') { wifiProfile.authentication = 4; } // Default to CCMP-AES
81
+
82
+ // Encyption
83
+ if (typeof wifiProfile.encryption == 'string') { wifiProfile.encryption = wifiProfile.encryption.toLowerCase(); }
84
+ if ((wifiProfile.encryption == 'ccmp-aes') || (wifiProfile.encryption == 'ccmp')) { wifiProfile.encryption = 4; }
85
+ if ((wifiProfile.encryption == 'tkip-rc4') || (wifiProfile.encryption == 'tkip')) { wifiProfile.encryption = 3; }
86
+ if (typeof wifiProfile.encryption != 'number') { wifiProfile.encryption = 6; } // Default to WPA2-PSK
87
+
88
+ // Type
89
+ wifiProfile.type = 3; // Infrastructure
90
+ }
91
+ goodWifiProfiles.push(wifiProfile);
92
+ }
93
+ }
94
+ domain.amtmanager.wifiprofiles = goodWifiProfiles;
95
+ } else {
96
+ delete domain.amtmanager.wifiprofiles;
97
}
98
}
99
@@ -479,29 +516,32 @@ module.exports.CreateAmtManager = function (parent) {
516
attemptTlsSync(dev, function (dev) {
517
// If we need to switch to TLS, do it now.
518
if (dev.switchToTls == 1) { delete dev.switchToTls; attemptInitialContact(dev); return; }
482
- // Check Intel AMT root certificate state
483
- attemptRootCertSync(dev, function (dev) {
484
- // Check Intel AMT CIRA settings
485
- attemptCiraSync(dev, function (dev) {
486
- // Check Intel AMT settings
487
- attemptSettingsSync(dev, function (dev) {
488
- // See if we need to get hardware inventory
489
- attemptFetchHardwareInventory(dev, function (dev) {
490
- dev.consoleMsg('Done.');
491
-
492
- // Remove from task limiter if needed
493
- if (dev.taskid != null) { obj.parent.taskLimiter.completed(dev.taskid); delete dev.taskLimiter; }
494
-
495
- if (dev.connType != 2) {
496
- // Start power polling if not connected to LMS
497
- var ppfunc = function powerPoleFunction() { fetchPowerState(powerPoleFunction.dev); }
498
- ppfunc.dev = dev;
499
- dev.polltimer = new setTimeout(ppfunc, 290000); // Poll for power state every 4 minutes 50 seconds.
500
- fetchPowerState(dev);
501
- } else {
502
- // For LMS connections, close now.
503
- dev.controlMsg({ action: 'close' });
504
- }
519
+ // Check Intel AMT WIFI state
520
+ attemptWifiSync(dev, function (dev) {
521
+ // Check Intel AMT root certificate state
522
+ attemptRootCertSync(dev, function (dev) {
523
+ // Check Intel AMT CIRA settings
524
+ attemptCiraSync(dev, function (dev) {
525
+ // Check Intel AMT settings
526
+ attemptSettingsSync(dev, function (dev) {
527
+ // See if we need to get hardware inventory
528
+ attemptFetchHardwareInventory(dev, function (dev) {
529
+ dev.consoleMsg('Done.');
530
+
531
+ // Remove from task limiter if needed
532
+ if (dev.taskid != null) { obj.parent.taskLimiter.completed(dev.taskid); delete dev.taskLimiter; }
533
+
534
+ if (dev.connType != 2) {
535
+ // Start power polling if not connected to LMS
536
+ var ppfunc = function powerPoleFunction() { fetchPowerState(powerPoleFunction.dev); }
537
+ ppfunc.dev = dev;
538
+ dev.polltimer = new setTimeout(ppfunc, 290000); // Poll for power state every 4 minutes 50 seconds.
539
+ fetchPowerState(dev);
540
+ } else {
541
+ // For LMS connections, close now.
542
+ dev.controlMsg({ action: 'close' });
543
+ }
544
+ });
545
});
546
});
547
});
@@ -904,6 +944,97 @@ module.exports.CreateAmtManager = function (parent) {
944
}
945
946
947
+ //
948
+ // Intel AMT WIFI
949
+ //
950
+
951
+ // This method will sync the WIFI profiles from the device and the server, but does not care about profile priority.
952
+ // We may want to work on an alternate version that does do priority if requested.
953
+ function attemptWifiSync(dev, func) {
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
+
958
+ // Get the current list of WIFI profiles
959
+ dev.taskCount = 1;
960
+ dev.taskCompleted = func;
961
+ dev.amtstack.BatchEnum(null, ['CIM_WiFiEndpointSettings'], function (stack, name, responses, status) {
962
+ const dev = stack.dev;
963
+ if (isAmtDeviceValid(dev) == false) return; // Device no longer exists, ignore this request.
964
+ if (status != 200) { devTaskCompleted(dev); return; } // We can't get wireless settings, ignore and carry on.
965
+
966
+ // The server and device WIFI profiles, find profiles to add and remove
967
+ const sevProfiles = parent.config.domains[dev.domainid].amtmanager.wifiprofiles;
968
+ const devProfiles = responses['CIM_WiFiEndpointSettings'].responses
969
+ var profilesToAdd = [], profilesToRemove = [];
970
+
971
+ // Look at the WIFI profiles in the device
972
+ for (var i in sevProfiles) {
973
+ var sevProfile = sevProfiles[i], match = false;
974
+ for (var j in devProfiles) {
975
+ var devProfile = devProfiles[j];
976
+ if (
977
+ (devProfile.ElementName == sevProfile.name) &&
978
+ (devProfile.SSID == sevProfile.ssid) &&
979
+ (devProfile.AuthenticationMethod == sevProfile.authentication) &&
980
+ (devProfile.EncryptionMethod == sevProfile.encryption) &&
981
+ (devProfile.BSSType == sevProfile.type)
982
+ ) { match = true; devProfile.match = true; }
983
+ }
984
+ if (match == false) { profilesToAdd.push(sevProfile); }
985
+ }
986
+ for (var j in devProfiles) {
987
+ var devProfile = devProfiles[j];
988
+ if (devProfile.match !== true) { profilesToRemove.push(devProfile); }
989
+ }
990
+
991
+ // If both lists are empty, we have nothing to do.
992
+ if ((profilesToAdd.length == 0) && (profilesToRemove.length == 0)) { devTaskCompleted(dev); return; }
993
+
994
+ // Compute what priorities are allowed
995
+ var prioritiesInUse = [];
996
+ for (var j in devProfiles) { if (devProfiles[j].match == true) { prioritiesInUse.push(devProfiles[j].Priority); }}
997
+
998
+ // 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 + ".");
1001
+
1002
+ // Remove any extra WIFI profiles
1003
+ for (var i in profilesToRemove) {
1004
+ dev.amtstack.Delete('CIM_WiFiEndpointSettings', { InstanceID: 'Intel(r) AMT:WiFi Endpoint Settings ' + profilesToRemove[i].ElementName }, function (stack, name, responses, status) { console.log('removed', status); }, 0, 1);
1005
+ }
1006
+
1007
+ // Add missing WIFI profiles
1008
+ var nextPriority = 0;
1009
+ for (var i in profilesToAdd) {
1010
+ while (prioritiesInUse.indexOf(nextPriority) >= 0) { nextPriority++; } // Figure out the next available priority slot.
1011
+ var profileToAdd = profilesToAdd[i];
1012
+ const wifiep = {
1013
+ __parameterType: 'reference',
1014
+ __resourceUri: 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_WiFiEndpoint',
1015
+ Name: 'WiFi Endpoint 0'
1016
+ };
1017
+ const wifiepsettinginput = {
1018
+ __parameterType: 'instance',
1019
+ __namespace: 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_WiFiEndpointSettings',
1020
+ ElementName: profileToAdd.name,
1021
+ InstanceID: 'Intel(r) AMT:WiFi Endpoint Settings ' + profileToAdd.name,
1022
+ AuthenticationMethod: profileToAdd.authentication,
1023
+ EncryptionMethod: profileToAdd.encryption,
1024
+ SSID: profileToAdd.ssid,
1025
+ Priority: nextPriority,
1026
+ PSKPassPhrase: profileToAdd.password
1027
+ }
1028
+ 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); });
1030
+ }
1031
+
1032
+ // Done
1033
+ devTaskCompleted(dev);
1034
+ });
1035
+ }
1036
+
1037
+
1038
//
1039
// Intel AMT Server Root Certificate
1040
//