From e6639df37144e417694f7980869ac1a301251246 Mon Sep 17 00:00:00 2001 From: Bryan Roe Date: Tue, 11 Aug 2020 18:38:38 -0700 Subject: [PATCH] Updated LMS metadata available to meshcore and server --- agents/meshcore.js | 48 +++++++++++++++++++++++++-- agents/modules_meshcore/amt-manage.js | 38 +++++++++++++++++++-- 2 files changed, 82 insertions(+), 4 deletions(-) diff --git a/agents/meshcore.js b/agents/meshcore.js index d25db3eb..0986e520 100644 --- a/agents/meshcore.js +++ b/agents/meshcore.js @@ -435,9 +435,34 @@ function createMeshCore(agent) { if (mesh.isControlChannelConnected) { mesh.SendCommand({ action: 'smbios', value: SMBiosTablesRaw }); } // If SMBios tables say that Intel AMT is present, try to connect MEI - if (SMBiosTables.amtInfo && (SMBiosTables.amtInfo.AMT == true)) { + if (SMBiosTables.amtInfo && (SMBiosTables.amtInfo.AMT == true)) + { var amtmodule = require('amt-manage'); amt = new amtmodule(mesh, db, false); + amt.on('portBinding_LMS', function (map) + { + var j = { action: 'lmsinfo', value: { ports: map.keys() } }; + mesh.SendCommand(j); + }); + amt.on('stateChange_LMS', function (v) + { + if (!meshCoreObj.intelamt) { meshCoreObj.intelamt = {}; } + switch(v) + { + case 0: + meshCoreObj.intelamt.microlms = 'DISABLED'; + break; + case 1: + meshCoreObj.intelamt.microlms = 'CONNECTING'; + break; + case 2: + meshCoreObj.intelamt.microlms = 'CONNECTED'; + break; + default: + break; + } + mesh.SendCommand(meshCoreObj); + }); amt.onStateChange = function (state) { if (state == 2) { sendPeriodicServerUpdate(1); } } if (amtPolicy != null) { amt.setPolicy(amtPolicy); } amt.start(); @@ -3492,7 +3517,26 @@ function createMeshCore(agent) { amt.getAmtInfo(function (meinfo) { try { if (meinfo == null) return; - var intelamt = {}, p = false; + var intelamt = {}; + if (amt != null) + { + switch(amt.lmsstate) + { + case 0: + intelamt.microlms = 'DISABLED' + break; + case 1: + intelamt.microlms = 'CONNECTING' + break; + case 2: + intelamt.microlms = 'CONNECTED' + break; + default: + intelamt.microlms = 'unknown' + break; + } + } + var p = false; if ((meinfo.Versions != null) && (meinfo.Versions.AMT != null)) { intelamt.ver = meinfo.Versions.AMT; p = true; if (meinfo.Versions.Sku != null) { intelamt.sku = parseInt(meinfo.Versions.Sku); } } if (meinfo.ProvisioningState != null) { intelamt.state = meinfo.ProvisioningState; p = true; } if (meinfo.Flags != null) { intelamt.flags = meinfo.Flags; p = true; } diff --git a/agents/modules_meshcore/amt-manage.js b/agents/modules_meshcore/amt-manage.js index b20a6508..e64eccfe 100644 --- a/agents/modules_meshcore/amt-manage.js +++ b/agents/modules_meshcore/amt-manage.js @@ -36,8 +36,38 @@ function AmtManager(agent, db, isdebug) { var obj = this; var mestate; var trustedHashes = null;; + + require('events').EventEmitter.call(obj, true) + .createEvent('stateChange_LMS') + .createEvent('portBinding_LMS'); + obj._lmsstate = 0; + obj._mapping = []; + + obj.on('newListener', function (name, callback) + { + if(name == 'portBinding_LMS') + { + callback.call(this, this._mapping); + } + }); + + Object.defineProperty(obj, 'lmsstate', + { + get: function () + { + return (this._lmsstate); + }, + set: function (value) + { + if (this._lmsstate != value) + { + this._lmsstate = value; + this.emit('stateChange_LMS', value); + } + } + }); + obj.state = 0; - obj.lmsstate = 0; obj.onStateChange = null; obj.setDebug = function (x) { isdebug = x; } @@ -124,7 +154,11 @@ function AmtManager(agent, db, isdebug) { amtLms = new lme_heci(); amtLms.on('error', function (e) { amtLmsState = 0; obj.lmsstate = 0; amtLms = null; debug("LMS error: " + e); setupMeiOsAdmin(1); }); amtLms.on('connect', function () { amtLmsState = 2; obj.lmsstate = 2; debug("LMS connected"); setupMeiOsAdmin(2); }); - //amtLms.on('bind', function (map) { }); + amtLms.on('bind', function (map) + { + obj._mapping = map; + obj.emit('portBinding_LMS', map); + }); amtLms.on('notify', function (data, options, str, code) { //debug('LMS notify'); if (code == 'iAMT0052-3') {