mirror of
https://github.com/Ylianst/MeshCentral.git
synced 2024-12-30 09:03:20 -05:00
1 line
9.2 KiB
JavaScript
1 line
9.2 KiB
JavaScript
|
var Q=require("queue");function amt_heci(){var d=require("events").inherits(this);d.createEvent("error");var u=require("heci");this._ObjectID="pthi";this._rq=new Q();this._setupPTHI=function b(){this._amt=u.create();this._amt.BiosVersionLen=65;this._amt.UnicodeStringLen=20;this._amt.Parent=this;this._amt.on("error",function E(G){if(this.Parent._rq.isEmpty()){this.Parent.emit("error",G)}else{var I=this.Parent._rq.deQueue();var H=I.optional;var F=I.func;H.unshift({Status:-1});F.apply(this.Parent,H);if(!this.Parent._rq.isEmpty()){this.connect(u.GUIDS.AMT,{noPipeline:1})}}});this._amt.on("connect",function D(){this.on("data",function F(H){var I=this.Parent.getCommand(H);var K=this.Parent._rq.deQueue();var J=K.optional;var G=K.func;J.unshift(I);G.apply(this.Parent,J);if(this.Parent._rq.isEmpty()){this.Parent._amt.disconnect();this.Parent._amt=null}else{this.write(this.Parent._rq.peekQueue().send)}});this.write(this.Parent._rq.peekQueue().send)})};function A(D){var E=D.indexOf("\0");if(E>=0){return D.substring(0,E)}else{return D}}this.getCommand=function g(D){var E=D.length==0?(this._rq.peekQueue().cmd|8388608):D.readUInt32LE(4);var F={IsResponse:(E&8388608)==8388608?true:false,Command:(E&8388607),Status:D.length!=0?D.readUInt32LE(12):-1,Data:D.length!=0?D.slice(16):null};return(F)};this.sendCommand=function x(){if(arguments.length<3||typeof(arguments[0])!="number"||typeof(arguments[1])!="object"||typeof(arguments[2])!="function"){throw ("invalid parameters")}var D=[];for(var F=3;F<arguments.length;++F){D.push(arguments[F])}var E=Buffer.from("010100000000000000000000","hex");E.writeUInt32LE(arguments[0]|67108864,4);E.writeUInt32LE(arguments[1]==null?0:arguments[1].length,8);this._rq.enQueue({cmd:arguments[0],func:arguments[2],optional:D,send:(arguments[1]==null?E:Buffer.concat([E,arguments[1]]))});if(!this._amt){this._setupPTHI();this._amt.connect(u.GUIDS.AMT,{noPipeline:1})}};this.getVersion=function t(D){var F=[];for(var E=1;E<arguments.length;++E){F.push(arguments[E])}this.sendCommand(26,null,function(I,H,K){if(I.Status==0){var J,G=I.Data,M={BiosVersion:G.slice(0,this._amt.BiosVersionLen).toString(),Versions:[]},L=G.slice(this._amt.BiosVersionLen+4);for(J=0;J<G.readUInt32LE(this._amt.BiosVersionLen);++J){M.Versions[J]={Description:L.slice(2,L.readUInt16LE(0)+2).toString(),Version:L.slice(4+this._amt.UnicodeStringLen,4+this._amt.UnicodeStringLen+L.readUInt16LE(2+this._amt.UnicodeStringLen)).toString()};L=L.slice(4+(2*this._amt.UnicodeStringLen))}if(M.BiosVersion.indexOf("\0")>0){M.BiosVersion=M.BiosVersion.substring(0,M.BiosVersion.indexOf("\0"))}K.unshift(M)}else{K.unshift(null)}H.apply(this,K)},D,F)};function C(F,E){if((E==null)&&(typeof(E)!="number")){return null}if(F==null){F=""}var G="";for(var D=0;D<E-F.length;D++){G+="0"}return G+F}this.getUuid=function s(D){var F=[];for(var E=1;E<arguments.length;++E){F.push(arguments[E])}this.sendCommand(92,null,function(H,G,I){if(H.Status==0){var J={};J.uuid=[C(H.Data.readUInt32LE(0).toString(16),8),C(H.Data.readUInt16LE(4).toString(16),4),C(H.Data.readUInt16LE(6).toString(16),4),C(H.Data.readUInt16BE(8).toString(16),4),C(H.Data.slice(10).toString("hex").toLowerCase(),12)].join("-");I.unshift(J)}else{I.unshift(null)}G.apply(this,I)},D,F)};this.getProvisioningState=function q(D){var F=[];for(var E=1;E<arguments.length;++E){F.push(arguments[E])}this.sendCommand(17,null,function(H,G,I){if(H.Status==0){var J={};J.state=H.Data.readUInt32LE(0);if(J.state<3){J.stateStr=["PRE","IN","POST"][J.state]}I.unshift(J)}else{I.unshift(null)}G.apply(this,I)},D,F)};this.getProvisioningMode=function p(D){var F=[];for(var E=1;E<arguments.length;++E){F.push(arguments[E])}this.sendCommand(8,null,function(H,G,I){if(H.Status==0){var J={};J.mode=H.Data.readUInt32LE(0);if(J.mode<4){J.modeStr=["NONE","ENTERPRISE","SMALL_BUSINESS","REMOTE_ASSISTANCE"][J.mode]}J.legacy=H.Data.readUInt32LE(4)==0?false:true;I.unshift(J)}else{I.unshift(null)}G.apply(this,I)},D,F)};this.getEHBCState=function j(D){var F=[];for(var E=1;E<arguments.length;++E){F.push(arguments[E])}this.sendCommand(132,null,function(H,G,I){if(H.Status
|